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)
407 break; // too many replacements
409 p1 = strstr(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
410 p2 = strstr(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
420 replacement = substring(msg, p, 2);
421 escape = substring(msg, p + 1, 1);
424 else if(escape == "\\")
426 else if(escape == "n")
428 else if(escape == "a")
429 replacement = ftos(floor(self.armorvalue));
430 else if(escape == "h")
431 replacement = ftos(floor(self.health));
432 else if(escape == "l")
433 replacement = NearestLocation(self.origin);
434 else if(escape == "y")
435 replacement = NearestLocation(self.cursor_trace_endpos);
436 else if(escape == "d")
437 replacement = NearestLocation(self.death_origin);
438 else if(escape == "w")
443 wep = self.switchweapon;
446 replacement = W_Name(wep);
448 else if(escape == "W")
450 if(self.items & IT_SHELLS) replacement = "shells";
451 else if(self.items & IT_NAILS) replacement = "bullets";
452 else if(self.items & IT_ROCKETS) replacement = "rockets";
453 else if(self.items & IT_CELLS) replacement = "cells";
454 else replacement = "batteries"; // ;)
456 else if(escape == "x")
458 replacement = self.cursor_trace_ent.netname;
459 if(!replacement || !self.cursor_trace_ent)
460 replacement = "nothing";
462 else if(escape == "p")
464 if(self.last_selected_player)
465 replacement = self.last_selected_player.netname;
467 replacement = "(nobody)";
469 msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
470 p = p + strlen(replacement);
481 >0: receives a cvar from name=argv(f) value=argv(f+1)
483 void GetCvars_handleString(string thisname, float f, .string field, string name)
488 strunzone(self.field);
489 self.field = string_null;
496 strunzone(self.field);
497 self.field = strzone(argv(f + 1));
501 stuffcmd(self, strcat("sendcvar ", name, "\n"));
503 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
505 GetCvars_handleString(thisname, f, field, name);
506 if(f >= 0) // also initialize to the fitting value for "" when sending cvars out
510 s = func(strcat1(self.field));
513 strunzone(self.field);
514 self.field = strzone(s);
518 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
526 self.field = stof(argv(f + 1));
529 stuffcmd(self, strcat("sendcvar ", name, "\n"));
531 string W_FixWeaponOrder_ForceComplete(string s);
532 string W_FixWeaponOrder_AllowIncomplete(string s);
533 float w_getbestweapon(entity e);
534 void GetCvars(float f)
538 s = strcat1(argv(f));
539 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
540 GetCvars_handleFloat(s, f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
541 GetCvars_handleFloat(s, f, cvar_scr_centertime, "scr_centertime");
542 GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames");
543 GetCvars_handleString(s, f, cvar_g_nexuizversion, "g_nexuizversion");
544 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
545 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
546 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
547 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
548 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
549 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
550 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
551 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
552 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
553 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
554 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
555 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
556 GetCvars_handleFloat(s, f, cvar_cl_autotaunt, "cl_autotaunt");
557 GetCvars_handleFloat(s, f, cvar_cl_voice_directional, "cl_voice_directional");
558 GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation");
559 GetCvars_handleFloat(s, f, cvar_cl_hitsound, "cl_hitsound");
561 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
564 if(s == "cl_weaponpriority")
565 self.switchweapon = w_getbestweapon(self);
569 float fexists(string f)
572 fh = fopen(f, FILE_READ);
579 void backtrace(string msg)
582 dev = cvar("developer");
583 cvar_set("developer", "1");
585 dprint("--- CUT HERE ---\nWARNING: ");
588 remove(world); // isn't there any better way to cause a backtrace?
589 dprint("\n--- CUT UNTIL HERE ---\n");
590 cvar_set("developer", ftos(dev));
593 string Team_ColorCode(float teamid)
595 if(teamid == COLOR_TEAM1)
597 else if(teamid == COLOR_TEAM2)
599 else if(teamid == COLOR_TEAM3)
601 else if(teamid == COLOR_TEAM4)
606 string Team_ColorName(float t)
608 // fixme: Search for team entities and get their .netname's!
619 string Team_ColorNameLowerCase(float t)
621 // fixme: Search for team entities and get their .netname's!
633 #define CENTERPRIO_POINT 1
634 #define CENTERPRIO_SPAM 2
635 #define CENTERPRIO_VOTE 4
636 #define CENTERPRIO_NORMAL 5
637 #define CENTERPRIO_SHIELDING 7
638 #define CENTERPRIO_MAPVOTE 9
639 #define CENTERPRIO_IDLEKICK 50
640 #define CENTERPRIO_ADMIN 99
641 .float centerprint_priority;
642 .float centerprint_expires;
643 void centerprint_atprio(entity e, float prio, string s)
645 if(intermission_running)
646 if(prio < CENTERPRIO_MAPVOTE)
648 if(time > e.centerprint_expires)
649 e.centerprint_priority = 0;
650 if(prio >= e.centerprint_priority)
652 e.centerprint_priority = prio;
653 if(timeoutStatus == 2)
654 e.centerprint_expires = time + (e.cvar_scr_centertime * TIMEOUT_SLOWMO_VALUE);
656 e.centerprint_expires = time + e.cvar_scr_centertime;
657 centerprint_builtin(e, s);
660 void centerprint_expire(entity e, float prio)
662 if(prio == e.centerprint_priority)
664 e.centerprint_priority = 0;
665 centerprint_builtin(e, "");
668 void centerprint(entity e, string s)
670 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
673 // decolorizes and team colors the player name when needed
674 string playername(entity p)
677 if(teams_matter && !intermission_running && p.classname == "player")
679 t = Team_ColorCode(p.team);
680 return strcat(t, strdecolorize(p.netname));
686 vector randompos(vector m1, vector m2)
690 v_x = m2_x * random() + m1_x;
691 v_y = m2_y * random() + m1_y;
692 v_z = m2_z * random() + m1_z;
696 float g_pickup_shells;
697 float g_pickup_shells_max;
698 float g_pickup_nails;
699 float g_pickup_nails_max;
700 float g_pickup_rockets;
701 float g_pickup_rockets_max;
702 float g_pickup_cells;
703 float g_pickup_cells_max;
704 float g_pickup_armorsmall;
705 float g_pickup_armorsmall_max;
706 float g_pickup_armormedium;
707 float g_pickup_armormedium_max;
708 float g_pickup_armorbig;
709 float g_pickup_armorbig_max;
710 float g_pickup_armorlarge;
711 float g_pickup_armorlarge_max;
712 float g_pickup_healthsmall;
713 float g_pickup_healthsmall_max;
714 float g_pickup_healthmedium;
715 float g_pickup_healthmedium_max;
716 float g_pickup_healthlarge;
717 float g_pickup_healthlarge_max;
718 float g_pickup_healthmega;
719 float g_pickup_healthmega_max;
721 string g_weaponarena_list;
725 float start_ammo_shells;
726 float start_ammo_nails;
727 float start_ammo_rockets;
728 float start_ammo_cells;
730 float start_armorvalue;
731 float warmup_start_weapons;
732 float warmup_start_ammo_shells;
733 float warmup_start_ammo_nails;
734 float warmup_start_ammo_rockets;
735 float warmup_start_ammo_cells;
736 float warmup_start_health;
737 float warmup_start_armorvalue;
740 entity get_weaponinfo(float w);
742 void readplayerstartcvars()
748 // initialize starting values for players
751 start_ammo_shells = 0;
752 start_ammo_nails = 0;
753 start_ammo_rockets = 0;
754 start_ammo_cells = 0;
755 start_health = cvar("g_balance_health_start");
756 start_armorvalue = cvar("g_balance_armor_start");
759 s = cvar_string("g_weaponarena");
765 g_weaponarena_list = "All Weapons";
766 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
768 e = get_weaponinfo(j);
769 g_weaponarena |= e.weapons;
770 weapon_action(e.weapon, WR_PRECACHE);
775 g_weaponarena_list = "Most Weapons";
776 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
778 e = get_weaponinfo(j);
779 if(e.spawnflags & WEPSPAWNFLAG_NORMAL)
781 g_weaponarena |= e.weapons;
782 weapon_action(e.weapon, WR_PRECACHE);
788 t = tokenize_sane(s);
789 g_weaponarena_list = "";
790 for(i = 0; i < t; ++i)
793 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
795 e = get_weaponinfo(j);
798 g_weaponarena |= e.weapons;
799 weapon_action(e.weapon, WR_PRECACHE);
800 g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
806 print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
809 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
814 start_weapons = g_weaponarena;
815 start_ammo_rockets = 999;
816 start_ammo_shells = 999;
817 start_ammo_cells = 999;
818 start_ammo_nails = 999;
819 start_items |= IT_UNLIMITED_AMMO;
824 // will be done later
825 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
827 e = get_weaponinfo(i);
830 weapon_action(e.weapon, WR_PRECACHE);
836 start_armorvalue = 0;
837 start_weapons = WEPBIT_MINSTANEX;
838 weapon_action(WEP_MINSTANEX, WR_PRECACHE);
839 start_ammo_cells = cvar("g_minstagib_ammo_start");
840 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
842 if(g_minstagib_invis_alpha <= 0)
843 g_minstagib_invis_alpha = -1;
849 start_ammo_shells = cvar("g_lms_start_ammo_shells");
850 start_ammo_nails = cvar("g_lms_start_ammo_nails");
851 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
852 start_ammo_cells = cvar("g_lms_start_ammo_cells");
853 start_health = cvar("g_lms_start_health");
854 start_armorvalue = cvar("g_lms_start_armor");
855 } else if (cvar("g_use_ammunition")) {
856 start_ammo_shells = cvar("g_start_ammo_shells");
857 start_ammo_nails = cvar("g_start_ammo_nails");
858 start_ammo_rockets = cvar("g_start_ammo_rockets");
859 start_ammo_cells = cvar("g_start_ammo_cells");
861 start_ammo_shells = cvar("g_pickup_shells_max");
862 start_ammo_nails = cvar("g_pickup_nails_max");
863 start_ammo_rockets = cvar("g_pickup_rockets_max");
864 start_ammo_cells = cvar("g_pickup_cells_max");
865 start_items |= IT_UNLIMITED_AMMO;
868 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
870 e = get_weaponinfo(i);
874 t = cvar(strcat("g_start_weapon_", e.netname));
876 if(t < 0) // "default" weapon selection
879 t = (e.spawnflags & WEPSPAWNFLAG_NORMAL);
881 t = (i == WEP_LASER);
883 t = (i == WEP_LASER || i == WEP_SHOTGUN);
884 if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
885 t += (i == WEP_HOOK);
890 start_weapons |= e.weapons;
891 weapon_action(e.weapon, WR_PRECACHE);
898 warmup_start_ammo_shells = start_ammo_shells;
899 warmup_start_ammo_nails = start_ammo_nails;
900 warmup_start_ammo_rockets = start_ammo_rockets;
901 warmup_start_ammo_cells = start_ammo_cells;
902 warmup_start_health = start_health;
903 warmup_start_armorvalue = start_armorvalue;
904 warmup_start_weapons = start_weapons;
906 if(!g_weaponarena && !g_nixnex && !g_minstagib)
908 if(cvar("g_use_ammunition"))
910 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
911 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
912 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
913 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
915 warmup_start_health = cvar("g_warmup_start_health");
916 warmup_start_armorvalue = cvar("g_warmup_start_armor");
917 if(cvar("g_warmup_allguns"))
919 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
921 e = get_weaponinfo(i);
924 if(e.spawnflags & WEPSPAWNFLAG_NORMAL)
926 warmup_start_weapons |= e.weapons;
927 weapon_action(e.weapon, WR_PRECACHE);
934 if(start_weapons & WEPBIT_HOOK)
936 // can't have off-hand hook, if hook weapon is enabled
938 // note: if g_grappling_hook is 1, also give some initial cells
941 if(!start_ammo_cells)
942 start_ammo_cells = g_pickup_cells;
943 if(!warmup_start_ammo_cells)
944 warmup_start_ammo_cells = g_pickup_cells;
947 g_grappling_hook = 0;
952 if(!start_ammo_cells)
953 start_ammo_cells = g_pickup_cells;
954 if(!warmup_start_ammo_cells)
955 warmup_start_ammo_cells = g_pickup_cells;
957 g_grappling_hook = 0; // these two can't coexist, as they use the same button
960 if(g_weapon_stay == 2)
962 if(!start_ammo_shells) start_ammo_shells = g_pickup_shells;
963 if(!start_ammo_nails) start_ammo_nails = g_pickup_nails;
964 if(!start_ammo_cells) start_ammo_cells = g_pickup_cells;
965 if(!start_ammo_rockets) start_ammo_rockets = g_pickup_rockets;
966 if(!warmup_start_ammo_shells) warmup_start_ammo_shells = g_pickup_shells;
967 if(!warmup_start_ammo_nails) warmup_start_ammo_nails = g_pickup_nails;
968 if(!warmup_start_ammo_cells) warmup_start_ammo_cells = g_pickup_cells;
969 if(!warmup_start_ammo_rockets) warmup_start_ammo_rockets = g_pickup_rockets;
972 start_ammo_shells = max(0, start_ammo_shells);
973 start_ammo_nails = max(0, start_ammo_nails);
974 start_ammo_cells = max(0, start_ammo_cells);
975 start_ammo_rockets = max(0, start_ammo_rockets);
977 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
978 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
979 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
980 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
984 float g_bugrigs_planar_movement;
985 float g_bugrigs_planar_movement_car_jumping;
986 float g_bugrigs_reverse_spinning;
987 float g_bugrigs_reverse_speeding;
988 float g_bugrigs_reverse_stopping;
989 float g_bugrigs_air_steering;
990 float g_bugrigs_angle_smoothing;
991 float g_bugrigs_friction_floor;
992 float g_bugrigs_friction_brake;
993 float g_bugrigs_friction_air;
994 float g_bugrigs_accel;
995 float g_bugrigs_speed_ref;
996 float g_bugrigs_speed_pow;
997 float g_bugrigs_steer;
999 float g_touchexplode;
1000 float g_touchexplode_radius;
1001 float g_touchexplode_damage;
1002 float g_touchexplode_edgedamage;
1003 float g_touchexplode_force;
1005 void readlevelcvars(void)
1007 g_bugrigs = cvar("g_bugrigs");
1008 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
1009 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
1010 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
1011 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
1012 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
1013 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
1014 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
1015 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
1016 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
1017 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
1018 g_bugrigs_accel = cvar("g_bugrigs_accel");
1019 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
1020 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
1021 g_bugrigs_steer = cvar("g_bugrigs_steer");
1023 g_touchexplode = cvar("g_touchexplode");
1024 g_touchexplode_radius = cvar("g_touchexplode_radius");
1025 g_touchexplode_damage = cvar("g_touchexplode_damage");
1026 g_touchexplode_edgedamage = cvar("g_touchexplode_edgedamage");
1027 g_touchexplode_force = cvar("g_touchexplode_force");
1029 sv_clones = cvar("sv_clones");
1030 sv_cheats = cvar("sv_cheats");
1031 sv_gentle = cvar("sv_gentle");
1032 sv_foginterval = cvar("sv_foginterval");
1033 g_cloaked = cvar("g_cloaked");
1034 g_jump_grunt = cvar("g_jump_grunt");
1035 g_footsteps = cvar("g_footsteps");
1036 g_grappling_hook = cvar("g_grappling_hook");
1037 g_jetpack = cvar("g_jetpack");
1038 g_laserguided_missile = cvar("g_laserguided_missile");
1039 g_midair = cvar("g_midair");
1040 g_minstagib = cvar("g_minstagib");
1041 g_nixnex = cvar("g_nixnex");
1042 g_nixnex_with_laser = cvar("g_nixnex_with_laser");
1043 g_norecoil = cvar("g_norecoil");
1044 g_vampire = cvar("g_vampire");
1045 g_bloodloss = cvar("g_bloodloss");
1046 sv_maxidle = cvar("sv_maxidle");
1047 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
1048 sv_pogostick = cvar("sv_pogostick");
1049 sv_doublejump = cvar("sv_doublejump");
1050 g_maplist_allow_hidden = cvar("g_maplist_allow_hidden");
1051 g_ctf_reverse = cvar("g_ctf_reverse");
1053 inWarmupStage = cvar("g_warmup");
1054 g_warmup_limit = cvar("g_warmup_limit");
1055 g_warmup_allguns = cvar("g_warmup_allguns");
1056 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
1058 if(g_race && g_race_qualifying == 2 || g_arena || g_assault || cvar("g_campaign"))
1059 inWarmupStage = 0; // these modes cannot work together, sorry
1061 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
1062 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
1063 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
1064 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
1065 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
1066 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
1068 if(g_minstagib) g_nixnex = g_weaponarena = 0;
1069 if(g_nixnex) g_weaponarena = 0;
1072 g_pickup_shells = cvar("g_pickup_shells");
1073 g_pickup_shells_max = cvar("g_pickup_shells_max");
1074 g_pickup_nails = cvar("g_pickup_nails");
1075 g_pickup_nails_max = cvar("g_pickup_nails_max");
1076 g_pickup_rockets = cvar("g_pickup_rockets");
1077 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
1078 g_pickup_cells = cvar("g_pickup_cells");
1079 g_pickup_cells_max = cvar("g_pickup_cells_max");
1080 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
1081 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
1082 g_pickup_armormedium = cvar("g_pickup_armormedium");
1083 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
1084 g_pickup_armorbig = cvar("g_pickup_armorbig");
1085 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
1086 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
1087 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
1088 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
1089 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
1090 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
1091 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
1092 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
1093 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
1094 g_pickup_healthmega = cvar("g_pickup_healthmega");
1095 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
1097 g_pinata = cvar("g_pinata");
1099 g_weapon_stay = cvar("g_weapon_stay");
1100 if(!g_weapon_stay && (cvar("deathmatch") == 2))
1103 if not(inWarmupStage)
1104 game_starttime = cvar("g_start_delay");
1106 readplayerstartcvars();
1110 // TODO sound pack system
1113 string precache_sound_builtin (string s) = #19;
1114 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
1115 string precache_sound(string s)
1117 return precache_sound_builtin(strcat(soundpack, s));
1119 void play2(entity e, string filename)
1121 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
1123 void sound(entity e, float chan, string samp, float vol, float atten)
1125 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
1130 string precache_sound (string s) = #19;
1131 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
1132 float precache_sound_index (string s) = #19;
1134 #define SND_VOLUME 1
1135 #define SND_ATTENUATION 2
1136 #define SND_LARGEENTITY 8
1137 #define SND_LARGESOUND 16
1139 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
1142 entno = num_for_edict(e);
1143 idx = precache_sound_index(samp);
1148 atten = floor(atten * 64);
1149 vol = floor(vol * 255);
1152 sflags |= SND_VOLUME;
1154 sflags |= SND_ATTENUATION;
1156 sflags |= SND_LARGEENTITY;
1158 sflags |= SND_LARGESOUND;
1160 WriteByte(dest, SVC_SOUND);
1161 WriteByte(dest, sflags);
1162 if(sflags & SND_VOLUME)
1163 WriteByte(dest, vol * 255);
1164 if(sflags & SND_ATTENUATION)
1165 WriteByte(dest, atten);
1166 if(sflags & SND_LARGEENTITY)
1168 WriteShort(dest, entno);
1169 WriteByte(dest, chan);
1173 WriteShort(dest, entno * 8 + chan);
1175 if(sflags & SND_LARGESOUND)
1176 WriteShort(dest, idx);
1178 WriteByte(dest, idx);
1180 WriteCoord(dest, o_x);
1181 WriteCoord(dest, o_y);
1182 WriteCoord(dest, o_z);
1184 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
1187 o = e.origin + 0.5 * (e.mins + e.maxs);
1188 soundtoat(dest, e, o, chan, samp, vol, atten);
1190 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
1192 soundtoat(MSG_BROADCAST, e, o, chan, samp, vol, atten);
1194 void stopsoundto(float dest, entity e, float chan)
1197 entno = num_for_edict(e);
1202 idx = precache_sound_index("misc/null.wav");
1203 sflags = SND_LARGEENTITY;
1205 sflags |= SND_LARGESOUND;
1206 WriteByte(dest, SVC_SOUND);
1207 WriteByte(dest, sflags);
1208 WriteShort(dest, entno);
1209 WriteByte(dest, chan);
1210 if(sflags & SND_LARGESOUND)
1211 WriteShort(dest, idx);
1213 WriteByte(dest, idx);
1214 WriteCoord(dest, e.origin_x);
1215 WriteCoord(dest, e.origin_y);
1216 WriteCoord(dest, e.origin_z);
1220 WriteByte(dest, SVC_STOPSOUND);
1221 WriteShort(dest, entno * 8 + chan);
1224 void stopsound(entity e, float chan)
1226 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
1227 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
1230 void play2(entity e, string filename)
1232 //stuffcmd(e, strcat("play2 ", filename, "\n"));
1234 soundtoat(MSG_ONE, world, '0 0 0', CHAN_AUTO, filename, VOL_BASE, ATTN_NONE);
1237 .float announcetime;
1238 float announce(entity player, string msg)
1240 if(time > player.announcetime)
1241 if(clienttype(player) == CLIENTTYPE_REAL)
1243 player.announcetime = time + 0.8;
1250 void play2team(float t, string filename)
1253 FOR_EACH_REALPLAYER(head)
1256 play2(head, filename);
1260 void play2all(string samp)
1262 sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
1265 void PrecachePlayerSounds(string f);
1266 void precache_all_models(string pattern)
1268 float globhandle, i, n;
1271 globhandle = search_begin(pattern, TRUE, FALSE);
1274 n = search_getsize(globhandle);
1275 for(i = 0; i < n; ++i)
1277 //print(search_getfilename(globhandle, i), "\n");
1278 f = search_getfilename(globhandle, i);
1280 PrecachePlayerSounds(strcat(f, ".sounds"));
1282 search_end(globhandle);
1287 // gamemode related things
1288 precache_model ("models/misc/chatbubble.spr");
1289 precache_model ("models/misc/teambubble.spr");
1292 precache_model ("models/runematch/curse.mdl");
1293 precache_model ("models/runematch/rune.mdl");
1296 #ifdef TTURRETS_ENABLED
1297 if(cvar("g_turrets"))
1301 // Precache all player models if desired
1302 if (cvar("sv_precacheplayermodels"))
1304 PrecachePlayerSounds("sound/player/default.sounds");
1305 precache_all_models("models/player/*.zym");
1306 precache_all_models("models/player/*.dpm");
1307 precache_all_models("models/player/*.md3");
1308 precache_all_models("models/player/*.psk");
1309 //precache_model("models/player/carni.zym");
1310 //precache_model("models/player/crash.zym");
1311 //precache_model("models/player/grunt.zym");
1312 //precache_model("models/player/headhunter.zym");
1313 //precache_model("models/player/insurrectionist.zym");
1314 //precache_model("models/player/jeandarc.zym");
1315 //precache_model("models/player/lurk.zym");
1316 //precache_model("models/player/lycanthrope.zym");
1317 //precache_model("models/player/marine.zym");
1318 //precache_model("models/player/nexus.zym");
1319 //precache_model("models/player/pyria.zym");
1320 //precache_model("models/player/shock.zym");
1321 //precache_model("models/player/skadi.zym");
1322 //precache_model("models/player/specop.zym");
1323 //precache_model("models/player/visitant.zym");
1326 if(cvar("sv_defaultcharacter"))
1329 s = cvar_string("sv_defaultplayermodel_red");
1333 PrecachePlayerSounds(strcat(s, ".sounds"));
1335 s = cvar_string("sv_defaultplayermodel_blue");
1339 PrecachePlayerSounds(strcat(s, ".sounds"));
1341 s = cvar_string("sv_defaultplayermodel_yellow");
1345 PrecachePlayerSounds(strcat(s, ".sounds"));
1347 s = cvar_string("sv_defaultplayermodel_pink");
1351 PrecachePlayerSounds(strcat(s, ".sounds"));
1353 s = cvar_string("sv_defaultplayermodel");
1357 PrecachePlayerSounds(strcat(s, ".sounds"));
1363 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1364 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1367 // gore and miscellaneous sounds
1368 //precache_sound ("misc/h2ohit.wav");
1369 precache_model ("models/hook.md3");
1370 precache_sound ("misc/armorimpact.wav");
1371 precache_sound ("misc/bodyimpact1.wav");
1372 precache_sound ("misc/bodyimpact2.wav");
1373 precache_sound ("misc/gib.wav");
1374 precache_sound ("misc/gib_splat01.wav");
1375 precache_sound ("misc/gib_splat02.wav");
1376 precache_sound ("misc/gib_splat03.wav");
1377 precache_sound ("misc/gib_splat04.wav");
1378 precache_sound ("misc/hit.wav");
1379 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1380 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1381 precache_sound ("misc/null.wav");
1382 precache_sound ("misc/spawn.wav");
1383 precache_sound ("misc/talk.wav");
1384 precache_sound ("misc/teleport.wav");
1385 precache_sound ("player/lava.wav");
1386 precache_sound ("player/slime.wav");
1388 // announcer sounds - male
1389 precache_sound ("announcer/male/electrobitch.wav");
1390 precache_sound ("announcer/male/airshot.wav");
1391 precache_sound ("announcer/male/03kills.wav");
1392 precache_sound ("announcer/male/05kills.wav");
1393 precache_sound ("announcer/male/10kills.wav");
1394 precache_sound ("announcer/male/15kills.wav");
1395 precache_sound ("announcer/male/20kills.wav");
1396 precache_sound ("announcer/male/25kills.wav");
1397 precache_sound ("announcer/male/30kills.wav");
1398 precache_sound ("announcer/male/botlike.wav");
1399 precache_sound ("announcer/male/yoda.wav");
1400 precache_sound ("announcer/male/headshot.wav");
1401 precache_sound ("announcer/male/impressive.wav");
1403 // announcer sounds - robotic
1404 precache_sound ("announcer/robotic/prepareforbattle.wav");
1405 precache_sound ("announcer/robotic/begin.wav");
1406 precache_sound ("announcer/robotic/timeoutcalled.wav");
1407 precache_sound ("announcer/robotic/1fragleft.wav");
1408 precache_sound ("announcer/robotic/1minuteremains.wav");
1409 precache_sound ("announcer/robotic/2fragsleft.wav");
1410 precache_sound ("announcer/robotic/3fragsleft.wav");
1413 precache_sound ("announcer/robotic/lastsecond.wav");
1414 precache_sound ("announcer/robotic/narrowly.wav");
1417 precache_model ("models/sprites/1.spr32");
1418 precache_model ("models/sprites/2.spr32");
1419 precache_model ("models/sprites/3.spr32");
1420 precache_model ("models/sprites/4.spr32");
1421 precache_model ("models/sprites/5.spr32");
1422 precache_model ("models/sprites/6.spr32");
1423 precache_model ("models/sprites/7.spr32");
1424 precache_model ("models/sprites/8.spr32");
1425 precache_model ("models/sprites/9.spr32");
1426 precache_model ("models/sprites/10.spr32");
1427 precache_sound ("announcer/robotic/1.wav");
1428 precache_sound ("announcer/robotic/2.wav");
1429 precache_sound ("announcer/robotic/3.wav");
1430 precache_sound ("announcer/robotic/4.wav");
1431 precache_sound ("announcer/robotic/5.wav");
1432 precache_sound ("announcer/robotic/6.wav");
1433 precache_sound ("announcer/robotic/7.wav");
1434 precache_sound ("announcer/robotic/8.wav");
1435 precache_sound ("announcer/robotic/9.wav");
1436 precache_sound ("announcer/robotic/10.wav");
1438 // common weapon precaches
1439 precache_sound ("weapons/weapon_switch.wav");
1440 precache_sound ("weapons/weaponpickup.wav");
1441 if(g_grappling_hook)
1443 precache_sound ("weapons/hook_fire.wav"); // hook
1444 precache_sound ("weapons/hook_impact.wav"); // hook
1447 if (cvar("sv_precacheweapons") || g_nixnex)
1449 //precache weapon models/sounds
1452 while (wep <= WEP_LAST)
1454 weapon_action(wep, WR_PRECACHE);
1459 precache_model("models/elaser.mdl");
1460 precache_model("models/laser.mdl");
1461 precache_model("models/ebomb.mdl");
1464 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
1466 if (!self.noise && self.music) // quake 3 uses the music field
1467 self.noise = self.music;
1469 // plays music for the level if there is any
1472 precache_sound (self.noise);
1473 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1478 // sorry, but using \ in macros breaks line numbers
1479 #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
1480 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1481 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1483 vector ExactTriggerHit_mins;
1484 vector ExactTriggerHit_maxs;
1485 float ExactTriggerHit_Recurse()
1491 tracebox('0 0 0', ExactTriggerHit_mins, ExactTriggerHit_maxs, '0 0 0', MOVE_NORMAL, other);
1494 if(trace_ent == self)
1499 se.solid = SOLID_NOT;
1500 f = ExactTriggerHit_Recurse();
1506 float ExactTriggerHit()
1510 if not(self.modelindex)
1514 self.solid = SOLID_BSP;
1515 ExactTriggerHit_mins = other.absmin;
1516 ExactTriggerHit_maxs = other.absmax;
1517 f = ExactTriggerHit_Recurse();
1523 // WARNING: this kills the trace globals
1524 #define EXACTTRIGGER_TOUCH if not(ExactTriggerHit()) return
1525 #define EXACTTRIGGER_INIT InitSolidBSPTrigger(); self.solid = SOLID_TRIGGER
1527 #define INITPRIO_FIRST 0
1528 #define INITPRIO_GAMETYPE 0
1529 #define INITPRIO_GAMETYPE_FALLBACK 1
1530 #define INITPRIO_CVARS 5
1531 #define INITPRIO_FINDTARGET 10
1532 #define INITPRIO_DROPTOFLOOR 20
1533 #define INITPRIO_SETLOCATION 90
1534 #define INITPRIO_LINKDOORS 91
1535 #define INITPRIO_LAST 99
1537 .void(void) initialize_entity;
1538 .float initialize_entity_order;
1539 .entity initialize_entity_next;
1540 entity initialize_entity_first;
1542 void make_safe_for_remove(entity e)
1544 if(e.initialize_entity)
1547 for(ent = initialize_entity_first; ent; )
1549 if((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1551 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1552 // skip it in linked list
1555 prev.initialize_entity_next = ent.initialize_entity_next;
1556 ent = prev.initialize_entity_next;
1560 initialize_entity_first = ent.initialize_entity_next;
1561 ent = initialize_entity_first;
1567 ent = ent.initialize_entity_next;
1573 void objerror(string s)
1575 make_safe_for_remove(self);
1576 objerror_builtin(s);
1579 void remove_unsafely(entity e)
1584 void remove_safely(entity e)
1586 make_safe_for_remove(e);
1590 void InitializeEntity(entity e, void(void) func, float order)
1594 if(!e || e.initialize_entity)
1596 // make a proxy initializer entity
1600 e.classname = "initialize_entity";
1604 e.initialize_entity = func;
1605 e.initialize_entity_order = order;
1607 cur = initialize_entity_first;
1610 if(!cur || cur.initialize_entity_order > order)
1612 // insert between prev and cur
1614 prev.initialize_entity_next = e;
1616 initialize_entity_first = e;
1617 e.initialize_entity_next = cur;
1621 cur = cur.initialize_entity_next;
1624 void InitializeEntitiesRun()
1627 startoflist = initialize_entity_first;
1628 initialize_entity_first = world;
1629 for(self = startoflist; self; )
1632 var void(void) func;
1633 e = self.initialize_entity_next;
1634 func = self.initialize_entity;
1635 self.initialize_entity_order = 0;
1636 self.initialize_entity = func_null;
1637 self.initialize_entity_next = world;
1638 if(self.classname == "initialize_entity")
1642 remove_builtin(self);
1645 //dprint("Delayed initialization: ", self.classname, "\n");
1651 .float uncustomizeentityforclient_set;
1652 .void(void) uncustomizeentityforclient;
1653 void(void) SUB_Nullpointer = #0;
1654 void UncustomizeEntitiesRun()
1658 for(self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1659 self.uncustomizeentityforclient();
1662 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1664 e.customizeentityforclient = customizer;
1665 e.uncustomizeentityforclient = uncustomizer;
1666 e.uncustomizeentityforclient_set = (uncustomizer != SUB_Nullpointer);
1670 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1673 void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc)
1677 if(e.classname == "")
1678 e.classname = "net_linked";
1680 if(e.model == "" || self.modelindex == 0)
1684 setmodel(e, "null");
1688 e.SendEntity = sendfunc;
1689 e.SendFlags = 0xFFFFFF;
1692 e.effects |= EF_NODEPTHTEST;
1696 e.nextthink = time + dt;
1697 e.think = SUB_Remove;
1701 void adaptor_think2touch()
1710 void adaptor_think2use()
1722 // deferred dropping
1723 void DropToFloor_Handler()
1725 droptofloor_builtin();
1726 self.dropped_origin = self.origin;
1731 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1736 float trace_hits_box_a0, trace_hits_box_a1;
1738 float trace_hits_box_1d(float end, float thmi, float thma)
1742 // just check if x is in range
1750 // do the trace with respect to x
1751 // 0 -> end has to stay in thmi -> thma
1752 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1753 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1754 if(trace_hits_box_a0 > trace_hits_box_a1)
1760 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1765 // now it is a trace from 0 to end
1767 trace_hits_box_a0 = 0;
1768 trace_hits_box_a1 = 1;
1770 if(!trace_hits_box_1d(end_x, thmi_x, thma_x))
1772 if(!trace_hits_box_1d(end_y, thmi_y, thma_y))
1774 if(!trace_hits_box_1d(end_z, thmi_z, thma_z))
1780 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1782 return trace_hits_box(start, end, thmi - ma, thma - mi);
1785 float SUB_NoImpactCheck()
1787 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1789 if(other == world && self.size != '0 0 0')
1792 tic = self.velocity * sys_ticrate;
1793 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
1794 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
1795 if(trace_fraction >= 1)
1797 dprint("Odd... did not hit...?\n");
1799 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1801 dprint("Detected and prevented the sky-grapple bug.\n");
1809 #define SUB_OwnerCheck() (other && (other == self.owner))
1811 #define PROJECTILE_TOUCH do { if(SUB_OwnerCheck()) return; if(SUB_NoImpactCheck()) { remove(self); return; } if(trace_ent && trace_ent.solid > SOLID_TRIGGER) UpdateCSQCProjectileNextFrame(self); } while(0)
1813 float MAX_IPBAN_URIS = 16;
1815 float URI_GET_DISCARD = 0;
1816 float URI_GET_IPBAN = 1;
1817 float URI_GET_IPBAN_END = 16;
1819 void URI_Get_Callback(float id, float status, string data)
1821 dprint("Received HTTP request data for id ", ftos(id), "; status is ", ftos(status), "\nData is\n:");
1823 dprint("\nEnd of data.\n");
1825 if(id == URI_GET_DISCARD)
1829 else if(id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
1832 OnlineBanList_URI_Get_Callback(id, status, data);
1836 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
1840 void print_to(entity e, string s)
1843 sprint(e, strcat(s, "\n"));
1862 for(i = 0; i < MapInfo_count; ++i)
1864 if(MapInfo_Get_ByID(i))
1866 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
1869 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
1870 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
1878 for(i = 0; i < MapInfo_count; ++i)
1880 if(MapInfo_Get_ByID(i))
1882 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/racerecord/time")));
1885 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/racerecord/netname"));
1886 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, mmsss(r)), " ", h, "\n");
1891 MapInfo_ClearTemps();
1894 return "No records are available on this server.\n";
1896 return strcat("Records on this server:\n", s);
1899 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
1902 vector start, org, delta, end, enddown, mstart;
1904 m = e.dphitcontentsmask;
1905 e.dphitcontentsmask = goodcontents | badcontents;
1908 delta = world.maxs - world.mins;
1910 for(i = 0; i < attempts; ++i)
1912 start_x = org_x + random() * delta_x;
1913 start_y = org_y + random() * delta_y;
1914 start_z = org_z + random() * delta_z;
1916 // rule 1: start inside world bounds, and outside
1917 // solid, and don't start from somewhere where you can
1918 // fall down to evil
1919 tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, e);
1920 if(trace_fraction >= 1)
1922 if(trace_startsolid)
1924 if(trace_dphitcontents & badcontents)
1926 if(trace_dphitq3surfaceflags & badsurfaceflags)
1929 // rule 2: if we are too high, lower the point
1930 if(trace_fraction * delta_z > maxaboveground)
1931 start = trace_endpos + '0 0 1' * maxaboveground;
1932 enddown = trace_endpos;
1934 // rule 3: make sure we aren't outside the map. This only works
1935 // for somewhat well formed maps. A good rule of thumb is that
1936 // the map should have a convex outside hull.
1937 // these can be traceLINES as we already verified the starting box
1938 mstart = start + 0.5 * (e.mins + e.maxs);
1939 traceline(mstart, mstart + '1 0 0' * delta_x, MOVE_NORMAL, e);
1940 if(trace_fraction >= 1)
1942 traceline(mstart, mstart - '1 0 0' * delta_x, MOVE_NORMAL, e);
1943 if(trace_fraction >= 1)
1945 traceline(mstart, mstart + '0 1 0' * delta_y, MOVE_NORMAL, e);
1946 if(trace_fraction >= 1)
1948 traceline(mstart, mstart - '0 1 0' * delta_y, MOVE_NORMAL, e);
1949 if(trace_fraction >= 1)
1951 traceline(mstart, mstart + '0 0 1' * delta_z, MOVE_NORMAL, e);
1952 if(trace_fraction >= 1)
1955 // find a random vector to "look at"
1956 end_x = org_x + random() * delta_x;
1957 end_y = org_y + random() * delta_y;
1958 end_z = org_z + random() * delta_z;
1959 end = start + normalize(end - start) * vlen(delta);
1961 // rule 4: start TO end must not be too short
1962 tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
1963 if(trace_startsolid)
1965 if(trace_fraction < minviewdistance / vlen(delta))
1968 // rule 5: don't want to look at sky
1969 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
1972 // rule 6: we must not end up in trigger_hurt
1973 if(tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
1975 dprint("trigger_hurt! ouch! and nothing else could find it!\n");
1982 e.dphitcontentsmask = m;
1986 setorigin(e, start);
1987 e.angles = vectoangles(end - start);
1988 dprint("Needed ", ftos(i + 1), " attempts\n");
1995 void zcurveparticles(float effectno, vector start, vector end, float end_dz, float spd)
1997 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
1998 WriteByte(MSG_BROADCAST, TE_CSQC_ZCURVEPARTICLES);
1999 WriteShort(MSG_BROADCAST, effectno);
2000 WriteCoord(MSG_BROADCAST, start_x);
2001 WriteCoord(MSG_BROADCAST, start_y);
2002 WriteCoord(MSG_BROADCAST, start_z);
2003 WriteCoord(MSG_BROADCAST, end_x);
2004 WriteCoord(MSG_BROADCAST, end_y);
2005 WriteCoord(MSG_BROADCAST, end_z);
2006 WriteCoord(MSG_BROADCAST, end_dz);
2007 WriteShort(MSG_BROADCAST, spd / 16);
2010 void zcurveparticles_from_tracetoss(float effectno, vector start, vector end, vector vel)
2013 vector vecxy, velxy;
2015 vecxy = end - start; vecxy_z = 0;
2016 velxy = vel; velxy_z = 0;
2018 if(vlen(velxy) < 0.000001 * fabs(vel_z))
2020 trailparticles(world, effectno, start, end);
2024 end_dz = vlen(vecxy) / vlen(velxy) * vel_z - (end_z - start_z);
2025 zcurveparticles(effectno, start, end, end_dz, vlen(vel));
2028 string GetGametype(); // g_world.qc
2029 void write_recordmarker(entity pl, float tstart, float dt)
2031 GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt / 10)));
2033 // also write a marker into demo files for demotc-race-record-extractor to find
2036 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", mmsss(dt * 10)),
2037 " ", ftos(tstart), " ", ftos(dt), "\n"));
2040 vector shotorg_adjust(vector vecs, float y_is_right, float visual)
2042 if (cvar("g_shootfromeye"))
2055 else if (cvar("g_shootfromcenter"))
2065 void attach_sameorigin(entity e, entity to, string tag)
2067 vector org, t_forward, t_left, t_up, e_forward, e_up;
2074 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2075 tagscale = pow(vlen(v_forward), -2); // undo a scale on the tag
2076 t_forward = v_forward * tagscale;
2077 t_left = v_right * -tagscale;
2078 t_up = v_up * tagscale;
2080 e.origin_x = org * t_forward;
2081 e.origin_y = org * t_left;
2082 e.origin_z = org * t_up;
2084 // current forward and up directions
2085 if(substring(e.model, 0, 1) == "*") // bmodels have their own rules
2086 e.angles_x = -e.angles_x;
2087 fixedmakevectors(e.angles);
2089 // untransform forward, up!
2090 e_forward_x = v_forward * t_forward;
2091 e_forward_y = v_forward * t_left;
2092 e_forward_z = v_forward * t_up;
2093 e_up_x = v_up * t_forward;
2094 e_up_y = v_up * t_left;
2095 e_up_z = v_up * t_up;
2097 e.angles = fixedvectoangles2(e_forward, e_up);
2098 if(substring(e.model, 0, 1) == "*") // bmodels have their own rules
2099 e.angles_x = -e.angles_x;
2101 setattachment(e, to, tag);
2102 setorigin(e, e.origin);
2105 void detach_sameorigin(entity e)
2108 org = gettaginfo(e, 0);
2109 e.angles = fixedvectoangles2(v_forward, v_up);
2110 if(substring(e.model, 0, 1) == "*") // bmodels have their own rules
2111 e.angles_x = -e.angles_x;
2113 setattachment(e, world, "");
2114 setorigin(e, e.origin);
2117 void follow_sameorigin(entity e, entity to)
2119 e.movetype = MOVETYPE_FOLLOW; // make the hole follow
2120 e.aiment = to; // make the hole follow bmodel
2121 e.punchangle = to.angles; // the original angles of bmodel
2122 e.view_ofs = e.origin - to.origin; // relative origin
2123 e.v_angle = e.angles - to.angles; // relative angles
2126 void unfollow_sameorigin(entity e)
2128 e.movetype = MOVETYPE_NONE;
2131 entity gettaginfo_relative_ent;
2132 vector gettaginfo_relative(entity e, float tag)
2134 if(!gettaginfo_relative_ent)
2136 gettaginfo_relative_ent = spawn();
2137 gettaginfo_relative_ent.effects = EF_NODRAW;
2139 gettaginfo_relative_ent.model = e.model;
2140 gettaginfo_relative_ent.modelindex = e.modelindex;
2141 gettaginfo_relative_ent.frame = e.frame;
2142 return gettaginfo(gettaginfo_relative_ent, tag);