]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - plugins/entity/entity.cpp
Merge commit '515673c08f8718a237e90c2130a1f5294f966d6a'
[xonotic/netradiant.git] / plugins / entity / entity.cpp
index 06f91737acd037fced016618afca303297542e68..36d7e919e2325a018d42749c234275a08ce1ddc7 100644 (file)
@@ -50,8 +50,7 @@ EGameType g_gameType;
 
 inline scene::Node& entity_for_eclass(EntityClass* eclass)
 {
-  if(classname_equal(eclass->name(), "misc_model")
-  || classname_equal(eclass->name(), "misc_gamemodel")
+  if((string_compare_nocase_n(eclass->name(), "misc_", 5) == 0 && string_equal_nocase(eclass->name() + string_length(eclass->name()) - 5, "model")) // misc_*model (also misc_model) // TODO make classname_* wrapper functions for this
   || classname_equal(eclass->name(), "model_static"))
   {
     return New_MiscModel(eclass);
@@ -132,12 +131,23 @@ class ConnectEntities
 public:
   Entity* m_e1;
   Entity* m_e2;
-  ConnectEntities(Entity* e1, Entity* e2) : m_e1(e1), m_e2(e2)
+  int m_index;
+  ConnectEntities(Entity* e1, Entity* e2, int index) : m_e1(e1), m_e2(e2), m_index(index)
   {
   }
+  const char *keyname()
+  {
+    StringOutputStream key(16);
+    if(m_index <= 0)
+      return "target";
+    if(m_index == 1)
+      return "killtarget";
+    key << "target" << m_index;
+    return key.c_str();
+  }
   void connect(const char* name)
   {
-         m_e1->setKeyValue("target", name);
+         m_e1->setKeyValue(keyname(), name);
          m_e2->setKeyValue("targetname", name);
   }
   typedef MemberCaller1<ConnectEntities, const char*, &ConnectEntities::connect> ConnectCaller;
@@ -168,7 +178,7 @@ public:
   {
     EntityKeyValues::setCounter(counter);
   }
-  void connectEntities(const scene::Path& path, const scene::Path& targetPath)
+  void connectEntities(const scene::Path& path, const scene::Path& targetPath, int index)
   {
     Entity* e1 = ScenePath_getEntity(path);
     Entity* e2 = ScenePath_getEntity(targetPath);
@@ -191,30 +201,39 @@ public:
     if(g_gameType == eGameTypeDoom3)
     {
       StringOutputStream key(16);
-      for(unsigned int i = 0; ; ++i)
+      if(index >= 0)
       {
-        key << "target";
-        if(i != 0)
-        {
-           key << i;
-        }
-        const char* value = e1->getKeyValue(key.c_str());
-        if(string_empty(value))
-        {
-          e1->setKeyValue(key.c_str(), e2->getKeyValue("name"));
-          break;
-        }
-        key.clear();
+         key << "target";
+         if(index != 0)
+         {
+           key << index;
+         }
+         e1->setKeyValue(key.c_str(), e2->getKeyValue("name"));
+         key.clear();
+      }
+      else
+      {
+       for(unsigned int i = 0; ; ++i)
+       {
+         key << "target";
+         if(i != 0)
+         {
+           key << i;
+         }
+         const char* value = e1->getKeyValue(key.c_str());
+         if(string_empty(value))
+         {
+           e1->setKeyValue(key.c_str(), e2->getKeyValue("name"));
+           break;
+         }
+         key.clear();
+       }
       }
     }
     else
     {
-      ConnectEntities connector(e1, e2);
+      ConnectEntities connector(e1, e2, index);
       const char* value = e2->getKeyValue("targetname");
-      if(string_empty(value))
-      {
-        value = e1->getKeyValue("target");
-      }
       if(!string_empty(value))
       {
         connector.connect(value);
@@ -258,6 +277,11 @@ public:
   {
     return g_showAngles;
   }
+
+  void printStatistics() const
+  {
+    StringPool_analyse(EntityKeyValues::getPool());
+  }
 };
 
 Quake3EntityCreator g_Quake3EntityCreator;
@@ -300,6 +324,7 @@ filter_entity_classname g_filter_entity_world("worldspawn");
 filter_entity_classname g_filter_entity_func_group("func_group");
 filter_entity_classname g_filter_entity_light("light");
 filter_entity_classname g_filter_entity_misc_model("misc_model");
+filter_entity_classname g_filter_entity_misc_gamemodel("misc_gamemodel");
 filter_entity_classgroup g_filter_entity_trigger("trigger_");
 filter_entity_classgroup g_filter_entity_path("path_");
 
@@ -321,8 +346,9 @@ void Entity_InitFilters()
        add_entity_filter(g_filter_entity_world, EXCLUDE_WORLD);
        add_entity_filter(g_filter_entity_func_group, EXCLUDE_WORLD);
        add_entity_filter(g_filter_entity_world, EXCLUDE_ENT, true);
-  add_entity_filter(g_filter_entity_trigger, EXCLUDE_TRIGGERS);
+    add_entity_filter(g_filter_entity_trigger, EXCLUDE_TRIGGERS);
        add_entity_filter(g_filter_entity_misc_model, EXCLUDE_MODELS);
+    add_entity_filter(g_filter_entity_misc_gamemodel, EXCLUDE_MODELS);
        add_entity_filter(g_filter_entity_doom3model, EXCLUDE_MODELS);
        add_entity_filter(g_filter_entity_light, EXCLUDE_LIGHTS);
        add_entity_filter(g_filter_entity_path, EXCLUDE_PATHS);