public void DrawProductionHeader(int x, int y) { FactionFC faction = Find.World.GetComponent <FactionFC>(); double egalitarianTaxBoost = 0; if (faction.hasPolicy(FCPolicyDefOf.egalitarian)) { egalitarianTaxBoost = Math.Floor(settlement.happiness / 10); if (settlement.trait_Egalitarian_TaxBreak_Enabled) { egalitarianTaxBoost -= 30; } } double isolationistTaxBoost = 0; if (faction.hasPolicy(FCPolicyDefOf.isolationist)) { isolationistTaxBoost = 10; } Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(new Rect(x, y, 400, 30), "Production".Translate()); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(new Rect(x + 5, y + 60, 150, 20), "TaxBase".Translate() + ": " + (((100 + egalitarianTaxBoost + isolationistTaxBoost) + TraitUtilsFC.cycleTraits("taxBasePercentage", settlement.traits, Operation.Addition) + TraitUtilsFC.cycleTraits("taxBasePercentage", Find.World.GetComponent <FactionFC>().traits, Operation.Addition))).ToString() + "%"); }
private void CalculateSettlementCreationCost() { settlementCreationCost = SettlementCreationBaseCost; if (faction.hasPolicy(FCPolicyDefOf.isolationist)) { settlementCreationCost *= 2; } if (!faction.hasPolicy(FCPolicyDefOf.expansionist)) { return; } if (!faction.settlements.Any() && !faction.settlementCaravansList.Any()) { traitExpansionistReducedFee = false; settlementCreationCost = 0; return; } if (faction.traitExpansionistTickLastUsedSettlementFeeReduction == -1 || (faction.traitExpansionistBoolCanUseSettlementFeeReduction)) { traitExpansionistReducedFee = true; settlementCreationCost /= 2; return; } traitExpansionistReducedFee = false; }
public static militaryForce createMilitaryForceFromSettlement(SettlementFC settlement, bool isAttacking = false, militaryForce homeDefendingForce = null) { FactionFC faction = Find.World.GetComponent <FactionFC>(); int militaryLevelBonus = 0; if (faction.hasTrait(FCPolicyDefOf.defenseInDepth) && isAttacking == false) { militaryLevelBonus += 2; } double homeForceLevel = 0; if (homeDefendingForce != null) { homeForceLevel = homeDefendingForce.militaryLevel; } double militaryLevel = settlement.settlementMilitaryLevel + militaryLevelBonus + homeForceLevel; double efficiency = TraitUtilsFC.cycleTraits("militaryMultiplierCombatEfficiency", faction.traits, Operation.Multiplication) * TraitUtilsFC.cycleTraits("militaryMultiplierCombatEfficiency", settlement.traits, Operation.Multiplication); if (isAttacking && faction.hasPolicy(FCPolicyDefOf.militaristic)) { efficiency *= 1.2; } militaryForce returnForce = new militaryForce(militaryLevel, efficiency, settlement, FactionColonies.getPlayerColonyFaction()); return(returnForce); //create and return force. }
static bool Prefix(ref Faction __instance, Pawn member, DamageInfo?dinfo, bool wasWorldPawn, Map map) { if (member.Faction.def.defName == "PColony" && !wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && map != null && map.IsPlayerHome && !__instance.HostileTo(Faction.OfPlayer)) { FactionFC faction = Find.World.GetComponent <FactionFC>(); if (!faction.hasPolicy(FCPolicyDefOf.pacifist) && dinfo != null) { if (dinfo.Value.Category == DamageInfo.SourceCategory.Collapse) { faction.GainUnrestForReason(new Message("DeathOfFactionPawn".Translate(), MessageTypeDefOf.PawnDeath), 5d); faction.GainHappiness(-5d); } else if (dinfo.Value.Instigator?.Faction == Find.FactionManager.OfPlayer) { faction.GainUnrestForReason(new Message("DeathOfFactionPawn".Translate(), MessageTypeDefOf.PawnDeath), 5d); faction.GainHappiness(-5d); } } //return false to stop from continuing method return(false); } return(true); }
public override void DrawTab(Rect rect) { Rect SettlementBox = new Rect(5, 45, 535, settlementHeight); Rect SettlementName = new Rect(SettlementBox.x + 5, SettlementBox.y + 5, 250, 25); Rect MilitaryLevel = new Rect(SettlementName.x, SettlementName.y + 30, 250, 25); Rect AssignedSquad = new Rect(MilitaryLevel.x, MilitaryLevel.y + 30, 250, 25); Rect isBusy = new Rect(AssignedSquad.x, AssignedSquad.y + 30, 250, 25); Rect buttonSetSquad = new Rect(SettlementBox.x + SettlementBox.width - 265, SettlementBox.y + 5, 100, 25); Rect buttonViewSquad = new Rect(buttonSetSquad.x, buttonSetSquad.y + 3 + buttonSetSquad.height, buttonSetSquad.width, buttonSetSquad.height); Rect buttonDeploySquad = new Rect(buttonViewSquad.x, buttonViewSquad.y + 3 + buttonViewSquad.height, buttonSetSquad.width, buttonSetSquad.height); Rect buttonResetPawns = new Rect(buttonDeploySquad.x, buttonDeploySquad.y + 3 + buttonDeploySquad.height, buttonSetSquad.width, buttonSetSquad.height); Rect buttonOrderFireSupport = new Rect(buttonSetSquad.x + 125 + 5, SettlementBox.y + 5, 125, 25); //set text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; int count = 0; foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements) { Text.Font = GameFont.Small; Widgets.DrawMenuSection(new Rect(SettlementBox.x, SettlementBox.y + (SettlementBox.height + settlementYSpacing) * count + scroll, SettlementBox.width, SettlementBox.height)); //click on settlement name if (Widgets.ButtonTextSubtle( new Rect(SettlementName.x, SettlementName.y + (SettlementBox.height + settlementYSpacing) * count + scroll, SettlementName.width, SettlementName.height), settlement.name)) { Find.WindowStack.Add(new SettlementWindowFc(settlement)); } Widgets.Label( new Rect(MilitaryLevel.x, MilitaryLevel.y + (SettlementBox.height + settlementYSpacing) * count + scroll, MilitaryLevel.width, MilitaryLevel.height * 2), "Mil Level: " + settlement.settlementMilitaryLevel + " - Max Squad Cost: " + FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel)); if (settlement.militarySquad != null) { if (settlement.militarySquad.outfit != null) { Widgets.Label( new Rect(AssignedSquad.x, AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, AssignedSquad.width, AssignedSquad.height), "Assigned Squad: " + settlement.militarySquad.outfit.name); //settlement.militarySquad.name); } else { Widgets.Label( new Rect(AssignedSquad.x, AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, AssignedSquad.width, AssignedSquad.height), "No assigned Squad"); //settlement.militarySquad.name); } } else { Widgets.Label( new Rect(AssignedSquad.x, AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, AssignedSquad.width, AssignedSquad.height), "No assigned Squad"); } Widgets.Label( new Rect(isBusy.x, isBusy.y + (SettlementBox.height + settlementYSpacing) * count + scroll, isBusy.width, isBusy.height), "Available: " + (!settlement.isMilitaryBusySilent())); Text.Font = GameFont.Tiny; //Set Squad Button if (Widgets.ButtonText( new Rect(buttonSetSquad.x, buttonSetSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonSetSquad.width, buttonSetSquad.height), "Set Squad")) { //check null if (util.squads == null) { util.resetSquads(); } List <FloatMenuOption> squads = new List <FloatMenuOption>(); squads.AddRange(util.squads .Select(squad => new FloatMenuOption(squad.name + " - Total Equipment Cost: " + squad.equipmentTotalCost, delegate { //Unit is selected util.attemptToAssignSquad(settlement, squad); }))); if (!squads.Any()) { squads.Add(new FloatMenuOption("No Available Squads", null)); } FloatMenu selection = new FloatMenuSearchable(squads); Find.WindowStack.Add(selection); } //View Squad if (Widgets.ButtonText( new Rect(buttonViewSquad.x, buttonViewSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonViewSquad.width, buttonViewSquad.height), "View Squad")) { Messages.Message("This is currently not implemented.", MessageTypeDefOf.RejectInput); } //Deploy Squad if (Widgets.ButtonText( new Rect(buttonDeploySquad.x, buttonDeploySquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonDeploySquad.width, buttonDeploySquad.height), "Deploy Squad")) { if (!(settlement.isMilitaryBusy()) && settlement.isMilitarySquadValid()) { Find.WindowStack.Add(new FloatMenu(DeploymentOptions(settlement))); } else if (settlement.isMilitaryBusy() && settlement.isMilitarySquadValid() && faction.hasPolicy(FCPolicyDefOf.militaristic)) { if ((faction.traitMilitaristicTickLastUsedExtraSquad + GenDate.TicksPerDay * 5) <= Find.TickManager.TicksGame) { int cost = (int)Math.Round(settlement.militarySquad.outfit.updateEquipmentTotalCost() * .2); List <FloatMenuOption> options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("Deploy Secondary Squad - $" + cost + " silver", delegate { if (PaymentUtil.getSilver() >= cost) { List <FloatMenuOption> deploymentOptions = new List <FloatMenuOption>(); deploymentOptions.Add(new FloatMenuOption("Walk into map", delegate { FactionColonies.CallinAlliedForces(settlement, false, cost); Find.WindowStack.currentlyDrawnWindow.Close(); })); //check if medieval only bool medievalOnly = LoadedModManager.GetMod <FactionColoniesMod>() .GetSettings <FactionColonies>().medievalTechOnly; if (!medievalOnly && (DefDatabase <ResearchProjectDef> .GetNamed("TransportPod", false)?.IsFinished ?? false)) { deploymentOptions.Add(new FloatMenuOption("Drop-Pod", delegate { FactionColonies.CallinAlliedForces(settlement, true, cost); Find.WindowStack.currentlyDrawnWindow.Close(); })); } Find.WindowStack.Add(new FloatMenu(deploymentOptions)); } else { Messages.Message("NotEnoughSilverToDeploySquad".Translate(), MessageTypeDefOf.RejectInput); } })); Find.WindowStack.Add(new FloatMenu(options)); } else { Messages.Message( "XDaysToRedeploy".Translate(Math.Round( ((faction.traitMilitaristicTickLastUsedExtraSquad + GenDate.TicksPerDay * 5) - Find.TickManager.TicksGame).TicksToDays(), 1)), MessageTypeDefOf.RejectInput); } } } //Reset Squad if (Widgets.ButtonText( new Rect(buttonResetPawns.x, buttonResetPawns.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonResetPawns.width, buttonResetPawns.height), "Reset Pawns")) { FloatMenuOption confirm = new FloatMenuOption("Are you sure? Click to confirm", delegate { if (settlement.militarySquad != null) { Messages.Message("Pawns have been regenerated for the squad", MessageTypeDefOf.NeutralEvent); settlement.militarySquad.initiateSquad(); } else { Messages.Message("There is no pawns to reset. Assign a squad first.", MessageTypeDefOf.RejectInput); } }); List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(confirm); Find.WindowStack.Add(new FloatMenu(list)); } //Order Fire Support if (Widgets.ButtonText( new Rect(buttonOrderFireSupport.x, buttonOrderFireSupport.y + (SettlementBox.height + settlementYSpacing) * count + scroll, buttonOrderFireSupport.width, buttonOrderFireSupport.height), "Order Fire Support")) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (MilitaryFireSupport support in util.fireSupportDefs) { float cost = support.returnTotalCost(); FloatMenuOption option = new FloatMenuOption(support.name + " - $" + cost, delegate { if (support.returnTotalCost() <= FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel)) { if (settlement.buildings.Contains(BuildingFCDefOf.artilleryOutpost)) { if (settlement.artilleryTimer <= Find.TickManager.TicksGame) { if (PaymentUtil.getSilver() >= cost) { FactionColonies.FireSupport(settlement, support); Find.WindowStack.TryRemove(typeof(MilitaryCustomizationWindowFc)); } else { Messages.Message( "You lack the required amount of silver to use that firesupport option!", MessageTypeDefOf.RejectInput); } } else { Messages.Message( "That firesupport option is on cooldown for another " + (settlement.artilleryTimer - Find.TickManager.TicksGame) .ToStringTicksToDays(), MessageTypeDefOf.RejectInput); } } else { Messages.Message( "The settlement requires an artillery outpost to be built to use that firesupport option", MessageTypeDefOf.RejectInput); } } else { Messages.Message( "The settlement requires a higher military level to use that fire support!", MessageTypeDefOf.RejectInput); } }); list.Add(option); } if (!list.Any()) { list.Add(new FloatMenuOption("No fire supports currently made. Make one", delegate { })); } FloatMenu menu = new FloatMenuSearchable(list); Find.WindowStack.Add(menu); } count++; } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y, settlementMaxScroll); } }
public void DrawButtons(int x, int y, int length, int size, int set) { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Tiny; if (set == 1) { for (int i = 0; i < buttons.Count(); i++) { if (Widgets.ButtonText(new Rect(x, y + ((size + 10) * i), length, size), buttons[i])) { //If click a button button if (buttons[i] == "UpgradeTown".Translate()) { //if click upgrade town button Find.WindowStack.Add(new SettlementUpgradeWindowFc(settlement)); //Log.Message(buttons[i]); } if (buttons[i] == "AreYouSureRemove".Translate()) { //if click to delete colony Find.WindowStack.TryRemove(this); FactionColonies.removePlayerSettlement(settlement); } if (buttons[i] == "DeleteSettlement".Translate()) { //if click town log button //Log.Message(buttons[i]); buttons[i] = "AreYouSureRemove".Translate(); } if (buttons[i] == "FCSpecialActions".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption> { //Add to all new FloatMenuOption("GoToLocation".Translate(), delegate { Find.WindowStack.TryRemove(this); settlement.goTo(); }) }; if (factionfc.hasPolicy(FCPolicyDefOf.authoritarian)) { list.Add(new FloatMenuOption("FCBuyLoyalty".Translate(), delegate { Find.WindowStack.Add(new FCWindow_Pay_Silver(settlement)); })); } if (factionfc.hasPolicy(FCPolicyDefOf.egalitarian)) { list.Add(new FloatMenuOption("FCGiveTaxBreak".Translate(), delegate { if (settlement.trait_Egalitarian_TaxBreak_Enabled == false) { Find.WindowStack.Add(new FCWindow_Confirm_TaxBreak(settlement)); } else { Messages.Message( "FCAlreadyGivingTaxBreak".Translate(Math.Round( (settlement.trait_Egalitarian_TaxBreak_Tick + GenDate.TicksPerDay * 10 - Find.TickManager.TicksGame) / (double)GenDate.TicksPerDay, 1)), MessageTypeDefOf.RejectInput); } })); } if (list.Count() == 0) { list.Add(new FloatMenuOption("No special actions to take", delegate { })); } Find.WindowStack.Add(new FloatMenu(list)); } if (buttons[i] == "PrisonersMenu".Translate()) { Find.WindowStack.Add(new FCPrisonerMenu(settlement)); } if (buttons[i] == "Military".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption> { new FloatMenuOption( "ToggleAutoDefend".Translate(settlement.autoDefend.ToString()), delegate { settlement.autoDefend = !settlement.autoDefend; Messages.Message("autoDefendWarning".Translate(), MessageTypeDefOf.CautionInput); }) }; if (settlement.isUnderAttack) { FCEvent evt = MilitaryUtilFC.returnMilitaryEventByLocation(settlement.mapLocation); list.Add(new FloatMenuOption( "SettlementDefendingInformation".Translate( evt.militaryForceDefending.homeSettlement.name, evt.militaryForceDefending.militaryLevel), null, MenuOptionPriority.High)); list.Add(new FloatMenuOption("ChangeDefendingForce".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); SettlementFC homeSettlement = settlement; settlementList.Add(new FloatMenuOption( "ResetToHomeSettlement".Translate(homeSettlement.settlementMilitaryLevel), delegate { MilitaryUtilFC.changeDefendingMilitaryForce(evt, homeSettlement); }, MenuOptionPriority.High)); foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements ) { if (settlement.isMilitaryValid() && settlement != homeSettlement) { //if military is valid to use. settlementList.Add(new FloatMenuOption( settlement.name + " " + "ShortMilitary".Translate() + " " + settlement.settlementMilitaryLevel + " - " + "FCAvailable".Translate() + ": " + (!settlement.isMilitaryBusySilent()).ToString(), delegate { if (settlement.isMilitaryBusy()) { //military is busy } else { MilitaryUtilFC.changeDefendingMilitaryForce(evt, settlement); } } )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("NoValidMilitaries".Translate(), null)); } Find.WindowStack.Add(new FloatMenuSearchable(settlementList) { vanishIfMouseDistant = true }); //set to raid settlement here })); Find.WindowStack.Add(new FloatMenu(list)); } else { list.Add(new FloatMenuOption("SettlementNotBeingAttacked".Translate(), null)); Find.WindowStack.Add(new FloatMenu(list)); } } } } } //set two buttons }
private void DrawFactionButtons(Rect inRect, int buttonSize) //Used to draw a list of buttons from the 'buttons' list { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Small; for (int i = 0; i < buttons.Count; i++) { if (Widgets.ButtonText(new Rect(140, 110 + ((buttonSize + 5) * i), 170, buttonSize), buttons[i])) { if (buttons[i] == "FCOverview".Translate()) { //if click trade policy button //Log.Message(buttons[i]); Log.Message("Success"); Find.WindowStack.Add(new FCWindow_Overview()); } if (buttons[i] == "Military".Translate()) { if (FactionColonies.getPlayerColonyFaction() == null) { Messages.Message(new Message("NoFactionForMilitary".Translate(), MessageTypeDefOf.RejectInput)); } else { Find.WindowStack.Add(new MilitaryCustomizationWindowFc()); } } if (buttons[i] == "Actions".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("TaxDeliveryMap".Translate(), delegate { List <FloatMenuOption> list2 = new List <FloatMenuOption>(); list2.Add(new FloatMenuOption("SetMap".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { settlementList.Add(new FloatMenuOption(map.Parent.LabelCap, delegate { faction.taxMap = map; Find.LetterStack.ReceiveLetter("Map Set!", "The tax delivery map has been set to the player colony of " + map.Parent.LabelCap + ".\n All taxes and other goods will be delivered there", LetterDefOf.NeutralEvent); } )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("No valid settlements to use.", null)); } FloatMenu floatMenu2 = new FloatMenu(settlementList); floatMenu2.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu2); })); FloatMenu floatMenu = new FloatMenu(list2); floatMenu.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu); })); list.Add(new FloatMenuOption("SetCapital".Translate(), delegate { faction.setCapital(); })); list.Add(new FloatMenuOption("ActivateResearch".Translate(), delegate { faction.updateDailyResearch(); })); list.Add(new FloatMenuOption("ResearchLevel".Translate(), delegate { Messages.Message("CurrentResearchLevel".Translate(faction.techLevel.ToString(), faction.returnNextTechToLevel()), MessageTypeDefOf.NeutralEvent); })); if (faction.hasPolicy(FCPolicyDefOf.technocratic)) { list.Add(new FloatMenuOption("FCSendResearchItems".Translate(), delegate { if (Find.ColonistBar.GetColonistsInOrder().Count > 0) { Pawn playerNegotiator = Find.ColonistBar.GetColonistsInOrder()[0]; //Log.Message(playerNegotiator.Name + " Negotiator"); FCTrader_Research trader = new FCTrader_Research(); Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, trader)); } else { Log.Message("Where are all the colonists?"); } })); } if (faction.hasPolicy(FCPolicyDefOf.feudal)) { list.Add(new FloatMenuOption("FCRequestMercenary".Translate(), delegate { if (faction.traitFeudalBoolCanUseMercenary) { faction.traitFeudalBoolCanUseMercenary = false; faction.traitFeudalTickLastUsedMercenary = Find.TickManager.TicksGame; PawnGenerationRequest request = FCPawnGenerator.WorkerOrMilitaryRequest; request.ColonistRelationChanceFactor = 20f; Pawn pawn = PawnGenerator.GeneratePawn(request); IncidentParms parms = new IncidentParms { target = Find.CurrentMap, faction = FactionColonies.getPlayerColonyFaction(), points = 999, raidArrivalModeForQuickMilitaryAid = true, raidNeverFleeIndividual = true, raidForceOneIncap = true, raidArrivalMode = PawnsArrivalModeDefOf.CenterDrop, raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly }; parms.raidArrivalModeForQuickMilitaryAid = true; PawnsArrivalModeWorker_EdgeWalkIn worker = new PawnsArrivalModeWorker_EdgeWalkIn(); worker.TryResolveRaidSpawnCenter(parms); worker.Arrive(new List <Pawn> { pawn }, parms); Find.LetterStack.ReceiveLetter("FCMercenaryJoined".Translate(), "FCMercenaryJoinedText".Translate(pawn.NameFullColored), LetterDefOf.PositiveEvent, new LookTargets(pawn)); pawn.SetFaction(Faction.OfPlayer); } else { Messages.Message("FCActionMercenaryOnCooldown".Translate(((faction.traitFeudalTickLastUsedMercenary + GenDate.TicksPerSeason) - Find.TickManager.TicksGame).ToTimeString()), MessageTypeDefOf.RejectInput); } })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } } } }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Buildings for (int i = 0; i < buildingList.Count; i++) { BuildingFCDef building = buildingList[i]; newBuildingWindow = new Rect(BaseBuildingWindow.x, BaseBuildingWindow.y + (i * (rowHeight)) + scroll, BaseBuildingWindow.width, BaseBuildingWindow.height); newBuildingIcon = new Rect(BaseBuildingIcon.x, BaseBuildingIcon.y + (i * (rowHeight)) + scroll, BaseBuildingIcon.width, BaseBuildingIcon.height); newBuildingLabel = new Rect(BaseBuildingLabel.x, BaseBuildingLabel.y + (i * (rowHeight)) + scroll, BaseBuildingLabel.width, BaseBuildingLabel.height); newBuildingDesc = new Rect(BaseBuildingDesc.x, BaseBuildingDesc.y + (i * (rowHeight)) + scroll, BaseBuildingDesc.width, BaseBuildingDesc.height); if (Widgets.ButtonInvisible(newBuildingWindow)) { //If click on building List <FloatMenuOption> list = new List <FloatMenuOption>(); if (building == buildingDef) { //if the same building list.Add(new FloatMenuOption("Destroy".Translate(), delegate { settlement.deconstructBuilding(buildingSlot); Find.WindowStack.TryRemove(this); Find.WindowStack.WindowOfType <SettlementWindowFc>().windowUpdateFc(); })); } else { //if not the same building list.Add(new FloatMenuOption("Build".Translate(), delegate { if (!settlement.validConstructBuilding(building, buildingSlot, settlement)) { return; } FCEvent tmpEvt = new FCEvent(true) { def = FCEventDefOf.constructBuilding, source = settlement.mapLocation, planetName = settlement.planetName, building = building, buildingSlot = buildingSlot }; int triggerTime = building.constructionDuration; if (factionfc.hasPolicy(FCPolicyDefOf.isolationist)) { triggerTime /= 2; } tmpEvt.timeTillTrigger = Find.TickManager.TicksGame + triggerTime; Find.World.GetComponent <FactionFC>().addEvent(tmpEvt); PaymentUtil.paySilver(Convert.ToInt32(building.cost)); settlement.deconstructBuilding(buildingSlot); Messages.Message(building.label + " " + "WillBeConstructedIn".Translate() + " " + (tmpEvt.timeTillTrigger - Find.TickManager.TicksGame).ToTimeString(), MessageTypeDefOf.PositiveEvent); settlement.buildings[buildingSlot] = BuildingFCDefOf.Construction; Find.WindowStack.TryRemove(this); Find.WindowStack.WindowOfType <SettlementWindowFc>().windowUpdateFc(); })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } Widgets.DrawMenuSection(newBuildingWindow); Widgets.DrawMenuSection(newBuildingIcon); Widgets.DrawLightHighlight(newBuildingIcon); Widgets.ButtonImage(newBuildingIcon, building.Icon); Text.Font = GameFont.Small; Widgets.ButtonTextSubtle(newBuildingLabel, ""); Widgets.Label(newBuildingLabel, " " + building.LabelCap + " - " + "Cost".Translate() + ": " + building.cost); Text.Font = GameFont.Tiny; Widgets.Label(newBuildingDesc, building.desc); } //Top Window Widgets.DrawMenuSection(TopWindow); Widgets.DrawHighlight(TopWindow); Widgets.DrawMenuSection(TopIcon); Widgets.DrawLightHighlight(TopIcon); Widgets.DrawBox(new Rect(0, 0, 400, 500)); Widgets.ButtonImage(TopIcon, buildingDef.Icon); Widgets.ButtonTextSubtle(TopName, ""); Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.UpperLeft; Widgets.Label(new Rect(TopName.x + 5, TopName.y, TopName.width, TopName.height), buildingDef.LabelCap); Widgets.DrawMenuSection(new Rect(TopDescription.x - 5, TopDescription.y - 5, TopDescription.width, TopDescription.height)); Text.Font = GameFont.Small; Widgets.Label(TopDescription, buildingDef.desc); Widgets.DrawLineHorizontal(0, TopWindow.y + TopWindow.height, 400); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; if (Event.current.type == EventType.ScrollWheel) { scrollWindow(Event.current.delta.y); } }
//Drawing public override void DoWindowContents(Rect inRect) { FactionFC faction = Find.World.GetComponent <FactionFC>(); faction.roadBuilder.DrawPaths(); if (Find.WorldSelector.selectedTile != -1 && Find.WorldSelector.selectedTile != currentTileSelected) { currentTileSelected = Find.WorldSelector.selectedTile; //Log.Message("Current: " + currentTileSelected + ", Selected: " + Find.WorldSelector.selectedTile); currentBiomeSelected = DefDatabase <BiomeResourceDef> .GetNamed( Find.WorldGrid.tiles[currentTileSelected].biome.ToString(), false); //default biome if (currentBiomeSelected == default(BiomeResourceDef)) { //Log Modded Biome currentBiomeSelected = BiomeResourceDefOf.defaultBiome; } currentHillinessSelected = DefDatabase <BiomeResourceDef> .GetNamed( Find.WorldGrid.tiles[currentTileSelected].hilliness.ToString()); if (currentBiomeSelected.canSettle && currentHillinessSelected.canSettle && currentTileSelected != 1) { timeToTravel = FactionColonies.ReturnTicksToArrive( Find.World.GetComponent <FactionFC>().capitalLocation, currentTileSelected); } else { timeToTravel = 0; } } //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; int silverToCreateSettlement = (int)(TraitUtilsFC.cycleTraits(new double(), "createSettlementMultiplier", Find.World.GetComponent <FactionFC>().traits, "multiply") * (FactionColonies.silverToCreateSettlement + (500 * (Find.World.GetComponent <FactionFC>().settlements.Count() + Find.World.GetComponent <FactionFC>().settlementCaravansList.Count())) + (TraitUtilsFC.cycleTraits(new double(), "createSettlementBaseCost", Find.World.GetComponent <FactionFC>().traits, "add")))); if (faction.hasPolicy(FCPolicyDefOf.isolationist)) { silverToCreateSettlement *= 2; } if (faction.hasPolicy(FCPolicyDefOf.expansionist)) { if (!faction.settlements.Any() && !faction.settlementCaravansList.Any()) { traitExpansionistReducedFee = false; silverToCreateSettlement = 0; } else { if (faction.traitExpansionistTickLastUsedSettlementFeeReduction == -1 || (faction.traitExpansionistBoolCanUseSettlementFeeReduction)) { traitExpansionistReducedFee = true; silverToCreateSettlement /= 2; } else { traitExpansionistReducedFee = false; } } } //Draw Label Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 0, 268, 40), "SettleANewColony".Translate()); //hori line Widgets.DrawLineHorizontal(0, 40, 300); //Upper menu Widgets.DrawMenuSection(new Rect(5, 45, 258, 220)); DrawLabelBox(10, 50, 100, 100, "TravelTime".Translate(), timeToTravel.ToStringTicksToDays()); DrawLabelBox(153, 50, 100, 100, "InitialCost".Translate(), silverToCreateSettlement + " " + "Silver".Translate()); //Lower Menu label Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 270, 268, 40), "BaseProductionStats".Translate()); //Lower menu Widgets.DrawMenuSection(new Rect(5, 310, 258, 220)); //Draw production Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; //Production headers Widgets.Label(new Rect(40, 310, 60, 25), "Base".Translate()); Widgets.Label(new Rect(110, 310, 60, 25), "Modifier".Translate()); Widgets.Label(new Rect(180, 310, 60, 25), "Final".Translate()); if (currentTileSelected != -1) { foreach (ResourceType titheType in ResourceUtils.resourceTypes) { int height = 15; if (Widgets.ButtonImage(new Rect(20, 335 + (int)titheType * (5 + height), height, height), faction.returnResource(titheType).getIcon())) { Find.WindowStack.Add(new DescWindowFc("SettlementProductionOf".Translate() + ": " + faction.returnResource(titheType).label, char.ToUpper(faction.returnResource(titheType).label[0]) + faction.returnResource(titheType).label.Substring(1))); } Widgets.Label(new Rect(40, 335 + (int)titheType * (5 + height), 60, height + 2), (currentBiomeSelected.BaseProductionAdditive[(int)titheType] + currentHillinessSelected.BaseProductionAdditive[(int)titheType]).ToString()); Widgets.Label(new Rect(110, 335 + (int)titheType * (5 + height), 60, height + 2), (currentBiomeSelected.BaseProductionMultiplicative[(int)titheType] * currentHillinessSelected.BaseProductionMultiplicative[(int)titheType]).ToString()); Widgets.Label(new Rect(180, 335 + (int)titheType * (5 + height), 60, height + 2), ((currentBiomeSelected.BaseProductionAdditive[(int)titheType] + currentHillinessSelected.BaseProductionAdditive[(int)titheType]) * (currentBiomeSelected.BaseProductionMultiplicative[(int)titheType] * currentHillinessSelected.BaseProductionMultiplicative[(int)titheType])).ToString()); } } //Settle button Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; int buttonLength = 130; if (Widgets.ButtonText(new Rect((InitialSize.x - 32 - buttonLength) / 2f, 535, buttonLength, 32), "Settle".Translate() + ": (" + silverToCreateSettlement + ")")) //add inital cost { //if click button to settle if (PaymentUtil.getSilver() >= silverToCreateSettlement) //if have enough monies to make new settlement { StringBuilder reason = new StringBuilder(); if (currentTileSelected == -1 || !TileFinder.IsValidTileForNewSettlement(currentTileSelected, reason) || Find.World.GetComponent <FactionFC>().checkSettlementCaravansList(currentTileSelected.ToString())) { //Alert Error to User Messages.Message(reason.ToString(), MessageTypeDefOf.NegativeEvent); } else { //Else if valid tile PaymentUtil.paySilver(silverToCreateSettlement); //if PROCESS MONEY HERE if (traitExpansionistReducedFee) { faction.traitExpansionistTickLastUsedSettlementFeeReduction = Find.TickManager.TicksGame; faction.traitExpansionistBoolCanUseSettlementFeeReduction = false; } //create settle event FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settleNewColony); tmp.location = currentTileSelected; tmp.planetName = Find.World.info.name; tmp.timeTillTrigger = Find.TickManager.TicksGame + timeToTravel; tmp.source = Find.World.GetComponent <FactionFC>().capitalLocation; Find.World.GetComponent <FactionFC>().addEvent(tmp); Find.World.GetComponent <FactionFC>().settlementCaravansList.Add(tmp.location.ToString()); Messages.Message("CaravanSentToLocation".Translate() + " " + (tmp.timeTillTrigger - Find.TickManager.TicksGame).ToStringTicksToDays() + "!", MessageTypeDefOf.PositiveEvent); // when event activate FactionColonies.createPlayerColonySettlement(currentTileSelected); } } else { //if don't have enough monies to make settlement Messages.Message("NotEnoughSilverToSettle".Translate() + "!", MessageTypeDefOf.NeutralEvent); } } //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
private void DrawFactionButtons(Rect inRect, int buttonSize) //Used to draw a list of buttons from the 'buttons' list { Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Small; for (int i = 0; i < buttons.Count; i++) { if (Widgets.ButtonText(new Rect(140, 110 + ((buttonSize + 5) * i), 170, buttonSize), buttons[i])) { if (buttons[i] == "FCOverview".Translate()) { //if click trade policy button //Log.Message(buttons[i]); Log.Message("Success"); Find.WindowStack.Add(new FCWindow_Overview()); } if (buttons[i] == "Military".Translate()) { if (FactionColonies.getPlayerColonyFaction() == null) { Messages.Message(new Message("NoFactionForMilitary".Translate(), MessageTypeDefOf.RejectInput)); } else { Find.WindowStack.Add(new militaryCustomizationWindowFC()); } } if (buttons[i] == "Actions".Translate()) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("TaxDeliveryMap".Translate(), delegate { List <FloatMenuOption> list2 = new List <FloatMenuOption>(); list2.Add(new FloatMenuOption("SetMap".Translate(), delegate { List <FloatMenuOption> settlementList = new List <FloatMenuOption>(); foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { settlementList.Add(new FloatMenuOption(map.Parent.LabelCap, delegate { faction.taxMap = map; Find.LetterStack.ReceiveLetter("Map Set!", "The tax delivery map has been set to the player colony of " + map.Parent.LabelCap + ".\n All taxes and other goods will be delivered there", LetterDefOf.NeutralEvent); } )); } } if (settlementList.Count == 0) { settlementList.Add(new FloatMenuOption("No valid settlements to use.", null)); } FloatMenu floatMenu2 = new FloatMenu(settlementList); floatMenu2.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu2); })); FloatMenu floatMenu = new FloatMenu(list2); floatMenu.vanishIfMouseDistant = true; Find.WindowStack.Add(floatMenu); })); list.Add(new FloatMenuOption("SetCapital".Translate(), delegate { faction.setCapital(); })); list.Add(new FloatMenuOption("ActivateResearch".Translate(), delegate { faction.updateDailyResearch(); })); list.Add(new FloatMenuOption("ResearchLevel".Translate(), delegate { Messages.Message("CurrentResearchLevel".Translate(faction.techLevel.ToString(), faction.returnNextTechToLevel()), MessageTypeDefOf.NeutralEvent); })); if (faction.hasPolicy(FCPolicyDefOf.technocratic)) { list.Add(new FloatMenuOption("FCSendResearchItems".Translate(), delegate { if (Find.ColonistBar.GetColonistsInOrder().Count > 0) { Pawn playerNegotiator = Find.ColonistBar.GetColonistsInOrder()[0]; //Log.Message(playerNegotiator.Name + " Negotiator"); FCTrader_Research trader = new FCTrader_Research(); Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, trader)); } else { Log.Message("Where are all the colonists?"); } })); } if (faction.hasPolicy(FCPolicyDefOf.feudal)) { list.Add(new FloatMenuOption("FCRequestMercenary".Translate(), delegate { if (faction.traitFeudalBoolCanUseMercenary) { faction.traitFeudalBoolCanUseMercenary = false; faction.traitFeudalTickLastUsedMercenary = Find.TickManager.TicksGame; List <PawnKindDef> listKindDef = new List <PawnKindDef>(); foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs) { listKindDef.Add(def.race.AnyPawnKind); } PawnGroupMaker groupMaker = FactionColonies.getPlayerColonyFaction().def.pawnGroupMakers.RandomElement(); PawnGroupMakerParms group = new PawnGroupMakerParms(); group.groupKind = groupMaker.kindDef; group.faction = FactionColonies.getPlayerColonyFaction(); group.dontUseSingleUseRocketLaunchers = true; group.generateFightersOnly = true; group.points = 2000; group.raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly; PawnKindDef pawnkind = new PawnKindDef(); PawnKindDef kind = groupMaker.GeneratePawns(group).RandomElement().kindDef; pawnkind = listKindDef.RandomElement(); pawnkind.techHediffsTags = kind.techHediffsTags; pawnkind.apparelTags = kind.apparelTags; pawnkind.isFighter = kind.isFighter; pawnkind.combatPower = kind.combatPower; pawnkind.gearHealthRange = kind.gearHealthRange; pawnkind.weaponTags = kind.weaponTags; pawnkind.apparelMoney = kind.apparelMoney; pawnkind.weaponMoney = kind.weaponMoney; pawnkind.apparelAllowHeadgearChance = kind.apparelAllowHeadgearChance; pawnkind.techHediffsMoney = kind.techHediffsMoney; pawnkind.label = kind.label; Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawnkind, Find.FactionManager.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 20f)); IncidentParms parms = new IncidentParms(); parms.target = Find.CurrentMap; parms.faction = FactionColonies.getPlayerColonyFaction(); parms.points = 999; parms.raidArrivalModeForQuickMilitaryAid = true; parms.raidNeverFleeIndividual = true; parms.raidForceOneIncap = true; parms.raidArrivalMode = PawnsArrivalModeDefOf.CenterDrop; parms.raidStrategy = RaidStrategyDefOf.ImmediateAttackFriendly; parms.raidArrivalModeForQuickMilitaryAid = true; PawnsArrivalModeWorker_EdgeWalkIn worker = new PawnsArrivalModeWorker_EdgeWalkIn(); worker.TryResolveRaidSpawnCenter(parms); worker.Arrive(new List <Pawn> { pawn }, parms); Find.LetterStack.ReceiveLetter("FCMercenaryJoined".Translate(), "FCMercenaryJoinedText".Translate(pawn.NameFullColored), LetterDefOf.PositiveEvent, new LookTargets(pawn)); } else { Messages.Message("FCActionMercenaryOnCooldown".Translate(((faction.traitFeudalTickLastUsedMercenary + GenDate.TicksPerSeason) - Find.TickManager.TicksGame).ToStringTicksToDays()), MessageTypeDefOf.RejectInput); } })); } FloatMenu menu = new FloatMenu(list); Find.WindowStack.Add(menu); } } } }
/// <summary> /// Attempts to create an upgrading <c>FCEvent</c> for a <c>SettlementFC</c>. /// </summary> /// <returns>A message describing if the process was successful or not, including a reason in case it was not</returns> private Message UpgradeSettlement() { //failure reasons if (settlement.IsBeingUpgraded) { return(new Message("AlreadyUpgradeSettlement".Translate(), MessageTypeDefOf.RejectInput)); } if (settlement.isUnderAttack) { return(new Message("SettlementUnderAttack".Translate(), MessageTypeDefOf.RejectInput)); } if (PaymentUtil.getSilver() < settlementUpgradeCost) { return(new Message("NotEnoughSilverUpgrade".Translate(), MessageTypeDefOf.RejectInput)); } //on success PaymentUtil.paySilver(settlementUpgradeCost); FCEvent tmp = new FCEvent(true) { def = FCEventDefOf.upgradeSettlement, location = settlement.mapLocation, planetName = settlement.planetName, timeTillTrigger = Find.TickManager.TicksGame + (settlement.settlementLevel + 1) * 60000 * (factionfc.hasPolicy(FCPolicyDefOf.isolationist) ? 1 : 2) }; Find.World.GetComponent <FactionFC>().addEvent(tmp); //Close this window and update the SettlementWindowFc Find.WindowStack.TryRemove(this); Find.WindowStack.WindowOfType <SettlementWindowFc>().windowUpdateFc(); return(new Message("StartUpgradeSettlement".Translate(), MessageTypeDefOf.NeutralEvent)); }
public override void DoWindowContents(Rect inRect) { //grab before anchor/font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; //Settlement Tax Collection Header Text.Anchor = TextAnchor.MiddleLeft; Text.Font = GameFont.Medium; Widgets.Label(new Rect(2, 0, 300, 60), header); //settlement buttons Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Tiny; //0 tithe total string //1 source - -1 //2 due/delivery date //3 Silver (- || +) //4 tithe if (settlement.settlementLevel < LoadedModManager.GetMod <FactionColoniesMod>() .GetSettings <FactionColonies>().settlementMaxLevel) //if settlement is not max level { if (Widgets.ButtonText(new Rect(xoffset + ((335 - 150) / 2), height + 10, 150, 40), "UpgradeSettlement".Translate() + ": " + settlementUpgradeCost)) { //if upgrade button clicked //if max level if (settlement.settlementLevel < LoadedModManager.GetMod <FactionColoniesMod>() .GetSettings <FactionColonies>().settlementMaxLevel) //if below max level { if (PaymentUtil.getSilver() > settlementUpgradeCost) //if have enough monies to pay { foreach (FCEvent evt in Find.World.GetComponent <FactionFC>().events) { if (evt.def == FCEventDefOf.upgradeSettlement && evt.location == settlement.mapLocation) { //if already existing event Messages.Message("AlreadyUpgradeSettlement".Translate(), MessageTypeDefOf.RejectInput); return; } } if (settlement.isUnderAttack) { Messages.Message("SettlementUnderAttack".Translate(), MessageTypeDefOf.RejectInput); return; } PaymentUtil.paySilver(settlementUpgradeCost); //settlement.upgradeSettlement(); FCEvent tmp = new FCEvent(true); tmp.def = FCEventDefOf.upgradeSettlement; tmp.location = settlement.mapLocation; tmp.planetName = settlement.planetName; int triggerTime = (settlement.settlementLevel + 1) * 60000 * 2; if (factionfc.hasPolicy(FCPolicyDefOf.isolationist)) { triggerTime /= 2; } tmp.timeTillTrigger = Find.TickManager.TicksGame + triggerTime; //Log.Message(list[i].enactDuration.ToString()); //Log.Message(tmp.timeTillTrigger.ToString()); Find.World.GetComponent <FactionFC>().addEvent(tmp); Find.WindowStack.TryRemove(this); Find.WindowStack.WindowOfType <SettlementWindowFc>().windowUpdateFc(); Messages.Message("StartUpgradeSettlement".Translate(), MessageTypeDefOf.NeutralEvent); } else { //if don't have enough monies Messages.Message("NotEnoughSilverUpgrade".Translate(), MessageTypeDefOf.RejectInput); } } else { Messages.Message(settlement.name + " " + "AlreadyMaxLevel".Translate() + "!", MessageTypeDefOf.RejectInput); } } } else //if settlement is max level { desc = "CannotBeUpgradedPastMax".Translate() + ": " + LoadedModManager.GetMod <FactionColoniesMod>() .GetSettings <FactionColonies>().settlementMaxLevel; } Widgets.Label(new Rect(xoffset + 2, yoffset - yspacing + 2, length - 4, height - 4 + yspacing * 2), desc); Widgets.DrawBox(new Rect(xoffset, yoffset - yspacing, length, height - yspacing * 2)); //reset anchor/font Text.Font = fontBefore; Text.Anchor = anchorBefore; }