Example #1
0
        public TransitionState PrecipiceSlide(Transition transition)
        {
            var     collisions      = transition.CollisionInfo;
            Vector3 collisionNormal = Vector3.Zero;
            var     found           = Walkable.find_crossed_edge(WalkableCheckPos, WalkableUp, ref collisionNormal);

            if (!found)
            {
                Walkable = null;
                return(TransitionState.Collided);
            }

            Walkable        = null;
            StepUp          = false;
            collisionNormal = WalkablePos.Frame.LocalToGlobalVec(collisionNormal);

            var blockOffset = LandDefs.GetBlockOffset(CurPos.ObjCellID, CheckPos.ObjCellID);
            var offset      = GlobalSphere[0].Center - GlobalCurrCenter[0].Center + blockOffset;;

            if (Vector3.Dot(collisionNormal, offset) > 0.0f)
            {
                collisionNormal *= -1.0f;
            }

            return(GlobalSphere[0].SlideSphere(transition, collisionNormal, GlobalCurrCenter[0].Center));
        }
Example #2
0
        public TransitionState CliffSlide(Plane contactPlane)
        {
            var contactNormal = Vector3.Cross(contactPlane.Normal, CollisionInfo.LastKnownContactPlane.Normal);

            contactNormal.Z = 0.0f;

            var collideNormal = new Vector3(contactNormal.Z - contactNormal.Y, contactNormal.X - contactNormal.Z, 0);

            if (Vec.NormalizeCheckSmall(ref collideNormal))
            {
                return(TransitionState.OK);
            }

            var blockOffset = LandDefs.GetBlockOffset(SpherePath.CurPos.ObjCellID, SpherePath.CheckPos.ObjCellID);
            var offset      = SpherePath.GlobalSphere[0].Center - SpherePath.GlobalCurrCenter[0].Center;

            var angle = Vector3.Dot(collideNormal, offset + blockOffset);

            if (angle <= 0.0f)
            {
                SpherePath.AddOffsetToCheckPos(collideNormal * angle);
                CollisionInfo.SetCollisionNormal(collideNormal);
            }
            else
            {
                SpherePath.AddOffsetToCheckPos(collideNormal * -angle);
                CollisionInfo.SetCollisionNormal(-collideNormal);
            }
            return(TransitionState.Adjusted);
        }
Example #3
0
        public Vector3 AdjustOffset(Vector3 offset)
        {
            var collisionAngle = Vector3.Dot(offset, CollisionInfo.SlidingNormal);

            if (CollisionInfo.SlidingNormalValid && collisionAngle >= 0.0f)
            {
                CollisionInfo.SlidingNormalValid = false;
            }

            if (!CollisionInfo.ContactPlaneValid)
            {
                return(offset - CollisionInfo.SlidingNormal * collisionAngle);
            }

            var slideAngle = Vector3.Dot(CollisionInfo.ContactPlane.Normal, CollisionInfo.SlidingNormal);

            if (CollisionInfo.SlidingNormalValid)
            {
                var contactSlide = Vector3.Cross(CollisionInfo.ContactPlane.Normal, CollisionInfo.SlidingNormal);
                if (!CollisionInfo.NormalizeCheckSmall(ref contactSlide))
                {
                    offset = Vector3.Dot(contactSlide, offset) * contactSlide;
                }
                else
                {
                    offset = Vector3.Zero;
                }
            }
            else if (slideAngle <= 0.0f)
            {
                offset -= CollisionInfo.ContactPlane.Normal * slideAngle;
            }
            else
            {
                CollisionInfo.ContactPlane.SnapToPlane(offset);
            }

            if (CollisionInfo.ContactPlaneCellID == 0 || CollisionInfo.ContactPlaneIsWater)
            {
                return(offset);
            }

            var globSphere  = SpherePath.GlobalSphere[0];
            var blockOffset = LandDefs.GetBlockOffset(SpherePath.CheckPos.ObjCellID, CollisionInfo.ContactPlaneCellID);
            var dist        = Vector3.Dot(globSphere.Center - blockOffset, CollisionInfo.ContactPlane.Normal);

            if (dist >= globSphere.Radius - PhysicsGlobals.EPSILON)
            {
                return(offset);
            }

            var zDist = (globSphere.Radius - dist) / CollisionInfo.ContactPlane.Normal.Z;

            if (globSphere.Radius > Math.Abs(zDist))
            {
                offset = new Vector3(0.0f, 0.0f, zDist);
                SpherePath.AddOffsetToCheckPos(offset);
            }
            return(offset);
        }
