Why does this work in Vanilla but cause CTD in GS and R&F?

TC_

Chieftain
Joined
Jul 8, 2017
Messages
77
I wanted to make a change to one of my longstanding mods, in order to prevent the AI from producing a unit. I went about it the way I have tackled that problem in other mods - with a dummy building being created for human players via lua, where that building is the prereq for the unit. It is working perfectly fine for me (in a heavily modded vanilla game), but when I uploaded it to the workshop I immediately began receiving messages of how the change broke everyone else's game (players who are using R&F and GS).

Here is the code I added:

LUA
Code:
local iBuilding = GameInfo.Buildings["BUILDING_EXPANSIONIST_UNLOCK"].Index;

function OnCityInitializedTC2(playerID, cityID, x, y)
    
    local pPlayer = Players[playerID];
    local pCity = pPlayer:GetCities():FindID(cityID);
    local cityPlotIndex = Map.GetPlot(pCity:GetX(), pCity:GetY()):GetIndex();
    local cityBuildings = pCity:GetBuildings();
    local cityBuildQ = pCity:GetBuildQueue();
    
    if pPlayer:IsHuman() then
        
        if not cityBuildings:HasBuilding(iBuilding) then               
            
            cityBuildQ:CreateIncompleteBuilding(iBuilding, cityPlotIndex, 100);
        
        end   
  
    elseif    cityBuildings:HasBuilding(iBuilding) then
      
        cityBuildings:RemoveBuilding(iBuilding);
  
    end
end

Events.CityInitialized.Add(OnCityInitializedTC2);

XML
Code:
<GameInfo>
  
  <Types>
      <Row Type="BUILDING_EXPANSIONIST_UNLOCK" Kind="KIND_BUILDING" />
  </Types>
  
  <Buildings>
      <Row BuildingType="BUILDING_EXPANSIONIST_UNLOCK" Name="Expansionist Unlock" Description="Allows human players to create the Expansionist unit." PrereqDistrict="DISTRICT_CITY_CENTER" Cost="1" AdvisorType="ADVISOR_GENERIC" Maintenance="0"/>
  </Buildings>
  
  <BuildingPrereqs>
      <Row Building="BUILDING_EXPANSIONIST_UNLOCK" PrereqBuilding="BUILDING_EXPANSIONIST_UNLOCK"/>
  </BuildingPrereqs>
  
  <CivilopediaPageExcludes>
      <Row SectionId="BUILDINGS" PageId="BUILDING_EXPANSIONIST_UNLOCK" />
  </CivilopediaPageExcludes>

</GameInfo>

Does anything stick out to those familiar with modding for the expansions?

Thanks in advance.
 
In Rise and Fall and Gathering Storm you can no longer set a building to be its own prerequisite.
You can still make two buildings each be the prerequisite for the other, but no third building can use either of these two buildings as a prerequisite.

In your <Buildings> row, set
Code:
InternalOnly="true"
And delete entirely the <BuildingPrereqs> table in your code.
 
Top Bottom