From 2012c7792fc454a1c64e088e3cd862de921ac759 Mon Sep 17 00:00:00 2001 From: Confectio Date: Mon, 11 Jun 2018 10:58:28 +0200 Subject: [PATCH 01/18] Creating Files --- .../DistributionManager/DistributionManager.cs | 17 +++++++++++++++++ Singularity/Singularity/Singularity.csproj | 1 + 2 files changed, 18 insertions(+) create mode 100644 Singularity/Singularity/DistributionManager/DistributionManager.cs diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs new file mode 100644 index 00000000..f2808152 --- /dev/null +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Singularity.Units; + +namespace Singularity.DistributionManager +{ + [DataContract()] + class DistributionManager + { + [DataMember()] + private List mUnits; + } +} diff --git a/Singularity/Singularity/Singularity.csproj b/Singularity/Singularity/Singularity.csproj index 66f80f46..5f598168 100644 --- a/Singularity/Singularity/Singularity.csproj +++ b/Singularity/Singularity/Singularity.csproj @@ -42,6 +42,7 @@ app.manifest + From 64b1615a2088da1a970e52e15c37dbcc866e42c7 Mon Sep 17 00:00:00 2001 From: Confectio Date: Mon, 11 Jun 2018 11:56:09 +0200 Subject: [PATCH 02/18] Further created frames for DistributionManager --- .../DistributionManager.cs | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index f2808152..daa20977 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -4,7 +4,11 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Singularity.Platform; +using Singularity.Resources; using Singularity.Units; +using Singularity.Utils; +using Action = Singularity.Platform.Action; namespace Singularity.DistributionManager { @@ -12,6 +16,50 @@ namespace Singularity.DistributionManager class DistributionManager { [DataMember()] - private List mUnits; + private List mIdle; + [DataMember()] + private List mConstruction; + [DataMember()] + private List mProduction; + [DataMember()] + private List mDefense; + [DataMember()] + private List mManual; + + [DataMember()] + private Queue> mResourceRequests; + + + //An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) + [DataMember()] + private List mBlueprintBuilds; + + //An der Stelle mit Felix reden, PlatformActionProduce als abstrakte Klasse würde helfen? + //[DataMember()] + //private List mProducingPlatforms; + + //[DataMember()] + //private List mDefensivePlatforms; + + //Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? + + public void ManualAssign(GeneralUnit unit, IPlatformAction action) + { + //Mit Felix reden: Warum ist da überhaupt JobType drin? + //action.AssignUnit(unit, JobType.); + } + + public void ManualUnassign(GeneralUnit unit) + { + //Siehe oben + //IPlatformAction.UnAssignUnits(unit, JobType.); + } + + public void RequestResource(PlatformBlank platform, Resource resource) + { + //Wozu? + } + + public void } } From 1a5ce45295456f4658ece4eb19484e089c8e869b Mon Sep 17 00:00:00 2001 From: Confectio Date: Mon, 11 Jun 2018 15:04:15 +0200 Subject: [PATCH 03/18] Added more logic, but i commented it out... furthermore the need to reimplement GeneralUnit is strong --- .../DistributionManager.cs | 58 +++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index daa20977..179a4281 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -8,7 +8,6 @@ using Singularity.Resources; using Singularity.Units; using Singularity.Utils; -using Action = Singularity.Platform.Action; namespace Singularity.DistributionManager { @@ -27,8 +26,11 @@ class DistributionManager private List mManual; [DataMember()] - private Queue> mResourceRequests; - + private Queue> mBuildingResources; + [DataMember()] + private Queue> mRefiningOrStoringResources; + [DataMember()] + private Queue> mReque //An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) [DataMember()] @@ -43,23 +45,57 @@ class DistributionManager //Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? - public void ManualAssign(GeneralUnit unit, IPlatformAction action) + public DistributionManager() + { + mIdle = new List(); + mConstruction = new List(); + mProduction = new List(); + mDefense = new List(); + mManual = new List(); + + mBuildingResources = new Queue>(); + mRefiningOrStoringResources = new Queue>(); + mBlueprintBuilds = new List(); + } + + public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) { - //Mit Felix reden: Warum ist da überhaupt JobType drin? - //action.AssignUnit(unit, JobType.); + action.AssignUnit(unit, job); } public void ManualUnassign(GeneralUnit unit) { - //Siehe oben - //IPlatformAction.UnAssignUnits(unit, JobType.); + throw new NotImplementedException(); + //I guess we need an extra method for that. } - public void RequestResource(PlatformBlank platform, Resource resource) + public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) { - //Wozu? + Pair request; + if (isbuilding) + { + request = mBuildingResources.Dequeue(); + //GeneralUnit has to be changed (Because wrong implemented). + //I will do that later, + //to not mess with svn + //var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); + //assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); + } + else + { + request = mRefiningOrStoringResources.Dequeue(); + //GeneralUnit has to be changed (Because wrong implemented). + //I will do that later, + //to not mess with svn + //var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); + //assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); + } } - public void + public void RequestUnits(PlatformBlank platform, JobType job) + { + throw new NotImplementedException(); + var request = m + } } } From 46238732616c9a96c8d909fcd2de91017748142e Mon Sep 17 00:00:00 2001 From: Confectio Date: Mon, 11 Jun 2018 16:04:05 +0200 Subject: [PATCH 04/18] I worked through the architecture, I will talk with felix about the details later today --- .../DistributionManager.cs | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 179a4281..509178ad 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -8,6 +8,7 @@ using Singularity.Resources; using Singularity.Units; using Singularity.Utils; +using Action = System.Action; namespace Singularity.DistributionManager { @@ -30,7 +31,7 @@ class DistributionManager [DataMember()] private Queue> mRefiningOrStoringResources; [DataMember()] - private Queue> mReque + private Queue> mRequestedUnits; //An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) [DataMember()] @@ -71,6 +72,8 @@ public void ManualUnassign(GeneralUnit unit) public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) { + throw new NotImplementedException(); + //Will repair request ressources or units? And what unit will be used? Pair request; if (isbuilding) { @@ -95,7 +98,51 @@ public void RequestResource(PlatformBlank platform, Resource resource, bool isbu public void RequestUnits(PlatformBlank platform, JobType job) { throw new NotImplementedException(); - var request = m + var request = mRequestedUnits.Dequeue(); + //Here again a reminder that a platformactionproduce interface would be nice + //if (request.GetSecond().GetType() == PlatformActionProduce) + //{ + // var assignee = mProduction.Find(x => x.GetTask() == Task.Idle()); + //A new type of task, produce, has to be implemented + // assignee.AssignedTask(Task.Produce, request.GetSecond().Platform); + //}elsif (request.GetSecond().GetType() == PlatformActionDefend) + //{ + // var assignee = mDefense.Find(x => x.GetTask() == Task.Idle); + // assignee.AssignedTask(Task.Defend, request.GetSecond().Platform); + //} + } + + //Do we even need that? I think the units should do that + public List PlatformRequests(PlatformBlank platform) + { + return platform.GetPlatformResources(); + } + + //Why does this have to return a Task? It should only take it into the queue + //and thats it, shouldnt it? Furthermore the platformaction shouldnt be optional. This is regarding the architecture. + //The unit should be optional tho, you give the unit only if there are assigned units for the platform. + public void RequestNewTask(Optional unit, JobType job, IPlatformAction action) + { + throw new NotImplementedException(); + switch (job) + { + case JobType.Construction: + foreach (var entry in action.GetRequiredResources()) + { + for (var i = entry.Value; i >= 0; i--) + { + mBuildingResources.Enqueue(new Pair(entry.Key, action)); + } + } + break; + //case JobType.others etc... + } + } + + public void PausePlatformAction(IPlatformAction action) + { + throw new NotImplementedException(); + //Actions need a sleep method } } } From f63cc6fdc789534109e5b551d57a8e7913b22fd5 Mon Sep 17 00:00:00 2001 From: fkarg Date: Tue, 12 Jun 2018 11:41:15 +0200 Subject: [PATCH 05/18] answered questions --- .../DistributionManager.cs | 93 +++++++++++-------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 509178ad..7b40f12d 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -33,21 +33,23 @@ class DistributionManager [DataMember()] private Queue> mRequestedUnits; - //An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) + // An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) - muss ich eh nochmal refactorn mit PlatformBlank und jz dem hier [DataMember()] private List mBlueprintBuilds; - //An der Stelle mit Felix reden, PlatformActionProduce als abstrakte Klasse würde helfen? - //[DataMember()] - //private List mProducingPlatforms; + // An der Stelle mit Felix reden, PlatformActionProduce als abstrakte Klasse würde helfen? + // Mhm weiß nicht ob das wirklich notwendig ist ... ich mach mir mal gedanken + // [DataMember()] + // private List mProducingPlatforms; - //[DataMember()] - //private List mDefensivePlatforms; + // [DataMember()] + // private List mDefensivePlatforms; - //Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? + // Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? + // Momentan ja, aber wenn du ne plattform haben willst die (rein theoretisch) verteidigen und Produzieren gleichzeitig kann? Oder gleichzeitig KineticDefense und LaserDefense ist? public DistributionManager() - { + { mIdle = new List(); mConstruction = new List(); mProduction = new List(); @@ -67,31 +69,34 @@ public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) public void ManualUnassign(GeneralUnit unit) { throw new NotImplementedException(); - //I guess we need an extra method for that. + // I guess we need an extra method for that. + // regarding that: actually we might want to have only the JobType and an integer .. I think I've refactored that somewhere else as well before (Platforms?) } - public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) + // Okay yes you're right. We want a PlatformAction here instead of a platform. + public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) // explain what 'isbuilding' is for, I got confused for a sec { throw new NotImplementedException(); - //Will repair request ressources or units? And what unit will be used? + // Will repair request ressources or units? And what unit will be used? + // We do not have repair yet or anytime soon. Pair request; if (isbuilding) { request = mBuildingResources.Dequeue(); - //GeneralUnit has to be changed (Because wrong implemented). - //I will do that later, - //to not mess with svn - //var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); - //assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); + // GeneralUnit has to be changed (Because wrong implemented). + // I will do that later, + // to not mess with svn + // var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); // no, this is wrong. you need to keep track of units with 'JobType: Idle', as well as those with 'JobType: Construction' but with nothing to do !! (they are supposed to ask for tasks frequently - but easy to get confused here :D + // assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); } else { request = mRefiningOrStoringResources.Dequeue(); - //GeneralUnit has to be changed (Because wrong implemented). - //I will do that later, - //to not mess with svn - //var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); - //assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); + // GeneralUnit has to be changed (Because wrong implemented). + // I will do that later, + // to not mess with svn + // var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); // <- careful with Idle here. They're not assigned to do anything! (we can make that optional later on though) + // assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); } } @@ -99,28 +104,37 @@ public void RequestUnits(PlatformBlank platform, JobType job) { throw new NotImplementedException(); var request = mRequestedUnits.Dequeue(); - //Here again a reminder that a platformactionproduce interface would be nice - //if (request.GetSecond().GetType() == PlatformActionProduce) - //{ - // var assignee = mProduction.Find(x => x.GetTask() == Task.Idle()); - //A new type of task, produce, has to be implemented - // assignee.AssignedTask(Task.Produce, request.GetSecond().Platform); - //}elsif (request.GetSecond().GetType() == PlatformActionDefend) - //{ - // var assignee = mDefense.Find(x => x.GetTask() == Task.Idle); - // assignee.AssignedTask(Task.Defend, request.GetSecond().Platform); - //} + // Here again a reminder that a platformactionproduce interface would be nice + // Produce, and which others? Defense and Construction also ask for units, with different JobTypes. Still, we might want the PlatformAction instead of the platform for pausing later on ... + // + // So, the way this is supposed to work is the following; each platformAction once(!) while being active requests units of the required JobTypes here (Logistics cannot be requested for, it's resulting from ResourceRequests). Now if the PlatformAction pauses it's refernce is getting deleted (it's asked-for units and resources) - and if it's unpaused again it's again requesting once(!) the required units. This can actually be a List with the PlatformActions-id as index or sth ... + // + // if (request.GetSecond().GetType() == PlatformActionProduce) + // { + // var assignee = mProduction.Find(x => x.GetTask() == Task.Idle()); + // A new type of task, produce, has to be implemented + // assignee.AssignedTask(Task.Produce, request.GetSecond().Platform); + // }elsif (request.GetSecond().GetType() == PlatformActionDefend) + // { + // var assignee = mDefense.Find(x => x.GetTask() == Task.Idle); + // assignee.AssignedTask(Task.Defend, request.GetSecond().Platform); + // } } - //Do we even need that? I think the units should do that - public List PlatformRequests(PlatformBlank platform) + // Do we even need that? I think the units should do that - huh? no this was supposed to be from platformId to Resources on that platform, primarily for internal use when searching resources ... if you have actual platform-references all the better (you could probably get them from the producing (and factory) PlatformActions ...) + public List PlatformRequests(PlatformBlank platform) { return platform.GetPlatformResources(); } - //Why does this have to return a Task? It should only take it into the queue - //and thats it, shouldnt it? Furthermore the platformaction shouldnt be optional. This is regarding the architecture. - //The unit should be optional tho, you give the unit only if there are assigned units for the platform. + // Why does this have to return a Task? It should only take it into the queue + // and thats it, shouldnt it? Furthermore the platformaction shouldnt be optional. This is regarding the architecture. + // The unit should be optional tho, you give the unit only if there are assigned units for the platform. + // + // Ah, I can see where your confusion is coming from. So, the version you're thinking about is absolutely valid but needs more (and better) coding. This would be the only 'bigger' function either way. Oh, and it'd absolutely need a different structure ... + // + // Okay, so how was it supposed to work (in my version, if you want to implement it is for you to decide): + // - The units (with nothing to do (idle, but not 'JobType: Idle') ask for new Tasks here. So what is needed is ... actually yes, unit is not required. So the JobType is required, to return a Task of that JobType. Also, if this unit is assigned to some specific PlatformAction (like building a Blueprint, Logistics for a certain Factory, ...), it is supposed to only get Tasks involving this PlatformAction. However, if a unit is not manually assigned somewhere, what action do you want to get here? public void RequestNewTask(Optional unit, JobType job, IPlatformAction action) { throw new NotImplementedException(); @@ -135,14 +149,15 @@ public void RequestNewTask(Optional unit, JobType job, IPlatformAct } } break; - //case JobType.others etc... + // case JobType.others etc... } } public void PausePlatformAction(IPlatformAction action) { throw new NotImplementedException(); - //Actions need a sleep method + // Actions need a sleep method + // No, they're just being removed from occurences in the DistributionManager. As soon as they unpause, they'll send requests for Resources and units again. } } } From 1a8a5efaf01eda7699c9368455f5a5a3530d9af6 Mon Sep 17 00:00:00 2001 From: Confectio Date: Tue, 12 Jun 2018 21:46:57 +0200 Subject: [PATCH 06/18] Just added some comments --- .../DistributionManager/DistributionManager.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 7b40f12d..47dd7e37 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -37,8 +37,10 @@ class DistributionManager [DataMember()] private List mBlueprintBuilds; - // An der Stelle mit Felix reden, PlatformActionProduce als abstrakte Klasse würde helfen? - // Mhm weiß nicht ob das wirklich notwendig ist ... ich mach mir mal gedanken + // L:An der Stelle mit Felix reden, PlatformActionProduce als abstrakte Klasse würde helfen? + // F:Mhm weiß nicht ob das wirklich notwendig ist ... ich mach mir mal gedanken + // L:Zumindest ein interface würde benötigt, ich denke nicht dass der sinn hinter der sache ist für jede produzierende plattform ne extra liste mit + // List zu erstellen. Das gleiche mit mDefensivePlatforms // [DataMember()] // private List mProducingPlatforms; @@ -47,7 +49,7 @@ class DistributionManager // Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? // Momentan ja, aber wenn du ne plattform haben willst die (rein theoretisch) verteidigen und Produzieren gleichzeitig kann? Oder gleichzeitig KineticDefense und LaserDefense ist? - + // Aber wollen wir das? also entweder so, oder halt wie oben vorgeschlagen. public DistributionManager() { mIdle = new List(); @@ -66,19 +68,23 @@ public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) action.AssignUnit(unit, job); } - public void ManualUnassign(GeneralUnit unit) + public void ManualUnassign(JobType job, int i) { throw new NotImplementedException(); // I guess we need an extra method for that. // regarding that: actually we might want to have only the JobType and an integer .. I think I've refactored that somewhere else as well before (Platforms?) + // I guess it was PlatformActions. } // Okay yes you're right. We want a PlatformAction here instead of a platform. - public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) // explain what 'isbuilding' is for, I got confused for a sec + public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) + // explain what 'isbuilding' is for, I got confused for a sec + // I guessed isbuilding is wether the resource requested, has been requested for building or for producing/Storing { throw new NotImplementedException(); // Will repair request ressources or units? And what unit will be used? // We do not have repair yet or anytime soon. + // In that case I guess Ill ignore it for now. Pair request; if (isbuilding) { @@ -158,6 +164,7 @@ public void PausePlatformAction(IPlatformAction action) throw new NotImplementedException(); // Actions need a sleep method // No, they're just being removed from occurences in the DistributionManager. As soon as they unpause, they'll send requests for Resources and units again. + // Ah ok I got that part } } } From 9bd29c4068d8c64b417c9ed4c1efd8af8bcd0247 Mon Sep 17 00:00:00 2001 From: Confectio Date: Tue, 12 Jun 2018 23:54:12 +0200 Subject: [PATCH 07/18] I now got how this class is supposed to work. I will implement it on the demo now to use all the stuff we got there --- .../DistributionManager.cs | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 47dd7e37..0be370a7 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -8,7 +8,6 @@ using Singularity.Resources; using Singularity.Units; using Singularity.Utils; -using Action = System.Action; namespace Singularity.DistributionManager { @@ -130,7 +129,8 @@ public void RequestUnits(PlatformBlank platform, JobType job) // Do we even need that? I think the units should do that - huh? no this was supposed to be from platformId to Resources on that platform, primarily for internal use when searching resources ... if you have actual platform-references all the better (you could probably get them from the producing (and factory) PlatformActions ...) public List PlatformRequests(PlatformBlank platform) { - return platform.GetPlatformResources(); + throw new NotImplementedException(); + //return platform.GetPlatformResources(); } // Why does this have to return a Task? It should only take it into the queue @@ -141,21 +141,13 @@ public List PlatformRequests(PlatformBlank platform) // // Okay, so how was it supposed to work (in my version, if you want to implement it is for you to decide): // - The units (with nothing to do (idle, but not 'JobType: Idle') ask for new Tasks here. So what is needed is ... actually yes, unit is not required. So the JobType is required, to return a Task of that JobType. Also, if this unit is assigned to some specific PlatformAction (like building a Blueprint, Logistics for a certain Factory, ...), it is supposed to only get Tasks involving this PlatformAction. However, if a unit is not manually assigned somewhere, what action do you want to get here? - public void RequestNewTask(Optional unit, JobType job, IPlatformAction action) + public void RequestNewTask(Optional unit, JobType job, Optional assignedAction) { - throw new NotImplementedException(); - switch (job) + switch(job) + { - case JobType.Construction: - foreach (var entry in action.GetRequiredResources()) - { - for (var i = entry.Value; i >= 0; i--) - { - mBuildingResources.Enqueue(new Pair(entry.Key, action)); - } - } - break; - // case JobType.others etc... + case job == JobType.Idle: + } } From 05028720b9c6950115a65ebd2828ce9bd4ae2e1f Mon Sep 17 00:00:00 2001 From: Confectio Date: Wed, 13 Jun 2018 01:28:02 +0200 Subject: [PATCH 08/18] Changed a few Implementation details of the manager and the units. They dont match at all --- .../DistributionManager.cs | 66 +++++++++++++++++-- Singularity/Singularity/Units/GeneralUnit.cs | 52 +++++++++++---- Singularity/Singularity/Units/Task.cs | 3 +- 3 files changed, 101 insertions(+), 20 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 0be370a7..7316fc54 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Remoting.Messaging; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -8,6 +9,7 @@ using Singularity.Resources; using Singularity.Units; using Singularity.Utils; +using Task = Singularity.Units.Task; namespace Singularity.DistributionManager { @@ -62,6 +64,58 @@ public DistributionManager() mBlueprintBuilds = new List(); } + /// + /// This is called by the player, when he wants to distribute the units to certain jobs. + /// + /// + /// + /// + public void DistributeJobs(JobType oldj, JobType newj, int change) + { + throw new NotImplementedException(); + List oldlist; + switch (oldj) + { + case JobType.Construction: + oldlist = mConstruction; + break; + case JobType.Idle: + oldlist = mIdle; + break; + case JobType.Production: + oldlist = mDefense; + break; + case JobType.Defense: + oldlist = mProduction; + break; + } + List newlist; + switch (newj) + { + case JobType.Construction: + newlist = mConstruction; + break; + case JobType.Idle: + newlist = mIdle; + break; + case JobType.Production: + newlist = mDefense; + break; + case JobType.Defense: + newlist = mProduction; + break; + } + for (int i = change; i >= 0; i++) + { + if (oldlist.Count == 0) + { + break; + } + var unassigned = oldlist.First(); + unassigned.ChangeJob(newj); + newlist.Add(unassigned); + } + } public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) { action.AssignUnit(unit, job); @@ -141,14 +195,16 @@ public List PlatformRequests(PlatformBlank platform) // // Okay, so how was it supposed to work (in my version, if you want to implement it is for you to decide): // - The units (with nothing to do (idle, but not 'JobType: Idle') ask for new Tasks here. So what is needed is ... actually yes, unit is not required. So the JobType is required, to return a Task of that JobType. Also, if this unit is assigned to some specific PlatformAction (like building a Blueprint, Logistics for a certain Factory, ...), it is supposed to only get Tasks involving this PlatformAction. However, if a unit is not manually assigned somewhere, what action do you want to get here? - public void RequestNewTask(Optional unit, JobType job, Optional assignedAction) + public Pair RequestNewTask(JobType job, Optional assignedAction) { - switch(job) + throw new NotImplementedException(); + /*switch(job) { - case job == JobType.Idle: - - } + case JobType.Idle: + var random = Generator.randomId; + return new Pair(Task.Move, random); + }*/ } public void PausePlatformAction(IPlatformAction action) diff --git a/Singularity/Singularity/Units/GeneralUnit.cs b/Singularity/Singularity/Units/GeneralUnit.cs index 7ffa0ee8..b40c1908 100644 --- a/Singularity/Singularity/Units/GeneralUnit.cs +++ b/Singularity/Singularity/Units/GeneralUnit.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Singularity.Platform; using Singularity.Property; using Singularity.Resources; +using Singularity.Utils; namespace Singularity.Units { @@ -16,7 +18,16 @@ public class GeneralUnit : IUnit, IUpdate, IDraw private int? mTargetId; private Stack mPathQueue; // the queue of platform and edges the unit has to traverse to get to its target private bool mConstructionResourceFound; // a flag to indicate that the unit has found the construction resource it was looking for + + //These are the assigned task and a flag, wether the unit is done with it. + private Pair mAssignedTask; + + private bool mDone; + + private DistributionManager.DistributionManager mDistrManager; + + private IPlatformAction AssignedAction; // TODO: also use the size for the units representation since we someday need to draw rectangles over units (bounding box) public Vector2 AbsolutePosition { get; set; } @@ -94,6 +105,10 @@ public void AssignedTask(Task assignedTask, int? targetId = null) Job = JobType.Idle; } break; + + //The idea is to use this task to move while your jobtype is idle (since we want these units to move around) + //case Task.Move: + //Move(targetId); } } /// @@ -109,6 +124,15 @@ private Vector2 Move(int targetPosition) return Vector2.Zero; } + /// + /// Used to change the job. Is usually only called if the player wants more/less Units working in a certain job. + /// + /// The job the unit should do. + public void ChangeJob(JobType job) + { + Job = job; + } + /// /// The method called by both construction and defense. Making it its own method simplifies the code. /// @@ -172,25 +196,25 @@ private void Build(int? targetPlatformId) } public void Update(GameTime gametime) { - // use switch to change between jobs - switch (Job) + + // I think the intention here was to do the tasks. + switch (mAssignedTask.GetFirst()) { - case JobType.Idle: - // does nothing + case Task.Idle: + mAssignedTask = mDistrManager.RequestNewTask(Job, Optional.Of(AssignedAction)); break; - case JobType.Construction: - // runs build() - Build(mTargetId); + case Task.Move: + //Move around break; - case JobType.Logistics: - // TODO unclear how this should be implmented + case Task.BuildPlatform: + //Build(); break; - case JobType.Defense: - // basically the same as the construction one - Build(mTargetId); + case Task.MoveResource: + //MoveResource(); + break; + case Task.RepairPlatform: + //Repair(); break; - default: - throw new ArgumentOutOfRangeException(); } throw new NotImplementedException(); } diff --git a/Singularity/Singularity/Units/Task.cs b/Singularity/Singularity/Units/Task.cs index 8db75186..47d2c124 100644 --- a/Singularity/Singularity/Units/Task.cs +++ b/Singularity/Singularity/Units/Task.cs @@ -5,6 +5,7 @@ public enum Task Idle, BuildPlatform, MoveResource, - RepairPlatform + RepairPlatform, + Move } } From 474dcc0840978348a0330f96aa13d8fadf32185c Mon Sep 17 00:00:00 2001 From: Confectio Date: Wed, 13 Jun 2018 16:06:49 +0200 Subject: [PATCH 09/18] Changed ManualAssign to match the idea --- .../DistributionManager.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 7316fc54..68c3552f 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -118,7 +118,30 @@ public void DistributeJobs(JobType oldj, JobType newj, int change) } public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) { + throw new NotImplementedException(); + var ujob = unit.Job; + List oldlist; + switch (ujob) + { + case JobType.Construction: + oldlist = mConstruction; + break; + case JobType.Idle: + oldlist = mIdle; + break; + case JobType.Production: + oldlist = mDefense; + break; + case JobType.Defense: + oldlist = mProduction; + break; + } + + var removeit = oldlist.Find(x => x.Equals(unit)); + oldlist.Remove(removeit); + mManual.Add(removeit); action.AssignUnit(unit, job); + } public void ManualUnassign(JobType job, int i) From b316aee83cdf3446ad51493e5ff2efa1fd5b3899 Mon Sep 17 00:00:00 2001 From: Confectio Date: Thu, 14 Jun 2018 02:59:32 +0200 Subject: [PATCH 10/18] Replaced the Task class and further modified GeneralUnit --- .../Singularity/DistributionManager/Task.cs | 37 +++++++++++++++++++ Singularity/Singularity/Singularity.csproj | 2 +- Singularity/Singularity/Units/GeneralUnit.cs | 22 +++++++++-- Singularity/Singularity/Units/Task.cs | 11 ------ Singularity/Singularity/Utils/Optional.cs | 2 +- 5 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 Singularity/Singularity/DistributionManager/Task.cs delete mode 100644 Singularity/Singularity/Units/Task.cs diff --git a/Singularity/Singularity/DistributionManager/Task.cs b/Singularity/Singularity/DistributionManager/Task.cs new file mode 100644 index 00000000..a2a12bbd --- /dev/null +++ b/Singularity/Singularity/DistributionManager/Task.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Security.AccessControl; +using System.Text; +using System.Threading.Tasks; +using Singularity.Resources; +using Singularity.Units; +using Singularity.Utils; + +namespace Singularity.DistributionManager +{ + [DataContract()] + public class Task + { + [DataMember()] + public JobType Job { get; set; } + + [DataMember()] + public int? StartId { get; set; } + + [DataMember()] + public int? EndId { get; set; } + + [DataMember()] + public Optional Getres { get; set; } + + public Task(JobType job, int? start, int? end, Optional res) + { + Job = job; + StartId = start; + EndId = end; + Getres = res; + } + } +} diff --git a/Singularity/Singularity/Singularity.csproj b/Singularity/Singularity/Singularity.csproj index 92fb0999..6d140aa7 100644 --- a/Singularity/Singularity/Singularity.csproj +++ b/Singularity/Singularity/Singularity.csproj @@ -43,6 +43,7 @@ + @@ -123,7 +124,6 @@ - diff --git a/Singularity/Singularity/Units/GeneralUnit.cs b/Singularity/Singularity/Units/GeneralUnit.cs index b40c1908..55fbf678 100644 --- a/Singularity/Singularity/Units/GeneralUnit.cs +++ b/Singularity/Singularity/Units/GeneralUnit.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Runtime.Serialization; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Singularity.DistributionManager; using Singularity.Platform; using Singularity.Property; using Singularity.Resources; @@ -9,25 +11,34 @@ namespace Singularity.Units { + [DataContract()] public class GeneralUnit : IUnit, IUpdate, IDraw { + [DataMember()] public int Id { get; } + [DataMember()] private int mPositionId; + [DataMember()] public string Assignment { get; set; } // TODO change to an enum type - public EResourceType Carrying { get; set; } // TODO change resource into a nullable type + [DataMember()] + public Resource Carrying { get; set; } // TODO change resource into a nullable type + [DataMember()] private int? mTargetId; + [DataMember()] private Stack mPathQueue; // the queue of platform and edges the unit has to traverse to get to its target + [DataMember()] private bool mConstructionResourceFound; // a flag to indicate that the unit has found the construction resource it was looking for //These are the assigned task and a flag, wether the unit is done with it. - private Pair mAssignedTask; + private Task mAssignedTask; private bool mDone; private DistributionManager.DistributionManager mDistrManager; private IPlatformAction AssignedAction; + // TODO: also use the size for the units representation since we someday need to draw rectangles over units (bounding box) public Vector2 AbsolutePosition { get; set; } @@ -45,7 +56,7 @@ public GeneralUnit(int spawnPositionId) Id = 0; // TODO make this randomized or simply ascending AbsolutePosition = Vector2.Zero; // TODO figure out how to search platform by ID and get its position mPositionId = spawnPositionId; - Carrying = EResourceType.Trash; // TODO change this to a nullable type or some other implementation after dist manager is implemented + Carrying = null; // TODO change this to a nullable type or some other implementation after dist manager is implemented mPathQueue = null; } /// @@ -57,6 +68,7 @@ public GeneralUnit(int spawnPositionId) /// which it should do the Task on. public void AssignedTask(Task assignedTask, int? targetId = null) { + throw new NotImplementedException(); switch (assignedTask) { case Task.Idle: @@ -118,6 +130,7 @@ public void AssignedTask(Task assignedTask, int? targetId = null) /// private Vector2 Move(int targetPosition) { + throw new NotImplementedException(); // first get the target position Vector2 position // then move x distance in that direction or until above the coordinate of the position // TODO @@ -139,6 +152,7 @@ public void ChangeJob(JobType job) /// The target platform that is to be constructed or repaired. private void Build(int? targetPlatformId) { + throw new NotImplementedException(); // pop out the required resource from the required resource list of the target platform // then goes and finds the nearest storage platform with that resource // does this by finding (using BFS) closest storage platform and querying it @@ -196,7 +210,7 @@ private void Build(int? targetPlatformId) } public void Update(GameTime gametime) { - + throw new NotImplementedException(); // I think the intention here was to do the tasks. switch (mAssignedTask.GetFirst()) { diff --git a/Singularity/Singularity/Units/Task.cs b/Singularity/Singularity/Units/Task.cs deleted file mode 100644 index 47d2c124..00000000 --- a/Singularity/Singularity/Units/Task.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Singularity.Units -{ - public enum Task - { - Idle, - BuildPlatform, - MoveResource, - RepairPlatform, - Move - } -} diff --git a/Singularity/Singularity/Utils/Optional.cs b/Singularity/Singularity/Utils/Optional.cs index 0ab613ab..ca5e2190 100644 --- a/Singularity/Singularity/Utils/Optional.cs +++ b/Singularity/Singularity/Utils/Optional.cs @@ -8,7 +8,7 @@ namespace Singularity.Utils /// and Get() will return the value. /// /// The type of this optional - internal sealed class Optional + public sealed class Optional { private readonly T mValue; From 7946af0bd5151a6a7683561bc1b1bb42b560397f Mon Sep 17 00:00:00 2001 From: Confectio Date: Fri, 15 Jun 2018 02:08:36 +0200 Subject: [PATCH 11/18] Resolved numerous errors. Further implemented the DistributionManager --- .../DistributionManager.cs | 133 ++++++++++-------- .../Singularity/DistributionManager/Task.cs | 16 ++- .../Singularity/Libraries/Bloom Filter.cs | 30 ++-- Singularity/Singularity/Map/StructureMap.cs | 9 ++ .../Singularity/Platform/PlatformBlank.cs | 2 +- .../Screen/ScreenClasses/GameScreen.cs | 11 +- Singularity/Singularity/Units/MilitaryUnit.cs | 2 +- Singularity/Singularity/Utils/IdGenerator.cs | 2 +- 8 files changed, 116 insertions(+), 89 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 547e43a5..1e0c12dc 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Runtime.Remoting.Messaging; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Singularity.Exceptions; using Singularity.Platform; using Singularity.Resources; using Singularity.Units; @@ -18,6 +20,8 @@ public class DistributionManager [DataMember()] private List mIdle; [DataMember()] + private List mLogistics; + [DataMember()] private List mConstruction; [DataMember()] private List mProduction; @@ -27,11 +31,13 @@ public class DistributionManager private List mManual; [DataMember()] - private Queue> mBuildingResources; + private Queue mBuildingResources; + [DataMember()] + private Queue mRefiningOrStoringResources; [DataMember()] - private Queue> mRefiningOrStoringResources; + private Queue mRequestedUnitsProduce; [DataMember()] - private Queue> mRequestedUnits; + private Queue mRequestedUnitsDefense; // An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) - muss ich eh nochmal refactorn mit PlatformBlank und jz dem hier [DataMember()] @@ -53,23 +59,26 @@ public class DistributionManager public DistributionManager() { mIdle = new List(); + mLogistics = new List(); mConstruction = new List(); mProduction = new List(); mDefense = new List(); mManual = new List(); - mBuildingResources = new Queue>(); - mRefiningOrStoringResources = new Queue>(); + mBuildingResources = new Queue(); + mRefiningOrStoringResources = new Queue(); + mRequestedUnitsProduce = new Queue(); + mRequestedUnitsDefense = new Queue(); mBlueprintBuilds = new List(); } /// /// This is called by the player, when he wants to distribute the units to certain jobs. /// - /// - /// - /// - public void DistributeJobs(JobType oldj, JobType newj, int change) + /// The old job of the units + /// The new job of the units + /// The amount of units to be transferred + public void DistributeJobs(JobType oldj, JobType newj, int amount) { List oldlist; switch (oldj) @@ -77,6 +86,9 @@ public void DistributeJobs(JobType oldj, JobType newj, int change) case JobType.Construction: oldlist = mConstruction; break; + case JobType.Logistics: + oldlist = mLogistics; + break; case JobType.Idle: oldlist = mIdle; break; @@ -86,6 +98,9 @@ public void DistributeJobs(JobType oldj, JobType newj, int change) case JobType.Defense: oldlist = mProduction; break; + default: + throw new InvalidGenericArgumentException("You have to use a JobType of Idle, Production, Logistics, Construction or Defense."); + } List newlist; switch (newj) @@ -96,14 +111,19 @@ public void DistributeJobs(JobType oldj, JobType newj, int change) case JobType.Idle: newlist = mIdle; break; + case JobType.Logistics: + newlist = mLogistics; + break; case JobType.Production: newlist = mDefense; break; case JobType.Defense: newlist = mProduction; break; + default: + throw new InvalidGenericArgumentException("You have to use a JobType of Idle, Production, Logistics, Construction or Defense."); } - for (int i = change; i >= 0; i++) + for (var i = amount; i >= 0; i--) { if (oldlist.Count == 0) { @@ -114,12 +134,17 @@ public void DistributeJobs(JobType oldj, JobType newj, int change) newlist.Add(unassigned); } } - public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) + + /// + /// Manually Assign Units to a certain PlatformAction. + /// + /// The amount of units to be assigned + /// The action to which the units shall be assigned + /// The Job the units are supposed to have. + public void ManualAssign(int amount, IPlatformAction action, JobType job) { - throw new NotImplementedException(); - var ujob = unit.Job; List oldlist; - switch (ujob) + switch (job) { case JobType.Construction: oldlist = mConstruction; @@ -133,72 +158,62 @@ public void ManualAssign(GeneralUnit unit, IPlatformAction action, JobType job) case JobType.Defense: oldlist = mProduction; break; + case JobType.Logistics: + oldlist = mLogistics; + break; + default: + throw new InvalidGenericArgumentException("You have to use a JobType of Idle, Production, Logistics, Construction or Defense."); } - var removeit = oldlist.Find(x => x.Equals(unit)); - oldlist.Remove(removeit); - mManual.Add(removeit); - action.AssignUnit(unit, job); - + for (var i = amount; i >= 0; i--) + { + var removeit = oldlist.First(); + oldlist.Remove(removeit); + mManual.Add(removeit); + action.AssignUnit(removeit, job); + } } - public void ManualUnassign(JobType job, int i) + /// + /// Manually Unassign some units of a Platformaction. + /// + /// The Job they are having + /// The amount of units to be unassigned + /// The platformaction of which they shall be unassigned + public void ManualUnassign(JobType job, int amount, IPlatformAction action) { - throw new NotImplementedException(); - // I guess we need an extra method for that. - // regarding that: actually we might want to have only the JobType and an integer .. I think I've refactored that somewhere else as well before (Platforms?) - // I guess it was PlatformActions. + action.UnAssignUnits(amount, job); } // Okay yes you're right. We want a PlatformAction here instead of a platform. - public void RequestResource(PlatformBlank platform, Resource resource, bool isbuilding = false) - // explain what 'isbuilding' is for, I got confused for a sec - // I guessed isbuilding is wether the resource requested, has been requested for building or for producing/Storing + public void RequestResource(PlatformBlank platform, EResourceType resource, IPlatformAction action, bool isbuilding = false) { - throw new NotImplementedException(); // Will repair request ressources or units? And what unit will be used? // We do not have repair yet or anytime soon. // In that case I guess Ill ignore it for now. - Pair request; + //TODO: Create Action references, when interfaces were created. if (isbuilding) { - request = mBuildingResources.Dequeue(); - // GeneralUnit has to be changed (Because wrong implemented). - // I will do that later, - // to not mess with svn - // var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); // no, this is wrong. you need to keep track of units with 'JobType: Idle', as well as those with 'JobType: Construction' but with nothing to do !! (they are supposed to ask for tasks frequently - but easy to get confused here :D - // assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); + mBuildingResources.Enqueue(new Task(JobType.Construction, platform, resource, action)); } else { - request = mRefiningOrStoringResources.Dequeue(); - // GeneralUnit has to be changed (Because wrong implemented). - // I will do that later, - // to not mess with svn - // var assignee = mConstruction.Find(x => x.GetTask() == Task.Idle); // <- careful with Idle here. They're not assigned to do anything! (we can make that optional later on though) - // assignee.AssignedTask(Task.BuildPlatform, Pair.GetFirst(), Pair.GetSecond().Platform); + mRefiningOrStoringResources.Enqueue(new Task(JobType.Logistics, platform, resource, action)); } } - public void RequestUnits(PlatformBlank platform, JobType job) + public void RequestUnits(PlatformBlank platform, JobType job, IPlatformAction action, bool isdefending = false) { - throw new NotImplementedException(); - var request = mRequestedUnits.Dequeue(); - // Here again a reminder that a platformactionproduce interface would be nice - // Produce, and which others? Defense and Construction also ask for units, with different JobTypes. Still, we might want the PlatformAction instead of the platform for pausing later on ... - // - // So, the way this is supposed to work is the following; each platformAction once(!) while being active requests units of the required JobTypes here (Logistics cannot be requested for, it's resulting from ResourceRequests). Now if the PlatformAction pauses it's refernce is getting deleted (it's asked-for units and resources) - and if it's unpaused again it's again requesting once(!) the required units. This can actually be a List with the PlatformActions-id as index or sth ... - // - // if (request.GetSecond().GetType() == PlatformActionProduce) - // { - // var assignee = mProduction.Find(x => x.GetTask() == Task.Idle()); - // A new type of task, produce, has to be implemented - // assignee.AssignedTask(Task.Produce, request.GetSecond().Platform); - // }elsif (request.GetSecond().GetType() == PlatformActionDefend) - // { - // var assignee = mDefense.Find(x => x.GetTask() == Task.Idle); - // assignee.AssignedTask(Task.Defend, request.GetSecond().Platform); - // } + //TODO: Create Action references, when interfaces were created. + EResourceType? resource = null; + if (isdefending) + { + mRequestedUnitsDefense.Enqueue(new Task(JobType.Construction, platform, resource, action)); + } + else + { + mRequestedUnitsProduce.Enqueue(new Task(JobType.Logistics, platform, resource, action)); + } } // Do we even need that? I think the units should do that - huh? no this was supposed to be from platformId to Resources on that platform, primarily for internal use when searching resources ... if you have actual platform-references all the better (you could probably get them from the producing (and factory) PlatformActions ...) diff --git a/Singularity/Singularity/DistributionManager/Task.cs b/Singularity/Singularity/DistributionManager/Task.cs index a2a12bbd..022df489 100644 --- a/Singularity/Singularity/DistributionManager/Task.cs +++ b/Singularity/Singularity/DistributionManager/Task.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Dynamic; using System.Linq; using System.Runtime.Serialization; using System.Security.AccessControl; using System.Text; using System.Threading.Tasks; +using Singularity.Platform; using Singularity.Resources; using Singularity.Units; using Singularity.Utils; @@ -18,20 +20,20 @@ public class Task public JobType Job { get; set; } [DataMember()] - public int? StartId { get; set; } + public PlatformBlank End { get; set; } [DataMember()] - public int? EndId { get; set; } - + public IPlatformAction Action { get; set; } + [DataMember()] - public Optional Getres { get; set; } + public EResourceType? Getres { get; set; } - public Task(JobType job, int? start, int? end, Optional res) + public Task(JobType job, PlatformBlank end, EResourceType? res, IPlatformAction action) { Job = job; - StartId = start; - EndId = end; + End = end; Getres = res; + Action = action; } } } diff --git a/Singularity/Singularity/Libraries/Bloom Filter.cs b/Singularity/Singularity/Libraries/Bloom Filter.cs index ffd17415..85de9844 100644 --- a/Singularity/Singularity/Libraries/Bloom Filter.cs +++ b/Singularity/Singularity/Libraries/Bloom Filter.cs @@ -32,7 +32,7 @@ namespace Libraries /// Then we downscale this extraction layer to the next mip map. /// While doing that we sample several pixels around the origin. /// We continue to downsample a few more times, defined in - /// BloomDownsamplePasses = 5 ( default is 5) + /// mBloomDownsamplePasses = 5 ( default is 5) /// /// Afterwards we upsample again, but blur in this step, too. /// The final output should be a blur with a very large kernel and smooth gradient. @@ -95,7 +95,7 @@ public class BloomFilter : IDisposable private float mBloomStrength4 = 1.0f; private float mBloomStrength5 = 1.0f; - public float BloomStrengthMultiplier = 1.0f; + private float BloomStrengthMultiplier = 1.0f; private float mRadiusMultiplier = 1.0f; @@ -104,8 +104,8 @@ public class BloomFilter : IDisposable #region public fields + enums - public bool BloomUseLuminance = true; - public int BloomDownsamplePasses = 5; + private bool BloomUseLuminance = true; + private int mBloomDownsamplePasses = 5; //enums public enum BloomPresets @@ -298,7 +298,7 @@ private void SetBloomPreset(BloomPresets preset) mBloomRadius2 = 2.0f; mBloomRadius1 = 1.0f; BloomStreakLength = 1; - BloomDownsamplePasses = 5; + mBloomDownsamplePasses = 5; break; } case BloomPresets.SuperWide: @@ -314,7 +314,7 @@ private void SetBloomPreset(BloomPresets preset) mBloomRadius2 = 2.0f; mBloomRadius1 = 2.0f; BloomStreakLength = 1; - BloomDownsamplePasses = 5; + mBloomDownsamplePasses = 5; break; } case BloomPresets.Focussed: @@ -330,7 +330,7 @@ private void SetBloomPreset(BloomPresets preset) mBloomRadius2 = 2.0f; mBloomRadius1 = 2.0f; BloomStreakLength = 1; - BloomDownsamplePasses = 5; + mBloomDownsamplePasses = 5; break; } case BloomPresets.Small: @@ -346,7 +346,7 @@ private void SetBloomPreset(BloomPresets preset) mBloomRadius2 = 1; mBloomRadius1 = 1; BloomStreakLength = 1; - BloomDownsamplePasses = 5; + mBloomDownsamplePasses = 5; break; } case BloomPresets.Cheap: @@ -356,7 +356,7 @@ private void SetBloomPreset(BloomPresets preset) mBloomRadius2 = 2; mBloomRadius1 = 2; BloomStreakLength = 1; - BloomDownsamplePasses = 2; + mBloomDownsamplePasses = 2; break; } case BloomPresets.One: @@ -372,7 +372,7 @@ private void SetBloomPreset(BloomPresets preset) mBloomRadius2 = 1.0f; mBloomRadius1 = 1.0f; BloomStreakLength = 1; - BloomDownsamplePasses = 5; + mBloomDownsamplePasses = 5; break; } } @@ -431,7 +431,7 @@ public Texture2D Draw(Texture2D inputTexture, int width, int height) mQuadRenderer.RenderQuad(mGraphicsDevice, Vector2.One * -1, Vector2.One); //Now downsample to the next lower mip texture - if (BloomDownsamplePasses > 0) + if (mBloomDownsamplePasses > 0) { //DOWNSAMPLE TO MIP1 mGraphicsDevice.SetRenderTarget(mBloomRenderTarget2DMip1); @@ -441,7 +441,7 @@ public Texture2D Draw(Texture2D inputTexture, int width, int height) mBloomPassDownsample.Apply(); mQuadRenderer.RenderQuad(mGraphicsDevice, Vector2.One * -1, Vector2.One); - if (BloomDownsamplePasses > 1) + if (mBloomDownsamplePasses > 1) { //Our input resolution is halfed, so our inverse 1/res. must be doubled BloomInverseResolution *= 2; @@ -454,7 +454,7 @@ public Texture2D Draw(Texture2D inputTexture, int width, int height) mBloomPassDownsample.Apply(); mQuadRenderer.RenderQuad(mGraphicsDevice, Vector2.One * -1, Vector2.One); - if (BloomDownsamplePasses > 2) + if (mBloomDownsamplePasses > 2) { BloomInverseResolution *= 2; @@ -466,7 +466,7 @@ public Texture2D Draw(Texture2D inputTexture, int width, int height) mBloomPassDownsample.Apply(); mQuadRenderer.RenderQuad(mGraphicsDevice, Vector2.One * -1, Vector2.One); - if (BloomDownsamplePasses > 3) + if (mBloomDownsamplePasses > 3) { BloomInverseResolution *= 2; @@ -478,7 +478,7 @@ public Texture2D Draw(Texture2D inputTexture, int width, int height) mBloomPassDownsample.Apply(); mQuadRenderer.RenderQuad(mGraphicsDevice, Vector2.One * -1, Vector2.One); - if (BloomDownsamplePasses > 4) + if (mBloomDownsamplePasses > 4) { BloomInverseResolution *= 2; diff --git a/Singularity/Singularity/Map/StructureMap.cs b/Singularity/Singularity/Map/StructureMap.cs index e8ede491..9a54a029 100644 --- a/Singularity/Singularity/Map/StructureMap.cs +++ b/Singularity/Singularity/Map/StructureMap.cs @@ -43,6 +43,15 @@ public StructureMap(PathManager pathManager) mRoads = new LinkedList(); } + /// + /// A method existing so the DistributionManager has access to all platforms. + /// + /// + public LinkedList GetPlatformList() + { + return mPlatforms; + } + /// /// Adds the specified platform to this map. /// diff --git a/Singularity/Singularity/Platform/PlatformBlank.cs b/Singularity/Singularity/Platform/PlatformBlank.cs index 8c5009be..6baaa781 100644 --- a/Singularity/Singularity/Platform/PlatformBlank.cs +++ b/Singularity/Singularity/Platform/PlatformBlank.cs @@ -336,7 +336,7 @@ public void Update(GameTime t) public PlatformBlank(Vector2 position, Texture2D spritesheet, Vector2 center = new Vector2()) { - Id = IdGenerator.NextID(); + Id = IdGenerator.NextiD(); mInwardsEdges = new List(); mOutwardsEdges = new List(); diff --git a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs index 22ad11b0..c80385ce 100644 --- a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs +++ b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs @@ -147,6 +147,7 @@ public void Update(GameTime gametime) public void LoadContent(ContentManager content) { var pathManager = new PathManager(); + var dist = new DistributionManager.DistributionManager(); var mapBackground = content.Load("MockUpBackground"); mMUnitSheet = content.Load("UnitSpriteSheet"); @@ -161,8 +162,8 @@ public void LoadContent(ContentManager content) mPlatform2 = new Junkyard(new Vector2(800, 600), mPlatformDomeTexture); mPlatform3 = new EnergyFacility(new Vector2(600, 200), mPlatformDomeTexture); mPlatform3 = new EnergyFacility(new Vector2(600, 200), mPlatformDomeTexture); - var genUnit2 = new GeneralUnit(mPlatform2, pathManager); - var genUnit3 = new GeneralUnit(mPlatform3, pathManager); + var genUnit2 = new GeneralUnit(mPlatform2, pathManager, dist); + var genUnit3 = new GeneralUnit(mPlatform3, pathManager, dist); mMap = new Map.Map(mapBackground, mGraphicsDevice.Viewport, mInputManager, pathManager, true); @@ -171,9 +172,9 @@ public void LoadContent(ContentManager content) var platform4 = new Well(new Vector2(1000, 200), mPlatformDomeTexture, mMap.GetResourceMap()); var platform5 = new Quarry(new Vector2(1300, 400), mPlatformDomeTexture, mMap.GetResourceMap()); - var genUnit = new GeneralUnit(mPlatform, pathManager); - var genUnit4 = new GeneralUnit(platform4, pathManager); - var genUnit5 = new GeneralUnit(platform5, pathManager); + var genUnit = new GeneralUnit(mPlatform, pathManager, dist); + var genUnit4 = new GeneralUnit(platform4, pathManager, dist); + var genUnit5 = new GeneralUnit(platform5, pathManager, dist); mFow = new FogOfWar(mCamera, mGraphicsDevice); diff --git a/Singularity/Singularity/Units/MilitaryUnit.cs b/Singularity/Singularity/Units/MilitaryUnit.cs index fc17aa13..15595f57 100644 --- a/Singularity/Singularity/Units/MilitaryUnit.cs +++ b/Singularity/Singularity/Units/MilitaryUnit.cs @@ -65,7 +65,7 @@ internal sealed class MilitaryUnit : ICollider, IUnit, IDraw, IUpdate, IRevealin public MilitaryUnit(Vector2 position, Texture2D spriteSheet, Camera camera, InputManager manager) { - Id = IdGenerator.NextID(); // TODO this will later use a random number generator to create a unique + Id = IdGenerator.NextiD(); // TODO this will later use a random number generator to create a unique // id for the specific unit. Health = 10; //TODO diff --git a/Singularity/Singularity/Utils/IdGenerator.cs b/Singularity/Singularity/Utils/IdGenerator.cs index d6fe3cab..655d876d 100644 --- a/Singularity/Singularity/Utils/IdGenerator.cs +++ b/Singularity/Singularity/Utils/IdGenerator.cs @@ -10,7 +10,7 @@ public static class IdGenerator { private static int sId = 0; - public static int NextID() + public static int NextiD() { sId++; return sId; From 396ad4538184336018a0599f48e77897426ec9b9 Mon Sep 17 00:00:00 2001 From: Confectio Date: Fri, 15 Jun 2018 03:46:46 +0200 Subject: [PATCH 12/18] The Distribution of Idle Units works now. --- .../DistributionManager.cs | 46 ++++++++++++++----- .../Singularity/Graph/Paths/PathManager.cs | 4 +- Singularity/Singularity/Map/Map.cs | 2 +- Singularity/Singularity/Map/StructureMap.cs | 2 +- Singularity/Singularity/Platform/Road.cs | 2 +- .../Screen/ScreenClasses/GameScreen.cs | 8 ++-- Singularity/Singularity/Units/GeneralUnit.cs | 29 ++++++++++-- Singularity/Singularity/Units/IUnit.cs | 2 +- 8 files changed, 69 insertions(+), 26 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 1e0c12dc..a190611d 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.Eventing; using System.Linq; using System.Runtime.Remoting.Messaging; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using Singularity.Exceptions; +using Singularity.Map; using Singularity.Platform; using Singularity.Resources; using Singularity.Units; @@ -30,6 +32,9 @@ public class DistributionManager [DataMember()] private List mManual; + [DataMember()] + private StructureMap mStructure; + [DataMember()] private Queue mBuildingResources; [DataMember()] @@ -47,16 +52,13 @@ public class DistributionManager // F:Mhm weiß nicht ob das wirklich notwendig ist ... ich mach mir mal gedanken // L:Zumindest ein interface würde benötigt, ich denke nicht dass der sinn hinter der sache ist für jede produzierende plattform ne extra liste mit // List zu erstellen. Das gleiche mit mDefensivePlatforms - // [DataMember()] - // private List mProducingPlatforms; - - // [DataMember()] - // private List mDefensivePlatforms; + [DataMember()] + private List mPlatformActions; // Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? // Momentan ja, aber wenn du ne plattform haben willst die (rein theoretisch) verteidigen und Produzieren gleichzeitig kann? Oder gleichzeitig KineticDefense und LaserDefense ist? // Aber wollen wir das? also entweder so, oder halt wie oben vorgeschlagen. - public DistributionManager() + public DistributionManager(StructureMap structure) { mIdle = new List(); mLogistics = new List(); @@ -65,13 +67,24 @@ public DistributionManager() mDefense = new List(); mManual = new List(); + mStructure = structure; + mBuildingResources = new Queue(); mRefiningOrStoringResources = new Queue(); mRequestedUnitsProduce = new Queue(); mRequestedUnitsDefense = new Queue(); mBlueprintBuilds = new List(); + mPlatformActions = new List(); } + /// + /// Is called by the unit when it is created. + /// + /// the unit that has been created + public void Register(GeneralUnit unit) + { + mIdle.Add(unit); + } /// /// This is called by the player, when he wants to distribute the units to certain jobs. /// @@ -233,14 +246,23 @@ public List PlatformRequests(PlatformBlank platform) // - The units (with nothing to do (idle, but not 'JobType: Idle') ask for new Tasks here. So what is needed is ... actually yes, unit is not required. So the JobType is required, to return a Task of that JobType. Also, if this unit is assigned to some specific PlatformAction (like building a Blueprint, Logistics for a certain Factory, ...), it is supposed to only get Tasks involving this PlatformAction. However, if a unit is not manually assigned somewhere, what action do you want to get here? public Task RequestNewTask(JobType job, Optional assignedAction) { - throw new NotImplementedException(); - /*switch(job) - + switch(job) + //TODO: Implement other Job cases. { case JobType.Idle: - var random = Generator.randomId; - return new Pair(Task.Move, random); - }*/ + //TODO: + //Find a more efficient way to determine the random platform to go to. It has to be Platformreferences (Julian requested it) + //but the List of Platforms currently used is a linkedlist which is not very efficient with ELementAt(); + //Maybe use the Graph somehow in the future + var plist = mStructure.GetPlatformList(); + var random = new Random(); + var rndnmbr = random.Next(1, plist.Count - 1); + //Just give them the inside of the Optional action witchout checking because + //it doesnt matter anyway if its null if the unit is idle. + return new Task(job, plist.ElementAt(rndnmbr), null, assignedAction.Get()); + } + //TODO: Make this disappear when the rest is implemented, since its only a placeholder + return new Task(job, mStructure.GetPlatformList().ElementAt(0), null, assignedAction.Get()); } public void PausePlatformAction(IPlatformAction action) diff --git a/Singularity/Singularity/Graph/Paths/PathManager.cs b/Singularity/Singularity/Graph/Paths/PathManager.cs index fb504c4a..7b309068 100644 --- a/Singularity/Singularity/Graph/Paths/PathManager.cs +++ b/Singularity/Singularity/Graph/Paths/PathManager.cs @@ -64,14 +64,14 @@ public IPath GetPath(T unit, INode destination) } throw new InvalidGenericArgumentException( - "The given argument was not one for which pathes are meant to be calculated. The following are" + + "The given argument was not one for which paths are meant to be calculated. The following are" + "supported: MilitaryUnit and GeneralUnit."); } private IPath GetPathForGeneralUnits(GeneralUnit unit, INode destination) { - //todo: know which units are on which graph + //todo: know which units are on which graph. return PathfindingFactory.GetPathfinding().AStar(mGraphs[0], unit.CurrentNode, destination); } diff --git a/Singularity/Singularity/Map/Map.cs b/Singularity/Singularity/Map/Map.cs index a47dc4a0..5ec131fe 100644 --- a/Singularity/Singularity/Map/Map.cs +++ b/Singularity/Singularity/Map/Map.cs @@ -18,7 +18,7 @@ namespace Singularity.Map internal sealed class Map : IDraw, IUpdate { private readonly CollisionMap mCollisionMap; - private readonly StructureMap mStructureMap; + public readonly StructureMap mStructureMap; private readonly ResourceMap mResourceMap; private readonly Camera mCamera; diff --git a/Singularity/Singularity/Map/StructureMap.cs b/Singularity/Singularity/Map/StructureMap.cs index 9a54a029..89ae3656 100644 --- a/Singularity/Singularity/Map/StructureMap.cs +++ b/Singularity/Singularity/Map/StructureMap.cs @@ -11,7 +11,7 @@ namespace Singularity.Map /// /// A Structure map holds all the structures currently in the game. /// - internal sealed class StructureMap + public sealed class StructureMap { /// /// A list of all the platforms currently in the game diff --git a/Singularity/Singularity/Platform/Road.cs b/Singularity/Singularity/Platform/Road.cs index f5a18c80..a4233130 100644 --- a/Singularity/Singularity/Platform/Road.cs +++ b/Singularity/Singularity/Platform/Road.cs @@ -7,7 +7,7 @@ namespace Singularity.Platform { - internal sealed class Road : ISpatial, IEdge + public sealed class Road : ISpatial, IEdge { private PlatformBlank Source { get; } diff --git a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs index c80385ce..bee4ea29 100644 --- a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs +++ b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs @@ -147,8 +147,10 @@ public void Update(GameTime gametime) public void LoadContent(ContentManager content) { var pathManager = new PathManager(); - var dist = new DistributionManager.DistributionManager(); var mapBackground = content.Load("MockUpBackground"); + mMap = new Map.Map(mapBackground, mGraphicsDevice.Viewport, mInputManager, pathManager, true); + mCamera = mMap.GetCamera(); + var dist = new DistributionManager.DistributionManager(mMap.mStructureMap); mMUnitSheet = content.Load("UnitSpriteSheet"); @@ -165,10 +167,6 @@ public void LoadContent(ContentManager content) var genUnit2 = new GeneralUnit(mPlatform2, pathManager, dist); var genUnit3 = new GeneralUnit(mPlatform3, pathManager, dist); - - mMap = new Map.Map(mapBackground, mGraphicsDevice.Viewport, mInputManager, pathManager, true); - mCamera = mMap.GetCamera(); - var platform4 = new Well(new Vector2(1000, 200), mPlatformDomeTexture, mMap.GetResourceMap()); var platform5 = new Quarry(new Vector2(1300, 400), mPlatformDomeTexture, mMap.GetResourceMap()); diff --git a/Singularity/Singularity/Units/GeneralUnit.cs b/Singularity/Singularity/Units/GeneralUnit.cs index 70321281..35ca2e86 100644 --- a/Singularity/Singularity/Units/GeneralUnit.cs +++ b/Singularity/Singularity/Units/GeneralUnit.cs @@ -97,6 +97,8 @@ public GeneralUnit(PlatformBlank platform, PathManager pathManager, Distribution mIsMoving = false; mPathManager = pathManager; mDistrManager = distrManager; + distrManager.Register(this); + mDone = true; } /// /// Used to pick the Task that the unit does. It assigns the unit to a job which the update method uses @@ -108,7 +110,7 @@ public GeneralUnit(PlatformBlank platform, PathManager pathManager, Distribution public void AssignedTask(Task assignedTask, int? targetId = null) { throw new NotImplementedException(); - switch (assignedTask) + /*switch (assignedTask) { case Task.Idle: Job = JobType.Idle; @@ -159,9 +161,10 @@ public void AssignedTask(Task assignedTask, int? targetId = null) //The idea is to use this task to move while your jobtype is idle (since we want these units to move around) //case Task.Move: - //Move(targetId); - } + //Move(targetId); + }*/ } + /// /// Moves the unit to the target position by its given speed. /// @@ -251,8 +254,24 @@ private void Build(int? targetPlatformId) */ } + + /// + /// Only contains implementation for the Idle case so far + /// + /// public void Update(GameTime gametime) { + if (!mIsMoving && mDone) + { + mDone = false; + if (Job == JobType.Idle) + { + //Care!!! DO NOT UNDER ANY CIRCUMSTANCES USE THIS PLACEHOLDER + IPlatformAction action = new ProduceMineResource(null, null); + mAssignedTask = mDistrManager.RequestNewTask(Job, Optional.Of(action)); + mDestination = mAssignedTask.End; + } + } // if this if clause is fulfilled we get a new path to move to. // we only do this if we're not moving, have no destination and our // current nodequeue is empty (the path) @@ -292,6 +311,10 @@ private bool ReachedTarget(Vector2 target) //since we're operating with float values we just want the distance to be smaller than 2 pixels. if (Vector2.Distance(AbsolutePosition, target) < 2) { + if (Job == JobType.Idle) + { + mDone = true; + } CurrentNode = mCurrentNode; mDestination = null; mIsMoving = false; diff --git a/Singularity/Singularity/Units/IUnit.cs b/Singularity/Singularity/Units/IUnit.cs index 5b3978e1..24bf680b 100644 --- a/Singularity/Singularity/Units/IUnit.cs +++ b/Singularity/Singularity/Units/IUnit.cs @@ -14,6 +14,6 @@ interface IUnit /// /// Type will eventually be Assignment type /// - String Assignment { get; set; } + string Assignment { get; set; } } } From f7d9037dc38e1772da34bdd9108f0a46aebb68fc Mon Sep 17 00:00:00 2001 From: Ativelox Date: Fri, 15 Jun 2018 11:04:00 +0900 Subject: [PATCH 13/18] Adjusted center for energy facility Just noticed that the center for the energy facility was off, just forgot to do it on my branch so I did it here quickly. Didn't change anything else --- Singularity/Singularity/Platform/EnergyFacility.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Singularity/Singularity/Platform/EnergyFacility.cs b/Singularity/Singularity/Platform/EnergyFacility.cs index 9c52be98..7b70ce1f 100644 --- a/Singularity/Singularity/Platform/EnergyFacility.cs +++ b/Singularity/Singularity/Platform/EnergyFacility.cs @@ -12,16 +12,14 @@ namespace Singularity.Platform { [DataContract()] - class EnergyFacility : PlatformBlank, IRevealing + class EnergyFacility : PlatformBlank { [DataMember()] private const int PlatformWidth = 144; [DataMember()] private const int PlatformHeight = 127; - public new Vector2 Center => new Vector2(AbsolutePosition.X + PlatformWidth / 2, AbsolutePosition.Y + PlatformHeight - 36); - - public EnergyFacility(Vector2 position, Texture2D spritesheet): base(position, spritesheet) + public EnergyFacility(Vector2 position, Texture2D spritesheet): base(position, spritesheet, new Vector2(position.X + PlatformWidth / 2f, position.Y + PlatformHeight - 36)) { mIPlatformActions = new IPlatformAction[2]; //mActions[0] = BuildPlatformBlueprint(this); From 0c1765803272a9be00796bbb082264a529216680 Mon Sep 17 00:00:00 2001 From: Confectio Date: Sat, 16 Jun 2018 13:51:38 +0200 Subject: [PATCH 14/18] Improved Randomising of destinations --- .../DistributionManager/DistributionManager.cs | 6 ++++-- Singularity/Singularity/Units/GeneralUnit.cs | 10 ++++------ Singularity/Singularity/Units/IUnit.cs | 5 ----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index a190611d..a73120fc 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -44,6 +44,8 @@ public class DistributionManager [DataMember()] private Queue mRequestedUnitsDefense; + [DataMember()] + private Random mRandom; // An Felix: Vielleicht BuildBluePrint nicht in "ProduceResourceAction.cs" reinhauen (da hätte ich nicht danach gesucht) - muss ich eh nochmal refactorn mit PlatformBlank und jz dem hier [DataMember()] private List mBlueprintBuilds; @@ -75,6 +77,7 @@ public DistributionManager(StructureMap structure) mRequestedUnitsDefense = new Queue(); mBlueprintBuilds = new List(); mPlatformActions = new List(); + mRandom = new Random(); } /// @@ -255,8 +258,7 @@ public Task RequestNewTask(JobType job, Optional assignedAction //but the List of Platforms currently used is a linkedlist which is not very efficient with ELementAt(); //Maybe use the Graph somehow in the future var plist = mStructure.GetPlatformList(); - var random = new Random(); - var rndnmbr = random.Next(1, plist.Count - 1); + var rndnmbr = mRandom.Next(1, plist.Count - 1); //Just give them the inside of the Optional action witchout checking because //it doesnt matter anyway if its null if the unit is idle. return new Task(job, plist.ElementAt(rndnmbr), null, assignedAction.Get()); diff --git a/Singularity/Singularity/Units/GeneralUnit.cs b/Singularity/Singularity/Units/GeneralUnit.cs index 35ca2e86..42ef6443 100644 --- a/Singularity/Singularity/Units/GeneralUnit.cs +++ b/Singularity/Singularity/Units/GeneralUnit.cs @@ -24,8 +24,6 @@ public class GeneralUnit : IUnit, IUpdate, IDraw, ISpatial [DataMember()] private int mPositionId; [DataMember()] - public string Assignment { get; set; } // TODO change to an enum type - [DataMember()] public Optional Carrying { get; set; } // TODO change resource into a nullable type [DataMember()] private int? mTargetId; @@ -297,6 +295,10 @@ public void Update(GameTime gametime) // check whether we have reached the target after our move call. ReachedTarget(((PlatformBlank)mCurrentNode).Center); + if (mNodeQueue.Count == 0 && Job == JobType.Idle) + { + mDone = true; + } } @@ -311,10 +313,6 @@ private bool ReachedTarget(Vector2 target) //since we're operating with float values we just want the distance to be smaller than 2 pixels. if (Vector2.Distance(AbsolutePosition, target) < 2) { - if (Job == JobType.Idle) - { - mDone = true; - } CurrentNode = mCurrentNode; mDestination = null; mIsMoving = false; diff --git a/Singularity/Singularity/Units/IUnit.cs b/Singularity/Singularity/Units/IUnit.cs index 24bf680b..252864e3 100644 --- a/Singularity/Singularity/Units/IUnit.cs +++ b/Singularity/Singularity/Units/IUnit.cs @@ -10,10 +10,5 @@ interface IUnit /// get method for unit ID /// int Id{ get; } - - /// - /// Type will eventually be Assignment type - /// - string Assignment { get; set; } } } From 46a1792009a24d5338ea824f812093823a08f24a Mon Sep 17 00:00:00 2001 From: Confectio Date: Sat, 16 Jun 2018 14:05:52 +0200 Subject: [PATCH 15/18] Tryin to fix the circle thing --- Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs b/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs index 1b33441b..b49818df 100644 --- a/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs +++ b/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs @@ -74,8 +74,10 @@ public IPath AStar(Graph graph, INode start, INode destination) openList.Remove(current); closedList.Add(current); - - foreach (var outgoing in current.GetOutwardsEdges()) + var edges = new List(); + edges.AddRange(current.GetOutwardsEdges()); + edges.AddRange(current.GetInwardsEdges()); + foreach (var outgoing in edges) { var neighbor = outgoing.GetChild(); From d88c45af687bfbbb5107b7a972ceaf9a21fca349 Mon Sep 17 00:00:00 2001 From: Confectio Date: Sat, 16 Jun 2018 14:14:23 +0200 Subject: [PATCH 16/18] Fixed it --- .../DistributionManager.cs | 2 +- .../Graph/Paths/DefaultPathfinding.cs | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index a73120fc..6492eaba 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -258,7 +258,7 @@ public Task RequestNewTask(JobType job, Optional assignedAction //but the List of Platforms currently used is a linkedlist which is not very efficient with ELementAt(); //Maybe use the Graph somehow in the future var plist = mStructure.GetPlatformList(); - var rndnmbr = mRandom.Next(1, plist.Count - 1); + var rndnmbr = mRandom.Next(0, plist.Count); //Just give them the inside of the Optional action witchout checking because //it doesnt matter anyway if its null if the unit is idle. return new Task(job, plist.ElementAt(rndnmbr), null, assignedAction.Get()); diff --git a/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs b/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs index b49818df..e6937acb 100644 --- a/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs +++ b/Singularity/Singularity/Graph/Paths/DefaultPathfinding.cs @@ -74,10 +74,10 @@ public IPath AStar(Graph graph, INode start, INode destination) openList.Remove(current); closedList.Add(current); - var edges = new List(); - edges.AddRange(current.GetOutwardsEdges()); - edges.AddRange(current.GetInwardsEdges()); - foreach (var outgoing in edges) + //var edges = new List(); + //edges.AddRange(current.GetOutwardsEdges()); + //edges.AddRange(current.GetInwardsEdges()); + foreach (var outgoing in current.GetOutwardsEdges()) { var neighbor = outgoing.GetChild(); @@ -98,6 +98,31 @@ public IPath AStar(Graph graph, INode start, INode destination) continue; } + cameFrom[neighbor] = current; + gScore[neighbor] = tentativeGScore; + fScore[neighbor] = gScore[neighbor] + HeuristicCostEstimate(neighbor, destination); + } + foreach (var outgoing in current.GetInwardsEdges()) + { + var neighbor = outgoing.GetParent(); + + if (closedList.Contains(neighbor)) + { + continue; + } + + if (!openList.Contains(neighbor)) + { + openList.Add(neighbor); + } + + var tentativeGScore = gScore[current] + outgoing.GetCost(); + + if (tentativeGScore >= gScore[neighbor]) + { + continue; + } + cameFrom[neighbor] = current; gScore[neighbor] = tentativeGScore; fScore[neighbor] = gScore[neighbor] + HeuristicCostEstimate(neighbor, destination); From 3868005782430012935acf0c3086c4b3c0b7a1a8 Mon Sep 17 00:00:00 2001 From: Confectio Date: Sat, 16 Jun 2018 17:11:11 +0200 Subject: [PATCH 17/18] Made the gettask for Jobtype.Idle more efficient, since we dont have to iterate through a linkedList anymore. Furthermore the unit is getting more reactive this way. --- .../DistributionManager.cs | 35 ++++++++++++------- .../Screen/ScreenClasses/GameScreen.cs | 8 ++++- Singularity/Singularity/Units/GeneralUnit.cs | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index 6492eaba..dccfc3ff 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -8,6 +8,8 @@ using System.Text; using System.Threading.Tasks; using Singularity.Exceptions; +using Singularity.Graph; +using Singularity.Graph.Paths; using Singularity.Map; using Singularity.Platform; using Singularity.Resources; @@ -33,7 +35,7 @@ public class DistributionManager private List mManual; [DataMember()] - private StructureMap mStructure; + private PathManager mPathManager; [DataMember()] private Queue mBuildingResources; @@ -60,7 +62,7 @@ public class DistributionManager // Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? // Momentan ja, aber wenn du ne plattform haben willst die (rein theoretisch) verteidigen und Produzieren gleichzeitig kann? Oder gleichzeitig KineticDefense und LaserDefense ist? // Aber wollen wir das? also entweder so, oder halt wie oben vorgeschlagen. - public DistributionManager(StructureMap structure) + public DistributionManager(PathManager pm) { mIdle = new List(); mLogistics = new List(); @@ -69,7 +71,7 @@ public DistributionManager(StructureMap structure) mDefense = new List(); mManual = new List(); - mStructure = structure; + mPathManager = pm; mBuildingResources = new Queue(); mRefiningOrStoringResources = new Queue(); @@ -247,24 +249,31 @@ public List PlatformRequests(PlatformBlank platform) // // Okay, so how was it supposed to work (in my version, if you want to implement it is for you to decide): // - The units (with nothing to do (idle, but not 'JobType: Idle') ask for new Tasks here. So what is needed is ... actually yes, unit is not required. So the JobType is required, to return a Task of that JobType. Also, if this unit is assigned to some specific PlatformAction (like building a Blueprint, Logistics for a certain Factory, ...), it is supposed to only get Tasks involving this PlatformAction. However, if a unit is not manually assigned somewhere, what action do you want to get here? - public Task RequestNewTask(JobType job, Optional assignedAction) + public Task RequestNewTask(GeneralUnit unit, JobType job, Optional assignedAction) { - switch(job) + var nodes = new List(); + switch (job) //TODO: Implement other Job cases. { case JobType.Idle: - //TODO: - //Find a more efficient way to determine the random platform to go to. It has to be Platformreferences (Julian requested it) - //but the List of Platforms currently used is a linkedlist which is not very efficient with ELementAt(); - //Maybe use the Graph somehow in the future - var plist = mStructure.GetPlatformList(); - var rndnmbr = mRandom.Next(0, plist.Count); + //It looks inefficient but I think its okay, the + //Platforms got not that much connections (or at least they are supposed to have not that much connections). + //That way the unit will only travel one node per task, but that makes it more reactive. + foreach (var edge in unit.CurrentNode.GetInwardsEdges()) + { + nodes.Add(edge.GetParent()); + } + foreach (var edge in unit.CurrentNode.GetOutwardsEdges()) + { + nodes.Add(edge.GetChild()); + } + var rndnmbr = mRandom.Next(0, nodes.Count); //Just give them the inside of the Optional action witchout checking because //it doesnt matter anyway if its null if the unit is idle. - return new Task(job, plist.ElementAt(rndnmbr), null, assignedAction.Get()); + return new Task(job, (PlatformBlank) nodes.ElementAt(rndnmbr), null, assignedAction.Get()); } //TODO: Make this disappear when the rest is implemented, since its only a placeholder - return new Task(job, mStructure.GetPlatformList().ElementAt(0), null, assignedAction.Get()); + return new Task(job, (PlatformBlank) nodes.ElementAt(0), null, assignedAction.Get()); } public void PausePlatformAction(IPlatformAction action) diff --git a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs index bee4ea29..894a26a5 100644 --- a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs +++ b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO.MemoryMappedFiles; +using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -150,7 +151,9 @@ public void LoadContent(ContentManager content) var mapBackground = content.Load("MockUpBackground"); mMap = new Map.Map(mapBackground, mGraphicsDevice.Viewport, mInputManager, pathManager, true); mCamera = mMap.GetCamera(); - var dist = new DistributionManager.DistributionManager(mMap.mStructureMap); + //Give the Distributionmanager the Graph he is operating on. + //TODO: Talk about whether the DistributionManager should operate on all Graphs or if we want to make additional DMs. + var dist = new DistributionManager.DistributionManager(pathManager); mMUnitSheet = content.Load("UnitSpriteSheet"); @@ -164,6 +167,9 @@ public void LoadContent(ContentManager content) mPlatform2 = new Junkyard(new Vector2(800, 600), mPlatformDomeTexture); mPlatform3 = new EnergyFacility(new Vector2(600, 200), mPlatformDomeTexture); mPlatform3 = new EnergyFacility(new Vector2(600, 200), mPlatformDomeTexture); + + + var genUnit2 = new GeneralUnit(mPlatform2, pathManager, dist); var genUnit3 = new GeneralUnit(mPlatform3, pathManager, dist); diff --git a/Singularity/Singularity/Units/GeneralUnit.cs b/Singularity/Singularity/Units/GeneralUnit.cs index 42ef6443..4b0b456c 100644 --- a/Singularity/Singularity/Units/GeneralUnit.cs +++ b/Singularity/Singularity/Units/GeneralUnit.cs @@ -266,7 +266,7 @@ public void Update(GameTime gametime) { //Care!!! DO NOT UNDER ANY CIRCUMSTANCES USE THIS PLACEHOLDER IPlatformAction action = new ProduceMineResource(null, null); - mAssignedTask = mDistrManager.RequestNewTask(Job, Optional.Of(action)); + mAssignedTask = mDistrManager.RequestNewTask(this, Job, Optional.Of(action)); mDestination = mAssignedTask.End; } } From d277b113c1c415eef3af4353b2cb2dc1713aa210 Mon Sep 17 00:00:00 2001 From: Confectio Date: Sat, 16 Jun 2018 17:17:07 +0200 Subject: [PATCH 18/18] Reverted some unnessessary changes --- .../Singularity/DistributionManager/DistributionManager.cs | 7 +------ Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Singularity/Singularity/DistributionManager/DistributionManager.cs b/Singularity/Singularity/DistributionManager/DistributionManager.cs index dccfc3ff..9cd53cf7 100644 --- a/Singularity/Singularity/DistributionManager/DistributionManager.cs +++ b/Singularity/Singularity/DistributionManager/DistributionManager.cs @@ -34,9 +34,6 @@ public class DistributionManager [DataMember()] private List mManual; - [DataMember()] - private PathManager mPathManager; - [DataMember()] private Queue mBuildingResources; [DataMember()] @@ -62,7 +59,7 @@ public class DistributionManager // Alternativ könnte man auch bei den beiden Listen direkt die Platformen einsetzen? // Momentan ja, aber wenn du ne plattform haben willst die (rein theoretisch) verteidigen und Produzieren gleichzeitig kann? Oder gleichzeitig KineticDefense und LaserDefense ist? // Aber wollen wir das? also entweder so, oder halt wie oben vorgeschlagen. - public DistributionManager(PathManager pm) + public DistributionManager() { mIdle = new List(); mLogistics = new List(); @@ -71,8 +68,6 @@ public DistributionManager(PathManager pm) mDefense = new List(); mManual = new List(); - mPathManager = pm; - mBuildingResources = new Queue(); mRefiningOrStoringResources = new Queue(); mRequestedUnitsProduce = new Queue(); diff --git a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs index 894a26a5..d1a3d38f 100644 --- a/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs +++ b/Singularity/Singularity/Screen/ScreenClasses/GameScreen.cs @@ -153,7 +153,7 @@ public void LoadContent(ContentManager content) mCamera = mMap.GetCamera(); //Give the Distributionmanager the Graph he is operating on. //TODO: Talk about whether the DistributionManager should operate on all Graphs or if we want to make additional DMs. - var dist = new DistributionManager.DistributionManager(pathManager); + var dist = new DistributionManager.DistributionManager(); mMUnitSheet = content.Load("UnitSpriteSheet");