]> icculus.org git repositories - divverent/nexuiz.git/blob - TeamNexuiz/game/gamec/w_common.c
bumps for morphed's teleporter model
[divverent/nexuiz.git] / TeamNexuiz / game / gamec / w_common.c
1 \r
2 // increments sprite frame, loops when end is hit.. simple\r
3 \r
4 float TE_SMOKE =77;\r
5 void (vector vec) WriteVec =\r
6 {\r
7                 WriteCoord (MSG_BROADCAST, vec_x);\r
8                 WriteCoord (MSG_BROADCAST, vec_y);\r
9                 WriteCoord (MSG_BROADCAST, vec_z);\r
10 }\r
11 void (vector org, vector dir, float counts) W_Smoke =\r
12 {\r
13                 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);\r
14                 WriteByte (MSG_BROADCAST, TE_SMOKE);\r
15                 WriteVec (org);\r
16                 WriteVec (dir);\r
17                 WriteByte (MSG_BROADCAST, counts);\r
18 }\r
19 \r
20 // increments sprite frame, loops when end is hit.. simple\r
21 void animate_sprite (float startframe, float frame_count)\r
22 {\r
23         if ((self.frame - startframe) >= (frame_count - 1 ))\r
24                 self.frame = startframe;\r
25         else\r
26                 self.frame = self.frame + 1;\r
27 }\r
28 \r
29 void W_UpdateAmmo (void)\r
30 {\r
31         /*\r
32         self.items = self.items - (self.items & (IT_NAILS | IT_SHELLS | IT_ROCKETS | IT_CELLS));\r
33 \r
34         if (self.weapon == IT_LASER)\r
35                 self.currentammo = 1;\r
36         else if (self.weapon == IT_SHOTGUN)\r
37         {\r
38                 self.currentammo = self.ammo_shells;\r
39                 self.items = self.items | IT_SHELLS;\r
40         }\r
41         else if (self.weapon == IT_UZI)\r
42         {\r
43                 self.currentammo = self.ammo_nails;\r
44                 self.items = self.items | IT_NAILS;\r
45         }\r
46         else if (self.weapon == IT_GRENADE_LAUNCHER || self.weapon == IT_HAGAR || self.weapon == IT_ROCKET_LAUNCHER)\r
47         {\r
48                 self.currentammo = self.ammo_rockets;\r
49                 self.items = self.items | IT_ROCKETS;\r
50         }\r
51         else if (self.weapon == IT_ELECTRO || self.weapon == IT_NEX || self.weapon == IT_CRYLINK)\r
52         {\r
53                 self.currentammo = self.ammo_cells;\r
54                 self.items = self.items | IT_CELLS;\r
55         }\r
56         */\r
57 }\r
58 \r
59 void W_UpdateWeapon (void)\r
60 {\r
61         /*\r
62         if (self.weapon == IT_LASER)\r
63                 self.weaponmodel = "models/weapons/w_laser.zym";\r
64         else if (self.weapon == IT_SHOTGUN)\r
65                 self.weaponmodel = "models/weapons/w_shotgun.zym";\r
66         else if (self.weapon == IT_UZI)\r
67                 self.weaponmodel = "models/weapons/w_uzi.zym";\r
68         else if (self.weapon == IT_GRENADE_LAUNCHER)\r
69                 self.weaponmodel = "models/weapons/w_gl.zym";\r
70         else if (self.weapon == IT_ELECTRO)\r
71                 self.weaponmodel = "models/weapons/w_electro.zym";\r
72         else if (self.weapon == IT_CRYLINK)\r
73                 self.weaponmodel = "models/weapons/w_crylink.zym";\r
74         else if (self.weapon == IT_NEX)\r
75                 self.weaponmodel = "models/weapons/w_nex.zym";\r
76         else if (self.weapon == IT_HAGAR)\r
77                 self.weaponmodel = "models/weapons/w_hagar.zym";\r
78         else if (self.weapon == IT_ROCKET_LAUNCHER)\r
79                 self.weaponmodel = "models/weapons/w_rl.zym";\r
80         else\r
81                 objerror ("Illegal weapon - please register your guns please!");\r
82         */\r
83 }\r
84 \r
85 float W_GetBestWeapon (entity e)\r
86 {\r
87         /*\r
88         if ((e.items & IT_ROCKET_LAUNCHER) && e.ammo_rockets)\r
89                 return IT_ROCKET_LAUNCHER;\r
90         else if ((e.items & IT_NEX) && e.ammo_cells)\r
91                 return IT_NEX;\r
92         else if ((e.items & IT_HAGAR) && e.ammo_rockets)\r
93                 return IT_HAGAR;\r
94         else if ((e.items & IT_GRENADE_LAUNCHER) && e.ammo_rockets)\r
95                 return IT_GRENADE_LAUNCHER;\r
96         else if ((e.items & IT_ELECTRO) && e.ammo_cells)\r
97                 return IT_ELECTRO;\r
98         else if ((e.items & IT_CRYLINK) && e.ammo_cells)\r
99                 return IT_CRYLINK;\r
100         else if ((e.items & IT_UZI) && e.ammo_nails)\r
101                 return IT_UZI;\r
102         else if ((e.items & IT_SHOTGUN) && e.ammo_shells)\r
103                 return IT_SHOTGUN;\r
104         else\r
105 \r
106                 */\r
107         return IT_LASER;\r
108 }\r
109 \r
110 void ResetExtraWeapon()\r
111 {\r
112         if(self.wpn5 == world)\r
113         {\r
114                 self.wpn5 = spawn();\r
115         }\r
116 \r
117         self.wpn5.weapon = 0;\r
118         self.wpn5.mass = 0;\r
119         self.items = self.items - (self.items & IT_WEP5);\r
120 }\r
121 \r
122 void W_GiveWeapon (entity e, float wep, string name, float wmass)\r
123 {\r
124         entity oldself;\r
125 \r
126         if (!wep)\r
127                 return;\r
128 \r
129         //e.items = e.items | wep;\r
130 \r
131         oldself = self;\r
132         self = e;\r
133 \r
134         self.wpn5.weapon = wep;\r
135         self.wpn5.mass = wmass;\r
136 \r
137         self.items = self.items | IT_WEP5;\r
138 \r
139         weapon_action(self.weapon, WR_UPDATECOUNTS);\r
140         if(self.weapon == WEP5)                                 // if using carrying # 5 already\r
141         {\r
142                 //bprint("reset wep5\n");\r
143                 self.wpn = self.wpn5.weapon;\r
144                 self.switchweapon = WEP5;\r
145                 weapon_action(self.weapon, WR_DROP);\r
146                 self.weapon = 0;\r
147                 //weapon_action(self.wpn, WR_SETUP);    // update the weapon we're holding\r
148                 //weapon_action(self.wpn, WR_RAISE);    // update the weapon we're holding\r
149         }\r
150 \r
151         if (other.classname == "player")\r
152         {\r
153                 sprint (other, "You got the ^2");\r
154                 sprint (other, name);\r
155                 sprint (other, "\n");\r
156         }\r
157 \r
158 \r
159 /*\r
160         W_UpdateWeapon ();\r
161         W_UpdateAmmo ();\r
162 */\r
163         self = oldself;\r
164 }\r
165 \r
166 /*\r
167 void W_SwitchWeapon (float wep)\r
168 {\r
169         float           nextwep;\r
170         var float       noammo = FALSE;\r
171 \r
172         if (wep == 1)\r
173                 nextwep = IT_LASER;\r
174         else if (wep == 2)\r
175         {\r
176                 nextwep = IT_SHOTGUN;\r
177                 if (!self.ammo_shells)\r
178                         noammo = TRUE;\r
179         }\r
180         else if (wep == 3)\r
181         {\r
182                 nextwep = IT_UZI;\r
183                 if (!self.ammo_nails)\r
184                         noammo = TRUE;\r
185         }\r
186         else if (wep == 4)\r
187         {\r
188                 nextwep = IT_CRYLINK;\r
189                 if (!self.ammo_cells)\r
190                         noammo = TRUE;\r
191         }\r
192         else if (wep == 5)\r
193         {\r
194                 nextwep = IT_ELECTRO;\r
195                 if (!self.ammo_cells)\r
196                         noammo = TRUE;\r
197         }\r
198         else if (wep == 6)\r
199         {\r
200                 nextwep = IT_GRENADE_LAUNCHER;\r
201                 if (!self.ammo_rockets)\r
202                         noammo = TRUE;\r
203         }\r
204         else if (wep == 7)\r
205         {\r
206                 nextwep = IT_HAGAR;\r
207                 if (!self.ammo_rockets)\r
208                         noammo = TRUE;\r
209         }\r
210         else if (wep == 8)\r
211         {\r
212                 nextwep = IT_NEX;\r
213                 if (!self.ammo_cells)\r
214                         noammo = TRUE;\r
215         }\r
216         else if (wep == 9)\r
217         {\r
218                 nextwep = IT_ROCKET_LAUNCHER;\r
219                 if (!self.ammo_rockets)\r
220                         noammo = TRUE;\r
221         }\r
222 \r
223 \r
224         if (!(self.items & nextwep))\r
225         {\r
226                 sprint (self, "You don't own that weapon\n");\r
227                 return;\r
228         }\r
229         else if (noammo)\r
230         {\r
231                 sprint (self, "You don't have any ammo for that weapon\n");\r
232                 return;\r
233         }\r
234 \r
235         self.weapon = nextwep;\r
236         W_UpdateWeapon ();\r
237         W_UpdateAmmo ();\r
238         self.attack_finished = time + 0.2;\r
239         if (self.viewzoom != 1)\r
240                 self.viewzoom = 1;\r
241 }\r
242 \r
243 void W_NextWeapon (void)\r
244 {\r
245         float   noammo;\r
246 \r
247         while (TRUE)\r
248         {\r
249                 noammo = FALSE;\r
250 \r
251                 if (self.weapon == IT_ROCKET_LAUNCHER)\r
252                         self.weapon = IT_LASER;\r
253                 else if (self.weapon == IT_LASER)\r
254                 {\r
255                         self.weapon = IT_SHOTGUN;\r
256                         if (!self.ammo_shells)\r
257                                 noammo = TRUE;\r
258                 }\r
259                 else if (self.weapon == IT_SHOTGUN)\r
260                 {\r
261                         self.weapon = IT_UZI;\r
262                         if (!self.ammo_nails)\r
263                                 noammo = TRUE;\r
264                 }\r
265                 else if (self.weapon == IT_UZI)\r
266                 {\r
267                         self.weapon = IT_CRYLINK;\r
268                         if (!self.ammo_cells)\r
269                         noammo = TRUE;\r
270                 }\r
271                 else if (self.weapon == IT_CRYLINK)\r
272                 {\r
273                         self.weapon = IT_ELECTRO;\r
274                         if (!self.ammo_cells)\r
275                                 noammo = TRUE;\r
276                 }\r
277                 else if (self.weapon == IT_ELECTRO)\r
278                 {\r
279                         self.weapon = IT_GRENADE_LAUNCHER;\r
280                         if (!self.ammo_cells)\r
281                                 noammo = TRUE;\r
282                 }\r
283                 else if (self.weapon == IT_GRENADE_LAUNCHER)\r
284                 {\r
285                         self.weapon = IT_HAGAR;\r
286                         if (!self.ammo_rockets)\r
287                                 noammo = TRUE;\r
288                 }\r
289                 else if (self.weapon == IT_HAGAR)\r
290                 {\r
291                         self.weapon = IT_NEX;\r
292                         if (!self.ammo_rockets)\r
293                         noammo = TRUE;\r
294                 }\r
295                 else if (self.weapon == IT_NEX)\r
296                 {\r
297                         self.weapon = IT_ROCKET_LAUNCHER;\r
298                         if (!self.ammo_cells)\r
299                         noammo = TRUE;\r
300                 }\r
301 \r
302                 if ((self.items & self.weapon) && !noammo)\r
303                 {\r
304                         W_UpdateWeapon ();\r
305                         W_UpdateAmmo ();\r
306                         return;\r
307                 }\r
308         }\r
309 }\r
310 \r
311 void W_PreviousWeapon (void)\r
312 {\r
313         float   noammo;\r
314 \r
315         while (TRUE)\r
316         {\r
317                 noammo = FALSE;\r
318 \r
319                 if (self.weapon == IT_SHOTGUN)\r
320                         self.weapon = IT_LASER;\r
321                 else if (self.weapon == IT_UZI)\r
322                 {\r
323                         self.weapon = IT_SHOTGUN;\r
324                         if (!self.ammo_shells)\r
325                                 noammo = TRUE;\r
326                 }\r
327                 else if (self.weapon == IT_CRYLINK)\r
328                 {\r
329                         self.weapon = IT_UZI;\r
330                         if (!self.ammo_nails)\r
331                                 noammo = TRUE;\r
332                 }\r
333                 else if (self.weapon == IT_ELECTRO)\r
334                 {\r
335                         self.weapon = IT_CRYLINK;\r
336                         if (!self.ammo_cells)\r
337                                 noammo = TRUE;\r
338                 }\r
339                 else if (self.weapon == IT_GRENADE_LAUNCHER)\r
340                 {\r
341                         self.weapon = IT_ELECTRO;\r
342                         if (!self.ammo_cells)\r
343                                 noammo = TRUE;\r
344                 }\r
345                 else if (self.weapon == IT_HAGAR)\r
346                 {\r
347                         self.weapon = IT_GRENADE_LAUNCHER;\r
348                         if (!self.ammo_rockets)\r
349                                 noammo = TRUE;\r
350                 }\r
351                 else if (self.weapon == IT_NEX)\r
352                 {\r
353                         self.weapon = IT_HAGAR;\r
354                         if (!self.ammo_rockets)\r
355                                 noammo = TRUE;\r
356                 }\r
357                 else if (self.weapon == IT_ROCKET_LAUNCHER)\r
358                 {\r
359                         self.weapon = IT_NEX;\r
360                         if (!self.ammo_cells)\r
361                                 noammo = TRUE;\r
362                 }\r
363                 else if (self.weapon == IT_LASER)\r
364                 {\r
365                         self.weapon = IT_ROCKET_LAUNCHER;\r
366                         if (!self.ammo_rockets)\r
367                                 noammo = TRUE;\r
368                 }\r
369 \r
370                 if ((self.items & self.weapon) && !noammo)\r
371                 {\r
372                         W_UpdateWeapon ();\r
373                         W_UpdateAmmo ();\r
374                         return;\r
375                 }\r
376         }\r
377 }\r
378 */\r
379 float W_CheckAmmo (void)\r
380 {\r
381         if ((cvar("g_instagib") == 1) | (cvar("g_rocketarena") == 1))\r
382                 return TRUE;\r
383 \r
384         W_UpdateAmmo ();\r
385         if (self.weapon == IT_LASER)\r
386                 return TRUE;\r
387         else if (self.currentammo)\r
388                 return TRUE;\r
389 \r
390         self.weapon = W_GetBestWeapon (self);\r
391         W_UpdateWeapon ();\r
392 \r
393         return FALSE;\r
394 }\r
395 \r
396 /*\r
397 void FireRailgunBullet (vector src, float bdamage, vector dir, float spread, float deathtype)\r
398 {\r
399         vector  v, lastpos;\r
400         entity  saveself, last;\r
401         vector  org;\r
402         org = self.origin + self.view_ofs;\r
403         if (bdamage < 1)\r
404                 return;\r
405 \r
406         last = self;\r
407         lastpos = src;\r
408 \r
409         while (bdamage > 0)\r
410         {\r
411                 traceline_hitcorpse (self, org, org + v_forward * 4096 + v_right * crandom () * spread + v_up * crandom () * spread, FALSE, self);\r
412                 last = trace_ent;\r
413                 lastpos = trace_endpos;\r
414                 if (trace_fraction != 1.0)\r
415                 {\r
416                         if (pointcontents(trace_endpos - dir*4) == CONTENT_SKY)\r
417                                 return;\r
418 \r
419                         if (trace_ent.takedamage || trace_ent.classname == "case")\r
420                         {\r
421                                 if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")\r
422                                         te_blood (trace_endpos, dir * bdamage * 16, bdamage);\r
423                                 Damage (trace_ent, self, self, bdamage, deathtype, trace_endpos, dir * bdamage);\r
424                         }\r
425                 }\r
426                 if (last.solid == SOLID_BSP)\r
427                         bdamage = 0;\r
428         }\r
429 }\r
430 */\r
431 \r
432 //vector railgun_hitlocation;\r
433 void FireRailgunBullet (vector start, vector end, float bdamage, float deathtype)\r
434 {\r
435         local vector hitloc, force;\r
436         local entity ent;\r
437         //local entity explosion;\r
438 \r
439         force = normalize(end - start) * 800; //(bdamage * 10);\r
440 \r
441         // find how far the beam can go until it hits a wall\r
442         traceline (start, end, TRUE, self);\r
443         // go a little bit into the wall because we need to hit this wall later\r
444         end = trace_endpos + normalize(end - start);\r
445 \r
446         // trace multiple times until we hit a wall, each obstacle will be made\r
447         // non-solid so we can hit the next, while doing this we spawn effects and\r
448         // note down which entities were hit so we can damage them later\r
449         while (1)\r
450         {\r
451                 traceline_hitcorpse (self, start, end, FALSE, self);\r
452 \r
453                 // if it is world we can't hurt it so stop now\r
454                 if (trace_ent == world || trace_fraction == 1)\r
455                         break;\r
456 \r
457                 // make the entity non-solid so we can hit the next one\r
458                 trace_ent.railgunhit = TRUE;\r
459                 trace_ent.railgunhitloc = trace_endpos;\r
460                 trace_ent.railgunhitsolidbackup = trace_ent.solid;\r
461 \r
462                 // stop if this is a wall\r
463                 if (trace_ent.solid == SOLID_BSP)\r
464                         break;\r
465 \r
466                 // make the entity non-solid\r
467                 trace_ent.solid = SOLID_NOT;\r
468         }\r
469 \r
470         // find all the entities the railgun hit and restore their solid state\r
471         ent = findfloat(world, railgunhit, TRUE);\r
472         while (ent)\r
473         {\r
474                 // restore their solid type\r
475                 ent.solid = ent.railgunhitsolidbackup;\r
476                 ent = findfloat(ent, railgunhit, TRUE);\r
477         }\r
478 \r
479         // spawn a temporary explosion entity for RadiusDamage calls\r
480         //explosion = spawn();\r
481 \r
482         // find all the entities the railgun hit and hurt them\r
483         ent = findfloat(world, railgunhit, TRUE);\r
484         while (ent)\r
485         {\r
486                 // get the details we need to call the damage function\r
487                 hitloc = ent.railgunhitloc;\r
488                 ent.railgunhitloc = '0 0 0';\r
489                 ent.railgunhitsolidbackup = SOLID_NOT;\r
490                 ent.railgunhit = FALSE;\r
491 \r
492                 // apply the damage\r
493                 if (ent.takedamage || ent.classname == "case")\r
494                         Damage (ent, self, self, bdamage, deathtype, hitloc, force);\r
495 \r
496                 // create a small explosion to throw gibs around (if applicable)\r
497                 //setorigin (explosion, hitloc);\r
498                 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);\r
499 \r
500                 // advance to the next entity\r
501                 ent = findfloat(ent, railgunhit, TRUE);\r
502         }\r
503 \r
504         // we're done with the explosion entity, remove it\r
505         //remove(explosion);\r
506 }\r
507 \r
508 void fireBullet2 (vector start, vector dir, float spread, float damage, float dtype, float tracer, float force)\r
509 {\r
510         vector  end;\r
511         float r;\r
512         local entity e;\r
513 \r
514         // use traceline_hitcorpse to make sure it can hit gibs and corpses too\r
515         dir = dir + randomvec() * spread;\r
516         end = start + dir * 4096;\r
517         traceline_hitcorpse (self, start, end, FALSE, self);\r
518 \r
519         if (tracer)\r
520         {\r
521                 e = spawn();\r
522                 e.owner = self;\r
523                 e.movetype = MOVETYPE_FLY;\r
524                 e.solid = SOLID_NOT;\r
525                 e.think = SUB_Remove;\r
526                 e.nextthink = time + vlen(trace_endpos - start) / 6000;\r
527                 e.velocity = dir * 6000;\r
528                 e.angles = vectoangles(e.velocity);\r
529                 setmodel (e, "models/tracer.mdl");\r
530                 setsize (e, '0 0 0', '0 0 0');\r
531                 setorigin (e, start);\r
532                 e.effects = e.effects | EF_ADDITIVE;\r
533         }\r
534 \r
535         // FIXME - causes excessive 'tinking'. Hopefully remove "tink1.wav" from the ricochets with csqc\r
536         if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))\r
537         {\r
538                 if (trace_ent.solid == SOLID_BSP)\r
539                 {\r
540                         pointcontents (self.origin);\r
541                         te_gunshot (trace_endpos);\r
542                         r = random ();\r
543                         if (r < 0.10)\r
544                                 PointSound (trace_endpos, "weapons/ric1.wav", 1, ATTN_NORM);\r
545                         else if (r < 0.20)\r
546                                 PointSound (trace_endpos, "weapons/ric2.wav", 1, ATTN_NORM);\r
547                         else if (r < 0.30)\r
548                                 PointSound (trace_endpos, "weapons/ric3.wav", 1, ATTN_NORM);\r
549                 }\r
550                 else if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")\r
551                         sound (self, CHAN_BODY, "misc/hit.wav", 1, ATTN_NORM);\r
552                 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);\r
553         }\r
554 }\r
555 \r
556 void fireBullet (vector start, vector dir, float spread, float damage, float dtype, float tracer)\r
557 {\r
558         fireBullet2(start, dir, spread, damage, dtype, tracer, damage * 5); // default force value\r
559 }\r
560 \r
561 /*\r
562 void W_Attack (void)\r
563 {\r
564         if (self.deadflag != DEAD_NO)\r
565         {\r
566                 if (self.death_time < time)\r
567                         PutClientInServer();\r
568 \r
569                 return;\r
570         }\r
571 \r
572         if (!W_CheckAmmo ())\r
573                 return;\r
574 \r
575         makevectors (self.v_angle);\r
576         //if (self.weapon == IT_LASER)\r
577         //      W_Laser_Attack ();\r
578         //if (self.weapon == IT_SHOTGUN)\r
579                 //W_Shotgun_Attack ();\r
580         //else if (self.weapon == IT_UZI)\r
581                 //W_Uzi_Attack ();\r
582         if (self.weapon == IT_CRYLINK)\r
583                 W_Crylink_Attack ();\r
584         else if (self.weapon == IT_ELECTRO)\r
585                 {\r
586                 W_Electro_Attack (self.electrocount);\r
587                 self.electrocount = self.electrocount + 1;\r
588                 if (self.electrocount == 3)\r
589                         self.electrocount = 0;\r
590                 }\r
591         else if (self.weapon == IT_GRENADE_LAUNCHER)\r
592                 W_Grenade_Attack ();\r
593         else if (self.weapon == IT_HAGAR)\r
594                 W_Hagar_Attack ();\r
595         else if (self.weapon == IT_NEX)\r
596                 W_Nex_Attack ();\r
597         //else if (self.weapon == IT_ROCKET_LAUNCHER)\r
598         //      W_Rocket_Attack ();\r
599 \r
600         W_UpdateAmmo ();\r
601 }\r
602 \r
603 void W_SecondaryAttack (void)\r
604 {\r
605         if (self.deadflag != DEAD_NO)\r
606         {\r
607                 if (self.death_time < time)\r
608                         PutClientInServer();\r
609 \r
610                 return;\r
611         }\r
612 \r
613         if (!W_CheckAmmo ())\r
614                 return;\r
615 \r
616         makevectors (self.v_angle);\r
617         //if (self.weapon == IT_LASER)\r
618                 //W_Laser_Attack2 ();\r
619         //if (self.weapon == IT_SHOTGUN)\r
620                 //W_Shotgun_Attack2 ();\r
621         //else if (self.weapon == IT_UZI)\r
622                 //W_Uzi_Attack2 ();\r
623         else if (self.weapon == IT_CRYLINK)\r
624                 W_Crylink_Attack2 ();\r
625         else if (self.weapon == IT_ELECTRO) {\r
626                 W_Electro_Attack2 (self.electrocount);\r
627                 self.electrocount = self.electrocount + 1;\r
628                 if (self.electrocount == 3)\r
629                         self.electrocount = 0;\r
630                 }\r
631         else if (self.weapon == IT_GRENADE_LAUNCHER)\r
632                 W_Grenade_Attack2 ();\r
633         else if (self.weapon == IT_HAGAR)\r
634                 W_Hagar_Attack2 ();\r
635         else if (self.weapon == IT_NEX)\r
636                 W_Nex_Attack2 ();\r
637         //else if (self.weapon == IT_ROCKET_LAUNCHER)\r
638                 //W_Rocket_Attack2 ();\r
639 \r
640         W_UpdateAmmo ();\r
641 }\r
642 \r
643 void W_ThirdAttack (void)\r
644 {\r
645         if (self.deadflag != DEAD_NO)\r
646         {\r
647                 if (self.death_time < time)\r
648                         PutClientInServer();\r
649 \r
650                 return;\r
651         }\r
652 \r
653         if (!W_CheckAmmo ())\r
654                 return;\r
655 \r
656         makevectors (self.v_angle);\r
657         //if (self.weapon == IT_LASER)\r
658                 //W_Laser_Attack2 ();\r
659         //if (self.weapon == IT_SHOTGUN)\r
660                 //W_Shotgun_Attack2 ();\r
661         //else if (self.weapon == IT_UZI)\r
662                 //W_Uzi_Attack3 ();\r
663         else if (self.weapon == IT_CRYLINK)\r
664                 W_Crylink_Attack2 ();\r
665         else if (self.weapon == IT_ELECTRO) {\r
666                 W_Electro_Attack3 (self.electrocount);\r
667                 self.electrocount = self.electrocount + 1;\r
668                 if (self.electrocount == 3)\r
669                         self.electrocount = 0;\r
670                 }\r
671         else if (self.weapon == IT_GRENADE_LAUNCHER)\r
672                 W_Grenade_Attack3 ();\r
673         else if (self.weapon == IT_HAGAR)\r
674                 W_Hagar_Attack3 ();\r
675         else if (self.weapon == IT_NEX)\r
676                 W_Nex_Attack2 ();\r
677         //else if (self.weapon == IT_ROCKET_LAUNCHER)\r
678                 //W_Rocket_Attack3 ();\r
679 \r
680         W_UpdateAmmo ();\r
681 }\r
682 */\r
683 \r
684 float RateFlameDamage(float flametime, float flamedmg, float flamerate)\r
685 {\r
686         // return (how much longer flame will last) * (how much to damage per think / how often to think)\r
687         return (flametime - time) * (flamedmg / flamerate);\r
688 }\r
689 \r
690 /*void FlamePuffThink()\r
691 {\r
692         self.nextthink = time + self.cnt;\r
693         self.frame = self.frame + 1;\r
694         if(self.frame >= self.count)\r
695                 self.think = SUB_Remove;\r
696 }\r
697 */\r
698 void FlameBurnTarget();\r
699 \r
700 \r
701 entity CreateFlame(entity targ, entity attacker)\r
702 {\r
703         entity f;\r
704         f = targ.onfire = spawn();\r
705         f.classname = "burning";\r
706         f.owner = attacker;\r
707         f.enemy = targ;\r
708         f.dmg = 0;\r
709         f.ltime = 0;\r
710         f.wait = 0;\r
711         f.think = FlameBurnTarget;\r
712         f.onfire = spawn();\r
713 \r
714         f.effects = f.onfire.effects = EF_ADDITIVE;\r
715         f.scale = f.onfire.scale = 2;\r
716 \r
717         setmodel(f, "models/sprites/fire_top.spr32");\r
718         setattachment(f, f.enemy, "");\r
719         setmodel(f.onfire, "models/sprites/fire_base.spr32");\r
720 \r
721         setorigin(f.onfire, '0 0 -5' * f.scale);\r
722         setorigin(f, '0 0 2' * f.scale + '0 0 20');\r
723         setattachment(f.onfire, f, "");\r
724 \r
725         return f;\r
726 }\r
727 \r
728 entity IgniteTarget (entity targ, entity attacker, float flametime, float flamedmg, float flamerate, float rateflame)\r
729 {\r
730         entity f;\r
731 \r
732         //bprint("ignite targets?\n");\r
733 \r
734         if(targ.class == CLASS_PYRO)\r
735         {\r
736                 //flametime = flametime / 5; // pyros don't stay on fire for long\r
737                 return world; // don't set pyros on fire\r
738         }\r
739 \r
740         if(targ.class == CLASS_MEDIC)\r
741         {\r
742                 //flametime = flametime / 3; // medics don't stay on fire for long\r
743                 return world; // don't set medics on fire\r
744         }\r
745 \r
746         f = targ.onfire;\r
747         if(f == world)\r
748         {\r
749                 f = CreateFlame(targ, attacker);\r
750         }\r
751         else\r
752         {\r
753                 if(f.nextthink <= 0)\r
754                         f.nextthink = time + flamerate;\r
755         }\r
756 \r
757 \r
758 //      bprint(ftos(f.wait), ", ", ftos(f.dmg), ", ", ftos(f.ltime), "\n");\r
759         //bprint(ftos(flametime), ", ", ftos(flamedmg), ", ", ftos(flamerate), "\n");\r
760 //      bprint(ftos(RateFlameDamage(f.wait, f.dmg, f.ltime)), ", ", ftos(RateFlameDamage(flametime, flamedmg, flamerate)), "\n");\r
761 \r
762         if(rateflame && RateFlameDamage(f.wait, f.dmg, f.ltime) > RateFlameDamage(time + flametime, flamedmg, flamerate))\r
763         {\r
764                 f.owner = attacker; // give the new attacker ownership of the burn damage\r
765                 return f; // current damage rating is larger, don't replace it\r
766         }\r
767 \r
768         //bprint("burning success: ", ftos(flametime), "\n");\r
769 \r
770         f.dmg = flamedmg;\r
771         f.ltime = flamerate;\r
772         f.wait = time + flametime;\r
773 \r
774         if(!f.nextthink || f.nextthink > time + f.ltime)\r
775                 f.nextthink = time + f.ltime;\r
776 \r
777         return f;\r
778 }\r
779 \r
780 void ExtinguishFlame(entity targ)\r
781 {\r
782         entity f, b;\r
783         if(!targ.onfire)//targ.onfire.classname != "burning")\r
784                 return;\r
785         //bprint(strcat("ExtinguishFlame(", targ.classname, ") ", targ.onfire.classname, "\n"));\r
786 \r
787         f = targ.onfire;\r
788         b = targ.onfire.onfire;\r
789 \r
790         // fixme: hiss sound\r
791 \r
792         if(b)\r
793         {\r
794                 b.think = SUB_Null;\r
795                 b.nextthink = -1;\r
796                 setmodel(b, "models/sprites/null.spr");\r
797                 setattachment(b, world, "");\r
798                 remove(b); // remove base model\r
799                 //targ.onfire.onfire.think = SUB_Remove;\r
800                 //targ.onfire.onfire.nextthink = time + 0.1;\r
801                 f.onfire = world;\r
802         }\r
803         f.think = SUB_Null;\r
804         f.nextthink = -1;\r
805         setmodel(f, "models/sprites/null.spr");\r
806         setattachment(f, world, "");\r
807         //targ.onfire.think = SUB_Remove;\r
808         //targ.onfire.nextthink = time + 0.1;\r
809         remove(f);\r
810         targ.onfire = world;\r
811 }\r
812 \r
813 void FlameBurnTarget()\r
814 {\r
815         entity head;\r
816         float flametime, flametimemax, radius, flameratio, distratio, edgeratio, damage;\r
817         //bprint("flame burn target\n");\r
818 \r
819         if(self.enemy == world || self.enemy.classname == "gib")\r
820         {\r
821                 if(self.enemy != world)\r
822                 {\r
823                         //bprint("on a gib, remove flame\n");\r
824                         //self.enemy.onfire = world;\r
825                         ExtinguishFlame(self.enemy);\r
826                         return;\r
827                 }\r
828                 //bprint("enemy is world, remove flame\n");\r
829                 self.think = SUB_Null;\r
830                 self.nextthink = -1;\r
831                 setmodel(self, "models/sprites/null.spr");\r
832                 setattachment(self, world, "");\r
833                 if(self.onfire)\r
834                 {\r
835                         self.onfire.think = SUB_Null;\r
836                         self.onfire.nextthink = -1;\r
837                         setmodel(self.onfire, "models/sprites/null.spr");\r
838                         setattachment(self.onfire, world, "");\r
839                         remove(self.onfire);\r
840                         self.onfire = world;\r
841                 }\r
842                 remove(self);\r
843                 return;\r
844         }\r
845 \r
846         if(self.wait < time || self.enemy.waterlevel > 2 || (!self.enemy.takedamage && self.enemy.classname != "grenade"))\r
847         {\r
848                 /*if(self.enemy != world)\r
849                 {\r
850                         self.enemy.effects = self.enemy.effects - (self.enemy.effects & EF_FLAME);\r
851                         self.enemy.onfire = world;\r
852                 }\r
853                 remove(self);*/\r
854                 ExtinguishFlame(self.enemy);\r
855                 return;\r
856         }\r
857         self.nextthink = time + self.ltime;\r
858 \r
859         Damage (self.enemy, self, self.owner, self.dmg, DEATH_BURNING, self.enemy.origin - '0 0 5', '0 0 0');//'0 0 -1' * self.dmg);\r
860 \r
861         // flames spread to other targets\r
862 \r
863         radius = cvar("g_balance_heat_radius");\r
864         head = findradius(self.enemy.origin, radius);\r
865         while(head)\r
866         {\r
867                 if((head.takedamage || head.classname == "grenade") && head != self.enemy)\r
868                 {\r
869                         //bprint(strcat("maybe burn ", head.classname, "\n"));\r
870                         // don't harm or spread to allies or pyros\r
871                         //if(!(head.classname == "player" && (head.team == self.owner.team || head.class == CLASS_PYRO)) )\r
872                         if(head.classname == "player")\r
873                         {\r
874                                 if(head.class == CLASS_PYRO || head.class == CLASS_MEDIC) // pyros & medics are mostly immune to fire\r
875                                 {       head = head.chain;      continue;}\r
876                                 if(head.team == self.owner.team && teamplay) // don't hurt teammates\r
877                                 {       head = head.chain;      continue;}\r
878                         }\r
879 \r
880                         traceline(self.enemy.origin, head.origin, TRUE, self);\r
881                         if(trace_fraction >= 1)\r
882                         {\r
883                                 //bprint(strcat("burn ", head.classname, "\n"));\r
884                                 edgeratio = cvar("g_balance_heat_edgeratio");\r
885                                 distratio = ( 1 - (vlen(self.enemy.origin - head.origin) / radius) );\r
886                                 flameratio = edgeratio + distratio*(1 - edgeratio);\r
887 \r
888                                 // increase the player's heat; if it goes over the max it'll get capped automatically by the cooldown code\r
889                                 //head.flame_heat = cvar("g_balance_maxheat");\r
890                                 head.flame_heat = head.flame_heat + flameratio * cvar("g_balance_heatup_rate") * self.ltime;\r
891                                 //head.flame_heat_time = time;\r
892 \r
893                                 // deal direct damage from the heat radiated by the fire\r
894                                 damage = flameratio * self.dmg*cvar("g_balance_heat_damage");\r
895                                 Damage (head, self, self.owner, damage, DEATH_BURNING, self.enemy.origin, '0 0 0');\r
896 \r
897                                 if(head.flame_heat >= 1.0 && head.takedamage == DAMAGE_AIM && head.health > 0)\r
898                                 {\r
899                                         flametimemax = cvar("g_balance_heat_timemax");\r
900                                         flametime = (self.wait - time) * cvar("g_balance_heat_transfer");\r
901                                         if(flametime > flametimemax)\r
902                                                 flametime = flametimemax;\r
903 \r
904 \r
905                                         //bprint(ftos(time), " - flame transfer - ", ftos(flametime), "\n");\r
906 \r
907                                         \r
908                                         IgniteTarget(head, self.owner, flametime, self.dmg, self.ltime, TRUE);\r
909                                 }\r
910                         }\r
911                 }\r
912                 head = head.chain;\r
913         }\r
914 }\r
915 \r
916 \r
917 void PoisonTarget(entity targ, float poisonDamage, float poisonTime, float ratepoison)\r
918 {\r
919         if(targ.class == CLASS_MEDIC)\r
920         {\r
921                 return; // don't poison medics\r
922         }\r
923 \r
924         if(ratepoison && targ.poison_damage > poisonDamage)\r
925                 return; // current damage rating is larger, don't replace it\r
926 \r
927         targ.poison_damage = poisonDamage;\r
928         targ.poison_rate = poisonDamage / poisonTime;\r
929 }\r
930 \r
931 \r
932 \r
933 \r
934 \r
935 \r
936 \r
937 \r
938 \r
939 \r
940 \r
941 float W_LimitNumEnts(string clname, float num_allowed, void() DeathFunc)\r
942 {\r
943         float num, oldest;\r
944         local entity e, selected;\r
945         e = world;\r
946         oldest = time + 1;\r
947         num = 0;\r
948         do\r
949         {\r
950                 e = find(e, classname, clname);\r
951                 if(e != world && e.owner == self)\r
952                 {\r
953                         num = num + 1;\r
954                         if(e.create_time < oldest)\r
955                         {\r
956                                 selected = e;\r
957                                 oldest = e.create_time;\r
958                         }\r
959                 }\r
960         }while(e);\r
961 \r
962         if(num > num_allowed)\r
963         {\r
964                 if(selected != world)\r
965                 {\r
966                         e = self;\r
967                         self = selected;\r
968                         DeathFunc();\r
969                         self = e;\r
970                         return TRUE;\r
971                 }\r
972                 else\r
973                         bprint("error (W_LimitNumEnts): cannot find oldest entity\n");\r
974         }\r
975         return FALSE;\r
976 }\r
977 \r