Beispiel #1
0
 protected AMakeUnit(PlatformBlank platform, ref Director director) : base(platform, ref director)
 {
     State             = PlatformActionState.Available; // now the init is a UIToggle. hacky but works.
     mBuildingCost     = new Dictionary <EResourceType, int>();
     mMissingResources = new Dictionary <EResourceType, int>();
     mToRequest        = new Dictionary <EResourceType, int>();
 }
Beispiel #2
0
 public MakeSettlerUnit(PlatformBlank platform, ref Director director) : base(platform, ref director)
 {
     // Todo: update prices
     mBuildingCost = new Dictionary <EResourceType, int> {
         { EResourceType.Metal, 15 }, { EResourceType.Stone, 10 }, { EResourceType.Fuel, 10 }, { EResourceType.Chip, 10 }, { EResourceType.Steel, 5 }
     };
 }
Beispiel #3
0
 public MakeGeneralUnit(PlatformBlank platform, ref Director director) : base(platform, ref director)
 {
     // Todo: update prices.
     mBuildingCost = new Dictionary <EResourceType, int> {
         { EResourceType.Chip, 3 }, { EResourceType.Fuel, 3 }
     };
 }
Beispiel #4
0
        public GeneralUnit(PlatformBlank platform, ref Director director) : base(ref director)
        {
            Graphid = platform.GetGraphIndex();
            platform.AddGeneralUnit(this);
            Id           = director.GetIdGenerator.NextId();
            mDestination = Optional <INode> .Of(null);

            CurrentNode = platform;
            Carrying    = Optional <Resource> .Of(null);

            AbsolutePosition = ((IRevealing)platform).Center;
            mPathQueue       = new Queue <Vector2>();
            mNodeQueue       = new Queue <INode>();

            mIsMoving = false;
            mDirector = director;
            mDirector.GetActionManager.AddObject(this,
                                                 delegate
            {
                mDirector.GetDistributionDirector.GetManager(Graphid).Register(this);
                mDirector.GetStoryManager.UpdateUnits("created");
                mInitialized = true;
                return(true);
            });
            mDone       = true;
            mFinishTask = false;
        }
Beispiel #5
0
        private void ActualRemovePlatform(PlatformBlank platform)
        {
            var platformAsCc = platform as CommandCenter;

            if (platformAsCc != null && platform.Friendly)
            {
                mCommandCenterCount--;

                if (mCommandCenterCount <= 0)
                {
                    mDirector.GetStoryManager.Lose();
                    return;
                }
            }

            mPlatforms.Remove(platform);


            // TODO : made this only for friendly platforms since right now enemy platforms should not be added to Graph ID
            if (platform.Friendly)
            {
                mFow.RemoveRevealingObject(platform);
                var index = mPlatformToGraphId[platform];
                mGraphIdToGraph[index] = null;

                mDirector.GetDistributionDirector.RemoveManager(index, mGraphIdToGraph);
                mDirector.GetPathManager.RemoveGraph(index);
                mPlatformToGraphId.Remove(platform);
            }
        }
Beispiel #6
0
 public MakeFastMilitaryUnit(PlatformBlank platform, ref Director director) : base(platform, ref director)
 {
     // mBuildingCost = new Dictionary<EResourceType, int> { { EResourceType.Metal, 3 }, { EResourceType.Chip, 2 }, {EResourceType.Fuel, 1} };
     mBuildingCost = new Dictionary <EResourceType, int> {
         { EResourceType.Metal, 2 }, { EResourceType.Copper, 2 }, { EResourceType.Fuel, 2 }
     };
 }
Beispiel #7
0
        public void Kill(PlatformBlank platform)
        {
            foreach (var structure in mStructure)
            {
                if (platform.Equals(structure.GetFirst().GetFirst()))
                {
                    mCommandCenterKillCount++;
                    structure.GetFirst().GetSecond().Remove(platform);
                    break;
                }

                if (!structure.GetFirst().GetSecond().Contains(platform))
                {
                    continue;
                }
                structure.GetFirst().GetSecond().Remove(platform);
                return;
            }

            if (mCommandCenterKillCount < mStructure.Count)
            {
                return;
            }
            mDirector.GetStoryManager.Win();
        }
