1 var void remove(entity e);
2 void objerror(string s);
4 .vector dropped_origin;
6 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
7 void crosshair_trace(entity pl)
9 traceline_antilag(pl, pl.cursor_trace_start, pl.cursor_trace_start + normalize(pl.cursor_trace_endpos - pl.cursor_trace_start) * MAX_SHOT_DISTANCE, MOVE_NORMAL, pl, ANTILAG_LATENCY(pl));
11 void crosshair_trace_plusvisibletriggers(entity pl)
15 first = findchainfloat(solid, SOLID_TRIGGER);
17 for (e = first; e; e = e.chain)
23 for (e = first; e; e = e.chain)
24 e.solid = SOLID_TRIGGER;
26 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
27 void WarpZone_crosshair_trace(entity pl)
29 WarpZone_traceline_antilag(pl, pl.cursor_trace_start, pl.cursor_trace_start + normalize(pl.cursor_trace_endpos - pl.cursor_trace_start) * MAX_SHOT_DISTANCE, MOVE_NORMAL, pl, ANTILAG_LATENCY(pl));
32 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
33 void() spawnpoint_use;
35 string ColoredTeamName(float t);
37 string admin_name(void)
39 if(autocvar_sv_adminnick != "")
40 return autocvar_sv_adminnick;
42 return "SERVER ADMIN";
45 float DistributeEvenly_amount;
46 float DistributeEvenly_totalweight;
47 void DistributeEvenly_Init(float amount, float totalweight)
49 if (DistributeEvenly_amount)
51 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
52 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
55 DistributeEvenly_amount = 0;
57 DistributeEvenly_amount = amount;
58 DistributeEvenly_totalweight = totalweight;
60 float DistributeEvenly_Get(float weight)
65 f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
66 DistributeEvenly_totalweight -= weight;
67 DistributeEvenly_amount -= f;
70 float DistributeEvenly_GetRandomized(float weight)
75 f = floor(random() + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
76 DistributeEvenly_totalweight -= weight;
77 DistributeEvenly_amount -= f;
81 #define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e)
84 string STR_PLAYER = "player";
85 string STR_SPECTATOR = "spectator";
86 string STR_OBSERVER = "observer";
89 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
90 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
91 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
92 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
94 #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
95 #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(v.flags & FL_CLIENT)
96 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
97 #define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER)
98 #define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER)
101 // copies a string to a tempstring (so one can strunzone it)
102 string strcat1(string s) = #115; // FRIK_FILE
107 void bcenterprint(string s)
109 // TODO replace by MSG_ALL (would show it to spectators too, though)?
111 FOR_EACH_PLAYER(head)
112 if (clienttype(head) == CLIENTTYPE_REAL)
113 centerprint(head, s);
116 void GameLogEcho(string s)
121 if (autocvar_sv_eventlog_files)
126 matches = autocvar_sv_eventlog_files_counter + 1;
127 cvar_set("sv_eventlog_files_counter", ftos(matches));
130 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
131 fn = strcat(autocvar_sv_eventlog_files_nameprefix, fn, autocvar_sv_eventlog_files_namesuffix);
132 logfile = fopen(fn, FILE_APPEND);
133 fputs(logfile, ":logversion:3\n");
137 if (autocvar_sv_eventlog_files_timestamps)
138 fputs(logfile, strcat(":time:", strftime(TRUE, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
140 fputs(logfile, strcat(s, "\n"));
143 if (autocvar_sv_eventlog_console)
152 // will be opened later
157 if (logfile_open && logfile >= 0)
164 float spawnpoint_nag;
165 void relocate_spawnpoint()
167 // nudge off the floor
168 setorigin(self, self.origin + '0 0 1');
170 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
171 if (trace_startsolid)
177 if (!move_out_of_solid(self))
178 objerror("could not get out of solid at all!");
179 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
180 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
181 print(" ", ftos(self.origin_y - o_y));
182 print(" ", ftos(self.origin_z - o_z), "'\n");
183 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
186 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
192 self.mins = self.maxs = '0 0 0';
193 objerror("player spawn point in solid, mapper sucks!\n");
198 self.use = spawnpoint_use;
199 self.team_saved = self.team;
203 if (have_team_spawns != 0)
205 have_team_spawns = 1;
206 have_team_spawns_forteam[self.team] = 1;
208 if (autocvar_r_showbboxes)
210 // show where spawnpoints point at too
211 makevectors(self.angles);
214 e.classname = "info_player_foo";
215 setorigin(e, self.origin + v_forward * 24);
216 setsize(e, '-8 -8 -8', '8 8 8');
217 e.solid = SOLID_TRIGGER;
221 #define strstr strstrofs
223 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
224 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
225 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
226 // BE CONSTANT OR strzoneD!
227 float strstr(string haystack, string needle, float offset)
231 len = strlen(needle);
232 endpos = strlen(haystack) - len;
233 while(offset <= endpos)
235 found = substring(haystack, offset, len);
244 float NUM_NEAREST_ENTITIES = 4;
245 entity nearest_entity[NUM_NEAREST_ENTITIES];
246 float nearest_length[NUM_NEAREST_ENTITIES];
247 entity findnearest(vector point, .string field, string value, vector axismod)
258 localhead = find(world, field, value);
261 if ((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
262 dist = localhead.oldorigin;
264 dist = localhead.origin;
266 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
269 for (i = 0; i < num_nearest; ++i)
271 if (len < nearest_length[i])
275 // now i tells us where to insert at
276 // INSERTION SORT! YOU'VE SEEN IT! RUN!
277 if (i < NUM_NEAREST_ENTITIES)
279 for (j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
281 nearest_length[j + 1] = nearest_length[j];
282 nearest_entity[j + 1] = nearest_entity[j];
284 nearest_length[i] = len;
285 nearest_entity[i] = localhead;
286 if (num_nearest < NUM_NEAREST_ENTITIES)
287 num_nearest = num_nearest + 1;
290 localhead = find(localhead, field, value);
293 // now use the first one from our list that we can see
294 for (i = 0; i < num_nearest; ++i)
296 traceline(point, nearest_entity[i].origin, TRUE, world);
297 if (trace_fraction == 1)
301 dprint("Nearest point (");
302 dprint(nearest_entity[0].netname);
303 dprint(") is not visible, using a visible one.\n");
305 return nearest_entity[i];
309 if (num_nearest == 0)
312 dprint("Not seeing any location point, using nearest as fallback.\n");
314 dprint("Candidates were: ");
315 for(j = 0; j < num_nearest; ++j)
319 dprint(nearest_entity[j].netname);
324 return nearest_entity[0];
327 void spawnfunc_target_location()
329 self.classname = "target_location";
330 // location name in netname
331 // eventually support: count, teamgame selectors, line of sight?
334 void spawnfunc_info_location()
336 self.classname = "target_location";
337 self.message = self.netname;
340 string NearestLocation(vector p)
345 loc = findnearest(p, classname, "target_location", '1 1 1');
352 loc = findnearest(p, target, "###item###", '1 1 4');
359 string formatmessage(string msg)
370 WarpZone_crosshair_trace(self);
371 cursor = trace_endpos;
372 cursor_ent = trace_ent;
376 break; // too many replacements
379 p1 = strstr(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
380 p2 = strstr(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
393 replacement = substring(msg, p, 2);
394 escape = substring(msg, p + 1, 1);
398 else if (escape == "\\")
400 else if (escape == "n")
402 else if (escape == "a")
403 replacement = ftos(floor(self.armorvalue));
404 else if (escape == "h")
405 replacement = ftos(floor(self.health));
406 else if (escape == "l")
407 replacement = NearestLocation(self.origin);
408 else if (escape == "y")
409 replacement = NearestLocation(cursor);
410 else if (escape == "d")
411 replacement = NearestLocation(self.death_origin);
412 else if (escape == "w") {
416 wep = self.switchweapon;
419 replacement = W_Name(wep);
420 } else if (escape == "W") {
421 if (self.items & IT_SHELLS) replacement = "shells";
422 else if (self.items & IT_NAILS) replacement = "bullets";
423 else if (self.items & IT_ROCKETS) replacement = "rockets";
424 else if (self.items & IT_CELLS) replacement = "cells";
425 else replacement = "batteries"; // ;)
426 } else if (escape == "x") {
427 replacement = cursor_ent.netname;
428 if (!replacement || !cursor_ent)
429 replacement = "nothing";
430 } else if (escape == "s")
431 replacement = ftos(vlen(self.velocity - self.velocity_z * '0 0 1'));
432 else if (escape == "S")
433 replacement = ftos(vlen(self.velocity));
435 msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
436 p = p + strlen(replacement);
441 float boolean(float value) { // if value is 0 return FALSE (0), otherwise return TRUE (1)
442 return (value == 0) ? FALSE : TRUE;
451 >0: receives a cvar from name=argv(f) value=argv(f+1)
453 void GetCvars_handleString(string thisname, float f, .string field, string name)
458 strunzone(self.field);
459 self.field = string_null;
463 if (thisname == name)
466 strunzone(self.field);
467 self.field = strzone(argv(f + 1));
471 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
473 void GetCvars_handleString_Fixup(string thisname, float f, .string field, string name, string(string) func)
475 GetCvars_handleString(thisname, f, field, name);
476 if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
477 if (thisname == name)
480 s = func(strcat1(self.field));
483 strunzone(self.field);
484 self.field = strzone(s);
488 void GetCvars_handleFloat(string thisname, float f, .float field, string name)
495 if (thisname == name)
496 self.field = stof(argv(f + 1));
499 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
501 void GetCvars_handleFloatOnce(string thisname, float f, .float field, string name)
508 if (thisname == name)
512 self.field = stof(argv(f + 1));
521 stuffcmd(self, strcat("cl_cmd sendcvar ", name, "\n"));
524 float w_getbestweapon(entity e);
525 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(string wo)
528 o = W_FixWeaponOrder_ForceComplete(wo);
529 if(self.weaponorder_byimpulse)
531 strunzone(self.weaponorder_byimpulse);
532 self.weaponorder_byimpulse = string_null;
534 self.weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(o));
537 void GetCvars(float f)
539 string s = string_null;
542 s = strcat1(argv(f));
546 MUTATOR_CALLHOOK(GetCvars);
547 GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch");
548 GetCvars_handleFloat(s, f, cvar_cl_autoscreenshot, "cl_autoscreenshot");
549 GetCvars_handleString(s, f, cvar_g_xonoticversion, "g_xonoticversion");
550 GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
551 GetCvars_handleFloat(s, f, cvar_cl_clippedspectating, "cl_clippedspectating");
552 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
553 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
554 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
555 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
556 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
557 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
558 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
559 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
560 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
561 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
562 GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
563 GetCvars_handleFloat(s, f, cvar_cl_weaponimpulsemode, "cl_weaponimpulsemode");
564 GetCvars_handleFloat(s, f, cvar_cl_autotaunt, "cl_autotaunt");
565 GetCvars_handleFloat(s, f, cvar_cl_noantilag, "cl_noantilag");
566 GetCvars_handleFloat(s, f, cvar_cl_voice_directional, "cl_voice_directional");
567 GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation");
568 GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_share, "cl_accuracy_data_share");
569 GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_receive, "cl_accuracy_data_receive");
571 self.cvar_cl_accuracy_data_share = boolean(self.cvar_cl_accuracy_data_share);
572 self.cvar_cl_accuracy_data_receive = boolean(self.cvar_cl_accuracy_data_receive);
574 #ifdef ALLOW_FORCEMODELS
575 GetCvars_handleFloat(s, f, cvar_cl_forceplayermodels, "cl_forceplayermodels");
576 GetCvars_handleFloat(s, f, cvar_cl_forceplayermodelsfromxonotic, "cl_forceplayermodelsfromxonotic");
578 GetCvars_handleFloatOnce(s, f, cvar_cl_gunalign, "cl_gunalign");
579 GetCvars_handleFloat(s, f, cvar_cl_allow_uid2name, "cl_allow_uid2name");
580 GetCvars_handleFloat(s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
581 GetCvars_handleFloat(s, f, cvar_cl_movement_track_canjump, "cl_movement_track_canjump");
582 GetCvars_handleFloat(s, f, cvar_cl_newusekeysupported, "cl_newusekeysupported");
584 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
587 if (s == "cl_weaponpriority")
588 self.switchweapon = w_getbestweapon(self);
589 if (s == "cl_allow_uidtracking")
590 PlayerStats_AddPlayer(self);
594 void backtrace(string msg)
597 dev = autocvar_developer;
598 war = autocvar_prvm_backtraceforwarnings;
599 cvar_set("developer", "1");
600 cvar_set("prvm_backtraceforwarnings", "1");
602 print("--- CUT HERE ---\nWARNING: ");
605 remove(world); // isn't there any better way to cause a backtrace?
606 print("\n--- CUT UNTIL HERE ---\n");
607 cvar_set("developer", ftos(dev));
608 cvar_set("prvm_backtraceforwarnings", ftos(war));
611 string Team_ColorCode(float teamid)
613 if (teamid == COLOR_TEAM1)
615 else if (teamid == COLOR_TEAM2)
617 else if (teamid == COLOR_TEAM3)
619 else if (teamid == COLOR_TEAM4)
625 string Team_ColorName(float t)
627 // fixme: Search for team entities and get their .netname's!
628 if (t == COLOR_TEAM1)
630 if (t == COLOR_TEAM2)
632 if (t == COLOR_TEAM3)
634 if (t == COLOR_TEAM4)
639 string Team_ColorNameLowerCase(float t)
641 // fixme: Search for team entities and get their .netname's!
642 if (t == COLOR_TEAM1)
644 if (t == COLOR_TEAM2)
646 if (t == COLOR_TEAM3)
648 if (t == COLOR_TEAM4)
653 float ColourToNumber(string team_colour)
655 if (team_colour == "red")
658 if (team_colour == "blue")
661 if (team_colour == "yellow")
664 if (team_colour == "pink")
667 if (team_colour == "auto")
673 float NumberToTeamNumber(float number)
690 // decolorizes and team colors the player name when needed
691 string playername(entity p)
694 if (teamplay && !intermission_running && p.classname == "player")
696 t = Team_ColorCode(p.team);
697 return strcat(t, strdecolorize(p.netname));
703 vector randompos(vector m1, vector m2)
707 v_x = m2_x * random() + m1_x;
708 v_y = m2_y * random() + m1_y;
709 v_z = m2_z * random() + m1_z;
713 //#NO AUTOCVARS START
715 float g_pickup_shells;
716 float g_pickup_shells_max;
717 float g_pickup_nails;
718 float g_pickup_nails_max;
719 float g_pickup_rockets;
720 float g_pickup_rockets_max;
721 float g_pickup_cells;
722 float g_pickup_cells_max;
724 float g_pickup_fuel_jetpack;
725 float g_pickup_fuel_max;
726 float g_pickup_armorsmall;
727 float g_pickup_armorsmall_max;
728 float g_pickup_armorsmall_anyway;
729 float g_pickup_armormedium;
730 float g_pickup_armormedium_max;
731 float g_pickup_armormedium_anyway;
732 float g_pickup_armorbig;
733 float g_pickup_armorbig_max;
734 float g_pickup_armorbig_anyway;
735 float g_pickup_armorlarge;
736 float g_pickup_armorlarge_max;
737 float g_pickup_armorlarge_anyway;
738 float g_pickup_healthsmall;
739 float g_pickup_healthsmall_max;
740 float g_pickup_healthsmall_anyway;
741 float g_pickup_healthmedium;
742 float g_pickup_healthmedium_max;
743 float g_pickup_healthmedium_anyway;
744 float g_pickup_healthlarge;
745 float g_pickup_healthlarge_max;
746 float g_pickup_healthlarge_anyway;
747 float g_pickup_healthmega;
748 float g_pickup_healthmega_max;
749 float g_pickup_healthmega_anyway;
750 float g_pickup_ammo_anyway;
751 float g_pickup_weapons_anyway;
753 WEPSET_DECLARE_A(g_weaponarena_weapons);
754 float g_weaponarena_random;
755 float g_weaponarena_random_with_laser;
756 string g_weaponarena_list;
757 float g_weaponspeedfactor;
758 float g_weaponratefactor;
759 float g_weapondamagefactor;
760 float g_weaponforcefactor;
761 float g_weaponspreadfactor;
763 WEPSET_DECLARE_A(start_weapons);
764 WEPSET_DECLARE_A(start_weapons_default);
765 WEPSET_DECLARE_A(start_weapons_defaultmask);
767 float start_ammo_shells;
768 float start_ammo_nails;
769 float start_ammo_rockets;
770 float start_ammo_cells;
771 float start_ammo_fuel;
773 float start_armorvalue;
774 WEPSET_DECLARE_A(warmup_start_weapons);
775 WEPSET_DECLARE_A(warmup_start_weapons_default);
776 WEPSET_DECLARE_A(warmup_start_weapons_defaultmask);
777 float warmup_start_ammo_shells;
778 float warmup_start_ammo_nails;
779 float warmup_start_ammo_rockets;
780 float warmup_start_ammo_cells;
781 float warmup_start_ammo_fuel;
782 float warmup_start_health;
783 float warmup_start_armorvalue;
786 entity get_weaponinfo(float w);
788 float want_weapon(string cvarprefix, entity weaponinfo, float allguns)
790 var float i = weaponinfo.weapon;
796 if (g_lms || g_ca || allguns)
798 if(weaponinfo.spawnflags & WEP_FLAG_NORMAL)
804 d = (i == WEP_SHOTGUN);
806 d = 0; // weapon is set a few lines later
808 d = (i == WEP_LASER || i == WEP_SHOTGUN);
810 if(g_grappling_hook) // if possible, redirect off-hand hook to on-hand hook
811 d |= (i == WEP_HOOK);
812 if(weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED) // never default mutator blocked guns
815 var float t = cvar(strcat(cvarprefix, weaponinfo.netname));
817 //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n"));
822 // 4: is set by default?
831 void readplayerstartcvars()
837 // initialize starting values for players
838 WEPSET_CLEAR_A(start_weapons);
839 WEPSET_CLEAR_A(start_weapons_default);
840 WEPSET_CLEAR_A(start_weapons_defaultmask);
842 start_ammo_shells = 0;
843 start_ammo_nails = 0;
844 start_ammo_rockets = 0;
845 start_ammo_cells = 0;
846 start_health = cvar("g_balance_health_start");
847 start_armorvalue = cvar("g_balance_armor_start");
850 WEPSET_CLEAR_A(g_weaponarena_weapons);
852 s = cvar_string("g_weaponarena");
853 if (s == "0" || s == "")
859 if (s == "0" || s == "")
865 // forcibly turn off weaponarena
870 g_weaponarena_list = "All Weapons";
871 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
873 e = get_weaponinfo(j);
874 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
875 WEPSET_OR_AW(g_weaponarena_weapons, j);
878 else if (s == "most")
881 g_weaponarena_list = "Most Weapons";
882 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
884 e = get_weaponinfo(j);
885 if not(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
886 if (e.spawnflags & WEP_FLAG_NORMAL)
887 WEPSET_OR_AW(g_weaponarena_weapons, j);
890 else if (s == "none")
893 g_weaponarena_list = "No Weapons";
898 t = tokenize_console(s);
899 g_weaponarena_list = "";
900 for (i = 0; i < t; ++i)
903 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
905 e = get_weaponinfo(j);
908 WEPSET_OR_AW(g_weaponarena_weapons, j);
909 g_weaponarena_list = strcat(g_weaponarena_list, e.message, " & ");
915 print("The weapon mutator list contains an unknown weapon ", s, ". Skipped.\n");
918 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
922 g_weaponarena_random = cvar("g_weaponarena_random");
924 g_weaponarena_random = 0;
925 g_weaponarena_random_with_laser = cvar("g_weaponarena_random_with_laser");
929 g_minstagib = 0; // incompatible
930 g_pinata = 0; // incompatible
931 g_weapon_stay = 0; // incompatible
932 WEPSET_COPY_AA(start_weapons, g_weaponarena_weapons);
934 start_items |= IT_UNLIMITED_AMMO;
936 else if (g_minstagib)
938 g_pinata = 0; // incompatible
939 g_weapon_stay = 0; // incompatible
940 g_bloodloss = 0; // incompatible
942 start_armorvalue = 0;
943 WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
944 g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
945 start_items |= IT_UNLIMITED_SUPERWEAPONS;
947 if (g_minstagib_invis_alpha <= 0)
948 g_minstagib_invis_alpha = -1;
952 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
954 e = get_weaponinfo(i);
955 float w = want_weapon("g_start_weapon_", e, FALSE);
957 WEPSET_OR_AW(start_weapons, i);
959 WEPSET_OR_AW(start_weapons_default, i);
961 WEPSET_OR_AW(start_weapons_defaultmask, i);
965 if(!cvar("g_use_ammunition"))
966 start_items |= IT_UNLIMITED_AMMO;
968 if(cvar("g_nexball"))
969 start_items |= IT_UNLIMITED_SUPERWEAPONS; // FIXME BAD BAD BAD BAD HACK, NEXBALL SHOULDN'T ABUSE PORTO'S WEAPON SLOT
973 start_ammo_cells = cvar("g_minstagib_ammo_start");
974 start_ammo_fuel = cvar("g_start_ammo_fuel");
976 else if(start_items & IT_UNLIMITED_WEAPON_AMMO)
978 start_ammo_rockets = 999;
979 start_ammo_shells = 999;
980 start_ammo_cells = 999;
981 start_ammo_nails = 999;
982 start_ammo_fuel = 999;
988 start_ammo_shells = cvar("g_lms_start_ammo_shells");
989 start_ammo_nails = cvar("g_lms_start_ammo_nails");
990 start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
991 start_ammo_cells = cvar("g_lms_start_ammo_cells");
992 start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
996 start_ammo_shells = cvar("g_start_ammo_shells");
997 start_ammo_nails = cvar("g_start_ammo_nails");
998 start_ammo_rockets = cvar("g_start_ammo_rockets");
999 start_ammo_cells = cvar("g_start_ammo_cells");
1000 start_ammo_fuel = cvar("g_start_ammo_fuel");
1006 start_health = cvar("g_lms_start_health");
1007 start_armorvalue = cvar("g_lms_start_armor");
1012 warmup_start_ammo_shells = start_ammo_shells;
1013 warmup_start_ammo_nails = start_ammo_nails;
1014 warmup_start_ammo_rockets = start_ammo_rockets;
1015 warmup_start_ammo_cells = start_ammo_cells;
1016 warmup_start_ammo_fuel = start_ammo_fuel;
1017 warmup_start_health = start_health;
1018 warmup_start_armorvalue = start_armorvalue;
1019 WEPSET_COPY_AA(warmup_start_weapons, start_weapons);
1020 WEPSET_COPY_AA(warmup_start_weapons_default, start_weapons_default);
1021 WEPSET_COPY_AA(warmup_start_weapons_defaultmask, start_weapons_defaultmask);
1023 if (!g_weaponarena && !g_minstagib && !g_ca)
1025 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
1026 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
1027 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
1028 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
1029 warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
1030 warmup_start_health = cvar("g_warmup_start_health");
1031 warmup_start_armorvalue = cvar("g_warmup_start_armor");
1032 WEPSET_CLEAR_A(warmup_start_weapons);
1033 WEPSET_CLEAR_A(warmup_start_weapons_default);
1034 WEPSET_CLEAR_A(warmup_start_weapons_defaultmask);
1035 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1037 e = get_weaponinfo(i);
1038 float w = want_weapon("g_start_weapon_", e, cvar("g_warmup_allguns"));
1040 WEPSET_OR_AW(warmup_start_weapons, i);
1042 WEPSET_OR_AW(warmup_start_weapons_default, i);
1044 WEPSET_OR_AW(warmup_start_weapons_defaultmask, i);
1050 start_items |= IT_JETPACK;
1052 MUTATOR_CALLHOOK(SetStartItems);
1054 if ((start_items & IT_JETPACK) || (g_grappling_hook && WEPSET_CONTAINS_AW(start_weapons, WEP_HOOK)))
1056 g_grappling_hook = 0; // these two can't coexist, as they use the same button
1057 start_items |= IT_FUEL_REGEN;
1058 start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1059 warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
1062 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
1064 e = get_weaponinfo(i);
1065 if(WEPSET_CONTAINS_AW(start_weapons, i) || WEPSET_CONTAINS_AW(warmup_start_weapons, i))
1066 weapon_action(i, WR_PRECACHE);
1069 start_ammo_shells = max(0, start_ammo_shells);
1070 start_ammo_nails = max(0, start_ammo_nails);
1071 start_ammo_cells = max(0, start_ammo_cells);
1072 start_ammo_rockets = max(0, start_ammo_rockets);
1073 start_ammo_fuel = max(0, start_ammo_fuel);
1075 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
1076 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
1077 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
1078 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
1079 warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
1083 float g_bugrigs_planar_movement;
1084 float g_bugrigs_planar_movement_car_jumping;
1085 float g_bugrigs_reverse_spinning;
1086 float g_bugrigs_reverse_speeding;
1087 float g_bugrigs_reverse_stopping;
1088 float g_bugrigs_air_steering;
1089 float g_bugrigs_angle_smoothing;
1090 float g_bugrigs_friction_floor;
1091 float g_bugrigs_friction_brake;
1092 float g_bugrigs_friction_air;
1093 float g_bugrigs_accel;
1094 float g_bugrigs_speed_ref;
1095 float g_bugrigs_speed_pow;
1096 float g_bugrigs_steer;
1098 float g_touchexplode;
1099 float g_touchexplode_radius;
1100 float g_touchexplode_damage;
1101 float g_touchexplode_edgedamage;
1102 float g_touchexplode_force;
1109 float sv_pitch_fixyaw;
1111 string GetGametype(); // g_world.qc
1112 void readlevelcvars(void)
1114 g_minstagib = cvar("g_minstagib");
1116 // load ALL the mutators
1117 if(cvar("g_dodging"))
1118 MUTATOR_ADD(mutator_dodging);
1119 if(cvar("g_spawn_near_teammate"))
1120 MUTATOR_ADD(mutator_spawn_near_teammate);
1123 if(cvar("g_invincible_projectiles"))
1124 MUTATOR_ADD(mutator_invincibleprojectiles);
1125 if(cvar("g_new_toys"))
1126 MUTATOR_ADD(mutator_new_toys);
1128 MUTATOR_ADD(mutator_nix);
1129 if(cvar("g_rocket_flying"))
1130 MUTATOR_ADD(mutator_rocketflying);
1131 if(cvar("g_vampire"))
1132 MUTATOR_ADD(mutator_vampire);
1135 // is this a mutator? is this a mode?
1136 if(cvar("g_sandbox"))
1137 MUTATOR_ADD(sandbox);
1139 if(cvar("sv_allow_fullbright"))
1140 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
1142 g_bugrigs = cvar("g_bugrigs");
1143 g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement");
1144 g_bugrigs_planar_movement_car_jumping = cvar("g_bugrigs_planar_movement_car_jumping");
1145 g_bugrigs_reverse_spinning = cvar("g_bugrigs_reverse_spinning");
1146 g_bugrigs_reverse_speeding = cvar("g_bugrigs_reverse_speeding");
1147 g_bugrigs_reverse_stopping = cvar("g_bugrigs_reverse_stopping");
1148 g_bugrigs_air_steering = cvar("g_bugrigs_air_steering");
1149 g_bugrigs_angle_smoothing = cvar("g_bugrigs_angle_smoothing");
1150 g_bugrigs_friction_floor = cvar("g_bugrigs_friction_floor");
1151 g_bugrigs_friction_brake = cvar("g_bugrigs_friction_brake");
1152 g_bugrigs_friction_air = cvar("g_bugrigs_friction_air");
1153 g_bugrigs_accel = cvar("g_bugrigs_accel");
1154 g_bugrigs_speed_ref = cvar("g_bugrigs_speed_ref");
1155 g_bugrigs_speed_pow = cvar("g_bugrigs_speed_pow");
1156 g_bugrigs_steer = cvar("g_bugrigs_steer");
1158 g_touchexplode = cvar("g_touchexplode");
1159 g_touchexplode_radius = cvar("g_touchexplode_radius");
1160 g_touchexplode_damage = cvar("g_touchexplode_damage");
1161 g_touchexplode_edgedamage = cvar("g_touchexplode_edgedamage");
1162 g_touchexplode_force = cvar("g_touchexplode_force");
1164 #ifdef ALLOW_FORCEMODELS
1165 sv_clforceplayermodels = cvar("sv_clforceplayermodels");
1168 sv_clones = cvar("sv_clones");
1169 sv_gentle = cvar("sv_gentle");
1170 sv_foginterval = cvar("sv_foginterval");
1171 g_cloaked = cvar("g_cloaked");
1173 g_cloaked = 1; // always enable cloak in CTS
1174 g_jump_grunt = cvar("g_jump_grunt");
1175 g_footsteps = cvar("g_footsteps");
1176 g_grappling_hook = cvar("g_grappling_hook");
1177 g_jetpack = cvar("g_jetpack");
1178 g_midair = cvar("g_midair");
1179 g_norecoil = cvar("g_norecoil");
1180 g_bloodloss = cvar("g_bloodloss");
1181 sv_maxidle = cvar("sv_maxidle");
1182 sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
1183 g_ctf_reverse = cvar("g_ctf_reverse");
1184 sv_autotaunt = cvar("sv_autotaunt");
1185 sv_taunt = cvar("sv_taunt");
1187 inWarmupStage = cvar("g_warmup");
1188 g_warmup_limit = cvar("g_warmup_limit");
1189 g_warmup_allguns = cvar("g_warmup_allguns");
1190 g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
1192 if ((g_race && g_race_qualifying == 2) || g_runematch || g_arena || g_assault || cvar("g_campaign"))
1193 inWarmupStage = 0; // these modes cannot work together, sorry
1195 g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
1196 g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
1197 g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
1198 g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
1199 g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
1200 g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
1201 g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
1202 g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
1203 g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
1204 g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
1205 g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
1206 g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
1207 g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
1208 g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
1210 g_weaponspeedfactor = cvar("g_weaponspeedfactor");
1211 g_weaponratefactor = cvar("g_weaponratefactor");
1212 g_weapondamagefactor = cvar("g_weapondamagefactor");
1213 g_weaponforcefactor = cvar("g_weaponforcefactor");
1214 g_weaponspreadfactor = cvar("g_weaponspreadfactor");
1216 g_pickup_shells = cvar("g_pickup_shells");
1217 g_pickup_shells_max = cvar("g_pickup_shells_max");
1218 g_pickup_nails = cvar("g_pickup_nails");
1219 g_pickup_nails_max = cvar("g_pickup_nails_max");
1220 g_pickup_rockets = cvar("g_pickup_rockets");
1221 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
1222 g_pickup_cells = cvar("g_pickup_cells");
1223 g_pickup_cells_max = cvar("g_pickup_cells_max");
1224 g_pickup_fuel = cvar("g_pickup_fuel");
1225 g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
1226 g_pickup_fuel_max = cvar("g_pickup_fuel_max");
1227 g_pickup_armorsmall = cvar("g_pickup_armorsmall");
1228 g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
1229 g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
1230 g_pickup_armormedium = cvar("g_pickup_armormedium");
1231 g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
1232 g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
1233 g_pickup_armorbig = cvar("g_pickup_armorbig");
1234 g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
1235 g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
1236 g_pickup_armorlarge = cvar("g_pickup_armorlarge");
1237 g_pickup_armorlarge_max = cvar("g_pickup_armorlarge_max");
1238 g_pickup_armorlarge_anyway = cvar("g_pickup_armorlarge_anyway");
1239 g_pickup_healthsmall = cvar("g_pickup_healthsmall");
1240 g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
1241 g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
1242 g_pickup_healthmedium = cvar("g_pickup_healthmedium");
1243 g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
1244 g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
1245 g_pickup_healthlarge = cvar("g_pickup_healthlarge");
1246 g_pickup_healthlarge_max = cvar("g_pickup_healthlarge_max");
1247 g_pickup_healthlarge_anyway = cvar("g_pickup_healthlarge_anyway");
1248 g_pickup_healthmega = cvar("g_pickup_healthmega");
1249 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
1250 g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
1252 g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
1253 g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
1255 g_pinata = cvar("g_pinata");
1257 g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
1259 g_weapon_stay = cvar("g_weapon_stay");
1261 if not(inWarmupStage && !g_ca)
1262 game_starttime = cvar("g_start_delay");
1264 sv_pitch_min = cvar("sv_pitch_min");
1265 sv_pitch_max = cvar("sv_pitch_max");
1266 sv_pitch_fixyaw = cvar("sv_pitch_fixyaw");
1268 readplayerstartcvars();
1274 string precache_sound (string s) = #19;
1275 float precache_sound_index (string s) = #19;
1277 #define SND_VOLUME 1
1278 #define SND_ATTENUATION 2
1279 #define SND_LARGEENTITY 8
1280 #define SND_LARGESOUND 16
1282 float sound_allowed(float dest, entity e)
1284 // sounds from world may always pass
1287 if (e.classname == "body")
1289 else if (e.realowner && e.realowner != e)
1291 else if (e.owner && e.owner != e)
1296 // sounds to self may always pass
1297 if (dest == MSG_ONE)
1298 if (e == msg_entity)
1300 // sounds by players can be removed
1301 if (autocvar_bot_sound_monopoly)
1302 if (clienttype(e) == CLIENTTYPE_REAL)
1304 // anything else may pass
1308 #ifdef COMPAT_XON010_CHANNELS
1309 void(entity e, float chan, string samp, float vol, float atten) builtin_sound = #8;
1310 void sound(entity e, float chan, string samp, float vol, float atten)
1312 if (!sound_allowed(MSG_BROADCAST, e))
1314 builtin_sound(e, chan, samp, vol, atten);
1318 void sound(entity e, float chan, string samp, float vol, float atten)
1320 if (!sound_allowed(MSG_BROADCAST, e))
1322 sound7(e, chan, samp, vol, atten, 0, 0);
1326 void soundtoat(float dest, entity e, vector o, float chan, string samp, float vol, float atten)
1330 if (!sound_allowed(dest, e))
1333 entno = num_for_edict(e);
1334 idx = precache_sound_index(samp);
1339 atten = floor(atten * 64);
1340 vol = floor(vol * 255);
1343 sflags |= SND_VOLUME;
1345 sflags |= SND_ATTENUATION;
1346 if (entno >= 8192 || chan < 0 || chan > 7)
1347 sflags |= SND_LARGEENTITY;
1349 sflags |= SND_LARGESOUND;
1351 WriteByte(dest, SVC_SOUND);
1352 WriteByte(dest, sflags);
1353 if (sflags & SND_VOLUME)
1354 WriteByte(dest, vol);
1355 if (sflags & SND_ATTENUATION)
1356 WriteByte(dest, atten);
1357 if (sflags & SND_LARGEENTITY)
1359 WriteShort(dest, entno);
1360 WriteByte(dest, chan);
1364 WriteShort(dest, entno * 8 + chan);
1366 if (sflags & SND_LARGESOUND)
1367 WriteShort(dest, idx);
1369 WriteByte(dest, idx);
1371 WriteCoord(dest, o_x);
1372 WriteCoord(dest, o_y);
1373 WriteCoord(dest, o_z);
1375 void soundto(float dest, entity e, float chan, string samp, float vol, float atten)
1379 if (!sound_allowed(dest, e))
1382 o = e.origin + 0.5 * (e.mins + e.maxs);
1383 soundtoat(dest, e, o, chan, samp, vol, atten);
1385 void soundat(entity e, vector o, float chan, string samp, float vol, float atten)
1387 soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, atten);
1389 void stopsoundto(float dest, entity e, float chan)
1393 if (!sound_allowed(dest, e))
1396 entno = num_for_edict(e);
1398 if (entno >= 8192 || chan < 0 || chan > 7)
1401 idx = precache_sound_index("misc/null.wav");
1402 sflags = SND_LARGEENTITY;
1404 sflags |= SND_LARGESOUND;
1405 WriteByte(dest, SVC_SOUND);
1406 WriteByte(dest, sflags);
1407 WriteShort(dest, entno);
1408 WriteByte(dest, chan);
1409 if (sflags & SND_LARGESOUND)
1410 WriteShort(dest, idx);
1412 WriteByte(dest, idx);
1413 WriteCoord(dest, e.origin_x);
1414 WriteCoord(dest, e.origin_y);
1415 WriteCoord(dest, e.origin_z);
1419 WriteByte(dest, SVC_STOPSOUND);
1420 WriteShort(dest, entno * 8 + chan);
1423 void stopsound(entity e, float chan)
1425 if (!sound_allowed(MSG_BROADCAST, e))
1428 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
1429 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
1432 void play2(entity e, string filename)
1434 //stuffcmd(e, strcat("play2 ", filename, "\n"));
1436 soundtoat(MSG_ONE, world, '0 0 0', CH_INFO, filename, VOL_BASE, ATTN_NONE);
1439 // use this one if you might be causing spam (e.g. from touch functions that might get called more than once per frame)
1441 float spamsound(entity e, float chan, string samp, float vol, float atten)
1443 if (!sound_allowed(MSG_BROADCAST, e))
1446 if (time > e.spamtime)
1449 sound(e, chan, samp, vol, atten);
1455 void play2team(float t, string filename)
1459 if (autocvar_bot_sound_monopoly)
1462 FOR_EACH_REALPLAYER(head)
1465 play2(head, filename);
1469 void play2all(string samp)
1471 if (autocvar_bot_sound_monopoly)
1474 sound(world, CH_INFO, samp, VOL_BASE, ATTN_NONE);
1477 void PrecachePlayerSounds(string f);
1478 void precache_playermodel(string m)
1480 float globhandle, i, n;
1483 if(substring(m, -9,5) == "_lod1")
1485 if(substring(m, -9,5) == "_lod2")
1488 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
1491 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
1495 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
1498 n = search_getsize(globhandle);
1499 for (i = 0; i < n; ++i)
1501 //print(search_getfilename(globhandle, i), "\n");
1502 f = search_getfilename(globhandle, i);
1503 PrecachePlayerSounds(f);
1505 search_end(globhandle);
1507 void precache_all_playermodels(string pattern)
1509 float globhandle, i, n;
1512 globhandle = search_begin(pattern, TRUE, FALSE);
1515 n = search_getsize(globhandle);
1516 for (i = 0; i < n; ++i)
1518 //print(search_getfilename(globhandle, i), "\n");
1519 f = search_getfilename(globhandle, i);
1520 precache_playermodel(f);
1522 search_end(globhandle);
1527 // gamemode related things
1528 precache_model ("models/misc/chatbubble.spr");
1531 precache_model ("models/runematch/curse.mdl");
1532 precache_model ("models/runematch/rune.mdl");
1535 #ifdef TTURRETS_ENABLED
1536 if (autocvar_g_turrets)
1540 // Precache all player models if desired
1541 if (autocvar_sv_precacheplayermodels)
1543 PrecachePlayerSounds("sound/player/default.sounds");
1544 precache_all_playermodels("models/player/*.zym");
1545 precache_all_playermodels("models/player/*.dpm");
1546 precache_all_playermodels("models/player/*.md3");
1547 precache_all_playermodels("models/player/*.psk");
1548 precache_all_playermodels("models/player/*.iqm");
1551 if (autocvar_sv_defaultcharacter)
1554 s = autocvar_sv_defaultplayermodel_red;
1556 precache_playermodel(s);
1557 s = autocvar_sv_defaultplayermodel_blue;
1559 precache_playermodel(s);
1560 s = autocvar_sv_defaultplayermodel_yellow;
1562 precache_playermodel(s);
1563 s = autocvar_sv_defaultplayermodel_pink;
1565 precache_playermodel(s);
1566 s = autocvar_sv_defaultplayermodel;
1568 precache_playermodel(s);
1573 PrecacheGlobalSound((globalsound_step = "misc/footstep0 6"));
1574 PrecacheGlobalSound((globalsound_metalstep = "misc/metalfootstep0 6"));
1577 // gore and miscellaneous sounds
1578 //precache_sound ("misc/h2ohit.wav");
1579 precache_model ("models/hook.md3");
1580 precache_sound ("misc/armorimpact.wav");
1581 precache_sound ("misc/bodyimpact1.wav");
1582 precache_sound ("misc/bodyimpact2.wav");
1583 precache_sound ("misc/gib.wav");
1584 precache_sound ("misc/gib_splat01.wav");
1585 precache_sound ("misc/gib_splat02.wav");
1586 precache_sound ("misc/gib_splat03.wav");
1587 precache_sound ("misc/gib_splat04.wav");
1588 PrecacheGlobalSound((globalsound_fall = "misc/hitground 4"));
1589 PrecacheGlobalSound((globalsound_metalfall = "misc/metalhitground 4"));
1590 precache_sound ("misc/null.wav");
1591 precache_sound ("misc/spawn.wav");
1592 precache_sound ("misc/talk.wav");
1593 precache_sound ("misc/teleport.wav");
1594 precache_sound ("misc/poweroff.wav");
1595 precache_sound ("player/lava.wav");
1596 precache_sound ("player/slime.wav");
1599 precache_sound ("misc/jetpack_fly.wav");
1601 precache_model ("models/sprites/0.spr32");
1602 precache_model ("models/sprites/1.spr32");
1603 precache_model ("models/sprites/2.spr32");
1604 precache_model ("models/sprites/3.spr32");
1605 precache_model ("models/sprites/4.spr32");
1606 precache_model ("models/sprites/5.spr32");
1607 precache_model ("models/sprites/6.spr32");
1608 precache_model ("models/sprites/7.spr32");
1609 precache_model ("models/sprites/8.spr32");
1610 precache_model ("models/sprites/9.spr32");
1611 precache_model ("models/sprites/10.spr32");
1613 // common weapon precaches
1614 precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound here
1615 precache_sound ("weapons/weapon_switch.wav");
1616 precache_sound ("weapons/weaponpickup.wav");
1617 precache_sound ("weapons/unavailable.wav");
1618 precache_sound ("weapons/dryfire.wav");
1619 if (g_grappling_hook)
1621 precache_sound ("weapons/hook_fire.wav"); // hook
1622 precache_sound ("weapons/hook_impact.wav"); // hook
1625 if(autocvar_sv_precacheweapons)
1627 //precache weapon models/sounds
1630 while (wep <= WEP_LAST)
1632 weapon_action(wep, WR_PRECACHE);
1637 precache_model("models/elaser.mdl");
1638 precache_model("models/laser.mdl");
1639 precache_model("models/ebomb.mdl");
1642 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
1644 if (!self.noise && self.music) // quake 3 uses the music field
1645 self.noise = self.music;
1647 // plays music for the level if there is any
1650 precache_sound (self.noise);
1651 ambientsound ('0 0 0', self.noise, VOL_BASE, ATTN_NONE);
1656 // sorry, but using \ in macros breaks line numbers
1657 #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
1658 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
1659 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
1662 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
1664 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
1667 WRITESPECTATABLE_MSG_ONE({
1668 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1669 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
1670 WriteByte(MSG_ONE, id);
1671 WriteString(MSG_ONE, s);
1672 if (id != 0 && s != "")
1674 WriteByte(MSG_ONE, duration);
1675 WriteByte(MSG_ONE, countdown_num);
1680 void Send_CSQC_Centerprint_Generic_Expire(entity e, float id)
1682 Send_CSQC_Centerprint_Generic(e, id, "", 1, 0);
1684 // WARNING: this kills the trace globals
1685 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
1686 #define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init()
1688 #define INITPRIO_FIRST 0
1689 #define INITPRIO_GAMETYPE 0
1690 #define INITPRIO_GAMETYPE_FALLBACK 1
1691 #define INITPRIO_FINDTARGET 10
1692 #define INITPRIO_DROPTOFLOOR 20
1693 #define INITPRIO_SETLOCATION 90
1694 #define INITPRIO_LINKDOORS 91
1695 #define INITPRIO_LAST 99
1697 .void(void) initialize_entity;
1698 .float initialize_entity_order;
1699 .entity initialize_entity_next;
1700 entity initialize_entity_first;
1702 void make_safe_for_remove(entity e)
1704 if (e.initialize_entity)
1706 entity ent, prev = world;
1707 for (ent = initialize_entity_first; ent; )
1709 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
1711 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
1712 // skip it in linked list
1715 prev.initialize_entity_next = ent.initialize_entity_next;
1716 ent = prev.initialize_entity_next;
1720 initialize_entity_first = ent.initialize_entity_next;
1721 ent = initialize_entity_first;
1727 ent = ent.initialize_entity_next;
1733 void objerror(string s)
1735 make_safe_for_remove(self);
1736 builtin_objerror(s);
1739 .float remove_except_protected_forbidden;
1740 void remove_except_protected(entity e)
1742 if(e.remove_except_protected_forbidden)
1743 error("not allowed to remove this at this point");
1747 void remove_unsafely(entity e)
1749 if(e.classname == "spike")
1750 error("Removing spikes is forbidden (crylink bug), please report");
1754 void remove_safely(entity e)
1756 make_safe_for_remove(e);
1760 void InitializeEntity(entity e, void(void) func, float order)
1764 if (!e || e.initialize_entity)
1766 // make a proxy initializer entity
1770 e.classname = "initialize_entity";
1774 e.initialize_entity = func;
1775 e.initialize_entity_order = order;
1777 cur = initialize_entity_first;
1781 if (!cur || cur.initialize_entity_order > order)
1783 // insert between prev and cur
1785 prev.initialize_entity_next = e;
1787 initialize_entity_first = e;
1788 e.initialize_entity_next = cur;
1792 cur = cur.initialize_entity_next;
1795 void InitializeEntitiesRun()
1798 startoflist = initialize_entity_first;
1799 initialize_entity_first = world;
1800 remove = remove_except_protected;
1801 for (self = startoflist; self; self = self.initialize_entity_next)
1803 self.remove_except_protected_forbidden = 1;
1805 for (self = startoflist; self; )
1808 var void(void) func;
1809 e = self.initialize_entity_next;
1810 func = self.initialize_entity;
1811 self.initialize_entity_order = 0;
1812 self.initialize_entity = func_null;
1813 self.initialize_entity_next = world;
1814 self.remove_except_protected_forbidden = 0;
1815 if (self.classname == "initialize_entity")
1819 builtin_remove(self);
1822 //dprint("Delayed initialization: ", self.classname, "\n");
1823 if(func != func_null)
1828 backtrace(strcat("Null function in: ", self.classname, "\n"));
1832 remove = remove_unsafely;
1835 .float uncustomizeentityforclient_set;
1836 .void(void) uncustomizeentityforclient;
1837 void(void) SUB_Nullpointer = #0;
1838 void UncustomizeEntitiesRun()
1842 for (self = world; (self = findfloat(self, uncustomizeentityforclient_set, 1)); )
1843 self.uncustomizeentityforclient();
1846 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
1848 e.customizeentityforclient = customizer;
1849 e.uncustomizeentityforclient = uncustomizer;
1850 e.uncustomizeentityforclient_set = (uncustomizer != SUB_Nullpointer);
1854 #define IFTARGETED if(!self.nottargeted && self.targetname != "")
1857 void Net_LinkEntity(entity e, float docull, float dt, float(entity, float) sendfunc)
1861 if (e.classname == "")
1862 e.classname = "net_linked";
1864 if (e.model == "" || self.modelindex == 0)
1868 setmodel(e, "null");
1872 e.SendEntity = sendfunc;
1873 e.SendFlags = 0xFFFFFF;
1876 e.effects |= EF_NODEPTHTEST;
1880 e.nextthink = time + dt;
1881 e.think = SUB_Remove;
1885 void adaptor_think2touch()
1894 void adaptor_think2use()
1906 void adaptor_think2use_hittype_splash() // for timed projectile detonation
1908 if not(self.flags & FL_ONGROUND) // if onground, we ARE touching something, but HITTYPE_SPLASH is to be networked if the damage causing projectile is not touching ANYTHING
1909 self.projectiledeathtype |= HITTYPE_SPLASH;
1910 adaptor_think2use();
1913 // deferred dropping
1914 void DropToFloor_Handler()
1916 builtin_droptofloor();
1917 self.dropped_origin = self.origin;
1922 InitializeEntity(self, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1927 float trace_hits_box_a0, trace_hits_box_a1;
1929 float trace_hits_box_1d(float end, float thmi, float thma)
1933 // just check if x is in range
1941 // do the trace with respect to x
1942 // 0 -> end has to stay in thmi -> thma
1943 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1944 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1945 if (trace_hits_box_a0 > trace_hits_box_a1)
1951 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1956 // now it is a trace from 0 to end
1958 trace_hits_box_a0 = 0;
1959 trace_hits_box_a1 = 1;
1961 if (!trace_hits_box_1d(end_x, thmi_x, thma_x))
1963 if (!trace_hits_box_1d(end_y, thmi_y, thma_y))
1965 if (!trace_hits_box_1d(end_z, thmi_z, thma_z))
1971 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1973 return trace_hits_box(start, end, thmi - ma, thma - mi);
1976 float SUB_NoImpactCheck()
1978 // zero hitcontents = this is not the real impact, but either the
1979 // mirror-impact of something hitting the projectile instead of the
1980 // projectile hitting the something, or a touchareagrid one. Neither of
1981 // these stop the projectile from moving, so...
1982 if(trace_dphitcontents == 0)
1984 //dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
1985 dprint(sprintf(_("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Profectile will self-destruct. (edict: %d, classname: %s, origin: %s)\n"), num_for_edict(self), self.classname, vtos(self.origin)));
1988 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1990 if (other == world && self.size != '0 0 0')
1993 tic = self.velocity * sys_frametime;
1994 tic = tic + normalize(tic) * vlen(self.maxs - self.mins);
1995 traceline(self.origin - tic, self.origin + tic, MOVE_NORMAL, self);
1996 if (trace_fraction >= 1)
1998 dprint("Odd... did not hit...?\n");
2000 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
2002 dprint("Detected and prevented the sky-grapple bug.\n");
2010 #define SUB_OwnerCheck() (other && (other == self.owner))
2012 void RemoveGrapplingHook(entity pl);
2013 void W_Crylink_Dequeue(entity e);
2014 float WarpZone_Projectile_Touch_ImpactFilter_Callback()
2016 if(SUB_OwnerCheck())
2018 if(SUB_NoImpactCheck())
2020 if(self.classname == "grapplinghook")
2021 RemoveGrapplingHook(self.realowner);
2022 else if(self.classname == "spike")
2024 W_Crylink_Dequeue(self);
2031 if(trace_ent && trace_ent.solid > SOLID_TRIGGER)
2032 UpdateCSQCProjectile(self);
2035 #define PROJECTILE_TOUCH if(WarpZone_Projectile_Touch()) return
2037 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
2038 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER) || ((dt) == DEATH_SLIME) || ((dt) == DEATH_LAVA) || ((dt) == DEATH_SWAMP))
2040 void URI_Get_Callback(float id, float status, string data)
2042 if(url_URI_Get_Callback(id, status, data))
2046 else if (id == URI_GET_DISCARD)
2050 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
2053 Curl_URI_Get_Callback(id, status, data);
2055 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
2058 OnlineBanList_URI_Get_Callback(id, status, data);
2062 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
2066 string uid2name(string myuid) {
2068 s = db_get(ServerProgsDB, strcat("/uid2name/", myuid));
2070 // FIXME remove this later after 0.6 release
2071 // convert old style broken records to correct style
2074 s = db_get(ServerProgsDB, strcat("uid2name", myuid));
2077 db_put(ServerProgsDB, strcat("/uid2name/", myuid), s);
2078 db_put(ServerProgsDB, strcat("uid2name", myuid), "");
2083 s = "^1Unregistered Player";
2087 float race_readTime(string map, float pos)
2095 return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
2098 string race_readUID(string map, float pos)
2106 return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)));
2109 float race_readPos(string map, float t) {
2111 for (i = 1; i <= RANKINGS_CNT; ++i)
2112 if (race_readTime(map, i) == 0 || race_readTime(map, i) > t)
2115 return 0; // pos is zero if unranked
2118 void race_writeTime(string map, float t, string myuid)
2127 newpos = race_readPos(map, t);
2129 float i, prevpos = 0;
2130 for(i = 1; i <= RANKINGS_CNT; ++i)
2132 if(race_readUID(map, i) == myuid)
2135 if (prevpos) { // player improved his existing record, only have to iterate on ranks between new and old recs
2136 for (i = prevpos; i > newpos; --i) {
2137 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2138 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2140 } else { // player has no ranked record yet
2141 for (i = RANKINGS_CNT; i > newpos; --i) {
2142 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
2143 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
2147 // store new time itself
2148 db_put(ServerProgsDB, strcat(map, rr, "time", ftos(newpos)), ftos(t));
2149 db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(newpos)), myuid);
2152 string race_readName(string map, float pos)
2160 return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))));
2163 string race_placeName(float pos) {
2164 if(floor((mod(pos, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
2166 if(mod(pos, 10) == 1)
2167 return strcat(ftos(pos), "st");
2168 else if(mod(pos, 10) == 2)
2169 return strcat(ftos(pos), "nd");
2170 else if(mod(pos, 10) == 3)
2171 return strcat(ftos(pos), "rd");
2173 return strcat(ftos(pos), "th");
2176 return strcat(ftos(pos), "th");
2179 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
2182 vector start, org, delta, end, enddown, mstart;
2185 m = e.dphitcontentsmask;
2186 e.dphitcontentsmask = goodcontents | badcontents;
2189 delta = world.maxs - world.mins;
2193 for (i = 0; i < attempts; ++i)
2195 start_x = org_x + random() * delta_x;
2196 start_y = org_y + random() * delta_y;
2197 start_z = org_z + random() * delta_z;
2199 // rule 1: start inside world bounds, and outside
2200 // solid, and don't start from somewhere where you can
2201 // fall down to evil
2202 tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, e);
2203 if (trace_fraction >= 1)
2205 if (trace_startsolid)
2207 if (trace_dphitcontents & badcontents)
2209 if (trace_dphitq3surfaceflags & badsurfaceflags)
2212 // rule 2: if we are too high, lower the point
2213 if (trace_fraction * delta_z > maxaboveground)
2214 start = trace_endpos + '0 0 1' * maxaboveground;
2215 enddown = trace_endpos;
2217 // rule 3: make sure we aren't outside the map. This only works
2218 // for somewhat well formed maps. A good rule of thumb is that
2219 // the map should have a convex outside hull.
2220 // these can be traceLINES as we already verified the starting box
2221 mstart = start + 0.5 * (e.mins + e.maxs);
2222 traceline(mstart, mstart + '1 0 0' * delta_x, MOVE_NORMAL, e);
2223 if (trace_fraction >= 1)
2225 traceline(mstart, mstart - '1 0 0' * delta_x, MOVE_NORMAL, e);
2226 if (trace_fraction >= 1)
2228 traceline(mstart, mstart + '0 1 0' * delta_y, MOVE_NORMAL, e);
2229 if (trace_fraction >= 1)
2231 traceline(mstart, mstart - '0 1 0' * delta_y, MOVE_NORMAL, e);
2232 if (trace_fraction >= 1)
2234 traceline(mstart, mstart + '0 0 1' * delta_z, MOVE_NORMAL, e);
2235 if (trace_fraction >= 1)
2238 // rule 4: we must "see" some spawnpoint
2239 for(sp = world; (sp = find(sp, classname, "info_player_deathmatch")); )
2240 if(checkpvs(mstart, sp))
2244 for(sp = world; (sp = findflags(sp, flags, FL_ITEM)); )
2245 if(checkpvs(mstart, sp))
2251 // find a random vector to "look at"
2252 end_x = org_x + random() * delta_x;
2253 end_y = org_y + random() * delta_y;
2254 end_z = org_z + random() * delta_z;
2255 end = start + normalize(end - start) * vlen(delta);
2257 // rule 4: start TO end must not be too short
2258 tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
2259 if (trace_startsolid)
2261 if (trace_fraction < minviewdistance / vlen(delta))
2264 // rule 5: don't want to look at sky
2265 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
2268 // rule 6: we must not end up in trigger_hurt
2269 if (tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
2275 e.dphitcontentsmask = m;
2279 setorigin(e, start);
2280 e.angles = vectoangles(end - start);
2281 dprint("Needed ", ftos(i + 1), " attempts\n");
2288 float zcurveparticles_effectno;
2289 vector zcurveparticles_start;
2290 float zcurveparticles_spd;
2292 void endzcurveparticles()
2294 if(zcurveparticles_effectno)
2297 WriteShort(MSG_BROADCAST, zcurveparticles_spd | 0x8000);
2299 zcurveparticles_effectno = 0;
2302 void zcurveparticles(float effectno, vector start, vector end, float end_dz, float spd)
2304 spd = bound(0, floor(spd / 16), 32767);
2305 if(effectno != zcurveparticles_effectno || start != zcurveparticles_start)
2307 endzcurveparticles();
2308 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
2309 WriteByte(MSG_BROADCAST, TE_CSQC_ZCURVEPARTICLES);
2310 WriteShort(MSG_BROADCAST, effectno);
2311 WriteCoord(MSG_BROADCAST, start_x);
2312 WriteCoord(MSG_BROADCAST, start_y);
2313 WriteCoord(MSG_BROADCAST, start_z);
2314 zcurveparticles_effectno = effectno;
2315 zcurveparticles_start = start;
2318 WriteShort(MSG_BROADCAST, zcurveparticles_spd);
2319 WriteCoord(MSG_BROADCAST, end_x);
2320 WriteCoord(MSG_BROADCAST, end_y);
2321 WriteCoord(MSG_BROADCAST, end_z);
2322 WriteCoord(MSG_BROADCAST, end_dz);
2323 zcurveparticles_spd = spd;
2326 void zcurveparticles_from_tracetoss(float effectno, vector start, vector end, vector vel)
2329 vector vecxy, velxy;
2331 vecxy = end - start;
2336 if (vlen(velxy) < 0.000001 * fabs(vel_z))
2338 endzcurveparticles();
2339 trailparticles(world, effectno, start, end);
2343 end_dz = vlen(vecxy) / vlen(velxy) * vel_z - (end_z - start_z);
2344 zcurveparticles(effectno, start, end, end_dz, vlen(vel));
2347 void write_recordmarker(entity pl, float tstart, float dt)
2349 GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
2351 // also write a marker into demo files for demotc-race-record-extractor to find
2354 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
2355 " ", ftos(tstart), " ", ftos(dt), "\n"));
2358 vector shotorg_adjustfromclient(vector vecs, float y_is_right, float allowcenter, float algn)
2371 if(allowcenter) // 2: allow center handedness
2384 if(allowcenter) // 2: allow center handedness
2400 vector shotorg_adjust_values(vector vecs, float y_is_right, float visual, float algn)
2405 if (autocvar_g_shootfromeye)
2418 else if (autocvar_g_shootfromcenter)
2423 else if ((s = autocvar_g_shootfromfixedorigin) != "")
2433 else if (autocvar_g_shootfromclient)
2435 vecs = shotorg_adjustfromclient(vecs, y_is_right, (autocvar_g_shootfromclient >= 2), algn);
2440 vector shotorg_adjust(vector vecs, float y_is_right, float visual)
2442 return shotorg_adjust_values(vecs, y_is_right, visual, self.owner.cvar_cl_gunalign);
2446 void attach_sameorigin(entity e, entity to, string tag)
2448 vector org, t_forward, t_left, t_up, e_forward, e_up;
2451 org = e.origin - gettaginfo(to, gettagindex(to, tag));
2452 tagscale = pow(vlen(v_forward), -2); // undo a scale on the tag
2453 t_forward = v_forward * tagscale;
2454 t_left = v_right * -tagscale;
2455 t_up = v_up * tagscale;
2457 e.origin_x = org * t_forward;
2458 e.origin_y = org * t_left;
2459 e.origin_z = org * t_up;
2461 // current forward and up directions
2462 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2463 e.angles = AnglesTransform_FromVAngles(e.angles);
2465 e.angles = AnglesTransform_FromAngles(e.angles);
2466 fixedmakevectors(e.angles);
2468 // untransform forward, up!
2469 e_forward_x = v_forward * t_forward;
2470 e_forward_y = v_forward * t_left;
2471 e_forward_z = v_forward * t_up;
2472 e_up_x = v_up * t_forward;
2473 e_up_y = v_up * t_left;
2474 e_up_z = v_up * t_up;
2476 e.angles = fixedvectoangles2(e_forward, e_up);
2477 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2478 e.angles = AnglesTransform_ToVAngles(e.angles);
2480 e.angles = AnglesTransform_ToAngles(e.angles);
2482 setattachment(e, to, tag);
2483 setorigin(e, e.origin);
2486 void detach_sameorigin(entity e)
2489 org = gettaginfo(e, 0);
2490 e.angles = fixedvectoangles2(v_forward, v_up);
2491 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
2492 e.angles = AnglesTransform_ToVAngles(e.angles);
2494 e.angles = AnglesTransform_ToAngles(e.angles);
2496 setattachment(e, world, "");
2497 setorigin(e, e.origin);
2500 void follow_sameorigin(entity e, entity to)
2502 e.movetype = MOVETYPE_FOLLOW; // make the hole follow
2503 e.aiment = to; // make the hole follow bmodel
2504 e.punchangle = to.angles; // the original angles of bmodel
2505 e.view_ofs = e.origin - to.origin; // relative origin
2506 e.v_angle = e.angles - to.angles; // relative angles
2509 void unfollow_sameorigin(entity e)
2511 e.movetype = MOVETYPE_NONE;
2514 entity gettaginfo_relative_ent;
2515 vector gettaginfo_relative(entity e, float tag)
2517 if (!gettaginfo_relative_ent)
2519 gettaginfo_relative_ent = spawn();
2520 gettaginfo_relative_ent.effects = EF_NODRAW;
2522 gettaginfo_relative_ent.model = e.model;
2523 gettaginfo_relative_ent.modelindex = e.modelindex;
2524 gettaginfo_relative_ent.frame = e.frame;
2525 return gettaginfo(gettaginfo_relative_ent, tag);
2528 void SoundEntity_StartSound(entity pl, float chan, string samp, float vol, float attn)
2532 if (pl.soundentity.cnt & p)
2534 soundtoat(MSG_ALL, pl.soundentity, gettaginfo(pl.soundentity, 0), chan, samp, vol, attn);
2535 pl.soundentity.cnt |= p;
2538 void SoundEntity_StopSound(entity pl, float chan)
2542 if (pl.soundentity.cnt & p)
2544 stopsoundto(MSG_ALL, pl.soundentity, chan);
2545 pl.soundentity.cnt &~= p;
2549 void SoundEntity_Attach(entity pl)
2551 pl.soundentity = spawn();
2552 pl.soundentity.classname = "soundentity";
2553 pl.soundentity.owner = pl;
2554 setattachment(pl.soundentity, pl, "");
2555 setmodel(pl.soundentity, "null");
2558 void SoundEntity_Detach(entity pl)
2561 for (i = 0; i <= 7; ++i)
2562 SoundEntity_StopSound(pl, i);
2567 float modeleffect_SendEntity(entity to, float sf)
2570 WriteByte(MSG_ENTITY, ENT_CLIENT_MODELEFFECT);
2573 if(self.velocity != '0 0 0')
2575 if(self.angles != '0 0 0')
2577 if(self.avelocity != '0 0 0')
2580 WriteByte(MSG_ENTITY, f);
2581 WriteShort(MSG_ENTITY, self.modelindex);
2582 WriteByte(MSG_ENTITY, self.skin);
2583 WriteByte(MSG_ENTITY, self.frame);
2584 WriteCoord(MSG_ENTITY, self.origin_x);
2585 WriteCoord(MSG_ENTITY, self.origin_y);
2586 WriteCoord(MSG_ENTITY, self.origin_z);
2589 WriteCoord(MSG_ENTITY, self.velocity_x);
2590 WriteCoord(MSG_ENTITY, self.velocity_y);
2591 WriteCoord(MSG_ENTITY, self.velocity_z);
2595 WriteCoord(MSG_ENTITY, self.angles_x);
2596 WriteCoord(MSG_ENTITY, self.angles_y);
2597 WriteCoord(MSG_ENTITY, self.angles_z);
2601 WriteCoord(MSG_ENTITY, self.avelocity_x);
2602 WriteCoord(MSG_ENTITY, self.avelocity_y);
2603 WriteCoord(MSG_ENTITY, self.avelocity_z);
2605 WriteShort(MSG_ENTITY, self.scale * 256.0);
2606 WriteShort(MSG_ENTITY, self.scale2 * 256.0);
2607 WriteByte(MSG_ENTITY, self.teleport_time * 100.0);
2608 WriteByte(MSG_ENTITY, self.fade_time * 100.0);
2609 WriteByte(MSG_ENTITY, self.alpha * 255.0);
2614 void modeleffect_spawn(string m, float s, float f, vector o, vector v, vector ang, vector angv, float s0, float s2, float a, float t1, float t2)
2619 e.classname = "modeleffect";
2627 e.teleport_time = t1;
2631 e.scale = s0 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2635 e.scale2 = s2 / max6(-e.mins_x, -e.mins_y, -e.mins_z, e.maxs_x, e.maxs_y, e.maxs_z);
2638 sz = max(e.scale, e.scale2);
2639 setsize(e, e.mins * sz, e.maxs * sz);
2640 Net_LinkEntity(e, FALSE, 0.1, modeleffect_SendEntity);
2643 void shockwave_spawn(string m, vector org, float sz, float t1, float t2)
2645 return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2);
2648 float randombit(float bits)
2650 if not(bits & (bits-1)) // this ONLY holds for powers of two!
2659 for(f = 1; f <= bits; f *= 2)
2668 r = (r - 1) / (n - 1);
2675 float randombits(float bits, float k, float error_return)
2679 while(k > 0 && bits != r)
2681 r += randombit(bits - r);
2690 void randombit_test(float bits, float iter)
2694 print(ftos(randombit(bits)), "\n");
2699 float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
2701 if(halflifedist > 0)
2702 return pow(0.5, (bound(mindist, d, maxdist) - mindist) / halflifedist);
2703 else if(halflifedist < 0)
2704 return pow(0.5, (bound(mindist, d, maxdist) - maxdist) / halflifedist);
2713 #define cvar_string_normal builtin_cvar_string
2714 #define cvar_normal builtin_cvar
2716 string cvar_string_normal(string n)
2718 if not(cvar_type(n) & 1)
2719 backtrace(strcat("Attempt to access undefined cvar: ", n));
2720 return builtin_cvar_string(n);
2723 float cvar_normal(string n)
2725 return stof(cvar_string_normal(n));
2728 #define cvar_set_normal builtin_cvar_set
2736 oself.think = SUB_Remove;
2737 oself.nextthink = time;
2743 Execute func() after time + fdelay.
2744 self when func is executed = self when defer is called
2746 void defer(float fdelay, void() func)
2753 e.think = defer_think;
2754 e.nextthink = time + fdelay;
2757 .string aiment_classname;
2758 .float aiment_deadflag;
2759 void SetMovetypeFollow(entity ent, entity e)
2761 // FIXME this may not be warpzone aware
2762 ent.movetype = MOVETYPE_FOLLOW; // make the hole follow
2763 ent.solid = SOLID_NOT; // MOVETYPE_FOLLOW is always non-solid - this means this cannot be teleported by warpzones any more! Instead, we must notice when our owner gets teleported.
2764 ent.aiment = e; // make the hole follow bmodel
2765 ent.punchangle = e.angles; // the original angles of bmodel
2766 ent.view_ofs = ent.origin - e.origin; // relative origin
2767 ent.v_angle = ent.angles - e.angles; // relative angles
2768 ent.aiment_classname = strzone(e.classname);
2769 ent.aiment_deadflag = e.deadflag;
2771 void UnsetMovetypeFollow(entity ent)
2773 ent.movetype = MOVETYPE_FLY;
2774 PROJECTILE_MAKETRIGGER(ent);
2777 float LostMovetypeFollow(entity ent)
2780 if(ent.movetype != MOVETYPE_FOLLOW)
2786 if(ent.aiment.classname != ent.aiment_classname)
2788 if(ent.aiment.deadflag != ent.aiment_deadflag)
2794 float isPushable(entity e)
2801 case "droppedweapon":
2802 case "keepawayball":
2803 case "nexball_basketball":
2804 case "nexball_football":
2806 case "bullet": // antilagged bullets can't hit this either
2809 if (e.projectiledeathtype)