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
68 def ai_hook_pickup_test(t):
69 return len(t["T_CARRIES"]) < \
70 world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]
73 used_slots = len(t["T_CARRIES"])
74 if used_slots < world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]:
75 from server.actions import actor_pickup
76 t_picked = actor_pickup(t)
78 ty = world_db["ThingTypes"][t_picked["T_TYPE"]]
79 if t != world_db["Things"][0] and t_picked["T_PLAYERDROP"] \
80 and ty["TT_TOOL"] == "food":
81 score = int(ty["TT_TOOLPOWER"] / 32)
82 world_db["GOD_FAVOR"] += score
83 t_picked["T_PLAYERDROP"] = 0
84 elif t == world_db["Things"][0]:
85 log("CAN'T pick up object: No storage room to carry more.")
87 def actor_pickup_test_hook(t, tid):
88 from server.ai import eat_vs_hunger_threshold
89 tt = world_db["ThingTypes"][tid]
90 return not (t != world_db["Things"][0] and (tt["TT_TOOL"] != "food" or
91 (tt["TT_TOOLPOWER"] <= eat_vs_hunger_threshold(t["T_TYPE"]))))
94 """Make t rop Thing from inventory to ground indexed by T_ARGUMENT."""
95 if len(t["T_CARRIES"]):
96 id = t["T_CARRIES"][t["T_ARGUMENT"]]
97 t["T_CARRIES"].remove(id)
98 world_db["Things"][id]["carried"] = False
99 if t == world_db["Things"][0]:
100 log("You DROP an object.")
101 world_db["Things"][id]["T_PLAYERDROP"] = 1
104 if len(t["T_CARRIES"]):
105 id = t["T_CARRIES"][t["T_ARGUMENT"]]
106 type = world_db["Things"][id]["T_TYPE"]
107 if type == world_db["SLIPPERS"]:
108 if t == world_db["Things"][0]:
109 log("You use the " + world_db["ThingTypes"][type]["TT_NAME"] +
110 ". It glows in wondrous colors, and emits a sound as if fr"
111 "om a dying cat. The Island God laughs.\n")
112 t["T_LIFEPOINTS"] = 1
113 from server.config.misc import decrement_lifepoints_func
114 decrement_lifepoints_func(t)
115 elif (world_db["ThingTypes"][type]["TT_TOOL"] == "carpentry"):
116 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
117 if (world_db["MAP"][pos] == ord("X")
118 or world_db["MAP"][pos] == ord("|")):
120 for id in [id for id in world_db["Things"]
121 if not world_db["Things"][id] == t
122 if not world_db["Things"][id]["carried"]
123 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
124 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]:
127 for id in t["T_CARRIES"]:
128 type_material = world_db["Things"][id]["T_TYPE"]
129 if (world_db["ThingTypes"][type_material]["TT_TOOL"]
134 t["T_CARRIES"].remove(wood_id)
135 del world_db["Things"][wood_id]
136 world_db["MAP"][pos] = ord("|")
137 log("With your " + world_db["ThingTypes"][type]["TT_NAME"]
138 + " you build a WOODEN BARRIER from your "
139 + world_db["ThingTypes"][type_material]["TT_NAME"] + ".")
140 elif world_db["ThingTypes"][type]["TT_TOOL"] == "fertilizer":
141 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
142 if world_db["MAP"][pos] == ord("."):
143 log("You create SOIL.")
144 world_db["MAP"][pos] = ord(":")
145 elif world_db["ThingTypes"][type]["TT_TOOL"] == "food":
146 t["T_CARRIES"].remove(id)
147 del world_db["Things"][id]
148 t["T_SATIATION"] += world_db["ThingTypes"][type]["TT_TOOLPOWER"]
149 if t == world_db["Things"][0]:
150 log("You CONSUME this thing.")
151 elif t == world_db["Things"][0]:
152 log("You try to use this object, but FAIL.")
154 def decrement_lifepoints(t):
155 t["T_LIFEPOINTS"] -= 1
156 live_type = t["T_TYPE"]
157 _id = [_id for _id in world_db["Things"] if world_db["Things"][_id] == t][0]
158 if 0 == t["T_LIFEPOINTS"]:
159 for id in t["T_CARRIES"]:
160 t["T_CARRIES"].remove(id)
161 world_db["Things"][id]["T_POSY"] = t["T_POSY"]
162 world_db["Things"][id]["T_POSX"] = t["T_POSX"]
163 world_db["Things"][id]["carried"] = False
164 t["T_TYPE"] = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"]
165 if world_db["Things"][0] == t:
166 t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
168 log("See README on how to start over.")
171 t["T_MEMMAP"] = False
172 t["T_MEMDEPTHMAP"] = False
174 n_species = len([id for id in world_db["Things"]
175 if world_db["Things"][id]["T_TYPE"] == live_type])
177 from server.new_thing import new_Thing
178 if world_db["FAVOR_STAGE"] >= 3 and \
179 live_type == world_db["ANIMAL_0"]:
180 world_db["GOD_FAVOR"] += 3000
181 log("CONGRATULATIONS! The "
182 + world_db["ThingTypes"][live_type]["TT_NAME"]
183 + " species has died out. The Island God is pleased.")
185 id = id_setter(-1, "Things")
186 world_db["Things"][id] = new_Thing(live_type,
189 + world_db["ThingTypes"][live_type]["TT_NAME"]
190 + " species has temporarily died out. "
191 + "One new-born is spawned at the altar.")
192 return world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]
197 def altar_msg_wait(limit):
198 log("The Island God will talk again when it favors you to >=" +
199 str(limit) + " points.")
201 altar_msg_0 = "The Island God speaks to you: \"I don't trust you. You in" \
202 "trude on the island's affairs. I think you're a nuisance at best, and a" \
203 " danger to my children at worst. I will give you a chance to lighten my" \
204 " mood, however: For a while now, I've been trying to spread the plant " \
205 + world_db["ThingTypes"][world_db["PLANT_0"]]["TT_NAME"] + " (\"" + \
206 world_db["ThingTypes"][world_db["PLANT_0"]]["TT_SYMBOL"] + "\"). I have " \
207 "not been very successful so far. Maybe you can make yourself useful the" \
208 "re. I will count each further " + \
209 world_db["ThingTypes"][world_db["PLANT_0"]]["TT_NAME"] + " that grows to" \
212 altar_msg_1 = "The Island God speaks to you: \"You could have done worse" \
213 " so far. Maybe you are not the worst to happen to this island since the" \
214 " metal birds threw the great lightning ball. Maybe you can help me spre" \
215 "ad another plant. It multiplies faster,and it is highly nutritious: " + \
216 world_db["ThingTypes"][world_db["PLANT_1"]]["TT_NAME"] + " (\"" + \
217 world_db["ThingTypes"][world_db["PLANT_1"]]["TT_SYMBOL"] + "\"). It is n" \
218 "ew. I give you the only example. Be very careful with it! I also give y" \
219 "ou another tool that may be helpful.\""
221 altar_msg_2 = "The Island God speaks to you: \"I am greatly disappointed" \
222 " that you lost all " + \
223 world_db["ThingTypes"][world_db["PLANT_1"]]["TT_NAME"] + " this island h" \
224 "ad. Here is another one. It cost me great work. Be more careful this ti" \
225 "me when planting it.\""
227 altar_msg_3 = "The Island God speaks to you: \"The " + \
228 world_db["ThingTypes"][world_db["ANIMAL_0"]]["TT_NAME"] + " has lately b" \
229 "ecome a pest. These creatures do not please me as much as they used to " \
230 "do. Exterminate them all. I will count each kill to your favor. To help" \
231 " you with the hunting, I grant you the empathy and knowledge to read an" \
234 altar_msg_4 = "You will now see animals' health bars, and activities (\"" \
235 "m\": moving (maybe for an attack), \"u\": eating, \"p\": picking someth" \
236 "ing up; no letter: waiting)."
238 altar_msg_5 = "The Island God speaks to you: \"You know what animal I fi" \
239 "nd the cutest? The " + \
240 world_db["ThingTypes"][world_db["ANIMAL_1"]]["TT_NAME"] + "! I think wha" \
241 "t this islands clearly needs more of is " + \
242 world_db["ThingTypes"][world_db["ANIMAL_1"]]["TT_NAME"] + "s. Why don't " \
243 "you help? Support them. Make sure they are well, and they will multiply" \
244 " faster. From now on, I will count each new-born " + \
245 world_db["ThingTypes"][world_db["ANIMAL_1"]]["TT_NAME"] + \
246 " (not spawned by me due to undo an extinction event) greatly to your fa" \
247 "vor. To help you with the feeding, here is something to make the ground" \
248 " bear more consumables."
250 altar_msg_6 = "The Island God speaks to you: \"You have proven yourself " \
251 "worthy of my respect. You were a good citizen to the island, and someti" \
252 "mes a better steward to its inhabitants than me. The island shall miss " \
253 "you when you leave. But you have earned the right to do so. Take this" + \
254 world_db["ThingTypes"][world_db["SLIPPERS"]]["TT_NAME"] + " and USE it w" \
255 "hen you please. It will take you to where you came from. (But do feel f" \
256 "ree to stay here as long as you like.)\""
259 from server.new_thing import new_Thing
260 if world_db["FAVOR_STAGE"] > 9000:
261 log("You step on a soul-less slab of stone.")
263 log("YOU ENTER SACRED GROUND.")
264 if world_db["FAVOR_STAGE"] == 0:
265 world_db["FAVOR_STAGE"] = 1
267 elif world_db["FAVOR_STAGE"] == 1 and world_db["GOD_FAVOR"] < 100:
269 elif world_db["FAVOR_STAGE"] == 1 and world_db["GOD_FAVOR"] >= 100:
270 world_db["FAVOR_STAGE"] = 2
272 id = id_setter(-1, "Things")
273 world_db["Things"][id] = new_Thing(world_db["PLANT_1"],
275 id = id_setter(-1, "Things")
276 world_db["Things"][id] = new_Thing(world_db["TOOL_0"],
278 elif world_db["FAVOR_STAGE"] == 2 and \
279 0 == len([id for id in world_db["Things"]
280 if world_db["Things"][id]["T_TYPE"]
281 == world_db["PLANT_1"]]):
283 id = id_setter(-1, "Things")
284 world_db["Things"][id] = new_Thing(world_db["PLANT_1"],
286 world_db["GOD_FAVOR"] -= 250
287 elif world_db["FAVOR_STAGE"] == 2 and world_db["GOD_FAVOR"] < 500:
289 elif world_db["FAVOR_STAGE"] == 2 and world_db["GOD_FAVOR"] >= 500:
290 world_db["FAVOR_STAGE"] = 3
293 world_db["EMPATHY"] = 1
294 elif world_db["FAVOR_STAGE"] == 3 and world_db["GOD_FAVOR"] < 5000:
296 elif world_db["FAVOR_STAGE"] == 3 and world_db["GOD_FAVOR"] >= 5000:
297 world_db["FAVOR_STAGE"] = 4
299 id = id_setter(-1, "Things")
300 world_db["Things"][id] = new_Thing(world_db["TOOL_1"],
302 elif world_db["GOD_FAVOR"] < 20000:
303 altar_msg_wait(20000)
304 elif world_db["GOD_FAVOR"] > 20000:
305 world_db["FAVOR_STAGE"] = 9001
307 id = id_setter(-1, "Things")
308 world_db["Things"][id] = new_Thing(world_db["SLIPPERS"],
311 from server.config.world_data import symbols_passable
312 from server.build_fov_map import build_fov_map
313 from server.config.misc import decrement_lifepoints_func
314 from server.new_thing import new_Thing
315 global mv_yx_in_dir_legal
317 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
318 t["T_POSY"], t["T_POSX"])
319 if 1 == move_result[0]:
320 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
321 hitted = [id for id in world_db["Things"]
322 if world_db["Things"][id] != t
323 if world_db["Things"][id]["T_LIFEPOINTS"]
324 if world_db["Things"][id]["T_POSY"] == move_result[1]
325 if world_db["Things"][id]["T_POSX"] == move_result[2]]
328 hitted_type = world_db["Things"][hit_id]["T_TYPE"]
329 if t == world_db["Things"][0]:
330 hitted_name = world_db["ThingTypes"][hitted_type]["TT_NAME"]
331 log("You WOUND " + hitted_name + ".")
332 world_db["GOD_FAVOR"] -= 1
334 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
335 log(hitter_name +" WOUNDS you.")
336 test = decrement_lifepoints_func(world_db["Things"][hit_id])
337 if test and world_db["FAVOR_STAGE"] >= 3 and \
338 hitted_type == world_db["ANIMAL_0"]:
339 world_db["GOD_FAVOR"] += 125
340 elif test and t == world_db["Things"][0]:
341 world_db["GOD_FAVOR"] -= 2 * test
343 if (ord("X") == world_db["MAP"][pos]
344 or ord("|") == world_db["MAP"][pos]):
345 for id in t["T_CARRIES"]:
346 type = world_db["Things"][id]["T_TYPE"]
347 if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
348 axe_name = world_db["ThingTypes"][type]["TT_NAME"]
349 if t == world_db["Things"][0]:
350 log("With your " + axe_name + ", you chop!")
351 if ord("X") == world_db["MAP"][pos]:
352 world_db["GOD_FAVOR"] -= 1
353 chop_power = world_db["ThingTypes"][type]["TT_TOOLPOWER"]
355 case_X = world_db["MAP"][pos] == ord("X")
358 0 == int(rand.next() / chop_power))
360 0 == int(rand.next() / (3 * chop_power))))):
361 if t == world_db["Things"][0]:
362 log("You chop it DOWN.")
363 if ord("X") == world_db["MAP"][pos]:
364 world_db["GOD_FAVOR"] -= 10
365 world_db["MAP"][pos] = ord(".")
366 i = 3 if case_X else 1
368 id = id_setter(-1, "Things")
369 world_db["Things"][id] = \
370 new_Thing(world_db["LUMBER"],
371 (move_result[1], move_result[2]))
374 passable = chr(world_db["MAP"][pos]) in symbols_passable
376 dir = [dir for dir in directions_db
377 if directions_db[dir] == chr(t["T_ARGUMENT"])][0]
379 t["T_POSY"] = move_result[1]
380 t["T_POSX"] = move_result[2]
381 for id in t["T_CARRIES"]:
382 world_db["Things"][id]["T_POSY"] = move_result[1]
383 world_db["Things"][id]["T_POSX"] = move_result[2]
385 if t == world_db["Things"][0]:
386 log("You MOVE " + dir + ".")
387 if (move_result[1] == world_db["altar"][0] and
388 move_result[2] == world_db["altar"][1]):
391 def command_ttid(id_string):
392 id = id_setter(id_string, "ThingTypes", command_ttid)
394 world_db["ThingTypes"][id] = {
399 "TT_START_NUMBER": 0,
406 def command_worldactive(worldactive_string):
407 val = integer_test(worldactive_string, 0, 1)
409 if 0 != world_db["WORLD_ACTIVE"]:
413 print("World already active.")
414 elif 0 == world_db["WORLD_ACTIVE"]:
415 for ThingAction in world_db["ThingActions"]:
416 if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
419 print("Ignored: No wait action defined for world to activate.")
421 for Thing in world_db["Things"]:
425 print("Ignored: No player defined for world to activate.")
428 pos = world_db["MAP"].find(b'_')
430 y = int(pos / world_db["MAP_LENGTH"])
431 x = pos % world_db["MAP_LENGTH"]
432 world_db["altar"] = (y, x)
434 print("Ignored: No altar defined for world to activate.")
437 print("Ignored: No map defined for world to activate.")
439 for name in world_db["specials"]:
440 if world_db[name] not in world_db["ThingTypes"]:
441 print("Ignored: Not all specials set for world to "
444 for id in world_db["Things"]:
445 if world_db["Things"][id]["T_LIFEPOINTS"]:
446 build_fov_map(world_db["Things"][id])
448 update_map_memory(world_db["Things"][id], False)
449 if not world_db["Things"][0]["T_LIFEPOINTS"]:
450 empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2)
451 world_db["Things"][0]["fovmap"] = empty_fovmap
452 world_db["WORLD_ACTIVE"] = 1
454 def play_move(str_arg):
455 if action_exists("move"):
456 from server.config.world_data import directions_db, symbols_passable
457 t = world_db["Things"][0]
458 if not str_arg in directions_db:
459 print("Illegal move direction string.")
461 dir = ord(directions_db[str_arg])
462 global mv_yx_in_dir_legal
463 move_result = mv_yx_in_dir_legal(chr(dir), t["T_POSY"], t["T_POSX"])
464 if 1 == move_result[0]:
465 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
466 if ord("~") == world_db["MAP"][pos]:
467 log("You can't SWIM.")
469 if (ord("X") == world_db["MAP"][pos]
470 or ord("|") == world_db["MAP"][pos]):
472 for id in t["T_CARRIES"]:
473 type = world_db["Things"][id]["T_TYPE"]
474 if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
475 world_db["Things"][0]["T_ARGUMENT"] = dir
478 if chr(world_db["MAP"][pos]) in symbols_passable:
479 world_db["Things"][0]["T_ARGUMENT"] = dir
482 log("You CAN'T move there.")
484 def play_use(str_arg):
485 if action_exists("use"):
486 t = world_db["Things"][0]
487 if 0 == len(t["T_CARRIES"]):
488 log("You have NOTHING to use in your inventory.")
490 val = integer_test(str_arg, 0, 255)
491 if None != val and val < len(t["T_CARRIES"]):
492 id = t["T_CARRIES"][val]
493 type = world_db["Things"][id]["T_TYPE"]
494 if (world_db["ThingTypes"][type]["TT_TOOL"] == "axe"
495 and t == world_db["Things"][0]):
496 log("To use this item for chopping, move towards a tree "
497 "while carrying it in your inventory.")
499 elif (world_db["ThingTypes"][type]["TT_TOOL"] == "carpentry"):
500 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
501 if (world_db["MAP"][pos] == ord("X")
502 or world_db["MAP"][pos] == ord("|")):
503 log("CAN'T build when standing on barrier.")
505 for id in [id for id in world_db["Things"]
506 if not world_db["Things"][id] == t
507 if not world_db["Things"][id]["carried"]
508 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
509 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]:
510 log("CAN'T build when standing objects.")
513 for id in t["T_CARRIES"]:
514 type_material = world_db["Things"][id]["T_TYPE"]
515 if (world_db["ThingTypes"][type_material]["TT_TOOL"]
520 log("You CAN'T use a "
521 + world_db["ThingTypes"][type]["TT_NAME"]
522 + " without some wood in your inventory.")
524 elif world_db["ThingTypes"][type]["TT_TOOL"] == "fertilizer":
525 pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
526 if not world_db["MAP"][pos] == ord("."):
527 log("Can only make soil out of NON-SOIL earth.")
529 elif world_db["ThingTypes"][type]["TT_TOOL"] == "wood":
530 log("To use wood, you NEED a carpentry tool.")
532 elif type != world_db["SLIPPERS"] and not \
533 world_db["ThingTypes"][type]["TT_TOOL"] == "food":
534 log("You CAN'T consume this thing.")
536 world_db["Things"][0]["T_ARGUMENT"] = val
539 print("Illegal inventory index.")
541 def specialtypesetter(name):
543 val = integer_test(str_int, 0)
546 if world_db["WORLD_ACTIVE"] \
547 and world_db[name] not in world_db["ThingTypes"]:
548 world_db["WORLD_ACTIVE"] = 0
549 print(name + " fits no known ThingType, deactivating world.")
552 def write_metamap_A():
553 from server.worldstate_write_helpers import write_map
555 length = world_db["MAP_LENGTH"]
556 metamapA = bytearray(b'0' * (length ** 2))
557 for id in [id for id in world_db["Things"]
558 if not world_db["Things"][id]["carried"]
559 if world_db["Things"][id]["T_LIFEPOINTS"]
560 if world_db["Things"][0]["fovmap"][
561 world_db["Things"][id]["T_POSY"] * length
562 + world_db["Things"][id]["T_POSX"]] == ord_v]:
563 pos = (world_db["Things"][id]["T_POSY"] * length
564 + world_db["Things"][id]["T_POSX"])
565 if id == 0 or world_db["EMPATHY"]:
566 type = world_db["Things"][id]["T_TYPE"]
567 max_hp = world_db["ThingTypes"][type]["TT_LIFEPOINTS"]
568 third_of_hp = max_hp / 3
569 hp = world_db["Things"][id]["T_LIFEPOINTS"]
571 if hp > 2 * third_of_hp:
573 elif hp > third_of_hp:
575 metamapA[pos] = ord('a') + add
577 metamapA[pos] = ord('X')
578 for mt in world_db["Things"][0]["T_MEMTHING"]:
579 pos = mt[1] * length + mt[2]
580 if metamapA[pos] < ord('2'):
582 return write_map(metamapA, length)
584 def write_metamap_B():
585 from server.worldstate_write_helpers import write_map
587 length = world_db["MAP_LENGTH"]
588 metamapB = bytearray(b' ' * (length ** 2))
589 for id in [id for id in world_db["Things"]
590 if not world_db["Things"][id]["carried"]
591 if world_db["Things"][id]["T_LIFEPOINTS"]
592 if world_db["Things"][0]["fovmap"][
593 world_db["Things"][id]["T_POSY"] * length
594 + world_db["Things"][id]["T_POSX"]] == ord_v]:
595 pos = (world_db["Things"][id]["T_POSY"] * length
596 + world_db["Things"][id]["T_POSX"])
597 if id == 0 or world_db["EMPATHY"]:
598 action = world_db["Things"][id]["T_COMMAND"]
600 name = world_db["ThingActions"][action]["TA_NAME"]
603 metamapB[pos] = ord(name[0])
604 return write_map(metamapB, length)
606 def calc_effort(thing_action, thing):
607 from math import sqrt
608 effort = thing_action["TA_EFFORT"]
609 if thing_action["TA_NAME"] == "move":
610 typ = thing["T_TYPE"]
611 max_hp = (world_db["ThingTypes"][typ]["TT_LIFEPOINTS"])
612 effort = int(effort / sqrt(max_hp))
613 effort = 1 if effort == 0 else effort
617 """Try "pickup" as player's T_COMMAND"."""
618 if action_exists("pickup"):
619 t = world_db["Things"][0]
620 ids = [id for id in world_db["Things"] if id
621 if not world_db["Things"][id]["carried"]
622 if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
623 if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
625 log("NOTHING to pick up.")
626 elif len(t["T_CARRIES"]) >= world_db["ThingTypes"][t["T_TYPE"]] \
628 log("CAN'T pick up: No storage room to carry anything more.")
630 set_command("pickup")
632 strong_write(io_db["file_out"], "PLUGIN PleaseTheIslandGod\n")
634 def set_zero_if_undefined(key):
635 if not key in world_db:
638 set_zero_if_undefined("GOD_FAVOR")
639 set_zero_if_undefined("FAVOR_STAGE")
640 set_zero_if_undefined("EMPATHY")
641 world_db["specials"] = ["SLIPPERS", "PLANT_0", "PLANT_1", "TOOL_0", "TOOL_1",
642 "LUMBER", "ANIMAL_0", "ANIMAL_1"]
643 for key in world_db["specials"]:
644 set_zero_if_undefined(key)
646 world_db["terrain_names"][":"] = "SOIL"
647 world_db["terrain_names"]["|"] = "WALL"
648 world_db["terrain_names"]["_"] = "ALTAR"
649 io_db["worldstate_write_order"] += [["GOD_FAVOR", "world_int"]]
650 io_db["worldstate_write_order"] += [[write_metamap_A, "func"]]
651 io_db["worldstate_write_order"] += [[write_metamap_B, "func"]]
653 import server.config.world_data
654 server.config.world_data.symbols_passable += ":_"
656 from server.config.world_data import thing_defaults
657 thing_defaults["T_PLAYERDROP"] = 0
659 import server.config.actions
660 server.config.actions.action_db["actor_move"] = actor_move
661 server.config.actions.action_db["actor_pickup"] = actor_pickup
662 server.config.actions.action_db["actor_drop"] = actor_drop
663 server.config.actions.action_db["actor_use"] = actor_use
664 server.config.actions.actor_pickup_test_hook = actor_pickup_test_hook
666 from server.config.commands import commands_db
667 commands_db["TT_ID"] = (1, False, command_ttid)
668 commands_db["GOD_FAVOR"] = (1, False, setter(None, "GOD_FAVOR", -32768, 32767))
669 commands_db["TT_STORAGE"] = (1, False, setter("ThingType", "TT_STORAGE", 0, 255))
670 commands_db["T_PLAYERDROP"] = (1, False, setter("Thing", "T_PLAYERDROP", 0, 1))
671 commands_db["WORLD_ACTIVE"] = (1, False, command_worldactive)
672 commands_db["FAVOR_STAGE"] = (1, False, setter(None, "FAVOR_STAGE", 0, 1))
673 commands_db["SLIPPERS"] = (1, False, specialtypesetter("SLIPPERS"))
674 commands_db["TOOL_0"] = (1, False, specialtypesetter("TOOL_0"))
675 commands_db["TOOL_1"] = (1, False, specialtypesetter("TOOL_1"))
676 commands_db["ANIMAL_0"] = (1, False, specialtypesetter("ANIMAL_0"))
677 commands_db["ANIMAL_1"] = (1, False, specialtypesetter("ANIMAL_1"))
678 commands_db["PLANT_0"] = (1, False, specialtypesetter("PLANT_0"))
679 commands_db["PLANT_1"] = (1, False, specialtypesetter("PLANT_1"))
680 commands_db["LUMBER"] = (1, False, specialtypesetter("LUMBER"))
681 commands_db["EMPATHY"] = (1, False, setter(None, "EMPATHY", 0, 1))
682 commands_db["use"] = (1, False, play_use)
683 commands_db["move"] = (1, False, play_move)
684 commands_db["pickup"] = (0, False, play_pickup)
686 import server.config.misc
687 server.config.misc.make_map_func = make_map
688 server.config.misc.decrement_lifepoints_func = decrement_lifepoints
689 server.config.misc.calc_effort_func = calc_effort
691 import server.config.make_world_helpers
692 server.config.make_world_helpers.pos_test_func = pos_test
693 server.config.make_world_helpers.world_makable_func = world_makable
694 server.config.make_world_helpers.make_map_func = make_map
696 import server.config.thingproliferation
697 server.config.thingproliferation.field_spreadable = field_spreadable
698 server.config.thingproliferation.thingprol_plugin_conditions = \
699 thingprol_plugin_conditions
700 server.config.thingproliferation.thingprol_plugin_post_create_hook = \
701 thingprol_plugin_post_create_hook
703 import server.config.ai
704 server.config.ai.ai_hook_pickup = ai_hook_pickup_test