Beispiel #8
0
 /// <summary>
 /// Removes the specified platform from this map. This also modifies the underlying graph structures.
 /// </summary>
 /// <param name="platform">The platform to be removed</param>
 public void RemovePlatform(PlatformBlank platform)
 {
     mDirector.GetActionManager.AddObject(platform, delegate(object p)
     {
         ActualRemovePlatform((PlatformBlank)p);
         return(true);
     });
 }
Beispiel #9
0
        /// <summary>
        /// Handles selection of platforms for the UI.
        /// Gets called by platforms if they notice that they're being clicked on.
        /// </summary>
        /// <param name="platform">platform that was selected</param>
        internal void ActivateMe(PlatformBlank platform)
        {
            // deactivate previously selected platform
            if (mActivePlatform != null)
            {
                mActivePlatform.IsSelected = false;
            }

            platform.IsSelected = true;
            mActivePlatform     = platform;
        }
Beispiel #10
0
        public RefineResourceAction(PlatformBlank platform,
                                    ref Director director,
                                    Dictionary <EResourceType, int> from,
                                    EResourceType to) : base(platform, ref director)
        {
            State         = PlatformActionState.Available;
            mBuildingCost = from;
            mRefiningTo   = to;

            // now, you actually might want to have the mRequestedResoucres higher than the cost of one building ... todo: another time.
        }
Beispiel #11
0
        /// <summary>
        /// Adds the specified platform to this map. This also modifies the graph structures
        /// used internally
        /// </summary>
        /// <param name="platform">The platform to be added</param>
        public void AddPlatform(PlatformBlank platform)
        {
            var platformAsCc = platform as CommandCenter;

            if (platformAsCc != null && platform.Friendly)
            {
                mCommandCenterCount++;
            }

            mPlatforms.AddLast(platform);

            // TODO: quick implementation to prevent enemy platforms from being discoverable through FOW
            if (!platform.Friendly)
            {
                return;
            }

            mFow.AddRevealingObject(platform);

            // first of all get the "connection graph" of the platform to add. The connection graph
            // describes the graph (nodes and edges) reachable from this platform
            var graph = Bfs(platform);

            foreach (var node in graph.GetNodes())
            {
                // if the platform in the current reachability graph isn't known then we don't do anything
                if (!mPlatformToGraphId.ContainsKey((PlatformBlank)node))
                {
                    continue;
                }

                //if its known, we add our platform to it, since obviously we're connected to the same graph now.
                var graphIndex = mPlatformToGraphId[(PlatformBlank)node];
                mPlatformToGraphId[platform] = graphIndex;
                mGraphIdToGraph[graphIndex].AddNode(platform);
                platform.SetGraphIndex(graphIndex);
                UpdateGenUnitsGraphIndex(mGraphIdToGraph[graphIndex], graphIndex);
                return;
            }

            // we failed, meaning that this platform creates a new graph on its own.
            // intuitively: "the reachability graph from this node is only this node"
            var index = mGraphIdToGraph.Count;

            mGraphIdToEnergyLevel[index] = 0;
            mGraphIdToGraph[index]       = graph;
            mPlatformToGraphId[platform] = index;
            platform.SetGraphIndex(index);

            UpdateGenUnitsGraphIndex(mGraphIdToGraph[index], index);

            mDirector.GetDistributionDirector.AddManager(index);
            mDirector.GetPathManager.AddGraph(index, graph);
        }
 /// <summary>
 /// A method for Platforms/their actions to request resources.
 /// </summary>
 /// <param name="platform">The platform making the request</param>
 /// <param name="resource">The wanted resource</param>
 /// <param name="action">The corresponding platformaction</param>
 /// <param name="isbuilding">True if the resources are for building, false otherwise</param>
 public void RequestResource(PlatformBlank platform, EResourceType resource, IPlatformAction action, bool isbuilding = false)
 {
     //TODO: Create Action references, when interfaces were created.
     if (isbuilding)
     {
         mBuildingResources.Enqueue(new Task(JobType.Construction, Optional <PlatformBlank> .Of(platform), resource, Optional <IPlatformAction> .Of(action)));
     }
     else
     {
         mRefiningOrStoringResources.Enqueue(new Task(JobType.Logistics, Optional <PlatformBlank> .Of(platform), resource, Optional <IPlatformAction> .Of(action)));
     }
 }
