JSAI: Rock hermit
This commit is contained in:
parent
9aa62fc2bd
commit
f128abf309
56
Resources/AIs/rockHermitAI.js
Normal file
56
Resources/AIs/rockHermitAI.js
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
rockHermitAI.js
|
||||
|
||||
Priority-based AI for rock hermits
|
||||
|
||||
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 Rock Hermit AI";
|
||||
this.version = "1.79";
|
||||
|
||||
this.aiStarted = function() {
|
||||
var ai = new worldScripts["oolite-libPriorityAI"].AILib(this.ship);
|
||||
|
||||
ai.setPriorities([
|
||||
/* Fight */
|
||||
{
|
||||
preconfiguration: ai.configurationStationValidateTarget,
|
||||
condition: ai.conditionInCombat,
|
||||
behaviour: ai.behaviourStationLaunchDefenseShips,
|
||||
reconsider: 5
|
||||
},
|
||||
/* Scan */
|
||||
{
|
||||
preconfiguration: ai.configurationCheckScanner,
|
||||
condition: ai.conditionScannerContainsRocks,
|
||||
behaviour: ai.behaviourStationLaunchMiner,
|
||||
reconsider: 60
|
||||
},
|
||||
{
|
||||
configuration: ai.configurationStationReduceAlertLevel,
|
||||
behaviour: ai.behaviourStationManageTraffic,
|
||||
reconsider: 60
|
||||
}
|
||||
]);
|
||||
}
|
@ -2033,7 +2033,7 @@
|
||||
};
|
||||
"oolite_template_rock-hermit" =
|
||||
{
|
||||
ai_type = "rockHermitAI.plist";
|
||||
ai_type = "rockHermitAI.js";
|
||||
cargo_type = "CARGO_NOT_CARGO";
|
||||
energy_recharge_rate = 5;
|
||||
"equipment_price_factor" = 4.5;
|
||||
|
@ -718,6 +718,11 @@ this.AILib = function(ship)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.conditionScannerContainsRocks();
|
||||
}
|
||||
|
||||
this.conditionScannerContainsRocks = function()
|
||||
{
|
||||
var scan1 = this.checkScannerWithPredicate(function(s) {
|
||||
return s.isInSpace && s.isBoulder;
|
||||
});
|
||||
@ -781,14 +786,6 @@ this.AILib = function(ship)
|
||||
}
|
||||
|
||||
|
||||
this.conditionScannerContainsPatrol = function()
|
||||
{
|
||||
return this.checkScannerWithPredicate(function(s) {
|
||||
return s.isInSpace && s.primaryRole == this.getParameter("oolite_stationPatrolRole");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.conditionHasReceivedDistressCall = function()
|
||||
{
|
||||
var aggressor = this.getParameter("oolite_distressAggressor");
|
||||
@ -1987,9 +1984,32 @@ this.AILib = function(ship)
|
||||
|
||||
}
|
||||
|
||||
this.behaviourStationLaunchMiner = function()
|
||||
{
|
||||
if (this.alertCondition > 1)
|
||||
{
|
||||
this.alertCondition--;
|
||||
}
|
||||
var handlers = {};
|
||||
this.responsesAddStation(handlers);
|
||||
this.setUpHandlers(handlers);
|
||||
if (this.ship.group)
|
||||
{
|
||||
for (var i = 0 ; i < this.ship.group.ships.length ; i++)
|
||||
{
|
||||
if (this.ship.group.ships[i].primaryRole == "miner")
|
||||
{
|
||||
// only one in flight at once
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.ship.launchMiner();
|
||||
}
|
||||
|
||||
|
||||
this.behaviourStationLaunchPatrol = function()
|
||||
{
|
||||
this.ship.launchPatrol();
|
||||
if (this.alertCondition > 1)
|
||||
{
|
||||
this.alertCondition--;
|
||||
@ -1998,6 +2018,19 @@ this.AILib = function(ship)
|
||||
this.responsesAddStation(handlers);
|
||||
this.setUpHandlers(handlers);
|
||||
|
||||
if (this.ship.group)
|
||||
{
|
||||
for (var i = 0 ; i < this.ship.group.ships.length ; i++)
|
||||
{
|
||||
if (this.ship.group.ships[i].primaryRole == this.getParameter("oolite_stationPatrolRole"))
|
||||
{
|
||||
// only one in flight at once
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ship.launchPatrol();
|
||||
}
|
||||
|
||||
this.behaviourStationManageTraffic = function()
|
||||
@ -2158,7 +2191,7 @@ this.AILib = function(ship)
|
||||
if (this.ship.group && this.ship.group.leader)
|
||||
{
|
||||
var leader = this.ship.group.leader;
|
||||
if (leader.target.target == leader && this.isFighting(leader) && leader.target.position.distanceTo(this.ship) < this.ship.scannerRange)
|
||||
if (leader.target && leader.target.target == leader && this.isFighting(leader) && leader.target.position.distanceTo(this.ship) < this.ship.scannerRange)
|
||||
{
|
||||
this.ship.target = leader.target;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user