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