Exemple #1
0
        public bool CanSee(int x1, int y1, int x2, int y2)
        {
            List <Point> line = Misc.GetLine(x1, y1, x2, y2, true);

            foreach (var p in line)
            {
                MapsquareData msdc = (MapsquareData)this.map_data.GetSingleComponent(p.X, p.Y, nameof(MapsquareData));
                if (msdc.blocksView)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        public void process(IEnumerable <AbstractEntity> playersUnits)
        {
            if (!this.ReCheckVisibility)
            {
                return;
            }
            this.ReCheckVisibility = false;

            // Set all to hidden initially
            for (int y = 0; y < this.map_data.getHeight(); y++)
            {
                for (int x = 0; x < this.map_data.getWidth(); x++)
                {
                    foreach (AbstractEntity sq in this.map_data.map[x, y])
                    {
                        MapsquareData msdc = (MapsquareData)sq.GetComponent(nameof(MapsquareData));
                        if (msdc != null)
                        {
                            msdc.visible = false;
                            break;
                        }
                    }
                }
            }

            // loop through each unit and see if they can see it
            foreach (var unit in playersUnits)
            {
                var pos = (PositionComponent)unit.GetComponent(nameof(PositionComponent));
                for (int y = 0; y < this.map_data.getHeight(); y++)
                {
                    for (int x = 0; x < this.map_data.getWidth(); x++)
                    {
                        foreach (AbstractEntity sq in this.map_data.map[x, y])
                        {
                            MapsquareData msdc = (MapsquareData)sq.GetComponent(nameof(MapsquareData));
                            if (msdc != null)
                            {
                                if (msdc.visible == false)   // Otherwise we know we've already checked it
                                {
                                    this.CheckAndMarkVisibility(pos.x, pos.y, x, y);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void CheckAndMarkVisibility(int x1, int y1, int x2, int y2)
        {
            List <Point> line = Misc.GetLine(x1, y1, x2, y2, true);

            foreach (var p in line)
            {
                foreach (AbstractEntity sq in this.map_data.map[p.X, p.Y])
                {
                    MapsquareData msdc = (MapsquareData)sq.GetComponent(nameof(MapsquareData)); // todo - better way of selecting map component
                    if (msdc != null)
                    {
                        msdc.visible = true; // Even walls get seen
                        msdc.seen    = true;
                        if (msdc.blocksView)
                        {
                            return;
                        }
                        break; // Found the mapsquare component, so move to next square
                    }
                }
            }
        }
        public void Process(List <AbstractEffect> effects)
        {
            // Draw map
            MapData map_data = this.viewData.GetMapData();

            if (map_data.map != null)
            {
                this.view.mapConsole.Clear();
                for (int y = 0; y < map_data.getHeight(); y++)
                {
                    for (int x = 0; x < map_data.getWidth(); x++)
                    {
                        var           entities = map_data.map[x, y];
                        var           mapEnt   = entities.Single(ent => ent.GetComponents().ContainsKey(nameof(MapsquareData)));
                        MapsquareData msdc     = (MapsquareData)mapEnt.GetComponent(nameof(MapsquareData));
                        if (msdc.visible || Settings.DEBUG_DRAW_ALL)
                        {
                            // Only draw stuff if mapsquare visible
                            AbstractEntity   sq = map_data.GetComponentToDraw(x, y);
                            GraphicComponent gc = (GraphicComponent)sq.GetComponent(nameof(GraphicComponent));
                            RLCell           tc = gc.getVisibleChar();
                            this.view.mapConsole.Set(x, y, tc);
                            if (sq == this.viewData.GetCurrentUnit())
                            {
                                this.view.mapConsole.SetBackColor(x, y, RLColor.Yellow);
                            }
                        }
                        else if (msdc.seen)
                        {
                            AbstractEntity   sq = map_data.GetComponentToDraw(x, y);
                            GraphicComponent gc = (GraphicComponent)sq.GetComponent(nameof(GraphicComponent));
                            this.view.mapConsole.Set(x, y, gc.getSeenChar());
                        }
                        else
                        {
                            this.view.mapConsole.Set(x, y, this.invisible);
                        }
                    }
                }
            }

            // Draw effects
            foreach (var effect in effects)
            {
                effect.draw(this.view.mapConsole);
            }

            // Draw line
            var line2 = this.viewData.GetLine();

            if (line2 != null)
            {
                foreach (var point in line2)
                {
                    this.view.mapConsole.SetBackColor(point.X, point.Y, RLColor.Gray);
                }
            }

            // Draw hover text
            this.view.mapConsole.Print(1, DefaultRLView._mapHeight - 1, this.viewData.GetHoverText(), RLColor.White);

            // Draw crew
            this.view.crewListConsole.Clear();
            int yPos = 0;

            this.view.crewListConsole.Print(0, yPos, "CREW LIST", RLColor.White);
            yPos++;
            int idx = 1;

            foreach (AbstractEntity e in this.viewData.GetUnits())
            {
                RLColor          c   = RLColor.White;
                MobDataComponent mdc = (MobDataComponent)e.GetComponent(nameof(MobDataComponent));
                if (e == this.viewData.GetCurrentUnit())
                {
                    c = RLColor.Yellow; // Highlight selected unit
                }
                else if (mdc.actionPoints <= 0)
                {
                    c = RLColor.Gray;
                }
                MovementDataComponent move = (MovementDataComponent)e.GetComponent(nameof(MovementDataComponent));
                string routeIndicator      = move.route == null || move.route.Count == 0 ? "" : "(R)";
                this.view.crewListConsole.Print(0, yPos, $"{idx}: {e.name} {routeIndicator} ({mdc.actionPoints} APs)", c);
                yPos++;
                idx++;
            }

            // Draw unit stats or menu selection
            this.view.statConsole.Clear();
            yPos = 0;
            Dictionary <int, AbstractEntity> items = this.viewData.GetItemSelectionList();

            if (items != null && items.Count > 0)
            {
                foreach (var idx2 in items.Keys)
                {
                    this.view.statConsole.Print(0, yPos, $"{idx2} : {items[idx2].name}", RLColor.White);
                    yPos++;
                }
            }
            else
            {
                AbstractEntity currentUnit = this.viewData.GetCurrentUnit();
                if (currentUnit != null)
                {
                    foreach (var s in this.viewData.GetStatsFor(currentUnit))
                    {
                        this.view.statConsole.Print(0, yPos, s, RLColor.White);
                        yPos++;
                    }
                }
            }

            // Draw log
            this.view.logConsole.Clear();
            var log = this.viewData.GetLog();
            int pos = 1;

            foreach (var line in log)
            {
                this.view.logConsole.Print(1, pos++, line, RLColor.White);
            }
        }