Exemple #1
0
    // must have valid trimmedRangeInches value; must also free preexisting ObjectList!
    public void GetTargetsInPath(LocAndOffsets originLoc, LocAndOffsets tgtLoc, float radiusInch)
    {
        using var rayPkt      = new RaycastPacket();
        rayPkt.sourceObj      = null;
        rayPkt.origin         = originLoc;
        rayPkt.rayRangeInches = trimmedRangeInches;
        rayPkt.targetLoc      = tgtLoc;
        rayPkt.radius         = radiusInch;
        rayPkt.flags          = RaycastFlag.ExcludeItemObjects | RaycastFlag.HasRadius | RaycastFlag.HasRangeLimit;
        rayPkt.Raycast();

        if (rayPkt.Count > 0)
        {
            result.objList = new List <GameObject>();

            foreach (var resultItem in rayPkt)
            {
                if (resultItem.obj != null)
                {
                    result.objList.Add(resultItem.obj);
                }
            }

            // is this ok? what if no ObjectHandles.were found? (this is in the original)
            result.flags |= PickerResultFlags.PRF_HAS_MULTI_OBJ;
        }
    }
Exemple #2
0
    public void GetTrimmedRange(LocAndOffsets originLoc, LocAndOffsets tgtLoc, float radiusInch, float maxRangeInch,
                                float incrementInches)
    {
        trimmedRangeInches = maxRangeInch;

        using var rayPkt      = new RaycastPacket();
        rayPkt.sourceObj      = null;
        rayPkt.origin         = originLoc;
        rayPkt.rayRangeInches = maxRangeInch;
        rayPkt.targetLoc      = tgtLoc;
        rayPkt.radius         = radiusInch;
        rayPkt.flags          = RaycastFlag.ExcludeItemObjects | RaycastFlag.HasRadius | RaycastFlag.HasRangeLimit;
        rayPkt.Raycast();

        foreach (var rayRes in rayPkt)
        {
            if (rayRes.obj == null)
            {
                var dist = rayPkt.origin.DistanceTo(rayRes.loc);
                if (dist < trimmedRangeInches)
                {
                    trimmedRangeInches = dist;
                }
            }
        }

        if (incrementInches > 0)
        {
            trimmedRangeInches = MathF.Ceiling(trimmedRangeInches / incrementInches) * incrementInches;
        }
    }
    private static bool HasLineOfSight(GameObject source, LocAndOffsets target)
    {
        var objIterator = new RaycastPacket();

        objIterator.flags    |= RaycastFlag.StopAfterFirstBlockerFound | RaycastFlag.ExcludeItemObjects;
        objIterator.origin    = source.GetLocationFull();
        objIterator.targetLoc = target;
        return(objIterator.TestLineOfSight());
    }
Exemple #4
0
 public bool LosBlocked(GameObject target)
 {
     using var raycast = new RaycastPacket();
     raycast.flags    |= RaycastFlag.StopAfterFirstBlockerFound | RaycastFlag.ExcludeItemObjects
                         | RaycastFlag.HasTargetObj;
     raycast.origin    = caster.GetLocationFull();
     raycast.targetLoc = target.GetLocationFull();
     raycast.target    = target;
     return(!raycast.TestLineOfSight());
 }
    private RaycastPacket CreateRaycast(LocAndOffsets targetLocation)
    {
        var rayPkt = new RaycastPacket();

        rayPkt.flags |= RaycastFlag.HasRangeLimit | RaycastFlag.ExcludeItemObjects | RaycastFlag.HasSourceObj |
                        RaycastFlag.HasRadius;
        rayPkt.sourceObj      = Picker.caster;
        rayPkt.origin         = Picker.caster.GetLocationFull();
        rayPkt.rayRangeInches = Picker.trimmedRangeInches;
        rayPkt.radius         = Picker.radiusTarget * locXY.INCH_PER_FEET / 2.0f;
        rayPkt.targetLoc      = targetLocation;
        return(rayPkt);
    }
