예제 #1
0
        public bool Load()
        {
            System.Text.Encoding encodeType = System.Text.Encoding.ASCII;
            string loadedFileSave           = "";

            //string MapPath = EnvPaths.GetMapsPath();

            if (!System.IO.File.Exists(MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.save)))
            {
                return(false);
            }

            loadedFileSave = System.IO.File.ReadAllText(MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.save), encodeType);

            //string loadedFileFunctions = LuaParser.Read.GetStructureText("lua_variable_functions.lua");
            //string loadedFileEndFunctions = LuaParser.Read.GetStructureText("lua_variable_end_functions.lua");
            string loadedFileFunctions    = MapLuaParser.Current.SaveLuaHeader.text;
            string loadedFileEndFunctions = MapLuaParser.Current.SaveLuaFooter.text;

            loadedFileSave = loadedFileFunctions + loadedFileSave + loadedFileEndFunctions;

            LuaFile = new Lua();
            LuaFile.LoadCLRPackage();

            loadedFileSave = loadedFileSave.Replace("GROUP ", "");

            try
            {
                LuaFile.DoString(loadedFileSave);
            }
            catch (NLua.Exceptions.LuaException e)
            {
                Debug.LogError(LuaParser.Read.FormatException(e), MapLuaParser.Current.gameObject);
                //HelperGui.MapLoaded = false;
                return(false);
            }

            Unload();
            LuaTable ScenarioInfoTab = LuaFile.GetTable(KEY_Scenario);

            Data.next_area_id = LuaParser.Read.IntFromTable(ScenarioInfoTab, Scenario.KEY_NEXTAREAID);


            // Areas
            LuaTable AreasTable = (LuaTable)ScenarioInfoTab.RawGet(Scenario.KEY_AREAS);

            LuaTable[] AreaTabs  = LuaParser.Read.GetTableTables(AreasTable);
            string[]   AreaNames = LuaParser.Read.GetTableKeys(AreasTable);

            Data.areas = new Areas[AreaTabs.Length];
            for (int i = 0; i < AreaTabs.Length; i++)
            {
                Data.areas[i]           = new Areas();
                Data.areas[i].Name      = AreaNames[i];
                Data.areas[i].rectangle = LuaParser.Read.RectFromTable(AreaTabs[i], Areas.KEY_RECTANGLE);
            }

            // Master Chains
            LuaTable MasterChainTable = (LuaTable)ScenarioInfoTab.RawGet(Scenario.KEY_MASTERCHAIN);

            LuaTable[] MasterChainTabs  = LuaParser.Read.GetTableTables(MasterChainTable);
            string[]   MasterChainNames = LuaParser.Read.GetTableKeys(MasterChainTable);
            Data.MasterChains = new MasterChain[MasterChainNames.Length];
            List <Marker> AllLoadedMarkers = new List <Marker>();

            for (int mc = 0; mc < MasterChainNames.Length; mc++)
            {
                Data.MasterChains[mc]      = new MasterChain();
                Data.MasterChains[mc].Name = MasterChainNames[mc];

                LuaTable   MarkersTable = (LuaTable)MasterChainTabs[mc].RawGet(MasterChain.KEY_MARKERS);
                LuaTable[] MarkersTabs  = LuaParser.Read.GetTableTables(MarkersTable);
                string[]   MarkersNames = LuaParser.Read.GetTableKeys(MarkersTable);
                Data.MasterChains[mc].Markers = new List <Marker>();
                for (int m = 0; m < MarkersTabs.Length; m++)
                {
                    Marker LoadedMarker = new Marker(MarkersNames[m], MarkersTabs[m]);


                    if (LoadedMarker.MarkerType == Marker.MarkerTypes.LandPathNode && LoadedMarker.Name.StartsWith("APM_Land_") ||
                        LoadedMarker.MarkerType == Marker.MarkerTypes.WaterPathNode && LoadedMarker.Name.StartsWith("APM_Water_")
                        )
                    {
                        continue;
                    }
                    else if (LoadedMarker.MarkerType == Marker.MarkerTypes.LandPathNode && LoadedMarker.Name.StartsWith("APM_Land_"))
                    {
                        LoadedMarker.MarkerType = Marker.MarkerTypes.AutoPathNode;
                        LoadedMarker.Name       = LoadedMarker.Name.Replace("APM_Amphibious_", "");
                        LoadedMarker.adjacentTo = LoadedMarker.adjacentTo.Replace("APM_Amphibious_", "");
                    }


                    Data.MasterChains[mc].Markers.Add(LoadedMarker);
                }
                AllLoadedMarkers.AddRange(Data.MasterChains[mc].Markers);
            }

            Markers.MarkersControler.LoadMarkers();

            // Chains
            LuaTable ChainsTable = (LuaTable)ScenarioInfoTab.RawGet(Scenario.KEY_CHAINS);

            LuaTable[] ChainTabs  = LuaParser.Read.GetTableTables(ChainsTable);
            string[]   ChainNames = LuaParser.Read.GetTableKeys(ChainsTable);
            Data.Chains = new Chain[ChainNames.Length];
            for (int c = 0; c < ChainNames.Length; c++)
            {
                Data.Chains[c]         = new Chain();
                Data.Chains[c].Name    = ChainNames[c];
                Data.Chains[c].Markers = LuaParser.Read.StringArrayFromTable(ChainTabs[c], Chain.KEY_MARKERS);
                Data.Chains[c].ConnectMarkers(AllLoadedMarkers);
            }


            Data.next_queue_id = LuaParser.Read.IntFromTable(ScenarioInfoTab, Scenario.KEY_NEXTQUEUEID);
            // Orders - leave as empty
            Data.next_platoon_id = LuaParser.Read.IntFromTable(ScenarioInfoTab, Scenario.KEY_NEXTPLATOONID);

            // Platoons
            LuaTable PlatoonsTable = (LuaTable)ScenarioInfoTab.RawGet(Scenario.KEY_PLATOONS);

            LuaTable[] PlatoonsTabs  = LuaParser.Read.GetTableTables(PlatoonsTable);
            string[]   PlatoonsNames = LuaParser.Read.GetTableKeys(PlatoonsTable);
            Data.Platoons = new Platoon[PlatoonsNames.Length];
            for (int p = 0; p < PlatoonsNames.Length; p++)
            {
                Data.Platoons[p] = new Platoon(PlatoonsNames[p], PlatoonsTabs[p]);
            }


            Data.next_army_id  = LuaParser.Read.IntFromTable(ScenarioInfoTab, Scenario.KEY_NEXTARMYID);
            Data.next_group_id = LuaParser.Read.IntFromTable(ScenarioInfoTab, Scenario.KEY_NEXTGROUPID);
            Data.next_unit_id  = LuaParser.Read.IntFromTable(ScenarioInfoTab, Scenario.KEY_NEXTUNITID);

            // Armies
            LuaTable ArmiesTable = (LuaTable)ScenarioInfoTab.RawGet(Scenario.KEY_ARMIES);

            LuaTable[] ArmiesTabs  = LuaParser.Read.GetTableTables(ArmiesTable);
            string[]   ArmiesNames = LuaParser.Read.GetTableKeys(ArmiesTable);
            //Data.Armies = new Army[ArmiesNames.Length];
            for (int a = 0; a < ArmiesNames.Length; a++)
            {
                Army NewArmy = new Army(ArmiesNames[a], ArmiesTabs[a]);
                MapLuaParser.Current.ScenarioLuaFile.AddDataToArmy(NewArmy);
            }

            // Conversions
            MapLuaParser.Current.ScenarioLuaFile.CheckForEmptyArmy();
            ConnectAdjacentMarkers();

            return(true);
        }
