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