Changeset 53643ca in network-game for common/Game.cpp


Ignore:
Timestamp:
Jul 19, 2014, 12:32:33 AM (10 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
4c00935
Parents:
cdb0e98
Message:

Server loads user profile and game history info from the database, saves game history to the db after every game, and uses a lua settings file to load db settings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    rcdb0e98 r53643ca  
    217217   p->takeDamage(damage);
    218218
    219    if (p->isDead)
    220    {
     219   if (p->isDead) {
    221220      ObjectType flagType = OBJECT_NONE;
    222221      if (p->hasBlueFlag)
     
    240239   bool gameFinished = false;
    241240
    242    for (it = this->getPlayers().begin(); it != this->getPlayers().end(); it++)
    243    {
    244       gameFinished = gameFinished ||
    245          this->handlePlayerEvents(it->second);
     241   for (it = this->getPlayers().begin(); it != this->getPlayers().end(); it++) {
     242      gameFinished = gameFinished || this->handlePlayerEvents(it->second);
    246243   }
    247244
    248245   if (gameFinished) {
    249       for (it = this->players.begin(); it != this->players.end(); it++)
    250       {
     246      for (it = this->players.begin(); it != this->players.end(); it++) {
    251247         it->second->currentGame = NULL;
    252248      }
     
    279275      bool ownFlagAtBase = false;
    280276
    281       switch(this->worldMap->getStructure(p->pos.x/25, p->pos.y/25))
    282       {
     277      switch(this->worldMap->getStructure(p->pos.x/25, p->pos.y/25)) {
    283278         case STRUCTURE_BLUE_FLAG:
    284279         {
    285             if (p->team == 0 && p->hasRedFlag)
    286             {
     280            if (p->team == 0 && p->hasRedFlag) {
    287281               // check that your flag is at your base
    288282               pos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
     
    291285               vector<WorldMap::Object>::iterator itObjects;
    292286
    293                for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
    294                {
    295                   if (itObjects->type == OBJECT_BLUE_FLAG)
    296                   {
    297                      if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12)
    298                      {
     287               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
     288                  if (itObjects->type == OBJECT_BLUE_FLAG) {
     289                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) {
    299290                        ownFlagAtBase = true;
    300291                        break;
     
    303294               }
    304295
    305                if (ownFlagAtBase)
    306                {
     296               if (ownFlagAtBase) {
    307297                  p->hasRedFlag = false;
    308298                  flagType = OBJECT_RED_FLAG;
     
    317307         case STRUCTURE_RED_FLAG:
    318308         {
    319             if (p->team == 1 && p->hasBlueFlag)
    320             {
     309            if (p->team == 1 && p->hasBlueFlag) {
    321310               // check that your flag is at your base
    322311               pos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
     
    325314               vector<WorldMap::Object>::iterator itObjects;
    326315
    327                for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
    328                {
    329                   if (itObjects->type == OBJECT_RED_FLAG)
    330                   {
    331                      if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12)
    332                      {
     316               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
     317                  if (itObjects->type == OBJECT_RED_FLAG) {
     318                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) {
    333319                        ownFlagAtBase = true;
    334320                        break;
     
    337323               }
    338324
    339                if (ownFlagAtBase)
    340                {
     325               if (ownFlagAtBase) {
    341326                  p->hasBlueFlag = false;
    342327                  flagType = OBJECT_BLUE_FLAG;
     
    355340      }
    356341
    357       if (flagTurnedIn)
    358       {
     342      if (flagTurnedIn) {
    359343         unsigned int blueScore = this->blueScore;
    360344         unsigned int redScore = this->redScore;
     
    399383      POSITION structPos;
    400384
    401       for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
    402       {
     385      for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
    403386         POSITION pos = itObjects->pos;
    404387
    405          if (posDistance(p->pos, pos.toFloat()) < 10)
    406          {
    407             if (p->team == 0 &&
    408                 itObjects->type == OBJECT_BLUE_FLAG)
    409             {
     388         if (posDistance(p->pos, pos.toFloat()) < 10) {
     389            if (p->team == 0 && itObjects->type == OBJECT_BLUE_FLAG) {
    410390               structPos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
    411391               flagReturned = true;
    412392               break;
    413             }
    414             else if (p->team == 1 &&
    415                      itObjects->type == OBJECT_RED_FLAG)
    416             {
     393            } else if (p->team == 1 && itObjects->type == OBJECT_RED_FLAG) {
    417394               structPos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
    418395               flagReturned = true;
     
    422399      }
    423400
    424       if (flagReturned)
    425       {
     401      if (flagReturned) {
    426402         itObjects->pos.x = structPos.x*25+12;
    427403         itObjects->pos.y = structPos.y*25+12;
     
    432408      }
    433409
    434       if (broadcastMove)
    435       {
     410      if (broadcastMove) {
    436411         serverMsg.type = MSG_TYPE_PLAYER;
    437412         p->serialize(serverMsg.buffer);
     
    443418
    444419   // check if the player's attack animation is complete
    445    if (p->isAttacking && p->timeAttackStarted+p->attackCooldown <= getCurrentMillis())
    446    {
     420   if (p->isAttacking && p->timeAttackStarted+p->attackCooldown <= getCurrentMillis()) {
    447421      p->isAttacking = false;
    448422      cout << "Attack animation is complete" << endl;
     
    451425      cout << "about to broadcast attack" << endl;
    452426
    453       if (p->attackType == Player::ATTACK_MELEE)
    454       {
     427      if (p->attackType == Player::ATTACK_MELEE) {
    455428         cout << "Melee attack" << endl;
    456429
    457430         Player* target = players[p->getTargetPlayer()];
    458431         this->dealDamageToPlayer(target, p->damage);
    459       }
    460       else if (p->attackType == Player::ATTACK_RANGED)
    461       {
     432      } else if (p->attackType == Player::ATTACK_RANGED) {
    462433         cout << "Ranged attack" << endl;
    463434
     
    476447         memcpy(serverMsg.buffer+12, &targetId, 4);
    477448         msgProcessor->broadcastMessage(serverMsg, players);
    478       }
    479       else
     449      } else
    480450         cout << "Invalid attack type: " << p->attackType << endl;
    481451   }
Note: See TracChangeset for help on using the changeset viewer.