Exemple #1
0
        private int CostToNeighbor(BoardCell fromCell, BoardCell toCell, ref BoardCellDynamicArray cells)
        {
            int num;

            if (fromCell.X != toCell.X && fromCell.Z != toCell.Z)
            {
                num = 1414;
            }
            else
            {
                num = 1000;
            }
            int num2 = num * 10 / this.maxSpeed;
            int num3 = this.TroopWidth - ((!this.NoWall) ? toCell.Clearance : toCell.ClearanceNoWall);

            if (num3 > 0)
            {
                int num4 = this.RasterCrossSection(fromCell.X, fromCell.Z, toCell.X, toCell.Z, this.TroopWidth, ref cells);
                for (int i = 0; i < num4; i++)
                {
                    BoardCell boardCell = cells.Array[i];
                    uint      flags     = boardCell.Flags;
                    if ((flags & 3u) != 0u)
                    {
                        if (!this.NoWall || (flags & 1u) != 0u)
                        {
                            if ((flags & 64u) != 0u || this.isHealer)
                            {
                                num2 = 2147483647;
                                break;
                            }
                            HealthComponent buildingHealth = boardCell.BuildingHealth;
                            if (buildingHealth != null && this.damagePerSecond != 0)
                            {
                                ArmorType armorType = buildingHealth.ArmorType;
                                int       num5      = 100;
                                if (this.projectileType != null)
                                {
                                    int num6 = this.projectileType.DamageMultipliers[(int)armorType];
                                    if (num6 >= 0)
                                    {
                                        num5 = num6;
                                    }
                                    else
                                    {
                                        Service.Logger.ErrorFormat("ArmorType {0} not found in ProjectileType {1}", new object[]
                                        {
                                            armorType,
                                            this.projectileType.Uid
                                        });
                                    }
                                }
                                int num7 = this.damagePerSecond * num5 / 100;
                                if (num7 <= 0)
                                {
                                    num2 = 2147483647;
                                    break;
                                }
                                num2 += buildingHealth.Health * 1000 / num7;
                            }
                        }
                    }
                }
                cells.Clear();
            }
            return(num2);
        }
Exemple #2
0
        public LinkedList <Entity> GetBlockingEntities(uint targetId, out LinkedList <Entity> wallListForCrushing)
        {
            HashSet <uint>        entityIds             = new HashSet <uint>();
            LinkedList <Entity>   linkedList            = new LinkedList <Entity>();
            LinkedList <Entity>   linkedList2           = new LinkedList <Entity>();
            BoardCellDynamicArray boardCellDynamicArray = new BoardCellDynamicArray(64);

            for (int i = 0; i < this.pathCells.Length; i++)
            {
                BoardCell boardCell = this.pathCells.Array[i];
                int       num       = (!this.NoWall || this.crushesWalls) ? boardCell.Clearance : boardCell.ClearanceNoWall;
                if (num < this.TroopWidth)
                {
                    int x;
                    int y;
                    if (i == 0)
                    {
                        if (this.pathCells.Length <= 1)
                        {
                            break;
                        }
                        x = boardCell.X * 2 - this.pathCells.Array[1].X;
                        y = boardCell.Z * 2 - this.pathCells.Array[1].Z;
                    }
                    else
                    {
                        x = this.pathCells.Array[i - 1].X;
                        y = this.pathCells.Array[i - 1].Z;
                    }
                    this.RasterCrossSection(x, y, boardCell.X, boardCell.Z, this.TroopWidth, ref boardCellDynamicArray);
                }
            }
            for (int j = 0; j < boardCellDynamicArray.Length; j++)
            {
                this.AddEntitiesOnCellToBlockingList(boardCellDynamicArray.Array[j], targetId, entityIds, linkedList, linkedList2, true);
            }
            if (!this.melee)
            {
                boardCellDynamicArray.Clear();
                int         num2 = 0;
                int         num3 = 0;
                int         halfWidthForOffset = BoardUtils.GetHalfWidthForOffset(this.TroopWidth);
                BoardCell   boardCell2         = this.pathCells.Array[this.pathCells.Length - 1];
                int         num4        = boardCell2.X + halfWidthForOffset;
                int         num5        = boardCell2.Z + halfWidthForOffset;
                SmartEntity smartEntity = null;
                bool        flag        = true;
                if (this.isTargetShield)
                {
                    foreach (BoardItem current in this.targetCell.Children)
                    {
                        if (GameUtils.IsEntityShieldGenerator((SmartEntity)current.Data))
                        {
                            smartEntity = (SmartEntity)current.Data;
                            break;
                        }
                    }
                    if (smartEntity == null)
                    {
                        Service.Logger.Error("Pathing believes target is shield generator, however targetCell does not have shield generator entity.");
                    }
                    else
                    {
                        flag = Service.ShieldController.IsPositionUnderShield(num4, num5, smartEntity);
                    }
                }
                this.RasterLine(num4, num5, this.targetCell.X, this.targetCell.Z, ref boardCellDynamicArray, out num2, out num3);
                for (int k = 0; k < boardCellDynamicArray.Length - 1; k++)
                {
                    if (this.isTargetShield && !flag && Service.ShieldController.IsPositionUnderShield(boardCellDynamicArray.Array[k].X, boardCellDynamicArray.Array[k].Z, smartEntity))
                    {
                        break;
                    }
                    this.AddEntitiesOnCellToBlockingList(boardCellDynamicArray.Array[k], targetId, entityIds, linkedList, linkedList2, false);
                }
            }
            wallListForCrushing = linkedList2;
            return(linkedList);
        }
