ship.broadcastDistressMessage() and ship event this.shipNowFacingDestination
This commit is contained in:
parent
6fb60e7996
commit
76dfaf36c4
@ -5022,6 +5022,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
|
||||
{
|
||||
// desired facing achieved and movement stabilised.
|
||||
[shipAI message:@"FACING_DESTINATION"];
|
||||
[self doScriptEvent:OOJSID("shipNowFacingDestination")];
|
||||
frustration = 0.0;
|
||||
if(docking_match_rotation) // IDLE stops rotating while docking
|
||||
{
|
||||
|
@ -37,8 +37,6 @@ MA 02110-1301, USA.
|
||||
- (void) switchAITo:(NSString *)aiString;
|
||||
|
||||
- (void) scanForHostiles;
|
||||
- (void) performTumble;
|
||||
- (void) performStop;
|
||||
- (BOOL) performHyperSpaceToSpecificSystem:(OOSystemID)systemID;
|
||||
- (void) scanForNearestIncomingMissile;
|
||||
|
||||
@ -51,21 +49,22 @@ MA 02110-1301, USA.
|
||||
|
||||
- (void) groupAttackTarget;
|
||||
|
||||
- (void) performFlyToRangeFromDestination;
|
||||
- (void) performIdle;
|
||||
- (void) performHold;
|
||||
- (void) performAttack;
|
||||
- (void) performCollect;
|
||||
|
||||
- (void) performIntercept;
|
||||
|
||||
- (void) performEscort;
|
||||
- (void) performFaceDestination;
|
||||
- (void) performFlee;
|
||||
|
||||
- (void) performFlyToRangeFromDestination;
|
||||
- (void) performHold;
|
||||
- (void) performIdle;
|
||||
- (void) performIntercept;
|
||||
- (void) performLandOnPlanet;
|
||||
- (void) performMining;
|
||||
- (void) performScriptedAI;
|
||||
- (void) performScriptedAttackAI;
|
||||
- (void) performFaceDestination;
|
||||
- (void) performLandOnPlanet;
|
||||
- (void) performEscort;
|
||||
- (void) performMining;
|
||||
- (void) performStop;
|
||||
- (void) performTumble;
|
||||
|
||||
- (void) broadcastDistressMessage;
|
||||
|
||||
@end
|
||||
|
@ -153,7 +153,6 @@
|
||||
|
||||
- (void) commsMessage:(NSString *)valueString;
|
||||
- (void) commsMessageByUnpiloted:(NSString *)valueString;
|
||||
- (void) broadcastDistressMessage;
|
||||
|
||||
- (void) ejectCargo;
|
||||
|
||||
@ -607,6 +606,70 @@
|
||||
}
|
||||
|
||||
|
||||
- (void) broadcastDistressMessage
|
||||
{
|
||||
/*-- Locates all the stations, bounty hunters and police ships in range and tells them that you are under attack --*/
|
||||
|
||||
[self checkScanner];
|
||||
DESTROY(_foundTarget);
|
||||
|
||||
ShipEntity *aggressor_ship = (ShipEntity*)[self primaryAggressor];
|
||||
if (aggressor_ship == nil) return;
|
||||
|
||||
// don't send too many distress messages at once, space them out semi-randomly
|
||||
if (messageTime > 2.0 * randf()) return;
|
||||
|
||||
NSString *distress_message = nil;
|
||||
BOOL is_buoy = (scanClass == CLASS_BUOY);
|
||||
if (is_buoy) distress_message = @"[buoy-distress-call]";
|
||||
else distress_message = @"[distress-call]";
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < n_scanned_ships; i++)
|
||||
{
|
||||
ShipEntity* ship = scanned_ships[i];
|
||||
|
||||
// dump cargo if energy is low
|
||||
if (!is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy)
|
||||
{
|
||||
[self ejectCargo];
|
||||
[self performFlee];
|
||||
}
|
||||
|
||||
// tell it!
|
||||
if (ship->isPlayer)
|
||||
{
|
||||
if (!is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy)
|
||||
{
|
||||
[self sendExpandedMessage:@"[beg-for-mercy]" toShip:ship];
|
||||
}
|
||||
else if ([self bounty] == 0)
|
||||
{
|
||||
// only send distress message to player if plausibly sending
|
||||
// one more generally
|
||||
[self sendExpandedMessage:distress_message toShip:ship];
|
||||
}
|
||||
|
||||
// reset the thanked_ship_id
|
||||
DESTROY(_thankedShip);
|
||||
}
|
||||
else if ([self bounty] == 0 && [ship crew]) // Only clean ships can have their distress calls accepted
|
||||
{
|
||||
[ship doScriptEvent:OOJSID("distressMessageReceived") withArgument:aggressor_ship andArgument:self];
|
||||
|
||||
// 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 acceptDistressMessageFrom:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -1455,70 +1518,6 @@
|
||||
}
|
||||
|
||||
|
||||
- (void) broadcastDistressMessage
|
||||
{
|
||||
/*-- Locates all the stations, bounty hunters and police ships in range and tells them that you are under attack --*/
|
||||
|
||||
[self checkScanner];
|
||||
DESTROY(_foundTarget);
|
||||
|
||||
ShipEntity *aggressor_ship = (ShipEntity*)[self primaryAggressor];
|
||||
if (aggressor_ship == nil) return;
|
||||
|
||||
// don't send too many distress messages at once, space them out semi-randomly
|
||||
if (messageTime > 2.0 * randf()) return;
|
||||
|
||||
NSString *distress_message = nil;
|
||||
BOOL is_buoy = (scanClass == CLASS_BUOY);
|
||||
if (is_buoy) distress_message = @"[buoy-distress-call]";
|
||||
else distress_message = @"[distress-call]";
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < n_scanned_ships; i++)
|
||||
{
|
||||
ShipEntity* ship = scanned_ships[i];
|
||||
|
||||
// dump cargo if energy is low
|
||||
if (!is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy)
|
||||
{
|
||||
[self ejectCargo];
|
||||
[self performFlee];
|
||||
}
|
||||
|
||||
// tell it!
|
||||
if (ship->isPlayer)
|
||||
{
|
||||
if (!is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy)
|
||||
{
|
||||
[self sendExpandedMessage:@"[beg-for-mercy]" toShip:ship];
|
||||
}
|
||||
else if ([self bounty] == 0)
|
||||
{
|
||||
// only send distress message to player if plausibly sending
|
||||
// one more generally
|
||||
[self sendExpandedMessage:distress_message toShip:ship];
|
||||
}
|
||||
|
||||
// reset the thanked_ship_id
|
||||
DESTROY(_thankedShip);
|
||||
}
|
||||
else if ([self bounty] == 0 && [ship crew]) // Only clean ships can have their distress calls accepted
|
||||
{
|
||||
[ship doScriptEvent:OOJSID("distressMessageReceived") withArgument:aggressor_ship andArgument:self];
|
||||
|
||||
// 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 acceptDistressMessageFrom:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) ejectCargo
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -93,6 +93,7 @@ static JSBool ShipGetMaterials(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipGetShaders(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipBecomeCascadeExplosion(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipBroadcastCascadeImminent(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipBroadcastDistressMessage(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipOfferToEscort(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipMarkTargetForFines(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool ShipEnterWormhole(JSContext *context, uintN argc, jsval *vp);
|
||||
@ -390,6 +391,7 @@ static JSFunctionSpec sShipMethods[] =
|
||||
{ "awardEquipment", ShipAwardEquipment, 1 },
|
||||
{ "becomeCascadeExplosion", ShipBecomeCascadeExplosion, 0 },
|
||||
{ "broadcastCascadeImminent", ShipBroadcastCascadeImminent, 0 },
|
||||
{ "broadcastDistressMessage", ShipBroadcastDistressMessage, 0 },
|
||||
{ "canAwardEquipment", ShipCanAwardEquipment, 1 },
|
||||
{ "clearDefenseTargets", ShipClearDefenseTargets, 0 },
|
||||
{ "commsMessage", ShipCommsMessage, 1 },
|
||||
@ -3002,6 +3004,20 @@ static JSBool ShipPerformTumble(JSContext *context, uintN argc, jsval *vp)
|
||||
}
|
||||
|
||||
|
||||
static JSBool ShipBroadcastDistressMessage(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
|
||||
ShipEntity *thisEnt = nil;
|
||||
GET_THIS_SHIP(thisEnt);
|
||||
[thisEnt broadcastDistressMessage];
|
||||
|
||||
OOJS_RETURN_VOID;
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
||||
|
||||
/** Static methods */
|
||||
|
||||
static JSBool ShipStaticKeys(JSContext *context, uintN argc, jsval *vp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user