Skip to content
Open

Teams #110

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Client/App/App.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,14 @@
RelativePath=".\v8datamodel\RootInstance.cpp"
>
</File>
<File
RelativePath=".\v8datamodel\Team.cpp"
>
</File>
<File
RelativePath=".\v8datamodel\Teams.cpp"
>
</File>
</Filter>
<Filter
Name="v8xml"
Expand Down
5 changes: 4 additions & 1 deletion Client/App/include/v8datamodel/BrickColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ namespace RBX

public:
BrickColor(int number);
BrickColor();
BrickColor()
: number(lego_194)
{
}
BrickColor(Number number)
: number(number)
{
Expand Down
6 changes: 3 additions & 3 deletions Client/App/include/v8datamodel/Team.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace RBX
virtual bool askSetParent(const Instance*) const;
virtual bool askAddChild(const Instance*) const;
int getScore() const;
void setScore(int);
void setScore(int newScore);
BrickColor getTeamColor() const;
void setTeamColor(BrickColor);
void setTeamColor(BrickColor newColor);
bool getAutoAssignable() const;
void setAutoAssignable(bool);
void setAutoAssignable(bool value);
public:
//Team& operator=(const Team&);
};
Expand Down
15 changes: 9 additions & 6 deletions Client/App/include/v8datamodel/Teams.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ namespace RBX
Teams();
virtual ~Teams();
public:
void assignNewPlayerToTeam(Network::Player*);
int getNumPlayersInTeam(BrickColor);
bool teamExists(BrickColor);
void assignNewPlayerToTeam(Network::Player* player);
int getNumPlayersInTeam(BrickColor brickColor);
bool teamExists(BrickColor brickColor);
bool isTeamGame();
void rebalanceTeams();
BrickColor getUnusedTeamColor();
Team* getTeamFromTeamColor(BrickColor);
Team* getTeamFromTeamColor(BrickColor brickColor);
Team* getTeamFromPlayer(Network::Player*);
boost::shared_ptr<const std::vector<boost::shared_ptr<Instance>>> getTeams();
G3D::Color3 getTeamColorForHumanoid(Humanoid*);
boost::shared_ptr<const std::vector<boost::shared_ptr<Instance>>> getTeams()
{
return teams.read();
}
G3D::Color3 getTeamColorForHumanoid(Humanoid* humanoid);
protected:
virtual void onChildAdded(Instance*);
virtual void onChildRemoving(Instance*);
Expand Down
52 changes: 52 additions & 0 deletions Client/App/v8datamodel/Team.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "v8datamodel/Team.h"

namespace RBX
{
const char* sTeam = "Team";

static const Reflection::PropDescriptor<Team, int> prop_Score("Score", "Data", &Team::getScore, &Team::setScore, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Team, BrickColor> prop_Color("TeamColor", "Data", &Team::getTeamColor, &Team::setTeamColor, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Team, bool> prop_AutoAssignable("AutoAssignable", "Data", &Team::getAutoAssignable, &Team::setAutoAssignable, Reflection::PropertyDescriptor::STANDARD);

Team::Team()
: score(0),
autoAssignable(true),
autoColorCharacters(true)
{
setName("Team");
color = BrickColor::lego_1;
}

int Team::getScore() const
{
return score;
}

void Team::setScore(int newScore)
{
score = newScore;
raisePropertyChanged(prop_Score);
}

BrickColor Team::getTeamColor() const
{
return color;
}

void Team::setTeamColor(BrickColor newColor)
{
color = newColor;
raisePropertyChanged(prop_Color);
}

bool Team::getAutoAssignable() const
{
return autoAssignable;
}

void Team::setAutoAssignable(bool value)
{
autoAssignable = value;
raisePropertyChanged(prop_AutoAssignable);
}
}
105 changes: 105 additions & 0 deletions Client/App/v8datamodel/Teams.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "v8datamodel/Teams.h"
#include "v8datamodel/ModelInstance.h"
#include "Network/Players.h"

namespace RBX
{
const char* sTeams = "Teams";

Teams::Teams()
{
setName("Teams");
}

Team::~Team()
{
}

int Teams::getNumPlayersInTeam(BrickColor brickColor)
{
Network::Players* players = ServiceProvider::findServiceProvider(this)->find<Network::Players>();
RBXASSERT(players);

int numOfPlayers = 0;
for (size_t i = 0; i < players->numChildren(); i++)
{
Network::Player* player = fastDynamicCast<Network::Player>(players->getChild(i));
if (player)
{
if (!player->getNeutral() && player->getTeamColor() == brickColor)
numOfPlayers++;
}
}

return numOfPlayers;
}

bool Teams::teamExists(BrickColor brickColor)
{
return getTeamFromTeamColor(brickColor) != NULL;
}

Team* Teams::getTeamFromTeamColor(BrickColor brickColor)
{
for (size_t i = 0; i < numChildren(); i++)
{
Team* team = fastDynamicCast<Team>(getChild(i));
if (team && team->getTeamColor() == brickColor)
return team;
}

return NULL;
}

G3D::Color3 Teams::getTeamColorForHumanoid(Humanoid* humanoid)
{
Network::Players* players = ServiceProvider::findServiceProvider(this)->find<Network::Players>();
RBXASSERT(players);

for (size_t i = 0; i < players->numChildren(); i++)
{
Network::Player* player = fastDynamicCast<Network::Player>(players->getChild(i));
if (player)
{
if (!player->getNeutral() && player->getCharacter())
{
ModelInstance* character = player->getCharacter();
if (character->findFirstChildOfType<Humanoid>() == humanoid)
{
return player->getTeamColor().color3();
}
}
}
}

return G3D::Color3::white();
}

void Teams::assignNewPlayerToTeam(Network::Player* player)
{
BrickColor currentTeam = BrickColor::lego_28;
bool foundTeam = false;

for (size_t i = 0; i < numChildren(); i++)
{
Team* team = fastDynamicCast<Team>(getChild(i));
if (team)
{
if (team->getAutoAssignable() == true)
{
if (getNumPlayersInTeam(team->getTeamColor()) < currentTeam.number)
{
currentTeam = team->getTeamColor();
foundTeam = true;
}
}
}
}

if (foundTeam)
{
player->setTeamColor(currentTeam);
player->setNeutral(false);
}
}
}
15 changes: 12 additions & 3 deletions Client/Network/include/Network/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,20 @@ namespace RBX
public:
virtual XmlElement* write();
virtual void setName(const std::string&);
ModelInstance* getCharacter() const;
ModelInstance* getCharacter() const
{
return character.get();
}
void setCharacter(ModelInstance*);
BrickColor getTeamColor() const;
BrickColor getTeamColor() const
{
return teamColor;
}
void setTeamColor(BrickColor);
bool getNeutral() const;
bool getNeutral() const
{
return neutral;
}
void setNeutral(bool);
std::string getCharacterAppearance() const;
void setCharacterAppearance(const std::string&);
Expand Down