예제 #2
0
    public IEnumerator LoadScmapFile()
    {
        map = new Map();

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        if (map.Load(path))
        {
            UpdateLighting();
        }
        else
        {
            Debug.LogWarning("File not found!\n" + path);
            yield break;
        }


        if (map.VersionMinor >= 60)
        {
            map.AdditionalSkyboxData.Data.UpdateSize();
        }
        else
        {
            LoadDefaultSkybox();
        }


        EnvPaths.CurrentGamedataPath = EnvPaths.GamedataPath;

        //Shader
        MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP";
        ToogleShader();

        // Set Variables
        int   xRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;


        TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex);
        Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        Shader.SetGlobalFloat("_WaterScaleX", xRes);
        Shader.SetGlobalFloat("_WaterScaleZ", xRes);

        //*****************************************
        // ***** Set Terrain proportives
        //*****************************************

        LoadHeights();


        // Load Stratum Textures Paths
        LoadStratumScdTextures();
        MapLuaParser.Current.InfoPopup.Show(true, "Loading map...\n( Assing scmap data )");


        WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes);
        TerrainMaterial.SetFloat("_GridScale", HalfxRes);
        TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        WaterMaterial.SetFloat("_GridScale", HalfxRes);


        for (int i = 0; i < map.EnvCubemapsFile.Length; i++)
        {
            if (map.EnvCubemapsName[i] == "<default>")
            {
                try
                {
                    CurrentEnvironmentCubemap = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.EnvCubemapsFile[i]);
                    Shader.SetGlobalTexture("environmentSampler", CurrentEnvironmentCubemap);
                }
                catch
                {
                    WaterMaterial.SetTexture("environmentSampler", DefaultWaterSky);
                }
            }
        }

        SetWaterTextures();

        SetWater();

        Teren.gameObject.layer = 8;

        SetTextures();

        if (Slope)
        {
            ToogleSlope(Slope);
        }

        yield return(null);
    }
