Example #1
0
        public void AddTombstoneIfNeeded()
        {
            if (!this.m_ejected && this.m_level.GetTombStoneCount() < 40)
            {
                int tileX = this.GetTileX();
                int tileY = this.GetTileY();

                LogicTileMap tileMap = this.m_level.GetTileMap();
                LogicTile    tile    = tileMap.GetTile(tileX, tileY);

                if (!this.TileOkForTombstone(tile))
                {
                    int minDistance  = 0;
                    int closestTileX = -1;
                    int closestTileY = -1;

                    for (int i = -1; i < 2; i++)
                    {
                        int offsetX = ((i + tileX) << 9) | 256;
                        int offsetY = 256 - (tileY << 9);

                        for (int j = -1; j < 2; j++, offsetY -= 512)
                        {
                            tile = tileMap.GetTile(tileX + i, tileY + j);

                            if (this.TileOkForTombstone(tile))
                            {
                                int distanceX = this.GetX() - offsetX;
                                int distanceY = this.GetY() + offsetY;
                                int distance  = distanceX * distanceX + distanceY * distanceY;

                                if (minDistance == 0 || distance < minDistance)
                                {
                                    minDistance  = distance;
                                    closestTileX = tileX + i;
                                    closestTileY = tileY + j;
                                }
                            }
                        }
                    }

                    if (minDistance == 0)
                    {
                        return;
                    }

                    tileX = closestTileX;
                    tileY = closestTileY;
                }

                LogicObstacleData tombstoneData = this.GetCharacterData().GetTombstone();

                if (tombstoneData != null)
                {
                    LogicObstacle tombstone = (LogicObstacle)LogicGameObjectFactory.CreateGameObject(tombstoneData, this.m_level, this.m_villageType);
                    tombstone.SetInitialPosition(tileX << 9, tileY << 9);
                    this.GetGameObjectManager().AddGameObject(tombstone, -1);
                }
            }
        }
Example #2
0
        public void CheckWall(LogicVector2 position)
        {
            if (this.m_parent != null)
            {
                LogicGameObject gameObject = this.m_parent.GetParent();
                LogicTile       tile       = gameObject.GetLevel().GetTileMap().GetTile(position.m_x >> 9, position.m_y >> 9);

                if (tile != null)
                {
                    for (int i = 0; i < tile.GetGameObjectCount(); i++)
                    {
                        LogicGameObject go = tile.GetGameObject(i);

                        if (go.IsWall() &&
                            go.IsAlive())
                        {
                            this.m_wall = go;

                            if (((LogicBuilding)go).GetHitWallDelay() <= 0)
                            {
                                ++this.m_wallCount;
                            }
                        }
                    }
                }
            }
        }
Example #3
0
 /*
  *  Expands LogicTile (which updates adjacent LogicTiles), removes it from the LogicTile lists, and destroys it
  */
 public void ExpandLT(LogicTile lt)
 {
     lt.Expand();
     unrevealedLTs.Remove(lt);
     unexpandedRevealedLTs.Remove(lt);
     Destroy(lt.gameObject);
 }
Example #4
0
    /*
     *  Instantiates two new LogicTiles in the same location based on the intersecting unrevealed LogicTiles with an adjacent LogicTile
     *      Unexpanded adjacent LogicTiles lists for both contain disjoint unrevealed LogicTiles and the same revealed LogicTiles
     *      Doesn't affect the original LogicTile
     *  Splits the number of active adjacent mines across the disjoint unrevealed adjacent LogicTiles
     *  Sets LogicTile color to yellow
     */
    private List <LogicTile> SplitLT(LogicTile ltToSplit, List <LogicTile> adjacentIntersect, List <LogicTile> adjacentDisjoint, int numSplitOffMines)
    {
        GameObject goNewDisjoint  = Instantiate(logicTilePrefab, ltToSplit.transform.position, Quaternion.identity, transform.GetChild(0));
        GameObject goNewIntersect = Instantiate(logicTilePrefab, ltToSplit.transform.position, Quaternion.identity, transform.GetChild(0));

        LogicTile ltNewDisjoint  = goNewDisjoint.GetComponent <LogicTile>();
        LogicTile ltNewIntersect = goNewIntersect.GetComponent <LogicTile>();

        ltNewDisjoint.LogicTileSetup(ltToSplit);
        ltNewIntersect.LogicTileSetup(ltToSplit);

        ltNewDisjoint.UnexpandedAdjacentLTs  = ltToSplit.UnexpandedAdjacentLTs.Except(adjacentIntersect).ToList();
        ltNewIntersect.UnexpandedAdjacentLTs = ltToSplit.UnexpandedAdjacentLTs.Except(adjacentDisjoint).ToList();

        ltNewDisjoint.ActiveAdjacentMinesModifier  += numSplitOffMines;
        ltNewIntersect.ActiveAdjacentMinesModifier += ltToSplit.NumActiveAdjacentMines - numSplitOffMines;

        ltNewDisjoint.UpdateNumActiveAdjacentMines();
        ltNewIntersect.UpdateNumActiveAdjacentMines();

        ltNewDisjoint.SetLogicTileColor(Color.yellow);
        ltNewIntersect.SetLogicTileColor(Color.yellow);

        return(new List <LogicTile>()
        {
            ltNewDisjoint, ltNewIntersect
        });
    }
