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

Method _SetOrderFlags

src/script/api/script_order.cpp:587–643  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

585}
586
587/* static */ bool ScriptOrder::_SetOrderFlags()
588{
589 /* Make sure we don't go into an infinite loop */
590 int retry = ScriptObject::GetCallbackVariable(3) - 1;
591 if (retry < 0) {
592 Debug(script, 0, "Possible infinite loop in SetOrderFlags() detected");
593 return false;
594 }
595 ScriptObject::SetCallbackVariable(3, retry);
596
597 VehicleID vehicle_id = (VehicleID)ScriptObject::GetCallbackVariable(0);
598 OrderPosition order_position = (OrderPosition)ScriptObject::GetCallbackVariable(1);
599 ScriptOrderFlags order_flags = (ScriptOrderFlags)ScriptObject::GetCallbackVariable(2);
600
601 order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
602
603 EnforceCompanyModeValid(false);
604 EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
605 EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags));
606
607 const Order *order = ::ResolveOrder(vehicle_id, order_position);
608 int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
609
610 ScriptOrderFlags current = GetOrderFlags(vehicle_id, order_position);
611
612 EnforcePrecondition(false, (order_flags & OF_GOTO_NEAREST_DEPOT) == (current & OF_GOTO_NEAREST_DEPOT));
613
614 if ((current & OF_NON_STOP_FLAGS) != (order_flags & OF_NON_STOP_FLAGS)) {
615 return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_NON_STOP, order_flags & OF_NON_STOP_FLAGS);
616 }
617
618 switch (order->GetType()) {
619 case OT_GOTO_DEPOT:
620 if ((current & OF_DEPOT_FLAGS) != (order_flags & OF_DEPOT_FLAGS)) {
621 OrderDepotAction data = OrderDepotAction::AlwaysGo;
622 if ((order_flags & OF_SERVICE_IF_NEEDED) != 0) data = OrderDepotAction::Service;
623 if ((order_flags & OF_STOP_IN_DEPOT) != 0) data = OrderDepotAction::Stop;
624 return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_DEPOT_ACTION, to_underlying(data));
625 }
626 break;
627
628 case OT_GOTO_STATION:
629 if ((current & OF_UNLOAD_FLAGS) != (order_flags & OF_UNLOAD_FLAGS)) {
630 return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_UNLOAD, (order_flags & OF_UNLOAD_FLAGS) >> 2);
631 }
632 if ((current & OF_LOAD_FLAGS) != (order_flags & OF_LOAD_FLAGS)) {
633 return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_LOAD, (order_flags & OF_LOAD_FLAGS) >> 5);
634 }
635 break;
636
637 default: break;
638 }
639
640 assert(GetOrderFlags(vehicle_id, order_position) == order_flags);
641
642 return true;
643}
644

Callers

nothing calls this directly

Calls 4

ResolveOrderFunction · 0.85
to_underlyingFunction · 0.85
GetTypeMethod · 0.45

Tested by

no test coverage detected