internal override void invest()
        {
            //should I invest?
            if (Economy.isMarket.checkIfTrue(Country) && Country.Invented(Invention.Manufactures))

            {
                // if AverageFactoryWorkforceFulfilling isn't full you can get more workforce by raising salary (implement it later)


                //var projects = Province.getAllInvestmentProjects().Where(x => x.GetMargin(Province).isBiggerThan(Options.minMarginToInvest));
                var projects = World.GetAllAllowedInvestments(this.Country, this);//.Where(x => x.GetMargin().isBiggerThan(Options.minMarginToInvest));
                var project  = projects.MaxByRandom(x => x.GetMargin().Multiply(getBusinessSecurity(x)).get());

                if (project != null && project.GetMargin().Multiply(getBusinessSecurity(project)).isBiggerThan(Options.minMarginToInvest))
                {
                    Value investmentCost = project.GetInvestmentCost();
                    if (!CanPay(investmentCost))
                    {
                        Bank.GiveLackingMoneyInCredit(this, investmentCost);
                    }
                    if (CanPay(investmentCost))
                    {
                        Factory factory = project as Factory;
                        if (factory != null)
                        {
                            if (factory.IsOpen)// upgrade existing factory
                            {
                                factory.upgrade(this);
                            }
                            else
                            {
                                factory.open(this, true);
                            }
                        }
                        else
                        {
                            Owners buyShare = project as Owners;
                            if (buyShare != null) // buy part of existing factory
                            {
                                buyShare.BuyStandardShare(this);
                            }
                            else
                            {
                                var factoryProject = project as NewFactoryProject;
                                if (factoryProject != null)
                                {
                                    Factory factory2 = factoryProject.Province.BuildFactory(this, factoryProject.Type, investmentCost);
                                    PayWithoutRecord(factory2, investmentCost);
                                }
                                else
                                {
                                    Debug.Log("Unknown investment type");
                                }
                            }
                        }
                    }
                }
            }
            base.invest();
        }
Beispiel #2
0
        internal override void invest()
        {
            // Aristocrats invests only in resource factories (and banks)
            if (Province.getResource() != null)
            {
                // if AverageFactoryWorkforceFulfilling isn't full you can get more workforce by raising salary (implement it later)
                var projects = Province.getAllInvestmentProjects(this).Where(x => x.CanProduce(Province.getResource()));

                var project = projects.MaxByRandom(x => x.GetMargin().Multiply(getBusinessSecurity(x)).get());
                if (project != null && project.GetMargin().Multiply(getBusinessSecurity(project)).isBiggerThan(Options.minMarginToInvest))
                {
                    var factoryProject = project as NewFactoryProject; // build new one
                    if (factoryProject != null)
                    {
                        // todo remove connection to grain
                        Storage resourceToBuild = factoryProject.Type.GetBuildNeeds().GetFirstSubstituteStorage(Product.Grain);

                        // try to build for grain
                        if (storage.has(resourceToBuild))
                        {
                            var factory = Province.BuildFactory(this, factoryProject.Type, Game.market.getCost(resourceToBuild));
                            storage.send(factory.getInputProductsReserve(), resourceToBuild);
                            factory.constructionNeeds.setZero();
                        }
                        else // build for money
                        {
                            ReadOnlyValue investmentCost = Game.market.getCost(resourceToBuild);
                            if (!CanPay(investmentCost))
                            {
                                Bank.GiveLackingMoneyInCredit(this, investmentCost);
                            }
                            if (CanPay(investmentCost))
                            {
                                var factory = Province.BuildFactory(this, factoryProject.Type, investmentCost);  // build new one
                                PayWithoutRecord(factory, investmentCost);
                            }
                        }
                    }
                    else
                    {
                        var factory = project as Factory;// existing one
                        if (factory != null)
                        {
                            Value investmentCost = factory.GetInvestmentCost();
                            if (!CanPay(investmentCost))
                            {
                                Bank.GiveLackingMoneyInCredit(this, investmentCost);
                            }
                            if (CanPay(investmentCost))
                            {
                                if (factory.IsOpen)
                                {
                                    factory.upgrade(this);
                                }
                                else
                                {
                                    factory.open(this, true);
                                }
                            }
                        }
                        else
                        {
                            Owners buyShare = project as Owners;
                            if (buyShare != null) // buy part of existing factory
                            {
                                Value investmentCost = buyShare.GetInvestmentCost();
                                if (!CanPay(investmentCost))
                                {
                                    Bank.GiveLackingMoneyInCredit(this, investmentCost);
                                }
                                if (CanPay(investmentCost))
                                {
                                    buyShare.BuyStandardShare(this);
                                }
                            }
                            else
                            {
                                Debug.Log("Unknown investment type");
                            }
                        }
                    }
                }
            }
            base.invest();
        }
