Changeset 48801af in network-game


Ignore:
Timestamp:
Nov 11, 2014, 1:20:11 AM (10 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
85da778
Parents:
c941e07
Message:

Use an enum for the player's team

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    rc941e07 r48801af  
    3030   this->range = 0;
    3131   this->attackCooldown = 0;
    32    this->team = 0;   // no team by default
     32   this->team = TEAM_NONE;
    3333   this->hasBlueFlag = false;
    3434   this->hasRedFlag = false;
     
    104104   this->range = 0;
    105105   this->attackCooldown = 0;
    106    this->team = 0;   // no team by default
     106   this->team = TEAM_NONE;
    107107   this->hasBlueFlag = false;
    108108   this->hasRedFlag = false;
  • common/Player.h

    rc941e07 r48801af  
    3939      ATTACK_MELEE,
    4040      ATTACK_RANGED
     41   };
     42
     43   enum PlayerTeam {
     44      TEAM_NONE,
     45      TEAM_BLUE,
     46      TEAM_RED
    4147   };
    4248
     
    8490   int range;
    8591   unsigned long long attackCooldown;
    86    int team; // 0 is none, 1 is blue, 2 is red
     92   PlayerTeam team;
    8793   bool hasBlueFlag;
    8894   bool hasRedFlag;
  • server/server.cpp

    rc941e07 r48801af  
    139139                  switch (p->team)
    140140                  {
    141                   case 1:// blue team
     141                  case Player::TEAM_BLUE:
    142142                     spawnPos = p->currentGame->getMap()->getStructureLocation(STRUCTURE_BLUE_FLAG);
    143143                     break;
    144                   case 2:// red team
     144                  case Player::TEAM_RED:
    145145                     spawnPos = p->currentGame->getMap()->getStructureLocation(STRUCTURE_RED_FLAG);
    146146                     break;
     
    781781         map<unsigned int, Player*>& oldPlayers = g->getPlayers();
    782782         g->addPlayer(p);
    783          p->team = 0;
     783         p->team = Player::TEAM_NONE;
    784784
    785785         // send info to other players
     
    922922         case STRUCTURE_BLUE_FLAG:
    923923         {
    924             if (p->team == 1 && p->hasRedFlag) {
     924            if (p->team == Player::TEAM_BLUE && p->hasRedFlag) {
    925925               // check that your flag is at your base
    926926               pos = game->getMap()->getStructureLocation(STRUCTURE_BLUE_FLAG);
     
    951951         case STRUCTURE_RED_FLAG:
    952952         {
    953             if (p->team == 2 && p->hasBlueFlag) {
     953            if (p->team == Player::TEAM_RED && p->hasBlueFlag) {
    954954               // check that your flag is at your base
    955955               pos = game->getMap()->getStructureLocation(STRUCTURE_RED_FLAG);
     
    10481048
    10491049         if (posDistance(p->pos, pos.toFloat()) < 10) {
    1050             if (p->team == 1 && itObjects->type == OBJECT_BLUE_FLAG) {
     1050            if (p->team == Player::TEAM_BLUE && itObjects->type == OBJECT_BLUE_FLAG) {
    10511051               structPos = game->getMap()->getStructureLocation(STRUCTURE_BLUE_FLAG);
    10521052               flagReturned = true;
    10531053               break;
    1054             } else if (p->team == 2 && itObjects->type == OBJECT_RED_FLAG) {
     1054            } else if (p->team == Player::TEAM_RED && itObjects->type == OBJECT_RED_FLAG) {
    10551055               structPos = game->getMap()->getStructureLocation(STRUCTURE_RED_FLAG);
    10561056               flagReturned = true;
Note: See TracChangeset for help on using the changeset viewer.