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