From edf000ec1de666259f384168a6e7cae8424f3de9 Mon Sep 17 00:00:00 2001 From: Nikos Barkas Date: Fri, 2 May 2008 17:43:40 +0000 Subject: [PATCH] Implemented commsMessageByUnpiloted for legacy scripts and ship AI. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1606 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/Entities/PlayerEntityLegacyScriptEngine.h | 8 +++----- src/Core/Entities/PlayerEntityLegacyScriptEngine.m | 4 ++-- src/Core/Entities/ShipEntity.h | 2 ++ src/Core/Entities/ShipEntity.m | 10 ++++++++-- src/Core/Entities/ShipEntityAI.h | 2 ++ src/Core/Entities/ShipEntityAI.m | 14 +++++++++++++- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.h b/src/Core/Entities/PlayerEntityLegacyScriptEngine.h index 37f74785..e9f436c6 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.h +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.h @@ -116,11 +116,9 @@ MA 02110-1301, USA. - (void) clearMissionDescriptionForMission:(NSString *)key; - (void) commsMessage:(NSString *)valueString; - -#if 0 // Disabled until approved for inclusion. -- (void) commsMessageByUnpiloted:(NSString *)valueString; // Same as commsMessage, but can be used by scripts to have - // unpiloted ships sending commsMessages, if we want to. -#endif +- (void) commsMessageByUnpiloted:(NSString *)valueString; // Enabled 02-May-2008 - Nikos. Same as commsMessage, but + // can be used by scripts to have unpiloted ships sending + // commsMessages, if we want to. - (void) consoleMessage3s:(NSString *)valueString; - (void) consoleMessage6s:(NSString *)valueString; diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index 3b671fed..e0f740a4 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -1153,14 +1153,14 @@ static int scriptRandomSeed = -1; // ensure proper random function } -#if 0 // Disabled until approved for inclusion. +// Enabled on 02-May-2008 - Nikos // This method does the same as -commsMessage, (which in fact calls), the difference being that scripts can use this // method to have unpiloted ship entities sending comms messages. - (void) commsMessageByUnpiloted:(NSString *)valueString { [self commsMessage:valueString]; } -#endif + - (void) consoleMessage3s:(NSString *)valueString { diff --git a/src/Core/Entities/ShipEntity.h b/src/Core/Entities/ShipEntity.h index d2e28b17..df58ee22 100644 --- a/src/Core/Entities/ShipEntity.h +++ b/src/Core/Entities/ShipEntity.h @@ -687,6 +687,8 @@ BOOL class_masslocks(int some_class); - (void) sendExpandedMessage:(NSString *) message_text toShip:(ShipEntity*) other_ship; - (void) broadcastAIMessage:(NSString *) ai_message; - (void) broadcastMessage:(NSString *) message_text; +// Unpiloted ships cannot broadcast messages, unless the unpilotedOverride is set to YES. +- (void) broadcastMessage:(NSString *) message_text withUnpilotedOverride:(BOOL) unpilotedOverride; - (void) setCommsMessageColor; - (void) receiveCommsMessage:(NSString *) message_text; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 5d2c6f08..88e89960 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -7530,11 +7530,17 @@ static BOOL AuthorityPredicate(Entity *entity, void *parameter) - (void) broadcastMessage:(NSString *) message_text +{ + [self broadcastMessage:message_text withUnpilotedOverride:NO]; +} + + +- (void) broadcastMessage:(NSString *) message_text withUnpilotedOverride:(BOOL) unpilotedOverride { NSString* expandedMessage = [NSString stringWithFormat:@"%@:\n %@", displayName, ExpandDescriptionForCurrentSystem(message_text)]; - if (!crew) - return; // nobody to send the signal + if (!crew && !unpilotedOverride) + return; // nobody to send the signal and no override for unpiloted craft is set [self setCommsMessageColor]; [self checkScanner]; diff --git a/src/Core/Entities/ShipEntityAI.h b/src/Core/Entities/ShipEntityAI.h index e073e409..6bd2f641 100644 --- a/src/Core/Entities/ShipEntityAI.h +++ b/src/Core/Entities/ShipEntityAI.h @@ -124,6 +124,8 @@ MA 02110-1301, USA. - (void) wormholeEntireGroup; - (void) commsMessage:(NSString *)valueString; +- (void) commsMessageByUnpiloted:(NSString *)valueString; +- (void) commsMessage:(NSString *)valueString withUnpilotedOverride:(BOOL)unpilotedOverride; - (void) broadcastDistressMessage; - (void) acceptDistressMessageFrom:(ShipEntity *)other; diff --git a/src/Core/Entities/ShipEntityAI.m b/src/Core/Entities/ShipEntityAI.m index 618bb175..91ad9c00 100644 --- a/src/Core/Entities/ShipEntityAI.m +++ b/src/Core/Entities/ShipEntityAI.m @@ -799,6 +799,18 @@ WormholeEntity* whole; - (void) commsMessage:(NSString *)valueString +{ + [self commsMessage:valueString withUnpilotedOverride:NO]; +} + + +- (void) commsMessageByUnpiloted:(NSString *)valueString +{ + [self commsMessage:valueString withUnpilotedOverride:YES]; +} + + +- (void) commsMessage:(NSString *)valueString withUnpilotedOverride:(BOOL)unpilotedOverride { Random_Seed very_random_seed; very_random_seed.a = rand() & 255; @@ -811,7 +823,7 @@ WormholeEntity* whole; NSString* expandedMessage = ExpandDescriptionForCurrentSystem(valueString); - [self broadcastMessage:expandedMessage]; + [self broadcastMessage:expandedMessage withUnpilotedOverride:unpilotedOverride]; }