]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/cl_impulse.qc
make the minstagib Nex a separate weapon
[divverent/nexuiz.git] / data / qcsrc / server / cl_impulse.qc
1 .vector personal_v_angle; // view angles to restore on impulse 77
2 .vector personal_velocity; // velocity to restore on impulse 77
3
4 void CopyBody(float keepvelocity);
5
6 // changes by LordHavoc on 03/30/04
7 // cleaned up dummy code
8 // dummies are now removed eventually after being gibbed (norespawn = TRUE)
9 // dummy impulse now checks sv_cheats to prevent players from overwhelming server with dummies
10 // dummies now use player code where possible
11
12 void player_anim (void);
13 void DummyThink(void)
14 {
15         self.think = DummyThink;
16         self.nextthink = time;
17         SV_PlayerPhysics();
18         PlayerPreThink();
19         //player_anim();
20         PlayerPostThink();
21 }
22
23 // from dpmod
24 void printsurfaceinfo(entity e, vector v)
25 {
26         local float surfnum, numpoints, vnum;
27         local string s;
28         local vector n;
29         surfnum = getsurfacenearpoint(e, v);
30         if (surfnum >= 0)
31         {
32                 sprint(self, "texture: ");
33                 s = getsurfacetexture(e, surfnum);
34                 sprint(self, s);
35                 sprint(self, " normal: ");
36                 n = getsurfacenormal(e, surfnum);
37                 sprint(self, vtos(n));
38                 sprint(self, " ");
39                 numpoints = getsurfacenumpoints(e, surfnum);
40                 sprint(self, ftos(numpoints));
41                 sprint(self, " verts:");
42                 vnum = 0;
43                 while (vnum < numpoints)
44                 {
45                         sprint(self, " ");
46                         n = getsurfacepoint(e, surfnum, vnum);
47                         sprint(self, vtos(n));
48                         vnum = vnum + 1;
49                 }
50                 sprint(self, " point tested: ");
51                 sprint(self, vtos(v));
52                 sprint(self, " nearest point on surface: ");
53                 n = getsurfaceclippedpoint(e, surfnum, v);
54                 sprint(self, vtos(n));
55                 sprint(self, "\n");
56         }
57 };
58
59 /*
60  * Impulse map:
61  *
62  * 0 reserved (no input)
63  * 1 to 9: weapon shortcuts
64  * 10: next weapon
65  * 11: most recently used weapon
66  * 12: previous weapon
67  * 13: best weapon
68  * 17: throw weapon
69  *
70  * 30 to 39: create waypoints
71  * 47: clear personal waypoints
72  * 48: clear team waypoints
73  * 49: turn base waypoints on/off
74  *
75  * 99: loaded
76  *
77  * 140: moving clone
78  * 141: ctf speedrun
79  * 142: fixed clone
80  * 143: emergency teleport
81  * 144: printsurfaceinfo
82  * 145: distance
83  *
84  * TODO:
85  * 200 to 209: prev weapon shortcuts
86  * 210 to 219: best weapon shortcuts
87  * 220 to 229: next weapon shortcuts
88  * 230 to 253: individual weapons (up to 24)
89  */
90
91 void ImpulseCommands (void)
92 {
93         local float imp;
94         vector start, end, enddown;
95         float i;
96         float m;
97         float good, evil, evilsurf;
98         float maxattempts;
99         vector org, delta;
100         float wep;
101         entity e;
102
103         imp = self.impulse;
104         if (!imp || gameover)
105                 return;
106         self.impulse = 0;
107
108         if (timeoutStatus == 2) //don't allow any impulses while the game is paused
109                 return;
110
111         if (imp >= 1 && imp <= 9)
112         {
113                 // weapon switching impulses
114                 if(self.deadflag == DEAD_NO)
115                         W_NextWeaponOnImpulse(imp);
116                 else
117                         self.impulse = imp; // retry in next frame
118         }
119         else if(imp >= 10 && imp <= 17)
120         {
121                 if(self.deadflag == DEAD_NO)
122                 {
123                         switch(imp)
124                         {
125                                 case 10:
126                                         W_NextWeapon ();
127                                         break;
128                                 case 11:
129                                         W_SwitchWeapon (self.cnt); // previously used
130                                         break;
131                                 case 12:
132                                         W_PreviousWeapon ();
133                                         break;
134                                 case 13:
135                                         W_SwitchWeapon (w_getbestweapon(self));
136                                         break;
137                                 case 17:
138                                         if (!g_minstagib)
139                                                 W_ThrowWeapon(W_CalculateProjectileVelocity(self.velocity, v_forward * 750), '0 0 0', TRUE);
140                                         break;
141                                 }
142                 }
143                 else
144                         self.impulse = imp; // retry in next frame
145         }
146         else if(imp >= 200 && imp <= 229)
147         {
148                 if(self.deadflag == DEAD_NO)
149                 {
150                         // custom order weapon cycling
151                         i = mod(imp, 10);
152                         m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
153                         W_CycleWeapon(self.(cvar_cl_weaponpriorities[i]), m);
154                 }
155                 else
156                         self.impulse = imp; // retry in next frame
157         }
158         else if(imp >= 230 && imp <= 253)
159         {
160                 if(self.deadflag == DEAD_NO)
161                         W_SwitchWeapon (imp - 230 + WEP_FIRST);
162                 else
163                         self.impulse = imp; // retry in next frame
164         }
165         // deploy waypoints
166         else if (imp >= 30 && imp <= 49)
167         {
168                 switch(imp)
169                 {
170                         case 30:
171                                 WaypointSprite_DeployPersonal("waypoint", self.origin);
172                                 self.personal_v_angle = self.v_angle;
173                                 self.personal_velocity = self.velocity;
174                                 sprint(self, "personal waypoint spawned at location\n");
175                                 break;
176                         case 31:
177                                 WaypointSprite_DeployPersonal("waypoint", self.cursor_trace_endpos);
178                                 self.personal_v_angle = self.v_angle;
179                                 self.personal_velocity = '0 0 0';
180                                 sprint(self, "personal waypoint spawned at crosshair\n");
181                                 break;
182                         case 32:
183                                 if(vlen(self.death_origin))
184                                 {
185                                         WaypointSprite_DeployPersonal("waypoint", self.death_origin);
186                                         self.personal_v_angle = self.v_angle;
187                                         self.personal_velocity = '0 0 0';
188                                         sprint(self, "personal waypoint spawned at death location\n");
189                                 }
190                                 break;
191                         case 33:
192                                 if(self.deadflag == DEAD_NO && teams_matter)
193                                 {
194                                         WaypointSprite_Attach("helpme", TRUE);
195                                         sprint(self, "HELP ME attached\n");
196                                 }
197                                 break;
198                         case 34:
199                                 WaypointSprite_DeployFixed("here", FALSE, self.origin);
200                                 sprint(self, "HERE spawned at location\n");
201                                 break;
202                         case 35:
203                                 WaypointSprite_DeployFixed("here", FALSE, self.cursor_trace_endpos);
204                                 sprint(self, "HERE spawned at crosshair\n");
205                                 break;
206                         case 36:
207                                 if(vlen(self.death_origin))
208                                 {
209                                         WaypointSprite_DeployFixed("here", FALSE, self.death_origin);
210                                         sprint(self, "HERE spawned at death location\n");
211                                 }
212                                 break;
213                         case 37:
214                                 WaypointSprite_DeployFixed("danger", FALSE, self.origin);
215                                 sprint(self, "DANGER spawned at location\n");
216                                 break;
217                         case 38:
218                                 WaypointSprite_DeployFixed("danger", FALSE, self.cursor_trace_endpos);
219                                 sprint(self, "DANGER spawned at crosshair\n");
220                                 break;
221                         case 39:
222                                 if(vlen(self.death_origin))
223                                 {
224                                         WaypointSprite_DeployFixed("danger", FALSE, self.death_origin);
225                                         sprint(self, "DANGER spawned at death location\n");
226                                 }
227                                 break;
228                         case 47:
229                                 WaypointSprite_ClearPersonal();
230                                 sprint(self, "personal waypoint cleared\n");
231                                 break;
232                         case 48:
233                                 WaypointSprite_ClearOwned();
234                                 sprint(self, "all waypoints cleared\n");
235                                 break;
236                         case 49:
237                                 self.cvar_cl_hidewaypoints = !(self.cvar_cl_hidewaypoints);
238                                 sprint(self, "fixed waypoints now ");
239                                 if(self.cvar_cl_hidewaypoints)
240                                         sprint(self, "OFF\n");
241                                 else
242                                         sprint(self, "ON\n");
243                                 break;
244                 }
245         }
246         else if(imp >= 140 && imp <= 149 || imp == 99) // 10 cheats ought to be enough for anyone
247         {
248                 if(sv_cheats)
249                 if(self.deadflag == DEAD_NO)
250                 {
251                         switch(imp)
252                         {
253                                 case 99:
254                                         self.weapons |= WEPBIT_ALL;
255                                         self.ammo_shells = g_pickup_shells_max;
256                                         self.ammo_nails = g_pickup_nails_max;
257                                         self.ammo_rockets = g_pickup_rockets_max;
258                                         self.ammo_cells = g_pickup_cells_max;
259                                         self.health = g_pickup_healthsmall_max;
260                                         self.armorvalue = g_pickup_armorsmall_max;
261                                         self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
262                                         self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
263                                         self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
264                                         // precache weapon models/sounds
265                                         wep = WEP_FIRST;
266                                         while (wep <= WEP_LAST)
267                                         {
268                                                 weapon_action(wep, WR_PRECACHE);
269                                                 wep = wep + 1;
270                                         }
271                                         break;
272                                 case 140:
273                                         makevectors (self.v_angle);
274                                         self.velocity = self.velocity + v_forward * 300;
275                                         CopyBody(1);
276                                         self.lip += 1;
277                                         self.velocity = self.velocity - v_forward * 300;
278                                         break;
279                                 case 141:
280                                         if(self.waypointsprite_deployed_personal)
281                                         {
282                                                 self.speedrunning = TRUE;
283                                                 tracebox(self.waypointsprite_deployed_personal.origin, self.mins, self.maxs, self.waypointsprite_deployed_personal.origin, MOVE_WORLDONLY, self);
284                                                 if(trace_startsolid)
285                                                 {
286                                                         sprint(self, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
287                                                 }
288                                                 else
289                                                 {
290                                                         // Abort speedrun, teleport back
291                                                         setorigin(self, self.waypointsprite_deployed_personal.origin);
292                                                         self.oldvelocity = self.velocity = self.personal_velocity;
293                                                         self.angles = self.personal_v_angle;
294                                                         self.fixangle = TRUE;
295                                                         if(self.flagcarried)
296                                                         {
297                                                                 bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
298                                                                 ReturnFlag(self.flagcarried);
299                                                         }
300                                                 }
301                                                 self.ammo_rockets = 999;
302                                                 self.ammo_nails = 999;
303                                                 self.ammo_cells = 999;
304                                                 self.ammo_shells = 999;
305                                                 self.health = start_health;
306                                                 self.armorvalue = start_armorvalue;
307                                                 self.weapons |= weaponsInMap;
308                                                 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
309                                                 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
310                                                 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
311                                         }
312                                         else if(self.deadflag != DEAD_NO)
313                                                 sprint(self, "UR DEAD AHAHAH))\n");
314                                         else
315                                                 sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
316                                         break;
317                                 case 142:
318                                         CopyBody(0);
319                                         self.lip += 1;
320                                         break;
321                                 case 143:
322                                         good = DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP;
323                                         evil = DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER;
324                                         evilsurf = Q3SURFACEFLAG_SKY;
325
326                                         m = self.dphitcontentsmask;
327                                         self.dphitcontentsmask = good | evil;
328
329                                         org = world.mins;
330                                         delta = world.maxs - world.mins;
331
332                                         maxattempts = ((sv_cheats >= 2) ? 100000 : 100);
333
334                                         for(i = 0; i < maxattempts; ++i)
335                                         {
336                                                 start_x = org_x + random() * delta_x;
337                                                 start_y = org_y + random() * delta_y;
338                                                 start_z = org_z + random() * delta_z;
339
340                                                 // rule 1: start inside world bounds, and outside
341                                                 // solid, and don't start from somewhere where you can
342                                                 // fall down to evil
343                                                 tracebox(start, self.mins, self.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, self);
344                                                 if(trace_fraction >= 1)
345                                                         continue;
346                                                 if(trace_startsolid)
347                                                         continue;
348                                                 dprint("hit contents ", ftos(trace_dphitcontents), "\n");
349                                                 if(trace_dphitcontents & evil)
350                                                         continue;
351                                                 if(trace_dphitq3surfaceflags & evilsurf)
352                                                         continue;
353
354                                                 // rule 2: if we are too high, lower the point
355                                                 if(trace_fraction * delta_z > 1024)
356                                                         start = trace_endpos + '0 0 1024';
357                                                 enddown = trace_endpos;
358
359                                                 // these can be traceLINES as we already verified the starting box
360                                                 traceline(start, start + '1 0 0' * delta_x, MOVE_NORMAL, self);
361                                                 if(trace_fraction >= 1)
362                                                         continue;
363                                                 traceline(start, start - '1 0 0' * delta_x, MOVE_NORMAL, self);
364                                                 if(trace_fraction >= 1)
365                                                         continue;
366                                                 traceline(start, start + '0 1 0' * delta_y, MOVE_NORMAL, self);
367                                                 if(trace_fraction >= 1)
368                                                         continue;
369                                                 traceline(start, start - '0 1 0' * delta_y, MOVE_NORMAL, self);
370                                                 if(trace_fraction >= 1)
371                                                         continue;
372                                                 traceline(start, start + '0 0 1' * delta_z, MOVE_NORMAL, self);
373                                                 if(trace_fraction >= 1)
374                                                         continue;
375
376                                                 end_x = org_x + random() * delta_x;
377                                                 end_y = org_y + random() * delta_y;
378                                                 end_z = org_z + random() * delta_z;
379                                                 end = start + normalize(end - start) * vlen(delta);
380
381                                                 // rule 3: start TO end must not be too short
382                                                 tracebox(start, self.mins, self.maxs, end, MOVE_NORMAL, self);
383                                                 if(trace_startsolid)
384                                                         continue;
385                                                 if(trace_fraction < 256 / vlen(delta))
386                                                         continue;
387
388                                                 // rule 4: don't want to look at sky
389                                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
390                                                         continue;
391
392                                                 // rule 5: we must not end up in trigger_hurt
393                                                 if(tracebox_hits_trigger_hurt(start, self.mins, self.maxs, enddown))
394                                                 {
395                                                         dprint("trigger_hurt! ouch! and nothing else could find it!\n");
396                                                         continue;
397                                                 }
398
399                                                 break;
400                                         }
401
402                                         if(i < maxattempts)
403                                         {
404                                                 self.origin = start;
405                                                 self.angles = vectoangles(end - start);
406                                                 self.angles_x = -self.angles_x;
407                                                 self.fixangle = TRUE;
408                                                 self.velocity = '0 0 0';
409                                                 dprint("Needed ", ftos(i + 1), " attempts\n");
410                                         }
411                                         else
412                                                 sprint(self, "Emergency teleport could not find a good location, forget it!\n");
413
414                                         self.dphitcontentsmask = m;
415                                         break;
416                                 case 144:
417                                         makevectors(self.v_angle);
418                                         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, FALSE, self);
419                                         if (trace_fraction < 1)
420                                                 printsurfaceinfo(trace_ent, trace_endpos);
421                                         break;
422                                 case 145:
423                                         makevectors(self.v_angle);
424                                         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 65536, FALSE, self);
425                                         sprint(self, strcat("distance: ", ftos(fabs(vlen(trace_endpos - (self.origin + self.view_ofs)))), "\n"));
426                                         break;
427                         }
428                 }
429         }
430         else if(imp >= 103 && imp <= 106)
431         {
432                 if(cvar("g_waypointeditor"))
433                 {
434                         switch(imp)
435                         {
436                                 case 103:
437                                         waypoint_schedulerelink(waypoint_spawn(self.origin, self.origin, 0));
438                                         break;
439                                 case 104:
440                                         e = navigation_findnearestwaypoint(self, FALSE);
441                                         if (e)
442                                                 waypoint_remove(e);
443                                         break;
444                                 case 105:
445                                         waypoint_schedulerelinkall();
446                                         break;
447                                 case 106:
448                                         waypoint_saveall();
449                                         break;
450                         }
451                 }
452         }
453
454         //TetrisImpulses(imp);
455 }