CARGO.CPP 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/CARGO.CPP 1 3/03/97 10:24a 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 : CARGO.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 23, 1994 *
  30. * *
  31. * Last Update : 10/31/94 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * CargoClass::Attach -- Add unit to cargo hold. *
  36. * CargoClass::Attached_Object -- Determine attached unit pointer. *
  37. * CargoClass::Debug_Dump -- Displays the cargo value to the monochrome screen. *
  38. * CargoClass::Detach_Object -- Removes a unit from the cargo hold. *
  39. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  40. #include "function.h"
  41. #ifdef CHEAT_KEYS
  42. /***********************************************************************************************
  43. * CargoClass::Debug_Dump -- Displays the cargo value to the monochrome screen. *
  44. * *
  45. * This routine is used to dump the current cargo value to the monochrome monitor. *
  46. * *
  47. * INPUT: none *
  48. * *
  49. * OUTPUT: none *
  50. * *
  51. * WARNINGS: none *
  52. * *
  53. * HISTORY: *
  54. * 06/02/1994 JLB : Created. *
  55. *=============================================================================================*/
  56. void CargoClass::Debug_Dump(MonoClass * mono) const
  57. {
  58. if (How_Many()) {
  59. mono->Set_Cursor(63, 3);
  60. mono->Printf("(%d)%04X", How_Many(), Attached_Object());
  61. }
  62. }
  63. #endif
  64. /***********************************************************************************************
  65. * CargoClass::Attach -- Add unit to cargo hold. *
  66. * *
  67. * This routine will add the specified unit to the cargo hold. The *
  68. * unit will chain to any existing units in the hold. The chaining is *
  69. * in a LIFO order. *
  70. * *
  71. * INPUT: object-- Pointer to the object to attach to the cargo hold. *
  72. * *
  73. * OUTPUT: none *
  74. * *
  75. * WARNINGS: none *
  76. * *
  77. * HISTORY: *
  78. * 04/23/1994 JLB : Created. *
  79. * 10/31/94 JLB : Handles chained objects. *
  80. *=============================================================================================*/
  81. void CargoClass::Attach(FootClass * object)
  82. {
  83. /*
  84. ** If there is no object, then no action is necessary.
  85. */
  86. if (object == NULL) return;
  87. object->Limbo();
  88. /*
  89. ** Attach any existing cargo hold object to the end of the list as indicated by the
  90. ** object pointer passed into this routine. This is necessary because several objects may
  91. ** be attached at one time or several objects may be attached as a result of several calls
  92. ** to this routine. Either case must be handled properly.
  93. */
  94. ObjectClass * o = object->Next;
  95. while (o != NULL) {
  96. if (o->Next == (void*)NULL) break;
  97. o = o->Next;
  98. }
  99. if (o != NULL) {
  100. o->Next = CargoHold;
  101. } else {
  102. object->Next = CargoHold;
  103. }
  104. /*
  105. ** Finally, assign the object pointer as the first object attached to this cargo hold.
  106. */
  107. CargoHold = object;
  108. Quantity = 0;
  109. object = CargoHold;
  110. while (object != NULL) {
  111. Quantity++;
  112. object = (FootClass *)(ObjectClass *)object->Next;
  113. }
  114. }
  115. /***********************************************************************************************
  116. * CargoClass::Detach_Object -- Removes a unit from the cargo hold. *
  117. * *
  118. * This routine will take a unit from the cargo hold and extract it. *
  119. * The unit extracted is the last unit added to the hold. If there *
  120. * is no unit in the hold or the occupant is not a unit, then NULL is *
  121. * returned. *
  122. * *
  123. * INPUT: none *
  124. * *
  125. * OUTPUT: Returns with a pointer to the unit that has been extracted. *
  126. * *
  127. * WARNINGS: none *
  128. * *
  129. * HISTORY: *
  130. * 04/23/1994 JLB : Created. *
  131. * 06/07/1994 JLB : Handles generic object types. *
  132. *=============================================================================================*/
  133. FootClass * CargoClass::Detach_Object(void)
  134. {
  135. TechnoClass * unit = Attached_Object();
  136. if (unit != NULL) {
  137. CargoHold = (FootClass *)(ObjectClass *)unit->Next;
  138. unit->Next = 0;
  139. Quantity--;
  140. }
  141. return((FootClass *)unit);
  142. }
  143. /***********************************************************************************************
  144. * CargoClass::Attached_Object -- Determine attached unit pointer. *
  145. * *
  146. * This routine will return with a pointer to the attached unit if one *
  147. * is present. One would need to know this if this is a transport *
  148. * unit and it needs to unload. *
  149. * *
  150. * INPUT: none *
  151. * *
  152. * OUTPUT: Returns a pointer to the attached unit. If there is no *
  153. * attached unit, then return NULL. *
  154. * *
  155. * WARNINGS: none *
  156. * *
  157. * HISTORY: *
  158. * 09/07/1992 JLB : Created. *
  159. * 06/07/1994 JLB : Handles generic object types. *
  160. *=============================================================================================*/
  161. FootClass * CargoClass::Attached_Object(void) const
  162. {
  163. if (Is_Something_Attached()) {
  164. return(CargoHold);
  165. }
  166. return(NULL);
  167. }