本文整理汇总了Python中ige.IDataHolder.IDataHolder.quantity方法的典型用法代码示例。如果您正苦于以下问题:Python IDataHolder.quantity方法的具体用法?Python IDataHolder.quantity怎么用?Python IDataHolder.quantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ige.IDataHolder.IDataHolder
的用法示例。
在下文中一共展示了IDataHolder.quantity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startConstruction
# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import quantity [as 别名]
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
示例2: startGlobalConstruction
# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import quantity [as 别名]
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