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