Why does this code no longer work?

General Tso

Panzer General
Joined
Oct 12, 2007
Messages
1,548
Location
U. S. of A.
This code used to cause the game to start with inactive civs being disabled and not selected as random civs. I'm not absolutely sure when it stopped working but it probably happened when BNW came out. Can anybody tell me what the problem is?

It cycles thru a list I created previously that has a boolean isActive for each civType and sets the values of certain database fields depending on the value of isActive (or at least it used to).

Code:
for civType, isActive in pairs(self.activeCivs) do		
	for result in DB.Query("UPDATE Civilizations SET Playable = ?, AIPlayable = ? WHERE Civilizations.Type = ?", isActive and 1 or 0, isActive and 1 or 0, civType) do
	end
end

Are those fields now cached where previously they where not? The whole database thing confuses me. It seems like it's overly complicated and to limited in what it can do.
 
I was under the impression from reading some other replies in this forum that all db values were cached on startup and not editable after init.
 
Does it make any difference if the values are used before the game starts? The database values are set in a modified Advanced Setup screen then used (I assume) when the map is created or possibly before that.
 
Most values from the database are stored in the DLL/exe when the game, or mod, is loaded/started. There are only a very small number of cases where editing the database after the game or mod has loaded will work.

The mystery to me is why that would have ever worked. Maybe the exe used to load the information from the database when it sets random civs, instead of calling the DLL. If so they probably "fixed" that in a patch so it now calls the functions in the DLL it was meant to call.


Unfortunately the code for choosing random civs appear to be in the exe. At least I can't seem to find it. So I can't tell you how it works or what has changed when.
 
It used to work because the system is in the "pre-game" state during the setup menus, when the database caches are not used, as per the comment in CvPreGame.cpp

Code:
// WARNING: Do not use any of the GC.*Info tables in this file.
//			These Game Core tables are not always current to what the loaded
//			database set contains.  This is the case when setting up a multiplayer
//			game or even in a single player game if you have returned from a multiplayer game.
//			The reason the Game Core data is not kept in sync is because the caching of all the data
//			can take a significant amount of time.

If the Lua in the OP has stopped working it would appear that the above comment no longer holds true and some caching is performed
 
Thanks for the reply's everybody.

It looks like the problem is as I feared - caching. That whole situation is frustrating. It doesn't make sense to design a game that can be heavily modded and then not allow the modder to change basic values.

As far as my problem goes. I'd rather have the game pick the random civs. It seems cleaner that way. I guess I'll have to manually pick them myself.
 
Interesting. I noticed that my saved games started loading a lot faster around the time this problem showed up. I wonder if they did something to speed things up and it may have had some unwanted effects.
 
Back
Top Bottom