Refactoring

This commit is contained in:
Jackz 2022-07-06 22:53:56 -05:00
parent a5aee1dc1d
commit bc8069ac48
No known key found for this signature in database
GPG key ID: E0BBD94CF657F603
6 changed files with 73 additions and 83 deletions

Binary file not shown.

View file

@ -4,7 +4,7 @@
public Action Command_GuessWho(int client, int args) { public Action Command_GuessWho(int client, int args) {
if(!isEnabled) ReplyToCommand(client, "Warn: Guess Who is not active"); if(!isEnabled) ReplyToCommand(client, "Warn: %s is not active", GAMEMODE_NAME);
if(args > 0) { if(args > 0) {
char subcmd[32]; char subcmd[32];
GetCmdArg(1, subcmd, sizeof(subcmd)); GetCmdArg(1, subcmd, sizeof(subcmd));
@ -17,18 +17,18 @@ public Action Command_GuessWho(int client, int args) {
if(args == 3) { if(args == 3) {
GetCmdArg(2, subcmd, sizeof(subcmd)); GetCmdArg(2, subcmd, sizeof(subcmd));
} else { } else {
subcmd = currentSet; subcmd = g_currentSet;
} }
if(movePoints.SaveMap(currentMap, subcmd)) { if(movePoints.SaveMap(g_currentMap, subcmd)) {
ReplyToCommand(client, "Saved movement data for %s/%s", currentMap, subcmd); ReplyToCommand(client, "Saved movement data for %s/%s", g_currentMap, subcmd);
} else { } else {
ReplyToCommand(client, "Failed to save map data"); ReplyToCommand(client, "Failed to save map data");
} }
} else if(StrEqual(subcmd, "load")) { } else if(StrEqual(subcmd, "load")) {
MovePoints points = MovePoints.LoadMap(currentMap, currentSet); MovePoints points = MovePoints.LoadMap(g_currentMap, g_currentSet);
if(points != null) { if(points != null) {
Game.SetPoints(points); Game.SetPoints(points);
ReplyToCommand(client, "Loaded movement data for %s/%s", currentMap, currentSet); ReplyToCommand(client, "Loaded movement data for %s/%s", g_currentMap, g_currentSet);
} else { } else {
ReplyToCommand(client, "Failed to load map data"); ReplyToCommand(client, "Failed to load map data");
} }
@ -55,11 +55,11 @@ public Action Command_GuessWho(int client, int args) {
ReplyToCommand(client, "Unknown option. Valid options: 'clear', 'save', 'load'"); ReplyToCommand(client, "Unknown option. Valid options: 'clear', 'save', 'load'");
} }
} else if(StrEqual(subcmd, "r") || StrEqual(subcmd, "reload", false)) { } else if(StrEqual(subcmd, "r") || StrEqual(subcmd, "reload", false)) {
GetCurrentMap(currentMap, sizeof(currentMap)); GetCurrentMap(g_currentMap, sizeof(g_currentMap));
char arg[4]; char arg[4];
GetCmdArg(2, arg, sizeof(arg)); GetCmdArg(2, arg, sizeof(arg));
if(ReloadMapDB()) { if(ReloadMapDB()) {
if(!LoadConfigForMap(currentMap)) { if(!LoadConfigForMap(g_currentMap)) {
ReplyToCommand(client, "Warn: Map has no config file"); ReplyToCommand(client, "Warn: Map has no config file");
} }
Game.Cleanup(true); Game.Cleanup(true);
@ -74,7 +74,7 @@ public Action Command_GuessWho(int client, int args) {
} else if(StrEqual(subcmd, "set", false)) { } else if(StrEqual(subcmd, "set", false)) {
char set[16]; char set[16];
if(args == 1) { if(args == 1) {
ReplyToCommand(client, "Current Map Set: \"%s\" (Specify with /gw set <set>)", currentSet); ReplyToCommand(client, "Current Map Set: \"%s\" (Specify with /gw set <set>)", g_currentSet);
if(validSets.Length == 0) ReplyToCommand(client, "Available Sets: (no map config found)"); if(validSets.Length == 0) ReplyToCommand(client, "Available Sets: (no map config found)");
else { else {
ReplyToCommand(client, "Available Sets: "); ReplyToCommand(client, "Available Sets: ");
@ -84,25 +84,25 @@ public Action Command_GuessWho(int client, int args) {
} }
} }
} else { } else {
GetCmdArg(2, currentSet, sizeof(currentSet)); GetCmdArg(2, g_currentSet, sizeof(g_currentSet));
for(int i = 0; i < validSets.Length; i++) { for(int i = 0; i < validSets.Length; i++) {
validSets.GetString(i, set, sizeof(set)); validSets.GetString(i, set, sizeof(set));
if(StrEqual(set, currentSet)) { if(StrEqual(set, g_currentSet)) {
if(!LoadConfigForMap(currentMap)) { if(!LoadConfigForMap(g_currentMap)) {
ReplyToCommand(client, "Warn: No config entry for %s", currentMap); ReplyToCommand(client, "Warn: No config entry for %s", g_currentMap);
} }
MovePoints points = MovePoints.LoadMap(currentMap, currentSet); MovePoints points = MovePoints.LoadMap(g_currentMap, g_currentSet);
if(points != null) { if(points != null) {
if(movePoints.Length == 0) { if(movePoints.Length == 0) {
ReplyToCommand(client, "Warn: No map data found for %s/%s", currentMap, currentSet); ReplyToCommand(client, "Warn: No map data found for %s/%s", g_currentMap, g_currentSet);
} }
Game.SetPoints(points); Game.SetPoints(points);
} else { } else {
ReplyToCommand(client, "Warn: %s/%s has 0 saved movement locations", currentMap, currentSet); ReplyToCommand(client, "Warn: %s/%s has 0 saved movement locations", g_currentMap, g_currentSet);
} }
Game.Cleanup(); Game.Cleanup();
SetupEntities(isNavBlockersEnabled, isPropsEnabled, isPortalsEnabled); SetupEntities(isNavBlockersEnabled, isPropsEnabled, isPortalsEnabled);
PrintToChatAll("[GuessWho] Map set has been changed to \"%s\"", currentSet); PrintToChatAll("[GuessWho] Map set has been changed to \"%s\"", g_currentSet);
return Plugin_Handled; return Plugin_Handled;
} }
} }
@ -182,11 +182,11 @@ public Action Command_GuessWho(int client, int args) {
do { do {
int mapIndex = GetURandomInt() % validMaps.Length; int mapIndex = GetURandomInt() % validMaps.Length;
validMaps.GetString(mapIndex, map, sizeof(map)); validMaps.GetString(mapIndex, map, sizeof(map));
if(!StrEqual(currentMap, map, false)) { if(!StrEqual(g_currentMap, map, false)) {
foundMap = true; foundMap = true;
} }
} while(!foundMap); } while(!foundMap);
PrintToChatAll("[GuessWho] Switching map to %s", map); PrintToChatAll("%s Switching map to %s", GAMEMODE_PREFIX, map);
ChangeMap(map); ChangeMap(map);
} else if(StrEqual(arg, "next", false)) { } else if(StrEqual(arg, "next", false)) {
if(args == 1) { if(args == 1) {
@ -196,7 +196,7 @@ public Action Command_GuessWho(int client, int args) {
GetCmdArg(3, arg2, sizeof(arg2)); GetCmdArg(3, arg2, sizeof(arg2));
if(IsMapValid(arg2)) { if(IsMapValid(arg2)) {
strcopy(nextRoundMap, sizeof(nextRoundMap), arg2); strcopy(nextRoundMap, sizeof(nextRoundMap), arg2);
PrintToChatAll("[H&S] Switching map next round to %s", arg2); PrintToChatAll("%s Switching map next round to %s", GAMEMODE_PREFIX, arg2);
ForceChangeLevel(arg, "SetMapSelect"); ForceChangeLevel(arg, "SetMapSelect");
} else { } else {
ReplyToCommand(client, "Map is not valid"); ReplyToCommand(client, "Map is not valid");
@ -286,7 +286,7 @@ public Action Command_GuessWho(int client, int args) {
ReplyToCommand(client, "State: %d | Tick: %d", view_as<int>(Game.State), Game.Tick); ReplyToCommand(client, "State: %d | Tick: %d", view_as<int>(Game.State), Game.Tick);
ReplyToCommand(client, "- Map Info -"); ReplyToCommand(client, "- Map Info -");
ReplyToCommand(client, "Map: %s (set %s)", currentMap, currentSet); ReplyToCommand(client, "Map: %s (set %s)", g_currentMap, g_currentSet);
if(mapConfig.hasSpawnpoint) if(mapConfig.hasSpawnpoint)
ReplyToCommand(client, "Has Spawnpoint: yes (%f %f %f)", mapConfig.spawnpoint[0], mapConfig.spawnpoint[1], mapConfig.spawnpoint[2]); ReplyToCommand(client, "Has Spawnpoint: yes (%f %f %f)", mapConfig.spawnpoint[0], mapConfig.spawnpoint[1], mapConfig.spawnpoint[2]);
else else
@ -298,7 +298,7 @@ public Action Command_GuessWho(int client, int args) {
} }
return Plugin_Handled; return Plugin_Handled;
} }
ReplyToCommand(client, " === [ Guess Who Commands ] ==="); ReplyToCommand(client, " === [ %s Commands ] ===", GAMEMODE_NAME);
if(GetUserAdmin(client) != INVALID_ADMIN_ID) { if(GetUserAdmin(client) != INVALID_ADMIN_ID) {
ReplyToCommand(client, "- Dev Commands -"); ReplyToCommand(client, "- Dev Commands -");
ReplyToCommand(client, "points:"); ReplyToCommand(client, "points:");

View file

@ -50,10 +50,10 @@ bool LoadConfigForMap(const char[] map) {
static char buffer[64]; static char buffer[64];
buffer[0] = '\0'; buffer[0] = '\0';
if(StrEqual(currentSet, "default") && kv.GetString("defaultset", buffer, sizeof(buffer)) && buffer[0] != '\0') { if(StrEqual(g_currentSet, "default") && kv.GetString("defaultset", buffer, sizeof(buffer)) && buffer[0] != '\0') {
strcopy(currentSet, sizeof(currentSet), buffer); strcopy(g_currentSet, sizeof(g_currentSet), buffer);
} }
PrintToServer("[GuessWho] Loading config data for set %s on %s", currentSet, map); PrintToServer("[GuessWho] Loading config data for set %s on %s", g_currentSet, map);
if(kv.JumpToKey("ents")) { if(kv.JumpToKey("ents")) {
kv.GotoFirstSubKey(); kv.GotoFirstSubKey();
@ -71,7 +71,7 @@ bool LoadConfigForMap(const char[] map) {
if(validSets.FindString(buffer) == -1) { if(validSets.FindString(buffer) == -1) {
validSets.PushString(buffer); validSets.PushString(buffer);
} }
if(StrEqual(buffer, "default") || StrEqual(currentSet, buffer, false)) { if(StrEqual(buffer, "default") || StrEqual(g_currentSet, buffer, false)) {
config.entities.PushArray(entCfg); config.entities.PushArray(entCfg);
} else { } else {
@ -100,7 +100,7 @@ bool LoadConfigForMap(const char[] map) {
config.hasSpawnpoint = false; config.hasSpawnpoint = false;
config.canClimb = true; config.canClimb = true;
config.pressButtons = true; config.pressButtons = true;
if(!StrEqual(currentSet, "default") && kv.JumpToKey("sets")) { if(!StrEqual(g_currentSet, "default") && kv.JumpToKey("sets")) {
char set[16]; char set[16];
kv.GotoFirstSubKey(true); kv.GotoFirstSubKey(true);
do { do {
@ -108,10 +108,10 @@ bool LoadConfigForMap(const char[] map) {
if(validSets.FindString(set) == -1) { if(validSets.FindString(set) == -1) {
validSets.PushString(set); validSets.PushString(set);
} }
if(StrEqual(currentSet, set, false)) { if(StrEqual(g_currentSet, set, false)) {
kv.GetVector("spawnpoint", config.spawnpoint); kv.GetVector("spawnpoint", config.spawnpoint);
if(config.spawnpoint[0] != 0.0 && config.spawnpoint[1] != 0.0 && config.spawnpoint[2] != 0.0) { if(config.spawnpoint[0] != 0.0 && config.spawnpoint[1] != 0.0 && config.spawnpoint[2] != 0.0) {
PrintToServer("[GuessWho] Using provided custom spawnpoint for set %s at %0.1f, %0.1f, %0.1f", currentSet, config.spawnpoint[0], config.spawnpoint[1], config.spawnpoint[2]); PrintToServer("[GuessWho] Using provided custom spawnpoint for set %s at %0.1f, %0.1f, %0.1f", g_currentSet, config.spawnpoint[0], config.spawnpoint[1], config.spawnpoint[2]);
config.hasSpawnpoint = true; config.hasSpawnpoint = true;
} }
mapTime = kv.GetNum("maptime", 0); mapTime = kv.GetNum("maptime", 0);

View file

@ -231,7 +231,7 @@ void SetupEntities(bool blockers = true, bool props = true, bool portals = true)
} }
#endif #endif
if(mapConfig.entities != null) { if(mapConfig.entities != null) {
PrintToServer("[GuessWho] Deploying %d custom entities (Set: %s) (blockers:%b props:%b portals:%b)", mapConfig.entities.Length, currentSet, blockers, props, portals); PrintToServer("[GuessWho] Deploying %d custom entities (Set: %s) (blockers:%b props:%b portals:%b)", mapConfig.entities.Length, g_currentSet, blockers, props, portals);
for(int i = 0; i < mapConfig.entities.Length; i++) { for(int i = 0; i < mapConfig.entities.Length; i++) {
EntityConfig config; EntityConfig config;
mapConfig.entities.GetArray(i, config); mapConfig.entities.GetArray(i, config);

View file

@ -42,7 +42,7 @@ bool FindSpawnPosition(float pos[3], bool includePlayers = true) {
static char buffer[128]; static char buffer[128];
methodmap GuessWhoGame { methodmap GuessWhoGame < BaseGame {
property int Seeker { property int Seeker {
public get() { public get() {

View file

@ -56,9 +56,7 @@ int PLAYER_GLOW_COLOR[3] = { 0, 255, 0 };
#include <left4dhooks> #include <left4dhooks>
#include <smlib/effects> #include <smlib/effects>
#include <sceneprocessor> #include <sceneprocessor>
#include <basegamemode>
#include <multicolors> #include <multicolors>
#include <gamemodes/cvars>
char SURVIVOR_MODELS[8][] = { char SURVIVOR_MODELS[8][] = {
"models/survivors/survivor_namvet.mdl", "models/survivors/survivor_namvet.mdl",
@ -125,6 +123,8 @@ float vecLastLocation[MAXPLAYERS+1][3];
MovePoints movePoints; MovePoints movePoints;
GuessWhoGame Game; GuessWhoGame Game;
#include <gamemodes/base>
#include <guesswho/gwcore> #include <guesswho/gwcore>
@ -147,6 +147,8 @@ public void OnPluginStart() {
SetFailState("This plugin is for L4D2 only."); SetFailState("This plugin is for L4D2 only.");
} }
Game.Init("GuessWho");
g_iTeamNum = FindSendPropInfo("CTerrorPlayerResource", "m_iTeam"); g_iTeamNum = FindSendPropInfo("CTerrorPlayerResource", "m_iTeam");
if (g_iTeamNum == -1) if (g_iTeamNum == -1)
SetFailState("CTerrorPlayerResource \"m_iTeam\" offset is invalid"); SetFailState("CTerrorPlayerResource \"m_iTeam\" offset is invalid");
@ -186,7 +188,7 @@ public void Event_GamemodeChange(ConVar cvar, const char[] oldValue, const char[
if(shouldEnable) { if(shouldEnable) {
cvarStorage = new GameConVarStorage(); cvarStorage = new GameConVarStorage();
SetCvars(cvarStorage); SetCvars(cvarStorage);
PrintToChatAll("[GuessWho] Gamemode is starting"); Game.Broadcast("Gamemode is starting");
HookEvent("round_start", Event_RoundStart); HookEvent("round_start", Event_RoundStart);
HookEvent("player_death", Event_PlayerDeath); HookEvent("player_death", Event_PlayerDeath);
HookEvent("player_bot_replace", Event_PlayerToBot); HookEvent("player_bot_replace", Event_PlayerToBot);
@ -200,7 +202,6 @@ public void Event_GamemodeChange(ConVar cvar, const char[] oldValue, const char[
UnhookEvent("player_bot_replace", Event_PlayerToBot); UnhookEvent("player_bot_replace", Event_PlayerToBot);
UnhookEvent("player_ledge_grab", Event_LedgeGrab); UnhookEvent("player_ledge_grab", Event_LedgeGrab);
Game.Cleanup(); Game.Cleanup();
PrintToChatAll("[GuessWho] Gamemode unloaded but cvars have not been reset.");
RemoveCommandListener(OnGoAwayFromKeyboard, "go_away_from_keyboard"); RemoveCommandListener(OnGoAwayFromKeyboard, "go_away_from_keyboard");
} }
isEnabled = shouldEnable; isEnabled = shouldEnable;
@ -223,7 +224,7 @@ void Event_PlayerToBot(Event event, const char[] name, bool dontBroadcast) {
// Do not kick bots being spawned in // Do not kick bots being spawned in
if(spawningTimer == null) { if(spawningTimer == null) {
PrintToServer("[GuessWho/debug] possible idle bot: %d (player: %d)", bot, player); Game.Debug("possible idle bot: %d (player: %d)", bot, player);
// ChangeClientTeam(player, 0); // ChangeClientTeam(player, 0);
// L4D_SetHumanSpec(bot, player); // L4D_SetHumanSpec(bot, player);
L4D_TakeOverBot(player); L4D_TakeOverBot(player);
@ -237,24 +238,23 @@ void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
int attacker = GetClientOfUserId(event.GetInt("attacker")); int attacker = GetClientOfUserId(event.GetInt("attacker"));
if(client > 0 && Game.State == State_Active) { if(client > 0 && Game.State == State_Active) {
if(client == currentSeeker) { if(client == currentSeeker) {
PrintToChatAll("The seeker, %N, has died. Hiders win!", currentSeeker); Game.Broadcast("The seeker, %N, has died. Hiders win!", currentSeeker);
Game.State = State_HidersWin;
Game.End(State_HidersWin); Game.End(State_HidersWin);
} else if(!IsFakeClient(client)) { } else if(!IsFakeClient(client)) {
if(attacker == currentSeeker) { if(attacker == currentSeeker) {
PrintToChatAll("%N was killed", client); Game.Broadcast("%N was killed", client);
} else { } else {
PrintToChatAll("%N died", client); Game.Broadcast("%N died", client);
} }
} else { } else {
KickClient(client); KickClient(client);
PrintToServer("[GuessWho] Bot(%d) was killed", client); Game.Debug("Bot(%d) was killed", client);
} }
} }
if(Game.AlivePlayers == 0) { if(Game.AlivePlayers == 0) {
if(Game.State == State_Active) { if(Game.State == State_Active) {
PrintToChatAll("Everyone has died. %N wins!", currentSeeker); Game.Broadcast("Everyone has died. %N wins!", currentSeeker);
Game.End(State_SeekerWon); Game.End(State_SeekerWon);
} }
} }
@ -272,16 +272,16 @@ public void OnMapStart() {
char map[128]; char map[128];
GetCurrentMap(map, sizeof(map)); GetCurrentMap(map, sizeof(map));
if(!StrEqual(currentMap, map)) { if(!StrEqual(g_currentMap, map)) {
strcopy(currentSet, sizeof(currentSet), "default"); strcopy(g_currentSet, sizeof(g_currentSet), "default");
if(!StrEqual(currentMap, "")) { if(!StrEqual(g_currentMap, "")) {
if(!movePoints.SaveMap(currentMap, currentSet)) { if(!movePoints.SaveMap(g_currentMap, g_currentSet)) {
LogError("Could not save map data to disk"); LogError("Could not save map data to disk");
} }
} }
ReloadMapDB(); ReloadMapDB();
strcopy(currentMap, sizeof(currentMap), map); strcopy(g_currentMap, sizeof(g_currentMap), map);
Game.SetPoints(MovePoints.LoadMap(map, currentSet)); Game.SetPoints(MovePoints.LoadMap(map, g_currentSet));
} }
g_iLaserIndex = PrecacheModel("materials/sprites/laserbeam.vmt"); g_iLaserIndex = PrecacheModel("materials/sprites/laserbeam.vmt");
@ -297,7 +297,7 @@ public void OnMapStart() {
int seeker = Game.Seeker; int seeker = Game.Seeker;
if(seeker > -1) { if(seeker > -1) {
currentSeeker = seeker; currentSeeker = seeker;
PrintToServer("[GuessWho] Late load, found seeker %N", currentSeeker); Game.Debug("-Late load- Seeker: %N",currentSeeker);
} }
for(int i = 1; i <= MaxClients; i++) { for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i)) { if(IsClientConnected(i) && IsClientInGame(i)) {
@ -341,7 +341,7 @@ public void OnClientPutInServer(int client) {
if(isEnabled && !IsFakeClient(client)) { if(isEnabled && !IsFakeClient(client)) {
ChangeClientTeam(client, 1); ChangeClientTeam(client, 1);
isPendingPlay[client] = true; isPendingPlay[client] = true;
PrintToChatAll("%N will play next round", client); Game.Broadcast("%N will play next round", client);
Game.TeleportToSpawn(client); Game.TeleportToSpawn(client);
} }
} }
@ -350,12 +350,12 @@ public void OnClientPutInServer(int client) {
public void OnClientDisconnect(int client) { public void OnClientDisconnect(int client) {
if(!isEnabled) return; if(!isEnabled) return;
if(client == currentSeeker) { if(client == currentSeeker) {
PrintToChatAll("The seeker has disconnected"); Game.Broadcast("The seeker has disconnected");
Game.End(State_HidersWin); Game.End(State_HidersWin);
} else if(!IsFakeClient(client) && Game.State == State_Active) { } else if(!IsFakeClient(client) && Game.State == State_Active) {
PrintToChatAll("A hider has left (%N)", client); Game.Broadcast("A hider has left (%N)", client);
if(Game.AlivePlayers == 0 && Game.State == State_Active) { if(Game.AlivePlayers == 0 && Game.State == State_Active) {
PrintToChatAll("Game Over. %N wins!", currentSeeker); Game.Broadcast("Game Over. %N wins!", currentSeeker);
Game.End(State_SeekerWon); Game.End(State_SeekerWon);
} }
} }
@ -363,7 +363,7 @@ public void OnClientDisconnect(int client) {
void SetCvars(GameConVarStorage storage) { void SetCvars(GameConVarStorage storage) {
PrintToServer("[GuessWho] Setting convars"); Game.Debug("Setting convars");
if(cvar_survivorLimit != null) { if(cvar_survivorLimit != null) {
cvar_survivorLimit.SetBounds(ConVarBound_Upper, true, 64.0); cvar_survivorLimit.SetBounds(ConVarBound_Upper, true, 64.0);
cvar_survivorLimit.RecordInt(MaxClients, storage); cvar_survivorLimit.RecordInt(MaxClients, storage);
@ -380,11 +380,11 @@ void SetCvars(GameConVarStorage storage) {
void InitGamemode() { void InitGamemode() {
if(isStarting && Game.State != State_Unknown) { if(isStarting && Game.State != State_Unknown) {
PrintToServer("[GuessWho] Warn: InitGamemode() called in an incorrect state (%d)", Game.State); Game.Warn("InitGamemode() called in an incorrect state (%d)", Game.State);
return; return;
} }
SetupEntities(); SetupEntities();
PrintToChatAll("InitGamemode(): activating"); Game.DebugConsole("InitGamemode(): activating");
ArrayList validPlayerIds = new ArrayList(); ArrayList validPlayerIds = new ArrayList();
for(int i = 1; i <= MaxClients; i++) { for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2) { if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2) {
@ -406,7 +406,7 @@ void InitGamemode() {
} }
} }
if(validPlayerIds.Length == 0) { if(validPlayerIds.Length == 0) {
PrintToServer("[GuessWho] Warn: Ignoring InitGamemode() with no valid survivors"); Game.Warn("Ignoring InitGamemode() with no valid survivors");
return; return;
} }
ignoreSeekerBalance = false; ignoreSeekerBalance = false;
@ -414,7 +414,7 @@ void InitGamemode() {
delete validPlayerIds; delete validPlayerIds;
if(newSeeker > 0) { if(newSeeker > 0) {
hasBeenSeeker[newSeeker] = true; hasBeenSeeker[newSeeker] = true;
PrintToChatAll("%N is the seeker", newSeeker); Game.Broadcast("%N is the seeker", newSeeker);
Game.Seeker = newSeeker; Game.Seeker = newSeeker;
SetPlayerBlind(newSeeker, 255); SetPlayerBlind(newSeeker, 255);
SetEntPropFloat(newSeeker, Prop_Send, "m_flLaggedMovementValue", 0.0); SetEntPropFloat(newSeeker, Prop_Send, "m_flLaggedMovementValue", 0.0);
@ -446,7 +446,7 @@ Action Timer_SpawnBots(Handle h, int max) {
Action Timer_SpawnPost(Handle h) { Action Timer_SpawnPost(Handle h) {
spawningTimer = null; spawningTimer = null;
PrintToChatAll("Timer_SpawnPost(): activating"); Game.DebugConsole("Timer_SpawnPost(): activating");
bool isL4D1 = L4D2_GetSurvivorSetMap() == 1; bool isL4D1 = L4D2_GetSurvivorSetMap() == 1;
int remainingSeekers; int remainingSeekers;
int survivorMaxIndex = isL4D1 ? 3 : 7; int survivorMaxIndex = isL4D1 ? 3 : 7;
@ -482,13 +482,13 @@ Action Timer_SpawnPost(Handle h) {
} }
if(remainingSeekers == 0) { if(remainingSeekers == 0) {
PrintToChatAll("All players have been seekers once"); Game.Broadcast("All players have been seekers once");
for(int i = 0; i <= MaxClients; i++) { for(int i = 0; i <= MaxClients; i++) {
hasBeenSeeker[i] = false; hasBeenSeeker[i] = false;
} }
} }
PrintToChatAll("[debug] waiting for safe area leave"); Game.Debug("waiting for safe area leave", BaseDebug_Server | BaseDebug_ChatAll);
CreateTimer(1.0, Timer_WaitForStart, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT); CreateTimer(1.0, Timer_WaitForStart, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
return Plugin_Handled; return Plugin_Handled;
@ -515,7 +515,7 @@ Action Timer_WaitForStart(Handle h) {
} }
} }
PrintToChatAll("[GuessWho] Seeker will start in %.0f seconds", SEED_TIME); Game.Broadcast("Seeker will start in %.0f seconds", SEED_TIME);
Game.State = State_Starting; Game.State = State_Starting;
Game.Tick = 0; Game.Tick = 0;
Game.MapTime = RoundFloat(SEED_TIME); Game.MapTime = RoundFloat(SEED_TIME);
@ -541,7 +541,7 @@ Action Timer_StartSeeker(Handle h) {
} }
Action Timer_TimesUp(Handle h) { Action Timer_TimesUp(Handle h) {
PrintToChatAll("The seeker ran out of time. Hiders win!"); Game.Broadcast("The seeker ran out of time. Hiders win!");
Game.End(State_HidersWin); Game.End(State_HidersWin);
return Plugin_Handled; return Plugin_Handled;
} }
@ -592,7 +592,7 @@ Action Timer_AcquireLocations(Handle h) {
if(meta.pos[0] != vecLastLocation[i][0] || meta.pos[1] != vecLastLocation[i][1] || meta.pos[2] != vecLastLocation[i][2]) { if(meta.pos[0] != vecLastLocation[i][0] || meta.pos[1] != vecLastLocation[i][1] || meta.pos[2] != vecLastLocation[i][2]) {
movePoints.AddPoint(meta); movePoints.AddPoint(meta);
if(movePoints.Length > MAX_VALID_LOCATIONS) { if(movePoints.Length > MAX_VALID_LOCATIONS) {
PrintToServer("[GuessWho] Hit MAX_VALID_LOCATIONS (%d), clearing some locations", MAX_VALID_LOCATIONS); Game.Warn("Hit MAX_VALID_LOCATIONS (%d), clearing some locations", MAX_VALID_LOCATIONS);
movePoints.Sort(Sort_Random, Sort_Float); movePoints.Sort(Sort_Random, Sort_Float);
movePoints.Erase(RoundFloat(MAX_VALID_LOCATIONS * MAX_VALID_LOCATIONS_KEEP_PERCENT)); movePoints.Erase(RoundFloat(MAX_VALID_LOCATIONS * MAX_VALID_LOCATIONS_KEEP_PERCENT));
} }
@ -606,15 +606,6 @@ Action Timer_AcquireLocations(Handle h) {
return Plugin_Continue; return Plugin_Continue;
} }
void GetMovePoint(int i) {
activeBotLocations[i].runto = GetURandomFloat() < BOT_MOVE_RUN_CHANCE;
activeBotLocations[i].attempts = 0;
movePoints.GetArray(GetURandomInt() % movePoints.Length, activeBotLocations[i]);
#if defined DEBUG_SHOW_POINTS
Effect_DrawBeamBoxRotatableToAll(activeBotLocations[i].pos, DEBUG_POINT_VIEW_MIN, DEBUG_POINT_VIEW_MAX, NULL_VECTOR, g_iLaserIndex, 0, 0, 0, 150.0, 0.1, 0.1, 0, 0.0, {255, 0, 255, 120}, 0);
#endif
}
Action Timer_BotMove(Handle h, int userid) { Action Timer_BotMove(Handle h, int userid) {
int i = GetClientOfUserId(userid); int i = GetClientOfUserId(userid);
if(i == 0) return Plugin_Stop; if(i == 0) return Plugin_Stop;
@ -637,7 +628,7 @@ Action Timer_BotMove(Handle h, int userid) {
TE_SendToAll(); TE_SendToAll();
L4D2_RunScript("CommandABot({cmd=1,bot=GetPlayerFromUserID(%i),pos=Vector(%f,%f,%f)})", GetClientUserId(i), seekerPos[0], seekerPos[1], seekerPos[2]); L4D2_RunScript("CommandABot({cmd=1,bot=GetPlayerFromUserID(%i),pos=Vector(%f,%f,%f)})", GetClientUserId(i), seekerPos[0], seekerPos[1], seekerPos[2]);
#if defined DEBUG_BOT_MOVE #if defined DEBUG_BOT_MOVE
PrintToConsoleAll("[gw/debug] BOT %N TOO FAR (%f) BOUNDS (%f, %f)-> Moving to seeker (%f %f %f)", i, botFlow, flowMin, flowMax, seekerPos[0], seekerPos[1], seekerPos[2]); Game.DebugConsole("BOT %N TOO FAR (%f) BOUNDS (%f, %f)-> Moving to seeker (%f %f %f)", i, botFlow, flowMin, flowMax, seekerPos[0], seekerPos[1], seekerPos[2]);
#endif #endif
activeBotLocations[i].attempts = 0; activeBotLocations[i].attempts = 0;
} else if(movePoints.Length > 0) { } else if(movePoints.Length > 0) {
@ -653,12 +644,12 @@ Action Timer_BotMove(Handle h, int userid) {
if(mapConfig.hasSpawnpoint && FloatAbs(botFlow - seekerFlow) < BOT_MOVE_AVOID_FLOW_DIST && GetURandomFloat() < BOT_MOVE_AVOID_SEEKER_CHANCE) { if(mapConfig.hasSpawnpoint && FloatAbs(botFlow - seekerFlow) < BOT_MOVE_AVOID_FLOW_DIST && GetURandomFloat() < BOT_MOVE_AVOID_SEEKER_CHANCE) {
if(!movePoints.GetRandomPointFar(seekerPos, activeBotLocations[i].pos, BOT_MOVE_AVOID_MIN_DISTANCE)) { if(!movePoints.GetRandomPointFar(seekerPos, activeBotLocations[i].pos, BOT_MOVE_AVOID_MIN_DISTANCE)) {
#if defined DEBUG_BOT_MOVE #if defined DEBUG_BOT_MOVE
PrintToConsoleAll("[gw/debug] BOT %N TOO CLOSE -> Failed to find far point, falling back to spawn", i); // DebugConsole("BOT %N TOO CLOSE -> Failed to find far point, falling back to spawn", i);
#endif #endif
activeBotLocations[i].pos = mapConfig.spawnpoint; activeBotLocations[i].pos = mapConfig.spawnpoint;
} else { } else {
#if defined DEBUG_BOT_MOVE #if defined DEBUG_BOT_MOVE
PrintToConsoleAll("[gw/debug] BOT %N TOO CLOSE -> Moving to far point (%f %f %f) (%f units away)", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2], GetVectorDistance(seekerPos, activeBotLocations[i].pos)); // DebugConsole("BOT %N TOO CLOSE -> Moving to far point (%f %f %f) (%f units away)", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2], GetVectorDistance(seekerPos, activeBotLocations[i].pos));
#endif #endif
} }
activeBotLocations[i].runto = GetURandomFloat() < 0.75; activeBotLocations[i].runto = GetURandomFloat() < 0.75;
@ -666,15 +657,14 @@ Action Timer_BotMove(Handle h, int userid) {
Effect_DrawBeamBoxRotatableToAll(activeBotLocations[i].pos, DEBUG_POINT_VIEW_MIN, DEBUG_POINT_VIEW_MAX, NULL_VECTOR, g_iLaserIndex, 0, 0, 0, 150.0, 0.2, 0.1, 0, 0.0, {255, 255, 255, 255}, 0); Effect_DrawBeamBoxRotatableToAll(activeBotLocations[i].pos, DEBUG_POINT_VIEW_MIN, DEBUG_POINT_VIEW_MAX, NULL_VECTOR, g_iLaserIndex, 0, 0, 0, 150.0, 0.2, 0.1, 0, 0.0, {255, 255, 255, 255}, 0);
#endif #endif
} else { } else {
GetMovePoint(i); movePoints.GetRandomPoint(activeBotLocations[i]);
} }
if(!L4D2_IsReachable(i, activeBotLocations[i].pos)) { if(!L4D2_IsReachable(i, activeBotLocations[i].pos)) {
#if defined DEBUG_BOT_MOVE #if defined DEBUG_BOT_MOVE
PrintToChatAll("[gw/debug] POINT UNREACHABLE (Bot:%d) (%f %f %f)", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2]); Game.Warn("Point is unreachable at (%f, %f, %f) for %L", activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2], i);
PrintToServer("[gw/debug] POINT UNREACHABLE (Bot:%d) (%f %f %f)", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2]);
Effect_DrawBeamBoxRotatableToAll(activeBotLocations[i].pos, DEBUG_POINT_VIEW_MIN, view_as<float>({ 10.0, 10.0, 100.0 }), NULL_VECTOR, g_iLaserIndex, 0, 0, 0, 400.0, 2.0, 3.0, 0, 0.0, {255, 0, 0, 255}, 0); Effect_DrawBeamBoxRotatableToAll(activeBotLocations[i].pos, DEBUG_POINT_VIEW_MIN, view_as<float>({ 10.0, 10.0, 100.0 }), NULL_VECTOR, g_iLaserIndex, 0, 0, 0, 400.0, 2.0, 3.0, 0, 0.0, {255, 0, 0, 255}, 0);
#endif #endif
GetMovePoint(i); movePoints.GetRandomPoint(activeBotLocations[i]);
} }
} else { } else {
// Has not reached dest // Has not reached dest
@ -685,7 +675,7 @@ Action Timer_BotMove(Handle h, int userid) {
if(activeBotLocations[i].attempts == BOT_MOVE_NOT_REACHED_ATTEMPT_RUNJUMP) { if(activeBotLocations[i].attempts == BOT_MOVE_NOT_REACHED_ATTEMPT_RUNJUMP) {
if(distanceToPoint <= (BOT_MOVE_NOT_REACHED_DISTANCE * 2)) { if(distanceToPoint <= (BOT_MOVE_NOT_REACHED_DISTANCE * 2)) {
#if defined DEBUG_BOT_MOVE #if defined DEBUG_BOT_MOVE
PrintToConsoleAll("[gw/debug] Bot %d still has not reached point (%f %f %f), jumping", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2]); Game.DebugConsole("Bot %d still has not reached point (%f %f %f), jumping", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2]);
L4D2_SetPlayerSurvivorGlowState(i, true); L4D2_SetPlayerSurvivorGlowState(i, true);
L4D2_SetEntityGlow(i, L4D2Glow_Constant, 0, 10, PLAYER_GLOW_COLOR, true); L4D2_SetEntityGlow(i, L4D2Glow_Constant, 0, 10, PLAYER_GLOW_COLOR, true);
#endif #endif
@ -693,7 +683,7 @@ Action Timer_BotMove(Handle h, int userid) {
} else { } else {
activeBotLocations[i].runto = true; activeBotLocations[i].runto = true;
#if defined DEBUG_BOT_MOVE #if defined DEBUG_BOT_MOVE
PrintToConsoleAll("[gw/debug] Bot %d not reached point (%f %f %f), running", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2]); Game.DebugConsole("Bot %d not reached point (%f %f %f), running", i, activeBotLocations[i].pos[0], activeBotLocations[i].pos[1], activeBotLocations[i].pos[2]);
L4D2_SetEntityGlow(i, L4D2Glow_Constant, 0, 10, PLAYER_GLOW_COLOR, true); L4D2_SetEntityGlow(i, L4D2Glow_Constant, 0, 10, PLAYER_GLOW_COLOR, true);
L4D2_SetPlayerSurvivorGlowState(i, true); L4D2_SetPlayerSurvivorGlowState(i, true);
#endif #endif
@ -704,7 +694,7 @@ Action Timer_BotMove(Handle h, int userid) {
L4D2_SetEntityGlow(i, L4D2Glow_Constant, 0, 10, SEEKER_GLOW_COLOR, true); L4D2_SetEntityGlow(i, L4D2Glow_Constant, 0, 10, SEEKER_GLOW_COLOR, true);
L4D2_SetPlayerSurvivorGlowState(i, true); L4D2_SetPlayerSurvivorGlowState(i, true);
#endif #endif
GetMovePoint(i); movePoints.GetRandomPoint(activeBotLocations[i]);
} }
#if defined DEBUG_SHOW_POINTS #if defined DEBUG_SHOW_POINTS
int color[4]; int color[4];