MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AreOrderFlagsValid

Method AreOrderFlagsValid

src/script/api/script_order.cpp:193–213  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

191
192
193/* static */ bool ScriptOrder::AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags)
194{
195 OrderType ot = (order_flags & OF_GOTO_NEAREST_DEPOT) ? OT_GOTO_DEPOT : ::GetOrderTypeByTile(destination);
196 switch (ot) {
197 case OT_GOTO_STATION:
198 return (order_flags & ~(OF_NON_STOP_FLAGS | OF_UNLOAD_FLAGS | OF_LOAD_FLAGS)) == 0 &&
199 /* Test the different mutual exclusive flags. */
200 HasAtMostOneBit(order_flags & (OF_TRANSFER | OF_UNLOAD | OF_NO_UNLOAD)) &&
201 HasAtMostOneBit(order_flags & (OF_NO_UNLOAD | OF_NO_LOAD)) &&
202 HasAtMostOneBit(order_flags & (OF_FULL_LOAD | OF_NO_LOAD)) &&
203 /* "Full load any" is "Full load" plus a bit. On its own that bit is invalid. */
204 ((order_flags & OF_FULL_LOAD_ANY) != (OF_FULL_LOAD_ANY & ~OF_FULL_LOAD));
205
206 case OT_GOTO_DEPOT:
207 return (order_flags & ~(OF_NON_STOP_FLAGS | OF_DEPOT_FLAGS)) == 0 &&
208 ((order_flags & OF_SERVICE_IF_NEEDED) == 0 || (order_flags & OF_STOP_IN_DEPOT) == 0);
209
210 case OT_GOTO_WAYPOINT: return (order_flags & ~(OF_NON_STOP_FLAGS)) == 0;
211 default: return false;
212 }
213}
214
215/* static */ bool ScriptOrder::IsValidConditionalOrder(OrderCondition condition, CompareFunction compare)
216{

Callers

nothing calls this directly

Calls 2

GetOrderTypeByTileFunction · 0.85
HasAtMostOneBitFunction · 0.85

Tested by

no test coverage detected