/// <summary> /// return true if buying is zero /// </summary> internal bool Buy(Producer buyer, PrimitiveStorageSet buying, Procent buyInTime, PrimitiveStorageSet ofWhat) { bool buyingIsEmpty = true; foreach (Storage what in ofWhat) { Storage consumeOnThisEteration = new Storage(what.getProduct(), what.get() * buyInTime.get()); if (consumeOnThisEteration.get() == 0) { return(true); } // check if buying still have enoth to subtract consumeOnThisEteration if (!buying.has(consumeOnThisEteration)) { consumeOnThisEteration = buying.findStorage(what.getProduct()); } consumeOnThisEteration.multipleInside(Consume(buyer, consumeOnThisEteration, null)); buying.subtract(consumeOnThisEteration); if (buying.findStorage(what.getProduct()).get() > 0) { buyingIsEmpty = false; } } return(buyingIsEmpty); }
internal float getInputFactor() { float inputFactor = 1; List <Storage> realInput = new List <Storage>(); //Storage available; // how much we really want foreach (Storage input in type.resourceInput) { realInput.Add(new Storage(input.getProduct(), input.get() * getWorkForceFullFilling())); } // checking if there is enough in market //old DSB //foreach (Storage input in realInput) //{ // available = Game.market.HowMuchAvailable(input); // if (available.get() < input.get()) // input.set(available); //} foreach (Storage input in realInput) { if (!inputReservs.has(input)) { Storage found = inputReservs.findStorage(input.getProduct()); if (found == null) { input.set(0f); } else { input.set(found); } } } //old last turn consumption checking thing //foreach (Storage input in realInput) //{ // //if (Game.market.getDemandSupplyBalance(input.getProduct()) >= 1f) // //available = input // available = consumedLastTurn.findStorage(input.getProduct()); // 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()); //} // searching lowest factor foreach (Storage rInput in realInput)//todo optimize - convert into for i { float newFactor = rInput.get() / (type.resourceInput.findStorage(rInput.getProduct()).get() * getWorkForceFullFilling()); if (newFactor < inputFactor) { inputFactor = newFactor; } } return(inputFactor); }