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(self.classname != "player")
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 bprint(sprintf("Player %s^7 tried to use cheat 'impulse %d'\n", self.netname, i));
71 bprint(sprintf("Player %s^7 tried to use cheat '%s'\n", self.netname, argv(0)));
73 bprint(sprintf("Player %s^7 tried to use cheat frame %d\n", self.netname, fr));
75 bprint(sprintf("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();
131 case CHIMPULSE_SPEEDRUN_INIT: // deploy personal waypoint
132 // shared with regular waypoint init, so this is not a cheat by itself
135 self.personal = spawn();
136 self.personal.classname = "personal_wp";
138 self.personal.origin = self.origin;
139 self.personal.v_angle = self.v_angle;
140 self.personal.velocity = self.velocity;
141 self.personal.ammo_rockets = self.ammo_rockets;
142 self.personal.ammo_nails = self.ammo_nails;
143 self.personal.ammo_cells = self.ammo_cells;
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 WEPSET_COPY_EE(self.personal, self);
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;
196 bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
197 ReturnFlag(self.flagcarried);
202 self.ammo_rockets = 999;
203 self.ammo_nails = 999;
204 self.ammo_cells = 999;
205 self.ammo_shells = 999;
206 self.ammo_fuel = 999;
207 self.health = start_health;
208 self.armorvalue = start_armorvalue;
209 WEPSET_OR_EA(self.personal, weaponsInMap);
210 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
211 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
212 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
213 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
214 self.strength_finished = 0;
215 self.invincible_finished = 0;
219 self.ammo_rockets = self.personal.ammo_rockets;
220 self.ammo_nails = self.personal.ammo_nails;
221 self.ammo_cells = self.personal.ammo_cells;
222 self.ammo_shells = self.personal.ammo_shells;
223 self.ammo_fuel = self.personal.ammo_fuel;
224 self.health = self.personal.health;
225 self.armorvalue = self.personal.armorvalue;
226 WEPSET_COPY_EE(self, self.personal);
227 self.items = self.personal.items;
228 self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
229 self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
230 self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
231 self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
232 self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
233 self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
238 if(self.deadflag != DEAD_NO)
239 sprint(self, "UR DEAD AHAHAH))\n");
241 sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
243 case CHIMPULSE_TELEPORT:
245 if(self.movetype == MOVETYPE_NOCLIP)
247 e = find(world, classname, "info_autoscreenshot");
250 sprint(self, "Emergency teleport used info_autoscreenshot location\n");
251 setorigin(self, e.origin);
252 self.angles = e.angles;
254 // should we? self.angles_x = -self.angles_x;
255 self.fixangle = TRUE;
256 self.velocity = '0 0 0';
261 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) ? 100000 : 100), 1024, 256))
263 sprint(self, "Emergency teleport used random location\n");
264 self.angles_x = -self.angles_x;
265 self.fixangle = TRUE;
266 self.velocity = '0 0 0';
270 sprint(self, "Emergency teleport could not find a good location, forget it!\n");
276 get_model_parameters(e.playermodel, e.skin);
277 if(get_model_parameters_sex == "Female")
279 makevectors(e.angles);
280 traceline(e.origin, e.origin + v_right * 256, MOVE_NORMAL, e);
287 org = normalize(org);
288 traceline(e.origin, e.origin + org * 256, MOVE_NORMAL, e); // random direction
291 org = findbetterlocation(trace_endpos, 12);
295 pointparticles(particleeffectnum("rocket_explode"), org, '0 0 0', 1);
296 sound(e2, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
297 RadiusDamage(e2, e, 1000, 0, 128, e, 500, DEATH_CHEAT, world);
300 print("404 Sportsmanship not found.\n");
305 END_CHEAT_FUNCTION();
308 void DragBox_Think();
310 float CheatCommand(float argc)
312 BEGIN_CHEAT_FUNCTION();
322 case "pointparticles":
323 IS_CHEAT(0, argc, 0);
328 // origin (0..1, on crosshair line)
331 effectnum = particleeffectnum(argv(1));
333 crosshair_trace(self);
334 start = (1-f) * self.origin + f * trace_endpos;
337 pointparticles(effectnum, start, end, f);
341 sprint(self, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
343 case "trailparticles":
344 IS_CHEAT(0, argc, 0);
349 effectnum = particleeffectnum(argv(1));
350 W_SetupShot(self, FALSE, FALSE, "", CH_WEAPON_A, 0);
351 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
352 trailparticles(self, effectnum, w_shotorg, trace_endpos);
356 sprint(self, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
359 IS_CHEAT(0, argc, 0);
365 W_SetupShot(self, FALSE, FALSE, "", CH_WEAPON_A, 0);
366 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, self);
367 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
369 sprint(self, "cannot make stuff there (bad surface)\n");
374 e.model = strzone(argv(1));
375 e.mdl = "rocket_explode";
377 setorigin(e, trace_endpos);
378 e.effects = EF_NOMODELFLAGS;
381 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
382 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
386 spawnfunc_func_breakable();
391 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
395 sprint(self, "cannot make stuff there (no space)\n");
405 sprint(self, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
408 IS_CHEAT(0, argc, 0);
411 race_ImposePenaltyTime(self, stof(argv(1)), argv(2));
415 sprint(self, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
417 case "dragbox_spawn":
418 IS_CHEAT(0, argc, 0);
420 e.classname = "dragbox_box";
421 e.think = DragBox_Think;
423 e.solid = -1; // black
424 setmodel(e, "null"); // network it
426 e.cnt = stof(argv(1));
428 e.cnt = max(0, drag_lastcnt);
431 e.aiment.classname = "dragbox_corner_1";
433 setmodel(e.aiment, "models/marker.md3");
435 setsize(e.aiment, '0 0 0', '0 0 0');
437 setorigin(e.aiment, stov(argv(2)));
440 crosshair_trace(self);
441 setorigin(e.aiment, trace_endpos);
445 e.enemy.classname = "dragbox_corner_2";
447 setmodel(e.enemy, "models/marker.md3");
449 setsize(e.enemy, '0 0 0', '0 0 0');
450 end = normalize(self.origin + self.view_ofs - e.aiment.origin);
451 end_x = (end_x > 0) * 2 - 1;
452 end_y = (end_y > 0) * 2 - 1;
453 end_z = (end_z > 0) * 2 - 1;
455 setorigin(e.enemy, stov(argv(3)));
457 setorigin(e.enemy, e.aiment.origin + 32 * end);
459 e.killindicator = spawn();
460 e.killindicator.classname = "drag_digit";
461 e.killindicator.owner = e;
462 setattachment(e.killindicator, e, "");
463 setorigin(e.killindicator, '0 0 -8');
464 e.killindicator.killindicator = spawn();
465 e.killindicator.killindicator.classname = "drag_digit";
466 e.killindicator.killindicator.owner = e;
467 setattachment(e.killindicator.killindicator, e, "");
468 setorigin(e.killindicator.killindicator, '0 0 8');
471 case "dragpoint_spawn":
472 IS_CHEAT(0, argc, 0);
474 e.classname = "dragpoint";
475 e.think = DragBox_Think;
477 e.solid = 0; // nothing special
478 setmodel(e, "models/marker.md3");
479 setsize(e, PL_MIN, PL_MAX);
482 e.cnt = stof(argv(1));
484 e.cnt = drag_lastcnt;
486 setorigin(e, stov(argv(2)));
489 crosshair_trace(self);
490 setorigin(e, trace_endpos + normalize(self.origin + self.view_ofs - trace_endpos));
491 move_out_of_solid(e);
494 e.killindicator = spawn();
495 e.killindicator.classname = "drag_digit";
496 e.killindicator.owner = e;
497 setattachment(e.killindicator, e, "");
498 setorigin(e.killindicator, '0 0 40');
499 e.killindicator.killindicator = spawn();
500 e.killindicator.killindicator.classname = "drag_digit";
501 e.killindicator.killindicator.owner = e;
502 setattachment(e.killindicator.killindicator, e, "");
503 setorigin(e.killindicator.killindicator, '0 0 56');
507 IS_CHEAT(0, argc, 0);
508 RandomSelection_Init();
509 crosshair_trace(self);
510 for(e = world; (e = find(e, classname, "dragbox_box")); )
511 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
512 for(e = world; (e = find(e, classname, "dragpoint")); )
513 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
514 if(RandomSelection_chosen_ent)
516 remove(RandomSelection_chosen_ent.killindicator.killindicator);
517 remove(RandomSelection_chosen_ent.killindicator);
518 if(RandomSelection_chosen_ent.aiment)
519 remove(RandomSelection_chosen_ent.aiment);
520 if(RandomSelection_chosen_ent.enemy)
521 remove(RandomSelection_chosen_ent.enemy);
522 remove(RandomSelection_chosen_ent);
527 IS_CHEAT(0, argc, 0);
530 RandomSelection_Init();
531 crosshair_trace(self);
532 for(e = world; (e = find(e, classname, "dragbox_box")); )
533 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
534 for(e = world; (e = find(e, classname, "dragpoint")); )
535 RandomSelection_Add(e, 0, string_null, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
536 if(RandomSelection_chosen_ent)
538 if(substring(argv(1), 0, 1) == "*")
539 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
541 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
546 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
549 IS_CHEAT(0, argc, 0);
552 f = fopen(argv(1), FILE_WRITE);
553 fputs(f, "cmd drag_clear\n");
554 for(e = world; (e = find(e, classname, "dragbox_box")); )
556 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
558 for(e = world; (e = find(e, classname, "dragpoint")); )
560 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
566 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
568 case "drag_saveraceent":
569 IS_CHEAT(0, argc, 0);
572 f = fopen(argv(1), FILE_WRITE);
573 for(e = world; (e = find(e, classname, "dragbox_box")); )
576 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
577 fputs(f, strcat("\"origin\" \"", ftos(e.absmin_x), " ", ftos(e.absmin_y), " ", ftos(e.absmin_z), "\"\n"));
578 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"));
579 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
580 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
583 for(e = world; (e = find(e, classname, "dragpoint")); )
587 for(oldself = world; (oldself = find(oldself, classname, "dragbox_box")); )
589 if(e.cnt <= 0 && oldself.cnt == 0 || e.cnt == oldself.cnt)
591 start = start + oldself.origin;
595 start *= 1 / effectnum;
597 fputs(f, "\"classname\" \"info_player_race\"\n");
598 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
599 fputs(f, strcat("\"origin\" \"", ftos(e.origin_x), " ", ftos(e.origin_y), " ", ftos(e.origin_z), "\"\n"));
602 fputs(f, "\"target\" \"checkpoint0\"\n");
603 fputs(f, "\"race_place\" \"0\"\n");
607 fputs(f, "\"target\" \"checkpoint0\"\n");
608 fputs(f, "\"race_place\" \"-1\"\n");
612 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
615 // these need race_place
618 for(oldself = world; (oldself = find(oldself, classname, "dragpoint")); )
621 if(vlen(oldself.origin - start) < vlen(e.origin - start))
623 else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
626 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
635 sprint(self, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
638 IS_CHEAT(0, argc, 0);
639 for(e = world; (e = find(e, classname, "dragbox_box")); )
641 for(e = world; (e = find(e, classname, "dragbox_corner_1")); )
643 for(e = world; (e = find(e, classname, "dragbox_corner_2")); )
645 for(e = world; (e = find(e, classname, "dragpoint")); )
647 for(e = world; (e = find(e, classname, "drag_digit")); )
652 IS_CHEAT(0, argc, 0);
653 BITXOR_ASSIGN(self.flags, FL_GODMODE);
654 if(self.flags & FL_GODMODE)
656 sprint(self, "godmode ON\n");
660 sprint(self, "godmode OFF\n");
663 IS_CHEAT(0, argc, 0);
664 BITXOR_ASSIGN(self.flags, FL_NOTARGET);
665 if(self.flags & FL_NOTARGET)
667 sprint(self, "notarget ON\n");
671 sprint(self, "notarget OFF\n");
674 IS_CHEAT(0, argc, 0);
675 if(self.movetype != MOVETYPE_NOCLIP)
677 self.movetype = MOVETYPE_NOCLIP;
678 sprint(self, "noclip ON\n");
683 self.movetype = MOVETYPE_WALK;
684 sprint(self, "noclip OFF\n");
688 IS_CHEAT(0, argc, 0);
689 if(self.movetype != MOVETYPE_FLY)
691 self.movetype = MOVETYPE_FLY;
692 sprint(self, "flymode ON\n");
697 self.movetype = MOVETYPE_WALK;
698 sprint(self, "flymode OFF\n");
702 IS_CHEAT(0, argc, 0);
703 if(GiveItems(self, 1, argc))
708 END_CHEAT_FUNCTION();
711 float Drag(entity e, float grab, float ischeat);
712 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
713 void Drag_Finish(entity dragger);
714 float Drag_IsDraggable(entity draggee);
715 float Drag_MayChangeAngles(entity draggee);
716 void Drag_MoveForward(entity dragger);
717 void Drag_SetSpeed(entity dragger, float s);
718 void Drag_MoveBackward(entity dragger);
719 void Drag_Update(entity dragger);
720 float Drag_CanDrag(entity dragger);
721 float Drag_IsDragging(entity dragger);
722 void Drag_MoveDrag(entity from, entity to);
727 BEGIN_CHEAT_FUNCTION();
729 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
730 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
731 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
732 // grabbing itself no longer being accounted as cheating.
737 if(self.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
739 // use cheat dragging if cheats are enabled
740 crosshair_trace_plusvisibletriggers(self);
741 Drag(trace_ent, TRUE, TRUE);
745 // drag is TRUE if the object can be picked up. While an object is being carried, the Drag() function
746 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
747 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
748 // it goes out of range while slinging it around.
751 crosshair_trace_plusvisibletriggers(self);
752 if(vlen(self.origin - trace_ent.origin) <= autocvar_g_grab_range)
754 switch(trace_ent.grab)
756 case 0: // can't grab
758 case 1: // owner can grab
759 if(trace_ent.owner == self || trace_ent.realowner == self)
762 case 2: // owner and team mates can grab
763 if(!IsDifferentTeam(trace_ent.owner, self) || !IsDifferentTeam(trace_ent.realowner, self) || trace_ent.team == self.team)
766 case 3: // anyone can grab
773 Drag(trace_ent, drag, FALSE); // execute dragging
778 END_CHEAT_FUNCTION();
787 float Drag(entity e, float pick, float ischeat)
789 BEGIN_CHEAT_FUNCTION();
791 // returns TRUE when an entity has been picked up
792 // If pick is TRUE, the object can also be picked up if it's not being held already
793 // If pick is FALSE, only keep dragging the object if it's already being held
798 if(Drag_IsDragging(self))
802 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
804 Drag_MoveForward(self);
807 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
809 Drag_MoveBackward(self);
812 else if(self.impulse >= 1 && self.impulse <= 9)
814 Drag_SetSpeed(self, self.impulse - 1);
816 else if(self.impulse == 14)
818 Drag_SetSpeed(self, 9);
831 if(Drag_CanDrag(self))
832 if(self.BUTTON_DRAG && pick)
835 if(Drag_IsDraggable(e))
838 IS_CHEAT(0, 0, CHRAME_DRAG);
840 Drag_Finish(e.draggedby);
842 detach_sameorigin(e);
843 Drag_Begin(self, e, trace_endpos);
857 .float dragspeed; // speed of mouse wheel action
858 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
859 .vector draglocalvector; // local attachment vector of the dragentity
860 .float draglocalangle;
864 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
868 draggee.dragmovetype = draggee.movetype;
869 draggee.draggravity = draggee.gravity;
870 draggee.movetype = MOVETYPE_WALK;
871 draggee.gravity = 0.00001;
872 draggee.flags &~= FL_ONGROUND;
873 draggee.draggedby = dragger;
875 dragger.dragentity = draggee;
877 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
878 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
879 touchpoint = touchpoint - gettaginfo(draggee, 0);
880 tagscale = pow(vlen(v_forward), -2);
881 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
882 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
883 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
885 dragger.dragspeed = 64;
888 void Drag_Finish(entity dragger)
891 draggee = dragger.dragentity;
893 dragger.dragentity = world;
894 draggee.draggedby = world;
895 draggee.movetype = draggee.dragmovetype;
896 draggee.gravity = draggee.draggravity;
898 switch(draggee.movetype)
903 case MOVETYPE_FLYMISSILE:
904 case MOVETYPE_BOUNCE:
905 case MOVETYPE_BOUNCEMISSILE:
906 case MOVETYPE_PHYSICS:
909 draggee.velocity = '0 0 0';
913 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
915 draggee.velocity = '0 0 0';
916 draggee.flags |= FL_ONGROUND; // floating items are FUN
920 float Drag_IsDraggable(entity draggee)
922 // TODO add more checks for bad stuff here
925 if(draggee.classname == "func_bobbing")
927 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)
929 if(draggee.classname == "plat")
931 if(draggee.classname == "func_button")
933 // if(draggee.model == "")
935 if(draggee.classname == "spectator")
937 if(draggee.classname == "observer")
939 if(draggee.classname == "exteriorweaponentity")
941 if(draggee.classname == "weaponentity")
947 float Drag_MayChangeAngles(entity draggee)
949 // TODO add more checks for bad stuff here
950 if(substring(draggee.model, 0, 1) == "*")
955 void Drag_MoveForward(entity dragger)
957 dragger.dragdistance += dragger.dragspeed;
960 void Drag_SetSpeed(entity dragger, float s)
962 dragger.dragspeed = pow(2, s);
965 void Drag_MoveBackward(entity dragger)
967 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
970 void Drag_Update(entity dragger)
972 vector curorigin, neworigin, goodvelocity;
976 draggee = dragger.dragentity;
977 draggee.flags &~= FL_ONGROUND;
979 curorigin = gettaginfo(draggee, 0);
980 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
981 makevectors(dragger.v_angle);
982 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
983 goodvelocity = (neworigin - curorigin) * (1 / frametime);
985 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
986 dragger.draglocalangle += 360;
987 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
988 dragger.draglocalangle -= 360;
990 f = min(frametime * 10, 1);
991 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
993 if(Drag_MayChangeAngles(draggee))
994 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
996 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
998 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
1001 float Drag_CanDrag(entity dragger)
1003 return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
1006 float Drag_IsDragging(entity dragger)
1008 if(!dragger.dragentity)
1010 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1012 dragger.dragentity = world;
1015 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
1017 Drag_Finish(dragger);
1023 void Drag_MoveDrag(entity from, entity to)
1027 to.draggedby = from.draggedby;
1028 to.draggedby.dragentity = to;
1029 from.draggedby = world;
1033 void DragBox_Think()
1035 if(self.aiment && self.enemy)
1037 self.origin_x = (self.aiment.origin_x + self.enemy.origin_x) * 0.5;
1038 self.origin_y = (self.aiment.origin_y + self.enemy.origin_y) * 0.5;
1039 self.origin_z = (self.aiment.origin_z + self.enemy.origin_z) * 0.5;
1040 self.maxs_x = fabs(self.aiment.origin_x - self.enemy.origin_x) * 0.5;
1041 self.maxs_y = fabs(self.aiment.origin_y - self.enemy.origin_y) * 0.5;
1042 self.maxs_z = fabs(self.aiment.origin_z - self.enemy.origin_z) * 0.5;
1043 self.mins = -1 * self.maxs;
1044 setorigin(self, self.origin); setsize(self, self.mins, self.maxs); // link edict
1047 if(self.cnt == -1) // actually race_place -1
1049 // show "10 10" for qualifying spawns
1050 setmodel(self.killindicator, "models/sprites/10.spr32");
1051 setmodel(self.killindicator.killindicator, "models/sprites/10.spr32");
1053 else if(self.cnt == -2) // actually race_place 0
1055 // show "10 0" for loser spawns
1056 setmodel(self.killindicator, "models/sprites/10.spr32");
1057 setmodel(self.killindicator.killindicator, "models/sprites/0.spr32");
1061 setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
1062 setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
1065 self.nextthink = time;