home · contact · privacy
Enable picking up from neighbbor tiles.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 6 Dec 2020 22:52:58 +0000 (23:52 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 6 Dec 2020 22:52:58 +0000 (23:52 +0100)
plomrogue/tasks.py
rogue_chat.html
rogue_chat_curses.py

index 105002316193b544448cdecabdc2a6410a5b41ef..dbe23153f11d7ee842b04bca60ed694bab40f038 100644 (file)
@@ -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
 
 
index 0e20ebca41b1bc563a7bc3481247b557fd4ad8ed..0df4e6ceba8aff655a58dda546ecf4b5be3b0713 100644 (file)
@@ -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]);
             }
index 1f93dd808b690d488b0cf9f93fd3ed80a72fa50e..3a5950c477372c2cf44510bde9c6e8e6a0d4370b 100755 (executable)
@@ -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: