ai: fix some crashes
This commit is contained in:
parent
75119eee78
commit
fc36f32e97
3 changed files with 12 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
import builtins
|
import builtins
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
__all__ = ['enumerate', 'nonRepeatingRandomList', 'describeException', 'pdir', 'choice']
|
__all__ = ['enumerate', 'nonRepeatingRandomList', 'describeException', 'pdir', 'choice', 'cmp']
|
||||||
|
|
||||||
if not hasattr(builtins, 'enumerate'):
|
if not hasattr(builtins, 'enumerate'):
|
||||||
def enumerate(L):
|
def enumerate(L):
|
||||||
|
@ -152,7 +152,11 @@ def isClient():
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def cmp(a, b):
|
||||||
|
return (a > b) - (a < b)
|
||||||
|
|
||||||
|
|
||||||
builtins.pdir = pdir
|
builtins.pdir = pdir
|
||||||
builtins.isClient = isClient
|
builtins.isClient = isClient
|
||||||
builtins.choice = choice
|
builtins.choice = choice
|
||||||
|
builtins.cmp = cmp
|
||||||
|
|
|
@ -253,7 +253,7 @@ class DistributedBuildingMgrAI:
|
||||||
if os.path.exists(working):
|
if os.path.exists(working):
|
||||||
os.remove(working)
|
os.remove(working)
|
||||||
os.rename(fileName, working)
|
os.rename(fileName, working)
|
||||||
file = open(working, 'w')
|
file = open(working, 'wb')
|
||||||
file.seek(0, 2)
|
file.seek(0, 2)
|
||||||
self.saveTo(file, block)
|
self.saveTo(file, block)
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -267,7 +267,7 @@ class DistributedBuildingMgrAI:
|
||||||
backup = fileName + self.backupExtension
|
backup = fileName + self.backupExtension
|
||||||
if os.path.exists(fileName):
|
if os.path.exists(fileName):
|
||||||
os.rename(fileName, backup)
|
os.rename(fileName, backup)
|
||||||
file = open(fileName, 'w')
|
file = open(fileName, 'wb')
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
self.saveTo(file)
|
self.saveTo(file)
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -291,12 +291,12 @@ class DistributedBuildingMgrAI:
|
||||||
def load(self):
|
def load(self):
|
||||||
fileName = self.getFileName()
|
fileName = self.getFileName()
|
||||||
try:
|
try:
|
||||||
file = open(fileName + self.backupExtension, 'r')
|
file = open(fileName + self.backupExtension, 'rb')
|
||||||
if os.path.exists(fileName):
|
if os.path.exists(fileName):
|
||||||
os.remove(fileName)
|
os.remove(fileName)
|
||||||
except IOError:
|
except IOError:
|
||||||
try:
|
try:
|
||||||
file = open(fileName, 'r')
|
file = open(fileName, 'rb')
|
||||||
except IOError:
|
except IOError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from otp.ai.AIBaseGlobal import *
|
from otp.ai.AIBaseGlobal import *
|
||||||
import random
|
import random, functools
|
||||||
from toontown.suit import SuitDNA
|
from toontown.suit import SuitDNA
|
||||||
from direct.directnotify import DirectNotifyGlobal
|
from direct.directnotify import DirectNotifyGlobal
|
||||||
from toontown.suit import DistributedSuitAI
|
from toontown.suit import DistributedSuitAI
|
||||||
|
@ -31,7 +31,7 @@ class SuitPlannerInteriorAI:
|
||||||
for currChance in range(num):
|
for currChance in range(num):
|
||||||
joinChances.append(random.randint(1, 100))
|
joinChances.append(random.randint(1, 100))
|
||||||
|
|
||||||
joinChances.sort(cmp)
|
joinChances.sort(key=functools.cmp_to_key(cmp))
|
||||||
return joinChances
|
return joinChances
|
||||||
|
|
||||||
def _genSuitInfos(self, numFloors, bldgLevel, bldgTrack):
|
def _genSuitInfos(self, numFloors, bldgLevel, bldgTrack):
|
||||||
|
@ -120,7 +120,7 @@ class SuitPlannerInteriorAI:
|
||||||
bossLvlRange = bldgInfo[SuitBuildingGlobals.SUIT_BLDG_INFO_BOSS_LVLS]
|
bossLvlRange = bldgInfo[SuitBuildingGlobals.SUIT_BLDG_INFO_BOSS_LVLS]
|
||||||
newLvl = random.randint(bossLvlRange[0], bossLvlRange[1])
|
newLvl = random.randint(bossLvlRange[0], bossLvlRange[1])
|
||||||
lvlList.append(newLvl)
|
lvlList.append(newLvl)
|
||||||
lvlList.sort(cmp)
|
lvlList.sort(key=functools.cmp_to_key(cmp))
|
||||||
self.notify.debug('LevelList: ' + repr(lvlList))
|
self.notify.debug('LevelList: ' + repr(lvlList))
|
||||||
return lvlList
|
return lvlList
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue