Example #1
0
    private void SetupPlayers(GameContext game, Presets preset, HexGridBehaviour grid)
    {
        PlayerListData pld = GameObject.FindObjectOfType <PlayerListData>();

        if (pld != null)
        {
            IEnumerator <Vector3> basePos = CoordinatesForBases(grid);
            foreach (var player in pld._model)
            {
                GameEntity pEntity = game.CreateEntity();
                pEntity.AddTeam(player.Color);
                pEntity.isLocalPlayer = (player.Type == PlayerTypeEnum.Human);
                pEntity.isAIPlayer    = (player.Type == PlayerTypeEnum.AI);

                basePos.MoveNext();
                GameEntity       baseEntity = preset.CreateBlueprint(Presets.EntitasPresetEnum.BASE);
                HexCellBehaviour home       = grid.GetCell(basePos.Current);
                baseEntity.ReplaceLocation(home, home.GetComponent <EntitasLink>().id);
                baseEntity.ReplaceTeam(player.Color);
                baseEntity.ReplaceStartPosition(home.transform.position.x, home.transform.position.y, home.transform.position.z);
            }
        }
        else
        {
            Debug.Log("No player setup found; I'm assuming this scene was started in Unity Editor for debugging purposes");

            GameEntity pEntity = game.CreateEntity();
            pEntity.AddTeam(0);
            pEntity.isLocalPlayer = true;
            pEntity.isAIPlayer    = false;
        }
    }
Example #2
0
 public NewUnitCommand(Contexts contexts) : base(contexts.input)
 {
     _game             = contexts.game;
     _grid             = UnityEngine.GameObject.FindObjectOfType <HexGridBehaviour>();
     _presets          = new Presets(_game, _grid);
     _selectedBarracks = _game.GetGroup(GameMatcher.AllOf(GameMatcher.Selected, GameMatcher.CanBuildVehicle));
 }
Example #3
0
        public AutoAttack(Contexts contexts)
        {
            _game          = contexts.game;
            _autoAttacking = _game.GetGroup(GameMatcher.AllOf(GameMatcher.Weapon, GameMatcher.AutoAttack));
            _grid          = GameObject.FindObjectOfType <HexGridBehaviour>();

            _treeForAttacker = new Dictionary <int, AutoAttackNearestBehaviour>();
        }
    public void ReplaceNavigateCommand(HexGridBehaviour newDestination)
    {
        var index     = InputComponentsLookup.NavigateCommand;
        var component = CreateComponent <NavigateCommandComponent>(index);

        component.destination = newDestination;
        ReplaceComponent(index, component);
    }
Example #5
0
        public BuildCommands(Contexts contexts) : base(contexts.input)
        {
            _game    = contexts.game;
            _grid    = UnityEngine.GameObject.FindObjectOfType <HexGridBehaviour>();
            _presets = new Presets(_game, _grid);

            _UICommands = contexts.input.GetGroup(InputMatcher.AnyOf(InputMatcher.UIBuildBarracks, InputMatcher.UIBuildTower));
            _selectedBarracksBuilders = _game.GetGroup(GameMatcher.AllOf(GameMatcher.Selected, GameMatcher.CanBuildBarracks));
            _selectedTowerBuilders    = _game.GetGroup(GameMatcher.AllOf(GameMatcher.Selected, GameMatcher.CanBuildBarracks));
        }
Example #6
0
        public StupidBehaviour(GameContext game, AIPlayers allplayers, GameEntity playa)
        {
            _game       = game;
            _player     = playa;
            _allPlayers = allplayers;
            _grid       = GameObject.FindObjectOfType <HexGridBehaviour>();

            _tree = new Sequence(
                new Inverter(new Condition(() => HasBarracks(playa))),
                new Action(() => BuildBarracks(playa))
                );
        }
