public override bool ShouldRemoveMapNow(out bool alsoRemoveWorldObject) { bool shouldRemove = !Map.mapPawns.AnyPawnBlockingMapRemoval; if (shouldRemove) { EnterCooldownComp cooldownComp = GetComponent <EnterCooldownComp>(); RealRuinsPOIComp poiComp = GetComponent <RealRuinsPOIComp>(); SetFaction(originalFaction); Debug.Log("Setting original faction ({0}), cached mat set to nil", originalFaction); cachedMat = null; //reset cached icon to recolor it Draw(); float blueprintCost = 1; if (poiComp != null) { if (poiComp.poiType == (int)POIType.Ruins) { alsoRemoveWorldObject = true; return(true); } else { blueprintCost = poiComp.approximateSnapshotCost; } } float mapWealth = CurrentMapWealth(); float difference = wealthOnEnter - mapWealth; float ratio = difference / blueprintCost; if (cooldownComp != null) { cooldownComp.Props.durationDays = Math.Max(4, difference / 2000); } Debug.Log(Debug.POI, "on enter {0}, now {1}, snapshot: {4}, diff {2}, ratio {3},", wealthOnEnter, mapWealth, difference, ratio, blueprintCost); alsoRemoveWorldObject = ratio > 0.5; //at least half worth of initial wealth is destroyed or stolen. return(true); } else { alsoRemoveWorldObject = false; } return(false); }
private List <AbstractDefenderForcesGenerator> GeneratorsForBlueprint(Blueprint bp, RealRuinsPOIComp poiComp, Faction faction) { List <AbstractDefenderForcesGenerator> result = new List <AbstractDefenderForcesGenerator>(); Debug.Log(Debug.Scatter, "Selecting force generators"); //override forces for any kind of POI if no faction selected if (faction == null || (POIType)poiComp.poiType == POIType.Ruins) { if (Rand.Chance(0.25f)) { result.Add(new AnimalInhabitantsForcesGenerator()); } else if (Rand.Chance(0.333f)) { result.Add(new MechanoidsForcesGenerator(0)); } else if (Rand.Chance(0.5f)) { result.Add(new CitizenForcesGeneration(1000, Find.FactionManager.RandomEnemyFaction(true, true, false))); } Debug.Log(Debug.Scatter, "Selected {0} for abandoned or ruins", result.Count); return(result); } switch ((POIType)poiComp.poiType) { case POIType.MilitaryBaseSmall: case POIType.MilitaryBaseLarge: case POIType.Stronghold: case POIType.Outpost: result.Add(new MilitaryForcesGenerator(poiComp.militaryPower)); break; case POIType.Camp: case POIType.City: case POIType.Factory: case POIType.PowerPlant: case POIType.Research: result.Add(new CitizenForcesGeneration(poiComp.bedsCount)); if (bp.totalCost > 50000 || bp.totalCost > 10000 && (poiComp.bedsCount < 6)) { result.Add(new MilitaryForcesGenerator(3)); } break; case POIType.Storage: if (bp.totalCost > 30000) { result.Add(new MilitaryForcesGenerator(2)); } else { result.Add(new CitizenForcesGeneration(poiComp.bedsCount)); } break; case POIType.Ruins: default: if (Rand.Chance(0.5f)) { result.Add(new MechanoidsForcesGenerator(0)); } break; } Debug.Log(Debug.Scatter, "Selected {0} for POIs", result.Count); return(result); }
public override void Generate(Map map, GenStepParams parms) { Find.TickManager.Pause(); //Debug.Message("Overridden LARGE generate"); RealRuinsPOIComp poiComp = map.Parent.GetComponent <RealRuinsPOIComp>(); string filename = SnapshotStoreManager.Instance.SnapshotNameFor(poiComp.blueprintName, poiComp.gameName); Debug.Log("Spawning POI: Preselected file name is {0}", filename); Debug.Log("Location is {0} {1}", poiComp.originX, poiComp.originZ); currentOptions = RealRuins_ModSettings.defaultScatterOptions.Copy(); //store as instance variable to keep accessible on subsequent ScatterAt calls currentOptions.minRadius = 400; currentOptions.maxRadius = 400; currentOptions.scavengingMultiplier = 0.0f; currentOptions.deteriorationMultiplier = 0.0f; currentOptions.hostileChance = 0.0f; currentOptions.blueprintFileName = filename; currentOptions.costCap = -1; currentOptions.startingPartyPoints = -1; currentOptions.minimumCostRequired = 0; currentOptions.minimumDensityRequired = 0.0f; currentOptions.minimumAreaRequired = 0; currentOptions.deleteLowQuality = false; currentOptions.shouldKeepDefencesAndPower = true; currentOptions.shouldLoadPartOnly = false; currentOptions.shouldAddRaidTriggers = false; currentOptions.claimableBlocks = false; if (poiComp.poiType == (int)POIType.Ruins || map.ParentFaction == null) { /*if (Rand.Chance(0.1f)) { * currentOptions.wallsDoorsOnly = true; * } else { * currentOptions.deteriorationMultiplier = Math.Abs(Rand.Gaussian(0, 0.15f)); * }*/ currentOptions.shouldAddFilth = true; currentOptions.forceFullHitPoints = false; currentOptions.enableDeterioration = true; currentOptions.overwritesEverything = false; currentOptions.costCap = (int)Math.Abs(Rand.Gaussian(0, 10000)); currentOptions.itemCostLimit = Rand.Range(50, 300); } else { currentOptions.shouldAddFilth = false; currentOptions.forceFullHitPoints = true; currentOptions.enableDeterioration = false; currentOptions.overwritesEverything = true; } currentOptions.overridePosition = new IntVec3(poiComp.originX, 0, poiComp.originZ); currentOptions.centerIfExceedsBounds = true; var bp = BlueprintLoader.LoadWholeBlueprintAtPath(filename); //FOR DEBUG LOGGING //var a = new BlueprintAnalyzer(bp, currentOptions); //a.Analyze(); Debug.Log(Debug.BlueprintTransfer, "Trying to place POI map at tile {0}, at {1},{2} to {3},{4} ({5}x{6})", map.Parent.Tile, poiComp.originX, poiComp.originZ, poiComp.originX + bp.width, poiComp.originZ + bp.height, bp.width, bp.height); var generators = GeneratorsForBlueprint(bp, poiComp, map.Parent.Faction); ResolveParams resolveParams = default(ResolveParams); BaseGen.globalSettings.map = map; resolveParams.faction = map.ParentFaction; resolveParams.rect = new CellRect(currentOptions.overridePosition.x, currentOptions.overridePosition.z, map.Size.x - currentOptions.overridePosition.x, map.Size.z - currentOptions.overridePosition.z); BaseGen.globalSettings.mainRect = resolveParams.rect; float uncoveredCost = currentOptions.uncoveredCost; if (resolveParams.faction != null) { //Debug.Log("Mannable count: {0}", poiComp.mannableCount); ManTurrets((int)(poiComp.mannableCount * 1.25f + 1), resolveParams, map); } RuinsScatterer.Scatter(resolveParams, currentOptions, null, generators); //ok, but why LIFO? Queue looks more suitable for map generation. //Looks like it was done for nested symbols resolving, but looks strange anyway. BaseGen.symbolStack.Push("chargeBatteries", resolveParams); BaseGen.symbolStack.Push("ensureCanHoldRoof", resolveParams); BaseGen.symbolStack.Push("refuel", resolveParams); BaseGen.Generate(); if (generators != null) { foreach (AbstractDefenderForcesGenerator generator in generators) { generator.GenerateStartingParty(map, resolveParams, currentOptions); } } }
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); }