Example #4
0
        public TransitionState CheckOtherCells(ObjCell currCell)
        {
            var result = TransitionState.OK;

            SpherePath.CellArrayValid   = true;
            SpherePath.HitsInteriorCell = false;
            ObjCell newCell = new ObjCell();    // null check?

            ObjCell.find_cell_list(CellArray, ref newCell, SpherePath);

            foreach (var cell in CellArray.Cells.Values)
            {
                if (cell == null || cell.Equals(currCell))
                {
                    continue;
                }
                var collides = cell.FindCollisions(this);
                switch (collides)
                {
                case TransitionState.Slid:
                    CollisionInfo.ContactPlaneValid   = false;
                    CollisionInfo.ContactPlaneIsWater = false;
                    return(collides);

                case TransitionState.Collided:
                case TransitionState.Adjusted:
                    return(collides);
                }
            }

            SpherePath.CheckCell = newCell;

            if (newCell != null)
            {
                SpherePath.AdjustCheckPos(newCell.ID);
                return(result);
            }
            if (SpherePath.StepDown)
            {
                return(TransitionState.Collided);
            }

            var checkPos = SpherePath.CheckPos;

            if ((checkPos.ObjCellID & 0xFFFF) < 0x100)
            {
                LandDefs.AdjustToOutside(checkPos);
            }

            if (checkPos.ObjCellID != 0)
            {
                SpherePath.AdjustCheckPos(checkPos.ObjCellID);
                SpherePath.SetCheckPos(checkPos, null);

                SpherePath.CellArrayValid = true;

                return(result);
            }
            return(TransitionState.Collided);
        }
Example #5
0
        /// <summary>
        /// Attempts to slide the sphere from a collision
        /// </summary>
        public TransitionState SlideSphere(Transition transition, Vector3 disp, float radsum, int sphereNum)
        {
            var path       = transition.SpherePath;
            var collisions = transition.CollisionInfo;

            var globSphere = path.GlobalSphere[sphereNum];

            var collisionNormal = path.GlobalCurrCenter[sphereNum].Center - Center;

            if (Vec.NormalizeCheckSmall(ref collisionNormal))
            {
                return(TransitionState.Collided);
            }

            collisions.SetCollisionNormal(collisionNormal);

            var contactPlane = collisions.ContactPlaneValid ? collisions.ContactPlane : collisions.LastKnownContactPlane;
            var skid_dir     = contactPlane.Normal;
            //var direction = Vector3.Cross(skid_dir, collisionNormal);
            var direction = Vector3.Cross(collisionNormal, skid_dir);

            var blockOffset = LandDefs.GetBlockOffset(path.CurPos.ObjCellID, path.CheckPos.ObjCellID);
            var globOffset  = globSphere.Center - path.GlobalCurrCenter[sphereNum].Center + blockOffset;
            var dirLenSq    = direction.LengthSquared();

            if (dirLenSq >= PhysicsGlobals.EPSILON)
            {
                skid_dir = Vector3.Dot(globOffset, direction) * direction;

                var invDirLenSq = 1.0f / dirLenSq;

                //skid_dir *= invDirLenSq * invDirLenSq;
                skid_dir *= invDirLenSq;
                direction = skid_dir;

                // only x?
                //if (direction.X * direction.X < PhysicsGlobals.EPSILON)
                if (direction.LengthSquared() < PhysicsGlobals.EPSILON)
                {
                    return(TransitionState.Collided);
                }

                direction -= globOffset;

                path.AddOffsetToCheckPos(direction, globSphere.Radius);
                return(TransitionState.Slid);
            }

            if (Vector3.Dot(skid_dir, disp) < 0.0f)
            {
                return(TransitionState.Collided);
            }

            direction = -Vector3.Dot(globOffset, collisionNormal) * collisionNormal;
            path.AddOffsetToCheckPos(direction, globSphere.Radius);
            return(TransitionState.Slid);
        }
