Example #1
0
        public Vector3D GetwalkableVector(Vector3D oldloc, Vector3D destloc)
        {
            Mooege.Core.GS.Map.Scene startscene = GetSceneAt(oldloc);
            Mooege.Core.GS.Map.Scene destscene  = GetSceneAt(destloc);

            if (startscene.DynamicID == destscene.DynamicID)
            {
                foreach (var mesh in startscene.NavZone.NavCells)
                {
                    /*if (mesh.Bounds.Contains(oldloc.AsPoint()) && mesh.Bounds.Contains(destloc.AsPoint()))
                     *  return destloc;
                     * else if (mesh.Bounds.Contains(oldloc.AsPoint()))
                     * {
                     *
                     * }
                     * else
                     * {
                     *
                     * }*/
                }
            }
            else
            {
                // cross scene
            }
            return(oldloc);
        }
Example #2
0
        // Hardcoded world generate to load first scene in new tristram on top of hill
        public static World Generate(Game game)
        {
            var world = new World(game, 71150);

            var scene = new Scene(world, new Vector3D(0, 0, 0), 33349, null)
            {
                MiniMapVisibility = true,
                SceneGroupSNO = -1,
                Specification = new SceneSpecification
                {
                    CellZ = 0,
                    Cell = new Vector2D{ X = 51, Y = 46 },
                    SNOLevelAreas = new int[] { 0x00004DEB, 0x00026186, -1, -1 },
                    SNOPrevWorld = -1,
                    Unknown1 = 0,
                    SNOPrevLevelArea = -1,
                    SNONextWorld = -1,
                    Unknown2 = 0,
                    SNONextLevelArea = -1,
                    SNOMusic = 0x000206F8,
                    SNOCombatMusic = -1,
                    SNOAmbient = 0x0002734F,
                    SNOReverb = 0x000375D0,
                    SNOWeather = 0x00013220,
                    SNOPresetWorld = 0x000115EE,
                    Unknown3 = -1,
                    Unknown4 = -1,
                    Unknown5 = 0,
                    ClusterID = -1,
                    SceneCachedValues = new SceneCachedValues
                    {
                        Unknown1 = 63,
                        Unknown2 = 96,
                        Unknown3 = 96,
                        Unknown4 = new int[] { 0, 0x4C8, 0, 0 },
                        Unknown5 = 9,
                        AABB1 = new Common.Types.Collision.AABB { Max = new Vector3D { X = 115.9387f, Y = 125.2578f, Z = 43.82879f }, Min = new Vector3D { X = 124.0615f, Y = 131.6655f, Z = 57.26923f } },
                        AABB2 = new Common.Types.Collision.AABB { Max = new Vector3D { X = 115.9387f, Y = 125.2578f, Z = 43.82879f }, Min = new Vector3D { X = 124.0615f, Y = 131.6655f, Z = 57.26923f } },
                    },
                },
                RotationAxis = new Vector3D{ X = 0.0f, Y = 0.0f, Z = 0.0f },
                RotationW = 1.0f,
                Position = new Vector3D { X = 3060.0f, Y = 2760.0f, Z = 0.0f },
            };

            scene.LoadMarkers();

            return world;
        }
