Esempio n. 1
0
    public IEnumerable <Army> GetArmiesInEncounterZone(WorldPosition attackerPosition, WorldOrientation attackDirection)
    {
        int            deploymentAreaWidth = Amplitude.Unity.Runtime.Runtime.Registry.GetValue <int>("Gameplay/Battle/DeploymentAreaWidth", 3);
        int            deploymentAreaDepth = Amplitude.Unity.Runtime.Runtime.Registry.GetValue <int>("Gameplay/Battle/DeploymentAreaDepth", 2);
        DeploymentArea area = new DeploymentArea(attackerPosition, attackDirection, this.world.WorldParameters);

        area.Initialize(deploymentAreaWidth, deploymentAreaDepth);
        WorldArea        attackerDeploymentArea = new WorldArea(area.GetWorldPositions(this.world.WorldParameters));
        WorldOrientation battleZone2Orientation = attackDirection.Rotate(3);
        WorldPosition    center2 = WorldPosition.GetNeighbourTile(attackerPosition, attackDirection, 1);

        area = new DeploymentArea(center2, battleZone2Orientation, this.world.WorldParameters);
        area.Initialize(deploymentAreaWidth, deploymentAreaDepth);
        WorldArea defenderDeploymentArea = new WorldArea(area.GetWorldPositions(this.world.WorldParameters));
        WorldArea battleArea             = new WorldArea(attackerDeploymentArea.Grow(this.world.WorldParameters));

        battleArea = battleArea.Union(defenderDeploymentArea.Grow(this.world.WorldParameters));
        foreach (WorldPosition worldPosition in battleArea)
        {
            Army army = this.worldAtlasArmies.GetValue(worldPosition);
            if (army != null)
            {
                yield return(army);
            }
        }
        yield break;
    }
Esempio n. 2
0
    private void GenerateBattleZone(WorldPosition attackerPosition, WorldOrientation orientation)
    {
        World world = (base.GameService.Game as global::Game).World;
        IGlobalPositionningService globalPositionningService = null;

        if (globalPositionningService == null)
        {
            WorldView worldView = Services.GetService <Amplitude.Unity.View.IViewService>().CurrentView as WorldView;
            if (worldView != null && worldView.CurrentWorldViewTechnique != null)
            {
                globalPositionningService = worldView.CurrentWorldViewTechnique.Services.GetService <IGlobalPositionningService>();
            }
        }
        if (!attackerPosition.IsValid)
        {
            return;
        }
        WorldPosition  worldPosition  = attackerPosition;
        DeploymentArea deploymentArea = new DeploymentArea(worldPosition, orientation, world.WorldParameters);

        deploymentArea.Initialize(this.DeploymentAreaWidth, this.DeploymentAreaDepth);
        WorldArea        worldArea       = new WorldArea(deploymentArea.GetWorldPositions(world.WorldParameters));
        WorldOrientation forward         = orientation.Rotate(3);
        DeploymentArea   deploymentArea2 = new DeploymentArea(WorldPosition.GetNeighbourTile(worldPosition, orientation, 1), forward, world.WorldParameters);

        deploymentArea2.Initialize(this.DeploymentAreaWidth, this.DeploymentAreaDepth);
        WorldArea worldArea2 = new WorldArea(deploymentArea2.GetWorldPositions(world.WorldParameters));
        WorldArea worldArea3 = new WorldArea(worldArea.Grow(world.WorldParameters));

        worldArea3 = worldArea3.Union(worldArea2.Grow(world.WorldParameters));
        WorldPatch worldPatch = globalPositionningService.GetWorldPatch(attackerPosition);

        this.GenerateGeometry(worldPatch, attackerPosition, worldArea3, worldArea, worldArea2);
    }
Esempio n. 3
0
    //Places the given unit at the position on the map. In the case of deployment
    //areas, only the x position is required, the y position of the unit is set
    //based on the units already in the area. Logs an error if the square does
    //not exist or is already occupied.
    public void placeUnit(Unit unit)
    {
        //Place the unit at the final position
        //If it is a square
        if (unit.position.x >= 0)
        {
            Square square = getSquare(unit.position);
            if (square != null)
            {
                //Not occupied
                if (!square.isOccupied)
                {
                    square.occupant   = unit;
                    square.isOccupied = true;
                }
                //Already occupied
                else
                {
                    Debug.LogError("Specified square already occupied for \"placeUnit\" " +
                                   "method.\r\nMethod called for (" + unit.position.x + ", " +
                                   unit.position.y + ")");
                }
            }
            //No such position
            else
            {
                Debug.LogError("No such destination square for \"placeUnit\" " +
                               "method.\r\nMethod called for (" + unit.position.x +
                               ", " + unit.position.y + ")");
            }
        }

        //If the position is a deployment area add it to the deployment area
        else if (otherAreas.Length > (-1 - (int)unit.position.x))
        {
            int            areaIndex = -1 - (int)unit.position.x;
            DeploymentArea area      = otherAreas[areaIndex];
            area.units.Add(unit);
            unit.position.y = area.units.Count - 1;
        }

        //If there is no such position
        else
        {
            Debug.LogError("No such destination square for \"placeUnit\" " +
                           "method.\r\nMethod called for (" + unit.position.x +
                           ", " + unit.position.y + ")");
        }
    }
