X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fgamemodes%2Fgamemode%2Fonslaught%2Fonslaught.qc;h=b35d8488319d805b34e6e3ca8c4b0fff4e955134;hp=04b5a3f7bf0c7ca7ca8537869afb8804b29239eb;hb=10c0e93c75ef6f408e3357bd5fb46c721e7e0576;hpb=317ec3eb27ada1c4668876e9499136125acb7984 diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc index 04b5a3f7b..b35d84883 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc @@ -13,7 +13,7 @@ REGISTER_MUTATOR(ons, false) ons_Initialize(); ActivateTeamplay(); - SetLimits(autocvar_g_onslaught_point_limit, -1, -1, -1); + SetLimits(autocvar_g_onslaught_point_limit, autocvar_leadlimit_override, autocvar_timelimit_override, -1); have_team_spawns = -1; // request team spawns } @@ -76,7 +76,7 @@ bool ons_stalemate; .float teleport_antispam; -.bool ons_roundlost; +.bool ons_roundlost = _STAT(ROUNDLOST); // waypoint sprites .entity bot_basewaypoint; // generator waypointsprite @@ -110,18 +110,16 @@ const int HAVOCBOT_ONS_ROLE_OFFENSE = 8; .int havocbot_role_flags; .float havocbot_attack_time; -void havocbot_role_ons_defense(); -void havocbot_role_ons_offense(); -void havocbot_role_ons_assistant(); +void havocbot_role_ons_defense(entity this); +void havocbot_role_ons_offense(entity this); +void havocbot_role_ons_assistant(entity this); -void havocbot_ons_reset_role(entity bot); -void havocbot_goalrating_items(float ratingscale, vector org, float sradius); -void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius); +void havocbot_ons_reset_role(entity this); +void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius); +void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius); // score rule declarations const int ST_ONS_CAPS = 1; -const int SP_ONS_CAPS = 4; -const int SP_ONS_TAKES = 6; #endif #endif @@ -133,7 +131,6 @@ const int SP_ONS_TAKES = 6; bool g_onslaught; -float autocvar_g_onslaught_debug; float autocvar_g_onslaught_teleport_wait; bool autocvar_g_onslaught_spawn_at_controlpoints; bool autocvar_g_onslaught_spawn_at_generator; @@ -163,42 +160,42 @@ void FixSize(entity e); // CaptureShield Functions // ======================= -bool ons_CaptureShield_Customize() -{SELFPARAM(); +bool ons_CaptureShield_Customize(entity this) +{ entity e = WaypointSprite_getviewentity(other); - if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; } - if(SAME_TEAM(self, e)) { return false; } + if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; } + if(SAME_TEAM(this, e)) { return false; } return true; } -void ons_CaptureShield_Touch() -{SELFPARAM(); - if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; } +void ons_CaptureShield_Touch(entity this) +{ + if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, other.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; } if(!IS_PLAYER(other)) { return; } - if(SAME_TEAM(other, self)) { return; } + if(SAME_TEAM(other, this)) { return; } - vector mymid = (self.absmin + self.absmax) * 0.5; + vector mymid = (this.absmin + this.absmax) * 0.5; vector othermid = (other.absmin + other.absmax) * 0.5; - Damage(other, self, self, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ons_captureshield_force); + Damage(other, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ons_captureshield_force); if(IS_REAL_CLIENT(other)) { play2(other, SND(ONS_DAMAGEBLOCKEDBYSHIELD)); - if(self.enemy.classname == "onslaught_generator") + if(this.enemy.classname == "onslaught_generator") Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED); else Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED); } } -void ons_CaptureShield_Reset() -{SELFPARAM(); - self.colormap = self.enemy.colormap; - self.team = self.enemy.team; +void ons_CaptureShield_Reset(entity this) +{ + this.colormap = this.enemy.colormap; + this.team = this.enemy.team; } void ons_CaptureShield_Spawn(entity generator, bool is_generator) @@ -209,8 +206,8 @@ void ons_CaptureShield_Spawn(entity generator, bool is_generator) shield.team = generator.team; shield.colormap = generator.colormap; shield.reset = ons_CaptureShield_Reset; - shield.touch = ons_CaptureShield_Touch; - shield.customizeentityforclient = ons_CaptureShield_Customize; + settouch(shield, ons_CaptureShield_Touch); + setcefc(shield, ons_CaptureShield_Customize); shield.effects = EF_ADDITIVE; shield.movetype = MOVETYPE_NOCLIP; shield.solid = SOLID_TRIGGER; @@ -229,15 +226,6 @@ void ons_CaptureShield_Spawn(entity generator, bool is_generator) // Junk Pile // ========== -void ons_debug(string input) -{ - switch(autocvar_g_onslaught_debug) - { - case 1: LOG_TRACE(input); break; - case 2: LOG_INFO(input); break; - } -} - void setmodel_fixsize(entity e, Model m) { setmodel(e, m); @@ -248,14 +236,14 @@ void onslaught_updatelinks() { entity l; // first check if the game has ended - ons_debug("--- updatelinks ---\n"); + LOG_DEBUG("--- updatelinks ---\n"); // mark generators as being shielded and networked for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext) { if (l.iscaptured) - ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n")); + LOG_DEBUG(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n")); else - ons_debug(strcat(etos(l), " (generator) is destroyed\n")); + LOG_DEBUG(strcat(etos(l), " (generator) is destroyed\n")); l.islinked = l.iscaptured; l.isshielded = l.iscaptured; l.sprite.SendFlags |= 16; @@ -267,7 +255,7 @@ void onslaught_updatelinks() l.isshielded = true; int i; for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; } - ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n")); + LOG_DEBUG(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n")); l.sprite.SendFlags |= 16; } // flow power outward from the generators through the network @@ -287,13 +275,13 @@ void onslaught_updatelinks() { stop = false; l.goalentity.islinked = true; - ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n")); + LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n")); } else if (!l.enemy.islinked) { stop = false; l.enemy.islinked = true; - ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n")); + LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n")); } } } @@ -306,7 +294,7 @@ void onslaught_updatelinks() { if(DIFF_TEAM(l.goalentity, l.enemy)) { - ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n")); + LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n")); l.enemy.isshielded = false; } if(l.goalentity.classname == "onslaught_generator") @@ -318,7 +306,7 @@ void onslaught_updatelinks() { if(DIFF_TEAM(l.goalentity, l.enemy)) { - ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n")); + LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n")); l.goalentity.isshielded = false; } if(l.enemy.classname == "onslaught_generator") @@ -332,13 +320,13 @@ void onslaught_updatelinks() { if (l.isshielded) { - ons_debug(strcat(etos(l), " (generator) is shielded\n")); + LOG_DEBUG(strcat(etos(l), " (generator) is shielded\n")); l.takedamage = DAMAGE_NO; l.bot_attack = false; } else { - ons_debug(strcat(etos(l), " (generator) is not shielded\n")); + LOG_DEBUG(strcat(etos(l), " (generator) is not shielded\n")); l.takedamage = DAMAGE_AIM; l.bot_attack = true; } @@ -350,7 +338,7 @@ void onslaught_updatelinks() { if (l.isshielded) { - ons_debug(strcat(etos(l), " (point) is shielded\n")); + LOG_DEBUG(strcat(etos(l), " (point) is shielded\n")); if (l.goalentity) { l.goalentity.takedamage = DAMAGE_NO; @@ -359,7 +347,7 @@ void onslaught_updatelinks() } else { - ons_debug(strcat(etos(l), " (point) is not shielded\n")); + LOG_DEBUG(strcat(etos(l), " (point) is not shielded\n")); if (l.goalentity) { l.goalentity.takedamage = DAMAGE_AIM; @@ -388,53 +376,53 @@ bool ons_Link_Send(entity this, entity to, int sendflags) WriteByte(MSG_ENTITY, sendflags); if(sendflags & 1) { - WriteCoord(MSG_ENTITY, self.goalentity.origin_x); - WriteCoord(MSG_ENTITY, self.goalentity.origin_y); - WriteCoord(MSG_ENTITY, self.goalentity.origin_z); + WriteCoord(MSG_ENTITY, this.goalentity.origin_x); + WriteCoord(MSG_ENTITY, this.goalentity.origin_y); + WriteCoord(MSG_ENTITY, this.goalentity.origin_z); } if(sendflags & 2) { - WriteCoord(MSG_ENTITY, self.enemy.origin_x); - WriteCoord(MSG_ENTITY, self.enemy.origin_y); - WriteCoord(MSG_ENTITY, self.enemy.origin_z); + WriteCoord(MSG_ENTITY, this.enemy.origin_x); + WriteCoord(MSG_ENTITY, this.enemy.origin_y); + WriteCoord(MSG_ENTITY, this.enemy.origin_z); } if(sendflags & 4) { - WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16 + WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16 } return true; } -void ons_Link_CheckUpdate() -{SELFPARAM(); +void ons_Link_CheckUpdate(entity this) +{ // TODO check if the two sides have moved (currently they won't move anyway) float cc = 0, cc1 = 0, cc2 = 0; - if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; } - if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; } + if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; } + if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; } cc = cc1 + cc2; - if(cc != self.clientcolors) + if(cc != this.clientcolors) { - self.clientcolors = cc; - self.SendFlags |= 4; + this.clientcolors = cc; + this.SendFlags |= 4; } - self.nextthink = time; + this.nextthink = time; } -void ons_DelayedLinkSetup() -{SELFPARAM(); - self.goalentity = find(world, targetname, self.target); - self.enemy = find(world, targetname, self.target2); - if(!self.goalentity) { objerror("can not find target\n"); } - if(!self.enemy) { objerror("can not find target2\n"); } +void ons_DelayedLinkSetup(entity this) +{ + this.goalentity = find(NULL, targetname, this.target); + this.enemy = find(NULL, targetname, this.target2); + if(!this.goalentity) { objerror(this, "can not find target\n"); } + if(!this.enemy) { objerror(this, "can not find target2\n"); } - ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n")); - self.SendFlags |= 3; - self.think = ons_Link_CheckUpdate; - self.nextthink = time; + LOG_DEBUG(strcat(etos(this.goalentity), " linked with ", etos(this.enemy), "\n")); + this.SendFlags |= 3; + setthink(this, ons_Link_CheckUpdate); + this.nextthink = time; } @@ -497,18 +485,18 @@ int ons_ControlPoint_Attackable(entity cp, int teamnumber) return 0; } -void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) -{SELFPARAM(); +void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) +{ if(damage <= 0) { return; } - if (self.owner.isshielded) + if (this.owner.isshielded) { // this is protected by a shield, so ignore the damage - if (time > self.pain_finished) + if (time > this.pain_finished) if (IS_PLAYER(attacker)) { play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD)); - self.pain_finished = time + 1; + this.pain_finished = time + 1; attacker.typehitsound += 1; // play both sounds (shield is way too quiet) } @@ -516,198 +504,182 @@ void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damag } if(IS_PLAYER(attacker)) - if(time - ons_notification_time[self.team] > 10) + if(time - ons_notification_time[this.team] > 10) { - play2team(self.team, SND(ONS_CONTROLPOINT_UNDERATTACK)); - ons_notification_time[self.team] = time; + play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK)); + ons_notification_time[this.team] = time; } - self.health = self.health - damage; - if(self.owner.iscaptured) - WaypointSprite_UpdateHealth(self.owner.sprite, self.health); + this.health = this.health - damage; + if(this.owner.iscaptured) + WaypointSprite_UpdateHealth(this.owner.sprite, this.health); else - WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE)); - self.pain_finished = time + 1; + WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE)); + this.pain_finished = time + 1; // particles on every hit pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1); //sound on every hit if (random() < 0.5) - sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM); + sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM); else - sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM); + sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM); - if (self.health < 0) + if (this.health < 0) { - sound(self, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM); - pointparticles(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1); - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname); + sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM); + pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname); PlayerScore_Add(attacker, SP_ONS_TAKES, 1); PlayerScore_Add(attacker, SP_SCORE, 10); - self.owner.goalentity = world; - self.owner.islinked = false; - self.owner.iscaptured = false; - self.owner.team = 0; - self.owner.colormap = 1024; + this.owner.goalentity = NULL; + this.owner.islinked = false; + this.owner.iscaptured = false; + this.owner.team = 0; + this.owner.colormap = 1024; - WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0); + WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0); onslaught_updatelinks(); // Use targets now (somebody make sure this is in the right place..) - setself(self.owner); - activator = self; - SUB_UseTargets (); - setself(this); + SUB_UseTargets(this.owner, this, NULL); - self.owner.waslinked = self.owner.islinked; - if(self.owner.model != "models/onslaught/controlpoint_pad.md3") - setmodel_fixsize(self.owner, MDL_ONS_CP_PAD1); - //setsize(self, '-32 -32 0', '32 32 8'); + this.owner.waslinked = this.owner.islinked; + if(this.owner.model != "models/onslaught/controlpoint_pad.md3") + setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1); + //setsize(this, '-32 -32 0', '32 32 8'); - remove(self); + remove(this); } - self.SendFlags |= CPSF_STATUS; + this.SendFlags |= CPSF_STATUS; } -void ons_ControlPoint_Icon_Think() -{SELFPARAM(); - self.nextthink = time + ONS_CP_THINKRATE; +void ons_ControlPoint_Icon_Think(entity this) +{ + this.nextthink = time + ONS_CP_THINKRATE; if(autocvar_g_onslaught_cp_proxydecap) { - int _enemy_count = 0; - int _friendly_count = 0; - float _dist; - entity _player; - - FOR_EACH_PLAYER(_player) - { - if(!_player.deadflag) - { - _dist = vlen(_player.origin - self.origin); - if(_dist < autocvar_g_onslaught_cp_proxydecap_distance) - { - if(SAME_TEAM(_player, self)) - ++_friendly_count; - else - ++_enemy_count; - } - } - } - - _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE); - _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE); - - self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health); - self.SendFlags |= CPSF_STATUS; - if(self.health <= 0) - { - ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0'); - return; - } - } - - if (time > self.pain_finished + 5) - { - if(self.health < self.max_health) + int _enemy_count = 0; + int _friendly_count = 0; + + FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), { + if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance)) + { + if(SAME_TEAM(it, this)) + ++_friendly_count; + else + ++_enemy_count; + } + }); + + _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE); + _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE); + + this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health); + this.SendFlags |= CPSF_STATUS; + if(this.health <= 0) + { + ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0'); + return; + } + } + + if (time > this.pain_finished + 5) + { + if(this.health < this.max_health) { - self.health = self.health + self.count; - if (self.health >= self.max_health) - self.health = self.max_health; - WaypointSprite_UpdateHealth(self.owner.sprite, self.health); + this.health = this.health + this.count; + if (this.health >= this.max_health) + this.health = this.max_health; + WaypointSprite_UpdateHealth(this.owner.sprite, this.health); } } - if(self.owner.islinked != self.owner.waslinked) + if(this.owner.islinked != this.owner.waslinked) { // unteam the spawnpoint if needed - int t = self.owner.team; - if(!self.owner.islinked) - self.owner.team = 0; + int t = this.owner.team; + if(!this.owner.islinked) + this.owner.team = 0; - setself(self.owner); - activator = self; - SUB_UseTargets (); - setself(this); + SUB_UseTargets(this.owner, this, NULL); - self.owner.team = t; + this.owner.team = t; - self.owner.waslinked = self.owner.islinked; + this.owner.waslinked = this.owner.islinked; } // damaged fx - if(random() < 0.6 - self.health / self.max_health) + if(random() < 0.6 - this.health / this.max_health) { - Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1); + Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1); if(random() > 0.8) - sound(self, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM); + sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM); else if (random() > 0.5) - sound(self, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM); + sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM); } } -void ons_ControlPoint_Icon_BuildThink() -{SELFPARAM(); +void ons_ControlPoint_Icon_BuildThink(entity this) +{ int a; - self.nextthink = time + ONS_CP_THINKRATE; + this.nextthink = time + ONS_CP_THINKRATE; // only do this if there is power - a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team); + a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team); if(!a) return; - self.health = self.health + self.count; + this.health = this.health + this.count; - self.SendFlags |= CPSF_STATUS; + this.SendFlags |= CPSF_STATUS; - if (self.health >= self.max_health) + if (this.health >= this.max_health) { - self.health = self.max_health; - self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on - self.think = ons_ControlPoint_Icon_Think; - sound(self, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM); - self.owner.iscaptured = true; - self.solid = SOLID_BBOX; + this.health = this.max_health; + this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on + setthink(this, ons_ControlPoint_Icon_Think); + sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM); + this.owner.iscaptured = true; + this.solid = SOLID_BBOX; - Send_Effect(EFFECT_CAP(self.owner.team), self.owner.origin, '0 0 0', 1); + Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1); - WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health); - WaypointSprite_UpdateHealth(self.owner.sprite, self.health); + WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health); + WaypointSprite_UpdateHealth(this.owner.sprite, this.health); - if(IS_PLAYER(self.owner.ons_toucher)) + if(IS_PLAYER(this.owner.ons_toucher)) { - Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message); - Send_Notification(NOTIF_ALL_EXCEPT, self.owner.ons_toucher, MSG_CENTER, APP_TEAM_ENT_4(self.owner.ons_toucher, CENTER_ONS_CAPTURE_), self.owner.message); - Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message); - PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1); - PlayerTeamScore_AddScore(self.owner.ons_toucher, 10); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message); + Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE), this.owner.message); + Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message); + PlayerScore_Add(this.owner.ons_toucher, SP_ONS_CAPS, 1); + PlayerTeamScore_AddScore(this.owner.ons_toucher, 10); } - self.owner.ons_toucher = world; + this.owner.ons_toucher = NULL; onslaught_updatelinks(); // Use targets now (somebody make sure this is in the right place..) - setself(self.owner); - activator = self; - SUB_UseTargets (); - setself(this); + SUB_UseTargets(this.owner, this, NULL); - self.SendFlags |= CPSF_SETUP; + this.SendFlags |= CPSF_SETUP; } - if(self.owner.model != MDL_ONS_CP_PAD2.model_str()) - setmodel_fixsize(self.owner, MDL_ONS_CP_PAD2); + if(this.owner.model != MDL_ONS_CP_PAD2.model_str()) + setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2); - if(random() < 0.9 - self.health / self.max_health) - Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1); + if(random() < 0.9 - this.health / this.max_health) + Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1); } -void onslaught_controlpoint_icon_link(entity e, void() spawnproc); +void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc); void ons_ControlPoint_Icon_Spawn(entity cp, entity player) { @@ -802,8 +774,8 @@ void ons_ControlPoint_UpdateSprite(entity e) } } -void ons_ControlPoint_Touch() -{SELFPARAM(); +void ons_ControlPoint_Touch(entity this) +{ entity toucher = other; int attackable; @@ -814,11 +786,11 @@ void ons_ControlPoint_Touch() return; if(!IS_PLAYER(toucher)) { return; } - if(toucher.frozen) { return; } - if(toucher.deadflag != DEAD_NO) { return; } + if(STAT(FROZEN, toucher)) { return; } + if(IS_DEAD(toucher)) { return; } - if ( SAME_TEAM(self,toucher) ) - if ( self.iscaptured ) + if ( SAME_TEAM(this,toucher) ) + if ( this.iscaptured ) { if(time <= toucher.teleport_antispam) Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time)); @@ -826,67 +798,63 @@ void ons_ControlPoint_Touch() Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT); } - attackable = ons_ControlPoint_Attackable(self, toucher.team); + attackable = ons_ControlPoint_Attackable(this, toucher.team); if(attackable != 2 && attackable != 4) return; // we've verified that this player has a legitimate claim to this point, // so start building the captured point icon (which only captures this // point if it successfully builds without being destroyed first) - ons_ControlPoint_Icon_Spawn(self, toucher); + ons_ControlPoint_Icon_Spawn(this, toucher); - self.ons_toucher = toucher; + this.ons_toucher = toucher; onslaught_updatelinks(); } -void ons_ControlPoint_Think() -{SELFPARAM(); - self.nextthink = time + ONS_CP_THINKRATE; - CSQCMODEL_AUTOUPDATE(self); +void ons_ControlPoint_Think(entity this) +{ + this.nextthink = time + ONS_CP_THINKRATE; + CSQCMODEL_AUTOUPDATE(this); } -void ons_ControlPoint_Reset() -{SELFPARAM(); - if(self.goalentity) - remove(self.goalentity); - - self.goalentity = world; - self.team = 0; - self.colormap = 1024; - self.iscaptured = false; - self.islinked = false; - self.isshielded = true; - self.think = ons_ControlPoint_Think; - self.ons_toucher = world; - self.nextthink = time + ONS_CP_THINKRATE; - setmodel_fixsize(self, MDL_ONS_CP_PAD1); - - WaypointSprite_UpdateMaxHealth(self.sprite, 0); - WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY); +void ons_ControlPoint_Reset(entity this) +{ + if(this.goalentity) + remove(this.goalentity); + + this.goalentity = NULL; + this.team = 0; + this.colormap = 1024; + this.iscaptured = false; + this.islinked = false; + this.isshielded = true; + setthink(this, ons_ControlPoint_Think); + this.ons_toucher = NULL; + this.nextthink = time + ONS_CP_THINKRATE; + setmodel_fixsize(this, MDL_ONS_CP_PAD1); + + WaypointSprite_UpdateMaxHealth(this.sprite, 0); + WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY); onslaught_updatelinks(); - activator = self; - SUB_UseTargets(); // to reset the structures, playerspawns etc. + SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc. - CSQCMODEL_AUTOUPDATE(self); + CSQCMODEL_AUTOUPDATE(this); } -void ons_DelayedControlPoint_Setup() -{SELFPARAM(); +void ons_DelayedControlPoint_Setup(entity this) +{ onslaught_updatelinks(); // captureshield setup - ons_CaptureShield_Spawn(self, false); + ons_CaptureShield_Spawn(this, false); - CSQCMODEL_AUTOINIT(self); + CSQCMODEL_AUTOINIT(this); } void ons_ControlPoint_Setup(entity cp) -{SELFPARAM(); - // declarations - setself(cp); // for later usage with droptofloor() - +{ // main setup cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist ons_worldcplist = cp; @@ -895,8 +863,8 @@ void ons_ControlPoint_Setup(entity cp) cp.team = 0; cp.solid = SOLID_BBOX; cp.movetype = MOVETYPE_NONE; - cp.touch = ons_ControlPoint_Touch; - cp.think = ons_ControlPoint_Think; + settouch(cp, ons_ControlPoint_Touch); + setthink(cp, ons_ControlPoint_Think); cp.nextthink = time + ONS_CP_THINKRATE; cp.reset = ons_ControlPoint_Reset; cp.colormap = 1024; @@ -919,14 +887,13 @@ void ons_ControlPoint_Setup(entity cp) { setorigin(cp, cp.origin + '0 0 20'); cp.noalign = false; - setself(cp); - droptofloor(); + droptofloor(cp); cp.movetype = MOVETYPE_TOSS; } // waypointsprites - WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE); - WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY); + WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE); + WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY); InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION); } @@ -970,65 +937,64 @@ void ons_Generator_UpdateSprite(entity e) } } -void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) -{SELFPARAM(); +void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) +{ if(damage <= 0) { return; } if(warmup_stage || gameover) { return; } if(!round_handler_IsRoundStarted()) { return; } - if (attacker != self) + if (attacker != this) { - if (self.isshielded) + if (this.isshielded) { // this is protected by a shield, so ignore the damage - if (time > self.pain_finished) + if (time > this.pain_finished) if (IS_PLAYER(attacker)) { play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD)); attacker.typehitsound += 1; - self.pain_finished = time + 1; + this.pain_finished = time + 1; } return; } - if (time > self.pain_finished) + if (time > this.pain_finished) { - self.pain_finished = time + 10; - entity head; - FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); } - play2team(self.team, SND(ONS_GENERATOR_UNDERATTACK)); + this.pain_finished = time + 10; + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK)); + play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK)); } } - self.health = self.health - damage; - WaypointSprite_UpdateHealth(self.sprite, self.health); + this.health = this.health - damage; + WaypointSprite_UpdateHealth(this.sprite, this.health); // choose an animation frame based on health - self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1); + this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1); // see if the generator is still functional, or dying - if (self.health > 0) + if (this.health > 0) { - self.lasthealth = self.health; + this.lasthealth = this.health; } else { - if (attacker == self) - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_)); + if (attacker == this) + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME)); else { - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_)); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED)); PlayerScore_Add(attacker, SP_SCORE, 100); } - self.iscaptured = false; - self.islinked = false; - self.isshielded = false; - self.takedamage = DAMAGE_NO; // can't be hurt anymore - self.event_damage = func_null; // won't do anything if hurt - self.count = 0; // reset counter - self.think = func_null; - self.nextthink = 0; - //self.think(); // do the first explosion now - - WaypointSprite_UpdateMaxHealth(self.sprite, 0); - WaypointSprite_Ping(self.sprite); - //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor + this.iscaptured = false; + this.islinked = false; + this.isshielded = false; + this.takedamage = DAMAGE_NO; // can't be hurt anymore + this.event_damage = func_null; // won't do anything if hurt + this.count = 0; // reset counter + setthink(this, func_null); + this.nextthink = 0; + //this.think(); // do the first explosion now + + WaypointSprite_UpdateMaxHealth(this.sprite, 0); + WaypointSprite_Ping(this.sprite); + //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor onslaught_updatelinks(); } @@ -1036,7 +1002,7 @@ void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int de // Throw some flaming gibs on damage, more damage = more chance for gib if(random() < damage/220) { - sound(self, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); + sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); } else { @@ -1045,93 +1011,90 @@ void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int de //sound on every hit if (random() < 0.5) - sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM); + sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM); else - sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM); + sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM); } - self.SendFlags |= GSF_STATUS; + this.SendFlags |= GSF_STATUS; } -void ons_GeneratorThink() -{SELFPARAM(); - entity e; - self.nextthink = time + GEN_THINKRATE; +void ons_GeneratorThink(entity this) +{ + this.nextthink = time + GEN_THINKRATE; if (!gameover) { - if(!self.isshielded && self.wait < time) - { - self.wait = time + 5; - FOR_EACH_REALPLAYER(e) - { - if(SAME_TEAM(e, self)) + if(!this.isshielded && this.wait < time) + { + this.wait = time + 5; + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { + if(SAME_TEAM(it, this)) { - Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM); - soundto(MSG_ONE, e, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound? - } + Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM); + soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound? + } else - Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_)); - } - } + Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED)); + }); + } } } -void ons_GeneratorReset() -{SELFPARAM(); - self.team = self.team_saved; - self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health; - self.takedamage = DAMAGE_AIM; - self.bot_attack = true; - self.iscaptured = true; - self.islinked = true; - self.isshielded = true; - self.event_damage = ons_GeneratorDamage; - self.think = ons_GeneratorThink; - self.nextthink = time + GEN_THINKRATE; - - Net_LinkEntity(self, false, 0, generator_send); - - self.SendFlags = GSF_SETUP; // just incase - self.SendFlags |= GSF_STATUS; - - WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health); - WaypointSprite_UpdateHealth(self.sprite, self.health); - WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY); +void ons_GeneratorReset(entity this) +{ + this.team = this.team_saved; + this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health; + this.takedamage = DAMAGE_AIM; + this.bot_attack = true; + this.iscaptured = true; + this.islinked = true; + this.isshielded = true; + this.event_damage = ons_GeneratorDamage; + setthink(this, ons_GeneratorThink); + this.nextthink = time + GEN_THINKRATE; + + Net_LinkEntity(this, false, 0, generator_send); + + this.SendFlags = GSF_SETUP; // just incase + this.SendFlags |= GSF_STATUS; + + WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health); + WaypointSprite_UpdateHealth(this.sprite, this.health); + WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY); onslaught_updatelinks(); } -void ons_DelayedGeneratorSetup() -{SELFPARAM(); +void ons_DelayedGeneratorSetup(entity this) +{ // 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; // captureshield setup - ons_CaptureShield_Spawn(self, true); + ons_CaptureShield_Spawn(this, true); onslaught_updatelinks(); - Net_LinkEntity(self, false, 0, generator_send); + Net_LinkEntity(this, false, 0, generator_send); } -void onslaught_generator_touch() -{SELFPARAM(); +void onslaught_generator_touch(entity this) +{ if ( IS_PLAYER(other) ) - if ( SAME_TEAM(self,other) ) - if ( self.iscaptured ) + if ( SAME_TEAM(this,other) ) + if ( this.iscaptured ) { Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT); } } void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc -{SELFPARAM(); +{ // declarations int teamnumber = gen.team; - setself(gen); // for later usage with droptofloor() // main setup gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist @@ -1147,12 +1110,12 @@ void ons_GeneratorSetup(entity gen) // called when spawning a generator entity o gen.bot_attack = true; gen.event_damage = ons_GeneratorDamage; gen.reset = ons_GeneratorReset; - gen.think = ons_GeneratorThink; + setthink(gen, ons_GeneratorThink); gen.nextthink = time + GEN_THINKRATE; gen.iscaptured = true; gen.islinked = true; gen.isshielded = true; - gen.touch = onslaught_generator_touch; + settouch(gen, onslaught_generator_touch); // appearence // model handled by CSQC @@ -1161,14 +1124,13 @@ void ons_GeneratorSetup(entity gen) // called when spawning a generator entity o gen.colormap = 1024 + (teamnumber - 1) * 17; // generator placement - setself(gen); - droptofloor(); + droptofloor(gen); // waypointsprites - WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE); - WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY); - WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health); - WaypointSprite_UpdateHealth(self.sprite, self.health); + WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE); + WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY); + WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health); + WaypointSprite_UpdateHealth(gen.sprite, gen.health); InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION); } @@ -1224,16 +1186,14 @@ void nades_Clear(entity e); #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1) bool Onslaught_CheckWinner() { - entity e; - if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)) { ons_stalemate = true; if (!wpforenemy_announced) { - Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); - sound(world, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE); + Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); + sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE); wpforenemy_announced = true; } @@ -1245,6 +1205,7 @@ bool Onslaught_CheckWinner() // tmp_entity.max_health / 300 gives 5 minutes of overtime. // control points reduce the overtime duration. d = 1; + entity e; for(e = ons_worldcplist; e; e = e.ons_worldcpnext) { if(DIFF_TEAM(e, tmp_entity)) @@ -1275,14 +1236,14 @@ bool Onslaught_CheckWinner() if(winner_team > 0) { - Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_)); - Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_)); + Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN)); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN)); TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1); } else if(winner_team == -1) { - Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED); - Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED); + Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED); + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED); } ons_stalemate = false; @@ -1291,13 +1252,12 @@ bool Onslaught_CheckWinner() round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit); - FOR_EACH_PLAYER(e) - { - e.ons_roundlost = true; - e.player_blocked = true; + FOREACH_CLIENT(IS_PLAYER(it), { + it.ons_roundlost = true; + it.player_blocked = true; - nades_Clear(e); - } + nades_Clear(it); + }); return 1; } @@ -1310,7 +1270,7 @@ bool Onslaught_CheckPlayers() void Onslaught_RoundStart() { entity tmp_entity; - FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; } + FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false); for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext) tmp_entity.sprite.SendFlags |= 16; @@ -1326,26 +1286,23 @@ void Onslaught_RoundStart() // NOTE: LEGACY CODE, needs to be re-written! -void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius) -{SELFPARAM(); +void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius) +{ entity head; float t, c; - int i; bool needarmor = false, needweapons = false; // Needs armor/health? - if(self.health<100) + if(this.health<100) needarmor = true; // Needs weapons? c = 0; - for(i = WEP_FIRST; i <= WEP_LAST ; ++i) - { - // Find weapon - if(self.weapons & WepSet_FromWeapon(i)) - if(++c>=4) + FOREACH(Weapons, it != WEP_Null, { + if(this.weapons & (it.m_wepset)) + if(++c >= 4) break; - } + }); if(c<4) needweapons = true; @@ -1353,8 +1310,8 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s if(!needweapons && !needarmor) return; - ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n")); - ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n")); + LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n")); + LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n")); // See what is around head = findchainfloat(bot_pickup, true); @@ -1363,59 +1320,46 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s // gather health and armor only if (head.solid) if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) ) - if (vlen(head.origin - org) < sradius) + if (vdist(head.origin - org, <, sradius)) { - t = head.bot_pickupevalfunc(self, head); + t = head.bot_pickupevalfunc(this, head); if (t > 0) - navigation_routerating(head, t * ratingscale, 500); + navigation_routerating(this, head, t * ratingscale, 500); } head = head.chain; } } -void havocbot_role_ons_setrole(entity bot, int role) +void havocbot_role_ons_setrole(entity this, int role) { - ons_debug(strcat(bot.netname," switched to ")); + LOG_DEBUG(strcat(this.netname," switched to ")); switch(role) { case HAVOCBOT_ONS_ROLE_DEFENSE: - ons_debug("defense"); - bot.havocbot_role = havocbot_role_ons_defense; - bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE; - bot.havocbot_role_timeout = 0; + LOG_DEBUG("defense"); + this.havocbot_role = havocbot_role_ons_defense; + this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE; + this.havocbot_role_timeout = 0; break; case HAVOCBOT_ONS_ROLE_ASSISTANT: - ons_debug("assistant"); - bot.havocbot_role = havocbot_role_ons_assistant; - bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT; - bot.havocbot_role_timeout = 0; + LOG_DEBUG("assistant"); + this.havocbot_role = havocbot_role_ons_assistant; + this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT; + this.havocbot_role_timeout = 0; break; case HAVOCBOT_ONS_ROLE_OFFENSE: - ons_debug("offense"); - bot.havocbot_role = havocbot_role_ons_offense; - bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE; - bot.havocbot_role_timeout = 0; + LOG_DEBUG("offense"); + this.havocbot_role = havocbot_role_ons_offense; + this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE; + this.havocbot_role_timeout = 0; break; } - ons_debug("\n"); + LOG_DEBUG("\n"); } -int havocbot_ons_teamcount(entity bot, int role) -{SELFPARAM(); - int c = 0; - entity head; - - FOR_EACH_PLAYER(head) - if(SAME_TEAM(head, self)) - if(head.havocbot_role_flags & role) - ++c; - - return c; -} - -void havocbot_goalrating_ons_controlpoints_attack(float ratingscale) -{SELFPARAM(); - entity cp, cp1, cp2, best, pl, wp; +void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale) +{ + entity cp, cp1, cp2, best, wp; float radius, bestvalue; int c; bool found; @@ -1430,16 +1374,17 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale) continue; // Ignore owned controlpoints - if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team])) + if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team])) continue; // Count team mates interested in this control point // (easier and cleaner than keeping counters per cp and teams) - FOR_EACH_PLAYER(pl) - if(SAME_TEAM(pl, self)) - if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE) - if(pl.havocbot_ons_target==cp2) - ++c; + FOREACH_CLIENT(IS_PLAYER(it), { + if(SAME_TEAM(it, this)) + if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE) + if(it.havocbot_ons_target == cp2) + ++c; + }); // NOTE: probably decrease the cost of attackable control points cp2.wpcost = c; @@ -1448,7 +1393,7 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale) // We'll consider only the best case bestvalue = 99999999999; - cp = world; + cp = NULL; for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext) { if (!cp1.wpconsidered) @@ -1458,21 +1403,21 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale) { bestvalue = cp1.wpcost; cp = cp1; - self.havocbot_ons_target = cp1; + this.havocbot_ons_target = cp1; } } if (!cp) return; - ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n")); + LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n")); if(cp.goalentity) { // Should be attacked // Rate waypoints near it found = false; - best = world; + best = NULL; bestvalue = 99999999999; for(radius=0; radius<1000 && !found; radius+=500) { @@ -1494,24 +1439,24 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale) if(best) { - navigation_routerating(best, ratingscale, 10000); + navigation_routerating(this, best, ratingscale, 10000); best.cnt += 1; - self.havocbot_attack_time = 0; - if(checkpvs(self.view_ofs,cp)) - if(checkpvs(self.view_ofs,best)) - self.havocbot_attack_time = time + 2; + this.havocbot_attack_time = 0; + if(checkpvs(this.view_ofs,cp)) + if(checkpvs(this.view_ofs,best)) + this.havocbot_attack_time = time + 2; } else { - navigation_routerating(cp, ratingscale, 10000); + navigation_routerating(this, cp, ratingscale, 10000); } - ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n")); + LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n")); } else { // Should be touched - ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n")); + LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n")); found = false; // Look for auto generated waypoint @@ -1520,32 +1465,32 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale) { if(wp.classname=="waypoint") { - navigation_routerating(wp, ratingscale, 10000); + navigation_routerating(this, wp, ratingscale, 10000); found = true; } } // Nothing found, rate the controlpoint itself if (!found) - navigation_routerating(cp, ratingscale, 10000); + navigation_routerating(this, cp, ratingscale, 10000); } } -bool havocbot_goalrating_ons_generator_attack(float ratingscale) -{SELFPARAM(); +bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale) +{ entity g, wp, bestwp; bool found; int best; for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext) { - if(SAME_TEAM(g, self) || g.isshielded) + if(SAME_TEAM(g, this) || g.isshielded) continue; // Should be attacked // Rate waypoints near it found = false; - bestwp = world; + bestwp = NULL; best = 99999999999; for(wp=findradius(g.origin,400); wp; wp=wp.chain) @@ -1564,99 +1509,84 @@ bool havocbot_goalrating_ons_generator_attack(float ratingscale) if(bestwp) { - ons_debug("waypoints found around generator\n"); - navigation_routerating(bestwp, ratingscale, 10000); + LOG_DEBUG("waypoints found around generator\n"); + navigation_routerating(this, bestwp, ratingscale, 10000); bestwp.cnt += 1; - self.havocbot_attack_time = 0; - if(checkpvs(self.view_ofs,g)) - if(checkpvs(self.view_ofs,bestwp)) - self.havocbot_attack_time = time + 5; + this.havocbot_attack_time = 0; + if(checkpvs(this.view_ofs,g)) + if(checkpvs(this.view_ofs,bestwp)) + this.havocbot_attack_time = time + 5; return true; } else { - ons_debug("generator found without waypoints around\n"); + LOG_DEBUG("generator found without waypoints around\n"); // if there aren't waypoints near the generator go straight to it - navigation_routerating(g, ratingscale, 10000); - self.havocbot_attack_time = 0; + navigation_routerating(this, g, ratingscale, 10000); + this.havocbot_attack_time = 0; return true; } } return false; } -void havocbot_role_ons_offense() -{SELFPARAM(); - if(self.deadflag != DEAD_NO) +void havocbot_role_ons_offense(entity this) +{ + if(IS_DEAD(this)) { - self.havocbot_attack_time = 0; - havocbot_ons_reset_role(self); + this.havocbot_attack_time = 0; + havocbot_ons_reset_role(this); 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_ons_reset_role(self); + havocbot_ons_reset_role(this); return; } - if(self.havocbot_attack_time>time) + if(this.havocbot_attack_time>time) return; - if (self.bot_strategytime < time) + if (this.bot_strategytime < time) { - navigation_goalrating_start(); - havocbot_goalrating_enemyplayers(20000, self.origin, 650); - if(!havocbot_goalrating_ons_generator_attack(20000)) - havocbot_goalrating_ons_controlpoints_attack(20000); - havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000); - navigation_goalrating_end(); + navigation_goalrating_start(this); + havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650); + if(!havocbot_goalrating_ons_generator_attack(this, 20000)) + havocbot_goalrating_ons_controlpoints_attack(this, 20000); + havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000); + navigation_goalrating_end(this); - self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; + this.bot_strategytime = time + autocvar_bot_ai_strategyinterval; } } -void havocbot_role_ons_assistant() -{SELFPARAM(); - havocbot_ons_reset_role(self); +void havocbot_role_ons_assistant(entity this) +{ + havocbot_ons_reset_role(this); } -void havocbot_role_ons_defense() -{SELFPARAM(); - havocbot_ons_reset_role(self); +void havocbot_role_ons_defense(entity this) +{ + havocbot_ons_reset_role(this); } -void havocbot_ons_reset_role(entity bot) -{SELFPARAM(); - entity head; - int c = 0; - - if(self.deadflag != DEAD_NO) +void havocbot_ons_reset_role(entity this) +{ + if(IS_DEAD(this)) return; - bot.havocbot_ons_target = world; + this.havocbot_ons_target = NULL; // TODO: Defend control points or generator if necessary - // if there is only me on the team switch to offense - c = 0; - FOR_EACH_PLAYER(head) - if(SAME_TEAM(head, self)) - ++c; - - if(c==1) - { - havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE); - return; - } - - havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE); + havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE); } @@ -1664,25 +1594,25 @@ void havocbot_ons_reset_role(entity bot) * Find control point or generator owned by the same team self which is nearest to pos * if max_dist is positive, only control points within this range will be considered */ -entity ons_Nearest_ControlPoint(vector pos, float max_dist) -{SELFPARAM(); - entity tmp_entity, closest_target = world; +entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist) +{ + entity tmp_entity, closest_target = NULL; tmp_entity = findchain(classname, "onslaught_controlpoint"); while(tmp_entity) { - if(SAME_TEAM(tmp_entity, self)) + if(SAME_TEAM(tmp_entity, this)) if(tmp_entity.iscaptured) - if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist) - if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world) + if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist)) + if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL) closest_target = tmp_entity; tmp_entity = tmp_entity.chain; } tmp_entity = findchain(classname, "onslaught_generator"); while(tmp_entity) { - if(SAME_TEAM(tmp_entity, self)) - if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist) - if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world) + if(SAME_TEAM(tmp_entity, this)) + if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist)) + if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL) closest_target = tmp_entity; tmp_entity = tmp_entity.chain; } @@ -1695,9 +1625,9 @@ entity ons_Nearest_ControlPoint(vector pos, float max_dist) * if max_dist is positive, only control points within this range will be considered * This function only check distances on the XY plane, disregarding Z */ -entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist) -{SELFPARAM(); - entity tmp_entity, closest_target = world; +entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist) +{ + entity tmp_entity, closest_target = NULL; vector delta; float smallest_distance = 0, distance; @@ -1708,10 +1638,10 @@ entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist) delta_z = 0; distance = vlen(delta); - if(SAME_TEAM(tmp_entity, self)) + if(SAME_TEAM(tmp_entity, this)) if(tmp_entity.iscaptured) if(max_dist <= 0 || distance <= max_dist) - if(closest_target == world || distance <= smallest_distance ) + if(closest_target == NULL || distance <= smallest_distance ) { closest_target = tmp_entity; smallest_distance = distance; @@ -1726,9 +1656,9 @@ entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist) delta_z = 0; distance = vlen(delta); - if(SAME_TEAM(tmp_entity, self)) + if(SAME_TEAM(tmp_entity, this)) if(max_dist <= 0 || distance <= max_dist) - if(closest_target == world || distance <= smallest_distance ) + if(closest_target == NULL || distance <= smallest_distance ) { closest_target = tmp_entity; smallest_distance = distance; @@ -1740,16 +1670,16 @@ entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist) return closest_target; } /** - * find the number of control points and generators in the same team as self + * find the number of control points and generators in the same team as this */ -int ons_Count_SelfControlPoints() -{SELFPARAM(); +int ons_Count_SelfControlPoints(entity this) +{ entity tmp_entity; tmp_entity = findchain(classname, "onslaught_controlpoint"); int n = 0; while(tmp_entity) { - if(SAME_TEAM(tmp_entity, self)) + if(SAME_TEAM(tmp_entity, this)) if(tmp_entity.iscaptured) n++; tmp_entity = tmp_entity.chain; @@ -1757,7 +1687,7 @@ int ons_Count_SelfControlPoints() tmp_entity = findchain(classname, "onslaught_generator"); while(tmp_entity) { - if(SAME_TEAM(tmp_entity, self)) + if(SAME_TEAM(tmp_entity, this)) n++; tmp_entity = tmp_entity.chain; } @@ -1791,10 +1721,10 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe loc += tele_target.origin + '0 0 128' * iteration_scale; - tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player); + tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player); if(trace_fraction == 1.0 && !trace_startsolid) { - traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world + traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL if(trace_fraction == 1.0 && !trace_startsolid) { if ( tele_effects ) @@ -1823,34 +1753,36 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe // ============== MUTATOR_HOOKFUNCTION(ons, reset_map_global) -{SELFPARAM(); - entity e; - FOR_EACH_PLAYER(e) - { - e.ons_roundlost = false; - e.ons_deathloc = '0 0 0'; - WITH(entity, self, e, PutClientInServer()); - } +{ + FOREACH_CLIENT(IS_PLAYER(it), { + it.ons_roundlost = false; + it.ons_deathloc = '0 0 0'; + WITHSELF(it, PutClientInServer()); + }); return false; } MUTATOR_HOOKFUNCTION(ons, ClientDisconnect) -{SELFPARAM(); - self.ons_deathloc = '0 0 0'; - return false; +{ + entity player = M_ARGV(0, entity); + + player.ons_deathloc = '0 0 0'; } MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver) -{SELFPARAM(); - self.ons_deathloc = '0 0 0'; - return false; +{ + entity player = M_ARGV(0, entity); + + player.ons_deathloc = '0 0 0'; } MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) -{SELFPARAM(); +{ + entity player = M_ARGV(0, entity); + if(!round_handler_IsRoundStarted()) { - self.player_blocked = true; + player.player_blocked = true; return false; } @@ -1864,13 +1796,13 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) l.sprite.SendFlags |= 16; } - if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); } + if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); } if ( autocvar_g_onslaught_spawn_choose ) - if ( self.ons_spawn_by ) - if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) ) + if ( player.ons_spawn_by ) + if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) ) { - self.ons_spawn_by = world; + player.ons_spawn_by = NULL; return false; } @@ -1878,8 +1810,8 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance) { float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random; - entity tmp_entity, closest_target = world; - vector spawn_loc = self.ons_deathloc; + entity tmp_entity, closest_target = NULL; + vector spawn_loc = player.ons_deathloc; // new joining player or round reset, don't bother checking if(spawn_loc == '0 0 0') { return false; } @@ -1888,10 +1820,10 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext) { - if(SAME_TEAM(tmp_entity, self)) + if(SAME_TEAM(tmp_entity, player)) if(random_target) RandomSelection_Add(tmp_entity, 0, string_null, 1, 1); - else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world) + else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL) closest_target = tmp_entity; } @@ -1907,14 +1839,14 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) iteration_scale -= i / 10; loc = closest_target.origin + '0 0 96' * iteration_scale; loc += ('0 1 0' * random()) * 128 * iteration_scale; - tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self); + tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player); if(trace_fraction == 1.0 && !trace_startsolid) { - traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world + traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL if(trace_fraction == 1.0 && !trace_startsolid) { - setorigin(self, loc); - self.angles = normalize(loc - closest_target.origin) * RAD2DEG; + setorigin(player, loc); + player.angles = normalize(loc - closest_target.origin) * RAD2DEG; return false; } } @@ -1926,8 +1858,8 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) if(random() <= autocvar_g_onslaught_spawn_at_generator_chance) { float random_target = autocvar_g_onslaught_spawn_at_generator_random; - entity tmp_entity, closest_target = world; - vector spawn_loc = self.ons_deathloc; + entity tmp_entity, closest_target = NULL; + vector spawn_loc = player.ons_deathloc; // new joining player or round reset, don't bother checking if(spawn_loc == '0 0 0') { return false; } @@ -1940,8 +1872,8 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) RandomSelection_Add(tmp_entity, 0, string_null, 1, 1); else { - if(SAME_TEAM(tmp_entity, self)) - if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world) + if(SAME_TEAM(tmp_entity, player)) + if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL) closest_target = tmp_entity; } } @@ -1958,14 +1890,14 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) iteration_scale -= i / 10; loc = closest_target.origin + '0 0 128' * iteration_scale; loc += ('0 1 0' * random()) * 256 * iteration_scale; - tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self); + tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player); if(trace_fraction == 1.0 && !trace_startsolid) { - traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world + traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL if(trace_fraction == 1.0 && !trace_startsolid) { - setorigin(self, loc); - self.angles = normalize(loc - closest_target.origin) * RAD2DEG; + setorigin(player, loc); + player.angles = normalize(loc - closest_target.origin) * RAD2DEG; return false; } } @@ -1973,11 +1905,13 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn) } } - return false; + return false; } MUTATOR_HOOKFUNCTION(ons, PlayerDies) -{SELFPARAM(); +{ + entity frag_target = M_ARGV(2, entity); + frag_target.ons_deathloc = frag_target.origin; entity l; for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext) @@ -1990,85 +1924,87 @@ MUTATOR_HOOKFUNCTION(ons, PlayerDies) } if ( autocvar_g_onslaught_spawn_choose ) - if ( ons_Count_SelfControlPoints() > 1 ) - stuffcmd(self, "qc_cmd_cl hud clickradar\n"); + if ( ons_Count_SelfControlPoints(frag_target) > 1 ) + stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n"); return false; } MUTATOR_HOOKFUNCTION(ons, MonsterMove) -{SELFPARAM(); - entity e = find(world, targetname, self.target); - if (e != world) - self.team = e.team; +{ + entity mon = M_ARGV(0, entity); - return false; + entity e = find(NULL, targetname, mon.target); + if (e != NULL) + mon.team = e.team; } -void ons_MonsterSpawn_Delayed() -{SELFPARAM(); - entity e, own = self.owner; +void ons_MonsterSpawn_Delayed(entity this) +{ + entity own = this.owner; - if(!own) { remove(self); return; } + if(!own) { remove(this); return; } if(own.targetname) { - e = find(world, target, own.targetname); - if(e != world) + entity e = find(NULL, target, own.targetname); + if(e != NULL) { own.team = e.team; - activator = e; - own.use(); + own.use(own, e, NULL); } } - remove(self); + remove(this); } MUTATOR_HOOKFUNCTION(ons, MonsterSpawn) -{SELFPARAM(); +{ + entity mon = M_ARGV(0, entity); + entity e = spawn(); - e.owner = self; + e.owner = mon; InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET); - - return false; } -void ons_TurretSpawn_Delayed() -{SELFPARAM(); - entity e, own = self.owner; +void ons_TurretSpawn_Delayed(entity this) +{ + entity own = this.owner; - if(!own) { remove(self); return; } + if(!own) { remove(this); return; } if(own.targetname) { - e = find(world, target, own.targetname); - if(e != world) + entity e = find(NULL, target, own.targetname); + if(e != NULL) { own.team = e.team; own.active = ACTIVE_NOT; - activator = e; - own.use(); + own.use(own, e, NULL); } } - remove(self); + remove(this); } MUTATOR_HOOKFUNCTION(ons, TurretSpawn) -{SELFPARAM(); +{ + entity turret = M_ARGV(0, entity); + entity e = spawn(); - e.owner = self; + e.owner = turret; InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET); return false; } MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole) -{SELFPARAM(); - havocbot_ons_reset_role(self); +{ + entity bot = M_ARGV(0, entity); + + havocbot_ons_reset_role(bot); return true; } @@ -2090,19 +2026,25 @@ MUTATOR_HOOKFUNCTION(ons, GetTeamCount) } MUTATOR_HOOKFUNCTION(ons, SpectateCopy) -{SELFPARAM(); - self.ons_roundlost = other.ons_roundlost; // make spectators see it too - return false; +{ + entity spectatee = M_ARGV(0, entity); + entity client = M_ARGV(1, entity); + + client.ons_roundlost = spectatee.ons_roundlost; // make spectators see it too } MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand) -{SELFPARAM(); +{ if(MUTATOR_RETURNVALUE) // command was already handled? return false; + entity player = M_ARGV(0, entity); + string cmd_name = M_ARGV(1, string); + int cmd_argc = M_ARGV(2, int); + if ( cmd_name == "ons_spawn" ) { - vector pos = self.origin; + vector pos = player.origin; if(cmd_argc > 1) pos_x = stof(argv(1)); if(cmd_argc > 2) @@ -2110,105 +2052,114 @@ MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand) if(cmd_argc > 3) pos_z = stof(argv(3)); - if ( IS_PLAYER(self) ) + if ( IS_PLAYER(player) ) { - if ( !self.frozen ) + if ( !STAT(FROZEN, player) ) { - entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius); + entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius); - if ( !source_point && self.health > 0 ) + if ( !source_point && player.health > 0 ) { - sprint(self, "\nYou need to be next to a control point\n"); - return 1; + sprint(player, "\nYou need to be next to a control point\n"); + return true; } - entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius); + entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius); - if ( closest_target == world ) + if ( closest_target == NULL ) { - sprint(self, "\nNo control point found\n"); - return 1; + sprint(player, "\nNo control point found\n"); + return true; } - if ( self.health <= 0 ) + if ( player.health <= 0 ) { - self.ons_spawn_by = closest_target; - self.respawn_flags = self.respawn_flags | RESPAWN_FORCE; + player.ons_spawn_by = closest_target; + player.respawn_flags = player.respawn_flags | RESPAWN_FORCE; } else { if ( source_point == closest_target ) { - sprint(self, "\nTeleporting to the same point\n"); - return 1; + sprint(player, "\nTeleporting to the same point\n"); + return true; } - if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) ) - sprint(self, "\nUnable to teleport there\n"); + if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) ) + sprint(player, "\nUnable to teleport there\n"); } - return 1; + return true; } - sprint(self, "\nNo teleportation for you\n"); + sprint(player, "\nNo teleportation for you\n"); } - return 1; + return true; } - return 0; + return false; } MUTATOR_HOOKFUNCTION(ons, PlayerUseKey) -{SELFPARAM(); +{ if(MUTATOR_RETURNVALUE || gameover) { return false; } - if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle) + entity player = M_ARGV(0, entity); + + if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle) { - entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius); + entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius); if ( source_point ) { - stuffcmd(self, "qc_cmd_cl hud clickradar\n"); + stuffcmd(player, "qc_cmd_cl hud clickradar\n"); return true; } } - - return false; } MUTATOR_HOOKFUNCTION(ons, PlayHitsound) { + entity frag_victim = M_ARGV(0, entity); + return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded) || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded); } MUTATOR_HOOKFUNCTION(ons, SendWaypoint) { - if(wp_sendflags & 16) + entity wp = M_ARGV(0, entity); + entity to = M_ARGV(1, entity); + int sf = M_ARGV(2, int); + int wp_flag = M_ARGV(3, int); + + if(sf & 16) { - if(self.owner.classname == "onslaught_controlpoint") + if(wp.owner.classname == "onslaught_controlpoint") { - entity wp_owner = self.owner; - entity e = WaypointSprite_getviewentity(wp_sendto); + entity wp_owner = wp.owner; + entity e = WaypointSprite_getviewentity(to); if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; } if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; } } - if(self.owner.classname == "onslaught_generator") + if(wp.owner.classname == "onslaught_generator") { - entity wp_owner = self.owner; + entity wp_owner = wp.owner; if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; } if(wp_owner.health <= 0) { wp_flag |= 2; } } } - return false; + M_ARGV(3, int) = wp_flag; } MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget) { + entity turret_target = M_ARGV(1, entity); + if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job! { - ret_float = -3; + M_ARGV(3, float) = -3; return true; } @@ -2217,18 +2168,18 @@ MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget) MUTATOR_HOOKFUNCTION(ons, TurretThink) { + entity turret = M_ARGV(0, entity); + // ONS uses somewhat backwards linking. - if(self.target) + if(turret.target) { - entity e = find(world, targetname, self.target); - if (e != world) - self.team = e.team; + entity e = find(NULL, targetname, turret.target); + if (e != NULL) + turret.team = e.team; } - if(self.team != self.tur_head.team) - turret_respawn(); - - return false; + if(turret.team != turret.tur_head.team) + turret_respawn(turret); } @@ -2247,16 +2198,16 @@ keys: */ spawnfunc(onslaught_link) { - if(!g_onslaught) { remove(self); return; } + if(!g_onslaught) { remove(this); return; } - if (self.target == "" || self.target2 == "") - objerror("target and target2 must be set\n"); + if (this.target == "" || this.target2 == "") + objerror(this, "target and target2 must be set\n"); - self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist - ons_worldlinklist = self; + this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist + ons_worldlinklist = this; - InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET); - Net_LinkEntity(self, false, 0, ons_Link_Send); + InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET); + Net_LinkEntity(this, false, 0, ons_Link_Send); } /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128) @@ -2272,9 +2223,9 @@ keys: spawnfunc(onslaught_controlpoint) { - if(!g_onslaught) { remove(self); return; } + if(!g_onslaught) { remove(this); return; } - ons_ControlPoint_Setup(self); + ons_ControlPoint_Setup(this); } /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64) @@ -2288,24 +2239,24 @@ keys: */ spawnfunc(onslaught_generator) { - if(!g_onslaught) { remove(self); return; } - if(!self.team) { objerror("team must be set"); } + if(!g_onslaught) { remove(this); return; } + if(!this.team) { objerror(this, "team must be set"); } - ons_GeneratorSetup(self); + ons_GeneratorSetup(this); } // scoreboard setup void ons_ScoreRules() { - CheckAllowedTeams(world); + CheckAllowedTeams(NULL); ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true); ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY); - ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); + ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY); ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0); ScoreRules_basics_end(); } -void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up +void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up { ons_ScoreRules(); @@ -2318,9 +2269,7 @@ void ons_Initialize() g_onslaught = true; ons_captureshield_force = autocvar_g_onslaught_shield_force; - addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost); - - InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE); + InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE); } #endif