+#include "gamemode_keyhunt.qh"
#ifndef GAMEMODE_KEYHUNT_H
#define GAMEMODE_KEYHUNT_H
.entity kh_next;
float kh_Key_AllOwnedByWhichTeam();
-typedef void(void) kh_Think_t;
+typedef void() kh_Think_t;
void kh_StartRound();
void kh_Controller_SetThink(float t, kh_Think_t func);
// bits 5- 9: team of key 2, or 0 for no such key, or 30 for dropped, or 31 for self
// bits 10-14: team of key 3, or 0 for no such key, or 30 for dropped, or 31 for self
// bits 15-19: team of key 4, or 0 for no such key, or 30 for dropped, or 31 for self
-.float kh_state;
+.float kh_state = _STAT(KH_KEYS);
.float siren_time; // time delay the siren
//.float stuff_time; // time delay to stuffcmd a cvar
float kh_KeyCarrier_waypointsprite_visible_for_player(entity e) // runs all the time
{SELFPARAM();
- if(!IS_PLAYER(e) || self.team != e.team)
+ if(!IS_PLAYER(e) || DIFF_TEAM(self, e))
if(!kh_tracking_enabled)
return false;
void kh_update_state()
{
- entity player;
entity key;
float s;
float f;
s |= pow(32, key.count) * f;
}
- FOR_EACH_CLIENT(player)
- {
- player.kh_state = s;
- }
+ FOREACH_CLIENT(true, LAMBDA(it.kh_state = s));
FOR_EACH_KH_KEY(key)
{
}
// in any case:
setattachment(key, world, "");
- setorigin(key, key.owner.origin + '0 0 1' * (PL_MIN.z - KH_KEY_MIN_z));
+ setorigin(key, key.owner.origin + '0 0 1' * (STAT(PL_MIN, NULL).z - KH_KEY_MIN_z));
key.angles = key.owner.angles;
#else
setorigin(key, key.owner.origin + key.origin.z * '0 0 1');
}
}
-void kh_Key_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
-{SELFPARAM();
- if(self.owner)
+void kh_Key_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{
+ if(this.owner)
return;
if(ITEM_DAMAGE_NEEDKILL(deathtype))
{
}
if(vlen(force) <= 0)
return;
- if(time > self.pushltime)
+ if(time > this.pushltime)
if(IS_PLAYER(attacker))
- self.team = attacker.team;
+ this.team = attacker.team;
}
void kh_Key_Collect(entity key, entity player) //a player picks up a dropped key
PlayerScore_Add(player, SP_KH_PICKUPS, 1);
}
key.kh_dropperteam = 0;
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(key, INFO_KEYHUNT_PICKUP_), player.netname);
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_PICKUP), player.netname);
kh_Key_AssignTo(key, player); // this also updates .kh_state
}
if (!IS_PLAYER(other))
return;
- if(other.deadflag != DEAD_NO)
+ if(IS_DEAD(other))
return;
if(other == self.enemy)
if(time < self.kh_droptime + autocvar_g_balance_keyhunt_delay_collect)
first = false;
}
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(teem, INFO_KEYHUNT_CAPTURE_), keyowner);
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(teem, INFO_KEYHUNT_CAPTURE), keyowner);
first = true;
midpoint = '0 0 0';
void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a flag carrier off the map
{
- entity player, key, attacker;
+ entity key, attacker;
float players;
float keys;
float f;
float of, fragsleft, i, j, thisteam;
of = autocvar_g_balance_keyhunt_score_destroyed_ownfactor;
- FOR_EACH_PLAYER(player)
- if(player.team != teem)
- ++players;
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team != teem, LAMBDA(++players));
FOR_EACH_KH_KEY(key)
if(key.owner && key.team != teem)
continue;
players = 0;
- FOR_EACH_PLAYER(player)
- if(player.team == thisteam)
- ++players;
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, LAMBDA(++players));
DistributeEvenly_Init(fragsleft, j);
fragsleft = DistributeEvenly_Get(j - 1);
DistributeEvenly_Init(DistributeEvenly_Get(1), players);
- FOR_EACH_PLAYER(player)
- if(player.team == thisteam)
- {
- f = DistributeEvenly_Get(1);
- kh_Scores_Event(player, world, "destroyed", f, 0);
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, LAMBDA(
+ f = DistributeEvenly_Get(1);
+ kh_Scores_Event(it, world, "destroyed", f, 0);
+ ));
--j;
}
}
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(lostkey, INFO_KEYHUNT_LOST_), lostkey.kh_previous_owner.netname);
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(lostkey, INFO_KEYHUNT_LOST), lostkey.kh_previous_owner.netname);
play2all(SND(KH_DESTROY));
te_tarexplosion(lostkey.origin);
void kh_Key_Think() // runs all the time
{SELFPARAM();
- entity head;
- //entity player; // needed by FOR_EACH_PLAYER
-
if(intermission_running)
return;
if(kh_interferemsg_time && time > kh_interferemsg_time)
{
kh_interferemsg_time = 0;
- FOR_EACH_PLAYER(head)
- {
- if(head.team == kh_interferemsg_team)
- if(head.kh_next)
- Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_KEYHUNT_MEET);
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(it.team == kh_interferemsg_team)
+ if(it.kh_next)
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_KEYHUNT_MEET);
else
- Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_KEYHUNT_HELP);
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_KEYHUNT_HELP);
else
- Send_Notification(NOTIF_ONE, head, MSG_CENTER, APP_TEAM_NUM_4(kh_interferemsg_team, CENTER_KEYHUNT_INTERFERE_));
- }
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(kh_interferemsg_team, CENTER_KEYHUNT_INTERFERE));
+ ));
}
self.nextthink = time + 0.05;
}
-void key_reset()
-{SELFPARAM();
- kh_Key_AssignTo(self, world);
- kh_Key_Remove(self);
+void key_reset(entity this)
+{
+ kh_Key_AssignTo(this, world);
+ kh_Key_Remove(this);
}
const string STR_ITEM_KH_KEY = "item_kh_key";
-void kh_Key_Spawn(entity initial_owner, float angle, float i) // runs every time a new flag is created, ie after all the keys have been collected
+void kh_Key_Spawn(entity initial_owner, float _angle, float i) // runs every time a new flag is created, ie after all the keys have been collected
{
entity key = spawn();
key.count = i;
key.think = kh_Key_Think;
key.nextthink = time;
key.items = IT_KEY1 | IT_KEY2;
- key.cnt = angle;
+ key.cnt = _angle;
key.angles = '0 360 0' * random();
key.event_damage = kh_Key_Damage;
key.takedamage = DAMAGE_YES;
key.kh_worldkeynext = kh_worldkeylist;
kh_worldkeylist = key;
- Send_Notification(NOTIF_ONE, initial_owner, MSG_CENTER, APP_TEAM_NUM_4(initial_owner.team, CENTER_KEYHUNT_START_));
+ Send_Notification(NOTIF_ONE, initial_owner, MSG_CENTER, APP_TEAM_NUM(initial_owner.team, CENTER_KEYHUNT_START));
WaypointSprite_Spawn(WP_KeyDropped, 0, 0, key, '0 0 1' * KH_KEY_WP_ZSHIFT, world, key.team, key, waypointsprite_attachedforcarrier, false, RADARICON_FLAG);
key.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = kh_Key_waypointsprite_visible_for_player;
kh_Scores_Event(player, key, "dropkey", 0, 0);
PlayerScore_Add(player, SP_KH_LOSSES, 1);
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(key, INFO_KEYHUNT_DROP_), player.netname);
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_DROP), player.netname);
kh_Key_AssignTo(key, world);
makevectors(player.v_angle);
{
kh_Scores_Event(player, key, "losekey", 0, 0);
PlayerScore_Add(player, SP_KH_LOSSES, 1);
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(key, INFO_KEYHUNT_LOST_), player.netname);
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_LOST), player.netname);
kh_Key_AssignTo(key, world);
makevectors('-1 0 0' * (45 + 45 * random()) + '0 360 0' * random());
key.velocity = W_CalculateProjectileVelocity(player.velocity, autocvar_g_balance_keyhunt_dropvelocity * v_forward, false);
{
float t_team = kh_Team_ByID(num);
float players = 0;
- entity tmp_player;
- FOR_EACH_PLAYER(tmp_player)
- if(tmp_player.deadflag == DEAD_NO)
- if(!tmp_player.BUTTON_CHAT)
- if(tmp_player.team == t_team)
- ++players;
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == t_team)
+ ++players;
+ ));
if (!players) { return t_team; }
}
if(KH_READY_TEAMS_OK())
{
if(prev_missing_teams_mask > 0)
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
prev_missing_teams_mask = -1;
Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, kh_StartRound);
if(player_count == 0)
{
if(prev_missing_teams_mask > 0)
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
prev_missing_teams_mask = -1;
}
else
{
- float missing_teams_mask = (!!p1) + (!!p2) * 2;
- if(kh_teams >= 3) missing_teams_mask += (!!p3) * 4;
- if(kh_teams >= 4) missing_teams_mask += (!!p4) * 8;
+ float missing_teams_mask = boolean(p1) + boolean(p2) * 2;
+ if(kh_teams >= 3) missing_teams_mask += boolean(p3) * 4;
+ if(kh_teams >= 4) missing_teams_mask += boolean(p4) * 8;
if(prev_missing_teams_mask != missing_teams_mask)
{
Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
void kh_EnableTrackingDevice() // runs after each round
{
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_KEYHUNT);
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_KEYHUNT_OTHER);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT_OTHER);
kh_tracking_enabled = true;
}
void kh_StartRound() // runs at the start of each round
{
float i, players, teem;
- entity player;
if(time < game_starttime)
{
return;
}
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_KEYHUNT);
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_KEYHUNT_OTHER);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT_OTHER);
for(i = 0; i < kh_teams; ++i)
{
teem = kh_Team_ByID(i);
players = 0;
entity my_player = world;
- FOR_EACH_PLAYER(player)
- if(player.deadflag == DEAD_NO)
- if(!player.BUTTON_CHAT)
- if(player.team == teem)
- {
- ++players;
- if(random() * players <= 1)
- my_player = player;
- }
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == teem)
+ {
+ ++players;
+ if(random() * players <= 1)
+ my_player = it;
+ }
+ ));
kh_Key_Spawn(my_player, 360 * i / kh_teams, i);
}
kh_controller.model = "";
kh_controller.modelindex = 0;
- addstat(STAT_KH_KEYS, AS_INT, kh_state);
-
kh_ScoreRules(kh_teams);
}
void havocbot_role_kh_carrier()
{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+ if(IS_DEAD(self))
return;
if (!(self.kh_next))
void havocbot_role_kh_defense()
{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+ if(IS_DEAD(self))
return;
if (self.kh_next)
void havocbot_role_kh_offense()
{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+ if(IS_DEAD(self))
return;
if (self.kh_next)
void havocbot_role_kh_freelancer()
{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+ if(IS_DEAD(self))
return;
if (self.kh_next)
}
MUTATOR_HOOKFUNCTION(kh, PlayerDies)
-{SELFPARAM();
- if(self == other)
- kh_Key_DropAll(self, true);
+{
+ if(frag_target == other)
+ kh_Key_DropAll(frag_target, true);
else if(IS_PLAYER(other))
- kh_Key_DropAll(self, false);
+ kh_Key_DropAll(frag_target, false);
else
- kh_Key_DropAll(self, true);
+ kh_Key_DropAll(frag_target, true);
return 0;
}
MUTATOR_HOOKFUNCTION(kh, HavocBot_ChooseRole)
{
- if(self.deadflag != DEAD_NO)
+ if(IS_DEAD(self))
return true;
float r = random() * 3;