[SDK] Execute a func after game load

Discussion in 'Civ4 - SDK/Python' started by keldath, Apr 21, 2022.

  1. keldath

    keldath LivE LonG AnD PrOsPeR

    Joined:
    Dec 20, 2005
    Messages:
    7,084
    Location:
    israel
    Hi all,

    Anyone have an idea where can i put a function to be executed after a load game?
    Also after map generation on the load process.

    Thanks in advance,
    Keldath
     
  2. Leoreth

    Leoreth Vampire of the Blue Moon Moderator

    Joined:
    Aug 23, 2009
    Messages:
    35,809
    Gender:
    Male
    Location:
    Paris
    For a specific map script, or for all of them?

    Map scripts provide the "afterGeneration" function that is called after the map has been generated. The more generic "GameStart" Python event should also work, though.
     
  3. f1rpo

    f1rpo plastics

    Joined:
    May 22, 2014
    Messages:
    1,214
    Location:
    Germany
    Assuming that this is (also) about loading savegames and the DLL, here's my crib sheet for the order of the read(FDataStreamBase*) calls:
    (I use it mostly for debugging savegame compatibility bugs.)
    Code:
    CvInitCore
    CvGameAI --> CvGame --> CvDeal
             --> CvRandom
             --> CvReplayMessage
    CvMap --> CvPlot
          --> CvArea
    CvTeamAI --> CvTeam
    CvPlayerAI --> CvPlayer --> CvCityAI --> CvCity
               --> CvUnitAI --> CvUnit
               --> CvSelectionGroupAI --> CvSelectionGroup
    CvStatistics
    The last part is initiated by the EXE, via CvEventReporter:
    Code:
    void CvEventReporter::readStatistics(FDataStreamBase* pStream)
    {
       m_kStatistics.reset();
       m_kStatistics.read(pStream);
       GC.getGame().onAllGameDataRead();
    }
    So that's where I've added a call to CvGame (as the catch-all class) for code that should run after a savegame has been fully loaded. However, I use that (almost?) exclusively for hacks to maintain save-compatibility. The procedure at the start of a game doesn't have much overlap with loading a game; mostly the reset functions I think. More generally, when having to place some new step in the order of initialization, I try to figure out what data is needed beforehand and what the earliest step is where all the required data is available.
     
  4. keldath

    keldath LivE LonG AnD PrOsPeR

    Joined:
    Dec 20, 2005
    Messages:
    7,084
    Location:
    israel
    hey folks,
    thanks for the replies.

    i needed a code to color plots after load game for my city state mechanizem.
    eventually, i experimented with CvGame::onAllGameDataRead()
    where i added my function for culture plot coloring.
    i added a counter of executions on the main interface function and i found the combo i needed to make sure the coloring will take place,
    the main issue that a clear was executed on the plots which deleted my border coloring.

    so f1, i was in the right place according to your post.

    Leo - thanks - but i was looking for a dll code part rather then the python, but thanks :)
     
    Leoreth likes this.
  5. f1rpo

    f1rpo plastics

    Joined:
    May 22, 2014
    Messages:
    1,214
    Location:
    Germany
    Initialization of graphics actually, for the most part, works the same way when loading a savegame as when launching a new game. Gets initiated by the EXE in various places, e.g. CvGame::updateColoredPlots, which would normally be the place for coloring plots. I've also tied some graphics init code to CvGlobals::SetGraphicsInitialized in the past.
     

Share This Page