AI jumping further than allowed? 3.2 LY with 3.8 LY fuel

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Milo
---- E L I T E ----
---- E L I T E ----
Posts: 462
Joined: Mon Sep 17, 2018 5:01 pm

AI jumping further than allowed? 3.2 LY with 3.8 LY fuel

Post by Milo »

19:11:36.925 [script.debug] -[ShipEntity(OOAIPrivate) performHyperSpaceExitReplace:toSystem:]: ----- WARNING: DEBUG: <ShipEntity 0x8959df90>{"Cruzer" position: (1.19362e+006, 3.52527e+006, -1.36659e+006) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT} Jumping 3.200000 which is further than allowed. I have 38 fuel
19:11:37.033 [script.debug] -[ShipEntity(OOAIPrivate) performHyperSpaceExitReplace:toSystem:]: ----- WARNING: DEBUG: <ShipEntity 0x89576220>{"Cobra Mark IV" position: (8.00245e+006, 2.40108e+007, -9.01716e+006) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT} Jumping 3.200000 which is further than allowed. I have 38 fuel
19:11:37.093 [script.debug] -[ShipEntity(OOAIPrivate) performHyperSpaceExitReplace:toSystem:]: ----- WARNING: DEBUG: <ShipEntity 0x8958a7a0>{"Fer-de-Lance" position: (1.08945e+007, 3.28118e+007, -1.23855e+007) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT} Jumping 3.200000 which is further than allowed. I have 38 fuel
19:11:37.112 [script.debug] -[ShipEntity(OOAIPrivate) performHyperSpaceExitReplace:toSystem:]: ----- WARNING: DEBUG: <ShipEntity 0x888ef110>{"Cobra Mark III Leader" position: (1.14354e+007, 3.44041e+007, -1.29834e+007) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT} Jumping 3.200000 which is further than allowed. I have 38 fuel
performHyperSpaceExitReplace is in shipEntityAI.m and the relevant code is as follows:

Code: Select all

	float dist = [[sDests oo_dictionaryAtIndex:i] oo_floatForKey:@"distance"];
	if (dist > [self maxHyperspaceDistance] || dist > fuel/10) 
	{
		OOLogWARN(@"script.debug", @"DEBUG: %@ Jumping %f which is further than allowed.  I have %d fuel", self, dist, fuel);
	}
	fuel -= 10 * dist;
Meanwhile shipEntity.m defines maxHyperspaceDistance:

Code: Select all

- (double) maxHyperspaceDistance
{
	return MAX_JUMP_RANGE; // defined in ShipEntity.h:   #define MAX_JUMP_RANGE	7.0	// the 7 ly limit
}
A 3.2 dist is not greater than 7.0 and it is also not > 3.8 (38 fuel divided by 10). Is [self maxHyperspaceDistance] not getting the expected value?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6821
Joined: Wed Feb 28, 2007 7:54 am

Re: AI jumping further than allowed? 3.2 LY with 3.8 LY fuel

Post by another_commander »

Fixed in commit 8f3921. It was an integer division issue. If fuel (an unsigned integer value) was 38 and distance was 3.2LY, then dividing 38/10 gives 3 in integer arithmetic and the second condition was becoming true, triggering the warning. Fixed by changing the 10 to 10.0f, promoting the operation to float division and yielding thus the correct result.
Post Reply