* Handles some calculations when the path is finished. */
| 469 | * Handles some calculations when the path is finished. |
| 470 | */ |
| 471 | void UnitWalkBState::postPathProcedures() |
| 472 | { |
| 473 | _action.TU = 0; |
| 474 | if (_unit->getFaction() != FACTION_PLAYER) |
| 475 | { |
| 476 | int dir = _action.finalFacing; |
| 477 | if (_action.finalAction) |
| 478 | { |
| 479 | _unit->dontReselect(); |
| 480 | } |
| 481 | if (_unit->getCharging() != 0) |
| 482 | { |
| 483 | dir = _parent->getTileEngine()->getDirectionTo(_unit->getPosition(), _unit->getCharging()->getPosition()); |
| 484 | if (_parent->getTileEngine()->validMeleeRange(_unit, _action.actor->getCharging(), dir)) |
| 485 | { |
| 486 | BattleAction action; |
| 487 | action.actor = _unit; |
| 488 | action.target = _unit->getCharging()->getPosition(); |
| 489 | action.weapon = _unit->getMainHandWeapon(); |
| 490 | action.type = BA_HIT; |
| 491 | action.TU = _unit->getActionTUs(action.type, action.weapon); |
| 492 | action.targeting = true; |
| 493 | _unit->setCharging(0); |
| 494 | _parent->statePushBack(new ProjectileFlyBState(_parent, action)); |
| 495 | } |
| 496 | } |
| 497 | else if (_unit->_hidingForTurn) |
| 498 | { |
| 499 | dir = _unit->getDirection() + 4; |
| 500 | _unit->_hidingForTurn = false; |
| 501 | _unit->dontReselect(); |
| 502 | } |
| 503 | if (dir != -1) |
| 504 | { |
| 505 | if (dir >= 8) |
| 506 | { |
| 507 | dir -= 8; |
| 508 | } |
| 509 | _unit->lookAt(dir); |
| 510 | while (_unit->getStatus() == STATUS_TURNING) |
| 511 | { |
| 512 | _unit->turn(); |
| 513 | _parent->getTileEngine()->calculateFOV(_unit); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | else if (!_parent->getPanicHandled()) |
| 518 | { |
| 519 | //todo: set the unit to aggrostate and try to find cover? |
| 520 | _unit->setTimeUnits(0); |
| 521 | } |
| 522 | |
| 523 | _unit->setCache(0); |
| 524 | _terrain->calculateUnitLighting(); |
| 525 | _terrain->calculateFOV(_unit); |
| 526 | _parent->getMap()->cacheUnit(_unit); |
| 527 | if (!_falling) |
| 528 | _parent->popState(); |
nothing calls this directly
no test coverage detected