Esempio n. 4
0
    /*
     * Lifecycle
     */

    protected void Awake()
    {
        pucks          = GetComponentsInChildren <PointAndShoot>();
        aimChevron     = GetComponentInChildren <AimChevron>();
        pmgm           = FindObjectOfType <PuckMasterGameManager>();
        powerIndicator = GetComponentInChildren <PowerIndicator>();

        foreach (var da in FindObjectsOfType <DeploymentArea>())
        {
            if (this.tag.Equals(da.tag))
            {
                deploymentArea = da;
            }
        }
    }
Esempio n. 5
0
 //Method for placing a blip in a deploymentArea. The deploymentArea
 //parameter is the index of the deploymentArea in the map.
 public void deployBlip(int deploymentArea, int gsInBlip)
 {
     if (gameMap.otherAreas.Length > deploymentArea)
     {
         DeploymentArea targetArea = gameMap.otherAreas[deploymentArea];
         Unit           blip       = new Unit("Blip", EntityType.Blip, new Vector2(-1 - deploymentArea, 0), targetArea.relativePosition);
         blip.AP     = UnitData.getMaxAP(blip.unitType);
         blip.noOfGS = gsInBlip;
         gameMap.placeUnit(blip);
         ioModule.placeUnit(blip);
     }
     else
     {
         Debug.LogError("No such deploymentArea for \"deployBlip\" method");
     }
 }
Esempio n. 6
0
    //Removes the unit at the position, resetting all other positions
    //that change in the process. Logs an error if there is no such
    //unit or no such position. Takes the calling method's name and
    //the position as parameters, and returns the class for the
    //removed unit.
    private Unit retrieveUnit(Vector2 position, string callingMethod)
    {
        Unit returnUnit;

        //If it is a position for a square
        if (position.x >= 0)
        {
            Square square = getSquare(position);
            if (square != null)
            {
                if (square.isOccupied)
                {
                    //If the door is closed, it is removed
                    if (!square.doorIsOpen && square.hasDoor)
                    {
                        returnUnit        = square.occupant;
                        square.occupant   = null;
                        square.isOccupied = false;
                        square.doorIsOpen = true;
                        square.hasDoor    = false;
                        return(returnUnit);
                    }
                    //Otherwise, just remove the unit
                    else
                    {
                        returnUnit        = square.occupant;
                        square.occupant   = null;
                        square.isOccupied = false;
                        return(returnUnit);
                    }
                }
                //No such unit
                else
                {
                    Debug.LogError("No such unit for \"" + callingMethod + "\" method\r\n" +
                                   "Method called for (" + position.x + ", " + position.y +
                                   ")");
                    return(null);
                }
            }
            //No such square
            else
            {
                Debug.LogError("No such square for \"" + callingMethod + "\" method\r\n" +
                               "Method called for (" + position.x + ", " + position.y +
                               ")");
                return(null);
            }
        }
        //If it is a position in a deployment area
        else if (otherAreas.Length > (-1 - position.x))
        {
            int            areaIndex = -1 - (int)position.x;
            DeploymentArea area      = otherAreas[areaIndex];
            //Remove the unit
            if (area.units.Count > position.y)
            {
                returnUnit = (Unit)area.units[(int)position.y];
                area.units.RemoveAt((int)position.y);
                //Reset the positions of the remaining units
                for (int i = 0; i < area.units.Count; i++)
                {
                    Unit unit = (Unit)area.units[i];
                    unit.position = new Vector2(position.x, i);
                }
                return(returnUnit);
            }
            //Unless there is no such unit
            else
            {
                Debug.LogError("No such unit for \"" + callingMethod + "\" method\r\n" +
                               "Method called for (" + position.x + ", " + position.y +
                               ")");
                return(null);
            }
        }
        //No such position
        else
        {
            Debug.LogError("No such square for \"" + callingMethod + "\" method\r\n" +
                           "Method called for (" + position.x + ", " + position.y +
                           ")");
            return(null);
        }
    }