예제 #1
0
        private static void ScanPrefabs(ZoneSystem __instance)
        {
            var prefabs = ZNetScene.instance.m_prefabs;

            {
                var prefabsWithDropTables = new List <Tuple <GameObject, CharacterDrop> >();

                foreach (var prefab in prefabs)
                {
                    var characterDrop = prefab.GetComponent <CharacterDrop>();
                    if (characterDrop)
                    {
                        prefabsWithDropTables.Add(new Tuple <GameObject, CharacterDrop>(prefab, characterDrop));
                    }
                }

                if (ConfigurationManager.GeneralConfig?.WriteCharacterDropsToFile?.Value == true)
                {
                    CharacterDropFileWriter.WriteToFile(prefabsWithDropTables);
                }

                if (ConfigurationManager.GeneralConfig?.WriteCreatureItemsToFile?.Value == true)
                {
                    CreatureItemFileWriter.WriteToFile(prefabsWithDropTables);
                }
            }
        }
예제 #2
0
 public void HouseholdIterationComplete(ITashaHousehold household, int hhldIteration, int totalHouseholdIterations)
 {
     foreach (var person in household.Persons)
     {
         if (person.Age < MinimumAge)
         {
             continue;
         }
         var expansionFactor = person.ExpansionFactor;
         foreach (var tripChain in person.TripChains)
         {
             foreach (var trip in tripChain.Trips)
             {
                 var tripTime = trip.TripStartTime;
                 if (tripTime >= StartTime && tripTime < EndTime)
                 {
                     var index  = GetIndex(trip.Mode);
                     var oIndex = ZoneSystem.GetFlatIndex(trip.OriginalZone.ZoneNumber);
                     var dIndex = ZoneSystem.GetFlatIndex(trip.DestinationZone.ZoneNumber);
                     if (oIndex >= 0 & dIndex >= 0)
                     {
                         bool taken = false;
                         DataLock[index].Enter(ref taken);
                         if (taken)
                         {
                             Data[index][oIndex][dIndex] += expansionFactor;
                             DataLock[index].Exit(true);
                         }
                     }
                 }
             }
         }
     }
 }
        public void Start()
        {
            if (FirstLoad)
            {
                ZoneSystem.LoadData();
                foreach (var network in NetworkData)
                {
                    network.LoadData();
                }
                TourLoader.LoadData();
                FirstLoad = false;
            }
            // the model needs to be loaded every time
            AccessStationChoiceModel.Load();
            var tours = TourLoader.ToArray();

            float result = ComputeError(tours);

            Completed = 0;
            // ReSharper disable once PossibleLossOfFraction
            _Progress          = () => Completed / tours.Length;
            Root.RetrieveValue = () =>
            {
                return(result);
            };
            if (ConfusionMatrix != null)
            {
                ProduceConfusionMatrix(tours);
            }
            _Progress = () => 1.0f;
        }
예제 #4
0
        public void IterationFinished(int iteration, int totalIterations)
        {
            var zones = ZoneSystem.ValidIndexArray();

            using (StreamWriter writer = new StreamWriter(SaveLocation))
            {
                writer.WriteLine("Mode,Origin,Destination,ExpandedTrips");
                for (int m = 0; m < Data.Length; m++)
                {
                    string modeName = Modes[m].ModeName + ",";
                    var    oRow     = Data[m];
                    for (int o = 0; o < oRow.Length; o++)
                    {
                        var dRow = oRow[o];
                        for (int d = 0; d < dRow.Length; d++)
                        {
                            if (dRow[d] > 0)
                            {
                                // this includes the comma already
                                writer.Write(modeName);
                                writer.Write(zones[o]);
                                writer.Write(',');
                                writer.Write(zones[d]);
                                writer.Write(',');
                                writer.WriteLine(dRow[d]);
                            }
                        }
                    }
                }
            }
            Data = null;
        }
