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