From 50921e339daf8f2c4cae8ab792e97b8a35a90dbe Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 31 Aug 2015 17:52:18 +0200 Subject: virus direction stats --- subscriber.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'subscriber.py') diff --git a/subscriber.py b/subscriber.py index 483ae04..4327e04 100644 --- a/subscriber.py +++ b/subscriber.py @@ -82,14 +82,37 @@ class EnhancingSubscriber(DummySubscriber): self.c = None self.history = {} self.time = 0 + self.victims = {} def set_client(self,c): self.c = c + + def cleanup_victims(self): + delete = [] + + for eater in self.victims: + self.victims[eater] = list(filter(lambda v : v[1] < self.time - 100, self.victims[eater])) + if len(self.victims[eater]) == 0: + delete += [eater] + + for eater in delete: + del self.victims[eater] + def on_cell_eaten(self, eater_id, eaten_id): + if self.c.world.cells[eater_id].is_virus: + print("virus ate something!") + if eater_id not in self.victims: + self.victims[eater_id] = [] + + self.victims[eater_id] += [(self.c.world.cells[eaten_id], self.time)] + def on_world_update_post(self): self.c.world.time = self.time self.time += 1 + if self.time % 100 == 0: + self.cleanup_victims() + # create and purge poslog history, movement and movement_angle for cid in self.history: self.history[cid].stale = True @@ -183,7 +206,26 @@ class EnhancingSubscriber(DummySubscriber): if is_split: cell.parent = min(cell.player.cells, key=lambda c : (c.pos - cell.poslog[0]).len() if c != cell else float('inf')) - cell.shoot_vec = None # TODO FIXME: use direction of the last ejected blob feed into the mother virus + try: + last_feed = self.victims[cell.parent.cid][-1][0] + if not last_feed.is_ejected_mass: + print("wtf, last virus feed was not ejected mass?!") + raise KeyError + else: + cell.shoot_vec = cell.parent.pos - last_feed.poslog[0] + cell.shoot_vec2 = last_feed.poslog[0] - last_feed.poslog[-1] + try: + pos_when_shot = last_feed.parent.poslog[len(last_feed.poslog)] + cell.shoot_vec3 = cell.parent.pos - pos_when_shot + except: + print("MOAAAHH") + cell.shoot_vec3 = None + except KeyError: + print("wtf, no last virus feed?!") + cell.shoot_vec = None + cell.shoot_vec2 = None + cell.shoot_vec3 = None + cell.calmed_down = False elif cell.is_ejected_mass: -- cgit v1.2.1