Added a "distresMessageReceived(agressor, sender)" event handler.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3838 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Eric Walch 2010-11-27 12:20:18 +00:00
parent 0898cfc152
commit 029f2860fe
5 changed files with 75 additions and 91 deletions

View File

@ -40,6 +40,8 @@
ENTER = ("setSpeedTo: 0.0", performIdle);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: interceptAI.plist");
"DOCKING_REQUESTED" = ("setSpeedFactorTo: 0.0", "setAITo: receivingDockingAI.plist");
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, deployEscorts, groupAttackTarget);
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 7", deployEscorts, groupAttackTarget);
ATTACKED = (setTargetToPrimaryAggressor, groupAttackTarget);
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, deployEscorts, groupAttackTarget);
"TARGET_FOUND" = (setTargetToFoundTarget, "setAITo: collectLootAI.plist");
@ -52,6 +54,8 @@
ENTER = ("setSpeedTo: 0.0", performIdle);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: interceptAI.plist");
"DOCKING_REQUESTED" = ("setSpeedFactorTo: 0.0", "setAITo: receivingDockingAI.plist");
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, deployEscorts, groupAttackTarget);
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 7", deployEscorts, groupAttackTarget);
ATTACKED = (setTargetToPrimaryAggressor, groupAttackTarget);
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, deployEscorts, groupAttackTarget);
"TARGET_FOUND" = (setTargetToFoundTarget, "setAITo: collectLootAI.plist");
@ -64,6 +68,7 @@
ENTER = (scanForFormationLeader);
RESTARTED = ("setStateTo: INBOUND_LOOT");
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 7", deployEscorts, groupAttackTarget);
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, deployEscorts, groupAttackTarget);
"TARGET_FOUND" = ("switchAITo: escortAI.plist");
"NOTHING_FOUND" = (checkForNormalSpace);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: interceptAI.plist");
@ -75,6 +80,7 @@
ENTER = (scanForFormationLeader);
RESTARTED = ("setStateTo: OUTBOUND_LOOT");
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 7", deployEscorts, groupAttackTarget);
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, deployEscorts, groupAttackTarget);
"TARGET_FOUND" = ("switchAITo: escortAI.plist");
"NOTHING_FOUND" = (checkForNormalSpace);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: interceptAI.plist");

View File

@ -70,6 +70,8 @@
ENTER = ("setSpeedTo: 0.0", performIdle);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: interceptAI.plist");
ATTACKED = (setTargetToPrimaryAggressor, groupAttackTarget);
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, deployEscorts, groupAttackTarget);
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 7", deployEscorts, groupAttackTarget);
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, deployEscorts, groupAttackTarget);
"TARGET_FOUND" = (setTargetToFoundTarget, "setAITo: collectLootAI.plist");
"NOTHING_FOUND" = (checkAegis, "setStateTo: HEAD_FOR_SUN");
@ -80,6 +82,8 @@
ENTER = ("setSpeedTo: 0.0", performIdle);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setAITo: interceptAI.plist");
ATTACKED = (setTargetToPrimaryAggressor, groupAttackTarget);
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, deployEscorts, groupAttackTarget);
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 7", deployEscorts, groupAttackTarget);
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToPrimaryAggressor, deployEscorts, groupAttackTarget);
"TARGET_FOUND" = (setTargetToFoundTarget, "setAITo: collectLootAI.plist");
"NOTHING_FOUND" = (checkAegis, "setStateTo: HEAD_FOR_PLANET");

View File

@ -742,6 +742,7 @@ BOOL class_masslocks(int some_class);
- (int) primaryTargetID;
- (void) noteLostTarget;
- (void) noteLostTargetAndGoIdle;
- (void) noteTargetDestroyed:(ShipEntity *)target;
- (OOBehaviour) behaviour;

View File

