]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_porto.qc
fix the same hook bug another, REAL, way :P
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_porto.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(PORTO, w_porto, 0, 0, WEP_TYPE_OTHER, 0, "porto" , "porto", _("Port-O-Launch"))
3 #else
4 #ifdef SVQC
5 .entity porto_current;
6 .vector porto_v_angle; // holds "held" view angles
7 .float porto_v_angle_held;
8 .vector right_vector;
9
10 void W_Porto_Success (void)
11 {
12         if(self.realowner == world)
13         {
14                 objerror("Cannot succeed successfully: no owner\n");
15                 return;
16         }
17
18         self.realowner.porto_current = world;
19         remove(self);
20 }
21
22 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
23 void W_Porto_Fail (float failhard)
24 {
25         if(self.realowner == world)
26         {
27                 objerror("Cannot fail successfully: no owner\n");
28                 return;
29         }
30
31         // no portals here!
32         Portal_ClearWithID(self.realowner, self.portal_id);
33         self.realowner.porto_current = world;
34
35         if(!failhard && self.realowner.playerid == self.playerid && self.realowner.deadflag == DEAD_NO && !(self.realowner.weapons & WEPBIT_PORTO))
36         {
37                 setsize (self, '-16 -16 0', '16 16 32');
38                 setorigin(self, self.origin + trace_plane_normal);
39                 if(move_out_of_solid(self))
40                 {
41                         self.flags = FL_ITEM;
42                         self.velocity = trigger_push_calculatevelocity(self.origin, self.realowner, 128);
43                         tracetoss(self, self);
44                         if(vlen(trace_endpos - self.realowner.origin) < 128)
45                         {
46                                 W_ThrowNewWeapon(self.realowner, WEP_PORTO, 0, self.origin, self.velocity);
47                                 centerprint(self.realowner, "^1Portal deployment failed.\n\n^2Catch it to try again!");
48                         }
49                 }
50         }
51         remove(self);
52 }
53
54 void W_Porto_Remove (entity p)
55 {
56         if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
57         {
58                 entity oldself;
59                 oldself = self;
60                 self = p.porto_current;
61                 W_Porto_Fail(1);
62                 self = oldself;
63         }
64 }
65
66 void W_Porto_Think (void)
67 {
68         trace_plane_normal = '0 0 0';
69         if(self.realowner.playerid != self.playerid)
70                 remove(self);
71         else
72                 W_Porto_Fail(0);
73 }
74
75 void W_Porto_Touch (void)
76 {
77         vector norm;
78
79         // do not use PROJECTILE_TOUCH here
80
81         if(other.classname == "portal")
82                 return; // handled by the portal
83
84         norm = trace_plane_normal;
85         if(trace_ent.iscreature)
86         {
87                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_z, MOVE_WORLDONLY, self);
88                 if(trace_fraction >= 1)
89                         return;
90                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
91                         return;
92                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
93                         return;
94         }
95
96         if(self.realowner.playerid != self.playerid)
97         {
98                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
99                 remove(self);
100         }
101         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
102         {
103                 spamsound(self, CH_SHOTS, "porto/bounce.wav", VOL_BASE, ATTN_NORM);
104                 // just reflect
105                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
106                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
107         }
108         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
109         {
110                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
111                 W_Porto_Fail(0);
112         }
113         else if(self.effects & EF_RED)
114         {
115                 self.effects += EF_BLUE - EF_RED;
116                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
117                 {
118                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTN_NORM);
119                         trace_plane_normal = norm;
120                         centerprint(self.realowner, "^1In^7-portal created.");
121                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
122                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
123                         CSQCProjectile(self, TRUE, PROJECTILE_PORTO_BLUE, TRUE); // change type
124                 }
125                 else
126                 {
127                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
128                         trace_plane_normal = norm;
129                         W_Porto_Fail(0);
130                 }
131         }
132         else
133         {
134                 if(self.realowner.portal_in.portal_id == self.portal_id)
135                 {
136                         if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
137                         {
138                                 sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTN_NORM);
139                                 trace_plane_normal = norm;
140                                 centerprint(self.realowner, "^4Out^7-portal created.");
141                                 W_Porto_Success();
142                         }
143                         else
144                         {
145                                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
146                                 W_Porto_Fail(0);
147                         }
148                 }
149                 else
150                 {
151                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
152                         W_Porto_Fail(0);
153                 }
154         }
155 }
156
157 void W_Porto_Attack (void)
158 {
159         local entity gren;
160
161         if not(self.items & IT_UNLIMITED_SUPERWEAPONS)
162                 self.weapons = self.weapons - (self.weapons & WEPBIT_PORTO);
163         W_SetupShot (self, FALSE, 4, "porto/fire.wav", CH_WEAPON_A, 0);
164         // always shoot from the eye
165         w_shotdir = v_forward;
166         w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
167
168         //pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
169
170         gren = spawn ();
171         gren.owner = gren.realowner = self;
172         gren.playerid = self.playerid;
173         gren.classname = "porto";
174         gren.bot_dodge = TRUE;
175         gren.bot_dodgerating = 200;
176         gren.movetype = MOVETYPE_BOUNCEMISSILE;
177         PROJECTILE_MAKETRIGGER(gren);
178         gren.effects = EF_RED;
179         gren.scale = 4;
180         setorigin(gren, w_shotorg);
181         setsize(gren, '0 0 0', '0 0 0');
182
183         gren.nextthink = time + autocvar_g_balance_porto_primary_lifetime;
184         gren.think = W_Porto_Think;
185         gren.touch = W_Porto_Touch;
186         if(self.items & IT_STRENGTH)
187                 W_SetupProjectileVelocity(gren, autocvar_g_balance_porto_primary_speed * autocvar_g_balance_powerup_strength_force, 0);
188         else
189                 W_SetupProjectileVelocity(gren, autocvar_g_balance_porto_primary_speed, 0);
190
191         gren.angles = vectoangles (gren.velocity);
192         gren.flags = FL_PROJECTILE;
193
194         gren.portal_id = time;
195         self.porto_current = gren;
196         gren.playerid = self.playerid;
197         fixedmakevectors(fixedvectoangles(gren.velocity));
198         gren.right_vector = v_right;
199
200         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
201
202         CSQCProjectile(gren, TRUE, PROJECTILE_PORTO_RED, TRUE);
203
204         other = gren; MUTATOR_CALLHOOK(EditProjectile);
205 }
206
207 void spawnfunc_weapon_porto (void)
208 {
209         weapon_defaultspawnfunc(WEP_PORTO);
210 }
211
212 float w_nexball_weapon(float req);
213 float w_porto(float req)
214 {
215         vector v_angle_save;
216
217         if (g_nexball) { return w_nexball_weapon(req); }
218         if (req == WR_AIM)
219         {
220                 self.BUTTON_ATCK = FALSE;
221                 self.BUTTON_ATCK2 = FALSE;
222                 if(bot_aim(autocvar_g_balance_porto_primary_speed, 0, autocvar_g_balance_grenadelauncher_primary_lifetime, FALSE))
223                         self.BUTTON_ATCK = TRUE;
224         }
225         else if (req == WR_THINK)
226         {
227                 if(self.porto_v_angle_held)
228                 {
229                         if(!self.BUTTON_ATCK2)
230                         {
231                                 self.porto_v_angle_held = 0;
232
233                                 ClientData_Touch(self);
234                         }
235                 }
236                 else
237                 {
238                         if(self.BUTTON_ATCK2)
239                         {
240                                 self.porto_v_angle = self.v_angle;
241                                 self.porto_v_angle_held = 1;
242
243                                 ClientData_Touch(self);
244                         }
245                 }
246                 v_angle_save = self.v_angle;
247                 if(self.porto_v_angle_held)
248                         makevectors(self.porto_v_angle); // override the previously set angles
249
250                 if (self.BUTTON_ATCK)
251                 if (!self.porto_current)
252                 if (!self.porto_forbidden)
253                 if (weapon_prepareattack(0, autocvar_g_balance_porto_primary_refire))
254                 {
255                         W_Porto_Attack();
256                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_porto_primary_animtime, w_ready);
257                 }
258         }
259         else if (req == WR_PRECACHE)
260         {
261                 precache_model ("models/weapons/g_porto.md3");
262                 precache_model ("models/weapons/v_porto.md3");
263                 precache_model ("models/weapons/h_porto.iqm");
264                 precache_model ("models/portal.md3");
265                 precache_sound ("porto/bounce.wav");
266                 precache_sound ("porto/create.wav");
267                 precache_sound ("porto/expire.wav");
268                 precache_sound ("porto/explode.wav");
269                 precache_sound ("porto/fire.wav");
270                 precache_sound ("porto/unsupported.wav");
271         }
272         else if (req == WR_SETUP)
273         {
274                 weapon_setup(WEP_PORTO);
275                 self.current_ammo = ammo_none;
276         }
277         else if (req == WR_RESETPLAYER)
278         {
279                 self.porto_current = world;
280         }
281         return TRUE;
282 };
283 #endif
284 #ifdef CSQC
285 float w_porto(float req)
286 {
287         if(req == WR_IMPACTEFFECT)
288         {
289                 print("Since when does Porto send DamageInfo?\n");
290         }
291         else if(req == WR_PRECACHE)
292         {
293                 // nothing to do
294         }
295         else if (req == WR_SUICIDEMESSAGE)
296                 w_deathtypestring = _("%s did the impossible");
297         else if (req == WR_KILLMESSAGE)
298                 w_deathtypestring = _("%s felt %s doing the impossible to him");
299         return TRUE;
300 }
301 #endif
302 #endif