src/newgrf_text.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9718 f82a4facea8b
child 9724 b39bc69bb2f2
equal deleted inserted replaced
9722:ebf0ece7d8f6 9723:eee46cb39750
    10  */
    10  */
    11 
    11 
    12 #include "stdafx.h"
    12 #include "stdafx.h"
    13 #include "debug.h"
    13 #include "debug.h"
    14 #include "openttd.h"
    14 #include "openttd.h"
    15 #include "string.h"
       
    16 #include "strings.h"
       
    17 #include "variables.h"
    15 #include "variables.h"
    18 #include "macros.h"
       
    19 #include "table/strings.h"
    16 #include "table/strings.h"
    20 #include "newgrf.h"
    17 #include "newgrf.h"
    21 #include "newgrf_text.h"
    18 #include "newgrf_text.h"
    22 #include "table/control_codes.h"
    19 #include "table/control_codes.h"
    23 #include "helpers.hpp"
    20 #include "strings_func.h"
    24 #include "date.h"
    21 #include "core/alloc_func.hpp"
       
    22 #include "newgrf_storage.h"
       
    23 #include "string_func.h"
    25 
    24 
    26 #define GRFTAB  28
    25 #define GRFTAB  28
    27 #define TABSIZE 11
    26 #define TABSIZE 11
    28 
    27 
    29 /**
    28 /**
   205 		unicode = true;
   204 		unicode = true;
   206 		str += len;
   205 		str += len;
   207 	}
   206 	}
   208 
   207 
   209 	for (;;) {
   208 	for (;;) {
   210 		const char *tmp = str; // Used for UTF-8 decoding
   209 		if (unicode && Utf8EncodedCharLen(*str) != 0) {
   211 
   210 			c = Utf8Consume(&str);
   212 		c = (byte)*str++;
   211 			/* 'Magic' range of control codes. */
       
   212 			if (GB(c, 8, 8) == 0xE0) c = GB(c, 0, 8);
       
   213 		} else {
       
   214 			c = (byte)*str++;
       
   215 		}
   213 		if (c == 0) break;
   216 		if (c == 0) break;
   214 
   217 
   215 		switch (c) {
   218 		switch (c) {
   216 			case 0x01:
   219 			case 0x01:
   217 				d += Utf8Encode(d, SCC_SETX);
   220 				d += Utf8Encode(d, SCC_SETX);
   288 			case 0xB5: d += Utf8Encode(d, SCC_LORRY); break;
   291 			case 0xB5: d += Utf8Encode(d, SCC_LORRY); break;
   289 			case 0xB6: d += Utf8Encode(d, SCC_BUS); break;
   292 			case 0xB6: d += Utf8Encode(d, SCC_BUS); break;
   290 			case 0xB7: d += Utf8Encode(d, SCC_PLANE); break;
   293 			case 0xB7: d += Utf8Encode(d, SCC_PLANE); break;
   291 			case 0xB8: d += Utf8Encode(d, SCC_SHIP); break;
   294 			case 0xB8: d += Utf8Encode(d, SCC_SHIP); break;
   292 			default:
   295 			default:
   293 				if (unicode) {
       
   294 					d += Utf8Encode(d, Utf8Consume(&tmp));
       
   295 					str = tmp;
       
   296 					break;
       
   297 				}
       
   298 
       
   299 				/* Validate any unhandled character */
   296 				/* Validate any unhandled character */
   300 				if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
   297 				if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
   301 				d += Utf8Encode(d, c);
   298 				d += Utf8Encode(d, c);
   302 				break;
   299 				break;
   303 		}
   300 		}
   505 	TextRefStack() : used(false) {}
   502 	TextRefStack() : used(false) {}
   506 
   503 
   507 	uint8  PopUnsignedByte()  { assert(this->position < lengthof(this->stack)); return this->stack[this->position++]; }
   504 	uint8  PopUnsignedByte()  { assert(this->position < lengthof(this->stack)); return this->stack[this->position++]; }
   508 	int8   PopSignedByte()    { return (int8)this->PopUnsignedByte(); }
   505 	int8   PopSignedByte()    { return (int8)this->PopUnsignedByte(); }
   509 
   506 
   510 	uint16 PopUnsignedWord()  { return this->PopUnsignedByte()  | (((uint16)this->PopUnsignedByte())  <<  8); }
   507 	uint16 PopUnsignedWord()
       
   508 	{
       
   509 		uint16 val = this->PopUnsignedByte();
       
   510 		return val | (this->PopUnsignedByte() << 8);
       
   511 	}
   511 	int16  PopSignedWord()    { return (int32)this->PopUnsignedWord(); }
   512 	int16  PopSignedWord()    { return (int32)this->PopUnsignedWord(); }
   512 
   513 
   513 	uint32 PopUnsignedDWord() { return this->PopUnsignedWord()  | (((uint32)this->PopUnsignedWord())  << 16); }
   514 	uint32 PopUnsignedDWord()
       
   515 	{
       
   516 		uint32 val = this->PopUnsignedWord();
       
   517 		return val | (this->PopUnsignedWord() << 16);
       
   518 	}
   514 	int32  PopSignedDWord()   { return (int32)this->PopUnsignedDWord(); }
   519 	int32  PopSignedDWord()   { return (int32)this->PopUnsignedDWord(); }
   515 
   520 
   516 	uint64 PopUnsignedQWord() { return this->PopUnsignedDWord() | (((uint64)this->PopUnsignedDWord()) << 32); }
   521 	uint64 PopUnsignedQWord()
       
   522 	{
       
   523 		uint64 val = this->PopUnsignedDWord();
       
   524 		return val | (((uint64)this->PopUnsignedDWord()) << 32);
       
   525 	}
   517 	int64  PopSignedQWord()   { return (int64)this->PopUnsignedQWord(); }
   526 	int64  PopSignedQWord()   { return (int64)this->PopUnsignedQWord(); }
   518 
   527 
   519 	/** Rotate the top four words down: W1, W2, W3, W4 -> W4, W1, W2, W3 */
   528 	/** Rotate the top four words down: W1, W2, W3, W4 -> W4, W1, W2, W3 */
   520 	void RotateTop4Words()
   529 	void RotateTop4Words()
   521 	{
   530 	{