| 67 | } |
| 68 | |
| 69 | Organisation::PurchaseResult |
| 70 | Organisation::canPurchaseFrom(GameState &state, const StateRef<Building> &buyer, bool vehicle) const |
| 71 | { |
| 72 | // Step 01: Check if org likes buyer |
| 73 | if (isRelatedTo(buyer->owner) == Relation::Hostile) |
| 74 | { |
| 75 | return PurchaseResult::OrgHostile; |
| 76 | } |
| 77 | // Step 02: Check if org has buildings in buyer's city |
| 78 | if (!getPurchaseBuilding(state, buyer)) |
| 79 | { |
| 80 | return PurchaseResult::OrgHasNoBuildings; |
| 81 | } |
| 82 | // Step 03: Checks for cargo delivery |
| 83 | if (!vehicle) |
| 84 | { |
| 85 | // Step 03.01: Find out who provides transportation services |
| 86 | std::list<StateRef<Organisation>> ferryCompanies; |
| 87 | for (auto &o : state.organisations) |
| 88 | { |
| 89 | if (o.second->providesTransportationServices) |
| 90 | { |
| 91 | ferryCompanies.emplace_back(&state, o.first); |
| 92 | } |
| 93 | } |
| 94 | // Step 03.02: Check if a ferry provider exists that likes us both |
| 95 | if (config().getBool("OpenApoc.NewFeature.FerryChecksRelationshipWhenBuying")) |
| 96 | { |
| 97 | // Clear those that don't like either |
| 98 | for (auto it = ferryCompanies.begin(); it != ferryCompanies.end();) |
| 99 | { |
| 100 | if ((*it)->isRelatedTo({&state, id}) == Relation::Hostile || |
| 101 | (*it)->isRelatedTo(buyer->owner) == Relation::Hostile) |
| 102 | { |
| 103 | it = ferryCompanies.erase(it); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | it++; |
| 108 | } |
| 109 | } |
| 110 | if (ferryCompanies.empty()) |
| 111 | { |
| 112 | return PurchaseResult::TranportHostile; |
| 113 | } |
| 114 | } |
| 115 | // Step 03.03: Check if ferry provider has free ferries |
| 116 | if (config().getBool("OpenApoc.NewFeature.CallExistingFerry")) |
| 117 | { |
| 118 | bool ferryFound = false; |
| 119 | for (auto &o : ferryCompanies) |
| 120 | { |
| 121 | for (auto &v : state.vehicles) |
| 122 | { |
| 123 | if (v.second->owner != o || !v.second->type->provideFreightCargo || |
| 124 | !v.second->missions.empty()) |
| 125 | { |
| 126 | continue; |
no test coverage detected