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