Example #6
0
        public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            RegionNumber = reader.ReadUInt32();
            Version      = reader.ReadUInt32();
            RegionName   = reader.ReadPString();    // "Dereth" in newer versions, "Lands of Dereth" in older
            reader.AlignBoundary();

            LandDefs.Unpack(reader);
            GameTime.Unpack(reader);

            PartsMask = reader.ReadUInt32();

            var curOffset = reader.BaseStream.Position;

            try
            {
                if ((PartsMask & 0x10) != 0)
                {
                    SkyInfo.Unpack(reader);
                }
            }
            catch
            {
                // At some point post TOD, the SkyObject had "properties" added to it.
                // Since we don't know when, this tries to catch that and revert to the old reading method before resetting back the status to TOD.
                if (DatManager.DatVersion == DatVersionType.ACTOD)
                {
                    reader.BaseStream.Position = curOffset;
                    DatManager.DatVersion      = DatVersionType.ACDM;
                    if ((PartsMask & 0x10) != 0)
                    {
                        SkyInfo.Unpack(reader);
                    }
                    DatManager.DatVersion = DatVersionType.ACTOD;
                }
            }

            if ((PartsMask & 0x01) != 0)
            {
                SoundInfo.Unpack(reader);
            }

            if ((PartsMask & 0x02) != 0)
            {
                SceneInfo.Unpack(reader);
            }

            TerrainInfo.Unpack(reader);

            if ((PartsMask & 0x0200) != 0)
            {
                RegionMisc.Unpack(reader);
            }
        }
Example #7
0
 public void AdjustCheckPos(int cellID)
 {
     if (cellID < 100)   // ?
     {
         var offset = LandDefs.GetBlockOffset(cellID, CheckPos.ObjCellID);
         CacheGlobalSphere(offset);
         CheckPos.Frame.Origin += offset;
     }
     CheckPos.ObjCellID = cellID;
 }
Example #8
0
            public static LandDefs Read(StreamReader data, StreamWriter outputData, bool write = true)
            {
                LandDefs obj = new LandDefs();

                obj.LandHeightTable = new List <float>();
                for (int i = 0; i < 256; i++)
                {
                    obj.LandHeightTable.Add(Utils.readAndWriteSingle(data, outputData, write));
                }
                return(obj);
            }
Example #9
0
        public static RegionDesc ReadFromDat()
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(REGION_ID))
            {
                return((RegionDesc)DatManager.PortalDat.FileCache[REGION_ID]);
            }
            else
            {
                DatReader  datReader = DatManager.PortalDat.GetReaderForFile(REGION_ID);
                RegionDesc region    = new RegionDesc();

                region.FileId     = datReader.ReadUInt32();
                region.BLoaded    = datReader.ReadUInt32();
                region.TimeStamp  = datReader.ReadUInt32();
                region.RegionName = datReader.ReadPString(); // "Dereth"
                datReader.AlignBoundary();
                region.PartsMask = datReader.ReadUInt32();

                // There are 7 x 4 byte entries here that are "unknown". We will just skip them.
                datReader.Offset += (7 * 4);

                region.LandDefs = LandDefs.Read(datReader);
                region.GameTime = GameTime.Read(datReader);

                region.PNext = datReader.ReadUInt32();

                if ((region.PNext & 0x10) > 0)
                {
                    region.SkyInfo = SkyDesc.Read(datReader);
                }

                if ((region.PNext & 0x01) > 0)
                {
                    region.SoundInfo = SoundDesc.Read(datReader);
                }

                if ((region.PNext & 0x02) > 0)
                {
                    region.SceneInfo = SceneDesc.Read(datReader);
                }

                region.TerrainInfo = TerrainDesc.Read(datReader);

                if ((region.PNext & 0x0200) > 0)
                {
                    region.RegionMisc = RegionMisc.Read(datReader);
                }

                DatManager.PortalDat.FileCache[REGION_ID] = region;
                return(region);
            }
        }
Example #10
0
        /// <summary>
        /// Attempts to slide a sphere from a collision
        /// </summary>
        public TransitionState SlideSphere(Transition transition, ref Vector3 collisionNormal, Vector3 currPos)
        {
            var path       = transition.SpherePath;
            var collisions = transition.CollisionInfo;

            if (collisionNormal.Equals(Vector3.Zero))
            {
                var halfOffset = (currPos - Center) * 0.5f;
                path.AddOffsetToCheckPos(halfOffset, Radius);
                return(TransitionState.Adjusted);
            }

            collisions.SetCollisionNormal(collisionNormal);

            var blockOffset = LandDefs.GetBlockOffset(path.CurPos.ObjCellID, path.CheckPos.ObjCellID);
            var gDelta      = blockOffset + (Center - currPos);

            var contactPlane = collisions.ContactPlaneValid ? collisions.ContactPlane : collisions.LastKnownContactPlane;
            var direction    = Vector3.Cross(collisionNormal, contactPlane.Normal);
            var dirLenSq     = direction.LengthSquared();

            if (dirLenSq >= PhysicsGlobals.EPSILON)
            {
                var diff        = Vector3.Dot(direction, gDelta);
                var invDirLenSq = 1.0f / dirLenSq;
                var offset      = direction * diff * invDirLenSq;
                if (offset.LengthSquared() < PhysicsGlobals.EPSILON)
                {
                    return(TransitionState.Collided);
                }

                offset -= gDelta;
                path.AddOffsetToCheckPos(offset, Radius);
                return(TransitionState.Slid);
            }

            if (Vector3.Dot(collisionNormal, contactPlane.Normal) >= 0.0f)
            {
                var diff   = Vector3.Dot(collisionNormal, gDelta);
                var offset = -collisionNormal * diff;
                path.AddOffsetToCheckPos(offset, Radius);
                return(TransitionState.Slid);
            }

            collisionNormal = -gDelta;
            if (!Vec.NormalizeCheckSmall(ref collisionNormal))
            {
                collisions.SetCollisionNormal(collisionNormal);
            }

            return(TransitionState.OK);
        }
