Nestharus
o-o
- Reaction score
- 84
Edit
Version 1.2 Beta (still pre-release state)
Still improving this ><
Oh, the code will be here http://www.thehelper.net/forums/showpost.php?p=1171917&postcount=6
Version 1.2 Beta (still pre-release state)
Still improving this ><
Oh, the code will be here http://www.thehelper.net/forums/showpost.php?p=1171917&postcount=6
JASS:
library TeamManager uses PlayerTracker {
/*Utility Information
===================================================================
Name: C Team Player Manager
Version: 1.3
Author: Nestharus
Settings:
*///===================================================================
define private TEAM_MAX_SIZE = 12 //how many players can be in a team, should be max players for your current game
define private DO_TEAM_ALLIANCES = true //can teams ally and be neutral to each other?
define private AUTO_REMOVE_TEAMS = true //if a team has no players after a player is removed, remove that team?
define private AUTO_GAME_OVER_CHECK = true //if a team is destroyed and all remaining teams are allies, game over?
define private DO_PLAYER_DRIVEN_SETUP = true //if this is enabled, use TeamManager.playerSetup to set your teams up
//Whether or not to do specific team alliance properties. If something here is false, it is removed from system
define private DO_SHARED_XP = true
define private DO_SHARED_SPELLS = true
define private DO_SHARED_VISION = true
define private DO_SHARED_CONTROL = false
define private DO_SHARED_ADV_CONTROL = false
//these will only run if AUTO_GAME_OVER_CHECK is true
//////////////////////////////////////////////////////////////////////////////
//Code to run when game is over and there are winners. ActiveTeams will always be winners
//! textmacro GAME_OVER_CODE
//! endtextmacro
//Code to run when there is no winner
//! textmacro GAME_OVER_CODE_NO_WINNER
//! endtextmacro
//////////////////////////////////////////////////////////////////////////////
//What PLAYER_TYPE do you want?
//Supported Player Types- Human, Computer, InactivePlayer, ActivePlayer
define <TeamManager.PLAYER_TYPE> = Human
//these will only be applicable if DO_PLAYER_DRIVEN_SETUP
//////////////////////////////////////////////////////////////////////////////
//This is where you put your structs and globals etc for your interface code
//! textmacro PlayerDrivenInterfaceData
//! endtextmacro
//this is where run time code goes for your interface
//! textmacro PlayerDrivenInterfaceCode
//! endtextmacro
define private PlayerDrivenInterfaceProperties = {
private int GetPlayerVoteCount() {//used to retrieve total vote count
return Get##TeamManager.PLAYER_TYPE##Count() //default value, can change it but not suggested
}//GetPlayerVoteCount
}//PlayerDrivenInterfaceProperties
//////////////////////////////////////////////////////////////////////////////
//Default Values for Team Alliance Properties
define private TEAM_DEFAULT_ALLIANCE_VALUES = {
#if DO_SHARED_XP
public static constant bool SHARED_XP = true
#endif
#if DO_SHARED_SPELLS
public static constant bool SHARED_SPELLS = true
#endif
#if DO_SHARED_VISION
public static constant bool SHARED_VISION = true
#endif
#if DO_SHARED_CONTROL
public static constant bool SHARED_CONTROL = false
#endif
#if DO_SHARED_ADV_CONTROL
public static constant bool SHARED_ADV_CONTROL = false
#endif
}
/*//===================================================================
Description:
Team Manager was made to replace forces and do better force alliances and alliances between forces.
Teams are much faster than forces (direct array reads) and handle better alliances as well (array reads).
Furthermore, player alliances are automatically modified when they join/leave a team (ally/unally all players on that
team and all players on allied teams). You can access all teams a player is on and all players within a given team.
You can also quickly access all allied and neutral teams of a given team.
If you want alliances between players, Team Manager can still be used (each player is on their own team).
If you want shared alliances, add players to a common team and you are set.
If you are ever doing alliances for player teams, Team Manager is the way to go.
Team Manager requires that all players that are to be in TeamManager teams be unallied. This can be done in
Force Properties under Scenario. Uncheck all the check boxes if you want the force to run. Don't mess with the
alliances either or that'll screw with the flags. Do all alliances through Team Manager teams.
Big Features-
Automatic Management of Alliances
When DO_TEAM_ALLIANCES is marked as true, Team Manager will manage alliances between teams quickly and easily.
Alliances include neutral and allied alliance. If a team is neither of those, it's an enemy. As players
are added and removed from teams, their alliances with all players on all teams with a standing to the team
they are joining/leaving will be modified.
Team 1 is allied to Team 2
Team 2 has player 6
Player 1 joins Team 1
Player 6 and Player 1 are automatically allied
When allying/unallying two teams, all players on each team will be modified accordingly
Team 1 unallies Team 2
Player 6 and Player 1 are no longer allies
Automatic Team Removal
If AUTO_REMOVE_TEAMS is true, teams will be automatically destroyed when there are no players left in them
as .removePlayer is used.
Automatic Game Over Check
If AUTO_GAME_OVER_CHECK is true, TeamManager will automatically check if the game is over as teams
are destroyed by seeing if all remaining teams are allied or if there is only one team left.
GAME_OVER_CODE is run when the game ends and all active teams are the winners.
GAME_OVER_CODE_NO_WINNER is run if for some reason there are no active teams left (no winners)
Automatic Team Setup with 3 ways of doing it and an open interface
StaticSetup-
1- The teams will be set up based on what teams the players are in in the game lobby (your forces)
2- The teams will be set up based on a team count. In this case, players are put into teams based on their
player id. If team count is 4, players 0-2 will be on team 1, 3-5 on team 2, etc.
DynamicSetup-
Balances out the teams as much as possible given a team count. If there are 10 players and 6 teams,
teams 1 through 5 will have 2 players and team 6 will have 0
2, 2, 2, 2
1, 1 -> 2
PlayerDrivenSetup-
Players vote for how big they want their teams to be and teams are set up accordingly so
everyone is as happy as possible. It allows a user defined interface (data area and run time area)
and provides an API for recording votes. It also has a time limit feature.
It also tries to keep bigger team players happy by making it so no team can be bigger
than remaining players - remaining open slots on that team. Also, no player that wants
a small team will be put on a bigger team.
Example 1-
Player 1 votes team size of 6
Player 2 votes team size of 6
Player 3 votes team size of 6
Player 4 votes team size of 4
Player 5 votes team size of 4
First it gives smaller votes priority (votes are entered in a sorted array)
1 - empty
2 - empty
3- empty
4- player 4, 5
5- 1, 2, 3
6-12 empty
So this would be-
Team 1- Player 4, 5
Team 2- player 1, 2, 3
The reason for this isn't because they voted differently.
Team 1 had 2 open slots left (smallest vote was 4, so 4 players preferred)
The issue is that the team size of team 1 became >= to the remaining players and there weren't
enough slots to fit all the players into the team.
Because the votes are sorted, as the teams are made, each subsequent player wants a bigger team.
In this way, no current team can be equal to the remaining players. At the very least, the last
team will always be the biggest (big votes clumped together).
Smallest votes get priority by getting processed first
Biggest votes get priority by getting biggest possible team size
Another example-
Team 1- Player 4, 5, 6 (max size 4)
Team 2- Player 7, 8, 9 (max size 6)
As can be seen, the teams turn out balanced.
Loops-
tloop(team loop)- loop through active teams
tploop(team's players loop)- loop through players on a team
ptloop(player's teams loop)- loop through teams a player is on
taloop(team alliances)- loop through a team's alliance teams
tnloop(team neutrals)- loop through a team's neutral teams
Requirements: PlayerTracker
Installation: Unallied Forces
API
------------------------------------------------------------------
ActiveTeam-
public int operator count()
Returns how many teams there are
public int get(int index)
Retrieves an active team given an indexed index
Example-
Team myTeam = ActiveTeam.get(ActiveTeam.count-1)
TeamPlayer-
------------------------------------------------------------------
public int operator teamCount()
Returns how many teams the player is on
Example-
int playerTeamCount = TeamPlayer[0].teamCount
public int getTeam(int index)
Retrieves a team a player is on given an indexed id
Example-
Team myTeam = TeamPlayer[0].getTeam(TeamPlayer[0].teamCount)
public bool isOnTeam(int teamId)
Determines whether or not a player is on a team
Example-
bool isOnTeam = Player[0].isOnTeam(GetActiveTeam(0))
public bool isAllied(int playerId)
Determines whether a player is allied or not to another player
Example-
if TeamPlayer[0].isAllied(1) {
prinf("Player 0 is allied to Player 1")
}//if
else {
printf("Player 0 is not allied to Player 1")
}//else
public bool isNeutral(int playerId) - DO_TEAM_ALLIANCES
Determines whether a player is neutral or not to another player
Example-
if TeamPlayer[0].isNeutral(1) {
prinf("Player 0 is neutral to Player 1")
}//if
else {
printf("Player 0 is not neutral to Player 1")
}//else
Team-
------------------------------------------------------------------
Default Team Alliance Values-
public static constant bool SHARED_XP - DO_SHARED_XP
public static constant bool SHARED_SPELLS - DO_SHARED_SPELLS
public static constant bool SHARED_VISION - DO_SHARED_VISION
public static constant bool SHARED_CONTROL - DO_SHARED_CONTROL
public static constant bool SHARED_ADV_CONTROL - DO_SHARED_ADV_CONTROL
Team Specific Alliance Values-
public bool sharedXp - DO_SHARED_XP
public bool sharedSpells - DO_SHARED_SPELLS
public bool sharedVision - DO_SHARED_VISION
public bool sharedControl - DO_SHARED_CONTROL
public bool sharedAdvControl - DO_SHARED_ADV_CONTROL
public int teamNumber-
A number that can be assigned to a team. Doesn't do anything, but useful for games with specific areas
for different teams.
public int operator size()
Retrieves how many players are on the team
public int operator neutralCount() - DO_TEAM_ALLIANCES
Retrieves how many neutral alliances the team has with other teams
public int operator allyCount() - DO_TEAM_ALLIANCES
Retrieves how many allied alliances the team has with other teams
public int getPlayer(int index)
Retrieves a player id from a team given an indexed id for that team
Example-
int myPlayerId = myTeam.getPlayer(myTeam.size-1)
public int getNeutral(int index) - DO_TEAM_ALLIANCES
Retrieves a team that has a neutral alliance with this team given an indexed id for this team
Example-
Team neutralTeam = myTeam.getNeutral(myTeam.neutralCount-1)
public int getAlly(int index) - DO_TEAM_ALLIANCES
Retrieves a team that has an allied alliance with this team given an indexed id for this team
Example-
Team alliedTeam = myTeam.getAlly(myTeam.allyCount-1)
public void destroy()
Destroys the team clearing out all alliancs and players
public bool isAllied(Team team2) - DO_TEAM_ALLIANCES
Determines whether this team is allied with another team
Example-
bool areTheyAllied = myTeam.isAllied(shadyTeam)
public bool isNeutral(Team team2) - DO_TEAM_ALLIANCES
Determines whether this team is neutral to another team
Example-
bool areTheyNeutral = myTeam.isNeutral(shadyTeam)
public static void neutralTeam(Team team1, Team team2) - DO_TEAM_ALLIANCES
Adds a neutral flag to two teams. The teams won't be neutral unless they aren't allies, but the flag
will be there in case they stop being allies.
Example-
Team.neutralTeam(myTeam, shadyTeam)
public static void allyTeams(Team team1, Team team2) - DO_TEAM_ALLIANCES
Adds an ally flag to two teams. The teams will become allies no matter what.
Example-
Team.allyTeams(myTeam, shadyTeam)
public static void unallyTeams(Team team1, Team team2) - DO_TEAM_ALLIANCES
Removes an ally flag from two teams. The teams will stop being allies. If they have a neutral flag,
they will become neutral rather than become enemies.
Example-
Team.unallyTeams(myTeam, shadyTeam)
public static void removeNeutralTeams(Team team1, Team team2) - DO_TEAM_ALLIANCES
Removes a neutral flag from two teams. If the teams are allied, they will still be allied.
Example-
Team.removeNeutralTeams(myTeam, shadyTeam)
public void addPlayer(int playerId)
Adds a player to a team given a player id. Players added to teams will automatically have their alliances
altered in regards to all players on that team. The alliances will also be altered for all players on allied and
neutral teams for that team.
Example-
myTeam.addPlayer(4)
public void removePlayer(int playerId)
Removes a player from a team given a player id. Players removed from teams will automatically have their alliances
altered in regards to all players on that team. The alliances will also be altered for all players on allied and
neutral teams for that team.
Example-
myTeam.removePlayer(4)
public static Team create()
Creates a new team
Team Setups-
------------------------------------------------------------------
TeamManager.staticSetup
Generates run time code for automatically setting up teams. Teams set up in this way
will be based on the forces they are on in the game lobby.
Force 1-
Player 0
Empty
Empty
Force 2-
Player 2
Empty
Player 3
With automatic team setup-
Force 1- Player 0
Force 2- Player 2, 3
scope Test initializer Initialization {
private void Initialization() {
TeamManager.staticSetup
}//Initialization
}//Test
TeamManager.staticSetup(teamCount)
Generates run time code for automatically setting up teams. Teams set up in this way
will be based on the player ids and the teamCount specified.
Team Count = 6
Force 1-
Player 0
Empty
Empty
Force 2-
Player 2
Player 3
Player 6
With automatic team setup-
Force 1- Player 0
Force 2- Player 2, 3
Force 3- Empty
Force 4- Player 6
scope Test initializer Initialization {
private void Initialization() {
TeamManager.staticSetup(6)
}//Initialization
}//Test
TeamManager.dynamicSetup(teamCount, teamSize)
Generates run time code for automatically setting up teams. Teams set up in this way
will be based on the total player count and team count. The teams will be as balanced as possible across
as many teams as possible
Team Count = 3
Team Size = 4
Force 1-
Player 0
Empty
Empty
Force 2-
Player 2
Player 3
Player 6
With automatic team setup-
Force 1- Player 0, 2
Force 2- Player 3, 6
scope Test initializer Initialization {
private void Initialization() {
TeamManager.dynamicSetup(3, 4)
}//Initialization
}//Test
DO_PLAYER_DRIVEN_SETUP-
------------------------------------------------------------------
These are accessible only from within DO_PLAYER_DRIVEN_SETUP areas
private void SetVoteTimeLimit(real timeLimit)
Sets a time limit for voting
Example-
SetVoteTimeLimit(20)
private bool HasPlayerVoted(int playerId)
Checks to see whether or not a player has voted
private void SetPlayerVote(int playerId, int vote)
Sets how big of a team a player votes for
Player 6 votes for a team size of 3
Example-
SetPlayerVote(6, 3)
void TeamManager.playerSetup()
Runs player driven auto team creation
scope Test initializer Initialization {
private void Initialization() {
TeamManager.playerSetup()
}//Initialization
}//Test
PlayerDrivenInterfaceData
Place all of your interface data like structs, globals, functions, and etc goes here
//! textmacro PlayerDrivenInterfaceData
dialog crappyMenu = DialogCreate()
trigger crappyMenuButtonEvent = CreateTrigger()
private bool DialogClicked() {
}//DialogClicked
//! endtextmacro
PlayerDrivenInterfaceCode
Place all of your run time code here
//! textmacro PlayerDrivenInterfaceCode
TriggerRegisterDialogButtonEvent(crappyMenuButtonEvent, DialogAddButton(crappyMenu, "0", '0'))
TriggerAddCondition(crappyMenuButtonEvent, Condition(function DialogClicked))
//! endtextmacro
PlayerDrivenInterfaceProperties
Place various interface properties for the system and tinker with default ones.
AUTO_GAME_OVER_CHECK-
------------------------------------------------------------------
//! textmacro GAME_OVER_CODE
Place code to run for when the game is over
//! textmacro GAME_OVER_CODE
bool playerWon[]
int curTeam
ploop(curPlayer, Human, true)
tloop(curTeam, false)
if TeamPlayer[curPlayer].isOnTeam[curTeam] {
DisplayTextToPlayer(Player(curPlayer), 0, 0, "YOU WON "+GetPlayerName(Player(curPlayer))+"!!")
playerWon[curPlayer] = true
exitwhen true
}//if
endtloop(curTeam)
endploop(curPlayer)
ploop(curPlayer, Human, false)
if !playerWon[curPlayer] {
DisplayTextToPlayer(Player(curPlayer), 0, 0, "YOU LOST "+GetPlayerName(Player(curPlayer))+"!!")
}//if
endploop(curPlayer)
//! endtextmacro
//! textmacro GAME_OVER_CODE_NO_WINNER
Place code to run for when the game is over and there is no winner
//! textmacro GAME_OVER_CODE_NO_WINNER
printf("You lost " + GetPlayerName(GetLocalHuman())+"!!")
//! endtextmacro
Syntax Features
------------------------------------------------------------------
tloop(processVar, processDeclare)
loop through active teams
tploop(processTeam, processVar, processDeclare)
loop through players on a team
ptloop(processTeamPlayer, processVar, processDeclare)
loop through teams a player is on
taloop(processTeam, processVar, processDeclare)
loop through a team's alliance teams
tnloop(processTeam, processVar, processDeclare)
loop through a team's neutral teams
===================================================================*/