home · contact · privacy
Add crates.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 16 Dec 2020 22:26:44 +0000 (23:26 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 16 Dec 2020 22:26:44 +0000 (23:26 +0100)
plomrogue/commands.py
plomrogue/game.py
plomrogue/tasks.py
plomrogue/things.py
rogue_chat.py

index 074cc343873a80b17e6383b604c7e109217210c6..c86aebe402ad5c1c6d5fadc776ad6e429d5092ed 100644 (file)
@@ -396,3 +396,17 @@ def cmd_THING_DOOR_KEY(game, key_id, door_id):
         raise GameError('thing of ID %s not a door' % key_id)
     key.door = door
 cmd_THING_DOOR_KEY.argtypes = 'int:pos int:pos'
+
+def cmd_THING_CRATE_ITEM(game, crate_id, item_id):
+    crate = game.get_thing(crate_id)
+    if not crate:
+        raise GameError('thing of ID %s not found' % crate_id)
+    if crate.type_ != 'Crate':
+        raise GameError('thing of ID %s not a crate' % crate_id)
+    item = game.get_thing(item_id)
+    if not item:
+        raise GameError('thing of ID %s not found' % item_id)
+    if item.type_ == 'Crate':
+        raise GameError('thing of ID %s is a crate' % item_id)
+    crate.accept(item)
+cmd_THING_CRATE_ITEM.argtypes = 'int:pos int:pos'
index 0c84e044d5b087baf52bdcde18b0c7b8f7e40267..b394c5d1024c4662c350b5ad6fdfb8f026a2006e 100755 (executable)
@@ -561,9 +561,14 @@ class Game(GameBase):
                     write(f, 'THING_BOTTLE_EMPTY %s' % t.id_)
                 elif t.type_ == 'DoorKey':
                     write(f, 'THING_DOOR_KEY %s %s' % (t.id_, t.door.id_))
+                elif t.type_ == 'Crate':
+                    for item in t.content:
+                        write(f, 'THING_CRATE_ITEM %s %s' % (t.id_, item.id_))
             write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0],
                                             self.spawn_point[1]))
 
+
+
     def get_map(self, big_yx, type_='normal'):
         if type_ == 'normal':
             maps = self.maps
index 14ea820bd153e20f016af575d59d74c110023826..95945055e0f7e15923bc34780a985c2b3a5ea556 100644 (file)
@@ -75,6 +75,9 @@ class Task_MOVE(Task):
             self.thing.game.record_change(self.thing.position, 'fov')
         if self.thing.carrying:
             self.thing.carrying.position = self.thing.position
+            if self.thing.carrying.type_ == 'Crate':
+                for t in self.thing.carrying.content:
+                    t.position = self.thing.position
 
 
 
@@ -139,6 +142,11 @@ class Task_PICK_UP(Task):
         to_pick_up.position = self.thing.position[:]
         self.thing.carrying = to_pick_up
         to_pick_up.carried = True
+        for t in [t for t in self.thing.game.things
+                  if t.type_ == 'Crate' and to_pick_up in t.content]:
+            t.remove_from_crate(to_pick_up)
+            self.thing.send_msg('CHAT "You take the item out of the crate."')
+            break
         self.thing.game.record_change(self.thing.position, 'other')
 
 
@@ -150,42 +158,43 @@ class Task_DROP(Task):
         if not self.thing.carrying:
             raise PlayError('nothing to drop')
         target_position = self._get_move_target()
-        if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
-            for t in [t for t in self.thing.game.things
-                      if t.type_ == 'BottleDeposit'
-                      and t.position == target_position]:
-                raise PlayError('cannot drop full bottle into bottle deposit')
-        for t in [t for t in self.thing.game.things
-                  if t.type_ == 'CookieSpawner'
-                  and t.position == target_position]:
-            if not self.thing.carrying.cookable:
+        targets = [t for t in self.thing.game.things
+                   if t.position == target_position
+                   and not t == self.thing.carrying]
+        for target in targets:
+            if target.type_ == 'CookieSpawner' and\
+               not self.thing.carrying.cookable:
                 raise PlayError('cannot cook items of this type')
-            break
+            elif target.type_ == 'BottleDeposit':
+                if not self.thing.carrying.type_ == 'Bottle':
+                    raise PlayError('cannot only put bottle into bottle deposit')
+                if self.thing.carrying.full:
+                    raise PlayError('cannot drop full '
+                                    'bottle into bottle deposit')
+            elif target.type_ == 'Crate' and\
+                 self.thing.carrying.type_ == 'Crate':
+                raise PlayError('cannot put crate into crate')
 
     def do(self):
         target_position = self._get_move_target()
         dropped = self.thing.uncarry()
         dropped.position = target_position
