Example #1
0
        public static void changeDefendingMilitaryForce(FCEvent evt, SettlementFC settlementOfMilitaryForce)
        {
            FactionFC factionfc = Find.World.GetComponent <FactionFC>();

            if (settlementOfMilitaryForce == evt.militaryForceDefending.homeSettlement)
            {
                Messages.Message("militaryAlreadyDefendingSettlement".Translate(), MessageTypeDefOf.RejectInput);
                return;
            }

            if (evt.militaryForceDefending.homeSettlement != factionfc.returnSettlementByLocation(evt.location, evt.planetName))
            {
                //if the forces defending aren't the forces belonging to the settlement
                evt.militaryForceDefending.homeSettlement.returnMilitary(false);
            }


            factionfc.militaryTargets.Remove(evt.location);
            evt.militaryForceDefending = militaryForce.createMilitaryForceFromSettlement(settlementOfMilitaryForce);

            if (settlementOfMilitaryForce == factionfc.returnSettlementByLocation(evt.location, evt.planetName))
            {
                //if home settlement is reseting to defense
                Messages.Message("defendingMilitaryReset".Translate(), MessageTypeDefOf.NeutralEvent);
            }
            else
            {
                //if settlement is foreign
                settlementOfMilitaryForce.sendMilitary(evt.settlementFCDefending.mapLocation, evt.planetName, "defendFriendlySettlement", -1, evt.militaryForceAttackingFaction);
            }
        }
Example #2
0
        public static void changeDefendingMilitaryForce(FCEvent evt, SettlementFC settlementOfMilitaryForce)
        {
            FactionFC     factionfc        = Find.World.GetComponent <FactionFC>();
            militaryForce tmpMilitaryForce = null;
            SettlementFC  homeSettlement   = factionfc.returnSettlementByLocation(evt.location, evt.planetName);

            if (settlementOfMilitaryForce == evt.militaryForceDefending.homeSettlement)
            {
                Messages.Message("militaryAlreadyDefendingSettlement".Translate(), MessageTypeDefOf.RejectInput);
                return;
            }

            WorldSettlementFC target = Find.World.worldObjects.WorldObjectAt <WorldSettlementFC>(evt.location);

            if (evt.militaryForceDefending.homeSettlement !=
                factionfc.returnSettlementByLocation(evt.location, evt.planetName))
            {
                //if the forces defending aren't the forces belonging to the settlement
                evt.militaryForceDefending.homeSettlement.returnMilitary(false);
            }

            if (settlementOfMilitaryForce != homeSettlement)
            {
                tmpMilitaryForce =
                    militaryForce.createMilitaryForceFromSettlement(
                        factionfc.returnSettlementByLocation(evt.location, evt.planetName), true);
            }

            factionfc.militaryTargets.Remove(evt.location);
            evt.militaryForceDefending =
                militaryForce.createMilitaryForceFromSettlement(settlementOfMilitaryForce,
                                                                homeDefendingForce: tmpMilitaryForce);

            target.defenderForce = evt.militaryForceDefending;

            if (settlementOfMilitaryForce == homeSettlement)
            {
                //if home settlement is reseting to defense
                Messages.Message("defendingMilitaryReset".Translate(), MessageTypeDefOf.NeutralEvent);
            }
            else
            {
                //if settlement is foreign
                settlementOfMilitaryForce.SendMilitary(evt.settlementFCDefending.mapLocation, evt.planetName,
                                                       util.MilitaryJob.DefendFriendlySettlement, -1, evt.militaryForceAttackingFaction);
                Find.LetterStack.ReceiveLetter("Military Action", "ForeignMilitarySwitch"
                                               .Translate(settlementOfMilitaryForce.name,
                                                          factionfc.returnSettlementByLocation(evt.location, evt.planetName).name,
                                                          evt.militaryForceDefending.militaryLevel), LetterDefOf.NeutralEvent);
            }
        }
