Changeset c76134b in network-game for server


Ignore:
Timestamp:
Jun 18, 2013, 11:16:21 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
66c4ec4
Parents:
1d0ede1
Message:

A player respawns at their flag 10 seconds after dying

Location:
server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/DataAccess.cpp

    r1d0ede1 rc76134b  
    8484      cout << "Creating a new player" << endl;
    8585      p = new Player(string(row[1]), string(row[2]));
     86      cout << "Created new player" << endl;
    8687   }else {
    8788      cout << "Returned no results for some reason" << endl;
  • server/server.cpp

    r1d0ede1 rc76134b  
    4343void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers);
    4444void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles);
     45void damagePlayer(Player *p, int damage);
    4546
    4647// this should probably go somewhere in the common folder
     
    150151         // set targets for all chasing players (or make them attack if they're close enough)
    151152         for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
     153            // check if it's time to revive dead players
     154            if (it->second.isDead) {
     155               if (getCurrentMillis() - it->second.timeDied >= 10000) {
     156                  it->second.isDead = false;
     157
     158                  POSITION spawnPos;
     159 
     160                  switch (it->second.team) {
     161                  case 0:// blue team
     162                     spawnPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     163                     break;
     164                  case 1:// red team
     165                     spawnPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     166                     break;
     167                  default:
     168                     // should never go here
     169                     cout << "Error: Invalid team" << endl;
     170                     break;
     171                  }
     172
     173                  // spawn the player to the right of their flag location
     174                  spawnPos.x = (spawnPos.x+1) * 25 + 12;
     175                  spawnPos.y = spawnPos.y * 25 + 12;
     176
     177                  it->second.pos = spawnPos.toFloat();
     178
     179                  serverMsg.type = MSG_TYPE_PLAYER;
     180                  it->second.serialize(serverMsg.buffer);
     181
     182                  map<unsigned int, Player>::iterator it2;
     183                  for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     184                  {
     185                     if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
     186                        error("sendMessage");
     187                  }
     188               }
     189
     190               continue;
     191            }
     192
    152193            if (it->second.updateTarget(mapPlayers)) {
    153194               serverMsg.type = MSG_TYPE_PLAYER;
     
    364405
    365406                  Player* target = &mapPlayers[it->second.targetPlayer];
    366 
    367                   target->health -= it->second.damage;
    368                   if (target->health < 0)
    369                      target->health = 0;
     407                  damagePlayer(target, it->second.damage);
    370408
    371409                  serverMsg.type = MSG_TYPE_PLAYER;
     
    408446         map<unsigned int, Projectile>::iterator itProj;
    409447         for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) {
     448            cout << "About to call projectile move" << endl;
    410449            if (itProj->second.move(mapPlayers)) {
    411450               // send a REMOVE_PROJECTILE message
     
    427466               Player* target = &mapPlayers[itProj->second.target];
    428467
    429                target->health -= itProj->second.damage;
    430                if (target->health < 0)
    431                   target->health = 0;
     468               damagePlayer(target, itProj->second.damage);
    432469
    433470               serverMsg.type = MSG_TYPE_PLAYER;
     
    441478               }
    442479            }
     480            cout << "Projectile was not moved" << endl;
    443481         }
    444482      }
     
    860898      id++;
    861899}
     900
     901void damagePlayer(Player *p, int damage) {
     902   p->health -= damage;
     903   if (p->health < 0)
     904      p->health = 0;
     905   if (p->health == 0) {
     906      p->isDead = true;
     907      p->timeDied = getCurrentMillis();
     908   }
     909}
Note: See TracChangeset for help on using the changeset viewer.