04f78c4f9fdbe0770b3efd146701626080b06fa3
[divverent/nexuiz.git] / data / qcsrc / server / cheats.qc
1 void CopyBody(float keepvelocity);
2
3 .float maycheat;
4 float sv_cheats;
5 float autocvar_sv_cheats;
6
7 #define CHIMPULSE_SPEEDRUN_INIT 30
8 #define CHIMPULSE_GIVE_ALL 99
9 #define CHIMPULSE_CLONE_MOVING 140
10 #define CHIMPULSE_SPEEDRUN 141
11 #define CHIMPULSE_CLONE_STANDING 142
12 #define CHIMPULSE_TELEPORT 143
13 #define CHIMPULSE_R00T 148
14
15 float CheatsAllowed(float i, float argc) // the cheat gets passed as argument for possible future ACL checking
16 {
17         if(i == CHIMPULSE_CLONE_MOVING || i == CHIMPULSE_CLONE_STANDING)
18                 if(self.lip < sv_clones)
19                         return 1;
20         if(self.maycheat)
21                 return 1;
22         if(sv_cheats && autocvar_sv_cheats)
23                 return 1;
24         if(autocvar_sv_cheats)
25                 sprint(self, "Cheats are not yet allowed, and will be activated at next map change.\n");
26         return 0;
27 }
28
29 float CheatImpulse(float i)
30 {
31         if not(CheatsAllowed(i, 0))
32                 return 0;
33         switch(i)
34         {
35                 float wep;
36                 entity e, e2;
37                 vector org;
38
39                 case CHIMPULSE_SPEEDRUN_INIT: // deploy personal waypoint
40                         if(!self.personal)
41                         {
42                                 self.personal = spawn();
43                                 self.personal.classname = "personal_wp";
44                         }
45                         self.personal.origin = self.origin;
46                         self.personal.v_angle = self.v_angle;
47                         self.personal.velocity = self.velocity;
48                         self.personal.ammo_rockets = self.ammo_rockets;
49                         self.personal.ammo_nails = self.ammo_nails;
50                         self.personal.ammo_cells = self.ammo_cells;
51                         self.personal.ammo_shells = self.ammo_shells;
52                         self.personal.ammo_fuel = self.ammo_fuel;
53                         self.personal.health = self.health;
54                         self.personal.armorvalue = self.armorvalue;
55                         self.personal.weapons = self.weapons;
56                         self.personal.items = self.items;
57                         self.personal.pauserotarmor_finished = self.pauserotarmor_finished;
58                         self.personal.pauserothealth_finished = self.pauserothealth_finished;
59                         self.personal.pauserotfuel_finished = self.pauserotfuel_finished;
60                         self.personal.pauseregen_finished = self.pauseregen_finished;
61                         self.personal.strength_finished = self.strength_finished;
62                         self.personal.invincible_finished = self.invincible_finished;
63                         self.personal.teleport_time = time;
64                         return 1;
65                 case CHIMPULSE_CLONE_MOVING:
66                         makevectors (self.v_angle);
67                         self.velocity = self.velocity + v_forward * 300;
68                         CopyBody(1);
69                         self.lip += 1;
70                         self.velocity = self.velocity - v_forward * 300;
71                         return 1;
72                 case CHIMPULSE_CLONE_STANDING:
73                         CopyBody(0);
74                         self.lip += 1;
75                         return 1;
76                 case CHIMPULSE_GIVE_ALL:
77                         self.weapons |= WEPBIT_ALL;
78                         self.items |= IT_UNLIMITED_AMMO;
79                         self.ammo_shells = g_pickup_shells_max;
80                         self.ammo_nails = g_pickup_nails_max;
81                         self.ammo_rockets = g_pickup_rockets_max;
82                         self.ammo_cells = g_pickup_cells_max;
83                         self.ammo_fuel = g_pickup_fuel_max;
84                         self.health = g_pickup_healthsmall_max;
85                         self.armorvalue = g_pickup_armorsmall_max;
86                         self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
87                         self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
88                         self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
89                         self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
90                         // precache weapon models/sounds
91                         wep = WEP_FIRST;
92                         while (wep <= WEP_LAST)
93                         {
94                                 weapon_action(wep, WR_PRECACHE);
95                                 wep = wep + 1;
96                         }
97                         return 1;
98                 case CHIMPULSE_SPEEDRUN:
99                         if(self.personal)
100                         {
101                                 self.speedrunning = TRUE;
102                                 tracebox(self.personal.origin, self.mins, self.maxs, self.personal.origin, MOVE_WORLDONLY, self);
103                                 if(trace_startsolid)
104                                 {
105                                         sprint(self, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
106                                 }
107                                 else
108                                 {
109                                         // Abort speedrun, teleport back
110                                         setorigin(self, self.personal.origin);
111                                         self.oldvelocity = self.velocity = self.personal.velocity;
112                                         self.angles = self.personal.v_angle;
113                                         self.fixangle = TRUE;
114                                         if(self.flagcarried)
115                                         {
116                                                 bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
117                                                 ReturnFlag(self.flagcarried);
118                                         }
119                                 }
120                                 if(g_ctf)
121                                 {
122                                         self.ammo_rockets = 999;
123                                         self.ammo_nails = 999;
124                                         self.ammo_cells = 999;
125                                         self.ammo_shells = 999;
126                                         self.ammo_fuel = 999;
127                                         self.health = start_health;
128                                         self.armorvalue = start_armorvalue;
129                                         self.weapons |= weaponsInMap;
130                                         self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
131                                         self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
132                                         self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
133                                         self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
134                                         self.strength_finished = 0;
135                                         self.invincible_finished = 0;
136                                 }
137                                 else
138                                 {
139                                         self.ammo_rockets = self.personal.ammo_rockets;
140                                         self.ammo_nails = self.personal.ammo_nails;
141                                         self.ammo_cells = self.personal.ammo_cells;
142                                         self.ammo_shells = self.personal.ammo_shells;
143                                         self.ammo_fuel = self.personal.ammo_fuel;
144                                         self.health = self.personal.health;
145                                         self.armorvalue = self.personal.armorvalue;
146                                         self.weapons = self.personal.weapons;
147                                         self.items = self.personal.items;
148                                         self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
149                                         self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
150                                         self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
151                                         self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
152                                         self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
153                                         self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
154                                 }
155                                 return 1;
156                         }
157                         else if(self.deadflag != DEAD_NO)
158                                 sprint(self, "UR DEAD AHAHAH))\n");
159                         else
160                                 sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
161                         break;
162                 case CHIMPULSE_TELEPORT:
163                         if(MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, ((sv_cheats >= 2) ? 100000 : 100), 1024, 256))
164                         {
165                                 self.angles_x = -self.angles_x;
166                                 self.fixangle = TRUE;
167                                 self.velocity = '0 0 0';
168                                 return 1;
169                         }
170                         else
171                                 sprint(self, "Emergency teleport could not find a good location, forget it!\n");
172                         break;
173                 case CHIMPULSE_R00T:
174                         FOR_EACH_PLAYER(e)
175                         {
176                                 if( e.playermodel == "models/player/jeandarc.zym"
177                                                 ||  e.playermodel == "models/player/pyria.zym"
178                                                 ||  e.playermodel == "models/player/skadi.zym"
179                                                 || (e.playermodel == "models/player/specop.zym" && random() < 0.5) // you never know
180                                                 ||  e.playermodel == "models/player/visitant.zym")
181                                 {
182                                         makevectors(e.angles);
183                                         traceline(e.origin, e.origin + v_right * 256, MOVE_NORMAL, e);
184                                 }
185                                 else
186                                 {
187                                         org_x = random();
188                                         org_y = random();
189                                         org_z = 0;
190                                         org = normalize(org);
191                                         traceline(e.origin, e.origin + org * 256, MOVE_NORMAL, e); // random direction
192                                 }
193
194                                 org = findbetterlocation(trace_endpos, 12);
195
196                                 e2 = spawn();
197                                 setorigin(e2, org);
198                                 pointparticles(particleeffectnum("rocket_explode"), org, '0 0 0', 1);
199                                 sound(e2, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
200                                 RadiusDamage(e2, e, 1000, 0, 128, e, 500, DEATH_CHEAT, world);
201                                 remove(e2);
202                         }
203                         print("404 Sportsmanship not found.\n");
204                         return 1;
205         }
206         return 0;
207 }
208
209 float CheatCommand(float argc)
210 {
211         if not(CheatsAllowed(0, argc))
212                 return 0;
213         string cmd;
214         cmd = argv(0);
215         switch(cmd)
216         {
217                 entity e;
218                 float effectnum, f;
219                 vector start, end;
220                 entity oldself;
221
222                 case "pointparticles":
223                         if(argc == 5)
224                         {
225                                 // arguments:
226                                 //   effectname
227                                 //   origin (0..1, on crosshair line)
228                                 //   velocity
229                                 //   howmany
230                                 effectnum = particleeffectnum(argv(1));
231                                 f = stof(argv(2));
232                                 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
233                                 end = stov(argv(3));
234                                 f = stof(argv(4));
235                                 pointparticles(effectnum, start, end, f);
236                                 return 1;
237                         }
238                         sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
239                         break;
240                 case "trailparticles":
241                         if(argc == 2)
242                         {
243                                 // arguments:
244                                 //   effectname
245                                 effectnum = particleeffectnum(argv(1));
246                                 W_SetupShot(self, FALSE, FALSE, "",0);
247                                 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
248                                 trailparticles(self, effectnum, w_shotorg, trace_endpos);
249                                 return 1;
250                         }
251                         sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
252                         break;
253                 case "make":
254                         if(argc == 3)
255                         {
256                                 // arguments:
257                                 //   modelname mode
258                                 f = stof(argv(2));
259                                 W_SetupShot(self, FALSE, FALSE, "", 0);
260                                 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
261                                 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
262                                 {
263                                         sprint(self, "cannot make stuff there (bad surface)\n");
264                                 }
265                                 else
266                                 {
267                                         e = spawn();
268                                         e.model = strzone(argv(1));
269                                         e.mdl = "rocket_explode";
270                                         e.health = 1000;
271                                         setorigin(e, trace_endpos);
272                                         e.effects = EF_NOMODELFLAGS;
273                                         if(f == 1)
274                                         {
275                                                 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
276                                                 e.angles = AnglesTransform_Multiply(e.angles, '-90 0 0'); // so unrotated models work
277                                         }
278                                         oldself = self;
279                                         self = e;
280                                         spawnfunc_func_breakable();
281                                         self = oldself;
282                                         // now, is it valid?
283                                         if(f == 0)
284                                         {
285                                                 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
286                                                 if(trace_startsolid)
287                                                 {
288                                                         remove(e);
289                                                         sprint(self, "cannot make stuff there (no space)\n");
290                                                 }
291                                                 else
292                                                         return 1;
293                                         }
294                                         else
295                                                 return 1;
296                                 }
297                         }
298                         else
299                                 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
300                         break;
301                 case "penalty":
302                         if(argc == 3)
303                         {
304                                 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
305                                 return 1;
306                         }
307                         sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
308                         break;
309                 case "dragbox_spawn":
310                         e = spawn();
311                         e.classname = "dragbox_box";
312                         e.think = DragBox_Think;
313                         e.nextthink = time;
314                         e.solid = -1; // black
315                         setmodel(e, "null"); // network it
316                         if(argc == 4)
317                                 e.cnt = stof(argv(1));
318                         else
319                                 e.cnt = max(0, drag_lastcnt);
320
321                         e.aiment = spawn();
322                         e.aiment.classname = "dragbox_corner_1";
323                         e.aiment.owner = e;
324                         setmodel(e.aiment, "models/marker.md3");
325                         e.aiment.skin = 0;
326                         setsize(e.aiment, '0 0 0', '0 0 0');
327                         if(argc == 4)
328                                 setorigin(e.aiment, stov(argv(2)));
329                         else
330                                 setorigin(e.aiment, self.cursor_trace_endpos);
331
332                         e.enemy = spawn();
333                         e.enemy.classname = "dragbox_corner_2";
334                         e.enemy.owner = e;
335                         setmodel(e.enemy, "models/marker.md3");
336                         e.enemy.skin = 1;
337                         setsize(e.enemy, '0 0 0', '0 0 0');
338                         end = normalize(self.cursor_trace_start - e.aiment.origin);
339                         end_x = (end_x > 0) * 2 - 1;
340                         end_y = (end_y > 0) * 2 - 1;
341                         end_z = (end_z > 0) * 2 - 1;
342                         if(argc == 4)
343                                 setorigin(e.enemy, stov(argv(3)));
344                         else
345                                 setorigin(e.enemy, e.aiment.origin + 32 * end);
346
347                         e.killindicator = spawn();
348                         e.killindicator.classname = "drag_digit";
349                         e.killindicator.owner = e;
350                         setattachment(e.killindicator, e, "");
351                         setorigin(e.killindicator, '0 0 -8');
352                         e.killindicator.killindicator = spawn();
353                         e.killindicator.killindicator.classname = "drag_digit";
354                         e.killindicator.killindicator.owner = e;
355                         setattachment(e.killindicator.killindicator, e, "");
356                         setorigin(e.killindicator.killindicator, '0 0 8');
357                         return 1;
358                 case "dragpoint_spawn":
359                         e = spawn();
360                         e.classname = "dragpoint";
361                         e.think = DragBox_Think;
362                         e.nextthink = time;
363                         e.solid = 0; // nothing special
364                         setmodel(e, "models/marker.md3");
365                         setsize(e, PL_MIN, PL_MAX);
366                         e.skin = 2;
367                         if(argc == 3)
368                                 e.cnt = stof(argv(1));
369                         else
370                                 e.cnt = drag_lastcnt;
371                         if(argc == 3)
372                                 setorigin(e, stov(argv(2)));
373                         else
374                         {
375                                 setorigin(e, self.cursor_trace_endpos + normalize(self.cursor_trace_start - self.cursor_trace_endpos));
376                                 move_out_of_solid(e);
377                         }
378
379                         e.killindicator = spawn();
380                         e.killindicator.classname = "drag_digit";
381                         e.killindicator.owner = e;
382                         setattachment(e.killindicator, e, "");
383                         setorigin(e.killindicator, '0 0 40');
384                         e.killindicator.killindicator = spawn();
385                         e.killindicator.killindicator.classname = "drag_digit";
386                         e.killindicator.killindicator.owner = e;
387                         setattachment(e.killindicator.killindicator, e, "");
388                         setorigin(e.killindicator.killindicator, '0 0 56');
389                         return 1;
390                 case "drag_remove":
391                         RandomSelection_Init();
392                         for(e = world; (e = find(e, classname, "dragbox_box")); )
393                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
394                         for(e = world; (e = find(e, classname, "dragpoint")); )
395                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
396                         if(RandomSelection_chosen_ent)
397                         {
398                                 remove(RandomSelection_chosen_ent.killindicator.killindicator);
399                                 remove(RandomSelection_chosen_ent.killindicator);
400                                 if(RandomSelection_chosen_ent.aiment)
401                                         remove(RandomSelection_chosen_ent.aiment);
402                                 if(RandomSelection_chosen_ent.enemy)
403                                         remove(RandomSelection_chosen_ent.enemy);
404                                 remove(RandomSelection_chosen_ent);
405                         }
406                         return 1;
407                 case "drag_setcnt":
408                         if(argc == 2)
409                         {
410                                 RandomSelection_Init();
411                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
412                                         RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
413                                 for(e = world; (e = find(e, classname, "dragpoint")); )
414                                         RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
415                                 if(RandomSelection_chosen_ent)
416                                 {
417                                         if(substring(argv(1), 0, 1) == "*")
418                                                 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
419                                         else
420                                                 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
421                                 }
422                                 return 1;
423                         }
424                         else
425                                 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
426                         break;
427                 case "drag_save":
428                         if(argc == 2)
429                         {
430                                 f = fopen(argv(1), FILE_WRITE);
431                                 fputs(f, "cmd drag_clear\n");
432                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
433                                 {
434                                         fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
435                                 }
436                                 for(e = world; (e = find(e, classname, "dragpoint")); )
437                                 {
438                                         fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
439                                 }
440                                 fclose(f);
441                                 return 1;
442                         }
443                         else
444                                 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
445                         break;
446                 case "drag_saveraceent":
447                         if(argc == 2)
448                         {
449                                 f = fopen(argv(1), FILE_WRITE);
450                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
451                                 {
452                                         fputs(f, "{\n");
453                                         fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
454                                         fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
455                                         fputs(f, strcat("\"maxs\" \"", ftos(e.absmax_x - e.absmin_x), " ", ftos(e.absmax_y - e.absmin_y), " ", ftos(e.absmax_z - e.absmin_z), "\"\n"));
456                                         fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
457                                         fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
458                                         fputs(f, "}\n");
459                                 }
460                                 for(e = world; (e = find(e, classname, "dragpoint")); )
461                                 {
462                                         start = '0 0 0';
463                                         effectnum = 0;
464                                         for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
465                                         {
466                                                 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
467                                                 {
468                                                         start = start + oldself.origin;
469                                                         ++effectnum;
470                                                 }
471                                         }
472                                         start *= 1 / effectnum;
473                                         fputs(f, "{\n");
474                                         fputs(f, "\"classname\" \"info_player_race\"\n");
475                                         fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
476                                         fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
477                                         if(e.cnt == -2)
478                                         {
479                                                 fputs(f, "\"target\" \"checkpoint0\"\n");
480                                                 fputs(f, "\"race_place\" \"0\"\n");
481                                         }
482                                         else if(e.cnt == -1)
483                                         {
484                                                 fputs(f, "\"target\" \"checkpoint0\"\n");
485                                                 fputs(f, "\"race_place\" \"-1\"\n");
486                                         }
487                                         else
488                                         {
489                                                 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
490                                                 if(e.cnt == 0)
491                                                 {
492                                                         // these need race_place
493                                                         // counting...
494                                                         effectnum = 1;
495                                                         for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
496                                                         if(oldself.cnt == 0)
497                                                         {
498                                                                 if(vlen(oldself.origin - start) < vlen(e.origin - start))
499                                                                         ++effectnum;
500                                                                 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
501                                                                         ++effectnum;
502                                                         }
503                                                         fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
504                                                 }
505                                         }
506                                         fputs(f, "}\n");
507                                 }
508                                 fclose(f);
509                                 return 1;
510                         }
511                         else
512                                 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
513                         break;
514                 case "drag_clear":
515                         for(e = world; (e = find(e, classname, "dragbox_box")); )
516                                 remove(e);
517                         for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
518                                 remove(e);
519                         for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
520                                 remove(e);
521                         for(e = world; (e = find(e, classname, "dragpoint")); )
522                                 remove(e);
523                         for(e = world; (e = find(e, classname, "drag_digit")); )
524                                 remove(e);
525                         return 1;
526         }
527         return 0;
528 }