Example #5
0
        public override void GetPathPointSubTile(LogicVector2 position, int idx)
        {
            if ((uint)idx >= this.m_pathLength)
            {
                Debugger.Error("illegal path index");
            }

            LogicTile tile = this.m_tileMap.GetTile(position.m_x, position.m_y);

            position.m_x *= 2;
            position.m_y *= 2;

            if (tile.IsPassablePathFinder(3))
            {
                if (tile.IsPassablePathFinder(2))
                {
                    if (tile.IsPassablePathFinder(1))
                    {
                        ++position.m_x;
                    }
                }

                ++position.m_y;
            }
        }
Example #6
0
 public void setTile(LogicTile newTile)
 {
     renderCleanup();
     myTile = newTile;
     instantiateRendering();
     updateRender();
 }
Example #7
0
 LogicTile GrowAttackPathTo(LogicTile neighbor)
 {
     if (!HasPath || neighbor == null || neighbor.HasPath || leftAttack < ATTACK_COST)
     {
         return(null);
     }
     neighbor.distance   = distance + 1;
     neighbor.leftAttack = leftAttack - ATTACK_COST;
     return(neighbor);
 }
Example #8
0
 /*
  *  Simulates a left click on unrevealed adjacent LogicTiles
  */
 public void RevealUnrevealedAdjacentLTs(LogicTile lt)
 {
     foreach (LogicTile adjacent in lt.UnexpandedAdjacentLTs)
     {
         if (!adjacent.IsRevealed)
         {
             adjacent.LeftClick();
         }
     }
 }
Example #9
0
        public void AStarAddTile(int tileIndex)
        {
            int tileX = tileIndex % this.m_mapWidth;
            int tileY = tileIndex / this.m_mapWidth;

            LogicTile tile = this.m_tileMap.GetTile(tileX, tileY);

            if (tile != null)
            {
                int pathFinderCost1 = tile.GetPathFinderCost(0, 0);
                int pathFinderCost2 = tile.GetPathFinderCost(1, 0);
                int pathFinderCost3 = tile.GetPathFinderCost(0, 1);
                int pathFinderCost4 = tile.GetPathFinderCost(1, 1);

                if (pathFinderCost1 != 0x7FFFFFFF || pathFinderCost2 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX, tileY - 1, tileIndex - this.m_mapWidth, 100);
                }

                if (pathFinderCost3 != 0x7FFFFFFF || pathFinderCost4 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX, tileY + 1, tileIndex + this.m_mapWidth, 100);
                }

                if (pathFinderCost1 != 0x7FFFFFFF || pathFinderCost3 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX - 1, tileY, tileIndex - 1, 100);
                }

                if (pathFinderCost2 != 0x7FFFFFFF || pathFinderCost4 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX + 1, tileY, tileIndex + 1, 100);
                }

                if (pathFinderCost1 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX - 1, tileY - 1, tileIndex - this.m_mapWidth - 1, 141);
                }

                if (pathFinderCost3 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX - 1, tileY + 1, tileIndex + this.m_mapWidth - 1, 141);
                }

                if (pathFinderCost2 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX + 1, tileY - 1, tileIndex - this.m_mapWidth + 1, 141);
                }

                if (pathFinderCost4 != 0x7FFFFFFF)
                {
                    this.AStarAddTile(tileIndex, tileX + 1, tileY + 1, tileIndex + this.m_mapWidth + 1, 141);
                }
            }
        }
Example #10
0
    public void LogicTileSetup(LogicTile lt)
    {
        baseTile    = lt.baseTile;
        Coordinates = lt.Coordinates;

        IsExpanded            = lt.IsExpanded;
        UnexpandedAdjacentLTs = lt.UnexpandedAdjacentLTs;

        activeAdjacentMinesModifier = lt.activeAdjacentMinesModifier;
        numFlaggedAdjacentLTs       = lt.numFlaggedAdjacentLTs;
        UpdateNumActiveAdjacentMines();
    }
