3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include <common/effects/all.qh>
6 #include <server/resources.qh>
9 #include "clientkill.qh"
12 #include "../common/mapobjects/teleporters.qh"
14 #include <server/mutators/_mod.qh>
16 #include "weapons/tracing.qh"
18 #include "../common/constants.qh"
19 #include "../common/deathtypes/all.qh"
20 #include "../common/util.qh"
22 #include <common/physics/player.qh>
24 #include "../common/monsters/_mod.qh"
26 #include <common/weapons/_all.qh>
28 #include "../common/mapobjects/subs.qh"
29 #include <common/mapobjects/triggers.qh>
31 #include "../common/mapobjects/func/breakable.qh"
33 #include "../lib/csqcmodel/sv_model.qh"
35 #include "../lib/warpzone/anglestransform.qh"
36 #include "../lib/warpzone/util_server.qh"
40 float CheatImpulse(entity this, int imp) { return 0; }
41 float CheatCommand(entity this, int argc) { return 0; }
42 float CheatFrame(entity this) { return 0; }
43 void CheatInit() { cheatcount_total = world.cheatcount; }
44 void CheatShutdown() { }
45 void Drag_MoveDrag(entity from, entity to) { }
50 float gamestart_sv_cheats;
56 gamestart_sv_cheats = autocvar_sv_cheats;
63 float CheatsAllowed(entity this, float i, int argc, float fr) // the cheat gets passed as argument for possible future ACL checking
65 // dead people cannot cheat
68 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
72 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
73 if(this.lip < sv_clones)
81 if(gamestart_sv_cheats && autocvar_sv_cheats)
84 // if we get here, player is not allowed to cheat. Log it.
86 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this, false), i);
88 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this, false), argv(0));
90 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this, false), fr);
92 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this, false));
97 #define BEGIN_CHEAT_FUNCTION() \
98 float cheating = 0, attempting = 0
101 #define ADD_CHEATS(e,n) \
102 cheatcount_total += n; \
104 #define END_CHEAT_FUNCTION() \
105 ADD_CHEATS(this, cheating); \
107 #define IS_CHEAT(ent,i,argc,fr) \
108 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
111 float num_autoscreenshot;
112 void info_autoscreenshot_findtarget(entity this)
115 e = find(NULL, targetname, this.target);
118 objerror(this, "Missing target. FAIL!");
121 vector a = vectoangles(e.origin - this.origin);
122 a.x = -a.x; // don't ask
125 // we leave Rick Roll alone
127 spawnfunc(info_autoscreenshot)
129 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
131 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
134 if(this.target != "")
135 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
136 // this one just has to exist
139 float CheatImpulse(entity this, int imp)
141 BEGIN_CHEAT_FUNCTION();
146 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
147 // shared with regular waypoint init, so this is not a cheat by itself
150 this.personal = new(personal_wp);
152 this.personal.origin = this.origin;
153 this.personal.v_angle = this.v_angle;
154 this.personal.velocity = this.velocity;
155 SetResource(this.personal, RES_ROCKETS, GetResource(this, RES_ROCKETS));
156 SetResource(this.personal, RES_BULLETS, GetResource(this, RES_BULLETS));
157 SetResource(this.personal, RES_CELLS, GetResource(this, RES_CELLS));
158 SetResource(this.personal, RES_PLASMA, GetResource(this, RES_PLASMA));
159 SetResource(this.personal, RES_SHELLS, GetResource(this, RES_SHELLS));
160 SetResource(this.personal, RES_FUEL, GetResource(this, RES_FUEL));
161 SetResource(this.personal, RES_HEALTH, max(1, GetResource(this, RES_HEALTH)));
162 SetResource(this.personal, RES_ARMOR, GetResource(this, RES_ARMOR));
163 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
164 STAT(BUFFS, this.personal) = STAT(BUFFS, this);
165 STAT(BUFF_TIME, this.personal) = STAT(BUFF_TIME, this);
166 this.personal.items = this.items;
167 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
168 this.personal.pauserothealth_finished = this.pauserothealth_finished;
169 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
170 this.personal.pauseregen_finished = this.pauseregen_finished;
171 this.personal.strength_finished = this.strength_finished;
172 this.personal.invincible_finished = this.invincible_finished;
173 this.personal.teleport_time = time;
174 break; // this part itself doesn't cheat, so let's not count this
175 case CHIMPULSE_CLONE_MOVING.impulse:
176 IS_CHEAT(this, imp, 0, 0);
177 makevectors (this.v_angle);
178 this.velocity = this.velocity + v_forward * 300;
181 this.velocity = this.velocity - v_forward * 300;
184 case CHIMPULSE_CLONE_STANDING.impulse:
185 IS_CHEAT(this, imp, 0, 0);
190 case CHIMPULSE_GIVE_ALL.impulse:
191 IS_CHEAT(this, imp, 0, 0);
192 CheatCommand(this, tokenize_console("give all"));
193 break; // already counted as cheat
194 case CHIMPULSE_SPEEDRUN.impulse:
195 if(!autocvar_g_allow_checkpoints)
196 IS_CHEAT(this, imp, 0, 0);
199 this.speedrunning = true;
200 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
203 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
207 // Abort speedrun, teleport back
208 setorigin(this, this.personal.origin);
209 this.oldvelocity = this.velocity = this.personal.velocity;
210 this.angles = this.personal.v_angle;
211 this.fixangle = true;
213 MUTATOR_CALLHOOK(AbortSpeedrun, this);
216 SetResource(this, RES_ROCKETS, GetResource(this.personal, RES_ROCKETS));
217 SetResource(this, RES_BULLETS, GetResource(this.personal, RES_BULLETS));
218 SetResource(this, RES_CELLS, GetResource(this.personal, RES_CELLS));
219 SetResource(this, RES_PLASMA, GetResource(this.personal, RES_PLASMA));
220 SetResource(this, RES_SHELLS, GetResource(this.personal, RES_SHELLS));
221 SetResource(this, RES_FUEL, GetResource(this.personal, RES_FUEL));
222 SetResource(this, RES_HEALTH, GetResource(this.personal, RES_HEALTH));
223 SetResource(this, RES_ARMOR, GetResource(this.personal, RES_ARMOR));
224 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
225 STAT(BUFFS, this) = STAT(BUFFS, this.personal);
226 STAT(BUFF_TIME, this) = STAT(BUFF_TIME, this.personal);
227 this.items = this.personal.items;
228 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
229 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
230 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
231 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
232 this.strength_finished = time + this.personal.strength_finished - this.personal.teleport_time;
233 this.invincible_finished = time + this.personal.invincible_finished - this.personal.teleport_time;
235 if(!autocvar_g_allow_checkpoints)
240 sprint(this, "UR DEAD AHAHAH))\n");
242 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
244 case CHIMPULSE_TELEPORT.impulse:
245 IS_CHEAT(this, imp, 0, 0);
246 if(this.move_movetype == MOVETYPE_NOCLIP)
248 e = find(NULL, classname, "info_autoscreenshot");
251 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
252 setorigin(this, e.origin);
253 this.angles = e.angles;
255 // should we? this.angles_x = -this.angles_x;
256 this.fixangle = true;
257 this.velocity = '0 0 0';
262 if(MoveToRandomMapLocation(this, 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))
264 sprint(this, "Emergency teleport used random location\n");
265 this.angles_x = -this.angles.x;
266 this.fixangle = true;
267 this.velocity = '0 0 0';
271 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
273 case CHIMPULSE_R00T.impulse:
274 IS_CHEAT(this, imp, 0, 0);
275 RandomSelection_Init();
276 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
277 if(RandomSelection_chosen_ent)
278 e = RandomSelection_chosen_ent;
282 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
283 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
286 setorigin(e2, e.origin);
287 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
290 LOG_INFO("404 Sportsmanship not found.");
295 END_CHEAT_FUNCTION();
299 float CheatCommand(entity this, int argc)
301 BEGIN_CHEAT_FUNCTION();
309 case "pointparticles":
310 IS_CHEAT(this, 0, argc, 0);
315 // origin (0..1, on crosshair line)
319 crosshair_trace(this);
320 start = (1-f) * this.origin + f * trace_endpos;
323 Send_Effect_(argv(1), start, end, f);
327 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
329 case "trailparticles":
330 IS_CHEAT(this, 0, argc, 0);
335 effectnum = _particleeffectnum(argv(1));
336 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
337 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
338 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
342 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
345 IS_CHEAT(this, 0, argc, 0);
351 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
352 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
353 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
355 sprint(this, "cannot make stuff there (bad surface)\n");
360 e.model = strzone(argv(1));
361 e.mdl = "rocket_explode";
362 SetResourceExplicit(e, RES_HEALTH, 1000);
363 setorigin(e, trace_endpos);
364 e.effects = EF_NOMODELFLAGS;
367 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
368 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
370 spawnfunc_func_breakable(e);
374 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
378 sprint(this, "cannot make stuff there (no space)\n");
388 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
391 IS_CHEAT(this, 0, argc, 0);
394 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
398 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
400 case "dragbox_spawn": {
401 IS_CHEAT(this, 0, argc, 0);
402 entity e = new(dragbox_box);
403 setthink(e, DragBox_Think);
405 e.solid = -1; // black
406 setmodel(e, MDL_Null); // network it
408 e.cnt = stof(argv(1));
410 e.cnt = max(0, drag_lastcnt);
412 e.aiment = new(dragbox_corner_1);
414 setmodel(e.aiment, MDL_MARKER);
416 setsize(e.aiment, '0 0 0', '0 0 0');
418 setorigin(e.aiment, stov(argv(2)));
421 crosshair_trace(this);
422 setorigin(e.aiment, trace_endpos);
425 e.enemy = new(dragbox_corner_2);
427 setmodel(e.enemy, MDL_MARKER);
429 setsize(e.enemy, '0 0 0', '0 0 0');
430 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
431 end.x = (end.x > 0) * 2 - 1;
432 end.y = (end.y > 0) * 2 - 1;
433 end.z = (end.z > 0) * 2 - 1;
435 setorigin(e.enemy, stov(argv(3)));
437 setorigin(e.enemy, e.aiment.origin + 32 * end);
439 e.killindicator = new(drag_digit);
440 e.killindicator.owner = e;
441 setattachment(e.killindicator, e, "");
442 setorigin(e.killindicator, '0 0 -8');
443 e.killindicator.killindicator = new(drag_digit);
444 e.killindicator.killindicator.owner = e;
445 setattachment(e.killindicator.killindicator, e, "");
446 setorigin(e.killindicator.killindicator, '0 0 8');
450 case "dragpoint_spawn": {
451 IS_CHEAT(this, 0, argc, 0);
452 entity e = new(dragpoint);
453 setthink(e, DragBox_Think);
455 e.solid = 0; // nothing special
456 setmodel(e, MDL_MARKER);
457 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
460 e.cnt = stof(argv(1));
462 e.cnt = drag_lastcnt;
464 setorigin(e, stov(argv(2)));
467 crosshair_trace(this);
468 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
469 move_out_of_solid(e);
472 e.killindicator = new(drag_digit);
473 e.killindicator.owner = e;
474 setattachment(e.killindicator, e, "");
475 setorigin(e.killindicator, '0 0 40');
476 e.killindicator.killindicator = new(drag_digit);
477 e.killindicator.killindicator.owner = e;
478 setattachment(e.killindicator.killindicator, e, "");
479 setorigin(e.killindicator.killindicator, '0 0 56');
484 IS_CHEAT(this, 0, argc, 0);
485 RandomSelection_Init();
486 crosshair_trace(this);
487 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
488 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
489 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
490 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
491 if(RandomSelection_chosen_ent)
493 delete(RandomSelection_chosen_ent.killindicator.killindicator);
494 delete(RandomSelection_chosen_ent.killindicator);
495 if(RandomSelection_chosen_ent.aiment)
496 delete(RandomSelection_chosen_ent.aiment);
497 if(RandomSelection_chosen_ent.enemy)
498 delete(RandomSelection_chosen_ent.enemy);
499 delete(RandomSelection_chosen_ent);
504 IS_CHEAT(this, 0, argc, 0);
507 RandomSelection_Init();
508 crosshair_trace(this);
509 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
510 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
511 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
512 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
513 if(RandomSelection_chosen_ent)
515 if(substring(argv(1), 0, 1) == "*")
516 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
518 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
523 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
526 IS_CHEAT(this, 0, argc, 0);
529 f = fopen(argv(1), FILE_WRITE);
530 fputs(f, "cmd drag_clear\n");
531 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
533 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
535 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
537 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
543 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
545 case "drag_saveraceent":
546 IS_CHEAT(this, 0, argc, 0);
549 f = fopen(argv(1), FILE_WRITE);
550 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
553 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
554 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
555 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"));
556 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
557 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
560 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
564 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
566 if(e.cnt <= 0 && ent.cnt == 0 || e.cnt == ent.cnt)
568 start = start + ent.origin;
572 start *= 1 / effectnum;
574 fputs(f, "\"classname\" \"info_player_race\"\n");
575 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
576 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
579 fputs(f, "\"target\" \"checkpoint0\"\n");
580 fputs(f, "\"race_place\" \"0\"\n");
584 fputs(f, "\"target\" \"checkpoint0\"\n");
585 fputs(f, "\"race_place\" \"-1\"\n");
589 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
592 // these need race_place
595 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
598 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
600 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
603 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
612 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
615 IS_CHEAT(this, 0, argc, 0);
616 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
618 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
620 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
622 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
624 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
629 IS_CHEAT(this, 0, argc, 0);
630 BITXOR_ASSIGN(this.flags, FL_GODMODE);
631 if(this.flags & FL_GODMODE)
633 sprint(this, "godmode ON\n");
637 sprint(this, "godmode OFF\n");
640 IS_CHEAT(this, 0, argc, 0);
641 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
642 if(this.flags & FL_NOTARGET)
644 sprint(this, "notarget ON\n");
648 sprint(this, "notarget OFF\n");
651 IS_CHEAT(this, 0, argc, 0);
652 if(this.move_movetype != MOVETYPE_NOCLIP)
654 set_movetype(this, MOVETYPE_NOCLIP);
655 sprint(this, "noclip ON\n");
660 set_movetype(this, MOVETYPE_WALK);
661 sprint(this, "noclip OFF\n");
665 IS_CHEAT(this, 0, argc, 0);
666 if(this.move_movetype != MOVETYPE_FLY)
668 set_movetype(this, MOVETYPE_FLY);
669 sprint(this, "flymode ON\n");
674 set_movetype(this, MOVETYPE_WALK);
675 sprint(this, "flymode OFF\n");
679 IS_CHEAT(this, 0, argc, 0);
680 if(GiveItems(this, 1, argc))
684 IS_CHEAT(this, 0, argc, 0);
687 SUB_UseTargets(e, this, NULL);
692 IS_CHEAT(this, 0, argc, 0);
694 e2.killtarget = argv(1);
695 SUB_UseTargets(e2, this, NULL);
699 case "teleporttotarget":
700 IS_CHEAT(this, 0, argc, 0);
701 entity ent = new(cheattriggerteleport);
702 setorigin(ent, ent.origin);
703 ent.target = argv(1);
704 teleport_findtarget(ent);
707 Simple_TeleportPlayer(ent, this);
714 END_CHEAT_FUNCTION();
719 float CheatFrame(entity this)
721 BEGIN_CHEAT_FUNCTION();
723 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
724 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
725 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
726 // grabbing itself no longer being accounted as cheating.
731 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
733 // use cheat dragging if cheats are enabled
734 //if(Drag_IsDragging(this))
735 //crosshair_trace_plusvisibletriggers(this);
736 Drag(this, true, true);
740 Drag(this, false, false); // execute dragging
745 END_CHEAT_FUNCTION();
756 .float dragspeed; // speed of mouse wheel action
757 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
758 .vector draglocalvector; // local attachment vector of the dragentity
759 .float draglocalangle;
764 float Drag(entity this, float force_allow_pick, float ischeat)
766 BEGIN_CHEAT_FUNCTION();
768 // returns true when an entity has been picked up
769 // If pick is true, the object can also be picked up if it's not being held already
770 // If pick is false, only keep dragging the object if it's already being held
775 if(Drag_IsDragging(this))
777 if(PHYS_INPUT_BUTTON_DRAG(this))
779 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
781 Drag_MoveForward(this);
782 CS(this).impulse = 0;
784 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
786 Drag_MoveBackward(this);
787 CS(this).impulse = 0;
789 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
791 Drag_SetSpeed(this, CS(this).impulse - 1);
793 else if(CS(this).impulse == 14)
795 Drag_SetSpeed(this, 9);
808 if(Drag_CanDrag(this))
809 if(PHYS_INPUT_BUTTON_DRAG(this))
811 crosshair_trace_plusvisibletriggers(this);
812 entity e = trace_ent;
813 float pick = force_allow_pick;
816 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
817 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
818 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
819 // it goes out of range while slinging it around.
821 if(vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
825 case 0: // can't grab
827 case 1: // owner can grab
828 if(e.owner == this || e.realowner == this)
831 case 2: // owner and team mates can grab
832 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
835 case 3: // anyone can grab
845 if(Drag_IsDraggable(e, this))
848 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
850 Drag_Finish(e.draggedby);
852 detach_sameorigin(e);
853 Drag_Begin(this, e, trace_endpos);
865 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
869 draggee.dragmovetype = draggee.move_movetype;
870 draggee.draggravity = draggee.gravity;
871 set_movetype(draggee, MOVETYPE_WALK);
872 draggee.gravity = 0.00001;
873 UNSET_ONGROUND(draggee);
874 draggee.draggedby = dragger;
876 dragger.dragentity = draggee;
878 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
879 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
880 touchpoint = touchpoint - gettaginfo(draggee, 0);
881 tagscale = (vlen(v_forward) ** -2);
882 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
883 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
884 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
886 dragger.dragspeed = 64;
889 void Drag_Finish(entity dragger)
892 draggee = dragger.dragentity;
894 dragger.dragentity = NULL;
895 draggee.draggedby = NULL;
896 set_movetype(draggee, draggee.dragmovetype);
897 draggee.gravity = draggee.draggravity;
899 switch(draggee.move_movetype)
904 case MOVETYPE_FLYMISSILE:
905 case MOVETYPE_BOUNCE:
906 case MOVETYPE_BOUNCEMISSILE:
907 case MOVETYPE_PHYSICS:
910 draggee.velocity = '0 0 0';
914 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
916 draggee.velocity = '0 0 0';
917 SET_ONGROUND(draggee); // floating items are FUN
921 bool drag_undraggable(entity draggee, entity dragger)
923 // stuff probably shouldn't need this, we should figure out why they do!
924 // exceptions of course are observers and weapon entities, where things mess up
928 float Drag_IsDraggable(entity draggee, entity dragger)
930 // TODO add more checks for bad stuff here
933 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)
934 return false; // probably due to BSP collision
935 // if(draggee.model == "")
938 return ((draggee.draggable) ? draggee.draggable(draggee, dragger) : true);
941 float Drag_MayChangeAngles(entity draggee)
943 // TODO add more checks for bad stuff here
944 if(substring(draggee.model, 0, 1) == "*")
949 void Drag_MoveForward(entity dragger)
951 dragger.dragdistance += dragger.dragspeed;
954 void Drag_SetSpeed(entity dragger, float s)
956 dragger.dragspeed = (2 ** s);
959 void Drag_MoveBackward(entity dragger)
961 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
964 void Drag_Update(entity dragger)
966 vector curorigin, neworigin, goodvelocity;
970 draggee = dragger.dragentity;
971 UNSET_ONGROUND(draggee);
973 curorigin = gettaginfo(draggee, 0);
974 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
975 makevectors(dragger.v_angle);
976 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
977 goodvelocity = (neworigin - curorigin) * (1 / frametime);
979 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
980 dragger.draglocalangle += 360;
981 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
982 dragger.draglocalangle -= 360;
984 f = min(frametime * 10, 1);
985 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
987 if(Drag_MayChangeAngles(draggee))
988 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
990 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
992 vector vecs = '0 0 0';
993 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
994 if(dragger.(weaponentity).movedir.x > 0)
995 vecs = dragger.(weaponentity).movedir;
997 vector dv = v_right * -vecs_y + v_up * vecs_z;
999 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
1002 float Drag_CanDrag(entity dragger)
1004 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
1007 float Drag_IsDragging(entity dragger)
1009 if(!dragger.dragentity)
1011 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1013 dragger.dragentity = NULL;
1016 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity, dragger))
1018 Drag_Finish(dragger);
1024 void Drag_MoveDrag(entity from, entity to)
1028 to.draggedby = from.draggedby;
1029 to.draggedby.dragentity = to;
1030 from.draggedby = NULL;
1034 void DragBox_Think(entity this)
1036 if(this.aiment && this.enemy)
1038 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1039 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1040 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1041 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1042 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1043 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1044 this.mins = -1 * this.maxs;
1045 setorigin(this, this.origin);
1046 setsize(this, this.mins, this.maxs); // link edict
1049 if(this.cnt == -1) // actually race_place -1
1051 // show "10 10" for qualifying spawns
1052 setmodel(this.killindicator, MDL_NUM(10));
1053 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1055 else if(this.cnt == -2) // actually race_place 0
1057 // show "10 0" for loser spawns
1058 setmodel(this.killindicator, MDL_NUM(10));
1059 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1063 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1064 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1067 this.nextthink = time;