[SDK] Advanced Unit Automations

CONFIRMED!
The fix provided by Afforess, the first one then overwritten by the second post with CvSelectionGroup.cpp worked! Here is the screenshot showing a worker working a road!

View attachment 256528
 
Greetings everyone, this is my first ever post in this FORUM so as you might probably suppose I'm a total noobie in Civ4 XML stuff, applying codes, etc...
But anyway, I will not bore you with much verbiage.

I downloaded 'Automations.008.zip' file. But I really don't know how to apply it. I'm playing BTS 3.19.
Can anyone help me on this?
 
You need to be able to compile a new dll before you can merge Advanced Automations in, as it is a SDK mod. You need basic C++ skills, and a working compiler. You can get a compiler working by reading the guide on the modiki.
 
attachment.php


border patrol does not work yet correctly for ships. this ship is stuck and when I add a modern ship like destroyer and set it to border patrol, the whole game gets slowed down - "laggy interface".

also, other people tell me, their ship is driving everywhere (around the sea, even outside the borders) when set to border patrol.
 
attachment.php


border patrol does not work yet correctly for ships. this ship is stuck and when I add a modern ship like destroyer and set it to border patrol, the whole game gets slowed down - "laggy interface".

also, other people tell me, their ship is driving everywhere (around the sea, even outside the borders) when set to border patrol.

Afforess is on vacation for next two weeks so be a while before he can answer your question on this :).
 
attachment.php


border patrol does not work yet correctly for ships. this ship is stuck and when I add a modern ship like destroyer and set it to border patrol, the whole game gets slowed down - "laggy interface".

also, other people tell me, their ship is driving everywhere (around the sea, even outside the borders) when set to border patrol.

I've made a couple changes for a future version (which will be out in a few weeks, I'm afraid...) that will allow you to force Border Patrol units to stay inside their borders, and I changed the AI a bit. Anyway, you should be aware, Border Patrol units CAN leave the borders, and go up to 2 tiles away before they come back. I meant it to be that way so they could kill units on the outskirts of the borders.

I haven't tested much with late-game units, I'll do that when I'm back. Ciao.
 
:) I'm giddy with excitement having just discovered this modcomp.

Brilliant work, Afforess! :bowdown:

I've had people asking it to be included in PIG mod and I can't see any reason not to satiate them.
 
Are all the updated files located in the OP?

Yes. Afforess does A New Dawn (AND) development, however that versions there of this should be the same. He's said he'll do more later when he comes back in a couple weeks, at that point he'll update the op here.
 
If Afforess comments his AUA in AND (search string), I'm sure someone here can just upload relevant files here for everyone else :).
 
Just checked SVN, he don't comment with name of modcomp (possibly to many, many modcomps he includes in AND and got lazy) so it will have to be up to someone who actually understand c++ code to look through code blocks by Afforess and figure out if they are for AUA. I think the new stuff is still in the same files he has in Opening Post but go ahead and search through others using search string "afforess".
 
*facepalm* There is no secret updated AND code for this modcomp. He didn't update the AND code and say hahahaha and not update this. You guys are going to have to wait

Seriously, what you have now is very stable and very playable, OK? What he has in AND is a small update of Border Patrol and few AI tweaks. You can still play with the current AUA for two weeks, then update to next version in two weeks. You WILL NOT, NOT, NOT! lose anything by it :).
 
@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");
 
My updated code? I havent updated the code. Even CCV 4.14B includes the mod as it is (with one little bugfix). I just had a look at it when I saw your post. I haven't done anything until now.

And I'm not sure if I should conquer this little mod while Afforess is on vacation. It's his mod. And when I remember right he already has got a new version. I think this should be a small hint for him how to (perhaps) improve his new code again and we should wait some time...
 
My interest in the automations has dwindled but I absolutely need to have that spy-waking-up part, there simply is no way around that.
Looking at it, I found something strange: This part of CvUnit::doTurn() here
Code:
	if (isSpy() && m_iSleepTimer > 0)
	{
		if (getFortifyTurns() == GC.getDefineINT("MAX_FORTIFY_TURNS"))
		{
			getGroup()->setActivityType(ACTIVITY_AWAKE);
			m_iSleepTimer = 0;
		}
	}
.. is located before this part:
Code:
	if (hasMoved())
	{
		if (isAlwaysHeal())
		{
			doHeal();
		}
	}
	else
	{
		if (isHurt())
		{
			doHeal();
		}

		if (!isCargo())
		{
			[U]changeFortifyTurns(1)[/U];
		}
	}
Which probably means that the spy will sleep 6 turns instead of just 5.

But I think I can do that (waking up after 5 turns) without any new member variable that gets saved and even without any new mission type. The idea is simple: if this round's changeFortifyTurns causes the fortifyTurns to reach MAX_FORTIFY_TURNS, set activity type to active if the unit was asleep.

Code:
		if (!isCargo())
		{
			[B]bool bAwaken = false;
			if (isSpy() && (getFortifyTurns() [U]+ 1[/U]) == GC.getDefineINT("MAX_FORTIFY_TURNS") && canEspionage(plot(), true))
			{
				bAwaken = true;
			}[/B]

			[U]changeFortifyTurns(1);[/U]

			[B]if (bAwaken && getGroup()->getActivityType() == ACTIVITY_SLEEP)
			{
				getGroup()->setActivityType(ACTIVITY_AWAKE);
			}[/B]
		}
 
Back
Top Bottom