Exemple #1
0
        public MilUnitFC CreateMilUnit()
        {
            MilUnitFC unit = new MilUnitFC(false)
            {
                name       = name,
                isCivilian = isCivilian,
                isTrader   = isTrader,
                animal     = animal,
                pawnKind   = pawnKind
            };

            if (!Find.World.GetComponent <FactionFC>().raceFilter.Allows(pawnKind.race))
            {
                unit.pawnKind = FactionColonies.getPlayerColonyFaction().RandomPawnKind();
            }
            unit.generateDefaultPawn();

            if (weapon.thing != null)
            {
                unit.equipWeapon((ThingWithComps)weapon.CreateThing());
            }

            apparel.ForEach(a =>
            {
                if (a.thing != null)
                {
                    unit.wearEquipment((Apparel)a.CreateThing(), true);
                }
            });

            unit.changeTick();
            unit.updateEquipmentTotalCost();

            return(unit);
        }
Exemple #2
0
        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.
        }
Exemple #3
0
        static bool Prefix(ref ThingSetMaker_RefugeePod __instance, ThingSetMakerParams parms, List <Thing> outThings)
        {
            Faction faction = DownedRefugeeQuestUtility.GetRandomFactionForRefugee();


            if (faction == FactionColonies.getPlayerColonyFaction())
            {
                List <PawnKindDef> list = new List <PawnKindDef>();
                foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs)
                {
                    list.Add(def.race.AnyPawnKind);
                }


                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, DownedRefugeeQuestUtility.GetRandomFactionForRefugee(), PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 20f, false, true, true, true, false, false, false, false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, null));
                outThings.Add(pawn);
                HealthUtility.DamageUntilDowned(pawn, true);



                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #4
0
        public static void updateFactionOnPlanet()
        {
            FactionFC worldcomp = Find.World.GetComponent <FactionFC>();
            Faction   faction1  = FactionColonies.getPlayerColonyFaction();

            //Log.Message((faction1 != null).ToString());
            if (faction1 == null && worldcomp.factionCreated == true)
            {
                Log.Message("Moved to new planet - Adding faction copy");
                //FactionColonies.createPlayerColonyFaction();
                FactionColonies.copyPlayerColonyFaction();
                faction1 = FactionColonies.getPlayerColonyFaction();
            }
            //Log.Message(((bool)(faction1 != null)).ToString());
            foreach (Faction factionOther in Find.FactionManager.AllFactionsListForReading)
            {
                //Log.Message(factionOther.def.defName);
                if (factionOther != faction1 && faction1.RelationWith(factionOther, true) == null)
                {
                    faction1.TryMakeInitialRelationsWith(factionOther);
                }
            }
            worldcomp.updateFactionIcon(ref faction1, "FactionIcons/" + worldcomp.factionIconPath);
            worldcomp.factionUpdated = true;
            //foreach (SettlementFC settlement in worldcomp.settlements)
            //{
            //    Settlement obj = Find.WorldObjects.SettlementAt(settlement.mapLocation);
            //    if (obj != null && obj.Faction != faction1)
            //    {
            //        obj.SetFaction(faction1);
            //    }
            //}
        }
Exemple #5
0
        static bool Prefix(ref QuestNode_GetPawn __instance, ref Pawn __result, Slate slate, Faction faction = null)
        {
            if (faction == FactionColonies.getPlayerColonyFaction())
            {
                List <PawnKindDef> list = new List <PawnKindDef>();
                foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs)
                {
                    list.Add(def.race.AnyPawnKind);
                }


                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(list.RandomElement(), faction, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, true, false, false, false, false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null));
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
                if (pawn.royalty != null && pawn.royalty.AllTitlesForReading.Any <RoyalTitle>())
                {
                    QuestPart_Hyperlinks questPart_Hyperlinks = new QuestPart_Hyperlinks();
                    questPart_Hyperlinks.pawns.Add(pawn);
                    QuestGen.quest.AddPart(questPart_Hyperlinks);
                }
                __result = pawn;



                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #6
