Commit 92823038 authored by Mikleo's avatar Mikleo
Browse files

Added commander picking, needs a lot more testing.

parent a319efeb
Pipeline #8533 passed with stages
in 25 seconds
......@@ -8,7 +8,7 @@
#include <empstats>
#include <updater>
#define PluginVersion "1.01"
#define PluginVersion "1.02"
#define UPDATE_URL "https://sourcemod.docs.empiresmod.com/DraftPick/dist/updater.txt"
......@@ -51,7 +51,7 @@ int stage = STAGE_DISABLED;
#define TEAM_BE 1;
ConVar mp_autoteambalance,mp_autoteambalance_skilldifference,cv_autoassign,cv_allowspectators,dp_default_draftmode, dp_default_draftmode_min_players,dp_captain_vote_time,dp_pick_wait_time,dp_pick_initial_multiplier,dp_time_increment,dp_in_draft,dp_maxpick,dp_squadlimitdefault,dp_autopick_randomizer,dp_autodraft_display_pick,dp_forceauto_max_imbalance,dp_overlay;
ConVar mp_autoteambalance,mp_autoteambalance_skilldifference,cv_autoassign,cv_allowspectators,dp_default_draftmode, dp_default_draftmode_min_players,dp_captain_vote_time,dp_pick_wait_time,dp_pick_initial_multiplier,dp_time_increment,dp_in_draft,dp_maxpick,dp_squadlimitdefault,dp_autopick_randomizer,dp_autodraft_display_pick,dp_forceauto_max_imbalance,dp_overlay,dp_autodraft_comms,dp_captainvote_playerratio;
int mp_autoteambalance_default = 1;
int cv_autoassign_default = 0;
......@@ -66,6 +66,8 @@ char sound_pick_music[128],sound_pick_end[128],sound_join_music[128],sound_opp_t
// stores the clientids of the captains.
int captains[2];
int captainVoteLimit = 1;
int captainsInVote = 0;
// if a captain was previously drafted, dont remove from team when they are removed as captain.
// still important
......@@ -91,6 +93,8 @@ int picksLeft = 0;
// could work around pause by detecting it.
int pickStartTime = 0;
int gameStageStartTime = 0;
int unlockTime = 0;
bool draftBegun = false;
......@@ -242,13 +246,14 @@ public void OnPluginStart()
dp_min_players = CreateConVar("dp_minplayers", "10", "The minimum number of players after which draft mode is disabled.");
dp_captain_vote_time = CreateConVar("dp_captain_vote_time", "100", "The time set in the captain vote stage");
dp_pick_wait_time = CreateConVar("dp_pick_wait_time", "60", "The time set in the pick wait stage");
dp_pick_wait_time = CreateConVar("w", "60", "The time set in the pick wait stage");
dp_pick_initial_multiplier = CreateConVar("dp_pick_initial_multiplier", "2", "Amount of initial time given to each captain per player");
dp_time_increment = CreateConVar("dp_time_increment", "3", "The time increment given to each captain per player in the pick phase");
dp_in_draft = CreateConVar("dp_in_draft", "0", "Notification of drafting. ignore");
dp_maxpick = CreateConVar("dp_maxpick", "40", "maximum number of picks before autopick");
dp_overlay = CreateConVar("dp_overlay", "draftpick/draft_background", "The overlay for draft mode.");
dp_autodraft_comms = CreateConVar("dp_autodraft_comms", "1", "Decide comms in autodraft.");
dp_captainvote_playerratio = CreateConVar("dp_captainvote_playerratio", "0.2", "Percent of players needed to vote for each captain");
dp_autodraft_display_pick = CreateConVar("dp_autodraft_display_pick", "0", "Should autodraft pick be displayed in chat");
......@@ -1032,8 +1037,12 @@ public Action Timer_Tick(Handle timer,client)
}
else if(stage == STAGE_AUTOPICKWAIT)
{
ChangeStage(STAGE_PICK);
AutoPickAll();
if(dp_autodraft_comms.IntValue == 0 || TryAssignCaptains())
{
ChangeStage(STAGE_PICK);
AutoPickAll();
}
}
else if (stage == STAGE_PICK)
{
......@@ -1045,7 +1054,17 @@ public Action Timer_Tick(Handle timer,client)
tickTime --;
}
char text[64];
if(stage == STAGE_CAPTAINVOTE || stage == STAGE_AUTOPICKWAIT && dp_autodraft_comms.IntValue == 1)
{
captainVoteLimit = RoundToCeil(GetTeamClientCount(2) * dp_captainvote_playerratio.FloatValue);
int leader1,leader2 = -1;
captainsInVote = NumCaptains() + GetVoteLeaders(captainVoteLimit,leader1,leader2);
}
char text[128];
if(stage == STAGE_GAME)
......@@ -1084,20 +1103,32 @@ public Action Timer_Tick(Handle timer,client)
else if(stage == STAGE_AUTOPICKWAIT)
{
Format(text,sizeof(text),"Team Selection in %d secs",tickTime);
}
float yPos;
char teamText[64];
float yPos = 0.92;
char teamText[128];
if(squadLimit > 0)
{
yPos = 0.9;
yPos -= 0.02;
Format(teamText,sizeof(teamText),"Press 'c' to join a squad\n%s",text);
}
else
{
yPos = 0.92;
Format(teamText,sizeof(teamText),"%s",text);
}
if(dp_autodraft_comms.IntValue == 1)
{
yPos -= 0.02;
Format(teamText,sizeof(teamText),"Vote for Commanders (%d/2)\n%s",captainsInVote,teamText);
}
SetHudTextParams(-1.0,yPos, 1.0, 255, 255, 255, 255);
ShowHudTextTeams(4,teamText);
SetHudTextParams(-1.0,0.9, 1.0, 255, 75, 75, 255);
......@@ -1242,17 +1273,18 @@ public Action Event_PlayerTeam(Event event, const char[] name, bool dontBroadcas
return Plugin_Continue;
}
void TryAssignCaptains()
int GetVoteLeaders(int numRequired,int &leader1,int &leader2)
{
int votes[MAXPLAYERS+1] = {0,...}; // votes for each player
EU_GetCommVoteCount(2,votes);
int voteLeaders = 0;
int mostVotesClient;
int mostVotes = 0;
int secondMostVotesClient;
int secondMostVotes = 0;
int mostVotesClient = -1;
int mostVotes = numRequired -1;
int secondMostVotesClient = -1;
int secondMostVotes = numRequired -1;
for (int i=1; i<=MaxClients; i++)
{
if(votes[i] >mostVotes)
......@@ -1271,27 +1303,68 @@ void TryAssignCaptains()
secondMostVotesClient = i;
}
}
if(mostVotesClient !=0)
if(mostVotesClient >=0)
{
SetCaptain(mostVotesClient,0);
leader1 = mostVotesClient;
voteLeaders++;
}
if(secondMostVotesClient >= 0 )
{
leader2 = secondMostVotesClient;
voteLeaders++;
}
if(!AreCaptainsFull() && secondMostVotesClient != 0)
return voteLeaders;
}
bool TryAssignCaptains()
{
int numCaptains = NumCaptains();
int requiredCaptains = 2- numCaptains;
int leader1 = -1;
int leader2 = -1;
if(GetVoteLeaders(1,leader1,leader2) >= requiredCaptains)
{
SetCaptain(secondMostVotesClient,0);
if(requiredCaptains >=1)
SetCaptain(leader1,0);
if(requiredCaptains >=2)
SetCaptain(leader2,0);
}
if(!AreCaptainsFull())
{
OptOutAll();
PrintToChatAll("\x04[DP] \x01Not all captains assigned. Resetting vote.");
tickTime = dp_captain_vote_time.IntValue;
if(draftMode == MODE_AUTODRAFT || draftMode == MODE_AUTOSQUADDRAFT)
{
PrintToChatAll("\x04[DP] \x01Not all commanders assigned. Resetting vote.");
tickTime = 20;
}
else
{
PrintToChatAll("\x04[DP] \x01Not all captains assigned. Resetting vote.");
tickTime = dp_captain_vote_time.IntValue;
}
return false;
}
else
{
return true;
}
}
bool AreCaptainsFull()
{
return captains[0] != 0 && captains[1] != 0;
}
int NumCaptains()
{
int capNum = 0;
if(captains[0] != 0)
capNum++;
if(captains[1] != 0)
capNum++;
return capNum;
}
BeginNewDraft()
{
draftBegun = true;
......@@ -1426,7 +1499,7 @@ void SetCaptain(int client,origin)
GetClientName(client,clientName,sizeof(clientName));
PrintToChatAll("%s%s\x01 made Captain of %s%s",teamcolors[target],clientName,teamcolors[target],teamnames[target]);
if(AreCaptainsFull())
if(stage == STAGE_CAPTAINVOTE && AreCaptainsFull())
{
ChangeStage(STAGE_PICKWAIT);
}
......@@ -1489,24 +1562,41 @@ void BeginPick()
// add on time at the start for how many picks they need to make.
teamTime[teamToPick] += dp_time_increment.IntValue * picksLeft;
pickStartTime = GetTime();
if(captains[teamToPick] > 0)
if(draftMode == MODE_DRAFT || draftMode == MODE_SQUADDRAFT)
{
char clientName[64];
GetClientName(captains[teamToPick],clientName,sizeof(clientName));
PrintToChatAll("\x04[DP] \x01It is %s%s\x01 time to pick, you have \x073399ff%d\x01 pick",teamcolors[teamToPick],clientName,picksLeft);
OptOutAll();
if(captains[teamToPick] > 0)
{
char clientName[64];
GetClientName(captains[teamToPick],clientName,sizeof(clientName));
PrintToChatAll("\x04[DP] \x01It is %s%s\x01 time to pick, you have \x073399ff%d\x01 pick",teamcolors[teamToPick],clientName,picksLeft);
}
if(captains[teamToPick] > 0)
EmitSoundToClient(captains[teamToPick],sound_your_turn);
if(captains[OppTeam(teamToPick)] > 0)
EmitSoundToClient(captains[OppTeam(teamToPick)],sound_opp_turn);
OptInCandidates();
}
tickTime = teamTime[teamToPick];
OptOutAll();
OptInCandidates();
if(captains[teamToPick] > 0)
EmitSoundToClient(captains[teamToPick],sound_your_turn);
if(captains[OppTeam(teamToPick)] > 0)
EmitSoundToClient(captains[OppTeam(teamToPick)],sound_opp_turn);
}
// pick players via the autopick list or randomly.
......@@ -1648,7 +1738,7 @@ void CheckMaxPick()
}
}
void CheckPickPlayers()
bool CheckPickPlayers()
{
int playersLeft = 0;
for (int i=1; i<=MaxClients; i++)
......@@ -1666,11 +1756,13 @@ void CheckPickPlayers()
if(playersLeft == 0)
{
ChangeStage(STAGE_GAME);
return true;
}
else if (squadIdentities && playersLeft <= squadLimit)
{
RemoveSquadIdentities();
}
return false;
}
void OptInCandidates()
......@@ -1906,6 +1998,8 @@ void SetUpDraft(mode)
Call_StartForward(g_DraftPhaseStart);
Call_Finish();
ServerCommand("eu_prelimcomm 0");
}
......@@ -1961,10 +2055,13 @@ DraftEnded()
if( squadLimit > 0 && draftBegun)
SquadModeEnd();
ServerCommand("eu_prelimcomm 1");
Call_StartForward(g_DraftPhaseEnd);
Call_Finish();
}
......@@ -2121,6 +2218,7 @@ public Action Command_Opt_Out(client, const String:command[], args)
if(stage == STAGE_PICK)
{
int team = GetSavedTeam(client);
// cant opt out if we dont have a team.
if(team == -1 )
{
......@@ -2128,6 +2226,15 @@ public Action Command_Opt_Out(client, const String:command[], args)
}
}
if(stage == STAGE_GAME)
{
int t = GetSavedTeam(client);
if(t >= 0 && captains[t] == client && (draftMode == MODE_AUTODRAFT || draftMode == MODE_AUTOSQUADDRAFT) && GetTime() < (gameStageStartTime + 30))
{
PrintToChat(client,"You must wait %d seconds before opting out",30 - (GetTime() - gameStageStartTime));
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action Command_Opt_In(client, const String:command[], args)
......@@ -2143,7 +2250,7 @@ public Action Command_Opt_In(client, const String:command[], args)
return Plugin_Handled;
}
}
else if(stage == STAGE_PICKWAIT || stage == STAGE_AUTOPICKWAIT)
else if(dp_autodraft_comms.IntValue == 0 && (stage == STAGE_PICKWAIT || stage == STAGE_AUTOPICKWAIT))
{
PrintToChat(client,"\x04[DP]\x01You cannot opt in because the teams have not been selected yet.");
return Plugin_Handled;
......@@ -2778,7 +2885,7 @@ Stage_Autopickwait_Start()
// prevent players entering comm vote.
OptOutAll();
AutopickWaitNotifyHandle = CreateTimer(8.0, Timer_AutoPickWaitNotify, _, TIMER_REPEAT);
AutopickWaitNotifyHandle = CreateTimer(16.0, Timer_AutoPickWaitNotify, _, TIMER_REPEAT);
tickTime = time;
......@@ -2821,6 +2928,11 @@ public Action Timer_AutoPickWaitNotify(Handle timer)
}
}
}
if(dp_autodraft_comms.IntValue ==1 )
{
PrintToChat(i,"\x04[DP] \x01Each commander needs \x04%d\x01 vote(s).",captainVoteLimit);
}
}
}
......@@ -2848,6 +2960,7 @@ int GetStartingTeam()
Stage_Pick_Start()
{
ServerCommand("es_showoptin 0");
if(!draftBegun)
{
BeginNewDraft();
......@@ -2885,6 +2998,7 @@ Stage_Pick_Start()
Stage_Pick_End()
{
StopMusic();
ServerCommand("es_showoptin 1");
}
Stage_Game_Start()
{
......@@ -2894,6 +3008,8 @@ Stage_Game_Start()
Format(mBuffer,sizeof(mBuffer),"\x04[DP] \x01 All players drafted. Vote for a commander and organize your teams!");
PrintToChatAllDelay(mBuffer,0.1);
gameStageStartTime = GetTime();
unlockTime = GetTime() + 30;
for (int i=1; i<=MaxClients; i++)
......@@ -2901,8 +3017,8 @@ Stage_Game_Start()
if(IsClientInGame(i))
{
int newTeam = GetSavedTeam(i) + 2;
int t = GetSavedTeam(i);
int newTeam = t + 2;
int currentTeam = GetClientTeam(i);
......@@ -2923,6 +3039,11 @@ Stage_Game_Start()
}
}
if(captains[t] == i)
{
// opt in here
FakeClientCommand(i,"emp_commander_vote_add_in");
}
}
......@@ -2944,6 +3065,24 @@ Stage_Game_Start()
}
public Action Timer_AfterGameStart(Handle timer)
{
for (int i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i))
{
int t = GetSavedTeam(i);
if(t>= 0 && captains[t] > 0)
{
// vote for captain here.
FakeClientCommand(i,"emp_commander_vote %d",captains[t]);
}
}
}
AfterGameStartHandle = INVALID_HANDLE;
cv_autoassign.IntValue = 1;
}
......@@ -3064,6 +3203,7 @@ Stage_Disabled_End()
Call_StartForward(g_DraftStart);
Call_Finish();
RefreshTeamBalanceCvars();
PrintToChatAll("\x04[DP] \x01Draft pick enabled");
......
"UnlitGeneric"
{
"$baseTexture" "draftpick/draft_background.vtf"
"$translucent" 1
"$selfillum" 1
}
"$baseTexture" "draftpick/draft_background.vtf"
"$translucent" 1
"$no_fullbright" 1
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
{
"Version"
{
"Latest" "1.01"
"Latest" "1.02"
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment