1
0
forked from s425077/PotatoPlan

Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML

This commit is contained in:
BOTLester 2020-05-10 21:16:51 +02:00
commit 9e2636641f
5 changed files with 94 additions and 29 deletions

View File

@ -45,6 +45,11 @@ class Crops
}
}
public float getSpeedFactor(float tractorSpeed)
{
return 1f / getCostOnMovement();
}
public SoilProperties getSoilProperties()
{
return soilProperties;
@ -103,7 +108,7 @@ class Crops
// Changes the time required for the crops to be harvestable
public void setCropTimer()
{
if (cropType == 0) // Carrots
if (cropType == 1) // Barley
{
Timer = 300;
fullTimer = Timer;
@ -133,25 +138,53 @@ class Crops
}
else if (Status == 2) //dirt
{
return 16;
return 8;
}
else
{
if (cropType == 0)
if (cropType == 1)
{
return 15; //Carrots
}
else if (cropType == 1)
{
return 30; //Wheat
return 16; //Barley
}
else if (cropType == 2)
{
return 40; //Berries
return 16; //Cotton
}
else if (cropType == 3)
{
return 16; //Ground Nuts
}
else if (cropType == 4)
{
return 16; //Maize
}
else if (cropType == 5)
{
return 16; //Millets
}
else if (cropType == 6)
{
return 16; //Oil Seeds
}
else if (cropType == 7)
{
return 16; //Paddy
}
else if (cropType == 8)
{
return 16; //Pulses
}
else if (cropType == 9)
{
return 16; //Sugarcane
}
else if (cropType == 10)
{
return 16; //Wheat
}
else
{
return 50; //Fruit Trees
return 16; //Tobacco
}
}
}

View File

@ -132,8 +132,11 @@ class Farm
{
for (int j = 0; j < Size.X; j++)
{
int x = getHighestProductionRate(i, j);
crops[i,j].setCropType(x, PresetCrops.getPresetCropTypes(x));
if (crops[i, j].getStatus() != 3)
{
int x = getHighestProductionRate(i, j);
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
}
}
}
}

View File

@ -1,17 +1,24 @@
using Microsoft.Xna.Framework;
using System;
class HandleRotation
{
int rotationSpeed = 5, Rotation = 180;
private float oldSpeed, movementSpeed;
private Vector2 oldTile, oldPosition;
public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position)
public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops)
{
Vector2 Direction;
if (Destination == 0)
if (oldSpeed != crops.getSpeedFactor(tractorSpeed))
{
Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y));
}
if (Destination == 0) // down
{
if (Rotation == 0)
{
Direction = new Vector2(0, 1) * tractorSpeed;
Direction = new Vector2(0, 1) * movementSpeed;
Position = Position + Direction;
}
else
@ -30,11 +37,11 @@ class HandleRotation
}
}
}
else if (Destination == 1)
else if (Destination == 1) // up
{
if (Rotation == 180)
{
Direction = new Vector2(0, -1) * tractorSpeed;
Direction = new Vector2(0, -1) * movementSpeed;
Position = Position + Direction;
}
else
@ -50,11 +57,11 @@ class HandleRotation
}
}
else if (Destination == 2)
else if (Destination == 2) // right
{
if (Rotation == 270)
{
Direction = new Vector2(1, 0) * tractorSpeed;
Direction = new Vector2(1, 0) * movementSpeed;
Position = Position + Direction;
}
else
@ -73,11 +80,11 @@ class HandleRotation
}
}
}
else if (Destination == 3)
else if (Destination == 3) // left
{
if (Rotation == 90)
{
Direction = new Vector2(-1, 0) * tractorSpeed;
Direction = new Vector2(-1, 0) * movementSpeed;
Position = Position + Direction;
}
else
@ -97,6 +104,8 @@ class HandleRotation
}
}
oldSpeed = crops.getSpeedFactor(tractorSpeed);
oldPosition = Position;
return Position;
}
@ -104,4 +113,19 @@ class HandleRotation
{
return Rotation;
}
public bool checkTile(Vector2 Position, int tileSize, int Spacing, float tractorSpeed, Crops crop)
{
Vector2 newTile = new Vector2((float)Math.Round(Position.X / (tileSize + Spacing)), (float)Math.Round(Position.Y / (tileSize + Spacing)));
if (oldTile != newTile)
{
oldTile = newTile;
movementSpeed = crop.getSpeedFactor(tractorSpeed);
return true;
}
else
{
return false;
}
}
}

View File

@ -1,11 +1,12 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
class Tractor
{
private int Spacing, sizeTile, Speed = 1;
private float tractorSpeed = 1;
private Vector2 Position, TargetPosition, Size, housePos;
private Vector2 Position, TargetPosition, Size, housePos, oldDeltaPosition, DeltaPosition;
private Path path = new Path();
private SmartTractor smartTractor = new SmartTractor();
private HandleRotation handleRotation = new HandleRotation();
@ -22,6 +23,7 @@ class Tractor
updatePosition(input.getSize(), Status);
housePos = newHousePos;
smartTractor.UpdateCrops(Speed);
}
public void init(Rectangle house, Input input)
@ -30,13 +32,14 @@ class Tractor
Spacing = input.getSpacing();
Position = housePos;
TargetPosition = new Vector2(house.X, house.Y);
smartTractor.init();
smartTractor.init(new Vector2(house.X, house.Y));
}
// Runs when the tractor reaches a tile
private void updateDirection(Vector2 Size, Vector2 newPosition)
{
Vector2 DeltaPosition = TargetPosition - Position;
DeltaPosition = TargetPosition - Position;
handleRotation.checkTile(Position, sizeTile, Spacing, tractorSpeed, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))));
if (DeltaPosition.X == 0)
{
@ -46,23 +49,24 @@ class Tractor
}
else if (DeltaPosition.Y > 0)
{
Position = handleRotation.UpdatePosition(0, tractorSpeed, Position);
Position = handleRotation.UpdatePosition(0, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))));
}
else if (DeltaPosition.Y < 0)
{
Position = handleRotation.UpdatePosition(1, tractorSpeed, Position);
Position = handleRotation.UpdatePosition(1, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))));
}
}
else if (DeltaPosition.X > 0)
{
Position = handleRotation.UpdatePosition(2, tractorSpeed, Position);
Position = handleRotation.UpdatePosition(2, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))));
}
else if (DeltaPosition.X < 0)
{
Position = handleRotation.UpdatePosition(3, tractorSpeed, Position);
Position = handleRotation.UpdatePosition(3, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))));
}
}
public void updatePosition(Vector2 Size, int Status) // updates the position
{

View File

@ -46,9 +46,10 @@ class SmartTractor
}
public void init()
public void init(Vector2 nHousePos)
{
ai.init();
housePos = nHousePos;
farm.init(new Vector2(100, (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / tileSize) - 125 / tileSize), housePos / (tileSize + Spacing));
}