fix issue where Station JS AI was not triggering an alertConditionChanged event (#311)
This commit is contained in:
parent
73f5af67de
commit
4a98662e68
@ -3792,14 +3792,19 @@ PriorityAIController.prototype.behaviourStationLaunchDefenseShips = function()
|
||||
}
|
||||
if (this.ship.target && this.isAggressive(this.ship.target))
|
||||
{
|
||||
this.ship.alertCondition = 3;
|
||||
if (this.ship.alertCondition < 3)
|
||||
{
|
||||
do {
|
||||
this.ship.increaseAlertLevel();
|
||||
} while (this.ship.alertCondition < 3);
|
||||
}
|
||||
this.ship.launchDefenseShip();
|
||||
this.communicate("oolite_launchDefenseShips",this.ship.target,3);
|
||||
this.ship.requestHelpFromGroup();
|
||||
}
|
||||
else if (this.ship.alertCondition > 1)
|
||||
{
|
||||
this.ship.alertCondition--;
|
||||
this.ship.decreaseAlertLevel();
|
||||
}
|
||||
var handlers = {};
|
||||
this.responsesAddStation(handlers);
|
||||
@ -3815,7 +3820,7 @@ PriorityAIController.prototype.behaviourStationLaunchMiner = function()
|
||||
}
|
||||
if (this.ship.alertCondition > 1)
|
||||
{
|
||||
this.ship.alertCondition--;
|
||||
this.ship.decreaseAlertLevel();
|
||||
}
|
||||
var handlers = {};
|
||||
this.responsesAddStation(handlers);
|
||||
@ -3844,7 +3849,7 @@ PriorityAIController.prototype.behaviourStationLaunchPatrol = function()
|
||||
}
|
||||
if (this.ship.alertCondition > 1)
|
||||
{
|
||||
this.ship.alertCondition--;
|
||||
this.ship.decreaseAlertLevel();
|
||||
}
|
||||
var handlers = {};
|
||||
this.responsesAddStation(handlers);
|
||||
@ -3874,7 +3879,7 @@ PriorityAIController.prototype.behaviourStationLaunchSalvager = function()
|
||||
}
|
||||
if (this.ship.alertCondition > 1)
|
||||
{
|
||||
this.ship.alertCondition--;
|
||||
this.ship.decreaseAlertLevel();
|
||||
}
|
||||
this.communicate("oolite_launchSalvager",this.ship.target,3);
|
||||
this.ship.launchScavenger();
|
||||
@ -3911,7 +3916,12 @@ PriorityAIController.prototype.behaviourStationRespondToDistressCall = function(
|
||||
if (this.distance(aggressor) < this.scannerRange)
|
||||
{
|
||||
this.ship.target = aggressor;
|
||||
this.ship.alertCondition = 3;
|
||||
if (this.ship.alertCondition < 3)
|
||||
{
|
||||
do {
|
||||
this.ship.increaseAlertLevel();
|
||||
} while (this.ship.alertCondition < 3);
|
||||
}
|
||||
this.ship.launchDefenseShip();
|
||||
this.communicate("oolite_distressResponseAggressor",aggressor,2);
|
||||
this.ship.requestHelpFromGroup();
|
||||
@ -4845,7 +4855,7 @@ PriorityAIController.prototype.configurationStationReduceAlertLevel = function()
|
||||
{
|
||||
if (this.ship.alertCondition > 1)
|
||||
{
|
||||
this.ship.alertCondition--;
|
||||
this.ship.decreaseAlertLevel();
|
||||
}
|
||||
}
|
||||
|
||||
@ -5764,14 +5774,24 @@ PriorityAIController.prototype.responseComponent_station_commsMessageReceived =
|
||||
|
||||
PriorityAIController.prototype.responseComponent_station_cascadeWeaponDetected = function(weapon)
|
||||
{
|
||||
this.ship.alertCondition = 3;
|
||||
if (this.ship.alertCondition < 3)
|
||||
{
|
||||
do {
|
||||
this.ship.increaseAlertLevel();
|
||||
} while (this.ship.alertCondition < 3);
|
||||
}
|
||||
this.reconsiderNow();
|
||||
};
|
||||
|
||||
|
||||
PriorityAIController.prototype.responseComponent_station_shipAttackedWithMissile = function(missile,whom)
|
||||
{
|
||||
this.ship.alertCondition = 3;
|
||||
if (this.ship.alertCondition < 3)
|
||||
{
|
||||
do {
|
||||
this.ship.increaseAlertLevel();
|
||||
} while (this.ship.alertCondition < 3);
|
||||
}
|
||||
if (this.ship.hasEquipmentProviding("EQ_ECM"))
|
||||
{
|
||||
this.fireECM();
|
||||
@ -5830,7 +5850,12 @@ PriorityAIController.prototype.responseComponent_station_shipBeingAttacked = fun
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.ship.alertCondition = 3;
|
||||
if (this.ship.alertCondition < 3)
|
||||
{
|
||||
do {
|
||||
this.ship.increaseAlertLevel();
|
||||
} while (this.ship.alertCondition < 3);
|
||||
}
|
||||
if (this.ship.defenseTargets.indexOf(whom) < 0)
|
||||
{
|
||||
this.ship.addDefenseTarget(whom);
|
||||
@ -6006,7 +6031,9 @@ PriorityAIController.prototype.responseComponent_station_offenceCommittedNearby
|
||||
this.ship.addDefenseTarget(attacker);
|
||||
if (this.ship.alertCondition < 3)
|
||||
{
|
||||
this.ship.alertCondition = 3;
|
||||
do {
|
||||
this.ship.increaseAlertLevel();
|
||||
} while (this.ship.alertCondition < 3);
|
||||
this.ship.target = attacker;
|
||||
}
|
||||
this.reconsiderNow();
|
||||
|
@ -45,6 +45,8 @@ static JSBool StationAbortAllDockings(JSContext *context, uintN argc, jsval *vp)
|
||||
static JSBool StationAbortDockingForShip(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationCanDockShip(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationDockPlayer(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationIncreaseAlertLevel(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationDecreaseAlertLevel(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationLaunchShipWithRole(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationLaunchDefenseShip(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool StationLaunchEscort(JSContext *context, uintN argc, jsval *vp);
|
||||
@ -129,6 +131,8 @@ static JSFunctionSpec sStationMethods[] =
|
||||
{ "abortDockingForShip", StationAbortDockingForShip, 1 },
|
||||
{ "canDockShip", StationCanDockShip, 1 },
|
||||
{ "dockPlayer", StationDockPlayer, 0 },
|
||||
{ "increaseAlertLevel", StationIncreaseAlertLevel, 0 },
|
||||
{ "decreaseAlertLevel", StationDecreaseAlertLevel, 0 },
|
||||
{ "launchDefenseShip", StationLaunchDefenseShip, 0 },
|
||||
{ "launchEscort", StationLaunchEscort, 0 },
|
||||
{ "launchMiner", StationLaunchMiner, 0 },
|
||||
@ -523,6 +527,40 @@ static JSBool StationDockPlayer(JSContext *context, uintN argc, jsval *vp)
|
||||
}
|
||||
|
||||
|
||||
static JSBool StationIncreaseAlertLevel(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
StationEntity *station = nil;
|
||||
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) OOJS_RETURN_VOID; // stale reference, no-op
|
||||
|
||||
OOJS_BEGIN_FULL_NATIVE(context)
|
||||
if ([station alertCondition] < 3)
|
||||
{
|
||||
[station increaseAlertLevel];
|
||||
}
|
||||
OOJS_END_FULL_NATIVE
|
||||
OOJS_RETURN_VOID;
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
static JSBool StationDecreaseAlertLevel(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
StationEntity *station = nil;
|
||||
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) OOJS_RETURN_VOID; // stale reference, no-op
|
||||
|
||||
OOJS_BEGIN_FULL_NATIVE(context)
|
||||
if ([station alertCondition] > 1)
|
||||
{
|
||||
[station decreaseAlertLevel];
|
||||
}
|
||||
OOJS_END_FULL_NATIVE
|
||||
OOJS_RETURN_VOID;
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
// launchShipWithRole(role : String [, abortAllDockings : boolean]) : shipEntity
|
||||
static JSBool StationLaunchShipWithRole(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user