예제 #5
0
    // Token: 0x0600107E RID: 4222 RVA: 0x00074C6C File Offset: 0x00072E6C
    private static List <DungeonDB.RoomData> SetupRooms()
    {
        GameObject[] array      = Resources.FindObjectsOfTypeAll <GameObject>();
        GameObject   gameObject = null;

        foreach (GameObject gameObject2 in array)
        {
            if (gameObject2.name == "_Rooms")
            {
                gameObject = gameObject2;
                break;
            }
        }
        if (gameObject == null || (DungeonDB.m_instance && gameObject.activeSelf))
        {
            if (DungeonDB.m_instance)
            {
                DungeonDB.m_instance.m_error = true;
            }
            ZLog.LogError("Rooms are f****d, missing _Rooms or its enabled");
        }
        List <DungeonDB.RoomData> list = new List <DungeonDB.RoomData>();

        for (int j = 0; j < gameObject.transform.childCount; j++)
        {
            Room component = gameObject.transform.GetChild(j).GetComponent <Room>();
            DungeonDB.RoomData roomData = new DungeonDB.RoomData();
            roomData.m_room = component;
            ZoneSystem.PrepareNetViews(component.gameObject, roomData.m_netViews);
            ZoneSystem.PrepareRandomSpawns(component.gameObject, roomData.m_randomSpawns);
            list.Add(roomData);
        }
        return(list);
    }
예제 #6
0
            static void Prefix(ZoneSystem __instance, Dictionary <Vector2i, ZoneSystem.LocationInstance> ___m_locationInstances)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                Dbgl($"Starting ZoneSystem, relocating merchant");

                for (int i = 0; i < ___m_locationInstances.Count; i++)
                {
                    Vector2i v = ___m_locationInstances.Keys.ToArray()[i];
                    ZoneSystem.LocationInstance loc = ___m_locationInstances[v];
                    if (loc.m_location.m_prefabName == "Vendor_BlackForest")
                    {
                        if (merchantPosition.Value != Vector3.zero)
                        {
                            ___m_locationInstances.Remove(v);
                            loc.m_position = merchantPosition.Value;
                            Vector2i zone = __instance.GetZone(merchantPosition.Value);
                        }

                        break;
                    }
                }
            }
        public void Start()
        {
            if (ZoneSystem != null)
            {
                ZoneSystem.LoadData();
            }
            int i = 0;

            _Progress = () =>
            {
                if (i < ToExecute.Length)
                {
                    return(((float)i / ToExecute.Length) + (1.0f / ToExecute.Length) * ToExecute[i].Progress);
                }
                return(1.0f);
            };
            _Status = () =>
            {
                return(ToExecute[i].ToString());
            };
            for (; i < ToExecute.Length; i++)
            {
                ToExecute[i].Start();
            }
            if (ZoneSystem != null)
            {
                ZoneSystem.UnloadData();
            }
        }
예제 #8
0
        public void Start()
        {
            if (FirstTime || LoadTruthEveryTime)
            {
                ZoneSystem.LoadData();
                foreach (var network in NetworkData)
                {
                    network.LoadData();
                }
                truth = TruthData.AcquireResource <SparseTwinIndex <float> >().GetFlatData();
                TruthData.ReleaseResource();
            }
            var model = ModelData.AcquireResource <SparseTriIndex <float> >().GetFlatData();
            var zones = ZoneSystem.ZoneArray.GetFlatData();

            // sum up the truth
            if (FirstTime || LoadTruthEveryTime)
            {
                // we only need to do this once
                TruthRows = (from row in truth
                             select row.Sum()).ToArray();

                InverseOfTotalTrips = 1.0f / TruthRows.Sum();
                if (AggregateToPlanningDistricts)
                {
                    PDError          = ZoneSystemHelper.CreatePDTwinArray <float>(ZoneSystem.ZoneArray);
                    ZoneToPDIndexMap = (from zone in zones
                                        select PDError.GetFlatIndex(zone.PlanningDistrict)).ToArray();
                    // transform the truth to be PD based
                    truth = AggregateResults((new float[][][] { truth }), zones)
                            .Select(row => row.Select(element => element).ToArray()).ToArray();
                }
                FirstTime = false;
            }
            var aggregated = AggregateResults(model, zones);
            // calculate the error
            float error = ComputeError(truth, aggregated);

            // set the value in the root
            Root.RetrieveValue = () => error;
            if (ModelSaveFile != null)
            {
                SaveData.SaveMatrix(zones, AggregateResults(model, zones), ModelSaveFile);
            }

            if (this.DistanceHistogram != null)
            {
                var distances = ZoneSystem.Distances.GetFlatData();
                this.DistanceHistogram.Export(distances, model);
            }


            ModelData.ReleaseResource();
            for (int i = 0; i < PostRun.Length; i++)
            {
                PostRun[i].Start();
            }
        }
