X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fmutators%2Fmutator%2Fgamemode_ctf.qc;h=55ec4a462ed991dbc89c7bc787bbc3bc719f60b5;hp=a6d34c0d4af675506a764d79d2284486e88bdacf;hb=87cbf00c7734cf2910502c217b5c5157511ba5ea;hpb=e0e847a336cdb7ab1fcb93d3cf3e1402b761a726 diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index a6d34c0d4a..55ec4a462e 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -1,6 +1,6 @@ -#ifndef GAMEMODE_CTF_H -#define GAMEMODE_CTF_H +#include "gamemode_ctf.qh" +#ifdef IMPLEMENTATION #ifndef CSQC void ctf_Initialize(); @@ -13,7 +13,7 @@ REGISTER_MUTATOR(ctf, false) ctf_Initialize(); ActivateTeamplay(); - SetLimits(autocvar_capturelimit_override, autocvar_captureleadlimit_override, -1, -1); + SetLimits(autocvar_capturelimit_override, autocvar_captureleadlimit_override, autocvar_timelimit_override, -1); have_team_spawns = -1; // request team spawns } @@ -34,179 +34,6 @@ REGISTER_MUTATOR(ctf, false) } #endif -#ifdef SVQC -// used in cheats.qc -void ctf_RespawnFlag(entity flag); - -// score rule declarations -const int ST_CTF_CAPS = 1; -const int SP_CTF_CAPS = 4; -const int SP_CTF_CAPTIME = 5; -const int SP_CTF_PICKUPS = 6; -const int SP_CTF_DROPS = 7; -const int SP_CTF_FCKILLS = 8; -const int SP_CTF_RETURNS = 9; - -CLASS(Flag, Pickup) - ATTRIB(Flag, m_mins, vector, PL_MIN_CONST + '0 0 -13') - ATTRIB(Flag, m_maxs, vector, PL_MAX_CONST + '0 0 -13') -ENDCLASS(Flag) -Flag CTF_FLAG; STATIC_INIT(Flag) { CTF_FLAG = NEW(Flag); } -void ctf_FlagTouch() { SELFPARAM(); ITEM_HANDLE(Pickup, CTF_FLAG, this, other); } - -// flag constants // for most of these, there is just one question to be asked: WHYYYYY? - -const float FLAG_SCALE = 0.6; - -const float FLAG_THINKRATE = 0.2; -const float FLAG_TOUCHRATE = 0.5; -const float WPFE_THINKRATE = 0.5; - -const vector FLAG_DROP_OFFSET = ('0 0 32'); -const vector FLAG_CARRY_OFFSET = ('-16 0 8'); -#define FLAG_SPAWN_OFFSET ('0 0 1' * (PL_MAX_CONST.z - 13)) -const vector FLAG_WAYPOINT_OFFSET = ('0 0 64'); -const vector FLAG_FLOAT_OFFSET = ('0 0 32'); -const vector FLAG_PASS_ARC_OFFSET = ('0 0 -10'); - -const vector VEHICLE_FLAG_OFFSET = ('0 0 96'); -const float VEHICLE_FLAG_SCALE = 1.0; - -// waypoint colors -#define WPCOLOR_ENEMYFC(t) ((t) ? colormapPaletteColor(t - 1, false) * 0.75 : '1 1 1') -#define WPCOLOR_FLAGCARRIER(t) (WP_FlagCarrier.m_color) -#define WPCOLOR_DROPPEDFLAG(t) ((t) ? ('0.25 0.25 0.25' + colormapPaletteColor(t - 1, false)) * 0.5 : '1 1 1') - -// 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; -.string snd_flag_pass; - -// effects -.string toucheffect; -.string passeffect; -.string capeffect; - -// list of flags on the map -entity ctf_worldflaglist; -.entity ctf_worldflagnext; -.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 wps_helpme_time; -bool wpforenemy_announced; -float wpforenemy_nextthink; - -// statuses -const int FLAG_BASE = 1; -const int FLAG_DROPPED = 2; -const int FLAG_CARRY = 3; -const int FLAG_PASSING = 4; - -const int DROP_NORMAL = 1; -const int DROP_THROW = 2; -const int DROP_PASS = 3; -const int DROP_RESET = 4; - -const int PICKUP_BASE = 1; -const int PICKUP_DROPPED = 2; - -const int CAPTURE_NORMAL = 1; -const int CAPTURE_DROPPED = 2; - -const int RETURN_TIMEOUT = 1; -const int RETURN_DROPPED = 2; -const int RETURN_DAMAGE = 3; -const int RETURN_SPEEDRUN = 4; -const int RETURN_NEEDKILL = 5; - -void ctf_Handle_Throw(entity player, entity receiver, float droptype); - -// flag properties -#define ctf_spawnorigin dropped_origin -bool ctf_stalemate; // indicates that a stalemate is active -float ctf_captimerecord; // record time for capturing the flag -.float ctf_pickuptime; -.float ctf_droptime; -.int ctf_status; // status of the flag (FLAG_BASE, FLAG_DROPPED, FLAG_CARRY declared globally) -.entity ctf_dropper; // don't allow spam of dropping the flag -.int max_flag_health; -.float next_take_time; -.bool ctf_flagdamaged; -int ctf_teams; - -// passing/throwing properties -.float pass_distance; -.entity pass_sender; -.entity pass_target; -.float throw_antispam; -.float throw_prevtime; -.int throw_count; - -// CaptureShield: If the player is too bad to be allowed to capture, shield them from taking the flag. -.bool 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 - -// 1 flag ctf -bool ctf_oneflag; // indicates whether or not a neutral flag has been found - -// bot player logic -const int HAVOCBOT_CTF_ROLE_NONE = 0; -const int HAVOCBOT_CTF_ROLE_DEFENSE = 2; -const int HAVOCBOT_CTF_ROLE_MIDDLE = 4; -const int HAVOCBOT_CTF_ROLE_OFFENSE = 8; -const int HAVOCBOT_CTF_ROLE_CARRIER = 16; -const int HAVOCBOT_CTF_ROLE_RETRIEVER = 32; -const int HAVOCBOT_CTF_ROLE_ESCORT = 64; - -.bool havocbot_cantfindflag; - -vector havocbot_ctf_middlepoint; -float havocbot_ctf_middlepoint_radius; - -void havocbot_role_ctf_setrole(entity bot, int role); - -// team checking -#define CTF_SAMETEAM(a,b) ((autocvar_g_ctf_reverse || (ctf_oneflag && autocvar_g_ctf_oneflag_reverse)) ? DIFF_TEAM(a,b) : SAME_TEAM(a,b)) -#define CTF_DIFFTEAM(a,b) ((autocvar_g_ctf_reverse || (ctf_oneflag && autocvar_g_ctf_oneflag_reverse)) ? SAME_TEAM(a,b) : DIFF_TEAM(a,b)) - -// networked flag statuses -.int ctf_flagstatus = _STAT(CTF_FLAGSTATUS); -#endif - -const int CTF_RED_FLAG_TAKEN = 1; -const int CTF_RED_FLAG_LOST = 2; -const int CTF_RED_FLAG_CARRYING = 3; -const int CTF_BLUE_FLAG_TAKEN = 4; -const int CTF_BLUE_FLAG_LOST = 8; -const int CTF_BLUE_FLAG_CARRYING = 12; -const int CTF_YELLOW_FLAG_TAKEN = 16; -const int CTF_YELLOW_FLAG_LOST = 32; -const int CTF_YELLOW_FLAG_CARRYING = 48; -const int CTF_PINK_FLAG_TAKEN = 64; -const int CTF_PINK_FLAG_LOST = 128; -const int CTF_PINK_FLAG_CARRYING = 192; -const int CTF_NEUTRAL_FLAG_TAKEN = 256; -const int CTF_NEUTRAL_FLAG_LOST = 512; -const int CTF_NEUTRAL_FLAG_CARRYING = 768; -const int CTF_FLAG_NEUTRAL = 2048; -const int CTF_SHIELDED = 4096; -#endif - -#ifdef IMPLEMENTATION - #ifdef SVQC #include #include @@ -298,8 +125,8 @@ void ctf_FakeTimeLimit(entity e, float t) void ctf_EventLog(string mode, int flagteam, entity actor) // use an alias for easy changing and quick editing later { if(autocvar_sv_eventlog) - GameLogEcho(sprintf(":ctf:%s:%d:%d:%s", mode, flagteam, actor.team, ((actor != world) ? ftos(actor.playerid) : ""))); - //GameLogEcho(strcat(":ctf:", mode, ":", ftos(flagteam), ((actor != world) ? (strcat(":", ftos(actor.playerid))) : ""))); + GameLogEcho(sprintf(":ctf:%s:%d:%d:%s", mode, flagteam, actor.team, ((actor != NULL) ? ftos(actor.playerid) : ""))); + //GameLogEcho(strcat(":ctf:", mode, ":", ftos(flagteam), ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : ""))); } void ctf_CaptureRecord(entity flag, entity player) @@ -309,10 +136,10 @@ void ctf_CaptureRecord(entity flag, entity player) string refername = db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/netname")); // notify about shit - if(ctf_oneflag) { Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_CTF_CAPTURE_NEUTRAL, player.netname); } - else if(!ctf_captimerecord) { Send_Notification(NOTIF_ALL, world, MSG_CHOICE, APP_TEAM_ENT(flag, CHOICE_CTF_CAPTURE_TIME), player.netname, (cap_time * 100)); } - else if(cap_time < cap_record) { Send_Notification(NOTIF_ALL, world, MSG_CHOICE, APP_TEAM_ENT(flag, CHOICE_CTF_CAPTURE_BROKEN), player.netname, refername, (cap_time * 100), (cap_record * 100)); } - else { Send_Notification(NOTIF_ALL, world, MSG_CHOICE, APP_TEAM_ENT(flag, CHOICE_CTF_CAPTURE_UNBROKEN), player.netname, refername, (cap_time * 100), (cap_record * 100)); } + if(ctf_oneflag) { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CTF_CAPTURE_NEUTRAL, player.netname); } + else if(!ctf_captimerecord) { Send_Notification(NOTIF_ALL, NULL, MSG_CHOICE, APP_TEAM_ENT(flag, CHOICE_CTF_CAPTURE_TIME), player.netname, (cap_time * 100)); } + else if(cap_time < cap_record) { Send_Notification(NOTIF_ALL, NULL, MSG_CHOICE, APP_TEAM_ENT(flag, CHOICE_CTF_CAPTURE_BROKEN), player.netname, refername, (cap_time * 100), (cap_record * 100)); } + else { Send_Notification(NOTIF_ALL, NULL, MSG_CHOICE, APP_TEAM_ENT(flag, CHOICE_CTF_CAPTURE_UNBROKEN), player.netname, refername, (cap_time * 100), (cap_record * 100)); } // write that shit in the database if(!ctf_oneflag) // but not in 1-flag mode @@ -325,12 +152,39 @@ void ctf_CaptureRecord(entity flag, entity player) } } +bool ctf_Return_Customize(entity this, entity client) +{ + // only to the carrier + return boolean(client == this.owner); +} + void ctf_FlagcarrierWaypoints(entity player) { - WaypointSprite_Spawn(WP_FlagCarrier, 0, 0, player, FLAG_WAYPOINT_OFFSET, world, player.team, player, wps_flagcarrier, true, RADARICON_FLAG); + WaypointSprite_Spawn(WP_FlagCarrier, 0, 0, player, FLAG_WAYPOINT_OFFSET, NULL, player.team, player, wps_flagcarrier, true, RADARICON_FLAG); WaypointSprite_UpdateMaxHealth(player.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(start_health, start_armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id) * 2); WaypointSprite_UpdateHealth(player.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(player.health, player.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id)); WaypointSprite_UpdateTeamRadar(player.wps_flagcarrier, RADARICON_FLAGCARRIER, WPCOLOR_FLAGCARRIER(player.team)); + + if(player.flagcarried && CTF_SAMETEAM(player, player.flagcarried)) + { + if(!player.wps_enemyflagcarrier) + { + entity wp = WaypointSprite_Spawn(((ctf_oneflag) ? WP_FlagCarrier : WP_FlagCarrierEnemy), 0, 0, player, FLAG_WAYPOINT_OFFSET, NULL, 0, player, wps_enemyflagcarrier, true, RADARICON_FLAG); + wp.colormod = WPCOLOR_ENEMYFC(player.team); + setcefc(wp, ctf_Stalemate_Customize); + + if(IS_REAL_CLIENT(player) && !ctf_stalemate) + Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CTF_PICKUP_VISIBLE); + } + + if(!player.wps_flagreturn) + { + entity owp = WaypointSprite_SpawnFixed(WP_FlagReturn, player.flagcarried.ctf_spawnorigin + FLAG_WAYPOINT_OFFSET, player, wps_flagreturn, RADARICON_FLAG); + owp.colormod = '0 0.8 0.8'; + //WaypointSprite_UpdateTeamRadar(player.wps_flagreturn, RADARICON_FLAG, ((player.team) ? colormapPaletteColor(player.team - 1, false) : '1 1 1')); + setcefc(owp, ctf_Return_Customize); + } + } } void ctf_CalculatePassVelocity(entity flag, vector to, vector from, float turnrate) @@ -451,41 +305,41 @@ void ctf_CaptureShield_Update(entity player, bool wanted_status) } } -bool ctf_CaptureShield_Customize() -{SELFPARAM(); - if(!other.ctf_captureshielded) { return false; } - if(CTF_SAMETEAM(self, other)) { return false; } +bool ctf_CaptureShield_Customize(entity this, entity client) +{ + if(!client.ctf_captureshielded) { return false; } + if(CTF_SAMETEAM(this, client)) { return false; } return true; } -void ctf_CaptureShield_Touch() -{SELFPARAM(); - if(!other.ctf_captureshielded) { return; } - if(CTF_SAMETEAM(self, other)) { return; } +void ctf_CaptureShield_Touch(entity this, entity toucher) +{ + if(!toucher.ctf_captureshielded) { return; } + if(CTF_SAMETEAM(this, toucher)) { return; } - vector mymid = (self.absmin + self.absmax) * 0.5; - vector othermid = (other.absmin + other.absmax) * 0.5; + vector mymid = (this.absmin + this.absmax) * 0.5; + vector theirmid = (toucher.absmin + toucher.absmax) * 0.5; - Damage(other, self, self, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ctf_captureshield_force); - if(IS_REAL_CLIENT(other)) { Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_CTF_CAPTURESHIELD_SHIELDED); } + Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(theirmid - mymid) * ctf_captureshield_force); + if(IS_REAL_CLIENT(toucher)) { Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_CTF_CAPTURESHIELD_SHIELDED); } } void ctf_CaptureShield_Spawn(entity flag) -{SELFPARAM(); +{ entity shield = new(ctf_captureshield); - shield.enemy = self; - shield.team = self.team; - shield.touch = ctf_CaptureShield_Touch; - shield.customizeentityforclient = ctf_CaptureShield_Customize; + shield.enemy = flag; + shield.team = flag.team; + settouch(shield, ctf_CaptureShield_Touch); + setcefc(shield, ctf_CaptureShield_Customize); shield.effects = EF_ADDITIVE; - shield.movetype = MOVETYPE_NOCLIP; + set_movetype(shield, MOVETYPE_NOCLIP); shield.solid = SOLID_TRIGGER; shield.avelocity = '7 0 11'; shield.scale = 0.5; - setorigin(shield, self.origin); + setorigin(shield, flag.origin); setmodel(shield, MDL_CTF_SHIELD); setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs); } @@ -501,7 +355,7 @@ void ctf_Handle_Drop(entity flag, entity player, int droptype) player = (player ? player : flag.pass_sender); // main - flag.movetype = MOVETYPE_TOSS; + set_movetype(flag, MOVETYPE_TOSS); flag.takedamage = DAMAGE_YES; flag.angles = '0 0 0'; flag.health = flag.max_flag_health; @@ -510,7 +364,7 @@ void ctf_Handle_Drop(entity flag, entity player, int droptype) flag.ctf_status = FLAG_DROPPED; // messages and sounds - Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_LOST) : INFO_CTF_LOST_NEUTRAL), player.netname); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_LOST) : INFO_CTF_LOST_NEUTRAL), player.netname); _sound(flag, CH_TRIGGER, flag.snd_flag_dropped, VOL_BASE, ATTEN_NONE); ctf_EventLog("dropped", player.team, player); @@ -520,7 +374,7 @@ void ctf_Handle_Drop(entity flag, entity player, int droptype) // waypoints if(autocvar_g_ctf_flag_dropped_waypoint) { - entity wp = WaypointSprite_Spawn(WP_FlagDropped, 0, 0, flag, FLAG_WAYPOINT_OFFSET, world, ((autocvar_g_ctf_flag_dropped_waypoint == 2) ? 0 : player.team), flag, wps_flagdropped, true, RADARICON_FLAG); + entity wp = WaypointSprite_Spawn(WP_FlagDropped, 0, 0, flag, FLAG_WAYPOINT_OFFSET, NULL, ((autocvar_g_ctf_flag_dropped_waypoint == 2) ? 0 : player.team), flag, wps_flagdropped, true, RADARICON_FLAG); wp.colormod = WPCOLOR_DROPPEDFLAG(flag.team); } @@ -535,8 +389,8 @@ void ctf_Handle_Drop(entity flag, entity player, int droptype) if(droptype == DROP_PASS) { flag.pass_distance = 0; - flag.pass_sender = world; - flag.pass_target = world; + flag.pass_sender = NULL; + flag.pass_target = NULL; } } @@ -560,7 +414,7 @@ void ctf_Handle_Retrieve(entity flag, entity player) setattachment(flag, player, ""); setorigin(flag, FLAG_CARRY_OFFSET); } - flag.movetype = MOVETYPE_NONE; + set_movetype(flag, MOVETYPE_NONE); flag.takedamage = DAMAGE_NO; flag.solid = SOLID_NOT; flag.angles = '0 0 0'; @@ -586,8 +440,8 @@ void ctf_Handle_Retrieve(entity flag, entity player) player.throw_antispam = sender.throw_antispam; flag.pass_distance = 0; - flag.pass_sender = world; - flag.pass_target = world; + flag.pass_sender = NULL; + flag.pass_target = NULL; } void ctf_Handle_Throw(entity player, entity receiver, int droptype) @@ -601,10 +455,10 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) if(flag.speedrunning) { ctf_RespawnFlag(flag); return; } // reset the flag - setattachment(flag, world, ""); + setattachment(flag, NULL, ""); setorigin(flag, player.origin + FLAG_DROP_OFFSET); - flag.owner.flagcarried = world; - flag.owner = world; + flag.owner.flagcarried = NULL; + flag.owner = NULL; flag.solid = SOLID_TRIGGER; flag.ctf_dropper = player; flag.ctf_droptime = time; @@ -626,7 +480,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) ctf_CalculatePassVelocity(flag, targ_origin, player.origin, false); // main - flag.movetype = MOVETYPE_FLY; + set_movetype(flag, MOVETYPE_FLY); flag.takedamage = DAMAGE_NO; flag.pass_sender = player; flag.pass_target = receiver; @@ -634,7 +488,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) // other _sound(player, CH_TRIGGER, flag.snd_flag_touch, VOL_BASE, ATTEN_NORM); - WarpZone_TrailParticles(world, _particleeffectnum(flag.passeffect), player.origin, targ_origin); + WarpZone_TrailParticles(NULL, _particleeffectnum(flag.passeffect), player.origin, targ_origin); ctf_EventLog("pass", flag.team, player); break; } @@ -644,7 +498,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) 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 & ITEM_Strength.m_itemid) ? autocvar_g_ctf_throw_strengthmultiplier : 1))); - flag.velocity = W_CalculateProjectileVelocity(player.velocity, flag_velocity, false); + flag.velocity = W_CalculateProjectileVelocity(player, player.velocity, flag_velocity, false); ctf_Handle_Drop(flag, player, droptype); break; } @@ -658,7 +512,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) default: 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); + flag.velocity = W_CalculateProjectileVelocity(player, 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; } @@ -671,6 +525,9 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) if(player.wps_enemyflagcarrier) WaypointSprite_Kill(player.wps_enemyflagcarrier); + if(player.wps_flagreturn) + WaypointSprite_Kill(player.wps_flagreturn); + // captureshield ctf_CaptureShield_Update(player, 0); // shield player from picking up flag } @@ -684,11 +541,13 @@ void shockwave_spawn(string m, vector org, float sz, float t1, float t2) // Event Handlers // ============== +void nades_GiveBonus(entity player, float score); + void ctf_Handle_Capture(entity flag, entity toucher, int capturetype) { entity enemy_flag = ((capturetype == CAPTURE_NORMAL) ? toucher.flagcarried : toucher); entity player = ((capturetype == CAPTURE_NORMAL) ? toucher : enemy_flag.ctf_dropper); - entity player_team_flag = world, tmp_entity; + entity player_team_flag = NULL, tmp_entity; float old_time, new_time; if(!player) { return; } // without someone to give the reward to, we can't possibly cap @@ -752,12 +611,12 @@ void ctf_Handle_Return(entity flag, entity player) // messages and sounds if(IS_MONSTER(player)) { - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(flag, INFO_CTF_RETURN_MONSTER), player.monster_name); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(flag, INFO_CTF_RETURN_MONSTER), player.monster_name); } else if(flag.team) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, APP_TEAM_ENT(flag, CENTER_CTF_RETURN)); - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(flag, INFO_CTF_RETURN), player.netname); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(flag, INFO_CTF_RETURN), player.netname); } _sound(player, CH_TRIGGER, flag.snd_flag_returned, VOL_BASE, ATTEN_NONE); ctf_EventLog("return", flag.team, player); @@ -809,7 +668,7 @@ void ctf_Handle_Pickup(entity flag, entity player, int pickuptype) } // flag setup - flag.movetype = MOVETYPE_NONE; + set_movetype(flag, MOVETYPE_NONE); flag.takedamage = DAMAGE_NO; flag.solid = SOLID_NOT; flag.angles = '0 0 0'; @@ -823,7 +682,7 @@ void ctf_Handle_Pickup(entity flag, entity player, int pickuptype) } // messages and sounds - Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_PICKUP) : INFO_CTF_PICKUP_NEUTRAL), player.netname); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_PICKUP) : INFO_CTF_PICKUP_NEUTRAL), player.netname); if(ctf_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CTF_STALEMATE_CARRIER); } if(!flag.team) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CTF_PICKUP_NEUTRAL); } else if(CTF_DIFFTEAM(player, flag)) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, APP_TEAM_ENT(flag, CENTER_CTF_PICKUP)); } @@ -902,31 +761,30 @@ void ctf_CheckFlagReturn(entity flag, int returntype) { switch(returntype) { - case RETURN_DROPPED: Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_DROPPED) : INFO_CTF_FLAGRETURN_DROPPED_NEUTRAL)); break; - case RETURN_DAMAGE: Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_DAMAGED) : INFO_CTF_FLAGRETURN_DAMAGED_NEUTRAL)); break; - case RETURN_SPEEDRUN: Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_SPEEDRUN) : INFO_CTF_FLAGRETURN_SPEEDRUN_NEUTRAL), ctf_captimerecord); break; - case RETURN_NEEDKILL: Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_NEEDKILL) : INFO_CTF_FLAGRETURN_NEEDKILL_NEUTRAL)); break; + case RETURN_DROPPED: Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_DROPPED) : INFO_CTF_FLAGRETURN_DROPPED_NEUTRAL)); break; + case RETURN_DAMAGE: Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_DAMAGED) : INFO_CTF_FLAGRETURN_DAMAGED_NEUTRAL)); break; + case RETURN_SPEEDRUN: Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_SPEEDRUN) : INFO_CTF_FLAGRETURN_SPEEDRUN_NEUTRAL), ctf_captimerecord); break; + case RETURN_NEEDKILL: Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_NEEDKILL) : INFO_CTF_FLAGRETURN_NEEDKILL_NEUTRAL)); break; default: case RETURN_TIMEOUT: - { Send_Notification(NOTIF_ALL, world, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_TIMEOUT) : INFO_CTF_FLAGRETURN_TIMEOUT_NEUTRAL)); break; } + { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((flag.team) ? APP_TEAM_ENT(flag, INFO_CTF_FLAGRETURN_TIMEOUT) : INFO_CTF_FLAGRETURN_TIMEOUT_NEUTRAL)); break; } } _sound(flag, CH_TRIGGER, flag.snd_flag_respawn, VOL_BASE, ATTEN_NONE); - ctf_EventLog("returned", flag.team, world); + ctf_EventLog("returned", flag.team, NULL); ctf_RespawnFlag(flag); } } } -bool ctf_Stalemate_Customize() -{SELFPARAM(); +bool ctf_Stalemate_Customize(entity this, entity client) +{ // make spectators see what the player would see - entity e, wp_owner; - e = WaypointSprite_getviewentity(other); - wp_owner = self.owner; + entity e = WaypointSprite_getviewentity(client); + entity wp_owner = this.owner; // team waypoints - if(CTF_SAMETEAM(wp_owner.flagcarried, wp_owner)) { return false; } + //if(CTF_SAMETEAM(wp_owner.flagcarried, wp_owner)) { return false; } if(SAME_TEAM(wp_owner, e)) { return false; } if(!IS_PLAYER(e)) { return false; } @@ -939,7 +797,7 @@ void ctf_CheckStalemate() int stale_flags = 0, stale_red_flags = 0, stale_blue_flags = 0, stale_yellow_flags = 0, stale_pink_flags = 0, stale_neutral_flags = 0; entity tmp_entity; - entity ctf_staleflaglist = world; // reset the list, we need to build the list each time this function runs + entity ctf_staleflaglist = NULL; // 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) @@ -983,9 +841,9 @@ void ctf_CheckStalemate() { if((tmp_entity.owner) && (!tmp_entity.owner.wps_enemyflagcarrier)) { - entity wp = WaypointSprite_Spawn(((ctf_oneflag) ? WP_FlagCarrier : WP_FlagCarrierEnemy), 0, 0, tmp_entity.owner, FLAG_WAYPOINT_OFFSET, world, 0, tmp_entity.owner, wps_enemyflagcarrier, true, RADARICON_FLAG); + entity wp = WaypointSprite_Spawn(((ctf_oneflag) ? WP_FlagCarrier : WP_FlagCarrierEnemy), 0, 0, tmp_entity.owner, FLAG_WAYPOINT_OFFSET, NULL, 0, tmp_entity.owner, wps_enemyflagcarrier, true, RADARICON_FLAG); wp.colormod = WPCOLOR_ENEMYFC(tmp_entity.owner.team); - tmp_entity.owner.wps_enemyflagcarrier.customizeentityforclient = ctf_Stalemate_Customize; + setcefc(tmp_entity.owner.wps_enemyflagcarrier, ctf_Stalemate_Customize); } } @@ -1022,29 +880,29 @@ void ctf_FlagDamage(entity this, entity inflictor, entity attacker, float damage } } -void ctf_FlagThink() -{SELFPARAM(); +void ctf_FlagThink(entity this) +{ // declarations entity tmp_entity; - self.nextthink = time + FLAG_THINKRATE; // only 5 fps, more is unnecessary. + this.nextthink = time + FLAG_THINKRATE; // only 5 fps, more is unnecessary. // captureshield - if(self == ctf_worldflaglist) // only for the first flag + if(this == ctf_worldflaglist) // only for the first flag FOREACH_CLIENT(true, LAMBDA(ctf_CaptureShield_Update(it, 1))); // release shield only // sanity checks - if(self.mins != CTF_FLAG.m_mins || self.maxs != CTF_FLAG.m_maxs) { // reset the flag boundaries in case it got squished + if(this.mins != CTF_FLAG.m_mins || this.maxs != CTF_FLAG.m_maxs) { // reset the flag boundaries in case it got squished LOG_TRACE("wtf the flag got squashed?\n"); - tracebox(self.origin, CTF_FLAG.m_mins, CTF_FLAG.m_maxs, self.origin, MOVE_NOMONSTERS, self); - if(!trace_startsolid || self.noalign) // can we resize it without getting stuck? - setsize(self, CTF_FLAG.m_mins, CTF_FLAG.m_maxs); } + tracebox(this.origin, CTF_FLAG.m_mins, CTF_FLAG.m_maxs, this.origin, MOVE_NOMONSTERS, this); + if(!trace_startsolid || this.noalign) // can we resize it without getting stuck? + setsize(this, CTF_FLAG.m_mins, CTF_FLAG.m_maxs); } - switch(self.ctf_status) // reset flag angles in case warpzones adjust it + switch(this.ctf_status) // reset flag angles in case warpzones adjust it { case FLAG_DROPPED: { - self.angles = '0 0 0'; + this.angles = '0 0 0'; break; } @@ -1052,7 +910,7 @@ void ctf_FlagThink() } // main think method - switch(self.ctf_status) + switch(this.ctf_status) { case FLAG_BASE: { @@ -1060,9 +918,9 @@ void ctf_FlagThink() { 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) + if(vdist(this.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); + ctf_Handle_Capture(this, tmp_entity, CAPTURE_DROPPED); } return; } @@ -1071,37 +929,37 @@ void ctf_FlagThink() { if(autocvar_g_ctf_flag_dropped_floatinwater) { - vector midpoint = ((self.absmin + self.absmax) * 0.5); + vector midpoint = ((this.absmin + this.absmax) * 0.5); if(pointcontents(midpoint) == CONTENT_WATER) { - self.velocity = self.velocity * 0.5; + this.velocity = this.velocity * 0.5; if(pointcontents(midpoint + FLAG_FLOAT_OFFSET) == CONTENT_WATER) - { self.velocity_z = autocvar_g_ctf_flag_dropped_floatinwater; } + { this.velocity_z = autocvar_g_ctf_flag_dropped_floatinwater; } else - { self.movetype = MOVETYPE_FLY; } + { set_movetype(this, MOVETYPE_FLY); } } - else if(self.movetype == MOVETYPE_FLY) { self.movetype = MOVETYPE_TOSS; } + else if(this.move_movetype == MOVETYPE_FLY) { set_movetype(this, MOVETYPE_TOSS); } } if(autocvar_g_ctf_flag_return_dropped) { - if((vlen(self.origin - self.ctf_spawnorigin) <= autocvar_g_ctf_flag_return_dropped) || (autocvar_g_ctf_flag_return_dropped == -1)) + if((vdist(this.origin - this.ctf_spawnorigin, <=, autocvar_g_ctf_flag_return_dropped)) || (autocvar_g_ctf_flag_return_dropped == -1)) { - self.health = 0; - ctf_CheckFlagReturn(self, RETURN_DROPPED); + this.health = 0; + ctf_CheckFlagReturn(this, RETURN_DROPPED); return; } } - if(self.ctf_flagdamaged) + if(this.ctf_flagdamaged) { - self.health -= ((self.max_flag_health / autocvar_g_ctf_flag_return_damage_delay) * FLAG_THINKRATE); - ctf_CheckFlagReturn(self, RETURN_NEEDKILL); + this.health -= ((this.max_flag_health / autocvar_g_ctf_flag_return_damage_delay) * FLAG_THINKRATE); + ctf_CheckFlagReturn(this, RETURN_NEEDKILL); return; } else 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); + this.health -= ((this.max_flag_health / autocvar_g_ctf_flag_return_time) * FLAG_THINKRATE); + ctf_CheckFlagReturn(this, RETURN_TIMEOUT); return; } return; @@ -1109,15 +967,13 @@ void ctf_FlagThink() case FLAG_CARRY: { - if(self.speedrunning && ctf_captimerecord && (time >= self.ctf_pickuptime + ctf_captimerecord)) + if(this.speedrunning && ctf_captimerecord && (time >= this.ctf_pickuptime + ctf_captimerecord)) { - self.health = 0; - ctf_CheckFlagReturn(self, RETURN_SPEEDRUN); + this.health = 0; + ctf_CheckFlagReturn(this, RETURN_SPEEDRUN); - setself(self.owner); - self.impulse = CHIMPULSE_SPEEDRUN.impulse; // move the player back to the waypoint they set - ImpulseCommands(self); - setself(this); + this.owner.impulse = CHIMPULSE_SPEEDRUN.impulse; // move the player back to the waypoint they set + ImpulseCommands(this.owner); } if(autocvar_g_ctf_stalemate) { @@ -1127,36 +983,36 @@ void ctf_FlagThink() wpforenemy_nextthink = time + WPFE_THINKRATE; // waypoint for enemy think rate (to reduce unnecessary spam of this check) } } - if(CTF_SAMETEAM(self, self.owner) && self.team) + if(CTF_SAMETEAM(this, this.owner) && this.team) { if(autocvar_g_ctf_flag_return) // drop the flag if reverse status has changed - ctf_Handle_Throw(self.owner, world, DROP_THROW); - else if(vlen(self.owner.origin - self.ctf_spawnorigin) <= autocvar_g_ctf_flag_return_carried_radius) - ctf_Handle_Return(self, self.owner); + ctf_Handle_Throw(this.owner, NULL, DROP_THROW); + else if(vdist(this.owner.origin - this.ctf_spawnorigin, <=, autocvar_g_ctf_flag_return_carried_radius)) + ctf_Handle_Return(this, this.owner); } return; } case FLAG_PASSING: { - vector targ_origin = ((self.pass_target.absmin + self.pass_target.absmax) * 0.5); - 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); - - if((self.pass_target == world) - || (IS_DEAD(self.pass_target)) - || (self.pass_target.flagcarried) - || (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)) + vector targ_origin = ((this.pass_target.absmin + this.pass_target.absmax) * 0.5); + targ_origin = WarpZone_RefSys_TransformOrigin(this.pass_target, this, targ_origin); // origin of target as seen by the flag (us) + WarpZone_TraceLine(this.origin, targ_origin, MOVE_NOMONSTERS, this); + + if((this.pass_target == NULL) + || (IS_DEAD(this.pass_target)) + || (this.pass_target.flagcarried) + || (vdist(this.origin - targ_origin, >, autocvar_g_ctf_pass_radius)) + || ((trace_fraction < 1) && (trace_ent != this.pass_target)) + || (time > this.ctf_droptime + autocvar_g_ctf_pass_timelimit)) { // give up, pass failed - ctf_Handle_Drop(self, world, DROP_PASS); + ctf_Handle_Drop(this, NULL, DROP_PASS); } else { // still a viable target, go for it - ctf_CalculatePassVelocity(self, targ_origin, self.origin, true); + ctf_CalculatePassVelocity(this, targ_origin, this.origin, true); } return; } @@ -1282,9 +1138,10 @@ void ctf_RespawnFlag(entity flag) if((flag.owner) && (flag.owner.flagcarried == flag)) { WaypointSprite_Kill(flag.owner.wps_enemyflagcarrier); + WaypointSprite_Kill(flag.owner.wps_flagreturn); WaypointSprite_Kill(flag.wps_flagcarrier); - flag.owner.flagcarried = world; + flag.owner.flagcarried = NULL; if(flag.speedrunning) ctf_FakeTimeLimit(flag.owner, -1); @@ -1297,10 +1154,10 @@ void ctf_RespawnFlag(entity flag) { WaypointSprite_Kill(flag.wps_flagdropped); } // reset the flag - setattachment(flag, world, ""); + setattachment(flag, NULL, ""); setorigin(flag, flag.ctf_spawnorigin); - flag.movetype = ((flag.noalign) ? MOVETYPE_NONE : MOVETYPE_TOSS); + set_movetype(flag, ((flag.noalign) ? MOVETYPE_NONE : MOVETYPE_TOSS)); flag.takedamage = DAMAGE_NO; flag.health = flag.max_flag_health; flag.solid = SOLID_TRIGGER; @@ -1309,11 +1166,11 @@ void ctf_RespawnFlag(entity flag) flag.flags = FL_ITEM | FL_NOTARGET; flag.ctf_status = FLAG_BASE; - flag.owner = world; + flag.owner = NULL; flag.pass_distance = 0; - flag.pass_sender = world; - flag.pass_target = world; - flag.ctf_dropper = world; + flag.pass_sender = NULL; + flag.pass_target = NULL; + flag.ctf_dropper = NULL; flag.ctf_pickuptime = 0; flag.ctf_droptime = 0; flag.ctf_flagdamaged = 0; @@ -1324,21 +1181,28 @@ void ctf_RespawnFlag(entity flag) void ctf_Reset(entity this) { if(this.owner && IS_PLAYER(this.owner)) - ctf_Handle_Throw(this.owner, world, DROP_RESET); + ctf_Handle_Throw(this.owner, NULL, DROP_RESET); ctf_RespawnFlag(this); } -void ctf_DelayedFlagSetup() // called after a flag is placed on a map by ctf_FlagSetup() -{SELFPARAM(); +bool ctf_FlagBase_Customize(entity this, entity client) +{ + if(client.flagcarried && CTF_SAMETEAM(client, client.flagcarried)) + return false; + return true; +} + +void ctf_DelayedFlagSetup(entity this) // 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; + waypoint_spawnforitem_force(this, this.origin); + this.nearestwaypointtimeout = 0; // activate waypointing again + this.bot_basewaypoint = this.nearestwaypoint; // waypointsprites entity basename; - switch (self.team) + switch (this.team) { case NUM_TEAM_1: basename = WP_FlagBaseRed; break; case NUM_TEAM_2: basename = WP_FlagBaseBlue; break; @@ -1347,24 +1211,24 @@ void ctf_DelayedFlagSetup() // called after a flag is placed on a map by ctf_Fla default: basename = WP_FlagBaseNeutral; break; } - entity wp = WaypointSprite_SpawnFixed(basename, self.origin + FLAG_WAYPOINT_OFFSET, self, wps_flagbase, RADARICON_FLAG); - wp.colormod = ((self.team) ? Team_ColorRGB(self.team) : '1 1 1'); - WaypointSprite_UpdateTeamRadar(self.wps_flagbase, RADARICON_FLAG, ((self.team) ? colormapPaletteColor(self.team - 1, false) : '1 1 1')); + 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); // captureshield setup - ctf_CaptureShield_Spawn(self); + ctf_CaptureShield_Spawn(this); } -void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag entity on the map as a spawnfunc -{SELFPARAM(); - // declarations - setself(flag); // for later usage with droptofloor() +.bool pushable; +void ctf_FlagSetup(int teamnumber, 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 ctf_worldflaglist = flag; - setattachment(flag, world, ""); + setattachment(flag, NULL, ""); flag.netname = strzone(sprintf("%s%s^7 flag", Team_ColorCode(teamnumber), Team_ColorName_Upper(teamnumber))); flag.team = teamnumber; @@ -1385,8 +1249,8 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e flag.velocity = '0 0 0'; flag.mangle = flag.angles; flag.reset = ctf_Reset; - flag.touch = ctf_FlagTouch; - flag.think = ctf_FlagThink; + settouch(flag, ctf_FlagTouch); + setthink(flag, ctf_FlagThink); flag.nextthink = time + FLAG_THINKRATE; flag.ctf_status = FLAG_BASE; @@ -1400,16 +1264,18 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e if (flag.capeffect == "") { flag.capeffect = EFFECT_CAP(teamnumber).eent_eff_name; } // sounds - flag.snd_flag_taken = strzone(SND(CTF_TAKEN(teamnumber))); - flag.snd_flag_returned = strzone(SND(CTF_RETURNED(teamnumber))); - flag.snd_flag_capture = strzone(SND(CTF_CAPTURE(teamnumber))); - flag.snd_flag_dropped = strzone(SND(CTF_DROPPED(teamnumber))); - if (flag.snd_flag_respawn == "") flag.snd_flag_respawn = strzone(SND(CTF_RESPAWN)); // if there is ever a team-based sound for this, update the code to match. - precache_sound(flag.snd_flag_respawn); - if (flag.snd_flag_touch == "") flag.snd_flag_touch = strzone(SND(CTF_TOUCH)); // again has no team-based sound - precache_sound(flag.snd_flag_touch); - if (flag.snd_flag_pass == "") flag.snd_flag_pass = strzone(SND(CTF_PASS)); // same story here - precache_sound(flag.snd_flag_pass); +#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_respawn, strzone(SND(CTF_RESPAWN))) + X(snd_flag_touch, strzone(SND(CTF_TOUCH))) + X(snd_flag_pass, strzone(SND(CTF_PASS))) +#undef X // precache precache_model(flag.model); @@ -1452,14 +1318,13 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e { flag.dropped_origin = flag.origin; flag.noalign = true; - flag.movetype = MOVETYPE_NONE; + set_movetype(flag, MOVETYPE_NONE); } else // drop to floor, automatically find a platform and set that as spawn origin { flag.noalign = false; - setself(flag); - droptofloor(); - flag.movetype = MOVETYPE_TOSS; + droptofloor(flag); + set_movetype(flag, MOVETYPE_NONE); } InitializeEntity(flag, ctf_DelayedFlagSetup, INITPRIO_SETLOCATION); @@ -1503,7 +1368,7 @@ entity havocbot_ctf_find_flag(entity bot) return f; f = f.ctf_worldflagnext; } - return world; + return NULL; } entity havocbot_ctf_find_enemy_flag(entity bot) @@ -1529,7 +1394,7 @@ entity havocbot_ctf_find_enemy_flag(entity bot) return f; f = f.ctf_worldflagnext; } - return world; + return NULL; } int havocbot_ctf_teamcount(entity bot, vector org, float tc_radius) @@ -1543,102 +1408,102 @@ int havocbot_ctf_teamcount(entity bot, vector org, float tc_radius) if(DIFF_TEAM(it, bot) || IS_DEAD(it) || it == bot) continue; - if(vlen(it.origin - org) < tc_radius) + if(vdist(it.origin - org, <, tc_radius)) ++c; )); return c; } -void havocbot_goalrating_ctf_ourflag(float ratingscale) -{SELFPARAM(); +void havocbot_goalrating_ctf_ourflag(entity this, float ratingscale) +{ entity head; head = ctf_worldflaglist; while (head) { - if (CTF_SAMETEAM(self, head)) + if (CTF_SAMETEAM(this, head)) break; head = head.ctf_worldflagnext; } if (head) - navigation_routerating(head, ratingscale, 10000); + navigation_routerating(this, head, ratingscale, 10000); } -void havocbot_goalrating_ctf_ourbase(float ratingscale) -{SELFPARAM(); +void havocbot_goalrating_ctf_ourbase(entity this, float ratingscale) +{ entity head; head = ctf_worldflaglist; while (head) { - if (CTF_SAMETEAM(self, head)) + if (CTF_SAMETEAM(this, head)) break; head = head.ctf_worldflagnext; } if (!head) return; - navigation_routerating(head.bot_basewaypoint, ratingscale, 10000); + navigation_routerating(this, head.bot_basewaypoint, ratingscale, 10000); } -void havocbot_goalrating_ctf_enemyflag(float ratingscale) -{SELFPARAM(); +void havocbot_goalrating_ctf_enemyflag(entity this, float ratingscale) +{ entity head; head = ctf_worldflaglist; while (head) { if(ctf_oneflag) { - if(CTF_DIFFTEAM(self, head)) + if(CTF_DIFFTEAM(this, head)) { if(head.team) { - if(self.flagcarried) + if(this.flagcarried) break; } - else if(!self.flagcarried) + else if(!this.flagcarried) break; } } - else if(CTF_DIFFTEAM(self, head)) + else if(CTF_DIFFTEAM(this, head)) break; head = head.ctf_worldflagnext; } if (head) - navigation_routerating(head, ratingscale, 10000); + navigation_routerating(this, head, ratingscale, 10000); } -void havocbot_goalrating_ctf_enemybase(float ratingscale) -{SELFPARAM(); +void havocbot_goalrating_ctf_enemybase(entity this, float ratingscale) +{ if (!bot_waypoints_for_items) { - havocbot_goalrating_ctf_enemyflag(ratingscale); + havocbot_goalrating_ctf_enemyflag(this, ratingscale); return; } entity head; - head = havocbot_ctf_find_enemy_flag(self); + head = havocbot_ctf_find_enemy_flag(this); if (!head) return; - navigation_routerating(head.bot_basewaypoint, ratingscale, 10000); + navigation_routerating(this, head.bot_basewaypoint, ratingscale, 10000); } -void havocbot_goalrating_ctf_ourstolenflag(float ratingscale) -{SELFPARAM(); +void havocbot_goalrating_ctf_ourstolenflag(entity this, float ratingscale) +{ entity mf; - mf = havocbot_ctf_find_flag(self); + mf = havocbot_ctf_find_flag(this); if(mf.ctf_status == FLAG_BASE) return; if(mf.tag_entity) - navigation_routerating(mf.tag_entity, ratingscale, 10000); + navigation_routerating(this, mf.tag_entity, ratingscale, 10000); } -void havocbot_goalrating_ctf_droppedflags(float ratingscale, vector org, float df_radius) +void havocbot_goalrating_ctf_droppedflags(entity this, float ratingscale, vector org, float df_radius) { entity head; head = ctf_worldflaglist; @@ -1646,227 +1511,223 @@ void havocbot_goalrating_ctf_droppedflags(float ratingscale, vector org, float d { // flag is out in the field if(head.ctf_status != FLAG_BASE) - if(head.tag_entity==world) // dropped + if(head.tag_entity==NULL) // dropped { if(df_radius) { - if(vlen(org-head.origin) 0) - navigation_routerating(head, t * ratingscale, 500); + navigation_routerating(this, it, t * ratingscale, 500); } - head = head.chain; - } + }); } -void havocbot_ctf_reset_role(entity bot) +void havocbot_ctf_reset_role(entity this) { float cdefense, cmiddle, coffense; entity mf, ef; float c; - if(IS_DEAD(bot)) + if(IS_DEAD(this)) return; - if(vlen(havocbot_ctf_middlepoint)==0) + if(havocbot_ctf_middlepoint == '0 0 0') havocbot_calculate_middlepoint(); // Check ctf flags - if (bot.flagcarried) + if (this.flagcarried) { - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_CARRIER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_CARRIER); return; } - mf = havocbot_ctf_find_flag(bot); - ef = havocbot_ctf_find_enemy_flag(bot); + mf = havocbot_ctf_find_flag(this); + ef = havocbot_ctf_find_enemy_flag(this); // Retrieve stolen flag if(mf.ctf_status!=FLAG_BASE) { - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_RETRIEVER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_RETRIEVER); return; } // If enemy flag is taken go to the middle to intercept pursuers if(ef.ctf_status!=FLAG_BASE) { - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_MIDDLE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_MIDDLE); return; } // if there is only me on the team switch to offense c = 0; - FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, bot), LAMBDA(++c)); + FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this), LAMBDA(++c)); if(c==1) { - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_OFFENSE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_OFFENSE); return; } // Evaluate best position to take // Count mates on middle position - cmiddle = havocbot_ctf_teamcount(bot, havocbot_ctf_middlepoint, havocbot_ctf_middlepoint_radius * 0.5); + cmiddle = havocbot_ctf_teamcount(this, havocbot_ctf_middlepoint, havocbot_ctf_middlepoint_radius * 0.5); // Count mates on defense position - cdefense = havocbot_ctf_teamcount(bot, mf.dropped_origin, havocbot_ctf_middlepoint_radius * 0.5); + cdefense = havocbot_ctf_teamcount(this, mf.dropped_origin, havocbot_ctf_middlepoint_radius * 0.5); // Count mates on offense position - coffense = havocbot_ctf_teamcount(bot, ef.dropped_origin, havocbot_ctf_middlepoint_radius); + coffense = havocbot_ctf_teamcount(this, ef.dropped_origin, havocbot_ctf_middlepoint_radius); if(cdefense<=coffense) - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_DEFENSE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_DEFENSE); else if(coffense<=cmiddle) - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_OFFENSE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_OFFENSE); else - havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_MIDDLE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_MIDDLE); } -void havocbot_role_ctf_carrier() -{SELFPARAM(); - if(IS_DEAD(self)) +void havocbot_role_ctf_carrier(entity this) +{ + if(IS_DEAD(this)) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.flagcarried == world) + if (this.flagcarried == NULL) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; - navigation_goalrating_start(); + navigation_goalrating_start(this); if(ctf_oneflag) - havocbot_goalrating_ctf_enemybase(50000); + havocbot_goalrating_ctf_enemybase(this, 50000); else - havocbot_goalrating_ctf_ourbase(50000); + havocbot_goalrating_ctf_ourbase(this, 50000); - if(self.health<100) - havocbot_goalrating_ctf_carrieritems(1000, self.origin, 1000); + if(this.health<100) + havocbot_goalrating_ctf_carrieritems(this, 1000, this.origin, 1000); - navigation_goalrating_end(); + navigation_goalrating_end(this); - if (self.navigation_hasgoals) - self.havocbot_cantfindflag = time + 10; - else if (time > self.havocbot_cantfindflag) + if (this.navigation_hasgoals) + this.havocbot_cantfindflag = time + 10; + else if (time > this.havocbot_cantfindflag) { // Can't navigate to my own base, suicide! // TODO: drop it and wander around - Damage(self, self, self, 100000, DEATH_KILL.m_id, self.origin, '0 0 0'); + Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0'); return; } } } -void havocbot_role_ctf_escort() -{SELFPARAM(); +void havocbot_role_ctf_escort(entity this) +{ entity mf, ef; - if(IS_DEAD(self)) + if(IS_DEAD(this)) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.flagcarried) + if (this.flagcarried) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_CARRIER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_CARRIER); return; } // If enemy flag is back on the base switch to previous role - ef = havocbot_ctf_find_enemy_flag(self); + ef = havocbot_ctf_find_enemy_flag(this); if(ef.ctf_status==FLAG_BASE) { - self.havocbot_role = self.havocbot_previous_role; - self.havocbot_role_timeout = 0; + this.havocbot_role = this.havocbot_previous_role; + this.havocbot_role_timeout = 0; return; } // If the flag carrier reached the base switch to defense - mf = havocbot_ctf_find_flag(self); + mf = havocbot_ctf_find_flag(this); if(mf.ctf_status!=FLAG_BASE) - if(vlen(ef.origin - mf.dropped_origin) < 300) + if(vdist(ef.origin - mf.dropped_origin, <, 300)) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_DEFENSE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_DEFENSE); return; } // Set the role timeout if necessary - if (!self.havocbot_role_timeout) + if (!this.havocbot_role_timeout) { - self.havocbot_role_timeout = time + random() * 30 + 60; + this.havocbot_role_timeout = time + random() * 30 + 60; } // If nothing happened just switch to previous role - if (time > self.havocbot_role_timeout) + if (time > this.havocbot_role_timeout) { - self.havocbot_role = self.havocbot_previous_role; - self.havocbot_role_timeout = 0; + this.havocbot_role = this.havocbot_previous_role; + this.havocbot_role_timeout = 0; return; } // Chase the flag carrier - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; - navigation_goalrating_start(); - havocbot_goalrating_ctf_enemyflag(30000); - havocbot_goalrating_ctf_ourstolenflag(40000); - havocbot_goalrating_items(10000, self.origin, 10000); - navigation_goalrating_end(); + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + navigation_goalrating_start(this); + havocbot_goalrating_ctf_enemyflag(this, 30000); + havocbot_goalrating_ctf_ourstolenflag(this, 40000); + havocbot_goalrating_items(this, 10000, this.origin, 10000); + navigation_goalrating_end(this); } } -void havocbot_role_ctf_offense() -{SELFPARAM(); +void havocbot_role_ctf_offense(entity this) +{ entity mf, ef; vector pos; - if(IS_DEAD(self)) + if(IS_DEAD(this)) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.flagcarried) + if (this.flagcarried) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_CARRIER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_CARRIER); return; } // Check flags - mf = havocbot_ctf_find_flag(self); - ef = havocbot_ctf_find_enemy_flag(self); + mf = havocbot_ctf_find_flag(this); + ef = havocbot_ctf_find_enemy_flag(this); // Own flag stolen if(mf.ctf_status!=FLAG_BASE) @@ -1877,9 +1738,9 @@ void havocbot_role_ctf_offense() pos = mf.origin; // Try to get it if closer than the enemy base - if(vlen(self.origin-ef.dropped_origin)>vlen(self.origin-pos)) + if(vlen2(this.origin-ef.dropped_origin)>vlen2(this.origin-pos)) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_RETRIEVER); return; } } @@ -1892,175 +1753,175 @@ void havocbot_role_ctf_offense() else pos = ef.origin; - if(vlen(pos-mf.dropped_origin)>700) + if(vdist(pos - mf.dropped_origin, >, 700)) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_ESCORT); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_ESCORT); return; } } // About to fail, switch to middlefield - if(self.health<50) + if(this.health<50) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_MIDDLE); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_MIDDLE); return; } // Set the role timeout if necessary - if (!self.havocbot_role_timeout) - self.havocbot_role_timeout = time + 120; + if (!this.havocbot_role_timeout) + this.havocbot_role_timeout = time + 120; - if (time > self.havocbot_role_timeout) + if (time > this.havocbot_role_timeout) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; - navigation_goalrating_start(); - havocbot_goalrating_ctf_ourstolenflag(50000); - havocbot_goalrating_ctf_enemybase(20000); - havocbot_goalrating_items(5000, self.origin, 1000); - havocbot_goalrating_items(1000, self.origin, 10000); - navigation_goalrating_end(); + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + navigation_goalrating_start(this); + havocbot_goalrating_ctf_ourstolenflag(this, 50000); + havocbot_goalrating_ctf_enemybase(this, 20000); + havocbot_goalrating_items(this, 5000, this.origin, 1000); + havocbot_goalrating_items(this, 1000, this.origin, 10000); + navigation_goalrating_end(this); } } // Retriever (temporary role): -void havocbot_role_ctf_retriever() -{SELFPARAM(); +void havocbot_role_ctf_retriever(entity this) +{ entity mf; - if(IS_DEAD(self)) + if(IS_DEAD(this)) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.flagcarried) + if (this.flagcarried) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_CARRIER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_CARRIER); return; } // If flag is back on the base switch to previous role - mf = havocbot_ctf_find_flag(self); + mf = havocbot_ctf_find_flag(this); if(mf.ctf_status==FLAG_BASE) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (!self.havocbot_role_timeout) - self.havocbot_role_timeout = time + 20; + if (!this.havocbot_role_timeout) + this.havocbot_role_timeout = time + 20; - if (time > self.havocbot_role_timeout) + if (time > this.havocbot_role_timeout) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { float rt_radius; rt_radius = 10000; - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; - navigation_goalrating_start(); - havocbot_goalrating_ctf_ourstolenflag(50000); - havocbot_goalrating_ctf_droppedflags(40000, self.origin, rt_radius); - havocbot_goalrating_ctf_enemybase(30000); - havocbot_goalrating_items(500, self.origin, rt_radius); - navigation_goalrating_end(); + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + navigation_goalrating_start(this); + havocbot_goalrating_ctf_ourstolenflag(this, 50000); + havocbot_goalrating_ctf_droppedflags(this, 40000, this.origin, rt_radius); + havocbot_goalrating_ctf_enemybase(this, 30000); + havocbot_goalrating_items(this, 500, this.origin, rt_radius); + navigation_goalrating_end(this); } } -void havocbot_role_ctf_middle() -{SELFPARAM(); +void havocbot_role_ctf_middle(entity this) +{ entity mf; - if(IS_DEAD(self)) + if(IS_DEAD(this)) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.flagcarried) + if (this.flagcarried) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_CARRIER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_CARRIER); return; } - mf = havocbot_ctf_find_flag(self); + mf = havocbot_ctf_find_flag(this); if(mf.ctf_status!=FLAG_BASE) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_RETRIEVER); return; } - if (!self.havocbot_role_timeout) - self.havocbot_role_timeout = time + 10; + if (!this.havocbot_role_timeout) + this.havocbot_role_timeout = time + 10; - if (time > self.havocbot_role_timeout) + if (time > this.havocbot_role_timeout) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { vector org; org = havocbot_ctf_middlepoint; - org.z = self.origin.z; + org.z = this.origin.z; - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; - navigation_goalrating_start(); - havocbot_goalrating_ctf_ourstolenflag(50000); - havocbot_goalrating_ctf_droppedflags(30000, self.origin, 10000); - havocbot_goalrating_enemyplayers(10000, org, havocbot_ctf_middlepoint_radius * 0.5); - havocbot_goalrating_items(5000, org, havocbot_ctf_middlepoint_radius * 0.5); - havocbot_goalrating_items(2500, self.origin, 10000); - havocbot_goalrating_ctf_enemybase(2500); - navigation_goalrating_end(); + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + navigation_goalrating_start(this); + havocbot_goalrating_ctf_ourstolenflag(this, 50000); + havocbot_goalrating_ctf_droppedflags(this, 30000, this.origin, 10000); + havocbot_goalrating_enemyplayers(this, 10000, org, havocbot_ctf_middlepoint_radius * 0.5); + havocbot_goalrating_items(this, 5000, org, havocbot_ctf_middlepoint_radius * 0.5); + havocbot_goalrating_items(this, 2500, this.origin, 10000); + havocbot_goalrating_ctf_enemybase(this, 2500); + navigation_goalrating_end(this); } } -void havocbot_role_ctf_defense() -{SELFPARAM(); +void havocbot_role_ctf_defense(entity this) +{ entity mf; - if(IS_DEAD(self)) + if(IS_DEAD(this)) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.flagcarried) + if (this.flagcarried) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_CARRIER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_CARRIER); return; } // If own flag was captured - mf = havocbot_ctf_find_flag(self); + mf = havocbot_ctf_find_flag(this); if(mf.ctf_status!=FLAG_BASE) { - havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER); + havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_RETRIEVER); return; } - if (!self.havocbot_role_timeout) - self.havocbot_role_timeout = time + 30; + if (!this.havocbot_role_timeout) + this.havocbot_role_timeout = time + 30; - if (time > self.havocbot_role_timeout) + if (time > this.havocbot_role_timeout) { - havocbot_ctf_reset_role(self); + havocbot_ctf_reset_role(this); return; } - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { float mp_radius; vector org; @@ -2068,11 +1929,11 @@ void havocbot_role_ctf_defense() org = mf.dropped_origin; mp_radius = havocbot_ctf_middlepoint_radius; - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; - navigation_goalrating_start(); + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + navigation_goalrating_start(this); // if enemies are closer to our base, go there - entity closestplayer = world; + entity closestplayer = NULL; float distance, bestdistance = 10000; FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), LAMBDA( distance = vlen(org - it.origin); @@ -2084,17 +1945,17 @@ void havocbot_role_ctf_defense() )); if(closestplayer) - if(DIFF_TEAM(closestplayer, self)) - if(vlen(org - self.origin)>1000) - if(checkpvs(self.origin,closestplayer)||random()<0.5) - havocbot_goalrating_ctf_ourbase(30000); + if(DIFF_TEAM(closestplayer, this)) + if(vdist(org - this.origin, >, 1000)) + if(checkpvs(this.origin,closestplayer)||random()<0.5) + havocbot_goalrating_ctf_ourbase(this, 30000); - havocbot_goalrating_ctf_ourstolenflag(20000); - havocbot_goalrating_ctf_droppedflags(20000, org, mp_radius); - havocbot_goalrating_enemyplayers(15000, org, mp_radius); - havocbot_goalrating_items(10000, org, mp_radius); - havocbot_goalrating_items(5000, self.origin, 10000); - navigation_goalrating_end(); + havocbot_goalrating_ctf_ourstolenflag(this, 20000); + havocbot_goalrating_ctf_droppedflags(this, 20000, org, mp_radius); + havocbot_goalrating_enemyplayers(this, 15000, org, mp_radius); + havocbot_goalrating_items(this, 10000, org, mp_radius); + havocbot_goalrating_items(this, 5000, this.origin, 10000); + navigation_goalrating_end(this); } } @@ -2149,59 +2010,66 @@ void havocbot_role_ctf_setrole(entity bot, int role) // ============== MUTATOR_HOOKFUNCTION(ctf, PlayerPreThink) -{SELFPARAM(); - entity flag; +{ + entity player = M_ARGV(0, entity); + int t = 0, t2 = 0, t3 = 0; // initially clear items so they can be set as necessary later. - self.ctf_flagstatus &= ~(CTF_RED_FLAG_CARRYING | CTF_RED_FLAG_TAKEN | CTF_RED_FLAG_LOST + player.ctf_flagstatus &= ~(CTF_RED_FLAG_CARRYING | CTF_RED_FLAG_TAKEN | CTF_RED_FLAG_LOST | CTF_BLUE_FLAG_CARRYING | CTF_BLUE_FLAG_TAKEN | CTF_BLUE_FLAG_LOST | CTF_YELLOW_FLAG_CARRYING | CTF_YELLOW_FLAG_TAKEN | CTF_YELLOW_FLAG_LOST | CTF_PINK_FLAG_CARRYING | CTF_PINK_FLAG_TAKEN | CTF_PINK_FLAG_LOST | CTF_NEUTRAL_FLAG_CARRYING | CTF_NEUTRAL_FLAG_TAKEN | CTF_NEUTRAL_FLAG_LOST - | CTF_FLAG_NEUTRAL | CTF_SHIELDED); + | CTF_FLAG_NEUTRAL | CTF_SHIELDED | CTF_STALEMATE); // scan through all the flags and notify the client about them - for(flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) + for(entity flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) { if(flag.team == NUM_TEAM_1) { t = CTF_RED_FLAG_CARRYING; t2 = CTF_RED_FLAG_TAKEN; t3 = CTF_RED_FLAG_LOST; } if(flag.team == NUM_TEAM_2) { t = CTF_BLUE_FLAG_CARRYING; t2 = CTF_BLUE_FLAG_TAKEN; t3 = CTF_BLUE_FLAG_LOST; } if(flag.team == NUM_TEAM_3) { t = CTF_YELLOW_FLAG_CARRYING; t2 = CTF_YELLOW_FLAG_TAKEN; t3 = CTF_YELLOW_FLAG_LOST; } if(flag.team == NUM_TEAM_4) { t = CTF_PINK_FLAG_CARRYING; t2 = CTF_PINK_FLAG_TAKEN; t3 = CTF_PINK_FLAG_LOST; } - if(flag.team == 0) { t = CTF_NEUTRAL_FLAG_CARRYING; t2 = CTF_NEUTRAL_FLAG_TAKEN; t3 = CTF_NEUTRAL_FLAG_LOST; self.ctf_flagstatus |= CTF_FLAG_NEUTRAL; } + if(flag.team == 0) { t = CTF_NEUTRAL_FLAG_CARRYING; t2 = CTF_NEUTRAL_FLAG_TAKEN; t3 = CTF_NEUTRAL_FLAG_LOST; player.ctf_flagstatus |= CTF_FLAG_NEUTRAL; } switch(flag.ctf_status) { case FLAG_PASSING: case FLAG_CARRY: { - if((flag.owner == self) || (flag.pass_sender == self)) - self.ctf_flagstatus |= t; // carrying: self is currently carrying the flag + if((flag.owner == player) || (flag.pass_sender == player)) + player.ctf_flagstatus |= t; // carrying: player is currently carrying the flag else - self.ctf_flagstatus |= t2; // taken: someone else is carrying the flag + player.ctf_flagstatus |= t2; // taken: someone else is carrying the flag break; } case FLAG_DROPPED: { - self.ctf_flagstatus |= t3; // lost: the flag is dropped somewhere on the map + player.ctf_flagstatus |= t3; // 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.ctf_flagstatus |= CTF_SHIELDED; + if(player.ctf_captureshielded) + player.ctf_flagstatus |= CTF_SHIELDED; - // update the health of the flag carrier waypointsprite - if(self.wps_flagcarrier) - WaypointSprite_UpdateHealth(self.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id)); + if(ctf_stalemate) + player.ctf_flagstatus |= CTF_STALEMATE; - return false; + // update the health of the flag carrier waypointsprite + if(player.wps_flagcarrier) + WaypointSprite_UpdateHealth(player.wps_flagcarrier, '1 0 0' * healtharmor_maxdamage(player.health, player.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id)); } MUTATOR_HOOKFUNCTION(ctf, PlayerDamage_Calculate) // for changing damage and force values that are applied to players in g_damage.qc { + entity frag_attacker = M_ARGV(1, entity); + entity frag_target = M_ARGV(2, entity); + float frag_damage = M_ARGV(4, float); + vector frag_force = M_ARGV(6, vector); + if(frag_attacker.flagcarried) // if the attacker is a flagcarrier { if(frag_target == frag_attacker) // damage done to yourself @@ -2214,6 +2082,9 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerDamage_Calculate) // for changing damage and for frag_damage *= autocvar_g_ctf_flagcarrier_damagefactor; frag_force *= autocvar_g_ctf_flagcarrier_forcefactor; } + + M_ARGV(4, float) = frag_damage; + M_ARGV(6, vector) = frag_force; } else if(frag_target.flagcarried && !IS_DEAD(frag_target) && CTF_DIFFTEAM(frag_target, frag_attacker)) // if the target is a flagcarrier { @@ -2225,11 +2096,13 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerDamage_Calculate) // for changing damage and for } // todo: add notification for when flag carrier needs help? } - return false; } MUTATOR_HOOKFUNCTION(ctf, PlayerDies) { + entity frag_attacker = M_ARGV(1, entity); + entity frag_target = M_ARGV(2, entity); + if((frag_attacker != frag_target) && (IS_PLAYER(frag_attacker)) && (frag_target.flagcarried)) { PlayerTeamScore_AddScore(frag_attacker, ((SAME_TEAM(frag_attacker, frag_target)) ? -autocvar_g_ctf_score_kill : autocvar_g_ctf_score_kill)); @@ -2239,65 +2112,65 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerDies) if(frag_target.flagcarried) { entity tmp_entity = frag_target.flagcarried; - ctf_Handle_Throw(frag_target, world, DROP_NORMAL); - tmp_entity.ctf_dropper = world; + ctf_Handle_Throw(frag_target, NULL, DROP_NORMAL); + tmp_entity.ctf_dropper = NULL; } - - return false; } MUTATOR_HOOKFUNCTION(ctf, GiveFragsForKill) { - frag_score = 0; + M_ARGV(2, float) = 0; // frag score return (autocvar_g_ctf_ignore_frags); // no frags counted in ctf if this is true } void ctf_RemovePlayer(entity player) { if(player.flagcarried) - { ctf_Handle_Throw(player, world, DROP_NORMAL); } + { ctf_Handle_Throw(player, NULL, DROP_NORMAL); } for(entity flag = ctf_worldflaglist; flag; flag = flag.ctf_worldflagnext) { - if(flag.pass_sender == player) { flag.pass_sender = world; } - if(flag.pass_target == player) { flag.pass_target = world; } - if(flag.ctf_dropper == player) { flag.ctf_dropper = world; } + if(flag.pass_sender == player) { flag.pass_sender = NULL; } + if(flag.pass_target == player) { flag.pass_target = NULL; } + if(flag.ctf_dropper == player) { flag.ctf_dropper = NULL; } } } MUTATOR_HOOKFUNCTION(ctf, MakePlayerObserver) -{SELFPARAM(); - ctf_RemovePlayer(self); - return false; +{ + entity player = M_ARGV(0, entity); + + ctf_RemovePlayer(player); } MUTATOR_HOOKFUNCTION(ctf, ClientDisconnect) -{SELFPARAM(); - ctf_RemovePlayer(self); - return false; +{ + entity player = M_ARGV(0, entity); + + ctf_RemovePlayer(player); } MUTATOR_HOOKFUNCTION(ctf, PortalTeleport) -{SELFPARAM(); - if(self.flagcarried) - if(!autocvar_g_ctf_portalteleport) - { ctf_Handle_Throw(self, world, DROP_NORMAL); } +{ + entity player = M_ARGV(0, entity); - return false; + if(player.flagcarried) + if(!autocvar_g_ctf_portalteleport) + { ctf_Handle_Throw(player, NULL, DROP_NORMAL); } } MUTATOR_HOOKFUNCTION(ctf, PlayerUseKey) -{SELFPARAM(); - if(MUTATOR_RETURNVALUE || gameover) { return false; } +{ + if(MUTATOR_RETURNVALUE || gameover) { return; } - entity player = self; + entity player = M_ARGV(0, entity); if((time > player.throw_antispam) && !IS_DEAD(player) && !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 = world; + entity head, closest_target = NULL; head = WarpZone_FindRadius(player.origin, autocvar_g_ctf_pass_radius, true); while(head) // find the closest acceptable target to pass to @@ -2332,7 +2205,7 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerUseKey) 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)) + if(vlen2(passer_center - head_center) < vlen2(passer_center - closest_target_center)) { closest_target = head; } } else { closest_target = head; } @@ -2354,7 +2227,7 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerUseKey) { player.throw_prevtime = time; player.throw_count = 1; - ctf_Handle_Throw(player, world, DROP_THROW); + ctf_Handle_Throw(player, NULL, DROP_THROW); return true; } else @@ -2370,26 +2243,26 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerUseKey) 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); + ctf_Handle_Throw(player, NULL, DROP_THROW); return true; } } } - - return false; } MUTATOR_HOOKFUNCTION(ctf, HelpMePing) -{SELFPARAM(); - if(self.wps_flagcarrier) // update the flagcarrier waypointsprite with "NEEDING HELP" notification +{ + entity player = M_ARGV(0, entity); + + if(player.wps_flagcarrier) // update the flagcarrier waypointsprite with "NEEDING HELP" notification { - self.wps_helpme_time = time; - WaypointSprite_HelpMePing(self.wps_flagcarrier); + player.wps_helpme_time = time; + WaypointSprite_HelpMePing(player.wps_flagcarrier); } else // create a normal help me waypointsprite { - WaypointSprite_Spawn(WP_Helpme, waypointsprite_deployed_lifetime, waypointsprite_limitedrange, self, FLAG_WAYPOINT_OFFSET, world, self.team, self, wps_helpme, false, RADARICON_HELPME); - WaypointSprite_Ping(self.wps_helpme); + WaypointSprite_Spawn(WP_Helpme, waypointsprite_deployed_lifetime, waypointsprite_limitedrange, player, FLAG_WAYPOINT_OFFSET, NULL, player.team, player, wps_helpme, false, RADARICON_HELPME); + WaypointSprite_Ping(player.wps_helpme); } return true; @@ -2397,52 +2270,52 @@ MUTATOR_HOOKFUNCTION(ctf, HelpMePing) MUTATOR_HOOKFUNCTION(ctf, VehicleEnter) { - if(vh_player.flagcarried) - { - vh_player.flagcarried.nodrawtoclient = vh_player; // hide the flag from the driver + entity player = M_ARGV(0, entity); + entity veh = M_ARGV(1, entity); + if(player.flagcarried) + { if(!autocvar_g_ctf_allow_vehicle_carry && !autocvar_g_ctf_allow_vehicle_touch) { - ctf_Handle_Throw(vh_player, world, DROP_NORMAL); + ctf_Handle_Throw(player, NULL, DROP_NORMAL); } else { - setattachment(vh_player.flagcarried, vh_vehicle, ""); - setorigin(vh_player.flagcarried, VEHICLE_FLAG_OFFSET); - vh_player.flagcarried.scale = VEHICLE_FLAG_SCALE; - //vh_player.flagcarried.angles = '0 0 0'; + player.flagcarried.nodrawtoclient = player; // hide the flag from the driver + setattachment(player.flagcarried, veh, ""); + setorigin(player.flagcarried, VEHICLE_FLAG_OFFSET); + player.flagcarried.scale = VEHICLE_FLAG_SCALE; + //player.flagcarried.angles = '0 0 0'; } return true; } - - return false; } MUTATOR_HOOKFUNCTION(ctf, VehicleExit) { - if(vh_player.flagcarried) + entity player = M_ARGV(0, entity); + + if(player.flagcarried) { - setattachment(vh_player.flagcarried, vh_player, ""); - setorigin(vh_player.flagcarried, FLAG_CARRY_OFFSET); - vh_player.flagcarried.scale = FLAG_SCALE; - vh_player.flagcarried.angles = '0 0 0'; - vh_player.flagcarried.nodrawtoclient = world; + setattachment(player.flagcarried, player, ""); + setorigin(player.flagcarried, FLAG_CARRY_OFFSET); + player.flagcarried.scale = FLAG_SCALE; + player.flagcarried.angles = '0 0 0'; + player.flagcarried.nodrawtoclient = NULL; return true; } - - return false; } MUTATOR_HOOKFUNCTION(ctf, AbortSpeedrun) -{SELFPARAM(); - if(self.flagcarried) +{ + entity player = M_ARGV(0, entity); + + if(player.flagcarried) { - Send_Notification(NOTIF_ALL, world, MSG_INFO, ((self.flagcarried.team) ? APP_TEAM_ENT(self.flagcarried, INFO_CTF_FLAGRETURN_ABORTRUN) : INFO_CTF_FLAGRETURN_ABORTRUN_NEUTRAL)); - ctf_RespawnFlag(self.flagcarried); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((player.flagcarried.team) ? APP_TEAM_ENT(player.flagcarried, INFO_CTF_FLAGRETURN_ABORTRUN) : INFO_CTF_FLAGRETURN_ABORTRUN_NEUTRAL)); + ctf_RespawnFlag(player.flagcarried); return true; } - - return false; } MUTATOR_HOOKFUNCTION(ctf, MatchEnd) @@ -2457,7 +2330,7 @@ MUTATOR_HOOKFUNCTION(ctf, MatchEnd) case FLAG_PASSING: { // lock the flag, game is over - flag.movetype = MOVETYPE_NONE; + set_movetype(flag, MOVETYPE_NONE); flag.takedamage = DAMAGE_NO; flag.solid = SOLID_NOT; flag.nextthink = false; // stop thinking @@ -2475,31 +2348,36 @@ MUTATOR_HOOKFUNCTION(ctf, MatchEnd) } } } - - return false; } MUTATOR_HOOKFUNCTION(ctf, HavocBot_ChooseRole) -{SELFPARAM(); - havocbot_ctf_reset_role(self); +{ + entity bot = M_ARGV(0, entity); + + havocbot_ctf_reset_role(bot); return true; } MUTATOR_HOOKFUNCTION(ctf, GetTeamCount) { - //ret_float = ctf_teams; - ret_string = "ctf_team"; + //M_ARGV(0, float) = ctf_teams; + M_ARGV(1, string) = "ctf_team"; return true; } MUTATOR_HOOKFUNCTION(ctf, SpectateCopy) -{SELFPARAM(); - self.ctf_flagstatus = other.ctf_flagstatus; - return false; +{ + entity spectatee = M_ARGV(0, entity); + entity client = M_ARGV(1, entity); + + client.ctf_flagstatus = spectatee.ctf_flagstatus; } MUTATOR_HOOKFUNCTION(ctf, GetRecords) { + int record_page = M_ARGV(0, int); + string ret_string = M_ARGV(1, string); + for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i) { if (MapInfo_Get_ByID(i)) @@ -2515,14 +2393,18 @@ MUTATOR_HOOKFUNCTION(ctf, GetRecords) } } - return false; + M_ARGV(1, string) = ret_string; } -bool superspec_Spectate(entity _player); // TODO +bool superspec_Spectate(entity this, entity targ); // TODO void superspec_msg(string _center_title, string _con_title, entity _to, string _msg, float _spamlevel); // TODO MUTATOR_HOOKFUNCTION(ctf, SV_ParseClientCommand) { - if(IS_PLAYER(self) || MUTATOR_RETURNVALUE || !cvar("g_superspectate")) { return false; } + entity player = M_ARGV(0, entity); + string cmd_name = M_ARGV(1, string); + int cmd_argc = M_ARGV(2, int); + + if(IS_PLAYER(player) || MUTATOR_RETURNVALUE || !cvar("g_superspectate")) { return false; } if(cmd_name == "followfc") { @@ -2536,10 +2418,10 @@ MUTATOR_HOOKFUNCTION(ctf, SV_ParseClientCommand) { switch(argv(1)) { - case "red": _team = NUM_TEAM_1; break; - case "blue": _team = NUM_TEAM_2; break; - case "yellow": if(ctf_teams >= 3) _team = NUM_TEAM_3; break; - case "pink": if(ctf_teams >= 4) _team = NUM_TEAM_4; break; + case "red": if(ctf_teams & BIT(0)) _team = NUM_TEAM_1; break; + case "blue": if(ctf_teams & BIT(1)) _team = NUM_TEAM_2; break; + case "yellow": if(ctf_teams & BIT(2)) _team = NUM_TEAM_3; break; + case "pink": if(ctf_teams & BIT(3)) _team = NUM_TEAM_4; break; } } @@ -2547,26 +2429,24 @@ MUTATOR_HOOKFUNCTION(ctf, SV_ParseClientCommand) if(it.flagcarried && (it.team == _team || _team == 0)) { found = true; - if(_team == 0 && IS_SPEC(self) && self.enemy == it) + if(_team == 0 && IS_SPEC(player) && player.enemy == it) continue; // already spectating this fc, try another - return superspec_Spectate(it); + return superspec_Spectate(player, it); } )); if(!found) - superspec_msg("", "", self, "No active flag carrier\n", 1); + superspec_msg("", "", player, "No active flag carrier\n", 1); return true; } - - return false; } MUTATOR_HOOKFUNCTION(ctf, DropSpecialItems) { + entity frag_target = M_ARGV(0, entity); + if(frag_target.flagcarried) - ctf_Handle_Throw(frag_target, world, DROP_THROW); - - return false; + ctf_Handle_Throw(frag_target, NULL, DROP_THROW); } @@ -2587,9 +2467,9 @@ Keys: "noise5" sound played when flag touches the ground... */ spawnfunc(item_flag_team1) { - if(!g_ctf) { remove(self); return; } + if(!g_ctf) { remove(this); return; } - ctf_FlagSetup(NUM_TEAM_1, self); + ctf_FlagSetup(NUM_TEAM_1, this); } /*QUAKED spawnfunc_item_flag_team2 (0 0.5 0.8) (-48 -48 -37) (48 48 37) @@ -2605,9 +2485,9 @@ Keys: "noise5" sound played when flag touches the ground... */ spawnfunc(item_flag_team2) { - if(!g_ctf) { remove(self); return; } + if(!g_ctf) { remove(this); return; } - ctf_FlagSetup(NUM_TEAM_2, self); + ctf_FlagSetup(NUM_TEAM_2, this); } /*QUAKED spawnfunc_item_flag_team3 (0 0.5 0.8) (-48 -48 -37) (48 48 37) @@ -2623,9 +2503,9 @@ Keys: "noise5" sound played when flag touches the ground... */ spawnfunc(item_flag_team3) { - if(!g_ctf) { remove(self); return; } + if(!g_ctf) { remove(this); return; } - ctf_FlagSetup(NUM_TEAM_3, self); + ctf_FlagSetup(NUM_TEAM_3, this); } /*QUAKED spawnfunc_item_flag_team4 (0 0.5 0.8) (-48 -48 -37) (48 48 37) @@ -2641,9 +2521,9 @@ Keys: "noise5" sound played when flag touches the ground... */ spawnfunc(item_flag_team4) { - if(!g_ctf) { remove(self); return; } + if(!g_ctf) { remove(this); return; } - ctf_FlagSetup(NUM_TEAM_4, self); + ctf_FlagSetup(NUM_TEAM_4, this); } /*QUAKED spawnfunc_item_flag_neutral (0 0.5 0.8) (-48 -48 -37) (48 48 37) @@ -2659,10 +2539,10 @@ Keys: "noise5" sound played when flag touches the ground... */ spawnfunc(item_flag_neutral) { - if(!g_ctf) { remove(self); return; } - if(!cvar("g_ctf_oneflag")) { remove(self); return; } + if(!g_ctf) { remove(this); return; } + if(!cvar("g_ctf_oneflag")) { remove(this); return; } - ctf_FlagSetup(0, self); + ctf_FlagSetup(0, this); } /*QUAKED spawnfunc_ctf_team (0 .5 .8) (-16 -16 -24) (16 16 32) @@ -2673,10 +2553,10 @@ Keys: "cnt" Scoreboard color of the team (for example 4 is red and 13 is blue)... */ spawnfunc(ctf_team) { - if(!g_ctf) { remove(self); return; } + if(!g_ctf) { remove(this); return; } - self.classname = "ctf_team"; - self.team = self.cnt + 1; + this.classname = "ctf_team"; + this.team = this.cnt + 1; } // compatibility for quake maps @@ -2689,8 +2569,8 @@ spawnfunc(info_player_team2); spawnfunc(team_CTF_blueplayer) { spawnfunc_info_player_team2(this); } spawnfunc(team_CTF_bluespawn) { spawnfunc_info_player_team2(this); } -void team_CTF_neutralflag() { SELFPARAM(); spawnfunc_item_flag_neutral(self); } -void team_neutralobelisk() { SELFPARAM(); spawnfunc_item_flag_neutral(self); } +spawnfunc(team_CTF_neutralflag) { spawnfunc_item_flag_neutral(this); } +spawnfunc(team_neutralobelisk) { spawnfunc_item_flag_neutral(this); } // ============== @@ -2700,7 +2580,7 @@ void team_neutralobelisk() { SELFPARAM(); spawnfunc_item_flag_neutral(self); // scoreboard setup void ctf_ScoreRules(int teams) { - CheckAllowedTeams(world); + CheckAllowedTeams(NULL); ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true); ScoreInfo_SetLabel_TeamScore (ST_CTF_CAPS, "caps", SFL_SORT_PRIO_PRIMARY); ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); @@ -2717,35 +2597,52 @@ void ctf_SpawnTeam (string teamname, int teamcolor) { entity this = new_pure(ctf_team); this.netname = teamname; - this.cnt = teamcolor; + this.cnt = teamcolor - 1; this.spawnfunc_checked = true; - WITH(entity, self, this, spawnfunc_ctf_team(this)); + this.team = teamcolor; } -void ctf_DelayedInit() // Do this check with a delay so we can wait for teams to be set up. +void ctf_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up. { - ctf_teams = 2; + ctf_teams = 0; entity tmp_entity; for(tmp_entity = ctf_worldflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_worldflagnext) { - if(tmp_entity.team == NUM_TEAM_3) { ctf_teams = max(3, ctf_teams); } - if(tmp_entity.team == NUM_TEAM_4) { ctf_teams = max(4, ctf_teams); } + //if(tmp_entity.team == NUM_TEAM_3) { ctf_teams = max(3, ctf_teams); } + //if(tmp_entity.team == NUM_TEAM_4) { ctf_teams = max(4, ctf_teams); } + + switch(tmp_entity.team) + { + case NUM_TEAM_1: BITSET_ASSIGN(ctf_teams, BIT(0)); break; + case NUM_TEAM_2: BITSET_ASSIGN(ctf_teams, BIT(1)); break; + case NUM_TEAM_3: BITSET_ASSIGN(ctf_teams, BIT(2)); break; + case NUM_TEAM_4: BITSET_ASSIGN(ctf_teams, BIT(3)); break; + } if(tmp_entity.team == 0) { ctf_oneflag = true; } } - ctf_teams = bound(2, ctf_teams, 4); + if(NumTeams(ctf_teams) < 2) // somehow, there's not enough flags! + { + ctf_teams = 0; // so set the default red and blue teams + BITSET_ASSIGN(ctf_teams, BIT(0)); + BITSET_ASSIGN(ctf_teams, BIT(1)); + } + + //ctf_teams = bound(2, ctf_teams, 4); // if no teams are found, spawn defaults - if(find(world, classname, "ctf_team") == world) + if(find(NULL, classname, "ctf_team") == NULL) { LOG_TRACE("No \"ctf_team\" entities found on this map, creating them anyway.\n"); - ctf_SpawnTeam("Red", NUM_TEAM_1 - 1); - ctf_SpawnTeam("Blue", NUM_TEAM_2 - 1); - if(ctf_teams >= 3) - ctf_SpawnTeam("Yellow", NUM_TEAM_3 - 1); - if(ctf_teams >= 4) - ctf_SpawnTeam("Pink", NUM_TEAM_4 - 1); + if(ctf_teams & BIT(0)) + ctf_SpawnTeam("Red", NUM_TEAM_1); + if(ctf_teams & BIT(1)) + ctf_SpawnTeam("Blue", NUM_TEAM_2); + if(ctf_teams & BIT(2)) + ctf_SpawnTeam("Yellow", NUM_TEAM_3); + if(ctf_teams & BIT(3)) + ctf_SpawnTeam("Pink", NUM_TEAM_4); } ctf_ScoreRules(ctf_teams); @@ -2759,7 +2656,7 @@ void ctf_Initialize() ctf_captureshield_max_ratio = autocvar_g_ctf_shield_max_ratio; ctf_captureshield_force = autocvar_g_ctf_shield_force; - InitializeEntity(world, ctf_DelayedInit, INITPRIO_GAMETYPE); + InitializeEntity(NULL, ctf_DelayedInit, INITPRIO_GAMETYPE); } #endif