/// <summary>  Return in pieces basing on current prices and needs  /// </summary>
        //override public float getLocalEffectiveDemand(Product product)
        //{
        //    return getLocalEffectiveDemand(product, getWorkForceFulFilling());
        //}

        /// <summary>
        /// per level
        /// </summary>
        internal Procent getEfficiency(bool useBonuses)
        {
            //limit production by smallest factor
            Procent efficencyFactor;
            Procent workforceProcent = GetWorkForceFulFilling();
            Procent inputFactor      = getInputFactor();

            if (inputFactor.isZero() & isJustHiredPeople())
            {
                inputFactor = Procent.HundredProcent.Copy();
            }

            if (inputFactor.isSmallerThan(workforceProcent))
            {
                efficencyFactor = inputFactor;
            }
            else
            {
                efficencyFactor = workforceProcent;
            }
            //float basicEff = efficencyFactor * getLevel();
            //Procent result = new Procent(basicEff);
            //Procent result = new Procent(efficencyFactor);
            if (useBonuses)
            {
                efficencyFactor.set(efficencyFactor.get() * modifierEfficiency.getModifier(this), false);
            }
            return(efficencyFactor);
        }
Example #2
0
        protected Procent getInputFactor(Procent multiplier)
        {
            if (multiplier.isZero())
            {
                return(Procent.ZeroProcent.Copy());
            }
            if (type.isResourceGathering())
            {
                return(Procent.HundredProcent.Copy());
            }

            List <Storage> reallyNeedResources = new List <Storage>();

            //Storage available;

            // how much we really want
            foreach (Storage input in type.resourceInput)
            {
                reallyNeedResources.Add(input.Copy().Multiply(multiplier));
            }

            // checking if there is enough in market
            //old DSB
            //foreach (Storage input in realInput)
            //{
            //    available = Country.market.HowMuchAvailable(input);
            //    if (available.get() < input.get())
            //        input.set(available);
            //}

            // check if we have enough resources
            foreach (Storage resource in reallyNeedResources)
            {
                Storage haveResource = getInputProductsReserve().getBiggestStorage(resource.Product);
                //if (!getInputProductsReserve().has(resource))
                if (haveResource.isSmallerThan(resource))
                {
                    // what we really have
                    resource.set(haveResource);
                }
            }
            //old last turn consumption checking thing
            //foreach (Storage input in realInput)
            //{
            //    //if (Country.market.getDemandSupplyBalance(input.Product) >= 1f)
            //    //available = input

            //    available = consumedLastTurn.findStorage(input.Product);
            //    if (available == null)
            //        ;// do nothing - pretend there is 100%, it fires only on shownFactory start
            //    else
            //    if (!justHiredPeople && available.get() < input.get())
            //        input.set(available);
            //}
            // checking if there is enough money to pay for
            // doesn't have sense with inputReserv
            //foreach (Storage input in realInput)
            //{
            //    Storage howMuchCan = wallet.HowMuchCanAfford(input);
            //    input.set(howMuchCan.get());
            //}
            var inputFactor = Procent.HundredProcent.Copy();

            // searching lowest factor
            foreach (Storage need in reallyNeedResources)
            {
                Value denominator = type.resourceInput.GetFirstSubstituteStorage(need.Product).Copy().Multiply(multiplier);
                if (denominator.isNotZero())
                {
                    var newfactor = new Procent(need, denominator);
                    if (newfactor.isSmallerThan(inputFactor))
                    {
                        inputFactor = newfactor;
                    }
                }
                else // no resources
                {
                    inputFactor.Set(0f);
                }
            }
            return(inputFactor);
        }