]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/porto.qc
Add rudimentary support for surfaceparm nodamage (negates fall damage)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / porto.qc
1 #include "porto.qh"
2
3 #ifdef CSQC
4 STATIC_INIT(Porto)
5 {
6         entity e = new_pure(porto);
7         e.draw = Porto_Draw;
8         IL_PUSH(g_drawables, e);
9         e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
10 }
11
12 const int polyline_length = 16;
13 .vector polyline[polyline_length];
14 void Porto_Draw(entity this)
15 {
16         if (spectatee_status || intermission == 1 || intermission == 2 || STAT(HEALTH) <= 0 || WEP_CVAR(porto, secondary)) return;
17
18         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
19         {
20                 entity wepent = viewmodels[slot];
21
22                 if (wepent.activeweapon != WEP_PORTO) continue;
23
24                 vector pos = view_origin;
25                 vector dir = view_forward;
26                 makevectors(((autocvar_chase_active) ? warpzone_save_view_angles : view_angles));
27                 pos += v_right * -wepent.movedir.y
28                         +  v_up * wepent.movedir.z;
29
30                 if (wepent.angles_held_status)
31                 {
32                         makevectors(wepent.angles_held);
33                         dir = v_forward;
34                 }
35
36                 wepent.polyline[0] = pos;
37
38                 int portal_number = 0, portal1_idx = 1, portal_max = 2;
39                 int n = 1 + 2;  // 2 lines == 3 points
40                 for (int idx = 0; idx < n && idx < polyline_length - 1; )
41                 {
42                         traceline(pos, pos + 65536 * dir, true, this);
43                         dir = reflect(dir, trace_plane_normal);
44                         pos = trace_endpos;
45                         wepent.polyline[++idx] = pos;
46                         if ((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
47                         {
48                                 n += 1;
49                                 continue;
50                         }
51                         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
52                         {
53                                 n = max(2, idx);
54                                 break;
55                         }
56                         // check size
57                         {
58                                 vector ang = vectoangles2(trace_plane_normal, dir);
59                                 ang.x = -ang.x;
60                                 makevectors(ang);
61                                 if (!CheckWireframeBox(this, pos - 48 * v_right - 48 * v_up + 16 * v_forward, 96 * v_right, 96 * v_up, 96 * v_forward))
62                                 {
63                                         n = max(2, idx);
64                                         break;
65                                 }
66                         }
67                         portal_number += 1;
68                         if (portal_number >= portal_max) break;
69                         if (portal_number == 1) portal1_idx = idx;
70                 }
71                 for (int idx = 0; idx < n - 1; ++idx)
72                 {
73                         vector p = wepent.polyline[idx], q = wepent.polyline[idx + 1];
74                         if (idx == 0) p -= view_up * 16;  // line from player
75                         vector rgb = (idx < portal1_idx) ? '1 0 0' : '0 0 1';
76                         Draw_CylindricLine(p, q, 4, "", 1, 0, rgb, 0.5, DRAWFLAG_NORMAL, view_origin);
77                 }
78         }
79 }
80 #endif
81
82 #ifdef SVQC
83 #include <common/mapobjects/trigger/jumppads.qh>
84 #include <server/weapons/throwing.qh>
85
86 REGISTER_MUTATOR(porto_ticker, true);
87 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
88         FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
89 }
90
91 void W_Porto_Success(entity this)
92 {
93         if(this.realowner == NULL)
94         {
95                 objerror(this, "Cannot succeed successfully: no owner\n");
96                 return;
97         }
98
99         this.realowner.porto_current = NULL;
100         delete(this);
101 }
102
103 void W_Porto_Fail(entity this, float failhard)
104 {
105         if(this.realowner == NULL)
106         {
107                 objerror(this, "Cannot fail successfully: no owner\n");
108                 return;
109         }
110
111         // no portals here!
112         if(this.cnt < 0)
113         {
114                 Portal_ClearWithID(this.realowner, this.portal_id);
115         }
116
117         this.realowner.porto_current = NULL;
118
119         if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(STAT(WEAPONS, this.realowner) & WEPSET(PORTO)))
120         {
121                 setsize(this, '-16 -16 0', '16 16 32');
122                 setorigin(this, this.origin + trace_plane_normal);
123                 if(move_out_of_solid(this))
124                 {
125                         this.flags = FL_ITEM;
126                         IL_PUSH(g_items, this);
127                         this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128, this);
128                         tracetoss(this, this);
129                         if(vdist(trace_endpos - this.realowner.origin, <, 128))
130                         {
131                                 .entity weaponentity = this.weaponentity_fld;
132                                 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity, weaponentity);
133                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
134                         }
135                 }
136         }
137         delete(this);
138 }
139
140 void W_Porto_Remove(entity p)
141 {
142         if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
143         {
144                 W_Porto_Fail(p.porto_current, 1);
145         }
146 }
147
148 void W_Porto_Think(entity this)
149 {
150         trace_plane_normal = '0 0 0';
151         if(this.realowner.playerid != this.playerid)
152                 delete(this);
153         else
154                 W_Porto_Fail(this, 0);
155 }
156
157 void W_Porto_Touch(entity this, entity toucher)
158 {
159         vector norm;
160
161         // do not use PROJECTILE_TOUCH here
162         // FIXME but DO handle warpzones!
163
164         if(toucher.classname == "portal")
165                 return; // handled by the portal
166
167         norm = trace_plane_normal;
168         if(trace_ent.iscreature)
169         {
170                 // TODO: why not use entity size?
171                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
172                 if(trace_fraction >= 1)
173                         return;
174                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
175                         return;
176                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
177                         return;
178         }
179
180         if(this.realowner.playerid != this.playerid)
181         {
182                 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
183                 delete(this);
184         }
185         else if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
186         {
187                 spamsound(this, CH_SHOTS, SND_PORTO_BOUNCE, VOL_BASE, ATTEN_NORM);
188                 // just reflect
189                 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
190                 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
191         }
192         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
193         {
194                 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
195                 W_Porto_Fail(this, 0);
196                 if(this.cnt < 0)
197                         Portal_ClearAll_PortalsOnly(this.realowner);
198         }
199         else if(this.cnt == 0)
200         {
201                 // in-portal only
202                 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
203                 {
204                         sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
205                         trace_plane_normal = norm;
206                         Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
207                         W_Porto_Success(this);
208                 }
209                 else
210                 {
211                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
212                         trace_plane_normal = norm;
213                         W_Porto_Fail(this, 0);
214                 }
215         }
216         else if(this.cnt == 1)
217         {
218                 // out-portal only
219                 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
220                 {
221                         sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
222                         trace_plane_normal = norm;
223                         Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
224                         W_Porto_Success(this);
225                 }
226                 else
227                 {
228                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
229                         trace_plane_normal = norm;
230                         W_Porto_Fail(this, 0);
231                 }
232         }
233         else if(this.effects & EF_RED)
234         {
235                 this.effects += EF_BLUE - EF_RED;
236                 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
237                 {
238                         sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
239                         trace_plane_normal = norm;
240                         Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
241                         this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
242                         this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
243                         CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
244                 }
245                 else
246                 {
247                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
248                         trace_plane_normal = norm;
249                         Portal_ClearAll_PortalsOnly(this.realowner);
250                         W_Porto_Fail(this, 0);
251                 }
252         }
253         else
254         {
255                 if(this.realowner.portal_in.portal_id == this.portal_id)
256                 {
257                         if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
258                         {
259                                 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
260                                 trace_plane_normal = norm;
261                                 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
262                                 W_Porto_Success(this);
263                         }
264                         else
265                         {
266                                 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
267                                 Portal_ClearAll_PortalsOnly(this.realowner);
268                                 W_Porto_Fail(this, 0);
269                         }
270                 }
271                 else
272                 {
273                         sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
274                         Portal_ClearAll_PortalsOnly(this.realowner);
275                         W_Porto_Fail(this, 0);
276                 }
277         }
278 }
279
280 void W_Porto_Attack(Weapon thiswep, entity actor, .entity weaponentity, float type)
281 {
282         entity gren;
283
284         W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0, thiswep.m_id); // TODO: does the deathtype even need to be set here? porto can't hurt people
285         // always shoot from the eye
286         w_shotdir = v_forward;
287         w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
288
289         //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
290
291         gren = new(porto);
292         gren.weaponentity_fld = weaponentity;
293         gren.cnt = type;
294         gren.owner = gren.realowner = actor;
295         gren.playerid = actor.playerid;
296         gren.bot_dodge = true;
297         gren.bot_dodgerating = 200;
298         set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
299         PROJECTILE_MAKETRIGGER(gren);
300         gren.effects = EF_RED;
301         gren.scale = 4;
302         setorigin(gren, w_shotorg);
303         setsize(gren, '0 0 0', '0 0 0');
304
305         gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
306         setthink(gren, W_Porto_Think);
307         settouch(gren, W_Porto_Touch);
308
309         if(actor.items & ITEM_Strength.m_itemid)
310                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
311         else
312                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
313
314         gren.angles = vectoangles(gren.velocity);
315         gren.flags = FL_PROJECTILE;
316         IL_PUSH(g_projectiles, gren);
317         IL_PUSH(g_bot_dodge, gren);
318
319         gren.portal_id = time;
320         actor.porto_current = gren;
321         gren.playerid = actor.playerid;
322         fixedmakevectors(fixedvectoangles(gren.velocity));
323         gren.right_vector = v_right;
324
325         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
326
327         if(type > 0)
328                 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
329         else
330                 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
331
332         MUTATOR_CALLHOOK(EditProjectile, actor, gren);
333 }
334
335 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
336 {
337     PHYS_INPUT_BUTTON_ATCK(actor) = false;
338     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
339     if(!WEP_CVAR(porto, secondary))
340         if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
341             PHYS_INPUT_BUTTON_ATCK(actor) = true;
342 }
343 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
344 {
345     if(WEP_CVAR(porto, secondary))
346     {
347         if(fire & 1)
348         if(!actor.porto_current)
349         if(!actor.porto_forbidden)
350         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
351         {
352             W_Porto_Attack(thiswep, actor, weaponentity, 0);
353             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
354         }
355
356         if(fire & 2)
357         if(!actor.porto_current)
358         if(!actor.porto_forbidden)
359         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
360         {
361             W_Porto_Attack(thiswep, actor, weaponentity, 1);
362             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
363         }
364     }
365     else
366     {
367         if(actor.(weaponentity).porto_v_angle_held)
368         {
369             if(!(fire & 2))
370                 actor.(weaponentity).porto_v_angle_held = 0;
371         }
372         else
373         {
374             if(fire & 2)
375             {
376                 actor.(weaponentity).porto_v_angle = actor.v_angle;
377                 actor.(weaponentity).porto_v_angle_held = 1;
378             }
379         }
380         if(actor.(weaponentity).porto_v_angle_held)
381             makevectors(actor.(weaponentity).porto_v_angle); // override the previously set angles
382
383         if(fire & 1)
384         if(!actor.porto_current)
385         if(!actor.porto_forbidden)
386         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
387         {
388             W_Porto_Attack(thiswep, actor, weaponentity, -1);
389             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
390         }
391     }
392 }
393 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this, .entity weaponentity))
394 {
395     // always allow infinite ammo
396     return true;
397 }
398 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity weaponentity))
399 {
400     // always allow infinite ammo
401     return true;
402 }
403 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
404 {
405     actor.porto_current = NULL;
406 }
407 #endif
408 #ifdef CSQC
409 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
410     LOG_WARN("Since when does Porto send DamageInfo?");
411 }
412 #endif