// Main way to initialise a carnival in town public CarnivalInfo ReInitWith(Lord lord, IntVec3 spawnCentre) { // MUST BE CALLED AFTER LordMaker.MakeNewLord() Cleanup(); currentLord = lord; // Set radius for carnies to stick to baseRadius = lord.ownedPawns.Count + AddToRadius.RandomInRange; baseRadius = Mathf.Clamp(baseRadius, MinRadius, MaxRadius); // Calculate setup centre setupCentre = CarnCellFinder.BestCarnivalSetupPosition(spawnCentre, map); // Set initial check cells checkForCells.AddRange(GenRadial.RadialCellsAround(setupCentre, baseRadius, true) .Where(c => c.InBounds(map) && c.Walkable(map))); // Set carnival area carnivalArea = CellRect.CenteredOn(setupCentre, (int)baseRadius + 10).ClipInsideMap(map).ContractedBy(10); // Set initial banner spot bannerCell = CarnCellFinder.PreCalculateBannerCell(); // Cache pawn roles to lists var roles = Enum.GetValues(typeof(CarnivalRole)); for (int i = 0; i < roles.Length; i++) { var role = (CarnivalRole)roles.GetValue(i); List <Pawn> pawns = (from p in lord.ownedPawns where i == 0 ? p.IsOnly(role) : p.Is(role) select p).ToList(); if (role == CarnivalRole.Vendor) { // Will enable this when they are standing in stalls pawns.ForEach(p => p.mindState.wantsToTradeWithColony = false); } pawnsWithRole.Add(role, pawns); } daysPassed = GenDate.DaysPassed; // The rest is assigned as the carnival goes along return(this); }
protected List <Pawn> SpawnPawns(IncidentParms parms, int spawnPointSpread) { Map map = (Map)parms.target; if (parms.spawnRotation != Rot4.East) { if (Prefs.DevMode) { Log.Message("[Carnivale] Spawn centre for CarnivalArrives was not precomputed. Resolving now."); } IntVec3 tempSpot = parms.spawnCenter; if (CarnCellFinder.BestCarnivalSpawnSpot(map, out tempSpot)) { parms.spawnCenter = tempSpot; } else if (Prefs.DevMode) { Log.Warning("[Carnivale] Failed to resolve spawn center for CarnivalArrives. Defaulting."); } int feePerColonist = CarnUtils.CalculateFeePerColonist(parms.points); CarnUtils.Info.feePerColonist = -feePerColonist; } PawnGroupMakerParms defaultMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms); List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(this.PawnGroupKindDef, defaultMakerParms, false).ToList(); foreach (Pawn p in list) { IntVec3 spawnPoint = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, spawnPointSpread, null); GenSpawn.Spawn(p, spawnPoint, map); } parms.faction.leader.skills.GetSkill(SkillDefOf.Shooting).levelInt = 9; return(list); }
public override bool TryExecute(IncidentParms parms) { Map map = (Map)parms.target; IntVec3 spawnSpot; int durationDays = Mathf.RoundToInt(this.def.durationDays.RandomInRange); if (Prefs.DevMode) { Log.Message("[Carnivale] Calculating spawn centre:"); } if (!CarnCellFinder.BestCarnivalSpawnSpot(map, out spawnSpot)) { if (Prefs.DevMode) { Log.Warning("[Carnivale] Tried to execute incident CarnivalApproaches, failed to find reachable spawn spot."); } return(false); } if (!FindCarnivalFaction(out parms.faction)) { if (Prefs.DevMode) { Log.Warning("[Carnivale] Tried to execute incident CarnivalApproaches, failed to find valid faction."); } return(false); } // Calculate fe int feePerColonist = CarnUtils.CalculateFeePerColonist(parms.points); // Main dialog node string title = "CarnivalApproachesTitle".Translate(parms.faction.Name); DiaNode initialNode = new DiaNode("CarnivalApproachesInitial".Translate(new object[] { parms.faction.Name, durationDays, feePerColonist + " " + ThingDefOf.Silver.label, map.info.parent.Label == "Colony" ? "your colony" : map.info.parent.Label })); // Accept button DiaOption acceptOption = new DiaOption("CarnivalApproachesAccept".Translate()); acceptOption.action = delegate { // Do accept action parms.faction.AffectGoodwillWith(Faction.OfPlayer, acceptanceBonus); IncidentParms arrivalParms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, IncidentCategory.AllyArrival, map); //arrivalParms.forced = true; // forcing not necessary arrivalParms.faction = parms.faction; arrivalParms.spawnCenter = spawnSpot; arrivalParms.points = parms.points; // Do this? // This is so it can be determined that the spawnpoint was precomputed. Rot4 sneakyValueForSpawnpointResolved = Rot4.East; arrivalParms.spawnRotation = sneakyValueForSpawnpointResolved; // This is super cheaty, but there is no other field to pass this to. arrivalParms.raidPodOpenDelay = durationDays; // End cheaty. // Assign fee per colonist to CarnivalInfo CarnUtils.Info.feePerColonist = -feePerColonist; QueuedIncident qi = new QueuedIncident(new FiringIncident(_DefOf.CarnivalArrives, null, arrivalParms), Find.TickManager.TicksGame + GenDate.TicksPerDay); Find.Storyteller.incidentQueue.Add(qi); }; initialNode.options.Add(acceptOption); // Accept thank you message DiaNode acceptedMessage = new DiaNode("CarnivalApproachesAcceptMessage".Translate(new object[] { parms.faction.leader.Name.ToStringFull })); DiaOption ok = new DiaOption("OK".Translate()); ok.resolveTree = true; acceptedMessage.options.Add(ok); acceptOption.link = acceptedMessage; // Reject button DiaOption rejectOption = new DiaOption("CarnivalApproachesReject".Translate()); rejectOption.action = delegate { // Do reject action parms.faction.AffectGoodwillWith(Faction.OfPlayer, rejectionPenalty); }; initialNode.options.Add(rejectOption); // Reject f**k you message (TODO: randomise response) DiaNode rejectedMessage = new DiaNode("CarnivalApproachesRejectMessage".Translate(new object[] { parms.faction.leader.Name.ToStringShort })); DiaOption hangup = new DiaOption("HangUp".Translate()); hangup.resolveTree = true; rejectedMessage.options.Add(hangup); rejectOption.link = rejectedMessage; // Draw dialog Find.WindowStack.Add(new Dialog_NodeTree(initialNode, true, true, title)); return(true); }