From: Christian Heller Date: Mon, 29 Feb 2016 00:16:47 +0000 (+0100) Subject: Server, plugin: Refactor command_ttid plugin hooking. X-Git-Tag: tce~121 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/day?a=commitdiff_plain;h=f8865085362ad23898ac4b6a00db3b915226d9d3;p=plomrogue Server, plugin: Refactor command_ttid plugin hooking. --- diff --git a/plugins/server/PleaseTheIslandGod.py b/plugins/server/PleaseTheIslandGod.py index e989d53..04ae0e1 100644 --- a/plugins/server/PleaseTheIslandGod.py +++ b/plugins/server/PleaseTheIslandGod.py @@ -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)) diff --git a/server/commands.py b/server/commands.py index fc38452..90de4a9 100644 --- a/server/commands.py +++ b/server/commands.py @@ -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" } diff --git a/server/config/world_data.py b/server/config/world_data.py index ec1e9b1..dcedabd 100644 --- a/server/config/world_data.py +++ b/server/config/world_data.py @@ -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 = "." diff --git a/server/utils.py b/server/utils.py index db33eba..22acb0d 100644 --- a/server/utils.py +++ b/server/utils.py @@ -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