Mine adjacency bonus - similar to farms

kaspergm

Deity
Joined
Aug 19, 2012
Messages
5,829
So, I wanted to do an experiment which I thought was quite simple. I wanted to make a two-fold change:
  • Mines don't get auto-bonus yields when teching up, but instead get adjacency bonus similar to how farms work (+1 production for every two mines with Apprenticeship, +1 production for every mine with Industrialization)
  • Further, upon researching Industrialization, you are allowed to build mines on flat grassland and plains
I tried to mirror the lines for the farms, but changing into production instead and substituting for suitable techs. However, game instantly crashes when I try to found my first city, so ... something must be wrong. :undecide: The database.log file doesn't give me any errors, however.

Have anybody tried something like this, and/or know if this is possible and just because I'm doing something wrong?
 
Can you post your code?

Here are the relevant fields for farm adjacency as far as I can tell. If you mirror these more or less directly and insert into the right tables I think it should work.

upload_2017-1-9_6-33-24.png
 
Thanx for your reply, I'll post here the changes I did to the file. Highlighted parts are lines I added. I've added a couple of comments here, they're in blue.

Spoiler :

<Improvement_Adjacencies>
<Row ImprovementType="IMPROVEMENT_FARM" YieldChangeId="Farms_MedievalAdjacency"/>
<Row ImprovementType="IMPROVEMENT_FARM" YieldChangeId="Farms_MechanizedAdjacency"/>
<Row ImprovementType="IMPROVEMENT_MINE" YieldChangeId="Mines_MedievalAdjacency"/>
<Row ImprovementType="IMPROVEMENT_MINE" YieldChangeId="Mines_IndustrialAdjacency"/>


(...)

<Improvement_ValidTerrains>
<Row ImprovementType="IMPROVEMENT_FARM" TerrainType="TERRAIN_PLAINS"/>
<Row ImprovementType="IMPROVEMENT_FARM" TerrainType="TERRAIN_GRASS"/>
<Row ImprovementType="IMPROVEMENT_FARM" TerrainType="TERRAIN_PLAINS_HILLS" PrereqCivic="CIVIC_CIVIL_ENGINEERING"/>
<Row ImprovementType="IMPROVEMENT_FARM" TerrainType="TERRAIN_GRASS_HILLS" PrereqCivic="CIVIC_CIVIL_ENGINEERING"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_GRASS_HILLS"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_PLAINS_HILLS"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_DESERT_HILLS"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_TUNDRA_HILLS"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_SNOW_HILLS"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_PLAINS" PrereqTech="TECH_INDUSTRIALIZATION"/>
<Row ImprovementType="IMPROVEMENT_MINE" TerrainType="TERRAIN_GRASS" PrereqTech="TECH_INDUSTRIALIZATION"/>


(...)

<Improvement_BonusYieldChanges>
<Row Id="6" ImprovementType="IMPROVEMENT_MINE" YieldType="YIELD_PRODUCTION" BonusYieldChange="0" PrereqTech="TECH_APPRENTICESHIP"/>
<Row Id="7" ImprovementType="IMPROVEMENT_MINE" YieldType="YIELD_PRODUCTION" BonusYieldChange="0" PrereqTech="TECH_INDUSTRIALIZATION"/>

NOTE: Changed these to zero instead of deleting the lines, because I figured the ID numbers might cause trouble if they were deleted. But the crash still happens even when I changed the numbers back to 1 just to test if this was the cause, so there is another problem.


(...)

<Adjacency_YieldChanges>
<Row ID="Farms_MedievalAdjacency" Description="Placeholder" YieldType="YIELD_FOOD" YieldChange="1" TilesRequired="2" AdjacentImprovement="IMPROVEMENT_FARM" PrereqCivic="CIVIC_FEUDALISM" ObsoleteTech="TECH_REPLACEABLE_PARTS"/>
<Row ID="Farms_MechanizedAdjacency" Description="Placeholder" YieldType="YIELD_FOOD" YieldChange="1" TilesRequired="1" AdjacentImprovement="IMPROVEMENT_FARM" PrereqTech="TECH_REPLACEABLE_PARTS"/>
<Row ID="Mines_MedievalAdjacency" Description="Placeholder" YieldType="YIELD_PRODUCTION" YieldChange="1" TilesRequired="2" AdjacentImprovement="IMPROVEMENT_MINE" PrereqTech="TECH_APPRENTICESHIP" ObsoleteTech="TECH_INDUSTRIALIZATION"/>
<Row ID="Mines_IndustrialAdjacency" Description="Placeholder" YieldType="YIELD_PRODUCTION" YieldChange="1" TilesRequired="1" AdjacentImprovement="IMPROVEMENT_MINE" PrereqTech="TECH_INDUSTRIALIZATION"/>


(...)



NOTE: I'm a bit uncertain whether the following parts actually needs to be added - the farm part could very well just relate to the Steppwell bonus? I tried to remove this part to see if this was what caused the crash, but the crash still happens with/without this part.


<RequirementSets>
<Row>
<RequirementSetId>PLOT_ADJACENT_TO_FARM_REQUIREMENTS</RequirementSetId>
<RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
</Row>
<Row>
<RequirementSetId>PLOT_ADJACENT_TO_MINE_REQUIREMENTS</RequirementSetId>
<RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
</Row>


(...)

<RequirementArguments>
<Row>
<RequirementId>REQUIRES_PLOT_ADJACENT_TO_FARM</RequirementId>
<Name>ImprovementType</Name>
<Value>IMPROVEMENT_FARM</Value>
</Row>
<Row>
<RequirementId>REQUIRES_PLOT_ADJACENT_TO_MINE</RequirementId>
<Name>ImprovementType</Name>
<Value>IMPROVEMENT_MINE</Value>
</Row>


<RequirementSetRequirements>
<Row>
<RequirementSetId>PLOT_ADJACENT_TO_FARM_REQUIREMENTS</RequirementSetId>
<RequirementId>REQUIRES_PLOT_ADJACENT_TO_FARM</RequirementId>
</Row>
<Row>
<RequirementSetId>PLOT_ADJACENT_TO_MINE_REQUIREMENTS</RequirementSetId>
<RequirementId>REQUIRES_PLOT_ADJACENT_TO_MINE</RequirementId>
</Row>


 
Last edited:
I think it is related to the PrereqTech usage in the ValidTerrain table. Change it to a Civic using the PrereqCivic.

When working on putting farms on Tundra, I discovered that PrereqTech does not work in that table. Now, I didn't try it for every terrain/improvement, but it caused a crash for me as well.

Also note, you cannot put improvements on Mountains, even if they are workable. You can do it in the DB, and the game does not crash, but the buttons do not show up on those terrains.
 
Last edited:
It's hard for me to say but my first guess on why this would crash is that you're inserting the Mines_MedievalAdjacency object into Improvement_Adjacencies before you create it in Adjacency_YieldChanges.

Is this the same order they appear in XML? I admit using the XML is challenging for me. I use SQL exclusively, precisely so I can test it before loading it into the game.

The SQL for this would be this, in this order:

First inserting the new adjacency into Adjacency_YieldChanges
Code:
INSERT INTO Adjacency_YieldChanges
    (ID,                Description,    YieldType,        YieldChange,    TilesRequired,    AdjacentImprovement)
VALUES ('Mines_MedievalAdjacency',     'Placeholder', 'YIELD_PRODUCTION',     '1',         '3',         'IMPROVEMENT_MINE') ;

The associate the new object with mines:

Code:
INSERT INTO Improvement_Adjacencies
    (ImprovementType,     YieldChangeId)
VALUES    ('IMPROVEMENT_MINE',    'Mines_MedievalAdjacency') ;


As a reminder, in a relational database, a record has to exist before you use a lookup table like Improvement_Adjacencies. Improvement_Adjancencies only function is to associate an Adjancency_YieldChange object with an Improvement (hence the name of the table). If either of those two object doesn't exist before you try to do that, game will crash. At least in SQL. I assume XML works basically the same.
 
I think it is related to the PrereqTech usage in the ValidTerrain table. Change it to a Civic using the PrereqCivic.

When working on putting farms on Tundra, I discovered that PrereqTech does not work in that table. Now, I didn't try it for every terrain/improvement, but it caused a crash for me as well.

Also note, you cannot put improvements on Mountains, even if they are workable. You can do it in the DB, and the game does not crash, but the buttons do not show up on those terrains.
This seems to be the issue. At least now I can settle a city. Now I have to test whether the rest of it works.

It's hard for me to say but my first guess on why this would crash is that you're inserting the Mines_MedievalAdjacency object into Improvement_Adjacencies before you create it in Adjacency_YieldChanges.

Is this the same order they appear in XML?
Yeah, since no modding tool has come out yet, I'm just doing a few minor things by writing them directly into the game file, so everything is in the order it appears in the file.
 
Well ... now it crashes on turn 3 (probably when the first AI tries to build a mine?), so ... something's still not good. :cry:
 
I hate to say it, but I tried to add something similar to this, but with forests adjacency, but it didn't work. I don't recall if it was crashing or what, I didn't spend a lot of time looking into it. Check Database.log and gameffects.log. Database.log teh errors should be obvious, in GameEffects.log look for things that start with Warning:

Sorry I couldn't be more help on this one, but like isau, I do all of my changes in SQL. It's easier for me to read, and I can test it before I put it in effect.
 
Pretty sure the error is not with the coding (although I hope I'm wrong), but apparently some of this is not supported on a deeper level. At least, no matter how I try to turn on/off the changes I have doubts about, I get the crash consistently at turn 3. So until someone proves me wrong my conclusion is that this is not supported by core game.
 
I didn't use all of the code, just tested with the SQL lines I posted earlier that handled adjacencies. I am able to make the adjacency bonuses work. I didn't test it with the Prereq set, but I don't think there should be a problem there because I've used prereqs a few times myself and they function.

Important note about Adjacency Bonuses by the way. For some reason I have never understood they don't seem to reload when you update the mod. You have to exit the game complete (as in close Civ 6 to the desktop) and relaunch it. It's the only thing I've encountered that works that way and I don't know why. Drove me batty when I was testing adjacency bonuses in my mod. (Or it's possible I am just paranoid.)

Before and after below:

20170109113227_1.jpg

20170109113233_1.jpg
 
Ok I just converted the second part of the code. I can confirm that adding a PrereqTech to the improvement crashes the game. The column exists in the database, but no improvement actually uses it.

The code below does work without crashes, and allows you to place mines on grass or plains:

Code:
INSERT INTO Improvement_ValidTerrains
                  (ImprovementType, TerrainType)
VALUES    ('IMPROVEMENT_MINE', 'TERRAIN_PLAINS'),
                   ('IMPROVEMENT_MINE', 'TERRAIN_GRASS');

I can't think of a way off hand to make this unlock work correctly. One option of course is to duplicate the Mine and insert a whole new copy of it that can be built only on Grass and Plains, but that requires a lot of work. I couldn't find a Modifier that unlocks improvement/terrain relationships. There could be one out there of course.
 
Thanx for the help guys. I did come as far as to conclude that the crash was in fact not caused by the whole mine thing, but by another small change I did (which I thought was not a problem because I did it during an old game, but apparently it causes problem when starting a new game, duh! :cringe:). So now I'm looking into the mine thing again. :crazyeye:
 
Important note about Adjacency Bonuses by the way. For some reason I have never understood they don't seem to reload when you update the mod. You have to exit the game complete (as in close Civ 6 to the desktop) and relaunch it. It's the only thing I've encountered that works that way and I don't know why. Drove me batty when I was testing adjacency bonuses in my mod. (Or it's possible I am just paranoid.)
Perhaps that is why I never got the one I was doing to work., Interesting, i guess I will try it again.

I can't think of a way off hand to make this unlock work correctly. One option of course is to duplicate the Mine and insert a whole new copy of it that can be built only on Grass and Plains, but that requires a lot of work. I couldn't find a Modifier that unlocks improvement/terrain relationships. There could be one out there of course.

Yeah, you can only use Civics, which blows, hopefully it will be fixed in the future.
 
Perhaps that is why I never got the one I was doing to work., Interesting, i guess I will try it again.


If you have problems with the SQL feel free to share. I've written in the neighborhood of 12 or so adjacency bonuses and even have one tied to a Leader modifier set up for Natural Wonders, which took some doing since those can be added with DLC.
 
I will if I have a problem again. The code I wrote is long gone, and was done when I first started making my mod. So it could also be my understanding fo things is better. I'll let you know when I give it a try. Thank you.
 
Back
Top Bottom