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