public void LoadAllMapsForSeed(string seed, int mapSize, float coverage, Action <bool, List <PlanetTileInfo> > completionHandler) { var path = APIRoot + MapsBySeedListPath + seed; string requestLink = path + "?limit=9999&coverage=" + coverage + "&mapSize=" + mapSize; Debug.Log(Debug.Loader, "Loading all compatible blueprings by link {0}", requestLink); UnityWebRequest request = new UnityWebRequest(requestLink, "GET") { downloadHandler = new DownloadHandlerBuffer() }; Action <byte[]> internalSuccessHandler = delegate(byte[] response) { string jsonString = Encoding.UTF8.GetString(response); List <PlanetTileInfo> tiles = new List <PlanetTileInfo>(); var json = JSON.Parse(jsonString); if (json != null) { foreach (JSONNode node in json) { string name = node["nameInBucket"]?.Value; if (name != null) { PlanetTileInfo tileInfo = new PlanetTileInfo(); tileInfo.mapId = name; tileInfo.tile = node["tileId"]?.AsInt ?? 0; tileInfo.biomeName = node["biome"]?.Value; tileInfo.originX = node["originX"]?.AsInt ?? 0; tileInfo.originZ = node["originZ"]?.AsInt ?? 0; tiles.Add(tileInfo); } } } completionHandler(true, tiles); }; void failureHandler(Exception ex) { Debug.Error(Debug.Loader, string.Format("Exception during loading object: {0}", ex), true); completionHandler(false, null); } AwaitUnityDataWebResponse(request, internalSuccessHandler, failureHandler); }
public static bool CreatePOI(PlanetTileInfo tileInfo, string gameName, bool biomeStrict, bool costStrict, bool itemsStrict) { if (tileInfo.tile >= Find.WorldGrid.TilesCount) { return(false); } if (!TileFinder.IsValidTileForNewSettlement(tileInfo.tile)) { return(false); } if (biomeStrict && tileInfo.biomeName != Find.WorldGrid.tiles[tileInfo.tile].biome.defName) { Debug.Warning(Debug.POI, "Skipped blueprint due to wrong biome"); return(false); } string filename = SnapshotStoreManager.Instance.SnapshotNameFor(tileInfo.mapId, gameName); Blueprint bp = BlueprintLoader.LoadWholeBlueprintAtPath(filename); if (bp == null) { return(false); } if (tileInfo.originX + bp.width > Find.World.info.initialMapSize.x || tileInfo.originZ + bp.height > Find.World.info.initialMapSize.z) { Debug.Warning(Debug.POI, "Skipped because of exceeding size ({{0} + {1} > {2} && {3} + {4} > {5})", tileInfo.originX, bp.width, Find.World.info.initialMapSize.x, tileInfo.originZ, bp.height, Find.World.info.initialMapSize.z); return(false); } BlueprintAnalyzer ba = new BlueprintAnalyzer(bp); ba.Analyze(); if (costStrict && (ba.result.totalItemsCost < 1000)) { Debug.Warning(Debug.POI, "Skipped blueprint due to low total cost or tiles count"); return(false); } if (ba.result.occupiedTilesCount < 50 || ba.result.totalArea < 200) { Debug.Warning(Debug.POI, "Skipped blueprint due to low area ({0}) and/or items count {1}", ba.result.totalArea, ba.result.occupiedTilesCount); return(false); } var poiType = ba.determinedType; Faction faction = null; if (Rand.Chance(ba.chanceOfHavingFaction())) { Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction(out faction, false, false, minTechLevel: MinTechLevelForPOIType(poiType)); } RealRuinsPOIWorldObject site = TryCreateWorldObject(tileInfo.tile, faction); if (site == null) { return(false); } RealRuinsPOIComp comp = site.GetComponent <RealRuinsPOIComp>(); if (comp == null) { Debug.Error(Debug.BlueprintTransfer, "POI Component is null!"); } else { comp.blueprintName = tileInfo.mapId; comp.gameName = gameName; comp.originX = tileInfo.originX; comp.originZ = tileInfo.originZ; comp.poiType = (int)poiType; comp.militaryPower = ba.militaryPower; comp.mannableCount = ba.mannableCount; comp.approximateSnapshotCost = ba.result.totalItemsCost; comp.bedsCount = ba.result.bedsCount; } return(true); }