Exemple #1
0
        public ProvinceBoundBox[] GetAllContainedIn( Rectangle rect )
        {
            ArrayList resultList = new ArrayList();

            for ( int i=0; i<boxes.Length; ++i ) {
                if ( rect.Contains( boxes[i].Box ) ) resultList.Add( boxes[i] );
            }

            ProvinceBoundBox[] result = new ProvinceBoundBox[resultList.Count];
            resultList.CopyTo( result );
            return result;
        }
Exemple #2
0
        public ProvinceBoundBox[] CalculateBoundBoxes()
        {
            ProvinceBoundBox[] boxes = new ProvinceBoundBox[Province.InternalCount];

            // Initialize array
            for ( ushort i=0; i<Province.InternalCount; ++i ) {
                boxes[i] = new ProvinceBoundBox( Lightmap.BaseWidth, Lightmap.BaseHeight, 0, 0, i );
            }

            // Walk over zones and shrink each box as needed
            IDZone firstZone, secondZone, lastZone;
            for ( int y=0; y<Lightmap.BaseHeight; ++y ) {
                Scanline line = lines[y];

                int bufcount = line.Count-2; // Don't need to include the stopper, and the last zone (see later)
                firstZone = line.GetZone( 0 );
                secondZone = line.GetZone( 1 );
                lastZone = line.GetZone( line.Count-2 );

                for ( int bufindex=0; bufindex<bufcount; ++bufindex ) {
                    ushort id = line.GetZone( bufindex ).ID;

                    if ( id == Province.TerraIncognitaID || id > Province.Count ) continue;

                    // Check Y values first (this is simple)
                    if ( boxes[id].Top > y ) boxes[id].Top = y;
                    if ( boxes[id].Bottom < y ) boxes[id].Bottom = y;

                    // Now for the X values
                    // We need to take special care for the zones at the dateline: the box is calculated from 2 zones...
                    if ( bufindex > 0 ) {
                        int left = line.GetZone( bufindex ).X;
                        int right = line.GetZone( bufindex+1 ).X;

                        // Full zone (this is simple)
                        if ( boxes[id].Right > Lightmap.BaseWidth ) {
                            // Don't have to check left, as it will never be able to match
                            if ( Lightmap.BaseNormalizeX( boxes[id].Right ) < right ) boxes[id].Right = right + Lightmap.BaseWidth;
                        }
                        else {
                            if ( boxes[id].Left > left ) boxes[id].Left = left;
                            if ( boxes[id].Right < right ) boxes[id].Right = right;
                        }
                    }
                    else {
                        // First zone, is it a split zone?
                        if ( firstZone.ID == lastZone.ID ) {
                            // Wrapping province, treat as 1
                            if ( boxes[firstZone.ID].Left > lastZone.X ) boxes[firstZone.ID].Left = lastZone.X;
                            if ( boxes[firstZone.ID].Right < secondZone.X+Lightmap.BaseWidth ) boxes[firstZone.ID].Right = secondZone.X+Lightmap.BaseWidth;
                        }
                        else {
                            // 2 seperate provinces with edge on dateline
                            boxes[firstZone.ID].Left = 0;
                            boxes[firstZone.ID].Right = secondZone.X;

                            boxes[lastZone.ID].Left = lastZone.X;
                            boxes[lastZone.ID].Right = Lightmap.BaseWidth;
                        }
                    }
                }
            }

            return boxes;
        }
Exemple #3
0
 public BoundBoxes( ProvinceBoundBox[] originals )
 {
     boxes = new ProvinceBoundBox[Province.InternalCount];
     originals.CopyTo( boxes, 0 );
 }
Exemple #4
0
 public BoundBoxes()
 {
     boxes = new ProvinceBoundBox[Province.InternalCount];
     for ( int i=0; i<Province.MaxValue; ++i ) boxes[i] = new ProvinceBoundBox( Rectangle.Empty, (ushort)i );
 }
Exemple #5
0
 public void ReadFrom( BinaryReader reader )
 {
     int i=0;
     try {
         for ( i=0; i<Province.MaxValue; ++i ) boxes[i].ReadFrom( reader );
     }
     catch ( System.IO.EndOfStreamException ) {
         for ( ; i<Province.MaxValue; ++i ) boxes[i] = new ProvinceBoundBox( 0, 0, 0, 0, (ushort)i );
     }
 }
Exemple #6
0
 public ProvinceBoundBox[] GetAllIntersectingWith( ProvinceBoundBox box )
 {
     return GetAllIntersectingWith( box.Box );
 }