1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
6 from server.config.world_data import world_db
10 from server.make_map import new_pos, is_neighbor
11 from server.utils import rand
12 world_db["MAP"] = bytearray(b'X' * (world_db["MAP_LENGTH"] ** 2))
13 length = world_db["MAP_LENGTH"]
14 add_half_width = (not (length % 2)) * int(length / 2)
15 world_db["MAP"][int((length ** 2) / 2) + add_half_width] = ord("#")
18 if "X" == chr(world_db["MAP"][pos]) and is_neighbor((y, x), "#"):
19 if y == 0 or y == (length - 1) or x == 0 or x == (length - 1):
21 world_db["MAP"][pos] = ord("#")
22 n_trees = int((length ** 2) / 16)
24 while (i_trees <= n_trees):
25 single_allowed = rand.next() % 32
27 if "#" == chr(world_db["MAP"][pos]) \
28 and ((not single_allowed) or is_neighbor((y, x), ".")):
29 world_db["MAP"][pos] = ord(".")
34 from server.build_fov_map import build_fov_map
35 from server.utils import mv_yx_in_dir_legal, rand
36 from server.config.world_data import directions_db, symbols_passable
38 move_result = mv_yx_in_dir_legal(chr(t["T_ARGUMENT"]),
39 t["T_POSY"], t["T_POSX"])
40 if 1 == move_result[0]:
41 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
42 hitted = [tid for tid in world_db["Things"]
43 if world_db["Things"][tid] != t
44 if world_db["Things"][tid]["T_LIFEPOINTS"]
45 if world_db["Things"][tid]["T_POSY"] == move_result[1]
46 if world_db["Things"][tid]["T_POSX"] == move_result[2]]
49 hitted_tid = world_db["Things"][hit_id]["T_TYPE"]
50 if t == world_db["Things"][0]:
51 hitted_name = world_db["ThingTypes"][hitted_tid]["TT_NAME"]
52 log("You BUMP into " + hitted_name + ".")
54 hitter_name = world_db["ThingTypes"][t["T_TYPE"]]["TT_NAME"]
55 log(hitter_name +" BUMPS into you.")
57 passable = chr(world_db["MAP"][pos]) in symbols_passable
58 direction = [direction for direction in directions_db
59 if directions_db[direction] == chr(t["T_ARGUMENT"])][0]
61 t["T_POSY"] = move_result[1]
62 t["T_POSX"] = move_result[2]
63 t["pos"] = move_result[1] * world_db["MAP_LENGTH"] + move_result[2]
66 if ord("#") == world_db["MAP"][pos] and 0 == int(rand.next() % 5):
67 world_db["MAP"][pos] = ord(".")
72 from server.ai import ai
73 from server.config.actions import action_db
74 from server.config.misc import calc_effort
75 from server.update_map_memory import update_map_memory
76 from server.io import try_worldstate_update
77 from server.config.io import io_db
78 while world_db["Things"][0]["T_LIFEPOINTS"]:
79 for tid in [tid for tid in world_db["Things"]]:
80 if not tid in world_db["Things"]:
82 Thing = world_db["Things"][tid]
83 if Thing["T_LIFEPOINTS"]:
84 if not Thing["T_COMMAND"]:
85 update_map_memory(Thing)
89 if Thing["T_LIFEPOINTS"]:
90 Thing["T_PROGRESS"] += 1
91 taid = [a for a in world_db["ThingActions"]
92 if a == Thing["T_COMMAND"]][0]
93 ThingAction = world_db["ThingActions"][taid]
94 effort = calc_effort(ThingAction, Thing)
95 if Thing["T_PROGRESS"] == effort:
96 action = action_db["actor_" + ThingAction["TA_NAME"]]
98 Thing["T_COMMAND"] = 0
99 Thing["T_PROGRESS"] = 0
100 world_db["TURN"] += 1
101 io_db["worldstate_updateable"] = True
102 try_worldstate_update()
103 world_db["turn_over"] = turn_over
106 def play_move(str_arg):
107 """Try "move" as player's T_COMMAND, str_arg as T_ARGUMENT / direction."""
108 if action_exists("move") and world_db["WORLD_ACTIVE"]:
109 from server.config.world_data import directions_db, symbols_passable
110 t = world_db["Things"][0]
111 if not str_arg in directions_db:
112 print("Illegal move direction string.")
114 d = ord(directions_db[str_arg])
115 from server.utils import mv_yx_in_dir_legal
116 move_result = mv_yx_in_dir_legal(chr(d), t["T_POSY"], t["T_POSX"])
117 if 1 == move_result[0]:
118 pos = (move_result[1] * world_db["MAP_LENGTH"]) + move_result[2]
119 if ord("#") == world_db["MAP"][pos]:
121 world_db["Things"][0]["T_ARGUMENT"] = d
122 world_db["set_command"]("move")
124 if chr(world_db["MAP"][pos]) in symbols_passable:
125 world_db["Things"][0]["T_ARGUMENT"] = d
126 world_db["set_command"]("move")
128 log("You CAN'T eat your way through there.")
132 """Call ai() on player Thing, then turn_over()."""
133 from server.ai import ai
134 if world_db["WORLD_ACTIVE"]:
135 ai(world_db["Things"][0])
136 world_db["turn_over"]()
139 def set_command(action):
140 """Set player's T_COMMAND, then call turn_over()."""
141 tid = [x for x in world_db["ThingActions"]
142 if world_db["ThingActions"][x]["TA_NAME"] == action][0]
143 world_db["Things"][0]["T_COMMAND"] = tid
144 world_db["turn_over"]()
145 world_db["set_command"] = set_command
149 """Try "wait" as player's T_COMMAND."""
150 if world_db["WORLD_ACTIVE"]:
151 world_db["set_command"]("wait")
154 #import server.config.actions
155 #server.config.actions.actor_move_attempts_hook = actor_move_attempts_hook
156 import server.config.world_data
157 server.config.world_data.symbols_hide += "#"
158 server.config.world_data.thing_defaults["STOMACH"] = 0
159 import server.config.make_world_helpers
160 server.config.make_world_helpers.make_map = make_map
161 from server.config.commands import commands_db
162 commands_db["ai"] = (0, False, command_ai)
163 commands_db["move"] = (1, False, play_move)
164 commands_db["wait"] = (0, False, play_wait)
165 commands_db["drop"] = (1, False, lambda x: None)
166 commands_db["use"] = (1, False, lambda x: None)
167 commands_db["pickup"] = (0, False, lambda: None)
168 from server.actions import actor_wait
169 import server.config.actions
170 server.config.actions.action_db = {
171 "actor_wait": actor_wait,
172 "actor_move": actor_move
175 strong_write(io_db["file_out"], "PLUGIN TheCrawlingEater\n")