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

Function ProcessNewGRFStringControlCode

src/newgrf_text.cpp:764–870  ·  view source on GitHub ↗

* Process NewGRF string control code instructions. * @param scc The string control code that has been read. * @param consumer The string that we are reading from. * @param stack The TextRefStack. * @param[out] params Output parameters */

Source from the content-addressed store, hash-verified

762 * @param[out] params Output parameters
763 */
764static void ProcessNewGRFStringControlCode(char32_t scc, StringConsumer &consumer, TextRefStack &stack, std::vector<StringParameter> &params)
765{
766 /* There is data on the NewGRF text stack, and we want to move them to OpenTTD's string stack.
767 * After this call, a new call is made with `modify_parameters` set to false when the string is finally formatted. */
768 switch (scc) {
769 default: return;
770
771 case SCC_PLURAL_LIST:
772 consumer.SkipUint8(); // plural form
773 [[fallthrough]];
774 case SCC_GENDER_LIST: {
775 consumer.SkipUint8(); // offset
776 /* plural and gender choices cannot contain any string commands, so just skip the whole thing */
777 uint num = consumer.ReadUint8();
778 uint total_len = 0;
779 for (uint i = 0; i != num; i++) {
780 total_len += consumer.ReadUint8();
781 }
782 consumer.Skip(total_len);
783 break;
784 }
785
786 case SCC_SWITCH_CASE: {
787 /* skip all cases and continue with default case */
788 uint num = consumer.ReadUint8();
789 for (uint i = 0; i != num; i++) {
790 consumer.SkipUint8();
791 auto len = consumer.ReadUint16LE();
792 consumer.Skip(len);
793 }
794 consumer.SkipUint16LE(); // length of default
795 break;
796 }
797
798 case SCC_GENDER_INDEX:
799 case SCC_SET_CASE:
800 consumer.SkipUint8();
801 break;
802
803 case SCC_ARG_INDEX:
804 NOT_REACHED();
805 break;
806
807 case SCC_NEWGRF_PRINT_BYTE_SIGNED: params.emplace_back(stack.PopSignedByte()); break;
808 case SCC_NEWGRF_PRINT_QWORD_CURRENCY: params.emplace_back(stack.PopSignedQWord()); break;
809
810 case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
811 case SCC_NEWGRF_PRINT_DWORD_SIGNED: params.emplace_back(stack.PopSignedDWord()); break;
812
813 case SCC_NEWGRF_PRINT_BYTE_HEX: params.emplace_back(stack.PopUnsignedByte()); break;
814 case SCC_NEWGRF_PRINT_QWORD_HEX: params.emplace_back(stack.PopUnsignedQWord()); break;
815
816 case SCC_NEWGRF_PRINT_WORD_SPEED:
817 case SCC_NEWGRF_PRINT_WORD_VOLUME_LONG:
818 case SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT:
819 case SCC_NEWGRF_PRINT_WORD_SIGNED: params.emplace_back(stack.PopSignedWord()); break;
820
821 case SCC_NEWGRF_PRINT_WORD_HEX:

Callers 1

Calls 15

NOT_REACHEDFunction · 0.85
GetCargoTranslationFunction · 0.85
GetStringPtrFunction · 0.85
MapGRFStringIDFunction · 0.85
SkipUint8Method · 0.80
ReadUint8Method · 0.80
ReadUint16LEMethod · 0.80
SkipUint16LEMethod · 0.80
PopSignedByteMethod · 0.80
PopSignedQWordMethod · 0.80
PopSignedDWordMethod · 0.80

Tested by

no test coverage detected