--=======================================================================================================================
-- UTILITY FUNCTIONS
--=======================================================================================================================
-- IsRagusaActive
--------------------------------------------------------------------------------------------------------------------------
local civilisationID = GameInfoTypes["CIVILIZATION_DMS_RAGUSA"]
function IsRagusaActive(civilisationID)
for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local slotStatus = PreGame.GetSlotStatus(iSlot)
if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
if PreGame.GetCivilization(iSlot) == civilisationID then
return true
end
end
end
return false
end
if IsRagusaActive(civilisationID) then
print("The Republic of Ragusa joins the game!")
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_AddPromotion
--------------------------------------------------------------------------------------------------------------------------
function JFD_AddPromotion(unit, promotionID)
if not unit:IsHasPromotion(promotionID) then
unit:SetHasPromotion(promotionID, true)
end
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_RemovePromotion
--------------------------------------------------------------------------------------------------------------------------
function JFD_RemovePromotion(unit, promotionID)
if unit:IsHasPromotion(promotionID) then
unit:SetHasPromotion(promotionID, false)
end
end
--------------------------------------------------------------------------------------------------------------------------
-- DMS_IsInCSTerritory
--------------------------------------------------------------------------------------------------------------------------
function DMS_IsInCSTerritory(unit)
local player = Players[playerID]
local plot = Map.GetPlot(unit:GetX(), unit:GetY())
if plot:GetOwner() == player:IsMinorCiv() then
return true
end
end
--------------------------------------------------------------------------------------------------------------------------
-- DMS_convertUnit
--------------------------------------------------------------------------------------------------------------------------
function DMS_convertUnit(pUnit, sNewUnitType)
local pPlayer = Players[pUnit:GetOwner()]
local pNewUnit = pPlayer:InitUnit(GameInfoTypes[sNewUnitType], pUnit:GetX(), pUnit:GetY())
pNewUnit:SetDamage(pUnit:GetDamage())
pNewUnit:SetExperience(pUnit:GetExperience())
pNewUnit:SetLevel(pUnit:GetLevel())
for unitPromotion in GameInfo.UnitPromotions() do
local iPromotionID = unitPromotion.ID;
if (pUnit:IsHasPromotion(iPromotionID)) then
if (pNewUnit:IsPromotionValid(iPromotionID)) then
pNewUnit:SetHasPromotion(iPromotionID, true)
end
end
end
end
--==========================================================================================================================
-- CORE FUNCTIONS
--==========================================================================================================================
local DMS_TradeColonyInternal = GameInfoTypes["IMPROVEMENT_DMS_TRADE_COLONY_INTERNAL"]
local DMS_TradeColonyCityState = GameInfoTypes["IMPROVEMENT_DMS_TRADE_COLONY_CITYSTATE"]
local DMS_SotR1 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_1"]
local DMS_SotR2 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_2"]
local DMS_SotR3 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_3"]
local DMS_SotR4 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_4"]
local DMS_SotR5 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_5"]
local DMS_SotR6 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_6"]
local DMS_SotR7 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_7"]
local DMS_SotR8 = GameInfoTypes["PROMOTION_SWORD_OF_THE_RECTOR_8"]
local DMS_Argosy = GameInfoTypes["UNIT_DMS_ARGOSY"]
local DMS_ArgosyUpg = GameInfoTypes["UNIT_DMS_ARGOSY_UPG"]
local DMS_Trgovac = GameInfoTypes["UNIT_DMS_TRGOVAC"]
local DMS_TrgovacCS = GameInfoTypes["UNIT_DMS_ARGOSY_UPG"]
--------------------------------------------------------------------------------------------------------------------------
-- DMS_CountTradeColonyCS
--------------------------------------------------------------------------------------------------------------------------
DMS_CountTradeColonyCS_PlayerID = 0
DMS_CountTradeColonyCS_iX = 0
DMS_CountTradeColonyCS_iY = 0
DMS_CountTradeColonyCS_ID = 0
function DMS_CountTradeColonyCS(playerID, plotX, plotY, improvementID)
if DMS_CountTradeColonyCS_PlayerID == playerID and DMS_CountTradeColonyCS_iX == iX and DMS_CountTradeColonyCS_iY == iY and DMS_CountTradeColonyCS_ID == improvementID then return end
DMS_CountTradeColonyCS_PlayerID = 0
DMS_CountTradeColonyCS_iX = 0
DMS_CountTradeColonyCS_iY = 0
DMS_CountTradeColonyCS_ID = 0
local player = Players[playerID]
local DMS_NumTradeColonyCS = 0
if player:IsAlive() and player:GetCivilizationType() == civilisationID then
if improvementID == DMS_TradeColonyCityState then
DMS_NumTradeColonyCS = DMS_NumTradeColonyCS + 1
end
return DMS_NumTradeColonyCS
end
end
GameEvents.BuildFinished.Add(DMS_CountTradeColonyCS)
--------------------------------------------------------------------------------------------------------------------------
-- DMS_ArgosyPromotions
--------------------------------------------------------------------------------------------------------------------------
function DMS_ArgosyPromotions(playerID)
local player = Players[playerID]
if player:IsAlive() and player:GetCivilizationType() == civilisationID then
for unit in player:Units() do
if unit and unit:GetUnitType() == DMS_Argosy or unit:GetUnitType() == DMS_ArgosyUpg then
if (DMS_NumTradeColonyCS == 1) then JFD_AddPromotion(unit, DMS_SotR1)
elseif (DMS_NumTradeColonyCS == 2) then JFD_AddPromotion(unit, DMS_SotR2) JFD_RemovePromotion(unit, DMS_SotR1)
elseif (DMS_NumTradeColonyCS == 3) then JFD_AddPromotion(unit, DMS_SotR3) JFD_RemovePromotion(unit, DMS_SotR2)
elseif (DMS_NumTradeColonyCS == 4) then JFD_AddPromotion(unit, DMS_SotR4) JFD_RemovePromotion(unit, DMS_SotR3)
elseif (DMS_NumTradeColonyCS == 5) then JFD_AddPromotion(unit, DMS_SotR5) JFD_RemovePromotion(unit, DMS_SotR4)
elseif (DMS_NumTradeColonyCS == 6) then JFD_AddPromotion(unit, DMS_SotR6) JFD_RemovePromotion(unit, DMS_SotR5)
elseif (DMS_NumTradeColonyCS == 7) then JFD_AddPromotion(unit, DMS_SotR7) JFD_RemovePromotion(unit, DMS_SotR6)
elseif (DMS_NumTradeColonyCS >= 8) then JFD_AddPromotion(unit, DMS_SotR8) JFD_RemovePromotion(unit, DMS_SotR7)
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(DMS_ArgosyPromotions)
------------------------------------------------------------------------------------------------------------------------
-- ConvertUnitInCSBorders
------------------------------------------------------------------------------------------------------------------------
function ConvertUnitInCSBorders(playerID)
local player = Players[playerID]
for unit in player:Units() do
if unit and DMS_IsInCSTerritory(unit) == true then
if unit:GetUnitType() == DMS_Argosy then
DMS_convertUnit(unit, DMS_ArgosyUpg)
elseif unit:GetUnitType() == DMS_Trgovac then
DMS_convertUnit(unit, DMS_TrgovacCS)
end
end
end
end
GameEvents.PlayerDoTurn.Add(ConvertUnitInCSBorders)
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------