static RealRuinsPOIWorldObject TryCreateWorldObject(int tile, Faction siteFaction) { Debug.Log("Creating site at tile: {0}", tile); if (Find.WorldObjects.AnyWorldObjectAt(tile)) { return(null); } RealRuinsPOIWorldObject site = (RealRuinsPOIWorldObject)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("RealRuinsPOI")); site.Tile = tile; site.SetFaction(siteFaction); Find.WorldObjects.Add(site); return(site); }
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); }