public void Place(Vector3[] Positions, Quaternion[] Rotations, Vector3[] Scales, bool RegisterUndo)
        {
            if (Positions.Length > 0 && RegisterUndo && !IsPasteAction && !UndoRegistered)
            {
                Undo.RegisterUndo(new UndoHistory.HistoryPropsChange());
            }

            for (int i = 0; i < Positions.Length; i++)
            {
                if (!MapLuaParser.IsInArea(Positions[i]))
                {
                    continue;
                }

                Positions[i].y = ScmapEditor.Current.Teren.SampleHeight(Positions[i]);

                Prop NewProp = new Prop();
                NewProp.GroupId = RandomPropGroup;
                NewProp.CreateObject(Positions[i], Rotations[i], Vector3.one);

                AllPropsTypes[RandomPropGroup].PropsInstances.Add(NewProp);

                if (IsPasteAction && i == 0)
                {
                    PastedObjects.Add(NewProp.Obj.gameObject);
                }
            }
        }
    Vector3 GetDiagonal3Symetry()
    {
        Vector3 Origin  = new Vector3(0, 0, -MapLuaParser.GetMapSizeY() / 10f);
        Vector3 Origin2 = new Vector3(MapLuaParser.GetMapSizeY() / 10f, 0, 0);
        Vector3 Point   = new Vector3(BrushPos.x, 0, BrushPos.z);

        Vector3 PointOfMirror = ClosestPointToLine(Origin, Origin2, Point);
        Vector3 FinalDir      = PointOfMirror - Point;

        FinalDir.y = 0;
        FinalDir.Normalize();
        float   FinalDist   = Vector3.Distance(PointOfMirror, Point);
        Vector3 MirroredPos = PointOfMirror + FinalDir * FinalDist;

        MirroredPos.y = BrushPos.y;



        Origin  = new Vector3(0, 0, 0);
        Origin2 = new Vector3(MapLuaParser.GetMapSizeY() / 10f, 0, -MapLuaParser.GetMapSizeY() / 10f);
        Point   = new Vector3(MirroredPos.x, 0, MirroredPos.z);

        PointOfMirror = ClosestPointToLine(Origin, Origin2, Point);
        FinalDir      = PointOfMirror - Point;
        FinalDir.y    = 0;
        FinalDir.Normalize();
        FinalDist     = Vector3.Distance(PointOfMirror, Point);
        MirroredPos   = PointOfMirror + FinalDir * FinalDist;
        MirroredPos.y = BrushPos.y;

        return(MirroredPos);
    }
示例#3
0
    IEnumerator PreloadEditor()
    {
        yield return(null);

        MapLuaParser.LoadStructurePaths();
        yield return(null);

        BrushGenerator.Current.LoadBrushes();
        yield return(null);

        //Preload heavy gamedata files
        GetGamedataFile.GetZipFileInstance(GetGamedataFile.UnitsScd);
        yield return(null);

        yield return(null);

        GetGamedataFile.GetFAFZipFileInstance(GetGamedataFile.UnitsScd);
        yield return(null);

        yield return(null);

        yield return(null);

        SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
    }
示例#4
0
    void Awake()
    {
        Current = this;
        LoadStructurePaths();

        DecalsInfo.Current = DecalsMenu;
        PropsInfo.Current  = PropsMenu;
        UnitsInfo.Current  = UnitsMenu;
    }
示例#5
0
        private static string GetUniqueTempPath()
        {
            string BackupPath = Application.dataPath;

#if UNITY_EDITOR
            BackupPath = BackupPath.Replace("Assets/", "TempMapUpload/");
#endif
            return(BackupPath + "/Structure/MapUpload/Temp/TempFile_" + MapLuaParser.GetUniqueId());
        }
