From 97c65692317f85cabfc5fa35de8185505cefe7bf Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 27 Aug 2017 16:59:25 +1000 Subject: [PATCH] GameRules: encapsulate player 'VIP' status --- .../gamemodes/gamemode/nexball/nexball.qc | 9 ++++++-- qcsrc/common/gamemodes/sv_rules.qc | 10 ++++++++ qcsrc/common/gamemodes/sv_rules.qh | 10 ++++++-- qcsrc/common/mutators/mutator/nades/nades.qc | 4 ++-- qcsrc/server/defs.qh | 1 - qcsrc/server/mutators/mutator/gamemode_ctf.qc | 4 ++++ .../mutators/mutator/gamemode_keepaway.qc | 23 +++++++++---------- 7 files changed, 42 insertions(+), 19 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index 163cc3854..e65176b22 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -15,6 +15,8 @@ MUTATOR_HOOKFUNCTION(cl_nb, WantEventchase) #ifdef SVQC .float metertime = _STAT(NB_METERSTART); +.entity ballcarried; + int autocvar_g_nexball_goalleadlimit; #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit") @@ -151,6 +153,7 @@ void GiveBall(entity plyr, entity ball) { ownr.effects &= ~autocvar_g_nexball_basketball_effects_default; ownr.ballcarried = NULL; + GameRules_scoring_vip(ownr, false); if(ownr.metertime) { ownr.metertime = 0; @@ -173,6 +176,7 @@ void GiveBall(entity plyr, entity ball) ball.weaponentity_fld = weaponentity; ball.team = plyr.team; plyr.ballcarried = ball; + GameRules_scoring_vip(plyr, true); ball.nb_dropper = plyr; plyr.effects |= autocvar_g_nexball_basketball_effects_default; @@ -230,8 +234,9 @@ void DropBall(entity ball, vector org, vector vel) WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT); - ball.owner.ballcarried = NULL; - ball.owner = NULL; + entity e = ball.owner; ball.owner = NULL; + e.ballcarried = NULL; + GameRules_scoring_vip(e, false); } void InitBall(entity this) diff --git a/qcsrc/common/gamemodes/sv_rules.qc b/qcsrc/common/gamemodes/sv_rules.qc index a4041f047..6da75b931 100644 --- a/qcsrc/common/gamemodes/sv_rules.qc +++ b/qcsrc/common/gamemodes/sv_rules.qc @@ -91,3 +91,13 @@ void _GameRules_scoring_end() { ScoreRules_basics_end(); } + +.bool m_GameRules_scoring_vip; +void GameRules_scoring_vip(entity player, bool value) +{ + player.m_GameRules_scoring_vip = value; +} +bool GameRules_scoring_is_vip(entity player) +{ + return player.m_GameRules_scoring_vip; +} diff --git a/qcsrc/common/gamemodes/sv_rules.qh b/qcsrc/common/gamemodes/sv_rules.qh index 33083b367..55ceb0dfc 100644 --- a/qcsrc/common/gamemodes/sv_rules.qh +++ b/qcsrc/common/gamemodes/sv_rules.qh @@ -23,8 +23,6 @@ void GameRules_limit_time_qualifying(int limit); */ void GameRules_limit_fallbacks(); -// derive score_enabled from !frags_enabled - /** * @param teams a bitmask of active teams * @param spprio player score priority (if frags aren't enabled) @@ -43,3 +41,11 @@ void _GameRules_scoring_begin(int teams, float spprio, float stprio); void _GameRules_scoring_field(entity i, string label, int scoreflags); void _GameRules_scoring_field_team(float i, string label, int scoreflags); void _GameRules_scoring_end(); + +/** + * Mark a player as being 'important' (flag carrier, ball carrier, etc) + * @param player the entity to mark + * @param value VIP status + */ +void GameRules_scoring_vip(entity player, bool value); +bool GameRules_scoring_is_vip(entity player); diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index ae1bbff65..62b0fcf79 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -1240,7 +1240,7 @@ MUTATOR_HOOKFUNCTION(nades, PlayerPreThink) FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; } float time_score; - if(player.flagcarried || player.ballcarried) // this player is important + if(GameRules_scoring_is_vip(player)) time_score = autocvar_g_nades_bonus_score_time_flagcarrier; else time_score = autocvar_g_nades_bonus_score_time; @@ -1379,7 +1379,7 @@ MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST) if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target) nades_RemoveBonus(frag_attacker); - else if(frag_target.flagcarried) + else if(GameRules_scoring_is_vip(frag_target)) nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium); else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1) { diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index d9f614357..4c3b1d221 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -270,7 +270,6 @@ void W_Porto_Remove (entity p); .float bulletcounter; // Nexball -.entity ballcarried; // Also used for keepaway float g_nexball_meter_period; void SUB_DontUseTargets(entity this, entity actor, entity trigger); diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index f54511f2c..b9ddbf5be 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -419,6 +419,7 @@ void ctf_Handle_Retrieve(entity flag, entity player) // transfer flag to player flag.owner = player; flag.owner.flagcarried = flag; + GameRules_scoring_vip(player, true); // reset flag if(player.vehicle) @@ -476,6 +477,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) setattachment(flag, NULL, ""); setorigin(flag, player.origin + FLAG_DROP_OFFSET); flag.owner.flagcarried = NULL; + GameRules_scoring_vip(flag.owner, false); flag.owner = NULL; flag.solid = SOLID_TRIGGER; flag.ctf_dropper = player; @@ -681,6 +683,7 @@ void ctf_Handle_Pickup(entity flag, entity player, int pickuptype) // attach the flag to the player flag.owner = player; player.flagcarried = flag; + GameRules_scoring_vip(player, true); if(player.vehicle) { setattachment(flag, player.vehicle, ""); @@ -1167,6 +1170,7 @@ void ctf_RespawnFlag(entity flag) WaypointSprite_Kill(flag.wps_flagcarrier); flag.owner.flagcarried = NULL; + GameRules_scoring_vip(flag.owner, false); if(flag.speedrunning) ctf_FakeTimeLimit(flag.owner, -1); diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc index 93ec6558b..6196f64d2 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc @@ -2,6 +2,8 @@ #include +.entity ballcarried; + int autocvar_g_keepaway_ballcarrier_effects; float autocvar_g_keepaway_ballcarrier_damage; float autocvar_g_keepaway_ballcarrier_force; @@ -105,6 +107,7 @@ void ka_TouchEvent(entity this, entity toucher) // runs any time that the ball c // attach the ball to the player this.owner = toucher; toucher.ballcarried = this; + GameRules_scoring_vip(toucher, true); setattachment(this, toucher, ""); setorigin(this, '0 0 0'); @@ -159,8 +162,9 @@ void ka_DropEvent(entity plyr) // runs any time that a player is supposed to los ball.effects &= ~EF_NODRAW; setorigin(ball, plyr.origin + '0 0 10'); ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom(); - ball.owner.ballcarried = world; // I hope nothing checks to see if the world has the ball in the rest of my code :P - ball.owner = NULL; + entity e = ball.owner; ball.owner = NULL; + e.ballcarried = NULL; + GameRules_scoring_vip(e, false); navigation_dynamicgoal_set(ball); // reset the player effects @@ -441,12 +445,12 @@ MUTATOR_HOOKFUNCTION(ka, DropSpecialItems) // Initialization // ============== +MODEL(KA_BALL, "models/orbs/orbblue.md3"); + void ka_SpawnBall() // loads various values for the ball, runs only once at start of match { entity e = new(keepawayball); - e.model = "models/orbs/orbblue.md3"; - precache_model(e.model); - _setmodel(e, e.model); + setmodel(e, MDL_KA_BALL); setsize(e, '-16 -16 -20', '16 16 20'); // 20 20 20 was too big, player is only 16 16 24... gotta cheat with the Z (20) axis so that the particle isn't cut off e.damageforcescale = autocvar_g_keepawayball_damageforcescale; e.takedamage = DAMAGE_YES; @@ -466,17 +470,12 @@ void ka_SpawnBall() // loads various values for the ball, runs only once at star InitializeEntity(e, ka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So. } -void ka_ScoreRules() +void ka_Initialize() // run at the start of a match, initiates game mode { GameRules_scoring(0, SFL_SORT_PRIO_PRIMARY, 0, { field(SP_KEEPAWAY_PICKUPS, "pickups", 0); field(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0); field(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY); - }); -} - -void ka_Initialize() // run at the start of a match, initiates game mode -{ - ka_ScoreRules(); + }); ka_SpawnBall(); } -- 2.39.2