1 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
3 string ColoredTeamName(float t);
5 float RandomSelection_totalweight;
6 float RandomSelection_best_priority;
7 entity RandomSelection_chosen_ent;
8 float RandomSelection_chosen_float;
9 void RandomSelection_Init()
11 RandomSelection_totalweight = 0;
12 RandomSelection_chosen_ent = world;
13 RandomSelection_chosen_float = 0;
14 RandomSelection_best_priority = -1;
16 void RandomSelection_Add(entity e, float f, float weight, float priority)
18 if(priority > RandomSelection_best_priority)
20 RandomSelection_best_priority = priority;
21 RandomSelection_chosen_ent = e;
22 RandomSelection_chosen_float = f;
23 RandomSelection_totalweight = weight;
25 else if(priority == RandomSelection_best_priority)
27 RandomSelection_totalweight += weight;
28 if(random() * RandomSelection_totalweight <= weight)
30 RandomSelection_chosen_ent = e;
31 RandomSelection_chosen_float = f;
36 float DistributeEvenly_amount;
37 float DistributeEvenly_totalweight;
38 void DistributeEvenly_Init(float amount, float totalweight)
40 if(DistributeEvenly_amount)
42 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
43 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
46 DistributeEvenly_amount = 0;
48 DistributeEvenly_amount = amount;
49 DistributeEvenly_totalweight = totalweight;
51 float DistributeEvenly_Get(float weight)
56 f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
57 DistributeEvenly_totalweight -= weight;
58 DistributeEvenly_amount -= f;
62 void move_out_of_solid_expand(entity e, vector by)
65 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
68 if(trace_fraction < 1)
71 // adjust origin in the other direction...
72 e.origin = e.origin - by * (1 - trace_fraction);
76 void move_out_of_solid(entity e)
81 traceline(o, o, MOVE_WORLDONLY, e);
84 dprint("origin is in solid too! (", vtos(o), ")");
88 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
96 move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
97 move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
98 move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
99 move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
100 move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
101 move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
102 setorigin(e, e.origin);
104 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
107 dprint("could not get out of solid (", vtos(o), ")\n");
112 string STR_PLAYER = "player";
115 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
116 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
117 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
118 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
120 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
121 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
122 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
123 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
124 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
127 // copies a string to a tempstring (so one can strunzone it)
128 string strcat1(string s) = #115; // FRIK_FILE
133 void bcenterprint(string s)
135 // TODO replace by MSG_ALL (would show it to spectators too, though)?
137 FOR_EACH_PLAYER(head)
138 if(clienttype(head) == CLIENTTYPE_REAL)
139 centerprint(head, s);
142 void ServerConsoleEcho(string s, float check_dangerous)
145 if (checkextension("DP_SV_PRINT"))
154 ch = substring(s, 0, 1);
155 if(ch != "\"" && ch != "\r" && ch != "\n")
157 s = substring(s, 1, strlen(s) - 1);
168 void GameLogEcho(string s, float check_dangerous)
173 if(cvar("sv_eventlog_files"))
178 matches = cvar("sv_eventlog_files_counter") + 1;
179 cvar_set("sv_eventlog_files_counter", ftos(matches));
182 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
183 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
184 logfile = fopen(fn, FILE_APPEND);
185 fputs(logfile, ":logversion:2\n");
189 if(cvar("sv_eventlog_files_timestamps"))
190 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
192 fputs(logfile, strcat(s, "\n"));
195 if(cvar("sv_eventlog_console"))
197 ServerConsoleEcho(s, check_dangerous);
204 // will be opened later
209 if(logfile_open && logfile >= 0)
216 float spawnpoint_nag;
217 void relocate_spawnpoint()
219 // nudge off the floor
220 setorigin(self, self.origin + '0 0 1');
222 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
223 if (trace_startsolid)
229 move_out_of_solid(self);
230 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
231 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
232 print(" ", ftos(self.origin_y - o_y));
233 print(" ", ftos(self.origin_z - o_z), "'\n");
234 if(cvar("g_spawnpoints_auto_move_out_of_solid"))
237 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
243 self.mins = self.maxs = '0 0 0';
244 objerror("player spawn point in solid, mapper sucks!\n");
249 if(cvar("g_spawnpoints_autodrop"))
251 setsize(self, PL_MIN, PL_MAX);
255 self.use = spawnpoint_use;
256 self.team_saved = self.team;
260 if(g_ctf || g_assault || g_onslaught || g_domination)
262 have_team_spawns = 1;
264 if(cvar("r_showbboxes"))
266 // show where spawnpoints point at too
267 makevectors(self.angles);
270 e.classname = "info_player_foo";
271 setorigin(e, self.origin + v_forward * 24);
272 setsize(e, '-8 -8 -8', '8 8 8');
273 e.solid = SOLID_TRIGGER;
277 #define strstr strstrofs
279 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
280 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
281 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
282 // BE CONSTANT OR strzoneD!
283 float strstr(string haystack, string needle, float offset)
287 len = strlen(needle);
288 endpos = strlen(haystack) - len;
289 while(offset <= endpos)
291 found = substring(haystack, offset, len);
300 float NUM_NEAREST_ENTITIES = 4;
301 entity nearest_entity[NUM_NEAREST_ENTITIES];
302 float nearest_length[NUM_NEAREST_ENTITIES];
303 entity findnearest(vector point, .string field, string value, vector axismod)
314 localhead = find(world, field, value);
317 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
318 dist = localhead.oldorigin;
320 dist = localhead.origin;
322 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
325 for(i = 0; i < num_nearest; ++i)
327 if(len < nearest_length[i])
331 // now i tells us where to insert at
332 // INSERTION SORT! YOU'VE SEEN IT! RUN!
333 if(i < NUM_NEAREST_ENTITIES)
335 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
337 nearest_length[j + 1] = nearest_length[j];
338 nearest_entity[j + 1] = nearest_entity[j];
340 nearest_length[i] = len;
341 nearest_entity[i] = localhead;
342 if(num_nearest < NUM_NEAREST_ENTITIES)
343 num_nearest = num_nearest + 1;
346 localhead = find(localhead, field, value);
349 // now use the first one from our list that we can see
350 for(i = 0; i < num_nearest; ++i)
352 traceline(point, nearest_entity[i].origin, TRUE, world);
353 if(trace_fraction == 1)
357 dprint("Nearest point (");
358 dprint(nearest_entity[0].netname);
359 dprint(") is not visible, using a visible one.\n");
361 return nearest_entity[i];
368 dprint("Not seeing any location point, using nearest as fallback.\n");
370 dprint("Candidates were: ");
371 for(j = 0; j < num_nearest; ++j)
375 dprint(nearest_entity[j].netname);
380 return nearest_entity[0];
383 void spawnfunc_target_location()
385 self.classname = "target_location";
386 // location name in netname
387 // eventually support: count, teamgame selectors, line of sight?
390 void spawnfunc_info_location()
392 self.classname = "target_location";
393 self.message = self.netname;
396 string NearestLocation(vector p)
401 loc = findnearest(p, classname, "target_location", '1 1 1');
408 loc = findnearest(p, target, "###item###", '1 1 4');
415 string formatmessage(string msg)
422 msg_save = strzone(msg);
428 break; // too many replacements
430 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
433 replacement = substring(msg_save, p, 2);
434 escape = substring(msg_save, p + 1, 1);
437 else if(escape == "a")
438 replacement = ftos(floor(self.armorvalue));
439 else if(escape == "h")
440 replacement = ftos(floor(self.health));
441 else if(escape == "l")
442 replacement = NearestLocation(self.origin);
443 else if(escape == "y")
444 replacement = NearestLocation(self.cursor_trace_endpos);
445 else if(escape == "d")
446 replacement = NearestLocation(self.death_origin);
447 else if(escape == "w")
452 wep = self.switchweapon;
455 replacement = W_Name(wep);
457 else if(escape == "W")
459 if(self.items & IT_SHELLS) replacement = "shells";
460 else if(self.items & IT_NAILS) replacement = "bullets";
461 else if(self.items & IT_ROCKETS) replacement = "rockets";
462 else if(self.items & IT_CELLS) replacement = "cells";
463 else replacement = "batteries"; // ;)
465 else if(escape == "x")
467 replacement = self.cursor_trace_ent.netname;
468 if(!replacement || !self.cursor_trace_ent)
469 replacement = "nothing";
471 else if(escape == "p")
473 if(self.last_selected_player)
474 replacement = self.last_selected_player.netname;
476 replacement = "(nobody)";
478 msg = strcat(substring(msg_save, 0, p), replacement);
479 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
481 msg_save = strzone(msg);
484 msg = strcat(msg_save, "");
495 >0: receives a cvar from name=argv(f) value=argv(f+1)
497 void GetCvars_handleString(float f, .string field, string name)
502 strunzone(self.field);
509 strunzone(self.field);
510 self.field = strzone(argv(f + 1));
514 stuffcmd(self, strcat("sendcvar ", name, "\n"));
516 void GetCvars_handleFloat(float f, .float field, string name)
524 self.field = stof(argv(f + 1));
527 stuffcmd(self, strcat("sendcvar ", name, "\n"));
529 void GetCvars(float f)
531 GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
532 GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
533 GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
534 GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
535 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
536 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
537 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
538 GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
539 GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
540 GetCvars_handleFloat(f, cvar_cl_handicap, "cl_handicap");
543 float fexists(string f)
546 fh = fopen(f, FILE_READ);
553 void backtrace(string msg)
556 dev = cvar("developer");
557 cvar_set("developer", "1");
559 dprint("--- CUT HERE ---\nWARNING: ");
562 remove(world); // isn't there any better way to cause a backtrace?
563 dprint("\n--- CUT UNTIL HERE ---\n");
564 cvar_set("developer", ftos(dev));
567 string Team_ColorCode(float teamid)
569 if(teamid == COLOR_TEAM1)
571 else if(teamid == COLOR_TEAM2)
573 else if(teamid == COLOR_TEAM3)
575 else if(teamid == COLOR_TEAM4)
580 string Team_ColorName(float t)
582 // fixme: Search for team entities and get their .netname's!
593 string Team_ColorNameLowerCase(float t)
595 // fixme: Search for team entities and get their .netname's!
607 #define CENTERPRIO_POINT 1
608 #define CENTERPRIO_SPAM 2
609 #define CENTERPRIO_REBALANCE 2
610 #define CENTERPRIO_VOTE 4
611 #define CENTERPRIO_NORMAL 5
612 #define CENTERPRIO_MAPVOTE 9
613 #define CENTERPRIO_IDLEKICK 50
614 #define CENTERPRIO_ADMIN 99
615 .float centerprint_priority;
616 .float centerprint_expires;
617 void centerprint_atprio(entity e, float prio, string s)
619 if(intermission_running)
620 if(prio < CENTERPRIO_MAPVOTE)
622 if(time > e.centerprint_expires)
623 e.centerprint_priority = 0;
624 if(prio >= e.centerprint_priority)
626 e.centerprint_priority = prio;
627 if(timeoutStatus == 2)
628 e.centerprint_expires = time + (e.cvar_scr_centertime * TIMEOUT_SLOWMO_VALUE);
630 e.centerprint_expires = time + e.cvar_scr_centertime;
631 centerprint_builtin(e, s);
634 void centerprint_expire(entity e, float prio)
636 if(prio == e.centerprint_priority)
638 e.centerprint_priority = 0;
639 centerprint_builtin(e, "");
642 void centerprint(entity e, string s)
644 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
649 // decolorizes and team colors the player name when needed
650 string playername(entity p)
653 if(teams_matter && !intermission_running && p.classname == "player")
655 t = Team_ColorCode(p.team);
656 return strcat(t, strdecolorize(p.netname));
662 vector randompos(vector m1, vector m2)
666 v_x = m2_x * random() + m1_x;
667 v_y = m2_y * random() + m1_y;
668 v_z = m2_z * random() + m1_z;
672 // requires that m2>m1 in all coordinates, and that m4>m3
673 float boxesoverlap(vector m1, vector m2, vector m3, vector m4) {return m2_x >= m3_x && m1_x <= m4_x && m2_y >= m3_y && m1_y <= m4_y && m2_z >= m3_z && m1_z <= m4_z;};
675 // requires the same, but is a stronger condition
676 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) {return smins_x >= bmins_x && smaxs_x <= bmaxs_x && smins_y >= bmins_y && smaxs_y <= bmaxs_y && smins_z >= bmins_z && smaxs_z <= bmaxs_z;};
678 float g_pickup_shells;
679 float g_pickup_shells_max;
680 float g_pickup_nails;
681 float g_pickup_nails_max;
682 float g_pickup_rockets;
683 float g_pickup_rockets_max;
684 float g_pickup_cells;
685 float g_pickup_cells_max;
686 float g_pickup_armorsmall;
687 float g_pickup_armorsmall_max;
688 float g_pickup_armormedium;
689 float g_pickup_armormedium_max;
690 float g_pickup_armorlarge;
691 float g_pickup_armorlarge_max;
692 float g_pickup_healthsmall;
693 float g_pickup_healthsmall_max;
694 float g_pickup_healthmedium;
695 float g_pickup_healthmedium_max;
696 float g_pickup_healthlarge;
697 float g_pickup_healthlarge_max;
698 float g_pickup_healthmega;
699 float g_pickup_healthmega_max;
702 float start_switchweapon;
703 float start_ammo_shells;
704 float start_ammo_nails;
705 float start_ammo_rockets;
706 float start_ammo_cells;
708 float start_armorvalue;
710 void readlevelcvars(void)
712 sv_cheats = cvar("sv_cheats");
713 sv_gentle = cvar("sv_gentle");
714 sv_foginterval = cvar("sv_foginterval");
715 g_cloaked = cvar("g_cloaked");
716 g_jump_grunt = cvar("g_jump_grunt");
717 g_footsteps = cvar("g_footsteps");
718 g_grappling_hook = cvar("g_grappling_hook");
719 g_instagib = cvar("g_instagib");
720 g_laserguided_missile = cvar("g_laserguided_missile");
721 g_midair = cvar("g_midair");
722 g_minstagib = cvar("g_minstagib");
723 g_nixnex = cvar("g_nixnex");
724 g_nixnex_with_laser = cvar("g_nixnex_with_laser");
725 g_norecoil = cvar("g_norecoil");
726 g_rocketarena = cvar("g_rocketarena");
727 g_vampire = cvar("g_vampire");
728 g_tourney = cvar("g_tourney");
729 sv_maxidle = cvar("sv_maxidle");
730 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
731 sv_pogostick = cvar("sv_pogostick");
732 sv_doublejump = cvar("sv_doublejump");
733 g_ctf_win_mode = cvar("g_ctf_win_mode");
734 g_race_qualifying = cvar("g_race_qualifying");
736 g_pickup_shells = cvar("g_pickup_shells");
737 g_pickup_shells_max = cvar("g_pickup_shells_max");
738 g_pickup_nails = cvar("g_pickup_nails");
739 g_pickup_nails_max = cvar("g_pickup_nails_max");
740 g_pickup_rockets = cvar("g_pickup_rockets");
741 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
742 g_pickup_cells = cvar("g_pickup_cells");
743 g_pickup_cells_max = cvar("g_pickup_cells_max");
744 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
745 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
746 g_pickup_armormedium = cvar("g_pickup_armormedium");
747 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
748 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
749 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
750 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
751 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
752 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
753 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
754 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
755 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
756 g_pickup_healthmega = cvar("g_pickup_healthmega");
757 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
759 // initialize starting values for players
761 start_switchweapon = 0;
762 start_ammo_shells = 0;
763 start_ammo_nails = 0;
764 start_ammo_rockets = 0;
765 start_ammo_cells = 0;
766 start_health = cvar("g_balance_health_start");
767 start_armorvalue = cvar("g_balance_armor_start");
771 start_items = IT_NEX;
772 start_switchweapon = WEP_NEX;
773 weapon_action(start_switchweapon, WR_PRECACHE);
774 start_ammo_cells = 999;
776 else if(g_rocketarena)
778 start_items = IT_ROCKET_LAUNCHER;
779 start_switchweapon = WEP_ROCKET_LAUNCHER;
780 weapon_action(start_switchweapon, WR_PRECACHE);
781 start_ammo_rockets = 999;
786 // will be done later
791 start_armorvalue = 0;
792 start_items = IT_NEX;
793 start_switchweapon = WEP_NEX;
794 weapon_action(start_switchweapon, WR_PRECACHE);
795 start_ammo_cells = cvar("g_minstagib_ammo_start");
796 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
802 start_ammo_shells = cvar("g_lms_start_ammo_shells");
803 start_ammo_nails = cvar("g_lms_start_ammo_nails");
804 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
805 start_ammo_cells = cvar("g_lms_start_ammo_cells");
806 start_health = cvar("g_lms_start_health");
807 start_armorvalue = cvar("g_lms_start_armor");
810 start_ammo_shells = cvar("g_tourney_start_ammo_shells");
811 start_ammo_nails = cvar("g_tourney_start_ammo_nails");
812 start_ammo_rockets = cvar("g_tourney_start_ammo_rockets");
813 start_ammo_cells = cvar("g_tourney_start_ammo_cells");
814 start_health = cvar("g_tourney_start_health");
815 start_armorvalue = cvar("g_tourney_start_armor");
817 else if (cvar("g_use_ammunition")) {
818 start_ammo_shells = cvar("g_start_ammo_shells");
819 start_ammo_nails = cvar("g_start_ammo_nails");
820 start_ammo_rockets = cvar("g_start_ammo_rockets");
821 start_ammo_cells = cvar("g_start_ammo_cells");
823 start_ammo_shells = cvar("g_pickup_shells_max");
824 start_ammo_nails = cvar("g_pickup_nails_max");
825 start_ammo_rockets = cvar("g_pickup_rockets_max");
826 start_ammo_cells = cvar("g_pickup_cells_max");
829 if (cvar("g_start_weapon_laser") || g_lms)
831 start_items = start_items | IT_LASER;
832 start_switchweapon = WEP_LASER;
833 weapon_action(start_switchweapon, WR_PRECACHE);
835 if (cvar("g_start_weapon_shotgun") || g_lms)
837 start_items = start_items | IT_SHOTGUN;
838 start_switchweapon = WEP_SHOTGUN;
839 weapon_action(start_switchweapon, WR_PRECACHE);
841 if (cvar("g_start_weapon_uzi") || g_lms || g_tourney)
843 start_items = start_items | IT_UZI;
844 start_switchweapon = WEP_UZI;
845 weapon_action(start_switchweapon, WR_PRECACHE);
847 if (cvar("g_start_weapon_grenadelauncher") || g_lms || g_tourney)
849 start_items = start_items | IT_GRENADE_LAUNCHER;
850 start_switchweapon = WEP_GRENADE_LAUNCHER;
851 weapon_action(start_switchweapon, WR_PRECACHE);
853 if (cvar("g_start_weapon_electro") || g_lms || g_tourney)
855 start_items = start_items | IT_ELECTRO;
856 start_switchweapon = WEP_ELECTRO;
857 weapon_action(start_switchweapon, WR_PRECACHE);
859 if (cvar("g_start_weapon_crylink") || g_lms || g_tourney)
861 start_items = start_items | IT_CRYLINK;
862 start_switchweapon = WEP_CRYLINK;
863 weapon_action(start_switchweapon, WR_PRECACHE);
865 if (cvar("g_start_weapon_nex") || g_lms || g_tourney)
867 start_items = start_items | IT_NEX;
868 start_switchweapon = WEP_NEX;
869 weapon_action(start_switchweapon, WR_PRECACHE);
871 if (cvar("g_start_weapon_hagar") || g_lms || g_tourney)
873 start_items = start_items | IT_HAGAR;
874 start_switchweapon = WEP_HAGAR;
875 weapon_action(start_switchweapon, WR_PRECACHE);
877 if (cvar("g_start_weapon_rocketlauncher") || g_lms || g_tourney)
879 start_items = start_items | IT_ROCKET_LAUNCHER;
880 start_switchweapon = WEP_ROCKET_LAUNCHER;
881 weapon_action(start_switchweapon, WR_PRECACHE);
887 // TODO sound pack system
890 string precache_sound_builtin (string s) = #19;
891 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
892 string precache_sound(string s)
894 return precache_sound_builtin(strcat(soundpack, s));
896 void play2(entity e, string filename)
898 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
900 void sound(entity e, float chan, string samp, float vol, float atten)
902 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
907 string precache_sound (string s) = #19;
908 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
909 float precache_sound_index (string s) = #19;
911 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
914 WriteByte(dest, 27); // all bits except SND_LOOPING
915 WriteByte(dest, vol * 255);
916 WriteByte(dest, atten * 64);
917 WriteEntity(dest, e);
918 WriteByte(dest, chan);
919 WriteShort(dest, precache_sound_index(samp));
920 WriteCoord(dest, o_x);
921 WriteCoord(dest, o_y);
922 WriteCoord(dest, o_z);
924 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
927 o = e.origin + 0.5 * (e.mins + e.maxs);
928 soundtoat(dest, e, o, chan, samp, vol, atten);
930 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
932 soundtoat(MSG_BROADCAST, e, o, chan, samp, vol, atten);
935 void play2(entity e, string filename)
937 //stuffcmd(e, strcat("play2 ", filename, "\n"));
939 soundtoat(MSG_ONE, world, '0 0 0', CHAN_AUTO, filename, VOL_BASE, ATTN_NONE);
943 void announce(entity player, string msg)
945 if(time > player.announcetime)
946 if(clienttype(player) == CLIENTTYPE_REAL)
948 player.announcetime = time + 0.3;
953 void play2team(float t, string filename)
956 FOR_EACH_REALPLAYER(head)
959 play2(head, filename);
963 void play2all(string samp)
965 sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
968 void PrecachePlayerSounds(string f);
969 void precache_all_models(string pattern)
971 float globhandle, i, n;
974 globhandle = search_begin(pattern, TRUE, FALSE);
977 n = search_getsize(globhandle);
978 for(i = 0; i < n; ++i)
980 //print(search_getfilename(globhandle, i), "\n");
981 f = search_getfilename(globhandle, i);
983 PrecachePlayerSounds(strcat(f, ".sounds"));
985 search_end(globhandle);
990 // gamemode related things
991 precache_model ("models/misc/chatbubble.spr");
992 precache_model ("models/misc/teambubble.spr");
995 precache_model ("models/runematch/curse.mdl");
996 precache_model ("models/runematch/rune.mdl");
999 // Precache all player models if desired
1000 if (cvar("sv_precacheplayermodels"))
1002 PrecachePlayerSounds("sound/player/default.sounds");
1003 precache_all_models("models/player/*.zym");
1004 precache_all_models("models/player/*.dpm");
1005 precache_all_models("models/player/*.md3");
1006 precache_all_models("models/player/*.psk");
1007 //precache_model("models/player/carni.zym");
1008 //precache_model("models/player/crash.zym");
1009 //precache_model("models/player/grunt.zym");
1010 //precache_model("models/player/headhunter.zym");
1011 //precache_model("models/player/insurrectionist.zym");
1012 //precache_model("models/player/jeandarc.zym");
1013 //precache_model("models/player/lurk.zym");
1014 //precache_model("models/player/lycanthrope.zym");
1015 //precache_model("models/player/marine.zym");
1016 //precache_model("models/player/nexus.zym");
1017 //precache_model("models/player/pyria.zym");
1018 //precache_model("models/player/shock.zym");
1019 //precache_model("models/player/skadi.zym");
1020 //precache_model("models/player/specop.zym");
1021 //precache_model("models/player/visitant.zym");
1026 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1027 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1030 // gore and miscellaneous sounds
1031 //precache_sound ("misc/h2ohit.wav");
1032 precache_model ("models/gibs/bloodyskull.md3");
1033 precache_model ("models/gibs/chunk.mdl");
1034 precache_model ("models/gibs/eye.md3");
1035 precache_model ("models/gibs/gib1.md3");
1036 precache_model ("models/gibs/gib2.md3");
1037 precache_model ("models/gibs/gib3.md3");
1038 precache_model ("models/gibs/gib4.md3");
1039 precache_model ("models/gibs/gib5.md3");
1040 precache_model ("models/gibs/gib6.md3");
1041 precache_model ("models/gibs/smallchest.md3");
1042 precache_model ("models/gibs/chest.md3");
1043 precache_model ("models/gibs/arm.md3");
1044 precache_model ("models/gibs/leg1.md3");
1045 precache_model ("models/gibs/leg2.md3");
1046 precache_model ("models/hook.md3");
1047 precache_sound ("misc/armorimpact.wav");
1048 precache_sound ("misc/bodyimpact1.wav");
1049 precache_sound ("misc/bodyimpact2.wav");
1050 precache_sound ("misc/gib.wav");
1051 precache_sound ("misc/gib_splat01.wav");
1052 precache_sound ("misc/gib_splat02.wav");
1053 precache_sound ("misc/gib_splat03.wav");
1054 precache_sound ("misc/gib_splat04.wav");
1055 precache_sound ("misc/hit.wav");
1056 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1057 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1058 precache_sound ("misc/null.wav");
1059 precache_sound ("misc/spawn.wav");
1060 precache_sound ("misc/talk.wav");
1061 precache_sound ("misc/teleport.wav");
1062 precache_sound ("player/lava.wav");
1063 precache_sound ("player/slime.wav");
1065 // announcer sounds - male
1066 //precache_sound ("announcer/male/electrobitch.wav");
1067 precache_sound ("announcer/male/03kills.wav");
1068 precache_sound ("announcer/male/05kills.wav");
1069 precache_sound ("announcer/male/10kills.wav");
1070 precache_sound ("announcer/male/15kills.wav");
1071 precache_sound ("announcer/male/20kills.wav");
1072 precache_sound ("announcer/male/25kills.wav");
1073 precache_sound ("announcer/male/30kills.wav");
1074 precache_sound ("announcer/male/botlike.wav");
1075 precache_sound ("announcer/male/yoda.wav");
1077 // announcer sounds - robotic
1078 precache_sound ("announcer/robotic/prepareforbattle.wav");
1079 precache_sound ("announcer/robotic/begin.wav");
1080 precache_sound ("announcer/robotic/timeoutcalled.wav");
1081 precache_sound ("announcer/robotic/1fragleft.wav");
1082 precache_sound ("announcer/robotic/1minuteremains.wav");
1083 precache_sound ("announcer/robotic/2fragsleft.wav");
1084 precache_sound ("announcer/robotic/3fragsleft.wav");
1087 precache_sound ("announcer/robotic/lastsecond.wav");
1088 precache_sound ("announcer/robotic/narrowly.wav");
1091 precache_model ("models/sprites/1.spr32");
1092 precache_model ("models/sprites/2.spr32");
1093 precache_model ("models/sprites/3.spr32");
1094 precache_model ("models/sprites/4.spr32");
1095 precache_model ("models/sprites/5.spr32");
1096 precache_model ("models/sprites/6.spr32");
1097 precache_model ("models/sprites/7.spr32");
1098 precache_model ("models/sprites/8.spr32");
1099 precache_model ("models/sprites/9.spr32");
1100 precache_model ("models/sprites/10.spr32");
1101 precache_sound ("announcer/robotic/1.ogg");
1102 precache_sound ("announcer/robotic/2.ogg");
1103 precache_sound ("announcer/robotic/3.ogg");
1104 precache_sound ("announcer/robotic/4.ogg");
1105 precache_sound ("announcer/robotic/5.ogg");
1106 precache_sound ("announcer/robotic/6.ogg");
1107 precache_sound ("announcer/robotic/7.ogg");
1108 precache_sound ("announcer/robotic/8.ogg");
1109 precache_sound ("announcer/robotic/9.ogg");
1110 precache_sound ("announcer/robotic/10.ogg");
1112 // common weapon precaches
1113 precache_sound ("weapons/weapon_switch.wav");
1114 precache_sound ("weapons/weaponpickup.wav");
1115 if (cvar("g_grappling_hook"))
1117 precache_sound ("weapons/hook_fire.wav"); // hook
1118 precache_sound ("weapons/hook_impact.wav"); // hook
1121 if (cvar("sv_precacheweapons") || g_nixnex)
1123 //precache weapon models/sounds
1126 while (wep <= WEP_LAST)
1128 weapon_action(wep, WR_PRECACHE);
1133 // plays music for the level if there is any
1136 precache_sound (self.noise);
1137 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);