Example #3
0
        public override void DoWindowContents(Rect inRect)
        {
            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            //top label
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            //build outline
            Widgets.DrawMenuSection(eventsBox);


            //loop through each event
            //GoTo Here if change
            int i = 0;

            Text.Anchor = TextAnchor.MiddleCenter;
            foreach (FCEvent evt in events)
            {
                i++;
                Rect name      = new Rect();
                Rect desc      = new Rect();
                Rect location  = new Rect();
                Rect time      = new Rect();
                Rect highlight = new Rect();


                name     = eventNameBase;
                desc     = eventDescBase;
                location = eventLocationBase;
                time     = eventTimeRemaining;

                name.y     = scroll + eventHeight * i;
                desc.y     = scroll + eventHeight * i;
                location.y = scroll + eventHeight * i;
                time.y     = scroll + eventHeight * i;

                highlight = new Rect(name.x, name.y, time.x + time.width, eventHeight);



                if (i % 2 == 0)
                {
                    Widgets.DrawHighlight(highlight);
                }
                Widgets.Label(name, evt.def.label);
                //
                if (Widgets.ButtonText(desc, "Desc"))
                {
                    if (evt.hasCustomDescription == false)
                    {
                        //If desc button clicked
                        string settlementString = "";
                        foreach (SettlementFC loc in evt.settlementTraitLocations)
                        {
                            if (loc != null)
                            {
                                if (settlementString == "")
                                {
                                    settlementString += loc.name;
                                }
                                else
                                {
                                    settlementString += ", " + loc.name;
                                }
                            }
                        }
                        if (settlementString != "")
                        {
                            Find.WindowStack.Add(new DescWindowFc(evt.def.description + "\n This event is affecting the following settlements: " + settlementString));
                        }
                        else
                        {
                            Find.WindowStack.Add(new DescWindowFc(evt.def.description));
                        }
                    }
                    else
                    {
                        //has custom description
                        Find.WindowStack.Add(new DescWindowFc(evt.customDescription));
                    }
                }
                //
                if (Widgets.ButtonText(location, "Location".Translate().CapitalizeFirst()))
                {
                    if (evt.hasDestination == true)
                    {
                        Find.WindowStack.Add(new SettlementWindowFc(faction.returnSettlementByLocation(evt.location, evt.planetName)));
                    }
                    else
                    {
                        if (evt.settlementTraitLocations.Count() > 0)
                        {
                            //if event affecting colonies
                            List <FloatMenuOption> list = new List <FloatMenuOption>();
                            foreach (SettlementFC settlement in evt.settlementTraitLocations)
                            {
                                if (settlement != null)
                                {
                                    list.Add(new FloatMenuOption(settlement.name, delegate { Find.WindowStack.Add(new SettlementWindowFc(settlement)); }));
                                }
                            }
                            if (list.Count == 0)
                            {
                                list.Add(new FloatMenuOption("Null", null));
                            }
                            Find.WindowStack.Add(new FloatMenu(list));
                        }
                        else
                        {
                            if (evt.def == FCEventDefOf.taxColony && evt.source != -1)
                            {
                                Find.WindowStack.Add(new SettlementWindowFc(faction.returnSettlementByLocation(evt.source, evt.planetName)));
                            }
                        }
                    }
                }
                Widgets.Label(time, (evt.timeTillTrigger - Find.TickManager.TicksGame).ToTimeString());
            }



            //Top label
            Widgets.ButtonTextSubtle(eventNameBase, "Name".Translate());
            Widgets.ButtonTextSubtle(eventDescBase, "Description".Translate());
            Widgets.ButtonTextSubtle(eventLocationBase, "Source".Translate());
            Widgets.ButtonTextSubtle(eventTimeRemaining, "TimeRemaining".Translate());

            //Menu Outline
            Widgets.DrawBox(eventsBox);


            //reset anchor/font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;


            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y);
            }
        }