Example #3
0
        public static World Generate(Game game, int worldSNO)
        {
            if (!MPQStorage.Data.Assets[SNOGroup.Worlds].ContainsKey(worldSNO))
            {
                Logger.Error("Can't find a valid world definition for sno: {0}", worldSNO);
                return(null);
            }

            var worldAsset = MPQStorage.Data.Assets[SNOGroup.Worlds][worldSNO];
            var worldData  = (Mooege.Common.MPQ.FileFormats.World)worldAsset.Data;


            if (worldData.IsGenerated)
            {
                Logger.Error("World {0} [{1}] is a dynamic world! Can't generate proper dynamic worlds yet!", worldAsset.Name, worldAsset.SNOId);

                if (!GenerateRandomDungeon(worldSNO, worldData))
                {
                    return(null);
                }
            }

            var world      = new World(game, worldSNO);
            var levelAreas = new Dictionary <int, List <Scene> >();

            // Create a clusterID => Cluster Dictionary
            var clusters = new Dictionary <int, Mooege.Common.MPQ.FileFormats.SceneCluster>();

            foreach (var cluster in worldData.SceneClusterSet.SceneClusters)
            {
                clusters[cluster.ClusterId] = cluster;
            }

            // Scenes are not aligned to (0, 0) but apparently need to be -farmy
            float minX = worldData.SceneParams.SceneChunks.Min(x => x.PRTransform.Vector3D.X);
            float minY = worldData.SceneParams.SceneChunks.Min(x => x.PRTransform.Vector3D.Y);

            // Count all occurences of each cluster /fasbat
            var clusterCount = new Dictionary <int, int>();

            foreach (var sceneChunk in worldData.SceneParams.SceneChunks)
            {
                var cID = sceneChunk.SceneSpecification.ClusterID;
                if (cID != -1 && clusters.ContainsKey(cID)) // Check for wrong clusters /fasbat
                {
                    if (!clusterCount.ContainsKey(cID))
                    {
                        clusterCount[cID] = 0;
                    }
                    clusterCount[cID]++;
                }
            }

            // For each cluster generate a list of randomly selected subcenes /fasbat
            var clusterSelected = new Dictionary <int, List <Mooege.Common.MPQ.FileFormats.SubSceneEntry> >();

            foreach (var cID in clusterCount.Keys)
            {
                var selected = new List <Mooege.Common.MPQ.FileFormats.SubSceneEntry>();
                clusterSelected[cID] = selected;
                var count = clusterCount[cID];
                foreach (var group in clusters[cID].SubSceneGroups)          // First select from each subscene group /fasbat
                {
                    for (int i = 0; i < group.I0 && count > 0; i++, count--) //TODO Rename I0 to requiredCount? /fasbat
                    {
                        var subSceneEntry = RandomHelper.RandomItem(group.Entries, entry => entry.Probability);
                        selected.Add(subSceneEntry);
                    }

                    if (count == 0)
                    {
                        break;
                    }
                }

                while (count > 0) // Fill the rest with defaults /fasbat
                {
                    //Default subscenes are not currently stored in db, use first if available
                    //var subSceneEntry = RandomHelper.RandomItem(clusters[cID].Default.Entries, entry => entry.Probability);
                    if (clusters[cID].SubSceneGroups.Count > 0)
                    {
                        var subSceneEntry = RandomHelper.RandomItem(clusters[cID].SubSceneGroups.First().Entries, entry => entry.Probability);
                        selected.Add(subSceneEntry);
                    }
                    count--;
                }
            }

            foreach (var sceneChunk in worldData.SceneParams.SceneChunks)
            {
                var position = sceneChunk.PRTransform.Vector3D - new Vector3D(minX, minY, 0);
                var scene    = new Scene(world, position, sceneChunk.SNOHandle.Id, null)
                {
                    MiniMapVisibility = true,
                    RotationW         = sceneChunk.PRTransform.Quaternion.W,
                    RotationAxis      = sceneChunk.PRTransform.Quaternion.Vector3D,
                    SceneGroupSNO     = -1
                };

                // If the scene has a subscene (cluster ID is set), choose a random subscenes from the cluster load it and attach it to parent scene /farmy
                if (sceneChunk.SceneSpecification.ClusterID != -1)
                {
                    if (!clusters.ContainsKey(sceneChunk.SceneSpecification.ClusterID))
                    {
                        Logger.Warn("Referenced clusterID {0} not found for chunk {1} in world {2}", sceneChunk.SceneSpecification.ClusterID, sceneChunk.SNOHandle.Id, worldSNO);
                    }
                    else
                    {
                        var entries = clusterSelected[sceneChunk.SceneSpecification.ClusterID]; // Select from our generated list /fasbat
                        Mooege.Common.MPQ.FileFormats.SubSceneEntry subSceneEntry = null;

                        if (entries.Count > 0)
                        {
                            //subSceneEntry = entries[RandomHelper.Next(entries.Count - 1)];

                            subSceneEntry = RandomHelper.RandomItem <Mooege.Common.MPQ.FileFormats.SubSceneEntry>(entries, entry => 1); // TODO Just shuffle the list, dont random every time. /fasbat
                            entries.Remove(subSceneEntry);
                        }
                        else
                        {
                            Logger.Error("No SubScenes defined for cluster {0} in world {1}", sceneChunk.SceneSpecification.ClusterID, world.DynamicID);
                        }

                        Vector3D pos = FindSubScenePosition(sceneChunk); // TODO According to BoyC, scenes can have more than one subscene, so better enumerate over all subscenepositions /farmy

                        if (pos == null)
                        {
                            Logger.Error("No scene position marker for SubScenes of Scene {0} found", sceneChunk.SNOHandle.Id);
                        }
                        else
                        {
                            // subSceneEntry is null is there is no subSceneGroups, until we get default subScene saved in DB.
                            if (subSceneEntry != null)
                            {
                                // HACK: avoid trying to create scenes with SNOs that aren't valid
                                if (MPQStorage.Data.Assets[SNOGroup.Scene].ContainsKey(subSceneEntry.SNOScene))
                                {
                                    var subScenePosition = scene.Position + pos;
                                    var subscene         = new Scene(world, subScenePosition, subSceneEntry.SNOScene, scene)
                                    {
                                        MiniMapVisibility = true,
                                        RotationW         = sceneChunk.PRTransform.Quaternion.W,
                                        RotationAxis      = sceneChunk.PRTransform.Quaternion.Vector3D,
                                        Specification     = sceneChunk.SceneSpecification
                                    };
                                    scene.Subscenes.Add(subscene);
                                    subscene.LoadMarkers();
                                }
                                else
                                {
                                    Logger.Error("Scene not found in mpq storage: {0}", subSceneEntry.SNOScene);
                                }
                            }
                        }
                    }
                }
                scene.Specification = sceneChunk.SceneSpecification;
                scene.LoadMarkers();

                // add scene to level area dictionary
                foreach (var levelArea in scene.Specification.SNOLevelAreas)
                {
                    if (levelArea != -1)
                    {
                        if (!levelAreas.ContainsKey(levelArea))
                        {
                            levelAreas.Add(levelArea, new List <Scene>());
                        }

                        levelAreas[levelArea].Add(scene);
                    }
                }
            }

            loadLevelAreas(levelAreas, world);
            return(world);
        }
