LoneGazebo / Community-Patch-DLL

Community Patch for Civilization V - Brave New World
Other
291 stars 160 forks source link

[Feature Request] ID remapper in DLL before caching the database entries #11310

Open azum4roll opened 1 month ago

azum4roll commented 1 month ago

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)

3. DROP TABLE IDRemapper;

This function should be placed before the ValidateGameDatabase() call in CvDllDatabaseUtility::CacheGameDatabaseData(). The ID validation in CvDllDatabaseUtility::ValidateGameDatabase() and Remapper.sql can be removed.

azum4roll commented 1 month ago

There are a couple of tables that don't have IDs starting at 0: