No announcement yet.

Modifying the AI to build more units

  • Filter
  • Time
  • Show
Clear All
new posts

  • Modifying the AI to build more units

    I am trying to modify the code for Civ4 Beyond the Swords so that the AI will want to build more units instead of trying to build things such as Research. I tried following many articles out there, such as the ones listed at "" on how to mod in general but it is not working. Can somebody explain the following things:

    1. If I modify a .cpp file, will it automatically take affect on a game that had been previously saved, or will I need to start a brand new game? Also, what do I exactly need to do in order to ensure that any changes I make to a .cpp file will be active the next time I launch Civ4 Beyond the Swords?

    2. To achieve my goal, it looks like I will need to modify the "CvCityAI.cpp" file. Does this sound right?

    If anybody can answer these questions, please provide as many details as possible since I am new to this and have absolutely no idea what I am doing. Any help would be appreciated!

  • #2
    Update: The instructions I used to install the SDK were Refar's instructions at|. Using Visual Studio, I am able to perform the build command without any errors, but when I modify CvCityAI.cpp to something like the following and "build":

    In void CvCityAI::AI_chooseProduction()

    Old code:

    int iCulturePressure;

    bDanger = AI_isDanger();

    New code:

    int iCulturePressure;

    int zero = 0;
    int test = 987654321/zero;

    bDanger = AI_isDanger();

    It is not crashing after completing a turn from a saved game like I would expect it to due to division by zero, which leads me back to question 1 from my previous post. I doubt it is the case that this code is not being hit, so do I need to do something else after running "build" in Visual Studio to make this code active?


    • #3
      Okay, I think I answered my own questions. First of all, I was not copying and pasting the "CvGameCoreDLL.dll" file from the "Final_Release" folder to the folder that Civ4 was using. Second, I was able to encourage the AI to build more units by changing the int CvCityAI::AI_buildUnitProb() function in CvCityAI.cpp to return a larger value.

      In any event, this has been a learning experience for me, and hopefully if others want to increase the number of units the AI builds, I have provided a starting place. Now I am going to play my modded game!