moved "give all" into items trigger code, so an items trigger can also cause it
[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 ADD_CHEATS(e,n) \
65         cheatcount_total += n; \
66         e.cheatcount += n
67 #define END_CHEAT_FUNCTION() \
68         ADD_CHEATS(self,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;
249                 float effectnum, f;
250                 vector start, end;
251                 entity oldself;
252
253                 case "pointparticles":
254                         if(argc == 5)
255                         {
256                                 // arguments:
257                                 //   effectname
258                                 //   origin (0..1, on crosshair line)
259                                 //   velocity
260                                 //   howmany
261                                 effectnum = particleeffectnum(argv(1));
262                                 f = stof(argv(2));
263                                 start = (1-f) * self.origin + f * self.cursor_trace_endpos;
264                                 end = stov(argv(3));
265                                 f = stof(argv(4));
266                                 pointparticles(effectnum, start, end, f);
267                                 DID_CHEAT();
268                                 break;
269                         }
270                         sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
271                         break;
272                 case "trailparticles":
273                         if(argc == 2)
274                         {
275                                 // arguments:
276                                 //   effectname
277                                 effectnum = particleeffectnum(argv(1));
278                                 W_SetupShot(self, FALSE, FALSE, "",0);
279                                 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
280                                 trailparticles(self, effectnum, w_shotorg, trace_endpos);
281                                 DID_CHEAT();
282                                 break;
283                         }
284                         sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
285                         break;
286                 case "make":
287                         if(argc == 3)
288                         {
289                                 // arguments:
290                                 //   modelname mode
291                                 f = stof(argv(2));
292                                 W_SetupShot(self, FALSE, FALSE, "", 0);
293                                 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
294                                 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
295                                 {
296                                         sprint(self, "cannot make stuff there (bad surface)\n");
297                                 }
298                                 else
299                                 {
300                                         e = spawn();
301                                         e.model = strzone(argv(1));
302                                         e.mdl = "rocket_explode";
303                                         e.health = 1000;
304                                         setorigin(e, trace_endpos);
305                                         e.effects = EF_NOMODELFLAGS;
306                                         if(f == 1)
307                                         {
308                                                 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
309                                                 e.angles = AnglesTransform_Multiply(e.angles, '-90 0 0'); // so unrotated models work
310                                         }
311                                         oldself = self;
312                                         self = e;
313                                         spawnfunc_func_breakable();
314                                         self = oldself;
315                                         // now, is it valid?
316                                         if(f == 0)
317                                         {
318                                                 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
319                                                 if(trace_startsolid)
320                                                 {
321                                                         remove(e);
322                                                         sprint(self, "cannot make stuff there (no space)\n");
323                                                 }
324                                                 else
325                                                         DID_CHEAT();
326                                         }
327                                         else
328                                                 DID_CHEAT();
329                                 }
330                         }
331                         else
332                                 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
333                         break;
334                 case "penalty":
335                         if(argc == 3)
336                         {
337                                 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
338                                 DID_CHEAT();
339                                 break;
340                         }
341                         sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
342                         break;
343                 case "dragbox_spawn":
344                         e = spawn();
345                         e.classname = "dragbox_box";
346                         e.think = DragBox_Think;
347                         e.nextthink = time;
348                         e.solid = -1; // black
349                         setmodel(e, "null"); // network it
350                         if(argc == 4)
351                                 e.cnt = stof(argv(1));
352                         else
353                                 e.cnt = max(0, drag_lastcnt);
354
355                         e.aiment = spawn();
356                         e.aiment.classname = "dragbox_corner_1";
357                         e.aiment.owner = e;
358                         setmodel(e.aiment, "models/marker.md3");
359                         e.aiment.skin = 0;
360                         setsize(e.aiment, '0 0 0', '0 0 0');
361                         if(argc == 4)
362                                 setorigin(e.aiment, stov(argv(2)));
363                         else
364                                 setorigin(e.aiment, self.cursor_trace_endpos);
365
366                         e.enemy = spawn();
367                         e.enemy.classname = "dragbox_corner_2";
368                         e.enemy.owner = e;
369                         setmodel(e.enemy, "models/marker.md3");
370                         e.enemy.skin = 1;
371                         setsize(e.enemy, '0 0 0', '0 0 0');
372                         end = normalize(self.cursor_trace_start - e.aiment.origin);
373                         end_x = (end_x > 0) * 2 - 1;
374                         end_y = (end_y > 0) * 2 - 1;
375                         end_z = (end_z > 0) * 2 - 1;
376                         if(argc == 4)
377                                 setorigin(e.enemy, stov(argv(3)));
378                         else
379                                 setorigin(e.enemy, e.aiment.origin + 32 * end);
380
381                         e.killindicator = spawn();
382                         e.killindicator.classname = "drag_digit";
383                         e.killindicator.owner = e;
384                         setattachment(e.killindicator, e, "");
385                         setorigin(e.killindicator, '0 0 -8');
386                         e.killindicator.killindicator = spawn();
387                         e.killindicator.killindicator.classname = "drag_digit";
388                         e.killindicator.killindicator.owner = e;
389                         setattachment(e.killindicator.killindicator, e, "");
390                         setorigin(e.killindicator.killindicator, '0 0 8');
391                         DID_CHEAT();
392                         break;
393                 case "dragpoint_spawn":
394                         e = spawn();
395                         e.classname = "dragpoint";
396                         e.think = DragBox_Think;
397                         e.nextthink = time;
398                         e.solid = 0; // nothing special
399                         setmodel(e, "models/marker.md3");
400                         setsize(e, PL_MIN, PL_MAX);
401                         e.skin = 2;
402                         if(argc == 3)
403                                 e.cnt = stof(argv(1));
404                         else
405                                 e.cnt = drag_lastcnt;
406                         if(argc == 3)
407                                 setorigin(e, stov(argv(2)));
408                         else
409                         {
410                                 setorigin(e, self.cursor_trace_endpos + normalize(self.cursor_trace_start - self.cursor_trace_endpos));
411                                 move_out_of_solid(e);
412                         }
413
414                         e.killindicator = spawn();
415                         e.killindicator.classname = "drag_digit";
416                         e.killindicator.owner = e;
417                         setattachment(e.killindicator, e, "");
418                         setorigin(e.killindicator, '0 0 40');
419                         e.killindicator.killindicator = spawn();
420                         e.killindicator.killindicator.classname = "drag_digit";
421                         e.killindicator.killindicator.owner = e;
422                         setattachment(e.killindicator.killindicator, e, "");
423                         setorigin(e.killindicator.killindicator, '0 0 56');
424                         DID_CHEAT();
425                         break;
426                 case "drag_remove":
427                         RandomSelection_Init();
428                         for(e = world; (e = find(e, classname, "dragbox_box")); )
429                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
430                         for(e = world; (e = find(e, classname, "dragpoint")); )
431                                 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
432                         if(RandomSelection_chosen_ent)
433                         {
434                                 remove(RandomSelection_chosen_ent.killindicator.killindicator);
435                                 remove(RandomSelection_chosen_ent.killindicator);
436                                 if(RandomSelection_chosen_ent.aiment)
437                                         remove(RandomSelection_chosen_ent.aiment);
438                                 if(RandomSelection_chosen_ent.enemy)
439                                         remove(RandomSelection_chosen_ent.enemy);
440                                 remove(RandomSelection_chosen_ent);
441                         }
442                         DID_CHEAT();
443                         break;
444                 case "drag_setcnt":
445                         if(argc == 2)
446                         {
447                                 RandomSelection_Init();
448                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
449                                         RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
450                                 for(e = world; (e = find(e, classname, "dragpoint")); )
451                                         RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - self.cursor_trace_endpos));
452                                 if(RandomSelection_chosen_ent)
453                                 {
454                                         if(substring(argv(1), 0, 1) == "*")
455                                                 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
456                                         else
457                                                 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
458                                 }
459                                 DID_CHEAT();
460                                 break;
461                         }
462                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
463                         break;
464                 case "drag_save":
465                         if(argc == 2)
466                         {
467                                 f = fopen(argv(1), FILE_WRITE);
468                                 fputs(f, "cmd drag_clear\n");
469                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
470                                 {
471                                         fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
472                                 }
473                                 for(e = world; (e = find(e, classname, "dragpoint")); )
474                                 {
475                                         fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
476                                 }
477                                 fclose(f);
478                                 DID_CHEAT();
479                                 break;
480                         }
481                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
482                         break;
483                 case "drag_saveraceent":
484                         if(argc == 2)
485                         {
486                                 f = fopen(argv(1), FILE_WRITE);
487                                 for(e = world; (e = find(e, classname, "dragbox_box")); )
488                                 {
489                                         fputs(f, "{\n");
490                                         fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
491                                         fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
492                                         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"));
493                                         fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
494                                         fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
495                                         fputs(f, "}\n");
496                                 }
497                                 for(e = world; (e = find(e, classname, "dragpoint")); )
498                                 {
499                                         start = '0 0 0';
500                                         effectnum = 0;
501                                         for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
502                                         {
503                                                 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
504                                                 {
505                                                         start = start + oldself.origin;
506                                                         ++effectnum;
507                                                 }
508                                         }
509                                         start *= 1 / effectnum;
510                                         fputs(f, "{\n");
511                                         fputs(f, "\"classname\" \"info_player_race\"\n");
512                                         fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
513                                         fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
514                                         if(e.cnt == -2)
515                                         {
516                                                 fputs(f, "\"target\" \"checkpoint0\"\n");
517                                                 fputs(f, "\"race_place\" \"0\"\n");
518                                         }
519                                         else if(e.cnt == -1)
520                                         {
521                                                 fputs(f, "\"target\" \"checkpoint0\"\n");
522                                                 fputs(f, "\"race_place\" \"-1\"\n");
523                                         }
524                                         else
525                                         {
526                                                 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
527                                                 if(e.cnt == 0)
528                                                 {
529                                                         // these need race_place
530                                                         // counting...
531                                                         effectnum = 1;
532                                                         for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
533                                                         if(oldself.cnt == 0)
534                                                         {
535                                                                 if(vlen(oldself.origin - start) < vlen(e.origin - start))
536                                                                         ++effectnum;
537                                                                 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
538                                                                         ++effectnum;
539                                                         }
540                                                         fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
541                                                 }
542                                         }
543                                         fputs(f, "}\n");
544                                 }
545                                 fclose(f);
546                                 DID_CHEAT();
547                                 break;
548                         }
549                         sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
550                         break;
551                 case "drag_clear":
552                         for(e = world; (e = find(e, classname, "dragbox_box")); )
553                                 remove(e);
554                         for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
555                                 remove(e);
556                         for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
557                                 remove(e);
558                         for(e = world; (e = find(e, classname, "dragpoint")); )
559                                 remove(e);
560                         for(e = world; (e = find(e, classname, "drag_digit")); )
561                                 remove(e);
562                         DID_CHEAT();
563                         break;
564                 case "warp":
565                         if(argc == 2) if(cvar("g_campaign"))
566                         {
567                                 CampaignLevelWarp(stof(argv(1)));
568                                 DID_CHEAT();
569                         }
570                         break;
571                 case "god":
572                         BITXOR_ASSIGN(self.flags, FL_GODMODE);
573                         if(self.flags & FL_GODMODE)
574                         {
575                                 sprint(self, "godmode ON\n");
576                                 DID_CHEAT();
577                         }
578                         else
579                                 sprint(self, "godmode OFF\n");
580                         break;
581                 case "notarget":
582                         BITXOR_ASSIGN(self.flags, FL_NOTARGET);
583                         if(self.flags & FL_NOTARGET)
584                         {
585                                 sprint(self, "notarget ON\n");
586                                 DID_CHEAT();
587                         }
588                         else
589                                 sprint(self, "notarget OFF\n");
590                         break;
591                 case "noclip":
592                         if(self.movetype != MOVETYPE_NOCLIP)
593                         {
594                                 self.movetype = MOVETYPE_NOCLIP;
595                                 sprint(self, "noclip ON\n");
596                                 DID_CHEAT();
597                         }
598                         else
599                         {
600                                 self.movetype = MOVETYPE_WALK;
601                                 sprint(self, "noclip OFF\n");
602                         }
603                         break;
604                 case "fly":
605                         if(self.movetype != MOVETYPE_FLY)
606                         {
607                                 self.movetype = MOVETYPE_FLY;
608                                 sprint(self, "flmodey ON\n");
609                                 DID_CHEAT();
610                         }
611                         else
612                         {
613                                 self.movetype = MOVETYPE_WALK;
614                                 sprint(self, "flymode OFF\n");
615                         }
616                         break;
617                 case "give":
618                         if(GiveItems(self, 1, argc))
619                                 DID_CHEAT();
620                         break;
621         }
622
623         END_CHEAT_FUNCTION();
624 }
625
626 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
627 void Drag_Finish(entity dragger);
628 float Drag_IsDraggable(entity draggee);
629 float Drag_MayChangeAngles(entity draggee);
630 void Drag_MoveForward(entity dragger);
631 void Drag_SetSpeed(entity dragger, float s);
632 void Drag_MoveBackward(entity dragger);
633 void Drag_Update(entity dragger);
634 float Drag_CanDrag(entity dragger);
635 float Drag_IsDragging(entity dragger);
636 void Drag_MoveDrag(entity from, entity to);
637 .entity dragentity;
638
639 float CheatFrame()
640 {
641         BEGIN_CHEAT_FUNCTION();
642
643         if(CheatsAllowed(0, 0, CHRAME_DRAG))
644                 if(Drag_CanDrag(self))
645                         if(self.BUTTON_DRAG)
646                                 if(!self.dragentity)
647                                         if(self.cursor_trace_ent)
648                                                 if(Drag_IsDraggable(self.cursor_trace_ent))
649                                                 {
650                                                         if(self.cursor_trace_ent.draggedby)
651                                                                 Drag_Finish(self.cursor_trace_ent.draggedby);
652                                                         if(self.cursor_trace_ent.tag_entity)
653                                                                 detach_sameorigin(self.cursor_trace_ent);
654                                                         Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
655                                                         DID_CHEAT();
656                                                 }
657         if(Drag_IsDragging(self))
658         {
659                 if(self.BUTTON_DRAG)
660                 {
661                         if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
662                         {
663                                 Drag_MoveForward(self);
664                                 self.impulse = 0;
665                         }
666                         else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
667                         {
668                                 Drag_MoveBackward(self);
669                                 self.impulse = 0;
670                         }
671                         else if(self.impulse >= 1 && self.impulse <= 9)
672                         {
673                                 Drag_SetSpeed(self, self.impulse - 1);
674                         }
675                         else if(self.impulse == 14)
676                         {
677                                 Drag_SetSpeed(self, 9);
678                         }
679
680                         if(frametime)
681                                 Drag_Update(self);
682                 }
683                 else
684                 {
685                         Drag_Finish(self);
686                 }
687         }
688
689         END_CHEAT_FUNCTION();
690 }
691
692
693
694
695
696 // ENTITY DRAGGING
697
698 // on dragger:
699 .float draggravity;
700 .float dragspeed; // speed of mouse wheel action
701 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
702 .vector draglocalvector; // local attachment vector of the dragentity
703 .float draglocalangle;
704 // on draggee:
705 .entity draggedby;
706 .float dragmovetype;
707 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
708 {
709         float tagscale;
710
711         draggee.dragmovetype = draggee.movetype;
712         draggee.draggravity = draggee.gravity;
713         draggee.movetype = MOVETYPE_WALK;
714         draggee.gravity = 0.00001;
715         draggee.flags &~= FL_ONGROUND;
716         draggee.draggedby = dragger;
717
718         dragger.dragentity = draggee;
719
720         dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
721         dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
722         touchpoint = touchpoint - gettaginfo(draggee, 0);
723         tagscale = pow(vlen(v_forward), -2);
724         dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
725         dragger.draglocalvector_y = touchpoint * v_right * tagscale;
726         dragger.draglocalvector_z = touchpoint * v_up * tagscale;
727
728         dragger.dragspeed = 64;
729 }
730
731 void Drag_Finish(entity dragger)
732 {
733         entity draggee;
734         draggee = dragger.dragentity;
735         if(dragger)
736                 dragger.dragentity = world;
737         draggee.draggedby = world;
738         draggee.movetype = draggee.dragmovetype;
739         draggee.gravity = draggee.draggravity;
740
741         switch(draggee.movetype)
742         {
743                 case MOVETYPE_TOSS:
744                 case MOVETYPE_WALK:
745                 case MOVETYPE_STEP:
746                 case MOVETYPE_FLYMISSILE:
747                 case MOVETYPE_BOUNCE:
748                 case MOVETYPE_BOUNCEMISSILE:
749                 case MOVETYPE_PHYSICS:
750                         break;
751                 default:
752                         draggee.velocity = '0 0 0';
753                         break;
754         }
755
756         if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
757         {
758                 draggee.velocity = '0 0 0';
759                 draggee.flags |= FL_ONGROUND; // floating items are FUN
760         }
761 }
762
763 float Drag_IsDraggable(entity draggee)
764 {
765         // TODO add more checks for bad stuff here
766         if(draggee.classname == "func_bobbing")
767                 return FALSE;
768         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)
769                 return FALSE;
770         if(draggee.classname == "plat")
771                 return FALSE;
772         if(draggee.classname == "func_button")
773                 return FALSE;
774         if(draggee.model == "")
775                 return FALSE;
776         if(draggee.classname == "spectator")
777                 return FALSE;
778         if(draggee.classname == "observer")
779                 return FALSE;
780         if(draggee.classname == "exteriorweaponentity")
781                 return FALSE;
782
783         return TRUE;
784 }
785
786 float Drag_MayChangeAngles(entity draggee)
787 {
788         // TODO add more checks for bad stuff here
789         if(substring(draggee.model, 0, 1) == "*")
790                 return FALSE;
791         return TRUE;
792 }
793
794 void Drag_MoveForward(entity dragger)
795 {
796         dragger.dragdistance += dragger.dragspeed;
797 }
798
799 void Drag_SetSpeed(entity dragger, float s)
800 {
801         dragger.dragspeed = pow(2, s);
802 }
803
804 void Drag_MoveBackward(entity dragger)
805 {
806         dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
807 }
808
809 void Drag_Update(entity dragger)
810 {
811         vector curorigin, neworigin, goodvelocity;
812         float f;
813         entity draggee;
814
815         draggee = dragger.dragentity;
816         draggee.flags &~= FL_ONGROUND;
817
818         curorigin = gettaginfo(draggee, 0);
819         curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
820         makevectors(dragger.v_angle);
821         neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
822         goodvelocity = (neworigin - curorigin) * (1 / frametime);
823
824         while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
825                 dragger.draglocalangle += 360;
826         while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
827                 dragger.draglocalangle -= 360;
828
829         f = min(frametime * 10, 1);
830         draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
831
832         if(Drag_MayChangeAngles(draggee))
833                 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
834
835         draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
836
837         te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
838 }
839
840 float Drag_CanDrag(entity dragger)
841 {
842         return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
843 }
844
845 float Drag_IsDragging(entity dragger)
846 {
847         if(!dragger.dragentity)
848                 return FALSE;
849         if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
850         {
851                 dragger.dragentity = world;
852                 return FALSE;
853         }
854         if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
855         {
856                 Drag_Finish(dragger);
857                 return FALSE;
858         }
859         return TRUE;
860 }
861
862 void Drag_MoveDrag(entity from, entity to)
863 {
864         if(from.draggedby)
865         {
866                 to.draggedby = from.draggedby;
867                 to.draggedby.dragentity = to;
868                 from.draggedby = world;
869         }
870 }
871
872
873
874
875
876
877 void DragBox_Think()
878 {
879         if(self.aiment && self.enemy)
880         {
881                 self.origin_x = (self.aiment.origin_x + self.enemy.origin_x) * 0.5;
882                 self.origin_y = (self.aiment.origin_y + self.enemy.origin_y) * 0.5;
883                 self.origin_z = (self.aiment.origin_z + self.enemy.origin_z) * 0.5;
884                 self.maxs_x = fabs(self.aiment.origin_x - self.enemy.origin_x) * 0.5;
885                 self.maxs_y = fabs(self.aiment.origin_y - self.enemy.origin_y) * 0.5;
886                 self.maxs_z = fabs(self.aiment.origin_z - self.enemy.origin_z) * 0.5;
887                 self.mins = -1 * self.maxs;
888                 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
889         }
890
891         if(self.cnt == -1) // actually race_place -1
892         {
893                 // show "10 10" for qualifying spawns
894                 setmodel(self.killindicator, "models/sprites/10.spr32");
895                 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
896         }
897         else if(self.cnt == -2) // actually race_place 0
898         {
899                 // show "10 0" for loser spawns
900                 setmodel(self.killindicator, "models/sprites/10.spr32");
901                 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
902         }
903         else
904         {
905                 setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
906                 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
907         }
908
909         self.nextthink = time;
910 }
911
912 #endif