c11ebc8a396ae3dbe041faf7d9ef682108a70c81
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / rpc.qc
1 #ifndef IMPLEMENTATION
2 CLASS(RocketPropelledChainsaw, Weapon)
3 /* ammotype  */ ATTRIB(RocketPropelledChainsaw, ammo_field, .int, ammo_rockets)
4 /* impulse   */ ATTRIB(RocketPropelledChainsaw, impulse, int, 7)
5 /* flags     */ ATTRIB(RocketPropelledChainsaw, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH | WEP_FLAG_SUPERWEAPON);
6 /* rating    */ ATTRIB(RocketPropelledChainsaw, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
7 /* color     */ ATTRIB(RocketPropelledChainsaw, wpcolor, vector, '0.5 0.5 0');
8 /* modelname */ ATTRIB(RocketPropelledChainsaw, mdl, string, "ok_rl");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(RocketPropelledChainsaw, m_model, Model, MDL_RPC_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(RocketPropelledChainsaw, w_crosshair, string, "gfx/crosshairrocketlauncher");
13 /* crosshair */ ATTRIB(RocketPropelledChainsaw, w_crosshair_size, float, 0.6);
14 /* wepimg    */ ATTRIB(RocketPropelledChainsaw, model2, string, "weaponrpc");
15 /* refname   */ ATTRIB(RocketPropelledChainsaw, netname, string, "rpc");
16 /* wepname   */ ATTRIB(RocketPropelledChainsaw, m_name, string, _("Rocket Propelled Chainsaw"));
17
18 #define X(BEGIN, P, END, class, prefix) \
19         BEGIN(class) \
20                 P(class, prefix, ammo, float, NONE) \
21                 P(class, prefix, animtime, float, NONE) \
22                 P(class, prefix, damage2, float, NONE) \
23                 P(class, prefix, damageforcescale, float, NONE) \
24                 P(class, prefix, damage, float, NONE) \
25                 P(class, prefix, edgedamage, float, NONE) \
26                 P(class, prefix, force, float, NONE) \
27                 P(class, prefix, health, float, NONE) \
28                 P(class, prefix, lifetime, float, NONE) \
29                 P(class, prefix, radius, float, NONE) \
30                 P(class, prefix, refire, float, NONE) \
31                 P(class, prefix, reload_ammo, float, NONE) \
32         P(class, prefix, reload_time, float, NONE) \
33                 P(class, prefix, speedaccel, float, NONE) \
34                 P(class, prefix, speed, float, NONE) \
35         P(class, prefix, switchdelay_drop, float, NONE) \
36         P(class, prefix, switchdelay_raise, float, NONE) \
37         P(class, prefix, weaponreplace, string, NONE) \
38         P(class, prefix, weaponstartoverride, float, NONE) \
39         P(class, prefix, weaponstart, float, NONE) \
40         P(class, prefix, weaponthrowable, float, NONE) \
41     END()
42     W_PROPS(X, RocketPropelledChainsaw, rpc)
43 #undef X
44
45 ENDCLASS(RocketPropelledChainsaw)
46 REGISTER_WEAPON(RPC, rpc, NEW(RocketPropelledChainsaw));
47
48 #endif
49 #ifdef IMPLEMENTATION
50 #ifdef SVQC
51 spawnfunc(weapon_rpc) { weapon_defaultspawnfunc(this, WEP_RPC); }
52
53 void W_RocketPropelledChainsaw_Explode()
54 {SELFPARAM();
55         self.event_damage = func_null;
56         self.takedamage = DAMAGE_NO;
57
58         RadiusDamage (self, self.realowner, WEP_CVAR(rpc, damage), WEP_CVAR(rpc, edgedamage), WEP_CVAR(rpc, radius), world, world, WEP_CVAR(rpc, force), self.projectiledeathtype, other);
59
60         remove (self);
61 }
62
63 void W_RocketPropelledChainsaw_Touch ()
64 {SELFPARAM();
65         if(WarpZone_Projectile_Touch())
66                 if(wasfreed(self))
67                         return;
68
69         W_RocketPropelledChainsaw_Explode();
70 }
71
72 void W_RocketPropelledChainsaw_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
73 {
74         if (this.health <= 0)
75                 return;
76
77         if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
78                 return; // g_projectiles_damage says to halt
79
80         this.health = this.health - damage;
81
82         if (this.health <= 0)
83                 W_PrepareExplosionByDamage(this, attacker, W_RocketPropelledChainsaw_Explode);
84 }
85
86 void W_RocketPropelledChainsaw_Think()
87 {SELFPARAM();
88         if(self.cnt <= time)
89         {
90                 remove(self);
91                 return;
92         }
93
94         self.cnt = vlen(self.velocity);
95         self.wait = self.cnt * sys_frametime;
96         self.pos1 = normalize(self.velocity);
97
98         tracebox(self.origin, self.mins, self.maxs, self.origin + self.pos1 * (2 * self.wait), MOVE_NORMAL, self);
99         if(IS_PLAYER(trace_ent))
100                 Damage (trace_ent, self, self.realowner, WEP_CVAR(rpc, damage2), self.projectiledeathtype, self.origin, normalize(self.origin - other.origin) * WEP_CVAR(rpc, force));
101
102         self.velocity = self.pos1 * (self.cnt + (WEP_CVAR(rpc, speedaccel) * sys_frametime));
103
104         UpdateCSQCProjectile(self);
105         self.nextthink = time;
106 }
107
108 void W_RocketPropelledChainsaw_Attack (Weapon thiswep)
109 {SELFPARAM();
110         entity missile = spawn(); //WarpZone_RefSys_SpawnSameRefSys(self);
111         entity flash = spawn ();
112
113         W_DecreaseAmmo(thiswep, self, WEP_CVAR(rpc, ammo));
114         W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', false, 5, SND_ROCKET_FIRE, CH_WEAPON_A, WEP_CVAR(rpc, damage));
115         Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
116         PROJECTILE_MAKETRIGGER(missile);
117
118         missile.owner = missile.realowner = self;
119         missile.bot_dodge = true;
120         missile.bot_dodgerating = WEP_CVAR(rpc, damage) * 2;
121
122         missile.takedamage = DAMAGE_YES;
123         missile.damageforcescale = WEP_CVAR(rpc, damageforcescale);
124         missile.health = WEP_CVAR(rpc, health);
125         missile.event_damage = W_RocketPropelledChainsaw_Damage;
126         missile.damagedbycontents = true;
127         missile.movetype = MOVETYPE_FLY;
128
129         missile.projectiledeathtype = WEP_RPC.m_id;
130         setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
131
132         setorigin (missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
133         W_SetupProjVelocity_Basic(missile, WEP_CVAR(rpc, speed), 0);
134
135         settouch(missile, W_RocketPropelledChainsaw_Touch);
136
137         setthink(missile, W_RocketPropelledChainsaw_Think);
138         missile.cnt = time + WEP_CVAR(rpc, lifetime);
139         missile.nextthink = time;
140         missile.flags = FL_PROJECTILE;
141
142         CSQCProjectile(missile, true, PROJECTILE_RPC, false);
143
144         setmodel(flash, MDL_RPC_MUZZLEFLASH); // precision set below
145         SUB_SetFade (flash, time, 0.1);
146         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
147         W_AttachToShotorg(self, flash, '5 0 0');
148         missile.pos1 = missile.velocity;
149
150         MUTATOR_CALLHOOK(EditProjectile, self, missile);
151 }
152
153 METHOD(RocketPropelledChainsaw, wr_aim, void(entity thiswep))
154 {
155     SELFPARAM();
156     PHYS_INPUT_BUTTON_ATCK(self) = bot_aim(self, WEP_CVAR(rpc, speed), 0, WEP_CVAR(rpc, lifetime), false);
157 }
158
159 METHOD(RocketPropelledChainsaw, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
160 {
161     if(WEP_CVAR(rpc, reload_ammo) && actor.clip_load < WEP_CVAR(rpc, ammo)) {
162         thiswep.wr_reload(thiswep, actor, weaponentity);
163     } else
164     {
165         if (fire & 1)
166         {
167             if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(rpc, refire)))
168             {
169                 W_RocketPropelledChainsaw_Attack(thiswep);
170                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(rpc, animtime), w_ready);
171             }
172         }
173
174         if (fire & 2)
175         {
176             // to-do
177         }
178     }
179 }
180
181 METHOD(RocketPropelledChainsaw, wr_checkammo1, bool(entity thiswep, entity actor))
182 {
183     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(rpc, ammo);
184     ammo_amount += actor.(weapon_load[WEP_RPC.m_id]) >= WEP_CVAR(rpc, ammo);
185     return ammo_amount;
186 }
187
188 METHOD(RocketPropelledChainsaw, wr_checkammo2, bool(entity thiswep, entity actor))
189 {
190     return false;
191 }
192
193 METHOD(RocketPropelledChainsaw, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
194 {
195     SELFPARAM();
196     W_Reload(self, WEP_CVAR(rpc, ammo), SND_RELOAD);
197 }
198
199 METHOD(RocketPropelledChainsaw, wr_suicidemessage, Notification(entity thiswep))
200 {
201     if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
202         return WEAPON_RPC_SUICIDE_SPLASH;
203     else
204         return WEAPON_RPC_SUICIDE_DIRECT;
205 }
206
207 METHOD(RocketPropelledChainsaw, wr_killmessage, Notification(entity thiswep))
208 {
209     if(w_deathtype & HITTYPE_SECONDARY)
210         return WEAPON_BLASTER_MURDER;
211     else if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
212         return WEAPON_RPC_MURDER_SPLASH;
213     else
214         return WEAPON_RPC_MURDER_DIRECT;
215 }
216
217 #endif
218
219 #ifdef CSQC
220
221 METHOD(RocketPropelledChainsaw, wr_impacteffect, void(entity thiswep))
222 {
223     SELFPARAM();
224     vector org2;
225     org2 = w_org + w_backoff * 12;
226     pointparticles(EFFECT_ROCKET_EXPLODE, org2, '0 0 0', 1);
227     if(!w_issilent)
228         sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
229 }
230
231 #endif
232 #endif