3 #include <common/weapons/_all.qh>
4 #include <common/stats.qh>
5 #include <common/effects/all.qh>
6 #include <server/resources.qh>
7 #include <server/main.qh>
8 #include <server/world.qh>
11 #include "clientkill.qh"
14 #include "../common/mapobjects/teleporters.qh"
16 #include <server/mutators/_mod.qh>
18 #include "weapons/tracing.qh"
20 #include "../common/constants.qh"
21 #include "../common/deathtypes/all.qh"
22 #include "../common/util.qh"
24 #include <common/physics/player.qh>
26 #include "../common/monsters/_mod.qh"
28 #include <common/items/_mod.qh>
30 #include <common/weapons/_all.qh>
32 #include "../common/mapobjects/subs.qh"
33 #include <common/mapobjects/triggers.qh>
35 #include "../common/mapobjects/func/breakable.qh"
37 #include "../lib/csqcmodel/sv_model.qh"
39 #include "../lib/warpzone/anglestransform.qh"
40 #include "../lib/warpzone/util_server.qh"
44 float CheatImpulse(entity this, int imp) { return 0; }
45 float CheatCommand(entity this, int argc) { return 0; }
46 float CheatFrame(entity this) { return 0; }
47 void CheatInit() { cheatcount_total = world.cheatcount; }
48 void CheatShutdown() { }
49 void Drag_MoveDrag(entity from, entity to) { }
54 float gamestart_sv_cheats;
60 gamestart_sv_cheats = autocvar_sv_cheats;
67 float CheatsAllowed(entity this, float i, int argc, float fr) // the cheat gets passed as argument for possible future ACL checking
71 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
74 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
75 if(this.lip < autocvar_sv_clones)
82 if(gamestart_sv_cheats && autocvar_sv_cheats)
85 // if we get here, player is not allowed to cheat. Log it.
87 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this.netname, this.team, false), i);
89 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this.netname, this.team, false), argv(0));
91 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this.netname, this.team, false), fr);
93 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this.netname, this.team, false));
98 #define BEGIN_CHEAT_FUNCTION() \
99 float cheating = 0, attempting = 0
100 #define DID_CHEAT() \
102 #define ADD_CHEATS(e,n) \
103 cheatcount_total += n; \
105 #define END_CHEAT_FUNCTION() \
106 ADD_CHEATS(this, cheating); \
108 #define IS_CHEAT(ent,i,argc,fr) \
109 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
112 float num_autoscreenshot;
113 void info_autoscreenshot_findtarget(entity this)
116 e = find(NULL, targetname, this.target);
119 objerror(this, "Missing target. FAIL!");
122 vector a = vectoangles(e.origin - this.origin);
123 a.x = -a.x; // don't ask
126 // we leave Rick Roll alone
128 spawnfunc(info_autoscreenshot)
130 // this one just has to exist
131 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
133 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
136 if(this.target != "")
137 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
140 float CheatImpulse(entity this, int imp)
142 BEGIN_CHEAT_FUNCTION();
147 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
148 // shared with regular waypoint init, so this is not a cheat by itself
151 this.personal = new(personal_wp);
153 this.personal.origin = this.origin;
154 this.personal.v_angle = this.v_angle;
155 this.personal.velocity = this.velocity;
156 SetResource(this.personal, RES_ROCKETS, GetResource(this, RES_ROCKETS));
157 SetResource(this.personal, RES_BULLETS, GetResource(this, RES_BULLETS));
158 SetResource(this.personal, RES_CELLS, GetResource(this, RES_CELLS));
159 SetResource(this.personal, RES_PLASMA, GetResource(this, RES_PLASMA));
160 SetResource(this.personal, RES_SHELLS, GetResource(this, RES_SHELLS));
161 SetResource(this.personal, RES_FUEL, GetResource(this, RES_FUEL));
162 SetResource(this.personal, RES_HEALTH, max(1, GetResource(this, RES_HEALTH)));
163 SetResource(this.personal, RES_ARMOR, GetResource(this, RES_ARMOR));
164 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
165 STAT(BUFFS, this.personal) = STAT(BUFFS, this);
166 STAT(BUFF_TIME, this.personal) = STAT(BUFF_TIME, this);
167 this.personal.items = this.items;
168 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
169 this.personal.pauserothealth_finished = this.pauserothealth_finished;
170 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
171 this.personal.pauseregen_finished = this.pauseregen_finished;
172 STAT(STRENGTH_FINISHED, this.personal) = STAT(STRENGTH_FINISHED, this);
173 STAT(INVINCIBLE_FINISHED, this.personal) = STAT(INVINCIBLE_FINISHED, this);
174 this.personal.teleport_time = time;
175 break; // this part itself doesn't cheat, so let's not count this
176 case CHIMPULSE_CLONE_MOVING.impulse:
177 IS_CHEAT(this, imp, 0, 0);
178 makevectors (this.v_angle);
179 this.velocity = this.velocity + v_forward * 300;
182 this.velocity = this.velocity - v_forward * 300;
185 case CHIMPULSE_CLONE_STANDING.impulse:
186 IS_CHEAT(this, imp, 0, 0);
191 case CHIMPULSE_GIVE_ALL.impulse:
192 IS_CHEAT(this, imp, 0, 0);
193 CheatCommand(this, tokenize_console("give all"));
194 break; // already counted as cheat
195 case CHIMPULSE_SPEEDRUN.impulse:
196 if(!autocvar_g_allow_checkpoints)
197 IS_CHEAT(this, imp, 0, 0);
200 this.speedrunning = true;
201 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
204 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
208 // Abort speedrun, teleport back
209 setorigin(this, this.personal.origin);
210 this.oldvelocity = this.velocity = this.personal.velocity;
211 this.angles = this.personal.v_angle;
212 this.fixangle = true;
214 MUTATOR_CALLHOOK(AbortSpeedrun, this);
217 SetResource(this, RES_ROCKETS, GetResource(this.personal, RES_ROCKETS));
218 SetResource(this, RES_BULLETS, GetResource(this.personal, RES_BULLETS));
219 SetResource(this, RES_CELLS, GetResource(this.personal, RES_CELLS));
220 SetResource(this, RES_PLASMA, GetResource(this.personal, RES_PLASMA));
221 SetResource(this, RES_SHELLS, GetResource(this.personal, RES_SHELLS));
222 SetResource(this, RES_FUEL, GetResource(this.personal, RES_FUEL));
223 SetResource(this, RES_HEALTH, GetResource(this.personal, RES_HEALTH));
224 SetResource(this, RES_ARMOR, GetResource(this.personal, RES_ARMOR));
225 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
226 STAT(BUFFS, this) = STAT(BUFFS, this.personal);
227 STAT(BUFF_TIME, this) = STAT(BUFF_TIME, this.personal);
228 this.items = this.personal.items;
229 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
230 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
231 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
232 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
233 STAT(STRENGTH_FINISHED, this) = time + STAT(STRENGTH_FINISHED, this.personal) - this.personal.teleport_time;
234 STAT(INVINCIBLE_FINISHED, this) = time + STAT(INVINCIBLE_FINISHED, this.personal) - this.personal.teleport_time;
236 if(!autocvar_g_allow_checkpoints)
241 sprint(this, "UR DEAD AHAHAH))\n");
243 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
245 case CHIMPULSE_TELEPORT.impulse:
246 IS_CHEAT(this, imp, 0, 0);
247 if(this.move_movetype == MOVETYPE_NOCLIP)
249 e = find(NULL, classname, "info_autoscreenshot");
252 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
253 setorigin(this, e.origin);
254 this.angles = e.angles;
256 // should we? this.angles_x = -this.angles_x;
257 this.fixangle = true;
258 this.velocity = '0 0 0';
263 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))
265 sprint(this, "Emergency teleport used random location\n");
266 this.angles_x = -this.angles.x;
267 this.fixangle = true;
268 this.velocity = '0 0 0';
272 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
274 case CHIMPULSE_R00T.impulse:
275 IS_CHEAT(this, imp, 0, 0);
276 RandomSelection_Init();
277 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
278 if(RandomSelection_chosen_ent)
279 e = RandomSelection_chosen_ent;
283 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
284 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
287 setorigin(e2, e.origin);
288 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
291 LOG_INFO("404 Sportsmanship not found.");
296 END_CHEAT_FUNCTION();
300 float CheatCommand(entity this, int argc)
302 BEGIN_CHEAT_FUNCTION();
310 case "pointparticles":
311 IS_CHEAT(this, 0, argc, 0);
316 // origin (0..1, on crosshair line)
320 crosshair_trace(this);
321 start = (1-f) * this.origin + f * trace_endpos;
324 Send_Effect_(argv(1), start, end, f);
328 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
330 case "trailparticles":
331 IS_CHEAT(this, 0, argc, 0);
336 effectnum = _particleeffectnum(argv(1));
337 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
338 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
339 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
343 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
346 IS_CHEAT(this, 0, argc, 0);
352 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
353 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
354 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
356 sprint(this, "cannot make stuff there (bad surface)\n");
361 e.model = strzone(argv(1));
362 e.mdl = "rocket_explode";
363 SetResourceExplicit(e, RES_HEALTH, 1000);
364 setorigin(e, trace_endpos);
365 e.effects = EF_NOMODELFLAGS;
368 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
369 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
371 spawnfunc_func_breakable(e);
375 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
379 sprint(this, "cannot make stuff there (no space)\n");
389 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
392 IS_CHEAT(this, 0, argc, 0);
395 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
399 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
401 case "dragbox_spawn": {
402 IS_CHEAT(this, 0, argc, 0);
403 entity e = new(dragbox_box);
404 setthink(e, DragBox_Think);
406 e.solid = -1; // black
407 setmodel(e, MDL_Null); // network it
409 e.cnt = stof(argv(1));
411 e.cnt = max(0, drag_lastcnt);
413 e.aiment = new(dragbox_corner_1);
415 setmodel(e.aiment, MDL_MARKER);
417 setsize(e.aiment, '0 0 0', '0 0 0');
419 setorigin(e.aiment, stov(argv(2)));
422 crosshair_trace(this);
423 setorigin(e.aiment, trace_endpos);
426 e.enemy = new(dragbox_corner_2);
428 setmodel(e.enemy, MDL_MARKER);
430 setsize(e.enemy, '0 0 0', '0 0 0');
431 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
432 end.x = (end.x > 0) * 2 - 1;
433 end.y = (end.y > 0) * 2 - 1;
434 end.z = (end.z > 0) * 2 - 1;
436 setorigin(e.enemy, stov(argv(3)));
438 setorigin(e.enemy, e.aiment.origin + 32 * end);
440 e.killindicator = new(drag_digit);
441 e.killindicator.owner = e;
442 setattachment(e.killindicator, e, "");
443 setorigin(e.killindicator, '0 0 -8');
444 e.killindicator.killindicator = new(drag_digit);
445 e.killindicator.killindicator.owner = e;
446 setattachment(e.killindicator.killindicator, e, "");
447 setorigin(e.killindicator.killindicator, '0 0 8');
451 case "dragpoint_spawn": {
452 IS_CHEAT(this, 0, argc, 0);
453 entity e = new(dragpoint);
454 setthink(e, DragBox_Think);
456 e.solid = 0; // nothing special
457 setmodel(e, MDL_MARKER);
458 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
461 e.cnt = stof(argv(1));
463 e.cnt = drag_lastcnt;
465 setorigin(e, stov(argv(2)));
468 crosshair_trace(this);
469 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
470 move_out_of_solid(e);
473 e.killindicator = new(drag_digit);
474 e.killindicator.owner = e;
475 setattachment(e.killindicator, e, "");
476 setorigin(e.killindicator, '0 0 40');
477 e.killindicator.killindicator = new(drag_digit);
478 e.killindicator.killindicator.owner = e;
479 setattachment(e.killindicator.killindicator, e, "");
480 setorigin(e.killindicator.killindicator, '0 0 56');
485 IS_CHEAT(this, 0, argc, 0);
486 RandomSelection_Init();
487 crosshair_trace(this);
488 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
489 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
490 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
491 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
492 if(RandomSelection_chosen_ent)
494 delete(RandomSelection_chosen_ent.killindicator.killindicator);
495 delete(RandomSelection_chosen_ent.killindicator);
496 if(RandomSelection_chosen_ent.aiment)
497 delete(RandomSelection_chosen_ent.aiment);
498 if(RandomSelection_chosen_ent.enemy)
499 delete(RandomSelection_chosen_ent.enemy);
500 delete(RandomSelection_chosen_ent);
505 IS_CHEAT(this, 0, argc, 0);
508 RandomSelection_Init();
509 crosshair_trace(this);
510 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
511 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
512 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
513 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
514 if(RandomSelection_chosen_ent)
516 if(substring(argv(1), 0, 1) == "*")
517 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
519 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
524 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
527 IS_CHEAT(this, 0, argc, 0);
530 f = fopen(argv(1), FILE_WRITE);
531 fputs(f, "cmd drag_clear\n");
532 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
534 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
536 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
538 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
544 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
546 case "drag_saveraceent":
547 IS_CHEAT(this, 0, argc, 0);
550 f = fopen(argv(1), FILE_WRITE);
551 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
554 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
555 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
556 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"));
557 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
558 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
561 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
565 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
567 if((e.cnt <= 0 && ent.cnt == 0) || e.cnt == ent.cnt)
569 start = start + ent.origin;
573 start *= 1 / effectnum;
575 fputs(f, "\"classname\" \"info_player_race\"\n");
576 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
577 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
580 fputs(f, "\"target\" \"checkpoint0\"\n");
581 fputs(f, "\"race_place\" \"0\"\n");
585 fputs(f, "\"target\" \"checkpoint0\"\n");
586 fputs(f, "\"race_place\" \"-1\"\n");
590 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
593 // these need race_place
596 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
599 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
601 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
604 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
613 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
616 IS_CHEAT(this, 0, argc, 0);
617 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
619 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
621 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
623 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
625 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
630 IS_CHEAT(this, 0, argc, 0);
631 BITXOR_ASSIGN(this.flags, FL_GODMODE);
632 if(this.flags & FL_GODMODE)
634 sprint(this, "godmode ON\n");
638 sprint(this, "godmode OFF\n");
641 IS_CHEAT(this, 0, argc, 0);
642 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
643 if(this.flags & FL_NOTARGET)
645 sprint(this, "notarget ON\n");
649 sprint(this, "notarget OFF\n");
652 IS_CHEAT(this, 0, argc, 0);
653 if(this.move_movetype != MOVETYPE_NOCLIP)
655 set_movetype(this, MOVETYPE_NOCLIP);
656 sprint(this, "noclip ON\n");
661 set_movetype(this, MOVETYPE_WALK);
662 sprint(this, "noclip OFF\n");
666 IS_CHEAT(this, 0, argc, 0);
667 if(this.move_movetype != MOVETYPE_FLY)
669 set_movetype(this, MOVETYPE_FLY);
670 sprint(this, "flymode ON\n");
675 set_movetype(this, MOVETYPE_WALK);
676 sprint(this, "flymode OFF\n");
680 IS_CHEAT(this, 0, argc, 0);
681 if(GiveItems(this, 1, argc))
685 IS_CHEAT(this, 0, argc, 0);
688 SUB_UseTargets(e, this, NULL);
693 IS_CHEAT(this, 0, argc, 0);
695 e2.killtarget = argv(1);
696 SUB_UseTargets(e2, this, NULL);
700 case "teleporttotarget":
701 IS_CHEAT(this, 0, argc, 0);
702 entity ent = new(cheattriggerteleport);
703 setorigin(ent, ent.origin);
704 ent.target = argv(1);
705 teleport_findtarget(ent);
708 Simple_TeleportPlayer(ent, this);
715 END_CHEAT_FUNCTION();
720 float CheatFrame(entity this)
722 BEGIN_CHEAT_FUNCTION();
724 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
725 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
726 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
727 // grabbing itself no longer being accounted as cheating.
732 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
734 // use cheat dragging if cheats are enabled
735 //if(Drag_IsDragging(this))
736 //crosshair_trace_plusvisibletriggers(this);
737 Drag(this, true, true);
741 Drag(this, false, false); // execute dragging
746 END_CHEAT_FUNCTION();
757 .float dragspeed; // speed of mouse wheel action
758 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
759 .vector draglocalvector; // local attachment vector of the dragentity
760 .float draglocalangle;
765 float Drag(entity this, float force_allow_pick, float ischeat)
767 BEGIN_CHEAT_FUNCTION();
769 // returns true when an entity has been picked up
770 // If pick is true, the object can also be picked up if it's not being held already
771 // If pick is false, only keep dragging the object if it's already being held
776 if(Drag_IsDragging(this))
778 if(PHYS_INPUT_BUTTON_DRAG(this))
780 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
782 Drag_MoveForward(this);
783 CS(this).impulse = 0;
785 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
787 Drag_MoveBackward(this);
788 CS(this).impulse = 0;
790 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
792 Drag_SetSpeed(this, CS(this).impulse - 1);
794 else if(CS(this).impulse == 14)
796 Drag_SetSpeed(this, 9);
807 else if(Drag_CanDrag(this) && PHYS_INPUT_BUTTON_DRAG(this))
809 crosshair_trace_plusvisibletriggers(this);
810 entity e = trace_ent;
811 float pick = force_allow_pick;
812 if (e && !pick && vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
814 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
815 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
816 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
817 // it goes out of range while slinging it around.
821 case 0: // can't grab
823 case 1: // owner can grab
824 if(e.owner == this || e.realowner == this)
827 case 2: // owner and team mates can grab
828 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
831 case 3: // anyone can grab
839 if(e && pick && Drag_IsDraggable(e, this))
842 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
844 Drag_Finish(e.draggedby);
846 detach_sameorigin(e);
847 Drag_Begin(this, e, trace_endpos);
858 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
862 draggee.dragmovetype = draggee.move_movetype;
863 draggee.draggravity = draggee.gravity;
864 set_movetype(draggee, MOVETYPE_WALK);
865 draggee.gravity = 0.00001;
866 UNSET_ONGROUND(draggee);
867 draggee.draggedby = dragger;
869 dragger.dragentity = draggee;
871 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
872 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
873 touchpoint = touchpoint - gettaginfo(draggee, 0);
874 tagscale = (vlen(v_forward) ** -2);
875 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
876 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
877 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
879 dragger.dragspeed = 64;
882 void Drag_Finish(entity dragger)
885 draggee = dragger.dragentity;
887 dragger.dragentity = NULL;
888 draggee.draggedby = NULL;
889 set_movetype(draggee, draggee.dragmovetype);
890 draggee.gravity = draggee.draggravity;
892 switch(draggee.move_movetype)
897 case MOVETYPE_FLYMISSILE:
898 case MOVETYPE_BOUNCE:
899 case MOVETYPE_BOUNCEMISSILE:
900 case MOVETYPE_PHYSICS:
903 draggee.velocity = '0 0 0';
907 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
909 draggee.velocity = '0 0 0';
910 SET_ONGROUND(draggee); // floating items are FUN
914 bool drag_undraggable(entity draggee, entity dragger)
916 // stuff probably shouldn't need this, we should figure out why they do!
917 // exceptions of course are observers and weapon entities, where things mess up
921 float Drag_IsDraggable(entity draggee, entity dragger)
923 // TODO add more checks for bad stuff here
926 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)
927 return false; // probably due to BSP collision
928 //if(draggee.model == "")
931 return ((draggee.draggable) ? draggee.draggable(draggee, dragger) : true);
934 float Drag_MayChangeAngles(entity draggee)
936 // TODO add more checks for bad stuff here
937 if(substring(draggee.model, 0, 1) == "*")
942 void Drag_MoveForward(entity dragger)
944 dragger.dragdistance += dragger.dragspeed;
947 void Drag_SetSpeed(entity dragger, float s)
949 dragger.dragspeed = (2 ** s);
952 void Drag_MoveBackward(entity dragger)
954 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
957 void Drag_Update(entity dragger)
959 vector curorigin, neworigin, goodvelocity;
963 draggee = dragger.dragentity;
964 UNSET_ONGROUND(draggee);
966 curorigin = gettaginfo(draggee, 0);
967 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
968 makevectors(dragger.v_angle);
969 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
970 goodvelocity = (neworigin - curorigin) * (1 / frametime);
972 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
973 dragger.draglocalangle += 360;
974 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
975 dragger.draglocalangle -= 360;
977 f = min(frametime * 10, 1);
978 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
980 if(Drag_MayChangeAngles(draggee))
981 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
983 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
985 vector vecs = '0 0 0';
986 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
987 if(dragger.(weaponentity).movedir.x > 0)
988 vecs = dragger.(weaponentity).movedir;
990 vector dv = v_right * -vecs_y + v_up * vecs_z;
992 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
995 float Drag_CanDrag(entity dragger)
997 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
1000 float Drag_IsDragging(entity dragger)
1002 if(!dragger.dragentity)
1004 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1006 dragger.dragentity = NULL;
1009 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity, dragger))
1011 Drag_Finish(dragger);
1017 void Drag_MoveDrag(entity from, entity to)
1021 to.draggedby = from.draggedby;
1022 to.draggedby.dragentity = to;
1023 from.draggedby = NULL;
1027 void DragBox_Think(entity this)
1029 if(this.aiment && this.enemy)
1031 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1032 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1033 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1034 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1035 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1036 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1037 this.mins = -1 * this.maxs;
1038 setorigin(this, this.origin);
1039 setsize(this, this.mins, this.maxs); // link edict
1042 if(this.cnt == -1) // actually race_place -1
1044 // show "10 10" for qualifying spawns
1045 setmodel(this.killindicator, MDL_NUM(10));
1046 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1048 else if(this.cnt == -2) // actually race_place 0
1050 // show "10 0" for loser spawns
1051 setmodel(this.killindicator, MDL_NUM(10));
1052 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1056 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1057 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1060 this.nextthink = time;