示例#6
0
        bool UpdateBrushPosition(bool Forced = false, bool Size = true, bool Position = true)
        {
            //Debug.Log(Vector3.Distance(MouseBeginClick, Input.mousePosition));
            if (Forced || Vector3.Distance(MouseBeginClick, Input.mousePosition) > 1)
            {
            }
            else
            {
                return(false);
            }

            float SizeXprop      = MapLuaParser.GetMapSizeX() / 512f;
            float SizeZprop      = MapLuaParser.GetMapSizeY() / 512f;
            float BrushSizeValue = BrushSize.value;

            if (BrushSizeValue < 0.2f)
            {
                BrushSizeValue = 0.2f;
            }

            if (Size)
            {
                TerrainMaterial.SetFloat("_BrushSize", BrushSizeValue / ((SizeXprop + SizeZprop) / 2f));
            }


            MouseBeginClick = Input.mousePosition;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Position && Physics.Raycast(ray, out hit, 2000, TerrainMask))
            {
                BrushPos = hit.point;
                if (SnapToGround.isOn && BrushSize.value < 1.5f)
                {
                    //BrushPos = Vector3.Lerp(ScmapEditor.SnapToSmallGridCenter(BrushPos), BrushPos, (BrushSize.value - 0.2f) / 1.5f);
                    BrushPos = ScmapEditor.SnapToSmallGrid(BrushPos + new Vector3(0.025f, 0, -0.025f));
                }

                BrushPos.y = ScmapEditor.Current.Teren.SampleHeight(BrushPos);

                Vector3 tempCoord = ScmapEditor.Current.Teren.gameObject.transform.InverseTransformPoint(BrushPos);
                Vector3 coord     = Vector3.zero;
                float   SizeX     = (int)((BrushSizeValue / SizeXprop) * 100) * 0.01f;
                float   SizeZ     = (int)((BrushSizeValue / SizeZprop) * 100) * 0.01f;
                coord.x = (tempCoord.x - SizeX * MapLuaParser.GetMapSizeX() * 0.0001f) / ScmapEditor.Current.Teren.terrainData.size.x;
                coord.z = (tempCoord.z - SizeZ * MapLuaParser.GetMapSizeY() * 0.0001f) / ScmapEditor.Current.Teren.terrainData.size.z;

                TerrainMaterial.SetFloat("_BrushUvX", coord.x);
                TerrainMaterial.SetFloat("_BrushUvY", coord.z);

                return(true);
            }
            return(false);
        }
示例#7
0
    void Awake()
    {
        Current = this;
        LoadStructurePaths();

        DecalsInfo.Current = DecalsMenu;
        PropsInfo.Current = PropsMenu;
        UnitsInfo.Current = UnitsMenu;

        GetGamedataFile.LoadGamedata();
    }
示例#8
0
    public void UpdateArmys()
    {
        Clean();


        if (MapLuaParser.Current.ScenarioLuaFile.Data.Configurations.Length == 0 || MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams.Length == 0)
        {
            return;
        }

        var AllArmies = MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams[0].Armys;

        for (int a = 0; a < AllArmies.Count; a++)
        {
            MapLua.SaveLua.Marker ArmyMarker = MapLua.SaveLua.GetMarker(AllArmies[a].Name);

            if (ArmyMarker != null && ArmyMarker.MarkerObj != null && ArmyMarker.MarkerType == MapLua.SaveLua.Marker.MarkerTypes.BlankMarker)
            {
                GameObject NewBut = Instantiate(ArmyButtonPrefab) as GameObject;
                NewBut.transform.SetParent(Pivot);
                ArmyButtons.Add(NewBut.GetComponent <ArmyMinimapButton>());
                ArmyButtons[a].Controler  = this;
                ArmyButtons[a].InstanceId = a;
                ArmyButtons[a].ArmyId     = a;
                ArmyButtons[a].ArmyTeam   = 0;
                //ArmyInfo.GetArmyId(MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].Name, out ArmyButtons[i].ArmyId, out ArmyButtons[i].ArmyTeam);

                //ArmyButtons[i].Name.text = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].Name.ToString();
                ArmyButtons[a].Name.text = (a + 1).ToString();

                Vector3 IconPos = ArmyMarker.MarkerObj.transform.localPosition;
                IconPos.y = IconPos.z;
                IconPos.z = 0;

                IconPos.x /= MapLuaParser.GetMapSizeX() / 10f;
                IconPos.y /= MapLuaParser.GetMapSizeY() / 10f;

                IconPos.x *= ImageSize;
                IconPos.y *= ImageSize;

                NewBut.GetComponent <RectTransform>().localPosition = IconPos;
            }
        }


        UpdateAutoteam();
    }
示例#9
0
        void Paint(Vector3 AtPosition, Quaternion Rotation)
        {
            if (!MapLuaParser.IsInArea(AtPosition))
            {
                return;
            }

            RegisterUndo();

            AtPosition.y = ScmapEditor.Current.Teren.SampleHeight(AtPosition);

            Prop NewProp = new Prop();

            NewProp.GroupId = RandomPropGroup;
            NewProp.CreateObject(AtPosition, Rotation, Vector3.one);

            AllPropsTypes[RandomPropGroup].PropsInstances.Add(NewProp);

            TotalMassCount   += AllPropsTypes[RandomPropGroup].PropObject.BP.ReclaimMassMax;
            TotalEnergyCount += AllPropsTypes[RandomPropGroup].PropObject.BP.ReclaimEnergyMax;
            TotalReclaimTime += AllPropsTypes[RandomPropGroup].PropObject.BP.ReclaimTime;
        }
