1 var void remove(entity e);
2 void objerror(string s);
4 .vector dropped_origin;
6 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
8 string ColoredTeamName(float t);
10 float RandomSelection_totalweight;
11 float RandomSelection_best_priority;
12 entity RandomSelection_chosen_ent;
13 float RandomSelection_chosen_float;
14 void RandomSelection_Init()
16 RandomSelection_totalweight = 0;
17 RandomSelection_chosen_ent = world;
18 RandomSelection_chosen_float = 0;
19 RandomSelection_best_priority = -1;
21 void RandomSelection_Add(entity e, float f, float weight, float priority)
23 if(priority > RandomSelection_best_priority)
25 RandomSelection_best_priority = priority;
26 RandomSelection_chosen_ent = e;
27 RandomSelection_chosen_float = f;
28 RandomSelection_totalweight = weight;
30 else if(priority == RandomSelection_best_priority)
32 RandomSelection_totalweight += weight;
33 if(random() * RandomSelection_totalweight <= weight)
35 RandomSelection_chosen_ent = e;
36 RandomSelection_chosen_float = f;
41 float DistributeEvenly_amount;
42 float DistributeEvenly_totalweight;
43 void DistributeEvenly_Init(float amount, float totalweight)
45 if(DistributeEvenly_amount)
47 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
48 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
51 DistributeEvenly_amount = 0;
53 DistributeEvenly_amount = amount;
54 DistributeEvenly_totalweight = totalweight;
56 float DistributeEvenly_Get(float weight)
61 f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
62 DistributeEvenly_totalweight -= weight;
63 DistributeEvenly_amount -= f;
67 void move_out_of_solid_expand(entity e, vector by)
70 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
73 if(trace_fraction < 1)
76 // adjust origin in the other direction...
77 e.origin = e.origin - by * (1 - trace_fraction);
81 float move_out_of_solid(entity e)
86 traceline(o, o, MOVE_WORLDONLY, e);
90 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
98 move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
99 move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
100 move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
101 move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
102 move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
103 move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
104 setorigin(e, e.origin);
106 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
116 string STR_PLAYER = "player";
117 string STR_SPECTATOR = "spectator";
118 string STR_OBSERVER = "observer";
121 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
122 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
123 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
124 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
126 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
127 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
128 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
129 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
130 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
133 // copies a string to a tempstring (so one can strunzone it)
134 string strcat1(string s) = #115; // FRIK_FILE
139 void bcenterprint(string s)
141 // TODO replace by MSG_ALL (would show it to spectators too, though)?
143 FOR_EACH_PLAYER(head)
144 if(clienttype(head) == CLIENTTYPE_REAL)
145 centerprint(head, s);
148 void GameLogEcho(string s)
153 if(cvar("sv_eventlog_files"))
158 matches = cvar("sv_eventlog_files_counter") + 1;
159 cvar_set("sv_eventlog_files_counter", ftos(matches));
162 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
163 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
164 logfile = fopen(fn, FILE_APPEND);
165 fputs(logfile, ":logversion:2\n");
169 if(cvar("sv_eventlog_files_timestamps"))
170 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
172 fputs(logfile, strcat(s, "\n"));
175 if(cvar("sv_eventlog_console"))
184 // will be opened later
189 if(logfile_open && logfile >= 0)
196 float spawnpoint_nag;
197 void relocate_spawnpoint()
199 // nudge off the floor
200 setorigin(self, self.origin + '0 0 1');
202 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
203 if (trace_startsolid)
209 if(!move_out_of_solid(self))
210 objerror("could not get out of solid at all!");
211 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
212 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
213 print(" ", ftos(self.origin_y - o_y));
214 print(" ", ftos(self.origin_z - o_z), "'\n");
215 if(cvar("g_spawnpoints_auto_move_out_of_solid"))
218 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
224 self.mins = self.maxs = '0 0 0';
225 objerror("player spawn point in solid, mapper sucks!\n");
230 if(cvar("g_spawnpoints_autodrop"))
232 setsize(self, PL_MIN, PL_MAX);
236 self.use = spawnpoint_use;
237 self.team_saved = self.team;
241 if(g_ctf || g_assault || g_onslaught || g_domination)
243 have_team_spawns = 1;
245 if(cvar("r_showbboxes"))
247 // show where spawnpoints point at too
248 makevectors(self.angles);
251 e.classname = "info_player_foo";
252 setorigin(e, self.origin + v_forward * 24);
253 setsize(e, '-8 -8 -8', '8 8 8');
254 e.solid = SOLID_TRIGGER;
258 #define strstr strstrofs
260 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
261 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
262 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
263 // BE CONSTANT OR strzoneD!
264 float strstr(string haystack, string needle, float offset)
268 len = strlen(needle);
269 endpos = strlen(haystack) - len;
270 while(offset <= endpos)
272 found = substring(haystack, offset, len);
281 float NUM_NEAREST_ENTITIES = 4;
282 entity nearest_entity[NUM_NEAREST_ENTITIES];
283 float nearest_length[NUM_NEAREST_ENTITIES];
284 entity findnearest(vector point, .string field, string value, vector axismod)
295 localhead = find(world, field, value);
298 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
299 dist = localhead.oldorigin;
301 dist = localhead.origin;
303 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
306 for(i = 0; i < num_nearest; ++i)
308 if(len < nearest_length[i])
312 // now i tells us where to insert at
313 // INSERTION SORT! YOU'VE SEEN IT! RUN!
314 if(i < NUM_NEAREST_ENTITIES)
316 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
318 nearest_length[j + 1] = nearest_length[j];
319 nearest_entity[j + 1] = nearest_entity[j];
321 nearest_length[i] = len;
322 nearest_entity[i] = localhead;
323 if(num_nearest < NUM_NEAREST_ENTITIES)
324 num_nearest = num_nearest + 1;
327 localhead = find(localhead, field, value);
330 // now use the first one from our list that we can see
331 for(i = 0; i < num_nearest; ++i)
333 traceline(point, nearest_entity[i].origin, TRUE, world);
334 if(trace_fraction == 1)
338 dprint("Nearest point (");
339 dprint(nearest_entity[0].netname);
340 dprint(") is not visible, using a visible one.\n");
342 return nearest_entity[i];
349 dprint("Not seeing any location point, using nearest as fallback.\n");
351 dprint("Candidates were: ");
352 for(j = 0; j < num_nearest; ++j)
356 dprint(nearest_entity[j].netname);
361 return nearest_entity[0];
364 void spawnfunc_target_location()
366 self.classname = "target_location";
367 // location name in netname
368 // eventually support: count, teamgame selectors, line of sight?
371 void spawnfunc_info_location()
373 self.classname = "target_location";
374 self.message = self.netname;
377 string NearestLocation(vector p)
382 loc = findnearest(p, classname, "target_location", '1 1 1');
389 loc = findnearest(p, target, "###item###", '1 1 4');
396 string formatmessage(string msg)
403 msg_save = strzone(msg);
409 break; // too many replacements
411 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
414 replacement = substring(msg_save, p, 2);
415 escape = substring(msg_save, p + 1, 1);
418 else if(escape == "a")
419 replacement = ftos(floor(self.armorvalue));
420 else if(escape == "h")
421 replacement = ftos(floor(self.health));
422 else if(escape == "l")
423 replacement = NearestLocation(self.origin);
424 else if(escape == "y")
425 replacement = NearestLocation(self.cursor_trace_endpos);
426 else if(escape == "d")
427 replacement = NearestLocation(self.death_origin);
428 else if(escape == "w")
433 wep = self.switchweapon;
436 replacement = W_Name(wep);
438 else if(escape == "W")
440 if(self.items & IT_SHELLS) replacement = "shells";
441 else if(self.items & IT_NAILS) replacement = "bullets";
442 else if(self.items & IT_ROCKETS) replacement = "rockets";
443 else if(self.items & IT_CELLS) replacement = "cells";
444 else replacement = "batteries"; // ;)
446 else if(escape == "x")
448 replacement = self.cursor_trace_ent.netname;
449 if(!replacement || !self.cursor_trace_ent)
450 replacement = "nothing";
452 else if(escape == "p")
454 if(self.last_selected_player)
455 replacement = self.last_selected_player.netname;
457 replacement = "(nobody)";
459 msg = strcat(substring(msg_save, 0, p), replacement);
460 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
462 msg_save = strzone(msg);
465 msg = strcat(msg_save, "");
476 >0: receives a cvar from name=argv(f) value=argv(f+1)
478 void GetCvars_handleString(string thisname, float f, .string field, string name)
483 strunzone(self.field);
490 strunzone(self.field);
491 self.field = strzone(argv(f + 1));
495 stuffcmd(self, strcat("sendcvar ", name, "\n"));
497 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
499 GetCvars_handleString(thisname, f, field, name);
500 if(f >= 0) // also initialize to the fitting value for "" when sending cvars out
504 s = func(strcat1(self.field));
507 strunzone(self.field);
508 self.field = strzone(s);
512 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
520 self.field = stof(argv(f + 1));
523 stuffcmd(self, strcat("sendcvar ", name, "\n"));
525 string W_FixWeaponOrder_ForceComplete(string s);
526 string W_FixWeaponOrder_AllowIncomplete(string s);
527 float w_getbestweapon(entity e);
528 void GetCvars(float f)
532 s = strcat1(argv(f));
533 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
534 GetCvars_handleFloat(s, f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
535 GetCvars_handleFloat(s, f, cvar_cl_nogibs, "cl_nogibs");
536 GetCvars_handleFloat(s, f, cvar_scr_centertime, "scr_centertime");
537 GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames");
538 GetCvars_handleString(s, f, cvar_g_nexuizversion, "g_nexuizversion");
539 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
540 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
541 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
542 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
543 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
544 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
545 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
546 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
547 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
548 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
549 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
550 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
552 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
555 if(s == "cl_weaponpriority")
556 self.switchweapon = w_getbestweapon(self);
560 float fexists(string f)
563 fh = fopen(f, FILE_READ);
570 void backtrace(string msg)
573 dev = cvar("developer");
574 cvar_set("developer", "1");
576 dprint("--- CUT HERE ---\nWARNING: ");
579 remove(world); // isn't there any better way to cause a backtrace?
580 dprint("\n--- CUT UNTIL HERE ---\n");
581 cvar_set("developer", ftos(dev));
584 string Team_ColorCode(float teamid)
586 if(teamid == COLOR_TEAM1)
588 else if(teamid == COLOR_TEAM2)
590 else if(teamid == COLOR_TEAM3)
592 else if(teamid == COLOR_TEAM4)
597 string Team_ColorName(float t)
599 // fixme: Search for team entities and get their .netname's!
610 string Team_ColorNameLowerCase(float t)
612 // fixme: Search for team entities and get their .netname's!
624 #define CENTERPRIO_POINT 1
625 #define CENTERPRIO_SPAM 2
626 #define CENTERPRIO_REBALANCE 2
627 #define CENTERPRIO_VOTE 4
628 #define CENTERPRIO_NORMAL 5
629 #define CENTERPRIO_MAPVOTE 9
630 #define CENTERPRIO_IDLEKICK 50
631 #define CENTERPRIO_ADMIN 99
632 .float centerprint_priority;
633 .float centerprint_expires;
634 void centerprint_atprio(entity e, float prio, string s)
636 if(intermission_running)
637 if(prio < CENTERPRIO_MAPVOTE)
639 if(time > e.centerprint_expires)
640 e.centerprint_priority = 0;
641 if(prio >= e.centerprint_priority)
643 e.centerprint_priority = prio;
644 if(timeoutStatus == 2)
645 e.centerprint_expires = time + (e.cvar_scr_centertime * TIMEOUT_SLOWMO_VALUE);
647 e.centerprint_expires = time + e.cvar_scr_centertime;
648 centerprint_builtin(e, s);
651 void centerprint_expire(entity e, float prio)
653 if(prio == e.centerprint_priority)
655 e.centerprint_priority = 0;
656 centerprint_builtin(e, "");
659 void centerprint(entity e, string s)
661 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
664 // decolorizes and team colors the player name when needed
665 string playername(entity p)
668 if(teams_matter && !intermission_running && p.classname == "player")
670 t = Team_ColorCode(p.team);
671 return strcat(t, strdecolorize(p.netname));
677 vector randompos(vector m1, vector m2)
681 v_x = m2_x * random() + m1_x;
682 v_y = m2_y * random() + m1_y;
683 v_z = m2_z * random() + m1_z;
687 // requires that m2>m1 in all coordinates, and that m4>m3
688 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;};
690 // requires the same, but is a stronger condition
691 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;};
693 float g_pickup_shells;
694 float g_pickup_shells_max;
695 float g_pickup_nails;
696 float g_pickup_nails_max;
697 float g_pickup_rockets;
698 float g_pickup_rockets_max;
699 float g_pickup_cells;
700 float g_pickup_cells_max;
701 float g_pickup_armorsmall;
702 float g_pickup_armorsmall_max;
703 float g_pickup_armormedium;
704 float g_pickup_armormedium_max;
705 float g_pickup_armorlarge;
706 float g_pickup_armorlarge_max;
707 float g_pickup_healthsmall;
708 float g_pickup_healthsmall_max;
709 float g_pickup_healthmedium;
710 float g_pickup_healthmedium_max;
711 float g_pickup_healthlarge;
712 float g_pickup_healthlarge_max;
713 float g_pickup_healthmega;
714 float g_pickup_healthmega_max;
718 float start_ammo_shells;
719 float start_ammo_nails;
720 float start_ammo_rockets;
721 float start_ammo_cells;
723 float start_armorvalue;
724 float warmup_start_weapons;
725 float warmup_start_ammo_shells;
726 float warmup_start_ammo_nails;
727 float warmup_start_ammo_rockets;
728 float warmup_start_ammo_cells;
729 float warmup_start_health;
730 float warmup_start_armorvalue;
732 entity get_weaponinfo(float w);
734 void readplayerstartcvars()
739 // initialize starting values for players
742 start_ammo_shells = 0;
743 start_ammo_nails = 0;
744 start_ammo_rockets = 0;
745 start_ammo_cells = 0;
746 start_health = cvar("g_balance_health_start");
747 start_armorvalue = cvar("g_balance_armor_start");
751 start_weapons = WEPBIT_ROCKET_LAUNCHER;
752 weapon_action(WEP_ROCKET_LAUNCHER, WR_PRECACHE);
753 start_ammo_rockets = 999;
754 start_items |= IT_UNLIMITED_AMMO;
759 // will be done later
764 start_armorvalue = 0;
765 start_weapons = WEPBIT_MINSTANEX;
766 weapon_action(WEP_MINSTANEX, WR_PRECACHE);
767 start_ammo_cells = cvar("g_minstagib_ammo_start");
768 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
774 start_ammo_shells = cvar("g_lms_start_ammo_shells");
775 start_ammo_nails = cvar("g_lms_start_ammo_nails");
776 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
777 start_ammo_cells = cvar("g_lms_start_ammo_cells");
778 start_health = cvar("g_lms_start_health");
779 start_armorvalue = cvar("g_lms_start_armor");
780 } else if (cvar("g_use_ammunition")) {
781 start_ammo_shells = cvar("g_start_ammo_shells");
782 start_ammo_nails = cvar("g_start_ammo_nails");
783 start_ammo_rockets = cvar("g_start_ammo_rockets");
784 start_ammo_cells = cvar("g_start_ammo_cells");
786 start_ammo_shells = cvar("g_pickup_shells_max");
787 start_ammo_nails = cvar("g_pickup_nails_max");
788 start_ammo_rockets = cvar("g_pickup_rockets_max");
789 start_ammo_cells = cvar("g_pickup_cells_max");
790 start_items |= IT_UNLIMITED_AMMO;
793 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
795 e = get_weaponinfo(i);
798 if(((e.spawnflags & 1) && g_lms) || cvar(strcat("g_start_weapon_", e.netname)))
800 start_weapons |= e.weapons;
801 weapon_action(e.weapon, WR_PRECACHE);
808 warmup_start_ammo_shells = start_ammo_shells;
809 warmup_start_ammo_nails = start_ammo_nails;
810 warmup_start_ammo_rockets = start_ammo_rockets;
811 warmup_start_ammo_cells = start_ammo_cells;
812 warmup_start_health = start_health;
813 warmup_start_armorvalue = start_armorvalue;
814 warmup_start_weapons = start_weapons;
816 if(!g_rocketarena && !g_nixnex && !g_minstagib)
818 if(cvar("g_use_ammunition"))
820 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
821 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
822 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
823 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
825 warmup_start_health = cvar("g_warmup_start_health");
826 warmup_start_armorvalue = cvar("g_warmup_start_armor");
827 if(cvar("g_warmup_allguns"))
829 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
831 e = get_weaponinfo(i);
836 warmup_start_weapons |= e.weapons;
837 weapon_action(e.weapon, WR_PRECACHE);
845 void readlevelcvars(void)
847 sv_cheats = cvar("sv_cheats");
848 sv_gentle = cvar("sv_gentle");
849 sv_foginterval = cvar("sv_foginterval");
850 g_cloaked = cvar("g_cloaked");
851 g_jump_grunt = cvar("g_jump_grunt");
852 g_footsteps = cvar("g_footsteps");
853 g_grappling_hook = cvar("g_grappling_hook");
854 g_laserguided_missile = cvar("g_laserguided_missile");
855 g_midair = cvar("g_midair");
856 g_minstagib = cvar("g_minstagib");
857 g_nixnex = cvar("g_nixnex");
858 g_nixnex_with_laser = cvar("g_nixnex_with_laser");
859 g_norecoil = cvar("g_norecoil");
860 g_rocketarena = cvar("g_rocketarena");
861 g_vampire = cvar("g_vampire");
862 sv_maxidle = cvar("sv_maxidle");
863 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
864 sv_pogostick = cvar("sv_pogostick");
865 sv_doublejump = cvar("sv_doublejump");
867 inWarmupStage = cvar("g_warmup");
868 g_warmup_limit = cvar("g_warmup_limit");
869 g_warmup_allguns = cvar("g_warmup_allguns");
870 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
872 if(g_race && g_race_qualifying == 2 || g_arena || g_assault || cvar("g_campaign"))
873 inWarmupStage = 0; // these modes cannot work together, sorry
875 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
876 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
877 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
878 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
880 if(g_minstagib) g_nixnex = g_rocketarena = 0;
881 if(g_nixnex) g_rocketarena = 0;
883 g_pickup_shells = cvar("g_pickup_shells");
884 g_pickup_shells_max = cvar("g_pickup_shells_max");
885 g_pickup_nails = cvar("g_pickup_nails");
886 g_pickup_nails_max = cvar("g_pickup_nails_max");
887 g_pickup_rockets = cvar("g_pickup_rockets");
888 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
889 g_pickup_cells = cvar("g_pickup_cells");
890 g_pickup_cells_max = cvar("g_pickup_cells_max");
891 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
892 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
893 g_pickup_armormedium = cvar("g_pickup_armormedium");
894 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
895 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
896 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
897 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
898 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
899 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
900 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
901 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
902 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
903 g_pickup_healthmega = cvar("g_pickup_healthmega");
904 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
906 readplayerstartcvars();
910 // TODO sound pack system
913 string precache_sound_builtin (string s) = #19;
914 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
915 string precache_sound(string s)
917 return precache_sound_builtin(strcat(soundpack, s));
919 void play2(entity e, string filename)
921 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
923 void sound(entity e, float chan, string samp, float vol, float atten)
925 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
930 string precache_sound (string s) = #19;
931 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
932 float precache_sound_index (string s) = #19;
934 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
937 WriteByte(dest, 27); // all bits except SND_LOOPING
938 WriteByte(dest, vol * 255);
939 WriteByte(dest, atten * 64);
940 WriteEntity(dest, e);
941 WriteByte(dest, chan);
942 WriteShort(dest, precache_sound_index(samp));
943 WriteCoord(dest, o_x);
944 WriteCoord(dest, o_y);
945 WriteCoord(dest, o_z);
947 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
950 o = e.origin + 0.5 * (e.mins + e.maxs);
951 soundtoat(dest, e, o, chan, samp, vol, atten);
953 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
955 soundtoat(MSG_BROADCAST, e, o, chan, samp, vol, atten);
958 void play2(entity e, string filename)
960 //stuffcmd(e, strcat("play2 ", filename, "\n"));
962 soundtoat(MSG_ONE, world, '0 0 0', CHAN_AUTO, filename, VOL_BASE, ATTN_NONE);
966 float announce(entity player, string msg)
968 if(time > player.announcetime)
969 if(clienttype(player) == CLIENTTYPE_REAL)
971 player.announcetime = time + 0.3;
978 void play2team(float t, string filename)
981 FOR_EACH_REALPLAYER(head)
984 play2(head, filename);
988 void play2all(string samp)
990 sound(world, CHAN_AUTO, samp, VOL_BASE, ATTN_NONE);
993 void PrecachePlayerSounds(string f);
994 void precache_all_models(string pattern)
996 float globhandle, i, n;
999 globhandle = search_begin(pattern, TRUE, FALSE);
1002 n = search_getsize(globhandle);
1003 for(i = 0; i < n; ++i)
1005 //print(search_getfilename(globhandle, i), "\n");
1006 f = search_getfilename(globhandle, i);
1008 PrecachePlayerSounds(strcat(f, ".sounds"));
1010 search_end(globhandle);
1015 // gamemode related things
1016 precache_model ("models/misc/chatbubble.spr");
1017 precache_model ("models/misc/teambubble.spr");
1020 precache_model ("models/runematch/curse.mdl");
1021 precache_model ("models/runematch/rune.mdl");
1024 #ifdef TTURRETS_ENABLED
1025 if(cvar("g_turrets"))
1029 // Precache all player models if desired
1030 if (cvar("sv_precacheplayermodels"))
1032 PrecachePlayerSounds("sound/player/default.sounds");
1033 precache_all_models("models/player/*.zym");
1034 precache_all_models("models/player/*.dpm");
1035 precache_all_models("models/player/*.md3");
1036 precache_all_models("models/player/*.psk");
1037 //precache_model("models/player/carni.zym");
1038 //precache_model("models/player/crash.zym");
1039 //precache_model("models/player/grunt.zym");
1040 //precache_model("models/player/headhunter.zym");
1041 //precache_model("models/player/insurrectionist.zym");
1042 //precache_model("models/player/jeandarc.zym");
1043 //precache_model("models/player/lurk.zym");
1044 //precache_model("models/player/lycanthrope.zym");
1045 //precache_model("models/player/marine.zym");
1046 //precache_model("models/player/nexus.zym");
1047 //precache_model("models/player/pyria.zym");
1048 //precache_model("models/player/shock.zym");
1049 //precache_model("models/player/skadi.zym");
1050 //precache_model("models/player/specop.zym");
1051 //precache_model("models/player/visitant.zym");
1056 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1057 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1060 // gore and miscellaneous sounds
1061 //precache_sound ("misc/h2ohit.wav");
1062 precache_model ("models/gibs/bloodyskull.md3");
1063 precache_model ("models/gibs/chunk.mdl");
1064 precache_model ("models/gibs/eye.md3");
1065 precache_model ("models/gibs/gib1.md3");
1066 precache_model ("models/gibs/gib2.md3");
1067 precache_model ("models/gibs/gib3.md3");
1068 precache_model ("models/gibs/gib4.md3");
1069 precache_model ("models/gibs/gib5.md3");
1070 precache_model ("models/gibs/gib6.md3");
1071 precache_model ("models/gibs/smallchest.md3");
1072 precache_model ("models/gibs/chest.md3");
1073 precache_model ("models/gibs/arm.md3");
1074 precache_model ("models/gibs/leg1.md3");
1075 precache_model ("models/gibs/leg2.md3");
1076 precache_model ("models/hook.md3");
1077 precache_sound ("misc/armorimpact.wav");
1078 precache_sound ("misc/bodyimpact1.wav");
1079 precache_sound ("misc/bodyimpact2.wav");
1080 precache_sound ("misc/gib.wav");
1081 precache_sound ("misc/gib_splat01.wav");
1082 precache_sound ("misc/gib_splat02.wav");
1083 precache_sound ("misc/gib_splat03.wav");
1084 precache_sound ("misc/gib_splat04.wav");
1085 precache_sound ("misc/hit.wav");
1086 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1087 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1088 precache_sound ("misc/null.wav");
1089 precache_sound ("misc/spawn.wav");
1090 precache_sound ("misc/talk.wav");
1091 precache_sound ("misc/teleport.wav");
1092 precache_sound ("player/lava.wav");
1093 precache_sound ("player/slime.wav");
1095 // announcer sounds - male
1096 precache_sound ("announcer/male/electrobitch.wav");
1097 precache_sound ("announcer/male/airshot.wav");
1098 precache_sound ("announcer/male/03kills.wav");
1099 precache_sound ("announcer/male/05kills.wav");
1100 precache_sound ("announcer/male/10kills.wav");
1101 precache_sound ("announcer/male/15kills.wav");
1102 precache_sound ("announcer/male/20kills.wav");
1103 precache_sound ("announcer/male/25kills.wav");
1104 precache_sound ("announcer/male/30kills.wav");
1105 precache_sound ("announcer/male/botlike.wav");
1106 precache_sound ("announcer/male/yoda.ogg");
1107 precache_sound ("announcer/male/headshot.ogg");
1108 precache_sound ("announcer/male/impressive.ogg");
1110 // announcer sounds - robotic
1111 precache_sound ("announcer/robotic/prepareforbattle.wav");
1112 precache_sound ("announcer/robotic/begin.wav");
1113 precache_sound ("announcer/robotic/timeoutcalled.wav");
1114 precache_sound ("announcer/robotic/1fragleft.wav");
1115 precache_sound ("announcer/robotic/1minuteremains.wav");
1116 precache_sound ("announcer/robotic/2fragsleft.wav");
1117 precache_sound ("announcer/robotic/3fragsleft.wav");
1120 precache_sound ("announcer/robotic/lastsecond.wav");
1121 precache_sound ("announcer/robotic/narrowly.wav");
1124 precache_model ("models/sprites/1.spr32");
1125 precache_model ("models/sprites/2.spr32");
1126 precache_model ("models/sprites/3.spr32");
1127 precache_model ("models/sprites/4.spr32");
1128 precache_model ("models/sprites/5.spr32");
1129 precache_model ("models/sprites/6.spr32");
1130 precache_model ("models/sprites/7.spr32");
1131 precache_model ("models/sprites/8.spr32");
1132 precache_model ("models/sprites/9.spr32");
1133 precache_model ("models/sprites/10.spr32");
1134 precache_sound ("announcer/robotic/1.ogg");
1135 precache_sound ("announcer/robotic/2.ogg");
1136 precache_sound ("announcer/robotic/3.ogg");
1137 precache_sound ("announcer/robotic/4.ogg");
1138 precache_sound ("announcer/robotic/5.ogg");
1139 precache_sound ("announcer/robotic/6.ogg");
1140 precache_sound ("announcer/robotic/7.ogg");
1141 precache_sound ("announcer/robotic/8.ogg");
1142 precache_sound ("announcer/robotic/9.ogg");
1143 precache_sound ("announcer/robotic/10.ogg");
1145 // common weapon precaches
1146 precache_sound ("weapons/weapon_switch.wav");
1147 precache_sound ("weapons/weaponpickup.wav");
1148 if (cvar("g_grappling_hook"))
1150 precache_sound ("weapons/hook_fire.wav"); // hook
1151 precache_sound ("weapons/hook_impact.wav"); // hook
1154 if (cvar("sv_precacheweapons") || g_nixnex)
1156 //precache weapon models/sounds
1159 while (wep <= WEP_LAST)
1161 weapon_action(wep, WR_PRECACHE);
1166 // plays music for the level if there is any
1169 precache_sound (self.noise);
1170 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1174 // sorry, but using \ in macros breaks line numbers
1175 #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
1176 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1177 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1179 vector ExactTriggerHit_mins;
1180 vector ExactTriggerHit_maxs;
1181 float ExactTriggerHit_Recurse()
1187 tracebox('0 0 0', ExactTriggerHit_mins, ExactTriggerHit_maxs, '0 0 0', MOVE_NORMAL, other);
1190 if(trace_ent == self)
1195 se.solid = SOLID_NOT;
1196 f = ExactTriggerHit_Recurse();
1202 float ExactTriggerHit()
1206 if not(self.modelindex)
1210 self.solid = SOLID_BSP;
1211 ExactTriggerHit_mins = other.absmin;
1212 ExactTriggerHit_maxs = other.absmax;
1213 f = ExactTriggerHit_Recurse();
1219 // WARNING: this kills the trace globals
1220 #define EXACTTRIGGER_TOUCH if not(ExactTriggerHit()) return
1221 #define EXACTTRIGGER_INIT InitSolidBSPTrigger(); self.solid = SOLID_TRIGGER
1223 #define INITPRIO_FIRST 0
1224 #define INITPRIO_GAMETYPE 0
1225 #define INITPRIO_GAMETYPE_FALLBACK 1
1226 #define INITPRIO_CVARS 5
1227 #define INITPRIO_FINDTARGET 10
1228 #define INITPRIO_DROPTOFLOOR 20
1229 #define INITPRIO_SETLOCATION 90
1230 #define INITPRIO_LINKDOORS 91
1231 #define INITPRIO_LAST 99
1233 .void(void) initialize_entity;
1234 .float initialize_entity_order;
1235 .entity initialize_entity_next;
1236 entity initialize_entity_first;
1238 void make_safe_for_remove(entity e)
1240 if(e.initialize_entity)
1243 for(ent = initialize_entity_first; ent; )
1245 if((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1247 print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1248 // skip it in linked list
1251 prev.initialize_entity_next = ent.initialize_entity_next;
1252 ent = prev.initialize_entity_next;
1256 initialize_entity_first = ent.initialize_entity_next;
1257 ent = initialize_entity_first;
1263 ent = ent.initialize_entity_next;
1269 void objerror(string s)
1271 make_safe_for_remove(self);
1272 objerror_builtin(s);
1275 void remove_safely(entity e)
1277 make_safe_for_remove(e);
1281 void InitializeEntity(entity e, void(void) func, float order)
1285 if(!e || e.initialize_entity)
1287 // make a proxy initializer entity
1291 e.classname = "initialize_entity";
1295 e.initialize_entity = func;
1296 e.initialize_entity_order = order;
1298 cur = initialize_entity_first;
1301 if(!cur || cur.initialize_entity_order > order)
1303 // insert between prev and cur
1305 prev.initialize_entity_next = e;
1307 initialize_entity_first = e;
1308 e.initialize_entity_next = cur;
1312 cur = cur.initialize_entity_next;
1315 void InitializeEntitiesRun()
1318 startoflist = initialize_entity_first;
1319 initialize_entity_first = world;
1320 for(self = startoflist; self; )
1323 var void(void) func;
1324 e = self.initialize_entity_next;
1325 func = self.initialize_entity;
1326 self.initialize_entity_order = 0;
1327 self.initialize_entity = func_null;
1328 self.initialize_entity_next = world;
1329 if(self.classname == "initialize_entity")
1333 remove_builtin(self);
1336 dprint("Delayed initialization: ", self.classname, "\n");
1342 .float uncustomizeentityforclient_set;
1343 .void(void) uncustomizeentityforclient;
1344 void(void) SUB_Nullpointer = #0;
1345 void UncustomizeEntitiesRun()
1349 for(self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1350 self.uncustomizeentityforclient();
1353 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1355 e.customizeentityforclient = customizer;
1356 e.uncustomizeentityforclient = uncustomizer;
1357 e.uncustomizeentityforclient_set = (uncustomizer != SUB_Nullpointer);
1361 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1363 float power2of(float e)
1367 float log2of(float x)
1369 // NOTE: generated code
1444 // - basically func_assault_destructible for general gameplay use
1447 void () SUB_UseTargets, assault_destructible_use, SUB_Remove, SUB_Null;
1448 void LaunchDebris (string debrisname) =
1452 if (debrisname == "" || !debrisname)
1456 dbr.origin = self.origin;
1457 setmodel (dbr, debrisname );
1458 setsize (dbr, '0 0 0', '0 0 0');
1459 dbr.velocity_x = 70 * crandom();
1460 dbr.velocity_y = 70 * crandom();
1461 dbr.velocity_z = 140 + 70 * random();
1462 dbr.movetype = MOVETYPE_BOUNCE;
1463 dbr.solid = SOLID_BBOX;
1464 dbr.avelocity_x = random()*600;
1465 dbr.avelocity_y = random()*600;
1466 dbr.avelocity_z = random()*600;
1467 dbr.think = SUB_Remove;
1468 dbr.nextthink = time + 13 + random()*10;
1471 .string debris1, debris2, debris3;
1473 void func_breakable_destroy() {
1475 setmodel(self, self.mdl_dead);
1478 self.solid = SOLID_NOT;
1480 self.takedamage = DAMAGE_NO;
1482 // now throw around the debris
1483 LaunchDebris(self.debris1);
1484 LaunchDebris(self.debris2);
1485 LaunchDebris(self.debris3);
1489 self.event_damage = SUB_Null;
1492 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) {
1495 self.health = self.health - damage;
1496 // add pain effects?
1499 if(self.health < 0) {
1500 activator = attacker;
1501 func_breakable_destroy();
1505 // destructible walls that can be used to trigger target_objective_decrease
1506 void spawnfunc_func_breakable() {
1510 self.max_health = self.health;
1512 //self.cnt = 0; // not yet activated
1516 self.classname = "func_breakable";
1517 self.mdl = self.model;
1518 setmodel(self, self.mdl);
1520 self.solid = SOLID_BSP;
1522 // precache all the models
1524 precache_model(self.mdl_dead);
1526 precache_model(self.debris1);
1528 precache_model(self.debris2);
1530 precache_model(self.debris3);
1532 self.use = assault_destructible_use; // shared use function, b/c they woudl do the same thing anyways
1533 self.event_damage = func_breakable_damage;
1536 void Net_LinkEntity(entity e)
1538 e.model = "net_entity";
1540 e.effects = EF_NODEPTHTEST | EF_LOWPRECISION;
1543 void adaptor_think2touch()
1552 void adaptor_think2use()
1564 // deferred dropping
1565 void DropToFloor_Handler()
1567 droptofloor_builtin();
1568 self.dropped_origin = self.origin;
1573 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1578 float trace_hits_box_a0, trace_hits_box_a1;
1580 float trace_hits_box_1d(float end, float thmi, float thma)
1584 // just check if x is in range
1592 // do the trace with respect to x
1593 // 0 -> end has to stay in thmi -> thma
1594 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1595 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1596 if(trace_hits_box_a0 > trace_hits_box_a1)
1602 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1607 // now it is a trace from 0 to end
1609 trace_hits_box_a0 = 0;
1610 trace_hits_box_a1 = 1;
1612 if(!trace_hits_box_1d(end_x, thmi_x, thma_x))
1614 if(!trace_hits_box_1d(end_y, thmi_y, thma_y))
1616 if(!trace_hits_box_1d(end_z, thmi_z, thma_z))
1622 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1624 return trace_hits_box(start, end, thmi - ma, thma - mi);