Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real Housing - GS update #395

Open
wants to merge 2 commits into
base: expansion2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 70 additions & 48 deletions Assets/Expansion1/CityBanners/citybannermanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4243,62 +4243,84 @@ end
-- ===========================================================================
-- CQUI calculate real housing from improvements
function CQUI_RealHousingFromImprovements(pCity, PlayerID, pCityID)
-- CQUI: There is a bug that shares housing from improvements for cities with the same IDs. So this bug is also added to the mod and will be removed after it will be fixed by developers.
local x, y = pCity:GetX(), pCity:GetY();
local CQUI_ID_BuggedTable = {};
for i = -3, 3 do
if i ~= 0 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + i, y) );
end
if i ~= 3 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y + 1) );
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y - 1) );
end
if i ~= -3 and i ~= 3 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + i, y + 2) );
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + i, y - 2) );
end
if i ~= -3 and i <=1 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y + 3) );
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y - 3) );
end
end

local CQUI_HousingFromImprovements = 0;
local kCityPlots :table = Map.GetCityPlots():GetPurchasedPlots(pCity);
if kCityPlots ~= nil then
for _, plotID in pairs(kCityPlots) do
local kPlot :table = Map.GetPlotByIndex(plotID);
if Map.GetPlotDistance( pCity:GetX(), pCity:GetY(), kPlot:GetX(), kPlot:GetY() ) <= 3 then
local eImprovementType :number = kPlot:GetImprovementType();
if eImprovementType ~= -1 then
if not kPlot:IsImprovementPillaged() then
local kImprovementData = GameInfo.Improvements[eImprovementType].Housing;
if kImprovementData == 1 then -- farms, pastures etc.
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 1;
elseif kImprovementData == 2 then -- stepwells, kampungs, mekewaps, golf courses
if GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_STEPWELL" then -- stepwells
local CQUI_PlayerResearchedSanitation :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_SANITATION"].Index); -- check if a player researched Sanitation
if not CQUI_PlayerResearchedSanitation then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_KAMPUNG" then -- kampungs
local CQUI_PlayerResearchedMassProduction :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_MASS_PRODUCTION"].Index); -- check if a player researched Mass Production
if not CQUI_PlayerResearchedMassProduction then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_MEKEWAP" then -- mekewaps
local CQUI_PlayerResearchedCivilService :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_CIVIL_SERVICE"].Index); -- check if a player researched Civil Service
if not CQUI_PlayerResearchedCivilService then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_GOLF_COURSE" then -- golf courses
local CQUI_PlayerResearchedGlobalization :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_GLOBALIZATION"].Index); -- check if a player researched Globalization
if CQUI_PlayerResearchedGlobalization then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
end
for _, kPlot in pairs(CQUI_ID_BuggedTable) do
local kPlotCity = Cities.GetPlotPurchaseCity(kPlot);
local kPlotCityID;
if kPlotCity ~= nil then
kPlotCityID = kPlotCity:GetID();
end
if kPlotCityID == pCityID then
local eImprovementType :number = kPlot:GetImprovementType();
if eImprovementType ~= -1 then
if not kPlot:IsImprovementPillaged() then
local kImprovementData = GameInfo.Improvements[eImprovementType].Housing;
if kImprovementData == 1 then -- Farms, Fishing Boats, Pastures, Plantations, Camps
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 1;
elseif kImprovementData == 2 then -- Stepwells, Kampungs, Mekewaps
if GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_STEPWELL" then -- Stepwells
local CQUI_PlayerResearchedSanitation :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_SANITATION"].Index); -- check if a player researched Sanitation
if not CQUI_PlayerResearchedSanitation then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_KAMPUNG" then -- Kampungs
local CQUI_PlayerResearchedMassProduction :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_MASS_PRODUCTION"].Index); -- check if a player researched Mass Production
if not CQUI_PlayerResearchedMassProduction then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
else -- Mekewaps (elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_MEKEWAP" then)
local CQUI_PlayerResearchedCivilService :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_CIVIL_SERVICE"].Index); -- check if a player researched Civil Service
if not CQUI_PlayerResearchedCivilService then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_GOLF_COURSE" then -- Golf Courses (kImprovementData == 0)
local CQUI_PlayerResearchedGlobalization :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_GLOBALIZATION"].Index); -- check if a player researched Globalization
if CQUI_PlayerResearchedGlobalization then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
end
end
end
end
end
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements * 0.5;
if CQUI_HousingFromImprovementsTable[PlayerID] == nil then
CQUI_HousingFromImprovementsTable[PlayerID] = {};
end
if CQUI_HousingUpdated[PlayerID] == nil then
CQUI_HousingUpdated[PlayerID] = {};
end
CQUI_HousingFromImprovementsTable[PlayerID][pCityID] = CQUI_HousingFromImprovements;
CQUI_HousingUpdated[PlayerID][pCityID] = true;
LuaEvents.CQUI_RealHousingFromImprovementsCalculated(pCityID, CQUI_HousingFromImprovements);
end
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements * 0.5;
if CQUI_HousingFromImprovementsTable[PlayerID] == nil then
CQUI_HousingFromImprovementsTable[PlayerID] = {};
end
if CQUI_HousingUpdated[PlayerID] == nil then
CQUI_HousingUpdated[PlayerID] = {};
end
CQUI_HousingFromImprovementsTable[PlayerID][pCityID] = CQUI_HousingFromImprovements;
CQUI_HousingUpdated[PlayerID][pCityID] = true;
LuaEvents.CQUI_RealHousingFromImprovementsCalculated(pCityID, CQUI_HousingFromImprovements);
end

-- ===========================================================================
Expand Down
127 changes: 79 additions & 48 deletions Assets/Expansion2/CityBanners/citybannermanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4391,62 +4391,93 @@ end
-- ===========================================================================
-- CQUI calculate real housing from improvements
function CQUI_RealHousingFromImprovements(pCity, PlayerID, pCityID)
-- CQUI: There is a bug that shares housing from improvements for cities with the same IDs. So this bug is also added to the mod and will be removed after it will be fixed by developers.
local x, y = pCity:GetX(), pCity:GetY();
local CQUI_ID_BuggedTable = {};
for i = -3, 3 do
if i ~= 0 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + i, y) );
end
if i ~= 3 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y + 1) );
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y - 1) );
end
if i ~= -3 and i ~= 3 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + i, y + 2) );
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + i, y - 2) );
end
if i ~= -3 and i <=1 then
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y + 3) );
table.insert( CQUI_ID_BuggedTable, Map.GetPlot(x + y % 2 + i, y - 3) );
end
end

