コード例 #1
0
        public static void Generate()
        {
            Mod.Log("--- Generating ---");

            SRand.SetSeed(World.inst.seed);

            generatorSeededState = SRand.value;
            try
            {
                GenerateBase();
                if (doSmoothing)
                {
                    ApplySmoothing();
                }
                Apply();

                ElevationManager.RefreshTerrain();

                BlockedTilePruner.DoRegionSearch(ElevationManager.GetAll());
            }
            catch (Exception ex)
            {
                DebugExt.HandleException(ex);
            }

            Mod.Log("--- Generation Complete ---");
        }
コード例 #2
0
ファイル: Mod.cs プロジェクト: DaDevFox/KCMods
 public void SceneLoaded()
 {
     try
     {
         Settings.Setup();
     }
     catch (Exception ex)
     {
         DebugExt.HandleException(ex);
     }
 }
コード例 #3
0
 static void Postfix()
 {
     try
     {
         MapGenerator.Generate();
     }
     catch (Exception ex)
     {
         DebugExt.HandleException(ex);
     }
 }
コード例 #4
0
 public static void Setup()
 {
     try
     {
         tierColoring = Settings.elevationColorPresets["Default"];
         BakeElevationMap();
         SetTerrainMat();
     }
     catch (Exception ex)
     {
         DebugExt.HandleException(ex);
     }
 }
コード例 #5
0
ファイル: Mod.cs プロジェクト: DaDevFox/KCMods
 static void Postfix()
 {
     try
     {
         Mod.Log("--- Preperation ---");
         ColorManager.Setup();
         ElevationManager.SetupCellMarks();
         Mod.Log("--- Preperation Complete ---");
     }
     catch (Exception ex)
     {
         DebugExt.HandleException(ex);
     }
 }
コード例 #6
0
ファイル: Mod.cs プロジェクト: DaDevFox/KCMods
        public void Preload(KCModHelper helper)
        {
            Mod.helper = helper;

            try
            {
                var harmony = HarmonyInstance.Create("harmony");
                harmony.PatchAll(Assembly.GetExecutingAssembly());
                //Mod.Log("test");
            }
            catch (Exception ex)
            {
                DebugExt.HandleException(ex);
            }
        }
コード例 #7
0
        public static void RefreshTerrain()
        {
            try
            {
                foreach (CellMark mark in cellMarkLookup.Values)
                {
                    Terraformer.SetCellHeight(mark.cell, mark.Elevation);
                }

                UpdateMarks();
                UpdatePatches();

                TerrainGen.inst.FinalizeChanges();
            }
            catch (Exception ex)
            {
                DebugExt.HandleException(ex);
            }

            DebugExt.dLog("terrain refreshed");
        }
コード例 #8
0
        public static void GenerateBase()
        {
            Reset();
            for (int landmass = 0; landmass < World.inst.NumLandMasses; landmass++)
            {
                foreach (Cell cell in World.inst.cellsToLandmass[landmass].data)
                {
                    CellData data = new CellData
                    {
                        valid = false
                    };
                    if (cell != null && ElevationManager.ValidTileForElevation(cell))
                    {
                        try
                        {
                            data.valid = true;
                            data.cell  = cell;
                            float yValue     = 0f;
                            float noiseValue = Mathf.PerlinNoise(cell.x / scale + generatorSeededState, cell.z / scale + generatorSeededState) * amplitude;

                            float weightage = GetFertilityDistanceWeightage(cell);
                            yValue = noiseValue * weightage * (ElevationManager.maxElevation - ElevationManager.minElevation) + ElevationManager.minElevation;

                            data.yValue = yValue;

                            int y = Clamp(yValue);

                            ElevationManager.TrySetElevation(cell, y);

                            cellsData.Add(cell, data);
                        }
                        catch (Exception ex)
                        {
                            DebugExt.HandleException(ex);
                        }
                    }
                }
            }
            Mod.helper.Log("Base Noise Generated");
        }
