MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / alienMovement

Method alienMovement

game/state/city/building.cpp:884–973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

882}
883
884void Building::alienMovement(GameState &state)
885{
886 if (!hasAliens())
887 {
888 return;
889 }
890 // Run once when crew landed and once every hour after grow
891 // Pick 15 intact buildings within range of 15 tiles (counting from center to center)
892 std::list<StateRef<Building>> neighbours;
893 for (auto &b : city->buildings)
894 {
895 auto distVec = bounds.p0 + bounds.p1 - b.second->bounds.p0 - b.second->bounds.p1;
896 distVec /= 2;
897 int distance = std::abs(distVec.x) + std::abs(distVec.y);
898 if (distance > 0 && distance <= 15)
899 {
900 neighbours.emplace_back(&state, b.first);
901 }
902 if (neighbours.size() >= 15)
903 {
904 break;
905 }
906 }
907 if (neighbours.empty())
908 {
909 return;
910 }
911 // Pick one random of them
912 auto bld = pickRandom(state.rng, neighbours);
913 // For every alien calculate move percent as:
914 // alien's move chance + random 0..30
915 // Calculate amount of moving aliens
916 std::map<StateRef<AgentType>, int> moveAmounts;
917 int totalMoveAmount = 0;
918 for (auto &e : current_crew)
919 {
920 if (e.second == 0)
921 {
922 continue;
923 }
924 int movePercent =
925 std::min(100, e.first->movementPercent + randBoundsInclusive(state.rng, 0, 30));
926 int moveAmount = e.second * movePercent / 100;
927 if (moveAmount > 0)
928 {
929 moveAmounts[e.first] = moveAmount;
930 totalMoveAmount += moveAmount;
931 }
932 }
933 if (totalMoveAmount == 0)
934 {
935 return;
936 }
937 // Chance to move is:
938 // 15 + 3 * amount + 20 (if owner is friendly+ to aliens)
939 int friendlyBonus = 0;
940 switch (bld->owner->isRelatedTo(state.getAliens()))
941 {

Callers 1

startMethod · 0.80

Calls 8

pickRandomFunction · 0.85
randBoundsInclusiveFunction · 0.85
emptyMethod · 0.80
isRelatedToMethod · 0.80
getAliensMethod · 0.80
pushEventMethod · 0.80
sizeMethod · 0.45
dieMethod · 0.45

Tested by

no test coverage detected