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 float move_out_of_solid(entity e)
81 traceline(o, o, MOVE_WORLDONLY, e);
85 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
93 move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
94 move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
95 move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
96 move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
97 move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
98 move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
99 setorigin(e, e.origin);
101 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
108 string STR_PLAYER = "player";
109 string STR_SPECTATOR = "spectator";
110 string STR_OBSERVER = "observer";
113 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
114 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
115 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
116 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
118 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
119 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
120 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
121 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
122 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
125 // copies a string to a tempstring (so one can strunzone it)
126 string strcat1(string s) = #115; // FRIK_FILE
131 void bcenterprint(string s)
133 // TODO replace by MSG_ALL (would show it to spectators too, though)?
135 FOR_EACH_PLAYER(head)
136 if(clienttype(head) == CLIENTTYPE_REAL)
137 centerprint(head, s);
140 void GameLogEcho(string s)
145 if(cvar("sv_eventlog_files"))
150 matches = cvar("sv_eventlog_files_counter") + 1;
151 cvar_set("sv_eventlog_files_counter", ftos(matches));
154 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
155 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
156 logfile = fopen(fn, FILE_APPEND);
157 fputs(logfile, ":logversion:2\n");
161 if(cvar("sv_eventlog_files_timestamps"))
162 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
164 fputs(logfile, strcat(s, "\n"));
167 if(cvar("sv_eventlog_console"))
176 // will be opened later
181 if(logfile_open && logfile >= 0)
188 float spawnpoint_nag;
189 void relocate_spawnpoint()
191 // nudge off the floor
192 setorigin(self, self.origin + '0 0 1');
194 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
195 if (trace_startsolid)
201 if(!move_out_of_solid(self))
202 objerror("could not get out of solid at all!");
203 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
204 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
205 print(" ", ftos(self.origin_y - o_y));
206 print(" ", ftos(self.origin_z - o_z), "'\n");
207 if(cvar("g_spawnpoints_auto_move_out_of_solid"))
210 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
216 self.mins = self.maxs = '0 0 0';
217 objerror("player spawn point in solid, mapper sucks!\n");
222 if(cvar("g_spawnpoints_autodrop"))
224 setsize(self, PL_MIN, PL_MAX);
228 self.use = spawnpoint_use;
229 self.team_saved = self.team;
233 if(g_ctf || g_assault || g_onslaught || g_domination)
235 have_team_spawns = 1;
237 if(cvar("r_showbboxes"))
239 // show where spawnpoints point at too
240 makevectors(self.angles);
243 e.classname = "info_player_foo";
244 setorigin(e, self.origin + v_forward * 24);
245 setsize(e, '-8 -8 -8', '8 8 8');
246 e.solid = SOLID_TRIGGER;
250 #define strstr strstrofs
252 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
253 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
254 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
255 // BE CONSTANT OR strzoneD!
256 float strstr(string haystack, string needle, float offset)
260 len = strlen(needle);
261 endpos = strlen(haystack) - len;
262 while(offset <= endpos)
264 found = substring(haystack, offset, len);
273 float NUM_NEAREST_ENTITIES = 4;
274 entity nearest_entity[NUM_NEAREST_ENTITIES];
275 float nearest_length[NUM_NEAREST_ENTITIES];
276 entity findnearest(vector point, .string field, string value, vector axismod)
287 localhead = find(world, field, value);
290 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
291 dist = localhead.oldorigin;
293 dist = localhead.origin;
295 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
298 for(i = 0; i < num_nearest; ++i)
300 if(len < nearest_length[i])
304 // now i tells us where to insert at
305 // INSERTION SORT! YOU'VE SEEN IT! RUN!
306 if(i < NUM_NEAREST_ENTITIES)
308 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
310 nearest_length[j + 1] = nearest_length[j];
311 nearest_entity[j + 1] = nearest_entity[j];
313 nearest_length[i] = len;
314 nearest_entity[i] = localhead;
315 if(num_nearest < NUM_NEAREST_ENTITIES)
316 num_nearest = num_nearest + 1;
319 localhead = find(localhead, field, value);
322 // now use the first one from our list that we can see
323 for(i = 0; i < num_nearest; ++i)
325 traceline(point, nearest_entity[i].origin, TRUE, world);
326 if(trace_fraction == 1)
330 dprint("Nearest point (");
331 dprint(nearest_entity[0].netname);
332 dprint(") is not visible, using a visible one.\n");
334 return nearest_entity[i];
341 dprint("Not seeing any location point, using nearest as fallback.\n");
343 dprint("Candidates were: ");
344 for(j = 0; j < num_nearest; ++j)
348 dprint(nearest_entity[j].netname);
353 return nearest_entity[0];
356 void spawnfunc_target_location()
358 self.classname = "target_location";
359 // location name in netname
360 // eventually support: count, teamgame selectors, line of sight?
363 void spawnfunc_info_location()
365 self.classname = "target_location";
366 self.message = self.netname;
369 string NearestLocation(vector p)
374 loc = findnearest(p, classname, "target_location", '1 1 1');
381 loc = findnearest(p, target, "###item###", '1 1 4');
388 string formatmessage(string msg)
395 msg_save = strzone(msg);
401 break; // too many replacements
403 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
406 replacement = substring(msg_save, p, 2);
407 escape = substring(msg_save, p + 1, 1);
410 else if(escape == "a")
411 replacement = ftos(floor(self.armorvalue));
412 else if(escape == "h")
413 replacement = ftos(floor(self.health));
414 else if(escape == "l")
415 replacement = NearestLocation(self.origin);
416 else if(escape == "y")
417 replacement = NearestLocation(self.cursor_trace_endpos);
418 else if(escape == "d")
419 replacement = NearestLocation(self.death_origin);
420 else if(escape == "w")
425 wep = self.switchweapon;
428 replacement = W_Name(wep);
430 else if(escape == "W")
432 if(self.items & IT_SHELLS) replacement = "shells";
433 else if(self.items & IT_NAILS) replacement = "bullets";
434 else if(self.items & IT_ROCKETS) replacement = "rockets";
435 else if(self.items & IT_CELLS) replacement = "cells";
436 else replacement = "batteries"; // ;)
438 else if(escape == "x")
440 replacement = self.cursor_trace_ent.netname;
441 if(!replacement || !self.cursor_trace_ent)
442 replacement = "nothing";
444 else if(escape == "p")
446 if(self.last_selected_player)
447 replacement = self.last_selected_player.netname;
449 replacement = "(nobody)";
451 msg = strcat(substring(msg_save, 0, p), replacement);
452 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
454 msg_save = strzone(msg);
457 msg = strcat(msg_save, "");
468 >0: receives a cvar from name=argv(f) value=argv(f+1)
470 void GetCvars_handleString(float f, .string field, string name)
475 strunzone(self.field);
482 strunzone(self.field);
483 self.field = strzone(argv(f + 1));
487 stuffcmd(self, strcat("sendcvar ", name, "\n"));
489 void GetCvars_handleString_Fixup(float f, .string field, string name, string(string) func)
491 GetCvars_handleString(f, field, name);
492 if(f >= 0) // also initialize to the fitting value for "" when sending cvars out
496 s = func(strcat1(self.field));
499 strunzone(self.field);
500 self.field = strzone(s);
504 void GetCvars_handleFloat(float f, .float field, string name)
512 self.field = stof(argv(f + 1));
515 stuffcmd(self, strcat("sendcvar ", name, "\n"));
517 string W_FixWeaponOrder_ForceComplete(string s);
518 string W_FixWeaponOrder_AllowIncomplete(string s);
519 void GetCvars(float f)
521 GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
522 GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
523 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
524 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
525 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
526 GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
527 GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
528 GetCvars_handleFloat(f, cvar_cl_handicap, "cl_handicap");
529 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
530 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
531 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
532 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
533 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
534 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
535 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
536 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
537 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
538 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
539 GetCvars_handleString_Fixup(f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
542 float fexists(string f)
545 fh = fopen(f, FILE_READ);
552 void backtrace(string msg)
555 dev = cvar("developer");
556 cvar_set("developer", "1");
558 dprint("--- CUT HERE ---\nWARNING: ");
561 remove(world); // isn't there any better way to cause a backtrace?
562 dprint("\n--- CUT UNTIL HERE ---\n");
563 cvar_set("developer", ftos(dev));
566 string Team_ColorCode(float teamid)
568 if(teamid == COLOR_TEAM1)
570 else if(teamid == COLOR_TEAM2)
572 else if(teamid == COLOR_TEAM3)
574 else if(teamid == COLOR_TEAM4)
579 string Team_ColorName(float t)
581 // fixme: Search for team entities and get their .netname's!
592 string Team_ColorNameLowerCase(float t)
594 // fixme: Search for team entities and get their .netname's!
606 #define CENTERPRIO_POINT 1
607 #define CENTERPRIO_SPAM 2
608 #define CENTERPRIO_REBALANCE 2
609 #define CENTERPRIO_VOTE 4
610 #define CENTERPRIO_NORMAL 5
611 #define CENTERPRIO_MAPVOTE 9
612 #define CENTERPRIO_IDLEKICK 50
613 #define CENTERPRIO_ADMIN 99
614 .float centerprint_priority;
615 .float centerprint_expires;
616 void centerprint_atprio(entity e, float prio, string s)
618 if(intermission_running)
619 if(prio < CENTERPRIO_MAPVOTE)
621 if(time > e.centerprint_expires)
622 e.centerprint_priority = 0;
623 if(prio >= e.centerprint_priority)
625 e.centerprint_priority = prio;
626 if(timeoutStatus == 2)
627 e.centerprint_expires = time + (e.cvar_scr_centertime * TIMEOUT_SLOWMO_VALUE);
629 e.centerprint_expires = time + e.cvar_scr_centertime;
630 centerprint_builtin(e, s);
633 void centerprint_expire(entity e, float prio)
635 if(prio == e.centerprint_priority)
637 e.centerprint_priority = 0;
638 centerprint_builtin(e, "");
641 void centerprint(entity e, string s)
643 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
648 // decolorizes and team colors the player name when needed
649 string playername(entity p)
652 if(teams_matter && !intermission_running && p.classname == "player")
654 t = Team_ColorCode(p.team);
655 return strcat(t, strdecolorize(p.netname));
661 vector randompos(vector m1, vector m2)
665 v_x = m2_x * random() + m1_x;
666 v_y = m2_y * random() + m1_y;
667 v_z = m2_z * random() + m1_z;
671 // requires that m2>m1 in all coordinates, and that m4>m3
672 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;};
674 // requires the same, but is a stronger condition
675 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;};
677 float g_pickup_shells;
678 float g_pickup_shells_max;
679 float g_pickup_nails;
680 float g_pickup_nails_max;
681 float g_pickup_rockets;
682 float g_pickup_rockets_max;
683 float g_pickup_cells;
684 float g_pickup_cells_max;
685 float g_pickup_armorsmall;
686 float g_pickup_armorsmall_max;
687 float g_pickup_armormedium;
688 float g_pickup_armormedium_max;
689 float g_pickup_armorlarge;
690 float g_pickup_armorlarge_max;
691 float g_pickup_healthsmall;
692 float g_pickup_healthsmall_max;
693 float g_pickup_healthmedium;
694 float g_pickup_healthmedium_max;
695 float g_pickup_healthlarge;
696 float g_pickup_healthlarge_max;
697 float g_pickup_healthmega;
698 float g_pickup_healthmega_max;
701 float start_switchweapon;
702 float start_ammo_shells;
703 float start_ammo_nails;
704 float start_ammo_rockets;
705 float start_ammo_cells;
707 float start_armorvalue;
709 void readlevelcvars(void)
711 sv_cheats = cvar("sv_cheats");
712 sv_gentle = cvar("sv_gentle");
713 sv_foginterval = cvar("sv_foginterval");
714 g_cloaked = cvar("g_cloaked");
715 g_jump_grunt = cvar("g_jump_grunt");
716 g_footsteps = cvar("g_footsteps");
717 g_grappling_hook = cvar("g_grappling_hook");
718 g_instagib = cvar("g_instagib");
719 g_laserguided_missile = cvar("g_laserguided_missile");
720 g_midair = cvar("g_midair");
721 g_minstagib = cvar("g_minstagib");
722 g_nixnex = cvar("g_nixnex");
723 g_nixnex_with_laser = cvar("g_nixnex_with_laser");
724 g_norecoil = cvar("g_norecoil");
725 g_rocketarena = cvar("g_rocketarena");
726 g_vampire = cvar("g_vampire");
727 g_tourney = cvar("g_tourney");
728 sv_maxidle = cvar("sv_maxidle");
729 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
730 sv_pogostick = cvar("sv_pogostick");
731 sv_doublejump = cvar("sv_doublejump");
733 if(g_instagib) g_minstagib = g_nixnex = g_rocketarena = 0;
734 if(g_minstagib) g_nixnex = g_rocketarena = 0;
735 if(g_nixnex) g_rocketarena = 0;
737 g_pickup_shells = cvar("g_pickup_shells");
738 g_pickup_shells_max = cvar("g_pickup_shells_max");
739 g_pickup_nails = cvar("g_pickup_nails");
740 g_pickup_nails_max = cvar("g_pickup_nails_max");
741 g_pickup_rockets = cvar("g_pickup_rockets");
742 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
743 g_pickup_cells = cvar("g_pickup_cells");
744 g_pickup_cells_max = cvar("g_pickup_cells_max");
745 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
746 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
747 g_pickup_armormedium = cvar("g_pickup_armormedium");
748 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
749 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
750 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
751 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
752 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
753 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
754 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
755 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
756 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
757 g_pickup_healthmega = cvar("g_pickup_healthmega");
758 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
760 // initialize starting values for players
762 start_switchweapon = 0;
763 start_ammo_shells = 0;
764 start_ammo_nails = 0;
765 start_ammo_rockets = 0;
766 start_ammo_cells = 0;
767 start_health = cvar("g_balance_health_start");
768 start_armorvalue = cvar("g_balance_armor_start");
772 start_weapons = WEPBIT_NEX;
773 start_switchweapon = WEP_NEX;
774 weapon_action(start_switchweapon, WR_PRECACHE);
775 start_ammo_cells = 999;
777 else if(g_rocketarena)
779 start_weapons = WEPBIT_ROCKET_LAUNCHER;
780 start_switchweapon = WEP_ROCKET_LAUNCHER;
781 weapon_action(start_switchweapon, WR_PRECACHE);
782 start_ammo_rockets = 999;
787 // will be done later
792 start_armorvalue = 0;
793 start_weapons = WEPBIT_NEX;
794 start_switchweapon = WEP_NEX;
795 weapon_action(start_switchweapon, WR_PRECACHE);
796 start_ammo_cells = cvar("g_minstagib_ammo_start");
797 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
803 start_ammo_shells = cvar("g_lms_start_ammo_shells");
804 start_ammo_nails = cvar("g_lms_start_ammo_nails");
805 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
806 start_ammo_cells = cvar("g_lms_start_ammo_cells");
807 start_health = cvar("g_lms_start_health");
808 start_armorvalue = cvar("g_lms_start_armor");
811 start_ammo_shells = cvar("g_tourney_start_ammo_shells");
812 start_ammo_nails = cvar("g_tourney_start_ammo_nails");
813 start_ammo_rockets = cvar("g_tourney_start_ammo_rockets");
814 start_ammo_cells = cvar("g_tourney_start_ammo_cells");
815 start_health = cvar("g_tourney_start_health");
816 start_armorvalue = cvar("g_tourney_start_armor");
818 else if (cvar("g_use_ammunition")) {
819 start_ammo_shells = cvar("g_start_ammo_shells");
820 start_ammo_nails = cvar("g_start_ammo_nails");
821 start_ammo_rockets = cvar("g_start_ammo_rockets");
822 start_ammo_cells = cvar("g_start_ammo_cells");
824 start_ammo_shells = cvar("g_pickup_shells_max");
825 start_ammo_nails = cvar("g_pickup_nails_max");
826 start_ammo_rockets = cvar("g_pickup_rockets_max");
827 start_ammo_cells = cvar("g_pickup_cells_max");
830 // %weaponaddpoint (except for superweapons)
831 if (cvar("g_start_weapon_laser") || g_lms)
833 start_weapons = start_weapons | WEPBIT_LASER;
834 start_switchweapon = WEP_LASER;
835 weapon_action(start_switchweapon, WR_PRECACHE);
837 if (cvar("g_start_weapon_shotgun") || g_lms)
839 start_weapons = start_weapons | WEPBIT_SHOTGUN;
840 start_switchweapon = WEP_SHOTGUN;
841 weapon_action(start_switchweapon, WR_PRECACHE);
843 if (cvar("g_start_weapon_uzi") || g_lms || g_tourney)
845 start_weapons = start_weapons | WEPBIT_UZI;
846 start_switchweapon = WEP_UZI;
847 weapon_action(start_switchweapon, WR_PRECACHE);
849 if (cvar("g_start_weapon_grenadelauncher") || g_lms || g_tourney)
851 start_weapons = start_weapons | WEPBIT_GRENADE_LAUNCHER;
852 start_switchweapon = WEP_GRENADE_LAUNCHER;
853 weapon_action(start_switchweapon, WR_PRECACHE);
855 if (cvar("g_start_weapon_electro") || g_lms || g_tourney)
857 start_weapons = start_weapons | WEPBIT_ELECTRO;
858 start_switchweapon = WEP_ELECTRO;
859 weapon_action(start_switchweapon, WR_PRECACHE);
861 if (cvar("g_start_weapon_crylink") || g_lms || g_tourney)
863 start_weapons = start_weapons | WEPBIT_CRYLINK;
864 start_switchweapon = WEP_CRYLINK;
865 weapon_action(start_switchweapon, WR_PRECACHE);
867 if (cvar("g_start_weapon_nex") || g_lms || g_tourney)
869 start_weapons = start_weapons | WEPBIT_NEX;
870 start_switchweapon = WEP_NEX;
871 weapon_action(start_switchweapon, WR_PRECACHE);
873 if (cvar("g_start_weapon_hagar") || g_lms || g_tourney)
875 start_weapons = start_weapons | WEPBIT_HAGAR;
876 start_switchweapon = WEP_HAGAR;
877 weapon_action(start_switchweapon, WR_PRECACHE);
879 if (cvar("g_start_weapon_rocketlauncher") || g_lms || g_tourney)
881 start_weapons = start_weapons | WEPBIT_ROCKET_LAUNCHER;
882 start_switchweapon = WEP_ROCKET_LAUNCHER;
883 weapon_action(start_switchweapon, WR_PRECACHE);
889 // TODO sound pack system
892 string precache_sound_builtin (string s) = #19;
893 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
894 string precache_sound(string s)
896 return precache_sound_builtin(strcat(soundpack, s));
898 void play2(entity e, string filename)
900 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
902 void sound(entity e, float chan, string samp, float vol, float atten)
904 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
909 string precache_sound (string s) = #19;
910 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
911 float precache_sound_index (string s) = #19;
913 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
916 WriteByte(dest, 27); // all bits except SND_LOOPING
917 WriteByte(dest, vol * 255);
918 WriteByte(dest, atten * 64);
919 WriteEntity(dest, e);
920 WriteByte(dest, chan);
921 WriteShort(dest, precache_sound_index(samp));
922 WriteCoord(dest, o_x);
923 WriteCoord(dest, o_y);
924 WriteCoord(dest, o_z);
926 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
929 o = e.origin + 0.5 * (e.mins + e.maxs);
930 soundtoat(dest, e, o, chan, samp, vol, atten);
932 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
934 soundtoat(MSG_BROADCAST, e, o, chan, samp, vol, atten);
937 void play2(entity e, string filename)
939 //stuffcmd(e, strcat("play2 ", filename, "\n"));
941 soundtoat(MSG_ONE, world, '0 0 0', CHAN_AUTO, filename, VOL_BASE, ATTN_NONE);
945 void announce(entity player, string msg)
947 if(time > player.announcetime)
948 if(clienttype(player) == CLIENTTYPE_REAL)
950 player.announcetime = time + 0.3;
955 void play2team(float t, string filename)
958 FOR_EACH_REALPLAYER(head)
961 play2(head, filename);
965 void play2all(string samp)
967 sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
970 void PrecachePlayerSounds(string f);
971 void precache_all_models(string pattern)
973 float globhandle, i, n;
976 globhandle = search_begin(pattern, TRUE, FALSE);
979 n = search_getsize(globhandle);
980 for(i = 0; i < n; ++i)
982 //print(search_getfilename(globhandle, i), "\n");
983 f = search_getfilename(globhandle, i);
985 PrecachePlayerSounds(strcat(f, ".sounds"));
987 search_end(globhandle);
992 // gamemode related things
993 precache_model ("models/misc/chatbubble.spr");
994 precache_model ("models/misc/teambubble.spr");
997 precache_model ("models/runematch/curse.mdl");
998 precache_model ("models/runematch/rune.mdl");
1001 // Precache all player models if desired
1002 if (cvar("sv_precacheplayermodels"))
1004 PrecachePlayerSounds("sound/player/default.sounds");
1005 precache_all_models("models/player/*.zym");
1006 precache_all_models("models/player/*.dpm");
1007 precache_all_models("models/player/*.md3");
1008 precache_all_models("models/player/*.psk");
1009 //precache_model("models/player/carni.zym");
1010 //precache_model("models/player/crash.zym");
1011 //precache_model("models/player/grunt.zym");
1012 //precache_model("models/player/headhunter.zym");
1013 //precache_model("models/player/insurrectionist.zym");
1014 //precache_model("models/player/jeandarc.zym");
1015 //precache_model("models/player/lurk.zym");
1016 //precache_model("models/player/lycanthrope.zym");
1017 //precache_model("models/player/marine.zym");
1018 //precache_model("models/player/nexus.zym");
1019 //precache_model("models/player/pyria.zym");
1020 //precache_model("models/player/shock.zym");
1021 //precache_model("models/player/skadi.zym");
1022 //precache_model("models/player/specop.zym");
1023 //precache_model("models/player/visitant.zym");
1028 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1029 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1032 // gore and miscellaneous sounds
1033 //precache_sound ("misc/h2ohit.wav");
1034 precache_model ("models/gibs/bloodyskull.md3");
1035 precache_model ("models/gibs/chunk.mdl");
1036 precache_model ("models/gibs/eye.md3");
1037 precache_model ("models/gibs/gib1.md3");
1038 precache_model ("models/gibs/gib2.md3");
1039 precache_model ("models/gibs/gib3.md3");
1040 precache_model ("models/gibs/gib4.md3");
1041 precache_model ("models/gibs/gib5.md3");
1042 precache_model ("models/gibs/gib6.md3");
1043 precache_model ("models/gibs/smallchest.md3");
1044 precache_model ("models/gibs/chest.md3");
1045 precache_model ("models/gibs/arm.md3");
1046 precache_model ("models/gibs/leg1.md3");
1047 precache_model ("models/gibs/leg2.md3");
1048 precache_model ("models/hook.md3");
1049 precache_sound ("misc/armorimpact.wav");
1050 precache_sound ("misc/bodyimpact1.wav");
1051 precache_sound ("misc/bodyimpact2.wav");
1052 precache_sound ("misc/gib.wav");
1053 precache_sound ("misc/gib_splat01.wav");
1054 precache_sound ("misc/gib_splat02.wav");
1055 precache_sound ("misc/gib_splat03.wav");
1056 precache_sound ("misc/gib_splat04.wav");
1057 precache_sound ("misc/hit.wav");
1058 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1059 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1060 precache_sound ("misc/null.wav");
1061 precache_sound ("misc/spawn.wav");
1062 precache_sound ("misc/talk.wav");
1063 precache_sound ("misc/teleport.wav");
1064 precache_sound ("player/lava.wav");
1065 precache_sound ("player/slime.wav");
1067 // announcer sounds - male
1068 //precache_sound ("announcer/male/electrobitch.wav");
1069 precache_sound ("announcer/male/03kills.wav");
1070 precache_sound ("announcer/male/05kills.wav");
1071 precache_sound ("announcer/male/10kills.wav");
1072 precache_sound ("announcer/male/15kills.wav");
1073 precache_sound ("announcer/male/20kills.wav");
1074 precache_sound ("announcer/male/25kills.wav");
1075 precache_sound ("announcer/male/30kills.wav");
1076 precache_sound ("announcer/male/botlike.wav");
1077 precache_sound ("announcer/male/yoda.wav");
1079 // announcer sounds - robotic
1080 precache_sound ("announcer/robotic/prepareforbattle.wav");
1081 precache_sound ("announcer/robotic/begin.wav");
1082 precache_sound ("announcer/robotic/timeoutcalled.wav");
1083 precache_sound ("announcer/robotic/1fragleft.wav");
1084 precache_sound ("announcer/robotic/1minuteremains.wav");
1085 precache_sound ("announcer/robotic/2fragsleft.wav");
1086 precache_sound ("announcer/robotic/3fragsleft.wav");
1089 precache_sound ("announcer/robotic/lastsecond.wav");
1090 precache_sound ("announcer/robotic/narrowly.wav");
1093 precache_model ("models/sprites/1.spr32");
1094 precache_model ("models/sprites/2.spr32");
1095 precache_model ("models/sprites/3.spr32");
1096 precache_model ("models/sprites/4.spr32");
1097 precache_model ("models/sprites/5.spr32");
1098 precache_model ("models/sprites/6.spr32");
1099 precache_model ("models/sprites/7.spr32");
1100 precache_model ("models/sprites/8.spr32");
1101 precache_model ("models/sprites/9.spr32");
1102 precache_model ("models/sprites/10.spr32");
1103 precache_sound ("announcer/robotic/1.ogg");
1104 precache_sound ("announcer/robotic/2.ogg");
1105 precache_sound ("announcer/robotic/3.ogg");
1106 precache_sound ("announcer/robotic/4.ogg");
1107 precache_sound ("announcer/robotic/5.ogg");
1108 precache_sound ("announcer/robotic/6.ogg");
1109 precache_sound ("announcer/robotic/7.ogg");
1110 precache_sound ("announcer/robotic/8.ogg");
1111 precache_sound ("announcer/robotic/9.ogg");
1112 precache_sound ("announcer/robotic/10.ogg");
1114 // common weapon precaches
1115 precache_sound ("weapons/weapon_switch.wav");
1116 precache_sound ("weapons/weaponpickup.wav");
1117 if (cvar("g_grappling_hook"))
1119 precache_sound ("weapons/hook_fire.wav"); // hook
1120 precache_sound ("weapons/hook_impact.wav"); // hook
1123 if (cvar("sv_precacheweapons") || g_nixnex)
1125 //precache weapon models/sounds
1128 while (wep <= WEP_LAST)
1130 weapon_action(wep, WR_PRECACHE);
1135 // plays music for the level if there is any
1138 precache_sound (self.noise);
1139 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1143 // sorry, but using \ in macros breaks line numbers
1144 #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
1145 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1146 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1148 vector ExactTriggerHit_mins;
1149 vector ExactTriggerHit_maxs;
1150 float ExactTriggerHit_Recurse()
1156 tracebox('0 0 0', ExactTriggerHit_mins, ExactTriggerHit_maxs, '0 0 0', MOVE_NORMAL, other);
1159 if(trace_ent == self)
1164 se.solid = SOLID_NOT;
1165 f = ExactTriggerHit_Recurse();
1171 float ExactTriggerHit()
1175 if not(self.modelindex)
1179 self.solid = SOLID_BSP;
1180 ExactTriggerHit_mins = other.absmin;
1181 ExactTriggerHit_maxs = other.absmax;
1182 f = ExactTriggerHit_Recurse();
1188 // WARNING: this kills the trace globals
1189 #define EXACTTRIGGER_TOUCH if not(ExactTriggerHit()) return
1190 #define EXACTTRIGGER_INIT InitSolidBSPTrigger(); self.solid = SOLID_TRIGGER
1192 #define INITPRIO_FIRST 0
1193 #define INITPRIO_GAMETYPE 0
1194 #define INITPRIO_GAMETYPE_FALLBACK 1
1195 #define INITPRIO_FINDTARGET 10
1196 #define INITPRIO_SETLOCATION 90
1197 #define INITPRIO_LINKDOORS 91
1198 #define INITPRIO_LAST 99
1200 .void(void) initialize_entity;
1201 .float initialize_entity_order;
1202 .entity initialize_entity_next;
1203 entity initialize_entity_first;
1204 void InitializeEntity(entity e, void(void) func, float order)
1208 if(!e || e.initialize_entity)
1210 // make a proxy initializer entity
1214 e.classname = "initialize_entity";
1218 e.initialize_entity = func;
1219 e.initialize_entity_order = order;
1221 cur = initialize_entity_first;
1224 if(!cur || cur.initialize_entity_order > order)
1226 // insert between prev and cur
1228 prev.initialize_entity_next = e;
1230 initialize_entity_first = e;
1231 e.initialize_entity_next = cur;
1235 cur = cur.initialize_entity_next;
1238 void InitializeEntitiesRun()
1240 for(self = initialize_entity_first; self; )
1243 var void(void) func;
1244 e = self.initialize_entity_next;
1245 func = self.initialize_entity;
1246 self.initialize_entity_order = 0;
1247 self.initialize_entity = func_null;
1248 self.initialize_entity_next = world;
1249 if(self.classname == "initialize_entity")
1256 dprint("Delayed initialization: ", self.classname, "\n");
1260 initialize_entity_first = world;
1264 #define IFTARGETED if(!self.nottargeted && self.targetname != "")