public static void RegisterActivated(CompGatherSpot spot) { if (!activeSpots.Contains(spot)) { activeSpots.Add(spot); } }
public static void RegisterDeactivated(CompGatherSpot spot) { if (activeSpots.Contains(spot)) { activeSpots.Remove(spot); } }
// Fill the cell with Thing (Building) private static void TrySetCell_2_SetThing(IntVec3 c, Map map, ThingDef thingDef, Rot4 thingRot, ThingDef stuffDef = null) { //Note: Here is no functionality to clear the cell by design, because it is possible to place items that are larger than 1x1 // 2nd step - work with the Thing (Buildings) if (thingDef != null) { ThingDef stuffDef1 = stuffDef; if (!thingDef.MadeFromStuff) { stuffDef1 = null; } Thing newThing = ThingMaker.MakeThing(thingDef, stuffDef1); if (thingRot == null || thingRot == Rot4.Invalid) { GenSpawn.Spawn(newThing, c, map); } else { GenSpawn.Spawn(newThing, c, map, thingRot); } // If CompGatherSpot -> disable it! CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } } }
public static void PlaceBuildingsAndItems(List <MapObject> mapObjects, Map map, Faction forceFaction, bool refuel) { foreach (var thing in mapObjects) { ThingData data = thing.key; if (data.Thing != null) { foreach (var pos in thing.value) { Thing newThing = ThingMaker.MakeThing(data.Thing, data.Stuff); var comp = newThing.TryGetComp <CompQuality>(); if (comp != null) { comp.SetQuality(data.Quality, ArtGenerationContext.Colony); } if (newThing.def.stackLimit != 1) { newThing.stackCount = data.Count; } newThing = GenSpawn.Spawn(newThing, pos, map, data.Rotate); CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } if (newThing.def.CanHaveFaction && forceFaction != null) { newThing.SetFaction(forceFaction); } CompRefuelable compRefuelable = newThing.TryGetComp <CompRefuelable>(); if (compRefuelable != null && refuel) { compRefuelable.Refuel(compRefuelable.Props.fuelCapacity); } } } } }
public static void ToggleCompGatherSpot(Thing t, bool force = false, bool value = false) { CompGatherSpot comp = t.TryGetComp <CompGatherSpot>(); if (comp is CompGatherSpot) { if (!force) { comp.Active = false; } else { comp.Active = value; } } else { Tools.Warn("should have found a CompGatherSpot but no CompGatherSpot found", true); } }
// Fill the cell with Thing (Building) private static void TrySetCell_2_SetThing(IntVec3 c, Map map, Faction faction, ThingData thingData, Rot4 thingRot, ThingDef stuffDef = null) { if (thingData == null) { return; } if (!Rand.Chance(thingData.Chance)) { return; } //Note: Here is no functionality to clear the cell by design, because it is possible to place items that are larger than 1x1 // 2nd step - work with the Thing (Buildings) if (thingData.Thing != null) { ThingDef thingDef = thingData.Thing; ThingDef stuffDef1 = null; if (thingData.Stuff.Count > 0) { float value = Rand.Value; foreach (var pair in thingData.Stuff.OrderBy(pair => pair.Value)) { if (value < pair.Value) { stuffDef1 = pair.Key; break; } } } if (stuffDef1 == null) { stuffDef1 = stuffDef; } if (!thingDef.MadeFromStuff) { stuffDef1 = null; } Thing newThing = ThingMaker.MakeThing(thingDef, stuffDef1); if (thingData.Quality.Count > 0) { var comp = newThing.TryGetComp <CompQuality>(); if (comp != null) { float value = Rand.Value; foreach (var pair in thingData.Quality.OrderBy(pair => pair.Value)) { if (value < pair.Value) { comp.SetQuality(pair.Key, ArtGenerationContext.Outsider); break; } } } } if (thingRot == null || thingRot == Rot4.Invalid) { newThing = GenSpawn.Spawn(newThing, c, map); } else { newThing = GenSpawn.Spawn(newThing, c, map, thingRot); } // Set it to the current faction newThing.SetFactionDirect(faction); // If CompGatherSpot -> disable it! CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } CompRefuelable compRefuelable = newThing.TryGetComp <CompRefuelable>(); if (compRefuelable != null) { compRefuelable.Refuel(compRefuelable.Props.fuelCapacity); } } }
//private void DoPawnAwayHandling() //{ // if (!Active) // return; // if (PawnsOutOfMap == null || PawnsOutOfMap.Count == 0) // return; // Dialog_RumorOf_Fight.CreateThisDialog(); //} private void DoPawnReturningHandling() { if (!Active) { return; } if (PawnsOutOfMap == null || PawnsOutOfMap.Count == 0) { return; } // Set the time the pawns will be gone, if not already set if (returnTicks < 0) { SetNewTravelTime(); } returnTicks--; if (returnTicks > 0) { return; } // returnTicks == 0 -> Do this: if (IncidentPoints < incidentPointsMin) { IncidentPoints = incidentPointsMin; } if (GatherSpotLister.activeSpots.Count > 0) { // Find a gather spot not inside a prison cell IntVec3 GatherSpotCell = IntVec3.Invalid; int n = 0; while (n < 25) { CompGatherSpot gs = GatherSpotLister.activeSpots.RandomElement(); GatherSpotCell = gs.parent.Position; if (GatherSpotCell.IsInPrisonCell()) { GatherSpotCell = IntVec3.Invalid; } if (GatherSpotCell != IntVec3.Invalid) { ReturnToBaseCell = GatherSpotCell; break; } n++; } } //// Nothing -> Try TradeDropSpot //if (ReturnToBaseCell == IntVec3.Invalid) // ReturnToBaseCell = RCellFinder.TradeDropSpot(); //Nothing -> Try Colonist Position if (ReturnToBaseCell == IntVec3.Invalid) { ReturnToBaseCell = Find.MapPawns.FreeColonistsSpawned.RandomElement().Position; } // Infos for return message bool treasureFound = false; Pawn treasureCarrier = null; bool enemyPursuit = false; List <Thing> treasures = new List <Thing>(); // Calculate a value of the weapons taken with them. Result may reduce the spawn enemy chance float weaponPoints = 0f; for (int i = 0; i < PawnsOutOfMap.Count; i++) { Pawn weaponPawn = PawnsOutOfMap[i] as Pawn; if (weaponPawn == null || weaponPawn.Destroyed || weaponPawn.Spawned) { continue; } weaponPoints += CalcVerbValue(weaponPawn.TryGetAttackVerb(true)); // Result: between 5 and 25 } // spawn the returning pawns float remainingPoints = IncidentPoints; if (GenDate.YearsPassed >= 2) { remainingPoints = remainingPoints * GenDate.YearsPassed / 3; } IntVec3 spawnCell; Predicate <IntVec3> predicateSpawnCell = (IntVec3 c) => { if (!c.Standable() || !c.CanReachColony()) { return(false); } return(true); }; bool allowTreasure = Rand.RangeInclusive(1, 100) < this.def.treasureChance; if (!allowTreasure) { remainingPoints = 0; } for (int i = 0; i < PawnsOutOfMap.Count; i++) { Pawn retPawn = PawnsOutOfMap[i] as Pawn; if (retPawn == null || retPawn.Destroyed || retPawn.Spawned) { continue; } CellFinder.TryFindRandomReachableCellNear(ExitMapCell, 13, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false), predicateSpawnCell, null, out spawnCell); retPawn = GenSpawn.Spawn(retPawn, spawnCell) as Pawn; if (retPawn == null) { continue; } Thing treasure = null; //Create the treasure (as long as there are points remaining) and carry it back if (remainingPoints > 0) { treasure = TryGetTreasure(); } // Treasure found: Add treasure to pawn and bring it to return cell if (treasure != null) { treasure = GenSpawn.Spawn(treasure, retPawn.Position); treasure.SetForbidden(true); IntVec3 deliverCell = CellFinder.RandomClosewalkCellNear(ReturnToBaseCell, 6); Job job = new Job(JobDefOf.HaulToCell, treasure, deliverCell); job.maxNumToCarry = treasure.stackCount; job.haulMode = HaulMode.ToCellNonStorage; job.ignoreForbidden = true; retPawn.jobs.StartJob(job); remainingPoints -= (treasure.MarketValue * treasure.stackCount / 10); //Log.Error("Remaining Points: " + remainingPoints.ToString()); // Infos for return message if (!treasureFound) { treasureCarrier = retPawn; } treasures.Add(treasure); treasureFound = true; } // No treasure? go to return cell else { IntVec3 returnCell = CellFinder.RandomClosewalkCellNear(ReturnToBaseCell, 6); retPawn.jobs.StartJob(new Job(JobDefOf.Goto, returnCell)); } } // Add a new found pawn Pawn pawnFound = null; if (def.pawnFoundChance > 0) { bool pawnFoundSuccess = Rand.RangeInclusive(0, 100) <= def.pawnFoundChance; if (pawnFoundSuccess && def.pawnFoundDefs != null && def.pawnFoundDefs.Count > 0) { Faction faction1 = Find.FactionManager.FirstFactionOfDef(FactionDefOf.Outlander); pawnFound = PawnGenerator.GeneratePawn(def.pawnFoundDefs.RandomElement(), faction1); /// Test-Equipment //ThingWithComps t = ThingMaker.MakeThing(DefDatabase<ThingDef>.GetNamed("Gun_Pistol")) as ThingWithComps; //pawnFound.equipment.AddEquipment(t); if (!def.pawnWithEquipment) { List <ThingWithComps> equipment = new List <ThingWithComps>(); foreach (ThingWithComps eq in pawnFound.equipment.AllEquipment) { equipment.Add(eq); } for (int i = equipment.Count; i > 0; i--) { ThingWithComps eq = equipment[i - 1]; if (!eq.def.IsApparel) { pawnFound.equipment.DestroyEquipment(eq); } } } CellFinder.TryFindRandomReachableCellNear(ExitMapCell, 10, TraverseParms.For(TraverseMode.NoPassClosedDoors), predicateSpawnCell, null, out spawnCell); GenSpawn.Spawn(pawnFound, spawnCell); pawnFound.SetFaction(Faction.OfPlayer); } } // Maybe start enemy spawn counter float randomValue = (float)Rand.RangeInclusive(0, 100); // If the weapons are good enough, reduce the chance for enemies (value * 2) if (weaponPoints * 3 > IncidentPoints / 10 ? true : false) { randomValue *= 2; } if ((treasureFound && randomValue < def.enemySpawnChanceTreasure) || (!treasureFound && randomValue < def.enemySpawnChanceNoTreasure)) { // Start enemy spawn ticks enemyPursuit = TryExecuteRaid(); } // Do returned letter handling LetterType letterType = LetterType.Good; StringBuilder returnMessage = new StringBuilder(); returnMessage.AppendLine(def.LetterMessage_ReturnedBaseVariable.Translate()).AppendLine(); if (treasureFound) { returnMessage.AppendLine(def.LetterMessage_ReturnedWithTreasureVariable.Translate()).AppendLine(); StringBuilder treasureString = new StringBuilder(); for (int i = 0; i < treasures.Count; i++) { //if (i > 0) // treasureString.Append(", "); //treasureString.Append(treasures[i].LabelCap); treasureString.AppendLine(treasures[i].LabelCap); } returnMessage.AppendLine(treasureString.ToString()); } else { returnMessage.AppendLine(def.LetterMessage_ReturnedNoTreasureVariable.Translate()); } if (pawnFound != null) { string message = def.LetterMessage_ReturnedWithNewColonistVariable.Translate(); returnMessage.AppendLine(message.AdjustedFor(pawnFound)); } if (enemyPursuit) { //returnMessage.AppendLine(); returnMessage.Append(def.LetterMessage_ReturnedWithEnemyVariable.Translate()); letterType = LetterType.BadNonUrgent; } // Show letter Letter letter = new Letter(def.LetterLabel_ReturnedVariable.Translate(), returnMessage.ToString(), letterType, treasureCarrier); Find.LetterStack.ReceiveLetter(letter, null); // Add letter to history //Find.History.AddHistoryRecordFromLetter(letter, null); // Reset Incident PawnsOutOfMap.Clear(); returnTicks = -1; autoDeactivateTicks = -1; Active = false; // Load random new def for next start def = null; }
// Fill the cell private void TrySetCellAs(IntVec3 c, Map map, ThingDef thingDef, Rot4 thingRot, ThingDef stuffDef = null, TerrainDef terrainDef = null, PawnKindDef pawnKindDef = null, ThingDef itemDef = null, MapGeneratorBlueprintDef blueprint = null) { //Note: Here is no functionality to clear the cell by design, because it is possible to place items that are larger than 1x1 // Check the cell information if (c == null || !c.InBounds(map)) { Log.Warning("GenStep_CreateBlueprint: Invalid Target-Cell: cell is null or out of bounds."); return; } // only continue to do work if here isn't anything indestructable List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (!thingList[i].def.destroyable) { return; } } // 1st step - work with the Terrain if (terrainDef != null) { map.terrainGrid.SetTerrain(c, terrainDef); } else if (terrainDef == null && thingDef != null && stuffDef != null) { map.terrainGrid.SetTerrain(c, this.CorrespondingTileDef(stuffDef)); } // 2nd step - work with the Thing (Buildings) if (thingDef != null) { ThingDef stuffDef1 = stuffDef; if (!thingDef.MadeFromStuff) { stuffDef1 = null; } Thing newThing = ThingMaker.MakeThing(thingDef, stuffDef1); if (thingRot == null || thingRot == Rot4.Invalid) { GenSpawn.Spawn(newThing, c, map); } else { GenSpawn.Spawn(newThing, c, map, thingRot); } CompGatherSpot compGathering = newThing.TryGetComp <CompGatherSpot>(); if (compGathering != null) { compGathering.Active = false; } } // The following needs blueprint data to work if (blueprint == null) { return; } // 3rd step - work with the Item //if (itemDef != null) // && blueprint.itemSpawnChance / 100 > Rand.Value) if (itemDef != null && blueprint.itemSpawnChance / 100 > Rand.Value) { ThingDef stuffDef2; if (itemDef.IsApparel) { if (!DefDatabase <ThingDef> .AllDefs.Where <ThingDef>(t => t.IsStuff && t.stuffProps != null && t.stuffProps.categories != null && t.stuffProps.categories.Contains(StuffCategoryDefOf.Fabric)) .TryRandomElement(out stuffDef2)) { stuffDef2 = DefDatabase <ThingDef> .GetNamedSilentFail("Synthread"); } } else { List <string> stuffPossibles = new List <string>() { "Steel", "Steel", "Steel", "Steel", "Silver", "Gold", "Jade", "Plasteel" }; stuffDef2 = DefDatabase <ThingDef> .GetNamedSilentFail(stuffPossibles.RandomElement()); } if (!itemDef.MadeFromStuff) { stuffDef2 = null; } Thing newItem = TryGetTreasure(itemDef, stuffDef2); newItem = GenSpawn.Spawn(newItem, c, map); // Don't forget to set the items to forbidden! if (newItem.TryGetComp <CompForbiddable>() != null) { newItem.SetForbidden(true, false); } // If it is a hive, it needs to be deactivated Hive newHive = newItem as Hive; if (newHive != null) { newHive.active = false; } } // 4th step - work with the Pawn if (pawnKindDef != null && blueprint.pawnSpawnChance / 100 > Rand.Value) { if (this.faction == null) { this.faction = Find.FactionManager.FirstFactionOfDef(blueprint.factionDef); } float pointsForRaid = map.IncidentPointsRandomFactorRange.RandomInRange; // still null - find a valid faction. if (this.faction == null) { switch (blueprint.factionSelection) { case FactionSelection.friendly: faction = (from fac in Find.FactionManager.AllFactions where !fac.HostileTo(Faction.OfPlayer) && fac.PlayerGoodwill > 0 && !(fac == Faction.OfPlayer) select fac) .RandomElementByWeight((Faction fac) => 101 - fac.def.RaidCommonalityFromPoints(pointsForRaid)); if (faction == null) { faction = Find.FactionManager.AllFactions.RandomElementByWeight((Faction fac) => fac.def.RaidCommonalityFromPoints(pointsForRaid)); } break; case FactionSelection.hostile: faction = (from fac in Find.FactionManager.AllFactions where fac.HostileTo(Faction.OfPlayer) select fac) .RandomElementByWeight((Faction fac) => 101 - fac.def.RaidCommonalityFromPoints(pointsForRaid)); if (faction == null) { faction = Faction.OfMechanoids; } break; case FactionSelection.none: faction = Find.FactionManager.AllFactions .RandomElementByWeight((Faction fac) => fac.def.RaidCommonalityFromPoints(pointsForRaid)); if (faction == null) { faction = Faction.OfMechanoids; } break; } } Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, faction); pawn.mindState.Active = false; pawn = GenSpawn.Spawn(pawn, c, map) as Pawn; if (pawn != null) { if (allSpawnedPawns == null) { allSpawnedPawns = new List <Pawn>(); } allSpawnedPawns.Add(pawn); } } }
static void Postfix(ref CompGatherSpot spot) { Main.Instance?.LabelPlacementHandler?.SetDirty(); }
public static void RegisterDeactivated( CompGatherSpot spot ) { if( activeSpots.Contains(spot) ) activeSpots.Remove(spot); }
public static void RegisterActivated( CompGatherSpot spot ) { if( !activeSpots.Contains(spot) ) activeSpots.Add(spot); }