How to Prevent Cargo Promotion Stacking?

sman1975

Emperor
Joined
Aug 27, 2016
Messages
1,370
Location
Dallas, TX
Hello,

The mod I'm working on has a group of units - in this case heavy capital ships. I'd like to allow the Battleship to carry 1 "missile" - which doesn't help much until Advanced Ballistics, so it shouldn't break the game. The Battleship will upgrade to the Missile Cruiser which can carry 3 missiles.

To set this up, I would give the Battleship the PROMOTION_CARGO_I promotion, and the Missile Cruiser already has the PROMOTION_CARGO_III promotion from the normal game.

The problem is the Battleship carries the Cargo 1 promotion when upgraded, so Missile Cruisers upgraded from Battleships can carry 4 missiles, but newly built Missile Cruisers will only carry 3.

I'm thinking about changing the "LostWithUpgrade" on the Cargo promotions to TRUE so each unit would start with the same carrying capacity.

Can anyone think of any circumstance where that breaks anything with other units? Or is there a better (preferably non-LUA) method to prevent these cargo promotions stacking?

Thanks!
 
That could work, though the Carrier and Nuclear sub seem to be using those same promotions (but have different SPECIALCARGO defined in the XML, where that special cargo are either nukes or planes).
What you could do is add a new promotion, which functions exactly the same as PROMOTION_CARGO_I but does have the the LostWithUpgrade tag set to true. This prevents any issues with other units, even those that might be added by other modders.
 
Thanks, @Troller0001. I hadn't considered that approach - creating a new series of cargo promotions for "my" units, and leaving the game's original set of cargo promotions alone. This would maximize compatibility in case someone wants to add more mods (that might rely on original cargo promotion behavior) while mine is active. You always seem to have such good suggestions!

Now, it's on to figuring out how to get factories to use either coal or oil.... :crazyeye:
 
Now, it's on to figuring out how to get factories to use either coal or oil.... :crazyeye:
Two same de facto building with coal/oil requirement. Then having a MutuallyExclusiveGroup attached to those buildings.
 
Two same de facto building with coal/oil requirement. Then having a MutuallyExclusiveGroup attached to those buildings.

You really only want one factory, due to the XBuiltTriggersIdeologyChoice element in the factory's definition. I don't even want to think about how to use two buildings contributing to that...

So, I was thinking of creating a "Oil Generator Station" and a "Coal Generator Station" - either of which would be a prereq for the factory. These buildings would be the ones that required resources to build - would be cheap to build so as not to slow things down too much.

The problem is with the Building_ClassesNeededInCity table - if there are two BuildingClassType entries for the same BuildingType, the game sees those as an AND relationship, requiring both Generator Stations as a prereq.

I thought about putting both Generator Stations into a single class that has no default building, but it's hard to structure the overrides if someone decides to add non-standard civs. I'm sure there's a SQL statement with the correct wildcards that would do this (assuming my mod loads last), but I haven't had time to research this enough. I'm really not even sure if the game allows two buildings in the same class available to all players.

I've seen a thread discussing this, but the solution seemed to require LUA:

https://forums.civfanatics.com/threads/or-requirements-for-buildings.543711/

The problem is, it sounds like using LUA would require replacing the city build UI - which other mods like to do as well - which limits compatibility of my mod with others. Avoiding this is preferable, I think.

I wonder if I can add the Factory to the city if I use the "FreeBuildingThisCity" element? Allow a player to build either Generator Station, and that will "give" the Factory to the city? Of course, I'd have to make the Generator Stations cost more than the factory - and make them mutually exclusive. Hmmm... Will have to do some testing on this...

Was hoping someone out there had already solved this so I wouldn't have to - especially one that doesn't require CityCanConstruct.

Guess I'll need to open a different thread on this - it's turning into a bit of a headache.... :wallbash:
 
Last edited:
Actually, after more research (but not testing), it seems the Generator Stations would have to be the buildings that add all the production. The factory would need to become an almost dummy building. Prevents a player from building the Generator Station, then getting the factory and then selling the Generator Station and reclaiming the coal/oil. Would also need to change both generator buildings and factory to "never capture" and "nuke immune" so there wouldn't be a situation where the factory survives city capture/nuking while the Generator Stations did not - i.e. no free factories...

Will test later today and post results.....
 
Last edited:
There's code in Enlightenment Era that allows for OR building prereqs; it reduces the matter down to just making insertions into a table.
 
I checked the code and you're right: enlightenment era does allow this, and fortunately without involving the production pop up. Will test it tomorrow.

Thanks for the suggestion!
 
On further review, I still have the same basic problem with the EE code - the relationship between the Factory and it's supporting (either oil or coal) Generator Station. If I use the EE building prereq OR code, I would still be able to sell the generator and reclaim the resource and still keep the factory. I'm still wanting to keep only 1 Factory type, so as to prevent the complicated issue of XBuiltTriggersIdeologyChoice (3 factories trigger Ideology - with more than 1 factory type, this gets tricky).

So, after a bit of thinking... (no laughs please!) I think my plan is:
- keep the normal factory (and it alone will be used with XBuiltTriggersIdeologyChoice)
- Introduce a new Oil Factory (prereq tech Replaceable Parts) - but it has nothing to do with Ideology. It also has similar costs/production bumps as the normal Factory. It would also be buildable in a city without a factory.
- Use the EE code to allow either the Factory or Oil Factory to be the prereq for the Solar Plant, Nuclear Plant, and Spaceship Factories

The last bullet may be not needed. The mod I'm working on introduces 75 new buildings. I could probably find new prereq candidates for those 3 buildings so the OR function wouldn't be needed.

Ugh. So much discussion. "A long climb for a short slide" we used to call it.... :lol:

Thanks everyone for the suggestions!
 
Last edited:
Alt ofc you could just remove the maintenance costs from the prereq buildings so that they can't be sold...
 
Top Bottom