Example #11
0
    private void Update()
    {
        if (true)
        {
            LogicTile temp = GameBoard.Instance.GetTileByPos(Vector3Int.CeilToInt(transform.position));
            GameBoard.Instance.FindMovePath(temp, charAttr.Move);

            foreach (LogicTile Lt in GameBoard.Instance.MoveTiles)
            {
            }
        }
    }
Example #12
0
        /// <summary>
        ///     Gets if the specified point is in collision with a gameobject.
        /// </summary>
        public bool IsCollision(int x, int y)
        {
            if (this._tileMap != null)
            {
                LogicTile tile = this._tileMap.GetTile(x >> 1, y >> 1);

                if (tile != null)
                {
                    return(true); // ?
                }
            }

            return(false);
        }
Example #13
0
    public List <LogicTile> FindUnrevealedIntersect(LogicTile adjacent)
    {
        List <LogicTile> intersect = new List <LogicTile>();

        foreach (LogicTile lt in FindUnrevealedAdjacentLTs())
        {
            if (adjacent.UnexpandedAdjacentLTs.Contains(lt))
            {
                intersect.Add(lt);
            }
        }

        return(intersect);
    }
        public bool IsCollision(int x, int y)
        {
            if (this.m_tileMap == null)
            {
                return(false);
            }

            LogicTile tile = this.m_tileMap.GetTile(x >> 1, y >> 1);

            if (tile != null)
            {
                return(!tile.IsPassablePathFinder((x & 1) + 2 * (y & 1)));
            }

            return(true);
        }
Example #15
0
    /*
     *  Set up a new LogicTile field:
     *      If an old LTfield exists, destroys it first
     *      Generates a new LTfield of the same dimensions as Minefield, one LogicTile for each Tile
     */
    public void InitializeAI()
    {
        newGame = true;
        RunAI   = false;

        FindAndSetNumMinesRemaining();

        // Deletes all old LogicTiles
        if (LTfield != null)
        {
            foreach (LogicTile lt in unrevealedLTs)
            {
                Destroy(lt.gameObject);
            }
            foreach (LogicTile lt in unexpandedRevealedLTs)
            {
                Destroy(lt.gameObject);
            }
        }

        unrevealedLTs         = new List <LogicTile>();
        unexpandedRevealedLTs = new List <LogicTile>();

        // Create new LogicTiles to represent every Tile in the Minefield and add them to LTfield and unrevealedLTs list
        LTfield = new LogicTile[gc.Minefield.GetLength(0), gc.Minefield.GetLength(1)];

        for (int x = 0; x < LTfield.GetLength(0); x++)
        {
            for (int y = 0; y < LTfield.GetLength(1); y++)
            {
                Tile       curr  = gc.Minefield[x, y];
                GameObject go    = Instantiate(logicTilePrefab, curr.transform.position, Quaternion.identity, transform.GetChild(0));
                LogicTile  newLT = go.GetComponent <LogicTile>();
                newLT.LogicTileSetup(curr, x, y);

                LTfield[x, y] = newLT;
                unrevealedLTs.Add(newLT);
            }
        }

        // Initializes adjacent LogicTiles list for all LogicTiles
        foreach (LogicTile lt in LTfield)
        {
            lt.UnexpandedAdjacentLTs = FindUnexpandedAdjacentLTs(lt);
        }
    }
Example #16
0
 /// <summary>
 /// 是否是边缘格子
 /// </summary>
 /// <param name="tile">判断的格子</param>
 /// <param name="tiles">移动范围</param>
 /// <returns></returns>
 static bool IsBoundTile(LogicTile tile, List <LogicTile> tiles)
 {
     if (tile.north != null && !tiles.Contains(tile.north))
     {
         return(true);
     }
     if (tile.east != null && !tiles.Contains(tile.east))
     {
         return(true);
     }
     if (tile.south != null && !tiles.Contains(tile.south))
     {
         return(true);
     }
     if (tile.west != null && !tiles.Contains(tile.west))
     {
         return(true);
     }
     return(false);
 }
