this.log_msg("Portable things in reach for pick-up:");
const y = game.player.position[0]
const x = game.player.position[1]
- let select_range = [y.toString() + ':' + x.toString(),
- (y + 0).toString() + ':' + (x - 1).toString(),
- (y + 0).toString() + ':' + (x + 1).toString(),
- (y - 1).toString() + ':' + (x).toString(),
- (y + 1).toString() + ':' + (x).toString()];
- if (game.map_geometry == 'Hex') {
+ let directed_moves = {
+ 'HERE': [0, 0], 'LEFT': [0, -1], 'RIGHT': [0, 1]
+ }
+ if (game.map_geometry == 'Square') {
+ directed_moves['UP'] = [-1, 0];
+ directed_moves['DOWN'] = [1, 0];
+ } else if (game.map_geometry == 'Hex') {
if (y % 2) {
- select_range.push((y - 1).toString() + ':' + (x + 1).toString());
- select_range.push((y + 1).toString() + ':' + (x + 1).toString());
+ directed_moves['UPLEFT'] = [-1, 0];
+ directed_moves['UPRIGHT'] = [-1, 1];
+ directed_moves['DOWNLEFT'] = [1, 0];
+ directed_moves['DOWNRIGHT'] = [1, 1];
} else {
- select_range.push((y - 1).toString() + ':' + (x - 1).toString());
- select_range.push((y + 1).toString() + ':' + (x - 1).toString());
+ directed_moves['UPLEFT'] = [-1, -1];
+ directed_moves['UPRIGHT'] = [-1, 0];
+ directed_moves['DOWNLEFT'] = [1, -1];
+ directed_moves['DOWNRIGHT'] = [1, 0];
}
- };
+ }
+ console.log(directed_moves);
+ let select_range = {};
+ for (const direction in directed_moves) {
+ const move = directed_moves[direction];
+ select_range[direction] = [y + move[0], x + move[1]];
+ }
this.selectables = [];
- for (const t_id in game.things) {
- const t = game.things[t_id];
- if (select_range.includes(t.position[0].toString()
- + ':' + t.position[1].toString())
- && t.portable) {
- this.selectables.push(t_id);
+ let directions = [];
+ for (const direction in select_range) {
+ for (const t_id in game.things) {
+ const t = game.things[t_id];
+ const position = select_range[direction];
+ if (t.portable
+ && t.position[0] == position[0]
+ && t.position[1] == position[1]) {
+ this.selectables.push(t_id);
+ directions.push(direction);
+ }
}
- };
+ }
if (this.selectables.length == 0) {
this.log_msg('none');
terminal.blink_screen();
} else {
for (let [i, t_id] of this.selectables.entries()) {
const t = game.things[t_id];
- this.log_msg(i + ': ' + explorer.get_thing_info(t));
+ const direction = directions[i];
+ this.log_msg(i + ' ' + direction + ': ' + explorer.get_thing_info(t));
}
}
} else if (this.mode.name == 'drop_thing') {
self.log_msg('@ enter username')
elif self.mode.name == 'take_thing':
self.log_msg('Portable things in reach for pick-up:')
- select_range = [self.game.player.position,
- self.game.player.position + YX(0,-1),
- self.game.player.position + YX(0, 1),
- self.game.player.position + YX(-1, 0),
- self.game.player.position + YX(1, 0)]
- if type(self.game.map_geometry) == MapGeometryHex:
+ directed_moves = {
+ 'HERE': YX(0, 0), 'LEFT': YX(0, -1), 'RIGHT': YX(0, 1)
+ }
+ if type(self.game.map_geometry) == MapGeometrySquare:
+ directed_moves['UP'] = YX(-1, 0)
+ directed_moves['DOWN'] = YX(1, 0)
+ elif type(self.game.map_geometry) == MapGeometryHex:
if self.game.player.position.y % 2:
- select_range += [self.game.player.position + YX(-1, 1),
- self.game.player.position + YX(1, 1)]
+ directed_moves['UPLEFT'] = YX(-1, 0)
+ directed_moves['UPRIGHT'] = YX(-1, 1)
+ directed_moves['DOWNLEFT'] = YX(1, 0)
+ directed_moves['DOWNRIGHT'] = YX(1, 1)
else:
- select_range += [self.game.player.position + YX(-1, -1),
- self.game.player.position + YX(1, -1)]
- self.selectables = [t.id_ for t in self.game.things
- if t.portable and t.position in select_range]
+ directed_moves['UPLEFT'] = YX(-1, -1)
+ directed_moves['UPRIGHT'] = YX(-1, 0)
+ directed_moves['DOWNLEFT'] = YX(1, -1)
+ directed_moves['DOWNRIGHT'] = YX(1, 0)
+ select_range = {}
+ for direction in directed_moves:
+ move = directed_moves[direction]
+ select_range[direction] = self.game.player.position + move
+ self.selectables = []
+ directions = []
+ for direction in select_range:
+ for t in [t for t in self.game.things
+ if t.portable and t.position == select_range[direction]]:
+ self.selectables += [t.id_]
+ directions += [direction]
if len(self.selectables) == 0:
return fail('nothing to pick-up')
else:
for i in range(len(self.selectables)):
t = self.game.get_thing(self.selectables[i])
- self.log_msg(str(i) + ': ' + self.get_thing_info(t))
+ self.log_msg('%s %s: %s' % (i, directions[i],
+ self.get_thing_info(t)))
elif self.mode.name == 'drop_thing':
self.log_msg('Direction to drop thing to:')
self.selectables =\