Request for whoward69 concerning dll mod and database

General Tso

Panzer General
Joined
Oct 12, 2007
Messages
1,548
Location
U. S. of A.
Would it be possible to allow in game changes (via Lua) to the database that would be recognized by a modified dll. For example MIN_CITY_RANGE in GlobalDefines appears to only be accessed in the DLL. I would like to have the option within Lua (during the Advanced Setup Screen) to change this value.

It would be awesome if this functionality was available in a modded DLL that didn't change game play in any other way (unless the other changes where optional). The best method would be to change the way the database works so that all values could be changed by Lua. Unfortunately I'm guessing that it would be beyond the scope of a mod. If that's the case would you have any interest in creating a mod that would allow Lua access to certain database objects? If such a thing is possible and you are interested, perhaps you could start a request thread for possible database items that could be included in the mod.

I know that this is a big request but I thought I'd try seeing if it's possible and if you are interested. If you're not, no problem - I understand we all have a limited amount of time for modding.
 
I though the database *could* be changed from Lua pre-game start - which is how you can change the Playable/AIPlayable state of civs in your Really Adv Setup mod in the "I don't want this civ to appear" drop-down.

Edit: Ummm, or are the Defines handled differently ...

To change the values post-game start would need a lot of Lua setters writing, not hard just very, very tedious (especially as I'm used to an environment - Eclipse - where you can click a few buttons and get this done automatically!)
 
Just tried it. On the Main Menu screen, in FireTuner, choose the Lua Context as MainMenu and execute

Code:
for row in DB.Query("UPDATE Defines SET Value=8 WHERE Name='MIN_CITY_RANGE'") do end

Start/Load a game and then from WorldView do

Code:
print(GameDefines.MIN_CITY_RANGE)

and you get 8, not 3
 
Really? I'll have to check it out! Will the dll understand whats happening?
 
Cool. Your suggestion worked for the most part. I tried testing this on my own several weeks ago. I don't remember exactly what I did but it didn't work. I must have done something wrong.

The only thing that didn't work with your suggestion was the hover help for the settler's build button (lower left side of the screen) - it still showed the original value. If that's done in Lua I should be able to solve that problem. I have to try and find that when I have more time.

Thanks for the help.
 
It's because it's hard coded into the text files

Code:
<Row Tag="TXT_KEY_MISSION_BUILD_CITY_DISABLED_HELP">
  <Text>Cannot found a City within 4 Tiles of another City.</Text>
</Row>
 
Thanks. That should be easy to fix.
 
You can change the defines during the setup screen, but the problem arise when you try to load a game: supposing you're still using a modded custom screen to load the game so you can change the define here again, how would you know what value was used initially with that specific save ?
 
Is Modding.OpenUserData(name, version) available pre-game?

To answer my own question - yes

Code:
[ Lua State = AdvancedSetup ]
> rasData = Modding.OpenUserData("RAS", 1)
> rasData.SetValue("CITY_DISTANCE", 5)
true
> rasData.GetValue("CITY_DISTANCE")
5
Exit and restart
Code:
[ Lua State = Automation Monitor ]
[ Lua State = Main State ]
 InstalledPanel: Refreshing Mods
 InstalledPanel: GetModBrowserListings()
> rasData = Modding.OpenUserData("RAS", 1)
> rasData.GetValue("CITY_DISTANCE")
5

So while you can't restore the value for a particular game, you can restore the user's last preference - which is probably what most people want ... "I want to play all my games at a city spacing of 4" and not "I want to play anther 20 turns of this one at 2 and then load a different save and play that at 5"

Although it does open up the possibility of being able to play the first 100 or so turns at a spacing of 5 and then decrease it to 3 for the rest of the game - which I've often thought would be useful!
 
The only other option is to expose the DLL method that loads the Defines table data into the cache as a Game.ReloadDefines() Lua method
 
You can change the defines during the setup screen, but the problem arise when you try to load a game: supposing you're still using a modded custom screen to load the game so you can change the define here again, how would you know what value was used initially with that specific save ?
I'm not sure I understand. Data (e.g. current state of your settings) can be stored with the save game. And an event to override settings loaded from the XML could be added to the mods and called on game init without too much hassle.

Edit: Perhaps I'm not understanding 'custom load screen'. Starting a new game has an options screen, but loading a saved one doesn't.
 
So while you can't restore the value for a particular game, you can restore the user's last preference - which is probably what most people want ... "I want to play all my games at a city spacing of 4" and not "I want to play anther 20 turns of this one at 2 and then load a different save and play that at 5"

Although it does open up the possibility of being able to play the first 100 or so turns at a spacing of 5 and then decrease it to 3 for the rest of the game - which I've often thought would be useful!
You're right, that's good when you want to control defines (or other DB entries) from setup screen instead of an additional mod.

Or when you want to change the resource placement rules from a setup screen for specific maps like YnAEMP does.

My problem was when I tried to alter the minor civilization database that way in YnAEMP to keep only (for example) the European CS before loading an Europe map instead of having to kill the non-European CS after the map is loaded. It would have allowed me to have only one mod with all added CS for all maps (way more than 41) and then keep only the 41 fitted for the selected map (or for more precise selection, have a CS replacing a major civ not selected for the game for example)

But there was no easy way to restore the DB to fit the CS corresponding to the save game when you quit and launch the game again, except if you assume that you will never have more than one game going on at all time...

Now, maybe we can get a save game date using the UI function, and store the needed values in user data with a save game ID based on file name & date :think:


I'm not sure I understand. Data (e.g. current state of your settings) can be stored with the save game. And an event to override settings loaded from the XML could be added to the mods and called on game init without too much hassle.

Edit: Perhaps I'm not understanding 'custom load screen'. Starting a new game has an options screen, but loading a saved one doesn't.

The DB is initialized when the mods are loaded, using the values given by the mods. You can still change those values before the game start, but you can't update them for the game engine once it's started.

If you save your game, quit and reload, the mods will erase the values you've changed in the DB, the save game does not keep a copy of the DB. You may have stored them in another format in the save game, but then you can't update the game engine to use them (without DLL modification)

You can restore a value that you had saved during the previous session using a custom screen setup, but you can't track different values for different saves. Except if the above idea with a save game ID is valid. Maybe worth a try.
 
The only other option is to expose the DLL method that loads the Defines table data into the cache as a Game.ReloadDefines() Lua method

This would be VERY good.
 
Back
Top Bottom