0
        static bool Prefix(ref Pawn __result, Quest quest, PawnKindDef kindDef, Faction faction, bool allowAddictions = true, IEnumerable <TraitDef> forcedTraits = null, float biocodeWeaponChance = 0f, bool mustBeCapableOfViolence = true, Pawn extraPawnForExtraRelationChance = null, float relationWithExtraPawnChanceFactor = 0f, float biocodeApparelChance = 0f, bool ensureNonNumericName = false, bool forceGenerateNewPawn = false)
        {
            if (faction == FactionColonies.getPlayerColonyFaction())
            {
                List <PawnKindDef> list = new List <PawnKindDef>();
                foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs)
                {
                    list.Add(def.race.AnyPawnKind);
                }



                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(list.RandomElement(), faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn, false, false, false, true, mustBeCapableOfViolence, 1f, false, true, true, allowAddictions, false, false, false, false, biocodeWeaponChance, extraPawnForExtraRelationChance, relationWithExtraPawnChanceFactor, null, null, forcedTraits, null, null, null, null, null, null, null, null, null)
                {
                    BiocodeApparelChance = biocodeApparelChance
                });
                if (ensureNonNumericName && (pawn.Name == null || pawn.Name.Numerical))
                {
                    pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, null);
                }
                QuestGen.AddToGeneratedPawns(pawn);
                if (!pawn.IsWorldPawn())
                {
                    Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
                }
                __result = pawn;


                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #7
0
        static bool Prefix(ref PawnGroupKindWorker_Trader __instance, ref Pawn __result, PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind)
        {
            if (parms.faction == FactionColonies.getPlayerColonyFaction())
            {
                List <PawnKindDef> list = new List <PawnKindDef>();
                foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs)
                {
                    list.Add(def.race.AnyPawnKind);
                }

                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(list.RandomElement(), parms.faction, PawnGenerationContext.NonPlayer, parms.tile, false, false, false, false, true, false, 1f, false, true, true, true, parms.inhabitants, false, false, false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, null));
                pawn.mindState.wantsToTradeWithColony = true;
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
                pawn.trader.traderKind = traderKind;
                parms.points          -= pawn.kindDef.combatPower;
                __result = pawn;


                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #8
