@@ -208,7 +208,14 @@ void CWeaponSystem::Reload()
208
208
209
209
m_tracerManager.Reset ();
210
210
211
- this ->RegisterXMLData ();
211
+ if (!gEnv ->bClient ) {
212
+ CryLogAlways (" [CryMP] Reloading XML weapon definitions" );
213
+ for (TFolderList::iterator it = m_folders.begin (); it != m_folders.end (); ++it)
214
+ Scan (it->c_str ());
215
+ } else {
216
+ CryLogAlways (" [CryMP] Reloading pre-compiled weapon definitions" );
217
+ this ->RegisterXMLData ();
218
+ }
212
219
213
220
m_reloading = false ;
214
221
}
@@ -456,6 +463,133 @@ int CWeaponSystem::QueryProjectiles(SProjectileQuery& q)
456
463
return q.nCount ;
457
464
}
458
465
466
+ // ------------------------------------------------------------------------
467
+ void CWeaponSystem::Scan (const char * folderName)
468
+ {
469
+ string folder = folderName;
470
+ string search = folder;
471
+ search += " /*.*" ;
472
+
473
+ if (!m_recursing)
474
+ CryLog (" Loading ammo XML definitions from '%s'!" , folderName);
475
+
476
+ for (auto & entry : CryFind (search.c_str ()))
477
+ {
478
+ if (entry.IsDirectory ())
479
+ {
480
+ string subName = folder + " /" + entry.name ;
481
+ if (m_recursing)
482
+ {
483
+ Scan (subName.c_str ());
484
+ }
485
+ else
486
+ {
487
+ m_recursing=true ;
488
+ Scan (subName.c_str ());
489
+ m_recursing=false ;
490
+ }
491
+ continue ;
492
+ }
493
+
494
+ if (_stricmp (CryPath::GetExt (entry.name ), " xml" ))
495
+ {
496
+ continue ;
497
+ }
498
+
499
+ string xmlFile = folder + string (" /" ) + string (entry.name );
500
+ XmlNodeRef rootNode = m_pSystem->LoadXmlFile (xmlFile.c_str ());
501
+
502
+ if (!rootNode)
503
+ {
504
+ CryLogWarning (" Invalid XML file '%s'! Skipping..." , xmlFile.c_str ());
505
+ continue ;
506
+ }
507
+
508
+ ScanXML (rootNode, xmlFile.c_str ());
509
+ }
510
+
511
+ if (!m_recursing)
512
+ CryLog (" Finished loading ammo XML definitions from '%s'!" , folderName);
513
+
514
+ if (!m_reloading && !m_recursing)
515
+ m_folders.push_back (folderName);
516
+ }
517
+
518
+ // ------------------------------------------------------------------------
519
+ bool CWeaponSystem::ScanXML (XmlNodeRef& root, const char * xmlFile)
520
+ {
521
+ if (strcmpi (root->getTag (), " ammo" ))
522
+ return false ;
523
+
524
+ const char * name = root->getAttr (" name" );
525
+ if (!name)
526
+ {
527
+ CryLogWarningAlways (" Missing ammo name in XML '%s'! Skipping..." , xmlFile);
528
+ return false ;
529
+ }
530
+
531
+ const char * className = root->getAttr (" class" );
532
+
533
+ if (!className)
534
+ {
535
+ CryLogWarningAlways (" Missing ammo class in XML '%s'! Skipping..." , xmlFile);
536
+ return false ;
537
+ }
538
+
539
+ TProjectileRegistry::iterator it = m_projectileregistry.find (CONST_TEMP_STRING (className));
540
+ if (it == m_projectileregistry.end ())
541
+ {
542
+ CryLogWarningAlways (" Unknown ammo class '%s' specified in XML '%s'! Skipping..." , className, xmlFile);
543
+ return false ;
544
+ }
545
+
546
+ const char * scriptName = root->getAttr (" script" );
547
+ IEntityClassRegistry::SEntityClassDesc classDesc;
548
+ classDesc.sName = name;
549
+ classDesc.sScriptFile = scriptName ? scriptName : " " ;
550
+ // classDesc.pUserProxyData = (void *)it->second;
551
+ // classDesc.pUserProxyCreateFunc = &CreateProxy<CProjectile>;
552
+ classDesc.flags |= ECLF_INVISIBLE;
553
+
554
+ IEntityClass* pClass = gEnv ->pEntitySystem ->GetClassRegistry ()->FindClass (name);
555
+
556
+ if (!m_reloading && !pClass)
557
+ {
558
+ m_pGame->GetIGameFramework ()->GetIGameObjectSystem ()->RegisterExtension (name, it->second , &classDesc);
559
+ pClass = gEnv ->pEntitySystem ->GetClassRegistry ()->FindClass (name);
560
+ assert (pClass);
561
+ }
562
+
563
+
564
+ TAmmoTypeParams::iterator ait = m_ammoparams.find (pClass);
565
+ if (ait == m_ammoparams.end ())
566
+ {
567
+ std::pair<TAmmoTypeParams::iterator, bool > result = m_ammoparams.insert (TAmmoTypeParams::value_type (pClass, SAmmoTypeDesc ()));
568
+ ait = result.first ;
569
+ }
570
+
571
+ const char * configName = root->getAttr (" configuration" );
572
+
573
+ IItemParamsNode* params = m_pItemSystem->CreateParams ();
574
+ params->ConvertFromXML (root);
575
+
576
+ SAmmoParams* pAmmoParams = new SAmmoParams (params, pClass);
577
+
578
+ SAmmoTypeDesc& desc = ait->second ;
579
+
580
+ if (!configName || !configName[0 ])
581
+ {
582
+ if (desc.params )
583
+ delete desc.params ;
584
+ desc.params = pAmmoParams;
585
+ }
586
+ else
587
+ desc.configurations .insert (std::make_pair<string, const SAmmoParams*>(configName, static_cast <const SAmmoParams*>(pAmmoParams)));
588
+
589
+ return true ;
590
+ }
591
+
592
+
459
593
// ------------------------------------------------------------------------
460
594
void CWeaponSystem::RegisterAmmo (const char * name, const char * className, const char * script, const char * config, IItemParamsNode* params)
461
595
{
0 commit comments