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