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

Using LUA to "replace" civs at game start

Discussion in 'Civ5 - Creation & Customization' started by sman1975, Jun 18, 2020.

Tags:
  1. sman1975

    sman1975 Emperor

    Joined:
    Aug 27, 2016
    Messages:
    1,187
    Location:
    Dallas, TX
    Hi, everyone!

    I'm building a mod that lets you play a WW2 scenario on any map, with 20 custom Civs included, along with a few other game changes to make the scenario feel more consistent/coherent.

    I'm trying to let the player select their desired civ (either a new custom or normal game civ), then "force" the rest of the AI civs in the game to come from the rest of the 20 custom civs.

    I've tried several approaches, including replacing Advanced Setup, KillUnits+KillCities+AddPlayer, and SetCivilization+SetLeaderType+SetPlayerColor. None have really worked well.

    I'm currently leaning towards the last solution, which replaces the AI Civ/Leader/colors but it has 2 basic problems: After the replacement (which occurs at SequenceGameInitComplete), the game still uses the original leader's Diplo screen, and the civ cultural boundary colors on the minimap retain the original civ's player colors.

    I've noticed if I save the game after the first turn, then reload the game, the leader and the minimap boundary colors magically become the replaced leader/colors - which means they are "correct" for the scenario. Obviously, this isn't good enough.


    Question: does anyone know how to "replace" an AI civ with a new AI civ at game start?

    Thanks!


    Ps - I was favoring this approach as it didn't interfere with normal game setup, meaning Really Advanced Setup compatibility.

    Pss - I've avoided other AI replacement solutions, mainly due to the caching problem up front, as is so thoroughly analyzed here: https://forums.civfanatics.com/thre...e-difficulty-list-in-basic-game-setup.519367/
     
  2. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,074
    Location:
    Illinois, USA
    If you are always using the same set of civs as the valid ones to use, you ought to be able to set <Playable> and <AIPlayable> in table Civilizations.

    Playable set to true allows any player to use that civ: this is the default setting
    AIPlayable set to true allows the AI players to play as that civilization: this is the default setting

    AIPlayable set to false does not allow the AI players to play as that civilization.
    Playable set to false makes the civilization entirely unplayable by anyone, as I recall.

    You could use SQL with triggers and perhaps a careful use of (IN) and (NOT IN) listing to only allow the civs you want to be used to be both Playable and AIPlayable.

    Sometihng like
    Code:
    UPDATE Civilizations SET Playable = 1, AIPlayable = 1 WHERE Type IN ('CIVILIZATION_AMERICA', 'CIVILIZATION_ENGLAND', 'CIVILIZATION_FRANCE', 'CIVILIZATION_GERMANY');
    
    UPDATE Civilizations SET Playable = 0, AIPlayable = 0 WHERE Type NOT IN ('CIVILIZATION_AMERICA', 'CIVILIZATION_ENGLAND', 'CIVILIZATION_FRANCE', 'CIVILIZATION_GERMANY');
    This sort of approach ought to work for all the official Firaxis content, but you may need to create a trigger in SQL so that later additions to table Civilizations by other mods (if a player is running any other than your scenario mod(s) ) will get the new civilization set to being unplayable or as being playable depending on whether or not they are something you want to let your system include into the scenario experience.

    Note: you need to verify that I've formatted the SQL code example properly since I did it from memory and off the top of my head. You should be able to find examples on the net for correct syntax for this sort of thing if my doing-it-from-memory was not correct.
     
  3. sman1975

    sman1975 Emperor

    Joined:
    Aug 27, 2016
    Messages:
    1,187
    Location:
    Dallas, TX
    Thanks, @LeeS. I don't think I explained the situation very well. I'll try again.

    1. At game set up time, I want the player to use normal game setup UI to select any Civ available (including all normal Civs, plus the 20 custom civs coming in the mod)

    2. The player can also select any available map from the normal map selection menu

    3. It should be OK to enter the "Advanced Setup" area and make any adjustments, and add specific AI Civs

    4. The player would then select the "Start Game" button to get things rolling

    ------------------------------

    Somewhere in this process above (0 - 5), I'd like to look at the list of Civs the game has setup. The mod wouldn't change any human players in the list of Civs. Ideally, there would be a way to check Advanced Setup and not change any of the Civs the player setting up the game made.

    At that point, the mod would look at the rest of the slots and substitute, in top-down order, a list of custom civs from the mod, and replace any non-human/non-selected Civs with the next available custom Civ from the mod - adding a varying number of Custom Civs, based on map size.

    I've figured out how to do this using a Custom Game front-end (thanks to the inimitable @whoward69), but it's a bunch of extra work beating the UI into submission. I was hoping there was a simple way to kill/add Civs in GT 0.

    And so far, I am able to do this, except for the Leader Diplo screen and minimap culture border colors not responding to the change (at least before a game save, that is).
     
  4. bc1

    bc1

    Joined:
    Jan 12, 2004
    Messages:
    1,257
    Changes need to be done pregame, so with a custom entry point.
    That entry point can load the regular AdvancedSetup screen, as done by barbarians evolved mod.
    If you want to make changes AFTER setup, try an event hook: Events.SerialEventStartGame.Add( myFunction ), it might mork
     

Share This Page