1 #include "miscfunctions.qh"
3 #include "command/common.qh"
4 #include "constants.qh"
7 #include "mutators/_mod.qh"
8 #include "../common/t_items.qh"
9 #include "weapons/accuracy.qh"
10 #include "weapons/csqcprojectile.qh"
11 #include "weapons/selection.qh"
12 #include "../common/command/_mod.qh"
13 #include "../common/constants.qh"
14 #include <common/net_linked.qh>
15 #include "../common/deathtypes/all.qh"
16 #include "../common/mapinfo.qh"
17 #include "../common/notifications/all.qh"
18 #include "../common/playerstats.qh"
19 #include "../common/teams.qh"
20 #include "../common/triggers/subs.qh"
21 #include "../common/util.qh"
22 #include "../common/turrets/sv_turrets.qh"
23 #include <common/weapons/_all.qh>
24 #include "../common/vehicles/sv_vehicles.qh"
25 #include "../common/vehicles/vehicle.qh"
26 #include "../common/items/_mod.qh"
27 #include "../common/state.qh"
28 #include "../common/effects/qc/globalsound.qh"
29 #include "../common/wepent.qh"
30 #include "../lib/csqcmodel/sv_model.qh"
31 #include "../lib/warpzone/anglestransform.qh"
32 #include "../lib/warpzone/server.qh"
34 void crosshair_trace(entity pl)
36 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));
38 .bool ctrace_solidchanged;
39 void crosshair_trace_plusvisibletriggers(entity pl)
41 FOREACH_ENTITY_FLOAT(solid, SOLID_TRIGGER,
46 it.ctrace_solidchanged = true;
52 FOREACH_ENTITY_FLOAT(ctrace_solidchanged, true,
54 it.solid = SOLID_TRIGGER;
55 it.ctrace_solidchanged = false;
58 void WarpZone_crosshair_trace(entity pl)
60 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));
66 if(autocvar_sv_adminnick != "")
67 return autocvar_sv_adminnick;
69 return "SERVER ADMIN";
73 void GameLogEcho(string s)
78 if (autocvar_sv_eventlog_files)
83 matches = autocvar_sv_eventlog_files_counter + 1;
84 cvar_set("sv_eventlog_files_counter", itos(matches));
87 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
88 fn = strcat(autocvar_sv_eventlog_files_nameprefix, fn, autocvar_sv_eventlog_files_namesuffix);
89 logfile = fopen(fn, FILE_APPEND);
90 fputs(logfile, ":logversion:3\n");
94 if (autocvar_sv_eventlog_files_timestamps)
95 fputs(logfile, strcat(":time:", strftime(true, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
97 fputs(logfile, strcat(s, "\n"));
100 if (autocvar_sv_eventlog_console)
102 dedicated_print(strcat(s, "\n"));
109 // will be opened later
114 if (logfile_open && logfile >= 0)
121 entity findnearest(vector point, .string field, string value, vector axismod)
132 localhead = find(NULL, field, value);
135 if ((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
136 dist = localhead.oldorigin;
138 dist = localhead.origin;
140 dist = dist.x * axismod.x * '1 0 0' + dist.y * axismod.y * '0 1 0' + dist.z * axismod.z * '0 0 1';
143 for (i = 0; i < num_nearest; ++i)
145 if (len < nearest_length[i])
149 // now i tells us where to insert at
150 // INSERTION SORT! YOU'VE SEEN IT! RUN!
151 if (i < NUM_NEAREST_ENTITIES)
153 for (j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
155 nearest_length[j + 1] = nearest_length[j];
156 nearest_entity[j + 1] = nearest_entity[j];
158 nearest_length[i] = len;
159 nearest_entity[i] = localhead;
160 if (num_nearest < NUM_NEAREST_ENTITIES)
161 num_nearest = num_nearest + 1;
164 localhead = find(localhead, field, value);
167 // now use the first one from our list that we can see
168 for (i = 0; i < num_nearest; ++i)
170 traceline(point, nearest_entity[i].origin, true, NULL);
171 if (trace_fraction == 1)
175 LOG_TRACE("Nearest point (");
176 LOG_TRACE(nearest_entity[0].netname);
177 LOG_TRACE(") is not visible, using a visible one.");
179 return nearest_entity[i];
183 if (num_nearest == 0)
186 LOG_TRACE("Not seeing any location point, using nearest as fallback.");
188 dprint("Candidates were: ");
189 for(j = 0; j < num_nearest; ++j)
193 dprint(nearest_entity[j].netname);
198 return nearest_entity[0];
201 string NearestLocation(vector p)
206 loc = findnearest(p, classname, "target_location", '1 1 1');
213 loc = findnearest(p, target, "###item###", '1 1 4');
220 string AmmoNameFromWeaponentity(entity wpn)
222 string ammoitems = "batteries";
223 switch((wpn.m_weapon).ammo_field)
225 case ammo_shells: ammoitems = ITEM_Shells.m_name; break;
226 case ammo_nails: ammoitems = ITEM_Bullets.m_name; break;
227 case ammo_rockets: ammoitems = ITEM_Rockets.m_name; break;
228 case ammo_cells: ammoitems = ITEM_Cells.m_name; break;
229 case ammo_plasma: ammoitems = ITEM_Plasma.m_name; break;
230 case ammo_fuel: ammoitems = ITEM_JetpackFuel.m_name; break;
235 string formatmessage(entity this, string msg)
246 WarpZone_crosshair_trace(this);
247 cursor = trace_endpos;
248 cursor_ent = trace_ent;
250 MUTATOR_CALLHOOK(PreFormatMessage, this, msg);
251 msg = M_ARGV(1, string);
255 break; // too many replacements
258 p1 = strstrofs(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
259 p2 = strstrofs(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
272 replacement = substring(msg, p, 2);
273 escape = substring(msg, p + 1, 1);
275 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
279 case "%": replacement = "%"; break;
280 case "\\":replacement = "\\"; break;
281 case "n": replacement = "\n"; break;
282 case "a": replacement = ftos(floor(this.armorvalue)); break;
283 case "h": replacement = ftos(floor(this.health)); break;
284 case "l": replacement = NearestLocation(this.origin); break;
285 case "y": replacement = NearestLocation(cursor); break;
286 case "d": replacement = NearestLocation(this.death_origin); break;
287 case "w": replacement = ((this.(weaponentity).m_weapon == WEP_Null) ? ((this.(weaponentity).m_switchweapon == WEP_Null) ? Weapons_from(this.(weaponentity).cnt) : this.(weaponentity).m_switchweapon) : this.(weaponentity).m_weapon).m_name; break;
288 case "W": replacement = AmmoNameFromWeaponentity(this.(weaponentity)); break;
289 case "x": replacement = ((cursor_ent.netname == "" || !cursor_ent) ? "nothing" : cursor_ent.netname); break;
290 case "s": replacement = ftos(vlen(this.velocity - this.velocity_z * '0 0 1')); break;
291 case "S": replacement = ftos(vlen(this.velocity)); break;
292 case "t": replacement = seconds_tostring(ceil(max(0, autocvar_timelimit * 60 + game_starttime - time))); break;
293 case "T": replacement = seconds_tostring(floor(time - game_starttime)); break;
296 MUTATOR_CALLHOOK(FormatMessage, this, escape, replacement, msg);
297 replacement = M_ARGV(2, string);
302 msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
303 p = p + strlen(replacement);
314 >0: receives a cvar from name=argv(f) value=argv(f+1)
316 void GetCvars_handleString(entity this, string thisname, float f, .string field, string name)
321 strunzone(this.(field));
322 this.(field) = string_null;
326 if (thisname == name)
329 strunzone(this.(field));
330 this.(field) = strzone(argv(f + 1));
334 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
336 void GetCvars_handleString_Fixup(entity this, string thisname, float f, .string field, string name, string(entity, string) func)
338 GetCvars_handleString(this, thisname, f, field, name);
339 if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
340 if (thisname == name)
342 string s = func(this, strcat1(this.(field)));
343 if (s != this.(field))
345 strunzone(this.(field));
346 this.(field) = strzone(s);
350 void GetCvars_handleFloat(entity this, string thisname, float f, .float field, string name)
357 if (thisname == name)
358 this.(field) = stof(argv(f + 1));
361 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
363 void GetCvars_handleFloatOnce(entity this, string thisname, float f, .float field, string name)
370 if (thisname == name)
374 this.(field) = stof(argv(f + 1));
383 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
386 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo)
389 o = W_FixWeaponOrder_ForceComplete(wo);
390 if(this.weaponorder_byimpulse)
392 strunzone(this.weaponorder_byimpulse);
393 this.weaponorder_byimpulse = string_null;
395 this.weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(o));
399 REPLICATE(autoswitch, bool, "cl_autoswitch");
401 REPLICATE(cvar_cl_allow_uid2name, bool, "cl_allow_uid2name");
403 REPLICATE(cvar_cl_autoscreenshot, int, "cl_autoscreenshot");
405 REPLICATE(cvar_cl_autotaunt, float, "cl_autotaunt");
407 REPLICATE(cvar_cl_clippedspectating, bool, "cl_clippedspectating");
409 REPLICATE(cvar_cl_handicap, float, "cl_handicap");
411 REPLICATE(cvar_cl_jetpack_jump, bool, "cl_jetpack_jump");
413 REPLICATE(cvar_cl_movement_track_canjump, bool, "cl_movement_track_canjump");
415 REPLICATE(cvar_cl_newusekeysupported, bool, "cl_newusekeysupported");
417 REPLICATE(cvar_cl_noantilag, bool, "cl_noantilag");
419 REPLICATE(cvar_cl_physics, string, "cl_physics");
421 REPLICATE(cvar_cl_voice_directional, int, "cl_voice_directional");
423 REPLICATE(cvar_cl_voice_directional_taunt_attenuation, float, "cl_voice_directional_taunt_attenuation");
425 REPLICATE(cvar_cl_weaponimpulsemode, int, "cl_weaponimpulsemode");
427 REPLICATE(cvar_g_xonoticversion, string, "g_xonoticversion");
430 * @param f -1: cleanup, 0: request, 1: receive
432 void GetCvars(entity this, int f)
434 string s = string_null;
437 s = strcat1(argv(f));
441 MUTATOR_CALLHOOK(GetCvars);
443 Notification_GetCvars(this);
445 ReplicateVars(this, s, f);
447 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
448 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
449 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
450 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
451 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
452 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
453 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
454 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
455 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
456 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
457 GetCvars_handleString_Fixup(this, s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
459 GetCvars_handleFloat(this, s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
461 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
464 if (s == "cl_weaponpriority")
466 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
468 .entity weaponentity = weaponentities[slot];
469 if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
470 this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
473 if (s == "cl_allow_uidtracking")
474 PlayerStats_GameReport_AddPlayer(this);
478 // decolorizes and team colors the player name when needed
479 string playername(entity p)
482 if (teamplay && !gameover && IS_PLAYER(p))
484 t = Team_ColorCode(p.team);
485 return strcat(t, strdecolorize(p.netname));
491 float want_weapon(entity weaponinfo, float allguns) // WEAPONTODO: what still needs done?
493 int i = weaponinfo.m_id;
495 bool allow_mutatorblocked = false;
500 bool mutator_returnvalue = MUTATOR_CALLHOOK(WantWeapon, weaponinfo, d, allguns, allow_mutatorblocked);
501 d = M_ARGV(1, float);
502 allguns = M_ARGV(2, bool);
503 allow_mutatorblocked = M_ARGV(3, bool);
507 if(weaponinfo.spawnflags & WEP_FLAG_NORMAL)
512 else if(!mutator_returnvalue)
513 d = !(!weaponinfo.weaponstart);
515 if(!allow_mutatorblocked && (weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED)) // never default mutator blocked guns
518 float t = weaponinfo.weaponstartoverride;
520 //print(strcat("want_weapon: ", weaponinfo.netname, " - d: ", ftos(d), ", t: ", ftos(t), ". \n"));
525 // 4: is set by default?
534 void readplayerstartcvars()
539 // initialize starting values for players
540 start_weapons = '0 0 0';
541 start_weapons_default = '0 0 0';
542 start_weapons_defaultmask = '0 0 0';
544 start_ammo_shells = 0;
545 start_ammo_nails = 0;
546 start_ammo_rockets = 0;
547 start_ammo_cells = 0;
548 start_ammo_plasma = 0;
549 start_health = cvar("g_balance_health_start");
550 start_armorvalue = cvar("g_balance_armor_start");
553 g_weaponarena_weapons = '0 0 0';
555 s = cvar_string("g_weaponarena");
557 MUTATOR_CALLHOOK(SetWeaponArena, s);
558 s = M_ARGV(0, string);
560 if (s == "0" || s == "")
566 // forcibly turn off weaponarena
568 else if (s == "all" || s == "1")
571 g_weaponarena_list = "All Weapons";
572 FOREACH(Weapons, it != WEP_Null, LAMBDA(
573 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED))
574 g_weaponarena_weapons |= (it.m_wepset);
577 else if (s == "devall")
580 g_weaponarena_list = "All Weapons"; // TODO: report as more than just all weapons?
581 FOREACH(Weapons, it != WEP_Null,
583 g_weaponarena_weapons |= (it.m_wepset);
586 else if (s == "most")
589 g_weaponarena_list = "Most Weapons";
590 FOREACH(Weapons, it != WEP_Null, LAMBDA(
591 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED))
592 if(it.spawnflags & WEP_FLAG_NORMAL)
593 g_weaponarena_weapons |= (it.m_wepset);
596 else if (s == "none")
599 g_weaponarena_list = "No Weapons";
604 t = tokenize_console(s);
605 g_weaponarena_list = "";
606 for (i = 0; i < t; ++i)
609 FOREACH(Weapons, it != WEP_Null, LAMBDA(
612 g_weaponarena_weapons |= (it.m_wepset);
613 g_weaponarena_list = strcat(g_weaponarena_list, it.m_name, " & ");
618 g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
622 g_weaponarena_random = cvar("g_weaponarena_random");
624 g_weaponarena_random = 0;
625 g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
629 g_weapon_stay = 0; // incompatible
630 start_weapons = g_weaponarena_weapons;
631 start_items |= IT_UNLIMITED_AMMO;
635 FOREACH(Weapons, it != WEP_Null, LAMBDA(
636 int w = want_weapon(it, false);
637 WepSet s = it.m_wepset;
641 start_weapons_default |= s;
643 start_weapons_defaultmask |= s;
647 if(!cvar("g_use_ammunition"))
648 start_items |= IT_UNLIMITED_AMMO;
650 if(start_items & IT_UNLIMITED_WEAPON_AMMO)
652 start_ammo_shells = 999;
653 start_ammo_nails = 999;
654 start_ammo_rockets = 999;
655 start_ammo_cells = 999;
656 start_ammo_plasma = 999;
657 start_ammo_fuel = 999;
661 start_ammo_shells = cvar("g_start_ammo_shells");
662 start_ammo_nails = cvar("g_start_ammo_nails");
663 start_ammo_rockets = cvar("g_start_ammo_rockets");
664 start_ammo_cells = cvar("g_start_ammo_cells");
665 start_ammo_plasma = cvar("g_start_ammo_plasma");
666 start_ammo_fuel = cvar("g_start_ammo_fuel");
671 warmup_start_ammo_shells = start_ammo_shells;
672 warmup_start_ammo_nails = start_ammo_nails;
673 warmup_start_ammo_rockets = start_ammo_rockets;
674 warmup_start_ammo_cells = start_ammo_cells;
675 warmup_start_ammo_plasma = start_ammo_plasma;
676 warmup_start_ammo_fuel = start_ammo_fuel;
677 warmup_start_health = start_health;
678 warmup_start_armorvalue = start_armorvalue;
679 warmup_start_weapons = start_weapons;
680 warmup_start_weapons_default = start_weapons_default;
681 warmup_start_weapons_defaultmask = start_weapons_defaultmask;
683 if (!g_weaponarena && !g_ca && !g_freezetag)
685 warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
686 warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
687 warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
688 warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
689 warmup_start_ammo_plasma = cvar("g_warmup_start_ammo_plasma");
690 warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
691 warmup_start_health = cvar("g_warmup_start_health");
692 warmup_start_armorvalue = cvar("g_warmup_start_armor");
693 warmup_start_weapons = '0 0 0';
694 warmup_start_weapons_default = '0 0 0';
695 warmup_start_weapons_defaultmask = '0 0 0';
696 FOREACH(Weapons, it != WEP_Null, LAMBDA(
697 int w = want_weapon(it, g_warmup_allguns);
698 WepSet s = (it.m_wepset);
700 warmup_start_weapons |= s;
702 warmup_start_weapons_default |= s;
704 warmup_start_weapons_defaultmask |= s;
710 start_items |= ITEM_Jetpack.m_itemid;
712 MUTATOR_CALLHOOK(SetStartItems);
714 if (start_items & ITEM_Jetpack.m_itemid)
716 start_items |= ITEM_JetpackRegen.m_itemid;
717 start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
718 warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
721 WepSet precache_weapons = start_weapons;
722 if (g_warmup_allguns != 1)
723 precache_weapons |= warmup_start_weapons;
724 FOREACH(Weapons, it != WEP_Null, LAMBDA(
725 if(precache_weapons & (it.m_wepset))
729 start_ammo_shells = max(0, start_ammo_shells);
730 start_ammo_nails = max(0, start_ammo_nails);
731 start_ammo_rockets = max(0, start_ammo_rockets);
732 start_ammo_cells = max(0, start_ammo_cells);
733 start_ammo_plasma = max(0, start_ammo_plasma);
734 start_ammo_fuel = max(0, start_ammo_fuel);
736 warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
737 warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
738 warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
739 warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
740 warmup_start_ammo_plasma = max(0, warmup_start_ammo_plasma);
741 warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
744 void precache_playermodel(string m)
746 float globhandle, i, n;
749 if(substring(m, -9,5) == "_lod1")
751 if(substring(m, -9,5) == "_lod2")
754 f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
757 f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
761 globhandle = search_begin(strcat(m, "_*.sounds"), true, false);
764 n = search_getsize(globhandle);
765 for (i = 0; i < n; ++i)
767 //print(search_getfilename(globhandle, i), "\n");
768 f = search_getfilename(globhandle, i);
769 PrecachePlayerSounds(f);
771 search_end(globhandle);
773 void precache_all_playermodels(string pattern)
775 int globhandle = search_begin(pattern, true, false);
776 if (globhandle < 0) return;
777 int n = search_getsize(globhandle);
778 for (int i = 0; i < n; ++i)
780 string s = search_getfilename(globhandle, i);
781 precache_playermodel(s);
783 search_end(globhandle);
786 void precache_playermodels(string s)
788 FOREACH_WORD(s, true, LAMBDA(precache_playermodel(it)));
793 // gamemode related things
795 // Precache all player models if desired
796 if (autocvar_sv_precacheplayermodels)
798 PrecachePlayerSounds("sound/player/default.sounds");
799 precache_all_playermodels("models/player/*.zym");
800 precache_all_playermodels("models/player/*.dpm");
801 precache_all_playermodels("models/player/*.md3");
802 precache_all_playermodels("models/player/*.psk");
803 precache_all_playermodels("models/player/*.iqm");
806 if (autocvar_sv_defaultcharacter)
808 precache_playermodels(autocvar_sv_defaultplayermodel_red);
809 precache_playermodels(autocvar_sv_defaultplayermodel_blue);
810 precache_playermodels(autocvar_sv_defaultplayermodel_yellow);
811 precache_playermodels(autocvar_sv_defaultplayermodel_pink);
812 precache_playermodels(autocvar_sv_defaultplayermodel);
816 // Disabled this code because it simply does not work (e.g. ignores bgmvolume, overlaps with "cd loop" controlled tracks).
818 if (!this.noise && this.music) // quake 3 uses the music field
819 this.noise = this.music;
821 // plays music for the level if there is any
824 precache_sound (this.noise);
825 ambientsound ('0 0 0', this.noise, VOL_BASE, ATTEN_NONE);
831 void make_safe_for_remove(entity e)
833 if (e.initialize_entity)
835 entity ent, prev = NULL;
836 for (ent = initialize_entity_first; ent; )
838 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
840 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
841 // skip it in linked list
844 prev.initialize_entity_next = ent.initialize_entity_next;
845 ent = prev.initialize_entity_next;
849 initialize_entity_first = ent.initialize_entity_next;
850 ent = initialize_entity_first;
856 ent = ent.initialize_entity_next;
862 .float remove_except_protected_forbidden;
863 void remove_except_protected(entity e)
865 if(e.remove_except_protected_forbidden)
866 error("not allowed to remove this at this point");
870 void remove_unsafely(entity e)
872 if(e.classname == "spike")
873 error("Removing spikes is forbidden (crylink bug), please report");
877 void remove_safely(entity e)
879 make_safe_for_remove(e);
883 void InitializeEntity(entity e, void(entity this) func, float order)
887 if (!e || e.initialize_entity)
889 // make a proxy initializer entity
891 e = new(initialize_entity);
895 e.initialize_entity = func;
896 e.initialize_entity_order = order;
898 cur = initialize_entity_first;
902 if (!cur || cur.initialize_entity_order > order)
904 // insert between prev and cur
906 prev.initialize_entity_next = e;
908 initialize_entity_first = e;
909 e.initialize_entity_next = cur;
913 cur = cur.initialize_entity_next;
916 void InitializeEntitiesRun()
918 entity startoflist = initialize_entity_first;
919 initialize_entity_first = NULL;
920 delete_fn = remove_except_protected;
921 for (entity e = startoflist; e; e = e.initialize_entity_next)
923 e.remove_except_protected_forbidden = 1;
925 for (entity e = startoflist; e; )
927 e.remove_except_protected_forbidden = 0;
928 e.initialize_entity_order = 0;
929 entity next = e.initialize_entity_next;
930 e.initialize_entity_next = NULL;
931 var void(entity this) func = e.initialize_entity;
932 e.initialize_entity = func_null;
933 if (e.classname == "initialize_entity")
935 entity wrappee = e.enemy;
939 //dprint("Delayed initialization: ", e.classname, "\n");
947 backtrace(strcat("Null function in: ", e.classname, "\n"));
951 delete_fn = remove_unsafely;
954 .float(entity) isEliminated;
955 bool EliminatedPlayers_SendEntity(entity this, entity to, float sendflags)
959 WriteHeader(MSG_ENTITY, ENT_CLIENT_ELIMINATEDPLAYERS);
960 WriteByte(MSG_ENTITY, sendflags);
964 for(i = 1; i <= maxclients; i += 8)
966 for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
968 if(eliminatedPlayers.isEliminated(e))
971 WriteByte(MSG_ENTITY, f);
978 void EliminatedPlayers_Init(float(entity) isEliminated_func)
980 if(eliminatedPlayers)
982 backtrace("Can't spawn eliminatedPlayers again!");
985 Net_LinkEntity(eliminatedPlayers = spawn(), false, 0, EliminatedPlayers_SendEntity);
986 eliminatedPlayers.isEliminated = isEliminated_func;
992 void adaptor_think2use_hittype_splash(entity this) // for timed projectile detonation
994 if(!(IS_ONGROUND(this))) // if onground, we ARE touching something, but HITTYPE_SPLASH is to be networked if the damage causing projectile is not touching ANYTHING
995 this.projectiledeathtype |= HITTYPE_SPLASH;
996 adaptor_think2use(this);
1000 void DropToFloor_Handler(entity this)
1002 WITHSELF(this, builtin_droptofloor());
1003 this.dropped_origin = this.origin;
1006 void droptofloor(entity this)
1008 InitializeEntity(this, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
1013 float trace_hits_box_a0, trace_hits_box_a1;
1015 float trace_hits_box_1d(float end, float thmi, float thma)
1019 // just check if x is in range
1027 // do the trace with respect to x
1028 // 0 -> end has to stay in thmi -> thma
1029 trace_hits_box_a0 = max(trace_hits_box_a0, min(thmi / end, thma / end));
1030 trace_hits_box_a1 = min(trace_hits_box_a1, max(thmi / end, thma / end));
1031 if (trace_hits_box_a0 > trace_hits_box_a1)
1037 float trace_hits_box(vector start, vector end, vector thmi, vector thma)
1042 // now it is a trace from 0 to end
1044 trace_hits_box_a0 = 0;
1045 trace_hits_box_a1 = 1;
1047 if (!trace_hits_box_1d(end.x, thmi.x, thma.x))
1049 if (!trace_hits_box_1d(end.y, thmi.y, thma.y))
1051 if (!trace_hits_box_1d(end.z, thmi.z, thma.z))
1057 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma)
1059 return trace_hits_box(start, end, thmi - ma, thma - mi);
1062 bool SUB_NoImpactCheck(entity this, entity toucher)
1064 // zero hitcontents = this is not the real impact, but either the
1065 // mirror-impact of something hitting the projectile instead of the
1066 // projectile hitting the something, or a touchareagrid one. Neither of
1067 // these stop the projectile from moving, so...
1068 if(trace_dphitcontents == 0)
1070 LOG_TRACEF("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct. (edict: %i, classname: %s, origin: %v)", this, this.classname, this.origin);
1073 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1075 if (toucher == NULL && this.size != '0 0 0')
1078 tic = this.velocity * sys_frametime;
1079 tic = tic + normalize(tic) * vlen(this.maxs - this.mins);
1080 traceline(this.origin - tic, this.origin + tic, MOVE_NORMAL, this);
1081 if (trace_fraction >= 1)
1083 LOG_TRACE("Odd... did not hit...?");
1085 else if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
1087 LOG_TRACE("Detected and prevented the sky-grapple bug.");
1095 #define SUB_OwnerCheck(ent,oth) ((oth) && ((oth) == (ent).owner))
1097 void W_Crylink_Dequeue(entity e);
1098 bool WarpZone_Projectile_Touch_ImpactFilter_Callback(entity this, entity toucher)
1100 if(SUB_OwnerCheck(this, toucher))
1102 if(SUB_NoImpactCheck(this, toucher))
1104 if(this.classname == "nade")
1105 return false; // no checks here
1106 else if(this.classname == "grapplinghook")
1108 else if(this.classname == "spike")
1110 W_Crylink_Dequeue(this);
1117 if(trace_ent && trace_ent.solid > SOLID_TRIGGER)
1118 UpdateCSQCProjectile(this);
1122 /** engine callback */
1123 void URI_Get_Callback(float id, float status, string data)
1125 if(url_URI_Get_Callback(id, status, data))
1129 else if (id == URI_GET_DISCARD)
1133 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
1136 Curl_URI_Get_Callback(id, status, data);
1138 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
1141 OnlineBanList_URI_Get_Callback(id, status, data);
1143 else if (MUTATOR_CALLHOOK(URI_GetCallback, id, status, data))
1145 // handled by a mutator
1149 LOG_INFO("Received HTTP request data for an invalid id ", ftos(id), ".\n");
1153 string uid2name(string myuid) {
1155 s = db_get(ServerProgsDB, strcat("/uid2name/", myuid));
1157 // FIXME remove this later after 0.6 release
1158 // convert old style broken records to correct style
1161 s = db_get(ServerProgsDB, strcat("uid2name", myuid));
1164 db_put(ServerProgsDB, strcat("/uid2name/", myuid), s);
1165 db_remove(ServerProgsDB, strcat("uid2name", myuid));
1170 s = "^1Unregistered Player";
1174 float MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundmax, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
1177 vector start, org, delta, end, enddown, mstart;
1179 m = e.dphitcontentsmask;
1180 e.dphitcontentsmask = goodcontents | badcontents;
1183 delta = boundmax - boundmin;
1187 for (i = 0; i < attempts; ++i)
1189 start.x = org.x + random() * delta.x;
1190 start.y = org.y + random() * delta.y;
1191 start.z = org.z + random() * delta.z;
1193 // rule 1: start inside world bounds, and outside
1194 // solid, and don't start from somewhere where you can
1195 // fall down to evil
1196 tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta.z, MOVE_NORMAL, e);
1197 if (trace_fraction >= 1)
1199 if (trace_startsolid)
1201 if (trace_dphitcontents & badcontents)
1203 if (trace_dphitq3surfaceflags & badsurfaceflags)
1206 // rule 2: if we are too high, lower the point
1207 if (trace_fraction * delta.z > maxaboveground)
1208 start = trace_endpos + '0 0 1' * maxaboveground;
1209 enddown = trace_endpos;
1211 // rule 3: make sure we aren't outside the map. This only works
1212 // for somewhat well formed maps. A good rule of thumb is that
1213 // the map should have a convex outside hull.
1214 // these can be traceLINES as we already verified the starting box
1215 mstart = start + 0.5 * (e.mins + e.maxs);
1216 traceline(mstart, mstart + '1 0 0' * delta.x, MOVE_NORMAL, e);
1217 if (trace_fraction >= 1 || trace_dphittexturename == "common/caulk")
1219 traceline(mstart, mstart - '1 0 0' * delta.x, MOVE_NORMAL, e);
1220 if (trace_fraction >= 1 || trace_dphittexturename == "common/caulk")
1222 traceline(mstart, mstart + '0 1 0' * delta.y, MOVE_NORMAL, e);
1223 if (trace_fraction >= 1 || trace_dphittexturename == "common/caulk")
1225 traceline(mstart, mstart - '0 1 0' * delta.y, MOVE_NORMAL, e);
1226 if (trace_fraction >= 1 || trace_dphittexturename == "common/caulk")
1228 traceline(mstart, mstart + '0 0 1' * delta.z, MOVE_NORMAL, e);
1229 if (trace_fraction >= 1 || trace_dphittexturename == "common/caulk")
1232 // rule 4: we must "see" some spawnpoint or item
1234 IL_EACH(g_spawnpoints, checkpvs(mstart, it),
1236 if((traceline(mstart, it.origin, MOVE_NORMAL, e), trace_fraction) >= 1)
1244 IL_EACH(g_items, checkpvs(mstart, it),
1246 if((traceline(mstart, it.origin + (it.mins + it.maxs) * 0.5, MOVE_NORMAL, e), trace_fraction) >= 1)
1257 // find a random vector to "look at"
1258 end.x = org.x + random() * delta.x;
1259 end.y = org.y + random() * delta.y;
1260 end.z = org.z + random() * delta.z;
1261 end = start + normalize(end - start) * vlen(delta);
1263 // rule 4: start TO end must not be too short
1264 tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
1265 if (trace_startsolid)
1267 if (trace_fraction < minviewdistance / vlen(delta))
1270 // rule 5: don't want to look at sky
1271 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
1274 // rule 6: we must not end up in trigger_hurt
1275 if (tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
1281 e.dphitcontentsmask = m;
1285 setorigin(e, start);
1286 e.angles = vectoangles(end - start);
1287 LOG_TRACE("Needed ", ftos(i + 1), " attempts");
1294 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
1296 return MoveToRandomLocationWithinBounds(e, world.mins, world.maxs, goodcontents, badcontents, badsurfaceflags, attempts, maxaboveground, minviewdistance);
1299 void write_recordmarker(entity pl, float tstart, float dt)
1301 GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
1303 // also write a marker into demo files for demotc-race-record-extractor to find
1306 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
1307 " ", ftos(tstart), " ", ftos(dt), "\n"));
1310 void attach_sameorigin(entity e, entity to, string tag)
1312 vector org, t_forward, t_left, t_up, e_forward, e_up;
1315 org = e.origin - gettaginfo(to, gettagindex(to, tag));
1316 tagscale = pow(vlen(v_forward), -2); // undo a scale on the tag
1317 t_forward = v_forward * tagscale;
1318 t_left = v_right * -tagscale;
1319 t_up = v_up * tagscale;
1321 e.origin_x = org * t_forward;
1322 e.origin_y = org * t_left;
1323 e.origin_z = org * t_up;
1325 // current forward and up directions
1326 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
1327 e.angles = AnglesTransform_FromVAngles(e.angles);
1329 e.angles = AnglesTransform_FromAngles(e.angles);
1330 fixedmakevectors(e.angles);
1332 // untransform forward, up!
1333 e_forward.x = v_forward * t_forward;
1334 e_forward.y = v_forward * t_left;
1335 e_forward.z = v_forward * t_up;
1336 e_up.x = v_up * t_forward;
1337 e_up.y = v_up * t_left;
1338 e_up.z = v_up * t_up;
1340 e.angles = fixedvectoangles2(e_forward, e_up);
1341 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
1342 e.angles = AnglesTransform_ToVAngles(e.angles);
1344 e.angles = AnglesTransform_ToAngles(e.angles);
1346 setattachment(e, to, tag);
1347 setorigin(e, e.origin);
1350 void detach_sameorigin(entity e)
1353 org = gettaginfo(e, 0);
1354 e.angles = fixedvectoangles2(v_forward, v_up);
1355 if (substring(e.model, 0, 1) == "*") // bmodels have their own rules
1356 e.angles = AnglesTransform_ToVAngles(e.angles);
1358 e.angles = AnglesTransform_ToAngles(e.angles);
1360 setattachment(e, NULL, "");
1361 setorigin(e, e.origin);
1364 void follow_sameorigin(entity e, entity to)
1366 set_movetype(e, MOVETYPE_FOLLOW); // make the hole follow
1367 e.aiment = to; // make the hole follow bmodel
1368 e.punchangle = to.angles; // the original angles of bmodel
1369 e.view_ofs = e.origin - to.origin; // relative origin
1370 e.v_angle = e.angles - to.angles; // relative angles
1373 void unfollow_sameorigin(entity e)
1375 set_movetype(e, MOVETYPE_NONE);
1378 entity gettaginfo_relative_ent;
1379 vector gettaginfo_relative(entity e, float tag)
1381 if (!gettaginfo_relative_ent)
1383 gettaginfo_relative_ent = spawn();
1384 gettaginfo_relative_ent.effects = EF_NODRAW;
1386 gettaginfo_relative_ent.model = e.model;
1387 gettaginfo_relative_ent.modelindex = e.modelindex;
1388 gettaginfo_relative_ent.frame = e.frame;
1389 return gettaginfo(gettaginfo_relative_ent, tag);
1392 .string aiment_classname;
1393 .float aiment_deadflag;
1394 void SetMovetypeFollow(entity ent, entity e)
1396 // FIXME this may not be warpzone aware
1397 set_movetype(ent, MOVETYPE_FOLLOW); // make the hole follow
1398 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.
1399 ent.aiment = e; // make the hole follow bmodel
1400 ent.punchangle = e.angles; // the original angles of bmodel
1401 ent.view_ofs = ent.origin - e.origin; // relative origin
1402 ent.v_angle = ent.angles - e.angles; // relative angles
1403 ent.aiment_classname = strzone(e.classname);
1404 ent.aiment_deadflag = e.deadflag;
1406 void UnsetMovetypeFollow(entity ent)
1408 set_movetype(ent, MOVETYPE_FLY);
1409 PROJECTILE_MAKETRIGGER(ent);
1412 float LostMovetypeFollow(entity ent)
1415 if(ent.move_movetype != MOVETYPE_FOLLOW)
1421 if(ent.aiment.classname != ent.aiment_classname)
1423 if(ent.aiment.deadflag != ent.aiment_deadflag)
1430 bool isPushable(entity e)
1441 case "droppedweapon":
1443 case "bullet": // antilagged bullets can't hit this either
1446 if (e.projectiledeathtype)