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

3.19 City governor rushes buildings using gold!

Discussion in 'Civ4 - Bug Reports' started by Pep, Aug 6, 2009.

  1. Pep

    Pep King

    Joined:
    May 28, 2002
    Messages:
    688
    Location:
    Spain
    I have noticed that, in oddly cases, when production automation is turned on in a city, the city governor uses gold to rush the building!

    I have attached a savegame. You can see that factory is 10 turns from completion in Hurrian, which has production automated turned on, and empire gold is 600. Next turn, the factory is finished and empire gold is 26.

    Turning off production automation in this city solves the problem in this particular case. Another cities with production automation turned on behave normally.

    A very odd bug indeed...

    Edit: Removed the savegame due to quota issues.
     
  2. r_rolo1

    r_rolo1 King of myself

    Joined:
    May 19, 2006
    Messages:
    13,818
    Location:
    Lisbon, Portugal
    It is not a bug IMHO. You will notice that it :whipped: too ....
     
  3. TheMeInTeam

    TheMeInTeam Top Logic

    Joined:
    Jan 26, 2008
    Messages:
    25,523
    It's no bug. It's been this way a long time.

    The production auto governor will also whip. When I have units looped in the early game and I'm just going mass war I often let it do so.
     
  4. Pep

    Pep King

    Joined:
    May 28, 2002
    Messages:
    688
    Location:
    Spain
    I think it's indeed a bug. If you have loaded the savegame, you can see it's nonsense that the city governor can spend almost all your civilization gold in a single building.

    I have searching the code and found this in function CvCityAI::AI_doHurry:

    //this overrides everything.
    if (bGrowth)
    {
    int iHurryGold = hurryGold((HurryTypes)iI);
    if ((iHurryGold > 0) && ((iHurryGold * 16) < GET_PLAYER(getOwnerINLINE()).getGold()))
    {
    hurry((HurryTypes)iI);
    break;
    }
    if (AI_countGoodTiles((healthRate(0) == 0), false, 100) <= (getPopulation() - iHurryPopulation))
    {
    hurry((HurryTypes)iI);
    break;
    }
    }

    It seems to happen when the city has enough population to pop-rush the building, but you aren't using slavery civic and you are using universal suffrage. The hurry function in black should execute only to pop-rushing but it executes to gold-rushing too, without checking the gold requeriments for gold-rush.

    Could be this portion of code the responsible of the low reserves of AI Civ gold in certain circumstances?
     
  5. r_rolo1

    r_rolo1 King of myself

    Joined:
    May 19, 2006
    Messages:
    13,818
    Location:
    Lisbon, Portugal
    Well, I definitely agree that the $rush code could use a redo... the issue is that the code for hurry a build is the same for slavery as to US $rush, as you pointed. Slavery is city limited ( you can't slave people in a city to get prod in other.... ) and $ rush isn't, but the code treats both in the same way.

    Well, more code for jdog to do :D
     
  6. ori

    ori Repair Guy Super Moderator

    Joined:
    Dec 17, 2005
    Messages:
    16,561
    Location:
    Baden-Württemberg, Germany
    this sort of behavior has been in their ever since Blake taught the AI to actually hurry things at all in one of the early BetterAI builds - it pretty much makes using the city production manager under Universal Suffrage a no-go - but in its essential parts it was intended - it just seems to not be easy to actually make it work well :rolleyes:
     
  7. Pep

    Pep King

    Joined:
    May 28, 2002
    Messages:
    688
    Location:
    Spain
    I think it can be fixed with this code:

    if (iHurryPopulation > 0)
    {
    if (AI_countGoodTiles((healthRate(0) == 0), false, 100) <= (getPopulation() - iHurryPopulation))
    {
    if (iHurryPopulation > 0)
    {
    hurry((HurryTypes)iI);
    }
    break;
    }
    }

    The value of iHurryPopulation is established by:
    iHurryPopulation = hurryPopulation((HurryTypes)iI);

    hurryPopulation calls getProductionPerPopulation(), which reads the XML tag "iProductionPerPopulation" in Civ4HurryInfo.xml. Its value is 0 for HURRY_GOLD and 30 for HURRY_POPULATION.
     
  8. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    I agree Pep, that's exactly the solution. There's a check that iHurryGold is > 0 for the gold half, there definitely needs to be a similar check for the population side.

    As it stands, when the AI is evaluating whether to hurry using gold under Universal Suffrage, it thinks hurrying by population is a fabulous idea because it will cost 0 population ... but then it actually does a gold hurry :crazyeye:

    Will be in the next UP.
     
  9. Pep

    Pep King

    Joined:
    May 28, 2002
    Messages:
    688
    Location:
    Spain
    Related to this bug, there are two different criteria to gold-rush in CvCityAI::AI_doHurry:

    - First:

    if (bGrowth)
    {
    int iHurryGold = hurryGold((HurryTypes)iI);
    if ((iHurryGold > 0) && ((iHurryGold * 16) < GET_PLAYER(getOwnerINLINE()).getGold()))
    {
    hurry((HurryTypes)iI);
    break;
    }
    ...

    - Second:

    int iValuePerTurn = AI_buildingValueThreshold(eProductionBuilding, BUILDINGFOCUS_GOLD | BUILDINGFOCUS_MAINTENANCE | BUILDINGFOCUS_PRODUCTION);

    iValuePerTurn /= 3;

    if (iValuePerTurn > 0)
    {
    int iHurryGold = hurryGold((HurryTypes)iI);
    if ((iHurryGold / iValuePerTurn) < getProductionTurnsLeft(eProductionBuilding, 1))
    {
    if (iHurryGold < (GET_PLAYER(getOwnerINLINE()).getGold() / 3))
    {
    hurry((HurryTypes)iI);
    return;
    }
    }
    }

    I don't know if this is intended or not, but I think spending 1/3 of your gold to rush a building isn't a good strategy. 1/16 makes more sense...
     
  10. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    Well, that gets away from clear bugs to AI improvements, I'll keep it in mind for BBAI though.

    There is a second instance of the gold hurry bug though, just a few lines below the first one you pointed out. Again, the AI will think a population hurry is a great idea when it's actually doing a gold hurry ... these bugs have a big effect.
     
  11. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    There's also one which works the other way, where the AI might whip population because the gold cost is 0.

    Jeez ...
     
  12. PieceOfMind

    PieceOfMind Drill IV Defender Retired Moderator

    Joined:
    Jan 15, 2006
    Messages:
    9,319
    Location:
    Australia
    That you and Pep are finding these bugs is music to my ears! :culture: These bugs are pretty amusing.
     

Share This Page