本文整理汇总了C++中Vehicle::GetEngine方法的典型用法代码示例。如果您正苦于以下问题:C++ Vehicle::GetEngine方法的具体用法?C++ Vehicle::GetEngine怎么用?C++ Vehicle::GetEngine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vehicle
的用法示例。
在下文中一共展示了Vehicle::GetEngine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CmdCloneVehicle
//.........这里部分代码省略.........
if (result.Failed()) {
/* The train can't be joined to make the same consist as the original.
* Sell what we already made (clean up) and return an error. */
DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
DoCommand(w_front->tile, w->index | 1 << 20, 0, flags, GetCmdSellVeh(w));
return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
}
} else {
/* this is a front engine or not a train. */
w_front = w;
w->service_interval = v->service_interval;
w->SetServiceIntervalIsCustom(v->ServiceIntervalIsCustom());
w->SetServiceIntervalIsPercent(v->ServiceIntervalIsPercent());
}
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
}
} while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != NULL);
if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) {
/* for trains this needs to be the front engine due to the callback function */
_new_vehicle_id = w_front->index;
}
if (flags & DC_EXEC) {
/* Cloned vehicles belong to the same group */
DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP);
}
/* Take care of refitting. */
w = w_front;
v = v_front;
/* Both building and refitting are influenced by newgrf callbacks, which
* makes it impossible to accurately estimate the cloning costs. In
* particular, it is possible for engines of the same type to be built with
* different numbers of articulated parts, so when refitting we have to
* loop over real vehicles first, and then the articulated parts of those
* vehicles in a different loop. */
do {
do {
if (flags & DC_EXEC) {
assert(w != NULL);
/* Find out what's the best sub type */
byte subtype = GetBestFittingSubType(v, w, v->cargo_type);
if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
CommandCost cost = DoCommand(0, w->index, v->cargo_type | 1U << 7 | (subtype << 8), flags, GetCmdRefitVeh(v));
if (cost.Succeeded()) total_cost.AddCost(cost);
}
if (w->IsGroundVehicle() && w->HasArticulatedPart()) {
w = w->GetNextArticulatedPart();
} else {
break;
}
} else {
const Engine *e = v->GetEngine();
CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) {
bool dummy;
total_cost.AddCost(GetRefitCost(NULL, v->engine_type, v->cargo_type, v->cargo_subtype, &dummy));
}
}
if (v->IsGroundVehicle() && v->HasArticulatedPart()) {
v = v->GetNextArticulatedPart();
} else {
break;
}
} while (v != NULL);
if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = w->GetNextVehicle();
} while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != NULL);
if (flags & DC_EXEC) {
/*
* Set the orders of the vehicle. Cannot do it earlier as we need
* the vehicle refitted before doing this, otherwise the moved
* cargo types might not match (passenger vs non-passenger)
*/
DoCommand(0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index, flags, CMD_CLONE_ORDER);
/* Now clone the vehicle's name, if it has one. */
if (v_front->name != NULL) CloneVehicleName(v_front, w_front);
}
/* Since we can't estimate the cost of cloning a vehicle accurately we must
* check whether the company has enough money manually. */
if (!CheckCompanyHasMoney(total_cost)) {
if (flags & DC_EXEC) {
/* The vehicle has already been bought, so now it must be sold again. */
DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
}
return total_cost;
}
return total_cost;
}