From: Christian Heller Date: Sun, 6 Dec 2020 22:52:58 +0000 (+0100) Subject: Enable picking up from neighbbor tiles. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/blog?a=commitdiff_plain;h=3ac4bfc7722ec4366698ae17f5e2006e6a9e8b30;p=plomrogue2 Enable picking up from neighbbor tiles. --- diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index 1050023..dbe2315 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -82,19 +82,23 @@ class Task_PICK_UP(Task): 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 diff --git a/rogue_chat.html b/rogue_chat.html index 0e20ebc..0df4e6c 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -803,11 +803,27 @@ let tui = { } 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]); } diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 1f93dd8..3a5950c 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -625,9 +625,21 @@ class TUI: 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: