home · contact · privacy
In pick-up selection, show reachable things' relative direction.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 14 Dec 2020 23:15:37 +0000 (00:15 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 14 Dec 2020 23:15:37 +0000 (00:15 +0100)
rogue_chat.html
rogue_chat_curses.py

index 35dc5d4aa812e88907dcdc80348f12e04b0476f2..c685581b91969031a0f217feca967bc9c4464aac 100644 (file)
@@ -861,29 +861,45 @@ let tui = {
         this.log_msg("Portable things in reach for pick-up:");
         const y = game.player.position[0]
         const x = game.player.position[1]
         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) {
             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 {
             } 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 = [];
         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();
         if (this.selectables.length == 0) {
             this.log_msg('none');
             terminal.blink_screen();
@@ -892,7 +908,8 @@ let tui = {
         } else {
             for (let [i, t_id] of this.selectables.entries()) {
                 const t = game.things[t_id];
         } 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') {
             }
         }
     } else if (this.mode.name == 'drop_thing') {
index c26c3805a0ec092c6e4ff8affead14a222c7127f..65d5385ee2d20d17f5fb117a4ac82ea987163445 100755 (executable)
@@ -724,26 +724,41 @@ class TUI:
                 self.log_msg('@ enter username')
         elif self.mode.name == 'take_thing':
             self.log_msg('Portable things in reach for pick-up:')
                 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:
                 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:
                 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])
             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 =\
         elif self.mode.name == 'drop_thing':
             self.log_msg('Direction to drop thing to:')
             self.selectables =\