| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: ArmorTemplate.cpp ///////////////////////////////////////////////////////////////////////////////
- // Author: Steven Johnson, November 2001
- // Desc: ArmorTemplate descriptions
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #define DEFINE_DAMAGE_NAMES // for DamageNames[]
- #include "Common/INI.h"
- #include "Common/ThingFactory.h"
- #include "GameLogic/Armor.h"
- #include "GameLogic/Damage.h"
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // PUBLIC DATA ////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- ArmorStore* TheArmorStore = NULL; ///< the ArmorTemplate store definition
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //-------------------------------------------------------------------------------------------------
- ArmorTemplate::ArmorTemplate()
- {
- clear();
- }
- //-------------------------------------------------------------------------------------------------
- void ArmorTemplate::clear()
- {
- for (int i = 0; i < DAMAGE_NUM_TYPES; i++)
- {
- m_damageCoefficient[i] = 1.0f;
- }
- }
- //-------------------------------------------------------------------------------------------------
- Real ArmorTemplate::adjustDamage(DamageType t, Real damage) const
- {
- if (t == DAMAGE_UNRESISTABLE)
- return damage;
- damage *= m_damageCoefficient[t];
- if (damage < 0.0f)
- damage = 0.0f;
-
- return damage;
- }
- //-------------------------------------------------------------------------------------------Static
- /*static*/ void ArmorTemplate::parseArmorCoefficients( INI* ini, void *instance, void* /* store */, const void* userData )
- {
- ArmorTemplate* self = (ArmorTemplate*) instance;
- const char* damageName = ini->getNextToken();
- Real pct = INI::scanPercentToReal(ini->getNextToken());
- if (stricmp(damageName, "Default") == 0)
- {
- for (Int i = 0; i < DAMAGE_NUM_TYPES; i++)
- {
- self->m_damageCoefficient[i] = pct;
- }
- return;
- }
- DamageType dt = (DamageType)INI::scanIndexList(damageName, TheDamageNames);
- self->m_damageCoefficient[dt] = pct;
- }
- //-------------------------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------------------------
- ArmorStore::ArmorStore()
- {
- m_armorTemplates.clear();
- }
- //-------------------------------------------------------------------------------------------------
- ArmorStore::~ArmorStore()
- {
- m_armorTemplates.clear();
- }
- //-------------------------------------------------------------------------------------------------
- const ArmorTemplate* ArmorStore::findArmorTemplate(AsciiString name) const
- {
- NameKeyType namekey = TheNameKeyGenerator->nameToKey(name);
- ArmorTemplateMap::const_iterator it = m_armorTemplates.find(namekey);
- if (it == m_armorTemplates.end())
- {
- return NULL;
- }
- else
- {
- return &(*it).second;
- }
- }
- //-------------------------------------------------------------------------------------------------
- /*static */ void ArmorStore::parseArmorDefinition(INI *ini)
- {
- static const FieldParse myFieldParse[] =
- {
- { "Armor", ArmorTemplate::parseArmorCoefficients, NULL, 0 }
- };
- const char *c = ini->getNextToken();
- NameKeyType key = TheNameKeyGenerator->nameToKey(c);
- ArmorTemplate& armorTmpl = TheArmorStore->m_armorTemplates[key];
- armorTmpl.clear();
- ini->initFromINI(&armorTmpl, myFieldParse);
- }
- //-------------------------------------------------------------------------------------------------
- /*static*/ void INI::parseArmorDefinition(INI *ini)
- {
- ArmorStore::parseArmorDefinition(ini);
- }
|