Weapons: remove useless weapon return values and implementations
[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, void(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 }
83 METHOD(RaptorCannon, wr_checkammo1, bool(RacerAttack thiswep)) {
84     SELFPARAM();
85     bool isPlayer = IS_PLAYER(self);
86     entity player = isPlayer ? self : self.owner;
87     entity veh = player.vehicle;
88     return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_raptor_cannon_cost;
89 }
90
91 float autocvar_g_vehicle_raptor_bombs_refire;
92
93 void raptor_bombdrop();
94 METHOD(RaptorBomb, wr_think, void(entity thiswep, bool fire1, bool fire2)) {
95     SELFPARAM();
96     bool isPlayer = IS_PLAYER(self);
97     entity player = isPlayer ? self : self.owner;
98     entity veh = player.vehicle;
99     setself(player);
100     if (fire2)
101     if (weapon_prepareattack(false, autocvar_g_vehicle_raptor_bombs_refire)) {
102         if (veh) setself(veh);
103         raptor_bombdrop();
104         weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
105     }
106     setself(this);
107 }
108
109 float autocvar_g_vehicle_raptor_flare_refire;
110 float autocvar_g_vehicle_raptor_flare_lifetime;
111 float autocvar_g_vehicle_raptor_flare_chase;
112 float autocvar_g_vehicle_raptor_flare_range;
113
114 void raptor_flare_think();
115 void raptor_flare_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force);
116 void raptor_flare_touch();
117
118 METHOD(RaptorFlare, wr_think, void(entity thiswep, bool fire1, bool fire2)) {
119     SELFPARAM();
120     bool isPlayer = IS_PLAYER(self);
121     entity player = isPlayer ? self : self.owner;
122     entity veh = player.vehicle;
123     setself(player);
124     if (fire2)
125     if (weapon_prepareattack(true, autocvar_g_vehicle_raptor_flare_refire)) {
126         for(int i = 0; i < 3; ++i) {
127             entity _flare = spawn();
128             setmodel(_flare, MDL_VEH_RAPTOR_FLARE);
129             _flare.effects = EF_LOWPRECISION | EF_FLAME;
130             _flare.scale = 0.5;
131             setorigin(_flare, self.origin - '0 0 16');
132             _flare.movetype = MOVETYPE_TOSS;
133             _flare.gravity = 0.15;
134             _flare.velocity = 0.25 * self.velocity + (v_forward + randomvec() * 0.25)* -500;
135             _flare.think = raptor_flare_think;
136             _flare.nextthink = time;
137             _flare.owner = veh ? veh : player;
138             _flare.solid = SOLID_CORPSE;
139             _flare.takedamage = DAMAGE_YES;
140             _flare.event_damage = raptor_flare_damage;
141             _flare.health = 20;
142             _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime;
143             _flare.touch = raptor_flare_touch;
144         }
145         weapon_thinkf(WFRAME_FIRE2, 0, w_ready);
146     }
147     setself(this);
148 }
149
150
151 void raptor_bomblet_boom()
152 {SELFPARAM();
153     RadiusDamage (self, self.realowner, autocvar_g_vehicle_raptor_bomblet_damage,
154                                     autocvar_g_vehicle_raptor_bomblet_edgedamage,
155                                     autocvar_g_vehicle_raptor_bomblet_radius, world, world,
156                                     autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB, world);
157     remove(self);
158 }
159
160 void raptor_bomblet_touch()
161 {SELFPARAM();
162     if(other == self.owner)
163         return;
164
165     PROJECTILE_TOUCH;
166     self.think = raptor_bomblet_boom;
167     self.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay;
168 }
169
170 void raptor_bomb_burst()
171 {SELFPARAM();
172     if(self.cnt > time)
173     if(autocvar_g_vehicle_raptor_bomblet_alt)
174     {
175         self.nextthink = time;
176         traceline(self.origin, self.origin + (normalize(self.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, self);
177         if((trace_fraction == 1.0) || (vlen(self.origin - self.owner.origin) < autocvar_g_vehicle_raptor_bomblet_radius))
178         {
179             UpdateCSQCProjectile(self);
180             return;
181         }
182     }
183
184     entity bomblet;
185     float i;
186
187     Damage_DamageInfo(self.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT, 0, self);
188
189     for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i)
190     {
191         bomblet = spawn();
192         setorigin(bomblet, self.origin);
193
194         bomblet.movetype        = MOVETYPE_TOSS;
195         bomblet.touch      = raptor_bomblet_touch;
196         bomblet.think      = raptor_bomblet_boom;
197         bomblet.nextthink   = time + 5;
198         bomblet.owner      = self.owner;
199         bomblet.realowner   = self.realowner;
200         bomblet.velocity        = normalize(normalize(self.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(self.velocity);
201
202         PROJECTILE_MAKETRIGGER(bomblet);
203         CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true);
204     }
205
206     remove(self);
207 }
208
209 void raptor_bombdrop()
210 {SELFPARAM();
211     entity bomb_1, bomb_2;
212
213     bomb_1 = spawn();
214     bomb_2 = spawn();
215
216     setorigin(bomb_1, gettaginfo(self, gettagindex(self, "bombmount_left")));
217     setorigin(bomb_2, gettaginfo(self, gettagindex(self, "bombmount_right")));
218
219     bomb_1.movetype      = bomb_2.movetype   = MOVETYPE_BOUNCE;
220     bomb_1.velocity      = bomb_2.velocity   = self.velocity;
221     bomb_1.touch                = bomb_2.touch    = raptor_bomb_burst;
222     bomb_1.think                = bomb_2.think    = raptor_bomb_burst;
223     bomb_1.cnt            = bomb_2.cnt          = time + 10;
224
225     if(autocvar_g_vehicle_raptor_bomblet_alt)
226         bomb_1.nextthink = bomb_2.nextthink  = time;
227     else
228         bomb_1.nextthink = bomb_2.nextthink  = time + autocvar_g_vehicle_raptor_bomblet_time;
229
230     bomb_1.owner         = bomb_2.owner   = self;
231     bomb_1.realowner = bomb_2.realowner  = self.owner;
232     bomb_1.solid         = bomb_2.solid   = SOLID_BBOX;
233     bomb_1.gravity   = bomb_2.gravity   = 1;
234
235     PROJECTILE_MAKETRIGGER(bomb_1);
236     PROJECTILE_MAKETRIGGER(bomb_2);
237
238     CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true);
239     CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true);
240 }
241
242 void raptor_flare_touch()
243 {SELFPARAM();
244     remove(self);
245 }
246
247 void raptor_flare_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
248 {SELFPARAM();
249     self.health -= damage;
250     if(self.health <= 0)
251         remove(self);
252 }
253
254 void raptor_flare_think()
255 {SELFPARAM();
256     self.nextthink = time + 0.1;
257     entity _missile = findchainentity(enemy, self.owner);
258     while(_missile)
259     {
260         if(_missile.flags & FL_PROJECTILE)
261         if(vlen(self.origin - _missile.origin) < autocvar_g_vehicle_raptor_flare_range)
262         if(random() > autocvar_g_vehicle_raptor_flare_chase)
263             _missile.enemy = self;
264         _missile = _missile.chain;
265     }
266
267     if(self.tur_impacttime < time)
268         remove(self);
269 }
270
271 #endif
272
273 #ifdef CSQC
274
275 void RaptorCBShellfragDraw()
276 {SELFPARAM();
277     if(wasfreed(self))
278         return;
279
280     Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
281     self.move_avelocity += randomvec() * 15;
282     self.renderflags = 0;
283
284     if(self.cnt < time)
285         self.alpha = bound(0, self.nextthink - time, 1);
286
287     if(self.alpha < ALPHA_MIN_VISIBLE)
288         remove(self);
289 }
290
291 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
292 {SELFPARAM();
293     entity sfrag;
294
295     sfrag = spawn();
296     setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT);
297     setorigin(sfrag, _org);
298
299     sfrag.move_movetype = MOVETYPE_BOUNCE;
300     sfrag.gravity = 0.15;
301     sfrag.solid = SOLID_CORPSE;
302
303     sfrag.draw = RaptorCBShellfragDraw;
304
305     sfrag.move_origin = sfrag.origin = _org;
306     sfrag.move_velocity = _vel;
307     sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
308     sfrag.angles = self.move_angles = _ang;
309
310     sfrag.move_time = time;
311     sfrag.damageforcescale = 4;
312
313     sfrag.nextthink = time + 3;
314     sfrag.cnt = time + 2;
315     sfrag.alpha = 1;
316     sfrag.drawmask = MASK_NORMAL;
317 }
318
319 #endif
320
321 #endif