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