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.io import log, strong_write
7 from server.config.world_data import world_db, directions_db
8 from server.utils import mv_yx_in_dir_legal, rand, id_setter
9 from server.config.io import io_db
11 def pos_test(type, y, x):
12 pos = y * world_db["MAP_LENGTH"] + x;
13 plant = world_db["ThingTypes"][type]["TT_PROLIFERATE"]
14 return (not plant or ":" == chr(world_db["MAP"][pos]))
17 from server.world_makable import world_makable
18 playertype = world_makable()
19 for name in world_db["specials"]:
20 if world_db[name] not in world_db["ThingTypes"]:
21 print("Ignoring: No valid " + name + " set.")
26 from server.make_map import make_map, is_neighbor, new_pos
29 length = world_db["MAP_LENGTH"]
30 n_colons = int((length ** 2) / 16)
32 while (i_colons <= n_colons):
33 single_allowed = rand.next() % 256
35 if ("." == chr(world_db["MAP"][pos])
36 and ((not single_allowed) or is_neighbor((y, x), ":"))):
37 world_db["MAP"][pos] = ord(":")
40 while not altar_placed:
42 if (("." == chr(world_db["MAP"][pos]
43 or ":" == chr(world_db["MAP"][pos]))
44 and not is_neighbor((y, x), "X"))):
45 world_db["MAP"][pos] = ord("_")
46 world_db["altar"] = (y, x)
49 def field_spreadable(c, t):
50 return ":" == c or (world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]
53 def thingprol_plugin_conditions(t):
54 tt = world_db["ThingTypes"][t["T_TYPE"]]
55 return (tt["TT_LIFEPOINTS"] == 0 or \
56 t["T_LIFEPOINTS"] >= 0.9 * tt["TT_LIFEPOINTS"])
58 def thingprol_plugin_post_create_hook(t):
59 tt = world_db["ThingTypes"][t["T_TYPE"]]
60 if (world_db["FAVOR_STAGE"] > 0 and t["T_TYPE"] == world_db["PLANT_0"]):
61 world_db["GOD_FAVOR"] += 5
62 elif t["T_TYPE"] == world_db["PLANT_1"]:
63 world_db["GOD_FAVOR"] += 25
64 elif world_db["FAVOR_STAGE"] >= 4 and t["T_TYPE"] == world_db["ANIMAL_1"]:
65 log("The Island God SMILES upon a new-born bear baby.")
66 world_db["GOD_FAVOR"] += 750
69 from server.ai import get_dir_to_target, get_inventory_slot_to_consume, \
71 t["T_COMMAND"] = [id for id in world_db["ThingActions"]
72 if world_db["ThingActions"][id]["TA_NAME"] == "wait"][0]
73 eating = len([id for id in world_db["ThingActions"]
74 if world_db["ThingActions"][id]["TA_NAME"] == "use"]) > 0
75 picking = len([id for id in world_db["ThingActions"]
76 if world_db["ThingActions"][id]["TA_NAME"] == "pickup"]) > 0
77 if eating and picking:
78 if get_dir_to_target(t, "f"):
80 sel = get_inventory_slot_to_consume(t)
82 t["T_COMMAND"] = [id for id in world_db["ThingActions"]
83 if world_db["ThingActions"][id]["TA_NAME"]
86 elif standing_on_food(t) and (len(t["T_CARRIES"]) <
87 world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]):
88 t["T_COMMAND"] = [id for id in world_db["ThingActions"]
89 if world_db["ThingActions"][id]["TA_NAME"]
92 going_to_known_food_spot = get_dir_to_target(t, "c")
93 if not going_to_known_food_spot:
94 aiming_for_walking_food = get_dir_to_target(t, "a")
95 if not aiming_for_walking_food:
96 get_dir_to_target(t, "s")
99 from server.ai import eat_vs_hunger_threshold
100 used_slots = len(t["T_CARRIES"])
101 if used_slots < world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]:
102 ids = [id for id in world_db["Things"] if world_db["Things"][id] != t
103 if not world_db["Things"][id]["carried"]
104 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
105 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
108 eat_cost = eat_vs_hunger_threshold(t["T_TYPE"])
110 tid = world_db["Things"][iid]["T_TYPE"]
111 if lowest_tid == -1 or tid < lowest_tid:
112 if (t != world_db["Things"][0] and
113 (world_db["ThingTypes"][tid]["TT_TOOL"] != "food"
114 or (world_db["ThingTypes"][tid]["TT_TOOLPOWER"]
119 world_db["Things"][id]["carried"] = True
120 ty = world_db["Things"][id]["T_TYPE"]
121 if (t != world_db["Things"][0]
122 and world_db["Things"][id]["T_PLAYERDROP"]
123 and world_db["ThingTypes"][ty]["TT_TOOL"] == "food"):
124 score = int(world_db["ThingTypes"][ty]["TT_TOOLPOWER"] / 32)
125 world_db["GOD_FAVOR"] += score
126 world_db["Things"][id]["T_PLAYERDROP"] = 0
127 t["T_CARRIES"].append(id)
128 if t == world_db["Things"][0]:
129 log("You PICK UP an object.")
130 elif t == world_db["Things"][0]:
131 log("CAN'T pick up object: No storage room to carry more.")
135 """Make t rop Thing from inventory to ground indexed by T_ARGUMENT."""
136 if len(t["T_CARRIES"]):
137 id = t["T_CARRIES"][t["T_ARGUMENT"]]
138 t["T_CARRIES"].remove(id)
139 world_db["Things"][id]["carried"] = False
140 if t == world_db["Things"][0]:
141 log("You DROP an object.")
142 world_db["Things"][id]["T_PLAYERDROP"] = 1
146 if len(t["T_CARRIES"]):
147 id = t["T_CARRIES"][t["T_ARGUMENT"]]
148 type = world_db["Things"][id]["T_TYPE"]
149 if type == world_db["SLIPPERS"]:
150 if t == world_db["Things"][0]:
151 log("You use the " + world_db["ThingTypes"][type]["TT_NAME"] +
152 ". It glows in wondrous colors, and emits a sound as if fr"
153 "om a dying cat. The Island God laughs.\n")
154 t["T_LIFEPOINTS"] = 1
155 from server.config.misc import decrement_lifepoints_func
156 decrement_lifepoints_func(t)
157 elif (world_db["ThingTypes"][type]["TT_TOOL"] == "carpentry"):
158 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
159 if (world_db["MAP"][pos] == ord("X")
160 or world_db["MAP"][pos] == ord("|")):
162 for id in [id for id in world_db["Things"]
163 if not world_db["Things"][id] == t
164 if not world_db["Things"][id]["carried"]
165 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
166 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]:
169 for id in t["T_CARRIES"]:
170 type_material = world_db["Things"][id]["T_TYPE"]
171 if (world_db["ThingTypes"][type_material]["TT_TOOL"]
176 t["T_CARRIES"].remove(wood_id)
177 del world_db["Things"][wood_id]
178 world_db["MAP"][pos] = ord("|")
179 log("With your " + world_db["ThingTypes"][type]["TT_NAME"]
180 + " you build a WOODEN BARRIER from your "
181 + world_db["ThingTypes"][type_material]["TT_NAME"] + ".")
182 elif world_db["ThingTypes"][type]["TT_TOOL"] == "fertilizer":
183 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
184 if world_db["MAP"][pos] == ord("."):
185 log("You create SOIL.")
186 world_db["MAP"][pos] = ord(":")
187 elif world_db["ThingTypes"][type]["TT_TOOL"] == "food":
188 t["T_CARRIES"].remove(id)
189 del world_db["Things"][id]
190 t["T_SATIATION"] += world_db["ThingTypes"][type]["TT_TOOLPOWER"]
191 if t == world_db["Things"][0]:
192 log("You CONSUME this thing.")
193 elif t == world_db["Things"][0]:
194 log("You try to use this object, but FAIL.")
196 def decrement_lifepoints(t):
197 t["T_LIFEPOINTS"] -= 1
198 live_type = t["T_TYPE"]
199 _id = [_id for _id in world_db["Things"] if world_db["Things"][_id] == t][0]
200 if 0 == t["T_LIFEPOINTS"]:
201 for id in t["T_CARRIES"]:
202 t["T_CARRIES"].remove(id)
203 world_db["Things"][id]["T_POSY"] = t["T_POSY"]
204 world_db["Things"][id]["T_POSX"] = t["T_POSX"]
205 world_db["Things"][id]["carried"] = False
206 t["T_TYPE"] = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"]
207 if world_db["Things"][0] == t:
208 t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
210 log("See README on how to start over.")
213 t["T_MEMMAP"] = False
214 t["T_MEMDEPTHMAP"] = False
216 n_species = len([id for id in world_db["Things"]
217 if world_db["Things"][id]["T_TYPE"] == live_type])
219 from server.new_thing import new_Thing
220 if world_db["FAVOR_STAGE"] >= 3 and \
221 live_type == world_db["ANIMAL_0"]:
222 world_db["GOD_FAVOR"] += 3000
223 log("CONGRATULATIONS! The "
224 + world_db["ThingTypes"][live_type]["TT_NAME"]
225 + " species has died out. The Island God is pleased.")
227 id = id_setter(-1, "Things")
228 world_db["Things"][id] = new_Thing(live_type,
231 + world_db["ThingTypes"][live_type]["TT_NAME"]
232 + " species has temporarily died out. "
233 + "One new-born is spawned at the altar.")
234 return world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]
239 def altar_msg_wait(limit):
240 log("The Island God will talk again when it favors you to >=" +
241 str(limit) + " points.")
243 altar_msg_0 = "The Island God speaks to you: \"I don't trust you. You in" \
244 "trude on the island's affairs. I think you're a nuisance at best, and a" \
245 " danger to my children at worst. I will give you a chance to lighten my" \
246 " mood, however: For a while now, I've been trying to spread the plant " \
247 + world_db["ThingTypes"][world_db["PLANT_0"]]["TT_NAME"] + " (\"" + \
248 world_db["ThingTypes"][world_db["PLANT_0"]]["TT_SYMBOL"] + "\"). I have " \
249 "not been very successful so far. Maybe you can make yourself useful the" \
250 "re. I will count each further " + \
251 world_db["ThingTypes"][world_db["PLANT_0"]]["TT_NAME"] + " that grows to" \
254 altar_msg_1 = "The Island God speaks to you: \"You could have done worse" \
255 " so far. Maybe you are not the worst to happen to this island since the" \
256 " metal birds threw the great lightning ball. Maybe you can help me spre" \
257 "ad another plant. It multiplies faster,and it is highly nutritious: " + \
258 world_db["ThingTypes"][world_db["PLANT_1"]]["TT_NAME"] + " (\"" + \
259 world_db["ThingTypes"][world_db["PLANT_1"]]["TT_SYMBOL"] + "\"). It is n" \
260 "ew. I give you the only example. Be very careful with it! I also give y" \
261 "ou another tool that may be helpful.\""
263 altar_msg_2 = "The Island God speaks to you: \"I am greatly disappointed" \
264 " that you lost all " + \
265 world_db["ThingTypes"][world_db["PLANT_1"]]["TT_NAME"] + " this island h" \
266 "ad. Here is another one. It cost me great work. Be more careful this ti" \
267 "me when planting it.\""
269 altar_msg_3 = "The Island God speaks to you: \"The " + \
270 world_db["ThingTypes"][world_db["ANIMAL_0"]]["TT_NAME"] + " has lately b" \
271 "ecome a pest. These creatures do not please me as much as they used to " \
272 "do. Exterminate them all. I will count each kill to your favor. To help" \
273 " you with the hunting, I grant you the empathy and knowledge to read an" \
276 altar_msg_4 = "You will now see animals' health bars, and activities (\"" \
277 "m\": moving (maybe for an attack), \"u\": eating, \"p\": picking someth" \
278 "ing up; no letter: waiting)."
280 altar_msg_5 = "The Island God speaks to you: \"You know what animal I fi" \
281 "nd the cutest? The " + \
282 world_db["ThingTypes"][world_db["ANIMAL_1"]]["TT_NAME"] + "! I think wha" \
283 "t this islands clearly needs more of is " + \
284 world_db["ThingTypes"][world_db["ANIMAL_1"]]["TT_NAME"] + "s. Why don't " \
285 "you help? Support them. Make sure they are well, and they will multiply" \
286 " faster. From now on, I will count each new-born " + \
287 world_db["ThingTypes"][world_db["ANIMAL_1"]]["TT_NAME"] + \
288 " (not spawned by me due to undo an extinction event) greatly to your fa" \
289 "vor. To help you with the feeding, here is something to make the ground" \
290 " bear more consumables."
292 altar_msg_6 = "The Island God speaks to you: \"You have proven yourself " \
293 "worthy of my respect. You were a good citizen to the island, and someti" \
294 "mes a better steward to its inhabitants than me. The island shall miss " \
295 "you when you leave. But you have earned the right to do so. Take this" + \
296 world_db["ThingTypes"][world_db["SLIPPERS"]]["TT_NAME"] + " and USE it w" \
297 "hen you please. It will take you to where you came from. (But do feel f" \
298 "ree to stay here as long as you like.)\""
301 from server.new_thing import new_Thing
302 if world_db["FAVOR_STAGE"] > 9000:
303 log("You step on a soul-less slab of stone.")
305 log("YOU ENTER SACRED GROUND.")
306 if world_db["FAVOR_STAGE"] == 0:
307 world_db["FAVOR_STAGE"] = 1
309 elif world_db["FAVOR_STAGE"] == 1 and world_db["GOD_FAVOR"] < 100:
311 elif world_db["FAVOR_STAGE"] == 1 and world_db["GOD_FAVOR"] >= 100:
312 world_db["FAVOR_STAGE"] = 2
314 id = id_setter(-1, "Things")
315 world_db["Things"][id] = new_Thing(world_db["PLANT_1"],
317 id = id_setter(-1, "Things")
318 world_db["Things"][id] = new_Thing(world_db["TOOL_0"],
320 elif world_db["FAVOR_STAGE"] == 2 and \
321 0 == len([id for id in world_db["Things"]
322 if world_db["Things"][id]["T_TYPE"]
323 == world_db["PLANT_1"]]):
325 id = id_setter(-1, "Things")
326 world_db["Things"][id] = new_Thing(world_db["PLANT_1"],
328 world_db["GOD_FAVOR"] -= 250
329 elif world_db["FAVOR_STAGE"] == 2 and world_db["GOD_FAVOR"] < 500:
331 elif world_db["FAVOR_STAGE"] == 2 and world_db["GOD_FAVOR"] >= 500:
332 world_db["FAVOR_STAGE"] = 3
335 world_db["EMPATHY"] = 1
336 elif world_db["FAVOR_STAGE"] == 3 and world_db["GOD_FAVOR"] < 5000:
338 elif world_db["FAVOR_STAGE"] == 3 and world_db["GOD_FAVOR"] >= 5000:
339 world_db["FAVOR_STAGE"] = 4
341 id = id_setter(-1, "Things")
342 world_db["Things"][id] = new_Thing(world_db["TOOL_1"],
344 elif world_db["GOD_FAVOR"] < 20000:
345 altar_msg_wait(20000)
346 elif world_db["GOD_FAVOR"] > 20000:
347 world_db["FAVOR_STAGE"] = 9001
349 id = id_setter(-1, "Things")
350 world_db["Things"][id] = new_Thing(world_db["SLIPPERS"],
353 from server.config.world_data import symbols_passable
354 from server.build_fov_map import build_fov_map
355 from server.config.misc import decrement_lifepoints_func
356 from server.new_thing import new_Thing
357 global mv_yx_in_dir_legal
359 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
360 t["T_POSY"], t["T_POSX"])
361 if 1 == move_result[0]:
362 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
363 hitted = [id for id in world_db["Things"]
364 if world_db["Things"][id] != t
365 if world_db["Things"][id]["T_LIFEPOINTS"]
366 if world_db["Things"][id]["T_POSY"] == move_result[1]
367 if world_db["Things"][id]["T_POSX"] == move_result[2]]
370 hitted_type = world_db["Things"][hit_id]["T_TYPE"]
371 if t == world_db["Things"][0]:
372 hitted_name = world_db["ThingTypes"][hitted_type]["TT_NAME"]
373 log("You WOUND " + hitted_name + ".")
374 world_db["GOD_FAVOR"] -= 1
376 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
377 log(hitter_name +" WOUNDS you.")
378 test = decrement_lifepoints_func(world_db["Things"][hit_id])
379 if test and world_db["FAVOR_STAGE"] >= 3 and \
380 hitted_type == world_db["ANIMAL_0"]:
381 world_db["GOD_FAVOR"] += 125
382 elif test and t == world_db["Things"][0]:
383 world_db["GOD_FAVOR"] -= 2 * test
385 if (ord("X") == world_db["MAP"][pos]
386 or ord("|") == world_db["MAP"][pos]):
387 for id in t["T_CARRIES"]:
388 type = world_db["Things"][id]["T_TYPE"]
389 if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
390 axe_name = world_db["ThingTypes"][type]["TT_NAME"]
391 if t == world_db["Things"][0]:
392 log("With your " + axe_name + ", you chop!")
393 if ord("X") == world_db["MAP"][pos]:
394 world_db["GOD_FAVOR"] -= 1
395 chop_power = world_db["ThingTypes"][type]["TT_TOOLPOWER"]
397 case_X = world_db["MAP"][pos] == ord("X")
400 0 == int(rand.next() / chop_power))
402 0 == int(rand.next() / (3 * chop_power))))):
403 if t == world_db["Things"][0]:
404 log("You chop it DOWN.")
405 if ord("X") == world_db["MAP"][pos]:
406 world_db["GOD_FAVOR"] -= 10
407 world_db["MAP"][pos] = ord(".")
408 i = 3 if case_X else 1
410 id = id_setter(-1, "Things")
411 world_db["Things"][id] = \
412 new_Thing(world_db["LUMBER"],
413 (move_result[1], move_result[2]))
416 passable = chr(world_db["MAP"][pos]) in symbols_passable
418 dir = [dir for dir in directions_db
419 if directions_db[dir] == chr(t["T_ARGUMENT"])][0]
421 t["T_POSY"] = move_result[1]
422 t["T_POSX"] = move_result[2]
423 for id in t["T_CARRIES"]:
424 world_db["Things"][id]["T_POSY"] = move_result[1]
425 world_db["Things"][id]["T_POSX"] = move_result[2]
427 if t == world_db["Things"][0]:
428 log("You MOVE " + dir + ".")
429 if (move_result[1] == world_db["altar"][0] and
430 move_result[2] == world_db["altar"][1]):
433 def command_ttid(id_string):
434 id = id_setter(id_string, "ThingTypes", command_ttid)
436 world_db["ThingTypes"][id] = {
441 "TT_START_NUMBER": 0,
448 def command_worldactive(worldactive_string):
449 val = integer_test(worldactive_string, 0, 1)
451 if 0 != world_db["WORLD_ACTIVE"]:
455 print("World already active.")
456 elif 0 == world_db["WORLD_ACTIVE"]:
457 for ThingAction in world_db["ThingActions"]:
458 if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
461 print("Ignored: No wait action defined for world to activate.")
463 for Thing in world_db["Things"]:
467 print("Ignored: No player defined for world to activate.")
470 pos = world_db["MAP"].find(b'_')
472 y = int(pos / world_db["MAP_LENGTH"])
473 x = pos % world_db["MAP_LENGTH"]
474 world_db["altar"] = (y, x)
476 print("Ignored: No altar defined for world to activate.")
479 print("Ignored: No map defined for world to activate.")
481 for name in world_db["specials"]:
482 if world_db[name] not in world_db["ThingTypes"]:
483 print("Ignored: Not all specials set for world to "
486 for id in world_db["Things"]:
487 if world_db["Things"][id]["T_LIFEPOINTS"]:
488 build_fov_map(world_db["Things"][id])
490 update_map_memory(world_db["Things"][id], False)
491 if not world_db["Things"][0]["T_LIFEPOINTS"]:
492 empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2)
493 world_db["Things"][0]["fovmap"] = empty_fovmap
494 world_db["WORLD_ACTIVE"] = 1
496 def play_move(str_arg):
497 if action_exists("move"):
498 from server.config.world_data import directions_db, symbols_passable
499 t = world_db["Things"][0]
500 if not str_arg in directions_db:
501 print("Illegal move direction string.")
503 dir = ord(directions_db[str_arg])
504 global mv_yx_in_dir_legal
505 move_result = mv_yx_in_dir_legal(chr(dir), t["T_POSY"], t["T_POSX"])
506 if 1 == move_result[0]:
507 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
508 if ord("~") == world_db["MAP"][pos]:
509 log("You can't SWIM.")
511 if (ord("X") == world_db["MAP"][pos]
512 or ord("|") == world_db["MAP"][pos]):
514 for id in t["T_CARRIES"]:
515 type = world_db["Things"][id]["T_TYPE"]
516 if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
517 world_db["Things"][0]["T_ARGUMENT"] = dir
520 if chr(world_db["MAP"][pos]) in symbols_passable:
521 world_db["Things"][0]["T_ARGUMENT"] = dir
524 log("You CAN'T move there.")
526 def play_use(str_arg):
527 if action_exists("use"):
528 t = world_db["Things"][0]
529 if 0 == len(t["T_CARRIES"]):
530 log("You have NOTHING to use in your inventory.")
532 val = integer_test(str_arg, 0, 255)
533 if None != val and val < len(t["T_CARRIES"]):
534 id = t["T_CARRIES"][val]
535 type = world_db["Things"][id]["T_TYPE"]
536 if (world_db["ThingTypes"][type]["TT_TOOL"] == "axe"
537 and t == world_db["Things"][0]):
538 log("To use this item for chopping, move towards a tree "
539 "while carrying it in your inventory.")
541 elif (world_db["ThingTypes"][type]["TT_TOOL"] == "carpentry"):
542 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
543 if (world_db["MAP"][pos] == ord("X")
544 or world_db["MAP"][pos] == ord("|")):
545 log("CAN'T build when standing on barrier.")
547 for id in [id for id in world_db["Things"]
548 if not world_db["Things"][id] == t
549 if not world_db["Things"][id]["carried"]
550 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
551 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]:
552 log("CAN'T build when standing objects.")
555 for id in t["T_CARRIES"]:
556 type_material = world_db["Things"][id]["T_TYPE"]
557 if (world_db["ThingTypes"][type_material]["TT_TOOL"]
562 log("You CAN'T use a "
563 + world_db["ThingTypes"][type]["TT_NAME"]
564 + " without some wood in your inventory.")
566 elif world_db["ThingTypes"][type]["TT_TOOL"] == "fertilizer":
567 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
568 if not world_db["MAP"][pos] == ord("."):
569 log("Can only make soil out of NON-SOIL earth.")
571 elif world_db["ThingTypes"][type]["TT_TOOL"] == "wood":
572 log("To use wood, you NEED a carpentry tool.")
574 elif type != world_db["SLIPPERS"] and not \
575 world_db["ThingTypes"][type]["TT_TOOL"] == "food":
576 log("You CAN'T consume this thing.")
578 world_db["Things"][0]["T_ARGUMENT"] = val
581 print("Illegal inventory index.")
583 def specialtypesetter(name):
585 val = integer_test(str_int, 0)
588 if world_db["WORLD_ACTIVE"] \
589 and world_db[name] not in world_db["ThingTypes"]:
590 world_db["WORLD_ACTIVE"] = 0
591 print(name + " fits no known ThingType, deactivating world.")
594 def write_metamap_A():
595 from server.worldstate_write_helpers import write_map
597 length = world_db["MAP_LENGTH"]
598 metamapA = bytearray(b'0' * (length ** 2))
599 for id in [id for id in world_db["Things"]
600 if not world_db["Things"][id]["carried"]
601 if world_db["Things"][id]["T_LIFEPOINTS"]
602 if world_db["Things"][0]["fovmap"][
603 world_db["Things"][id]["T_POSY"] * length
604 + world_db["Things"][id]["T_POSX"]] == ord_v]:
605 pos = (world_db["Things"][id]["T_POSY"] * length
606 + world_db["Things"][id]["T_POSX"])
607 if id == 0 or world_db["EMPATHY"]:
608 type = world_db["Things"][id]["T_TYPE"]
609 max_hp = world_db["ThingTypes"][type]["TT_LIFEPOINTS"]
610 third_of_hp = max_hp / 3
611 hp = world_db["Things"][id]["T_LIFEPOINTS"]
613 if hp > 2 * third_of_hp:
615 elif hp > third_of_hp:
617 metamapA[pos] = ord('a') + add
619 metamapA[pos] = ord('X')
620 for mt in world_db["Things"][0]["T_MEMTHING"]:
621 pos = mt[1] * length + mt[2]
622 if metamapA[pos] < ord('2'):
624 return write_map(metamapA, length)
626 def write_metamap_B():
627 from server.worldstate_write_helpers import write_map
629 length = world_db["MAP_LENGTH"]
630 metamapB = bytearray(b' ' * (length ** 2))
631 for id in [id for id in world_db["Things"]
632 if not world_db["Things"][id]["carried"]
633 if world_db["Things"][id]["T_LIFEPOINTS"]
634 if world_db["Things"][0]["fovmap"][
635 world_db["Things"][id]["T_POSY"] * length
636 + world_db["Things"][id]["T_POSX"]] == ord_v]:
637 pos = (world_db["Things"][id]["T_POSY"] * length
638 + world_db["Things"][id]["T_POSX"])
639 if id == 0 or world_db["EMPATHY"]:
640 action = world_db["Things"][id]["T_COMMAND"]
642 name = world_db["ThingActions"][action]["TA_NAME"]
645 metamapB[pos] = ord(name[0])
646 return write_map(metamapB, length)
648 def calc_effort(thing_action, thing):
649 from math import sqrt
650 effort = thing_action["TA_EFFORT"]
651 if thing_action["TA_NAME"] == "move":
652 typ = thing["T_TYPE"]
653 max_hp = (world_db["ThingTypes"][typ]["TT_LIFEPOINTS"])
654 effort = int(effort / sqrt(max_hp))
655 effort = 1 if effort == 0 else effort
659 """Try "pickup" as player's T_COMMAND"."""
660 if action_exists("pickup"):
661 t = world_db["Things"][0]
662 ids = [id for id in world_db["Things"] if id
663 if not world_db["Things"][id]["carried"]
664 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
665 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
667 log("NOTHING to pick up.")
668 elif len(t["T_CARRIES"]) >= world_db["ThingTypes"][t["T_TYPE"]] \
670 log("CAN'T pick up: No storage room to carry anything more.")
672 set_command("pickup")
674 strong_write(io_db["file_out"], "PLUGIN PleaseTheIslandGod\n")
676 def set_zero_if_undefined(key):
677 if not key in world_db:
680 set_zero_if_undefined("GOD_FAVOR")
681 set_zero_if_undefined("FAVOR_STAGE")
682 set_zero_if_undefined("EMPATHY")
683 world_db["specials"] = ["SLIPPERS", "PLANT_0", "PLANT_1", "TOOL_0", "TOOL_1",
684 "LUMBER", "ANIMAL_0", "ANIMAL_1"]
685 for key in world_db["specials"]:
686 set_zero_if_undefined(key)
688 world_db["terrain_names"][":"] = "SOIL"
689 world_db["terrain_names"]["|"] = "WALL"
690 world_db["terrain_names"]["_"] = "ALTAR"
691 io_db["worldstate_write_order"] += [["GOD_FAVOR", "world_int"]]
692 io_db["worldstate_write_order"] += [[write_metamap_A, "func"]]
693 io_db["worldstate_write_order"] += [[write_metamap_B, "func"]]
695 import server.config.world_data
696 server.config.world_data.symbols_passable += ":_"
698 from server.config.world_data import thing_defaults
699 thing_defaults["T_PLAYERDROP"] = 0
701 import server.config.actions
702 server.config.actions.action_db["actor_move"] = actor_move
703 server.config.actions.action_db["actor_pickup"] = actor_pickup
704 server.config.actions.action_db["actor_drop"] = actor_drop
705 server.config.actions.action_db["actor_use"] = actor_use
706 server.config.actions.ai_func = ai
708 from server.config.commands import commands_db
709 commands_db["TT_ID"] = (1, False, command_ttid)
710 commands_db["GOD_FAVOR"] = (1, False, setter(None, "GOD_FAVOR", -32768, 32767))
711 commands_db["TT_STORAGE"] = (1, False, setter("ThingType", "TT_STORAGE", 0, 255))
712 commands_db["T_PLAYERDROP"] = (1, False, setter("Thing", "T_PLAYERDROP", 0, 1))
713 commands_db["WORLD_ACTIVE"] = (1, False, command_worldactive)
714 commands_db["FAVOR_STAGE"] = (1, False, setter(None, "FAVOR_STAGE", 0, 1))
715 commands_db["SLIPPERS"] = (1, False, specialtypesetter("SLIPPERS"))
716 commands_db["TOOL_0"] = (1, False, specialtypesetter("TOOL_0"))
717 commands_db["TOOL_1"] = (1, False, specialtypesetter("TOOL_1"))
718 commands_db["ANIMAL_0"] = (1, False, specialtypesetter("ANIMAL_0"))
719 commands_db["ANIMAL_1"] = (1, False, specialtypesetter("ANIMAL_1"))
720 commands_db["PLANT_0"] = (1, False, specialtypesetter("PLANT_0"))
721 commands_db["PLANT_1"] = (1, False, specialtypesetter("PLANT_1"))
722 commands_db["LUMBER"] = (1, False, specialtypesetter("LUMBER"))
723 commands_db["EMPATHY"] = (1, False, setter(None, "EMPATHY", 0, 1))
724 commands_db["use"] = (1, False, play_use)
725 commands_db["move"] = (1, False, play_move)
726 commands_db["pickup"] = (0, False, play_pickup)
728 import server.config.misc
729 server.config.misc.make_map_func = make_map
730 server.config.misc.decrement_lifepoints_func = decrement_lifepoints
731 server.config.misc.calc_effort_func = calc_effort
733 import server.config.make_world_helpers
734 server.config.make_world_helpers.pos_test_func = pos_test
735 server.config.make_world_helpers.world_makable_func = world_makable
736 server.config.make_world_helpers.make_map_func = make_map
738 import server.config.thingproliferation
739 server.config.thingproliferation.field_spreadable = field_spreadable
740 server.config.thingproliferation.thingprol_plugin_conditions = \
741 thingprol_plugin_conditions
742 server.config.thingproliferation.thingprol_plugin_post_create_hook = \
743 thingprol_plugin_post_create_hook