Example #4
0
        public static World Generate(Game game, int worldSNO)
        {
            if (!MPQStorage.Data.Assets[SNOGroup.Worlds].ContainsKey(worldSNO))
            {
                Logger.Error("Can't find a valid world definition for sno: {0}", worldSNO);
                return null;
            }

            var worldAsset = MPQStorage.Data.Assets[SNOGroup.Worlds][worldSNO];
            var worldData = (Mooege.Common.MPQ.FileFormats.World)worldAsset.Data;


            if (worldData.IsGenerated)
            {
                Logger.Error("World {0} [{1}] is a dynamic world! Can't generate proper dynamic worlds yet!", worldAsset.Name, worldAsset.SNOId);

                GenerateRandomDungeon(worldSNO, worldData);
            }

            var world = new World(game, worldSNO);
            var levelAreas = new Dictionary<int, List<Scene>>();

            // Create a clusterID => Cluster Dictionary
            var clusters = new Dictionary<int, Mooege.Common.MPQ.FileFormats.SceneCluster>();
            foreach (var cluster in worldData.SceneClusterSet.SceneClusters)
                clusters[cluster.ClusterId] = cluster;

            // Scenes are not aligned to (0, 0) but apparently need to be -farmy
            float minX = worldData.SceneParams.SceneChunks.Min(x => x.PRTransform.Vector3D.X);
            float minY = worldData.SceneParams.SceneChunks.Min(x => x.PRTransform.Vector3D.Y);

            // Count all occurences of each cluster /fasbat
            var clusterCount = new Dictionary<int, int>();

            foreach (var sceneChunk in worldData.SceneParams.SceneChunks)
            {
                var cID = sceneChunk.SceneSpecification.ClusterID;
                if (cID != -1 && clusters.ContainsKey(cID)) // Check for wrong clusters /fasbat
                {
                    if (!clusterCount.ContainsKey(cID))
                        clusterCount[cID] = 0;
                    clusterCount[cID]++;
                }
            }

            // For each cluster generate a list of randomly selected subcenes /fasbat
            var clusterSelected = new Dictionary<int, List<Mooege.Common.MPQ.FileFormats.SubSceneEntry>>();
            foreach (var cID in clusterCount.Keys)
            {
                var selected = new List<Mooege.Common.MPQ.FileFormats.SubSceneEntry>();
                clusterSelected[cID] = selected;
                var count = clusterCount[cID];
                foreach (var group in clusters[cID].SubSceneGroups) // First select from each subscene group /fasbat
                {
                    for (int i = 0; i < group.I0 && count > 0; i++, count--) //TODO Rename I0 to requiredCount? /fasbat
                    {
                        var subSceneEntry = RandomHelper.RandomItem(group.Entries, entry => entry.Probability);
                        selected.Add(subSceneEntry);
                    }

                    if (count == 0)
                        break;
                }

                while (count > 0) // Fill the rest with defaults /fasbat
                {
                    var subSceneEntry = RandomHelper.RandomItem(clusters[cID].Default.Entries, entry => entry.Probability);
                    selected.Add(subSceneEntry);
                    count--;
                }
            }

            foreach (var sceneChunk in worldData.SceneParams.SceneChunks)
            {
                var position = sceneChunk.PRTransform.Vector3D - new Vector3D(minX, minY, 0);
                var scene = new Scene(world, position, sceneChunk.SNOHandle.Id, null)
                {
                    MiniMapVisibility = true,
                    RotationW = sceneChunk.PRTransform.Quaternion.W,
                    RotationAxis = sceneChunk.PRTransform.Quaternion.Vector3D,
                    SceneGroupSNO = -1
                };

                // If the scene has a subscene (cluster ID is set), choose a random subscenes from the cluster load it and attach it to parent scene /farmy
                if (sceneChunk.SceneSpecification.ClusterID != -1)
                {
                    if (!clusters.ContainsKey(sceneChunk.SceneSpecification.ClusterID))
                    {
                        Logger.Warn("Referenced clusterID {0} not found for chunk {1} in world {2}", sceneChunk.SceneSpecification.ClusterID, sceneChunk.SNOHandle.Id, worldSNO);
                    }
                    else
                    {
                        var entries = clusterSelected[sceneChunk.SceneSpecification.ClusterID]; // Select from our generated list /fasbat
                        Mooege.Common.MPQ.FileFormats.SubSceneEntry subSceneEntry = null;

                        if (entries.Count > 0)
                        {
                            //subSceneEntry = entries[RandomHelper.Next(entries.Count - 1)];

                            subSceneEntry = RandomHelper.RandomItem<Mooege.Common.MPQ.FileFormats.SubSceneEntry>(entries, entry => 1); // TODO Just shuffle the list, dont random every time. /fasbat
                            entries.Remove(subSceneEntry);
                        }
                        else
                            Logger.Error("No SubScenes defined for cluster {0} in world {1}", sceneChunk.SceneSpecification.ClusterID, world.DynamicID);

                        Vector3D pos = FindSubScenePosition(sceneChunk); // TODO According to BoyC, scenes can have more than one subscene, so better enumerate over all subscenepositions /farmy

                        if (pos == null)
                        {
                            Logger.Error("No scene position marker for SubScenes of Scene {0} found", sceneChunk.SNOHandle.Id);
                        }
                        else
                        {
                            // HACK: avoid trying to create scenes with SNOs that aren't valid
                            if (MPQStorage.Data.Assets[SNOGroup.Scene].ContainsKey(subSceneEntry.SNOScene))
                            {
                                var subScenePosition = scene.Position + pos;
                                var subscene = new Scene(world, subScenePosition, subSceneEntry.SNOScene, scene)
                                {
                                    MiniMapVisibility = true,
                                    RotationW = sceneChunk.PRTransform.Quaternion.W,
                                    RotationAxis = sceneChunk.PRTransform.Quaternion.Vector3D,
                                    Specification = sceneChunk.SceneSpecification
                                };
                                scene.Subscenes.Add(subscene);
                                subscene.LoadMarkers();
                            }
                            else
                            {
                                Logger.Error("Scene not found in mpq storage: {0}", subSceneEntry.SNOScene);
                            }
                        }
                    }

                }
                scene.Specification = sceneChunk.SceneSpecification;
                scene.LoadMarkers();

                // add scene to level area dictionary
                foreach (var levelArea in scene.Specification.SNOLevelAreas)
                {
                    if (levelArea != -1)
                    {
                        if (!levelAreas.ContainsKey(levelArea))
                            levelAreas.Add(levelArea, new List<Scene>());

                        levelAreas[levelArea].Add(scene);
                    }
                }
            }

            loadLevelAreas(levelAreas, world);
            return world;
        }