Beispiel #1
0
        public ActionResult DeleteGeneralConfirmed(int id)
        {
            GeneralUnit gUnit = generalUnitService.GetById(id);

            generalUnitService.Delete(gUnit);
            return(RedirectToAction("Details", "Groups", new { id = gUnit.GeneralGroup_Id, active = gUnit.GeneralGroup.ToString() }));
        }
        public void Kill(GeneralUnit unit)
        {
            var lists = new List <List <GeneralUnit> > {
                mIdle, mLogistics, mConstruction, mProduction, mDefense, mManual
            };

            lists.ForEach(l => l.Remove(unit));
        }
Beispiel #3
0
        protected override void CreateUnit()
        {
            var unit = new GeneralUnit(mPlatform, ref mDirector);

            mDirector.GetStoryManager.Level.GameScreen.AddObject(unit);

            mDirector.GetUserInterfaceController.UpdateSLiderHandler();
        }
Beispiel #4
0
 public ActionResult EditGeneral([Bind(Include = "Id,Name,GeneralGroup_Id,GeneralType,Description,Image")] GeneralUnit unit)
 {
     if (ModelState.IsValid)
     {
         unitService.Update(unit);
         return(RedirectToAction("Details", "Groups", new { id = unit.GeneralGroup_Id, active = unit.GeneralType.ToString() }));
     }
     return(View(unit));
 }
Beispiel #5
0
 public ActionResult CreateGeneral(GeneralUnit unit)
 {
     if (ModelState.IsValid)
     {
         generalUnitService.Create(unit);
         return(RedirectToAction("Details", "Groups", new { id = unit.GeneralGroup_Id, active = unit.GeneralType.ToString() }));
     }
     return(View(unit));
 }
Beispiel #6
0
        public ActionResult DeleteGeneral(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GeneralUnit unit = generalUnitService.GetById((int)id);

            if (unit == null)
            {
                return(HttpNotFound());
            }
            return(View(unit));
        }
Beispiel #7
0
        private IPath GetPathForGeneralUnits(GeneralUnit unit, INode destination, int graphIndex)
        {
            IPath path;

            try
            {
                path = PathfindingFactory.GetPathfinding().AStar(mGraphs[graphIndex], unit.CurrentNode, destination);
            }
            catch (KeyNotFoundException)
            {
                path = new SortedPath();
            }

            return(path);
        }
Beispiel #8
0
        PatientsDay GetDailyPatientsFromRaw(ImmutableDictionary <string, int> header, string line)
        {
            var fields = ParseLine(line);
            Dictionary <string, Dictionary <string, int?> > result = new Dictionary <string, Dictionary <string, int?> >();

            foreach (var headerPair in header)
            {
                string[] headerParts = headerPair.Key.Split('.');
                if (headerParts.Length == 3)
                {
                    if (!result.TryGetValue(headerParts[1], out Dictionary <string, int?> regions))
                    {
                        regions = new Dictionary <string, int?>();
                        result.Add(headerParts[1], regions);
                    }
                    regions[headerParts[2]] = GetInt(fields[headerPair.Value]);
                }
            }
            var date        = GetDate(fields[header["date"]]);
            var generalUnit = new GeneralUnit(
                inHospital: GetHospitalMovement(facility: null, "in_hospital", header, fields),
                GetHospitalMovement(facility: null, "icu", header, fields),
                GetHospitalMovement(facility: null, "niv", header, fields),
                GetHospitalMovement(facility: null, "critical", header, fields),
                GetStateDeceased(header, fields),
                GetHospitalMovement(facility: null, "care", header, fields),
                GetDeceasedCare(facility: null, header, fields),
                new OutOfHospital(GetInt(fields[header["state.out_of_hospital.todate"]]))
                );
            ImmutableDictionary <string, Unit> f = ImmutableDictionary <string, Unit> .Empty;

            foreach (string facility in facilities)
            {
                var unit = new Unit(
                    inHospital: GetHospitalMovement(facility, "in_hospital", header, fields),
                    GetHospitalMovement(facility, "icu", header, fields),
                    GetHospitalMovement(facility, "niv", header, fields),
                    GetHospitalMovement(facility, "critical", header, fields),
                    GetDeceased(facility, header, fields),
                    GetHospitalMovement(facility, "care", header, fields),
                    GetDeceasedCare(facility, header, fields)
                    );
                f = f.Add(facility, unit);
            }
            return(new PatientsDay(GetInt(fields[header["day"]]) ?? 0, date.Year, date.Month, date.Day, generalUnit, f));
        }
 /// <summary>
 /// This is a method to find a new home for genunits with destroyed workstations.
 /// </summary>
 /// <param name="unit">The poor unit</param>
 /// <param name="isDefense">True if its a defending unit, false if it is producing</param>
 public void NewProductionHall(GeneralUnit unit, bool isDefense)
 {
     if (isDefense)
     {
         mDefense.Remove(unit);
         unit.ChangeJob(JobType.Idle);
         var units = new List <GeneralUnit>();
         units.Add(unit);
         AssignUnitsFairly(new List <GeneralUnit>(units), true);
     }
     else
     {
         mProduction.Remove(unit);
         unit.ChangeJob(JobType.Idle);
         var units = new List <GeneralUnit>();
         units.Add(unit);
         AssignUnitsFairly(new List <GeneralUnit>(units), false);
     }
 }
