/// <summary> /// Given an entity, this function will cause the entity to perform whatever action is currently on the entity's /// action queue. /// </summary> /// <param name="entity"></param> public void update(Entity entity, EntityLocController locController) { Queue<ActionCommand> actionQueue = entity.getActionQueue(); if(actionQueue.Count > 0) { ActionCommand command = actionQueue.Peek(); if (command.work()) { actionQueue.Dequeue(); } if (entity.entityType == Entity.EntityType.Unit) { locController.updateUnitLocation((Unit)entity); } } }
/// <summary> /// Given an entity, this function will cause the entity to perform whatever action is currently on the entity's /// action queue. /// </summary> /// <param name="entity"></param> public void update(Entity entity, EntityLocController locController) { List<ActionCommand> actionQueue = entity.getActionQueue(); if(actionQueue.Count > 0) { ActionCommand command = actionQueue[0]; if (command.work()) { // Action is done, remove and set Entity's state to idle. actionQueue.RemoveAt(0); entity.getState().setPrimaryState(State.PrimaryState.Idle); } if (entity.entityType == Entity.EntityType.Unit) { // Unit may have moved, update it's location in the GameWorld. locController.updateUnitLocation((Unit)entity); } } }
/// <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); }
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. List<ActionCommand> queue = entity.getActionQueue(); queue.Clear(); // Give the entity the command. entity.getActionQueue().Add(command); return true; }
/// <summary> /// This function will determine if an entity can be "interrupted" with a new Action. /// </summary> /// <param name="entity"></param> /// <returns></returns> private static bool isInterruptable(Entity entity) { if (entity.getActionQueue().Count == 0) { return true; } return false; }