3 #include "weapons/tracing.qh"
4 #include <common/constants.qh>
5 #include <common/deathtypes/all.qh>
6 #include <common/effects/all.qh>
7 #include <common/items/_mod.qh>
8 #include <common/mapobjects/func/breakable.qh>
9 #include <common/mapobjects/subs.qh>
10 #include <common/mapobjects/teleporters.qh>
11 #include <common/mapobjects/triggers.qh>
12 #include <common/monsters/_mod.qh>
13 #include <common/mutators/mutator/status_effects/_mod.qh>
14 #include <common/physics/player.qh>
15 #include <common/resources/sv_resources.qh>
16 #include <common/stats.qh>
17 #include <common/util.qh>
18 #include <common/weapons/_all.qh>
19 #include <common/weapons/_all.qh>
20 #include <lib/csqcmodel/sv_model.qh>
21 #include <lib/warpzone/anglestransform.qh>
22 #include <lib/warpzone/common.qh>
23 #include <lib/warpzone/util_server.qh>
24 #include <server/clientkill.qh>
25 #include <server/damage.qh>
26 #include <server/main.qh>
27 #include <server/mutators/_mod.qh>
28 #include <server/player.qh>
29 #include <server/race.qh>
30 #include <server/world.qh>
34 float CheatImpulse(entity this, int imp) { return 0; }
35 float CheatCommand(entity this, int argc) { return 0; }
36 float CheatFrame(entity this) { return 0; }
37 void CheatInit() { cheatcount_total = world.cheatcount; }
38 void CheatShutdown() { }
39 void Drag_MoveDrag(entity from, entity to) { }
44 float gamestart_sv_cheats;
50 gamestart_sv_cheats = autocvar_sv_cheats;
57 float CheatsAllowed(entity this, float i, int argc, float fr) // the cheat gets passed as argument for possible future ACL checking
61 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
64 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
65 if(this.lip < autocvar_sv_clones)
72 if(gamestart_sv_cheats && autocvar_sv_cheats)
75 // if we get here, player is not allowed to cheat. Log it.
77 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this.netname, this.team, false), i);
79 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this.netname, this.team, false), argv(0));
81 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this.netname, this.team, false), fr);
83 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this.netname, this.team, false));
88 #define BEGIN_CHEAT_FUNCTION() \
89 float cheating = 0, attempting = 0
92 #define ADD_CHEATS(e,n) \
93 cheatcount_total += n; \
95 #define END_CHEAT_FUNCTION() \
96 ADD_CHEATS(this, cheating); \
98 #define IS_CHEAT(ent,i,argc,fr) \
99 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
102 float num_autoscreenshot;
103 void info_autoscreenshot_findtarget(entity this)
106 e = find(NULL, targetname, this.target);
109 objerror(this, "Missing target. FAIL!");
112 vector a = vectoangles(e.origin - this.origin);
113 a.x = -a.x; // don't ask
116 // we leave Rick Roll alone
118 spawnfunc(info_autoscreenshot)
120 // this one just has to exist
121 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
123 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
126 if(this.target != "")
127 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
130 float CheatImpulse(entity this, int imp)
132 BEGIN_CHEAT_FUNCTION();
137 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
138 // shared with regular waypoint init, so this is not a cheat by itself
141 this.personal = new(personal_wp);
143 this.personal.origin = this.origin;
144 this.personal.v_angle = this.v_angle;
145 this.personal.velocity = this.velocity;
146 SetResource(this.personal, RES_ROCKETS, GetResource(this, RES_ROCKETS));
147 SetResource(this.personal, RES_BULLETS, GetResource(this, RES_BULLETS));
148 SetResource(this.personal, RES_CELLS, GetResource(this, RES_CELLS));
149 SetResource(this.personal, RES_PLASMA, GetResource(this, RES_PLASMA));
150 SetResource(this.personal, RES_SHELLS, GetResource(this, RES_SHELLS));
151 SetResource(this.personal, RES_FUEL, GetResource(this, RES_FUEL));
152 SetResource(this.personal, RES_HEALTH, max(1, GetResource(this, RES_HEALTH)));
153 SetResource(this.personal, RES_ARMOR, GetResource(this, RES_ARMOR));
154 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
155 StatusEffects_copy(this.statuseffects, this.personal, 0);
156 this.personal.items = this.items;
157 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
158 this.personal.pauserothealth_finished = this.pauserothealth_finished;
159 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
160 this.personal.pauseregen_finished = this.pauseregen_finished;
161 this.personal.teleport_time = time;
162 break; // this part itself doesn't cheat, so let's not count this
163 case CHIMPULSE_CLONE_MOVING.impulse:
164 IS_CHEAT(this, imp, 0, 0);
165 makevectors (this.v_angle);
166 this.velocity = this.velocity + v_forward * 300;
169 this.velocity = this.velocity - v_forward * 300;
172 case CHIMPULSE_CLONE_STANDING.impulse:
173 IS_CHEAT(this, imp, 0, 0);
178 case CHIMPULSE_GIVE_ALL.impulse:
179 IS_CHEAT(this, imp, 0, 0);
180 CheatCommand(this, tokenize_console("give all"));
181 break; // already counted as cheat
182 case CHIMPULSE_SPEEDRUN.impulse:
183 if(!autocvar_g_allow_checkpoints)
184 IS_CHEAT(this, imp, 0, 0);
187 this.speedrunning = true;
188 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
191 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
195 // Abort speedrun, teleport back
196 setorigin(this, this.personal.origin);
197 this.oldvelocity = this.velocity = this.personal.velocity;
198 this.angles = this.personal.v_angle;
199 this.fixangle = true;
201 MUTATOR_CALLHOOK(AbortSpeedrun, this);
204 SetResource(this, RES_ROCKETS, GetResource(this.personal, RES_ROCKETS));
205 SetResource(this, RES_BULLETS, GetResource(this.personal, RES_BULLETS));
206 SetResource(this, RES_CELLS, GetResource(this.personal, RES_CELLS));
207 SetResource(this, RES_PLASMA, GetResource(this.personal, RES_PLASMA));
208 SetResource(this, RES_SHELLS, GetResource(this.personal, RES_SHELLS));
209 SetResource(this, RES_FUEL, GetResource(this.personal, RES_FUEL));
210 SetResource(this, RES_HEALTH, GetResource(this.personal, RES_HEALTH));
211 SetResource(this, RES_ARMOR, GetResource(this.personal, RES_ARMOR));
212 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
213 this.items = this.personal.items;
214 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
215 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
216 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
217 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
218 StatusEffects_copy(this.personal, this.statuseffects, this.personal.teleport_time);
219 StatusEffects_update(this);
221 if(!autocvar_g_allow_checkpoints)
226 sprint(this, "UR DEAD AHAHAH))\n");
228 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
230 case CHIMPULSE_TELEPORT.impulse:
231 IS_CHEAT(this, imp, 0, 0);
232 if(this.move_movetype == MOVETYPE_NOCLIP)
234 e = find(NULL, classname, "info_autoscreenshot");
237 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
238 setorigin(this, e.origin);
239 this.angles = e.angles;
241 // should we? this.angles_x = -this.angles_x;
242 this.fixangle = true;
243 this.velocity = '0 0 0';
248 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))
250 sprint(this, "Emergency teleport used random location\n");
251 this.angles_x = -this.angles.x;
252 this.fixangle = true;
253 this.velocity = '0 0 0';
257 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
259 case CHIMPULSE_R00T.impulse:
260 IS_CHEAT(this, imp, 0, 0);
261 RandomSelection_Init();
262 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
263 if(RandomSelection_chosen_ent)
264 e = RandomSelection_chosen_ent;
268 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
269 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
272 setorigin(e2, e.origin);
273 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
276 LOG_INFO("404 Sportsmanship not found.");
281 END_CHEAT_FUNCTION();
285 float CheatCommand(entity this, int argc)
287 BEGIN_CHEAT_FUNCTION();
295 case "pointparticles":
296 IS_CHEAT(this, 0, argc, 0);
300 crosshair_trace(this);
301 start = (1-f) * this.origin + f * trace_endpos;
304 Send_Effect_(argv(1), start, end, f);
308 sprint(this, "Usage:^3 sv_cheats 1; restart; cmd pointparticles <effectname> <position> <velocity> <countmultiplier>\n");
309 sprint(this, " Where <position> is a number from 0 to 1 representing distance on the crosshair line,\n");
310 sprint(this, " and <velocity> is a vector \"x y z\"\n");
312 case "trailparticles":
313 IS_CHEAT(this, 0, argc, 0);
318 effectnum = _particleeffectnum(argv(1));
319 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
320 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
321 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
325 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles <effectname>\n");
328 IS_CHEAT(this, 0, argc, 0);
332 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
333 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
334 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
336 sprint(this, "cannot make stuff there (bad surface)\n");
340 entity e = new(func_breakable);
341 e.model = strzone(argv(1));
342 e.mdl = "rocket_explode";
343 SetResourceExplicit(e, RES_HEALTH, 1000);
344 setorigin(e, trace_endpos);
345 e.effects = EF_NOMODELFLAGS;
348 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
349 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
351 func_breakable_setup(e);
355 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
359 sprint(this, "cannot make stuff there (no space)\n");
370 sprint(this, "Usage:^3 sv_cheats 1; restart; cmd make <modelname> <mode>\n");
371 sprint(this, " where <mode> can be 0, 1 or 2\n");
375 IS_CHEAT(this, 0, argc, 0);
378 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
382 sprint(this, "Usage:^3 sv_cheats 1; restart; cmd penalty <duration> <reason>))\n");
384 case "dragbox_spawn": {
385 IS_CHEAT(this, 0, argc, 0);
386 entity e = new(dragbox_box);
387 setthink(e, DragBox_Think);
389 e.solid = -1; // black
390 setmodel(e, MDL_Null); // network it
392 e.cnt = stof(argv(1));
394 e.cnt = max(0, drag_lastcnt);
396 e.aiment = new(dragbox_corner_1);
398 setmodel(e.aiment, MDL_MARKER);
400 setsize(e.aiment, '0 0 0', '0 0 0');
402 setorigin(e.aiment, stov(argv(2)));
405 crosshair_trace(this);
406 setorigin(e.aiment, trace_endpos);
409 e.enemy = new(dragbox_corner_2);
411 setmodel(e.enemy, MDL_MARKER);
413 setsize(e.enemy, '0 0 0', '0 0 0');
414 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
415 end.x = (end.x > 0) * 2 - 1;
416 end.y = (end.y > 0) * 2 - 1;
417 end.z = (end.z > 0) * 2 - 1;
419 setorigin(e.enemy, stov(argv(3)));
421 setorigin(e.enemy, e.aiment.origin + 32 * end);
423 e.killindicator = new(drag_digit);
424 e.killindicator.owner = e;
425 setattachment(e.killindicator, e, "");
426 setorigin(e.killindicator, '0 0 -8');
427 e.killindicator.killindicator = new(drag_digit);
428 e.killindicator.killindicator.owner = e;
429 setattachment(e.killindicator.killindicator, e, "");
430 setorigin(e.killindicator.killindicator, '0 0 8');
434 case "dragpoint_spawn": {
435 IS_CHEAT(this, 0, argc, 0);
436 entity e = new(dragpoint);
437 setthink(e, DragBox_Think);
439 e.solid = 0; // nothing special
440 setmodel(e, MDL_MARKER);
441 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
444 e.cnt = stof(argv(1));
446 e.cnt = drag_lastcnt;
448 setorigin(e, stov(argv(2)));
451 crosshair_trace(this);
452 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
453 move_out_of_solid(e);
456 e.killindicator = new(drag_digit);
457 e.killindicator.owner = e;
458 setattachment(e.killindicator, e, "");
459 setorigin(e.killindicator, '0 0 40');
460 e.killindicator.killindicator = new(drag_digit);
461 e.killindicator.killindicator.owner = e;
462 setattachment(e.killindicator.killindicator, e, "");
463 setorigin(e.killindicator.killindicator, '0 0 56');
468 IS_CHEAT(this, 0, argc, 0);
469 RandomSelection_Init();
470 crosshair_trace(this);
471 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
472 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
473 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
474 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
475 if(RandomSelection_chosen_ent)
477 delete(RandomSelection_chosen_ent.killindicator.killindicator);
478 delete(RandomSelection_chosen_ent.killindicator);
479 if(RandomSelection_chosen_ent.aiment)
480 delete(RandomSelection_chosen_ent.aiment);
481 if(RandomSelection_chosen_ent.enemy)
482 delete(RandomSelection_chosen_ent.enemy);
483 delete(RandomSelection_chosen_ent);
488 IS_CHEAT(this, 0, argc, 0);
491 RandomSelection_Init();
492 crosshair_trace(this);
493 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
494 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
495 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
496 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
497 if(RandomSelection_chosen_ent)
499 if(substring(argv(1), 0, 1) == "*")
500 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
502 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
507 sprint(this, "Usage:^3 sv_cheats 1; restart; cmd dragbox_setcnt <cnt>\n");
510 IS_CHEAT(this, 0, argc, 0);
513 f = fopen(argv(1), FILE_WRITE);
514 fputs(f, "cmd drag_clear\n");
515 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
517 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
519 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
521 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
527 sprint(this, "Usage:^3 sv_cheats 1; restart; cmd dragbox_save <filename>\n");
529 case "drag_saveraceent":
530 IS_CHEAT(this, 0, argc, 0);
533 f = fopen(argv(1), FILE_WRITE);
534 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
537 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
538 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
539 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"));
540 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
541 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
544 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
548 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
550 if((e.cnt <= 0 && ent.cnt == 0) || e.cnt == ent.cnt)
552 start = start + ent.origin;
556 start *= 1 / effectnum;
558 fputs(f, "\"classname\" \"info_player_race\"\n");
559 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
560 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
563 fputs(f, "\"target\" \"checkpoint0\"\n");
564 fputs(f, "\"race_place\" \"0\"\n");
568 fputs(f, "\"target\" \"checkpoint0\"\n");
569 fputs(f, "\"race_place\" \"-1\"\n");
573 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
576 // these need race_place
579 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
582 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
584 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
587 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
596 sprint(this, "Usage:^3 sv_cheats 1; restart; cmd dragbox_save <filename>\n");
599 IS_CHEAT(this, 0, argc, 0);
600 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
602 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
604 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
606 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
608 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
613 IS_CHEAT(this, 0, argc, 0);
614 BITXOR_ASSIGN(this.flags, FL_GODMODE);
615 if(this.flags & FL_GODMODE)
617 sprint(this, "godmode ON\n");
621 sprint(this, "godmode OFF\n");
624 IS_CHEAT(this, 0, argc, 0);
625 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
626 if(this.flags & FL_NOTARGET)
628 sprint(this, "notarget ON\n");
632 sprint(this, "notarget OFF\n");
635 IS_CHEAT(this, 0, argc, 0);
636 if(this.move_movetype != MOVETYPE_NOCLIP)
638 set_movetype(this, MOVETYPE_NOCLIP);
639 sprint(this, "noclip ON\n");
644 set_movetype(this, MOVETYPE_WALK);
645 sprint(this, "noclip OFF\n");
649 IS_CHEAT(this, 0, argc, 0);
650 if(this.move_movetype != MOVETYPE_FLY)
652 set_movetype(this, MOVETYPE_FLY);
653 sprint(this, "flymode ON\n");
658 set_movetype(this, MOVETYPE_WALK);
659 sprint(this, "flymode OFF\n");
663 IS_CHEAT(this, 0, argc, 0);
664 if(GiveItems(this, 1, argc))
668 IS_CHEAT(this, 0, argc, 0);
671 SUB_UseTargets(e, this, NULL);
676 IS_CHEAT(this, 0, argc, 0);
678 e2.killtarget = argv(1);
679 SUB_UseTargets(e2, this, NULL);
683 case "teleporttotarget":
684 IS_CHEAT(this, 0, argc, 0);
685 entity ent = new(cheattriggerteleport);
686 setorigin(ent, ent.origin);
687 ent.target = argv(1);
688 teleport_findtarget(ent);
691 Simple_TeleportPlayer(ent, this);
698 END_CHEAT_FUNCTION();
703 float CheatFrame(entity this)
705 BEGIN_CHEAT_FUNCTION();
707 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
708 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
709 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
710 // grabbing itself no longer being accounted as cheating.
715 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
717 // use cheat dragging if cheats are enabled
718 //if(Drag_IsDragging(this))
719 //crosshair_trace_plusvisibletriggers(this);
720 Drag(this, true, true);
724 Drag(this, false, false); // execute dragging
729 END_CHEAT_FUNCTION();
740 .float dragspeed; // speed of mouse wheel action
741 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
742 .vector draglocalvector; // local attachment vector of the dragentity
743 .float draglocalangle;
748 float Drag(entity this, float force_allow_pick, float ischeat)
750 BEGIN_CHEAT_FUNCTION();
752 // returns true when an entity has been picked up
753 // If pick is true, the object can also be picked up if it's not being held already
754 // If pick is false, only keep dragging the object if it's already being held
759 if(Drag_IsDragging(this))
761 if(PHYS_INPUT_BUTTON_DRAG(this))
763 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
765 Drag_MoveForward(this);
766 CS(this).impulse = 0;
768 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
770 Drag_MoveBackward(this);
771 CS(this).impulse = 0;
773 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
775 Drag_SetSpeed(this, CS(this).impulse - 1);
777 else if(CS(this).impulse == 14)
779 Drag_SetSpeed(this, 9);
790 else if(Drag_CanDrag(this) && PHYS_INPUT_BUTTON_DRAG(this))
792 crosshair_trace_plusvisibletriggers(this);
793 entity e = trace_ent;
794 float pick = force_allow_pick;
795 if (e && !pick && vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
797 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
798 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
799 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
800 // it goes out of range while slinging it around.
804 case 0: // can't grab
806 case 1: // owner can grab
807 if(e.owner == this || e.realowner == this)
810 case 2: // owner and team mates can grab
811 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
814 case 3: // anyone can grab
822 if(e && pick && Drag_IsDraggable(e, this))
825 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
827 Drag_Finish(e.draggedby);
829 detach_sameorigin(e);
830 Drag_Begin(this, e, trace_endpos);
841 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
845 draggee.dragmovetype = draggee.move_movetype;
846 draggee.draggravity = draggee.gravity;
847 set_movetype(draggee, MOVETYPE_WALK);
848 draggee.gravity = 0.00001;
849 UNSET_ONGROUND(draggee);
850 draggee.draggedby = dragger;
852 dragger.dragentity = draggee;
854 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
855 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
856 touchpoint = touchpoint - gettaginfo(draggee, 0);
857 tagscale = (vlen(v_forward) ** -2);
858 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
859 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
860 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
862 dragger.dragspeed = 64;
865 void Drag_Finish(entity dragger)
868 draggee = dragger.dragentity;
870 dragger.dragentity = NULL;
871 draggee.draggedby = NULL;
872 set_movetype(draggee, draggee.dragmovetype);
873 draggee.gravity = draggee.draggravity;
875 switch(draggee.move_movetype)
880 case MOVETYPE_FLYMISSILE:
881 case MOVETYPE_BOUNCE:
882 case MOVETYPE_BOUNCEMISSILE:
883 case MOVETYPE_PHYSICS:
886 draggee.velocity = '0 0 0';
890 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
892 draggee.velocity = '0 0 0';
893 SET_ONGROUND(draggee); // floating items are FUN
897 bool drag_undraggable(entity draggee, entity dragger)
899 // stuff probably shouldn't need this, we should figure out why they do!
900 // exceptions of course are observers and weapon entities, where things mess up
904 float Drag_IsDraggable(entity draggee, entity dragger)
906 // TODO add more checks for bad stuff here
909 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)
910 return false; // probably due to BSP collision
911 //if(draggee.model == "")
914 return ((draggee.draggable) ? draggee.draggable(draggee, dragger) : true);
917 float Drag_MayChangeAngles(entity draggee)
919 // TODO add more checks for bad stuff here
920 if(substring(draggee.model, 0, 1) == "*")
925 void Drag_MoveForward(entity dragger)
927 dragger.dragdistance += dragger.dragspeed;
930 void Drag_SetSpeed(entity dragger, float s)
932 dragger.dragspeed = (2 ** s);
935 void Drag_MoveBackward(entity dragger)
937 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
940 void Drag_Update(entity dragger)
942 vector curorigin, neworigin, goodvelocity;
946 draggee = dragger.dragentity;
947 UNSET_ONGROUND(draggee);
949 curorigin = gettaginfo(draggee, 0);
950 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
951 makevectors(dragger.v_angle);
952 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
953 goodvelocity = (neworigin - curorigin) * (1 / frametime);
955 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
956 dragger.draglocalangle += 360;
957 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
958 dragger.draglocalangle -= 360;
960 f = min(frametime * 10, 1);
961 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
963 if(Drag_MayChangeAngles(draggee))
964 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
966 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
968 vector vecs = '0 0 0';
969 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
970 if(dragger.(weaponentity).movedir.x > 0)
971 vecs = dragger.(weaponentity).movedir;
973 vector dv = v_right * -vecs_y + v_up * vecs_z;
975 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
978 float Drag_CanDrag(entity dragger)
980 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
983 float Drag_IsDragging(entity dragger)
985 if(!dragger.dragentity)
987 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
989 dragger.dragentity = NULL;
992 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity, dragger))
994 Drag_Finish(dragger);
1000 void Drag_MoveDrag(entity from, entity to)
1004 to.draggedby = from.draggedby;
1005 to.draggedby.dragentity = to;
1006 from.draggedby = NULL;
1010 void DragBox_Think(entity this)
1012 if(this.aiment && this.enemy)
1014 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1015 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1016 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1017 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1018 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1019 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1020 this.mins = -1 * this.maxs;
1021 setorigin(this, this.origin);
1022 setsize(this, this.mins, this.maxs); // link edict
1025 if(this.cnt == -1) // actually race_place -1
1027 // show "10 10" for qualifying spawns
1028 setmodel(this.killindicator, MDL_NUM(10));
1029 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1031 else if(this.cnt == -2) // actually race_place 0
1033 // show "10 0" for loser spawns
1034 setmodel(this.killindicator, MDL_NUM(10));
1035 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1039 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1040 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1043 this.nextthink = time;