ai: fix some crashes

This commit is contained in:
John Cote 2019-12-30 18:20:32 -05:00
parent 75119eee78
commit fc36f32e97
3 changed files with 12 additions and 8 deletions

View file

@ -1,7 +1,7 @@
import builtins
import sys
__all__ = ['enumerate', 'nonRepeatingRandomList', 'describeException', 'pdir', 'choice']
__all__ = ['enumerate', 'nonRepeatingRandomList', 'describeException', 'pdir', 'choice', 'cmp']
if not hasattr(builtins, 'enumerate'):
def enumerate(L):
@ -152,7 +152,11 @@ def isClient():
return False
return True
def cmp(a, b):
return (a > b) - (a < b)
builtins.pdir = pdir
builtins.isClient = isClient
builtins.choice = choice
builtins.cmp = cmp

View file

@ -253,7 +253,7 @@ class DistributedBuildingMgrAI:
if os.path.exists(working):
os.remove(working)
os.rename(fileName, working)
file = open(working, 'w')
file = open(working, 'wb')
file.seek(0, 2)
self.saveTo(file, block)
file.close()
@ -267,7 +267,7 @@ class DistributedBuildingMgrAI:
backup = fileName + self.backupExtension
if os.path.exists(fileName):
os.rename(fileName, backup)
file = open(fileName, 'w')
file = open(fileName, 'wb')
file.seek(0)
self.saveTo(file)
file.close()
@ -291,12 +291,12 @@ class DistributedBuildingMgrAI:
def load(self):
fileName = self.getFileName()
try:
file = open(fileName + self.backupExtension, 'r')
file = open(fileName + self.backupExtension, 'rb')
if os.path.exists(fileName):
os.remove(fileName)
except IOError:
try:
file = open(fileName, 'r')
file = open(fileName, 'rb')
except IOError:
return {}

View file

@ -1,5 +1,5 @@
from otp.ai.AIBaseGlobal import *
import random
import random, functools
from toontown.suit import SuitDNA
from direct.directnotify import DirectNotifyGlobal
from toontown.suit import DistributedSuitAI
@ -31,7 +31,7 @@ class SuitPlannerInteriorAI:
for currChance in range(num):
joinChances.append(random.randint(1, 100))
joinChances.sort(cmp)
joinChances.sort(key=functools.cmp_to_key(cmp))
return joinChances
def _genSuitInfos(self, numFloors, bldgLevel, bldgTrack):
@ -120,7 +120,7 @@ class SuitPlannerInteriorAI:
bossLvlRange = bldgInfo[SuitBuildingGlobals.SUIT_BLDG_INFO_BOSS_LVLS]
newLvl = random.randint(bossLvlRange[0], bossLvlRange[1])
lvlList.append(newLvl)
lvlList.sort(cmp)
lvlList.sort(key=functools.cmp_to_key(cmp))
self.notify.debug('LevelList: ' + repr(lvlList))
return lvlList