- Timestamp:
- Jun 11, 2013, 1:24:09 AM (12 years ago)
- Branches:
- master
- Children:
- 5b1e31e
- Parents:
- 11d21ee
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r11d21ee rff2133a 149 149 // set targets for all chasing players (or make them attack if they're close enough) 150 150 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) { 151 Player* p = &it->second; 152 151 //Player* p = &it->second; 152 it->second.updateTarget(mapPlayers); 153 154 /* 153 155 if (p->isChasing) { 154 156 p->target.x = mapPlayers[p->targetPlayer].pos.x; … … 164 166 } 165 167 } 168 */ 166 169 } 167 170 … … 171 174 bool broadcastMove = false; 172 175 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) { 176 cout << "Starting new for loop iteration" << endl; 173 177 oldPos = it->second.pos; 174 178 if (it->second.move(gameMap)) { … … 362 366 363 367 if (it->second.attackType == Player::ATTACK_MELEE) { 368 cout << "Melee attack" << endl; 369 364 370 Player* target = &mapPlayers[it->second.targetPlayer]; 365 371 … … 371 377 target->serialize(serverMsg.buffer); 372 378 }else if (it->second.attackType == Player::ATTACK_RANGED) { 379 cout << "Ranged attack" << endl; 380 373 381 Projectile proj(it->second.pos.x, it->second.pos.y, it->second.targetPlayer, it->second.damage); 374 382 proj.id = unusedProjectileId; … … 389 397 390 398 // broadcast either a PLAYER or PROJECTILE message 399 cout << "Broadcasting player or projectile message" << endl; 400 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 401 { 402 if (sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 403 error("sendMessage"); 404 } 405 cout << "Done broadcasting" << endl; 406 } 407 } 408 409 cout << "Done with the for loop" << endl; 410 411 // move all projectiles 412 cout << "Moving projectiles" << endl; 413 map<unsigned int, Projectile>::iterator itProj; 414 for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) { 415 if (itProj->second.move(mapPlayers)) { 416 // send a REMOVE_PROJECTILE message 417 cout << "send a REMOVE_PROJECTILE message" << endl; 418 serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE; 419 memcpy(serverMsg.buffer, &itProj->second.id, 4); 420 mapProjectiles.erase(itProj->second.id); 421 422 map<unsigned int, Player>::iterator it2; 423 cout << "Broadcasting REMOVE_PROJECTILE" << endl; 391 424 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 392 425 { … … 394 427 error("sendMessage"); 395 428 } 396 } 397 }398 399 // move all projectiles400 map<unsigned int, Projectile>::iterator itProj; 401 for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) {402 if (itProj->second.move(mapPlayers)) {403 // send a REMOVE_PROJECTILE message404 serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE; 405 memcpy(serverMsg.buffer, &itProj->second.id, 4);406 mapProjectiles.erase(itProj->second.id);407 408 map<unsigned int, Player>::iterator it2;429 430 cout << "send a PLAYER message after dealing damage" << endl; 431 // send a PLAYER message after dealing damage 432 Player* target = &mapPlayers[itProj->second.target]; 433 434 target->health -= itProj->second.damage; 435 if (target->health < 0) 436 target->health = 0; 437 438 serverMsg.type = MSG_TYPE_PLAYER; 439 target->serialize(serverMsg.buffer); 440 441 cout << "Sending a PLAYER message" << endl; 409 442 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 410 443 { … … 412 445 error("sendMessage"); 413 446 } 414 415 // send a PLAYER message after dealing damage 416 Player* target = &mapPlayers[itProj->second.target]; 417 418 target->health -= itProj->second.damage; 419 if (target->health < 0) 420 target->health = 0; 421 422 serverMsg.type = MSG_TYPE_PLAYER; 423 target->serialize(serverMsg.buffer); 424 425 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 426 { 427 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 428 error("sendMessage"); 429 } 430 } 431 } 432 } 447 } 448 } 449 } 450 cout << "Done moving projectiles" << endl; 433 451 434 452 n = receiveMessage(&clientMsg, sock, &from);
Note:
See TracChangeset
for help on using the changeset viewer.