Exemplo n.º 1
0
    /// <summary>
    /// Initializes a player for a battle.
    /// </summary>
    /// <returns>The player.</returns>
    /// <param name="race">The player's race.</param>
    /// <param name="strongholdGameObject">Name of the game object placed where
    /// the player's stronghold should be.</param>
    private Battle.PlayerInformation initializePlayer(Storage.Races race, string strongholdGameObject)
    {
        GameObject stronghold;

        Battle.PlayerInformation player = new Battle.PlayerInformation(race);
        stronghold = GameObject.Find(strongholdGameObject);
        player.AddBuilding(BuildingTypes.STRONGHOLD, stronghold.transform.position.x, stronghold.transform.position.z, EntityStatus.IDLE);
        player.AddUnit(UnitTypes.HERO, stronghold.transform.position.x - 50, stronghold.transform.position.z);
        player.SetInitialResources(2000, 2000, 2000, 2000);
        return(player);
    }
Exemplo n.º 2
0
        public override void Start()
        {
            base.Start();
            DifficultyLvl = info.Difficulty;
            _selfRace     = info.GetPlayerRace() == Races.MEN ? Races.ELVES : Races.MEN;

            //Init lists
            EnemyUnits     = new List <Unit>();
            EnemyBuildings = new List <IGameEntity>();
            OwnResources   = new List <Resource>();
            OwnBarracks    = new List <Barrack>();
            modules        = new List <AIModule>();
            Army           = new List <Unit>();
            Workers        = new List <Unit>();

            Battle.PlayerInformation me = info.GetBattle().GetPlayerInformationList()[playerId - 1];
            SetInitialResources(me.GetResources().Wood, me.GetResources().Food, me.GetResources().Metal, me.GetResources().Gold);
            Battle.PlayableEntity.EntityPosition pos = me.GetBuildings()[0].position;
            rootBasePosition = new Vector3(pos.X, 80, pos.Y);
            buildPosition    = rootBasePosition;
            Macro            = new MacroManager(this);
            StoryMode        = Macro.architect.constructionGrid.mode != AIMode.BATTLE;
            Micro            = new MicroManager(this);
            modules.Add(new AIModule(Macro.MacroHigh, !StoryMode ? (39 - DifficultyLvl * 3) : 1));
            modules.Add(new AIModule(Macro.MacroLow, 8 - DifficultyLvl));
            modules.Add(new AIModule(Micro.Micro, 4 - DifficultyLvl));
            timers        = new float[modules.Count];
            hasStronghold = true;
            for (int i = 0; i < modules.Count; i++)
            {
                timers[i] = 0;
            }

            InstantiateBuildings(me.GetBuildings());
            InstantiateUnits(me.GetUnits());

            ActorSelector selector = new ActorSelector()
            {
                registerCondition = gameObject => gameObject.GetComponent <FOWEntity>().IsOwnedByPlayer,
                fireCondition     = gameObject => true
            };

            Subscriber <FOWEntity.Actions, FOWEntity> .get.registerForAll(FOWEntity.Actions.DISCOVERED, OnEntityFound, selector);

            Subscriber <FOWEntity.Actions, FOWEntity> .get.registerForAll(FOWEntity.Actions.HIDDEN, OnEntityLost, selector);

            if (AI_DEBUG_ENABLED)
            {
                aiDebug = AIDebugSystem.CreateComponent(gameObject, this);
            }

            missionStatus = new MissionStatus(playerId);
        }
Exemplo n.º 3
0
    /// <summary>
    /// Sets the battle with predefined parameters for the mission, player
    /// settings, and resources.
    /// </summary>
    private void hardcodedBattle()
    {
        game = new Battle();
        // Sets the mission
        Battle.MissionDefinition.TargetType t = new Battle.MissionDefinition.TargetType();
        t.unit = UnitTypes.HERO;
        game.AddMission(Battle.MissionType.DESTROY, 1, EntityType.UNIT, t, 0, true, "");
        // Initializes the human civilization
        Battle.PlayerInformation player = new Battle.PlayerInformation(Races.MEN);
        player.AddBuilding(BuildingTypes.STRONGHOLD, 752, 880, EntityStatus.IDLE);
        player.AddUnit(UnitTypes.HERO, 764.9564f, 823.0175f);
        player.SetInitialResources(2000, 2000, 2000, 2000);
        game.AddPlayerInformation(player);
        // Initializes the elven civilization
        player = new Battle.PlayerInformation(Races.ELVES);
        player.AddUnit(UnitTypes.HERO, 331.35f, 575.81f);
        player.AddBuilding(BuildingTypes.STRONGHOLD, 283.7f, 562.5f, EntityStatus.IDLE);
        player.SetInitialResources(2000, 2000, 2000, 2000);
        game.AddPlayerInformation(player);

        game.SetWorldResources(5000, 5000, 5000);
    }
