Bazaar developer reference

CvUnit::setXY(int, int, bool, bool, bool, bool, bool)

Defined in
CvUnit.cpp, line 15547
Class
CvUnit
Hook name
CivHooks::CvUnit_setXY
Changed in
0.5.0
Lua events
GameEvents.UnitCaptured, GameEvents.CanDisplaceCivilian, GameEvents.UnitSetXY

Hand-placed hooks inside

A replacement for this function that does not call original stops these hooks from running.

Hooks

static bool BeforeCvUnit_setXY(CvUnit* self, int iX, int iY, bool bGroup, bool bUpdate, bool bShow, bool bCheckPlotVisible, bool bNoMove);static void AfterCvUnit_setXY(CvUnit* self, int iX, int iY, bool bGroup, bool bUpdate, bool bShow, bool bCheckPlotVisible, bool bNoMove);static void ReplaceCvUnit_setXY(void (*original)(CvUnit*, int, int, bool, bool, bool, bool, bool), CvUnit* self, int iX, int iY, bool bGroup, bool bUpdate, bool bShow, bool bCheckPlotVisible, bool bNoMove);CivRegisterBefore<CivHooks::CvUnit_setXY>(host, &BeforeCvUnit_setXY);CivRegisterAfter<CivHooks::CvUnit_setXY>(host, &AfterCvUnit_setXY);CivRegisterReplace<CivHooks::CvUnit_setXY>(host, &ReplaceCvUnit_setXY);

Code

