Bazaar developer reference

CvPlayer::DoUprising()

Defined in
CvPlayer.cpp, line 11650
Class
CvPlayer
Hook name
CivHooks::CvPlayer_DoUprising

Hooks

static bool BeforeCvPlayer_DoUprising(CvPlayer* self);static void AfterCvPlayer_DoUprising(CvPlayer* self);static void ReplaceCvPlayer_DoUprising(void (*original)(CvPlayer*), CvPlayer* self);CivRegisterBefore<CivHooks::CvPlayer_DoUprising>(host, &BeforeCvPlayer_DoUprising);CivRegisterAfter<CivHooks::CvPlayer_DoUprising>(host, &AfterCvPlayer_DoUprising);CivRegisterReplace<CivHooks::CvPlayer_DoUprising>(host, &ReplaceCvPlayer_DoUprising);

Code

11649// Fire off an uprising somewhere11650void CvPlayer::DoUprising()11651{11652	// In hundreds11653	int iNumRebels = /*100*/ GC.getUPRISING_NUM_BASE();11654	int iExtraRoll = (getNumCities() - 1) * /*20*/ GC.getUPRISING_NUM_CITY_COUNT();11655	iExtraRoll += 100;11656	iNumRebels += GC.getGame().getJonRandNum(iExtraRoll, "Rebel count rand roll");11657	iNumRebels /= 100;1165811659	// Find a random city to pop up a bad man11660	CvCity* pBestCity = NULL;11661	int iBestWeight = 0;1166211663	int iTempWeight;1166411665	CvCity* pLoopCity;11666	int iLoop;11667	CvGame& theGame = GC.getGame();11668	for(pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))11669	{11670		iTempWeight = pLoopCity->getPopulation();11671		iTempWeight += theGame.getJonRandNum(10, "Uprising rand weight.");1167211673		if(iTempWeight > iBestWeight)11674		{11675			iBestWeight = iTempWeight;11676			pBestCity = pLoopCity;11677		}11678	}1167911680	// Found a place to set up an uprising?11681	if(pBestCity != NULL)11682	{11683		int iBestPlot = -1;11684		int iBestPlotWeight = -1;11685		CvPlot* pPlot;1168611687		CvCityCitizens* pCitizens = pBestCity->GetCityCitizens();1168811689		// Start at 1, since ID 0 is the city plot itself11690#if defined(MOD_GLOBAL_CITY_WORKING)11691		for(int iPlotLoop = 1; iPlotLoop < pBestCity->GetNumWorkablePlots(); iPlotLoop++)11692#else11693		for(int iPlotLoop = 1; iPlotLoop < NUM_CITY_PLOTS; iPlotLoop++)11694#endif11695		{11696			pPlot = pCitizens->GetCityPlotFromIndex(iPlotLoop);1169711698			if(!pPlot)		// Should be valid, but make sure11699				continue;1170011701			// Can't be impassable11702			if(pPlot->isImpassable() || pPlot->isMountain())11703				continue;1170411705			// Can't be water11706			if(pPlot->isWater())11707				continue;1170811709			// Can't be ANOTHER city11710			if(pPlot->isCity())11711				continue;1171211713			// Don't place on a plot where a unit is already standing11714			if(pPlot->getNumUnits() > 0)11715				continue;1171611717			iTempWeight = theGame.getJonRandNum(10, "Uprising rand plot location.");1171811719			// Add weight if there's an improvement here!11720			if(pPlot->getImprovementType() != NO_IMPROVEMENT)11721			{11722				iTempWeight += 4;1172311724				// If also a a resource, even more weight!11725				if(pPlot->getResourceType(getTeam()) != NO_RESOURCE)11726					iTempWeight += 3;11727			}1172811729			// Add weight if there's a defensive bonus for this plot11730			if(pPlot->defenseModifier(BARBARIAN_TEAM, false, false))11731				iTempWeight += 4;1173211733			// Don't pick plots that aren't ours11734			if(pPlot->getOwner() != GetID())11735				iTempWeight = -1;1173611737			if(iTempWeight > iBestPlotWeight)11738			{11739				iBestPlotWeight = iTempWeight;11740				iBestPlot = iPlotLoop;11741			}11742		}1174311744		// Found valid plot11745		if(iBestPlot != -1)11746		{11747			// Make barbs able to enter ANYONE'S territory11748			theGame.SetBarbarianReleaseTurn(0);1174911750			pPlot = pCitizens->GetCityPlotFromIndex(iBestPlot);1175111752			// Pick a unit type11753			UnitTypes eUnit = theGame.GetRandomSpawnUnitType(GetID(), /*bIncludeUUs*/ false, /*bIncludeRanged*/ false);1175411755			CvNotifications* pNotifications = GetNotifications();11756			if(pNotifications)11757			{11758				Localization::String strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_REBELS");11759				Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_REBELS_SUMMARY");11760				pNotifications->Add(NOTIFICATION_REBELS, strMessage.toUTF8(), strSummary.toUTF8(), pPlot->getX(), pPlot->getY(), eUnit, BARBARIAN_PLAYER);11761			}1176211763			// Init unit11764			GET_PLAYER(BARBARIAN_PLAYER).initUnit(eUnit, pPlot->getX(), pPlot->getY());11765			iNumRebels--;	// Reduce the count since we just added the seed rebel1176611767			// Loop until all rebels are placed11768			do11769			{11770				iNumRebels--;1177111772				// Init unit11773				CvUnit* pUnit = GET_PLAYER(BARBARIAN_PLAYER).initUnit(eUnit, pPlot->getX(), pPlot->getY());11774				CvAssert(pUnit);11775				if (pUnit)11776				{11777					if (!pUnit->jumpToNearestValidPlotWithinRange(5))11778						pUnit->kill(false);		// Could not find a spot!11779				}11780			}11781			while(iNumRebels > 0);11782		}11783	}11784}

Calls

Called by