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 pos = world_db["Things"][0]["pos"]
12 if not (chr(world_db["MAP"][pos]) == "0"
13 and world_db["wetmap"][pos] > ord("0")):
14 log("NOTHING to drink here.")
16 elif world_db["Things"][0]["T_KIDNEY"] >= 32:
17 log("You're too FULL to drink more.")
19 world_db["set_command"]("drink")
24 if chr(world_db["MAP"][pos]) == "0" and \
25 world_db["wetmap"][pos] > ord("0") and t["T_KIDNEY"] < 32:
26 if world_db["Things"][0] == t:
29 world_db["wetmap"][pos] -= 1
30 if world_db["wetmap"][pos] == ord("0"):
31 world_db["MAP"][pos] = ord("0")
32 elif t == world_db["Things"][0]:
33 log("YOU FAIL TO DRINK " + str(world_db["MAP"][pos] - ord("0")))
37 if action_exists("pee") and world_db["WORLD_ACTIVE"]:
38 if world_db["Things"][0]["T_BLADDER"] < 1:
39 log("Nothing to drop from empty bladder.")
41 world_db["set_command"]("pee")
45 if t["T_BLADDER"] < 1:
47 if t == world_db["Things"][0]:
48 log("You LOSE fluid.")
49 if not world_db["test_air"](t):
52 world_db["wetmap"][t["pos"]] += 1
56 if action_exists("drop") and world_db["WORLD_ACTIVE"]:
57 if world_db["Things"][0]["T_BOWEL"] < 1:
58 log("Nothing to drop from empty bowel.")
60 world_db["set_command"]("drop")
66 if t == world_db["Things"][0]:
67 log("You DROP waste.")
68 if not world_db["test_air"](t):
70 world_db["MAP"][t["pos"]] += 1
74 def play_move(str_arg):
75 """Try "move" as player's T_COMMAND, str_arg as T_ARGUMENT / direction."""
76 if action_exists("move") and world_db["WORLD_ACTIVE"]:
77 from server.config.world_data import directions_db, symbols_passable
78 t = world_db["Things"][0]
79 if not str_arg in directions_db:
80 print("Illegal move direction string.")
82 d = ord(directions_db[str_arg])
83 from server.utils import mv_yx_in_dir_legal
84 move_result = mv_yx_in_dir_legal(chr(d), t["T_POSY"], t["T_POSX"])
85 if 1 == move_result[0]:
86 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
87 hitted = [tid for tid in world_db["Things"]
88 if world_db["Things"][tid]["T_POSY"] == move_result[1]
89 if world_db["Things"][tid]["T_POSX"] == move_result[2]]
91 if t["T_STOMACH"] >= 32 and t["T_KIDNEY"] >= 32:
92 if t == world_db["Things"][0]:
93 log("You're too FULL to suck from another creature.")
95 world_db["Things"][0]["T_ARGUMENT"] = d
96 world_db["set_command"]("eat")
98 if chr(world_db["MAP"][pos]) in "34":
99 if t["T_STOMACH"] >= 32:
100 if t == world_db["Things"][0]:
101 log("You're too FULL to eat.")
103 world_db["Things"][0]["T_ARGUMENT"] = d
104 world_db["set_command"]("eat")
106 if chr(world_db["MAP"][pos]) in symbols_passable:
107 world_db["Things"][0]["T_ARGUMENT"] = d
108 world_db["set_command"]("move")
110 log("You CAN'T eat your way through there.")
114 from server.utils import mv_yx_in_dir_legal, rand
115 from server.config.world_data import symbols_passable
117 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
118 t["T_POSY"], t["T_POSX"])
119 if 1 == move_result[0]:
120 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
121 hitted = [tid for tid in world_db["Things"]
122 if world_db["Things"][tid]["T_POSY"] == move_result[1]
123 if world_db["Things"][tid]["T_POSX"] == move_result[2]]
126 hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
127 if t == world_db["Things"][0]:
128 hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
129 log("You SUCK from " + hitted_name + ".")
131 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
132 log(hitter_name +" SUCKS from you.")
133 hitted = world_db["Things"][hit_id]
134 if t["T_STOMACH"] < 32:
135 t["T_STOMACH"] = t["T_STOMACH"] + 1
136 hitted["T_STOMACH"] -= 1
137 if t["T_KIDNEY"] < 32:
138 t["T_KIDNEY"] = t["T_KIDNEY"] + 1
139 hitted["T_KIDNEY"] -= 1
141 passable = chr(world_db["MAP"][pos]) in symbols_passable
142 if passable and t == world_db["Things"][0]:
143 log("You try to EAT, but fail.")
145 height = world_db["MAP"][pos] - ord("0")
146 if t["T_STOMACH"] >= 32 or height == 5:
149 if t == world_db["Things"][0]:
151 eaten = (height == 3 and 0 == int(rand.next() % 2)) or \
152 (height == 4 and 0 == int(rand.next() % 5))
154 world_db["MAP"][pos] = ord("0")
155 if t["T_STOMACH"] > 32:
160 from server.build_fov_map import build_fov_map
161 from server.utils import mv_yx_in_dir_legal, rand
162 from server.config.world_data import symbols_passable
164 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
165 t["T_POSY"], t["T_POSX"])
166 if 1 == move_result[0]:
167 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
168 hitted = [tid for tid in world_db["Things"]
169 if world_db["Things"][tid]["T_POSY"] == move_result[1]
170 if world_db["Things"][tid]["T_POSX"] == move_result[2]]
173 hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
174 if t == world_db["Things"][0]:
175 hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
176 log("You BUMP into " + hitted_name + ".")
178 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
179 log(hitter_name +" BUMPS into you.")
181 passable = chr(world_db["MAP"][pos]) in symbols_passable
183 t["T_POSY"] = move_result[1]
184 t["T_POSX"] = move_result[2]
185 t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
186 world_db["soundmap"][t["pos"]] = ord("9")
187 elif t == world_db["Things"][0]:
188 log("You try to MOVE there, but fail.")
192 if world_db["MAP"][t["pos"]] == ord("-"):
193 world_db["die"](t, "You FALL in a hole, and die.")
196 world_db["test_hole"] = test_hole
200 if world_db["terrain_fullness"](t["pos"]) > 5:
201 world_db["die"](t, "You SUFFOCATE")
204 world_db["test_air"] = test_air
208 t["T_LIFEPOINTS"] = 0
209 if t == world_db["Things"][0]:
210 t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
211 t["T_MEMMAP"][t["pos"]] = ord("@")
214 world_db["MAP"][t["pos"]] = ord("5")
215 world_db["HUMILITY"] = t["T_KIDNEY"] + t["T_BLADDER"] + \
216 (world_db["wetmap"][t["pos"]] - ord("0"))
217 world_db["wetmap"][t["pos"]] = 0
218 tid = next(tid for tid in world_db["Things"]
219 if world_db["Things"][tid] == t)
220 del world_db["Things"][tid]
221 world_db["die"] = die
225 from server.make_map import new_pos, is_neighbor
226 from server.utils import rand
227 world_db["MAP"] = bytearray(b'5' * (world_db["MAP_LENGTH"] ** 2))
228 length = world_db["MAP_LENGTH"]
229 add_half_width = (not (length % 2)) * int(length / 2)
230 world_db["MAP"][int((length ** 2) / 2) + add_half_width] = ord("4")
232 y, x, pos = new_pos()
233 if "5" == chr(world_db["MAP"][pos]) and is_neighbor((y, x), "4"):
234 if y == 0 or y == (length - 1) or x == 0 or x == (length - 1):
236 world_db["MAP"][pos] = ord("4")
237 n_ground = int((length ** 2) / 16)
239 while (i_ground <= n_ground):
240 single_allowed = rand.next() % 32
241 y, x, pos = new_pos()
242 if "4" == chr(world_db["MAP"][pos]) \
243 and ((not single_allowed) or is_neighbor((y, x), "0")):
244 world_db["MAP"][pos] = ord("0")
246 n_water = int((length ** 2) / 32)
248 while (i_water <= n_water):
249 y, x, pos = new_pos()
250 if ord("0") == world_db["MAP"][pos] and \
251 ord("0") == world_db["wetmap"][pos]:
252 world_db["wetmap"][pos] = ord("3")
256 def calc_effort(ta, t):
257 from server.utils import mv_yx_in_dir_legal
258 if ta["TA_NAME"] == "move":
259 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
260 t["T_POSY"], t["T_POSX"])
261 if 1 == move_result[0]:
262 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
263 narrowness = world_db["MAP"][pos] - ord("0")
264 return 2 ** narrowness
266 world_db["calc_effort"] = calc_effort
270 from server.ai import ai
271 from server.config.actions import action_db
272 from server.update_map_memory import update_map_memory
273 from server.io import try_worldstate_update
274 from server.config.io import io_db
275 from server.utils import rand
276 from server.build_fov_map import build_fov_map
277 while world_db["Things"][0]["T_LIFEPOINTS"]:
278 for tid in [tid for tid in world_db["Things"]]:
279 if not tid in world_db["Things"]:
281 t = world_db["Things"][tid]
282 if t["T_LIFEPOINTS"]:
283 if not (world_db["test_air"](t) and world_db["test_hole"](t)):
285 if not t["T_COMMAND"]:
291 if t["T_LIFEPOINTS"]:
293 taid = [a for a in world_db["ThingActions"]
294 if a == t["T_COMMAND"]][0]
295 ThingAction = world_db["ThingActions"][taid]
296 effort = world_db["calc_effort"](ThingAction, t)
297 if t["T_PROGRESS"] >= effort:
298 action = action_db["actor_" + ThingAction["TA_NAME"]]
302 if t["T_BOWEL"] > 16:
303 if 0 == (rand.next() % (33 - t["T_BOWEL"])):
304 action_db["actor_drop"](t)
305 if t["T_BLADDER"] > 16:
306 if 0 == (rand.next() % (33 - t["T_BLADDER"])):
307 action_db["actor_pee"](t)
308 if 0 == world_db["TURN"] % 5:
313 if t["T_STOMACH"] <= 0:
314 world_db["die"](t, "You DIE of hunger.")
315 elif t["T_KIDNEY"] <= 0:
316 world_db["die"](t, "You DIE of dehydration.")
317 for pos in range(world_db["MAP_LENGTH"] ** 2):
318 wetness = world_db["wetmap"][pos] - ord("0")
319 height = world_db["MAP"][pos] - ord("0")
320 if height == 0 and wetness > 0 \
321 and 0 == rand.next() % ((2 ** 13) / (2 ** wetness)):
322 world_db["MAP"][pos] = ord("-")
323 if ((wetness > 0 and height != 0) or wetness > 1) \
324 and 0 == rand.next() % 5:
325 world_db["wetmap"][pos] -= 1
326 world_db["HUMIDITY"] += 1
327 if world_db["HUMIDITY"] > 0:
328 if world_db["HUMIDITY"] > 2 and 0 == rand.next() % 2:
329 world_db["NEW_SPAWN"] += 1
330 world_db["HUMIDITY"] -= 1
331 if world_db["NEW_SPAWN"] >= 16:
332 world_db["NEW_SPAWN"] -= 16
333 from server.new_thing import new_Thing
335 y = rand.next() % world_db["MAP_LENGTH"]
336 x = rand.next() % world_db["MAP_LENGTH"]
337 if chr(world_db["MAP"][y * world_db["MAP_LENGTH"] + x]) !=\
339 from server.utils import id_setter
340 tid = id_setter(-1, "Things")
341 world_db["Things"][tid] = new_Thing(
342 world_db["PLAYER_TYPE"], (y, x))
343 pos = y * world_db["MAP_LENGTH"] + x
345 positions_to_wet = []
346 for pos in range(world_db["MAP_LENGTH"] ** 2):
347 if world_db["MAP"][pos] == ord("0") \
348 and world_db["wetmap"][pos] < ord("5"):
349 positions_to_wet += [pos]
350 while world_db["HUMIDITY"] > 0 and len(positions_to_wet) > 0:
351 select = rand.next() % len(positions_to_wet)
352 pos = positions_to_wet[select]
353 world_db["wetmap"][pos] += 1
354 positions_to_wet.remove(pos)
355 world_db["HUMIDITY"] -= 1
356 for pos in range(world_db["MAP_LENGTH"] ** 2):
357 if world_db["soundmap"][pos] > ord("0"):
358 world_db["soundmap"][pos] -= 1
359 world_db["TURN"] += 1
360 io_db["worldstate_updateable"] = True
361 try_worldstate_update()
362 world_db["turn_over"] = turn_over
366 """Call ai() on player Thing, then turn_over()."""
367 from server.ai import ai
368 if world_db["WORLD_ACTIVE"]:
369 ai(world_db["Things"][0])
370 world_db["turn_over"]()
373 def set_command(action):
374 """Set player's T_COMMAND, then call turn_over()."""
375 tid = [x for x in world_db["ThingActions"]
376 if world_db["ThingActions"][x]["TA_NAME"] == action][0]
377 world_db["Things"][0]["T_COMMAND"] = tid
378 world_db["turn_over"]()
379 world_db["set_command"] = set_command
383 """Try "wait" as player's T_COMMAND."""
384 if world_db["WORLD_ACTIVE"]:
385 world_db["set_command"]("wait")
389 length = world_db["MAP_LENGTH"]
391 for i in range(length):
392 line = world_db["wetmap"][i * length:(i * length) + length].decode()
393 string = string + "WETMAP" + " " + str(i) + " " + line + "\n"
394 for i in range(length):
395 line = world_db["soundmap"][i * length:(i * length) + length].decode()
396 string = string + "SOUNDMAP" + " " + str(i) + " " + line + "\n"
400 def soundmapset(str_int, mapline):
401 def valid_map_line(str_int, mapline):
402 from server.utils import integer_test
403 val = integer_test(str_int, 0, 255)
405 if val >= world_db["MAP_LENGTH"]:
406 print("Illegal value for map line number.")
407 elif len(mapline) != world_db["MAP_LENGTH"]:
408 print("Map line length is unequal map width.")
412 val = valid_map_line(str_int, mapline)
414 length = world_db["MAP_LENGTH"]
415 if not world_db["soundmap"]:
416 m = bytearray(b' ' * (length ** 2))
418 m = world_db["soundmap"]
419 m[val * length:(val * length) + length] = mapline.encode()
420 if not world_db["soundmap"]:
421 world_db["soundmap"] = m
424 def wetmapset(str_int, mapline):
425 def valid_map_line(str_int, mapline):
426 from server.utils import integer_test
427 val = integer_test(str_int, 0, 255)
429 if val >= world_db["MAP_LENGTH"]:
430 print("Illegal value for map line number.")
431 elif len(mapline) != world_db["MAP_LENGTH"]:
432 print("Map line length is unequal map width.")
436 val = valid_map_line(str_int, mapline)
438 length = world_db["MAP_LENGTH"]
439 if not world_db["wetmap"]:
440 m = bytearray(b' ' * (length ** 2))
442 m = world_db["wetmap"]
443 m[val * length:(val * length) + length] = mapline.encode()
444 if not world_db["wetmap"]:
445 world_db["wetmap"] = m
448 def write_soundmap():
449 from server.worldstate_write_helpers import write_map
450 length = world_db["MAP_LENGTH"]
451 return write_map(world_db["soundmap"], world_db["MAP_LENGTH"])
455 from server.worldstate_write_helpers import write_map
456 length = world_db["MAP_LENGTH"]
457 visible_wetmap = bytearray(b' ' * (length ** 2))
458 for i in range(length ** 2):
459 if world_db["Things"][0]["fovmap"][i] == ord('v'):
460 visible_wetmap[i] = world_db["wetmap"][i]
461 return write_map(visible_wetmap, world_db["MAP_LENGTH"])
465 if world_db["WORLD_ACTIVE"]:
466 world_db["ai"](world_db["Things"][0])
467 world_db["turn_over"]()
470 def get_dir_to_target(t, target):
472 from server.utils import rand, libpr, c_pointer_to_bytearray
473 from server.config.world_data import symbols_passable
475 def get_map_score(pos):
476 result = libpr.get_map_score(pos)
478 raise RuntimeError("No score map allocated for get_map_score().")
481 def zero_score_map_where_char_on_memdepthmap(c):
482 map = c_pointer_to_bytearray(t["T_MEMDEPTHMAP"])
483 if libpr.zero_score_map_where_char_on_memdepthmap(c, map):
484 raise RuntimeError("No score map allocated for "
485 "zero_score_map_where_char_on_memdepthmap().")
487 def set_map_score(pos, score):
488 test = libpr.set_map_score(pos, score)
490 raise RuntimeError("No score map allocated for set_map_score().")
492 def set_movement_cost_map():
493 memmap = c_pointer_to_bytearray(t["T_MEMMAP"])
494 if libpr.TCE_set_movement_cost_map(memmap):
495 raise RuntimeError("No movement cost map allocated for "
496 "set_movement_cost_map().")
498 def animates_in_fov(maplength):
499 return [Thing for Thing in world_db["Things"].values()
500 if Thing["T_LIFEPOINTS"] and 118 == t["fovmap"][Thing["pos"]]
501 and (not Thing == t)]
507 except StopIteration:
510 mapsize = world_db["MAP_LENGTH"] ** 2
511 if target == "food" and t["T_MEMMAP"]:
512 return exists(pos for pos in range(mapsize)
513 if ord("2") < t["T_MEMMAP"][pos] < ord("5"))
514 elif target == "fluid_certain" and t["fovmap"]:
515 return exists(pos for pos in range(mapsize)
516 if t["fovmap"] == ord("v")
517 if world_db["MAP"][pos] == ord("0")
518 if world_db["wetmap"][pos] > ord("0"))
519 elif target == "fluid_potential" and t["T_MEMMAP"] and t["fovmap"]:
520 return exists(pos for pos in range(mapsize)
521 if t["T_MEMMAP"][pos] == ord("0")
522 if t["fovmap"] != ord("v"))
523 elif target == "space" and t["T_MEMMAP"] and t["fovmap"]:
524 return exists(pos for pos in range(mapsize)
525 if ord("0") <= t["T_MEMMAP"][pos] <= ord("2")
526 if (t["fovmap"] != ord("v")
527 or world_db["terrain_fullness"](pos) < 5))
528 elif target in {"hunt", "flee"} and t["fovmap"]:
529 return exists(Thing for
530 Thing in animates_in_fov(world_db["MAP_LENGTH"]))
533 def init_score_map():
534 test = libpr.init_score_map()
535 set_movement_cost_map()
536 mapsize = world_db["MAP_LENGTH"] ** 2
538 raise RuntimeError("Malloc error in init_score_map().")
539 if target == "food" and t["T_MEMMAP"]:
540 [set_map_score(pos, 0) for pos in range(mapsize)
541 if ord("2") < t["T_MEMMAP"][pos] < ord("5")]
542 elif target == "fluid_certain" and t["fovmap"]:
543 [set_map_score(pos, 0) for pos in range(mapsize)
544 if t["fovmap"] == ord("v")
545 if world_db["MAP"][pos] == ord("0")
546 if world_db["wetmap"][pos] > ord("0")]
547 elif target == "fluid_potential" and t["T_MEMMAP"] and t["fovmap"]:
548 [set_map_score(pos, 0) for pos in range(mapsize)
549 if t["T_MEMMAP"][pos] == ord("0")
550 if t["fovmap"] != ord("v")]
551 elif target == "space" and t["T_MEMMAP"] and t["fovmap"]:
552 [set_map_score(pos, 0) for pos in range(mapsize)
553 if ord("0") <= t["T_MEMMAP"][pos] <= ord("2")
554 if (t["fovmap"] != ord("v")
555 or world_db["terrain_fullness"](pos) < 5)]
556 elif target == "search":
557 zero_score_map_where_char_on_memdepthmap(mem_depth_c[0])
558 elif target in {"hunt", "flee"}:
559 [set_map_score(Thing["pos"], 0) for
560 Thing in animates_in_fov(world_db["MAP_LENGTH"])]
562 def rand_target_dir(neighbors, cmp, dirs):
565 for i in range(len(dirs)):
566 if cmp == neighbors[i]:
567 candidates.append(dirs[i])
569 return candidates[rand.next() % n_candidates] if n_candidates else 0
571 def get_neighbor_scores(dirs, eye_pos):
573 if libpr.ready_neighbor_scores(eye_pos):
574 raise RuntimeError("No score map allocated for " +
575 "ready_neighbor_scores.()")
576 for i in range(len(dirs)):
577 scores.append(libpr.get_neighbor_score(i))
580 def get_dir_from_neighbors():
582 dir_to_target = False
585 neighbors = get_neighbor_scores(dirs, eye_pos)
586 minmax_start = 0 if "flee" == target else 65535 - 1
587 minmax_neighbor = minmax_start
588 for i in range(len(dirs)):
589 if ("flee" == target and get_map_score(t["pos"]) < neighbors[i] and
590 minmax_neighbor < neighbors[i] and 65535 != neighbors[i]) \
591 or ("flee" != target and minmax_neighbor > neighbors[i]):
592 minmax_neighbor = neighbors[i]
593 if minmax_neighbor != minmax_start:
594 dir_to_target = rand_target_dir(neighbors, minmax_neighbor, dirs)
596 distance = get_map_score(t["pos"])
599 if not dir_to_target:
600 if attack_distance >= distance:
601 dir_to_target = rand_target_dir(neighbors,
603 elif dir_to_target and fear_distance < distance:
605 return dir_to_target, minmax_neighbor
607 dir_to_target = False
609 run_i = 9 + 1 if "search" == target else 1
611 while run_i and not dir_to_target and \
612 ("search" == target or seeing_thing()):
615 mem_depth_c = b'9' if b' ' == mem_depth_c \
616 else bytes([mem_depth_c[0] - 1])
617 if libpr.TCE_dijkstra_map_with_movement_cost():
618 raise RuntimeError("No score map allocated for dijkstra_map().")
619 dir_to_target, minmax_neighbor = get_dir_from_neighbors()
620 libpr.free_score_map()
621 if dir_to_target and str == type(dir_to_target):
623 from server.utils import mv_yx_in_dir_legal
624 move_result = mv_yx_in_dir_legal(dir_to_target, t["T_POSY"],
626 if 1 != move_result[0]:
628 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
629 hitted = [tid for tid in world_db["Things"]
630 if world_db["Things"][tid]["pos"] == pos]
631 if world_db["MAP"][pos] > ord("2") or len(hitted) > 0:
633 t["T_COMMAND"] = [taid for taid in world_db["ThingActions"]
634 if world_db["ThingActions"][taid]["TA_NAME"]
636 t["T_ARGUMENT"] = ord(dir_to_target)
637 return dir_to_target, minmax_neighbor
638 world_db["get_dir_to_target"] = get_dir_to_target
641 def terrain_fullness(pos):
642 return (world_db["MAP"][pos] - ord("0")) + \
643 (world_db["wetmap"][pos] - ord("0"))
644 world_db["terrain_fullness"] = terrain_fullness
649 if t["T_LIFEPOINTS"] == 0:
652 def standing_on_fluid(t):
653 if world_db["MAP"][t["pos"]] == ord("0") and \
654 world_db["wetmap"][t["pos"]] > ord("0"):
659 def thing_action_id(name):
660 return [taid for taid in world_db["ThingActions"]
661 if world_db["ThingActions"][taid]
662 ["TA_NAME"] == name][0]
664 t["T_COMMAND"] = thing_action_id("wait")
667 "safe_pee": (world_db["terrain_fullness"](t["pos"]) * t["T_BLADDER"]) / 4,
668 "safe_drop": (world_db["terrain_fullness"](t["pos"]) * t["T_BOWEL"]) / 4,
669 "food": 33 - t["T_STOMACH"],
670 "fluid_certain": 33 - t["T_KIDNEY"],
671 "fluid_potential": 32 - t["T_KIDNEY"],
674 from operator import itemgetter
675 needs = sorted(needs.items(), key=itemgetter(1,0))
679 if need[0] in {"fluid_certain", "fluid_potential"}:
680 if standing_on_fluid(t):
681 t["T_COMMAND"] = thing_action_id("drink")
683 elif t["T_BLADDER"] > 0 and \
684 world_db["MAP"][t["pos"]] == ord("0"):
685 t["T_COMMAND"] = thing_action_id("pee")
687 elif need[0] in {"safe_pee", "safe_drop"}:
688 action_name = need[0][len("safe_"):]
689 if world_db["terrain_fullness"](t["pos"]) < 4:
690 t["T_COMMAND"] = thing_action_id(action_name)
693 test = world_db["get_dir_to_target"](t, "space")
695 if (not test[1] < 5) and \
696 world_db["terrain_fullness"](t["pos"]) < 5:
697 t["T_COMMAND"] = thing_action_id(action_name)
699 if t["T_STOMACH"] < 32 and \
700 world_db["get_dir_to_target"](t, "food")[0]:
703 if need[0] in {"fluid_certain", "fluid_potential", "food"}:
704 if world_db["get_dir_to_target"](t, need[0])[0]:
706 elif world_db["get_dir_to_target"](t, "hunt")[0]:
708 elif need[0] != "food" and t["T_STOMACH"] < 32 and \
709 world_db["get_dir_to_target"](t, "food")[0]:
711 elif world_db["get_dir_to_target"](t, need[0])[0]:
716 from server.config.io import io_db
717 io_db["worldstate_write_order"] += [["T_STOMACH", "player_int"]]
718 io_db["worldstate_write_order"] += [["T_KIDNEY", "player_int"]]
719 io_db["worldstate_write_order"] += [["T_BOWEL", "player_int"]]
720 io_db["worldstate_write_order"] += [["T_BLADDER", "player_int"]]
721 io_db["worldstate_write_order"] += [[write_wetmap, "func"]]
722 io_db["worldstate_write_order"] += [[write_soundmap, "func"]]
723 import server.config.world_data
724 server.config.world_data.symbols_hide = "345"
725 server.config.world_data.symbols_passable = "012-"
726 server.config.world_data.thing_defaults["T_STOMACH"] = 16
727 server.config.world_data.thing_defaults["T_BOWEL"] = 0
728 server.config.world_data.thing_defaults["T_KIDNEY"] = 16
729 server.config.world_data.thing_defaults["T_BLADDER"] = 0
730 world_db["soundmap"] = bytearray(b"0" * world_db["MAP_LENGTH"] ** 2)
731 world_db["wetmap"] = bytearray(b"0" * world_db["MAP_LENGTH"] ** 2)
732 if not "NEW_SPAWN" in world_db:
733 world_db["NEW_SPAWN"] = 0
734 if not "HUMIDITY" in world_db:
735 world_db["HUMIDITY"] = 0
736 io_db["hook_save"] = save_maps
737 import server.config.make_world_helpers
738 server.config.make_world_helpers.make_map = make_map
739 from server.config.commands import commands_db
740 commands_db["THINGS_HERE"] = (2, True, lambda x, y: None)
741 commands_db["ai"] = (0, False, command_ai)
742 commands_db["move"] = (1, False, play_move)
743 commands_db["eat"] = (1, False, play_move)
744 commands_db["wait"] = (0, False, play_wait)
745 commands_db["drop"] = (0, False, play_drop)
746 commands_db["drink"] = (0, False, play_drink)
747 commands_db["pee"] = (0, False, play_pee)
748 commands_db["use"] = (1, False, lambda x: None)
749 commands_db["pickup"] = (0, False, lambda: None)
750 commands_db["NEW_SPAWN"] = (1, False, setter(None, "NEW_SPAWN", 0, 255))
751 commands_db["HUMIDITY"] = (1, False, setter(None, "HUMIDITY", 0, 65535))
752 commands_db["T_STOMACH"] = (1, False, setter("Thing", "T_STOMACH", 0, 255))
753 commands_db["T_KIDNEY"] = (1, False, setter("Thing", "T_KIDNEY", 0, 255))
754 commands_db["T_BOWEL"] = (1, False, setter("Thing", "T_BOWEL", 0, 255))
755 commands_db["T_BLADDER"] = (1, False, setter("Thing", "T_BLADDER", 0, 255))
756 commands_db["WETMAP"] = (2, False, wetmapset)
757 commands_db["SOUNDMAP"] = (2, False, soundmapset)
758 from server.actions import actor_wait
759 import server.config.actions
760 server.config.actions.action_db = {
761 "actor_wait": actor_wait,
762 "actor_move": actor_move,
763 "actor_drop": actor_drop,
764 "actor_drink": actor_drink,
765 "actor_pee": actor_pee,
766 "actor_eat": actor_eat,
769 strong_write(io_db["file_out"], "PLUGIN TheCrawlingEater\n")