예제 #9
0
        private static void AddCustomMobs(On.ZoneSystem.orig_Awake orig, ZoneSystem self)
        {
            orig(self);

            var spawnSystem = self.m_zoneCtrlPrefab.GetComponent <SpawnSystem>();

            OnAfterInit.SafeInvoke(spawnSystem);
            OnAfterInit = null;
        }
예제 #10
0
 private static void SpawnZone_Postfix(ZoneSystem __instance, Vector2i zoneID, GameObject root)
 {
     if (!(root == null))
     {
         HMAPManager.SetGameObject(zoneID, root.GetComponentInChildren <Heightmap>().gameObject);
         HMAPManager.SetHeightmap(zoneID, root.GetComponentInChildren <Heightmap>());
         HMAPManager.CalcTMods(zoneID);
         HMAPManager.GetZoneInfo(zoneID).hmap.Regenerate();
     }
 }
        private static void PrintLocations(ZoneSystem __instance)
        {
            if (__instance.m_locations is null)
            {
                return;
            }

            if (ConfigurationManager.GeneralConfig.WriteLocationsToFile)
            {
                LocationsFileWriter.WriteToList(__instance.m_locations);
            }
        }
    private static void ScanAndWriteLocations(ZoneSystem __instance)
    {
        if (__instance.m_locations is null)
        {
            return;
        }

        if (ConfigurationManager.GeneralConfig?.WriteCreatureSpawnersToFile?.Value == true)
        {
            CreatureSpawnerFileDumper.WriteToFile(__instance.m_locations);
        }
    }
예제 #13
0
 public void Execute(ITashaHousehold household, int iteration)
 {
     lock (this)
     {
         var householdZone = ZoneSystem.GetFlatIndex(household.HomeZone.ZoneNumber);
         Households.Add(household);
         foreach (var pool in PopulationPools)
         {
             pool.AddIfContained(household, householdZone, Households.Count - 1);
         }
     }
 }
예제 #14
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;
            }
        }
            private static bool GenerateLocationsPrefix(ZoneSystem __instance, ZoneSystem.ZoneLocation location)
            {
                var groupName = string.IsNullOrEmpty(location.m_group) ? "<unnamed>" : location.m_group;

                Log($"Generating location of group {groupName}, required {location.m_quantity}, unique {location.m_unique}, name {location.m_prefabName}");
                if (Settings.EnabledForThisWorld)
                {
                    if (Settings.HasSpawnmap)
                    {
                        // Place all locations specified by the spawn map, ignoring counts specified in the prefab
                        int placed = 0;
                        foreach (var normalizedPosition in Settings.GetAllSpawns(location.m_prefabName))
                        {
                            var worldPos = NormalizedToWorld(normalizedPosition);
                            var position = new Vector3(
                                worldPos.x,
                                WorldGenerator.instance.GetHeight(worldPos.x, worldPos.y),
                                worldPos.y
                                );
                            RegisterLocation(__instance, location, position, false);
                            Log($"Position of {location.m_prefabName} ({++placed}/{location.m_quantity}) overriden: set to {position}");
                        }

                        // The vanilla placement algorithm considers already placed zones, but we can early out here anyway if we place them all
                        // (this is required in the case of the StartTemple as we don't want to place it twice if OverrideStartPosition is specified)
                        if (placed >= location.m_quantity)
                        {
                            return(false);
                        }
                    }

                    if (Settings.OverrideStartPosition && location.m_prefabName == "StartTemple")
                    {
                        var position = new Vector3(
                            Settings.StartPositionX,
                            WorldGenerator.instance.GetHeight(Settings.StartPositionX, Settings.StartPositionY),
                            Settings.StartPositionY
                            );
                        RegisterLocation(__instance, location, position, false);
                        Log($"Start position overriden: set to {position}");
                        return(false);
                    }

                    if (location.m_prefabName != "StartTemple" && ConfigDebugSkipDefaultLocationPlacement.Value)
                    {
                        return(false);
                    }
                }
                return(true);
            }
예제 #16
0
 private void AddToMatrix(float expFactor, Time startTime, IZone origin, IZone destination)
 {
     if (startTime >= StartTime & startTime < EndTime)
     {
         var  originIndex      = ZoneSystem.GetFlatIndex(origin.ZoneNumber);
         var  destinationIndex = ZoneSystem.GetFlatIndex(destination.ZoneNumber);
         bool gotLock          = false;
         WriteLock.Enter(ref gotLock);
         Matrix[originIndex][destinationIndex] += expFactor;
         if (gotLock)
         {
             WriteLock.Exit(true);
         }
     }
 }
예제 #17
0
 public void Start()
 {
     ZoneSystem.LoadData();
     for (int i = 0; i < PreRun.Length; i++)
     {
         _status = () => PreRun[i].ToString();
         PreRun[i].Start();
     }
     foreach (var model in RunYearly)
     {
         _status = () => model.ToString();
         model.BeforeFirstYear(StartYear);
     }
     for (int year = 0; year < NumberOfYears && !_exit; year++)
     {
         for (int i = 0; i < RunYearly.Length && !_exit; i++)
         {
             _status = () => RunYearly[i].ToString();
             RunYearly[i].BeforeYearlyExecute(StartYear + year);
         }
         for (int i = 0; i < RunYearly.Length && !_exit; i++)
         {
             _status  = () => (year + this.StartYear) + ": " + RunYearly[i].ToString();
             Progress = (float)year / NumberOfYears + (1.0f / NumberOfYears) * ((float)i / RunYearly.Length);
             RunYearly[i].Execute(StartYear + year);
         }
         for (int i = 0; i < RunYearly.Length && !_exit; i++)
         {
             _status = () => RunYearly[i].ToString();
             RunYearly[i].AfterYearlyExecute(StartYear + year);
         }
     }
     foreach (var model in RunYearly)
     {
         _status = () => model.ToString();
         model.RunFinished(StartYear + NumberOfYears - 1);
     }
     for (int i = 0; i < PostRun.Length; i++)
     {
         _status = () => PostRun[i].ToString();
         PostRun[i].Start();
     }
     ZoneSystem.UnloadData();
 }
        public static bool HasGlobalKey(this ZoneSystem zoneSystem, string playerName, string key)
        {
            HashSet <string> globalKeys = _globalKeysField.GetValue(zoneSystem) as HashSet <string>;

#if DEBUG
            Log.LogDebug($"Checking for {key} in keys: " + globalKeys.Join());
#endif

            if (globalKeys is null)
            {
                Log.LogWarning("Unable to find/access global keys.");
                return(false);
            }

            if (Enum.TryParse(ConfigurationManager.GeneralConfig.KeyMode.Value, true, out KeyMode keyMode))
            {
                switch (keyMode)
                {
                case KeyMode.Player:
#if DEBUG
                    Log.LogDebug($"Checking key {key} for player {playerName}");
#endif
                    return(EnhancedGlobalKey.HasPlayerKey(playerName, key, globalKeys));

                case KeyMode.Tribe:
#if DEBUG
                    Log.LogDebug($"Checking key {key} for tribe of {playerName}");
#endif
                    return(EnhancedGlobalKey.HasTribeKey(playerName, key, globalKeys));

                default:
                    return(globalKeys.Contains(key));
                }
            }

            //If no key-mode is set, use default global keys.
            Log.LogWarning("Unable to find valid key-mode configuration. Will fallback to Default mode.");
            return(globalKeys.Contains(key));
        }
예제 #19
0
            static void Postfix(ref ZoneSystem __instance, ref bool __result, PrefixState __state)
            {
                if (__result)
                {
                    return;
                }
                if (__state.isDungeon)
                {
                    var locationInstances = AccessTools.FieldRefAccess <ZoneSystem, Dictionary <Vector2i, ZoneSystem.LocationInstance> >(__instance, "m_locationInstances");

                    foreach (ZoneSystem.LocationInstance locationInstance in locationInstances.Values)
                    {
                        var prefabName = locationInstance.m_location.m_prefabName;
                        if ((IsDungeon(prefabName) || IsTrollCave(prefabName)) &&
                            Vector3.Distance(locationInstance.m_position, __state.point) < __state.radius)
                        {
                            __result = true;
                            return;
                        }
                    }
                }
                return;
            }
