//	--------------------------------------------------------------------------------
/// Gameplay informing us when a Camp has either been created or spawned a Unit so we can reseed the spawn counter
void CvBarbarians::DoCityActivationNotice(CvPlot* pPlot)
{
	if (!pPlot)
		return;

	CvGame& kGame = GC.getGame();
	// Default to between 8 and 12 turns per spawn
	//bumped a bit - too many barbs gets annoying.

#if defined(MOD_CORE_REDUCE_RANDOMNESS)
	bool isMP = kGame.isReallyNetworkMultiPlayer();
	int iRand = kGame.getSmallFakeRandNum(10, *pPlot);
	int iAddVal = isMP ? 5 : iRand;
	int iNumTurnsToSpawn = 7 + iAddVal;
#else
	int iNumTurnsToSpawn = 15 + kGame.getJonRandNum(5, "Barb Spawn Rand call");
#endif

	if (GC.getGame().isOption(GAMEOPTION_CHILL_BARBARIANS))
	{
		iNumTurnsToSpawn *= 3;
		iNumTurnsToSpawn /= 2;
	}

	// Raging
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
		iNumTurnsToSpawn /= 2;

#if defined(MOD_BUGFIX_BARB_CAMP_SPAWNING)
	if (m_aiPlotBarbCityNumUnitsSpawned == NULL) {
		// Probably means we are being called as CvWorldBuilderMapLoaded is adding camps, MapInit() will follow soon and set everything up correctly
		return;
	}
#endif
		
	// Num Units Spawned
	int iNumUnitsSpawned = m_aiPlotBarbCityNumUnitsSpawned[pPlot->GetPlotIndex()];

	// Reduce turns between spawn if we've pumped out more guys (meaning we're further into the game)
	iNumTurnsToSpawn -= min(3, iNumUnitsSpawned);	// -1 turns if we've spawned one Unit, -3 turns if we've spawned three

	// Increment # of barbs spawned from this camp
	m_aiPlotBarbCityNumUnitsSpawned[pPlot->GetPlotIndex()]++;	// This starts at -1 so when a camp is first created it will bump up to 0, which is correct

	// Difficulty level can add time between spawns (e.g. Settler is +8 turns)
	CvHandicapInfo* pHandicapInfo = GC.getHandicapInfo(kGame.getHandicapType());
	if (pHandicapInfo)
		iNumTurnsToSpawn += pHandicapInfo->getBarbSpawnMod();

	// Game Speed can increase or decrease amount of time between spawns (ranges from 67 on Quick to 400 on Marathon)
	CvGameSpeedInfo* pGameSpeedInfo = GC.getGameSpeedInfo(kGame.getGameSpeedType());
	if (pGameSpeedInfo)
	{
		iNumTurnsToSpawn *= pGameSpeedInfo->getBarbPercent();
		iNumTurnsToSpawn /= 100;
	}

	m_aiPlotBarbCitySpawnCounter[pPlot->GetPlotIndex()] = iNumTurnsToSpawn;
}
//	--------------------------------------------------------------------------------
/// Gameplay informing us when a Camp has either been created or spawned a Unit so we can reseed the spawn counter
void CvBarbarians::DoCampActivationNotice(CvPlot* pPlot)
{
	if (!pPlot)
		return;

	CvGame& kGame = GC.getGame();
	// Default to between 8 and 12 turns per spawn
#if defined(MOD_CORE_REDUCE_RANDOMNESS)
	int iNumTurnsToSpawn = 12 + kGame.getSmallFakeRandNum(10,*pPlot);
#else
	int iNumTurnsToSpawn = 8 + kGame.getJonRandNum(5, "Barb Spawn Rand call");
#endif

	// Raging
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
		iNumTurnsToSpawn /= 2;

#if defined(MOD_BUGFIX_BARB_CAMP_SPAWNING)
	if (m_aiPlotBarbCampNumUnitsSpawned == NULL) {
		// Probably means we are being called as CvWorldBuilderMapLoaded is adding camps, MapInit() will follow soon and set everything up correctly
		return;
	}
#endif
		
	// Num Units Spawned
	int iNumUnitsSpawned = m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()];

	// Reduce turns between spawn if we've pumped out more guys (meaning we're further into the game)
	iNumTurnsToSpawn -= min(3, iNumUnitsSpawned);	// -1 turns if we've spawned one Unit, -3 turns if we've spawned three

	// Increment # of barbs spawned from this camp
	m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()]++;	// This starts at -1 so when a camp is first created it will bump up to 0, which is correct

	//// If it's too early to spawn then add in a small amount to delay things a bit - between 3 and 6 extra turns
	//if (CanBarbariansSpawn())
	//{
	//	iNumTurnsToSpawn += 3;
	//	iNumTurnsToSpawn += auto_ptr<ICvGame1> pGame = GameCore::GetGame();\n.getJonRandNum(4, "Early game Barb Spawn Rand call");
	//}

	// Difficulty level can add time between spawns (e.g. Settler is +8 turns)
	CvHandicapInfo* pHandicapInfo = GC.getHandicapInfo(kGame.getHandicapType());
	if (pHandicapInfo)
		iNumTurnsToSpawn += pHandicapInfo->getBarbSpawnMod();

	// Game Speed can increase or decrease amount of time between spawns (ranges from 67 on Quick to 400 on Marathon)
	CvGameSpeedInfo* pGameSpeedInfo = GC.getGameSpeedInfo(kGame.getGameSpeedType());
	if (pGameSpeedInfo)
	{
		iNumTurnsToSpawn *= pGameSpeedInfo->getBarbPercent();
		iNumTurnsToSpawn /= 100;
	}

	m_aiPlotBarbCampSpawnCounter[pPlot->GetPlotIndex()] = iNumTurnsToSpawn;
}
Esempio n. 3
0
//	--------------------------------------------------------------------------------
/// Gameplay informing us when a Camp has either been created or spawned a Unit so we can reseed the spawn counter
void CvBarbarians::DoCampActivationNotice(CvPlot* pPlot)
{
	CvGame& kGame = GC.getGame();
	// Default to between 8 and 12 turns per spawn
	int iNumTurnsToSpawn = 8 + kGame.getJonRandNum(5, "Barb Spawn Rand call");

	// Raging
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
		iNumTurnsToSpawn /= 2;

	// Num Units Spawned
	int iNumUnitsSpawned = m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()];

	// Reduce turns between spawn if we've pumped out more guys (meaning we're further into the game)
	iNumTurnsToSpawn -= min(3, iNumUnitsSpawned);	// -1 turns if we've spawned one Unit, -3 turns if we've spawned three

	// Increment # of barbs spawned from this camp
	m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()]++;	// This starts at -1 so when a camp is first created it will bump up to 0, which is correct

	//// If it's too early to spawn then add in a small amount to delay things a bit - between 3 and 6 extra turns
	//if (CanBarbariansSpawn())
	//{
	//	iNumTurnsToSpawn += 3;
	//	iNumTurnsToSpawn += auto_ptr<ICvGame1> pGame = GameCore::GetGame();\n.getJonRandNum(4, "Early game Barb Spawn Rand call");
	//}

	// Difficulty level can add time between spawns (e.g. Settler is +8 turns)
	CvHandicapInfo* pHandicapInfo = GC.getHandicapInfo(kGame.getHandicapType());
	if (pHandicapInfo)
		iNumTurnsToSpawn += pHandicapInfo->getBarbSpawnMod();

	// Game Speed can increase or decrease amount of time between spawns (ranges from 67 on Quick to 400 on Marathon)
	CvGameSpeedInfo* pGameSpeedInfo = GC.getGameSpeedInfo(kGame.getGameSpeedType());
	if (pGameSpeedInfo)
	{
		iNumTurnsToSpawn *= pGameSpeedInfo->getBarbPercent();
		iNumTurnsToSpawn /= 100;
	}

	m_aiPlotBarbCampSpawnCounter[pPlot->GetPlotIndex()] = iNumTurnsToSpawn;
}
int getTurnMonthForGame(int iGameTurn, int iStartYear, CalendarTypes eCalendar, GameSpeedTypes eSpeed)
{
	int iTurnMonth;
	int iTurnCount;
	int iI;

	CvGameSpeedInfo* pkGameSpeedInfo = GC.getGameSpeedInfo(eSpeed);
	if(pkGameSpeedInfo == NULL)
	{
		//This function requires a valid game speed type!
		CvAssert(pkGameSpeedInfo);
		return 0;
	}

	const int iNumMonths = DB.Count("Months");

	iTurnMonth = iStartYear * iNumMonths;

	switch(eCalendar)
	{
	case CALENDAR_DEFAULT:
		{
			iTurnCount = 0;
			const int iGameSpeedNumTurnIncrements = pkGameSpeedInfo->getNumTurnIncrements();

			for(iI = 0; iI < iGameSpeedNumTurnIncrements; iI++)
			{
				const GameTurnInfo& gameTurnInfo = pkGameSpeedInfo->getGameTurnInfo(iI);

				if(iGameTurn > (iTurnCount + gameTurnInfo.iNumGameTurnsPerIncrement))
				{
					iTurnMonth += (gameTurnInfo.iMonthIncrement * gameTurnInfo.iNumGameTurnsPerIncrement);
					iTurnCount += gameTurnInfo.iNumGameTurnsPerIncrement;
				}
				else
				{
					iTurnMonth += (gameTurnInfo.iMonthIncrement * (iGameTurn - iTurnCount));
					iTurnCount += (iGameTurn - iTurnCount);
					break;
				}
			}

			if(iGameTurn > iTurnCount)
			{
				iTurnMonth += (pkGameSpeedInfo->getGameTurnInfo(iGameSpeedNumTurnIncrements - 1).iMonthIncrement * (iGameTurn - iTurnCount));
			}
		}
		break;

	case CALENDAR_BI_YEARLY:
		iTurnMonth += (2 * iGameTurn * iNumMonths);
		break;

	case CALENDAR_YEARS:
	case CALENDAR_TURNS:
		iTurnMonth += iGameTurn * iNumMonths;
		break;

	case CALENDAR_SEASONS:
		iTurnMonth += (iGameTurn * iNumMonths) / DB.Count("Seasons");
		break;

	case CALENDAR_MONTHS:
		iTurnMonth += iGameTurn;
		break;

	case CALENDAR_WEEKS:
		iTurnMonth += iGameTurn / GC.getWEEKS_PER_MONTHS();
		break;

	default:
		CvAssert(false);
	}

	return iTurnMonth;
}
Esempio n. 5
0
//	--------------------------------------------------------------------------------
/// Gameplay informing us when a Camp has either been created or spawned a Unit so we can reseed the spawn counter
void CvBarbarians::DoCampActivationNotice(CvPlot* pPlot)
{
	CvGame& kGame = GC.getGame();
	// Default to 6 turns (also changed to double to accomodate decimals.
#ifdef Imperial_Barbarian_Algorithm
	double iNumTurnsToSpawn = 7 + kGame.getJonRandNum(2, "Barb Spawn Rand call");
	// Raging barbs; reduced to 4 turns.
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
	{
		iNumTurnsToSpawn -= 3 + kGame.getJonRandNum(1, "Barb Spawn Rand call");
	}
#else
	int iNumTurnsToSpawn = 6 + kGame.getJonRandNum(5, "Barb Spawn Rand call");

	// Raging
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
		iNumTurnsToSpawn /= 2;
#endif
	

	// Reduce turns between spawn if we've pumped out more guys (meaning we're further into the game)
#ifdef Imperial_Barbarian_Algorithm
	// Number of units this camp has already spawned
	double dNumUnitsSpawned = m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()];

	/* For every unit this camp has spawned (through official channels, does not include spawns handled by other AI classes)
	 reduce the counter by 0.3 turns, up to a maximum reduction of 2 turns (@ 7 units spawned in). */
	dNumUnitsSpawned = min((dNumUnitsSpawned * 0.3), (double)2);

	iNumTurnsToSpawn -= dNumUnitsSpawned; 
