public CachedSector(SectorLoc loc, Sector sector)
 {
     Loaded    = TimePoint.Now;
     Loc       = loc;
     Sector    = sector;
     LockCount = 0;
 }
    public SectorVisibility Lock(SectorLoc location)
    {
        var visibility = Get(location);

        visibility.UsageCount++;
        return(visibility);
    }
Esempio n. 3
0
    private static void HandleEnterNewSector(SectorLoc loc, GameObject obj)
    {
        {
            using var sectorLock = new LockedMapSector(loc);
            var sector      = sectorLock.Sector;
            var lightScheme = sector.lightScheme;
            if (lightScheme == 0)
            {
                lightScheme = GameSystems.LightScheme.GetDefaultScheme();
            }
            if (lightScheme != GameSystems.LightScheme.GetCurrentScheme())
            {
                var hourOfDay = GameSystems.TimeEvent.HourOfDay;
                GameSystems.LightScheme.SetCurrentScheme(sector.lightScheme, hourOfDay);
            }

            if (sector.soundList.scheme1 != 0 || sector.soundList.scheme2 != 0)
            {
                GameSystems.SoundGame.SetScheme(sector.soundList.scheme1, sector.soundList.scheme2);
            }
        }

        GameSystems.TileScript.TriggerSectorScript(loc, obj);

        var followers = GameSystems.Critter.EnumerateDirectFollowers(obj);

        foreach (var follower in followers)
        {
            GameSystems.Script.ExecuteObjectScript(obj, follower, 0,
                                                   ObjScriptEvent.NewSector);
        }
    }
 public PartialSector(SectorLoc sectorLoc, bool fullSector, Rectangle tileRectangle, LockedMapSector sector)
 {
     SectorLoc     = sectorLoc;
     FullSector    = fullSector;
     TileRectangle = tileRectangle;
     Sector        = sector;
 }
Esempio n. 5
0
    public static void UpdateRenderingState(this GameObject obj, bool sectorChanged)
    {
        obj.AdvanceAnimationTime(0.0f);
        var flags = obj.GetFlags();
        // Clears flags 0x04000000‬ and 0x02000000‬
        var renderflags = obj.GetUInt32(obj_f.render_flags) & 0xF9FFFFFF;

        var loc = obj.GetLocation();

        if (!flags.HasFlag(ObjectFlag.DISALLOW_WADING))
        {
            if (GameSystems.Tile.MapTileHasSinksFlag(loc))
            {
                if (!flags.HasFlag(ObjectFlag.WADING))
                {
                    obj.SetFlag(ObjectFlag.WADING, true);
                }
            }
            else if (flags.HasFlag(ObjectFlag.WADING))
            {
                obj.SetFlag(ObjectFlag.WADING, false);
            }
        }

        if (obj.IsPC() && GameSystems.Party.IsInParty(obj))
        {
            GameSystems.TownMap.sub_10052430(loc);
            GameSystems.Scroll.SetLocation(loc);
        }

        if (obj.IsCritter())
        {
            GameSystems.TileScript.TriggerTileScript(loc, obj);
        }

        var stashedObj = GameSystems.MapObject.GlobalStashedObject;

        if (stashedObj != null)
        {
            if (stashedObj == obj || GameSystems.Party.IsInParty(obj))
            {
                var firstPartyMember = GameSystems.Party.GetPCGroupMemberN(0);
                // TODO NULLSUB! call_ui_pfunc28(firstPartyMember, stashedObj);
            }
        }

        if (sectorChanged)
        {
            if (obj.IsPC() && GameSystems.Party.IsInParty(obj))
            {
                var sectorLoc = new SectorLoc(loc);
                HandleEnterNewSector(sectorLoc, obj);
            }

            GameSystems.MapSector.MapSectorResetLightHandle(obj);
        }

        obj.SetUInt32(obj_f.render_flags, renderflags);
    }
 public IEnumerable <GameObject> EnumerateInSector(SectorLoc sectorLoc)
 {
     // TODO: Needs to be more efficient
     foreach (var obj in GameSystems.Object.EnumerateNonProtos())
     {
         var loc = obj.GetLocation();
         if (new SectorLoc(loc) == sectorLoc)
         {
             yield return(obj);
         }
     }
 }
