]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/units/unit_tessla.qc
Merge remote branch 'origin/mirceakitsune/fix_antilag_teleporttime' as of '44a728d415...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / units / unit_tessla.qc
1 void spawnfunc_turret_tesla();
2 void turret_tesla_dinit();
3 void turret_tesla_fire();
4
5 entity toast(entity from, float range, float damage)
6 {
7     entity e;
8     entity etarget;
9     float d,dd;
10     float r;
11
12     dd = range + 1;
13
14     e = findradius(from.origin,range);
15     while (e)
16     {
17         if ((e.railgunhit != 1) && (e != from))
18         {
19             r = turret_validate_target(self,e,self.target_validate_flags);
20             if (r > 0)
21             {
22                 traceline(from.origin,0.5 * (e.absmin + e.absmax),MOVE_WORLDONLY,from);
23                 if (trace_fraction == 1.0)
24                 {
25                     d = vlen(e.origin - from.origin);
26                     if (d < dd)
27                     {
28                         dd = d;
29                         etarget = e;
30                     }
31                 }
32             }
33         }
34         e = e.chain;
35     }
36
37     if (etarget)
38     {        
39         te_csqc_lightningarc(from.origin,etarget.origin);
40         Damage(etarget, self, self, damage, DEATH_TURRET_TESLA, etarget.origin, '0 0 0');
41         etarget.railgunhit = 1;
42     }
43
44     return etarget;
45 }
46
47 float turret_tesla_firecheck()
48 {
49     if not (turret_stdproc_firecheck())
50         return 0;
51
52     self.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
53
54     self.enemy = turret_select_target();
55
56     if(self.enemy)
57         return 1;
58
59     return 0;
60
61 }
62
63 void turret_tesla_fire()
64 {
65     entity e,t;
66     float d,r,i;
67
68     //w_deathtypestring = "discoverd how a tesla coil works";
69
70     d = self.shot_dmg;
71     r = self.target_range;
72     e = spawn();
73     setorigin(e,self.tur_shotorg);
74
75     self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
76
77     t = toast(e,r,d);
78     remove(e);
79
80     if (t == world) return;
81
82     self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_TEAMCHECK;
83
84     self.attack_finished_single = time + self.shot_refire;
85     for (i = 0; i < 10; ++i)
86     {
87         d *= 0.75;
88         r *= 0.85;
89         t = toast(t, r, d);
90         if (t == world) break;
91
92     }
93
94     e = findchainfloat(railgunhit, 1);
95     while (e)
96     {
97         e.railgunhit = 0;
98         e = e.chain;
99     }
100 }
101
102 void turret_tesla_postthink()
103 {
104     if not (self.tur_active)
105     {
106         self.tur_head.avelocity = '0 0 0';
107         return;
108     }
109
110     if(self.ammo < self.shot_dmg)
111     {
112         self.tur_head.avelocity = '0 45 0' * (self.ammo / self.shot_dmg);
113     }
114     else
115     {
116         self.tur_head.avelocity = '0 180 0' * (self.ammo / self.shot_dmg);
117
118         if(self.attack_finished_single > time)
119             return;
120
121         float f;
122         f = (self.ammo / self.ammo_max);
123         f = f * f;
124         if(f > random())
125             if(random() < 0.1)
126                 te_csqc_lightningarc(self.tur_shotorg,self.tur_shotorg + (randomvec() * 350));
127     }
128 }
129
130
131 void turret_tesla_dinit()
132 {
133     if (self.netname == "")      self.netname     = "Tesla Coil";
134
135     self.turrcaps_flags      = TFL_TURRCAPS_HITSCAN | TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MISSILEKILL;
136
137     self.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
138                                TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
139
140     self.firecheck_flags     = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_OWM_AMMO;
141     self.shoot_flags         = TFL_SHOOT_CUSTOM;
142     self.ammo_flags          = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIVE;
143     self.aim_flags           = TFL_AIM_NO;
144     self.track_flags         = TFL_TRACK_NO;
145
146     if (turret_stdproc_init("tesla_std", "models/turrets/tesla_base.md3", "models/turrets/tesla_head.md3", TID_TESLA) == 0)
147     {
148         remove(self);
149         return;
150     }
151     setsize(self,'-60 -60 0','60 60 128');
152
153     self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
154                                  TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
155
156     self.turret_firefunc      = turret_tesla_fire;
157     self.turret_postthink     = turret_tesla_postthink;
158     self.turret_firecheckfunc = turret_tesla_firecheck;
159 }
160
161 /*QUAKED turret_tesla (0 .5 .8) ?
162 */
163 void spawnfunc_turret_tesla()
164 {
165     precache_model ("models/turrets/tesla_head.md3");
166     precache_model ("models/turrets/tesla_base.md3");
167
168
169     self.think = turret_tesla_dinit;
170     self.nextthink = time + 0.5;
171 }
172