diff --git a/Client/App/App.vcproj b/Client/App/App.vcproj index 813b5c2f..82ea9ce9 100644 --- a/Client/App/App.vcproj +++ b/Client/App/App.vcproj @@ -1322,6 +1322,14 @@ RelativePath=".\v8datamodel\RootInstance.cpp" > + + + + >> getTeams(); - G3D::Color3 getTeamColorForHumanoid(Humanoid*); + boost::shared_ptr>> getTeams() + { + return teams.read(); + } + G3D::Color3 getTeamColorForHumanoid(Humanoid* humanoid); protected: virtual void onChildAdded(Instance*); virtual void onChildRemoving(Instance*); diff --git a/Client/App/v8datamodel/Team.cpp b/Client/App/v8datamodel/Team.cpp new file mode 100644 index 00000000..3431de76 --- /dev/null +++ b/Client/App/v8datamodel/Team.cpp @@ -0,0 +1,52 @@ +#include "v8datamodel/Team.h" + +namespace RBX +{ + const char* sTeam = "Team"; + + static const Reflection::PropDescriptor prop_Score("Score", "Data", &Team::getScore, &Team::setScore, Reflection::PropertyDescriptor::STANDARD); + static const Reflection::PropDescriptor prop_Color("TeamColor", "Data", &Team::getTeamColor, &Team::setTeamColor, Reflection::PropertyDescriptor::STANDARD); + static const Reflection::PropDescriptor 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); + } +} \ No newline at end of file diff --git a/Client/App/v8datamodel/Teams.cpp b/Client/App/v8datamodel/Teams.cpp new file mode 100644 index 00000000..71005b1a --- /dev/null +++ b/Client/App/v8datamodel/Teams.cpp @@ -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(); + RBXASSERT(players); + + int numOfPlayers = 0; + for (size_t i = 0; i < players->numChildren(); i++) + { + Network::Player* player = fastDynamicCast(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(getChild(i)); + if (team && team->getTeamColor() == brickColor) + return team; + } + + return NULL; + } + + G3D::Color3 Teams::getTeamColorForHumanoid(Humanoid* humanoid) + { + Network::Players* players = ServiceProvider::findServiceProvider(this)->find(); + RBXASSERT(players); + + for (size_t i = 0; i < players->numChildren(); i++) + { + Network::Player* player = fastDynamicCast(players->getChild(i)); + if (player) + { + if (!player->getNeutral() && player->getCharacter()) + { + ModelInstance* character = player->getCharacter(); + if (character->findFirstChildOfType() == 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(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); + } + } +} \ No newline at end of file diff --git a/Client/Network/include/Network/Player.h b/Client/Network/include/Network/Player.h index 8c3cdee0..1bef48de 100644 --- a/Client/Network/include/Network/Player.h +++ b/Client/Network/include/Network/Player.h @@ -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&);