aliens

Author Topic: Question about:int TileEngine::calculateLine  (Read 1018 times)

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Question about:int TileEngine::calculateLine
« on: March 09, 2022, 06:08:54 am »
I have a question about this method: int TileEngine::calculateLine in file Battlescape\TileEngine.cpp:

First the code does this:

      //passes through this point?
      if (doVoxelCheck)
      {
         result = voxelCheck(Position(cx, cy, cz), excludeUnit, false, onlyVisible, excludeAllBut);
         if (result != V_EMPTY)
         {
            if (trajectory)
            { // store the position of impact
               trajectory->push_back(Position(cx, cy, cz));
            }
            return result;
         }
      }

Then later the code does this:

      //check for xy diagonal intermediate voxel step
      if (doVoxelCheck)
      {
         cx = x;   cz = z; cy = y;
         if (swap_xz) std::swap(cx, cz);
         if (swap_xy) std::swap(cx, cy);
         result = voxelCheck(Position(cx, cy, cz), excludeUnit, excludeAllUnits, onlyVisible, excludeAllBut);
         if (result != V_EMPTY)
         {
            if (trajectory != 0)
            { // store the position of impact
               trajectory->push_back(Position(cx, cy, cz));
            }
            return result;
         }
      }

The first call looks like:

         result = voxelCheck(Position(cx, cy, cz), excludeUnit, false, onlyVisible, excludeAllBut);

The second call looks like:

      result = voxelCheck(Position(cx, cy, cz), excludeUnit, excludeAllUnits, onlyVisible, excludeAllBut);

Notice how the first call has a "false" parameter.

Is this intentional or is this a bug ?

If it's intentional why does the first call use a false parameter and the others ExcludeAllUnits ?

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Re: Question about:int TileEngine::calculateLine
« Reply #1 on: March 31, 2022, 11:27:52 am »
I have a futher question about this method calculateLine:

What does this code do ?

Why is there temp_res ?

And most of all, what is the steps++ doing ?
steps < 2 seems to check for walls or floor every other step or so.

Vertical and Horizontal blockage is that in the x any y direction ?

Why check for result -1 ?

Why check for temp_res greater than 127 ? why then reset to zero ?

Why add temp_res to result ? why then check again for greater than 127 ?

This code definetly needs some further explaining, comments or code clean up/improvements.

            int temp_res = verticalBlockage(_save->getTile(LastPoint), _save->getTile(Position(VoxelX, VoxelY, VoxelZ)), DT_NONE);
            result = horizontalBlockage(_save->getTile(LastPoint), _save->getTile(Position(VoxelX, VoxelY, VoxelZ)), DT_NONE, steps<2);
            steps++;
            if (result == -1)
            {
               if (temp_res > 127)
               {
                  result = 0;
               }
               else
               {
                  return result; // We hit a big wall
               }
            }
            result += temp_res;
            if (result > 127)
            {
               return result;
            }

            LastPoint = Position(VoxelX, VoxelY, VoxelZ);