@@ -365,6 +365,20 @@ void WeaponTemplate::reset( void )
365365 m_historicDamage.clear ();
366366}
367367
368+ void WeaponTemplate::copy_from (const WeaponTemplate& other) {
369+ // Backup nextTemplate, name and namekey
370+ WeaponTemplate* nextTempl = this ->m_nextTemplate ;
371+ AsciiString name = this ->m_name ;
372+ NameKeyType nameKey = this ->m_nameKey ;
373+
374+ // take all values from other
375+ *this = other;
376+
377+ this ->m_nextTemplate = nextTempl;
378+ this ->m_name = name;
379+ this ->m_nameKey = nameKey;
380+ }
381+
368382// -------------------------------------------------------------------------------------------------
369383/* static*/ void WeaponTemplate::parseWeaponBonusSet ( INI * ini, void *instance, void * /* store*/ , const void * /* userData*/ )
370384{
@@ -1936,6 +1950,69 @@ void WeaponStore::postProcessLoad()
19361950
19371951}
19381952
1953+
1954+ // -------------------------------------------------------------------------------------------------
1955+ /* static*/ void WeaponStore::parseWeaponExtendTemplateDefinition (INI * ini)
1956+ {
1957+ AsciiString name;
1958+ AsciiString parent;
1959+
1960+ // read the weapon name
1961+ const char * c = ini->getNextToken ();
1962+ name.set (c);
1963+
1964+ // read the parent name
1965+ const char * c2 = ini->getNextToken ();
1966+ parent.set (c2);
1967+
1968+ // find parent if present
1969+ WeaponTemplate* parentWeapon = TheWeaponStore->findWeaponTemplatePrivate (TheNameKeyGenerator->nameToKey (parent));
1970+ if (parentWeapon)
1971+ {
1972+
1973+ // find existing item if present
1974+ WeaponTemplate* weapon = TheWeaponStore->findWeaponTemplatePrivate (TheNameKeyGenerator->nameToKey (name));
1975+ if (weapon)
1976+ {
1977+ if (ini->getLoadType () == INI_LOAD_CREATE_OVERRIDES )
1978+ weapon = TheWeaponStore->newOverride (weapon);
1979+ else
1980+ {
1981+ DEBUG_CRASH ((" Weapon '%s' already exists, but OVERRIDE not specified" , c));
1982+ return ;
1983+ }
1984+
1985+ }
1986+ else
1987+ {
1988+ // no item is present, create a new one
1989+ weapon = TheWeaponStore->newWeaponTemplate (name);
1990+ }
1991+
1992+ // copy from parent
1993+ weapon->copy_from (*parentWeapon);
1994+
1995+ // parse the ini weapon definition
1996+ ini->initFromINI (weapon, weapon->getFieldParse ());
1997+
1998+ if (weapon->m_projectileName .isNone ())
1999+ weapon->m_projectileName .clear ();
2000+
2001+ #if defined(RTS_DEBUG)
2002+ if (!weapon->getFireSound ().getEventName ().isEmpty () && weapon->getFireSound ().getEventName ().compareNoCase (" NoSound" ) != 0 )
2003+ {
2004+ DEBUG_ASSERTCRASH (TheAudio->isValidAudioEvent (&weapon->getFireSound ()), (" Invalid FireSound %s in Weapon '%s'." , weapon->getFireSound ().getEventName ().str (), weapon->getName ().str ()));
2005+ }
2006+ #endif
2007+
2008+ }
2009+ else
2010+ {
2011+ DEBUG_CRASH ((" Weapon '%s' cannot extend parrent '%s' as it not exists" , c, c2));
2012+ }
2013+
2014+ }
2015+
19392016// -------------------------------------------------------------------------------------------------
19402017// -------------------------------------------------------------------------------------------------
19412018// -------------------------------------------------------------------------------------------------
0 commit comments