X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fmutators%2Fmutator%2Fgamemode_keyhunt.qc;h=d3ec3358e9a62f8ffbe294d42e85b1ce10fac31b;hb=451e02a2857d8c671f6dcf6a0639ea7c609b3ba9;hp=448a2bbc78c47d1d905de3a9d13910e71a987e74;hpb=f6dd336135aa93ee4617df2389c3bfb28f0e1c58;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc index 448a2bbc7..d3ec3358e 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc @@ -1,66 +1,12 @@ #include "gamemode_keyhunt.qh" -#ifndef GAMEMODE_KEYHUNT_H -#define GAMEMODE_KEYHUNT_H - -#define autocvar_g_keyhunt_point_limit cvar("g_keyhunt_point_limit") -int autocvar_g_keyhunt_point_leadlimit; -bool autocvar_g_keyhunt_team_spawns; -void kh_Initialize(); - -REGISTER_MUTATOR(kh, false) -{ - MUTATOR_ONADD - { - if (time > 1) // game loads at time 1 - error("This is a game type and it cannot be added at runtime."); - kh_Initialize(); - - ActivateTeamplay(); - SetLimits(autocvar_g_keyhunt_point_limit, autocvar_g_keyhunt_point_leadlimit, autocvar_timelimit_override, -1); - if (autocvar_g_keyhunt_team_spawns) - have_team_spawns = -1; // request team spawns - } - - MUTATOR_ONROLLBACK_OR_REMOVE - { - // we actually cannot roll back kh_Initialize here - // BUT: we don't need to! If this gets called, adding always - // succeeds. - } - - MUTATOR_ONREMOVE - { - LOG_INFO("This is a game type and it cannot be removed at runtime."); - return -1; - } - - return 0; -} - -#define FOR_EACH_KH_KEY(v) for(v = kh_worldkeylist; v; v = v.kh_worldkeynext ) - -// ALL OF THESE should be removed in the future, as other code should not have to care - -// used by bots: -float kh_tracking_enabled; -.entity kh_next; -float kh_Key_AllOwnedByWhichTeam(); - -USING(kh_Think_t, void()); -void kh_StartRound(); -void kh_Controller_SetThink(float t, kh_Think_t func); - -entity kh_worldkeylist; -.entity kh_worldkeynext; -#endif - -#ifdef IMPLEMENTATION float autocvar_g_balance_keyhunt_damageforcescale; float autocvar_g_balance_keyhunt_delay_collect; +float autocvar_g_balance_keyhunt_delay_damage_return; float autocvar_g_balance_keyhunt_delay_return; float autocvar_g_balance_keyhunt_delay_round; float autocvar_g_balance_keyhunt_delay_tracking; +float autocvar_g_balance_keyhunt_return_when_unreachable; float autocvar_g_balance_keyhunt_dropvelocity; float autocvar_g_balance_keyhunt_maxdist; float autocvar_g_balance_keyhunt_protecttime; @@ -73,7 +19,7 @@ int autocvar_g_balance_keyhunt_score_destroyed_ownfactor; int autocvar_g_balance_keyhunt_score_push; float autocvar_g_balance_keyhunt_throwvelocity; -int autocvar_g_keyhunt_teams; +//int autocvar_g_keyhunt_teams; int autocvar_g_keyhunt_teams_override; // #define KH_PLAYER_USE_ATTACHMENT @@ -96,24 +42,24 @@ const vector KH_KEY_MIN = '-10 -10 -46'; const vector KH_KEY_MAX = '10 10 3'; const float KH_KEY_BRIGHTNESS = 2; -float kh_no_radar_circles; +bool kh_no_radar_circles; // kh_state // bits 0- 4: team of key 1, or 0 for no such key, or 30 for dropped, or 31 for self // bits 5- 9: team of key 2, or 0 for no such key, or 30 for dropped, or 31 for self // bits 10-14: team of key 3, or 0 for no such key, or 30 for dropped, or 31 for self // bits 15-19: team of key 4, or 0 for no such key, or 30 for dropped, or 31 for self -.float kh_state = _STAT(KH_KEYS); +.int kh_state = _STAT(KH_KEYS); .float siren_time; // time delay the siren //.float stuff_time; // time delay to stuffcmd a cvar -float kh_keystatus[17]; +int kh_keystatus[17]; //kh_keystatus[0] = status of dropped keys, kh_keystatus[1 - 16] = player # //replace 17 with cvar("maxplayers") or similar !!!!!!!!! //for(i = 0; i < maxplayers; ++i) // kh_keystatus[i] = "0"; -float kh_Team_ByID(float t) +int kh_Team_ByID(int t) { if(t == 0) return NUM_TEAM_1; if(t == 1) return NUM_TEAM_2; @@ -125,26 +71,22 @@ float kh_Team_ByID(float t) //entity kh_worldkeylist; .entity kh_worldkeynext; entity kh_controller; -//float kh_tracking_enabled; -float kh_teams; -float kh_interferemsg_time, kh_interferemsg_team; +//bool kh_tracking_enabled; +int kh_teams; +int kh_interferemsg_team; +float kh_interferemsg_time; .entity kh_next, kh_prev; // linked list .float kh_droptime; -.float kh_dropperteam; +.int kh_dropperteam; .entity kh_previous_owner; -.float kh_previous_owner_playerid; -.float kh_cp_duration; +.int kh_previous_owner_playerid; -float kh_key_dropped, kh_key_carried; +int kh_key_dropped, kh_key_carried; + +int kh_Key_AllOwnedByWhichTeam(); const float ST_KH_CAPS = 1; -const float SP_KH_CAPS = 4; -const float SP_KH_PUSHES = 5; -const float SP_KH_DESTROYS = 6; -const float SP_KH_PICKUPS = 7; -const float SP_KH_KCKILLS = 8; -const float SP_KH_LOSSES = 9; -void kh_ScoreRules(float teams) +void kh_ScoreRules(int teams) { ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); ScoreInfo_SetLabel_TeamScore( ST_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); @@ -180,10 +122,8 @@ bool kh_Key_waypointsprite_visible_for_player(entity this, entity player, entity void kh_update_state() { entity key; - float s; - float f; - - s = 0; + int f; + int s = 0; FOR_EACH_KH_KEY(key) { if(key.owner) @@ -217,10 +157,13 @@ void kh_Controller_SetThink(float t, kh_Think_t func) // runs occasionaly void kh_WaitForPlayers(); void kh_Controller_Think(entity this) // called a lot { - if(intermission_running) + if(gameover) return; if(this.cnt > 0) - { if(getthink(this) != kh_WaitForPlayers) { this.cnt -= 1; } } + { + if(getthink(this) != kh_WaitForPlayers) + this.cnt -= 1; + } else if(this.cnt == 0) { this.cnt -= 1; @@ -234,7 +177,7 @@ void kh_Controller_Think(entity this) // called a lot void kh_Scores_Event(entity player, entity key, string what, float frags_player, float frags_owner) // update the score when a key is captured { string s; - if(intermission_running) + if(gameover) return; if(frags_player) @@ -275,8 +218,7 @@ vector kh_AttachedOrigin(entity e) // runs when a team captures the flag, it ca void kh_Key_Attach(entity key) // runs when a player picks up a key and several times when a key is assigned to a player at the start of a round { #ifdef KH_PLAYER_USE_ATTACHMENT - entity first; - first = key.owner.kh_next; + entity first = key.owner.kh_next; if(key == first) { setattachment(key, key.owner, KH_PLAYER_ATTACHMENT_BONE); @@ -306,8 +248,9 @@ void kh_Key_Attach(entity key) // runs when a player picks up a key and several key.angles_y -= key.owner.angles.y; #endif key.flags = 0; + IL_REMOVE(g_items, key); key.solid = SOLID_NOT; - key.movetype = MOVETYPE_NONE; + set_movetype(key, MOVETYPE_NONE); key.team = key.owner.team; key.nextthink = time; key.damageforcescale = 0; @@ -318,8 +261,7 @@ void kh_Key_Attach(entity key) // runs when a player picks up a key and several void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs several times times when all the keys are captured { #ifdef KH_PLAYER_USE_ATTACHMENT - entity first; - first = key.owner.kh_next; + entity first = key.owner.kh_next; if(key == first) { if(key.kh_next) @@ -337,7 +279,7 @@ void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs } // in any case: setattachment(key, NULL, ""); - setorigin(key, key.owner.origin + '0 0 1' * (STAT(PL_MIN, NULL).z - KH_KEY_MIN_z)); + setorigin(key, key.owner.origin + '0 0 1' * (STAT(PL_MIN, key.owner).z - KH_KEY_MIN_z)); key.angles = key.owner.angles; #else setorigin(key, key.owner.origin + key.origin.z * '0 0 1'); @@ -345,8 +287,9 @@ void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs key.angles_y += key.owner.angles.y; #endif key.flags = FL_ITEM; + IL_PUSH(g_items, key); key.solid = SOLID_TRIGGER; - key.movetype = MOVETYPE_TOSS; + set_movetype(key, MOVETYPE_TOSS); key.pain_finished = time + autocvar_g_balance_keyhunt_delay_return; key.damageforcescale = autocvar_g_balance_keyhunt_damageforcescale; key.takedamage = DAMAGE_YES; @@ -358,12 +301,10 @@ void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs void kh_Key_AssignTo(entity key, entity player) // runs every time a key is picked up or assigned. Runs prior to kh_key_attach { - entity k; - float ownerteam0, ownerteam; if(key.owner == player) return; - ownerteam0 = kh_Key_AllOwnedByWhichTeam(); + int ownerteam0 = kh_Key_AllOwnedByWhichTeam(); if(key.owner) { @@ -435,15 +376,16 @@ void kh_Key_AssignTo(entity key, entity player) // runs every time a key is pic key.pusher = NULL; - ownerteam = kh_Key_AllOwnedByWhichTeam(); + int ownerteam = kh_Key_AllOwnedByWhichTeam(); if(ownerteam != ownerteam0) { + entity k; if(ownerteam != -1) { kh_interferemsg_time = time + 0.2; kh_interferemsg_team = player.team; - // audit all key carrier sprites, update them to RUN HERE + // audit all key carrier sprites, update them to "Run here" FOR_EACH_KH_KEY(k) { if (!k.owner) continue; @@ -458,7 +400,7 @@ void kh_Key_AssignTo(entity key, entity player) // runs every time a key is pic { kh_interferemsg_time = 0; - // audit all key carrier sprites, update them to RUN HERE + // audit all key carrier sprites, update them to "Key Carrier" FOR_EACH_KH_KEY(k) { if (!k.owner) continue; @@ -478,12 +420,10 @@ void kh_Key_Damage(entity this, entity inflictor, entity attacker, float damage, return; if(ITEM_DAMAGE_NEEDKILL(deathtype)) { - // touching lava, or hurt trigger - // what shall we do? - // immediately return is bad - // maybe start a shorter countdown? + this.pain_finished = bound(time, time + autocvar_g_balance_keyhunt_delay_damage_return, this.pain_finished); + return; } - if(vlen(force) <= 0) + if(force == '0 0 0') return; if(time > this.pushltime) if(IS_PLAYER(attacker)) @@ -500,14 +440,15 @@ void kh_Key_Collect(entity key, entity player) //a player picks up a dropped ke PlayerScore_Add(player, SP_KH_PICKUPS, 1); } key.kh_dropperteam = 0; - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_PICKUP), player.netname); + int realteam = kh_Team_ByID(key.count); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_PICKUP), player.netname); kh_Key_AssignTo(key, player); // this also updates .kh_state } -void kh_Key_Touch(entity this) // runs many, many times when a key has been dropped and can be picked up +void kh_Key_Touch(entity this, entity toucher) // runs many, many times when a key has been dropped and can be picked up { - if(intermission_running) + if(gameover) return; if(this.owner) // already carried @@ -515,26 +456,23 @@ void kh_Key_Touch(entity this) // runs many, many times when a key has been dro if(ITEM_TOUCH_NEEDKILL()) { - // touching sky, or nodrop - // what shall we do? - // immediately return is bad - // maybe start a shorter countdown? + this.pain_finished = bound(time, time + autocvar_g_balance_keyhunt_delay_damage_return, this.pain_finished); + return; } - if (!IS_PLAYER(other)) + if (!IS_PLAYER(toucher)) return; - if(IS_DEAD(other)) + if(IS_DEAD(toucher)) return; - if(other == this.enemy) + if(toucher == this.enemy) if(time < this.kh_droptime + autocvar_g_balance_keyhunt_delay_collect) return; // you just dropped it! - kh_Key_Collect(this, other); + kh_Key_Collect(this, toucher); } void kh_Key_Remove(entity key) // runs after when all the keys have been collected or when a key has been dropped for more than X seconds { - entity o; - o = key.owner; + entity o = key.owner; kh_Key_AssignTo(key, NULL); if(o) // it was attached WaypointSprite_Kill(key.waypointsprite_attachedforcarrier); @@ -558,7 +496,7 @@ void kh_Key_Remove(entity key) // runs after when all the keys have been collec } } - remove(key); + delete(key); kh_update_state(); } @@ -578,27 +516,25 @@ void kh_FinishRound() // runs when a team captures the keys kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, kh_StartRound); } -void kh_WinnerTeam(float teem) // runs when a team wins // Samual: Teem?.... TEEM?!?! what the fuck is wrong with you people +void nades_GiveBonus(entity player, float score); + +void kh_WinnerTeam(int winner_team) // runs when a team wins { // all key carriers get some points - vector firstorigin, lastorigin, midpoint; - float first; entity key; - float score; - score = (kh_teams - 1) * autocvar_g_balance_keyhunt_score_capture; - DistributeEvenly_Init(score, kh_teams); + float score = (NumTeams(kh_teams) - 1) * autocvar_g_balance_keyhunt_score_capture; + DistributeEvenly_Init(score, NumTeams(kh_teams)); // twice the score for 3 team games, three times the score for 4 team games! // note: for a win by destroying the key, this should NOT be applied FOR_EACH_KH_KEY(key) { - float f; - f = DistributeEvenly_Get(1); + float f = DistributeEvenly_Get(1); kh_Scores_Event(key.owner, key, "capture", f, 0); PlayerTeamScore_Add(key.owner, SP_KH_CAPS, ST_KH_CAPS, 1); nades_GiveBonus(key.owner, autocvar_g_nades_bonus_score_high); } - first = true; + bool first = true; string keyowner = ""; FOR_EACH_KH_KEY(key) if(key.owner.kh_next == key) @@ -609,17 +545,14 @@ void kh_WinnerTeam(float teem) // runs when a team wins // Samual: Teem?.... TE first = false; } - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(teem, INFO_KEYHUNT_CAPTURE), keyowner); + Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN)); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_KEYHUNT_CAPTURE), keyowner); first = true; - midpoint = '0 0 0'; - firstorigin = '0 0 0'; - lastorigin = '0 0 0'; + vector firstorigin = '0 0 0', lastorigin = '0 0 0', midpoint = '0 0 0'; FOR_EACH_KH_KEY(key) { - vector thisorigin; - - thisorigin = kh_AttachedOrigin(key); + vector thisorigin = kh_AttachedOrigin(key); //dprint("Key origin: ", vtos(thisorigin), "\n"); midpoint += thisorigin; @@ -630,32 +563,26 @@ void kh_WinnerTeam(float teem) // runs when a team wins // Samual: Teem?.... TE firstorigin = thisorigin; first = false; } - if(kh_teams > 2) + if(NumTeams(kh_teams) > 2) { te_lightning2(NULL, lastorigin, firstorigin); } - midpoint = midpoint * (1 / kh_teams); - te_customflash(midpoint, 1000, 1, Team_ColorRGB(teem) * 0.5 + '0.5 0.5 0.5'); // make the color >=0.5 in each component + midpoint = midpoint * (1 / NumTeams(kh_teams)); + te_customflash(midpoint, 1000, 1, Team_ColorRGB(winner_team) * 0.5 + '0.5 0.5 0.5'); // make the color >=0.5 in each component play2all(SND(KH_CAPTURE)); kh_FinishRound(); } -void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a flag carrier off the map +void kh_LoserTeam(int loser_team, entity lostkey) // runs when a player pushes a flag carrier off the map { - entity key, attacker; - float players; - float keys; float f; - - attacker = NULL; + entity attacker = NULL; if(lostkey.pusher) - if(lostkey.pusher.team != teem) + if(lostkey.pusher.team != loser_team) if(IS_PLAYER(lostkey.pusher)) attacker = lostkey.pusher; - players = keys = 0; - if(attacker) { if(lostkey.kh_previous_owner) @@ -667,13 +594,15 @@ void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a fl } else { - float of, fragsleft, i, j, thisteam; - of = autocvar_g_balance_keyhunt_score_destroyed_ownfactor; + int players = 0; + float of = autocvar_g_balance_keyhunt_score_destroyed_ownfactor; - FOREACH_CLIENT(IS_PLAYER(it) && it.team != teem, LAMBDA(++players)); + FOREACH_CLIENT(IS_PLAYER(it) && it.team != loser_team, LAMBDA(++players)); + entity key; + int keys = 0; FOR_EACH_KH_KEY(key) - if(key.owner && key.team != teem) + if(key.owner && key.team != loser_team) ++keys; if(lostkey.kh_previous_owner) @@ -686,20 +615,20 @@ void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a fl DistributeEvenly_Init(autocvar_g_balance_keyhunt_score_destroyed, keys * of + players); FOR_EACH_KH_KEY(key) - if(key.owner && key.team != teem) + if(key.owner && key.team != loser_team) { f = DistributeEvenly_Get(of); kh_Scores_Event(key.owner, NULL, "destroyed_holdingkey", f, 0); } - fragsleft = DistributeEvenly_Get(players); + int fragsleft = DistributeEvenly_Get(players); // Now distribute these among all other teams... - j = kh_teams - 1; - for(i = 0; i < kh_teams; ++i) + int j = NumTeams(kh_teams) - 1; + for(int i = 0; i < NumTeams(kh_teams); ++i) { - thisteam = kh_Team_ByID(i); - if(thisteam == teem) // bad boy, no cookie - this WILL happen + int thisteam = kh_Team_ByID(i); + if(thisteam == loser_team) // bad boy, no cookie - this WILL happen continue; players = 0; @@ -718,7 +647,12 @@ void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a fl } } - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(lostkey, INFO_KEYHUNT_LOST), lostkey.kh_previous_owner.netname); + int realteam = kh_Team_ByID(lostkey.count); + Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(loser_team, CENTER_ROUND_TEAM_LOSS)); + if(attacker) + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_PUSHED), attacker.netname, lostkey.kh_previous_owner.netname); + else + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_DESTROYED), lostkey.kh_previous_owner.netname); play2all(SND(KH_DESTROY)); te_tarexplosion(lostkey.origin); @@ -728,7 +662,7 @@ void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a fl void kh_Key_Think(entity this) // runs all the time { - if(intermission_running) + if(gameover) return; if(this.owner) @@ -754,8 +688,7 @@ void kh_Key_Think(entity this) // runs all the time } entity key; - vector p; - p = this.owner.origin; + vector p = this.owner.origin; FOR_EACH_KH_KEY(key) if(vdist(key.owner.origin - p, >, autocvar_g_balance_keyhunt_maxdist)) goto not_winning; @@ -800,6 +733,8 @@ void kh_Key_Spawn(entity initial_owner, float _angle, float i) // runs every ti key.angles = '0 360 0' * random(); key.event_damage = kh_Key_Damage; key.takedamage = DAMAGE_YES; + key.damagedbytriggers = autocvar_g_balance_keyhunt_return_when_unreachable; + key.damagedbycontents = autocvar_g_balance_keyhunt_return_when_unreachable; key.modelindex = kh_key_dropped; key.model = "key"; key.kh_dropperteam = 0; @@ -840,14 +775,11 @@ void kh_Key_Spawn(entity initial_owner, float _angle, float i) // runs every ti } // -1 when no team completely owns all keys yet -float kh_Key_AllOwnedByWhichTeam() // constantly called. check to see if all the keys are owned by the same team +int kh_Key_AllOwnedByWhichTeam() // constantly called. check to see if all the keys are owned by the same team { entity key; - float teem; - float keys; - - teem = -1; - keys = kh_teams; + int teem = -1; + int keys = NumTeams(kh_teams); FOR_EACH_KH_KEY(key) { if(!key.owner) @@ -866,15 +798,15 @@ float kh_Key_AllOwnedByWhichTeam() // constantly called. check to see if all th void kh_Key_DropOne(entity key) { // prevent collecting this one for some time - entity player; - player = key.owner; + entity player = key.owner; key.kh_droptime = time; key.enemy = player; kh_Scores_Event(player, key, "dropkey", 0, 0); PlayerScore_Add(player, SP_KH_LOSSES, 1); - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_DROP), player.netname); + int realteam = kh_Team_ByID(key.count); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_DROP), player.netname); kh_Key_AssignTo(key, NULL); makevectors(player.v_angle); @@ -888,19 +820,20 @@ void kh_Key_DropOne(entity key) void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies { - entity key; - entity mypusher; if(player.kh_next) { - mypusher = NULL; + entity mypusher = NULL; if(player.pusher) if(time < player.pushltime) mypusher = player.pusher; + + entity key; while((key = player.kh_next)) { kh_Scores_Event(player, key, "losekey", 0, 0); PlayerScore_Add(player, SP_KH_LOSSES, 1); - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_LOST), player.netname); + int realteam = kh_Team_ByID(key.count); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(realteam, INFO_KEYHUNT_LOST), player.netname); kh_Key_AssignTo(key, NULL); makevectors('-1 0 0' * (45 + 45 * random()) + '0 360 0' * random()); key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_dropvelocity * v_forward, false); @@ -913,35 +846,37 @@ void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies } } -float kh_CheckPlayers(float num) +int kh_GetMissingTeams() { - if(num < kh_teams) + int missing_teams = 0; + for(int i = 0; i < NumTeams(kh_teams); ++i) { - float t_team = kh_Team_ByID(num); - float players = 0; + int teem = kh_Team_ByID(i); + int players = 0; FOREACH_CLIENT(IS_PLAYER(it), LAMBDA( - if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == t_team) + if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == teem) ++players; )); - - if (!players) { return t_team; } + if (!players) + missing_teams |= pow(2, i); } - return 0; + return missing_teams; } -#define KH_READY_TEAMS() (!p1 + !p2 + ((kh_teams >= 3) ? !p3 : p3) + ((kh_teams >= 4) ? !p4 : p4)) -#define KH_READY_TEAMS_OK() (KH_READY_TEAMS() == kh_teams) void kh_WaitForPlayers() // delay start of the round until enough players are present { + static int prev_missing_teams_mask; if(time < game_starttime) { + if (prev_missing_teams_mask > 0) + Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS); + prev_missing_teams_mask = -1; kh_Controller_SetThink(game_starttime - time + 0.1, kh_WaitForPlayers); return; } - static float prev_missing_teams_mask; - float p1 = kh_CheckPlayers(0), p2 = kh_CheckPlayers(1), p3 = kh_CheckPlayers(2), p4 = kh_CheckPlayers(3); - if(KH_READY_TEAMS_OK()) + int missing_teams_mask = kh_GetMissingTeams(); + if(!missing_teams_mask) { if(prev_missing_teams_mask > 0) Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS); @@ -959,9 +894,6 @@ void kh_WaitForPlayers() // delay start of the round until enough players are p } else { - float missing_teams_mask = boolean(p1) + boolean(p2) * 2; - if(kh_teams >= 3) missing_teams_mask += boolean(p3) * 4; - if(kh_teams >= 4) missing_teams_mask += boolean(p4) * 8; if(prev_missing_teams_mask != missing_teams_mask) { Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask); @@ -982,16 +914,13 @@ void kh_EnableTrackingDevice() // runs after each round void kh_StartRound() // runs at the start of each round { - float i, players, teem; - if(time < game_starttime) { kh_Controller_SetThink(game_starttime - time + 0.1, kh_WaitForPlayers); return; } - float p1 = kh_CheckPlayers(0), p2 = kh_CheckPlayers(1), p3 = kh_CheckPlayers(2), p4 = kh_CheckPlayers(3); - if(!KH_READY_TEAMS_OK()) + if(kh_GetMissingTeams()) { kh_Controller_SetThink(1, kh_WaitForPlayers); return; @@ -1000,10 +929,10 @@ void kh_StartRound() // runs at the start of each round Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT); Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT_OTHER); - for(i = 0; i < kh_teams; ++i) + for(int i = 0; i < NumTeams(kh_teams); ++i) { - teem = kh_Team_ByID(i); - players = 0; + int teem = kh_Team_ByID(i); + int players = 0; entity my_player = NULL; FOREACH_CLIENT(IS_PLAYER(it), LAMBDA( if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == teem) @@ -1013,7 +942,7 @@ void kh_StartRound() // runs at the start of each round my_player = it; } )); - kh_Key_Spawn(my_player, 360 * i / kh_teams, i); + kh_Key_Spawn(my_player, 360 * i / NumTeams(kh_teams), i); } kh_tracking_enabled = false; @@ -1030,10 +959,8 @@ float kh_HandleFrags(entity attacker, entity targ, float f) // adds to the play { if(attacker.team == targ.team) { - entity k; - float nk; - nk = 0; - for(k = targ.kh_next; k != NULL; k = k.kh_next) + int nk = 0; + for(entity k = targ.kh_next; k != NULL; k = k.kh_next) ++nk; kh_Scores_Event(attacker, targ.kh_next, "carrierfrag", -nk * autocvar_g_balance_keyhunt_score_collect, 0); } @@ -1053,9 +980,17 @@ void kh_Initialize() // sets up th KH environment // setup variables kh_teams = autocvar_g_keyhunt_teams_override; if(kh_teams < 2) - kh_teams = autocvar_g_keyhunt_teams; + kh_teams = cvar("g_keyhunt_teams"); // read the cvar directly as it gets written earlier in the same frame kh_teams = bound(2, kh_teams, 4); + int teams = 0; + if(kh_teams >= 1) teams |= BIT(0); + if(kh_teams >= 2) teams |= BIT(1); + if(kh_teams >= 3) teams |= BIT(2); + if(kh_teams >= 4) teams |= BIT(3); + + kh_teams = teams; // now set it? + // make a KH entity for controlling the game kh_controller = spawn(); setthink(kh_controller, kh_Controller_Think); @@ -1085,7 +1020,7 @@ void kh_finalize() { // to be called before intermission kh_FinishRound(); - remove(kh_controller); + delete(kh_controller); kh_controller = NULL; } @@ -1133,7 +1068,7 @@ void havocbot_role_kh_carrier(entity this) if (!(this.kh_next)) { - LOG_TRACE("changing role to freelancer\n"); + LOG_TRACE("changing role to freelancer"); this.havocbot_role = havocbot_role_kh_freelancer; this.havocbot_role_timeout = 0; return; @@ -1160,7 +1095,7 @@ void havocbot_role_kh_defense(entity this) if (this.kh_next) { - LOG_TRACE("changing role to carrier\n"); + LOG_TRACE("changing role to carrier"); this.havocbot_role = havocbot_role_kh_carrier; this.havocbot_role_timeout = 0; return; @@ -1170,7 +1105,7 @@ void havocbot_role_kh_defense(entity this) this.havocbot_role_timeout = time + random() * 10 + 20; if (time > this.havocbot_role_timeout) { - LOG_TRACE("changing role to freelancer\n"); + LOG_TRACE("changing role to freelancer"); this.havocbot_role = havocbot_role_kh_freelancer; this.havocbot_role_timeout = 0; return; @@ -1201,7 +1136,7 @@ void havocbot_role_kh_offense(entity this) if (this.kh_next) { - LOG_TRACE("changing role to carrier\n"); + LOG_TRACE("changing role to carrier"); this.havocbot_role = havocbot_role_kh_carrier; this.havocbot_role_timeout = 0; return; @@ -1211,7 +1146,7 @@ void havocbot_role_kh_offense(entity this) this.havocbot_role_timeout = time + random() * 10 + 20; if (time > this.havocbot_role_timeout) { - LOG_TRACE("changing role to freelancer\n"); + LOG_TRACE("changing role to freelancer"); this.havocbot_role = havocbot_role_kh_freelancer; this.havocbot_role_timeout = 0; return; @@ -1243,7 +1178,7 @@ void havocbot_role_kh_freelancer(entity this) if (this.kh_next) { - LOG_TRACE("changing role to carrier\n"); + LOG_TRACE("changing role to carrier"); this.havocbot_role = havocbot_role_kh_carrier; this.havocbot_role_timeout = 0; return; @@ -1255,12 +1190,12 @@ void havocbot_role_kh_freelancer(entity this) { if (random() < 0.5) { - LOG_TRACE("changing role to offense\n"); + LOG_TRACE("changing role to offense"); this.havocbot_role = havocbot_role_kh_offense; } else { - LOG_TRACE("changing role to defense\n"); + LOG_TRACE("changing role to defense"); this.havocbot_role = havocbot_role_kh_defense; } this.havocbot_role_timeout = 0; @@ -1269,12 +1204,10 @@ void havocbot_role_kh_freelancer(entity this) if (this.bot_strategytime < time) { - float key_owner_team; - this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; navigation_goalrating_start(this); - key_owner_team = kh_Key_AllOwnedByWhichTeam(); + int key_owner_team = kh_Key_AllOwnedByWhichTeam(); if(key_owner_team == this.team) havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend anyway else if(key_owner_team == -1) @@ -1329,7 +1262,7 @@ MUTATOR_HOOKFUNCTION(kh, MatchEnd) kh_finalize(); } -MUTATOR_HOOKFUNCTION(kh, GetTeamCount, CBC_ORDER_EXCLUSIVE) +MUTATOR_HOOKFUNCTION(kh, CheckAllowedTeams, CBC_ORDER_EXCLUSIVE) { M_ARGV(0, float) = kh_teams; } @@ -1378,13 +1311,11 @@ MUTATOR_HOOKFUNCTION(kh, HavocBot_ChooseRole) MUTATOR_HOOKFUNCTION(kh, DropSpecialItems) { entity frag_target = M_ARGV(0, entity); - + kh_Key_DropAll(frag_target, false); } MUTATOR_HOOKFUNCTION(kh, reset_map_global) { - kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round + (game_starttime - time), kh_StartRound); + kh_WaitForPlayers(); // takes care of killing the "missing teams" message } - -#endif