]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_ctf.qc
Better use of TRUE/FALSE in gamemode_ctf.qc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_ctf.qc
index dd16e17681249f9c92f7c493174b4200741992e8..b0c4c4c400f6bfa25734fa9f9bcf6d5f1cfadb31 100644 (file)
@@ -1,16 +1,8 @@
 // ================================================================
 //  Official capture the flag game mode coding, reworked by Samual
-//  Last updated: March 30th, 2012
+//  Last updated: September, 2012
 // ================================================================
 
-float ctf_ReadScore(string parameter) // make this obsolete
-{
-       //if(g_ctf_win_mode != 2)
-               return cvar(strcat("g_ctf_personal", parameter));
-       //else
-       //      return cvar(strcat("g_ctf_flag", parameter));
-}
-
 void ctf_FakeTimeLimit(entity e, float t)
 {
        msg_entity = e;
@@ -184,7 +176,7 @@ void ctf_Handle_Drop(entity flag, entity player, float droptype)
        ctf_EventLog("dropped", player.team, player);
 
        // scoring
-       PlayerTeamScore_AddScore(player, -ctf_ReadScore("penalty_drop"));       
+       PlayerTeamScore_AddScore(player, -autocvar_g_ctf_score_penalty_drop);   
        PlayerScore_Add(player, SP_CTF_DROPS, 1);
        
        // waypoints
@@ -212,7 +204,6 @@ void ctf_Handle_Retrieve(entity flag, entity player)
        entity sender = flag.pass_sender;
        
        // transfer flag to player
-       flag.ctf_carrier = player;
        flag.owner = player;
        flag.owner.flagcarried = flag;
        
@@ -222,19 +213,18 @@ void ctf_Handle_Retrieve(entity flag, entity player)
        flag.movetype = MOVETYPE_NONE;
        flag.takedamage = DAMAGE_NO;
        flag.solid = SOLID_NOT;
-       flag.ctf_carrier = player;
        flag.ctf_status = FLAG_CARRY;
 
        // messages and sounds
-       sound(player, CH_TRIGGER, "keepaway/respawn.wav", VOL_BASE, ATTN_NORM); // FIXCTF
-       ctf_EventLog("recieve", flag.team, player);
+       sound(player, CH_TRIGGER, flag.snd_flag_pass, VOL_BASE, ATTN_NORM);
+       ctf_EventLog("receive", flag.team, player);
        
        FOR_EACH_REALPLAYER(tmp_player)
        {
                if(tmp_player == sender)
                        centerprint(tmp_player, strcat("You passed the ", flag.netname, " to ", player.netname));
                else if(tmp_player == player)
-                       centerprint(tmp_player, strcat("You recieved the ", flag.netname, " from ", sender.netname));
+                       centerprint(tmp_player, strcat("You received the ", flag.netname, " from ", sender.netname));
                else if(!IsDifferentTeam(tmp_player, sender))
                        centerprint(tmp_player, strcat(sender.netname, " passed the ", flag.netname, " to ", player.netname));
        }
@@ -244,17 +234,18 @@ void ctf_Handle_Retrieve(entity flag, entity player)
        
        sender.throw_antispam = time + autocvar_g_ctf_pass_wait;
        player.throw_antispam = sender.throw_antispam;
-       
+
        flag.pass_sender = world;
        flag.pass_target = world;
 }
 
