Changeset 53643ca in network-game for common/Game.cpp
- Timestamp:
- Jul 19, 2014, 12:32:33 AM (10 years ago)
- Branches:
- master
- Children:
- 4c00935
- Parents:
- cdb0e98
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Game.cpp
rcdb0e98 r53643ca 217 217 p->takeDamage(damage); 218 218 219 if (p->isDead) 220 { 219 if (p->isDead) { 221 220 ObjectType flagType = OBJECT_NONE; 222 221 if (p->hasBlueFlag) … … 240 239 bool gameFinished = false; 241 240 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); 246 243 } 247 244 248 245 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++) { 251 247 it->second->currentGame = NULL; 252 248 } … … 279 275 bool ownFlagAtBase = false; 280 276 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)) { 283 278 case STRUCTURE_BLUE_FLAG: 284 279 { 285 if (p->team == 0 && p->hasRedFlag) 286 { 280 if (p->team == 0 && p->hasRedFlag) { 287 281 // check that your flag is at your base 288 282 pos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG); … … 291 285 vector<WorldMap::Object>::iterator itObjects; 292 286 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) { 299 290 ownFlagAtBase = true; 300 291 break; … … 303 294 } 304 295 305 if (ownFlagAtBase) 306 { 296 if (ownFlagAtBase) { 307 297 p->hasRedFlag = false; 308 298 flagType = OBJECT_RED_FLAG; … … 317 307 case STRUCTURE_RED_FLAG: 318 308 { 319 if (p->team == 1 && p->hasBlueFlag) 320 { 309 if (p->team == 1 && p->hasBlueFlag) { 321 310 // check that your flag is at your base 322 311 pos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG); … … 325 314 vector<WorldMap::Object>::iterator itObjects; 326 315 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) { 333 319 ownFlagAtBase = true; 334 320 break; … … 337 323 } 338 324 339 if (ownFlagAtBase) 340 { 325 if (ownFlagAtBase) { 341 326 p->hasBlueFlag = false; 342 327 flagType = OBJECT_BLUE_FLAG; … … 355 340 } 356 341 357 if (flagTurnedIn) 358 { 342 if (flagTurnedIn) { 359 343 unsigned int blueScore = this->blueScore; 360 344 unsigned int redScore = this->redScore; … … 399 383 POSITION structPos; 400 384 401 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) 402 { 385 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) { 403 386 POSITION pos = itObjects->pos; 404 387 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) { 410 390 structPos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG); 411 391 flagReturned = true; 412 392 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) { 417 394 structPos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG); 418 395 flagReturned = true; … … 422 399 } 423 400 424 if (flagReturned) 425 { 401 if (flagReturned) { 426 402 itObjects->pos.x = structPos.x*25+12; 427 403 itObjects->pos.y = structPos.y*25+12; … … 432 408 } 433 409 434 if (broadcastMove) 435 { 410 if (broadcastMove) { 436 411 serverMsg.type = MSG_TYPE_PLAYER; 437 412 p->serialize(serverMsg.buffer); … … 443 418 444 419 // 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()) { 447 421 p->isAttacking = false; 448 422 cout << "Attack animation is complete" << endl; … … 451 425 cout << "about to broadcast attack" << endl; 452 426 453 if (p->attackType == Player::ATTACK_MELEE) 454 { 427 if (p->attackType == Player::ATTACK_MELEE) { 455 428 cout << "Melee attack" << endl; 456 429 457 430 Player* target = players[p->getTargetPlayer()]; 458 431 this->dealDamageToPlayer(target, p->damage); 459 } 460 else if (p->attackType == Player::ATTACK_RANGED) 461 { 432 } else if (p->attackType == Player::ATTACK_RANGED) { 462 433 cout << "Ranged attack" << endl; 463 434 … … 476 447 memcpy(serverMsg.buffer+12, &targetId, 4); 477 448 msgProcessor->broadcastMessage(serverMsg, players); 478 } 479 else 449 } else 480 450 cout << "Invalid attack type: " << p->attackType << endl; 481 451 }
Note:
See TracChangeset
for help on using the changeset viewer.