// ================================================================
// Official capture the flag game mode coding, reworked by Samual
-// Last updated: March 27th, 2011
+// Last updated: March 28th, 2011
// ================================================================
// Flag constants
#define FLAG_MAX (PL_MAX + '0 0 -13')
#define FLAG_CARRY_POS '-15 0 7'
-// Flag waypointsprite
-.entity basewaypoint;
-.entity sprite;
+.entity bot_basewaypoint; // flag waypointsprite
+.entity wps_flagbase;
+.entity wps_flagcarrier;
+.entity wps_flagdropped;
-// CTF flags in the map
-entity ctf_worldflaglist;
+entity ctf_worldflaglist; // CTF flags in the map
.entity ctf_worldflagnext;
-// Don't allow spam of dropping the flag.
-.float ctf_dropperid;
+.vector ctf_spawnorigin; // stored vector for where the flag is placed on the map itself.
+
+float ctf_captimerecord; // record time for capturing the flag
+.float ctf_pickuptime;
+.float ctf_pickupid;
+.float ctf_dropperid; // don't allow spam of dropping the flag
.float ctf_droptime;
+.float ctf_status; // status of the flag (FLAG_BASE, FLAG_DROPPED, FLAG_CARRY declared globally)
-// Delay between when the person can pick up a flag // replace with .wait?
-.float next_take_time;
-// Record time for capturing the flag
-float flagcaptimerecord;
-.float flagpickuptime;
+.float next_take_time; // Delay between when the person can pick up a flag // is this obsolete from the stuff above?
// 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 captureshield_min_negscore; // punish at -20 points
-float captureshield_max_ratio; // punish at most 30% of each team
-float captureshield_force; // push force of the shield
-
-
-// declare functions so they can be used in any order in the file
-void ctf_TouchEvent(void);
-void ctf_FlagThink(void);
-void ctf_SetupFlag(float, entity);
-
-
-void ctf_CreateBaseWaypoints(float teamnumber)
-{
- waypoint_spawnforitem_force(self, self.origin);
- self.nearestwaypointtimeout = 0; // activate waypointing again
- self.basewaypoint = self.nearestwaypoint;
-
- if(self.team == COLOR_TEAM1)
- {
- WaypointSprite_SpawnFixed(((self.team == COLOR_TEAM1) ? "redbase" : "bluebase"), self.origin + '0 0 61', self, sprite);
- WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM1 - 1, FALSE));
- }
- else
- {
- WaypointSprite_SpawnFixed("bluebase", self.origin + '0 0 61', self, sprite);
- WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_FLAG, colormapPaletteColor(COLOR_TEAM2 - 1, FALSE));
- }
-}
+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
+// after game mode is finished, these will be changed to use #define with other entities so as to not create many more.
// ==================
// Misc CTF functions
// ==================
-float ctf_ReadScore(string parameter)
+float ctf_ReadScore(string parameter) // make this obsolete
{
- if(g_ctf_win_mode != 2)
+ //if(g_ctf_win_mode != 2)
return cvar(strcat("g_ctf_personal", parameter));
- else
- return cvar(strcat("g_ctf_flag", parameter));
+ //else
+ // return cvar(strcat("g_ctf_flag", parameter));
}
void ctf_FakeTimeLimit(entity e, float t)
WriteCoord(MSG_ONE, (t + 1) / 60);
}
-void ctf_EventLog(string mode, float flagteam, entity actor)
+void ctf_EventLog(string mode, float flagteam, entity actor) // use an alias for easy changing and quick editing later
{
- string s;
- if(!autocvar_sv_eventlog)
- return;
- s = strcat(":ctf:", mode);
- s = strcat(s, ":", ftos(flagteam));
- if(actor != world)
- s = strcat(s, ":", ftos(actor.playerid));
- GameLogEcho(s);
+ if(autocvar_sv_eventlog)
+ GameLogEcho(strcat(":ctf:", mode, ":", ftos(flagteam), ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
}
-void ctf_CaptureShockwave(vector org)
+
+// =======================
+// CaptureShield Functions
+// =======================
+
+float ctf_CaptureShield_CheckStatus(entity p)
{
- shockwave_spawn("models/ctf/shockwavetransring.md3", org - '0 0 15', -0.8, 0, 1);
+ 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(e.team != p.team)
+ 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_SetStatus_ForType(entity flag, float type)
+void ctf_CaptureShield_Update(entity player, float wanted_status)
{
- if(flag.cnt == FLAG_CARRY)
+ float updated_status = ctf_CaptureShield_CheckStatus(player);
+ if((wanted_status == player.ctf_captureshielded) && (updated_status != wanted_status)) // 0: shield only, 1: unshield only
{
- if(flag.owner == self)
- self.items |= type * 3; // carrying: self is currently carrying the flag
- else
- self.items |= type * 1; // taken: someone on self's team is carrying the flag
+ 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;
}
- else if(flag.cnt == FLAG_DROPPED)
- self.items |= type * 2; // lost: the flag is dropped somewhere on the map
}
-void ctf_SetStatus()
+float ctf_CaptureShield_Customize()
{
- // declarations
- float redflags, blueflags;
- local entity flag;
+ if not(other.ctf_captureshielded)
+ return FALSE;
+ if(self.team == other.team)
+ return FALSE;
+ return TRUE;
+}
+
+void ctf_CaptureShield_Touch()
+{
+ if not(other.ctf_captureshielded)
+ return;
+ if(self.team == other.team)
+ return;
+ vector mymid;
+ vector othermid;
+ mymid = (self.absmin + self.absmax) * 0.5;
+ 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 e;
+ e = spawn();
+ e.enemy = self;
+ e.team = self.team;
+ e.touch = ctf_CaptureShield_Touch;
+ e.customizeentityforclient = ctf_CaptureShield_Customize;
+ e.classname = "ctf_captureshield";
+ e.effects = EF_ADDITIVE;
+ e.movetype = MOVETYPE_NOCLIP;
+ e.solid = SOLID_TRIGGER;
+ e.avelocity = '7 0 11';
+ setorigin(e, self.origin);
+ setmodel(e, "models/ctf/shield.md3");
+ e.scale = 0.5;
+ setsize(e, e.scale * e.mins, e.scale * e.maxs);
+}
+
+
+// ==============
+// Event Handlers
+// ==============
+
+void ctf_Handle_Drop(entity player)
+{
+ entity flag = player.flagcarried;
+
+ if(!flag) { return; }
+ if(flag.speedrunning) { ctf_RespawnFlag(flag); return; }
- // initially clear items so they can be set as necessary later.
- self.items &~= (IT_RED_FLAG_TAKEN | IT_RED_FLAG_LOST | IT_BLUE_FLAG_TAKEN | IT_BLUE_FLAG_LOST | IT_CTF_SHIELDED);
+ // reset the flag
+ setattachment(flag, world, "");
+ setorigin(flag, player.origin - '0 0 24' + '0 0 37');
+ flag.owner.flagcarried = world;
+ flag.owner = world;
+ flag.movetype = MOVETYPE_TOSS;
+ flag.solid = SOLID_TRIGGER;
+ flag.takedamage = DAMAGE_YES;
+ flag.velocity = ('0 0 200' + ('0 100 0' * crandom()) + ('100 0 0' * crandom()));
+ flag.pain_finished = time + autocvar_g_ctf_flag_returntime; // replace this later
+
+ flag.ctf_droptime = time;
+ flag.ctf_dropperid = player.playerid;
+ flag.ctf_status = FLAG_DROPPED;
- // item for stopping players from capturing the flag too often
- if(self.ctf_captureshielded)
- self.items |= IT_CTF_SHIELDED;
+ // messages and sounds
+ Send_KillNotification(player.netname, flag.netname, "", INFO_LOSTFLAG, MSG_INFO);
+ sound(flag, CH_TRIGGER, flag.noise4, 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
+ WaypointSprite_Spawn("flagdropped", 0, 0, flag, '0 0 64', world, player.team, flag, wps_flagdropped, FALSE, RADARICON_FLAG, '0 1 1'); // (COLOR_TEAM1 + COLOR_TEAM2 - flag.team)
+ WaypointSprite_Ping(player.wps_flagcarrier);
+ WaypointSprite_Kill(player.wps_flagcarrier);
+
+ // captureshield
+ ctf_CaptureShield_Update(player, 0); // shield only
+
+ // check if the flag will fall off the map
+ trace_startsolid = FALSE;
+ tracebox(flag.origin, flag.mins, flag.maxs, flag.origin, TRUE, flag);
+ if(trace_startsolid)
+ dprint("FLAG FALLTHROUGH will happen SOON\n");
+}
+
+void ctf_Handle_Capture(entity flag, entity player)
+{
+ // declarations
+ float cap_time, cap_record, success;
+ string cap_message, refername;
+
+ // records
+ if((autocvar_g_ctf_captimerecord_always) || (player_count - currentbots)) {
+ cap_record = ctf_captimerecord;
+ cap_time = (time - player.flagcarried.ctf_pickuptime);
- // figure out what flags we already own
- for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
+ 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); } }
+
+ // messages and sounds
+ Send_KillNotification(player.netname, player.flagcarried.netname, cap_message, INFO_CAPTUREFLAG, MSG_INFO);
+ sound(player, CH_TRIGGER, flag.noise2, VOL_BASE, ATTN_NONE); // "ctf/*_capture.wav"
+ ctf_EventLog("capture", player.flagcarried.team, player);
+
+ // 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)
{
- if(flag.items & IT_KEY2) // blue
- ++redflags;
- else if(flag.items & IT_KEY1) // red
- ++blueflags;
+ 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);
}
- // blinking magic: if there is more than one flag, show one of these in a clever way // wtf?
- if(redflags)
- redflags = mod(floor(time * redflags * 0.75), redflags);
-
- if(blueflags)
- blueflags = mod(floor(time * blueflags * 0.75), blueflags);
+ // waypointsprites
+ WaypointSprite_Kill(player.wps_flagcarrier);
- for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) if(flag.cnt != FLAG_BASE)
+ // reset the flag
+ if(flag.speedrunning) { ctf_FakeTimeLimit(player, -1); }
+
+ ctf_RespawnFlag(player.flagcarried);
+}
+
+void ctf_Handle_Return(entity flag, entity player)
+{
+ // messages and sounds
+ Send_KillNotification (player.netname, flag.netname, "", INFO_RETURNFLAG, MSG_INFO);
+ sound(player, CH_TRIGGER, flag.noise1, VOL_BASE, ATTN_NONE);
+ ctf_EventLog("return", flag.team, player);
+
+ // scoring
+ PlayerTeamScore_AddScore(player, ctf_ReadScore(strcat("score_return", ((player.playerid == flag.playerid) ? "_by_killer" : "")))); // reward for return
+ PlayerScore_Add(player, SP_CTF_RETURNS, 1); // add to count of returns
+
+ TeamScore_AddToTeam(((flag.team == COLOR_TEAM1) ? COLOR_TEAM2 : COLOR_TEAM1), ST_SCORE, -ctf_ReadScore("penalty_returned")); // punish the team who was last carrying it
+ FOR_EACH_PLAYER(player) if(player.playerid == flag.ctf_dropperid) // punish the player who dropped the flag
{
- if(flag.items & IT_KEY2) // blue
- {
- if(--redflags == -1) // happens exactly once (redflags is in 0..count-1, and will --'ed count times) // WHAT THE FUCK DOES THIS MEAN? whoever wrote this is shitty at explaining things.
- ctf_SetStatus_ForType(flag, IT_RED_FLAG_TAKEN);
- }
- else if(flag.items & IT_KEY1) // red
- {
- if(--blueflags == -1) // happens exactly once
- ctf_SetStatus_ForType(flag, IT_BLUE_FLAG_TAKEN);
- }
+ PlayerScore_Add(player, SP_SCORE, -ctf_ReadScore("penalty_returned"));
+ ctf_CaptureShield_Update(player, 0); // shield only
}
+
+ // waypointsprites
+ WaypointSprite_Kill(flag.wps_flagdropped);
+
+ // reset the flag
+ ctf_RespawnFlag(flag);
}
-void ctf_Reset()
+void ctf_Handle_Pickup_Base(entity flag, entity player)
{
- DropFlag(self, world, world);
+ 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
- ReturnFlag(self);
+ // attach the flag to the player
+ flag.owner = player;
+ player.flagcarried = flag;
+ setattachment(flag, player, "");
+ setorigin(flag, FLAG_CARRY_POS);
+
+ // set up the flag
+ flag.movetype = MOVETYPE_NONE;
+ flag.takedamage = DAMAGE_NO;
+ flag.solid = SOLID_NOT;
+ flag.angles = '0 0 0';
+ flag.ctf_pickuptime = time; // used for timing runs
+ flag.ctf_pickupid = player.playerid;
+ flag.ctf_status = FLAG_CARRY;
+
+ // messages and sounds
+ Send_KillNotification (player.netname, flag.netname, "", INFO_GOTFLAG, MSG_INFO);
+ sound(player, CH_TRIGGER, flag.noise, VOL_BASE, ATTN_NONE);
+ ctf_EventLog("steal", flag.team, player);
+ verbosename = ((autocvar_g_ctf_flag_pickup_verbosename) ? strcat("(", player.netname, ")") : ""); // replace TRUE with an autocvar for it.
+ FOR_EACH_PLAYER(tmp_player)
+ if(tmp_player.team == flag.team)
+ centerprint(tmp_player, strcat("The enemy ", verbosename, "got your flag! Retrieve it!"));
+ else if((tmp_player.team == player.team) && (tmp_player != player))
+ centerprint(tmp_player, strcat("Your team mate ", verbosename, "got the flag! Protect them!"));
+
+ // scoring
+ PlayerTeamScore_AddScore(player, ctf_ReadScore("score_pickup_base"));
+ PlayerScore_Add(player, SP_CTF_PICKUPS, 1);
+
+ // speedrunning
+ 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
+ WaypointSprite_Spawn("flagcarrier", 0, 0, player, '0 0 64', world, player.team, player, wps_flagcarrier, FALSE, RADARICON_FLAG, '1 1 0'); // (COLOR_TEAM1 + COLOR_TEAM2 - flag.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, '1 1 0');
+ WaypointSprite_Ping(player.wps_flagcarrier);
+}
+
+void ctf_Handle_Pickup_Dropped(entity flag, entity player) // make sure this works
+{
+ // declarations
+ float returnscore = bound(0, (flag.pain_finished - time) / autocvar_g_ctf_flag_returntime, 1); // can this be division by zero?
+ 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
+
+ // attach the flag to the player
+ flag.owner = player;
+ player.flagcarried = flag;
+ setattachment(flag, player, "");
+ setorigin(flag, FLAG_CARRY_POS);
+
+ // set up the flag
+ flag.movetype = MOVETYPE_NONE;
+ flag.takedamage = DAMAGE_NO;
+ flag.solid = SOLID_NOT;
+ flag.angles = '0 0 0';
+ //flag.ctf_pickuptime = time; // don't update pickuptime since this isn't a real steal.
+ flag.ctf_pickupid = player.playerid;
+ flag.ctf_status = FLAG_CARRY;
+
+ // messages and sounds
+ Send_KillNotification (player.netname, flag.netname, "", INFO_PICKUPFLAG, MSG_INFO);
+ sound (player, CH_TRIGGER, flag.noise, VOL_BASE, ATTN_NONE);
+ ctf_EventLog("pickup", flag.team, player);
+ verbosename = ((autocvar_g_ctf_flag_pickup_verbosename) ? strcat("(", player.netname, ")") : "");
+ FOR_EACH_PLAYER(tmp_player)
+ if(tmp_player.team == flag.team)
+ centerprint(tmp_player, strcat("The enemy ", verbosename, "got your flag! Retrieve it!"));
+ else if((tmp_player.team == player.team) && (tmp_player != player))
+ centerprint(tmp_player, strcat("Your team mate ", verbosename, "got the flag! Protect them!"));
+
+ // scoring
+ returnscore = floor((ctf_ReadScore("score_pickup_dropped_late") * (1-returnscore) + ctf_ReadScore("score_pickup_dropped_early") * returnscore) + 0.5);
+ print("score is ", ftos(returnscore), "\n");
+ PlayerTeamScore_AddScore(player, returnscore);
+ PlayerScore_Add(player, SP_CTF_PICKUPS, 1);
+
+ // effects
+ if (autocvar_g_ctf_flag_pickup_effects) // field pickup effect
+ {
+ pointparticles(particleeffectnum("smoke_ring"), 0.5 * (flag.absmin + flag.absmax), '0 0 0', 1);
+ }
+
+ // waypoints
+ WaypointSprite_Kill(flag.wps_flagdropped);
+ WaypointSprite_Spawn("flagcarrier", 0, 0, player, '0 0 64', world, player.team, player, wps_flagcarrier, FALSE, RADARICON_FLAG, '1 1 0'); // (COLOR_TEAM1 + COLOR_TEAM2 - flag.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, '1 1 0');
+ WaypointSprite_Ping(player.wps_flagcarrier);
}
// Main Flag Functions
// ===================
+void ctf_FlagThink()
+{
+ // declarations
+ entity tmp_entity;
+
+ self.nextthink = time + 0.1; // only 10 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 squished?\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); }
+
+ if(self.owner.classname != "player" || (self.owner.deadflag) || (self.owner.flagcarried != self)) {
+ dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
+ ctf_Handle_Drop(self.owner);
+ return; }
+
+ // main think method
+ switch(self.ctf_status)
+ {
+ case FLAG_BASE: // nothing to do here
+ return;
+
+ case FLAG_DROPPED:
+ // flag fallthrough? FIXME remove this if bug is really fixed now
+ if(self.origin_z < -131072)
+ {
+ dprint("FLAG FALLTHROUGH just happened\n");
+ self.pain_finished = 0;
+ }
+ setattachment(self, world, "");
+ if(time > self.pain_finished)
+ {
+ bprint("The ", self.netname, " has returned to base\n");
+ sound (self, CH_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
+ ctf_EventLog("returned", self.team, world);
+ ctf_RespawnFlag(self);
+ }
+ return;
+
+ case FLAG_CARRY:
+ if((self.owner) && (self.speedrunning) && (ctf_captimerecord) && (time >= self.ctf_pickuptime + ctf_captimerecord))
+ {
+ bprint("The ", self.netname, " became impatient after ", ftos_decimals(ctf_captimerecord, 2), " seconds and returned itself\n");
+ sound (self, CH_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
+
+ self.owner.impulse = 141; // returning!
+
+ tmp_entity = self;
+ self = self.owner;
+ ctf_RespawnFlag(tmp_entity);
+ ImpulseCommands();
+ self = tmp_entity;
+ }
+ return;
+
+ default: // this should never happen
+ dprint("Think: Flag exists with no status?\n");
+ return;
+ }
+}
+
+void ctf_FlagTouch()
+{
+ if(gameover) { return; }
+ if(!self) { return; }
+ if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
+ { // The flag fell off the map, respawn it since players can't get to it
+ //ctf_RespawnFlag(self);
+ return;
+ }
+ if(other.deadflag != DEAD_NO) { return; }
+ if(other.classname != "player")
+ { // The flag just touched an object, most likely the world
+ pointparticles(particleeffectnum("kaball_sparks"), self.origin, '0 0 0', 1);
+ sound(self, CH_TRIGGER, "keepaway/touch.wav", VOL_BASE, ATTN_NORM);
+ return;
+ }
+ else if(self.wait > time) { return; }
+
+ switch(self.ctf_status)
+ {
+ case FLAG_BASE:
+ if((other.team == self.team) && (other.flagcarried) && (other.flagcarried.team != self.team))
+ ctf_Handle_Capture(self, other); // other just captured the enemies flag to his base
+ else if((other.team != self.team) && (!other.flagcarried) && (!other.ctf_captureshielded))
+ ctf_Handle_Pickup_Base(self, other); // other just stole the enemies flag
+ break;
+
+ case FLAG_DROPPED:
+ if(other.team == self.team)
+ ctf_Handle_Return(self, other); // other just returned his own flag
+ else if((!other.flagcarried) && ((other.playerid != self.ctf_dropperid) || (time > self.ctf_droptime + autocvar_g_balance_ctf_delay_collect)))
+ ctf_Handle_Pickup_Dropped(self, other); // other just picked up a dropped enemy flag
+ break;
+
+ case FLAG_CARRY:
+ dprint("Someone touched a flag even though it was being carried?\n");
+ break;
+
+ default: // this should never happen
+ dprint("Touch: Flag exists with no status?\n");
+ break;
+ }
+}
+
+void ctf_RespawnFlag(entity flag)
+{
+ // reset the player (if there is one)
+ if((flag.owner) && (flag.owner.flagcarried == flag))
+ {
+ WaypointSprite_Kill(flag.wps_flagcarrier);
+ flag.owner.flagcarried = world;
+
+ if(flag.speedrunning)
+ ctf_FakeTimeLimit(flag.owner, -1);
+ }
+
+ // reset the flag
+ setattachment(flag, world, "");
+ setorigin(flag, flag.ctf_spawnorigin); // replace with flag.ctf_spawnorigin
+ flag.movetype = ((flag.noalign) ? MOVETYPE_NONE : MOVETYPE_TOSS);
+ flag.takedamage = DAMAGE_NO;
+ flag.solid = SOLID_TRIGGER;
+ flag.velocity = '0 0 0';
+ flag.angles = flag.mangle;
+ flag.ctf_status = FLAG_BASE;
+ flag.flags = FL_ITEM | FL_NOTARGET;
+ flag.owner = world;
+}
+
+void ctf_Reset()
+{
+ if(self.owner)
+ if(self.owner.classname == "player")
+ ctf_Handle_Drop(self.owner);
+
+ ctf_RespawnFlag(self);
+}
+
void ctf_SetupFlag(float teamnumber, entity flag) // called when spawning a flag entity on the map as a spawnfunc
{
// declarations
- teamnumber = fabs(teamnumber - bound(0, g_ctf_reverse, 1));
- string flag_team_by_name;
+ teamnumber = fabs(teamnumber - bound(0, g_ctf_reverse, 1)); // if we were originally 1, this will become 0. If we were originally 0, this will become 1.
// main setup
flag.ctf_worldflagnext = ctf_worldflaglist; // link flag into ctf_worldflaglist // todo: find out if this can be simplified
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.noalign = (flag.spawnflags & 1);
+ flag.flags = FL_ITEM | FL_NOTARGET;
+ flag.solid = SOLID_TRIGGER;
+ flag.velocity = '0 0 0';
+ flag.ctf_status = FLAG_BASE;
+ flag.ctf_spawnorigin = flag.origin;
+ flag.mangle = flag.angles;
+ flag.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
+
+ if(flag.spawnflags & 1) // I don't understand what all this is about.
+ {
+ flag.noalign = TRUE;
+ flag.movetype = MOVETYPE_NONE;
+ print("This map was loaded with flags using MOVETYPE_NONE\n");
+ }
+ else
+ {
+ flag.noalign = FALSE;
+ flag.movetype = MOVETYPE_TOSS;
+ print("This map was loaded with flags using MOVETYPE_TOSS\n");
+ }
- flag.nextthink = time + 0.2; // start after doors etc // Samual: 0.2 though? Why?
- flag.think = ctf_PlaceFlag; // todo: needs renaming
flag.reset = ctf_Reset;
+ flag.touch = ctf_FlagTouch;
// appearence
if(!flag.model) { flag.model = ((teamnumber) ? autocvar_g_ctf_flag_red_model : autocvar_g_ctf_flag_blue_model); }
setmodel (flag, flag.model); // precision set below
setsize(flag, FLAG_MIN, FLAG_MAX);
- setorigin(flag, flag.origin + '0 0 37');
+ setorigin(flag, flag.origin);
if(!flag.scale) { flag.scale = 0.6; }
flag.skin = ((teamnumber) ? autocvar_g_ctf_flag_red_skin : autocvar_g_ctf_flag_blue_skin);
precache_model(flag.model);
precache_model("models/ctf/shield.md3");
precache_model("models/ctf/shockwavetransring.md3");
-}
-
-void ctf_PlaceFlag()
-{
- if(self.classname != "item_flag_team") { backtrace("ctf_PlaceFlag was called incorrectly."); return; }
-
- setattachment(self, world, "");
- self.mdl = self.model; // why?
- self.flags = FL_ITEM;
- self.solid = SOLID_TRIGGER;
- self.movetype = MOVETYPE_NONE;
- self.velocity = '0 0 0';
- self.origin_z = self.origin_z + 6; // why 6?
- self.think = ctf_FlagThink;
- self.touch = ctf_TouchEvent;
- self.nextthink = time + 0.1; // why?
- self.cnt = FLAG_BASE;
- self.mangle = self.angles;
- self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
- //self.effects = self.effects | EF_DIMLIGHT;
-
- if(self.noalign) { self.dropped_origin = self.origin; }
- else { droptofloor(); self.movetype = MOVETYPE_TOSS; }
-
- ctf_CreateBaseWaypoints();
- ctf_CaptureShield_Spawn();
- //InitializeEntity(self, ctf_CaptureShield_Spawn, INITPRIO_SETLOCATION);
-}
-
-void ctf_RegenFlag(entity e)
-{
- if(self.classname != "item_flag_team") { backtrace("ctf_RegenFlag was called incorrectly."); return; }
- if(e.waypointsprite_attachedforcarrier)
- WaypointSprite_DetachCarrier(e);
+ // bot waypoints
+ waypoint_spawnforitem_force(flag, flag.origin);
+ flag.nearestwaypointtimeout = 0; // activate waypointing again
+ flag.bot_basewaypoint = flag.nearestwaypoint;
- setattachment(e, world, "");
- e.damageforcescale = 0;
- e.takedamage = DAMAGE_NO;
- e.movetype = MOVETYPE_NONE;
- if(!e.noalign)
- e.movetype = MOVETYPE_TOSS;
- e.velocity = '0 0 0';
- e.solid = SOLID_TRIGGER;
- // TODO: play a sound here
- setorigin(e, e.dropped_origin);
- e.angles = e.mangle;
- e.cnt = FLAG_BASE;
- e.owner = world;
- e.flags = FL_ITEM; // clear FL_ONGROUND and any other junk // there shouldn't be any "junk" set on this... look into it and make sure it's kept clean.
-}
-
-void ctf_ReturnFlag(entity e)
-{
- if(e.classname != "item_flag_team") { backtrace("ctf_ReturnFlag was called incorrectly."); return; }
+ // waypointsprites
+ WaypointSprite_SpawnFixed(((teamnumber) ? "redbase" : "bluebase"), flag.origin + '0 0 64', flag, wps_flagbase, RADARICON_FLAG, colormapPaletteColor(((teamnumber) ? COLOR_TEAM1 : COLOR_TEAM2) - 1, FALSE));
+ WaypointSprite_UpdateTeamRadar(flag.wps_flagbase, RADARICON_FLAG, colormapPaletteColor(((teamnumber) ? COLOR_TEAM1 : COLOR_TEAM2) - 1, FALSE));
- if(e.owner)
- if(e.owner.flagcarried == e)
- {
- WaypointSprite_DetachCarrier(e.owner);
- e.owner.flagcarried = world;
-
- if(e.speedrunning)
- FakeTimeLimit(e.owner, -1);
- }
- e.owner = world;
- RegenFlag(e);
+ // captureshield setup
+ ctf_CaptureShield_Spawn(flag);
}
-void ctf_DropEvent(entity flag, entity penalty_receiver, entity attacker)
-{
- local entity carrier = flag.owner;
-
- // Called on an entity that is not a flag?
- if(flag.classname != "item_flag_team") {
- backtrace("DropFlag a non-flag");
- return; }
-
- // Reset the flag when speedrunning is enabled.
- if(flag.speedrunning) {
- ReturnFlag(flag);
- return; }
-
- // HOW OFTEN DO THESE EVEN HAPPEN? IS THIS NEEDED? todo: remove if not needed.
- if(!flag.owner) {
- dprint("FLAG: drop - no owner?!?!\n");
- return; }
- if(carrier.flagcarried != flag) {
- dprint("FLAG: drop - owner is not carrying this flag??\n");
- return; }
-
- //bprint(p.netname, "^7 lost the ", e.netname, "\n");
- Send_KillNotification (carrier.netname, flag.netname, "", INFO_LOSTFLAG, MSG_INFO);
-
- if(penalty_receiver)
- UpdateFrags(penalty_receiver, -ctf_score_value("penalty_suicidedrop"));
- else
- UpdateFrags(carrier, -ctf_score_value("penalty_drop"));
-
- PlayerScore_Add(carrier, SP_CTF_DROPS, +1);
- ctf_captureshield_update(carrier, 0); // shield only
- flag.playerid = attacker.playerid;
- flag.ctf_droptime = time;
- WaypointSprite_Spawn("flagdropped", 0, 0, flag, '0 0 1' * 61, world, COLOR_TEAM1 + COLOR_TEAM2 - flag.team, flag, waypointsprite_attachedforcarrier, FALSE);
-
- if(carrier.waypointsprite_attachedforcarrier)
- {
- WaypointSprite_Ping(carrier.waypointsprite_attachedforcarrier);
- WaypointSprite_DetachCarrier(carrier);
- }
- else
- {
- bprint("\{1}^1Flag carrier had no flag sprite?!?\n");
- backtrace("Flag carrier had no flag sprite?!?");
- }
-
- ctf_EventLog("dropped", carrier.team, carrier);
- sound (self, CHAN_TRIGGER, self.noise4, VOL_BASE, ATTN_NONE);
- setattachment(flag, world, "");
- flag.damageforcescale = autocvar_g_balance_ctf_damageforcescale;
- flag.takedamage = DAMAGE_YES;
-
- if(carrier.flagcarried == flag)
- carrier.flagcarried = world;
- flag.owner = world;
-
- flag.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
- flag.solid = SOLID_TRIGGER;
- flag.movetype = MOVETYPE_TOSS;
- // setsize(e, '-16 -16 0', '16 16 74');
- setorigin(flag, p.origin - '0 0 24' + '0 0 37');
- flag.cnt = FLAG_DROPPED;
- flag.velocity = '0 0 300';
- flag.pain_finished = time + autocvar_g_ctf_flag_returntime;//30;
+// ==============
+// Hook Functions
+// ==============
- trace_startsolid = FALSE;
- tracebox(flag.origin, flag.mins, flag.maxs, flag.origin, TRUE, flag);
- if(trace_startsolid)
- dprint("FLAG FALLTHROUGH will happen SOON\n");
-}
+// g_ctf_ignore_frags
-void ctf_FlagThink()
+MUTATOR_HOOKFUNCTION(ctf_RemovePlayer)
{
- local entity e;
-
- self.nextthink = time + 0.1;
-
- // sorry, we have to reset the flag size if it got squished by something
- if(self.mins != FLAG_MIN || self.maxs != FLAG_MAX)
- {
- // if we can grow back, grow back
- tracebox(self.origin, FLAG_MIN, FLAG_MAX, self.origin, MOVE_NOMONSTERS, self);
- if(!trace_startsolid)
- setsize(self, FLAG_MIN, FLAG_MAX);
- }
-
- if(self == ctf_worldflaglist) // only for the first flag
- {
- FOR_EACH_CLIENT(e)
- ctf_captureshield_update(e, 1); // release shield only
- }
-
- if(self.speedrunning)
- if(self.cnt == FLAG_CARRY)
- {
- if(self.owner)
- if(flagcaptimerecord)
- if(time >= self.flagpickuptime + flagcaptimerecord)
- {
- bprint("The ", self.netname, " became impatient after ", ftos_decimals(flagcaptimerecord, 2), " seconds and returned itself\n");
-
- sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
- self.owner.impulse = 141; // returning!
-
- e = self;
- self = self.owner;
- ReturnFlag(e);
- ImpulseCommands();
- self = e;
- return;
- }
- }
-
- if(self.cnt == FLAG_BASE)
- return;
-
- if(self.cnt == FLAG_DROPPED)
- {
- // flag fallthrough? FIXME remove this if bug is really fixed now
- if(self.origin_z < -131072)
- {
- dprint("FLAG FALLTHROUGH just happened\n");
- self.pain_finished = 0;
- }
- setattachment(self, world, "");
- if(time > self.pain_finished)
- {
- bprint("The ", self.netname, " has returned to base\n");
- sound (self, CHAN_TRIGGER, self.noise3, VOL_BASE, ATTN_NONE);
- ctf_EventLog("returned", self.team, world);
- ReturnFlag(self);
- }
- return;
- }
-
- e = self.owner;
- if(e.classname != "player" || (e.deadflag) || (e.flagcarried != self))
- {
- dprint("CANNOT HAPPEN - player dead and STILL had a flag!\n");
- DropFlag(self, world, world);
- return;
- }
-
- if(autocvar_g_ctf_allow_drop)
- if(e.BUTTON_USE)
- DropFlag(self, e, world);
+ if(self.flagcarried) { ctf_Handle_Drop(self); }
+ return 0;
}
-void ctf_TouchEvent()
+MUTATOR_HOOKFUNCTION(ctf_PlayerPreThink)
{
- if(gameover) { return; }
- if(!self) { return; }
+ entity flag;
- local float t;
- local entity player;
- local string s, s0, h0, h1;
- if(other.classname != "player")
- return;
- if(other.health < 1)
- return;
+ // 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);
- if(self.cnt == FLAG_CARRY)
- return;
+ // item for stopping players from capturing the flag too often
+ if(self.ctf_captureshielded)
+ self.items |= IT_CTF_SHIELDED;
- if(self.cnt == FLAG_BASE)
- if(other.team == self.team)
- if(other.flagcarried) // he's got a flag
- if(other.flagcarried.team != self.team) // capture
+ // scan through all the flags and notify the client about them
+ for (flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext)
{
- ctf_Handle_Capture(self, other);
-
- /*
- if(other.flagcarried == world)
- {
- return;
- }
- if(autocvar_g_ctf_captimerecord_always || player_count - currentbots <= 1) // at most one human
- {
- t = time - other.flagcarried.flagpickuptime;
- s = ftos_decimals(t, 2);
- s0 = ftos_decimals(flagcaptimerecord, 2);
- h0 = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"));
- h1 = other.netname;
- if(h0 == h1)
- h0 = "their";
- else
- h0 = strcat(h0, "^7's"); // h0: display text for previous netname
- if(flagcaptimerecord == 0)
- {
- s = strcat(" in ", s, " seconds");
- flagcaptimerecord = t;
- db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
- db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
- write_recordmarker(other, time - t, t);
- }
- else if(t < flagcaptimerecord)
- {
- s = strcat(" in ", s, " seconds, breaking ", h0, " previous record of ", s0, " seconds");
- flagcaptimerecord = t;
- db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time"), ftos(t));
- db_put(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname"), h1);
- write_recordmarker(other, time - t, t);
- }
- else
- {
- s = strcat(" in ", s, " seconds, failing to break ", h0, " record of ", s0, " seconds");
- }
- }
- else
- s = "";
-
- Send_KillNotification (other.netname, other.flagcarried.netname, s, INFO_CAPTUREFLAG, MSG_INFO);
-
- PlayerTeamScore_Add(other, SP_CTF_CAPS, ST_CTF_CAPS, 1);
- ctf_EventLog("capture", other.flagcarried.team, other);
- // give credit to the individual player
- UpdateFrags(other, ctf_score_value("score_capture"));
-
- if(autocvar_g_ctf_flag_capture_effects) {
- if(other.team == COLOR_TEAM1) { // red team scores effect
- pointparticles(particleeffectnum("red_ground_quake"), self.origin, '0 0 0', 1);
- flag_cap_ring_spawn(self.origin);
- }
- if(other.team == COLOR_TEAM2) { // blue team scores effect
- pointparticles(particleeffectnum("blue_ground_quake"), self.origin, '0 0 0', 1);
- flag_cap_ring_spawn(self.origin);
- }
- }
-
- sound (other, CHAN_AUTO, self.noise2, VOL_BASE, ATTN_NONE);
- WaypointSprite_DetachCarrier(other);
- if(self.speedrunning)
- FakeTimeLimit(other, -1);
- RegenFlag (other.flagcarried);
- other.flagcarried = world;
- other.next_take_time = time + 1;
- */
+ if(flag.ctf_status == FLAG_CARRY)
+ if(flag.owner == self)
+ self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_CARRYING : IT_BLUE_FLAG_CARRYING); // carrying: self is currently carrying the flag
+ else
+ self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_TAKEN : IT_BLUE_FLAG_TAKEN); // taken: someone on self's team is carrying the flag
+ else if(flag.ctf_status == FLAG_DROPPED)
+ self.items |= ((flag.items & IT_KEY2) ? IT_RED_FLAG_LOST : IT_BLUE_FLAG_LOST); // lost: the flag is dropped somewhere on the map
}
- if(self.cnt == FLAG_BASE)
- if(other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2) // only red and blue team can steal flags // todo: needed still if rogues are gone?
- if(other.team != self.team)
- if(!other.flagcarried)
- if(!other.ctf_captureshielded)
- {
- ctf_Handle_Pickup(self, other);
-
- /*
- if(other.next_take_time > time)
- return;
-
- if(autocvar_g_ctf_flag_pickup_effects) // pickup effect
- pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
-
- // pick up
- self.flagpickuptime = time; // used for timing runs
- self.speedrunning = other.speedrunning; // if speedrunning, flag will self-return and teleport the owner back after the record
- if(other.speedrunning)
- if(flagcaptimerecord)
- FakeTimeLimit(other, time + flagcaptimerecord);
- self.solid = SOLID_NOT;
- setorigin(self, self.origin); // relink
- self.owner = other;
- other.flagcarried = self;
- self.cnt = FLAG_CARRY;
- self.angles = '0 0 0';
- //bprint(other.netname, "^7 got the ", self.netname, "\n");
- Send_KillNotification (other.netname, self.netname, "", INFO_GOTFLAG, MSG_INFO);
- UpdateFrags(other, ctf_score_value("score_pickup_base"));
- self.ctf_dropperid = other.playerid;
- PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
- ctf_EventLog("steal", self.team, other);
- sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
-
- FOR_EACH_PLAYER(player)
- if(player.team == self.team)
- centerprint(player, "The enemy got your flag! Retrieve it!");
-
- self.movetype = MOVETYPE_NONE;
- setorigin(self, FLAG_CARRY_POS);
- setattachment(self, other, "");
- WaypointSprite_AttachCarrier("flagcarrier", other);
- WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
- WaypointSprite_Ping(self.sprite);
-
- return;
- */
- }
+ return 0;
+}
- if(self.cnt == FLAG_DROPPED)
+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
{
- self.flags = FL_ITEM; // clear FL_ONGROUND and any other junk
- if(other.team == self.team || (other.team != COLOR_TEAM1 && other.team != COLOR_TEAM2))
+ if(frag_target == frag_attacker) // damage done to yourself
{
- // return flag
- Send_KillNotification (other.netname, self.netname, "", INFO_RETURNFLAG, MSG_INFO);
- //bprint(other.netname, "^7 returned the ", self.netname, "\n");
-
- // punish the player who last had it
- FOR_EACH_PLAYER(player)
- if(player.playerid == self.ctf_dropperid)
- {
- PlayerScore_Add(player, SP_SCORE, -ctf_score_value("penalty_returned"));
- ctf_captureshield_update(player, 0); // shield only
- }
-
- // punish the team who was last carrying it
- if(self.team == COLOR_TEAM1)
- TeamScore_AddToTeam(COLOR_TEAM2, ST_SCORE, -ctf_score_value("penalty_returned"));
- else
- TeamScore_AddToTeam(COLOR_TEAM1, ST_SCORE, -ctf_score_value("penalty_returned"));
-
- // reward the player who returned it
- if(other.playerid == self.playerid) // is this the guy who killed the FC last?
- {
- if(other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
- UpdateFrags(other, ctf_score_value("score_return_by_killer"));
- else
- UpdateFrags(other, ctf_score_value("score_return_rogue_by_killer"));
- }
- else
- {
- if(other.team == COLOR_TEAM1 || other.team == COLOR_TEAM2)
- UpdateFrags(other, ctf_score_value("score_return"));
- else
- UpdateFrags(other, ctf_score_value("score_return_rogue"));
- }
- PlayerScore_Add(other, SP_CTF_RETURNS, 1);
- ctf_EventLog("return", self.team, other);
- sound (other, CHAN_AUTO, self.noise1, VOL_BASE, ATTN_NONE);
- ReturnFlag(self);
+ frag_damage *= autocvar_g_ctf_flagcarrier_selfdamagefactor;
+ frag_force *= autocvar_g_ctf_flagcarrier_selfforcefactor;
}
- else if(!other.flagcarried && (other.playerid != self.ctf_dropperid || time > self.ctf_droptime + autocvar_g_balance_ctf_delay_collect))
+ else // damage done to noncarriers
{
- if(self.waypointsprite_attachedforcarrier)
- WaypointSprite_DetachCarrier(self);
-
- if(autocvar_g_ctf_flag_pickup_effects) // field pickup effect
- pointparticles(particleeffectnum("smoke_ring"), 0.5 * (self.absmin + self.absmax), '0 0 0', 1);
-
- // pick up
- self.solid = SOLID_NOT;
- setorigin(self, self.origin); // relink
- self.owner = other;
- other.flagcarried = self;
- self.cnt = FLAG_CARRY;
- Send_KillNotification (other.netname, self.netname, "", INFO_PICKUPFLAG, MSG_INFO);
- //bprint(other.netname, "^7 picked up the ", self.netname, "\n");
-
- float f;
- f = bound(0, (self.pain_finished - time) / autocvar_g_ctf_flag_returntime, 1);
- //print("factor is ", ftos(f), "\n");
- f = ctf_score_value("score_pickup_dropped_late") * (1-f)
- + ctf_score_value("score_pickup_dropped_early") * f;
- f = floor(f + 0.5);
- self.ctf_dropperid = other.playerid;
- //print("score is ", ftos(f), "\n");
-
- UpdateFrags(other, f);
- PlayerScore_Add(other, SP_CTF_PICKUPS, 1);
- ctf_EventLog("pickup", self.team, other);
- sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
-
- FOR_EACH_PLAYER(player)
- if(player.team == self.team)
- centerprint(player, "The enemy got your flag! Retrieve it!");
-
- self.movetype = MOVETYPE_NONE; // flag must have MOVETYPE_NONE here, otherwise it will drop through the floor...
- setorigin(self, FLAG_CARRY_POS);
- setattachment(self, other, "");
- self.damageforcescale = 0;
- self.takedamage = DAMAGE_NO;
- WaypointSprite_AttachCarrier("flagcarrier", other);
- WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 1 0');
+ frag_damage *= autocvar_g_ctf_flagcarrier_damagefactor;
+ frag_force *= autocvar_g_ctf_flagcarrier_forcefactor;
}
- }
+ }*/
+ return 0;
}
-
-// =======================
-// CaptureShield Functions
-// =======================
-
-float ctf_CaptureShield_CheckStatus(entity p) // check to see
+MUTATOR_HOOKFUNCTION(ctf_GiveFragsForKill)
{
- float s, se;
- entity e;
- float players_worseeq, players_total;
-
- if(captureshield_max_ratio <= 0)
- return FALSE;
-
- s = PlayerScore_Add(p, SP_SCORE, 0);
- if(s >= -captureshield_min_negscore)
- return FALSE;
-
- players_total = players_worseeq = 0;
- FOR_EACH_PLAYER(e)
- {
- if(e.team != p.team)
- 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 * captureshield_max_ratio)
- return FALSE;
-
- return TRUE;
+ frag_score = 0; // no frags counted in keepaway
+ return (g_ctf_ignore_frags); // you deceptive little bugger ;3 This needs to be true in order for this function to even count.
}
-void ctf_CaptureShield_Update(entity p, float dir)
+MUTATOR_HOOKFUNCTION(ctf_PlayerUseKey)
{
- float should;
- if(dir == p.ctf_captureshielded) // 0: shield only, 1: unshield only
- {
- should = ctf_CaptureShield_CheckStatus(p);
- if(should != dir)
- {
- if(should) // TODO csqc notifier for this
- centerprint_atprio(p, CENTERPRIO_SHIELDING, "^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.");
- else
- centerprint_atprio(p, CENTERPRIO_SHIELDING, "^3You are now free.\n\n^3Feel free to ^1try to capture^3 the flag again\n^3if you think you will succeed.");
-
- p.ctf_captureshielded = should;
- }
- }
-}
-
-float ctf_CaptureShield_Customize()
-{
- if not(other.ctf_captureshielded)
- return FALSE;
- if(self.team == other.team)
- return FALSE;
- return TRUE;
-}
-
-void ctf_CaptureShield_Touch()
-{
- if not(other.ctf_captureshielded)
- return;
- if(self.team == other.team)
- return;
- vector mymid;
- vector othermid;
- mymid = (self.absmin + self.absmax) * 0.5;
- othermid = (other.absmin + other.absmax) * 0.5;
- Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * captureshield_force);
- centerprint_atprio(other, CENTERPRIO_SHIELDING, "^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.");
-}
-
-void ctf_CaptureShield_Spawn()
-{
- entity e;
- e = spawn();
- e.enemy = self;
- e.team = self.team;
- e.touch = ctf_CaptureShield_Touch;
- e.customizeentityforclient = ctf_CaptureShield_Customize;
- e.classname = "ctf_captureshield";
- e.effects = EF_ADDITIVE;
- e.movetype = MOVETYPE_NOCLIP;
- e.solid = SOLID_TRIGGER;
- e.avelocity = '7 0 11';
- setorigin(e, self.origin);
- setmodel(e, "models/ctf/shield.md3");
- e.scale = 0.5;
- setsize(e, e.scale * e.mins, e.scale * e.maxs);
-}
-
-
-// ==============
-// Hook Functions
-// ==============
-
-MUTATOR_HOOKFUNCTION(ctf_RemovePlayer)
-{
- if(self.flagcarried) { ctf_DropEvent(self); } // figure this out
-
- return TRUE;
+ if(autocvar_g_ctf_allow_drop)
+ ctf_Handle_Drop(self);
+
+ return 0;
}
-
// ==========
// Spawnfuncs
// ==========
{
if(!g_ctf) { remove(self); return; }
- ctf_SetupFlag(1, self);
+ ctf_SetupFlag(1, self); // 1 = red
}
/*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -37) (48 48 37)
{
if(!g_ctf) { remove(self); return; }
- ctf_SetupFlag(0, self);
+ ctf_SetupFlag(0, self); // the 0 is misleading, but -- 0 = blue.
}
/*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32)
// Initialization
// ==============
-// code from here on is just to support maps that don't have control point and team entities
+// code from here on is just to support maps that don't have flag and team entities
void ctf_SpawnTeam (string teamname, float teamcolor)
{
- local entity oldself;
+ entity oldself;
oldself = self;
self = spawn();
self.classname = "ctf_team";
self = oldself;
}
-void ctf_DelayedInit()
+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 TEAMS FOUND FOR CTF! creating them anyway.\n");
ctf_SpawnTeam("Red", COLOR_TEAM1 - 1);
ctf_SpawnTeam("Blue", COLOR_TEAM2 - 1);
}
+
+ ScoreRules_ctf();
}
void ctf_Initialize()
{
- flagcaptimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
+ ctf_captimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
- captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;
- captureshield_max_ratio = autocvar_g_ctf_shield_max_ratio;
- captureshield_force = autocvar_g_ctf_shield_force;
+ 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;
- g_ctf_win_mode = cvar("g_ctf_win_mode");
-
- ScoreRules_ctf();
+ //g_ctf_win_mode = cvar("g_ctf_win_mode");
InitializeEntity(world, ctf_DelayedInit, INITPRIO_GAMETYPE);
}
MUTATOR_HOOK(MakePlayerObserver, ctf_RemovePlayer, CBC_ORDER_ANY);
MUTATOR_HOOK(ClientDisconnect, ctf_RemovePlayer, CBC_ORDER_ANY);
MUTATOR_HOOK(PlayerDies, ctf_RemovePlayer, 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(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(PlayerPowerups, ctf_PlayerPowerups, CBC_ORDER_ANY);
MUTATOR_ONADD
error("This is a game type and it cannot be removed at runtime.");
}
- return TRUE;
-}
\ No newline at end of file
+ return 0;
+}