Production System fixed

This commit is contained in:
Joel 2020-05-07 13:53:07 +02:00
parent da7a7822d4
commit 095ccc0fc6
4 changed files with 42 additions and 34 deletions

View File

@ -75,7 +75,7 @@ class CropTypesHolder
cropTypes[4].Humidity = 57.3f; cropTypes[4].Humidity = 57.3f;
cropTypes[4].Moisture = 38.5f; cropTypes[4].Moisture = 38.5f;
cropTypes[4].Nitrogen = 23.2f; cropTypes[4].Nitrogen = 23.2f;
cropTypes[4].Potassium = 0; cropTypes[4].Potassium = 0.1f;
cropTypes[4].Phosphorous = 14.4f; cropTypes[4].Phosphorous = 14.4f;
//Oil Seeds //Oil Seeds

View File

@ -12,21 +12,23 @@ class Crops
private int Status; private int Status;
private int originalStatus; private int originalStatus;
private int cropType = 0; private int cropType = 0;
private int Timer = 1; private float Timer = 1;
private int UpdateCrop; private int UpdateCrop;
private int fullTimer; private float fullTimer;
private bool housePos = false; private bool housePos = false;
private Vector2 Size; private Vector2 Size;
private CropTypes DataSet; private CropTypes DataSet;
SoilProperties soilProperties = new SoilProperties(); SoilProperties soilProperties = new SoilProperties();
private float ProductionRate = 0;
public void updateCrop(Vector2 newSize) public void updateCrop(Vector2 newSize)
{ {
getProductionRate();
if (Status == 3 && Timer != 1) if (Status == 3 && Timer != 1)
{ {
Timer--; Timer = Timer - 1 * ProductionRate;
} }
Size = newSize; Size = newSize;
UpdateCrop++; UpdateCrop++;
@ -35,6 +37,10 @@ class Crops
degradeSoil(); degradeSoil();
UpdateCrop = 0; UpdateCrop = 0;
} }
if (Timer < 1)
{
Timer = 1;
}
} }
@ -43,7 +49,7 @@ class Crops
return soilProperties; return soilProperties;
} }
public int getCropTimer() public float getCropTimer()
{ {
return Timer; return Timer;
} }
@ -187,38 +193,33 @@ class Crops
return housePos; return housePos;
} }
public float getProductionRate() public void getProductionRate()
{ {
ProductionRate = 1;
if (DataSet != null) if (DataSet != null)
{ {
int ProductionRate = 100; ProductionRate = (ProductionRate * compareToDatset(soilProperties.Temperature, DataSet.Temparature));
ProductionRate = (int)(ProductionRate * compareToDatset(soilProperties.Temperature, DataSet.Temparature)); ProductionRate = (ProductionRate * compareToDatset(soilProperties.Moisture, DataSet.Moisture));
ProductionRate = (int)(ProductionRate * compareToDatset(soilProperties.Moisture , DataSet.Moisture)); ProductionRate = (ProductionRate * compareToDatset(soilProperties.Humidity, DataSet.Humidity));
ProductionRate = (int)(ProductionRate * compareToDatset(soilProperties.Humidity , DataSet.Humidity)); ProductionRate = (ProductionRate * compareToDatset(soilProperties.Phosphorous, DataSet.Phosphorous));
ProductionRate = (int)(ProductionRate * compareToDatset(soilProperties.Phosphorous , DataSet.Phosphorous)); ProductionRate = (ProductionRate * compareToDatset(soilProperties.Potassium, DataSet.Potassium));
ProductionRate = (int)(ProductionRate * compareToDatset(soilProperties.Potassium , DataSet.Potassium)); ProductionRate = (ProductionRate * compareToDatset(soilProperties.Nitrogen, DataSet.Nitrogen));
ProductionRate = (int)(ProductionRate * compareToDatset(soilProperties.Nitrogen , DataSet.Nitrogen));
if (ProductionRate < 0) if (ProductionRate < 0)
{ {
return 0; ProductionRate = 0;
} }
else
{
return ProductionRate;
}
}
else
{
return 0;
} }
} }
public float compareToDatset(float i, float j) public float compareToDatset(float i, float j)
{ {
if (i < j) if (i > j)
{ {
return (i / j) * 0.2f; return (i / j) * 0.15f;
}
else if (i < j / 2)
{
return (i / j) * 2f;
} }
else else
{ {
@ -276,13 +277,13 @@ class Crops
spriteBatch.DrawString(Bold, "Humidity: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 202), Color.DarkRed); spriteBatch.DrawString(Bold, "Humidity: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 202), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Humidity.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 202), Color.DarkBlue); spriteBatch.DrawString(Bold, soilProperties.Humidity.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 202), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Phosphorous: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 222), Color.DarkRed); spriteBatch.DrawString(Bold, "Phosphorous: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 222), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Phosphorous.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 222), Color.DarkBlue); spriteBatch.DrawString(Bold, Math.Round(soilProperties.Phosphorous,1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 222), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Potassium: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 242), Color.DarkRed); spriteBatch.DrawString(Bold, "Potassium: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 242), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Potassium.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 242), Color.DarkBlue); spriteBatch.DrawString(Bold, Math.Round(soilProperties.Potassium, 1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 242), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Nitrogen: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 262), Color.DarkRed); spriteBatch.DrawString(Bold, "Nitrogen: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 262), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Nitrogen.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 262), Color.DarkBlue); spriteBatch.DrawString(Bold, Math.Round(soilProperties.Nitrogen, 1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 262), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Production Rate: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 282), Color.DarkRed); spriteBatch.DrawString(Bold, "Production Rate: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 282), Color.DarkRed);
spriteBatch.DrawString(Bold, getProductionRate().ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 282), Color.DarkBlue); spriteBatch.DrawString(Bold, Math.Round((ProductionRate * 100), 1).ToString() + "%", new Vector2(370, Size.Y * (tileSize + Spacing) + 282), Color.DarkBlue);
spriteBatch.End(); spriteBatch.End();
} }
} }

View File

@ -11,6 +11,7 @@ class Farm
private Crops[,] crops; private Crops[,] crops;
private Random r; private Random r;
private CropTypesHolder PresetCrops = new CropTypesHolder(); private CropTypesHolder PresetCrops = new CropTypesHolder();
private int Update;
//initializes the crops //initializes the crops
@ -43,6 +44,9 @@ class Farm
} }
public void updateFarm(Vector2 Size) public void updateFarm(Vector2 Size)
{
Update++;
if (Update == 30)
{ {
for (int i = 0; i < Size.X; i++) for (int i = 0; i < Size.X; i++)
{ {
@ -52,6 +56,9 @@ class Farm
crops[i, j].updateCrop(Size); crops[i, j].updateCrop(Size);
} }
} }
Update = 0;
}
} }
//Changes the properties of the tile when the tractor reaches this tile. //Changes the properties of the tile when the tractor reaches this tile.

View File

@ -48,8 +48,8 @@ class SoilProperties
Humidity = Temperature * GetRandomNumber(1.9, 2.1); Humidity = Temperature * GetRandomNumber(1.9, 2.1);
Moisture = GetRandomNumber(20, 70); Moisture = GetRandomNumber(20, 70);
Nitrogen = GetRandomNumber(4 , 55); Nitrogen = GetRandomNumber(4 , 55);
Potassium = GetRandomNumber(0, 28); Potassium = GetRandomNumber(0.01f, 28);
Phosphorous = GetRandomNumber(0, 60); Phosphorous = GetRandomNumber(0.01f, 60);
} }
public float GetRandomNumber(double minimum, double maximum) public float GetRandomNumber(double minimum, double maximum)