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