Beispiel #10
0
        public ActionResult CreateGeneral(int?id, string type)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var group = groupService.GetById((int)id);

            if (group == null)
            {
                return(HttpNotFound());
            }

            GeneralUnit unit = new GeneralUnit()
            {
                GeneralGroup_Id = (int)id, GeneralType = (GeneralUnitType)Enum.Parse(typeof(GeneralUnitType), type)
            };

            return(View(unit));
        }
Beispiel #11
0
        public void Follow(GeneralUnit unit)
        {
            // now, using an actual velocity and without abruptly stopping, this should look way better.
            var diff = unit.AbsolutePosition - AbsolutePosition;
            // var targetPosition = diff - Geometry.NormalizeVector(diff) * 40 + AbsolutePosition;
            var dist = (float)Geometry.Length(diff);

            mVelocity = Geometry.NormalizeVector(diff) * Speed;
            if (dist < 10)
            {
                mVelocity = default(Vector2);
            }
            else if (dist < 30)
            {
                mVelocity = Vector2.Multiply(mVelocity, dist / 120f);
            }
            else if (dist < 70)
            {
                mVelocity = Vector2.Multiply(mVelocity, dist / 70f);
            }

            AbsolutePosition += mVelocity;
        }
Beispiel #12
0
 public void Kill(GeneralUnit unit)
 {
     mAssignedUnits.Remove(unit);
 }
        /// <summary>
        /// A method for the GeneralUnits to ask for a task to do.
        /// </summary>
        /// <param name="unit">The GeneralUnit asking</param>
        /// <param name="job">Its Job</param>
        /// <param name="assignedAction">The PlatformAction the unit is eventually assigned to</param>
        /// <returns></returns>
        internal Task RequestNewTask(GeneralUnit unit, JobType job, Optional <IPlatformAction> assignedAction)
        {
            var  nodes = new List <INode>();
            Task task;

            switch (job)
            {
            case JobType.Idle:
                //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())
                {
                    var possibleedge = edge as Road;
                    if (possibleedge == null)
                    {
                        continue;
                    }
                    if (!possibleedge.Blueprint)
                    {
                        nodes.Add(edge.GetParent());
                    }
                }
                foreach (var edge in unit.CurrentNode.GetOutwardsEdges())
                {
                    var possibleedge = edge as Road;
                    if (possibleedge == null)
                    {
                        continue;
                    }
                    if (!possibleedge.Blueprint)
                    {
                        nodes.Add(edge.GetChild());
                    }
                }

                if (nodes.Count == 0)
                {
                    //Could be very inefficient, since the Units will bombard the DistributionManager with asks for tasks when there is only one platform
                    //connected to theirs
                    nodes.Add(unit.CurrentNode);
                }
                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, Optional <PlatformBlank> .Of((PlatformBlank)nodes.ElementAt(rndnmbr)), null, assignedAction));

            case JobType.Production:
                throw new InvalidGenericArgumentException("You shouldnt ask for Production tasks, you just assign units to production.");

            case JobType.Defense:
                throw new InvalidGenericArgumentException("You shouldnt ask for Defense tasks, you just assign units to defense.");

            case JobType.Construction:
                if (mBuildingResources.Count == 0)
                {
                    var nulltask = new Task(JobType.Logistics,
                                            Optional <PlatformBlank> .Of(null),
                                            null,
                                            Optional <IPlatformAction> .Of(null));
                    nulltask.Begin = Optional <PlatformBlank> .Of(null);

                    return(nulltask);
                }
                task = mBuildingResources.Dequeue();
                //This means that the Action is paused.
                if (task.Action.IsPresent() && !mPlatformActions.Contains(task.Action.Get()) && task.Job != JobType.Construction)
                {
                    return(RequestNewTask(unit, job, assignedAction));
                }
                if (task.End.IsPresent() && task.GetResource != null)
                {
                    var begin = FindBegin(task.End.Get(), (EResourceType)task.GetResource);
                    //Use BFS to find the place you want to get your resources from
                    if (begin != null)
                    {
                        task.Begin = Optional <PlatformBlank> .Of(begin);
                    }
                    else
                    {
                        //TODO: Talk with felix about how this could affect the killing thing
                        mBuildingResources.Enqueue(task);
                        //This means the unit will identify this task as "do nothing" and ask again.
                        task.Begin = Optional <PlatformBlank> .Of(null);
                    }
                }
                else
                {
                    throw new InvalidGenericArgumentException("There is a task in your queue that is faulty. Check the RequestResource method!!!");
                }
                break;

            case JobType.Logistics:
                if (mRefiningOrStoringResources.Count == 0)
                {
                    var nulltask = new Task(JobType.Logistics,
                                            Optional <PlatformBlank> .Of(null),
                                            null,
                                            Optional <IPlatformAction> .Of(null));
                    nulltask.Begin = Optional <PlatformBlank> .Of(null);

                    return(nulltask);
                }
                task = mRefiningOrStoringResources.Dequeue();
                //This means that the Action is paused.
                if (task.Action.IsPresent() && !mPlatformActions.Contains(task.Action.Get()))
                {
                    return(RequestNewTask(unit, job, assignedAction));
                }
                if (task.End.IsPresent() && task.GetResource != null)
                {
                    var begin = FindBegin(task.End.Get(), (EResourceType)task.GetResource);
                    //Use BFS to find the place you want to get your resources from
                    if (begin != null)
                    {
                        task.Begin = Optional <PlatformBlank> .Of(begin);
                    }
                    else
                    {
                        //TODO: Talk with felix about how this could affect the killing thing
                        mRefiningOrStoringResources.Enqueue(task);
                        //This means the unit will identify this task as "do nothing" and ask again.
                        task.Begin = Optional <PlatformBlank> .Of(null);
                    }
                }
                else
                {
                    throw new InvalidGenericArgumentException("There is a task in your queue that is faulty. Check the RequestResource method!!!");
                }
                break;

            default:
                throw new InvalidGenericArgumentException("Your requested JobType does not exist.");
            }

            mKilled = mKilled.Select(p => new Pair <int, int>(p.GetFirst(), p.GetSecond() - 1)).ToList();
            if (mKilled != null)
            {
                mKilled.RemoveAll(p => p.GetSecond() < 0);
                return(mKilled.TrueForAll(p => !task.Contains(p.GetFirst())) ? task : RequestNewTask(unit, job, assignedAction));
            }

            return(task);
        }
 /// <summary>
 /// Is called to add the unit with a certain job.
 /// </summary>
 /// <param name="unit">the unit that has been mentioned</param>
 /// <param name="job">the job of the unit.</param>
 public void Register(GeneralUnit unit, JobType job)
 {
     GetJobUnits(job).Add(unit);
 }
        /*
         * /// <summary>
         * /// Manually Assign Units to a certain PlatformAction.
         * /// </summary>
         * /// <param name="amount">The amount of units to be assigned</param>
         * /// <param name="action">The action to which the units shall be assigned</param>
         * /// <param name="job">The Job the units had/are supposed to have.</param>
         * public void ManualAssign(int amount, IPlatformAction action, JobType job)
         * {
         *  var oldlist = GetJobUnits(job);
         *
         *  //COLLECT THE UNITS
         *  List<GeneralUnit> list;
         *  if (job == JobType.Defense)
         *  {
         *      list = GetUnitsFairly(amount, mDefPlatforms, true);
         *  }
         *  else if (job == JobType.Production)
         *  {
         *      list = GetUnitsFairly(amount, mProdPlatforms, false);
         *  }
         *  else
         *  {
         *      list = new List<GeneralUnit>();
         *      for (var i = amount; i >= 0; i--)
         *      {
         *          //Change the job of a random unit
         *          var rand = mRandom.Next(0, oldlist.Count);
         *          var removeit = oldlist.ElementAt(rand);
         *          list.Add(removeit);
         *      }
         *  }
         *
         *  foreach (var unit in list)
         *  {
         *      mManual.Add(unit);
         *      action.AssignUnit(unit, job);
         *      if (job == JobType.Production)
         *      {
         *
         *      }
         *      else if (job == JobType.Defense)
         *      {
         *
         *      }
         *  }
         *
         *  if (mHandler != null)
         *  {
         *      mHandler.Refresh();
         *  }
         * }
         *
         * /// <summary>
         * /// Manually Unassign some units of a Platformaction.
         * /// </summary>
         * /// <param name="job">The Job they are having</param>
         * /// <param name="amount">The amount of units to be unassigned</param>
         * /// <param name="action">The platformaction of which they shall be unassigned</param>
         * public void ManualUnassign(JobType job, int amount, IPlatformAction action)
         * {
         *  var list = action.UnAssignUnits(amount, job);
         *  foreach (var unit in list)
         *  {
         *      mManual.Remove(unit);
         *      unit.ChangeJob(JobType.Idle);
         *      mIdle.Add(unit);
         *  }
         *
         *  if (mHandler != null)
         *  {
         *      mHandler.Refresh();
         *  }
         * }
         */
        #endregion

        #region Register or Unregister

        /// <summary>
        /// Is called by the unit when it is created.
        /// </summary>
        /// <param name="unit">the unit that has been created</param>
        public void Register(GeneralUnit unit)
        {
            mIdle.Add(unit);
        }
