Esempio n. 1
0
    // USAGE: if there is a nearby enemy of the attached unit, attack it
    //        return true if there was a successful attack
    public bool attackNearby(HashSet <Cell> nearbyCells, Unit u)
    {
        bool madeAttack = false;

        if (nearbyCells.Count == 0)
        {
            return(madeAttack);
        }

        foreach (Cell c in nearbyCells)
        {
            if (!c.getOccupied())
            {
                continue;
            }

            Unit.Faction f = c.getUnit().unitFaction;
            if (f == Unit.Faction.Player || f == Unit.Faction.Allied)                // found an enemy --> let's attack it!
            {
                IntfActionModule attack = findBestAttack(u);
                attack.executeAction(u.currentCell, u.currentDir);
                madeAttack = true;
                break;
            }
        }
        return(madeAttack);
    }
Esempio n. 2
0
 public void UpdateNetworkFaction(int otherPlayerNumber, Unit.Faction newFaction)
 {
     factions[otherPlayerNumber] = newFaction;
 }
Esempio n. 3
0
    // add a new unit to the field
    public void addUnit(List <string> actions, bool isSelectable, Cell startCell, string unitName, Unit.Faction faction,
                        Unit.Direction facing, int id, List <Unit.Faction> enemyFactions)
    {
        if (allUnits == null)
        {
            allUnits = new List <Unit>();
        }

        // the unit will set its proper name later
        GameObject newUnit = new GameObject("newUnit");

        // adds appropriate tag in reference to the unit's faction
        newUnit.tag = faction.ToString();

        // BoxCollider is needed to make this unit clickable
        if (isSelectable)
        {
            newUnit.AddComponent <BoxCollider2D>();
        }

        // For now, all units get a basic ai controller except
        // units directly controlled by the player
        if (faction == Unit.Faction.Player)
        {
            newUnit.AddComponent <ManualController>();
        }
        else
        {
            // newUnit.AddComponent<RandomAIController>();
            newUnit.AddComponent <SimpleAIController>();                                /// MODIFED THIS HERE FOR TESTING !!! ///
        }
        // add the appropriate IntfActionModule impls to the unit
        foreach (string action in actions)
        {
            switch (action)
            {
            case "singlepanelbasicattack":
                newUnit.AddComponent <SinglePanelBasicAttack>();
                break;

            case "smacknearby":
                newUnit.AddComponent <SmackNearby>();
                break;

            case "jumptest":
                newUnit.AddComponent <JumpTestAction>();
                break;
            }
        }

        Unit unitComp = newUnit.AddComponent <Unit>();

        unitComp.setUnit(startCell, facing, Unit.Faction.Player, unitName, id, enemyFactions);
        startCell.setUnit(unitComp);
        allUnits.Add(unitComp);
    }