Example #11
0
        /// <summary>
        /// Redirects a sphere to be on collision course towards a point
        /// </summary>
        /// <param name="transition">The transition information for the sphere</param>
        /// <param name="checkPos">The spherical point to redirect towards</param>
        /// <param name="disp">Currently doesn't seem to be used?</param>
        /// <param name="radsum">The sum of the sphere and spherical point radii</param>
        /// <param name="sphereNum">Used as an offset in path.GlobalCurrCenter to determine movement</param>
        /// <returns>The TransitionState either collided or adjusted</returns>
        public TransitionState CollideWithPoint(Transition transition, Sphere checkPos, Vector3 disp, float radsum, int sphereNum)
        {
            var obj        = transition.ObjectInfo;
            var path       = transition.SpherePath;
            var collisions = transition.CollisionInfo;

            var gCenter      = path.GlobalCurrCenter[sphereNum].Center;
            var globalOffset = gCenter - Center;

            // if set to PerfectClip, does a more precise check
            if (obj.State.HasFlag(ObjectInfoState.PerfectClip))
            {
                var blockOffset   = LandDefs.GetBlockOffset(path.CurPos.ObjCellID, path.CheckPos.ObjCellID);
                var checkOffset   = checkPos.Center - gCenter + blockOffset;
                var collisionTime = FindTimeOfCollision(checkOffset, globalOffset, radsum + PhysicsGlobals.EPSILON);
                if (collisionTime < PhysicsGlobals.EPSILON || collisionTime > 1.0f)
                {
                    return(TransitionState.Collided);
                }
                else
                {
                    var collisionOffset  = checkOffset * (float)collisionTime - checkOffset;
                    var old_disp         = collisionOffset + checkPos.Center - Center;
                    var invRad           = 1.0f / radsum;
                    var collision_normal = old_disp * invRad;
                    collisions.SetCollisionNormal(collision_normal);
                    path.AddOffsetToCheckPos(old_disp, checkPos.Radius);
                    return(TransitionState.Adjusted);
                }
            }
            else
            {
                if (!Vec.NormalizeCheckSmall(ref globalOffset))
                {
                    collisions.SetCollisionNormal(globalOffset);
                }

                return(TransitionState.Collided);
            }
        }
Example #12
0
        public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            RegionNumber = reader.ReadUInt32();
            Version      = reader.ReadUInt32();
            RegionName   = reader.ReadPString();    // "Dereth"
            reader.AlignBoundary();

            LandDefs.Unpack(reader);
            GameTime.Unpack(reader);

            PartsMask = reader.ReadUInt32();

            if ((PartsMask & 0x10) != 0)
            {
                SkyInfo.Unpack(reader);
            }

            if ((PartsMask & 0x01) != 0)
            {
                SoundInfo.Unpack(reader);
            }

            if ((PartsMask & 0x02) != 0)
            {
                SceneInfo.Unpack(reader);
            }

            TerrainInfo.Unpack(reader);

            if ((PartsMask & 0x0200) != 0)
            {
                RegionMisc.Unpack(reader);
            }
        }
