summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-26 22:50:06 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-26 22:50:06 +0200
commit739c6c05fdbd980688b847ac778564a32dbd5d8a (patch)
tree30cee2c951ef75a23a229fe8854429a5195b2873
parentbea9a124317fef3556c5cabacdc66124b201b08b (diff)
cell.player attribute
-rw-r--r--subscriber.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/subscriber.py b/subscriber.py
index 01853a8..b2b6643 100644
--- a/subscriber.py
+++ b/subscriber.py
@@ -71,6 +71,11 @@ class CellHistory:
self.poslog = deque(maxlen=10)
self.stale = False
+class OtherPlayer:
+ def __init__(self, playerid):
+ self.playerid = playerid
+ self.cells = set()
+
class EnhancingSubscriber(DummySubscriber):
def __init__(self):
self.c = None
@@ -80,6 +85,8 @@ class EnhancingSubscriber(DummySubscriber):
self.c = c
def on_world_update_post(self):
+
+ # create and purge poslog history, movement and movement_angle
for cid in self.history:
self.history[cid].stale = True
@@ -104,3 +111,18 @@ class EnhancingSubscriber(DummySubscriber):
except (AttributeError, IndexError):
# no oldpos available
pass
+
+
+ # create OtherPlayer entries
+ otherplayers = {}
+ for cell in self.c.world.cells.values():
+ if not cell.is_food and not cell.is_ejected_mass and not cell.is_virus:
+ playerid = (cell.name, cell.color)
+ if playerid not in otherplayers:
+ otherplayers[playerid] = OtherPlayer(playerid)
+
+ cell.player = otherplayers[playerid]
+ cell.player.cells.add(cell)
+ else:
+ cell.player = None
+