From: Christian Heller Date: Sat, 19 Jan 2019 23:44:19 +0000 (+0100) Subject: Redo world generation with GEN_MAP command. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/calendar?a=commitdiff_plain;h=70388a86c4f8fd774eb94b6deaa85bb1cb1d0aed;p=plomrogue2-experiments Redo world generation with GEN_MAP command. --- diff --git a/server.py b/server.py index 9791d5f..cdeb27d 100755 --- 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() diff --git a/server_/game.py b/server_/game.py index 8068556..5595cea 100644 --- a/server_/game.py +++ b/server_/game.py @@ -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'