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