-void ctf_Handle_Throw(entity player, entity reciever, float droptype)
+void ctf_Handle_Throw(entity player, entity receiver, float droptype)
 {
        entity flag = player.flagcarried;
+       vector targ_origin, flag_velocity;
        
        if(!flag) { return; }
-       if((droptype == DROP_PASS) && !reciever) { return; }
+       if((droptype == DROP_PASS) && !receiver) { return; }
        
        if(flag.speedrunning) { ctf_RespawnFlag(flag); return; }
        
@@ -264,6 +255,7 @@ void ctf_Handle_Throw(entity player, entity reciever, float droptype)
        flag.owner.flagcarried = world;
        flag.owner = world;
        flag.solid = SOLID_TRIGGER;
+       flag.ctf_dropper = player;
        flag.ctf_droptime = time;
        
        flag.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND for MOVETYPE_TOSS
@@ -272,7 +264,8 @@ void ctf_Handle_Throw(entity player, entity reciever, float droptype)
        {
                case DROP_PASS:
                {
-                       vector targ_origin = (0.5 * (reciever.absmin + reciever.absmax));
+                       WarpZone_RefSys_Copy(flag, receiver);
+                       targ_origin = WarpZone_RefSys_TransformOrigin(receiver, flag, (0.5 * (receiver.absmin + receiver.absmax)));
                        flag.velocity = (normalize(targ_origin - player.origin) * autocvar_g_ctf_pass_velocity);
                        break;
                }
@@ -280,7 +273,8 @@ void ctf_Handle_Throw(entity player, entity reciever, float droptype)
                case DROP_THROW:
                {
                        makevectors((player.v_angle_y * '0 1 0') + (player.v_angle_x * '0.5 0 0'));
-                       flag.velocity = W_CalculateProjectileVelocity(player.velocity, ('0 0 200' + (v_forward * autocvar_g_ctf_drop_velocity)), FALSE);
+                       flag_velocity = ('0 0 200' + ((v_forward * autocvar_g_ctf_drop_velocity) * ((player.items & IT_STRENGTH) ? autocvar_g_ctf_drop_strengthmultiplier : 1)));
+                       flag.velocity = W_CalculateProjectileVelocity(player.velocity, flag_velocity, FALSE);
                        break;
                }
                
@@ -306,13 +300,13 @@ void ctf_Handle_Throw(entity player, entity reciever, float droptype)
                        flag.movetype = MOVETYPE_FLY;
                        flag.takedamage = DAMAGE_NO;
                        flag.pass_sender = player;
-                       flag.pass_target = reciever;
+                       flag.pass_target = receiver;
                        flag.ctf_status = FLAG_PASSING;
                        
                        // other
                        sound(player, CH_TRIGGER, flag.snd_flag_touch, VOL_BASE, ATTN_NORM);
+                       WarpZone_TrailParticles(world, particleeffectnum(flag.passeffect), targ_origin, player.origin);
                        ctf_EventLog("pass", flag.team, player);
-                       te_lightning2(world, reciever.origin, player.origin);
                        break;
                }
 
@@ -336,7 +330,7 @@ void ctf_Handle_Throw(entity player, entity reciever, float droptype)
        WaypointSprite_Kill(player.wps_flagcarrier);
        
        if(player.wps_enemyflagcarrier)
-                       WaypointSprite_Kill(player.wps_enemyflagcarrier);
+               WaypointSprite_Kill(player.wps_enemyflagcarrier);
        
        // captureshield
        ctf_CaptureShield_Update(player, 0); // shield player from picking up flag
@@ -351,6 +345,7 @@ void ctf_Handle_Capture(entity flag, entity toucher, float capturetype)
 {
        entity enemy_flag = ((capturetype == CAPTURE_NORMAL) ? toucher.flagcarried : toucher);
        entity player = ((capturetype == CAPTURE_NORMAL) ? toucher : enemy_flag.ctf_dropper);
+       float old_time, new_time; 
        
        if not(player) { return; } // without someone to give the reward to, we can't possibly cap
        
@@ -366,9 +361,14 @@ void ctf_Handle_Capture(entity flag, entity toucher, float capturetype)
        }
        
        // scoring
-       PlayerTeamScore_AddScore(player, ctf_ReadScore("score_capture"));
+       PlayerTeamScore_AddScore(player, autocvar_g_ctf_score_capture);
        PlayerTeamScore_Add(player, SP_CTF_CAPS, ST_CTF_CAPS, 1);
 
+       old_time = PlayerScore_Add(player, SP_CTF_CAPTIME, 0);
+       new_time = TIME_ENCODE(time - enemy_flag.ctf_pickuptime);
+       if(!old_time || new_time < old_time)
+               PlayerScore_Add(player, SP_CTF_CAPTIME, new_time - old_time);
+
        // effects
        if(autocvar_g_ctf_flag_capture_effects) 
        {
@@ -381,6 +381,9 @@ void ctf_Handle_Capture(entity flag, entity toucher, float capturetype)
        {
                WaypointSprite_Kill(player.wps_flagcarrier);
                if(flag.speedrunning) { ctf_FakeTimeLimit(player, -1); }
+               
+               if((enemy_flag.ctf_dropper) && (player != enemy_flag.ctf_dropper))
+                       { PlayerTeamScore_AddScore(enemy_flag.ctf_dropper, autocvar_g_ctf_score_capture_assist); }
        }
        
        // reset the flag
@@ -397,14 +400,14 @@ void ctf_Handle_Return(entity flag, entity player)
        ctf_EventLog("return", flag.team, player);
 
        // scoring
-       PlayerTeamScore_AddScore(player, ctf_ReadScore("score_return")); // reward for return
+       PlayerTeamScore_AddScore(player, autocvar_g_ctf_score_return); // reward for return
        PlayerScore_Add(player, SP_CTF_RETURNS, 1); // add to count of returns
 
-       TeamScore_AddToTeam(flag.team, ST_SCORE, -ctf_ReadScore("penalty_returned")); // punish the team who was last carrying it
+       TeamScore_AddToTeam(flag.team, ST_SCORE, -autocvar_g_ctf_score_penalty_returned); // punish the team who was last carrying it
        
        if(flag.ctf_dropper) 
        {
-               PlayerScore_Add(flag.ctf_dropper, SP_SCORE, -ctf_ReadScore("penalty_returned")); // punish the player who dropped the flag
+               PlayerScore_Add(flag.ctf_dropper, SP_SCORE, -autocvar_g_ctf_score_penalty_returned); // punish the player who dropped the flag
                ctf_CaptureShield_Update(flag.ctf_dropper, 0); // shield player from picking up flag 
                flag.ctf_dropper.next_take_time = time + autocvar_g_ctf_flag_collect_delay; // set next take time
        }
@@ -431,7 +434,6 @@ void ctf_Handle_Pickup(entity flag, entity player, float pickuptype)
        flag.takedamage = DAMAGE_NO;
        flag.solid = SOLID_NOT;
        flag.angles = '0 0 0';
-       flag.ctf_carrier = player;
        flag.ctf_status = FLAG_CARRY;
        
        switch(pickuptype)
@@ -469,14 +471,14 @@ void ctf_Handle_Pickup(entity flag, entity player, float pickuptype)
        {               
                case PICKUP_BASE:
                {
-                       PlayerTeamScore_AddScore(player, ctf_ReadScore("score_pickup_base"));
+                       PlayerTeamScore_AddScore(player, autocvar_g_ctf_score_pickup_base);
                        break;
                }
                
                case PICKUP_DROPPED:
                {
                        pickup_dropped_score = (autocvar_g_ctf_flag_return_time ? bound(0, ((flag.ctf_droptime + autocvar_g_ctf_flag_return_time) - time) / autocvar_g_ctf_flag_return_time, 1) : 1);
-                       pickup_dropped_score = floor((ctf_ReadScore("score_pickup_dropped_late") * (1 - pickup_dropped_score) + ctf_ReadScore("score_pickup_dropped_early") * pickup_dropped_score) + 0.5);
+                       pickup_dropped_score = floor((autocvar_g_ctf_score_pickup_dropped_late * (1 - pickup_dropped_score) + autocvar_g_ctf_score_pickup_dropped_early * pickup_dropped_score) + 0.5);
                        print("pickup_dropped_score is ", ftos(pickup_dropped_score), "\n");
                        PlayerTeamScore_AddScore(player, pickup_dropped_score);
                        break;
@@ -531,6 +533,59 @@ void ctf_CheckFlagReturn(entity flag, float returntype)
        }
 }
 
+void ctf_CheckStalemate(void)
+{
+       // declarations
+       float stale_red_flags, stale_blue_flags;
+       entity tmp_entity;
+
+       entity ctf_staleflaglist; // reset the list, we need to build the list each time this function runs
+
+       // build list of stale flags
+       for(tmp_entity = ctf_worldflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_worldflagnext)
+       {
+               if(autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
+               if(tmp_entity.ctf_status != FLAG_BASE)
+               if(time >= tmp_entity.ctf_pickuptime + autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
+               {
+                       tmp_entity.ctf_staleflagnext = ctf_staleflaglist; // link flag into staleflaglist
+                       ctf_staleflaglist = tmp_entity;
+                       
+                       switch(tmp_entity.team)
+                       {
+                               case COLOR_TEAM1: ++stale_red_flags; break;
+                               case COLOR_TEAM2: ++stale_blue_flags; break;
+                       }
+               }
+       }
+
+       if(stale_red_flags && stale_blue_flags)
+               ctf_stalemate = TRUE;
+       else if(!stale_red_flags && !stale_blue_flags)
+               ctf_stalemate = FALSE;
+       
+       // if sufficient stalemate, then set up the waypointsprite and announce the stalemate if necessary
+       if(ctf_stalemate)
+       {
+               for(tmp_entity = ctf_staleflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_staleflagnext)
+               {
+                       if((tmp_entity.owner) && (!tmp_entity.owner.wps_enemyflagcarrier))
+                               WaypointSprite_Spawn("enemyflagcarrier", 0, 0, tmp_entity.owner, FLAG_WAYPOINT_OFFSET, world, tmp_entity.team, tmp_entity.owner, wps_enemyflagcarrier, TRUE, RADARICON_FLAG, WPCOLOR_ENEMYFC(tmp_entity.owner.team));
+               }
+               
+               if not(wpforenemy_announced)
+               {
+                       FOR_EACH_REALPLAYER(tmp_entity)
+                               if(tmp_entity.flagcarried)
+                                       centerprint(tmp_entity, "Stalemate! Enemies can now see you on radar!");
+                               else
+                                       centerprint(tmp_entity, "Stalemate! Flag carriers can now be seen by enemies on radar!");
+                       
+                       wpforenemy_announced = TRUE;
+               }
+       }
+}
+
 void ctf_FlagDamage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
        if(ITEM_DAMAGE_NEEDKILL(deathtype))
@@ -540,7 +595,6 @@ void ctf_FlagDamage(entity inflictor, entity attacker, float damage, float death
                ctf_CheckFlagReturn(self, RETURN_NEEDKILL);
                return;
        }
-       
        if(autocvar_g_ctf_flag_return_damage) 
        {
                // reduce health and check if it should be returned
@@ -598,9 +652,20 @@ void ctf_FlagThink()
                
                case FLAG_DROPPED:
                {
-                       if(autocvar_g_ctf_flag_dropped_floatinwater && (self.flags & FL_INWATER))
-                                       self.velocity_z = autocvar_g_ctf_flag_dropped_floatinwater;
-               
+                       if(autocvar_g_ctf_flag_dropped_floatinwater)
+                       {
+                               vector midpoint = ((self.absmin + self.absmax) * 0.5);
+                               if(pointcontents(midpoint) == CONTENT_WATER)
+                               {
+                                       self.velocity = self.velocity * 0.5;
+                                       
+                                       if(pointcontents(midpoint + FLAG_FLOAT_OFFSET) == CONTENT_WATER)
+                                               { self.velocity_z = autocvar_g_ctf_flag_dropped_floatinwater; }
+                                       else
+                                               { self.movetype = MOVETYPE_FLY; }
+                               }
+                               else if(self.movetype == MOVETYPE_FLY) { self.movetype = MOVETYPE_TOSS; }
+                       }
                        if(autocvar_g_ctf_flag_return_dropped)
                        {
                                if((vlen(self.origin - self.ctf_spawnorigin) <= autocvar_g_ctf_flag_return_dropped) || (autocvar_g_ctf_flag_return_dropped == -1))
@@ -632,34 +697,25 @@ void ctf_FlagThink()
                                ImpulseCommands();
                                self = tmp_entity;
                        }
-                       
-                       if(autocvar_g_ctf_flagcarrier_waypointforenemy_time)
-                       if((time >= self.ctf_pickuptime + autocvar_g_ctf_flagcarrier_waypointforenemy_time) && !self.owner.wps_enemyflagcarrier)
+                       if(autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
                        {
-                               WaypointSprite_Spawn("enemyflagcarrier", 0, 0, self.owner, FLAG_WAYPOINT_OFFSET, world, self.team, self.owner, wps_enemyflagcarrier, TRUE, RADARICON_FLAG, WPCOLOR_ENEMYFC(self.owner.team));
-                               
-                               if(!self.wpforenemy_announced)
+                               if(time >= wpforenemy_nextthink)
                                {
-                                       FOR_EACH_REALPLAYER(tmp_entity)
-                                       {
-                                               if(tmp_entity == self.owner)
-                                                       centerprint(tmp_entity, strcat("Enemies can now see you on radar! (held ", self.netname, " for ", ftos(autocvar_g_ctf_flagcarrier_waypointforenemy_time), " seconds)"));
-                                               else if(IsDifferentTeam(tmp_entity, self.owner))
-                                                       centerprint(tmp_entity, strcat("You can now see the enemy flag carrier on radar! (held ", self.netname, " for ", ftos(autocvar_g_ctf_flagcarrier_waypointforenemy_time), " seconds)"));
-                                               else
-                                                       centerprint(tmp_entity, strcat("Enemies can now see your flag carrier on radar! (held ", self.netname, " for ", ftos(autocvar_g_ctf_flagcarrier_waypointforenemy_time), " seconds)"));
-                                       }
-                                       
-                                       self.wpforenemy_announced = TRUE;
+                                       ctf_CheckStalemate();
+                                       wpforenemy_nextthink = time + WPFE_THINKRATE; // waypoint for enemy think rate (to reduce unnecessary spam of this check)
                                }
                        }
                        return;
                }
                
                case FLAG_PASSING: // todo make work with warpzones
-               {                       
+               {
                        vector targ_origin = ((self.pass_target.absmin + self.pass_target.absmax) * 0.5);
-                       traceline(self.origin, targ_origin, MOVE_NOMONSTERS, self);
+                       vector old_targ_origin = targ_origin;
+                       targ_origin = WarpZone_RefSys_TransformOrigin(self.pass_target, self, targ_origin);
+                       WarpZone_TraceLine(self.origin, targ_origin, MOVE_NOMONSTERS, self);
+
+                       print(strcat("self: ", vtos(self.origin), ", old: ", vtos(old_targ_origin), " (", ftos(vlen(self.origin - old_targ_origin)), "qu)"), ", transformed: ", vtos(targ_origin), " (", ftos(vlen(self.origin - targ_origin)), "qu)", ".\n");
                        
                        if((self.pass_target.deadflag != DEAD_NO)
                                || (vlen(self.origin - targ_origin) > autocvar_g_ctf_pass_radius)
@@ -672,7 +728,7 @@ void ctf_FlagThink()
                        {
                                vector desired_direction = normalize(targ_origin - self.origin);
                                vector current_direction = normalize(self.velocity);
-                               
+
                                self.velocity = (normalize(current_direction + (desired_direction * autocvar_g_ctf_pass_turnrate)) * autocvar_g_ctf_pass_velocity); 
                        }
                        return;
@@ -712,7 +768,7 @@ void ctf_FlagTouch()
        {
                if(time > self.wait) // if we haven't in a while, play a sound/effect
                {
-                       pointparticles(particleeffectnum("kaball_sparks"), self.origin, '0 0 0', 1);
+                       pointparticles(particleeffectnum(self.toucheffect), self.origin, '0 0 0', 1);
                        sound(self, CH_TRIGGER, self.snd_flag_touch, VOL_BASE, ATTN_NORM);
                        self.wait = time + FLAG_TOUCHRATE;
                }
@@ -757,12 +813,6 @@ void ctf_FlagTouch()
                        }
                        break;
                }
-               
-               default: // this should never happen
-               {
-                       dprint("Touch: Flag exists with no status?\n");
-                       break;
-               }
        }
 }
 
@@ -801,11 +851,11 @@ void ctf_RespawnFlag(entity flag)
        flag.owner = world;
        flag.pass_sender = world;
        flag.pass_target = world;
-       flag.ctf_carrier = world;
        flag.ctf_dropper = world;
        flag.ctf_pickuptime = 0;
        flag.ctf_droptime = 0;
-       flag.wpforenemy_announced = FALSE;
+
+       wpforenemy_announced = FALSE;
 }
 
 void ctf_Reset()
@@ -871,6 +921,8 @@ void ctf_FlagSetup(float teamnumber, entity flag) // called when spawning a flag
        if(!flag.model) { flag.model = ((teamnumber) ? autocvar_g_ctf_flag_red_model : autocvar_g_ctf_flag_blue_model); }
        if(!flag.scale) { flag.scale = FLAG_SCALE; }
        if(!flag.skin) { flag.skin = ((teamnumber) ? autocvar_g_ctf_flag_red_skin : autocvar_g_ctf_flag_blue_skin); }
+       if(!flag.toucheffect) { flag.toucheffect = ((teamnumber) ? "redflag_touch" : "blueflag_touch"); }
+       if(!flag.passeffect) { flag.passeffect = ((!teamnumber) ? "red_pass" : "blue_pass"); } // invert the team number of the flag to pass as enemy team color
        
        // sound 
        if(!flag.snd_flag_taken) { flag.snd_flag_taken  = ((teamnumber) ? "ctf/red_taken.wav" : "ctf/blue_taken.wav"); }
@@ -878,7 +930,8 @@ void ctf_FlagSetup(float teamnumber, entity flag) // called when spawning a flag
        if(!flag.snd_flag_capture) { flag.snd_flag_capture = ((teamnumber) ? "ctf/red_capture.wav" : "ctf/blue_capture.wav"); } // blue team scores by capturing the red flag
        if(!flag.snd_flag_respawn) { flag.snd_flag_respawn = "ctf/flag_respawn.wav"; } // if there is ever a team-based sound for this, update the code to match.
        if(!flag.snd_flag_dropped) { flag.snd_flag_dropped = ((teamnumber) ? "ctf/red_dropped.wav" : "ctf/blue_dropped.wav"); }
-       if(!flag.snd_flag_touch) { flag.snd_flag_touch = "keepaway/touch.wav"; } // again has no team-based sound // FIXME
+       if(!flag.snd_flag_touch) { flag.snd_flag_touch = "ctf/touch.wav"; } // again has no team-based sound
+       if(!flag.snd_flag_pass) { flag.snd_flag_pass = "ctf/pass.wav"; } // same story here
        
        // precache
        precache_sound(flag.snd_flag_taken);
@@ -887,6 +940,7 @@ void ctf_FlagSetup(float teamnumber, entity flag) // called when spawning a flag
        precache_sound(flag.snd_flag_respawn);
        precache_sound(flag.snd_flag_dropped);
        precache_sound(flag.snd_flag_touch);
+       precache_sound(flag.snd_flag_pass);
        precache_model(flag.model);
        precache_model("models/ctf/shield.md3");
        precache_model("models/ctf/shockwavetransring.md3");
@@ -941,13 +995,23 @@ MUTATOR_HOOKFUNCTION(ctf_PlayerPreThink)
        // scan through all the flags and notify the client about them 
        for(flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext)
        {
-               if(flag.ctf_status == FLAG_CARRY)
-                       if(flag.owner == self)
-                               self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_CARRYING : IT_BLUE_FLAG_CARRYING); // carrying: self is currently carrying the flag
-                       else 
-                               self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_TAKEN : IT_BLUE_FLAG_TAKEN); // taken: someone on self's team is carrying the flag
-               else if(flag.ctf_status == FLAG_DROPPED) 
-                       self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_LOST : IT_BLUE_FLAG_LOST); // lost: the flag is dropped somewhere on the map
+               switch(flag.ctf_status)
+               {
+                       case FLAG_PASSING:
+                       case FLAG_CARRY:
+                       {
+                               if((flag.owner == self) || (flag.pass_sender == self))
+                                       self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_CARRYING : IT_BLUE_FLAG_CARRYING); // carrying: self is currently carrying the flag
+                               else 
+                                       self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_TAKEN : IT_BLUE_FLAG_TAKEN); // taken: someone on self's team is carrying the flag
+                               break;
+                       }
+                       case FLAG_DROPPED:
+                       {
+                               self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_LOST : IT_BLUE_FLAG_LOST); // lost: the flag is dropped somewhere on the map
+                               break;
+                       }
+               }
        }
        
        // item for stopping players from capturing the flag too often
