c884e5a28b908e5e1c0f8bc755382d3ed92acfba
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / raptor_weapons.qc
1 #ifndef VEHICLE_RAPTOR_WEAPONS_H
2 #define VEHICLE_RAPTOR_WEAPONS_H
3
4 #include "../../weapons/all.qh"
5
6 CLASS(RaptorCannon, PortoLaunch)
7 /* flags     */ ATTRIB(RaptorCannon, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN);
8 /* impulse   */ ATTRIB(RaptorCannon, impulse, int, 3);
9 /* refname   */ ATTRIB(RaptorCannon, netname, string, "raptorcannon");
10 /* wepname   */ ATTRIB(RaptorCannon, message, string, _("Raptor cannon"));
11 ENDCLASS(RaptorCannon)
12 REGISTER_WEAPON(RAPTOR, NEW(RaptorCannon));
13
14 CLASS(RaptorBomb, PortoLaunch)
15 /* flags     */ ATTRIB(RaptorBomb, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN);
16 /* impulse   */ ATTRIB(RaptorBomb, impulse, int, 3);
17 /* refname   */ ATTRIB(RaptorBomb, netname, string, "raptorbomb");
18 /* wepname   */ ATTRIB(RaptorBomb, message, string, _("Raptor bomb"));
19 ENDCLASS(RaptorBomb)
20 REGISTER_WEAPON(RAPTOR_BOMB, NEW(RaptorBomb));
21
22 CLASS(RaptorFlare, PortoLaunch)
23 /* flags     */ ATTRIB(RaptorFlare, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN);
24 /* impulse   */ ATTRIB(RaptorFlare, impulse, int, 3);
25 /* refname   */ ATTRIB(RaptorFlare, netname, string, "raptorflare");
26 /* wepname   */ ATTRIB(RaptorFlare, message, string, _("Raptor flare"));
27 ENDCLASS(RaptorFlare)
28 REGISTER_WEAPON(RAPTOR_FLARE, NEW(RaptorFlare));
29
30 #endif
31
32 #ifdef IMPLEMENTATION
33
34 #ifdef SVQC
35
36 float autocvar_g_vehicle_raptor_cannon_cost;
37 float autocvar_g_vehicle_raptor_cannon_damage;
38 float autocvar_g_vehicle_raptor_cannon_radius;
39 float autocvar_g_vehicle_raptor_cannon_refire;
40 float autocvar_g_vehicle_raptor_cannon_speed;
41 float autocvar_g_vehicle_raptor_cannon_spread;
42 float autocvar_g_vehicle_raptor_cannon_force;
43
44 float autocvar_g_vehicle_raptor_bomblets;
45 float autocvar_g_vehicle_raptor_bomblet_alt;
46 float autocvar_g_vehicle_raptor_bomblet_time;
47 float autocvar_g_vehicle_raptor_bomblet_damage;
48 float autocvar_g_vehicle_raptor_bomblet_spread;
49 float autocvar_g_vehicle_raptor_bomblet_edgedamage;
50 float autocvar_g_vehicle_raptor_bomblet_radius;
51 float autocvar_g_vehicle_raptor_bomblet_force;
52 float autocvar_g_vehicle_raptor_bomblet_explode_delay;
53
54 METHOD(RaptorCannon, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
55     SELFPARAM();
56     bool isPlayer = IS_PLAYER(self);
57     entity player = isPlayer ? self : self.owner;
58     entity veh = player.vehicle;
59     setself(player);
60     // 1 [wait] 1 [wait] 2 [wait] 2 [wait] [wait]
61     float t = autocvar_g_vehicle_raptor_cannon_refire * (1 + veh.misc_bulletcounter == 4);
62     if (fire1)
63     if (weapon_prepareattack(false, t)) {
64         if (isPlayer) W_SetupShot_Dir(player, v_forward, false, 0, SND(Null), CH_WEAPON_B, 0);
65         vector org = w_shotorg;
66         vector dir = w_shotdir;
67         if (veh) {
68             veh.misc_bulletcounter += 1;
69             org = (veh.misc_bulletcounter <= 2) ? gettaginfo(veh.gun1, gettagindex(veh.gun1, "fire1"))
70               : (((veh.misc_bulletcounter == 4) ? veh.misc_bulletcounter = 0 : 0), gettaginfo(veh.gun2, gettagindex(veh.gun2, "fire1")));
71             dir = v_forward;
72             veh.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost;
73             self.cnt = time;
74         }
75         vehicles_projectile(EFFECT_RAPTOR_MUZZLEFLASH.eent_eff_name, SND(LASERGUN_FIRE),
76                                org, normalize(dir + randomvec() * autocvar_g_vehicle_raptor_cannon_spread) * autocvar_g_vehicle_raptor_cannon_speed,
77                                autocvar_g_vehicle_raptor_cannon_damage, autocvar_g_vehicle_raptor_cannon_radius, autocvar_g_vehicle_raptor_cannon_force,  0,
78                                DEATH_VH_RAPT_CANNON, PROJECTILE_RAPTORCANNON, 0, true, true, veh ? veh : player);
79         weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
80     }
81     setself(this);
82     return true;
83 }
84 METHOD(RaptorCannon, wr_checkammo1, bool(RacerAttack thiswep)) {
85     SELFPARAM();
86     bool isPlayer = IS_PLAYER(self);
87     entity player = isPlayer ? self : self.owner;
88     entity veh = player.vehicle;
89     return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_raptor_cannon_cost;
90 }
91
92 float autocvar_g_vehicle_raptor_bombs_refire;
93
94 void raptor_bombdrop();
95 METHOD(RaptorBomb, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
96     SELFPARAM();
97     bool isPlayer = IS_PLAYER(self);
98     entity player = isPlayer ? self : self.owner;
99     entity veh = player.vehicle;
100     setself(player);
101     if (fire2)
102     if (weapon_prepareattack(false, autocvar_g_vehicle_raptor_bombs_refire)) {
103         if (veh) setself(veh);
104         raptor_bombdrop();
105         weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
106     }
107     setself(this);
108     return true;
109 }
110
111 float autocvar_g_vehicle_raptor_flare_refire;
112 float autocvar_g_vehicle_raptor_flare_lifetime;
113 float autocvar_g_vehicle_raptor_flare_chase;
114 float autocvar_g_vehicle_raptor_flare_range;
115
116 void raptor_flare_think();
117 void raptor_flare_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force);
118 void raptor_flare_touch();
119
120 METHOD(RaptorFlare, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
121     SELFPARAM();
122     bool isPlayer = IS_PLAYER(self);
123     entity player = isPlayer ? self : self.owner;
124     entity veh = player.vehicle;
125     setself(player);
126     if (fire2)
127     if (weapon_prepareattack(true, autocvar_g_vehicle_raptor_flare_refire)) {
128         for(int i = 0; i < 3; ++i) {
129             entity _flare = spawn();
130             setmodel(_flare, MDL_VEH_RAPTOR_FLARE);
131             _flare.effects = EF_LOWPRECISION | EF_FLAME;
132             _flare.scale = 0.5;
133             setorigin(_flare, self.origin - '0 0 16');
134             _flare.movetype = MOVETYPE_TOSS;
135             _flare.gravity = 0.15;
136             _flare.velocity = 0.25 * self.velocity + (v_forward + randomvec() * 0.25)* -500;
137             _flare.think = raptor_flare_think;
138             _flare.nextthink = time;
139             _flare.owner = veh ? veh : player;
140             _flare.solid = SOLID_CORPSE;
141             _flare.takedamage = DAMAGE_YES;
142             _flare.event_damage = raptor_flare_damage;
143             _flare.health = 20;
144             _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime;
145             _flare.touch = raptor_flare_touch;
146         }
147         weapon_thinkf(WFRAME_FIRE2, 0, w_ready);
148     }
149     setself(this);
150     return true;
151 }
152
153
154 void raptor_bomblet_boom()
155 {SELFPARAM();
156     RadiusDamage (self, self.realowner, autocvar_g_vehicle_raptor_bomblet_damage,
157                                     autocvar_g_vehicle_raptor_bomblet_edgedamage,
158                                     autocvar_g_vehicle_raptor_bomblet_radius, world, world,
159                                     autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB, world);
160     remove(self);
161 }
162
163 void raptor_bomblet_touch()
164 {SELFPARAM();
165     if(other == self.owner)
166         return;
167
168     PROJECTILE_TOUCH;
169     self.think = raptor_bomblet_boom;
170     self.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay;
171 }
172
173 void raptor_bomb_burst()
174 {SELFPARAM();
175     if(self.cnt > time)
176     if(autocvar_g_vehicle_raptor_bomblet_alt)
177     {
178         self.nextthink = time;
179         traceline(self.origin, self.origin + (normalize(self.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, self);
180         if((trace_fraction == 1.0) || (vlen(self.origin - self.owner.origin) < autocvar_g_vehicle_raptor_bomblet_radius))
181         {
182             UpdateCSQCProjectile(self);
183             return;
184         }
185     }
186
187     entity bomblet;
188     float i;
189
190     Damage_DamageInfo(self.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT, 0, self);
191
192     for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i)
193     {
194         bomblet = spawn();
195         setorigin(bomblet, self.origin);
196
197         bomblet.movetype        = MOVETYPE_TOSS;
198         bomblet.touch      = raptor_bomblet_touch;
199         bomblet.think      = raptor_bomblet_boom;
200         bomblet.nextthink   = time + 5;
201         bomblet.owner      = self.owner;
202         bomblet.realowner   = self.realowner;
203         bomblet.velocity        = normalize(normalize(self.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(self.velocity);
204
205         PROJECTILE_MAKETRIGGER(bomblet);
206         CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true);
207     }
208
209     remove(self);
210 }
211
212 void raptor_bombdrop()
213 {SELFPARAM();
214     entity bomb_1, bomb_2;
215
216     bomb_1 = spawn();
217     bomb_2 = spawn();
218
219     setorigin(bomb_1, gettaginfo(self, gettagindex(self, "bombmount_left")));
220     setorigin(bomb_2, gettaginfo(self, gettagindex(self, "bombmount_right")));
221
222     bomb_1.movetype      = bomb_2.movetype   = MOVETYPE_BOUNCE;
223     bomb_1.velocity      = bomb_2.velocity   = self.velocity;
224     bomb_1.touch                = bomb_2.touch    = raptor_bomb_burst;
225     bomb_1.think                = bomb_2.think    = raptor_bomb_burst;
226     bomb_1.cnt            = bomb_2.cnt          = time + 10;
227
228     if(autocvar_g_vehicle_raptor_bomblet_alt)
229         bomb_1.nextthink = bomb_2.nextthink  = time;
230     else
231         bomb_1.nextthink = bomb_2.nextthink  = time + autocvar_g_vehicle_raptor_bomblet_time;
232
233     bomb_1.owner         = bomb_2.owner   = self;
234     bomb_1.realowner = bomb_2.realowner  = self.owner;
235     bomb_1.solid         = bomb_2.solid   = SOLID_BBOX;
236     bomb_1.gravity   = bomb_2.gravity   = 1;
237
238     PROJECTILE_MAKETRIGGER(bomb_1);
239     PROJECTILE_MAKETRIGGER(bomb_2);
240
241     CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true);
242     CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true);
243 }
244
245 void raptor_flare_touch()
246 {SELFPARAM();
247     remove(self);
248 }
249
250 void raptor_flare_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
251 {SELFPARAM();
252     self.health -= damage;
253     if(self.health <= 0)
254         remove(self);
255 }
256
257 void raptor_flare_think()
258 {SELFPARAM();
259     self.nextthink = time + 0.1;
260     entity _missile = findchainentity(enemy, self.owner);
261     while(_missile)
262     {
263         if(_missile.flags & FL_PROJECTILE)
264         if(vlen(self.origin - _missile.origin) < autocvar_g_vehicle_raptor_flare_range)
265         if(random() > autocvar_g_vehicle_raptor_flare_chase)
266             _missile.enemy = self;
267         _missile = _missile.chain;
268     }
269
270     if(self.tur_impacttime < time)
271         remove(self);
272 }
273
274 #endif
275
276 #ifdef CSQC
277
278 void RaptorCBShellfragDraw()
279 {SELFPARAM();
280     if(wasfreed(self))
281         return;
282
283     Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
284     self.move_avelocity += randomvec() * 15;
285     self.renderflags = 0;
286
287     if(self.cnt < time)
288         self.alpha = bound(0, self.nextthink - time, 1);
289
290     if(self.alpha < ALPHA_MIN_VISIBLE)
291         remove(self);
292 }
293
294 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
295 {SELFPARAM();
296     entity sfrag;
297
298     sfrag = spawn();
299     setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT);
300     setorigin(sfrag, _org);
301
302     sfrag.move_movetype = MOVETYPE_BOUNCE;
303     sfrag.gravity = 0.15;
304     sfrag.solid = SOLID_CORPSE;
305
306     sfrag.draw = RaptorCBShellfragDraw;
307
308     sfrag.move_origin = sfrag.origin = _org;
309     sfrag.move_velocity = _vel;
310     sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
311     sfrag.angles = self.move_angles = _ang;
312
313     sfrag.move_time = time;
314     sfrag.damageforcescale = 4;
315
316     sfrag.nextthink = time + 3;
317     sfrag.cnt = time + 2;
318     sfrag.alpha = 1;
319     sfrag.drawmask = MASK_NORMAL;
320 }
321
322 #endif
323
324 #endif