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/physics/player.qh>
14 #include <common/stats.qh>
15 #include <common/util.qh>
16 #include <common/weapons/_all.qh>
17 #include <common/weapons/_all.qh>
18 #include <lib/csqcmodel/sv_model.qh>
19 #include <lib/warpzone/anglestransform.qh>
20 #include <lib/warpzone/util_server.qh>
21 #include <server/clientkill.qh>
22 #include <server/damage.qh>
23 #include <server/main.qh>
24 #include <server/mutators/_mod.qh>
25 #include <server/player.qh>
26 #include <server/race.qh>
27 #include <server/resources.qh>
28 #include <server/world.qh>
32 float CheatImpulse(entity this, int imp) { return 0; }
33 float CheatCommand(entity this, int argc) { return 0; }
34 float CheatFrame(entity this) { return 0; }
35 void CheatInit() { cheatcount_total = world.cheatcount; }
36 void CheatShutdown() { }
37 void Drag_MoveDrag(entity from, entity to) { }
42 float gamestart_sv_cheats;
48 gamestart_sv_cheats = autocvar_sv_cheats;
55 float CheatsAllowed(entity this, float i, int argc, float fr) // the cheat gets passed as argument for possible future ACL checking
59 if(gamestart_sv_cheats < 2 && !IS_PLAYER(this))
62 if(i == CHIMPULSE_CLONE_MOVING.impulse || i == CHIMPULSE_CLONE_STANDING.impulse)
63 if(this.lip < autocvar_sv_clones)
70 if(gamestart_sv_cheats && autocvar_sv_cheats)
73 // if we get here, player is not allowed to cheat. Log it.
75 bprintf("Player %s^7 tried to use cheat 'impulse %d'\n", playername(this.netname, this.team, false), i);
77 bprintf("Player %s^7 tried to use cheat '%s'\n", playername(this.netname, this.team, false), argv(0));
79 bprintf("Player %s^7 tried to use cheat frame %d\n", playername(this.netname, this.team, false), fr);
81 bprintf("Player %s^7 tried to use an unknown cheat\n", playername(this.netname, this.team, false));
86 #define BEGIN_CHEAT_FUNCTION() \
87 float cheating = 0, attempting = 0
90 #define ADD_CHEATS(e,n) \
91 cheatcount_total += n; \
93 #define END_CHEAT_FUNCTION() \
94 ADD_CHEATS(this, cheating); \
96 #define IS_CHEAT(ent,i,argc,fr) \
97 if((++attempting, !CheatsAllowed(ent,i,argc,fr))) \
100 float num_autoscreenshot;
101 void info_autoscreenshot_findtarget(entity this)
104 e = find(NULL, targetname, this.target);
107 objerror(this, "Missing target. FAIL!");
110 vector a = vectoangles(e.origin - this.origin);
111 a.x = -a.x; // don't ask
114 // we leave Rick Roll alone
116 spawnfunc(info_autoscreenshot)
118 // this one just has to exist
119 if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
121 objerror(this, "Too many info_autoscreenshot entitites. FAIL!");
124 if(this.target != "")
125 InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET);
128 float CheatImpulse(entity this, int imp)
130 BEGIN_CHEAT_FUNCTION();
135 case CHIMPULSE_SPEEDRUN_INIT.impulse: // deploy personal waypoint
136 // shared with regular waypoint init, so this is not a cheat by itself
139 this.personal = new(personal_wp);
141 this.personal.origin = this.origin;
142 this.personal.v_angle = this.v_angle;
143 this.personal.velocity = this.velocity;
144 SetResource(this.personal, RES_ROCKETS, GetResource(this, RES_ROCKETS));
145 SetResource(this.personal, RES_BULLETS, GetResource(this, RES_BULLETS));
146 SetResource(this.personal, RES_CELLS, GetResource(this, RES_CELLS));
147 SetResource(this.personal, RES_PLASMA, GetResource(this, RES_PLASMA));
148 SetResource(this.personal, RES_SHELLS, GetResource(this, RES_SHELLS));
149 SetResource(this.personal, RES_FUEL, GetResource(this, RES_FUEL));
150 SetResource(this.personal, RES_HEALTH, max(1, GetResource(this, RES_HEALTH)));
151 SetResource(this.personal, RES_ARMOR, GetResource(this, RES_ARMOR));
152 STAT(WEAPONS, this.personal) = STAT(WEAPONS, this);
153 STAT(BUFFS, this.personal) = STAT(BUFFS, this);
154 STAT(BUFF_TIME, this.personal) = STAT(BUFF_TIME, this);
155 this.personal.items = this.items;
156 this.personal.pauserotarmor_finished = this.pauserotarmor_finished;
157 this.personal.pauserothealth_finished = this.pauserothealth_finished;
158 this.personal.pauserotfuel_finished = this.pauserotfuel_finished;
159 this.personal.pauseregen_finished = this.pauseregen_finished;
160 STAT(STRENGTH_FINISHED, this.personal) = STAT(STRENGTH_FINISHED, this);
161 STAT(INVINCIBLE_FINISHED, this.personal) = STAT(INVINCIBLE_FINISHED, this);
162 this.personal.teleport_time = time;
163 break; // this part itself doesn't cheat, so let's not count this
164 case CHIMPULSE_CLONE_MOVING.impulse:
165 IS_CHEAT(this, imp, 0, 0);
166 makevectors (this.v_angle);
167 this.velocity = this.velocity + v_forward * 300;
170 this.velocity = this.velocity - v_forward * 300;
173 case CHIMPULSE_CLONE_STANDING.impulse:
174 IS_CHEAT(this, imp, 0, 0);
179 case CHIMPULSE_GIVE_ALL.impulse:
180 IS_CHEAT(this, imp, 0, 0);
181 CheatCommand(this, tokenize_console("give all"));
182 break; // already counted as cheat
183 case CHIMPULSE_SPEEDRUN.impulse:
184 if(!autocvar_g_allow_checkpoints)
185 IS_CHEAT(this, imp, 0, 0);
188 this.speedrunning = true;
189 tracebox(this.personal.origin, this.mins, this.maxs, this.personal.origin, MOVE_WORLDONLY, this);
192 sprint(this, "Cannot move there, cheater - only waypoints set using g_waypointsprite_personal work\n");
196 // Abort speedrun, teleport back
197 setorigin(this, this.personal.origin);
198 this.oldvelocity = this.velocity = this.personal.velocity;
199 this.angles = this.personal.v_angle;
200 this.fixangle = true;
202 MUTATOR_CALLHOOK(AbortSpeedrun, this);
205 SetResource(this, RES_ROCKETS, GetResource(this.personal, RES_ROCKETS));
206 SetResource(this, RES_BULLETS, GetResource(this.personal, RES_BULLETS));
207 SetResource(this, RES_CELLS, GetResource(this.personal, RES_CELLS));
208 SetResource(this, RES_PLASMA, GetResource(this.personal, RES_PLASMA));
209 SetResource(this, RES_SHELLS, GetResource(this.personal, RES_SHELLS));
210 SetResource(this, RES_FUEL, GetResource(this.personal, RES_FUEL));
211 SetResource(this, RES_HEALTH, GetResource(this.personal, RES_HEALTH));
212 SetResource(this, RES_ARMOR, GetResource(this.personal, RES_ARMOR));
213 STAT(WEAPONS, this) = STAT(WEAPONS, this.personal);
214 STAT(BUFFS, this) = STAT(BUFFS, this.personal);
215 STAT(BUFF_TIME, this) = STAT(BUFF_TIME, this.personal);
216 this.items = this.personal.items;
217 this.pauserotarmor_finished = time + this.personal.pauserotarmor_finished - this.personal.teleport_time;
218 this.pauserothealth_finished = time + this.personal.pauserothealth_finished - this.personal.teleport_time;
219 this.pauserotfuel_finished = time + this.personal.pauserotfuel_finished - this.personal.teleport_time;
220 this.pauseregen_finished = time + this.personal.pauseregen_finished - this.personal.teleport_time;
221 STAT(STRENGTH_FINISHED, this) = time + STAT(STRENGTH_FINISHED, this.personal) - this.personal.teleport_time;
222 STAT(INVINCIBLE_FINISHED, this) = time + STAT(INVINCIBLE_FINISHED, this.personal) - this.personal.teleport_time;
224 if(!autocvar_g_allow_checkpoints)
229 sprint(this, "UR DEAD AHAHAH))\n");
231 sprint(this, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
233 case CHIMPULSE_TELEPORT.impulse:
234 IS_CHEAT(this, imp, 0, 0);
235 if(this.move_movetype == MOVETYPE_NOCLIP)
237 e = find(NULL, classname, "info_autoscreenshot");
240 sprint(this, "Emergency teleport used info_autoscreenshot location\n");
241 setorigin(this, e.origin);
242 this.angles = e.angles;
244 // should we? this.angles_x = -this.angles_x;
245 this.fixangle = true;
246 this.velocity = '0 0 0';
251 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))
253 sprint(this, "Emergency teleport used random location\n");
254 this.angles_x = -this.angles.x;
255 this.fixangle = true;
256 this.velocity = '0 0 0';
260 sprint(this, "Emergency teleport could not find a good location, forget it!\n");
262 case CHIMPULSE_R00T.impulse:
263 IS_CHEAT(this, imp, 0, 0);
264 RandomSelection_Init();
265 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it) && DIFF_TEAM(it, this), { RandomSelection_AddEnt(it, 1, 1); });
266 if(RandomSelection_chosen_ent)
267 e = RandomSelection_chosen_ent;
271 Send_Effect(EFFECT_ROCKET_EXPLODE, e.origin, '0 0 0', 1);
272 sound(e, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
275 setorigin(e2, e.origin);
276 RadiusDamage(e2, this, 1000, 0, 128, NULL, NULL, 500, DEATH_CHEAT.m_id, DMG_NOWEP, e);
279 LOG_INFO("404 Sportsmanship not found.");
284 END_CHEAT_FUNCTION();
288 float CheatCommand(entity this, int argc)
290 BEGIN_CHEAT_FUNCTION();
298 case "pointparticles":
299 IS_CHEAT(this, 0, argc, 0);
304 // origin (0..1, on crosshair line)
308 crosshair_trace(this);
309 start = (1-f) * this.origin + f * trace_endpos;
312 Send_Effect_(argv(1), start, end, f);
316 sprint(this, "Usage: sv_cheats 1; restart; cmd pointparticles effectname position(0..1) velocityvector multiplier\n");
318 case "trailparticles":
319 IS_CHEAT(this, 0, argc, 0);
324 effectnum = _particleeffectnum(argv(1));
325 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
326 traceline(w_shotorg, w_shotorg + w_shotdir * max_shot_distance, MOVE_NORMAL, this);
327 __trailparticles(this, effectnum, w_shotorg, trace_endpos);
331 sprint(this, "Usage: sv_cheats 1; restart; cmd trailparticles effectname\n");
334 IS_CHEAT(this, 0, argc, 0);
340 W_SetupShot(this, weaponentities[0], false, false, SND_Null, CH_WEAPON_A, 0, 0);
341 traceline(w_shotorg, w_shotorg + w_shotdir * 2048, MOVE_NORMAL, this);
342 if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) || trace_fraction == 1)
344 sprint(this, "cannot make stuff there (bad surface)\n");
349 e.model = strzone(argv(1));
350 e.mdl = "rocket_explode";
351 SetResourceExplicit(e, RES_HEALTH, 1000);
352 setorigin(e, trace_endpos);
353 e.effects = EF_NOMODELFLAGS;
356 e.angles = fixedvectoangles2(trace_plane_normal, v_forward);
357 e.angles = AnglesTransform_ApplyToAngles(e.angles, '-90 0 0'); // so unrotated models work
359 spawnfunc_func_breakable(e);
363 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_NORMAL, e);
367 sprint(this, "cannot make stuff there (no space)\n");
377 sprint(this, "Usage: sv_cheats 1; restart; cmd make models/... 0/1/2\n");
380 IS_CHEAT(this, 0, argc, 0);
383 race_ImposePenaltyTime(this, stof(argv(1)), argv(2));
387 sprint(this, "Usage: sv_cheats 1; restart; cmd penalty 5.0 AHAHAHAHAHAHAH))\n");
389 case "dragbox_spawn": {
390 IS_CHEAT(this, 0, argc, 0);
391 entity e = new(dragbox_box);
392 setthink(e, DragBox_Think);
394 e.solid = -1; // black
395 setmodel(e, MDL_Null); // network it
397 e.cnt = stof(argv(1));
399 e.cnt = max(0, drag_lastcnt);
401 e.aiment = new(dragbox_corner_1);
403 setmodel(e.aiment, MDL_MARKER);
405 setsize(e.aiment, '0 0 0', '0 0 0');
407 setorigin(e.aiment, stov(argv(2)));
410 crosshair_trace(this);
411 setorigin(e.aiment, trace_endpos);
414 e.enemy = new(dragbox_corner_2);
416 setmodel(e.enemy, MDL_MARKER);
418 setsize(e.enemy, '0 0 0', '0 0 0');
419 end = normalize(this.origin + this.view_ofs - e.aiment.origin);
420 end.x = (end.x > 0) * 2 - 1;
421 end.y = (end.y > 0) * 2 - 1;
422 end.z = (end.z > 0) * 2 - 1;
424 setorigin(e.enemy, stov(argv(3)));
426 setorigin(e.enemy, e.aiment.origin + 32 * end);
428 e.killindicator = new(drag_digit);
429 e.killindicator.owner = e;
430 setattachment(e.killindicator, e, "");
431 setorigin(e.killindicator, '0 0 -8');
432 e.killindicator.killindicator = new(drag_digit);
433 e.killindicator.killindicator.owner = e;
434 setattachment(e.killindicator.killindicator, e, "");
435 setorigin(e.killindicator.killindicator, '0 0 8');
439 case "dragpoint_spawn": {
440 IS_CHEAT(this, 0, argc, 0);
441 entity e = new(dragpoint);
442 setthink(e, DragBox_Think);
444 e.solid = 0; // nothing special
445 setmodel(e, MDL_MARKER);
446 setsize(e, STAT(PL_MIN, this), STAT(PL_MAX, this));
449 e.cnt = stof(argv(1));
451 e.cnt = drag_lastcnt;
453 setorigin(e, stov(argv(2)));
456 crosshair_trace(this);
457 setorigin(e, trace_endpos + normalize(this.origin + this.view_ofs - trace_endpos));
458 move_out_of_solid(e);
461 e.killindicator = new(drag_digit);
462 e.killindicator.owner = e;
463 setattachment(e.killindicator, e, "");
464 setorigin(e.killindicator, '0 0 40');
465 e.killindicator.killindicator = new(drag_digit);
466 e.killindicator.killindicator.owner = e;
467 setattachment(e.killindicator.killindicator, e, "");
468 setorigin(e.killindicator.killindicator, '0 0 56');
473 IS_CHEAT(this, 0, argc, 0);
474 RandomSelection_Init();
475 crosshair_trace(this);
476 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
477 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
478 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
479 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
480 if(RandomSelection_chosen_ent)
482 delete(RandomSelection_chosen_ent.killindicator.killindicator);
483 delete(RandomSelection_chosen_ent.killindicator);
484 if(RandomSelection_chosen_ent.aiment)
485 delete(RandomSelection_chosen_ent.aiment);
486 if(RandomSelection_chosen_ent.enemy)
487 delete(RandomSelection_chosen_ent.enemy);
488 delete(RandomSelection_chosen_ent);
493 IS_CHEAT(this, 0, argc, 0);
496 RandomSelection_Init();
497 crosshair_trace(this);
498 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
499 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
500 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
501 RandomSelection_AddEnt(e, 1, 1 / vlen(e.origin + (e.mins + e.maxs) * 0.5 - trace_endpos));
502 if(RandomSelection_chosen_ent)
504 if(substring(argv(1), 0, 1) == "*")
505 RandomSelection_chosen_ent.cnt = drag_lastcnt = RandomSelection_chosen_ent.cnt + stof(substring(argv(1), 1, -1));
507 RandomSelection_chosen_ent.cnt = drag_lastcnt = stof(argv(1));
512 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_setcnt cnt\n");
515 IS_CHEAT(this, 0, argc, 0);
518 f = fopen(argv(1), FILE_WRITE);
519 fputs(f, "cmd drag_clear\n");
520 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
522 fputs(f, strcat("cmd dragbox_spawn ", ftos(e.cnt), " \"", vtos(e.aiment.origin), "\" \"", vtos(e.enemy.origin), "\"\n"));
524 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
526 fputs(f, strcat("cmd dragpoint_spawn ", ftos(e.cnt), " \"", vtos(e.origin), "\"\n"));
532 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
534 case "drag_saveraceent":
535 IS_CHEAT(this, 0, argc, 0);
538 f = fopen(argv(1), FILE_WRITE);
539 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
542 fputs(f, "\"classname\" \"trigger_race_checkpoint\"\n");
543 fputs(f, strcat("\"origin\" \"", ftos(e.absmin.x), " ", ftos(e.absmin.y), " ", ftos(e.absmin.z), "\"\n"));
544 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"));
545 fputs(f, strcat("\"cnt\" \"", ftos(e.cnt), "\"\n"));
546 fputs(f, strcat("\"targetname\" \"checkpoint", ftos(e.cnt), "\"\n"));
549 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
553 for(entity ent = NULL; (ent = find(ent, classname, "dragbox_box")); )
555 if((e.cnt <= 0 && ent.cnt == 0) || e.cnt == ent.cnt)
557 start = start + ent.origin;
561 start *= 1 / effectnum;
563 fputs(f, "\"classname\" \"info_player_race\"\n");
564 fputs(f, strcat("\"angle\" \"", ftos(vectoyaw(start - e.origin)), "\"\n"));
565 fputs(f, strcat("\"origin\" \"", ftos(e.origin.x), " ", ftos(e.origin.y), " ", ftos(e.origin.z), "\"\n"));
568 fputs(f, "\"target\" \"checkpoint0\"\n");
569 fputs(f, "\"race_place\" \"0\"\n");
573 fputs(f, "\"target\" \"checkpoint0\"\n");
574 fputs(f, "\"race_place\" \"-1\"\n");
578 fputs(f, strcat("\"target\" \"checkpoint", ftos(e.cnt), "\"\n"));
581 // these need race_place
584 for(entity ent = NULL; (ent = find(ent, classname, "dragpoint")); )
587 if(vlen2(ent.origin - start) < vlen2(e.origin - start))
589 else if(vlen2(ent.origin - start) == vlen2(e.origin - start) && etof(ent) < etof(e))
592 fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
601 sprint(this, "Usage: sv_cheats 1; restart; cmd dragbox_save filename\n");
604 IS_CHEAT(this, 0, argc, 0);
605 for(entity e = NULL; (e = find(e, classname, "dragbox_box")); )
607 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_1")); )
609 for(entity e = NULL; (e = find(e, classname, "dragbox_corner_2")); )
611 for(entity e = NULL; (e = find(e, classname, "dragpoint")); )
613 for(entity e = NULL; (e = find(e, classname, "drag_digit")); )
618 IS_CHEAT(this, 0, argc, 0);
619 BITXOR_ASSIGN(this.flags, FL_GODMODE);
620 if(this.flags & FL_GODMODE)
622 sprint(this, "godmode ON\n");
626 sprint(this, "godmode OFF\n");
629 IS_CHEAT(this, 0, argc, 0);
630 BITXOR_ASSIGN(this.flags, FL_NOTARGET);
631 if(this.flags & FL_NOTARGET)
633 sprint(this, "notarget ON\n");
637 sprint(this, "notarget OFF\n");
640 IS_CHEAT(this, 0, argc, 0);
641 if(this.move_movetype != MOVETYPE_NOCLIP)
643 set_movetype(this, MOVETYPE_NOCLIP);
644 sprint(this, "noclip ON\n");
649 set_movetype(this, MOVETYPE_WALK);
650 sprint(this, "noclip OFF\n");
654 IS_CHEAT(this, 0, argc, 0);
655 if(this.move_movetype != MOVETYPE_FLY)
657 set_movetype(this, MOVETYPE_FLY);
658 sprint(this, "flymode ON\n");
663 set_movetype(this, MOVETYPE_WALK);
664 sprint(this, "flymode OFF\n");
668 IS_CHEAT(this, 0, argc, 0);
669 if(GiveItems(this, 1, argc))
673 IS_CHEAT(this, 0, argc, 0);
676 SUB_UseTargets(e, this, NULL);
681 IS_CHEAT(this, 0, argc, 0);
683 e2.killtarget = argv(1);
684 SUB_UseTargets(e2, this, NULL);
688 case "teleporttotarget":
689 IS_CHEAT(this, 0, argc, 0);
690 entity ent = new(cheattriggerteleport);
691 setorigin(ent, ent.origin);
692 ent.target = argv(1);
693 teleport_findtarget(ent);
696 Simple_TeleportPlayer(ent, this);
703 END_CHEAT_FUNCTION();
708 float CheatFrame(entity this)
710 BEGIN_CHEAT_FUNCTION();
712 // Dragging can be used as either a cheat, or a function for some objects. If sv_cheats is active,
713 // the cheat dragging is used (unlimited pickup range and any entity can be carried). If sv_cheats
714 // is disabled, normal dragging is used (limited pickup range and only dragable objects can be carried),
715 // grabbing itself no longer being accounted as cheating.
720 if(this.maycheat || (gamestart_sv_cheats && autocvar_sv_cheats))
722 // use cheat dragging if cheats are enabled
723 //if(Drag_IsDragging(this))
724 //crosshair_trace_plusvisibletriggers(this);
725 Drag(this, true, true);
729 Drag(this, false, false); // execute dragging
734 END_CHEAT_FUNCTION();
745 .float dragspeed; // speed of mouse wheel action
746 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
747 .vector draglocalvector; // local attachment vector of the dragentity
748 .float draglocalangle;
753 float Drag(entity this, float force_allow_pick, float ischeat)
755 BEGIN_CHEAT_FUNCTION();
757 // returns true when an entity has been picked up
758 // If pick is true, the object can also be picked up if it's not being held already
759 // If pick is false, only keep dragging the object if it's already being held
764 if(Drag_IsDragging(this))
766 if(PHYS_INPUT_BUTTON_DRAG(this))
768 if(CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18)
770 Drag_MoveForward(this);
771 CS(this).impulse = 0;
773 else if(CS(this).impulse == 12 || CS(this).impulse == 16 || CS(this).impulse == 19)
775 Drag_MoveBackward(this);
776 CS(this).impulse = 0;
778 else if(CS(this).impulse >= 1 && CS(this).impulse <= 9)
780 Drag_SetSpeed(this, CS(this).impulse - 1);
782 else if(CS(this).impulse == 14)
784 Drag_SetSpeed(this, 9);
795 else if(Drag_CanDrag(this) && PHYS_INPUT_BUTTON_DRAG(this))
797 crosshair_trace_plusvisibletriggers(this);
798 entity e = trace_ent;
799 float pick = force_allow_pick;
800 if (e && !pick && vdist(this.origin - e.origin, <=, autocvar_g_grab_range))
802 // pick is true if the object can be picked up. While an object is being carried, the Drag() function
803 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
804 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
805 // it goes out of range while slinging it around.
809 case 0: // can't grab
811 case 1: // owner can grab
812 if(e.owner == this || e.realowner == this)
815 case 2: // owner and team mates can grab
816 if(SAME_TEAM(e.owner, this) || SAME_TEAM(e.realowner, this) || e.team == this.team)
819 case 3: // anyone can grab
827 if(e && pick && Drag_IsDraggable(e, this))
830 IS_CHEAT(this, 0, 0, CHRAME_DRAG);
832 Drag_Finish(e.draggedby);
834 detach_sameorigin(e);
835 Drag_Begin(this, e, trace_endpos);
846 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
850 draggee.dragmovetype = draggee.move_movetype;
851 draggee.draggravity = draggee.gravity;
852 set_movetype(draggee, MOVETYPE_WALK);
853 draggee.gravity = 0.00001;
854 UNSET_ONGROUND(draggee);
855 draggee.draggedby = dragger;
857 dragger.dragentity = draggee;
859 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
860 dragger.draglocalangle = draggee.angles.y - dragger.v_angle.y;
861 touchpoint = touchpoint - gettaginfo(draggee, 0);
862 tagscale = (vlen(v_forward) ** -2);
863 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
864 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
865 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
867 dragger.dragspeed = 64;
870 void Drag_Finish(entity dragger)
873 draggee = dragger.dragentity;
875 dragger.dragentity = NULL;
876 draggee.draggedby = NULL;
877 set_movetype(draggee, draggee.dragmovetype);
878 draggee.gravity = draggee.draggravity;
880 switch(draggee.move_movetype)
885 case MOVETYPE_FLYMISSILE:
886 case MOVETYPE_BOUNCE:
887 case MOVETYPE_BOUNCEMISSILE:
888 case MOVETYPE_PHYSICS:
891 draggee.velocity = '0 0 0';
895 if((draggee.flags & FL_ITEM) && (vdist(draggee.velocity, <, 32)))
897 draggee.velocity = '0 0 0';
898 SET_ONGROUND(draggee); // floating items are FUN
902 bool drag_undraggable(entity draggee, entity dragger)
904 // stuff probably shouldn't need this, we should figure out why they do!
905 // exceptions of course are observers and weapon entities, where things mess up
909 float Drag_IsDraggable(entity draggee, entity dragger)
911 // TODO add more checks for bad stuff here
914 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)
915 return false; // probably due to BSP collision
916 //if(draggee.model == "")
919 return ((draggee.draggable) ? draggee.draggable(draggee, dragger) : true);
922 float Drag_MayChangeAngles(entity draggee)
924 // TODO add more checks for bad stuff here
925 if(substring(draggee.model, 0, 1) == "*")
930 void Drag_MoveForward(entity dragger)
932 dragger.dragdistance += dragger.dragspeed;
935 void Drag_SetSpeed(entity dragger, float s)
937 dragger.dragspeed = (2 ** s);
940 void Drag_MoveBackward(entity dragger)
942 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
945 void Drag_Update(entity dragger)
947 vector curorigin, neworigin, goodvelocity;
951 draggee = dragger.dragentity;
952 UNSET_ONGROUND(draggee);
954 curorigin = gettaginfo(draggee, 0);
955 curorigin = curorigin + v_forward * dragger.draglocalvector.x + v_right * dragger.draglocalvector.y + v_up * dragger.draglocalvector.z;
956 makevectors(dragger.v_angle);
957 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
958 goodvelocity = (neworigin - curorigin) * (1 / frametime);
960 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle > 180)
961 dragger.draglocalangle += 360;
962 while(draggee.angles.y - dragger.v_angle.y - dragger.draglocalangle <= -180)
963 dragger.draglocalangle -= 360;
965 f = min(frametime * 10, 1);
966 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
968 if(Drag_MayChangeAngles(draggee))
969 draggee.angles_y = draggee.angles.y * (1 - f) + (dragger.v_angle.y + dragger.draglocalangle) * f;
971 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
973 vector vecs = '0 0 0';
974 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
975 if(dragger.(weaponentity).movedir.x > 0)
976 vecs = dragger.(weaponentity).movedir;
978 vector dv = v_right * -vecs_y + v_up * vecs_z;
980 te_lightning1(draggee, dragger.origin + dragger.view_ofs + dv, curorigin);
983 float Drag_CanDrag(entity dragger)
985 return (!IS_DEAD(dragger)) || (IS_PLAYER(dragger));
988 float Drag_IsDragging(entity dragger)
990 if(!dragger.dragentity)
992 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
994 dragger.dragentity = NULL;
997 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity, dragger))
999 Drag_Finish(dragger);
1005 void Drag_MoveDrag(entity from, entity to)
1009 to.draggedby = from.draggedby;
1010 to.draggedby.dragentity = to;
1011 from.draggedby = NULL;
1015 void DragBox_Think(entity this)
1017 if(this.aiment && this.enemy)
1019 this.origin_x = (this.aiment.origin.x + this.enemy.origin.x) * 0.5;
1020 this.origin_y = (this.aiment.origin.y + this.enemy.origin.y) * 0.5;
1021 this.origin_z = (this.aiment.origin.z + this.enemy.origin.z) * 0.5;
1022 this.maxs_x = fabs(this.aiment.origin.x - this.enemy.origin.x) * 0.5;
1023 this.maxs_y = fabs(this.aiment.origin.y - this.enemy.origin.y) * 0.5;
1024 this.maxs_z = fabs(this.aiment.origin.z - this.enemy.origin.z) * 0.5;
1025 this.mins = -1 * this.maxs;
1026 setorigin(this, this.origin);
1027 setsize(this, this.mins, this.maxs); // link edict
1030 if(this.cnt == -1) // actually race_place -1
1032 // show "10 10" for qualifying spawns
1033 setmodel(this.killindicator, MDL_NUM(10));
1034 setmodel(this.killindicator.killindicator, MDL_NUM(10));
1036 else if(this.cnt == -2) // actually race_place 0
1038 // show "10 0" for loser spawns
1039 setmodel(this.killindicator, MDL_NUM(10));
1040 setmodel(this.killindicator.killindicator, MDL_NUM(0));
1044 setmodel(this.killindicator, MDL_NUM(this.cnt % 10));
1045 setmodel(this.killindicator.killindicator, MDL_NUM(floor(this.cnt / 10)));
1048 this.nextthink = time;