1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
6 from server.config.world_data import world_db
10 if action_exists("drink") and world_db["WORLD_ACTIVE"]:
11 if ord("~") != world_db["MAP"][world_db["Things"][0]["pos"]]:
12 log("NOTHING to drink here.")
14 world_db["set_command"]("drink")
18 if ord("~") == world_db["MAP"][world_db["Things"][0]["pos"]]:
24 if action_exists("pee") and world_db["WORLD_ACTIVE"]:
25 if world_db["Things"][0]["T_BLADDER"] < 1:
26 log("Nothing to drop from empty bladder.")
28 world_db["set_command"]("pee")
32 if t["T_BLADDER"] < 1:
34 if t == world_db["Things"][0]:
35 log("You LOSE fluid.")
36 terrain = world_db["MAP"][t["pos"]]
41 if action_exists("drop") and world_db["WORLD_ACTIVE"]:
42 if world_db["Things"][0]["T_BOWEL"] < 1:
43 log("Nothing to drop from empty bowel.")
45 world_db["set_command"]("drop")
51 if t == world_db["Things"][0]:
52 log("You DROP waste.")
53 terrain = world_db["MAP"][t["pos"]]
55 if chr(terrain) == "_":
56 world_db["MAP"][t["pos"]] = ord(".")
57 elif chr(terrain) == ".":
58 world_db["MAP"][t["pos"]] = ord(":")
59 elif chr(terrain) == ":":
60 world_db["MAP"][t["pos"]] = ord("%")
61 elif chr(terrain) == "%":
62 world_db["MAP"][t["pos"]] = ord("#")
63 elif chr(terrain) == "#":
64 world_db["MAP"][t["pos"]] = ord("X")
65 elif chr(terrain) == "X":
67 if t == world_db["Things"][0]:
68 t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
72 def play_move(str_arg):
73 """Try "move" as player's T_COMMAND, str_arg as T_ARGUMENT / direction."""
74 if action_exists("move") and world_db["WORLD_ACTIVE"]:
75 from server.config.world_data import directions_db, symbols_passable
76 t = world_db["Things"][0]
77 if not str_arg in directions_db:
78 print("Illegal move direction string.")
80 d = ord(directions_db[str_arg])
81 from server.utils import mv_yx_in_dir_legal
82 move_result = mv_yx_in_dir_legal(chr(d), t["T_POSY"], t["T_POSX"])
83 if 1 == move_result[0]:
84 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
85 if ord("%") == world_db["MAP"][pos] or \
86 ord("#") == world_db["MAP"][pos]:
87 if t["T_BOWEL"] >= 32:
88 if t == world_db["Things"][0]:
89 log("You're too FULL to eat.")
91 world_db["Things"][0]["T_ARGUMENT"] = d
92 world_db["set_command"]("move")
94 if chr(world_db["MAP"][pos]) in symbols_passable:
95 world_db["Things"][0]["T_ARGUMENT"] = d
96 world_db["set_command"]("move")
98 log("You CAN'T eat your way through there.")
102 from server.build_fov_map import build_fov_map
103 from server.utils import mv_yx_in_dir_legal, rand
104 from server.config.world_data import directions_db, symbols_passable
106 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
107 t["T_POSY"], t["T_POSX"])
108 if 1 == move_result[0]:
109 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
110 hitted = [tid for tid in world_db["Things"]
111 if world_db["Things"][tid] != t
112 if world_db["Things"][tid]["T_LIFEPOINTS"]
113 if world_db["Things"][tid]["T_POSY"] == move_result[1]
114 if world_db["Things"][tid]["T_POSX"] == move_result[2]]
117 hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
118 if t == world_db["Things"][0]:
119 hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
120 log("You BUMP into " + hitted_name + ".")
122 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
123 log(hitter_name +" BUMPS into you.")
125 passable = chr(world_db["MAP"][pos]) in symbols_passable
126 direction = [direction for direction in directions_db
127 if directions_db[direction] == chr(t["T_ARGUMENT"])][0]
129 t["T_POSY"] = move_result[1]
130 t["T_POSX"] = move_result[2]
131 t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
134 if t["T_BOWEL"] >= 32:
136 elif ord("%") == world_db["MAP"][pos] and 0 == int(rand.next() % 2):
138 world_db["MAP"][pos] = ord("_")
140 elif ord("#") == world_db["MAP"][pos] and 0 == int(rand.next() % 5):
142 world_db["MAP"][pos] = ord("_")
144 if t["T_BOWEL"] > 32:
149 from server.make_map import new_pos, is_neighbor
150 from server.utils import rand
151 world_db["MAP"] = bytearray(b'X' * (world_db["MAP_LENGTH"] ** 2))
152 length = world_db["MAP_LENGTH"]
153 add_half_width = (not (length % 2)) * int(length / 2)
154 world_db["MAP"][int((length ** 2) / 2) + add_half_width] = ord("#")
156 y, x, pos = new_pos()
157 if "X" == chr(world_db["MAP"][pos]) and is_neighbor((y, x), "#"):
158 if y == 0 or y == (length - 1) or x == 0 or x == (length - 1):
160 world_db["MAP"][pos] = ord("#")
161 n_ground = int((length ** 2) / 16)
163 while (i_ground <= n_ground):
164 single_allowed = rand.next() % 32
165 y, x, pos = new_pos()
166 if "#" == chr(world_db["MAP"][pos]) \
167 and ((not single_allowed) or is_neighbor((y, x), "_")):
168 world_db["MAP"][pos] = ord("_")
170 n_water = int((length ** 2) / 64)
172 while (i_water <= n_water):
173 single_allowed = rand.next() % 32
174 y, x, pos = new_pos()
175 if "_" == chr(world_db["MAP"][pos]) \
176 and ((not single_allowed) or is_neighbor((y, x), "~")):
177 world_db["MAP"][pos] = ord("~")
181 def calc_effort(ta, t):
182 from server.utils import mv_yx_in_dir_legal
183 if ta["TA_NAME"] == "move":
184 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
185 t["T_POSY"], t["T_POSX"])
186 if 1 == move_result[0]:
187 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
188 terrain = chr(world_db["MAP"][pos])
194 world_db["calc_effort"] = calc_effort
198 from server.ai import ai
199 from server.config.actions import action_db
200 from server.update_map_memory import update_map_memory
201 from server.io import try_worldstate_update
202 from server.config.io import io_db
203 from server.utils import rand
204 while world_db["Things"][0]["T_LIFEPOINTS"]:
205 for tid in [tid for tid in world_db["Things"]]:
206 if not tid in world_db["Things"]:
208 Thing = world_db["Things"][tid]
209 if Thing["T_LIFEPOINTS"]:
210 if not Thing["T_COMMAND"]:
211 update_map_memory(Thing)
215 if Thing["T_LIFEPOINTS"]:
216 Thing["T_PROGRESS"] += 1
217 taid = [a for a in world_db["ThingActions"]
218 if a == Thing["T_COMMAND"]][0]
219 ThingAction = world_db["ThingActions"][taid]
220 effort = world_db["calc_effort"](ThingAction, Thing)
221 if Thing["T_PROGRESS"] >= effort:
222 action = action_db["actor_" + ThingAction["TA_NAME"]]
224 Thing["T_COMMAND"] = 0
225 Thing["T_PROGRESS"] = 0
226 if Thing["T_BOWEL"] > 16:
227 if 0 == (rand.next() % (33 - Thing["T_BOWEL"])):
228 action_db["actor_drop"](Thing)
229 if Thing["T_BLADDER"] > 16:
230 if 0 == (rand.next() % (33 - Thing["T_BLADDER"])):
231 action_db["actor_pee"](Thing)
232 world_db["TURN"] += 1
233 io_db["worldstate_updateable"] = True
234 try_worldstate_update()
235 world_db["turn_over"] = turn_over
239 """Call ai() on player Thing, then turn_over()."""
240 from server.ai import ai
241 if world_db["WORLD_ACTIVE"]:
242 ai(world_db["Things"][0])
243 world_db["turn_over"]()
246 def set_command(action):
247 """Set player's T_COMMAND, then call turn_over()."""
248 tid = [x for x in world_db["ThingActions"]
249 if world_db["ThingActions"][x]["TA_NAME"] == action][0]
250 world_db["Things"][0]["T_COMMAND"] = tid
251 world_db["turn_over"]()
252 world_db["set_command"] = set_command
256 """Try "wait" as player's T_COMMAND."""
257 if world_db["WORLD_ACTIVE"]:
258 world_db["set_command"]("wait")
261 from server.config.io import io_db
262 io_db["worldstate_write_order"] += [["T_BOWEL", "player_int"]]
263 io_db["worldstate_write_order"] += [["T_BLADDER", "player_int"]]
264 import server.config.world_data
265 server.config.world_data.symbols_hide = "%#X"
266 server.config.world_data.symbols_passable = "_.:~"
267 server.config.world_data.thing_defaults["T_BOWEL"] = 0
268 server.config.world_data.thing_defaults["T_BLADDER"] = 0
269 import server.config.make_world_helpers
270 server.config.make_world_helpers.make_map = make_map
271 from server.config.commands import commands_db
272 commands_db["THINGS_HERE"] = (2, True, lambda x, y: None)
273 commands_db["ai"] = (0, False, command_ai)
274 commands_db["move"] = (1, False, play_move)
275 commands_db["wait"] = (0, False, play_wait)
276 commands_db["drop"] = (0, False, play_drop)
277 commands_db["drink"] = (0, False, play_drink)
278 commands_db["pee"] = (0, False, play_pee)
279 commands_db["use"] = (1, False, lambda x: None)
280 commands_db["pickup"] = (0, False, lambda: None)
281 commands_db["T_BOWEL"] = (1, False, setter("Thing", "T_BOWEL", 0, 255))
282 commands_db["T_BLADDER"] = (1, False, setter("Thing", "T_BLADDER", 0, 255))
283 from server.actions import actor_wait
284 import server.config.actions
285 server.config.actions.action_db = {
286 "actor_wait": actor_wait,
287 "actor_move": actor_move,
288 "actor_drop": actor_drop,
289 "actor_drink": actor_drink,
290 "actor_pee": actor_pee,
293 strong_write(io_db["file_out"], "PLUGIN TheCrawlingEater\n")