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 #ifdef ALLOW_FORCEMODELS
580 GetCvars_handleFloat(s, f, cvar_cl_forceplayermodels, "cl_forceplayermodels");
581 GetCvars_handleFloat(s, f, cvar_cl_forceplayermodelsfromxonotic, "cl_forceplayermodelsfromxonotic");
583 GetCvars_handleFloatOnce(s, f, cvar_cl_gunalign, "cl_gunalign");
584 GetCvars_handleFloat(s, f, cvar_cl_allow_uid2name, "cl_allow_uid2name");
585 GetCvars_handleFloat(s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
586 GetCvars_handleFloat(s, f, cvar_cl_movement_track_canjump, "cl_movement_track_canjump");
587 GetCvars_handleFloat(s, f, cvar_cl_newusekeysupported, "cl_newusekeysupported");
589 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
592 if (s == "cl_weaponpriority")
593 self.switchweapon = w_getbestweapon(self);
594 if (s == "cl_allow_uidtracking")
595 PlayerStats_AddPlayer(self);
599 void backtrace(string msg)
602 dev = autocvar_developer;
603 war = autocvar_prvm_backtraceforwarnings;
604 cvar_set("developer", "1");
605 cvar_set("prvm_backtraceforwarnings", "1");
607 print("--- CUT HERE ---\nWARNING: ");
610 remove(world); // isn't there any better way to cause a backtrace?
611 print("\n--- CUT UNTIL HERE ---\n");
612 cvar_set("developer", ftos(dev));
613 cvar_set("prvm_backtraceforwarnings", ftos(war));
616 string Team_ColorCode(float teamid)
618 if (teamid == COLOR_TEAM1)
620 else if (teamid == COLOR_TEAM2)
622 else if (teamid == COLOR_TEAM3)
624 else if (teamid == COLOR_TEAM4)
630 string Team_ColorName(float t)
632 // fixme: Search for team entities and get their .netname's!
633 if (t == COLOR_TEAM1)
635 if (t == COLOR_TEAM2)
637 if (t == COLOR_TEAM3)
639 if (t == COLOR_TEAM4)
644 string Team_ColorNameLowerCase(float t)
646 // fixme: Search for team entities and get their .netname's!
647 if (t == COLOR_TEAM1)
649 if (t == COLOR_TEAM2)
651 if (t == COLOR_TEAM3)
653 if (t == COLOR_TEAM4)
658 float ColourToNumber(string team_colour)
660 if (team_colour == "red")
663 if (team_colour == "blue")
666 if (team_colour == "yellow")
669 if (team_colour == "pink")
672 if (team_colour == "auto")
678 float NumberToTeamNumber(float number)
695 // decolorizes and team colors the player name when needed
696 string playername(entity p)
699 if (teamplay && !intermission_running && p.classname == "player")
701 t = Team_ColorCode(p.team);
702 return strcat(t, strdecolorize(p.netname));
708 vector randompos(vector m1, vector m2)
712 v_x = m2_x * random() + m1_x;
713 v_y = m2_y * random() + m1_y;
714 v_z = m2_z * random() + m1_z;
718 //#NO AUTOCVARS START
720 float g_pickup_shells;
721 float g_pickup_shells_max;
722 float g_pickup_nails;
723 float g_pickup_nails_max;
724 float g_pickup_rockets;
725 float g_pickup_rockets_max;
726 float g_pickup_cells;
727 float g_pickup_cells_max;
729 float g_pickup_fuel_jetpack;
730 float g_pickup_fuel_max;
731 float g_pickup_armorsmall;
732 float g_pickup_armorsmall_max;
733 float g_pickup_armorsmall_anyway;
734 float g_pickup_armormedium;
735 float g_pickup_armormedium_max;
736 float g_pickup_armormedium_anyway;
737 float g_pickup_armorbig;
738 float g_pickup_armorbig_max;
739 float g_pickup_armorbig_anyway;
740 float g_pickup_armorlarge;
741 float g_pickup_armorlarge_max;
742 float g_pickup_armorlarge_anyway;
743 float g_pickup_healthsmall;
744 float g_pickup_healthsmall_max;
745 float g_pickup_healthsmall_anyway;
746 float g_pickup_healthmedium;
747 float g_pickup_healthmedium_max;
748 float g_pickup_healthmedium_anyway;
749 float g_pickup_healthlarge;
750 float g_pickup_healthlarge_max;
751 float g_pickup_healthlarge_anyway;
752 float g_pickup_healthmega;
753 float g_pickup_healthmega_max;
754 float g_pickup_healthmega_anyway;
755 float g_pickup_ammo_anyway;
756 float g_pickup_weapons_anyway;
758 WEPSET_DECLARE_A(g_weaponarena_weapons);
759 float g_weaponarena_random;
760 float g_weaponarena_random_with_laser;
761 string g_weaponarena_list;
762 float g_weaponspeedfactor;
763 float g_weaponratefactor;
764 float g_weapondamagefactor;
765 float g_weaponforcefactor;
766 float g_weaponspreadfactor;
768 WEPSET_DECLARE_A(start_weapons);
769 WEPSET_DECLARE_A(start_weapons_default);
770 WEPSET_DECLARE_A(start_weapons_defaultmask);
772 float start_ammo_shells;
773 float start_ammo_nails;
774 float start_ammo_rockets;
775 float start_ammo_cells;
776 float start_ammo_fuel;
778 float start_armorvalue;
779 WEPSET_DECLARE_A(warmup_start_weapons);
780 WEPSET_DECLARE_A(warmup_start_weapons_default);
781 WEPSET_DECLARE_A(warmup_start_weapons_defaultmask);
782 float warmup_start_ammo_shells;
783 float warmup_start_ammo_nails;
784 float warmup_start_ammo_rockets;
785 float warmup_start_ammo_cells;
786 float warmup_start_ammo_fuel;
787 float warmup_start_health;
788 float warmup_start_armorvalue;
791 entity get_weaponinfo(float w);
793 float want_weapon(string cvarprefix, entity weaponinfo, float allguns)
795 var float i = weaponinfo.weapon;
801 if (g_lms || g_ca || allguns)
803 if(weaponinfo.spawnflags & WEP_FLAG_NORMAL)
809 d = (i == WEP_SHOTGUN);
811 d = 0; // weapon is set a few lines later
813 d = (i == WEP_LASER || i == WEP_SHOTGUN);
815 if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
816 d |= (i == WEP_HOOK);
817 if(weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED) // never default mutator blocked guns
820 var float t = cvar(strcat(cvarprefix, weaponinfo.netname));
822 //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n"));
827 // 4: is set by default?
836 void readplayerstartcvars()
842 // initialize starting values for players
843 WEPSET_CLEAR_A(start_weapons);
844 WEPSET_CLEAR_A(start_weapons_default);
845 WEPSET_CLEAR_A(start_weapons_defaultmask);
847 start_ammo_shells = 0;
848 start_ammo_nails = 0;
849 start_ammo_rockets = 0;
850 start_ammo_cells = 0;
851 start_health = cvar("g_balance_health_start");
852 start_armorvalue = cvar("g_balance_armor_start");
855 WEPSET_CLEAR_A(g_weaponarena_weapons);
857 s = cvar_string("g_weaponarena");
858 if (s == "0" || s == "")
864 if (s == "0" || s == "")
870 // forcibly turn off weaponarena
875 g_weaponarena_list = "All Weapons";
876 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
878 e = get_weaponinfo(j);
879 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
880 WEPSET_OR_AW(g_weaponarena_weapons, j);
883 else if (s == "most")
886 g_weaponarena_list = "Most Weapons";
887 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
889 e = get_weaponinfo(j);
890 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
891 if (e.spawnflags & WEP_FLAG_NORMAL)
892 WEPSET_OR_AW(g_weaponarena_weapons, j);
895 else if (s == "none")
898 g_weaponarena_list = "No Weapons";
903 t = tokenize_console(s);
904 g_weaponarena_list = "";
905 for (i = 0; i < t; ++i)
908 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
910 e = get_weaponinfo(j);
913 WEPSET_OR_AW(g_weaponarena_weapons, j);
914 g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
920 print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
923 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
927 g_weaponarena_random = cvar("g_weaponarena_random");
929 g_weaponarena_random = 0;
930 g_weaponarena_random_with_laser = cvar("g_weaponarena_random_with_laser");
934 g_minstagib = 0; // incompatible
935 g_pinata = 0; // incompatible
936 g_weapon_stay = 0; // incompatible
937 WEPSET_COPY_AA(start_weapons, g_weaponarena_weapons);
939 start_items |= IT_UNLIMITED_AMMO;
941 else if (g_minstagib)
943 g_pinata = 0; // incompatible
944 g_weapon_stay = 0; // incompatible
945 g_bloodloss = 0; // incompatible
947 start_armorvalue = 0;
948 WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
949 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
950 start_items |= IT_UNLIMITED_SUPERWEAPONS;
952 if (g_minstagib_invis_alpha <= 0)
953 g_minstagib_invis_alpha = -1;
957 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
959 e = get_weaponinfo(i);
960 float w = want_weapon("g_start_weapon_", e, FALSE);
962 WEPSET_OR_AW(start_weapons, i);
964 WEPSET_OR_AW(start_weapons_default, i);
966 WEPSET_OR_AW(start_weapons_defaultmask, i);
970 if(!cvar("g_use_ammunition"))
971 start_items |= IT_UNLIMITED_AMMO;
973 if(cvar("g_nexball"))
974 start_items |= IT_UNLIMITED_SUPERWEAPONS; // FIXME BAD BAD BAD BAD HACK, NEXBALL SHOULDN'T ABUSE PORTO'S WEAPON SLOT
978 start_ammo_cells = cvar("g_minstagib_ammo_start");
979 start_ammo_fuel = cvar("g_start_ammo_fuel");
981 else if(start_items & IT_UNLIMITED_WEAPON_AMMO)
983 start_ammo_rockets = 999;
984 start_ammo_shells = 999;
985 start_ammo_cells = 999;
986 start_ammo_nails = 999;
987 start_ammo_fuel = 999;
993 start_ammo_shells = cvar("g_lms_start_ammo_shells");
994 start_ammo_nails = cvar("g_lms_start_ammo_nails");
995 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
996 start_ammo_cells = cvar("g_lms_start_ammo_cells");
997 start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
1001 start_ammo_shells = cvar("g_start_ammo_shells");
1002 start_ammo_nails = cvar("g_start_ammo_nails");
1003 start_ammo_rockets = cvar("g_start_ammo_rockets");
1004 start_ammo_cells = cvar("g_start_ammo_cells");
1005 start_ammo_fuel = cvar("g_start_ammo_fuel");
1011 start_health = cvar("g_lms_start_health");
1012 start_armorvalue = cvar("g_lms_start_armor");
1017 warmup_start_ammo_shells = start_ammo_shells;
1018 warmup_start_ammo_nails = start_ammo_nails;
1019 warmup_start_ammo_rockets = start_ammo_rockets;
1020 warmup_start_ammo_cells = start_ammo_cells;
1021 warmup_start_ammo_fuel = start_ammo_fuel;
1022 warmup_start_health = start_health;
1023 warmup_start_armorvalue = start_armorvalue;
1024 WEPSET_COPY_AA(warmup_start_weapons, start_weapons);
1025 WEPSET_COPY_AA(warmup_start_weapons_default, start_weapons_default);
1026 WEPSET_COPY_AA(warmup_start_weapons_defaultmask, start_weapons_defaultmask);
1028 if (!g_weaponarena && !g_minstagib && !g_ca)
1030 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
1031 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
1032 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
1033 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
1034 warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
1035 warmup_start_health = cvar("g_warmup_start_health");
1036 warmup_start_armorvalue = cvar("g_warmup_start_armor");
1037 WEPSET_CLEAR_A(warmup_start_weapons);
1038 WEPSET_CLEAR_A(warmup_start_weapons_default);
1039 WEPSET_CLEAR_A(warmup_start_weapons_defaultmask);
1040 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1042 e = get_weaponinfo(i);
1043 float w = want_weapon("g_start_weapon_", e, cvar("g_warmup_allguns"));
1045 WEPSET_OR_AW(warmup_start_weapons, i);
1047 WEPSET_OR_AW(warmup_start_weapons_default, i);
1049 WEPSET_OR_AW(warmup_start_weapons_defaultmask, i);
1055 start_items |= IT_JETPACK;
1057 MUTATOR_CALLHOOK(SetStartItems);
1059 if ((start_items & IT_JETPACK) || (g_grappling_hook && WEPSET_CONTAINS_AW(start_weapons, WEP_HOOK)))
1061 g_grappling_hook = 0; // these two can't coexist, as they use the same button
1062 start_items |= IT_FUEL_REGEN;
1063 start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1064 warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1067 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1069 e = get_weaponinfo(i);
1070 if(WEPSET_CONTAINS_AW(start_weapons, i) || WEPSET_CONTAINS_AW(warmup_start_weapons, i))
1071 weapon_action(i, WR_PRECACHE);
1074 start_ammo_shells = max(0, start_ammo_shells);
1075 start_ammo_nails = max(0, start_ammo_nails);
1076 start_ammo_cells = max(0, start_ammo_cells);
1077 start_ammo_rockets = max(0, start_ammo_rockets);
1078 start_ammo_fuel = max(0, start_ammo_fuel);
1080 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
1081 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
1082 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
1083 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
1084 warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
1088 float g_bugrigs_planar_movement;
1089 float g_bugrigs_planar_movement_car_jumping;
1090 float g_bugrigs_reverse_spinning;
1091 float g_bugrigs_reverse_speeding;
1092 float g_bugrigs_reverse_stopping;
1093 float g_bugrigs_air_steering;
1094 float g_bugrigs_angle_smoothing;
1095 float g_bugrigs_friction_floor;
1096 float g_bugrigs_friction_brake;
1097 float g_bugrigs_friction_air;
1098 float g_bugrigs_accel;
1099 float g_bugrigs_speed_ref;
1100 float g_bugrigs_speed_pow;
1101 float g_bugrigs_steer;
1103 float g_touchexplode;
1104 float g_touchexplode_radius;
1105 float g_touchexplode_damage;
1106 float g_touchexplode_edgedamage;
1107 float g_touchexplode_force;
1114 float sv_pitch_fixyaw;
1116 string GetGametype(); // g_world.qc
1117 void readlevelcvars(void)
1119 g_minstagib = cvar("g_minstagib");
1121 monster_skill = cvar("g_monsters_skill");
1123 // load ALL the mutators
1124 if(cvar("g_dodging"))
1125 MUTATOR_ADD(mutator_dodging);
1126 if(cvar("g_spawn_near_teammate"))
1127 MUTATOR_ADD(mutator_spawn_near_teammate);
1130 if(cvar("g_invincible_projectiles"))
1131 MUTATOR_ADD(mutator_invincibleprojectiles);
1132 if(cvar("g_new_toys"))
1133 MUTATOR_ADD(mutator_new_toys);
1135 MUTATOR_ADD(mutator_nix);
1136 if(cvar("g_rocket_flying"))
1137 MUTATOR_ADD(mutator_rocketflying);
1138 if(cvar("g_vampire"))
1139 MUTATOR_ADD(mutator_vampire);
1140 if(cvar("g_superspectate"))
1141 MUTATOR_ADD(mutator_superspec);
1144 // is this a mutator? is this a mode?
1145 if(cvar("g_sandbox"))
1146 MUTATOR_ADD(sandbox);
1149 MUTATOR_ADD(mutator_zombie_apocalypse);
1151 if(cvar("sv_allow_fullbright"))
1152 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
1154 g_bugrigs = cvar("g_bugrigs");
1155 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
1156 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
1157 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
1158 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
1159 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
1160 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
1161 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
1162 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
1163 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
1164 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
1165 g_bugrigs_accel = cvar("g_bugrigs_accel");
1166 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
1167 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
1168 g_bugrigs_steer = cvar("g_bugrigs_steer");
1170 g_touchexplode = cvar("g_touchexplode");
1171 g_touchexplode_radius = cvar("g_touchexplode_radius");
1172 g_touchexplode_damage = cvar("g_touchexplode_damage");
1173 g_touchexplode_edgedamage = cvar("g_touchexplode_edgedamage");
1174 g_touchexplode_force = cvar("g_touchexplode_force");
1176 #ifdef ALLOW_FORCEMODELS
1177 sv_clforceplayermodels = cvar("sv_clforceplayermodels");
1180 sv_clones = cvar("sv_clones");
1181 sv_gentle = cvar("sv_gentle");
1182 sv_foginterval = cvar("sv_foginterval");
1183 g_cloaked = cvar("g_cloaked");
1185 g_cloaked = 1; // always enable cloak in CTS
1186 g_jump_grunt = cvar("g_jump_grunt");
1187 g_footsteps = cvar("g_footsteps");
1188 g_grappling_hook = cvar("g_grappling_hook");
1189 g_jetpack = cvar("g_jetpack");
1190 g_midair = cvar("g_midair");
1191 g_norecoil = cvar("g_norecoil");
1192 g_bloodloss = cvar("g_bloodloss");
1193 sv_maxidle = cvar("sv_maxidle");
1194 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
1195 sv_autotaunt = cvar("sv_autotaunt");
1196 sv_taunt = cvar("sv_taunt");
1198 inWarmupStage = cvar("g_warmup");
1199 g_warmup_limit = cvar("g_warmup_limit");
1200 g_warmup_allguns = cvar("g_warmup_allguns");
1201 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
1203 if ((g_race && g_race_qualifying == 2) || g_runematch || g_arena || g_assault || cvar("g_campaign"))
1204 inWarmupStage = 0; // these modes cannot work together, sorry
1206 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
1207 g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
1208 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
1209 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
1210 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
1211 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
1212 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
1213 g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
1214 g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
1215 g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
1216 g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
1217 g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
1218 g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
1219 g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
1221 g_weaponspeedfactor = cvar("g_weaponspeedfactor");
1222 g_weaponratefactor = cvar("g_weaponratefactor");
1223 g_weapondamagefactor = cvar("g_weapondamagefactor");
1224 g_weaponforcefactor = cvar("g_weaponforcefactor");
1225 g_weaponspreadfactor = cvar("g_weaponspreadfactor");
1227 g_pickup_shells = cvar("g_pickup_shells");
1228 g_pickup_shells_max = cvar("g_pickup_shells_max");
1229 g_pickup_nails = cvar("g_pickup_nails");
1230 g_pickup_nails_max = cvar("g_pickup_nails_max");
1231 g_pickup_rockets = cvar("g_pickup_rockets");
1232 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
1233 g_pickup_cells = cvar("g_pickup_cells");
1234 g_pickup_cells_max = cvar("g_pickup_cells_max");
1235 g_pickup_fuel = cvar("g_pickup_fuel");
1236 g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
1237 g_pickup_fuel_max = cvar("g_pickup_fuel_max");
1238 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
1239 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
1240 g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
1241 g_pickup_armormedium = cvar("g_pickup_armormedium");
1242 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
1243 g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
1244 g_pickup_armorbig = cvar("g_pickup_armorbig");
1245 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
1246 g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
1247 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
1248 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
1249 g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
1250 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
1251 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
1252 g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
1253 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
1254 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
1255 g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
1256 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
1257 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
1258 g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
1259 g_pickup_healthmega = cvar("g_pickup_healthmega");
1260 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
1261 g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
1263 g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
1264 g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
1266 g_pinata = cvar("g_pinata");
1268 g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
1270 g_weapon_stay = cvar("g_weapon_stay");
1272 if not(inWarmupStage && !g_ca)
1273 game_starttime = cvar("g_start_delay");
1275 sv_pitch_min = cvar("sv_pitch_min");
1276 sv_pitch_max = cvar("sv_pitch_max");
1277 sv_pitch_fixyaw = cvar("sv_pitch_fixyaw");
1279 readplayerstartcvars();
1285 string precache_sound (string s) = #19;
1286 float precache_sound_index (string s) = #19;
1288 #define SND_VOLUME 1
1289 #define SND_ATTENUATION 2
1290 #define SND_LARGEENTITY 8
1291 #define SND_LARGESOUND 16
1293 float sound_allowed(float dest, entity e)
1295 // sounds from world may always pass
1298 if (e.classname == "body")
1300 else if (e.realowner && e.realowner != e)
1302 else if (e.owner && e.owner != e)
1307 // sounds to self may always pass
1308 if (dest == MSG_ONE)
1309 if (e == msg_entity)
1311 // sounds by players can be removed
1312 if (autocvar_bot_sound_monopoly)
1313 if (clienttype(e) == CLIENTTYPE_REAL)
1315 // anything else may pass
1319 #ifdef COMPAT_XON010_CHANNELS
1320 void(entity e, float chan, string samp, float vol, float atten) builtin_sound = #8;
1321 void sound(entity e, float chan, string samp, float vol, float atten)
1323 if (!sound_allowed(MSG_BROADCAST, e))
1325 builtin_sound(e, chan, samp, vol, atten);
1329 void sound(entity e, float chan, string samp, float vol, float atten)
1331 if (!sound_allowed(MSG_BROADCAST, e))
1333 sound7(e, chan, samp, vol, atten, 0, 0);
1337 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
1341 if (!sound_allowed(dest, e))
1344 entno = num_for_edict(e);
1345 idx = precache_sound_index(samp);
1350 atten = floor(atten * 64);
1351 vol = floor(vol * 255);
1354 sflags |= SND_VOLUME;
1356 sflags |= SND_ATTENUATION;
1357 if (entno >= 8192 || chan < 0 || chan > 7)
1358 sflags |= SND_LARGEENTITY;
1360 sflags |= SND_LARGESOUND;
1362 WriteByte(dest, SVC_SOUND);
1363 WriteByte(dest, sflags);
1364 if (sflags & SND_VOLUME)
1365 WriteByte(dest, vol);
1366 if (sflags & SND_ATTENUATION)
1367 WriteByte(dest, atten);
1368 if (sflags & SND_LARGEENTITY)
1370 WriteShort(dest, entno);
1371 WriteByte(dest, chan);
1375 WriteShort(dest, entno * 8 + chan);
1377 if (sflags & SND_LARGESOUND)
1378 WriteShort(dest, idx);
1380 WriteByte(dest, idx);
1382 WriteCoord(dest, o_x);
1383 WriteCoord(dest, o_y);
1384 WriteCoord(dest, o_z);
1386 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
1390 if (!sound_allowed(dest, e))
1393 o = e.origin + 0.5 * (e.mins + e.maxs);
1394 soundtoat(dest, e, o, chan, samp, vol, atten);
1396 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
1398 soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, atten);
1400 void stopsoundto(float dest, entity e, float chan)
1404 if (!sound_allowed(dest, e))
1407 entno = num_for_edict(e);
1409 if (entno >= 8192 || chan < 0 || chan > 7)
1412 idx = precache_sound_index("misc/null.wav");
1413 sflags = SND_LARGEENTITY;
1415 sflags |= SND_LARGESOUND;
1416 WriteByte(dest, SVC_SOUND);
1417 WriteByte(dest, sflags);
1418 WriteShort(dest, entno);
1419 WriteByte(dest, chan);
1420 if (sflags & SND_LARGESOUND)
1421 WriteShort(dest, idx);
1423 WriteByte(dest, idx);
1424 WriteCoord(dest, e.origin_x);
1425 WriteCoord(dest, e.origin_y);
1426 WriteCoord(dest, e.origin_z);
1430 WriteByte(dest, SVC_STOPSOUND);
1431 WriteShort(dest, entno * 8 + chan);
1434 void stopsound(entity e, float chan)
1436 if (!sound_allowed(MSG_BROADCAST, e))
1439 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
1440 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
1443 void play2(entity e, string filename)
1445 //stuffcmd(e, strcat("play2 ", filename, "\n"));
1447 soundtoat(MSG_ONE, world, '0 0 0', CH_INFO, filename, VOL_BASE, ATTN_NONE);
1450 // use this one if you might be causing spam (e.g. from touch functions that might get called more than once per frame)
1452 float spamsound(entity e, float chan, string samp, float vol, float atten)
1454 if (!sound_allowed(MSG_BROADCAST, e))
1457 if (time > e.spamtime)
1460 sound(e, chan, samp, vol, atten);
1466 void play2team(float t, string filename)
1470 if (autocvar_bot_sound_monopoly)
1473 FOR_EACH_REALPLAYER(head)
1476 play2(head, filename);
1480 void play2all(string samp)
1482 if (autocvar_bot_sound_monopoly)
1485 sound(world, CH_INFO, samp, VOL_BASE, ATTN_NONE);
1488 void PrecachePlayerSounds(string f);
1489 void precache_playermodel(string m)
1491 float globhandle, i, n;
1494 if(substring(m, -9,5) == "_lod1")
1496 if(substring(m, -9,5) == "_lod2")
1499 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
1502 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
1506 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
1509 n = search_getsize(globhandle);
1510 for (i = 0; i < n; ++i)
1512 //print(search_getfilename(globhandle, i), "\n");
1513 f = search_getfilename(globhandle, i);
1514 PrecachePlayerSounds(f);
1516 search_end(globhandle);
1518 void precache_all_playermodels(string pattern)
1520 float globhandle, i, n;
1523 globhandle = search_begin(pattern, TRUE, FALSE);
1526 n = search_getsize(globhandle);
1527 for (i = 0; i < n; ++i)
1529 //print(search_getfilename(globhandle, i), "\n");
1530 f = search_getfilename(globhandle, i);
1531 precache_playermodel(f);
1533 search_end(globhandle);
1538 // gamemode related things
1539 precache_model ("models/misc/chatbubble.spr");
1542 precache_model ("models/runematch/curse.mdl");
1543 precache_model ("models/runematch/rune.mdl");
1546 #ifdef TTURRETS_ENABLED
1547 if (autocvar_g_turrets)
1551 // Precache all player models if desired
1552 if (autocvar_sv_precacheplayermodels)
1554 PrecachePlayerSounds("sound/player/default.sounds");
1555 precache_all_playermodels("models/player/*.zym");
1556 precache_all_playermodels("models/player/*.dpm");
1557 precache_all_playermodels("models/player/*.md3");
1558 precache_all_playermodels("models/player/*.psk");
1559 precache_all_playermodels("models/player/*.iqm");
1562 if (autocvar_sv_defaultcharacter)
1565 s = autocvar_sv_defaultplayermodel_red;
1567 precache_playermodel(s);
1568 s = autocvar_sv_defaultplayermodel_blue;
1570 precache_playermodel(s);
1571 s = autocvar_sv_defaultplayermodel_yellow;
1573 precache_playermodel(s);
1574 s = autocvar_sv_defaultplayermodel_pink;
1576 precache_playermodel(s);
1577 s = autocvar_sv_defaultplayermodel;
1579 precache_playermodel(s);
1584 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1585 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1588 // gore and miscellaneous sounds
1589 //precache_sound ("misc/h2ohit.wav");
1590 precache_model ("models/hook.md3");
1591 precache_sound ("misc/armorimpact.wav");
1592 precache_sound ("misc/bodyimpact1.wav");
1593 precache_sound ("misc/bodyimpact2.wav");
1594 precache_sound ("misc/gib.wav");
1595 precache_sound ("misc/gib_splat01.wav");
1596 precache_sound ("misc/gib_splat02.wav");
1597 precache_sound ("misc/gib_splat03.wav");
1598 precache_sound ("misc/gib_splat04.wav");
1599 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1600 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1601 precache_sound ("misc/null.wav");
1602 precache_sound ("misc/spawn.wav");
1603 precache_sound ("misc/talk.wav");
1604 precache_sound ("misc/teleport.wav");
1605 precache_sound ("misc/poweroff.wav");
1606 precache_sound ("player/lava.wav");
1607 precache_sound ("player/slime.wav");
1609 precache_model ("models/sprites/0.spr32");
1610 precache_model ("models/sprites/1.spr32");
1611 precache_model ("models/sprites/2.spr32");
1612 precache_model ("models/sprites/3.spr32");
1613 precache_model ("models/sprites/4.spr32");
1614 precache_model ("models/sprites/5.spr32");
1615 precache_model ("models/sprites/6.spr32");
1616 precache_model ("models/sprites/7.spr32");
1617 precache_model ("models/sprites/8.spr32");
1618 precache_model ("models/sprites/9.spr32");
1619 precache_model ("models/sprites/10.spr32");
1621 // common weapon precaches
1622 precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound here
1623 precache_sound ("weapons/weapon_switch.wav");
1624 precache_sound ("weapons/weaponpickup.wav");
1625 precache_sound ("weapons/unavailable.wav");
1626 precache_sound ("weapons/dryfire.wav");
1627 if (g_grappling_hook)
1629 precache_sound ("weapons/hook_fire.wav"); // hook
1630 precache_sound ("weapons/hook_impact.wav"); // hook
1633 if(autocvar_sv_precacheweapons)
1635 //precache weapon models/sounds
1638 while (wep <= WEP_LAST)
1640 weapon_action(wep, WR_PRECACHE);
1645 precache_model("models/elaser.mdl");
1646 precache_model("models/laser.mdl");
1647 precache_model("models/ebomb.mdl");
1650 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
1652 if (!self.noise && self.music) // quake 3 uses the music field
1653 self.noise = self.music;
1655 // plays music for the level if there is any
1658 precache_sound (self.noise);
1659 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1664 // sorry, but using \ in macros breaks line numbers
1665 #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
1666 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1667 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1670 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
1672 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
1675 WRITESPECTATABLE_MSG_ONE({
1676 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1677 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
1678 WriteByte(MSG_ONE, id);
1679 WriteString(MSG_ONE, s);
1680 if (id != 0 && s != "")
1682 WriteByte(MSG_ONE, duration);
1683 WriteByte(MSG_ONE, countdown_num);
1688 void Send_CSQC_Centerprint_Generic_Expire(entity e, float id)
1690 Send_CSQC_Centerprint_Generic(e, id, "", 1, 0);
1692 // WARNING: this kills the trace globals
1693 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
1694 #define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init()
1696 #define INITPRIO_FIRST 0
1697 #define INITPRIO_GAMETYPE 0
1698 #define INITPRIO_GAMETYPE_FALLBACK 1
1699 #define INITPRIO_FINDTARGET 10
1700 #define INITPRIO_DROPTOFLOOR 20
1701 #define INITPRIO_SETLOCATION 90
1702 #define INITPRIO_LINKDOORS 91
1703 #define INITPRIO_LAST 99
1705 .void(void) initialize_entity;
1706 .float initialize_entity_order;
1707 .entity initialize_entity_next;
1708 entity initialize_entity_first;
1710 void make_safe_for_remove(entity e)
1712 if (e.initialize_entity)
1714 entity ent, prev = world;
1715 for (ent = initialize_entity_first; ent; )
1717 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1719 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1720 // skip it in linked list
1723 prev.initialize_entity_next = ent.initialize_entity_next;
1724 ent = prev.initialize_entity_next;
1728 initialize_entity_first = ent.initialize_entity_next;
1729 ent = initialize_entity_first;
1735 ent = ent.initialize_entity_next;
1741 void objerror(string s)
1743 make_safe_for_remove(self);
1744 builtin_objerror(s);
1747 .float remove_except_protected_forbidden;
1748 void remove_except_protected(entity e)
1750 if(e.remove_except_protected_forbidden)
1751 error("not allowed to remove this at this point");
1755 void remove_unsafely(entity e)
1757 if(e.classname == "spike")
1758 error("Removing spikes is forbidden (crylink bug), please report");
1762 void remove_safely(entity e)
1764 make_safe_for_remove(e);
1768 void InitializeEntity(entity e, void(void) func, float order)
1772 if (!e || e.initialize_entity)
1774 // make a proxy initializer entity
1778 e.classname = "initialize_entity";
1782 e.initialize_entity = func;
1783 e.initialize_entity_order = order;
1785 cur = initialize_entity_first;
1789 if (!cur || cur.initialize_entity_order > order)
1791 // insert between prev and cur
1793 prev.initialize_entity_next = e;
1795 initialize_entity_first = e;
1796 e.initialize_entity_next = cur;
1800 cur = cur.initialize_entity_next;
1803 void InitializeEntitiesRun()
1806 startoflist = initialize_entity_first;
1807 initialize_entity_first = world;
1808 remove = remove_except_protected;
1809 for (self = startoflist; self; self = self.initialize_entity_next)
1811 self.remove_except_protected_forbidden = 1;
1813 for (self = startoflist; self; )
1816 var void(void) func;
1817 e = self.initialize_entity_next;
1818 func = self.initialize_entity;
1819 self.initialize_entity_order = 0;
1820 self.initialize_entity = func_null;
1821 self.initialize_entity_next = world;
1822 self.remove_except_protected_forbidden = 0;
1823 if (self.classname == "initialize_entity")
1827 builtin_remove(self);
1830 //dprint("Delayed initialization: ", self.classname, "\n");
1836 backtrace(strcat("Null function in: ", self.classname, "\n"));
1840 remove = remove_unsafely;
1843 .float uncustomizeentityforclient_set;
1844 .void(void) uncustomizeentityforclient;
1845 void UncustomizeEntitiesRun()
1849 for (self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1850 self.uncustomizeentityforclient();
1853 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1855 e.customizeentityforclient = customizer;
1856 e.uncustomizeentityforclient = uncustomizer;
1857 e.uncustomizeentityforclient_set = !!uncustomizer;
1861 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1864 void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc)
1868 if (e.classname == "")
1869 e.classname = "net_linked";
1871 if (e.model == "" || self.modelindex == 0)
1875 setmodel(e, "null");
1879 e.SendEntity = sendfunc;
1880 e.SendFlags = 0xFFFFFF;
1883 e.effects |= EF_NODEPTHTEST;
1887 e.nextthink = time + dt;
1888 e.think = SUB_Remove;
1892 void adaptor_think2touch()
1901 void adaptor_think2use()
1913 void adaptor_think2use_hittype_splash() // for timed projectile detonation
1915 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
1916 self.projectiledeathtype |= HITTYPE_SPLASH;
1917 adaptor_think2use();
1920 // deferred dropping
1921 void DropToFloor_Handler()
1923 builtin_droptofloor();
1924 self.dropped_origin = self.origin;
1929 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1934 float trace_hits_box_a0, trace_hits_box_a1;
1936 float trace_hits_box_1d(float end, float thmi, float thma)
1940 // just check if x is in range
1948 // do the trace with respect to x
1949 // 0 -> end has to stay in thmi -> thma
1950 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1951 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1952 if (trace_hits_box_a0 > trace_hits_box_a1)
1958 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1963 // now it is a trace from 0 to end
1965 trace_hits_box_a0 = 0;
1966 trace_hits_box_a1 = 1;
1968 if (!trace_hits_box_1d(end_x, thmi_x, thma_x))
1970 if (!trace_hits_box_1d(end_y, thmi_y, thma_y))
1972 if (!trace_hits_box_1d(end_z, thmi_z, thma_z))
1978 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1980 return trace_hits_box(start, end, thmi - ma, thma - mi);
1983 float SUB_NoImpactCheck()
1985 // zero hitcontents = this is not the real impact, but either the
1986 // mirror-impact of something hitting the projectile instead of the
1987 // projectile hitting the something, or a touchareagrid one. Neither of
1988 // these stop the projectile from moving, so...
1989 if(trace_dphitcontents == 0)
1991 //dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
1992 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)));
1995 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1997 if (other == world && self.size != '0 0 0')
2000 tic = self.velocity * sys_frametime;
2001 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
2002 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
2003 if (trace_fraction >= 1)
2005 dprint("Odd... did not hit...?\n");
2007 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
2009 dprint("Detected and prevented the sky-grapple bug.\n");
2017 #define SUB_OwnerCheck() (other && (other == self.owner))
2019 void RemoveGrapplingHook(entity pl);
2020 void W_Crylink_Dequeue(entity e);
2021 float WarpZone_Projectile_Touch_ImpactFilter_Callback()
2023 if(SUB_OwnerCheck())
2025 if(SUB_NoImpactCheck())
2027 if(self.classname == "grapplinghook")
2028 RemoveGrapplingHook(self.realowner);
2029 else if(self.classname == "spike")
2031 W_Crylink_Dequeue(self);
2038 if(trace_ent && trace_ent.solid > SOLID_TRIGGER)
2039 UpdateCSQCProjectile(self);
2042 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
2044 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
2045 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER) || ((dt) == DEATH_SLIME) || ((dt) == DEATH_LAVA) || ((dt) == DEATH_SWAMP))
2047 void URI_Get_Callback(float id, float status, string data)
2049 if(url_URI_Get_Callback(id, status, data))
2053 else if (id == URI_GET_DISCARD)
2057 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
2060 Curl_URI_Get_Callback(id, status, data);
2062 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
2065 OnlineBanList_URI_Get_Callback(id, status, data);
2069 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
2073 string uid2name(string myuid) {
2075 s = db_get(ServerProgsDB, strcat("/uid2name/", myuid));
2077 // FIXME remove this later after 0.6 release
2078 // convert old style broken records to correct style
2081 s = db_get(ServerProgsDB, strcat("uid2name", myuid));
2084 db_put(ServerProgsDB, strcat("/uid2name/", myuid), s);
2085 db_put(ServerProgsDB, strcat("uid2name", myuid), "");
2090 s = "^1Unregistered Player";
2094 float race_readTime(string map, float pos)
2102 return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
2105 string race_readUID(string map, float pos)
2113 return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)));
2116 float race_readPos(string map, float t) {
2118 for (i = 1; i <= RANKINGS_CNT; ++i)
2119 if (race_readTime(map, i) == 0 || race_readTime(map, i) > t)
2122 return 0; // pos is zero if unranked
2125 void race_writeTime(string map, float t, string myuid)
2134 newpos = race_readPos(map, t);
2136 float i, prevpos = 0;
2137 for(i = 1; i <= RANKINGS_CNT; ++i)
2139 if(race_readUID(map, i) == myuid)
2142 if (prevpos) { // player improved his existing record, only have to iterate on ranks between new and old recs
2143 for (i = prevpos; i > newpos; --i) {
2144 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2145 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2147 } else { // player has no ranked record yet
2148 for (i = RANKINGS_CNT; i > newpos; --i) {
2149 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2150 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2154 // store new time itself
2155 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(newpos)), ftos(t));
2156 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(newpos)), myuid);
2159 string race_readName(string map, float pos)
2167 return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))));
2170 string race_placeName(float pos) {
2171 if(floor((mod(pos, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
2173 if(mod(pos, 10) == 1)
2174 return strcat(ftos(pos), "st");
2175 else if(mod(pos, 10) == 2)
2176 return strcat(ftos(pos), "nd");
2177 else if(mod(pos, 10) == 3)
2178 return strcat(ftos(pos), "rd");
2180 return strcat(ftos(pos), "th");
2183 return strcat(ftos(pos), "th");
2186 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
2189 vector start, org, delta, end, enddown, mstart;
2192 m = e.dphitcontentsmask;
2193 e.dphitcontentsmask = goodcontents | badcontents;
2196 delta = world.maxs - world.mins;
2200 for (i = 0; i < attempts; ++i)
2202 start_x = org_x + random() * delta_x;
2203 start_y = org_y + random() * delta_y;
2204 start_z = org_z + random() * delta_z;
2206 // rule 1: start inside world bounds, and outside
2207 // solid, and don't start from somewhere where you can
2208 // fall down to evil
2209 tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, e);
2210 if (trace_fraction >= 1)
2212 if (trace_startsolid)
2214 if (trace_dphitcontents & badcontents)
2216 if (trace_dphitq3surfaceflags & badsurfaceflags)
2219 // rule 2: if we are too high, lower the point
2220 if (trace_fraction * delta_z > maxaboveground)
2221 start = trace_endpos + '0 0 1' * maxaboveground;
2222 enddown = trace_endpos;
2224 // rule 3: make sure we aren't outside the map. This only works
2225 // for somewhat well formed maps. A good rule of thumb is that
2226 // the map should have a convex outside hull.
2227 // these can be traceLINES as we already verified the starting box
2228 mstart = start + 0.5 * (e.mins + e.maxs);
2229 traceline(mstart, mstart + '1 0 0' * delta_x, MOVE_NORMAL, e);
2230 if (trace_fraction >= 1)
2232 traceline(mstart, mstart - '1 0 0' * delta_x, MOVE_NORMAL, e);
2233 if (trace_fraction >= 1)
2235 traceline(mstart, mstart + '0 1 0' * delta_y, MOVE_NORMAL, e);
2236 if (trace_fraction >= 1)
2238 traceline(mstart, mstart - '0 1 0' * delta_y, MOVE_NORMAL, e);
2239 if (trace_fraction >= 1)
2241 traceline(mstart, mstart + '0 0 1' * delta_z, MOVE_NORMAL, e);
2242 if (trace_fraction >= 1)
2245 // rule 4: we must "see" some spawnpoint
2246 for(sp = world; (sp = find(sp, classname, "info_player_deathmatch")); )
2247 if(checkpvs(mstart, sp))
2251 for(sp = world; (sp = findflags(sp, flags, FL_ITEM)); )
2252 if(checkpvs(mstart, sp))
2258 // find a random vector to "look at"
2259 end_x = org_x + random() * delta_x;
2260 end_y = org_y + random() * delta_y;
2261 end_z = org_z + random() * delta_z;
2262 end = start + normalize(end - start) * vlen(delta);
2264 // rule 4: start TO end must not be too short
2265 tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
2266 if (trace_startsolid)
2268 if (trace_fraction < minviewdistance / vlen(delta))
2271 // rule 5: don't want to look at sky
2272 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
2275 // rule 6: we must not end up in trigger_hurt
2276 if (tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
2282 e.dphitcontentsmask = m;
2286 setorigin(e, start);
2287 e.angles = vectoangles(end - start);
2288 dprint("Needed ", ftos(i + 1), " attempts\n");
2295 float zcurveparticles_effectno;
2296 vector zcurveparticles_start;
2297 float zcurveparticles_spd;
2299 void endzcurveparticles()
2301 if(zcurveparticles_effectno)
2304 WriteShort(MSG_BROADCAST, zcurveparticles_spd | 0x8000);
2306 zcurveparticles_effectno = 0;
2309 void zcurveparticles(float effectno, vector start, vector end, float end_dz, float spd)
2311 spd = bound(0, floor(spd / 16), 32767);
2312 if(effectno != zcurveparticles_effectno || start != zcurveparticles_start)
2314 endzcurveparticles();
2315 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
2316 WriteByte(MSG_BROADCAST, TE_CSQC_ZCURVEPARTICLES);
2317 WriteShort(MSG_BROADCAST, effectno);
2318 WriteCoord(MSG_BROADCAST, start_x);
2319 WriteCoord(MSG_BROADCAST, start_y);
2320 WriteCoord(MSG_BROADCAST, start_z);
2321 zcurveparticles_effectno = effectno;
2322 zcurveparticles_start = start;
2325 WriteShort(MSG_BROADCAST, zcurveparticles_spd);
2326 WriteCoord(MSG_BROADCAST, end_x);
2327 WriteCoord(MSG_BROADCAST, end_y);
2328 WriteCoord(MSG_BROADCAST, end_z);
2329 WriteCoord(MSG_BROADCAST, end_dz);
2330 zcurveparticles_spd = spd;
2333 void zcurveparticles_from_tracetoss(float effectno, vector start, vector end, vector vel)
2336 vector vecxy, velxy;
2338 vecxy = end - start;
2343 if (vlen(velxy) < 0.000001 * fabs(vel_z))
2345 endzcurveparticles();
2346 trailparticles(world, effectno, start, end);
2350 end_dz = vlen(vecxy) / vlen(velxy) * vel_z - (end_z - start_z);
2351 zcurveparticles(effectno, start, end, end_dz, vlen(vel));
2354 void write_recordmarker(entity pl, float tstart, float dt)
2356 GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
2358 // also write a marker into demo files for demotc-race-record-extractor to find
2361 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
2362 " ", ftos(tstart), " ", ftos(dt), "\n"));
2365 vector shotorg_adjustfromclient(vector vecs, float y_is_right, float allowcenter, float algn)
2378 if(allowcenter) // 2: allow center handedness
2391 if(allowcenter) // 2: allow center handedness
2407 vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn)
2412 if (autocvar_g_shootfromeye)
2416 if (autocvar_g_shootfromclient) { vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn); }
2417 else { vecs_y = 0; vecs_z -= 2; }
2425 else if (autocvar_g_shootfromcenter)
2430 else if ((s = autocvar_g_shootfromfixedorigin) != "")
2440 else if (autocvar_g_shootfromclient)
2442 vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn);
2447 vector shotorg_adjust(vector vecs, float y_is_right, float visual)
2449 return shotorg_adjust_values(vecs, y_is_right, visual, self.owner.cvar_cl_gunalign);
2453 void attach_sameorigin(entity e, entity to, string tag)
2455 vector org, t_forward, t_left, t_up, e_forward, e_up;
2458 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2459 tagscale = pow(vlen(v_forward), -2); // undo a scale on the tag
2460 t_forward = v_forward * tagscale;
2461 t_left = v_right * -tagscale;
2462 t_up = v_up * tagscale;
2464 e.origin_x = org * t_forward;
2465 e.origin_y = org * t_left;
2466 e.origin_z = org * t_up;
2468 // current forward and up directions
2469 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2470 e.angles = AnglesTransform_FromVAngles(e.angles);
2472 e.angles = AnglesTransform_FromAngles(e.angles);
2473 fixedmakevectors(e.angles);
2475 // untransform forward, up!
2476 e_forward_x = v_forward * t_forward;
2477 e_forward_y = v_forward * t_left;
2478 e_forward_z = v_forward * t_up;
2479 e_up_x = v_up * t_forward;
2480 e_up_y = v_up * t_left;
2481 e_up_z = v_up * t_up;
2483 e.angles = fixedvectoangles2(e_forward, e_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, to, tag);
2490 setorigin(e, e.origin);
2493 void detach_sameorigin(entity e)
2496 org = gettaginfo(e, 0);
2497 e.angles = fixedvectoangles2(v_forward, v_up);
2498 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2499 e.angles = AnglesTransform_ToVAngles(e.angles);
2501 e.angles = AnglesTransform_ToAngles(e.angles);
2503 setattachment(e, world, "");
2504 setorigin(e, e.origin);
2507 void follow_sameorigin(entity e, entity to)
2509 e.movetype = MOVETYPE_FOLLOW; // make the hole follow
2510 e.aiment = to; // make the hole follow bmodel
2511 e.punchangle = to.angles; // the original angles of bmodel
2512 e.view_ofs = e.origin - to.origin; // relative origin
2513 e.v_angle = e.angles - to.angles; // relative angles
2516 void unfollow_sameorigin(entity e)
2518 e.movetype = MOVETYPE_NONE;
2521 entity gettaginfo_relative_ent;
2522 vector gettaginfo_relative(entity e, float tag)
2524 if (!gettaginfo_relative_ent)
2526 gettaginfo_relative_ent = spawn();
2527 gettaginfo_relative_ent.effects = EF_NODRAW;
2529 gettaginfo_relative_ent.model = e.model;
2530 gettaginfo_relative_ent.modelindex = e.modelindex;
2531 gettaginfo_relative_ent.frame = e.frame;
2532 return gettaginfo(gettaginfo_relative_ent, tag);
2537 float modeleffect_SendEntity(entity to, float sf)
2540 WriteByte(MSG_ENTITY, ENT_CLIENT_MODELEFFECT);
2543 if(self.velocity != '0 0 0')
2545 if(self.angles != '0 0 0')
2547 if(self.avelocity != '0 0 0')
2550 WriteByte(MSG_ENTITY, f);
2551 WriteShort(MSG_ENTITY, self.modelindex);
2552 WriteByte(MSG_ENTITY, self.skin);
2553 WriteByte(MSG_ENTITY, self.frame);
2554 WriteCoord(MSG_ENTITY, self.origin_x);
2555 WriteCoord(MSG_ENTITY, self.origin_y);
2556 WriteCoord(MSG_ENTITY, self.origin_z);
2559 WriteCoord(MSG_ENTITY, self.velocity_x);
2560 WriteCoord(MSG_ENTITY, self.velocity_y);
2561 WriteCoord(MSG_ENTITY, self.velocity_z);
2565 WriteCoord(MSG_ENTITY, self.angles_x);
2566 WriteCoord(MSG_ENTITY, self.angles_y);
2567 WriteCoord(MSG_ENTITY, self.angles_z);
2571 WriteCoord(MSG_ENTITY, self.avelocity_x);
2572 WriteCoord(MSG_ENTITY, self.avelocity_y);
2573 WriteCoord(MSG_ENTITY, self.avelocity_z);
2575 WriteShort(MSG_ENTITY, self.scale * 256.0);
2576 WriteShort(MSG_ENTITY, self.scale2 * 256.0);
2577 WriteByte(MSG_ENTITY, self.teleport_time * 100.0);
2578 WriteByte(MSG_ENTITY, self.fade_time * 100.0);
2579 WriteByte(MSG_ENTITY, self.alpha * 255.0);
2584 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)
2589 e.classname = "modeleffect";
2597 e.teleport_time = t1;
2601 e.scale = s0 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2605 e.scale2 = s2 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2608 sz = max(e.scale, e.scale2);
2609 setsize(e, e.mins * sz, e.maxs * sz);
2610 Net_LinkEntity(e, FALSE, 0.1, modeleffect_SendEntity);
2613 void shockwave_spawn(string m, vector org, float sz, float t1, float t2)
2615 return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2);
2618 float randombit(float bits)
2620 if not(bits & (bits-1)) // this ONLY holds for powers of two!
2629 for(f = 1; f <= bits; f *= 2)
2638 r = (r - 1) / (n - 1);
2645 float randombits(float bits, float k, float error_return)
2649 while(k > 0 && bits != r)
2651 r += randombit(bits - r);
2660 void randombit_test(float bits, float iter)
2664 print(ftos(randombit(bits)), "\n");
2669 float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
2671 if(halflifedist > 0)
2672 return pow(0.5, (bound(mindist, d, maxdist) - mindist) / halflifedist);
2673 else if(halflifedist < 0)
2674 return pow(0.5, (bound(mindist, d, maxdist) - maxdist) / halflifedist);
2683 #define cvar_string_normal builtin_cvar_string
2684 #define cvar_normal builtin_cvar
2686 string cvar_string_normal(string n)
2688 if not(cvar_type(n) & 1)
2689 backtrace(strcat("Attempt to access undefined cvar: ", n));
2690 return builtin_cvar_string(n);
2693 float cvar_normal(string n)
2695 return stof(cvar_string_normal(n));
2698 #define cvar_set_normal builtin_cvar_set
2706 oself.think = SUB_Remove;
2707 oself.nextthink = time;
2713 Execute func() after time + fdelay.
2714 self when func is executed = self when defer is called
2716 void defer(float fdelay, void() func)
2723 e.think = defer_think;
2724 e.nextthink = time + fdelay;
2727 .string aiment_classname;
2728 .float aiment_deadflag;
2729 void SetMovetypeFollow(entity ent, entity e)
2731 // FIXME this may not be warpzone aware
2732 ent.movetype = MOVETYPE_FOLLOW; // make the hole follow
2733 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.
2734 ent.aiment = e; // make the hole follow bmodel
2735 ent.punchangle = e.angles; // the original angles of bmodel
2736 ent.view_ofs = ent.origin - e.origin; // relative origin
2737 ent.v_angle = ent.angles - e.angles; // relative angles
2738 ent.aiment_classname = strzone(e.classname);
2739 ent.aiment_deadflag = e.deadflag;
2741 void UnsetMovetypeFollow(entity ent)
2743 ent.movetype = MOVETYPE_FLY;
2744 PROJECTILE_MAKETRIGGER(ent);
2747 float LostMovetypeFollow(entity ent)
2750 if(ent.movetype != MOVETYPE_FOLLOW)
2756 if(ent.aiment.classname != ent.aiment_classname)
2758 if(ent.aiment.deadflag != ent.aiment_deadflag)
2764 float isPushable(entity e)
2773 case "droppedweapon":
2774 case "keepawayball":
2775 case "nexball_basketball":
2776 case "nexball_football":
2778 case "bullet": // antilagged bullets can't hit this either
2781 if (e.projectiledeathtype)