当前位置: 首页>>代码示例>>Python>>正文


Python IDataHolder.techID方法代码示例

本文整理汇总了Python中ige.IDataHolder.IDataHolder.techID方法的典型用法代码示例。如果您正苦于以下问题:Python IDataHolder.techID方法的具体用法?Python IDataHolder.techID怎么用?Python IDataHolder.techID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ige.IDataHolder.IDataHolder的用法示例。


在下文中一共展示了IDataHolder.techID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startConstruction

# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import techID [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
开发者ID:OuterDeepSpace,项目名称:OuterDeepSpace,代码行数:47,代码来源:IPlanet.py

示例2: startGlobalConstruction

# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import techID [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
开发者ID:Lukc,项目名称:ospace-lukc,代码行数:41,代码来源:IPlayer.py

示例3: startResearch

# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import techID [as 别名]
	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
开发者ID:mozts2005,项目名称:OuterSpace,代码行数:40,代码来源:IPlayer.py

示例4: processRSRCHPhase

# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import techID [as 别名]
	def processRSRCHPhase(self, tran, obj, data):
		if not obj.timeEnabled:
			return
		# sci pts from allies
		pts = obj.sciPoints
		for partnerID in obj.diplomacyRels:
			if self.cmd(obj).isPactActive(tran, obj, partnerID, PACT_MINOR_SCI_COOP):
				partner = tran.db[partnerID]
				pactSpec = Rules.pactDescrs[PACT_MINOR_SCI_COOP]
				pts += min(
					int(partner.sciPoints * pactSpec.effectivity),
					int(obj.sciPoints * pactSpec.effectivity),
				)
			if self.cmd(obj).isPactActive(tran, obj, partnerID, PACT_MAJOR_SCI_COOP):
				partner = tran.db[partnerID]
				pactSpec = Rules.pactDescrs[PACT_MAJOR_SCI_COOP]
				pts += min(
					int(partner.sciPoints * pactSpec.effectivity),
					int(obj.sciPoints * pactSpec.effectivity),
				)
		# compute effective sci pts
		obj.effSciPoints = epts = pts - int(obj.stats.storPop * Rules.sciPtsPerCitizen[obj.techLevel])
		index = 0
		while epts > 0 and obj.rsrchQueue and index < len(obj.rsrchQueue):
			item = obj.rsrchQueue[index]
			tech = Rules.techs[item.techID]
			# check requirements
			canResearch = 1
			# player has to be a right race
			if obj.race not in tech.researchRaces:
				canResearch = 0
			for stratRes in tech.researchReqSRes:
				if obj.stratRes.get(stratRes, 0) < 1 and item.improvement == 1:
					Utils.sendMessage(tran, obj, MSG_MISSING_STRATRES, OID_NONE, stratRes)
					canResearch = 0
					break
			for tmpTechID in obj.techs:
				if item.techID in Rules.techs[tmpTechID].researchDisables:
					canResearch = 0
					Utils.sendMessage(tran, obj, MSG_DELETED_RESEARCH, OID_NONE, item.techID)
					del obj.rsrchQueue[index]
					index -= 1
					break
			if tech.level > obj.techLevel:
				canResearch = 0
				Utils.sendMessage(tran, obj, MSG_DELETED_RESEARCH, OID_NONE, item.techID)
				del obj.rsrchQueue[index]
				index -= 1
			if not canResearch:
				index += 1
				continue
			researchSci = Utils.getTechRCost(obj, item.techID)
			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]
#.........这里部分代码省略.........
开发者ID:mozts2005,项目名称:OuterSpace,代码行数:103,代码来源:IPlayer.py


注:本文中的ige.IDataHolder.IDataHolder.techID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。