c6d68de3b171c678d4388c878c48efbbfe1e3d2e
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_rpc.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id      */ RPC,
4 /* function      */ W_RocketPropelledChainsaw,
5 /* ammotype      */ ammo_rockets,
6 /* impulse       */ 7,
7 /* flags         */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH | WEP_FLAG_SUPERWEAPON,
8 /* rating        */ BOT_PICKUP_RATING_HIGH,
9 /* color     */ '1 1 0',
10 /* modelname */ "ok_rl",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairrocketlauncher 0.5875",
13 /* wepimg    */ "weaponrpc",
14 /* refname   */ "rpc",
15 /* wepname       */ _("Rocket Propelled Chainsaw")
16 );
17
18 #define RPC_SETTINGS(w_cvar,w_prop) RPC_SETTINGS_LIST(w_cvar, w_prop, RPC, rpc)
19 #define RPC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, NONE, ammo) \
21         w_cvar(id, sn, NONE, animtime) \
22         w_cvar(id, sn, NONE, damage) \
23         w_cvar(id, sn, NONE, damage2) \
24         w_cvar(id, sn, NONE, damageforcescale) \
25         w_cvar(id, sn, NONE, edgedamage) \
26         w_cvar(id, sn, NONE, force) \
27         w_cvar(id, sn, NONE, health) \
28         w_cvar(id, sn, NONE, lifetime) \
29         w_cvar(id, sn, NONE, radius) \
30         w_cvar(id, sn, NONE, refire) \
31         w_cvar(id, sn, NONE, speed) \
32         w_cvar(id, sn, NONE, speedaccel) \
33         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
34         w_prop(id, sn, float,  reloading_time, reload_time) \
35         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
36         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
37         w_prop(id, sn, string, weaponreplace, weaponreplace) \
38         w_prop(id, sn, float,  weaponstart, weaponstart) \
39         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
40         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
41
42 #ifdef SVQC
43 RPC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
44 #endif
45 #else
46 #ifdef SVQC
47 void spawnfunc_weapon_rpc() { weapon_defaultspawnfunc(WEP_RPC); }
48
49 void W_RocketPropelledChainsaw_Explode()
50 {
51         self.event_damage = func_null;
52         self.takedamage = DAMAGE_NO;
53
54         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);
55
56         remove (self);
57 }
58
59 void W_RocketPropelledChainsaw_Touch (void)
60 {
61         if(WarpZone_Projectile_Touch())
62                 if(wasfreed(self))
63                         return;
64
65         W_RocketPropelledChainsaw_Explode();
66 }
67
68 void W_RocketPropelledChainsaw_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
69 {
70         if (self.health <= 0)
71                 return;
72
73         if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
74                 return; // g_projectiles_damage says to halt
75
76         self.health = self.health - damage;
77
78         if (self.health <= 0)
79                 W_PrepareExplosionByDamage(attacker, W_RocketPropelledChainsaw_Explode);
80 }
81
82 void W_RocketPropelledChainsaw_Think()
83 {
84         if(self.cnt <= time)
85         {
86                 remove(self);
87                 return;
88         }
89
90         self.cnt = vlen(self.velocity);
91         self.wait = self.cnt * sys_frametime;
92         self.pos1 = normalize(self.velocity);
93
94         tracebox(self.origin, self.mins, self.maxs, self.origin + self.pos1 * (2 * self.wait), MOVE_NORMAL, self);
95         if(IS_PLAYER(trace_ent))
96                 Damage (trace_ent, self, self.realowner, WEP_CVAR(rpc, damage2), self.projectiledeathtype, self.origin, normalize(self.origin - other.origin) * WEP_CVAR(rpc, force));
97
98         self.velocity = self.pos1 * (self.cnt + (WEP_CVAR(rpc, speedaccel) * sys_frametime));
99
100         UpdateCSQCProjectile(self);
101         self.nextthink = time;
102 }
103
104 void W_RocketPropelledChainsaw_Attack (void)
105 {
106         entity missile = spawn(); //WarpZone_RefSys_SpawnSameRefSys(self);
107         entity flash = spawn ();
108
109         W_DecreaseAmmo(WEP_CVAR(rpc, ammo));
110         W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 5, "weapons/rocket_fire.wav", CH_WEAPON_A, WEP_CVAR(rpc, damage));
111         pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
112         PROJECTILE_MAKETRIGGER(missile);
113
114         missile.owner = missile.realowner = self;
115         missile.bot_dodge = TRUE;
116         missile.bot_dodgerating = WEP_CVAR(rpc, damage) * 2;
117
118         missile.takedamage = DAMAGE_YES;
119         missile.damageforcescale = WEP_CVAR(rpc, damageforcescale);
120         missile.health = WEP_CVAR(rpc, health);
121         missile.event_damage = W_RocketPropelledChainsaw_Damage;
122         missile.damagedbycontents = TRUE;
123         missile.movetype = MOVETYPE_FLY;
124
125         missile.projectiledeathtype = WEP_RPC;
126         setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
127
128         setorigin (missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
129         W_SetupProjVelocity_Basic(missile, WEP_CVAR(rpc, speed), 0);
130
131         missile.touch = W_RocketPropelledChainsaw_Touch;
132
133         missile.think = W_RocketPropelledChainsaw_Think;
134         missile.cnt = time + WEP_CVAR(rpc, lifetime);
135         missile.nextthink = time;
136         missile.flags = FL_PROJECTILE;
137
138         CSQCProjectile(missile, TRUE, PROJECTILE_RPC, FALSE);
139
140         setmodel(flash, "models/flash.md3"); // precision set below
141         SUB_SetFade (flash, time, 0.1);
142         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
143         W_AttachToShotorg(flash, '5 0 0');
144         missile.pos1 = missile.velocity;
145
146         other = missile; MUTATOR_CALLHOOK(EditProjectile);
147 }
148
149 float W_RocketPropelledChainsaw(float req)
150 {
151         float ammo_amount = FALSE;
152         switch(req)
153         {
154                 case WR_AIM:
155                 {
156                         self.BUTTON_ATCK = bot_aim(WEP_CVAR(rpc, speed), 0, WEP_CVAR(rpc, lifetime), FALSE);
157                         return TRUE;
158                 }
159                 case WR_THINK:
160                 {
161                         if(WEP_CVAR(rpc, reload_ammo) && self.clip_load < WEP_CVAR(rpc, ammo))
162                                 WEP_ACTION(self.weapon, WR_RELOAD);
163                         else
164                         {
165                                 if (self.BUTTON_ATCK)
166                                 {
167                                         if(weapon_prepareattack(0, WEP_CVAR(rpc, refire)))
168                                         {
169                                                 W_RocketPropelledChainsaw_Attack();
170                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(rpc, animtime), w_ready);
171                                         }
172                                 }
173
174                                 if (self.BUTTON_ATCK2)
175                                 {
176                                         // to-do
177                                 }
178                         }
179
180                         return TRUE;
181                 }
182                 case WR_INIT:
183                 {
184                         precache_model ("models/flash.md3");
185                         precache_model("models/weapons/h_ok_rl.iqm");
186                         precache_model("models/weapons/v_ok_rl.md3");
187                         precache_model("models/weapons/g_ok_rl.md3");
188                         precache_sound ("weapons/rocket_fire.wav");
189                         RPC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
190                         return TRUE;
191                 }
192                 case WR_CHECKAMMO1:
193                 {
194                         ammo_amount = self.WEP_AMMO(RPC) >= WEP_CVAR(rpc, ammo);
195                         ammo_amount += self.(weapon_load[WEP_RPC]) >= WEP_CVAR(rpc, ammo);
196                         return ammo_amount;
197                 }
198                 case WR_CHECKAMMO2:
199                 {
200                         return FALSE;
201                 }
202                 case WR_CONFIG:
203                 {
204                         RPC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
205                         return TRUE;
206                 }
207                 case WR_RELOAD:
208                 {
209                         W_Reload(WEP_CVAR(rpc, ammo), "weapons/reload.wav");
210                         return TRUE;
211                 }
212                 case WR_SUICIDEMESSAGE:
213                 {
214                         if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
215                                 return WEAPON_RPC_SUICIDE_SPLASH;
216                         else
217                                 return WEAPON_RPC_SUICIDE_DIRECT;
218                 }
219                 case WR_KILLMESSAGE:
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_RPC_MURDER_SPLASH;
225                         else
226                                 return WEAPON_RPC_MURDER_DIRECT;
227                 }
228         }
229
230         return FALSE;
231 }
232 #endif
233
234 #ifdef CSQC
235 float W_RocketPropelledChainsaw(float req)
236 {
237         switch(req)
238         {
239                 case WR_IMPACTEFFECT:
240                 {
241                         vector org2;
242                         org2 = w_org + w_backoff * 12;
243                         pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
244                         if(!w_issilent)
245                                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
246
247                         return TRUE;
248                 }
249                 case WR_INIT:
250                 {
251                         precache_sound("weapons/rocket_impact.wav");
252                         return TRUE;
253                 }
254                 case WR_ZOOMRETICLE:
255                 {
256                         // no weapon specific image for this weapon
257                         return FALSE;
258                 }
259         }
260
261         return FALSE;
262 }
263 #endif
264 #endif