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 --- game_mechanics.txt | 8 ------ gui.py | 9 ++++++ reversing_game_mechanics/game_mechanics.txt | 8 ++++++ subscriber.py | 44 ++++++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 9 deletions(-) delete mode 100644 game_mechanics.txt create mode 100644 reversing_game_mechanics/game_mechanics.txt diff --git a/game_mechanics.txt b/game_mechanics.txt deleted file mode 100644 index 9c64805..0000000 --- a/game_mechanics.txt +++ /dev/null @@ -1,8 +0,0 @@ -can eject: if size >= 60 i.e. mass >= 35 -eject makes me lose 16 mass -eject distance is between (600+my.size) and (700+my.size), about 10-15 deg deviation -can eat ejected mass if mass >= 18 i.e. size >= 43 - -cell can eat us, if their size/mass(??) is at least 1.25* our size/mass - -zoom level is 369.399 * sum(own_cells.size) ** 0.431776 diff --git a/gui.py b/gui.py index 6ba6f36..2040f32 100644 --- a/gui.py +++ b/gui.py @@ -319,8 +319,12 @@ def draw_markers(): def draw_debug(): for cell in c.world.cells.values(): parent = None + shoot_vec = None + settled = None try: parent = cell.parent + shoot_vec = cell.shoot_vec + settled = cell.calmed_down except AttributeError: pass @@ -329,6 +333,11 @@ def draw_debug(): draw_circle(parent.pos,3,(255,0,0),True) + if shoot_vec != None and settled != True: + shoot_vec = 400 * shoot_vec / shoot_vec.len() + draw_line(cell.pos, cell.pos+shoot_vec, (0,255,255)) + + def draw_frame(): global screen, movement, zoom, screensize, input, bot_input, marker, marker_updated, running diff --git a/reversing_game_mechanics/game_mechanics.txt b/reversing_game_mechanics/game_mechanics.txt new file mode 100644 index 0000000..9c64805 --- /dev/null +++ b/reversing_game_mechanics/game_mechanics.txt @@ -0,0 +1,8 @@ +can eject: if size >= 60 i.e. mass >= 35 +eject makes me lose 16 mass +eject distance is between (600+my.size) and (700+my.size), about 10-15 deg deviation +can eat ejected mass if mass >= 18 i.e. size >= 43 + +cell can eat us, if their size/mass(??) is at least 1.25* our size/mass + +zoom level is 369.399 * sum(own_cells.size) ** 0.431776 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.3