"take_thing": "z",
"drop_thing": "u",
"teleport": "p",
+ "door": "D",
"help": "h",
"toggle_map_mode": "L",
"toggle_tile_draw": "m",
if not speaker:
raise GameError('need to be logged in for this')
largest_audible_distance = 20
- dijkstra_map = DijkstraMap(game.maps, speaker.position,
+ dijkstra_map = DijkstraMap(game.things, game.maps, speaker.position,
largest_audible_distance, game.get_map)
for c_id in game.sessions:
listener = game.get_player(c_id)
class SourcedMap(Map):
- def __init__(self, source_maps, source_center, radius, get_map):
+ def __init__(self, things, source_maps, source_center, radius, get_map):
self.source_maps = source_maps
self.radius = radius
example_map = get_map(YX(0, 0))
for yx in self:
big_yx, _ = self.source_yxyx(yx)
get_map(big_yx)
+ self.source_map_segment = ''
+ obstacles = {}
+ for yxyx in [t.position for t in things if t.blocking]:
+ if yxyx == source_center:
+ continue
+ if yxyx[0] not in obstacles:
+ obstacles[yxyx[0]] = []
+ obstacles[yxyx[0]] += [yxyx[1]]
+ for yx in self:
+ big_yx, little_yx = self.source_yxyx(yx)
+ if big_yx in obstacles and little_yx in obstacles[big_yx]:
+ self.source_map_segment += 'X'
+ else:
+ self.source_map_segment += self.source_maps[big_yx][little_yx]
def source_yxyx(self, yx):
absolute_yx = yx + self.offset
self.terrain = [255] * self.size_i
self[self.center] = 0
shrunk = True
- source_map_segment = ''
- for yx in self:
- big_yx, little_yx = self.source_yxyx(yx)
- source_map_segment += self.source_maps[big_yx][little_yx]
while shrunk:
shrunk = False
for i in range(self.size_i):
- if source_map_segment[i] == 'X':
+ if self.source_map_segment[i] == 'X':
continue
neighbors = self.geometry.get_neighbors_i(i)
for direction in [d for d in neighbors if neighbors[d]]:
self.shadow_cones = []
self.circle_out(self.center, self.shadow_process)
- def throws_shadow(self, big_yx, little_yx):
- return self.source_maps[big_yx][little_yx] == 'X'
+ def throws_shadow(self, yx):
+ return self.source_map_segment[self.get_position_index(yx)] == 'X'
- def shadow_process(self, yx, source_yxyx, distance_to_center, dir_i, dir_progress):
+ def shadow_process(self, yx, distance_to_center, dir_i, dir_progress):
# Possible optimization: If no shadow_cones yet and self[yx] == '.',
# skip all.
CIRCLE = 360 # Since we'll float anyways, number is actually arbitrary.
if in_shadow_cone(cone):
return
self[yx] = '.'
- if self.throws_shadow(*source_yxyx):
+ if self.throws_shadow(yx):
unmerged = True
while merge_cone(cone):
unmerged = False
for dir_progress in range(distance):
direction = self.circle_out_directions[dir_i]
yx = self.circle_out_move(yx, direction)
- source_yxyx = self.source_yxyx(yx)
- f(yx, source_yxyx, distance, dir_i, dir_progress)
+ f(yx, distance, dir_i, dir_progress)
distance += 1
+
class FovMapHex(FovMap):
circle_out_directions = ('DOWNLEFT', 'LEFT', 'UPLEFT',
'UPRIGHT', 'RIGHT', 'DOWNRIGHT')
def do(self):
self.thing.carrying = None
+
+
+
+class Task_DOOR(Task):
+ todo = 1
+
+ def do(self):
+ self.thing.carrying = None
+ action_radius = list(self.thing.game.map_geometry.
+ get_neighbors_yxyx(self.thing.position).values())
+ for t in [t for t in self.thing.game.things if
+ t.type_ == 'Door' and t.position in action_radius]:
+ if t.blocking:
+ t.open()
+ else:
+ t.close()
+class Thing_DoorSpawner(ThingSpawner):
+ child_type = 'Door'
+
+
+
+class Thing_Door(Thing):
+ symbol_hint = 'D'
+ blocking = False
+ portable = True
+
+ def open(self):
+ self.blocking = False
+ self.portable = True
+
+ def close(self):
+ self.blocking = True
+ self.portable = False
+
+
+
class ThingAnimate(Thing):
blocking = True
if self._fov:
return self._fov
fov_map_class = self.game.map_geometry.fov_map_class
- self._fov = fov_map_class(self.game.maps, self.position, 12,
- self.game.get_map)
+ self._fov = fov_map_class(self.game.things, self.game.maps, self.position,
+ 12, self.game.get_map)
return self._fov
def fov_test(self, big_yx, little_yx):
<td>
<button id="take_thing"></button>
<button id="drop_thing"></button>
+ <button id="door"></button>
<button id="teleport"></button>
</td>
</tr>
<li>teleport: <input id="key_teleport" type="text" value="p" />
<li>pick up thing: <input id="key_take_thing" type="text" value="z" />
<li>drop thing: <input id="key_drop_thing" type="text" value="u" />
+<li>open/close: <input id="key_door" type="text" value="D" />
<li><input id="key_switch_to_chat" type="text" value="t" />
<li><input id="key_switch_to_play" type="text" value="p" />
<li><input id="key_switch_to_study" type="text" value="?" />
'teleport': 'teleport',
'take_thing': 'pick up thing',
'drop_thing': 'drop thing',
+ 'door': 'open/close',
'toggle_map_mode': 'toggle map view',
'toggle_tile_draw': 'toggle protection character drawing',
'hex_move_upleft': 'up-left',
};
} else if (tokens[0] === 'TASKS') {
game.tasks = tokens[1].split(',');
+ console.log(game.tasks);
tui.mode_write.legal = game.tasks.includes('WRITE');
} else if (tokens[0] === 'THING_TYPE') {
game.thing_types[tokens[1]] = tokens[2]
'take_thing': 'PICK_UP',
'drop_thing': 'DROP',
'move': 'MOVE',
+ 'door': 'DOOR',
},
init: function() {
this.mode_chat.available_modes = ["play", "study", "edit", "admin_enter"]
this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
- this.mode_play.available_actions = ["move", "take_thing", "drop_thing", "teleport"];
+ this.mode_play.available_actions = ["move", "take_thing", "drop_thing",
+ "teleport", "door"];
this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
this.mode_study.available_actions = ["toggle_map_mode", "move_explorer"];
this.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
server.send(["TASK:PICK_UP"]);
} else if (event.key === tui.keys.drop_thing && tui.task_action_on('drop_thing')) {
server.send(["TASK:DROP"]);
+ } else if (event.key === tui.keys.door && tui.task_action_on('door')) {
+ server.send(["TASK:DOOR"]);
} else if (event.key in tui.movement_keys && tui.task_action_on('move')) {
server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
} else if (event.key === tui.keys.teleport) {
document.getElementById("flatten").onclick = function() {
server.send(['TASK:FLATTEN_SURROUNDINGS', tui.password]);
};
+document.getElementById("door").onclick = function() {
+ server.send(['TASK:DOOR']);
+};
document.getElementById("teleport").onclick = function() {
game.teleport();
};
cmd_GOD_THING_PROTECTION, cmd_THING_PROTECTION,
cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT)
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
- Task_DROP, Task_FLATTEN_SURROUNDINGS)
+ Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR)
from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
- Thing_SpawnPoint, Thing_SpawnPointSpawner)
+ Thing_SpawnPoint, Thing_SpawnPointSpawner,
+ Thing_Door, Thing_DoorSpawner)
from plomrogue.config import config
game = Game(config['savefile'])
game.register_task(Task_FLATTEN_SURROUNDINGS)
game.register_task(Task_PICK_UP)
game.register_task(Task_DROP)
+game.register_task(Task_DOOR)
game.register_thing_type(Thing_Player)
game.register_thing_type(Thing_Item)
game.register_thing_type(Thing_ItemSpawner)
game.register_thing_type(Thing_SpawnPoint)
game.register_thing_type(Thing_SpawnPointSpawner)
+game.register_thing_type(Thing_Door)
+game.register_thing_type(Thing_DoorSpawner)
game.read_savefile()
game.io.start_loop()
for port in config['servers']:
import json
self.mode_play.available_modes = ["chat", "study", "edit", "admin_enter"]
self.mode_play.available_actions = ["move", "take_thing", "drop_thing",
- "teleport"]
+ "teleport", "door"]
self.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
self.mode_study.available_actions = ["toggle_map_mode", "move_explorer"]
self.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
'take_thing': 'z',
'drop_thing': 'u',
'teleport': 'p',
+ 'door': 'D',
'help': 'h',
'toggle_map_mode': 'L',
'toggle_tile_draw': 'm',
'drop_thing': 'drop thing',
'toggle_map_mode': 'toggle map view',
'toggle_tile_draw': 'toggle protection character drawing',
+ 'door': 'open/close',
}
action_tasks = {
'flatten': 'FLATTEN_SURROUNDINGS',
'take_thing': 'PICK_UP',
'drop_thing': 'DROP',
- 'move': 'MOVE'
+ 'door': 'DOOR',
+ 'move': 'MOVE',
}
curses.curs_set(False) # hide cursor
self.send('TASK:PICK_UP')
elif key == self.keys['drop_thing'] and task_action_on('drop_thing'):
self.send('TASK:DROP')
+ elif key == self.keys['door'] and task_action_on('door'):
+ self.send('TASK:DOOR')
elif key == self.keys['teleport']:
player = self.game.get_thing(self.game.player_id)
if player.position in self.game.portals: