]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge remote-tracking branch 'origin/master' into samual/mutator_ctf
authorSamual Lenks <samual@xonotic.org>
Wed, 29 Aug 2012 05:14:44 +0000 (01:14 -0400)
committerSamual Lenks <samual@xonotic.org>
Wed, 29 Aug 2012 05:14:44 +0000 (01:14 -0400)
Conflicts:
qcsrc/server/mutators/base.qh
qcsrc/server/progs.src
qcsrc/server/vehicles/vehicles.qc
vehicles.cfg

31 files changed:
defaultXonotic.cfg
qcsrc/client/announcer.qc
qcsrc/client/autocvars.qh
qcsrc/client/waypointsprites.qc
qcsrc/common/items.qh
qcsrc/server/attic/monsters/m_monsters.qc
qcsrc/server/attic/nexball.qc
qcsrc/server/autocvars.qh
qcsrc/server/bot/havocbot/role_ctf.qc
qcsrc/server/cheats.qc
qcsrc/server/cl_client.qc
qcsrc/server/cl_impulse.qc
qcsrc/server/cl_player.qc
qcsrc/server/constants.qh
qcsrc/server/defs.qh
qcsrc/server/g_damage.qc
qcsrc/server/g_triggers.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/base.qh
qcsrc/server/mutators/gamemode_ctf.qc [new file with mode: 0644]
qcsrc/server/mutators/gamemode_ctf.qh [new file with mode: 0644]
qcsrc/server/mutators/gamemode_nexball.qc
qcsrc/server/mutators/mutators.qh
qcsrc/server/portals.qc
qcsrc/server/progs.src
qcsrc/server/t_teleporters.qc
qcsrc/server/teamplay.qc
qcsrc/server/tturrets/units/unit_ewheel.qc
qcsrc/server/tturrets/units/unit_walker.qc
qcsrc/server/vehicles/vehicles.qc
vehicles.cfg

index cad7ac396b1d568824e0eedb64faf2591d4ea53f..31073b05b226366f4bcb71d882f87c4ad1de2ffb 100644 (file)
@@ -599,15 +599,39 @@ set gamecfg 1     // "deathmatch"
 
 // ctf
 set g_ctf 0 "Capture The Flag: take the enemy flag and bring it to yours at your base to score"
-set g_ctf_flag_returntime 30
-set g_ctf_flagcarrier_selfdamage 1
-set g_ctf_flagcarrier_selfforce 1
+set g_ctf_flag_return_time 15
+set g_ctf_flag_return_dropped 100
+set g_ctf_flag_return_damage 0
+set g_ctf_flag_return_when_unreachable 1 "automatically return the flag if it falls into lava/slime/trigger hurt"
+set g_ctf_flagcarrier_auto_helpme_when_damaged 50
+set g_ctf_flagcarrier_allow_vehicle_carry 1 
+set g_ctf_flagcarrier_selfdamagefactor 1
+set g_ctf_flagcarrier_selfforcefactor 1
+set g_ctf_flagcarrier_damagefactor 1
+set g_ctf_flagcarrier_forcefactor 1
+set g_ctf_flagcarrier_waypointforenemy_stalemate 30 "show the enemy flagcarrier location after both teams have held the flags for this amount of time"
+set g_ctf_flagcarrier_waypointforenemy_spotting 1 "show the enemy flagcarrier location if a team mate presses +use to spot them"
+set g_ctf_dropped_capture_radius 100 "allow dropped flags to be automatically captured by base flags if the dropped flag is within this radius of it"
 set g_ctf_fullbrightflags 0
 set g_ctf_dynamiclights 0
-set g_ctf_allow_drop 1 "dropping allows circumventing carrierkill score, so enable this with care!"
+set g_ctf_flag_damageforcescale 2
+set g_ctf_portalteleport 0 "allow flag carriers to go through portals made in portal gun without dropping the flag"
 set g_ctf_reverse 0    "if enabled, flags positions are switched: you have to capture the enemy's flag from your own base by bringing it to your own flag in the enemy base"
-set g_balance_ctf_delay_collect 1.0
-set g_balance_ctf_damageforcescale 1
+set g_ctf_flag_collect_delay 1
+set g_ctf_flag_health 0
+set g_ctf_flag_dropped_waypoint 2 "show dropped flag waypointsprite when a flag is lost. 1 = team only, 2 = for all players"
+set g_ctf_flag_dropped_floatinwater 200 "move upwards while in water at this velocity"
+set g_ctf_flag_pickup_verbosename 0 "show the name of the person who picked up the flag too"
+set g_ctf_drop 1 "dropping allows circumventing carrierkill score, so enable this with care!"
+set g_ctf_drop_velocity 500 "how fast or far a player can throw the flag"
+set g_ctf_pass 1 "allow passing of flags to nearby team mates"
+set g_ctf_pass_radius 500 "maximum radius that you can pass to a team mate in"
+set g_ctf_pass_wait 2 "delay in seconds between how often players can pass the flag (antispam, essentially)"
+set g_ctf_pass_request 1 "allow players to request the flag carrier to pass the flag to them"
+set g_ctf_pass_turnrate 50 "how well the flag follows the best direction to its target while passing"
+set g_ctf_pass_timelimit 2 "how long a flag can stay trying to pass before it gives up and just becomes dropped"
+set g_ctf_pass_velocity 750 "how fast or far a player can pass the flag"
+set g_ctf_allow_vehicle_touch 1 "allow flags to be picked up/captured/returned from inside a vehicle
 
 set g_ctf_shield_max_ratio 0   "shield at most this percentage of a team from the enemy flag (try: 0.4 for 40%)"
 set g_ctf_shield_min_negscore 20       "shield the player from the flag if he's got this negative amount of points or less"
@@ -879,7 +903,6 @@ sv_sound_watersplash ""
 seta cl_announcer default "name of the announcer you wish to use from data/sound/announcer"
 seta cl_announcer_antispam 2 "number of seconds before an announcement of the same sound can be played again"
 seta cl_announcer_maptime 3 "play announcer sound telling you the remaining maptime - 0: do not play at all, 1: play at one minute, 2: play at five minutes, 3: play both"
-seta cl_notify_carried_items "3" "notify you of carried items when you obtain them (e.g. flags in CTF) - 0: disabled, 1: notify of taken items, 2: notify of picking up dropped items, 3: notify of both"
 
 // startmap_dm is used when running with the -listen or -dedicated commandline options
 set serverconfig server.cfg
index 3e109e78052036fd77f33f88b5138e12844f4418..db1ae41336d5e1eb54d30c437975b7323b330739 100644 (file)
@@ -134,52 +134,10 @@ void Announcer_Time()
        }
 }
 
-float redflag_prev;
-float blueflag_prev;
-void carrierAnnouncer() {
-       float stat_items, redflag, blueflag;
-       float pickup;
-       string item;
-
-       if not(autocvar_cl_notify_carried_items)
-               return;
-
-       stat_items = getstati(STAT_ITEMS);
-
-       redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
-       blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
-
-       if (redflag == 3 && redflag != redflag_prev) {
-               item = _("^1RED^7 flag");
-               pickup = (redflag_prev == 2);
-       }
-
-       if (blueflag == 3 && blueflag != blueflag_prev) {
-               item = _("^4BLUE^7 flag");
-               pickup = (blueflag_prev == 2);
-       }
-
-       if (item)
-       {
-               if (pickup) {
-                       if (autocvar_cl_notify_carried_items & 2)
-                               centerprint_hud(sprintf(_("You picked up the %s!"), item));
-               }
-               else {
-                       if (autocvar_cl_notify_carried_items & 1)
-                               centerprint_hud(sprintf(_("You got the %s!"), item));
-               }
-       }
-
-       blueflag_prev = blueflag;
-       redflag_prev = redflag;
-}
-
 void Announcer()
 {
        Announcer_Gamestart();
        Announcer_Time();
-       carrierAnnouncer();
 }
 
 void Announcer_Precache () 
index dd482a8f252a73de57d9a51ee3976df07e4a5662..ee402287283d690259ff9bffcc6e89e56d94a555 100644 (file)
@@ -54,7 +54,6 @@ float autocvar_cl_gunalign;
 float autocvar_cl_hidewaypoints;
 float autocvar_cl_lockview;
 float autocvar_cl_nogibs;
-float autocvar_cl_notify_carried_items;
 float autocvar_cl_particlegibs;
 float autocvar_cl_particles_oldnexbeam;
 float autocvar_cl_particles_quality;
index 513c66eb8b9ca96623a1eb7c55ccab0de2e38103..d3d57aba9e8cbcd52ad7606466f912dc394032a9 100644 (file)
@@ -256,6 +256,7 @@ string spritelookuptext(string s)
                case "as-defend": return _("Defend");
                case "bluebase": return _("Blue base");
                case "danger": return _("DANGER");
+               case "enemyflagcarrier": return _("Enemy carrier");
                case "flagcarrier": return _("Flag carrier");
                case "flagdropped": return _("Dropped flag");
                case "helpme": return _("Help me!");
index 33fa21f7eeef5fb96bb0986971ce5223f27d0979..c20715d5852c3cbf09eae967424bf50d2a6754b2 100644 (file)
@@ -31,16 +31,16 @@ float   IT_STRENGTH                  = 8192;
 float   IT_INVINCIBLE                = 16384;
 float   IT_HEALTH                    = 32768;
 // union:
-        // for items:
-        float   IT_KEY1              = 131072;
-        float   IT_KEY2              = 262144;
-        // for players:
-        float   IT_RED_FLAG_TAKEN    = 32768;
-        float   IT_RED_FLAG_LOST     = 65536;
-        float   IT_RED_FLAG_CARRING  = 98304;
-        float   IT_BLUE_FLAG_TAKEN   = 131072;
-        float   IT_BLUE_FLAG_LOST    = 262144;
-        float   IT_BLUE_FLAG_CARRING = 393216;
+       // for items:
+       float   IT_KEY1                                 = 131072;
+       float   IT_KEY2                                 = 262144;
+       // for players:
+       float   IT_RED_FLAG_TAKEN               = 32768;
+       float   IT_RED_FLAG_LOST                = 65536;
+       float   IT_RED_FLAG_CARRYING            = 98304;
+       float   IT_BLUE_FLAG_TAKEN              = 131072;
+       float   IT_BLUE_FLAG_LOST               = 262144;
+       float   IT_BLUE_FLAG_CARRYING   = 393216;
 // end
 float   IT_5HP                       = 524288;
 float   IT_25HP                      = 1048576;
index 3e160d97b543e89e84fe01a53084dced6aa4139b..b450f761e31af442b2c084763e97fd44ae5faf84 100644 (file)
@@ -259,6 +259,7 @@ void() walkmonster_start_go =
 // spread think times so they don't all happen at same time
        self.nextthink = self.nextthink + random()*0.5 + 0.1;
        self.iscreature = TRUE;
+       self.teleportable = TELEPORT_NORMAL;
        self.damagedbycontents = TRUE;
 
        force_retouch = 2; // mainly to detect teleports
@@ -353,6 +354,7 @@ void() flymonster_start_go =
                }
        }
        self.iscreature = TRUE;
+       self.teleportable = TELEPORT_NORMAL;
        self.damagedbycontents = TRUE;
 
        force_retouch = 2; // mainly to detect teleports
@@ -442,6 +444,7 @@ void() swimmonster_start_go =
                }
        }
        self.iscreature = TRUE;
+       self.teleportable = TELEPORT_NORMAL;
        self.damagedbycontents = TRUE;
 
        force_retouch = 2; // mainly to detect teleports
index a068a33a54e236017194c3ec5ac05e5caa0b9df1..d3f4b55f4a49acf42693df6e04df24942a1b99f3 100644 (file)
@@ -28,6 +28,9 @@ float nb_teams;
 
 .float teamtime;
 
+.float nb_dropperid;
+.float nb_droptime;
+
 void nb_delayedinit();
 void nb_init() // Called early (worldspawn stage)
 {
@@ -155,7 +158,7 @@ void GiveBall (entity plyr, entity ball)
        ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
        ball.team = plyr.team;
        plyr.ballcarried = ball;
-       ball.dropperid = plyr.playerid;
+       ball.nb_dropperid = plyr.playerid;
 
        plyr.effects |= g_nexball_basketball_effects_default;
        ball.effects &~= g_nexball_basketball_effects_default;
@@ -188,7 +191,7 @@ void DropBall (entity ball, vector org, vector vel)
        ball.flags &~= FL_ONGROUND;
        ball.scale = ball_scale;
        ball.velocity = vel;
-       ball.ctf_droptime = time;
+       ball.nb_droptime = time;
        ball.touch = basketball_touch;
        ball.think = ResetBall;
        ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
@@ -302,7 +305,7 @@ void basketball_touch (void)
                football_touch();
                return;
        }
-       if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_nexball_delay_collect)) {
+       if (!self.cnt && other.classname == "player" && (other.playerid != self.nb_dropperid || time > self.nb_droptime + autocvar_g_nexball_delay_collect)) {
                if (other.health <= 0)
                        return;
                LogNB("caught", other);
index 12a343eb726b6fac85a0ff52693bc9bec340b8d2..39c2cbebc38a2e2f01664d25d37b020a0faed6c0 100644 (file)
@@ -179,8 +179,6 @@ float autocvar_g_balance_crylink_secondary_speed;
 float autocvar_g_balance_crylink_secondary_spread;
 float autocvar_g_balance_crylink_reload_ammo;
 float autocvar_g_balance_crylink_reload_time;
-float autocvar_g_balance_ctf_damageforcescale;
-float autocvar_g_balance_ctf_delay_collect;
 float autocvar_g_balance_curse_empathy_minhealth;
 float autocvar_g_balance_curse_empathy_takedamage;
 float autocvar_g_balance_curse_slow_atkrate;
@@ -762,23 +760,51 @@ float autocvar_g_chat_flood_spl_team;
 float autocvar_g_chat_flood_spl_tell;
 float autocvar_g_chat_nospectators;
 float autocvar_g_chat_teamcolors;
+float autocvar_g_ctf_allow_vehicle_touch;
+float autocvar_g_ctf_drop;
+float autocvar_g_ctf_drop_velocity;
+float autocvar_g_ctf_portalteleport;
+float autocvar_g_ctf_pass;
+float autocvar_g_ctf_pass_radius;
+float autocvar_g_ctf_pass_wait;
+float autocvar_g_ctf_pass_request;
+float autocvar_g_ctf_pass_turnrate;
+float autocvar_g_ctf_pass_timelimit;
+float autocvar_g_ctf_pass_velocity;
 float autocvar_g_ctf_captimerecord_always;
 float autocvar_g_ctf_dynamiclights;
 string autocvar_g_ctf_flag_blue_model;
 float autocvar_g_ctf_flag_blue_skin;
 float autocvar_g_ctf_flag_capture_effects;
+float autocvar_g_ctf_flag_collect_delay;
+float autocvar_g_ctf_flag_damageforcescale;
+float autocvar_g_ctf_flag_dropped_waypoint;
+float autocvar_g_ctf_flag_dropped_floatinwater;
 float autocvar_g_ctf_flag_glowtrails;
+float autocvar_g_ctf_flag_health;
 float autocvar_g_ctf_flag_pickup_effects;
+float autocvar_g_ctf_flag_pickup_verbosename;
 string autocvar_g_ctf_flag_red_model;
 float autocvar_g_ctf_flag_red_skin;
-float autocvar_g_ctf_flag_returntime;
-float autocvar_g_ctf_flagcarrier_selfdamage;
-float autocvar_g_ctf_flagcarrier_selfforce;
+float autocvar_g_ctf_flag_return_time;
+float autocvar_g_ctf_flag_return_when_unreachable;
+float autocvar_g_ctf_flag_return_damage;
+float autocvar_g_ctf_flag_return_dropped;
+float autocvar_g_ctf_flagcarrier_auto_helpme_when_damaged;
+float autocvar_g_ctf_flagcarrier_allow_vehicle_carry;
+float autocvar_g_ctf_flagcarrier_selfdamagefactor;
+float autocvar_g_ctf_flagcarrier_selfforcefactor;
+float autocvar_g_ctf_flagcarrier_damagefactor;
+float autocvar_g_ctf_flagcarrier_forcefactor;
+float autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate;
+float autocvar_g_ctf_flagcarrier_waypointforenemy_spotting;
 float autocvar_g_ctf_fullbrightflags;
 float autocvar_g_ctf_ignore_frags;
 float autocvar_g_ctf_shield_force;
 float autocvar_g_ctf_shield_max_ratio;
 float autocvar_g_ctf_shield_min_negscore;
+float autocvar_g_ctf_reverse;
+float autocvar_g_ctf_dropped_capture_radius;
 float autocvar_g_cts_finish_kill_delay;
 float autocvar_g_cts_selfdamage;
 float autocvar_g_debug_bot_commands;
index 178ee0da6e8cfe236be697a433ba96a6c4a4cb55..0946f4342582fe7d974db23fbca2fef2579b7fbd 100644 (file)
@@ -23,7 +23,7 @@ void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplay
 .float havocbot_cantfindflag;
 .float havocbot_role_timeout;
 .entity ctf_worldflagnext;
-.entity basewaypoint;
+.entity bot_basewaypoint;
 
 entity ctf_worldflaglist;
 vector havocbot_ctf_middlepoint;
@@ -102,7 +102,7 @@ void havocbot_goalrating_ctf_ourbase(float ratingscale)
        if not(head)
                return;
 
-       navigation_routerating(head.basewaypoint, ratingscale, 10000);
+       navigation_routerating(head.bot_basewaypoint, ratingscale, 10000);
 }
 
 void havocbot_goalrating_ctf_enemyflag(float ratingscale)
@@ -134,7 +134,7 @@ void havocbot_goalrating_ctf_enemybase(float ratingscale)
        if not(head)
                return;
 
-       navigation_routerating(head.basewaypoint, ratingscale, 10000);
+       navigation_routerating(head.bot_basewaypoint, ratingscale, 10000);
 }
 
 void havocbot_goalrating_ctf_ourstolenflag(float ratingscale)
@@ -143,7 +143,7 @@ void havocbot_goalrating_ctf_ourstolenflag(float ratingscale)
 
        mf = havocbot_ctf_find_flag(self);
 
-       if(mf.cnt == FLAG_BASE)
+       if(mf.ctf_status == FLAG_BASE)
                return;
 
        if(mf.tag_entity)
@@ -157,7 +157,7 @@ void havocbot_goalrating_ctf_droppedflags(float ratingscale, vector org, float r
        while (head)
        {
                // flag is out in the field
-               if(head.cnt != FLAG_BASE)
+               if(head.ctf_status != FLAG_BASE)
                if(head.tag_entity==world)      // dropped
                {
                        if(radius)
@@ -295,7 +295,7 @@ void havocbot_role_ctf_escort()
 
        // If enemy flag is back on the base switch to previous role
        ef = havocbot_ctf_find_enemy_flag(self);
-       if(ef.cnt==FLAG_BASE)
+       if(ef.ctf_status==FLAG_BASE)
        {
                self.havocbot_role = self.havocbot_previous_role;
                self.havocbot_role_timeout = 0;
@@ -304,7 +304,7 @@ void havocbot_role_ctf_escort()
 
        // If the flag carrier reached the base switch to defense
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        if(vlen(ef.origin - mf.dropped_origin) < 300)
        {
                havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_DEFENSE);
@@ -359,7 +359,7 @@ void havocbot_role_ctf_offense()
        ef = havocbot_ctf_find_enemy_flag(self);
 
        // Own flag stolen
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                if(mf.tag_entity)
                        pos = mf.tag_entity.origin;
@@ -375,7 +375,7 @@ void havocbot_role_ctf_offense()
        }
 
        // Escort flag carrier
-       if(ef.cnt!=FLAG_BASE)
+       if(ef.ctf_status!=FLAG_BASE)
        {
                if(ef.tag_entity)
                        pos = ef.tag_entity.origin;
@@ -437,7 +437,7 @@ void havocbot_role_ctf_retriever()
 
        // If flag is back on the base switch to previous role
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt==FLAG_BASE)
+       if(mf.ctf_status==FLAG_BASE)
        {
                havocbot_ctf_reset_role(self);
                return;
@@ -484,7 +484,7 @@ void havocbot_role_ctf_middle()
        }
 
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER);
                return;
@@ -536,7 +536,7 @@ void havocbot_role_ctf_defense()
 
        // If own flag was captured
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER);
                return;
@@ -635,14 +635,14 @@ void havocbot_ctf_reset_role(entity bot)
        ef = havocbot_ctf_find_enemy_flag(bot);
 
        // Retrieve stolen flag
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_RETRIEVER);
                return;
        }
 
        // If enemy flag is taken go to the middle to intercept pursuers
-       if(ef.cnt!=FLAG_BASE)
+       if(ef.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_MIDDLE);
                return;
index 2f6a660cb203f4debee868d307f05fd4c018e4d4..8377eb465a167d5ebb328b499ebd8fe620f60022 100644 (file)
@@ -191,47 +191,26 @@ float CheatImpulse(float i)
                                        self.oldvelocity = self.velocity = self.personal.velocity;
                                        self.angles = self.personal.v_angle;
                                        self.fixangle = TRUE;
-                                       if(self.flagcarried)
-                                       {
-                                               bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
-                                               ReturnFlag(self.flagcarried);
-                                       }
-                               }
-                               if(g_ctf)
-                               {
-                                       self.ammo_rockets = 999;
-                                       self.ammo_nails = 999;
-                                       self.ammo_cells = 999;
-                                       self.ammo_shells = 999;
-                                       self.ammo_fuel = 999;
-                                       self.health = start_health;
-                                       self.armorvalue = start_armorvalue;
-                                       WEPSET_OR_EA(self.personal, weaponsInMap);
-                                       self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
-                                       self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
-                                       self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
-                                       self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
-                                       self.strength_finished = 0;
-                                       self.invincible_finished = 0;
-                               }
-                               else
-                               {
-                                       self.ammo_rockets = self.personal.ammo_rockets;
-                                       self.ammo_nails = self.personal.ammo_nails;
-                                       self.ammo_cells = self.personal.ammo_cells;
-                                       self.ammo_shells = self.personal.ammo_shells;
-                                       self.ammo_fuel = self.personal.ammo_fuel;
-                                       self.health = self.personal.health;
-                                       self.armorvalue = self.personal.armorvalue;
-                                       WEPSET_COPY_EE(self, self.personal);
-                                       self.items = self.personal.items;
-                                       self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
-                                       self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
-                                       self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
-                                       self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
-                                       self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
-                                       self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
+                                       
+                                       MUTATOR_CALLHOOK(AbortSpeedrun);
                                }
+
+                               self.ammo_rockets = self.personal.ammo_rockets;
+                               self.ammo_nails = self.personal.ammo_nails;
+                               self.ammo_cells = self.personal.ammo_cells;
+                               self.ammo_shells = self.personal.ammo_shells;
+                               self.ammo_fuel = self.personal.ammo_fuel;
+                               self.health = self.personal.health;
+                               self.armorvalue = self.personal.armorvalue;
+                               WEPSET_COPY_EE(self, self.personal);
+                               self.items = self.personal.items;
+                               self.pauserotarmor_finished = time + self.personal.pauserotarmor_finished - self.personal.teleport_time;
+                               self.pauserothealth_finished = time + self.personal.pauserothealth_finished - self.personal.teleport_time;
+                               self.pauserotfuel_finished = time + self.personal.pauserotfuel_finished - self.personal.teleport_time;
+                               self.pauseregen_finished = time + self.personal.pauseregen_finished - self.personal.teleport_time;
+                               self.strength_finished = time + self.personal.strength_finished - self.personal.teleport_time;
+                               self.invincible_finished = time + self.personal.invincible_finished - self.personal.teleport_time;
+
                                DID_CHEAT();
                                break;
                        }
index 2be7889e99985c75da72c912dc597d5bad063766..9d6bcf798d8b3026e6fb542731491923ba99b715 100644 (file)
@@ -417,9 +417,6 @@ void PutObserverInServer (void)
        if(self.vehicle)
                vehicles_exit(VHEF_RELESE);         
 
-       if(self.flagcarried)
-               DropFlag(self.flagcarried, world, world);
-
        WaypointSprite_PlayerDead();
 
        if not(g_ca)  // don't reset teams when moving a ca player to the spectators
