home · contact · privacy
Don't enter command_thing mode when not carrying anything commandable.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 00:44:39 +0000 (01:44 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 00:44:39 +0000 (01:44 +0100)
plomrogue/game.py
rogue_chat.html
rogue_chat_curses.py

index b0233b327574dba4ee8fe946395c68066a8e9130..143248f4e7afaf0546beca3431fe1df485ca2887 100755 (executable)
@@ -267,9 +267,9 @@ class Game(GameBase):
             self.io.send('MAP_CONTROL %s' % quote(player.visible_control), c_id)
             for t in [t for t in self.things if player.fov_test(*t.position)]:
                 target_yx = player.fov_stencil.target_yx(*t.position)
-                self.io.send('THING %s %s %s %s %s' % (target_yx, t.type_,
-                                                       quote(t.protection),
-                                                       t.id_, int(t.portable)),
+                self.io.send('THING %s %s %s %s %s %s'
+                             % (target_yx, t.type_, quote(t.protection), t.id_,
+                                int(t.portable), int(t.commandable)),
                              c_id)
                 if hasattr(t, 'name'):
                     self.io.send('THING_NAME %s %s' % (t.id_, quote(t.name)), c_id)
@@ -283,7 +283,8 @@ class Game(GameBase):
                     self.io.send('THING_CHAR %s %s' % (t.id_,
                                                        quote(t.thing_char)), c_id)
                 if hasattr(t, 'carrying') and t.carrying:
-                    self.io.send('THING_CARRYING %s' % (t.id_), c_id)
+                    self.io.send('THING_CARRYING %s %s' % (t.id_, t.carrying.id_),
+                                 c_id)
                 if hasattr(t, 'installable') and not t.portable:
                     self.io.send('THING_INSTALLED %s' % (t.id_), c_id)
             for big_yx in self.portals:
index 1b501b5189354e70fcb5658c61db8a62e4acb862..2e37e7f3376b2ed24f0600f6a63c1564833e90ba 100644 (file)
@@ -485,6 +485,7 @@ let server = {
             t.type_ = tokens[2];
             t.protection = tokens[3];
             t.portable = parseInt(tokens[5]);
+            t.commandable = parseInt(tokens[6]);
         } else if (tokens[0] === 'THING_NAME') {
             let t = game.get_thing(tokens[1], false);
             t.name_ = tokens[2];
@@ -506,7 +507,7 @@ let server = {
             game.thing_types[tokens[1]] = tokens[2]
         } else if (tokens[0] === 'THING_CARRYING') {
             let t = game.get_thing(tokens[1], false);
-            t.carrying = true;
+            t.carrying = t = game.get_thing(tokens[2], false);
         } else if (tokens[0] === 'THING_INSTALLED') {
             let t = game.get_thing(tokens[1], false);
             t.installed = true;
@@ -756,17 +757,24 @@ let tui = {
         tui.log_msg('@ finished tile protection drawing.')
     }
     this.tile_draw = false;
+    const player = game.things[game.player_id];
+    if (mode_name == 'command_thing' && (!player.carrying || !player.carrying.commandable)) {
+        this.log_msg('? not carrying anything commandable');
+        terminal.blink_screen();
+        this.switch_mode('play');
+        return;
+    };
     if (mode_name == 'admin_enter' && this.is_admin) {
         mode_name = 'admin';
     } else if (['name_thing', 'admin_thing_protect'].includes(mode_name)) {
-        let player_position = game.things[game.player_id].position;
         let thing_id = null;
         for (let t_id in game.things) {
             if (t_id == game.player_id) {
                 continue;
             }
             let t = game.things[t_id];
-            if (player_position[0] == t.position[0] && player_position[1] == t.position[1]) {
+            if (player.position[0] == t.position[0]
+                && player.position[1] == t.position[1]) {
                 thing_id = t_id;
                 break;
             }
@@ -1459,10 +1467,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
         tui.inputEl.value = "";
         tui.switch_mode('edit');
     } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') {
-        if (tui.task_action_on('command')) {
-            server.send(['TASK:COMMAND', tui.inputEl.value]);
-            tui.inputEl.value = "";
-        }
+        server.send(['TASK:COMMAND', tui.inputEl.value]);
+        tui.inputEl.value = "";
     } else if (tui.mode.name == 'take_thing' && event.key == 'Enter') {
         const i = parseInt(tui.inputEl.value);
         if (isNaN(i) || i < 0 || i >= tui.selectables.length) {
index aeb955e60f9593d113f37fb6f0f33c4f9b2817d6..15f59bf5d915bd13d8b3c5fafe1f761440854cd8 100755 (executable)
@@ -199,7 +199,7 @@ def cmd_PLAYER_ID(game, player_id):
     game.player_id = player_id
 cmd_PLAYER_ID.argtypes = 'int:nonneg'
 
-def cmd_THING(game, yx, thing_type, protection, thing_id, portable):
+def cmd_THING(game, yx, thing_type, protection, thing_id, portable, commandable):
     t = game.get_thing(thing_id)
     if not t:
         t = ThingBase(game, thing_id)
@@ -208,7 +208,8 @@ def cmd_THING(game, yx, thing_type, protection, thing_id, portable):
     t.type_ = thing_type
     t.protection = protection
     t.portable = portable
-cmd_THING.argtypes = 'yx_tuple:nonneg string:thing_type char int:nonneg bool'
+    t.commandable = commandable
+cmd_THING.argtypes = 'yx_tuple:nonneg string:thing_type char int:nonneg bool bool'
 
 def cmd_THING_NAME(game, thing_id, name):
     t = game.get_thing(thing_id)
@@ -309,9 +310,9 @@ def cmd_THING_INSTALLED(game, thing_id):
     game.get_thing(thing_id).installed = True
 cmd_THING_INSTALLED.argtypes = 'int:pos'
 
-def cmd_THING_CARRYING(game, thing_id):
-    game.get_thing(thing_id).carrying = True
-cmd_THING_CARRYING.argtypes = 'int:pos'
+def cmd_THING_CARRYING(game, thing_id, carried_id):
+    game.get_thing(thing_id).carrying = game.get_thing(carried_id)
+cmd_THING_CARRYING.argtypes = 'int:pos int:pos'
 
 def cmd_TERRAIN(game, terrain_char, terrain_desc):
     game.terrains[terrain_char] = terrain_desc
@@ -620,10 +621,16 @@ class TUI:
         if self.mode and self.mode.name == 'control_tile_draw':
             self.log_msg('@ finished tile protection drawing.')
         self.tile_draw = False
+        player = self.game.get_thing(self.game.player_id)
+        if mode_name == 'command_thing' and\
+           (not hasattr(player, 'carrying') or not player.carrying.commandable):
+            self.log_msg('? not carrying anything commandable')
+            self.flash = True
+            self.switch_mode('play')
+            return
         if mode_name == 'admin_enter' and self.is_admin:
             mode_name = 'admin'
         elif mode_name in {'name_thing', 'admin_thing_protect'}:
-            player = self.game.get_thing(self.game.player_id)
             thing = None
             for t in [t for t in self.game.things if t.position == player.position
                       and t.id_ != player.id_]:
@@ -1090,9 +1097,8 @@ class TUI:
                 self.input_ = ''
                 self.switch_mode('play')
             elif self.mode.name == 'command_thing' and key == '\n':
-                if task_action_on('command'):
-                    self.send('TASK:COMMAND ' + quote(self.input_))
-                    self.input_ = ""
+                self.send('TASK:COMMAND ' + quote(self.input_))
+                self.input_ = ""
             elif self.mode.name == 'control_pw_pw' and key == '\n':
                 if self.input_ == '':
                     self.log_msg('@ aborted')