private static void DebugResetAllMobileUnits() { int resetCount = 0; List <WorldObject> woList = Find.WorldObjects.AllWorldObjects; if (woList != null && woList.Count > 0) { for (int i = 0; i < woList.Count; i++) { WarObject rwo = woList[i] as WarObject; if (rwo != null) { RimWarData rwd = WorldUtility.GetRimWarDataForFaction(rwo.Faction); if (rwd != null && rwd.WorldSettlements != null && rwd.WorldSettlements.Count > 0) { resetCount++; RimWorld.Planet.Settlement settlement = rwd.WorldSettlements.RandomElement(); if (settlement != null) { if (settlement.Destroyed) { Log.Warning("Detected destroyed settlement in Rim War data for " + rwd.RimWarFaction.Name); } else { RimWarSettlementComp rwsc = settlement.GetComponent <RimWarSettlementComp>(); if (rwsc != null) { rwsc.RimWarPoints += rwo.RimWarPoints; } else { Log.Warning("Found no Rim War component for settlement " + settlement.Label); Log.Warning("Settlement in faction " + settlement.Faction); Log.Warning("Settlement defname " + settlement.def.defName); } } } else { Log.Warning("Detected null settlement in Rim War data for " + rwd.RimWarFaction.Name); } if (!rwo.Destroyed) { rwo.Destroy(); } } else { Log.Warning("Tried to reset unit but no Faction data exists - cleaning up object."); if (!rwo.Destroyed) { rwo.Destroy(); } } } } Log.Message("Reset " + resetCount + " Rim War units."); } }
protected override bool TryExecuteWorker(IncidentParms parms) { parms.points *= IncidentPointsFactorRange.RandomInRange; Caravan caravan = (Caravan)parms.target; bool factionCanFight = WorldUtility.FactionCanFight((int)parms.points, parms.faction); //if (!PawnGroupMakerUtility.TryGetRandomFactionForCombatPawnGroup(parms.points, out parms.faction)) //{ // return false; //} List <ThingCount> demands = GenerateDemands(caravan); if (demands.NullOrEmpty() && parms.faction.HostileTo(caravan.Faction)) { return(false); } PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, parms); defaultPawnGroupMakerParms.generateFightersOnly = true; defaultPawnGroupMakerParms.dontUseSingleUseRocketLaunchers = true; List <Pawn> attackers = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms).ToList(); if (attackers.Count == 0) { Log.Error("Caravan demand incident couldn't generate any enemies even though min points have been checked. faction=" + defaultPawnGroupMakerParms.faction + "(" + ((defaultPawnGroupMakerParms.faction != null) ? defaultPawnGroupMakerParms.faction.def.ToString() : "null") + ") parms=" + parms); return(false); } CameraJumper.TryJumpAndSelect(caravan); DiaNode diaNode = new DiaNode(GenerateMessageText(parms.faction, attackers.Count, demands, caravan)); DiaOption diaOption = new DiaOption("CaravanDemand_Give".Translate()); diaOption.action = delegate { ActionGive(caravan, demands, attackers); wo.interactable = false; }; if (!wo.Faction.HostileTo(caravan.Faction)) { string str = "RW_CaravanDemand_GiveDisabled".Translate(wo.GetInspectString()); diaOption.SetText(str); diaOption.Disable(""); } diaOption.resolveTree = true; diaNode.options.Add(diaOption); string fightString = "CaravanDemand_Fight".Translate(); if (!wo.Faction.HostileTo(caravan.Faction)) { fightString = "RW_Attack_Verbatum".Translate(); } DiaOption diaOption2 = new DiaOption(fightString); diaOption2.action = delegate { ActionFight(caravan, attackers); wo.Destroy(); }; diaOption2.resolveTree = true; diaNode.options.Add(diaOption2); DiaOption diaOption3 = new DiaOption("CaravanMeeting_MoveOn".Translate()); diaOption3.action = delegate { ActionMoveOn(caravan, attackers); }; if (wo.Faction.HostileTo(caravan.Faction)) { diaOption3.Disable("CaravanMeeting_MoveOn".Translate()); } diaOption3.resolveTree = true; diaNode.options.Add(diaOption3); TaggedString taggedString = "CaravanDemandTitle".Translate(parms.faction.Name); Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, parms.faction, true, false, taggedString)); Find.Archive.Add(new ArchivedDialog(diaNode.text, taggedString, parms.faction)); return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { //if(this.wo != null) //{ // this.wo.interactable = false; //} if (parms.target is Map) { return(IncidentDefOf.TravelerGroup.Worker.TryExecute(parms)); } Caravan caravan = (Caravan)parms.target; Faction faction = parms.faction; bool factionCanTrade = WorldUtility.FactionCanTrade(parms.faction); //if (parms.faction != null && factionCanTrade) //{ // faction = parms.faction; //} //else //{ // return false; //} List <Pawn> list = GenerateCaravanPawns(faction, wo.RimWarPoints); if (!list.Any()) { Log.Error("IncidentWorker_CaravanMeeting could not generate any pawns."); return(false); } Caravan metCaravan = CaravanMaker.MakeCaravan(list, faction, -1, addToWorldPawnsIfNotAlready: false); bool hostileToPlayer = faction.HostileTo(Faction.OfPlayer); CameraJumper.TryJumpAndSelect(caravan); DiaNode diaNode = new DiaNode((string)"CaravanMeeting".Translate(caravan.Name, faction.Name, PawnUtility.PawnKindsToLineList(from x in metCaravan.PawnsListForReading select x.kindDef, " - ")).CapitalizeFirst()); Pawn bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan, faction, metCaravan.TraderKind); if (metCaravan.CanTradeNow) { DiaOption diaOption = new DiaOption("CaravanMeeting_Trade".Translate()); diaOption.action = delegate { Find.WindowStack.Add(new Dialog_Trade(bestPlayerNegotiator, metCaravan)); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(metCaravan.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithOtherCaravan".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent); }; if (bestPlayerNegotiator == null) { if (metCaravan.TraderKind.permitRequiredForTrading != null && !caravan.pawns.Any(delegate(Pawn p) { if (p.royalty != null) { return(p.royalty.HasPermit(metCaravan.TraderKind.permitRequiredForTrading, faction)); } return(false); })) { RoyalTitleDef royalTitleDef = faction.def.RoyalTitlesAwardableInSeniorityOrderForReading.First(delegate(RoyalTitleDef t) { if (t.permits != null) { return(t.permits.Contains(metCaravan.TraderKind.permitRequiredForTrading)); } return(false); }); diaOption.Disable("CaravanMeeting_NoPermit".Translate(royalTitleDef.GetLabelForBothGenders(), faction).Resolve()); } else if (hostileToPlayer) { diaOption.Disable("RW_CaravanMeeting_TradeUnwilling".Translate(faction.Name)); } else { diaOption.Disable("CaravanMeeting_TradeIncapable".Translate()); } } else if (!factionCanTrade) { diaOption.Disable("RW_CaravanMeeting_FactionIncapableOfTrade".Translate()); } diaNode.options.Add(diaOption); } DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate()); diaOption2.action = delegate { LongEventHandler.QueueLongEvent(delegate { Pawn t2 = caravan.PawnsListForReading[0]; faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, true, "GoodwillChangedReason_AttackedCaravan".Translate(), t2); Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedNonPlayerCaravan); map.Parent.SetFaction(faction); MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 playerSpot, out IntVec3 enemySpot); CaravanEnterMapUtility.Enter(caravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(playerSpot, map, 12), CaravanDropInventoryMode.DoNotDrop, draftColonists: true); List <Pawn> list2 = metCaravan.PawnsListForReading.ToList(); CaravanEnterMapUtility.Enter(metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12)); LordMaker.MakeNewLord(faction, new LordJob_DefendAttackedTraderCaravan(list2[0].Position), map, list2); Find.TickManager.Notify_GeneratedPotentiallyHostileMap(); CameraJumper.TryJumpAndSelect(t2); PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(list2, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, informEvenIfSeenBefore: true); wo.Destroy(); }, "GeneratingMapForNewEncounter", false, null);