0
        private void DrawColonySettlementCreationButton(Rect inRect)
        {
            Rect button = new Rect(InitialSize.x - 215, 40, 190, 20);

            Text.Anchor = TextAnchor.MiddleLeft;
            Text.Font   = GameFont.Small;

            Faction gfaction = FactionColonies.getPlayerColonyFaction();

            if (gfaction != null)
            {
                if (Widgets.ButtonText(button, "CreateNewColony".Translate()))
                {
                    Find.WindowStack.Add(new createColonyWindowFC());

                    //Move player to world map
                    Find.World.renderer.wantedMode = WorldRenderMode.Planet;

                    Messages.Message("SelectTile".Translate(), MessageTypeDefOf.NegativeEvent);
                }
            }
            else               //create new faction
            {
                if (Widgets.ButtonText(button, "Create New Faction"))
                {
                    FactionColonies.createPlayerColonyFaction();
                    Find.WindowStack.Add(new factionCustomizeWindowFC(faction));
                    //Initial release - Autocreate faction
                    Messages.Message(Find.WorldObjects.SettlementAt(Find.CurrentMap.Parent.Tile).Name + " " + "SetAsFactionCapital".Translate() + "!", MessageTypeDefOf.NeutralEvent);
                }
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            //set text anchor and font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            Text.Anchor = TextAnchor.MiddleLeft;
            Text.Font   = GameFont.Small;


            Widgets.Label(new Rect(0, 0, 250, 25), label);
            text = Widgets.TextField(new Rect(0, 35, 150, 25), text);
            if (Widgets.ButtonText(new Rect(155, 35, 60, 25), "Confirm"))
            {
                if (reason == "faction")
                {
                    Find.World.GetComponent <FactionFC>().name = text;
                    FactionColonies.getPlayerColonyFaction().Name = text;
                }
                Find.WindowStack.TryRemove(this);
            }


            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
Exemple #10
0
 public override void OnAcceptKeyPressed()
 {
     base.OnAcceptKeyPressed();
     faction.title = title;
     faction.name  = name;
     FactionColonies.getPlayerColonyFaction().Name = name;
     Find.World.GetComponent <FactionFC>().name = name;
 }
 static void Postfix(ref IncidentWorker_RaidFriendly __instance, ref bool __result, IncidentParms parms)
 {
     if (parms.faction == FactionColonies.getPlayerColonyFaction())
     {
         parms.faction = null;
         __result      = false;
     }
 }
        public static PawnGenerationRequest CivilianRequest(PawnKindDef pawnKindDef = null)
        {
            PawnGenerationRequest request = baseRequest;

            request.KindDef = pawnKindDef ?? (FactionColonies.getPlayerColonyFaction()?.RandomPawnKind());
            request.Faction = FactionColonies.getPlayerColonyFaction();

            return(request);
        }
        public static PawnGenerationRequest AnimalRequest(PawnKindDef race)
        {
            PawnGenerationRequest request = baseRequest;

            request.KindDef            = race;
            request.Faction            = FactionColonies.getPlayerColonyFaction();
            request.FixedBiologicalAge = request.KindDef.GetReasonableMercenaryAge();

            return(request);
        }
Exemple #14
0
        public MilUnitFC(bool blank)
        {
            loadID             = Find.World.GetComponent <FactionFC>().NextUnitID;
            isBlank            = blank;
            equipmentTotalCost = 0;

            pawnKind = FactionColonies.getPlayerColonyFaction()?.RandomPawnKind() ?? DefDatabase <FactionDef> .GetNamed("PColony").pawnGroupMakers.RandomElement().options.RandomElement().kind;

            generateDefaultPawn();
        }
Exemple #15
0
 public FCPrisoner(Pawn pawn, SettlementFC settlement)
 {
     prisoner        = pawn;
     this.settlement = settlement;
     unrest          = 0;
     healthTracker   = new Pawn_HealthTracker(pawn);
     healthTracker   = pawn.health;
     health          = (float)Math.Round(prisoner.health.summaryHealth.SummaryHealthPercent * 100);
     isReturning     = false;
     loadID          = Find.World.GetComponent <FactionFC>().GetNextPrisonerID();
     pawn.guest.SetGuestStatus(FactionColonies.getPlayerColonyFaction(), GuestStatus.Prisoner);
 }
        public static PawnGenerationRequest WorkerOrMilitaryRequest(PawnKindDef pawnKindDef = null)
        {
            PawnGenerationRequest request = baseRequest;

            request.KindDef = pawnKindDef ?? FactionColonies.getPlayerColonyFaction()?.RandomPawnKind() ?? DefDatabase <FactionDef> .GetNamed("PColony").pawnGroupMakers.RandomElement().options.RandomElement().kind;

            request.Faction                 = FactionColonies.getPlayerColonyFaction();
            request.FixedBiologicalAge      = request.KindDef.GetReasonableMercenaryAge();
            request.MustBeCapableOfViolence = true;

            return(request);
        }
Exemple #17
0
		public static Pawn generatePrisoner(Faction faction)
		{
			Pawn pawn;

			PawnKindDef raceChoice;
			raceChoice = faction.RandomPawnKind();

			pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(raceChoice, FactionColonies.getPlayerColonyFaction(), PawnGenerationContext.NonPlayer, -1, false, false, false, false, false, true, 0, false, false, false, false, false, false, false, false, 0, null, 0, null, null, null, null, null, null, null, null, null, null, null, null));
			pawn.guest.isPrisonerInt = true;



			return pawn;
		}
Exemple #18
0
        public override void Notify_PawnLost(Pawn pawn, PawnLostCondition condition)
        {
            if (condition == PawnLostCondition.ChangedFaction || condition == PawnLostCondition.ExitedMap)
            {
                lord.AddPawn(pawn);
                return;
            }
            pawn.SetFaction(FactionColonies.getPlayerColonyFaction());
            FactionFC faction = Find.World.GetComponent <FactionFC>();
            //Check if a settlement battle ended
            SettlementFC settlement = faction.getSettlement(pawn.Tile, Find.World.info.name);

            settlement?.worldSettlement.removeDefender(pawn);
        }
Exemple #19
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    = "settlementAboutToBeAttacked"
                                       .Translate(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)
            {
                changeDefendingMilitaryForce(tmp, highest);
            }

            settlement.worldSettlement.defenderForce = tmp.militaryForceDefending;
            settlement.worldSettlement.attackerForce = tmp.militaryForceAttacking;

            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.WorldObjectAt <WorldSettlementFC>(settlement.mapLocation)));
        }
