Esempio n. 1
0
        public TrackObjectZones(byte[] data, TrackAI ai)
        {
            this.frontView = new TrackObjectZonesView(new[] { data[0], data[1], data[2], data[3] }, ai);
            this.rearView  = new TrackObjectZonesView(new[] { data[5], data[6], data[7], data[8] }, ai);

            this.frontView.DataChanged += this.frontView_DataChanged;
            this.rearView.DataChanged  += this.rearView_DataChanged;
        }
        private static byte[][] GetGridFilledFromNearestTiles(sbyte[][] zones)
        {
            byte[][] newZones = new byte[zones.Length][];

            for (int y = 0; y < zones.Length; y++)
            {
                newZones[y] = new byte[zones[y].Length];
                for (int x = 0; x < zones[y].Length; x++)
                {
                    if (zones[y][x] != -1)
                    {
                        newZones[y][x] = (byte)zones[y][x];
                        continue;
                    }

                    int   depth     = 1;
                    sbyte zoneIndex = -1;
                    while (zoneIndex == -1)
                    {
                        sbyte matchFound;

                        matchFound = TrackObjectZonesView.GetTopRightNearestTile(zones, x, y, depth);
                        if (matchFound > zoneIndex)
                        {
                            zoneIndex = matchFound;
                        }

                        matchFound = TrackObjectZonesView.GetBottomRightNearestTile(zones, x, y, depth);
                        if (matchFound > zoneIndex)
                        {
                            zoneIndex = matchFound;
                        }

                        matchFound = TrackObjectZonesView.GetBottomLeftNearestTile(zones, x, y, depth);
                        if (matchFound > zoneIndex)
                        {
                            zoneIndex = matchFound;
                        }

                        matchFound = TrackObjectZonesView.GetTopLeftNearestTile(zones, x, y, depth);
                        if (matchFound > zoneIndex)
                        {
                            zoneIndex = matchFound;
                        }

                        depth++;
                    }

                    newZones[y][x] = (byte)zoneIndex;
                }
            }

            return(newZones);
        }
        public byte[][] GetGrid()
        {
            byte[][] zones;

            if (this.ai.ElementCount == 0)
            {
                zones = new byte[GridSize][];

                for (int y = 0; y < zones.Length; y++)
                {
                    zones[y] = new byte[GridSize];
                }

                return(zones);
            }

            sbyte[][] sZones = TrackObjectZonesView.InitZones();
            this.FillGridFromAI(sZones);
            zones = TrackObjectZonesView.GetGridFilledFromNearestTiles(sZones);

            return(zones);
        }