MISSION.CPP 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /*
  2. ** Command & Conquer(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: F:\projects\c&c\vcs\code\mission.cpv 2.18 16 Oct 1995 16:49:12 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 : June 25, 1995 [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_From_Name -- Fetch order pointer from its name. *
  42. * MissionClass::Mission_Name -- Converts a mission number into an ASCII string. *
  43. * MissionClass::Overide_Mission -- temporarily overides the units mission *
  44. * MissionClass::Restore_Mission -- Restores overidden mission *
  45. * MissionClass::Set_Mission -- Sets the mission to the specified value. *
  46. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  47. #include "function.h"
  48. /***********************************************************************************************
  49. * MissionClass::MissionClass -- Default constructor for the mission object type. *
  50. * *
  51. * This is the default constructor for the mission class object. It sets the mission *
  52. * handler into a default -- do nothing -- state. *
  53. * *
  54. * INPUT: none *
  55. * *
  56. * OUTPUT: none *
  57. * *
  58. * WARNINGS: none *
  59. * *
  60. * HISTORY: *
  61. * 01/23/1995 JLB : Created. *
  62. *=============================================================================================*/
  63. MissionClass::MissionClass(void)
  64. {
  65. Status = 0;
  66. Timer = 0;
  67. Mission = MISSION_NONE;
  68. SuspendedMission = MISSION_NONE;
  69. MissionQueue = MISSION_NONE;
  70. }
  71. int MissionClass::Mission_Sleep(void) {return TICKS_PER_SECOND*30;};
  72. int MissionClass::Mission_Ambush(void) {return TICKS_PER_SECOND*30;};
  73. int MissionClass::Mission_Attack(void) {return TICKS_PER_SECOND*30;};
  74. int MissionClass::Mission_Capture(void) {return TICKS_PER_SECOND*30;};
  75. int MissionClass::Mission_Guard(void) {return TICKS_PER_SECOND*30;};
  76. int MissionClass::Mission_Guard_Area(void) {return TICKS_PER_SECOND*30;};
  77. int MissionClass::Mission_Harvest(void) {return TICKS_PER_SECOND*30;};
  78. int MissionClass::Mission_Hunt(void) {return TICKS_PER_SECOND*30;};
  79. int MissionClass::Mission_Timed_Hunt(void) {return TICKS_PER_SECOND*30;};
  80. int MissionClass::Mission_Move(void) {return TICKS_PER_SECOND*30;};
  81. int MissionClass::Mission_Retreat(void) {return TICKS_PER_SECOND*30;};
  82. int MissionClass::Mission_Return(void) {return TICKS_PER_SECOND*30;};
  83. int MissionClass::Mission_Stop(void) {return TICKS_PER_SECOND*30;};
  84. int MissionClass::Mission_Unload(void) {return TICKS_PER_SECOND*30;};
  85. int MissionClass::Mission_Enter(void) {return TICKS_PER_SECOND*30;};
  86. int MissionClass::Mission_Construction(void) {return TICKS_PER_SECOND*30;};
  87. int MissionClass::Mission_Deconstruction(void) {return TICKS_PER_SECOND*30;};
  88. int MissionClass::Mission_Repair(void) {return TICKS_PER_SECOND*30;};
  89. int MissionClass::Mission_Missile(void) {return TICKS_PER_SECOND*30;};
  90. /***********************************************************************************************
  91. * MissionClass::Set_Mission -- Sets the mission to the specified value. *
  92. * *
  93. * Use this routine to set the current mission for this object. This routine will blast *
  94. * over the current mission, bypassing the queue method. Call it when the mission needs *
  95. * to be changed immediately. *
  96. * *
  97. * INPUT: mission -- The mission to set to. *
  98. * *
  99. * OUTPUT: none *
  100. * *
  101. * WARNINGS: none *
  102. * *
  103. * HISTORY: *
  104. * 01/23/1995 JLB : Created. *
  105. *=============================================================================================*/
  106. void MissionClass::Set_Mission(MissionType mission)
  107. {
  108. Mission = mission;
  109. MissionQueue = MISSION_NONE;
  110. }
  111. /***********************************************************************************************
  112. * MissionClass::Get_Mission -- Fetches the mission that this object is acting under. *
  113. * *
  114. * Use this routine to fetch the mission that this object is CURRENTLY acting under. The *
  115. * mission queue may be filled with a immanent mission change, but this routine does not *
  116. * consider that. It only returns the CURRENT mission. *
  117. * *
  118. * INPUT: none *
  119. * *
  120. * OUTPUT: Returns with the mission that this unit is currently following. *
  121. * *
  122. * WARNINGS: none *
  123. * *
  124. * HISTORY: *
  125. * 01/23/1995 JLB : Created. *
  126. *=============================================================================================*/
  127. MissionType MissionClass::Get_Mission(void) const
  128. {
  129. return(Mission == MISSION_NONE ? MissionQueue : Mission);
  130. }
  131. #ifdef CHEAT_KEYS
  132. /***********************************************************************************************
  133. * MissionClass::Debug_Dump -- Dumps status values to mono screen. *
  134. * *
  135. * This is a debugging function that dumps this class' status to the monochrome screen *
  136. * for review. *
  137. * *
  138. * INPUT: none *
  139. * *
  140. * OUTPUT: none *
  141. * *
  142. * WARNINGS: none *
  143. * *
  144. * HISTORY: *
  145. * 05/28/1994 JLB : Created. *
  146. *=============================================================================================*/
  147. void MissionClass::Debug_Dump(MonoClass *mono) const
  148. {
  149. mono->Set_Cursor(21, 1);mono->Printf("%5.5s[%4.4s]", MissionClass::Mission_Name(Mission), MissionClass::Mission_Name(MissionQueue));
  150. // mono->Text_Print(MissionClass::Mission_Name(Mission), 21, 1);
  151. mono->Set_Cursor(20, 7);mono->Printf("%2d", (long)Timer);
  152. mono->Set_Cursor(74, 1);mono->Printf("%2d", Status);
  153. ObjectClass::Debug_Dump(mono);
  154. }
  155. #endif
  156. /***********************************************************************************************
  157. * MissionClass::AI -- Processes order script. *
  158. * *
  159. * This routine will process the order script for as much time as *
  160. * possible or until a script delay is detected. This routine should *
  161. * be called for every unit once per game loop (if possible). *
  162. * *
  163. * INPUT: none *
  164. * *
  165. * OUTPUT: none *
  166. * *
  167. * WARNINGS: none *
  168. * *
  169. * HISTORY: *
  170. * 04/23/1994 JLB : Created. *
  171. * 06/25/1995 JLB : Added new missions. *
  172. *=============================================================================================*/
  173. void MissionClass::AI(void)
  174. {
  175. ObjectClass::AI();
  176. /*
  177. ** This is the script AI equivalent processing.
  178. */
  179. if (Timer.Expired() && Strength > 0) {
  180. switch (Mission) {
  181. default:
  182. case MISSION_STICKY:
  183. case MISSION_SLEEP:
  184. Timer = Mission_Sleep();
  185. break;
  186. case MISSION_GUARD:
  187. Timer = Mission_Guard();
  188. break;
  189. case MISSION_ENTER:
  190. Timer = Mission_Enter();
  191. break;
  192. case MISSION_CONSTRUCTION:
  193. Timer = Mission_Construction();
  194. break;
  195. case MISSION_DECONSTRUCTION:
  196. Timer = Mission_Deconstruction();
  197. break;
  198. case MISSION_CAPTURE:
  199. case MISSION_SABOTAGE:
  200. Timer = Mission_Capture();
  201. break;
  202. case MISSION_MOVE:
  203. Timer = Mission_Move();
  204. break;
  205. case MISSION_ATTACK:
  206. Timer = Mission_Attack();
  207. break;
  208. case MISSION_RETREAT:
  209. Timer = Mission_Retreat();
  210. break;
  211. case MISSION_HARVEST:
  212. Timer = Mission_Harvest();
  213. break;
  214. case MISSION_GUARD_AREA:
  215. Timer = Mission_Guard_Area();
  216. break;
  217. case MISSION_RETURN:
  218. Timer = Mission_Return();
  219. break;
  220. case MISSION_STOP:
  221. Timer = Mission_Stop();
  222. break;
  223. case MISSION_AMBUSH:
  224. Timer = Mission_Ambush();
  225. break;
  226. case MISSION_HUNT:
  227. case MISSION_RESCUE:
  228. Timer = Mission_Hunt();
  229. break;
  230. case MISSION_TIMED_HUNT:
  231. Timer = Mission_Timed_Hunt();
  232. break;
  233. case MISSION_UNLOAD:
  234. Timer = Mission_Unload();
  235. break;
  236. case MISSION_REPAIR:
  237. Timer = Mission_Repair();
  238. break;
  239. case MISSION_MISSILE:
  240. Timer = Mission_Missile();
  241. break;
  242. }
  243. }
  244. }
  245. /***********************************************************************************************
  246. * MissionClass::Commence -- Start script with new order. *
  247. * *
  248. * This routine will start script processing according to any queued *
  249. * order it may have. If there is no queued order, then this routine *
  250. * does nothing. Call this routine whenever the unit is in a good *
  251. * position to change its order (such as when it is stopped). *
  252. * *
  253. * INPUT: none *
  254. * *
  255. * OUTPUT: Did the mission actually change? *
  256. * *
  257. * WARNINGS: none *
  258. * *
  259. * HISTORY: *
  260. * 04/23/1994 JLB : Created. *
  261. * 07/14/1994 JLB : Simplified. *
  262. * 06/17/1995 JLB : Returns success flag. *
  263. *=============================================================================================*/
  264. bool MissionClass::Commence(void)
  265. {
  266. if (MissionQueue != MISSION_NONE) {
  267. Mission = MissionQueue;
  268. MissionQueue = MISSION_NONE;
  269. /*
  270. ** Force immediate state machine processing at the first state machine state value.
  271. */
  272. Timer = 0;
  273. Status = 0;
  274. return(true);
  275. }
  276. return(false);
  277. }
  278. /***********************************************************************************************
  279. * MissionClass::Assign_Mission -- Give an order to a unit. *
  280. * *
  281. * This assigns an order to a unit. It does NOT do the AI, but merely *
  282. * flags the unit for normal AI processing. At that time the computer *
  283. * will determine the unit's course of action. *
  284. * *
  285. * INPUT: order -- Mission to give the unit. *
  286. * *
  287. * OUTPUT: none *
  288. * *
  289. * WARNINGS: none *
  290. * *
  291. * HISTORY: *
  292. * 06/04/1991 JLB : Created. *
  293. * 04/15/1994 JLB : Converted to member function. *
  294. *=============================================================================================*/
  295. void MissionClass::Assign_Mission(MissionType order)
  296. {
  297. if (order == MISSION_NONE || Mission == order) return;
  298. // Status = 0;
  299. MissionQueue = order;
  300. }
  301. /***********************************************************************************************
  302. * MissionClass::Mission_From_Name -- Fetch order pointer from its name. *
  303. * *
  304. * This routine is used to convert an ASCII order name into the actual *
  305. * order number it represents. Typically, this is used when processing *
  306. * a scenario INI file. *
  307. * *
  308. * INPUT: name -- The ASCII order name to process. *
  309. * *
  310. * OUTPUT: Returns with the actual order number that the ASCII name *
  311. * represents. *
  312. * *
  313. * WARNINGS: none *
  314. * *
  315. * HISTORY: *
  316. * 10/07/1992 JLB : Created. *
  317. * 04/22/1994 JLB : Converted to static member function. *
  318. *=============================================================================================*/
  319. MissionType MissionClass::Mission_From_Name(char const *name)
  320. {
  321. MissionType order;
  322. if (name) {
  323. for (order = MISSION_FIRST; order < MISSION_COUNT; order++) {
  324. if (stricmp(Missions[order], name) == 0) {
  325. return(order);
  326. }
  327. }
  328. }
  329. return(MISSION_NONE);
  330. }
  331. /***********************************************************************************************
  332. * MissionClass::Mission_Name -- Converts a mission number into an ASCII string. *
  333. * *
  334. * Use this routine to convert a mission number into the ASCII string that represents *
  335. * it. Typical use of this is when generating an INI file. *
  336. * *
  337. * INPUT: mission -- The mission number to convert. *
  338. * *
  339. * OUTPUT: Returns with a pointer to the ASCII string that represents the mission type. *
  340. * *
  341. * WARNINGS: none *
  342. * *
  343. * HISTORY: *
  344. * 01/23/1995 JLB : Created. *
  345. *=============================================================================================*/
  346. char const * MissionClass::Mission_Name(MissionType mission)
  347. {
  348. return(mission == MISSION_NONE ? "None" : Missions[mission]);
  349. }
  350. /***********************************************************************************************
  351. * MissionClass::Override_Mission -- temporarily overides the units mission *
  352. * *
  353. * *
  354. * *
  355. * INPUT: MissionType mission - the mission we want to overide *
  356. * TARGET tarcom - the new target we want to overide *
  357. * TARGET navcom - the new navigation point to overide *
  358. * *
  359. * OUTPUT: none *
  360. * *
  361. * WARNINGS: If a mission is already overidden, the current mission is *
  362. * just re-assigned. *
  363. * *
  364. * HISTORY: *
  365. * 04/28/1995 PWG : Created. *
  366. *=============================================================================================*/
  367. void MissionClass::Override_Mission(MissionType mission, TARGET, TARGET)
  368. {
  369. if (MissionQueue != MISSION_NONE) {
  370. SuspendedMission = MissionQueue;
  371. } else {
  372. SuspendedMission = Mission;
  373. }
  374. Assign_Mission(mission);
  375. }
  376. /***********************************************************************************************
  377. * MissionClass::Restore_Mission -- Restores overidden mission *
  378. * *
  379. * INPUT: none *
  380. * *
  381. * OUTPUT: none *
  382. * *
  383. * WARNINGS: none *
  384. * *
  385. * HISTORY: *
  386. * 04/28/1995 PWG : Created. *
  387. *=============================================================================================*/
  388. bool MissionClass::Restore_Mission(void)
  389. {
  390. if (SuspendedMission != MISSION_NONE) {
  391. Assign_Mission(SuspendedMission);
  392. SuspendedMission= MISSION_NONE;
  393. return(true);
  394. }
  395. return(false);
  396. }
  397. /***********************************************************************************************
  398. ** Unit order names. These names correspond to the player selectable orders
  399. ** a unit can have. The system initiated orders have no use for the ASCII name
  400. ** associated, but they are listed here for completeness sake.
  401. */
  402. char const * MissionClass::Missions[MISSION_COUNT] = {
  403. "Sleep",
  404. "Attack",
  405. "Move",
  406. "Retreat",
  407. "Guard",
  408. "Sticky",
  409. "Enter",
  410. "Capture",
  411. "Harvest",
  412. "Area Guard",
  413. "Return",
  414. "Stop",
  415. "Ambush",
  416. "Hunt",
  417. "Timed Hunt",
  418. "Unload",
  419. "Sabotage",
  420. "Construction",
  421. "Selling",
  422. "Repair",
  423. "Rescue",
  424. "Missile",
  425. };