Example #1
0
        public List <Position> GetPath(Entity self, Position start, Position goal, int length)
        {
            Path = new List <Position>();
            if (CombinedMap[goal.Y, goal.X] > Dungeon.Floor)
            {
                return(Path);
            }
            SetGoal(goal.Y, goal.X);
            Scan(self);
            Position currentPos = start;

            //            Path.Add(currentPos);
            while (CombinedMap[currentPos.Y, currentPos.X] > 0)
            {
                if (_frustration > 500)
                {
                    Path         = new List <Position>();
                    _frustration = 0;
                    ClearGoals();
                    return(Path);
                }
                int   best = 9999, choice = 0, whichOrder = Rand.Next(24);
                int[] dirsY = DirShuffledY[whichOrder], dirsX = DirShuffledX[whichOrder];
                for (int d = 0; d < 4; d++)
                {
                    if (CombinedMap[currentPos.Y + dirsY[d], currentPos.X + dirsX[d]] < best)
                    {
                        best   = CombinedMap[currentPos.Y + dirsY[d], currentPos.X + dirsX[d]];
                        choice = d;
                    }
                }
                if (best >= 9999)
                {
                    _frustration = 0;
                    Path         = new List <Position>();
                    return(Path);
                }
                currentPos.Y += dirsY[choice];
                currentPos.X += dirsX[choice];
                Path.Add(currentPos);
                _frustration++;
                if (Path.Count >= length)
                {
                    if (self.Allies.ContainsKey(currentPos))
                    {
                        _closed.UpdateWithPositions(self.Allies, Width);
                        Scan(self);
                        return(GetPath(self, start, goal, length));
                    }
                    ClearGoals();
                    return(Path);
                }
            }
            _frustration = 0;
            ClearGoals();
            return(Path);
        }
Example #2
0
 public static int Next(int upperBound)
 {
     return(xsr.Next(upperBound));
 }
