Esempio n. 1
0
        IAssignment CreateSleepAssignmentIfNeeded(ILivingObject worker, ActionPriority priority)
        {
            if (priority == ActionPriority.High && worker.Exhaustion < 500)
            {
                return(null);
            }

            if (priority == ActionPriority.Idle && worker.Exhaustion < 100)
            {
                return(null);
            }

            var env = worker.Environment;

            var ob = env.Contents
                     .OfType <IItemObject>()
                     .Where(o => o.ItemID == ItemID.Bed)
                     .Where(o => o.IsReserved == false && o.IsInstalled)
                     .OrderBy(o => (o.Location - worker.Location).ManhattanLength)
                     .Where(o => AStar.CanReach(env, worker.Location, o.Location, DirectionSet.Exact))
                     .FirstOrDefault();

            if (ob != null)
            {
                m_priorityAction = true;
                var job = new MoveSleepAssignment(this, ob);
                ob.ReservedBy = this;
                return(job);
            }

            return(null);
        }
Esempio n. 2
0
        IAssignment IJobSource.FindAssignment(ILivingObject living)
        {
            var tick = this.Environment.World.TickNumber;

            var designations = m_map
                               .Where(kvp => kvp.Value.Job == null && kvp.Value.ReachableSimple && kvp.Value.NextReacahbleCheck <= tick)
                               .OrderBy(kvp => (kvp.Key - living.Location).Length);

            foreach (var d in designations)
            {
                var p  = d.Key;
                var dt = d.Value;

                var ds = GetDesignationPositioning(p, dt.Type);

                // XXX we should pass the found path to the job, to avoid re-pathing
                bool canreach = AStar.CanReach(this.Environment, living.Location, p, ds);
                if (!canreach)
                {
                    dt.NextReacahbleCheck = tick + 10;
                    continue;
                }

                IAssignment job;

                switch (dt.Type)
                {
                case DesignationType.Mine:
                case DesignationType.CreateStairs:
                    MineActionType mat = DesignationTypeToMineActionType(dt.Type);

                    job = new Jobs.AssignmentGroups.MoveMineAssignment(this, this.Environment, p, mat);

                    break;

                case DesignationType.FellTree:

                    job = new Jobs.AssignmentGroups.MoveFellTreeAssignment(this, this.Environment, p);
                    break;

                default:
                    throw new Exception();
                }

                this.Environment.World.Jobs.Add(job);
                dt.Job = job;

                return(job);
            }

            return(null);
        }
Esempio n. 3
0
        public ItemObject GetReachableItemByDistance(IntVector3 location, IItemFilter filter,
                                                     Unreachables unreachables)
        {
            var items = m_items
                        .Where(i => i.IsReserved == false && i.IsInstalled == false && unreachables.IsUnreachable(i.Location) == false)
                        .Where(i => filter.Match(i))
                        .OrderBy(i => (i.Location - location).ManhattanLength);

            foreach (var item in items)
            {
                var found = AStar.CanReach(m_env, location, item.Location, DirectionSet.Exact);

                if (found)
                {
                    return(item);
                }

                unreachables.Add(item.Location);
            }

            return(null);
        }