Exemple #20
0
        static bool Prefix(ref PawnGroupKindWorker_Trader __instance, PawnGroupMakerParms parms, PawnGroupMaker groupMaker, Pawn trader, List <Thing> wares, List <Pawn> outPawns)
        {
            if (parms.faction == FactionColonies.getPlayerColonyFaction())
            {
                List <PawnKindDef> list = new List <PawnKindDef>();
                foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs)
                {
                    list.Add(def.race.AnyPawnKind);
                }

                if (!groupMaker.guards.Any <PawnGenOption>())
                {
                    return(false);
                }
                foreach (PawnGenOption pawnGenOption in PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints(parms.points, groupMaker.guards, parms))
                {
                    PawnKindDef pawnkind = new PawnKindDef();
                    pawnkind = list.RandomElement();
                    pawnkind.techHediffsTags            = pawnGenOption.kind.techHediffsTags;
                    pawnkind.apparelTags                = pawnGenOption.kind.apparelTags;
                    pawnkind.isFighter                  = pawnGenOption.kind.isFighter;
                    pawnkind.combatPower                = pawnGenOption.kind.combatPower;
                    pawnkind.gearHealthRange            = pawnGenOption.kind.gearHealthRange;
                    pawnkind.weaponTags                 = pawnGenOption.kind.weaponTags;
                    pawnkind.apparelMoney               = pawnGenOption.kind.apparelMoney;
                    pawnkind.weaponMoney                = pawnGenOption.kind.weaponMoney;
                    pawnkind.apparelAllowHeadgearChance = pawnGenOption.kind.apparelAllowHeadgearChance;
                    pawnkind.techHediffsMoney           = pawnGenOption.kind.techHediffsMoney;
                    pawnkind.label = pawnGenOption.kind.label;

                    PawnGenerationRequest request = PawnGenerationRequest.MakeDefault();
                    request.KindDef = pawnkind;
                    Log.Message(request.KindDef.ToString());
                    request.Faction = parms.faction;
                    request.Tile    = parms.tile;
                    request.MustBeCapableOfViolence = true;
                    request.Inhabitant       = parms.inhabitants;
                    request.RedressValidator = ((Pawn x) => x.royalty == null || !x.royalty.AllTitlesForReading.Any <RoyalTitle>());
                    Pawn item = PawnGenerator.GeneratePawn(request);
                    outPawns.Add(item);
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #21
0
        public static void resetPlayerColonyRelations()
        {
            Faction PCFaction = FactionColonies.getPlayerColonyFaction();

            foreach (Faction faction in Find.FactionManager.AllFactionsInViewOrder)
            {
                if (faction != Find.FactionManager.OfPlayer && faction != PCFaction)
                {
                    //if not player faction or player colony faction
                    PCFaction.TryAffectGoodwillWith(faction, (Find.FactionManager.OfPlayer.RelationWith(faction).goodwill - PCFaction.RelationWith(faction).goodwill));
                    PCFaction.TrySetRelationKind(faction, Find.FactionManager.OfPlayer.RelationKindWith(faction));
                    //Log.Message(Find.FactionManager.OfPlayer.RelationWith(faction).goodwill + " player:colony " + PCFaction.RelationWith(faction).goodwill);
                }
            }
        }
 private void DrawFactionName(Rect inRect)
 {
     Text.Anchor = TextAnchor.MiddleLeft;
     Text.Font   = GameFont.Medium;
     Widgets.Label(new Rect(7, 32, 200, 40), faction.name);
     if (Widgets.ButtonImage(new Rect(210, 37, 20, 20), texLoad.iconCustomize))
     {             //if click faction customize button
                   //Log.Message("Faction customize clicked");
         Faction fact = FactionColonies.getPlayerColonyFaction();
         if (fact != null)
         {
             Find.WindowStack.Add(new factionCustomizeWindowFC(faction));
         }
         else
         {
             Messages.Message("No faction created to customize", MessageTypeDefOf.RejectInput);
         }
     }
 }
        static bool Prefix(Pawn __instance)
        {
            if (__instance.IsMercenary())
            {
                if (__instance.Faction != FactionColonies.getPlayerColonyFaction())
                {
                    __instance.SetFaction(FactionColonies.getPlayerColonyFaction());
                }
                MercenarySquadFC squad = Find.World.GetComponent <FactionFC>().militaryCustomizationUtil.returnSquadFromUnit(__instance);
                if (squad != null)
                {
                    Mercenary merc = Find.World.GetComponent <FactionFC>().militaryCustomizationUtil.returnMercenaryFromUnit(__instance, squad);
                    if (merc != null)
                    {
                        if (squad.settlement != null)
                        {
                            if (FactionColonies.Settings().deadPawnsIncreaseMilitaryCooldown)
                            {
                                squad.dead += 1;
                            }

                            squad.settlement.happiness -= 1;
                        }

                        squad.PassPawnToDeadMercenaries(merc);
                    }

                    squad.removeDroppedEquipment();
                }
                else
                {
                    Log.Message("Mercenary Errored out. Did not find squad.");
                }

                __instance.equipment?.DestroyAllEquipment();
                __instance.apparel?.DestroyAll();
                //__instance.Destroy();
                return(true);
            }

            return(true);
        }
Exemple #24
0
        public void createNewPawn(ref Mercenary merc, PawnKindDef race)
        {
            PawnKindDef raceChoice = race;
            FactionFC   factionFc  = Find.World.GetComponent <FactionFC>();

            if (race == null || !factionFc.raceFilter.Allows(raceChoice.race))
            {
                raceChoice = FactionColonies.getPlayerColonyFaction().RandomPawnKind();
            }

            Pawn newPawn = PawnGenerator.GeneratePawn(FCPawnGenerator.WorkerOrMilitaryRequest(raceChoice));

            newPawn.apparel?.DestroyAll();
            newPawn.equipment?.DestroyAllEquipment();
            //merc = (Mercenary)newPawn;
            merc.squad      = this;
            merc.settlement = settlement;
            //Log.Message(newPawn.Name + "   State: Dead - " + newPawn.health.Dead + "    Apparel Count: " + newPawn.apparel.WornApparel.Count());
            merc.pawn = newPawn;
        }
Exemple #25
0
        public static void attackPlayerSettlement(militaryForce attackingForce, SettlementFC settlement, Faction enemyFaction)
        {
            FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settlementBeingAttacked);

            tmp.hasCustomDescription          = true;
            tmp.timeTillTrigger               = Find.TickManager.TicksGame + 60000;
            tmp.location                      = settlement.mapLocation;
            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;
            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)));
        }