@ -3027,9 +3027,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{
if (primaryTarget == NO_TARGET)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
return;
}
[self trackPrimaryTarget:delta_t:NO];
@ -3058,6 +3056,11 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{
// = BEHAVIOUR_COLLECT_TARGET
ShipEntity* target = [self primaryTarget];
if (!target)
{
[self noteLostTargetAndGoIdle];
return;
}
double target_speed = [target speed];
double eta = range / (flightSpeed - target_speed);
double last_success_factor = success_factor;
@ -3078,25 +3081,15 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
desired_speed += target_speed;
if (target_speed > maxFlightSpeed)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
return;
}
}
//
if (target) // check introduced to stop crash at next line
{
destination = target->position;
desired_range = 0.5 * target->collision_radius;
[self trackDestination: delta_t : NO];
}
else
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
}
destination = target->position;
desired_range = 0.5 * target->collision_radius;
[self trackDestination: delta_t : NO];
//
if (distance < last_distance) // improvement
{
@ -3203,9 +3196,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
if (range > SCANNER_MAX_RANGE || primaryTarget == NO_TARGET)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
return;
}
@ -3295,9 +3286,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
double range = [self rangeToPrimaryTarget];
if (primaryTarget == NO_TARGET || range > SCANNER_MAX_RANGE)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
desired_speed = maxFlightSpeed * 0.375;
return;
}
@ -3333,11 +3322,10 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
if (canBurn) max_available_speed *= [self afterburnerFactor];
if (primaryTarget == NO_TARGET)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
return;
}
ShipEntity* target = [UNIVERSE entityForUniversalID:primaryTarget];
if ((range < COMBAT_IN_RANGE_FACTOR * weaponRange)||(proximity_alert != NO_TARGET))
{
if (proximity_alert == NO_TARGET || proximity_alert == primaryTarget)
@ -3349,7 +3337,6 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
ship is achieved with a z-distance at the size of the actual distance. However, to allow fast flying ships avoiding collisions,
the jink point should be defined closer to the ship itself.
*/
ShipEntity* target = [UNIVERSE entityForUniversalID:primaryTarget];
float relativeSpeed = magnitude(vector_subtract([self velocity], [target velocity]));
jink.x = (ranrot_rand() % 256) - 128.0;
jink.y = (ranrot_rand() % 256) - 128.0;
@ -3375,9 +3362,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{
if (range > SCANNER_MAX_RANGE)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
return;
}
}
@ -3386,7 +3371,6 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
//
BOOL isUsingAfterburner = canBurn && (flightSpeed > maxFlightSpeed);
double slow_down_range = weaponRange * COMBAT_WEAPON_RANGE_FACTOR * ((isUsingAfterburner)? 3.0 * [self afterburnerFactor] : 1.0);
ShipEntity* target = [UNIVERSE entityForUniversalID:primaryTarget];
double target_speed = [target speed];
if (range <= slow_down_range)
desired_speed = OOMax_d(target_speed, 0.25 * maxFlightSpeed); // within the weapon's range match speed
@ -3440,9 +3424,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
if (primaryTarget == NO_TARGET)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
[self noteLostTargetAndGoIdle];
return;
}
if (last_success_factor > success_factor) // our target is closing in.
@ -6572,6 +6554,13 @@ BOOL class_masslocks(int some_class)
}
- (void) noteLostTargetAndGoIdle
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget];
}
- (void) noteTargetDestroyed:(ShipEntity *)target
{
[self collectBountyFor:(ShipEntity *)target];
@ -6792,9 +6781,7 @@ BOOL class_masslocks(int some_class)
if (!target) // leave now!
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget]; // NOTE: was AI message: rather than reactToMessage:
[self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
return 0.0;
}
@ -6808,9 +6795,7 @@ BOOL class_masslocks(int some_class)
if (range2 > SCANNER_MAX_RANGE2)
{
behaviour = BEHAVIOUR_IDLE;
frustration = 0.0;
[self noteLostTarget]; // NOTE: was AI message: rather than reactToMessage:
[self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
return 0.0;
}

View File

@ -1199,10 +1199,12 @@ static WormholeEntity *whole = nil;
[self checkScanner];
//
GLfloat d2;
GLfloat found_d2 = SCANNER_MAX_RANGE2;
NSString* distress_message;
found_target = NO_TARGET;
BOOL is_buoy = (scanClass == CLASS_BUOY);
ShipEntity* aggressor_ship = [UNIVERSE entityForUniversalID:primaryAggressor];
if (!primaryAggressor) return;
if (messageTime > 2.0 * randf())
return; // don't send too many distress messages at once, space them out semi-randomly
@ -1217,32 +1219,34 @@ static WormholeEntity *whole = nil;
{
ShipEntity* ship = scanned_ships[i];
d2 = distance2_scanned_ships[i];
if (d2 < found_d2)
// tell it! //
if (ship->isPlayer)
{
// tell it! //
if (ship->isPlayer)
if ((primaryAggressor == [ship universalID])&&(energy < 0.375 * maxEnergy)&&(!is_buoy))
{
if ((primaryAggressor == [ship universalID])&&(energy < 0.375 * maxEnergy)&&(!is_buoy))
{
[self sendExpandedMessage:ExpandDescriptionForCurrentSystem(@"[beg-for-mercy]") toShip:ship];
[self ejectCargo];
[self performFlee];
}
else
[self sendExpandedMessage:ExpandDescriptionForCurrentSystem(distress_message) toShip:ship];
// reset the thanked_ship_id
//
thanked_ship_id = NO_TARGET;
}
if ([self bounty] == 0) // Only clean ships can have their distress calls accepted
{
if (ship->isStation)
[ship acceptDistressMessageFrom:self];
if ([ship hasPrimaryRole:@"police"]) // Not isPolice because we don't want wingmen shooting off... but what about interceptors?
[ship acceptDistressMessageFrom:self];
if ([ship hasPrimaryRole:@"hunter"])
[ship acceptDistressMessageFrom:self];
[self sendExpandedMessage:ExpandDescriptionForCurrentSystem(@"[beg-for-mercy]") toShip:ship];
[self ejectCargo];
[self performFlee];
}
else
[self sendExpandedMessage:ExpandDescriptionForCurrentSystem(distress_message) toShip:ship];
// reset the thanked_ship_id
//
thanked_ship_id = NO_TARGET;
}
else if ([self bounty] == 0 && [ship crew]) // Only clean ships can have their distress calls accepted
{
[ship doScriptEvent:@"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.
if (ship->isStation)
[ship acceptDistressMessageFrom:self];
if ([ship hasPrimaryRole:@"police"])
[ship acceptDistressMessageFrom:self];
if ([ship hasPrimaryRole:@"hunter"])
[ship acceptDistressMessageFrom:self];
}
}
}
@ -2503,33 +2507,17 @@ static WormholeEntity *whole = nil;
- (void) acceptDistressMessageFrom:(ShipEntity *)other
{
found_target = [[other primaryTarget] universalID];
switch (behaviour)
if ([self isPolice])
{
case BEHAVIOUR_ATTACK_TARGET :
case BEHAVIOUR_ATTACK_FLY_TO_TARGET :
case BEHAVIOUR_ATTACK_FLY_FROM_TARGET :
// busy - ignore the request
break;
case BEHAVIOUR_FLEE_TARGET :
// scared - ignore the request;
break;
default:
{
if ([self isPolice])
{
[[UNIVERSE entityForUniversalID:found_target] markAsOffender:8]; // you have been warned!!
}
NSString *context = nil;
#ifndef NDEBUG
context = [NSString stringWithFormat:@"%@ broadcastDistressMessage", [other shortDescription]];
#endif
[shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL" context:context];
break;
}
[[UNIVERSE entityForUniversalID:found_target] markAsOffender:8]; // you have been warned!!
}
NSString *context = nil;
#ifndef NDEBUG
context = [NSString stringWithFormat:@"%@ broadcastDistressMessage", [other shortDescription]];
#endif
[shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL" context:context];
}
@end