WEAPON.CPP (20474B)
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 /* $Header: /CounterStrike/WEAPON.CPP 1 3/03/97 10:26a Joe_bostic $ */ 17 /*********************************************************************************************** 18 *** 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 *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : WEAPON.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 05/20/96 * 28 * * 29 * Last Update : September 9, 1996 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * Armor_From_Name -- Convert ASCII name into armor type number. * 34 * WeaponTypeClass::As_Pointer -- Give a weapon type ID, fetch pointer to weapon type object.* 35 * WeaponTypeClass::Read_INI -- Fetch the weapon data from the INI database. * 36 * WeaponTypeClass::WeaponTypeClass -- Default constructor for weapon type objects. * 37 * WeaponTypeClass::operator delete -- Returns weapon type object back to special heap. * 38 * WeaponTypeClass::operator new -- Allocates a weapon type object form the special heap. * 39 * WeaponTypeClass::~WeaponTypeClass -- Destructor for weapon type class objects. * 40 * Weapon_From_Name -- Conver ASCII name to weapon type ID number. * 41 * WeaponTypeClass::Allowed_Threats -- Determine what threats this weapon can address. * 42 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 43 44 #include "function.h" 45 46 47 /*************************************************************************** 48 ** These are the various weapons and their characteristics. 49 */ 50 TFixedIHeapClass<WeaponTypeClass> Weapons; 51 52 53 /*********************************************************************************************** 54 * WeaponTypeClass::WeaponTypeClass -- Default constructor for weapon type objects. * 55 * * 56 * This default constructor will initialize all the values of the weapon to the default * 57 * state. Thus, if any of these settings are not specifically overridden by the rules.ini * 58 * file, they will remain this value in the game. * 59 * * 60 * INPUT: none * 61 * * 62 * OUTPUT: none * 63 * * 64 * WARNINGS: none * 65 * * 66 * HISTORY: * 67 * 07/17/1996 JLB : Created. * 68 *=============================================================================================*/ 69 WeaponTypeClass::WeaponTypeClass(char const * name) : 70 ID(Weapons.ID(this)), 71 IniName(name), 72 IsSupressed(false), 73 IsCamera(false), 74 IsElectric(false), 75 Burst(1), 76 Bullet(NULL), 77 Attack(0), 78 MaxSpeed(MPH_IMMOBILE), 79 WarheadPtr(NULL), 80 ROF(0), 81 Range(0), 82 Sound(VOC_NONE), 83 Anim(ANIM_NONE) 84 { 85 } 86 87 88 /*********************************************************************************************** 89 * WeaponTypeClass::~WeaponTypeClass -- Destructor for weapon type class objects. * 90 * * 91 * This destructor really doesn't do anything but set the pointers to NULL. This is a * 92 * general purposes safety tactic but is otherwise useless. * 93 * * 94 * INPUT: none * 95 * * 96 * OUTPUT: none * 97 * * 98 * WARNINGS: none * 99 * * 100 * HISTORY: * 101 * 07/17/1996 JLB : Created. * 102 *=============================================================================================*/ 103 WeaponTypeClass::~WeaponTypeClass(void) 104 { 105 IniName = NULL; 106 Bullet = NULL; 107 WarheadPtr = NULL; 108 } 109 110 111 /*********************************************************************************************** 112 * WeaponTypeClass::operator new -- Allocates a weapon type object form the special heap. * 113 * * 114 * This will allocate a weapon type object from a special heap that has been set up for * 115 * that purpose. * 116 * * 117 * INPUT: none * 118 * * 119 * OUTPUT: Returns with a pointer to the weapon type object allocated. If there was * 120 * insufficient memory available, NULL is returned. * 121 * * 122 * WARNINGS: none * 123 * * 124 * HISTORY: * 125 * 07/17/1996 JLB : Created. * 126 *=============================================================================================*/ 127 void * WeaponTypeClass::operator new(size_t) 128 { 129 return(Weapons.Alloc()); 130 } 131 132 133 /*********************************************************************************************** 134 * WeaponTypeClass::operator delete -- Returns weapon type object back to special heap. * 135 * * 136 * This routine will return the weapon type object back to the heap so that the memory * 137 * can be reused for subsiquent allocations of weapon type objects. * 138 * * 139 * INPUT: pointer -- Pointer to the weapon type object to return to the special heap. * 140 * * 141 * OUTPUT: none * 142 * * 143 * WARNINGS: none * 144 * * 145 * HISTORY: * 146 * 07/17/1996 JLB : Created. * 147 *=============================================================================================*/ 148 void WeaponTypeClass::operator delete(void * pointer) 149 { 150 Weapons.Free((WeaponTypeClass *)pointer); 151 } 152 153 154 /*********************************************************************************************** 155 * WeaponTypeClass::As_Pointer -- Give a weapon type ID, fetch pointer to weapon type object. * 156 * * 157 * This routine will conver the weapon type ID specified into a pointer to the weapon type * 158 * object it represents. * 159 * * 160 * INPUT: weapon -- The weapon type object ID to convert to a pointer. * 161 * * 162 * OUTPUT: Returns with a pointer to the weapon type class object that is represented by the * 163 * weapon ID number specified. If no match could be found, then NULL is returned. * 164 * * 165 * WARNINGS: none * 166 * * 167 * HISTORY: * 168 * 07/17/1996 JLB : Created. * 169 *=============================================================================================*/ 170 WeaponTypeClass * WeaponTypeClass::As_Pointer(WeaponType weapon) 171 { 172 if (weapon != WEAPON_NONE) { 173 return(Weapons.Ptr(weapon)); 174 // for (int index = 0; index < Weapons.Count(); index++) { 175 // WeaponTypeClass * ptr = Weapons.Ptr(index); 176 // if (ptr->ID == weapon) { 177 // return(ptr); 178 // } 179 // } 180 } 181 return(NULL); 182 } 183 184 185 /*********************************************************************************************** 186 * WeaponTypeClass::Read_INI -- Fetch the weapon data from the INI database. * 187 * * 188 * This routine will fetch the weapon data for this weapon type object from the INI * 189 * database specified. * 190 * * 191 * INPUT: ini -- Reference to the INI database that the weapon data will be fetched * 192 * from. * 193 * * 194 * OUTPUT: bool; Was this weapon type described in the database and the values retrieved? * 195 * * 196 * WARNINGS: none * 197 * * 198 * HISTORY: * 199 * 07/19/1996 JLB : Created. * 200 *=============================================================================================*/ 201 bool WeaponTypeClass::Read_INI(CCINIClass & ini) 202 { 203 if (ini.Is_Present(Name())) { 204 IsSupressed = ini.Get_Bool(Name(), "Supress", IsSupressed); 205 Burst = ini.Get_Int(Name(), "Burst", Burst); 206 Attack = ini.Get_Int(Name(), "Damage", Attack); 207 MaxSpeed = ini.Get_MPHType(Name(), "Speed", MaxSpeed); 208 ROF = ini.Get_Int(Name(), "ROF", ROF); 209 Range = ini.Get_Lepton(Name(), "Range", Range); 210 Sound = ini.Get_VocType(Name(), "Report", Sound); 211 Anim = ini.Get_AnimType(Name(), "Anim", Anim); 212 IsCamera = ini.Get_Bool(Name(), "Camera", IsCamera); 213 IsElectric = ini.Get_Bool(Name(), "Charges", IsElectric); 214 IsTurboBoosted = ini.Get_Bool(Name(), "TurboBoost", IsTurboBoosted); 215 216 WarheadType wtype = (WarheadPtr != NULL) ? WarheadType(WarheadPtr->ID) : WARHEAD_NONE; 217 wtype = ini.Get_WarheadType(Name(), "Warhead", wtype); 218 if (wtype != WARHEAD_NONE) { 219 WarheadPtr = WarheadTypeClass::As_Pointer(wtype); 220 // WarheadPtr = &Warheads[wtype]; 221 } else { 222 WarheadPtr = NULL; 223 } 224 225 BulletType btype = (Bullet != NULL) ? BulletType(Bullet->ID) : BULLET_NONE; 226 btype = ini.Get_BulletType(Name(), "Projectile", btype); 227 if (btype != BULLET_NONE) { 228 Bullet = &BulletTypeClass::As_Reference(btype); 229 } else { 230 Bullet = NULL; 231 } 232 233 return(true); 234 } 235 return(false); 236 } 237 238 239 /*********************************************************************************************** 240 * Weapon_From_Name -- Conver ASCII name to weapon type ID number. * 241 * * 242 * This will find the weapon whos name matches that specified and then it will return the * 243 * weapon ID number associated with it. * 244 * * 245 * INPUT: name -- Pointer to the ASCII name of the weapon type. * 246 * * 247 * OUTPUT: Returns with the weapon type ID number that matches the name specified. If no * 248 * match could be found, then WEAPON_NONE is returned. * 249 * * 250 * WARNINGS: none * 251 * * 252 * HISTORY: * 253 * 07/17/1996 JLB : Created. * 254 *=============================================================================================*/ 255 WeaponType Weapon_From_Name(char const * name) 256 { 257 if (!name) return(WEAPON_NONE); 258 259 for (int index = 0; index < Weapons.Count(); index++) { 260 if (stricmp(Weapons.Ptr(index)->Name(), name) == 0) { 261 return(WeaponType(Weapons.Ptr(index)->ID)); 262 } 263 } 264 265 return(WEAPON_NONE); 266 } 267 268 269 /*********************************************************************************************** 270 * Armor_From_Name -- Convert ASCII name into armor type number. * 271 * * 272 * This will find the armor type that matches the ASCII name specified and then will return * 273 * the armor ID number of it. * 274 * * 275 * INPUT: name -- Pointer to the ASCII name of the armor to find. * 276 * * 277 * OUTPUT: Returns with the armor ID number of the armor that matches the name specified. If * 278 * no match could be found, then ARMOR_NONE is returned. * 279 * * 280 * WARNINGS: none * 281 * * 282 * HISTORY: * 283 * 07/17/1996 JLB : Created. * 284 *=============================================================================================*/ 285 ArmorType Armor_From_Name(char const * name) 286 { 287 if (!name) return(ARMOR_NONE); 288 289 for (ArmorType index = ARMOR_FIRST; index < ARMOR_COUNT; index++) { 290 if (stricmp(ArmorName[index], name) == 0) { 291 return(index); 292 } 293 } 294 295 return(ARMOR_NONE); 296 } 297 298 299 /*********************************************************************************************** 300 * WeaponTypeClass::Allowed_Threats -- Determine what threats this weapon can address. * 301 * * 302 * This routine will examine the capabilities of this weapon and return with the threat * 303 * types that it can address. * 304 * * 305 * INPUT: none * 306 * * 307 * OUTPUT: Returns with the threat types that this weapon can address. * 308 * * 309 * WARNINGS: none * 310 * * 311 * HISTORY: * 312 * 09/09/1996 JLB : Created. * 313 *=============================================================================================*/ 314 ThreatType WeaponTypeClass::Allowed_Threats(void) const 315 { 316 ThreatType threat = THREAT_NORMAL; 317 if (Bullet->IsAntiAircraft) { 318 threat = threat | THREAT_AIR; 319 } 320 if (Bullet->IsAntiGround) { 321 threat = threat | THREAT_INFANTRY|THREAT_VEHICLES|THREAT_BOATS|THREAT_BUILDINGS; 322 } 323 return(threat); 324 } 325 326 327 bool WeaponTypeClass::Is_Wall_Destroyer(void) const 328 { 329 if (WarheadPtr != NULL && WarheadPtr->IsWallDestroyer) { 330 return(true); 331 } 332 return(false); 333 }