Ejemplo n.º 1
0
        public override void OnInitialise()
        {
            SystemCore.CursorVisible = true;
            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();

            cameraObject = new GameObject();

            //give it some random ID to keep it out the range of the doom objects
            cameraObject.ID = 990000;


            cameraObject.AddComponent(new ComponentCamera(MathHelper.PiOver4, SystemCore.GraphicsDevice.Viewport.AspectRatio, 0.25f, 1000.0f, false));
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(cameraObject);
            SystemCore.SetActiveCamera(cameraObject.GetComponent <ComponentCamera>());
            cameraObject.Transform.AbsoluteTransform = Matrix.CreateWorld(new Vector3(0, -500, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1));


            var file = new FileInfo(filePath);

            using (var fs = file.OpenRead())
            {
                var doomWad = DoomWad.FromFile(filePath);

                string desiredLevel = "E1M1";

                int levelMarker = doomWad.Index.FindIndex(x => x.Name.Contains(desiredLevel));
                for (int i = levelMarker + 1; i < doomWad.NumIndexEntries; i++)
                {
                    var currentIndex = doomWad.Index[i];

                    if (currentIndex.Name.Contains("E1M2"))
                    {
                        break;
                    }

                    if (currentIndex.Name == ("SECTORS\0"))
                    {
                        sectors = currentIndex.Contents as DoomWad.Sectors;
                    }

                    if (currentIndex.Name.Contains("BLOCKMAP"))
                    {
                        blockMap = currentIndex.Contents as DoomWad.Blockmap;
                    }

                    if (currentIndex.Name.Contains("SIDEDEF"))
                    {
                        sideDefs = currentIndex.Contents as DoomWad.Sidedefs;
                    }

                    if (currentIndex.Name.Contains("VERTEX"))
                    {
                        vertices = currentIndex.Contents as DoomWad.Vertexes;
                    }

                    if (currentIndex.Name.Contains("THING"))
                    {
                        things = currentIndex.Contents as DoomWad.Things;
                    }

                    if (currentIndex.Name.Contains("LINEDEF"))
                    {
                        lineDefs = currentIndex.Contents as DoomWad.Linedefs;
                    }
                }
            }


            worldObjects = new Dictionary <int, GameObject>();
            apiHandler   = new DoomAPIHandler(restHost, restPort);
            aStar        = new AStar();

            GenerateNavStructures();

            base.OnInitialise();
        }