Example #17
0
        public bool TileOkForSpawn(LogicTile tile)
        {
            if (tile != null && !tile.IsFullyNotPassable())
            {
                for (int i = 0; i < tile.GetGameObjectCount(); i++)
                {
                    LogicGameObjectType gameObjectType = tile.GetGameObject(i).GetGameObjectType();

                    if (gameObjectType == LogicGameObjectType.BUILDING || gameObjectType == LogicGameObjectType.OBSTACLE ||
                        gameObjectType == LogicGameObjectType.TRAP || gameObjectType == LogicGameObjectType.DECO)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
Example #18
0
        public override void ActivateContent(LogicTile t)
        {
            foreach (var gate in t.Gates)
            {
                switch (BitAction)
                {
                case ActionState.Clear:
                    gate[BitIndex] = false;
                    break;

                case ActionState.Set:
                    gate[BitIndex] = true;
                    break;

                case ActionState.Toggle:
                    gate[BitIndex] ^= true;
                    break;

                case ActionState.Hold:
                    throw new InvalidOperationException();
                }
            }

            foreach (var counter in t.Counters)
            {
                switch (BitAction)
                {
                case ActionState.Set:
                    counter.Increase();
                    break;

                case ActionState.Clear:
                case ActionState.Toggle:
                    counter.Decrease();
                    break;

                case ActionState.Hold:
                    throw new InvalidOperationException();
                }
            }
        }
Example #19
0
    void PopulateTiles()
    {
        LogicTile[,] logicTileArray = new LogicTile[numTilesX, numTilesY];
        //int tileColor = 1;

        // Populate board and tile array

        for (int i = 0; i < numTilesX; i++)
        {
            for (int j = 0; j < numTilesY; j++)
            {
                GameObject myTile = Instantiate(tilePrefab, transform);

                myTile.transform.localPosition = new Vector3((tileWidth / 2) + i * tileWidth, -(tileWidth / 2) + j * -tileWidth);

                // Tinting even tiles

                /*
                 * if (tileColor % 2 == 0)
                 * {
                 *  myTile.transform.GetChild(0).GetComponent<SpriteRenderer>().color = new Color(0.8f, 0.8f, 0.8f, 1);
                 * }
                 *
                 * tileColor = i + j;*/

                // Show material
                myTile.GetComponent <LogicTile>().showMaterial(numMaterials);

                // Filling logic tile array
                logicTileArray[i, j] = myTile.GetComponent <LogicTile>();
            }
        }

        //Positioning the whole board

        float offsetX = 0 - ((tileWidth * numTilesX) / 2);
        float offsetY = 0 + ((tileWidth * numTilesY) / 2);

        transform.localPosition = new Vector3(offsetX, offsetY);
    }
Example #20
0
    /// <summary>
    /// 一个格移动到另一个格子
    /// </summary>
    /// <param name="neighbor">目标</param>
    /// <returns>目标</returns>
    LogicTile GrowPathTo(LogicTile neighbor)
    {
        // 是否有目标,目标是否已经走过,行动力是否小于目标行动力要求
        if (!HasPath || neighbor == null || neighbor.HasPath || leftCost < neighbor.moveCost || !neighbor.CanWalk)
        {
            return(null);
        }
        if (neighbor.PlayerOnTile != null)
        {
            if (neighbor.PlayerOnTile.charAttr.Team == TeamType.Enemy)
            {
                return(null);
            }
        }
        neighbor.distance = distance + 1;

        neighbor.leftCost = leftCost - neighbor.moveCost;

        neighbor.NextOnPath = this;

        return(neighbor);
    }
Example #21
0
        public Tile GetTargetTile(ActuatorItemData callingActuator)
        {
            var targetPos = ((RemoteTarget)callingActuator.ActionLocation).Position.Position.ToAbsolutePosition(CurrentMap);

            Tile targetTile = null;

            if (TilesPositions.TryGetValue(targetPos, out targetTile))
            {
                return(targetTile);
            }
            else
            {
                //try find tile in raw data, and than actuator, add it to Tiles Positions
                var virtualTileData = CurrentMap[targetPos.X, targetPos.Y];
                if (virtualTileData.Actuators.Any()) //virtual tile will be proccessed at the and so any checking shouldnt be necessary
                {
                    var newTile = new LogicTile(targetPos.ToGridVector3(CurrentLevel));
                    newTile.Gates    = virtualTileData.Actuators.Where(x => x.ActuatorType == 5).Select(y => InitLogicGates(y, newTile)).ToArray(); //recurse
                    newTile.Counters = virtualTileData.Actuators.Where(x => x.ActuatorType == 6).Select(y => InitCounters(y, newTile)).ToArray();   //recurse

                    TilesPositions.Add(targetPos, targetTile = newTile);                                                                            //subitems will be processed
                }
                else if (virtualTileData.TextTags.Any())
                {
                    var textTag = virtualTileData.TextTags.Single();
                    textTag.HasTargetingActuator = true;
                    targetTile = TilesPositions[textTag.GetParentPosition(targetPos)];

                    if (textTag.Processed)
                    {
                        targetTile.SubItems.Single(x => x is TextTag).AcceptMessages = true;
                    }
                }

                return(targetTile); //TODO (if null)  think out what to do
                //Acutor at the begining references wall near by with tag only ... what to do ?
            }
        }
Example #22
0
    /*
     *  Returns a list of all unexpanded adjacent LogicTiles, revealed or unrevealed
     *  Ignores expanded adjacent LogicTiles
     *      (x, y) +/- 1
     */
    private List <LogicTile> FindUnexpandedAdjacentLTs(LogicTile lt)
    {
        List <LogicTile> adjacentLTs = new List <LogicTile>();

        // Iterate over x position -/+ 1
        for (int x = lt.Coordinates.x - 1; x <= lt.Coordinates.x + 1; x++)
        {
            // Skip iteration if x is outside bounds of LTfield
            if (x < 0 || x >= LTfield.GetLength(0))
            {
                continue;
            }
            else
            {
                // Iterate over y position -/+ 1
                for (int y = lt.Coordinates.y - 1; y <= lt.Coordinates.y + 1; y++)
                {
                    // Skip iteration if y is outside bounds of LTfield, or if [x, y] = [lt.Coordinates.x, lt.Coordinates.y],
                    //      otherwise, if adjacent LogicTile is not expanded, add it to the adjacent list
                    if (y < 0 || y >= LTfield.GetLength(1) || (x == lt.Coordinates.x && y == lt.Coordinates.y))
                    {
                        continue;
                    }
                    else
                    {
                        if (!LTfield[x, y].IsExpanded)
                        {
                            adjacentLTs.Add(LTfield[x, y]);
                        }
                    }
                }
            }
        }

        return(adjacentLTs);
    }
Example #23
0
 public virtual void ActivateContent(LogicTile t)
 {
 }
Example #24
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (level.GetVillageType() == 0)
                {
                    if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                    {
                        if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9))
                        {
                            return(-2);
                        }
                    }
                    else
                    {
                        LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9);

                        if (tile == null)
                        {
                            return(-4);
                        }

                        if (tile.GetPassableFlag() == 0)
                        {
                            return(-3);
                        }
                    }

                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar != null)
                    {
                        if (this.m_data != null)
                        {
                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                            if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0)
                            {
                                LogicAlliancePortal  alliancePortal  = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType());
                                LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent();

                                alliancePortal.SetInitialPosition(this.m_x, this.m_y);

                                if (bunkerComponent != null)
                                {
                                    bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity());

                                    if (level.GetBattleLog() != null)
                                    {
                                        if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                        {
                                            level.UpdateLastUsedArmy();
                                        }
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    bunkerComponent.RemoveAllUnits();

                                    LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits();

                                    for (int i = 0; i < allianceUnits.Size(); i++)
                                    {
                                        LogicUnitSlot       slot = allianceUnits[i];
                                        LogicCombatItemData data = (LogicCombatItemData)slot.GetData();

                                        if (data != null)
                                        {
                                            int count = slot.GetCount();

                                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                                    {
                                                        bunkerComponent.AddUnitImpl(data, slot.GetLevel());
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character");
                                        }
                                    }
                                }

                                gameObjectManager.AddGameObject(alliancePortal, -1);

                                return(0);
                            }
                        }
                    }

                    return(-5);
                }
            }

            return(-1);
        }