Beispiel #13
0
 public BuildBluePrint(PlatformBlank platform, Road road, ref Director director) : base(platform, ref director)
 {
     //mBuildingCost = new Dictionary<EResourceType, int> { {EResourceType.Metal, 1}, {EResourceType.Stone, 1} };
     mBuildingCost        = new Dictionary <EResourceType, int>();
     mRBuilding           = road;
     mRBuilding.Blueprint = true;
     mRBuilding.SetBluePrint(this);
     mBuildRoad  = true;
     mIsBuilding = true;
     UpdateResources();
     mDirector.GetDistributionDirector.GetManager(mPlatform.GetGraphIndex()).Register(this);
     State = PlatformActionState.Active;
 }
Beispiel #14
0
 internal PlatformInfoBox(List <IWindowItem> itemList, Vector2 size, PlatformBlank platform, Director director) :
     base(itemList: itemList,
          size: size,
          borderColor: new Color(r: 0.86f, g: 0.86f, b: 0.86f),
          centerColor: new Color(r: 1f, g: 1, b: 1),
          boxed: true,
          director: director,
          mousePosition: false,
          location: platform.AbsolutePosition)
 {
     Position = platform.AbsolutePosition + new Vector2(0, platform.AbsoluteSize.Y + 10);
     Active   = true;
     mCounter = 11;
 }
        public StructurePlacer(EStructureType platformType, EPlacementType placementType, EScreen screen, Camera camera, ref Director director, ref Map.Map map, float x = 0, float y = 0, ResourceMap resourceMap = null)
        {
            mUnregister = false;

            mCamera   = camera;
            Screen    = screen;
            mDirector = director;

            mPlatformType = platformType;

            // need the structure map to make sure platforms arent placed on collidable objects
            mMap = map;

            mDirector.GetInputManager.FlagForAddition(this, EClickType.Both, EClickType.Both);
            mDirector.GetInputManager.AddMousePositionListener(this);
            mCurrentState = new State3();

            director.GetUserInterfaceController.BuildingProcessStarted(platformType);


            // for further information as to why which states refer to the documentation for mCurrentState
            switch (placementType)
            {
            case EPlacementType.RoadMouseFollowAndRoad:
                mIsRoadPlacement = true;
                break;

            case EPlacementType.PlatformMouseFollowAndRoad:
                break;
            }

            if (mIsRoadPlacement)
            {
                return;
            }
            mPlatform = PlatformFactory.Get(platformType, ref director, x, y, resourceMap);
            mPlatform.SetLayer(LayerConstants.PlatformAboveFowLayer);
            UpdateBounds();

            // makes a sound once when platform is placed
            mPlatformCreateSoundId = mDirector.GetSoundManager.CreateSoundInstance("PlatformCreate",
                                                                                   mPlatform.Center.X,
                                                                                   mPlatform.Center.Y,
                                                                                   .24f,
                                                                                   .01f,
                                                                                   true,
                                                                                   false,
                                                                                   SoundClass.Effect);
        }
Beispiel #16
0
        public void Place(PlatformBlank source, PlatformBlank dest)
        {
            if (source == null || dest == null)
            {
                return;
            }

            SourceAsNode      = source;
            DestinationAsNode = dest;

            Source      = source.Center;
            Destination = dest.Center;

            source.AddEdge(this, EEdgeFacing.Outwards);
            dest.AddEdge(this, EEdgeFacing.Inwards);
        }
