home · contact · privacy
Server, plugin: Refactor command_ttid plugin hooking.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 29 Feb 2016 00:16:47 +0000 (01:16 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 29 Feb 2016 00:16:47 +0000 (01:16 +0100)
plugins/server/PleaseTheIslandGod.py
server/commands.py
server/config/world_data.py
server/utils.py

index e989d539d5f790d392d2e6f3f633d449f03ea9c4..04ae0e16e59ea8bdae0bd8e834dd0d92c131c6d7 100644 (file)
@@ -323,21 +323,6 @@ def decrement_lifepoints(t):
                     "at the altar.")
     return test
 
-def command_ttid(id_string):
-    id = id_setter(id_string, "ThingTypes", command_ttid)
-    if None != id:
-        world_db["ThingTypes"][id] = {
-            "TT_NAME": "(none)",
-            "TT_TOOLPOWER": 0,
-            "TT_LIFEPOINTS": 0,
-            "TT_PROLIFERATE": 0,
-            "TT_START_NUMBER": 0,
-            "TT_STORAGE": 0,
-            "TT_SYMBOL": "?",
-            "TT_CORPSE_ID": id,
-            "TT_TOOL": ""
-        }
-
 def command_worldactive(worldactive_string):
     val = integer_test(worldactive_string, 0, 1)
     if None != val:
@@ -588,8 +573,9 @@ io_db["worldstate_write_order"] += [[write_metamap_B, "func"]]
 import server.config.world_data
 server.config.world_data.symbols_passable += ":_"
 
-from server.config.world_data import thing_defaults
+from server.config.world_data import thing_defaults, thingtype_defaults
 thing_defaults["T_PLAYERDROP"] = 0
+thingtype_defaults["TT_STORAGE"] = 0
 
 import server.config.actions
 server.config.actions.action_db["actor_move"] = actor_move
@@ -600,7 +586,6 @@ server.config.actions.actor_use_attempts_hook = actor_use_attempts_hook
 server.config.actions.actor_move_attempts_hook = actor_move_attempts_hook
 
 from server.config.commands import commands_db
-commands_db["TT_ID"] = (1, False, command_ttid)
 commands_db["GOD_FAVOR"] = (1, False, setter(None, "GOD_FAVOR", -32768, 32767))
 commands_db["TT_STORAGE"] = (1, False, setter("ThingType", "TT_STORAGE", 0, 255))
 commands_db["T_PLAYERDROP"] = (1, False, setter("Thing", "T_PLAYERDROP", 0, 1))
index fc384528704cf88e8cfec3b975a857d1433594f2..90de4a9f05092086caf050f441e27672ab72d530 100644 (file)
@@ -149,34 +149,28 @@ def command_tid(id_string):
 
     Default new Thing's type to the first available ThingType, others: zero.
     """
-    id = id_setter(id_string, "Things", command_tid)
-    if None != id:
+    tid = id_setter(id_string, "Things", command_tid)
+    if None != tid:
         if world_db["ThingTypes"] == {}:
             print("Ignoring: No ThingType to settle new Thing in.")
             return
-        type = list(world_db["ThingTypes"].keys())[0]
+        ty = list(world_db["ThingTypes"].keys())[0]
         from server.new_thing import new_Thing
-        world_db["Things"][id] = new_Thing(type)
+        world_db["Things"][tid] = new_Thing(ty)
 
 
 def command_ttid(id_string):
     """Set ID of ThingType to manipulate. ID unused? Create new one.
 
-    Default new ThingType's TT_SYMBOL to "?", TT_CORPSE_ID to self, TT_TOOL to
-    "", others: 0. 
+    Set new type's TT_CORPSE_ID to self, other fields to thingtype_defaults.
     """
-    id = id_setter(id_string, "ThingTypes", command_ttid)
-    if None != id:
-        world_db["ThingTypes"][id] = {
-            "TT_NAME": "(none)",
-            "TT_TOOLPOWER": 0,
-            "TT_LIFEPOINTS": 0,
-            "TT_PROLIFERATE": 0,
-            "TT_START_NUMBER": 0,
-            "TT_SYMBOL": "?",
-            "TT_CORPSE_ID": id,
-            "TT_TOOL": ""
-        }
+    ttid = id_setter(id_string, "ThingTypes", command_ttid)
+    if None != ttid:
+        from server.config.world_data import thingtype_defaults
+        world_db["ThingTypes"][ttid] = {}
+        for key in thingtype_defaults:
+            world_db["ThingTypes"][ttid][key] = thingtype_defaults[key]
+        world_db["ThingTypes"][ttid]["TT_CORPSE_ID"] = ttid
 
 
 def command_taid(id_string):
@@ -184,9 +178,9 @@ def command_taid(id_string):
 
     Default new ThingAction's TA_EFFORT to 1, its TA_NAME to "wait".
     """
-    id = id_setter(id_string, "ThingActions", command_taid, True)
-    if None != id:
-        world_db["ThingActions"][id] = {
+    taid = id_setter(id_string, "ThingActions", command_taid, True)
+    if None != taid:
+        world_db["ThingActions"][taid] = {
             "TA_EFFORT": 1,
             "TA_NAME": "wait"
         }
index ec1e9b15c7d52a24c88b1c99e2a59dec32296a9e..dcedabd0529ffdd4f5c51d41c56e3b77d0a205e3 100644 (file)
@@ -27,16 +27,26 @@ directions_db = {"east": "d", "south-east": "c", "south-west": "x",
                  "west": "s", "north-west": "w", "north-east": "e"}
 
 thing_defaults = {
-        "T_ARGUMENT": 0,
-        "T_PROGRESS": 0,
-        "T_SATIATION": 0,
-        "T_COMMAND": 0,
-        "T_CARRIES": [],
-        "carried": False,
-        "T_MEMTHING": [],
-        "T_MEMMAP": False,
-        "T_MEMDEPTHMAP": False,
-        "fovmap": False
+    "T_ARGUMENT": 0,
+    "T_PROGRESS": 0,
+    "T_SATIATION": 0,
+    "T_COMMAND": 0,
+    "T_CARRIES": [],
+    "carried": False,
+    "T_MEMTHING": [],
+    "T_MEMMAP": False,
+    "T_MEMDEPTHMAP": False,
+    "fovmap": False
+}
+
+thingtype_defaults = {
+        "TT_NAME": "(none)",
+        "TT_TOOLPOWER": 0,
+        "TT_LIFEPOINTS": 0,
+        "TT_PROLIFERATE": 0,
+        "TT_START_NUMBER": 0,
+        "TT_SYMBOL": "?",
+        "TT_TOOL": ""
 }
 
 symbols_passable = "."
index db33eba88ebe79c368f72baf6a38e32c00c63c2f..22acb0dec6564eda7729be8b918e2e85ee9232a6 100644 (file)
@@ -42,7 +42,8 @@ def integer_test(val_string, min, max=None):
 
 
 def id_setter(id, category, id_store=False, start_at_1=False):
-    """Set ID of object of category to manipulate ID. Unused? Create new one.
+    """Set ID of object of category to manipulate. ID unused? Create new one.
+
     The ID is stored as id_store.id (if id_store is set). If the integer of the
     input is valid (if start_at_1, >= 0, else >= -1), but <0 or (if start_at_1)
     <1, calculate new ID: lowest unused ID >=0 or (if start_at_1) >= 1. None is