Example #13
0
        /// <summary>
        /// Redirects a cylinder sphere to be on collision course towards a point
        /// </summary>
        /// <param name="transition">The transition information for the sphere</param>
        /// <param name="checkPos">The spherical point to redirect towards</param>
        /// <param name="disp">Used for calculating the collision normal</param>
        /// <param name="radsum">The sum of the sphere and spherical point radii</param>
        /// <param name="sphereNum">Used as an offset in path.GlobalCurrCenter to determine movement</param>
        /// <returns>The TransitionState either collided or adjusted</returns>
        public TransitionState CollideWithPoint(Transition transition, Sphere checkPos, Vector3 disp, float radsum, int sphereNum)
        {
            var obj        = transition.ObjectInfo;
            var path       = transition.SpherePath;
            var collisions = transition.CollisionInfo;

            Vector3 collisionNormal;
            var     definate = CollisionNormal(transition, checkPos, disp, radsum, sphereNum, out collisionNormal);

            if (Vec.NormalizeCheckSmall(ref collisionNormal))
            {
                return(TransitionState.Collided);
            }
            if (!obj.State.HasFlag(ObjectInfoState.PerfectClip))
            {
                collisions.SetCollisionNormal(collisionNormal);
                return(TransitionState.Collided);
            }
            var globCenter = path.GlobalCurrCenter[0].Center;
            var movement   = LandDefs.GetBlockOffset(path.CurPos.ObjCellID, path.CheckPos.ObjCellID);

            movement += checkPos.Center - globCenter;
            var old_disp = globCenter - LowPoint;

            radsum += PhysicsGlobals.EPSILON;

            // this is similar to ray/sphere intersection, could be inlined...
            var     xyMoveLenSq = movement.LengthSquared2D();
            var     xyDiff = -movement.Dot2D(old_disp);
            var     diffSq = xyDiff * xyDiff - (old_disp.LengthSquared2D() - radsum * radsum) * xyMoveLenSq;
            var     diff = (float)Math.Sqrt(diffSq);
            Vector3 scaledMovement, offset;
            float   time;   // calculated below, refactor

            if (!definate)
            {
                if (Math.Abs(movement.Z) < PhysicsGlobals.EPSILON)
                {
                    return(TransitionState.Collided);
                }
                if (movement.Z > 0.0f)
                {
                    collisionNormal = new Vector3(0, 0, -1.0f);
                    time            = (movement.Z + checkPos.Radius) / movement.Z * -1.0f;
                }
                else
                {
                    collisionNormal = new Vector3(0, 0, 1.0f);
                    time            = (checkPos.Radius + Height - movement.Z) / movement.Z;
                }

                scaledMovement = movement * time;
                var scaledLenSq = (scaledMovement + old_disp).LengthSquared2D();
                if (scaledLenSq >= radsum * radsum)
                {
                    if (Math.Abs(xyMoveLenSq) < PhysicsGlobals.EPSILON)
                    {
                        return(TransitionState.Collided);
                    }

                    if (diffSq >= 0.0f && xyMoveLenSq > PhysicsGlobals.EPSILON)
                    {
                        if (xyDiff - diff < 0.0f)
                        {
                            time = (float)((diff - movement.Dot2D(old_disp)) / xyMoveLenSq);
                        }
                        else
                        {
                            time = (float)((xyDiff - diff) / xyMoveLenSq);
                        }

                        scaledMovement = movement * time;
                    }
                    collisionNormal   = (scaledMovement + globCenter - LowPoint) / radsum;
                    collisionNormal.Z = 0.0f;
                }

                if (time < 0.0f || time > 1.0f)
                {
                    return(TransitionState.Collided);
                }

                offset = globCenter - scaledMovement - checkPos.Center;
                path.AddOffsetToCheckPos(offset, checkPos.Radius);
                collisions.SetCollisionNormal(collisionNormal);

                return(TransitionState.Adjusted);
            }

            if (collisionNormal.Z != 0.0f)
            {
                if (Math.Abs(movement.Z) < PhysicsGlobals.EPSILON)
                {
                    return(TransitionState.Collided);
                }

                if (movement.Z > 0.0f)
                {
                    time = -((old_disp.Z + checkPos.Radius) / movement.Z);
                }
                else
                {
                    time = (checkPos.Radius + Height - old_disp.Z) / movement.Z;
                }

                scaledMovement = movement * time;

                if (time < 0.0f || time > 1.0f)
                {
                    return(TransitionState.Collided);
                }

                offset = globCenter + scaledMovement - checkPos.Center;
                path.AddOffsetToCheckPos(offset, checkPos.Radius);
                collisions.SetCollisionNormal(collisionNormal);

                return(TransitionState.Adjusted);
            }

            // duplicated from above, refactor...
            if (diffSq < 0.0f || xyMoveLenSq < PhysicsGlobals.EPSILON)
            {
                return(TransitionState.Collided);
            }

            if (xyDiff - diff < 0.0f)
            {
                time = (float)((diff - movement.Dot2D(old_disp)) / xyMoveLenSq);
            }
            else
            {
                time = (float)((xyDiff - diff) / xyMoveLenSq);
            }

            scaledMovement = movement * time;
            if (time < 0.0f || time > 1.0f)
            {
                return(TransitionState.Collided);
            }

            collisionNormal   = (scaledMovement + globCenter - LowPoint) / radsum;
            collisionNormal.Z = 0.0f;
            offset            = globCenter + scaledMovement - checkPos.Center;
            path.AddOffsetToCheckPos(offset, checkPos.Radius);
            collisions.SetCollisionNormal(collisionNormal);

            return(TransitionState.Adjusted);
        }
Example #14
0
        static public void convert(string filename)
        {
            StreamReader inputFile = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read));

            if (inputFile == null)
            {
                Console.WriteLine("Unable to open {0}", filename);
                return;
            }
            StreamWriter outputFile = new StreamWriter(new FileStream("./Region/13000000 - World Info - Winter.bin", FileMode.Create, FileAccess.Write));

            if (outputFile == null)
            {
                Console.WriteLine("Unable to open 13000000 - World Info - Winter.bin");
                return;
            }

            Console.WriteLine("Converting region file to winter...");

            uint   fileHeader;
            uint   loaded;
            uint   timeStamp;
            string regionName;
            uint   partsMask;
            uint   unknown1;
            uint   unknown2;
            uint   unknown3;
            uint   unknown4;
            uint   unknown5;
            uint   unknown6;
            uint   unknown7;

            LandDefs landDef;
            GameTime gameTime;
            uint     next;

            SkyDesc     skyInfo;
            SoundDesc   soundInfo;
            SceneDesc   sceneInfo;
            TerrainDesc terrainInfo;
            RegionMisc  regionMisc;

            fileHeader = Utils.readAndWriteUInt32(inputFile, outputFile);
            if (fileHeader != 0x13000000)
            {
                Console.WriteLine("Invalid header, aborting.");
                return;
            }

            loaded     = Utils.readAndWriteUInt32(inputFile, outputFile);
            timeStamp  = Utils.readAndWriteUInt32(inputFile, outputFile);
            regionName = Utils.readAndWriteString(inputFile, outputFile);
            partsMask  = Utils.readAndWriteUInt32(inputFile, outputFile);

            unknown1 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown2 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown3 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown4 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown5 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown6 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown7 = Utils.readAndWriteUInt32(inputFile, outputFile);

            landDef  = LandDefs.Read(inputFile, outputFile);
            gameTime = GameTime.Read(inputFile, outputFile);

            next = Utils.readAndWriteUInt32(inputFile, outputFile);

            if ((next & 0x10) > 0)
            {
                skyInfo = SkyDesc.Read(inputFile, outputFile);
            }

            if ((next & 0x01) > 0)
            {
                soundInfo = SoundDesc.Read(inputFile, outputFile);
            }

            if ((next & 0x02) > 0)
            {
                sceneInfo = SceneDesc.Read(inputFile, outputFile);
            }

            terrainInfo = TerrainDesc.Read(inputFile, outputFile);

            if ((next & 0x0200) > 0)
            {
                regionMisc = RegionMisc.Read(inputFile, outputFile);
            }

            //StreamWriter outputFile2 = new StreamWriter(new FileStream("./13000000 - Terrain Textures -ToD.txt", FileMode.Create, FileAccess.Write));
            //if (outputFile2 == null)
            //{
            //    Console.WriteLine("Unable to open 13000000 - Terrain Textures - ToD.txt");
            //    return;
            //}

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps.Count; i++)
            //{
            //    TerrainAlphaMap cornerTerrainMap = terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps[i];

            //    outputFile2.WriteLine("{0}", cornerTerrainMap.TexGID.ToString("x8"));
            //    outputFile2.Flush();
            //}

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.SideTerrainMaps.Count; i++)
            //{
            //    TerrainAlphaMap sideTerrainMap = terrainInfo.LandSurfaces.texMerge.SideTerrainMaps[i];

            //    outputFile2.WriteLine("{0}", sideTerrainMap.TexGID.ToString("x8"));
            //    outputFile2.Flush();
            //}

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.RoadMaps.Count; i++)
            //{
            //    RoadAlphaMap roadMap = terrainInfo.LandSurfaces.texMerge.RoadMaps[i];

            //    outputFile2.WriteLine("{0}", roadMap.RoadTexGID.ToString("x8"));
            //    outputFile2.Flush();
            //}

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.TerrainDescription.Count; i++)//ignore first entry as it's a repeat of the second
            //{

            //    TMTerrainDesc desc = terrainInfo.LandSurfaces.texMerge.TerrainDescription[i];
            //    string terrainName = "Unknown";
            //    uint terrainColor = 0;
            //    if (i < terrainInfo.TerrainTypes.Count)
            //    {
            //        terrainName = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainName;
            //        terrainColor = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainColor;
            //    }
            //    else if (i == 32)
            //    {
            //        terrainName = "Road";
            //        terrainColor = 0;
            //    }

            //    terrainName = terrainName.PadLeft(20);

            //    outputFile2.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", desc.terrainType, terrainName, desc.terrainTex.TexGID.ToString("x8"), desc.terrainTex.TexTiling, desc.terrainTex.DetailTexGID.ToString("x8"),
            //        desc.terrainTex.DetailTexTiling, desc.terrainTex.MaxVertBright, desc.terrainTex.MaxVertHue, desc.terrainTex.MaxVertSaturate, desc.terrainTex.MinVertBright,
            //        desc.terrainTex.MinVertHue, desc.terrainTex.MinVertSaturate);

            //    //outputFile2.WriteLine("TextureConverter.toBin(\"Landscape Texture Conversion/DM/Textures/Upscaled/xxx.png\", 0x{0}, 21);//{1}",desc.terrainTex.TexGID.ToString("x8"),terrainName);

            //    //outputFile2.WriteLine("writedat client_portal.dat -f {0}={0}.bin", desc.terrainTex.TexGID.ToString("x8"));
            //    outputFile2.Flush();
            //}
            //outputFile2.Close();

            inputFile.Close();

            outputFile.Flush();
            outputFile.Close();
            Console.WriteLine("Done");
        }