示例#10
0
        public void LoadBrushes()
        {
            Clean();

            StructurePath = MapLuaParser.GetDataPath() + "/Structure/";;

            StructurePath += "brush";

            if (!Directory.Exists(StructurePath))
            {
                Debug.LogError("Cant find brush folder");
                return;
            }

            BrushToggles = new List <Toggle>();

            for (int i = 0; i < BrushGenerator.Current.Brushes.Count; i++)
            {
                GameObject NewBrush = Instantiate(BrushListObject) as GameObject;
                NewBrush.transform.SetParent(BrushListPivot, false);
                NewBrush.transform.localScale = Vector3.one;
                string ThisName = BrushGenerator.Current.BrushesNames[i];
                BrushToggles.Add(NewBrush.GetComponent <BrushListId>().SetBrushList(ThisName, BrushGenerator.Current.Brushes[i], i));
                NewBrush.GetComponent <BrushListId>().Controler = this;
            }

            foreach (Toggle tog in BrushToggles)
            {
                tog.isOn = false;
                //tog.group = ToogleGroup;
            }
            BrushToggles[0].isOn = true;
            SelectedFalloff      = 0;

            BrusheshLoaded = true;
        }
    void Awake()
    {
        ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = 0;


        EnvPaths.GenerateDefaultPaths();

        if (string.IsNullOrEmpty(EnvPaths.GetInstalationPath()))
        {
            EnvPaths.GenerateGamedataPath();
            EnvPaths.SetInstalationPath(EnvPaths.DefaultGamedataPath);
        }

        Current       = this;
        StructurePath = Application.dataPath + "/Structure/";;
#if UNITY_EDITOR
        StructurePath = StructurePath.Replace("Assets", "");
#endif


        DecalsInfo.Current = DecalsMenu;
        PropsInfo.Current  = PropsMenu;
        UnitsInfo.Current  = UnitsMenu;
    }
示例#12
0
	public static void ReadSpawnWithArmy(out MapLuaParser.armys ArmyValue, LHTable ReadTable){
		string SpawnName = ReadTable.GetStringValue ("SpawnWithArmy");

		if (SpawnName.Contains ("ARMY") && !SpawnName.Contains ("ARMY_")) {
			SpawnName = SpawnName.Replace ("ARMY", "ARMY_");
		}
			
		switch(SpawnName){
		case "ARMY_1":
			ArmyValue = MapLuaParser.armys.ARMY1;
			break;
		case "ARMY_2":
			ArmyValue = MapLuaParser.armys.ARMY2;
			break;
		case "ARMY_3":
			ArmyValue = MapLuaParser.armys.ARMY3;
			break;
		case "ARMY_4":
			ArmyValue = MapLuaParser.armys.ARMY4;
			break;
		case "ARMY_5":
			ArmyValue = MapLuaParser.armys.ARMY5;
			break;
		case "ARMY_6":
			ArmyValue = MapLuaParser.armys.ARMY6;
			break;
		case "ARMY_7":
			ArmyValue = MapLuaParser.armys.ARMY7;
			break;
		case "ARMY_8":
			ArmyValue = MapLuaParser.armys.ARMY8;
			break;
		case "ARMY_9":
			ArmyValue = MapLuaParser.armys.ARMY9;
			break;
		case "ARMY_10":
			ArmyValue = MapLuaParser.armys.ARMY10;
			break;
		case "ARMY_11":
			ArmyValue = MapLuaParser.armys.ARMY11;
			break;
		case "ARMY_12":
			ArmyValue = MapLuaParser.armys.ARMY12;
			break;
		case "ARMY_13":
			ArmyValue = MapLuaParser.armys.ARMY13;
			break;
		case "ARMY_14":
			ArmyValue = MapLuaParser.armys.ARMY14;
			break;
		case "ARMY_15":
			ArmyValue = MapLuaParser.armys.ARMY15;
			break;
		case "ARMY_16":
			ArmyValue = MapLuaParser.armys.ARMY16;
			break;
		default:
			ArmyValue = MapLuaParser.armys.none;
			break;
		}
	}
