]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/rpc.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / rpc.qc
1 #include "rpc.qh"
2
3 #ifdef SVQC
4
5 void W_RocketPropelledChainsaw_Explode(entity this, entity directhitentity)
6 {
7         this.event_damage = func_null;
8         this.takedamage = DAMAGE_NO;
9
10         RadiusDamage (this, this.realowner, WEP_CVAR_PRI(rpc, damage), WEP_CVAR_PRI(rpc, edgedamage), WEP_CVAR_PRI(rpc, radius), NULL, NULL, WEP_CVAR_PRI(rpc, force), this.projectiledeathtype, directhitentity);
11
12         delete(this);
13 }
14
15 void W_RocketPropelledChainsaw_Explode_think(entity this)
16 {
17         W_RocketPropelledChainsaw_Explode(this, NULL);
18 }
19
20 void W_RocketPropelledChainsaw_Touch (entity this, entity toucher)
21 {
22         if(WarpZone_Projectile_Touch(this, toucher))
23                 if(wasfreed(this))
24                         return;
25
26         W_RocketPropelledChainsaw_Explode(this, toucher);
27 }
28
29 void W_RocketPropelledChainsaw_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
30 {
31         if (this.health <= 0)
32                 return;
33
34         if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
35                 return; // g_projectiles_damage says to halt
36
37         this.health = this.health - damage;
38
39         if (this.health <= 0)
40                 W_PrepareExplosionByDamage(this, attacker, W_RocketPropelledChainsaw_Explode_think);
41 }
42
43 void W_RocketPropelledChainsaw_Think(entity this)
44 {
45         if(this.cnt <= time)
46         {
47                 delete(this);
48                 return;
49         }
50
51         float myspeed = vlen(this.velocity);
52         float myspeed_accel = myspeed * sys_frametime;
53         vector mydir = normalize(this.velocity);
54
55         tracebox(this.origin, this.mins, this.maxs, this.origin + mydir * (2 * myspeed_accel), MOVE_NORMAL, this);
56         if(IS_PLAYER(trace_ent))
57                 Damage (trace_ent, this, this.realowner, WEP_CVAR_PRI(rpc, damage2), this.projectiledeathtype, this.origin, normalize(this.origin - other.origin) * WEP_CVAR_PRI(rpc, force));
58
59         this.velocity = mydir * (myspeed + (WEP_CVAR_PRI(rpc, speedaccel) * sys_frametime));
60
61         UpdateCSQCProjectile(this);
62         this.nextthink = time;
63 }
64
65 void W_RocketPropelledChainsaw_Attack (Weapon thiswep, entity actor, .entity weaponentity)
66 {
67         entity missile = spawn(); //WarpZone_RefSys_SpawnSameRefSys(actor);
68         entity flash = spawn ();
69
70         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(rpc, ammo), weaponentity);
71         W_SetupShot_ProjectileSize (actor, weaponentity, '-3 -3 -3', '3 3 3', false, 5, SND_ROCKET_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(rpc, damage));
72         Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
73         PROJECTILE_MAKETRIGGER(missile);
74
75         missile.owner = missile.realowner = actor;
76         missile.bot_dodge = true;
77         missile.bot_dodgerating = WEP_CVAR_PRI(rpc, damage) * 2;
78
79         missile.takedamage = DAMAGE_YES;
80         missile.damageforcescale = WEP_CVAR_PRI(rpc, damageforcescale);
81         missile.health = WEP_CVAR_PRI(rpc, health);
82         missile.event_damage = W_RocketPropelledChainsaw_Damage;
83         missile.damagedbycontents = true;
84         IL_PUSH(g_damagedbycontents, missile);
85         set_movetype(missile, MOVETYPE_FLY);
86
87         missile.projectiledeathtype = WEP_RPC.m_id;
88         setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
89
90         setorigin(missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
91         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(rpc, speed), 0);
92
93         settouch(missile, W_RocketPropelledChainsaw_Touch);
94
95         setthink(missile, W_RocketPropelledChainsaw_Think);
96         missile.cnt = time + WEP_CVAR_PRI(rpc, lifetime);
97         missile.nextthink = time;
98         missile.flags = FL_PROJECTILE;
99         IL_PUSH(g_projectiles, missile);
100         IL_PUSH(g_bot_dodge, missile);
101
102         CSQCProjectile(missile, true, PROJECTILE_RPC, false);
103
104         setmodel(flash, MDL_RPC_MUZZLEFLASH); // precision set below
105         SUB_SetFade (flash, time, 0.1);
106         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
107         W_AttachToShotorg(actor, weaponentity, flash, '5 0 0');
108
109         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
110 }
111
112 METHOD(RocketPropelledChainsaw, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
113 {
114     PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(rpc, speed), 0, WEP_CVAR_PRI(rpc, lifetime), false);
115 }
116
117 METHOD(RocketPropelledChainsaw, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
118 {
119         if ((WEP_CVAR_SEC(rpc, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
120         {
121                 // Secondary uses it's own refire timer if refire_type is 1.
122                 actor.jump_interval = time + WEP_CVAR_SEC(rpc, refire) * W_WeaponRateFactor(actor);
123                 // Ugly hack to reuse the fire mode of the blaster.
124                 makevectors(actor.v_angle);
125                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
126                 actor.(weaponentity).m_weapon = WEP_BLASTER;
127                 W_Blaster_Attack(
128                         actor,
129                         weaponentity,
130                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
131                         WEP_CVAR_SEC(rpc, shotangle),
132                         WEP_CVAR_SEC(rpc, damage),
133                         WEP_CVAR_SEC(rpc, edgedamage),
134                         WEP_CVAR_SEC(rpc, radius),
135                         WEP_CVAR_SEC(rpc, force),
136                         WEP_CVAR_SEC(rpc, speed),
137                         WEP_CVAR_SEC(rpc, spread),
138                         WEP_CVAR_SEC(rpc, delay),
139                         WEP_CVAR_SEC(rpc, lifetime)
140                 );
141                 actor.(weaponentity).m_weapon = oldwep;
142                 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
143                         (actor.(weaponentity).wframe == WFRAME_FIRE2))
144                 {
145                         // Set secondary fire animation.
146                         vector a = '0 0 0';
147                         actor.(weaponentity).wframe = WFRAME_FIRE2;
148                         a = actor.(weaponentity).anim_fire2;
149                         a.z *= g_weaponratefactor;
150                         FOREACH_CLIENT(true, LAMBDA(
151                                 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
152                                 {
153                                         wframe_send(it, actor.(weaponentity), a, true);
154                                 }
155                         ));
156                         animdecide_setaction(actor, ANIMACTION_SHOOT, true);
157                 }
158         }
159         if (WEP_CVAR(rpc, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(rpc, ammo))
160         {
161                 // Forced reload
162                 thiswep.wr_reload(thiswep, actor, weaponentity);
163                 return;
164         }
165         if (fire & 1) // Primary attack
166         {
167                 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(rpc, refire)))
168                 {
169                         return;
170                 }
171                 W_RocketPropelledChainsaw_Attack(thiswep, actor, weaponentity);
172                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(rpc, animtime), w_ready);
173                 return;
174         }
175         if ((fire & 2) && (WEP_CVAR_SEC(rpc, refire_type) == 0)) // Secondary attack
176         {
177                 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(rpc, refire)))
178                 {
179                         return;
180                 }
181                 // ugly instagib hack to reuse the fire mode of the laser
182                 makevectors(actor.v_angle);
183                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
184                 actor.(weaponentity).m_weapon = WEP_BLASTER;
185                 W_Blaster_Attack(
186                         actor,
187                         weaponentity,
188                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
189                         WEP_CVAR_SEC(rpc, shotangle),
190                         WEP_CVAR_SEC(rpc, damage),
191                         WEP_CVAR_SEC(rpc, edgedamage),
192                         WEP_CVAR_SEC(rpc, radius),
193                         WEP_CVAR_SEC(rpc, force),
194                         WEP_CVAR_SEC(rpc, speed),
195                         WEP_CVAR_SEC(rpc, spread),
196                         WEP_CVAR_SEC(rpc, delay),
197                         WEP_CVAR_SEC(rpc, lifetime)
198                 );
199                 actor.(weaponentity).m_weapon = oldwep;
200                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(rpc, animtime), w_ready);
201         }
202 }
203
204 METHOD(RocketPropelledChainsaw, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
205 {
206         float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(rpc, ammo);
207         ammo_amount += actor.(weaponentity).(weapon_load[WEP_RPC.m_id]) >= WEP_CVAR_PRI(rpc, ammo);
208         return ammo_amount;
209 }
210
211 METHOD(RocketPropelledChainsaw, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
212 {
213         float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(rpc, ammo);
214         ammo_amount += actor.(weaponentity).(weapon_load[WEP_RPC.m_id]) >= WEP_CVAR_SEC(rpc, ammo);
215         return ammo_amount;
216 }
217
218 METHOD(RocketPropelledChainsaw, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
219 {
220     W_Reload(actor, weaponentity, WEP_CVAR_PRI(rpc, ammo), SND_RELOAD);
221 }
222
223 METHOD(RocketPropelledChainsaw, wr_suicidemessage, Notification(entity thiswep))
224 {
225     if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
226         return WEAPON_RPC_SUICIDE_SPLASH;
227     else
228         return WEAPON_RPC_SUICIDE_DIRECT;
229 }
230
231 METHOD(RocketPropelledChainsaw, wr_killmessage, Notification(entity thiswep))
232 {
233     if(w_deathtype & HITTYPE_SECONDARY)
234         return WEAPON_BLASTER_MURDER;
235     else if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
236         return WEAPON_RPC_MURDER_SPLASH;
237     else
238         return WEAPON_RPC_MURDER_DIRECT;
239 }
240
241 #endif
242
243 #ifdef CSQC
244
245 METHOD(RocketPropelledChainsaw, wr_impacteffect, void(entity thiswep, entity actor))
246 {
247     vector org2;
248     org2 = w_org + w_backoff * 12;
249     pointparticles(EFFECT_ROCKET_EXPLODE, org2, '0 0 0', 1);
250     if(!w_issilent)
251         sound(actor, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
252 }
253
254 #endif