Beispiel #16
0
        /// <summary>
        /// This get executed when a settler is transformed into a command center
        /// Essentially this builds a command center
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        /// <param name="v"> the position at which the settler is currently at</param>
        /// <param name="s"> settler passes itself along so that it can be deleted </param>
        private void SettlerBuild(object sender, EventArgs eventArgs, Vector2 v, Settler s)
        {
            // TODO eventually the EPlacementType should be instance but currently that
            // TODO requires a road to be place and therefore throws an exception !!!!!

            // adds the command center to the GameScreen, as well as two general units

            var cCenter = PlatformFactory.Get(EStructureType.Command, ref mDirector, v.X - 55, v.Y - 100, commandBlueprint: false);

            mDirector.GetMilitaryManager.AddPlatform(cCenter);
            mDirector.GetStoryManager.Level.Map.AddPlatform(cCenter);

            var genUnit = new GeneralUnit(cCenter, ref mDirector);

            AddObject(genUnit);

            var genUnit2 = new GeneralUnit(cCenter, ref mDirector);

            AddObject(genUnit2);

            var genUnit3 = new GeneralUnit(cCenter, ref mDirector);

            AddObject(genUnit3);

            /* This is only for Debug
             * var beginRes = new Dictionary<EResourceType, int>
             * {
             *  {EResourceType.Metal, 100},
             *  {EResourceType.Stone, 100},
             *  {EResourceType.Water, 100},
             *  {EResourceType.Oil, 100},
             *  {EResourceType.Copper, 100},
             *  {EResourceType.Fuel, 100},
             *  {EResourceType.Chip, 100},
             *  {EResourceType.Concrete, 100},
             *  {EResourceType.Plastic, 100},
             *  {EResourceType.Steel, 100},
             *  {EResourceType.Sand, 100},
             *  {EResourceType.Silicon, 100},
             *  {EResourceType.Trash, 2}
             * }; // */

            var beginRes = new Dictionary <EResourceType, int> {
                { EResourceType.Metal, 12 }, { EResourceType.Stone, 8 }
            };

            foreach (var pair in beginRes)
            {
                for (int i = 0; i < pair.Value; i++)
                {
                    cCenter.StoreResource(new Resource(pair.Key, cCenter.Center, mDirector));

/*                    cCenter.StoreResource(new Resource(pair.Key, cCenter.Center, mDirector));
 *                  cCenter.StoreResource(new Resource(pair.Key, cCenter.Center, mDirector));
 *                  cCenter.StoreResource(new Resource(pair.Key, cCenter.Center, mDirector));
 *                  cCenter.StoreResource(new Resource(pair.Key, cCenter.Center, mDirector)); */
                }
            }


            // removes the settler from the GameScreen
            RemoveObject(s);
            mUistarted = true;
        }