diff --git a/src/core/bitmath_func.cpp b/src/core/bitmath_func.cpp index 7763227315..5f3484f964 100644 --- a/src/core/bitmath_func.cpp +++ b/src/core/bitmath_func.cpp @@ -53,6 +53,13 @@ uint8 FindFirstBit(uint32 x) return pos; } +uint8 FindFirstBit64(uint64 x) +{ + if (x == 0) return 0; + if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit(x); + return FindFirstBit(x >> 32) + 32; +} + /** * Search the last set bit in a 64 bit variable. * diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 86512e6141..9aa1639e35 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -630,8 +630,8 @@ void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueTyp break; case TRVT_CARGO_ID: - assert(_sorted_standard_cargo_specs_size > 0); - SetTraceRestrictValue(item, _sorted_cargo_specs[0]->Index()); + assert(_standard_cargo_mask != 0); + SetTraceRestrictValue(item, FindFirstBit64(_standard_cargo_mask)); SetTraceRestrictAuxField(item, 0); break;