JSAI: shuttle AI
This commit is contained in:
parent
228344c540
commit
968eace6db
88
Resources/AIs/shuttleAI.js
Normal file
88
Resources/AIs/shuttleAI.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
shuttleAI.js
|
||||||
|
|
||||||
|
Priority-based AI for in-system shuttles
|
||||||
|
|
||||||
|
Oolite
|
||||||
|
Copyright © 2004-2013 Giles C Williams and contributors
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
MA 02110-1301, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
this.name = "Oolite Shuttle AI";
|
||||||
|
this.version = "1.79";
|
||||||
|
|
||||||
|
this.aiStarted = function() {
|
||||||
|
var ai = new worldScripts["oolite-libPriorityAI"].AILib(this.ship);
|
||||||
|
|
||||||
|
ai.setParameter("oolite_flag_sendsDistressCalls",true);
|
||||||
|
ai.setParameter("oolite_flag_allowPlanetaryLanding",true);
|
||||||
|
|
||||||
|
ai.setCommunication("oolite_landingOnPlanet","Commencing final approach to %N spaceport");
|
||||||
|
|
||||||
|
ai.setPriorities([
|
||||||
|
{
|
||||||
|
condition: ai.conditionInCombat,
|
||||||
|
behaviour: ai.behaviourFleeCombat
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: ai.conditionHasSelectedStation,
|
||||||
|
truebranch: [
|
||||||
|
{
|
||||||
|
condition: ai.conditionSelectedStationNearby,
|
||||||
|
configuration: ai.configurationSetSelectedStationForDocking,
|
||||||
|
behaviour: ai.behaviourDockWithStation,
|
||||||
|
reconsider: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
configuration: ai.configurationSetDestinationToSelectedStation,
|
||||||
|
behaviour: ai.behaviourApproachDestination,
|
||||||
|
reconsider: 30
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: ai.conditionHasSelectedPlanet,
|
||||||
|
truebranch: [
|
||||||
|
{
|
||||||
|
preconfiguration: ai.configurationSetDestinationToSelectedPlanet,
|
||||||
|
condition: ai.conditionNearDestination,
|
||||||
|
behaviour: ai.behaviourLandOnPlanet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
behaviour: ai.behaviourApproachDestination,
|
||||||
|
reconsider: 30
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
/* TODO: need to try to hitchhike out! */
|
||||||
|
{
|
||||||
|
condition: ai.conditionInInterstellarSpace,
|
||||||
|
configuration: ai.configurationSetDestinationToWitchpoint,
|
||||||
|
behaviour: ai.behaviourApproachDestination,
|
||||||
|
reconsider: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
configuration: ai.configurationSelectShuttleDestination,
|
||||||
|
behaviour: ai.behaviourApproachDestination,
|
||||||
|
reconsider: 1
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
@ -24,7 +24,7 @@
|
|||||||
"police" = "policeAI.js";
|
"police" = "policeAI.js";
|
||||||
"trader" = "traderAI.js";
|
"trader" = "traderAI.js";
|
||||||
"scavenger" = "scavengerAI.plist";
|
"scavenger" = "scavengerAI.plist";
|
||||||
"shuttle" = "fallingShuttleAI.plist";
|
"shuttle" = "shuttleAI.js";
|
||||||
"sunskim-trader" = "traderAI.js";
|
"sunskim-trader" = "traderAI.js";
|
||||||
"wingman" = "policeAI.js";
|
"wingman" = "policeAI.js";
|
||||||
}
|
}
|
||||||
|
@ -520,7 +520,7 @@ this.AILib = function(ship)
|
|||||||
|
|
||||||
this.conditionMothershipInCombat = function()
|
this.conditionMothershipInCombat = function()
|
||||||
{
|
{
|
||||||
if (this.ship.group && this.ship.group.leader != this.ship && this.ship.group.leader.escortGroup.containsShip(this.ship))
|
if (this.ship.group && this.ship.group.leader && this.ship.group.leader != this.ship && this.ship.group.leader.escortGroup.containsShip(this.ship))
|
||||||
{
|
{
|
||||||
var leader = this.ship.group.leader;
|
var leader = this.ship.group.leader;
|
||||||
if (leader.position.distanceTo(this.ship) > this.ship.scannerRange)
|
if (leader.position.distanceTo(this.ship) > this.ship.scannerRange)
|
||||||
@ -710,7 +710,7 @@ this.AILib = function(ship)
|
|||||||
this.conditionHasSelectedStation = function()
|
this.conditionHasSelectedStation = function()
|
||||||
{
|
{
|
||||||
var station = this.getParameter("oolite_selectedStation");
|
var station = this.getParameter("oolite_selectedStation");
|
||||||
if (station && !station.isValid)
|
if (station && (!station.isValid || !station.isStation))
|
||||||
{
|
{
|
||||||
this.setParameter("oolite_selectedStation",null);
|
this.setParameter("oolite_selectedStation",null);
|
||||||
return false;
|
return false;
|
||||||
@ -718,6 +718,18 @@ this.AILib = function(ship)
|
|||||||
return station != null;
|
return station != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.conditionHasSelectedPlanet = function()
|
||||||
|
{
|
||||||
|
var planet = this.getParameter("oolite_selectedPlanet");
|
||||||
|
if (planet && (!planet.isValid || !planet.isPlanet))
|
||||||
|
{
|
||||||
|
this.setParameter("oolite_selectedPlanet",null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return planet != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.conditionInInterstellarSpace = function()
|
this.conditionInInterstellarSpace = function()
|
||||||
{
|
{
|
||||||
return system.isInterstellarSpace;
|
return system.isInterstellarSpace;
|
||||||
@ -1297,16 +1309,19 @@ this.AILib = function(ship)
|
|||||||
{
|
{
|
||||||
if (blocker.isPlanet || blocker.isSun)
|
if (blocker.isPlanet || blocker.isSun)
|
||||||
{
|
{
|
||||||
if (this.ship.position.distanceTo(blocker) < blocker.radius * 3)
|
// the selected planet can't block
|
||||||
|
if (blocker.isSun || this.getParameter("oolite_selectedPlanet") != blocker)
|
||||||
{
|
{
|
||||||
if (waypoints == null)
|
if (this.ship.position.distanceTo(blocker) < blocker.radius * 3)
|
||||||
{
|
{
|
||||||
waypoints = [];
|
if (waypoints == null)
|
||||||
|
{
|
||||||
|
waypoints = [];
|
||||||
|
}
|
||||||
|
waypoints.push(this.ship.getSafeCourseToDestination());
|
||||||
|
this.ship.destination = waypoints[waypoints.length-1];
|
||||||
|
this.ship.desiredRange = 1000;
|
||||||
}
|
}
|
||||||
waypoints.push(this.ship.getSafeCourseToDestination());
|
|
||||||
this.ship.destination = waypoints[waypoints.length-1];
|
|
||||||
this.ship.desiredRange = 1000;
|
|
||||||
log(this.ship,"Avoiding blocker "+blocker);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (blocker.isShip)
|
else if (blocker.isShip)
|
||||||
@ -1323,7 +1338,6 @@ this.AILib = function(ship)
|
|||||||
waypoints.push(this.ship.getSafeCourseToDestination());
|
waypoints.push(this.ship.getSafeCourseToDestination());
|
||||||
this.ship.destination = waypoints[waypoints.length-1];
|
this.ship.destination = waypoints[waypoints.length-1];
|
||||||
this.ship.desiredRange = 1000;
|
this.ship.desiredRange = 1000;
|
||||||
log(this.ship,"Avoiding blocker "+blocker);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1775,6 +1789,15 @@ this.AILib = function(ship)
|
|||||||
this.ship.performTumble();
|
this.ship.performTumble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.behaviourLandOnPlanet = function()
|
||||||
|
{
|
||||||
|
this.ship.desiredSpeed = this.ship.maxSpeed / 4;
|
||||||
|
this.ship.performLandOnPlanet();
|
||||||
|
this.ship.AIScriptWakeTime = 0; // cancel reconsiderations
|
||||||
|
this.setUpHandlers({}); // cancel interruptions
|
||||||
|
this.communicate("oolite_landingOnPlanet");
|
||||||
|
}
|
||||||
|
|
||||||
/* ****************** Configuration functions ************** */
|
/* ****************** Configuration functions ************** */
|
||||||
|
|
||||||
/* Configurations. Configurations are set up actions for a behaviour
|
/* Configurations. Configurations are set up actions for a behaviour
|
||||||
@ -1939,6 +1962,55 @@ this.AILib = function(ship)
|
|||||||
this.ship.target = this.getParameter("oolite_scanResultSpecific");
|
this.ship.target = this.getParameter("oolite_scanResultSpecific");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.configurationSelectShuttleDestination = function()
|
||||||
|
{
|
||||||
|
var possibles = system.planets.concat(system.stations);
|
||||||
|
var destinations1 = [];
|
||||||
|
var destinations2 = [];
|
||||||
|
for (var i = 0; i < possibles.length ; i++)
|
||||||
|
{
|
||||||
|
var possible = possibles[i];
|
||||||
|
// travel at least a little way
|
||||||
|
var distance = possible.position.distanceTo(this.ship);
|
||||||
|
if (distance > possible.collisionRadius + 10000)
|
||||||
|
{
|
||||||
|
// must be friendly destination and not moving too fast
|
||||||
|
if (possible.isPlanet || this.friendlyStation(possible) || possible.maxSpeed > this.ship.maxSpeed / 5)
|
||||||
|
{
|
||||||
|
if (distance > system.mainPlanet.radius * 5)
|
||||||
|
{
|
||||||
|
destinations2.push(possible);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
destinations1.push(possible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no nearby destinations
|
||||||
|
if (destinations1.length == 0)
|
||||||
|
{
|
||||||
|
destinations1 = destinations2;
|
||||||
|
}
|
||||||
|
// no destinations
|
||||||
|
if (destinations1.length == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var destination = destinations1[Math.floor(Math.random()*destinations1.length)];
|
||||||
|
if (destination.isPlanet)
|
||||||
|
{
|
||||||
|
this.setParameter("oolite_selectedPlanet",destination);
|
||||||
|
this.setParameter("oolite_selectedStation",null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.setParameter("oolite_selectedStation",destination);
|
||||||
|
this.setParameter("oolite_selectedPlanet",null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.configurationSelectRandomTradeStation = function()
|
this.configurationSelectRandomTradeStation = function()
|
||||||
{
|
{
|
||||||
var stations = system.stations;
|
var stations = system.stations;
|
||||||
@ -2011,6 +2083,18 @@ this.AILib = function(ship)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.configurationSetDestinationToSelectedPlanet = function()
|
||||||
|
{
|
||||||
|
var planet = this.getParameter("oolite_selectedPlanet");
|
||||||
|
if (planet)
|
||||||
|
{
|
||||||
|
this.ship.destination = planet.position;
|
||||||
|
this.ship.desiredRange = planet.radius+100;
|
||||||
|
this.ship.desiredSpeed = this.cruiseSpeed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.configurationSetDestinationToPirateLurk = function()
|
this.configurationSetDestinationToPirateLurk = function()
|
||||||
{
|
{
|
||||||
var lurk = this.getParameter("oolite_pirateLurk");
|
var lurk = this.getParameter("oolite_pirateLurk");
|
||||||
@ -2412,7 +2496,18 @@ this.AILib = function(ship)
|
|||||||
}
|
}
|
||||||
handlers.approachingPlanetSurface = function()
|
handlers.approachingPlanetSurface = function()
|
||||||
{
|
{
|
||||||
this.reconsiderNow();
|
if (this.getParameter("oolite_flag_allowPlanetaryLanding"))
|
||||||
|
{
|
||||||
|
this.ship.desiredSpeed = this.ship.maxSpeed / 4;
|
||||||
|
this.ship.performLandOnPlanet();
|
||||||
|
this.ship.AIScriptWakeTime = 0; // cancel reconsiderations
|
||||||
|
this.setUpHandlers({}); // cancel interruptions
|
||||||
|
this.communicate("oolite_landingOnPlanet");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.reconsiderNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handlers.shipLaunchedFromStation = function(station)
|
handlers.shipLaunchedFromStation = function(station)
|
||||||
{
|
{
|
||||||
|
@ -568,7 +568,7 @@ static OOColor *ColorWithHSBColor(Vector c)
|
|||||||
|
|
||||||
[shuttle_ship setScanClass: CLASS_NEUTRAL];
|
[shuttle_ship setScanClass: CLASS_NEUTRAL];
|
||||||
[shuttle_ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
|
[shuttle_ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
|
||||||
[shuttle_ship switchAITo:@"risingShuttleAI.plist"];
|
[shuttle_ship switchAITo:@"shuttleAI.js"];
|
||||||
[UNIVERSE addEntity:shuttle_ship]; // STATUS_IN_FLIGHT, AI state GLOBAL
|
[UNIVERSE addEntity:shuttle_ship]; // STATUS_IN_FLIGHT, AI state GLOBAL
|
||||||
_shuttlesOnGround--;
|
_shuttlesOnGround--;
|
||||||
_lastLaunchTime = [UNIVERSE getTime];
|
_lastLaunchTime = [UNIVERSE getTime];
|
||||||
|
@ -1194,7 +1194,7 @@ static const BaseFace kTexturedFaces[][3] =
|
|||||||
|
|
||||||
[shuttle_ship setScanClass: CLASS_NEUTRAL];
|
[shuttle_ship setScanClass: CLASS_NEUTRAL];
|
||||||
[shuttle_ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
|
[shuttle_ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
|
||||||
[shuttle_ship switchAITo:@"risingShuttleAI.plist"];
|
[shuttle_ship switchAITo:@"shuttleAI.js"];
|
||||||
[UNIVERSE addEntity:shuttle_ship];
|
[UNIVERSE addEntity:shuttle_ship];
|
||||||
|
|
||||||
[shuttle_ship release];
|
[shuttle_ship release];
|
||||||
|
@ -1860,7 +1860,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords,
|
|||||||
docked_shuttles--;
|
docked_shuttles--;
|
||||||
[shuttle_ship setScanClass: CLASS_NEUTRAL];
|
[shuttle_ship setScanClass: CLASS_NEUTRAL];
|
||||||
[shuttle_ship setCargoFlag:CARGO_FLAG_FULL_SCARCE];
|
[shuttle_ship setCargoFlag:CARGO_FLAG_FULL_SCARCE];
|
||||||
[shuttle_ship switchAITo:@"fallingShuttleAI.plist"];
|
[shuttle_ship switchAITo:@"shuttleAI.js"];
|
||||||
[self addShipToLaunchQueue:shuttle_ship withPriority:NO];
|
[self addShipToLaunchQueue:shuttle_ship withPriority:NO];
|
||||||
|
|
||||||
[shuttle_ship autorelease];
|
[shuttle_ship autorelease];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user