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