Commit 2bef09d9 authored by Mikleo's avatar Mikleo
Browse files

changed scenario selection files

use these 2 steps to upgrade files.
change votelist.txt to selection.txt
(can be done by selecting them all in windows search and rename)
change "Scenarios" to "Options"
(can be done with something like "replace in files" with notepad++ within scenario folder.
parent d9a131aa
Pipeline #12662 passed with stages
in 14 seconds
......@@ -10,7 +10,7 @@
#include <SteamWorks>
#define PluginVersion "1.38"
#define PluginVersion "1.39"
float pVersion;
// note linearmap field is unstable
......@@ -31,8 +31,7 @@ bool editedAuthor = false;
int lastMinorEditTime = 0;
Handle ScenarioVoteTimer = INVALID_HANDLE;
Menu ScenarioVoteMenu = null;
int currentHammerID = BASEHAMMERID;
......@@ -61,7 +60,7 @@ char lastCommand[64];
bool usedFlagIndex[32] = {false,...};
ConVar ef_editlock,ef_baseswap,ef_scenario_vote_delay,ef_scenario_vote_duration,ef_scenario_vote_runoff_duration,ef_scenario_vote_min_timeleft,ef_scenario_vote_display_description,ef_scenario_vote_display_name,ef_scenario_vote_display_tags,ef_scenario_reload_map_config,ef_votelist_base,ef_alledit,ef_downloadeditorcfg,ef_dynamic_prop_shadows;
ConVar ef_editlock,ef_baseswap,ef_scenario_reload_map_config,ef_alledit,ef_downloadeditorcfg,ef_dynamic_prop_shadows;
ConVar emp_sv_commander_freeze_time, emp_sv_player_refinery_multiplier, emp_sv_refinery_multiplier;
......@@ -139,6 +138,8 @@ ArrayList keyData;
int NFTeamEntity,BETeamEntity;
#include "empfun/funcs.sp"
#include "empfun/selection.sp"
// must be saved before user has begun editing the map
int latestKnownMapEntity = 0;
......@@ -199,8 +200,7 @@ public void OnPluginStart()
RegAdminCmd("sm_snr", Command_Scenario_Var, ADMFLAG_SLAY);
RegAdminCmd("sm_editingset", Command_EditingSet, ADMFLAG_SLAY);
RegAdminCmd("sm_scenariovote", Command_Scenario_Vote, ADMFLAG_SLAY);
RegAdminCmd("sm_scenariovotelist", Command_Scenario_Votelist, ADMFLAG_SLAY);
RegAdminCmd("sm_renamescenario", Command_Rename_Scenario, ADMFLAG_SLAY);
RegAdminCmd("sm_savescenario", Command_Save_Scenario, ADMFLAG_SLAY);
RegAdminCmd("sm_loadscenario", Command_Load_Scenario, ADMFLAG_SLAY);
......@@ -223,15 +223,8 @@ public void OnPluginStart()
ef_baseswap = CreateConVar("ef_baseswap", "0", "Enable Base Swapping");
// set to 0 in case cvar already existed.
ef_baseswap.IntValue = 0;
ef_scenario_vote_delay = CreateConVar("ef_scenario_vote_delay", "25", "Scenario Vote Delay");
ef_scenario_vote_duration = CreateConVar("ef_scenario_vote_duration", "25", "Scenario Vote Duration");
ef_scenario_vote_runoff_duration = CreateConVar("ef_scenario_vote_runoff_duration", "15", "Scenario Vote Runoff Duration");
ef_scenario_vote_min_timeleft = CreateConVar("ef_scenario_vote_min_timeleft", "80", "Scenario Vote Min Timeleft");
ef_scenario_vote_display_description = CreateConVar("ef_scenario_vote_display_description", "1", "Display Description during scenario vote");
ef_scenario_vote_display_name = CreateConVar("ef_scenario_vote_display_name", "1", "Display name during scenario vote");
ef_scenario_vote_display_tags = CreateConVar("ef_scenario_vote_display_tags", "1", "Display tags during scenario vote");
ef_scenario_reload_map_config= CreateConVar("ef_scenario_reload_map_config", "0", "Reload the map config when loading a scenario ");
ef_votelist_base = CreateConVar("ef_votelist_base", "votelist_base.txt", "the name of the votelist file to use if no votelist is available.");
ef_alledit = CreateConVar("ef_alledit","0","Allow non admins to edit the map");
ef_downloadeditorcfg = CreateConVar("ef_downloadeditorcfg","0","Add editor.cfg to download list");
......@@ -254,7 +247,7 @@ public void OnPluginStart()
scenarioEditingSet = new StringMap();
Selection_OnPluginStart();
Funcs_OnPluginStart();
}
......@@ -277,13 +270,17 @@ public void OnAllPluginsLoaded()
public OnMapEnd()
{
CancelScenarioVote();
// make sure baseswap is turned off for the next round.
ef_baseswap.IntValue = 0;
delete currentScenarioKV;
Selection_OnMapEnd();
Funcs_OnMapEnd();
......@@ -392,7 +389,7 @@ public OnMapStart()
Funcs_OnMapStart();
ScenarioVoteMenu = null;
Selection_OnMapStart();
displayHandles = false;
}
......@@ -429,367 +426,13 @@ public OnGameEnd()
// not called on late loads, after onmapstart
public void OnConfigsExecuted()
{
CreateTimer(1.0,Timer_LoadStartingScenario);
}
public bool SetupScenarioVote()
{
KeyValues kv = new KeyValues("VoteData");
char path[128];
GetActingVoteListPath(path,sizeof(path));
bool succeeded = true;
if(!kv.ImportFromFile(path))
{
succeeded = false;
}
else
{
// by default its enabled.
int enabled = kv.GetNum("enabled",1);
if(enabled != 1)
{
succeeded = false;
}
else
{
ScenarioVoteTimer = CreateTimer(ef_scenario_vote_delay.FloatValue, Timer_StartDefaultScenarioVote);
}
}
delete kv;
return succeeded;
}
public Action Timer_StartDefaultScenarioVote(Handle timer,int entity)
{
// make sure handle is empty so we dont attempt to kill a bad timer.
ScenarioVoteTimer = INVALID_HANDLE;
StartDefaultScenarioVote();
return Plugin_Handled;
}
public Action Timer_VoteWarnTimer(Handle timer,int entity)
{
// make sure handle is empty so we dont attempt to kill a bad timer.
ScenarioVoteTimer = INVALID_HANDLE;
PrintToChatAll("The vote will end in 5 seconds...");
}
bool StartDefaultScenarioVote()
{
KeyValues kv = new KeyValues("VoteData");
char path[128];
GetActingVoteListPath(path,sizeof(path));
kv.ImportFromFile(path);
kv.JumpToKey("scenarios");
StartScenarioVote(kv);
delete kv;
}
public bool StartScenarioVote(KeyValues kv)
{
if (IsVoteInProgress())
{
return;
}
if(EU_GetWaitTime() < 20)
return;
if(EU_GetWaitTime() < ef_scenario_vote_min_timeleft.IntValue)
{
EU_SetWaitTime(ef_scenario_vote_min_timeleft.IntValue);
}
char path[128];
ScenarioVoteMenu = new Menu(Handle_VoteMenu);
ScenarioVoteMenu.SetTitle("Vote For a Scenario\n");
ScenarioVoteMenu.AddItem("", "Default \nThe Current Scenario");
KeyValues kv_scenario;
char descriptionBuffer[100];
char nameBuffer[32];
char displayName[64];
char tags[32];
char optionText[128];
int numOptions = 0;
int numPlayers = GetClientCount(true);
kv.GotoFirstSubKey();
do
{
kv.GetSectionName(nameBuffer, sizeof(nameBuffer));
GetScenarioPath(nameBuffer,path,sizeof(path));
int minPlayers = kv.GetNum("min_players",-1);
if(minPlayers != -1 && numPlayers < minPlayers)
{
continue;
}
int maxPlayers = kv.GetNum("max_players",-1);
if(maxPlayers != -1 && numPlayers > maxPlayers)
{
continue;
}
float chance = kv.GetFloat("chance", 1.0);
if(GetRandomFloat(0.0, 1.0) > chance)
{
continue;
}
kv.GetString("description_override",descriptionBuffer,sizeof(descriptionBuffer),"-");
kv.GetString("tags_override",tags,sizeof(tags));
strcopy(displayName,sizeof(displayName),nameBuffer);
kv_scenario = new KeyValues("Scenario");
if(kv_scenario.ImportFromFile(path))
{
if(strlen(descriptionBuffer) <= 1)
{
kv_scenario.GetString("Description",descriptionBuffer,sizeof(descriptionBuffer));
}
if(strlen(tags) <= 1)
{
kv_scenario.GetString("Tags",tags,sizeof(tags));
}
strcopy(optionText,sizeof(optionText),"");
if(ef_scenario_vote_display_name.IntValue == 1)
{
Format(optionText,sizeof(optionText),"%s%s",optionText,displayName);
}
if(ef_scenario_vote_display_tags.IntValue == 1 && strlen(tags) > 1)
{
Format(optionText,sizeof(optionText),"%s (%s)",optionText,tags);
}
if(ef_scenario_vote_display_description.IntValue == 1)
{
char displayBuffer[128];
DivideString(descriptionBuffer,sizeof(descriptionBuffer),75,2,displayBuffer);
Format(optionText,sizeof(optionText),"%s\n%s",optionText,displayBuffer);
}
Format(optionText,sizeof(optionText),"%s ",optionText);
ScenarioVoteMenu.AddItem(nameBuffer, optionText);
numOptions ++;
}
delete kv_scenario;
} while (kv.GotoNextKey(false) && numOptions < 6);
if(numOptions > 0)
{
ScenarioVoteMenu.ExitButton = false;
ScenarioVoteMenu.VoteResultCallback = Handle_VoteResults;
ScenarioVoteMenu.DisplayVoteToAll(ef_scenario_vote_duration.IntValue);
ScenarioVoteTimer = CreateTimer(ef_scenario_vote_duration.FloatValue - 5.0, Timer_VoteWarnTimer);
}
else
{
delete ScenarioVoteMenu;
ScenarioVoteMenu = null;
}
}
//https://wiki.alliedmods.net/Menu_API_(SourceMod)#Voting
public int Handle_VoteMenu(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_End)
{
/* This is called after VoteEnd */
if(ScenarioVoteTimer != INVALID_HANDLE)
{
KillTimer(ScenarioVoteTimer);
ScenarioVoteTimer = INVALID_HANDLE;
}
delete menu;
ScenarioVoteMenu = null;
}
}
public void Handle_VoteResults(Menu menu, int num_votes, int num_clients, const int[][] client_info, int num_items, const int[][] item_info)
{
/* See if there were multiple winners */
int winner = -1;
char info[32];
int style;
char display[128];
if(num_items < 0)
{
//noone has voted, do not continue
return;
}
int winningvotes = item_info[0][VOTEINFO_ITEM_VOTES];
int required = RoundToCeil(num_votes * 0.5);
if(winningvotes >= required || menu.ItemCount <=2)
{
winner = 0;
menu.GetItem(item_info[winner][VOTEINFO_ITEM_INDEX], info, sizeof(info),style,display,sizeof(display));
float percent = 100 * float(winningvotes) / float(num_votes);
if(strlen(info) > 0)
{
PrintToChatAll("(%.0f%%%%) Loading Scenario: %s",percent,display);
LoadScenario(0,info);
ShowScenarioInfo(-1,30);
if(ScenarioVoteTimer != INVALID_HANDLE)
{
KillTimer(ScenarioVoteTimer);
ScenarioVoteTimer = INVALID_HANDLE;
}
}
else
{
PrintToChatAll("(%.0f%%%%) Scenario will not change.",percent);
}
}
else
{
// start a new vote with the top 2 items of existing vote.
Menu newMenu = new Menu(Handle_VoteMenu);
newMenu.SetTitle("Scenario Runoff Vote");
menu.GetItem(item_info[0][VOTEINFO_ITEM_INDEX], info, sizeof(info),style,display,sizeof(display));
newMenu.AddItem(info, display);
menu.GetItem(item_info[1][VOTEINFO_ITEM_INDEX], info, sizeof(info),style,display,sizeof(display));
newMenu.AddItem(info, display);
newMenu.ExitButton = false;
newMenu.VoteResultCallback = Handle_VoteResults;
PrintToChatAll("[EF] No scenario has a majority \nCommencing runoff vote in 5 seconds...");
CreateTimer(3.5, Timer_RunoffVote,newMenu);
}
}
public bool IsInScenarioVote()
{
return ScenarioVoteMenu != null;
}
// returns true if there was an active vote which was cancelled
public bool CancelScenarioVote()
{
if(ScenarioVoteTimer != INVALID_HANDLE)
{
KillTimer(ScenarioVoteTimer);
ScenarioVoteTimer = INVALID_HANDLE;
}
if(ScenarioVoteMenu != null)
{
CancelVote();
ScenarioVoteMenu = null;
return true;
}
return false;
}
// make sure that valid refinery points are available. hack for now
public Action Timer_RunoffVote(Handle timer,Menu menu)
{
if(!EU_HasGameStarted())
{
menu.DisplayVoteToAll(ef_scenario_vote_runoff_duration.IntValue);
ScenarioVoteTimer = CreateTimer(ef_scenario_vote_runoff_duration.FloatValue - 5.0, Timer_VoteWarnTimer);
}
else
{
delete menu;
}
}
// make sure that valid refinery points are available. hack for now
public Action Timer_LoadStartingScenario(Handle timer,int entity)
{
if(!EU_HasGameStarted())
{
if(strlen(nextMapScenario) > 0)
{
LoadScenario(0,nextMapScenario);
strcopy(nextMapScenario,sizeof(nextMapScenario),"");
}
else
{
bool overrideLoaded = LoadOverrideScenario();
if(!overrideLoaded && ef_baseswap.IntValue == 1)
{
DelayedBaseSwap();
}
SetupScenarioVote();
}
}
Selection_OnConfigsExecuted();
}
bool LoadOverrideScenario()
{
ArrayList scenarioList = new ArrayList(128);
GetScenarioList(scenarioList);
char fileBuffer[128];
bool loadedOverride = false;
for(int i = 0;i<scenarioList.Length;i++)
{
scenarioList.GetString(i,fileBuffer,sizeof(fileBuffer));
if(StrContains(fileBuffer, "override", true) == 0)
{
LoadScenario(0,fileBuffer);
PrintToServer("loaded %s ", fileBuffer);
loadedOverride = true;
break;
}
}
delete scenarioList;
return loadedOverride;
}
GetScenarioList(ArrayList items)
{
char fileBuffer[128];
......@@ -4017,152 +3660,7 @@ public Action Command_EditingSet(int client, int args)
return Plugin_Handled;
}
// maybe an option to specify later.
public Action Command_Scenario_Vote(int client, int args)
{
// just cancel the existing vote.
CancelScenarioVote();
if(args == 0)
{
StartDefaultScenarioVote();
}
else
{
KeyValues kv = new KeyValues("VoteData");
char arg[32];
for(int i = 0; i <= GetCmdArgs(); i++)
{
GetCmdArg(i, arg, sizeof(arg));
kv.JumpToKey(arg,true);
kv.GoBack();
}
StartScenarioVote(kv);
delete kv;
}
char clientName[128];
GetClientName(client,clientName,sizeof(clientName));
PrintToChatAll("%s started a scenario vote",clientName);
return Plugin_Handled;
}
public Action Command_Scenario_Votelist(int client, int args)
{
// set description,author and baseswap "Options: Description Author Baseswap(1/0)"
char arg1 [128];
char arg2 [128];
char votelistpath[128];
GetVoteListPath(votelistpath,sizeof(votelistpath));
KeyValues kv = new KeyValues("VoteList");
kv.ImportFromFile(votelistpath);
kv.Rewind();
if(!GetCmdArg(1, arg1, sizeof(arg1)))
{
char scenarioPath[128];
PrintToChat(client,"VoteList:");
// set it to enabled so when a scenario is added it is automatically enabled.
int enabled = kv.GetNum("enabled",1);
kv.JumpToKey("scenarios",true);
kv.GotoFirstSubKey();
do
{
kv.GetSectionName(scenarioPath, sizeof(scenarioPath));
PrintToChat(client,scenarioPath);
} while (kv.GotoNextKey(false));
kv.Rewind();
PrintToChat(client,"Enabled: %d \n usage !scenariovotelist [add/remove] [scenarioname]\n !scenariovotelist [enable/disable]",enabled);
}
else
{
int hasArg2 = GetCmdArg(2, arg2, sizeof(arg2));
if(StrEqual(arg1,"enable",false))
{
kv.SetString("enabled","1");
PrintToChat(client,"scenario vote list enabled",arg2);
kv.Rewind();
ExportKV(kv,votelistpath);
}
else if(StrEqual(arg1,"disable",false))
{
kv.SetString("enabled","0");
PrintToChat(client,"scenario vote list disabled",arg2);
kv.Rewind();
ExportKV(kv,votelistpath);
}
else if(StrEqual(arg1,"add",false))
{
char scenarioPath[128];
GetScenarioPath(arg2,scenarioPath,sizeof(scenarioPath));
if(FileExists(scenarioPath))
{
kv.JumpToKey("scenarios",true);
if(!kv.JumpToKey(arg2,false))
{
// needs some solid values to actually save this.
kv.JumpToKey(arg2,true);
kv.SetNum("min_players",0);
kv.SetNum("max_players",65);
kv.SetString("tags_override","-");
kv.SetString("description_override","-");
}
kv.Rewind();
ExportKV(kv,votelistpath);
PrintToChat(client,"scenario %s added to vote list",arg2);
}
else
{
PrintToChat(client,"second argument must be valid scenario name. Check !scenariolist");
}
}
else if(StrEqual(arg1,"remove",false))
{
if(hasArg2)
{
kv.JumpToKey("scenarios",true);
kv.DeleteKey(arg2);
kv.Rewind();
ExportKV(kv,votelistpath);
PrintToChat(client,"scenario %s removed from vote list",arg2);
}
else
{
PrintToChat(client,"second argument must be valid scenario name. Check !scenariolist");
}
}
else
{
PrintToChat(client,"first argument must be add/remove/enable/disable");
}
}
delete kv;
return Plugin_Handled;
}
ExportKV(KeyValues kv,char[] path)
{
kv.ExportToFile(path);
......@@ -4566,25 +4064,7 @@ GetScenarioBackupPath(char[] path,int size,char[] filename)
}
GetVoteListPath(char[] path,int size)
{
char mapPath[64];
GetScenarioMapPath(mapPath,size);
Format(path,size,"%s/votelist.txt",mapPath);
}
GetActingVoteListPath(char[] path,int size)
{
char mapPath[64];
GetScenarioMapPath(mapPath,size);
Format(path,size,"%s/votelist.txt",mapPath);
if(!FileExists(path))
{
char basePath[64];
ef_votelist_base.GetString(basePath,sizeof(basePath));
Format(path,size,"%s/%s",mapPath,basePath);
}