Beispiel #1
0
 public Entity(string name, Position pos, char left, char right, Color coloring, int faction, Sheet stats, Dijkstra seeker, ImmutableDictionary <Position, int> enemies,
               ImmutableDictionary <Position, int> allies, ImmutableDictionary <Position, int> obstacles)
 {
     Name      = name;
     Pos       = pos;
     Left      = left;
     Right     = right;
     Coloring  = coloring;
     Faction   = faction;
     Stats     = stats;
     Seeker    = seeker;
     Enemies   = enemies;
     Allies    = allies;
     Obstacles = obstacles;
 }
Beispiel #2
0
        public Entry()
        {
            State s = new State();

            s.Entities     = new EntityDictionary();
            s.Initiative   = new Schedule();
            s.TurnsLeft    = 0;
            s.DungeonStart = new Dungeon(TilesetType.DEFAULT_DUNGEON, 40, 40); //ROUND_ROOMS_DIAGONAL_CORRIDORS
            var spawnPoint = s.DungeonStart.LogicWorld.RandomMatch(Dungeon.Floor);


            Seeker       = new Dijkstra(s.DungeonStart.LogicWorld);
            VisualRandom = new XSRandom();
            BeingDamaged = new Dictionary <string, bool>();

//            Player.Seeker.SetGoal(Player.Pos.Y, Player.Pos.X);
//            Player.Seeker.Scan();

            for (int i = 0; i < 6; i++)
            {
                do
                {
                    if (s.Entities.Contains(spawnPoint))
                    {
                        spawnPoint = s.DungeonStart.LogicWorld.RandomMatch(Dungeon.Floor);
                        continue;
                    }
                    Entity player =
                        new Entity("Hero " + ((char)(65 + i)), "@" + WeaponGlyphs[i], _playerColors[i], spawnPoint.Y,
                                   spawnPoint.X, 5, 3 + XSSR.Next(4), 0).UpdateStats(health: new Gauge(10), damage: 3);
                    // \u1202
                    player.Seeker = new Dijkstra(s.DungeonStart.LogicWorld);
                    s.Entities.Add(player);
                    spawnPoint = s.DungeonStart.LogicWorld.RandomMatch(Dungeon.Floor);
                    break;
                } while (true);
            }

            for (int i = 0; i < 25; i++)
            {
                spawnPoint = s.DungeonStart.LogicWorld.RandomMatch(Dungeon.Floor);
                if (spawnPoint.Y >= 0 && !s.Entities.Contains(spawnPoint))
                {
                    Entity baddie = new Entity("Baddie " + (char)(65 + i), "b" + IconGlyphs.RandomElement(), _bloodRed, spawnPoint.Y, spawnPoint.X, 4, XSSR.Next(1, 5), -1);
                    baddie.Seeker = new Dijkstra(s.DungeonStart.LogicWorld);
//                    baddie.Seeker.SetGoal(baddie.Pos.Y, baddie.Pos.X);
//                    baddie.Seeker.Scan();
                    s.Entities.Add(baddie);
                }
            }
            foreach (var k in s.Entities.NameToEntity.Keys)
            {
                IEnumerable <Position> foes =
                    s.Entities.NameToEntity.Where(kv => kv.Value.Faction != s.Entities[k].Faction)
                    .Select(e => e.Value.Pos);
                s.Entities[k] = s.Entities[k].AddEnemies(foes);
                IEnumerable <Position> friends =
                    s.Entities.NameToEntity.Where(kv => kv.Value.Faction == s.Entities[k].Faction)
                    .Select(e => e.Value.Pos);
                s.Entities[k] = s.Entities[k].AddAllies(friends);
            }
            s.StepsTaken = 0;
            s.XSSRState  = XSSR.GetState();
            H.S          = s;

            H.ResetInitiative();
            Entity first = H.S.Entities[H.S.Initiative.PeekTurn().Actor];

            H.S.CurrentActor = first.Name;
            H.S.Cursor       = first.Pos;
            H.S.Camera       = first.Pos;
            if (first.Faction == 0)
            {
                Seeker.SetGoal(first.Pos.Y, first.Pos.X);
                Seeker.Scan(first);

                H.S.CurrentReason = WaitReason.Receiving;
                H.Remember();
            }


            //            Player.Seeker.GetPath(Player.Y, Player.X);
        }
Beispiel #3
0
        public bool PlaceBones()
        {
            /*
             * for (int sy = Height + 10; sy > -Width - 20; sy -= 40)
             * {
             *  for (int x = -10, y = sy; x < Width + 20 && y < Height + 20; x += 10, y += 10)
             *  {
             *      DLevel.Insert(Herringbone.Horizontal.RandomElement(), y, x);
             *  }
             * }
             * for (int sy = Height - 20; sy > -Width - 20; sy -= 40)
             * {
             *  for (int x = -10, y = sy; x < Width + 20 && y < Height + 20; x += 10, y += 10)
             *  {
             *      DLevel.Insert(Herringbone.Vertical.RandomElement(), y, x);
             *  }
             * }
             * for(int x = 0; x < Width; x++)
             * {
             *  DLevel[0, x] = '#';
             *  DLevel[1, x] = '#';
             *  DLevel[Height - 1, x] = '#';
             *  DLevel[Height - 2, x] = '#';
             * }
             * for(int y = 0; y < Height; y++)
             * {
             *  DLevel[y, 0] = '#';
             *  DLevel[y, 1] = '#';
             *  DLevel[y, Width - 1] = '#';
             *  DLevel[y, Width - 2] = '#';
             * }
             */
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (World[y, x] == '#')
                    {
                        int q = 0;
                        q |= (y <= 0 || World[y - 1, x] == '#') ? 1 : 0;
                        q |= (y <= 0 || x >= Width - 1 || World[y - 1, x + 1] == '#') ? 2 : 0;
                        q |= (x >= Width - 1 || World[y, x + 1] == '#') ? 4 : 0;
                        q |= (y >= Height - 1 || x >= Width - 1 || World[y + 1, x + 1] == '#') ? 8 : 0;
                        q |= (y >= Height - 1 || World[y + 1, x] == '#') ? 16 : 0;
                        q |= (y >= Height - 1 || x <= 0 || World[y + 1, x - 1] == '#') ? 32 : 0;
                        q |= (x <= 0 || World[y, x - 1] == '#') ? 64 : 0;
                        q |= (y <= 0 || x <= 0 || World[y - 1, x - 1] == '#') ? 128 : 0;

                        if (q == 0xff)
                        {
                            LogicWorld[y, x] = Dark; //(int)' '
                        }
                        else
                        {
                            LogicWorld[y, x] = Wall;
                        }
                    }
                    else
                    {
                        LogicWorld[y, x] = Floor;
                    }
                }
            }
            Entrance = LogicWorld.RandomMatch(Floor);
            if (Entrance.Y < 0)
            {
                return(false);
            }

            LogicWorld = LogicWorld.Surround(Dark);
            World      = World.Surround(' ');
            Height    += 2;
            Width     += 2;

            Dijkstra scanner = new Dijkstra(LogicWorld);

            scanner.Reset();
            scanner.SetGoal(Entrance.Y + 1, Entrance.X + 1);
            scanner.Scan(new Entity("Blubberrump Corndogg X-TREME", "  ", Entrance.Y + 1, Entrance.X + 1));
            int floorCount = 0;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (scanner.CombinedMap[y, x] == Dark)
                    {
                        LogicWorld[y, x] = Dark;
                        World[y, x]      = ' ';
                    }
                    else if (scanner.CombinedMap[y, x] < Floor)
                    {
                        ++floorCount;
                    }
                }
            }
            if (floorCount < Height * Width * 0.125)
            {
                return(false);
            }
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (LogicWorld[y, x] == Wall)
                    {
                        bool n  = (y <= 0 || LogicWorld[y - 1, x] == Wall);
                        bool ne = (y <= 0 || x >= Width - 1 || LogicWorld[y - 1, x + 1] == Wall || LogicWorld[y - 1, x + 1] == Dark);
                        bool e  = (x >= Width - 1 || LogicWorld[y, x + 1] == Wall);
                        bool se = (y >= Height - 1 || x >= Width - 1 || LogicWorld[y + 1, x + 1] == Wall || LogicWorld[y + 1, x + 1] == Dark);
                        bool s  = (y >= Height - 1 || LogicWorld[y + 1, x] == Wall);
                        bool sw = (y >= Height - 1 || x <= 0 || LogicWorld[y + 1, x - 1] == Wall || LogicWorld[y + 1, x - 1] == Dark);
                        bool w  = (x <= 0 || LogicWorld[y, x - 1] == Wall);
                        bool nw = (y <= 0 || x <= 0 || LogicWorld[y - 1, x - 1] == Wall || LogicWorld[y - 1, x - 1] == Dark);

                        if (n)
                        {
                            if (e)
                            {
                                if (s)
                                {
                                    if (w)
                                    {
                                        World[y, x] = '┼';
                                    }
                                    else
                                    {
                                        World[y, x] = '├';
                                    }
                                }
                                else if (w)
                                {
                                    World[y, x] = '┴';
                                }
                                else
                                {
                                    World[y, x] = '└';
                                }
                            }
                            else if (s)
                            {
                                if (w)
                                {
                                    World[y, x] = '┤';
                                }
                                else
                                {
                                    World[y, x] = '│';
                                }
                            }
                            else if (w)
                            {
                                World[y, x] = '┘';
                            }
                            else
                            {
                                World[y, x] = '│';
                            }
                        }
                        else if (e)  // ┼ ├ ┤ ┴ ┬ ┌ ┐ └ ┘ │ ─
                        {
                            if (s)
                            {
                                if (w)
                                {
                                    World[y, x] = '┬';
                                }
                                else
                                {
                                    World[y, x] = '┌';
                                }
                            }
                            else if (w)
                            {
                                World[y, x] = '─';
                            }
                            else
                            {
                                World[y, x] = '─';
                            }
                        }
                        else if (s)
                        {
                            if (w)
                            {
                                World[y, x] = '┐';
                            }
                            else
                            {
                                World[y, x] = '│';
                            }
                        }
                        else if (w)
                        {
                            World[y, x] = '─';
                        }
                        else
                        {
                            World[y, x] = '─';
                        }
                    }
                    else
                    {
                        if (LogicWorld[y, x] == Dark)
                        {
                            World[y, x] = ' ';
                        }
                    }
                }
            }
            //vertical crossbar removal
            for (int y = 1; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    // ┼ ├ ┤ ┴ ┬ ┌ ┐ └ ┘ │ ─
                    if (World[y, x] == '┼' || World[y, x] == '├' || World[y, x] == '┤' || World[y, x] == '┴')
                    {
                        if (World[y - 1, x] == '┼' || World[y - 1, x] == '├' || World[y - 1, x] == '┤' || World[y - 1, x] == '┬')
                        {
                            if ((y <= 0 || x >= Width - 1 || LogicWorld[y - 1, x + 1] == Wall || LogicWorld[y - 1, x + 1] == Dark) &&
                                (y <= 0 || x <= 0 || LogicWorld[y - 1, x - 1] == Wall || LogicWorld[y - 1, x - 1] == Dark) &&
                                (y <= 0 || x >= Width - 1 || LogicWorld[y, x + 1] == Wall || LogicWorld[y, x + 1] == Dark) &&
                                (y <= 0 || x <= 0 || LogicWorld[y, x - 1] == Wall || LogicWorld[y, x - 1] == Dark))
                            {
                                switch (World[y, x])
                                {
                                case '┼':
                                    World[y, x] = '┬';
                                    break;

                                case '├':
                                    World[y, x] = '┌';
                                    break;

                                case '┤':
                                    World[y, x] = '┐';
                                    break;

                                case '┴':
                                    World[y, x] = '─';
                                    break;
                                }
                                switch (World[y - 1, x])
                                {
                                case '┼':
                                    World[y - 1, x] = '┴';
                                    break;

                                case '├':
                                    World[y - 1, x] = '└';
                                    break;

                                case '┤':
                                    World[y - 1, x] = '┘';
                                    break;

                                case '┬':
                                    World[y - 1, x] = '─';
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            //horizontal crossbar removal
            for (int y = 0; y < Height; y++)
            {
                for (int x = 1; x < Width; x++)
                {
                    // ┼ ├ ┤ ┴ ┬ ┌ ┐ └ ┘ │ ─
                    if (World[y, x] == '┼' || World[y, x] == '┤' || World[y, x] == '┬' || World[y, x] == '┴')
                    {
                        if (World[y, x - 1] == '┼' || World[y, x - 1] == '├' || World[y, x - 1] == '┬' || World[y, x - 1] == '┴')
                        {
                            if ((y >= Height - 1 || x >= Width - 1 || LogicWorld[y + 1, x - 1] == Wall || LogicWorld[y + 1, x - 1] == Dark) &&
                                (y <= 0 || x <= 0 || LogicWorld[y - 1, x - 1] == Wall || LogicWorld[y - 1, x - 1] == Dark) &&
                                (y >= Height - 1 || LogicWorld[y + 1, x] == Wall || LogicWorld[y + 1, x] == Dark) &&
                                (y <= 0 || LogicWorld[y - 1, x] == Wall || LogicWorld[y - 1, x] == Dark))
                            {
                                switch (World[y, x])
                                {
                                case '┼':
                                    World[y, x] = '├';
                                    break;

                                case '┤':
                                    World[y, x] = '│';
                                    break;

                                case '┬':
                                    World[y, x] = '┌';
                                    break;

                                case '┴':
                                    World[y, x] = '└';
                                    break;
                                }
                                switch (World[y, x - 1])
                                {
                                case '┼':
                                    World[y, x - 1] = '┤';
                                    break;

                                case '├':
                                    World[y, x - 1] = '│';
                                    break;

                                case '┬':
                                    World[y, x - 1] = '┐';
                                    break;

                                case '┴':
                                    World[y, x - 1] = '┘';
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            Height    -= 2;
            Width     -= 2;
            LogicWorld = LogicWorld.Portion(1, 1, Height, Width);
            World      = World.Portion(1, 1, Height, Width);


            for (int y = 0; y < Height; y++)
            {
                for (int x = 0, px = 0; x < Width; x++, px += 2)
                {
                    PairedWorld[y, px] = World[y, x];
                    switch (PairedWorld[y, px])
                    {
                    //                        case '┼ ├ ┤ ┴ ┬ ┌ ┐ └ ┘ │ ─'
                    case '┼':
                    case '├':
                    case '┴':
                    case '┬':
                    case '┌':
                    case '└':
                    case '─':
                        PairedWorld[y, px + 1] = '─';
                        break;

                    default:
                        PairedWorld[y, px + 1] = ' ';
                        break;

                        /*
                         * case '.':
                         * case '┤':
                         * case '┐':
                         * case '┘':
                         * case '│':
                         */
                    }
                }
            }

            return(true);
        }
Beispiel #4
0
 public Entry(State state)
 {
     H.S          = state;
     Seeker       = new Dijkstra(H.S.DungeonStart.LogicWorld);
     VisualRandom = new XSRandom();
 }