當前位置: 首頁>>代碼示例>>Python>>正文


Python PlayerUtil.getPlayerTeamAndID方法代碼示例

本文整理匯總了Python中PlayerUtil.getPlayerTeamAndID方法的典型用法代碼示例。如果您正苦於以下問題:Python PlayerUtil.getPlayerTeamAndID方法的具體用法?Python PlayerUtil.getPlayerTeamAndID怎麽用?Python PlayerUtil.getPlayerTeamAndID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PlayerUtil的用法示例。


在下文中一共展示了PlayerUtil.getPlayerTeamAndID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getKnownTrainableUnits

# 需要導入模塊: import PlayerUtil [as 別名]
# 或者: from PlayerUtil import getPlayerTeamAndID [as 別名]
def getKnownTrainableUnits(playerOrID, askingPlayerOrID, knowableUnits, bonuses, military=None):
    player, team = PlayerUtil.getPlayerAndTeam(playerOrID)
    askingPlayer = PlayerUtil.getPlayer(askingPlayerOrID)
    eAskingTeam, askingTeam = PlayerUtil.getPlayerTeamAndID(askingPlayer)
    # trade = player.canTradeNetworkWith(askingPlayer.getID())
    cities = PlayerUtil.getPlayerCities(player, lambda city: city.isRevealed(eAskingTeam, False))
    # separate units into two groups: yes and maybe
    units = getTrainableUnits(playerOrID, knowableUnits, False, military)
    yesUnits = set()
    maybeUnits = set()
    BugUtil.debug("-----------------------")
    for eUnit in units:
        if not canAnyCityBuildUnit(eUnit, cities, eAskingTeam, False):
            BugUtil.debug("  no    %s", gc.getUnitInfo(eUnit).getDescription())
        elif hasBonusesForUnit(eUnit, bonuses):
            BugUtil.debug("  yes   %s", gc.getUnitInfo(eUnit).getDescription())
            yesUnits.add(eUnit)
        elif bonuses is None:
            BugUtil.debug("  maybe %s", gc.getUnitInfo(eUnit).getDescription())
            maybeUnits.add(eUnit)
    return yesUnits, maybeUnits
開發者ID:,項目名稱:,代碼行數:23,代碼來源:

示例2: getCanTrainUnits

# 需要導入模塊: import PlayerUtil [as 別名]
# 或者: from PlayerUtil import getPlayerTeamAndID [as 別名]
def getCanTrainUnits(playerOrID, askingPlayerOrID=None, military=None):
	"""
	Returns the set of all units the player can train.
	
	Searches all of the player's cities to find which units can be trained.
	
	If askingPlayerOrID is given, only cities they have seen are checked, and
	only units whose prerequisite techs they know or can research are returned.
	Also, if the two players' trade networks are not connected, units that
	require resources to train are returned in a second set.
	
	If military is provided, only military or civilian units are checked
	depending on its value, True or False, respectively.
	
	*** OBSOLETE ***
	
	"""
	player, team = PlayerUtil.getPlayerAndTeam(playerOrID)
	askingPlayer = PlayerUtil.getPlayer(askingPlayerOrID)
	if askingPlayer:
		eAskingTeam, askingTeam = PlayerUtil.getPlayerTeamAndID(askingPlayer)
		trade = player.canTradeNetworkWith(askingPlayer.getID())
	civInfo = gc.getCivilizationInfo(player.getCivilizationType())
	units = set()
	maybeUnits = set()
	for eClass in range(NUM_CLASSES):
		eUnit = civInfo.getCivilizationUnits(eClass)
		if eUnit == -1:
			classInfo = gc.getUnitClassInfo(eClass)
			BugUtil.debug("%s doesn't have %s", civInfo.getDescription(), classInfo.getDescription())
			eUnit = classInfo.getDefaultUnitIndex()
		unitInfo = gc.getUnitInfo(eUnit)
		if unitInfo:
			if ((military == True and unitInfo.getUnitCombatType() <= 0)
			or (military == False and unitInfo.getUnitCombatType() > 0)):
				BugUtil.debug("skipping (non-)military %s", unitInfo.getDescription())
				continue
			if askingPlayer:
				for eTech in unitTechs[eUnit]:
					if not (askingTeam.isHasTech(eTech) or askingPlayer.canResearch(eTech, False)):
						BugUtil.debug("%s doesn't comprehend %s", askingPlayer.getName(), gc.getTechInfo(eTech).getDescription())
						skip = True
						break
				else:
					skip = False
				if skip:
					BugUtil.debug("skipping unknowable %s", unitInfo.getDescription())
					continue
			for city in PlayerUtil.playerCities(player):
				if askingPlayer:
					if not city.isRevealed(eAskingTeam, False):
						continue
					if city.canTrain(eUnit, False, not trade):
						if eUnit in unitsWithBonuses:
							maybeUnits.add(eUnit)
						else:
							units.add(eUnit)
						break
				else:
					if city.canTrain(eUnit, False, False):
						units.add(eUnit)
						break
	BugUtil.debug("%s can train:", player.getName())
	for eUnit in units:
		unitInfo = gc.getUnitInfo(eUnit)
		BugUtil.debug("  %s", unitInfo.getDescription())
	if askingPlayer:
		BugUtil.debug("%s can maybe train:", player.getName())
		for eUnit in maybeUnits:
			unitInfo = gc.getUnitInfo(eUnit)
			BugUtil.debug("  %s", unitInfo.getDescription())
		return units, maybeUnits
	else:
		return units
開發者ID:markourm,項目名稱:fall,代碼行數:76,代碼來源:UnitUtil.py


注:本文中的PlayerUtil.getPlayerTeamAndID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。