コード例 #9
0
            static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
            {
                var codes = new List <CodeInstruction>(instructions);

                try
                {
                    // Fertility value 1

                    //Push desired destination var's memory address onto stack
                    FieldInfo f1 = typeof(MapGenerator).
                                   GetField("fertility_value1", BindingFlags.Static | BindingFlags.Public);
                    codes.Add(new CodeInstruction(OpCodes.Ldflda, f1));

                    //Push the value of value1 local onto stack
                    codes.Add(new CodeInstruction(OpCodes.Ldloc_0));

                    //Store value into fertility_value1
                    codes.Add(new CodeInstruction(OpCodes.Stind_R4));


                    // Fertility value 2

                    //Push desired destination var's memory address onto stack
                    FieldInfo f2 = typeof(MapGenerator).
                                   GetField("fertility_value2", BindingFlags.Static | BindingFlags.Public);
                    codes.Add(new CodeInstruction(OpCodes.Ldflda, f2));

                    //Push the value of value2 local onto stack
                    codes.Add(new CodeInstruction(OpCodes.Ldloc_1));

                    //Store value into fertility_value2
                    codes.Add(new CodeInstruction(OpCodes.Stind_R4));
                }
                catch (Exception ex)
                {
                    DebugExt.HandleException(ex);
                }

                return(codes.AsEnumerable());
            }
コード例 #10
0
ファイル: InputManager.cs プロジェクト: DaDevFox/KCMods
        public static void Update()
        {
            Cell selected = GameUI.inst.GetCellSelected();

            if (Settings.debug)
            {
                if (Input.GetKeyDown(Settings.keycode_raise))
                {
                    try
                    {
                        if (ElevationManager.TryProcessElevationChange(selected, 1))
                        {
                            DebugExt.dLog("Elevation raise succesful");
                        }
                    }
                    catch (Exception ex)
                    {
                        DebugExt.HandleException(ex);
                    }
                }
                else if (Input.GetKeyDown(Settings.keycode_lower))
                {
                    try
                    {
                        if (ElevationManager.TryProcessElevationChange(selected, -1))
                        {
                            DebugExt.dLog("Elevation lower succesful");
                        }
                    }
                    catch (Exception ex)
                    {
                        DebugExt.HandleException(ex);
                    }
                }



                if (Input.GetKeyDown(Settings.keycode_sampleCell))
                {
                    string text = "";

                    text += "Cell at " + selected.Center.ToString() + ": ";
                    text += Environment.NewLine;
                    text += "has mark: " + (ElevationManager.GetCellMark(selected) != null).ToString();
                    text += Environment.NewLine;
                    text += (ElevationManager.GetCellMark(selected) != null) ? ("Blockers: " + ElevationManager.GetCellMark(selected).blockers.Count.ToString()) +
                            Environment.NewLine : "";
                    text += BlockedTilePruner.GetTileRegion(selected) != -1 ? BlockedTilePruner.GetTileRegion(selected).ToString() +
                            Environment.NewLine : "";
                    text += BlockedTilePruner.Unreachable.Contains(selected) ? "<color=red> Pruned from pathfinding; unreachable </color>" : "";

                    DebugExt.dLog(text);
                }
                if (Input.GetKeyDown(KeyCode.H))
                {
                    BlockedTilePruner.DoRegionSearch(ElevationManager.GetAll());
                }
            }
            if (Input.GetKeyDown(Settings.keycode_topDownView))
            {
                TopDownModeCamera.ToggleTopDownView();
            }
        }
コード例 #11
0
 private static void OnUnsuccesfulSettingUpdate(Exception ex)
 {
     Mod.Log("Setting Update Unsuccsesful");
     DebugExt.HandleException(ex);
 }
コード例 #12
0
 private static void OnModRegistrationFailed(Exception ex)
 {
     Mod.helper.Log("Mod registration to ModMenu failed");
     DebugExt.HandleException(ex);
 }