예제 #3
0
    public void SaveScmapFile()
    {
        float LowestElevation  = ScmapEditor.MaxElevation;
        float HighestElevation = 0;

        if (Teren)
        {
            heights       = Teren.terrainData.GetHeights(0, 0, Teren.terrainData.heightmapWidth, Teren.terrainData.heightmapHeight);
            heightsLength = heights.GetLength(0);

            int y = 0;
            int x = 0;
            for (y = 0; y < map.Width + 1; y++)
            {
                for (x = 0; x < map.Height + 1; x++)
                {
                    float Height = heights[x, y];

                    LowestElevation  = Mathf.Min(LowestElevation, Height);
                    HighestElevation = Mathf.Max(HighestElevation, Height);

                    //double HeightValue = ((double)Height) * HeightResize;
                    //map.SetHeight(y, map.Height - x, (short)(HeightValue + RoundingError));
                    map.SetHeight(y, map.Height - x, (ushort)(Height * HeightResize));
                }
            }
        }

        LowestElevation  = (LowestElevation * TerrainHeight) / 0.1f;
        HighestElevation = (HighestElevation * TerrainHeight) / 0.1f;


        if (HighestElevation - LowestElevation > 49.9)
        {
            Debug.Log("Lowest point: " + LowestElevation);
            Debug.Log("Highest point: " + HighestElevation);

            Debug.LogWarning("Height difference is too high! it might couse rendering issues! Height difference is: " + (HighestElevation - LowestElevation));
            GenericInfoPopup.ShowInfo("Height difference " + (HighestElevation - LowestElevation) + " is too high!\nIt might couse rendering issues!");
        }


        if (MapLuaParser.Current.EditMenu.MapInfoMenu.SaveAsFa.isOn)
        {
            if (map.AdditionalSkyboxData == null || map.AdditionalSkyboxData.Data == null || map.AdditionalSkyboxData.Data.Position.x == 0)
            {             // Convert to v60
                LoadDefaultSkybox();
            }

            map.VersionMinor = 60;
            map.AdditionalSkyboxData.Data.UpdateSize();
        }
        else if (map.VersionMinor >= 60)        // Convert to v56
        {
            LoadDefaultSkybox();
            map.AdditionalSkyboxData.Data.UpdateSize();
            map.VersionMinor = 56;
        }

        //Debug.Log("Set Heightmap to map " + map.Width + ", " + map.Height);

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        //TODO force values if needed
        //map.TerrainShader = Shader;
        map.TerrainShader = MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn ? ("TTerrainXP") : ("TTerrain");

        map.MinimapContourColor   = new Color32(0, 0, 0, 255);
        map.MinimapDeepWaterColor = new Color32(71, 140, 181, 255);
        map.MinimapShoreColor     = new Color32(141, 200, 225, 255);
        map.MinimapLandStartColor = new Color32(119, 101, 108, 255);
        map.MinimapLandEndColor   = new Color32(206, 206, 176, 255);
        //map.MinimapLandEndColor = new Color32 (255, 255, 215, 255);
        map.MinimapContourInterval = 10;

        map.WatermapTex = new Texture2D(map.UncompressedWatermapTex.width, map.UncompressedWatermapTex.height, map.UncompressedWatermapTex.format, false);
        map.WatermapTex.SetPixels(map.UncompressedWatermapTex.GetPixels());
        map.WatermapTex.Apply();
        map.WatermapTex.Compress(true);
        map.WatermapTex.Apply();

        map.NormalmapTex = new Texture2D(map.UncompressedNormalmapTex.width, map.UncompressedNormalmapTex.height, map.UncompressedNormalmapTex.format, false);
        map.NormalmapTex.SetPixels(map.UncompressedNormalmapTex.GetPixels());
        map.NormalmapTex.Apply();
        map.NormalmapTex.Compress(true);
        map.NormalmapTex.Apply();

        map.PreviewTex = PreviewRenderer.RenderPreview(((LowestElevation + HighestElevation) / 2) * 0.1f);


        for (int i = 0; i < map.Layers.Count; i++)
        {
            Textures[i].AlbedoPath = GetGamedataFile.FixMapsPath(Textures[i].AlbedoPath);
            Textures[i].NormalPath = GetGamedataFile.FixMapsPath(Textures[i].NormalPath);

            map.Layers[i].PathTexture   = Textures[i].AlbedoPath;
            map.Layers[i].PathNormalmap = Textures[i].NormalPath;

            map.Layers[i].ScaleTexture   = Textures[i].AlbedoScale;
            map.Layers[i].ScaleNormalmap = Textures[i].NormalScale;
        }



        List <Prop> AllProps = new List <Prop>();

        if (EditMap.PropsInfo.AllPropsTypes != null)
        {
            int Count = EditMap.PropsInfo.AllPropsTypes.Count;
            for (int i = 0; i < EditMap.PropsInfo.AllPropsTypes.Count; i++)
            {
                AllProps.AddRange(EditMap.PropsInfo.AllPropsTypes[i].GenerateSupComProps());
            }
        }
        map.Props = AllProps;


        if (map.VersionMinor < 56)
        {
            map.ConvertToV56();
        }

        map.Save(path, map.VersionMinor);
    }
