MISSION.CPP 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /CounterStrike/MISSION.CPP 1 3/03/97 10:25a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** 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 ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : MISSION.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 23, 1994 *
  30. * *
  31. * Last Update : September 14, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * MissionClass::AI -- Processes order script. *
  36. * MissionClass::Assign_Mission -- Give an order to a unit. *
  37. * MissionClass::Commence -- Start script with new order. *
  38. * MissionClass::Debug_Dump -- Dumps status values to mono screen. *
  39. * MissionClass::Get_Mission -- Fetches the mission that this object is acting under. *
  40. * MissionClass::MissionClass -- Default constructor for the mission object type. *
  41. * MissionClass::Mission_??? -- Stub mission functions that do nothing. *
  42. * MissionClass::Mission_From_Name -- Fetch order pointer from its name. *
  43. * MissionClass::Mission_Name -- Converts a mission number into an ASCII string. *
  44. * MissionClass::Override_Mission -- temporarily overrides the units mission *
  45. * MissionClass::Restore_Mission -- Restores overridden mission *
  46. * MissionClass::Set_Mission -- Sets the mission to the specified value. *
  47. * MissionClass::Is_Recruitable_Mission -- Determines if this mission is recruitable for a te*
  48. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  49. #include "function.h"
  50. /***********************************************************************************************
  51. * MissionClass::MissionClass -- Default constructor for the mission object type. *
  52. * *
  53. * This is the default constructor for the mission class object. It sets the mission *
  54. * handler into a default -- do nothing -- state. *
  55. * *
  56. * INPUT: none *
  57. * *
  58. * OUTPUT: none *
  59. * *
  60. * WARNINGS: none *
  61. * *
  62. * HISTORY: *
  63. * 01/23/1995 JLB : Created. *
  64. * 03/01/1996 JLB : Uses initializer lists. *
  65. *=============================================================================================*/
  66. MissionClass::MissionClass(RTTIType rtti, int id) :
  67. ObjectClass(rtti, id),
  68. Mission(MISSION_NONE),
  69. SuspendedMission(MISSION_NONE),
  70. MissionQueue(MISSION_NONE),
  71. Status(0),
  72. Timer(0)
  73. {
  74. }
  75. /***********************************************************************************************
  76. * MissionClass::Mission_??? -- Stub mission functions that do nothing. *
  77. * *
  78. * These are the stub routines that handle the mission logic. They do nothing at this *
  79. * level. Derived classes will override these routine as necessary. *
  80. * *
  81. * INPUT: none *
  82. * *
  83. * OUTPUT: Returns with the number of game frames to delay before calling this mission *
  84. * handler again. *
  85. * *
  86. * WARNINGS: none *
  87. * *
  88. * HISTORY: *
  89. * 01/23/1995 JLB : Created. *
  90. *=============================================================================================*/
  91. int MissionClass::Mission_Sleep(void) {return TICKS_PER_SECOND*30;};
  92. int MissionClass::Mission_Ambush(void) {return TICKS_PER_SECOND*30;};
  93. int MissionClass::Mission_Attack(void) {return TICKS_PER_SECOND*30;};
  94. int MissionClass::Mission_Capture(void) {return TICKS_PER_SECOND*30;};
  95. int MissionClass::Mission_Guard(void) {return TICKS_PER_SECOND*30;};
  96. int MissionClass::Mission_Guard_Area(void) {return TICKS_PER_SECOND*30;};
  97. int MissionClass::Mission_Harvest(void) {return TICKS_PER_SECOND*30;};
  98. int MissionClass::Mission_Hunt(void) {return TICKS_PER_SECOND*30;};
  99. int MissionClass::Mission_Move(void) {return TICKS_PER_SECOND*30;};
  100. int MissionClass::Mission_Retreat(void) {return TICKS_PER_SECOND*30;};
  101. int MissionClass::Mission_Return(void) {return TICKS_PER_SECOND*30;};
  102. int MissionClass::Mission_Stop(void) {return TICKS_PER_SECOND*30;};
  103. int MissionClass::Mission_Unload(void) {return TICKS_PER_SECOND*30;};
  104. int MissionClass::Mission_Enter(void) {return TICKS_PER_SECOND*30;};
  105. int MissionClass::Mission_Construction(void) {return TICKS_PER_SECOND*30;};
  106. int MissionClass::Mission_Deconstruction(void) {return TICKS_PER_SECOND*30;};
  107. int MissionClass::Mission_Repair(void) {return TICKS_PER_SECOND*30;};
  108. int MissionClass::Mission_Missile(void) {return TICKS_PER_SECOND*30;};
  109. /***********************************************************************************************
  110. * MissionClass::Set_Mission -- Sets the mission to the specified value. *
  111. * *
  112. * Use this routine to set the current mission for this object. This routine will blast *
  113. * over the current mission, bypassing the queue method. Call it when the mission needs *
  114. * to be changed immediately. *
  115. * *
  116. * INPUT: mission -- The mission to set to. *
  117. * *
  118. * OUTPUT: none *
  119. * *
  120. * WARNINGS: none *
  121. * *
  122. * HISTORY: *
  123. * 01/23/1995 JLB : Created. *
  124. *=============================================================================================*/
  125. void MissionClass::Set_Mission(MissionType mission)
  126. {
  127. assert(IsActive);
  128. Mission = mission;
  129. MissionQueue = MISSION_NONE;
  130. }
  131. /***********************************************************************************************
  132. * MissionClass::Get_Mission -- Fetches the mission that this object is acting under. *
  133. * *
  134. * Use this routine to fetch the mission that this object is CURRENTLY acting under. The *
  135. * mission queue may be filled with a imminent mission change, but this routine does not *
  136. * consider that. It only returns the CURRENT mission. *
  137. * *
  138. * INPUT: none *
  139. * *
  140. * OUTPUT: Returns with the mission that this unit is currently following. *
  141. * *
  142. * WARNINGS: none *
  143. * *
  144. * HISTORY: *
  145. * 01/23/1995 JLB : Created. *
  146. *=============================================================================================*/
  147. MissionType MissionClass::Get_Mission(void) const
  148. {
  149. assert(IsActive);
  150. return(Mission == MISSION_NONE ? MissionQueue : Mission);
  151. }
  152. #ifdef CHEAT_KEYS
  153. /***********************************************************************************************
  154. * MissionClass::Debug_Dump -- Dumps status values to mono screen. *
  155. * *
  156. * This is a debugging function that dumps this class' status to the monochrome screen *
  157. * for review. *
  158. * *
  159. * INPUT: none *
  160. * *
  161. * OUTPUT: none *
  162. * *
  163. * WARNINGS: none *
  164. * *
  165. * HISTORY: *
  166. * 05/28/1994 JLB : Created. *
  167. *=============================================================================================*/
  168. void MissionClass::Debug_Dump(MonoClass * mono) const
  169. {
  170. assert(IsActive);
  171. mono->Set_Cursor(1, 9);mono->Printf("%-14s", MissionClass::Mission_Name(Mission));
  172. mono->Set_Cursor(16, 9);mono->Printf("%-12s", MissionClass::Mission_Name(MissionQueue));
  173. mono->Set_Cursor(1, 7);mono->Printf("%3d", (long)Timer);
  174. mono->Set_Cursor(6, 7);mono->Printf("%2d", Status);
  175. ObjectClass::Debug_Dump(mono);
  176. }
  177. #endif
  178. /***********************************************************************************************
  179. * MissionClass::AI -- Processes order script. *
  180. * *
  181. * This routine will process the order script for as much time as *
  182. * possible or until a script delay is detected. This routine should *
  183. * be called for every unit once per game loop (if possible). *
  184. * *
  185. * INPUT: none *
  186. * *
  187. * OUTPUT: none *
  188. * *
  189. * WARNINGS: none *
  190. * *
  191. * HISTORY: *
  192. * 04/23/1994 JLB : Created. *
  193. * 06/25/1995 JLB : Added new missions. *
  194. *=============================================================================================*/
  195. void MissionClass::AI(void)
  196. {
  197. assert(IsActive);
  198. ObjectClass::AI();
  199. /*
  200. ** If this is the kind of object that is "paralyzed with fear" while it is above
  201. ** ground level (such as when be paradropped), it will perform no mission AI
  202. ** processing.
  203. */
  204. if ((What_Am_I() == RTTI_INFANTRY || What_Am_I() == RTTI_UNIT || What_Am_I() == RTTI_VESSEL) && Height > 0) {
  205. return;
  206. }
  207. /*
  208. ** This is the script AI equivalent processing.
  209. */
  210. BStart(BENCH_MISSION);
  211. if (Timer == 0 && Strength > 0) {
  212. switch (Mission) {
  213. default:
  214. Timer = Mission_Sleep();
  215. break;
  216. case MISSION_HARMLESS:
  217. case MISSION_SLEEP:
  218. Timer = Mission_Sleep();
  219. break;
  220. case MISSION_STICKY:
  221. case MISSION_GUARD:
  222. Timer = Mission_Guard();
  223. break;
  224. case MISSION_ENTER:
  225. Timer = Mission_Enter();
  226. break;
  227. case MISSION_CONSTRUCTION:
  228. Timer = Mission_Construction();
  229. break;
  230. case MISSION_DECONSTRUCTION:
  231. Timer = Mission_Deconstruction();
  232. break;
  233. case MISSION_CAPTURE:
  234. case MISSION_SABOTAGE:
  235. Timer = Mission_Capture();
  236. break;
  237. case MISSION_QMOVE:
  238. case MISSION_MOVE:
  239. Timer = Mission_Move();
  240. break;
  241. case MISSION_ATTACK:
  242. Timer = Mission_Attack();
  243. break;
  244. case MISSION_RETREAT:
  245. Timer = Mission_Retreat();
  246. break;
  247. case MISSION_HARVEST:
  248. Timer = Mission_Harvest();
  249. break;
  250. case MISSION_GUARD_AREA:
  251. Timer = Mission_Guard_Area();
  252. break;
  253. case MISSION_RETURN:
  254. Timer = Mission_Return();
  255. break;
  256. case MISSION_STOP:
  257. Timer = Mission_Stop();
  258. break;
  259. case MISSION_AMBUSH:
  260. Timer = Mission_Ambush();
  261. break;
  262. case MISSION_HUNT:
  263. case MISSION_RESCUE:
  264. Timer = Mission_Hunt();
  265. break;
  266. // case MISSION_TIMED_HUNT:
  267. // Timer = Mission_Timed_Hunt();
  268. // break;
  269. case MISSION_UNLOAD:
  270. Timer = Mission_Unload();
  271. break;
  272. case MISSION_REPAIR:
  273. Timer = Mission_Repair();
  274. break;
  275. case MISSION_MISSILE:
  276. Timer = Mission_Missile();
  277. break;
  278. }
  279. }
  280. BEnd(BENCH_MISSION);
  281. }
  282. /***********************************************************************************************
  283. * MissionClass::Commence -- Start script with new order. *
  284. * *
  285. * This routine will start script processing according to any queued *
  286. * order it may have. If there is no queued order, then this routine *
  287. * does nothing. Call this routine whenever the unit is in a good *
  288. * position to change its order (such as when it is stopped). *
  289. * *
  290. * INPUT: none *
  291. * *
  292. * OUTPUT: Did the mission actually change? *
  293. * *
  294. * WARNINGS: none *
  295. * *
  296. * HISTORY: *
  297. * 04/23/1994 JLB : Created. *
  298. * 07/14/1994 JLB : Simplified. *
  299. * 06/17/1995 JLB : Returns success flag. *
  300. *=============================================================================================*/
  301. bool MissionClass::Commence(void)
  302. {
  303. assert(IsActive);
  304. if (MissionQueue != MISSION_NONE) {
  305. Mission = MissionQueue;
  306. MissionQueue = MISSION_NONE;
  307. /*
  308. ** Force immediate state machine processing at the first state machine state value.
  309. */
  310. Timer = 0;
  311. Status = 0;
  312. return(true);
  313. }
  314. return(false);
  315. }
  316. /***********************************************************************************************
  317. * MissionClass::Assign_Mission -- Give an order to a unit. *
  318. * *
  319. * This routine will assign the specified mission to the mission queue for this object. *
  320. * The actual mission logic will then be performed at the first available and legal *
  321. * opportunity. *
  322. * *
  323. * INPUT: order -- Mission to give the unit. *
  324. * *
  325. * OUTPUT: none *
  326. * *
  327. * WARNINGS: none *
  328. * *
  329. * HISTORY: *
  330. * 06/04/1991 JLB : Created. *
  331. * 04/15/1994 JLB : Converted to member function. *
  332. *=============================================================================================*/
  333. void MissionClass::Assign_Mission(MissionType order)
  334. {
  335. assert(IsActive);
  336. /*
  337. ** Ensure that a MISSION_QMOVE is translated into a MISSION_MOVE.
  338. */
  339. if (order == MISSION_QMOVE) order = MISSION_MOVE;
  340. if (order != MISSION_NONE && Mission != order) {
  341. MissionQueue = order;
  342. }
  343. }
  344. /***********************************************************************************************
  345. * MissionClass::Mission_From_Name -- Fetch order pointer from its name. *
  346. * *
  347. * This routine is used to convert an ASCII order name into the actual *
  348. * order number it represents. Typically, this is used when processing *
  349. * a scenario INI file. *
  350. * *
  351. * INPUT: name -- The ASCII order name to process. *
  352. * *
  353. * OUTPUT: Returns with the actual order number that the ASCII name *
  354. * represents. *
  355. * *
  356. * WARNINGS: none *
  357. * *
  358. * HISTORY: *
  359. * 10/07/1992 JLB : Created. *
  360. * 04/22/1994 JLB : Converted to static member function. *
  361. *=============================================================================================*/
  362. MissionType MissionClass::Mission_From_Name(char const * name)
  363. {
  364. MissionType order;
  365. if (name) {
  366. for (order = MISSION_FIRST; order < MISSION_COUNT; order++) {
  367. if (stricmp(Missions[order], name) == 0) {
  368. return(order);
  369. }
  370. }
  371. }
  372. return(MISSION_NONE);
  373. }
  374. /***********************************************************************************************
  375. * MissionClass::Mission_Name -- Converts a mission number into an ASCII string. *
  376. * *
  377. * Use this routine to convert a mission number into the ASCII string that represents *
  378. * it. Typical use of this is when generating an INI file. *
  379. * *
  380. * INPUT: mission -- The mission number to convert. *
  381. * *
  382. * OUTPUT: Returns with a pointer to the ASCII string that represents the mission type. *
  383. * *
  384. * WARNINGS: none *
  385. * *
  386. * HISTORY: *
  387. * 01/23/1995 JLB : Created. *
  388. *=============================================================================================*/
  389. char const * MissionClass::Mission_Name(MissionType mission)
  390. {
  391. if (mission != MISSION_NONE) {
  392. return(Missions[mission]);
  393. }
  394. return("None");
  395. }
  396. /***********************************************************************************************
  397. * MissionClass::Override_Mission -- temporarily overrides the units mission *
  398. * *
  399. * *
  400. * *
  401. * INPUT: MissionType mission - the mission we want to override *
  402. * TARGET tarcom - the new target we want to override *
  403. * TARGET navcom - the new navigation point to override *
  404. * *
  405. * OUTPUT: none *
  406. * *
  407. * WARNINGS: If a mission is already overridden, the current mission is *
  408. * just re-assigned. *
  409. * *
  410. * HISTORY: *
  411. * 04/28/1995 PWG : Created. *
  412. *=============================================================================================*/
  413. void MissionClass::Override_Mission(MissionType mission, TARGET, TARGET)
  414. {
  415. assert(IsActive);
  416. if (MissionQueue != MISSION_NONE) {
  417. SuspendedMission = MissionQueue;
  418. } else {
  419. SuspendedMission = Mission;
  420. }
  421. Assign_Mission(mission);
  422. }
  423. /***********************************************************************************************
  424. * MissionClass::Restore_Mission -- Restores overridden mission *
  425. * *
  426. * INPUT: none *
  427. * *
  428. * OUTPUT: none *
  429. * *
  430. * WARNINGS: none *
  431. * *
  432. * HISTORY: *
  433. * 04/28/1995 PWG : Created. *
  434. *=============================================================================================*/
  435. bool MissionClass::Restore_Mission(void)
  436. {
  437. assert(IsActive);
  438. if (SuspendedMission != MISSION_NONE) {
  439. Assign_Mission(SuspendedMission);
  440. SuspendedMission= MISSION_NONE;
  441. return(true);
  442. }
  443. return(false);
  444. }
  445. /***********************************************************************************************
  446. * MissionClass::Is_Recruitable_Mission -- Determines if this mission is recruitable for a tea *
  447. * *
  448. * Some missions preclude recruitment into a team. This routine will examine the mission *
  449. * specified and if not allowed for a team, it will return false. *
  450. * *
  451. * INPUT: mission -- The mission type to examine. *
  452. * *
  453. * OUTPUT: bool; Is an object following this mission allowed to be recruited into a team? *
  454. * *
  455. * WARNINGS: none *
  456. * *
  457. * HISTORY: *
  458. * 09/14/1996 JLB : Created. *
  459. *=============================================================================================*/
  460. bool MissionClass::Is_Recruitable_Mission(MissionType mission) const
  461. {
  462. if (mission == MISSION_NONE) {
  463. return(true);
  464. }
  465. return(MissionControl[mission].IsRecruitable);
  466. }
  467. MissionControlClass::MissionControlClass(void) :
  468. Mission(MISSION_NONE),
  469. IsNoThreat(false),
  470. IsZombie(false),
  471. IsRecruitable(true),
  472. IsParalyzed(false),
  473. IsRetaliate(true),
  474. IsScatter(true),
  475. Rate(".016"),
  476. AARate(".016")
  477. {
  478. }
  479. char const * MissionControlClass::Name(void) const
  480. {
  481. if (Mission == MISSION_NONE) {
  482. return("<none>");
  483. }
  484. return(Missions[Mission]);
  485. }
  486. bool MissionControlClass::Read_INI(CCINIClass & ini)
  487. {
  488. if (ini.Is_Present(Name())) {
  489. IsNoThreat = ini.Get_Bool(Name(), "NoThreat", IsNoThreat);
  490. IsZombie = ini.Get_Bool(Name(), "Zombie", IsZombie);
  491. IsRecruitable = ini.Get_Bool(Name(), "Recruitable", IsRecruitable);
  492. IsParalyzed = ini.Get_Bool(Name(), "Paralyzed", IsParalyzed);
  493. IsRetaliate = ini.Get_Bool(Name(), "Retaliate", IsRetaliate);
  494. IsScatter = ini.Get_Bool(Name(), "Scatter", IsScatter);
  495. Rate = ini.Get_Fixed(Name(), "Rate", Rate);
  496. AARate = ini.Get_Fixed(Name(), "AARate", 0);
  497. if (AARate == 0) {
  498. AARate = Rate;
  499. }
  500. return(true);
  501. }
  502. return(false);
  503. }