From ef1e640f9e53dc381e95b48398ddeb3f9eac5799 Mon Sep 17 00:00:00 2001 From: BOTLester <58360400+BOTLester@users.noreply.github.com> Date: Sun, 10 May 2020 18:17:53 +0200 Subject: [PATCH] bugfixes, finetuning --- Game1/Content/ProgressionBarStatus.png | Bin 3316 -> 3311 bytes Game1/Game1.cs | 2 +- Game1/Sources/Crops/Crops.cs | 38 ++++++++++++++++++----- Game1/Sources/Pathing/PriorityQueueC5.cs | 5 +++ Game1/Sources/Smart/AI.cs | 17 +++++++++- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/Game1/Content/ProgressionBarStatus.png b/Game1/Content/ProgressionBarStatus.png index 45b89791d93c85d534c71534cd79a892c9bbd133..d7b9361f085ab6dd4eb4666db9352bc4ab66ee5f 100644 GIT binary patch delta 96 zcmV-m0H6Q#8Sfd8I|~lP000ie0hKEb8<9pRC~QeYK~#8N?bk5@z#tI7z^DE_14Av4 z>28UJtbGjt06^gT3jhG{oU@?;JPWg+0R{mVh|C=6R|u@eU-w)90000gTe~DWM4f D0nH-! diff --git a/Game1/Game1.cs b/Game1/Game1.cs index cbbff67..1a1b4d8 100644 --- a/Game1/Game1.cs +++ b/Game1/Game1.cs @@ -258,7 +258,7 @@ namespace Game1 if ((tractorUnit.getFarm().getCrop(i, j).getStatus() == 3)) { spriteBatch.Draw(ProgressionBar, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 3, j * (input.getSpacingTile()), input.getTileSize() / 3, input.getTileSize()), Color.White); - spriteBatch.Draw(ProgressionBarStatus, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 4, j * (input.getSpacingTile()) + input.getTileSize() / 3, input.getTileSize() / 4, tractorUnit.getFarm().getCrop(i, j).getCropTimerBar((input.getTileSize())) + 1), Color.White); + spriteBatch.Draw(ProgressionBarStatus, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 4, j * (input.getSpacingTile()) + input.getTileSize() / 3, input.getTileSize() / 4, tractorUnit.getFarm().getCrop(i, j).getCropTimerBar((input.getTileSize())) + 1), new Color(tractorUnit.getFarm().getCrop(i, j).getColour())); } spriteBatch.Draw(Crops[tractorUnit.getFarm().getCrop(i, j).getCropType()], new Rectangle((int)(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 2.5), j * (input.getSpacingTile()), (int)(input.getTileSize() / 2.5), input.getTileSize() / 3), Color.White); } diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index d4fd891..74a0b01 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -161,15 +161,15 @@ class Crops if (soilProperties.Nitrogen > 4.0f) { - soilProperties.Nitrogen = soilProperties.Nitrogen - soilProperties.NitrogenDegradeRate; + soilProperties.Nitrogen = soilProperties.Nitrogen - (soilProperties.NitrogenDegradeRate * (float)Math.Pow(ProductionRate, 2)); } if (soilProperties.Phosphorous > 0.1f) { - soilProperties.Phosphorous = soilProperties.Phosphorous - soilProperties.PhosphorousDegradeRate; + soilProperties.Phosphorous = soilProperties.Phosphorous - (soilProperties.PhosphorousDegradeRate * (float)Math.Pow(ProductionRate, 2)); } if (soilProperties.Potassium > 0.1f) { - soilProperties.Potassium = soilProperties.Potassium - soilProperties.PotassiumDegradeRate; + soilProperties.Potassium = soilProperties.Potassium - (soilProperties.PotassiumDegradeRate * (float)Math.Pow(ProductionRate, 2)); } } @@ -232,22 +232,46 @@ class Crops return ((int)(soilProperties.Nitrogen + soilProperties.Potassium + soilProperties.Phosphorous)) < soilProperties.Capacity; } + public Vector4 getColour() + { + float r, g, b, a; + float productionRate, overhead; + + if (ProductionRate > 1.0f) + { + productionRate = 1.0f; + overhead = ProductionRate - 1.0f; + } + else + { + productionRate = ProductionRate; + overhead = 0.0f; + } + + r = (1.0f - productionRate) * 2; + g = 0.0f + productionRate; + b = 0.0f + (float)Math.Pow((double)overhead * 10, 2); + a = 255; + + return new Vector4(r, g, b, a); + } + public float getProductionRate(CropTypes Sample) { ProductionRate = 1; float min = 1.0f; if (DataSet != null) { - ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, Sample.Temparature)); - ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, Sample.Moisture)); - ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Humidity, Sample.Humidity)); + //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, Sample.Temparature)); + //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, Sample.Moisture)); + //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Humidity, Sample.Humidity)); min = Math.Min(compareToDatset(soilProperties.Phosphorous, Sample.Phosphorous), Math.Min(compareToDatset(soilProperties.Potassium, Sample.Potassium), compareToDatset(soilProperties.Nitrogen, Sample.Nitrogen))); ProductionRate = ProductionRate + (ProductionRate * min); if (ProductionRate < 0) { ProductionRate = 0; } - ProductionRate = ProductionRate / 10; + ProductionRate = ProductionRate / 1.5f; } return ProductionRate; } diff --git a/Game1/Sources/Pathing/PriorityQueueC5.cs b/Game1/Sources/Pathing/PriorityQueueC5.cs index c318a73..15017ba 100644 --- a/Game1/Sources/Pathing/PriorityQueueC5.cs +++ b/Game1/Sources/Pathing/PriorityQueueC5.cs @@ -46,4 +46,9 @@ class PriorityQueueC5 queue.AddAll(entryList); } + public int getCount() + { + return queue.Count(); + } + } \ No newline at end of file diff --git a/Game1/Sources/Smart/AI.cs b/Game1/Sources/Smart/AI.cs index 44f007e..1910b5d 100644 --- a/Game1/Sources/Smart/AI.cs +++ b/Game1/Sources/Smart/AI.cs @@ -53,6 +53,11 @@ class AI int count = 0; int testsize = 2; Path newTarget; + Nodes nodes; + if (astar.GetAdjacentNodes(tractorPos).Count == 0) + nodes = new Nodes(housePos); + else + nodes = astar.GetAdjacentNodes(tractorPos)[0]; if (tractorPos != housePos) if (inventory.getWeight() == inventory.getMaxWeight() || inventory.isMissingFertilizer()) { @@ -81,9 +86,19 @@ class AI } if (count > 0) break; + else if (queue.getCount() == 0) + { + astar.update(farm.getCrops(), Size, tractorPos, housePos, nodes.getCords(), Rotation); + return newTarget = astar.FindPath(true); + } else //if (tractorPos != housePos) - return newTarget = GetMaxFNode(testsize, queue); + return newTarget = GetMaxFNode(Math.Min(queue.getCount(), testsize), queue); } + if (queue.getCount() == 0) + { + astar.update(farm.getCrops(), Size, tractorPos, housePos, nodes.getCords(), Rotation); + return newTarget = astar.FindPath(true); + } newTarget = GetMinFNode(Math.Min(testsize, count), queue); queue = null;