Ejemplo n.º 1
0
        public override void consumeNeeds()
        {
            base.consumeNeeds();
            if (artisansProduction != null)
            {
                payWithoutRecord(artisansProduction, cash);

                // take loan if don't have enough money to buy inputs
                if (getCountry().isInvented(Invention.Banking) && !artisansProduction.isAllInputProductsCollected())
                {
                    if (artisansProduction.getType().getPossibleProfit().isNotZero())
                    {
                        var needs = artisansProduction.getRealAllNeeds();
                        if (!artisansProduction.canAfford(needs))
                        {
                            var loanSize = Game.market.getCost(needs); // takes little more than really need, could be fixed
                            if (getBank().canGiveMoney(this, loanSize))
                            {
                                getBank().giveMoney(this, loanSize);
                            }
                            payWithoutRecord(artisansProduction, cash);
                        }
                    }
                }

                artisansProduction.consumeNeeds();
                artisansProduction.payWithoutRecord(this, artisansProduction.cash);

                // consuming made in artisansProduction.consumeNeeds()
                // here is data transfering
                // todo rework data transfering from artisans?
                this.getConsumedInMarket().add(artisansProduction.getConsumedInMarket());
                this.getConsumed().add(artisansProduction.getConsumed());
                this.getConsumedLastTurn().add(artisansProduction.getConsumedLastTurn());
            }
        }
Ejemplo n.º 2
0
        private void changeProductionType()
        {
            KeyValuePair <FactoryType, float> result = new KeyValuePair <FactoryType, float>(null, 0f);

            foreach (FactoryType factoryType in FactoryType.getAllNonResourceTypes(getCountry()))
            {
                float possibleProfit = factoryType.getPossibleProfit().get();
                if (possibleProfit > result.Value)
                {
                    result = new KeyValuePair <FactoryType, float>(factoryType, possibleProfit);
                }
            }
            if (result.Key != null && (artisansProduction == null || artisansProduction != null && result.Key != artisansProduction.getType()))
            {
                artisansProduction = new ArtisanProduction(result.Key, getProvince(), this);
                base.changeProductionType(artisansProduction.getType().basicProduction.getProduct());
            }
        }