예제 #4
0
    public IEnumerator LoadScmapFile()
    {
        //UnloadMap();

        map = new Map();

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        //Debug.Log("Load SCMAP file: " + path);


        if (map.Load(path))
        {
            UpdateLighting();
            Skybox.LoadSkybox();
        }
        else
        {
            Debug.LogError("File not found!" + path);
            MapLuaParser.Current.StopCoroutine(MapLuaParser.LoadScmapFile);
        }


        if (map.VersionMinor >= 60)
        {
        }
        else
        {
            LoadDefaultSkybox();
        }


        EnvPaths.CurrentGamedataPath = EnvPaths.GamedataPath;

        //Shader
        MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP";
        ToogleShader();

        // Set Variables
        int   xRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;


        TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex);
        Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        Shader.SetGlobalFloat("_WaterScaleX", xRes);
        Shader.SetGlobalFloat("_WaterScaleZ", xRes);

        //*****************************************
        // ***** Set Terrain proportives
        //*****************************************

        LoadHeights();


        // Load Stratum Textures Paths
        LoadStratumScdTextures();
        MapLuaParser.Current.InfoPopup.Show(true, "Loading map...\n( Assing scmap data )");


        WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes);
        TerrainMaterial.SetFloat("_GridScale", HalfxRes);
        TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        WaterMaterial.SetFloat("_GridScale", HalfxRes);



        /*
         * // Cubemap
         * Texture2D Cubemap = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.TexPathCubemap);
         * Debug.Log(Cubemap.width);
         * Cubemap cb = new Cubemap(Cubemap.width, TextureFormat.RGB24, Cubemap.mipmapCount > 1);
         * cb.SetPixels(Cubemap.GetPixels(), CubemapFace.PositiveX);
         * WaterMaterial.SetTexture("_Reflection", cb);
         */

        for (int i = 0; i < map.EnvCubemapsFile.Length; i++)
        {
            if (map.EnvCubemapsName[i] == "<default>")
            {
                try
                {
                    CurrentEnvironmentCubemap = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.EnvCubemapsFile[i]);
                    Shader.SetGlobalTexture("environmentSampler", CurrentEnvironmentCubemap);
                }
                catch
                {
                    WaterMaterial.SetTexture("environmentSampler", DefaultWaterSky);
                }
            }
        }

        SetWaterTextures();

        SetWater();



        Teren.gameObject.layer = 8;

        SetTextures();

        if (Slope)
        {
            ToogleSlope(Slope);
        }

        yield return(null);
        //Debug.Log("Scmap load complited");

        //GetGamedataFile.UnitObject NewUnit = new GetGamedataFile.UnitObject();
    }