Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animals are disobeying orders given to them in the map editor. #1948

Open
Inveriss opened this issue Jan 2, 2024 · 2 comments
Open

Animals are disobeying orders given to them in the map editor. #1948

Inveriss opened this issue Jan 2, 2024 · 2 comments

Comments

@Inveriss
Copy link

Inveriss commented Jan 2, 2024

Hello

In the map editor, when you click on any character, first you will be able to give them proper order / behavior like: stationary, on guard, seek enemy and others. This works fine with all kind of human characters because there is a code for that.

Unfortunately creators gave animals only code for one behavior which is "MAX_ROAMING_RANGE", which corresponds to the function "seek enemy". That's why they are running whenever and wherever they want.

Is it possible to improve the code a bit and at least give bloodcats and crepitus the ability to behave the way we want them to in modifications?

I think the base code for that is in file "Game / Tactical / AIUtils.cc" in line 1933. For humans there are "Cases" with all kind of orders but not for the mentioned animals.

Would it take a lot of changes to give these animals these "cases" also with this "switch" function for all the behaviors?

Regards

JA2S version Game version Vanilla bug? Used to work?
0.21.0 JA2 Gold 1.12 ENG YES NO
INT16 RoamingRange(SOLDIERTYPE *pSoldier, INT16 * pusFromGridNo)
{
	if ( CREATURE_OR_BLOODCAT( pSoldier ) )
	{
		if ( pSoldier->bAlertStatus == STATUS_BLACK )
		{
			*pusFromGridNo = pSoldier->sGridNo; // from current position!
			return(MAX_ROAMING_RANGE);
		}
	}
	if ( pSoldier->bOrders == POINTPATROL || pSoldier->bOrders == RNDPTPATROL )
	{
		// roam near NEXT PATROL POINT, not from where merc starts out
		*pusFromGridNo = pSoldier->usPatrolGrid[pSoldier->bNextPatrolPnt];
	}
	else
	{
		// roam around where mercs started
		//*pusFromGridNo = pSoldier->sInitialGridNo;
		*pusFromGridNo = pSoldier->usPatrolGrid[0];
	}

	switch (pSoldier->bOrders)
	{
		// JA2 GOLD: give non-NPCs a 5 tile roam range for cover in combat when being shot at
		case STATIONARY:
			if (pSoldier->ubProfile != NO_PROFILE || (pSoldier->bAlertStatus < STATUS_BLACK && !(pSoldier->bUnderFire)))
			{
				return( 0 );
			}
			else
			{
				return( 5 );
			}
		case ONGUARD:
			return( 5 );
		case CLOSEPATROL:
			return( 15 );
		case RNDPTPATROL:
		case POINTPATROL:
			return(10 );     // from nextPatrolGrid, not whereIWas
		case FARPATROL:
			if (pSoldier->bAlertStatus < STATUS_RED)
			{
				return( 25 );
			}
			else
			{
				return( 50 );
			}
		case ONCALL:
			if (pSoldier->bAlertStatus < STATUS_RED)
			{
				return( 10 );
			}
			else
			{
				return( 30 );
			}
		case SEEKENEMY:
			*pusFromGridNo = pSoldier->sGridNo; // from current position!
			return(MAX_ROAMING_RANGE);
		default:
			return(0);
	}
}
@momoko-h
Copy link
Contributor

momoko-h commented Jan 3, 2024

Would it take a lot of changes? If you really just want to change the behavior of RoamingRange(), then all it takes would be to disable the first if block. One could do that by just removing the block, but we prefer not to change vanilla behavior unconditionally.
That means you would have to add a new game option. If you're interested in implementing this yourself (your best path forward if you need this feature urgently) then start by looking at the following files:

game.schema.yaml (the 'ai' section)
GamePolicy.h
DefaultGamePolicy.cc

For your mod you could then advise players to set this new option in game.json.

The other approach to allow mods to override default game behavior are Lua scripts, which means you would have to add an Obervable callback for RoamingRange(). This is more flexible but also a bit more complex to implement.

@Inveriss
Copy link
Author

Inveriss commented Jan 3, 2024

Thanks a lot for additional info. I will try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants