Home » MODDING HQ 1.13 » v1.13 Coding Talk » Roof climbing problem in 1.13
Roof climbing problem in 1.13[message #344502] Sun, 13 March 2016 10:44 Go to next message
Deleted.

 
Messages:2656
Registered:December 2012
Location: Russian Federation
1. In 1.13, roof climbing used ASTAR.
2. At some moment, ASTAR was disabled.
3. As a result, roof climbing is partially broken now.
4. As solution, all functions that use ASTAR should be reverted to vanilla state.

For example, FindClosestClimbPoint in FindLocations.cpp:
// 0verhaul:  This function is optimized to take advantage of the new climb point info.

if (gpWorldLevelData[ sGridNo].ubExtFlags[0] & MAPELEMENT_EXT_CLIMBPOINT)


MAPELEMENT_EXT_CLIMBPOINT is set in void AStarPathfinder::ExecuteAStarLogic(), which is disabled.

So, all functions that use MAPELEMENT_EXT_CLIMBPOINT should be reverted to vanilla state:
FindClosestClimbPoint, FindDirectionForClimbing

Another problem:
in GenerateBuilding (Buildings.cpp), the following code is used:
if ( !(gpWorldLevelData[ sCurrGridNo ].ubExtFlags[0] & MAPELEMENT_EXT_ROOFCODE_VISITED) )
		{
			gpWorldLevelData[ sCurrGridNo ].ubExtFlags[0] |= MAPELEMENT_EXT_ROOFCODE_VISITED;

			gubBuildingInfo[ sCurrGridNo ] = ubBuildingID;

			// consider this location as possible climb gridno
			// there must be a regular wall adjacent to this for us to consider it a
			// climb gridno

What is interesting is
gubBuildingInfo[ sCurrGridNo ] = ubBuildingID;

which sets building information for the tile that is outside of the building. As a result, all tiles adjacent to building are set as they belong to that building, as a result, SameBuilding returns TRUE when first gridno is inside building and second gridno is outside of the building.
There's no such code in vanilla source, this looks like some old 1.13 bug.

Another problem:
when AI tries to find a path to a disturbance on different level, it first searches for a closest climb point.
Then, if the climbing point is found, it tries to estimate path cost to climb point, at which moment it fails if the soldier is already standing at the climb point, because EstimatePathCostToLocation returns 0.
This means that if AI was moving to climb and reached the climb point, next turn instead of climbing he moves to another climb point or simply decides taking cover or something else, because his seacrh for closest disturbance call fails.

--------------------------------------------------------------------------------------------------------------

My solution to some probems, implemented and tested in ja2+ai:

in Buildings.cpp/FindClosestClimbPoint:
allow climbing from the spot where soldier stands:
Toggle Spoiler


In AIUtils.cpp/EstimatePathCostToLocation:
don't return 0 if soldier is standing at climb point:
Toggle Spoiler


FindLocations.cpp/FindClosestClimbPoint: new calculation using FindHeigherLevel
Toggle Spoiler


FindLocations.cpp/FindDirectionForClimbing: new calculation using FindHeigherLevel/FindLowerLevel
Toggle Spoiler


Hope that helps.

[Updated on: Sun, 13 March 2016 10:47]




Left this community.

Report message to a moderator

Lieutenant

Re: Roof climbing problem in 1.13[message #344527 is a reply to message #344502] Mon, 14 March 2016 09:40 Go to previous messageGo to next message
wanne (aka RoWa21) is currently offline wanne (aka RoWa21)

 
Messages:1961
Registered:October 2005
Location: Austria
sevenfm, thanks for the climbing fixes. I hope I merged all the patches you posted here correctly to the 1.13 source...

EDIT: I can't compile the code, because the 1.13 "Water" function only takes one parameter and your (modified) function takes 2 parameters. Can you post your "Water" function.
This is the current 1.13 "Water" function:

BOOLEAN Water( INT32 sGridNo )
{
	MAP_ELEMENT *			pMapElement;
	
	if( TileIsOutOfBounds( sGridNo ) )
	{
		return( FALSE );
	}

	pMapElement = &(gpWorldLevelData[sGridNo]);
	if ( TERRAIN_IS_WATER( pMapElement->ubTerrainID) )
	{
		// check for a bridge!  otherwise...
		return( TRUE );
	}
	else
	{
		return( FALSE );
	}
}


Please also post the source code changes that are calling your 2 parameter "Water" function, so I will know which second parameter I have to pass to the function on all places. Thanks.

[Updated on: Mon, 14 March 2016 09:47]

Report message to a moderator

Sergeant Major

Re: Roof climbing problem in 1.13[message #344529 is a reply to message #344527] Mon, 14 March 2016 10:43 Go to previous messageGo to next message
Deleted.

 
Messages:2656
Registered:December 2012
Location: Russian Federation
Sorry I posted the code from my ja2+ai project, where I also changed Water, DeepWater and WaterTooDeepForAttack functions to accepts second parameter (level), as it allows AI to make correct decisions for locations on bridges (roof above the water).
For the simple roof climbing fix it should be enough to use default 1.13 water checks, so you can simply remove second (level) parameter, or you can use updated functions and change all instances in the code to use correct second parameter (usually pSoldier->pathing.bLevel)

The checks in Water functions are simple - return FALSE if level > 0, because we cannot have water on roofs anyway
here's the code:
Toggle Spoiler


There are also some other roof climbing decision problems in DecideAction, for example I think there's a path in RED seek code when AI will not climb when it should, but fixing it requires much more changes than simple patch. I think the original RED seek logic was partially broken at the time when flanking was added originally.

There's also a problem with the vanilla code that creates climbing spots for building, especially on some maps where building info is not set up correctly, but I never looked too deep to fix it. The result is that AI cannot climb on some buildings even when the climbing code works correcly (for example, some Wildfire maps), but this probably should be fixed with map editor.



Left this community.

Report message to a moderator

Lieutenant

Re: Roof climbing problem in 1.13[message #344541 is a reply to message #344529] Mon, 14 March 2016 19:05 Go to previous message
wanne (aka RoWa21) is currently offline wanne (aka RoWa21)

 
Messages:1961
Registered:October 2005
Location: Austria
Thanks, I will commit the patch tomorrow.

EDIT: Bugfixes are committed. I also updated the "Water", ... methods with the additional parameter

[Updated on: Tue, 15 March 2016 14:47]

Report message to a moderator

Sergeant Major

Previous Topic: Path finding problems in 1.13
Next Topic: Item choices
Goto Forum:
  


Current Time: Tue Feb 18 22:08:24 GMT+2 2025

Total time taken to generate the page: 0.00936 seconds