Example #25
0
        public void CreatePathPoint(LogicVector2 startPosition)
        {
            int pathLength      = this.m_pathLength;
            int tileMapSubWidth = this.m_mapWidth * 2;
            int mapSize         = 4 * this.m_mapWidth * this.m_mapHeight;

            for (int i = 0; i < mapSize; i++)
            {
                this.m_parentBuffer[i] = -1;
                this.m_pathCost[i]     = -1;
            }

            int pathPoints = 0;

            for (int i = 0; i < pathLength; i++)
            {
                this.GetPathPoint(this.m_pathPointOutput, i);

                LogicTile tile = this.m_tileMap.GetTile(this.m_pathPointOutput.m_x, this.m_pathPointOutput.m_y);

                int pathPointIdx = 4 * this.m_mapWidth * this.m_pathPointOutput.m_y + 2 * this.m_pathPointOutput.m_x;

                if (tile.GetPathFinderCostIgnorePos(0, 0) != 0x7FFFFFFF)
                {
                    pathPoints += 1;
                    this.m_pathCost[pathPointIdx] = 0x7FFFFFFF;
                }

                if (tile.GetPathFinderCostIgnorePos(1, 0) != 0x7FFFFFFF)
                {
                    pathPoints += 1;
                    this.m_pathCost[pathPointIdx | 1] = 0x7FFFFFFF;
                }

                if (tile.GetPathFinderCostIgnorePos(0, 1) != 0x7FFFFFFF)
                {
                    pathPoints += 1;
                    this.m_pathCost[pathPointIdx + tileMapSubWidth] = 0x7FFFFFFF;
                }

                if (tile.GetPathFinderCostIgnorePos(1, 1) != 0x7FFFFFFF)
                {
                    pathPoints += 1;
                    this.m_pathCost[(pathPointIdx + tileMapSubWidth) | 1] = 0x7FFFFFFF;
                }
            }

            int heapValue = startPosition.m_x + tileMapSubWidth * startPosition.m_y;

            this.m_heapBuffer[0]       = heapValue;
            this.m_pathCost[heapValue] = 1;

            for (int i = 0, stackSize = 1; i < pathPoints; i++)
            {
                int stackIdx = stackSize - 1;
                int heap     = this.m_heapBuffer[stackSize - 1];

                int minIdx  = 0;
                int minCost = 0x7FFFFFFF;

                for (int j = 0; j < stackSize; j++)
                {
                    int heap2 = this.m_heapBuffer[j];

                    if (minCost > this.m_pathCost[heap2])
                    {
                        heap    = heap2;
                        minIdx  = j;
                        minCost = this.m_pathCost[heap2];
                    }
                }

                int cost = this.m_pathCost[heap];

                if (minIdx < stackIdx)
                {
                    Array.Copy(this.m_heapBuffer, minIdx + 1, this.m_heapBuffer, minIdx, stackIdx - minIdx);
                }

                this.m_heapBuffer[stackSize] = -1;

                if (stackSize > 4096)
                {
                    Debugger.Warning("LPFNew stack grew too large!");
                    break;
                }

                int idx1 = heap - tileMapSubWidth; // - 1y
                int idx2 = heap + tileMapSubWidth; // + 1y
                int idx3 = heap - 1;               // - 1x
                int idx4 = heap + 1;               // + 1x

                if (idx1 >= 0 && idx1 < mapSize && this.m_pathCost[idx1] > cost + 100)
                {
                    this.m_pathCost[idx1]         = cost + 100;
                    this.m_parentBuffer[idx1]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx1;
                }

                if (idx2 >= 0 && idx2 < mapSize && this.m_pathCost[idx2] > cost + 100)
                {
                    this.m_pathCost[idx2]         = cost + 100;
                    this.m_parentBuffer[idx2]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx2;
                }

                if (idx3 >= 0 && idx3 < mapSize && this.m_pathCost[idx3] > cost + 100)
                {
                    this.m_pathCost[idx3]         = cost + 100;
                    this.m_parentBuffer[idx3]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx3;
                }

                if (idx4 >= 0 && idx4 < mapSize && this.m_pathCost[idx4] > cost + 100)
                {
                    this.m_pathCost[idx4]         = cost + 100;
                    this.m_parentBuffer[idx4]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx4;
                }

                idx1 = heap - tileMapSubWidth - 1; // - 1y - 1x
                idx2 = heap - tileMapSubWidth + 1; // - 1y + 1x
                idx3 = heap + tileMapSubWidth - 1; // + 1y - 1x
                idx4 = heap + tileMapSubWidth + 1; // + 1y + 1x

                if (idx1 >= 0 && idx1 < mapSize && this.m_pathCost[idx1] > cost + 141)
                {
                    this.m_pathCost[idx1]         = cost + 141;
                    this.m_parentBuffer[idx1]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx1;
                }

                if (idx2 >= 0 && idx2 < mapSize && this.m_pathCost[idx2] > cost + 141)
                {
                    this.m_pathCost[idx2]         = cost + 141;
                    this.m_parentBuffer[idx2]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx2;
                }

                if (idx3 >= 0 && idx3 < mapSize && this.m_pathCost[idx3] > cost + 141)
                {
                    this.m_pathCost[idx3]         = cost + 141;
                    this.m_parentBuffer[idx3]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx3;
                }

                if (idx4 >= 0 && idx4 < mapSize && this.m_pathCost[idx4] > cost + 141)
                {
                    this.m_pathCost[idx4]         = cost + 141;
                    this.m_parentBuffer[idx4]     = heap;
                    this.m_heapBuffer[stackIdx++] = idx4;
                }

                if (stackIdx <= 0)
                {
                    break;
                }

                stackSize = stackIdx;
            }
        }