Exemple #6
0
    private static bool HasLineOfSight(LocAndOffsets originLoc, GameObject target)
    {
        if (originLoc == LocAndOffsets.Zero)
        {
            return(false);
        }

        var objIterator = new RaycastPacket();

        objIterator.flags |= RaycastFlag.StopAfterFirstBlockerFound | RaycastFlag.ExcludeItemObjects
                             | RaycastFlag.HasTargetObj;
        objIterator.origin    = originLoc;
        objIterator.targetLoc = target.GetLocationFull();
        objIterator.target    = target;
        return(objIterator.TestLineOfSight());
    }
    private bool IsBlocked(Vector2 pos, float radius)
    {
        var loc = LocAndOffsets.FromInches(pos);

        using var raycastPacket = new RaycastPacket();
        raycastPacket.origin    = loc;
        raycastPacket.targetLoc = loc;
        raycastPacket.radius    = radius;
        raycastPacket.flags    |= RaycastFlag.StopAfterFirstFlyoverFound
                                  | RaycastFlag.StopAfterFirstBlockerFound
                                  | RaycastFlag.ExcludeItemObjects
                                  | RaycastFlag.HasSourceObj
                                  | RaycastFlag.HasRadius;

        return(raycastPacket.RaycastShortRange() > 0);
    }
    private bool IsTargetLocationClear(LocAndOffsets targetLocation)
    {
        var radius = Picker.flagsTarget.HasFlag(UiPickerFlagsTarget.Radius)
            ? Picker.radiusTarget * locXY.INCH_PER_FEET
            : Picker.caster.GetRadius();

        using var raycast = new RaycastPacket();
        raycast.sourceObj = Picker.caster;
        raycast.origin    = targetLocation;
        raycast.targetLoc = targetLocation;
        raycast.radius    = radius;
        raycast.flags     = RaycastFlag.ExcludeItemObjects
                            | RaycastFlag.StopAfterFirstBlockerFound
                            | RaycastFlag.StopAfterFirstFlyoverFound
                            | RaycastFlag.HasSourceObj
                            | RaycastFlag.HasRadius;

        return(raycast.RaycastShortRange() == 0);
    }
