home
·
contact
·
privacy
projects
/
plomrogue2-experiments
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use terminal-size-indepenent max log length.
[plomrogue2-experiments]
/
new2
/
plomrogue
/
game.py
diff --git
a/new2/plomrogue/game.py
b/new2/plomrogue/game.py
index 52e0d600e37b2f90fcc3209d704c2d0866f330e2..2202343d2bf61bc2fd63c5467ae4fb373bf7f20e 100755
(executable)
--- a/
new2/plomrogue/game.py
+++ b/
new2/plomrogue/game.py
@@
-1,8
+1,9
@@
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE,
Task_FLATTEN_SURROUNDINGS)
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,
from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING,
- cmd_TURN, cmd_MAP_LINE, cmd_MAP)
+ cmd_TURN, cmd_MAP_LINE, cmd_MAP, cmd_GET_ANNOTATION,
+ 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.io import GameIO
from plomrogue.misc import quote
from plomrogue.things import Thing, ThingPlayer
@@
-48,12
+49,18
@@
class Game(GameBase):
'LOGIN': cmd_LOGIN,
'TURN': cmd_TURN,
'MAP_LINE': cmd_MAP_LINE,
'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,
'PING': cmd_PING}
self.thing_type = Thing
self.thing_types = {'player': ThingPlayer}
self.sessions = {}
self.map = Map(self.map_geometry.size)
'MAP': cmd_MAP,
'PING': cmd_PING}
self.thing_type = Thing
self.thing_types = {'player': ThingPlayer}
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')
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')
@@
-63,7
+70,7
@@
class Game(GameBase):
for i in range(len(lines)):
line = lines[i]
print("FILE INPUT LINE %5s: %s" % (i, line), end='')
for i in range(len(lines)):
line = lines[i]
print("FILE INPUT LINE %5s: %s" % (i, line), end='')
- self.io.handle_input(line)
+ self.io.handle_input(line
, god_mode=True
)
def get_string_options(self, string_option_type):
import string
def get_string_options(self, string_option_type):
import string
@@
-71,7
+78,7
@@
class Game(GameBase):
return self.map_geometry.get_directions()
if string_option_type == 'char':
return [c for c in
return self.map_geometry.get_directions()
if string_option_type == 'char':
return [c for c in
- string.digits + string.ascii_letters + string.punctuation]
+ string.digits + string.ascii_letters + string.punctuation
+ ' '
]
return None
def send_gamestate(self, connection_id=None):
return None
def send_gamestate(self, connection_id=None):
@@
-79,23
+86,33
@@
class Game(GameBase):
def send_thing(thing):
self.io.send('THING_POS %s %s' % (thing.id_, t.position))
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_, 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)))
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, self.portals[yx]))
self.io.send('GAME_STATE_COMPLETE')
def run_tick(self):
to_delete = []
for connection_id in self.sessions:
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]
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:
for t in [t for t in self.things]:
if t in self.things:
try:
@@
-104,6
+121,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)
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()
if self.changed:
self.turn += 1
self.send_gamestate()
@@
-163,7
+184,12
@@
class Game(GameBase):
write(f, 'MAP %s' % (self.map_geometry.size,))
for y, line in self.map.lines():
write(f, 'MAP_LINE %5s %s' % (y, quote(line)))
write(f, 'MAP %s' % (self.map_geometry.size,))
for y, line in self.map.lines():
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_
map
(self, size):
+ def new_
world
(self, size):
self.map_geometry = MapGeometrySquare(YX(size.y, size.x))
self.map = Map(self.map_geometry.size)
self.map_geometry = MapGeometrySquare(YX(size.y, size.x))
self.map = Map(self.map_geometry.size)
+ self.annotations = {}