26edade48cf7c8831f294779a502b2e5e7667c05
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / porto.qc
1 #ifndef IMPLEMENTATION
2 CLASS(PortoLaunch, Weapon)
3 /* ammotype  */ ATTRIB(PortoLaunch, ammo_field, .int, ammo_none)
4 /* impulse   */ ATTRIB(PortoLaunch, impulse, int, 0)
5 /* flags     */ ATTRIB(PortoLaunch, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON);
6 /* rating    */ ATTRIB(PortoLaunch, bot_pickupbasevalue, float, 0);
7 /* color     */ ATTRIB(PortoLaunch, wpcolor, vector, '0.5 0.5 0.5');
8 /* modelname */ ATTRIB(PortoLaunch, mdl, string, "porto");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(PortoLaunch, m_model, Model, MDL_PORTO_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair, string, "gfx/crosshairporto");
13 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair_size, float, 0.6);
14 /* wepimg    */ ATTRIB(PortoLaunch, model2, string, "weaponporto");
15 /* refname   */ ATTRIB(PortoLaunch, netname, string, "porto");
16 /* wepname   */ ATTRIB(PortoLaunch, message, string, _("Port-O-Launch"));
17 ENDCLASS(PortoLaunch)
18 REGISTER_WEAPON(PORTO, NEW(PortoLaunch));
19
20 #define PORTO_SETTINGS(w_cvar,w_prop) PORTO_SETTINGS_LIST(w_cvar, w_prop, PORTO, porto)
21 #define PORTO_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22         w_cvar(id, sn, BOTH, animtime) \
23         w_cvar(id, sn, BOTH, lifetime) \
24         w_cvar(id, sn, BOTH, refire) \
25         w_cvar(id, sn, BOTH, speed) \
26         w_cvar(id, sn, NONE, secondary) \
27         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
28         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
29         w_prop(id, sn, string, weaponreplace, weaponreplace) \
30         w_prop(id, sn, float,  weaponstart, weaponstart) \
31         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
32         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
33
34 #ifdef SVQC
35 PORTO_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
36 .entity porto_current;
37 .vector porto_v_angle; // holds "held" view angles
38 .float porto_v_angle_held;
39 .vector right_vector;
40 #endif
41 #endif
42 #ifdef IMPLEMENTATION
43 #ifdef SVQC
44 #include "../../triggers/trigger/jumppads.qh"
45
46 void spawnfunc_weapon_porto(void) { weapon_defaultspawnfunc(WEP_PORTO.m_id); }
47
48 void W_Porto_Success(void)
49 {SELFPARAM();
50         if(self.realowner == world)
51         {
52                 objerror("Cannot succeed successfully: no owner\n");
53                 return;
54         }
55
56         self.realowner.porto_current = world;
57         remove(self);
58 }
59
60 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
61 void W_Porto_Fail(float failhard)
62 {SELFPARAM();
63         if(self.realowner == world)
64         {
65                 objerror("Cannot fail successfully: no owner\n");
66                 return;
67         }
68
69         // no portals here!
70         if(self.cnt < 0)
71         {
72                 Portal_ClearWithID(self.realowner, self.portal_id);
73         }
74
75         self.realowner.porto_current = world;
76
77         if(self.cnt < 0 && !failhard && self.realowner.playerid == self.playerid && self.realowner.deadflag == DEAD_NO && !(self.realowner.weapons & WEPSET_PORTO))
78         {
79                 setsize(self, '-16 -16 0', '16 16 32');
80                 setorigin(self, self.origin + trace_plane_normal);
81                 if(move_out_of_solid(self))
82                 {
83                         self.flags = FL_ITEM;
84                         self.velocity = trigger_push_calculatevelocity(self.origin, self.realowner, 128);
85                         tracetoss(self, self);
86                         if(vlen(trace_endpos - self.realowner.origin) < 128)
87                         {
88                                 W_ThrowNewWeapon(self.realowner, WEP_PORTO.m_id, 0, self.origin, self.velocity);
89                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
90                         }
91                 }
92         }
93         remove(self);
94 }
95
96 void W_Porto_Remove(entity p)
97 {SELFPARAM();
98         if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
99         {
100                 WITH(entity, self, p.porto_current, W_Porto_Fail(1));
101         }
102 }
103
104 void W_Porto_Think(void)
105 {SELFPARAM();
106         trace_plane_normal = '0 0 0';
107         if(self.realowner.playerid != self.playerid)
108                 remove(self);
109         else
110                 W_Porto_Fail(0);
111 }
112
113 void W_Porto_Touch(void)
114 {SELFPARAM();
115         vector norm;
116
117         // do not use PROJECTILE_TOUCH here
118         // FIXME but DO handle warpzones!
119
120         if(other.classname == "portal")
121                 return; // handled by the portal
122
123         norm = trace_plane_normal;
124         if(trace_ent.iscreature)
125         {
126                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN.z, MOVE_WORLDONLY, self);
127                 if(trace_fraction >= 1)
128                         return;
129                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
130                         return;
131                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
132                         return;
133         }
134
135         if(self.realowner.playerid != self.playerid)
136         {
137                 sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
138                 remove(self);
139         }
140         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
141         {
142                 spamsound(self, CH_SHOTS, SND(PORTO_BOUNCE), VOL_BASE, ATTEN_NORM);
143                 // just reflect
144                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
145                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
146         }
147         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
148         {
149                 sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
150                 W_Porto_Fail(0);
151                 if(self.cnt < 0)
152                         Portal_ClearAll_PortalsOnly(self.realowner);
153         }
154         else if(self.cnt == 0)
155         {
156                 // in-portal only
157                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
158                 {
159                         sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
160                         trace_plane_normal = norm;
161                         Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
162                         W_Porto_Success();
163                 }
164                 else
165                 {
166                         sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
167                         trace_plane_normal = norm;
168                         W_Porto_Fail(0);
169                 }
170         }
171         else if(self.cnt == 1)
172         {
173                 // out-portal only
174                 if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
175                 {
176                         sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
177                         trace_plane_normal = norm;
178                         Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
179                         W_Porto_Success();
180                 }
181                 else
182                 {
183                         sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
184                         trace_plane_normal = norm;
185                         W_Porto_Fail(0);
186                 }
187         }
188         else if(self.effects & EF_RED)
189         {
190                 self.effects += EF_BLUE - EF_RED;
191                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
192                 {
193                         sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
194                         trace_plane_normal = norm;
195                         Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
196                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
197                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
198                         CSQCProjectile(self, true, PROJECTILE_PORTO_BLUE, true); // change type
199                 }
200                 else
201                 {
202                         sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
203                         trace_plane_normal = norm;
204                         Portal_ClearAll_PortalsOnly(self.realowner);
205                         W_Porto_Fail(0);
206                 }
207         }
208         else
209         {
210                 if(self.realowner.portal_in.portal_id == self.portal_id)
211                 {
212                         if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
213                         {
214                                 sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
215                                 trace_plane_normal = norm;
216                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
217                                 W_Porto_Success();
218                         }
219                         else
220                         {
221                                 sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
222                                 Portal_ClearAll_PortalsOnly(self.realowner);
223                                 W_Porto_Fail(0);
224                         }
225                 }
226                 else
227                 {
228                         sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
229                         Portal_ClearAll_PortalsOnly(self.realowner);
230                         W_Porto_Fail(0);
231                 }
232         }
233 }
234
235 void W_Porto_Attack(float type)
236 {SELFPARAM();
237         entity gren;
238
239         W_SetupShot(self, false, 4, SND(PORTO_FIRE), CH_WEAPON_A, 0);
240         // always shoot from the eye
241         w_shotdir = v_forward;
242         w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
243
244         //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
245
246         gren = spawn();
247         gren.cnt = type;
248         gren.owner = gren.realowner = self;
249         gren.playerid = self.playerid;
250         gren.classname = "porto";
251         gren.bot_dodge = true;
252         gren.bot_dodgerating = 200;
253         gren.movetype = MOVETYPE_BOUNCEMISSILE;
254         PROJECTILE_MAKETRIGGER(gren);
255         gren.effects = EF_RED;
256         gren.scale = 4;
257         setorigin(gren, w_shotorg);
258         setsize(gren, '0 0 0', '0 0 0');
259
260         gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
261         gren.think = W_Porto_Think;
262         gren.touch = W_Porto_Touch;
263
264         if(self.items & ITEM_Strength.m_itemid)
265                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
266         else
267                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
268
269         gren.angles = vectoangles(gren.velocity);
270         gren.flags = FL_PROJECTILE;
271
272         gren.portal_id = time;
273         self.porto_current = gren;
274         gren.playerid = self.playerid;
275         fixedmakevectors(fixedvectoangles(gren.velocity));
276         gren.right_vector = v_right;
277
278         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
279
280         if(type > 0)
281                 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
282         else
283                 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
284
285         MUTATOR_CALLHOOK(EditProjectile, self, gren);
286 }
287
288                 METHOD(PortoLaunch, wr_aim, bool(entity thiswep))
289                 {
290                         SELFPARAM();
291                         self.BUTTON_ATCK = false;
292                         self.BUTTON_ATCK2 = false;
293                         if(!WEP_CVAR(porto, secondary))
294                                 if(bot_aim(WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
295                                         self.BUTTON_ATCK = true;
296
297                         return true;
298                 }
299                 METHOD(PortoLaunch, wr_config, bool(entity this))
300                 {
301                         PORTO_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
302                         return true;
303                 }
304                 METHOD(PortoLaunch, wr_think, bool(entity thiswep, bool fire1, bool fire2))
305                 {
306                         SELFPARAM();
307                         if(WEP_CVAR(porto, secondary))
308                         {
309                                 if(fire1)
310                                 if(!self.porto_current)
311                                 if(!self.porto_forbidden)
312                                 if(weapon_prepareattack(false, WEP_CVAR_PRI(porto, refire)))
313                                 {
314                                         W_Porto_Attack(0);
315                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
316                                 }
317
318                                 if(fire2)
319                                 if(!self.porto_current)
320                                 if(!self.porto_forbidden)
321                                 if(weapon_prepareattack(true, WEP_CVAR_SEC(porto, refire)))
322                                 {
323                                         W_Porto_Attack(1);
324                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
325                                 }
326                         }
327                         else
328                         {
329                                 if(self.porto_v_angle_held)
330                                 {
331                                         if(!fire2)
332                                         {
333                                                 self.porto_v_angle_held = 0;
334
335                                                 ClientData_Touch(self);
336                                         }
337                                 }
338                                 else
339                                 {
340                                         if(fire2)
341                                         {
342                                                 self.porto_v_angle = self.v_angle;
343                                                 self.porto_v_angle_held = 1;
344
345                                                 ClientData_Touch(self);
346                                         }
347                                 }
348                                 if(self.porto_v_angle_held)
349                                         makevectors(self.porto_v_angle); // override the previously set angles
350
351                                 if(fire1)
352                                 if(!self.porto_current)
353                                 if(!self.porto_forbidden)
354                                 if(weapon_prepareattack(false, WEP_CVAR_PRI(porto, refire)))
355                                 {
356                                         W_Porto_Attack(-1);
357                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
358                                 }
359                         }
360
361                         return true;
362                 }
363                 METHOD(PortoLaunch, wr_checkammo1, bool(entity this))
364                 {
365                         // always allow infinite ammo
366                         return true;
367                 }
368                 METHOD(PortoLaunch, wr_checkammo2, bool(entity this))
369                 {
370                         // always allow infinite ammo
371                         return true;
372                 }
373                 METHOD(PortoLaunch, wr_init, bool(entity this))
374                 {
375                         PORTO_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
376                         return true;
377                 }
378                 METHOD(PortoLaunch, wr_setup, bool(entity thiswep))
379                 {
380                         SELFPARAM();
381                         self.ammo_field = ammo_none;
382                         return true;
383                 }
384                 METHOD(PortoLaunch, wr_resetplayer, bool(entity thiswep))
385                 {
386                         SELFPARAM();
387                         self.porto_current = world;
388                         return true;
389                 }
390 #endif
391 #ifdef CSQC
392                 METHOD(PortoLaunch, wr_impacteffect, bool(entity this)) {
393                         LOG_WARNING("Since when does Porto send DamageInfo?\n");
394                         return true;
395                 }
396                 METHOD(PortoLaunch, wr_init, bool(entity this)) {
397                         // nothing to do
398                         return true;
399                 }
400                 METHOD(PortoLaunch, wr_zoomreticle, bool(entity this)) {
401                         // no weapon specific image for this weapon
402                         return false;
403                 }
404 #endif
405 #endif