+#include "gamemode_keyhunt.qh"
#ifndef GAMEMODE_KEYHUNT_H
#define GAMEMODE_KEYHUNT_H
kh_Initialize();
ActivateTeamplay();
- SetLimits(autocvar_g_keyhunt_point_limit, autocvar_g_keyhunt_point_leadlimit, -1, -1);
+ SetLimits(autocvar_g_keyhunt_point_limit, autocvar_g_keyhunt_point_leadlimit, autocvar_timelimit_override, -1);
if (autocvar_g_keyhunt_team_spawns)
have_team_spawns = -1; // request team spawns
}
.entity kh_next;
float kh_Key_AllOwnedByWhichTeam();
-typedef void(void) kh_Think_t;
+USING(kh_Think_t, void());
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
const float SP_KH_PICKUPS = 7;
const float SP_KH_KCKILLS = 8;
const float SP_KH_LOSSES = 9;
-void kh_ScoreRules(float teams)
+void kh_ScoreRules(int teams)
{
ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true);
ScoreInfo_SetLabel_TeamScore( ST_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
ScoreRules_basics_end();
}
-float kh_KeyCarrier_waypointsprite_visible_for_player(entity e) // runs all the time
-{SELFPARAM();
- if(!IS_PLAYER(e) || self.team != e.team)
+bool kh_KeyCarrier_waypointsprite_visible_for_player(entity this, entity player, entity view) // runs all the time
+{
+ if(!IS_PLAYER(view) || DIFF_TEAM(this, view))
if(!kh_tracking_enabled)
return false;
return true;
}
-float kh_Key_waypointsprite_visible_for_player(entity e) // ??
-{SELFPARAM();
+bool kh_Key_waypointsprite_visible_for_player(entity this, entity player, entity view)
+{
if(!kh_tracking_enabled)
return false;
- if(!self.owner)
+ if(!this.owner)
return true;
- if(!self.owner.owner)
+ if(!this.owner.owner)
return true;
return false; // draw only when key is not owned
}
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)
{
if(key.owner)
key.owner.kh_state |= pow(32, key.count) * 31;
}
- //print(ftos((nextent(world)).kh_state), "\n");
+ //print(ftos((nextent(NULL)).kh_state), "\n");
}
kh_controller.nextthink = time; // force
}
void kh_WaitForPlayers();
-void kh_Controller_Think() // called a lot
-{SELFPARAM();
+void kh_Controller_Think(entity this) // called a lot
+{
if(intermission_running)
return;
- if(self.cnt > 0)
- { if(self.think != kh_WaitForPlayers) { self.cnt -= 1; } }
- else if(self.cnt == 0)
+ if(this.cnt > 0)
+ { if(getthink(this) != kh_WaitForPlayers) { this.cnt -= 1; } }
+ else if(this.cnt == 0)
{
- self.cnt -= 1;
+ this.cnt -= 1;
kh_Controller_Thinkfunc();
}
- self.nextthink = time + 1;
+ this.nextthink = time + 1;
}
// frags f: take from cvar * f
#endif
key.flags = 0;
key.solid = SOLID_NOT;
- key.movetype = MOVETYPE_NONE;
+ set_movetype(key, MOVETYPE_NONE);
key.team = key.owner.team;
key.nextthink = time;
key.damageforcescale = 0;
setorigin(first, first.origin + 0.5 * KH_PLAYER_ATTACHMENT_DIST);
}
// in any case:
- setattachment(key, world, "");
- setorigin(key, key.owner.origin + '0 0 1' * (PL_MIN.z - KH_KEY_MIN_z));
+ setattachment(key, NULL, "");
+ 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');
- setattachment(key, world, "");
+ setattachment(key, NULL, "");
key.angles_y += key.owner.angles.y;
#endif
key.flags = FL_ITEM;
key.solid = SOLID_TRIGGER;
- key.movetype = MOVETYPE_TOSS;
+ set_movetype(key, MOVETYPE_TOSS);
key.pain_finished = time + autocvar_g_balance_keyhunt_delay_return;
key.damageforcescale = autocvar_g_balance_keyhunt_damageforcescale;
key.takedamage = DAMAGE_YES;
if(key.kh_next)
key.kh_next.kh_prev = key.kh_prev;
key.kh_prev.kh_next = key.kh_next;
- key.kh_next = world;
- key.kh_prev = world;
+ key.kh_next = NULL;
+ key.kh_prev = NULL;
- if(key.owner.kh_next == world)
+ if(key.owner.kh_next == NULL)
{
// No longer a key carrier
if(!kh_no_radar_circles)
kh_Key_Attach(key);
- if(key.kh_next == world)
+ if(key.kh_next == NULL)
{
// player is now a key carrier
entity wp = WaypointSprite_AttachCarrier(WP_Null, player, RADARICON_FLAGCARRIER);
// moved that here, also update if there's no player
kh_update_state();
- key.pusher = world;
+ key.pusher = NULL;
ownerteam = kh_Key_AllOwnedByWhichTeam();
if(ownerteam != ownerteam0)
}
}
-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, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_PICKUP), player.netname);
kh_Key_AssignTo(key, player); // this also updates .kh_state
}
-void kh_Key_Touch() // runs many, many times when a key has been dropped and can be picked up
-{SELFPARAM();
+void kh_Key_Touch(entity this, entity toucher) // runs many, many times when a key has been dropped and can be picked up
+{
if(intermission_running)
return;
- if(self.owner) // already carried
+ if(this.owner) // already carried
return;
if(ITEM_TOUCH_NEEDKILL())
// maybe start a shorter countdown?
}
- if (!IS_PLAYER(other))
+ if (!IS_PLAYER(toucher))
return;
- if(other.deadflag != DEAD_NO)
+ if(IS_DEAD(toucher))
return;
- if(other == self.enemy)
- if(time < self.kh_droptime + autocvar_g_balance_keyhunt_delay_collect)
+ if(toucher == this.enemy)
+ if(time < this.kh_droptime + autocvar_g_balance_keyhunt_delay_collect)
return; // you just dropped it!
- kh_Key_Collect(self, other);
+ kh_Key_Collect(this, toucher);
}
void kh_Key_Remove(entity key) // runs after when all the keys have been collected or when a key has been dropped for more than X seconds
{
entity o;
o = key.owner;
- kh_Key_AssignTo(key, world);
+ kh_Key_AssignTo(key, NULL);
if(o) // it was attached
WaypointSprite_Kill(key.waypointsprite_attachedforcarrier);
else // it was dropped
}
}
- remove(key);
+ delete(key);
kh_update_state();
}
kh_Key_Remove(key);
kh_no_radar_circles = false;
- Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
+ Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, kh_StartRound);
}
first = false;
}
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(teem, INFO_KEYHUNT_CAPTURE_), keyowner);
+ Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(teem, INFO_KEYHUNT_CAPTURE), keyowner);
first = true;
midpoint = '0 0 0';
midpoint += thisorigin;
if(!first)
- te_lightning2(world, lastorigin, thisorigin);
+ te_lightning2(NULL, lastorigin, thisorigin);
lastorigin = thisorigin;
if(first)
firstorigin = thisorigin;
}
if(kh_teams > 2)
{
- te_lightning2(world, lastorigin, firstorigin);
+ te_lightning2(NULL, lastorigin, firstorigin);
}
midpoint = midpoint * (1 / kh_teams);
te_customflash(midpoint, 1000, 1, Team_ColorRGB(teem) * 0.5 + '0.5 0.5 0.5'); // make the color >=0.5 in each component
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;
- attacker = world;
+ attacker = NULL;
if(lostkey.pusher)
if(lostkey.pusher.team != teem)
if(IS_PLAYER(lostkey.pusher))
if(attacker)
{
if(lostkey.kh_previous_owner)
- kh_Scores_Event(lostkey.kh_previous_owner, world, "pushed", 0, -autocvar_g_balance_keyhunt_score_push);
+ kh_Scores_Event(lostkey.kh_previous_owner, NULL, "pushed", 0, -autocvar_g_balance_keyhunt_score_push);
// don't actually GIVE him the -nn points, just log
- kh_Scores_Event(attacker, world, "push", autocvar_g_balance_keyhunt_score_push, 0);
+ kh_Scores_Event(attacker, NULL, "push", autocvar_g_balance_keyhunt_score_push, 0);
PlayerScore_Add(attacker, SP_KH_PUSHES, 1);
//centerprint(attacker, "Your push is the best!"); // does this really need to exist?
}
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)
++keys;
if(lostkey.kh_previous_owner)
- kh_Scores_Event(lostkey.kh_previous_owner, world, "destroyed", 0, -autocvar_g_balance_keyhunt_score_destroyed);
+ kh_Scores_Event(lostkey.kh_previous_owner, NULL, "destroyed", 0, -autocvar_g_balance_keyhunt_score_destroyed);
// don't actually GIVE him the -nn points, just log
if(lostkey.kh_previous_owner.playerid == lostkey.kh_previous_owner_playerid)
if(key.owner && key.team != teem)
{
f = DistributeEvenly_Get(of);
- kh_Scores_Event(key.owner, world, "destroyed_holdingkey", f, 0);
+ kh_Scores_Event(key.owner, NULL, "destroyed_holdingkey", f, 0);
}
fragsleft = DistributeEvenly_Get(players);
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, NULL, "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, NULL, MSG_INFO, APP_TEAM_ENT(lostkey, INFO_KEYHUNT_LOST), lostkey.kh_previous_owner.netname);
play2all(SND(KH_DESTROY));
te_tarexplosion(lostkey.origin);
kh_FinishRound();
}
-void kh_Key_Think() // runs all the time
-{SELFPARAM();
- entity head;
- //entity player; // needed by FOR_EACH_PLAYER
-
+void kh_Key_Think(entity this) // runs all the time
+{
if(intermission_running)
return;
- if(self.owner)
+ if(this.owner)
{
#ifndef KH_PLAYER_USE_ATTACHMENT
- makevectors('0 1 0' * (self.cnt + (time % 360) * KH_KEY_XYSPEED));
- setorigin(self, v_forward * KH_KEY_XYDIST + '0 0 1' * self.origin.z);
+ makevectors('0 1 0' * (this.cnt + (time % 360) * KH_KEY_XYSPEED));
+ setorigin(this, v_forward * KH_KEY_XYDIST + '0 0 1' * this.origin.z);
#endif
}
// if in nodrop or time over, end the round
- if(!self.owner)
- if(time > self.pain_finished)
- kh_LoserTeam(self.team, self);
+ if(!this.owner)
+ if(time > this.pain_finished)
+ kh_LoserTeam(this.team, this);
- if(self.owner)
+ if(this.owner)
if(kh_Key_AllOwnedByWhichTeam() != -1)
{
- if(self.siren_time < time)
+ if(this.siren_time < time)
{
- sound(self.owner, CH_TRIGGER, SND_KH_ALARM, VOL_BASE, ATTEN_NORM); // play a simple alarm
- self.siren_time = time + 2.5; // repeat every 2.5 seconds
+ sound(this.owner, CH_TRIGGER, SND_KH_ALARM, VOL_BASE, ATTEN_NORM); // play a simple alarm
+ this.siren_time = time + 2.5; // repeat every 2.5 seconds
}
entity key;
vector p;
- p = self.owner.origin;
+ p = this.owner.origin;
FOR_EACH_KH_KEY(key)
- if(vlen(key.owner.origin - p) > autocvar_g_balance_keyhunt_maxdist)
+ if(vdist(key.owner.origin - p, >, autocvar_g_balance_keyhunt_maxdist))
goto not_winning;
- kh_WinnerTeam(self.team);
-:not_winning
+ kh_WinnerTeam(this.team);
+LABEL(not_winning)
}
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;
+ this.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, NULL);
+ 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.classname = STR_ITEM_KH_KEY;
- key.touch = kh_Key_Touch;
- key.think = kh_Key_Think;
+ settouch(key, kh_Key_Touch);
+ setthink(key, 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);
+ WaypointSprite_Spawn(WP_KeyDropped, 0, 0, key, '0 0 1' * KH_KEY_WP_ZSHIFT, NULL, key.team, key, waypointsprite_attachedforcarrier, false, RADARICON_FLAG);
key.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = kh_Key_waypointsprite_visible_for_player;
kh_Key_AssignTo(key, initial_owner);
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, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_DROP), player.netname);
- kh_Key_AssignTo(key, world);
+ kh_Key_AssignTo(key, NULL);
makevectors(player.v_angle);
- key.velocity = W_CalculateProjectileVelocity(player.velocity, autocvar_g_balance_keyhunt_throwvelocity * v_forward, false);
- key.pusher = world;
+ key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_throwvelocity * v_forward, false);
+ key.pusher = NULL;
key.pushltime = time + autocvar_g_balance_keyhunt_protecttime;
key.kh_dropperteam = key.team;
entity mypusher;
if(player.kh_next)
{
- mypusher = world;
+ mypusher = NULL;
if(player.pusher)
if(time < player.pushltime)
mypusher = player.pusher;
{
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);
- kh_Key_AssignTo(key, world);
+ Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_LOST), player.netname);
+ kh_Key_AssignTo(key, NULL);
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);
+ key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_dropvelocity * v_forward, false);
key.pusher = mypusher;
key.pushltime = time + autocvar_g_balance_keyhunt_protecttime;
if(suicide)
{
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, NULL, 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);
+ Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, kh_StartRound);
}
else
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, NULL, 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;
+ int missing_teams_mask = 0;
+ if(kh_teams & BIT(0))
+ missing_teams_mask += boolean(p1) * 1;
+ if(kh_teams & BIT(1))
+ missing_teams_mask += boolean(p2) * 2;
+ if(kh_teams & BIT(2))
+ missing_teams_mask += boolean(p3) * 4;
+ if(kh_teams & BIT(3))
+ 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);
+ Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
prev_missing_teams_mask = 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, NULL, MSG_CENTER, CPID_KEYHUNT);
+ Kill_Notification(NOTIF_ALL, NULL, 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, NULL, MSG_CENTER, CPID_KEYHUNT);
+ Kill_Notification(NOTIF_ALL, NULL, 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;
- }
+ entity my_player = NULL;
+ 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_tracking_enabled = false;
- Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEYHUNT_SCAN, autocvar_g_balance_keyhunt_delay_tracking);
+ Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_SCAN, autocvar_g_balance_keyhunt_delay_tracking);
kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_tracking, kh_EnableTrackingDevice);
}
entity k;
float nk;
nk = 0;
- for(k = targ.kh_next; k != world; k = k.kh_next)
+ for(k = targ.kh_next; k != NULL; k = k.kh_next)
++nk;
kh_Scores_Event(attacker, targ.kh_next, "carrierfrag", -nk * autocvar_g_balance_keyhunt_score_collect, 0);
}
kh_teams = autocvar_g_keyhunt_teams;
kh_teams = bound(2, kh_teams, 4);
+ int teams = 0;
+ if(kh_teams >= 1) teams |= BIT(0);
+ if(kh_teams >= 2) teams |= BIT(1);
+ if(kh_teams >= 3) teams |= BIT(2);
+ if(kh_teams >= 4) teams |= BIT(3);
+
+ kh_teams = teams; // now set it?
+
// make a KH entity for controlling the game
kh_controller = spawn();
- kh_controller.think = kh_Controller_Think;
+ setthink(kh_controller, kh_Controller_Think);
kh_Controller_SetThink(0, kh_WaitForPlayers);
setmodel(kh_controller, MDL_KH_KEY);
kh_controller.model = "";
kh_controller.modelindex = 0;
- addstat(STAT_KH_KEYS, AS_INT, kh_state);
-
kh_ScoreRules(kh_teams);
}
{
// to be called before intermission
kh_FinishRound();
- remove(kh_controller);
- kh_controller = world;
+ delete(kh_controller);
+ kh_controller = NULL;
}
// legacy bot role
-void() havocbot_role_kh_carrier;
-void() havocbot_role_kh_defense;
-void() havocbot_role_kh_offense;
-void() havocbot_role_kh_freelancer;
+void(entity this) havocbot_role_kh_carrier;
+void(entity this) havocbot_role_kh_defense;
+void(entity this) havocbot_role_kh_offense;
+void(entity this) havocbot_role_kh_freelancer;
-void havocbot_goalrating_kh(float ratingscale_team, float ratingscale_dropped, float ratingscale_enemy)
-{SELFPARAM();
+void havocbot_goalrating_kh(entity this, float ratingscale_team, float ratingscale_dropped, float ratingscale_enemy)
+{
entity head;
for (head = kh_worldkeylist; head; head = head.kh_worldkeynext)
{
- if(head.owner == self)
+ if(head.owner == this)
continue;
if(!kh_tracking_enabled)
{
// if it's carried by our team we know about it
// otherwise we have to see it to know about it
- if(!head.owner || head.team != self.team)
+ if(!head.owner || head.team != this.team)
{
- traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
+ traceline(this.origin + this.view_ofs, head.origin, MOVE_NOMONSTERS, this);
if (trace_fraction < 1 && trace_ent != head)
continue; // skip what I can't see
}
}
if(!head.owner)
- navigation_routerating(head, ratingscale_dropped * BOT_PICKUP_RATING_HIGH, 100000);
- else if(head.team == self.team)
- navigation_routerating(head.owner, ratingscale_team * BOT_PICKUP_RATING_HIGH, 100000);
+ navigation_routerating(this, head, ratingscale_dropped * BOT_PICKUP_RATING_HIGH, 100000);
+ else if(head.team == this.team)
+ navigation_routerating(this, head.owner, ratingscale_team * BOT_PICKUP_RATING_HIGH, 100000);
else
- navigation_routerating(head.owner, ratingscale_enemy * BOT_PICKUP_RATING_HIGH, 100000);
+ navigation_routerating(this, head.owner, ratingscale_enemy * BOT_PICKUP_RATING_HIGH, 100000);
}
- havocbot_goalrating_items(1, self.origin, 10000);
+ havocbot_goalrating_items(this, 1, this.origin, 10000);
}
-void havocbot_role_kh_carrier()
-{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+void havocbot_role_kh_carrier(entity this)
+{
+ if(IS_DEAD(this))
return;
- if (!(self.kh_next))
+ if (!(this.kh_next))
{
LOG_TRACE("changing role to freelancer\n");
- self.havocbot_role = havocbot_role_kh_freelancer;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_kh_freelancer;
+ this.havocbot_role_timeout = 0;
return;
}
- if (self.bot_strategytime < time)
+ if (this.bot_strategytime < time)
{
- self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
- navigation_goalrating_start();
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+ navigation_goalrating_start(this);
- if(kh_Key_AllOwnedByWhichTeam() == self.team)
- havocbot_goalrating_kh(10, 0.1, 0.1); // bring home
+ if(kh_Key_AllOwnedByWhichTeam() == this.team)
+ havocbot_goalrating_kh(this, 10, 0.1, 0.1); // bring home
else
- havocbot_goalrating_kh(4, 4, 1); // play defensively
+ havocbot_goalrating_kh(this, 4, 4, 1); // play defensively
- navigation_goalrating_end();
+ navigation_goalrating_end(this);
}
}
-void havocbot_role_kh_defense()
-{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+void havocbot_role_kh_defense(entity this)
+{
+ if(IS_DEAD(this))
return;
- if (self.kh_next)
+ if (this.kh_next)
{
LOG_TRACE("changing role to carrier\n");
- self.havocbot_role = havocbot_role_kh_carrier;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_kh_carrier;
+ this.havocbot_role_timeout = 0;
return;
}
- if (!self.havocbot_role_timeout)
- self.havocbot_role_timeout = time + random() * 10 + 20;
- if (time > self.havocbot_role_timeout)
+ if (!this.havocbot_role_timeout)
+ this.havocbot_role_timeout = time + random() * 10 + 20;
+ if (time > this.havocbot_role_timeout)
{
LOG_TRACE("changing role to freelancer\n");
- self.havocbot_role = havocbot_role_kh_freelancer;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_kh_freelancer;
+ this.havocbot_role_timeout = 0;
return;
}
- if (self.bot_strategytime < time)
+ if (this.bot_strategytime < time)
{
float key_owner_team;
- self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
- navigation_goalrating_start();
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+ navigation_goalrating_start(this);
key_owner_team = kh_Key_AllOwnedByWhichTeam();
- if(key_owner_team == self.team)
- havocbot_goalrating_kh(10, 0.1, 0.1); // defend key carriers
+ if(key_owner_team == this.team)
+ havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend key carriers
else if(key_owner_team == -1)
- havocbot_goalrating_kh(4, 1, 0.1); // play defensively
+ havocbot_goalrating_kh(this, 4, 1, 0.1); // play defensively
else
- havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK ANYWAY
+ havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK ANYWAY
- navigation_goalrating_end();
+ navigation_goalrating_end(this);
}
}
-void havocbot_role_kh_offense()
-{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+void havocbot_role_kh_offense(entity this)
+{
+ if(IS_DEAD(this))
return;
- if (self.kh_next)
+ if (this.kh_next)
{
LOG_TRACE("changing role to carrier\n");
- self.havocbot_role = havocbot_role_kh_carrier;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_kh_carrier;
+ this.havocbot_role_timeout = 0;
return;
}
- if (!self.havocbot_role_timeout)
- self.havocbot_role_timeout = time + random() * 10 + 20;
- if (time > self.havocbot_role_timeout)
+ if (!this.havocbot_role_timeout)
+ this.havocbot_role_timeout = time + random() * 10 + 20;
+ if (time > this.havocbot_role_timeout)
{
LOG_TRACE("changing role to freelancer\n");
- self.havocbot_role = havocbot_role_kh_freelancer;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_kh_freelancer;
+ this.havocbot_role_timeout = 0;
return;
}
- if (self.bot_strategytime < time)
+ if (this.bot_strategytime < time)
{
float key_owner_team;
- self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
- navigation_goalrating_start();
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+ navigation_goalrating_start(this);
key_owner_team = kh_Key_AllOwnedByWhichTeam();
- if(key_owner_team == self.team)
- havocbot_goalrating_kh(10, 0.1, 0.1); // defend anyway
+ if(key_owner_team == this.team)
+ havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend anyway
else if(key_owner_team == -1)
- havocbot_goalrating_kh(0.1, 1, 4); // play offensively
+ havocbot_goalrating_kh(this, 0.1, 1, 4); // play offensively
else
- havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK! EMERGENCY!
+ havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK! EMERGENCY!
- navigation_goalrating_end();
+ navigation_goalrating_end(this);
}
}
-void havocbot_role_kh_freelancer()
-{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+void havocbot_role_kh_freelancer(entity this)
+{
+ if(IS_DEAD(this))
return;
- if (self.kh_next)
+ if (this.kh_next)
{
LOG_TRACE("changing role to carrier\n");
- self.havocbot_role = havocbot_role_kh_carrier;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_kh_carrier;
+ this.havocbot_role_timeout = 0;
return;
}
- if (!self.havocbot_role_timeout)
- self.havocbot_role_timeout = time + random() * 10 + 10;
- if (time > self.havocbot_role_timeout)
+ if (!this.havocbot_role_timeout)
+ this.havocbot_role_timeout = time + random() * 10 + 10;
+ if (time > this.havocbot_role_timeout)
{
if (random() < 0.5)
{
LOG_TRACE("changing role to offense\n");
- self.havocbot_role = havocbot_role_kh_offense;
+ this.havocbot_role = havocbot_role_kh_offense;
}
else
{
LOG_TRACE("changing role to defense\n");
- self.havocbot_role = havocbot_role_kh_defense;
+ this.havocbot_role = havocbot_role_kh_defense;
}
- self.havocbot_role_timeout = 0;
+ this.havocbot_role_timeout = 0;
return;
}
- if (self.bot_strategytime < time)
+ if (this.bot_strategytime < time)
{
float key_owner_team;
- self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
- navigation_goalrating_start();
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+ navigation_goalrating_start(this);
key_owner_team = kh_Key_AllOwnedByWhichTeam();
- if(key_owner_team == self.team)
- havocbot_goalrating_kh(10, 0.1, 0.1); // defend anyway
+ if(key_owner_team == this.team)
+ havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend anyway
else if(key_owner_team == -1)
- havocbot_goalrating_kh(1, 10, 4); // prefer dropped keys
+ havocbot_goalrating_kh(this, 1, 10, 4); // prefer dropped keys
else
- havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK ANYWAY
+ havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK ANYWAY
- navigation_goalrating_end();
+ navigation_goalrating_end(this);
}
}
// register this as a mutator
MUTATOR_HOOKFUNCTION(kh, ClientDisconnect)
-{SELFPARAM();
- kh_Key_DropAll(self, true);
- return 0;
+{
+ entity player = M_ARGV(0, entity);
+
+ kh_Key_DropAll(player, true);
}
MUTATOR_HOOKFUNCTION(kh, MakePlayerObserver)
-{SELFPARAM();
- kh_Key_DropAll(self, true);
- return 0;
+{
+ entity player = M_ARGV(0, entity);
+
+ kh_Key_DropAll(player, true);
}
MUTATOR_HOOKFUNCTION(kh, PlayerDies)
-{SELFPARAM();
- if(self == other)
- kh_Key_DropAll(self, true);
- else if(IS_PLAYER(other))
- kh_Key_DropAll(self, false);
+{
+ entity frag_attacker = M_ARGV(1, entity);
+ entity frag_target = M_ARGV(2, entity);
+
+ if(frag_target == frag_attacker)
+ kh_Key_DropAll(frag_target, true);
+ else if(IS_PLAYER(frag_attacker))
+ kh_Key_DropAll(frag_target, false);
else
- kh_Key_DropAll(self, true);
- return 0;
+ kh_Key_DropAll(frag_target, true);
}
MUTATOR_HOOKFUNCTION(kh, GiveFragsForKill, CBC_ORDER_FIRST)
{
- frag_score = kh_HandleFrags(frag_attacker, frag_target, frag_score);
- return 0;
+ entity frag_attacker = M_ARGV(0, entity);
+ entity frag_target = M_ARGV(1, entity);
+ float frag_score = M_ARGV(2, float);
+ M_ARGV(2, float) = kh_HandleFrags(frag_attacker, frag_target, frag_score);
}
MUTATOR_HOOKFUNCTION(kh, MatchEnd)
{
kh_finalize();
- return 0;
}
MUTATOR_HOOKFUNCTION(kh, GetTeamCount, CBC_ORDER_EXCLUSIVE)
{
- ret_float = kh_teams;
- return false;
+ M_ARGV(0, float) = kh_teams;
}
MUTATOR_HOOKFUNCTION(kh, SpectateCopy)
-{SELFPARAM();
- self.kh_state = other.kh_state;
- return 0;
+{
+ entity spectatee = M_ARGV(0, entity);
+ entity client = M_ARGV(1, entity);
+
+ client.kh_state = spectatee.kh_state;
}
MUTATOR_HOOKFUNCTION(kh, PlayerUseKey)
-{SELFPARAM();
+{
+ entity player = M_ARGV(0, entity);
+
if(MUTATOR_RETURNVALUE == 0)
{
- entity k;
- k = self.kh_next;
+ entity k = player.kh_next;
if(k)
{
kh_Key_DropOne(k);
- return 1;
+ return true;
}
}
- return 0;
}
MUTATOR_HOOKFUNCTION(kh, HavocBot_ChooseRole)
{
- if(self.deadflag != DEAD_NO)
+ entity bot = M_ARGV(0, entity);
+
+ if(IS_DEAD(bot))
return true;
float r = random() * 3;
if (r < 1)
- self.havocbot_role = havocbot_role_kh_offense;
+ bot.havocbot_role = havocbot_role_kh_offense;
else if (r < 2)
- self.havocbot_role = havocbot_role_kh_defense;
+ bot.havocbot_role = havocbot_role_kh_defense;
else
- self.havocbot_role = havocbot_role_kh_freelancer;
+ bot.havocbot_role = havocbot_role_kh_freelancer;
return true;
}
MUTATOR_HOOKFUNCTION(kh, DropSpecialItems)
{
+ entity frag_target = M_ARGV(0, entity);
+
kh_Key_DropAll(frag_target, false);
- return false;
}
MUTATOR_HOOKFUNCTION(kh, reset_map_global)
{
kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round + (game_starttime - time), kh_StartRound);
- return false;
}
#endif