Exemple #26
0
        //
        //[HarmonyPatch(typeof(Scenario), "PostWorldGenerate")]
        public static void Postfix()
        {
            FactionFC worldcomp = Find.World.GetComponent <FactionFC>();


            //FactionFC worldcomp = Find.World.GetComponent<FactionFC>();
            if (worldcomp != null && worldcomp.planetName != null && worldcomp.planetName != Find.World.info.name && Find.TickManager.TicksGame > 60000)
            {
                Faction faction1 = FactionColonies.getPlayerColonyFaction();
                updateFactionOnPlanet();

                if (worldcomp.SoSMoving == true)
                {
                    int difference = Find.TickManager.TicksGame - worldcomp.travelTime;
                    worldcomp.taxTimeDue      = worldcomp.taxTimeDue + difference;
                    worldcomp.dailyTimer      = worldcomp.dailyTimer + difference;
                    worldcomp.militaryTimeDue = worldcomp.militaryTimeDue + difference;
                    worldcomp.SoSMoving       = false;
                }
                if (worldcomp.SoSShipTaxMap == true)
                {
                    worldcomp.taxMap = Find.CurrentMap;
                    Log.Message("Updated Tax map to ship");
                    Log.Message(worldcomp.taxMap.Parent.Label);
                }
                if (worldcomp.SoSShipCapitalMoving == true)
                {
                    worldcomp.SoSShipCapitalMoving = false;
                    worldcomp.setCapital();
                }

                ///
                worldcomp.boolChangedPlanet = true;
                worldcomp.planetName        = Find.World.info.name;
            }



            //ResetFactionLeaders();
        }
