Changeset c76134b in network-game for server/server.cpp
- Timestamp:
- Jun 18, 2013, 11:16:21 PM (11 years ago)
- Branches:
- master
- Children:
- 66c4ec4
- Parents:
- 1d0ede1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r1d0ede1 rc76134b 43 43 void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers); 44 44 void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles); 45 void damagePlayer(Player *p, int damage); 45 46 46 47 // this should probably go somewhere in the common folder … … 150 151 // set targets for all chasing players (or make them attack if they're close enough) 151 152 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 152 193 if (it->second.updateTarget(mapPlayers)) { 153 194 serverMsg.type = MSG_TYPE_PLAYER; … … 364 405 365 406 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); 370 408 371 409 serverMsg.type = MSG_TYPE_PLAYER; … … 408 446 map<unsigned int, Projectile>::iterator itProj; 409 447 for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) { 448 cout << "About to call projectile move" << endl; 410 449 if (itProj->second.move(mapPlayers)) { 411 450 // send a REMOVE_PROJECTILE message … … 427 466 Player* target = &mapPlayers[itProj->second.target]; 428 467 429 target->health -= itProj->second.damage; 430 if (target->health < 0) 431 target->health = 0; 468 damagePlayer(target, itProj->second.damage); 432 469 433 470 serverMsg.type = MSG_TYPE_PLAYER; … … 441 478 } 442 479 } 480 cout << "Projectile was not moved" << endl; 443 481 } 444 482 } … … 860 898 id++; 861 899 } 900 901 void 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.