Esempio n. 7
0
    public static ObjList ListTile(locXY loc, ObjectListFilter flags)
    {
        Span <bool> returnTypes = stackalloc bool[ObjectTypes.Count];

        CreateTypeFilter(flags, returnTypes);

        var result = new ObjList();

        var sectorLoc = new SectorLoc(loc);

        if ((flags & ObjectListFilter.OLC_STATIC) != 0 || GameSystems.MapSector.IsSectorLoaded(sectorLoc))
        {
            using var lockedSector = new LockedMapSector(sectorLoc);

            Sector.GetSectorTileCoords(loc, out var tileX, out var tileY);

            var objects = lockedSector.GetObjectsAt(tileX, tileY);
            result.EnsureCapacity(objects.Count);
            foreach (var obj in objects)
            {
                if (!GameSystems.MapObject.IsHiddenByFlags(obj) && returnTypes[(int)obj.type])
                {
                    result.Add(obj);
                }
            }
        }
        else
        {
            foreach (var obj in GameSystems.Object.SpatialIndex.EnumerateInSector(sectorLoc))
            {
                if (!obj.type.IsStatic())
                {
                    if (!obj.HasFlag(ObjectFlag.INVENTORY) &&
                        obj.GetLocation() == loc &&
                        !GameSystems.MapObject.IsHiddenByFlags(obj) &&
                        returnTypes[(int)obj.type])
                    {
                        result.Add(obj);
                    }
                }
            }
        }

        ++dword_10808CF8;
        return(result);
    }
    private SectorVisibility Get(SectorLoc location)
    {
        if (_cache.TryGetValue(location, out var cachedVisibility))
        {
            cachedVisibility.MarkUsed();
            return(cachedVisibility);
        }

        // Always create a new one
        var visibility = new SectorVisibility(location);

        _cache[location] = visibility;

        var svbFilename = GetSvbFilename(location);

        if (_useSaveFolder)
        {
            // Flag 0x10 seems to mean "allow loading from the save directory", which is inactive for vanilla
            var svgSavePath = Path.Join(_saveDir, svbFilename);
            if (File.Exists(svgSavePath))
            {
                using var reader = new BinaryReader(new FileStream(svgSavePath, FileMode.Open));
                if (!visibility.Load(reader))
                {
                    Logger.Error("Failed to load sector visibility file {0}", svgSavePath);
                }
                return(visibility);
            }
        }

        // Attempt loading it from the archives
        var svbPath = _dataDir + "/" + svbFilename;

        if (Tig.FS.FileExists(svbPath))
        {
            using var reader = Tig.FS.OpenBinaryReader(svbPath);
            if (!visibility.Load(reader))
            {
                Logger.Error("Failed to load sector visibility file {0}", svbPath);
            }
        }

        return(visibility);
    }
    public bool MoveNext()
    {
        _lockedSector?.Dispose();

        if (_currentX >= _endX || _currentY >= _endY)
        {
            return(false);
        }

        var secX = _currentX / 64;
        var remX = _currentX % 64;
        var secY = _currentY / 64;
        var remY = _currentY % 64;
        var w    = Math.Min(64 - remX, _endX - _currentX);
        var h    = Math.Min(64 - remY, _endY - _currentY);

        var sectorLoc = new SectorLoc(secX, secY);

        if (_lockSectors)
        {
            _lockedSector = new LockedMapSector(sectorLoc);
        }

        Current = new PartialSector(
            sectorLoc,
            w < 64 || h < 64,
            new Rectangle(remX, remY, w, h),
            _lockedSector
            );

        _currentX += w;
        if (_currentX >= _endX)
        {
            _currentX  = _tileRectangle.Left;
            _currentY += h;
        }

        return(true);
    }
    public void Unlock(SectorLoc location)
    {
        var visibility = Get(location);

        visibility.UsageCount--;
    }
 public SectorVisibility(SectorLoc location)
 {
     Location = location;
 }
 private static string GetSvbFilename(SectorLoc location)
 {
     return(location.Pack().ToString(CultureInfo.InvariantCulture) + ".svb");
 }
Esempio n. 13
0
 public bool Equals(SectorLoc other)
 {
     return(X == other.X && Y == other.Y);
 }
Esempio n. 14
0
 public SavedSectorTime(SectorLoc sector, GameTime time)
 {
     Sector = sector;
     Time   = time;
 }
 public LockedMapSector(SectorLoc loc)
 {
     Loc    = loc;
     Sector = GameSystems.MapSector.LockSector(loc);
 }
    public SectorClearanceData GetSectorClearance(SectorLoc loc)
    {
        var sectorIdx = clrIdx.clrAddr[loc.X, loc.Y];

        return(secClr[sectorIdx]);
    }
Esempio n. 17
0
 public SubTileMeshBuilder(SectorLoc sector)
 {
     _basePos = sector.GetBaseTile().ToInches2D();
 }