-entity findnearest(vector point, bool checkitems, vector axismod)
-{
- vector dist;
- int num_nearest = 0;
-
- IL_EACH(((checkitems) ? g_items : g_locations), ((checkitems) ? (it.target == "###item###") : (it.classname == "target_location")),
- {
- if ((it.items == IT_KEY1 || it.items == IT_KEY2) && it.target == "###item###")
- dist = it.oldorigin;
- else
- dist = it.origin;
- dist = dist - point;
- dist = dist.x * axismod.x * '1 0 0' + dist.y * axismod.y * '0 1 0' + dist.z * axismod.z * '0 0 1';
- float len = vlen2(dist);
-
- int l;
- for (l = 0; l < num_nearest; ++l)
- {
- if (len < nearest_length[l])
- break;
- }
-
- // now i tells us where to insert at
- // INSERTION SORT! YOU'VE SEEN IT! RUN!
- if (l < NUM_NEAREST_ENTITIES)
- {
- for (int j = NUM_NEAREST_ENTITIES - 1; j >= l; --j)
- {
- nearest_length[j + 1] = nearest_length[j];
- nearest_entity[j + 1] = nearest_entity[j];
- }
- nearest_length[l] = len;
- nearest_entity[l] = it;
- if (num_nearest < NUM_NEAREST_ENTITIES)
- num_nearest = num_nearest + 1;
- }
- });
-
- // now use the first one from our list that we can see
- for (int j = 0; j < num_nearest; ++j)
- {
- traceline(point, nearest_entity[j].origin, true, NULL);
- if (trace_fraction == 1)
- {
- if (j != 0)
- LOG_TRACEF("Nearest point (%s) is not visible, using a visible one.", nearest_entity[0].netname);
- return nearest_entity[j];
- }
- }
-
- if (num_nearest == 0)
- return NULL;
-
- LOG_TRACE("Not seeing any location point, using nearest as fallback.");
- /* DEBUGGING CODE:
- dprint("Candidates were: ");
- for(j = 0; j < num_nearest; ++j)
- {
- if(j != 0)
- dprint(", ");
- dprint(nearest_entity[j].netname);
- }
- dprint("\n");
- */
-
- return nearest_entity[0];
-}
-
-string NearestLocation(vector p)
-{
- string ret = "somewhere";
- entity loc = findnearest(p, false, '1 1 1');
- if (loc)
- ret = loc.message;
- else
- {
- loc = findnearest(p, true, '1 1 4');
- if (loc)
- ret = loc.netname;
- }
- return ret;
-}
-
-string PlayerHealth(entity this)
-{
- float myhealth = floor(GetResource(this, RES_HEALTH));
- if(myhealth == -666)
- return "spectating";
- else if(myhealth == -2342 || (myhealth == 2342 && mapvote_initialized))
- return "observing";
- else if(myhealth <= 0 || IS_DEAD(this))
- return "dead";
- return ftos(myhealth);
-}
-
-string WeaponNameFromWeaponentity(entity this, .entity weaponentity)
-{
- entity wepent = this.(weaponentity);
- if(!wepent)
- return "none";
- else if(wepent.m_weapon != WEP_Null)
- return wepent.m_weapon.m_name;
- else if(wepent.m_switchweapon != WEP_Null)
- return wepent.m_switchweapon.m_name;
- return "none"; //REGISTRY_GET(Weapons, wepent.cnt).m_name;
-}
-
-string formatmessage(entity this, string msg)
-{
- float p, p1, p2;
- float n;
- vector cursor = '0 0 0';
- entity cursor_ent = NULL;
- string escape;
- string replacement;
- p = 0;
- n = 7;
- bool traced = false;
-
- MUTATOR_CALLHOOK(PreFormatMessage, this, msg);
- msg = M_ARGV(1, string);
-
- while (1) {
- if (n < 1)
- break; // too many replacements
-
- n = n - 1;
- p1 = strstrofs(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
- p2 = strstrofs(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
-
- if (p1 < 0)
- p1 = p2;
-
- if (p2 < 0)
- p2 = p1;
-
- p = min(p1, p2);
-
- if (p < 0)
- break;
-
- if(!traced)
- {
- WarpZone_crosshair_trace_plusvisibletriggers(this);
- cursor = trace_endpos;
- cursor_ent = trace_ent;
- traced = true;
- }
-
- replacement = substring(msg, p, 2);
- escape = substring(msg, p + 1, 1);
-
- .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-
- switch(escape)
- {
- case "%": replacement = "%"; break;
- case "\\":replacement = "\\"; break;
- case "n": replacement = "\n"; break;
- case "a": replacement = ftos(floor(GetResource(this, RES_ARMOR))); break;
- case "h": replacement = PlayerHealth(this); break;
- case "l": replacement = NearestLocation(this.origin); break;
- case "y": replacement = NearestLocation(cursor); break;
- case "d": replacement = NearestLocation(this.death_origin); break;
- case "w": replacement = WeaponNameFromWeaponentity(this, weaponentity); break;
- case "W": replacement = GetAmmoName(this.(weaponentity).m_weapon.ammo_type); break;
- case "x": replacement = ((cursor_ent.netname == "" || !cursor_ent) ? "nothing" : cursor_ent.netname); break;
- case "s": replacement = ftos(vlen(this.velocity - this.velocity_z * '0 0 1')); break;
- case "S": replacement = ftos(vlen(this.velocity)); break;
- case "t": replacement = seconds_tostring(ceil(max(0, autocvar_timelimit * 60 + game_starttime - time))); break;
- case "T": replacement = seconds_tostring(floor(time - game_starttime)); break;
- default:
- {
- MUTATOR_CALLHOOK(FormatMessage, this, escape, replacement, msg);
- replacement = M_ARGV(2, string);
- break;
- }
- }
-
- msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
- p = p + strlen(replacement);
- }
- return msg;
-}
-
-/*
-=============
-GetCvars
-=============
-Called with:
- 0: sends the request
- >0: receives a cvar from name=argv(f) value=argv(f+1)
-*/
-void GetCvars_handleString(entity this, entity store, string thisname, float f, .string field, string name)
-{
- if (f < 0)
- {
- strfree(store.(field));
- }
- else if (f > 0)
- {
- if (thisname == name)
- {
- strcpy(store.(field), argv(f + 1));
- }
- }
- else
- stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
-}
-void GetCvars_handleString_Fixup(entity this, entity store, string thisname, float f, .string field, string name, string(entity, string) func)
-{
- GetCvars_handleString(this, store, thisname, f, field, name);
- if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
- if (thisname == name)
- {
- string s = func(this, strcat1(store.(field)));
- if (s != store.(field))
- {
- strcpy(store.(field), s);
- }
- }
-}
-void GetCvars_handleFloat(entity this, entity store, string thisname, float f, .float field, string name)
-{
- if (f < 0)
- {
- }
- else if (f > 0)
- {
- if (thisname == name)
- store.(field) = stof(argv(f + 1));
- }
- else
- stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
-}
-void GetCvars_handleFloatOnce(entity this, entity store, string thisname, float f, .float field, string name)
-{
- if (f < 0)
- {
- }
- else if (f > 0)
- {
- if (thisname == name)
- {
- if (!store.(field))
- {
- store.(field) = stof(argv(f + 1));
- if (!store.(field))
- store.(field) = -1;
- }
- }
- }
- else
- {
- if (!store.(field))
- stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
- }
-}
-string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo)
-{
- string o = W_FixWeaponOrder_ForceComplete(wo);
- strcpy(CS(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o));
- return o;
-}
-
-/**
- * @param f -1: cleanup, 0: request, 1: receive
- */
-void GetCvars(entity this, entity store, int f)
-{
- string s = string_null;
-
- if (f == 0)
- LOG_INFO("Warning: requesting cvar values is deprecated. Client should send them automatically using REPLICATE.\n");
-
- if (f > 0)
- s = strcat1(argv(f));
-
- get_cvars_f = f;
- get_cvars_s = s;
- MUTATOR_CALLHOOK(GetCvars);
-
- Notification_GetCvars(this);
-
- ReplicateVars(this, store, s, f);
-
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
- GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
-
- GetCvars_handleFloat(this, store, s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
-
- // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
- if (f > 0)
- {
- if (s == "cl_weaponpriority")
- {
- for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
- {
- .entity weaponentity = weaponentities[slot];
- if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
- this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
- }
- }
- if (s == "cl_allow_uidtracking")
- PlayerStats_GameReport_AddPlayer(this);
- //if (s == "cl_gunalign")
- //W_ResetGunAlign(this, store.cvar_cl_gunalign);
- }
-}
-
-// decolorizes and team colors the player name when needed
-string playername(entity p, bool team_colorize)
-{
- string t;
- if (team_colorize && teamplay && !intermission_running && IS_PLAYER(p))
- {
- t = Team_ColorCode(p.team);
- return strcat(t, strdecolorize(p.netname));
- }
- else
- return p.netname;
-}
-
-float want_weapon(entity weaponinfo, float allguns)
-{
- int d = 0;
- bool allow_mutatorblocked = false;
-
- if(!weaponinfo.m_id)
- return 0;
-
- bool mutator_returnvalue = MUTATOR_CALLHOOK(WantWeapon, weaponinfo, d, allguns, allow_mutatorblocked);
- d = M_ARGV(1, float);
- allguns = M_ARGV(2, bool);
- allow_mutatorblocked = M_ARGV(3, bool);
-
- if(allguns)
- d = boolean((weaponinfo.spawnflags & WEP_FLAG_NORMAL) && !(weaponinfo.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK)));
- else if(!mutator_returnvalue)
- d = !(!weaponinfo.weaponstart);
-
- if(!allow_mutatorblocked && (weaponinfo.spawnflags & WEP_FLAG_MUTATORBLOCKED)) // never default mutator blocked guns
- d = 0;
-
- float t = weaponinfo.weaponstartoverride;
-
- //LOG_INFOF("want_weapon: %s - d: %d t: %d\n", weaponinfo.netname, d, t);
-
- // bit order in t:
- // 1: want or not
- // 2: is default?
- // 4: is set by default?
- if(t < 0)
- t = 4 | (3 * d);
- else
- t |= (2 * d);
-
- return t;
-}
-
-/// Weapons the player normally starts with outside weapon arena.
-WepSet weapons_start()
-{
- WepSet ret = '0 0 0';
- FOREACH(Weapons, it != WEP_Null, {
- int w = want_weapon(it, false);
- if (w & 1)
- ret |= it.m_wepset;
- });
- return ret;
-}
-
-WepSet weapons_all()
-{
- WepSet ret = '0 0 0';
- FOREACH(Weapons, it != WEP_Null, {
- if (!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)))
- ret |= it.m_wepset;
- });
- return ret;
-}
-
-WepSet weapons_devall()
-{
- WepSet ret = '0 0 0';
- FOREACH(Weapons, it != WEP_Null,
- {
- ret |= it.m_wepset;
- });
- return ret;
-}
-
-WepSet weapons_most()
-{
- WepSet ret = '0 0 0';
- FOREACH(Weapons, it != WEP_Null, {
- if ((it.spawnflags & WEP_FLAG_NORMAL) && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK)))
- ret |= it.m_wepset;
- });
- return ret;
-}
-
-void weaponarena_available_all_update(entity this)
-{
- if (weaponsInMapAll)
- {
- start_weapons = warmup_start_weapons = g_weaponarena_weapons = weapons_start() | (weaponsInMapAll & weapons_all());
- }
- else
- {
- // if no weapons are available on the map, just fall back to all weapons arena
- start_weapons = warmup_start_weapons = g_weaponarena_weapons = weapons_all();
- }
-}
-
-void weaponarena_available_devall_update(entity this)
-{
- if (weaponsInMapAll)
- {
- start_weapons = warmup_start_weapons = g_weaponarena_weapons = weapons_start() | weaponsInMapAll;
- }
- else
- {
- // if no weapons are available on the map, just fall back to devall weapons arena
- start_weapons = warmup_start_weapons = g_weaponarena_weapons = weapons_devall();
- }
-}
-
-void weaponarena_available_most_update(entity this)
-{
- if (weaponsInMapAll)
- {
- start_weapons = warmup_start_weapons = g_weaponarena_weapons = weapons_start() | (weaponsInMapAll & weapons_most());
- }
- else
- {
- // if no weapons are available on the map, just fall back to most weapons arena
- start_weapons = warmup_start_weapons = g_weaponarena_weapons = weapons_most();
- }
-}
-
-void readplayerstartcvars()
-{
- // initialize starting values for players
- start_weapons = '0 0 0';
- start_weapons_default = '0 0 0';
- start_weapons_defaultmask = '0 0 0';
- start_items = 0;
- start_ammo_shells = 0;
- start_ammo_nails = 0;
- start_ammo_rockets = 0;
- start_ammo_cells = 0;
- start_ammo_plasma = 0;
- if (random_start_ammo == NULL)
- {
- random_start_ammo = spawn();
- }
- start_health = cvar("g_balance_health_start");
- start_armorvalue = cvar("g_balance_armor_start");
-
- g_weaponarena = 0;
- g_weaponarena_weapons = '0 0 0';
-
- string s = cvar_string("g_weaponarena");
-
- MUTATOR_CALLHOOK(SetWeaponArena, s);
- s = M_ARGV(0, string);
-
- if (s == "0" || s == "")
- {
- // no arena
- }
- else if (s == "off")
- {
- // forcibly turn off weaponarena
- }
- else if (s == "all" || s == "1")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "All Weapons";
- g_weaponarena_weapons = weapons_all();
- }
- else if (s == "devall")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "Dev All Weapons";
- g_weaponarena_weapons = weapons_devall();
- }
- else if (s == "most")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "Most Weapons";
- g_weaponarena_weapons = weapons_most();
- }
- else if (s == "all_available")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "All Available Weapons";
-
- // this needs to run after weaponsInMapAll is initialized
- InitializeEntity(NULL, weaponarena_available_all_update, INITPRIO_FINDTARGET);
- }
- else if (s == "devall_available")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "Dev All Available Weapons";
-
- // this needs to run after weaponsInMapAll is initialized
- InitializeEntity(NULL, weaponarena_available_devall_update, INITPRIO_FINDTARGET);
- }
- else if (s == "most_available")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "Most Available Weapons";
-
- // this needs to run after weaponsInMapAll is initialized
- InitializeEntity(NULL, weaponarena_available_most_update, INITPRIO_FINDTARGET);
- }
- else if (s == "none")
- {
- g_weaponarena = 1;
- g_weaponarena_list = "No Weapons";
- }
- else
- {
- g_weaponarena = 1;
- float t = tokenize_console(s);
- g_weaponarena_list = "";
- for (int j = 0; j < t; ++j)
- {
- s = argv(j);
- Weapon wep = Weapon_from_name(s);
- if(wep != WEP_Null)
- {
- g_weaponarena_weapons |= (wep.m_wepset);
- g_weaponarena_list = strcat(g_weaponarena_list, wep.m_name, " & ");
- }
- }
- g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
- }
-
- if (g_weaponarena)
- {
- g_weapon_stay = 0; // incompatible
- start_weapons = g_weaponarena_weapons;
- start_items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
- }
- else
- {
- FOREACH(Weapons, it != WEP_Null, {
- int w = want_weapon(it, false);
- WepSet s = it.m_wepset;
- if(w & 1)
- start_weapons |= s;
- if(w & 2)
- start_weapons_default |= s;
- if(w & 4)
- start_weapons_defaultmask |= s;
- });
- }
-
- if(cvar("g_balance_superweapons_time") < 0)
- start_items |= IT_UNLIMITED_SUPERWEAPONS;
-
- if(!cvar("g_use_ammunition"))
- start_items |= IT_UNLIMITED_AMMO;
-
- if(start_items & IT_UNLIMITED_AMMO)
- {
- start_ammo_shells = 999;
- start_ammo_nails = 999;
- start_ammo_rockets = 999;
- start_ammo_cells = 999;
- start_ammo_plasma = 999;
- start_ammo_fuel = 999;
- }
- else
- {
- start_ammo_shells = cvar("g_start_ammo_shells");
- start_ammo_nails = cvar("g_start_ammo_nails");
- start_ammo_rockets = cvar("g_start_ammo_rockets");
- start_ammo_cells = cvar("g_start_ammo_cells");
- start_ammo_plasma = cvar("g_start_ammo_plasma");
- start_ammo_fuel = cvar("g_start_ammo_fuel");
- random_start_weapons_count = cvar("g_random_start_weapons_count");
- SetResource(random_start_ammo, RES_SHELLS, cvar("g_random_start_shells"));
- SetResource(random_start_ammo, RES_BULLETS, cvar("g_random_start_bullets"));
- SetResource(random_start_ammo, RES_ROCKETS,cvar("g_random_start_rockets"));
- SetResource(random_start_ammo, RES_CELLS, cvar("g_random_start_cells"));
- SetResource(random_start_ammo, RES_PLASMA, cvar("g_random_start_plasma"));
- }
-
- warmup_start_ammo_shells = start_ammo_shells;
- warmup_start_ammo_nails = start_ammo_nails;
- warmup_start_ammo_rockets = start_ammo_rockets;
- warmup_start_ammo_cells = start_ammo_cells;
- warmup_start_ammo_plasma = start_ammo_plasma;
- warmup_start_ammo_fuel = start_ammo_fuel;
- warmup_start_health = start_health;
- warmup_start_armorvalue = start_armorvalue;
- warmup_start_weapons = start_weapons;
- warmup_start_weapons_default = start_weapons_default;
- warmup_start_weapons_defaultmask = start_weapons_defaultmask;
-
- if (!g_weaponarena)
- {
- warmup_start_ammo_shells = cvar("g_warmup_start_ammo_shells");
- warmup_start_ammo_nails = cvar("g_warmup_start_ammo_nails");
- warmup_start_ammo_rockets = cvar("g_warmup_start_ammo_rockets");
- warmup_start_ammo_cells = cvar("g_warmup_start_ammo_cells");
- warmup_start_ammo_plasma = cvar("g_warmup_start_ammo_plasma");
- warmup_start_ammo_fuel = cvar("g_warmup_start_ammo_fuel");
- warmup_start_health = cvar("g_warmup_start_health");
- warmup_start_armorvalue = cvar("g_warmup_start_armor");
- warmup_start_weapons = '0 0 0';
- warmup_start_weapons_default = '0 0 0';
- warmup_start_weapons_defaultmask = '0 0 0';
- FOREACH(Weapons, it != WEP_Null, {
- int w = want_weapon(it, autocvar_g_warmup_allguns);
- WepSet s = it.m_wepset;
- if(w & 1)
- warmup_start_weapons |= s;
- if(w & 2)
- warmup_start_weapons_default |= s;
- if(w & 4)
- warmup_start_weapons_defaultmask |= s;
- });
- }
-
- if (autocvar_g_jetpack)
- start_items |= ITEM_Jetpack.m_itemid;
-
- MUTATOR_CALLHOOK(SetStartItems);
-
- if (start_items & ITEM_Jetpack.m_itemid)
- {
- start_items |= ITEM_JetpackRegen.m_itemid;
- start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
- warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable"));
- }
-
- start_ammo_shells = max(0, start_ammo_shells);
- start_ammo_nails = max(0, start_ammo_nails);
- start_ammo_rockets = max(0, start_ammo_rockets);
- start_ammo_cells = max(0, start_ammo_cells);
- start_ammo_plasma = max(0, start_ammo_plasma);
- start_ammo_fuel = max(0, start_ammo_fuel);
- SetResource(random_start_ammo, RES_SHELLS,
- max(0, GetResource(random_start_ammo, RES_SHELLS)));
- SetResource(random_start_ammo, RES_BULLETS,
- max(0, GetResource(random_start_ammo, RES_BULLETS)));
- SetResource(random_start_ammo, RES_ROCKETS,
- max(0, GetResource(random_start_ammo, RES_ROCKETS)));
- SetResource(random_start_ammo, RES_CELLS,
- max(0, GetResource(random_start_ammo, RES_CELLS)));
- SetResource(random_start_ammo, RES_PLASMA,
- max(0, GetResource(random_start_ammo, RES_PLASMA)));
-
- warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
- warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
- warmup_start_ammo_rockets = max(0, warmup_start_ammo_rockets);
- warmup_start_ammo_cells = max(0, warmup_start_ammo_cells);
- warmup_start_ammo_plasma = max(0, warmup_start_ammo_plasma);
- warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel);
-}
-
-void precache_playermodel(string m)
-{
- int globhandle, i, n;
- string f;
-
- // remove :<skinnumber> suffix
- int j = strstrofs(m, ":", 0);
- if(j >= 0)
- m = substring(m, 0, j);
-
- if(substring(m, -9, 5) == "_lod1")
- return;
- if(substring(m, -9, 5) == "_lod2")
- return;
- precache_model(m);
- f = strcat(substring(m, 0, -5), "_lod1", substring(m, -4, -1));
- if(fexists(f))
- precache_model(f);
- f = strcat(substring(m, 0, -5), "_lod2", substring(m, -4, -1));
- if(fexists(f))
- precache_model(f);
-
- globhandle = search_begin(strcat(m, "_*.sounds"), true, false);
- if (globhandle < 0)
- return;
- n = search_getsize(globhandle);
- for (i = 0; i < n; ++i)
- {
- //print(search_getfilename(globhandle, i), "\n");
- f = search_getfilename(globhandle, i);
- PrecachePlayerSounds(f);
- }
- search_end(globhandle);
-}
-void precache_all_playermodels(string pattern)
-{
- int globhandle = search_begin(pattern, true, false);
- if (globhandle < 0) return;
- int n = search_getsize(globhandle);
- for (int i = 0; i < n; ++i)
- {
- string s = search_getfilename(globhandle, i);
- precache_playermodel(s);
- }
- search_end(globhandle);
-}
-
-void precache_playermodels(string s)
-{
- FOREACH_WORD(s, true, { precache_playermodel(it); });
-}
-
-PRECACHE(PlayerModels)
-{
- // Precache all player models if desired
- if (autocvar_sv_precacheplayermodels)
- {
- PrecachePlayerSounds("sound/player/default.sounds");
- precache_all_playermodels("models/player/*.zym");
- precache_all_playermodels("models/player/*.dpm");
- precache_all_playermodels("models/player/*.md3");
- precache_all_playermodels("models/player/*.psk");
- precache_all_playermodels("models/player/*.iqm");
- }
-
- if (autocvar_sv_defaultcharacter)
- {
- precache_playermodels(autocvar_sv_defaultplayermodel_red);
- precache_playermodels(autocvar_sv_defaultplayermodel_blue);
- precache_playermodels(autocvar_sv_defaultplayermodel_yellow);
- precache_playermodels(autocvar_sv_defaultplayermodel_pink);
- precache_playermodels(autocvar_sv_defaultplayermodel);
- }
-}
-
-void InitializeEntity(entity e, void(entity this) func, int order)
-{
- entity prev, cur;
-
- if (!e || e.initialize_entity)
- {
- // make a proxy initializer entity
- entity e_old = e;
- e = new(initialize_entity);
- e.enemy = e_old;
- }
-
- e.initialize_entity = func;
- e.initialize_entity_order = order;
-
- cur = initialize_entity_first;
- prev = NULL;
- for (;;)
- {
- if (!cur || cur.initialize_entity_order > order)
- {
- // insert between prev and cur
- if (prev)
- prev.initialize_entity_next = e;
- else
- initialize_entity_first = e;
- e.initialize_entity_next = cur;
- return;
- }
- prev = cur;
- cur = cur.initialize_entity_next;
- }
-}
-void InitializeEntitiesRun()
-{
- entity startoflist = initialize_entity_first;
- initialize_entity_first = NULL;
- delete_fn = remove_except_protected;
- for (entity e = startoflist; e; e = e.initialize_entity_next)
- {
- e.remove_except_protected_forbidden = 1;
- }
- for (entity e = startoflist; e; )
- {
- e.remove_except_protected_forbidden = 0;
- e.initialize_entity_order = 0;
- entity next = e.initialize_entity_next;
- e.initialize_entity_next = NULL;
- var void(entity this) func = e.initialize_entity;
- e.initialize_entity = func_null;
- if (e.classname == "initialize_entity")
- {
- entity wrappee = e.enemy;
- builtin_remove(e);
- e = wrappee;
- }
- //dprint("Delayed initialization: ", e.classname, "\n");
- if (func)
- {
- func(e);
- }
- else
- {
- eprint(e);
- backtrace(strcat("Null function in: ", e.classname, "\n"));
- }
- e = next;
- }
- delete_fn = remove_unsafely;
-}
-
-void adaptor_think2use_hittype_splash(entity this) // for timed projectile detonation
-{
- 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
- this.projectiledeathtype |= HITTYPE_SPLASH;
- adaptor_think2use(this);
-}
-
-// deferred dropping
-void DropToFloor_Handler(entity this)
-{
- WITHSELF(this, builtin_droptofloor());
- this.dropped_origin = this.origin;
-}
-
-void droptofloor(entity this)
-{
- InitializeEntity(this, DropToFloor_Handler, INITPRIO_DROPTOFLOOR);
-}
-
-
-