X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fgamemodes%2Fgamemode%2Fctf%2Fsv_ctf.qc;h=ec296a9c9cec51484a6c66e97c4e091928ca36f9;hb=258867c634125e1d048869b4a5d8ef279e8b8228;hp=09a46312305e5c8563b5eeb1c9315d1c458ade4a;hpb=e30214cf338291f1709fb02ed5e84cad9321e156;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc index 09a463123..ec296a9c9 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc @@ -1,7 +1,16 @@ #include "sv_ctf.qh" #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -48,6 +57,8 @@ bool autocvar_g_ctf_flag_return_when_unreachable; float autocvar_g_ctf_flag_return_damage; float autocvar_g_ctf_flag_return_damage_delay; float autocvar_g_ctf_flag_return_dropped; +bool autocvar_g_ctf_flag_waypoint = true; +float autocvar_g_ctf_flag_waypoint_maxdistance; float autocvar_g_ctf_flagcarrier_auto_helpme_damage; float autocvar_g_ctf_flagcarrier_auto_helpme_time; float autocvar_g_ctf_flagcarrier_selfdamagefactor; @@ -145,7 +156,7 @@ void ctf_FlagcarrierWaypoints(entity player) { WaypointSprite_Spawn(WP_FlagCarrier, 0, 0, player, FLAG_WAYPOINT_OFFSET, NULL, player.team, player, wps_flagcarrier, true, RADARICON_FLAG); WaypointSprite_UpdateMaxHealth(player.wps_flagcarrier, 2 * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x); - WaypointSprite_UpdateHealth(player.wps_flagcarrier, healtharmor_maxdamage(GetResourceAmount(player, RESOURCE_HEALTH), GetResourceAmount(player, RESOURCE_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x); + WaypointSprite_UpdateHealth(player.wps_flagcarrier, healtharmor_maxdamage(GetResource(player, RES_HEALTH), GetResource(player, RES_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x); WaypointSprite_UpdateTeamRadar(player.wps_flagcarrier, RADARICON_FLAGCARRIER, WPCOLOR_FLAGCARRIER(player.team)); if(player.flagcarried && CTF_SAMETEAM(player, player.flagcarried)) @@ -341,7 +352,7 @@ void ctf_Handle_Drop(entity flag, entity player, int droptype) set_movetype(flag, MOVETYPE_TOSS); flag.takedamage = DAMAGE_YES; flag.angles = '0 0 0'; - SetResourceAmount(flag, RESOURCE_HEALTH, flag.max_flag_health); + SetResourceExplicit(flag, RES_HEALTH, flag.max_health); flag.ctf_droptime = time; flag.ctf_dropper = player; flag.ctf_status = FLAG_DROPPED; @@ -363,8 +374,8 @@ void ctf_Handle_Drop(entity flag, entity player, int droptype) 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, GetResourceAmount(flag, RESOURCE_HEALTH)); + WaypointSprite_UpdateMaxHealth(flag.wps_flagdropped, flag.max_health); + WaypointSprite_UpdateHealth(flag.wps_flagdropped, GetResource(flag, RES_HEALTH)); } player.throw_antispam = time + autocvar_g_ctf_pass_wait; @@ -436,11 +447,24 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) if(!flag) { return; } if((droptype == DROP_PASS) && !receiver) { return; } - if(flag.speedrunning) { ctf_RespawnFlag(flag); return; } + if(flag.speedrunning) + { + // ensure old waypoints are removed before resetting the flag + WaypointSprite_Kill(player.wps_flagcarrier); + + if(player.wps_enemyflagcarrier) + WaypointSprite_Kill(player.wps_enemyflagcarrier); + + if(player.wps_flagreturn) + WaypointSprite_Kill(player.wps_flagreturn); + ctf_RespawnFlag(flag); + return; + } // reset the flag setattachment(flag, NULL, ""); - setorigin(flag, player.origin + FLAG_DROP_OFFSET); + tracebox(player.origin - FLAG_DROP_OFFSET, flag.m_mins, flag.m_maxs, player.origin + FLAG_DROP_OFFSET, MOVE_NOMONSTERS, flag); + setorigin(flag, trace_endpos); flag.owner.flagcarried = NULL; GameRules_scoring_vip(flag.owner, false); flag.owner = NULL; @@ -519,10 +543,12 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) ctf_CaptureShield_Update(player, 0); // shield player from picking up flag } +#if 0 void shockwave_spawn(string m, vector org, float sz, float t1, float t2) { return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2); } +#endif // ============== // Event Handlers @@ -586,7 +612,9 @@ void ctf_Handle_Capture(entity flag, entity toucher, int capturetype) // effects Send_Effect_(flag.capeffect, flag.origin, '0 0 0', 1); - //shockwave_spawn("models/ctf/shockwavetransring.md3", flag.origin - '0 0 15', -0.8, 0, 1); +#if 0 + shockwave_spawn("models/ctf/shockwavetransring.md3", flag.origin - '0 0 15', -0.8, 0, 1); +#endif // other if(capturetype == CAPTURE_NORMAL) @@ -679,7 +707,7 @@ void ctf_Handle_Pickup(entity flag, entity player, int pickuptype) switch(pickuptype) { case PICKUP_BASE: flag.ctf_pickuptime = time; break; // used for timing runs - case PICKUP_DROPPED: SetResourceAmount(flag, RESOURCE_HEALTH, flag.max_flag_health); break; // reset health/return timelimit + case PICKUP_DROPPED: SetResourceExplicit(flag, RES_HEALTH, flag.max_health); break; // reset health/return timelimit default: break; } @@ -763,9 +791,9 @@ void ctf_CheckFlagReturn(entity flag, int returntype) { if((flag.ctf_status == FLAG_DROPPED) || (flag.ctf_status == FLAG_PASSING)) { - if(flag.wps_flagdropped) { WaypointSprite_UpdateHealth(flag.wps_flagdropped, GetResourceAmount(flag, RESOURCE_HEALTH)); } + if(flag.wps_flagdropped) { WaypointSprite_UpdateHealth(flag.wps_flagdropped, GetResource(flag, RES_HEALTH)); } - if((GetResourceAmount(flag, RESOURCE_HEALTH) <= 0) || (time >= flag.ctf_droptime + autocvar_g_ctf_flag_return_time)) + if((GetResource(flag, RES_HEALTH) <= 0) || (time >= flag.ctf_droptime + autocvar_g_ctf_flag_return_time)) { switch(returntype) { @@ -876,7 +904,7 @@ void ctf_FlagDamage(entity this, entity inflictor, entity attacker, float damage this.ctf_flagdamaged_byworld = true; else { - SetResourceAmount(this, RESOURCE_HEALTH, 0); + SetResourceExplicit(this, RES_HEALTH, 0); ctf_CheckFlagReturn(this, RETURN_NEEDKILL); } return; @@ -884,7 +912,7 @@ void ctf_FlagDamage(entity this, entity inflictor, entity attacker, float damage if(autocvar_g_ctf_flag_return_damage) { // reduce health and check if it should be returned - TakeResource(this, RESOURCE_HEALTH, damage); + TakeResource(this, RES_HEALTH, damage); ctf_CheckFlagReturn(this, RETURN_DAMAGE); return; } @@ -947,20 +975,20 @@ void ctf_FlagThink(entity this) { if((vdist(this.origin - this.ctf_spawnorigin, <=, autocvar_g_ctf_flag_return_dropped)) || (autocvar_g_ctf_flag_return_dropped == -1)) { - SetResourceAmount(this, RESOURCE_HEALTH, 0); + SetResourceExplicit(this, RES_HEALTH, 0); ctf_CheckFlagReturn(this, RETURN_DROPPED); return; } } if(this.ctf_flagdamaged_byworld) { - TakeResource(this, RESOURCE_HEALTH, ((this.max_flag_health / autocvar_g_ctf_flag_return_damage_delay) * FLAG_THINKRATE)); + TakeResource(this, RES_HEALTH, (this.max_health / autocvar_g_ctf_flag_return_damage_delay) * FLAG_THINKRATE); ctf_CheckFlagReturn(this, RETURN_NEEDKILL); return; } else if(autocvar_g_ctf_flag_return_time) { - TakeResource(this, RESOURCE_HEALTH, ((this.max_flag_health / autocvar_g_ctf_flag_return_time) * FLAG_THINKRATE)); + TakeResource(this, RES_HEALTH, (this.max_health / autocvar_g_ctf_flag_return_time) * FLAG_THINKRATE); ctf_CheckFlagReturn(this, RETURN_TIMEOUT); return; } @@ -971,7 +999,7 @@ void ctf_FlagThink(entity this) { if(this.speedrunning && ctf_captimerecord && (time >= this.ctf_pickuptime + ctf_captimerecord)) { - SetResourceAmount(this, RESOURCE_HEALTH, 0); + SetResourceExplicit(this, RES_HEALTH, 0); ctf_CheckFlagReturn(this, RETURN_SPEEDRUN); CS(this.owner).impulse = CHIMPULSE_SPEEDRUN.impulse; // move the player back to the waypoint they set @@ -1040,7 +1068,7 @@ METHOD(Flag, giveTo, bool(Flag this, entity flag, entity toucher)) { if(!autocvar_g_ctf_flag_return_damage_delay) { - SetResourceAmount(flag, RESOURCE_HEALTH, 0); + SetResourceExplicit(flag, RES_HEALTH, 0); ctf_CheckFlagReturn(flag, RETURN_NEEDKILL); } if(!flag.ctf_flagdamaged_byworld) { return; } @@ -1132,6 +1160,7 @@ METHOD(Flag, giveTo, bool(Flag this, entity flag, entity toucher)) .float last_respawn; void ctf_RespawnFlag(entity flag) { + flag.watertype = CONTENT_EMPTY; // TODO: it is unclear why this workaround is needed, likely many other potential breakage points!! // check for flag respawn being called twice in a row if(flag.last_respawn > time - 0.5) { backtrace("flag respawn called twice quickly! please notify Samual about this..."); } @@ -1162,9 +1191,10 @@ void ctf_RespawnFlag(entity flag) setattachment(flag, NULL, ""); setorigin(flag, flag.ctf_spawnorigin); - set_movetype(flag, ((flag.noalign) ? MOVETYPE_NONE : MOVETYPE_TOSS)); + //set_movetype(flag, ((flag.noalign) ? MOVETYPE_NONE : MOVETYPE_TOSS)); // would be desired, except maps that want floating flags have it set to fall! + set_movetype(flag, MOVETYPE_NONE); // match the initial setup handling (flag doesn't move when spawned) flag.takedamage = DAMAGE_NO; - SetResourceAmount(flag, RESOURCE_HEALTH, flag.max_flag_health); + SetResourceExplicit(flag, RES_HEALTH, flag.max_health); flag.solid = SOLID_TRIGGER; flag.velocity = '0 0 0'; flag.angles = flag.mangle; @@ -1222,10 +1252,14 @@ void ctf_DelayedFlagSetup(entity this) // called after a flag is placed on a map default: basename = WP_FlagBaseNeutral; break; } - entity wp = WaypointSprite_SpawnFixed(basename, this.origin + FLAG_WAYPOINT_OFFSET, this, wps_flagbase, RADARICON_FLAG); - wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 1 1'); - WaypointSprite_UpdateTeamRadar(this.wps_flagbase, RADARICON_FLAG, ((this.team) ? colormapPaletteColor(this.team - 1, false) : '1 1 1')); - setcefc(wp, ctf_FlagBase_Customize); + if(autocvar_g_ctf_flag_waypoint) + { + entity wp = WaypointSprite_SpawnFixed(basename, this.origin + FLAG_WAYPOINT_OFFSET, this, wps_flagbase, RADARICON_FLAG); + wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 1 1'); + wp.fade_rate = autocvar_g_ctf_flag_waypoint_maxdistance; + WaypointSprite_UpdateTeamRadar(this.wps_flagbase, RADARICON_FLAG, ((this.team) ? colormapPaletteColor(this.team - 1, false) : '1 1 1')); + setcefc(wp, ctf_FlagBase_Customize); + } // captureshield setup ctf_CaptureShield_Spawn(this); @@ -1233,7 +1267,7 @@ void ctf_DelayedFlagSetup(entity this) // called after a flag is placed on a map .bool pushable; -void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag entity on the map as a spawnfunc +void ctf_FlagSetup(int teamnum, entity flag) // called when spawning a flag entity on the map as a spawnfunc { // main setup flag.ctf_worldflagnext = ctf_worldflaglist; // link flag into ctf_worldflaglist @@ -1241,8 +1275,8 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e setattachment(flag, NULL, ""); - flag.netname = strzone(sprintf("%s%s^7 flag", Team_ColorCode(teamnumber), Team_ColorName_Upper(teamnumber))); - flag.team = teamnumber; + flag.netname = strzone(sprintf("%s%s^7 flag", Team_ColorCode(teamnum), Team_ColorName_Upper(teamnum))); + flag.team = teamnum; flag.classname = "item_flag_team"; flag.target = "###item###"; // for finding the nearest item using findnearest flag.flags = FL_ITEM | FL_NOTARGET; @@ -1250,8 +1284,8 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e 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); - SetResourceAmount(flag, RESOURCE_HEALTH, flag.max_flag_health); + flag.max_health = ((autocvar_g_ctf_flag_return_damage && autocvar_g_ctf_flag_health) ? autocvar_g_ctf_flag_health : 100); + SetResourceExplicit(flag, RES_HEALTH, flag.max_health); flag.event_damage = ctf_FlagDamage; flag.pushable = true; flag.teleportable = TELEPORT_NORMAL; @@ -1272,24 +1306,24 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e if(autocvar_g_ctf_score_ignore_fields) flag.cnt = flag.score_assist = flag.score_team_capture = flag.score_capture = flag.score_drop = flag.score_pickup = flag.score_return = 0; - string teamname = Static_Team_ColorName_Lower(teamnumber); + string teamname = Static_Team_ColorName_Lower(teamnum); // appearence if(!flag.scale) { flag.scale = FLAG_SCALE; } if(flag.skin == 0) { flag.skin = cvar(sprintf("g_ctf_flag_%s_skin", teamname)); } if(flag.model == "") { flag.model = cvar_string(sprintf("g_ctf_flag_%s_model", teamname)); } - if (flag.toucheffect == "") { flag.toucheffect = EFFECT_FLAG_TOUCH(teamnumber).eent_eff_name; } - if (flag.passeffect == "") { flag.passeffect = EFFECT_PASS(teamnumber).eent_eff_name; } - if (flag.capeffect == "") { flag.capeffect = EFFECT_CAP(teamnumber).eent_eff_name; } + if (flag.toucheffect == "") { flag.toucheffect = EFFECT_FLAG_TOUCH(teamnum).eent_eff_name; } + if (flag.passeffect == "") { flag.passeffect = EFFECT_PASS(teamnum).eent_eff_name; } + if (flag.capeffect == "") { flag.capeffect = EFFECT_CAP(teamnum).eent_eff_name; } // sounds #define X(s,b) \ if(flag.s == "") flag.s = b; \ precache_sound(flag.s); - X(snd_flag_taken, strzone(SND(CTF_TAKEN(teamnumber)))) - X(snd_flag_returned, strzone(SND(CTF_RETURNED(teamnumber)))) - X(snd_flag_capture, strzone(SND(CTF_CAPTURE(teamnumber)))) - X(snd_flag_dropped, strzone(SND(CTF_DROPPED(teamnumber)))) + X(snd_flag_taken, strzone(SND(CTF_TAKEN(teamnum)))) + X(snd_flag_returned, strzone(SND(CTF_RETURNED(teamnum)))) + X(snd_flag_capture, strzone(SND(CTF_CAPTURE(teamnum)))) + X(snd_flag_dropped, strzone(SND(CTF_DROPPED(teamnum)))) X(snd_flag_respawn, strzone(SND(CTF_RESPAWN))) X(snd_flag_touch, strzone(SND(CTF_TOUCH))) X(snd_flag_pass, strzone(SND(CTF_PASS))) @@ -1307,7 +1341,7 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e if(autocvar_g_ctf_flag_glowtrails) { - switch(teamnumber) + switch(teamnum) { case NUM_TEAM_1: flag.glow_color = 251; break; case NUM_TEAM_2: flag.glow_color = 210; break; @@ -1323,7 +1357,7 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e if(autocvar_g_ctf_fullbrightflags) { flag.effects |= EF_FULLBRIGHT; } if(autocvar_g_ctf_dynamiclights) { - switch(teamnumber) + switch(teamnum) { case NUM_TEAM_1: flag.effects |= EF_RED; break; case NUM_TEAM_2: flag.effects |= EF_BLUE; break; @@ -1385,7 +1419,7 @@ void havocbot_ctf_calculate_middlepoint() // for symmetrical editing of waypoints entity f1 = ctf_worldflaglist; entity f2 = f1.ctf_worldflagnext; - float m = -(f1.origin.y - f2.origin.y) / (f1.origin.x - f2.origin.x); + float m = -(f1.origin.y - f2.origin.y) / (max(f1.origin.x - f2.origin.x, FLOAT_EPSILON)); float q = havocbot_middlepoint.y - m * havocbot_middlepoint.x; havocbot_symmetry_axis_m = m; havocbot_symmetry_axis_q = q; @@ -1521,7 +1555,7 @@ void havocbot_goalrating_ctf_enemyflag(entity this, float ratingscale) { // adjust rating of our flag carrier depending on his health head = head.tag_entity; - float f = bound(0, (GetResourceAmount(head, RESOURCE_HEALTH) + GetResourceAmount(head, RESOURCE_ARMOR)) / 100, 2) - 1; + float f = bound(0, (GetResource(head, RES_HEALTH) + GetResource(head, RES_ARMOR)) / 100, 2) - 1; ratingscale += ratingscale * f * 0.1; } navigation_routerating(this, head, ratingscale, 10000); @@ -2168,7 +2202,7 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerPreThink) // update the health of the flag carrier waypointsprite if(player.wps_flagcarrier) - WaypointSprite_UpdateHealth(player.wps_flagcarrier, healtharmor_maxdamage(GetResourceAmount(player, RESOURCE_HEALTH), GetResourceAmount(player, RESOURCE_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x); + WaypointSprite_UpdateHealth(player.wps_flagcarrier, healtharmor_maxdamage(GetResource(player, RES_HEALTH), GetResource(player, RES_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x); } MUTATOR_HOOKFUNCTION(ctf, Damage_Calculate) // for changing damage and force values that are applied to players in g_damage.qc @@ -2196,7 +2230,7 @@ MUTATOR_HOOKFUNCTION(ctf, Damage_Calculate) // for changing damage and force val } else if(frag_target.flagcarried && !IS_DEAD(frag_target) && CTF_DIFFTEAM(frag_target, frag_attacker)) // if the target is a flagcarrier { - if(autocvar_g_ctf_flagcarrier_auto_helpme_damage > healtharmor_maxdamage(GetResourceAmount(frag_target, RESOURCE_HEALTH), GetResourceAmount(frag_target, RESOURCE_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x + if(autocvar_g_ctf_flagcarrier_auto_helpme_damage > healtharmor_maxdamage(GetResource(frag_target, RES_HEALTH), GetResource(frag_target, RES_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x && time > frag_target.wps_helpme_time + autocvar_g_ctf_flagcarrier_auto_helpme_time) { frag_target.wps_helpme_time = time; @@ -2592,6 +2626,13 @@ MUTATOR_HOOKFUNCTION(ctf, DropSpecialItems) ctf_Handle_Throw(frag_target, NULL, DROP_THROW); } +MUTATOR_HOOKFUNCTION(ctf, LogDeath_AppendItemCodes) +{ + entity player = M_ARGV(0, entity); + if(player.flagcarried) + M_ARGV(1, string) = strcat(M_ARGV(1, string), "F"); // item codes +} + // ========== // Spawnfuncs