1 void CopyBody(float keepvelocity);
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) { }
17 float gamestart_sv_cheats;
19 #define CHIMPULSE_SPEEDRUN_INIT 30
20 #define CHIMPULSE_GIVE_ALL 99
21 #define CHIMPULSE_CLONE_MOVING 140
22 #define CHIMPULSE_SPEEDRUN 141
23 #define CHIMPULSE_CLONE_STANDING 142
24 #define CHIMPULSE_TELEPORT 143
25 #define CHIMPULSE_R00T 148
31 gamestart_sv_cheats = autocvar_sv_cheats;
38 void CheatInitClient()
42 void CheatShutdownClient()
46 float CheatsAllowed(float i, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking
48 // dead people cannot cheat
49 if(self.deadflag != DEAD_NO)
51 if(gamestart_sv_cheats < 2 && !IS_PLAYER(self))
55 if(i == CHIMPULSE_CLONE_MOVING || i == CHIMPULSE_CLONE_STANDING)
56 if(self.lip < sv_clones)
64 if(gamestart_sv_cheats && autocvar_sv_cheats)
67 // if we get here, player is not allowed to cheat. Log it.
69 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", self.netname, i);
71 bprintf("Player %s^7 tried to use cheat '%s'\n", self.netname, argv(0));
73 bprintf("Player %s^7 tried to use cheat frame %d\n", self.netname, fr);
75 bprintf("Player %s^7 tried to use an unknown cheat\n", self.netname);
80 #define BEGIN_CHEAT_FUNCTION() \
81 float cheating, attempting; \
82 cheating = 0; attempting = 0
85 #define ADD_CHEATS(e,n) \
86 cheatcount_total += n; \
88 #define END_CHEAT_FUNCTION() \
89 ADD_CHEATS(self,cheating); \
91 #define IS_CHEAT(i,argc,fr) \
92 if((++attempting, !CheatsAllowed(i,argc,fr))) \
95 float num_autoscreenshot;
96 void info_autoscreenshot_findtarget()
99 e = find(world, targetname, self.target);
102 objerror("Missing target. FAIL!");
105 vector a = vectoangles(e.origin - self.origin);
106 a_x = -a_x; // don't ask
109 // we leave Rick Roll alone
111 void spawnfunc_info_autoscreenshot()
113 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
115 objerror("Too many info_autoscreenshot entitites. FAIL!");
118 if(self.target != "")
119 InitializeEntity(self, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
120 // this one just has to exist
123 float CheatImpulse(float i)
125 BEGIN_CHEAT_FUNCTION();
130 case CHIMPULSE_SPEEDRUN_INIT: // deploy personal waypoint
131 // shared with regular waypoint init, so this is not a cheat by itself
134 self.personal = spawn();
135 self.personal.classname = "personal_wp";
137 self.personal.origin = self.origin;
138 self.personal.v_angle = self.v_angle;
139 self.personal.velocity = self.velocity;
140 self.personal.ammo_rockets = self.ammo_rockets;
141 self.personal.ammo_nails = self.ammo_nails;
142 self.personal.ammo_cells = self.ammo_cells;
143 self.personal.ammo_plasma = self.ammo_plasma;
144 self.personal.ammo_shells = self.ammo_shells;
145 self.personal.ammo_fuel = self.ammo_fuel;
146 self.personal.health = self.health;
147 self.personal.armorvalue = self.armorvalue;
148 self.personal.weapons = self.weapons;
149 self.personal.items = self.items;
150 self.personal.pauserotarmor_finished = self.pauserotarmor_finished;
151 self.personal.pauserothealth_finished = self.pauserothealth_finished;
152 self.personal.pauserotfuel_finished = self.pauserotfuel_finished;
153 self.personal.pauseregen_finished = self.pauseregen_finished;
154 self.personal.strength_finished = self.strength_finished;
155 self.personal.invincible_finished = self.invincible_finished;
156 self.personal.teleport_time = time;
157 break; // this part itself doesn't cheat, so let's not count this
158 case CHIMPULSE_CLONE_MOVING:
160 makevectors (self.v_angle);
161 self.velocity = self.velocity + v_forward * 300;
164 self.velocity = self.velocity - v_forward * 300;
167 case CHIMPULSE_CLONE_STANDING:
173 case CHIMPULSE_GIVE_ALL:
175 CheatCommand(tokenize_console("give all"));
176 break; // already counted as cheat
177 case CHIMPULSE_SPEEDRUN:
181 self.speedrunning = TRUE;
182 tracebox(self.personal.origin, self.mins, self.maxs, self.personal.origin, MOVE_WORLDONLY, self);
185 sprint(self, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
189 // Abort speedrun, teleport back
190 setorigin(self, self.personal.origin);
191 self.oldvelocity = self.velocity = self.personal.velocity;
192 self.angles = self.personal.v_angle;
193 self.fixangle = TRUE;
195 MUTATOR_CALLHOOK(AbortSpeedrun);
198 self.ammo_rockets = self.personal.ammo_rockets;
199 self.ammo_nails = self.personal.ammo_nails;
200 self.ammo_cells = self.personal.ammo_cells;
201 self.ammo_plasma = self.personal.ammo_plasma;
202 self.ammo_shells = self.personal.ammo_shells;
203 self.ammo_fuel = self.personal.ammo_fuel;
204 self.health = self.personal.health;
205 self.armorvalue = self.personal.armorvalue;
206 self.weapons = self.personal.weapons;
207 self.items = self.personal.items;
208 self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
209 self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
210 self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
211 self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
212 self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
213 self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
218 if(self.deadflag != DEAD_NO)
219 sprint(self, "UR DEAD AHAHAH))\n");
221 sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
223 case CHIMPULSE_TELEPORT:
225 if(self.movetype == MOVETYPE_NOCLIP)
227 e = find(world, classname, "info_autoscreenshot");
230 sprint(self, "Emergency teleport used info_autoscreenshot location\n");
231 setorigin(self, e.origin);
232 self.angles = e.angles;
234 // should we? self.angles_x = -self.angles_x;
235 self.fixangle = TRUE;
236 self.velocity = '0 0 0';
241 if(MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, ((gamestart_sv_cheats < 2) ? 100 : 100000), 384, 384))
243 sprint(self, "Emergency teleport used random location\n");
244 self.angles_x = -self.angles_x;
245 self.fixangle = TRUE;
246 self.velocity = '0 0 0';
250 sprint(self, "Emergency teleport could not find a good location, forget it!\n");
254 RandomSelection_Init();
256 if(e.deadflag == DEAD_NO)
257 if(DIFF_TEAM(e, self))
258 RandomSelection_Add(e, 0, string_null, 1, 1);
259 if(RandomSelection_chosen_ent)
260 e = RandomSelection_chosen_ent;
264 pointparticles(particleeffectnum("rocket_explode"), e.origin, '0 0 0', 1);
265 sound(e, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
268 setorigin(e2, e.origin);
269 RadiusDamage(e2, self, 1000, 0, 128, world, world, 500, DEATH_CHEAT, e);
272 print("404 Sportsmanship not found.\n");
277 END_CHEAT_FUNCTION();
280 void DragBox_Think();
282 float CheatCommand(float argc)
284 BEGIN_CHEAT_FUNCTION();
294 case "pointparticles":
295 IS_CHEAT(0, argc, 0);
300 // origin (0..1, on crosshair line)
303 effectnum = particleeffectnum(argv(1));
305 crosshair_trace(self);
306 start = (1-f) * self.origin + f * trace_endpos;
309 pointparticles(effectnum, start, end, f);
313 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
315 case "trailparticles":
316 IS_CHEAT(0, argc, 0);
321 effectnum = particleeffectnum(argv(1));
322 W_SetupShot(self, FALSE, FALSE, "", CH_WEAPON_A, 0);
323 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
324 trailparticles(self, effectnum, w_shotorg, trace_endpos);
328 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
331 IS_CHEAT(0, argc, 0);
337 W_SetupShot(self, FALSE, FALSE, "", CH_WEAPON_A, 0);
338 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
339 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
341 sprint(self, "cannot make stuff there (bad surface)\n");
346 e.model = strzone(argv(1));
347 e.mdl = "rocket_explode";
349 setorigin(e, trace_endpos);
350 e.effects = EF_NOMODELFLAGS;
353 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
354 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
358 spawnfunc_func_breakable();
363 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
367 sprint(self, "cannot make stuff there (no space)\n");
377 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
380 IS_CHEAT(0, argc, 0);
383 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
387 sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
389 case "dragbox_spawn":
390 IS_CHEAT(0, argc, 0);
392 e.classname = "dragbox_box";
393 e.think = DragBox_Think;
395 e.solid = -1; // black
396 setmodel(e, "null"); // network it
398 e.cnt = stof(argv(1));
400 e.cnt = max(0, drag_lastcnt);
403 e.aiment.classname = "dragbox_corner_1";
405 setmodel(e.aiment, "models/marker.md3");
407 setsize(e.aiment, '0 0 0', '0 0 0');
409 setorigin(e.aiment, stov(argv(2)));
412 crosshair_trace(self);
413 setorigin(e.aiment, trace_endpos);
417 e.enemy.classname = "dragbox_corner_2";
419 setmodel(e.enemy, "models/marker.md3");
421 setsize(e.enemy, '0 0 0', '0 0 0');
422 end = normalize(self.origin + self.view_ofs - e.aiment.origin);
423 end_x = (end_x > 0) * 2 - 1;
424 end_y = (end_y > 0) * 2 - 1;
425 end_z = (end_z > 0) * 2 - 1;
427 setorigin(e.enemy, stov(argv(3)));
429 setorigin(e.enemy, e.aiment.origin + 32 * end);
431 e.killindicator = spawn();
432 e.killindicator.classname = "drag_digit";
433 e.killindicator.owner = e;
434 setattachment(e.killindicator, e, "");
435 setorigin(e.killindicator, '0 0 -8');
436 e.killindicator.killindicator = spawn();
437 e.killindicator.killindicator.classname = "drag_digit";
438 e.killindicator.killindicator.owner = e;
439 setattachment(e.killindicator.killindicator, e, "");
440 setorigin(e.killindicator.killindicator, '0 0 8');
443 case "dragpoint_spawn":
444 IS_CHEAT(0, argc, 0);
446 e.classname = "dragpoint";
447 e.think = DragBox_Think;
449 e.solid = 0; // nothing special
450 setmodel(e, "models/marker.md3");
451 setsize(e, PL_MIN, PL_MAX);
454 e.cnt = stof(argv(1));
456 e.cnt = drag_lastcnt;
458 setorigin(e, stov(argv(2)));
461 crosshair_trace(self);
462 setorigin(e, trace_endpos + normalize(self.origin + self.view_ofs - trace_endpos));
463 move_out_of_solid(e);
466 e.killindicator = spawn();
467 e.killindicator.classname = "drag_digit";
468 e.killindicator.owner = e;
469 setattachment(e.killindicator, e, "");
470 setorigin(e.killindicator, '0 0 40');
471 e.killindicator.killindicator = spawn();
472 e.killindicator.killindicator.classname = "drag_digit";
473 e.killindicator.killindicator.owner = e;
474 setattachment(e.killindicator.killindicator, e, "");
475 setorigin(e.killindicator.killindicator, '0 0 56');
479 IS_CHEAT(0, argc, 0);
480 RandomSelection_Init();
481 crosshair_trace(self);
482 for(e = world; (e = find(e, classname, "dragbox_box")); )
483 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
484 for(e = world; (e = find(e, classname, "dragpoint")); )
485 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
486 if(RandomSelection_chosen_ent)
488 remove(RandomSelection_chosen_ent.killindicator.killindicator);
489 remove(RandomSelection_chosen_ent.killindicator);
490 if(RandomSelection_chosen_ent.aiment)
491 remove(RandomSelection_chosen_ent.aiment);
492 if(RandomSelection_chosen_ent.enemy)
493 remove(RandomSelection_chosen_ent.enemy);
494 remove(RandomSelection_chosen_ent);
499 IS_CHEAT(0, argc, 0);
502 RandomSelection_Init();
503 crosshair_trace(self);
504 for(e = world; (e = find(e, classname, "dragbox_box")); )
505 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
506 for(e = world; (e = find(e, classname, "dragpoint")); )
507 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
508 if(RandomSelection_chosen_ent)
510 if(substring(argv(1), 0, 1) == "*")
511 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
513 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
518 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
521 IS_CHEAT(0, argc, 0);
524 f = fopen(argv(1), FILE_WRITE);
525 fputs(f, "cmd drag_clear\n");
526 for(e = world; (e = find(e, classname, "dragbox_box")); )
528 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
530 for(e = world; (e = find(e, classname, "dragpoint")); )
532 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
538 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
540 case "drag_saveraceent":
541 IS_CHEAT(0, argc, 0);
544 f = fopen(argv(1), FILE_WRITE);
545 for(e = world; (e = find(e, classname, "dragbox_box")); )
548 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
549 fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
550 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"));
551 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
552 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
555 for(e = world; (e = find(e, classname, "dragpoint")); )
559 for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
561 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
563 start = start + oldself.origin;
567 start *= 1 / effectnum;
569 fputs(f, "\"classname\" \"info_player_race\"\n");
570 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
571 fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
574 fputs(f, "\"target\" \"checkpoint0\"\n");
575 fputs(f, "\"race_place\" \"0\"\n");
579 fputs(f, "\"target\" \"checkpoint0\"\n");
580 fputs(f, "\"race_place\" \"-1\"\n");
584 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
587 // these need race_place
590 for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
593 if(vlen(oldself.origin - start) < vlen(e.origin - start))
595 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
598 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
607 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
610 IS_CHEAT(0, argc, 0);
611 for(e = world; (e = find(e, classname, "dragbox_box")); )
613 for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
615 for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
617 for(e = world; (e = find(e, classname, "dragpoint")); )
619 for(e = world; (e = find(e, classname, "drag_digit")); )
624 IS_CHEAT(0, argc, 0);
625 BITXOR_ASSIGN(self.flags, FL_GODMODE);
626 if(self.flags & FL_GODMODE)
628 sprint(self, "godmode ON\n");
632 sprint(self, "godmode OFF\n");
635 IS_CHEAT(0, argc, 0);
636 BITXOR_ASSIGN(self.flags, FL_NOTARGET);
637 if(self.flags & FL_NOTARGET)
639 sprint(self, "notarget ON\n");
643 sprint(self, "notarget OFF\n");
646 IS_CHEAT(0, argc, 0);
647 if(self.movetype != MOVETYPE_NOCLIP)
649 self.movetype = MOVETYPE_NOCLIP;
650 sprint(self, "noclip ON\n");
655 self.movetype = MOVETYPE_WALK;
656 sprint(self, "noclip OFF\n");
660 IS_CHEAT(0, argc, 0);
661 if(self.movetype != MOVETYPE_FLY)
663 self.movetype = MOVETYPE_FLY;
664 sprint(self, "flymode ON\n");
669 self.movetype = MOVETYPE_WALK;
670 sprint(self, "flymode OFF\n");
674 IS_CHEAT(0, argc, 0);
675 if(GiveItems(self, 1, argc))
679 IS_CHEAT(0, argc, 0);
682 self.target = argv(1);
690 IS_CHEAT(0, argc, 0);
693 self.killtarget = argv(1);
700 case "teleporttotarget":
701 IS_CHEAT(0, argc, 0);
704 setorigin(self, self.origin);
705 self.classname = "cheattriggerteleport";
706 self.target = argv(1);
707 teleport_findtarget();
710 Simple_TeleportPlayer(self, e);
720 END_CHEAT_FUNCTION();
723 float Drag(float force_allow_pick, float ischeat);
724 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
725 void Drag_Finish(entity dragger);
726 float Drag_IsDraggable(entity draggee);
727 float Drag_MayChangeAngles(entity draggee);
728 void Drag_MoveForward(entity dragger);
729 void Drag_SetSpeed(entity dragger, float s);
730 void Drag_MoveBackward(entity dragger);
731 void Drag_Update(entity dragger);
732 float Drag_CanDrag(entity dragger);
733 float Drag_IsDragging(entity dragger);
734 void Drag_MoveDrag(entity from, entity to);
739 BEGIN_CHEAT_FUNCTION();
741 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
742 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
743 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
744 // grabbing itself no longer being accounted as cheating.
749 if(self.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
751 // use cheat dragging if cheats are enabled
752 crosshair_trace_plusvisibletriggers(self);
757 Drag(FALSE, FALSE); // execute dragging
762 END_CHEAT_FUNCTION();
771 float Drag(float force_allow_pick, float ischeat)
773 BEGIN_CHEAT_FUNCTION();
775 // returns TRUE when an entity has been picked up
776 // If pick is TRUE, the object can also be picked up if it's not being held already
777 // If pick is FALSE, only keep dragging the object if it's already being held
782 if(Drag_IsDragging(self))
786 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
788 Drag_MoveForward(self);
791 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
793 Drag_MoveBackward(self);
796 else if(self.impulse >= 1 && self.impulse <= 9)
798 Drag_SetSpeed(self, self.impulse - 1);
800 else if(self.impulse == 14)
802 Drag_SetSpeed(self, 9);
815 if(Drag_CanDrag(self))
818 crosshair_trace_plusvisibletriggers(self);
819 entity e = trace_ent;
820 float pick = force_allow_pick;
823 // pick is TRUE if the object can be picked up. While an object is being carried, the Drag() function
824 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
825 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
826 // it goes out of range while slinging it around.
828 if(vlen(self.origin - e.origin) <= autocvar_g_grab_range)
832 case 0: // can't grab
834 case 1: // owner can grab
835 if(e.owner == self || e.realowner == self)
838 case 2: // owner and team mates can grab
839 if(SAME_TEAM(e.owner, self) || SAME_TEAM(e.realowner, self) || e.team == self.team)
842 case 3: // anyone can grab
852 if(Drag_IsDraggable(e))
855 IS_CHEAT(0, 0, CHRAME_DRAG);
857 Drag_Finish(e.draggedby);
859 detach_sameorigin(e);
860 Drag_Begin(self, e, trace_endpos);
874 .float dragspeed; // speed of mouse wheel action
875 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
876 .vector draglocalvector; // local attachment vector of the dragentity
877 .float draglocalangle;
881 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
885 draggee.dragmovetype = draggee.movetype;
886 draggee.draggravity = draggee.gravity;
887 draggee.movetype = MOVETYPE_WALK;
888 draggee.gravity = 0.00001;
889 draggee.flags &= ~FL_ONGROUND;
890 draggee.draggedby = dragger;
892 dragger.dragentity = draggee;
894 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
895 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
896 touchpoint = touchpoint - gettaginfo(draggee, 0);
897 tagscale = pow(vlen(v_forward), -2);
898 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
899 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
900 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
902 dragger.dragspeed = 64;
905 void Drag_Finish(entity dragger)
908 draggee = dragger.dragentity;
910 dragger.dragentity = world;
911 draggee.draggedby = world;
912 draggee.movetype = draggee.dragmovetype;
913 draggee.gravity = draggee.draggravity;
915 switch(draggee.movetype)
920 case MOVETYPE_FLYMISSILE:
921 case MOVETYPE_BOUNCE:
922 case MOVETYPE_BOUNCEMISSILE:
923 case MOVETYPE_PHYSICS:
926 draggee.velocity = '0 0 0';
930 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
932 draggee.velocity = '0 0 0';
933 draggee.flags |= FL_ONGROUND; // floating items are FUN
937 float Drag_IsDraggable(entity draggee)
939 // TODO add more checks for bad stuff here
942 if(draggee.classname == "func_bobbing")
944 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)
946 if(draggee.classname == "plat")
948 if(draggee.classname == "func_button")
950 // if(draggee.model == "")
954 if(IS_OBSERVER(draggee))
956 if(draggee.classname == "exteriorweaponentity")
958 if(draggee.classname == "weaponentity")
964 float Drag_MayChangeAngles(entity draggee)
966 // TODO add more checks for bad stuff here
967 if(substring(draggee.model, 0, 1) == "*")
972 void Drag_MoveForward(entity dragger)
974 dragger.dragdistance += dragger.dragspeed;
977 void Drag_SetSpeed(entity dragger, float s)
979 dragger.dragspeed = pow(2, s);
982 void Drag_MoveBackward(entity dragger)
984 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
987 void Drag_Update(entity dragger)
989 vector curorigin, neworigin, goodvelocity;
993 draggee = dragger.dragentity;
994 draggee.flags &= ~FL_ONGROUND;
996 curorigin = gettaginfo(draggee, 0);
997 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
998 makevectors(dragger.v_angle);
999 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
1000 goodvelocity = (neworigin - curorigin) * (1 / frametime);
1002 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
1003 dragger.draglocalangle += 360;
1004 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
1005 dragger.draglocalangle -= 360;
1007 f = min(frametime * 10, 1);
1008 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
1010 if(Drag_MayChangeAngles(draggee))
1011 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
1013 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
1015 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
1018 float Drag_CanDrag(entity dragger)
1020 return (dragger.deadflag == DEAD_NO) || (IS_PLAYER(dragger));
1023 float Drag_IsDragging(entity dragger)
1025 if(!dragger.dragentity)
1027 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1029 dragger.dragentity = world;
1032 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
1034 Drag_Finish(dragger);
1040 void Drag_MoveDrag(entity from, entity to)
1044 to.draggedby = from.draggedby;
1045 to.draggedby.dragentity = to;
1046 from.draggedby = world;
1050 void DragBox_Think()
1052 if(self.aiment && self.enemy)
1054 self.origin_x = (self.aiment.origin_x + self.enemy.origin_x) * 0.5;
1055 self.origin_y = (self.aiment.origin_y + self.enemy.origin_y) * 0.5;
1056 self.origin_z = (self.aiment.origin_z + self.enemy.origin_z) * 0.5;
1057 self.maxs_x = fabs(self.aiment.origin_x - self.enemy.origin_x) * 0.5;
1058 self.maxs_y = fabs(self.aiment.origin_y - self.enemy.origin_y) * 0.5;
1059 self.maxs_z = fabs(self.aiment.origin_z - self.enemy.origin_z) * 0.5;
1060 self.mins = -1 * self.maxs;
1061 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
1064 if(self.cnt == -1) // actually race_place -1
1066 // show "10 10" for qualifying spawns
1067 setmodel(self.killindicator, "models/sprites/10.spr32");
1068 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
1070 else if(self.cnt == -2) // actually race_place 0
1072 // show "10 0" for loser spawns
1073 setmodel(self.killindicator, "models/sprites/10.spr32");
1074 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
1078 setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
1079 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
1082 self.nextthink = time;