290 lines
9.4 KiB
C#
290 lines
9.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
class Crops
|
|
{
|
|
private int Status;
|
|
private int originalStatus;
|
|
private int cropType = 0;
|
|
private float Timer = 1;
|
|
private int UpdateCrop;
|
|
private float fullTimer;
|
|
private bool housePos = false;
|
|
private Vector2 Size;
|
|
private CropTypes DataSet;
|
|
SoilProperties soilProperties = new SoilProperties();
|
|
private float ProductionRate;
|
|
|
|
|
|
|
|
public void updateCrop(Vector2 newSize)
|
|
{
|
|
getProductionRate();
|
|
if (UpdateCrop == 60)
|
|
{
|
|
degradeSoil();
|
|
UpdateCrop = 0;
|
|
}
|
|
|
|
if (Status == 3 && Timer != 1)
|
|
{
|
|
Timer = Timer - 1f * ProductionRate;
|
|
}
|
|
Size = newSize;
|
|
UpdateCrop++;
|
|
|
|
if (Timer < 1)
|
|
{
|
|
Timer = 1;
|
|
}
|
|
}
|
|
|
|
public SoilProperties getSoilProperties()
|
|
{
|
|
return soilProperties;
|
|
}
|
|
|
|
public float getCropTimer()
|
|
{
|
|
return Timer;
|
|
}
|
|
|
|
public int getCropTimerBar(int tileSize)
|
|
{
|
|
|
|
int x = (int)((1 - ((float)Timer / fullTimer)) * (tileSize - tileSize / 3));
|
|
return x;
|
|
}
|
|
|
|
public void init()
|
|
{
|
|
soilProperties.setSoilProperties();
|
|
}
|
|
|
|
// Changes the time required for the crops to be harvestable
|
|
public void setCropTimer()
|
|
{
|
|
if (cropType == 0) // Carrots
|
|
{
|
|
Timer = 300;
|
|
fullTimer = Timer;
|
|
}
|
|
else if (cropType == 1) // Wheat
|
|
{
|
|
Timer = 600;
|
|
fullTimer = Timer;
|
|
}
|
|
else if (cropType == 2) // Berries
|
|
{
|
|
Timer = 1200;
|
|
fullTimer = Timer;
|
|
}
|
|
else // Fruit Trees
|
|
{
|
|
Timer = 2400;
|
|
fullTimer = Timer;
|
|
}
|
|
}
|
|
|
|
public int getCostOnMovement()
|
|
{
|
|
if (Status == 1) //grass
|
|
{
|
|
return 1;
|
|
}
|
|
else if (Status == 2) //dirt
|
|
{
|
|
return 8;
|
|
}
|
|
else
|
|
{
|
|
if (cropType == 0)
|
|
{
|
|
return 15; //Carrots
|
|
}
|
|
else if (cropType == 1)
|
|
{
|
|
return 30; //Wheat
|
|
}
|
|
else if (cropType == 2)
|
|
{
|
|
return 40; //Berries
|
|
}
|
|
else
|
|
{
|
|
return 50; //Fruit Trees
|
|
}
|
|
}
|
|
}
|
|
|
|
public void degradeSoil()
|
|
{
|
|
|
|
if (soilProperties.Nitrogen > 4.0f)
|
|
{
|
|
soilProperties.Nitrogen = soilProperties.Nitrogen - soilProperties.NitrogenDegradeRate;
|
|
}
|
|
if (soilProperties.Phosphorous > 0.1f)
|
|
{
|
|
soilProperties.Phosphorous = soilProperties.Phosphorous - soilProperties.PhosphorousDegradeRate;
|
|
}
|
|
if (soilProperties.Potassium > 0.1f)
|
|
{
|
|
soilProperties.Potassium = soilProperties.Potassium - soilProperties.PotassiumDegradeRate;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public void setCropType(int Type, CropTypes nCropType)
|
|
{
|
|
DataSet = nCropType;
|
|
cropType = Type;
|
|
}
|
|
|
|
public int getStatus()
|
|
{
|
|
if (Status != 3)
|
|
{
|
|
return Status;
|
|
}
|
|
else
|
|
{
|
|
return Status; // + cropType; When unique crop textures have been added
|
|
}
|
|
}
|
|
|
|
public int getCropType()
|
|
{
|
|
return cropType;
|
|
}
|
|
|
|
public void setStatus(int newStatus)
|
|
{
|
|
Status = newStatus;
|
|
}
|
|
|
|
public void setOriginalStatus()
|
|
{
|
|
originalStatus = Status;
|
|
}
|
|
|
|
|
|
public void setHousePos(bool state)
|
|
{
|
|
housePos = state;
|
|
if (state)
|
|
{
|
|
Status = 1;
|
|
}
|
|
else
|
|
{
|
|
Status = originalStatus;
|
|
}
|
|
}
|
|
|
|
public bool getHousePos()
|
|
{
|
|
return housePos;
|
|
}
|
|
|
|
public float getProductionRate(CropTypes Sample)
|
|
{
|
|
ProductionRate = 1;
|
|
if (DataSet != null)
|
|
{
|
|
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, DataSet.Temparature));
|
|
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, DataSet.Moisture));
|
|
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Humidity, DataSet.Humidity));
|
|
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Phosphorous, DataSet.Phosphorous));
|
|
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Potassium, DataSet.Potassium));
|
|
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Nitrogen, DataSet.Nitrogen));
|
|
if (ProductionRate < 0)
|
|
{
|
|
ProductionRate = 0;
|
|
}
|
|
ProductionRate = ProductionRate / 20;
|
|
}
|
|
return ProductionRate;
|
|
}
|
|
|
|
public float compareToDatset(float i, float j)
|
|
{
|
|
if (i < j)
|
|
{
|
|
return (i / j);
|
|
}
|
|
else
|
|
{
|
|
return (j / i);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Inspect(int tileSize, int Spacing, SpriteFont Bold, SpriteBatch spriteBatch, string[] cropTypesNames)
|
|
{
|
|
spriteBatch.Begin();
|
|
if (housePos)
|
|
{
|
|
spriteBatch.DrawString(Bold, "Tiletype: House", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
|
|
}
|
|
else if (Status == 0)
|
|
{
|
|
spriteBatch.DrawString(Bold, "Tiletype: Boulders", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
|
|
}
|
|
else if (Status == 1)
|
|
{
|
|
spriteBatch.DrawString(Bold, "Tiletype: Grassfield", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
|
|
}
|
|
else if (Status == 2)
|
|
{
|
|
spriteBatch.DrawString(Bold, "Tiletype: Soil", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
|
|
}
|
|
else if (Status == 3)
|
|
{
|
|
int x = (int)(((float)Timer / fullTimer) * 100);
|
|
x = 100 - x;
|
|
spriteBatch.DrawString(Bold, "Tiletype: Crop ", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
|
|
spriteBatch.DrawString(Bold, "Completion: " + x + "%", new Vector2(240, Size.Y * (tileSize + Spacing) + 82), Color.DarkBlue);
|
|
}
|
|
if (Status != 3)
|
|
{
|
|
spriteBatch.DrawString(Bold, "-------------", new Vector2(240, Size.Y * (tileSize + Spacing) + 82), Color.DarkRed);
|
|
}
|
|
if (Status > 1)
|
|
{
|
|
spriteBatch.DrawString(Bold, "Prefered Crop: " + cropTypesNames[cropType], new Vector2(240, Size.Y * (tileSize + Spacing) + 62), Color.DarkBlue);
|
|
}
|
|
else
|
|
{
|
|
spriteBatch.DrawString(Bold, "None", new Vector2(240, Size.Y * (tileSize + Spacing) + 62), Color.DarkBlue);
|
|
}
|
|
spriteBatch.DrawString(Bold, "Soil Properties:", new Vector2(240, Size.Y * (tileSize + Spacing) + 122), Color.DarkRed);
|
|
spriteBatch.DrawString(Bold, "Soil Type: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 142), Color.DarkRed);
|
|
spriteBatch.DrawString(Bold, soilProperties.soilType, new Vector2(370, Size.Y * (tileSize + Spacing) + 142), Color.DarkBlue);
|
|
spriteBatch.DrawString(Bold, "Temparature: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 162), Color.DarkRed);
|
|
spriteBatch.DrawString(Bold, soilProperties.Temperature.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 162), Color.DarkBlue);
|
|
spriteBatch.DrawString(Bold, "Moisture: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 182), Color.DarkRed);
|
|
spriteBatch.DrawString(Bold, soilProperties.Moisture.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 182), Color.DarkBlue);
|
|
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, "Phosphorous: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 222), Color.DarkRed);
|
|
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, 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, 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, Math.Round((ProductionRate * 100), 1).ToString() + "%", new Vector2(370, Size.Y * (tileSize + Spacing) + 282), Color.DarkBlue);
|
|
spriteBatch.End();
|
|
}
|
|
}
|