* Finds a fitting node where a unit can spawn. * @param nodeRank Rank of the node (this is not the rank of the alien!). * @param unit Pointer to the unit (to get its position). * @return Pointer to the chosen node. */
| 1095 | * @return Pointer to the chosen node. |
| 1096 | */ |
| 1097 | Node *SavedBattleGame::getSpawnNode(int nodeRank, BattleUnit *unit) |
| 1098 | { |
| 1099 | int highestPriority = -1; |
| 1100 | std::vector<Node*> compliantNodes; |
| 1101 | |
| 1102 | for (std::vector<Node*>::iterator i = getNodes()->begin(); i != getNodes()->end(); ++i) |
| 1103 | { |
| 1104 | if ((*i)->getRank() == nodeRank // ranks must match |
| 1105 | && (!((*i)->getType() & Node::TYPE_SMALL) |
| 1106 | || unit->getArmor()->getSize() == 1) // the small unit bit is not set or the unit is small |
| 1107 | && (!((*i)->getType() & Node::TYPE_FLYING) |
| 1108 | || unit->getArmor()->getMovementType() == MT_FLY)// the flying unit bit is not set or the unit can fly |
| 1109 | && (*i)->getPriority() > 0 // priority 0 is no spawnplace |
| 1110 | && setUnitPosition(unit, (*i)->getPosition(), true)) // check if not already occupied |
| 1111 | { |
| 1112 | if ((*i)->getPriority() > highestPriority) |
| 1113 | { |
| 1114 | highestPriority = (*i)->getPriority(); |
| 1115 | compliantNodes.clear(); // drop the last nodes, as we found a higher priority now |
| 1116 | } |
| 1117 | if ((*i)->getPriority() == highestPriority) |
| 1118 | { |
| 1119 | compliantNodes.push_back((*i)); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | if (compliantNodes.empty()) return 0; |
| 1125 | |
| 1126 | int n = RNG::generate(0, compliantNodes.size() - 1); |
| 1127 | |
| 1128 | return compliantNodes[n]; |
| 1129 | } |
| 1130 | |
| 1131 | /** |
| 1132 | * Finds a fitting node where a unit can patrol to. |
no test coverage detected