/* * ------------------------------------------------------------------------- * MARK: PARTY MEMBER MOVE SERVICE FUNCTIONS * ------------------------------------------------------------------------- */ /* * Handles construction of move map. * Performed each time a unit attempts to move. */ public bool ConstructMoveMap(Vector3 unitPosition, int movement, Utils.EntityType entityType) { Assert.IsTrue(movement >= 1); bool hasValidMove = false; Queue <Node> toVisit = new Queue <Node>(); Node rootNode = GetNodeByPosition(unitPosition); rootNode.moveVisited = true; if (IsPartyMember(entityType)) { rootNode.moveColor = Utils.TileColor.OccupiedByParty; } toVisit.Enqueue(rootNode); while (toVisit.Count > 0) { Node curr = toVisit.Dequeue(); foreach (Node directionalNode in curr.GetDirectionalNodes()) { if (!directionalNode.moveVisited && IsValidMove(directionalNode) && curr.moveDepth == movement - 1) { MarkMoveNode(curr, directionalNode); hasValidMove = true; } else if (!directionalNode.moveVisited && (IsValidMove(directionalNode) || IsSameEntityType(directionalNode, entityType)) && curr.moveDepth < movement - 1) { MarkMoveNode(curr, directionalNode); toVisit.Enqueue(directionalNode); hasValidMove = true; } else if (!directionalNode.moveVisited && IsPartyMember(entityType)) { MarkMoveNode(curr, directionalNode); } } } return(hasValidMove); }
// Check if entity type is enemy unit. bool IsEnemyUnit(Utils.EntityType entityType) { return(entityType == Utils.EntityType.EnemyUnit); }
// Check if entity type is party member. bool IsPartyMember(Utils.EntityType entityType) { return(entityType == Utils.EntityType.PartyMember); }
// Checks if tile is occupied by party member. bool IsSameEntityType(Node node, Utils.EntityType entityType) { return(node.tileController.occupyingEntity != EntityController.Empty && node.tileController.occupyingEntity.EntityType == entityType); }
/* * ------------------------------------------------------------------------- * MARK: PARTY MEMBER ATTACK SERVICE FUNCTIONS * ------------------------------------------------------------------------- */ /* * Handles construction of attack map. * Performed each time a unit attempts to attack. */ public bool ConstructAttackMap(Vector3 unitPosition, int minRange, int maxRange, Utils.EntityType entityType) { Assert.IsTrue(minRange >= 1 && minRange <= maxRange); bool hasValidAttack = false; Queue <Node> toVisit = new Queue <Node>(); Node rootNode = GetNodeByPosition(unitPosition); rootNode.attackVisited = true; toVisit.Enqueue(rootNode); while (toVisit.Count > 0) { Node curr = toVisit.Dequeue(); foreach (Node directionalNode in curr.GetDirectionalNodes()) { if (!directionalNode.attackVisited && curr.attackDepth < minRange - 1) { MarkAttackNode(curr, directionalNode); if (IsNotBlocked(directionalNode)) { toVisit.Enqueue(directionalNode); } } else if (!directionalNode.attackVisited && curr.attackDepth >= minRange - 1 && curr.attackDepth < maxRange - 1) { MarkAttackNode(curr, directionalNode); if (directionalNode.tileController.occupyingEntity == EntityController.Empty) { toVisit.Enqueue(directionalNode); } else { switch (directionalNode.tileController.occupyingEntity.EntityType) { case Utils.EntityType.PartyMember: toVisit.Enqueue(directionalNode); break; case Utils.EntityType.EnemyUnit: toVisit.Enqueue(directionalNode); hasValidAttack = true; break; case Utils.EntityType.Obstacle: default: break; } } } else if (!directionalNode.attackVisited && curr.attackDepth == maxRange - 1) { MarkAttackNode(curr, directionalNode); if (directionalNode.tileController.occupyingEntity != EntityController.Empty && IsEnemyUnit(directionalNode.tileController.occupyingEntity.EntityType)) { hasValidAttack = true; } } } } return(hasValidAttack); }