/// <summary> /// Given an Entity and an ActionCommand, this function will attempt to assign the ActionCommand to the Entity's /// action queue. /// </summary> /// <param name="entity"></param> /// <param name="command"></param> /// <returns>false if the entity rejects the command. true otherwise.</returns> public bool giveCommand(Entity entity, ActionCommand command) { if (entity == null) { return false; } // Commands that only Units can execute. else if (command.actionType == ActionCommand.ActionType.Move || command.actionType == ActionCommand.ActionType.SimpleAttack || command.actionType == ActionCommand.ActionType.BuildBuilding) { return handleUnitCommand(entity, command); } return false; }
private bool handleUnitCommand(Entity entity, ActionCommand command) { // Check if the entity is a Unit. Reject the command if the entity is not a Unit. if (entity.getEntityType() != Entity.EntityType.Unit) { return false; } // Get the action queue from the entity and clear it. Queue<ActionCommand> queue = entity.getActionQueue(); queue.Clear(); // Give the entity the command. entity.getActionQueue().Enqueue(command); return true; }
/// <summary> /// Given an Entity and an ActionCommand, this function will attempt to assign the ActionCommand to the Entity's /// action queue. /// </summary> /// <param name="entity"></param> /// <param name="command"></param> /// <returns>false if the entity rejects the command. true otherwise.</returns> public bool giveCommand(Entity entity, ActionCommand command) { if (entity == null) { return false; } else if (command.actionType == ActionCommand.ActionType.Move) { return handleUnitCommand(entity, command); } else if (command.actionType == ActionCommand.ActionType.SimpleAttack) { return handleUnitCommand(entity, command); } return false; }
/// <summary> /// Given an Entity and an ActionCommand, this function will attempt to give the Entity the ActionCommand /// </summary> /// <param name="entity"></param> /// <param name="command"></param> /// <returns>false if the command was rejected, true if the command was accepted.</returns> public bool giveActionCommand(Entity entity, ActionCommand command) { return actionController.giveCommand(entity, command); }
/// <summary> /// This function will insert a command at the beginning of an Entity's action queue. This will interrupt the action currently /// being performed (if any) by the entity. /// </summary> /// <param name="entity"></param> /// <param name="command"></param> public static void insertIntoActionQueue(Entity entity, ActionCommand command) { entity.getActionQueue().Insert(0, command); }