home · contact · privacy
TCE: Add limit to drinking.
[plomrogue] / plugins / server / TheCrawlingEater.py
index 210356a1753e267b730502237270b7cb4c9d6c70..1fc7e0c5737cd0e7cb38b0827388812e9850ff07 100644 (file)
@@ -11,15 +11,36 @@ def play_drink():
         if ord("~") != world_db["MAP"][world_db["Things"][0]["pos"]]:
             log("NOTHING to drink here.")
             return
+        elif world_db["Things"][0]["T_BLADDER"] >= 32:
+            log("You're too FULL to drink more.")
+            return
         world_db["set_command"]("drink")
 
 
 def actor_drink(t):
-    if ord("~") == world_db["MAP"][world_db["Things"][0]["pos"]]:
+    if ord("~") == world_db["MAP"][world_db["Things"][0]["pos"]] and \
+            t["T_BLADDER"] < 32:
         log("You DRINK.")
         t["T_BLADDER"] += 1
 
 
+def play_pee():
+    if action_exists("pee") and world_db["WORLD_ACTIVE"]:
+        if world_db["Things"][0]["T_BLADDER"] < 1:
+            log("Nothing to drop from empty bladder.")
+            return
+        world_db["set_command"]("pee")
+
+
+def actor_pee(t):
+    if t["T_BLADDER"] < 1:
+        return
+    if t == world_db["Things"][0]:
+        log("You LOSE fluid.")
+    terrain = world_db["MAP"][t["pos"]]
+    t["T_BLADDER"] -= 1
+
+
 def play_drop():
     if action_exists("drop") and world_db["WORLD_ACTIVE"]:
         if world_db["Things"][0]["T_BOWEL"] < 1:
@@ -67,6 +88,10 @@ def play_move(str_arg):
             pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
             if ord("%") == world_db["MAP"][pos] or \
                     ord("#") == world_db["MAP"][pos]:
+                if t["T_BOWEL"] >= 32:
+                    if t == world_db["Things"][0]:
+                        log("You're too FULL to eat.")
+                    return
                 world_db["Things"][0]["T_ARGUMENT"] = d
                 world_db["set_command"]("move")
                 return
@@ -111,8 +136,7 @@ def actor_move(t):
         build_fov_map(t)
     else:
         if t["T_BOWEL"] >= 32:
-            if t == world_db["Things"][0]:
-                log("You're too FULL to eat.")
+            return
         elif ord("%") == world_db["MAP"][pos] and 0 == int(rand.next() % 2):
             log("You EAT.")
             world_db["MAP"][pos] = ord("_")
@@ -206,6 +230,9 @@ def turn_over():
                     if Thing["T_BOWEL"] > 16:
                         if 0 == (rand.next() % (33 - Thing["T_BOWEL"])):
                             action_db["actor_drop"](Thing)
+                    if Thing["T_BLADDER"] > 16:
+                        if 0 == (rand.next() % (33 - Thing["T_BLADDER"])):
+                            action_db["actor_pee"](Thing)
         world_db["TURN"] += 1
         io_db["worldstate_updateable"] = True
         try_worldstate_update()
@@ -252,6 +279,7 @@ commands_db["move"] = (1, False, play_move)
 commands_db["wait"] = (0, False, play_wait)
 commands_db["drop"] = (0, False, play_drop)
 commands_db["drink"] = (0, False, play_drink)
+commands_db["pee"] = (0, False, play_pee)
 commands_db["use"] = (1, False, lambda x: None)
 commands_db["pickup"] = (0, False, lambda: None)
 commands_db["T_BOWEL"] = (1, False, setter("Thing", "T_BOWEL", 0, 255))
@@ -263,6 +291,7 @@ server.config.actions.action_db = {
     "actor_move": actor_move,
     "actor_drop": actor_drop,
     "actor_drink": actor_drink,
+    "actor_pee": actor_pee,
 }
 
 strong_write(io_db["file_out"], "PLUGIN TheCrawlingEater\n")