CARGO.CPP 11 KB

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