@@ -956,9 +1020,9 @@ MUTATOR_HOOKFUNCTION(ctf_PlayerPreThink)
        
        // update the health of the flag carrier waypointsprite
        if(self.wps_flagcarrier) 
-               WaypointSprite_UpdateHealth(self.wps_flagcarrier, self.health);
+               WaypointSprite_UpdateHealth(self.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent));
        
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_PlayerDamage) // for changing damage and force values that are applied to players in g_damage.qc
@@ -970,27 +1034,32 @@ MUTATOR_HOOKFUNCTION(ctf_PlayerDamage) // for changing damage and force values t
                        frag_damage *= autocvar_g_ctf_flagcarrier_selfdamagefactor;
                        frag_force *= autocvar_g_ctf_flagcarrier_selfforcefactor;
                }
-               else // damage done everyone else
+               else // damage done to everyone else
                {
                        frag_damage *= autocvar_g_ctf_flagcarrier_damagefactor;
                        frag_force *= autocvar_g_ctf_flagcarrier_forcefactor;
                }
        }
-       return 0;
+       else if(frag_target.flagcarried && (frag_target.deadflag == DEAD_NO) && IsDifferentTeam(frag_target, frag_attacker)) // if the target is a flagcarrier
+       {
+               if(autocvar_g_ctf_flagcarrier_auto_helpme_when_damaged > ('1 0 0' * healtharmor_maxdamage(frag_target.health, frag_target.armorvalue, autocvar_g_balance_armor_blockpercent)))
+                       WaypointSprite_HelpMePing(frag_target.wps_flagcarrier); // TODO: only do this if there is a significant loss of health?
+       }
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_PlayerDies)
 {
        if((frag_attacker != frag_target) && (frag_attacker.classname == "player") && (frag_target.flagcarried))
        {
-               PlayerTeamScore_AddScore(frag_attacker, ctf_ReadScore("score_kill"));
+               PlayerTeamScore_AddScore(frag_attacker, autocvar_g_ctf_score_kill);
                PlayerScore_Add(frag_attacker, SP_CTF_FCKILLS, 1);
        }
                                
        if(frag_target.flagcarried)
                { ctf_Handle_Throw(frag_target, world, DROP_NORMAL); }
                
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_GiveFragsForKill)
@@ -1004,7 +1073,7 @@ MUTATOR_HOOKFUNCTION(ctf_RemovePlayer)
        if(self.flagcarried)
                { ctf_Handle_Throw(self, world, DROP_NORMAL); }
                
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_PortalTeleport)
@@ -1013,20 +1082,22 @@ MUTATOR_HOOKFUNCTION(ctf_PortalTeleport)
        if(!autocvar_g_ctf_portalteleport)
                { ctf_Handle_Throw(self, world, DROP_NORMAL); }
 
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_PlayerUseKey)
 {
+       if(gameover) { return FALSE; }
+       
        entity player = self;
 
-       if((time > player.throw_antispam) && !player.speedrunning && (!player.vehicle || autocvar_g_ctf_allow_vehicle_touch))
+       if((time > player.throw_antispam) && (player.deadflag == DEAD_NO) && !player.speedrunning && (!player.vehicle || autocvar_g_ctf_allow_vehicle_touch))
        {
                // pass the flag to a team mate
                if(autocvar_g_ctf_pass)
                {
                        entity head, closest_target;
-                       head = findradius(player.origin, autocvar_g_ctf_pass_radius);
+                       head = WarpZone_FindRadius(player.origin, autocvar_g_ctf_pass_radius, TRUE);
                        
                        while(head) // find the closest acceptable target to pass to
                        {
@@ -1034,43 +1105,43 @@ MUTATOR_HOOKFUNCTION(ctf_PlayerUseKey)
                                if(head != player && !IsDifferentTeam(head, player))
                                if(!head.speedrunning && (!head.vehicle || autocvar_g_ctf_allow_vehicle_touch))
                                {
-                                       traceline(player.origin, head.origin, MOVE_NOMONSTERS, player);
-                                       if not((trace_fraction < 1) && (trace_ent != head))
-                                       {
-                                               if(autocvar_g_ctf_pass_request && !player.flagcarried && head.flagcarried) 
-                                               { 
-                                                       if(clienttype(head) == CLIENTTYPE_BOT)
-                                                       {
-                                                               centerprint(player, strcat("Requesting ", head.netname, " to pass you the ", head.flagcarried.netname)); 
-                                                               ctf_Handle_Throw(head, player, DROP_PASS);
-                                                       }
-                                                       else
-                                                       {
-                                                               centerprint(head, strcat(player.netname, " requests you to pass the ", head.flagcarried.netname)); 
-                                                               centerprint(player, strcat("Requesting ", head.netname, " to pass you the ", head.flagcarried.netname)); 
-                                                       }
-                                                       player.throw_antispam = time + autocvar_g_ctf_pass_wait; 
-                                                       return 0; 
+                                       if(autocvar_g_ctf_pass_request && !player.flagcarried && head.flagcarried) 
+                                       { 
+                                               if(clienttype(head) == CLIENTTYPE_BOT)
+                                               {
+                                                       centerprint(player, strcat("Requesting ", head.netname, " to pass you the ", head.flagcarried.netname)); 
+                                                       ctf_Handle_Throw(head, player, DROP_PASS);
                                                }
-                                               else if(player.flagcarried)
+                                               else
+                                               {
+                                                       centerprint(head, strcat(player.netname, " requests you to pass the ", head.flagcarried.netname)); 
+                                                       centerprint(player, strcat("Requesting ", head.netname, " to pass you the ", head.flagcarried.netname)); 
+                                               }
+                                               player.throw_antispam = time + autocvar_g_ctf_pass_wait; 
+                                               return TRUE; 
+                                       }
+                                       else if(player.flagcarried)
+                                       {
+                                               if(closest_target)
                                                {
-                                                       if(closest_target) { if(vlen(player.origin - head.origin) < vlen(player.origin - closest_target.origin)) { closest_target = head; } }
-                                                       else { closest_target = head; }
+                                                       if(vlen(player.origin - WarpZone_UnTransformOrigin(head, head.origin)) < vlen(player.origin - WarpZone_UnTransformOrigin(closest_target, closest_target.origin)))
+                                                               { closest_target = head; }
                                                }
+                                               else { closest_target = head; }
                                        }
                                }
                                head = head.chain;
                        }
                        
-                       if(closest_target) { ctf_Handle_Throw(player, closest_target, DROP_PASS); return 0; }
+                       if(closest_target) { ctf_Handle_Throw(player, closest_target, DROP_PASS); return TRUE; }
                }
                
                // throw the flag in front of you
                if(autocvar_g_ctf_drop && player.flagcarried)
-                       { ctf_Handle_Throw(player, world, DROP_THROW); }
+                       { ctf_Handle_Throw(player, world, DROP_THROW); return TRUE; }
        }
                
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_HelpMePing)
@@ -1085,40 +1156,41 @@ MUTATOR_HOOKFUNCTION(ctf_HelpMePing)
                WaypointSprite_Ping(self.wps_helpme);
        }
 
-       return 1;
+       return TRUE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_VehicleEnter)
 {
-       if(other.flagcarried)
+       if(vh_player.flagcarried)
        {
                if(!autocvar_g_ctf_flagcarrier_allow_vehicle_carry)
                {
-                       ctf_Handle_Throw(self, world, DROP_NORMAL);
+                       ctf_Handle_Throw(vh_player, world, DROP_NORMAL);
                }
                else
                {            
-                       setattachment(other.flagcarried, self, ""); 
-                       setorigin(other, VEHICLE_FLAG_OFFSET);
-                       other.flagcarried.scale = VEHICLE_FLAG_SCALE;
-                       //other.flagcarried.angles = '0 0 0';   
+                       setattachment(vh_player.flagcarried, vh_vehicle, ""); 
+                       setorigin(vh_player.flagcarried, VEHICLE_FLAG_OFFSET);
+                       vh_player.flagcarried.scale = VEHICLE_FLAG_SCALE;
+                       //vh_player.flagcarried.angles = '0 0 0';       
                }
        }
                
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_VehicleExit)
 {
-       if(self.owner.flagcarried)
+       if(vh_player.flagcarried)
        {
-               setattachment(self.owner.flagcarried, self.owner, ""); 
-               setorigin(self.owner.flagcarried, FLAG_CARRY_OFFSET);
-               self.owner.flagcarried.scale = FLAG_SCALE;
-               self.owner.flagcarried.angles = '0 0 0';        
+               setattachment(vh_player.flagcarried, vh_player, ""); 
+               setorigin(vh_player.flagcarried, FLAG_CARRY_OFFSET);
+               vh_player.flagcarried.scale = FLAG_SCALE;
+               vh_player.flagcarried.angles = '0 0 0';
+               return TRUE;
        }
 
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_AbortSpeedrun)
@@ -1127,9 +1199,10 @@ MUTATOR_HOOKFUNCTION(ctf_AbortSpeedrun)
        {
                bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
                ctf_RespawnFlag(self);
+               return TRUE;
        }
        
-       return 0;
+       return FALSE;
 }
 
 MUTATOR_HOOKFUNCTION(ctf_MatchEnd)
@@ -1147,7 +1220,7 @@ MUTATOR_HOOKFUNCTION(ctf_MatchEnd)
                                flag.movetype = MOVETYPE_NONE;
                                flag.takedamage = DAMAGE_NO;
                                flag.solid = SOLID_NOT;
-                               flag.nextthink = 0; // stop thinking
+                               flag.nextthink = FALSE; // stop thinking
                                
                                print("stopping the ", flag.netname, " from moving.\n");
                                break;
@@ -1163,7 +1236,7 @@ MUTATOR_HOOKFUNCTION(ctf_MatchEnd)
                }
        }
        
-       return 0;
+       return FALSE;
 }