@@ -448,6 +445,7 @@ void PutObserverInServer (void)
        
        self.classname = "observer";
        self.iscreature = FALSE;
+       self.teleportable = TELEPORT_SIMPLE;
        self.damagedbycontents = FALSE;
        self.health = -666;
        self.takedamage = DAMAGE_NO;
@@ -641,7 +639,6 @@ PutClientInServer
 Called when a client spawns in the server
 =============
 */
-//void() ctf_playerchanged;
 
 void PutClientInServer (void)
 {
@@ -698,6 +695,7 @@ void PutClientInServer (void)
                self.classname = "player";
                self.wasplayer = TRUE;
                self.iscreature = TRUE;
+               self.teleportable = TELEPORT_NORMAL;
                self.damagedbycontents = TRUE;
                self.movetype = MOVETYPE_WALK;
                self.solid = SOLID_SLIDEBOX;
@@ -925,9 +923,6 @@ void PutClientInServer (void)
        } else if(self.classname == "observer") {
                PutObserverInServer ();
        }
-
-       //if(g_ctf)
-       //      ctf_playerchanged();
 }
 
 .float ebouncefactor, ebouncestop; // electro's values
@@ -1340,7 +1335,6 @@ ClientConnect
 Called when a client connects to the server
 =============
 */
-//void ctf_clientconnect();
 string ColoredTeamName(float t);
 void DecodeLevelParms (void);
 //void dom_player_join_team(entity pl);
@@ -1512,10 +1506,6 @@ void ClientConnect (void)
                if(g_arena)
                        Spawnqueue_Insert(self);
        }
-       /*else if(g_ctf)
-       {
-               ctf_clientconnect();
-       }*/
 
        attach_entcs();
 
@@ -1653,8 +1643,6 @@ void ClientDisconnect (void)
        Portal_ClearAll(self);
 
        RemoveGrapplingHook(self);
-       if(self.flagcarried)
-               DropFlag(self.flagcarried, world, world);
 
        // Here, everything has been done that requires this player to be a client.
 
@@ -2535,7 +2523,6 @@ void SpectatorThink()
        self.flags |= FL_CLIENT | FL_NOTARGET;
 }
 
-float ctf_usekey();
 void PlayerUseKey()
 {
        if(self.classname != "player")
@@ -2548,9 +2535,6 @@ void PlayerUseKey()
        }
        
        // a use key was pressed; call handlers
-       if(ctf_usekey())
-               return;
-
        MUTATOR_CALLHOOK(PlayerUseKey);
 }
 
@@ -2564,7 +2548,6 @@ Called every frame for each client before the physics are run
 =============
 */
 .float usekeypressed;
-void() ctf_setstatus;
 void() nexball_setstatus;
 .float items_added;
 void PlayerPreThink (void)
@@ -2863,9 +2846,6 @@ void PlayerPreThink (void)
                if(frametime)
                        player_anim();
 
-               if(g_ctf)
-                       ctf_setstatus();
-
                if(g_nexball)
                        nexball_setstatus();
                
index 987e07c46f228b892e9741c3c4b75e00a5571968..529567a3b407cc7118590aa59c451fb3444798ac 100644 (file)
@@ -165,11 +165,14 @@ void ImpulseCommands (void)
                        case 33:
                                if(self.deadflag == DEAD_NO && teamplay)
                                {
-                                       wp = WaypointSprite_Attach("helpme", TRUE, RADARICON_HELPME, '1 0.5 0');
-                                       if(!wp)
-                                               WaypointSprite_HelpMePing(self.waypointsprite_attachedforcarrier);
-                                       else
-                                               WaypointSprite_Ping(wp);
+                                       if not(MUTATOR_CALLHOOK(HelpMePing))
+                                       {
+                                               wp = WaypointSprite_Attach("helpme", TRUE, RADARICON_HELPME, '1 0.5 0');
+                                               if(!wp)
+                                                       WaypointSprite_HelpMePing(self.waypointsprite_attachedforcarrier);
+                                               else
+                                                       WaypointSprite_Ping(wp);
+                                       }
                                        sprint(self, "HELP ME attached\n");
                                }
                                break;
index 1e8ea301ea0b3384b222cd5798b7270abf54b9a4..3e560bd2452a71020d339d7ed22830a76b212ec8 100644 (file)
@@ -152,6 +152,7 @@ void CopyBody(float keepvelocity)
        self.lip = oldself.lip;
        self.colormap = oldself.colormap;
        self.iscreature = oldself.iscreature;
+       self.teleportable = oldself.teleportable;
        self.damagedbycontents = oldself.damagedbycontents;
        self.angles = oldself.angles;
        self.avelocity = oldself.avelocity;
@@ -704,15 +705,6 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
 
                RemoveGrapplingHook(self);
 
-               if(self.flagcarried)
-               {
-                       if(attacker.classname != "player")
-                               DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
-                       else if(attacker.team == self.team)
-                               DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
-                       else
-                               DropFlag(self.flagcarried, world, attacker);
-               }
                Portal_ClearAllLater(self);
 
                if(clienttype(self) == CLIENTTYPE_REAL)
index b95c7261366b099902f2bb67ac4730661c024db7..aec1e3256b020878305579b179dfeea42a18e67e 100644 (file)
@@ -142,11 +142,6 @@ float      MSG_ENTITY                              = 5; // csqc
 
 float TE_BEAM                                  = 13;           // grappling hook
 
-// CTF
-float FLAG_BASE = 1;
-float FLAG_CARRY = 2;
-float FLAG_DROPPED = 3;
-
 float COLOR_TEAM1      = 5;  // red
 float COLOR_TEAM2      = 14; // blue
 float COLOR_TEAM3      = 13; // yellow
index 8564e04e9d3c7cb7624287acb8343486a46e989c..9068fa75bf53e95400df5e635e8551faa3ae3a2c 100644 (file)
@@ -16,14 +16,10 @@ noref float require_spawnfunc_prefix; // if this float exists, only functions wi
 
 // Globals
 
-float ctf_score_value(string parameter);
-
 float g_cloaked, g_footsteps, g_jump_grunt, g_grappling_hook, g_midair, g_minstagib, g_pinata, g_norecoil, g_minstagib_invis_alpha, g_bloodloss;
 float g_warmup_limit;
 float g_warmup_allguns;
 float g_warmup_allow_timeout;
-float g_ctf_ignore_frags;
-float g_ctf_reverse;
 float g_race_qualifying;
 float inWarmupStage;
 float g_pickup_respawntime_weapon;
@@ -201,6 +197,9 @@ void setanim(entity e, vector anim, float looping, float override, float restart
 .float watersound_finished;
 .float iscreature;
 .float damagedbycontents;
+.float damagedbytriggers;
+.float pushable;
+.float teleportable;
 .vector oldvelocity;
 
 .float pauseregen_finished;
@@ -343,7 +342,6 @@ string gamemode_name;
 
 float startitem_failed;
 
-void DropFlag(entity flag, entity penalty_receiver, entity attacker);
 void DropAllRunes(entity pl);
 
 
@@ -570,7 +568,6 @@ float servertime, serverprevtime, serverframetime;
 
 string matchid;
 .float hitplotfh;
-.string noise4;
 
 .float last_pickup;
 
index 7b02f4e5ecdc9a2fe0446c49782089aa4b89dd43..046e0f5137981e426082c31a524140697f4c72cb 100644 (file)
@@ -219,11 +219,6 @@ void GiveFrags (entity attacker, entity targ, float f, float deathtype)
                        }
                        f = 0;
                }
-               else if(g_ctf)
-               {
-                       if(g_ctf_ignore_frags)
-                               f = 0;
-               }
        }
 
        attacker.totalfrags += f;
@@ -443,14 +438,7 @@ void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
 
                                Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
 
-                               if(g_ctf && targ.flagcarried)
-                               {
-                                       UpdateFrags(attacker, ctf_score_value("score_kill"));
-                                       PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
-                                       GiveFrags(attacker, targ, 0, deathtype); // for logging
-                               }
-                               else
-                                       GiveFrags(attacker, targ, 1, deathtype);
+                               GiveFrags(attacker, targ, 1, deathtype);
 
                                if (targ.killcount > 2) {
                                        Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
@@ -764,15 +752,6 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
                }
 
-               // CTF: reduce damage/force
-               if(g_ctf)
-               if(targ == attacker)
-               if(targ.flagcarried)
-               {
-                       damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
-                       force = force * autocvar_g_ctf_flagcarrier_selfforce;
-               }
-
                if(g_runematch)
                {
                        // apply strength rune
index 6115b4218a8f45834d4477f3684a0168e5c17f6f..20ddc655170cfbc483ff0b41fe22ccec1e2c2284 100644 (file)
@@ -466,16 +466,19 @@ void trigger_hurt_touch()
                        Damage (other, self, own, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
                }
        }
