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