PotatoPlan/Game1/Sources/Smart/SmartTractor.cs

99 lines
2.6 KiB
C#
Raw Normal View History

2020-05-06 16:22:30 +02:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
2020-05-03 13:05:05 +02:00
class SmartTractor
{
2020-05-05 16:27:45 +02:00
private AI ai = new AI();
2020-05-06 16:22:30 +02:00
private Farm farm = new Farm();
private Astar astar = new Astar();
2020-05-03 13:05:05 +02:00
2020-05-06 16:22:30 +02:00
private Vector2 housePos, tractorPos, Size, Target;
2020-05-03 13:05:05 +02:00
2020-05-06 16:22:30 +02:00
private int Score, Rotation, tileSize = 56, Spacing = 1;
2020-05-05 16:27:45 +02:00
2020-05-06 16:22:30 +02:00
//What to do next
public Path returnChoice()
{
ai.update(farm, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
2020-05-07 21:46:33 +02:00
farm.UpdatePreferedCrops(Size);
2020-05-06 16:22:30 +02:00
farm = ai.changeCropStatus();
2020-05-07 22:09:45 +02:00
astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Rotation);
2020-05-10 13:51:19 +02:00
//getTargetPosition(ai.newTarget());
//astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
2020-05-10 01:38:08 +02:00
if (tractorPos == housePos)
ai.reloadCargo();
2020-05-10 13:51:19 +02:00
2020-05-10 15:02:22 +02:00
return ai.newTarget();
2020-05-10 13:51:19 +02:00
//return astar.FindPath(true);
2020-05-03 13:05:05 +02:00
}
//Updates the variables every frame
2020-05-06 16:22:30 +02:00
public void updateMap(Vector2 newTractorPos, Vector2 newHousePos, Vector2 newSize, int newTileSize, int newSpacing, int rotation)
2020-05-03 13:05:05 +02:00
{
housePos = newHousePos;
tractorPos = newTractorPos;
Size = newSize;
tileSize = newTileSize;
Spacing = newSpacing;
Rotation = rotation;
2020-05-03 13:05:05 +02:00
}
2020-05-10 21:07:03 +02:00
public void init(Vector2 nHousePos)
2020-05-06 16:22:30 +02:00
{
ai.init();
2020-05-10 21:07:03 +02:00
housePos = nHousePos;
2020-05-06 16:22:30 +02:00
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);
}
2020-05-05 16:27:45 +02:00
private void getTargetPosition(Vector2 newTarget)
2020-05-03 13:05:05 +02:00
{
2020-05-05 16:27:45 +02:00
Target = newTarget * (tileSize + Spacing);
2020-05-03 16:35:46 +02:00
}
2020-05-06 16:22:30 +02:00
public Farm getFarm()
{
return farm;
}
public void setNewHousePos(Vector2 pos, bool newState)
{
farm.setNewHousePos(pos, newState);
}
2020-05-23 20:37:11 +02:00
public void UpdateCrops(int Speed, int nDay)
2020-05-06 16:22:30 +02:00
{
for (int i = 0; i < Speed; i++)
{
2020-05-23 20:37:11 +02:00
farm.updateFarm(Size, nDay);
2020-05-06 16:22:30 +02:00
}
}
2020-05-06 20:48:20 +02:00
public Inventory getInventory()
{
return ai.getInventory();
}
2020-05-10 15:02:22 +02:00
public bool getWaitTwoFrames()
{
return ai.WaitTwoFrames;
}
public void setWaitTwoFrames(bool input)
{
ai.WaitTwoFrames = input;
}
2020-05-03 13:05:05 +02:00
}