| 251 | } |
| 252 | |
| 253 | void ScriptExt::LoadIntoTransports(TeamClass* pTeam) |
| 254 | { |
| 255 | std::vector<FootClass*> transports; |
| 256 | |
| 257 | // Collect available transports |
| 258 | for (auto pUnit = pTeam->FirstUnit; pUnit; pUnit = pUnit->NextTeamMember) |
| 259 | { |
| 260 | auto const pType = pUnit->GetTechnoType(); |
| 261 | |
| 262 | if (pType->Passengers > 0 |
| 263 | && pUnit->Passengers.NumPassengers < pType->Passengers |
| 264 | && pUnit->Passengers.GetTotalSize() < pType->Passengers) |
| 265 | { |
| 266 | transports.emplace_back(pUnit); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | if (transports.size() == 0) |
| 271 | { |
| 272 | // This action finished |
| 273 | pTeam->StepCompleted = true; |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | // Now load units into transports |
| 278 | for (auto pTransport : transports) |
| 279 | { |
| 280 | for (auto pUnit = pTeam->FirstUnit; pUnit; pUnit = pUnit->NextTeamMember) |
| 281 | { |
| 282 | auto const pTransportType = pTransport->GetTechnoType(); |
| 283 | auto const pUnitType = pUnit->GetTechnoType(); |
| 284 | |
| 285 | if (pTransport != pUnit |
| 286 | && pUnitType->WhatAmI() != AbstractType::AircraftType |
| 287 | && !pUnit->InLimbo && !pUnitType->ConsideredAircraft |
| 288 | && pUnit->Health > 0) |
| 289 | { |
| 290 | if (pUnitType->Size > 0 |
| 291 | && pUnitType->Size <= pTransportType->SizeLimit |
| 292 | && pUnitType->Size <= pTransportType->Passengers - pTransport->Passengers.GetTotalSize()) |
| 293 | { |
| 294 | // If is still flying wait a bit more |
| 295 | if (pTransport->IsInAir()) |
| 296 | return; |
| 297 | |
| 298 | // All fine |
| 299 | if (pUnit->GetCurrentMission() != Mission::Enter) |
| 300 | { |
| 301 | pUnit->QueueMission(Mission::Enter, false); |
| 302 | pUnit->SetTarget(nullptr); |
| 303 | pUnit->SetDestination(pTransport, true); |
| 304 | |
| 305 | return; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
nothing calls this directly
no test coverage detected