Ejemplo n.º 2
0
        public void ParseWad()
        {
            var file = new FileInfo(wadPath);

            using (var fs = file.OpenRead())
            {
                var doomWad = DoomWad.FromFile(wadPath);

                string desiredLevel = startMarker;

                int levelMarker = doomWad.Index.FindIndex(x => x.Name.Contains(desiredLevel));
                for (int i = levelMarker + 1; i < doomWad.NumIndexEntries; i++)
                {
                    var currentIndex = doomWad.Index[i];

                    if (currentIndex.Name.Contains(endMarker))
                    {
                        break;
                    }

                    if (currentIndex.Name == ("SECTORS\0"))
                    {
                        sectors = currentIndex.Contents as DoomWad.Sectors;
                    }

                    if (currentIndex.Name.Contains("BLOCKMAP"))
                    {
                        blockMap = currentIndex.Contents as DoomWad.Blockmap;
                    }

                    if (currentIndex.Name.Contains("SIDEDEF"))
                    {
                        sideDefs = currentIndex.Contents as DoomWad.Sidedefs;
                    }

                    if (currentIndex.Name.Contains("VERTEX"))
                    {
                        vertices = currentIndex.Contents as DoomWad.Vertexes;
                    }

                    if (currentIndex.Name.Contains("THING"))
                    {
                        things = currentIndex.Contents as DoomWad.Things;
                    }

                    if (currentIndex.Name.Contains("LINEDEF"))
                    {
                        lineDefs = currentIndex.Contents as DoomWad.Linedefs;
                    }
                }
            }

            var exitLine = lineDefs.Entries.Find(x => x.LineType == 11);

            DoomWad.Vertex startExit = vertices.Entries[exitLine.VertexStartIdx];
            DoomWad.Vertex endExit   = vertices.Entries[exitLine.VertexEndIdx];
            var            p1Exit    = new Vector3((startExit.X) / scale + offsetX, 0,
                                                   (startExit.Y) / scale + offsetZ);
            var p2Exit = new Vector3((endExit.X) / scale + offsetX, 0,
                                     (endExit.Y) / scale + offsetZ);

            LevelEnd = (p1Exit + p2Exit) / 2;


            levelLines = new List <DoomLine>();
            foreach (DoomWad.Linedef lineDef in lineDefs.Entries)
            {
                //sector tag is useless - always 0
                //DoomWad.Sector sector = sectors.Entries[lineDef.SectorTag];

                DoomWad.Sidedef sideDefLeft, sideDefRight;
                sideDefLeft = null;

                //most lineDefs are not double sided. SideDef ID of 65535 means no side def for this direction
                if (lineDef.SidedefLeftIdx != 65535)
                {
                    sideDefLeft = sideDefs.Entries[lineDef.SidedefLeftIdx];
                }

                sideDefRight = sideDefs.Entries[lineDef.SidedefRightIdx];

                var sector = sectors.Entries[sideDefRight.SectorId];

                Color lineColor, lineColorMin, lineColorMax;


                float heightDiff = 0;
                if (sideDefLeft != null)
                {
                    var sec1 = sectors.Entries[sideDefRight.SectorId];
                    var sec2 = sectors.Entries[sideDefLeft.SectorId];
                    heightDiff = Math.Abs(sec1.FloorZ - sec2.FloorZ);
                }



                //convert the ceiling or floor height to a useful range.
                float convertedHeight = sector.CeilZ / 8;
                convertedHeight += 17;
                convertedHeight /= 34;

                lineColorMin = Color.Blue;
                lineColorMax = Color.Red;

                lineColor = Color.Lerp(lineColorMin, lineColorMax, convertedHeight);


                DoomWad.Vertex start = vertices.Entries[lineDef.VertexStartIdx];
                DoomWad.Vertex end   = vertices.Entries[lineDef.VertexEndIdx];



                var p1 = new Vector3((start.X) / scale + offsetX, 0,
                                     (start.Y) / scale + offsetZ);

                var p2 = new Vector3((end.X) / scale + offsetX, 0,
                                     (end.Y) / scale + offsetZ);

                if (sideDefLeft == null)
                {
                    levelLines.Add(new DoomLine()
                    {
                        start = p1, end = p2, color = lineColor, BlocksLineOfSight = true
                    });
                }

                if (sideDefLeft != null && heightDiff > 24)
                {
                    levelLines.Add(new DoomLine()
                    {
                        start = p1, end = p2, color = lineColor, BlocksLineOfSight = false
                    });
                }

                if (sideDefLeft != null && heightDiff <= 24)
                {
                    Console.WriteLine("Potential door");
                    if (lineDef.LineType == 1)
                    {
                        Doors.Add(new DoomLine()
                        {
                            start = p1, end = p2, color = Color.OrangeRed, BlocksLineOfSight = true
                        });
                    }
                    else
                    {
                        int    value     = lineDef.Flags;
                        string binary    = Convert.ToString(value, 2);
                        int    blockFlag = 1;
                        var    mystring  = binary.Substring(binary.Length - 1, 1);
                        if (mystring == blockFlag.ToString())
                        {
                            levelLines.Add(new DoomLine()
                            {
                                start = p1, end = p2, color = Color.Aquamarine, BlocksLineOfSight = true
                            });
                        }
                        else
                        {
                            //find out if the line here crosses into a floor damage sector
                            if (sector.SpecialType == DoomWad.Sector.SpecialSector.DDamageEnd ||
                                sector.SpecialType == DoomWad.Sector.SpecialSector.DDamageHellslime ||
                                sector.SpecialType == DoomWad.Sector.SpecialSector.DDamageLavaHefty ||
                                sector.SpecialType == DoomWad.Sector.SpecialSector.DDamageLavaWimpy ||
                                sector.SpecialType == DoomWad.Sector.SpecialSector.DDamageNukage ||
                                sector.SpecialType == DoomWad.Sector.SpecialSector.DDamageSuperHellslime)
                            {
                                HazardLines.Add(new DoomLine()
                                {
                                    start = p1, end = p2, color = Color.Green, BlocksLineOfSight = false
                                });
                            }
                            else
                            {
                                InternalLines.Add(new DoomLine()
                                {
                                    start = p1, end = p2, color = Color.White, BlocksLineOfSight = false
                                });
                            }
                        }
                    }
                }
            }


            var blockingThings = things.Entries.Where(x => blockingObjectIDs.Contains(x.Type));

            foreach (DoomWad.Thing t in blockingThings)
            {
                var pos = new Vector3((t.X) / scale + offsetX, 0,
                                      (t.Y) / scale + offsetZ);

                float   size        = 0.2f;
                Vector3 topLeft     = pos + new Vector3(-size, 0, size);
                Vector3 topRight    = pos + new Vector3(size, 0, size);
                Vector3 bottomRight = pos + new Vector3(size, 0, -size);
                Vector3 bottomLeft  = pos + new Vector3(-size, 0, -size);
                levelLines.Add(new DoomLine()
                {
                    start = topLeft, end = topRight, color = Color.Red, BlocksLineOfSight = true
                });
                levelLines.Add(new DoomLine()
                {
                    start = topRight, end = bottomRight, color = Color.Red, BlocksLineOfSight = true
                });
                levelLines.Add(new DoomLine()
                {
                    start = bottomRight, end = bottomLeft, color = Color.Red, BlocksLineOfSight = true
                });
                levelLines.Add(new DoomLine()
                {
                    start = bottomLeft, end = topLeft, color = Color.Red, BlocksLineOfSight = true
                });
            }
        }