本文整理汇总了C++中Vehicle::GetLastEnginePart方法的典型用法代码示例。如果您正苦于以下问题:C++ Vehicle::GetLastEnginePart方法的具体用法?C++ Vehicle::GetLastEnginePart怎么用?C++ Vehicle::GetLastEnginePart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vehicle
的用法示例。
在下文中一共展示了Vehicle::GetLastEnginePart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TransferCargo
/**
* Transfer cargo from a single (articulated )old vehicle to the new vehicle chain
* @param old_veh Old vehicle that will be sold
* @param new_head Head of the completely constructed new vehicle chain
* @param part_of_chain The vehicle is part of a train
*/
static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chain)
{
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 && !src->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to old_veh */
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 && !dest->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to new_head */
dest = dest->GetLastEnginePart();
continue;
}
if (dest->cargo_type != src->cargo_type) continue;
uint amount = min(src->cargo.Count(), dest->cargo_cap - dest->cargo.Count());
if (amount <= 0) continue;
src->cargo.MoveTo(&dest->cargo, amount, VehicleCargoList::MTA_UNLOAD, NULL);
}
}
/* Update train weight etc., the old vehicle will be sold anyway */
if (part_of_chain && new_head->type == VEH_TRAIN) Train::From(new_head)->ConsistChanged(true);
}