Bazaar developer reference

CvUnit::canPillage(const CvPlot *) const

Defined in
CvUnit.cpp, line 7681
Class
CvUnit
Hook name
CivHooks::CvUnit_canPillage
Lua events
GameEvents.UnitCanPillage

Hooks

static bool BeforeCvUnit_canPillage(const CvUnit* self, const CvPlot* pPlot, bool& result);static void AfterCvUnit_canPillage(const CvUnit* self, const CvPlot* pPlot, bool& result);static bool ReplaceCvUnit_canPillage(bool (*original)(const CvUnit*, const CvPlot*), const CvUnit* self, const CvPlot* pPlot);CivRegisterBefore<CivHooks::CvUnit_canPillage>(host, &BeforeCvUnit_canPillage);CivRegisterAfter<CivHooks::CvUnit_canPillage>(host, &AfterCvUnit_canPillage);CivRegisterReplace<CivHooks::CvUnit_canPillage>(host, &ReplaceCvUnit_canPillage);

Code

7681bool CvUnit::canPillage(const CvPlot* pPlot) const7682{7683	VALIDATE_OBJECT7684	if(isEmbarked())7685	{7686		return false;7687	}76887689#if defined(MOD_BUGFIX_MINOR)7690	// Bail early if the unit has no moves left7691	if (getMoves() <= 0)7692	{7693		return false;7694	}7695#endif76967697	if(!(getUnitInfo().IsPillage()))7698	{7699		return false;7700	}7701	else7702	{7703		TechTypes ePillagePrereq = (TechTypes) getUnitInfo().GetPrereqPillageTech();7704		if(ePillagePrereq != NO_TECH)7705		{7706			if(!GET_TEAM(GET_PLAYER(getOwner()).getTeam()).GetTeamTechs()->HasTech(ePillagePrereq))7707			{7708				return false;7709			}7710		}7711	}77127713	// Barbarian boats not allowed to pillage, as they're too annoying :)7714	if(isBarbarian() && getDomainType() == DOMAIN_SEA)7715	{7716		return false;7717	}77187719	if(pPlot->isCity())7720	{7721		return false;7722	}77237724	ImprovementTypes eImprovementType = pPlot->getImprovementType();7725	if(eImprovementType == NO_IMPROVEMENT)7726	{7727		if(!(pPlot->isRoute()))7728		{7729			return false;7730		}7731	}7732	else if(eImprovementType == (ImprovementTypes)GC.getRUINS_IMPROVEMENT())7733	{7734		return false;7735	}7736	else7737	{7738		CvImprovementEntry* pImprovementInfo = GC.getImprovementInfo(pPlot->getImprovementType());7739		if(pImprovementInfo->IsPermanent())7740		{7741			return false;7742		}7743		else if(pImprovementInfo->IsGoody())7744		{7745			return false;7746		}77477748		// Special case: Feitoria can be in a city-state's lands, don't allow pillaging unless at war with its owner7749		if(pImprovementInfo->GetLuxuryCopiesSiphonedFromMinor() > 0)7750		{7751			PlayerTypes eOwner = pPlot->getOwner();7752			PlayerTypes eSiphoner = pPlot->GetPlayerThatBuiltImprovement();7753			if (eOwner != NO_PLAYER && GET_PLAYER(eOwner).isMinorCiv())7754			{7755				if (eSiphoner != NO_PLAYER && GET_PLAYER(eSiphoner).isAlive())7756				{7757					if (!atWar(getTeam(), GET_PLAYER(eSiphoner).getTeam()))7758					{7759						return false;7760					}7761				}7762			}7763		}7764	}77657766	// Either nothing to pillage or everything is pillaged to its max7767	if((eImprovementType == NO_IMPROVEMENT || pPlot->IsImprovementPillaged()) &&7768	        (pPlot->getRouteType() == NO_ROUTE || pPlot->IsRoutePillaged() /* == GC.getPILLAGE_NUM_TURNS_DISABLED()*/))7769	{7770		return false;7771	}77727773	if(pPlot->isOwned())7774	{7775		if(!potentialWarAction(pPlot))7776		{7777			if((eImprovementType == NO_IMPROVEMENT && !pPlot->isRoute()) || (pPlot->getOwner() != getOwner()))7778			{7779				return false;7780			}7781		}7782	}77837784	// can no longer pillage our tiles7785	if(pPlot->getOwner() == getOwner())7786	{7787		return false;7788	}77897790	if(!(pPlot->isValidDomainForAction(*this)))7791	{7792		return false;7793	}7794	7795#if defined(MOD_EVENTS_UNIT_ACTIONS)7796	if (MOD_EVENTS_UNIT_ACTIONS) {7797		if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_UnitCanPillage, getOwner(), GetID(), eImprovementType, pPlot->getRouteType()) == GAMEEVENTRETURN_FALSE) {7798			return false;7799		}7800	}7801#endif78027803	return true;7804}

Calls

Called by