Using GameConfiguration Values in Ingame SQL/XML

zzragnar0kzz

Chieftain
Joined
May 2, 2021
Messages
22
There are a few places in the Frontend configuration where database queries can vary depending on the value(s) of one or more GameConfiguration settings. Take the following examples from SetupParameters.xml, which together define the range of the City-States slider:
Code:
<Queries>
 <Row QueryId="CityStateCountRange" SQL="SELECT 'CityStateCountRange' AS Domain, ?1 AS MinimumValue, ?2 AS MaximumValue LIMIT 1"/>
</Queries>

Code:
<QueryParameters>
 <Row QueryId="CityStateCountRange" Index="1" ConfigurationGroup="Map" ConfigurationId="MAP_MIN_MINOR_PLAYERS"/>
 <Row QueryId="CityStateCountRange" Index="2" ConfigurationGroup="Map" ConfigurationId="MAP_MAX_MINOR_PLAYERS"/>
</QueryParameters>

In ENWS, I use similar code for the Natural Wonder slider, with some alterations to cap the maximum value to the lesser of two values, as follows:
Code:
INSERT INTO Queries (QueryId, SQL)
VALUES
    ('StandardNaturalWonderCountRange', 'SELECT ''StandardNaturalWonderCountRange'' AS Domain, ?1 AS MinimumValue, (SELECT CASE WHEN (SELECT Count(*) FROM NaturalWonders WHERE Domain = ''StandardNaturalWonders'') < ?2 THEN (SELECT Count(*) FROM NaturalWonders WHERE Domain = ''StandardNaturalWonders'') ELSE ?2 END) AS MaximumValue LIMIT 1');

Code:
<QueryParameters>
  <Row QueryId="StandardNaturalWonderCountRange" Index="1" ConfigurationGroup="Map" ConfigurationId="MAP_MIN_NATURAL_WONDERS"/>
  <Row QueryId="StandardNaturalWonderCountRange" Index="2" ConfigurationGroup="Map" ConfigurationId="MAP_MAX_NATURAL_WONDERS"/>
</QueryParameters>

Is there any way to do something similar in the Ingame database? Specifically, when updating table T, if a particular GameConfiguration setting S = 1, then set column C = X; if S != 1, then set C = Y. Substituting the GameConfiguration setting directly in the query unsurprisingly doesn't seem to work, and there doesn't appear to be any mechanism in that database similar to the way the above-referenced tables work together to produce variable queries.

Using <Criteria> and <UpdateDatabase> tags with corresponding files in the .modinfo file, it is possible to simulate the behavior I'm looking for, like so:
Code:
<ActionCriteria>
  <Criteria id="Dummy_Setting_Enabled" any="1">
    <ConfigurationValueMatches>
      <ConfigurationId>DUMMY_SETTING</ConfigurationId>
      <Group>Game</Group>
      <Value>1</Value>
    </ConfigurationValueMatches>
  </Criteria>
</ActionCriteria>

<InGameActions>
  <UpdateDatabase id="Dummy_Setting_Changes" criteria="Dummy_Setting_Enabled">
    <Properties>
      <LoadOrder>12345</LoadOrder>
    </Properties>
    <File>Path/To/File.sql</File>
  </UpdateDatabase>
</InGameActions>

Here, Path/To/File.sql contains any changes to make to the Ingame DB when DUMMY_SETTING = 1. This solution quickly becomes unwieldy with any more than a handful of GameConfiguration settings, so it's close, but not quite what I'm looking for. Is what I'm looking for even possible?
 
Last edited:
Back
Top Bottom