X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=new2%2Fplomrogue%2Fgame.py;h=e871d59401f1a9418ccc97c5f6c7fd5a055dd58a;hb=9506b64fe6040ba2489d84ecf852c6e2ad7fef65;hp=e7a4262df8bffd7b44e3ba7639cefa276b545573;hpb=dcb275a3ae06858ba25eee3c5cd7ab6c1d44a4df;p=plomrogue2-experiments
diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py
index e7a4262..e871d59 100755
--- a/new2/plomrogue/game.py
+++ b/new2/plomrogue/game.py
@@ -1,9 +1,9 @@
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE,
Task_FLATTEN_SURROUNDINGS)
-from plomrogue.errors import GameError
+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
@@ -50,6 +50,7 @@ class Game(GameBase):
'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 +60,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')
@@ -89,18 +91,25 @@ class Game(GameBase):
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, self.portals[yx]))
self.io.send('GAME_STATE_COMPLETE')
def run_tick(self):
to_delete = []
for connection_id in self.sessions:
- if not connection_id in self.io.server.clients:
+ connection_id_found = False
+ for server in self.io.servers:
+ if connection_id in server.clients:
+ connection_id_found = True
+ break
+ if not connection_id_found:
t = self.get_thing(self.sessions[connection_id], create_unfound=False)
self.things.remove(t)
to_delete += [connection_id]
for connection_id in to_delete:
del self.sessions[connection_id]
- self.changed = True
+ self.changed = True
for t in [t for t in self.things]:
if t in self.things:
try:
@@ -109,6 +118,10 @@ class Game(GameBase):
for connection_id in [c_id for c_id in self.sessions
if self.sessions[c_id] == t.id_]:
self.io.send('GAME_ERROR ' + quote(str(e)), connection_id)
+ except PlayError as e:
+ for connection_id in [c_id for c_id in self.sessions
+ if self.sessions[c_id] == t.id_]:
+ self.io.send('PLAY_ERROR ' + quote(str(e)), connection_id)
if self.changed:
self.turn += 1
self.send_gamestate()
@@ -170,6 +183,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, self.portals[yx]))
def new_world(self, size):
self.map_geometry = MapGeometrySquare(YX(size.y, size.x))