- wget -O data/maps/stormkeep.waypoints https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints
- wget -O data/maps/stormkeep.waypoints.cache https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints.cache
- make
- - EXPECT=0a08daa9132d147f533776deda07643e
+ - EXPECT=ed9be8d1b1a544f89bcdd7d36876fede
- HASH=$(${ENGINE} -noconfig -nohome +exec serverbench.cfg
| tee /dev/stderr
| grep '^:'
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 40
+set g_random_start_cells 30
+set g_random_start_plasma 30
set g_warmup_start_health 100 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage"
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 15
+set g_random_start_cells 25
+set g_random_start_plasma 25
set g_warmup_start_health 250 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 50 "starting values when being in warmup-stage"
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 40
+set g_random_start_cells 30
+set g_random_start_plasma 30
set g_warmup_start_health 100 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage"
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 40
+set g_random_start_cells 30
+set g_random_start_plasma 30
set g_warmup_start_health 100 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage"
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 40
+set g_random_start_cells 30
+set g_random_start_plasma 30
set g_warmup_start_health 100 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage"
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 40
+set g_random_start_cells 30
+set g_random_start_plasma 30
set g_warmup_start_health 100 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage"
set g_start_ammo_cells 0
set g_start_ammo_plasma 0
set g_start_ammo_fuel 0
+set g_random_start_weapons_count 0
+set g_random_start_weapons "machinegun mortar electro crylink vortex hagar devastator"
+set g_random_start_shells 15
+set g_random_start_bullets 80
+set g_random_start_rockets 40
+set g_random_start_cells 30
+set g_random_start_plasma 30
set g_warmup_start_health 100 "starting values when being in warmup-stage"
set g_warmup_start_armor 100 "starting values when being in warmup-stage"
set g_warmup_start_ammo_shells 30 "starting values when being in warmup-stage"
set sv_simple_items 1 "allow or forbid client use of simple items"
set sv_showspectators 1 "Show who's spectating who in the player info panel when client has cl_showspectators on. Shouldn't be used on competitive servers, also disable when watching a suspected cheater"
+
+set sv_damagetext 2 "<= 0: disabled, >= 1: visible to spectators, >= 2: visible to attacker, >= 3: all players see everyone's damage"
// running guns
// ==============
set g_running_guns 0 "... or wonder, till it drives you mad, what would have followed if you had."
+
+// ==================
+// dynamic handicap
+// ==================
+set g_dynamic_handicap 0 "Whether to enable dynamic handicap."
+set g_dynamic_handicap_scale 0.2 "The scale of the handicap. Larger values mean more penalties for strong players and more buffs for weak players."
+set g_dynamic_handicap_exponent 1 "The exponent used to calculate handicap. 1 means linear scale. Values more than 1 mean stronger non-linear handicap. Values less than 1 mean weaker non-linear handicap"
+set g_dynamic_handicap_min 0 "The minimum value of the handicap."
+set g_dynamic_handicap_max 0 "The maximum value of the handicap."
// RegisterPlayer(o);
//playerchecker will do this for us later, if it has not already done so
- int sf, lf;
- sf = ReadShort();
- lf = ReadShort();
+ int sf = ReadShort();
+ int lf = ReadShort();
FOREACH(Scores, true, {
- int p = 1 << (i % 16);
+ int p = 1 << (i % 16);
if (sf & p)
{
if (lf & p)
else
o.(scores(it)) = ReadChar();
}
- });
+ });
return = true;
{
make_pure(this);
int i;
- entity o;
this.team = ReadByte();
- o = this.owner = GetTeam(this.team, true); // these team numbers can always be trusted
+ entity o = this.owner = GetTeam(this.team, true); // these team numbers can always be trusted
- int sf, lf;
#if MAX_TEAMSCORE <= 8
- sf = ReadByte();
- lf = ReadByte();
+ int sf = ReadByte();
+ int lf = ReadByte();
#else
- sf = ReadShort();
- lf = ReadShort();
+ int sf = ReadShort();
+ int lf = ReadShort();
#endif
- int p;
- for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
- if(sf & p)
+ for(i = 0; i < MAX_TEAMSCORE; ++i)
+ if(sf & BIT(i))
{
- if(lf & p)
+ if(lf & BIT(i))
o.(teamscores(i)) = ReadInt24_t();
else
o.(teamscores(i)) = ReadChar();
make_pure(this);
float newspectatee_status;
- int f = ReadByte();
+ int f = ReadByte();
scoreboard_showscores_force = (f & BIT(0));
NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
{
make_pure(this);
- int i, j, b, f;
+ int i, j, b, f;
- int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
+ int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
if(!(nags & BIT(2)))
{
for(i = 1; i <= maxclients; i += 8)
{
f = ReadByte();
- for(j = i-1, b = 1; b < 256; b *= 2, ++j)
+ for(j = i-1, b = BIT(0); b < BIT(8); b <<= 1, ++j)
if (!(f & b))
if(playerslots[j])
playerslots[j].ready = 0;
NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
{
make_pure(this);
- int i, j, b, f;
-
- int sf = ReadByte();
- if(sf & 1)
- {
- for(j = 0; j < maxclients; ++j)
- if(playerslots[j])
+ int sf = 0;
+ serialize(byte, 0, sf);
+ if (sf & 1) {
+ for (int j = 0; j < maxclients; ++j) {
+ if (playerslots[j]) {
playerslots[j].eliminated = 1;
- for(i = 1; i <= maxclients; i += 8)
- {
- f = ReadByte();
- for(j = i-1, b = 1; b < 256; b *= 2, ++j)
- if (!(f & b))
- if(playerslots[j])
- playerslots[j].eliminated = 0;
+ }
+ }
+ for (int i = 1; i <= maxclients; i += 8) {
+ int f = 0;
+ serialize(byte, 0, f);
+ for (int b = 0; b < 8; ++b) {
+ if (f & BIT(b)) continue;
+ int j = i - 1 + b;
+ if (playerslots[j]) {
+ playerslots[j].eliminated = 0;
+ }
+ }
}
}
return true;
NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
{
make_pure(this);
- int sf = ReadInt24_t();
+ int sf = ReadInt24_t();
if (sf == 0) {
for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
weapon_accuracy[w] = -1;
int f = 1;
for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
if (sf & f) {
- int b = ReadByte();
+ int b = ReadByte();
if (b == 0)
weapon_accuracy[w] = -1;
else if (b == 255)
int i;
if ( mv_num_maps < 24 )
{
- int mask, power;
+ int mask;
if(mv_num_maps < 8)
mask = ReadByte();
else if(mv_num_maps < 16)
else
mask = ReadLong();
- for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
+ for(i = 0; i < mv_num_maps; ++i)
{
- if ( mask & power )
+ if (mask & BIT(i))
mv_flags[i] |= GTV_AVAILABLE;
else
mv_flags[i] &= ~GTV_AVAILABLE;
/** True when private information such as origin is available */
.bool m_entcs_private;
+
/** True when origin is available */
+// FIXME: it seems sometimes this is false when observing even though observers should be able to know about all players
+// easily reproducible on heart_v2 or The_Yard with bots - might be because they lack waypoints and bots stand still
+// it has happened in matches with players and no bots but much more rarely
.bool has_origin;
+
/** True when a recent server sent origin has been received */
.bool has_sv_origin;
#include <common/mutators/mutator/damagetext/_mod.inc>
#include <common/mutators/mutator/dodging/_mod.inc>
#include <common/mutators/mutator/doublejump/_mod.inc>
+#include <common/mutators/mutator/dynamic_handicap/_mod.inc>
#include <common/mutators/mutator/globalforces/_mod.inc>
#include <common/mutators/mutator/hook/_mod.inc>
#include <common/mutators/mutator/instagib/_mod.inc>
#include <common/mutators/mutator/damagetext/_mod.qh>
#include <common/mutators/mutator/dodging/_mod.qh>
#include <common/mutators/mutator/doublejump/_mod.qh>
+#include <common/mutators/mutator/dynamic_handicap/_mod.qh>
#include <common/mutators/mutator/globalforces/_mod.qh>
#include <common/mutators/mutator/hook/_mod.qh>
#include <common/mutators/mutator/instagib/_mod.qh>
}
make_impure(NEW(DamageText, server_entity_index, entcs.origin, false, health, armor, potential_damage, deathtype, friendlyfire));
} else if (autocvar_cl_damagetext_2d && spectatee_status != -1) {
- // never show 2d damagetext when observing
- // on some maps (hearth_v2, The_Yard), sometimes has_origin is false even though observers should know about all players
- // it happens mostly with bots but occasionally also with players
+ // never show 2d damagetext when observing - might be a bug in .has_origin
// screen coords only
vector screen_pos = vec2(vid_conwidth * autocvar_cl_damagetext_2d_pos.x, vid_conheight * autocvar_cl_damagetext_2d_pos.y);
--- /dev/null
+// generated file; do not modify
+#ifdef SVQC
+ #include <common/mutators/mutator/dynamic_handicap/sv_dynamic_handicap.qc>
+#endif
--- /dev/null
+// generated file; do not modify
+#ifdef SVQC
+ #include <common/mutators/mutator/dynamic_handicap/sv_dynamic_handicap.qh>
+#endif
--- /dev/null
+#include "sv_dynamic_handicap.qh"
+/// \file
+/// \brief Source file that contains implementation of the Dynamic handicap
+/// mutator.
+/// \author Lyberta
+/// \copyright GNU GPLv2 or any later version.
+
+//======================= Global variables ====================================
+
+int autocvar_g_dynamic_handicap; ///< Whether to enable dynamic handicap.
+/// \brief The scale of the handicap. Larget values mean more penalties for
+/// strong players and more buffs for weak players.
+float autocvar_g_dynamic_handicap_scale;
+/// \brief The exponent used to calculate handicap. 1 means linear scale. Values
+/// more than 1 mean stronger non-linear handicap. Values less than 1 mean
+/// weaker non-linear handicap.
+float autocvar_g_dynamic_handicap_exponent;
+float autocvar_g_dynamic_handicap_min; ///< The minimum value of the handicap.
+float autocvar_g_dynamic_handicap_max; ///< The maximum value of the handicap.
+
+//====================== Forward declarations =================================
+
+/// \brief Clamps the value of the handicap.
+/// \param[in] handicap Value to clamp.
+/// \return Clamped value.
+float DynamicHandicap_ClampHandicap(float handicap);
+
+//========================= Free functions ====================================
+
+/// \brief Updates the handicap of all players.
+/// \return No return.
+void DynamicHandicap_UpdateHandicap()
+{
+ float total_score = 0;
+ float total_players = 0;
+ FOREACH_CLIENT(IS_PLAYER(it),
+ {
+ total_score += PlayerScore_Get(it, SP_SCORE);
+ ++total_players;
+ });
+ float mean_score = total_score / total_players;
+ FOREACH_CLIENT(true,
+ {
+ float score = PlayerScore_Get(it, SP_SCORE);
+ float handicap = fabs((score - mean_score) *
+ autocvar_g_dynamic_handicap_scale);
+ handicap = handicap ** autocvar_g_dynamic_handicap_exponent;
+ if (score < mean_score)
+ {
+ handicap = -handicap;
+ }
+ if (handicap >= 0)
+ {
+ handicap += 1;
+ }
+ else
+ {
+ handicap = 1 / (fabs(handicap) + 1);
+ }
+ handicap = DynamicHandicap_ClampHandicap(handicap);
+ Handicap_SetForcedHandicap(it, handicap);
+ });
+}
+
+float DynamicHandicap_ClampHandicap(float handicap)
+{
+ if ((autocvar_g_dynamic_handicap_min >= 0) && (handicap <
+ autocvar_g_dynamic_handicap_min))
+ {
+ handicap = autocvar_g_dynamic_handicap_min;
+ }
+ if ((autocvar_g_dynamic_handicap_max > 0) && (handicap >
+ autocvar_g_dynamic_handicap_max))
+ {
+ handicap = autocvar_g_dynamic_handicap_max;
+ }
+ return handicap;
+}
+
+//============================= Hooks ========================================
+
+REGISTER_MUTATOR(dynamic_handicap, autocvar_g_dynamic_handicap);
+
+MUTATOR_HOOKFUNCTION(dynamic_handicap, BuildMutatorsString)
+{
+ M_ARGV(0, string) = strcat(M_ARGV(0, string), ":handicap");
+}
+
+MUTATOR_HOOKFUNCTION(dynamic_handicap, BuildMutatorsPrettyString)
+{
+ M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Dynamic handicap");
+}
+
+MUTATOR_HOOKFUNCTION(dynamic_handicap, ClientDisconnect)
+{
+ DynamicHandicap_UpdateHandicap();
+}
+
+MUTATOR_HOOKFUNCTION(dynamic_handicap, PutClientInServer)
+{
+ DynamicHandicap_UpdateHandicap();
+}
+
+MUTATOR_HOOKFUNCTION(dynamic_handicap, MakePlayerObserver)
+{
+ DynamicHandicap_UpdateHandicap();
+}
+
+MUTATOR_HOOKFUNCTION(dynamic_handicap, AddedPlayerScore)
+{
+ if (M_ARGV(0, entity) != SP_SCORE)
+ {
+ return;
+ }
+ DynamicHandicap_UpdateHandicap();
+}
--- /dev/null
+#pragma once
Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
}
+void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
+ entity ammo_entity)
+{
+ if (num_weapons == 0)
+ {
+ return;
+ }
+ int num_potential_weapons = tokenize_console(weapon_names);
+ for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
+ {
+ RandomSelection_Init();
+ for (int weapon_index = 0; weapon_index < num_potential_weapons;
+ ++weapon_index)
+ {
+ string weapon = argv(weapon_index);
+ FOREACH(Weapons, it != WEP_Null,
+ {
+ // Finding a weapon which player doesn't have.
+ if (!(receiver.weapons & it.m_wepset) && (it.netname == weapon))
+ {
+ RandomSelection_AddEnt(it, 1, 1);
+ break;
+ }
+ });
+ }
+ if (RandomSelection_chosen_ent == NULL)
+ {
+ return;
+ }
+ receiver.weapons |= RandomSelection_chosen_ent.m_wepset;
+ if (RandomSelection_chosen_ent.ammo_type == RESOURCE_NONE)
+ {
+ continue;
+ }
+ if (GetResourceAmount(receiver,
+ RandomSelection_chosen_ent.ammo_type) != 0)
+ {
+ continue;
+ }
+ GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
+ GetResourceAmount(ammo_entity,
+ RandomSelection_chosen_ent.ammo_type));
+ }
+}
+
float Item_GiveAmmoTo(entity item, entity player, int resource_type, float ammomax)
{
float amount = GetResourceAmount(item, resource_type);
if(it.itemdef) // is a registered item
{
Item_Show(it, -1);
+ it.scheduledrespawntime = 0;
RandomSelection_AddEnt(it, it.cnt, 0);
}
});
void Item_ScheduleInitialRespawn(entity e);
+/// \brief Give several random weapons and ammo to the entity.
+/// \param[in,out] receiver Entity to give weapons to.
+/// \param[in] num_weapons Number of weapons to give.
+/// \param[in] weapon_names Names of weapons to give separated by spaces.
+/// \param[in] ammo Entity containing the ammo amount for each possible weapon.
+/// \return No return.
+void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
+ entity ammo_entity);
+
float Item_GiveAmmoTo(entity item, entity player, int resource_type, float ammomax);
float Item_GiveTo(entity item, entity player);
void SV_OnEntityPreSpawnFunction()
{
ENGINE_EVENT();
- if (_SV_OnEntityPreSpawnFunction) _SV_OnEntityPreSpawnFunction(this);
+ __spawnfunc_expecting = true;
+ __spawnfunc_expect = this;
}
#define SV_OnEntityPreSpawnFunction _SV_OnEntityPreSpawnFunction
#include "sort.qh"
#include "yenc.qh"
+// netcode mismatch and not sure what caused it? developer_csqcentities 1
+
.string netname;
.int m_id;
.bool(entity this, entity sender, bool isNew) m_read;
#define NET_HANDLE(id, param) bool Net_Handle_##id(entity this, entity sender, param)
+#define NET_GUARD(id) \
+ bool Net_Handle_##id##_guard(entity this, entity sender, bool isNew) { \
+ bool valid = false; \
+ serialize_marker(to, valid); \
+ if (!valid) LOG_FATALF("Last message not fully parsed: %s", _net_prevmsgstr); \
+ _net_prevmsgstr = #id; \
+ return Net_Handle_##id(this, sender, isNew); \
+ }
#ifdef CSQC
+string _net_prevmsgstr;
#define REGISTER_NET_TEMP(id) \
NET_HANDLE(id, bool); \
- REGISTER(TempEntities, NET, id, m_id, new_pure(net_temp_packet)) \
- { \
+ NET_GUARD(id); \
+ REGISTER(TempEntities, NET, id, m_id, new_pure(net_temp_packet)) { \
this.netname = #id; \
- this.m_read = Net_Handle_##id; \
+ this.m_read = Net_Handle_##id##_guard; \
}
#else
#define REGISTER_NET_TEMP(id) \
this.sourceLoc = __FILE__ ":" STR(__LINE__); \
if (!this) isnew = true; \
} \
+ NET_GUARD(id); \
REGISTER(LinkedEntities, NET, id, m_id, new_pure(net_linked_packet)) \
{ \
this.netname = #id; \
- this.m_read = Net_Handle_##id; \
+ this.m_read = Net_Handle_##id##_guard; \
}
#else
#define REGISTER_NET_LINKED(id) \
MACRO_BEGIN { \
if (NET_##id##_istemp) WriteByte(to, SVC_TEMPENTITY); \
WriteByte(to, NET_##id.m_id); \
+ bool _net_valid = false; serialize_marker(to, _net_valid); \
} MACRO_END
#endif
#define stream_writing(stream) false
#endif
-#define serialize(T, stream, ...) serialize_##T(stream, __VA_ARGS__)
+#define serialize(T, stream, ...) \
+MACRO_BEGIN \
+ noref Stream _stream = stream; \
+ serialize_##T(_stream, __VA_ARGS__); \
+MACRO_END
#if defined(SVQC)
#define serialize_byte(stream, this) \
#endif
#define serialize_vector(stream, this) \
- MACRO_BEGIN \
+MACRO_BEGIN \
vector _v = this; \
serialize_float(stream, _v.x); \
serialize_float(stream, _v.y); \
serialize_float(stream, _v.z); \
this = _v; \
- MACRO_END
+MACRO_END
+
+#define serialize_marker(stream, this) \
+MACRO_BEGIN \
+ if (NDEBUG) { \
+ this = true; \
+ } else { \
+ int _de = 0xDE, _ad = 0xAD, _be = 0xBE, _ef = 0xEF; \
+ serialize_byte(stream, _de); \
+ serialize_byte(stream, _ad); \
+ serialize_byte(stream, _be); \
+ serialize_byte(stream, _ef); \
+ this = (_de == 0xDE && _ad == 0xAD && _be == 0xBE && _ef == 0xEF); \
+ } \
+MACRO_END
// serialization: old
#define EVAL_REGISTER_REGISTRY(...) __VA_ARGS__
#define REGISTER_REGISTRY_1(id) REGISTER_REGISTRY_2(id, #id)
#define REGISTER_REGISTRY_2(id, str) \
- ACCUMULATE_FUNCTION(__static_init, Register##id) \
+ ACCUMULATE_FUNCTION(__static_init_1, Register##id) \
CLASS(id##Registry, Object) \
ATTRIB(id##Registry, m_name, string, str); \
ATTRIB(id##Registry, REGISTRY_NEXT, entity, id##_first); \
g_map_entities = IL_NEW(); \
IL_EACH(g_spawn_queue, true, __spawnfunc_spawn(it)); \
MACRO_END
-
+#ifdef SVQC
+ void _SV_OnEntityPreSpawnFunction(entity this);
+#endif
void __spawnfunc_spawn(entity prototype)
{
entity e = new(clone);
#define X(T, fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; }
SPAWNFUNC_INTERNAL_FIELDS(X);
#undef X
+#ifdef SVQC
+ _SV_OnEntityPreSpawnFunction(e);
+ if (wasfreed(e)) {
+ return;
+ }
+#endif
e.__spawnfunc_constructor(e);
}
+ noref bool __spawnfunc_first;
+
#define spawnfunc_1(id) spawnfunc_2(id, FIELDS_UNION)
#define spawnfunc_2(id, whitelist) \
void __spawnfunc_##id(entity this); \
[[accumulate]] void spawnfunc_##id(entity this) \
{ \
+ if (!__spawnfunc_first) { \
+ __spawnfunc_first = true; \
+ static_init_early(); \
+ } \
bool dospawn = true; \
if (__spawnfunc_expecting > 1) { __spawnfunc_expecting = false; } \
else if (__spawnfunc_expecting) { \
#pragma once
-void __static_init() {}
-#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
-void __static_init_late() {}
-#define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_late)
-void __static_init_precache() {}
-#define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_precache)
-void __shutdown() {}
-#define shutdownhooks() CALL_ACCUMULATED_FUNCTION(__shutdown)
-
#define GETTIME_REALTIME 1
#ifdef MENUQC
float(int tmr) _gettime = #67;
LOG_TRACEF("[%f] %s", rt - g_starttime, s);
}
-#define _STATIC_INIT(where, func) \
+#define _STATIC_INIT(func, where) \
[[accumulate]] void _static_##func() { profile(#func); } \
ACCUMULATE_FUNCTION(where, _static_##func) \
void _static_##func()
-#define STATIC_INIT(func) _STATIC_INIT(__static_init, func)
-#define STATIC_INIT_LATE(func) _STATIC_INIT(__static_init_late, func##_late)
-#define PRECACHE(func) _STATIC_INIT(__static_init_precache, func##_precache)
-#define SHUTDOWN(func) _STATIC_INIT(__shutdown, func##_shutdown)
+/** before worldspawn */
+#define STATIC_INIT_EARLY(func) _STATIC_INIT(func##_0, __static_init_0)
+#define static_init_early() CALL_ACCUMULATED_FUNCTION(__static_init_0)
+void __static_init_0() {}
+
+/** during worldspawn */
+#define STATIC_INIT(func) _STATIC_INIT(func##_1, __static_init_1)
+#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init_1)
+void __static_init_1() {}
+
+/** directly after STATIC_INIT */
+#define STATIC_INIT_LATE(func) _STATIC_INIT(func##_2, __static_init_2)
+#define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_2)
+void __static_init_2() {}
+
+/** directly after STATIC_INIT_LATE */
+#define PRECACHE(func) _STATIC_INIT(func##_3, __static_init_3)
+#define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_3)
+void __static_init_3() {}
+
+/* other map entities spawn now */
+
+/** before shutdown */
+#define SHUTDOWN(func) _STATIC_INIT(func##_shutdown, __shutdown)
+#define shutdownhooks() CALL_ACCUMULATED_FUNCTION( __shutdown)
+void __shutdown() {}
#include <server/g_models.qc>
#include <server/g_subs.qc>
#include <server/g_world.qc>
+#include <server/handicap.qc>
#include <server/impulse.qc>
#include <server/ipban.qc>
#include <server/item_key.qc>
#include <server/g_models.qh>
#include <server/g_subs.qh>
#include <server/g_world.qh>
+#include <server/handicap.qh>
#include <server/impulse.qh>
#include <server/ipban.qh>
#include <server/item_key.qh>
float autocvar_g_balance_selfdamagepercent;
bool autocvar_g_balance_teams;
bool autocvar_g_balance_teams_prevent_imbalance;
-float autocvar_g_balance_teams_scorefactor;
+//float autocvar_g_balance_teams_scorefactor;
float autocvar_g_ballistics_density_corpse;
float autocvar_g_ballistics_density_player;
float autocvar_g_ballistics_mindistance;
#include "spawnpoints.qh"
#include "resources.qh"
#include "g_damage.qh"
+#include "handicap.qh"
#include "g_hook.qh"
#include "command/common.qh"
#include "cheats.qh"
bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver, this);
PlayerState_detach(this);
- if (IS_PLAYER(this) && this.health >= 1) {
- // despawn effect
- Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
+ if (IS_PLAYER(this))
+ {
+ if(this.health >= 1)
+ {
+ // despawn effect
+ Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
+ }
+
+ // was a player, recount votes and ready status
+ if(IS_REAL_CLIENT(this))
+ {
+ if (vote_called) { VoteCount(false); }
+ ReadyCount();
+ }
}
{
if (mutator_returnvalue) {
// mutator prevents resetting teams+score
} else {
+ int oldteam = this.team;
this.team = -1; // move this as it is needed to log the player spectating in eventlog
+ MUTATOR_CALLHOOK(Player_ChangedTeam, this, oldteam, this.team);
this.frags = FRAGS_SPECTATOR;
PlayerScore_Clear(this); // clear scores when needed
}
this.flags |= FL_NOTARGET;
this.takedamage = DAMAGE_AIM;
this.effects = EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
- this.dmg = 2; // WTF
if (warmup_stage) {
this.ammo_shells = warmup_start_ammo_shells;
this.health = start_health;
this.armorvalue = start_armorvalue;
this.weapons = start_weapons;
+ GiveRandomWeapons(this, random_start_weapons_count,
+ autocvar_g_random_start_weapons, random_start_ammo);
}
SetSpectatee_status(this, 0);
if(CS(this).killindicator_teamchange)
ClientKill_Now_TeamChange(this);
- if(!IS_SPEC(this) && !IS_OBSERVER(this))
+ if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
+ {
Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0');
+ }
// now I am sure the player IS dead
}
it.init_for_player(it, this);
});
+ Handicap_Initialize(this);
+
MUTATOR_CALLHOOK(ClientConnect, this);
if (IS_REAL_CLIENT(this))
if(this.air_finished < time)
PlayerSound(this, playersound_gasp, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
this.air_finished = time + autocvar_g_balance_contents_drowndelay;
- this.dmg = 2;
}
else if (this.air_finished < time)
{ // drown!
return false;
}
-float c1, c2, c3, c4;
-
void play_countdown(entity this, float finished, Sound samp);
float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit);
{
case CMD_REQUEST_COMMAND:
{
- if (argv(1) != "")
+ if (argv(1) == "")
{
- if (IS_CLIENT(caller))
+ return;
+ }
+ if (!IS_CLIENT(caller))
+ {
+ return;
+ }
+ if (!teamplay)
+ {
+ sprint(caller, "^7selectteam can only be used in teamgames\n");
+ return;
+ }
+ if (caller.team_forced > 0)
+ {
+ sprint(caller, "^7selectteam can not be used as your team is forced\n");
+ return;
+ }
+ if (lockteams)
+ {
+ sprint(caller, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
+ return;
+ }
+ float selection;
+ switch (argv(1))
+ {
+ case "red":
{
- if (teamplay)
- {
- if (caller.team_forced <= 0)
- {
- if (!lockteams)
- {
- float selection;
-
- switch (argv(1))
- {
- case "red": selection = NUM_TEAM_1;
- break;
- case "blue": selection = NUM_TEAM_2;
- break;
- case "yellow": selection = NUM_TEAM_3;
- break;
- case "pink": selection = NUM_TEAM_4;
- break;
- case "auto": selection = (-1);
- break;
-
- default: selection = 0;
- break;
- }
-
- if (selection)
- {
- if (caller.team == selection && selection != -1 && !IS_DEAD(caller))
- {
- sprint(caller, "^7You already are on that team.\n");
- }
- else if (CS(caller).wasplayer && autocvar_g_changeteam_banned)
- {
- sprint(caller, "^1You cannot change team, forbidden by the server.\n");
- }
- else
- {
- if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
- {
- CheckAllowedTeams(caller);
- GetTeamCounts(caller);
- if (!TeamSmallerEqThanTeam(Team_TeamToNumber(selection), Team_TeamToNumber(caller.team), caller))
- {
- Send_Notification(NOTIF_ONE, caller, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
- return;
- }
- }
- ClientKill_TeamChange(caller, selection);
- }
- if(!IS_PLAYER(caller))
- caller.team_selected = true; // avoids asking again for team selection on join
- }
- }
- else
- {
- sprint(caller, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
- }
- }
- else
- {
- sprint(caller, "^7selectteam can not be used as your team is forced\n");
- }
- }
- else
- {
- sprint(caller, "^7selectteam can only be used in teamgames\n");
- }
+ selection = NUM_TEAM_1;
+ break;
+ }
+ case "blue":
+ {
+ selection = NUM_TEAM_2;
+ break;
+ }
+ case "yellow":
+ {
+ selection = NUM_TEAM_3;
+ break;
+ }
+ case "pink":
+ {
+ selection = NUM_TEAM_4;
+ break;
}
+ case "auto":
+ {
+ selection = (-1);
+ break;
+ }
+ default:
+ {
+ return;
+ }
+ }
+ if (caller.team == selection && selection != -1 && !IS_DEAD(caller))
+ {
+ sprint(caller, "^7You already are on that team.\n");
+ return;
+ }
+ if (CS(caller).wasplayer && autocvar_g_changeteam_banned)
+ {
+ sprint(caller, "^1You cannot change team, forbidden by the server.\n");
return;
}
+ if ((selection != -1) && autocvar_g_balance_teams &&
+ autocvar_g_balance_teams_prevent_imbalance)
+ {
+ CheckAllowedTeams(caller);
+ GetTeamCounts(caller);
+ if ((BIT(Team_TeamToNumber(selection) - 1) & FindBestTeams(caller, false)) == 0)
+ {
+ Send_Notification(NOTIF_ONE, caller, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
+ return;
+ }
+ }
+ ClientKill_TeamChange(caller, selection);
+ if (!IS_PLAYER(caller))
+ {
+ caller.team_selected = true; // avoids asking again for team selection on join
+ }
+ return;
}
-
default:
sprint(caller, "Incorrect parameters for ^2selectteam^7\n");
case CMD_REQUEST_USAGE:
// If so, lets continue and finally move the player
client.team_forced = 0;
- MoveToTeam(client, team_id, 6);
- successful = strcat(successful, (successful ? ", " : ""), playername(client, false));
- LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ") has been moved to the ", Team_ColoredFullName(team_id), "^7.");
+ if (MoveToTeam(client, team_id, 6))
+ {
+ successful = strcat(successful, (successful ? ", " : ""), playername(client, false));
+ LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ") has been moved to the ", Team_ColoredFullName(team_id), "^7.");
+ }
+ else
+ {
+ LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ")");
+ }
continue;
}
else
{
for (i = 1; i <= maxclients; i += 8)
{
- for (f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
- if (!IS_REAL_CLIENT(e) || e.ready) f |= b;
+ for (f = 0, e = edict_num(i), b = BIT(0); b < BIT(8); b <<= 1, e = nextent(e))
+ if (!IS_REAL_CLIENT(e) || e.ready)
+ f |= b;
WriteByte(MSG_ENTITY, f);
}
}
int VoteCommand_parse(entity caller, string vote_command, string vote_list, float startpos, float argc)
{
- string first_command;
+ string first_command = argv(startpos);
+ int missing_chars = argv_start_index(startpos);
- first_command = argv(startpos);
-
- /*printf("VoteCommand_parse(): Command: '%s', Length: %f.\n",
- substring(vote_command, argv_start_index(startpos), strlen(vote_command) - argv_start_index(startpos)),
- strlen(substring(vote_command, argv_start_index(startpos), strlen(vote_command) - argv_start_index(startpos)))
- );*/
-
- if (
- (autocvar_sv_vote_limit > 0)
- &&
- (strlen(substring(vote_command, argv_start_index(startpos), strlen(vote_command) - argv_start_index(startpos))) > autocvar_sv_vote_limit)
- ) return 0;
+ if (autocvar_sv_vote_limit > 0 && strlen(vote_command) > autocvar_sv_vote_limit)
+ return 0;
if (!VoteCommand_checkinlist(first_command, vote_list)) return 0;
if (accepted > 0)
{
- string reason = ((argc > next_token) ? substring(vote_command, argv_start_index(next_token), strlen(vote_command) - argv_start_index(next_token)) : "No reason provided");
- string command_arguments;
+ string reason = "No reason provided";
+ if(argc > next_token)
+ reason = substring(vote_command, argv_start_index(next_token) - missing_chars, -1);
- if (first_command == "kickban") command_arguments = strcat(ftos(autocvar_g_ban_default_bantime), " ", ftos(autocvar_g_ban_default_masksize), " ~");
- else command_arguments = reason;
+ string command_arguments = reason;
+ if (first_command == "kickban")
+ command_arguments = strcat(ftos(autocvar_g_ban_default_bantime), " ", ftos(autocvar_g_ban_default_masksize), " ~");
vote_parsed_command = strcat(first_command, " # ", ftos(etof(victim)), " ", command_arguments);
- vote_parsed_display = strcat("^1", vote_command, " (^7", victim.netname, "^1): ", reason);
+ vote_parsed_display = sprintf("^1%s #%d ^7%s^1 %s", first_command, etof(victim), victim.netname, reason);
}
else { print_to(caller, strcat("vcall: ", GetClientErrorString(accepted, argv(startpos + 1)), ".\n")); return 0; }
if(parse_error == 0)
print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info.");
}
-
else // everything went okay, continue with calling the vote
{
vote_caller = caller; // remember who called the vote
}
FOREACH_CLIENT(IS_REAL_CLIENT(it), { ++tmp_playercount; });
- if (tmp_playercount > 1) Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_VOTE_CALL); // don't announce a "vote now" sound if player is alone
+ if (tmp_playercount > 1)
+ Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_VOTE_CALL);
bprint("\{1}^2* ^3", OriginalCallerName(), "^2 calls a vote for ", vote_called_display, "\n");
- if (autocvar_sv_eventlog) GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display));
+ if (autocvar_sv_eventlog)
+ GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display));
Nagger_VoteChanged();
VoteCount(true); // needed if you are the only one
}
int parse_error;
vote_command = VoteCommand_extractcommand(vote_command, 3, argc);
- if (!caller.vote_master) { print_to(caller, "^1You do not have vote master privelages."); }
+ if (!caller.vote_master)
+ print_to(caller, "^1You do not have vote master privileges.");
else if (!VoteCommand_checknasty(vote_command))
{
print_to(caller, "^1Syntax error in command, see 'vhelp' for more info.");
if(parse_error == 0)
print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info.");
}
-
else // everything went okay, proceed with command
{
localcmd(strcat(vote_parsed_command, "\n"));
print_to(caller, strcat("Executing command '", vote_parsed_display, "' on server."));
bprint("\{1}^2* ^3", GetCallerName(caller), "^2 used their ^3master^2 status to do \"^2", vote_parsed_display, "^2\".\n");
- if (autocvar_sv_eventlog) GameLogEcho(strcat(":vote:vdo:", ftos(caller.playerid), ":", vote_parsed_display)); }
+ if (autocvar_sv_eventlog)
+ GameLogEcho(strcat(":vote:vdo:", ftos(caller.playerid), ":", vote_parsed_display));
+ }
return;
}
{
print_to(caller, strcat("Rejected vote master login from ", GetCallerName(caller)));
}
-
else // everything went okay, proceed with giving this player master privilages
{
caller.vote_master = true;
print_to(caller, strcat("Accepted vote master login from ", GetCallerName(caller)));
bprint("\{1}^2* ^3", GetCallerName(caller), "^2 logged in as ^3master^2\n");
- if (autocvar_sv_eventlog) GameLogEcho(strcat(":vote:vlogin:", ftos(caller.playerid))); }
+ if (autocvar_sv_eventlog)
+ GameLogEcho(strcat(":vote:vlogin:", ftos(caller.playerid)));
+ }
return;
}
{
print_to(caller, "^1You can not call a vote while a timeout is active.");
}
-
else // everything went okay, continue with creating vote
{
vote_caller = caller;
caller.vote_waittime = time + autocvar_sv_vote_wait;
bprint("\{1}^2* ^3", OriginalCallerName(), "^2 calls a vote to become ^3master^2.\n");
- if (autocvar_sv_eventlog) GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display));
+ if (autocvar_sv_eventlog)
+ GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display));
Nagger_VoteChanged();
VoteCount(true); // needed if you are the only one
}
print_to(caller, "^1You rejected the vote.");
caller.vote_selection = VOTE_SELECT_REJECT;
msg_entity = caller;
- if (!autocvar_sv_vote_singlecount) VoteCount(false); }
+ if (!autocvar_sv_vote_singlecount)
+ VoteCount(false);
+ }
return;
}
{
print_to(caller, "^1You have already voted.");
}
-
else // everything went okay, continue changing vote
{
print_to(caller, "^1You accepted the vote.");
caller.vote_selection = VOTE_SELECT_ACCEPT;
msg_entity = caller;
- if (!autocvar_sv_vote_singlecount) VoteCount(false); }
+ if (!autocvar_sv_vote_singlecount)
+ VoteCount(false);
+ }
return;
}
e = new(info_player_deathmatch); // safeguard against player joining
- this.classname = "worldspawn"; // safeguard against various stuff ;)
+ // assign reflectively to avoid "assignment to world" warning
+ for (int i = 0, n = numentityfields(); i < n; ++i) {
+ string k = entityfieldname(i);
+ if (k == "classname") {
+ // safeguard against various stuff ;)
+ putentityfieldstring(i, this, "worldspawn");
+ break;
+ }
+ }
// needs to be done so early because of the constants they create
static_init();
MapInfo_Shutdown();
}
+STATIC_INIT_EARLY(maxclients)
+{
+ maxclients = 0;
+ for (entity head = nextent(NULL); head; head = nextent(head)) {
+ ++maxclients;
+ }
+}
+
void Map_MarkAsRecent(string m);
float world_already_spawned;
void Nagger_Init();
cvar_changes_init(); // do this very early now so it REALLY matches the server config
- maxclients = 0;
- for (entity head = nextent(NULL); head; head = nextent(head))
- {
- ++maxclients;
- }
-
// needs to be done so early because of the constants they create
static_init();
--- /dev/null
+#include "handicap.qh"
+
+/// \file
+/// \brief Source file that contains implementation of the handicap system.
+/// \author Lyberta
+/// \copyright GNU GPLv2 or any later version.
+
+#include <common/state.qh>
+#include "client.qh"
+
+.float m_handicap; ///< Holds the handicap value.
+
+void Handicap_Initialize(entity player)
+{
+ CS(player).m_handicap = 1;
+}
+
+float Handicap_GetVoluntaryHandicap(entity player)
+{
+ return bound(1.0, CS(player).cvar_cl_handicap, 10.0);
+}
+
+float Handicap_GetForcedHandicap(entity player)
+{
+ return CS(player).m_handicap;
+}
+
+void Handicap_SetForcedHandicap(entity player, float value)
+{
+ if (value <= 0)
+ {
+ error("Handicap_SetForcedHandicap: Invalid handicap value.");
+ }
+ CS(player).m_handicap = value;
+}
+
+float Handicap_GetTotalHandicap(entity player)
+{
+ return Handicap_GetForcedHandicap(player) * Handicap_GetVoluntaryHandicap(
+ player);
+}
--- /dev/null
+#pragma once
+
+/// \file
+/// \brief Header file that describes the handicap system.
+/// \author Lyberta
+/// \copyright GNU GPLv2 or any later version.
+
+// Handicap is used to make the game harder for strong players and easier for
+// weak players. Values greater than 1 make the game harder and values less than
+// 1 make the game easier. Right now handicap only affects damage. There are 2
+// types of handicap: voluntary and forced. Voluntary handicap can be set via
+// cl_handicap cvar. For obvious reasons, it can't be less than 1. Forced
+// handicap can be set by server mutators. The total handicap is the product of
+// voluntary and forced handicap.
+
+/// \brief Initializes handicap to its default value.
+/// \param[in,out] player Player to initialize.
+/// \return No return.
+void Handicap_Initialize(entity player);
+
+/// \brief Returns the voluntary handicap of the player.
+/// \param[in] player Player to check.
+/// \return Voluntary handicap of the player.
+float Handicap_GetVoluntaryHandicap(entity player);
+
+/// \brief Returns the forced handicap of the player.
+/// \param[in] player Player to check.
+/// \return Forced handicap of the player.
+float Handicap_GetForcedHandicap(entity player);
+
+/// \brief Sets the forced handicap of the player.
+/// \param[in] player Player to alter.
+/// \param[in] value Handicap value to set.
+/// \return No return.
+void Handicap_SetForcedHandicap(entity player, float value);
+
+/// \brief Returns the total handicap of the player.
+/// \param[in] player Player to check.
+/// \return Total handicap of the player.
+float Handicap_GetTotalHandicap(entity player);
#include "ipban.qh"
#include "mutators/_mod.qh"
#include "../common/t_items.qh"
+#include "resources.qh"
#include "weapons/accuracy.qh"
#include "weapons/csqcprojectile.qh"
#include "weapons/selection.qh"
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");
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");
+ SetResourceAmount(random_start_ammo, RESOURCE_SHELLS, cvar(
+ "g_random_start_shells"));
+ SetResourceAmount(random_start_ammo, RESOURCE_BULLETS, cvar(
+ "g_random_start_bullets"));
+ SetResourceAmount(random_start_ammo, RESOURCE_ROCKETS,
+ cvar("g_random_start_rockets"));
+ SetResourceAmount(random_start_ammo, RESOURCE_CELLS, cvar(
+ "g_random_start_cells"));
+ SetResourceAmount(random_start_ammo, RESOURCE_PLASMA, cvar(
+ "g_random_start_plasma"));
}
if (warmup_stage)
start_ammo_cells = max(0, start_ammo_cells);
start_ammo_plasma = max(0, start_ammo_plasma);
start_ammo_fuel = max(0, start_ammo_fuel);
+ SetResourceAmount(random_start_ammo, RESOURCE_SHELLS, max(0,
+ GetResourceAmount(random_start_ammo, RESOURCE_SHELLS)));
+ SetResourceAmount(random_start_ammo, RESOURCE_BULLETS, max(0,
+ GetResourceAmount(random_start_ammo, RESOURCE_BULLETS)));
+ SetResourceAmount(random_start_ammo, RESOURCE_ROCKETS, max(0,
+ GetResourceAmount(random_start_ammo, RESOURCE_ROCKETS)));
+ SetResourceAmount(random_start_ammo, RESOURCE_CELLS, max(0,
+ GetResourceAmount(random_start_ammo, RESOURCE_CELLS)));
+ SetResourceAmount(random_start_ammo, RESOURCE_PLASMA, max(0,
+ GetResourceAmount(random_start_ammo, RESOURCE_PLASMA)));
warmup_start_ammo_shells = max(0, warmup_start_ammo_shells);
warmup_start_ammo_nails = max(0, warmup_start_ammo_nails);
.float(entity) isEliminated;
bool EliminatedPlayers_SendEntity(entity this, entity to, float sendflags)
{
- float i, f, b;
- entity e;
- WriteHeader(MSG_ENTITY, ENT_CLIENT_ELIMINATEDPLAYERS);
- WriteByte(MSG_ENTITY, sendflags);
-
- if(sendflags & 1)
- {
- for(i = 1; i <= maxclients; i += 8)
- {
- for(f = 0, e = edict_num(i), b = 1; b < 256; b *= 2, e = nextent(e))
- {
- if(eliminatedPlayers.isEliminated(e))
- f |= b;
+ Stream out = MSG_ENTITY;
+ WriteHeader(out, ENT_CLIENT_ELIMINATEDPLAYERS);
+ serialize(byte, out, sendflags);
+ if (sendflags & 1) {
+ for (int i = 1; i <= maxclients; i += 8) {
+ int f = 0;
+ entity e = edict_num(i);
+ for (int b = 0; b < 8; ++b, e = nextent(e)) {
+ if (eliminatedPlayers.isEliminated(e)) {
+ f |= BIT(b);
+ }
}
- WriteByte(MSG_ENTITY, f);
+ serialize(byte, out, f);
}
}
-
return true;
}
float start_ammo_cells;
float start_ammo_plasma;
float start_ammo_fuel;
+/// \brief Number of random start weapons to give to players.
+int random_start_weapons_count;
+/// \brief Holds a list of possible random start weapons.
+string autocvar_g_random_start_weapons;
+/// \brief Entity that contains amount of ammo to give with random start
+/// weapons.
+entity random_start_ammo;
float start_health;
float start_armorvalue;
WepSet warmup_start_weapons;
/**/
MUTATOR_HOOKABLE(CheckAllowedTeams, EV_CheckAllowedTeams);
+/** return true to manually override team counts */
+MUTATOR_HOOKABLE(GetTeamCounts, EV_NO_ARGS);
+
+/** allow overriding of team counts */
+#define EV_GetTeamCount(i, o) \
+ /** team to count */ i(float, MUTATOR_ARGV_0_float) \
+ /** player to ignore */ i(entity, MUTATOR_ARGV_1_entity) \
+ /** number of players in a team */ i(float, MUTATOR_ARGV_2_float) \
+ /**/ o(float, MUTATOR_ARGV_2_float) \
+ /** number of bots in a team */ i(float, MUTATOR_ARGV_3_float) \
+ /**/ o(float, MUTATOR_ARGV_3_float) \
+ /** lowest scoring human in a team */ i(entity, MUTATOR_ARGV_4_entity) \
+ /**/ o(entity, MUTATOR_ARGV_4_entity) \
+ /** lowest scoring bot in a team */ i(entity, MUTATOR_ARGV_5_entity) \
+ /**/ o(entity, MUTATOR_ARGV_5_entity) \
+ /**/
+MUTATOR_HOOKABLE(GetTeamCount, EV_GetTeamCount);
+
+/** allows overriding best teams */
+#define EV_FindBestTeams(i, o) \
+ /** player checked */ i(entity, MUTATOR_ARGV_0_entity) \
+ /** bitmask of teams */ o(float, MUTATOR_ARGV_1_float) \
+ /**/
+MUTATOR_HOOKABLE(FindBestTeams, EV_FindBestTeams);
+
/** copies variables for spectating "spectatee" to "this" */
#define EV_SpectateCopy(i, o) \
/** spectatee */ i(entity, MUTATOR_ARGV_0_entity) \
/**/
MUTATOR_HOOKABLE(ClientKill, EV_ClientKill);
+/** called when player is about to be killed during kill command or changing teams */
+#define EV_ClientKill_Now(i, o) \
+ /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+ /**/
+MUTATOR_HOOKABLE(ClientKill_Now, EV_ClientKill_Now);
+
#define EV_FixClientCvars(i, o) \
/** player */ i(entity, MUTATOR_ARGV_0_entity) \
/**/
/**/
MUTATOR_HOOKABLE(AddPlayerScore, EV_AddPlayerScore);
+#define EV_AddedPlayerScore(i, o) \
+ /** score field */ i(entity, MUTATOR_ARGV_0_entity) \
+ /** score */ i(float, MUTATOR_ARGV_1_float) \
+ /** player */ i(entity, MUTATOR_ARGV_2_entity) \
+ /**/
+MUTATOR_HOOKABLE(AddedPlayerScore, EV_AddPlayerScore);
+
#define EV_GetPlayerStatus(i, o) \
/** player */ i(entity, MUTATOR_ARGV_0_entity) \
/**/
/**/
MUTATOR_HOOKABLE(MonsterModel, EV_MonsterModel);
-/**/
+/**
+ * Called before player changes their team. Return true to block team change.
+ */
#define EV_Player_ChangeTeam(i, o) \
/** player */ i(entity, MUTATOR_ARGV_0_entity) \
/** current team */ i(float, MUTATOR_ARGV_1_float) \
/**/
MUTATOR_HOOKABLE(Player_ChangeTeam, EV_Player_ChangeTeam);
+/**
+ * Called after player has changed their team.
+ */
+#define EV_Player_ChangedTeam(i, o) \
+ /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+ /** old team */ i(float, MUTATOR_ARGV_1_float) \
+ /** current team */ i(float, MUTATOR_ARGV_2_float) \
+ /**/
+MUTATOR_HOOKABLE(Player_ChangedTeam, EV_Player_ChangedTeam);
+
+/**
+ * Called when player is about to be killed when changing teams. Return true to block killing.
+ */
+#define EV_Player_ChangeTeamKill(i, o) \
+ /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+ /**/
+MUTATOR_HOOKABLE(Player_ChangeTeamKill, EV_Player_ChangeTeamKill);
+
/**/
#define EV_URI_GetCallback(i, o) \
/** id */ i(float, MUTATOR_ARGV_0_float) \
#include "bot/api.qh"
#include "cheats.qh"
#include "g_damage.qh"
+#include "handicap.qh"
#include "g_subs.qh"
#include "miscfunctions.qh"
#include "portals.qh"
if(!DEATH_ISSPECIAL(deathtype))
{
- damage *= bound(1.0, CS(this).cvar_cl_handicap, 10.0);
- if(this != attacker && IS_PLAYER(attacker))
- damage /= bound(1.0, CS(attacker).cvar_cl_handicap, 10.0);
+ damage *= Handicap_GetTotalHandicap(this);
+ if (this != attacker && IS_PLAYER(attacker))
+ {
+ damage /= Handicap_GetTotalHandicap(attacker);
+ }
}
if (time < this.spawnshieldtime && autocvar_g_spawnshield_blockdamage < 1)
}
}
-void MoveToTeam(entity client, int team_colour, int type)
+bool MoveToTeam(entity client, int team_colour, int type)
{
int lockteams_backup = lockteams; // backup any team lock
lockteams = 0; // disable locked teams
TeamchangeFrags(client); // move the players frags
- SetPlayerColors(client, team_colour - 1); // set the players colour
+ if (!SetPlayerTeamSimple(client, team_colour))
+ {
+ return false;
+ }
Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0'); // kill the player
lockteams = lockteams_backup; // restore the team lock
LogTeamchange(client.playerid, client.team, type);
+ return true;
}
/** print(), but only print if the server is not local */
void ClientKill_Now_TeamChange(entity this);
-void MoveToTeam(entity client, float team_colour, float type);
+/// \brief Moves player to the specified team.
+/// \param[in,out] client Client to move.
+/// \param[in] team_colour Color of the team.
+/// \param[in] type ???
+/// \return True on success, false otherwise.
+bool MoveToTeam(entity client, float team_colour, float type);
void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force);
/// \author Lyberta
/// \copyright GNU GPLv2 or any later version.
+#include <common/resources.qh>
+
/// \brief Unconditional maximum amount of resources the entity can have.
const int RESOURCE_AMOUNT_HARD_LIMIT = 999;
bool TeamScore_SendEntity(entity this, entity to, float sendflags)
{
- float i, p, longflags;
+ float i, longflags;
WriteHeader(MSG_ENTITY, ENT_CLIENT_TEAMSCORES);
int t = this.team - 1;
WriteByte(MSG_ENTITY, t);
longflags = 0;
- for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
+ for(i = 0; i < MAX_TEAMSCORE; ++i)
if(this.(teamscores(i)) > 127 || this.(teamscores(i)) <= -128)
- longflags |= p;
+ longflags |= BIT(i);
#if MAX_TEAMSCORE <= 8
WriteByte(MSG_ENTITY, sendflags);
WriteShort(MSG_ENTITY, sendflags);
WriteShort(MSG_ENTITY, longflags);
#endif
- for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
- if(sendflags & p)
+ for(i = 0; i < MAX_TEAMSCORE; ++i)
+ if(sendflags & BIT(i))
{
- if(longflags & p)
+ if(longflags & BIT(i))
WriteInt24_t(MSG_ENTITY, this.(teamscores(i)));
else
WriteChar(MSG_ENTITY, this.(teamscores(i)));
s.SendFlags |= (2 ** (scorefield.m_id % 16));
if(!warmup_stage)
PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
- return (s.(scores(scorefield)) += score);
+ s.(scores(scorefield)) += score;
+ MUTATOR_CALLHOOK(AddedPlayerScore, scorefield, score, player);
+ return s.(scores(scorefield));
}
float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
#include "client.qh"
#include "scores.qh"
#include <common/gamemodes/rules.qh>
+#include "teamplay.qh"
int ScoreRules_teams;
this.dmgtime = 0;
}
this.air_finished = time + 12;
- this.dmg = 2;
}
}
void SV_OnEntityPreSpawnFunction(entity this)
{
- __spawnfunc_expecting = true;
- __spawnfunc_expect = this;
if (this)
if (this.gametypefilter != "")
if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, this.gametypefilter))
return;
LABEL(cleanup)
builtin_remove(this);
- __spawnfunc_expecting = false;
}
void WarpZone_PostInitialize_Callback()
int done = 0; for (int i = 0, n = numentityfields(); i < n; ++i) {
string k = entityfieldname(i); vector v = (k == "mins") ? mi_min : (k == "maxs") ? mi_max : '0 0 0';
if (v) {
- putentityfieldstring(i, world, sprintf("%d %d %d", v));
+ putentityfieldstring(i, world, sprintf("%v", v));
if (++done == 2) break;
}
}
#endif
}
-void SetPlayerColors(entity pl, float _color)
+void SetPlayerColors(entity player, float _color)
{
- /*string s;
- s = ftos(cl);
- stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
- pl.team = cl + 1;
- //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
- pl.clientcolors = 16*cl + cl;*/
-
- float pants, shirt;
- pants = _color & 0x0F;
- shirt = _color & 0xF0;
-
-
- if(teamplay) {
- setcolor(pl, 16*pants + pants);
- } else {
- setcolor(pl, shirt + pants);
+ float pants = _color & 0x0F;
+ float shirt = _color & 0xF0;
+ if (teamplay)
+ {
+ setcolor(player, 16 * pants + pants);
+ }
+ else
+ {
+ setcolor(player, shirt + pants);
}
}
-void SetPlayerTeam(entity pl, float t, float s, float noprint)
+void KillPlayerForTeamChange(entity player)
{
- float _color;
-
- if(t == 4)
- _color = NUM_TEAM_4 - 1;
- else if(t == 3)
- _color = NUM_TEAM_3 - 1;
- else if(t == 2)
- _color = NUM_TEAM_2 - 1;
- else
- _color = NUM_TEAM_1 - 1;
-
- SetPlayerColors(pl,_color);
-
- if(t != s) {
- LogTeamchange(pl.playerid, pl.team, 3); // log manual team join
+ if (IS_DEAD(player))
+ {
+ return;
+ }
+ if (MUTATOR_CALLHOOK(Player_ChangeTeamKill, player) == true)
+ {
+ return;
+ }
+ Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, player.origin,
+ '0 0 0');
+}
- if(!noprint)
- bprint(playername(pl, false), "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n");
+bool SetPlayerTeamSimple(entity player, int team_num)
+{
+ if (player.team == team_num)
+ {
+ // This is important when players join the game and one of their color
+ // matches the team color while other doesn't. For example [BOT]Lion.
+ SetPlayerColors(player, team_num - 1);
+ return true;
}
+ if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, Team_TeamToNumber(
+ player.team), Team_TeamToNumber(team_num)) == true)
+ {
+ // Mutator has blocked team change.
+ return false;
+ }
+ int old_team = player.team;
+ SetPlayerColors(player, team_num - 1);
+ MUTATOR_CALLHOOK(Player_ChangedTeam, player, old_team, player.team);
+ return true;
+}
+bool SetPlayerTeam(entity player, int destination_team, int source_team,
+ bool no_print)
+{
+ int team_num = Team_NumberToTeam(destination_team);
+ if (!SetPlayerTeamSimple(player, team_num))
+ {
+ return false;
+ }
+ LogTeamchange(player.playerid, player.team, 3); // log manual team join
+ if (no_print)
+ {
+ return true;
+ }
+ bprint(playername(player, false), "^7 has changed from ", Team_NumberToColoredFullName(source_team), "^7 to ", Team_NumberToColoredFullName(destination_team), "\n");
+ return true;
}
// set c1...c4 to show what teams are allowed
-void CheckAllowedTeams (entity for_whom)
+void CheckAllowedTeams(entity for_whom)
{
int teams_mask = 0;
c1 = c2 = c3 = c4 = -1;
- cb1 = cb2 = cb3 = cb4 = 0;
+ num_bots_team1 = num_bots_team2 = num_bots_team3 = num_bots_team4 = 0;
string teament_name = string_null;
// teams that are allowed will now have their player counts stored in c1...c4
void GetTeamCounts(entity ignore)
{
- float value, bvalue;
- // now count how many players are on each team already
-
- // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
- // also remember the lowest-scoring player
-
- FOREACH_CLIENT(true, {
- float t;
- if(IS_PLAYER(it) || it.caplayer)
- t = it.team;
- else if(it.team_forced > 0)
- t = it.team_forced; // reserve the spot
- else
- continue;
- if(it != ignore)// && it.netname != "")
+ if (MUTATOR_CALLHOOK(GetTeamCounts) == true)
+ {
+ if (c1 >= 0)
+ {
+ MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_1, ignore, c1,
+ num_bots_team1, lowest_human_team1, lowest_bot_team1);
+ c1 = M_ARGV(2, float);
+ num_bots_team1 = M_ARGV(3, float);
+ lowest_human_team1 = M_ARGV(4, entity);
+ lowest_bot_team1 = M_ARGV(5, entity);
+ }
+ if (c2 >= 0)
+ {
+ MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_2, ignore, c2,
+ num_bots_team2, lowest_human_team2, lowest_bot_team2);
+ c2 = M_ARGV(2, float);
+ num_bots_team2 = M_ARGV(3, float);
+ lowest_human_team2 = M_ARGV(4, entity);
+ lowest_bot_team2 = M_ARGV(5, entity);
+ }
+ if (c3 >= 0)
+ {
+ MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_3, ignore, c3,
+ num_bots_team3, lowest_human_team3, lowest_bot_team3);
+ c3 = M_ARGV(2, float);
+ num_bots_team3 = M_ARGV(3, float);
+ lowest_human_team3 = M_ARGV(4, entity);
+ lowest_bot_team3 = M_ARGV(5, entity);
+ }
+ if (c4 >= 0)
+ {
+ MUTATOR_CALLHOOK(GetTeamCount, NUM_TEAM_4, ignore,
+ c4, num_bots_team4, lowest_human_team4, lowest_bot_team4);
+ c4 = M_ARGV(2, float);
+ num_bots_team4 = M_ARGV(3, float);
+ lowest_human_team4 = M_ARGV(4, entity);
+ lowest_bot_team4 = M_ARGV(5, entity);
+ }
+ }
+ else
+ {
+ float value, bvalue;
+ // now count how many players are on each team already
+ float lowest_human_score1 = FLOAT_MAX;
+ float lowest_bot_score1 = FLOAT_MAX;
+ float lowest_human_score2 = FLOAT_MAX;
+ float lowest_bot_score2 = FLOAT_MAX;
+ float lowest_human_score3 = FLOAT_MAX;
+ float lowest_bot_score3 = FLOAT_MAX;
+ float lowest_human_score4 = FLOAT_MAX;
+ float lowest_bot_score4 = FLOAT_MAX;
+ FOREACH_CLIENT(true,
{
+ float t;
+ if (IS_PLAYER(it) || it.caplayer)
+ {
+ t = it.team;
+ }
+ else if (it.team_forced > 0)
+ {
+ t = it.team_forced; // reserve the spot
+ }
+ else
+ {
+ continue;
+ }
+ if (it == ignore)
+ {
+ continue;
+ }
value = PlayerValue(it);
- if(IS_BOT_CLIENT(it))
+ if (IS_BOT_CLIENT(it))
+ {
bvalue = value;
+ }
else
+ {
bvalue = 0;
- if(t == NUM_TEAM_1)
+ }
+ if (value == 0)
{
- if(c1 >= 0)
- {
- c1 = c1 + value;
- cb1 = cb1 + bvalue;
- }
+ continue;
}
- else if(t == NUM_TEAM_2)
+ switch (t)
{
- if(c2 >= 0)
+ case NUM_TEAM_1:
{
- c2 = c2 + value;
- cb2 = cb2 + bvalue;
+ if (c1 < 0)
+ {
+ break;
+ }
+ c1 += value;
+ num_bots_team1 += bvalue;
+ float temp_score = PlayerScore_Get(it, SP_SCORE);
+ if (!bvalue)
+ {
+ if (temp_score < lowest_human_score1)
+ {
+ lowest_human_team1 = it;
+ lowest_human_score1 = temp_score;
+ }
+ break;
+ }
+ if (temp_score < lowest_bot_score1)
+ {
+ lowest_bot_team1 = it;
+ lowest_bot_score1 = temp_score;
+ }
+ break;
}
- }
- else if(t == NUM_TEAM_3)
- {
- if(c3 >= 0)
+ case NUM_TEAM_2:
{
- c3 = c3 + value;
- cb3 = cb3 + bvalue;
+ if (c2 < 0)
+ {
+ break;
+ }
+ c2 += value;
+ num_bots_team2 += bvalue;
+ float temp_score = PlayerScore_Get(it, SP_SCORE);
+ if (!bvalue)
+ {
+ if (temp_score < lowest_human_score2)
+ {
+ lowest_human_team2 = it;
+ lowest_human_score2 = temp_score;
+ }
+ break;
+ }
+ if (temp_score < lowest_bot_score2)
+ {
+ lowest_bot_team2 = it;
+ lowest_bot_score2 = temp_score;
+ }
+ break;
}
- }
- else if(t == NUM_TEAM_4)
- {
- if(c4 >= 0)
+ case NUM_TEAM_3:
+ {
+ if (c3 < 0)
+ {
+ break;
+ }
+ c3 += value;
+ num_bots_team3 += bvalue;
+ float temp_score = PlayerScore_Get(it, SP_SCORE);
+ if (!bvalue)
+ {
+ if (temp_score < lowest_human_score3)
+ {
+ lowest_human_team3 = it;
+ lowest_human_score3 = temp_score;
+ }
+ break;
+ }
+ if (temp_score < lowest_bot_score3)
+ {
+ lowest_bot_team3 = it;
+ lowest_bot_score3 = temp_score;
+ }
+ break;
+ }
+ case NUM_TEAM_4:
{
- c4 = c4 + value;
- cb4 = cb4 + bvalue;
+ if (c4 < 0)
+ {
+ break;
+ }
+ c4 += value;
+ num_bots_team4 += bvalue;
+ float temp_score = PlayerScore_Get(it, SP_SCORE);
+ if (!bvalue)
+ {
+ if (temp_score < lowest_human_score4)
+ {
+ lowest_human_team4 = it;
+ lowest_human_score4 = temp_score;
+ }
+ break;
+ }
+ if (temp_score < lowest_bot_score4)
+ {
+ lowest_bot_team4 = it;
+ lowest_bot_score4 = temp_score;
+ }
+ break;
}
}
- }
- });
+ });
+ }
// if the player who has a forced team has not joined yet, reserve the spot
if(autocvar_g_campaign)
{
switch(autocvar_g_campaign_forceteam)
{
- case 1: if(c1 == cb1) ++c1; break;
- case 2: if(c2 == cb2) ++c2; break;
- case 3: if(c3 == cb3) ++c3; break;
- case 4: if(c4 == cb4) ++c4; break;
+ case 1: if(c1 == num_bots_team1) ++c1; break;
+ case 2: if(c2 == num_bots_team2) ++c2; break;
+ case 3: if(c3 == num_bots_team3) ++c3; break;
+ case 4: if(c4 == num_bots_team4) ++c4; break;
}
}
}
-float TeamSmallerEqThanTeam(float ta, float tb, entity e)
+bool IsTeamSmallerThanTeam(int team_a, int team_b, entity player,
+ bool use_score)
{
+ if (team_a == team_b)
+ {
+ return false;
+ }
// we assume that CheckAllowedTeams and GetTeamCounts have already been called
- float f;
- float ca = -1, cb = -1, cba = 0, cbb = 0, sa = 0, sb = 0;
-
- switch(ta)
+ int num_players_team_a = -1, num_players_team_b = -1;
+ int num_bots_team_a = 0, num_bots_team_b = 0;
+ float score_team_a = 0, score_team_b = 0;
+ switch (team_a)
{
- case 1: ca = c1; cba = cb1; sa = team1_score; break;
- case 2: ca = c2; cba = cb2; sa = team2_score; break;
- case 3: ca = c3; cba = cb3; sa = team3_score; break;
- case 4: ca = c4; cba = cb4; sa = team4_score; break;
+ case 1:
+ {
+ num_players_team_a = c1;
+ num_bots_team_a = num_bots_team1;
+ score_team_a = team1_score;
+ break;
+ }
+ case 2:
+ {
+ num_players_team_a = c2;
+ num_bots_team_a = num_bots_team2;
+ score_team_a = team2_score;
+ break;
+ }
+ case 3:
+ {
+ num_players_team_a = c3;
+ num_bots_team_a = num_bots_team3;
+ score_team_a = team3_score;
+ break;
+ }
+ case 4:
+ {
+ num_players_team_a = c4;
+ num_bots_team_a = num_bots_team4;
+ score_team_a = team4_score;
+ break;
+ }
}
- switch(tb)
+ switch (team_b)
{
- case 1: cb = c1; cbb = cb1; sb = team1_score; break;
- case 2: cb = c2; cbb = cb2; sb = team2_score; break;
- case 3: cb = c3; cbb = cb3; sb = team3_score; break;
- case 4: cb = c4; cbb = cb4; sb = team4_score; break;
+ case 1:
+ {
+ num_players_team_b = c1;
+ num_bots_team_b = num_bots_team1;
+ score_team_b = team1_score;
+ break;
+ }
+ case 2:
+ {
+ num_players_team_b = c2;
+ num_bots_team_b = num_bots_team2;
+ score_team_b = team2_score;
+ break;
+ }
+ case 3:
+ {
+ num_players_team_b = c3;
+ num_bots_team_b = num_bots_team3;
+ score_team_b = team3_score;
+ break;
+ }
+ case 4:
+ {
+ num_players_team_b = c4;
+ num_bots_team_b = num_bots_team4;
+ score_team_b = team4_score;
+ break;
+ }
}
-
// invalid
- if(ca < 0 || cb < 0)
+ if (num_players_team_a < 0 || num_players_team_b < 0)
+ {
return false;
-
- // equal
- if(ta == tb)
+ }
+ if (IS_REAL_CLIENT(player) && bots_would_leave)
+ {
+ num_players_team_a -= num_bots_team_a;
+ num_players_team_b -= num_bots_team_b;
+ }
+ if (!use_score)
+ {
+ return num_players_team_a < num_players_team_b;
+ }
+ if (num_players_team_a < num_players_team_b)
+ {
return true;
+ }
+ if (num_players_team_a > num_players_team_b)
+ {
+ return false;
+ }
+ return score_team_a < score_team_b;
+}
- if(IS_REAL_CLIENT(e))
+bool IsTeamEqualToTeam(int team_a, int team_b, entity player, bool use_score)
+{
+ if (team_a == team_b)
{
- if(bots_would_leave)
+ return true;
+ }
+ // we assume that CheckAllowedTeams and GetTeamCounts have already been called
+ int num_players_team_a = -1, num_players_team_b = -1;
+ int num_bots_team_a = 0, num_bots_team_b = 0;
+ float score_team_a = 0, score_team_b = 0;
+ switch (team_a)
+ {
+ case 1:
{
- ca -= cba * 0.999;
- cb -= cbb * 0.999;
+ num_players_team_a = c1;
+ num_bots_team_a = num_bots_team1;
+ score_team_a = team1_score;
+ break;
+ }
+ case 2:
+ {
+ num_players_team_a = c2;
+ num_bots_team_a = num_bots_team2;
+ score_team_a = team2_score;
+ break;
+ }
+ case 3:
+ {
+ num_players_team_a = c3;
+ num_bots_team_a = num_bots_team3;
+ score_team_a = team3_score;
+ break;
+ }
+ case 4:
+ {
+ num_players_team_a = c4;
+ num_bots_team_a = num_bots_team4;
+ score_team_a = team4_score;
+ break;
}
}
+ switch (team_b)
+ {
+ case 1:
+ {
+ num_players_team_b = c1;
+ num_bots_team_b = num_bots_team1;
+ score_team_b = team1_score;
+ break;
+ }
+ case 2:
+ {
+ num_players_team_b = c2;
+ num_bots_team_b = num_bots_team2;
+ score_team_b = team2_score;
+ break;
+ }
+ case 3:
+ {
+ num_players_team_b = c3;
+ num_bots_team_b = num_bots_team3;
+ score_team_b = team3_score;
+ break;
+ }
+ case 4:
+ {
+ num_players_team_b = c4;
+ num_bots_team_b = num_bots_team4;
+ score_team_b = team4_score;
+ break;
+ }
+ }
+ // invalid
+ if (num_players_team_a < 0 || num_players_team_b < 0)
+ return false;
- // keep teams alive (teams of size 0 always count as smaller, ignoring score)
- if(ca < 1)
- if(cb >= 1)
- return true;
- if(ca >= 1)
- if(cb < 1)
- return false;
-
- // first, normalize
- f = max(ca, cb, 1);
- ca /= f;
- cb /= f;
- f = max(sa, sb, 1);
- sa /= f;
- sb /= f;
-
- // the more we're at the end of the match, the more take scores into account
- f = bound(0, game_completion_ratio * autocvar_g_balance_teams_scorefactor, 1);
- ca += (sa - ca) * f;
- cb += (sb - cb) * f;
+ if (IS_REAL_CLIENT(player) && bots_would_leave)
+ {
+ num_players_team_a -= num_bots_team_a;
+ num_players_team_b -= num_bots_team_b;
+ }
+ if (!use_score)
+ {
+ return num_players_team_a == num_players_team_b;
+ }
+ if (num_players_team_a != num_players_team_b)
+ {
+ return false;
+ }
+ return score_team_a == score_team_b;
+}
- return ca <= cb;
+int FindBestTeams(entity player, bool use_score)
+{
+ if (MUTATOR_CALLHOOK(FindBestTeams, player) == true)
+ {
+ return M_ARGV(1, float);
+ }
+ int team_bits = 0;
+ int previous_team = 0;
+ if (c1 >= 0)
+ {
+ team_bits = BIT(0);
+ previous_team = 1;
+ }
+ if (c2 >= 0)
+ {
+ if (previous_team == 0)
+ {
+ team_bits = BIT(1);
+ previous_team = 2;
+ }
+ else if (IsTeamSmallerThanTeam(2, previous_team, player, use_score))
+ {
+ team_bits = BIT(1);
+ previous_team = 2;
+ }
+ else if (IsTeamEqualToTeam(2, previous_team, player, use_score))
+ {
+ team_bits |= BIT(1);
+ previous_team = 2;
+ }
+ }
+ if (c3 >= 0)
+ {
+ if (previous_team == 0)
+ {
+ team_bits = BIT(2);
+ previous_team = 3;
+ }
+ else if (IsTeamSmallerThanTeam(3, previous_team, player, use_score))
+ {
+ team_bits = BIT(2);
+ previous_team = 3;
+ }
+ else if (IsTeamEqualToTeam(3, previous_team, player, use_score))
+ {
+ team_bits |= BIT(2);
+ previous_team = 3;
+ }
+ }
+ if (c4 >= 0)
+ {
+ if (previous_team == 0)
+ {
+ team_bits = BIT(3);
+ }
+ else if (IsTeamSmallerThanTeam(4, previous_team, player, use_score))
+ {
+ team_bits = BIT(3);
+ }
+ else if (IsTeamEqualToTeam(4, previous_team, player, use_score))
+ {
+ team_bits |= BIT(3);
+ }
+ }
+ return team_bits;
}
// returns # of smallest team (1, 2, 3, 4)
// NOTE: Assumes CheckAllowedTeams has already been called!
-float FindSmallestTeam(entity pl, float ignore_pl)
+int FindSmallestTeam(entity player, float ignore_player)
{
- int totalteams = 0;
- int t = 1; // initialize with a random team?
- if(c4 >= 0) t = 4;
- if(c3 >= 0) t = 3;
- if(c2 >= 0) t = 2;
- if(c1 >= 0) t = 1;
-
- // find out what teams are available
- //CheckAllowedTeams();
-
- // make sure there are at least 2 teams to join
- if(c1 >= 0)
- totalteams = totalteams + 1;
- if(c2 >= 0)
- totalteams = totalteams + 1;
- if(c3 >= 0)
- totalteams = totalteams + 1;
- if(c4 >= 0)
- totalteams = totalteams + 1;
-
- if((autocvar_bot_vs_human || pl.team_forced > 0) && totalteams == 1)
- totalteams += 1;
-
- if(totalteams <= 1)
+ // count how many players are in each team
+ if (ignore_player)
{
- if(autocvar_g_campaign && pl && IS_REAL_CLIENT(pl))
- return 1; // special case for campaign and player joining
- else if(totalteams == 1) // single team
- LOG_TRACEF("Only 1 team available for %s, you may need to fix your map", MapInfo_Type_ToString(MapInfo_CurrentGametype()));
- else // no teams, major no no
- error(sprintf("No teams available for %s\n", MapInfo_Type_ToString(MapInfo_CurrentGametype())));
+ GetTeamCounts(player);
}
-
- // count how many players are in each team
- if(ignore_pl)
- GetTeamCounts(pl);
else
+ {
GetTeamCounts(NULL);
-
+ }
+ int team_bits = FindBestTeams(player, true);
+ if (team_bits == 0)
+ {
+ error(sprintf("No teams available for %s\n", MapInfo_Type_ToString(MapInfo_CurrentGametype())));
+ }
RandomSelection_Init();
-
- if(TeamSmallerEqThanTeam(1, t, pl))
- t = 1;
- if(TeamSmallerEqThanTeam(2, t, pl))
- t = 2;
- if(TeamSmallerEqThanTeam(3, t, pl))
- t = 3;
- if(TeamSmallerEqThanTeam(4, t, pl))
- t = 4;
-
- // now t is the minimum, or A minimum!
- if(t == 1 || TeamSmallerEqThanTeam(1, t, pl))
+ if ((team_bits & BIT(0)) != 0)
+ {
RandomSelection_AddFloat(1, 1, 1);
- if(t == 2 || TeamSmallerEqThanTeam(2, t, pl))
+ }
+ if ((team_bits & BIT(1)) != 0)
+ {
RandomSelection_AddFloat(2, 1, 1);
- if(t == 3 || TeamSmallerEqThanTeam(3, t, pl))
+ }
+ if ((team_bits & BIT(2)) != 0)
+ {
RandomSelection_AddFloat(3, 1, 1);
- if(t == 4 || TeamSmallerEqThanTeam(4, t, pl))
+ }
+ if ((team_bits & BIT(3)) != 0)
+ {
RandomSelection_AddFloat(4, 1, 1);
-
+ }
return RandomSelection_chosen_float;
}
-int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
+int JoinBestTeam(entity this, bool only_return_best, bool force_best_team)
{
- float smallest, selectedteam;
-
// don't join a team if we're not playing a team game
- if(!teamplay)
+ if (!teamplay)
+ {
return 0;
+ }
// find out what teams are available
CheckAllowedTeams(this);
// if we don't care what team he ends up on, put him on whatever team he entered as.
// if he's not on a valid team, then let other code put him on the smallest team
- if(!forcebestteam)
+ if (!force_best_team)
{
+ int selected_team;
if( c1 >= 0 && this.team == NUM_TEAM_1)
- selectedteam = this.team;
+ selected_team = this.team;
else if(c2 >= 0 && this.team == NUM_TEAM_2)
- selectedteam = this.team;
+ selected_team = this.team;
else if(c3 >= 0 && this.team == NUM_TEAM_3)
- selectedteam = this.team;
+ selected_team = this.team;
else if(c4 >= 0 && this.team == NUM_TEAM_4)
- selectedteam = this.team;
+ selected_team = this.team;
else
- selectedteam = -1;
+ selected_team = -1;
- if(selectedteam > 0)
+ if (selected_team > 0)
{
- if(!only_return_best)
+ if (!only_return_best)
{
- SetPlayerColors(this, selectedteam - 1);
+ SetPlayerTeamSimple(this, selected_team);
// when JoinBestTeam is called by client.qc/ClientKill_Now_TeamChange the players team is -1 and thus skipped
// when JoinBestTeam is called by client.qc/ClientConnect the player_id is 0 the log attempt is rejected
LogTeamchange(this.playerid, this.team, 99);
}
- return selectedteam;
+ return selected_team;
}
// otherwise end up on the smallest team (handled below)
}
- smallest = FindSmallestTeam(this, true);
-
- if(!only_return_best && !this.bot_forced_team)
+ int best_team = FindSmallestTeam(this, true);
+ if (only_return_best || this.bot_forced_team)
{
- TeamchangeFrags(this);
- if(smallest == 1)
- {
- SetPlayerColors(this, NUM_TEAM_1 - 1);
- }
- else if(smallest == 2)
- {
- SetPlayerColors(this, NUM_TEAM_2 - 1);
- }
- else if(smallest == 3)
- {
- SetPlayerColors(this, NUM_TEAM_3 - 1);
- }
- else if(smallest == 4)
- {
- SetPlayerColors(this, NUM_TEAM_4 - 1);
- }
- else
- {
- error("smallest team: invalid team\n");
- }
-
- LogTeamchange(this.playerid, this.team, 2); // log auto join
-
- if(!IS_DEAD(this))
- Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
+ return best_team;
}
-
- return smallest;
+ best_team = Team_NumberToTeam(best_team);
+ if (best_team == -1)
+ {
+ error("JoinBestTeam: invalid team\n");
+ }
+ int old_team = Team_TeamToNumber(this.team);
+ TeamchangeFrags(this);
+ SetPlayerTeamSimple(this, best_team);
+ LogTeamchange(this.playerid, this.team, 2); // log auto join
+ if (!IS_BOT_CLIENT(this))
+ {
+ AutoBalanceBots(old_team, Team_TeamToNumber(best_team));
+ }
+ KillPlayerForTeamChange(this);
+ return best_team;
}
-//void() ctf_playerchanged;
void SV_ChangeTeam(entity this, float _color)
{
- float scolor, dcolor, steam, dteam; //, dbotcount, scount, dcount;
+ float source_color, destination_color, source_team, destination_team;
// in normal deathmatch we can just apply the color and we're done
if(!teamplay)
if(!teamplay)
return;
- scolor = this.clientcolors & 0x0F;
- dcolor = _color & 0x0F;
-
- if(scolor == NUM_TEAM_1 - 1)
- steam = 1;
- else if(scolor == NUM_TEAM_2 - 1)
- steam = 2;
- else if(scolor == NUM_TEAM_3 - 1)
- steam = 3;
- else // if(scolor == NUM_TEAM_4 - 1)
- steam = 4;
- if(dcolor == NUM_TEAM_1 - 1)
- dteam = 1;
- else if(dcolor == NUM_TEAM_2 - 1)
- dteam = 2;
- else if(dcolor == NUM_TEAM_3 - 1)
- dteam = 3;
- else // if(dcolor == NUM_TEAM_4 - 1)
- dteam = 4;
+ source_color = this.clientcolors & 0x0F;
+ destination_color = _color & 0x0F;
+
+ source_team = Team_TeamToNumber(source_color + 1);
+ destination_team = Team_TeamToNumber(destination_color + 1);
CheckAllowedTeams(this);
- if(dteam == 1 && c1 < 0) dteam = 4;
- if(dteam == 4 && c4 < 0) dteam = 3;
- if(dteam == 3 && c3 < 0) dteam = 2;
- if(dteam == 2 && c2 < 0) dteam = 1;
+ if (destination_team == 1 && c1 < 0) destination_team = 4;
+ if (destination_team == 4 && c4 < 0) destination_team = 3;
+ if (destination_team == 3 && c3 < 0) destination_team = 2;
+ if (destination_team == 2 && c2 < 0) destination_team = 1;
// not changing teams
- if(scolor == dcolor)
+ if (source_color == destination_color)
{
- //bprint("same team change\n");
- SetPlayerTeam(this, dteam, steam, true);
+ SetPlayerTeam(this, destination_team, source_team, true);
return;
}
}
// autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless
- if(autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
+ if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
{
GetTeamCounts(this);
- if(!TeamSmallerEqThanTeam(dteam, steam, this))
+ if ((BIT(destination_team - 1) & FindBestTeams(this, false)) == 0)
{
Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
return;
}
}
-
-// bprint("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n");
-
- if(IS_PLAYER(this) && steam != dteam)
+ if(IS_PLAYER(this) && source_team != destination_team)
{
// reduce frags during a team change
TeamchangeFrags(this);
}
-
- MUTATOR_CALLHOOK(Player_ChangeTeam, this, steam, dteam);
-
- SetPlayerTeam(this, dteam, steam, !IS_CLIENT(this));
-
- if(IS_PLAYER(this) && steam != dteam)
+ if (!SetPlayerTeam(this, destination_team, source_team, !IS_CLIENT(this)))
+ {
+ return;
+ }
+ AutoBalanceBots(source_team, destination_team);
+ if (!IS_PLAYER(this) || (source_team == destination_team))
{
- // kill player when changing teams
- if(!IS_DEAD(this))
- Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
+ return;
}
+ KillPlayerForTeamChange(this);
}
-void ShufflePlayerOutOfTeam (float source_team)
+void AutoBalanceBots(int source_team, int destination_team)
{
- float smallestteam, smallestteam_count, steam;
- float lowest_bot_score, lowest_player_score;
- entity lowest_bot, lowest_player, selected;
-
- smallestteam = 0;
- smallestteam_count = 999999999;
-
- if(c1 >= 0 && c1 < smallestteam_count)
- {
- smallestteam = 1;
- smallestteam_count = c1;
- }
- if(c2 >= 0 && c2 < smallestteam_count)
- {
- smallestteam = 2;
- smallestteam_count = c2;
- }
- if(c3 >= 0 && c3 < smallestteam_count)
+ if ((source_team == -1) || (destination_team == -1))
{
- smallestteam = 3;
- smallestteam_count = c3;
+ return;
}
- if(c4 >= 0 && c4 < smallestteam_count)
+ if (!autocvar_g_balance_teams ||
+ !autocvar_g_balance_teams_prevent_imbalance)
{
- smallestteam = 4;
- smallestteam_count = c4;
- }
-
- if(!smallestteam)
- {
- bprint("warning: no smallest team\n");
return;
}
-
- if(source_team == 1)
- steam = NUM_TEAM_1;
- else if(source_team == 2)
- steam = NUM_TEAM_2;
- else if(source_team == 3)
- steam = NUM_TEAM_3;
- else // if(source_team == 4)
- steam = NUM_TEAM_4;
-
- lowest_bot = NULL;
- lowest_bot_score = 999999999;
- lowest_player = NULL;
- lowest_player_score = 999999999;
-
- // find the lowest-scoring player & bot of that team
- FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, {
- if(it.isbot)
+ int num_players_source_team = 0;
+ int num_players_destination_team = 0;
+ entity lowest_bot_destination_team = NULL;
+ switch (source_team)
+ {
+ case 1:
{
- if(it.totalfrags < lowest_bot_score)
- {
- lowest_bot = it;
- lowest_bot_score = it.totalfrags;
- }
+ num_players_source_team = c1;
+ break;
}
- else
+ case 2:
{
- if(it.totalfrags < lowest_player_score)
- {
- lowest_player = it;
- lowest_player_score = it.totalfrags;
- }
+ num_players_source_team = c2;
+ break;
+ }
+ case 3:
+ {
+ num_players_source_team = c3;
+ break;
+ }
+ case 4:
+ {
+ num_players_source_team = c4;
+ break;
}
- });
-
- // prefers to move a bot...
- if(lowest_bot != NULL)
- selected = lowest_bot;
- // but it will move a player if it has to
- else
- selected = lowest_player;
- // don't do anything if it couldn't find anyone
- if(!selected)
- {
- bprint("warning: couldn't find a player to move from team\n");
- return;
- }
-
- // smallest team gains a member
- if(smallestteam == 1)
- {
- c1 = c1 + 1;
- }
- else if(smallestteam == 2)
- {
- c2 = c2 + 1;
- }
- else if(smallestteam == 3)
- {
- c3 = c3 + 1;
- }
- else if(smallestteam == 4)
- {
- c4 = c4 + 1;
- }
- else
- {
- bprint("warning: destination team invalid\n");
- return;
- }
- // source team loses a member
- if(source_team == 1)
- {
- c1 = c1 + 1;
- }
- else if(source_team == 2)
- {
- c2 = c2 + 2;
- }
- else if(source_team == 3)
- {
- c3 = c3 + 3;
}
- else if(source_team == 4)
+ switch (destination_team)
{
- c4 = c4 + 4;
+ case 1:
+ {
+ num_players_destination_team = c1;
+ lowest_bot_destination_team = lowest_bot_team1;
+ break;
+ }
+ case 2:
+ {
+ num_players_destination_team = c2;
+ lowest_bot_destination_team = lowest_bot_team2;
+ break;
+ }
+ case 3:
+ {
+ num_players_destination_team = c3;
+ lowest_bot_destination_team = lowest_bot_team3;
+ break;
+ }
+ case 4:
+ {
+ num_players_destination_team = c4;
+ lowest_bot_destination_team = lowest_bot_team4;
+ break;
+ }
}
- else
+ if ((num_players_destination_team <= num_players_source_team) ||
+ (lowest_bot_destination_team == NULL))
{
- bprint("warning: source team invalid\n");
return;
}
-
- // move the player to the new team
- TeamchangeFrags(selected);
- SetPlayerTeam(selected, smallestteam, source_team, false);
-
- if(!IS_DEAD(selected))
- Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
- Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);
+ SetPlayerTeamSimple(lowest_bot_destination_team,
+ Team_NumberToTeam(source_team));
+ KillPlayerForTeamChange(lowest_bot_destination_team);
}
string cache_mutatormsg;
string cache_lastmutatormsg;
-// client counts for each team
-//float c1, c2, c3, c4;
-// # of bots on those teams
-float cb1, cb2, cb3, cb4;
+// The following variables are used for balancing. They are not updated
+// automatically. You need to call CheckAllowedTeams and GetTeamCounts to get
+// proper values.
+
+// These four have 2 different states. If they are equal to -1, it means that
+// the player can't join the team. Zero or positive value means that player can
+// join the team and means the number of players on that team.
+float c1;
+float c2;
+float c3;
+float c4;
+float num_bots_team1; ///< Number of bots in the first team.
+float num_bots_team2; ///< Number of bots in the second team.
+float num_bots_team3; ///< Number of bots in the third team.
+float num_bots_team4; ///< Number of bots in the fourth team.
+entity lowest_human_team1; ///< Human with the lowest score in the first team.
+entity lowest_human_team2; ///< Human with the lowest score in the second team.
+entity lowest_human_team3; ///< Human with the lowest score in the third team.
+entity lowest_human_team4; ///< Human with the lowest score in the fourth team.
+entity lowest_bot_team1; ///< Bot with the lowest score in the first team.
+entity lowest_bot_team2; ///< Bot with the lowest score in the second team.
+entity lowest_bot_team3; ///< Bot with the lowest score in the third team.
+entity lowest_bot_team4; ///< Bot with the lowest score in the fourth team.
int redowned, blueowned, yellowowned, pinkowned;
string getwelcomemessage(entity this);
-void SetPlayerColors(entity pl, float _color);
+void SetPlayerColors(entity player, float _color);
-void SetPlayerTeam(entity pl, float t, float s, float noprint);
+/// \brief Kills player as a result of team change.
+/// \param[in,out] player Player to kill.
+/// \return No return.
+void KillPlayerForTeamChange(entity player);
+
+/// \brief Sets the team of the player.
+/// \param[in,out] player Player to adjust.
+/// \param[in] team_num Team number to set. See TEAM_NUM constants.
+/// \return True if team switch was successful, false otherwise.
+bool SetPlayerTeamSimple(entity player, int team_num);
+
+/// \brief Sets the team of the player.
+/// \param[in,out] player Player to adjust.
+/// \param[in] destination_team Team to set.
+/// \param[in] source_team Previous team of the player.
+/// \param[in] no_print Whether to print this event to players' console.
+/// \return True if team switch was successful, false otherwise.
+bool SetPlayerTeam(entity player, int destination_team, int source_team,
+ bool no_print);
// set c1...c4 to show what teams are allowed
-void CheckAllowedTeams (entity for_whom);
+void CheckAllowedTeams(entity for_whom);
float PlayerValue(entity p);
// teams that are allowed will now have their player counts stored in c1...c4
void GetTeamCounts(entity ignore);
-float TeamSmallerEqThanTeam(float ta, float tb, entity e);
+/// \brief Returns whether one team is smaller than the other.
+/// \param[in] team_a First team.
+/// \param[in] team_b Second team.
+/// \param[in] player Player to check.
+/// \param[in] use_score Whether to take into account team scores.
+/// \return True if first team is smaller than the second one, false otherwise.
+/// \note This function assumes that CheckAllowedTeams and GetTeamCounts have
+/// been called.
+bool IsTeamSmallerThanTeam(int team_a, int team_b, entity player,
+ bool use_score);
+
+/// \brief Returns whether one team is equal to the other.
+/// \param[in] team_a First team.
+/// \param[in] team_b Second team.
+/// \param[in] player Player to check.
+/// \param[in] use_score Whether to take into account team scores.
+/// \return True if first team is equal to the second one, false otherwise.
+/// \note This function assumes that CheckAllowedTeams and GetTeamCounts have
+/// been called.
+bool IsTeamEqualToTeam(int team_a, int team_b, entity player, bool use_score);
+
+/// \brief Returns the bitmask of the best teams for the player to join.
+/// \param[in] player Player to check.
+/// \param[in] use_score Whether to take into account team scores.
+/// \return Bitmask of the best teams for the player to join.
+/// \note This function assumes that CheckAllowedTeams and GetTeamCounts have
+/// been called.
+int FindBestTeams(entity player, bool use_score);
// returns # of smallest team (1, 2, 3, 4)
// NOTE: Assumes CheckAllowedTeams has already been called!
-float FindSmallestTeam(entity pl, float ignore_pl);
-
-int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam);
+int FindSmallestTeam(entity player, float ignore_player);
-//void() ctf_playerchanged;
+int JoinBestTeam(entity this, bool only_return_best, bool force_best_team);
-void ShufflePlayerOutOfTeam (float source_team);
+/// \brief Auto balances bots in teams after the player has changed team.
+/// \param[in] source_team Previous team of the player (1, 2, 3, 4).
+/// \param[in] destination_team Current team of the player (1, 2, 3, 4).
+/// \return No return.
+/// \note This function assumes that CheckAllowedTeams and GetTeamCounts have
+/// been called.
+void AutoBalanceBots(int source_team, int destination_team);
void setcolor(entity this, int clr);
} \
} MACRO_END
-#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), body)
+#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), LAMBDA(body))
// using the "inside out" version of knuth-fisher-yates shuffle
// https://en.wikipedia.org/wiki/Fisher–Yates_shuffle
this.superweapons_finished = autocvar_g_balance_superweapons_time;
// if we don't already have ammo, give us some ammo
- if (!GetResourceAmount(this, wpn.ammo_type))
+ if ((wpn.ammo_type != RESOURCE_NONE) && !GetResourceAmount(this, wpn.ammo_type))
{
switch (wpn.ammo_type)
{