• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

[GS] [SOLVED] Apply Petra Bonus To All Cities

racha

Prince
Joined
Jul 27, 2013
Messages
335
Location
Over there --->
Prior to GS, I had Petra happily applying its yield bonuses to all of the cities owned by the player who controlled Petra's city. With the odd changes they made to the modifiers in GS this stopped working and I haven't been able to get it working again.

I've tried removing all references to REQUIRES_CITY_HAS_PETRA, and I've also tried completely removing everything to do with the all Petra modifiers (and their requirements) and then re-adding my own similar ones. Neither method has worked and both result in Petra not giving bonuses at all, even in the city it's build in.

Does anyone know how I can make my desert cities fun again?
 
Here's a look at how Petra is currently set up (I used the database query at the top to produce results at the bottom):

upload_2019-4-13_13-34-31.png



MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD has a scope of one city. There are a few ways to get this to apply to all cities. But perhaps the easiest would be to add an MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER (which attaches a Modifier to every city a player owns) and add that to the Building instead of the current modifier.


Code:
-- This Modifier will attach to all cities the player owns
INSERT INTO Modifiers
  (ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId)
VALUES ('MYMODIFIER_PETRA_YIELD_MODIFIER_PLAYER', 'MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER', 0, 0, NULL,NULL) ;

-- In the arguments, we add the Modifier we want to apply to all cities (the original Modifier attached to Petra)
INSERT INTO ModifierArguments
  (ModifierId,    Name,   Type,    Value,    Extra,  SecondExtra)
VALUES ('MYMODIFIER_PETRA_YIELD_MODIFIER_PLAYER',  'ModifierId',  'ARGTYPE_IDENTITY',  'PETRA_YIELD_MODIFIER',   NULL,  NULL);

-- Delete the Modifier currently attached to Petra
DELETE FROM BuildingModifiers WHERE BuildingType='BUILDING_PETRA' AND ModifierId='PETRA_YIELD_MODIFIER';

-- Add our new Modifier
INSERT INTO BuildingModifiers
  (BuildingType, ModifierId)
VALUES ('BUILDING_PETRA','MYMODIFIER_PETRA_YIELD_MODIFIER_PLAYER');
 
Thank-you very much, this works like a charm! :goodjob:

Now I just have to wrap my head around why your code works and my long-winded approach didn't. :confused:
 
Thank-you very much, this works like a charm! :goodjob:

Now I just have to wrap my head around why your code works and my long-winded approach didn't. :confused:


Probably the reason your code didn't work is related to the CollectionType of the Modifier type, which defines its scope. I'm not familiar with how Petra used to be coded, but from what you described it sounds like it might have been a Global Modifier that applied to all cities in the game and used a RequirementSet to detect the city with Petra. Removing the RequirementSet in that situation would make it apply to all cities.

The Petra that exists in Gathering Storm uses a Modifier with a CollectionType of just that one city.

CollectionTypes are defined in the DynamicModifiers table. The CollectionType used by the ModifierType MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD is COLLECTION_CITY_PLOT_YIELDS.
 
Probably the reason your code didn't work is related to the CollectionType of the Modifier type, which defines its scope. I'm not familiar with how Petra used to be coded, but from what you described it sounds like it might have been a Global Modifier that applied to all cities in the game and used a RequirementSet to detect the city with Petra. Removing the RequirementSet in that situation would make it apply to all cities.

The Petra that exists in Gathering Storm uses a Modifier with a CollectionType of just that one city.

CollectionTypes are defined in the DynamicModifiers table. The CollectionType used by the ModifierType MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD is COLLECTION_CITY_PLOT_YIELDS.
Vanilla did just that for both Petra (I'm pretty sure) and Chicken Pizza (I know for a fact):apply the modifier to all cities everywhere, and then requirement that the city have the building. Funny part was that the simpler method was always available, but it took a couple of Xpacs before someone at Firaxis realized how unecessarily round-about that method was. I guess that's what happens when you just copy/paste/edit to get something working and don't think through what you are actually loading into the game.

I copied the Chichtzen Itza code from the original Vanilla files and used it as a template for a world wonder in one of my mods. And then studied the code some more. And asked whyever for this roundabout method ? and then re-wrote the code to use the simpler method (assuming it would not work because Firaxis) but ta-da! the simpler method worked just fine. Scratched my head over that one for quite a while before I realized they must have copy-pasted parts of the code from one of the Beliefs and then edited as needed to adapt to a Building.
 
Vanilla did just that for both Petra (I'm pretty sure) and Chicken Pizza (I know for a fact):apply the modifier to all cities everywhere, and then requirement that the city have the building. Funny part was that the simpler method was always available, but it took a couple of Xpacs before someone at Firaxis realized how unecessarily round-about that method was. I guess that's what happens when you just copy/paste/edit to get something working and don't think through what you are actually loading into the game.

I copied the Chichtzen Itza code from the original Vanilla files and used it as a template for a world wonder in one of my mods. And then studied the code some more. And asked whyever for this roundabout method ? and then re-wrote the code to use the simpler method (assuming it would not work because Firaxis) but ta-da! the simpler method worked just fine. Scratched my head over that one for quite a while before I realized they must have copy-pasted parts of the code from one of the Beliefs and then edited as needed to adapt to a Building.


Was there a COLLECTION_CITY_PLOT_YIELDS in Vanilla? I can't remember. I barely knew what CollectionTypes were back then. My first attempts at modding resulted in accidentally applying Modifiers to ALL cities in the game rather than just the player's.
 
Yup. So far as I know it hasn't been alterred in effect-type, and is still used in this dynamic modifier
Code:
		<Row>
			<ModifierType>MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD</ModifierType>
			<CollectionType>COLLECTION_CITY_PLOT_YIELDS</CollectionType>
			<EffectType>EFFECT_ADJUST_PLOT_YIELD</EffectType>
		</Row>
 
Back
Top Bottom