+       else if(other.damagedbytriggers)
+       {
+               if(other.takedamage)
+               {
+                       EXACTTRIGGER_TOUCH;
+                       Damage(other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+               }
+       }
        else
        {
                if (!other.owner)
                {
-                       if (other.items & IT_KEY1 || other.items & IT_KEY2)     // reset flag
-                       {
-                               EXACTTRIGGER_TOUCH;
-                               other.pain_finished = min(other.pain_finished, time + 2);
-                       }
-                       else if (other.classname == "rune")                     // reset runes
+                       if (other.classname == "rune")                  // reset runes
                        {
                                EXACTTRIGGER_TOUCH;
                                other.nextthink = min(other.nextthink, time + 1);
index bb0d5280356957aba68f7b696362db8a94680fa8..726f2b50316799555901a7e31f97733703588634 100644 (file)
@@ -1183,7 +1183,6 @@ void readlevelcvars(void)
        g_bloodloss = cvar("g_bloodloss");
        sv_maxidle = cvar("sv_maxidle");
        sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
-       g_ctf_reverse = cvar("g_ctf_reverse");
        sv_autotaunt = cvar("sv_autotaunt");
        sv_taunt = cvar("sv_taunt");
 
@@ -2798,6 +2797,8 @@ float isPushable(entity e)
 {
        if(e.iscreature)
                return TRUE;
+       if(e.pushable)
+               return TRUE;
        switch(e.classname)
        {
                case "body":
index e46d5b6728244e42a67bc2c837543ed175b5f969..52e7a8811484f4b42a0c57dc055d04507d3ab680 100644 (file)
@@ -213,6 +213,39 @@ MUTATOR_HOOKABLE(SetWeaponreplace);
        // IN+OUT
                string ret_string;
 
+MUTATOR_HOOKABLE(PortalTeleport);
+       // called whenever a player goes through a portal gun teleport
+       // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
+       // INPUT
+       entity self;
+       
+MUTATOR_HOOKABLE(HelpMePing);
+       // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
+       // normally help me ping uses self.waypointsprite_attachedforcarrier,
+       // but if your mutator uses something different then you can handle it
+       // in a special manner using this hook
+       // INPUT
+       entity self; // the player who pressed impulse 33
+       
+MUTATOR_HOOKABLE(VehicleEnter);
+       // called when a player enters a vehicle
+       // allows mutators to set special settings in this event
+       // INPUT
+       entity other; // player
+       entity self; // vehicle
+       
+MUTATOR_HOOKABLE(VehicleExit);
+       // called when a player exits a vehicle
+       // allows mutators to set special settings in this event
+       // INPUT
+       entity other; // player
+       entity self; // vehicle
+       
+MUTATOR_HOOKABLE(AbortSpeedrun);
+       // called when a speedrun is aborted and the player is teleported back to start position
+       // INPUT
+       entity self; // player
+
 MUTATOR_HOOKABLE(ItemTouch);
        // called at when a item is touched. Called early, can edit item properties.
        entity self;    // item
diff --git a/qcsrc/server/mutators/gamemode_ctf.qc b/qcsrc/server/mutators/gamemode_ctf.qc
new file mode 100644 (file)
index 0000000..b82e263
--- /dev/null
@@ -0,0 +1,1386 @@
+// ================================================================
+//  Official capture the flag game mode coding, reworked by Samual
+//  Last updated: March 30th, 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;
+       WriteByte(MSG_ONE, 3); // svc_updatestat
+       WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
+       if(t < 0)
+               WriteCoord(MSG_ONE, autocvar_timelimit);
+       else
+               WriteCoord(MSG_ONE, (t + 1) / 60);
+}
+
+void ctf_EventLog(string mode, float flagteam, entity actor) // use an alias for easy changing and quick editing later
+{
+       if(autocvar_sv_eventlog)
+               GameLogEcho(strcat(":ctf:", mode, ":", ftos(flagteam), ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
+}
+
+string ctf_CaptureRecord(entity flag, entity player)
+{
+       float cap_time, cap_record, success;
+       string cap_message, refername;
+       
+       if((autocvar_g_ctf_captimerecord_always) || (player_count - currentbots)) 
+       {
+               cap_record = ctf_captimerecord;
+               cap_time = (time - flag.ctf_pickuptime);
+
+               refername = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
+               refername = ((refername == player.netname) ? "their" : strcat(refername, "^7's"));
+
+               if(!ctf_captimerecord) 
+                       { cap_message = strcat(" in ", ftos_decimals(cap_time, 2), " seconds"); success = TRUE; }
+               else if(cap_time < cap_record) 
+                       { cap_message = strcat(" in ", ftos_decimals(cap_time, 2), " seconds, breaking ", refername, " previous record of ", ftos_decimals(cap_record, 2), " seconds"); success = TRUE; }
+               else
+                       { cap_message = strcat(" in ", ftos_decimals(cap_time, 2), " seconds, failing to break ", refername, " record of ", ftos_decimals(cap_record, 2), " seconds"); success = FALSE; }
+
+               if(success) 
+               {
+                       ctf_captimerecord = cap_time;
+                       db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(cap_time));
+                       db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), player.netname);
+                       write_recordmarker(player, (time - cap_time), cap_time); 
+               } 
+       }
+       
+       return cap_message;
+}
+
+void ctf_FlagcarrierWaypoints(entity player)
+{
+       WaypointSprite_Spawn("flagcarrier", 0, 0, player, FLAG_WAYPOINT_OFFSET, world, player.team, player, wps_flagcarrier, TRUE, RADARICON_FLAG, WPCOLOR_FLAGCARRIER(player.team));
+       WaypointSprite_UpdateMaxHealth(player.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent) * 2);
+       WaypointSprite_UpdateHealth(player.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(player.health, player.armorvalue, autocvar_g_balance_armor_blockpercent));
+       WaypointSprite_UpdateTeamRadar(player.wps_flagcarrier, RADARICON_FLAGCARRIER, WPCOLOR_FLAGCARRIER(player.team));
+}
+
+
+// =======================
+// CaptureShield Functions 
+// =======================
+
+float ctf_CaptureShield_CheckStatus(entity p) 
+{
+       float s, se;
+       entity e;
+       float players_worseeq, players_total;
+
+       if(ctf_captureshield_max_ratio <= 0)
+               return FALSE;
+
+       s = PlayerScore_Add(p, SP_SCORE, 0);
+       if(s >= -ctf_captureshield_min_negscore)
+               return FALSE;
+
+       players_total = players_worseeq = 0;
+       FOR_EACH_PLAYER(e)
+       {
+               if(IsDifferentTeam(e, p))
+                       continue;
+               se = PlayerScore_Add(e, SP_SCORE, 0);
+               if(se <= s)
+                       ++players_worseeq;
+               ++players_total;
+       }
+
+       // player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
+       // use this rule here
+       
+       if(players_worseeq >= players_total * ctf_captureshield_max_ratio)
+               return FALSE;
+
+       return TRUE;
+}
+
+void ctf_CaptureShield_Update(entity player, float wanted_status)
+{
+       float updated_status = ctf_CaptureShield_CheckStatus(player);
+       if((wanted_status == player.ctf_captureshielded) && (updated_status != wanted_status)) // 0: shield only, 1: unshield only
+       {
+               if(updated_status) // TODO csqc notifier for this // Samual: How?
+                       Send_CSQC_Centerprint_Generic(player, CPID_CTF_CAPTURESHIELD, "^3You are now ^4shielded^3 from the flag\n^3for ^1too many unsuccessful attempts^3 to capture.\n\n^3Make some defensive scores before trying again.", 5, 0);
+               else
+                       Send_CSQC_Centerprint_Generic(player, CPID_CTF_CAPTURESHIELD, "^3You are now free.\n\n^3Feel free to ^1try to capture^3 the flag again\n^3if you think you will succeed.", 5, 0);
+                       
+               player.ctf_captureshielded = updated_status;
+       }
+}
+
+float ctf_CaptureShield_Customize()
+{
+       if(!other.ctf_captureshielded) { return FALSE; }
+       if(!IsDifferentTeam(self, other)) { return FALSE; }
+       
+       return TRUE;
+}
+
+void ctf_CaptureShield_Touch()
+{
+       if(!other.ctf_captureshielded) { return; }
+       if(!IsDifferentTeam(self, other)) { return; }
+       
+       vector mymid = (self.absmin + self.absmax) * 0.5;
+       vector othermid = (other.absmin + other.absmax) * 0.5;
+
+       Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * ctf_captureshield_force);
+       Send_CSQC_Centerprint_Generic(other, CPID_CTF_CAPTURESHIELD, "^3You are ^4shielded^3 from the flag\n^3for ^1too many unsuccessful attempts^3 to capture.\n\n^3Get some defensive scores before trying again.", 5, 0);
+}
+
+void ctf_CaptureShield_Spawn(entity flag)
+{
+       entity shield = spawn();
+       
+       shield.enemy = self;
+       shield.team = self.team;
+       shield.touch = ctf_CaptureShield_Touch;
+       shield.customizeentityforclient = ctf_CaptureShield_Customize;
+       shield.classname = "ctf_captureshield";
+       shield.effects = EF_ADDITIVE;
+       shield.movetype = MOVETYPE_NOCLIP;
+       shield.solid = SOLID_TRIGGER;
+       shield.avelocity = '7 0 11';
+       shield.scale = 0.5;
+       
+       setorigin(shield, self.origin);
+       setmodel(shield, "models/ctf/shield.md3");
+       setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
+}
+
+
+// ====================
+// Drop/Pass/Throw Code
+// ====================
+
+void ctf_Handle_Drop(entity flag, entity player, float droptype)
+{
+       // declarations
+       player = (player ? player : flag.pass_sender);
+
+       // main
+       flag.movetype = MOVETYPE_TOSS;
+       flag.takedamage = DAMAGE_YES;
+       flag.health = flag.max_flag_health;
+       flag.ctf_droptime = time;
+       flag.ctf_dropper = player;
+       flag.ctf_status = FLAG_DROPPED;
+       
+       // messages and sounds
+       Send_KillNotification(player.netname, flag.netname, "", INFO_LOSTFLAG, MSG_INFO);
+       sound(flag, CH_TRIGGER, flag.snd_flag_dropped, VOL_BASE, ATTN_NONE);
+       ctf_EventLog("dropped", player.team, player);
+
+       // scoring
+       PlayerTeamScore_AddScore(player, -ctf_ReadScore("penalty_drop"));       
+       PlayerScore_Add(player, SP_CTF_DROPS, 1);
+       
+       // waypoints
+       if(autocvar_g_ctf_flag_dropped_waypoint)
+               WaypointSprite_Spawn("flagdropped", 0, 0, flag, FLAG_WAYPOINT_OFFSET, world, ((autocvar_g_ctf_flag_dropped_waypoint == 2) ? 0 : player.team), flag, wps_flagdropped, TRUE, RADARICON_FLAG, WPCOLOR_DROPPEDFLAG(flag.team));
+
+       if(autocvar_g_ctf_flag_return_time || (autocvar_g_ctf_flag_return_damage && autocvar_g_ctf_flag_health))
+       {
+               WaypointSprite_UpdateMaxHealth(flag.wps_flagdropped, flag.max_flag_health);
+               WaypointSprite_UpdateHealth(flag.wps_flagdropped, flag.health);
+       }
+       
+       player.throw_antispam = time + autocvar_g_ctf_pass_wait;
+       
+       if(droptype == DROP_PASS)
+       {
+               flag.pass_sender = world;
+               flag.pass_target = world;
+       }
+}
+
+void ctf_Handle_Retrieve(entity flag, entity player)
+{
+       entity tmp_player; // temporary entity which the FOR_EACH_PLAYER loop uses to scan players
+       entity sender = flag.pass_sender;
+       
+       // transfer flag to player
+       flag.ctf_carrier = player;
+       flag.owner = player;
+       flag.owner.flagcarried = flag;
+       
+       // reset flag
+       setattachment(flag, player, "");
+       setorigin(flag, FLAG_CARRY_OFFSET);
+       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);
+       
+       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));
+               else if(!IsDifferentTeam(tmp_player, sender))
+                       centerprint(tmp_player, strcat(sender.netname, " passed the ", flag.netname, " to ", player.netname));
+       }
+       
+       // create new waypoint
+       ctf_FlagcarrierWaypoints(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)
+{
+       entity flag = player.flagcarried;
+       
+       if(!flag) { return; }
+       if((droptype == DROP_PASS) && !reciever) { return; }
+       
+       if(flag.speedrunning) { ctf_RespawnFlag(flag); return; }
+       
+       // reset the flag
+       setattachment(flag, world, "");
+       setorigin(flag, player.origin + FLAG_DROP_OFFSET);
+       flag.owner.flagcarried = world;
+       flag.owner = world;
+       flag.solid = SOLID_TRIGGER;
+       flag.ctf_droptime = time;
+       
+       flag.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND for MOVETYPE_TOSS
+       
+       switch(droptype)
+       {
+               case DROP_PASS:
+               {
+                       vector targ_origin = (0.5 * (reciever.absmin + reciever.absmax));
+                       flag.velocity = (normalize(targ_origin - player.origin) * autocvar_g_ctf_pass_velocity);
+                       break;
+               }
+               
+               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);
+                       break;
+               }
+               
+               case DROP_RESET:
+               {
+                       flag.velocity = '0 0 0'; // do nothing
+                       break;
+               }
+               
+               default:
+               case DROP_NORMAL:
+               {
+                       flag.velocity = W_CalculateProjectileVelocity(player.velocity, ('0 0 200' + ('0 100 0' * crandom()) + ('100 0 0' * crandom())), FALSE);
+                       break;
+               }
+       }
+       
+       switch(droptype)
+       {
+               case DROP_PASS:
+               {
+                       // main
+                       flag.movetype = MOVETYPE_FLY;
+                       flag.takedamage = DAMAGE_NO;
+                       flag.pass_sender = player;
+                       flag.pass_target = reciever;
+                       flag.ctf_status = FLAG_PASSING;
+                       
+                       // other
+                       sound(player, CH_TRIGGER, flag.snd_flag_touch, VOL_BASE, ATTN_NORM);
+                       ctf_EventLog("pass", flag.team, player);
+                       te_lightning2(world, reciever.origin, player.origin);
+                       break;
+               }
+
+               case DROP_RESET: 
+               {
+                       // do nothing
+                       break;
+               }
+               
+               default:
+               case DROP_THROW:
+               case DROP_NORMAL:
+               {
+                       ctf_Handle_Drop(flag, player, droptype);
+                       break;
+               }
+       }
+
+       // kill old waypointsprite
+       WaypointSprite_Ping(player.wps_flagcarrier);
+       WaypointSprite_Kill(player.wps_flagcarrier);
+       
+       if(player.wps_enemyflagcarrier)
+               WaypointSprite_Kill(player.wps_enemyflagcarrier);
+       
+       // captureshield
+       ctf_CaptureShield_Update(player, 0); // shield player from picking up flag
+}
+
+
+// ==============
+// Event Handlers
+// ==============
+
+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);
+       
+       if not(player) { return; } // without someone to give the reward to, we can't possibly cap
+       
+       // messages and sounds
+       Send_KillNotification(player.netname, enemy_flag.netname, ctf_CaptureRecord(enemy_flag, player), INFO_CAPTUREFLAG, MSG_INFO);
+       sound(player, CH_TRIGGER, flag.snd_flag_capture, VOL_BASE, ATTN_NONE);
+       
+       switch(capturetype)
+       {
+               case CAPTURE_NORMAL: ctf_EventLog("capture", enemy_flag.team, player); break;
+               case CAPTURE_DROPPED: ctf_EventLog("droppedcapture", enemy_flag.team, player); break;
+               default: break;
+       }
+       
+       // scoring
+       PlayerTeamScore_AddScore(player, ctf_ReadScore("score_capture"));
+       PlayerTeamScore_Add(player, SP_CTF_CAPS, ST_CTF_CAPS, 1);
+
+       // effects
+       if(autocvar_g_ctf_flag_capture_effects) 
+       {
+               pointparticles(particleeffectnum((player.team == COLOR_TEAM1) ? "red_ground_quake" : "blue_ground_quake"), flag.origin, '0 0 0', 1);
+               shockwave_spawn("models/ctf/shockwavetransring.md3", flag.origin - '0 0 15', -0.8, 0, 1);
+       }
+
+       // other
+       if(capturetype == CAPTURE_NORMAL)
+       {
+               WaypointSprite_Kill(player.wps_flagcarrier);
+               if(flag.speedrunning) { ctf_FakeTimeLimit(player, -1); }
+       }
+       
+       // reset the flag
+       player.next_take_time = time + autocvar_g_ctf_flag_collect_delay;
+       ctf_RespawnFlag(enemy_flag);
+}
+
+void ctf_Handle_Return(entity flag, entity player)
+{
+       // messages and sounds
+       //centerprint(player, strcat("You returned the ", flag.netname));
+       Send_KillNotification(player.netname, flag.netname, "", INFO_RETURNFLAG, MSG_INFO);
+       sound(player, CH_TRIGGER, flag.snd_flag_returned, VOL_BASE, ATTN_NONE);
+       ctf_EventLog("return", flag.team, player);
+
+       // scoring
+       PlayerTeamScore_AddScore(player, ctf_ReadScore("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
+       
+       if(flag.ctf_dropper) 
+       {
+               PlayerScore_Add(flag.ctf_dropper, SP_SCORE, -ctf_ReadScore("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
+       }
+       
+       // reset the flag
+       ctf_RespawnFlag(flag);
+}
+
+void ctf_Handle_Pickup(entity flag, entity player, float pickuptype)
+{
+       // declarations
+       entity tmp_player; // temporary entity which the FOR_EACH_PLAYER loop uses to scan players
+       string verbosename; // holds the name of the player OR no name at all for printing in the centerprints
+       float pickup_dropped_score; // used to calculate dropped pickup score
+       
+       // attach the flag to the player
+       flag.owner = player;
+       player.flagcarried = flag;
+       setattachment(flag, player, "");
+       setorigin(flag, FLAG_CARRY_OFFSET);
+       
+       // flag setup
+       flag.movetype = MOVETYPE_NONE;
+       flag.takedamage = DAMAGE_NO;
+       flag.solid = SOLID_NOT;
+       flag.angles = '0 0 0';
+       flag.ctf_carrier = player;
+       flag.ctf_status = FLAG_CARRY;
+       
+       switch(pickuptype)
+       {
+               case PICKUP_BASE: flag.ctf_pickuptime = time; break; // used for timing runs
+               case PICKUP_DROPPED: flag.health = flag.max_flag_health; break; // reset health/return timelimit
+               default: break;
+       }
+
+       // messages and sounds
+       Send_KillNotification (player.netname, flag.netname, "", INFO_GOTFLAG, MSG_INFO);
+       sound(player, CH_TRIGGER, flag.snd_flag_taken, VOL_BASE, ATTN_NONE);
+       verbosename = ((autocvar_g_ctf_flag_pickup_verbosename) ? strcat(Team_ColorCode(player.team), "(^7", player.netname, Team_ColorCode(player.team), ") ") : "");
+       
+       FOR_EACH_REALPLAYER(tmp_player)
+       {
+               if(tmp_player == player)
+                       centerprint(tmp_player, strcat("You got the ", flag.netname, "!"));
+               else if(!IsDifferentTeam(tmp_player, player))
+                       centerprint(tmp_player, strcat("Your ", Team_ColorCode(player.team), "team mate ", verbosename, "^7got the flag! Protect them!"));
+               else if(!IsDifferentTeam(tmp_player, flag))
+                       centerprint(tmp_player, strcat("The ", Team_ColorCode(player.team), "enemy ", verbosename, "^7got your flag! Retrieve it!"));
+       }
+               
+       switch(pickuptype)
+       {
+               case PICKUP_BASE: ctf_EventLog("steal", flag.team, player); break;
+               case PICKUP_DROPPED: ctf_EventLog("pickup", flag.team, player); break;
+               default: break;
+       }
+       
+       // scoring
+       PlayerScore_Add(player, SP_CTF_PICKUPS, 1);
+       switch(pickuptype)
+       {               
+               case PICKUP_BASE:
+               {
+                       PlayerTeamScore_AddScore(player, ctf_ReadScore("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);
+                       print("pickup_dropped_score is ", ftos(pickup_dropped_score), "\n");
+                       PlayerTeamScore_AddScore(player, pickup_dropped_score);
+                       break;
+               }
+               
+               default: break;
+       }
+       
+       // speedrunning
+       if(pickuptype == PICKUP_BASE)
+       {
+               flag.speedrunning = player.speedrunning; // if speedrunning, flag will flag-return and teleport the owner back after the record
+               if((player.speedrunning) && (ctf_captimerecord))
+                       ctf_FakeTimeLimit(player, time + ctf_captimerecord);
+       }
+               
+       // effects
+       if(autocvar_g_ctf_flag_pickup_effects)
+               pointparticles(particleeffectnum("smoke_ring"), 0.5 * (flag.absmin + flag.absmax), '0 0 0', 1);
+       
+       // waypoints 
+       if(pickuptype == PICKUP_DROPPED) { WaypointSprite_Kill(flag.wps_flagdropped); }
+       ctf_FlagcarrierWaypoints(player);
+       WaypointSprite_Ping(player.wps_flagcarrier);
+}
+
+
+// ===================
+// Main Flag Functions
+// ===================
+
+void ctf_CheckFlagReturn(entity flag, float returntype)
+{
+       if(flag.wps_flagdropped) { WaypointSprite_UpdateHealth(flag.wps_flagdropped, flag.health); }
+       
+       if((flag.health <= 0) || (time >= flag.ctf_droptime + autocvar_g_ctf_flag_return_time))
+       {
+               switch(returntype)
+               {
+                       case RETURN_DROPPED: bprint("The ", flag.netname, " was dropped in the base and returned itself\n"); break;
+                       case RETURN_DAMAGE: bprint("The ", flag.netname, " was destroyed and returned to base\n"); break;
+                       case RETURN_SPEEDRUN: bprint("The ", flag.netname, " became impatient after ", ftos_decimals(ctf_captimerecord, 2), " seconds and returned itself\n"); break;
+                       case RETURN_NEEDKILL: bprint("The ", flag.netname, " fell somewhere it couldn't be reached and returned to base\n"); break;
+                       
+                       default:
+                       case RETURN_TIMEOUT:
+                               { bprint("The ", flag.netname, " has returned to base\n"); break; }
+               }
+               sound(flag, CH_TRIGGER, flag.snd_flag_respawn, VOL_BASE, ATTN_NONE);
+               ctf_EventLog("returned", flag.team, world);
+               ctf_RespawnFlag(flag);
+       }
+}
+
+void ctf_CheckStalemate(void)
+{
+       // declarations
+       float stale_red_flags, stale_blue_flags;
+       entity tmp_entity;
+
+       // 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(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 sufficient stalemate, then set up the waypointsprite and announce the stalemate if necessary
+       if(stale_red_flags && stale_blue_flags)
+       {
+               for(tmp_entity = ctf_staleflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_staleflagnext)
+               {
+                       if not(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))
+       {
+               // automatically kill the flag and return it
+               self.health = 0;
+               ctf_CheckFlagReturn(self, RETURN_NEEDKILL);
+               return;
+       }
+       if(autocvar_g_ctf_flag_return_damage) 
+       {
+               // reduce health and check if it should be returned
+               self.health = self.health - damage;
+               ctf_CheckFlagReturn(self, RETURN_DAMAGE);
+               return;
+       }
+}
+
+void ctf_FlagThink()
+{
+       // declarations
+       entity tmp_entity;
+
+       self.nextthink = time + FLAG_THINKRATE; // only 5 fps, more is unnecessary.
+
+       // captureshield
+       if(self == ctf_worldflaglist) // only for the first flag
+               FOR_EACH_CLIENT(tmp_entity)
+                       ctf_CaptureShield_Update(tmp_entity, 1); // release shield only
+
+       // sanity checks
+       if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX) { // reset the flag boundaries in case it got squished
+               dprint("wtf the flag got squashed?\n");
+               tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
+               if(!trace_startsolid) // can we resize it without getting stuck?
+                       setsize(self, FLAG_MIN, FLAG_MAX); }
+                       
+       switch(self.ctf_status) // reset flag angles in case warpzones adjust it
+       {
+               case FLAG_DROPPED:
+               case FLAG_PASSING:
+               {
+                       self.angles = '0 0 0';
+                       break;
+               }
+               
+               default: break;
+       }
+
+       // main think method
+       switch(self.ctf_status)
+       {       
+               case FLAG_BASE:
+               {
+                       if(autocvar_g_ctf_dropped_capture_radius)
+                       {
+                               for(tmp_entity = ctf_worldflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_worldflagnext)
+                                       if(tmp_entity.ctf_status == FLAG_DROPPED)
+                                               if(vlen(self.origin - tmp_entity.origin) < autocvar_g_ctf_dropped_capture_radius)
+                                                       ctf_Handle_Capture(self, tmp_entity, CAPTURE_DROPPED);
+                       }
+                       return;
+               }
+               
+               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_return_dropped)
+                       {
+                               if((vlen(self.origin - self.ctf_spawnorigin) <= autocvar_g_ctf_flag_return_dropped) || (autocvar_g_ctf_flag_return_dropped == -1))
+                               {
+                                       self.health = 0;
+                                       ctf_CheckFlagReturn(self, RETURN_DROPPED);
+                                       return;
+                               }
+                       }
+                       if(autocvar_g_ctf_flag_return_time)
+                       {
+                               self.health -= ((self.max_flag_health / autocvar_g_ctf_flag_return_time) * FLAG_THINKRATE);
+                               ctf_CheckFlagReturn(self, RETURN_TIMEOUT);
+                               return;
+                       } 
+                       return;
+               }
+                       
+               case FLAG_CARRY:
+               {
+                       if(self.speedrunning && ctf_captimerecord && (time >= self.ctf_pickuptime + ctf_captimerecord)) 
+                       {
+                               self.health = 0;
+                               ctf_CheckFlagReturn(self, RETURN_SPEEDRUN);
+
+                               tmp_entity = self;
+                               self = self.owner;
+                               self.impulse = CHIMPULSE_SPEEDRUN; // move the player back to the waypoint they set
+                               ImpulseCommands();
+                               self = tmp_entity;
+                       }
+                       if(autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
+                       {
+                               if(time >= wpforenemy_nextthink)
+                               {
+                                       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);
+                       
+                       if((self.pass_target.deadflag != DEAD_NO)
+                               || (vlen(self.origin - targ_origin) > autocvar_g_ctf_pass_radius)
+                               || ((trace_fraction < 1) && (trace_ent != self.pass_target))
+                               || (time > self.ctf_droptime + autocvar_g_ctf_pass_timelimit))
+                       {
+                               ctf_Handle_Drop(self, world, DROP_PASS);
+                       }
+                       else // still a viable target, go for it
+                       {
+                               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;
+               }
+
+               default: // this should never happen
+               {
+                       dprint("ctf_FlagThink(): Flag exists with no status?\n");
+                       return;
+               }
+       }
+}
+
+void ctf_FlagTouch()
+{
+       if(gameover) { return; }
+       
+       entity toucher = other;
+       
+       // automatically kill the flag and return it if it touched lava/slime/nodrop surfaces
+       if(ITEM_TOUCH_NEEDKILL())
+       {
+               self.health = 0;
+               ctf_CheckFlagReturn(self, RETURN_NEEDKILL);
+               return;
+       }
+       
+       // special touch behaviors
+       if(toucher.vehicle_flags & VHF_ISVEHICLE)
+       {
+               if(autocvar_g_ctf_allow_vehicle_touch)
+                       toucher = toucher.owner; // the player is actually the vehicle owner, not other
+               else
+                       return; // do nothing
+       }
+       else if(toucher.classname != "player") // The flag just touched an object, most likely the world
+       {
+               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);
+                       sound(self, CH_TRIGGER, self.snd_flag_touch, VOL_BASE, ATTN_NORM);
+                       self.wait = time + FLAG_TOUCHRATE;
+               }
+               return;
+       }
+       else if(toucher.deadflag != DEAD_NO) { return; }
+
+       switch(self.ctf_status) 
+       {       
+               case FLAG_BASE:
+               {
+                       if(!IsDifferentTeam(toucher, self) && (toucher.flagcarried) && IsDifferentTeam(toucher.flagcarried, self))
+                               ctf_Handle_Capture(self, toucher, CAPTURE_NORMAL); // toucher just captured the enemies flag to his base
+                       else if(IsDifferentTeam(toucher, self) && (!toucher.flagcarried) && (!toucher.ctf_captureshielded) && (time > toucher.next_take_time))
+                               ctf_Handle_Pickup(self, toucher, PICKUP_BASE); // toucher just stole the enemies flag
+                       break;
+               }
+               
+               case FLAG_DROPPED:
+               {
+                       if(!IsDifferentTeam(toucher, self))
+                               ctf_Handle_Return(self, toucher); // toucher just returned his own flag
+                       else if((!toucher.flagcarried) && ((toucher != self.ctf_dropper) || (time > self.ctf_droptime + autocvar_g_ctf_flag_collect_delay)))
+                               ctf_Handle_Pickup(self, toucher, PICKUP_DROPPED); // toucher just picked up a dropped enemy flag
+                       break;
+               }
+                       
+               case FLAG_CARRY:
+               {
+                       dprint("Someone touched a flag even though it was being carried?\n");
+                       break;
+               }
+               
+               case FLAG_PASSING:
+               {
+                       if((toucher.classname == "player") && (toucher.deadflag == DEAD_NO) && (toucher != self.pass_sender))
+                       {
+                               if(IsDifferentTeam(toucher, self.pass_sender))
+                                       ctf_Handle_Return(self, toucher);
+                               else
+                                       ctf_Handle_Retrieve(self, toucher);
+                       }
+                       break;
+               }
+       }
+}
+
+void ctf_RespawnFlag(entity flag)
+{
+       // reset the player (if there is one)
+       if((flag.owner) && (flag.owner.flagcarried == flag))
+       {
+               if(flag.owner.wps_enemyflagcarrier)
+                       WaypointSprite_Kill(flag.owner.wps_enemyflagcarrier);
+                       
+               WaypointSprite_Kill(flag.wps_flagcarrier);
+               
+               flag.owner.flagcarried = world;
+
+               if(flag.speedrunning)
+                       ctf_FakeTimeLimit(flag.owner, -1);
+       }
+
+       if((flag.ctf_status == FLAG_DROPPED) && (flag.wps_flagdropped))
+               { WaypointSprite_Kill(flag.wps_flagdropped); }
+
+       // reset the flag
+       setattachment(flag, world, "");
+       setorigin(flag, flag.ctf_spawnorigin);
+       
+       flag.movetype = ((flag.noalign) ? MOVETYPE_NONE : MOVETYPE_TOSS);
+       flag.takedamage = DAMAGE_NO;
+       flag.health = flag.max_flag_health;
+       flag.solid = SOLID_TRIGGER;
+       flag.velocity = '0 0 0';
+       flag.angles = flag.mangle;
+       flag.flags = FL_ITEM | FL_NOTARGET;
+       
+       flag.ctf_status = FLAG_BASE;
+       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;
+
+       wpforenemy_announced = FALSE;
+}
+
+void ctf_Reset()
+{
+       if(self.owner)
+               if(self.owner.classname == "player")
+                       ctf_Handle_Throw(self.owner, world, DROP_RESET);
+                       
+       ctf_RespawnFlag(self);
+}
+
+void ctf_DelayedFlagSetup(void) // called after a flag is placed on a map by ctf_FlagSetup()
+{
+       // bot waypoints
+       waypoint_spawnforitem_force(self, self.origin);
+       self.nearestwaypointtimeout = 0; // activate waypointing again
+       self.bot_basewaypoint = self.nearestwaypoint;
+
+       // waypointsprites
+       WaypointSprite_SpawnFixed(((self.team == COLOR_TEAM1) ? "redbase" : "bluebase"), self.origin + FLAG_WAYPOINT_OFFSET, self, wps_flagbase, RADARICON_FLAG, colormapPaletteColor(self.team - 1, FALSE));
+       WaypointSprite_UpdateTeamRadar(self.wps_flagbase, RADARICON_FLAG, colormapPaletteColor(self.team - 1, FALSE));
+
+       // captureshield setup
+       ctf_CaptureShield_Spawn(self);
+}
+
+void ctf_FlagSetup(float teamnumber, entity flag) // called when spawning a flag entity on the map as a spawnfunc 
+{      
+       // declarations
+       teamnumber = fabs(teamnumber - bound(0, autocvar_g_ctf_reverse, 1)); // if we were originally 1, this will become 0. If we were originally 0, this will become 1. 
+       self = flag; // for later usage with droptofloor()
+       
+       // main setup
+       flag.ctf_worldflagnext = ctf_worldflaglist; // link flag into ctf_worldflaglist
+       ctf_worldflaglist = flag;
+
+       setattachment(flag, world, ""); 
+
+       flag.netname = ((teamnumber) ? "^1RED^7 flag" : "^4BLUE^7 flag");
+       flag.team = ((teamnumber) ? COLOR_TEAM1 : COLOR_TEAM2); // COLOR_TEAM1: color 4 team (red) - COLOR_TEAM2: color 13 team (blue)
+       flag.items = ((teamnumber) ? IT_KEY2 : IT_KEY1); // IT_KEY2: gold key (redish enough) - IT_KEY1: silver key (bluish enough)
+       flag.classname = "item_flag_team";
+       flag.target = "###item###"; // wut?
+       flag.flags = FL_ITEM | FL_NOTARGET;
+       flag.solid = SOLID_TRIGGER;
+       flag.takedamage = DAMAGE_NO;
+       flag.damageforcescale = autocvar_g_ctf_flag_damageforcescale;   
+       flag.max_flag_health = ((autocvar_g_ctf_flag_return_damage && autocvar_g_ctf_flag_health) ? autocvar_g_ctf_flag_health : 100);
+       flag.health = flag.max_flag_health;
+       flag.event_damage = ctf_FlagDamage;
+       flag.pushable = TRUE;
+       flag.teleportable = TELEPORT_NORMAL;
+       flag.damagedbytriggers = autocvar_g_ctf_flag_return_when_unreachable;
+       flag.damagedbycontents = autocvar_g_ctf_flag_return_when_unreachable;
+       flag.velocity = '0 0 0';
+       flag.mangle = flag.angles;
+       flag.reset = ctf_Reset;
+       flag.touch = ctf_FlagTouch;
+       flag.think = ctf_FlagThink;
+       flag.nextthink = time + FLAG_THINKRATE;
+       flag.ctf_status = FLAG_BASE;
+       
+       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); }
+       
+       // sound 
+       if(!flag.snd_flag_taken) { flag.snd_flag_taken  = ((teamnumber) ? "ctf/red_taken.wav" : "ctf/blue_taken.wav"); }
+       if(!flag.snd_flag_returned) { flag.snd_flag_returned = ((teamnumber) ? "ctf/red_returned.wav" : "ctf/blue_returned.wav"); }
+       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
+       
+       // precache
+       precache_sound(flag.snd_flag_taken);
+       precache_sound(flag.snd_flag_returned);
+       precache_sound(flag.snd_flag_capture);
+       precache_sound(flag.snd_flag_respawn);
+       precache_sound(flag.snd_flag_dropped);
+       precache_sound(flag.snd_flag_touch);
+       precache_model(flag.model);
+       precache_model("models/ctf/shield.md3");
+       precache_model("models/ctf/shockwavetransring.md3");
+
+       // appearence
+       setmodel(flag, flag.model); // precision set below
+       setsize(flag, FLAG_MIN, FLAG_MAX);
+       setorigin(flag, (flag.origin + FLAG_SPAWN_OFFSET));
+       
+       if(autocvar_g_ctf_flag_glowtrails)
+       {
+               flag.glow_color = ((teamnumber) ? 251 : 210); // 251: red - 210: blue
+               flag.glow_size = 25;
+               flag.glow_trail = 1;
+       }
+       
+       flag.effects |= EF_LOWPRECISION;
+       if(autocvar_g_ctf_fullbrightflags) { flag.effects |= EF_FULLBRIGHT; }
+       if(autocvar_g_ctf_dynamiclights)   { flag.effects |= ((teamnumber) ? EF_RED : EF_BLUE); }
+       
+       // flag placement
+       if((flag.spawnflags & 1) || flag.noalign) // don't drop to floor, just stay at fixed location
+       {       
+               flag.dropped_origin = flag.origin; 
+               flag.noalign = TRUE;
+               flag.movetype = MOVETYPE_NONE;
+       }
+       else // drop to floor, automatically find a platform and set that as spawn origin
+       { 
+               flag.noalign = FALSE;
+               self = flag;
+               droptofloor();
+               flag.movetype = MOVETYPE_TOSS; 
+       }       
+       
+       InitializeEntity(flag, ctf_DelayedFlagSetup, INITPRIO_SETLOCATION);
+}
+
+
+// ==============
+// Hook Functions
+// ==============
+
+MUTATOR_HOOKFUNCTION(ctf_PlayerPreThink)
+{
+       entity flag;
+       
+       // initially clear items so they can be set as necessary later.
+       self.items &~= (IT_RED_FLAG_CARRYING | IT_RED_FLAG_TAKEN | IT_RED_FLAG_LOST 
+               | IT_BLUE_FLAG_CARRYING | IT_BLUE_FLAG_TAKEN | IT_BLUE_FLAG_LOST | IT_CTF_SHIELDED);
+
+       // scan through all the flags and notify the client about them 
+       for(flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext)
+       {
+               switch(flag.ctf_status)
+               {
+                       case 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
+                               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
+       if(self.ctf_captureshielded)
+               self.items |= IT_CTF_SHIELDED;
+       
+       // update the health of the flag carrier waypointsprite
+       if(self.wps_flagcarrier) 
+               WaypointSprite_UpdateHealth(self.wps_flagcarrier, self.health);
+       
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_PlayerDamage) // for changing damage and force values that are applied to players in g_damage.qc
+{
+       if(frag_attacker.flagcarried) // if the attacker is a flagcarrier
+       {
+               if(frag_target == frag_attacker) // damage done to yourself
+               {
+                       frag_damage *= autocvar_g_ctf_flagcarrier_selfdamagefactor;
+                       frag_force *= autocvar_g_ctf_flagcarrier_selfforcefactor;
+               }
+               else // damage done to everyone else
+               {
+                       frag_damage *= autocvar_g_ctf_flagcarrier_damagefactor;
+                       frag_force *= autocvar_g_ctf_flagcarrier_forcefactor;
+               }
+       }
+       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 > frag_target.health)
+                       WaypointSprite_HelpMePing(frag_target.wps_flagcarrier); // TODO: only do this if there is a significant loss of health?
+       }
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_PlayerDies)
+{
+       if((frag_attacker != frag_target) && (frag_attacker.classname == "player") && (frag_target.flagcarried))
+       {
+               PlayerTeamScore_AddScore(frag_attacker, ctf_ReadScore("score_kill"));
+               PlayerScore_Add(frag_attacker, SP_CTF_FCKILLS, 1);
+       }
+                               
+       if(frag_target.flagcarried)
+               { ctf_Handle_Throw(frag_target, world, DROP_NORMAL); }
+               
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_GiveFragsForKill)
+{
+       frag_score = 0;
+       return (autocvar_g_ctf_ignore_frags); // no frags counted in ctf if this is true
+}
+
+MUTATOR_HOOKFUNCTION(ctf_RemovePlayer)
+{
+       if(self.flagcarried)
+               { ctf_Handle_Throw(self, world, DROP_NORMAL); }
+               
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_PortalTeleport)
+{
+       if(self.flagcarried) 
+       if(!autocvar_g_ctf_portalteleport)
+               { ctf_Handle_Throw(self, world, DROP_NORMAL); }
+
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_PlayerUseKey)
+{
+       entity player = self;
+
+       if((time > player.throw_antispam) && !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);
+                       
+                       while(head) // find the closest acceptable target to pass to
+                       {
+                               if(head.classname == "player" && head.deadflag == DEAD_NO)
+                               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; 
+                                               }
+                                               else if(player.flagcarried)
+                                               {
+                                                       if(closest_target) { if(vlen(player.origin - head.origin) < vlen(player.origin - 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; }
+               }
+               
+               // throw the flag in front of you
+               if(autocvar_g_ctf_drop && player.flagcarried)
+                       { ctf_Handle_Throw(player, world, DROP_THROW); }
+       }
+               
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_HelpMePing)
+{
+       if(self.wps_flagcarrier) // update the flagcarrier waypointsprite with "NEEDING HELP" notification
+       {
+               WaypointSprite_HelpMePing(self.wps_flagcarrier);
+       } 
+       else // create a normal help me waypointsprite
+       {
+               WaypointSprite_Spawn("helpme", waypointsprite_deployed_lifetime, waypointsprite_limitedrange, self, FLAG_WAYPOINT_OFFSET, world, self.team, self, wps_helpme, FALSE, RADARICON_HELPME, '1 0.5 0');
+               WaypointSprite_Ping(self.wps_helpme);
+       }
+
+       return 1;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_VehicleEnter)
+{
+       if(other.flagcarried)
+       {
+               if(!autocvar_g_ctf_flagcarrier_allow_vehicle_carry)
+               {
+                       ctf_Handle_Throw(self, 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';   
+               }
+       }
+               
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_VehicleExit)
+{
+       if(self.owner.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';        
+       }
+
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_AbortSpeedrun)
+{
+       if(self.flagcarried)
+       {
+               bprint("The ", self.flagcarried.netname, " was returned to base by its carrier\n");
+               ctf_RespawnFlag(self);
+       }
+       
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(ctf_MatchEnd)
+{
+       entity flag; // temporary entity for the search method
+       
+       for(flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext)
+       {
+               switch(flag.ctf_status)
+               {
+                       case FLAG_DROPPED:
+                       case FLAG_PASSING:
+                       {
+                               // lock the flag, game is over
+                               flag.movetype = MOVETYPE_NONE;
+                               flag.takedamage = DAMAGE_NO;
+                               flag.solid = SOLID_NOT;
+                               flag.nextthink = 0; // stop thinking
+                               
+                               print("stopping the ", flag.netname, " from moving.\n");
+                               break;
+                       }
+                       
+                       default:
+                       case FLAG_BASE:
+                       case FLAG_CARRY:
+                       {
+                               // do nothing for these flags
+                               break;
+                       }
+               }
+       }
+       
+       return 0;
+}
+
+
+// ==========
+// Spawnfuncs
+// ==========
+
+/*QUAKED spawnfunc_info_player_team1 (1 0 0) (-16 -16 -24) (16 16 24)
+CTF Starting point for a player in team one (Red).
+Keys: "angle" viewing angle when spawning. */
+void spawnfunc_info_player_team1()
+{
+       if(g_assault) { remove(self); return; }
+       
+       self.team = COLOR_TEAM1; // red
+       spawnfunc_info_player_deathmatch();
+}
+
+
+/*QUAKED spawnfunc_info_player_team2 (1 0 0) (-16 -16 -24) (16 16 24)
+CTF Starting point for a player in team two (Blue).
+Keys: "angle" viewing angle when spawning. */
+void spawnfunc_info_player_team2()
+{
+       if(g_assault) { remove(self); return; }
+       
+       self.team = COLOR_TEAM2; // blue
+       spawnfunc_info_player_deathmatch();
+}
+
+/*QUAKED spawnfunc_info_player_team3 (1 0 0) (-16 -16 -24) (16 16 24)
+CTF Starting point for a player in team three (Yellow).
+Keys: "angle" viewing angle when spawning. */
+void spawnfunc_info_player_team3()
+{
+       if(g_assault) { remove(self); return; }
+       
+       self.team = COLOR_TEAM3; // yellow
+       spawnfunc_info_player_deathmatch();
+}
+
+
+/*QUAKED spawnfunc_info_player_team4 (1 0 0) (-16 -16 -24) (16 16 24)
+CTF Starting point for a player in team four (Purple).
+Keys: "angle" viewing angle when spawning. */
+void spawnfunc_info_player_team4()
+{
+       if(g_assault) { remove(self); return; }
+       
+       self.team = COLOR_TEAM4; // purple
+       spawnfunc_info_player_deathmatch();
+}
+
+/*QUAKED spawnfunc_item_flag_team1 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
+CTF flag for team one (Red).
+Keys: 
+"angle" Angle the flag will point (minus 90 degrees)... 
+"model" model to use, note this needs red and blue as skins 0 and 1...
+"noise" sound played when flag is picked up...
+"noise1" sound played when flag is returned by a teammate...
+"noise2" sound played when flag is captured...
+"noise3" sound played when flag is lost in the field and respawns itself... 
+"noise4" sound played when flag is dropped by a player...
+"noise5" sound played when flag touches the ground... */
+void spawnfunc_item_flag_team1()
+{
+       if(!g_ctf) { remove(self); return; }
+
+       ctf_FlagSetup(1, self); // 1 = red
+}
+
+/*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
+CTF flag for team two (Blue).
+Keys: 
+"angle" Angle the flag will point (minus 90 degrees)... 
+"model" model to use, note this needs red and blue as skins 0 and 1...
+"noise" sound played when flag is picked up...
+"noise1" sound played when flag is returned by a teammate...
+"noise2" sound played when flag is captured...
+"noise3" sound played when flag is lost in the field and respawns itself... 
+"noise4" sound played when flag is dropped by a player...
+"noise5" sound played when flag touches the ground... */
+void spawnfunc_item_flag_team2()
+{
+       if(!g_ctf) { remove(self); return; }
+
+       ctf_FlagSetup(0, self); // the 0 is misleading, but -- 0 = blue.
+}
+
+/*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
+Team declaration for CTF gameplay, this allows you to decide what team names and control point models are used in your map.
+Note: If you use spawnfunc_ctf_team entities you must define at least 2!  However, unlike domination, you don't need to make a blank one too.
+Keys:
+"netname" Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)...
+"cnt" Scoreboard color of the team (for example 4 is red and 13 is blue)... */
+void spawnfunc_ctf_team()
+{
+       if(!g_ctf) { remove(self); return; }
+       
+       self.classname = "ctf_team";
+       self.team = self.cnt + 1;
+}
+
+
+// ==============
+// Initialization
+// ==============
+
+// code from here on is just to support maps that don't have flag and team entities
+void ctf_SpawnTeam (string teamname, float teamcolor)
+{
+       entity oldself;
+       oldself = self;
+       self = spawn();
+       self.classname = "ctf_team";
+       self.netname = teamname;
+       self.cnt = teamcolor;
+
+       spawnfunc_ctf_team();
+
+       self = oldself;
+}
+
+void ctf_DelayedInit() // Do this check with a delay so we can wait for teams to be set up.
+{
+       // if no teams are found, spawn defaults
+       if(find(world, classname, "ctf_team") == world)
+       {
+               print("No ""ctf_team"" entities found on this map, creating them anyway.\n");
+               ctf_SpawnTeam("Red", COLOR_TEAM1 - 1);
+               ctf_SpawnTeam("Blue", COLOR_TEAM2 - 1);
+       }
+       
+       ScoreRules_ctf();
+}
+
+void ctf_Initialize()
+{
+       ctf_captimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
+
+       ctf_captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;
+       ctf_captureshield_max_ratio = autocvar_g_ctf_shield_max_ratio;
+       ctf_captureshield_force = autocvar_g_ctf_shield_force;
+       
+       InitializeEntity(world, ctf_DelayedInit, INITPRIO_GAMETYPE);
+}
+
+
+MUTATOR_DEFINITION(gamemode_ctf)
+{
+       MUTATOR_HOOK(MakePlayerObserver, ctf_RemovePlayer, CBC_ORDER_ANY);
+       MUTATOR_HOOK(ClientDisconnect, ctf_RemovePlayer, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerDies, ctf_PlayerDies, CBC_ORDER_ANY);
+       MUTATOR_HOOK(MatchEnd, ctf_MatchEnd, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PortalTeleport, ctf_PortalTeleport, CBC_ORDER_ANY);
+       MUTATOR_HOOK(GiveFragsForKill, ctf_GiveFragsForKill, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerPreThink, ctf_PlayerPreThink, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerDamage_Calculate, ctf_PlayerDamage, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerUseKey, ctf_PlayerUseKey, CBC_ORDER_ANY);
+       MUTATOR_HOOK(HelpMePing, ctf_HelpMePing, CBC_ORDER_ANY);
+       MUTATOR_HOOK(VehicleEnter, ctf_VehicleEnter, CBC_ORDER_ANY);
+       MUTATOR_HOOK(VehicleExit, ctf_VehicleExit, CBC_ORDER_ANY);
+       MUTATOR_HOOK(AbortSpeedrun, ctf_AbortSpeedrun, CBC_ORDER_ANY);
+       
+       MUTATOR_ONADD
+       {
+               if(time > 1) // game loads at time 1
+                       error("This is a game type and it cannot be added at runtime.");
+               g_ctf = 1;
+               ctf_Initialize();
+       }
+
+       MUTATOR_ONREMOVE
+       {
+               g_ctf = 0;
+               error("This is a game type and it cannot be removed at runtime.");
+       }
+
+       return 0;
+}
diff --git a/qcsrc/server/mutators/gamemode_ctf.qh b/qcsrc/server/mutators/gamemode_ctf.qh
new file mode 100644 (file)
index 0000000..a558916
--- /dev/null
@@ -0,0 +1,105 @@
+// these are needed since mutators are compiled last
+
+// used in cheats.qc
+void ctf_RespawnFlag(entity flag)
+
+// used in t_quake3.qc
+void spawnfunc_info_player_team1();
+void spawnfunc_info_player_team2();
+void spawnfunc_info_player_team3();
+void spawnfunc_info_player_team4();
+void spawnfunc_item_flag_team1();
+void spawnfunc_item_flag_team2();
+void spawnfunc_ctf_team();
+
+// flag constants // for most of these, there is just one question to be asked: WHYYYYY?
+#define FLAG_MIN (PL_MIN + '0 0 -13')
+#define FLAG_MAX (PL_MAX + '0 0 -13')
+
+#define FLAG_SCALE 0.6
+
+#define FLAG_THINKRATE 0.2
+#define FLAG_TOUCHRATE 0.5
+#define WPFE_THINKRATE 0.5
+
+#define FLAG_DROP_OFFSET ('0 0 32')
+#define FLAG_CARRY_OFFSET ('-16 0 8')
+#define FLAG_SPAWN_OFFSET ('0 0 1' * (PL_MAX_z - 13))
+#define FLAG_WAYPOINT_OFFSET ('0 0 64')
+
+#define VEHICLE_FLAG_OFFSET ('0 0 96')
+#define VEHICLE_FLAG_SCALE 1.0
+
+// waypoint colors
+#define WPCOLOR_ENEMYFC(t) (colormapPaletteColor(t - 1, FALSE) * 0.75)
+#define WPCOLOR_FLAGCARRIER(t) ('0.8 0.8 0')
+#define WPCOLOR_DROPPEDFLAG(t) (('0.25 0.25 0.25' + colormapPaletteColor(t - 1, FALSE)) * 0.5)
+
+// sounds 
+#define snd_flag_taken noise
+#define snd_flag_returned noise1
+#define snd_flag_capture noise2
+#define snd_flag_respawn noise3
+.string snd_flag_dropped;
+.string snd_flag_touch;
+
+// list of flags on the map
+entity ctf_worldflaglist;
+.entity ctf_worldflagnext;
+entity ctf_staleflaglist;
+.entity ctf_staleflagnext;
+
+// waypoint sprites
+.entity bot_basewaypoint; // flag waypointsprite
+.entity wps_helpme;
+.entity wps_flagbase; 
+.entity wps_flagcarrier;
+.entity wps_flagdropped;
+.entity wps_enemyflagcarrier;
+float wpforenemy_announced;
+float wpforenemy_nextthink;
+
+// statuses
+#define FLAG_BASE 1
+#define FLAG_DROPPED 2
+#define FLAG_CARRY 3
+#define FLAG_PASSING 4
+
+#define DROP_NORMAL 1
+#define DROP_THROW 2
+#define DROP_PASS 3
+#define DROP_RESET 4
+
+#define PICKUP_BASE 1
+#define PICKUP_DROPPED 2
+
+#define CAPTURE_NORMAL 1
+#define CAPTURE_DROPPED 2
+
+#define RETURN_TIMEOUT 1
+#define RETURN_DROPPED 2
+#define RETURN_DAMAGE 3
+#define RETURN_SPEEDRUN 4
+#define RETURN_NEEDKILL 5
+
+// flag properties
+#define ctf_spawnorigin dropped_origin
+float ctf_captimerecord; // record time for capturing the flag
+.float ctf_pickuptime;
+.float ctf_droptime;
+.float ctf_status; // status of the flag (FLAG_BASE, FLAG_DROPPED, FLAG_CARRY declared globally)
+.entity ctf_carrier;
+.entity ctf_dropper; // don't allow spam of dropping the flag
+.float max_flag_health;
+.float next_take_time;
+
+// passing properties
+.entity pass_sender;
+.entity pass_target;
+.float throw_antispam;
+
+// CaptureShield: If the player is too bad to be allowed to capture, shield them from taking the flag.
+.float ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture
+float ctf_captureshield_min_negscore; // punish at -20 points
+float ctf_captureshield_max_ratio; // punish at most 30% of each team
+float ctf_captureshield_force; // push force of the shield
\ No newline at end of file
index ec8de781e257fa754167f2c028c3e6c5dc5ea3cc..1b94746356c85ee15576d809f3e0ce3b57f9c076 100644 (file)
@@ -117,7 +117,7 @@ void GiveBall(entity plyr, entity ball)
        ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
        ball.team = plyr.team;
        plyr.ballcarried = ball;
-       ball.dropperid = plyr.playerid;
+       ball.ctf_dropper = plyr;
 
        plyr.effects |= autocvar_g_nexball_basketball_effects_default;
        ball.effects &~= autocvar_g_nexball_basketball_effects_default;
@@ -287,7 +287,7 @@ void basketball_touch(void)
                football_touch();
                return;
        }
-       if(!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_nexball_delay_collect))
+       if(!self.cnt && other.classname == "player" && (other != self.ctf_dropper || time > self.ctf_droptime + autocvar_g_nexball_delay_collect))
        {
                if(other.health <= 0)
                        return;
index 61c2b896ae50d1d036ebe71ba942d99dd9afd276..2ac6094d339d578d174da5ec3ed06eed91fcad20 100644 (file)
@@ -1,6 +1,7 @@
 MUTATOR_DECLARATION(gamemode_keyhunt);
 MUTATOR_DECLARATION(gamemode_freezetag);
 MUTATOR_DECLARATION(gamemode_keepaway);
+MUTATOR_DECLARATION(gamemode_ctf);
 MUTATOR_DECLARATION(gamemode_nexball);
 MUTATOR_DECLARATION(gamemode_onslaught);
 
index 76af253dca5c0f3bd3b5785134f9c378687fdf8c..75dae14bf5f28d666e9beb91e820e912389a1a54 100644 (file)
@@ -154,8 +154,11 @@ float Portal_TeleportPlayer(entity teleporter, entity player)
        // factor -1 allows chaining portals, but may be weird
        player.right_vector = -1 * AnglesTransform_Apply(transform, player.right_vector);
 
-       if(player.flagcarried)
-               DropFlag(player.flagcarried, player, world);
+       entity oldself = self;
+       self = player;
+       MUTATOR_CALLHOOK(PortalTeleport);
+       player = self;
+       self = oldself;
 
        if not(teleporter.enemy)
        {
index b58f5d53216631dc990389cb1fd54558146b0335..39c29037a0be3b10ba18af7df71c1bb835cddb5e 100644 (file)
@@ -29,6 +29,7 @@ defs.qh               // Should rename this, it has fields and globals
 
 mutators/base.qh
 mutators/mutators.qh
+mutators/gamemode_ctf.qh
 mutators/gamemode_keyhunt.qh // TODO fix this
 mutators/gamemode_nexball.qh 
 mutators/mutator_dodging.qh
@@ -138,7 +139,7 @@ cl_client.qc
 t_plats.qc
 antilag.qc
 
-ctf.qc
+//ctf.qc
 domination.qc
 //mode_onslaught.qc
 //nexball.qc
@@ -205,10 +206,11 @@ playerstats.qc
 ../common/explosion_equation.qc
 
 mutators/base.qc
-mutators/gamemode_nexball.qc
-mutators/gamemode_keyhunt.qc
+mutators/gamemode_ctf.qc
 mutators/gamemode_freezetag.qc
+mutators/gamemode_keyhunt.qc
 mutators/gamemode_keepaway.qc
+mutators/gamemode_nexball.qc
 mutators/gamemode_onslaught.qc
 mutators/mutator_invincibleproj.qc
 mutators/mutator_new_toys.qc
index 25dc837f953a514ce0ad9918b02d6d0bec92adc2..2cfdd8a7720f5bf665d22ed5d7916da177375887 100644 (file)
@@ -75,6 +75,11 @@ void spawn_tdeath(vector v0, entity e, vector v)
 #define TELEPORT_FLAGS_WARPZONE   0
 #define TELEPORT_FLAGS_PORTAL     (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH | TELEPORT_FLAG_FORCE_TDEATH)
 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)
+
+// types for .teleportable entity setting
+#define TELEPORT_NORMAL 1 // play sounds/effects etc
+#define TELEPORT_SIMPLE 2 // only do teleport, nothing special
+
 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)
 {
        entity telefragger;
@@ -87,7 +92,7 @@ void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angle
 
        makevectors (to_angles);
 
-       if(player.classname == "player") // don't play sounds or show particles for anything that isn't a player, maybe change later to block only observers
+       if(player.teleportable == TELEPORT_NORMAL) // don't play sounds or show particles for anything that isn't a player, maybe change later to block only observers
        {
                if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps
                {
@@ -197,20 +202,17 @@ void Teleport_Touch (void)
        if (self.active != ACTIVE_ACTIVE)
                return;
        
-       if not(other.iscreature)
-               return;
-
-       // for gameplay: vehicles can't teleport
-       if (other.vehicle_flags & VHF_ISVEHICLE)
+       if not(other.teleportable)
                return;
     
-    if(other.vehicle)
-        return;
-        
-    if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
-        return;
+       if(other.vehicle)
+       if(!other.vehicle.teleportable)
+               return;
+                       
+       if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
+               return;
         
-       if (other.deadflag != DEAD_NO)
+       if(other.deadflag != DEAD_NO)
                return;
 
        if(self.team)
index c245a30a32995bc8f2a7560ebbc1a77ee504061a..917aa11bcc3c586a97cea50d3d9bc3c02cf1fb78 100644 (file)
@@ -53,7 +53,6 @@ string TeamNoName(float t)
 }
 
 void dom_init();
-void ctf_init();
 void runematch_init();
 void tdm_init();
 void entcs_init();
@@ -142,10 +141,9 @@ void InitGameplayMode()
        if(g_ctf)
        {
                ActivateTeamplay();
-               g_ctf_ignore_frags = autocvar_g_ctf_ignore_frags;
                fraglimit_override = autocvar_capturelimit_override;
                leadlimit_override = autocvar_captureleadlimit_override;
-               ctf_init();
+               MUTATOR_ADD(gamemode_ctf);
                have_team_spawns = -1; // request team spawns
        }
 
@@ -911,7 +909,6 @@ void SV_ChangeTeam(float _color)
                if(self.deadflag == DEAD_NO)
                        Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
        }
-       //ctf_playerchanged();
 }
 
 void ShufflePlayerOutOfTeam (float source_team)
index 767c346620547b0dd565f58f093f46b675b1f8f8..31b984e391767845be993b5faecb3bc4779f1ae5 100644 (file)
@@ -255,6 +255,7 @@ void turret_ewheel_dinit()
     self.target_select_flags   = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
     self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
     self.iscreature = TRUE;
+    self.teleportable = TELEPORT_NORMAL;
     self.damagedbycontents = TRUE;
     self.movetype   = MOVETYPE_WALK;
     self.solid      = SOLID_SLIDEBOX;
index f47003f4bb19d0d581ed529e8d4c71246dba2a28..599eb5776968117caabdc4eed6b1b1b9610a23a0 100644 (file)
@@ -593,6 +593,7 @@ void turret_walker_dinit()
     self.target_select_flags   = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
     self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
     self.iscreature = TRUE;
+    self.teleportable = TELEPORT_NORMAL;
     self.damagedbycontents = TRUE;
     self.movetype   = MOVETYPE_WALK;
     self.solid      = SOLID_SLIDEBOX;
index f66c2b925278575cb08235a72394a572aab208de..87ceecc0c61fd2688a5a6243fdf34f59d5561798 100644 (file)
@@ -2,7 +2,6 @@ float autocvar_g_vehicles_crush_dmg;
 float autocvar_g_vehicles_crush_force;
 float autocvar_g_vehicles_delayspawn;
 float autocvar_g_vehicles_delayspawn_jitter;
-float autocvar_g_vehicles_allow_flagcarry;
 
 var float autocvar_g_vehicles_nex_damagerate = 0.5;
 var float autocvar_g_vehicles_uzi_damagerate = 0.5;
@@ -472,6 +471,7 @@ void vehicles_spawn()
     self.touch              = vehicles_touch;
     self.event_damage       = vehicles_damage;
     self.iscreature         = TRUE;
+    self.teleportable       = FALSE; // no teleporting for vehicles, too buggy
     self.damagedbycontents     = TRUE;
     self.movetype           = MOVETYPE_WALK;
     self.solid              = SOLID_SLIDEBOX;
@@ -658,18 +658,8 @@ void vehicles_enter()
     vehicles_clearrturn();
 
     CSQCVehicleSetup(self.owner, self.hud);
-
-    if(other.flagcarried)
-    {
-        if(!autocvar_g_vehicles_allow_flagcarry)
-            DropFlag(other.flagcarried, world, world);
-        else
-        {
-            other.flagcarried.scale = 1;
-            setattachment(other.flagcarried, self, "");
-            setorigin(other.flagcarried, self.maxs_z * '0 0 1');
-        }
-    }
+    
+    MUTATOR_CALLHOOK(VehicleEnter);
 
     self.vehicle_enter();
     antilag_clear(other);
@@ -812,13 +802,10 @@ void vehicles_exit(float eject)
     if(!teamplay)
         _vehicle.team = 0;
     else
-        _vehicle.team = _vehicle.tur_head.team;
-        
-    sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTN_NORM);
-    _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;   
-    _vehicle.phase = time + 1;
     
-    _vehicle.vehicle_exit(eject);
+    self.team = self.tur_head.team;
+   
+    MUTATOR_CALLHOOK(VehicleExit);
     
     vehicles_setreturn();
     vehicles_reset_colors();        
@@ -1265,6 +1252,7 @@ float vehicle_initialize(string  net_name,
     self.takedamage         = DAMAGE_AIM;
     self.bot_attack         = TRUE;
     self.iscreature         = TRUE;
+    self.teleportable       = FALSE; // no teleporting for vehicles, too buggy
     self.damagedbycontents     = TRUE;
     self.hud                = vhud;
     self.tur_health          = _max_health;
@@ -1410,4 +1398,4 @@ vector predict_target(entity _targ, vector _from, float _shot_speed)
 
     return _predict_pos;
 }
-*/
\ No newline at end of file
+*/
index 2a350bf89414cc10aea84603b51ef295d71d17f8..4030c64885d7945d728e9608a309c2b742e8e063 100644 (file)
@@ -17,10 +17,10 @@ set cl_vehicles_hudscale 0.5way
 
 set g_vehicles_delayspawn 1
 set g_vehicles_delayspawn_jitter 10
-set g_vehicles_allow_flagcarry 1
 
 set g_vehicles_nex_damagerate 0.5
 set g_vehicles_uzi_damagerate 0.65
 set g_vehicles_rifle_damagerate 1
 set g_vehicles_minstanex_damagerate 0.001
-set g_vehicles_tag_damagerate 2
\ No newline at end of file
+set g_vehicles_tag_damagerate 2
+