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

Method detect

game/state/city/building.cpp:754–829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

752}
753
754void Building::detect(GameState &state, bool forced)
755{
756 if (ticksDetectionTimeOut > 0)
757 {
758 return;
759 }
760 if (!forced)
761 {
762 bool alien_spotted = false;
763 int detectionValue = 0;
764 for (auto &pair : current_crew)
765 {
766 if (pair.second == 0)
767 {
768 continue;
769 }
770 if (randBoundsExclusive(state.rng, 0, 100) < 100 / (pair.second + 1))
771 {
772 alien_spotted = true;
773 }
774 detectionValue += pair.first->detectionWeight * pair.second;
775 }
776 if (!alien_spotted)
777 {
778 return;
779 }
780 detectionValue *= function->detectionWeight - 2 * state.difficulty;
781 detectionValue /= 100;
782 if (owner->isRelatedTo(state.getAliens()) == Organisation::Relation::Allied)
783 {
784 detectionValue /= 2;
785 }
786 if (owner->isRelatedTo(state.getPlayer()) == Organisation::Relation::Hostile)
787 {
788 detectionValue /= 2;
789 }
790 if (owner->takenOver)
791 {
792 detectionValue /= 2;
793 }
794 if (randBoundsExclusive(state.rng, 0, 100) >= detectionValue - 10)
795 {
796 return;
797 }
798 }
799 else
800 {
801 bool alien_spotted = false;
802 for (auto &pair : current_crew)
803 {
804 if (pair.second == 0)
805 {
806 continue;
807 }
808 alien_spotted = true;
809 break;
810 }
811 if (!alien_spotted)

Callers

nothing calls this directly

Calls 5

randBoundsExclusiveFunction · 0.85
isRelatedToMethod · 0.80
getAliensMethod · 0.80
getPlayerMethod · 0.80
pushEventMethod · 0.80

Tested by

no test coverage detected