string ctf_CaptureRecord(entity flag, entity player)
{
float cap_time, cap_record, success;
- string cap_message, refername;
+ string cap_message = string_null, refername;
if((autocvar_g_ctf_captimerecord_always) || (player_count - currentbots))
{
WaypointSprite_UpdateTeamRadar(player.wps_flagcarrier, RADARICON_FLAGCARRIER, WPCOLOR_FLAGCARRIER(player.team));
}
+void ctf_CalculatePassVelocity(entity flag, vector to, vector from, float turnrate)
+{
+ float current_distance = vlen((('1 0 0' * to_x) + ('0 1 0' * to_y)) - (('1 0 0' * from_x) + ('0 1 0' * from_y))); // for the sake of this check, exclude Z axis
+ float initial_height = min(autocvar_g_ctf_pass_arc_max, (flag.pass_distance * tanh(autocvar_g_ctf_pass_arc)));
+ float current_height = (initial_height * min(1, (current_distance / flag.pass_distance)));
+ //print("current_height = ", ftos(current_height), ", initial_height = ", ftos(initial_height), ".\n");
+
+ vector targpos;
+ if(current_height) // make sure we can actually do this arcing path
+ {
+ targpos = (to + ('0 0 1' * current_height));
+ WarpZone_TraceLine(flag.origin, targpos, MOVE_NOMONSTERS, flag);
+ if(trace_fraction < 1)
+ {
+ //print("normal arc line failed, trying to find new pos...");
+ WarpZone_TraceLine(to, targpos, MOVE_NOMONSTERS, flag);
+ targpos = (trace_endpos + FLAG_PASS_ARC_OFFSET);
+ WarpZone_TraceLine(flag.origin, targpos, MOVE_NOMONSTERS, flag);
+ if(trace_fraction < 1) { targpos = to; /* print(" ^1FAILURE^7, reverting to original direction.\n"); */ }
+ /*else { print(" ^3SUCCESS^7, using new arc line.\n"); } */
+ }
+ }
+ else { targpos = to; }
+
+ //flag.angles = normalize(('0 1 0' * to_y) - ('0 1 0' * from_y));
+
+ vector desired_direction = normalize(targpos - from);
+ if(turnrate) { flag.velocity = (normalize(normalize(flag.velocity) + (desired_direction * autocvar_g_ctf_pass_turnrate)) * autocvar_g_ctf_pass_velocity); }
+ else { flag.velocity = (desired_direction * autocvar_g_ctf_pass_velocity); }
+}
+
+float ctf_CheckPassDirection(vector head_center, vector passer_center, vector passer_angle, vector nearest_to_passer)
+{
+ if(autocvar_g_ctf_pass_directional_max || autocvar_g_ctf_pass_directional_min)
+ {
+ // directional tracing only
+ float spreadlimit;
+ makevectors(passer_angle);
+
+ // find the closest point on the enemy to the center of the attack
+ float ang; // angle between shotdir and h
+ float h; // hypotenuse, which is the distance between attacker to head
+ float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
+
+ h = vlen(head_center - passer_center);
+ ang = acos(dotproduct(normalize(head_center - passer_center), v_forward));
+ a = h * cos(ang);
+
+ vector nearest_on_line = (passer_center + a * v_forward);
+ float distance_from_line = vlen(nearest_to_passer - nearest_on_line);
+
+ spreadlimit = (autocvar_g_ctf_pass_radius ? min(1, (vlen(passer_center - nearest_on_line) / autocvar_g_ctf_pass_radius)) : 1);
+ spreadlimit = (autocvar_g_ctf_pass_directional_min * (1 - spreadlimit) + autocvar_g_ctf_pass_directional_max * spreadlimit);
+
+ if(spreadlimit && (distance_from_line <= spreadlimit) && ((vlen(normalize(head_center - passer_center) - v_forward) * RAD2DEG) <= 90))
+ { return TRUE; }
+ else
+ { return FALSE; }
+ }
+ else { return TRUE; }
+}
+
// =======================
// CaptureShield Functions
// main
flag.movetype = MOVETYPE_TOSS;
flag.takedamage = DAMAGE_YES;
+ flag.angles = '0 0 0';
flag.health = flag.max_flag_health;
flag.ctf_droptime = time;
flag.ctf_dropper = player;
if(droptype == DROP_PASS)
{
+ flag.pass_distance = 0;
flag.pass_sender = world;
flag.pass_target = world;
}
flag.movetype = MOVETYPE_NONE;
flag.takedamage = DAMAGE_NO;
flag.solid = SOLID_NOT;
+ flag.angles = '0 0 0';
flag.ctf_status = FLAG_CARRY;
// messages and sounds
sender.throw_antispam = time + autocvar_g_ctf_pass_wait;
player.throw_antispam = sender.throw_antispam;
+ flag.pass_distance = 0;
flag.pass_sender = world;
flag.pass_target = world;
}
{
case DROP_PASS:
{
+ // warpzone support:
+ // for the examples, we assume player -> wz1 -> ... -> wzn -> receiver
+ // findradius has already put wzn ... wz1 into receiver's warpzone parameters!
WarpZone_RefSys_Copy(flag, receiver);
- targ_origin = WarpZone_RefSys_TransformOrigin(receiver, flag, (0.5 * (receiver.absmin + receiver.absmax)));
- flag.velocity = (normalize(targ_origin - player.origin) * autocvar_g_ctf_pass_velocity);
- break;
- }
-
- case DROP_THROW:
- {
- makevectors((player.v_angle_y * '0 1 0') + (player.v_angle_x * '0.5 0 0'));
- flag_velocity = ('0 0 200' + ((v_forward * autocvar_g_ctf_drop_velocity) * ((player.items & IT_STRENGTH) ? autocvar_g_ctf_drop_strengthmultiplier : 1)));
- flag.velocity = W_CalculateProjectileVelocity(player.velocity, flag_velocity, FALSE);
- break;
- }
-
- 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:
- {
+ WarpZone_RefSys_AddInverse(flag, receiver); // wz1^-1 ... wzn^-1 receiver
+ targ_origin = WarpZone_RefSys_TransformOrigin(receiver, flag, (0.5 * (receiver.absmin + receiver.absmax))); // this is target origin as seen by the flag
+
+ flag.pass_distance = vlen((('1 0 0' * targ_origin_x) + ('0 1 0' * targ_origin_y)) - (('1 0 0' * player.origin_x) + ('0 1 0' * player.origin_y))); // for the sake of this check, exclude Z axis
+ ctf_CalculatePassVelocity(flag, targ_origin, player.origin, FALSE);
+
// main
flag.movetype = MOVETYPE_FLY;
flag.takedamage = DAMAGE_NO;
// other
sound(player, CH_TRIGGER, flag.snd_flag_touch, VOL_BASE, ATTN_NORM);
- WarpZone_TrailParticles(world, particleeffectnum(flag.passeffect), targ_origin, player.origin);
+ WarpZone_TrailParticles(world, particleeffectnum(flag.passeffect), player.origin, targ_origin);
ctf_EventLog("pass", flag.team, player);
break;
}
-
- case DROP_RESET:
+
+ case DROP_THROW:
{
- // do nothing
+ makevectors((player.v_angle_y * '0 1 0') + (bound(autocvar_g_ctf_throw_angle_min, player.v_angle_x, autocvar_g_ctf_throw_angle_max) * '1 0 0'));
+
+ flag_velocity = (('0 0 1' * autocvar_g_ctf_throw_velocity_up) + ((v_forward * autocvar_g_ctf_throw_velocity_forward) * ((player.items & IT_STRENGTH) ? autocvar_g_ctf_throw_strengthmultiplier : 1)));
+ flag.velocity = W_CalculateProjectileVelocity(player.velocity, flag_velocity, FALSE);
+ ctf_Handle_Drop(flag, player, droptype);
+ break;
+ }
+
+ case DROP_RESET:
+ {
+ flag.velocity = '0 0 0'; // do nothing
break;
}
default:
- case DROP_THROW:
case DROP_NORMAL:
{
+ flag.velocity = W_CalculateProjectileVelocity(player.velocity, (('0 0 1' * autocvar_g_ctf_drop_velocity_up) + ((('0 1 0' * crandom()) + ('1 0 0' * crandom())) * autocvar_g_ctf_drop_velocity_side)), FALSE);
ctf_Handle_Drop(flag, player, droptype);
break;
}
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!"));
+ //if(ctf_stalemate) { centerprint(tmp_player, "Stalemate! Enemies can see you on radar!"); }
+ }
+ //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);
case PICKUP_BASE:
{
PlayerTeamScore_AddScore(player, autocvar_g_ctf_score_pickup_base);
+ ctf_EventLog("steal", flag.team, player);
break;
}
pickup_dropped_score = floor((autocvar_g_ctf_score_pickup_dropped_late * (1 - pickup_dropped_score) + autocvar_g_ctf_score_pickup_dropped_early * pickup_dropped_score) + 0.5);
dprint("pickup_dropped_score is ", ftos(pickup_dropped_score), "\n");
PlayerTeamScore_AddScore(player, pickup_dropped_score);
+ ctf_EventLog("pickup", flag.team, player);
break;
}
void ctf_CheckStalemate(void)
{
// declarations
- float stale_red_flags, stale_blue_flags;
+ float stale_red_flags = 0, stale_blue_flags = 0;
entity tmp_entity;
- entity ctf_staleflaglist; // reset the list, we need to build the list each time this function runs
+ entity ctf_staleflaglist = world; // reset the list, we need to build the list each time this function runs
// build list of stale flags
for(tmp_entity = ctf_worldflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_worldflagnext)
{
- if(autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
+ if(autocvar_g_ctf_stalemate)
if(tmp_entity.ctf_status != FLAG_BASE)
- if(time >= tmp_entity.ctf_pickuptime + autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
+ if(time >= tmp_entity.ctf_pickuptime + autocvar_g_ctf_stalemate_time)
{
tmp_entity.ctf_staleflagnext = ctf_staleflaglist; // link flag into staleflaglist
ctf_staleflaglist = tmp_entity;
if(stale_red_flags && stale_blue_flags)
ctf_stalemate = TRUE;
- else if(!stale_red_flags && !stale_blue_flags)
- ctf_stalemate = FALSE;
-
+ else if((!stale_red_flags && !stale_blue_flags) && autocvar_g_ctf_stalemate_endcondition == 2)
+ { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; }
+ else if((!stale_red_flags || !stale_blue_flags) && autocvar_g_ctf_stalemate_endcondition == 1)
+ { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; }
+
// if sufficient stalemate, then set up the waypointsprite and announce the stalemate if necessary
if(ctf_stalemate)
{
switch(self.ctf_status) // reset flag angles in case warpzones adjust it
{
case FLAG_DROPPED:
- case FLAG_PASSING:
{
self.angles = '0 0 0';
break;
{
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);
+ if(vlen(self.origin - tmp_entity.origin) < autocvar_g_ctf_dropped_capture_radius)
+ if(time > tmp_entity.ctf_droptime + autocvar_g_ctf_dropped_capture_delay)
+ ctf_Handle_Capture(self, tmp_entity, CAPTURE_DROPPED);
}
return;
}
ImpulseCommands();
self = tmp_entity;
}
- if(autocvar_g_ctf_flagcarrier_waypointforenemy_stalemate)
+ if(autocvar_g_ctf_stalemate)
{
if(time >= wpforenemy_nextthink)
{
return;
}
- case FLAG_PASSING: // todo make work with warpzones
+ case FLAG_PASSING:
{
vector targ_origin = ((self.pass_target.absmin + self.pass_target.absmax) * 0.5);
- vector old_targ_origin = targ_origin;
- targ_origin = WarpZone_RefSys_TransformOrigin(self.pass_target, self, targ_origin);
+ targ_origin = WarpZone_RefSys_TransformOrigin(self.pass_target, self, targ_origin); // origin of target as seen by the flag (us)
WarpZone_TraceLine(self.origin, targ_origin, MOVE_NOMONSTERS, self);
-
- print(strcat("self: ", vtos(self.origin), ", old: ", vtos(old_targ_origin), " (", ftos(vlen(self.origin - old_targ_origin)), "qu)"), ", transformed: ", vtos(targ_origin), " (", ftos(vlen(self.origin - targ_origin)), "qu)", ".\n");
- if((self.pass_target.deadflag != DEAD_NO)
+ if((self.pass_target == world)
+ || (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))
{
+ // give up, pass failed
ctf_Handle_Drop(self, world, DROP_PASS);
}
- else // still a viable target, go for it
+ else
{
- 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);
+ // still a viable target, go for it
+ ctf_CalculatePassVelocity(self, targ_origin, self.origin, TRUE);
}
return;
}
flag.ctf_status = FLAG_BASE;
flag.owner = world;
+ flag.pass_distance = 0;
flag.pass_sender = world;
flag.pass_target = world;
flag.ctf_dropper = world;
flag.ctf_pickuptime = 0;
flag.ctf_droptime = 0;
-
- wpforenemy_announced = FALSE;
}
void ctf_Reset()
}
else if(frag_target.flagcarried && (frag_target.deadflag == DEAD_NO) && IsDifferentTeam(frag_target, frag_attacker)) // if the target is a flagcarrier
{
- if(autocvar_g_ctf_flagcarrier_auto_helpme_when_damaged > ('1 0 0' * healtharmor_maxdamage(frag_target.health, frag_target.armorvalue, autocvar_g_balance_armor_blockpercent)))
+ if(autocvar_g_ctf_flagcarrier_auto_helpme_damage > ('1 0 0' * healtharmor_maxdamage(frag_target.health, frag_target.armorvalue, autocvar_g_balance_armor_blockpercent)))
+ if(time > frag_target.wps_helpme_time + autocvar_g_ctf_flagcarrier_auto_helpme_time)
+ {
+ frag_target.wps_helpme_time = time;
WaypointSprite_HelpMePing(frag_target.wps_flagcarrier);
+ }
}
return FALSE;
}
// pass the flag to a team mate
if(autocvar_g_ctf_pass)
{
- entity head, closest_target;
+ entity head, closest_target = world;
head = WarpZone_FindRadius(player.origin, autocvar_g_ctf_pass_radius, TRUE);
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))
+ if(!head.speedrunning && !head.vehicle)
{
- 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 TRUE;
- }
- else if(player.flagcarried)
+ // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
+ vector head_center = WarpZone_UnTransformOrigin(head, CENTER_OR_VIEWOFS(head));
+ vector passer_center = CENTER_OR_VIEWOFS(player);
+
+ if(ctf_CheckPassDirection(head_center, passer_center, player.v_angle, head.WarpZone_findradius_nearest))
{
- if(closest_target)
+ 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 TRUE;
+ }
+ else if(player.flagcarried)
{
- if(vlen(player.origin - WarpZone_UnTransformOrigin(head, head.origin)) < vlen(player.origin - WarpZone_UnTransformOrigin(closest_target, closest_target.origin)))
- { closest_target = head; }
+ if(closest_target)
+ {
+ vector closest_target_center = WarpZone_UnTransformOrigin(closest_target, CENTER_OR_VIEWOFS(closest_target));
+ if(vlen(passer_center - head_center) < vlen(passer_center - closest_target_center))
+ { closest_target = head; }
+ }
+ else { closest_target = head; }
}
- else { closest_target = head; }
}
}
head = head.chain;
}
// throw the flag in front of you
- if(autocvar_g_ctf_drop && player.flagcarried)
- { ctf_Handle_Throw(player, world, DROP_THROW); return TRUE; }
+ if(autocvar_g_ctf_throw && player.flagcarried)
+ {
+ if(player.throw_count == -1)
+ {
+ if(time > player.throw_prevtime + autocvar_g_ctf_throw_punish_delay)
+ {
+ player.throw_prevtime = time;
+ player.throw_count = 1;
+ ctf_Handle_Throw(player, world, DROP_THROW);
+ return TRUE;
+ }
+ else
+ {
+ centerprint(player, strcat("Too many flag throws, throwing disabled for ", ftos(rint((player.throw_prevtime + autocvar_g_ctf_throw_punish_delay) - time)), " seconds."));
+ return FALSE;
+ }
+ }
+ else
+ {
+ if(time > player.throw_prevtime + autocvar_g_ctf_throw_punish_time) { player.throw_count = 1; }
+ else { player.throw_count += 1; }
+ if(player.throw_count >= autocvar_g_ctf_throw_punish_count) { player.throw_count = -1; }
+
+ player.throw_prevtime = time;
+ ctf_Handle_Throw(player, world, DROP_THROW);
+ return TRUE;
+ }
+ }
}
return FALSE;
{
if(self.wps_flagcarrier) // update the flagcarrier waypointsprite with "NEEDING HELP" notification
{
+ self.wps_helpme_time = time;
WaypointSprite_HelpMePing(self.wps_flagcarrier);
}
else // create a normal help me waypointsprite
{
if(vh_player.flagcarried)
{
- if(!autocvar_g_ctf_allow_vehicle_carry)
+ if(!autocvar_g_ctf_allow_vehicle_carry && !autocvar_g_ctf_allow_vehicle_touch)
{
ctf_Handle_Throw(vh_player, world, DROP_NORMAL);
}
flag.solid = SOLID_NOT;
flag.nextthink = FALSE; // stop thinking
- print("stopping the ", flag.netname, " from moving.\n");
+ //dprint("stopping the ", flag.netname, " from moving.\n");
break;
}
{
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.");
}