]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
GameRules: encapsulate player 'VIP' status
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Aug 2017 06:59:25 +0000 (16:59 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Aug 2017 06:59:25 +0000 (16:59 +1000)
qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
qcsrc/common/gamemodes/sv_rules.qc
qcsrc/common/gamemodes/sv_rules.qh
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/server/defs.qh
qcsrc/server/mutators/mutator/gamemode_ctf.qc
qcsrc/server/mutators/mutator/gamemode_keepaway.qc

index 163cc3854185fbd7b52165fdf6ef0399e1275a44..e65176b22d134756dfe27ab4c1f2aa789e3bef72 100644 (file)
@@ -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)
index a4041f047a9bcf6622b45ec76de27faed441b09c..6da75b9319cc16e59c5dcbb762ec111e2acb9337 100644 (file)
@@ -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;
+}
index 33083b367798ee9f5afb544c054d3d9104a7cab9..55ceb0dfc1e1f32fed2a92827cb055373e3e2932 100644 (file)
@@ -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);
index ae1bbff6525cac70a7348eb46bc4049ae81c76a7..62b0fcf79dfde23b3d0ff10a500b210e9f7e9dd6 100644 (file)
@@ -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)
                {
index d9f614357ce4a6b2bc240247965c36f353c3b413..4c3b1d221ea4ae73be7f0ff7cc7b7ed5d7b9000f 100644 (file)
@@ -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);
index f54511f2c156ee8f36a2d12d7f7231c1710aa471..b9ddbf5beb601a3bcdcc0917a10101c7f4a7b8bd 100644 (file)
@@ -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);
index 93ec6558b6778f7bc70e5c91b95784988e1414d9..6196f64d2115bd51a5919153a598ec2e332b6277 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <common/effects/all.qh>
 
+.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();
 }