]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_decors.c
Updating
[divverent/nexuiz.git] / qcsrc / gamec / g_decors.c
1
2 float maxclients; // set by worldspawn code
3 float numdecors;
4 float maxdecors;
5 .float createdtime;
6 .void() th_gib;
7
8 //void(vector org, entity en, vector dir, float splattype, float importance) newbloodsplat;
9 //void(vector org, float bodydamage, float armordamage, vector vel, float damgtype) genericbleedfunc;
10
11 // removes the oldest decors each frame to maintain a certain maximum decors
12 void() decorframe =
13 {
14         local entity estart, e, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10;
15         local float bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt10, iterations;
16
17         // numdecors is allowed to be bogus as long as it is >= the real number of decors
18         // (but perfection is clearly preferable)
19         if (numdecors <= maxdecors)
20                 return;
21
22         // recount all the decors
23         numdecors = 0;
24         estart = e = findchain(classname, "decor");
25         while(e)
26         {
27                 numdecors = numdecors + 1;
28                 e = e.chain;
29         }
30         if (numdecors <= maxdecors)
31                 return; // nothing to do
32
33         // limit it to considering 10000 entities per frame,
34         // otherwise it can cause a runaway loop error
35         iterations = 0;
36         while (numdecors > maxdecors && iterations < 10000)
37         {
38                 iterations = iterations + 1;
39                 // find and remove the oldest decors (upto 10 at once)
40                 b1 = b2  = b3  = b4  = b5  = b6 = b7 = b8 = b9 = b10 = world;
41                 bt1 = bt2 = bt3 = bt4 = bt5 = bt6 = bt7 = bt8 = bt9 = bt10 = time + 10000;
42                 if (iterations > 0)
43                         estart = findchain(classname, "decor");
44                 e = estart;
45                 while(e)
46                 {
47                         iterations = iterations + 1;
48                         if (e.createdtime < bt10)
49                         {
50                                 if (e.createdtime < bt9)
51                                 {
52                                         if (e.createdtime < bt8)
53                                         {
54                                                 if (e.createdtime < bt7)
55                                                 {
56                                                         if (e.createdtime < bt6)
57                                                         {
58                                                                 if (e.createdtime < bt5)
59                                                                 {
60                                                                         if (e.createdtime < bt4)
61                                                                         {
62                                                                                 if (e.createdtime < bt3)
63                                                                                 {
64                                                                                         if (e.createdtime < bt2)
65                                                                                         {
66                                                                                                 if (e.createdtime < bt1)
67                                                                                                 {
68                                                                                                         b10=b9;bt10=bt9;
69                                                                                                         b9=b8;bt9=bt8;
70                                                                                                         b8=b7;bt8=bt7;
71                                                                                                         b7=b6;bt7=bt6;
72                                                                                                         b6=b5;bt6=bt5;
73                                                                                                         b5=b4;bt5=bt4;
74                                                                                                         b4=b3;bt4=bt3;
75                                                                                                         b3=b2;bt3=bt2;
76                                                                                                         b2=b1;bt2=bt1;
77                                                                                                         b1=e;bt1=e.createdtime;
78                                                                                                 }
79                                                                                                 else
80                                                                                                 {
81                                                                                                         b10=b9;bt10=bt9;
82                                                                                                         b9=b8;bt9=bt8;
83                                                                                                         b8=b7;bt8=bt7;
84                                                                                                         b7=b6;bt7=bt6;
85                                                                                                         b6=b5;bt6=bt5;
86                                                                                                         b5=b4;bt5=bt4;
87                                                                                                         b4=b3;bt4=bt3;
88                                                                                                         b3=b2;bt3=bt2;
89                                                                                                         b2=e;bt2=e.createdtime;
90                                                                                                 }
91                                                                                         }
92                                                                                         else
93                                                                                         {
94                                                                                                 b10=b9;bt10=bt9;
95                                                                                                 b9=b8;bt9=bt8;
96                                                                                                 b8=b7;bt8=bt7;
97                                                                                                 b7=b6;bt7=bt6;
98                                                                                                 b6=b5;bt6=bt5;
99                                                                                                 b5=b4;bt5=bt4;
100                                                                                                 b4=b3;bt4=bt3;
101                                                                                                 b3=e;bt3=e.createdtime;
102                                                                                         }
103                                                                                 }
104                                                                                 else
105                                                                                 {
106                                                                                         b10=b9;bt10=bt9;
107                                                                                         b9=b8;bt9=bt8;
108                                                                                         b8=b7;bt8=bt7;
109                                                                                         b7=b6;bt7=bt6;
110                                                                                         b6=b5;bt6=bt5;
111                                                                                         b5=b4;bt5=bt4;
112                                                                                         b4=e;bt4=e.createdtime;
113                                                                                 }
114                                                                         }
115                                                                         else
116                                                                         {
117                                                                                 b10=b9;bt10=bt9;
118                                                                                 b9=b8;bt9=bt8;
119                                                                                 b8=b7;bt8=bt7;
120                                                                                 b7=b6;bt7=bt6;
121                                                                                 b6=b5;bt6=bt5;
122                                                                                 b5=e;bt5=e.createdtime;
123                                                                         }
124                                                                 }
125                                                                 else
126                                                                 {
127                                                                         b10=b9;bt10=bt9;
128                                                                         b9=b8;bt9=bt8;
129                                                                         b8=b7;bt8=bt7;
130                                                                         b7=b6;bt7=bt6;
131                                                                         b6=e;bt6=e.createdtime;
132                                                                 }
133                                                         }
134                                                         else
135                                                         {
136                                                                 b10=b9;bt10=bt9;
137                                                                 b9=b8;bt9=bt8;
138                                                                 b8=b7;bt8=bt7;
139                                                                 b7=e;bt7=e.createdtime;
140                                                         }
141                                                 }
142                                                 else
143                                                 {
144                                                         b10=b9;bt10=bt9;
145                                                         b9=b8;bt9=bt8;
146                                                         b8=e;bt8=e.createdtime;
147                                                 }
148                                         }
149                                         else
150                                         {
151                                                 b10=b9;bt10=bt9;
152                                                 b9=e;bt9=e.createdtime;
153                                         }
154                                 }
155                                 else
156                                 {
157                                         b10=e;bt10=e.createdtime;
158                                 }
159                         }
160                         // failed all 10 slots
161                         e = e.chain;
162                 }
163                 // remove the oldest decors
164                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b1);}
165                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b2);}
166                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b3);}
167                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b4);}
168                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b5);}
169                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b6);}
170                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b7);}
171                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b8);}
172                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b9);}
173                 if (numdecors > maxdecors) {numdecors = numdecors - 1;remove(b10);}
174         }
175 };
176
177 entity() newdecor =
178 {
179         local entity e;
180         numdecors++;
181         e = spawn();
182         e.classname = "decor";
183         return e;
184 };
185
186 void(entity e) removedecor =
187 {
188         numdecors--;
189         remove(e);
190 };
191
192
193 void(vector org, vector vel, float amount) blood =
194 {
195         te_blood(org, vel, amount);
196 };
197
198 void(vector org, vector vel, float amount) spark =
199 {
200         te_spark(org, vel, amount);
201 };
202
203 void(vector m1, vector m2, float vel, float amount) bloodshower =
204 {
205         te_bloodshower(m1, m2, vel, amount);
206 };
207
208 void(vector org, float quad) bulletpuff =
209 {
210         if (quad)
211                 te_gunshotquad(org);
212         else
213                 te_gunshot(org);
214 };
215
216 void(vector org, float quad) nailpuff =
217 {
218         if (quad)
219                 te_superspikequad(org);
220         else
221                 te_superspike(org);
222 };
223
224 // used for various little bouncing debris to avoid getting stuck in the air
225 void() DecorThink =
226 {
227         self.nextthink = time;
228         self.flags = self.flags - (self.flags & FL_ONGROUND);
229         if (pointcontents(self.origin) == CONTENT_SOLID)
230                 removedecor(self);
231 };
232
233 .float  createdtime;
234
235 void() InitDecors =
236 {
237         // different number of decors in multi-player (to avoid lag on modems)
238         if (maxclients > 1)
239                 maxdecors = 32;
240         else
241                 maxdecors = 100;
242         // overridable by saved2 cvar on server console
243         if (cvar("decors"))
244                 maxdecors = cvar("decors");
245         if (maxdecors < 1)
246                 maxdecors = 1;
247 };