3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include <common/effects/all.qh>
6 #include <server/resources.qh>
10 #include "../common/mapobjects/teleporters.qh"
12 #include <server/mutators/_mod.qh>
14 #include "weapons/tracing.qh"
16 #include "../common/constants.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/util.qh"
20 #include <common/physics/player.qh>
22 #include "../common/monsters/_mod.qh"
24 #include <common/weapons/_all.qh>
26 #include "../common/mapobjects/subs.qh"
27 #include <common/mapobjects/triggers.qh>
29 #include "../common/mapobjects/func/breakable.qh"
31 #include "../lib/csqcmodel/sv_model.qh"
33 #include "../lib/warpzone/anglestransform.qh"
34 #include "../lib/warpzone/util_server.qh"
36 void CopyBody(entity this, float keepvelocity);
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, float argc, float fr) // the cheat gets passed as argument for possible future ACL checking
65 // dead people cannot cheat
68 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
72 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
73 if(this.lip < sv_clones)
81 if(gamestart_sv_cheats && autocvar_sv_cheats)
84 // if we get here, player is not allowed to cheat. Log it.
86 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this, false), i);
88 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this, false), argv(0));
90 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this, false), fr);
92 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this, false));
97 #define BEGIN_CHEAT_FUNCTION() \
98 float cheating, attempting; \
99 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 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
132 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
135 if(this.target != "")
136 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
137 // this one just has to exist
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 SetResourceAmount(this.personal, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS));
157 SetResourceAmount(this.personal, RESOURCE_BULLETS, GetResourceAmount(this, RESOURCE_BULLETS));
158 SetResourceAmount(this.personal, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS));
159 SetResourceAmount(this.personal, RESOURCE_PLASMA, GetResourceAmount(this, RESOURCE_PLASMA));
160 SetResourceAmount(this.personal, RESOURCE_SHELLS, GetResourceAmount(this, RESOURCE_SHELLS));
161 SetResourceAmount(this.personal, RESOURCE_FUEL, GetResourceAmount(this, RESOURCE_FUEL));
162 this.personal.health = max(1, this.health);
163 this.personal.armorvalue = this.armorvalue;
164 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
165 this.personal.items = this.items;
166 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
167 this.personal.pauserothealth_finished = this.pauserothealth_finished;
168 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
169 this.personal.pauseregen_finished = this.pauseregen_finished;
170 this.personal.strength_finished = this.strength_finished;
171 this.personal.invincible_finished = this.invincible_finished;
172 this.personal.teleport_time = time;
173 break; // this part itself doesn't cheat, so let's not count this
174 case CHIMPULSE_CLONE_MOVING.impulse:
175 IS_CHEAT(this, imp, 0, 0);
176 makevectors (this.v_angle);
177 this.velocity = this.velocity + v_forward * 300;
180 this.velocity = this.velocity - v_forward * 300;
183 case CHIMPULSE_CLONE_STANDING.impulse:
184 IS_CHEAT(this, imp, 0, 0);
189 case CHIMPULSE_GIVE_ALL.impulse:
190 IS_CHEAT(this, imp, 0, 0);
191 CheatCommand(this, tokenize_console("give all"));
192 break; // already counted as cheat
193 case CHIMPULSE_SPEEDRUN.impulse:
194 if(!autocvar_g_allow_checkpoints)
195 IS_CHEAT(this, imp, 0, 0);
198 this.speedrunning = true;
199 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
202 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
206 // Abort speedrun, teleport back
207 setorigin(this, this.personal.origin);
208 this.oldvelocity = this.velocity = this.personal.velocity;
209 this.angles = this.personal.v_angle;
210 this.fixangle = true;
212 MUTATOR_CALLHOOK(AbortSpeedrun, this);
215 SetResourceAmount(this, RESOURCE_ROCKETS, GetResourceAmount(this.personal, RESOURCE_ROCKETS));
216 SetResourceAmount(this, RESOURCE_BULLETS, GetResourceAmount(this.personal, RESOURCE_BULLETS));
217 SetResourceAmount(this, RESOURCE_CELLS, GetResourceAmount(this.personal, RESOURCE_CELLS));
218 SetResourceAmount(this, RESOURCE_PLASMA, GetResourceAmount(this.personal, RESOURCE_PLASMA));
219 SetResourceAmount(this, RESOURCE_SHELLS, GetResourceAmount(this.personal, RESOURCE_SHELLS));
220 SetResourceAmount(this, RESOURCE_FUEL, GetResourceAmount(this.personal, RESOURCE_FUEL));
221 this.health = this.personal.health;
222 this.armorvalue = this.personal.armorvalue;
223 STAT(WEAPONS, this) = STAT(WEAPONS, 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 this.strength_finished = time + this.personal.strength_finished - this.personal.teleport_time;
230 this.invincible_finished = time + this.personal.invincible_finished - 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();
295 void DragBox_Think(entity this);
297 float CheatCommand(entity this, int argc)
299 BEGIN_CHEAT_FUNCTION();
307 case "pointparticles":
308 IS_CHEAT(this, 0, argc, 0);
313 // origin (0..1, on crosshair line)
317 crosshair_trace(this);
318 start = (1-f) * this.origin + f * trace_endpos;
321 Send_Effect_(argv(1), start, end, f);
325 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
327 case "trailparticles":
328 IS_CHEAT(this, 0, argc, 0);
333 effectnum = _particleeffectnum(argv(1));
334 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
335 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
336 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
340 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
343 IS_CHEAT(this, 0, argc, 0);
349 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
350 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
351 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
353 sprint(this, "cannot make stuff there (bad surface)\n");
358 e.model = strzone(argv(1));
359 e.mdl = "rocket_explode";
361 setorigin(e, trace_endpos);
362 e.effects = EF_NOMODELFLAGS;
365 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
366 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
368 spawnfunc_func_breakable(e);
372 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
376 sprint(this, "cannot make stuff there (no space)\n");
386 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
389 IS_CHEAT(this, 0, argc, 0);
392 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
396 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
398 case "dragbox_spawn": {
399 IS_CHEAT(this, 0, argc, 0);
400 entity e = new(dragbox_box);
401 setthink(e, DragBox_Think);
403 e.solid = -1; // black
404 setmodel(e, MDL_Null); // network it
406 e.cnt = stof(argv(1));
408 e.cnt = max(0, drag_lastcnt);
410 e.aiment = new(dragbox_corner_1);
412 setmodel(e.aiment, MDL_MARKER);
414 setsize(e.aiment, '0 0 0', '0 0 0');
416 setorigin(e.aiment, stov(argv(2)));
419 crosshair_trace(this);
420 setorigin(e.aiment, trace_endpos);
423 e.enemy = new(dragbox_corner_2);
425 setmodel(e.enemy, MDL_MARKER);
427 setsize(e.enemy, '0 0 0', '0 0 0');
428 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
429 end.x = (end.x > 0) * 2 - 1;
430 end.y = (end.y > 0) * 2 - 1;
431 end.z = (end.z > 0) * 2 - 1;
433 setorigin(e.enemy, stov(argv(3)));
435 setorigin(e.enemy, e.aiment.origin + 32 * end);
437 e.killindicator = new(drag_digit);
438 e.killindicator.owner = e;
439 setattachment(e.killindicator, e, "");
440 setorigin(e.killindicator, '0 0 -8');
441 e.killindicator.killindicator = new(drag_digit);
442 e.killindicator.killindicator.owner = e;
443 setattachment(e.killindicator.killindicator, e, "");
444 setorigin(e.killindicator.killindicator, '0 0 8');
448 case "dragpoint_spawn": {
449 IS_CHEAT(this, 0, argc, 0);
450 entity e = new(dragpoint);
451 setthink(e, DragBox_Think);
453 e.solid = 0; // nothing special
454 setmodel(e, MDL_MARKER);
455 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
458 e.cnt = stof(argv(1));
460 e.cnt = drag_lastcnt;
462 setorigin(e, stov(argv(2)));
465 crosshair_trace(this);
466 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
467 move_out_of_solid(e);
470 e.killindicator = new(drag_digit);
471 e.killindicator.owner = e;
472 setattachment(e.killindicator, e, "");
473 setorigin(e.killindicator, '0 0 40');
474 e.killindicator.killindicator = new(drag_digit);
475 e.killindicator.killindicator.owner = e;
476 setattachment(e.killindicator.killindicator, e, "");
477 setorigin(e.killindicator.killindicator, '0 0 56');
482 IS_CHEAT(this, 0, argc, 0);
483 RandomSelection_Init();
484 crosshair_trace(this);
485 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
486 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
487 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
488 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
489 if(RandomSelection_chosen_ent)
491 delete(RandomSelection_chosen_ent.killindicator.killindicator);
492 delete(RandomSelection_chosen_ent.killindicator);
493 if(RandomSelection_chosen_ent.aiment)
494 delete(RandomSelection_chosen_ent.aiment);
495 if(RandomSelection_chosen_ent.enemy)
496 delete(RandomSelection_chosen_ent.enemy);
497 delete(RandomSelection_chosen_ent);
502 IS_CHEAT(this, 0, argc, 0);
505 RandomSelection_Init();
506 crosshair_trace(this);
507 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
508 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
509 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
510 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
511 if(RandomSelection_chosen_ent)
513 if(substring(argv(1), 0, 1) == "*")
514 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
516 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
521 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
524 IS_CHEAT(this, 0, argc, 0);
527 f = fopen(argv(1), FILE_WRITE);
528 fputs(f, "cmd drag_clear\n");
529 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
531 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
533 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
535 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
541 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
543 case "drag_saveraceent":
544 IS_CHEAT(this, 0, argc, 0);
547 f = fopen(argv(1), FILE_WRITE);
548 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
551 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
552 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
553 fputs(f, strcat("\"maxs\" \"", ftos(e.absmax.x - e.absmin.x), " ", ftos(e.absmax.y - e.absmin.y), " ", ftos(e.absmax.z - e.absmin.z), "\"\n"));
554 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
555 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
558 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
562 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
564 if(e.cnt <= 0 && ent.cnt == 0 || e.cnt == ent.cnt)
566 start = start + ent.origin;
570 start *= 1 / effectnum;
572 fputs(f, "\"classname\" \"info_player_race\"\n");
573 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
574 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
577 fputs(f, "\"target\" \"checkpoint0\"\n");
578 fputs(f, "\"race_place\" \"0\"\n");
582 fputs(f, "\"target\" \"checkpoint0\"\n");
583 fputs(f, "\"race_place\" \"-1\"\n");
587 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
590 // these need race_place
593 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
596 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
598 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
601 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
610 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
613 IS_CHEAT(this, 0, argc, 0);
614 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
616 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
618 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
620 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
622 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
627 IS_CHEAT(this, 0, argc, 0);
628 BITXOR_ASSIGN(this.flags, FL_GODMODE);
629 if(this.flags & FL_GODMODE)
631 sprint(this, "godmode ON\n");
635 sprint(this, "godmode OFF\n");
638 IS_CHEAT(this, 0, argc, 0);
639 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
640 if(this.flags & FL_NOTARGET)
642 sprint(this, "notarget ON\n");
646 sprint(this, "notarget OFF\n");
649 IS_CHEAT(this, 0, argc, 0);
650 if(this.move_movetype != MOVETYPE_NOCLIP)
652 set_movetype(this, MOVETYPE_NOCLIP);
653 sprint(this, "noclip ON\n");
658 set_movetype(this, MOVETYPE_WALK);
659 sprint(this, "noclip OFF\n");
663 IS_CHEAT(this, 0, argc, 0);
664 if(this.move_movetype != MOVETYPE_FLY)
666 set_movetype(this, MOVETYPE_FLY);
667 sprint(this, "flymode ON\n");
672 set_movetype(this, MOVETYPE_WALK);
673 sprint(this, "flymode OFF\n");
677 IS_CHEAT(this, 0, argc, 0);
678 if(GiveItems(this, 1, argc))
682 IS_CHEAT(this, 0, argc, 0);
685 SUB_UseTargets(e, this, NULL);
690 IS_CHEAT(this, 0, argc, 0);
692 e2.killtarget = argv(1);
693 SUB_UseTargets(e2, this, NULL);
697 case "teleporttotarget":
698 IS_CHEAT(this, 0, argc, 0);
699 entity ent = new(cheattriggerteleport);
700 setorigin(ent, ent.origin);
701 ent.target = argv(1);
702 teleport_findtarget(ent);
705 Simple_TeleportPlayer(ent, this);
712 END_CHEAT_FUNCTION();
715 float Drag(entity this, float force_allow_pick, float ischeat);
716 void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
717 void Drag_Finish(entity dragger);
718 float Drag_IsDraggable(entity draggee);
719 float Drag_MayChangeAngles(entity draggee);
720 void Drag_MoveForward(entity dragger);
721 void Drag_SetSpeed(entity dragger, float s);
722 void Drag_MoveBackward(entity dragger);
723 void Drag_Update(entity dragger);
724 float Drag_CanDrag(entity dragger);
725 float Drag_IsDragging(entity dragger);
726 void Drag_MoveDrag(entity from, entity to);
729 float CheatFrame(entity this)
731 BEGIN_CHEAT_FUNCTION();
733 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
734 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
735 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
736 // grabbing itself no longer being accounted as cheating.
741 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
743 // use cheat dragging if cheats are enabled
744 //if(Drag_IsDragging(this))
745 //crosshair_trace_plusvisibletriggers(this);
746 Drag(this, true, true);
750 Drag(this, false, false); // execute dragging
755 END_CHEAT_FUNCTION();
766 .float dragspeed; // speed of mouse wheel action
767 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
768 .vector draglocalvector; // local attachment vector of the dragentity
769 .float draglocalangle;
774 float Drag(entity this, float force_allow_pick, float ischeat)
776 BEGIN_CHEAT_FUNCTION();
778 // returns true when an entity has been picked up
779 // If pick is true, the object can also be picked up if it's not being held already
780 // If pick is false, only keep dragging the object if it's already being held
785 if(Drag_IsDragging(this))
787 if(PHYS_INPUT_BUTTON_DRAG(this))
789 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
791 Drag_MoveForward(this);
792 CS(this).impulse = 0;
794 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
796 Drag_MoveBackward(this);
797 CS(this).impulse = 0;
799 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
801 Drag_SetSpeed(this, CS(this).impulse - 1);
803 else if(CS(this).impulse == 14)
805 Drag_SetSpeed(this, 9);
818 if(Drag_CanDrag(this))
819 if(PHYS_INPUT_BUTTON_DRAG(this))
821 crosshair_trace_plusvisibletriggers(this);
822 entity e = trace_ent;
823 float pick = force_allow_pick;
826 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
827 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
828 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
829 // it goes out of range while slinging it around.
831 if(vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
835 case 0: // can't grab
837 case 1: // owner can grab
838 if(e.owner == this || e.realowner == this)
841 case 2: // owner and team mates can grab
842 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
845 case 3: // anyone can grab
855 if(Drag_IsDraggable(e))
858 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
860 Drag_Finish(e.draggedby);
862 detach_sameorigin(e);
863 Drag_Begin(this, e, trace_endpos);
875 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
879 draggee.dragmovetype = draggee.move_movetype;
880 draggee.draggravity = draggee.gravity;
881 set_movetype(draggee, MOVETYPE_WALK);
882 draggee.gravity = 0.00001;
883 UNSET_ONGROUND(draggee);
884 draggee.draggedby = dragger;
886 dragger.dragentity = draggee;
888 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
889 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
890 touchpoint = touchpoint - gettaginfo(draggee, 0);
891 tagscale = (vlen(v_forward) ** -2);
892 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
893 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
894 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
896 dragger.dragspeed = 64;
899 void Drag_Finish(entity dragger)
902 draggee = dragger.dragentity;
904 dragger.dragentity = NULL;
905 draggee.draggedby = NULL;
906 set_movetype(draggee, draggee.dragmovetype);
907 draggee.gravity = draggee.draggravity;
909 switch(draggee.move_movetype)
914 case MOVETYPE_FLYMISSILE:
915 case MOVETYPE_BOUNCE:
916 case MOVETYPE_BOUNCEMISSILE:
917 case MOVETYPE_PHYSICS:
920 draggee.velocity = '0 0 0';
924 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
926 draggee.velocity = '0 0 0';
927 SET_ONGROUND(draggee); // floating items are FUN
931 float Drag_IsDraggable(entity draggee)
933 // TODO add more checks for bad stuff here
936 if(draggee.classname == "func_bobbing")
938 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)
940 if(draggee.classname == "plat")
942 if(draggee.classname == "func_button")
944 // if(draggee.model == "")
948 if(IS_OBSERVER(draggee))
950 if(draggee.classname == "exteriorweaponentity")
952 if(draggee.classname == "weaponentity")
958 float Drag_MayChangeAngles(entity draggee)
960 // TODO add more checks for bad stuff here
961 if(substring(draggee.model, 0, 1) == "*")
966 void Drag_MoveForward(entity dragger)
968 dragger.dragdistance += dragger.dragspeed;
971 void Drag_SetSpeed(entity dragger, float s)
973 dragger.dragspeed = (2 ** s);
976 void Drag_MoveBackward(entity dragger)
978 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
981 void Drag_Update(entity dragger)
983 vector curorigin, neworigin, goodvelocity;
987 draggee = dragger.dragentity;
988 UNSET_ONGROUND(draggee);
990 curorigin = gettaginfo(draggee, 0);
991 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
992 makevectors(dragger.v_angle);
993 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
994 goodvelocity = (neworigin - curorigin) * (1 / frametime);
996 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
997 dragger.draglocalangle += 360;
998 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
999 dragger.draglocalangle -= 360;
1001 f = min(frametime * 10, 1);
1002 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
1004 if(Drag_MayChangeAngles(draggee))
1005 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
1007 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
1009 vector vecs = '0 0 0';
1010 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
1011 if(dragger.(weaponentity).movedir.x > 0)
1012 vecs = dragger.(weaponentity).movedir;
1014 vector dv = v_right * -vecs_y + v_up * vecs_z;
1016 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
1019 float Drag_CanDrag(entity dragger)
1021 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
1024 float Drag_IsDragging(entity dragger)
1026 if(!dragger.dragentity)
1028 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
1030 dragger.dragentity = NULL;
1033 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
1035 Drag_Finish(dragger);
1041 void Drag_MoveDrag(entity from, entity to)
1045 to.draggedby = from.draggedby;
1046 to.draggedby.dragentity = to;
1047 from.draggedby = NULL;
1051 void DragBox_Think(entity this)
1053 if(this.aiment && this.enemy)
1055 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1056 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1057 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1058 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1059 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1060 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1061 this.mins = -1 * this.maxs;
1062 setorigin(this, this.origin);
1063 setsize(this, this.mins, this.maxs); // link edict
1066 if(this.cnt == -1) // actually race_place -1
1068 // show "10 10" for qualifying spawns
1069 setmodel(this.killindicator, MDL_NUM(10));
1070 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1072 else if(this.cnt == -2) // actually race_place 0
1074 // show "10 0" for loser spawns
1075 setmodel(this.killindicator, MDL_NUM(10));
1076 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1080 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1081 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1084 this.nextthink = time;