Exemplo n.º 1
0
 public static void RegenerateZone(BetterTerrain.ZoneInfo zone)
 {
     if (zone == null)
     {
         return;
     }
     CalcTMods(ZoneSystem.instance.GetZone(zone.hmap.transform.position));
     if (zone.saved)
     {
         for (int j = 0; j < zone.hmap.m_heights.Count; j++)
         {
             zone.hmap.m_heights[j] = zone.heights[j];
         }
         zone.hmap.m_clearedMask.SetPixels(zone.colors);
         zone.hmap.m_clearedMask.Apply();
     }
     zone.hmap.ApplyModifiers();
     if (can_save && (zone.tmods.Count > 0 || zone.has_location))
     {
         if (zone.heights.Count != zone.hmap.m_heights.Count)
         {
             zone.heights = new List <float>(new float[zone.hmap.m_heights.Count]);
         }
         for (int i = 0; i < zone.hmap.m_heights.Count; i++)
         {
             zone.heights[i] = zone.hmap.m_heights[i];
         }
         zone.colors = (Color[])zone.hmap.m_clearedMask.GetPixels().Clone();
         zone.saved  = true;
     }
 }
Exemplo n.º 2
0
 public static void CalcTMods(BetterTerrain.ZoneInfo zone)
 {
     foreach (TerrainModifier tmod in TerrainModifier.m_instances)
     {
         if (zone.hmap.TerrainVSModifier(tmod))
         {
             zone.tmods.Add(tmod);
         }
     }
 }
Exemplo n.º 3
0
 public static void SetHeightmap(Vector2i id, Heightmap heightmap)
 {
     if (!(heightmap == null))
     {
         if (!IsZoneKnown(id))
         {
             zone_info[id] = new BetterTerrain.ZoneInfo();
         }
         zone_info[id].hmap = heightmap;
     }
 }
Exemplo n.º 4
0
 public static void SetGameObject(Vector2i id, GameObject gameObject)
 {
     if (!(gameObject == null))
     {
         if (!IsZoneKnown(id))
         {
             zone_info[id] = new BetterTerrain.ZoneInfo();
         }
         zone_info[id].game_object = gameObject;
     }
 }
Exemplo n.º 5
0
        private static void LocationAwake_Postfix(ZoneSystem __instance, GameObject __result, Vector3 pos)
        {
            Vector2i zone2 = ZoneSystem.instance.GetZone(pos);

            BetterTerrain.ZoneInfo zone = HMAPManager.GetZoneInfo(zone2);
            if (HMAPManager.IsZoneKnown(zone2))
            {
                if (zone.has_location)
                {
                    zone.hmap.Regenerate();
                }
                zone.has_location = true;
            }
        }
Exemplo n.º 6
0
        private static bool Generate_Prefix(Heightmap __instance, int ___m_width, ref List <float> ___m_heights, ref Texture2D ___m_clearedMask, HeightmapBuilder.HMBuildData ___m_buildData)
        {
            if (ZoneSystem.instance == null)
            {
                return(true);
            }
            Vector3 position = __instance.transform.position;

            __instance.Initialize();
            int num3 = __instance.m_width + 1;
            int num2 = num3 * num3;

            BetterTerrain.ZoneInfo zone = HMAPManager.GetZoneInfo(__instance.transform.position);
            if (zone == null || zone.game_object != __instance.gameObject)
            {
                return(true);
            }
            if (!zone.generated)
            {
                if (__instance.m_buildData == null || __instance.m_buildData.m_baseHeights.Count != num2 || __instance.m_buildData.m_center != position || __instance.m_buildData.m_scale != __instance.m_scale || __instance.m_buildData.m_worldGen != WorldGenerator.instance)
                {
                    __instance.m_buildData    = HeightmapBuilder.instance.RequestTerrainSync(position, __instance.m_width, __instance.m_scale, __instance.m_isDistantLod, WorldGenerator.instance);
                    __instance.m_cornerBiomes = __instance.m_buildData.m_cornerBiomes;
                }
                for (int i = 0; i < num2; i++)
                {
                    __instance.m_heights[i] = __instance.m_buildData.m_baseHeights[i];
                }
                Color[] pixels = new Color[__instance.m_clearedMask.width * __instance.m_clearedMask.height];
                __instance.m_clearedMask.SetPixels(pixels);
                zone.generated = true;
                zone.hmap      = __instance;
            }
            HMAPManager.RegenerateZone(zone);
            return(false);
        }
Exemplo n.º 7
0
        private static bool ApplyModifier_Prefix(TerrainModifier modifier, Heightmap __instance, int ___m_width, ref List <float> ___m_heights, ref Texture2D ___m_clearedMask, HeightmapBuilder.HMBuildData ___m_buildData)
        {
            if (ZoneSystem.instance == null)
            {
                return(true);
            }
            Vector2i zoneID = ZoneSystem.instance.GetZone(__instance.transform.position);

            BetterTerrain.ZoneInfo zone = HMAPManager.GetZoneInfo(zoneID);
            if (zone == null || modifier == null || __instance != zone.hmap)
            {
                return(false);
            }
            bool was_applied = zone.applied_tmods.Contains(modifier);

            if (!was_applied)
            {
                zone.applied_tmods.Add(modifier);
            }
            bool  can_delete      = true;
            float modifier_radius = modifier.GetRadius();

            if (!zone.deletable_tmods.Contains(modifier))
            {
                for (int y = -1; y <= 1; y++)
                {
                    for (int x = -1; x <= 1; x++)
                    {
                        BetterTerrain.ZoneInfo check_zone = HMAPManager.GetZoneInfo(new Vector2i(zoneID.x + x, zoneID.y + y));
                        if (check_zone != null && check_zone.generated)
                        {
                            foreach (TerrainModifier tmod in check_zone.tmods.Except(check_zone.applied_tmods))
                            {
                                if (tmod != null)
                                {
                                    float radius = Math.Max(tmod.GetRadius(), modifier_radius);
                                    if (tmod != modifier && Vector3.Distance(tmod.transform.position, modifier.transform.position) <= radius)
                                    {
                                        Debug.Log(Vector3.Distance(tmod.transform.position, modifier.transform.position));
                                        can_delete = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            can_delete = false;
                        }
                    }
                }
                if (can_delete)
                {
                    Debug.Log("x");
                    zone.deletable_tmods.Add(modifier);
                }
            }
            if (was_applied)
            {
                return(false);
            }
            if (zone.saved && HMAPManager.loading_object)
            {
                return(false);
            }
            return(true);
        }