예제 #20
0
        public void Start()
        {
            if (ZoneSystem != null)
            {
                ZoneSystem.LoadData();
            }
            int i = 0;

            _Progress = () =>
            {
                if (i < ToExecute.Length)
                {
                    return(((float)i / ToExecute.Length) + (1.0f / ToExecute.Length) * ToExecute[i].Progress);
                }
                return(1.0f);
            };
            _Status = () =>
            {
                return(ToExecute[i].ToString());
            };
            Parallel.For(0, NetworkData.Count, (int n) =>
            {
                NetworkData[n].LoadData();
            });
            for (; i < ToExecute.Length; i++)
            {
                ToExecute[i].Start();
            }
            Parallel.For(0, NetworkData.Count, (int n) =>
            {
                NetworkData[n].UnloadData();
            });
            if (ZoneSystem != null)
            {
                ZoneSystem.UnloadData();
            }
        }
예제 #21
0
        private static void ReplaceHeightmapTextures()
        {
            Dbgl($"Reloading Heightmap textures for {Heightmap.GetAllHeightmaps().Count} heightmaps");

            ZoneSystem zoneSystem = (ZoneSystem)typeof(ZoneSystem).GetField("m_instance", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);

            logDump.Clear();

            Heightmap hm = (Heightmap)typeof(EnvMan).GetField("m_cachedHeightmap", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(EnvMan.instance);

            if (hm != null)
            {
                Material mat = hm.m_material;

                if (mat != null)
                {
                    outputDump.Add($"terrain {zoneSystem.name}, prefab {zoneSystem.m_zonePrefab}");
                    ReplaceMaterialTextures(zoneSystem.m_zonePrefab.name, mat, zoneSystem.name, "terrain", "Terrain", zoneSystem.m_zonePrefab.name);
                    hm.Regenerate();
                }
            }

            foreach (Heightmap h in Heightmap.GetAllHeightmaps())
            {
                Material mat = h.m_material;

                if (mat != null)
                {
                    outputDump.Add($"terrain {zoneSystem.name}, prefab {zoneSystem.m_zonePrefab}");
                    ReplaceMaterialTextures(zoneSystem.m_zonePrefab.name, mat, zoneSystem.name, "terrain", "Terrain", zoneSystem.m_zonePrefab.name);
                }
            }
            if (logDump.Any())
            {
                Dbgl("\n" + string.Join("\n", logDump));
            }
        }
예제 #22
0
        private static void ReplaceZoneSystemTextures(ZoneSystem __instance)
        {
            Dbgl($"Reloading ZoneSystem textures {__instance.name} {__instance.m_zonePrefab.name}");

            ReplaceOneZoneTextures(__instance.name, __instance.m_zonePrefab);
        }
예제 #23
0
        public void Start()
        {
            if (!ZoneSystem.Loaded)
            {
                ZoneSystem.LoadData();
            }
            var truth = TruthData.AcquireResource <SparseTriIndex <float> >().GetFlatData();

            if (first)
            {
                TotalTruth       = truth.Select(category => category.Sum(row => VectorHelper.Sum(row, 0, row.Length))).ToArray();
                TotalTruthByZone = new float[TotalTruth.Length][];
                for (int category = 0; category < TotalTruth.Length; category++)
                {
                    TotalTruthByZone[category] = new float[truth[category].Length];
                    //normalize the truth data
                    Parallel.For(0, truth[category].Length, (int i) =>
                    {
                        float[] truthRow = truth[category][i];
                        TotalTruthByZone[category][i] = VectorHelper.Sum(truthRow, 0, truthRow.Length);
                        VectorHelper.Multiply(truthRow, 0, truthRow, 0, 1.0f / TotalTruth[category], truthRow.Length);
                    });
                }
                for (int i = 0; i < NetworkData.Count; i++)
                {
                    NetworkData[i].LoadData();
                }
                first = false;
            }
            var model = ModelData.AcquireResource <SparseTriIndex <float> >().GetFlatData();

            ModelData.ReleaseResource();
            // Normalize the model data
            float[] modelTotalByCategory = model.Select(cateogry => cateogry.Sum(row => VectorHelper.Sum(row, 0, row.Length))).ToArray();
            for (int category = 0; category < modelTotalByCategory.Length; category++)
            {
                //normalize the truth data
                Parallel.For(0, model[category].Length, (int i) =>
                {
                    float[] modelRow = model[category][i];
                    VectorHelper.Multiply(modelRow, 0, modelRow, 0, 1.0f / modelTotalByCategory[category], modelRow.Length);
                });
            }
            float fitness = 0.0f;

            for (int category = 0; category < truth.Length; category++)
            {
                Parallel.For(0, truth[category].Length,
                             () =>
                {
                    return(new float[truth[category].Length]);
                },
                             (int i, ParallelLoopState _, float[] errorForHomeZone) =>
                {
                    var observedLinkagesForZone = TotalTruthByZone[category][i];
                    var truthRow = truth[category][i];
                    var modelRow = model[category][i];
                    if (observedLinkagesForZone > 0.0f)
                    {
                        var local = 0.0f;
                        for (int j = 0; j < truthRow.Length; j++)
                        {
                            local += (truthRow[j] * (float)Math.Max(Math.Log(modelRow[j]), MaximumError));
                        }
                        errorForHomeZone[i] += observedLinkagesForZone * local;
                    }
                    return(errorForHomeZone);
                },
                             (float[] errorData) =>
                {
                    var sumOfError = VectorHelper.Sum(errorData, 0, errorData.Length);
                    lock (this)
                    {
                        fitness += sumOfError;
                    }
                });
            }
            Root.RetrieveValue = () => VectorHelper.Sum(TotalTruth, 0, TotalTruth.Length) * fitness;
        }
예제 #24
0
 static void Prefix(ZoneSystem __instance)
 {
     ReplaceZoneSystemTextures(__instance);
 }
예제 #25
0
 public void Start()
 {
     ZoneSystem.LoadData();
     this.SelfContainedModule.Start();
     ZoneSystem.UnloadData();
 }
 private int GetFlatIndex(IZone zone)
 {
     return(ZoneSystem.GetFlatIndex(zone.ZoneNumber));
 }
예제 #27
0
            static void Postfix(ZoneSystem __instance)
            {
                Vector3 startPos;

                ZoneSystem.instance.GetLocationIcon("StartTemple", out startPos);
                WebMapConfig.WORLD_START_POS = startPos;

                if (mapDataServer.mapImageData != null)
                {
                    Debug.Log("WebMap: MAP ALREADY BUILT!");
                    return;
                }
                Debug.Log("WebMap: BUILD MAP!");

                int   num  = WebMapConfig.TEXTURE_SIZE / 2;
                float num2 = WebMapConfig.PIXEL_SIZE / 2f;

                Color32[] colorArray    = new Color32[WebMapConfig.TEXTURE_SIZE * WebMapConfig.TEXTURE_SIZE];
                Color32[] treeMaskArray = new Color32[WebMapConfig.TEXTURE_SIZE * WebMapConfig.TEXTURE_SIZE];
                float[]   heightArray   = new float[WebMapConfig.TEXTURE_SIZE * WebMapConfig.TEXTURE_SIZE];
                for (int i = 0; i < WebMapConfig.TEXTURE_SIZE; i++)
                {
                    for (int j = 0; j < WebMapConfig.TEXTURE_SIZE; j++)
                    {
                        float           wx          = (float)(j - num) * WebMapConfig.PIXEL_SIZE + num2;
                        float           wy          = (float)(i - num) * WebMapConfig.PIXEL_SIZE + num2;
                        Heightmap.Biome biome       = WorldGenerator.instance.GetBiome(wx, wy);
                        float           biomeHeight = WorldGenerator.instance.GetBiomeHeight(biome, wx, wy);
                        colorArray[i * WebMapConfig.TEXTURE_SIZE + j]    = GetPixelColor(biome);
                        treeMaskArray[i * WebMapConfig.TEXTURE_SIZE + j] = GetMaskColor(wx, wy, biomeHeight, biome);
                        heightArray[i * WebMapConfig.TEXTURE_SIZE + j]   = biomeHeight;
                    }
                }

                var waterLevel = ZoneSystem.instance.m_waterLevel;
                var sunDir     = new Vector3(-0.57735f, 0.57735f, 0.57735f);
                var newColors  = new Color[colorArray.Length];

                for (var t = 0; t < colorArray.Length; t++)
                {
                    var h = heightArray[t];

                    var tUp = t - WebMapConfig.TEXTURE_SIZE;
                    if (tUp < 0)
                    {
                        tUp = t;
                    }
                    var tDown = t + WebMapConfig.TEXTURE_SIZE;
                    if (tDown > colorArray.Length - 1)
                    {
                        tDown = t;
                    }
                    var tRight = t + 1;
                    if (tRight > colorArray.Length - 1)
                    {
                        tRight = t;
                    }
                    var tLeft = t - 1;
                    if (tLeft < 0)
                    {
                        tLeft = t;
                    }
                    var hUp    = heightArray[tUp];
                    var hRight = heightArray[tRight];
                    var hLeft  = heightArray[tLeft];
                    var hDown  = heightArray[tDown];

                    var va     = new Vector3(2f, 0f, hRight - hLeft).normalized;
                    var vb     = new Vector3(0f, 2f, hUp - hDown).normalized;
                    var normal = Vector3.Cross(va, vb);

                    var surfaceLight = Vector3.Dot(normal, sunDir) * 0.25f + 0.75f;

                    float shoreMask   = Mathf.Clamp(h - waterLevel, 0, 1);
                    float shallowRamp = Mathf.Clamp((h - waterLevel + 0.2f * 12.5f) * 0.5f, 0, 1);
                    float deepRamp    = Mathf.Clamp((h - waterLevel + 1f * 12.5f) * 0.1f, 0, 1);

                    var   mapColor = colorArray[t];
                    Color ans      = Color.Lerp(ShoreColor, mapColor, shoreMask);
                    ans = Color.Lerp(ShallowWaterColor, ans, shallowRamp);
                    ans = Color.Lerp(DeepWaterColor, ans, deepRamp);

                    newColors[t] = new Color(ans.r * surfaceLight, ans.g * surfaceLight, ans.b * surfaceLight, ans.a);
                }

                var newTexture = new Texture2D(WebMapConfig.TEXTURE_SIZE, WebMapConfig.TEXTURE_SIZE, TextureFormat.RGBA32, false);

                newTexture.SetPixels(newColors);
                byte[] pngBytes = newTexture.EncodeToPNG();

                mapDataServer.mapImageData = pngBytes;
                try {
                    File.WriteAllBytes(Path.Combine(worldDataPath, "map"), pngBytes);
                } catch {
                    Debug.Log("WebMap: FAILED TO WRITE MAP FILE!");
                }
                Debug.Log("WebMap: BUILDING MAP DONE!");
            }
예제 #28
0
 static void Prefix(ZoneSystem __instance)
 {
     outputDump.Clear();
     ReplaceZoneSystemTextures(__instance);
 }
예제 #29
0
        public void Start()
        {
            // setup the status to be initializing
            _Status          = null;
            _Progress        = () => 0f;
            CurrentIteration = 0;
            if (!VehicleTypes.Contains(AutoType))
            {
                VehicleTypes.Add(AutoType);
            }
            ZoneSystem.LoadData();
            if (PreRun != null)
            {
                foreach (var module in PreRun)
                {
                    module.Start();
                }
            }
            IterationPercentage = 1f / TotalIterations;
            if (PostScheduler != null)
            {
                foreach (var module in PostScheduler)
                {
                    module.Load(TotalIterations);
                }
            }
            if (PostHousehold != null)
            {
                foreach (var module in PostHousehold)
                {
                    module.Load(TotalIterations);
                }
            }

            if (OverrideModeParameters)
            {
                InitializeParameters();
            }
            LoadNetworkData(0);
            if (Scheduler != null)
            {
                Scheduler.LoadOneTimeLocalData();
            }

            if (ModeChoice != null)
            {
                ModeChoice.LoadOneTimeLocalData();
            }

            for (int i = 0; i < TotalIterations; i++)
            {
                if (!_ExitRequested)
                {
                    CurrentHousehold             = 0;
                    CurrentIteration             = i;
                    CompletedIterationPercentage = i * IterationPercentage;
                    if (LoadAllHouseholds)
                    {
                        if (!SkipLoadingHouseholds)
                        {
                            HouseholdLoader.LoadData();
                        }
                    }
                    RunIteration(i);
                }
            }
            if (PostRun != null)
            {
                foreach (var module in PostRun)
                {
                    module.Start();
                }
            }
            ZoneSystem.UnloadData();
        }
        public static bool HasGlobalKey(this ZoneSystem zoneSystem, Player player, string key)
        {
            string playerName = player.GetHoverName();

            return(HasGlobalKey(zoneSystem, playerName, key));
        }