]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/porto.qc
Merge branch 'master' into Mario/cts_respawn_clear
[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, .entity weaponentity);
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                         IL_PUSH(g_items, this);
94                         this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128);
95                         tracetoss(this, this);
96                         if(vdist(trace_endpos - this.realowner.origin, <, 128))
97                         {
98                                 .entity weaponentity = this.weaponentity_fld;
99                                 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity, weaponentity);
100                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
101                         }
102                 }
103         }
104         delete(this);
105 }
106
107 void W_Porto_Remove(entity p)
108 {
109         if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
110         {
111                 W_Porto_Fail(p.porto_current, 1);
112         }
113 }
114
115 void W_Porto_Think(entity this)
116 {
117         trace_plane_normal = '0 0 0';
118         if(this.realowner.playerid != this.playerid)
119                 delete(this);
120         else
121                 W_Porto_Fail(this, 0);
122 }
123
124 void W_Porto_Touch(entity this, entity toucher)
125 {
126         vector norm;
127
128         // do not use PROJECTILE_TOUCH here
129         // FIXME but DO handle warpzones!
130
131         if(toucher.classname == "portal")
132                 return; // handled by the portal
133
134         norm = trace_plane_normal;
135         if(trace_ent.iscreature)
136         {
137                 // TODO: why not use entity size?
138                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
139                 if(trace_fraction >= 1)
140                         return;
141                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
142                         return;
143                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
144                         return;
145         }
146
147         if(this.realowner.playerid != this.playerid)
148         {
149                 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
150                 delete(this);
151         }
152         else if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
153         {
154                 spamsound(this, CH_SHOTS, SND_PORTO_BOUNCE, VOL_BASE, ATTEN_NORM);
155                 // just reflect
156                 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
157                 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
158         }
159         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
160         {
161                 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
162                 W_Porto_Fail(this, 0);
163                 if(this.cnt < 0)
164                         Portal_ClearAll_PortalsOnly(this.realowner);
165         }
166         else if(this.cnt == 0)
167         {
168                 // in-portal only
169                 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
170                 {
171                         sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
172                         trace_plane_normal = norm;
173                         Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
174                         W_Porto_Success(this);
175                 }
176                 else
177                 {
178                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
179                         trace_plane_normal = norm;
180                         W_Porto_Fail(this, 0);
181                 }
182         }
183         else if(this.cnt == 1)
184         {
185                 // out-portal only
186                 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
187                 {
188                         sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
189                         trace_plane_normal = norm;
190                         Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
191                         W_Porto_Success(this);
192                 }
193                 else
194                 {
195                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
196                         trace_plane_normal = norm;
197                         W_Porto_Fail(this, 0);
198                 }
199         }
200         else if(this.effects & EF_RED)
201         {
202                 this.effects += EF_BLUE - EF_RED;
203                 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
204                 {
205                         sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
206                         trace_plane_normal = norm;
207                         Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
208                         this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
209                         this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
210                         CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
211                 }
212                 else
213                 {
214                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
215                         trace_plane_normal = norm;
216                         Portal_ClearAll_PortalsOnly(this.realowner);
217                         W_Porto_Fail(this, 0);
218                 }
219         }
220         else
221         {
222                 if(this.realowner.portal_in.portal_id == this.portal_id)
223                 {
224                         if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
225                         {
226                                 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
227                                 trace_plane_normal = norm;
228                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
229                                 W_Porto_Success(this);
230                         }
231                         else
232                         {
233                                 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
234                                 Portal_ClearAll_PortalsOnly(this.realowner);
235                                 W_Porto_Fail(this, 0);
236                         }
237                 }
238                 else
239                 {
240                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
241                         Portal_ClearAll_PortalsOnly(this.realowner);
242                         W_Porto_Fail(this, 0);
243                 }
244         }
245 }
246
247 void W_Porto_Attack(entity actor, .entity weaponentity, float type)
248 {
249         entity gren;
250
251         W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0);
252         // always shoot from the eye
253         w_shotdir = v_forward;
254         w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
255
256         //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
257
258         gren = new(porto);
259         gren.weaponentity_fld = weaponentity;
260         gren.cnt = type;
261         gren.owner = gren.realowner = actor;
262         gren.playerid = actor.playerid;
263         gren.bot_dodge = true;
264         gren.bot_dodgerating = 200;
265         set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
266         PROJECTILE_MAKETRIGGER(gren);
267         gren.effects = EF_RED;
268         gren.scale = 4;
269         setorigin(gren, w_shotorg);
270         setsize(gren, '0 0 0', '0 0 0');
271
272         gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
273         setthink(gren, W_Porto_Think);
274         settouch(gren, W_Porto_Touch);
275
276         if(actor.items & ITEM_Strength.m_itemid)
277                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
278         else
279                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
280
281         gren.angles = vectoangles(gren.velocity);
282         gren.flags = FL_PROJECTILE;
283         IL_PUSH(g_projectiles, gren);
284         IL_PUSH(g_bot_dodge, gren);
285
286         gren.portal_id = time;
287         actor.porto_current = gren;
288         gren.playerid = actor.playerid;
289         fixedmakevectors(fixedvectoangles(gren.velocity));
290         gren.right_vector = v_right;
291
292         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
293
294         if(type > 0)
295                 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
296         else
297                 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
298
299         MUTATOR_CALLHOOK(EditProjectile, actor, gren);
300 }
301
302 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
303 {
304     PHYS_INPUT_BUTTON_ATCK(actor) = false;
305     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
306     if(!WEP_CVAR(porto, secondary))
307         if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
308             PHYS_INPUT_BUTTON_ATCK(actor) = true;
309 }
310 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
311 {
312     if(WEP_CVAR(porto, secondary))
313     {
314         if(fire & 1)
315         if(!actor.porto_current)
316         if(!actor.porto_forbidden)
317         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
318         {
319             W_Porto_Attack(actor, weaponentity, 0);
320             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
321         }
322
323         if(fire & 2)
324         if(!actor.porto_current)
325         if(!actor.porto_forbidden)
326         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
327         {
328             W_Porto_Attack(actor, weaponentity, 1);
329             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
330         }
331     }
332     else
333     {
334         if(actor.(weaponentity).porto_v_angle_held)
335         {
336             if(!(fire & 2))
337                 actor.(weaponentity).porto_v_angle_held = 0;
338         }
339         else
340         {
341             if(fire & 2)
342             {
343                 actor.(weaponentity).porto_v_angle = actor.v_angle;
344                 actor.(weaponentity).porto_v_angle_held = 1;
345             }
346         }
347         if(actor.(weaponentity).porto_v_angle_held)
348             makevectors(actor.(weaponentity).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, .entity weaponentity))
361 {
362     // always allow infinite ammo
363     return true;
364 }
365 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity weaponentity))
366 {
367     // always allow infinite ammo
368     return true;
369 }
370 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
371 {
372     actor.porto_current = NULL;
373 }
374 #endif
375 #ifdef CSQC
376 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
377     LOG_WARN("Since when does Porto send DamageInfo?");
378 }
379 #endif
380 #endif