示例#1
0
    public void onBuildClick()
    {
        //if (Game.player.economy.allowsFactoryBuildingByGovernment())
        {
            bool buildSomething  = false;
            var  resourceToBuild = selectedFactoryType.getBuildNeeds();
            if (Economy.isMarket.checkIftrue(Game.player))
            //if (Game.player.economy.status == Economy.StateCapitalism)
            //have money /resourse
            {
                Value cost = Game.market.getCost(resourceToBuild);
                cost.add(Game.factoryMoneyReservPerLevel);
                if (Game.player.wallet.canPay(cost))
                {
                    var f = new Factory(Game.selectedProvince, Game.player, selectedFactoryType);
                    Game.player.wallet.pay(f.wallet, cost);
                    buildSomething = true;
                    MainCamera.factoryPanel.Show(f);
                }
            }
            else // non market
            {
                Storage needFood = resourceToBuild.findStorage(Product.Food);
                if (Game.player.storageSet.has(needFood))
                {
                    Factory fact = new Factory(Game.selectedProvince, Game.player, selectedFactoryType);

                    //wallet.pay(fact.wallet, new Value(100f));
                    Game.player.storageSet.subtract(needFood);
                    buildSomething = true;
                    MainCamera.factoryPanel.Show(fact);
                }
            }

            if (buildSomething == true)
            {
                // voteButton.interactable = false;
                MainCamera.topPanel.refresh();
                if (MainCamera.productionWindow.isActiveAndEnabled)
                {
                    MainCamera.productionWindow.refresh();
                }
                selectedFactoryType = null;

                //Hide();
                //show();
                refresh();
            }
        }
    }
示例#2
0
    /// <summary>
    /// Now includes workforce/efficineneece. Here also happening buying dor upgrading\building
    /// </summary>
    override public void consume()
    {
        //if (getLevel() > 0)
        if (isWorking())
        {
            List <Storage> needs = getHowMuchReservesWants();

            //todo !CAPITALISM part
            if (isSubsidized())
            {
                Game.market.Buy(this, new PrimitiveStorageSet(needs), province.owner.getCountryWallet());
            }
            else
            {
                Game.market.Buy(this, new PrimitiveStorageSet(needs), null);
            }
        }
        if (isUpgrading() || isBuilding())
        {
            bool isBuyingComplete = false;
            daysInConstruction++;
            bool isMarket = Economy.isMarket.checkIftrue(province.owner);// province.owner.isInvented(InventionType.capitalism);
            if (isMarket)
            {
                if (isBuilding())
                {
                    isBuyingComplete = Game.market.Buy(this, needsToUpgrade, Game.BuyInTimeFactoryUpgradeNeeds, type.getBuildNeeds());
                }
                else
                if (isUpgrading())
                {
                    isBuyingComplete = Game.market.Buy(this, needsToUpgrade, Game.BuyInTimeFactoryUpgradeNeeds, type.getUpgradeNeeds());
                }
                // what if not enough money to complete buildinG?
                float minimalFond = wallet.haveMoney.get() - 50f;

                if (minimalFond < 0 && getOwnerWallet().canPay(minimalFond * -1f))
                {
                    getOwnerWallet().payWithoutRecord(this.wallet, new Value(minimalFond * -1f));
                }
            }
            if (isBuyingComplete || (!isMarket && daysInConstruction == Game.fabricConstructionTimeWithoutCapitalism))
            {
                level++;
                building  = false;
                upgrading = false;
                needsToUpgrade.SetZero();
                daysInConstruction = 0;
                inputReservs.subtract(type.getBuildNeeds());
                inputReservs.subtract(type.getUpgradeNeeds());

                reopen(this);
            }
            else if (daysInConstruction == Game.maxDaysBuildingBeforeRemoving)
            {
                if (isBuilding())
                {
                    markToDestroy();
                }
                else // upgrading
                {
                    stopUpgrading();
                }
            }
        }
    }
