changeset 19156:98160a3a9c08 draft

(svn r24022) -Add: CARGO_LIST control code for strings
author rubidium <rubidium@openttd.org>
date Sat, 10 Mar 2012 19:04:49 +0000
parents 25b34879737f
children 5d15de953532
files src/strings.cpp src/table/control_codes.h src/table/strgen_tables.h
diffstat 3 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -1106,6 +1106,38 @@
 				break;
 			}
 
+			case SCC_CARGO_LIST: { // {CARGO_LIST}
+				uint32 cmask = args->GetInt32(SCC_CARGO_LIST);
+				bool first = true;
+
+				const CargoSpec *cs;
+				FOR_ALL_SORTED_CARGOSPECS(cs) {
+					if (!HasBit(cmask, cs->Index())) continue;
+
+					if (buff >= last - 2) break; // ',' and ' '
+
+					if (first) {
+						first = false;
+					} else {
+						/* Add a comma if this is not the first item */
+						*buff++ = ',';
+						*buff++ = ' ';
+					}
+
+					buff = GetStringWithArgs(buff, cs->name, args, last, next_substr_case_index, game_script);
+				}
+
+				/* If first is still true then no cargo is accepted */
+				if (first) buff = GetStringWithArgs(buff, STR_JUST_NOTHING, args, last, next_substr_case_index, game_script);
+
+				*buff = '\0';
+				next_substr_case_index = 0;
+
+				/* Make sure we detect any buffer overflow */
+				assert(buff < last);
+				break;
+			}
+
 			case SCC_CURRENCY_SHORT: // {CURRENCY_SHORT}
 				buff = FormatGenericCurrency(buff, _currency, args->GetInt64(), true, last);
 				break;
--- a/src/table/control_codes.h
+++ b/src/table/control_codes.h
@@ -54,6 +54,7 @@
 	SCC_CARGO_LONG,
 	SCC_CARGO_SHORT,
 	SCC_CARGO_TINY,
+	SCC_CARGO_LIST,
 	SCC_POWER,
 	SCC_VOLUME_LONG,
 	SCC_VOLUME_SHORT,
--- a/src/table/strgen_tables.h
+++ b/src/table/strgen_tables.h
@@ -73,6 +73,7 @@
 	{"CARGO_LONG",        EmitSingleChar, SCC_CARGO_LONG,         2, C_NONE | C_GENDER},
 	{"CARGO_SHORT",       EmitSingleChar, SCC_CARGO_SHORT,        2, C_NONE}, // short cargo description, only ### tons, or ### litres
 	{"CARGO_TINY",        EmitSingleChar, SCC_CARGO_TINY,         2, C_NONE}, // tiny cargo description with only the amount, not a specifier for the amount or the actual cargo name
+	{"CARGO_LIST",        EmitSingleChar, SCC_CARGO_LIST,         1, C_CASE},
 	{"POWER",             EmitSingleChar, SCC_POWER,              1, C_NONE},
 	{"VOLUME_LONG",       EmitSingleChar, SCC_VOLUME_LONG,        1, C_NONE},
 	{"VOLUME_SHORT",      EmitSingleChar, SCC_VOLUME_SHORT,       1, C_NONE},