-        over_cookie_spawner = None
-        for t in [t for t in self.thing.game.things
-                  if t.type_ == 'CookieSpawner'
-                  and t.position == dropped.position]:
-            over_cookie_spawner = t
-            break
-        if over_cookie_spawner:
-            over_cookie_spawner.accept(dropped)
-            self.thing.game.remove_thing(dropped)
-        elif dropped.type_ == 'Bottle' and not dropped.full:
-            for t in [t for t in self.thing.game.things
-                      if t.type_ == 'BottleDeposit'
-                      and t.position == dropped.position]:
-                t.accept()
+        targets = [t for t in self.thing.game.things
+                   if t.position == dropped.position and not t == dropped]
+        for target in targets:
+            if target.type_ == 'CookieSpawner':
+                target.accept(dropped)
                 self.thing.game.remove_thing(dropped)
                 break
-        elif dropped.type_ == 'Hat':
-            for t in [t for t in self.thing.game.things
-                      if t.type_ == 'HatRemixer'
-                      and t.position == dropped.position]:
+            elif target.type_ == 'BottleDeposit':
+                target.accept()
+                self.thing.game.remove_thing(dropped)
+                break
+            elif target.type_ == 'Crate':
+                target.accept(dropped)
+                self.thing.send_msg('CHAT "You put the item into the crate."')
+                break
+            elif target.type_ == 'HatRemixer':
                 t.accept(dropped)
                 break
         self.thing.game.record_change(self.thing.position, 'other')
index a0db94a0f639907d0cd1d35169c8d77cf3e19b9f..25197980ff860b165349ebd89fe98c2c06f5d45a 100644 (file)
@@ -456,6 +456,28 @@ class Thing_CookieSpawner(Thing):
 
 
 
+class Thing_Crate(Thing):
+    portable = True
+    symbol_hint = 'C'
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.content = []
+
+    def accept(self, thing):
+        self.content += [thing]
+
+    def remove_from_crate(self, thing):
+        self.content.remove(thing)
+
+
+
+class Thing_CrateSpawner(ThingSpawner):
+    child_type = 'Crate'
+    symbol_hint = 'C'
+
+
+
 class ThingAnimate(Thing):
     weariness = 0
 
index a3654b0908c29464f05b6e7109deb0a29b30bdc8..cc6421f0384d48e7d6062c78836c51bfe72dabbf 100755 (executable)
@@ -15,7 +15,8 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN
                                 cmd_THING_BOTTLE_EMPTY, cmd_PLAYER_FACE,
                                 cmd_GOD_PLAYER_FACE, cmd_GOD_PLAYER_HAT,
                                 cmd_GOD_PLAYERS_HAT_CHARS, cmd_PLAYER_HAT,
-                                cmd_TERRAIN_TAG, cmd_THING_DOOR_KEY)
+                                cmd_TERRAIN_TAG, cmd_THING_DOOR_KEY,
+                                cmd_THING_CRATE_ITEM)
 from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
                              Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR,
                              Task_INTOXICATE, Task_COMMAND, Task_INSTALL,
@@ -26,7 +27,8 @@ from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
                               Thing_BottleSpawner, Thing_BottleDeposit,
                               Thing_MusicPlayer, Thing_Hat, Thing_HatRemixer,
                               Thing_Cookie, Thing_CookieSpawner, Thing_Psychedelic,
-                              Thing_PsychedelicSpawner, Thing_DoorKey)
+                              Thing_PsychedelicSpawner, Thing_DoorKey,
+                              Thing_Crate, Thing_CrateSpawner)
 
 from plomrogue.config import config
 game = Game(config['savefile'])
@@ -71,6 +73,7 @@ game.register_command(cmd_GOD_PLAYERS_HAT_CHARS)
 game.register_command(cmd_PLAYER_HAT)
 game.register_command(cmd_THING_HAT_DESIGN)
 game.register_command(cmd_THING_DOOR_KEY)
+game.register_command(cmd_THING_CRATE_ITEM)
 game.register_task(Task_WAIT)
 game.register_task(Task_MOVE)
 game.register_task(Task_WRITE)
@@ -101,6 +104,8 @@ game.register_thing_type(Thing_Cookie)
 game.register_thing_type(Thing_CookieSpawner)
 game.register_thing_type(Thing_Psychedelic)
 game.register_thing_type(Thing_PsychedelicSpawner)
+game.register_thing_type(Thing_Crate)
+game.register_thing_type(Thing_CrateSpawner)
 game.read_savefile()
 game.io.start_loop()
 for port in config['servers']: