Please help me solve an sql problem!

anansethespider

Warlord
Joined
Oct 27, 2016
Messages
288
I want to add a new district to the game that requires adjacency to an existing district, in much the same fashion as wonders like the Great Library require campus adjacency. Just so we're not speaking in abstracts, lets say I am trying to add a district called Jeweler's Quarter that requires adjacency to a commercial hub.

I added the Jeweler's Quarter to the game with xml, copied icons and artdefs. That was all easy enough. But the problem began when I started trying to give it that requirement of an existing commercial hub. You see, the sql table that defines what districts can and can't do does not have any column for AdjacentDistricts or PrereqDistricts. So when you copy over those commands from a Wonder, they do nothing at all.

I thought I could around this by editing the 01_GameplaySchema.sql file, which defines the tables in the game including Districts. Here's the code I added to the table:

(-----under TABLE Districts)

"AdjacentDistrict" TEXT,
"PrereqDistrict" TEXT,

FOREIGN KEY (PrereqDistrict) REFERENCES Districts(DistrictType) ON DELETE SET DEFAULT ON UPDATE SET DEFAULT,
FOREIGN KEY (AdjacentDistrict) REFERENCES Districts(DistrictType) ON DELETE SET DEFAULT ON UPDATE SET DEFAULT,


(----at the bottom of the file)

INSERT INTO NavigationProperties("BaseTable", "PropertyName", "TargetTable", "IsCollection", "Query") VALUES("Districts", "AdjacentDistrictReference", "Districts", 0,"SELECT T1.rowid from Districts as T1 inner join Districts as T2 on T2.AdjacentDistrict = T1.DistrictType where T2.rowid = ? ORDER BY T1.rowid ASC LIMIT 1");

INSERT INTO NavigationProperties("BaseTable", "PropertyName", "TargetTable", "IsCollection", "Query") VALUES("Districts", "PrereqDistrictReference", "Districts", 0,"SELECT T1.rowid from Districts as T1 inner join Districts as T2 on T2.PrereqDistrict = T1.DistrictType where T2.rowid = ? ORDER BY T1.rowid ASC LIMIT 1");


And with this combination of code the game runs stable, which is to say it doesn't crash, but neither the adjacency requirement nor district prerequisites have any effect. This leads me to believe I am writing the code correctly, but misunderstanding something fundamental about what needs to be done. I would really appreciate any help or guidance from more experienced modders, and thank you in advance :)


edit, in case it helps, here's the relevant part of code for the modded district from the xml file:

<Row DistrictType="DISTRICT_JEWELERY" Name="LOC_DISTRICT_JEWELERY_NAME" Description="LOC_DISTRICT_JEWELERY_DESCRIPTION" PrereqTech="TECH_CURRENCY" PlunderType="PLUNDER_GOLD" PlunderAmount="50" AdvisorType="ADVISOR_GENERIC" Cost="100" CostProgressionModel="COST_PROGRESSION_NUM_UNDER_AVG_PLUS_TECH" CostProgressionParam1="25" RequiresPlacement="true" RequiresPopulation="true" PrereqDistrict="DISTRICT_COMMERCIAL_HUB" AdjacentDistrict="DISTRICT_COMMERCIAL_HUB" Aqueduct="false" NoAdjacentCity="false" InternalOnly="false" ZOC="false" TradeRouteCapacity="1" CaptureRemovesBuildings="false" CaptureRemovesCityDefenses="false" MilitaryDomain="NO_DOMAIN" TravelTime="3" CityStrengthModifier="2"/>
 
I think you might have posted in the wrong subforum. This is Civ 5 C&C.
(Unless I missed a major mod which adds districts to civ V of course :p)

(I've asked a mod to move this :))


EDIT: Post got moved
 
Last edited:
I literally reposted it there 2 mins before you moved it :/

Please delete the other one?
 
Last edited:
I'm still having no progress with this at all. It's super frustrating! Has anyone been able to successfully add a new column to an SQL table and reference it in the XML? Pretty much any example of this would be enough for me to learn from if I could find it.
 
You see, the sql table that defines what districts can and can't do does not have any column for AdjacentDistricts or PrereqDistricts.
This realisation should already tell you what you need to know: It doesn't work. A wonder can have such requirements, PrereqDistrict is for buildings, they all need to be built inside a certain district, AdjacentDistrict is for wonders that need to be next to one. Since both wonders and buildings are in the same table it might be possible to add an AdjacentDistrict requirement to a normal building - I just doubt it would work though, that functionality is probably not coded in.
Only what you are trying to do definitely can't work, you can't fill a column that doesn't exist, and even if you could add a column, without any functionality coded for it, nothing will happen.
 
Last edited:
Back
Top Bottom