Uighur_Caesar
Comandante en Jefe
A civ I'm trying to make is supposed to give +2 Movement to Settlers (and colonists if playing with JFD's CCC) that start their turn on one of your trade routes. I'm trying to use Tomatekh's Garamantes' code as a reference since it gives units starting on their trade routes +1 movement and no rough terrain penalties, but I'm having a hard time understanding it, particularly the strTradeRouteStr stuff. Could someone please help me understand what's going on in it and what changes I would need to make for my UA to work?
Spoiler :
Code:
local pNoTerrainCost = GameInfoTypes.PROMOTION_IGNORE_TERRAIN_COST;
local pChariotRoute = GameInfoTypes.PROMOTION_LIBYAN_CHARIOT_ROUTE;
local pNoMovement = GameInfoTypes.PROMOTION_ROUGH_TERRAIN_ENDS_TURN;
local pWood = GameInfoTypes.PROMOTION_WOODSMAN;
local fForest = GameInfoTypes.FEATURE_FOREST;
local fJungle = GameInfoTypes.FEATURE_JUNGLE;
local uCargo = GameInfoTypes.UNIT_CARGO_SHIP;
local uCaravan = GameInfoTypes.UNIT_CARAVAN;
local uChariot = GameInfoTypes.UNIT_CHARIOT_ARCHER
local uWarChariot = GameInfoTypes.UNIT_EGYPTIAN_WARCHARIOT
local uHitChariot = GameInfoTypes.UNIT_HITTITE_MOD_THREE_MAN_CHARIOT
function GetTradeRouteString(pPlot, pPlayer, pUnit)
local strTradeRouteStr = "";
local astrTradeRouteStrings = pPlayer:GetInternationalTradeRoutePlotToolTip(pPlot);
for i,v in ipairs(astrTradeRouteStrings) do
if (strTradeRouteStr == "") then
strTradeRouteStr = strTradeRouteStr .. Locale.ConvertTextKey("TXT_KEY_TRADE_ROUTE_TT_PLOT_HEADING");
else
strTradeRouteStr = strTradeRouteStr .. "[NEWLINE]";
end
strTradeRouteStr = strTradeRouteStr .. v.String;
end
return strTradeRouteStr;
end
GameEvents.UnitSetXY.Add(
function(iPlayerID, iUnitID, iX, iY)
local pPlot = Map.GetPlot(iX, iY)
local pPlayer = Players[iPlayerID]
local pUnit = pPlayer:GetUnitByID(iUnitID)
if pPlot then
if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_ANCIENT_LIBYA_MOD) then
if (pUnit:GetUnitType() ~= uCargo) and (pUnit:GetUnitType() ~= uCaravan) then
if (pUnit:GetDomainType() == DomainTypes.DOMAIN_LAND) and not pUnit:IsEmbarked() then
local strTradeRouteStr = GetTradeRouteString(pPlot, pPlayer, pUnit)
if strTradeRouteStr ~= "" then
if (pPlayer:IsHuman()) then --Might confuse AI movement?
if not pUnit:IsHasPromotion(pNoTerrainCost) then
if not pUnit:IsHasPromotion(pChariotRoute) then
pUnit:SetHasPromotion(pChariotRoute, true)
end
end
if (pUnit:GetUnitType() == uChariot) or (pUnit:GetUnitType() == uWarChariot) or (pUnit:GetUnitType() == uHitChariot) then
if pUnit:IsHasPromotion(pNoMovement) then
pUnit:SetHasPromotion(pNoMovement, false)
end
end
end
elseif strTradeRouteStr == "" then
if (pPlayer:IsHuman()) then
if pUnit:IsHasPromotion(pChariotRoute) then
pUnit:SetHasPromotion(pChariotRoute, false)
if pPlot:IsRoughGround() and not pPlot:IsRoute() then
if not pUnit:IsHasPromotion(pWood) then
pUnit:ChangeMoves(-60)
elseif pUnit:IsHasPromotion(pWood) then
if (pPlot:GetFeatureType() ~= fForest) and (pPlot:GetFeatureType() ~= fJungle) then
pUnit:ChangeMoves(-60)
end
end
end
end
if (pUnit:GetUnitType() == uChariot) or (pUnit:GetUnitType() == uWarChariot) or (pUnit:GetUnitType() == uHitChariot) then
if not pUnit:IsHasPromotion(pNoMovement) then
pUnit:SetHasPromotion(pNoMovement, true)
if pPlot:IsRoughGround() and not pPlot:IsRoute() then
local MovesLeft = pUnit:GetMoves();
pUnit:ChangeMoves(-MovesLeft)
end
end
end
end
end
end
end
end
end
end);
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
local pPlayer = Players[iPlayer];
local iCurrentTurn = Game.GetGameTurn()
if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_ANCIENT_LIBYA_MOD) then
for pUnit in pPlayer:Units() do
if (pUnit:GetUnitType() ~= uCargo) and (pUnit:GetUnitType() ~= uCaravan) then
if (pUnit:GetDomainType() == DomainTypes.DOMAIN_LAND) and not pUnit:IsEmbarked() then
local pPlot = pUnit:GetPlot()
local strTradeRouteStr = GetTradeRouteString(pPlot, pPlayer, pUnit)
if strTradeRouteStr ~= "" then
if (pPlayer:IsHuman()) then
if not pUnit:IsHasPromotion(pNoTerrainCost) then
if not pUnit:IsHasPromotion(pChariotRoute) then
pUnit:SetHasPromotion(pChariotRoute, true)
end
end
if (pUnit:GetUnitType() == uChariot) or (pUnit:GetUnitType() == uWarChariot) or (pUnit:GetUnitType() == uHitChariot) then
if pUnit:IsHasPromotion(pNoMovement) then
pUnit:SetHasPromotion(pNoMovement, false)
end
end
end
if pUnit:GetMoves() ~= 0 then
local pMax = pUnit:MaxMoves();
pUnit:SetMoves(pMax + 60);
--AI Handicap
if not (pPlayer:IsHuman()) then
if (pUnit:GetGameTurnCreated() == iCurrentTurn) then
if not pUnit:IsHasPromotion(pNoTerrainCost) then
if not pUnit:IsHasPromotion(pChariotRoute) then
pUnit:SetHasPromotion(pChariotRoute, true)
end
end
end
end
--
end
elseif strTradeRouteStr == "" then
if (pPlayer:IsHuman()) then
if pUnit:IsHasPromotion(pChariotRoute) then
pUnit:SetHasPromotion(pChariotRoute, false)
end
if (pUnit:GetUnitType() == uChariot) or (pUnit:GetUnitType() == uWarChariot) or (pUnit:GetUnitType() == uHitChariot) then
if not pUnit:IsHasPromotion(pNoMovement) then
pUnit:SetHasPromotion(pNoMovement, true)
end
end
end
end
end
end
--AI Handicap
if not (pPlayer:IsHuman()) then
if (pUnit:GetGameTurnCreated() ~= iCurrentTurn) then
if pUnit:IsHasPromotion(pChariotRoute) then
pUnit:SetHasPromotion(pChariotRoute, false)
end
end
end
--
end
end
end);