Exemple #27
0
        private static void Postfix(ref Pawn __instance, ref IEnumerable <Gizmo> __result)
        {
            var output = __result.ToList();

            if (__result == null || __instance?.Faction == null || !output.Any() ||
                !(__instance.Map.Parent is WorldSettlementFC))
            {
                return;
            }

            var found = __instance;
            var pawnDraftController = __instance.drafter ?? new Pawn_DraftController(__instance);

            var settlementFc = (WorldSettlementFC)__instance.Map.Parent;

            if (__instance.Faction.Equals(FactionColonies.getPlayerColonyFaction()))
            {
                var draftColonists = new Command_Toggle
                {
                    hotKey       = KeyBindingDefOf.Command_ColonistDraft,
                    isActive     = () => false,
                    toggleAction = () =>
                    {
                        if (pawnDraftController.pawn.Faction.Equals(Faction.OfPlayer))
                        {
                            return;
                        }
                        pawnDraftController.pawn.SetFaction(Faction.OfPlayer);
                        pawnDraftController.Drafted = true;
                    },
                    defaultDesc  = "CommandToggleDraftDesc".Translate(),
                    icon         = TexCommand.Draft,
                    turnOnSound  = SoundDefOf.DraftOn,
                    groupKey     = 81729172,
                    defaultLabel = "CommandDraftLabel".Translate()
                };
                if (pawnDraftController.pawn.Downed)
                {
                    draftColonists.Disable("IsIncapped".Translate(
                                               (NamedArgument)pawnDraftController.pawn.LabelShort,
                                               (NamedArgument)pawnDraftController.pawn));
                }
                draftColonists.tutorTag = "Draft";
                output.Add(draftColonists);
            }
            else if (__instance.Faction.Equals(Faction.OfPlayer) && __instance.Drafted &&
                     !settlementFc.supporting.Any(caravan => caravan.pawns.Any(pawn => pawn.Equals(found))))
            {
                foreach (Command_Toggle action in output.Where(gizmo => gizmo is Command_Toggle))
                {
                    if (action.hotKey != KeyBindingDefOf.Command_ColonistDraft)
                    {
                        continue;
                    }

                    var index = output.IndexOf(action);
                    action.toggleAction = () =>
                    {
                        found.SetFaction(FactionColonies.getPlayerColonyFaction());
                        //settlementFc.worldSettlement.defenderLord.AddPawn(__instance);
                    };
                    output[index] = action;
                    break;
                }
            }

            __result = output;
        }
Exemple #28
0
        public static militaryForce createMilitaryForceFromSettlement(SettlementFC settlement)
        {
            //get efficiency from traits and settlement efficiency.
            double        militaryLevel = settlement.settlementMilitaryLevel;
            double        efficiency    = traitUtilsFC.cycleTraits(new double(), "militaryMultiplierCombatEfficiency", Find.World.GetComponent <FactionFC>().traits, "multiply") * traitUtilsFC.cycleTraits(new double(), "militaryMultiplierCombatEfficiency", settlement.traits, "multiply");
            militaryForce returnForce   = new militaryForce(militaryLevel, efficiency, settlement, FactionColonies.getPlayerColonyFaction());

            return(returnForce);
            //create and return force.
        }
