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