summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-03-25 11:32:58 +0000
committertron <tron@openttd.org>2005-03-25 11:32:58 +0000
commit0c325e10dab3223cc5bef75e2bd0d1719457a740 (patch)
tree0e7bd63c45044b1b65e883fd68ab18c71a309837
parent9cde836d085ddfb00ee254e110c5bc5ab0582a46 (diff)
downloadopenttd-0c325e10dab3223cc5bef75e2bd0d1719457a740.tar.xz
(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
-rw-r--r--misc_gui.c20
-rw-r--r--station_gui.c18
-rw-r--r--strings.h8
3 files changed, 20 insertions, 26 deletions
diff --git a/misc_gui.c b/misc_gui.c
index 4811a8228..0b35bbcc3 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -669,28 +669,20 @@ static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, u
char *b;
b = _userstring;
- b[0] = 0x81;
- b[1] = STR_000D_ACCEPTS;
- b[2] = STR_000D_ACCEPTS >> 8;
- b += 3;
+ b = InlineString(b, STR_000D_ACCEPTS);
for(i=0; i!=NUM_CARGO; i++,mask>>=1) {
if (accepts[i] >= 8 && (mask&1) ) {
StringID id = _cargoc.names_s[i];
- b[0] = 0x81;
- b[1] = (byte)(id & 255);
- b[2] = (byte)(id >> 8);
- b[3] = ',';
- b[4] = ' ';
- b += 5;
+ b = InlineString(b, id);
+ *b++ = ',';
+ *b++ = ' ';
}
}
if (b == &_userstring[3]) {
- b[0] = 0x81;
- b[1] = (char)STR_00D0_NOTHING;
- b[2] = STR_00D0_NOTHING >> 8;
- b[3] = 0;
+ b = InlineString(b, STR_00D0_NOTHING);
+ *b++ = '\0';
} else {
b[-2] = 0;
}
diff --git a/station_gui.c b/station_gui.c
index 702351c14..b98afe617 100644
--- a/station_gui.c
+++ b/station_gui.c
@@ -401,27 +401,21 @@ static void DrawStationViewWindow(Window *w)
char *b;
b = _userstring;
- b[0] = 0x81;
- b[1] = STR_000C_ACCEPTS;
- b[2] = STR_000C_ACCEPTS >> 8;
- b += 3;
+ b = InlineString(b, STR_000C_ACCEPTS);
for(i=0; i!=NUM_CARGO; i++) {
if ((b - _userstring) + 5 > USERSTRING_LEN - 1)
break;
if (st->goods[i].waiting_acceptance & 0x8000) {
- b[0] = 0x81;
- WRITE_LE_UINT16(b+1, _cargoc.names_s[i]);
- WRITE_LE_UINT16(b+3, 0x202C);
- b += 5;
+ b = InlineString(b, _cargoc.names_s[i]);
+ WRITE_LE_UINT16(b, 0x202C);
+ b += 2;
}
}
if (b == &_userstring[3]) {
- b[0] = 0x81;
- b[1] = (char)STR_00D0_NOTHING;
- b[2] = STR_00D0_NOTHING >> 8;
- b[3] = 0;
+ b = InlineString(b, STR_00D0_NOTHING);
+ *b++ = '\0';
} else {
b[-2] = 0;
}
diff --git a/strings.h b/strings.h
index 8cf629255..f3cd34d1d 100644
--- a/strings.h
+++ b/strings.h
@@ -1,6 +1,14 @@
#ifndef 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);
void InjectDParam(int amount);