6 #include "t_teleporters.qh"
8 #include "mutators/mutators_include.qh"
10 #include "weapons/tracing.qh"
12 #include "../common/constants.qh"
13 #include "../common/deathtypes.qh"
14 #include "../common/util.qh"
16 #include "../common/monsters/all.qh"
18 #include "../common/weapons/all.qh"
20 #include "../csqcmodellib/sv_model.qh"
22 #include "../warpzonelib/anglestransform.qh"
23 #include "../warpzonelib/util_server.qh"
25 void CopyBody(float keepvelocity);
29 float CheatImpulse(float i) { return 0; }
30 float CheatCommand(float argc) { return 0; }
31 float CheatFrame() { return 0; }
32 void CheatInit() { cheatcount_total = world.cheatcount; }
33 void CheatShutdown() { }
34 void CheatInitClient() { }
35 void CheatShutdownClient() { }
36 void Drag_MoveDrag(entity from, entity to) { }
41 float gamestart_sv_cheats;
47 gamestart_sv_cheats = autocvar_sv_cheats;
54 void CheatInitClient()
58 void CheatShutdownClient()
62 float CheatsAllowed(float i, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking
64 // dead people cannot cheat
65 if(self.deadflag != DEAD_NO)
67 if(gamestart_sv_cheats < 2 && !IS_PLAYER(self))
71 if(i == CHIMPULSE_CLONE_MOVING || i == CHIMPULSE_CLONE_STANDING)
72 if(self.lip < sv_clones)
80 if(gamestart_sv_cheats && autocvar_sv_cheats)
83 // if we get here, player is not allowed to cheat. Log it.
85 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", self.netname, i);
87 bprintf("Player %s^7 tried to use cheat '%s'\n", self.netname, argv(0));
89 bprintf("Player %s^7 tried to use cheat frame %d\n", self.netname, fr);
91 bprintf("Player %s^7 tried to use an unknown cheat\n", self.netname);
96 #define BEGIN_CHEAT_FUNCTION() \
97 float cheating, attempting; \
98 cheating = 0; attempting = 0
101 #define ADD_CHEATS(e,n) \
102 cheatcount_total += n; \
104 #define END_CHEAT_FUNCTION() \
105 ADD_CHEATS(self,cheating); \
107 #define IS_CHEAT(i,argc,fr) \
108 if((++attempting, !CheatsAllowed(i,argc,fr))) \
111 float num_autoscreenshot;
112 void info_autoscreenshot_findtarget()
115 e = find(world, targetname, self.target);
118 objerror("Missing target. FAIL!");
121 vector a = vectoangles(e.origin - self.origin);
122 a.x = -a.x; // don't ask
125 // we leave Rick Roll alone
127 void spawnfunc_info_autoscreenshot()
129 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
131 objerror("Too many info_autoscreenshot entitites. FAIL!");
134 if(self.target != "")
135 InitializeEntity(self, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
136 // this one just has to exist
139 float CheatImpulse(float i)
141 BEGIN_CHEAT_FUNCTION();
146 case CHIMPULSE_SPEEDRUN_INIT: // deploy personal waypoint
147 // shared with regular waypoint init, so this is not a cheat by itself
150 self.personal = spawn();
151 self.personal.classname = "personal_wp";
153 self.personal.origin = self.origin;
154 self.personal.v_angle = self.v_angle;
155 self.personal.velocity = self.velocity;
156 self.personal.ammo_rockets = self.ammo_rockets;
157 self.personal.ammo_nails = self.ammo_nails;
158 self.personal.ammo_cells = self.ammo_cells;
159 self.personal.ammo_plasma = self.ammo_plasma;
160 self.personal.ammo_shells = self.ammo_shells;
161 self.personal.ammo_fuel = self.ammo_fuel;
162 self.personal.health = self.health;
163 self.personal.armorvalue = self.armorvalue;
164 self.personal.weapons = self.weapons;
165 self.personal.items = self.items;
166 self.personal.pauserotarmor_finished = self.pauserotarmor_finished;
167 self.personal.pauserothealth_finished = self.pauserothealth_finished;
168 self.personal.pauserotfuel_finished = self.pauserotfuel_finished;
169 self.personal.pauseregen_finished = self.pauseregen_finished;
170 self.personal.strength_finished = self.strength_finished;
171 self.personal.invincible_finished = self.invincible_finished;
172 self.personal.teleport_time = time;
173 break; // this part itself doesn't cheat, so let's not count this
174 case CHIMPULSE_CLONE_MOVING:
176 makevectors (self.v_angle);
177 self.velocity = self.velocity + v_forward * 300;
180 self.velocity = self.velocity - v_forward * 300;
183 case CHIMPULSE_CLONE_STANDING:
189 case CHIMPULSE_GIVE_ALL:
191 CheatCommand(tokenize_console("give all"));
192 break; // already counted as cheat
193 case CHIMPULSE_SPEEDRUN:
197 self.speedrunning = true;
198 tracebox(self.personal.origin, self.mins, self.maxs, self.personal.origin, MOVE_WORLDONLY, self);
201 sprint(self, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
205 // Abort speedrun, teleport back
206 setorigin(self, self.personal.origin);
207 self.oldvelocity = self.velocity = self.personal.velocity;
208 self.angles = self.personal.v_angle;
209 self.fixangle = true;
211 MUTATOR_CALLHOOK(AbortSpeedrun);
214 self.ammo_rockets = self.personal.ammo_rockets;
215 self.ammo_nails = self.personal.ammo_nails;
216 self.ammo_cells = self.personal.ammo_cells;
217 self.ammo_plasma = self.personal.ammo_plasma;
218 self.ammo_shells = self.personal.ammo_shells;
219 self.ammo_fuel = self.personal.ammo_fuel;
220 self.health = self.personal.health;
221 self.armorvalue = self.personal.armorvalue;
222 self.weapons = self.personal.weapons;
223 self.items = self.personal.items;
224 self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
225 self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
226 self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
227 self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
228 self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
229 self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
234 if(self.deadflag != DEAD_NO)
235 sprint(self, "UR DEAD AHAHAH))\n");
237 sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
239 case CHIMPULSE_TELEPORT:
241 if(self.movetype == MOVETYPE_NOCLIP)
243 e = find(world, classname, "info_autoscreenshot");
246 sprint(self, "Emergency teleport used info_autoscreenshot location\n");
247 setorigin(self, e.origin);
248 self.angles = e.angles;
250 // should we? self.angles_x = -self.angles_x;
251 self.fixangle = true;
252 self.velocity = '0 0 0';
257 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))
259 sprint(self, "Emergency teleport used random location\n");
260 self.angles_x = -self.angles.x;
261 self.fixangle = true;
262 self.velocity = '0 0 0';
266 sprint(self, "Emergency teleport could not find a good location, forget it!\n");
270 RandomSelection_Init();
272 if(e.deadflag == DEAD_NO)
273 if(DIFF_TEAM(e, self))
274 RandomSelection_Add(e, 0, string_null, 1, 1);
275 if(RandomSelection_chosen_ent)
276 e = RandomSelection_chosen_ent;
280 pointparticles(particleeffectnum("rocket_explode"), e.origin, '0 0 0', 1);
281 sound(e, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
284 setorigin(e2, e.origin);
285 RadiusDamage(e2, self, 1000, 0, 128, world, world, 500, DEATH_CHEAT, e);
288 print("404 Sportsmanship not found.\n");
293 END_CHEAT_FUNCTION();
296 void DragBox_Think();
298 float CheatCommand(float argc)
300 BEGIN_CHEAT_FUNCTION();
310 case "pointparticles":
311 IS_CHEAT(0, argc, 0);
316 // origin (0..1, on crosshair line)
319 effectnum = particleeffectnum(argv(1));
321 crosshair_trace(self);
322 start = (1-f) * self.origin + f * trace_endpos;
325 pointparticles(effectnum, start, end, f);
329 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
331 case "trailparticles":
332 IS_CHEAT(0, argc, 0);
337 effectnum = particleeffectnum(argv(1));
338 W_SetupShot(self, false, false, "", CH_WEAPON_A, 0);
339 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
340 trailparticles(self, effectnum, w_shotorg, trace_endpos);
344 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
347 IS_CHEAT(0, argc, 0);
353 W_SetupShot(self, false, false, "", CH_WEAPON_A, 0);
354 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
355 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
357 sprint(self, "cannot make stuff there (bad surface)\n");
362 e.model = strzone(argv(1));
363 e.mdl = "rocket_explode";
365 setorigin(e, trace_endpos);
366 e.effects = EF_NOMODELFLAGS;
369 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
370 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
374 spawnfunc_func_breakable();
379 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
383 sprint(self, "cannot make stuff there (no space)\n");
393 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
396 IS_CHEAT(0, argc, 0);
399 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
403 sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
405 case "dragbox_spawn":
406 IS_CHEAT(0, argc, 0);
408 e.classname = "dragbox_box";
409 e.think = DragBox_Think;
411 e.solid = -1; // black
412 setmodel(e, "null"); // network it
414 e.cnt = stof(argv(1));
416 e.cnt = max(0, drag_lastcnt);
419 e.aiment.classname = "dragbox_corner_1";
421 setmodel(e.aiment, "models/marker.md3");
423 setsize(e.aiment, '0 0 0', '0 0 0');
425 setorigin(e.aiment, stov(argv(2)));
428 crosshair_trace(self);
429 setorigin(e.aiment, trace_endpos);
433 e.enemy.classname = "dragbox_corner_2";
435 setmodel(e.enemy, "models/marker.md3");
437 setsize(e.enemy, '0 0 0', '0 0 0');
438 end = normalize(self.origin + self.view_ofs - e.aiment.origin);
439 end.x = (end.x > 0) * 2 - 1;
440 end.y = (end.y > 0) * 2 - 1;
441 end.z = (end.z > 0) * 2 - 1;
443 setorigin(e.enemy, stov(argv(3)));
445 setorigin(e.enemy, e.aiment.origin + 32 * end);
447 e.killindicator = spawn();
448 e.killindicator.classname = "drag_digit";
449 e.killindicator.owner = e;
450 setattachment(e.killindicator, e, "");
451 setorigin(e.killindicator, '0 0 -8');
452 e.killindicator.killindicator = spawn();
453 e.killindicator.killindicator.classname = "drag_digit";
454 e.killindicator.killindicator.owner = e;
455 setattachment(e.killindicator.killindicator, e, "");
456 setorigin(e.killindicator.killindicator, '0 0 8');
459 case "dragpoint_spawn":
460 IS_CHEAT(0, argc, 0);
462 e.classname = "dragpoint";
463 e.think = DragBox_Think;
465 e.solid = 0; // nothing special
466 setmodel(e, "models/marker.md3");
467 setsize(e, PL_MIN, PL_MAX);
470 e.cnt = stof(argv(1));
472 e.cnt = drag_lastcnt;
474 setorigin(e, stov(argv(2)));
477 crosshair_trace(self);
478 setorigin(e, trace_endpos + normalize(self.origin + self.view_ofs - trace_endpos));
479 move_out_of_solid(e);
482 e.killindicator = spawn();
483 e.killindicator.classname = "drag_digit";
484 e.killindicator.owner = e;
485 setattachment(e.killindicator, e, "");
486 setorigin(e.killindicator, '0 0 40');
487 e.killindicator.killindicator = spawn();
488 e.killindicator.killindicator.classname = "drag_digit";
489 e.killindicator.killindicator.owner = e;
490 setattachment(e.killindicator.killindicator, e, "");
491 setorigin(e.killindicator.killindicator, '0 0 56');
495 IS_CHEAT(0, argc, 0);
496 RandomSelection_Init();
497 crosshair_trace(self);
498 for(e = world; (e = find(e, classname, "dragbox_box")); )
499 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
500 for(e = world; (e = find(e, classname, "dragpoint")); )
501 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
502 if(RandomSelection_chosen_ent)
504 remove(RandomSelection_chosen_ent.killindicator.killindicator);
505 remove(RandomSelection_chosen_ent.killindicator);
506 if(RandomSelection_chosen_ent.aiment)
507 remove(RandomSelection_chosen_ent.aiment);
508 if(RandomSelection_chosen_ent.enemy)
509 remove(RandomSelection_chosen_ent.enemy);
510 remove(RandomSelection_chosen_ent);
515 IS_CHEAT(0, argc, 0);
518 RandomSelection_Init();
519 crosshair_trace(self);
520 for(e = world; (e = find(e, classname, "dragbox_box")); )
521 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
522 for(e = world; (e = find(e, classname, "dragpoint")); )
523 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
524 if(RandomSelection_chosen_ent)
526 if(substring(argv(1), 0, 1) == "*")
527 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
529 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
534 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
537 IS_CHEAT(0, argc, 0);
540 f = fopen(argv(1), FILE_WRITE);
541 fputs(f, "cmd drag_clear\n");
542 for(e = world; (e = find(e, classname, "dragbox_box")); )
544 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
546 for(e = world; (e = find(e, classname, "dragpoint")); )
548 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
554 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
556 case "drag_saveraceent":
557 IS_CHEAT(0, argc, 0);
560 f = fopen(argv(1), FILE_WRITE);
561 for(e = world; (e = find(e, classname, "dragbox_box")); )
564 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
565 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
566 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"));
567 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
568 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
571 for(e = world; (e = find(e, classname, "dragpoint")); )
575 for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
577 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
579 start = start + oldself.origin;
583 start *= 1 / effectnum;
585 fputs(f, "\"classname\" \"info_player_race\"\n");
586 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
587 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
590 fputs(f, "\"target\" \"checkpoint0\"\n");
591 fputs(f, "\"race_place\" \"0\"\n");
595 fputs(f, "\"target\" \"checkpoint0\"\n");
596 fputs(f, "\"race_place\" \"-1\"\n");
600 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
603 // these need race_place
606 for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
609 if(vlen(oldself.origin - start) < vlen(e.origin - start))
611 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
614 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
623 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
626 IS_CHEAT(0, argc, 0);
627 for(e = world; (e = find(e, classname, "dragbox_box")); )
629 for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
631 for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
633 for(e = world; (e = find(e, classname, "dragpoint")); )
635 for(e = world; (e = find(e, classname, "drag_digit")); )
640 IS_CHEAT(0, argc, 0);
641 BITXOR_ASSIGN(self.flags, FL_GODMODE);
642 if(self.flags & FL_GODMODE)
644 sprint(self, "godmode ON\n");
648 sprint(self, "godmode OFF\n");
651 IS_CHEAT(0, argc, 0);
652 BITXOR_ASSIGN(self.flags, FL_NOTARGET);
653 if(self.flags & FL_NOTARGET)
655 sprint(self, "notarget ON\n");
659 sprint(self, "notarget OFF\n");
662 IS_CHEAT(0, argc, 0);
663 if(self.movetype != MOVETYPE_NOCLIP)
665 self.movetype = MOVETYPE_NOCLIP;
666 sprint(self, "noclip ON\n");
671 self.movetype = MOVETYPE_WALK;
672 sprint(self, "noclip OFF\n");
676 IS_CHEAT(0, argc, 0);
677 if(self.movetype != MOVETYPE_FLY)
679 self.movetype = MOVETYPE_FLY;
680 sprint(self, "flymode ON\n");
685 self.movetype = MOVETYPE_WALK;
686 sprint(self, "flymode OFF\n");
690 IS_CHEAT(0, argc, 0);
691 if(GiveItems(self, 1, argc))
695 IS_CHEAT(0, argc, 0);
698 self.target = argv(1);
706 IS_CHEAT(0, argc, 0);
709 self.killtarget = argv(1);
716 case "teleporttotarget":
717 IS_CHEAT(0, argc, 0);
720 setorigin(self, self.origin);
721 self.classname = "cheattriggerteleport";
722 self.target = argv(1);
723 teleport_findtarget();
726 Simple_TeleportPlayer(self, e);
736 END_CHEAT_FUNCTION();
739 float Drag(float force_allow_pick, float ischeat);
740 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
741 void Drag_Finish(entity dragger);
742 float Drag_IsDraggable(entity draggee);
743 float Drag_MayChangeAngles(entity draggee);
744 void Drag_MoveForward(entity dragger);
745 void Drag_SetSpeed(entity dragger, float s);
746 void Drag_MoveBackward(entity dragger);
747 void Drag_Update(entity dragger);
748 float Drag_CanDrag(entity dragger);
749 float Drag_IsDragging(entity dragger);
750 void Drag_MoveDrag(entity from, entity to);
755 BEGIN_CHEAT_FUNCTION();
757 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
758 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
759 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
760 // grabbing itself no longer being accounted as cheating.
765 if(self.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
767 // use cheat dragging if cheats are enabled
768 crosshair_trace_plusvisibletriggers(self);
773 Drag(false, false); // execute dragging
778 END_CHEAT_FUNCTION();
789 .float dragspeed; // speed of mouse wheel action
790 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
791 .vector draglocalvector; // local attachment vector of the dragentity
792 .float draglocalangle;
797 float Drag(float force_allow_pick, float ischeat)
799 BEGIN_CHEAT_FUNCTION();
801 // returns true when an entity has been picked up
802 // If pick is true, the object can also be picked up if it's not being held already
803 // If pick is false, only keep dragging the object if it's already being held
808 if(Drag_IsDragging(self))
812 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
814 Drag_MoveForward(self);
817 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
819 Drag_MoveBackward(self);
822 else if(self.impulse >= 1 && self.impulse <= 9)
824 Drag_SetSpeed(self, self.impulse - 1);
826 else if(self.impulse == 14)
828 Drag_SetSpeed(self, 9);
841 if(Drag_CanDrag(self))
844 crosshair_trace_plusvisibletriggers(self);
845 entity e = trace_ent;
846 float pick = force_allow_pick;
849 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
850 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
851 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
852 // it goes out of range while slinging it around.
854 if(vlen(self.origin - e.origin) <= autocvar_g_grab_range)
858 case 0: // can't grab
860 case 1: // owner can grab
861 if(e.owner == self || e.realowner == self)
864 case 2: // owner and team mates can grab
865 if(SAME_TEAM(e.owner, self) || SAME_TEAM(e.realowner, self) || e.team == self.team)
868 case 3: // anyone can grab
878 if(Drag_IsDraggable(e))
881 IS_CHEAT(0, 0, CHRAME_DRAG);
883 Drag_Finish(e.draggedby);
885 detach_sameorigin(e);
886 Drag_Begin(self, e, trace_endpos);
898 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
902 draggee.dragmovetype = draggee.movetype;
903 draggee.draggravity = draggee.gravity;
904 draggee.movetype = MOVETYPE_WALK;
905 draggee.gravity = 0.00001;
906 draggee.flags &= ~FL_ONGROUND;
907 draggee.draggedby = dragger;
909 dragger.dragentity = draggee;
911 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
912 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
913 touchpoint = touchpoint - gettaginfo(draggee, 0);
914 tagscale = pow(vlen(v_forward), -2);
915 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
916 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
917 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
919 dragger.dragspeed = 64;
922 void Drag_Finish(entity dragger)
925 draggee = dragger.dragentity;
927 dragger.dragentity = world;
928 draggee.draggedby = world;
929 draggee.movetype = draggee.dragmovetype;
930 draggee.gravity = draggee.draggravity;
932 switch(draggee.movetype)
937 case MOVETYPE_FLYMISSILE:
938 case MOVETYPE_BOUNCE:
939 case MOVETYPE_BOUNCEMISSILE:
940 case MOVETYPE_PHYSICS:
943 draggee.velocity = '0 0 0';
947 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
949 draggee.velocity = '0 0 0';
950 draggee.flags |= FL_ONGROUND; // floating items are FUN
954 float Drag_IsDraggable(entity draggee)
956 // TODO add more checks for bad stuff here
959 if(draggee.classname == "func_bobbing")
961 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)
963 if(draggee.classname == "plat")
965 if(draggee.classname == "func_button")
967 // if(draggee.model == "")
971 if(IS_OBSERVER(draggee))
973 if(draggee.classname == "exteriorweaponentity")
975 if(draggee.classname == "weaponentity")
981 float Drag_MayChangeAngles(entity draggee)
983 // TODO add more checks for bad stuff here
984 if(substring(draggee.model, 0, 1) == "*")
989 void Drag_MoveForward(entity dragger)
991 dragger.dragdistance += dragger.dragspeed;
994 void Drag_SetSpeed(entity dragger, float s)
996 dragger.dragspeed = pow(2, s);
999 void Drag_MoveBackward(entity dragger)
1001 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
1004 void Drag_Update(entity dragger)
1006 vector curorigin, neworigin, goodvelocity;
1010 draggee = dragger.dragentity;
1011 draggee.flags &= ~FL_ONGROUND;
1013 curorigin = gettaginfo(draggee, 0);
1014 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
1015 makevectors(dragger.v_angle);
1016 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
1017 goodvelocity = (neworigin - curorigin) * (1 / frametime);
1019 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
1020 dragger.draglocalangle += 360;
1021 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
1022 dragger.draglocalangle -= 360;
1024 f = min(frametime * 10, 1);
1025 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
1027 if(Drag_MayChangeAngles(draggee))
1028 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
1030 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
1032 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
1035 float Drag_CanDrag(entity dragger)
1037 return (dragger.deadflag == DEAD_NO) || (IS_PLAYER(dragger));
1040 float Drag_IsDragging(entity dragger)
1042 if(!dragger.dragentity)
1044 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1046 dragger.dragentity = world;
1049 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
1051 Drag_Finish(dragger);
1057 void Drag_MoveDrag(entity from, entity to)
1061 to.draggedby = from.draggedby;
1062 to.draggedby.dragentity = to;
1063 from.draggedby = world;
1067 void DragBox_Think()
1069 if(self.aiment && self.enemy)
1071 self.origin_x = (self.aiment.origin.x + self.enemy.origin.x) * 0.5;
1072 self.origin_y = (self.aiment.origin.y + self.enemy.origin.y) * 0.5;
1073 self.origin_z = (self.aiment.origin.z + self.enemy.origin.z) * 0.5;
1074 self.maxs_x = fabs(self.aiment.origin.x - self.enemy.origin.x) * 0.5;
1075 self.maxs_y = fabs(self.aiment.origin.y - self.enemy.origin.y) * 0.5;
1076 self.maxs_z = fabs(self.aiment.origin.z - self.enemy.origin.z) * 0.5;
1077 self.mins = -1 * self.maxs;
1078 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
1081 if(self.cnt == -1) // actually race_place -1
1083 // show "10 10" for qualifying spawns
1084 setmodel(self.killindicator, "models/sprites/10.spr32");
1085 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
1087 else if(self.cnt == -2) // actually race_place 0
1089 // show "10 0" for loser spawns
1090 setmodel(self.killindicator, "models/sprites/10.spr32");
1091 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
1095 setmodel(self.killindicator, strcat("models/sprites/", ftos(self.cnt % 10), ".spr32"));
1096 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
1099 self.nextthink = time;