changeset 10135:1a32fa2498b6 draft

(svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
author rubidium <rubidium@openttd.org>
date Sun, 14 Sep 2008 14:31:37 +0000
parents 9cf387b1a828
children 2971d47cbce7
files src/newgrf_text.cpp src/strings.cpp src/table/control_codes.h
diffstat 3 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -284,6 +284,16 @@
 						d += Utf8Encode(d, SCC_NEWGRF_UNPRINT);
 						d += Utf8Encode(d, *str++);
 						break;
+					case 6:
+						d += Utf8Encode(d, SCC_NEWGRF_PRINT_HEX_BYTE);
+						break;
+					case 7:
+						d += Utf8Encode(d, SCC_NEWGRF_PRINT_HEX_WORD);
+						break;
+					case 8:
+						d += Utf8Encode(d, SCC_NEWGRF_PRINT_HEX_DWORD);
+						break;
+
 					default:
 						grfmsg(1, "missing handler for extended format code");
 						break;
@@ -625,6 +635,10 @@
 			case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
 			case SCC_NEWGRF_PRINT_DWORD:          *argv = _newgrf_textrefstack->PopSignedDWord();   break;
 
+			case SCC_NEWGRF_PRINT_HEX_BYTE:       *argv = _newgrf_textrefstack->PopUnsignedByte();  break;
+			case SCC_NEWGRF_PRINT_HEX_DWORD:      *argv = _newgrf_textrefstack->PopUnsignedDWord(); break;
+
+			case SCC_NEWGRF_PRINT_HEX_WORD:
 			case SCC_NEWGRF_PRINT_WORD_SPEED:
 			case SCC_NEWGRF_PRINT_WORD_LITRES:
 			case SCC_NEWGRF_PRINT_UNSIGNED_WORD:  *argv = _newgrf_textrefstack->PopUnsignedWord();  break;
@@ -653,6 +667,11 @@
 		case SCC_NEWGRF_PRINT_UNSIGNED_WORD:
 			return SCC_COMMA;
 
+		case SCC_NEWGRF_PRINT_HEX_BYTE:
+		case SCC_NEWGRF_PRINT_HEX_WORD:
+		case SCC_NEWGRF_PRINT_HEX_DWORD:
+			return SCC_HEX;
+
 		case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
 		case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
 			return SCC_CURRENCY;
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -267,6 +267,10 @@
 	return buff;
 }
 
+static char *FormatHexNumber(char *buff, int64 number, const char *last)
+{
+	return buff + snprintf(buff, last - buff, "0x%x", (uint32)number);
+}
 
 static char *FormatYmdString(char *buff, Date date, const char* last)
 {
@@ -815,6 +819,10 @@
 				buff = FormatNoCommaNumber(buff, GetInt64(&argv), last);
 				break;
 
+			case SCC_HEX: // {HEX}
+				buff = FormatHexNumber(buff, GetInt64(&argv), last);
+				break;
+
 			case SCC_CURRENCY: // {CURRENCY}
 				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
 				break;
--- a/src/table/control_codes.h
+++ b/src/table/control_codes.h
@@ -64,6 +64,7 @@
 	SCC_STRING,
 	SCC_COMMA,
 	SCC_NUM,
+	SCC_HEX,
 
 	SCC_STRING_ID,
 	SCC_RAW_STRING_POINTER,
@@ -101,7 +102,7 @@
 	SCC_NEWGRF_FIRST,
 	SCC_NEWGRF_PRINT_DWORD = SCC_NEWGRF_FIRST, ///< Read 4 bytes from the stack
 	SCC_NEWGRF_PRINT_SIGNED_WORD,              ///< Read 2 bytes from the stack as signed value
-	SCC_NEWGRF_PRINT_SIGNED_BYTE,              ///< Read 1 bytes from the stack as signed value
+	SCC_NEWGRF_PRINT_SIGNED_BYTE,              ///< Read 1 byte from the stack as signed value
 	SCC_NEWGRF_PRINT_UNSIGNED_WORD,            ///< Read 2 bytes from the stack as unsigned value
 	SCC_NEWGRF_PRINT_DWORD_CURRENCY,           ///< Read 4 bytes from the stack as currency
 	SCC_NEWGRF_PRINT_STRING_ID,                ///< Read 2 bytes from the stack as String ID
@@ -110,6 +111,9 @@
 	SCC_NEWGRF_PRINT_WORD_SPEED,               ///< Read 2 bytes from the stack as signed speed
 	SCC_NEWGRF_PRINT_WORD_LITRES,              ///< Read 2 bytes from the stack as signed litres
 	SCC_NEWGRF_PRINT_QWORD_CURRENCY,           ///< Read 8 bytes from the stack as currency
+	SCC_NEWGRF_PRINT_HEX_BYTE,                 ///< Read 1 byte from the stack and print it as hex
+	SCC_NEWGRF_PRINT_HEX_WORD,                 ///< Read 2 bytes from the stack and print it as hex
+	SCC_NEWGRF_PRINT_HEX_DWORD,                ///< Read 4 bytes from the stack and print it as hex
 	SCC_NEWGRF_PUSH_WORD,                      ///< Pushes 2 bytes onto the stack
 	SCC_NEWGRF_UNPRINT,                        ///< "Unprints" the given number of bytes from the string
 	SCC_NEWGRF_DISCARD_WORD,                   ///< Discard the next two bytes