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