CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

WARHEAD.CPP (12287B)


      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/WARHEAD.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 : WARHEAD.CPP                                                  *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 05/20/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : July 19, 1996 [JLB]                                          *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   WarheadTypeClass::As_Pointer -- Convert a warhead type number into a pointer.             *
     34  *   WarheadTypeClass::Read_INI -- Fetches the warhead data from the INI database.             *
     35  *   WarheadTypeClass::WarheadTypeClass -- Default constructor for warhead objects.            *
     36  *   WarheadTypeClass::operator delete -- Returns warhead object back to special memory pool.  *
     37  *   WarheadTypeClass::operator new -- Allocate a warhead object from the special heap.        *
     38  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     39 
     40 
     41 #include	"function.h"
     42 
     43 
     44 /***************************************************************************
     45 **	This is the warhead data object array.
     46 */
     47 TFixedIHeapClass<WarheadTypeClass> Warheads;
     48 
     49 
     50 /***********************************************************************************************
     51  * WarheadTypeClass::WarheadTypeClass -- Default constructor for warhead objects.              *
     52  *                                                                                             *
     53  *    This default constructor for a warhead object will fill in all the default values        *
     54  *    for a warhead. It is presumed that these values will be normal unless specifically       *
     55  *    overridden by the INI database.                                                          *
     56  *                                                                                             *
     57  * INPUT:   none                                                                               *
     58  *                                                                                             *
     59  * OUTPUT:  none                                                                               *
     60  *                                                                                             *
     61  * WARNINGS:   none                                                                            *
     62  *                                                                                             *
     63  * HISTORY:                                                                                    *
     64  *   07/19/1996 JLB : Created.                                                                 *
     65  *=============================================================================================*/
     66 WarheadTypeClass::WarheadTypeClass(char const * name) :
     67 	ID(Warheads.ID(this)),
     68 	IniName(name),
     69 	SpreadFactor(1),
     70 	IsWallDestroyer(false),
     71 	IsWoodDestroyer(false),
     72 	IsTiberiumDestroyer(false),
     73 	IsOrganic(false),
     74 	ExplosionSet(0),
     75 	InfantryDeath(0)
     76 {
     77 	for (ArmorType armor = ARMOR_FIRST; armor < ARMOR_COUNT; armor++) {
     78 		Modifier[armor] = 1;
     79 	}
     80 }
     81 
     82 
     83 /***********************************************************************************************
     84  * WarheadTypeClass::operator new -- Allocate a warhead object from the special heap.          *
     85  *                                                                                             *
     86  *    This will allocate a warhead object from the special heap that is maintained for         *
     87  *    this purpose.                                                                            *
     88  *                                                                                             *
     89  * INPUT:   none                                                                               *
     90  *                                                                                             *
     91  * OUTPUT:  Returns with a pointer to the newly allocated warhead type object. If there is     *
     92  *          insufficient memory for the allocation, then NULL is returned.                     *
     93  *                                                                                             *
     94  * WARNINGS:   none                                                                            *
     95  *                                                                                             *
     96  * HISTORY:                                                                                    *
     97  *   07/19/1996 JLB : Created.                                                                 *
     98  *=============================================================================================*/
     99 void * WarheadTypeClass::operator new(size_t)
    100 {
    101 	return(Warheads.Alloc());
    102 }
    103 
    104 
    105 /***********************************************************************************************
    106  * WarheadTypeClass::operator delete -- Returns warhead object back to special memory pool.    *
    107  *                                                                                             *
    108  *    This routine will return the warhead object to the memory pool from whence it came.      *
    109  *                                                                                             *
    110  * INPUT:   pointer  -- Pointer to the warhead object to return to the memory pool.            *
    111  *                                                                                             *
    112  * OUTPUT:  none                                                                               *
    113  *                                                                                             *
    114  * WARNINGS:   none                                                                            *
    115  *                                                                                             *
    116  * HISTORY:                                                                                    *
    117  *   07/19/1996 JLB : Created.                                                                 *
    118  *=============================================================================================*/
    119 void WarheadTypeClass::operator delete(void * pointer)
    120 {
    121 	Warheads.Free((WarheadTypeClass *)pointer);
    122 }
    123 
    124 
    125 /***********************************************************************************************
    126  * WarheadTypeClass::As_Pointer -- Convert a warhead type number into a pointer.               *
    127  *                                                                                             *
    128  *    This will locate the warhead type specified and return a pointer to it.                  *
    129  *                                                                                             *
    130  * INPUT:   warhead  -- The warhead to convert into a pointer.                                 *
    131  *                                                                                             *
    132  * OUTPUT:  Returns with a pointer to the warhead type object that is represented by the       *
    133  *          warhead type number specified.                                                     *
    134  *                                                                                             *
    135  * WARNINGS:   none                                                                            *
    136  *                                                                                             *
    137  * HISTORY:                                                                                    *
    138  *   07/19/1996 JLB : Created.                                                                 *
    139  *=============================================================================================*/
    140 WarheadTypeClass * WarheadTypeClass::As_Pointer(WarheadType warhead)
    141 {
    142 	if (warhead != WARHEAD_NONE) {
    143 		return(Warheads.Ptr(warhead));
    144 	}
    145 	return(NULL);
    146 }
    147 
    148 
    149 /***********************************************************************************************
    150  * WarheadTypeClass::Read_INI -- Fetches the warhead data from the INI database.               *
    151  *                                                                                             *
    152  *    Use this routine to retrieve the data specific to this warhead type class object from    *
    153  *    the INI database specified. Typical use of this is when processing the rules.ini         *
    154  *    file.                                                                                    *
    155  *                                                                                             *
    156  * INPUT:   ini   -- Reference to the INI database to fetch the values from.                   *
    157  *                                                                                             *
    158  * OUTPUT:  bool; Was the warhead entry found and the data retrieved?                          *
    159  *                                                                                             *
    160  * WARNINGS:   none                                                                            *
    161  *                                                                                             *
    162  * HISTORY:                                                                                    *
    163  *   07/19/1996 JLB : Created.                                                                 *
    164  *=============================================================================================*/
    165 bool WarheadTypeClass::Read_INI(CCINIClass & ini)
    166 {
    167 	if (ini.Is_Present(Name())) {
    168 		SpreadFactor = ini.Get_Int(Name(), "Spread", SpreadFactor);
    169 		IsWallDestroyer = ini.Get_Bool(Name(), "Wall", IsWallDestroyer);
    170 		IsWoodDestroyer = ini.Get_Bool(Name(), "Wood", IsWoodDestroyer);
    171 		IsTiberiumDestroyer = ini.Get_Bool(Name(), "Ore", IsTiberiumDestroyer);
    172 		ExplosionSet = ini.Get_Int(Name(), "Explosion", ExplosionSet);
    173 		InfantryDeath = ini.Get_Int(Name(), "InfDeath", InfantryDeath);
    174 
    175 		char buffer[128];
    176 		if (ini.Get_String(Name(), "Verses", "100%%,100%%,100%%,100%%,100%%", buffer, sizeof(buffer))) {
    177 			char * aval = strtok(buffer, ",");
    178 			for (ArmorType armor = ARMOR_FIRST; armor < ARMOR_COUNT; armor++) {
    179 				Modifier[armor] = fixed(aval);
    180 				aval = strtok(NULL, ",");
    181 			}
    182 		}
    183 
    184 		IsOrganic = (Modifier[ARMOR_STEEL] == 0);
    185 		return(true);
    186 	}
    187 	return(false);
    188 }
    189