Beispiel #1
0
    protected List <TileWithLevel> CalculateTilesFromTemplate(RelativeFootprintTemplate footprint, TileCoords pivotTile, TileCoords pivotFacing, int pivotLevel)
    {
        List <TileWithLevel> footprintList = new List <TileWithLevel>();

        foreach (var part in footprint.footprintParts)
        {
            TileWithFacing newVec = new TileWithFacing()
            {
                position = pivotTile, facing = pivotFacing
            };
            if (part.relativePosStep1.step > 0)
            {
                newVec = newVec.Traverse(part.relativePosStep1.direction, part.relativePosStep1.step);
            }
            if (part.relativePosStep2.step > 0)
            {
                newVec = newVec.Traverse(part.relativePosStep2.direction, part.relativePosStep2.step);
            }
            footprintList.Add(new TileWithLevel()
            {
                position = newVec.position, level = pivotLevel + part.relativeLevel
            });
        }
        return(footprintList);
    }
Beispiel #2
0
    public override BaseGamePiece FindTarget()
    {
        List <ShipGamePiece> allShips = ShipManager.GetAllShips();

        //Next Turn Hex
        TileWithFacing startVec = new TileWithFacing()
        {
            position = myGamePiece.currentTile, facing = myGamePiece.currentTileFacing
        };
        TileWithFacing headingTile = startVec.Traverse(HexDirection.Forward, myGamePiece.currentVelocity);

        //Find the ship closest to where I will be if I move forward. Exclude the ship that fired me.
        ShipGamePiece closestShip         = null;
        float         closestShipDistance = float.MaxValue;

        foreach (ShipGamePiece ship in allShips)
        {
            if (ship == myGamePiece.motherGamePiece)
            {
                continue;
            }

            float distance = HexMapHelper.CrowFlyDistance(headingTile.position, myGamePiece.currentLevel, ship.currentTile, ship.currentLevel);
            if (distance < closestShipDistance)
            {
                closestShipDistance = distance;
                closestShip         = ship;
            }
        }

        currentTarget = closestShip;
        Debug.DrawLine(HexMapHelper.GetWorldPointFromTile(myGamePiece.currentTile), HexMapHelper.GetWorldPointFromTile(currentTarget.currentTile), Color.yellow, 5f);
        return(currentTarget);
    }
Beispiel #3
0
    void OnNewTurn(GameControllerFsm.Events.BeginCommandSelectionState @event)
    {
        FindTarget();
        TileWithFacing startVec = new TileWithFacing()
        {
            position = myGamePiece.currentTile, facing = myGamePiece.currentTileFacing
        };
        TileCoords missileOkayZone = startVec.Traverse(HexDirection.Forward, myGamePiece.shipTemplete.missileTemplate.TopSpeed).position;

        if (HexMapHelper.CrowFlyDistance(missileOkayZone, myGamePiece.currentLevel, currentTarget.currentTile, currentTarget.currentLevel) < 4f)
        {
            myGamePiece.QueueMissile(true);
        }
    }