示例#3
0
    internal Factory(Province iprovince, Owner inowner, FactoryType intype)
    { //assuming this is level 0 building
        type           = intype;
        needsToUpgrade = type.getBuildNeeds();
        iprovince.allFactories.Add(this);
        factoryOwner = inowner;
        province     = iprovince;

        gainGoodsThisTurn = new Storage(type.basicProduction.getProduct());
        storageNow        = new Storage(type.basicProduction.getProduct());
        sentToMarket      = new Storage(type.basicProduction.getProduct());

        salary.set(province.getLocalMinSalary());


        modifierHasResourceInProvince = new Modifier(delegate(Country forWhom)
        {
            return(!type.isResourceGathering() && province.isProducingOnFactories(type.resourceInput));
        },
                                                     "Has input resource in thst province", true, 20f);
        modifierLevelBonus = new Modifier(delegate() { return(this.getLevel()); }, "High production concetration bonus", true, 5f);
        modifierInventedMiningAndIsShaft = new Modifier(
            delegate(Country forWhom)
        {
            return(forWhom.isInvented(InventionType.mining) && type.isShaft());
        },
            new StringBuilder("Invented ").Append(InventionType.mining.ToString()).ToString(), false, 50f);
        modifierBelongsToCountry = new Modifier(
            delegate(Country forWhom)
        {
            return(factoryOwner is Country);
        },
            "Belongs to government", false, -20f);

        modifierNotBelongsToCountry = new Condition(
            (Country x) => !(factoryOwner is Country),
            "Doesn't belongs to government", false);
        modifierIsSubsidised = new Modifier((x) => isSubsidized(), "Is subsidized", false, -10f);
        modifierEfficiency   = new ModifiersList(new List <Condition>()
        {
            new Modifier(InventionType.steamPower, true, 25f),
            modifierInventedMiningAndIsShaft,
            new Modifier(Economy.StateCapitalism, true, 10f),
            new Modifier(Economy.Interventionism, true, 30f),
            new Modifier(Economy.LaissezFaire, true, 50f),
            new Modifier(Economy.PlannedEconomy, true, -10f),
            modifierHasResourceInProvince, modifierLevelBonus,
            modifierBelongsToCountry, modifierIsSubsidised
        });

        conditionsUpgrade = new ConditionsList(new List <Condition>()
        {
            new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true),
            new Condition(delegate(Owner forWhom) { return(!isUpgrading()); }, "Not upgrading", false),
            new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false),
            new Condition(delegate(Owner forWhom) { return(isWorking()); }, "Open", false),
            new Condition(delegate(Owner forWhom) { return(level != Game.maxFactoryLevel); }, "Max level not achieved", false),
            new Condition(delegate(Owner forWhom) {
                Value cost = this.getUpgradeCost();
                return(forWhom.wallet.canPay(cost));
            }, delegate() {
                Game.threadDangerSB.Clear();
                Game.threadDangerSB.Append("Have ").Append(getUpgradeCost()).Append(" coins");
                return(Game.threadDangerSB.ToString());
            }, true)
        });

        conditionsClose = new ConditionsList(new List <Condition>()
        {
            new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true),
            new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false),
            new Condition(delegate(Owner forWhom) { return(isWorking()); }, "Open", false),
        });
        conditionsReopen = new ConditionsList(new List <Condition>()
        {
            new Condition(delegate(Owner forWhom) { return(province.owner.economy.status != Economy.LaissezFaire || forWhom is PopUnit); }, "Economy policy is not Laissez Faire", true),
            new Condition(delegate(Owner forWhom) { return(!isBuilding()); }, "Not building", false),
            new Condition(delegate(Owner forWhom) { return(!isWorking()); }, "Close", false),
            new Condition(delegate(Owner forWhom) {
                return(forWhom.wallet.canPay(getReopenCost()));
            }, delegate() {
                Game.threadDangerSB.Clear();
                Game.threadDangerSB.Append("Have ").Append(getReopenCost()).Append(" coins");
                return(Game.threadDangerSB.ToString());
            }, true)
        });
        conditionsDestroy = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF
        });
        //status == Economy.LaissezFaire || status == Economy.Interventionism || status == Economy.NaturalEconomy
        conditionsSell = ConditionsList.IsNotImplemented; // !Planned and ! State

        //(status == Economy.StateCapitalism || status == Economy.Interventionism || status == Economy.NaturalEconomy)
        conditionsBuy = ConditionsList.IsNotImplemented; // ! LF and !Planned

        // (status == Economy.PlannedEconomy || status == Economy.NaturalEconomy || status == Economy.StateCapitalism)
        conditionsNatinalize = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Economy.isNotInterventionism, modifierNotBelongsToCountry
        }); //!LF and ! Inter


        conditionsSubsidize = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Economy.isNotNatural
        });

        conditionsDontHireOnSubsidies = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Economy.isNotNatural, Condition.IsNotImplemented
        });

        conditionsChangePriority = new ConditionsList(new List <Condition>()
        {
            Economy.isNotLF, Condition.IsNotImplemented
        });
    }