Single Player bugs and crashes v38 plus (SVN) - After the 20th of February 2018

That code is just :crazyeye:
If that happens the building is more important as the hunter in that moment for that city.
We agree that the broker system is hard to follow. But something isnt right about the priority establishment imo.
 
We agree that the broker system is hard to follow. But something isnt right about the priority establishment imo.
I noticed a lot of lines in code, that say "Return;", maybe that somehow messes with code?
@alberts2

50 turns in on Noble/Standard/Normal with practically free units costing 1:hammers: and no explorers/hunters sent....
Maybe maintenance cost calculation is broken for AI?
 
But something isnt right about the priority establishment imo.

That's why i asked if something changed in the area of Food or maybe Health in terms of balance because the AI builds lot's of Food giving buildings at the start of the game.
I can't recall any recent code changes to get them to produce more of those but i am not sure about the balance or maybe AI handicap modifiers.
 
That's why i askes if something changed in the area of Food or maybe Health in terms of balance because the AI builds lot's of Food giving buildings at the start of the game.
I can't recall any recent code changes to get them to produce more of those but i am not sure about the balance or maybe AI handicap modifiers.
Cities are unhealthy on beginning.
Not sure if health/happiness changes are only for player or affect AI too in Handicaps @Toffer90
Those are for Noble:
<iHealthBonus>5</iHealthBonus>
<iHappyBonus>5</iHappyBonus>
 
If that happens the building is more important as the hunter in that moment for that city.
I did some experiment - strong reduce all buildings costs. AI starting build science, money(thay have about 1k money in reserve), anything else - but didn't build the hunters.
 
I did some experiment - strong reduce all buildings costs. AI starting build science, money(thay have about 1k money in reserve), anything else - but didn't build the hunters.

Next issue could be something in the unit evaluation because i saw them build Stone Throwers as explorers instead of Wanderers.
 
Even with almost free units and with hundreds of thousands of gold AIs still doesn't want to train units.
 
I did some experiment - strong reduce all buildings costs. AI starting build science, money(thay have about 1k money in reserve), anything else - but didn't build the hunters.

That about money is strange the AI should go for that with high priority but only if they are in Financial Trouble. Maybe the Financial Trouble evaluation is flawed??????
 
I added units to queue, built them, and then let AI autoplay (hunters, tribe and property control units).
Then it built 5 scouts, atlatl and then fell back to building research.

Tribe is unused in city. Hunters are hunting stuff and property control units seems to do their job.
They don't use gatherers to upgrade land.
 
Last edited:
Cities are unhealthy on beginning.
Not sure if health/happiness changes are only for player or affect AI too in Handicaps @Toffer90
Those are for Noble:
<iHealthBonus>5</iHealthBonus>
<iHappyBonus>5</iHappyBonus>
They should work for the AI too.
That's why i asked if something changed in the area of Food or maybe Health in terms of balance because the AI builds lot's of Food giving buildings at the start of the game.
I can't recall any recent code changes to get them to produce more of those but i am not sure about the balance or maybe AI handicap modifiers.
Before I rebalanced Handicaps the AI used to get these from Noble:
<iHealthBonus>2</iHealthBonus>
<iHappyBonus>4</iHappyBonus>
 
GlobalDefines and GlobalDefinesAlt both have had multiple "new" defines added. To support the new formulas and coding used for the new system.

If the AI is worried about it's Wealth over production then this change to appease a modmod/scenario maker, could be a contributor to the AI's problem. From GlobalDefines:

<!-- AI Gold Slider Safety Percent begin -->
<!-- This is the BASE amount of slider allocation required towards gold that the AI feels comfortable with -->
<!-- It noteworthily affects how much tolerance the AI has where it feels ready to grow -->
<!-- Reduce to make the AI more sensitive to gold concerns and increase for more reckless behavior -->
<!-- This may be rather interesting to convert to an AI personality matter or at least give a personality based modifier eventually -->
<!-- Original Value was set to 50 - I've adjusted to 40.-->
<Define>
<DefineName>SAFE_GOLD_PERCENT</DefineName>
<iDefineIntVal>40</iDefineIntVal>

Maybe put it back to 50?

Also there are as I said "new" defines that have changed the way the AI behaves as well. These imo should be compared to the Old Defines and maybe removed as Defines. Because again from the time line the testing on these new defines was not very long.

EDIT:
Also this Define was changed:

<Define>
<DefineName>INITIAL_AI_CITY_PRODUCTION</DefineName>
<iDefineIntVal>1</iDefineIntVal>

It was always 10 until the past few months when it got reduced to 1.

Why is it so hard to compare coding from pre v38, say SVN 9700 range when the AI was robust, with current SVN? Yes it's looking a 2 sets of coding line by line. There is that, but still that seems like an obvious way to go for starters.

It is also possible that the new system and underlying formula(s) just don't work as intended (seems that way from all the problems). Would it be a real Disaster to go back to Pre v38 base and work in it's confines again? Just maybe Firaxis really did know what they were doing?
 
