Пример #1
0
        /// <summary>
        /// Decompresses the idtable stored in the byte stream. 
        /// </summary>
        /// <param name="data">The byte stream containing the compressed table. </param>
        /// <param name="index"></param>
        private static int DecompressIdTable( byte[] data, ref int index, AdjacencyTable adjacent, out Pixel[] owners )
        {
            // -- Get a list of province ids
            int idCount = -1;
            ushort[] idTable = new ushort[IdTableSize];
            do {
                ++idCount;
                idTable[idCount] = (ushort)(data[index] + ((data[index+1] & 127) << 8));
                index += 2;
            } while ( data[index-1] < Terminator );
            ++idCount;

            // -- Fill the ownertable
            owners = new Pixel[IdTableSize];
            for ( int i=0; i<idCount; ++i ) {
                if ( idTable[i] <= Province.Count ) {
                    owners[i] = new Pixel( 0, idTable[i] );
                }
                else {
                    // We're dealing with a pixel that's on a border. Decode some more...
                    int val = idTable[i];
                    int color = val&1;
                    ushort id1 = (ushort)idTable[((val>>9)&63)-4];
                    if ( id1 >= Province.Count ) id1 = Province.TerraIncognitaID;
                    //ushort id2 = adjacent == null ? Province.TerraIncognitaID : adjacent.GetAdjacency( id1, (val>>1)&15 ).ID;
                    ushort id2 = Province.TerraIncognitaID;
                    byte riveradj = (byte)((val>>5)&15);
                    if ( riveradj != Adjacent.Invalid && adjacent != null ) {
                        id2 = id1;
                        id1 = adjacent.GetAdjacency( id2, riveradj ).ID;
                    }

                    owners[i] = new Pixel( 0, id1, id2, (byte)(color+1) );
                }
            }

            return idCount;
        }
Пример #2
0
        /// <summary>
        /// Decompresses the idtable stored in the byte stream. 
        /// </summary>
        /// <param name="data">The byte stream containing the compressed table. </param>
        /// <param name="index"></param>
        private void DecompressIdTable( byte[] data, ref int index, AdjacencyTable adjacent )
        {
            const int IdTableSize = 256;
            const int Terminator = 128;

            // -- Get a list of province ids
            int idCount = -1;
            ushort[] idTable = new ushort[IdTableSize];
            do {
                ++idCount;
                idTable[idCount] = (ushort)(data[index] + ((data[index+1]&127) << 8));
                index += 2;
            } while ( data[index-1] < Terminator );
            ++idCount;

            // -- Fill the ownertable
            owners = new OwnerInfo[idCount];
            for ( int i=0; i<idCount; ++i ) {
                if ( idTable[i] < Province.Count ) {
                    owners[i] = new OwnerInfo( idTable[i] );
                }
                else {
                    // We're dealing with a pixel that's on a border. Decode some more...
                    int val = idTable[i];
                    int color = val&1;
                    ushort id1 = (ushort)idTable[((val>>9)&63)-4];
                    if ( id1 >= Province.Count ) id1 = Province.TerraIncognitaID;
                    ushort id2 = adjacent == null ? Province.TerraIncognitaID : adjacent.GetAdjacency( id1, (val>>1)&15 ).ID;

                    owners[i] = new OwnerInfo( id1, id2, (byte)((val>>5)&15) );
                }
            }
        }