]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/tesla_weapon.qc
Merge branch 'master' into Mario/entrap_nade
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / tesla_weapon.qc
1 #include "tesla_weapon.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6
7 entity toast(entity actor, entity from, float range, float damage);
8 SOUND(TeslaCoilTurretAttack_FIRE, W_Sound("electro_fire"));
9 METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
10     bool isPlayer = IS_PLAYER(actor);
11     if (fire & 1)
12     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) {
13         if (isPlayer) {
14             turret_initparams(actor);
15             W_SetupShot_Dir(actor, v_forward, false, 0, SND_TeslaCoilTurretAttack_FIRE, CH_WEAPON_B, 0);
16             actor.tur_shotdir_updated = w_shotdir;
17             actor.tur_shotorg = w_shotorg;
18             actor.tur_head = actor;
19             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
20         }
21
22         float d = actor.shot_dmg;
23         float r = actor.target_range;
24         entity e = spawn();
25         setorigin(e, actor.tur_shotorg);
26
27         actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
28
29         entity t = toast(actor, e,r,d);
30         remove(e);
31
32         if (t == NULL) return;
33
34         actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_TEAMCHECK;
35
36         actor.attack_finished_single[0] = time + actor.shot_refire;
37         for (int i = 0; i < 10; ++i) {
38             d *= 0.75;
39             r *= 0.85;
40             t = toast(actor, t, r, d);
41             if (t == NULL) break;
42
43         }
44
45         e = findchainfloat(railgunhit, 1);
46         while (e) {
47             e.railgunhit = 0;
48             e = e.chain;
49         }
50
51     }
52 }
53
54 entity toast(entity actor, entity from, float range, float damage)
55 {
56     entity e;
57     entity etarget = NULL;
58     float d,dd;
59     float r;
60
61     dd = range + 1;
62
63     e = findradius(from.origin,range);
64     while (e)
65     {
66         if ((e.railgunhit != 1) && (e != from))
67         {
68             r = turret_validate_target(actor,e,actor.target_validate_flags);
69             if (r > 0)
70             {
71                 traceline(from.origin,0.5 * (e.absmin + e.absmax),MOVE_WORLDONLY,from);
72                 if (trace_fraction == 1.0)
73                 {
74                     d = vlen(e.origin - from.origin);
75                     if (d < dd)
76                     {
77                         dd = d;
78                         etarget = e;
79                     }
80                 }
81             }
82         }
83         e = e.chain;
84     }
85
86     if (etarget)
87     {
88         te_csqc_lightningarc(from.origin,etarget.origin);
89         Damage(etarget, actor, actor, damage, DEATH_TURRET_TESLA.m_id, etarget.origin, '0 0 0');
90         etarget.railgunhit = 1;
91     }
92
93     return etarget;
94 }
95
96 #endif
97
98 #endif