Example #1
0
  //
  // CanMoveToCell
  //
  // Calls above method, but first gets the movement balance data
  //
  Bool CanMoveToCell(U8 tractionType, TerrainData::Cell &cell)
  {
    // Get the balance info
    MoveTable::BalanceData &d = MoveTable::GetBalance(cell.surface, tractionType);

    // And call the above method
    return (CanMoveToCell(d, cell));
  }
Example #2
0
 //
 // CanMoveToCell
 //
 // Calls above method, but first checks that the position is on the map
 // 
 Bool CanMoveToCell(U8 tractionType, U32 x, U32 z)
 {
   return 
   (
     WorldCtrl::CellOnMap(x, z) && 
     CanMoveToCell(tractionType, TerrainData::GetCell(x, z))
   );
 }
  //
  // RequestPath
  //
  // Request a new path be found.  Returns FALSE if request is invalid.
  //
  Finder::RequestResult Finder::RequestPath
  (
    U32 sx, U32 sz, U32 dx, U32 dz, U8 traction, UnitObj *unit,
    SearchType type, U32 flags, PointList *blockList
  )
  {
    // Forget any current path
    ForgetPath();

    // Is destination on the map
    if (!WorldCtrl::CellOnMap(sx, sz) || !WorldCtrl::CellOnMap(dx, dz))
    {
      LOG_DIAG(("Request position is not on the map (%u, %u)->(%u,%u)", sx, sz, dx, dz));
      return (RR_OFFMAP);
    }

    // Filter out requests to move to the same cell
    if (sx == dx && sz == dz)
    {
      return (RR_SAMECELL);
    }

    // Can this traction type move to this cell
    if (!CanMoveToCell(traction, dx, dz))
    {
      U32 xNew, zNew;

      // Find the closest location we can move to
      if (FindClosestCell(traction, dx, dz, xNew, zNew, 15))
      {
        // Use the new location
        dx = xNew;
        dz = zNew;
      }
      else

      // AStar will fail, so jump straight to trace
      if (type == ST_ASTAR)
      {
        type = ST_TRACE;
      }
    }

    // Create a new path
    path = new Path(sx, sz, dx, dz, traction, unit, type, flags, blockList);

    // Add to the system
    AddPath(path);

    // Success
    return (RR_SUBMITTED);
  }