1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[MOD FIX] IndieStone Anti Deletion-Crash Fixinator SQL

Discussion in 'Civ5 - Mod Components' started by lemmy101, Nov 1, 2010.

  1. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
    Important note: Unfortunately, pre-made scenarios may have problems with this code as it seems units are placed on the map via their IDs and not their type names. Thanks to primordial stew for pointing this out. To avoid this you can remove the unit section from the XML (just search for unit and delete the 4 line segment for units and unitclasses. I'm not entirely sure actually that units cause crashes anyway, I think it's mainly techs, policies etc that do. Basically if you have problems, trim out as much as possible and keep only what types you're actually deleting in your mod.

    Hello all. In Civ at the moment there is an issue where if you delete something, say for example a technology or a unit or a policy branch or something. It will cause instability and crashes during game.

    In my investigations getting completely new tech trees to work with our tech tree editor (http://forums.civfanatics.com/showthread.php?t=395209) I've realised that this is because the deleted thing has an ID associated with it, and Civ uses these IDs to grab the objects when iterating through with arrays.

    For e.g.

    Code:
    for unit in Game.Units() do
    
    end
    behind the scenes somewhere, it's looking for unit 0, then unit 1, then unit 2 and so on. When it reaches your missing unit's ID, it will crash the game because it's trying to operate on a null item.

    To fix?

    Add this SQL file to your Mod, adding a Mod Action to OnModActivated, UpdateDatabase for the SQL (and making sure it's the LAST thing in the action list)

    It will go through every table that uses IDs and store them in a temporary table, then use this to generate incrementing ID values to put back into the first table, to ensure they all go from 0 to whatever with no gaps.

    This should make your mod safe to add or delete entries from any table in the game without crashes, as it covers every iterable GameInfo type and at the bottom of your mod action list will happen after all your mod's changes.

    Also, in cases of multiple mods... providing all mods that delete or add to these tables use this, then it will work, as the first will reassign the IDs when it is activated, then the second will redefine the IDs when it is activated, and so on. Meaning whichever order they activate, you will have perfectly incrementing IDs for all the data each mod added or removed.

    Note if one mod doesn't use it, however, and deletes rows of GameInfo tables, then there are no guarantees what order they will activate, so if they activate after one with this fix, they could then bugger up the fixed IDs. That said, such a mod is unlikely to be released as it would likely crash with or without other mods.

    Note in the case of technologies, there seems to be some importance in the ordering of them. For this reason I put an order command to order them by their X position on the tech tree (ORDER BY GridX ASC), to make sure later techs don't have a lower ID than a prerequisite tech (which was causing crashes in itself) so the same may be true for other tables, but I've not managed to check as there are so many of them. If you get a crash down to deleting things when using this SQL you could try putting your own sort command in the SQL as this may fix it.

    It would be a good idea to check your tables data in the database (Core or Debug in 'cache' directory in My Docs/My Games/Civ 5/) using a tool like this: http://forums.civfanatics.com/showthread.php?t=386494 before and after activating your mod and going into Single Player, just to make sure it's taken effect. For one you could have mistyped the mod action, but more likely since there was a s**tton of these I couldn't possibly test them all, and I may have made an error somewhere in adding them.

    Now onto the SQL!

    Code:
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Technologies ORDER BY GridX ASC;
    UPDATE Technologies SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Technologies.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM AICityStrategies;
    UPDATE AICityStrategies SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE AICityStrategies.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM AIEconomicStrategies;
    UPDATE AIEconomicStrategies SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE AIEconomicStrategies.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM AIGrandStrategies;
    UPDATE AIGrandStrategies SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE AIGrandStrategies.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM AIMilitaryStrategies;
    UPDATE AIMilitaryStrategies SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE AIMilitaryStrategies.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM CitySpecializations;
    UPDATE CitySpecializations SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE CitySpecializations.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM TacticalMoves;
    UPDATE TacticalMoves SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE TacticalMoves.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Attitudes;
    UPDATE Attitudes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Attitudes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Calendars;
    UPDATE Calendars SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Calendars.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM CitySizes;
    UPDATE CitySizes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE CitySizes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Concepts;
    UPDATE Concepts SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Concepts.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Contacts;
    UPDATE Contacts SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Contacts.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Domains;
    UPDATE Domains SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Domains.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM InvisibleInfos;
    UPDATE InvisibleInfos SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE InvisibleInfos.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MajorCivApproachTypes;
    UPDATE MajorCivApproachTypes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MajorCivApproachTypes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MinorCivApproachTypes;
    UPDATE MinorCivApproachTypes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MinorCivApproachTypes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MinorCivTraits;
    UPDATE MinorCivTraits SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MinorCivTraits.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Months;
    UPDATE Months SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Months.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Seasons;
    UPDATE Seasons SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Seasons.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM UnitAIInfos;
    UPDATE UnitAIInfos SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE UnitAIInfos.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM UnitCombatInfos;
    UPDATE UnitCombatInfos SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE UnitCombatInfos.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM BuildingClasses;
    UPDATE BuildingClasses SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE BuildingClasses.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Buildings;
    UPDATE Buildings SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Buildings.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Civilizations;
    UPDATE Civilizations SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Civilizations.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MinorCivilizations;
    UPDATE MinorCivilizations SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MinorCivilizations.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Regions;
    UPDATE Regions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Regions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Traits;
    UPDATE Traits SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Traits.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM ArtStyleTypes;
    UPDATE ArtStyleTypes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE ArtStyleTypes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Climates;
    UPDATE Climates SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Climates.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Cursors;
    UPDATE Cursors SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Cursors.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM EmphasizeInfos;
    UPDATE EmphasizeInfos SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE EmphasizeInfos.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Eras;
    UPDATE Eras SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Eras.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Flavors;
    UPDATE Flavors SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Flavors.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM GameOptions;
    UPDATE GameOptions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE GameOptions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM GameSpeeds;
    UPDATE GameSpeeds SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE GameSpeeds.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM GoodyHuts;
    UPDATE GoodyHuts SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE GoodyHuts.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM HandicapInfos;
    UPDATE HandicapInfos SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE HandicapInfos.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM HurryInfos;
    UPDATE HurryInfos SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE HurryInfos.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MultiplayerOptions;
    UPDATE MultiplayerOptions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MultiplayerOptions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM PlayerOptions;
    UPDATE PlayerOptions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE PlayerOptions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Policies;
    UPDATE Policies SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Policies.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM PolicyBranchTypes;
    UPDATE PolicyBranchTypes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE PolicyBranchTypes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Processes;
    UPDATE Processes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Processes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM PolicyBranchTypes;
    UPDATE PolicyBranchTypes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE PolicyBranchTypes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Projects;
    UPDATE Projects SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Projects.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM SeaLevels;
    UPDATE SeaLevels SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE SeaLevels.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Specialists;
    UPDATE Specialists SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Specialists.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Trades;
    UPDATE Trades SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Trades.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM TurnTimers;
    UPDATE TurnTimers SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE TurnTimers.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Votes;
    UPDATE Votes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Votes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM VoteSources;
    UPDATE VoteSources SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE VoteSources.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Worlds;
    UPDATE Worlds SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Worlds.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Colors;
    UPDATE Colors SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Colors.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM InterfaceModes;
    UPDATE InterfaceModes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE InterfaceModes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Leaders;
    UPDATE Leaders SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Leaders.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM PlayerColors;
    UPDATE PlayerColors SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE PlayerColors.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Routes;
    UPDATE Routes SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Routes.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Features;
    UPDATE Features SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Features.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM FakeFeatures;
    UPDATE FakeFeatures SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE FakeFeatures.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Improvements;
    UPDATE Improvements SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Improvements.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM ResourceClasses;
    UPDATE ResourceClasses SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE ResourceClasses.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Resources;
    UPDATE Resources SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Resources.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Terrains;
    UPDATE Terrains SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Terrains.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Yields;
    UPDATE Yields SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Yields.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM AnimationCategories;
    UPDATE AnimationCategories SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE AnimationCategories.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM AnimationPaths;
    UPDATE AnimationPaths SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE AnimationPaths.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Automates;
    UPDATE Automates SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Automates.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Builds;
    UPDATE Builds SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Builds.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Commands;
    UPDATE Commands SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Commands.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Controls;
    UPDATE Controls SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Controls.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM EntityEvents;
    UPDATE EntityEvents SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE EntityEvents.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Missions;
    UPDATE Missions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Missions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MultiUnitFormations;
    UPDATE MultiUnitFormations SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MultiUnitFormations.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM MultiUnitPositions;
    UPDATE MultiUnitPositions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE MultiUnitPositions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM SpecialUnits;
    UPDATE SpecialUnits SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE SpecialUnits.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM UnitClasses;
    UPDATE UnitClasses SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE UnitClasses.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM UnitPromotions;
    UPDATE UnitPromotions SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE UnitPromotions.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
    INSERT INTO IDRemapper (Type) SELECT Type FROM Units;
    UPDATE Units SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Units.Type = IDRemapper.Type);
    
    DROP TABLE IDRemapper;
    
    Hope this helps! :) Let me know if you needed to add any additional info such as an ordering command for any of the other types, so I can add it here.
     
  2. poncratias

    poncratias Chieftain

    Joined:
    Feb 9, 2010
    Messages:
    336
  3. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
  4. poncratias

    poncratias Chieftain

    Joined:
    Feb 9, 2010
    Messages:
    336
    meant as a compliment^^
     
  5. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
  6. Ahwaric

    Ahwaric Shrubbery-hugger

    Joined:
    Nov 12, 2005
    Messages:
    1,217
    Location:
    Kraków, Poland
    I love you :)
    (meant simply as a HUGE compliment)

    THANKS!

    Edit: Actually, what Putmalk says ;)
     
  7. Putmalk

    Putmalk Chieftain

    Joined:
    Sep 26, 2010
    Messages:
    2,623
    Location:
    New York
    I will test this out.

    If it works, I love you.
     
  8. Pazyryk

    Pazyryk Chieftain

    Joined:
    Jun 13, 2008
    Messages:
    3,584
    Great! Just remember that if you delete items wholesale, you still need to deal with any dependencies on those items in both Lua and XML/SQL. For Lua, you can at least find those references using WindowsGrep to search Assets folder (I can't for the life of me figure out Windows searches). For XML/SQL (ie, the database) dependencies, there is a lot of discussion of this in my thread here, most especially Gedrin's post #21 and my examples in post #33.
     
  9. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
    Yeah cool, I should have mentioned that really. I'm working on a tool that should take care of that. The tech editor currently does this for tech trees but the system should work for anything with some work.
     
  10. blazekid87

    blazekid87 Chieftain

    Joined:
    Oct 5, 2010
    Messages:
    179
    Location:
    NYC
    good stuff....yea I already had realised a the problem with ID's and dropping rows when I was doing Eras...had to drop all the Era rows and reassign all IDs in the correct order manually, or else it would assign IDs starting from 6 . But having the technology codes not in order (by gridX) never seemed to be a problem. Also the tech tree will break if two technologies from different eras have the same gridX position.
     
  11. Ahwaric

    Ahwaric Shrubbery-hugger

    Joined:
    Nov 12, 2005
    Messages:
    1,217
    Location:
    Kraków, Poland
    Just dropped by to say that I confirm, I love you ;)

    I have changed my mod form to, well, mod form and it started. With the removal of most of the techs and adding 80 new ones, cutting few eras worth of buildings and units etc.

    I just deleted all tables from civs, leaders, traits, units, unitclasses, promotions, buildings, buildingclasses and technologies, then added new files created by my xlsm editor, then I have added crash fixinator.

    Voila, no crash, I could play the mod :)

    I am going back to expanding the mod, will post details later, probably in Pazyryk's thread on gutted mod.
     
  12. Whys

    Whys Between the Lines

    Joined:
    Oct 20, 2007
    Messages:
    456
  13. primordial stew

    primordial stew Chieftain

    Joined:
    Sep 1, 2005
    Messages:
    1,219
    Location:
    a puddle
    Thanks a ton :goodjob:

    Nice that some tables start with 0 and others with 1....

    Since the units/buildings/etc.. can be reordered, does this mean the only good way to add these to a scenario is using lua? In civ4 the map used the unit name, but is this still done? It will be very punishing to those of us with pre made maps who are also deleting things.

    Am still playing around, but I've got a battle map with a bunch of units set down prior to adding this, and while it still looks right in WB it CTDs in civ5. If all the units are deleted then it starts fine.

    My other map has a bunch of cities and no units, and that starts up fine. And the units show up fine in the pedia, and look good in sql.
     
  14. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
  15. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
    Crumbs. Never thought of that. Bah. ;)

    Try removing just the unit / unitclasses sections of the SQL? Should still allow tech modding etc without buggering your scenario?
     
  16. Le Sage

    Le Sage Chieftain

    Joined:
    Apr 24, 2009
    Messages:
    1,522
    Location:
    Digging up your garden
    Nice utility again!

    I tried removing several units in my mod, but it caused Saved Games to get screwed up and they wouldn't restore. I think it was when I removed the Settler that it went too far, but I also removed the UU's for both France and England. Therefore I am also looking forward to your removal addition to the Tech Tree Editor! Keep it up.
     
  17. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
    Is this saved games saved using the same mod code exactly?

    i.e. no changes in between loading / saving?
     
  18. Le Sage

    Le Sage Chieftain

    Joined:
    Apr 24, 2009
    Messages:
    1,522
    Location:
    Digging up your garden
    It was using the same versions of the files.

    I was unclear in my previous post. The save game problem I had was not while using your utilities. I had it before I downloaded the Tech Tree editor and the sql here, and could only solve it removing the file that deleted these said units.

    I was really referring to your note about not being sure about removing units would cause problems and that it's mostly Techs and Policies and such. The removal of units does indeed seem to cause problems and it is because of this, I am waiting for your removal utility where we'll be able to remove stuff safely.
     
  19. lemmy101

    lemmy101 Chieftain

    Joined:
    Apr 10, 2006
    Messages:
    1,064
  20. Le Sage

    Le Sage Chieftain

    Joined:
    Apr 24, 2009
    Messages:
    1,522
    Location:
    Digging up your garden
    No. Instead your Tech Tree editor works very well. My mod is entirely scenario-driven, but I've had no problems at all with the units in my scenarios or anything else, and I didn't remove the references to Units in your sql either. I am just adding techs to the Medieval Era, but I'm not touching the Tech Tree otherwise at all.
     

Share This Page