Ejemplo n.º 1
0
        public bool CopyAndTile(byte[] data, uint texSize, TerrainTex terrainTex)
        {
            var baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.CopyCSI(data, texSize, texSize, baseTexture, terrainTex.TexTiling);
                return(true);
            }

            if (terrainTex.TexGID != 0) // stru_841760
            {
                var qdid = new QualifiedDataID(11, terrainTex.TexGID);

                var surfaceTexture = DBObj.GetSurfaceTexture(terrainTex.TexGID);
                terrainTex.BaseTexture = new ImgTex(surfaceTexture);
            }
            baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.CopyCSI(data, texSize, texSize, baseTexture, terrainTex.TexTiling);
                return(true);
            }
            else
            {
                ImgTex.CopyCSI(data, texSize, texSize, null, 1);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public TerrainAlphaMap FindTerrainAlpha(uint pcode, uint tcode, out LandDefs.Rotation rot, out int alphaIdx)
        {
            List <TerrainAlphaMap> terrainMaps = null;
            var baseIdx = 0;

            // corner tcodes - sw / se / ne / nw
            if (tcode != 1 && tcode != 2 && tcode != 4 && tcode != 8)
            {
                baseIdx     = 4;
                terrainMaps = SideTerrainMaps;   // common tcode: 9
            }
            else
            {
                terrainMaps = CornerTerrainMaps; // common tcode: 8
            }
            var numTerrains = terrainMaps.Count;

            var prng = (int)Math.Floor((1379576222 * pcode - 1372186442) * 2.3283064e-10 * numTerrains);

            if (prng >= numTerrains)
            {
                prng = 0;
            }

            var alpha = terrainMaps[prng];

            alphaIdx = baseIdx + prng;

            rot = LandDefs.Rotation.Rot0;

            var i         = 0;
            var alphaCode = alpha.TCode;

            while (alphaCode != tcode)
            {
                // corners: 8 -> 1 -> 2 -> 4
                // sides: 9 -> 3 -> 6 -> 12
                // west / south / east / north?
                alphaCode *= 2;
                if (alphaCode >= 16)
                {
                    alphaCode -= 15;
                }
                if (++i >= 4)
                {
                    return(null);
                }
            }
            rot = (LandDefs.Rotation)i;

            if (alpha.Texture == null && alpha.TexGID != 0)
            {
                var qdid = new QualifiedDataID(11, alpha.TexGID);
                alpha.Texture = new ImgTex(DBObj.GetSurfaceTexture(alpha.TexGID));
            }
            return(alpha);
        }
Ejemplo n.º 3
0
        public RoadAlphaMap FindRoadAlpha(uint pcode, uint rcode, out LandDefs.Rotation rot, out int alphaIdx)
        {
            rot      = LandDefs.Rotation.Rot0;
            alphaIdx = -1;

            var numRoadMaps = RoadMaps.Count;

            if (numRoadMaps == 0)
            {
                return(null);
            }

            var prng = (int)Math.Floor((1379576222 * pcode - 1372186442) * 2.3283064e-10 * numRoadMaps);

            for (var i = 0; i < numRoadMaps; i++)
            {
                var idx   = (i + prng) % numRoadMaps;
                var alpha = RoadMaps[idx];
                rot = LandDefs.Rotation.Rot0;
                var alphaCode = alpha.RCode;
                alphaIdx = 5 + idx;

                for (var j = 0; j < 4; j++)
                {
                    if (alphaCode == rcode)
                    {
                        rot = (LandDefs.Rotation)j;
                        if (alpha.Texture == null && alpha.RoadTexGID != 0)
                        {
                            alpha.Texture = new ImgTex(DBObj.GetSurfaceTexture(alpha.RoadTexGID));
                        }

                        return(alpha);
                    }
                    alphaCode *= 2;
                    if (alphaCode >= 16)
                    {
                        alphaCode -= 15;
                    }
                }
            }
            alphaIdx = -1;
            return(null);
        }