if self.thing.carrying:
raise PlayError('already carrying something')
to_pick_up = self.thing.game.get_thing(self.args[0])
+ neighbors = self.thing.game.map_geometry.\
+ get_neighbors_yxyx(self.thing.position).values()
+ reach = [self.thing.position] + list(neighbors)
if to_pick_up is None:
raise PlayError('no thing of ID %s exists %s' % self.args[0])
elif to_pick_up == self.thing:
raise PlayError('cannot pick up oneself')
elif to_pick_up.type_ == 'Player':
raise PlayError('cannot pick up player')
- elif to_pick_up.position != self.thing.position:
+ elif to_pick_up.position not in reach:
raise PlayError('thing of ID %s not in reach' % self.args[0])
elif not to_pick_up.portable:
raise PlayError('thing of ID %s not portable' % self.args[0])
def do(self):
to_pick_up = self.thing.game.get_thing(self.args[0])
+ to_pick_up.position = self.thing.position[:]
self.thing.carrying = to_pick_up
} else if (this.mode.name == 'take_thing') {
this.log_msg("selectable things:");
const player = game.things[game.player_id];
+ const y = player.position[0]
+ const x = 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') {
+ if (y % 2) {
+ select_range.push((y - 1).toString() + ':' + (x + 1).toString());
+ select_range.push((y + 1).toString() + ':' + (x + 1).toString());
+ } else {
+ select_range.push((y - 1).toString() + ':' + (x - 1).toString());
+ select_range.push((y + 1).toString() + ':' + (x - 1).toString());
+ }
+ };
this.selectables = [];
for (const t_id in game.things) {
const t = game.things[t_id];
- if (t.position[0] == player.position[0]
- && t.position[1] == player.position[1]
+ if (select_range.includes(t.position[0].toString()
+ + ':' + t.position[1].toString())
&& t != player && t.type_ != 'Player') {
this.selectables.push([t_id, t]);
}
elif self.mode.name == 'take_thing':
self.log_msg('selectable things:')
player = self.game.get_thing(self.game.player_id)
+ select_range = [player.position,
+ player.position + YX(0,-1),
+ player.position + YX(0, 1),
+ player.position + YX(-1, 0),
+ player.position + YX(1, 0)]
+ if type(self.game.map_geometry) == MapGeometryHex:
+ if player.position.y % 2:
+ select_range += [player.position + YX(-1, 1),
+ player.position + YX(1, 1)]
+ else:
+ select_range += [player.position + YX(-1, -1),
+ player.position + YX(1, -1)]
self.selectables = [t for t in self.game.things
if t != player and t.type_ != 'Player'
- and t.position == player.position]
+ and t.position in select_range]
if len(self.selectables) == 0:
self.log_msg('none')
else: