From: TimePath Date: Sun, 13 Mar 2016 02:02:05 +0000 (+1100) Subject: CA: cleanup; fix being moved to spectators X-Git-Tag: xonotic-v0.8.2~1111 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=49e9a84ae90f687029fded182097344b6687365e;p=xonotic%2Fxonotic-data.pk3dir.git CA: cleanup; fix being moved to spectators --- diff --git a/qcsrc/common/notifications/all.qc b/qcsrc/common/notifications/all.qc index a23c95f1d..60fd62599 100644 --- a/qcsrc/common/notifications/all.qc +++ b/qcsrc/common/notifications/all.qc @@ -1548,6 +1548,7 @@ void Send_Notification( MSG net_type, Notification net_name, ...count) { + if (!IS_REAL_CLIENT(client)) return; entity notif = net_name; string parms = sprintf("%s, '%s', %s, %s", Get_Notif_BroadcastName(broadcast), diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index f2e075c4d..df51f8813 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -168,7 +168,10 @@ void PutObserverInServer() bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver); PlayerState_detach(this); - if (IS_PLAYER(this)) Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); + if (IS_PLAYER(this) && this.health >= 1) { + // despawn effect + Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); + } { entity spot = SelectSpawnPoint(true); @@ -206,8 +209,13 @@ void PutObserverInServer() WaypointSprite_PlayerDead(this); - if (!mutator_returnvalue) // mutator prevents resetting teams + if (mutator_returnvalue) { + // mutator prevents resetting teams+score + } else { this.team = -1; // move this as it is needed to log the player spectating in eventlog + this.frags = FRAGS_SPECTATOR; + PlayerScore_Clear(this); // clear scores when needed + } if (this.killcount != FRAGS_SPECTATOR) { @@ -222,12 +230,9 @@ void PutObserverInServer() this.just_joined = false; } - PlayerScore_Clear(this); // clear scores when needed - accuracy_resend(this); this.spectatortime = time; - this.frags = FRAGS_SPECTATOR; this.bot_attack = false; this.hud = HUD_NORMAL; this.classname = STR_OBSERVER; diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qc b/qcsrc/server/mutators/mutator/gamemode_ca.qc index 5e74d18bb..57e96abf9 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qc @@ -3,17 +3,45 @@ 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; -void ca_Initialize(); + +int ca_teams; +bool allowed_to_spawn; + +const int ST_CA_ROUNDS = 1; + +bool CA_CheckTeams(); +bool CA_CheckWinner(); +void CA_RoundStart(); +bool ca_isEliminated(entity e); 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); + ret_float = ca_teams; + + 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); @@ -37,22 +65,7 @@ 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() { @@ -140,10 +153,7 @@ float CA_CheckWinner() void CA_RoundStart() { - if(warmup_stage) - allowed_to_spawn = true; - else - allowed_to_spawn = false; + allowed_to_spawn = boolean(warmup_stage); } bool CA_CheckTeams() @@ -188,7 +198,7 @@ bool ca_isEliminated(entity e) /** 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; + if (SAME_TEAM(start, player)) return start; // continue from current player for (entity e = start; (e = find(e, classname, STR_PLAYER)); ) { @@ -204,60 +214,57 @@ entity CA_SpectateNext(entity player, entity start) MUTATOR_HOOKFUNCTION(ca, PlayerSpawn) -{SELFPARAM(); - self.caplayer = 1; - if(!warmup_stage) +{ + SELFPARAM(); + this.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 +{ + SELFPARAM(); + if (!allowed_to_spawn && IS_PLAYER(this)) // this is true even when player is trying to join { - self.classname = STR_OBSERVER; - if(self.jointime != time) //not when connecting - if(!self.caplayer) + this.classname = STR_OBSERVER; + if (this.jointime != time && !this.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); + this.caplayer = 0.5; + Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CA_JOIN_LATE); } } - return 1; } MUTATOR_HOOKFUNCTION(ca, reset_map_players) -{SELFPARAM(); - FOREACH_CLIENT(true, LAMBDA( - setself(it); - 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(); + it.classname = STR_PLAYER; + it.caplayer = 1; + WITH(entity, self, it, PutClientInServer()); } - )); - return 1; + }); + return true; } MUTATOR_HOOKFUNCTION(ca, ClientConnect) -{SELFPARAM(); - self.classname = STR_OBSERVER; - return 1; +{ + SELFPARAM(); + this.classname = STR_OBSERVER; + return true; } MUTATOR_HOOKFUNCTION(ca, reset_map_global) { allowed_to_spawn = true; - return 1; + return true; } MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE) @@ -267,26 +274,27 @@ MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE) } entity ca_LastPlayerForTeam() -{SELFPARAM(); - entity last_pl = world; - FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA( - if(!IS_DEAD(it)) - if(SAME_TEAM(self, it)) - if(!last_pl) +{ + SELFPARAM(); + 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() { - if(round_handler_IsActive()) - if(round_handler_IsRoundStarted()) + if (round_handler_IsActive()) + if (round_handler_IsRoundStarted()) { entity pl = ca_LastPlayerForTeam(); - if(pl) + if (pl) Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE); } } @@ -294,16 +302,17 @@ void ca_LastPlayerForTeam_Notify() MUTATOR_HOOKFUNCTION(ca, PlayerDies) { ca_LastPlayerForTeam_Notify(); - if(!allowed_to_spawn) + if (!allowed_to_spawn) frag_target.respawn_flags = RESPAWN_SILENT; - if(!warmup_stage) + if (!warmup_stage) eliminatedPlayers.SendFlags |= 1; return 1; } MUTATOR_HOOKFUNCTION(ca, ClientDisconnect) -{SELFPARAM(); - if(self.caplayer == 1) +{ + SELFPARAM(); + if (this.caplayer == 1) ca_LastPlayerForTeam_Notify(); return 1; } @@ -314,16 +323,17 @@ MUTATOR_HOOKFUNCTION(ca, ForbidPlayerScore_Clear) } MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver) -{SELFPARAM(); - if(self.caplayer == 1) +{ + SELFPARAM(); + if (this.caplayer == 1) ca_LastPlayerForTeam_Notify(); - if(self.killindicator_teamchange == -2) - self.caplayer = 0; - if(self.caplayer) - self.frags = FRAGS_LMS_LOSER; - if(!warmup_stage) + if (this.killindicator_teamchange == -2) + this.caplayer = 0; + if (this.caplayer) + this.frags = FRAGS_LMS_LOSER; + if (!warmup_stage) eliminatedPlayers.SendFlags |= 1; - return true; + return true; // prevent team reset } MUTATOR_HOOKFUNCTION(ca, ForbidThrowCurrentWeapon) @@ -339,7 +349,7 @@ MUTATOR_HOOKFUNCTION(ca, GiveFragsForKill, CBC_ORDER_FIRST) 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"); @@ -354,9 +364,9 @@ MUTATOR_HOOKFUNCTION(ca, SetStartItems) MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate) { - 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) + 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; @@ -365,12 +375,13 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate) } MUTATOR_HOOKFUNCTION(ca, FilterItem) -{SELFPARAM(); - if(autocvar_g_powerups <= 0) - if(self.flags & FL_POWERUP) +{ + SELFPARAM(); + if (autocvar_g_powerups <= 0) + if (this.flags & FL_POWERUP) return true; - if(autocvar_g_pickup_items <= 0) + if (autocvar_g_pickup_items <= 0) return true; return false; @@ -380,7 +391,7 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor) { 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; @@ -400,35 +411,37 @@ MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining) MUTATOR_HOOKFUNCTION(ca, SpectateSet) { - if(!autocvar_g_ca_spectate_enemies && self.caplayer) - if(DIFF_TEAM(spec_player, self)) + SELFPARAM(); + if (!autocvar_g_ca_spectate_enemies && this.caplayer) + if (DIFF_TEAM(spec_player, this)) return true; return false; } MUTATOR_HOOKFUNCTION(ca, SpectateNext) -{SELFPARAM(); - if(!autocvar_g_ca_spectate_enemies && self.caplayer) +{ + SELFPARAM(); + if (!autocvar_g_ca_spectate_enemies && this.caplayer) { - spec_player = CA_SpectateNext(self, spec_player); + spec_player = CA_SpectateNext(this, spec_player); return true; } return false; } MUTATOR_HOOKFUNCTION(ca, SpectatePrev) -{SELFPARAM(); - if(!autocvar_g_ca_spectate_enemies && self.caplayer) +{ + SELFPARAM(); + if (!autocvar_g_ca_spectate_enemies && this.caplayer) { do { spec_player = spec_player.chain; } - while(spec_player && DIFF_TEAM(spec_player, self)); + while(spec_player && DIFF_TEAM(spec_player, this)); if (!spec_player) { - spec_player = spec_first; - while(spec_player && DIFF_TEAM(spec_player, self)) - spec_player = spec_player.chain; - if(spec_player == self.enemy) + for (spec_player = spec_first; spec_player && DIFF_TEAM(spec_player, this); spec_player = spec_player.chain); + + if (spec_player == this.enemy) return MUT_SPECPREV_RETURN; } } @@ -438,22 +451,22 @@ MUTATOR_HOOKFUNCTION(ca, SpectatePrev) MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE) { - FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( - if(IS_PLAYER(it) || it.caplayer == 1) + FOREACH_CLIENT(IS_REAL_CLIENT(it), { + if (IS_PLAYER(it) || it.caplayer == 1) ++bot_activerealplayers; ++bot_realplayers; - )); - + }); return true; } MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate) { - if(self.caplayer) + SELFPARAM(); + if (this.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(this) || IS_OBSERVER(this))) + Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CA_LEAVE); return MUT_SPECCMD_FORCE; } @@ -468,34 +481,13 @@ MUTATOR_HOOKFUNCTION(ca, WantWeapon) MUTATOR_HOOKFUNCTION(ca, GetPlayerStatus) { - if(set_player.caplayer == 1) - return true; - return false; + return set_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); - - EliminatedPlayers_Init(ca_isEliminated); + if (ret_string == "0" || ret_string == "") ret_string = "most"; } #endif diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qc b/qcsrc/server/mutators/mutator/gamemode_lms.qc index 77f6b6ca8..cbca46300 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qc +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qc @@ -172,8 +172,6 @@ MUTATOR_HOOKFUNCTION(lms, PutClientInServer) self.classname = STR_OBSERVER; Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_LMS_NOLIVES); } - - return false; } MUTATOR_HOOKFUNCTION(lms, PlayerDies) @@ -204,9 +202,10 @@ MUTATOR_HOOKFUNCTION(lms, ClientDisconnect) } MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver) -{SELFPARAM(); - lms_RemovePlayer(self); - return false; +{ + SELFPARAM(); + lms_RemovePlayer(this); + return true; // prevent team reset } MUTATOR_HOOKFUNCTION(lms, ClientConnect)