PotatoPlan/Game1/Sources/Smart/SmartTractor.cs
2020-05-24 22:24:32 +02:00

101 lines
2.7 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class SmartTractor
{
private AI ai = new AI();
private Farm farm = new Farm();
private Astar astar = new Astar();
private Vector2 housePos, tractorPos, Size, Target;
private int Score, Rotation, tileSize = 56, Spacing = 1;
//What to do next
public Path returnChoice()
{
//System.Threading.ThreadStart tractorThread = new System.Threading.ThreadStart(farm.UpdatePreferedCrops);
ai.update(farm, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
farm.UpdatePreferedCrops(Size);
farm = ai.changeCropStatus();
astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Rotation);
//getTargetPosition(ai.newTarget());
//astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
if (tractorPos == housePos)
ai.reloadCargo();
return ai.newTarget();
//return astar.FindPath(true);
}
//Updates the variables every frame
public void updateMap(Vector2 newTractorPos, Vector2 newHousePos, Vector2 newSize, int newTileSize, int newSpacing, int rotation)
{
housePos = newHousePos;
tractorPos = newTractorPos;
Size = newSize;
tileSize = newTileSize;
Spacing = newSpacing;
Rotation = rotation;
}
public void init(Vector2 nHousePos)
{
ai.init();
housePos = nHousePos;
farm.init(new Vector2(100, (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / tileSize) - 125 / tileSize), housePos / (tileSize + Spacing));
}
public void drawInventory(Input input, SpriteBatch spriteBatch, SpriteFont Bold, Cargo itemStorageDefined)
{
ai.drawInventory(input, spriteBatch, Bold, itemStorageDefined);
}
private void getTargetPosition(Vector2 newTarget)
{
Target = newTarget * (tileSize + Spacing);
}
public Farm getFarm()
{
return farm;
}
public void setNewHousePos(Vector2 pos, bool newState)
{
farm.setNewHousePos(pos, newState);
}
public void UpdateCrops(int Speed, DayNightCycle nTime)
{
for (int i = 0; i < Speed; i++)
{
farm.updateFarm(Size);
}
farm.updateRainFall(Size, nTime);
}
public Inventory getInventory()
{
return ai.getInventory();
}
public bool getWaitTwoFrames()
{
return ai.WaitTwoFrames;
}
public void setWaitTwoFrames(bool input)
{
ai.WaitTwoFrames = input;
}
}