Beispiel #17
0
        public BuildBluePrint(PlatformBlank platform, PlatformBlank toBeBuilt, Road connectingRoad, ref Director director) : base(
                platform,
                ref director)
        {
            mBuildingCost        = new Dictionary <EResourceType, int>(PlatformBlank.GetResourceCosts(toBeBuilt.mType));
            mBuilding            = toBeBuilt;
            mRBuilding           = connectingRoad;
            mRBuilding.Blueprint = true;
            mRBuilding.SetBluePrint(this);
            mDirector.GetStoryManager.Level.GameScreen.AddObject(mRBuilding);

            UpdateResources();
            mIsBuilding = true;
            mDirector.GetDistributionDirector.GetManager(mPlatform.GetGraphIndex()).Register(this);
            State = PlatformActionState.Active;
        }
Beispiel #18
0
        /*
         * public List<GeneralUnit> UnAssignUnits(int amount, JobType job)
         * {
         *  var list = new List<GeneralUnit>();
         *  foreach (var unit in mAssignedUnits.Keys)
         *  {
         *      if (unit.Job != job || amount <= 0)
         *      {
         *          continue;
         *      }
         *
         *      mAssignedUnits.Remove(unit);
         *      list.Add(unit);
         *      amount -= 1;
         *  }
         *
         *  return list;
         * }
         */

        public bool Die()
        {
            if (mPlatform == null)
            {
                return(true);
            }
            if (mPlatform.Friendly)
            {
                mDirector.GetDistributionDirector.GetManager(mPlatform.GetGraphIndex()).Kill(this);
            }
            State          = PlatformActionState.Disabled;
            mAssignedUnits = new Dictionary <GeneralUnit, JobType>();
            mPlatform.Kill(this);
            mPlatform = null;

            return(true);
        }
        /// <summary>
        /// Removes a platform from the Military Manager (i.e. it died).
        /// </summary>
        /// <param name="platform">The platform to be removed.</param>
        internal void RemovePlatform(PlatformBlank platform)
        {
            var defensePlatform = platform as DefenseBase;

            // Figure out if it is a defense platform. If yes, then figure out if it is friendly
            if (defensePlatform != null)
            {
                if (platform.Friendly)
                {
                    mFriendlyDefensePlatforms.Remove(defensePlatform);
                }
                else
                {
                    mHostileDefensePlatforms.Remove(defensePlatform);
                }
            }

            mUnitMap.RemoveUnit(platform);
            mReconstructionList.Remove(platform);
        }
        /// <summary>
        /// Is called by producing and defending Platforms when they are created or added to the distributionmanager.
        /// </summary>
        /// <param name="platform">The platform itself</param>
        public void Register(PlatformBlank platform)
        {
            var isDef             = platform.IsDefense();
            var job               = isDef ? JobType.Defense : JobType.Production;
            var joblist           = isDef ? mDefense : mProduction;
            var alreadyonplatform = 0;

            if (platform.GetAssignedUnits()[job].Count > 0)
            {
                alreadyonplatform = platform.GetAssignedUnits()[job].Count;
            }

            //Make sure the units are added to their joblist if they arent already.
            foreach (var unitbool in platform.GetAssignedUnits()[job])
            {
                if (!joblist.Contains(unitbool.GetFirst()))
                {
                    joblist.Add(unitbool.GetFirst());
                }
            }
            NewlyDistribute(platform, isDef, alreadyonplatform);
        }
