forked from s425077/PotatoPlan
85 lines
2.2 KiB
C#
85 lines
2.2 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()
|
|
{
|
|
ai.update(farm, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
|
|
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);
|
|
|
|
|
|
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()
|
|
{
|
|
ai.init();
|
|
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)
|
|
{
|
|
for (int i = 0; i < Speed; i++)
|
|
{
|
|
farm.updateFarm(Size);
|
|
}
|
|
}
|
|
|
|
public Inventory getInventory()
|
|
{
|
|
return ai.getInventory();
|
|
}
|
|
}
|