- Timestamp:
- Dec 22, 2013, 2:29:05 AM (11 years ago)
- Branches:
- master
- Children:
- 1d96513
- Parents:
- b8abc90
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
rb8abc90 r483a2cb 235 235 cout << "moving player" << endl; 236 236 bool broadcastMove = false; 237 238 // xompute playersInGame here 237 239 238 240 // move player and perform associated tasks … … 426 428 427 429 // check if the player's attack animation is complete 428 if ( it->second->isAttacking && it->second->timeAttackStarted+it->second->attackCooldown <= getCurrentMillis())430 if (p->isAttacking && p->timeAttackStarted+p->attackCooldown <= getCurrentMillis()) 429 431 { 430 it->second->isAttacking = false;432 p->isAttacking = false; 431 433 cout << "Attack animation is complete" << endl; 432 434 … … 435 437 436 438 serverMsg.type = MSG_TYPE_ATTACK; 437 memcpy(serverMsg.buffer, &it->second->id, 4); 438 memcpy(serverMsg.buffer+4, &it->second->targetPlayer, 4); 439 439 memcpy(serverMsg.buffer, &p->id, 4); 440 memcpy(serverMsg.buffer+4, &p->targetPlayer, 4); 441 442 map<unsigned int, Player*>& playersInGame = p->currentGame->getPlayers(); 440 443 map<unsigned int, Player*>::iterator it2; 441 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)444 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) 442 445 { 443 446 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 ) … … 445 448 } 446 449 447 if ( it->second->attackType == Player::ATTACK_MELEE)450 if (p->attackType == Player::ATTACK_MELEE) 448 451 { 449 452 cout << "Melee attack" << endl; 450 453 451 Player* target = mapPlayers[it->second->targetPlayer];452 damagePlayer(target, it->second->damage);454 Player* target = playersInGame[p->targetPlayer]; 455 damagePlayer(target, p->damage); 453 456 454 457 if (target->isDead) … … 461 464 462 465 if (flagType != WorldMap::OBJECT_NONE) { 463 addObjectToMap(flagType, target->pos.x, target->pos.y, gameMap, mapPlayers, msgProcessor, sock, outputLog);466 addObjectToMap(flagType, target->pos.x, target->pos.y, p->currentGame->getMap(), playersInGame, msgProcessor, sock, outputLog); 464 467 } 465 468 } … … 468 471 target->serialize(serverMsg.buffer); 469 472 } 470 else if ( it->second->attackType == Player::ATTACK_RANGED)473 else if (p->attackType == Player::ATTACK_RANGED) 471 474 { 472 475 cout << "Ranged attack" << endl; 473 476 474 Projectile proj( it->second->pos.x, it->second->pos.y, it->second->targetPlayer, it->second->damage);477 Projectile proj(p->pos.x, p->pos.y, p->targetPlayer, p->damage); 475 478 proj.id = unusedProjectileId; 476 479 updateUnusedProjectileId(unusedProjectileId, mapProjectiles); … … 491 494 // broadcast either a PLAYER or PROJECTILE message 492 495 cout << "Broadcasting player or projectile message" << endl; 493 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)496 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) 494 497 { 495 498 if (msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 ) … … 503 506 504 507 // move all projectiles 508 // see if this can be moved inside the game class 505 509 map<unsigned int, Projectile>::iterator itProj; 506 510 for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++)
Note:
See TracChangeset
for help on using the changeset viewer.