Exemple #3
0
        private void CalculatePath(out bool found, ref BoardCellDynamicArray scratchCells)
        {
            int num = 46 - this.TroopWidth;

            while (!this.curPathingCell.InRange)
            {
                if (this.maxPathLength < 0 || this.curPathingCell.PathLength < this.maxPathLength)
                {
                    BoardCell cell = this.curPathingCell.Cell;
                    int       x    = cell.X;
                    int       z    = cell.Z;
                    for (int i = 0; i < 8; i++)
                    {
                        int num2 = x + Path.dirX[i];
                        if (num2 >= 0 && num2 <= num)
                        {
                            int num3 = z + Path.dirY[i];
                            if (num3 >= 0 && num3 <= num)
                            {
                                BoardCell boardCell = this.board.Cells[num2, num3];
                                if ((boardCell.Flags & 64u) == 0u)
                                {
                                    if (!this.destructible)
                                    {
                                        int num4 = (!this.NoWall) ? boardCell.Clearance : boardCell.ClearanceNoWall;
                                        if (this.TroopWidth > num4)
                                        {
                                            goto IL_29A;
                                        }
                                    }
                                    int num5 = this.CostToNeighbor(cell, boardCell, ref scratchCells);
                                    if (num5 != 2147483647)
                                    {
                                        int num6       = this.curPathingCell.PastCost + num5;
                                        int pathLength = this.curPathingCell.PathLength + 1;
                                        PathfindingCellInfo pathfindingCellInfo = boardCell.PathInfo;
                                        if (pathfindingCellInfo != null && pathfindingCellInfo.PoolIndex < this.pathingManager.FreeCellIndex)
                                        {
                                            if (!pathfindingCellInfo.InClosedSet)
                                            {
                                                if (!this.openCells.Contains(pathfindingCellInfo))
                                                {
                                                    Service.Logger.ErrorFormat("Allocated cell not in close/open sets,PoolIndex:{0}, FreeIndex:{1}", new object[]
                                                    {
                                                        pathfindingCellInfo.PoolIndex,
                                                        this.pathingManager.FreeCellIndex
                                                    });
                                                }
                                                else if (num6 < pathfindingCellInfo.PastCost)
                                                {
                                                    pathfindingCellInfo.PastCost   = num6;
                                                    pathfindingCellInfo.PathLength = pathLength;
                                                    this.openCells.UpdatePriority(pathfindingCellInfo, pathfindingCellInfo.PastCost + pathfindingCellInfo.RemainingCost);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            pathfindingCellInfo          = this.pathingManager.GetPathingCell();
                                            pathfindingCellInfo.PrevCell = this.curPathingCell;
                                            if (boardCell.PathInfo != null)
                                            {
                                                PathfindingCellInfo pathInfo = boardCell.PathInfo;
                                                pathInfo.Cell = null;
                                            }
                                            pathfindingCellInfo.Cell          = boardCell;
                                            boardCell.PathInfo                = pathfindingCellInfo;
                                            pathfindingCellInfo.InRange       = this.InRangeOfTarget(boardCell);
                                            pathfindingCellInfo.RemainingCost = this.HeuristicDiagonal(boardCell, this.destCell);
                                            pathfindingCellInfo.PastCost      = num6;
                                            pathfindingCellInfo.PathLength    = pathLength;
                                            this.openCells.Enqueue(pathfindingCellInfo, pathfindingCellInfo.PastCost + pathfindingCellInfo.RemainingCost);
                                        }
                                    }
                                }
                            }
                        }
                        IL_29A :;
                    }
                }
                if (this.openCells.Count == 0)
                {
                    this.pathingManager.RecycleAllPathingCells();
                    this.openCells = null;
                    found          = false;
                    scratchCells.Clear();
                    return;
                }
                this.curPathingCell             = this.openCells.Dequeue();
                this.curPathingCell.InClosedSet = true;
            }
            if (!this.curPathingCell.InRange)
            {
                this.pathingManager.RecycleAllPathingCells();
                this.openCells = null;
                found          = false;
                scratchCells.Clear();
                return;
            }
            do
            {
                scratchCells.Add(this.curPathingCell.Cell);
                this.curPathingCell = this.curPathingCell.PrevCell;
            }while (this.curPathingCell != null);
            int length = scratchCells.Length;

            if (length == 0)
            {
                Service.Logger.ErrorFormat("Empth Path from {0} to {1} within range {2}", new object[]
                {
                    this.startCell,
                    this.destCell,
                    this.maxShooterRange
                });
            }
            if (scratchCells.Array[length - 1] != this.startCell)
            {
                Service.Logger.ErrorFormat("First cell doesn't match: {0} and {1}", new object[]
                {
                    this.startCell,
                    scratchCells.Array[length - 1]
                });
            }
            BoardCellDynamicArray boardCellDynamicArray = this.FindTheTurns(ref scratchCells);

            this.SmoothThePath(ref boardCellDynamicArray, ref this.pathCells, ref this.turns, this.turnDistances);
            this.pathingManager.RecycleAllPathingCells();
            this.openCells = null;
            found          = true;
            scratchCells.Clear();
        }