* Marks tiles for the path preview. * @param bRemove Remove preview? * @return True, if a path is previewed. */
| 837 | * @return True, if a path is previewed. |
| 838 | */ |
| 839 | bool Pathfinding::previewPath(bool bRemove) |
| 840 | { |
| 841 | if (_path.empty()) |
| 842 | return false; |
| 843 | |
| 844 | if (!bRemove && _pathPreviewed) |
| 845 | return false; |
| 846 | |
| 847 | _pathPreviewed = !bRemove; |
| 848 | |
| 849 | Position pos = _unit->getPosition(); |
| 850 | Position destination; |
| 851 | int tus = _unit->getTimeUnits(); |
| 852 | if (_unit->isKneeled()) |
| 853 | { |
| 854 | tus -= 8; |
| 855 | } |
| 856 | int energy = _unit->getEnergy(); |
| 857 | int size = _unit->getArmor()->getSize() - 1; |
| 858 | int total = _unit->isKneeled() ? 8 : 0; |
| 859 | bool switchBack = false; |
| 860 | if (_save->getBattleGame()->getReservedAction() == BA_NONE) |
| 861 | { |
| 862 | switchBack = true; |
| 863 | _save->getBattleGame()->setTUReserved(BA_AUTOSHOT, false); |
| 864 | } |
| 865 | _modifierUsed = (SDL_GetModState() & KMOD_CTRL) != 0; |
| 866 | bool running = Options::strafe && _modifierUsed && _unit->getArmor()->getSize() == 1 && _path.size() > 1; |
| 867 | for (std::vector<int>::reverse_iterator i = _path.rbegin(); i != _path.rend(); ++i) |
| 868 | { |
| 869 | int dir = *i; |
| 870 | int tu = getTUCost(pos, dir, &destination, _unit, 0, false); // gets tu cost, but also gets the destination position. |
| 871 | if (running) |
| 872 | { |
| 873 | tu *= 0.75; |
| 874 | } |
| 875 | if (dir < Pathfinding::DIR_UP) |
| 876 | { |
| 877 | energy -= tu / 2; |
| 878 | } |
| 879 | |
| 880 | tus -= tu; |
| 881 | total += tu; |
| 882 | bool reserve = _save->getBattleGame()->checkReservedTU(_unit, total, true); |
| 883 | pos = destination; |
| 884 | for (int x = size; x >= 0; x--) |
| 885 | { |
| 886 | for (int y = size; y >= 0; y--) |
| 887 | { |
| 888 | Tile *tile = _save->getTile(pos + Position(x,y,0)); |
| 889 | Tile *tileAbove = _save->getTile(pos + Position(x,y,1)); |
| 890 | if (!bRemove) |
| 891 | { |
| 892 | if (i == _path.rend() - 1) |
| 893 | { |
| 894 | tile->setPreview(10); |
| 895 | } |
| 896 | else |
no test coverage detected