print ("loaded")
include( "SaveUtils" ); MY_MOD_NAME = "Tuscany";
function TuscanUA (iPlayer)
local pPlayer = Players[iPlayer];
-- Ignore Minors and Barbarians
if( pPlayer:IsMinorCiv() or pPlayer:IsBarbarian() ) then
--print("Player is minor or barbarian, not executing code.");
return;
end
-- for testing purposes --print these out to verify they are equal / not equal
----print( tostring(pPlayer:GetCivilizationType()) );
----print( tostring(GameInfoTypes["CIVILIZATION_TUSCANY"] ) );
if ( pPlayer:GetCivilizationType() ~= GameInfoTypes["CIVILIZATION_TUSCANY"] ) then
----print("Player " .. tostring(iPlayer) .. " is not Tuscany");
return;
end
local pCity = pPlayer:GetCapitalCity();
--local iBuildingType = GameInfo.Buildings()
for building in GameInfo.Buildings() do
strName = GameInfo.Buildings[building.ID].Description
strCityName = pCity:GetName()
if pCity:IsHasBuilding(building.ID) then
if load( pPlayer, building.ID .. "and" .. iPlayer) ~= true then
strBuildingClass = GameInfo.Buildings[building.ID].BuildingClass
if GameInfo.BuildingClasses[strBuildingClass].MaxPlayerInstances > (-1)then
save( pPlayer, building.ID .. "and" .. iPlayer, true );
----print(strName .. " inserted from: " .. strCityName .. " but not applicable for UA")
else if GameInfo.BuildingClasses[strBuildingClass].MaxGlobalInstances > (-1) then
save( pPlayer, building.ID .. "and" .. iPlayer, true );
----print(strName .. " inserted from: " .. strCityName .. " but not applicable for UA")
else
strSlotName = GameInfo.Buildings[building.ID].GreatWorkSlotType
save( pPlayer, building.ID .. "and" .. iPlayer, true );
----print(strName .. " inserted from: " .. strCityName)
----print(strSlotName);
if (strSlotName == "GREAT_WORK_SLOT_MUSIC") then
----print(strSlotName);
local iUnitID = GameInfo.Units.UNIT_MUSICIAN.ID
pPlayer:InitUnit (iUnitID, pCity:GetX(), pCity:GetY() );
elseif (strSlotName == "GREAT_WORK_SLOT_LITERATURE") then
--print(strSlotName);
local iUnitID = GameInfo.Units.UNIT_WRITER.ID
pPlayer:InitUnit (iUnitID, pCity:GetX(), pCity:GetY() );
elseif (strSlotName == "GREAT_WORK_SLOT_ART_ARTIFACT") then
--print(strSlotName);
local iUnitID = GameInfo.Units.UNIT_ARTIST.ID
pPlayer:InitUnit (iUnitID, pCity:GetX(), pCity:GetY() );
else
--print("has no Great Work slot");
end
end
end
else
--print (strName .. " not new construction in city: " .. strCityName)
end
else
--print("Building: " .. strName .. " does not exist in city: " .. strCityName)
end
end
end
GameEvents.PlayerDoTurn.Add(TuscanUA)
GameEvents.PlayerAdoptPolicy.Add(TuscanUA)
function CityScreenTuscanUA()
local iPlayer = Game.GetActivePlayer()
TuscanUA(iPlayer)
end
Events.SerialEventExitCityScreen.Add(CityScreenTuscanUA)