]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/effects/qc/rubble.qc
Fixed electro secondary limit being global
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / rubble.qc
index 27dd7d40ea69b070dc313d7a0dd3178d5f064d91..f0a29bd5ba5edf38cb8874aab28a5109cb116f25 100644 (file)
@@ -1,8 +1,8 @@
 #include "rubble.qh"
 
 #ifdef GAMEQC
-void RubbleLimit(string cname, int limit, void(entity) deleteproc)
-{
+
+void LimitedChildrenRubble(IntrusiveList list, string cname, int limit, void(entity) deleteproc, entity parent){
        // remove rubble of the same type if it's at the limit
        // remove multiple rubble if the limit has been decreased
        while (1)
@@ -13,13 +13,15 @@ void RubbleLimit(string cname, int limit, void(entity) deleteproc)
                entity oldest = NULL;
                float oldesttime = 0;
                // compare to all other matching entities
-               IL_EACH(g_rubble, it.classname == cname,
+               IL_EACH(list, it.classname == cname,
                {
-                       ++c;
-                       if(!oldest || oldesttime > it.creationtime)
-                       {
-                               oldest = it;
-                               oldesttime = it.creationtime;
+                       if(!parent ||parent == it.owner){
+                               ++c;
+                               if(!oldest || oldesttime > it.creationtime)
+                               {
+                                       oldest = it;
+                                       oldesttime = it.creationtime;
+                               }
                        }
                });
 
@@ -31,10 +33,20 @@ void RubbleLimit(string cname, int limit, void(entity) deleteproc)
        }
 }
 
-entity RubbleNew(entity e)
-{
-       e.creationtime = time;
-       IL_PUSH(g_rubble, e);
-       return e;
+
+// This function doesn't preserve linked list order but it is not needed as creationtime is used instead of list position for comparing ages.
+// IL_Replace or similiar order preserving function did not exist at the time of creating this.
+entity ReplaceOldListedChildRubble(IntrusiveList list, entity child, entity oldChild){
+       child.creationtime = oldChild.creationtime;
+       IL_REMOVE(list, oldChild);
+       IL_PUSH(list, child);
+       return child;
 }
+
+entity ListNewChildRubble(IntrusiveList list, entity child){
+       child.creationtime = time;
+       IL_PUSH(list, child);
+       return child;
+}
+
 #endif