예제 #1
0
    public void ExecuteCommand(AICommand c)
    {
        if (state == UnitState.Dead)
        {
            //already dead
            return;
        }

        switch (c.commandType)
        {
        case AICommand.CommandType.GoToAndIdle:
            GoToAndIdle(c.destination);
            break;

        case AICommand.CommandType.GoToAndGuard:
            GoToAndGuard(c.destination);
            break;

        case AICommand.CommandType.Stop:
            Stop();
            break;

        case AICommand.CommandType.AttackTarget:
            MoveToAttack(c.target);
            break;

        case AICommand.CommandType.Die:
            Die();
            break;
        }
    }
예제 #2
0
        public static AICommand GetStrategy(IMap map, Unit unit)
        {
            var command = new AICommand();

            command.Command = AICommand.Move;
            command.Unit    = unit.Id;

            if (inDefenseMode)
            {
                command.Dir = Defend(map, unit);

                if (command.Dir == "base") //Turret Mode
                {
                    var turAction = Turret(map, unit);
                    if (turAction.Command == AICommand.Shoot)
                    {
                        return(turAction);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                return(Attack(map, unit));
            }

            return(command);
        }
예제 #3
0
 // Use this for initialization
 void Start()
 {
     gManager   = GameObject.Find("gameManager");
     c_interval = interval;
     command    = GetComponent <AICommand> ();
     playerID   = command.playerID;
 }
예제 #4
0
 void inSetup()
 {
     aiCommand = GetComponent <AICommand> ();
     playerID  = aiCommand.playerID;
     AIseed    = this.gameObject;
     _state    = State.Scan;
 }
예제 #5
0
        public static AICommand GetStrategy(IMap map, Unit unit)
        {
            var command = new AICommand();

            command.Command = AICommand.Move;
            command.Unit    = unit.Id;


            if (unit.CarryingResource)
            {
                command.Dir = MoveToBase(map, unit);
            }
            else if (map.HasResources)
            {
                command.Dir = GetDirectionToGem(map, unit);
                if (command.Dir == "None")
                {
                    command.Command = AICommand.Gather;
                    command.Dir     = AICommand.SerializeDirection(map.DirectionToAdjacentResource(unit.Location));
                }

                if (command.Dir == "no path")
                {
                    command.Dir = Explore(map, unit);
                }
            }
            else
            {
                command.Dir = Explore(map, unit);
            }


            return(command);
        }
예제 #6
0
 // Update is called once per frame
 void Update()
 {
     if (currentCommand != null)
     {
         currentCommand.Update(Time.deltaTime);
         if (currentCommand.finished)
         {
             currentCommand = null;
         }
     }
 }
예제 #7
0
파일: Platoon.cs 프로젝트: BUGyyc/UnityRTS
    /// <summary>
    /// 执行命令
    /// </summary>
    /// <param name="command"></param>
    public void ExecuteCommand(AICommand command)
    {
        tempPositions = GetFormationPositions(command.destination);
        for (int i = 0; i < units.Count; i++)
        {
            if (units.Count > 1)
            {
                //change the position for the command for each unit
                //so they move to a formation position rather than in the exact same place
                command.destination = tempPositions[i];
            }

            units[i].ExecuteCommand(command);
        }
    }
예제 #8
0
 public void doEffect(AICommand.AIState pCammand)
 {
     GameObject lEffect = null;
     switch (pCammand)
     {
         case AICommand.AIState.free:
             lEffect = (GameObject)Instantiate(freeEffect);
             break;
         case AICommand.AIState.follow:
             lEffect = (GameObject)Instantiate(followEffect);
             break;
         case AICommand.AIState.guard:
             lEffect = (GameObject)Instantiate(guardEffect);
             break;
     }
     lEffect.transform.parent = effectTransform;
     lEffect.transform.localPosition = Vector3.zero;
 }
예제 #9
0
        public static string Explore(IMap map, Unit unit)
        {
            PathFinder finder = new PathFinder(map);

            if (!navDirection.ContainsKey(unit.Id))
            {
                navDirection.Add(unit.Id, AICommand.SerializeDirection(MapDirections.RandomDirection()));
            }

            var results = finder.FindPath(unit.Location, GetPointFromDir(unit.Location, navDirection[unit.Id]));

            if (results == null)
            {
                var rnd = new Random();
                if (navDirection[unit.Id] == "N" || navDirection[unit.Id] == "S")
                {
                    if (rnd.Next(0, 2) == 0)
                    {
                        navDirection[unit.Id] = "E";
                    }
                    else
                    {
                        navDirection[unit.Id] = "W";
                    }
                }
                else if (navDirection[unit.Id] == "E" || navDirection[unit.Id] == "W")
                {
                    if (rnd.Next(0, 2) == 0)
                    {
                        navDirection[unit.Id] = "N";
                    }
                    else
                    {
                        navDirection[unit.Id] = "S";
                    }
                }
            }
            else
            {
                return(Globals.directionToAdjactentPoint(unit.Location, results[0]));
            }

            return("None");
        }
예제 #10
0
        public static AICommand Turret(IMap map, Unit unit)
        {
            var atkCommand = new AICommand();

            atkCommand.Command = AICommand.Shoot;
            atkCommand.Unit    = unit.Id;

            var locations = map.EnemyLocationsInRange(unit.Location, 2);

            if (locations.Count > 0)
            {
                atkCommand.Dx = locations[0].X - unit.Location.X;
                atkCommand.Dy = locations[0].Y - unit.Location.Y;
            }
            else
            {
                atkCommand.Command = "";
            }

            return(atkCommand);
        }
예제 #11
0
        public void Test_BuildCommandList()
        {
            var unit1    = new Mock <Unit>();
            var command1 = new AICommand()
            {
                Command = AICommand.Move, Unit = 1, Dir = AICommand.North
            };

            unit1.Setup(u => u.BuildCommand()).Returns(command1);

            var unit2    = new Mock <Unit>();
            var command2 = new AICommand()
            {
                Command = AICommand.Move, Unit = 2, Dir = AICommand.South
            };

            unit2.Setup(u => u.BuildCommand()).Returns(command2);

            var unit3 = new Mock <Unit>();

            unit3.Setup(u => u.BuildCommand()).Returns((AICommand)null);

            var unitManager = new Mock <IUnitManager>();
            var units       = new Dictionary <int, Unit>()
            {
                { 1, unit1.Object },
                { 2, unit2.Object },
                { 3, unit3.Object }
            };

            unitManager.Setup(g => g.Units).Returns(units);

            var map      = new Map();
            var commands = new AIStrategy(unitManager.Object, map).BuildCommandList();

            commands.Count.Should().Be(2);
            commands[0].Should().Be(command1);
            commands[1].Should().Be(command2);
        }
예제 #12
0
    //Happens in Play mode
    //Uses the NavMeshAgent to control the units, delegating their movement and animations to the AI
    private void ProcessPlayModeFrame(Playable playable)
    {
        int inputCount = playable.GetInputCount();

        for (int i = 0; i < inputCount; i++)
        {
            float inputWeight = playable.GetInputWeight(i);
            ScriptPlayable <AICommandBehaviour> inputPlayable = (ScriptPlayable <AICommandBehaviour>)playable.GetInput(i);
            AICommandBehaviour input = inputPlayable.GetBehaviour();

            //Make the Unit script execute the command
            if (inputWeight > 0f)
            {
                if (!input.commandExecuted)
                {
                    AICommand c = new AICommand(input.commandType, input.targetPosition, input.targetUnit);
                    trackBinding.ExecuteCommand(c);
                    input.commandExecuted = true;                     //this prevents the command to be executed every frame of this clip
                }
            }
        }
    }
예제 #13
0
    public void AttackTarget(Unit tgtUnit)
    {
        AICommand newCommand = new AICommand(AICommand.CommandType.AttackTarget, tgtUnit);

        IssueCommand(newCommand);
    }
예제 #14
0
    public void SentSelectedUnitsTo(Vector3 pos)
    {
        AICommand newCommand = new AICommand(AICommand.CommandType.GoToAndGuard, pos);

        IssueCommand(newCommand);
    }
예제 #15
0
 public void IssueCommand(AICommand cmd)
 {
     selectedPlatoon.ExecuteCommand(cmd);
 }
예제 #16
0
 public void doCammand(AICommand.AIState pCammand)
 {
     cammand = pCammand;
     doCammand();
 }