Exemplo n.º 4
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();
        _selection = GetComponent <Managers.SelectionManager>();
        //request the race of the player
        _selfRace = info.GetPlayerRace();
        _selection.SetRace(race);

        cam    = GameObject.FindWithTag("MainCamera").GetComponent <CameraController>();
        events = GetComponent <EventsNotifier>();

        Battle.PlayerInformation me = info.GetBattle().GetPlayerInformationList()[playerId - 1];
        InstantiateBuildings(me.GetBuildings());
        InstantiateUnits(me.GetUnits());
        SetInitialResources(me.GetResources().Wood, me.GetResources().Food, me.GetResources().Metal, me.GetResources().Gold);
        // gameObject.AddComponent<ResourcesPlacer>();

        missionStatus    = new MissionStatus(playerId);
        _resourcesPlacer = ResourcesPlacer.get(this); // initialization

        // TODO Set this values dynamically
        minFoodTolerance  = 100;
        minWoodTolerance  = 500;
        minMetalTolerance = 500;
        minGoldTolerance  = 500;

        foodDepleted = _resourcesPlacer.Amount(WorldResources.Type.FOOD) <= 0;

        ActorSelector selector = new ActorSelector()
        {
            registerCondition = (g) => !(g.GetComponent <FOWEntity>().IsOwnedByPlayer),
            fireCondition     = (g) => true
        };

        Utils.Subscriber <FOWEntity.Actions, FOWEntity> .get.registerForAll(FOWEntity.Actions.DISCOVERED, OnEntityFound, selector);

        timeToShow = WAIT_FOR_FINISH;
    }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a player for a battle.
 /// </summary>
 /// <returns>The player.</returns>
 /// <param name="race">The player's race.</param>
 /// <param name="strongholdGameObject">Name of the game object placed where
 /// the player's stronghold should be.</param>
 private Battle.PlayerInformation initializePlayer(Storage.Races race, string strongholdGameObject)
 {
     GameObject stronghold;
     Battle.PlayerInformation player = new Battle.PlayerInformation(race);
     stronghold = GameObject.Find(strongholdGameObject);
     player.AddBuilding(BuildingTypes.STRONGHOLD, stronghold.transform.position.x, stronghold.transform.position.z, EntityStatus.IDLE);
     player.AddUnit(UnitTypes.HERO, stronghold.transform.position.x - 50, stronghold.transform.position.z);
     player.SetInitialResources(2000, 2000, 2000, 2000);
     return player;
 }
Exemplo n.º 6
0
    /// <summary>
    /// Sets the battle with predefined parameters for the mission, player
    /// settings, and resources.
    /// </summary>
    private void hardcodedBattle()
    {
        game = new Battle();
        // Sets the mission
        Battle.MissionDefinition.TargetType t = new Battle.MissionDefinition.TargetType();
        t.unit = UnitTypes.HERO;
        game.AddMission(Battle.MissionType.DESTROY, 1, EntityType.UNIT, t, 0, true, "");
        // Initializes the human civilization
        Battle.PlayerInformation player = new Battle.PlayerInformation(Races.MEN);
        player.AddBuilding(BuildingTypes.STRONGHOLD, 752, 880, EntityStatus.IDLE);
        player.AddUnit(UnitTypes.HERO, 764.9564f, 823.0175f);
        player.SetInitialResources(2000, 2000, 2000, 2000);
        game.AddPlayerInformation(player);
        // Initializes the elven civilization
        player = new Battle.PlayerInformation(Races.ELVES);
        player.AddUnit(UnitTypes.HERO, 331.35f, 575.81f);
        player.AddBuilding(BuildingTypes.STRONGHOLD, 283.7f, 562.5f, EntityStatus.IDLE);
        player.SetInitialResources(2000, 2000, 2000, 2000);
        game.AddPlayerInformation(player);

        game.SetWorldResources(5000, 5000, 5000);
    }