0x004B9A88
| 3097 | |
| 3098 | // 0x004B9A88 |
| 3099 | bool VehicleHead::updateUnloadCargoComponent(VehicleCargo& cargo, VehicleBogie* bogie) |
| 3100 | { |
| 3101 | if (cargo.qty == 0) |
| 3102 | { |
| 3103 | return false; |
| 3104 | } |
| 3105 | |
| 3106 | if (stationId == StationId::null) |
| 3107 | { |
| 3108 | return false; |
| 3109 | } |
| 3110 | |
| 3111 | auto* station = StationManager::get(stationId); |
| 3112 | auto& cargoStats = station->cargoStats[cargo.type]; |
| 3113 | if (cargoStats.isAccepted()) |
| 3114 | { |
| 3115 | station->deliverCargoToTown(cargo.type, cargo.qty); |
| 3116 | auto* sourceStation = StationManager::get(cargo.townFrom); |
| 3117 | auto stationLoc = World::Pos2{ station->x, station->y }; |
| 3118 | auto sourceLoc = World::Pos2{ sourceStation->x, sourceStation->y }; |
| 3119 | auto tilesDistance = Math::Vector::distance2D(stationLoc, sourceLoc) / 32; |
| 3120 | |
| 3121 | Ui::WindowManager::invalidate(Ui::WindowType::company, enumValue(owner)); |
| 3122 | auto* company = CompanyManager::get(owner); |
| 3123 | company->cargoUnitsTotalDelivered += cargo.qty; |
| 3124 | |
| 3125 | auto cargoDist = static_cast<uint32_t>(std::min<uint64_t>(static_cast<uint64_t>(cargo.qty) * tilesDistance, std::numeric_limits<uint32_t>::max())); |
| 3126 | company->cargoUnitsTotalDistance += cargoDist; |
| 3127 | |
| 3128 | auto cargoPayment = CompanyManager::calculateDeliveredCargoPayment(cargo.type, cargo.qty, tilesDistance, cargo.numDays); |
| 3129 | company->cargoDelivered[cargo.type] = Math::Bound::add(company->cargoDelivered[cargo.type], cargo.qty); |
| 3130 | |
| 3131 | updateLastIncomeStats(cargo.type, cargo.qty, tilesDistance, cargo.numDays, cargoPayment); |
| 3132 | |
| 3133 | var_58 += cargoPayment; |
| 3134 | station->var_3B1 = 0; |
| 3135 | station->flags |= StationFlags::flag_8; |
| 3136 | |
| 3137 | if (cargoStats.industryId != IndustryId::null) |
| 3138 | { |
| 3139 | auto* industry = IndustryManager::get(cargoStats.industryId); |
| 3140 | const auto* industryObj = industry->getObject(); |
| 3141 | |
| 3142 | for (auto i = 0; i < 3; ++i) |
| 3143 | { |
| 3144 | if (industryObj->requiredCargoType[i] != cargo.type) |
| 3145 | { |
| 3146 | continue; |
| 3147 | } |
| 3148 | |
| 3149 | industry->receivedCargoQuantityDailyTotal[i] = Math::Bound::add(industry->receivedCargoQuantityDailyTotal[i], cargo.qty); |
| 3150 | industry->receivedCargoQuantityMonthlyTotal[i] = Math::Bound::add(industry->receivedCargoQuantityMonthlyTotal[i], cargo.qty); |
| 3151 | } |
| 3152 | |
| 3153 | if (!(industry->history_min_production[0] & (1ULL << cargo.type))) |
| 3154 | { |
| 3155 | industry->history_min_production[0] |= 1ULL << cargo.type; |
| 3156 | MessageManager::post(MessageType::workersCelebrate, owner, enumValue(id), enumValue(cargoStats.industryId), enumValue(cargoStats.industryId) | (cargo.type << 8)); |
nothing calls this directly
no test coverage detected