Last edited:
That about money is strange the AI should go for that with high priority but only if they are in Financial Trouble. Maybe the Financial Trouble evaluation is flawed??????
No. Financial trouble isn't hindering them. According to watching chooseProduction. Money or priority really isn't the problem. It's that whatever is handed off to the brokerage system (MOST unit calls filter through this) never comes back to enter the queue. The stone thrower as an explore AI may have been queued before the wanderer was available too.
If the AI is worried about it's Wealth over production then this change to appease a modmod/scenario maker, could be a contributor to the AI's problem. From GlobalDefines:
This is what establishes the % at which the AI considers itself in financial trouble. But again, financial trouble isn't the issue. Units are being called to be queued and they simply aren't getting queued. Later selected buildings are coming up as more important to build.

Why is it so hard to compare coding from pre v38, say SVN 9700 range when the AI was robust, with current SVN? Yes it's looking a 2 sets of coding line by line. There is that, but still that seems like an obvious way to go for starters.
There's been a lot of that kind of work and all conclusions from this have oddly not been successful at solving the issue.
Would it be a real Disaster to go back to Pre v38 base and work in it's confines again?
Then try to remember all the hundreds of things that have been fixed since?

Just maybe Firaxis really did know what they were doing?
We're not struggling against firaxis. That was abandoned in this area years ago.
 
No. Financial trouble isn't hindering them. According to watching chooseProduction. Money or priority really isn't the problem. It's that whatever is handed off to the brokerage system (MOST unit calls filter through this) never comes back to enter the queue. The stone thrower as an explore AI may have been queued before the wanderer was available too.

Are you 100% sure that the buildings are queued later and have a lower priority. The AI city production code selects one of each to build the building is queued and the unit requested using the brokerage system. If the priority of the unit request is high enough the unit gets queued immediately but if the building is more important the unit won't be queued. This used to work and you already checked if the changes you made broke something.

Something messes with the build prioritys at the moment and I I can't see how going for meager wealth if they have lots of money already should happen unless there is another issue unrelated to the Ai production choice.
 
Are you 100% sure that the buildings are queued later and have a lower priority. The AI city production code selects one of each to build the building is queued and the unit requested using the brokerage system. If the priority of the unit request is high enough the unit gets queued immediately but if the building is more important the unit won't be queued. This used to work and you already checked if the changes you made broke something.

Something messes with the build prioritys at the moment and I I can't see how going for meager wealth if they have lots of money already should happen unless there is another issue unrelated to the Ai production choice.
I found the problem. Don't stress it. I did watch some odd behavior with that, yes, but it was the changes I made recently in bool CvCityAI::AI_chooseUnit in an attempt to eliminate what appeared to be some unnecessary processing that was the issue. I have checked a lot of recent changes but hadn't suspected the problem was in CvCityAI. I had assumed it was in the brokerage. In my search I had not followed the code yet into that function and when I did it quickly became clear what was wrong.

I don't have enough time to compile this tonight - and there's some other things I want to back out of backing out of now that I've found the source of the problem. So unfortunately it will be 24-48 hours out still due to tomorrow night being mostly spoken for as well already. So if you'd like to help everyone out here you could compile a new DLL with this:
Code:
bool CvCityAI::AI_chooseUnit(const char* reason, UnitAITypes eUnitAI, int iOdds, int iUnitStrength, int iPriorityOverride, CvUnitSelectionCriteria* criteria, UnitTypes eUnitType)
{//Adding a unit type direct selection here...
   CvString   unitAIType;

#ifdef USE_UNIT_TENDERING
   //   Have we already contracted for a unit?
   if ( m_bRequestedUnit )
   {
       return false;
   }
#endif

   if( iOdds < 0 || getCitySorenRandNum(100, "City AI choose unit") < iOdds )
   {
       if ( iPriorityOverride == -1 )
       {
           iPriorityOverride = m_iTempBuildPriority;
       }

       if (eUnitAI != NO_UNITAI)
       {
           CvInfoBase& AIType = GC.getUnitAIInfo(eUnitAI);
           unitAIType = AIType.getType();
       }
       else
       {
           unitAIType = "NO_UNITAI";
       }

#ifdef USE_UNIT_TENDERING
       if ( !isNPC() )
       {
           //   Check someone can build a suitable unit before putting out a tender for one.
           if ( eUnitAI == NO_UNITAI || eUnitType != NO_UNIT || GET_PLAYER(getOwnerINLINE()).bestBuildableUnitForAIType(NO_DOMAIN, eUnitAI, criteria) != NO_UNIT )
           {
               if( gCityLogLevel >= 2 )
               {
                   logBBAI("      City %S pop %d puts out tenders for %d unit strength of AIType: %s at priority %d (reason: %s)", getName().GetCString(), getPopulation(), iUnitStrength, unitAIType.c_str(), iPriorityOverride, reason);
               }

                   //   Put out a tender for this unit
                   GET_PLAYER(getOwnerINLINE()).getContractBroker().advertiseWork(iPriorityOverride,
                                                                                   NO_UNITCAPABILITIES,
                                                                                   getX_INLINE(),
                                                                                   getY_INLINE(),
                                                                                   NULL,
                                                                                   eUnitAI,
                                                                                   iUnitStrength,
                                                                                   criteria,
                                                                                   MAX_INT,
                                                                                   eUnitType);

                   m_bRequestedUnit = true;

                   return m_bRequestedBuilding;
           }
           //   Looks like we probably can't build it, but fallback check if we can ourselves, and if so just
           //   queue it here (handles edge cases where building requirements mean it can be built locally but
           //   not in capital or best coastal).  Do this by falling through to local handling
       }
#endif

       return AI_chooseUnitImmediate(reason, eUnitAI, criteria, eUnitType);
   }

   return false;
}
 
