home · contact · privacy
25ac15377ed63461bc94d851c29fa525154d429d
[plomrogue] / plugins / server / PleaseTheIslandGod.py
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.
4
5
6 from server.io import log, strong_write
7 from server.config.world_data import world_db, symbols_passable, directions_db
8 from server.utils import mv_yx_in_dir_legal, rand, id_setter
9 from server.config.io import io_db
10 from server.new_thing import new_Thing
11
12 def make_world(seed):
13     from server.update_map_memory import update_map_memory
14     from server.config.misc import make_map_func
15     from server.utils import libpr
16
17     def free_pos(plant=False):
18         i = 0
19         while 1:
20             err = "Space to put thing on too hard to find. Map too small?"
21             while 1:
22                 y = rand.next() % world_db["MAP_LENGTH"]
23                 x = rand.next() % world_db["MAP_LENGTH"]
24                 pos = y * world_db["MAP_LENGTH"] + x;
25                 if (not plant
26                     and "." == chr(world_db["MAP"][pos])) \
27                    or ":" == chr(world_db["MAP"][pos]):
28                     break
29                 i += 1
30                 if i == 65535:
31                     raise SystemExit(err)
32             pos_clear = (0 == len([id for id in world_db["Things"]
33                                    if world_db["Things"][id]["T_LIFEPOINTS"]
34                                    if world_db["Things"][id]["T_POSY"] == y
35                                    if world_db["Things"][id]["T_POSX"] == x]))
36             if pos_clear:
37                 break
38         return (y, x)
39
40     rand.seed = seed
41     if world_db["MAP_LENGTH"] < 1:
42         print("Ignoring: No map length >= 1 defined.")
43         return
44     libpr.set_maplength(world_db["MAP_LENGTH"])
45     player_will_be_generated = False
46     playertype = world_db["PLAYER_TYPE"]
47     for ThingType in world_db["ThingTypes"]:
48         if playertype == ThingType:
49             if 0 < world_db["ThingTypes"][ThingType]["TT_START_NUMBER"]:
50                 player_will_be_generated = True
51             break
52     if not player_will_be_generated:
53         print("Ignoring: No player type with start number >0 defined.")
54         return
55     wait_action = False
56     for ThingAction in world_db["ThingActions"]:
57         if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
58             wait_action = True
59     if not wait_action:
60         print("Ignoring beyond SEED_MAP: " +
61               "No thing action with name 'wait' defined.")
62         return
63     if not world_db["SLIPPERS"] in world_db["ThingTypes"]:
64         print("Ignoring: No valid SLIPPERS set.")
65         return
66     if not world_db["PLANT_0"] in world_db["ThingTypes"]:
67         print("Ignoring: No valid PLANT_0 set.")
68         return
69     if not world_db["LUMBER"] in world_db["ThingTypes"]:
70         print("Ignoring: No valid LUMBER set.")
71         return
72     #for name in specials:
73     #    if world_db[name] not in world_db["ThingTypes"]:
74     #        print("Ignoring: No valid " + name + " set.")
75     #        return
76     world_db["Things"] = {}
77     make_map()
78     world_db["WORLD_ACTIVE"] = 1
79     world_db["TURN"] = 1
80     for i in range(world_db["ThingTypes"][playertype]["TT_START_NUMBER"]):
81         id = id_setter(-1, "Things")
82         world_db["Things"][id] = new_Thing(playertype, free_pos())
83     if not world_db["Things"][0]["fovmap"]:
84         empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2)
85         world_db["Things"][0]["fovmap"] = empty_fovmap
86     update_map_memory(world_db["Things"][0])
87     for type in world_db["ThingTypes"]:
88         for i in range(world_db["ThingTypes"][type]["TT_START_NUMBER"]):
89             if type != playertype:
90                 id = id_setter(-1, "Things")
91                 plantness = world_db["ThingTypes"][type]["TT_PROLIFERATE"]
92                 world_db["Things"][id] = new_Thing(type, free_pos(plantness))
93     strong_write(io_db["file_out"], "NEW_WORLD\n")
94
95 def thingproliferation(t, prol_map):
96     from server.new_thing import new_Thing
97     global directions_db, mv_yx_in_dir_legal
98     prolscore = world_db["ThingTypes"][t["T_TYPE"]]["TT_PROLIFERATE"]
99     if prolscore and \
100       (world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"] == 0 or
101        t["T_LIFEPOINTS"] >= 0.9 *
102                         world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]) \
103        and \
104       (1 == prolscore or 1 == (rand.next() % prolscore)):
105         candidates = []
106         for dir in [directions_db[key] for key in directions_db]:
107             mv_result = mv_yx_in_dir_legal(dir, t["T_POSY"], t["T_POSX"])
108             pos = mv_result[1] * world_db["MAP_LENGTH"] + mv_result[2]
109             if mv_result[0] and \
110                (ord(":") == prol_map[pos]
111                 or (world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]
112                     and ord(".") == prol_map[pos])):
113                 candidates.append((mv_result[1], mv_result[2]))
114         if len(candidates):
115             i = rand.next() % len(candidates)
116             id = id_setter(-1, "Things")
117             newT = new_Thing(t["T_TYPE"], (candidates[i][0], candidates[i][1]))
118             world_db["Things"][id] = newT
119             if (world_db["FAVOR_STAGE"] > 0
120                 and t["T_TYPE"] == world_db["PLANT_0"]):
121                 world_db["GOD_FAVOR"] += 5
122             #elif t["T_TYPE"] == world_db["PLANT_1"];
123             #    world_db["GOD_FAVOR"] += 25
124             #elif world_db["FAVOR_STAGE"] >= 4 and \
125             #     t["T_TYPE"] == world_db["ANIMAL_1"]:
126             #    log("The Island God SMILES upon a new-born bear baby.")
127             #    world_db["GOD_FAVOR"] += 750
128
129 def make_map():
130     global rand
131
132     def is_neighbor(coordinates, type):
133         y = coordinates[0]
134         x = coordinates[1]
135         length = world_db["MAP_LENGTH"]
136         ind = y % 2
137         diag_west = x + (ind > 0)
138         diag_east = x + (ind < (length - 1))
139         pos = (y * length) + x
140         if (y > 0 and diag_east
141             and type == chr(world_db["MAP"][pos - length + ind])) \
142            or (x < (length - 1)
143                and type == chr(world_db["MAP"][pos + 1])) \
144            or (y < (length - 1) and diag_east
145                and type == chr(world_db["MAP"][pos + length + ind])) \
146            or (y > 0 and diag_west
147                and type == chr(world_db["MAP"][pos - length - (not ind)])) \
148            or (x > 0
149                and type == chr(world_db["MAP"][pos - 1])) \
150            or (y < (length - 1) and diag_west
151                and type == chr(world_db["MAP"][pos + length - (not ind)])):
152             return True
153         return False
154
155     world_db["MAP"] = bytearray(b'~' * (world_db["MAP_LENGTH"] ** 2))
156     length = world_db["MAP_LENGTH"]
157     add_half_width = (not (length % 2)) * int(length / 2)
158     world_db["MAP"][int((length ** 2) / 2) + add_half_width] = ord(".")
159     while (1):
160         y = rand.next() % length
161         x = rand.next() % length
162         pos = (y * length) + x
163         if "~" == chr(world_db["MAP"][pos]) and is_neighbor((y, x), "."):
164             if y == 0 or y == (length - 1) or x == 0 or x == (length - 1):
165                 break
166             world_db["MAP"][pos] = ord(".")
167     n_trees = int((length ** 2) / 16)
168     i_trees = 0
169     while (i_trees <= n_trees):
170         single_allowed = rand.next() % 32
171         y = rand.next() % length
172         x = rand.next() % length
173         pos = (y * length) + x
174         if "." == chr(world_db["MAP"][pos]) \
175           and ((not single_allowed) or is_neighbor((y, x), "X")):
176             world_db["MAP"][pos] = ord("X")
177             i_trees += 1
178     n_colons = int((length ** 2) / 16)
179     i_colons = 0
180     while (i_colons <= n_colons):
181         single_allowed = rand.next() % 256
182         y = rand.next() % length
183         x = rand.next() % length
184         pos = (y * length) + x
185         if ("." == chr(world_db["MAP"][pos])
186           and ((not single_allowed) or is_neighbor((y, x), ":"))):
187             world_db["MAP"][pos] = ord(":")
188             i_colons += 1
189     altar_placed = False
190     while not altar_placed:
191         y = rand.next() % length
192         x = rand.next() % length
193         pos = (y * length) + x
194         if (("." == chr(world_db["MAP"][pos]
195              or ":" == chr(world_db["MAP"][pos]))
196             and not is_neighbor((y, x), "X"))):
197             world_db["MAP"][pos] = ord("_")
198             world_db["altar"] = (y, x)
199             altar_placed = True
200
201 def ai(t):
202     from server.ai import get_dir_to_target, get_inventory_slot_to_consume, \
203         standing_on_food
204     t["T_COMMAND"] = [id for id in world_db["ThingActions"]
205                       if world_db["ThingActions"][id]["TA_NAME"] == "wait"][0]
206     eating = len([id for id in world_db["ThingActions"]
207                   if world_db["ThingActions"][id]["TA_NAME"] == "use"]) > 0
208     picking = len([id for id in world_db["ThingActions"]
209                    if world_db["ThingActions"][id]["TA_NAME"] == "pickup"]) > 0
210     if eating and picking:
211         if get_dir_to_target(t, "f"):
212             return
213         sel = get_inventory_slot_to_consume(t)
214         if -1 != sel:
215             t["T_COMMAND"] = [id for id in world_db["ThingActions"]
216                               if world_db["ThingActions"][id]["TA_NAME"]
217                                  == "use"][0]
218             t["T_ARGUMENT"] = sel
219         elif standing_on_food(t) and (len(t["T_CARRIES"]) <
220                 world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]):
221                 t["T_COMMAND"] = [id for id in world_db["ThingActions"]
222                                   if world_db["ThingActions"][id]["TA_NAME"]
223                                   == "pickup"][0]
224         else:
225             going_to_known_food_spot = get_dir_to_target(t, "c")
226             if not going_to_known_food_spot:
227                 aiming_for_walking_food = get_dir_to_target(t, "a")
228                 if not aiming_for_walking_food:
229                     get_dir_to_target(t, "s")
230
231 def actor_pickup(t):
232     from server.ai import eat_vs_hunger_threshold
233     used_slots = len(t["T_CARRIES"])
234     if used_slots < world_db["ThingTypes"][t["T_TYPE"]]["TT_STORAGE"]:
235         ids = [id for id in world_db["Things"] if world_db["Things"][id] != t
236                if not world_db["Things"][id]["carried"]
237                if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
238                if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]
239         if len(ids):
240             lowest_tid = -1
241             eat_cost = eat_vs_hunger_threshold(t["T_TYPE"])
242             for iid in ids:
243                 tid = world_db["Things"][iid]["T_TYPE"] 
244                 if lowest_tid == -1 or tid < lowest_tid:
245                     if (t != world_db["Things"][0] and
246                         (world_db["ThingTypes"][tid]["TT_TOOL"] != "food"
247                          or (world_db["ThingTypes"][tid]["TT_TOOLPOWER"]
248                              <= eat_cost))):
249                         continue
250                     id = iid
251                     lowest_tid = tid
252             world_db["Things"][id]["carried"] = True
253             ty = world_db["Things"][id]["T_TYPE"]
254             if (t != world_db["Things"][0]
255                 and world_db["Things"][id]["T_PLAYERDROP"]
256                 and world_db["ThingTypes"][ty]["TT_TOOL"] == "food"):
257                 score = int(world_db["ThingTypes"][ty]["TT_TOOLPOWER"] / 32)
258                 world_db["GOD_FAVOR"] += score
259                 world_db["Things"][id]["T_PLAYERDROP"] = 0
260             t["T_CARRIES"].append(id)
261             if t == world_db["Things"][0]:
262                 log("You PICK UP an object.")
263     elif t == world_db["Things"][0]:
264         log("Can't pick up object: No storage room to carry more.")
265
266
267 def actor_drop(t):
268     """Make t rop Thing from inventory to ground indexed by T_ARGUMENT."""
269     if len(t["T_CARRIES"]):
270         id = t["T_CARRIES"][t["T_ARGUMENT"]]
271         t["T_CARRIES"].remove(id)
272         world_db["Things"][id]["carried"] = False
273         if t == world_db["Things"][0]:
274             log("You DROP an object.")
275             world_db["Things"][id]["T_PLAYERDROP"] = 1
276
277
278 def actor_use(t):
279     if len(t["T_CARRIES"]):
280         id = t["T_CARRIES"][t["T_ARGUMENT"]]
281         type = world_db["Things"][id]["T_TYPE"]
282         if type == world_db["SLIPPERS"]:
283             if t == world_db["Things"][0]:
284                 log("You use the " + world_db["ThingTypes"][type]["TT_NAME"]
285                     + ". It glows in wondrous colors, and emits a sound as if "
286                     + "from a dying cat. The Island God laughs.\n")
287             t["T_LIFEPOINTS"] = 1
288             from server.config.misc import decrement_lifepoints_func
289             decrement_lifepoints_func(t)
290         elif (world_db["ThingTypes"][type]["TT_TOOL"] == "carpentry"):
291             pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
292             if (world_db["MAP"][pos] == ord("X")
293                 or world_db["MAP"][pos] == ord("|")):
294                 return
295             for id in [id for id in world_db["Things"]
296                        if not world_db["Things"][id] == t
297                        if not world_db["Things"][id]["carried"]
298                        if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
299                        if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]:
300                  return
301             wood_id = None
302             for id in t["T_CARRIES"]:
303                 type_material = world_db["Things"][id]["T_TYPE"]
304                 if (world_db["ThingTypes"][type_material]["TT_TOOL"]
305                     == "wood"):
306                     wood_id = id
307                     break
308             if wood_id != None:
309                 t["T_CARRIES"].remove(wood_id)
310                 del world_db["Things"][wood_id]
311                 world_db["MAP"][pos] = ord("|")
312                 log("With your " + world_db["ThingTypes"][type]["TT_NAME"]
313                     + " you build a wooden barrier from your "
314                     + world_db["ThingTypes"][type_material]["TT_NAME"] + ".")
315         elif world_db["ThingTypes"][type]["TT_TOOL"] == "food":
316             t["T_CARRIES"].remove(id)
317             del world_db["Things"][id]
318             t["T_SATIATION"] += world_db["ThingTypes"][type]["TT_TOOLPOWER"]
319             if t == world_db["Things"][0]:
320                 log("You CONSUME this object.")
321         elif t == world_db["Things"][0]:
322             log("You try to use this object, but FAIL.")
323
324 def decrement_lifepoints(t):
325     t["T_LIFEPOINTS"] -= 1
326     _id = [_id for _id in world_db["Things"] if world_db["Things"][_id] == t][0]
327     if 0 == t["T_LIFEPOINTS"]:
328         sadness = world_db["ThingTypes"][t["T_TYPE"]]["TT_LIFEPOINTS"]
329         for id in t["T_CARRIES"]:
330             t["T_CARRIES"].remove(id)
331             world_db["Things"][id]["T_POSY"] = t["T_POSY"]
332             world_db["Things"][id]["T_POSX"] = t["T_POSX"]
333             world_db["Things"][id]["carried"] = False
334         t["T_TYPE"] = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"]
335         if world_db["Things"][0] == t:
336             t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
337             log("You die.")
338             log("See README on how to start over.")
339         else:
340             t["fovmap"] = False
341             t["T_MEMMAP"] = False
342             t["T_MEMDEPTHMAP"] = False
343             t["T_MEMTHING"] = []
344         return sadness
345     return 0
346
347 def actor_move(t):
348
349     def enter_altar():
350         from server.new_thing import new_Thing
351         if world_db["FAVOR_STAGE"] > 9000:
352            log("You step on a soul-less slab of stone.")
353            return
354         log("YOU ENTER SACRED GROUND.")
355         if world_db["FAVOR_STAGE"] == 0:
356             world_db["FAVOR_STAGE"] = 1
357             log("The Island God speaks to you: \"I don't trust you. You intrud"
358                  + "e on the island's affairs. I think you're a nuisance at be"
359                  + "st, and a danger to my children at worst. I will give you "
360                  + "a chance to lighten my mood, however: For a while now, I'v"
361                  + "e been trying to spread the plant "
362                  + world_db["ThingTypes"][world_db["PLANT_0"]]["TT_NAME"]
363                  + " (\""
364                  + world_db["ThingTypes"][world_db["PLANT_0"]]["TT_SYMBOL"]
365                  + "\"). I have not been very successful so far. Maybe you can"
366                  + " make yourself useful there. I will count each further "
367                  + world_db["ThingTypes"][world_db["PLANT_0"]]["TT_NAME"]
368                  + " that grows to your favor.\"")
369         elif world_db["GOD_FAVOR"] > 150:
370             world_db["FAVOR_STAGE"] = 9001
371             log("The Island God speaks to you: \"You have proven yourself wort"
372                  + "hy of my respect. You were a good citizen to the island, a"
373                  + "nd sometimes a better steward to its inhabitants than me. "
374                  + "The island shall miss you when you leave. But you have ear"
375                  + "ned the right to do so. Take this "
376                  + world_db["ThingTypes"][world_db["SLIPPERS"]]["TT_NAME"]
377                  + " and USE it when you please. It will take you to where you"
378                  + " came from. (But do feel free to stay here as long as you "
379                  + "like.)\"")
380             id = id_setter(-1, "Things")
381             world_db["Things"][id] = new_Thing(world_db["SLIPPERS"],
382                                                world_db["altar"])
383
384     from server.config.world_data import symbols_passable
385     from server.build_fov_map import build_fov_map
386     from server.config.misc import decrement_lifepoints_func
387     from server.new_thing import new_Thing
388     passable = False
389     move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
390                                      t["T_POSY"], t["T_POSX"])
391     if 1 == move_result[0]:
392         pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
393         hitted = [id for id in world_db["Things"]
394                   if world_db["Things"][id] != t
395                   if world_db["Things"][id]["T_LIFEPOINTS"]
396                   if world_db["Things"][id]["T_POSY"] == move_result[1]
397                   if world_db["Things"][id]["T_POSX"] == move_result[2]]
398         if len(hitted):
399             hit_id = hitted[0]
400             if t == world_db["Things"][0]:
401                 hitted_type = world_db["Things"][hit_id]["T_TYPE"]
402                 hitted_name = world_db["ThingTypes"][hitted_type]["TT_NAME"]
403                 log("You WOUND " + hitted_name + ".")
404                 world_db["GOD_FAVOR"] -= 1
405             elif 0 == hit_id:
406                 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
407                 log(hitter_name +" WOUNDS you.")
408             test = decrement_lifepoints_func(world_db["Things"][hit_id])
409             if test and t == world_db["Things"][0]:
410                 world_db["GOD_FAVOR"] -= test 
411             return
412         if (ord("X") == world_db["MAP"][pos]
413             or ord("|") == world_db["MAP"][pos]):
414             carries_axe = False
415             for id in t["T_CARRIES"]:
416                 type = world_db["Things"][id]["T_TYPE"]
417                 if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
418                     carries_axe = True
419                     break
420             if carries_axe:
421                 axe_name = world_db["ThingTypes"][type]["TT_NAME"]
422                 if t == world_db["Things"][0]:
423                     log("With your " + axe_name + ", you chop!")
424                     if ord("X") == world_db["MAP"][pos]:
425                         world_db["GOD_FAVOR"] -= 1
426                 chop_power = world_db["ThingTypes"][type]["TT_TOOLPOWER"]
427
428                 case_X = world_db["MAP"][pos] == ord("X")
429                 if (chop_power > 0
430                     and ((case_X and
431                           0 == int(rand.next() / chop_power))
432                     or (not case_X and
433                              0 == int(rand.next() / (3 * chop_power))))):
434                     if t == world_db["Things"][0]:
435                         log("You chop it DOWN.")
436                         world_db["GOD_FAVOR"] -= 10
437                     world_db["MAP"][pos] = ord(".")
438                     i = 3 if case_X else 1
439                     for i in range(i):
440                         id = id_setter(-1, "Things")
441                         world_db["Things"][id] = \
442                           new_Thing(world_db["LUMBER"],
443                                     (move_result[1], move_result[2]))
444                     build_fov_map(t)
445                 return
446         passable = chr(world_db["MAP"][pos]) in symbols_passable
447     dir = [dir for dir in directions_db
448            if directions_db[dir] == chr(t["T_ARGUMENT"])][0]
449     if passable:
450         t["T_POSY"] = move_result[1]
451         t["T_POSX"] = move_result[2]
452         for id in t["T_CARRIES"]:
453             world_db["Things"][id]["T_POSY"] = move_result[1]
454             world_db["Things"][id]["T_POSX"] = move_result[2]
455         build_fov_map(t)
456         if t == world_db["Things"][0]:
457             log("You MOVE " + dir + ".")
458             if (move_result[1] == world_db["altar"][0] and
459                 move_result[2] == world_db["altar"][1]):
460                 enter_altar()
461
462 def command_ttid(id_string):
463     id = id_setter(id_string, "ThingTypes", command_ttid)
464     if None != id:
465         world_db["ThingTypes"][id] = {
466             "TT_NAME": "(none)",
467             "TT_TOOLPOWER": 0,
468             "TT_LIFEPOINTS": 0,
469             "TT_PROLIFERATE": 0,
470             "TT_START_NUMBER": 0,
471             "TT_STORAGE": 0,
472             "TT_SYMBOL": "?",
473             "TT_CORPSE_ID": id,
474             "TT_TOOL": ""
475         }
476
477 def command_worldactive(worldactive_string):
478     val = integer_test(worldactive_string, 0, 1)
479     if None != val:
480         if 0 != world_db["WORLD_ACTIVE"]:
481             if 0 == val:
482                 set_world_inactive()
483             else:
484                 print("World already active.")
485         elif 0 == world_db["WORLD_ACTIVE"]:
486             wait_exists = False
487             for ThingAction in world_db["ThingActions"]:
488                 if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
489                     wait_exists = True
490                     break
491             player_exists = False
492             for Thing in world_db["Things"]:
493                 if 0 == Thing:
494                     player_exists = True
495                     break
496             altar_found = False
497             if world_db["MAP"]:
498                 pos = world_db["MAP"].find(b'_')
499                 if pos > 0:
500                     y = int(pos / world_db["MAP_LENGTH"])
501                     x = pos % world_db["MAP_LENGTH"]
502                     world_db["altar"] = (y, x)
503                     altar_found = True
504             valid_slippers = world_db["SLIPPERS"] in world_db["ThingTypes"]
505             valid_plant0 = world_db["PLANT_0"] in world_db["ThingTypes"]
506             valid_lumber = world_db["LUMBER"] in world_db["ThingTypes"]
507             if altar_found and wait_exists and player_exists and \
508                     world_db["MAP"] and valid_slippers and valid_plant0 and \
509                     valid_lumber:
510                 for id in world_db["Things"]:
511                     if world_db["Things"][id]["T_LIFEPOINTS"]:
512                         build_fov_map(world_db["Things"][id])
513                         if 0 == id:
514                             update_map_memory(world_db["Things"][id], False)
515                 if not world_db["Things"][0]["T_LIFEPOINTS"]:
516                     empty_fovmap = bytearray(b" " * world_db["MAP_LENGTH"] ** 2)
517                     world_db["Things"][0]["fovmap"] = empty_fovmap
518                 world_db["WORLD_ACTIVE"] = 1
519             else:
520                 print("Ignoring: Not all conditions for world activation met.")
521
522 def command_slippers(str_int):
523     val = integer_test(str_int, 0)
524     if None != val:
525         world_db["SLIPPERS"] = val
526         if world_db["WORLD_ACTIVE"] and \
527            world_db["SLIPPERS"] not in world_db["ThingTypes"]:
528             world_db["WORLD_ACTIVE"] = 0
529             print("SLIPPERS matches no known ThingTypes, deactivating world.")
530
531 def command_plant0(str_int):
532     val = integer_test(str_int, 0)
533     if None != val:
534         world_db["PLANT_0"] = val
535         if world_db["WORLD_ACTIVE"] and \
536            world_db["PLANT_0"] not in world_db["ThingTypes"]:
537             world_db["WORLD_ACTIVE"] = 0
538             print("PLANT_0 matches no known ThingTypes, deactivating world.")
539
540 def play_move(str_arg):
541     if action_exists("move"):
542         from server.config.world_data import directions_db, symbols_passable
543         t = world_db["Things"][0]
544         if not str_arg in directions_db:
545             print("Illegal move direction string.")
546             return
547         dir = ord(directions_db[str_arg])
548         from server.utils import mv_yx_in_dir_legal
549         move_result = mv_yx_in_dir_legal(chr(dir), t["T_POSY"], t["T_POSX"])
550         if 1 == move_result[0]:
551             pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
552             if ord("~") == world_db["MAP"][pos]:
553                 log("You can't SWIM.")
554                 return
555             if (ord("X") == world_db["MAP"][pos]
556                 or ord("|") == world_db["MAP"][pos]):
557                 carries_axe = False
558                 for id in t["T_CARRIES"]:
559                     type = world_db["Things"][id]["T_TYPE"]
560                     if world_db["ThingTypes"][type]["TT_TOOL"] == "axe":
561                         world_db["Things"][0]["T_ARGUMENT"] = dir
562                         set_command("move")
563                         return
564             if chr(world_db["MAP"][pos]) in symbols_passable:
565                 world_db["Things"][0]["T_ARGUMENT"] = dir
566                 set_command("move")
567                 return
568         log("You CAN'T move there.")
569
570 def play_use(str_arg):
571     if action_exists("use"):
572         t = world_db["Things"][0]
573         if 0 == len(t["T_CARRIES"]):
574             log("You have NOTHING to use in your inventory.")
575         else:
576             val = integer_test(str_arg, 0, 255)
577             if None != val and val < len(t["T_CARRIES"]):
578                 id = t["T_CARRIES"][val]
579                 type = world_db["Things"][id]["T_TYPE"]
580                 if (world_db["ThingTypes"][type]["TT_TOOL"] == "axe"
581                       and t == world_db["Things"][0]):
582                     log("To use this item for chopping, move towards a tree "
583                          + "while carrying it in your inventory.")
584                     return
585                 elif (world_db["ThingTypes"][type]["TT_TOOL"] == "carpentry"):
586                     pos = t["T_POSY"] * world_db["MAP_LENGTH"] + t["T_POSX"]
587                     if (world_db["MAP"][pos] == ord("X")
588                         or world_db["MAP"][pos] == ord("|")):
589                         log("Can't build when standing on barrier.")
590                         return
591                     for id in [id for id in world_db["Things"]
592                                if not world_db["Things"][id] == t
593                                if not world_db["Things"][id]["carried"]
594                                if world_db["Things"][id]["T_POSY"] == t["T_POSY"]
595                                if world_db["Things"][id]["T_POSX"] == t["T_POSX"]]:
596                          log("Can't build when standing objects.")
597                          return
598                     wood_id = None
599                     for id in t["T_CARRIES"]:
600                         type_material = world_db["Things"][id]["T_TYPE"]
601                         if (world_db["ThingTypes"][type_material]["TT_TOOL"]
602                             == "wood"):
603                             wood_id = id
604                             break
605                     if wood_id == None:
606                         log("You can't use a "
607                             + world_db["ThingTypes"][type]["TT_NAME"]
608                             + " without some wood in your inventory.")
609                         return
610                 elif type != world_db["SLIPPERS"] and not \
611                         world_db["ThingTypes"][type]["TT_TOOL"] == "food":
612                     log("You CAN'T consume this thing.")
613                     return
614                 world_db["Things"][0]["T_ARGUMENT"] = val
615                 set_command("use")
616             else:
617                 print("Illegal inventory index.")
618
619 def command_lumber(str_int):  # #
620     val = integer_test(str_int, 0)
621     if None != val:
622         world_db["LUMBER"] = val
623         if world_db["WORLD_ACTIVE"] and \
624            world_db["LUMBER"] not in world_db["ThingTypes"]:
625             world_db["WORLD_ACTIVE"] = 0
626             print("LUMBER matches no known ThingTypes, deactivating world.")
627
628 strong_write(io_db["file_out"], "PLUGIN PleaseTheIslandGod\n")
629
630 if not "GOD_FAVOR" in world_db:
631     world_db["GOD_FAVOR"] = 0
632 if not "FAVOR_STAGE" in world_db:
633     world_db["FAVOR_STAGE"] = 0
634 if not "SLIPPERS" in world_db:
635     world_db["SLIPPERS"] = 0
636 if not "PLANT_0" in world_db:
637     world_db["PLANT_0"] = 0
638 if not "LUMBER" in world_db:
639     world_db["LUMBER"] = 0
640 io_db["worldstate_write_order"] += [["GOD_FAVOR", "world_int"]]
641
642 import server.config.world_data
643 server.config.world_data.symbols_passable += ":_"
644
645 from server.config.world_data import thing_defaults
646 thing_defaults["T_PLAYERDROP"] = 0
647
648 import server.config.actions
649 server.config.actions.action_db["actor_move"] = actor_move
650 server.config.actions.action_db["actor_pickup"] = actor_pickup
651 server.config.actions.action_db["actor_drop"] = actor_drop
652 server.config.actions.action_db["actor_use"] = actor_use
653 server.config.actions.ai_func = ai
654
655 from server.config.commands import commands_db
656 commands_db["TT_ID"] = (1, False, command_ttid)
657 commands_db["GOD_FAVOR"] = (1, False, setter(None, "GOD_FAVOR", -32768, 32767))
658 commands_db["TT_STORAGE"] = (1, False, setter("ThingType", "TT_STORAGE", 0, 255))
659 commands_db["T_PLAYERDROP"] = (1, False, setter("Thing", "T_PLAYERDROP", 0, 1))
660 commands_db["WORLD_ACTIVE"] = (1, False, command_worldactive)
661 commands_db["FAVOR_STAGE"] = (1, False, setter(None, "FAVOR_STAGE", 0, 1))
662 commands_db["SLIPPERS"] = (1, False, command_slippers)
663 commands_db["PLANT_0"] = (1, False, command_plant0)
664 commands_db["LUMBER"] = (1, False, command_lumber)
665 commands_db["use"] = (1, False, play_use)
666 commands_db["move"] = (1, False, play_move)
667
668 import server.config.misc
669 server.config.misc.make_map_func = make_map
670 server.config.misc.thingproliferation_func = thingproliferation
671 server.config.misc.make_world = make_world
672 server.config.decrement_lifepoints_func = decrement_lifepoints