1 var void remove(entity e);
2 void objerror(string s);
4 .vector dropped_origin;
6 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
8 string ColoredTeamName(float t);
10 float RandomSelection_totalweight;
11 float RandomSelection_best_priority;
12 entity RandomSelection_chosen_ent;
13 float RandomSelection_chosen_float;
14 void RandomSelection_Init()
16 RandomSelection_totalweight = 0;
17 RandomSelection_chosen_ent = world;
18 RandomSelection_chosen_float = 0;
19 RandomSelection_best_priority = -1;
21 void RandomSelection_Add(entity e, float f, float weight, float priority)
23 if(priority > RandomSelection_best_priority)
25 RandomSelection_best_priority = priority;
26 RandomSelection_chosen_ent = e;
27 RandomSelection_chosen_float = f;
28 RandomSelection_totalweight = weight;
30 else if(priority == RandomSelection_best_priority)
32 RandomSelection_totalweight += weight;
33 if(random() * RandomSelection_totalweight <= weight)
35 RandomSelection_chosen_ent = e;
36 RandomSelection_chosen_float = f;
41 float DistributeEvenly_amount;
42 float DistributeEvenly_totalweight;
43 void DistributeEvenly_Init(float amount, float totalweight)
45 if(DistributeEvenly_amount)
47 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
48 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
51 DistributeEvenly_amount = 0;
53 DistributeEvenly_amount = amount;
54 DistributeEvenly_totalweight = totalweight;
56 float DistributeEvenly_Get(float weight)
61 f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
62 DistributeEvenly_totalweight -= weight;
63 DistributeEvenly_amount -= f;
67 void move_out_of_solid_expand(entity e, vector by)
70 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
73 if(trace_fraction < 1)
76 // adjust origin in the other direction...
77 e.origin = e.origin - by * (1 - trace_fraction);
81 float move_out_of_solid(entity e)
86 traceline(o, o, MOVE_WORLDONLY, e);
90 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
98 move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
99 move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
100 move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
101 move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
102 move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
103 move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
104 setorigin(e, e.origin);
106 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
116 string STR_PLAYER = "player";
117 string STR_SPECTATOR = "spectator";
118 string STR_OBSERVER = "observer";
121 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
122 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
123 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
124 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
126 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
127 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
128 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
129 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
130 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
133 // copies a string to a tempstring (so one can strunzone it)
134 string strcat1(string s) = #115; // FRIK_FILE
139 void bcenterprint(string s)
141 // TODO replace by MSG_ALL (would show it to spectators too, though)?
143 FOR_EACH_PLAYER(head)
144 if(clienttype(head) == CLIENTTYPE_REAL)
145 centerprint(head, s);
148 void GameLogEcho(string s)
153 if(cvar("sv_eventlog_files"))
158 matches = cvar("sv_eventlog_files_counter") + 1;
159 cvar_set("sv_eventlog_files_counter", ftos(matches));
162 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
163 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
164 logfile = fopen(fn, FILE_APPEND);
165 fputs(logfile, ":logversion:3\n");
169 if(cvar("sv_eventlog_files_timestamps"))
170 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
172 fputs(logfile, strcat(s, "\n"));
175 if(cvar("sv_eventlog_console"))
184 // will be opened later
189 if(logfile_open && logfile >= 0)
196 float spawnpoint_nag;
197 void relocate_spawnpoint()
199 // nudge off the floor
200 setorigin(self, self.origin + '0 0 1');
202 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
203 if (trace_startsolid)
209 if(!move_out_of_solid(self))
210 objerror("could not get out of solid at all!");
211 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
212 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
213 print(" ", ftos(self.origin_y - o_y));
214 print(" ", ftos(self.origin_z - o_z), "'\n");
215 if(cvar("g_spawnpoints_auto_move_out_of_solid"))
218 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
224 self.mins = self.maxs = '0 0 0';
225 objerror("player spawn point in solid, mapper sucks!\n");
230 if(cvar("g_spawnpoints_autodrop"))
232 setsize(self, PL_MIN, PL_MAX);
236 self.use = spawnpoint_use;
237 self.team_saved = self.team;
241 if(g_ctf || g_assault || g_onslaught || g_domination)
243 have_team_spawns = 1;
245 if(cvar("r_showbboxes"))
247 // show where spawnpoints point at too
248 makevectors(self.angles);
251 e.classname = "info_player_foo";
252 setorigin(e, self.origin + v_forward * 24);
253 setsize(e, '-8 -8 -8', '8 8 8');
254 e.solid = SOLID_TRIGGER;
258 #define strstr strstrofs
260 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
261 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
262 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
263 // BE CONSTANT OR strzoneD!
264 float strstr(string haystack, string needle, float offset)
268 len = strlen(needle);
269 endpos = strlen(haystack) - len;
270 while(offset <= endpos)
272 found = substring(haystack, offset, len);
281 float NUM_NEAREST_ENTITIES = 4;
282 entity nearest_entity[NUM_NEAREST_ENTITIES];
283 float nearest_length[NUM_NEAREST_ENTITIES];
284 entity findnearest(vector point, .string field, string value, vector axismod)
295 localhead = find(world, field, value);
298 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
299 dist = localhead.oldorigin;
301 dist = localhead.origin;
303 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
306 for(i = 0; i < num_nearest; ++i)
308 if(len < nearest_length[i])
312 // now i tells us where to insert at
313 // INSERTION SORT! YOU'VE SEEN IT! RUN!
314 if(i < NUM_NEAREST_ENTITIES)
316 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
318 nearest_length[j + 1] = nearest_length[j];
319 nearest_entity[j + 1] = nearest_entity[j];
321 nearest_length[i] = len;
322 nearest_entity[i] = localhead;
323 if(num_nearest < NUM_NEAREST_ENTITIES)
324 num_nearest = num_nearest + 1;
327 localhead = find(localhead, field, value);
330 // now use the first one from our list that we can see
331 for(i = 0; i < num_nearest; ++i)
333 traceline(point, nearest_entity[i].origin, TRUE, world);
334 if(trace_fraction == 1)
338 dprint("Nearest point (");
339 dprint(nearest_entity[0].netname);
340 dprint(") is not visible, using a visible one.\n");
342 return nearest_entity[i];
349 dprint("Not seeing any location point, using nearest as fallback.\n");
351 dprint("Candidates were: ");
352 for(j = 0; j < num_nearest; ++j)
356 dprint(nearest_entity[j].netname);
361 return nearest_entity[0];
364 void spawnfunc_target_location()
366 self.classname = "target_location";
367 // location name in netname
368 // eventually support: count, teamgame selectors, line of sight?
371 void spawnfunc_info_location()
373 self.classname = "target_location";
374 self.message = self.netname;
377 string NearestLocation(vector p)
382 loc = findnearest(p, classname, "target_location", '1 1 1');
389 loc = findnearest(p, target, "###item###", '1 1 4');
396 string formatmessage(string msg)
403 msg_save = strzone(msg);
409 break; // too many replacements
411 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
414 replacement = substring(msg_save, p, 2);
415 escape = substring(msg_save, p + 1, 1);
418 else if(escape == "a")
419 replacement = ftos(floor(self.armorvalue));
420 else if(escape == "h")
421 replacement = ftos(floor(self.health));
422 else if(escape == "l")
423 replacement = NearestLocation(self.origin);
424 else if(escape == "y")
425 replacement = NearestLocation(self.cursor_trace_endpos);
426 else if(escape == "d")
427 replacement = NearestLocation(self.death_origin);
428 else if(escape == "w")
433 wep = self.switchweapon;
436 replacement = W_Name(wep);
438 else if(escape == "W")
440 if(self.items & IT_SHELLS) replacement = "shells";
441 else if(self.items & IT_NAILS) replacement = "bullets";
442 else if(self.items & IT_ROCKETS) replacement = "rockets";
443 else if(self.items & IT_CELLS) replacement = "cells";
444 else replacement = "batteries"; // ;)
446 else if(escape == "x")
448 replacement = self.cursor_trace_ent.netname;
449 if(!replacement || !self.cursor_trace_ent)
450 replacement = "nothing";
452 else if(escape == "p")
454 if(self.last_selected_player)
455 replacement = self.last_selected_player.netname;
457 replacement = "(nobody)";
459 msg = strcat(substring(msg_save, 0, p), replacement);
460 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
462 msg_save = strzone(msg);
465 msg = strcat(msg_save, "");
476 >0: receives a cvar from name=argv(f) value=argv(f+1)
478 void GetCvars_handleString(string thisname, float f, .string field, string name)
483 strunzone(self.field);
484 self.field = string_null;
491 strunzone(self.field);
492 self.field = strzone(argv(f + 1));
496 stuffcmd(self, strcat("sendcvar ", name, "\n"));
498 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
500 GetCvars_handleString(thisname, f, field, name);
501 if(f >= 0) // also initialize to the fitting value for "" when sending cvars out
505 s = func(strcat1(self.field));
508 strunzone(self.field);
509 self.field = strzone(s);
513 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
521 self.field = stof(argv(f + 1));
524 stuffcmd(self, strcat("sendcvar ", name, "\n"));
526 string W_FixWeaponOrder_ForceComplete(string s);
527 string W_FixWeaponOrder_AllowIncomplete(string s);
528 float w_getbestweapon(entity e);
529 void GetCvars(float f)
533 s = strcat1(argv(f));
534 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
535 GetCvars_handleFloat(s, f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
536 GetCvars_handleFloat(s, f, cvar_scr_centertime, "scr_centertime");
537 GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames");
538 GetCvars_handleString(s, f, cvar_g_nexuizversion, "g_nexuizversion");
539 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
540 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
541 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
542 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
543 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
544 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
545 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
546 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
547 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
548 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
549 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
550 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
551 GetCvars_handleFloat(s, f, cvar_cl_autotaunt, "cl_autotaunt");
552 GetCvars_handleFloat(s, f, cvar_cl_voice_directional, "cl_voice_directional");
553 GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation");
554 GetCvars_handleFloat(s, f, cvar_cl_hitsound, "cl_hitsound");
556 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
559 if(s == "cl_weaponpriority")
560 self.switchweapon = w_getbestweapon(self);
564 float fexists(string f)
567 fh = fopen(f, FILE_READ);
574 void backtrace(string msg)
577 dev = cvar("developer");
578 cvar_set("developer", "1");
580 dprint("--- CUT HERE ---\nWARNING: ");
583 remove(world); // isn't there any better way to cause a backtrace?
584 dprint("\n--- CUT UNTIL HERE ---\n");
585 cvar_set("developer", ftos(dev));
588 string Team_ColorCode(float teamid)
590 if(teamid == COLOR_TEAM1)
592 else if(teamid == COLOR_TEAM2)
594 else if(teamid == COLOR_TEAM3)
596 else if(teamid == COLOR_TEAM4)
601 string Team_ColorName(float t)
603 // fixme: Search for team entities and get their .netname's!
614 string Team_ColorNameLowerCase(float t)
616 // fixme: Search for team entities and get their .netname's!
628 #define CENTERPRIO_POINT 1
629 #define CENTERPRIO_SPAM 2
630 #define CENTERPRIO_VOTE 4
631 #define CENTERPRIO_NORMAL 5
632 #define CENTERPRIO_SHIELDING 7
633 #define CENTERPRIO_MAPVOTE 9
634 #define CENTERPRIO_IDLEKICK 50
635 #define CENTERPRIO_ADMIN 99
636 .float centerprint_priority;
637 .float centerprint_expires;
638 void centerprint_atprio(entity e, float prio, string s)
640 if(intermission_running)
641 if(prio < CENTERPRIO_MAPVOTE)
643 if(time > e.centerprint_expires)
644 e.centerprint_priority = 0;
645 if(prio >= e.centerprint_priority)
647 e.centerprint_priority = prio;
648 if(timeoutStatus == 2)
649 e.centerprint_expires = time + (e.cvar_scr_centertime * TIMEOUT_SLOWMO_VALUE);
651 e.centerprint_expires = time + e.cvar_scr_centertime;
652 centerprint_builtin(e, s);
655 void centerprint_expire(entity e, float prio)
657 if(prio == e.centerprint_priority)
659 e.centerprint_priority = 0;
660 centerprint_builtin(e, "");
663 void centerprint(entity e, string s)
665 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
668 // decolorizes and team colors the player name when needed
669 string playername(entity p)
672 if(teams_matter && !intermission_running && p.classname == "player")
674 t = Team_ColorCode(p.team);
675 return strcat(t, strdecolorize(p.netname));
681 vector randompos(vector m1, vector m2)
685 v_x = m2_x * random() + m1_x;
686 v_y = m2_y * random() + m1_y;
687 v_z = m2_z * random() + m1_z;
691 float g_pickup_shells;
692 float g_pickup_shells_max;
693 float g_pickup_nails;
694 float g_pickup_nails_max;
695 float g_pickup_rockets;
696 float g_pickup_rockets_max;
697 float g_pickup_cells;
698 float g_pickup_cells_max;
699 float g_pickup_armorsmall;
700 float g_pickup_armorsmall_max;
701 float g_pickup_armormedium;
702 float g_pickup_armormedium_max;
703 float g_pickup_armorlarge;
704 float g_pickup_armorlarge_max;
705 float g_pickup_healthsmall;
706 float g_pickup_healthsmall_max;
707 float g_pickup_healthmedium;
708 float g_pickup_healthmedium_max;
709 float g_pickup_healthlarge;
710 float g_pickup_healthlarge_max;
711 float g_pickup_healthmega;
712 float g_pickup_healthmega_max;
714 string g_weaponarena_list;
718 float start_ammo_shells;
719 float start_ammo_nails;
720 float start_ammo_rockets;
721 float start_ammo_cells;
723 float start_armorvalue;
724 float warmup_start_weapons;
725 float warmup_start_ammo_shells;
726 float warmup_start_ammo_nails;
727 float warmup_start_ammo_rockets;
728 float warmup_start_ammo_cells;
729 float warmup_start_health;
730 float warmup_start_armorvalue;
733 entity get_weaponinfo(float w);
735 void readplayerstartcvars()
741 // initialize starting values for players
744 start_ammo_shells = 0;
745 start_ammo_nails = 0;
746 start_ammo_rockets = 0;
747 start_ammo_cells = 0;
748 start_health = cvar("g_balance_health_start");
749 start_armorvalue = cvar("g_balance_armor_start");
752 s = cvar_string("g_weaponarena");
758 g_weaponarena_list = "All Weapons";
759 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
761 e = get_weaponinfo(j);
762 g_weaponarena |= e.weapons;
763 weapon_action(e.weapon, WR_PRECACHE);
768 g_weaponarena_list = "Most Weapons";
769 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
771 e = get_weaponinfo(j);
772 if(e.spawnflags & WEPSPAWNFLAG_NORMAL)
774 g_weaponarena |= e.weapons;
775 weapon_action(e.weapon, WR_PRECACHE);
781 t = tokenize_sane(s);
782 g_weaponarena_list = "";
783 for(i = 0; i < t; ++i)
786 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
788 e = get_weaponinfo(j);
791 g_weaponarena |= e.weapons;
792 weapon_action(e.weapon, WR_PRECACHE);
793 g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
799 print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
802 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
807 start_weapons = g_weaponarena;
808 start_ammo_rockets = 999;
809 start_ammo_shells = 999;
810 start_ammo_cells = 999;
811 start_ammo_nails = 999;
812 start_items |= IT_UNLIMITED_AMMO;
817 // will be done later
818 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
820 e = get_weaponinfo(i);
823 weapon_action(e.weapon, WR_PRECACHE);
829 start_armorvalue = 0;
830 start_weapons = WEPBIT_MINSTANEX;
831 weapon_action(WEP_MINSTANEX, WR_PRECACHE);
832 start_ammo_cells = cvar("g_minstagib_ammo_start");
833 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
839 start_ammo_shells = cvar("g_lms_start_ammo_shells");
840 start_ammo_nails = cvar("g_lms_start_ammo_nails");
841 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
842 start_ammo_cells = cvar("g_lms_start_ammo_cells");
843 start_health = cvar("g_lms_start_health");
844 start_armorvalue = cvar("g_lms_start_armor");
845 } else if (cvar("g_use_ammunition")) {
846 start_ammo_shells = cvar("g_start_ammo_shells");
847 start_ammo_nails = cvar("g_start_ammo_nails");
848 start_ammo_rockets = cvar("g_start_ammo_rockets");
849 start_ammo_cells = cvar("g_start_ammo_cells");
851 start_ammo_shells = cvar("g_pickup_shells_max");
852 start_ammo_nails = cvar("g_pickup_nails_max");
853 start_ammo_rockets = cvar("g_pickup_rockets_max");
854 start_ammo_cells = cvar("g_pickup_cells_max");
855 start_items |= IT_UNLIMITED_AMMO;
858 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
860 e = get_weaponinfo(i);
863 if(((e.spawnflags & WEPSPAWNFLAG_NORMAL) && g_lms) || cvar(strcat("g_start_weapon_", e.netname)))
865 start_weapons |= e.weapons;
866 weapon_action(e.weapon, WR_PRECACHE);
873 warmup_start_ammo_shells = start_ammo_shells;
874 warmup_start_ammo_nails = start_ammo_nails;
875 warmup_start_ammo_rockets = start_ammo_rockets;
876 warmup_start_ammo_cells = start_ammo_cells;
877 warmup_start_health = start_health;
878 warmup_start_armorvalue = start_armorvalue;
879 warmup_start_weapons = start_weapons;
881 if(!g_weaponarena && !g_nixnex && !g_minstagib)
883 if(cvar("g_use_ammunition"))
885 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
886 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
887 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
888 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
890 warmup_start_health = cvar("g_warmup_start_health");
891 warmup_start_armorvalue = cvar("g_warmup_start_armor");
892 if(cvar("g_warmup_allguns"))
894 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
896 e = get_weaponinfo(i);
899 if(e.spawnflags & WEPSPAWNFLAG_NORMAL)
901 warmup_start_weapons |= e.weapons;
902 weapon_action(e.weapon, WR_PRECACHE);
909 if(g_grappling_hook) // offhand hook
911 start_weapons &~= WEPBIT_HOOK;
912 warmup_start_weapons &~= WEPBIT_HOOK;
915 if(g_weapon_stay == 2)
917 if(!start_ammo_shells) start_ammo_shells = g_pickup_shells;
918 if(!start_ammo_nails) start_ammo_shells = g_pickup_nails;
919 if(!start_ammo_cells) start_ammo_shells = g_pickup_cells;
920 if(!start_ammo_rockets) start_ammo_shells = g_pickup_rockets;
921 if(!warmup_start_ammo_shells) warmup_start_ammo_shells = g_pickup_shells;
922 if(!warmup_start_ammo_nails) warmup_start_ammo_shells = g_pickup_nails;
923 if(!warmup_start_ammo_cells) warmup_start_ammo_shells = g_pickup_cells;
924 if(!warmup_start_ammo_rockets) warmup_start_ammo_shells = g_pickup_rockets;
927 start_ammo_shells = max(0, start_ammo_shells);
928 start_ammo_nails = max(0, start_ammo_nails);
929 start_ammo_cells = max(0, start_ammo_cells);
930 start_ammo_rockets = max(0, start_ammo_rockets);
932 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
933 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
934 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
935 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
939 float g_bugrigs_planar_movement;
940 float g_bugrigs_planar_movement_car_jumping;
941 float g_bugrigs_reverse_spinning;
942 float g_bugrigs_reverse_speeding;
943 float g_bugrigs_reverse_stopping;
944 float g_bugrigs_air_steering;
945 float g_bugrigs_angle_smoothing;
946 float g_bugrigs_friction_floor;
947 float g_bugrigs_friction_brake;
948 float g_bugrigs_friction_air;
949 float g_bugrigs_accel;
950 float g_bugrigs_speed_ref;
951 float g_bugrigs_speed_pow;
952 float g_bugrigs_steer;
954 float g_touchexplode;
955 float g_touchexplode_radius;
956 float g_touchexplode_damage;
957 float g_touchexplode_edgedamage;
958 float g_touchexplode_force;
960 void readlevelcvars(void)
962 g_bugrigs = cvar("g_bugrigs");
963 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
964 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
965 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
966 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
967 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
968 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
969 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
970 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
971 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
972 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
973 g_bugrigs_accel = cvar("g_bugrigs_accel");
974 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
975 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
976 g_bugrigs_steer = cvar("g_bugrigs_steer");
978 g_touchexplode = cvar("g_touchexplode");
979 g_touchexplode_radius = cvar("g_touchexplode_radius");
980 g_touchexplode_damage = cvar("g_touchexplode_damage");
981 g_touchexplode_edgedamage = cvar("g_touchexplode_edgedamage");
982 g_touchexplode_force = cvar("g_touchexplode_force");
984 sv_clones = cvar("sv_clones");
985 sv_cheats = cvar("sv_cheats");
986 sv_gentle = cvar("sv_gentle");
987 sv_foginterval = cvar("sv_foginterval");
988 g_cloaked = cvar("g_cloaked");
989 g_jump_grunt = cvar("g_jump_grunt");
990 g_footsteps = cvar("g_footsteps");
991 g_grappling_hook = cvar("g_grappling_hook");
992 g_laserguided_missile = cvar("g_laserguided_missile");
993 g_midair = cvar("g_midair");
994 g_minstagib = cvar("g_minstagib");
995 g_nixnex = cvar("g_nixnex");
996 g_nixnex_with_laser = cvar("g_nixnex_with_laser");
997 g_norecoil = cvar("g_norecoil");
998 g_vampire = cvar("g_vampire");
999 sv_maxidle = cvar("sv_maxidle");
1000 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
1001 sv_pogostick = cvar("sv_pogostick");
1002 sv_doublejump = cvar("sv_doublejump");
1003 g_maplist_allow_hidden = cvar("g_maplist_allow_hidden");
1004 g_ctf_reverse = cvar("g_ctf_reverse");
1006 inWarmupStage = cvar("g_warmup");
1007 g_warmup_limit = cvar("g_warmup_limit");
1008 g_warmup_allguns = cvar("g_warmup_allguns");
1009 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
1011 if(g_race && g_race_qualifying == 2 || g_arena || g_assault || cvar("g_campaign"))
1012 inWarmupStage = 0; // these modes cannot work together, sorry
1014 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
1015 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
1016 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
1017 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
1018 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
1019 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
1021 if(g_minstagib) g_nixnex = g_weaponarena = 0;
1022 if(g_nixnex) g_weaponarena = 0;
1025 g_pickup_shells = cvar("g_pickup_shells");
1026 g_pickup_shells_max = cvar("g_pickup_shells_max");
1027 g_pickup_nails = cvar("g_pickup_nails");
1028 g_pickup_nails_max = cvar("g_pickup_nails_max");
1029 g_pickup_rockets = cvar("g_pickup_rockets");
1030 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
1031 g_pickup_cells = cvar("g_pickup_cells");
1032 g_pickup_cells_max = cvar("g_pickup_cells_max");
1033 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
1034 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
1035 g_pickup_armormedium = cvar("g_pickup_armormedium");
1036 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
1037 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
1038 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
1039 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
1040 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
1041 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
1042 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
1043 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
1044 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
1045 g_pickup_healthmega = cvar("g_pickup_healthmega");
1046 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
1048 g_weapon_stay = cvar("g_weapon_stay");
1049 if(!g_weapon_stay && (cvar("deathmatch") == 2))
1052 if not(inWarmupStage)
1054 game_starttime = cvar("g_start_delay");
1057 restartAnnouncer = spawn();
1058 restartAnnouncer.think = restartAnnouncer_Think;
1059 restartAnnouncer.nextthink = time + 0.1;
1060 restartAnnouncer.spawnflags = 0;
1064 readplayerstartcvars();
1068 // TODO sound pack system
1071 string precache_sound_builtin (string s) = #19;
1072 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
1073 string precache_sound(string s)
1075 return precache_sound_builtin(strcat(soundpack, s));
1077 void play2(entity e, string filename)
1079 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
1081 void sound(entity e, float chan, string samp, float vol, float atten)
1083 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
1088 string precache_sound (string s) = #19;
1089 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
1090 float precache_sound_index (string s) = #19;
1092 #define SND_VOLUME 1
1093 #define SND_ATTENUATION 2
1094 #define SND_LARGEENTITY 8
1095 #define SND_LARGESOUND 16
1097 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
1100 entno = num_for_edict(e);
1101 idx = precache_sound_index(samp);
1106 atten = floor(atten * 64);
1107 vol = floor(vol * 255);
1110 sflags |= SND_VOLUME;
1112 sflags |= SND_ATTENUATION;
1114 sflags |= SND_LARGEENTITY;
1116 sflags |= SND_LARGESOUND;
1118 WriteByte(dest, SVC_SOUND);
1119 WriteByte(dest, sflags);
1120 if(sflags & SND_VOLUME)
1121 WriteByte(dest, vol * 255);
1122 if(sflags & SND_ATTENUATION)
1123 WriteByte(dest, atten);
1124 if(sflags & SND_LARGEENTITY)
1126 WriteShort(dest, entno);
1127 WriteByte(dest, chan);
1131 WriteShort(dest, entno * 8 + chan);
1133 if(sflags & SND_LARGESOUND)
1134 WriteShort(dest, idx);
1136 WriteByte(dest, idx);
1138 WriteCoord(dest, o_x);
1139 WriteCoord(dest, o_y);
1140 WriteCoord(dest, o_z);
1142 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
1145 o = e.origin + 0.5 * (e.mins + e.maxs);
1146 soundtoat(dest, e, o, chan, samp, vol, atten);
1148 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
1150 soundtoat(MSG_BROADCAST, e, o, chan, samp, vol, atten);
1152 void stopsoundto(float dest, entity e, float chan)
1155 entno = num_for_edict(e);
1160 idx = precache_sound_index("misc/null.wav");
1161 sflags = SND_LARGEENTITY;
1163 sflags |= SND_LARGESOUND;
1164 WriteByte(dest, SVC_SOUND);
1165 WriteByte(dest, sflags);
1166 WriteShort(dest, entno);
1167 WriteByte(dest, chan);
1168 if(sflags & SND_LARGESOUND)
1169 WriteShort(dest, idx);
1171 WriteByte(dest, idx);
1172 WriteCoord(dest, e.origin_x);
1173 WriteCoord(dest, e.origin_y);
1174 WriteCoord(dest, e.origin_z);
1178 WriteByte(dest, SVC_STOPSOUND);
1179 WriteShort(dest, entno * 8 + chan);
1182 void stopsound(entity e, float chan)
1184 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
1185 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
1188 void play2(entity e, string filename)
1190 //stuffcmd(e, strcat("play2 ", filename, "\n"));
1192 soundtoat(MSG_ONE, world, '0 0 0', CHAN_AUTO, filename, VOL_BASE, ATTN_NONE);
1195 .float announcetime;
1196 float announce(entity player, string msg)
1198 if(time > player.announcetime)
1199 if(clienttype(player) == CLIENTTYPE_REAL)
1201 player.announcetime = time + 0.8;
1208 void play2team(float t, string filename)
1211 FOR_EACH_REALPLAYER(head)
1214 play2(head, filename);
1218 void play2all(string samp)
1220 sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
1223 void PrecachePlayerSounds(string f);
1224 void precache_all_models(string pattern)
1226 float globhandle, i, n;
1229 globhandle = search_begin(pattern, TRUE, FALSE);
1232 n = search_getsize(globhandle);
1233 for(i = 0; i < n; ++i)
1235 //print(search_getfilename(globhandle, i), "\n");
1236 f = search_getfilename(globhandle, i);
1238 PrecachePlayerSounds(strcat(f, ".sounds"));
1240 search_end(globhandle);
1245 // gamemode related things
1246 precache_model ("null");
1247 precache_model ("models/misc/chatbubble.spr");
1248 precache_model ("models/misc/teambubble.spr");
1251 precache_model ("models/runematch/curse.mdl");
1252 precache_model ("models/runematch/rune.mdl");
1255 #ifdef TTURRETS_ENABLED
1256 if(cvar("g_turrets"))
1260 // Precache all player models if desired
1261 if (cvar("sv_precacheplayermodels"))
1263 PrecachePlayerSounds("sound/player/default.sounds");
1264 precache_all_models("models/player/*.zym");
1265 precache_all_models("models/player/*.dpm");
1266 precache_all_models("models/player/*.md3");
1267 precache_all_models("models/player/*.psk");
1268 //precache_model("models/player/carni.zym");
1269 //precache_model("models/player/crash.zym");
1270 //precache_model("models/player/grunt.zym");
1271 //precache_model("models/player/headhunter.zym");
1272 //precache_model("models/player/insurrectionist.zym");
1273 //precache_model("models/player/jeandarc.zym");
1274 //precache_model("models/player/lurk.zym");
1275 //precache_model("models/player/lycanthrope.zym");
1276 //precache_model("models/player/marine.zym");
1277 //precache_model("models/player/nexus.zym");
1278 //precache_model("models/player/pyria.zym");
1279 //precache_model("models/player/shock.zym");
1280 //precache_model("models/player/skadi.zym");
1281 //precache_model("models/player/specop.zym");
1282 //precache_model("models/player/visitant.zym");
1285 if(cvar("sv_defaultcharacter"))
1288 s = cvar_string("sv_defaultplayermodel_red");
1292 PrecachePlayerSounds(strcat(s, ".sounds"));
1294 s = cvar_string("sv_defaultplayermodel_blue");
1298 PrecachePlayerSounds(strcat(s, ".sounds"));
1300 s = cvar_string("sv_defaultplayermodel_yellow");
1304 PrecachePlayerSounds(strcat(s, ".sounds"));
1306 s = cvar_string("sv_defaultplayermodel_pink");
1310 PrecachePlayerSounds(strcat(s, ".sounds"));
1312 s = cvar_string("sv_defaultplayermodel");
1316 PrecachePlayerSounds(strcat(s, ".sounds"));
1322 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1323 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1326 // gore and miscellaneous sounds
1327 //precache_sound ("misc/h2ohit.wav");
1328 precache_model ("models/hook.md3");
1329 precache_sound ("misc/armorimpact.wav");
1330 precache_sound ("misc/bodyimpact1.wav");
1331 precache_sound ("misc/bodyimpact2.wav");
1332 precache_sound ("misc/gib.wav");
1333 precache_sound ("misc/gib_splat01.wav");
1334 precache_sound ("misc/gib_splat02.wav");
1335 precache_sound ("misc/gib_splat03.wav");
1336 precache_sound ("misc/gib_splat04.wav");
1337 precache_sound ("misc/hit.wav");
1338 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1339 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1340 precache_sound ("misc/null.wav");
1341 precache_sound ("misc/spawn.wav");
1342 precache_sound ("misc/talk.wav");
1343 precache_sound ("misc/teleport.wav");
1344 precache_sound ("player/lava.wav");
1345 precache_sound ("player/slime.wav");
1347 // announcer sounds - male
1348 precache_sound ("announcer/male/electrobitch.wav");
1349 precache_sound ("announcer/male/airshot.wav");
1350 precache_sound ("announcer/male/03kills.wav");
1351 precache_sound ("announcer/male/05kills.wav");
1352 precache_sound ("announcer/male/10kills.wav");
1353 precache_sound ("announcer/male/15kills.wav");
1354 precache_sound ("announcer/male/20kills.wav");
1355 precache_sound ("announcer/male/25kills.wav");
1356 precache_sound ("announcer/male/30kills.wav");
1357 precache_sound ("announcer/male/botlike.wav");
1358 precache_sound ("announcer/male/yoda.wav");
1359 precache_sound ("announcer/male/headshot.wav");
1360 precache_sound ("announcer/male/impressive.wav");
1362 // announcer sounds - robotic
1363 precache_sound ("announcer/robotic/prepareforbattle.wav");
1364 precache_sound ("announcer/robotic/begin.wav");
1365 precache_sound ("announcer/robotic/timeoutcalled.wav");
1366 precache_sound ("announcer/robotic/1fragleft.wav");
1367 precache_sound ("announcer/robotic/1minuteremains.wav");
1368 precache_sound ("announcer/robotic/2fragsleft.wav");
1369 precache_sound ("announcer/robotic/3fragsleft.wav");
1372 precache_sound ("announcer/robotic/lastsecond.wav");
1373 precache_sound ("announcer/robotic/narrowly.wav");
1376 precache_model ("models/sprites/1.spr32");
1377 precache_model ("models/sprites/2.spr32");
1378 precache_model ("models/sprites/3.spr32");
1379 precache_model ("models/sprites/4.spr32");
1380 precache_model ("models/sprites/5.spr32");
1381 precache_model ("models/sprites/6.spr32");
1382 precache_model ("models/sprites/7.spr32");
1383 precache_model ("models/sprites/8.spr32");
1384 precache_model ("models/sprites/9.spr32");
1385 precache_model ("models/sprites/10.spr32");
1386 precache_sound ("announcer/robotic/1.wav");
1387 precache_sound ("announcer/robotic/2.wav");
1388 precache_sound ("announcer/robotic/3.wav");
1389 precache_sound ("announcer/robotic/4.wav");
1390 precache_sound ("announcer/robotic/5.wav");
1391 precache_sound ("announcer/robotic/6.wav");
1392 precache_sound ("announcer/robotic/7.wav");
1393 precache_sound ("announcer/robotic/8.wav");
1394 precache_sound ("announcer/robotic/9.wav");
1395 precache_sound ("announcer/robotic/10.wav");
1397 // common weapon precaches
1398 precache_sound ("weapons/weapon_switch.wav");
1399 precache_sound ("weapons/weaponpickup.wav");
1400 if (cvar("g_grappling_hook"))
1402 precache_sound ("weapons/hook_fire.wav"); // hook
1403 precache_sound ("weapons/hook_impact.wav"); // hook
1406 if (cvar("sv_precacheweapons") || g_nixnex)
1408 //precache weapon models/sounds
1411 while (wep <= WEP_LAST)
1413 weapon_action(wep, WR_PRECACHE);
1418 precache_model("models/elaser.mdl");
1419 precache_model("models/laser.mdl");
1420 precache_model("models/ebomb.mdl");
1423 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
1425 if (!self.noise && self.music) // quake 3 uses the music field
1426 self.noise = self.music;
1428 // plays music for the level if there is any
1431 precache_sound (self.noise);
1432 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1437 // sorry, but using \ in macros breaks line numbers
1438 #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
1439 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1440 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1442 vector ExactTriggerHit_mins;
1443 vector ExactTriggerHit_maxs;
1444 float ExactTriggerHit_Recurse()
1450 tracebox('0 0 0', ExactTriggerHit_mins, ExactTriggerHit_maxs, '0 0 0', MOVE_NORMAL, other);
1453 if(trace_ent == self)
1458 se.solid = SOLID_NOT;
1459 f = ExactTriggerHit_Recurse();
1465 float ExactTriggerHit()
1469 if not(self.modelindex)
1473 self.solid = SOLID_BSP;
1474 ExactTriggerHit_mins = other.absmin;
1475 ExactTriggerHit_maxs = other.absmax;
1476 f = ExactTriggerHit_Recurse();
1482 // WARNING: this kills the trace globals
1483 #define EXACTTRIGGER_TOUCH if not(ExactTriggerHit()) return
1484 #define EXACTTRIGGER_INIT InitSolidBSPTrigger(); self.solid = SOLID_TRIGGER
1486 #define INITPRIO_FIRST 0
1487 #define INITPRIO_GAMETYPE 0
1488 #define INITPRIO_GAMETYPE_FALLBACK 1
1489 #define INITPRIO_CVARS 5
1490 #define INITPRIO_FINDTARGET 10
1491 #define INITPRIO_DROPTOFLOOR 20
1492 #define INITPRIO_SETLOCATION 90
1493 #define INITPRIO_LINKDOORS 91
1494 #define INITPRIO_LAST 99
1496 .void(void) initialize_entity;
1497 .float initialize_entity_order;
1498 .entity initialize_entity_next;
1499 entity initialize_entity_first;
1501 void make_safe_for_remove(entity e)
1503 if(e.initialize_entity)
1506 for(ent = initialize_entity_first; ent; )
1508 if((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1510 print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1511 // skip it in linked list
1514 prev.initialize_entity_next = ent.initialize_entity_next;
1515 ent = prev.initialize_entity_next;
1519 initialize_entity_first = ent.initialize_entity_next;
1520 ent = initialize_entity_first;
1526 ent = ent.initialize_entity_next;
1532 void objerror(string s)
1534 make_safe_for_remove(self);
1535 objerror_builtin(s);
1538 void remove_unsafely(entity e)
1543 void remove_safely(entity e)
1545 make_safe_for_remove(e);
1549 void InitializeEntity(entity e, void(void) func, float order)
1553 if(!e || e.initialize_entity)
1555 // make a proxy initializer entity
1559 e.classname = "initialize_entity";
1563 e.initialize_entity = func;
1564 e.initialize_entity_order = order;
1566 cur = initialize_entity_first;
1569 if(!cur || cur.initialize_entity_order > order)
1571 // insert between prev and cur
1573 prev.initialize_entity_next = e;
1575 initialize_entity_first = e;
1576 e.initialize_entity_next = cur;
1580 cur = cur.initialize_entity_next;
1583 void InitializeEntitiesRun()
1586 startoflist = initialize_entity_first;
1587 initialize_entity_first = world;
1588 for(self = startoflist; self; )
1591 var void(void) func;
1592 e = self.initialize_entity_next;
1593 func = self.initialize_entity;
1594 self.initialize_entity_order = 0;
1595 self.initialize_entity = func_null;
1596 self.initialize_entity_next = world;
1597 if(self.classname == "initialize_entity")
1601 remove_builtin(self);
1604 //dprint("Delayed initialization: ", self.classname, "\n");
1610 .float uncustomizeentityforclient_set;
1611 .void(void) uncustomizeentityforclient;
1612 void(void) SUB_Nullpointer = #0;
1613 void UncustomizeEntitiesRun()
1617 for(self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1618 self.uncustomizeentityforclient();
1621 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1623 e.customizeentityforclient = customizer;
1624 e.uncustomizeentityforclient = uncustomizer;
1625 e.uncustomizeentityforclient_set = (uncustomizer != SUB_Nullpointer);
1629 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1631 void Net_LinkEntity(entity e)
1633 setmodel(e, "null");
1634 e.effects = EF_NODEPTHTEST | EF_LOWPRECISION;
1637 void adaptor_think2touch()
1646 void adaptor_think2use()
1658 // deferred dropping
1659 void DropToFloor_Handler()
1661 droptofloor_builtin();
1662 self.dropped_origin = self.origin;
1667 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1672 float trace_hits_box_a0, trace_hits_box_a1;
1674 float trace_hits_box_1d(float end, float thmi, float thma)
1678 // just check if x is in range
1686 // do the trace with respect to x
1687 // 0 -> end has to stay in thmi -> thma
1688 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1689 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1690 if(trace_hits_box_a0 > trace_hits_box_a1)
1696 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1701 // now it is a trace from 0 to end
1703 trace_hits_box_a0 = 0;
1704 trace_hits_box_a1 = 1;
1706 if(!trace_hits_box_1d(end_x, thmi_x, thma_x))
1708 if(!trace_hits_box_1d(end_y, thmi_y, thma_y))
1710 if(!trace_hits_box_1d(end_z, thmi_z, thma_z))
1716 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1718 return trace_hits_box(start, end, thmi - ma, thma - mi);
1721 float SUB_NoImpactCheck()
1723 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1725 if(other == world && self.size != '0 0 0')
1728 tic = self.velocity * sys_ticrate;
1729 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
1730 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
1731 if(trace_fraction >= 1)
1733 dprint("Odd... did not hit...?\n");
1735 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1737 dprint("Detected and prevented the sky-grapple bug.\n");
1745 #define SUB_OwnerCheck() (other && (other == self.owner))
1747 #define PROJECTILE_TOUCH do { if(SUB_OwnerCheck()) return; if(SUB_NoImpactCheck()) { remove(self); return; } } while(0)
1748 #define PROJECTILE_TOUCH_NOSOUND do { if(SUB_OwnerCheck()) return; if(SUB_NoImpactCheck()) { stopsound(self, CHAN_PAIN); remove(self); return; } } while(0)
1750 float MAX_IPBAN_URIS = 16;
1752 float URI_GET_DISCARD = 0;
1753 float URI_GET_IPBAN = 1;
1754 float URI_GET_IPBAN_END = 16;
1756 void URI_Get_Callback(float id, float status, string data)
1758 dprint("Received HTTP request data for id ", ftos(id), "; status is ", ftos(status), "\nData is\n:");
1760 dprint("\nEnd of data.\n");
1762 if(id == URI_GET_DISCARD)
1766 else if(id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
1769 OnlineBanList_URI_Get_Callback(id, status, data);
1773 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
1777 void print_to(entity e, string s)
1780 sprint(e, strcat(s, "\n"));
1799 for(i = 0; i < MapInfo_count; ++i)
1801 if(MapInfo_Get_ByID(i))
1803 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
1806 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
1807 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
1815 for(i = 0; i < MapInfo_count; ++i)
1817 if(MapInfo_Get_ByID(i))
1819 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/racerecord/time")));
1822 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/racerecord/netname"));
1823 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, mmsss(r)), " ", h, "\n");
1830 return "No records are available on this server.\n";
1832 return strcat("Records on this server:\n", s);