private int getYield(Crop crop) { int yield = (crop.weeks[crop.GetMaturityLength() - 1].Health * crop.GetCropYield()) / 100; yield = Ares * yield; // Zisis to do return(yield); }
private void CalCurrentDate(int week, int CropMaturity, Crop crop) { if (isNotEmptyAtSpecificWeek(week)) { // run Caluclations for that week // First Cultivate Lands NurishLand(week, crop); if (CropMaturity == 0) { //Crop is being intialized crop.FertilizerCosts = 0; crop.WaterCosts = 0; plotWeeks[week].imageNumber = 0; plotWeeks[week].imageChange = true; if (week != 0) { if (plotWeeks[week - 1].isEmpty) { plotWeeks[week - 1].imageNumber = -1; plotWeeks[week - 1].imageChange = true; } } } else if (CropMaturity + 1 == crop.GetMaturityLength()) { //Crop Finished if (plotWeeks.Count > week + 1) { if (plotWeeks[week + 1].isEmpty) { plotWeeks[week + 1].imageChange = true; plotWeeks[week + 1].imageNumber = -1; } } if (crop.weeks[CropMaturity].Health > 0) { cropsHarvested++; } } else if (crop.weeks[CropMaturity].Health == 0 && crop.weeks[CropMaturity - 1].Health != 0) { //Crop Dead plotWeeks[week].imageChange = true; plotWeeks[week].imageNumber = 5; } else { //Run Calculations for Crop CalculateCropWater(week, CropMaturity, crop); // CalculateCropNutrition(week, CropMaturity, crop); // CalculateCropTemperature(week, CropMaturity, crop); CalculateCropGrowth(week, CropMaturity, crop); } } }
private string reasonOfDeath(Crop crop) { int weekofdeath = 0; int weekThatHoldsCrop = 0; for (int i = 0; i < plotWeeks.Count; i++) { if (!plotWeeks[i].isEmpty && plotWeeks[i].getCrop() == crop) { weekThatHoldsCrop = i; break; } } for (int i = weekofdeath; i < crop.GetMaturityLength(); i++) { if (crop.weeks[i].Health < 4) { weekofdeath = i - 1; break; } else { weekThatHoldsCrop++; } } if (plotWeeks[weekThatHoldsCrop].Water < crop.GetWaterMinimum()) { return(crop.GetCropName() + " Died from lack of Water"); } else if (plotWeeks[weekThatHoldsCrop].SoilNutrition < crop.GetNeededNutrition()) { return(crop.GetCropName() + " Died from lack of Nutrients"); } decimal temp = plotWeeks[weekThatHoldsCrop].weather.GetTemp(); decimal tempDifference = temp - crop.GetTemperature(); if (tempDifference < -4) { // Too cold return(crop.GetCropName() + " died because it is too cold"); } else if (tempDifference > 5) { //Too Hot return(crop.GetCropName() + " Died because it is too warm"); } else { return("Unknown Reasons"); } }
private decimal getCropProfits(Crop crop) { decimal profits = 0; int health = crop.weeks[crop.GetMaturityLength() - 1].Health; if (health != 0) { return(profits = (crop.GetSellPrice() * getYield(crop))); } else { return(0); } }
public bool AddCrop(Crop crop) { int length = crop.GetMaturityLength(); if (canInsertPlot(length)) { int week = simulation.CurrentWeek; for (int i = 0; i < length; i++, week++) { plotWeeks[week].setCrop(crop); } hasCrop++; CalBeginToEnd(); return(true); } else { return(false); } }
public void CalBeginToEnd() { cropsHarvested = 0; PlotWaterCost = 0; PlotFertilizerCost = 0; if (hasCrop == 0) { setSoilType(this.soiltype); // resets the Plot } else { int cropsCalculated = 0; for (int startWeek = 0; startWeek < plotWeeks.Count && this.hasCrop != cropsCalculated;) { // If null then has reached the end of PlotWeeks if (!plotWeeks[startWeek].isEmpty) { Crop c = plotWeeks[startWeek].getCrop(); int end = c.GetMaturityLength(); for (int i = 0; i < end; i++, startWeek++) { CalCurrentDate(startWeek, i, c); if (i == end - 1) { cropsCalculated++; } } } else { CalculateWeatherFactors(startWeek); AddWaterToSoil(startWeek, soiltype.GetWaterLoseRate()); startWeek++; } } } }
private void CalculateCropGrowth(int PlotWeek, int CropWeek, Crop crop) { int maturity = crop.GetMaturityLength() / 4; int stage1, stage2, stage3; stage1 = maturity; stage2 = maturity * 2; stage3 = maturity * 3; if (CropWeek == stage1) { plotWeeks[PlotWeek].imageChange = true; plotWeeks[PlotWeek].imageNumber = 1; } else if (CropWeek == stage2) { plotWeeks[PlotWeek].imageChange = true; plotWeeks[PlotWeek].imageNumber = 2; } else if (CropWeek == stage3) { plotWeeks[PlotWeek].imageChange = true; plotWeeks[PlotWeek].imageNumber = 3; } }
private bool isNotEmptyAtSpecificWeek(int week, out Crop getCrop, out int weekCropWasSet) { getCrop = null; weekCropWasSet = 0; if (plotWeeks[week].isEmpty) { return(false); } else { getCrop = plotWeeks[week].getCrop(); // Crop not empty if (week == 0) { weekCropWasSet = 0; //Crop must have been set at week 0 return(true); } else if (plotWeeks[week - 1].isEmpty || plotWeeks[week - 1].getCrop() != getCrop) { // Week before different therefore week is its starting date weekCropWasSet = week; return(true); } else { if ((getCrop.weeks.Count - 1) > week) { // Not enough weeks must go forward to find begin date int EndWeek = (plotWeeks.Count) - week; for (int search = 1; search < EndWeek; search++) { if (search == EndWeek - 1) { weekCropWasSet = (week + search) - getCrop.GetMaturityLength(); return(true); } if (plotWeeks[week + search].isEmpty || plotWeeks[week + search].getCrop() != getCrop) { weekCropWasSet = (week + search) - getCrop.GetMaturityLength(); return(true); } } } else { //Look backwards until found for (int search = week - 2; search >= 0; search--) { if (search == 0) { weekCropWasSet = search; return(true); } if (plotWeeks[search].isEmpty || plotWeeks[search].getCrop() != getCrop) { weekCropWasSet = search + 1; return(true); } } } } } return(true); }
private void NurishLand(int week, Crop crop) { CalculateWeatherFactors(week); AddWaterToSoil(week, -soiltype.GetWaterLoseRate()); decimal AmountOfWaterToAdd = 0; decimal hundred = 100; decimal percentage = 1; if (simulation.Watering == "Minimal") { AmountOfWaterToAdd = crop.GetWaterMinimum() + (crop.GetWaterMinimum() / 100); percentage = 5; } else if (simulation.Watering == "Sufficent") { AmountOfWaterToAdd = ((crop.GetWaterMaximum() + crop.GetWaterMinimum()) / 2) - (crop.GetWaterMinimum() / 100); percentage = 10; } else if (simulation.Watering == "Abundant") { AmountOfWaterToAdd = crop.GetWaterMaximum() - ((crop.GetWaterMaximum() + crop.GetWaterMinimum()) / 10); percentage = 15; } decimal minimumPercentageWater = percentage / hundred; //Give the Plot Enough Water if (((plotWeeks[week].Water - (plotWeeks[week].Water * minimumPercentageWater)) < AmountOfWaterToAdd)) { if (AmountOfWaterToAdd - plotWeeks[week].Water < (soiltype.GetMaximumWater() * minimumPercentageWater)) { AmountOfWaterToAdd = (soiltype.GetMaximumWater() * minimumPercentageWater) + (AmountOfWaterToAdd - plotWeeks[week].Water); } else { AmountOfWaterToAdd = AmountOfWaterToAdd - plotWeeks[week].Water; } decimal excesswater = AddWaterToSoil(week, AmountOfWaterToAdd); PlotWaterCost += addWaterCost(AmountOfWaterToAdd - excesswater); crop.WaterCosts += addWaterCost(AmountOfWaterToAdd - excesswater); } //Nutrition Factors decimal AmountOfFertilizerToAdd = 0; if (simulation.Fertilizer == "Minimal") { AmountOfFertilizerToAdd = (crop.GetNeededNutrition() / Convert.ToDecimal(crop.GetMaturityLength())) * Convert.ToDecimal(0.5); } else if (simulation.Fertilizer == "Sufficent") { AmountOfFertilizerToAdd = crop.GetNeededNutrition() / Convert.ToDecimal(crop.GetMaturityLength()); } else if (simulation.Fertilizer == "Abundant") { AmountOfFertilizerToAdd = (crop.GetNeededNutrition() / Convert.ToDecimal(crop.GetMaturityLength())) * Convert.ToDecimal(1.5); } //Give the Plot Enough Nutrition if (plotWeeks[week].SoilNutrition < AmountOfFertilizerToAdd) { AmountOfFertilizerToAdd = AmountOfFertilizerToAdd - plotWeeks[week].SoilNutrition; AddFertilizerToSoil(week, (AmountOfFertilizerToAdd)); PlotFertilizerCost += addFertilizerCost(AmountOfFertilizerToAdd); crop.FertilizerCosts += addFertilizerCost(AmountOfFertilizerToAdd); } }