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
67 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
70 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
71 if(this.lip < sv_clones)
78 if(gamestart_sv_cheats && autocvar_sv_cheats)
81 // if we get here, player is not allowed to cheat. Log it.
83 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this, false), i);
85 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this, false), argv(0));
87 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this, false), fr);
89 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this, false));
94 #define BEGIN_CHEAT_FUNCTION() \
95 float cheating = 0, attempting = 0
98 #define ADD_CHEATS(e,n) \
99 cheatcount_total += n; \
101 #define END_CHEAT_FUNCTION() \
102 ADD_CHEATS(this, cheating); \
104 #define IS_CHEAT(ent,i,argc,fr) \
105 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
108 float num_autoscreenshot;
109 void info_autoscreenshot_findtarget(entity this)
112 e = find(NULL, targetname, this.target);
115 objerror(this, "Missing target. FAIL!");
118 vector a = vectoangles(e.origin - this.origin);
119 a.x = -a.x; // don't ask
122 // we leave Rick Roll alone
124 spawnfunc(info_autoscreenshot)
126 // this one just has to exist
127 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
129 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
132 if(this.target != "")
133 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
136 float CheatImpulse(entity this, int imp)
138 BEGIN_CHEAT_FUNCTION();
143 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
144 // shared with regular waypoint init, so this is not a cheat by itself
147 this.personal = new(personal_wp);
149 this.personal.origin = this.origin;
150 this.personal.v_angle = this.v_angle;
151 this.personal.velocity = this.velocity;
152 SetResource(this.personal, RES_ROCKETS, GetResource(this, RES_ROCKETS));
153 SetResource(this.personal, RES_BULLETS, GetResource(this, RES_BULLETS));
154 SetResource(this.personal, RES_CELLS, GetResource(this, RES_CELLS));
155 SetResource(this.personal, RES_PLASMA, GetResource(this, RES_PLASMA));
156 SetResource(this.personal, RES_SHELLS, GetResource(this, RES_SHELLS));
157 SetResource(this.personal, RES_FUEL, GetResource(this, RES_FUEL));
158 SetResource(this.personal, RES_HEALTH, max(1, GetResource(this, RES_HEALTH)));
159 SetResource(this.personal, RES_ARMOR, GetResource(this, RES_ARMOR));
160 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
161 STAT(BUFFS, this.personal) = STAT(BUFFS, this);
162 STAT(BUFF_TIME, this.personal) = STAT(BUFF_TIME, this);
163 this.personal.items = this.items;
164 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
165 this.personal.pauserothealth_finished = this.pauserothealth_finished;
166 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
167 this.personal.pauseregen_finished = this.pauseregen_finished;
168 STAT(STRENGTH_FINISHED, this.personal) = STAT(STRENGTH_FINISHED, this);
169 STAT(INVINCIBLE_FINISHED, this.personal) = STAT(INVINCIBLE_FINISHED, this);
170 this.personal.teleport_time = time;
171 break; // this part itself doesn't cheat, so let's not count this
172 case CHIMPULSE_CLONE_MOVING.impulse:
173 IS_CHEAT(this, imp, 0, 0);
174 makevectors (this.v_angle);
175 this.velocity = this.velocity + v_forward * 300;
178 this.velocity = this.velocity - v_forward * 300;
181 case CHIMPULSE_CLONE_STANDING.impulse:
182 IS_CHEAT(this, imp, 0, 0);
187 case CHIMPULSE_GIVE_ALL.impulse:
188 IS_CHEAT(this, imp, 0, 0);
189 CheatCommand(this, tokenize_console("give all"));
190 break; // already counted as cheat
191 case CHIMPULSE_SPEEDRUN.impulse:
192 if(!autocvar_g_allow_checkpoints)
193 IS_CHEAT(this, imp, 0, 0);
196 this.speedrunning = true;
197 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
200 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
204 // Abort speedrun, teleport back
205 setorigin(this, this.personal.origin);
206 this.oldvelocity = this.velocity = this.personal.velocity;
207 this.angles = this.personal.v_angle;
208 this.fixangle = true;
210 MUTATOR_CALLHOOK(AbortSpeedrun, this);
213 SetResource(this, RES_ROCKETS, GetResource(this.personal, RES_ROCKETS));
214 SetResource(this, RES_BULLETS, GetResource(this.personal, RES_BULLETS));
215 SetResource(this, RES_CELLS, GetResource(this.personal, RES_CELLS));
216 SetResource(this, RES_PLASMA, GetResource(this.personal, RES_PLASMA));
217 SetResource(this, RES_SHELLS, GetResource(this.personal, RES_SHELLS));
218 SetResource(this, RES_FUEL, GetResource(this.personal, RES_FUEL));
219 SetResource(this, RES_HEALTH, GetResource(this.personal, RES_HEALTH));
220 SetResource(this, RES_ARMOR, GetResource(this.personal, RES_ARMOR));
221 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
222 STAT(BUFFS, this) = STAT(BUFFS, this.personal);
223 STAT(BUFF_TIME, this) = STAT(BUFF_TIME, this.personal);
224 this.items = this.personal.items;
225 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
226 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
227 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
228 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
229 STAT(STRENGTH_FINISHED, this) = time + STAT(STRENGTH_FINISHED, this.personal) - this.personal.teleport_time;
230 STAT(INVINCIBLE_FINISHED, this) = time + STAT(INVINCIBLE_FINISHED, this.personal) - this.personal.teleport_time;
232 if(!autocvar_g_allow_checkpoints)
237 sprint(this, "UR DEAD AHAHAH))\n");
239 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
241 case CHIMPULSE_TELEPORT.impulse:
242 IS_CHEAT(this, imp, 0, 0);
243 if(this.move_movetype == MOVETYPE_NOCLIP)
245 e = find(NULL, classname, "info_autoscreenshot");
248 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
249 setorigin(this, e.origin);
250 this.angles = e.angles;
252 // should we? this.angles_x = -this.angles_x;
253 this.fixangle = true;
254 this.velocity = '0 0 0';
259 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))
261 sprint(this, "Emergency teleport used random location\n");
262 this.angles_x = -this.angles.x;
263 this.fixangle = true;
264 this.velocity = '0 0 0';
268 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
270 case CHIMPULSE_R00T.impulse:
271 IS_CHEAT(this, imp, 0, 0);
272 RandomSelection_Init();
273 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
274 if(RandomSelection_chosen_ent)
275 e = RandomSelection_chosen_ent;
279 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
280 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
283 setorigin(e2, e.origin);
284 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
287 LOG_INFO("404 Sportsmanship not found.");
292 END_CHEAT_FUNCTION();
296 float CheatCommand(entity this, int argc)
298 BEGIN_CHEAT_FUNCTION();
306 case "pointparticles":
307 IS_CHEAT(this, 0, argc, 0);
312 // origin (0..1, on crosshair line)
316 crosshair_trace(this);
317 start = (1-f) * this.origin + f * trace_endpos;
320 Send_Effect_(argv(1), start, end, f);
324 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
326 case "trailparticles":
327 IS_CHEAT(this, 0, argc, 0);
332 effectnum = _particleeffectnum(argv(1));
333 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
334 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
335 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
339 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
342 IS_CHEAT(this, 0, argc, 0);
348 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
349 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
350 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
352 sprint(this, "cannot make stuff there (bad surface)\n");
357 e.model = strzone(argv(1));
358 e.mdl = "rocket_explode";
359 SetResourceExplicit(e, RES_HEALTH, 1000);
360 setorigin(e, trace_endpos);
361 e.effects = EF_NOMODELFLAGS;
364 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
365 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
367 spawnfunc_func_breakable(e);
371 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
375 sprint(this, "cannot make stuff there (no space)\n");
385 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
388 IS_CHEAT(this, 0, argc, 0);
391 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
395 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
397 case "dragbox_spawn": {
398 IS_CHEAT(this, 0, argc, 0);
399 entity e = new(dragbox_box);
400 setthink(e, DragBox_Think);
402 e.solid = -1; // black
403 setmodel(e, MDL_Null); // network it
405 e.cnt = stof(argv(1));
407 e.cnt = max(0, drag_lastcnt);
409 e.aiment = new(dragbox_corner_1);
411 setmodel(e.aiment, MDL_MARKER);
413 setsize(e.aiment, '0 0 0', '0 0 0');
415 setorigin(e.aiment, stov(argv(2)));
418 crosshair_trace(this);
419 setorigin(e.aiment, trace_endpos);
422 e.enemy = new(dragbox_corner_2);
424 setmodel(e.enemy, MDL_MARKER);
426 setsize(e.enemy, '0 0 0', '0 0 0');
427 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
428 end.x = (end.x > 0) * 2 - 1;
429 end.y = (end.y > 0) * 2 - 1;
430 end.z = (end.z > 0) * 2 - 1;
432 setorigin(e.enemy, stov(argv(3)));
434 setorigin(e.enemy, e.aiment.origin + 32 * end);
436 e.killindicator = new(drag_digit);
437 e.killindicator.owner = e;
438 setattachment(e.killindicator, e, "");
439 setorigin(e.killindicator, '0 0 -8');
440 e.killindicator.killindicator = new(drag_digit);
441 e.killindicator.killindicator.owner = e;
442 setattachment(e.killindicator.killindicator, e, "");
443 setorigin(e.killindicator.killindicator, '0 0 8');
447 case "dragpoint_spawn": {
448 IS_CHEAT(this, 0, argc, 0);
449 entity e = new(dragpoint);
450 setthink(e, DragBox_Think);
452 e.solid = 0; // nothing special
453 setmodel(e, MDL_MARKER);
454 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
457 e.cnt = stof(argv(1));
459 e.cnt = drag_lastcnt;
461 setorigin(e, stov(argv(2)));
464 crosshair_trace(this);
465 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
466 move_out_of_solid(e);
469 e.killindicator = new(drag_digit);
470 e.killindicator.owner = e;
471 setattachment(e.killindicator, e, "");
472 setorigin(e.killindicator, '0 0 40');
473 e.killindicator.killindicator = new(drag_digit);
474 e.killindicator.killindicator.owner = e;
475 setattachment(e.killindicator.killindicator, e, "");
476 setorigin(e.killindicator.killindicator, '0 0 56');
481 IS_CHEAT(this, 0, argc, 0);
482 RandomSelection_Init();
483 crosshair_trace(this);
484 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
485 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
486 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
487 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
488 if(RandomSelection_chosen_ent)
490 delete(RandomSelection_chosen_ent.killindicator.killindicator);
491 delete(RandomSelection_chosen_ent.killindicator);
492 if(RandomSelection_chosen_ent.aiment)
493 delete(RandomSelection_chosen_ent.aiment);
494 if(RandomSelection_chosen_ent.enemy)
495 delete(RandomSelection_chosen_ent.enemy);
496 delete(RandomSelection_chosen_ent);
501 IS_CHEAT(this, 0, argc, 0);
504 RandomSelection_Init();
505 crosshair_trace(this);
506 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
507 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
508 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
509 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
510 if(RandomSelection_chosen_ent)
512 if(substring(argv(1), 0, 1) == "*")
513 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
515 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
520 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
523 IS_CHEAT(this, 0, argc, 0);
526 f = fopen(argv(1), FILE_WRITE);
527 fputs(f, "cmd drag_clear\n");
528 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
530 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
532 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
534 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
540 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
542 case "drag_saveraceent":
543 IS_CHEAT(this, 0, argc, 0);
546 f = fopen(argv(1), FILE_WRITE);
547 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
550 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
551 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
552 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"));
553 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
554 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
557 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
561 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
563 if((e.cnt <= 0 && ent.cnt == 0) || e.cnt == ent.cnt)
565 start = start + ent.origin;
569 start *= 1 / effectnum;
571 fputs(f, "\"classname\" \"info_player_race\"\n");
572 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
573 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
576 fputs(f, "\"target\" \"checkpoint0\"\n");
577 fputs(f, "\"race_place\" \"0\"\n");
581 fputs(f, "\"target\" \"checkpoint0\"\n");
582 fputs(f, "\"race_place\" \"-1\"\n");
586 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
589 // these need race_place
592 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
595 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
597 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
600 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
609 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
612 IS_CHEAT(this, 0, argc, 0);
613 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
615 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
617 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
619 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
621 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
626 IS_CHEAT(this, 0, argc, 0);
627 BITXOR_ASSIGN(this.flags, FL_GODMODE);
628 if(this.flags & FL_GODMODE)
630 sprint(this, "godmode ON\n");
634 sprint(this, "godmode OFF\n");
637 IS_CHEAT(this, 0, argc, 0);
638 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
639 if(this.flags & FL_NOTARGET)
641 sprint(this, "notarget ON\n");
645 sprint(this, "notarget OFF\n");
648 IS_CHEAT(this, 0, argc, 0);
649 if(this.move_movetype != MOVETYPE_NOCLIP)
651 set_movetype(this, MOVETYPE_NOCLIP);
652 sprint(this, "noclip ON\n");
657 set_movetype(this, MOVETYPE_WALK);
658 sprint(this, "noclip OFF\n");
662 IS_CHEAT(this, 0, argc, 0);
663 if(this.move_movetype != MOVETYPE_FLY)
665 set_movetype(this, MOVETYPE_FLY);
666 sprint(this, "flymode ON\n");
671 set_movetype(this, MOVETYPE_WALK);
672 sprint(this, "flymode OFF\n");
676 IS_CHEAT(this, 0, argc, 0);
677 if(GiveItems(this, 1, argc))
681 IS_CHEAT(this, 0, argc, 0);
684 SUB_UseTargets(e, this, NULL);
689 IS_CHEAT(this, 0, argc, 0);
691 e2.killtarget = argv(1);
692 SUB_UseTargets(e2, this, NULL);
696 case "teleporttotarget":
697 IS_CHEAT(this, 0, argc, 0);
698 entity ent = new(cheattriggerteleport);
699 setorigin(ent, ent.origin);
700 ent.target = argv(1);
701 teleport_findtarget(ent);
704 Simple_TeleportPlayer(ent, this);
711 END_CHEAT_FUNCTION();
716 float CheatFrame(entity this)
718 BEGIN_CHEAT_FUNCTION();
720 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
721 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
722 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
723 // grabbing itself no longer being accounted as cheating.
728 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
730 // use cheat dragging if cheats are enabled
731 //if(Drag_IsDragging(this))
732 //crosshair_trace_plusvisibletriggers(this);
733 Drag(this, true, true);
737 Drag(this, false, false); // execute dragging
742 END_CHEAT_FUNCTION();
753 .float dragspeed; // speed of mouse wheel action
754 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
755 .vector draglocalvector; // local attachment vector of the dragentity
756 .float draglocalangle;
761 float Drag(entity this, float force_allow_pick, float ischeat)
763 BEGIN_CHEAT_FUNCTION();
765 // returns true when an entity has been picked up
766 // If pick is true, the object can also be picked up if it's not being held already
767 // If pick is false, only keep dragging the object if it's already being held
772 if(Drag_IsDragging(this))
774 if(PHYS_INPUT_BUTTON_DRAG(this))
776 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
778 Drag_MoveForward(this);
779 CS(this).impulse = 0;
781 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
783 Drag_MoveBackward(this);
784 CS(this).impulse = 0;
786 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
788 Drag_SetSpeed(this, CS(this).impulse - 1);
790 else if(CS(this).impulse == 14)
792 Drag_SetSpeed(this, 9);
803 else if(Drag_CanDrag(this) && PHYS_INPUT_BUTTON_DRAG(this))
805 crosshair_trace_plusvisibletriggers(this);
806 entity e = trace_ent;
807 float pick = force_allow_pick;
808 if (e && !pick && vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
810 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
811 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
812 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
813 // it goes out of range while slinging it around.
817 case 0: // can't grab
819 case 1: // owner can grab
820 if(e.owner == this || e.realowner == this)
823 case 2: // owner and team mates can grab
824 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
827 case 3: // anyone can grab
835 if(e && pick && Drag_IsDraggable(e, this))
838 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
840 Drag_Finish(e.draggedby);
842 detach_sameorigin(e);
843 Drag_Begin(this, e, trace_endpos);
854 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
858 draggee.dragmovetype = draggee.move_movetype;
859 draggee.draggravity = draggee.gravity;
860 set_movetype(draggee, MOVETYPE_WALK);
861 draggee.gravity = 0.00001;
862 UNSET_ONGROUND(draggee);
863 draggee.draggedby = dragger;
865 dragger.dragentity = draggee;
867 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
868 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
869 touchpoint = touchpoint - gettaginfo(draggee, 0);
870 tagscale = (vlen(v_forward) ** -2);
871 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
872 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
873 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
875 dragger.dragspeed = 64;
878 void Drag_Finish(entity dragger)
881 draggee = dragger.dragentity;
883 dragger.dragentity = NULL;
884 draggee.draggedby = NULL;
885 set_movetype(draggee, draggee.dragmovetype);
886 draggee.gravity = draggee.draggravity;
888 switch(draggee.move_movetype)
893 case MOVETYPE_FLYMISSILE:
894 case MOVETYPE_BOUNCE:
895 case MOVETYPE_BOUNCEMISSILE:
896 case MOVETYPE_PHYSICS:
899 draggee.velocity = '0 0 0';
903 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
905 draggee.velocity = '0 0 0';
906 SET_ONGROUND(draggee); // floating items are FUN
910 bool drag_undraggable(entity draggee, entity dragger)
912 // stuff probably shouldn't need this, we should figure out why they do!
913 // exceptions of course are observers and weapon entities, where things mess up
917 float Drag_IsDraggable(entity draggee, entity dragger)
919 // TODO add more checks for bad stuff here
922 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)
923 return false; // probably due to BSP collision
924 //if(draggee.model == "")
927 return ((draggee.draggable) ? draggee.draggable(draggee, dragger) : true);
930 float Drag_MayChangeAngles(entity draggee)
932 // TODO add more checks for bad stuff here
933 if(substring(draggee.model, 0, 1) == "*")
938 void Drag_MoveForward(entity dragger)
940 dragger.dragdistance += dragger.dragspeed;
943 void Drag_SetSpeed(entity dragger, float s)
945 dragger.dragspeed = (2 ** s);
948 void Drag_MoveBackward(entity dragger)
950 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
953 void Drag_Update(entity dragger)
955 vector curorigin, neworigin, goodvelocity;
959 draggee = dragger.dragentity;
960 UNSET_ONGROUND(draggee);
962 curorigin = gettaginfo(draggee, 0);
963 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
964 makevectors(dragger.v_angle);
965 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
966 goodvelocity = (neworigin - curorigin) * (1 / frametime);
968 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
969 dragger.draglocalangle += 360;
970 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
971 dragger.draglocalangle -= 360;
973 f = min(frametime * 10, 1);
974 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
976 if(Drag_MayChangeAngles(draggee))
977 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
979 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
981 vector vecs = '0 0 0';
982 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
983 if(dragger.(weaponentity).movedir.x > 0)
984 vecs = dragger.(weaponentity).movedir;
986 vector dv = v_right * -vecs_y + v_up * vecs_z;
988 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
991 float Drag_CanDrag(entity dragger)
993 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
996 float Drag_IsDragging(entity dragger)
998 if(!dragger.dragentity)
1000 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1002 dragger.dragentity = NULL;
1005 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity, dragger))
1007 Drag_Finish(dragger);
1013 void Drag_MoveDrag(entity from, entity to)
1017 to.draggedby = from.draggedby;
1018 to.draggedby.dragentity = to;
1019 from.draggedby = NULL;
1023 void DragBox_Think(entity this)
1025 if(this.aiment && this.enemy)
1027 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1028 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1029 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1030 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1031 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1032 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1033 this.mins = -1 * this.maxs;
1034 setorigin(this, this.origin);
1035 setsize(this, this.mins, this.maxs); // link edict
1038 if(this.cnt == -1) // actually race_place -1
1040 // show "10 10" for qualifying spawns
1041 setmodel(this.killindicator, MDL_NUM(10));
1042 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1044 else if(this.cnt == -2) // actually race_place 0
1046 // show "10 0" for loser spawns
1047 setmodel(this.killindicator, MDL_NUM(10));
1048 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1052 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1053 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1056 this.nextthink = time;