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; } }
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); }
// Use this for initialization void Start() { gManager = GameObject.Find("gameManager"); c_interval = interval; command = GetComponent <AICommand> (); playerID = command.playerID; }
void inSetup() { aiCommand = GetComponent <AICommand> (); playerID = aiCommand.playerID; AIseed = this.gameObject; _state = State.Scan; }
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); }
// Update is called once per frame void Update() { if (currentCommand != null) { currentCommand.Update(Time.deltaTime); if (currentCommand.finished) { currentCommand = null; } } }
/// <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); } }
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; }
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"); }
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); }
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); }
//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 } } } }
public void AttackTarget(Unit tgtUnit) { AICommand newCommand = new AICommand(AICommand.CommandType.AttackTarget, tgtUnit); IssueCommand(newCommand); }
public void SentSelectedUnitsTo(Vector3 pos) { AICommand newCommand = new AICommand(AICommand.CommandType.GoToAndGuard, pos); IssueCommand(newCommand); }
public void IssueCommand(AICommand cmd) { selectedPlatoon.ExecuteCommand(cmd); }
public void doCammand(AICommand.AIState pCammand) { cammand = pCammand; doCammand(); }