Then try to remember all the hundreds of things that have been fixed since?
They would be different, because the system is different. And many of those fixes that came inbetween would not even be relevant.

We're not struggling against firaxis. That was abandoned in this area years ago.

Difference of opinion and perspective at what is being looked at and how it's been looked at. But... if you have found a solution for the new way.... then carry on. All we can do is wait and watch...... then test. Sometimes modders have ideas that just don't pan out. No gold to be found in the bottom of the pan after all, just sand.
 
EDIT:
Also this Define was changed:

<Define>
<DefineName>INITIAL_AI_CITY_PRODUCTION</DefineName>
<iDefineIntVal>1</iDefineIntVal>

It was always 10 until the past few months when it got reduced to 1.

Why is it so hard to compare coding from pre v38, say SVN 9700 range when the AI was robust, with current SVN? Yes it's looking a 2 sets of coding line by line. There is that, but still that seems like an obvious way to go for starters.

It is also possible that the new system and underlying formula(s) just don't work as intended (seems that way from all the problems). Would it be a real Disaster to go back to Pre v38 base and work in it's confines again? Just maybe Firaxis really did know what they were doing?

I searched for this define in all files using Notepad++
There were only two instances of it:

Caveman2Cosmos\Assets\XML\GlobalDefines.xml (1 hit)
Line 406: <DefineName>INITIAL_AI_CITY_PRODUCTION</DefineName>
Caveman2Cosmos\Sources\CvCity.cpp (1 hit)
Line 530: changeOverflowProduction(GC.getDefineINT("INITIAL_AI_CITY_PRODUCTION"), 0);

It seems like this controls production overflow for AI.
Code:
if (GC.getGameINLINE().isFinalInitialized())
    {
        if (GET_PLAYER(getOwnerINLINE()).getNumCities() == 1)
        {
            for (iI = 0; iI < GC.getNumBuildingClassInfos(); iI++)
            {
                if (GC.getCivilizationInfo(getCivilizationType()).isCivilizationFreeBuildingClass(iI))
                {
                    eLoopBuilding = ((BuildingTypes)(GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(iI)));

                    if (eLoopBuilding != NO_BUILDING)
                    {
                        setNumRealBuilding(eLoopBuilding, 1);
                    }
                }
            }

            if (!isHuman())
            {
                changeOverflowProduction(GC.getDefineINT("INITIAL_AI_CITY_PRODUCTION"), 0);
            }
        }
    }
@Thunderbrd @alberts2 what this define actually does?

Civ4 modiki doesn't know what it does, setting it to 10000000 to see what explodes.
It appears to be some sort of city kickstart, basically free production overflow, that is given to city when its founded.
If it isn't scaled then it very quickly becomes useless.
Even with scaling AI could get only cheapest buildings - that is alpha male/female or buildings from few first columns.
 
Last edited:
what this define actually does?
It gives the first AI city a couple of hammers that can be put into the first thing they build for free when the city is founded.

It is a pretty stupid define that should imo be removed completely from the game.

Edit: You are a strange one, you ask a question and then go ahead and answer it right away in the same post. This is not the first time to say the least. ^^
 
It gives the first AI city a couple of hammers that can be put into the first thing they build for free when the city is founded.

It is a pretty stupid define that should imo be removed completely from the game.
So its what I suspected.
Is it scaled by game speed or era?

I wasn't sure of what it does, and I wanted someone to confirm my test :p
For example that define could make several buildings free for AI (Blitz/Nightmare).
 
It is a pretty stupid define that should imo be removed completely from the game.
Then why did Firaxis put it in the game?
It is a pretty stupid define that should imo be removed completely from the game.
Firaxis did not think so. Straight from the vanilla Civ IV GlobalDefines.xml :
<Define>
<DefineName>INITIAL_AI_CITY_PRODUCTION</DefineName>
<iDefineIntVal>10</iDefineIntVal>
</Define>

I know, I know, modders know better than the Original Devs. But they also made the engine and exe that we can not see or manipulate directly either. Hmmm.........dumb Firaxis.....
 
Back
Top Bottom