diff --git a/GNUmakefile b/GNUmakefile index a8818977..36ffc104 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,6 +4,7 @@ BUILD_WITH_DEBUG_FUNCTIONALITY = yes DOCKING_CLEARANCE = yes PROCEDURAL_PLANETS = yes WORMHOLE_SCANNER = yes +TARGET_INCOMING_MISSILES = no vpath %.m src/SDL:src/Core:src/Core/Entities:src/Core/Materials:src/Core/Scripting:src/Core/OXPVerifier:src/Core/Debug vpath %.h src/SDL:src/Core:src/Core/Entities:src/Core/Materials:src/Core/Scripting:src/Core/OXPVerifier:src/Core/Debug vpath %.c src/SDL:src/Core:src/BSDCompat:src/Core/Debug @@ -50,6 +51,10 @@ ifeq ($(WORMHOLE_SCANNER),yes) ADDITIONAL_CFLAGS += -DWORMHOLE_SCANNER ADDITIONAL_OBJCFLAGS += -DWORMHOLE_SCANNER endif +ifeq ($(TARGET_INCOMING_MISSILES),yes) + ADDITIONAL_CFLAGS += -DTARGET_INCOMING_MISSILES + ADDITIONAL_OBJCFLAGS += -DTARGET_INCOMING_MISSILES +endif OBJC_PROGRAM_NAME = oolite diff --git a/src/Cocoa/JoystickHandler.h b/src/Cocoa/JoystickHandler.h index 9bb66250..f97b8c83 100644 --- a/src/Cocoa/JoystickHandler.h +++ b/src/Cocoa/JoystickHandler.h @@ -87,6 +87,9 @@ enum { BUTTON_ARMMISSILE, BUTTON_LAUNCHMISSILE, BUTTON_UNARM, +#ifdef TARGET_INCOMING_MISSILES + BUTTON_TARGETINCOMINGMISSILE, +#endif BUTTON_CYCLEMISSILE, BUTTON_ENERGYBOMB, BUTTON_ID, diff --git a/src/Core/Entities/PlayerEntity.h b/src/Core/Entities/PlayerEntity.h index 047b745e..21665a60 100644 --- a/src/Core/Entities/PlayerEntity.h +++ b/src/Core/Entities/PlayerEntity.h @@ -349,6 +349,9 @@ typedef enum OOKeyCode key_target_missile; OOKeyCode key_untarget_missile; +#ifdef TARGET_INCOMING_MISSILES + OOKeyCode key_target_incoming_missile; +#endif OOKeyCode key_ident_system; OOKeyCode key_scanner_zoom; diff --git a/src/Core/Entities/PlayerEntityControls.m b/src/Core/Entities/PlayerEntityControls.m index ee2b36aa..df55ecaf 100644 --- a/src/Core/Entities/PlayerEntityControls.m +++ b/src/Core/Entities/PlayerEntityControls.m @@ -62,6 +62,9 @@ static BOOL previous_target_pressed; static BOOL next_missile_pressed; static BOOL fire_missile_pressed; static BOOL target_missile_pressed; +#ifdef TARGET_INCOMING_MISSILES +static BOOL target_incoming_missile_pressed; +#endif static BOOL ident_pressed; static BOOL safety_pressed; static BOOL cloak_pressed; @@ -190,6 +193,9 @@ static NSTimeInterval time_last_frame; LOAD_KEY_SETTING(key_target_missile, 't' ); LOAD_KEY_SETTING(key_untarget_missile, 'u' ); +#ifdef TARGET_INCOMING_MISSILES + LOAD_KEY_SETTING(key_target_incoming_missile, 'T' ); +#endif LOAD_KEY_SETTING(key_ident_system, 'r' ); LOAD_KEY_SETTING(key_scanner_zoom, 'z' ); @@ -688,6 +694,18 @@ static NSTimeInterval time_last_frame; ident_pressed = YES; } else ident_pressed = NO; +#ifdef TARGET_INCOMING_MISSILES + // target nearest incoming missile 'T' - useful for quickly giving a missile target to turrets + if ([gameView isDown:key_target_incoming_missile] || joyButtonState[BUTTON_TARGETINCOMINGMISSILE]) + { + if (!target_incoming_missile_pressed) + { + [self targetNearestIncomingMissile]; + } + target_incoming_missile_pressed = YES; + } + else target_incoming_missile_pressed = NO; +#endif // shoot 't' // switch on missile targetting if (([gameView isDown:key_target_missile] || joyButtonState[BUTTON_ARMMISSILE])&&(missile_entity[activeMissile])) diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.h b/src/Core/Entities/PlayerEntityLegacyScriptEngine.h index 612911e4..4e0d0e71 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.h +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.h @@ -233,6 +233,9 @@ typedef enum - (BOOL) mapKey:(NSString *) keycode toOXP:(OOScript *)oxp; - (void) targetNearestHostile; +#ifdef TARGET_INCOMING_MISSILES +- (void) targetNearestIncomingMissile; +#endif - (void) setGalacticHyperspaceBehaviourTo:(NSString *) galacticHyperspaceBehaviourString; - (void) setGalacticHyperspaceFixedCoordsTo:(NSString *) galacticHyperspaceFixedCoordsString; diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index bd299e02..ec457b6d 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -2645,6 +2645,24 @@ static int scriptRandomSeed = -1; // ensure proper random function } +#ifdef TARGET_INCOMING_MISSILES +- (void) targetNearestIncomingMissile +{ + [self scanForNearestIncomingMissile]; + if (found_target != NO_TARGET) + { + Entity *ent = [UNIVERSE entityForUniversalID:found_target]; + if (ent != 0x00) + { + ident_engaged = YES; + missile_status = MISSILE_STATUS_TARGET_LOCKED; + [self addTarget:ent]; + } + } +} +#endif + + - (void) setGalacticHyperspaceBehaviourTo:(NSString *)galacticHyperspaceBehaviourString { OOGalacticHyperspaceBehaviour ghBehaviour = StringToGalacticHyperspaceBehaviour(galacticHyperspaceBehaviourString); diff --git a/src/Core/Entities/PlayerEntityStickMapper.m b/src/Core/Entities/PlayerEntityStickMapper.m index cdd07868..87db62fb 100644 --- a/src/Core/Entities/PlayerEntityStickMapper.m +++ b/src/Core/Entities/PlayerEntityStickMapper.m @@ -425,6 +425,13 @@ MA 02110-1301, USA. allowable: HW_BUTTON axisfn: STICK_NOFUNCTION butfn: BUTTON_UNARM]]; +#ifdef TARGET_INCOMING_MISSILES + [funcList addObject: + [self makeStickGuiDict: @"Target nearest incoming missile" + allowable: HW_BUTTON + axisfn: STICK_NOFUNCTION + butfn: BUTTON_TARGETINCOMINGMISSILE]]; +#endif [funcList addObject: [self makeStickGuiDict: @"Cycle secondary" allowable: HW_BUTTON diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index f48a6f1a..195c475c 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -3575,6 +3575,8 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple { if (primaryTarget == NO_TARGET) return NO; + if ([self isMissile]) + return YES; // missiles are always fired against a hostile target if ((behaviour == BEHAVIOUR_AVOID_COLLISION)&&(previousCondition)) { int old_behaviour = [previousCondition intForKey:@"behaviour"]; diff --git a/src/Core/Entities/ShipEntityAI.h b/src/Core/Entities/ShipEntityAI.h index 3b90774d..acdf6e7f 100644 --- a/src/Core/Entities/ShipEntityAI.h +++ b/src/Core/Entities/ShipEntityAI.h @@ -37,8 +37,10 @@ MA 02110-1301, USA. - (void) switchAITo:(NSString *)aiString; - (void) scanForHostiles; - - (void) performTumble; - (void) performStop; +#ifdef TARGET_INCOMING_MISSILES +- (void) scanForNearestIncomingMissile; +#endif @end diff --git a/src/Core/Entities/ShipEntityAI.m b/src/Core/Entities/ShipEntityAI.m index bb50b70f..67547daf 100644 --- a/src/Core/Entities/ShipEntityAI.m +++ b/src/Core/Entities/ShipEntityAI.m @@ -274,6 +274,19 @@ MA 02110-1301, USA. } +#ifdef TARGET_INCOMING_MISSILES +- (void) scanForNearestIncomingMissile +{ + BinaryOperationPredicateParameter param = + { + HasScanClassPredicate, [NSNumber numberWithInt:CLASS_MISSILE], + IsHostileAgainstTargetPredicate, self + }; + [self scanForNearestShipWithPredicate:ANDPredicate parameter:¶m]; +} +#endif + + - (void) performTumble { flightRoll = max_flight_roll*2.0*(randf() - 0.5); diff --git a/src/Core/OOEntityFilterPredicate.h b/src/Core/OOEntityFilterPredicate.h index bb47515b..6955fc93 100644 --- a/src/Core/OOEntityFilterPredicate.h +++ b/src/Core/OOEntityFilterPredicate.h @@ -73,3 +73,6 @@ BOOL HasRolePredicate(Entity *ship, void *parameter); // Parameter: NSString BOOL HasPrimaryRolePredicate(Entity *ship, void *parameter); // Parameter: NSString BOOL HasRoleInSetPredicate(Entity *ship, void *parameter); // Parameter: NSSet BOOL HasPrimaryRoleInSetPredicate(Entity *ship, void *parameter); // Parameter: NSSet +#ifdef TARGET_INCOMING_MISSILES +BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter); // Parameter: id +#endif diff --git a/src/Core/OOEntityFilterPredicate.m b/src/Core/OOEntityFilterPredicate.m index 0d75d92e..dcbb4a73 100644 --- a/src/Core/OOEntityFilterPredicate.m +++ b/src/Core/OOEntityFilterPredicate.m @@ -166,3 +166,11 @@ BOOL HasPrimaryRoleInSetPredicate(Entity *ship, void *parameter) { return [(NSSet *)parameter containsObject:[(ShipEntity *)ship primaryRole]]; } + + +#ifdef TARGET_INCOMING_MISSILES +BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter) +{ + return [(ShipEntity *)ship hasHostileTarget] && [(ShipEntity *)ship primaryTarget] == (ShipEntity *)parameter; +} +#endif diff --git a/src/Core/OOLogHeader.m b/src/Core/OOLogHeader.m index b57d9c9c..d4184b40 100644 --- a/src/Core/OOLogHeader.m +++ b/src/Core/OOLogHeader.m @@ -115,7 +115,13 @@ void OOPrintLogHeader(void) #define OPT3_STR "" #endif - #define OPT_STR OPT1_STR OPT2_STR OPT3_STR + #ifdef TARGET_INCOMING_MISSILES + #define OPT4_STR " [Target Incoming Missiles]" + #else + #define OPT4_STR "" + #endif + + #define OPT_STR OPT1_STR OPT2_STR OPT3_STR OPT4_STR // systemString: NSString with system type and possibly version. #if OOLITE_MAC_OS_X diff --git a/src/SDL/JoystickHandler.h b/src/SDL/JoystickHandler.h index 68356ee9..8e751414 100644 --- a/src/SDL/JoystickHandler.h +++ b/src/SDL/JoystickHandler.h @@ -66,6 +66,9 @@ enum { BUTTON_FIRE, BUTTON_ARMMISSILE, BUTTON_LAUNCHMISSILE, +#ifdef TARGET_INCOMING_MISSILES + BUTTON_TARGETINCOMINGMISSILE, +#endif BUTTON_UNARM, BUTTON_CYCLEMISSILE, BUTTON_ENERGYBOMB,