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