Example #1
0
        public static void attackPlayerSettlement(militaryForce attackingForce, SettlementFC settlement, Faction enemyFaction)
        {
            FactionFC factionfc = Find.World.GetComponent <FactionFC>();

            FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settlementBeingAttacked);

            tmp.hasCustomDescription          = true;
            tmp.timeTillTrigger               = Find.TickManager.TicksGame + 60000;
            tmp.location                      = settlement.mapLocation;
            tmp.planetName                    = settlement.planetName;
            tmp.hasDestination                = true;
            tmp.customDescription             = TranslatorFormattedStringExtensions.Translate("settlementAboutToBeAttacked", settlement.name, enemyFaction.Name);// +
            tmp.militaryForceDefending        = militaryForce.createMilitaryForceFromSettlement(settlement);
            tmp.militaryForceDefendingFaction = FactionColonies.getPlayerColonyFaction();
            tmp.militaryForceAttacking        = attackingForce;
            tmp.militaryForceAttackingFaction = enemyFaction;
            tmp.settlementFCDefending         = settlement;


            SettlementFC highest = null;

            foreach (SettlementFC settlementCompare in factionfc.settlements)
            {
                if (settlementCompare.autoDefend && settlementCompare.militaryBusy == false && settlementCompare.settlementMilitaryLevel > settlement.settlementMilitaryLevel && (highest == null || settlementCompare.settlementMilitaryLevel > highest.settlementMilitaryLevel))
                {
                    highest = settlementCompare;
                }
            }

            if (highest != null)
            {
                MilitaryUtilFC.changeDefendingMilitaryForce(tmp, highest);
            }



            Find.World.GetComponent <FactionFC>().addEvent(tmp);

            tmp.customDescription   += "\n\nThe estimated attacking force's power is: " + tmp.militaryForceAttacking.forceRemaining;
            settlement.isUnderAttack = true;

            Find.LetterStack.ReceiveLetter("settlementInDanger".Translate(), tmp.customDescription, LetterDefOf.ThreatBig, new LookTargets(Find.WorldObjects.SettlementAt(settlement.mapLocation)));
        }
Example #2
0
        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] == "GoToLocation".Translate())
                        {                         //if click go to location
                                                  //Log.Message(buttons[i]);
                            Find.WindowStack.TryRemove(this);
                            settlement.goTo();
                        }
                        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] == "PrisonersMenu".Translate())
                        {
                            Find.WindowStack.Add(new FCPrisonerMenu(settlement));                                //put prisoner window here.
                        }
                        if (buttons[i] == "Military".Translate())
                        {
                            List <FloatMenuOption> list = new List <FloatMenuOption>();
                            list.Add(new FloatMenuOption(TranslatorFormattedStringExtensions.Translate("ToggleAutoDefend", settlement.autoDefend.ToString()), delegate { settlement.autoDefend = !settlement.autoDefend; }));

                            if (settlement.isUnderAttack == true)
                            {
                                FCEvent evt = MilitaryUtilFC.returnMilitaryEventByLocation(settlement.mapLocation);

                                list.Add(new FloatMenuOption(TranslatorFormattedStringExtensions.Translate("SettlementDefendingInformation", 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(TranslatorFormattedStringExtensions.Translate("ResetToHomeSettlement", homeSettlement.settlementMilitaryLevel), delegate
                                    {
                                        MilitaryUtilFC.changeDefendingMilitaryForce(evt, homeSettlement);
                                    }, MenuOptionPriority.High));

                                    foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements)
                                    {
                                        if (settlement.isMilitaryValid() == true && 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() == true)
                                                {
                                                    //military is busy
                                                }
                                                else
                                                {
                                                    MilitaryUtilFC.changeDefendingMilitaryForce(evt, settlement);
                                                }
                                            }, MenuOptionPriority.Default, null, null, 0f, null, null
                                                                                   ));
                                        }
                                    }

                                    if (settlementList.Count == 0)
                                    {
                                        settlementList.Add(new FloatMenuOption("NoValidMilitaries".Translate(), null));
                                    }

                                    FloatMenu floatMenu2            = new FloatMenu(settlementList);
                                    floatMenu2.vanishIfMouseDistant = true;
                                    Find.WindowStack.Add(floatMenu2);


                                    //set to raid settlement here
                                }));



                                FloatMenu floatMenu = new FloatMenu(list);
                                floatMenu.vanishIfMouseDistant = true;
                                Find.WindowStack.Add(floatMenu);
                            }
                            else
                            {
                                list.Add(new FloatMenuOption("SettlementNotBeingAttacked".Translate(), null));
                                FloatMenu menu = new FloatMenu(list);
                                Find.WindowStack.Add(menu);
                            }
                        }
                    }
                }
            }
            //set two buttons
        }
Example #3
0
        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
        }
 public override void Arrived(Caravan caravan) => settlement.startDefence(MilitaryUtilFC.returnMilitaryEventByLocation(settlement.settlement.mapLocation), () => settlement.CaravanDefend(caravan));