X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new2%2Fplomrogue%2Fgame.py;h=da148460d0c244b3f350bd6c0ada8c407ec5e4e3;hb=e4b04a5ba87c262b7f01a52ce6e25001b8a53506;hp=d90aa0b0f8a47350536244d7f3fab39ffdb01fce;hpb=61e7b58cf8be7a0c24d78a1336e54fdbf088deea;p=plomrogue2-experiments diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index d90aa0b..da14846 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -3,10 +3,10 @@ from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, from plomrogue.errors import GameError, PlayError from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING, cmd_TURN, cmd_MAP_LINE, cmd_MAP, cmd_GET_ANNOTATION, - cmd_ANNOTATE, cmd_GET_GAMESTATE) + cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE) from plomrogue.io import GameIO from plomrogue.misc import quote -from plomrogue.things import Thing, ThingPlayer +from plomrogue.things import Thing, ThingPlayer from plomrogue.mapping import YX, MapGeometrySquare, Map @@ -14,9 +14,9 @@ from plomrogue.mapping import YX, MapGeometrySquare, Map class GameBase: def __init__(self): - pass self.turn = 0 self.things = [] + self.map_geometry = MapGeometrySquare(YX(24, 40)) def get_thing(self, id_, create_unfound): # No default for create_unfound because every call to get_thing @@ -43,13 +43,13 @@ class Game(GameBase): 'MOVE': Task_MOVE, 'WRITE': Task_WRITE, 'FLATTEN_SURROUNDINGS': Task_FLATTEN_SURROUNDINGS} - self.map_geometry = MapGeometrySquare(YX(24, 40)) self.commands = {'QUERY': cmd_QUERY, 'ALL': cmd_ALL, 'LOGIN': cmd_LOGIN, 'TURN': cmd_TURN, 'MAP_LINE': cmd_MAP_LINE, 'GET_ANNOTATION': cmd_GET_ANNOTATION, + 'PORTAL': cmd_PORTAL, 'GET_GAMESTATE': cmd_GET_GAMESTATE, 'ANNOTATE': cmd_ANNOTATE, 'MAP': cmd_MAP, @@ -59,6 +59,7 @@ class Game(GameBase): self.sessions = {} self.map = Map(self.map_geometry.size) self.annotations = {} + self.portals = {} if os.path.exists(self.io.save_file): if not os.path.isfile(self.io.save_file): raise GameError('save file path refers to non-file') @@ -84,11 +85,15 @@ class Game(GameBase): def send_thing(thing): self.io.send('THING_POS %s %s' % (thing.id_, t.position)) + if hasattr(thing, 'nickname'): + self.io.send('THING_NAME %s %s' % (thing.id_, quote(t.nickname))) self.io.send('TURN ' + str(self.turn)) for t in self.things: send_thing(t) self.io.send('MAP %s %s' % (self.map_geometry.size, quote(self.map.terrain))) + for yx in self.portals: + self.io.send('PORTAL %s %s' % (yx, quote(self.portals[yx]))) self.io.send('GAME_STATE_COMPLETE') def run_tick(self): @@ -179,6 +184,8 @@ class Game(GameBase): write(f, 'MAP_LINE %5s %s' % (y, quote(line))) for yx in self.annotations: write(f, 'ANNOTATE %s %s' % (yx, quote(self.annotations[yx]))) + for yx in self.portals: + write(f, 'PORTAL %s %s' % (yx, quote(self.portals[yx]))) def new_world(self, size): self.map_geometry = MapGeometrySquare(YX(size.y, size.x))