1
0
Fork 0

Add: Variable to test how many vehicles in a chain contain a specific badge. (#13594)

pull/13662/head
Peter Nelson 2025-02-25 20:55:11 +00:00 committed by GitHub
parent ae72e15951
commit a8f56fe7b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 0 deletions

View File

@ -692,6 +692,23 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
default: return 0x00;
}
case 0x64: { // Count consist's badge ID occurrence
if (v->type != VEH_TRAIN) return GetBadgeVariableResult(*object->ro.grffile, v->GetEngine()->badges, parameter);
/* Look up badge index. */
if (parameter >= std::size(object->ro.grffile->badge_list)) return UINT_MAX;
BadgeID index = object->ro.grffile->badge_list[parameter];
/* Count number of vehicles that contain this badge index. */
uint count = 0;
for (; v != nullptr; v = v->Next()) {
const auto &badges = v->GetEngine()->badges;
if (std::ranges::find(badges, index) != std::end(badges)) count++;
}
return count;
}
case 0x7A: return GetBadgeVariableResult(*object->ro.grffile, v->GetEngine()->badges, parameter);
case 0xFE: