コード例 #1
0
ファイル: RevUtils.py プロジェクト: csu-anzai/Caveman2Cosmos
def computeBribeCosts(CyCity):
    iTurn = GAME.getGameTurn()

    turnBribeData = RevData.getCityVal(CyCity, 'TurnBribeCosts')
    if turnBribeData != None and iTurn == turnBribeData[0]:
        return [turnBribeData[1][0], turnBribeData[1][1], turnBribeData[1][2]]

    # Compute costs to bribe rebels at three levels
    # Start by computing a base cost based on players economy strength
    iPlayer = CyCity.getOwner()
    CyPlayer = GC.getPlayer(iPlayer)

    iRevIdx = CyCity.getRevolutionIndex()
    localRevIdx = CyCity.getLocalRevIndex()

    iPop = CyCity.getPopulation()
    fBaseCost = (iRevIdx + 16 * localRevIdx +
                 3 * CyCity.getNumRevolts(iPlayer)) * (iPop**1.1) / 8.0

    fMod = (1 + CyPlayer.getCurrentEra() - 9 / (8.1 + iPop**1.3)) / 3
    fMod *= GC.getGameSpeedInfo(
        GAME.getGameSpeedType()).getGrowthPercent() / 100.0

    if not CyPlayer.isHuman():
        fMod /= 2

    iCost = int(fMod * fBaseCost)
    if iCost < 3:
        iCost = 3
    aList = [2 * iCost / 3, iCost, 5 * iCost / 3]
    RevData.setCityVal(CyCity, 'TurnBribeCosts', [iTurn, aList])

    return aList
コード例 #2
0
ファイル: RevUtils.py プロジェクト: csu-anzai/Caveman2Cosmos
def bribeCity(CyCity, bribeSize):

    if bribeSize == 'Small':
        # Small reduction in rev index, mostly just for buyoffturns
        newRevIdx = int(0.9 * CyCity.getRevolutionIndex() - 10)
        if newRevIdx < 0:
            newRevIdx = 0
        CyCity.changeRevolutionCounter(5)
    elif bribeSize == 'Med':
        # Med reduction in rev index
        newRevIdx = int(0.8 * CyCity.getRevolutionIndex() - 25)
        if newRevIdx < 0:
            newRevIdx = 0
        CyCity.changeRevolutionCounter(7)
    elif bribeSize == 'Large':
        # Large reduction in rev index, longer time till next revolt too
        newRevIdx = int(0.7 * CyCity.getRevolutionIndex() - 50)
        if newRevIdx < 0:
            newRevIdx = 0
        CyCity.changeRevolutionCounter(10)
    else:
        print 'Error!  Unrecognized bribeSize string %s' % bribeSize
        return
    CyCity.setRevolutionIndex(newRevIdx)
    RevData.setCityVal(CyCity, 'BribeTurn', GAME.getGameTurn())
    RevData.setCityVal(CyCity, 'TurnBribeCosts', None)
コード例 #3
0
def onCityAcquired( argsList ):
	owner,playerType,pCity,bConquest,bTrade = argsList

	checkRebelBonuses( argsList )
	updateRevolutionIndices( argsList )

	# Init city script data (unit spawn counter, rebel player)
	iRevCiv = RevData.getCityVal(pCity, 'RevolutionCiv')
	RevData.initCity(pCity)
	RevData.setCityVal( pCity, 'RevolutionCiv', iRevCiv )

	iTurns = pCity.getOccupationTimer()
	pCity.setRevolutionCounter( max([int(1.5*iTurns),3]) )
コード例 #4
0
def doSmallRevolts(iPlayer, CyPlayer):

	if iPlayer > 39:
		raise "NPC does not revolt!"

	for city in CyPlayer.cities():

		revIdx = city.getRevolutionIndex()

		if revIdx <= 5 * RevDefs.revReadyDividend * RevDefs.revInstigatorThreshold / (4 * RevDefs.revReadyDivisor):
			continue

		if city.getOccupationTimer() > 0 or city.getRevolutionCounter() > 0 or RevData.getCityVal(city, 'SmallRevoltCounter') > 0:
			continue # Already in a revolt

		localRevIdx = city.getLocalRevIndex()
		if localRevIdx > 0:
			localFactor = 1 + localRevIdx / 3
			if localFactor > 10:
				localFactor = 10
		else:
			localFactor = localRevIdx - 1
			if localFactor < -15:
				localFactor = -15

		iOdds = localFactor + 100 * revIdx / (8 * RevDefs.alwaysViolentThreshold)
		if iOdds > 15:
			iOdds = 15

		if GAME.getSorenRandNum(100, "Rev: Small Revolt") < iOdds:
			szName = city.getName()
			print "[REV] Small revolt in %s with odds %d (%d idx, %d loc)" %(szName, iOdds, revIdx, localRevIdx)
			city.setOccupationTimer(2)

			RevData.setCityVal(city, 'SmallRevoltCounter', 6)

			szTxt = TRNSLTR.getText("TXT_KEY_REV_MESS_SMALL_REVOLT",()) % szName
			icon = CyArtFileMgr().getInterfaceArtInfo("INTERFACE_RESISTANCE").getPath()
			CvUtil.sendMessage(szTxt, iPlayer, 16, icon, ColorTypes(7), city.getX(), city.getY(), True, True, InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT, "AS2D_CITY_REVOLT", False)
コード例 #5
0
ファイル: RevEvents.py プロジェクト: adityavs/Caveman2Cosmos
def doSmallRevolts(iPlayer, CyPlayer):

	CyCity, i = CyPlayer.firstCity(False)
	while CyCity:

		revIdx = CyCity.getRevolutionIndex()

		if revIdx > int(1.25*RevDefs.revReadyFrac*RevDefs.revInstigatorThreshold):

			if CyCity.getOccupationTimer() > 0 or CyCity.getRevolutionCounter() > 0 or RevData.getCityVal(CyCity, 'SmallRevoltCounter') > 0:
				CyCity, i = CyPlayer.nextCity(i, False)
				continue # Already in a revolt

			localRevIdx = CyCity.getLocalRevIndex()
			if localRevIdx > 0:
				localFactor = 1 + localRevIdx/3
				if localFactor > 10:
					localFactor = 10
			else:
				localFactor = localRevIdx - 1
				if localFactor < -15:
					localFactor = -15

			iOdds = int(100*revIdx/(8.0*RevDefs.alwaysViolentThreshold)) + localFactor
			if iOdds > 15:
				iOdds = 15

			if GAME.getSorenRandNum(100, "Rev: Small Revolt") < iOdds:
				szName = CyCity.getName()
				print "[REV] Small revolt in %s with odds %d (%d idx, %d loc)" %(szName, iOdds, revIdx, localRevIdx)
				CyCity.setOccupationTimer(2)

				RevData.setCityVal(CyCity, 'SmallRevoltCounter', 6)

				szTxt = TRNSLTR.getText("TXT_KEY_REV_MESS_SMALL_REVOLT",()) % szName
				icon = CyArtFileMgr().getInterfaceArtInfo("INTERFACE_RESISTANCE").getPath()
				CvUtil.sendMessage(szTxt, iPlayer, 16, icon, ColorTypes(7), CyCity.getX(), CyCity.getY(), True, True, InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT, "AS2D_CITY_REVOLT", False)

		CyCity, i = CyPlayer.nextCity(i, False)
コード例 #6
0
def computeBribeCosts( pCity, bSilent = True ) :

	iSmall = -1
	iMed = -1
	iLarge = -1

	turnBribeData = RevData.getCityVal( pCity, 'TurnBribeCosts' )
	if( not turnBribeData == None ) :
		if( game.getGameTurn() == turnBribeData[0] ) :
			iSmall = turnBribeData[1][0]
			iMed = turnBribeData[1][1]
			iLarge = turnBribeData[1][2]

			return [iSmall, iMed, iLarge]

	# Compute costs to bribe rebels at three levels
	# Start by computing a base cost based on players economy strength
	iTurn = game.getGameTurn()
	pPlayer = gc.getPlayer( pCity.getOwner() )
	iGold = pPlayer.getGold()
	iEra = pPlayer.getCurrentEra()

	if( LOG_DEBUG and not bSilent ) : CvUtil.pyPrint("  Rev - Computing bribe city costs for %s, %s   pop %d"%(pCity.getName(),pPlayer.getCivilizationDescription(0),pCity.getPopulation()))

	iBaseCost = 0
	if( iTurn < 10 ) :
		iBaseCost = 0
	else :
		iAvgEcon = (pPlayer.getEconomyHistory(iTurn-4) + pPlayer.getEconomyHistory(iTurn-3) + pPlayer.getEconomyHistory(iTurn-2) + pPlayer.getEconomyHistory(iTurn-1))/4.0
		iAvgEcon = max([iAvgEcon,0])

		iBaseCost = pow(iAvgEcon,0.65) + iGold/20 + 10
		if( LOG_DEBUG and not bSilent ) : CvUtil.pyPrint("  Rev - Avg Econ : %d, cur gold : %d, iBaseCost : %d = %d + %d + 10"%(iAvgEcon, iGold, iBaseCost,pow(iAvgEcon,0.65),iGold/20))

	iRevIdx = pCity.getRevolutionIndex()
	localRevIdx = pCity.getLocalRevIndex()

	iRevCost = (iRevIdx + 20*min([localRevIdx,20]) - 0.35*600)/(9 + 2*gc.getNumEraInfos() - 2*iEra)

	if( LOG_DEBUG and not bSilent ) : CvUtil.pyPrint("  Rev - Rev Cost: %d from index %d, %d local"%(iRevCost,iRevIdx,localRevIdx))

	iModifier = 1.0
	lastBribeTurn = RevData.getCityVal( pCity, 'BribeTurn' )
	if( not lastBribeTurn == None ) :
		iModifier += 10/(iTurn - lastBribeTurn + 1.0)
	if( pCity.getPopulation() < 7 ) :
		iModifier -= 1/(2.0 + pCity.getPopulation())
	if( not pPlayer.isHuman() ) :
		iModifier = (2*iModifier)/3.0

	iExtra = 0
	if( pCity.getNumRevolts(pCity.getOwner()) > 1 ) :
		iExtra = 10 + iEra

	iRand = 7*game.getGameTurn() + pCity.getID()

	iMed = iModifier*(iBaseCost + iRevCost + iExtra)
	iSmall = (2*iMed)/3 + iRand%10
	iLarge = (5*iMed)/3 + iRand%(1+int(iMed/14))
	iMed += iRand%15

	iSmall = int(max([iSmall,21]))
	iMed   = int(max([iMed,  40]))
	iLarge = int(max([iLarge,78]))

	if( LOG_DEBUG and not bSilent ) : CvUtil.pyPrint("  Rev - Bribe costs: small %d, med %d, large %d"%(iSmall,iMed,iLarge))

	RevData.setCityVal( pCity, 'TurnBribeCosts', [game.getGameTurn(), [iSmall,iMed,iLarge]] )

	return [iSmall, iMed, iLarge]
コード例 #7
0
def bribeCity( pCity, bribeSize ) :

	iRevIdx = pCity.getRevolutionIndex()
	localRevIdx = pCity.getLocalRevIndex()

	if( bribeSize == 'Small' ) :
		# Small reduction in rev index, mostly just for buyoffturns
		newRevIdx = int( 0.9*iRevIdx - 10 )
		newRevIdx = max([newRevIdx,0])
		pCity.setRevolutionIndex( newRevIdx )
		pCity.changeRevolutionCounter( 5 )
		RevData.setCityVal( pCity, 'BribeTurn', game.getGameTurn() )
		RevData.setCityVal( pCity, 'TurnBribeCosts', None )
	elif( bribeSize == 'Med' ) :
		# Med reduction in rev index
		newRevIdx = int( 0.8*iRevIdx - 25 )
		newRevIdx = max([newRevIdx,0])
		pCity.setRevolutionIndex( newRevIdx )
		pCity.changeRevolutionCounter( 7 )
		RevData.setCityVal( pCity, 'BribeTurn', game.getGameTurn() )
		RevData.setCityVal( pCity, 'TurnBribeCosts', None )
	elif( bribeSize == 'Large' ) :
		# Large reduction in rev index, longer time till next revolt too
		newRevIdx = int( 0.7*iRevIdx - 50 )
		newRevIdx = max([newRevIdx,0])
		pCity.setRevolutionIndex( newRevIdx )
		pCity.changeRevolutionCounter( 10 )
		RevData.setCityVal( pCity, 'BribeTurn', game.getGameTurn() )
		RevData.setCityVal( pCity, 'TurnBribeCosts', None )
	else :
		print 'Error!  Unrecognized bribeSize string %s'%(bribeSize)