Example #15
0
 public Vector3 GetCurPosCheckPosBlockOffset()
 {
     return(LandDefs.GetBlockOffset(CurPos.ObjCellID, CheckPos.ObjCellID));
 }
Example #16
0
        //In DM the 130F0000 is the equivalent of ToD 13000000 and the DM's 13000000 is possibly used for software rendering
        static public void convert(string filename)
        {
            StreamReader inputFile = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read));

            if (inputFile == null)
            {
                Console.WriteLine("Unable to open {0}", filename);
                return;
            }
            StreamWriter outputFile = new StreamWriter(new FileStream("./130F0000 - World Info - DM.bin", FileMode.Create, FileAccess.Write));

            if (outputFile == null)
            {
                Console.WriteLine("Unable to open 130F0000 - World Info - Winter.bin");
                return;
            }

            Console.WriteLine("Converting region file to winter...");

            byte[] buffer = new byte[1024];

            uint   fileHeader;
            uint   loaded;
            uint   timeStamp;
            string regionName;
            uint   partsMask;
            uint   unknown1;
            uint   unknown2;
            uint   unknown3;
            uint   unknown4;
            uint   unknown5;
            uint   unknown6;
            uint   unknown7;

            LandDefs landDef;
            GameTime gameTime;
            uint     next;

            SkyDesc     skyInfo;
            SoundDesc   soundInfo;
            SceneDesc   sceneInfo;
            TerrainDesc terrainInfo;
            RegionMisc  regionMisc;

            fileHeader = Utils.readAndWriteUInt32(inputFile, outputFile);
            if (fileHeader != 0x13000000 && fileHeader != 0x130F0000)
            {
                Console.WriteLine("Invalid header, aborting.");
                return;
            }

            loaded     = Utils.readAndWriteUInt32(inputFile, outputFile);
            timeStamp  = Utils.readAndWriteUInt32(inputFile, outputFile);
            regionName = Utils.readAndWriteString(inputFile, outputFile);
            partsMask  = Utils.readAndWriteUInt32(inputFile, outputFile);

            unknown1 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown2 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown3 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown4 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown5 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown6 = Utils.readAndWriteUInt32(inputFile, outputFile);
            unknown7 = Utils.readAndWriteUInt32(inputFile, outputFile);

            landDef  = LandDefs.Read(inputFile, outputFile);
            gameTime = GameTime.Read(inputFile, outputFile);

            next = Utils.readAndWriteUInt32(inputFile, outputFile);

            if ((next & 0x10) > 0)
            {
                skyInfo = SkyDesc.Read(inputFile, outputFile);
            }

            if ((next & 0x01) > 0)
            {
                soundInfo = SoundDesc.Read(inputFile, outputFile);
            }

            if ((next & 0x02) > 0)
            {
                sceneInfo = SceneDesc.Read(inputFile, outputFile);
            }

            terrainInfo = TerrainDesc.Read(inputFile, outputFile);

            if ((next & 0x0200) > 0)
            {
                regionMisc = RegionMisc.Read(inputFile, outputFile);
            }

            StreamWriter outputFile2 = new StreamWriter(new FileStream("./130F0000 - Terrain Textures - DM.txt", FileMode.Create, FileAccess.Write));

            if (outputFile2 == null)
            {
                Console.WriteLine("Unable to open 130F0000 - Terrain Textures - DM.txt");
                return;
            }

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps.Count; i++)
            //{
            //    TerrainAlphaMap cornerTerrainMap = terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps[i];

            //    outputFile2.WriteLine("{0}", cornerTerrainMap.TexGID.ToString("x"));
            //    outputFile2.Flush();
            //}

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.SideTerrainMaps.Count; i++)
            //{
            //    TerrainAlphaMap sideTerrainMap = terrainInfo.LandSurfaces.texMerge.SideTerrainMaps[i];

            //    outputFile2.WriteLine("{0}", sideTerrainMap.TexGID.ToString("x"));
            //    outputFile2.Flush();
            //}

            //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.RoadMaps.Count; i++)
            //{
            //    RoadAlphaMap roadMap = terrainInfo.LandSurfaces.texMerge.RoadMaps[i];

            //    outputFile2.WriteLine("{0}", roadMap.RoadTexGID.ToString("x"));
            //    outputFile2.Flush();
            //}

            for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.TerrainDescription.Count; i++)
            {
                TMTerrainDesc desc         = terrainInfo.LandSurfaces.texMerge.TerrainDescription[i];
                string        terrainName  = "Unknown";
                uint          terrainColor = 0;
                if (i < terrainInfo.TerrainTypes.Count)
                {
                    terrainName  = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainName;
                    terrainColor = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainColor;
                }
                else if (i == 31)
                {
                    terrainName  = "Unused";
                    terrainColor = 0;
                }
                else if (i == 32)
                {
                    terrainName  = "Road";
                    terrainColor = 0;
                }

                terrainName = terrainName.PadLeft(20);

                outputFile2.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", desc.terrainType, terrainName, desc.terrainTex.TexGID.ToString("x8"), desc.terrainTex.TexTiling, desc.terrainTex.DetailTexGID.ToString("x8"),
                                      desc.terrainTex.DetailTexTiling, desc.terrainTex.MaxVertBright, desc.terrainTex.MaxVertHue, desc.terrainTex.MaxVertSaturate, desc.terrainTex.MinVertBright,
                                      desc.terrainTex.MinVertHue, desc.terrainTex.MinVertSaturate);

                //outputFile2.WriteLine("{0}\t{1}", terrainName, desc.terrainTex.TexGID.ToString("x8"));
                outputFile2.Flush();
            }
            outputFile2.Close();

            inputFile.Close();

            outputFile.Flush();
            outputFile.Close();
            Console.WriteLine("Done");
        }
