[SDK] Advanced Unit Automations

I'm not saying it wouldn't work, I just don't want it because I have hope that I can make my Better BUG AI savegame compatible to basic Better BTS AI, and new automations would almost certainly kill that.
If I am wrong and it's possible to make it savegame compatible even with AUA I'll merge it in some time later, for now it's low priority though.

If you already have a merge though, would you mind making the changed SDK files available to me? That might save me some effort.
 
Interesting Fuyu, I wrote the Spy Sleep code a long time ago, so I didn't pay much attention to detail then, and simply chose the quickest and dirtiest method that I knew would work. (Since Save compatibility means little to me).
 
I can see AND sources get updated... cannot wait for the next AUA update. :)
 
Yep. I've fixed a couple issues with multiple automated units not attacking in stacks, and tried to discourage units from suiciding more.
 
I won't update my own public mod without your AUA update. Can you tell us any release date? :D
 
Is now soon enough? ;)

v1.33 Update

Changes:
  • Automated Units will not attack enemy units when they are surrounded
  • New Player Option: Stay In Border, which forces Border Patrolling units to never leave their borders
  • Automated Units are less likely to attack when the odds are poor
  • Automated Units will now attack in groups instead of only attacking with the head unit of the stack




@Cybah

I had a quick view at the code. The code is not optimal. It can produces stupid results in many cases. Here an example:

PHP:
bool CvUnitAI::AI_patrolBorders()
{
	PROFILE_FUNC();
	
	CvPlot* pBestPlot;
	int iValue;
	int iBestValue;

	iBestValue = 0;
	pBestPlot = NULL;
	
	int iDX, iDY;

	int iSearchRange = baseMoves();

	for (iDX = -(iSearchRange); iDX <= iSearchRange; iDX++)
	{
		for (iDY = -(iSearchRange); iDY <= iSearchRange; iDY++)
		{
			CvPlot* pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iDX, iDY);

			if (pLoopPlot != NULL)
			{
				if (canMoveInto(pLoopPlot))
				{
					DirectionTypes eNewDirection = estimateDirection(plot(), pLoopPlot);
					iValue = GC.getGameINLINE().getSorenRandNum(1000, "AI Border Patrol");
					if (pLoopPlot->isBorder(true))
					{
						iValue += GC.getGameINLINE().getSorenRandNum(1000, "AI Border Patrol");
					}
					else if (pLoopPlot->isBorder(false))
					{
						iValue += GC.getGameINLINE().getSorenRandNum(500, "AI Border Patrol");
					}
					//Avoid heading backwards, we want to circuit our borders, if possible.
					if (eNewDirection == getOppositeDirection(getFacingDirection(false)))
					{
						iValue /= 25;
					}
					else if (isAdjacentDirection(getOppositeDirection(getFacingDirection(false)), eNewDirection))
					{
						iValue /= 10;
					}
					if (pLoopPlot->getOwnerINLINE() != getOwnerINLINE())
					{
						iValue /= 10;
					}
					if (iValue > iBestValue)
					{
						iBestValue = iValue;
						pBestPlot = pLoopPlot;
					}
				}
			}
		}
	}
	if (pBestPlot != NULL)
	{
		FAssert(!atPlot(pBestPlot));
		getGroup()->pushMission(MISSION_MOVE_TO, pBestPlot->getX_INLINE(), pBestPlot->getY_INLINE());
		return true;
	}
	
	return false;
}

The start value is a random number from 0 to 999. And this value can be divided by 250. So all start values from 0 to 249 can give you a value of int 0 at the end. And because of iValue > iBestValue (initial 0) many valid plots different from NULL are simply ignored.

To fix it search through the code and add offsets.

Here for example:

PHP:
iValue = 1000 + GC.getGameINLINE().getSorenRandNum(1000, "AI Border Patrol");

Not Optimal how? First off, the whole point of the function is to get units to traverse around border tiles. Nothing else. It weights tiles that have more borders heavily, and doesn't consider the rest. I WANT the function to fail (return false) if there are no borders to circuit. For example, if the tile in your example only have a value of 50 from the random number, and it was promptly divided into oblivion, that's fine. It would be strange to see the unit head back and forth over two tiles and get stuck that way. The heavy emphasis on the divisors makes it harder to find valid plots, so the function returns false more often. That way, the unit does something else smarter, like heading back to the nearest city to wait.
 