Beispiel #21
0
 /// <summary>
 /// Road is simply an edge between two platforms.
 /// </summary>
 /// <param name="source">The source IRevealing object from which this road gets drawn</param>
 /// <param name="destination">The destinaion IRevealing object to which this road gets drawn</param>
 /// <param name="director">The Director of all Managers</param>
 /// <param name="blueprint">Whether this road is a blueprint or not</param>
 public Road(PlatformBlank source, PlatformBlank destination, ref Director director, bool blueprint = false) : base(ref director)
 {
     // the hardcoded values need some changes for different platforms, ill wait until those are implemented to find a good solution.
     if (source == null && destination == null)
     {
         throw new Exception("Source and Destination can't both be null");
     }
     if (source == null)
     {
         Destination = destination.Center;
         Source      = destination.Center;
     }
     else if (destination == null)
     {
         Source      = source.Center;
         Destination = source.Center;
     }
     else
     {
         Place(source, destination);
     }
     Blueprint = blueprint;
 }
        /// <summary>
        /// Adds a new platform to the military manager. This also adds it to the UnitMap.
        /// </summary>
        /// <param name="platform">Any type of platform which can be damaged (i.e. all platforms)</param>
        internal void AddPlatform(PlatformBlank platform)
        {
            var defensePlatform = platform as DefenseBase;
            var position        = mUnitMap.VectorToTilePos(platform.AbsolutePosition);

            // Figure out if it is a defense platform. If yes, then figure out its allegiance then
            // add it to the appropriate list.
            if (defensePlatform != null)
            {
                if (platform.Friendly)
                {
                    mFriendlyDefensePlatforms.Add(defensePlatform);
                }
                else
                {
                    mHostileDefensePlatforms.Add(defensePlatform);
                }
            }

            // Then add it to the unitMap and the reconstructionlist.
            mReconstructionList.Add(platform);
            mUnitMap.AddUnit(platform, position);
        }
        public void Kill(PlatformBlank platform)
        {
            // Strong assumption that a platform is only listed at most once in either of these.
            mProdPlatforms.Remove(mProdPlatforms.Find(p => p.GetFirst().Equals(platform)));
            mDefPlatforms.Remove(mDefPlatforms.Find(p => p.GetFirst().Equals(platform)));
            var lists = new List <List <GeneralUnit> > {
                mIdle, mLogistics, mConstruction, mProduction, mDefense, mManual
            };

            foreach (var list in lists)
            {
                //We need this because the list is changed by the call of unit.Kill
                var copy = new List <GeneralUnit>();
                copy.AddRange(list);
                foreach (var unit in copy)
                {
                    unit.Kill(platform.Id);
                }
            }
            //Update the handler afterwards
            mHandler?.ForceSliderPages();
            // the first in the pair is the id, the second is the TTL
            mKilled.Add(new Pair <int, int>(platform.Id, mBuildingResources.Count + mRefiningOrStoringResources.Count));
        }
Beispiel #24
0
 protected APlatformAction(PlatformBlank platform, ref Director director)
 {
     mPlatform = platform;
     mDirector = director;
     Id        = director.GetIdGenerator.NextId();
 }
Beispiel #25
0
 public MakeStandardMilitaryUnit(PlatformBlank platform, ref Director director) : base(platform, ref director)
 {
     mBuildingCost = new Dictionary <EResourceType, int> {
         { EResourceType.Steel, 3 }, { EResourceType.Chip, 2 }, { EResourceType.Fuel, 2 }
     };
 }
