Thanks Eric. I made that change and a similar one in RETREAT, and also lowered some of the speeds to reduce the (slight) risk of collision. I tried compensating for possible performFaceDestination issues in "GO_TO_COORDS", but sticking performFlyToRangeFromDestination in UPDATE seemed to make the ships too reckless, and adding pauses destroyed the elegance of the final approach! So, unless there's something clever I haven't thought of, I think I've pushed this AI as far as I can. Which is probably far enough, given that I've only witnessed one ship getting stuck in "GO_TO_COORDS" so far, and overall the ships are behaving with more "intelligence" than I've seen before in Oolite.
I've no idea why performFaceDestination doesn't always seem to work. I can understand why it wouldn't if the ship were very close to another object, but a FRUSTRATED line should take care of that - and in the one instance I had of a ship getting stuck in "GO_TO_COORDS", it didn't. Oh well - it's beyond my control, as the Vicomte de Valmont would say.
Here's the revised code for RETREAT, "GO_TO_COORDS" and ABORT anyway:
Code: Select all
RETREAT = {
ENTER = (recallDockingInstructions, "setSpeedTo: 0.0", setDestinationToDockingAbort, performFaceDestination, "pauseAI: 10");
"FACING_DESTINATION" = ("setSpeedFactorTo: 0.5", "setDesiredRangeTo: 500.0", performFlyToRangeFromDestination);
"DESIRED_RANGE_ACHIEVED" = ("setSpeedTo: 0.0", requestDockingCoordinates, "setStateTo: AWAIT_COORDS");
"DOCKING_ABORTED" = ("setStateTo: ABORT");
"COLLISION" = ("setStateTo: ABORT");
"RESTART_DOCKING" = ("setStateTo: GLOBAL");
ATTACKED = (setTargetToPrimaryAggressor, "setAITo: taranisDefenderAI.plist");
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, "setAITo: taranisDefenderAI.plist");
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: taranisDefenderAI.plist");
EXIT = ();
UPDATE = ("setSpeedFactorTo: 1.0", "setDesiredRangeTo: 500.0", performFlyToRangeFromDestination, "pauseAI: 10");
};
"GO_TO_COORDS" = {
ENTER = (performFaceDestination);
FRUSTRATED = ("setSpeedTo: 0.0", performFaceDestination);
"FACING_DESTINATION" = (recallDockingInstructions, performFlyToRangeFromDestination);
"DESIRED_RANGE_ACHIEVED" = (requestDockingCoordinates, "setStateTo: AWAIT_COORDS");
"DOCKING_ABORTED" = ("setStateTo: ABORT");
"COLLISION" = ("setStateTo: ABORT");
"RESTART_DOCKING" = ("setStateTo: GLOBAL");
ATTACKED = (setTargetToPrimaryAggressor, "setAITo: taranisDefenderAI.plist");
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, "setAITo: taranisDefenderAI.plist");
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: taranisDefenderAI.plist");
EXIT = ();
UPDATE = ();
};
ABORT = {
ENTER = (abortDocking, "setSpeedTo: 0.0", setDestinationToDockingAbort, "setDesiredRangeTo: 500.0", performFaceDestination, "pauseAI: 10");
FRUSTRATED = ("setSpeedTo: 0.0", performFaceDestination);
"FACING_DESTINATION" = ("setSpeedFactorTo: 0.5", "setDesiredRangeTo: 500.0", performFlyToRangeFromDestination);
"RESTART_DOCKING" = ("setStateTo: GLOBAL");
"REACHED_SAFETY" = (performIdle, "setStateTo: GLOBAL");
"DESIRED_RANGE_ACHIEVED" = (performIdle, "setStateTo: GLOBAL");
ATTACKED = (setTargetToPrimaryAggressor, "setAITo: taranisDefenderAI.plist");
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, "setAITo: taranisDefenderAI.plist");
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: taranisDefenderAI.plist");
UPDATE = ("setSpeedFactorTo: 1.0", "setDesiredRangeTo: 500.0", performFlyToRangeFromDestination, "pauseAI: 10");
EXIT = ();
};
With that more or less sorted, I've already run into my next AI problem, but hopefully this one will be easier to solve! I've modified the station's AI so it occasionally launches various types of "traffic":
Code: Select all
"ROLL_1" = ("launchShipWithRole: taranis_traffic");
"ROLL_2" = ("launchShipWithRole: taranis_traffic_nohyp");
"ROLL_3" = ("addShips: taranis_traffic3 1");
UPDATE = ("rollD: 15000", decreaseAlertLevel, "scanForNearestShipWithPrimaryRole: player");
Previously I had a "rollD: 5000" to launch just the one type of traffic, and ships were emerging at reasonable intervals, so you can see why I went up to 15000 (as I want the overall amount of traffic to remain about the same). However, when I went to the witchpoint to check that "ROLL_3" ships were emerging there... I saw no ships. I increased the probability and tried again, but still no joy.
I'm not sure whether I've made a mistake with addShips (I think it was LittleBear who said this can be used in an AI), or whether I've experienced that "random seed" thing inherent to the dice-rolling. If it's the latter, then how can I get around this? Should I perhaps use the JavaScript timer Ahruman suggested on page 3 of this thread, in conjunction with a lower rollD number? How low should this number be to avoid the "random seeding" problem?