simplify "give all"
[divverent/nexuiz.git] / data / qcsrc / server / cheats.qc
1 void CopyBody(float keepvelocity);
2
3 #ifdef NOCHEATS
4
5 float CheatImpulse(float i) { return 0; }
6 float CheatCommand(float argc) { return 0; }
7 float CheatFrame() { return 0; }
8 void CheatInit() { cheatcount_total = world.cheatcount; }
9 void CheatShutdown() { }
10 void CheatInitClient() { }
11 void CheatShutdownClient() { }
12 void Drag_MoveDrag(entity from, entity to) { }
13
14 #else
15
16 .float maycheat;
17 float sv_cheats;
18 float autocvar_sv_cheats;
19
20 #define CHIMPULSE_SPEEDRUN_INIT 30
21 #define CHIMPULSE_GIVE_ALL 99
22 #define CHIMPULSE_CLONE_MOVING 140
23 #define CHIMPULSE_SPEEDRUN 141
24 #define CHIMPULSE_CLONE_STANDING 142
25 #define CHIMPULSE_TELEPORT 143
26 #define CHIMPULSE_R00T 148
27
28 #define CHRAME_DRAG 1
29
30 void CheatInit()
31 {
32         sv_cheats = cvar("sv_cheats");
33 }
34
35 void CheatShutdown()
36 {
37 }
38
39 void CheatInitClient()
40 {
41 }
42
43 void CheatShutdownClient()
44 {
45 }
46
47 float CheatsAllowed(float i, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking
48 {
49         if(i == CHIMPULSE_CLONE_MOVING || i == CHIMPULSE_CLONE_STANDING)
50                 if(self.lip < sv_clones)
51                         return 1;
52         if(self.maycheat)
53                 return 1;
54         if(sv_cheats && autocvar_sv_cheats)
55                 return 1;
56         if(autocvar_sv_cheats)
57                 sprint(self, "Cheats are not yet allowed, and will be activated at next map change.\n");
58         return 0;
59 }
60
61 float CheatImpulse(float i)
62 {
63         if not(CheatsAllowed(i, 0, 0))
64                 return 0;
65         switch(i)
66         {
67                 entity e, e2;
68                 vector org;
69
70                 case CHIMPULSE_SPEEDRUN_INIT: // deploy personal waypoint
71                         if(!self.personal)
72                         {
73                                 self.personal = spawn();
74                                 self.personal.classname = "personal_wp";
75                         }
76                         self.personal.origin = self.origin;
77                         self.personal.v_angle = self.v_angle;
78                         self.personal.velocity = self.velocity;
79                         self.personal.ammo_rockets = self.ammo_rockets;
80                         self.personal.ammo_nails = self.ammo_nails;
81                         self.personal.ammo_cells = self.ammo_cells;
82                         self.personal.ammo_shells = self.ammo_shells;
83                         self.personal.ammo_fuel = self.ammo_fuel;
84                         self.personal.health = self.health;
85                         self.personal.armorvalue = self.armorvalue;
86                         self.personal.weapons = self.weapons;
87                         self.personal.items = self.items;
88                         self.personal.pauserotarmor_finished = self.pauserotarmor_finished;
89                         self.personal.pauserothealth_finished = self.pauserothealth_finished;
90                         self.personal.pauserotfuel_finished = self.pauserotfuel_finished;
91                         self.personal.pauseregen_finished = self.pauseregen_finished;
92                         self.personal.strength_finished = self.strength_finished;
93                         self.personal.invincible_finished = self.invincible_finished;
94                         self.personal.teleport_time = time;
95                         break; // this part itself doesn't cheat, so let's not count this
96                 case CHIMPULSE_CLONE_MOVING:
97                         makevectors (self.v_angle);
98                         self.velocity = self.velocity + v_forward * 300;
99                         CopyBody(1);
100                         self.lip += 1;
101                         self.velocity = self.velocity - v_forward * 300;
102                         goto cheated;
103                 case CHIMPULSE_CLONE_STANDING:
104                         CopyBody(0);
105                         self.lip += 1;
106                         goto cheated;
107                 case CHIMPULSE_GIVE_ALL:
108                         CheatCommand(tokenize_console("give all"));
109                         break; // already counted as cheat
110                 case CHIMPULSE_SPEEDRUN:
111                         if(self.personal)
112                         {
113                                 self.speedrunning = TRUE;
114                                 tracebox(self.personal.origin, self.mins, self.maxs, self.personal.origin, MOVE_WORLDONLY, self);
115                                 if(trace_startsolid)
116                                 {
117                                         sprint(self, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
118                                 }
119                                 else
120                                 {
121                                         // Abort speedrun, teleport back
122                                         setorigin(self, self.personal.origin);
123                                         self.oldvelocity = self.velocity = self.personal.velocity;
124                                         self.angles = self.personal.v_angle;
125                                         self.fixangle = TRUE;
126                                         if(self.flagcarried)
127                                         {
128                                                 bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
129                                                 ReturnFlag(self.flagcarried);
130                                         }
131                                 }
132                                 if(g_ctf)
133                                 {
134                                         self.ammo_rockets = 999;
135                                         self.ammo_nails = 999;
136                                         self.ammo_cells = 999;
137                                         self.ammo_shells = 999;
138                                         self.ammo_fuel = 999;
139                                         self.health = start_health;
140                                         self.armorvalue = start_armorvalue;
141                                         self.weapons |= weaponsInMap;
142                                         self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
143                                         self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
144                                         self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
145                                         self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
146                                         self.strength_finished = 0;
147                                         self.invincible_finished = 0;
148                                 }
149                                 else
150                                 {
151                                         self.ammo_rockets = self.personal.ammo_rockets;
152                                         self.ammo_nails = self.personal.ammo_nails;
153                                         self.ammo_cells = self.personal.ammo_cells;
154                                         self.ammo_shells = self.personal.ammo_shells;
155                                         self.ammo_fuel = self.personal.ammo_fuel;
156                                         self.health = self.personal.health;
157                                         self.armorvalue = self.personal.armorvalue;
158                                         self.weapons = self.personal.weapons;
159                                         self.items = self.personal.items;
160                                         self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
161                                         self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
162                                         self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
163                                         self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
164                                         self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
165                                         self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
166                                 }
167                                 goto cheated;
168                         }
169                         else if(self.deadflag != DEAD_NO)
170                                 sprint(self, "UR DEAD AHAHAH))\n");
171                         else
172                                 sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
173                         break;
174                 case CHIMPULSE_TELEPORT:
175                         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))
176                         {
177                                 self.angles_x = -self.angles_x;
178                                 self.fixangle = TRUE;
179                                 self.velocity = '0 0 0';
180                                 goto cheated;
181                         }
182                         else
183                                 sprint(self, "Emergency teleport could not find a good location, forget it!\n");
184                         break;
185                 case CHIMPULSE_R00T:
186                         FOR_EACH_PLAYER(e)
187                         {
188                                 if( e.playermodel == "models/player/jeandarc.zym"
189                                                 ||  e.playermodel == "models/player/pyria.zym"
190                                                 ||  e.playermodel == "models/player/skadi.zym"
191                                                 || (e.playermodel == "models/player/specop.zym" && random() < 0.5) // you never know
192                                                 ||  e.playermodel == "models/player/visitant.zym")
193                                 {
194                                         makevectors(e.angles);
195                                         traceline(e.origin, e.origin + v_right * 256, MOVE_NORMAL, e);
196                                 }
197                                 else
198                                 {
199                                         org_x = random();
200                                         org_y = random();
201                                         org_z = 0;
202                                         org = normalize(org);
203                                         traceline(e.origin, e.origin + org * 256, MOVE_NORMAL, e); // random direction
204                                 }
205
206                                 org = findbetterlocation(trace_endpos, 12);
207
208                                 e2 = spawn();
209                                 setorigin(e2, org);
210                                 pointparticles(particleeffectnum("rocket_explode"), org, '0 0 0', 1);
211                                 sound(e2, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
212                                 RadiusDamage(e2, e, 1000, 0, 128, e, 500, DEATH_CHEAT, world);
213                                 remove(e2);
214                         }
215                         print("404 Sportsmanship not found.\n");
216                         goto cheated;
217         }
218         return 0;
219
220 :cheated
221         cheatcount_total += 1;
222         self.cheatcount += 1;
223         return 1;
224 }
225
226 void DragBox_Think();
227 float drag_lastcnt;
228 float CheatCommand(float argc)
229 {
230         if not(CheatsAllowed(0, argc, 0))
231                 return 0;
232         string cmd;
233         cmd = argv(0);
234         switch(cmd)
235         {
236                 entity e, wi;
237                 float effectnum, f, j;
238                 vector start, end;
239                 entity oldself;
240                 string s;
241
242                 case "pointparticles":
243                         if(argc == 5)
244                         {
245                                 // arguments:
246                                 //   effectname
247                                 //   origin (0..1, on crosshair line)
248                                 //   velocity
249                                 //   howmany
250                                 effectnum = particleeffectnum(argv(1));
251                                 f = stof(argv(2));
252                                 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
253                                 end = stov(argv(3));
254                                 f = stof(argv(4));
255                                 pointparticles(effectnum, start, end, f);
256                                 goto cheated;
257                         }
258                         sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
259                         break;
260                 case "trailparticles":
261                         if(argc == 2)
262                         {
263                                 // arguments:
264                                 //   effectname
265                                 effectnum = particleeffectnum(argv(1));
266                                 W_SetupShot(self, FALSE, FALSE, "",0);
267                                 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
268                                 trailparticles(self, effectnum, w_shotorg, trace_endpos);
269                                 goto cheated;
270                         }
271                         sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
272                         break;
273                 case "make":
274                         if(argc == 3)
275                         {
276                                 // arguments:
277                                 //   modelname mode
278                                 f = stof(argv(2));
279                                 W_SetupShot(self, FALSE, FALSE, "", 0);
280                                 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
281                                 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
282                                 {
283                                         sprint(self, "cannot make stuff there (bad surface)\n");
284                                 }
285                                 else
286                                 {
287                                         e = spawn();
288                                         e.model = strzone(argv(1));
289                                         e.mdl = "rocket_explode";
290                                         e.health = 1000;
291                                         setorigin(e, trace_endpos);
292                                         e.effects = EF_NOMODELFLAGS;
293                                         if(f == 1)
294                                         {
295                                                 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
296                                                 e.angles = AnglesTransform_Multiply(e.angles, '-90 0 0'); // so unrotated models work
297                                         }
298                                         oldself = self;
299                                         self = e;
300                                         spawnfunc_func_breakable();
301                                         self = oldself;
302                                         // now, is it valid?
303                                         if(f == 0)
304                                         {
305                                                 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
306                                                 if(trace_startsolid)
307                                                 {
308                                                         remove(e);
309                                                         sprint(self, "cannot make stuff there (no space)\n");
310                                                 }
311                                                 else
312                                                         goto cheated;
313                                         }
314                                         else
315                                                 goto cheated;
316                                 }
317                         }
318                         else
319                                 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
320                         break;
321                 case "penalty":
322                         if(argc == 3)
323                         {
324                                 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
325                                 goto cheated;
326                         }
327                         sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
328                         break;
329                 case "dragbox_spawn":
330                         e = spawn();
331                         e.classname = "dragbox_box";
332                         e.think = DragBox_Think;
333                         e.nextthink = time;
334                         e.solid = -1; // black
335                         setmodel(e, "null"); // network it
336                         if(argc == 4)
337                                 e.cnt = stof(argv(1));
338                         else
339                                 e.cnt = max(0, drag_lastcnt);
340
341                         e.aiment = spawn();
342                         e.aiment.classname = "dragbox_corner_1";
343                         e.aiment.owner = e;
344                         setmodel(e.aiment, "models/marker.md3");
345                         e.aiment.skin = 0;
346                         setsize(e.aiment, '0 0 0', '0 0 0');
347                         if(argc == 4)
348                                 setorigin(e.aiment, stov(argv(2)));
349                         else
350                                 setorigin(e.aiment, self.cursor_trace_endpos);
351
352                         e.enemy = spawn();
353                         e.enemy.classname = "dragbox_corner_2";
354                         e.enemy.owner = e;
355                         setmodel(e.enemy, "models/marker.md3");
356                         e.enemy.skin = 1;
357                         setsize(e.enemy, '0 0 0', '0 0 0');
358                         end = normalize(self.cursor_trace_start - e.aiment.origin);
359                         end_x = (end_x > 0) * 2 - 1;
360                         end_y = (end_y > 0) * 2 - 1;
361                         end_z = (end_z > 0) * 2 - 1;
362                         if(argc == 4)
363                                 setorigin(e.enemy, stov(argv(3)));
364                         else
365                                 setorigin(e.enemy, e.aiment.origin + 32 * end);
366
367                         e.killindicator = spawn();
368                         e.killindicator.classname = "drag_digit";
369                         e.killindicator.owner = e;
370                         setattachment(e.killindicator, e, "");
371                         setorigin(e.killindicator, '0 0 -8');
372                         e.killindicator.killindicator = spawn();
373                         e.killindicator.killindicator.classname = "drag_digit";
374                         e.killindicator.killindicator.owner = e;
375                         setattachment(e.killindicator.killindicator, e, "");
376                         setorigin(e.killindicator.killindicator, '0 0 8');
377                         goto cheated;
378                 case "dragpoint_spawn":
379                         e = spawn();
380                         e.classname = "dragpoint";
381                         e.think = DragBox_Think;
382                         e.nextthink = time;
383                         e.solid = 0; // nothing special
384                         setmodel(e, "models/marker.md3");
385                         setsize(e, PL_MIN, PL_MAX);
386                         e.skin = 2;
387                         if(argc == 3)
388                                 e.cnt = stof(argv(1));
389                         else
390                                 e.cnt = drag_lastcnt;
391                         if(argc == 3)
392                                 setorigin(e, stov(argv(2)));
393                         else
394                         {
395                                 setorigin(e, self.cursor_trace_endpos + normalize(self.cursor_trace_start - self.cursor_trace_endpos));
396                                 move_out_of_solid(e);
397                         }
398
399                         e.killindicator = spawn();
400                         e.killindicator.classname = "drag_digit";
401                         e.killindicator.owner = e;
402                         setattachment(e.killindicator, e, "");
403                         setorigin(e.killindicator, '0 0 40');
404                         e.killindicator.killindicator = spawn();
405                         e.killindicator.killindicator.classname = "drag_digit";
406                         e.killindicator.killindicator.owner = e;
407                         setattachment(e.killindicator.killindicator, e, "");
408                         setorigin(e.killindicator.killindicator, '0 0 56');
409                         goto cheated;
410                 case "drag_remove":
411                         RandomSelection_Init();
412                         for(e = world; (e = find(e, classname, "dragbox_box")); )
413                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
414                         for(e = world; (e = find(e, classname, "dragpoint")); )
415                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
416                         if(RandomSelection_chosen_ent)
417                         {
418                                 remove(RandomSelection_chosen_ent.killindicator.killindicator);
419                                 remove(RandomSelection_chosen_ent.killindicator);
420                                 if(RandomSelection_chosen_ent.aiment)
421                                         remove(RandomSelection_chosen_ent.aiment);
422                                 if(RandomSelection_chosen_ent.enemy)
423                                         remove(RandomSelection_chosen_ent.enemy);
424                                 remove(RandomSelection_chosen_ent);
425                         }
426                         goto cheated;
427                 case "drag_setcnt":
428                         if(argc == 2)
429                         {
430                                 RandomSelection_Init();
431                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
432                                         RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
433                                 for(e = world; (e = find(e, classname, "dragpoint")); )
434                                         RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
435                                 if(RandomSelection_chosen_ent)
436                                 {
437                                         if(substring(argv(1), 0, 1) == "*")
438                                                 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
439                                         else
440                                                 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
441                                 }
442                                 goto cheated;
443                         }
444                         else
445                                 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
446                         break;
447                 case "drag_save":
448                         if(argc == 2)
449                         {
450                                 f = fopen(argv(1), FILE_WRITE);
451                                 fputs(f, "cmd drag_clear\n");
452                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
453                                 {
454                                         fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
455                                 }
456                                 for(e = world; (e = find(e, classname, "dragpoint")); )
457                                 {
458                                         fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
459                                 }
460                                 fclose(f);
461                                 goto cheated;
462                         }
463                         else
464                                 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
465                         break;
466                 case "drag_saveraceent":
467                         if(argc == 2)
468                         {
469                                 f = fopen(argv(1), FILE_WRITE);
470                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
471                                 {
472                                         fputs(f, "{\n");
473                                         fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
474                                         fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
475                                         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"));
476                                         fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
477                                         fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
478                                         fputs(f, "}\n");
479                                 }
480                                 for(e = world; (e = find(e, classname, "dragpoint")); )
481                                 {
482                                         start = '0 0 0';
483                                         effectnum = 0;
484                                         for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
485                                         {
486                                                 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
487                                                 {
488                                                         start = start + oldself.origin;
489                                                         ++effectnum;
490                                                 }
491                                         }
492                                         start *= 1 / effectnum;
493                                         fputs(f, "{\n");
494                                         fputs(f, "\"classname\" \"info_player_race\"\n");
495                                         fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
496                                         fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
497                                         if(e.cnt == -2)
498                                         {
499                                                 fputs(f, "\"target\" \"checkpoint0\"\n");
500                                                 fputs(f, "\"race_place\" \"0\"\n");
501                                         }
502                                         else if(e.cnt == -1)
503                                         {
504                                                 fputs(f, "\"target\" \"checkpoint0\"\n");
505                                                 fputs(f, "\"race_place\" \"-1\"\n");
506                                         }
507                                         else
508                                         {
509                                                 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
510                                                 if(e.cnt == 0)
511                                                 {
512                                                         // these need race_place
513                                                         // counting...
514                                                         effectnum = 1;
515                                                         for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
516                                                         if(oldself.cnt == 0)
517                                                         {
518                                                                 if(vlen(oldself.origin - start) < vlen(e.origin - start))
519                                                                         ++effectnum;
520                                                                 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
521                                                                         ++effectnum;
522                                                         }
523                                                         fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
524                                                 }
525                                         }
526                                         fputs(f, "}\n");
527                                 }
528                                 fclose(f);
529                                 goto cheated;
530                         }
531                         else
532                                 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
533                         break;
534                 case "drag_clear":
535                         for(e = world; (e = find(e, classname, "dragbox_box")); )
536                                 remove(e);
537                         for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
538                                 remove(e);
539                         for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
540                                 remove(e);
541                         for(e = world; (e = find(e, classname, "dragpoint")); )
542                                 remove(e);
543                         for(e = world; (e = find(e, classname, "drag_digit")); )
544                                 remove(e);
545                         goto cheated;
546                 case "warp":
547                         if(argc == 2) if(cvar("g_campaign"))
548                         {
549                                 CampaignLevelWarp(stof(argv(1)));
550                                 goto cheated;
551                         }
552                         break;
553                 case "god":
554                         BITXOR_ASSIGN(self.flags, FL_GODMODE);
555                         if(self.flags & FL_GODMODE)
556                         {
557                                 sprint(self, "godmode ON\n");
558                                 goto cheated;
559                         }
560                         else
561                                 sprint(self, "godmode OFF\n");
562                         break;
563                 case "notarget":
564                         BITXOR_ASSIGN(self.flags, FL_NOTARGET);
565                         if(self.flags & FL_NOTARGET)
566                         {
567                                 sprint(self, "notarget ON\n");
568                                 goto cheated;
569                         }
570                         else
571                                 sprint(self, "notarget OFF\n");
572                         break;
573                 case "noclip":
574                         if(self.movetype != MOVETYPE_NOCLIP)
575                         {
576                                 self.movetype = MOVETYPE_NOCLIP;
577                                 sprint(self, "noclip ON\n");
578                                 goto cheated;
579                         }
580                         else
581                         {
582                                 self.movetype = MOVETYPE_WALK;
583                                 sprint(self, "noclip OFF\n");
584                         }
585                         break;
586                 case "fly":
587                         if(self.movetype != MOVETYPE_FLY)
588                         {
589                                 self.movetype = MOVETYPE_FLY;
590                                 sprint(self, "flmodey ON\n");
591                                 goto cheated;
592                         }
593                         else
594                         {
595                                 self.movetype = MOVETYPE_WALK;
596                                 sprint(self, "flymode OFF\n");
597                         }
598                         break;
599                 case "give":
600                         if(argv(1) == "all")
601                         {
602                                 s = "unlimited_ammo jetpack fuel_regen strength invinicible cells shells nails rockets health armor fuel";
603                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
604                                 {
605                                         wi = get_weaponinfo(j);
606                                         if(wi.weapon)
607                                                 s = strcat(s, " ", wi.netname);
608                                 }
609                                 argc = tokenize_console(s);
610                                 GiveItems(self, 0, tokenize_console(s));
611                                 goto cheated;
612                         }
613                         if(GiveItems(self, 1, argc))
614                                 goto cheated;
615                         break;
616         }
617         return 0;
618
619 :cheated
620         cheatcount_total += 1;
621         self.cheatcount += 1;
622         return 1;
623 }
624
625 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
626 void Drag_Finish(entity dragger);
627 float Drag_IsDraggable(entity draggee);
628 float Drag_MayChangeAngles(entity draggee);
629 void Drag_MoveForward(entity dragger);
630 void Drag_SetSpeed(entity dragger, float s);
631 void Drag_MoveBackward(entity dragger);
632 void Drag_Update(entity dragger);
633 float Drag_CanDrag(entity dragger);
634 float Drag_IsDragging(entity dragger);
635 void Drag_MoveDrag(entity from, entity to);
636 .entity dragentity;
637
638 float CheatFrame()
639 {
640         float cheating;
641         cheating = 0;
642
643         if(CheatsAllowed(0, 0, CHRAME_DRAG))
644                 if(Drag_CanDrag(self))
645                         if(self.BUTTON_DRAG)
646                                 if(!self.dragentity)
647                                         if(self.cursor_trace_ent)
648                                                 if(Drag_IsDraggable(self.cursor_trace_ent))
649                                                 {
650                                                         if(self.cursor_trace_ent.draggedby)
651                                                                 Drag_Finish(self.cursor_trace_ent.draggedby);
652                                                         if(self.cursor_trace_ent.tag_entity)
653                                                                 detach_sameorigin(self.cursor_trace_ent);
654                                                         Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
655                                                         ++cheating;
656                                                 }
657         if(Drag_IsDragging(self))
658         {
659                 if(self.BUTTON_DRAG)
660                 {
661                         if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
662                         {
663                                 Drag_MoveForward(self);
664                                 self.impulse = 0;
665                         }
666                         else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
667                         {
668                                 Drag_MoveBackward(self);
669                                 self.impulse = 0;
670                         }
671                         else if(self.impulse >= 1 && self.impulse <= 9)
672                         {
673                                 Drag_SetSpeed(self, self.impulse - 1);
674                         }
675                         else if(self.impulse == 14)
676                         {
677                                 Drag_SetSpeed(self, 9);
678                         }
679
680                         if(frametime)
681                                 Drag_Update(self);
682                 }
683                 else
684                 {
685                         Drag_Finish(self);
686                 }
687         }
688
689         if(cheating)
690         {
691                 cheatcount_total += 1;
692                 self.cheatcount += 1;
693                 return 1;
694         }
695
696         return cheating;
697 }
698
699
700
701
702
703 // ENTITY DRAGGING
704
705 // on dragger:
706 .float draggravity;
707 .float dragspeed; // speed of mouse wheel action
708 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
709 .vector draglocalvector; // local attachment vector of the dragentity
710 .float draglocalangle;
711 // on draggee:
712 .entity draggedby;
713 .float dragmovetype;
714 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
715 {
716         float tagscale;
717
718         draggee.dragmovetype = draggee.movetype;
719         draggee.draggravity = draggee.gravity;
720         draggee.movetype = MOVETYPE_WALK;
721         draggee.gravity = 0.00001;
722         draggee.flags &~= FL_ONGROUND;
723         draggee.draggedby = dragger;
724
725         dragger.dragentity = draggee;
726
727         dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
728         dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
729         touchpoint = touchpoint - gettaginfo(draggee, 0);
730         tagscale = pow(vlen(v_forward), -2);
731         dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
732         dragger.draglocalvector_y = touchpoint * v_right * tagscale;
733         dragger.draglocalvector_z = touchpoint * v_up * tagscale;
734
735         dragger.dragspeed = 64;
736 }
737
738 void Drag_Finish(entity dragger)
739 {
740         entity draggee;
741         draggee = dragger.dragentity;
742         if(dragger)
743                 dragger.dragentity = world;
744         draggee.draggedby = world;
745         draggee.movetype = draggee.dragmovetype;
746         draggee.gravity = draggee.draggravity;
747
748         switch(draggee.movetype)
749         {
750                 case MOVETYPE_TOSS:
751                 case MOVETYPE_WALK:
752                 case MOVETYPE_STEP:
753                 case MOVETYPE_FLYMISSILE:
754                 case MOVETYPE_BOUNCE:
755                 case MOVETYPE_BOUNCEMISSILE:
756                 case MOVETYPE_PHYSICS:
757                         break;
758                 default:
759                         draggee.velocity = '0 0 0';
760                         break;
761         }
762
763         if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
764         {
765                 draggee.velocity = '0 0 0';
766                 draggee.flags |= FL_ONGROUND; // floating items are FUN
767         }
768 }
769
770 float Drag_IsDraggable(entity draggee)
771 {
772         // TODO add more checks for bad stuff here
773         if(draggee.classname == "func_bobbing")
774                 return FALSE;
775         if(draggee.classname == "door") // FIXME find out why these must be excluded, or work around the problem (trying to drag these causes like 4 fps)
776                 return FALSE;
777         if(draggee.classname == "plat")
778                 return FALSE;
779         if(draggee.classname == "func_button")
780                 return FALSE;
781         if(draggee.model == "")
782                 return FALSE;
783         if(draggee.classname == "spectator")
784                 return FALSE;
785         if(draggee.classname == "observer")
786                 return FALSE;
787         if(draggee.classname == "exteriorweaponentity")
788                 return FALSE;
789
790         return TRUE;
791 }
792
793 float Drag_MayChangeAngles(entity draggee)
794 {
795         // TODO add more checks for bad stuff here
796         if(substring(draggee.model, 0, 1) == "*")
797                 return FALSE;
798         return TRUE;
799 }
800
801 void Drag_MoveForward(entity dragger)
802 {
803         dragger.dragdistance += dragger.dragspeed;
804 }
805
806 void Drag_SetSpeed(entity dragger, float s)
807 {
808         dragger.dragspeed = pow(2, s);
809 }
810
811 void Drag_MoveBackward(entity dragger)
812 {
813         dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
814 }
815
816 void Drag_Update(entity dragger)
817 {
818         vector curorigin, neworigin, goodvelocity;
819         float f;
820         entity draggee;
821
822         draggee = dragger.dragentity;
823         draggee.flags &~= FL_ONGROUND;
824
825         curorigin = gettaginfo(draggee, 0);
826         curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
827         makevectors(dragger.v_angle);
828         neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
829         goodvelocity = (neworigin - curorigin) * (1 / frametime);
830
831         while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
832                 dragger.draglocalangle += 360;
833         while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
834                 dragger.draglocalangle -= 360;
835
836         f = min(frametime * 10, 1);
837         draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
838
839         if(Drag_MayChangeAngles(draggee))
840                 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
841
842         draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
843
844         te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
845 }
846
847 float Drag_CanDrag(entity dragger)
848 {
849         return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
850 }
851
852 float Drag_IsDragging(entity dragger)
853 {
854         if(!dragger.dragentity)
855                 return FALSE;
856         if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
857         {
858                 dragger.dragentity = world;
859                 return FALSE;
860         }
861         if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
862         {
863                 Drag_Finish(dragger);
864                 return FALSE;
865         }
866         return TRUE;
867 }
868
869 void Drag_MoveDrag(entity from, entity to)
870 {
871         if(from.draggedby)
872         {
873                 to.draggedby = from.draggedby;
874                 to.draggedby.dragentity = to;
875                 from.draggedby = world;
876         }
877 }
878
879
880
881
882
883
884 void DragBox_Think()
885 {
886         if(self.aiment && self.enemy)
887         {
888                 self.origin_x = (self.aiment.origin_x + self.enemy.origin_x) * 0.5;
889                 self.origin_y = (self.aiment.origin_y + self.enemy.origin_y) * 0.5;
890                 self.origin_z = (self.aiment.origin_z + self.enemy.origin_z) * 0.5;
891                 self.maxs_x = fabs(self.aiment.origin_x - self.enemy.origin_x) * 0.5;
892                 self.maxs_y = fabs(self.aiment.origin_y - self.enemy.origin_y) * 0.5;
893                 self.maxs_z = fabs(self.aiment.origin_z - self.enemy.origin_z) * 0.5;
894                 self.mins = -1 * self.maxs;
895                 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
896         }
897
898         if(self.cnt == -1) // actually race_place -1
899         {
900                 // show "10 10" for qualifying spawns
901                 setmodel(self.killindicator, "models/sprites/10.spr32");
902                 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
903         }
904         else if(self.cnt == -2) // actually race_place 0
905         {
906                 // show "10 0" for loser spawns
907                 setmodel(self.killindicator, "models/sprites/10.spr32");
908                 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
909         }
910         else
911         {
912                 setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
913                 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
914         }
915
916         self.nextthink = time;
917 }
918
919 #endif