]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_porto.qc
prevent an exploit to create portals on noimpact
[divverent/nexuiz.git] / data / qcsrc / server / w_porto.qc
1 .float portal_id;
2 .entity porto_current;
3 .vector porto_v_angle; // holds "held" view angles
4 .float porto_v_angle_held;
5 .vector right_vector;
6
7 void W_Porto_Success (void)
8 {
9         if(self.owner == world)
10         {
11                 objerror("Cannot succeed successfully: no owner\n");
12                 return;
13         }
14
15         self.owner.porto_current = world;
16         remove(self);
17 }
18
19 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
20 void W_Porto_Fail (float failhard)
21 {
22         if(self.owner == world)
23         {
24                 objerror("Cannot fail successfully: no owner\n");
25                 return;
26         }
27
28         // no portals here!
29         Portal_ClearWithID(self.owner, self.portal_id);
30         self.owner.porto_current = world;
31
32         if(!failhard && !(self.owner.weapons & WEPBIT_PORTO))
33         {
34                 setsize (self, '-16 -16 0', '16 16 32');
35                 setorigin(self, self.origin + trace_plane_normal);
36                 if(move_out_of_solid(self))
37                 {
38                         self.flags = FL_ITEM;
39                         self.velocity = trigger_push_calculatevelocity(self.origin, self.owner, 128);
40                         tracetoss(self, self);
41                         if(vlen(trace_endpos - self.owner.origin) < 128)
42                         {
43                                 W_ThrowNewWeapon(self.owner, WEP_PORTO, 0, self.origin, self.velocity);
44                                 centerprint(self.owner, "^1Portal deployment failed.\n\n^2Catch it to try again!");
45                         }
46                 }
47         }
48         remove(self);
49 }
50
51 void W_Porto_Think (void)
52 {
53         trace_plane_normal = '0 0 0';
54         if(self.owner.playerid != self.playerid)
55                 remove(self);
56         else
57                 W_Porto_Fail(0);
58 }
59
60 void W_Porto_Touch (void)
61 {
62         vector norm;
63         float noreflect;
64
65         if(other.classname == "portal")
66                 return; // handled by the portal
67
68         noreflect = 0;
69         if(trace_ent.movetype == MOVETYPE_WALK)
70         {
71                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_z, MOVE_NORMAL, self);
72                 if(trace_fraction >= 1)
73                         return;
74                 noreflect = 1;
75         }
76
77         norm = trace_plane_normal;
78         if(self.owner.playerid != self.playerid)
79         {
80                 remove(self);
81         }
82         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
83         {
84                 if(!noreflect)
85                 {
86                         // just reflect
87                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
88                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
89                 }
90         }
91         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
92         {
93                 if(!noreflect)
94                         W_Porto_Fail(0);
95         }
96         else if(self.effects & EF_RED)
97         {
98                 self.effects += EF_BLUE - EF_RED;
99                 if(Portal_SpawnInPortalAtTrace(self.owner, self.right_vector, self.portal_id))
100                 {
101                         sound(self, CHAN_PROJECTILE, "misc/invshot.wav", VOL_BASE, ATTN_NORM);
102                         centerprint(self.owner, "^1In^7-portal created.\n");
103                         trace_plane_normal = norm;
104                         if(!noreflect)
105                         {
106                                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
107                                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
108                         }
109                 }
110                 else
111                 {
112                         trace_plane_normal = norm;
113                         W_Porto_Fail(0);
114                 }
115         }
116         else
117         {
118                 if(Portal_SpawnOutPortalAtTrace(self.owner, self.right_vector, self.portal_id))
119                 {
120                         sound(self, CHAN_PROJECTILE, "misc/invshot.wav", VOL_BASE, ATTN_NORM);
121                         centerprint(self.owner, "^4Out^7-portal created.\n");
122                         W_Porto_Success();
123                 }
124                 else
125                 {
126                         trace_plane_normal = norm;
127                         W_Porto_Fail(0);
128                 }
129         }
130
131 }
132
133 void W_Porto_Attack (void)
134 {
135         local entity gren;
136
137         if not(self.items & IT_UNLIMITED_AMMO)
138                 self.weapons = self.weapons - (self.weapons & WEPBIT_PORTO);
139         W_SetupShot (self, '0 0 0', FALSE, 4, "weapons/grenade_fire.wav");
140
141         //pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
142
143         gren = spawn ();
144         gren.owner = self;
145         gren.classname = "porto";
146         gren.bot_dodge = TRUE;
147         gren.bot_dodgerating = 200;
148         gren.movetype = MOVETYPE_BOUNCEMISSILE;
149         gren.solid = SOLID_BBOX;
150         gren.effects = EF_LOWPRECISION | EF_RED;
151         gren.scale = 4;
152         gren.modelflags = MF_GRENADE;
153         setmodel(gren, "models/grenademodel.md3"); // precision set above
154         setsize(gren, '0 0 0', '0 0 0');
155         setorigin(gren, w_shotorg);
156
157         gren.nextthink = time + cvar("g_balance_porto_primary_lifetime");
158         gren.think = W_Porto_Think;
159         gren.touch = W_Porto_Touch;
160         gren.velocity = w_shotdir * cvar("g_balance_porto_primary_speed");
161         if(self.items & IT_STRENGTH)
162                 gren.velocity = gren.velocity * cvar("g_balance_powerup_strength_force");
163         W_SetupProjectileVelocity(gren);
164
165         gren.angles = vectoangles (gren.velocity);
166         gren.flags = FL_PROJECTILE;
167
168         gren.portal_id = time;
169         self.porto_current = gren;
170         gren.playerid = self.playerid;
171         fixedmakevectors(vectoangles(gren.velocity));
172         gren.right_vector = v_right;
173
174         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
175 }
176
177 void spawnfunc_weapon_porto (void)
178 {
179         weapon_defaultspawnfunc(WEP_PORTO);
180 }
181
182 float w_porto(float req)
183 {
184         vector v_angle_save;
185
186         if (req == WR_AIM)
187         {
188                 self.BUTTON_ATCK = FALSE;
189                 self.BUTTON_ATCK2 = FALSE;
190                 if(bot_aim(cvar("g_balance_porto_primary_speed"), 0, cvar("g_balance_grenadelauncher_primary_lifetime"), FALSE))
191                         self.BUTTON_ATCK = TRUE;
192         }
193         else if (req == WR_THINK)
194         {
195                 if(self.porto_v_angle_held)
196                 {
197                         if(!self.BUTTON_ATCK2)
198                         {
199                                 msg_entity = self;
200                                 WRITESPECTATABLE_MSG_ONE({
201                                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
202                                         WriteByte(MSG_ONE, TE_CSQC_HOLDANGLES);
203                                         WriteByte(MSG_ONE, WEP_PORTO);
204                                         WriteByte(MSG_ONE, 0);
205                                 });
206                                 self.porto_v_angle_held = 0;
207                         }
208                 }
209                 else
210                 {
211                         if(self.BUTTON_ATCK2)
212                         {
213                                 self.porto_v_angle = self.v_angle;
214                                 msg_entity = self;
215                                 WRITESPECTATABLE_MSG_ONE({
216                                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
217                                         WriteByte(MSG_ONE, TE_CSQC_HOLDANGLES);
218                                         WriteByte(MSG_ONE, WEP_PORTO);
219                                         WriteByte(MSG_ONE, 1);
220                                         WriteCoord(MSG_ONE, self.v_angle_x);
221                                         WriteCoord(MSG_ONE, self.v_angle_y);
222                                 });
223                                 self.porto_v_angle_held = 1;
224                         }
225                 }
226                 v_angle_save = self.v_angle;
227                 if(self.porto_v_angle_held)
228                         makevectors(self.porto_v_angle); // override the previously set angles
229
230                 if (self.BUTTON_ATCK)
231                 if (!self.porto_current)
232                 if (!self.porto_forbidden)
233                 if (weapon_prepareattack(0, cvar("g_balance_porto_primary_refire")))
234                 {
235                         W_Porto_Attack();
236                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_porto_primary_animtime"), w_ready);
237                 }
238         }
239         else if (req == WR_PRECACHE)
240         {
241                 precache_model ("models/grenademodel.md3");
242                 precache_model ("models/weapons/g_porto.md3");
243                 precache_model ("models/weapons/v_porto.md3");
244                 precache_model ("models/weapons/w_porto.zym");
245                 precache_sound ("weapons/grenade_fire.wav");
246                 precache_model ("models/portal.md3");
247         }
248         else if (req == WR_SETUP)
249                 weapon_setup(WEP_PORTO);
250         else if (req == WR_SUICIDEMESSAGE)
251                 w_deathtypestring = "did the impossible";
252         else if (req == WR_KILLMESSAGE)
253                 w_deathtypestring = "felt # doing the impossible";
254         return TRUE;
255 };