You appear to be missing these two txt keys:
Code:
	<TEXT>
		<Tag>TXT_KEY_MISSION_ESPIONAGE_SLEEP</Tag>
		<English>Gather Intel</English>
		<French>Récolte d'Infos</French>
		<German>Sammle Informationen</German>
		<Italian>Gather Intel</Italian>
		<Spanish>Gather Intel</Spanish>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_MISSION_ESPIONAGE_SLEEP_HELP</Tag>
		<English>This unit will gather intelligence and not awaken until it reaches the maximum espionage bonus</English>
		<French>Cette Unité va récolter des Informations et devenir à nouveau active lorsqu'elle aura atteint son bonus maximum d'espionnage.</French>
		<German>Diese Einheit wird Informationen sammeln und nicht aufwachen bis sie ihr Maximum an Spionagepunkten erreicht hat</German>
		<Italian>This unit will gather intelligence and not awaken until it reaches the maximum espionage bonus</Italian>
		<Spanish>This unit will gather intelligence and not awaken until it reaches the maximum espionage bonus</Spanish>
	</TEXT>
 
Im having some trouble with the spy sleep automation, it is displaying with the sentry until healed icon as well as its txt, but its function is correct.
I cant figure out where i copied stuff over wrong. Any ideas?
 

Attachments

  • Civ4ScreenShot0002.JPG
    Civ4ScreenShot0002.JPG
    57.4 KB · Views: 60
It's likely you messed up the order. The order of missions in CvEnums.h must EXACTLY match CIV4MissionInfos.xml.
 
AI_huntRange is declared wrong in the header file. It should be
Code:
bool AI_huntRange(int iRange, int iOddsThreshold, bool bStayInBorders, int iMinValue);
And im finding it very difficult to compile this as a standalone (for testing purposes). THere are problems abound with Cvglobals, the stock bts one doesnt work.

Has anyone else gotten this fully working?
 
Oops. That's what I get for not compiling. Thanks, I updated the download.
 
Trying to compile this on its own, errors in CvXMLLoadUtilitySetMod.cpp.
Heres a few:
Code:
CvXMLLoadUtilitySetMod.cpp(22) : error C2039: 'resetModLoadControlVector' : is not a member of 'CvGlobals'
CvXMLLoadUtilitySetMod.cpp(25) : error C2039: 'setModLoadControlVector' : is not a member of 'CvGlobals'
CvXMLLoadUtilitySetMod.cpp(32) : error C2065: 'CvXMLLoadUtilityModTools' : undeclared identifier
CvXMLLoadUtilitySetMod.cpp(32) : error C2065: 'p_szDirName' : undeclared identifier
CvXMLLoadUtilitySetMod.cpp(32) : error C2061: syntax error : identifier 'CvXMLLoadUtilityModTools'
CvXMLLoadUtilitySetMod.cpp(34) : error C2227: left of '->GetProgramDir' must point to class/struct/union
CvXMLLoadUtilitySetMod.cpp(34) : error C3861: 'p_szDirName': identifier not found, even with argument-dependent lookup
CvXMLLoadUtilitySetMod.cpp(41) : error C2039: 'logMLF' : is not a member of 'CvXMLLoadUtility'
 
Trying to compile this on its own, errors in CvXMLLoadUtilitySetMod.cpp.
Heres a few:
Code:
CvXMLLoadUtilitySetMod.cpp(22) : error C2039: 'resetModLoadControlVector' : is not a member of 'CvGlobals'
CvXMLLoadUtilitySetMod.cpp(25) : error C2039: 'setModLoadControlVector' : is not a member of 'CvGlobals'
CvXMLLoadUtilitySetMod.cpp(32) : error C2065: 'CvXMLLoadUtilityModTools' : undeclared identifier
CvXMLLoadUtilitySetMod.cpp(32) : error C2065: 'p_szDirName' : undeclared identifier
CvXMLLoadUtilitySetMod.cpp(32) : error C2061: syntax error : identifier 'CvXMLLoadUtilityModTools'
CvXMLLoadUtilitySetMod.cpp(34) : error C2227: left of '->GetProgramDir' must point to class/struct/union
CvXMLLoadUtilitySetMod.cpp(34) : error C3861: 'p_szDirName': identifier not found, even with argument-dependent lookup
CvXMLLoadUtilitySetMod.cpp(41) : error C2039: 'logMLF' : is not a member of 'CvXMLLoadUtility'

I didn't include those files (and they aren't even part of BTS, it's a part of RevDCM), so your problem isn't caused by me.
 
New Release. Only some minor bugs that I missed before. Only CvPlot.cpp and CvUnitAI.cpp were changed. Save-Compatible. Enjoy! ;)
 
Top Bottom