Esempio n. 1
0
        public ClearZone(int t0, Actor who, ZoneLoc dest) : base(t0, who)
        {
            m_Zone  = dest;
            threats = who.Threats    // these two should agree on whether they're null or not
#if DEBUG
                      ?? throw new ArgumentNullException("who.Threats")
#endif
            ;
            tourism = who.InterestingLocs
#if DEBUG
                      ?? throw new ArgumentNullException("who.InterestingLocs")
#endif
            ;
            Func <Point, bool> ok = pt => m_Zone.Rect.Contains(pt);
            m_Unverified.UnionWith(threats.ThreatWhere(dest.m).Where(ok));
            m_Unverified.UnionWith(tourism.In(dest.m).Where(ok));
#if OBSOLETE
            // the civilian case
            if (null == threats && null == sights_to_see)
            {
                m_Unverified.UnionWith(m_Zone.Rect.Where(pt => who.CanEnter(new Location(m_Zone.m, pt)))); // \todo? eliminate GC thrashing
            }
#endif
            // nonserialized fields
            oai = (m_Actor.Controller as ObjectiveAI)
#if DEBUG
                  ?? throw new ArgumentNullException("who.Controller is ObjectiveAI")
#endif
            ;
        }
Esempio n. 2
0
 private void _upgrade(ObjectiveAI ai)
 {
     if (null == pt_path)
     {
         return;
     }
     loc_path = _upgrade(HomeMap(ai), pt_path);
     pt_path  = null;
 }
Esempio n. 3
0
 private Map?HomeMap(ObjectiveAI ai)
 {
     if (null == pt_path)
     {
         return(null);
     }
     if (0 < reasons.Count)
     {
         return(reasons.First().Key.Map);
     }
     return(ai.ControlledActor.Location.Map);
 }
Esempio n. 4
0
        public void Install(Map m, List <List <Point> >?src, ObjectiveAI ai)
        {
            if (null == src || 0 >= src.Count)
            {
                ForgetStaging();
                return;
            }
            if (null != pt_path && m != HomeMap(ai))
            {
                _upgrade(ai);
            }
            if (null != loc_path)   // merging into location path
            {
                Install(_upgrade(m, src), ai);
                return;
            }
            if (null == pt_path)
            {
                pt_path = src;
            }
            else
            {
                int merge_ub = pt_path.Count;
                int ub       = src.Count;
                int i        = -1;
                while (++i < ub)
                {
                    if (merge_ub <= i)
                    {
                        pt_path.Add(src[i]);
                    }
                    else
                    {
                        var step = pt_path[i];
                        foreach (var pt in src[i])
                        {
                            if (!step.Contains(pt))
                            {
                                step.Add(pt);
                            }
                        }
                    }
                }
            }

            _merge_reasons(ai);
            _expired = false;
        }
Esempio n. 5
0
        public void Install(List <List <Location> >?src, ObjectiveAI ai)
        {
            if (null == src || 0 >= src.Count)
            {
                ForgetStaging();
                return;
            }
            if (null != pt_path)
            {
                _upgrade(ai);
            }
            if (null == loc_path)
            {
                loc_path = src;
            }
            else
            {
                int merge_ub = loc_path.Count;
                int ub       = src.Count;
                int i        = -1;
                while (++i < ub)
                {
                    if (merge_ub <= i)
                    {
                        loc_path.Add(src[i]);
                    }
                    else
                    {
                        var step = loc_path[i];
                        foreach (var pt in src[i])
                        {
                            if (!step.Contains(pt))
                            {
                                step.Add(pt);
                            }
                        }
                    }
                }
            }

            _merge_reasons(ai);
            _expired = false;
        }
Esempio n. 6
0
        private void _merge_reasons(ObjectiveAI ai)
        {
            if (0 < stage_view.Count)
            {
                foreach (var x in stage_view)
                {
                    reasons[x] = (int)What.VIEW;
                }
                stage_view.Clear();
            }
            if (0 < stage_inventory.Count)
            {
                var items = ai.ItemMemory;
                if (null != items)
                {
                    var need = ai.WhatDoINeedNow();
                    var want = ai.WhatDoIWantNow();

                    int code(in Location loc)
                    {
                        var think_is_there = items.WhatIsAt(loc);

                        if (null != think_is_there)
                        {
                            // \todo duplicate cheating postfilters from ActorController::WhereIs
                            foreach (var it in need)
                            {
                                if (think_is_there.Contains(it))
                                {
                                    return((int)What.INVENTORY - (int)it);
                                }
                            }
                            foreach (var it in want)
                            {
                                if (think_is_there.Contains(it))
                                {
                                    return((int)What.INVENTORY - (int)it);
                                }
                            }
                        }
                        return(0);
                    }

                    int test;
                    foreach (var x in stage_inventory)
                    {
                        if (0 != (test = code(in x)))
                        {
                            reasons[x] = test;
                        }
                    }
                }
                stage_inventory.Clear();
            }
            if (0 < stage_generators.Count)
            {
                foreach (var x in stage_generators)
                {
                    reasons[x.Location] = (int)What.GENERATOR_OFF;                                   // will downgrade to real reason on update
                }
                stage_generators.Clear();
            }
        }
Esempio n. 7
0
 [OnDeserialized] private void OnDeserialized(StreamingContext context)
 {
     oai = (m_Actor.Controller as ObjectiveAI) !;
 }