526 |
526 |
527 return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16; |
527 return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16; |
528 } |
528 } |
529 |
529 |
530 case 0x42: { // Consist cargo information |
530 case 0x42: { // Consist cargo information |
531 /* XXX Missing support for common refit cycle and property 25 */ |
|
532 const Vehicle *u; |
531 const Vehicle *u; |
533 byte cargo_classes = 0; |
532 byte cargo_classes = 0; |
534 uint common_cargo_best = 0; |
533 uint8 common_cargo_best = 0; |
535 uint common_cargos[NUM_CARGO]; |
534 uint8 common_cargos[NUM_CARGO]; |
|
535 uint8 common_subtype_best = 0; |
|
536 uint8 common_subtypes[256]; |
536 byte user_def_data = 0; |
537 byte user_def_data = 0; |
537 CargoID common_cargo_type = CT_PASSENGERS; |
538 CargoID common_cargo_type = CT_PASSENGERS; |
|
539 uint8 common_subtype = 0; |
538 |
540 |
539 /* Reset our arrays */ |
541 /* Reset our arrays */ |
540 memset(common_cargos, 0, sizeof(common_cargos)); |
542 memset(common_cargos, 0, sizeof(common_cargos)); |
|
543 memset(common_subtypes, 0, sizeof(common_subtypes)); |
541 |
544 |
542 for (u = v; u != NULL; u = u->next) { |
545 for (u = v; u != NULL; u = u->next) { |
543 /* Skip empty engines */ |
546 /* Skip empty engines */ |
544 if (u->cargo_cap == 0) continue; |
547 if (u->cargo_cap == 0) continue; |
545 |
548 |
546 cargo_classes |= GetCargo(u->cargo_type)->classes; |
549 cargo_classes |= GetCargo(u->cargo_type)->classes; |
547 common_cargos[u->cargo_type]++; |
550 common_cargos[u->cargo_type]++; |
548 user_def_data |= RailVehInfo(u->engine_type)->user_def_data; |
551 user_def_data |= RailVehInfo(u->engine_type)->user_def_data; |
|
552 common_subtypes[u->cargo_subtype]++; |
549 } |
553 } |
550 |
554 |
551 /* Pick the most common cargo type */ |
555 /* Pick the most common cargo type */ |
552 for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) { |
556 for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) { |
553 if (common_cargos[cargo] > common_cargo_best) { |
557 if (common_cargos[cargo] > common_cargo_best) { |
554 common_cargo_best = common_cargos[cargo]; |
558 common_cargo_best = common_cargos[cargo]; |
555 common_cargo_type = GetCargo(cargo)->bitnum; |
559 common_cargo_type = GetCargo(cargo)->bitnum; |
556 } |
560 } |
557 } |
561 } |
558 |
562 |
559 return cargo_classes | (common_cargo_type << 8) | (user_def_data << 24); |
563 for (uint i = 0; i < lengthof(common_subtypes); i++) { |
|
564 if (common_subtypes[i] > common_subtype_best) { |
|
565 common_subtype_best = common_subtypes[i]; |
|
566 common_subtype = i; |
|
567 } |
|
568 } |
|
569 |
|
570 return cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24); |
560 } |
571 } |
561 |
572 |
562 case 0x43: // Player information |
573 case 0x43: // Player information |
563 return v->owner | (GetPlayer(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24); |
574 return v->owner | (GetPlayer(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24); |
564 |
575 |