UTRACKER.CPP 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. /***************************************************************************
  15. ** 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 **
  16. ***************************************************************************
  17. * *
  18. * Project Name : Command & Conquer *
  19. * *
  20. * File Name : UTRACKER.CPP *
  21. * *
  22. * Programmer : Steve Tall *
  23. * *
  24. * Start Date : June 3rd, 1996 *
  25. * *
  26. * Last Update : June 7th, 1996 [ST] *
  27. * *
  28. *-------------------------------------------------------------------------*
  29. * The UnitTracker class exists to track the various statistics *
  30. * required for internet games. *
  31. * *
  32. * *
  33. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  34. * *
  35. * Functions: *
  36. * *
  37. * *
  38. * *
  39. * *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "function.h"
  42. /*
  43. ** Define host to network to host functions for DOS
  44. */
  45. #ifndef WIN32
  46. #define htonl(val) 0
  47. #define ntohl(val) 0
  48. #endif //WIN32
  49. /***********************************************************************************************
  50. * UTC::UnitTrackerClass -- Class constructor *
  51. * *
  52. * *
  53. * *
  54. * INPUT: Number of unit types to reserve space for *
  55. * *
  56. * OUTPUT: Nothing *
  57. * *
  58. * WARNINGS: None *
  59. * *
  60. * HISTORY: *
  61. * 6/7/96 0:10AM ST : Created *
  62. *=============================================================================================*/
  63. UnitTrackerClass::UnitTrackerClass (int unit_count)
  64. {
  65. UnitTotals = new long [unit_count]; // Allocate memory for the unit totals
  66. UnitCount = unit_count; // Keep a record of how many unit entries there are
  67. InNetworkFormat = 0; // The unit entries are in host format
  68. Clear_Unit_Total(); // Clear each entry
  69. }
  70. /***********************************************************************************************
  71. * UTC::~UnitTrackerClass -- Class destructor *
  72. * *
  73. * *
  74. * *
  75. * INPUT: Nothing *
  76. * *
  77. * OUTPUT: Nothing *
  78. * *
  79. * WARNINGS: None *
  80. * *
  81. * HISTORY: *
  82. * 6/7/96 0:10AM ST : Created *
  83. *=============================================================================================*/
  84. UnitTrackerClass::~UnitTrackerClass (void)
  85. {
  86. delete UnitTotals;
  87. }
  88. /***********************************************************************************************
  89. * UTC::Increment_Unit_Total -- Increment the total for the specefied unit *
  90. * *
  91. * *
  92. * *
  93. * INPUT: Unit number *
  94. * *
  95. * OUTPUT: Nothing *
  96. * *
  97. * WARNINGS: None *
  98. * *
  99. * HISTORY: *
  100. * 6/7/96 0:12AM ST : Created *
  101. *=============================================================================================*/
  102. void UnitTrackerClass::Increment_Unit_Total(int unit_type)
  103. {
  104. UnitTotals[unit_type]++;
  105. }
  106. /***********************************************************************************************
  107. * UTC::Decrement_Unit_Total -- Decrement the total for the specefied unit *
  108. * *
  109. * *
  110. * *
  111. * INPUT: Unit number *
  112. * *
  113. * OUTPUT: Nothing *
  114. * *
  115. * WARNINGS: None *
  116. * *
  117. * HISTORY: *
  118. * 6/7/96 0:13AM ST : Created *
  119. *=============================================================================================*/
  120. void UnitTrackerClass::Decrement_Unit_Total(int unit_type)
  121. {
  122. UnitTotals[unit_type]--;
  123. }
  124. /***********************************************************************************************
  125. * UTC::Get_All_Totals -- Returns a pointer to the start of the unit totals list *
  126. * *
  127. * *
  128. * *
  129. * INPUT: Nothing *
  130. * *
  131. * OUTPUT: Ptr to unit totals list *
  132. * *
  133. * WARNINGS: None *
  134. * *
  135. * HISTORY: *
  136. * 6/7/96 0:13AM ST : Created *
  137. *=============================================================================================*/
  138. long *UnitTrackerClass::Get_All_Totals (void)
  139. {
  140. return (UnitTotals);
  141. }
  142. /***********************************************************************************************
  143. * UTC::Clear_Unit_Total -- Clear out all the unit totals *
  144. * *
  145. * *
  146. * *
  147. * INPUT: Nothing *
  148. * *
  149. * OUTPUT: Nothing *
  150. * *
  151. * WARNINGS: None *
  152. * *
  153. * HISTORY: *
  154. * 6/7/96 0:14AM ST : Created *
  155. *=============================================================================================*/
  156. void UnitTrackerClass::Clear_Unit_Total (void)
  157. {
  158. memset (UnitTotals, 0, UnitCount * sizeof(long) );
  159. }
  160. /***********************************************************************************************
  161. * UTC::To_Network_Format -- Changes all unit totals to network format for the internet *
  162. * *
  163. * *
  164. * *
  165. * INPUT: Nothing *
  166. * *
  167. * OUTPUT: Nothing *
  168. * *
  169. * WARNINGS: None *
  170. * *
  171. * HISTORY: *
  172. * 6/7/96 0:15AM ST : Created *
  173. *=============================================================================================*/
  174. void UnitTrackerClass::To_Network_Format (void)
  175. {
  176. if (!InNetworkFormat){
  177. for (int i=0 ; i<UnitCount ; i++){
  178. UnitTotals[i] = htonl (UnitTotals[i]);
  179. }
  180. }
  181. InNetworkFormat = 1; // Flag that data is now in network format
  182. }
  183. /***********************************************************************************************
  184. * UTC::To_PC_Format -- Changes all unit totals to PC format from network format *
  185. * *
  186. * *
  187. * *
  188. * INPUT: Nothing *
  189. * *
  190. * OUTPUT: Nothing *
  191. * *
  192. * WARNINGS: None *
  193. * *
  194. * HISTORY: *
  195. * 6/7/96 0:15AM ST : Created *
  196. *=============================================================================================*/
  197. void UnitTrackerClass::To_PC_Format (void)
  198. {
  199. if (InNetworkFormat){
  200. for (int i=0 ; i<UnitCount ; i++){
  201. UnitTotals[i] = ntohl (UnitTotals[i]);
  202. }
  203. }
  204. InNetworkFormat = 0; // Flag that data is now in PC format
  205. }
  206. // MBL 01.17.2020: Defined in .h, but not implemented
  207. int UnitTrackerClass::Get_Unit_Total (int unit_type)
  208. {
  209. if (UnitTotals == NULL)
  210. {
  211. return 0;
  212. }
  213. if (unit_type >= 0 && unit_type < UnitCount)
  214. {
  215. return UnitTotals[unit_type];
  216. }
  217. return 0;
  218. }