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


Python IDataHolder.changeSci方法代码示例

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


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

示例1: startResearch

# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import changeSci [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

示例2: processRSRCHPhase

# 需要导入模块: from ige.IDataHolder import IDataHolder [as 别名]
# 或者: from ige.IDataHolder.IDataHolder import changeSci [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.changeSci方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。