示例#13
0
	void Awake(){
		ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = 0;

		#if UNITY_EDITOR
		//PlayerPrefs.DeleteAll();
		#endif

		EnvPaths.GenerateDefaultPaths ();

		Current = this;
		StructurePath = Application.dataPath + "/Structure/";;
		#if UNITY_EDITOR
		StructurePath = StructurePath.Replace("Assets", "");
		#endif

		ParsingStructureData.LoadData ();
	}
示例#14
0
        void LoadWavePatterns()
        {
            Lua LuaFile;

            System.Text.Encoding encodeType = System.Text.Encoding.ASCII;

            string path = MapLuaParser.GetDataPath() + "/Structure/Waves/wavepatterns.lua";

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Debug.LogError("Cant find Waves folder");
                return;
            }
            if (!File.Exists(path))
            {
                Debug.LogError("Cant find Waves file");
                return;
            }

            string loadedFile = File.ReadAllText(path, encodeType);

            LuaFile = new Lua();
            LuaFile.LoadCLRPackage();
            try
            {
                LuaFile.DoString(MapLuaParser.Current.SaveLuaHeader.text + loadedFile);
            }
            catch (NLua.Exceptions.LuaException e)
            {
                Debug.LogError(LuaParser.Read.FormatException(e), MapLuaParser.Current.gameObject);
                return;
            }

            var patternTable = LuaFile.GetTable(KEY_patterns);

            LuaTable[] wvTabs = LuaParser.Read.GetTableTables(patternTable);

            WavePatterns = new WavePattern[wvTabs.Length];

            for (int i = 0; i < WavePatterns.Length; i++)
            {
                WavePattern pattern = new WavePattern();

                pattern.name    = LuaParser.Read.StringFromTable(wvTabs[i], "name", "pattern" + i);
                pattern.preview = LuaParser.Read.StringFromTable(wvTabs[i], "preview", "/editor/tools/water/nopreview.bmp");

                LuaTable parametersTable = (LuaTable)wvTabs[i].RawGet("parameters");

                LuaTable[] parameters = LuaParser.Read.GetTableTables(parametersTable);
                pattern.parameters = new WavePattern.Parameters[parameters.Length];
                for (int p = 0; p < parameters.Length; p++)
                {
                    pattern.parameters[p]                   = new WavePattern.Parameters();
                    pattern.parameters[p].texture           = LuaParser.Read.StringFromTable(parameters[p], "texture", "/env/common/decals/shoreline/wavetest.dds");
                    pattern.parameters[p].ramp              = LuaParser.Read.StringFromTable(parameters[p], "ramp", "/env/common/decals/shoreline/waveramptest.dds");
                    pattern.parameters[p].position          = LuaParser.Read.Vector3FromTable(parameters[p], "position");
                    pattern.parameters[p].period            = LuaParser.Read.FloatFromTable(parameters[p], "period");
                    pattern.parameters[p].periodVariance    = LuaParser.Read.FloatFromTable(parameters[p], "periodVariance");
                    pattern.parameters[p].speed             = LuaParser.Read.FloatFromTable(parameters[p], "speed");
                    pattern.parameters[p].speedVariance     = LuaParser.Read.FloatFromTable(parameters[p], "speedVariance");
                    pattern.parameters[p].lifetime          = LuaParser.Read.FloatFromTable(parameters[p], "lifetime");
                    pattern.parameters[p].lifetimeVariance  = LuaParser.Read.FloatFromTable(parameters[p], "lifetimeVariance");
                    pattern.parameters[p].scale             = LuaParser.Read.Vector2FromTable(parameters[p], "scale");
                    pattern.parameters[p].scaleVariance     = LuaParser.Read.FloatFromTable(parameters[p], "scaleVariance");
                    pattern.parameters[p].velocityDelta     = LuaParser.Read.Vector3FromTable(parameters[p], "velocityDelta");
                    pattern.parameters[p].frameCount        = LuaParser.Read.IntFromTable(parameters[p], "frameCount");
                    pattern.parameters[p].frameRate         = LuaParser.Read.FloatFromTable(parameters[p], "frameRate");
                    pattern.parameters[p].frameRateVariance = LuaParser.Read.FloatFromTable(parameters[p], "frameRateVariance");
                    pattern.parameters[p].stripCount        = LuaParser.Read.IntFromTable(parameters[p], "stripCount");
                }

                WavePatterns[i] = pattern;
            }
        }
示例#15
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);
        }
    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);
    }
    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);
    }
示例#18
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();
    }