Ejemplo n.º 1
0
    private void initializeGame()
    {
        MoveTowardsTarget movement_script_current;
        MeleeCombatAI melee_combat_script;

        Unit unit;

        GameObject[] preset_units_man_at_arms = GameObject.FindGameObjectsWithTag("PlayerUnit_MAA");
        GameObject[] preset_units_archer = GameObject.FindGameObjectsWithTag("PlayerUnit_ARCHER");
        GameObject unit_faction_leader = GameObject.FindGameObjectWithTag("PlayerUnit_FL");

        foreach(GameObject elem in preset_units_man_at_arms)
        {
            unit = new ManAtArms();
            unit.setGameObject(elem);
            ObjectBank.instance().addPlayerUnit(ref unit);

            unit.setCombatFocus(Unit.OFFENSIVE_FOCUS);

            movement_script_current = elem.GetComponent<MoveTowardsTarget>();
            movement_script_current.setUnitAgility(unit.getAgility());
        }

        foreach (GameObject elem in preset_units_archer)
        {
            unit = new Archer();
            unit.setGameObject(elem);
            ObjectBank.instance().addPlayerUnit(ref unit);

            unit.setCombatFocus(Unit.OFFENSIVE_FOCUS);

            movement_script_current = elem.GetComponent<MoveTowardsTarget>();
            movement_script_current.setUnitAgility(unit.getAgility());
        }

        if (unit_faction_leader != null)
        {
            unit = new FactionLeader();
            unit.setGameObject(unit_faction_leader);
            ObjectBank.instance().addPlayerUnit(ref unit);

            unit.setCombatFocus(Unit.OFFENSIVE_FOCUS);

            movement_script_current = unit_faction_leader.GetComponent<MoveTowardsTarget>();
            movement_script_current.setUnitAgility(unit.getAgility());
        }

        //Enemy units.
        preset_units_man_at_arms = GameObject.FindGameObjectsWithTag("EnemyUnit_MAA");
        preset_units_archer = GameObject.FindGameObjectsWithTag("EnemyUnit_ARCHER");

        foreach (GameObject elem in preset_units_man_at_arms)
        {
            unit = new ManAtArms();
            unit.setGameObject(elem);
            ObjectBank.instance().addEnemyUnit(ref unit);

            unit.setCombatFocus(Unit.DEFENSIVE_FOCUS);

            melee_combat_script = elem.GetComponent<MeleeCombatAI>();
            melee_combat_script.initialize(Unit.MAX_HIT_POINTS,
                                           unit.getDefaultMorale(),
                                           unit.getArmor().getDamageReductionFactor());

            movement_script_current = elem.GetComponent<MoveTowardsTarget>();
            movement_script_current.setUnitAgility(unit.getAgility());
        }

        foreach (GameObject elem in preset_units_archer)
        {
            unit = new Archer();
            unit.setGameObject(elem);
            ObjectBank.instance().addEnemyUnit(ref unit);

            unit.setCombatFocus(Unit.DEFENSIVE_FOCUS);

            movement_script_current = elem.GetComponent<MoveTowardsTarget>();
            movement_script_current.setUnitAgility(unit.getAgility());
        }

        Debug.Log("Number player units: " + ObjectBank.instance().getUnitList().Length );
        Debug.Log("Number enemy units: " + ObjectBank.instance().getEnemyUnitList().Length );
    }