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);
111 string STR_PLAYER = "player";
112 string STR_SPECTATOR = "spectator";
113 string STR_OBSERVER = "observer";
116 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
117 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
118 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
119 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
121 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
122 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
123 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
124 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
125 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
128 // copies a string to a tempstring (so one can strunzone it)
129 string strcat1(string s) = #115; // FRIK_FILE
134 void bcenterprint(string s)
136 // TODO replace by MSG_ALL (would show it to spectators too, though)?
138 FOR_EACH_PLAYER(head)
139 if(clienttype(head) == CLIENTTYPE_REAL)
140 centerprint(head, s);
143 void GameLogEcho(string s)
148 if(cvar("sv_eventlog_files"))
153 matches = cvar("sv_eventlog_files_counter") + 1;
154 cvar_set("sv_eventlog_files_counter", ftos(matches));
157 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
158 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
159 logfile = fopen(fn, FILE_APPEND);
160 fputs(logfile, ":logversion:2\n");
164 if(cvar("sv_eventlog_files_timestamps"))
165 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
167 fputs(logfile, strcat(s, "\n"));
170 if(cvar("sv_eventlog_console"))
179 // will be opened later
184 if(logfile_open && logfile >= 0)
191 float spawnpoint_nag;
192 void relocate_spawnpoint()
194 // nudge off the floor
195 setorigin(self, self.origin + '0 0 1');
197 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
198 if (trace_startsolid)
204 if(!move_out_of_solid(self))
205 objerror("could not get out of solid at all!");
206 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
207 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
208 print(" ", ftos(self.origin_y - o_y));
209 print(" ", ftos(self.origin_z - o_z), "'\n");
210 if(cvar("g_spawnpoints_auto_move_out_of_solid"))
213 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
219 self.mins = self.maxs = '0 0 0';
220 objerror("player spawn point in solid, mapper sucks!\n");
225 if(cvar("g_spawnpoints_autodrop"))
227 setsize(self, PL_MIN, PL_MAX);
231 self.use = spawnpoint_use;
232 self.team_saved = self.team;
236 if(g_ctf || g_assault || g_onslaught || g_domination)
238 have_team_spawns = 1;
240 if(cvar("r_showbboxes"))
242 // show where spawnpoints point at too
243 makevectors(self.angles);
246 e.classname = "info_player_foo";
247 setorigin(e, self.origin + v_forward * 24);
248 setsize(e, '-8 -8 -8', '8 8 8');
249 e.solid = SOLID_TRIGGER;
253 #define strstr strstrofs
255 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
256 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
257 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
258 // BE CONSTANT OR strzoneD!
259 float strstr(string haystack, string needle, float offset)
263 len = strlen(needle);
264 endpos = strlen(haystack) - len;
265 while(offset <= endpos)
267 found = substring(haystack, offset, len);
276 float NUM_NEAREST_ENTITIES = 4;
277 entity nearest_entity[NUM_NEAREST_ENTITIES];
278 float nearest_length[NUM_NEAREST_ENTITIES];
279 entity findnearest(vector point, .string field, string value, vector axismod)
290 localhead = find(world, field, value);
293 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
294 dist = localhead.oldorigin;
296 dist = localhead.origin;
298 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
301 for(i = 0; i < num_nearest; ++i)
303 if(len < nearest_length[i])
307 // now i tells us where to insert at
308 // INSERTION SORT! YOU'VE SEEN IT! RUN!
309 if(i < NUM_NEAREST_ENTITIES)
311 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
313 nearest_length[j + 1] = nearest_length[j];
314 nearest_entity[j + 1] = nearest_entity[j];
316 nearest_length[i] = len;
317 nearest_entity[i] = localhead;
318 if(num_nearest < NUM_NEAREST_ENTITIES)
319 num_nearest = num_nearest + 1;
322 localhead = find(localhead, field, value);
325 // now use the first one from our list that we can see
326 for(i = 0; i < num_nearest; ++i)
328 traceline(point, nearest_entity[i].origin, TRUE, world);
329 if(trace_fraction == 1)
333 dprint("Nearest point (");
334 dprint(nearest_entity[0].netname);
335 dprint(") is not visible, using a visible one.\n");
337 return nearest_entity[i];
344 dprint("Not seeing any location point, using nearest as fallback.\n");
346 dprint("Candidates were: ");
347 for(j = 0; j < num_nearest; ++j)
351 dprint(nearest_entity[j].netname);
356 return nearest_entity[0];
359 void spawnfunc_target_location()
361 self.classname = "target_location";
362 // location name in netname
363 // eventually support: count, teamgame selectors, line of sight?
366 void spawnfunc_info_location()
368 self.classname = "target_location";
369 self.message = self.netname;
372 string NearestLocation(vector p)
377 loc = findnearest(p, classname, "target_location", '1 1 1');
384 loc = findnearest(p, target, "###item###", '1 1 4');
391 string formatmessage(string msg)
398 msg_save = strzone(msg);
404 break; // too many replacements
406 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
409 replacement = substring(msg_save, p, 2);
410 escape = substring(msg_save, p + 1, 1);
413 else if(escape == "a")
414 replacement = ftos(floor(self.armorvalue));
415 else if(escape == "h")
416 replacement = ftos(floor(self.health));
417 else if(escape == "l")
418 replacement = NearestLocation(self.origin);
419 else if(escape == "y")
420 replacement = NearestLocation(self.cursor_trace_endpos);
421 else if(escape == "d")
422 replacement = NearestLocation(self.death_origin);
423 else if(escape == "w")
428 wep = self.switchweapon;
431 replacement = W_Name(wep);
433 else if(escape == "W")
435 if(self.items & IT_SHELLS) replacement = "shells";
436 else if(self.items & IT_NAILS) replacement = "bullets";
437 else if(self.items & IT_ROCKETS) replacement = "rockets";
438 else if(self.items & IT_CELLS) replacement = "cells";
439 else replacement = "batteries"; // ;)
441 else if(escape == "x")
443 replacement = self.cursor_trace_ent.netname;
444 if(!replacement || !self.cursor_trace_ent)
445 replacement = "nothing";
447 else if(escape == "p")
449 if(self.last_selected_player)
450 replacement = self.last_selected_player.netname;
452 replacement = "(nobody)";
454 msg = strcat(substring(msg_save, 0, p), replacement);
455 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
457 msg_save = strzone(msg);
460 msg = strcat(msg_save, "");
471 >0: receives a cvar from name=argv(f) value=argv(f+1)
473 void GetCvars_handleString(string thisname, float f, .string field, string name)
478 strunzone(self.field);
485 strunzone(self.field);
486 self.field = strzone(argv(f + 1));
490 stuffcmd(self, strcat("sendcvar ", name, "\n"));
492 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
494 GetCvars_handleString(thisname, f, field, name);
495 if(f >= 0) // also initialize to the fitting value for "" when sending cvars out
499 s = func(strcat1(self.field));
502 strunzone(self.field);
503 self.field = strzone(s);
507 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
515 self.field = stof(argv(f + 1));
518 stuffcmd(self, strcat("sendcvar ", name, "\n"));
520 string W_FixWeaponOrder_ForceComplete(string s);
521 string W_FixWeaponOrder_AllowIncomplete(string s);
522 float w_getbestweapon(entity e);
523 void GetCvars(float f)
527 s = strcat1(argv(f));
528 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
529 GetCvars_handleFloat(s, f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
530 GetCvars_handleFloat(s, f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
531 GetCvars_handleFloat(s, f, cvar_cl_nogibs, "cl_nogibs");
532 GetCvars_handleFloat(s, f, cvar_scr_centertime, "scr_centertime");
533 GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames");
534 GetCvars_handleString(s, f, cvar_g_nexuizversion, "g_nexuizversion");
535 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
536 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
537 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
538 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
539 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
540 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
541 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
542 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
543 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
544 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
545 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
546 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
548 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
551 if(s == "cl_weaponpriority")
552 self.switchweapon = w_getbestweapon(self);
556 float fexists(string f)
559 fh = fopen(f, FILE_READ);
566 void backtrace(string msg)
569 dev = cvar("developer");
570 cvar_set("developer", "1");
572 dprint("--- CUT HERE ---\nWARNING: ");
575 remove(world); // isn't there any better way to cause a backtrace?
576 dprint("\n--- CUT UNTIL HERE ---\n");
577 cvar_set("developer", ftos(dev));
580 string Team_ColorCode(float teamid)
582 if(teamid == COLOR_TEAM1)
584 else if(teamid == COLOR_TEAM2)
586 else if(teamid == COLOR_TEAM3)
588 else if(teamid == COLOR_TEAM4)
593 string Team_ColorName(float t)
595 // fixme: Search for team entities and get their .netname's!
606 string Team_ColorNameLowerCase(float t)
608 // fixme: Search for team entities and get their .netname's!
620 #define CENTERPRIO_POINT 1
621 #define CENTERPRIO_SPAM 2
622 #define CENTERPRIO_REBALANCE 2
623 #define CENTERPRIO_VOTE 4
624 #define CENTERPRIO_NORMAL 5
625 #define CENTERPRIO_MAPVOTE 9
626 #define CENTERPRIO_IDLEKICK 50
627 #define CENTERPRIO_ADMIN 99
628 .float centerprint_priority;
629 .float centerprint_expires;
630 void centerprint_atprio(entity e, float prio, string s)
632 if(intermission_running)
633 if(prio < CENTERPRIO_MAPVOTE)
635 if(time > e.centerprint_expires)
636 e.centerprint_priority = 0;
637 if(prio >= e.centerprint_priority)
639 e.centerprint_priority = prio;
640 if(timeoutStatus == 2)
641 e.centerprint_expires = time + (e.cvar_scr_centertime * TIMEOUT_SLOWMO_VALUE);
643 e.centerprint_expires = time + e.cvar_scr_centertime;
644 centerprint_builtin(e, s);
647 void centerprint_expire(entity e, float prio)
649 if(prio == e.centerprint_priority)
651 e.centerprint_priority = 0;
652 centerprint_builtin(e, "");
655 void centerprint(entity e, string s)
657 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
662 // decolorizes and team colors the player name when needed
663 string playername(entity p)
666 if(teams_matter && !intermission_running && p.classname == "player")
668 t = Team_ColorCode(p.team);
669 return strcat(t, strdecolorize(p.netname));
675 vector randompos(vector m1, vector m2)
679 v_x = m2_x * random() + m1_x;
680 v_y = m2_y * random() + m1_y;
681 v_z = m2_z * random() + m1_z;
685 // requires that m2>m1 in all coordinates, and that m4>m3
686 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;};
688 // requires the same, but is a stronger condition
689 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;};
691 float g_pickup_shells;
692 float g_pickup_shells_max;
693 float g_pickup_nails;
694 float g_pickup_nails_max;
695 float g_pickup_rockets;
696 float g_pickup_rockets_max;
697 float g_pickup_cells;
698 float g_pickup_cells_max;
699 float g_pickup_armorsmall;
700 float g_pickup_armorsmall_max;
701 float g_pickup_armormedium;
702 float g_pickup_armormedium_max;
703 float g_pickup_armorlarge;
704 float g_pickup_armorlarge_max;
705 float g_pickup_healthsmall;
706 float g_pickup_healthsmall_max;
707 float g_pickup_healthmedium;
708 float g_pickup_healthmedium_max;
709 float g_pickup_healthlarge;
710 float g_pickup_healthlarge_max;
711 float g_pickup_healthmega;
712 float g_pickup_healthmega_max;
716 float start_ammo_shells;
717 float start_ammo_nails;
718 float start_ammo_rockets;
719 float start_ammo_cells;
721 float start_armorvalue;
722 float warmup_start_weapons;
723 float warmup_start_ammo_shells;
724 float warmup_start_ammo_nails;
725 float warmup_start_ammo_rockets;
726 float warmup_start_ammo_cells;
727 float warmup_start_health;
728 float warmup_start_armorvalue;
730 entity get_weaponinfo(float w);
732 void readplayerstartcvars()
737 // initialize starting values for players
740 start_ammo_shells = 0;
741 start_ammo_nails = 0;
742 start_ammo_rockets = 0;
743 start_ammo_cells = 0;
744 start_health = cvar("g_balance_health_start");
745 start_armorvalue = cvar("g_balance_armor_start");
749 start_weapons = WEPBIT_ROCKET_LAUNCHER;
750 weapon_action(WEP_ROCKET_LAUNCHER, WR_PRECACHE);
751 start_ammo_rockets = 999;
752 start_items |= IT_UNLIMITED_AMMO;
757 // will be done later
762 start_armorvalue = 0;
763 start_weapons = WEPBIT_MINSTANEX;
764 weapon_action(WEP_MINSTANEX, WR_PRECACHE);
765 start_ammo_cells = cvar("g_minstagib_ammo_start");
766 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
772 start_ammo_shells = cvar("g_lms_start_ammo_shells");
773 start_ammo_nails = cvar("g_lms_start_ammo_nails");
774 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
775 start_ammo_cells = cvar("g_lms_start_ammo_cells");
776 start_health = cvar("g_lms_start_health");
777 start_armorvalue = cvar("g_lms_start_armor");
778 } else if (cvar("g_use_ammunition")) {
779 start_ammo_shells = cvar("g_start_ammo_shells");
780 start_ammo_nails = cvar("g_start_ammo_nails");
781 start_ammo_rockets = cvar("g_start_ammo_rockets");
782 start_ammo_cells = cvar("g_start_ammo_cells");
784 start_ammo_shells = cvar("g_pickup_shells_max");
785 start_ammo_nails = cvar("g_pickup_nails_max");
786 start_ammo_rockets = cvar("g_pickup_rockets_max");
787 start_ammo_cells = cvar("g_pickup_cells_max");
788 start_items |= IT_UNLIMITED_AMMO;
791 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
793 e = get_weaponinfo(i);
796 if(((e.spawnflags & 1) && g_lms) || cvar(strcat("g_start_weapon_", e.netname)))
798 start_weapons |= e.weapons;
799 weapon_action(e.weapon, WR_PRECACHE);
806 warmup_start_ammo_shells = start_ammo_shells;
807 warmup_start_ammo_nails = start_ammo_nails;
808 warmup_start_ammo_rockets = start_ammo_rockets;
809 warmup_start_ammo_cells = start_ammo_cells;
810 warmup_start_health = start_health;
811 warmup_start_armorvalue = start_armorvalue;
812 warmup_start_weapons = start_weapons;
814 if(!g_rocketarena && !g_nixnex && !g_minstagib)
816 if(cvar("g_use_ammunition"))
818 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
819 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
820 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
821 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
823 warmup_start_health = cvar("g_warmup_start_health");
824 warmup_start_armorvalue = cvar("g_warmup_start_armor");
825 if(cvar("g_warmup_allguns"))
827 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
829 e = get_weaponinfo(i);
834 warmup_start_weapons |= e.weapons;
835 weapon_action(e.weapon, WR_PRECACHE);
843 void readlevelcvars(void)
845 sv_cheats = cvar("sv_cheats");
846 sv_gentle = cvar("sv_gentle");
847 sv_foginterval = cvar("sv_foginterval");
848 g_cloaked = cvar("g_cloaked");
849 g_jump_grunt = cvar("g_jump_grunt");
850 g_footsteps = cvar("g_footsteps");
851 g_grappling_hook = cvar("g_grappling_hook");
852 g_laserguided_missile = cvar("g_laserguided_missile");
853 g_midair = cvar("g_midair");
854 g_minstagib = cvar("g_minstagib");
855 g_nixnex = cvar("g_nixnex");
856 g_nixnex_with_laser = cvar("g_nixnex_with_laser");
857 g_norecoil = cvar("g_norecoil");
858 g_rocketarena = cvar("g_rocketarena");
859 g_vampire = cvar("g_vampire");
860 sv_maxidle = cvar("sv_maxidle");
861 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
862 sv_pogostick = cvar("sv_pogostick");
863 sv_doublejump = cvar("sv_doublejump");
865 inWarmupStage = cvar("g_warmup");
866 g_warmup_limit = cvar("g_warmup_limit");
867 g_warmup_allguns = cvar("g_warmup_allguns");
868 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
870 if(g_race && g_race_qualifying == 2 || g_arena || g_assault || cvar("g_campaign"))
871 inWarmupStage = 0; // these modes cannot work together, sorry
873 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
874 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
875 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
876 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
878 if(g_minstagib) g_nixnex = g_rocketarena = 0;
879 if(g_nixnex) g_rocketarena = 0;
881 g_pickup_shells = cvar("g_pickup_shells");
882 g_pickup_shells_max = cvar("g_pickup_shells_max");
883 g_pickup_nails = cvar("g_pickup_nails");
884 g_pickup_nails_max = cvar("g_pickup_nails_max");
885 g_pickup_rockets = cvar("g_pickup_rockets");
886 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
887 g_pickup_cells = cvar("g_pickup_cells");
888 g_pickup_cells_max = cvar("g_pickup_cells_max");
889 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
890 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
891 g_pickup_armormedium = cvar("g_pickup_armormedium");
892 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
893 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
894 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
895 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
896 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
897 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
898 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
899 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
900 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
901 g_pickup_healthmega = cvar("g_pickup_healthmega");
902 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
904 readplayerstartcvars();
908 // TODO sound pack system
911 string precache_sound_builtin (string s) = #19;
912 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
913 string precache_sound(string s)
915 return precache_sound_builtin(strcat(soundpack, s));
917 void play2(entity e, string filename)
919 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
921 void sound(entity e, float chan, string samp, float vol, float atten)
923 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
928 string precache_sound (string s) = #19;
929 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
930 float precache_sound_index (string s) = #19;
932 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
935 WriteByte(dest, 27); // all bits except SND_LOOPING
936 WriteByte(dest, vol * 255);
937 WriteByte(dest, atten * 64);
938 WriteEntity(dest, e);
939 WriteByte(dest, chan);
940 WriteShort(dest, precache_sound_index(samp));
941 WriteCoord(dest, o_x);
942 WriteCoord(dest, o_y);
943 WriteCoord(dest, o_z);
945 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
948 o = e.origin + 0.5 * (e.mins + e.maxs);
949 soundtoat(dest, e, o, chan, samp, vol, atten);
951 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
953 soundtoat(MSG_BROADCAST, e, o, chan, samp, vol, atten);
956 void play2(entity e, string filename)
958 //stuffcmd(e, strcat("play2 ", filename, "\n"));
960 soundtoat(MSG_ONE, world, '0 0 0', CHAN_AUTO, filename, VOL_BASE, ATTN_NONE);
964 void announce(entity player, string msg)
966 if(time > player.announcetime)
967 if(clienttype(player) == CLIENTTYPE_REAL)
969 player.announcetime = time + 0.3;
974 void play2team(float t, string filename)
977 FOR_EACH_REALPLAYER(head)
980 play2(head, filename);
984 void play2all(string samp)
986 sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
989 void PrecachePlayerSounds(string f);
990 void precache_all_models(string pattern)
992 float globhandle, i, n;
995 globhandle = search_begin(pattern, TRUE, FALSE);
998 n = search_getsize(globhandle);
999 for(i = 0; i < n; ++i)
1001 //print(search_getfilename(globhandle, i), "\n");
1002 f = search_getfilename(globhandle, i);
1004 PrecachePlayerSounds(strcat(f, ".sounds"));
1006 search_end(globhandle);
1011 // gamemode related things
1012 precache_model ("models/misc/chatbubble.spr");
1013 precache_model ("models/misc/teambubble.spr");
1016 precache_model ("models/runematch/curse.mdl");
1017 precache_model ("models/runematch/rune.mdl");
1020 // Precache all player models if desired
1021 if (cvar("sv_precacheplayermodels"))
1023 PrecachePlayerSounds("sound/player/default.sounds");
1024 precache_all_models("models/player/*.zym");
1025 precache_all_models("models/player/*.dpm");
1026 precache_all_models("models/player/*.md3");
1027 precache_all_models("models/player/*.psk");
1028 //precache_model("models/player/carni.zym");
1029 //precache_model("models/player/crash.zym");
1030 //precache_model("models/player/grunt.zym");
1031 //precache_model("models/player/headhunter.zym");
1032 //precache_model("models/player/insurrectionist.zym");
1033 //precache_model("models/player/jeandarc.zym");
1034 //precache_model("models/player/lurk.zym");
1035 //precache_model("models/player/lycanthrope.zym");
1036 //precache_model("models/player/marine.zym");
1037 //precache_model("models/player/nexus.zym");
1038 //precache_model("models/player/pyria.zym");
1039 //precache_model("models/player/shock.zym");
1040 //precache_model("models/player/skadi.zym");
1041 //precache_model("models/player/specop.zym");
1042 //precache_model("models/player/visitant.zym");
1047 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1048 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1051 // gore and miscellaneous sounds
1052 //precache_sound ("misc/h2ohit.wav");
1053 precache_model ("models/gibs/bloodyskull.md3");
1054 precache_model ("models/gibs/chunk.mdl");
1055 precache_model ("models/gibs/eye.md3");
1056 precache_model ("models/gibs/gib1.md3");
1057 precache_model ("models/gibs/gib2.md3");
1058 precache_model ("models/gibs/gib3.md3");
1059 precache_model ("models/gibs/gib4.md3");
1060 precache_model ("models/gibs/gib5.md3");
1061 precache_model ("models/gibs/gib6.md3");
1062 precache_model ("models/gibs/smallchest.md3");
1063 precache_model ("models/gibs/chest.md3");
1064 precache_model ("models/gibs/arm.md3");
1065 precache_model ("models/gibs/leg1.md3");
1066 precache_model ("models/gibs/leg2.md3");
1067 precache_model ("models/hook.md3");
1068 precache_sound ("misc/armorimpact.wav");
1069 precache_sound ("misc/bodyimpact1.wav");
1070 precache_sound ("misc/bodyimpact2.wav");
1071 precache_sound ("misc/gib.wav");
1072 precache_sound ("misc/gib_splat01.wav");
1073 precache_sound ("misc/gib_splat02.wav");
1074 precache_sound ("misc/gib_splat03.wav");
1075 precache_sound ("misc/gib_splat04.wav");
1076 precache_sound ("misc/hit.wav");
1077 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1078 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1079 precache_sound ("misc/null.wav");
1080 precache_sound ("misc/spawn.wav");
1081 precache_sound ("misc/talk.wav");
1082 precache_sound ("misc/teleport.wav");
1083 precache_sound ("player/lava.wav");
1084 precache_sound ("player/slime.wav");
1086 // announcer sounds - male
1087 //precache_sound ("announcer/male/electrobitch.wav");
1088 precache_sound ("announcer/male/03kills.wav");
1089 precache_sound ("announcer/male/05kills.wav");
1090 precache_sound ("announcer/male/10kills.wav");
1091 precache_sound ("announcer/male/15kills.wav");
1092 precache_sound ("announcer/male/20kills.wav");
1093 precache_sound ("announcer/male/25kills.wav");
1094 precache_sound ("announcer/male/30kills.wav");
1095 precache_sound ("announcer/male/botlike.wav");
1096 precache_sound ("announcer/male/yoda.wav");
1098 // announcer sounds - robotic
1099 precache_sound ("announcer/robotic/prepareforbattle.wav");
1100 precache_sound ("announcer/robotic/begin.wav");
1101 precache_sound ("announcer/robotic/timeoutcalled.wav");
1102 precache_sound ("announcer/robotic/1fragleft.wav");
1103 precache_sound ("announcer/robotic/1minuteremains.wav");
1104 precache_sound ("announcer/robotic/2fragsleft.wav");
1105 precache_sound ("announcer/robotic/3fragsleft.wav");
1108 precache_sound ("announcer/robotic/lastsecond.wav");
1109 precache_sound ("announcer/robotic/narrowly.wav");
1112 precache_model ("models/sprites/1.spr32");
1113 precache_model ("models/sprites/2.spr32");
1114 precache_model ("models/sprites/3.spr32");
1115 precache_model ("models/sprites/4.spr32");
1116 precache_model ("models/sprites/5.spr32");
1117 precache_model ("models/sprites/6.spr32");
1118 precache_model ("models/sprites/7.spr32");
1119 precache_model ("models/sprites/8.spr32");
1120 precache_model ("models/sprites/9.spr32");
1121 precache_model ("models/sprites/10.spr32");
1122 precache_sound ("announcer/robotic/1.ogg");
1123 precache_sound ("announcer/robotic/2.ogg");
1124 precache_sound ("announcer/robotic/3.ogg");
1125 precache_sound ("announcer/robotic/4.ogg");
1126 precache_sound ("announcer/robotic/5.ogg");
1127 precache_sound ("announcer/robotic/6.ogg");
1128 precache_sound ("announcer/robotic/7.ogg");
1129 precache_sound ("announcer/robotic/8.ogg");
1130 precache_sound ("announcer/robotic/9.ogg");
1131 precache_sound ("announcer/robotic/10.ogg");
1133 // common weapon precaches
1134 precache_sound ("weapons/weapon_switch.wav");
1135 precache_sound ("weapons/weaponpickup.wav");
1136 if (cvar("g_grappling_hook"))
1138 precache_sound ("weapons/hook_fire.wav"); // hook
1139 precache_sound ("weapons/hook_impact.wav"); // hook
1142 if (cvar("sv_precacheweapons") || g_nixnex)
1144 //precache weapon models/sounds
1147 while (wep <= WEP_LAST)
1149 weapon_action(wep, WR_PRECACHE);
1154 // plays music for the level if there is any
1157 precache_sound (self.noise);
1158 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1162 // sorry, but using \ in macros breaks line numbers
1163 #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
1164 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1165 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1167 vector ExactTriggerHit_mins;
1168 vector ExactTriggerHit_maxs;
1169 float ExactTriggerHit_Recurse()
1175 tracebox('0 0 0', ExactTriggerHit_mins, ExactTriggerHit_maxs, '0 0 0', MOVE_NORMAL, other);
1178 if(trace_ent == self)
1183 se.solid = SOLID_NOT;
1184 f = ExactTriggerHit_Recurse();
1190 float ExactTriggerHit()
1194 if not(self.modelindex)
1198 self.solid = SOLID_BSP;
1199 ExactTriggerHit_mins = other.absmin;
1200 ExactTriggerHit_maxs = other.absmax;
1201 f = ExactTriggerHit_Recurse();
1207 // WARNING: this kills the trace globals
1208 #define EXACTTRIGGER_TOUCH if not(ExactTriggerHit()) return
1209 #define EXACTTRIGGER_INIT InitSolidBSPTrigger(); self.solid = SOLID_TRIGGER
1211 #define INITPRIO_FIRST 0
1212 #define INITPRIO_GAMETYPE 0
1213 #define INITPRIO_GAMETYPE_FALLBACK 1
1214 #define INITPRIO_FINDTARGET 10
1215 #define INITPRIO_SETLOCATION 90
1216 #define INITPRIO_LINKDOORS 91
1217 #define INITPRIO_LAST 99
1219 .void(void) initialize_entity;
1220 .float initialize_entity_order;
1221 .entity initialize_entity_next;
1222 entity initialize_entity_first;
1223 void InitializeEntity(entity e, void(void) func, float order)
1227 if(!e || e.initialize_entity)
1229 // make a proxy initializer entity
1233 e.classname = "initialize_entity";
1237 e.initialize_entity = func;
1238 e.initialize_entity_order = order;
1240 cur = initialize_entity_first;
1243 if(!cur || cur.initialize_entity_order > order)
1245 // insert between prev and cur
1247 prev.initialize_entity_next = e;
1249 initialize_entity_first = e;
1250 e.initialize_entity_next = cur;
1254 cur = cur.initialize_entity_next;
1257 void InitializeEntitiesRun()
1259 for(self = initialize_entity_first; self; )
1262 var void(void) func;
1263 e = self.initialize_entity_next;
1264 func = self.initialize_entity;
1265 self.initialize_entity_order = 0;
1266 self.initialize_entity = func_null;
1267 self.initialize_entity_next = world;
1268 if(self.classname == "initialize_entity")
1275 dprint("Delayed initialization: ", self.classname, "\n");
1279 initialize_entity_first = world;
1283 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1285 float power2of(float e)
1289 float log2of(float x)
1291 // NOTE: generated code
1366 // - basically func_assault_destructible for general gameplay use
1369 void () SUB_UseTargets, assault_destructible_use, SUB_Remove, SUB_Null;
1370 void LaunchDebris (string debrisname) =
1374 if (debrisname == "" || !debrisname)
1378 dbr.origin = self.origin;
1379 setmodel (dbr, debrisname );
1380 setsize (dbr, '0 0 0', '0 0 0');
1381 dbr.velocity_x = 70 * crandom();
1382 dbr.velocity_y = 70 * crandom();
1383 dbr.velocity_z = 140 + 70 * random();
1384 dbr.movetype = MOVETYPE_BOUNCE;
1385 dbr.solid = SOLID_BBOX;
1386 dbr.avelocity_x = random()*600;
1387 dbr.avelocity_y = random()*600;
1388 dbr.avelocity_z = random()*600;
1389 dbr.think = SUB_Remove;
1390 dbr.nextthink = time + 13 + random()*10;
1393 .string debris1, debris2, debris3;
1395 void func_breakable_destroy() {
1397 setmodel(self, self.mdl_dead);
1400 self.solid = SOLID_NOT;
1402 self.takedamage = DAMAGE_NO;
1404 // now throw around the debris
1405 LaunchDebris(self.debris1);
1406 LaunchDebris(self.debris2);
1407 LaunchDebris(self.debris3);
1411 self.event_damage = SUB_Null;
1414 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) {
1417 self.health = self.health - damage;
1418 // add pain effects?
1421 if(self.health < 0) {
1422 activator = attacker;
1423 func_breakable_destroy();
1427 // destructible walls that can be used to trigger target_objective_decrease
1428 void spawnfunc_func_breakable() {
1432 self.max_health = self.health;
1434 //self.cnt = 0; // not yet activated
1438 self.classname = "func_breakable";
1439 self.mdl = self.model;
1440 setmodel(self, self.mdl);
1442 self.solid = SOLID_BSP;
1444 // precache all the models
1446 precache_model(self.mdl_dead);
1448 precache_model(self.debris1);
1450 precache_model(self.debris2);
1452 precache_model(self.debris3);
1454 self.use = assault_destructible_use; // shared use function, b/c they woudl do the same thing anyways
1455 self.event_damage = func_breakable_damage;