Beispiel #1
0
        /// <summary>
        /// Override for MoveToLocation to handle UI changes that don't
        /// happen for AI agents.
        /// </summary>
        /// <param name="newLoc">The Location target.</param>
        protected override void MoveToLocation(Location newLoc)
        {
            base.MoveToLocation(newLoc);

            newLoc.LoadLayout();
            newLoc.LoadMap();

            Game.Instance.Date = Game.Instance.Date.AddSeconds(300);

            Game.Instance.Synchronize();
        }
Beispiel #2
0
        private void UpdateLocation(Location location)
        {
            //Debug.WriteLine("   Starting AI task for " + location.DisplayName);

            _Tasks[_ThreadCount] = Task.Factory.StartNew(() => UpdateLocationOccupants(location));
            _ThreadCount++;

            foreach (Location loc in location.Children)
            {
                this.UpdateLocation(loc);
            }
        }
        public List<Person> GetPeopleAtLocation(Location loc)
        {
            List<Person> atLoc = new List<Person>();

            foreach (Person per in this.People)
            {
                if (per.Location == loc)
                {
                    atLoc.Add(per);
                }
            }

            return atLoc;
        }
Beispiel #4
0
        /// <summary>
        /// Override for MoveToLocation to handle UI changes that don't
        /// happen for AI agents.
        /// </summary>
        /// <param name="newLoc">The Location target.</param>
        public void MoveToLocation(Location newLoc, bool doUpdate = true)
        {
            base.MoveToLocation(newLoc);

            newLoc.LoadLayout();
            newLoc.LoadMap();

            if (doUpdate)
            {
                Game.Instance.Date = Game.Instance.Date.AddSeconds(300);

                Game.Instance.Synchronize();
            }
        }
        public void AddMapButton(Location parent)
        {
            Window form = WindowController.Get<MapWindow>();

            Size offset = new Size(0, 0);

            LocationButton button = new LocationButton();
            button.target = Location.Get(this.Node);
            button.VerticalAlignment = VerticalAlignment.Top;
            button.HorizontalAlignment = HorizontalAlignment.Left;

            if (parent.LocationMode == MapSizeModes.Absolute)
            {
                button.Margin = new Thickness(this.Point.X + offset.Width, this.Point.Y + offset.Height, 0, 0);

                button.Width    = this.Size.Width;
                button.Height   = this.Size.Height;
            }
            else if (parent.LocationMode == MapSizeModes.Relative)
            {
                button.Margin = new Thickness(
                    (this.Point.X + offset.Width)   * parent.AutoSizeMultiplier, 
                    (this.Point.Y + offset.Height)  * parent.AutoSizeMultiplier, 
                    0, 
                    0);

                button.Width    = this.Size.Width    * parent.AutoSizeMultiplier;
                button.Height   = this.Size.Height   * parent.AutoSizeMultiplier;
            }
            else if (parent.LocationMode == MapSizeModes.Percent)
            {
                button.Margin = new Thickness(
                    (((double)this.Point.X / 100) * parent.Size.Width)    + offset.Width,
                    (((double)this.Point.Y / 100) * parent.Size.Height)   + offset.Height,
                    0,
                    0);

                button.Width    = this.Size.Width * parent.AutoSizeMultiplier;
                button.Height   = this.Size.Height * parent.AutoSizeMultiplier;
            }

            button.Load();

            ((Grid)LogicalTreeHelper.FindLogicalNode(form, "grid")).Children.Add(button);

            ToolTip tooltip = new ToolTip();
            tooltip.Content = this.Node;
            button.ToolTip = tooltip;
        }
Beispiel #6
0
        private void UpdateLocationOccupants(Location loc)
        {
            for (int i = 0; i < loc.Occupants.Count; i++)
            {
                if (loc.Occupants[i] == Game.Instance.Player)
                {
                    continue;
                }

                //Debug.Write("       Updating AI for " + occupant.Name);

                DateTime start = DateTime.Now;

                loc.Occupants[i].Update();

                DateTime end = DateTime.Now;

                //Debug.Write(".\tTook " + (end- start) + ".\n");
            }
        }
Beispiel #7
0
        protected virtual void MoveToLocation(Location newLoc)
        {
            if(this.GetType() == typeof(Prop))
            {
                if (this.Location != null)
                {
                    this.Location.Inventory.Remove((Prop)this);
                }

                newLoc.Inventory.Add((Prop)this);
            }
            else if (this.GetType() == typeof(Person))
            {
                if (this.Location != null)
                {
                    this.Location.Occupants.Remove((Person)this);
                }

                newLoc.Occupants.Add((Person)this);
            }
            
            this._location = newLoc;
        }
        public Prop GetClosestProp(List<Prop> props, Location start)
        {
            double min = 0;
            Prop minLoc = null;

            foreach (Prop prop in props)
            {
                double distance = start.TravelTime(prop.Location);

                if (distance < min)
                {
                    min = distance;
                    minLoc = prop;
                }
            }

            return minLoc;
        }
        public List<Prop> GetPropsByAction(GameAction action, Location zone = null)
        {
            List<Prop> props = new List<Prop>();

            foreach (PropTemplate template in this.GetPropTemplatesByAction(action))
            {
                props.AddRange(this.GetPropsByTemplate(template, zone));
            }

            return props;
        }
Beispiel #10
0
        public List<Prop> GetPropsByTemplate(PropTemplate template, Location zone = null)
        {
            List<Prop> props = new List<Prop>();

            List<Prop> haystack = this.Props;

            if (zone != null)
            {
                haystack = zone.Inventory;
            }

            foreach (Prop prop in haystack)
            {
                if (prop.Template == template)
                {
                    props.Add(prop);
                }
            }

            return props;
        }
Beispiel #11
0
 public List<Location> PathfindTo(Location end)
 {
     return Location.Pathfind(this, end);
 }
Beispiel #12
0
        public static List<Location> Pathfind(Location start, Location end)
        {
            List<Location> locPath = new List<Location>();

            PathNode path = PathfindingUtilities.FindPath(
                PathfindingUtilities.PathfindingAlgorithms.Dijkstra, 
                Game.Instance.City.NavMap.Nodes[start], 
                Game.Instance.City.NavMap.Nodes[end], 
                Game.Instance.City.NavMap);

            while (path != null)
            {
                locPath.Add(path.Location);

                path = path.backPointer;
            }

            return locPath;
        }
Beispiel #13
0
        public static List<Location> GetAll(Location root)
        {
            List<Location> locs = new List<Location>();

            locs.Add(root);

            foreach(Location child in root.Children)
            {
                locs.AddRange(Location.GetAll(child));
            }

            return locs;
        }