X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fserver%2Fmutators%2Fmutator%2Fgamemode_ca.qc;h=943fd27d7a27fe86c27750264bb279626f4646c7;hb=450125fe9fa5ce6324db12446fe689cbde0678a3;hp=725569bfff6469745c55a56ffcce910131287071;hpb=c741e6b3f012aa525f23e1df30d1d933b383fbc5;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qc b/qcsrc/server/mutators/mutator/gamemode_ca.qc index 725569bff..943fd27d7 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qc @@ -1,22 +1,52 @@ +#include "gamemode_ca.qh" #ifndef GAMEMODE_CA_H #define GAMEMODE_CA_H int autocvar_g_ca_point_limit; int autocvar_g_ca_point_leadlimit; +float autocvar_g_ca_round_timelimit; bool autocvar_g_ca_team_spawns; +int autocvar_g_ca_teams; +int autocvar_g_ca_teams_override; +float autocvar_g_ca_warmup; + + +int ca_teams; +bool allowed_to_spawn; + +const int ST_CA_ROUNDS = 1; -void ca_Initialize(); +bool CA_CheckTeams(); +bool CA_CheckWinner(); +void CA_RoundStart(); +bool ca_isEliminated(entity e); + +void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override); REGISTER_MUTATOR(ca, false) { MUTATOR_ONADD { - if (time > 1) // game loads at time 1 - error("This is a game type and it cannot be added at runtime."); - ca_Initialize(); + // game loads at time 1 + if (time > 1) error("This is a game type and it cannot be added at runtime."); + + allowed_to_spawn = true; + + ca_teams = autocvar_g_ca_teams_override; + if (ca_teams < 2) ca_teams = autocvar_g_ca_teams; + ca_teams = bound(2, ca_teams, 4); + + ScoreRules_basics(ca_teams, SFL_SORT_PRIO_PRIMARY, 0, true); + ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); + ScoreRules_basics_end(); + + round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart); + round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit); + + EliminatedPlayers_Init(ca_isEliminated); ActivateTeamplay(); - SetLimits(autocvar_g_ca_point_limit, autocvar_g_ca_point_leadlimit, -1, -1); + SetLimits(autocvar_g_ca_point_limit, autocvar_g_ca_point_leadlimit, autocvar_timelimit_override, -1); if (autocvar_g_ca_team_spawns) have_team_spawns = -1; // request team spawns @@ -37,55 +67,26 @@ REGISTER_MUTATOR(ca, false) #ifdef IMPLEMENTATION float autocvar_g_ca_damage2score_multiplier; -float autocvar_g_ca_round_timelimit; bool autocvar_g_ca_spectate_enemies; -int autocvar_g_ca_teams; -int autocvar_g_ca_teams_override; -float autocvar_g_ca_warmup; - -float ca_teams; -float allowed_to_spawn; - -const float ST_CA_ROUNDS = 1; -void ca_ScoreRules(float teams) -{ - ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true); - ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); - ScoreRules_basics_end(); -} void CA_count_alive_players() { - entity e; total_players = redalive = bluealive = yellowalive = pinkalive = 0; - FOR_EACH_PLAYER(e) { - if(e.team == NUM_TEAM_1) - { - ++total_players; - if (e.health >= 1) ++redalive; - } - else if(e.team == NUM_TEAM_2) - { - ++total_players; - if (e.health >= 1) ++bluealive; - } - else if(e.team == NUM_TEAM_3) + FOREACH_CLIENT(IS_PLAYER(it), LAMBDA( + switch(it.team) { - ++total_players; - if (e.health >= 1) ++yellowalive; + case NUM_TEAM_1: ++total_players; if(!IS_DEAD(it)) ++redalive; break; + case NUM_TEAM_2: ++total_players; if(!IS_DEAD(it)) ++bluealive; break; + case NUM_TEAM_3: ++total_players; if(!IS_DEAD(it)) ++yellowalive; break; + case NUM_TEAM_4: ++total_players; if(!IS_DEAD(it)) ++pinkalive; break; } - else if(e.team == NUM_TEAM_4) - { - ++total_players; - if (e.health >= 1) ++pinkalive; - } - } - FOR_EACH_REALCLIENT(e) { - e.redalive_stat = redalive; - e.bluealive_stat = bluealive; - e.yellowalive_stat = yellowalive; - e.pinkalive_stat = pinkalive; - } + )); + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( + it.redalive_stat = redalive; + it.bluealive_stat = bluealive; + it.yellowalive_stat = yellowalive; + it.pinkalive_stat = pinkalive; + )); } float CA_GetWinnerTeam() @@ -113,19 +114,19 @@ float CA_GetWinnerTeam() return -1; // no player left } +void nades_Clear(entity player); + #define CA_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0)) #define CA_ALIVE_TEAMS_OK() (CA_ALIVE_TEAMS() == ca_teams) float CA_CheckWinner() { - entity e; if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0) { Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER); Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER); allowed_to_spawn = false; round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit); - FOR_EACH_PLAYER(e) - nades_Clear(e); + FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it))); return 1; } @@ -133,11 +134,11 @@ float CA_CheckWinner() if(CA_ALIVE_TEAMS() > 1) return 0; - float winner_team = CA_GetWinnerTeam(); + int winner_team = CA_GetWinnerTeam(); if(winner_team > 0) { - Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_)); - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_)); + Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN)); + Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN)); TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1); } else if(winner_team == -1) @@ -149,40 +150,36 @@ float CA_CheckWinner() allowed_to_spawn = false; round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit); - FOR_EACH_PLAYER(e) - nades_Clear(e); + FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it))); return 1; } void CA_RoundStart() { - if(warmup_stage) - allowed_to_spawn = true; - else - allowed_to_spawn = false; + allowed_to_spawn = boolean(warmup_stage); } -float CA_CheckTeams() +bool CA_CheckTeams() { - static float prev_missing_teams_mask; + static int prev_missing_teams_mask; allowed_to_spawn = true; CA_count_alive_players(); if(CA_ALIVE_TEAMS_OK()) { if(prev_missing_teams_mask > 0) - Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS); + Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS); prev_missing_teams_mask = -1; - return 1; + return true; } if(total_players == 0) { if(prev_missing_teams_mask > 0) - Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS); + Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS); prev_missing_teams_mask = -1; - return 0; + return false; } - float missing_teams_mask = (!redalive) + (!bluealive) * 2; + int missing_teams_mask = (!redalive) + (!bluealive) * 2; if(ca_teams >= 3) missing_teams_mask += (!yellowalive) * 4; if(ca_teams >= 4) missing_teams_mask += (!pinkalive) * 8; if(prev_missing_teams_mask != missing_teams_mask) @@ -190,147 +187,142 @@ float CA_CheckTeams() Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask); prev_missing_teams_mask = missing_teams_mask; } - return 0; + return false; } -float ca_isEliminated(entity e) +bool ca_isEliminated(entity e) { - if(e.caplayer == 1 && (e.deadflag != DEAD_NO || e.frags == FRAGS_LMS_LOSER)) + if(e.caplayer == 1 && (IS_DEAD(e) || e.frags == FRAGS_LMS_LOSER)) return true; if(e.caplayer == 0.5) return true; return false; } -// Returns next available player to spectate if g_ca_spectate_enemies == 0 +/** Returns next available player to spectate if g_ca_spectate_enemies == 0 */ entity CA_SpectateNext(entity player, entity start) { - if(SAME_TEAM(start, player)) - return start; - - entity spec_other = start; + if (SAME_TEAM(start, player)) return start; // continue from current player - while(spec_other && DIFF_TEAM(spec_other, player)) - spec_other = find(spec_other, classname, "player"); - - if (!spec_other) + for (entity e = start; (e = find(e, classname, STR_PLAYER)); ) { - // restart from begining - spec_other = find(spec_other, classname, "player"); - while(spec_other && DIFF_TEAM(spec_other, player)) - spec_other = find(spec_other, classname, "player"); + if (SAME_TEAM(player, e)) return e; } - - return spec_other; + // restart from begining + for (entity e = NULL; (e = find(e, classname, STR_PLAYER)); ) + { + if (SAME_TEAM(player, e)) return e; + } + return start; } + MUTATOR_HOOKFUNCTION(ca, PlayerSpawn) -{SELFPARAM(); - self.caplayer = 1; - if(!warmup_stage) +{ + entity player = M_ARGV(0, entity); + + player.caplayer = 1; + if (!warmup_stage) eliminatedPlayers.SendFlags |= 1; - return 1; } MUTATOR_HOOKFUNCTION(ca, PutClientInServer) -{SELFPARAM(); - if(!allowed_to_spawn) - if(IS_PLAYER(self)) // this is true even when player is trying to join +{ + entity player = M_ARGV(0, entity); + + if (!allowed_to_spawn && IS_PLAYER(player)) // this is true even when player is trying to join { - self.classname = STR_OBSERVER; - if(self.jointime != time) //not when connecting - if(!self.caplayer) + TRANSMUTE(Observer, player); + if (player.jointime != time && !player.caplayer) // not when connecting { - self.caplayer = 0.5; - if(IS_REAL_CLIENT(self)) - Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CA_JOIN_LATE); + player.caplayer = 0.5; + Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE); } } - return 1; } MUTATOR_HOOKFUNCTION(ca, reset_map_players) -{SELFPARAM(); - entity e; - FOR_EACH_CLIENT(e) - { - setself(e); - self.killcount = 0; - if(!self.caplayer && IS_BOT_CLIENT(self)) +{ + FOREACH_CLIENT(true, { + it.killcount = 0; + if (!it.caplayer && IS_BOT_CLIENT(it)) { - self.team = -1; - self.caplayer = 1; + it.team = -1; + it.caplayer = 1; } - if(self.caplayer) + if (it.caplayer) { - self.classname = STR_PLAYER; - self.caplayer = 1; - PutClientInServer(); + TRANSMUTE(Player, it); + it.caplayer = 1; + WITHSELF(it, PutClientInServer()); } - } - return 1; + }); + return true; } MUTATOR_HOOKFUNCTION(ca, ClientConnect) -{SELFPARAM(); - self.classname = STR_OBSERVER; - return 1; +{ + entity player = M_ARGV(0, entity); + + TRANSMUTE(Observer, player); + return true; } MUTATOR_HOOKFUNCTION(ca, reset_map_global) { allowed_to_spawn = true; - return 1; + return true; } MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE) { - ret_float = ca_teams; - return false; + M_ARGV(0, float) = ca_teams; } -entity ca_LastPlayerForTeam() -{SELFPARAM(); - entity pl, last_pl = world; - FOR_EACH_PLAYER(pl) - { - if(pl.health >= 1) - if(pl != self) - if(pl.team == self.team) - if(!last_pl) - last_pl = pl; +entity ca_LastPlayerForTeam(entity this) +{ + entity last_pl = NULL; + FOREACH_CLIENT(IS_PLAYER(it) && it != this, { + if (!IS_DEAD(it)) + if (SAME_TEAM(this, it)) + if (!last_pl) + last_pl = it; else - return world; - } + return NULL; + }); return last_pl; } -void ca_LastPlayerForTeam_Notify() +void ca_LastPlayerForTeam_Notify(entity this) { - if(round_handler_IsActive()) - if(round_handler_IsRoundStarted()) + if (round_handler_IsActive()) + if (round_handler_IsRoundStarted()) { - entity pl = ca_LastPlayerForTeam(); - if(pl) + entity pl = ca_LastPlayerForTeam(this); + if (pl) Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE); } } MUTATOR_HOOKFUNCTION(ca, PlayerDies) -{SELFPARAM(); - ca_LastPlayerForTeam_Notify(); - if(!allowed_to_spawn) - self.respawn_flags = RESPAWN_SILENT; - if(!warmup_stage) +{ + entity frag_target = M_ARGV(2, entity); + + ca_LastPlayerForTeam_Notify(frag_target); + if (!allowed_to_spawn) + frag_target.respawn_flags = RESPAWN_SILENT; + if (!warmup_stage) eliminatedPlayers.SendFlags |= 1; return 1; } MUTATOR_HOOKFUNCTION(ca, ClientDisconnect) -{SELFPARAM(); - if(self.caplayer == 1) - ca_LastPlayerForTeam_Notify(); - return 1; +{ + entity player = M_ARGV(0, entity); + + if (player.caplayer == 1) + ca_LastPlayerForTeam_Notify(player); + return true; } MUTATOR_HOOKFUNCTION(ca, ForbidPlayerScore_Clear) @@ -339,32 +331,34 @@ MUTATOR_HOOKFUNCTION(ca, ForbidPlayerScore_Clear) } MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver) -{SELFPARAM(); - if(self.caplayer == 1) - ca_LastPlayerForTeam_Notify(); - if(self.killindicator_teamchange == -2) - self.caplayer = 0; - if(self.caplayer) - self.frags = FRAGS_LMS_LOSER; - if(!warmup_stage) +{ + entity player = M_ARGV(0, entity); + + if (!IS_DEAD(player)) + ca_LastPlayerForTeam_Notify(player); + if (player.killindicator_teamchange == -2) + player.caplayer = 0; + if (player.caplayer) + player.frags = FRAGS_LMS_LOSER; + if (!warmup_stage) eliminatedPlayers.SendFlags |= 1; - return true; + return true; // prevent team reset } MUTATOR_HOOKFUNCTION(ca, ForbidThrowCurrentWeapon) { - return 1; + return true; } MUTATOR_HOOKFUNCTION(ca, GiveFragsForKill, CBC_ORDER_FIRST) { - frag_score = 0; // score will be given to the winner team when the round ends - return 1; + M_ARGV(2, float) = 0; // score will be given to the winner team when the round ends + return true; } MUTATOR_HOOKFUNCTION(ca, SetStartItems) { - start_items &= ~IT_UNLIMITED_AMMO; + start_items &= ~IT_UNLIMITED_AMMO; start_health = warmup_start_health = cvar("g_lms_start_health"); start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor"); start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells"); @@ -379,23 +373,34 @@ MUTATOR_HOOKFUNCTION(ca, SetStartItems) MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate) { - if(IS_PLAYER(frag_target)) - if(frag_target.deadflag == DEAD_NO) - if(frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL.m_id) + entity frag_attacker = M_ARGV(1, entity); + entity frag_target = M_ARGV(2, entity); + float frag_deathtype = M_ARGV(3, float); + float frag_damage = M_ARGV(4, float); + float frag_mirrordamage = M_ARGV(5, float); + + if (IS_PLAYER(frag_target)) + if (!IS_DEAD(frag_target)) + if (frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL.m_id) frag_damage = 0; frag_mirrordamage = 0; + M_ARGV(4, float) = frag_damage; + M_ARGV(5, float) = frag_mirrordamage; + return false; } MUTATOR_HOOKFUNCTION(ca, FilterItem) -{SELFPARAM(); - if(autocvar_g_powerups <= 0) - if(self.flags & FL_POWERUP) +{ + entity item = M_ARGV(0, entity); + + if (autocvar_g_powerups <= 0) + if (item.flags & FL_POWERUP) return true; - if(autocvar_g_pickup_items <= 0) + if (autocvar_g_pickup_items <= 0) return true; return false; @@ -403,12 +408,16 @@ MUTATOR_HOOKFUNCTION(ca, FilterItem) MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor) { + entity frag_attacker = M_ARGV(1, entity); + entity frag_target = M_ARGV(2, entity); + float frag_damage = M_ARGV(7, float); + float damage_take = M_ARGV(4, float); + float damage_save = M_ARGV(5, float); + float excess = max(0, frag_damage - damage_take - damage_save); - if(frag_target != frag_attacker && IS_PLAYER(frag_attacker)) + if (frag_target != frag_attacker && IS_PLAYER(frag_attacker)) PlayerTeamScore_Add(frag_attacker, SP_SCORE, ST_SCORE, (frag_damage - excess) * autocvar_g_ca_damage2score_multiplier); - - return false; } MUTATOR_HOOKFUNCTION(ca, PlayerRegen) @@ -425,35 +434,45 @@ MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining) MUTATOR_HOOKFUNCTION(ca, SpectateSet) { - if(!autocvar_g_ca_spectate_enemies && self.caplayer) - if(DIFF_TEAM(spec_player, self)) + entity client = M_ARGV(0, entity); + entity targ = M_ARGV(1, entity); + + if (!autocvar_g_ca_spectate_enemies && client.caplayer) + if (DIFF_TEAM(targ, client)) return true; + return false; } MUTATOR_HOOKFUNCTION(ca, SpectateNext) -{SELFPARAM(); - if(!autocvar_g_ca_spectate_enemies && self.caplayer) +{ + entity client = M_ARGV(0, entity); + entity targ = M_ARGV(1, entity); + + if (!autocvar_g_ca_spectate_enemies && client.caplayer) { - spec_player = CA_SpectateNext(self, spec_player); + targ = CA_SpectateNext(client, targ); return true; } return false; } MUTATOR_HOOKFUNCTION(ca, SpectatePrev) -{SELFPARAM(); - if(!autocvar_g_ca_spectate_enemies && self.caplayer) +{ + entity client = M_ARGV(0, entity); + entity targ = M_ARGV(1, entity); + entity first = M_ARGV(2, entity); + + if (!autocvar_g_ca_spectate_enemies && client.caplayer) { - do { spec_player = spec_player.chain; } - while(spec_player && DIFF_TEAM(spec_player, self)); + do { targ = targ.chain; } + while(targ && DIFF_TEAM(targ, client)); - if (!spec_player) + if (!targ) { - spec_player = spec_first; - while(spec_player && DIFF_TEAM(spec_player, self)) - spec_player = spec_player.chain; - if(spec_player == self.enemy) + for (targ = first; targ && DIFF_TEAM(targ, client); targ = targ.chain); + + if (targ == client.enemy) return MUT_SPECPREV_RETURN; } } @@ -463,24 +482,23 @@ MUTATOR_HOOKFUNCTION(ca, SpectatePrev) MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE) { - entity head; - FOR_EACH_REALCLIENT(head) - { - if(IS_PLAYER(head) || head.caplayer == 1) - ++bot_activerealplayers; - ++bot_realplayers; - } - + FOREACH_CLIENT(IS_REAL_CLIENT(it), { + if (IS_PLAYER(it) || it.caplayer == 1) + ++M_ARGV(0, int); + ++M_ARGV(1, int); + }); return true; } MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate) { - if(self.caplayer) + entity player = M_ARGV(0, entity); + + if (player.caplayer) { // they're going to spec, we can do other checks - if(autocvar_sv_spectate && (IS_SPEC(self) || IS_OBSERVER(self))) - Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CA_LEAVE); + if (autocvar_sv_spectate && (IS_SPEC(player) || IS_OBSERVER(player))) + Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_LEAVE); return MUT_SPECCMD_FORCE; } @@ -489,45 +507,20 @@ MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate) MUTATOR_HOOKFUNCTION(ca, WantWeapon) { - want_allguns = true; - return false; + M_ARGV(2, bool) = true; // all weapons } MUTATOR_HOOKFUNCTION(ca, GetPlayerStatus) { - if(set_player.caplayer == 1) - return true; - return false; + entity player = M_ARGV(0, entity); + + return player.caplayer == 1; } MUTATOR_HOOKFUNCTION(ca, SetWeaponArena) { // most weapons arena - if(ret_string == "0" || ret_string == "") - ret_string = "most"; - return false; -} - -void ca_Initialize() -{ - allowed_to_spawn = true; - - ca_teams = autocvar_g_ca_teams_override; - if(ca_teams < 2) - ca_teams = autocvar_g_ca_teams; - ca_teams = bound(2, ca_teams, 4); - ret_float = ca_teams; - ca_ScoreRules(ca_teams); - - round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart); - round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit); - - addstat(STAT_REDALIVE, AS_INT, redalive_stat); - addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat); - addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat); - addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat); - - EliminatedPlayers_Init(ca_isEliminated); + if (M_ARGV(0, string) == "0" || M_ARGV(0, string) == "") M_ARGV(0, string) = "most"; } #endif