Beispiel #3
0
        public override void invest()
        {
            //should I invest?
            if (Economy.isMarket.checkIfTrue(Country) && Country.Science.IsInvented(Invention.Manufactures))
            {
                // if AverageFactoryWorkforceFulfilling isn't full you can get more workforce by raising salary (implement it later)

                //var projects = Province.getAllInvestmentProjects().Where(x => x.GetMargin(Province).isBiggerThan(Options.minMarginToInvest));
                var projects = World.GetAllAllowedInvestments(this).Where(
                    delegate(KeyValuePair <IInvestable, Procent> x)
                {
                    var isFactory = x.Key as Factory;
                    if (isFactory != null)
                    {
                        return(Country.Science.IsInventedFactory(isFactory.Type));
                    }
                    else
                    {
                        var newFactory = x.Key as NewFactoryProject;
                        if (newFactory != null)
                        {
                            return(Country.Science.IsInventedFactory(newFactory.Type));
                        }
                        else
                        {
                            var isBuyingShare = x.Key as Owners;
                            if (isBuyingShare != null)
                            {
                                if (isBuyingShare.HowMuchSelling(this).isNotZero())
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    return(true);
                }
                    );
                if (Game.logInvestments)
                {
                    var c = projects.ToList();
                    c = c.OrderByDescending(x => x.Value.get()).ToList();
                    var d = c.MaxBy(x => x.Value.get());
                    var e = c.MaxByRandom(x => x.Value.get());
                    var f = c.MaxByRandom(x => x.Value.Copy().Multiply(getBusinessSecurity(x.Key)).get());
                    c.Any();
                }
                var project = projects.MaxByRandom(x => x.Value.Copy().Multiply(getBusinessSecurity(x.Key)).get());

                if (!project.Equals(default(KeyValuePair <IInvestable, Procent>)) && project.Value.Copy().Multiply(getBusinessSecurity(project.Key)).isBiggerThan(Options.minMarginToInvest))
                {
                    MoneyView investmentCost = project.Key.GetInvestmentCost(project.Key.Country.market);
                    if (!CanPay(investmentCost))
                    {
                        Bank.GiveLackingMoneyInCredit(this, investmentCost);
                    }
                    if (CanPay(investmentCost))
                    {
                        project.Value.Set(Procent.Zero);
                        Factory factory = project.Key as Factory;
                        if (factory != null)
                        {
                            if (factory.IsOpen)// upgrade existing factory
                            {
                                factory.upgrade(this);
                            }
                            else
                            {
                                factory.open(this, true);
                            }
                        }
                        else
                        {
                            Owners buyShare = project.Key as Owners;
                            if (buyShare != null) // buy part of existing factory
                            {
                                buyShare.BuyStandardShare(this);
                            }
                            else
                            {
                                var factoryProject = project.Key as NewFactoryProject;
                                if (factoryProject != null)
                                {
                                    Factory factory2 = factoryProject.Province.BuildFactory(this, factoryProject.Type, investmentCost);
                                    PayWithoutRecord(factory2, investmentCost, Register.Account.Construction);
                                }
                                else
                                {
                                    Debug.Log("Unknown investment type");
                                }
                            }
                        }
                    }
                }
            }
            base.invest();
        }
Beispiel #4
0
        public override void invest()
        {
            // Aristocrats invests only in resource factories (and banks)
            if (Province.getResource() != null)
            {
                // if AverageFactoryWorkforceFulfilling isn't full you can get more workforce by raising salary (implement it later)
                var projects = Province.AllInvestmentProjects().Where(
                    //x => x.CanProduce(Province.getResource())
                    delegate(IInvestable x)
                {
                    if (!x.CanProduce(Province.getResource()))
                    {
                        return(false);
                    }
                    var isFactory = x as Factory;
                    if (isFactory != null)
                    {
                        return(Country.Science.IsInventedFactory(isFactory.Type));
                    }
                    else
                    {
                        var newFactory = x as NewFactoryProject;
                        if (newFactory != null)
                        {
                            return(Country.Science.IsInventedFactory(newFactory.Type));
                        }
                        else
                        {
                            var isBuyingShare = x as Owners;
                            if (isBuyingShare != null)
                            {
                                if (isBuyingShare.HowMuchSelling(this).isNotZero())
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    return(true);
                }
                    );
                if (Game.logInvestments)
                {
                    var c = projects.ToList();
                    c = c.OrderByDescending(x => x.GetMargin().get()).ToList();
                    var d = c.MaxBy(x => x.GetMargin().get());
                    var e = c.MaxByRandom(x => x.GetMargin().get());
                }
                var project = projects.MaxByRandom(x => x.GetMargin().Multiply(getBusinessSecurity(x)).get());
                if (project != null && project.GetMargin().Multiply(getBusinessSecurity(project)).isBiggerThan(Options.minMarginToInvest))
                {
                    var factoryProject = project as NewFactoryProject; // build new one
                    if (factoryProject != null)
                    {
                        // todo remove connection to grain
                        Storage resourceToBuild = factoryProject.Type.GetBuildNeeds().GetFirstSubstituteStorage(Product.Grain);

                        // try to build for grain
                        if (storage.has(resourceToBuild))
                        {
                            var factory = Province.BuildFactory(this, factoryProject.Type, Country.market.getCost(resourceToBuild));
                            storage.send(factory.getInputProductsReserve(), resourceToBuild);
                            factory.constructionNeeds.setZero();
                        }
                        else // build for money
                        {
                            MoneyView investmentCost = Country.market.getCost(resourceToBuild);
                            if (!CanPay(investmentCost))
                            {
                                Bank.GiveLackingMoneyInCredit(this, investmentCost);
                            }
                            if (CanPay(investmentCost))
                            {
                                var factory = Province.BuildFactory(this, factoryProject.Type, investmentCost);  // build new one
                                PayWithoutRecord(factory, investmentCost, Register.Account.Construction);
                            }
                        }
                    }
                    else
                    {
                        var factory = project as Factory;// existing one
                        if (factory != null)
                        {
                            MoneyView investmentCost = factory.GetInvestmentCost(Country.market);
                            if (!CanPay(investmentCost))
                            {
                                Bank.GiveLackingMoneyInCredit(this, investmentCost);
                            }
                            if (CanPay(investmentCost))
                            {
                                if (factory.IsOpen)
                                {
                                    factory.upgrade(this);
                                }
                                else
                                {
                                    factory.open(this, true);
                                }
                            }
                        }
                        else
                        {
                            Owners buyShare = project as Owners;
                            if (buyShare != null) // buy part of existing factory
                            {
                                MoneyView investmentCost = buyShare.GetInvestmentCost();
                                if (!CanPay(investmentCost))
                                {
                                    Bank.GiveLackingMoneyInCredit(this, investmentCost);
                                }
                                if (CanPay(investmentCost))
                                {
                                    buyShare.BuyStandardShare(this);
                                }
                            }
                            else
                            {
                                Debug.Log("Unknown investment type");
                            }
                        }
                    }
                }
            }
            base.invest();
        }