]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/rubble.qh
Fix use of self in .draw
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / rubble.qh
1 #ifndef RUBBLE_H
2 #define RUBBLE_H
3
4 #ifdef CSQC
5
6 entityclass(Rubble);
7 class(Rubble).float creationtime;
8
9 void RubbleLimit(string cname, float limit, void(entity) deleteproc)
10 {
11         SELFPARAM();
12         entity e;
13         entity oldest;
14         float c;
15         float oldesttime;
16
17         // remove rubble of the same type if it's at the limit
18         // remove multiple rubble if the limit has been decreased
19         while (1)
20         {
21                 e = findchain(classname, cname);
22                 if (e == world) break;
23                 // walk the list and count the entities, find the oldest
24                 // initialize our search with the first entity
25                 c = 1;
26                 oldest = e;
27                 oldesttime = e.creationtime;
28                 e = e.chain;
29                 // compare to all other matching entities
30                 while (e)
31                 {
32                         c = c + 1;
33                         if (oldesttime > e.creationtime)
34                         {
35                                 oldesttime = e.creationtime;
36                                 oldest = e;
37                         }
38                         e = e.chain;
39                 }
40
41                 // stop if there are less than the limit already
42                 if (c <= limit) break;
43
44                 // delete this oldest one and search again
45                 deleteproc(oldest);
46         }
47 }
48
49 entity RubbleNew(string cname)
50 {
51         // spawn a new entity and return it
52         entity e = spawn();
53         e.classname = cname;
54         e.creationtime = time;
55         return e;
56 }
57
58 #endif
59
60 #endif