Beispiel #26
0
        public void Update(GameTime gametime)
        {
            // the platform which currently gets hovered. This only gets set if we actually need it
            // e.g. when we have a "to be placed platform" currently in the game. This also
            // fulfills multiple purposes.
            // First is when the platform to be placed is in its
            // first state, then the hovering refers to the platform which is under the platform
            // to place. This is needed to make sure that the platform to be placed doesn't get
            // placed ontop of another.
            // The second is when the platform to be placed is in its second state,
            // then the hovering refers to the platform the road snaps to.
            PlatformBlank hovering = null;

            foreach (var platform in mPlatforms)
            {
                platform.Update(gametime);

                // we only want to continue if we have platforms to place.
                // the reason this is in this for loop is simply due to me
                // not having to iterate the same list twice.
                if (mStructuresToPlace.Count <= 0)
                {
                    continue;
                }

                // this for loop is needed to fulfill the first hovering purpose mentioned.
                foreach (var structureToAdd in mStructuresToPlace)
                {
                    if (structureToAdd.GetPlatform() == null)
                    {
                        continue;
                    }

                    // first make sure to update the bounds, etc., since our platforms normally don't move
                    // these don't get updated automatically.
                    structureToAdd.GetPlatform().UpdateValues();

                    // if our current platform doesn't intersect with the platform to be placed we
                    // aren't hovering it, thus we continue to the next platform.
                    if (!structureToAdd.GetPlatform().AbsBounds.Intersects(platform.AbsBounds))
                    {
                        continue;
                    }
                    // this means, we're currently hovering a platform with the platform to place
                    // thus set it accordingly, so it can be handled in the respective class.
                    hovering = platform;
                }

                // this is needed to fulfill the second hovering purpose mentioned.
                if (!platform.AbsBounds.Intersects(new Rectangle((int)mMouseX, (int)mMouseY, 1, 1)))
                {
                    continue;
                }

                hovering = platform;
            }

            foreach (var road in mRoads)
            {
                road.Update(gametime);
            }

            // we use this list to "mark" all the platformplacements to remove from the actual list. Since
            // we need to ensure that the actual list doesn't change size while iterating.
            var toRemove = new LinkedList <StructurePlacer>();

            foreach (var structureToAdd in mStructuresToPlace)
            {
                // finished means, that the platform either got set, or got canceled, where canceled means
                // that the building process got canceled
                if (!structureToAdd.IsFinished())
                {
                    structureToAdd.SetHovering(hovering);
                    structureToAdd.Update(gametime);
                    continue;
                }
                // the platform is finished AND canceled. Make sure to remove it, and update it a last time so it can clean up all its references
                // to other classes.
                if (structureToAdd.IsCanceled())
                {
                    structureToAdd.Update(gametime);
                    toRemove.AddLast(structureToAdd);
                    continue;
                }

                //platform is finished
                toRemove.AddLast(structureToAdd);
                if (structureToAdd.GetPlatform() != null)
                {
                    mDirector.GetStoryManager.Level.GameScreen.AddObject(structureToAdd.GetPlatform());
                    structureToAdd.GetConnectionRoad().Place(structureToAdd.GetPlatform(), hovering);
                    // mDirector.GetStoryManager.Level.GameScreen.AddObject(structureToAdd.GetConnectionRoad());
                }
                else
                {
                    // structureToAdd.GetRoad().Place(structureToAdd.GetPlatform(), hovering);
                    mDirector.GetStoryManager.Level.GameScreen.AddObject(structureToAdd.GetRoad());
                }
            }

            //finally make sure to remove the "marked" platformplacements to be removed
            foreach (var platformToRemove in toRemove)
            {
                mStructuresToPlace.Remove(platformToRemove);
            }

            // now update the energy level of all graphs
            foreach (var graphId in mGraphIdToGraph.Keys)
            {
                if (mGraphIdToGraph[graphId] == null)
                {
                    continue;
                }

                UpdateEnergyLevel(graphId);
            }
        }
        public bool MouseButtonClicked(EMouseAction mouseAction, bool withinBounds)
        {
            var giveThrough = true;

            if (mouseAction == EMouseAction.LeftClick)
            {
                switch (mCurrentState.GetState())
                {
                case 1:
                    if (!mIsRoadPlacement)
                    {
                        mPlatform.UpdateValues();

                        //first check if the platform is even on the map, if not we don't want to progress, since it isn't a valid position
                        if (!Map.Map.IsOnTop(mPlatform.AbsBounds) || mHoveringPlatform != null || mNatureObjectThere)
                        {
                            break;
                        }

                        // the platform was on the map -> advance to next state and create the road to connect to another platform
                        mCurrentState.NextState();
                        mConnectionRoad = new Road(mPlatform, null, ref mDirector, true);

                        giveThrough = false;
                    }
                    else
                    {
                        if (mHoveringPlatform != null)
                        {
                            mRoadToBuild = new Road(mHoveringPlatform, null, ref mDirector, true);
                            mOldHovering = mHoveringPlatform;
                            mCurrentState.NextState();
                            giveThrough = false;
                        }
                    }

                    break;


                case 2:
                    if (!mIsRoadPlacement)
                    {
                        if (mHoveringPlatform == null || !mHoveringPlatform.Friendly)
                        {
                            break;
                        }

                        // this limits two platforms to only be connectable by a road if the road isn't in the fog of war this was requested by felix
                        if (Vector2.Distance(mHoveringPlatform.Center, mPlatform.Center) <=
                            mPlatform.RevelationRadius + mHoveringPlatform.RevelationRadius)
                        {
                            mCurrentState.NextState();
                        }

                        giveThrough = false;
                    }
                    else
                    {
                        if (mHoveringPlatform == null || mHoveringPlatform.Equals(mOldHovering) || !mHoveringPlatform.Friendly)
                        {
                            break;
                        }

                        mRoadToBuild.DestinationAsNode = mHoveringPlatform;
                        mRoadToBuild.Destination       = mHoveringPlatform.Center;
                        mHoveringPlatform.AddBlueprint(new BuildBluePrint(mHoveringPlatform, mRoadToBuild, ref mDirector));
                        mCurrentState.NextState();
                    }

                    break;
                }
            }

            if (mouseAction == EMouseAction.RightClick)
            {
                if (mCurrentState.GetState() == 1)
                {
                    mDirector.GetUserInterfaceController.BuildingProcessFinished();
                    mCanceled   = true;
                    mIsFinished = true;
                    giveThrough = false;
                    mUnregister = true;

                    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                    // Done for consistency
                    return(giveThrough);
                }

                // we only need to do something with rightclick if were in the 2nd state, since then we revert.
                if (mCurrentState.GetState() != 2)
                {
                    return(giveThrough);
                }

                if (!mIsRoadPlacement)
                {
                    // make sure to reset colors when reverting to the last state. The rest is just some cleanup to properly
                    // get to the previous state
                    mPlatform.ResetColor();
                    mConnectionRoad = null;
                    mCurrentState.PreviousState();
                    giveThrough = false;
                }
                else
                {
                    mRoadToBuild = null;
                    mCurrentState.PreviousState();
                    giveThrough = false;
                }
            }

            return(giveThrough);
        }
        /// <summary>
        /// Deactivates tasks requested by a certain action.
        /// </summary>
        //// <param name="removeaction">The Action I was talking about</param>
        // private void DeactivateAction(IPlatformAction removeaction)
        // {
        // mPlatformActions.Remove(removeaction);
        // }

        #region Looking for Resources

        /// <summary>
        /// Uses BFS to find the nearest Platform holding a resource you want to get. Might be expensive...
        /// </summary>
        /// <param name="destination">The platform you start the bfs from.</param>
        /// <param name="res">The resourcetype to look for.</param>
        /// <returns>The platform with the desired resource, if it exists, null if not</returns>
        private PlatformBlank FindBegin(PlatformBlank destination, EResourceType res)
        {
            var visited = new List <PlatformBlank>();

            var currentlevel = new List <PlatformBlank>();

            currentlevel.Add(destination);

            //Check whether the platform has the resource itself
            if (destination.GetPlatformResources()
                .Any(resource => resource.Type == res))
            {
                return(destination);
            }

            var nextlevel = new List <PlatformBlank>();

            while (currentlevel.Count > 0)
            {
                //Create the next level of BFS. While doing this, check if any platform has the resource you want. If yes return it.
                foreach (var platform in currentlevel)
                {
                    foreach (var edge in platform.GetInwardsEdges())
                    {
                        var candidatePlatform = (PlatformBlank)edge.GetParent();
                        //If true, we have already visited this platform
                        if (visited.Contains(candidatePlatform))
                        {
                            continue;
                        }
                        //Check for the resource
                        if (candidatePlatform.GetPlatformResources()
                            .Any(resource => resource.Type == res))
                        {
                            return(candidatePlatform);
                        }
                        //If true, this Platform has already been put in the next level
                        if (!nextlevel.Contains(candidatePlatform))
                        {
                            nextlevel.Add(candidatePlatform);
                        }
                    }

                    foreach (var edge in platform.GetOutwardsEdges())
                    {
                        var candidatePlatform = (PlatformBlank)edge.GetChild();
                        //If true, we have already visited this platform
                        if (visited.Contains(candidatePlatform))
                        {
                            continue;
                        }
                        //Check for the resource
                        if (candidatePlatform.GetPlatformResources().Any(resource => resource.Type == res))
                        {
                            return(candidatePlatform);
                        }
                        //If true, this Platform has already been put in the next level
                        if (!nextlevel.Contains(candidatePlatform))
                        {
                            nextlevel.Add(candidatePlatform);
                        }
                    }
                    //mark that you have visited this platform now
                    visited.Add(platform);
                }

                //Update levels
                currentlevel = nextlevel;
                nextlevel    = new List <PlatformBlank>();
            }
            return(null);
        }
 /// <summary>
 /// Sets the hovering platform.
 /// </summary>
 /// <param name="hovering">The platform which currently gets hovered by the user</param>
 public void SetHovering(PlatformBlank hovering)
 {
     mHoveringPlatform = hovering;
 }
        /// <summary>
        /// A method called by the DistributionManager in case a new platform is registered, then it will redistribute all the units.
        /// BE SURE ALL THE UNITS THAT ARE ON THE PLATFORM ARE REGISTERED IN THE DISTRIBUTIONMANAGER OTHERWISE THIS WILL FAIL!
        /// </summary>
        /// <param name="platform">The newly registered platform</param>
        /// <param name="isDefense">Is true if its a DefensePlatform, false otherwise</param>
        /// <param name="alreadyonplatform">The amount of units already working on the platform</param>
        private void NewlyDistribute(PlatformBlank platform, bool isDefense, int alreadyonplatform)
        {
            var job     = isDefense ? JobType.Defense : JobType.Production;
            var joblist = isDefense ? mDefense : mProduction;

            if (isDefense)
            {
                // + 1 because we didnt add the new platform yet
                var times = mDefense.Count / (mDefPlatforms.Count + 1);
                if (times > alreadyonplatform)
                {
                    times = times - alreadyonplatform;

                    var list = GetUnitsFairly(times, mDefPlatforms, true);

                    foreach (var unit in list)
                    {
                        //We have to re-add the units to the job list because GetUnitsFairly did unassign them
                        joblist.Add(unit);
                        //Also unassigns the unit.
                        unit.AssignTask(new Task(JobType.Defense, Optional <PlatformBlank> .Of(platform), null, Optional <IPlatformAction> .Of(null)));
                    }

                    mDefPlatforms.Add(new Pair <PlatformBlank, int>(platform, list.Count));
                }
                else if (times < alreadyonplatform)
                {
                    times = alreadyonplatform - times;
                    var units = new List <GeneralUnit>();
                    for (var i = times; i > 0; i--)
                    {
                        GeneralUnit transferunit;
                        transferunit = platform.GetAssignedUnits()[job].First().GetFirst();
                        units.Add(transferunit);
                        mIdle.Add(transferunit);
                        joblist.Remove(transferunit);
                        transferunit.ChangeJob(JobType.Idle);
                    }
                    AssignUnitsFairly(units, true);
                }
                else
                {
                    mDefPlatforms.Add(new Pair <PlatformBlank, int>(platform, alreadyonplatform));
                }
            }
            else
            {
                // + 1 because we didnt add the new platform yet
                var times = mProduction.Count / (mProdPlatforms.Count + 1);
                if (times > alreadyonplatform)
                {
                    times = times - alreadyonplatform;

                    var list = GetUnitsFairly(times, mProdPlatforms, false);

                    foreach (var unit in list)
                    {
                        //We have to re-add the units to the job list because GetUnitsFairly did unassign them
                        mProduction.Add(unit);
                        //Also unassigns the unit.
                        unit.AssignTask(new Task(JobType.Production, Optional <PlatformBlank> .Of(platform), null, Optional <IPlatformAction> .Of(platform.GetIPlatformActions()[0])));
                    }

                    mProdPlatforms.Add(new Pair <PlatformBlank, int>(platform, list.Count));
                }
                else if (times < alreadyonplatform)
                {
                    times = alreadyonplatform - times;
                    var units = new List <GeneralUnit>();
                    for (var i = times; i > 0; i--)
                    {
                        GeneralUnit transferunit;
                        transferunit = platform.GetAssignedUnits()[job].First().GetFirst();
                        units.Add(transferunit);
                        mIdle.Add(transferunit);
                        joblist.Remove(transferunit);
                        transferunit.ChangeJob(JobType.Idle);
                    }
                    AssignUnitsFairly(units, false);
                }
                else
                {
                    mProdPlatforms.Add(new Pair <PlatformBlank, int>(platform, alreadyonplatform));
                }
            }
        }