Skip to content

Commit

Permalink
Fixes bug #10
Browse files Browse the repository at this point in the history
Not satisfying quick enough - still marking an RFE to improve efficiency
  • Loading branch information
lkingsford committed Nov 9, 2014
1 parent b644130 commit 87e599f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
25 changes: 6 additions & 19 deletions src/Zombie.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def ToDefend(self):
def danger(self):
return (5 + self.levelMod/2)


def RefreshZombies(self):
pass

def update(self):
super().update()
try:
Expand All @@ -56,22 +60,5 @@ def update(self):
return


# Update nearby DVs
for j in [i for i in self.currentMap.characters if i.chartype != "Zombie" and i.chartype != "Necromancer"]:
# Check for adjacent zombies
zombies = [i for i in self.currentMap.characters if (i.chartype == "Zombie")\
and (abs(i.x - j.x) < 2)\
and (abs(i.y - j.y) < 2)]
if len(zombies) > 0:
closedCount = len(zombies)
for x in range(j.x-1,j.x+2):
for y in range(self.y-1,self.y+2):
if self.currentMap.Map[x][y].walkable == False:
closedCount += 1
else:
closedCount = 0
j.ZombieMod = closedCount
if j.ZombieMod > 4 and j.ZombieMod < 8:
self.messageLog.append(Message.Message(j.name + " is almost surrounded by the undead!"))
if j.ZombieMod == 8:
self.messageLog.append(Message.Message(j.name + " has been overrun by the undead!"))
for i in self.currentMap.characters:
i.RefreshZombies()
26 changes: 24 additions & 2 deletions src/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def dead(self):


def update(self):
self.RefreshZombies()
if self.burning:
if self.moved:
self.burnWaitTurns = self.DEFAULT_BURN_WAIT_TURNS
Expand Down Expand Up @@ -557,6 +558,27 @@ def Extinguish(self):
self.burnWaitTurns = self.DEFAULT_BURN_WAIT_TURNS
self.messageLog.append(Message.Message(self.name + " is no longer on fire"))

# This is called when Zombies move, and when the character moves
# I don't know how efficient that is
def RefreshZombies(self):
adjacent_zombies = [i for i in self.currentMap.characters if (i.chartype == "Zombie"\
and (abs(i.x - self.x) < 2)\
and (abs(i.y - self.y) < 2))]
if len(adjacent_zombies) > 0:
closedCount = len(adjacent_zombies)
for x in range(self.x-1,self.x+2):
for y in range(self.y-1,self.y+2):
if self.currentMap.Map[x][y].walkable == False:
closedCount += 1
else:
closedCount = 0
if closedCount > self.ZombieMod:
if self.ZombieMod > 4 and self.ZombieMod < 8:
self.messageLog.append(Message.Message(j.name + " is almost surrounded by the undead!"))
elif self.ZombieMod == 8:
self.messageLog.append(Message.Message(j.name + " has been overrun by the undead!"))
self.ZombieMod = closedCount

def Stun(self):
self.ticksUntilTurn += round(200/self.speed)

Expand Down Expand Up @@ -730,7 +752,7 @@ def GetNearest(self, destLogic, startingPointAllowed = False):
CurSquare = [j for j in (OpenList+ClosedList) if j[0] == CurSquare[2] and j[1] == CurSquare[3]][0]
Route.insert(0, CurSquare)
return Route






0 comments on commit 87e599f

Please sign in to comment.