15547void CvUnit::setXY(int iX, int iY, bool bGroup, bool bUpdate, bool bShow, bool bCheckPlotVisible, bool bNoMove)15548{15549	VALIDATE_OBJECT15550	IDInfo* pUnitNode = 0;15551	CvCity* pOldCity = 0;15552	CvCity* pNewCity = 0;15553	CvUnit* pTransportUnit = 0;15554	CvUnit* pLoopUnit = 0;15555	CvPlot* pOldPlot = 0;15556	CvPlot* pNewPlot = 0;15557	FStaticVector<IDInfo, 10, true, c_eCiv5GameplayDLL, 0> oldUnitList;15558	FStaticVector<CvUnitCaptureDefinition, 8, true, c_eCiv5GameplayDLL, 0> kCaptureUnitList;15559#if defined(CIV_HOST_API)15560	std::vector<IDInfo> kCivHostCapturedFrom;15561#endif15562	ActivityTypes eOldActivityType = NO_ACTIVITY;15563	int iI;15564	TeamTypes activeTeam = GC.getGame().getActiveTeam();15565	TeamTypes eOurTeam = getTeam();1556615567	CvPlayerAI& kPlayer = GET_PLAYER(getOwner());1556815569	bool bOwnerIsActivePlayer = GC.getGame().getActivePlayer() == getOwner();15570	// Delay any popups that might be caused by our movement (goody huts, natural wonders, etc.) so the unit movement event gets sent before the popup event.15571	if (bOwnerIsActivePlayer)15572		DLLUI->SetDontShowPopups(true);1557315574	CvAssert(!at(iX, iY));15575	CvAssert(!isFighting());15576	CvAssert((iX == INVALID_PLOT_COORD) || (GC.getMap().plot(iX, iY)->getX() == iX));15577	CvAssert((iY == INVALID_PLOT_COORD) || (GC.getMap().plot(iX, iY)->getY() == iY));1557815579	eOldActivityType = GetActivityType();1558015581	CvCity *pkPrevGarrisonedCity = GetGarrisonedCity();1558215583	if(isSetUpForRangedAttack())15584	{15585		setSetUpForRangedAttack(false);15586	}1558715588	if(!bGroup || isCargo())15589	{15590		bShow = false;15591	}1559215593	int iMapLayer = m_iMapLayer;1559415595	pNewPlot = GC.getMap().plot(iX, iY);1559615597	if(pNewPlot != NULL && !bNoMove)15598	{15599		pTransportUnit = getTransportUnit();1560015601		if(pTransportUnit != NULL)15602		{15603			if(!(pTransportUnit->atPlot(*pNewPlot)))15604			{15605				setTransportUnit(NULL);15606			}15607		}1560815609		if(IsCombatUnit())15610		{15611			oldUnitList.clear();1561215613			pUnitNode = pNewPlot->headUnitNode();1561415615			while(pUnitNode != NULL)15616			{15617				oldUnitList.push_back(*pUnitNode);15618				pUnitNode = pNewPlot->nextUnitNode(pUnitNode);15619			}1562015621			int iUnitListSize = (int) oldUnitList.size();15622			for(int iVectorLoop = 0; iVectorLoop < (int) iUnitListSize; ++iVectorLoop)15623			{15624				pLoopUnit = ::getUnit(oldUnitList[iVectorLoop]);15625				{15626					if(pLoopUnit && !pLoopUnit->isDelayedDeath())15627					{15628						if(isEnemy(pLoopUnit->getTeam(), pNewPlot) || pLoopUnit->isEnemy(eOurTeam))15629						{15630							if(!pLoopUnit->canCoexistWithEnemyUnit(eOurTeam))15631							{15632								// Unit somehow ended up on top of an enemy combat unit15633								if(NO_UNITCLASS == pLoopUnit->getUnitInfo().GetUnitCaptureClassType() && pLoopUnit->IsCanDefend(pNewPlot))15634								{15635									if(!pNewPlot->isCity())15636									{15637										if (!pLoopUnit->jumpToNearestValidPlot())15638											pLoopUnit->kill(false, getOwner());15639									}15640									else15641									{15642#if defined(MOD_API_UNIFIED_YIELDS)15643										kPlayer.DoYieldsFromKill(this, pLoopUnit, iX, iY, 0);15644#else15645										kPlayer.DoYieldsFromKill(getUnitType(), pLoopUnit->getUnitType(), iX, iY, pLoopUnit->isBarbarian(), 0);15646#endif15647										pLoopUnit->kill(false, getOwner());15648									}15649								}15650								// Ran into a noncombat unit15651								else15652								{15653									bool bDisplaced = false;15654									ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();15655									if(pkScriptSystem)15656									{15657										CvLuaArgsHandle args;15658										args->Push(pLoopUnit->getOwner());15659										args->Push(pLoopUnit->GetID());  // captured unit1566015661										bool bResult = false;15662#if defined(MOD_BUGFIX_MINOR)15663										if (LuaSupport::CallTestAny(pkScriptSystem, "CanDisplaceCivilian", args.get(), bResult))15664#else15665										if (LuaSupport::CallTestAll(pkScriptSystem, "CanDisplaceCivilian", args.get(), bResult))15666#endif15667										{15668											// Check the result.15669											if(bResult)15670											{15671												bDisplaced = true;15672											}15673										}15674									}1567515676									if (!bDisplaced)15677									{15678										Localization::String strMessage;15679										Localization::String strSummary;1568015681										bool bDoCapture = false;15682										// Some units can't capture civilians. Embarked units are also not captured, they're simply killed. And some aren't a type that gets captured.15683										// slewis - removed the capture clause so that helicopter gunships could capture workers. The promotion says that No Capture only effects cities.15684										//if(!isNoCapture() && (!pLoopUnit->isEmbarked() || pLoopUnit->getUnitInfo().IsCaptureWhileEmbarked()) && pLoopUnit->getCaptureUnitType(GET_PLAYER(pLoopUnit->getOwner()).getCivilizationType()) != NO_UNIT)15685										if((!pLoopUnit->isEmbarked() || pLoopUnit->getUnitInfo().IsCaptureWhileEmbarked()) && pLoopUnit->getCaptureUnitType(GET_PLAYER(pLoopUnit->getOwner()).getCivilizationType()) != NO_UNIT)15686										{15687											bDoCapture = true;1568815689											if(isBarbarian())15690											{15691												strMessage = Localization::Lookup("TXT_KEY_UNIT_CAPTURED_BARBS_DETAILED");15692												strMessage << pLoopUnit->getUnitInfo().GetTextKey();15693												strSummary = Localization::Lookup("TXT_KEY_UNIT_CAPTURED_BARBS");15694											}15695											else15696											{15697												strMessage = Localization::Lookup("TXT_KEY_UNIT_CAPTURED_DETAILED");15698												strMessage << pLoopUnit->getUnitInfo().GetTextKey() << GET_PLAYER(getOwner()).getNameKey();15699												strSummary = Localization::Lookup("TXT_KEY_UNIT_CAPTURED");15700											}15701										}15702#if defined(MOD_EVENTS_UNIT_CAPTURE)1570315704										if (MOD_EVENTS_UNIT_CAPTURE) {15705											GAMEEVENTINVOKE_HOOK(GAMEEVENT_UnitCaptured, getOwner(), GetID(), pLoopUnit->getOwner(), pLoopUnit->GetID(), !bDoCapture, 0);15706										}1570715708										if (!bDoCapture)15709#else15710										else15711#endif15712										// Unit was killed instead15713										{15714											if(pLoopUnit->isEmbarked())15715#if defined(MOD_UNITS_XP_TIMES_100)15716												changeExperienceTimes100(1 * 100);15717#else15718												changeExperience(1);15719#endif1572015721											CvString strBuffer = GetLocalizedText("TXT_KEY_MISC_YOU_UNIT_DESTROYED_ENEMY", getNameKey(), 0, pLoopUnit->getNameKey());15722											DLLUI->AddUnitMessage(0, GetIDInfo(), getOwner(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer/*, GC.getEraInfo(GC.getGame().getCurrentEra())->getAudioUnitVictoryScript(), MESSAGE_TYPE_INFO, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pkTargetPlot->getX(), pkTargetPlot->getY()*/);15723											MILITARYLOG(getOwner(), strBuffer.c_str(), plot(), pLoopUnit->getOwner());1572415725											strMessage = Localization::Lookup("TXT_KEY_UNIT_LOST");15726											strSummary = strMessage;1572715728#if defined(MOD_API_UNIFIED_YIELDS)15729											kPlayer.DoYieldsFromKill(this, pLoopUnit, iX, iY, 0);15730#else15731											kPlayer.DoYieldsFromKill(getUnitType(), pLoopUnit->getUnitType(), iX, iY, pLoopUnit->isBarbarian(), 0);15732#endif15733#if defined(MOD_API_EXTENSIONS)15734											kPlayer.DoUnitKilledCombat(this, pLoopUnit->getOwner(), pLoopUnit->getUnitType());15735#else15736											kPlayer.DoUnitKilledCombat(pLoopUnit->getOwner(), pLoopUnit->getUnitType());15737#endif15738										}1573915740										CvNotifications* pNotification = GET_PLAYER(pLoopUnit->getOwner()).GetNotifications();15741										if(pNotification)15742											pNotification->Add(NOTIFICATION_UNIT_DIED, strMessage.toUTF8(), strSummary.toUTF8(), pLoopUnit->getX(), pLoopUnit->getY(), (int) pLoopUnit->getUnitType(), pLoopUnit->getOwner());1574315744										if(pLoopUnit->isEmbarked())15745											setMadeAttack(true);1574615747										// If we're capturing the unit, we want to delay the capture, else as the unit is converted to our side, it will be the first unit on our15748										// side in the plot and can end up taking over a city, rather than the advancing unit15749										CvUnitCaptureDefinition kCaptureDef;15750										if(bDoCapture)15751										{15752											if(pLoopUnit->getCaptureDefinition(&kCaptureDef, getOwner()))15753											{15754												kCaptureUnitList.push_back(kCaptureDef);15755#if defined(CIV_HOST_API)15756												kCivHostCapturedFrom.push_back(pLoopUnit->GetIDInfo());15757#endif15758											}15759											pLoopUnit->setCapturingPlayer(NO_PLAYER);	// Make absolutely sure this is not valid so the kill does not do the capture.15760										}1576115762										pLoopUnit->kill(false, getOwner());15763									}15764								}15765							}15766						}15767					}15768				}15769			}15770		}15771	}1577215773	pOldPlot = plot();1577415775	if(pOldPlot != NULL)15776	{15777		pOldPlot->removeUnit(this, bUpdate);1577815779		if (iMapLayer == DEFAULT_UNIT_MAP_LAYER)15780		{15781			// if leaving a city, reveal the unit15782			if(pOldPlot->getPlotCity())15783			{15784				// if pNewPlot is a valid pointer, we are leaving the city and need to visible15785				// if pNewPlot is NULL than we are "dead" (e.g. a settler) and need to blend out15786				auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(this));15787				gDLL->GameplayUnitVisibility(pDllUnit.get(), pNewPlot != NULL && !this->isInvisible(activeTeam, false));1578815789				if (GetBaseCombatStrength(true/*bIgnoreEmbarked*/) > 0 && getDomainType() == DOMAIN_LAND)15790				{15791					pOldPlot->getPlotCity()->ChangeJONSCulturePerTurnFromPolicies(-(GET_PLAYER(getOwner()).GetPlayerPolicies()->GetNumericModifier(POLICYMOD_CULTURE_FROM_GARRISON)));15792				}15793			}1579415795			if (canChangeVisibility())15796#if defined(MOD_API_EXTENSIONS)15797				pOldPlot->changeAdjacentSight(eOurTeam, visibilityRange(), false, getSeeInvisibleType(), getFacingDirection(true), this);15798#else15799				pOldPlot->changeAdjacentSight(eOurTeam, visibilityRange(), false, getSeeInvisibleType(), getFacingDirection(true));15800#endif1580115802			pOldPlot->area()->changeUnitsPerPlayer(getOwner(), -1);1580315804			setLastMoveTurn(GC.getGame().getTurnSlice());1580515806			pOldCity = pOldPlot->getPlotCity();15807		}15808	}1580915810	if(pNewPlot != NULL)15811	{15812		m_iX = pNewPlot->getX();15813		m_iY = pNewPlot->getY();15814	}15815	else15816	{15817		m_iX = INVALID_PLOT_COORD;15818		m_iY = INVALID_PLOT_COORD;15819	}1582015821	CvAssertMsg(plot() == pNewPlot, "plot is expected to equal pNewPlot");1582215823	if(pNewPlot != NULL)15824	{15825		//update facing direction15826		if(pOldPlot != NULL)15827		{15828#if defined(MOD_API_UNIT_STATS)15829			changeStatsTravelled(plotDistance(pOldPlot->getX(), pOldPlot->getY(), pNewPlot->getX(), pNewPlot->getY()));15830#endif15831			DirectionTypes newDirection = directionXY(pOldPlot, pNewPlot);15832			if(newDirection != NO_DIRECTION)15833				m_eFacingDirection = newDirection;15834		}1583515836		//update cargo mission animations15837		if(isCargo())15838		{15839			if(eOldActivityType != ACTIVITY_MISSION)15840			{15841				SetActivityType(eOldActivityType);15842			}15843		}1584415845		// if entering a city, hide the unit15846		if(pNewPlot->getPlotCity() && iMapLayer == DEFAULT_UNIT_MAP_LAYER)15847		{15848			auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(this));15849			gDLL->GameplayUnitVisibility(pDllUnit.get(), false /*bVisible*/);15850			15851			if (GetBaseCombatStrength(true/*bIgnoreEmbarked*/) > 0 && getDomainType() == DOMAIN_LAND)15852			{15853				pNewPlot->getPlotCity()->ChangeJONSCulturePerTurnFromPolicies((GET_PLAYER(getOwner()).GetPlayerPolicies()->GetNumericModifier(POLICYMOD_CULTURE_FROM_GARRISON)));15854			}15855		}1585615857		setFortifyTurns(0);1585815859		if (iMapLayer == DEFAULT_UNIT_MAP_LAYER)15860		{15861			if (canChangeVisibility())15862#if defined(MOD_API_EXTENSIONS)15863				pNewPlot->changeAdjacentSight(eOurTeam, visibilityRange(), true, getSeeInvisibleType(), getFacingDirection(true), this); // needs to be here so that the square is considered visible when we move into it...15864#else15865				pNewPlot->changeAdjacentSight(eOurTeam, visibilityRange(), true, getSeeInvisibleType(), getFacingDirection(true)); // needs to be here so that the square is considered visible when we move into it...15866#endif1586715868			pNewPlot->addUnit(this, bUpdate);1586915870			pNewPlot->area()->changeUnitsPerPlayer(getOwner(), 1);15871			pNewCity = pNewPlot->getPlotCity();15872		}15873		else15874		{15875			GC.getMap().plotManager().AddUnit(GetIDInfo(), iX, iY, iMapLayer);15876		}1587715878		// Moving into a City (friend or foe)15879		if(pNewCity != NULL)15880		{15881			pNewCity->updateStrengthValue();1588215883			if(isEnemy(pNewCity->getTeam()) && !canCoexistWithEnemyUnit(pNewCity->getTeam()))15884			{15885				PlayerTypes eNewOwner = GET_PLAYER(getOwner()).pickConqueredCityOwner(*pNewCity);1588615887				if(NO_PLAYER != eNewOwner)15888				{15889					15890#if !defined(NO_ACHIEVEMENTS)15891					//Test for City Achievements here since we need to know about the capturing unit.15892					if(getOwner() == GC.getGame().getActivePlayer())15893					{15894						//Expansion 1 - Capture the city that built Petra using a Landship15895						if(strcmp(getUnitInfo().GetType(), "UNIT_WWI_TANK") == 0)15896						{15897							const int numBuildings = GC.getNumBuildingInfos();15898							for(int i = 0; i < numBuildings; ++i)15899							{15900								const BuildingTypes eBuilding = static_cast<BuildingTypes>(i);15901								const CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);1590215903								if(pkBuildingInfo != NULL && strcmp(pkBuildingInfo->GetType(), "BUILDING_PETRA") == 0)15904								{15905									if(pNewCity->GetCityBuildings()->GetNumRealBuilding(eBuilding) > 0)15906									{15907										gDLL->UnlockAchievement(ACHIEVEMENT_XP1_26);15908									}15909									break;15910								}15911							}15912						}1591315914						//Expansion 1 - Capture a Spanish Coastal City with a Dutch Sea Begger15915						if(strcmp(getUnitInfo().GetType(), "UNIT_DUTCH_SEA_BEGGAR") == 0)15916						{15917							if(pNewCity->isCoastal())15918							{15919								if(strcmp(pNewCity->getCivilizationInfo().GetType(), "CIVILIZATION_SPAIN") == 0)15920								{15921									gDLL->UnlockAchievement(ACHIEVEMENT_XP1_28);15922								}15923							}15924						}1592515926						// Expansion 2 - Capture Venice's holy city as Venice15927						// if venice15928						//   find venice religion15929						//   compare religion to if city is holy city of conquered15930						if (!GC.getGame().isGameMultiPlayer())15931						{15932							if(strcmp(getCivilizationInfo().GetType(), "CIVILIZATION_VENICE") == 0)15933							{15934#if defined(MOD_BUGFIX_USE_GETTERS)15935								CvCity* pCity = GET_MY_PLAYER().getCapitalCity();15936#else15937								CvCity* pCity = GET_PLAYER(m_eOwner).getCapitalCity();15938#endif15939								ReligionTypes eReligion = pCity->GetCityReligions()->GetReligiousMajority();15940								if (eReligion != NO_RELIGION)15941								{15942									if (pNewCity->GetCityReligions()->IsHolyCityForReligion(eReligion))15943									{15944										gDLL->UnlockAchievement(ACHIEVEMENT_XP2_26);15945									}15946								}15947							}15948						}15949					}1595015951					bool bUsingXP1Scenario2 = gDLL->IsModActivated(CIV5_XP1_SCENARIO2_MODID);15952					if(bUsingXP1Scenario2)15953					{15954						if(strcmp(getCivilizationInfo().GetType(), "CIVILIZATION_SONGHAI") == 0)15955						{15956							const int iRomeX = 33;15957							const int iRomeY = 31;1595815959							//Did we, as vandals, just capture Rome with a boat?15960							if(pNewCity->getX() == iRomeX && pNewCity->getY() == iRomeY && getDomainType() == DOMAIN_SEA)15961							{15962								gDLL->UnlockAchievement(ACHIEVEMENT_XP1_52);15963							}15964						}15965					}15966#endif15967					1596815969					1597015971					GET_PLAYER(eNewOwner).acquireCity(pNewCity, true, false); // will delete the pointer15972					pNewCity = NULL;15973				}15974			}15975		}1597615977		if(pOldPlot != NULL)15978		{15979			if(pOldCity != NULL)15980			{15981				pOldCity->updateStrengthValue();15982			}15983		}1598415985		if(shouldLoadOnMove(pNewPlot))15986		{15987			load();15988		}1598915990		// Can someone can see the plot we moved our Unit into?15991		TeamTypes eTeamLoop;15992		for(iI = 0; iI < MAX_CIV_TEAMS; iI++)15993		{15994			eTeamLoop = (TeamTypes) iI;1599515996			CvTeam& kLoopTeam = GET_TEAM(eTeamLoop);1599715998			if(kLoopTeam.isAlive())15999			{16000				// Human can't be met by an AI spotting him.  If both players are human then they don't need to see one another16001				if(!isHuman() || kLoopTeam.isHuman())16002				{16003					if(!isInvisible(eTeamLoop, false))16004					{16005						if(pNewPlot->isVisible(eTeamLoop))16006						{16007							kLoopTeam.meet(eOurTeam, false);16008						}16009					}16010				}16011			}16012		}1601316014		// if I was invisible to the active team but won't be any more or vice versa16015		InvisibleTypes eInvisoType = getInvisibleType();16016		if(eOurTeam != activeTeam && eInvisoType != NO_INVISIBLE)16017		{16018			bool bOldInvisibleVisible = false;16019			if(pOldPlot)16020				bOldInvisibleVisible = pOldPlot->isInvisibleVisible(activeTeam, eInvisoType);16021			bool bNewInvisibleVisible = pNewPlot->isInvisibleVisible(activeTeam, eInvisoType);16022			if(bOldInvisibleVisible != bNewInvisibleVisible)16023			{16024				auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(this));16025				gDLL->GameplayUnitVisibility(pDllUnit.get(), bNewInvisibleVisible, true);16026			}16027		}1602816029		CvTeam& kOurTeam = GET_TEAM(eOurTeam);1603016031		// If a Unit is adjacent to someone's borders, meet them16032		CvPlot* pAdjacentPlot;16033		for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)16034		{16035			pAdjacentPlot = plotDirection(pNewPlot->getX(), pNewPlot->getY(), ((DirectionTypes)iI));1603616037			if(pAdjacentPlot != NULL)16038			{16039				// Owned by someone16040				if(pAdjacentPlot->getTeam() != NO_TEAM)16041				{16042					kOurTeam.meet(pAdjacentPlot->getTeam(), false);16043				}1604416045				// Have a naval unit here?16046				if(isBarbarian() && getDomainType() == DOMAIN_SEA && pAdjacentPlot->isWater())16047				{16048					UnitHandle pAdjacentUnit = pAdjacentPlot->getBestDefender(NO_PLAYER, BARBARIAN_PLAYER, NULL, true);16049					if(pAdjacentUnit)16050					{16051#if defined(MOD_EVENTS_UNIT_CAPTURE)16052						GET_PLAYER(pAdjacentUnit->getOwner()).GetPlayerTraits()->CheckForBarbarianConversion(this, pAdjacentPlot);16053#else16054						GET_PLAYER(pAdjacentUnit->getOwner()).GetPlayerTraits()->CheckForBarbarianConversion(pAdjacentPlot);16055#endif16056					}16057				}1605816059				// Is this a missionary and do we have a belief that converts barbarians here?16060				UnitClassTypes eMissionary = (UnitClassTypes)GC.getInfoTypeForString("UNITCLASS_MISSIONARY", true);16061				if (eMissionary != NO_UNITCLASS)16062				{16063					if (getUnitClassType() == eMissionary)16064					{16065						ReligionTypes eFoundedReligion = kPlayer.GetReligions()->GetReligionCreatedByPlayer();16066						const CvReligion* pReligion = GC.getGame().GetGameReligions()->GetReligion(eFoundedReligion, kPlayer.GetID());16067						if (pReligion && pReligion->m_Beliefs.IsConvertsBarbarians())16068						{16069							UnitHandle pAdjacentUnit = pAdjacentPlot->getBestDefender(BARBARIAN_PLAYER);16070							if(pAdjacentUnit)16071							{16072#if defined(MOD_EVENTS_UNIT_CAPTURE)16073								CvBeliefHelpers::ConvertBarbarianUnit(this, pAdjacentUnit);16074#else16075								CvBeliefHelpers::ConvertBarbarianUnit(&kPlayer, pAdjacentUnit);16076#endif16077							}16078						}16079					}16080					// Or other way around, barbarian moving up to a missionary16081					else if (isBarbarian())16082					{16083						if(pAdjacentPlot->getNumUnits() > 0)16084						{16085							for(int iNearbyUnitLoop = 0; iNearbyUnitLoop < pAdjacentPlot->getNumUnits(); iNearbyUnitLoop++)16086							{16087								const CvUnit* const adjUnit = pAdjacentPlot->getUnitByIndex(iNearbyUnitLoop);16088								if (adjUnit && adjUnit->getUnitClassType() == eMissionary)16089								{16090									CvPlayer &adjUnitPlayer = GET_PLAYER(adjUnit->getOwner());16091									ReligionTypes eFoundedReligion = adjUnitPlayer.GetReligions()->GetReligionCreatedByPlayer();16092									const CvReligion* pReligion = GC.getGame().GetGameReligions()->GetReligion(eFoundedReligion, adjUnitPlayer.GetID());16093									if (pReligion && pReligion->m_Beliefs.IsConvertsBarbarians())16094									{16095#if defined(MOD_EVENTS_UNIT_CAPTURE)16096										if (CvBeliefHelpers::ConvertBarbarianUnit(adjUnit, this))16097#else16098										if (CvBeliefHelpers::ConvertBarbarianUnit(&adjUnitPlayer, this))16099#endif16100										{16101											ClearMissionQueue();16102										}16103									}16104								}16105							}16106						}16107					}16108				}1610916110				// Natural wonder that provides free promotions?16111				FeatureTypes eFeature = pAdjacentPlot->getFeatureType();16112				if(eFeature != NO_FEATURE && GC.getFeatureInfo(eFeature)->IsNaturalWonder())16113				{16114					PromotionTypes ePromotion = (PromotionTypes)GC.getFeatureInfo(eFeature)->getAdjacentUnitFreePromotion();16115					if(ePromotion != NO_PROMOTION)16116					{16117						// Is this a valid Promotion for the UnitCombatType?16118						if(m_pUnitInfo->GetUnitCombatType() != NO_UNITCOMBAT &&16119						        (::IsPromotionValidForUnitCombatType(ePromotion, getUnitType()) || ::IsPromotionValidForUnitCombatType(ePromotion, getUnitType())))16120						{16121							setHasPromotion(ePromotion, true);16122						}16123					}16124				}16125			}16126		}1612716128		if(pOldPlot != NULL && getDomainType() == DOMAIN_SEA)16129		{16130#if defined(MOD_EVENTS_UNIT_CAPTURE)16131			kPlayer.GetPlayerTraits()->CheckForBarbarianConversion(this, pNewPlot);16132#else16133			kPlayer.GetPlayerTraits()->CheckForBarbarianConversion(pNewPlot);16134#endif16135		}1613616137		if(GC.IsGraphicsInitialized())16138		{16139			//override bShow if check plot visible16140			if(bCheckPlotVisible && (pNewPlot->isVisibleToWatchingHuman() || pOldPlot->isVisibleToWatchingHuman()))16141				bShow = true;1614216143			if(CvPreGame::quickMovement())16144			{16145				bShow = false;16146			}1614716148			if(bShow)16149			{16150				QueueMoveForVisualization(pNewPlot);16151			}16152			else16153			{16154				SetPosition(pNewPlot);16155			}16156		}1615716158	}1615916160	if(pOldPlot != NULL)16161	{16162		if(hasCargo())16163		{16164			pUnitNode = pOldPlot->headUnitNode();1616516166			while(pUnitNode != NULL)16167			{16168				pLoopUnit = ::getUnit(*pUnitNode);16169				pUnitNode = pOldPlot->nextUnitNode(pUnitNode);1617016171				if(pLoopUnit && pLoopUnit->getTransportUnit() == this)16172				{16173					pLoopUnit->setXY(iX, iY, bGroup, bUpdate);1617416175					// Reset to head node since we just moved some cargo around, and the unit storage in the plot is going to be different now16176					pUnitNode = pOldPlot->headUnitNode();16177				}16178			}16179		}16180	}1618116182	if(pNewPlot != NULL && iMapLayer == DEFAULT_UNIT_MAP_LAYER)16183	{16184		if(!bNoMove)16185		{16186			if(pNewPlot->isGoody(getTeam()))16187			{16188				GET_PLAYER(getOwner()).doGoody(pNewPlot, this);16189			}16190			if(!isBarbarian())16191			{16192				if(pNewPlot->getImprovementType() == GC.getBARBARIAN_CAMP_IMPROVEMENT())16193				{16194					// See if we need to remove a temporary dominance zone16195					kPlayer.GetTacticalAI()->DeleteTemporaryZone(pNewPlot);1619616197					// Is there a camp guard that will convert to our side here, if so have special routine to handle it16198#if defined(MOD_EVENTS_UNIT_CAPTURE)16199					if (!kPlayer.GetPlayerTraits()->CheckForBarbarianConversion(this, pNewPlot))16200#else16201					if (!kPlayer.GetPlayerTraits()->CheckForBarbarianConversion(pNewPlot))16202#endif16203					{16204						int iNumGold = GC.getGame().getHandicapInfo().getBarbCampGold();16205						iNumGold *= (100 + kPlayer.GetPlayerTraits()->GetPlunderModifier()) / 100;1620616207						// Game Speed Mod16208						iNumGold *= GC.getGameSpeedInfo(GC.getGame().getGameSpeedType())->getGoldPercent();16209						iNumGold /= 100;1621016211						// Normal way to handle it16212						if(getOwner() == GC.getGame().getActivePlayer())16213						{16214							DLLUI->AddUnitMessage(0, GetIDInfo(), getOwner(), true, GC.getEVENT_MESSAGE_TIME(), GetLocalizedText("TXT_KEY_MISC_DESTROYED_BARBARIAN_CAMP", iNumGold));16215							MILITARYLOG(getOwner(), GetLocalizedText("TXT_KEY_MISC_DESTROYED_BARBARIAN_CAMP", iNumGold).c_str(), pNewPlot, BARBARIAN_PLAYER);16216						}1621716218						pNewPlot->setImprovementType(NO_IMPROVEMENT);1621916220						CvBarbarians::DoBarbCampCleared(pNewPlot, getOwner());1622116222						kPlayer.GetTreasury()->ChangeGold(iNumGold);1622316224						// Set who last cleared the camp here16225						pNewPlot->SetPlayerThatClearedBarbCampHere(getOwner());1622616227						if(getOwner() < MAX_MAJOR_CIVS)16228						{16229							// Completes a quest for anyone?16230							PlayerTypes eMinor;16231							for(int iMinorLoop = MAX_MAJOR_CIVS; iMinorLoop < MAX_CIV_PLAYERS; iMinorLoop++)16232							{16233								eMinor = (PlayerTypes) iMinorLoop;16234								CvPlayer& minorPlayer = GET_PLAYER(eMinor);1623516236								if(!minorPlayer.isAlive())16237									continue;1623816239								CvMinorCivAI* pMinorCivAI = minorPlayer.GetMinorCivAI();16240								pMinorCivAI->DoTestActiveQuestsForPlayer(getOwner(), /*bTestComplete*/ true, /*bTestObsolete*/ false, MINOR_CIV_QUEST_KILL_CAMP);16241							}16242						}1624316244#if defined(CIV_HOST_API)16245						CivHandPopupRaised(getOwner(), BUTTONPOPUP_BARBARIAN_CAMP_REWARD, iNumGold, -1, -1, false, false, "");hand-placed hook: PopupRaised16246#endif16247						// If it's the active player then show the popup16248						if(getOwner() == GC.getGame().getActivePlayer())16249						{16250							// Don't show in MP16251#if defined(MOD_API_EXTENSIONS)16252							if(!GC.getGame().isReallyNetworkMultiPlayer())16253#else16254							if(!GC.getGame().isNetworkMultiPlayer())	// KWG: Candidate for !GC.getGame().isOption(GAMEOPTION_SIMULTANEOUS_TURNS)16255#endif16256							{16257								CvPopupInfo kPopupInfo(BUTTONPOPUP_BARBARIAN_CAMP_REWARD, iNumGold);16258								DLLUI->AddPopup(kPopupInfo);16259								// We are adding a popup that the player must make a choice in, make sure they are not in the end-turn phase.16260								CancelActivePlayerEndTurn();1626116262#if !defined(NO_ACHIEVEMENTS)16263								//Increment Stat16264								if(kPlayer.isHuman() && !GC.getGame().isGameMultiPlayer())16265								{16266									gDLL->IncrementSteamStatAndUnlock(ESTEAMSTAT_BARBARIANCAMPS, 100, ACHIEVEMENT_100CAMPS);16267								}16268#endif1626916270							}16271						}16272					}16273				}16274			}16275		}1627616277		// New plot location is owned by someone16278		PlayerTypes ePlotOwner = pNewPlot->getOwner();16279		if(ePlotOwner != NO_PLAYER)16280		{16281			// If we're in friendly territory and we can embark, give the promotion for free16282			if(pNewPlot->IsFriendlyTerritory(getOwner()))16283			{16284				if(GET_TEAM(eOurTeam).canEmbark())16285				{16286					PromotionTypes ePromotionEmbarkation = kPlayer.GetEmbarkationPromotion();1628716288					bool bGivePromotion = false;1628916290					// Civilians get it for free16291					if(getDomainType() == DOMAIN_LAND)16292					{16293						if(!IsCombatUnit())16294							bGivePromotion = true;16295					}1629616297					// Can the unit get this? (handles water units and such)16298					if(!bGivePromotion && ::IsPromotionValidForUnitCombatType(ePromotionEmbarkation, getUnitType()))16299						bGivePromotion = true;1630016301					// Some case that gives us the promotion?16302					if(bGivePromotion)16303						setHasPromotion(ePromotionEmbarkation, true);16304						16305#if defined(MOD_PROMOTIONS_DEEP_WATER_EMBARKATION)16306					if (MOD_PROMOTIONS_DEEP_WATER_EMBARKATION) {16307						// Incredibly unlikely to ever happen as it implies that hovering units come before embarkation in the tech tree!16308						PromotionTypes ePromotionDeepWaterEmbarkation = kPlayer.GetDeepWaterEmbarkationPromotion();16309						if(::IsPromotionValidForUnitCombatType(ePromotionDeepWaterEmbarkation, getUnitType())) {16310							setHasPromotion(ePromotionDeepWaterEmbarkation, true);16311						}16312					}16313#endif16314				}16315			}1631616317			// Are we in enemy territory? If so, give notification to owner16318			if(GET_TEAM(getTeam()).isAtWar(GET_PLAYER(ePlotOwner).getTeam()) && !isInvisible(GET_PLAYER(ePlotOwner).getTeam(),false,false))16319			{16320				CvNotifications* pNotifications = GET_PLAYER(ePlotOwner).GetNotifications();16321				if(pNotifications)16322				{16323					Localization::String strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_ENEMY");16324					Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_ENEMY_SUMMARY");16325					pNotifications->Add(NOTIFICATION_ENEMY_IN_TERRITORY, strMessage.toUTF8(), strSummary.toUTF8(), iX, iY, getUnitType(), getOwner());16326				}16327			}16328		}16329	}1633016331	// Create any units we captured, now that we own the destination16332	for(uint uiCaptureIndex = 0; uiCaptureIndex < kCaptureUnitList.size(); ++uiCaptureIndex)16333	{16334#if defined(CIV_HOST_API)16335		CivHostCaptureFrom(kCivHostCapturedFrom[uiCaptureIndex].eOwner, kCivHostCapturedFrom[uiCaptureIndex].iID);16336#endif16337		createCaptureUnit(kCaptureUnitList[uiCaptureIndex]);16338#if defined(CIV_HOST_API)16339		CivHostCaptureDone();16340#endif16341	}1634216343	CvAssert(pOldPlot != pNewPlot);1634416345	if(IsSelected())16346		gDLL->GameplayMinimapUnitSelect(iX, iY);1634716348	setInfoBarDirty(true);1634916350	// if there is an enemy city nearby, alert any scripts to this16351#if defined(MOD_EVENTS_CITY_BOMBARD)16352	int iAttackRange = (MOD_EVENTS_CITY_BOMBARD ? GC.getMAX_CITY_ATTACK_RANGE() : GC.getCITY_ATTACK_RANGE());16353#else16354	int iAttackRange = GC.getCITY_ATTACK_RANGE();16355#endif16356	for(int iDX = -iAttackRange; iDX <= iAttackRange; iDX++)16357	{16358		for(int iDY = -iAttackRange; iDY <= iAttackRange; iDY++)16359		{16360			CvPlot* pTargetPlot = plotXYWithRangeCheck(getX(), getY(), iDX, iDY, iAttackRange);16361			if(pTargetPlot && pTargetPlot->isCity())16362			{16363				if(isEnemy(pTargetPlot->getTeam()))16364				{16365					// do it16366					CvCity* pkPlotCity = pTargetPlot->getPlotCity();16367#if defined(MOD_EVENTS_CITY_BOMBARD)16368					if (!MOD_EVENTS_CITY_BOMBARD || plotXYWithRangeCheck(getX(), getY(), iDX, iDY, pkPlotCity->getBombardRange()))16369					{16370#endif16371						auto_ptr<ICvCity1> pPlotCity = GC.WrapCityPointer(pkPlotCity);16372						DLLUI->SetSpecificCityInfoDirty(pPlotCity.get(), CITY_UPDATE_TYPE_ENEMY_IN_RANGE);16373#if defined(MOD_EVENTS_CITY_BOMBARD)16374					}16375#endif16376				}16377			}16378		}16379	}1638016381	// Units moving into and out of cities change garrison happiness16382	if((pNewPlot && pNewPlot->isCity()) || (pOldPlot && pOldPlot->isCity()))16383	{16384		GET_PLAYER(getOwner()).DoUpdateHappiness();16385	}1638616387	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();16388	if(pkScriptSystem)16389	{16390		CvLuaArgsHandle args;16391		args->Push(getOwner());16392		args->Push(GetID());16393		args->Push(getX());16394		args->Push(getY());1639516396		bool bResult;16397		LuaSupport::CallHook(pkScriptSystem, "UnitSetXY", args.get(), bResult);16398	}1639916400	if (bOwnerIsActivePlayer)16401		DLLUI->SetDontShowPopups(false);1640216403	// Send out a message that the unit has updated the garrison for the city it was in.16404	CvCity* pkNewGarrisonCity = GetGarrisonedCity();16405	if (pkNewGarrisonCity && pkNewGarrisonCity != pkPrevGarrisonedCity)16406	{16407		auto_ptr<ICvCity1> pkDllCity(new CvDllCity(pkNewGarrisonCity));16408		DLLUI->SetSpecificCityInfoDirty(pkDllCity.get(), CITY_UPDATE_TYPE_GARRISON);16409	}16410	if(pkPrevGarrisonedCity && pkPrevGarrisonedCity != pkNewGarrisonCity)16411	{16412		auto_ptr<ICvCity1> pkDllCity(new CvDllCity(pkPrevGarrisonedCity));16413		DLLUI->SetSpecificCityInfoDirty(pkDllCity.get(), CITY_UPDATE_TYPE_GARRISON);16414	}16415	16416#if !defined(NO_ACHIEVEMENTS)16417	//Dr. Livingstone I presume?16418	if (isHuman() && !isDelayedDeath())16419	{16420		if(strcmp(getCivilizationInfo().GetType(), "CIVILIZATION_BRAZIL") == 0){16421			UnitTypes eExplorer = (UnitTypes) GC.getInfoTypeForString("UNIT_EXPLORER", true /*bHideAssert*/); 16422			if(getUnitType() == eExplorer && strcmp(getNameNoDesc(), "TXT_KEY_EXPLORER_STANLEY") == 0 ){16423				CvPlot* pAdjacentPlot;16424				for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)16425				{16426					pAdjacentPlot = plotDirection(pNewPlot->getX(), pNewPlot->getY(), ((DirectionTypes)iI));1642716428					if(pAdjacentPlot != NULL && pAdjacentPlot->getNumUnits() != NULL){16429						for(int iJ = 0; iJ < pAdjacentPlot->getNumUnits(); iJ++){16430							if(pAdjacentPlot->getUnitByIndex(iJ)->getUnitType() ==  eExplorer && strcmp(pAdjacentPlot->getUnitByIndex(iJ)->getNameNoDesc(), "TXT_KEY_EXPLORER_LIVINGSTON") == 0){16431								gDLL->UnlockAchievement(ACHIEVEMENT_XP2_52);16432							}16433						}16434					}16435				}16436			}16437		}16438	}16439#endif16440}

Calls

Called by