public ItemOrder WillBuyMeal(int item, int amountStored) { //if you don't want anything, stop if (foodQualWant == Quality.None) { return(null); } //if this food is not high enough quality and we're not desperate enough, don't buy if (!WillAcceptFoodTypes(ResourcesDatabase.GetQuality(Enums.GetItemName(item, ItemType.Meal)))) { return(null); } int delta = Hunger; //if we don't have that much food, sell as much as we can if (amountStored < delta) { delta = amountStored; } ItemOrder io = new ItemOrder(delta, item, ItemType.Meal); //if house cannot afford, find the largest amount it can buy for the smallest price if (io.ExchangeValue() > Savings) { float priceOfOne = ResourcesDatabase.GetBasePrice(new ItemOrder(1, item, ItemType.Meal)); int smallestAmount = (int)(Savings / priceOfOne); int smallestAmountWantToBuy = (int)(0.25f * delta); if (smallestAmount <= smallestAmountWantToBuy) { return(null); } io.amount = smallestAmount; } return(io); }
public float ExchangeValue() { //get initial base value (item worth * amount) float baseValue = ResourcesDatabase.GetBasePrice(this); if (city != null) { baseValue += city.distance; } //if (city == null) return(baseValue); //float modifier = city.attitude * 10; //if this is an import, we want to subtract the price if it's from a friendly city, not add to it //if (direction == TradeDirection.Import) // modifier *= -1; //return baseValue * (100 + modifier) / 100; //if attitude is 2, modifier is 20 //if an import, final price is 80% of base //otherwise it's 120% }
public ItemOrder WillBuyGood(int item, int amountStored) { bool wantsToBuy = false; //check the wanted good first if there is one if (goodWanted != GoodType.END) { //only proceed if the good considered is the good that this house wants if ((int)goodWanted == item) { wantsToBuy = true; } } //now we're going to check the same for each good that we need if we don't want it to evolve // if we don't need this good, don't proceed if (!wantsToBuy) { foreach (GoodType good in goodsNeeded) { if ((int)good == item) { wantsToBuy = true; } } } //if we don't want this good, return null if (!wantsToBuy) { return(null); } //the smallest amount we want to buy is 1 unit, and the most we can have is 2 * houseSize // if the vendor has less goods than we want, match that int delta = GoodsMax - Goods[item]; if (amountStored < delta) { delta = amountStored; } ItemOrder io = new ItemOrder(delta, item, ItemType.Good); //if house cannot afford, find the largest amount it can buy for the smallest price if (io.ExchangeValue() > Savings) { float priceOfOne = ResourcesDatabase.GetBasePrice(new ItemOrder(1, item, ItemType.Good)); int smallestAmount = (int)(Savings / priceOfOne); int smallestAmountWantToBuy = (int)(0.25f * delta); if (smallestAmount <= smallestAmountWantToBuy) { return(null); } io.amount = smallestAmount; } return(io); }