Bazaar developer reference

CvUnit::CanDistanceGift(PlayerTypes) const

Defined in
CvUnit.cpp, line 4204
Class
CvUnit
Hook name
CivHooks::CvUnit_CanDistanceGift
Lua events
GameEvents.PlayerCanGiftUnit

Hooks

static bool BeforeCvUnit_CanDistanceGift(const CvUnit* self, PlayerTypes eToPlayer, bool& result);static void AfterCvUnit_CanDistanceGift(const CvUnit* self, PlayerTypes eToPlayer, bool& result);static bool ReplaceCvUnit_CanDistanceGift(bool (*original)(const CvUnit*, PlayerTypes), const CvUnit* self, PlayerTypes eToPlayer);CivRegisterBefore<CivHooks::CvUnit_CanDistanceGift>(host, &BeforeCvUnit_CanDistanceGift);CivRegisterAfter<CivHooks::CvUnit_CanDistanceGift>(host, &AfterCvUnit_CanDistanceGift);CivRegisterReplace<CivHooks::CvUnit_CanDistanceGift>(host, &ReplaceCvUnit_CanDistanceGift);

Code

4203// Long-distance gift to a city state4204bool CvUnit::CanDistanceGift(PlayerTypes eToPlayer) const4205{4206	VALIDATE_OBJECT42074208	if (eToPlayer == NO_PLAYER)4209		return false;42104211	// Minors4212	if(GET_PLAYER(eToPlayer).isMinorCiv())4213	{4214		// No settlers4215		if(isFound() || IsFoundAbroad())4216			return false;42174218		// No scouts4219		UnitClassTypes eScoutClass = (UnitClassTypes) GC.getInfoTypeForString("UNITCLASS_SCOUT", true);4220		if (eScoutClass != NO_UNITCLASS && eScoutClass == getUnitClassType())4221			return false;42224223		// No non-combat units4224		if(!IsCombatUnit() && !canAirAttack())4225		{4226#if defined(MOD_BUGFIX_USE_GETTERS)4227			CvPlayer& kPlayer = GET_MY_PLAYER();4228#else4229			CvPlayer& kPlayer = GET_PLAYER(m_eOwner);4230#endif42314232			// Unless okay by trait4233			if(kPlayer.GetPlayerTraits()->GetGreatPersonGiftInfluence() == 0 || !IsGreatPerson())4234			{4235				return false;4236			}4237		}42384239		// Is there a distance gift from us waiting to be delivered?4240		if (GET_PLAYER(eToPlayer).GetIncomingUnitType(getOwner()) != NO_UNIT)4241		{4242			return false;4243		}4244	}42454246	// No Majors4247	else4248		return false;42494250	TeamTypes eToTeam = GET_PLAYER(eToPlayer).getTeam();42514252	// Maxed out unit class for team4253	if(GET_TEAM(eToTeam).isUnitClassMaxedOut(getUnitClassType(), GET_TEAM(eToTeam).getUnitClassMaking(getUnitClassType())))4254		return false;42554256	// Maxed out unit class for Player4257	if(GET_PLAYER(eToPlayer).isUnitClassMaxedOut(getUnitClassType(), GET_PLAYER(eToPlayer).getUnitClassMaking(getUnitClassType())))4258		return false;4259	4260#if defined(MOD_EVENTS_MINORS_INTERACTION)4261	if(atWar(eToTeam, getTeam()))4262		return false;4263	4264	if (MOD_EVENTS_MINORS_INTERACTION) {4265		if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_PlayerCanGiftUnit, getOwner(), eToPlayer, GetID()) == GAMEEVENTRETURN_FALSE) {4266			return false;4267		}4268	}4269	4270	return true;4271#else4272	return !atWar(eToTeam, getTeam());4273#endif				4274}

Calls

Called by