Example #17
0
        public TransitionState CheckOtherCells(ObjCell currCell)
        {
            if (DateTime.Now > MaxTime)
            {
                if (ShowDebugInfo)
                {
                    Debug();
                    ShowDebugInfo = false;
                    Bailout       = true;
                }
                return(TransitionState.OK);
            }

            var result = TransitionState.OK;

            SpherePath.CellArrayValid   = true;
            SpherePath.HitsInteriorCell = false;

            //ObjCell newCell = null;
            var newCell = new ObjCell();    // null check?

            ObjCell.find_cell_list(CellArray, ref newCell, SpherePath);

            for (var i = 0; i < CellArray.Cells.Count; i++)
            {
                var cell = CellArray.Cells.Values.ElementAt(i);
                if (cell == null || cell.Equals(currCell))
                {
                    continue;
                }

                var collides = cell.FindCollisions(this);
                switch (collides)
                {
                case TransitionState.Slid:
                    CollisionInfo.ContactPlaneValid   = false;
                    CollisionInfo.ContactPlaneIsWater = false;
                    return(collides);

                case TransitionState.Collided:
                case TransitionState.Adjusted:
                    return(collides);
                }
            }
            SpherePath.CheckCell = newCell;

            if (newCell != null)
            {
                SpherePath.AdjustCheckPos(newCell.ID);
                return(result);
            }

            if (SpherePath.StepDown)
            {
                return(TransitionState.Collided);
            }

            var checkPos = new Position(SpherePath.CheckPos);

            if ((checkPos.ObjCellID & 0xFFFF) < 0x100)
            {
                LandDefs.AdjustToOutside(checkPos);
            }

            if (checkPos.ObjCellID != 0)
            {
                SpherePath.AdjustCheckPos(checkPos.ObjCellID);
                SpherePath.SetCheckPos(checkPos, null);

                SpherePath.CellArrayValid = true;

                return(result);
            }
            return(TransitionState.Collided);
        }