Beispiel #4
0
    // Start is called before the first frame update
    void Start()
    {
        TileCoords     startTile = HexMapHelper.GetTileFromWorldPoint(transform.position);
        TileWithFacing startVec  = new TileWithFacing()
        {
            position = startTile,
            facing   = HexMapHelper.GetNeighborTiles(startTile)[facingIndex]
        };

        List <TileWithLevel> footprintParts = new List <TileWithLevel>();

        footprintParts.Add(new TileWithLevel()
        {
            position = startVec.position, level = level
        });

        List <Vector3> lineNodes  = new List <Vector3>();
        TileWithFacing currentVec = startVec;

        for (int nodeIndex = 0; nodeIndex < maxLength; nodeIndex++)
        {
            currentVec = currentVec.Traverse(HexDirection.Forward);
            if (currentVec.position == startVec.position)
            {
                break;
            }
            lineNodes.Add(HexMapHelper.GetWorldPointFromTile(currentVec.position, level));
            footprintParts.Add(new TileWithLevel()
            {
                position = currentVec.position, level = level
            });
        }
        line.positionCount = lineNodes.Count;
        line.SetPositions(lineNodes.ToArray());

        footprint = new StaticFootprint(footprintParts);
    }
    public void GenerateCommandPoints()
    {
        if (hasGeneratedThisTurn)
        {
            return;
        }

        //Standard Destinations

        //Forward Facing (current speed)
        //This is the default selected command point for players
        TileWithFacing startingVec = new TileWithFacing {
            position = pieceController.GetPivotTilePosition(), facing = pieceController.GetTileFacing()
        };

        var defalutSelectedPoint = InstantiateCommandPoint(
            startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity),
            pieceController.GetPivotTileLevel(),
            pieceController.gamePiece.currentVelocity);

        //Forward Facing (speed up)
        if (pieceController.gamePiece.currentVelocity < pieceController.pieceTemplate.TopSpeed && pieceController.pieceTemplate.canAccelerate)
        {
            InstantiateCommandPoint(
                startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity + 1),
                pieceController.GetPivotTileLevel(),
                pieceController.gamePiece.currentVelocity + 1);
        }

        //Forward Facing (slow down)
        if (pieceController.gamePiece.currentVelocity > 2 && pieceController.pieceTemplate.canDecelerate)
        {
            InstantiateCommandPoint(
                startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity - 1),
                pieceController.GetPivotTileLevel(),
                pieceController.gamePiece.currentVelocity - 1);
        }

        //Turn Left (straight bank)
        InstantiateCommandPoint(
            startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity).Face(HexDirection.ForwardLeft),
            pieceController.GetPivotTileLevel(),
            pieceController.gamePiece.currentVelocity);


        //Turn Right (straight bank)
        InstantiateCommandPoint(
            startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity).Face(HexDirection.ForwardRight),
            pieceController.GetPivotTileLevel(),
            pieceController.gamePiece.currentVelocity);

        for (int manu = 1; manu <= pieceController.pieceTemplate.Maneuverability; manu++)
        {
            if (pieceController.gamePiece.currentVelocity - manu >= 1)
            {
                if (pieceController.pieceTemplate.canStrafe)
                {
                    //Strafe Left
                    InstantiateCommandPoint(
                        startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity - manu).Traverse(HexDirection.ForwardLeft, manu).Face(HexDirection.ForwardRight),
                        pieceController.GetPivotTileLevel(),
                        pieceController.gamePiece.currentVelocity);

                    //Strafe Right
                    InstantiateCommandPoint(
                        startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity - manu).Traverse(HexDirection.ForwardRight, manu).Face(HexDirection.ForwardLeft),
                        pieceController.GetPivotTileLevel(),
                        pieceController.gamePiece.currentVelocity);
                }

                //Turn Left
                InstantiateCommandPoint(
                    startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity - manu).Traverse(HexDirection.ForwardLeft, manu),
                    pieceController.GetPivotTileLevel(),
                    pieceController.gamePiece.currentVelocity);

                //Turn Right
                InstantiateCommandPoint(
                    startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity - manu).Traverse(HexDirection.ForwardRight, manu),
                    pieceController.GetPivotTileLevel(),
                    pieceController.gamePiece.currentVelocity);
            }
        }



        //Climb Altitude
        if (pieceController.pieceTemplate.effortlessClimb)
        {
            if (pieceController.GetPivotTileLevel() < 6)
            {
                InstantiateCommandPoint(
                    startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity),
                    pieceController.GetPivotTileLevel() + 1,
                    pieceController.gamePiece.currentVelocity);
            }
        }
        else
        {
            if (pieceController.GetPivotTileLevel() < 6 && pieceController.gamePiece.currentVelocity >= 2)
            {
                InstantiateCommandPoint(
                    startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity - 1),
                    pieceController.GetPivotTileLevel() + 1,
                    pieceController.gamePiece.currentVelocity);
            }
        }

        //Descend Altitude
        if (pieceController.GetPivotTileLevel() > 1)
        {
            InstantiateCommandPoint(
                startingVec.Traverse(HexDirection.Forward, pieceController.gamePiece.currentVelocity),
                pieceController.GetPivotTileLevel() - 1,
                pieceController.gamePiece.currentVelocity);
        }

        if (pieceController.isPlayerControlled)
        {
            defalutSelectedPoint.SelectPoint(true);
        }

        hasGeneratedThisTurn = true;
    }