home · contact · privacy
Redo world generation with GEN_MAP command.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 19 Jan 2019 23:44:19 +0000 (00:44 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 19 Jan 2019 23:44:19 +0000 (00:44 +0100)
server.py
server_/game.py

index 9791d5f0bacf830fd4faa19a2b23b6184c2be0b1..cdeb27dc6c5081093c37117d8e144818098379a1 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -20,14 +20,5 @@ if os.path.exists(game_file_name):
             print("FILE INPUT LINE %s: %s" % (i, line), end='')
             game.io.handle_input(line, store=False)
 else:
-    game.io.handle_input('MAP Hex Y:5,X:5')
-    game.io.handle_input('TERRAIN_LINE 0 "xxxxx"')
-    game.io.handle_input('TERRAIN_LINE 1 "x...x"')
-    game.io.handle_input('TERRAIN_LINE 2 "x.X.x"')
-    game.io.handle_input('TERRAIN_LINE 3 "x...x"')
-    game.io.handle_input('TERRAIN_LINE 4 "xxxxx"')
-    game.io.handle_input('THING_TYPE 0 human')
-    game.io.handle_input('THING_POS 0 Y:3,X:3')
-    game.io.handle_input('THING_TYPE 1 monster')
-    game.io.handle_input('THING_POS 1 Y:1,X:1')
+    game.io.handle_input('GEN_WORLD Hex Y:16,X:16 bar')
 game.io.run_loop_with_server()
index 8068556ca89521f59648ad80afeae73ebee8e1a3..5595cea567ea2dfed0a82d35d580b7ea059ad572 100644 (file)
@@ -44,6 +44,26 @@ class World(game_common.World):
     def get_player(self):
         return self.get_thing(self.player_id)
 
+    def make_new(self, geometry, yx, seed):
+        import random
+        random.seed(seed)
+        self.turn = 0
+        self.new_map(geometry, yx)
+        for pos in self.map_:
+            if 0 in pos or (yx[0] - 1) == pos[0] or (yx[1] - 1) == pos[1]:
+                self.map_[pos] = '#'
+                continue
+            self.map_[pos] = random.choice(('.', '.', '.', '.', 'x'))
+        player = self.Thing(self, 0)
+        player.type_ = 'human'
+        player.position = [random.randint(0, yx[0] -1),
+                           random.randint(0, yx[1] - 1)]
+        npc = self.Thing(self, 1)
+        npc.type_ = 'monster'
+        npc.position = [random.randint(0, yx[0] -1),
+                        random.randint(0, yx[1] -1)]
+        self.things = [player, npc]
+
 
 class Task:
 
@@ -84,12 +104,12 @@ class Thing(game_common.Thing):
         return 'success'
 
     def decide_task(self):
-        if self.position[1] > 1:
-            self.set_task('move', 'LEFT')
-        elif self.position[1] < 3:
-            self.set_task('move', 'RIGHT')
-        else:
-            self.set_task('wait')
+        #if self.position[1] > 1:
+        #    self.set_task('move', 'LEFT')
+        #elif self.position[1] < 3:
+        #    self.set_task('move', 'RIGHT')
+        #else:
+        self.set_task('wait')
 
     def set_task(self, task_name, *args, **kwargs):
         self.task = Task(self, task_name, args, kwargs)
@@ -267,3 +287,11 @@ class Game(game_common.CommonCommandsMixin):
     def cmd_TERRAIN_LINE(self, y, terrain_line):
         self.world.map_.set_line(y, terrain_line)
     cmd_TERRAIN_LINE.argtypes = 'int:nonneg string'
+
+    def cmd_GEN_WORLD(self, geometry, yx, seed):
+        legal_grids = self.map_manager.get_map_geometries()
+        if geometry not in legal_grids:
+            raise ArgError('First map argument must be one of: ' +
+                           ', '.join(legal_grids))
+        self.world.make_new(geometry, yx, seed)
+    cmd_GEN_WORLD.argtypes = 'string yx_tuple:pos string'