private void LoadSaveLua(){ System.Text.Encoding encodeType = System.Text.Encoding.ASCII; string loadedFileSave = ""; string MapPath = EnvPaths.GetMapsPath(); loadedFileSave = System.IO.File.ReadAllText(ScenarioData.SaveLua.Replace("/maps/", MapPath), encodeType); string loadedFileFunctions = LuaHelper.GetStructureText ("lua_variable_functions.lua"); //loadedFileFunctions = System.IO.File.ReadAllText(StructurePath + "lua_variable_functions.lua", encodeType); string loadedFileEndFunctions = LuaHelper.GetStructureText ("lua_variable_end_functions.lua"); //loadedFileEndFunctions = System.IO.File.ReadAllText(StructurePath + "lua_variable_end_functions.lua", encodeType); loadedFileSave = loadedFileFunctions + loadedFileSave + loadedFileEndFunctions; save = new Lua(); save.LoadCLRPackage(); try { save.DoString(loadedFileSave); } catch(NLua.Exceptions.LuaException e) { Debug.LogError(ParsingStructureData.FormatException(e), gameObject); HelperGui.MapLoaded = false; return; } // LoadArea ScenarioData.Area = new Rect(); if(save.GetTable("Scenario.Areas.AREA_1") != null && save.GetTable("Scenario.Areas.AREA_1").ToString() != "null"){ ScenarioData.DefaultArea = true; ScenarioData.Area.x = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[1].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ScenarioData.Area.y = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[2].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ScenarioData.Area.width = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[3].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ScenarioData.Area.height = float.Parse(save.GetTable("Scenario.Areas.AREA_1.rectangle")[4].ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); UpdateArea(); } else{ ScenarioData.DefaultArea = false; HeightmapControler.TerrainMaterial.SetInt("_Area", ScenarioData.DefaultArea?1:0); MapElements.SetActive(false); HeightmapControler.TerrainMaterial.SetFloat("_AreaX", 0); HeightmapControler.TerrainMaterial.SetFloat("_AreaY", 0); HeightmapControler.TerrainMaterial.SetFloat("_AreaWidht", ScenarioData.Size.x / 10f); HeightmapControler.TerrainMaterial.SetFloat("_AreaHeight", ScenarioData.Size.y / 10f); } MapCenterPoint = Vector3.zero; MapCenterPoint.x = (ScenarioData.Size.x / 20); MapCenterPoint.z = -1 * (ScenarioData.Size.y / 20); // LoadMarkers #region Load Markers //int MarkersCount = save.GetTable("Scenario.MasterChain._MASTERCHAIN_.Markers").Values.Count; Mexes = new List<Mex>(); Hydros = new List<Hydro>(); ARMY_ = new List<Army>(); SiMarkers = new List<Marker>(); //LuaTable MasterChain = save.GetTable("Scenario.MasterChain._MASTERCHAIN_.Markers") as LuaTable; //string[] KeysArray = new string[MarkersCount]; //MasterChain.Keys.CopyTo(KeysArray, 0); LuaHelper.LHTable MarkersTable = new LuaHelper.LHTable(save.GetTable("Scenario.MasterChain._MASTERCHAIN_.Markers")); for(int m = 0; m < MarkersTable.Count; m++){ //LuaTable MarkerTab = MasterChain[KeysArray[m]] as LuaTable; LuaHelper.LHTable MarkerTable = new LuaHelper.LHTable(MarkersTable, MarkersTable.Keys[m]); Vector3 MarkerPosParsed = Vector3.zero; MarkerTable.GetVector3Value("position", out MarkerPosParsed); Vector3 MarkerRotParsed = Vector3.zero; MarkerTable.GetVector3Value("orientation", out MarkerRotParsed); string TypeOfMarker = MarkerTable.GetStringValue("type"); if(TypeOfMarker == "Mass"){ Mex newMex = new Mex(); newMex.name = MarkersTable.Keys[m]; newMex.position = HeightmapControler.MapPosInWorld(MarkerPosParsed); newMex.orientation = MarkerRotParsed; LuaHelper.ReadSpawnWithArmy(out newMex.SpawnWithArmy, MarkerTable); Mexes.Add(newMex); } else if(TypeOfMarker == "Hydrocarbon"){ Hydro NewHydro = new Hydro(); NewHydro.name = MarkersTable.Keys[m]; NewHydro.size = MarkerTable.GetFloatValue("size"); NewHydro.amount = MarkerTable.GetFloatValue("amount"); NewHydro.resource = MarkerTable.GetBoolValue("resource"); NewHydro.prop = MarkerTable.GetStringValue("prop"); NewHydro.color = MarkerTable.GetColorValue("color"); NewHydro.position = HeightmapControler.MapPosInWorld(MarkerPosParsed); NewHydro.orientation = MarkerRotParsed; LuaHelper.ReadSpawnWithArmy(out NewHydro.SpawnWithArmy, MarkerTable); Hydros.Add(NewHydro); } else if(MarkersTable.Keys[m].Contains("ARMY_")){ Army NewArmy = new Army(); NewArmy.name = MarkersTable.Keys[m]; NewArmy.Id = int.Parse(MarkersTable.Keys[m].Replace("ARMY_", "")); NewArmy.position = HeightmapControler.MapPosInWorld(MarkerPosParsed); NewArmy.orientation = MarkerRotParsed; ARMY_.Add(NewArmy); } else{ Marker NewMarker = new Marker(); NewMarker.name = MarkersTable.Keys[m]; NewMarker.position = HeightmapControler.MapPosInWorld(MarkerPosParsed); NewMarker.orientation = MarkerRotParsed; NewMarker.type = TypeOfMarker; NewMarker.prop = MarkerTable.GetStringValue("prop"); // HINT NewMarker.hintValue = MarkerTable.GetStringValue("hint"); NewMarker.hint = MarkerTable.GetBoolValue("hint"); // GRAPH NewMarker.graph = MarkerTable.GetStringValue("graph"); // adjacentTo NewMarker.adjacentTo = MarkerTable.GetStringValue("adjacentTo"); // Color if (!string.IsNullOrEmpty(MarkerTable.GetStringValue("color"))) { //Color MyColor = Color.white; //ColorUtility.TryParseHtmlString (MarkerTable.GetStringValue("color"), out MyColor); NewMarker.Kolor = MarkerTable.GetColorValue("color"); } else NewMarker.Kolor = Color.white; LuaHelper.ReadSpawnWithArmy(out NewMarker.SpawnWithArmy, MarkerTable); SiMarkers.Add(NewMarker); } } SortArmys(); MexTotalCount = Mexes.Count; HydrosTotalCount = Hydros.Count; SiTotalCount = SiMarkers.Count; #endregion #region Load Army Save SaveArmys = new List<SaveArmy> (); LuaHelper.LHTable ArmiesTable = new LuaHelper.LHTable(save.GetTable("Scenario.Armies")); for(int m = 0; m < ArmiesTable.Count; m++){ LuaHelper.LHTable ArmyTable = new LuaHelper.LHTable(ArmiesTable, ArmiesTable.Keys[m]); SaveArmy NewArmy = new SaveArmy(); NewArmy.Name = ArmiesTable.Keys[m]; AddSaveArmyMarker(NewArmy.Name); NewArmy.personality = ArmyTable.GetStringValue("personality"); NewArmy.plans = ArmyTable.GetStringValue("plans"); NewArmy.color = ArmyTable.GetIntValue("color"); NewArmy.faction = ArmyTable.GetIntValue("faction"); LuaHelper.LHTable EconomyTable = new LuaHelper.LHTable(ArmyTable, "Economy"); NewArmy.EconomyMass = EconomyTable.GetIntValue("mass"); NewArmy.EconomyEnergy = EconomyTable.GetIntValue("energy"); NewArmy.Alliances = ArmyTable.GetStringArrayValue("Alliances"); // Get units NewArmy.UnitsOrders = ""; NewArmy.UnitsPlatoon = ""; NewArmy.Units = new List<UnitGroup>(); LuaHelper.LHTable ArmyUnitsTable; ArmyTable.GetLuaArmyGroup("Units", out NewArmy.UnitsOrders, out NewArmy.UnitsPlatoon, out ArmyUnitsTable); for(int i = 0; i < ArmyUnitsTable.Count; i++){ UnitGroup NewUnitGroup = new UnitGroup(); NewUnitGroup.Name = ArmyUnitsTable.Keys[i]; LuaHelper.LHTable UnitsGroupTable; ArmyUnitsTable.GetLuaArmyGroup(ArmyUnitsTable.Keys[i], out NewUnitGroup.orders, out NewUnitGroup.platoon, out UnitsGroupTable); for(int u = 0; u < UnitsGroupTable.Count; u++){ Unit NewUnit = new Unit(); LuaHelper.LHTable UnitTable = new LuaHelper.LHTable(UnitsGroupTable, UnitsGroupTable.Keys[u]); NewUnit.Name = UnitsGroupTable.Keys[u]; NewUnit.type = UnitTable.GetStringValue("type"); NewUnit.orders = UnitTable.GetStringValue("orders"); NewUnit.platoon = UnitTable.GetStringValue("platoon"); UnitTable.GetVector3Value("Position", out NewUnit.Position); UnitTable.GetVector3Value("Orientation", out NewUnit.Orientation); NewUnitGroup.Units.Add(NewUnit); } NewArmy.Units.Add(NewUnitGroup); } SaveArmys.Add(NewArmy); } #endregion }
private void LoadScenarioLua(){ System.Text.Encoding encodeType = System.Text.Encoding.ASCII; string MapPath = EnvPaths.GetMapsPath(); string loadedFile = ""; Debug.Log("Load file:" + MapPath + FolderName + "/" + ScenarioFileName + ".lua"); string loc = MapPath + FolderName + "/" + ScenarioFileName + ".lua"; loadedFile = System.IO.File.ReadAllText(loc, encodeType); string loadedFileFunctions = ""; loadedFileFunctions = System.IO.File.ReadAllText(StructurePath + "lua_variable_functions.lua", encodeType); env = new Lua(); env.LoadCLRPackage(); try { env.DoString(loadedFileFunctions + loadedFile); } catch(NLua.Exceptions.LuaException e) { Debug.LogError(ParsingStructureData.FormatException(e), gameObject); HelperGui.MapLoaded = false; return; } // Load Map Prop ScenarioData.MapName = env.GetTable("ScenarioInfo").RawGet("name").ToString(); ScenarioData.MapDesc = env.GetTable("ScenarioInfo").RawGet("description").ToString(); ScenarioData.Type = env.GetTable("ScenarioInfo").RawGet("type").ToString(); if(env.GetTable("ScenarioInfo").RawGet("map_version") != null && env.GetTable("ScenarioInfo").RawGet("map_version").ToString() != "null"){ ScenarioData.Version = float.Parse(env.GetTable("ScenarioInfo").RawGet("map_version").ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); } else{ ScenarioData.Version = 1; } if(env.GetTable("ScenarioInfo").RawGet("AdaptiveMap") != null && env.GetTable("ScenarioInfo").RawGet("AdaptiveMap").ToString() != "null"){ ScenarioData.AdaptiveMap = env.GetTable("ScenarioInfo").RawGet("AdaptiveMap").ToString() == "true"; } else{ ScenarioData.AdaptiveMap = false; } if(env.GetTable("ScenarioInfo").RawGet("preview") != null && env.GetTable("ScenarioInfo").RawGet("preview").ToString() != "null"){ ScenarioData.Preview = env.GetTable("ScenarioInfo").RawGet("preview").ToString(); } else{ ScenarioData.Preview = ""; } ScenarioData.SaveLua = env.GetTable("ScenarioInfo").RawGet("save").ToString(); ScenarioData.Scmap = env.GetTable("ScenarioInfo").RawGet("map").ToString(); ScenarioData.ScriptLua = env.GetTable("ScenarioInfo").RawGet("script").ToString(); // Load Map Size var width = env.GetTable("ScenarioInfo.size")[1].ToString(); var height = env.GetTable("ScenarioInfo.size")[2].ToString(); ScenarioData.Size.x = float.Parse(width.ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ScenarioData.Size.y = float.Parse(height.ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ScenarioData.MaxHeight = 128; CamControll.MapSize = Mathf.Max(ScenarioData.Size.x, ScenarioData.Size.y); CamControll.RestartCam(); // Load Players LuaTable TeamsTab = env.GetTable("ScenarioInfo.Configurations.standard.teams")[1] as LuaTable; LuaTable ArmyTab = TeamsTab.RawGet("armies") as LuaTable; ScenarioData.Players = ArmyTab.Values.Count; ScenarioData.NoRushRadius = float.Parse(env.GetTable("ScenarioInfo").RawGet("norushradius").ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); ScenarioData.NoRushARMY = new Vector2[ScenarioData.Players]; for(int id = 0; id < ScenarioData.Players; id++) { ScenarioData.NoRushARMY[id] = Vector2.zero; if(env.GetTable("ScenarioInfo").RawGet("norushoffsetX_ARMY_" + (id + 1)) != null) ScenarioData.NoRushARMY[id].x = float.Parse(env.GetTable("ScenarioInfo").RawGet("norushoffsetX_ARMY_" + (id + 1)).ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); if(env.GetTable("ScenarioInfo").RawGet("norushoffsetY_ARMY_" + (id + 1)) != null) ScenarioData.NoRushARMY[id].y = float.Parse(env.GetTable("ScenarioInfo").RawGet("norushoffsetY_ARMY_" + (id + 1)).ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); } ScenarioData.CustomProps = new List<customprop> (); LuaHelper.LHTable CustomPropsTable = new LuaHelper.LHTable(env.GetTable("ScenarioInfo.Configurations.standard.customprops")); for (int i = 0; i < CustomPropsTable.Count; i++) { customprop NewProp = new customprop (); NewProp.key = CustomPropsTable.Keys [i]; NewProp.value = CustomPropsTable.GetStringValue (CustomPropsTable.Keys [i]); ScenarioData.CustomProps.Add (NewProp); } }