Exemple #9
0
    public void TestRaycast()
    {
        var origin = new LocAndOffsets(new locXY(496, 458), -9.42809f, -8.42809f);
        var target = new LocAndOffsets(new locXY(512, 611), -7.42809f, -7.42809f);
        var radius = 17.5f;

        var ray_search = new RaycastPointSearchPacket();

        ray_search.origin = origin.ToInches2D();
        ray_search.target = target.ToInches2D();
        ray_search.radius = radius;

        ray_search.direction  = ray_search.target - ray_search.origin;
        ray_search.rangeInch  = ray_search.direction.Length();
        ray_search.direction /= ray_search.rangeInch;

        ray_search.absOdotU = Vector2.Dot(ray_search.direction, ray_search.origin);

        var locBeforeCover = target;
        SearchPointAlongRay search_func = RaycastPacket.IsPointCloseToSegment;

        var tileRadius = 1 + (int)(radius / locXY.INCH_PER_TILE);

        TestContext.Out.WriteLine(tileRadius.ToString());
        var tile_rect = RaycastPacket.BuildSearchRectangle(ray_search.origin, ray_search.target);

        var canFly = false;

        foreach (var s in tile_rect)
        {
            //int left = Math.Max(0, s.TileRectangle.Left - tileRadius);
            //int top = Math.Max(0, s.TileRectangle.Top - tileRadius);
            //int right = Math.Min(64, s.TileRectangle.Right + tileRadius);
            //int bottom = Math.Min(64, s.TileRectangle.Bottom + tileRadius);

            int left   = s.TileRectangle.Left;
            int top    = s.TileRectangle.Top;
            int right  = s.TileRectangle.Right;
            int bottom = s.TileRectangle.Bottom;

            TestContext.Out.WriteLine($"{s.SectorLoc.X} {s.SectorLoc.Y} {left},{top} {right},{bottom}");
        }
        TestContext.Out.WriteLine("OLD OLD OLD");

        if (!PreciseSectorRows.Build(tile_rect, out var sector_tiles))
        {
            return;
        }

        var local_254 = Math.Min(origin.location.locx, target.location.locx);
        var local_25c = Math.Max(origin.location.locx, target.location.locx);
        var local_2a4 = Math.Min(origin.location.locy, target.location.locy);
        var local_2b4 = Math.Max(origin.location.locy, target.location.locy);

/*
 *          local_254 -= tileRadius;
 *          local_2a4 -= tileRadius;
 *          local_25c += tileRadius;
 *          local_2b4 += tileRadius;
 */
        for (var local_2dc = 0; local_2dc < sector_tiles.RowCount; local_2dc++)
        {
            ref var pPVar2 = ref sector_tiles.Rows[local_2dc];

            Span <int> local_208 = stackalloc int[pPVar2.colCount];
            Span <int> local_1d8 = stackalloc int[pPVar2.colCount];

            for (var i = 0; i < pPVar2.colCount; i++)
            {
                local_208[i] = pPVar2.startTiles[i];
                local_1d8[i] = 64 - pPVar2.strides[i];
            }

            for (var local_2f0 = 0; local_2f0 < pPVar2.colCount; local_2f0++)
            {
                var sectorBaseTile = pPVar2.sectors[local_2f0].GetBaseTile();
                var sectorTileMinX = local_254 - sectorBaseTile.locx;
                var sectorTileMaxX = local_25c - sectorBaseTile.locx;
                var sectorTileMinY = local_2a4 - sectorBaseTile.locy;
                var sectorTileMaxY = local_2b4 - sectorBaseTile.locy;
                if (sectorTileMinX < 0)
                {
                    sectorTileMinX = 0;
                }

                if (sectorTileMinY < 0)
                {
                    sectorTileMinY = 0;
                }

                if (sectorTileMaxX > 63)
                {
                    sectorTileMaxX = 63;
                }

                if (sectorTileMaxY > 63)
                {
                    sectorTileMaxY = 63;
                }

                TestContext.Out.WriteLine($"{pPVar2.sectors[local_2f0].X} {pPVar2.sectors[local_2f0].Y} {sectorTileMinX},{sectorTileMinY}->{sectorTileMaxX},{sectorTileMaxY}");
            }
        }
    private int SearchInStraightLine(ref AnimPathData boPkt)
    {
        if (boPkt.srcLoc.EstimateDistance(boPkt.destLoc) > 32)
        {
            return(0);
        }

        var regardSinks = (boPkt.flags & AnimPathDataFlags.UNK_8) != 0;

        MapObjectSystem.ObstacleFlag flags = 0;
        if ((boPkt.flags & AnimPathDataFlags.CantOpenDoors) != 0)
        {
            flags = MapObjectSystem.ObstacleFlag.UNK_1;
        }

        if ((boPkt.flags & AnimPathDataFlags.UNK_4) != 0)
        {
            flags |= MapObjectSystem.ObstacleFlag.UNK_2;
        }

        if ((boPkt.flags & AnimPathDataFlags.UNK10) != 0)
        {
            flags |= MapObjectSystem.ObstacleFlag.UNK_4;
        }

        var curLoc = boPkt.srcLoc;

        int i;

        for (i = 0; i < boPkt.size; i++)
        {
            if (curLoc == boPkt.destLoc)
            {
                break;
            }

            var direction = curLoc.GetCompassDirection(boPkt.destLoc);
            boPkt.deltas[i] = (sbyte)direction;
            var nextLoc      = curLoc.Offset(direction);
            var backoffFlags = boPkt.flags;
            if ((backoffFlags & AnimPathDataFlags.UNK40) == 0)
            {
                if (nextLoc == boPkt.destLoc && (backoffFlags & AnimPathDataFlags.UNK_1) != 0)
                {
                    curLoc = nextLoc;
                    continue;
                }

                if (!regardSinks &&
                    (backoffFlags & AnimPathDataFlags.UNK_4000) == 0 &&
                    GameSystems.Tile.IsBlockingOldVersion(nextLoc))
                {
                    break;
                }

                if (GameSystems.MapObject.HasBlockingObjectInDir(boPkt.handle, new LocAndOffsets(curLoc), direction,
                                                                 flags))
                {
                    break;
                }

                if ((boPkt.flags & AnimPathDataFlags.UNK_2000) != 0)
                {
                    using var objIterator = new RaycastPacket();
                    objIterator.flags    |= RaycastFlag.StopAfterFirstFlyoverFound
                                            | RaycastFlag.StopAfterFirstBlockerFound
                                            | RaycastFlag.HasSourceObj
                                            | RaycastFlag.HasRadius;
                    objIterator.targetLoc.location.locx = nextLoc.locx;
                    objIterator.origin = new LocAndOffsets(curLoc);
                    objIterator.targetLoc.location.locy = nextLoc.locy;
                    objIterator.radius    = boPkt.handle.GetRadius() * 0.5f;
                    objIterator.sourceObj = boPkt.handle;
                    if (objIterator.Raycast() > 0)
                    {
                        break;
                    }
                }

                var trap = FindTrapAtLocation(nextLoc);
                if (trap != null && GameSystems.Trap.KnowsAboutDangerousTrap(boPkt.handle, trap))
                {
                    break;
                }

                if ((boPkt.flags & AnimPathDataFlags.UNK400) != 0)
                {
                    if (FindBurningScenery(nextLoc) != null)
                    {
                        break;
                    }
                }
            }

            curLoc = nextLoc;
        }

        // Did not reach the destination
        if (curLoc != boPkt.destLoc)
        {
            boPkt.distTiles = i;
            return(0);
        }

        if ((boPkt.flags & AnimPathDataFlags.UNK_1) != 0)
        {
            return(i - 1);
        }

        return(i);
    }