1
0
Fork 0

(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.

release/0.4.5
tron 2005-03-25 11:32:58 +00:00
parent 9cde836d08
commit 0c325e10da
3 changed files with 20 additions and 26 deletions

View File

@ -669,28 +669,20 @@ static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, u
char *b; char *b;
b = _userstring; b = _userstring;
b[0] = 0x81; b = InlineString(b, STR_000D_ACCEPTS);
b[1] = STR_000D_ACCEPTS;
b[2] = STR_000D_ACCEPTS >> 8;
b += 3;
for(i=0; i!=NUM_CARGO; i++,mask>>=1) { for(i=0; i!=NUM_CARGO; i++,mask>>=1) {
if (accepts[i] >= 8 && (mask&1) ) { if (accepts[i] >= 8 && (mask&1) ) {
StringID id = _cargoc.names_s[i]; StringID id = _cargoc.names_s[i];
b[0] = 0x81; b = InlineString(b, id);
b[1] = (byte)(id & 255); *b++ = ',';
b[2] = (byte)(id >> 8); *b++ = ' ';
b[3] = ',';
b[4] = ' ';
b += 5;
} }
} }
if (b == &_userstring[3]) { if (b == &_userstring[3]) {
b[0] = 0x81; b = InlineString(b, STR_00D0_NOTHING);
b[1] = (char)STR_00D0_NOTHING; *b++ = '\0';
b[2] = STR_00D0_NOTHING >> 8;
b[3] = 0;
} else { } else {
b[-2] = 0; b[-2] = 0;
} }

View File

@ -401,27 +401,21 @@ static void DrawStationViewWindow(Window *w)
char *b; char *b;
b = _userstring; b = _userstring;
b[0] = 0x81; b = InlineString(b, STR_000C_ACCEPTS);
b[1] = STR_000C_ACCEPTS;
b[2] = STR_000C_ACCEPTS >> 8;
b += 3;
for(i=0; i!=NUM_CARGO; i++) { for(i=0; i!=NUM_CARGO; i++) {
if ((b - _userstring) + 5 > USERSTRING_LEN - 1) if ((b - _userstring) + 5 > USERSTRING_LEN - 1)
break; break;
if (st->goods[i].waiting_acceptance & 0x8000) { if (st->goods[i].waiting_acceptance & 0x8000) {
b[0] = 0x81; b = InlineString(b, _cargoc.names_s[i]);
WRITE_LE_UINT16(b+1, _cargoc.names_s[i]); WRITE_LE_UINT16(b, 0x202C);
WRITE_LE_UINT16(b+3, 0x202C); b += 2;
b += 5;
} }
} }
if (b == &_userstring[3]) { if (b == &_userstring[3]) {
b[0] = 0x81; b = InlineString(b, STR_00D0_NOTHING);
b[1] = (char)STR_00D0_NOTHING; *b++ = '\0';
b[2] = STR_00D0_NOTHING >> 8;
b[3] = 0;
} else { } else {
b[-2] = 0; b[-2] = 0;
} }

View File

@ -1,6 +1,14 @@
#ifndef STRINGS_H #ifndef STRINGS_H
#define STRINGS_H #define STRINGS_H
static inline char* InlineString(char* buf, uint16 string)
{
*buf++ = '\x81';
*buf++ = string & 0xFF;
*buf++ = string >> 8;
return buf;
}
char *GetString(char *buffr, uint16 string); char *GetString(char *buffr, uint16 string);
void InjectDParam(int amount); void InjectDParam(int amount);