示例#1
0
        public float CalculateDistance(LayerTile tile)
        {
            float dist = visitedTiles.ContainsKey(tile) ? visitedTiles[tile] : 1;

            if (fog.IsVisible(tile))
            {
                //Tile visible, we check real objects
                WorldObject obs = map.GetWorldObject(tile.X, tile.Y);
                WorldObject mob = map.GetMobile(tile.X, tile.Y);
                if (map.IsTileOccupied(tile.X, tile.Y) ||
                    (obs != null && !obs.IsTraversable(wo)) ||
                    (mob != null && !mob.IsTraversable(wo)))
                {
                    dist = float.PositiveInfinity;
                }
            }
            else if (fog.IsPartiallyVisible(tile))
            {
                //partial fog, we check only revealed entity
                WorldObject obs = fog.GetRevealedWO(tile.X, tile.Y);
                if (obs != null && !obs.IsTraversable(wo))
                {
                    dist = float.PositiveInfinity;
                }
            }

            return(dist);
        }
示例#2
0
        /**
         * <summary>
         * Assumes selectedWO is not null. Checks all posible actions between selectedWO and any of the mouse tile WOs
         * </summary>
         */
        private void HandleAction()
        {
            //We can't do anything if we are moving (you'd better not modify that)
            if (!selectedWO.IsActionBlocking())
            {
                ui.ClearActionButtons();
                //As always, when handling actions we must save the instances at the moment
                //If you remove this lines, when a person tries to exit a cottage, for example,
                //the tile for exit will be the currentTile below the button at the moment it is pressed (which will probably be null), and not the tile that was selected
                WorldObject currentWO     = null;
                WorldObject currentMobile = null;
                LayerTile   currentTile   = this.currentTile;
                if (fog == null || fog.IsVisible(currentTile.X, currentTile.Y))
                {
                    currentWO     = this.currentWO;
                    currentMobile = this.currentMobile;
                }
                else if (fog.IsPartiallyVisible(currentTile.X, currentTile.Y))
                {
                    currentWO = fog.GetRevealedWO(currentTile.X, currentTile.Y);
                }
                foreach (ActionBehavior act in selectedWO.allActions)
                {
                    if (act.CanShowButton(currentMobile))
                    {
                        ui.AddAction(act.GetCommandName(currentMobile), () => HandleMovementAction(currentMobile, currentTile, act));
                    }
                    if (act.CanShowButton(currentWO))
                    {
                        ui.AddAction(act.GetCommandName(currentWO), () => HandleMovementAction(currentWO, currentTile, act));
                    }
                }

                if (selectedWO.IsMobile())
                {
                    //A button to move if "we see" the tile is free
                    if ((currentWO == null || currentWO.IsTraversable(selectedWO)) && (currentMobile == null || currentMobile.IsTraversable(selectedWO)))
                    {
                        ui.AddAction("Move", () => CalculatePathDStar(selectedWO, currentTile));
                    }
                }
                Cottage cottage = selectedWO.Owner.FindComponent <Cottage>();
                if (cottage != null)
                {
                    for (int i = 0; i < cottage.GetPeople().Count; i++)
                    {
                        //Careful with event handlers, actions in loops, because the i variable wont work
                        int         aux          = i;
                        WorldObject peopleInside = cottage.GetPeople()[aux];
                        if ((currentMobile == null || currentMobile.IsTraversable(peopleInside)) &&
                            (currentWO == null || currentWO.IsTraversable(peopleInside)))
                        {
                            ui.AddAction(string.Format("Exit cottage {0}: {1}", aux + 1, cottage.GetPeople()[aux].GetWoName()), () => SendExit(aux + 1, currentTile));
                        }
                    }
                }

                if (ui.actions.Count == 1)
                {
                    //if there is only an action, we directly execute it
                    ui.ExecuteAction(0);
                }
                else if (ui.actions.Count > 1)
                {
                    for (int i = 0; i < ui.actions.Count; i++)
                    {
                        //Careful with event handlers, actions in loops, because the i variable wont work
                        int aux = i;
                        if (i >= ui.buttons.Count)
                        {
                            //We have less buttons than actions, create a new one
                            ui.CreateActionButton();
                        }
                        ui.UpdateActionButton(aux);
                    }
                    ui.optionsAlreadyShown = true;
                    lastActionTile         = currentTile;
                    WaveServices.Layout.PerformLayout(Owner.Scene);
                }
            }
        }