Open azum4roll opened 1 month ago
There are a couple of tables that don't have IDs starting at 0:
setReplayDataValue()
calls in CvPlayer::GatherPerTurnReplayStats()
. It's very likely safe to have IDs start at 0 instead of 1 (IDs aren't used in Lua), but we need to test.CvTypes::AcquireTypes()
instead of using CvDllDatabaseUtility::PrefetchCollection()
to fetch from the database. I can't be sure if making its IDs start at 0 would break anything.
Currently, we have a Remapper.sql in the (2) mod that reorders the ID of each table so there is no skipped ID due to row deletion.
However, this is only guaranteed to work for VP. Modmods frequently delete from tables, and CP-only doesn't have this for performance reasons. Similarly, we can't have a trigger for this either.
The best way to handle this is to do it in the DLL, after all database entries (except Defines and CustomModOptions, due to PostDefines and CustomModPostDefines being a thing) are finalized. We just need someone familiar with database code to do it.
Rough draft of the algorithm:
1.
CREATE TABLE IDRemapper (ID integer PRIMARY KEY, Type text);
2. for each table with ID and Type that's not IDRemapper: (CvDllDatabaseUtility::ValidateGameDatabase()
has existing code that does this)INSERT INTO IDRemapper (Type) SELECT Type FROM <table name> ORDER BY ID;
UPDATE <table name> SET ID = (SELECT IDRemapper.ID - 1 FROM IDRemapper where <table name>.Type = IDRemapper.Type);
DELETE FROM IDRemapper;
3.
DROP TABLE IDRemapper;
This function should be placed before the
ValidateGameDatabase()
call inCvDllDatabaseUtility::CacheGameDatabaseData()
. The ID validation inCvDllDatabaseUtility::ValidateGameDatabase()
and Remapper.sql can be removed.