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)
94 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
95 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
96 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
97 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
98 #define FOR_EACH_SPEC(v) FOR_EACH_CLIENT(v) if(v.classname != STR_PLAYER)
99 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
102 #define CENTER_OR_VIEWOFS(ent) (ent.origin + ((ent.classname == STR_PLAYER) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
104 // copies a string to a tempstring (so one can strunzone it)
105 string strcat1(string s) = #115; // FRIK_FILE
110 void bcenterprint(string s)
112 // TODO replace by MSG_ALL (would show it to spectators too, though)?
114 FOR_EACH_PLAYER(head)
115 if (clienttype(head) == CLIENTTYPE_REAL)
116 centerprint(head, s);
119 void GameLogEcho(string s)
124 if (autocvar_sv_eventlog_files)
129 matches = autocvar_sv_eventlog_files_counter + 1;
130 cvar_set("sv_eventlog_files_counter", ftos(matches));
133 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
134 fn = strcat(autocvar_sv_eventlog_files_nameprefix, fn, autocvar_sv_eventlog_files_namesuffix);
135 logfile = fopen(fn, FILE_APPEND);
136 fputs(logfile, ":logversion:3\n");
140 if (autocvar_sv_eventlog_files_timestamps)
141 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
143 fputs(logfile, strcat(s, "\n"));
146 if (autocvar_sv_eventlog_console)
155 // will be opened later
160 if (logfile_open && logfile >= 0)
167 float spawnpoint_nag;
168 void relocate_spawnpoint()
170 // nudge off the floor
171 setorigin(self, self.origin + '0 0 1');
173 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
174 if (trace_startsolid)
180 if (!move_out_of_solid(self))
181 objerror("could not get out of solid at all!");
182 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
183 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
184 print(" ", ftos(self.origin_y - o_y));
185 print(" ", ftos(self.origin_z - o_z), "'\n");
186 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
189 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
195 self.mins = self.maxs = '0 0 0';
196 objerror("player spawn point in solid, mapper sucks!\n");
201 self.use = spawnpoint_use;
202 self.team_saved = self.team;
206 if (have_team_spawns != 0)
208 have_team_spawns = 1;
209 have_team_spawns_forteam[self.team] = 1;
211 if (autocvar_r_showbboxes)
213 // show where spawnpoints point at too
214 makevectors(self.angles);
217 e.classname = "info_player_foo";
218 setorigin(e, self.origin + v_forward * 24);
219 setsize(e, '-8 -8 -8', '8 8 8');
220 e.solid = SOLID_TRIGGER;
224 #define strstr strstrofs
226 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
227 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
228 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
229 // BE CONSTANT OR strzoneD!
230 float strstr(string haystack, string needle, float offset)
234 len = strlen(needle);
235 endpos = strlen(haystack) - len;
236 while(offset <= endpos)
238 found = substring(haystack, offset, len);
247 float NUM_NEAREST_ENTITIES = 4;
248 entity nearest_entity[NUM_NEAREST_ENTITIES];
249 float nearest_length[NUM_NEAREST_ENTITIES];
250 entity findnearest(vector point, .string field, string value, vector axismod)
261 localhead = find(world, field, value);
264 if ((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
265 dist = localhead.oldorigin;
267 dist = localhead.origin;
269 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
272 for (i = 0; i < num_nearest; ++i)
274 if (len < nearest_length[i])
278 // now i tells us where to insert at
279 // INSERTION SORT! YOU'VE SEEN IT! RUN!
280 if (i < NUM_NEAREST_ENTITIES)
282 for (j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
284 nearest_length[j + 1] = nearest_length[j];
285 nearest_entity[j + 1] = nearest_entity[j];
287 nearest_length[i] = len;
288 nearest_entity[i] = localhead;
289 if (num_nearest < NUM_NEAREST_ENTITIES)
290 num_nearest = num_nearest + 1;
293 localhead = find(localhead, field, value);
296 // now use the first one from our list that we can see
297 for (i = 0; i < num_nearest; ++i)
299 traceline(point, nearest_entity[i].origin, TRUE, world);
300 if (trace_fraction == 1)
304 dprint("Nearest point (");
305 dprint(nearest_entity[0].netname);
306 dprint(") is not visible, using a visible one.\n");
308 return nearest_entity[i];
312 if (num_nearest == 0)
315 dprint("Not seeing any location point, using nearest as fallback.\n");
317 dprint("Candidates were: ");
318 for(j = 0; j < num_nearest; ++j)
322 dprint(nearest_entity[j].netname);
327 return nearest_entity[0];
330 void spawnfunc_target_location()
332 self.classname = "target_location";
333 // location name in netname
334 // eventually support: count, teamgame selectors, line of sight?
337 void spawnfunc_info_location()
339 self.classname = "target_location";
340 self.message = self.netname;
343 string NearestLocation(vector p)
348 loc = findnearest(p, classname, "target_location", '1 1 1');
355 loc = findnearest(p, target, "###item###", '1 1 4');
362 string formatmessage(string msg)
373 WarpZone_crosshair_trace(self);
374 cursor = trace_endpos;
375 cursor_ent = trace_ent;
379 break; // too many replacements
382 p1 = strstr(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
383 p2 = strstr(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
396 replacement = substring(msg, p, 2);
397 escape = substring(msg, p + 1, 1);
401 else if (escape == "\\")
403 else if (escape == "n")
405 else if (escape == "a")
406 replacement = ftos(floor(self.armorvalue));
407 else if (escape == "h")
408 replacement = ftos(floor(self.health));
409 else if (escape == "l")
410 replacement = NearestLocation(self.origin);
411 else if (escape == "y")
412 replacement = NearestLocation(cursor);
413 else if (escape == "d")
414 replacement = NearestLocation(self.death_origin);
415 else if (escape == "w") {
419 wep = self.switchweapon;
422 replacement = W_Name(wep);
423 } else if (escape == "W") {
424 if (self.items & IT_SHELLS) replacement = "shells";
425 else if (self.items & IT_NAILS) replacement = "bullets";
426 else if (self.items & IT_ROCKETS) replacement = "rockets";
427 else if (self.items & IT_CELLS) replacement = "cells";
428 else replacement = "batteries"; // ;)
429 } else if (escape == "x") {
430 replacement = cursor_ent.netname;
431 if (replacement == "" || !cursor_ent)
432 replacement = "nothing";
433 } else if (escape == "s")
434 replacement = ftos(vlen(self.velocity - self.velocity_z * '0 0 1'));
435 else if (escape == "S")
436 replacement = ftos(vlen(self.velocity));
438 msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
439 p = p + strlen(replacement);
444 float boolean(float value) { // if value is 0 return FALSE (0), otherwise return TRUE (1)
445 return (value == 0) ? FALSE : TRUE;
454 >0: receives a cvar from name=argv(f) value=argv(f+1)
456 void GetCvars_handleString(string thisname, float f, .string field, string name)
461 strunzone(self.field);
462 self.field = string_null;
466 if (thisname == name)
469 strunzone(self.field);
470 self.field = strzone(argv(f + 1));
474 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
476 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
478 GetCvars_handleString(thisname, f, field, name);
479 if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
480 if (thisname == name)
483 s = func(strcat1(self.field));
486 strunzone(self.field);
487 self.field = strzone(s);
491 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
498 if (thisname == name)
499 self.field = stof(argv(f + 1));
502 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
504 void GetCvars_handleFloatOnce(string thisname, float f, .float field, string name)
511 if (thisname == name)
515 self.field = stof(argv(f + 1));
524 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
527 float w_getbestweapon(entity e);
528 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(string wo)
531 o = W_FixWeaponOrder_ForceComplete(wo);
532 if(self.weaponorder_byimpulse)
534 strunzone(self.weaponorder_byimpulse);
535 self.weaponorder_byimpulse = string_null;
537 self.weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(o));
540 void GetCvars(float f)
542 string s = string_null;
545 s = strcat1(argv(f));
549 MUTATOR_CALLHOOK(GetCvars);
550 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
551 GetCvars_handleFloat(s, f, cvar_cl_autoscreenshot, "cl_autoscreenshot");
552 GetCvars_handleString(s, f, cvar_g_xonoticversion, "g_xonoticversion");
553 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
554 GetCvars_handleFloat(s, f, cvar_cl_clippedspectating, "cl_clippedspectating");
555 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
556 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
557 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
558 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
559 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
560 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
561 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
562 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
563 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
564 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
565 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
566 GetCvars_handleFloat(s, f, cvar_cl_weaponimpulsemode, "cl_weaponimpulsemode");
567 GetCvars_handleFloat(s, f, cvar_cl_autotaunt, "cl_autotaunt");
568 GetCvars_handleFloat(s, f, cvar_cl_noantilag, "cl_noantilag");
569 GetCvars_handleFloat(s, f, cvar_cl_voice_directional, "cl_voice_directional");
570 GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation");
571 GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_share, "cl_accuracy_data_share");
572 GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_receive, "cl_accuracy_data_receive");
574 self.cvar_cl_accuracy_data_share = boolean(self.cvar_cl_accuracy_data_share);
575 self.cvar_cl_accuracy_data_receive = boolean(self.cvar_cl_accuracy_data_receive);
577 #ifdef ALLOW_FORCEMODELS
578 GetCvars_handleFloat(s, f, cvar_cl_forceplayermodels, "cl_forceplayermodels");
579 GetCvars_handleFloat(s, f, cvar_cl_forceplayermodelsfromxonotic, "cl_forceplayermodelsfromxonotic");
581 GetCvars_handleFloatOnce(s, f, cvar_cl_gunalign, "cl_gunalign");
582 GetCvars_handleFloat(s, f, cvar_cl_allow_uid2name, "cl_allow_uid2name");
583 GetCvars_handleFloat(s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
584 GetCvars_handleFloat(s, f, cvar_cl_movement_track_canjump, "cl_movement_track_canjump");
585 GetCvars_handleFloat(s, f, cvar_cl_newusekeysupported, "cl_newusekeysupported");
587 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
590 if (s == "cl_weaponpriority")
591 self.switchweapon = w_getbestweapon(self);
592 if (s == "cl_allow_uidtracking")
593 PlayerStats_AddPlayer(self);
597 void backtrace(string msg)
600 dev = autocvar_developer;
601 war = autocvar_prvm_backtraceforwarnings;
602 cvar_set("developer", "1");
603 cvar_set("prvm_backtraceforwarnings", "1");
605 print("--- CUT HERE ---\nWARNING: ");
608 remove(world); // isn't there any better way to cause a backtrace?
609 print("\n--- CUT UNTIL HERE ---\n");
610 cvar_set("developer", ftos(dev));
611 cvar_set("prvm_backtraceforwarnings", ftos(war));
614 string Team_ColorCode(float teamid)
616 if (teamid == COLOR_TEAM1)
618 else if (teamid == COLOR_TEAM2)
620 else if (teamid == COLOR_TEAM3)
622 else if (teamid == COLOR_TEAM4)
628 string Team_ColorName(float t)
630 // fixme: Search for team entities and get their .netname's!
631 if (t == COLOR_TEAM1)
633 if (t == COLOR_TEAM2)
635 if (t == COLOR_TEAM3)
637 if (t == COLOR_TEAM4)
642 string Team_ColorNameLowerCase(float t)
644 // fixme: Search for team entities and get their .netname's!
645 if (t == COLOR_TEAM1)
647 if (t == COLOR_TEAM2)
649 if (t == COLOR_TEAM3)
651 if (t == COLOR_TEAM4)
656 float ColourToNumber(string team_colour)
658 if (team_colour == "red")
661 if (team_colour == "blue")
664 if (team_colour == "yellow")
667 if (team_colour == "pink")
670 if (team_colour == "auto")
676 float NumberToTeamNumber(float number)
693 // decolorizes and team colors the player name when needed
694 string playername(entity p)
697 if (teamplay && !intermission_running && p.classname == "player")
699 t = Team_ColorCode(p.team);
700 return strcat(t, strdecolorize(p.netname));
706 vector randompos(vector m1, vector m2)
710 v_x = m2_x * random() + m1_x;
711 v_y = m2_y * random() + m1_y;
712 v_z = m2_z * random() + m1_z;
716 //#NO AUTOCVARS START
718 float g_pickup_shells;
719 float g_pickup_shells_max;
720 float g_pickup_nails;
721 float g_pickup_nails_max;
722 float g_pickup_rockets;
723 float g_pickup_rockets_max;
724 float g_pickup_cells;
725 float g_pickup_cells_max;
727 float g_pickup_fuel_jetpack;
728 float g_pickup_fuel_max;
729 float g_pickup_armorsmall;
730 float g_pickup_armorsmall_max;
731 float g_pickup_armorsmall_anyway;
732 float g_pickup_armormedium;
733 float g_pickup_armormedium_max;
734 float g_pickup_armormedium_anyway;
735 float g_pickup_armorbig;
736 float g_pickup_armorbig_max;
737 float g_pickup_armorbig_anyway;
738 float g_pickup_armorlarge;
739 float g_pickup_armorlarge_max;
740 float g_pickup_armorlarge_anyway;
741 float g_pickup_healthsmall;
742 float g_pickup_healthsmall_max;
743 float g_pickup_healthsmall_anyway;
744 float g_pickup_healthmedium;
745 float g_pickup_healthmedium_max;
746 float g_pickup_healthmedium_anyway;
747 float g_pickup_healthlarge;
748 float g_pickup_healthlarge_max;
749 float g_pickup_healthlarge_anyway;
750 float g_pickup_healthmega;
751 float g_pickup_healthmega_max;
752 float g_pickup_healthmega_anyway;
753 float g_pickup_ammo_anyway;
754 float g_pickup_weapons_anyway;
756 WEPSET_DECLARE_A(g_weaponarena_weapons);
757 float g_weaponarena_random;
758 float g_weaponarena_random_with_laser;
759 string g_weaponarena_list;
760 float g_weaponspeedfactor;
761 float g_weaponratefactor;
762 float g_weapondamagefactor;
763 float g_weaponforcefactor;
764 float g_weaponspreadfactor;
766 WEPSET_DECLARE_A(start_weapons);
767 WEPSET_DECLARE_A(start_weapons_default);
768 WEPSET_DECLARE_A(start_weapons_defaultmask);
770 float start_ammo_shells;
771 float start_ammo_nails;
772 float start_ammo_rockets;
773 float start_ammo_cells;
774 float start_ammo_fuel;
776 float start_armorvalue;
777 WEPSET_DECLARE_A(warmup_start_weapons);
778 WEPSET_DECLARE_A(warmup_start_weapons_default);
779 WEPSET_DECLARE_A(warmup_start_weapons_defaultmask);
780 float warmup_start_ammo_shells;
781 float warmup_start_ammo_nails;
782 float warmup_start_ammo_rockets;
783 float warmup_start_ammo_cells;
784 float warmup_start_ammo_fuel;
785 float warmup_start_health;
786 float warmup_start_armorvalue;
789 entity get_weaponinfo(float w);
791 float want_weapon(string cvarprefix, entity weaponinfo, float allguns)
793 var float i = weaponinfo.weapon;
799 if (g_lms || g_ca || allguns)
801 if(weaponinfo.spawnflags & WEP_FLAG_NORMAL)
807 d = (i == WEP_SHOTGUN);
809 d = 0; // weapon is set a few lines later
811 d = (i == WEP_LASER || i == WEP_SHOTGUN);
813 if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
814 d |= (i == WEP_HOOK);
815 if(weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED) // never default mutator blocked guns
818 var float t = cvar(strcat(cvarprefix, weaponinfo.netname));
820 //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n"));
825 // 4: is set by default?
834 void readplayerstartcvars()
840 // initialize starting values for players
841 WEPSET_CLEAR_A(start_weapons);
842 WEPSET_CLEAR_A(start_weapons_default);
843 WEPSET_CLEAR_A(start_weapons_defaultmask);
845 start_ammo_shells = 0;
846 start_ammo_nails = 0;
847 start_ammo_rockets = 0;
848 start_ammo_cells = 0;
849 start_health = cvar("g_balance_health_start");
850 start_armorvalue = cvar("g_balance_armor_start");
853 WEPSET_CLEAR_A(g_weaponarena_weapons);
855 s = cvar_string("g_weaponarena");
856 if (s == "0" || s == "")
862 if (s == "0" || s == "")
868 // forcibly turn off weaponarena
873 g_weaponarena_list = "All Weapons";
874 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
876 e = get_weaponinfo(j);
877 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
878 WEPSET_OR_AW(g_weaponarena_weapons, j);
881 else if (s == "most")
884 g_weaponarena_list = "Most Weapons";
885 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
887 e = get_weaponinfo(j);
888 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
889 if (e.spawnflags & WEP_FLAG_NORMAL)
890 WEPSET_OR_AW(g_weaponarena_weapons, j);
893 else if (s == "none")
896 g_weaponarena_list = "No Weapons";
901 t = tokenize_console(s);
902 g_weaponarena_list = "";
903 for (i = 0; i < t; ++i)
906 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
908 e = get_weaponinfo(j);
911 WEPSET_OR_AW(g_weaponarena_weapons, j);
912 g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
918 print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
921 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
925 g_weaponarena_random = cvar("g_weaponarena_random");
927 g_weaponarena_random = 0;
928 g_weaponarena_random_with_laser = cvar("g_weaponarena_random_with_laser");
932 g_minstagib = 0; // incompatible
933 g_pinata = 0; // incompatible
934 g_weapon_stay = 0; // incompatible
935 WEPSET_COPY_AA(start_weapons, g_weaponarena_weapons);
937 start_items |= IT_UNLIMITED_AMMO;
939 else if (g_minstagib)
941 g_pinata = 0; // incompatible
942 g_weapon_stay = 0; // incompatible
943 g_bloodloss = 0; // incompatible
945 start_armorvalue = 0;
946 WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
947 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
948 start_items |= IT_UNLIMITED_SUPERWEAPONS;
950 if (g_minstagib_invis_alpha <= 0)
951 g_minstagib_invis_alpha = -1;
955 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
957 e = get_weaponinfo(i);
958 float w = want_weapon("g_start_weapon_", e, FALSE);
960 WEPSET_OR_AW(start_weapons, i);
962 WEPSET_OR_AW(start_weapons_default, i);
964 WEPSET_OR_AW(start_weapons_defaultmask, i);
968 if(!cvar("g_use_ammunition"))
969 start_items |= IT_UNLIMITED_AMMO;
971 if(cvar("g_nexball"))
972 start_items |= IT_UNLIMITED_SUPERWEAPONS; // FIXME BAD BAD BAD BAD HACK, NEXBALL SHOULDN'T ABUSE PORTO'S WEAPON SLOT
976 start_ammo_cells = cvar("g_minstagib_ammo_start");
977 start_ammo_fuel = cvar("g_start_ammo_fuel");
979 else if(start_items & IT_UNLIMITED_WEAPON_AMMO)
981 start_ammo_rockets = 999;
982 start_ammo_shells = 999;
983 start_ammo_cells = 999;
984 start_ammo_nails = 999;
985 start_ammo_fuel = 999;
991 start_ammo_shells = cvar("g_lms_start_ammo_shells");
992 start_ammo_nails = cvar("g_lms_start_ammo_nails");
993 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
994 start_ammo_cells = cvar("g_lms_start_ammo_cells");
995 start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
999 start_ammo_shells = cvar("g_start_ammo_shells");
1000 start_ammo_nails = cvar("g_start_ammo_nails");
1001 start_ammo_rockets = cvar("g_start_ammo_rockets");
1002 start_ammo_cells = cvar("g_start_ammo_cells");
1003 start_ammo_fuel = cvar("g_start_ammo_fuel");
1009 start_health = cvar("g_lms_start_health");
1010 start_armorvalue = cvar("g_lms_start_armor");
1015 warmup_start_ammo_shells = start_ammo_shells;
1016 warmup_start_ammo_nails = start_ammo_nails;
1017 warmup_start_ammo_rockets = start_ammo_rockets;
1018 warmup_start_ammo_cells = start_ammo_cells;
1019 warmup_start_ammo_fuel = start_ammo_fuel;
1020 warmup_start_health = start_health;
1021 warmup_start_armorvalue = start_armorvalue;
1022 WEPSET_COPY_AA(warmup_start_weapons, start_weapons);
1023 WEPSET_COPY_AA(warmup_start_weapons_default, start_weapons_default);
1024 WEPSET_COPY_AA(warmup_start_weapons_defaultmask, start_weapons_defaultmask);
1026 if (!g_weaponarena && !g_minstagib && !g_ca)
1028 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
1029 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
1030 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
1031 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
1032 warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
1033 warmup_start_health = cvar("g_warmup_start_health");
1034 warmup_start_armorvalue = cvar("g_warmup_start_armor");
1035 WEPSET_CLEAR_A(warmup_start_weapons);
1036 WEPSET_CLEAR_A(warmup_start_weapons_default);
1037 WEPSET_CLEAR_A(warmup_start_weapons_defaultmask);
1038 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1040 e = get_weaponinfo(i);
1041 float w = want_weapon("g_start_weapon_", e, cvar("g_warmup_allguns"));
1043 WEPSET_OR_AW(warmup_start_weapons, i);
1045 WEPSET_OR_AW(warmup_start_weapons_default, i);
1047 WEPSET_OR_AW(warmup_start_weapons_defaultmask, i);
1053 start_items |= IT_JETPACK;
1055 MUTATOR_CALLHOOK(SetStartItems);
1057 if ((start_items & IT_JETPACK) || (g_grappling_hook && WEPSET_CONTAINS_AW(start_weapons, WEP_HOOK)))
1059 g_grappling_hook = 0; // these two can't coexist, as they use the same button
1060 start_items |= IT_FUEL_REGEN;
1061 start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1062 warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1065 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1067 e = get_weaponinfo(i);
1068 if(WEPSET_CONTAINS_AW(start_weapons, i) || WEPSET_CONTAINS_AW(warmup_start_weapons, i))
1069 weapon_action(i, WR_PRECACHE);
1072 start_ammo_shells = max(0, start_ammo_shells);
1073 start_ammo_nails = max(0, start_ammo_nails);
1074 start_ammo_cells = max(0, start_ammo_cells);
1075 start_ammo_rockets = max(0, start_ammo_rockets);
1076 start_ammo_fuel = max(0, start_ammo_fuel);
1078 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
1079 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
1080 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
1081 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
1082 warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
1086 float g_bugrigs_planar_movement;
1087 float g_bugrigs_planar_movement_car_jumping;
1088 float g_bugrigs_reverse_spinning;
1089 float g_bugrigs_reverse_speeding;
1090 float g_bugrigs_reverse_stopping;
1091 float g_bugrigs_air_steering;
1092 float g_bugrigs_angle_smoothing;
1093 float g_bugrigs_friction_floor;
1094 float g_bugrigs_friction_brake;
1095 float g_bugrigs_friction_air;
1096 float g_bugrigs_accel;
1097 float g_bugrigs_speed_ref;
1098 float g_bugrigs_speed_pow;
1099 float g_bugrigs_steer;
1101 float g_touchexplode;
1102 float g_touchexplode_radius;
1103 float g_touchexplode_damage;
1104 float g_touchexplode_edgedamage;
1105 float g_touchexplode_force;
1110 string GetGametype(); // g_world.qc
1111 void readlevelcvars(void)
1113 g_minstagib = cvar("g_minstagib");
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);
1142 if(cvar("sv_allow_fullbright"))
1143 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
1145 g_bugrigs = cvar("g_bugrigs");
1146 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
1147 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
1148 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
1149 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
1150 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
1151 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
1152 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
1153 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
1154 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
1155 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
1156 g_bugrigs_accel = cvar("g_bugrigs_accel");
1157 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
1158 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
1159 g_bugrigs_steer = cvar("g_bugrigs_steer");
1161 g_touchexplode = cvar("g_touchexplode");
1162 g_touchexplode_radius = cvar("g_touchexplode_radius");
1163 g_touchexplode_damage = cvar("g_touchexplode_damage");
1164 g_touchexplode_edgedamage = cvar("g_touchexplode_edgedamage");
1165 g_touchexplode_force = cvar("g_touchexplode_force");
1167 #ifdef ALLOW_FORCEMODELS
1168 sv_clforceplayermodels = cvar("sv_clforceplayermodels");
1171 sv_clones = cvar("sv_clones");
1172 sv_gentle = cvar("sv_gentle");
1173 sv_foginterval = cvar("sv_foginterval");
1174 g_cloaked = cvar("g_cloaked");
1176 g_cloaked = 1; // always enable cloak in CTS
1177 g_jump_grunt = cvar("g_jump_grunt");
1178 g_footsteps = cvar("g_footsteps");
1179 g_grappling_hook = cvar("g_grappling_hook");
1180 g_jetpack = cvar("g_jetpack");
1181 g_midair = cvar("g_midair");
1182 g_norecoil = cvar("g_norecoil");
1183 g_bloodloss = cvar("g_bloodloss");
1184 sv_maxidle = cvar("sv_maxidle");
1185 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
1186 sv_autotaunt = cvar("sv_autotaunt");
1187 sv_taunt = cvar("sv_taunt");
1189 inWarmupStage = cvar("g_warmup");
1190 g_warmup_limit = cvar("g_warmup_limit");
1191 g_warmup_allguns = cvar("g_warmup_allguns");
1192 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
1194 if ((g_race && g_race_qualifying == 2) || g_runematch || g_arena || g_assault || cvar("g_campaign"))
1195 inWarmupStage = 0; // these modes cannot work together, sorry
1197 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
1198 g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
1199 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
1200 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
1201 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
1202 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
1203 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
1204 g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
1205 g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
1206 g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
1207 g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
1208 g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
1209 g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
1210 g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
1212 g_weaponspeedfactor = cvar("g_weaponspeedfactor");
1213 g_weaponratefactor = cvar("g_weaponratefactor");
1214 g_weapondamagefactor = cvar("g_weapondamagefactor");
1215 g_weaponforcefactor = cvar("g_weaponforcefactor");
1216 g_weaponspreadfactor = cvar("g_weaponspreadfactor");
1218 g_pickup_shells = cvar("g_pickup_shells");
1219 g_pickup_shells_max = cvar("g_pickup_shells_max");
1220 g_pickup_nails = cvar("g_pickup_nails");
1221 g_pickup_nails_max = cvar("g_pickup_nails_max");
1222 g_pickup_rockets = cvar("g_pickup_rockets");
1223 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
1224 g_pickup_cells = cvar("g_pickup_cells");
1225 g_pickup_cells_max = cvar("g_pickup_cells_max");
1226 g_pickup_fuel = cvar("g_pickup_fuel");
1227 g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
1228 g_pickup_fuel_max = cvar("g_pickup_fuel_max");
1229 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
1230 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
1231 g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
1232 g_pickup_armormedium = cvar("g_pickup_armormedium");
1233 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
1234 g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
1235 g_pickup_armorbig = cvar("g_pickup_armorbig");
1236 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
1237 g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
1238 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
1239 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
1240 g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
1241 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
1242 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
1243 g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
1244 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
1245 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
1246 g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
1247 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
1248 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
1249 g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
1250 g_pickup_healthmega = cvar("g_pickup_healthmega");
1251 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
1252 g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
1254 g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
1255 g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
1257 g_pinata = cvar("g_pinata");
1259 g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
1261 g_weapon_stay = cvar("g_weapon_stay");
1263 if not(inWarmupStage && !g_ca)
1264 game_starttime = cvar("g_start_delay");
1266 readplayerstartcvars();
1272 string precache_sound (string s) = #19;
1273 float precache_sound_index (string s) = #19;
1275 #define SND_VOLUME 1
1276 #define SND_ATTENUATION 2
1277 #define SND_LARGEENTITY 8
1278 #define SND_LARGESOUND 16
1280 float sound_allowed(float dest, entity e)
1282 // sounds from world may always pass
1285 if (e.classname == "body")
1287 else if (e.realowner && e.realowner != e)
1289 else if (e.owner && e.owner != e)
1294 // sounds to self may always pass
1295 if (dest == MSG_ONE)
1296 if (e == msg_entity)
1298 // sounds by players can be removed
1299 if (autocvar_bot_sound_monopoly)
1300 if (clienttype(e) == CLIENTTYPE_REAL)
1302 // anything else may pass
1306 #ifdef COMPAT_XON010_CHANNELS
1307 void(entity e, float chan, string samp, float vol, float atten) builtin_sound = #8;
1308 void sound(entity e, float chan, string samp, float vol, float atten)
1310 if (!sound_allowed(MSG_BROADCAST, e))
1312 builtin_sound(e, chan, samp, vol, atten);
1316 void sound(entity e, float chan, string samp, float vol, float atten)
1318 if (!sound_allowed(MSG_BROADCAST, e))
1320 sound7(e, chan, samp, vol, atten, 0, 0);
1324 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
1328 if (!sound_allowed(dest, e))
1331 entno = num_for_edict(e);
1332 idx = precache_sound_index(samp);
1337 atten = floor(atten * 64);
1338 vol = floor(vol * 255);
1341 sflags |= SND_VOLUME;
1343 sflags |= SND_ATTENUATION;
1344 if (entno >= 8192 || chan < 0 || chan > 7)
1345 sflags |= SND_LARGEENTITY;
1347 sflags |= SND_LARGESOUND;
1349 WriteByte(dest, SVC_SOUND);
1350 WriteByte(dest, sflags);
1351 if (sflags & SND_VOLUME)
1352 WriteByte(dest, vol);
1353 if (sflags & SND_ATTENUATION)
1354 WriteByte(dest, atten);
1355 if (sflags & SND_LARGEENTITY)
1357 WriteShort(dest, entno);
1358 WriteByte(dest, chan);
1362 WriteShort(dest, entno * 8 + chan);
1364 if (sflags & SND_LARGESOUND)
1365 WriteShort(dest, idx);
1367 WriteByte(dest, idx);
1369 WriteCoord(dest, o_x);
1370 WriteCoord(dest, o_y);
1371 WriteCoord(dest, o_z);
1373 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
1377 if (!sound_allowed(dest, e))
1380 o = e.origin + 0.5 * (e.mins + e.maxs);
1381 soundtoat(dest, e, o, chan, samp, vol, atten);
1383 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
1385 soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, atten);
1387 void stopsoundto(float dest, entity e, float chan)
1391 if (!sound_allowed(dest, e))
1394 entno = num_for_edict(e);
1396 if (entno >= 8192 || chan < 0 || chan > 7)
1399 idx = precache_sound_index("misc/null.wav");
1400 sflags = SND_LARGEENTITY;
1402 sflags |= SND_LARGESOUND;
1403 WriteByte(dest, SVC_SOUND);
1404 WriteByte(dest, sflags);
1405 WriteShort(dest, entno);
1406 WriteByte(dest, chan);
1407 if (sflags & SND_LARGESOUND)
1408 WriteShort(dest, idx);
1410 WriteByte(dest, idx);
1411 WriteCoord(dest, e.origin_x);
1412 WriteCoord(dest, e.origin_y);
1413 WriteCoord(dest, e.origin_z);
1417 WriteByte(dest, SVC_STOPSOUND);
1418 WriteShort(dest, entno * 8 + chan);
1421 void stopsound(entity e, float chan)
1423 if (!sound_allowed(MSG_BROADCAST, e))
1426 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
1427 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
1430 void play2(entity e, string filename)
1432 //stuffcmd(e, strcat("play2 ", filename, "\n"));
1434 soundtoat(MSG_ONE, world, '0 0 0', CH_INFO, filename, VOL_BASE, ATTN_NONE);
1437 // use this one if you might be causing spam (e.g. from touch functions that might get called more than once per frame)
1439 float spamsound(entity e, float chan, string samp, float vol, float atten)
1441 if (!sound_allowed(MSG_BROADCAST, e))
1444 if (time > e.spamtime)
1447 sound(e, chan, samp, vol, atten);
1453 void play2team(float t, string filename)
1457 if (autocvar_bot_sound_monopoly)
1460 FOR_EACH_REALPLAYER(head)
1463 play2(head, filename);
1467 void play2all(string samp)
1469 if (autocvar_bot_sound_monopoly)
1472 sound(world, CH_INFO, samp, VOL_BASE, ATTN_NONE);
1475 void PrecachePlayerSounds(string f);
1476 void precache_playermodel(string m)
1478 float globhandle, i, n;
1481 if(substring(m, -9,5) == "_lod1")
1483 if(substring(m, -9,5) == "_lod2")
1486 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
1489 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
1493 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
1496 n = search_getsize(globhandle);
1497 for (i = 0; i < n; ++i)
1499 //print(search_getfilename(globhandle, i), "\n");
1500 f = search_getfilename(globhandle, i);
1501 PrecachePlayerSounds(f);
1503 search_end(globhandle);
1505 void precache_all_playermodels(string pattern)
1507 float globhandle, i, n;
1510 globhandle = search_begin(pattern, TRUE, FALSE);
1513 n = search_getsize(globhandle);
1514 for (i = 0; i < n; ++i)
1516 //print(search_getfilename(globhandle, i), "\n");
1517 f = search_getfilename(globhandle, i);
1518 precache_playermodel(f);
1520 search_end(globhandle);
1525 // gamemode related things
1526 precache_model ("models/misc/chatbubble.spr");
1529 precache_model ("models/runematch/curse.mdl");
1530 precache_model ("models/runematch/rune.mdl");
1533 #ifdef TTURRETS_ENABLED
1534 if (autocvar_g_turrets)
1538 // Precache all player models if desired
1539 if (autocvar_sv_precacheplayermodels)
1541 PrecachePlayerSounds("sound/player/default.sounds");
1542 precache_all_playermodels("models/player/*.zym");
1543 precache_all_playermodels("models/player/*.dpm");
1544 precache_all_playermodels("models/player/*.md3");
1545 precache_all_playermodels("models/player/*.psk");
1546 precache_all_playermodels("models/player/*.iqm");
1549 if (autocvar_sv_defaultcharacter)
1552 s = autocvar_sv_defaultplayermodel_red;
1554 precache_playermodel(s);
1555 s = autocvar_sv_defaultplayermodel_blue;
1557 precache_playermodel(s);
1558 s = autocvar_sv_defaultplayermodel_yellow;
1560 precache_playermodel(s);
1561 s = autocvar_sv_defaultplayermodel_pink;
1563 precache_playermodel(s);
1564 s = autocvar_sv_defaultplayermodel;
1566 precache_playermodel(s);
1571 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1572 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1575 // gore and miscellaneous sounds
1576 //precache_sound ("misc/h2ohit.wav");
1577 precache_model ("models/hook.md3");
1578 precache_sound ("misc/armorimpact.wav");
1579 precache_sound ("misc/bodyimpact1.wav");
1580 precache_sound ("misc/bodyimpact2.wav");
1581 precache_sound ("misc/gib.wav");
1582 precache_sound ("misc/gib_splat01.wav");
1583 precache_sound ("misc/gib_splat02.wav");
1584 precache_sound ("misc/gib_splat03.wav");
1585 precache_sound ("misc/gib_splat04.wav");
1586 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1587 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1588 precache_sound ("misc/null.wav");
1589 precache_sound ("misc/spawn.wav");
1590 precache_sound ("misc/talk.wav");
1591 precache_sound ("misc/teleport.wav");
1592 precache_sound ("misc/poweroff.wav");
1593 precache_sound ("player/lava.wav");
1594 precache_sound ("player/slime.wav");
1596 precache_model ("models/sprites/0.spr32");
1597 precache_model ("models/sprites/1.spr32");
1598 precache_model ("models/sprites/2.spr32");
1599 precache_model ("models/sprites/3.spr32");
1600 precache_model ("models/sprites/4.spr32");
1601 precache_model ("models/sprites/5.spr32");
1602 precache_model ("models/sprites/6.spr32");
1603 precache_model ("models/sprites/7.spr32");
1604 precache_model ("models/sprites/8.spr32");
1605 precache_model ("models/sprites/9.spr32");
1606 precache_model ("models/sprites/10.spr32");
1608 // common weapon precaches
1609 precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound here
1610 precache_sound ("weapons/weapon_switch.wav");
1611 precache_sound ("weapons/weaponpickup.wav");
1612 precache_sound ("weapons/unavailable.wav");
1613 precache_sound ("weapons/dryfire.wav");
1614 if (g_grappling_hook)
1616 precache_sound ("weapons/hook_fire.wav"); // hook
1617 precache_sound ("weapons/hook_impact.wav"); // hook
1620 if(autocvar_sv_precacheweapons)
1622 //precache weapon models/sounds
1625 while (wep <= WEP_LAST)
1627 weapon_action(wep, WR_PRECACHE);
1632 precache_model("models/elaser.mdl");
1633 precache_model("models/laser.mdl");
1634 precache_model("models/ebomb.mdl");
1637 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
1639 if (!self.noise && self.music) // quake 3 uses the music field
1640 self.noise = self.music;
1642 // plays music for the level if there is any
1645 precache_sound (self.noise);
1646 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1651 // sorry, but using \ in macros breaks line numbers
1652 #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
1653 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1654 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1657 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
1659 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
1662 WRITESPECTATABLE_MSG_ONE({
1663 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1664 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
1665 WriteByte(MSG_ONE, id);
1666 WriteString(MSG_ONE, s);
1667 if (id != 0 && s != "")
1669 WriteByte(MSG_ONE, duration);
1670 WriteByte(MSG_ONE, countdown_num);
1675 void Send_CSQC_Centerprint_Generic_Expire(entity e, float id)
1677 Send_CSQC_Centerprint_Generic(e, id, "", 1, 0);
1679 // WARNING: this kills the trace globals
1680 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
1681 #define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init()
1683 #define INITPRIO_FIRST 0
1684 #define INITPRIO_GAMETYPE 0
1685 #define INITPRIO_GAMETYPE_FALLBACK 1
1686 #define INITPRIO_FINDTARGET 10
1687 #define INITPRIO_DROPTOFLOOR 20
1688 #define INITPRIO_SETLOCATION 90
1689 #define INITPRIO_LINKDOORS 91
1690 #define INITPRIO_LAST 99
1692 .void(void) initialize_entity;
1693 .float initialize_entity_order;
1694 .entity initialize_entity_next;
1695 entity initialize_entity_first;
1697 void make_safe_for_remove(entity e)
1699 if (e.initialize_entity)
1701 entity ent, prev = world;
1702 for (ent = initialize_entity_first; ent; )
1704 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1706 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1707 // skip it in linked list
1710 prev.initialize_entity_next = ent.initialize_entity_next;
1711 ent = prev.initialize_entity_next;
1715 initialize_entity_first = ent.initialize_entity_next;
1716 ent = initialize_entity_first;
1722 ent = ent.initialize_entity_next;
1728 void objerror(string s)
1730 make_safe_for_remove(self);
1731 builtin_objerror(s);
1734 .float remove_except_protected_forbidden;
1735 void remove_except_protected(entity e)
1737 if(e.remove_except_protected_forbidden)
1738 error("not allowed to remove this at this point");
1742 void remove_unsafely(entity e)
1744 if(e.classname == "spike")
1745 error("Removing spikes is forbidden (crylink bug), please report");
1749 void remove_safely(entity e)
1751 make_safe_for_remove(e);
1755 void InitializeEntity(entity e, void(void) func, float order)
1759 if (!e || e.initialize_entity)
1761 // make a proxy initializer entity
1765 e.classname = "initialize_entity";
1769 e.initialize_entity = func;
1770 e.initialize_entity_order = order;
1772 cur = initialize_entity_first;
1776 if (!cur || cur.initialize_entity_order > order)
1778 // insert between prev and cur
1780 prev.initialize_entity_next = e;
1782 initialize_entity_first = e;
1783 e.initialize_entity_next = cur;
1787 cur = cur.initialize_entity_next;
1790 void InitializeEntitiesRun()
1793 startoflist = initialize_entity_first;
1794 initialize_entity_first = world;
1795 remove = remove_except_protected;
1796 for (self = startoflist; self; self = self.initialize_entity_next)
1798 self.remove_except_protected_forbidden = 1;
1800 for (self = startoflist; self; )
1803 var void(void) func;
1804 e = self.initialize_entity_next;
1805 func = self.initialize_entity;
1806 self.initialize_entity_order = 0;
1807 self.initialize_entity = func_null;
1808 self.initialize_entity_next = world;
1809 self.remove_except_protected_forbidden = 0;
1810 if (self.classname == "initialize_entity")
1814 builtin_remove(self);
1817 //dprint("Delayed initialization: ", self.classname, "\n");
1823 backtrace(strcat("Null function in: ", self.classname, "\n"));
1827 remove = remove_unsafely;
1830 .float uncustomizeentityforclient_set;
1831 .void(void) uncustomizeentityforclient;
1832 void UncustomizeEntitiesRun()
1836 for (self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1837 self.uncustomizeentityforclient();
1840 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1842 e.customizeentityforclient = customizer;
1843 e.uncustomizeentityforclient = uncustomizer;
1844 e.uncustomizeentityforclient_set = !!uncustomizer;
1848 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1851 void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc)
1855 if (e.classname == "")
1856 e.classname = "net_linked";
1858 if (e.model == "" || self.modelindex == 0)
1862 setmodel(e, "null");
1866 e.SendEntity = sendfunc;
1867 e.SendFlags = 0xFFFFFF;
1870 e.effects |= EF_NODEPTHTEST;
1874 e.nextthink = time + dt;
1875 e.think = SUB_Remove;
1879 void adaptor_think2touch()
1888 void adaptor_think2use()
1900 void adaptor_think2use_hittype_splash() // for timed projectile detonation
1902 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
1903 self.projectiledeathtype |= HITTYPE_SPLASH;
1904 adaptor_think2use();
1907 // deferred dropping
1908 void DropToFloor_Handler()
1910 builtin_droptofloor();
1911 self.dropped_origin = self.origin;
1916 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1921 float trace_hits_box_a0, trace_hits_box_a1;
1923 float trace_hits_box_1d(float end, float thmi, float thma)
1927 // just check if x is in range
1935 // do the trace with respect to x
1936 // 0 -> end has to stay in thmi -> thma
1937 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1938 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1939 if (trace_hits_box_a0 > trace_hits_box_a1)
1945 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1950 // now it is a trace from 0 to end
1952 trace_hits_box_a0 = 0;
1953 trace_hits_box_a1 = 1;
1955 if (!trace_hits_box_1d(end_x, thmi_x, thma_x))
1957 if (!trace_hits_box_1d(end_y, thmi_y, thma_y))
1959 if (!trace_hits_box_1d(end_z, thmi_z, thma_z))
1965 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1967 return trace_hits_box(start, end, thmi - ma, thma - mi);
1970 float SUB_NoImpactCheck()
1972 // zero hitcontents = this is not the real impact, but either the
1973 // mirror-impact of something hitting the projectile instead of the
1974 // projectile hitting the something, or a touchareagrid one. Neither of
1975 // these stop the projectile from moving, so...
1976 if(trace_dphitcontents == 0)
1978 //dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
1979 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)));
1982 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1984 if (other == world && self.size != '0 0 0')
1987 tic = self.velocity * sys_frametime;
1988 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
1989 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
1990 if (trace_fraction >= 1)
1992 dprint("Odd... did not hit...?\n");
1994 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1996 dprint("Detected and prevented the sky-grapple bug.\n");
2004 #define SUB_OwnerCheck() (other && (other == self.owner))
2006 void RemoveGrapplingHook(entity pl);
2007 void W_Crylink_Dequeue(entity e);
2008 float WarpZone_Projectile_Touch_ImpactFilter_Callback()
2010 if(SUB_OwnerCheck())
2012 if(SUB_NoImpactCheck())
2014 if(self.classname == "grapplinghook")
2015 RemoveGrapplingHook(self.realowner);
2016 else if(self.classname == "spike")
2018 W_Crylink_Dequeue(self);
2025 if(trace_ent && trace_ent.solid > SOLID_TRIGGER)
2026 UpdateCSQCProjectile(self);
2029 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
2031 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
2032 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER) || ((dt) == DEATH_SLIME) || ((dt) == DEATH_LAVA) || ((dt) == DEATH_SWAMP))
2034 void URI_Get_Callback(float id, float status, string data)
2036 if(url_URI_Get_Callback(id, status, data))
2040 else if (id == URI_GET_DISCARD)
2044 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
2047 Curl_URI_Get_Callback(id, status, data);
2049 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
2052 OnlineBanList_URI_Get_Callback(id, status, data);
2056 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
2060 string uid2name(string myuid) {
2062 s = db_get(ServerProgsDB, strcat("/uid2name/", myuid));
2064 // FIXME remove this later after 0.6 release
2065 // convert old style broken records to correct style
2068 s = db_get(ServerProgsDB, strcat("uid2name", myuid));
2071 db_put(ServerProgsDB, strcat("/uid2name/", myuid), s);
2072 db_put(ServerProgsDB, strcat("uid2name", myuid), "");
2077 s = "^1Unregistered Player";
2081 float race_readTime(string map, float pos)
2089 return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
2092 string race_readUID(string map, float pos)
2100 return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)));
2103 float race_readPos(string map, float t) {
2105 for (i = 1; i <= RANKINGS_CNT; ++i)
2106 if (race_readTime(map, i) == 0 || race_readTime(map, i) > t)
2109 return 0; // pos is zero if unranked
2112 void race_writeTime(string map, float t, string myuid)
2121 newpos = race_readPos(map, t);
2123 float i, prevpos = 0;
2124 for(i = 1; i <= RANKINGS_CNT; ++i)
2126 if(race_readUID(map, i) == myuid)
2129 if (prevpos) { // player improved his existing record, only have to iterate on ranks between new and old recs
2130 for (i = prevpos; i > newpos; --i) {
2131 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2132 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2134 } else { // player has no ranked record yet
2135 for (i = RANKINGS_CNT; i > newpos; --i) {
2136 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2137 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2141 // store new time itself
2142 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(newpos)), ftos(t));
2143 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(newpos)), myuid);
2146 string race_readName(string map, float pos)
2154 return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))));
2157 string race_placeName(float pos) {
2158 if(floor((mod(pos, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
2160 if(mod(pos, 10) == 1)
2161 return strcat(ftos(pos), "st");
2162 else if(mod(pos, 10) == 2)
2163 return strcat(ftos(pos), "nd");
2164 else if(mod(pos, 10) == 3)
2165 return strcat(ftos(pos), "rd");
2167 return strcat(ftos(pos), "th");
2170 return strcat(ftos(pos), "th");
2173 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
2176 vector start, org, delta, end, enddown, mstart;
2179 m = e.dphitcontentsmask;
2180 e.dphitcontentsmask = goodcontents | badcontents;
2183 delta = world.maxs - world.mins;
2187 for (i = 0; i < attempts; ++i)
2189 start_x = org_x + random() * delta_x;
2190 start_y = org_y + random() * delta_y;
2191 start_z = org_z + random() * delta_z;
2193 // rule 1: start inside world bounds, and outside
2194 // solid, and don't start from somewhere where you can
2195 // fall down to evil
2196 tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, e);
2197 if (trace_fraction >= 1)
2199 if (trace_startsolid)
2201 if (trace_dphitcontents & badcontents)
2203 if (trace_dphitq3surfaceflags & badsurfaceflags)
2206 // rule 2: if we are too high, lower the point
2207 if (trace_fraction * delta_z > maxaboveground)
2208 start = trace_endpos + '0 0 1' * maxaboveground;
2209 enddown = trace_endpos;
2211 // rule 3: make sure we aren't outside the map. This only works
2212 // for somewhat well formed maps. A good rule of thumb is that
2213 // the map should have a convex outside hull.
2214 // these can be traceLINES as we already verified the starting box
2215 mstart = start + 0.5 * (e.mins + e.maxs);
2216 traceline(mstart, mstart + '1 0 0' * delta_x, MOVE_NORMAL, e);
2217 if (trace_fraction >= 1)
2219 traceline(mstart, mstart - '1 0 0' * delta_x, MOVE_NORMAL, e);
2220 if (trace_fraction >= 1)
2222 traceline(mstart, mstart + '0 1 0' * delta_y, MOVE_NORMAL, e);
2223 if (trace_fraction >= 1)
2225 traceline(mstart, mstart - '0 1 0' * delta_y, MOVE_NORMAL, e);
2226 if (trace_fraction >= 1)
2228 traceline(mstart, mstart + '0 0 1' * delta_z, MOVE_NORMAL, e);
2229 if (trace_fraction >= 1)
2232 // rule 4: we must "see" some spawnpoint
2233 for(sp = world; (sp = find(sp, classname, "info_player_deathmatch")); )
2234 if(checkpvs(mstart, sp))
2238 for(sp = world; (sp = findflags(sp, flags, FL_ITEM)); )
2239 if(checkpvs(mstart, sp))
2245 // find a random vector to "look at"
2246 end_x = org_x + random() * delta_x;
2247 end_y = org_y + random() * delta_y;
2248 end_z = org_z + random() * delta_z;
2249 end = start + normalize(end - start) * vlen(delta);
2251 // rule 4: start TO end must not be too short
2252 tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
2253 if (trace_startsolid)
2255 if (trace_fraction < minviewdistance / vlen(delta))
2258 // rule 5: don't want to look at sky
2259 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
2262 // rule 6: we must not end up in trigger_hurt
2263 if (tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
2269 e.dphitcontentsmask = m;
2273 setorigin(e, start);
2274 e.angles = vectoangles(end - start);
2275 dprint("Needed ", ftos(i + 1), " attempts\n");
2282 float zcurveparticles_effectno;
2283 vector zcurveparticles_start;
2284 float zcurveparticles_spd;
2286 void endzcurveparticles()
2288 if(zcurveparticles_effectno)
2291 WriteShort(MSG_BROADCAST, zcurveparticles_spd | 0x8000);
2293 zcurveparticles_effectno = 0;
2296 void zcurveparticles(float effectno, vector start, vector end, float end_dz, float spd)
2298 spd = bound(0, floor(spd / 16), 32767);
2299 if(effectno != zcurveparticles_effectno || start != zcurveparticles_start)
2301 endzcurveparticles();
2302 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
2303 WriteByte(MSG_BROADCAST, TE_CSQC_ZCURVEPARTICLES);
2304 WriteShort(MSG_BROADCAST, effectno);
2305 WriteCoord(MSG_BROADCAST, start_x);
2306 WriteCoord(MSG_BROADCAST, start_y);
2307 WriteCoord(MSG_BROADCAST, start_z);
2308 zcurveparticles_effectno = effectno;
2309 zcurveparticles_start = start;
2312 WriteShort(MSG_BROADCAST, zcurveparticles_spd);
2313 WriteCoord(MSG_BROADCAST, end_x);
2314 WriteCoord(MSG_BROADCAST, end_y);
2315 WriteCoord(MSG_BROADCAST, end_z);
2316 WriteCoord(MSG_BROADCAST, end_dz);
2317 zcurveparticles_spd = spd;
2320 void zcurveparticles_from_tracetoss(float effectno, vector start, vector end, vector vel)
2323 vector vecxy, velxy;
2325 vecxy = end - start;
2330 if (vlen(velxy) < 0.000001 * fabs(vel_z))
2332 endzcurveparticles();
2333 trailparticles(world, effectno, start, end);
2337 end_dz = vlen(vecxy) / vlen(velxy) * vel_z - (end_z - start_z);
2338 zcurveparticles(effectno, start, end, end_dz, vlen(vel));
2341 void write_recordmarker(entity pl, float tstart, float dt)
2343 GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
2345 // also write a marker into demo files for demotc-race-record-extractor to find
2348 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
2349 " ", ftos(tstart), " ", ftos(dt), "\n"));
2352 vector shotorg_adjustfromclient(vector vecs, float y_is_right, float allowcenter, float algn)
2365 if(allowcenter) // 2: allow center handedness
2378 if(allowcenter) // 2: allow center handedness
2394 vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn)
2399 if (autocvar_g_shootfromeye)
2403 if (autocvar_g_shootfromclient) { vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn); }
2404 else { vecs_y = 0; vecs_z -= 2; }
2412 else if (autocvar_g_shootfromcenter)
2417 else if ((s = autocvar_g_shootfromfixedorigin) != "")
2427 else if (autocvar_g_shootfromclient)
2429 vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn);
2434 vector shotorg_adjust(vector vecs, float y_is_right, float visual)
2436 return shotorg_adjust_values(vecs, y_is_right, visual, self.owner.cvar_cl_gunalign);
2440 void attach_sameorigin(entity e, entity to, string tag)
2442 vector org, t_forward, t_left, t_up, e_forward, e_up;
2445 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2446 tagscale = pow(vlen(v_forward), -2); // undo a scale on the tag
2447 t_forward = v_forward * tagscale;
2448 t_left = v_right * -tagscale;
2449 t_up = v_up * tagscale;
2451 e.origin_x = org * t_forward;
2452 e.origin_y = org * t_left;
2453 e.origin_z = org * t_up;
2455 // current forward and up directions
2456 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2457 e.angles = AnglesTransform_FromVAngles(e.angles);
2459 e.angles = AnglesTransform_FromAngles(e.angles);
2460 fixedmakevectors(e.angles);
2462 // untransform forward, up!
2463 e_forward_x = v_forward * t_forward;
2464 e_forward_y = v_forward * t_left;
2465 e_forward_z = v_forward * t_up;
2466 e_up_x = v_up * t_forward;
2467 e_up_y = v_up * t_left;
2468 e_up_z = v_up * t_up;
2470 e.angles = fixedvectoangles2(e_forward, e_up);
2471 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2472 e.angles = AnglesTransform_ToVAngles(e.angles);
2474 e.angles = AnglesTransform_ToAngles(e.angles);
2476 setattachment(e, to, tag);
2477 setorigin(e, e.origin);
2480 void detach_sameorigin(entity e)
2483 org = gettaginfo(e, 0);
2484 e.angles = fixedvectoangles2(v_forward, v_up);
2485 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2486 e.angles = AnglesTransform_ToVAngles(e.angles);
2488 e.angles = AnglesTransform_ToAngles(e.angles);
2490 setattachment(e, world, "");
2491 setorigin(e, e.origin);
2494 void follow_sameorigin(entity e, entity to)
2496 e.movetype = MOVETYPE_FOLLOW; // make the hole follow
2497 e.aiment = to; // make the hole follow bmodel
2498 e.punchangle = to.angles; // the original angles of bmodel
2499 e.view_ofs = e.origin - to.origin; // relative origin
2500 e.v_angle = e.angles - to.angles; // relative angles
2503 void unfollow_sameorigin(entity e)
2505 e.movetype = MOVETYPE_NONE;
2508 entity gettaginfo_relative_ent;
2509 vector gettaginfo_relative(entity e, float tag)
2511 if (!gettaginfo_relative_ent)
2513 gettaginfo_relative_ent = spawn();
2514 gettaginfo_relative_ent.effects = EF_NODRAW;
2516 gettaginfo_relative_ent.model = e.model;
2517 gettaginfo_relative_ent.modelindex = e.modelindex;
2518 gettaginfo_relative_ent.frame = e.frame;
2519 return gettaginfo(gettaginfo_relative_ent, tag);
2524 float modeleffect_SendEntity(entity to, float sf)
2527 WriteByte(MSG_ENTITY, ENT_CLIENT_MODELEFFECT);
2530 if(self.velocity != '0 0 0')
2532 if(self.angles != '0 0 0')
2534 if(self.avelocity != '0 0 0')
2537 WriteByte(MSG_ENTITY, f);
2538 WriteShort(MSG_ENTITY, self.modelindex);
2539 WriteByte(MSG_ENTITY, self.skin);
2540 WriteByte(MSG_ENTITY, self.frame);
2541 WriteCoord(MSG_ENTITY, self.origin_x);
2542 WriteCoord(MSG_ENTITY, self.origin_y);
2543 WriteCoord(MSG_ENTITY, self.origin_z);
2546 WriteCoord(MSG_ENTITY, self.velocity_x);
2547 WriteCoord(MSG_ENTITY, self.velocity_y);
2548 WriteCoord(MSG_ENTITY, self.velocity_z);
2552 WriteCoord(MSG_ENTITY, self.angles_x);
2553 WriteCoord(MSG_ENTITY, self.angles_y);
2554 WriteCoord(MSG_ENTITY, self.angles_z);
2558 WriteCoord(MSG_ENTITY, self.avelocity_x);
2559 WriteCoord(MSG_ENTITY, self.avelocity_y);
2560 WriteCoord(MSG_ENTITY, self.avelocity_z);
2562 WriteShort(MSG_ENTITY, self.scale * 256.0);
2563 WriteShort(MSG_ENTITY, self.scale2 * 256.0);
2564 WriteByte(MSG_ENTITY, self.teleport_time * 100.0);
2565 WriteByte(MSG_ENTITY, self.fade_time * 100.0);
2566 WriteByte(MSG_ENTITY, self.alpha * 255.0);
2571 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)
2576 e.classname = "modeleffect";
2584 e.teleport_time = t1;
2588 e.scale = s0 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2592 e.scale2 = s2 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2595 sz = max(e.scale, e.scale2);
2596 setsize(e, e.mins * sz, e.maxs * sz);
2597 Net_LinkEntity(e, FALSE, 0.1, modeleffect_SendEntity);
2600 void shockwave_spawn(string m, vector org, float sz, float t1, float t2)
2602 return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2);
2605 float randombit(float bits)
2607 if not(bits & (bits-1)) // this ONLY holds for powers of two!
2616 for(f = 1; f <= bits; f *= 2)
2625 r = (r - 1) / (n - 1);
2632 float randombits(float bits, float k, float error_return)
2636 while(k > 0 && bits != r)
2638 r += randombit(bits - r);
2647 void randombit_test(float bits, float iter)
2651 print(ftos(randombit(bits)), "\n");
2656 float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
2658 if(halflifedist > 0)
2659 return pow(0.5, (bound(mindist, d, maxdist) - mindist) / halflifedist);
2660 else if(halflifedist < 0)
2661 return pow(0.5, (bound(mindist, d, maxdist) - maxdist) / halflifedist);
2670 #define cvar_string_normal builtin_cvar_string
2671 #define cvar_normal builtin_cvar
2673 string cvar_string_normal(string n)
2675 if not(cvar_type(n) & 1)
2676 backtrace(strcat("Attempt to access undefined cvar: ", n));
2677 return builtin_cvar_string(n);
2680 float cvar_normal(string n)
2682 return stof(cvar_string_normal(n));
2685 #define cvar_set_normal builtin_cvar_set
2693 oself.think = SUB_Remove;
2694 oself.nextthink = time;
2700 Execute func() after time + fdelay.
2701 self when func is executed = self when defer is called
2703 void defer(float fdelay, void() func)
2710 e.think = defer_think;
2711 e.nextthink = time + fdelay;
2714 .string aiment_classname;
2715 .float aiment_deadflag;
2716 void SetMovetypeFollow(entity ent, entity e)
2718 // FIXME this may not be warpzone aware
2719 ent.movetype = MOVETYPE_FOLLOW; // make the hole follow
2720 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.
2721 ent.aiment = e; // make the hole follow bmodel
2722 ent.punchangle = e.angles; // the original angles of bmodel
2723 ent.view_ofs = ent.origin - e.origin; // relative origin
2724 ent.v_angle = ent.angles - e.angles; // relative angles
2725 ent.aiment_classname = strzone(e.classname);
2726 ent.aiment_deadflag = e.deadflag;
2728 void UnsetMovetypeFollow(entity ent)
2730 ent.movetype = MOVETYPE_FLY;
2731 PROJECTILE_MAKETRIGGER(ent);
2734 float LostMovetypeFollow(entity ent)
2737 if(ent.movetype != MOVETYPE_FOLLOW)
2743 if(ent.aiment.classname != ent.aiment_classname)
2745 if(ent.aiment.deadflag != ent.aiment_deadflag)
2751 float isPushable(entity e)
2760 case "droppedweapon":
2761 case "keepawayball":
2762 case "nexball_basketball":
2763 case "nexball_football":
2765 case "bullet": // antilagged bullets can't hit this either
2768 if (e.projectiledeathtype)