@@ -227,7 +227,9 @@ bool TileEngine::calculateFOV(BattleUnit *unit)
227227
228228 if (unit->isOut ())
229229 return false ;
230-
230+ Position pos = unit->getPosition ();
231+ if ((unit->getHeight () + -_save->getTile (unit->getPosition ())->getTerrainLevel ()) > 24 )
232+ ++pos.z ;
231233 for (int x = 0 ; x <= MAX_VIEW_DISTANCE ; ++x)
232234 {
233235 if (unit->getDirection ()%2 )
@@ -267,7 +269,7 @@ bool TileEngine::calculateFOV(BattleUnit *unit)
267269 if (unit->getFaction () == FACTION_PLAYER )
268270 {
269271 // this sets tiles to discovered if they are in LOS - tile visibility is not calculated in voxelspace but in tilespace
270- if (calculateLine (unit-> getPosition () , test, false , 0 , unit, false ) <= 0 )
272+ if (calculateLine (pos , test, false , 0 , unit, false ) <= 0 )
271273 {
272274 unit->addToVisibleTiles (_save->getTile (test));
273275 _save->getTile (test)->setDiscovered (true , 2 );
@@ -355,7 +357,7 @@ bool TileEngine::visible(BattleUnit *currentUnit, Tile *tile)
355357 {
356358 targetVoxel.z = i;
357359 _trajectory.clear ();
358- int test = calculateLine (originVoxel, targetVoxel, false , &_trajectory, currentUnit);
360+ int test = calculateLine (originVoxel, targetVoxel, false , &_trajectory, currentUnit, true , true );
359361 if (test == 4 )
360362 {
361363 Position hitPosition = Position (_trajectory.at (0 ).x /16 , _trajectory.at (0 ).y /16 , _trajectory.at (0 ).z /24 );
@@ -914,12 +916,15 @@ int TileEngine::vectorToDirection(const Position &vector)
914916 * 1 ufo door is starting to open, make a whoosh sound, don't walk through.
915917 * 3 ufo door is still opening, don't walk through it yet. (have patience, futuristic technology...)
916918 */
917- int TileEngine::unitOpensDoor (BattleUnit *unit)
919+ int TileEngine::unitOpensDoor (BattleUnit *unit, bool rClick )
918920{
919921 int door = -1 ;
920-
922+ int TUCost = 0 ;
921923 int size = unit->getArmor ()->getSize ();
922924
925+ if (size > 1 && rClick)
926+ return door;
927+
923928 for (int x = 0 ; x < size; x++)
924929 {
925930 for (int y = 0 ; y < size; y++)
@@ -929,9 +934,12 @@ int TileEngine::unitOpensDoor(BattleUnit *unit)
929934
930935 if (unit->getDirection () == 0 || unit->getDirection () == 1 || unit->getDirection () == 7 ) // north, northeast or northwest
931936 {
932- door = tile->openDoor (MapData::O_NORTHWALL );
937+ door = tile->openDoor (MapData::O_NORTHWALL , unit, _save->getDebugMode ());
938+ if (door == 0 && rClick)
939+ TUCost = tile->getTUCost (MapData::O_WESTWALL , unit->getArmor ()->getMovementType ());
933940 if (door == 1 )
934941 {
942+ TUCost = tile->getTUCost (MapData::O_NORTHWALL , unit->getArmor ()->getMovementType ());
935943 // check for adjacent door(s)
936944 tile = _save->getTile (unit->getPosition () + Position (x,y,0 ) + Position (1 , 0 , 0 ));
937945 if (tile) tile->openDoor (MapData::O_NORTHWALL );
@@ -946,9 +954,12 @@ int TileEngine::unitOpensDoor(BattleUnit *unit)
946954 if ((unit->getDirection () == 2 || unit->getDirection () == 1 || unit->getDirection () == 3 ) && door == -1 ) // east, northeast or southeast
947955 {
948956 tile = _save->getTile (unit->getPosition () + Position (x,y,0 ) + Position (1 , 0 , 0 ));
949- if (tile) door = tile->openDoor (MapData::O_WESTWALL );
957+ if (tile) door = tile->openDoor (MapData::O_WESTWALL , unit, _save->getDebugMode ());
958+ if (door == 0 && rClick)
959+ TUCost = tile->getTUCost (MapData::O_NORTHWALL , unit->getArmor ()->getMovementType ());
950960 if (door == 1 )
951961 {
962+ TUCost = tile->getTUCost (MapData::O_WESTWALL , unit->getArmor ()->getMovementType ());
952963 // check for adjacent door(s)
953964 tile = _save->getTile (unit->getPosition () + Position (x,y,0 ) + Position (1 , 1 , 0 ));
954965 if (tile) tile->openDoor (MapData::O_WESTWALL );
@@ -963,9 +974,12 @@ int TileEngine::unitOpensDoor(BattleUnit *unit)
963974 if ((unit->getDirection () == 4 || unit->getDirection () == 5 || unit->getDirection () == 3 ) && door == -1 ) // south, southwest or southeast
964975 {
965976 tile = _save->getTile (unit->getPosition () + Position (x,y,0 ) + Position (0 , 1 , 0 ));
966- if (tile) door = tile->openDoor (MapData::O_NORTHWALL );
977+ if (tile) door = tile->openDoor (MapData::O_NORTHWALL , unit, _save->getDebugMode ());
978+ if (door == 0 && rClick)
979+ TUCost = tile->getTUCost (MapData::O_WESTWALL , unit->getArmor ()->getMovementType ());
967980 if (door == 1 )
968981 {
982+ TUCost = tile->getTUCost (MapData::O_NORTHWALL , unit->getArmor ()->getMovementType ());
969983 // check for adjacent door(s)
970984 tile = _save->getTile (unit->getPosition () + Position (x,y,0 ) + Position (1 , 1 , 0 ));
971985 if (tile) tile->openDoor (MapData::O_NORTHWALL );
@@ -979,9 +993,12 @@ int TileEngine::unitOpensDoor(BattleUnit *unit)
979993 }
980994 if ((unit->getDirection () == 6 || unit->getDirection () == 5 || unit->getDirection () == 7 ) && door == -1 ) // west, southwest or northwest
981995 {
982- door = tile->openDoor (MapData::O_WESTWALL );
996+ door = tile->openDoor (MapData::O_WESTWALL , unit, _save->getDebugMode ());
997+ if (door == 0 && rClick)
998+ TUCost = tile->getTUCost (MapData::O_NORTHWALL , unit->getArmor ()->getMovementType ());
983999 if (door == 1 )
9841000 {
1001+ TUCost = tile->getTUCost (MapData::O_WESTWALL , unit->getArmor ()->getMovementType ());
9851002 // check for adjacent door(s)
9861003 tile = _save->getTile (unit->getPosition () + Position (x,y,0 ) + Position (0 , 1 , 0 ));
9871004 if (tile) tile->openDoor (MapData::O_WESTWALL );
@@ -999,6 +1016,8 @@ int TileEngine::unitOpensDoor(BattleUnit *unit)
9991016
10001017 if (door == 0 || door == 1 )
10011018 {
1019+
1020+ unit->spendTimeUnits (TUCost, _save->getDebugMode ());
10021021 calculateFOV (unit->getPosition ());
10031022 }
10041023
@@ -1031,7 +1050,7 @@ int TileEngine::closeUfoDoors()
10311050 * @param doVoxelCheck Check against voxel or tile blocking? (first one for units visibility and line of fire, second one for terrain visibility)
10321051 * @return the objectnumber(0-3) or unit(4) or out of map (5) or -1(hit nothing)
10331052 */
1034- int TileEngine::calculateLine (const Position& origin, const Position& target, bool storeTrajectory, std::vector<Position> *trajectory, BattleUnit *excludeUnit, bool doVoxelCheck)
1053+ int TileEngine::calculateLine (const Position& origin, const Position& target, bool storeTrajectory, std::vector<Position> *trajectory, BattleUnit *excludeUnit, bool doVoxelCheck, bool LOSCalc )
10351054{
10361055 int x, x0, x1, delta_x, step_x;
10371056 int y, y0, y1, delta_y, step_y;
@@ -1099,6 +1118,15 @@ int TileEngine::calculateLine(const Position& origin, const Position& target, bo
10991118 if (doVoxelCheck)
11001119 {
11011120 int result = voxelCheck (Position (cx, cy, cz), excludeUnit);
1121+ if (LOSCalc)
1122+ {
1123+ int result2 = voxelCheck (Position (cx, cy, cz-1 ), excludeUnit);
1124+ int result3 = voxelCheck (Position (cx, cy, cz+1 ), excludeUnit);
1125+ if (result2 != -1 )
1126+ result = result2;
1127+ if (result3 != -1 )
1128+ result = result3;
1129+ }
11021130 if (result != -1 )
11031131 {
11041132 if (!storeTrajectory && trajectory != 0 )
0 commit comments