Ticket #3405: ticket3405-fix.diff

File ticket3405-fix.diff, 3.9 KB (added by mimo, 9 years ago)
  • source/simulation2/helpers/PathGoal.cpp

     
    155155        {
    156156            for (int i = i0; imin <= i && i <= imax; i += di)
    157157            {
    158                 entity_pos_t x0 = entity_pos_t::FromInt(i).Multiply(Pathfinding::NAVCELL_SIZE);
    159                 entity_pos_t z0 = entity_pos_t::FromInt(j).Multiply(Pathfinding::NAVCELL_SIZE);
    160                 entity_pos_t x1 = x0 + Pathfinding::NAVCELL_SIZE;
    161                 entity_pos_t z1 = z0 + Pathfinding::NAVCELL_SIZE;
    162                 entity_pos_t nx = Clamp(x, x0, x1);
    163                 entity_pos_t nz = Clamp(z, z0, z1);
    164                 if ((CFixedVector2D(nx, nz) - CFixedVector2D(x, z)).CompareLength(hw) <= 0)
     158                if (NavcellContainsCircle(i, j, x, z, hw, true))
    165159                {
    166160                    if (gi)
    167161                        *gi = i;
     
    185179        {
    186180            for (int i = i0; imin <= i && i <= imax; i += di)
    187181            {
    188                 entity_pos_t x0 = entity_pos_t::FromInt(i).Multiply(Pathfinding::NAVCELL_SIZE);
    189                 entity_pos_t z0 = entity_pos_t::FromInt(j).Multiply(Pathfinding::NAVCELL_SIZE);
    190                 entity_pos_t x1 = x0 + Pathfinding::NAVCELL_SIZE;
    191                 entity_pos_t z1 = z0 + Pathfinding::NAVCELL_SIZE;
    192                 entity_pos_t nx = Clamp(x, x0, x1);
    193                 entity_pos_t nz = Clamp(z, z0, z1);
    194                 if ((CFixedVector2D(nx, nz) - CFixedVector2D(x, z)).CompareLength(hw) > 0)
     182                if (NavcellContainsCircle(i, j, x, z, hw, false))
    195183                {
    196184                    if (gi)
    197185                        *gi = i;
     
    215203        {
    216204            for (int i = i0; imin <= i && i <= imax; i += di)
    217205            {
    218                 entity_pos_t x0 = entity_pos_t::FromInt(i).Multiply(Pathfinding::NAVCELL_SIZE);
    219                 entity_pos_t z0 = entity_pos_t::FromInt(j).Multiply(Pathfinding::NAVCELL_SIZE);
    220                 entity_pos_t x1 = x0 + Pathfinding::NAVCELL_SIZE;
    221                 entity_pos_t z1 = z0 + Pathfinding::NAVCELL_SIZE;
    222                 entity_pos_t nx = Clamp(x, x0, x1);
    223                 entity_pos_t nz = Clamp(z, z0, z1);
    224                 if (Geometry::PointIsInSquare(CFixedVector2D(nx - x, nz - z), u, v, CFixedVector2D(hw, hh)))
     206                if (NavcellContainsSquare(i, j, x, z, u, v, hw, hh, true))
    225207                {
    226208                    if (gi)
    227209                        *gi = i;
     
    245227        {
    246228            for (int i = i0; imin <= i && i <= imax; i += di)
    247229            {
    248                 entity_pos_t x0 = entity_pos_t::FromInt(i).Multiply(Pathfinding::NAVCELL_SIZE);
    249                 entity_pos_t z0 = entity_pos_t::FromInt(j).Multiply(Pathfinding::NAVCELL_SIZE);
    250                 entity_pos_t x1 = x0 + Pathfinding::NAVCELL_SIZE;
    251                 entity_pos_t z1 = z0 + Pathfinding::NAVCELL_SIZE;
    252                 entity_pos_t nx = Clamp(x, x0, x1);
    253                 entity_pos_t nz = Clamp(z, z0, z1);
    254                 if (!Geometry::PointIsInSquare(CFixedVector2D(nx - x, nz - z), u, v, CFixedVector2D(hw, hh)))
     230                if (NavcellContainsSquare(i, j, x, z, u, v, hw, hh, false))
    255231                {
    256232                    if (gi)
    257233                        *gi = i;
     
    284260
    285261    case INVERTED_CIRCLE:
    286262    {
    287         entity_pos_t nx = Clamp(x, x0, x1);
    288         entity_pos_t nz = Clamp(z, z0, z1);
    289         return (CFixedVector2D(nx, nz) - CFixedVector2D(x, z)).CompareLength(hw) > 0;
     263        return ((CFixedVector2D(x0, z0) - CFixedVector2D(x, z)).CompareLength(hw) >= 0
     264             || (CFixedVector2D(x1, z0) - CFixedVector2D(x, z)).CompareLength(hw) >= 0
     265                 || (CFixedVector2D(x0, z1) - CFixedVector2D(x, z)).CompareLength(hw) >= 0
     266                 || (CFixedVector2D(x1, z1) - CFixedVector2D(x, z)).CompareLength(hw) >= 0);
    290267    }
    291268
    292269    case SQUARE:
     
    298275
    299276    case INVERTED_SQUARE:
    300277    {
    301         entity_pos_t nx = Clamp(x, x0, x1);
    302         entity_pos_t nz = Clamp(z, z0, z1);
    303         return !Geometry::PointIsInSquare(CFixedVector2D(nx - x, nz - z), u, v, CFixedVector2D(hw, hh));
     278        return    (!Geometry::PointIsInSquare(CFixedVector2D(x0 - x, z0 - z), u, v, CFixedVector2D(hw, hh))
     279            || !Geometry::PointIsInSquare(CFixedVector2D(x1 - x, z0 - z), u, v, CFixedVector2D(hw, hh))
     280            || !Geometry::PointIsInSquare(CFixedVector2D(x0 - x, z1 - z), u, v, CFixedVector2D(hw, hh))
     281            || !Geometry::PointIsInSquare(CFixedVector2D(x1 - x, z1 - z), u, v, CFixedVector2D(hw, hh)));
    304282    }
    305283
    306284    NODEFAULT;