Example #26
0
 public TerrainType GetTerrain()
 {
     return(LogicTile.GetTerrain(tile));
 }
Example #27
0
    void Render()
    {
        LogicArray2 <int> tiles = world.map;

        LogicArray2 <RenderTile> renderTiles = new LogicArray2 <RenderTile>(tiles.width, tiles.height, null);

        { //Vertex creation
            int index = 0;
            for (int y = 0; y < tiles.height; ++y)
            {
                for (int x = 0; x < tiles.width; ++x)
                {
                    int     tile = tiles.Get(x, y);
                    Vector3 pos  = HexToWorldPos(new LogicHex(x, y));

                    Color32 color = TerrainTypeToColor(LogicTile.GetTerrain(tile));
                    renderTiles.Set(x, y, new RenderTile(tile, pos, Vector3.zero, color));

                    ++index;
                }
            }
        }

        {                                                    //Smooth normal calculations
            int index = 0;
            for (int y = 1; y < renderTiles.height - 1; ++y) //Skip edge tiles
            {
                for (int x = 1; x < renderTiles.width - 1; ++x)
                {
                    RenderTile tile = renderTiles.Get(x, y);

                    Vector3 p0 = tile.position;
                    for (int h = 0; h < 6; ++h)
                    {
                        LogicHex dir1 = LogicHex.Direction(h);
                        LogicHex dir2 = LogicHex.Direction(h + 1);

                        Vector3 p1 = renderTiles.Get(x + dir1.q, y + dir1.r).position;
                        Vector3 p2 = renderTiles.Get(x + dir2.q, y + dir2.r).position;

                        Vector3 side1 = p1 - p0;
                        Vector3 side2 = p2 - p0;
                        Vector3 perp  = Vector3.Cross(side1, side2);

                        //float perpLength = perp.magnitude;
                        //perp /= perpLength;

                        tile.normal += perp;
                    }

                    float normLength = tile.normal.magnitude;
                    tile.normal /= normLength;

                    ++index;
                }
            }
        }

        { //Mesh creation (splitting in chunks, triangulation etc.)
            int widthInChunks  = renderTiles.width / CHUNK_SIZE;
            int heightInChunks = renderTiles.height / CHUNK_SIZE;

            if (chunks == null)
            {
                chunks = new LogicArray2 <Chunk>(widthInChunks, heightInChunks, null);
            }

            for (int cy = 0; cy < heightInChunks; ++cy)
            {
                for (int cx = 0; cx < widthInChunks; ++cx)
                {
                    DynamicMesh dynamicMesh = new DynamicMesh();

                    //Chunk bounds
                    int startY = cy * CHUNK_SIZE;
                    int endY   = startY + CHUNK_SIZE;
                    int startX = cx * CHUNK_SIZE;
                    int endX   = startX + CHUNK_SIZE;

                    if (cx == widthInChunks - 1)
                    {
                        endX--;
                    }

                    if (cy == widthInChunks - 1)
                    {
                        endY--;
                    }


                    for (int y = startY; y < endY; ++y)
                    {
                        for (int x = startX; x < endX; ++x)
                        {
                            RenderTile tile0 = renderTiles.Get(x, y);
                            RenderTile tile1 = renderTiles.Get(x + 1, y);
                            RenderTile tile2 = renderTiles.Get(x, y + 1);
                            RenderTile tile3 = renderTiles.Get(x + 1, y + 1);

                            RenderTriangle(dynamicMesh, tile0, tile1, tile2);
                            RenderTriangle(dynamicMesh, tile2, tile1, tile3);
                        }
                    }

                    Mesh  mesh  = dynamicMesh.Create();
                    Chunk chunk = GetChunk(cy, cx);
                    chunk.SetMesh(mesh);
                }
            }
        }

        //Debug.Log("Triangles:" + dynamicMesh.triangles.Count + "Vertices:" + dynamicMesh.vertices.Count);

        //Mesh mesh = dynamicMesh.Create();

        //meshFilter.mesh = mesh;

        //meshCollider.sharedMesh = mesh;
        //Debug.Log("NavigationBlob::MeshUpdate duration=" + (Time.realtimeSinceStartup - timer));
    }
 public virtual void ActivateContent(LogicTile t){}
