Пример #1
0
        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() + "%");
        }
Пример #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.
        }
Пример #3
0
        public static double cycleTraits(double var, string field, List <FCTraitEffectDef> traits, string addOrMultiply)
        {
            double tempTrait = -1;

            if (addOrMultiply == "add")
            {
                tempTrait = 0;
            }
            else
            if (addOrMultiply == "multiply")
            {
                tempTrait = 1;
            }

            foreach (FCTraitEffectDef trait in traits)
            {
                if (addOrMultiply == "add")
                {
                    tempTrait += TraitUtilsFC.returnVariable(new double(), field, trait);
                }
                else
                if (addOrMultiply == "multiply")
                {
                    tempTrait *= TraitUtilsFC.returnVariable(new double(), field, trait);
                }
            }
            return(tempTrait);
        }
Пример #4
0
        public bool resolve()
        {
            FactionFC factionfc = Find.World.GetComponent <FactionFC>();

            if (PaymentUtil.getSilver() >= -1 * taxes.silverAmount || taxes.silverAmount >= 0)
            { //if have enough silver on the current map to pay  & map belongs to player
                FCEventMaker.createTaxEvent(this);
                if (taxes.researchCompleted != 0)
                {
                    factionfc.researchPointPool += taxes.researchCompleted;
                    Messages.Message("PointsAddedToResearchPool".Translate(taxes.researchCompleted), MessageTypeDefOf.PositiveEvent);
                }

                if (taxes.electricityAllotted != 0)
                {
                    factionfc.powerPool += taxes.electricityAllotted;
                }

                return(true);
            }

            Messages.Message("NotEnoughSilverForBill".Translate() + " " + settlement.name + ". " + "ConfiscatedTithes".Translate() + "." + " " + "UnpaidTitheEffect".Translate(), MessageTypeDefOf.NegativeEvent);
            settlement.unrest    += 10 * TraitUtilsFC.cycleTraits(new double(), "unrestGainedMultiplier", settlement.traits, "multiply") * TraitUtilsFC.cycleTraits(new double(), "unrestGainedMultiplier", factionfc.traits, "multiply");
            settlement.happiness -= 10 * TraitUtilsFC.cycleTraits(new double(), "happinessLostMultiplier", settlement.traits, "multiply") * TraitUtilsFC.cycleTraits(new double(), "happinessLostMultiplier", factionfc.traits, "multiply");
            factionfc.Bills.Remove(this);
            return(false);
        }
Пример #5
0
        public double returnLowestCost()
        {
            double minimum = filter.AllowedThingDefs.Aggregate <ThingDef, double>(999999,
                                                                                  (current, thing) => Math.Min(thing?.BaseMarketValue ?? 100, current));

            //Log.Message(minimum.ToString());
            taxMinimumToTithe = minimum + FactionColonies.Settings().productionTitheMod +
                                TraitUtilsFC.cycleTraits("taxBaseRandomModifier", Find.World.GetComponent <FactionFC>().traits, Operation.Addition) +
                                TraitUtilsFC.cycleTraits("taxBaseRandomModifier", settlement.traits, Operation.Addition);
            return(minimum);
        }
Пример #6
0
        public static bool isValidRandomEvent(FCEventDef cEvent)
        {
            FactionFC tmp = Find.World.GetComponent <FactionFC>();

            if (cEvent.isRandomEvent && Find.World.PlayerWealthForStoryteller >= cEvent.requiredWealth)
            {
                //If meets happiness requirement
                if (cEvent.minimumHappiness <= tmp.averageHappiness && tmp.averageHappiness <= cEvent.maximumHappiness)
                {
                    //If meets loyalty requirement
                    if (cEvent.minimumLoyalty <= tmp.averageLoyalty && tmp.averageLoyalty <= cEvent.maximumLoyalty)
                    {
                        //If meets unrest requirement
                        if (cEvent.minimumUnrest <= tmp.averageUnrest && tmp.averageUnrest <= cEvent.maximumUnrest)
                        {
                            //If meets prosperity requirement
                            if (cEvent.minimumProsperity <= tmp.averageProsperity &&
                                tmp.averageProsperity <= cEvent.maximumProsperity)
                            {
                                if (cEvent.rangeSettlementsAffected.min == 0 &&
                                    cEvent.rangeSettlementsAffected.max == 0 ||
                                    Find.World.GetComponent <FactionFC>().settlements.Count() >=
                                    cEvent.rangeSettlementsAffected.min)
                                {
                                    //if doesn't require resource or if required resource has more than 1 production
                                    if (cEvent.requiredResource == null
                                        ? Find.World.GetComponent <FactionFC>().returnResource(cEvent.requiredResource)
                                        .assignedWorkers > 0
                                        : true || (cEvent.requiredResource == "research" &&
                                                   TraitUtilsFC.returnResearchAmount() > 0))
                                    {
                                        //if event is not incompatible with any currently-running events
                                        foreach (FCEvent evt in Find.World.GetComponent <FactionFC>().events)
                                        {
                                            if (evt.def != null)
                                            {
                                                if (cEvent == evt.def)
                                                {
                                                    //if there's already the same event running
                                                    return(false);
                                                }

                                                foreach (FCEventDef inEvt in evt.def.incompatibleEvents)
                                                {
                                                    if (cEvent == inEvt)
                                                    {
                                                        //if not compatible
                                                        return(false);
                                                    }
                                                }
                                            }
                                        }

                                        //If there are no required biomes
                                        if (cEvent.applicableBiomes.Count() != 0)
                                        {
                                            foreach (string biome in cEvent.applicableBiomes)
                                            {
                                                // if(cEvent.)
                                            }
                                        }

                                        //else if compatible
                                        return(true);
                                    }

                                    return(false);
                                }

                                return(false);
                            }

                            return(false);
                        }

                        return(false);
                    }

                    return(false);
                }

                return(false);
            }

            return(false);
        }
Пример #7
0
        //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;
        }