MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / getSpawnNode

Method getSpawnNode

src/Savegame/SavedBattleGame.cpp:1097–1129  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1095 * @return Pointer to the chosen node.
1096 */
1097Node *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.

Callers 4

nextStageMethod · 0.80
addXCOMUnitMethod · 0.80
addAlienMethod · 0.80
addCivilianMethod · 0.80

Calls 10

generateFunction · 0.85
getMovementTypeMethod · 0.80
getPriorityMethod · 0.80
getRankMethod · 0.45
getTypeMethod · 0.45
getSizeMethod · 0.45
getArmorMethod · 0.45
getPositionMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected