UTRACKER.CPP 15 KB

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