Example #3
0
        public void Render(long currentTime, long previousTime)
        {
            long delta = currentTime - previousTime;

            if (Input == Terminal.TK_LBRACKET || Input == Terminal.TK_ESCAPE)
            {
                H.Backward();
                return;
            }
            _now = _timer.ElapsedMilliseconds;

            _currentPlayerColor    = ((int)currentTime / 80) % 12;
            _currentHighlightColor = ((int)currentTime / 80) % 8;
            Position p = new Position(0, 0);
            Entity   acting = H.S.Entities[H.S.CurrentActor];
            int      top = H.S.Camera.Y - 12, bottom = H.S.Camera.Y + 12, left = H.S.Camera.X - 12, right = H.S.Camera.X + 12;

            if (top < 0)
            {
                bottom -= top;
                top     = 0;
            }
            if (bottom > H.S.DungeonStart.World.GetUpperBound(0))
            {
                top   -= bottom - H.S.DungeonStart.World.GetUpperBound(0);
                bottom = H.S.DungeonStart.World.GetUpperBound(0);
            }
            if (left < 0)
            {
                right -= left;
                left   = 0;
            }
            if (right > H.S.DungeonStart.World.GetUpperBound(1))
            {
                left -= right - H.S.DungeonStart.World.GetUpperBound(1);
                right = H.S.DungeonStart.World.GetUpperBound(1);
            }
            OffsetY = top;
            OffsetX = left;
            Terminal.Layer(0);
            if (H.S.CurrentReason == WaitReason.Receiving)
            {
                for (int y = OffsetY, sy = 0; sy < 25; y++, sy++)
                {
                    for (int x = OffsetX, sx = 0; sx < 25; x++, sx++)
                    {
                        if (Seeker.CombinedMap[y, x] <= acting.Stats.MoveSpeed)
                        {
                            Terminal.BkColor(_highlightColors[(_currentHighlightColor + 100 - Seeker.CombinedMap[y, x]) % _highlightColors.Length]);
                            Terminal.Put(sx * 2 + 1, sy + 1, ' ');
                            Terminal.Put(sx * 2 + 2, sy + 1, ' ');
                        }
                        else
                        {
                            Terminal.BkColor(_lightGray);
                            Terminal.Put(sx * 2 + 1, sy + 1, ' ');
                            Terminal.Put(sx * 2 + 2, sy + 1, ' ');
                        }
                    }
                }
            }
            else
            {
                for (int y = OffsetY, sy = 0; sy < 25; y++, sy++)
                {
                    for (int x = OffsetX, sx = 0; sx < 25; x++, sx++)
                    {
                        Terminal.BkColor(_lightGray);
                        Terminal.Put(sx * 2 + 1, sy + 1, ' ');
                        Terminal.Put(sx * 2 + 2, sy + 1, ' ');
                    }
                }
            }
            Terminal.Layer(1);

            for (int y = OffsetY, sy = 0; sy < 25; y++, sy++)
            {
                for (int x = OffsetX, sx = 0; sx < 25; x++, sx++)
                {
                    p.Y = y;
                    p.X = x;
                    Entity e = H.S.Entities[p];
                    if (e != null)
                    {
                        Terminal.Color(e.Coloring);
                        if (H.S.CurrentReason == WaitReason.AttackAnimating && BeingDamaged.ContainsKey(e.Name))
                        {
                            Terminal.Layer(3);
                            Terminal.PutExt(sx * 2 + 1, sy + 1, VisualRandom.Next(7) - 3, VisualRandom.Next(7) - 3, e.Left);
                            Terminal.PutExt(sx * 2 + 2, sy + 1, VisualRandom.Next(7) - 3, VisualRandom.Next(7) - 3, e.Right);
                            Terminal.Layer(1);
                            Terminal.Put(sx * 2 + 1, sy + 1, ' ');
                            Terminal.Put(sx * 2 + 2, sy + 1, ' ');
                        }
                        else
                        {
                            Terminal.Put(sx * 2 + 1, sy + 1, e.Left);
                            Terminal.Put(sx * 2 + 2, sy + 1, e.Right);
                        }
                        Terminal.Color(_darkGray);
                    }
                    else if (H.S.Cursor.Y == y && H.S.Cursor.X == x)
                    {
                        Terminal.Color(_playerColors[(_currentPlayerColor + 3) % _playerColors.Length]);
                        Terminal.Put(sx * 2 + 1, sy + 1, '{');
                        Terminal.Put(sx * 2 + 2, sy + 1, '}');
                        Terminal.Color(_darkGray);
                    }
                    else if (acting.Faction == 0 && acting.Seeker.Path.Contains(p))
                    {
                        Terminal.Color(_playerColors[_currentPlayerColor]);
                        Terminal.Put(sx * 2 + 1, sy + 1, H.S.DungeonStart.PairedWorld[y, x * 2]);
                        Terminal.Put(sx * 2 + 2, sy + 1, H.S.DungeonStart.PairedWorld[y, x * 2 + 1]);
                        Terminal.Color(_darkGray);
                    }

/*                    else if(seeker.CombinedMap[y, x] < 100)
 *                  {
 *                      Terminal.Print(sx * 2 + 1, sy + 1, "" + seeker.CombinedMap[y, x]);
 *                  }*/
                    else
                    {
                        Terminal.Put(sx * 2 + 1, sy + 1, H.S.DungeonStart.PairedWorld[y, x * 2]);
                        Terminal.Put(sx * 2 + 2, sy + 1, H.S.DungeonStart.PairedWorld[y, x * 2 + 1]);
                    }
                }
            }

            Terminal.Print(60, 9, "Acting: " + H.S.CurrentActor);
            Gauge hp = H.S.Entities[H.S.CurrentActor].Stats.Health;

            Terminal.Print(60, 10, "Health: " + hp.Current + "/" + hp.Max);
            Terminal.Print(60, 12, message);

/*            Terminal.Print(60, 10, "Y: " + Cursor.Y + ", X: " + Cursor.X);
 *          Terminal.Print(60, 11, "Seeker Value: " + seeker.CombinedMap[Cursor.Y, Cursor.X]);
 *          Terminal.Print(60, 12, "Physical Value: " + seeker.PhysicalMap[Cursor.Y, Cursor.X]);*/

            Terminal.Refresh();
            Terminal.Clear();
            if (H.S.CurrentReason == WaitReason.WalkAnimating)
            {
                if (delta < 85)
                {
                    _now = previousTime; // This run didn't count toward advancing animations.
                    return;
                }
                H.S.StepsLeft = H.S.Entities.Step(H.S.CurrentActor);
                ++H.S.StepsTaken;
                if (H.S.StepsLeft <= 0 || H.S.StepsTaken > acting.Stats.MoveSpeed)
                {
                    FinishMove();
                    if (H.S.CurrentReason == WaitReason.AttackAnimating)
                    {
                        return;
                    }
                    else
                    {
                        NextTurn();
                    }
                }
            }
            else if (H.S.CurrentReason == WaitReason.AttackAnimating)
            {
                if (delta < 120)
                {
                    _now = previousTime; // This run didn't count toward advancing animations.
                    return;
                }
                NextTurn();
            }
            else if (H.S.CurrentReason == WaitReason.CameraMoving)
            {
                if (delta < 55)
                {
                    _now = previousTime; // This run didn't count toward advancing animations.
                    return;
                }
                if (H.S.Camera.X < acting.Pos.X)
                {
                    H.S.Camera.Move(0, 1);
                    if (H.S.Camera.X + 12 > H.S.DungeonStart.World.GetUpperBound(1))
                    {
                        H.S.Camera.X = acting.Pos.X;
                    }
                }
                else if (H.S.Camera.X > acting.Pos.X)
                {
                    H.S.Camera.Move(0, -1);
                    if (H.S.Camera.X < 12)
                    {
                        H.S.Camera.X = acting.Pos.X;
                    }
                }
                if (H.S.Camera.Y < acting.Pos.Y)
                {
                    H.S.Camera.Move(1, 0);
                    if (H.S.Camera.Y + 12 > H.S.DungeonStart.World.GetUpperBound(0))
                    {
                        H.S.Camera.Y = acting.Pos.Y;
                    }
                }
                else if (H.S.Camera.Y > acting.Pos.Y)
                {
                    H.S.Camera.Move(-1, 0);
                    if (H.S.Camera.Y < 12)
                    {
                        H.S.Camera.Y = acting.Pos.Y;
                    }
                }
                if (H.S.Camera.X == acting.Pos.X && H.S.Camera.Y == acting.Pos.Y)
                {
                    if (acting.Faction == 0)
                    {
                        H.S.CurrentReason = WaitReason.Receiving;
                        H.Remember();
                    }
                    else
                    {
                        H.S.CurrentReason = WaitReason.WalkAnimating;
                        acting.Seeker.GetPath(acting, acting.Pos, H.S.Entities.NameToEntity.Where(kv => kv.Value.Faction == 0).Select(kv => kv.Value.Pos), acting.Stats.MoveSpeed);
                    }
                }
            }
        }