Hide the MOTD when going spec
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / tesla_weapon.qc
1 #ifndef TURRET_TESLA_WEAPON_H
2 #define TURRET_TESLA_WEAPON_H
3
4 CLASS(TeslaCoilTurretAttack, PortoLaunch)
5 /* flags     */ ATTRIB(TeslaCoilTurretAttack, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
6 /* impulse   */ ATTRIB(TeslaCoilTurretAttack, impulse, int, 9);
7 /* refname   */ ATTRIB(TeslaCoilTurretAttack, netname, string, "turret_tesla");
8 /* wepname   */ ATTRIB(TeslaCoilTurretAttack, message, string, _("Tesla Coil"));
9 ENDCLASS(TeslaCoilTurretAttack)
10 REGISTER_WEAPON(TESLA, NEW(TeslaCoilTurretAttack));
11
12 #endif
13
14 #ifdef IMPLEMENTATION
15
16 #ifdef SVQC
17
18 entity toast(entity from, float range, float damage);
19 METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2)) {
20     bool isPlayer = IS_PLAYER(actor);
21     if (fire1)
22     if (!isPlayer || weapon_prepareattack(thiswep, actor, false, WEP_CVAR_PRI(electro, refire))) {
23         if (isPlayer) {
24             turret_initparams(actor);
25             W_SetupShot_Dir(actor, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
26             actor.tur_shotdir_updated = w_shotdir;
27             actor.tur_shotorg = w_shotorg;
28             actor.tur_head = actor;
29             weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
30         }
31
32         float d = actor.shot_dmg;
33         float r = actor.target_range;
34         entity e = spawn();
35         setorigin(e,actor.tur_shotorg);
36
37         actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
38
39         entity t = toast(e,r,d);
40         remove(e);
41
42         if (t == NULL) return;
43
44         actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_TEAMCHECK;
45
46         actor.attack_finished_single = time + actor.shot_refire;
47         for (int i = 0; i < 10; ++i) {
48             d *= 0.75;
49             r *= 0.85;
50             t = toast(t, r, d);
51             if (t == world) break;
52
53         }
54
55         e = findchainfloat(railgunhit, 1);
56         while (e) {
57             e.railgunhit = 0;
58             e = e.chain;
59         }
60
61     }
62 }
63
64 entity toast(entity from, float range, float damage)
65 {SELFPARAM();
66     entity e;
67     entity etarget = world;
68     float d,dd;
69     float r;
70
71     dd = range + 1;
72
73     e = findradius(from.origin,range);
74     while (e)
75     {
76         if ((e.railgunhit != 1) && (e != from))
77         {
78             r = turret_validate_target(self,e,self.target_validate_flags);
79             if (r > 0)
80             {
81                 traceline(from.origin,0.5 * (e.absmin + e.absmax),MOVE_WORLDONLY,from);
82                 if (trace_fraction == 1.0)
83                 {
84                     d = vlen(e.origin - from.origin);
85                     if (d < dd)
86                     {
87                         dd = d;
88                         etarget = e;
89                     }
90                 }
91             }
92         }
93         e = e.chain;
94     }
95
96     if (etarget)
97     {
98         te_csqc_lightningarc(from.origin,etarget.origin);
99         Damage(etarget, self, self, damage, DEATH_TURRET_TESLA.m_id, etarget.origin, '0 0 0');
100         etarget.railgunhit = 1;
101     }
102
103     return etarget;
104 }
105
106 #endif
107
108 #endif