home · contact · privacy
Only contact with player's radius creates new maps.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 27 Apr 2019 20:01:16 +0000 (22:01 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 27 Apr 2019 20:01:16 +0000 (22:01 +0200)
new/plomrogue/commands.py
new/plomrogue/game.py
new/plomrogue/things.py

index 2d9ecb6e1a2088aef39cb4449f00bc6c9446cfad..bd740b7404999e7d894da1ff8b1ce14e6f86204f 100644 (file)
@@ -20,7 +20,7 @@ cmd_MAP_SIZE.argtypes = 'yx_tuple:pos'
 
 def cmd_MAP(game, map_pos):
     """Ensure (possibly empty/'?'-filled) map at position map_pos."""
-    game.world.ensure_map(map_pos)
+    game.world.get_map(map_pos)
 cmd_MAP.argtypes = 'yx_tuple'
 
 def cmd_THING_TYPE(game, i, type_):
index 7bf958f2a513714f99158475a0e3220d3db1530c..669fae3dd0b42483d3800e5ba989bdce37428daf 100755 (executable)
@@ -79,10 +79,16 @@ class World(WorldBase):
             return 0
         return self.things[-1].id_ + 1
 
-    def ensure_map(self, map_pos):
-        if map_pos in self.maps and self.maps[map_pos].size == self.map_size:
-            return
-        self.maps[map_pos] = self.game.map_type(self.map_size)
+    def get_map(self, map_pos, create_unfound=True):
+        if not (map_pos in self.maps and
+                self.maps[map_pos].size == self.map_size):
+            if create_unfound:
+                self.maps[map_pos] = self.game.map_type(self.map_size)
+                for pos in self.maps[map_pos]:
+                    self.maps[map_pos][pos] = '~'
+            else:
+                return None
+        return self.maps[map_pos]
 
     def proceed_to_next_player_turn(self):
         """Run game world turns until player can decide their next step.
@@ -138,23 +144,9 @@ class World(WorldBase):
         self.turn = 0
         self.maps = {}
         self.map_size = yx
-        self.ensure_map(YX(0,0))
-        self.ensure_map(YX(0,1))
-        self.ensure_map(YX(1,1))
-        self.ensure_map(YX(1,0))
-        self.ensure_map(YX(1,-1))
-        self.ensure_map(YX(0,-1))
-        self.ensure_map(YX(-1,-1))
-        self.ensure_map(YX(-1,0))
-        self.ensure_map(YX(-1,1))
-        for map_pos in self.maps:
-            map_ = self.maps[map_pos]
-            if YX(0,0) == map_pos:
-                for pos in map_:
-                    map_[pos] = self.rand.choice(('.', '.', '.', '.', 'x'))
-            else:
-                for pos in map_:
-                    map_[pos] = '~'
+        map_ = self.get_map(YX(0,0))
+        for pos in map_:
+            map_[pos] = self.rand.choice(('.', '.', '.', '.', 'x'))
         player = add_thing_at_random('human')
         self.player_id = player.id_
         add_thing_at_random('monster')
index 1b3a46d3953a3070c9ebc2021f01ca7fc8415840..ed3b5474d6a64bf978c86ef8b41436043171565b 100644 (file)
@@ -8,11 +8,11 @@ class ThingBase:
 
     def __init__(self, world, id_=None, position=(YX(0,0), YX(0,0))):
         self.world = world
-        self.position = position
         if id_ is None:
             self.id_ = self.world.new_thing_id()
         else:
             self.id_ = id_
+        self.position = position
 
     @property
     def position(self):
@@ -42,6 +42,7 @@ class Thing(ThingBase):
 
     def __init__(self, *args, **kwargs):
         self.inventory = []
+        self._radius = 8
         super().__init__(*args, **kwargs)
 
     def proceed(self):
@@ -52,6 +53,28 @@ class Thing(ThingBase):
         for t_id in self.inventory:
             t = self.world.get_thing(t_id)
             t.position = self.position
+        if not self.id_ == self.world.player_id:
+            return
+        edge_left = self.position[1].x - self._radius
+        edge_right = self.position[1].x + self._radius
+        edge_up = self.position[1].y - self._radius
+        edge_down = self.position[1].y + self._radius
+        if edge_left < 0:
+            self.world.get_map(self.position[0] - YX(1,-1))
+            self.world.get_map(self.position[0] - YX(0,-1))
+            self.world.get_map(self.position[0] - YX(-1,-1))
+        if edge_right >= self.world.map_size.x:
+            self.world.get_map(self.position[0] + YX(1,1))
+            self.world.get_map(self.position[0] + YX(0,1))
+            self.world.get_map(self.position[0] + YX(-1,1))
+        if edge_up < 0:
+            self.world.get_map(self.position[0] - YX(-1,1))
+            self.world.get_map(self.position[0] - YX(-1,0))
+            self.world.get_map(self.position[0] - YX(-1,-1))
+        if edge_down >= self.world.map_size.y:
+            self.world.get_map(self.position[0] + YX(1,1))
+            self.world.get_map(self.position[0] + YX(1,0))
+            self.world.get_map(self.position[0] + YX(1,-1))
 
 
 
@@ -72,7 +95,6 @@ class ThingAnimate(Thing):
         super().__init__(*args, **kwargs)
         self.set_task('WAIT')
         self._last_task_result = None
-        self._radius = 8
         self.unset_surroundings()
 
     def move_on_dijkstra_map(self, own_pos, targets):
@@ -250,7 +272,10 @@ class ThingAnimate(Thing):
             big_x, small_x = pan_and_scan(size.x, pos.x, offset.x)
             big_yx = YX(big_y, big_x)
             small_yx = YX(small_y, small_x)
-            self._surrounding_map[pos] = self.world.maps[big_yx][small_yx]
+            map_ = self.world.get_map(big_yx, False)
+            if map_ is None:
+                map_ = self.world.game.map_type(size=self.world.map_size)
+            self._surrounding_map[pos] = map_[small_yx]
         return self._surrounding_map
 
     def get_stencil(self):