/* ** Command & Conquer Generals Zero Hour(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 . */ //////////////////////////////////////////////////////////////////////////////// // // // (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 #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; if (t == DAMAGE_SUBDUAL_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)DamageTypeFlags::getSingleBitFromName(damageName); 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); }