]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_porto.qc
More work on config
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_porto.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ PORTO,
4 /* function */ w_porto,
5 /* ammotype */ 0,
6 /* impulse  */ 0,
7 /* flags    */ WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON,
8 /* rating   */ 0,
9 /* model    */ "porto" ,
10 /* netname  */ "porto",
11 /* fullname */ _("Port-O-Launch")
12 );
13
14 #define PORTO_SETTINGS(weapon) \
15         WEP_ADD_CVAR(weapon, MO_BOTH, animtime) \
16         WEP_ADD_CVAR(weapon, MO_BOTH, lifetime) \
17         WEP_ADD_CVAR(weapon, MO_BOTH, refire) \
18         WEP_ADD_CVAR(weapon, MO_BOTH, speed) \
19         WEP_ADD_CVAR(weapon, MO_NONE, secondary) \
20         WEP_ADD_PROP(weapon, reloading_ammo, reload_ammo) \
21         WEP_ADD_PROP(weapon, reloading_time, reload_time) \
22         WEP_ADD_PROP(weapon, switchdelay_raise, switchdelay_raise) \
23         WEP_ADD_PROP(weapon, switchdelay_drop, switchdelay_drop)
24
25 #ifdef SVQC
26 PORTO_SETTINGS(porto)
27 void spawnfunc_weapon_porto (void) { weapon_defaultspawnfunc(WEP_PORTO); }
28
29 .entity porto_current;
30 .vector porto_v_angle; // holds "held" view angles
31 .float porto_v_angle_held;
32 .vector right_vector;
33 #endif
34 #else
35 #ifdef SVQC
36
37 void W_Porto_Success (void)
38 {
39         if(self.realowner == world)
40         {
41                 objerror("Cannot succeed successfully: no owner\n");
42                 return;
43         }
44
45         self.realowner.porto_current = world;
46         remove(self);
47 }
48
49 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
50 void W_Porto_Fail (float failhard)
51 {
52         if(self.realowner == world)
53         {
54                 objerror("Cannot fail successfully: no owner\n");
55                 return;
56         }
57
58         // no portals here!
59         if(self.cnt < 0)
60         {
61                 Portal_ClearWithID(self.realowner, self.portal_id);
62         }
63
64         self.realowner.porto_current = world;
65
66         if(self.cnt < 0 && !failhard && self.realowner.playerid == self.playerid && self.realowner.deadflag == DEAD_NO && !WEPSET_CONTAINS_EW(self.realowner, WEP_PORTO))
67         {
68                 setsize (self, '-16 -16 0', '16 16 32');
69                 setorigin(self, self.origin + trace_plane_normal);
70                 if(move_out_of_solid(self))
71                 {
72                         self.flags = FL_ITEM;
73                         self.velocity = trigger_push_calculatevelocity(self.origin, self.realowner, 128);
74                         tracetoss(self, self);
75                         if(vlen(trace_endpos - self.realowner.origin) < 128)
76                         {
77                                 W_ThrowNewWeapon(self.realowner, WEP_PORTO, 0, self.origin, self.velocity);
78                                 centerprint(self.realowner, "^1Portal deployment failed.\n\n^2Catch it to try again!");
79                         }
80                 }
81         }
82         remove(self);
83 }
84
85 void W_Porto_Remove (entity p)
86 {
87         if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
88         {
89                 entity oldself;
90                 oldself = self;
91                 self = p.porto_current;
92                 W_Porto_Fail(1);
93                 self = oldself;
94         }
95 }
96
97 void W_Porto_Think (void)
98 {
99         trace_plane_normal = '0 0 0';
100         if(self.realowner.playerid != self.playerid)
101                 remove(self);
102         else
103                 W_Porto_Fail(0);
104 }
105
106 void W_Porto_Touch (void)
107 {
108         vector norm;
109
110         // do not use PROJECTILE_TOUCH here
111         // FIXME but DO handle warpzones!
112
113         if(other.classname == "portal")
114                 return; // handled by the portal
115
116         norm = trace_plane_normal;
117         if(trace_ent.iscreature)
118         {
119                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_z, MOVE_WORLDONLY, self);
120                 if(trace_fraction >= 1)
121                         return;
122                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
123                         return;
124                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
125                         return;
126         }
127
128         if(self.realowner.playerid != self.playerid)
129         {
130                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
131                 remove(self);
132         }
133         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
134         {
135                 spamsound(self, CH_SHOTS, "porto/bounce.wav", VOL_BASE, ATTN_NORM);
136                 // just reflect
137                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
138                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
139         }
140         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
141         {
142                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
143                 W_Porto_Fail(0);
144                 if(self.cnt < 0)
145                         Portal_ClearAll_PortalsOnly(self.realowner);
146         }
147         else if(self.cnt == 0)
148         {
149                 // in-portal only
150                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
151                 {
152                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTN_NORM);
153                         trace_plane_normal = norm;
154                         centerprint(self.realowner, "^1In^7-portal created.");
155                         W_Porto_Success();
156                 }
157                 else
158                 {
159                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
160                         trace_plane_normal = norm;
161                         W_Porto_Fail(0);
162                 }
163         }
164         else if(self.cnt == 1)
165         {
166                 // out-portal only
167                 if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
168                 {
169                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTN_NORM);
170                         trace_plane_normal = norm;
171                         centerprint(self.realowner, "^4Out^7-portal created.");
172                         W_Porto_Success();
173                 }
174                 else
175                 {
176                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
177                         trace_plane_normal = norm;
178                         W_Porto_Fail(0);
179                 }
180         }
181         else if(self.effects & EF_RED)
182         {
183                 self.effects += EF_BLUE - EF_RED;
184                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
185                 {
186                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTN_NORM);
187                         trace_plane_normal = norm;
188                         centerprint(self.realowner, "^1In^7-portal created.");
189                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
190                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
191                         CSQCProjectile(self, TRUE, PROJECTILE_PORTO_BLUE, TRUE); // change type
192                 }
193                 else
194                 {
195                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
196                         trace_plane_normal = norm;
197                         Portal_ClearAll_PortalsOnly(self.realowner);
198                         W_Porto_Fail(0);
199                 }
200         }
201         else
202         {
203                 if(self.realowner.portal_in.portal_id == self.portal_id)
204                 {
205                         if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
206                         {
207                                 sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTN_NORM);
208                                 trace_plane_normal = norm;
209                                 centerprint(self.realowner, "^4Out^7-portal created.");
210                                 W_Porto_Success();
211                         }
212                         else
213                         {
214                                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
215                                 Portal_ClearAll_PortalsOnly(self.realowner);
216                                 W_Porto_Fail(0);
217                         }
218                 }
219                 else
220                 {
221                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
222                         Portal_ClearAll_PortalsOnly(self.realowner);
223                         W_Porto_Fail(0);
224                 }
225         }
226 }
227
228 void W_Porto_Attack (float type)
229 {
230         entity gren;
231
232         W_SetupShot (self, FALSE, 4, "porto/fire.wav", CH_WEAPON_A, 0);
233         // always shoot from the eye
234         w_shotdir = v_forward;
235         w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
236
237         //pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
238
239         gren = spawn ();
240         gren.cnt = type;
241         gren.owner = gren.realowner = self;
242         gren.playerid = self.playerid;
243         gren.classname = "porto";
244         gren.bot_dodge = TRUE;
245         gren.bot_dodgerating = 200;
246         gren.movetype = MOVETYPE_BOUNCEMISSILE;
247         PROJECTILE_MAKETRIGGER(gren);
248         gren.effects = EF_RED;
249         gren.scale = 4;
250         setorigin(gren, w_shotorg);
251         setsize(gren, '0 0 0', '0 0 0');
252         
253         gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
254         gren.think = W_Porto_Think;
255         gren.touch = W_Porto_Touch;
256         
257         if(self.items & IT_STRENGTH)
258                 W_SetupProjectileVelocity(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
259         else
260                 W_SetupProjectileVelocity(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
261
262         gren.angles = vectoangles (gren.velocity);
263         gren.flags = FL_PROJECTILE;
264
265         gren.portal_id = time;
266         self.porto_current = gren;
267         gren.playerid = self.playerid;
268         fixedmakevectors(fixedvectoangles(gren.velocity));
269         gren.right_vector = v_right;
270
271         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
272
273         if(type > 0)
274                 CSQCProjectile(gren, TRUE, PROJECTILE_PORTO_BLUE, TRUE);
275         else
276                 CSQCProjectile(gren, TRUE, PROJECTILE_PORTO_RED, TRUE);
277
278         other = gren; MUTATOR_CALLHOOK(EditProjectile);
279 }
280
281 float w_nexball_weapon(float req);
282 float w_porto(float req)
283 {
284         //vector v_angle_save;
285
286         if (g_nexball) { return w_nexball_weapon(req); }
287         
288         switch(req)
289         {
290                 case WR_AIM:
291                 {
292                         self.BUTTON_ATCK = FALSE;
293                         self.BUTTON_ATCK2 = FALSE;
294                         if(!WEP_CVAR(porto, secondary))
295                                 if(bot_aim(WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), FALSE))
296                                         self.BUTTON_ATCK = TRUE;
297                                         
298                         return TRUE;
299                 }
300                 case WR_CONFIG:
301                 {
302                         #define WEP_ADD_CVAR(weapon,mode,name) WEP_CONFIG_WRITE_CVARS(weapon,mode,name)
303                         #define WEP_ADD_PROP(weapon,prop,name) WEP_CONFIG_WRITE_PROPS(weapon,prop,name)
304                         PORTO_SETTINGS(porto)
305                         #undef WEP_ADD_CVAR
306                         #undef WEP_ADD_PROP
307                         return TRUE;
308                 }
309                 case WR_THINK:
310                 {
311                         if(WEP_CVAR(porto, secondary))
312                         {
313                                 if (self.BUTTON_ATCK)
314                                 if (!self.porto_current)
315                                 if (!self.porto_forbidden)
316                                 if (weapon_prepareattack(0, WEP_CVAR_PRI(porto, refire)))
317                                 {
318                                         W_Porto_Attack(0);
319                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
320                                 }
321
322                                 if (self.BUTTON_ATCK2)
323                                 if (!self.porto_current)
324                                 if (!self.porto_forbidden)
325                                 if (weapon_prepareattack(1, WEP_CVAR_SEC(porto, refire)))
326                                 {
327                                         W_Porto_Attack(1);
328                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
329                                 }
330                         }
331                         else
332                         {
333                                 if(self.porto_v_angle_held)
334                                 {
335                                         if(!self.BUTTON_ATCK2)
336                                         {
337                                                 self.porto_v_angle_held = 0;
338
339                                                 ClientData_Touch(self);
340                                         }
341                                 }
342                                 else
343                                 {
344                                         if(self.BUTTON_ATCK2)
345                                         {
346                                                 self.porto_v_angle = self.v_angle;
347                                                 self.porto_v_angle_held = 1;
348
349                                                 ClientData_Touch(self);
350                                         }
351                                 }
352                                 if(self.porto_v_angle_held)
353                                         makevectors(self.porto_v_angle); // override the previously set angles
354
355                                 if (self.BUTTON_ATCK)
356                                 if (!self.porto_current)
357                                 if (!self.porto_forbidden)
358                                 if (weapon_prepareattack(0, WEP_CVAR_PRI(porto, refire)))
359                                 {
360                                         W_Porto_Attack(-1);
361                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
362                                 }
363                         }
364                         
365                         return TRUE;
366                 }
367                 case WR_INIT:
368                 {
369                         precache_model ("models/weapons/g_porto.md3");
370                         precache_model ("models/weapons/v_porto.md3");
371                         precache_model ("models/weapons/h_porto.iqm");
372                         precache_model ("models/portal.md3");
373                         precache_sound ("porto/bounce.wav");
374                         precache_sound ("porto/create.wav");
375                         precache_sound ("porto/expire.wav");
376                         precache_sound ("porto/explode.wav");
377                         precache_sound ("porto/fire.wav");
378                         precache_sound ("porto/unsupported.wav");
379                         #define WEP_ADD_CVAR(weapon,mode,name) /*nothing*/
380                         #define WEP_ADD_PROP(weapon,prop,name) WEP_SET_PROP(WEP_PORTO,weapon,prop,name)
381                         PORTO_SETTINGS(porto)
382                         #undef WEP_ADD_CVAR
383                         #undef WEP_ADD_PROP
384                         return TRUE;
385                 }
386                 case WR_SETUP:
387                 {
388                         weapon_setup(WEP_PORTO);
389                         self.current_ammo = ammo_none;
390                         return TRUE;
391                 }
392                 case WR_RESETPLAYER:
393                 {
394                         self.porto_current = world;
395                         return TRUE;
396                 }
397         }
398         return TRUE;
399 }
400 #endif
401 #ifdef CSQC
402 float w_porto(float req)
403 {
404         switch(req)
405         {
406                 case WR_IMPACTEFFECT:
407                 {
408                         print("Since when does Porto send DamageInfo?\n");
409                         return TRUE;
410                 }
411                 case WR_INIT:
412                 {
413                         // nothing to do
414                         return TRUE;
415                 }
416         }
417         return TRUE;
418 }
419 #endif
420 #endif