本文整理汇总了Python中ige.IDataHolder.IDataHolder类的典型用法代码示例。如果您正苦于以下问题:Python IDataHolder类的具体用法?Python IDataHolder怎么用?Python IDataHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDataHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTechInfo
def getTechInfo(techID):
player = db[db.playerID]
tech = Rules.techs[techID]
# player possess this technology
if player.techs.has_key(techID):
return tech
if tech.fullInfo:
return tech
# player can research this technology
canResearch = 1
if player.race not in tech.researchRaces:
canResearch = 0
for tmpTechID, improvement in tech.researchRequires:
if not player.techs.has_key(tmpTechID) or player.techs[tmpTechID] < improvement:
canResearch = 0
break
for stratRes in tech.researchReqSRes:
if player.stratRes.get(stratRes, 0) < 1:
canResearch = 0
break
for tmpTechID in player.techs:
if techID in Rules.techs[tmpTechID].researchDisables:
canResearch = 0
break
if tech.level > player.techLevel:
canResearch = 0
if canResearch:
result = IDataHolder()
result.partialData = None
for attr in [
"name",
"isDiscovery",
"isStructure",
"isProject",
"isShipEquip",
"isShipHull",
"researchMod",
"researchTurns",
"textPreRsrch",
"researchRequires",
"subtype",
"researchReqSRes",
"researchDisables",
"level",
"researchRaces",
]:
setattr(result, attr, getattr(tech, attr))
return result
# player should know only basic params about tech
result = IDataHolder()
result.partialData = None
for attr in ["name", "researchRequires", "subtype", "level", "researchRaces"]:
setattr(result, attr, getattr(tech, attr))
return result
示例2: forceAllyWithEDEN
def forceAllyWithEDEN(self,tran,obj):
for partyID in obj.diplomacyRels.keys():
party = tran.db.get(partyID, None)
if party.type == T_AIEDENPLAYER:
diplSelf = obj.diplomacyRels.get(party.oid, None)
log.debug("Allying Pirate with EDEN (forced)", obj.oid, partyID)
diplEDEN = IDataHolder()
diplEDEN.type = T_DIPLREL
diplEDEN.pacts = {
PACT_ALLOW_CIVILIAN_SHIPS: [PACT_ACTIVE, PACT_ALLOW_CIVILIAN_SHIPS],
PACT_ALLOW_MILITARY_SHIPS: [PACT_ACTIVE, PACT_ALLOW_MILITARY_SHIPS]
}
diplEDEN.relation = REL_FRIENDLY
diplEDEN.relChng = 0
diplEDEN.lastContact = tran.db[OID_UNIVERSE].turn
diplEDEN.contactType = CONTACT_STATIC
diplEDEN.stats = None
diplSelf.relation = REL_FRIENDLY
diplSelf.pacts = {
PACT_ALLOW_CIVILIAN_SHIPS: [PACT_ACTIVE, PACT_ALLOW_CIVILIAN_SHIPS],
PACT_ALLOW_MILITARY_SHIPS: [PACT_ACTIVE, PACT_ALLOW_MILITARY_SHIPS]
}
obj.diplomacyRels[party.oid] = diplSelf
party.diplomacyRels[obj.oid] = diplEDEN
示例3: getDiplomacyWith
def getDiplomacyWith(self, tran, obj, playerID):
# this AI battles with overyone
# make default
dipl = IDataHolder()
dipl.type = T_DIPLREL
dipl.pacts = {}
if obj.oid == playerID:
dipl.relation = REL_UNITY
else:
dipl.relation = REL_ENEMY
dipl.relChng = 0
dipl.lastContact = tran.db[OID_UNIVERSE].turn
dipl.contactType = CONTACT_NONE
dipl.stats = None
return dipl
示例4: findPopCenterPlanets
def findPopCenterPlanets(db, planetsIDs):
""" It finds "center of mass" of population.
Returns sorted list of all planets, beginning with those nearest to the
found center.
"""
x = 0
y = 0
population = 0
for planetID in planetsIDs:
planet = db[planetID]
x += planet.x * planet.storPop
y += planet.y * planet.storPop
population += planet.storPop
x /= population
y /= population
fakeObj = IDataHolder()
fakeObj.x = x
fakeObj.y = y
return findNearest(db, fakeObj, planetsIDs, maxDist=99999, number=len(planetsIDs))
示例5: getDiplomacyWith
def getDiplomacyWith(contactID):
obj = getPlayer()
dipl = obj.diplomacyRels.get(contactID, None)
if not dipl:
# make default
dipl = IDataHolder()
dipl.type = T_DIPLREL
dipl.pacts = {PACT_ALLOW_CIVILIAN_SHIPS: [PACT_ACTIVE, PACT_ALLOW_CIVILIAN_SHIPS]}
dipl.relation = obj.defaultRelation
dipl.relChng = 0
dipl.lastContact = 0
dipl.stats = None
dipl.contactType = CONTACT_NONE
obj.diplomacyRels[playerID] = dipl
return dipl
示例6: getIntroInfo
def getIntroInfo(self, tran, obj):
result = IDataHolder()
result.cid = tran.cid
result.turn = obj.turn
result.serverTime = time.time()
result.version = ige.version.version
# legacy client side update support
# TODO: Remove once not needed
result.lastClientVersion = (
ige.version.major,
ige.version.minor,
ige.version.revision,
ige.version.status,
)
result.lastClientRevision = ige.version.svnRevision
return result
示例7: getDiplomacyWith
def getDiplomacyWith(self, tran, obj, playerID):
if obj.governorOf:
# player is a governor
leader = tran.db[obj.governorOf]
return self.cmd(leader).getDiplomacyWith(tran, leader, objID)
# player is independent
dipl = obj.diplomacyRels.get(playerID, None)
if not dipl:
# make default
dipl = IDataHolder()
dipl.type = T_DIPLREL
dipl.pacts = {
PACT_ALLOW_CIVILIAN_SHIPS: [PACT_ACTIVE, PACT_ALLOW_CIVILIAN_SHIPS]
}
dipl.relation = obj.defaultRelation
dipl.relChng = 0
dipl.lastContact = tran.db[OID_UNIVERSE].turn
dipl.contactType = CONTACT_NONE
dipl.stats = None
if playerID != obj.oid:
obj.diplomacyRels[playerID] = dipl
else:
log.debug("getDiplomacyWith myself", obj.oid)
return dipl
示例8: startGlobalConstruction
def startGlobalConstruction(self, tran, player, techID, quantity, isShip, reportFinished, queue):
if len(player.prodQueues) <= queue:
raise GameException('Invalid queue.')
if len(player.prodQueues[queue]) > Rules.maxProdQueueLen:
raise GameException('Queue is full.')
if quantity < 1:
raise GameException("Quantity must be greater than 0")
if not player.techs.has_key(techID) and isShip == 0:
raise GameException('You do not own this kind of technology.')
if not player.shipDesigns.has_key(techID) and isShip == 1:
raise GameException('You do not own this ship design.')
if isShip:
tech = player.shipDesigns[techID]
if tech.upgradeTo:
raise GameException("You cannot build obsolete ship design.")
else:
tech = Rules.techs[techID]
if tech.isStructure or not tech.isProject:
raise GameException('You cannot construct this technology.')
elif tech.globalDisabled:
raise GameException('You cannot construct targeted project.')
neededSR = {}
for sr in tech.buildSRes:
if player.stratRes.get(sr, 0) < neededSR.get(sr, 0) + quantity:
raise GameException("You do not own required strategic resource(s)")
neededSR[sr] = neededSR.get(sr, 0) + quantity
# consume strategic resources
for sr in neededSR:
player.stratRes[sr] -= neededSR[sr]
# start construction
item = IDataHolder()
item.techID = techID
item.quantity = int(quantity)
item.changePerc = 0
item.isShip = bool(isShip)
item.reportFin = bool(reportFinished)
item.type = T_TASK
player.prodQueues[queue].append(item)
return player.prodQueues[queue], player.stratRes
示例9: startResearch
def startResearch(self, tran, obj, techID, improveToMax = 0):
if len(obj.rsrchQueue) > Rules.maxRsrchQueueLen:
GameException('Queue is full.')
tech = Rules.techs[techID]
# player has to be a right race
if obj.race not in tech.researchRaces:
raise GameException("Your race cannot research this technology.")
# item cannot be researched twice
for tmpTech in obj.rsrchQueue:
if tmpTech.techID == techID:
raise GameException('Technology is already sheduled for research.')
# disabled?
for tmpTechID in obj.techs:
if techID in Rules.techs[tmpTechID].researchDisables:
raise GameException("Previous research has disabled this technology.")
# check requirements
for tmpTechID, improvement in tech.researchRequires:
if not obj.techs.has_key(tmpTechID) or obj.techs[tmpTechID] < improvement:
raise GameException('You cannot research this technology yet.')
improvement = obj.techs.get(techID, Rules.techBaseImprovement - 1) + 1
if improvement > Rules.techMaxImprovement or improvement > tech.maxImprovement:
raise GameException('You cannot improve this technology further.')
if tech.level > obj.techLevel:
raise GameException("Your technological level is insufficient.")
# check strategic resources
if improvement == 1:
for stratRes in tech.researchReqSRes:
if obj.stratRes.get(stratRes, 0) < 1:
raise GameException("Required strategy resource missing.")
item = IDataHolder()
item.techID = techID
item.improvement = improvement
item.currSci = 0
item.changeSci = 0
item.improveToMax = improveToMax
item.type = T_RESTASK
obj.rsrchQueue.append(item)
return obj.rsrchQueue
示例10: getPublicInfo
def getPublicInfo(self, tran, obj):
result = IDataHolder()
result.oid = obj.oid
return result
示例11: makeShipFullSpec
def makeShipFullSpec(player, name, hullID, eqIDs, improvements, raiseExs = True):
if not hullID:
raise GameException("Ship's hull must be specified.")
hull = Rules.techs[hullID]
if not hull.isShipHull:
raise GameException("Ship's hull must be specified.")
ship = IDataHolder()
ship.type = Const.T_SHIP
# initial values
hullTechEff = Rules.techImprEff[player.techs.get(hullID, Rules.techBaseImprovement)]
ship.name = name
ship.hullID = hullID
ship.eqIDs = eqIDs
ship.level = hull.level
ship.combatClass = hull.combatClass
ship.improvements = improvements
ship.buildProd = hull.buildProd
ship.buildSRes = copy.copy(hull.buildSRes)
# stats grouped as "Base"
ship.operEn = hull.operEn
ship.storEn = hull.storEn * hullTechEff
ship.weight = hull.weight
ship.slots = 0
ship.scannerPwr = max(hull.scannerPwr * hullTechEff, Rules.scannerMinPwr)
ship.engPwr = 0
ship.engStlPwr = 0
ship.speed = 0.0
ship.battleSpeed = 0.0
# stats grouped as "Signature"
ship.signature = hull.signature
ship.negsignature = 0
ship.minSignature = hull.minSignature
ship.signatureCloak = 1.0
ship.signatureDecloak = 1.0
# stats grouped as "Combat"
ship.combatAttBase = hull.combatAtt * hullTechEff
ship.combatAtt = 0
ship.combatAttMultiplier = 1.0
ship.combatDefBase = hull.combatDef * hullTechEff
ship.combatDef = 0
ship.combatDefMultiplier = 1.0
ship.missileDefBase = hull.missileDef * hullTechEff
ship.missileDef = 0
ship.missileDefMultiplier = 1.0
ship.weaponIDs = []
ship.isMilitary = 0
ship.baseExp = 0
combatExtra = 0
# stats grouped as "Sturdiness"
ship.autoRepairFix = hull.autoRepairFix
ship.autoRepairPerc = hull.autoRepairPerc
ship.shieldRechargeFix = hull.shieldRechargeFix
ship.shieldRechargePerc = hull.shieldRechargePerc
ship.hardShield = 0.0
ship.shieldHP = 0
ship.maxHP = int(hull.maxHP * hullTechEff)
ship.damageAbsorb = 0
shieldPerc = 0.0
# stats grouped as "Deployables"
ship.deployStructs = []
ship.deployHandlers = []
ship.upgradeTo = 0
counter = {}
installations = {}
equipCounter = {}
for techID in eqIDs:
tech = Rules.techs[techID]
techEff = Rules.techImprEff[player.techs.get(techID, Rules.techBaseImprovement)]
if eqIDs[techID] < 0 and raiseExs:
raise GameException("Invalid equipment count (less than 0).")
for i in xrange(0, eqIDs[techID]):
counter[tech.subtype] = 1 + counter.get(tech.subtype, 0)
installations[techID] = 1 + installations.get(techID, 0)
_checkValidity(ship, tech, installations, equipCounter, raiseExs)
# add values
_moduleBase(ship, tech, techEff)
_moduleSignature(ship, tech)
_moduleCombat(ship, tech, techEff, combatExtra)
_moduleSturdiness(ship, tech, techEff, shieldPerc)
_moduleDeployables(ship, tech)
_checkValidityWhole(ship, hull, counter, raiseExs)
_finalizeBase(ship, hull)
_finalizeSignature(ship, hull)
_finalizeCombat(ship)
_finalizeSturdiness(ship, shieldPerc)
_setCombatPower(ship, combatExtra)
return ship
示例12: tool_parseDB
def tool_parseDB(client, db, enemyTypes):
""" Parses all data in db for needs of other tools. Other in the name
means other players.
"""
data = IDataHolder()
data.myPlanets = set()
data.myProdPlanets = set()
data.mySystems = set()
data.freePlanets = set()
data.freeSystems = set()
data.nonhabPlanets = set()
data.unknownSystems = set()
data.otherPlanets = set()
data.enemyPlanets = set()
data.otherSystems = set()
data.enemySystems = set()
data.systems = set()
data.myFleets = set()
data.myMPPerSystem = {}
data.myTargetedSystems = set()
data.endangeredSystems = {}
data.otherFleets = set()
data.otherInboundFleets = set()
data.idleFleets = set()
data.myFleetsWithDesign = {}
data.myFleetSheets = {}
data.pirateSystems = set()
data.relevantSystems = set()
data.myRelevantSystems = set()
data.distanceToRelevance = {}
playerID = client.getPlayerID()
player = client.getPlayer()
owners = {}
for objID in db.keys():
try:
obj = db[objID]
except KeyError:
# TODO find out why there are these errors
continue
objType = getattr(obj, 'type', None)
if objType == Const.T_PLANET:
ownerID = getattr(obj, 'owner', None)
plSlots = getattr(obj, 'plSlots', 0)
slots = getattr(obj, 'slots', [])
prodProd = getattr(obj, 'prodProd', 0)
plType = getattr(obj, 'plType', None)
if plType == u'G' or plType == u'A':
data.nonhabPlanets.add(objID)
continue
if ownerID == playerID and prodProd:
data.myProdPlanets.add(objID)
data.mySystems.add(obj.compOf)
elif ownerID == playerID and not prodProd:
# myPlanets are later joined by myProdPlanets
data.myPlanets.add(objID)
data.mySystems.add(obj.compOf)
elif ownerID == Const.OID_NONE and plSlots:
data.freePlanets.add(objID)
elif not plSlots:
data.unknownSystems.add(obj.compOf)
else:
# systems with owner other than myself, ignore EDEN planets
if not ownerID:
continue
elif ownerID not in owners:
owners[ownerID] = client.get(ownerID, publicOnly = 1)
if not getattr(owners[ownerID], 'type', Const.OID_NONE) == Const.T_AIEDENPLAYER:
data.otherSystems.add(db[objID].compOf)
data.otherPlanets.add(objID)
if getattr(owners[ownerID], 'type', Const.OID_NONE) in enemyTypes:
data.enemySystems.add(db[objID].compOf)
data.enemyPlanets.add(objID)
if getattr(owners[ownerID], 'type', Const.OID_NONE) in (Const.T_AIPIRPLAYER, Const.T_PIRPLAYER):
data.pirateSystems.add(db[objID].compOf)
elif objType == Const.T_SYSTEM:
if getattr(obj, "starClass", "a")[0] == 'b':
# black hole -> nothing to see here, let's ignore it completely
continue
data.systems.add(objID)
if not hasattr(db[objID], 'planets'):
data.unknownSystems.add(objID)
elif objType == Const.T_FLEET:
ownerID = getattr(obj, 'owner', None)
if ownerID == playerID:
data.myFleets.add(objID)
data.myFleetSheets[objID] = getFleetSheet(obj)
if len(obj.actions[obj.actionIndex:]) == 0:
data.idleFleets.add(objID)
for designID in data.myFleetSheets[objID].keys():
if not data.myFleetsWithDesign.get(designID, set()):
data.myFleetsWithDesign[designID] = set([objID])
else:
data.myFleetsWithDesign[designID] |= set([objID])
else:
data.otherFleets.add(objID)
# ==================
# second phase
# analyzing fleet action queues
#.........这里部分代码省略.........
示例13: startConstruction
def startConstruction(self, tran, obj, techID, quantity, targetID, isShip, reportFinished,
demolishStruct):
if len(obj.prodQueue) > Rules.maxProdQueueLen:
raise GameException('Queue is full.')
if quantity < 1:
raise GameException("Quantity must be greater than 0")
player = tran.db[obj.owner]
if not player.techs.has_key(techID) and isShip == 0:
raise GameException('You do not own this kind of technology.')
if not player.shipDesigns.has_key(techID) and isShip == 1:
raise GameException('You do not own this ship design.')
if targetID not in tran.db[obj.compOf].planets:
raise GameException('You can build only in the same system.')
if isShip:
tech = player.shipDesigns[techID]
if tech.upgradeTo:
raise GameException("You cannot build obsolete ship design.")
else:
tech = Rules.techs[techID]
if not (tech.isStructure or tech.isProject):
raise GameException('You cannot construct this technology.')
if not tech.validateConstrHandler(tran, obj, tran.db[targetID], tech):
raise GameException('Conditions for construction are not satisfied.')
neededSR = {}
for sr in tech.buildSRes:
if player.stratRes.get(sr, 0) < neededSR.get(sr, 0) + quantity:
raise GameException("You do not own required strategic resource(s)")
neededSR[sr] = neededSR.get(sr, 0) + quantity
# consume strategic resources
for sr in neededSR:
player.stratRes[sr] -= neededSR[sr]
# start construction
item = IDataHolder()
item.techID = techID
item.currProd = 0
item.currTurn = 0
item.quantity = int(quantity)
item.targetID = targetID
item.changePerc = 0
item.isShip = bool(isShip)
item.reportFin = bool(reportFinished)
item.demolishStruct = demolishStruct
item.type = T_TASK
obj.prodQueue.append(item)
return obj.prodQueue, player.stratRes
示例14: getScanInfos
def getScanInfos(self, tran, obj, scanPwr, player):
if scanPwr >= Rules.level1InfoScanPwr:
result = IDataHolder()
result._type = T_SCAN
result.scanPwr = scanPwr
result.oid = obj.oid
result.signature = obj.signature
result.type = obj.type
result.orbit = obj.orbit
result.compOf = obj.compOf
result.x = obj.x
result.y = obj.y
result.plType = obj.plType
if scanPwr >= Rules.level2InfoScanPwr:
result.plDiameter = obj.plDiameter
if getattr(obj, "plType", 'X') != 'G':
result.plMin = obj.plMin
result.plBio = obj.plBio
result.plEn = obj.plEn
result.plSlots = obj.plSlots
result.plStratRes = obj.plStratRes
result.plMaxSlots = obj.plMaxSlots
if scanPwr >= Rules.level3InfoScanPwr:
result.name = obj.name
result.storPop = obj.storPop
result.owner = obj.owner
if scanPwr >= Rules.level4InfoScanPwr:
# TODO provide less information
result.hasRefuel = (obj.refuelInc > 0) #simple detect if docks exist for problems dialog
result.slots = obj.slots
result.shield = obj.shield
result.prevShield = -1
result.maxShield = -1
if scanPwr >= Rules.partnerScanPwr:
result.maxShield = obj.maxShield
result.prevShield = obj.prevShield
result.refuelMax = obj.refuelMax
result.refuelInc = obj.refuelInc
result.scannerPwr = obj.scannerPwr
result.trainShipInc = obj.trainShipInc
result.trainShipMax = obj.trainShipMax
result.upgradeShip = obj.upgradeShip
result.repairShip = obj.repairShip
result.fleetSpeedBoost = obj.fleetSpeedBoost
return [result]
示例15: processRSRCHPhase
#.........这里部分代码省略.........
wantSci = min(epts, researchSci - item.currSci,
researchSci / tech.researchTurns)
item.currSci += wantSci
item.changeSci = wantSci
epts -= wantSci
if item.currSci >= researchSci:
del obj.rsrchQueue[index]
obj.techs[item.techID] = item.improvement
# call finish handler
tech = Rules.techs[item.techID]
tech.finishResearchHandler(tran, obj, tech)
Utils.sendMessage(tran, obj, MSG_COMPLETED_RESEARCH, OID_NONE, item.techID)
# update derived attributes of player
self.cmd(obj).update(tran, obj)
# repeat research if required by player
if item.improveToMax == 1 and item.improvement < Rules.techMaxImprovement:
# reinsert the item on the top of the queue
self.cmd(obj).startResearch(tran, obj, item.techID, improveToMax = 1)
idx = len(obj.rsrchQueue) - 1
self.cmd(obj).moveResearch(tran, obj, idx, - idx)
if epts > 0 and 0: # TODO: remove me
Utils.sendMessage(tran, obj, MSG_WASTED_SCIPTS, OID_NONE, epts)
return
# oops we have negative epts
while epts < 0:
log.debug("Not enought RP", epts, obj.oid)
if obj.rsrchQueue:
item = obj.rsrchQueue[0]
if item.currSci > 0:
wantSci = min(item.currSci, - epts)
item.currSci -= wantSci
item.changeSci = - wantSci
epts += wantSci
if item.currSci == 0:
# remove item from the queue - TODO send message to player
del obj.rsrchQueue[0]
# at this point, epts can be zero
if epts == 0:
log.debug("RP deficit satisfied", obj.oid)
break
# try next project
if obj.rsrchQueue:
continue
# oops we must find technology to degrade
avail = obj.techs.keys()
# do not degrade technologies, which enables others
for techID in obj.techs:
tech = Rules.techs[techID]
for tmpTechID, impr in tech.researchRequires:
if tmpTechID in avail:
avail.remove(tmpTechID)
log.debug("Techs avialable for degradation", avail)
if not avail:
# no technology...
break
# from hight to low IDs
avail.sort()
avail.reverse()
degraded = 0
for level in range(obj.techLevel, 0, -1):
for techID in avail:
tech = Rules.techs[techID]
# check level
if tech.level != level:
continue
# do not touch starting technologies
if tech.isStarting and obj.techs[techID] <= 3:
continue
# ok we have one to degrade
item = IDataHolder()
item.techID = techID
item.improvement = obj.techs[techID]
item.currSci = Utils.getTechRCost(obj, techID, obj.techs[techID])
item.changeSci = 0
item.improveToMax = 0
item.type = T_RESTASK
obj.rsrchQueue.append(item)
# degrade tech
if obj.techs[techID] == 1:
# TODO send message
del obj.techs[techID]
else:
# TODO send message
obj.techs[techID] -= 1
if tech.recheckWhenTechLost:
# reset some attributes
plLevel = obj.techLevel
obj.techLevel = 1
# recheck remaining techs
for level in range(1, plLevel + 1):
for techID in obj.techs:
tech = Rules.techs[techID]
if tech.level != level:
continue
# call finish handler again
tech.finishResearchHandler(tran, obj, tech)
degraded = 1
break
if degraded: break
return