1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-09-01 19:09:09 +00:00

(svn r21924) -Codechange: Unify some parts of the articulated vehicle code.

-Cleanup: Avoid conversions to Train and RoadVehicle that are no longer required.
This commit is contained in:
terkhen
2011-01-29 17:30:25 +00:00
parent 50b0e10026
commit 734994c9ba
9 changed files with 26 additions and 56 deletions

View File

@@ -101,18 +101,18 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
assert(!part_of_chain || new_head->IsPrimaryVehicle());
/* Loop through source parts */
for (Vehicle *src = old_veh; src != NULL; src = src->Next()) {
if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !Train::From(src)->IsArticulatedPart()) {
if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !src->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to old_veh */
src = Train::From(src)->GetLastEnginePart();
src = src->GetLastEnginePart();
continue;
}
if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue;
/* Find free space in the new chain */
for (Vehicle *dest = new_head; dest != NULL && src->cargo.Count() > 0; dest = dest->Next()) {
if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !Train::From(dest)->IsArticulatedPart()) {
if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !dest->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to new_head */
dest = Train::From(dest)->GetLastEnginePart();
dest = dest->GetLastEnginePart();
continue;
}
if (dest->cargo_type != src->cargo_type) continue;
@@ -218,7 +218,7 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool
*/
static EngineID GetNewEngineType(const Vehicle *v, const Company *c)
{
assert(v->type != VEH_TRAIN || !Train::From(v)->IsArticulatedPart());
assert(v->type != VEH_TRAIN || !v->IsArticulatedPart());
if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) {
/* we build the rear ends of multiheaded trains with the front ones */