Esempio n. 1
0
 internal void ReloadContent(ref Director director, ContentManager content)
 {
     base.ReloadContent(ref director);
     if (Carrying.IsPresent())
     {
         Carrying.Get().ReloadContent(ref director);
     }
     mDirector       = director;
     mGenUnitTexture = content.Load <Texture2D>("GenUnit");
 }
Esempio n. 2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(mGenUnitTexture,
                             AbsolutePosition,
                             null,
                             Color.White,
                             0f,
                             new Vector2(10),
                             Vector2.One,
                             SpriteEffects.None,
                             LayerConstants.GeneralUnitLayer);

            if (Carrying.IsPresent())
            {
                Carrying.Get().Draw(spriteBatch);
            }
        }
Esempio n. 3
0
        public override bool Die()
        {
            // stats tracking for the death of a general unit
            mDirector.GetStoryManager.UpdateUnits("lost");

            mTask = new Task(Job, Optional <PlatformBlank> .Of(null), null, Optional <IPlatformAction> .Of(null));
            if (Carrying.IsPresent())
            {
                Carrying.Get().Die();
                Carrying = Optional <Resource> .Of(null);
            }

            mDirector.GetDistributionDirector.GetManager(Graphid).Kill(this);
            mAssignedAction?.Kill(this);
            mDirector.GetStoryManager.Level.GameScreen.RemoveObject(this);

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Logistics and Construction resemble each other very much, so this is the method to handle both.
        /// </summary>
        private void HandleTransport(GameTime time)
        {
            if (!mIsMoving && mDone)
            {
                mDone = false;

                mTask = mDirector.GetDistributionDirector.GetManager(Graphid).RequestNewTask(unit: this, job: Job, assignedAction: Optional <IPlatformAction> .Of(null));
                //First go to the location where you want to get your Resource from
                //Check if the given destination is null (it shouldnt).
                if (mTask.Begin.IsPresent())
                {
                    mDestination = Optional <INode> .Of(mTask.Begin.Get());

                    TargetGraphid = mTask.Begin.Get().GetGraphIndex();
                }
                else
                {
                    //In this case the DistributionManager has given you no valid task. That means there is no work in this job to be done. Ask in the next cycle.
                    mDone = true;
                }
            }

            //This means we arrived at the point we want to pick up a Resource
            if (mTask.Begin.IsPresent() && CurrentNode.Equals(mTask.Begin.Get()) &&
                ReachedTarget(mTask.Begin.Get().Center))
            {
                if (!Carrying.IsPresent())
                {
                    if (mTask.GetResource != null)
                    {
                        PickUp((EResourceType)mTask.GetResource);
                    }

                    //Failed to get resource, because no Resources were present. Tell the DistributionManager and consider your work done.
                    if (!Carrying.IsPresent())
                    {
                        if (mTask.Job == JobType.Logistics)
                        {
                            if (mTask.Action.IsPresent())
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, mTask.Action.Get());
                                }
                            }
                            else
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, null);
                                }
                            }
                        }
                        if (mTask.Job == JobType.Construction)
                        {
                            if (mTask.Action.IsPresent())
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, mTask.Action.Get(), true);
                                }
                            }
                            else
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, null, true);
                                }
                            }
                        }
                        mDone = true;
                    }
                }

                //Everything went fine with picking up, so now move on to your final destination
                if (mTask.End.IsPresent() && !mDone)
                {
                    mDestination = Optional <INode> .Of(mTask.End.Get());

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

            //This means we arrived at the point we want to leave the Resource and consider our work done
            if (mTask.End.IsPresent() && CurrentNode.Equals(mTask.End.Get()) &&
                ReachedTarget(mTask.End.Get().Center) && Carrying.IsPresent())
            {
                var res = Carrying.Get();
                res.UnFollow();
                ((PlatformBlank)CurrentNode).StoreResource(res);
                Carrying = Optional <Resource> .Of(null);

                mDone = true;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// In the Idle case the unit will just get a Target to move to and do so.
        /// In the Production case the unit will go to the producing Platform and call its produce method.
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (!mInitialized)
            {
                return;
            }
            //If true, this unit has still a task to finish and shall not act like the job it has now until the task is finished.
            //This should only occur when Logistic or Constructing units have only just picked up a Resource and their job changed after that.
            if (mFinishTask)
            {
                RegulateMovement();
                if (Carrying.IsPresent())
                {
                    Carrying.Get().Follow(this);
                }
                //This means we arrived at the point we want to leave the Resource and consider our work done
                if (!mTask.End.IsPresent() || !CurrentNode.Equals(mTask.End.Get()) ||
                    !ReachedTarget(mTask.End.Get().Center))
                {
                    return;
                }

                if (Carrying.IsPresent())
                {
                    var res = Carrying.Get();
                    res.UnFollow();
                    ((PlatformBlank)CurrentNode).StoreResource(res);
                    Carrying = Optional <Resource> .Of(null);
                }
                mDone = true;
                //We can now do the job we were assigned to.
                mFinishTask = false;
            }
            else
            {
                switch (Job)
                {
                case JobType.Idle:
                    if (!mIsMoving && mDone)
                    {
                        mDone = false;

                        mTask = mDirector.GetDistributionDirector.GetManager(Graphid)
                                .RequestNewTask(unit: this, job: Job, assignedAction: Optional <IPlatformAction> .Of(null));
                        //Check if the given destination is null (it shouldnt)
                        if (mTask.End.IsPresent())
                        {
                            mDestination = Optional <INode> .Of(mTask.End.Get());

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

                    RegulateMovement();

                    //We arrived at the target, so its now time to get another job
                    if (mNodeQueue.Count == 0 && Job == JobType.Idle)
                    {
                        mDone = true;
                    }
                    break;

                case JobType.Production:
                    //You arrived at your destination and you now want to work.
                    if (!mIsMoving && !mDone && CurrentNode.Equals(mTask.End.Get()) && !mAssigned)
                    {
                        mTask.End.Get().ShowedUp(this, Job);
                        mAssigned = true;
                    }
                    if (mAssigned)
                    {
                        mTask.End.Get().Produce();
                    }

                    RegulateMovement();
                    break;

                case JobType.Defense:
                    //You arrived at your destination and you now want to work.
                    if (!mIsMoving && !mDone && CurrentNode.Equals(mTask.End.Get()))
                    {
                        if (!mAssigned)
                        {
                            mTask.End.Get().ShowedUp(this, Job);
                            mAssigned = true;
                        }
                    }
                    RegulateMovement();
                    break;

                case JobType.Logistics:

                    HandleTransport(gametime);
                    RegulateMovement();

                    if (Carrying.IsPresent())
                    {
                        Carrying.Get().Follow(this);
                    }
                    break;

                case JobType.Construction:
                    HandleTransport(gametime);
                    RegulateMovement();

                    if (Carrying.IsPresent())
                    {
                        Carrying.Get().Follow(this);
                    }
                    break;
                }
            }
        }