3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include <common/effects/all.qh>
6 #include <server/resources.qh>
11 #include "../common/mapobjects/teleporters.qh"
13 #include <server/mutators/_mod.qh>
15 #include "weapons/tracing.qh"
17 #include "../common/constants.qh"
18 #include "../common/deathtypes/all.qh"
19 #include "../common/util.qh"
21 #include <common/physics/player.qh>
23 #include "../common/monsters/_mod.qh"
25 #include <common/weapons/_all.qh>
27 #include "../common/mapobjects/subs.qh"
28 #include <common/mapobjects/triggers.qh>
30 #include "../common/mapobjects/func/breakable.qh"
32 #include "../lib/csqcmodel/sv_model.qh"
34 #include "../lib/warpzone/anglestransform.qh"
35 #include "../lib/warpzone/util_server.qh"
39 float CheatImpulse(entity this, int imp) { return 0; }
40 float CheatCommand(entity this, int argc) { return 0; }
41 float CheatFrame(entity this) { return 0; }
42 void CheatInit() { cheatcount_total = world.cheatcount; }
43 void CheatShutdown() { }
44 void Drag_MoveDrag(entity from, entity to) { }
49 float gamestart_sv_cheats;
55 gamestart_sv_cheats = autocvar_sv_cheats;
62 float CheatsAllowed(entity this, float i, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking
64 // dead people cannot cheat
67 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)
80 if(gamestart_sv_cheats && autocvar_sv_cheats)
83 // if we get here, player is not allowed to cheat. Log it.
85 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this, false), i);
87 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this, false), argv(0));
89 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this, false), fr);
91 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this, false));
96 #define BEGIN_CHEAT_FUNCTION() \
97 float cheating, attempting; \
98 cheating = 0; attempting = 0
101 #define ADD_CHEATS(e,n) \
102 cheatcount_total += n; \
104 #define END_CHEAT_FUNCTION() \
105 ADD_CHEATS(this, cheating); \
107 #define IS_CHEAT(ent,i,argc,fr) \
108 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
111 float num_autoscreenshot;
112 void info_autoscreenshot_findtarget(entity this)
115 e = find(NULL, targetname, this.target);
118 objerror(this, "Missing target. FAIL!");
121 vector a = vectoangles(e.origin - this.origin);
122 a.x = -a.x; // don't ask
125 // we leave Rick Roll alone
127 spawnfunc(info_autoscreenshot)
129 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
131 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
134 if(this.target != "")
135 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
136 // this one just has to exist
139 float CheatImpulse(entity this, int imp)
141 BEGIN_CHEAT_FUNCTION();
146 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
147 // shared with regular waypoint init, so this is not a cheat by itself
150 this.personal = new(personal_wp);
152 this.personal.origin = this.origin;
153 this.personal.v_angle = this.v_angle;
154 this.personal.velocity = this.velocity;
155 SetResourceAmount(this.personal, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS));
156 SetResourceAmount(this.personal, RESOURCE_BULLETS, GetResourceAmount(this, RESOURCE_BULLETS));
157 SetResourceAmount(this.personal, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS));
158 SetResourceAmount(this.personal, RESOURCE_PLASMA, GetResourceAmount(this, RESOURCE_PLASMA));
159 SetResourceAmount(this.personal, RESOURCE_SHELLS, GetResourceAmount(this, RESOURCE_SHELLS));
160 SetResourceAmount(this.personal, RESOURCE_FUEL, GetResourceAmount(this, RESOURCE_FUEL));
161 SetResourceAmount(this.personal, RESOURCE_HEALTH, max(1, GetResourceAmount(this, RESOURCE_HEALTH)));
162 SetResourceAmount(this.personal, RESOURCE_ARMOR, GetResourceAmount(this, RESOURCE_ARMOR));
163 STAT(WEAPONS, this.personal) = STAT(WEAPONS, 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 this.personal.strength_finished = this.strength_finished;
170 this.personal.invincible_finished = this.invincible_finished;
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 SetResourceAmount(this, RESOURCE_ROCKETS, GetResourceAmount(this.personal, RESOURCE_ROCKETS));
215 SetResourceAmount(this, RESOURCE_BULLETS, GetResourceAmount(this.personal, RESOURCE_BULLETS));
216 SetResourceAmount(this, RESOURCE_CELLS, GetResourceAmount(this.personal, RESOURCE_CELLS));
217 SetResourceAmount(this, RESOURCE_PLASMA, GetResourceAmount(this.personal, RESOURCE_PLASMA));
218 SetResourceAmount(this, RESOURCE_SHELLS, GetResourceAmount(this.personal, RESOURCE_SHELLS));
219 SetResourceAmount(this, RESOURCE_FUEL, GetResourceAmount(this.personal, RESOURCE_FUEL));
220 SetResourceAmount(this, RESOURCE_HEALTH, GetResourceAmount(this.personal, RESOURCE_HEALTH));
221 SetResourceAmount(this, RESOURCE_ARMOR, GetResourceAmount(this.personal, RESOURCE_ARMOR));
222 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
223 this.items = this.personal.items;
224 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
225 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
226 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
227 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
228 this.strength_finished = time + this.personal.strength_finished - this.personal.teleport_time;
229 this.invincible_finished = time + this.personal.invincible_finished - this.personal.teleport_time;
231 if(!autocvar_g_allow_checkpoints)
236 sprint(this, "UR DEAD AHAHAH))\n");
238 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
240 case CHIMPULSE_TELEPORT.impulse:
241 IS_CHEAT(this, imp, 0, 0);
242 if(this.move_movetype == MOVETYPE_NOCLIP)
244 e = find(NULL, classname, "info_autoscreenshot");
247 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
248 setorigin(this, e.origin);
249 this.angles = e.angles;
251 // should we? this.angles_x = -this.angles_x;
252 this.fixangle = true;
253 this.velocity = '0 0 0';
258 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))
260 sprint(this, "Emergency teleport used random location\n");
261 this.angles_x = -this.angles.x;
262 this.fixangle = true;
263 this.velocity = '0 0 0';
267 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
269 case CHIMPULSE_R00T.impulse:
270 IS_CHEAT(this, imp, 0, 0);
271 RandomSelection_Init();
272 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
273 if(RandomSelection_chosen_ent)
274 e = RandomSelection_chosen_ent;
278 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
279 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
282 setorigin(e2, e.origin);
283 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
286 LOG_INFO("404 Sportsmanship not found.");
291 END_CHEAT_FUNCTION();
295 float CheatCommand(entity this, int argc)
297 BEGIN_CHEAT_FUNCTION();
305 case "pointparticles":
306 IS_CHEAT(this, 0, argc, 0);
311 // origin (0..1, on crosshair line)
315 crosshair_trace(this);
316 start = (1-f) * this.origin + f * trace_endpos;
319 Send_Effect_(argv(1), start, end, f);
323 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
325 case "trailparticles":
326 IS_CHEAT(this, 0, argc, 0);
331 effectnum = _particleeffectnum(argv(1));
332 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
333 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
334 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
338 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
341 IS_CHEAT(this, 0, argc, 0);
347 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
348 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
349 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
351 sprint(this, "cannot make stuff there (bad surface)\n");
356 e.model = strzone(argv(1));
357 e.mdl = "rocket_explode";
358 SetResourceAmountExplicit(e, RESOURCE_HEALTH, 1000);
359 setorigin(e, trace_endpos);
360 e.effects = EF_NOMODELFLAGS;
363 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
364 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
366 spawnfunc_func_breakable(e);
370 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
374 sprint(this, "cannot make stuff there (no space)\n");
384 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
387 IS_CHEAT(this, 0, argc, 0);
390 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
394 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
396 case "dragbox_spawn": {
397 IS_CHEAT(this, 0, argc, 0);
398 entity e = new(dragbox_box);
399 setthink(e, DragBox_Think);
401 e.solid = -1; // black
402 setmodel(e, MDL_Null); // network it
404 e.cnt = stof(argv(1));
406 e.cnt = max(0, drag_lastcnt);
408 e.aiment = new(dragbox_corner_1);
410 setmodel(e.aiment, MDL_MARKER);
412 setsize(e.aiment, '0 0 0', '0 0 0');
414 setorigin(e.aiment, stov(argv(2)));
417 crosshair_trace(this);
418 setorigin(e.aiment, trace_endpos);
421 e.enemy = new(dragbox_corner_2);
423 setmodel(e.enemy, MDL_MARKER);
425 setsize(e.enemy, '0 0 0', '0 0 0');
426 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
427 end.x = (end.x > 0) * 2 - 1;
428 end.y = (end.y > 0) * 2 - 1;
429 end.z = (end.z > 0) * 2 - 1;
431 setorigin(e.enemy, stov(argv(3)));
433 setorigin(e.enemy, e.aiment.origin + 32 * end);
435 e.killindicator = new(drag_digit);
436 e.killindicator.owner = e;
437 setattachment(e.killindicator, e, "");
438 setorigin(e.killindicator, '0 0 -8');
439 e.killindicator.killindicator = new(drag_digit);
440 e.killindicator.killindicator.owner = e;
441 setattachment(e.killindicator.killindicator, e, "");
442 setorigin(e.killindicator.killindicator, '0 0 8');
446 case "dragpoint_spawn": {
447 IS_CHEAT(this, 0, argc, 0);
448 entity e = new(dragpoint);
449 setthink(e, DragBox_Think);
451 e.solid = 0; // nothing special
452 setmodel(e, MDL_MARKER);
453 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
456 e.cnt = stof(argv(1));
458 e.cnt = drag_lastcnt;
460 setorigin(e, stov(argv(2)));
463 crosshair_trace(this);
464 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
465 move_out_of_solid(e);
468 e.killindicator = new(drag_digit);
469 e.killindicator.owner = e;
470 setattachment(e.killindicator, e, "");
471 setorigin(e.killindicator, '0 0 40');
472 e.killindicator.killindicator = new(drag_digit);
473 e.killindicator.killindicator.owner = e;
474 setattachment(e.killindicator.killindicator, e, "");
475 setorigin(e.killindicator.killindicator, '0 0 56');
480 IS_CHEAT(this, 0, argc, 0);
481 RandomSelection_Init();
482 crosshair_trace(this);
483 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
484 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
485 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
486 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
487 if(RandomSelection_chosen_ent)
489 delete(RandomSelection_chosen_ent.killindicator.killindicator);
490 delete(RandomSelection_chosen_ent.killindicator);
491 if(RandomSelection_chosen_ent.aiment)
492 delete(RandomSelection_chosen_ent.aiment);
493 if(RandomSelection_chosen_ent.enemy)
494 delete(RandomSelection_chosen_ent.enemy);
495 delete(RandomSelection_chosen_ent);
500 IS_CHEAT(this, 0, argc, 0);
503 RandomSelection_Init();
504 crosshair_trace(this);
505 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
506 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
507 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
508 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
509 if(RandomSelection_chosen_ent)
511 if(substring(argv(1), 0, 1) == "*")
512 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
514 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
519 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
522 IS_CHEAT(this, 0, argc, 0);
525 f = fopen(argv(1), FILE_WRITE);
526 fputs(f, "cmd drag_clear\n");
527 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
529 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
531 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
533 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
539 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
541 case "drag_saveraceent":
542 IS_CHEAT(this, 0, argc, 0);
545 f = fopen(argv(1), FILE_WRITE);
546 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
549 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
550 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
551 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"));
552 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
553 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
556 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
560 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
562 if(e.cnt <= 0 && ent.cnt == 0 || e.cnt == ent.cnt)
564 start = start + ent.origin;
568 start *= 1 / effectnum;
570 fputs(f, "\"classname\" \"info_player_race\"\n");
571 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
572 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
575 fputs(f, "\"target\" \"checkpoint0\"\n");
576 fputs(f, "\"race_place\" \"0\"\n");
580 fputs(f, "\"target\" \"checkpoint0\"\n");
581 fputs(f, "\"race_place\" \"-1\"\n");
585 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
588 // these need race_place
591 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
594 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
596 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
599 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
608 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
611 IS_CHEAT(this, 0, argc, 0);
612 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
614 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
616 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
618 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
620 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
625 IS_CHEAT(this, 0, argc, 0);
626 BITXOR_ASSIGN(this.flags, FL_GODMODE);
627 if(this.flags & FL_GODMODE)
629 sprint(this, "godmode ON\n");
633 sprint(this, "godmode OFF\n");
636 IS_CHEAT(this, 0, argc, 0);
637 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
638 if(this.flags & FL_NOTARGET)
640 sprint(this, "notarget ON\n");
644 sprint(this, "notarget OFF\n");
647 IS_CHEAT(this, 0, argc, 0);
648 if(this.move_movetype != MOVETYPE_NOCLIP)
650 set_movetype(this, MOVETYPE_NOCLIP);
651 sprint(this, "noclip ON\n");
656 set_movetype(this, MOVETYPE_WALK);
657 sprint(this, "noclip OFF\n");
661 IS_CHEAT(this, 0, argc, 0);
662 if(this.move_movetype != MOVETYPE_FLY)
664 set_movetype(this, MOVETYPE_FLY);
665 sprint(this, "flymode ON\n");
670 set_movetype(this, MOVETYPE_WALK);
671 sprint(this, "flymode OFF\n");
675 IS_CHEAT(this, 0, argc, 0);
676 if(GiveItems(this, 1, argc))
680 IS_CHEAT(this, 0, argc, 0);
683 SUB_UseTargets(e, this, NULL);
688 IS_CHEAT(this, 0, argc, 0);
690 e2.killtarget = argv(1);
691 SUB_UseTargets(e2, this, NULL);
695 case "teleporttotarget":
696 IS_CHEAT(this, 0, argc, 0);
697 entity ent = new(cheattriggerteleport);
698 setorigin(ent, ent.origin);
699 ent.target = argv(1);
700 teleport_findtarget(ent);
703 Simple_TeleportPlayer(ent, this);
710 END_CHEAT_FUNCTION();
715 float CheatFrame(entity this)
717 BEGIN_CHEAT_FUNCTION();
719 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
720 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
721 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
722 // grabbing itself no longer being accounted as cheating.
727 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
729 // use cheat dragging if cheats are enabled
730 //if(Drag_IsDragging(this))
731 //crosshair_trace_plusvisibletriggers(this);
732 Drag(this, true, true);
736 Drag(this, false, false); // execute dragging
741 END_CHEAT_FUNCTION();
752 .float dragspeed; // speed of mouse wheel action
753 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
754 .vector draglocalvector; // local attachment vector of the dragentity
755 .float draglocalangle;
760 float Drag(entity this, float force_allow_pick, float ischeat)
762 BEGIN_CHEAT_FUNCTION();
764 // returns true when an entity has been picked up
765 // If pick is true, the object can also be picked up if it's not being held already
766 // If pick is false, only keep dragging the object if it's already being held
771 if(Drag_IsDragging(this))
773 if(PHYS_INPUT_BUTTON_DRAG(this))
775 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
777 Drag_MoveForward(this);
778 CS(this).impulse = 0;
780 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
782 Drag_MoveBackward(this);
783 CS(this).impulse = 0;
785 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
787 Drag_SetSpeed(this, CS(this).impulse - 1);
789 else if(CS(this).impulse == 14)
791 Drag_SetSpeed(this, 9);
804 if(Drag_CanDrag(this))
805 if(PHYS_INPUT_BUTTON_DRAG(this))
807 crosshair_trace_plusvisibletriggers(this);
808 entity e = trace_ent;
809 float pick = force_allow_pick;
812 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
813 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
814 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
815 // it goes out of range while slinging it around.
817 if(vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
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
841 if(Drag_IsDraggable(e))
844 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
846 Drag_Finish(e.draggedby);
848 detach_sameorigin(e);
849 Drag_Begin(this, e, trace_endpos);
861 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
865 draggee.dragmovetype = draggee.move_movetype;
866 draggee.draggravity = draggee.gravity;
867 set_movetype(draggee, MOVETYPE_WALK);
868 draggee.gravity = 0.00001;
869 UNSET_ONGROUND(draggee);
870 draggee.draggedby = dragger;
872 dragger.dragentity = draggee;
874 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
875 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
876 touchpoint = touchpoint - gettaginfo(draggee, 0);
877 tagscale = (vlen(v_forward) ** -2);
878 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
879 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
880 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
882 dragger.dragspeed = 64;
885 void Drag_Finish(entity dragger)
888 draggee = dragger.dragentity;
890 dragger.dragentity = NULL;
891 draggee.draggedby = NULL;
892 set_movetype(draggee, draggee.dragmovetype);
893 draggee.gravity = draggee.draggravity;
895 switch(draggee.move_movetype)
900 case MOVETYPE_FLYMISSILE:
901 case MOVETYPE_BOUNCE:
902 case MOVETYPE_BOUNCEMISSILE:
903 case MOVETYPE_PHYSICS:
906 draggee.velocity = '0 0 0';
910 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
912 draggee.velocity = '0 0 0';
913 SET_ONGROUND(draggee); // floating items are FUN
917 float Drag_IsDraggable(entity draggee)
919 // TODO add more checks for bad stuff here
922 if(draggee.classname == "func_bobbing")
924 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)
926 if(draggee.classname == "plat")
928 if(draggee.classname == "func_button")
930 // if(draggee.model == "")
934 if(IS_OBSERVER(draggee))
936 if(draggee.classname == "exteriorweaponentity")
938 if(draggee.classname == "weaponentity")
944 float Drag_MayChangeAngles(entity draggee)
946 // TODO add more checks for bad stuff here
947 if(substring(draggee.model, 0, 1) == "*")
952 void Drag_MoveForward(entity dragger)
954 dragger.dragdistance += dragger.dragspeed;
957 void Drag_SetSpeed(entity dragger, float s)
959 dragger.dragspeed = (2 ** s);
962 void Drag_MoveBackward(entity dragger)
964 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
967 void Drag_Update(entity dragger)
969 vector curorigin, neworigin, goodvelocity;
973 draggee = dragger.dragentity;
974 UNSET_ONGROUND(draggee);
976 curorigin = gettaginfo(draggee, 0);
977 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
978 makevectors(dragger.v_angle);
979 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
980 goodvelocity = (neworigin - curorigin) * (1 / frametime);
982 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
983 dragger.draglocalangle += 360;
984 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
985 dragger.draglocalangle -= 360;
987 f = min(frametime * 10, 1);
988 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
990 if(Drag_MayChangeAngles(draggee))
991 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
993 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
995 vector vecs = '0 0 0';
996 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
997 if(dragger.(weaponentity).movedir.x > 0)
998 vecs = dragger.(weaponentity).movedir;
1000 vector dv = v_right * -vecs_y + v_up * vecs_z;
1002 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
1005 float Drag_CanDrag(entity dragger)
1007 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
1010 float Drag_IsDragging(entity dragger)
1012 if(!dragger.dragentity)
1014 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1016 dragger.dragentity = NULL;
1019 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
1021 Drag_Finish(dragger);
1027 void Drag_MoveDrag(entity from, entity to)
1031 to.draggedby = from.draggedby;
1032 to.draggedby.dragentity = to;
1033 from.draggedby = NULL;
1037 void DragBox_Think(entity this)
1039 if(this.aiment && this.enemy)
1041 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1042 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1043 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1044 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1045 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1046 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1047 this.mins = -1 * this.maxs;
1048 setorigin(this, this.origin);
1049 setsize(this, this.mins, this.maxs); // link edict
1052 if(this.cnt == -1) // actually race_place -1
1054 // show "10 10" for qualifying spawns
1055 setmodel(this.killindicator, MDL_NUM(10));
1056 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1058 else if(this.cnt == -2) // actually race_place 0
1060 // show "10 0" for loser spawns
1061 setmodel(this.killindicator, MDL_NUM(10));
1062 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1066 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1067 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1070 this.nextthink = time;