hmm?? uh, it should be there! I just forget to update the comments.
def abletogen(self,ch_sx, ch_sy, ch_w, ch_h):
check = 1
global points
for check_w in range(ch_w):
for check_h in range(ch_h):
if self.map[ch_sx+check_w][ch_sy+check_h] > 0:
check = 0
for check_w in range(ch_w):
for check_h in range(ch_h):
if self.map[ch_sx-check_w][ch_sy-check_h] > 0:
check = 0
return check
def pathfind(startx=0,starty=0,endx=4,endy=0):
notdone = 1
crashguard = 0
#Add the starting square (or node) to the open list.
openlist = [[startx,starty, 0, (abs(startx - endx * 10))+(abs(starty - endy*10))]]
closedlist = []
inlist = 0
while notdone:
lowestf = openlist[0]
entity.DBmsg("Starting Pathchecking loop...")
#Repeat the following:
for f in openlist:
#a) Look for the lowest F cost square on the open list. We refer to this as the current square.
if f[2]+f[3] < lowestf[2]+lowestf[3]:
lowestf = f
#b) Switch it to the closed list.
closedlist.append(lowestf)
entity.DBmsg("Added:" + str(lowestf[0]) +"," + str(lowestf[1]) + " to path list.")
if lowestf[0] == endx and lowestf[1] == endy:
notdone = 0
for f in openlist:
if f == lowestf:
openlist.remove(f)
pass
for x in range (0,3):
for y in range(0,3):
#If it is not walkable or if it is on the closed list, ignore it. Otherwise do the following.
if game.levels[game.gv_currentdungeon].map[lowestf[0]-1+x][lowestf[1]-1+y] == 1:
entity.DBmsg("Can't add that square.")
pass
else:
if x == 0 and y == 0:
listcheck = [lowestf[0]-1+x,lowestf[1]-1+y,14,(abs(lowestf[0]-1+x - endx * 10))+(abs(lowestf[1]-1+y- endy*10))]
else:
listcheck = [lowestf[0]-1+x,lowestf[1]-1+y,10,(abs(lowestf[0]-1+x - endx * 10))+(abs(lowestf[1]-1+y- endy*10))]
for f in openlist:
if inlist == 0:
#If it is on the open list already, check to see if this path to that square is better, using G cost as the measure.
#A lower G cost means that this is a better path. If so, change the parent of the square to the current square,
#and recalculate the G and F scores of the square. If you are keeping your open list sorted by F score, you may need to resort the list to account for
#the change.
if f[0] == listcheck[0] and f[1] == listcheck[1]:
inlist = 1
if listcheck[2] < f[2]:
openlist.remove(f)
openlist.append(listcheck)
else:
inlist = 0
openlist.append(listcheck)
crashguard += 1
if crashguard == 1000:
return closedlist
return closedlist
it's very buggy. any ideas on how to fix it?