Example #7
0
    // Use this for initialization
    void Start()
    {
        //first init system (important, because I want systems to exist before any entities are created):
        _systems = new RootSystem(Contexts.sharedInstance);
        _systems.Initialize();

        HexGridBehaviour grid   = GameObject.FindObjectOfType <HexGridBehaviour>();
        GameContext      game   = Contexts.sharedInstance.game;
        Presets          preset = new Presets(game, grid);

        TurnGridToEntities(game, grid);
        FindEntitiesInUnity(game, preset);
        SetupPlayers(game, preset, grid);
    }
Example #8
0
    private IEnumerator <Vector3> CoordinatesForBases(HexGridBehaviour grid)
    {
        yield return(new Vector3(0, -grid.size, grid.size));

        yield return(new Vector3(-grid.size, grid.size, 0));

        yield return(new Vector3(grid.size, 0, -grid.size));

        yield return(new Vector3(0, grid.size, -grid.size));

        yield return(new Vector3(-grid.size, 0, -grid.size));

        yield return(new Vector3(grid.size, -grid.size, 0));
    }
Example #9
0
    private void TurnGridToEntities(GameContext game, HexGridBehaviour grid)
    {
        for (var c = grid.GetCellEnumerator(); c.MoveNext();)
        {
            HexCellBehaviour cell = c.Current;
            GameEntity       ge   = game.CreateEntity();

            Vector3    world = cell.transform.position;
            Vector3    cube  = cell.cubeCoordinates;
            Quaternion rot   = cell.transform.rotation;
            ge.AddHexCell(world.x, world.y, world.z, cube.x, cube.y, cube.z);
            ge.AddGameObject(cell.gameObject);
            ge.AddWorldCoordinates(world.x, world.y, world.z, rot.x, rot.y, rot.z, rot.w);

            //now that the entity has been created with a unique ID,
            //put this ID on the unity GameObject for easy reference:
            EntitasLink el = cell.gameObject.AddComponent <EntitasLink>();
            el.id = ge.iD.value;
        }
    }
Example #10
0
    public AutoAttackNearestBehaviour(GameContext game, GameEntity turret, HexGridBehaviour grid)
    {
        _game   = game;
        _turret = turret;
        _grid   = grid;

        inRange        = _grid.GetWithinRange(_turret.weapon.range, _turret.location.cell.cubeCoordinates);
        _CellIdInRange = new int[inRange.Count];
        for (int i = 0; i < _CellIdInRange.Length; ++i)
        {
            _CellIdInRange[i] = inRange[i].GetComponent <EntitasLink>().id;
        }

        _tree =
            new Sequence(
                new Selector(
                    new Action(KeepExistingTarget),
                    new Action(FindClosestEnemy)
                    ),
                new Action(AttackTarget)
                );
    }
Example #11
0
 public Detour(Contexts contexts) : base(contexts.game)
 {
     _game = contexts.game;
     _grid = GameObject.FindObjectOfType <HexGridBehaviour>();
 }
Example #12
0
 public Presets(GameContext game, HexGridBehaviour grid)
 {
     _game = game;
     _grid = grid;
 }
Example #13
0
 public AttackExecute(Contexts contexts)
 {
     _game           = contexts.game;
     _attackingUnits = _game.GetGroup(GameMatcher.AllOf(GameMatcher.WeaponAimed, GameMatcher.AttackTarget));
     _grid           = GameObject.FindObjectOfType <HexGridBehaviour>();
 }
Example #14
0
 public ShowWeaponRange(Contexts contexts)
 {
     _selectedUnitsWithWeapons = contexts.game.GetGroup(GameMatcher.AllOf(GameMatcher.Selected, GameMatcher.Weapon, GameMatcher.Location));
     _grid = GameObject.FindObjectOfType <HexGridBehaviour>();
 }
 public CreateNavigationPath(Contexts contexts) : base(contexts.game)
 {
     _game = contexts.game;
     _grid = GameObject.FindObjectOfType <HexGridBehaviour>();
 }