1 var void remove(entity e);
2 void objerror(string s);
4 .vector dropped_origin;
6 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
7 void crosshair_trace(entity pl)
9 traceline_antilag(pl, pl.cursor_trace_start, pl.cursor_trace_start + normalize(pl.cursor_trace_endpos - pl.cursor_trace_start) * MAX_SHOT_DISTANCE, MOVE_NORMAL, pl, ANTILAG_LATENCY(pl));
11 void crosshair_trace_plusvisibletriggers(entity pl)
15 first = findchainfloat(solid, SOLID_TRIGGER);
17 for (e = first; e; e = e.chain)
23 for (e = first; e; e = e.chain)
24 e.solid = SOLID_TRIGGER;
26 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
27 void WarpZone_crosshair_trace(entity pl)
29 WarpZone_traceline_antilag(pl, pl.cursor_trace_start, pl.cursor_trace_start + normalize(pl.cursor_trace_endpos - pl.cursor_trace_start) * MAX_SHOT_DISTANCE, MOVE_NORMAL, pl, ANTILAG_LATENCY(pl));
32 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
33 void() spawnpoint_use;
35 string ColoredTeamName(float t);
37 string admin_name(void)
39 if(autocvar_sv_adminnick != "")
40 return autocvar_sv_adminnick;
42 return "SERVER ADMIN";
45 float DistributeEvenly_amount;
46 float DistributeEvenly_totalweight;
47 void DistributeEvenly_Init(float amount, float totalweight)
49 if (DistributeEvenly_amount)
51 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
52 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
55 DistributeEvenly_amount = 0;
57 DistributeEvenly_amount = amount;
58 DistributeEvenly_totalweight = totalweight;
60 float DistributeEvenly_Get(float weight)
65 f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
66 DistributeEvenly_totalweight -= weight;
67 DistributeEvenly_amount -= f;
70 float DistributeEvenly_GetRandomized(float weight)
75 f = floor(random() + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
76 DistributeEvenly_totalweight -= weight;
77 DistributeEvenly_amount -= f;
81 #define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e)
84 string STR_PLAYER = "player";
85 string STR_SPECTATOR = "spectator";
86 string STR_OBSERVER = "observer";
89 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
90 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
91 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
92 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
93 #define FOR_EACH_MONSTER(v) for(v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
95 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
96 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
97 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
98 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
99 #define FOR_EACH_SPEC(v) FOR_EACH_CLIENT(v) if(v.classname != STR_PLAYER)
100 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
101 #define FOR_EACH_MONSTER(v) for(v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
104 #define CENTER_OR_VIEWOFS(ent) (ent.origin + ((ent.classname == STR_PLAYER) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
106 // copies a string to a tempstring (so one can strunzone it)
107 string strcat1(string s) = #115; // FRIK_FILE
112 void bcenterprint(string s)
114 // TODO replace by MSG_ALL (would show it to spectators too, though)?
116 FOR_EACH_PLAYER(head)
117 if (clienttype(head) == CLIENTTYPE_REAL)
118 centerprint(head, s);
121 void GameLogEcho(string s)
126 if (autocvar_sv_eventlog_files)
131 matches = autocvar_sv_eventlog_files_counter + 1;
132 cvar_set("sv_eventlog_files_counter", ftos(matches));
135 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
136 fn = strcat(autocvar_sv_eventlog_files_nameprefix, fn, autocvar_sv_eventlog_files_namesuffix);
137 logfile = fopen(fn, FILE_APPEND);
138 fputs(logfile, ":logversion:3\n");
142 if (autocvar_sv_eventlog_files_timestamps)
143 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
145 fputs(logfile, strcat(s, "\n"));
148 if (autocvar_sv_eventlog_console)
157 // will be opened later
162 if (logfile_open && logfile >= 0)
169 float spawnpoint_nag;
170 void relocate_spawnpoint()
172 // nudge off the floor
173 setorigin(self, self.origin + '0 0 1');
175 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
176 if (trace_startsolid)
182 if (!move_out_of_solid(self))
183 objerror("could not get out of solid at all!");
184 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
185 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
186 print(" ", ftos(self.origin_y - o_y));
187 print(" ", ftos(self.origin_z - o_z), "'\n");
188 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
191 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
197 self.mins = self.maxs = '0 0 0';
198 objerror("player spawn point in solid, mapper sucks!\n");
203 self.use = spawnpoint_use;
204 self.team_saved = self.team;
208 if (have_team_spawns != 0)
210 have_team_spawns = 1;
211 have_team_spawns_forteam[self.team] = 1;
213 if (autocvar_r_showbboxes)
215 // show where spawnpoints point at too
216 makevectors(self.angles);
219 e.classname = "info_player_foo";
220 setorigin(e, self.origin + v_forward * 24);
221 setsize(e, '-8 -8 -8', '8 8 8');
222 e.solid = SOLID_TRIGGER;
226 #define strstr strstrofs
228 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
229 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
230 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
231 // BE CONSTANT OR strzoneD!
232 float strstr(string haystack, string needle, float offset)
236 len = strlen(needle);
237 endpos = strlen(haystack) - len;
238 while(offset <= endpos)
240 found = substring(haystack, offset, len);
249 float NUM_NEAREST_ENTITIES = 4;
250 entity nearest_entity[NUM_NEAREST_ENTITIES];
251 float nearest_length[NUM_NEAREST_ENTITIES];
252 entity findnearest(vector point, .string field, string value, vector axismod)
263 localhead = find(world, field, value);
266 if ((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
267 dist = localhead.oldorigin;
269 dist = localhead.origin;
271 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
274 for (i = 0; i < num_nearest; ++i)
276 if (len < nearest_length[i])
280 // now i tells us where to insert at
281 // INSERTION SORT! YOU'VE SEEN IT! RUN!
282 if (i < NUM_NEAREST_ENTITIES)
284 for (j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
286 nearest_length[j + 1] = nearest_length[j];
287 nearest_entity[j + 1] = nearest_entity[j];
289 nearest_length[i] = len;
290 nearest_entity[i] = localhead;
291 if (num_nearest < NUM_NEAREST_ENTITIES)
292 num_nearest = num_nearest + 1;
295 localhead = find(localhead, field, value);
298 // now use the first one from our list that we can see
299 for (i = 0; i < num_nearest; ++i)
301 traceline(point, nearest_entity[i].origin, TRUE, world);
302 if (trace_fraction == 1)
306 dprint("Nearest point (");
307 dprint(nearest_entity[0].netname);
308 dprint(") is not visible, using a visible one.\n");
310 return nearest_entity[i];
314 if (num_nearest == 0)
317 dprint("Not seeing any location point, using nearest as fallback.\n");
319 dprint("Candidates were: ");
320 for(j = 0; j < num_nearest; ++j)
324 dprint(nearest_entity[j].netname);
329 return nearest_entity[0];
332 void spawnfunc_target_location()
334 self.classname = "target_location";
335 // location name in netname
336 // eventually support: count, teamgame selectors, line of sight?
339 void spawnfunc_info_location()
341 self.classname = "target_location";
342 self.message = self.netname;
345 string NearestLocation(vector p)
350 loc = findnearest(p, classname, "target_location", '1 1 1');
357 loc = findnearest(p, target, "###item###", '1 1 4');
364 string formatmessage(string msg)
375 WarpZone_crosshair_trace(self);
376 cursor = trace_endpos;
377 cursor_ent = trace_ent;
381 break; // too many replacements
384 p1 = strstr(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
385 p2 = strstr(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
398 replacement = substring(msg, p, 2);
399 escape = substring(msg, p + 1, 1);
403 else if (escape == "\\")
405 else if (escape == "n")
407 else if (escape == "a")
408 replacement = ftos(floor(self.armorvalue));
409 else if (escape == "h")
410 replacement = ftos(floor(self.health));
411 else if (escape == "l")
412 replacement = NearestLocation(self.origin);
413 else if (escape == "y")
414 replacement = NearestLocation(cursor);
415 else if (escape == "d")
416 replacement = NearestLocation(self.death_origin);
417 else if (escape == "w") {
421 wep = self.switchweapon;
424 replacement = W_Name(wep);
425 } else if (escape == "W") {
426 if (self.items & IT_SHELLS) replacement = "shells";
427 else if (self.items & IT_NAILS) replacement = "bullets";
428 else if (self.items & IT_ROCKETS) replacement = "rockets";
429 else if (self.items & IT_CELLS) replacement = "cells";
430 else replacement = "batteries"; // ;)
431 } else if (escape == "x") {
432 replacement = cursor_ent.netname;
433 if (replacement == "" || !cursor_ent)
434 replacement = "nothing";
435 } else if (escape == "s")
436 replacement = ftos(vlen(self.velocity - self.velocity_z * '0 0 1'));
437 else if (escape == "S")
438 replacement = ftos(vlen(self.velocity));
440 msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
441 p = p + strlen(replacement);
446 float boolean(float value) { // if value is 0 return FALSE (0), otherwise return TRUE (1)
447 return (value == 0) ? FALSE : TRUE;
456 >0: receives a cvar from name=argv(f) value=argv(f+1)
458 void GetCvars_handleString(string thisname, float f, .string field, string name)
463 strunzone(self.field);
464 self.field = string_null;
468 if (thisname == name)
471 strunzone(self.field);
472 self.field = strzone(argv(f + 1));
476 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
478 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
480 GetCvars_handleString(thisname, f, field, name);
481 if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
482 if (thisname == name)
485 s = func(strcat1(self.field));
488 strunzone(self.field);
489 self.field = strzone(s);
493 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
500 if (thisname == name)
501 self.field = stof(argv(f + 1));
504 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
506 void GetCvars_handleFloatOnce(string thisname, float f, .float field, string name)
513 if (thisname == name)
517 self.field = stof(argv(f + 1));
526 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
529 float w_getbestweapon(entity e);
530 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(string wo)
533 o = W_FixWeaponOrder_ForceComplete(wo);
534 if(self.weaponorder_byimpulse)
536 strunzone(self.weaponorder_byimpulse);
537 self.weaponorder_byimpulse = string_null;
539 self.weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(o));
542 void GetCvars(float f)
544 string s = string_null;
547 s = strcat1(argv(f));
551 MUTATOR_CALLHOOK(GetCvars);
552 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
553 GetCvars_handleFloat(s, f, cvar_cl_autoscreenshot, "cl_autoscreenshot");
554 GetCvars_handleString(s, f, cvar_g_xonoticversion, "g_xonoticversion");
555 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
556 GetCvars_handleFloat(s, f, cvar_cl_clippedspectating, "cl_clippedspectating");
557 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
558 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
559 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
560 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
561 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
562 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
563 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
564 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
565 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
566 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
567 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
568 GetCvars_handleFloat(s, f, cvar_cl_weaponimpulsemode, "cl_weaponimpulsemode");
569 GetCvars_handleFloat(s, f, cvar_cl_autotaunt, "cl_autotaunt");
570 GetCvars_handleFloat(s, f, cvar_cl_noantilag, "cl_noantilag");
571 GetCvars_handleFloat(s, f, cvar_cl_voice_directional, "cl_voice_directional");
572 GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation");
573 GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_share, "cl_accuracy_data_share");
574 GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_receive, "cl_accuracy_data_receive");
576 self.cvar_cl_accuracy_data_share = boolean(self.cvar_cl_accuracy_data_share);
577 self.cvar_cl_accuracy_data_receive = boolean(self.cvar_cl_accuracy_data_receive);
579 GetCvars_handleFloatOnce(s, f, cvar_cl_gunalign, "cl_gunalign");
580 GetCvars_handleFloat(s, f, cvar_cl_allow_uid2name, "cl_allow_uid2name");
581 GetCvars_handleFloat(s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
582 GetCvars_handleFloat(s, f, cvar_cl_movement_track_canjump, "cl_movement_track_canjump");
583 GetCvars_handleFloat(s, f, cvar_cl_newusekeysupported, "cl_newusekeysupported");
585 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
588 if (s == "cl_weaponpriority")
589 self.switchweapon = w_getbestweapon(self);
590 if (s == "cl_allow_uidtracking")
591 PlayerStats_AddPlayer(self);
595 void backtrace(string msg)
598 dev = autocvar_developer;
599 war = autocvar_prvm_backtraceforwarnings;
600 cvar_set("developer", "1");
601 cvar_set("prvm_backtraceforwarnings", "1");
603 print("--- CUT HERE ---\nWARNING: ");
606 remove(world); // isn't there any better way to cause a backtrace?
607 print("\n--- CUT UNTIL HERE ---\n");
608 cvar_set("developer", ftos(dev));
609 cvar_set("prvm_backtraceforwarnings", ftos(war));
612 string Team_ColorCode(float teamid)
614 if (teamid == COLOR_TEAM1)
616 else if (teamid == COLOR_TEAM2)
618 else if (teamid == COLOR_TEAM3)
620 else if (teamid == COLOR_TEAM4)
626 string Team_ColorName(float t)
628 // fixme: Search for team entities and get their .netname's!
629 if (t == COLOR_TEAM1)
631 if (t == COLOR_TEAM2)
633 if (t == COLOR_TEAM3)
635 if (t == COLOR_TEAM4)
640 string Team_ColorNameLowerCase(float t)
642 // fixme: Search for team entities and get their .netname's!
643 if (t == COLOR_TEAM1)
645 if (t == COLOR_TEAM2)
647 if (t == COLOR_TEAM3)
649 if (t == COLOR_TEAM4)
654 float ColourToNumber(string team_colour)
656 if (team_colour == "red")
659 if (team_colour == "blue")
662 if (team_colour == "yellow")
665 if (team_colour == "pink")
668 if (team_colour == "auto")
674 float NumberToTeamNumber(float number)
691 // decolorizes and team colors the player name when needed
692 string playername(entity p)
695 if (teamplay && !intermission_running && p.classname == "player")
697 t = Team_ColorCode(p.team);
698 return strcat(t, strdecolorize(p.netname));
704 vector randompos(vector m1, vector m2)
708 v_x = m2_x * random() + m1_x;
709 v_y = m2_y * random() + m1_y;
710 v_z = m2_z * random() + m1_z;
714 //#NO AUTOCVARS START
716 float g_pickup_shells;
717 float g_pickup_shells_max;
718 float g_pickup_nails;
719 float g_pickup_nails_max;
720 float g_pickup_rockets;
721 float g_pickup_rockets_max;
722 float g_pickup_cells;
723 float g_pickup_cells_max;
725 float g_pickup_fuel_jetpack;
726 float g_pickup_fuel_max;
727 float g_pickup_armorsmall;
728 float g_pickup_armorsmall_max;
729 float g_pickup_armorsmall_anyway;
730 float g_pickup_armormedium;
731 float g_pickup_armormedium_max;
732 float g_pickup_armormedium_anyway;
733 float g_pickup_armorbig;
734 float g_pickup_armorbig_max;
735 float g_pickup_armorbig_anyway;
736 float g_pickup_armorlarge;
737 float g_pickup_armorlarge_max;
738 float g_pickup_armorlarge_anyway;
739 float g_pickup_healthsmall;
740 float g_pickup_healthsmall_max;
741 float g_pickup_healthsmall_anyway;
742 float g_pickup_healthmedium;
743 float g_pickup_healthmedium_max;
744 float g_pickup_healthmedium_anyway;
745 float g_pickup_healthlarge;
746 float g_pickup_healthlarge_max;
747 float g_pickup_healthlarge_anyway;
748 float g_pickup_healthmega;
749 float g_pickup_healthmega_max;
750 float g_pickup_healthmega_anyway;
751 float g_pickup_ammo_anyway;
752 float g_pickup_weapons_anyway;
754 WEPSET_DECLARE_A(g_weaponarena_weapons);
755 float g_weaponarena_random;
756 float g_weaponarena_random_with_laser;
757 string g_weaponarena_list;
758 float g_weaponspeedfactor;
759 float g_weaponratefactor;
760 float g_weapondamagefactor;
761 float g_weaponforcefactor;
762 float g_weaponspreadfactor;
764 WEPSET_DECLARE_A(start_weapons);
765 WEPSET_DECLARE_A(start_weapons_default);
766 WEPSET_DECLARE_A(start_weapons_defaultmask);
768 float start_ammo_shells;
769 float start_ammo_nails;
770 float start_ammo_rockets;
771 float start_ammo_cells;
772 float start_ammo_fuel;
774 float start_armorvalue;
775 WEPSET_DECLARE_A(warmup_start_weapons);
776 WEPSET_DECLARE_A(warmup_start_weapons_default);
777 WEPSET_DECLARE_A(warmup_start_weapons_defaultmask);
778 float warmup_start_ammo_shells;
779 float warmup_start_ammo_nails;
780 float warmup_start_ammo_rockets;
781 float warmup_start_ammo_cells;
782 float warmup_start_ammo_fuel;
783 float warmup_start_health;
784 float warmup_start_armorvalue;
787 entity get_weaponinfo(float w);
789 float want_weapon(string cvarprefix, entity weaponinfo, float allguns)
791 var float i = weaponinfo.weapon;
797 if (g_lms || g_ca || allguns)
799 if(weaponinfo.spawnflags & WEP_FLAG_NORMAL)
805 d = (i == WEP_SHOTGUN);
807 d = 0; // weapon is set a few lines later
809 d = (i == WEP_LASER || i == WEP_SHOTGUN);
811 if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
812 d |= (i == WEP_HOOK);
813 if(weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED) // never default mutator blocked guns
816 var float t = cvar(strcat(cvarprefix, weaponinfo.netname));
818 //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n"));
823 // 4: is set by default?
832 void readplayerstartcvars()
838 // initialize starting values for players
839 WEPSET_CLEAR_A(start_weapons);
840 WEPSET_CLEAR_A(start_weapons_default);
841 WEPSET_CLEAR_A(start_weapons_defaultmask);
843 start_ammo_shells = 0;
844 start_ammo_nails = 0;
845 start_ammo_rockets = 0;
846 start_ammo_cells = 0;
847 start_health = cvar("g_balance_health_start");
848 start_armorvalue = cvar("g_balance_armor_start");
851 WEPSET_CLEAR_A(g_weaponarena_weapons);
853 s = cvar_string("g_weaponarena");
854 if (s == "0" || s == "")
860 if (s == "0" || s == "")
866 // forcibly turn off weaponarena
871 g_weaponarena_list = "All Weapons";
872 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
874 e = get_weaponinfo(j);
875 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
876 WEPSET_OR_AW(g_weaponarena_weapons, j);
879 else if (s == "most")
882 g_weaponarena_list = "Most Weapons";
883 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
885 e = get_weaponinfo(j);
886 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
887 if (e.spawnflags & WEP_FLAG_NORMAL)
888 WEPSET_OR_AW(g_weaponarena_weapons, j);
891 else if (s == "none")
894 g_weaponarena_list = "No Weapons";
899 t = tokenize_console(s);
900 g_weaponarena_list = "";
901 for (i = 0; i < t; ++i)
904 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
906 e = get_weaponinfo(j);
909 WEPSET_OR_AW(g_weaponarena_weapons, j);
910 g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
916 print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
919 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
923 g_weaponarena_random = cvar("g_weaponarena_random");
925 g_weaponarena_random = 0;
926 g_weaponarena_random_with_laser = cvar("g_weaponarena_random_with_laser");
930 g_minstagib = 0; // incompatible
931 g_pinata = 0; // incompatible
932 g_weapon_stay = 0; // incompatible
933 WEPSET_COPY_AA(start_weapons, g_weaponarena_weapons);
935 start_items |= IT_UNLIMITED_AMMO;
937 else if (g_minstagib)
939 g_pinata = 0; // incompatible
940 g_weapon_stay = 0; // incompatible
941 g_bloodloss = 0; // incompatible
943 start_armorvalue = 0;
944 WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
945 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
946 start_items |= IT_UNLIMITED_SUPERWEAPONS;
948 if (g_minstagib_invis_alpha <= 0)
949 g_minstagib_invis_alpha = -1;
953 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
955 e = get_weaponinfo(i);
956 float w = want_weapon("g_start_weapon_", e, FALSE);
958 WEPSET_OR_AW(start_weapons, i);
960 WEPSET_OR_AW(start_weapons_default, i);
962 WEPSET_OR_AW(start_weapons_defaultmask, i);
966 if(!cvar("g_use_ammunition"))
967 start_items |= IT_UNLIMITED_AMMO;
969 if(cvar("g_nexball"))
970 start_items |= IT_UNLIMITED_SUPERWEAPONS; // FIXME BAD BAD BAD BAD HACK, NEXBALL SHOULDN'T ABUSE PORTO'S WEAPON SLOT
974 start_ammo_cells = cvar("g_minstagib_ammo_start");
975 start_ammo_fuel = cvar("g_start_ammo_fuel");
977 else if(start_items & IT_UNLIMITED_WEAPON_AMMO)
979 start_ammo_rockets = 999;
980 start_ammo_shells = 999;
981 start_ammo_cells = 999;
982 start_ammo_nails = 999;
983 start_ammo_fuel = 999;
989 start_ammo_shells = cvar("g_lms_start_ammo_shells");
990 start_ammo_nails = cvar("g_lms_start_ammo_nails");
991 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
992 start_ammo_cells = cvar("g_lms_start_ammo_cells");
993 start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
997 start_ammo_shells = cvar("g_start_ammo_shells");
998 start_ammo_nails = cvar("g_start_ammo_nails");
999 start_ammo_rockets = cvar("g_start_ammo_rockets");
1000 start_ammo_cells = cvar("g_start_ammo_cells");
1001 start_ammo_fuel = cvar("g_start_ammo_fuel");
1007 start_health = cvar("g_lms_start_health");
1008 start_armorvalue = cvar("g_lms_start_armor");
1013 warmup_start_ammo_shells = start_ammo_shells;
1014 warmup_start_ammo_nails = start_ammo_nails;
1015 warmup_start_ammo_rockets = start_ammo_rockets;
1016 warmup_start_ammo_cells = start_ammo_cells;
1017 warmup_start_ammo_fuel = start_ammo_fuel;
1018 warmup_start_health = start_health;
1019 warmup_start_armorvalue = start_armorvalue;
1020 WEPSET_COPY_AA(warmup_start_weapons, start_weapons);
1021 WEPSET_COPY_AA(warmup_start_weapons_default, start_weapons_default);
1022 WEPSET_COPY_AA(warmup_start_weapons_defaultmask, start_weapons_defaultmask);
1024 if (!g_weaponarena && !g_minstagib && !g_ca)
1026 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
1027 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
1028 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
1029 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
1030 warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
1031 warmup_start_health = cvar("g_warmup_start_health");
1032 warmup_start_armorvalue = cvar("g_warmup_start_armor");
1033 WEPSET_CLEAR_A(warmup_start_weapons);
1034 WEPSET_CLEAR_A(warmup_start_weapons_default);
1035 WEPSET_CLEAR_A(warmup_start_weapons_defaultmask);
1036 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1038 e = get_weaponinfo(i);
1039 float w = want_weapon("g_start_weapon_", e, cvar("g_warmup_allguns"));
1041 WEPSET_OR_AW(warmup_start_weapons, i);
1043 WEPSET_OR_AW(warmup_start_weapons_default, i);
1045 WEPSET_OR_AW(warmup_start_weapons_defaultmask, i);
1051 start_items |= IT_JETPACK;
1053 MUTATOR_CALLHOOK(SetStartItems);
1055 if ((start_items & IT_JETPACK) || (g_grappling_hook && WEPSET_CONTAINS_AW(start_weapons, WEP_HOOK)))
1057 g_grappling_hook = 0; // these two can't coexist, as they use the same button
1058 start_items |= IT_FUEL_REGEN;
1059 start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1060 warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1063 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1065 e = get_weaponinfo(i);
1066 if(WEPSET_CONTAINS_AW(start_weapons, i) || WEPSET_CONTAINS_AW(warmup_start_weapons, i))
1067 weapon_action(i, WR_PRECACHE);
1070 start_ammo_shells = max(0, start_ammo_shells);
1071 start_ammo_nails = max(0, start_ammo_nails);
1072 start_ammo_cells = max(0, start_ammo_cells);
1073 start_ammo_rockets = max(0, start_ammo_rockets);
1074 start_ammo_fuel = max(0, start_ammo_fuel);
1076 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
1077 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
1078 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
1079 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
1080 warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
1084 float g_bugrigs_planar_movement;
1085 float g_bugrigs_planar_movement_car_jumping;
1086 float g_bugrigs_reverse_spinning;
1087 float g_bugrigs_reverse_speeding;
1088 float g_bugrigs_reverse_stopping;
1089 float g_bugrigs_air_steering;
1090 float g_bugrigs_angle_smoothing;
1091 float g_bugrigs_friction_floor;
1092 float g_bugrigs_friction_brake;
1093 float g_bugrigs_friction_air;
1094 float g_bugrigs_accel;
1095 float g_bugrigs_speed_ref;
1096 float g_bugrigs_speed_pow;
1097 float g_bugrigs_steer;
1099 float g_touchexplode;
1100 float g_touchexplode_radius;
1101 float g_touchexplode_damage;
1102 float g_touchexplode_edgedamage;
1103 float g_touchexplode_force;
1108 string GetGametype(); // g_world.qc
1109 void readlevelcvars(void)
1111 g_minstagib = cvar("g_minstagib");
1113 monster_skill = cvar("g_monsters_skill");
1115 // load ALL the mutators
1116 if(cvar("g_dodging"))
1117 MUTATOR_ADD(mutator_dodging);
1118 if(cvar("g_spawn_near_teammate"))
1119 MUTATOR_ADD(mutator_spawn_near_teammate);
1120 if(cvar("g_physical_items"))
1121 MUTATOR_ADD(mutator_physical_items);
1124 if(cvar("g_invincible_projectiles"))
1125 MUTATOR_ADD(mutator_invincibleprojectiles);
1126 if(cvar("g_new_toys"))
1127 MUTATOR_ADD(mutator_new_toys);
1129 MUTATOR_ADD(mutator_nix);
1130 if(cvar("g_rocket_flying"))
1131 MUTATOR_ADD(mutator_rocketflying);
1132 if(cvar("g_vampire"))
1133 MUTATOR_ADD(mutator_vampire);
1134 if(cvar("g_superspectate"))
1135 MUTATOR_ADD(mutator_superspec);
1138 // is this a mutator? is this a mode?
1139 if(cvar("g_sandbox"))
1140 MUTATOR_ADD(sandbox);
1143 MUTATOR_ADD(mutator_zombie_apocalypse);
1145 if(cvar("sv_allow_fullbright"))
1146 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
1148 g_bugrigs = cvar("g_bugrigs");
1149 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
1150 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
1151 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
1152 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
1153 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
1154 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
1155 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
1156 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
1157 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
1158 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
1159 g_bugrigs_accel = cvar("g_bugrigs_accel");
1160 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
1161 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
1162 g_bugrigs_steer = cvar("g_bugrigs_steer");
1164 g_touchexplode = cvar("g_touchexplode");
1165 g_touchexplode_radius = cvar("g_touchexplode_radius");
1166 g_touchexplode_damage = cvar("g_touchexplode_damage");
1167 g_touchexplode_edgedamage = cvar("g_touchexplode_edgedamage");
1168 g_touchexplode_force = cvar("g_touchexplode_force");
1170 sv_clones = cvar("sv_clones");
1171 sv_gentle = cvar("sv_gentle");
1172 sv_foginterval = cvar("sv_foginterval");
1173 g_cloaked = cvar("g_cloaked");
1175 g_cloaked = 1; // always enable cloak in CTS
1176 g_jump_grunt = cvar("g_jump_grunt");
1177 g_footsteps = cvar("g_footsteps");
1178 g_grappling_hook = cvar("g_grappling_hook");
1179 g_jetpack = cvar("g_jetpack");
1180 g_midair = cvar("g_midair");
1181 g_norecoil = cvar("g_norecoil");
1182 g_bloodloss = cvar("g_bloodloss");
1183 sv_maxidle = cvar("sv_maxidle");
1184 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
1185 sv_autotaunt = cvar("sv_autotaunt");
1186 sv_taunt = cvar("sv_taunt");
1188 inWarmupStage = cvar("g_warmup");
1189 g_warmup_limit = cvar("g_warmup_limit");
1190 g_warmup_allguns = cvar("g_warmup_allguns");
1191 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
1193 if ((g_race && g_race_qualifying == 2) || g_runematch || g_arena || g_assault || cvar("g_campaign"))
1194 inWarmupStage = 0; // these modes cannot work together, sorry
1196 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
1197 g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
1198 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
1199 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
1200 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
1201 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
1202 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
1203 g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
1204 g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
1205 g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
1206 g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
1207 g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
1208 g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
1209 g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
1211 g_weaponspeedfactor = cvar("g_weaponspeedfactor");
1212 g_weaponratefactor = cvar("g_weaponratefactor");
1213 g_weapondamagefactor = cvar("g_weapondamagefactor");
1214 g_weaponforcefactor = cvar("g_weaponforcefactor");
1215 g_weaponspreadfactor = cvar("g_weaponspreadfactor");
1217 g_pickup_shells = cvar("g_pickup_shells");
1218 g_pickup_shells_max = cvar("g_pickup_shells_max");
1219 g_pickup_nails = cvar("g_pickup_nails");
1220 g_pickup_nails_max = cvar("g_pickup_nails_max");
1221 g_pickup_rockets = cvar("g_pickup_rockets");
1222 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
1223 g_pickup_cells = cvar("g_pickup_cells");
1224 g_pickup_cells_max = cvar("g_pickup_cells_max");
1225 g_pickup_fuel = cvar("g_pickup_fuel");
1226 g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
1227 g_pickup_fuel_max = cvar("g_pickup_fuel_max");
1228 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
1229 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
1230 g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
1231 g_pickup_armormedium = cvar("g_pickup_armormedium");
1232 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
1233 g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
1234 g_pickup_armorbig = cvar("g_pickup_armorbig");
1235 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
1236 g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
1237 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
1238 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
1239 g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
1240 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
1241 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
1242 g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
1243 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
1244 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
1245 g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
1246 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
1247 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
1248 g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
1249 g_pickup_healthmega = cvar("g_pickup_healthmega");
1250 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
1251 g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
1253 g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
1254 g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
1256 g_pinata = cvar("g_pinata");
1258 g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
1260 g_weapon_stay = cvar("g_weapon_stay");
1262 if not(inWarmupStage && !g_ca)
1263 game_starttime = cvar("g_start_delay");
1265 readplayerstartcvars();
1271 string precache_sound (string s) = #19;
1272 float precache_sound_index (string s) = #19;
1274 #define SND_VOLUME 1
1275 #define SND_ATTENUATION 2
1276 #define SND_LARGEENTITY 8
1277 #define SND_LARGESOUND 16
1279 float sound_allowed(float dest, entity e)
1281 // sounds from world may always pass
1284 if (e.classname == "body")
1286 else if (e.realowner && e.realowner != e)
1288 else if (e.owner && e.owner != e)
1293 // sounds to self may always pass
1294 if (dest == MSG_ONE)
1295 if (e == msg_entity)
1297 // sounds by players can be removed
1298 if (autocvar_bot_sound_monopoly)
1299 if (clienttype(e) == CLIENTTYPE_REAL)
1301 // anything else may pass
1305 #ifdef COMPAT_XON010_CHANNELS
1306 void(entity e, float chan, string samp, float vol, float atten) builtin_sound = #8;
1307 void sound(entity e, float chan, string samp, float vol, float atten)
1309 if (!sound_allowed(MSG_BROADCAST, e))
1311 builtin_sound(e, chan, samp, vol, atten);
1315 void sound(entity e, float chan, string samp, float vol, float atten)
1317 if (!sound_allowed(MSG_BROADCAST, e))
1319 sound7(e, chan, samp, vol, atten, 0, 0);
1323 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
1327 if (!sound_allowed(dest, e))
1330 entno = num_for_edict(e);
1331 idx = precache_sound_index(samp);
1336 atten = floor(atten * 64);
1337 vol = floor(vol * 255);
1340 sflags |= SND_VOLUME;
1342 sflags |= SND_ATTENUATION;
1343 if (entno >= 8192 || chan < 0 || chan > 7)
1344 sflags |= SND_LARGEENTITY;
1346 sflags |= SND_LARGESOUND;
1348 WriteByte(dest, SVC_SOUND);
1349 WriteByte(dest, sflags);
1350 if (sflags & SND_VOLUME)
1351 WriteByte(dest, vol);
1352 if (sflags & SND_ATTENUATION)
1353 WriteByte(dest, atten);
1354 if (sflags & SND_LARGEENTITY)
1356 WriteShort(dest, entno);
1357 WriteByte(dest, chan);
1361 WriteShort(dest, entno * 8 + chan);
1363 if (sflags & SND_LARGESOUND)
1364 WriteShort(dest, idx);
1366 WriteByte(dest, idx);
1368 WriteCoord(dest, o_x);
1369 WriteCoord(dest, o_y);
1370 WriteCoord(dest, o_z);
1372 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
1376 if (!sound_allowed(dest, e))
1379 o = e.origin + 0.5 * (e.mins + e.maxs);
1380 soundtoat(dest, e, o, chan, samp, vol, atten);
1382 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
1384 soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, atten);
1386 void stopsoundto(float dest, entity e, float chan)
1390 if (!sound_allowed(dest, e))
1393 entno = num_for_edict(e);
1395 if (entno >= 8192 || chan < 0 || chan > 7)
1398 idx = precache_sound_index("misc/null.wav");
1399 sflags = SND_LARGEENTITY;
1401 sflags |= SND_LARGESOUND;
1402 WriteByte(dest, SVC_SOUND);
1403 WriteByte(dest, sflags);
1404 WriteShort(dest, entno);
1405 WriteByte(dest, chan);
1406 if (sflags & SND_LARGESOUND)
1407 WriteShort(dest, idx);
1409 WriteByte(dest, idx);
1410 WriteCoord(dest, e.origin_x);
1411 WriteCoord(dest, e.origin_y);
1412 WriteCoord(dest, e.origin_z);
1416 WriteByte(dest, SVC_STOPSOUND);
1417 WriteShort(dest, entno * 8 + chan);
1420 void stopsound(entity e, float chan)
1422 if (!sound_allowed(MSG_BROADCAST, e))
1425 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
1426 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
1429 void play2(entity e, string filename)
1431 //stuffcmd(e, strcat("play2 ", filename, "\n"));
1433 soundtoat(MSG_ONE, world, '0 0 0', CH_INFO, filename, VOL_BASE, ATTN_NONE);
1436 // use this one if you might be causing spam (e.g. from touch functions that might get called more than once per frame)
1438 float spamsound(entity e, float chan, string samp, float vol, float atten)
1440 if (!sound_allowed(MSG_BROADCAST, e))
1443 if (time > e.spamtime)
1446 sound(e, chan, samp, vol, atten);
1452 void play2team(float t, string filename)
1456 if (autocvar_bot_sound_monopoly)
1459 FOR_EACH_REALPLAYER(head)
1462 play2(head, filename);
1466 void play2all(string samp)
1468 if (autocvar_bot_sound_monopoly)
1471 sound(world, CH_INFO, samp, VOL_BASE, ATTN_NONE);
1474 void PrecachePlayerSounds(string f);
1475 void precache_playermodel(string m)
1477 float globhandle, i, n;
1480 if(substring(m, -9,5) == "_lod1")
1482 if(substring(m, -9,5) == "_lod2")
1485 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
1488 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
1492 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
1495 n = search_getsize(globhandle);
1496 for (i = 0; i < n; ++i)
1498 //print(search_getfilename(globhandle, i), "\n");
1499 f = search_getfilename(globhandle, i);
1500 PrecachePlayerSounds(f);
1502 search_end(globhandle);
1504 void precache_all_playermodels(string pattern)
1506 float globhandle, i, n;
1509 globhandle = search_begin(pattern, TRUE, FALSE);
1512 n = search_getsize(globhandle);
1513 for (i = 0; i < n; ++i)
1515 //print(search_getfilename(globhandle, i), "\n");
1516 f = search_getfilename(globhandle, i);
1517 precache_playermodel(f);
1519 search_end(globhandle);
1524 // gamemode related things
1525 precache_model ("models/misc/chatbubble.spr");
1528 precache_model ("models/runematch/curse.mdl");
1529 precache_model ("models/runematch/rune.mdl");
1532 #ifdef TTURRETS_ENABLED
1533 if (autocvar_g_turrets)
1537 // Precache all player models if desired
1538 if (autocvar_sv_precacheplayermodels)
1540 PrecachePlayerSounds("sound/player/default.sounds");
1541 precache_all_playermodels("models/player/*.zym");
1542 precache_all_playermodels("models/player/*.dpm");
1543 precache_all_playermodels("models/player/*.md3");
1544 precache_all_playermodels("models/player/*.psk");
1545 precache_all_playermodels("models/player/*.iqm");
1548 if (autocvar_sv_defaultcharacter)
1551 s = autocvar_sv_defaultplayermodel_red;
1553 precache_playermodel(s);
1554 s = autocvar_sv_defaultplayermodel_blue;
1556 precache_playermodel(s);
1557 s = autocvar_sv_defaultplayermodel_yellow;
1559 precache_playermodel(s);
1560 s = autocvar_sv_defaultplayermodel_pink;
1562 precache_playermodel(s);
1563 s = autocvar_sv_defaultplayermodel;
1565 precache_playermodel(s);
1570 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1571 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1574 // gore and miscellaneous sounds
1575 //precache_sound ("misc/h2ohit.wav");
1576 precache_model ("models/hook.md3");
1577 precache_sound ("misc/armorimpact.wav");
1578 precache_sound ("misc/bodyimpact1.wav");
1579 precache_sound ("misc/bodyimpact2.wav");
1580 precache_sound ("misc/gib.wav");
1581 precache_sound ("misc/gib_splat01.wav");
1582 precache_sound ("misc/gib_splat02.wav");
1583 precache_sound ("misc/gib_splat03.wav");
1584 precache_sound ("misc/gib_splat04.wav");
1585 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1586 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1587 precache_sound ("misc/null.wav");
1588 precache_sound ("misc/spawn.wav");
1589 precache_sound ("misc/talk.wav");
1590 precache_sound ("misc/teleport.wav");
1591 precache_sound ("misc/poweroff.wav");
1592 precache_sound ("player/lava.wav");
1593 precache_sound ("player/slime.wav");
1595 precache_model ("models/sprites/0.spr32");
1596 precache_model ("models/sprites/1.spr32");
1597 precache_model ("models/sprites/2.spr32");
1598 precache_model ("models/sprites/3.spr32");
1599 precache_model ("models/sprites/4.spr32");
1600 precache_model ("models/sprites/5.spr32");
1601 precache_model ("models/sprites/6.spr32");
1602 precache_model ("models/sprites/7.spr32");
1603 precache_model ("models/sprites/8.spr32");
1604 precache_model ("models/sprites/9.spr32");
1605 precache_model ("models/sprites/10.spr32");
1607 // common weapon precaches
1608 precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound here
1609 precache_sound ("weapons/weapon_switch.wav");
1610 precache_sound ("weapons/weaponpickup.wav");
1611 precache_sound ("weapons/unavailable.wav");
1612 precache_sound ("weapons/dryfire.wav");
1613 if (g_grappling_hook)
1615 precache_sound ("weapons/hook_fire.wav"); // hook
1616 precache_sound ("weapons/hook_impact.wav"); // hook
1619 if(autocvar_sv_precacheweapons)
1621 //precache weapon models/sounds
1624 while (wep <= WEP_LAST)
1626 weapon_action(wep, WR_PRECACHE);
1631 precache_model("models/elaser.mdl");
1632 precache_model("models/laser.mdl");
1633 precache_model("models/ebomb.mdl");
1636 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
1638 if (!self.noise && self.music) // quake 3 uses the music field
1639 self.noise = self.music;
1641 // plays music for the level if there is any
1644 precache_sound (self.noise);
1645 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1650 // sorry, but using \ in macros breaks line numbers
1651 #define WRITESPECTATABLE_MSG_ONE_VARNAME(varname,statement) entity varname; varname = msg_entity; FOR_EACH_REALCLIENT(msg_entity) if(msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) statement msg_entity = varname
1652 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1653 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1656 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
1658 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
1661 WRITESPECTATABLE_MSG_ONE({
1662 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1663 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
1664 WriteByte(MSG_ONE, id);
1665 WriteString(MSG_ONE, s);
1666 if (id != 0 && s != "")
1668 WriteByte(MSG_ONE, duration);
1669 WriteByte(MSG_ONE, countdown_num);
1674 void Send_CSQC_Centerprint_Generic_Expire(entity e, float id)
1676 Send_CSQC_Centerprint_Generic(e, id, "", 1, 0);
1678 // WARNING: this kills the trace globals
1679 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
1680 #define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init()
1682 #define INITPRIO_FIRST 0
1683 #define INITPRIO_GAMETYPE 0
1684 #define INITPRIO_GAMETYPE_FALLBACK 1
1685 #define INITPRIO_FINDTARGET 10
1686 #define INITPRIO_DROPTOFLOOR 20
1687 #define INITPRIO_SETLOCATION 90
1688 #define INITPRIO_LINKDOORS 91
1689 #define INITPRIO_LAST 99
1691 .void(void) initialize_entity;
1692 .float initialize_entity_order;
1693 .entity initialize_entity_next;
1694 entity initialize_entity_first;
1696 void make_safe_for_remove(entity e)
1698 if (e.initialize_entity)
1700 entity ent, prev = world;
1701 for (ent = initialize_entity_first; ent; )
1703 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1705 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1706 // skip it in linked list
1709 prev.initialize_entity_next = ent.initialize_entity_next;
1710 ent = prev.initialize_entity_next;
1714 initialize_entity_first = ent.initialize_entity_next;
1715 ent = initialize_entity_first;
1721 ent = ent.initialize_entity_next;
1727 void objerror(string s)
1729 make_safe_for_remove(self);
1730 builtin_objerror(s);
1733 .float remove_except_protected_forbidden;
1734 void remove_except_protected(entity e)
1736 if(e.remove_except_protected_forbidden)
1737 error("not allowed to remove this at this point");
1741 void remove_unsafely(entity e)
1743 if(e.classname == "spike")
1744 error("Removing spikes is forbidden (crylink bug), please report");
1748 void remove_safely(entity e)
1750 make_safe_for_remove(e);
1754 void InitializeEntity(entity e, void(void) func, float order)
1758 if (!e || e.initialize_entity)
1760 // make a proxy initializer entity
1764 e.classname = "initialize_entity";
1768 e.initialize_entity = func;
1769 e.initialize_entity_order = order;
1771 cur = initialize_entity_first;
1775 if (!cur || cur.initialize_entity_order > order)
1777 // insert between prev and cur
1779 prev.initialize_entity_next = e;
1781 initialize_entity_first = e;
1782 e.initialize_entity_next = cur;
1786 cur = cur.initialize_entity_next;
1789 void InitializeEntitiesRun()
1792 startoflist = initialize_entity_first;
1793 initialize_entity_first = world;
1794 remove = remove_except_protected;
1795 for (self = startoflist; self; self = self.initialize_entity_next)
1797 self.remove_except_protected_forbidden = 1;
1799 for (self = startoflist; self; )
1802 var void(void) func;
1803 e = self.initialize_entity_next;
1804 func = self.initialize_entity;
1805 self.initialize_entity_order = 0;
1806 self.initialize_entity = func_null;
1807 self.initialize_entity_next = world;
1808 self.remove_except_protected_forbidden = 0;
1809 if (self.classname == "initialize_entity")
1813 builtin_remove(self);
1816 //dprint("Delayed initialization: ", self.classname, "\n");
1822 backtrace(strcat("Null function in: ", self.classname, "\n"));
1826 remove = remove_unsafely;
1829 .float uncustomizeentityforclient_set;
1830 .void(void) uncustomizeentityforclient;
1831 void UncustomizeEntitiesRun()
1835 for (self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1836 self.uncustomizeentityforclient();
1839 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1841 e.customizeentityforclient = customizer;
1842 e.uncustomizeentityforclient = uncustomizer;
1843 e.uncustomizeentityforclient_set = !!uncustomizer;
1847 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1850 void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc)
1854 if (e.classname == "")
1855 e.classname = "net_linked";
1857 if (e.model == "" || self.modelindex == 0)
1861 setmodel(e, "null");
1865 e.SendEntity = sendfunc;
1866 e.SendFlags = 0xFFFFFF;
1869 e.effects |= EF_NODEPTHTEST;
1873 e.nextthink = time + dt;
1874 e.think = SUB_Remove;
1878 void adaptor_think2touch()
1887 void adaptor_think2use()
1899 void adaptor_think2use_hittype_splash() // for timed projectile detonation
1901 if not(self.flags & FL_ONGROUND) // if onground, we ARE touching something, but HITTYPE_SPLASH is to be networked if the damage causing projectile is not touching ANYTHING
1902 self.projectiledeathtype |= HITTYPE_SPLASH;
1903 adaptor_think2use();
1906 // deferred dropping
1907 void DropToFloor_Handler()
1909 builtin_droptofloor();
1910 self.dropped_origin = self.origin;
1915 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1920 float trace_hits_box_a0, trace_hits_box_a1;
1922 float trace_hits_box_1d(float end, float thmi, float thma)
1926 // just check if x is in range
1934 // do the trace with respect to x
1935 // 0 -> end has to stay in thmi -> thma
1936 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1937 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1938 if (trace_hits_box_a0 > trace_hits_box_a1)
1944 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1949 // now it is a trace from 0 to end
1951 trace_hits_box_a0 = 0;
1952 trace_hits_box_a1 = 1;
1954 if (!trace_hits_box_1d(end_x, thmi_x, thma_x))
1956 if (!trace_hits_box_1d(end_y, thmi_y, thma_y))
1958 if (!trace_hits_box_1d(end_z, thmi_z, thma_z))
1964 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1966 return trace_hits_box(start, end, thmi - ma, thma - mi);
1969 float SUB_NoImpactCheck()
1971 // zero hitcontents = this is not the real impact, but either the
1972 // mirror-impact of something hitting the projectile instead of the
1973 // projectile hitting the something, or a touchareagrid one. Neither of
1974 // these stop the projectile from moving, so...
1975 if(trace_dphitcontents == 0)
1977 //dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
1978 dprint(sprintf(_("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Profectile will self-destruct. (edict: %d, classname: %s, origin: %s)\n"), num_for_edict(self), self.classname, vtos(self.origin)));
1981 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1983 if (other == world && self.size != '0 0 0')
1986 tic = self.velocity * sys_frametime;
1987 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
1988 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
1989 if (trace_fraction >= 1)
1991 dprint("Odd... did not hit...?\n");
1993 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1995 dprint("Detected and prevented the sky-grapple bug.\n");
2003 #define SUB_OwnerCheck() (other && (other == self.owner))
2005 void RemoveGrapplingHook(entity pl);
2006 void W_Crylink_Dequeue(entity e);
2007 float WarpZone_Projectile_Touch_ImpactFilter_Callback()
2009 if(SUB_OwnerCheck())
2011 if(SUB_NoImpactCheck())
2013 if(self.classname == "grapplinghook")
2014 RemoveGrapplingHook(self.realowner);
2015 else if(self.classname == "spike")
2017 W_Crylink_Dequeue(self);
2024 if(trace_ent && trace_ent.solid > SOLID_TRIGGER)
2025 UpdateCSQCProjectile(self);
2028 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
2030 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
2031 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER) || ((dt) == DEATH_SLIME) || ((dt) == DEATH_LAVA) || ((dt) == DEATH_SWAMP))
2033 void URI_Get_Callback(float id, float status, string data)
2035 if(url_URI_Get_Callback(id, status, data))
2039 else if (id == URI_GET_DISCARD)
2043 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
2046 Curl_URI_Get_Callback(id, status, data);
2048 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
2051 OnlineBanList_URI_Get_Callback(id, status, data);
2055 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
2059 string uid2name(string myuid) {
2061 s = db_get(ServerProgsDB, strcat("/uid2name/", myuid));
2063 // FIXME remove this later after 0.6 release
2064 // convert old style broken records to correct style
2067 s = db_get(ServerProgsDB, strcat("uid2name", myuid));
2070 db_put(ServerProgsDB, strcat("/uid2name/", myuid), s);
2071 db_put(ServerProgsDB, strcat("uid2name", myuid), "");
2076 s = "^1Unregistered Player";
2080 float race_readTime(string map, float pos)
2088 return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
2091 string race_readUID(string map, float pos)
2099 return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)));
2102 float race_readPos(string map, float t) {
2104 for (i = 1; i <= RANKINGS_CNT; ++i)
2105 if (race_readTime(map, i) == 0 || race_readTime(map, i) > t)
2108 return 0; // pos is zero if unranked
2111 void race_writeTime(string map, float t, string myuid)
2120 newpos = race_readPos(map, t);
2122 float i, prevpos = 0;
2123 for(i = 1; i <= RANKINGS_CNT; ++i)
2125 if(race_readUID(map, i) == myuid)
2128 if (prevpos) { // player improved his existing record, only have to iterate on ranks between new and old recs
2129 for (i = prevpos; i > newpos; --i) {
2130 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2131 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2133 } else { // player has no ranked record yet
2134 for (i = RANKINGS_CNT; i > newpos; --i) {
2135 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2136 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2140 // store new time itself
2141 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(newpos)), ftos(t));
2142 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(newpos)), myuid);
2145 string race_readName(string map, float pos)
2153 return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))));
2156 string race_placeName(float pos) {
2157 if(floor((mod(pos, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
2159 if(mod(pos, 10) == 1)
2160 return strcat(ftos(pos), "st");
2161 else if(mod(pos, 10) == 2)
2162 return strcat(ftos(pos), "nd");
2163 else if(mod(pos, 10) == 3)
2164 return strcat(ftos(pos), "rd");
2166 return strcat(ftos(pos), "th");
2169 return strcat(ftos(pos), "th");
2172 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
2175 vector start, org, delta, end, enddown, mstart;
2178 m = e.dphitcontentsmask;
2179 e.dphitcontentsmask = goodcontents | badcontents;
2182 delta = world.maxs - world.mins;
2186 for (i = 0; i < attempts; ++i)
2188 start_x = org_x + random() * delta_x;
2189 start_y = org_y + random() * delta_y;
2190 start_z = org_z + random() * delta_z;
2192 // rule 1: start inside world bounds, and outside
2193 // solid, and don't start from somewhere where you can
2194 // fall down to evil
2195 tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, e);
2196 if (trace_fraction >= 1)
2198 if (trace_startsolid)
2200 if (trace_dphitcontents & badcontents)
2202 if (trace_dphitq3surfaceflags & badsurfaceflags)
2205 // rule 2: if we are too high, lower the point
2206 if (trace_fraction * delta_z > maxaboveground)
2207 start = trace_endpos + '0 0 1' * maxaboveground;
2208 enddown = trace_endpos;
2210 // rule 3: make sure we aren't outside the map. This only works
2211 // for somewhat well formed maps. A good rule of thumb is that
2212 // the map should have a convex outside hull.
2213 // these can be traceLINES as we already verified the starting box
2214 mstart = start + 0.5 * (e.mins + e.maxs);
2215 traceline(mstart, mstart + '1 0 0' * delta_x, MOVE_NORMAL, e);
2216 if (trace_fraction >= 1)
2218 traceline(mstart, mstart - '1 0 0' * delta_x, MOVE_NORMAL, e);
2219 if (trace_fraction >= 1)
2221 traceline(mstart, mstart + '0 1 0' * delta_y, MOVE_NORMAL, e);
2222 if (trace_fraction >= 1)
2224 traceline(mstart, mstart - '0 1 0' * delta_y, MOVE_NORMAL, e);
2225 if (trace_fraction >= 1)
2227 traceline(mstart, mstart + '0 0 1' * delta_z, MOVE_NORMAL, e);
2228 if (trace_fraction >= 1)
2231 // rule 4: we must "see" some spawnpoint
2232 for(sp = world; (sp = find(sp, classname, "info_player_deathmatch")); )
2233 if(checkpvs(mstart, sp))
2237 for(sp = world; (sp = findflags(sp, flags, FL_ITEM)); )
2238 if(checkpvs(mstart, sp))
2244 // find a random vector to "look at"
2245 end_x = org_x + random() * delta_x;
2246 end_y = org_y + random() * delta_y;
2247 end_z = org_z + random() * delta_z;
2248 end = start + normalize(end - start) * vlen(delta);
2250 // rule 4: start TO end must not be too short
2251 tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
2252 if (trace_startsolid)
2254 if (trace_fraction < minviewdistance / vlen(delta))
2257 // rule 5: don't want to look at sky
2258 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
2261 // rule 6: we must not end up in trigger_hurt
2262 if (tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
2268 e.dphitcontentsmask = m;
2272 setorigin(e, start);
2273 e.angles = vectoangles(end - start);
2274 dprint("Needed ", ftos(i + 1), " attempts\n");
2281 float zcurveparticles_effectno;
2282 vector zcurveparticles_start;
2283 float zcurveparticles_spd;
2285 void endzcurveparticles()
2287 if(zcurveparticles_effectno)
2290 WriteShort(MSG_BROADCAST, zcurveparticles_spd | 0x8000);
2292 zcurveparticles_effectno = 0;
2295 void zcurveparticles(float effectno, vector start, vector end, float end_dz, float spd)
2297 spd = bound(0, floor(spd / 16), 32767);
2298 if(effectno != zcurveparticles_effectno || start != zcurveparticles_start)
2300 endzcurveparticles();
2301 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
2302 WriteByte(MSG_BROADCAST, TE_CSQC_ZCURVEPARTICLES);
2303 WriteShort(MSG_BROADCAST, effectno);
2304 WriteCoord(MSG_BROADCAST, start_x);
2305 WriteCoord(MSG_BROADCAST, start_y);
2306 WriteCoord(MSG_BROADCAST, start_z);
2307 zcurveparticles_effectno = effectno;
2308 zcurveparticles_start = start;
2311 WriteShort(MSG_BROADCAST, zcurveparticles_spd);
2312 WriteCoord(MSG_BROADCAST, end_x);
2313 WriteCoord(MSG_BROADCAST, end_y);
2314 WriteCoord(MSG_BROADCAST, end_z);
2315 WriteCoord(MSG_BROADCAST, end_dz);
2316 zcurveparticles_spd = spd;
2319 void zcurveparticles_from_tracetoss(float effectno, vector start, vector end, vector vel)
2322 vector vecxy, velxy;
2324 vecxy = end - start;
2329 if (vlen(velxy) < 0.000001 * fabs(vel_z))
2331 endzcurveparticles();
2332 trailparticles(world, effectno, start, end);
2336 end_dz = vlen(vecxy) / vlen(velxy) * vel_z - (end_z - start_z);
2337 zcurveparticles(effectno, start, end, end_dz, vlen(vel));
2340 void write_recordmarker(entity pl, float tstart, float dt)
2342 GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
2344 // also write a marker into demo files for demotc-race-record-extractor to find
2347 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
2348 " ", ftos(tstart), " ", ftos(dt), "\n"));
2351 vector shotorg_adjustfromclient(vector vecs, float y_is_right, float allowcenter, float algn)
2364 if(allowcenter) // 2: allow center handedness
2377 if(allowcenter) // 2: allow center handedness
2393 vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn)
2398 if (autocvar_g_shootfromeye)
2402 if (autocvar_g_shootfromclient) { vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn); }
2403 else { vecs_y = 0; vecs_z -= 2; }
2411 else if (autocvar_g_shootfromcenter)
2416 else if ((s = autocvar_g_shootfromfixedorigin) != "")
2426 else if (autocvar_g_shootfromclient)
2428 vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn);
2433 vector shotorg_adjust(vector vecs, float y_is_right, float visual)
2435 return shotorg_adjust_values(vecs, y_is_right, visual, self.owner.cvar_cl_gunalign);
2439 void attach_sameorigin(entity e, entity to, string tag)
2441 vector org, t_forward, t_left, t_up, e_forward, e_up;
2444 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2445 tagscale = pow(vlen(v_forward), -2); // undo a scale on the tag
2446 t_forward = v_forward * tagscale;
2447 t_left = v_right * -tagscale;
2448 t_up = v_up * tagscale;
2450 e.origin_x = org * t_forward;
2451 e.origin_y = org * t_left;
2452 e.origin_z = org * t_up;
2454 // current forward and up directions
2455 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2456 e.angles = AnglesTransform_FromVAngles(e.angles);
2458 e.angles = AnglesTransform_FromAngles(e.angles);
2459 fixedmakevectors(e.angles);
2461 // untransform forward, up!
2462 e_forward_x = v_forward * t_forward;
2463 e_forward_y = v_forward * t_left;
2464 e_forward_z = v_forward * t_up;
2465 e_up_x = v_up * t_forward;
2466 e_up_y = v_up * t_left;
2467 e_up_z = v_up * t_up;
2469 e.angles = fixedvectoangles2(e_forward, e_up);
2470 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2471 e.angles = AnglesTransform_ToVAngles(e.angles);
2473 e.angles = AnglesTransform_ToAngles(e.angles);
2475 setattachment(e, to, tag);
2476 setorigin(e, e.origin);
2479 void detach_sameorigin(entity e)
2482 org = gettaginfo(e, 0);
2483 e.angles = fixedvectoangles2(v_forward, v_up);
2484 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2485 e.angles = AnglesTransform_ToVAngles(e.angles);
2487 e.angles = AnglesTransform_ToAngles(e.angles);
2489 setattachment(e, world, "");
2490 setorigin(e, e.origin);
2493 void follow_sameorigin(entity e, entity to)
2495 e.movetype = MOVETYPE_FOLLOW; // make the hole follow
2496 e.aiment = to; // make the hole follow bmodel
2497 e.punchangle = to.angles; // the original angles of bmodel
2498 e.view_ofs = e.origin - to.origin; // relative origin
2499 e.v_angle = e.angles - to.angles; // relative angles
2502 void unfollow_sameorigin(entity e)
2504 e.movetype = MOVETYPE_NONE;
2507 entity gettaginfo_relative_ent;
2508 vector gettaginfo_relative(entity e, float tag)
2510 if (!gettaginfo_relative_ent)
2512 gettaginfo_relative_ent = spawn();
2513 gettaginfo_relative_ent.effects = EF_NODRAW;
2515 gettaginfo_relative_ent.model = e.model;
2516 gettaginfo_relative_ent.modelindex = e.modelindex;
2517 gettaginfo_relative_ent.frame = e.frame;
2518 return gettaginfo(gettaginfo_relative_ent, tag);
2523 float modeleffect_SendEntity(entity to, float sf)
2526 WriteByte(MSG_ENTITY, ENT_CLIENT_MODELEFFECT);
2529 if(self.velocity != '0 0 0')
2531 if(self.angles != '0 0 0')
2533 if(self.avelocity != '0 0 0')
2536 WriteByte(MSG_ENTITY, f);
2537 WriteShort(MSG_ENTITY, self.modelindex);
2538 WriteByte(MSG_ENTITY, self.skin);
2539 WriteByte(MSG_ENTITY, self.frame);
2540 WriteCoord(MSG_ENTITY, self.origin_x);
2541 WriteCoord(MSG_ENTITY, self.origin_y);
2542 WriteCoord(MSG_ENTITY, self.origin_z);
2545 WriteCoord(MSG_ENTITY, self.velocity_x);
2546 WriteCoord(MSG_ENTITY, self.velocity_y);
2547 WriteCoord(MSG_ENTITY, self.velocity_z);
2551 WriteCoord(MSG_ENTITY, self.angles_x);
2552 WriteCoord(MSG_ENTITY, self.angles_y);
2553 WriteCoord(MSG_ENTITY, self.angles_z);
2557 WriteCoord(MSG_ENTITY, self.avelocity_x);
2558 WriteCoord(MSG_ENTITY, self.avelocity_y);
2559 WriteCoord(MSG_ENTITY, self.avelocity_z);
2561 WriteShort(MSG_ENTITY, self.scale * 256.0);
2562 WriteShort(MSG_ENTITY, self.scale2 * 256.0);
2563 WriteByte(MSG_ENTITY, self.teleport_time * 100.0);
2564 WriteByte(MSG_ENTITY, self.fade_time * 100.0);
2565 WriteByte(MSG_ENTITY, self.alpha * 255.0);
2570 void modeleffect_spawn(string m, float s, float f, vector o, vector v, vector ang, vector angv, float s0, float s2, float a, float t1, float t2)
2575 e.classname = "modeleffect";
2583 e.teleport_time = t1;
2587 e.scale = s0 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2591 e.scale2 = s2 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2594 sz = max(e.scale, e.scale2);
2595 setsize(e, e.mins * sz, e.maxs * sz);
2596 Net_LinkEntity(e, FALSE, 0.1, modeleffect_SendEntity);
2599 void shockwave_spawn(string m, vector org, float sz, float t1, float t2)
2601 return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2);
2604 float randombit(float bits)
2606 if not(bits & (bits-1)) // this ONLY holds for powers of two!
2615 for(f = 1; f <= bits; f *= 2)
2624 r = (r - 1) / (n - 1);
2631 float randombits(float bits, float k, float error_return)
2635 while(k > 0 && bits != r)
2637 r += randombit(bits - r);
2646 void randombit_test(float bits, float iter)
2650 print(ftos(randombit(bits)), "\n");
2655 float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
2657 if(halflifedist > 0)
2658 return pow(0.5, (bound(mindist, d, maxdist) - mindist) / halflifedist);
2659 else if(halflifedist < 0)
2660 return pow(0.5, (bound(mindist, d, maxdist) - maxdist) / halflifedist);
2669 #define cvar_string_normal builtin_cvar_string
2670 #define cvar_normal builtin_cvar
2672 string cvar_string_normal(string n)
2674 if not(cvar_type(n) & 1)
2675 backtrace(strcat("Attempt to access undefined cvar: ", n));
2676 return builtin_cvar_string(n);
2679 float cvar_normal(string n)
2681 return stof(cvar_string_normal(n));
2684 #define cvar_set_normal builtin_cvar_set
2692 oself.think = SUB_Remove;
2693 oself.nextthink = time;
2699 Execute func() after time + fdelay.
2700 self when func is executed = self when defer is called
2702 void defer(float fdelay, void() func)
2709 e.think = defer_think;
2710 e.nextthink = time + fdelay;
2713 .string aiment_classname;
2714 .float aiment_deadflag;
2715 void SetMovetypeFollow(entity ent, entity e)
2717 // FIXME this may not be warpzone aware
2718 ent.movetype = MOVETYPE_FOLLOW; // make the hole follow
2719 ent.solid = SOLID_NOT; // MOVETYPE_FOLLOW is always non-solid - this means this cannot be teleported by warpzones any more! Instead, we must notice when our owner gets teleported.
2720 ent.aiment = e; // make the hole follow bmodel
2721 ent.punchangle = e.angles; // the original angles of bmodel
2722 ent.view_ofs = ent.origin - e.origin; // relative origin
2723 ent.v_angle = ent.angles - e.angles; // relative angles
2724 ent.aiment_classname = strzone(e.classname);
2725 ent.aiment_deadflag = e.deadflag;
2727 void UnsetMovetypeFollow(entity ent)
2729 ent.movetype = MOVETYPE_FLY;
2730 PROJECTILE_MAKETRIGGER(ent);
2733 float LostMovetypeFollow(entity ent)
2736 if(ent.movetype != MOVETYPE_FOLLOW)
2742 if(ent.aiment.classname != ent.aiment_classname)
2744 if(ent.aiment.deadflag != ent.aiment_deadflag)
2750 float isPushable(entity e)
2759 case "droppedweapon":
2760 case "keepawayball":
2761 case "nexball_basketball":
2762 case "nexball_football":
2764 case "bullet": // antilagged bullets can't hit this either
2767 if (e.projectiledeathtype)