Improve distress message handling

This commit is contained in:
cim 2013-08-30 21:14:55 +01:00
parent 8cf615c168
commit c7e7e2f75f
4 changed files with 34 additions and 6 deletions

View File

@ -35,6 +35,7 @@ this.aiStarted = function() {
ai.setCommunicationsRole("_thargoid");
ai.setCommunicationsPersonality("tharglet");
ai.setParameter("oolite_flag_fightsNearHostileStations",true);
ai.setParameter("oolite_flag_scanIgnoresUnpowered",true);
ai.setPriorities([

View File

@ -32,6 +32,8 @@ this.version = "1.79";
this.aiStarted = function() {
var ai = new worldScripts["oolite-libPriorityAI"].AILib(this.ship);
ai.setParameter("oolite_flag_fightsNearHostileStations",true);
ai.setCommunicationsRole("_thargoid");
ai.setCommunicationsPersonality("thargoid");

View File

@ -509,6 +509,11 @@ AILib.prototype.allied = function(ship1,ship2)
AILib.prototype.broadcastDistressMessage = function()
{
if (this.__ltcache.oolite_sentDistressMessage)
{
return;
}
this.__ltcache.oolite_sentDistressMessage = true;
this.ship.broadcastDistressMessage();
if (this.ship.AIPrimaryAggressor)
{
@ -4235,6 +4240,13 @@ AILib.prototype.responseComponent_standard_distressMessageReceived = function(ag
{
return;
}
if (this.ship.scanClass == "CLASS_POLICE" || (this.ship.isStation && this.ship.allegiance == "galcop"))
{
if (this.distance(aggressor) < this.scannerRange)
{
aggressor.bounty |= 8;
}
}
this.setParameter("oolite_distressAggressor",aggressor);
this.setParameter("oolite_distressSender",sender);
this.setParameter("oolite_distressTimestamp",clock.adjustedSeconds);
@ -4375,7 +4387,7 @@ AILib.prototype.responseComponent_standard_shipAttackedOther = function(other)
AILib.prototype.responseComponent_standard_shipAttackedWithMissile = function(missile,whom)
{
if (!this.ship.hasHostileTarget && this.getParameter("oolite_flag_sendsDistressCalls"))
if (this.getParameter("oolite_flag_sendsDistressCalls"))
{
this.broadcastDistressMessage();
}
@ -4459,7 +4471,7 @@ AILib.prototype.responseComponent_standard_shipBeingAttacked = function(whom)
// don't get confused and shoot the station!
this.ship.target = null;
}
if (!this.ship.hasHostileTarget && this.getParameter("oolite_flag_sendsDistressCalls"))
if (this.getParameter("oolite_flag_sendsDistressCalls"))
{
this.broadcastDistressMessage();
}
@ -4534,7 +4546,7 @@ AILib.prototype.responseComponent_standard_shipBeingAttacked = function(whom)
AILib.prototype.responseComponent_standard_shipBeingAttackedUnsuccessfully = function(whom)
{
if (!this.ship.hasHostileTarget && this.getParameter("oolite_flag_sendsDistressCalls"))
if (this.getParameter("oolite_flag_sendsDistressCalls"))
{
this.broadcastDistressMessage();
}
@ -4873,6 +4885,13 @@ AILib.prototype.responseComponent_station_distressMessageReceived = function(agg
{
return;
}
if (this.ship.scanClass == "CLASS_POLICE" || (this.ship.isStation && this.ship.allegiance == "galcop"))
{
if (this.distance(aggressor) < this.scannerRange)
{
aggressor.bounty |= 8;
}
}
this.setParameter("oolite_distressAggressor",aggressor);
this.setParameter("oolite_distressSender",sender);
this.setParameter("oolite_distressTimestamp",clock.adjustedSeconds);

View File

@ -806,10 +806,16 @@
// we only can send distressMessages to ships that are known to have a "ACCEPT_DISTRESS_CALL" reaction
// in their AI, or they might react wrong on the added found_target.
// FIXME: this test only works with core AIs
if (ship->isStation || [ship hasPrimaryRole:@"police"] || [ship hasPrimaryRole:@"hunter"])
// ship must have a plist AI for this next bit. JS AIs
// should already have done something sensible on
// distressMessageReceived
if (![[[self getAI] name] isEqualToString:@"nullAI.plist"])
{
[ship acceptDistressMessageFrom:self];
// FIXME: this test only works with core AIs
if (ship->isStation || [ship hasPrimaryRole:@"police"] || [ship hasPrimaryRole:@"hunter"])
{
[ship acceptDistressMessageFrom:self];
}
}
}
}