Exemple #29
0
        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(3, 3, 300, 60), header);


            Text.Font = GameFont.Small;
            for (int i = 0; i < 3; i++)             //for each field to customize
            {
                switch (i)
                {
                case 0:                          //faction name
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionName".Translate() + ": ");
                    name = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), name);
                    break;

                case 1:                         //faction title
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionTitle".Translate() + ": ");
                    title = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), title);
                    break;

                case 2:                                                                                                                  //faction icon
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionIcon".Translate() + ": ");
                    if (Widgets.ButtonImage(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, 40, 40), texLoad.iconUnrest)) //change to faction icon
                    {
                        Messages.Message("ButtonNotAvailable".Translate() + ".", MessageTypeDefOf.CautionInput);
                        //Log.Message("Faction icon select pressed");
                        //Open window to select new icon
                    }
                    break;
                }
            }

            if (Widgets.ButtonText(new Rect((InitialSize.x - 120 - 18) / 2, yoffset + InitialSize.y - 120, 120, 30), "ConfirmChanges".Translate()))
            {
                faction.title = title;
                faction.name  = name;
                FactionColonies.getPlayerColonyFaction().Name = name;
                Find.World.GetComponent <FactionFC>().name = name;
                Find.WindowStack.TryRemove(this);
            }

            //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


            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;
        }
        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(labelFaction, header);

            Text.Font = GameFont.Small;
            Widgets.Label(labelFactionName, "FactionName".Translate() + ":");
            name = Widgets.TextField(textfieldName, name);

            Widgets.Label(labelFactionTitle, "FactionTitle".Translate() + ":");
            title = Widgets.TextField(textfieldTitle, title);

            Widgets.Label(labelFactionIcon, "FactionIcon".Translate());
            if (Widgets.ButtonImage(buttonIcon, tempFactionIcon))
            {
                List <FloatMenuOption> list = TexLoad.factionIcons.Select(texture => new FloatMenuOption(texture.name, delegate
                {
                    tempFactionIcon     = texture;
                    tempFactionIconPath = texture.name;
                }, texture, Color.white)).ToList();

                FloatMenu menu = new FloatMenu(list);
                Find.WindowStack.Add(menu);
            }

            if (Widgets.ButtonTextSubtle(buttonAllowedRaces, "AllowedRaces".Translate()))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>
                {
                    new FloatMenuOption("Enable All", delegate { faction.resetRaceFilter(); })
                };
                List <string> races = new List <string>();
                foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading.Where(def => def.IsHumanlikeWithLabelRace() && !races.Contains(def.race.label)))
                {
                    if (def.race.label == "Human" && def.LabelCap != "Colonist")
                    {
                        continue;
                    }
                    races.Add(def.race.label);
                    list.Add(new FloatMenuOption(
                                 def.race.label.CapitalizeFirst() + " - Allowed: " + faction.raceFilter.Allows(def.race),
                                 delegate
                    {
                        if (faction.raceFilter.AllowedThingDefs.Count() == 1 && faction.raceFilter.Allows(def.race))
                        {
                            Messages.Message("CannotHaveLessThanOneRace".Translate(), MessageTypeDefOf.RejectInput);
                        }
                        else if (faction.raceFilter.AllowedThingDefs.Count() > 0)
                        {
                            if (!faction.raceFilter.SetAllow(def.race, !faction.raceFilter.Allows(def.race)))
                            {
                                Messages.Message(new Message("InvalidFaction".Translate(), MessageTypeDefOf.RejectInput));
                            }
                        }
                        else
                        {
                            Log.Message("Empire Error - Zero races available for faction - Report this");
                            Log.Message("Resetting race filter");
                            faction.resetRaceFilter();
                        }
                    }));
                }

                FloatMenu menu = new FloatMenu(list);
                Find.WindowStack.Add(menu);
            }

            if (Widgets.ButtonText(buttonConfirm, "ConfirmChanges".Translate()))
            {
                Faction fact = FactionColonies.getPlayerColonyFaction();
                faction.title           = title;
                faction.name            = name;
                fact.Name               = name;
                faction.name            = name;
                faction.factionIconPath = tempFactionIconPath;
                faction.factionIcon     = tempFactionIcon;
                faction.updateFactionRaces();
                faction.factionBackup = fact;

                faction.updateFactionIcon(ref fact, "FactionIcons/" + tempFactionIconPath);


                if (!traitsChosen)
                {
                    //check each trait bool. If true and does not exist already, add to factionfc
                    if (boolMilitaristic)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.militaristic));
                    }
                    if (boolPacifist)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.pacifist));
                    }
                    if (boolAuthoritarian)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.authoritarian));
                    }
                    if (boolEgalitarian)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.egalitarian));
                    }
                    if (boolIsolationist)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.isolationist));
                    }
                    if (boolExpansionist)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.expansionist));
                    }
                    if (boolTechnocrat)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.technocratic));
                    }
                    if (boolFeudal)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.feudal));
                    }
                }

                Find.WindowStack.TryRemove(this);
            }


            if (!traitsChosen)
            {
                switch (faction.policies.Count())
                {
                case 0:
                case 1:
                    alertText = "FCSelectTraits0".Translate();
                    break;

                case 2:
                    alertText = "FCSelectTraits2".Translate();
                    break;
                }
            }
            else
            {
                alertText = "FCTraitsChosen".Translate();
            }


            Widgets.Label(labelPickTrait, alertText);


            Texture2D icon = TexLoad.iconLoyalty;

            if (boolMilitaristic)
            {
                icon = FCPolicyDefOf.militaristic.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.militaristic.IconDark;
            }
            if (buttonMilitaristic.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonMilitaristic, returnPolicyText(FCPolicyDefOf.militaristic));
            }

            if (Widgets.ButtonImage(buttonMilitaristic, icon))
            {
                if (numberTraitsSelected <= 1 || boolMilitaristic)
                {
                    //Continue
                    if (boolPacifist == false)
                    {
                        boolMilitaristic = !boolMilitaristic;
                        if (boolMilitaristic)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.militaristic);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolAuthoritarian)
            {
                icon = FCPolicyDefOf.authoritarian.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.authoritarian.IconDark;
            }
            if (buttonAuthoritarian.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonAuthoritarian, returnPolicyText(FCPolicyDefOf.authoritarian));
            }

            if (Widgets.ButtonImage(buttonAuthoritarian, icon))
            {
                if (numberTraitsSelected <= 1 || boolAuthoritarian)
                {
                    //Continue
                    if (boolEgalitarian == false)
                    {
                        boolAuthoritarian = !boolAuthoritarian;
                        if (boolAuthoritarian)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.authoritarian);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolIsolationist)
            {
                icon = FCPolicyDefOf.isolationist.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.isolationist.IconDark;
            }
            if (buttonIsolationist.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonIsolationist, returnPolicyText(FCPolicyDefOf.isolationist));
            }

            if (Widgets.ButtonImage(buttonIsolationist, icon))
            {
                if (numberTraitsSelected <= 1 || boolIsolationist)
                {
                    //Continue
                    if (boolExpansionist == false)
                    {
                        boolIsolationist = !boolIsolationist;
                        if (boolIsolationist)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.isolationist);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolFeudal)
            {
                icon = FCPolicyDefOf.feudal.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.feudal.IconDark;
            }
            if (buttonFeudal.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonFeudal, returnPolicyText(FCPolicyDefOf.feudal));
            }

            if (Widgets.ButtonImage(buttonFeudal, icon))
            {
                if (numberTraitsSelected <= 1 || boolFeudal)
                {
                    //Continue
                    if (boolTechnocrat == false)
                    {
                        boolFeudal = !boolFeudal;
                        if (boolFeudal)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.feudal);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolPacifist)
            {
                icon = FCPolicyDefOf.pacifist.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.pacifist.IconDark;
            }
            if (buttonPacifist.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonPacifist, returnPolicyText(FCPolicyDefOf.pacifist));
            }

            if (Widgets.ButtonImage(buttonPacifist, icon))
            {
                if (numberTraitsSelected <= 1 || boolPacifist)
                {
                    //Continue
                    if (boolMilitaristic == false)
                    {
                        boolPacifist = !boolPacifist;
                        if (boolPacifist)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.pacifist);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolEgalitarian)
            {
                icon = FCPolicyDefOf.egalitarian.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.egalitarian.IconDark;
            }
            if (buttonEgalitarian.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonEgalitarian, returnPolicyText(FCPolicyDefOf.egalitarian));
            }

            if (Widgets.ButtonImage(buttonEgalitarian, icon))
            {
                if (numberTraitsSelected <= 1 || boolEgalitarian)
                {
                    //Continue
                    if (boolAuthoritarian == false)
                    {
                        boolEgalitarian = !boolEgalitarian;
                        if (boolEgalitarian)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.egalitarian);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolExpansionist)
            {
                icon = FCPolicyDefOf.expansionist.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.expansionist.IconDark;
            }
            if (buttonExpansionist.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonExpansionist, returnPolicyText(FCPolicyDefOf.expansionist));
            }

            if (Widgets.ButtonImage(buttonExpansionist, icon))
            {
                if (numberTraitsSelected <= 1 || boolExpansionist)
                {
                    //Continue
                    if (boolIsolationist == false)
                    {
                        boolExpansionist = !boolExpansionist;
                        if (boolExpansionist)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.expansionist);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolTechnocrat)
            {
                icon = FCPolicyDefOf.technocratic.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.technocratic.IconDark;
            }
            if (buttonTechnocrat.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonTechnocrat, returnPolicyText(FCPolicyDefOf.technocratic));
            }

            if (Widgets.ButtonImage(buttonTechnocrat, icon))
            {
                if (numberTraitsSelected <= 1 || boolTechnocrat)
                {
                    //Continue
                    if (boolFeudal == false)
                    {
                        boolTechnocrat = !boolTechnocrat;
                        if (boolTechnocrat)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.technocratic);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            //Widgets.DrawMenuSection(menusectionTrait);
            //Widgets.Label(menusectionTrait, policyText);


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