local CQUI_HousingFromImprovements = 0;
local kCityPlots :table = Map.GetCityPlots():GetPurchasedPlots(pCity);
if kCityPlots ~= nil then
for _, plotID in pairs(kCityPlots) do
local kPlot :table = Map.GetPlotByIndex(plotID);
if Map.GetPlotDistance( pCity:GetX(), pCity:GetY(), kPlot:GetX(), kPlot:GetY() ) <= 3 then
local eImprovementType :number = kPlot:GetImprovementType();
if eImprovementType ~= -1 then
if not kPlot:IsImprovementPillaged() then
local kImprovementData = GameInfo.Improvements[eImprovementType].Housing;
if kImprovementData == 1 then -- farms, pastures etc.
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 1;
elseif kImprovementData == 2 then -- stepwells, kampungs, mekewaps, golf courses
if GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_STEPWELL" then -- stepwells
local CQUI_PlayerResearchedSanitation :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_SANITATION"].Index); -- check if a player researched Sanitation
if not CQUI_PlayerResearchedSanitation then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_KAMPUNG" then -- kampungs
local CQUI_PlayerResearchedMassProduction :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_MASS_PRODUCTION"].Index); -- check if a player researched Mass Production
if not CQUI_PlayerResearchedMassProduction then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_MEKEWAP" then -- mekewaps
local CQUI_PlayerResearchedCivilService :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_CIVIL_SERVICE"].Index); -- check if a player researched Civil Service
if not CQUI_PlayerResearchedCivilService then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_GOLF_COURSE" then -- golf courses
local CQUI_PlayerResearchedGlobalization :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_GLOBALIZATION"].Index); -- check if a player researched Globalization
if CQUI_PlayerResearchedGlobalization then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
end
for _, kPlot in pairs(CQUI_ID_BuggedTable) do
local kPlotCity = Cities.GetPlotPurchaseCity(kPlot);
local kPlotCityID;
if kPlotCity ~= nil then
kPlotCityID = kPlotCity:GetID();
end
if kPlotCityID == pCityID then
local eImprovementType :number = kPlot:GetImprovementType();
if eImprovementType ~= -1 then
if not kPlot:IsImprovementPillaged() then
local kImprovementData = GameInfo.Improvements[eImprovementType].Housing;
if kImprovementData == 1 then -- Farms, Fishing Boats, Pastures, Plantations, Camps
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 1;
elseif kImprovementData == 2 then -- Stepwells, Kampungs, Mekewaps, Cahokia Mounds
if GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_STEPWELL" then -- Stepwells
local CQUI_PlayerResearchedSanitation :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_SANITATION"].Index); -- check if a player researched Sanitation
if not CQUI_PlayerResearchedSanitation then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_KAMPUNG" then -- Kampungs
local CQUI_PlayerResearchedMassProduction :boolean = Players[Game.GetLocalPlayer()]:GetTechs():HasTech(GameInfo.Technologies["TECH_MASS_PRODUCTION"].Index); -- check if a player researched Mass Production
if not CQUI_PlayerResearchedMassProduction then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_MEKEWAP" then -- Mekewaps
local CQUI_PlayerResearchedCivilService :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_CIVIL_SERVICE"].Index); -- check if a player researched Civil Service
if not CQUI_PlayerResearchedCivilService then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
else -- Cahokia Mounds (elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_MOUND" then)
local CQUI_PlayerResearchedCivilService :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_CULTURAL_HERITAGE"].Index); -- check if a player researched Cultural Heritage
if not CQUI_PlayerResearchedCivilService then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
else
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
end
end
elseif kImprovementData == 4 then -- Seasteads
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 4;
elseif GameInfo.Improvements[eImprovementType].ImprovementType == "IMPROVEMENT_GOLF_COURSE" then -- Golf Courses (kImprovementData == 0)
local CQUI_PlayerResearchedGlobalization :boolean = Players[Game.GetLocalPlayer()]:GetCulture():HasCivic(GameInfo.Civics["CIVIC_GLOBALIZATION"].Index); -- check if a player researched Globalization
if CQUI_PlayerResearchedGlobalization then
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements + 2;
end
end
end
end
end
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements * 0.5;
if CQUI_HousingFromImprovementsTable[PlayerID] == nil then
CQUI_HousingFromImprovementsTable[PlayerID] = {};
end
if CQUI_HousingUpdated[PlayerID] == nil then
CQUI_HousingUpdated[PlayerID] = {};
end
CQUI_HousingFromImprovementsTable[PlayerID][pCityID] = CQUI_HousingFromImprovements;
CQUI_HousingUpdated[PlayerID][pCityID] = true;
LuaEvents.CQUI_RealHousingFromImprovementsCalculated(pCityID, CQUI_HousingFromImprovements);
end
CQUI_HousingFromImprovements = CQUI_HousingFromImprovements * 0.5;
if CQUI_HousingFromImprovementsTable[PlayerID] == nil then
CQUI_HousingFromImprovementsTable[PlayerID] = {};
end
if CQUI_HousingUpdated[PlayerID] == nil then
CQUI_HousingUpdated[PlayerID] = {};
end
CQUI_HousingFromImprovementsTable[PlayerID][pCityID] = CQUI_HousingFromImprovements;
CQUI_HousingUpdated[PlayerID][pCityID] = true;
LuaEvents.CQUI_RealHousingFromImprovementsCalculated(pCityID, CQUI_HousingFromImprovements);
end

-- ===========================================================================
Expand Down
Loading