Exemple #1
0
        /// <summary>
        /// Used to Abort the current Task, when the unit notices it cannot reach its destination.
        /// </summary>
        // private void AbortTask()
        // {
        //TODO: This. Also dont forget to put the task back in the task queue, but not sure if this is necessary. Talk with felix about that.
        // }


        /// <summary>
        /// Is called if this Units Job is changed to Production or Defense. BUT NOT BY THE UNIT ITSELF. Should only be called by the DistrManager.
        /// Can also be used to just change the "home" of the unit. In that case just give it the job it already has (in the task).
        /// </summary>
        /// <param name="task">The new task for the unit</param>
        internal void AssignTask(Task task)
        {
            mDone = false;
            mTask = task;
            ChangeJob(mTask.Job);
            //Check whether there is a Destination. (it should)
            if (mTask.End.IsPresent())
            {
                //This only tells the platform that the unit is on the way! Use ShowedUp to tell the platform that the unit has arrived.
                mTask.End.Get().AssignUnits(this, Job);
                mDestination = Optional <INode> .Of(mTask.End.Get());

                TargetGraphid = mTask.End.Get().GetGraphIndex();
            }

            if (mTask.Action.IsPresent())
            {
                mAssignedAction = mTask.Action.Get();
            }
            else
            {
                mAssignedAction = null;
            }
            //This is needed so the unit will not first go to the end of their previous task
            mNodeQueue = new Queue <INode>();
        }
 public void PausePlatformAction(IPlatformAction action, Director director)
 {
     director.GetActionManager.AddObject(action,
                                         delegate
     {
         Kill(action);
         return(true);
     });
 }
 /// <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)));
     }
 }
        public void Kill(IPlatformAction action)
        {
            // Strong assumption that a PlatformAction is only listed at most once here.
            mPlatformActions.Remove(mPlatformActions.Find(p => p.Equals(action)));

            var lists = new List <List <GeneralUnit> > {
                mIdle, mLogistics, mConstruction, mProduction, mDefense, mManual
            };

            lists.ForEach(l => l.ForEach(u => u.Kill(action.Id)));
            // the first in the pair is the id, the second is the TTL
            mKilled.Add(new Pair <int, int>(action.Id, mBuildingResources.Count + mRefiningOrStoringResources.Count));
        }
Exemple #5
0
 public static void CurrentPlatform(this IPlatformAction platform)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         platform.Windows();
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         platform.macOS();
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         platform.Linux();
     }
     else
     {
         throw new NotSupportedException("Unknown platform.");
     }
 }
 public void Register(IPlatformAction action)
 {
     mPlatformActions.Add(action);
 }
        /// <summary>
        /// Creates a PlatformAction IWindowItem which represents a platformaction with it's name, state and a button to (de)activate it.
        /// </summary>
        /// <param name="platformAction">the platformaction to be represented</param>
        /// <param name="spriteFont">spritefont for text</param>
        /// <param name="position">position of the IWindowItem (Vector.Zero if added to window)</param>
        /// <param name="size">size to fit the item in (width is important)</param>
        /// <param name="director">director</param>
        /// <param name="refineRes">the action is of type refineRes</param>
        public PlatformActionIWindowItem(IPlatformAction platformAction, SpriteFont spriteFont, Vector2 position, Vector2 size, Director director, bool refineRes = false)
        {
            Size     = new Vector2(size.X, spriteFont.MeasureString("A").Y * 2 + 5);
            Position = position;

            mPlatformAction = platformAction;

            ActiveInWindow = true;

            // infobox items list
            var infoBoxItemsList = new List <IWindowItem>();

            // get action description
            var name = platformAction.ToString().Split('.')[2];

            if (refineRes)
            {
                // since the action is of type refine resource
                name = "refining to " + ((RefineResourceAction)platformAction).GetRefiningTo();
            }

            // the platformAction's name
            mNameTextField = new TextField(
                text: name,
                position: Vector2.Zero,
                size: new Vector2(spriteFont.MeasureString(name).X, 0), // the size of the textfield should be as big as the string it contains
                spriteFont: spriteFont,
                color: Color.White);

            // the platformAction's current state ((de)active)
            var stateTextField = new TextField(
                text: platformAction.State.ToString(),
                position: Vector2.Zero,
                size: new Vector2(spriteFont.MeasureString(platformAction.State.ToString()).X, 0), // the size of the textfield should be as big as the string it contains
                spriteFont: spriteFont,
                color: Color.White);

            if (mPlatformAction is MakeFastMilitaryUnit ||
                mPlatformAction is MakeHeavyMilitaryUnit ||
                mPlatformAction is MakeStandardMilitaryUnit ||
                mPlatformAction is MakeGeneralUnit ||
                mPlatformAction is MakeSettlerUnit)
            {
                // don't use the standard text for the button since the action is different (just creat button - will toggle back when created)
                mStateToggleButton = new Button("create", spriteFont, Vector2.Zero)
                {
                    Opacity = 1f
                };
            }
            else
            {
                // button that (de)activates the platformAction
                mStateToggleButton = new Button("(de)activate", spriteFont, Vector2.Zero)
                {
                    Opacity = 1f
                };
            }

            // a textfiel that is just added to shift the button in the horizontal collection
            var emptyToShift = new TextField(
                text: "",
                position: Vector2.Zero,
                size: new Vector2(spriteFont.MeasureString(platformAction.State.ToString()).X, 0), // the size of the textfield should be as big as the string it contains
                spriteFont: spriteFont,
                color: Color.White);

            // button management
            mStateToggleButton.ButtonClicked     += ActivateToggle;
            mStateToggleButton.ButtonReleased    += ToggleButton;
            mStateToggleButton.ButtonHovering    += ShowRequirements;
            mStateToggleButton.ButtonHoveringEnd += HideRequirements;

            // create a horizontal collection of the state and the button
            mCollection = new HorizontalCollection(new List <IWindowItem> {
                stateTextField, mStateToggleButton, emptyToShift
            }, new Vector2(size.X, spriteFont.MeasureString("A").Y + 5), Position);

            //mBottomBar = new BarIWindowItem(size.X - 50, Color.White);

            #region manage the requirements

            // set up
            var productionUnits   = 0;
            var constructionUnits = 0;
            var logisticUnits     = 0;
            var defenseUnits      = 0;

            // count the required units
            foreach (var units in platformAction.UnitsRequired)
            {
                switch (units)
                {
                case JobType.Production:
                    productionUnits += 1;
                    break;

                case JobType.Construction:
                    constructionUnits += 1;
                    break;

                case JobType.Logistics:
                    logisticUnits += 1;
                    break;

                case JobType.Defense:
                    defenseUnits += 1;
                    break;
                }
            }

            // add a unit type + required count to infoBox if it's needed to enable the platformAction, disable it else
            if (productionUnits > 0)
            {
                infoBoxItemsList.Add(new TextField(productionUnits + " production units",
                                                   Vector2.Zero,
                                                   spriteFont.MeasureString(productionUnits + " prouduction units"),
                                                   spriteFont,
                                                   Color.White));
            }
            if (constructionUnits > 0)
            {
                infoBoxItemsList.Add(new TextField(constructionUnits + " construction units",
                                                   Vector2.Zero,
                                                   spriteFont.MeasureString(constructionUnits + " construction units"),
                                                   spriteFont,
                                                   Color.White));
            }
            if (logisticUnits > 0)
            {
                infoBoxItemsList.Add(new TextField(logisticUnits + " logistics units",
                                                   Vector2.Zero,
                                                   spriteFont.MeasureString(logisticUnits + " logistics units"),
                                                   spriteFont,
                                                   Color.White));
            }
            if (defenseUnits > 0)
            {
                infoBoxItemsList.Add(new TextField(defenseUnits + " defense units",
                                                   Vector2.Zero,
                                                   spriteFont.MeasureString(defenseUnits + " defense units"),
                                                   spriteFont,
                                                   Color.White));
            }

            // add required resources infoBox
            if (mPlatformAction is AMakeUnit)
            {
                infoBoxItemsList.AddRange(((AMakeUnit)platformAction).GetBuildingCost().Select(resource => new ResourceIWindowItem(resource.Key, resource.Value, Vector2.Zero, spriteFont)));
            }

            // create a infoBox containing all requirements to activate the platformAction
            mInfoBoxRequirements = new InfoBoxWindow(infoBoxItemsList, Vector2.Zero, Color.White, Color.Black, true, director);

            #endregion
        }