| 171 | } |
| 172 | |
| 173 | void Organisation::purchase(GameState &state, const StateRef<Building> &buyer, |
| 174 | StateRef<VEquipmentType> vehicleEquipment, int count) |
| 175 | { |
| 176 | int price = 0; |
| 177 | if (state.economy.find(vehicleEquipment.id) == state.economy.end()) |
| 178 | { |
| 179 | LogError("Economy not found for %s: How are we buying it then!?", vehicleEquipment.id); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | auto &economy = state.economy[vehicleEquipment.id]; |
| 184 | price = economy.currentPrice; |
| 185 | if (buyer->owner == state.getPlayer()) |
| 186 | { |
| 187 | economy.currentStock -= count; |
| 188 | if (economy.currentStock < 0) |
| 189 | { |
| 190 | LogInfo("Economy went into negative stock for %s: Was it because we used economy " |
| 191 | "to transfer?", |
| 192 | vehicleEquipment.id); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Expecting to be able to purchase |
| 198 | auto building = buyer->owner->id == id ? buyer : getPurchaseBuilding(state, buyer); |
| 199 | building->cargo.emplace_back(state, vehicleEquipment, count, price, |
| 200 | StateRef<Organisation>{&state, id}, buyer); |
| 201 | LogWarning("PURCHASE: %s bought %dx%s at %s to %s ", buyer->owner.id, count, |
| 202 | vehicleEquipment.id, building.id, buyer.id); |
| 203 | auto owner = buyer->owner; |
| 204 | owner->balance -= count * price; |
| 205 | } |
| 206 | |
| 207 | void Organisation::purchase(GameState &state, const StateRef<Building> &buyer, |
| 208 | StateRef<VAmmoType> vehicleAmmo, int count) |
no test coverage detected