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