RADIO.CPP (15961B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: /CounterStrike/RADIO.CPP 1 3/03/97 10:25a Joe_bostic $ */ 17 /*********************************************************************************************** 18 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : RADIO.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : September 10, 1993 * 28 * * 29 * Last Update : June 5, 1996 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * RadioClass::Debug_Dump -- Displays the current status of the radio to the mono monitor. * 34 * RadioClass::Limbo -- When limboing a unit will always break radio contact. * 35 * RadioClass::Receive_Message -- Handles receipt of a radio message. * 36 * RadioClass::Transmit_Message -- Transmit message from one object to another. * 37 * RadioClass::Transmit_Message -- Transmits a message to the object specified. * 38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 39 40 #include "function.h" 41 42 43 /* 44 ** These are the text representations of the radio messages that can be transmitted. 45 */ 46 char const * RadioClass::Messages[RADIO_COUNT] = { 47 "static (no message)", 48 "Roger.", 49 "Come in.", 50 "Over and out.", 51 "Requesting transport.", 52 "Attach to transport.", 53 "I've got a delivery for you.", 54 "I'm performing load/unload maneuver. Be careful.", 55 "I'm clear.", 56 "You are clear to unload. Driving away now.", 57 "Am unable to comply.", 58 "I'm starting construction now... act busy.", 59 "I've finished construction. You are free.", 60 "We bumped, redraw yourself please.", 61 "I'm trying to load up now.", 62 "May I become a passenger?", 63 "Are you ready to receive shipment?", 64 "Are you trying to become a passenger?", 65 "Move to location X.", 66 "Do you need to move?", 67 "All right already. Now what?", 68 "I'm a passenger now.", 69 "Backup into refinery now.", 70 "Run away!", 71 "Tether established.", 72 "Tether broken.", 73 "Repair one step.", 74 "Are you prepared to fight?", 75 "Attack this target please.", 76 "Reload one step.", 77 "Circumstances prevent success.", 78 "All done with the request.", 79 "Do you need service depot work?", 80 "Are you sitting on service depot?" 81 }; 82 83 84 #ifdef CHEAT_KEYS 85 /*********************************************************************************************** 86 * RadioClass::Debug_Dump -- Displays the current status of the radio to the mono monitor. * 87 * * 88 * This displays the radio connection value to the monochrome monitor. * 89 * * 90 * INPUT: none * 91 * * 92 * OUTPUT: none * 93 * * 94 * WARNINGS: none * 95 * * 96 * HISTORY: * 97 * 06/02/1994 JLB : Created. * 98 *=============================================================================================*/ 99 void RadioClass::Debug_Dump(MonoClass * mono) const 100 { 101 assert(IsActive); 102 103 mono->Set_Cursor(29, 7);mono->Printf("0-%-47s", Messages[Old[0]]); 104 mono->Set_Cursor(29, 8);mono->Printf("1-%-47s", Messages[Old[1]]); 105 mono->Set_Cursor(29, 9);mono->Printf("2-%-47s", Messages[Old[2]]); 106 if (Radio) { 107 mono->Set_Cursor(20, 7);mono->Printf("%08X", Radio->As_Target()); 108 } 109 MissionClass::Debug_Dump(mono); 110 } 111 #endif 112 113 114 /*********************************************************************************************** 115 * RadioClass::Receive_Message -- Handles receipt of a radio message. * 116 * * 117 * This is the base version of what should happen when a radio message is received. It * 118 * turns the radio off when the "OVER_OUT" message is received. All other messages are * 119 * merely acknowledged with a "ROGER". * 120 * * 121 * INPUT: from -- The object that is initiating this radio message (always valid). * 122 * * 123 * message -- The radio message received. * 124 * * 125 * param -- Reference to optional value that might be used to return more * 126 * information than can be conveyed in the simple radio response * 127 * messages. * 128 * * 129 * OUTPUT: Returns with the response radio message. * 130 * * 131 * WARNINGS: none * 132 * * 133 * HISTORY: * 134 * 05/28/1994 JLB : Created. * 135 * 09/24/1994 JLB : Streamlined to be only a communications carrier. * 136 * 05/22/1995 JLB : Recognized who is sending the message * 137 * 06/05/1996 JLB : Radio message history tracking. * 138 *=============================================================================================*/ 139 RadioMessageType RadioClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param) 140 { 141 assert(IsActive); 142 143 /* 144 ** Keep a record of the last message received by this radio. 145 */ 146 if (message != Old[0]) { 147 Old[2] = Old[1]; 148 Old[1] = Old[0]; 149 Old[0] = message; 150 } 151 152 /* 153 ** When this message is received, it means that the other object 154 ** has already turned its radio off. Turn this radio off as well. 155 ** This only applies if the message is coming from the object that 156 ** has an established conversation with this object. 157 */ 158 if (from == Radio && message == RADIO_OVER_OUT) { 159 MissionClass::Receive_Message(from, message, param); 160 Radio_Off(); 161 return(RADIO_ROGER); 162 } 163 164 /* 165 ** The "hello" message is an attempt to establish contact. If this radio 166 ** is already in an established conversation with another object, then 167 ** return with "negative". If all is well, return with "roger". 168 */ 169 if (message == RADIO_HELLO && Strength) { 170 if (Radio == from || Radio == NULL) { 171 Radio = from; 172 return(RADIO_ROGER); 173 } 174 return(RADIO_NEGATIVE); 175 } 176 177 return(MissionClass::Receive_Message(from, message, param)); 178 } 179 180 181 /*********************************************************************************************** 182 * RadioClass::Transmit_Message -- Transmit message from one object to another. * 183 * * 184 * This routine is used to transmit a radio message from this object to another. Most * 185 * inter object coordination is handled through this mechanism. * 186 * * 187 * INPUT: to -- Pointer to the object that will receive the radio message. * 188 * * 189 * message -- The message itself (see RadioType). * 190 * * 191 * param -- Optional reference to parameter that might be used to pass or * 192 * receive additional information. * 193 * * 194 * OUTPUT: Returns with the response radio message from the receiving object. * 195 * * 196 * WARNINGS: none * 197 * * 198 * HISTORY: * 199 * 05/22/1995 JLB : Created. * 200 *=============================================================================================*/ 201 RadioMessageType RadioClass::Transmit_Message(RadioMessageType message, long & param, RadioClass * to) 202 { 203 assert(IsActive); 204 205 if (to == NULL) { 206 to = Contact_With_Whom(); 207 } 208 209 /* 210 ** If there is no target for the radio message, then always return static. 211 */ 212 if (to == NULL) return(RADIO_STATIC); 213 214 /* 215 ** Handle some special case processing that occurs when certain messages 216 ** are transmitted. 217 */ 218 if (to == Radio && message == RADIO_OVER_OUT) { 219 Radio = 0; 220 } 221 222 /* 223 ** If this object is not in radio contact but the message 224 ** indicates that radio contact should be established, then 225 ** try to do so. If the other party agrees then contact 226 ** is established. 227 */ 228 if (message == RADIO_HELLO) { 229 Transmit_Message(RADIO_OVER_OUT); 230 if (to->Receive_Message(this, message, param) == RADIO_ROGER) { 231 Radio = to; 232 return(RADIO_ROGER); 233 } 234 return(RADIO_NEGATIVE); 235 } 236 237 return(to->Receive_Message(this, message, param)); 238 } 239 240 241 /*********************************************************************************************** 242 * RadioClass::Limbo -- When limboing a unit will always break radio contact. * 243 * * 244 * This routine will break radio contact as the object is entering limbo state. * 245 * * 246 * INPUT: none * 247 * * 248 * OUTPUT: Was the object successfully limboed? * 249 * * 250 * WARNINGS: none * 251 * * 252 * HISTORY: * 253 * 06/25/1995 JLB : Created. * 254 *=============================================================================================*/ 255 bool RadioClass::Limbo(void) 256 { 257 assert(IsActive); 258 259 if (!IsInLimbo) { 260 Transmit_Message(RADIO_OVER_OUT); 261 } 262 return(MissionClass::Limbo()); 263 } 264 265 266 /*********************************************************************************************** 267 * RadioClass::Transmit_Message -- Transmits a message to the object specified. * 268 * * 269 * This routine will transmit the specified message to the object. This routine differs * 270 * from the normal Transmit_Message in that the LParam value is "faked" into the * 271 * parameter list. It is presumed that the message sent with this function does not * 272 * require the LParam. * 273 * * 274 * INPUT: message -- The message to transmit. * 275 * * 276 * to -- The requested receiver of this message. * 277 * * 278 * OUTPUT: Returns with the radio response from the receiver. * 279 * * 280 * WARNINGS: none * 281 * * 282 * HISTORY: * 283 * 09/21/1995 JLB : Created. * 284 *=============================================================================================*/ 285 RadioMessageType RadioClass::Transmit_Message(RadioMessageType message, RadioClass * to) 286 { 287 assert(IsActive); 288 289 return(Transmit_Message(message, LParam, to)); 290 }