#else
	// Num Units Spawned
	int iNumUnitsSpawned = m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()];
	iNumTurnsToSpawn -= min(3, iNumUnitsSpawned);	// -1 turns if we've spawned one Unit, -3 turns if we've spawned three
#endif
	// Increment # of barbs spawned from this camp
	m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()]++;	// This starts at -1 so when a camp is first created it will bump up to 0, which is correct

	// Difficulty level can add time between spawns (e.g. Settler is +8 turns)
	CvHandicapInfo* pHandicapInfo = GC.getHandicapInfo(kGame.getHandicapType());
	if (pHandicapInfo)
	{
		iNumTurnsToSpawn += pHandicapInfo->getBarbSpawnMod();
	}

	// Game Speed can increase or decrease amount of time between spawns (ranges from 67 on Quick to 400 on Marathon)
	CvGameSpeedInfo* pGameSpeedInfo = GC.getGameSpeedInfo(kGame.getGameSpeedType());
	if (pGameSpeedInfo)
	{
		iNumTurnsToSpawn *= pGameSpeedInfo->getBarbPercent();
		iNumTurnsToSpawn /= 100;
	}

#ifdef Imperial_Barbarian_Algorithm
	iNumTurnsToSpawn = max((double)0, iNumTurnsToSpawn); // never below zero! zero = spawn a barb every turn!
	// Round up if above 0.4, round down otherwise.
	if (fmod(iNumTurnsToSpawn, 1) > 0.4)
	{
		iNumTurnsToSpawn = ceil(iNumTurnsToSpawn);
	}
	else
	{
		iNumTurnsToSpawn = floor(iNumTurnsToSpawn);		
	}
#ifdef Imperial_Barbarians_Logging_
	CvString sCount;
	sCount.Format("Barbarian spawned C!, Number of turns until next spawn:, %d", (int)iNumTurnsToSpawn);
	kGame.ImperialGameLogging(sCount, BARBARIAN_PLAYER);
#endif
#endif

	m_aiPlotBarbCampSpawnCounter[pPlot->GetPlotIndex()] = iNumTurnsToSpawn;
}