Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

AI-induced migraines ahoy!

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

Post Reply
User avatar
thirdeye77
Above Average
Above Average
Posts: 21
Joined: Sat Jul 29, 2006 8:12 pm

AI-induced migraines ahoy!

Post by thirdeye77 »

Ohhhh....my head hurts. The last 2 days have been spent trying to get an apparently straightforward AI to work:

Code: Select all

ENTER = ("scanForNearestShipWithRole: shipwreck");
"TARGET_FOUND" = (setTargetToFoundTarget, setDestinationToTarget, "setSpeedFactorTo: 0.3", "setDesiredRangeTo: 350.0", performFlyToRangeFromDestination);
"NOTHING_FOUND" = ("setStateTo: WANDER");
"DESIRED_RANGE_ACHIEVED" = (becomeExplosion, "setStateTo: SCHOOL");
It should be simple - the ship scans for a "shipwreck" and flies towards it until it reaches a range of 350m and then explodes (for testing purposes). So how come the ship explodes immediately even tho its 10km away from the destination????

I know its picking up the "shipwreck" and will fly towards it correctly without the "DESIRED_RANGE_ACHIEVED" line.

I've also tried using the checkCourseToDestination method as used in other AIs but it seems the desired range achieved message is always received immediately, regardless of the actual range to destination. Having played around with every combination of methods I can think of I'm now kinda stumped :?
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

first thing I notice is the statechange AFTER becomeExplosion.

But your AI looks sound otherwise,
maybe a previous method messaging "range achieved",
we need to see the whole AI.

Try using a statechange to state "EXPLODE" instead of the immediate method.
Riding the Rocket!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

There is a debug way to have the nearby objects dump their AI states into the logfile...I don't recall how anymore.
I used a cumbersome method of commsmessages a whileback to keep track of the AI while in-game.

One thing you may try is:

Code: Select all

"NOTHING_FOUND" = ("commsMessage: No target in range");
UPDATE = ("commsMessage: scanning again", "scanForShipWithRole: wreckage");
Riding the Rocket!
User avatar
thirdeye77
Above Average
Above Average
Posts: 21
Joined: Sat Jul 29, 2006 8:12 pm

Post by thirdeye77 »

The becomeExplosion was only put in there to make it really obvious when the statechange was coming into play. It won't be there in the finished version.

Desired range achieved seemed to be flagged as soon as scanForShipWithRole was used, regardless of whether a desired range had been set or not, or if the range was set to 0 or 100000.

I've now managed to get it to work by just sticking the Desired Range Achieved flag in a separate state:

Code: Select all

"CHECK_RANGE" = { ENTER = (); "DESIRED_RANGE_ACHIEVED" = ("setStateTo: SCHOOL"); };
and then switching to this state after the performFlyToRangeFromDestination:

Code: Select all

"TARGET_FOUND" = (setTargetToFoundTarget, setDestinationToTarget, "setSpeedFactorTo: 1.0", "setDesiredRangeTo: 500.0", performFlyToRangeFromDestination, "setStateTo: CHECK_RANGE");
It seems to work now, no idea why!

Thanks for the input Arexack_Heretic :D
Glad to know I'm not the only one littering comms messages throughout the AI. Must remember to take them out in the finished product :roll:
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

thirdeye77 wrote:
Glad to know I'm not the only one littering comms messages throughout the AI. Must remember to take them out in the finished product :roll:
I'm doing it all the time. It seems the best way for checking out AIs.

Hmmm, putting things in seperate states could be a way of dealing with a problem I had in an AI. Should try it out...
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

I had a similar problem with the orb-missile...couldnt just launch it, but spawning it it didn't seem able to lock on to a target.
It just exploded, I used performFlyToRange as well.
Riding the Rocket!
Post Reply