Example #29
0
 /// <summary>
 /// 设置色块的北,南的临近色块
 /// </summary>
 /// <param name="north">北面</param>
 /// <param name="south">南面</param>
 public static void MakeNorthSouthNeighbor(LogicTile north, LogicTile south)
 {
     north.south = south;
     south.north = north;
 }
        private void Spawn()
        {
            int free = LogicMath.Min(LogicMath.Min(this.m_spawnCount, this.m_maxSpawned - this.m_spawned.Size()), this.m_maxLifetimeSpawns - this.m_lifeTimeSpawns);

            if (free > 0)
            {
                int x           = this.m_parent.GetX();
                int y           = this.m_parent.GetY();
                int tileX       = this.m_parent.GetTileX();
                int tileY       = this.m_parent.GetTileY();
                int width       = this.m_parent.GetWidthInTiles();
                int height      = this.m_parent.GetHeightInTiles();
                int levelWidth  = this.m_parent.GetLevel().GetWidthInTiles();
                int levelHeight = this.m_parent.GetLevel().GetHeightInTiles();

                int startTileX = LogicMath.Clamp(tileX - this.m_radius, 0, levelWidth);
                int startTileY = LogicMath.Clamp(tileY - this.m_radius, 0, levelHeight);
                int endTileX   = LogicMath.Clamp(tileX + this.m_radius + width, 0, levelWidth);
                int endTileY   = LogicMath.Clamp(tileY + this.m_radius + height, 0, levelHeight);

                int radius      = (this.m_radius << 9) * (this.m_radius << 9);
                int possibility = (endTileX - startTileX) * (endTileY - startTileY);

                LogicArrayList <LogicTile> spawnPoints = new LogicArrayList <LogicTile>(possibility);
                LogicTileMap tileMap = this.m_parent.GetLevel().GetTileMap();

                int spawnPointUpStartX = x + (width << 9);
                int spawnPointUpStartY = y + (height << 9);

                int tmp4 = y - 256 - (startTileY << 9);

                int startMidX = (startTileX << 9) | 256;
                int startMidY = (startTileY << 9) | 256;

                for (int i = startTileX, j = startMidX; i < endTileX; i++, j += 512)
                {
                    int tmp1 = j >= spawnPointUpStartX ? -spawnPointUpStartX + j + 1 : 0;
                    int tmp2 = j >= x ? tmp1 : x - j;

                    tmp2 *= tmp2;

                    for (int k = startTileY, l = startMidY, m = tmp4; k < endTileY; k++, l += 512, m -= 512)
                    {
                        LogicTile tile = tileMap.GetTile(i, k);

                        if (tile.GetGameObjectCount() == 0)
                        {
                            int tmp3 = y <= l ? l < spawnPointUpStartY ? 0 : -spawnPointUpStartY + l + 1 : m;

                            tmp3 *= tmp3;

                            if (tmp2 + tmp3 <= radius)
                            {
                                spawnPoints.Add(tile);
                            }
                        }
                    }
                }

                for (int i = free; i > 0 && spawnPoints.Size() > 0; i--, ++this.m_lifeTimeSpawns)
                {
                    int idx = this.m_randomizer.Rand(spawnPoints.Size());

                    LogicTile       tile       = spawnPoints[idx];
                    LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(this.m_spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                    gameObject.SetInitialPosition(tile.GetX() << 9, tile.GetY() << 9);

                    this.m_parent.GetGameObjectManager().AddGameObject(gameObject, -1);
                    this.m_spawned.Add(gameObject.GetGlobalID());

                    spawnPoints.Remove(idx);
                }
            }
        }
Example #31
0
 /// <summary>
 /// 设置该色块的东,西方向临近色块
 /// </summary>
 /// <param name="east">东面</param>
 /// <param name="west">西面</param>
 public static void MakEastWestNeighbor(LogicTile east, LogicTile west)
 {
     east.west = west;
     west.east = east;
 }
Example #32
0
        public bool PlaceOneUnit()
        {
            if (this.m_placePositionX == -1 && this.m_placePositionY == -1)
            {
                int startAreaY   = this.m_level.GetPlayArea().GetStartY();
                int widthInTiles = this.m_level.GetWidthInTiles();

                int minDistance = -1;

                for (int i = 0; i < widthInTiles; i++)
                {
                    int centerY = (startAreaY - 1) / 2;

                    for (int j = 0; j < startAreaY - 1; j++, centerY--)
                    {
                        int distance = ((widthInTiles >> 1) - i) * ((widthInTiles >> 1) - i) + centerY * centerY;

                        if (minDistance == -1 || distance < minDistance)
                        {
                            LogicTile tile = this.m_level.GetTileMap().GetTile(i, j);

                            if (tile.GetPassableFlag() != 0)
                            {
                                this.m_placePositionX = i;
                                this.m_placePositionY = j;
                                minDistance           = distance;
                            }
                        }
                    }
                }
            }

            if (this.m_placePositionX == -1 && this.m_placePositionY == -1)
            {
                Debugger.Error("LogicNpcAttack::placeOneUnit - No attack position found!");
            }
            else
            {
                LogicArrayList <LogicDataSlot> units = this.m_npcAvatar.GetUnits();

                for (int i = 0; i < units.Size(); i++)
                {
                    LogicDataSlot slot = units[i];

                    if (slot.GetCount() > 0)
                    {
                        LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(this.m_npcAvatar, (LogicCharacterData)slot.GetData(), this.m_level,
                                                                                           this.m_placePositionX << 9,
                                                                                           this.m_placePositionY << 9);

                        if (!this.m_unitsDeployStarted)
                        {
                            character.GetListener().MapUnlocked();
                        }

                        character.GetCombatComponent().SetPreferredTarget(this.m_buildingClass, 100, false);

                        this.m_unitsDeployStarted = true;

                        return(true);
                    }
                }
            }

            return(false);
        }