-- ICSKiller
-- Author: Dale
-- DateCreated: 11/21/2010 10:25:44 PM
--------------------------------------------------------------
include( "SaveUtils" ); MY_MOD_NAME = "DaleKentICSKiller";
-- Globals
----------
Player.bNeedToLoadData = true;
Player.bNeedToSaveData = false;
Player.ICSHappinessFromBuildings = 0;
Player.ICSCheckHandicapHappy = 0;
Player.ICSHappinessFromHandicap = 0;
Player.ICSBureaucracyUnhappiness = 0;
-- Functions
------------
function ICSGetHappiness()
for iPlayerID = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
local count = 0;
local pPlayer = Players[iPlayerID];
if( pPlayer.bNeedToLoadData ) then
pPlayer.ICSHappinessFromBuildings = load( pPlayer, "ICSHappinessFromBuildings" );
pPlayer.ICSCheckHandicapHappy = load( pPlayer, "ICSCheckHandicapHappy" );
pPlayer.ICSHappinessFromHandicap = load( pPlayer, "ICSHappinessFromHandicap" );
pPlayer.ICSBureaucracyUnhappiness = load( pPlayer, "ICSBureaucracyUnhappiness" );
pPlayer.bNeedToLoadData = false;
end
ICSSetHappinessFromBuildings();
ICSSetBureaucracyUnhappiness();
local iPoliciesHappiness = pPlayer:GetHappinessFromPolicies();
local iResourcesHappiness = pPlayer:GetHappinessFromResources();
local iExtraLuxuryHappiness = pPlayer:GetExtraHappinessPerLuxury();
local iBuildingHappiness = pPlayer.ICSHappinessFromBuildings;
local iGarrisonedUnitsHappiness = pPlayer:GetHappinessFromGarrisonedUnits();
local iTradeRouteHappiness = pPlayer:GetHappinessFromTradeRoutes();
local iReligionHappiness = pPlayer:GetHappinessFromReligion();
local iNaturalWonderHappiness = pPlayer:GetHappinessFromNaturalWonders();
local iExtraHappinessPerCity = pPlayer:GetExtraHappinessPerCity() * pPlayer:GetNumCities();
local iMinorCivHappiness = 0;
local iBureaucracyUnhappiness = pPlayer.ICSBureaucracyUnhappiness;
-- Loop through all the Minors the active player knows
for iPlayerLoop = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
iMinorCivHappiness = iMinorCivHappiness + pPlayer:GetHappinessFromMinor(iPlayerLoop);
end
if (pPlayer.ICSCheckHandicapHappy <= 0) then
pPlayer.ICSHappinessFromHandicap = pPlayer:GetHappiness();
pPlayer.ICSCheckHandicapHappy = 1;
end
local iHandicapHappiness = pPlayer.ICSHappinessFromHandicap;
local iTotalHappiness = iPoliciesHappiness + iResourcesHappiness + iBuildingHappiness + iMinorCivHappiness + iHandicapHappiness + iTradeRouteHappiness + iReligionHappiness + iNaturalWonderHappiness + iExtraHappinessPerCity - iBureaucracyUnhappiness;
pPlayer:SetHappiness(iTotalHappiness);
if( pPlayer.bNeedToSaveData ) then
save( pPlayer, "ICSHappinessFromBuildings", pPlayer.ICSHappinessFromBuildings );
save( pPlayer, "ICSCheckHandicapHappy", pPlayer.ICSCheckHandicapHappy );
save( pPlayer, "ICSHappinessFromHandicap", pPlayer.ICSHappinessFromHandicap );
save( pPlayer, "ICSBureaucracyUnhappiness", pPlayer.ICSBureaucracyUnhappiness );
pPlayer.bNeedToSaveData = false;
end
end
end
function ICSSetHappinessFromBuildings()
for iPlayerID = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
local count = 0;
local pPlayer = Players[iPlayerID];
if( pPlayer:IsAlive() ) then
if( pPlayer:GetNumCities() > 0 ) then
for cityIndex = 0, pPlayer:GetNumCities() - 1, 1 do
local pCity = pPlayer:GetCityByID( cityIndex );
if( pCity ~= nil ) then
for building in GameInfo.Buildings() do
if (pCity:IsHasBuilding(building.ID)) then
if (building.Happiness > 0) then
if (building.Type == "BUILDING_COLOSSEUM") then
count = count + (pCity:GetPopulation() / 4);
elseif (building.Type == "BUILDING_THEATRE") then
count = count + (pCity:GetPopulation() / 4);
elseif (building.Type == "BUILDING_STADIUM") then
count = count + (pCity:GetPopulation() / 4);
else
count = count + building.Happiness;
end
end
end
end
end
end
end
if( count ~= pPlayer.ICSHappinessFromBuildings ) then
pPlayer.ICSHappinessFromBuildings = count;
pPlayer.bNeedToSaveData = true;
end
end
end
end
function ICSSetBureaucracyUnhappiness()
for iPlayerID = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
local count = 0;
local pPlayer = Players[iPlayerID];
if( pPlayer:IsAlive() ) then
if( pPlayer:GetNumCities() > 0 ) then
for cityIndex = 0, pPlayer:GetNumCities() - 1, 1 do
count = count + (cityIndex / 3);
end
end
if( count ~= pPlayer.ICSBureaucracyUnhappiness ) then
pPlayer.ICSBureaucracyUnhappiness = count;
pPlayer.bNeedToSaveData = true;
end
end
end
end
Events.SerialEventGameDataDirty.Add(ICSGetHappiness);
Events.SerialEventTurnTimerDirty.Add(ICSGetHappiness);
Events.SerialEventCityInfoDirty.Add(ICSGetHappiness);
Events.GameplaySetActivePlayer.Add(ICSGetHappiness);
ICSGetHappiness();