]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/rubble.qc
27dd7d40ea69b070dc313d7a0dd3178d5f064d91
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / rubble.qc
1 #include "rubble.qh"
2
3 #ifdef GAMEQC
4 void RubbleLimit(string cname, int limit, void(entity) deleteproc)
5 {
6         // remove rubble of the same type if it's at the limit
7         // remove multiple rubble if the limit has been decreased
8         while (1)
9         {
10                 // walk the list and count the entities, find the oldest
11                 // initialize our search with the first entity
12                 int c = 0;
13                 entity oldest = NULL;
14                 float oldesttime = 0;
15                 // compare to all other matching entities
16                 IL_EACH(g_rubble, it.classname == cname,
17                 {
18                         ++c;
19                         if(!oldest || oldesttime > it.creationtime)
20                         {
21                                 oldest = it;
22                                 oldesttime = it.creationtime;
23                         }
24                 });
25
26                 // stop if there are less than the limit already
27                 if (c <= limit) break;
28
29                 // delete this oldest one and search again
30                 deleteproc(oldest);
31         }
32 }
33
34 entity RubbleNew(entity e)
35 {
36         e.creationtime = time;
37         IL_PUSH(g_rubble, e);
38         return e;
39 }
40 #endif