3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include <common/effects/all.qh>
6 #include <server/resources.qh>
7 #include <server/sv_main.qh>
10 #include "clientkill.qh"
13 #include "../common/mapobjects/teleporters.qh"
15 #include <server/mutators/_mod.qh>
17 #include "weapons/tracing.qh"
19 #include "../common/constants.qh"
20 #include "../common/deathtypes/all.qh"
21 #include "../common/util.qh"
23 #include <common/physics/player.qh>
25 #include "../common/monsters/_mod.qh"
27 #include <common/weapons/_all.qh>
29 #include "../common/mapobjects/subs.qh"
30 #include <common/mapobjects/triggers.qh>
32 #include "../common/mapobjects/func/breakable.qh"
34 #include "../lib/csqcmodel/sv_model.qh"
36 #include "../lib/warpzone/anglestransform.qh"
37 #include "../lib/warpzone/util_server.qh"
41 float CheatImpulse(entity this, int imp) { return 0; }
42 float CheatCommand(entity this, int argc) { return 0; }
43 float CheatFrame(entity this) { return 0; }
44 void CheatInit() { cheatcount_total = world.cheatcount; }
45 void CheatShutdown() { }
46 void Drag_MoveDrag(entity from, entity to) { }
51 float gamestart_sv_cheats;
57 gamestart_sv_cheats = autocvar_sv_cheats;
64 float CheatsAllowed(entity this, float i, int argc, float fr) // the cheat gets passed as argument for possible future ACL checking
68 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
71 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
72 if(this.lip < sv_clones)
79 if(gamestart_sv_cheats && autocvar_sv_cheats)
82 // if we get here, player is not allowed to cheat. Log it.
84 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this, false), i);
86 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this, false), argv(0));
88 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this, false), fr);
90 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this, false));
95 #define BEGIN_CHEAT_FUNCTION() \
96 float cheating = 0, attempting = 0
99 #define ADD_CHEATS(e,n) \
100 cheatcount_total += n; \
102 #define END_CHEAT_FUNCTION() \
103 ADD_CHEATS(this, cheating); \
105 #define IS_CHEAT(ent,i,argc,fr) \
106 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
109 float num_autoscreenshot;
110 void info_autoscreenshot_findtarget(entity this)
113 e = find(NULL, targetname, this.target);
116 objerror(this, "Missing target. FAIL!");
119 vector a = vectoangles(e.origin - this.origin);
120 a.x = -a.x; // don't ask
123 // we leave Rick Roll alone
125 spawnfunc(info_autoscreenshot)
127 // this one just has to exist
128 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
130 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
133 if(this.target != "")
134 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
137 float CheatImpulse(entity this, int imp)
139 BEGIN_CHEAT_FUNCTION();
144 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
145 // shared with regular waypoint init, so this is not a cheat by itself
148 this.personal = new(personal_wp);
150 this.personal.origin = this.origin;
151 this.personal.v_angle = this.v_angle;
152 this.personal.velocity = this.velocity;
153 SetResource(this.personal, RES_ROCKETS, GetResource(this, RES_ROCKETS));
154 SetResource(this.personal, RES_BULLETS, GetResource(this, RES_BULLETS));
155 SetResource(this.personal, RES_CELLS, GetResource(this, RES_CELLS));
156 SetResource(this.personal, RES_PLASMA, GetResource(this, RES_PLASMA));
157 SetResource(this.personal, RES_SHELLS, GetResource(this, RES_SHELLS));
158 SetResource(this.personal, RES_FUEL, GetResource(this, RES_FUEL));
159 SetResource(this.personal, RES_HEALTH, max(1, GetResource(this, RES_HEALTH)));
160 SetResource(this.personal, RES_ARMOR, GetResource(this, RES_ARMOR));
161 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
162 STAT(BUFFS, this.personal) = STAT(BUFFS, this);
163 STAT(BUFF_TIME, this.personal) = STAT(BUFF_TIME, this);
164 this.personal.items = this.items;
165 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
166 this.personal.pauserothealth_finished = this.pauserothealth_finished;
167 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
168 this.personal.pauseregen_finished = this.pauseregen_finished;
169 STAT(STRENGTH_FINISHED, this.personal) = STAT(STRENGTH_FINISHED, this);
170 STAT(INVINCIBLE_FINISHED, this.personal) = STAT(INVINCIBLE_FINISHED, this);
171 this.personal.teleport_time = time;
172 break; // this part itself doesn't cheat, so let's not count this
173 case CHIMPULSE_CLONE_MOVING.impulse:
174 IS_CHEAT(this, imp, 0, 0);
175 makevectors (this.v_angle);
176 this.velocity = this.velocity + v_forward * 300;
179 this.velocity = this.velocity - v_forward * 300;
182 case CHIMPULSE_CLONE_STANDING.impulse:
183 IS_CHEAT(this, imp, 0, 0);
188 case CHIMPULSE_GIVE_ALL.impulse:
189 IS_CHEAT(this, imp, 0, 0);
190 CheatCommand(this, tokenize_console("give all"));
191 break; // already counted as cheat
192 case CHIMPULSE_SPEEDRUN.impulse:
193 if(!autocvar_g_allow_checkpoints)
194 IS_CHEAT(this, imp, 0, 0);
197 this.speedrunning = true;
198 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
201 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
205 // Abort speedrun, teleport back
206 setorigin(this, this.personal.origin);
207 this.oldvelocity = this.velocity = this.personal.velocity;
208 this.angles = this.personal.v_angle;
209 this.fixangle = true;
211 MUTATOR_CALLHOOK(AbortSpeedrun, this);
214 SetResource(this, RES_ROCKETS, GetResource(this.personal, RES_ROCKETS));
215 SetResource(this, RES_BULLETS, GetResource(this.personal, RES_BULLETS));
216 SetResource(this, RES_CELLS, GetResource(this.personal, RES_CELLS));
217 SetResource(this, RES_PLASMA, GetResource(this.personal, RES_PLASMA));
218 SetResource(this, RES_SHELLS, GetResource(this.personal, RES_SHELLS));
219 SetResource(this, RES_FUEL, GetResource(this.personal, RES_FUEL));
220 SetResource(this, RES_HEALTH, GetResource(this.personal, RES_HEALTH));
221 SetResource(this, RES_ARMOR, GetResource(this.personal, RES_ARMOR));
222 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
223 STAT(BUFFS, this) = STAT(BUFFS, this.personal);
224 STAT(BUFF_TIME, this) = STAT(BUFF_TIME, this.personal);
225 this.items = this.personal.items;
226 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
227 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
228 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
229 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
230 STAT(STRENGTH_FINISHED, this) = time + STAT(STRENGTH_FINISHED, this.personal) - this.personal.teleport_time;
231 STAT(INVINCIBLE_FINISHED, this) = time + STAT(INVINCIBLE_FINISHED, this.personal) - this.personal.teleport_time;
233 if(!autocvar_g_allow_checkpoints)
238 sprint(this, "UR DEAD AHAHAH))\n");
240 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
242 case CHIMPULSE_TELEPORT.impulse:
243 IS_CHEAT(this, imp, 0, 0);
244 if(this.move_movetype == MOVETYPE_NOCLIP)
246 e = find(NULL, classname, "info_autoscreenshot");
249 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
250 setorigin(this, e.origin);
251 this.angles = e.angles;
253 // should we? this.angles_x = -this.angles_x;
254 this.fixangle = true;
255 this.velocity = '0 0 0';
260 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))
262 sprint(this, "Emergency teleport used random location\n");
263 this.angles_x = -this.angles.x;
264 this.fixangle = true;
265 this.velocity = '0 0 0';
269 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
271 case CHIMPULSE_R00T.impulse:
272 IS_CHEAT(this, imp, 0, 0);
273 RandomSelection_Init();
274 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
275 if(RandomSelection_chosen_ent)
276 e = RandomSelection_chosen_ent;
280 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
281 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
284 setorigin(e2, e.origin);
285 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
288 LOG_INFO("404 Sportsmanship not found.");
293 END_CHEAT_FUNCTION();
297 float CheatCommand(entity this, int argc)
299 BEGIN_CHEAT_FUNCTION();
307 case "pointparticles":
308 IS_CHEAT(this, 0, argc, 0);
313 // origin (0..1, on crosshair line)
317 crosshair_trace(this);
318 start = (1-f) * this.origin + f * trace_endpos;
321 Send_Effect_(argv(1), start, end, f);
325 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
327 case "trailparticles":
328 IS_CHEAT(this, 0, argc, 0);
333 effectnum = _particleeffectnum(argv(1));
334 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
335 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
336 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
340 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
343 IS_CHEAT(this, 0, argc, 0);
349 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
350 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
351 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
353 sprint(this, "cannot make stuff there (bad surface)\n");
358 e.model = strzone(argv(1));
359 e.mdl = "rocket_explode";
360 SetResourceExplicit(e, RES_HEALTH, 1000);
361 setorigin(e, trace_endpos);
362 e.effects = EF_NOMODELFLAGS;
365 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
366 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
368 spawnfunc_func_breakable(e);
372 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
376 sprint(this, "cannot make stuff there (no space)\n");
386 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
389 IS_CHEAT(this, 0, argc, 0);
392 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
396 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
398 case "dragbox_spawn": {
399 IS_CHEAT(this, 0, argc, 0);
400 entity e = new(dragbox_box);
401 setthink(e, DragBox_Think);
403 e.solid = -1; // black
404 setmodel(e, MDL_Null); // network it
406 e.cnt = stof(argv(1));
408 e.cnt = max(0, drag_lastcnt);
410 e.aiment = new(dragbox_corner_1);
412 setmodel(e.aiment, MDL_MARKER);
414 setsize(e.aiment, '0 0 0', '0 0 0');
416 setorigin(e.aiment, stov(argv(2)));
419 crosshair_trace(this);
420 setorigin(e.aiment, trace_endpos);
423 e.enemy = new(dragbox_corner_2);
425 setmodel(e.enemy, MDL_MARKER);
427 setsize(e.enemy, '0 0 0', '0 0 0');
428 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
429 end.x = (end.x > 0) * 2 - 1;
430 end.y = (end.y > 0) * 2 - 1;
431 end.z = (end.z > 0) * 2 - 1;
433 setorigin(e.enemy, stov(argv(3)));
435 setorigin(e.enemy, e.aiment.origin + 32 * end);
437 e.killindicator = new(drag_digit);
438 e.killindicator.owner = e;
439 setattachment(e.killindicator, e, "");
440 setorigin(e.killindicator, '0 0 -8');
441 e.killindicator.killindicator = new(drag_digit);
442 e.killindicator.killindicator.owner = e;
443 setattachment(e.killindicator.killindicator, e, "");
444 setorigin(e.killindicator.killindicator, '0 0 8');
448 case "dragpoint_spawn": {
449 IS_CHEAT(this, 0, argc, 0);
450 entity e = new(dragpoint);
451 setthink(e, DragBox_Think);
453 e.solid = 0; // nothing special
454 setmodel(e, MDL_MARKER);
455 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
458 e.cnt = stof(argv(1));
460 e.cnt = drag_lastcnt;
462 setorigin(e, stov(argv(2)));
465 crosshair_trace(this);
466 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
467 move_out_of_solid(e);
470 e.killindicator = new(drag_digit);
471 e.killindicator.owner = e;
472 setattachment(e.killindicator, e, "");
473 setorigin(e.killindicator, '0 0 40');
474 e.killindicator.killindicator = new(drag_digit);
475 e.killindicator.killindicator.owner = e;
476 setattachment(e.killindicator.killindicator, e, "");
477 setorigin(e.killindicator.killindicator, '0 0 56');
482 IS_CHEAT(this, 0, argc, 0);
483 RandomSelection_Init();
484 crosshair_trace(this);
485 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
486 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
487 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
488 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
489 if(RandomSelection_chosen_ent)
491 delete(RandomSelection_chosen_ent.killindicator.killindicator);
492 delete(RandomSelection_chosen_ent.killindicator);
493 if(RandomSelection_chosen_ent.aiment)
494 delete(RandomSelection_chosen_ent.aiment);
495 if(RandomSelection_chosen_ent.enemy)
496 delete(RandomSelection_chosen_ent.enemy);
497 delete(RandomSelection_chosen_ent);
502 IS_CHEAT(this, 0, argc, 0);
505 RandomSelection_Init();
506 crosshair_trace(this);
507 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
508 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
509 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
510 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
511 if(RandomSelection_chosen_ent)
513 if(substring(argv(1), 0, 1) == "*")
514 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
516 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
521 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
524 IS_CHEAT(this, 0, argc, 0);
527 f = fopen(argv(1), FILE_WRITE);
528 fputs(f, "cmd drag_clear\n");
529 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
531 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
533 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
535 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
541 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
543 case "drag_saveraceent":
544 IS_CHEAT(this, 0, argc, 0);
547 f = fopen(argv(1), FILE_WRITE);
548 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
551 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
552 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
553 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"));
554 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
555 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
558 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
562 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
564 if((e.cnt <= 0 && ent.cnt == 0) || e.cnt == ent.cnt)
566 start = start + ent.origin;
570 start *= 1 / effectnum;
572 fputs(f, "\"classname\" \"info_player_race\"\n");
573 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
574 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
577 fputs(f, "\"target\" \"checkpoint0\"\n");
578 fputs(f, "\"race_place\" \"0\"\n");
582 fputs(f, "\"target\" \"checkpoint0\"\n");
583 fputs(f, "\"race_place\" \"-1\"\n");
587 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
590 // these need race_place
593 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
596 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
598 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
601 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
610 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
613 IS_CHEAT(this, 0, argc, 0);
614 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
616 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
618 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
620 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
622 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
627 IS_CHEAT(this, 0, argc, 0);
628 BITXOR_ASSIGN(this.flags, FL_GODMODE);
629 if(this.flags & FL_GODMODE)
631 sprint(this, "godmode ON\n");
635 sprint(this, "godmode OFF\n");
638 IS_CHEAT(this, 0, argc, 0);
639 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
640 if(this.flags & FL_NOTARGET)
642 sprint(this, "notarget ON\n");
646 sprint(this, "notarget OFF\n");
649 IS_CHEAT(this, 0, argc, 0);
650 if(this.move_movetype != MOVETYPE_NOCLIP)
652 set_movetype(this, MOVETYPE_NOCLIP);
653 sprint(this, "noclip ON\n");
658 set_movetype(this, MOVETYPE_WALK);
659 sprint(this, "noclip OFF\n");
663 IS_CHEAT(this, 0, argc, 0);
664 if(this.move_movetype != MOVETYPE_FLY)
666 set_movetype(this, MOVETYPE_FLY);
667 sprint(this, "flymode ON\n");
672 set_movetype(this, MOVETYPE_WALK);
673 sprint(this, "flymode OFF\n");
677 IS_CHEAT(this, 0, argc, 0);
678 if(GiveItems(this, 1, argc))
682 IS_CHEAT(this, 0, argc, 0);
685 SUB_UseTargets(e, this, NULL);
690 IS_CHEAT(this, 0, argc, 0);
692 e2.killtarget = argv(1);
693 SUB_UseTargets(e2, this, NULL);
697 case "teleporttotarget":
698 IS_CHEAT(this, 0, argc, 0);
699 entity ent = new(cheattriggerteleport);
700 setorigin(ent, ent.origin);
701 ent.target = argv(1);
702 teleport_findtarget(ent);
705 Simple_TeleportPlayer(ent, this);
712 END_CHEAT_FUNCTION();
717 float CheatFrame(entity this)
719 BEGIN_CHEAT_FUNCTION();
721 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
722 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
723 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
724 // grabbing itself no longer being accounted as cheating.
729 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
731 // use cheat dragging if cheats are enabled
732 //if(Drag_IsDragging(this))
733 //crosshair_trace_plusvisibletriggers(this);
734 Drag(this, true, true);
738 Drag(this, false, false); // execute dragging
743 END_CHEAT_FUNCTION();
754 .float dragspeed; // speed of mouse wheel action
755 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
756 .vector draglocalvector; // local attachment vector of the dragentity
757 .float draglocalangle;
762 float Drag(entity this, float force_allow_pick, float ischeat)
764 BEGIN_CHEAT_FUNCTION();
766 // returns true when an entity has been picked up
767 // If pick is true, the object can also be picked up if it's not being held already
768 // If pick is false, only keep dragging the object if it's already being held
773 if(Drag_IsDragging(this))
775 if(PHYS_INPUT_BUTTON_DRAG(this))
777 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
779 Drag_MoveForward(this);
780 CS(this).impulse = 0;
782 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
784 Drag_MoveBackward(this);
785 CS(this).impulse = 0;
787 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
789 Drag_SetSpeed(this, CS(this).impulse - 1);
791 else if(CS(this).impulse == 14)
793 Drag_SetSpeed(this, 9);
804 else if(Drag_CanDrag(this) && PHYS_INPUT_BUTTON_DRAG(this))
806 crosshair_trace_plusvisibletriggers(this);
807 entity e = trace_ent;
808 float pick = force_allow_pick;
809 if (e && !pick && vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
811 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
812 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
813 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
814 // it goes out of range while slinging it around.
818 case 0: // can't grab
820 case 1: // owner can grab
821 if(e.owner == this || e.realowner == this)
824 case 2: // owner and team mates can grab
825 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
828 case 3: // anyone can grab
836 if(e && pick && Drag_IsDraggable(e, this))
839 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
841 Drag_Finish(e.draggedby);
843 detach_sameorigin(e);
844 Drag_Begin(this, e, trace_endpos);
855 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
859 draggee.dragmovetype = draggee.move_movetype;
860 draggee.draggravity = draggee.gravity;
861 set_movetype(draggee, MOVETYPE_WALK);
862 draggee.gravity = 0.00001;
863 UNSET_ONGROUND(draggee);
864 draggee.draggedby = dragger;
866 dragger.dragentity = draggee;
868 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
869 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
870 touchpoint = touchpoint - gettaginfo(draggee, 0);
871 tagscale = (vlen(v_forward) ** -2);
872 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
873 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
874 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
876 dragger.dragspeed = 64;
879 void Drag_Finish(entity dragger)
882 draggee = dragger.dragentity;
884 dragger.dragentity = NULL;
885 draggee.draggedby = NULL;
886 set_movetype(draggee, draggee.dragmovetype);
887 draggee.gravity = draggee.draggravity;
889 switch(draggee.move_movetype)
894 case MOVETYPE_FLYMISSILE:
895 case MOVETYPE_BOUNCE:
896 case MOVETYPE_BOUNCEMISSILE:
897 case MOVETYPE_PHYSICS:
900 draggee.velocity = '0 0 0';
904 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
906 draggee.velocity = '0 0 0';
907 SET_ONGROUND(draggee); // floating items are FUN
911 bool drag_undraggable(entity draggee, entity dragger)
913 // stuff probably shouldn't need this, we should figure out why they do!
914 // exceptions of course are observers and weapon entities, where things mess up
918 float Drag_IsDraggable(entity draggee, entity dragger)
920 // TODO add more checks for bad stuff here
923 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)
924 return false; // probably due to BSP collision
925 //if(draggee.model == "")
928 return ((draggee.draggable) ? draggee.draggable(draggee, dragger) : true);
931 float Drag_MayChangeAngles(entity draggee)
933 // TODO add more checks for bad stuff here
934 if(substring(draggee.model, 0, 1) == "*")
939 void Drag_MoveForward(entity dragger)
941 dragger.dragdistance += dragger.dragspeed;
944 void Drag_SetSpeed(entity dragger, float s)
946 dragger.dragspeed = (2 ** s);
949 void Drag_MoveBackward(entity dragger)
951 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
954 void Drag_Update(entity dragger)
956 vector curorigin, neworigin, goodvelocity;
960 draggee = dragger.dragentity;
961 UNSET_ONGROUND(draggee);
963 curorigin = gettaginfo(draggee, 0);
964 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
965 makevectors(dragger.v_angle);
966 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
967 goodvelocity = (neworigin - curorigin) * (1 / frametime);
969 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
970 dragger.draglocalangle += 360;
971 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
972 dragger.draglocalangle -= 360;
974 f = min(frametime * 10, 1);
975 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
977 if(Drag_MayChangeAngles(draggee))
978 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
980 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
982 vector vecs = '0 0 0';
983 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
984 if(dragger.(weaponentity).movedir.x > 0)
985 vecs = dragger.(weaponentity).movedir;
987 vector dv = v_right * -vecs_y + v_up * vecs_z;
989 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
992 float Drag_CanDrag(entity dragger)
994 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
997 float Drag_IsDragging(entity dragger)
999 if(!dragger.dragentity)
1001 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1003 dragger.dragentity = NULL;
1006 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity, dragger))
1008 Drag_Finish(dragger);
1014 void Drag_MoveDrag(entity from, entity to)
1018 to.draggedby = from.draggedby;
1019 to.draggedby.dragentity = to;
1020 from.draggedby = NULL;
1024 void DragBox_Think(entity this)
1026 if(this.aiment && this.enemy)
1028 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1029 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1030 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1031 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1032 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1033 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1034 this.mins = -1 * this.maxs;
1035 setorigin(this, this.origin);
1036 setsize(this, this.mins, this.maxs); // link edict
1039 if(this.cnt == -1) // actually race_place -1
1041 // show "10 10" for qualifying spawns
1042 setmodel(this.killindicator, MDL_NUM(10));
1043 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1045 else if(this.cnt == -2) // actually race_place 0
1047 // show "10 0" for loser spawns
1048 setmodel(this.killindicator, MDL_NUM(10));
1049 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1053 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1054 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1057 this.nextthink = time;