--- a/src/strings.cpp Sun Jun 17 21:31:00 2007 +0000
+++ b/src/strings.cpp Tue Jun 26 23:40:58 2007 +0000
@@ -28,6 +28,10 @@
#include "cargotype.h"
#include "group.h"
#include "debug.h"
+#include "newgrf_townname.h"
+#include "signs.h"
+#include "vehicle.h"
+#include "newgrf_engine.h"
/* for opendir/readdir/closedir */
# include "fios.h"
@@ -37,9 +41,9 @@
static char *StationGetSpecialString(char *buff, int x, const char* last);
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last);
-static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last);
+static char *GetSpecialPlayerNameString(char *buff, int ind, const int64 *argv, const char* last);
-static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei, const char* last);
+static char *FormatString(char *buff, const char *str, const int64 *argv, uint casei, const char* last);
struct LanguagePack {
uint32 ident; // 32-bits identifier
@@ -60,27 +64,22 @@
/** Read an int64 from the argv array. */
-static inline int64 GetInt64(const int32 **argv)
-{
- int64 result;
-
- assert(argv);
- result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32);
- (*argv) += 2;
- return result;
-}
-
-/** Read an int32 from the argv array. */
-static inline int32 GetInt32(const int32 **argv)
+static inline int64 GetInt64(const int64 **argv)
{
assert(argv);
return *(*argv)++;
}
+/** Read an int32 from the argv array. */
+static inline int32 GetInt32(const int64 **argv)
+{
+ return (int32)GetInt64(argv);
+}
+
/** Read an array from the argv array. */
-static inline const int32 *GetArgvPtr(const int32 **argv, int n)
+static inline const int64 *GetArgvPtr(const int64 **argv, int n)
{
- const int32 *result;
+ const int64 *result;
assert(*argv);
result = *argv;
(*argv) += n;
@@ -114,7 +113,7 @@
* @param last
* @return a formatted string of char
*/
-static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv, const char* last)
+static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, const char* last)
{
uint index = GB(string, 0, 11);
uint tab = GB(string, 11, 5);
@@ -179,7 +178,7 @@
char *GetString(char *buffr, StringID string, const char* last)
{
- return GetStringWithArgs(buffr, string, (int32*)_decode_parameters, last);
+ return GetStringWithArgs(buffr, string, (int64*)_decode_parameters, last);
}
@@ -221,7 +220,7 @@
void InjectDParam(int amount)
{
- memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32));
+ memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint64));
}
static const uint32 _divisor_table[] = {
@@ -311,7 +310,7 @@
YearMonthDay ymd;
ConvertDateToYMD(date, &ymd);
- int32 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
+ int64 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
return FormatString(buff, GetStringPtr(STR_DATE_LONG), args, 0, last);
}
@@ -320,7 +319,7 @@
YearMonthDay ymd;
ConvertDateToYMD(date, &ymd);
- int32 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
+ int64 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
return FormatString(buff, GetStringPtr(STR_DATE_SHORT), args, 0, last);
}
@@ -335,19 +334,21 @@
snprintf(day, lengthof(day), "%02i", ymd.day);
snprintf(month, lengthof(month), "%02i", ymd.month + 1);
- int32 args[3] = { BindCString(day), BindCString(month), ymd.year };
+ int64 args[3] = { BindCString(day), BindCString(month), ymd.year };
return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
}
-static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last)
+static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money number, bool compact, const char* last)
{
const char* multiplier = "";
char buf[40];
char* p;
int j;
- /* multiply by exchange rate */
- number *= spec->rate;
+ /* Multiply by exchange rate, but do it safely. */
+ CommandCost cs(number);
+ cs.MultiplyCost(spec->rate);
+ number = cs.GetCost();
/* convert from negative */
if (number < 0) {
@@ -522,11 +523,11 @@
},
};
-static char* FormatString(char* buff, const char* str, const int32* argv, uint casei, const char* last)
+static char* FormatString(char* buff, const char* str, const int64* argv, uint casei, const char* last)
{
extern const char _openttd_revision[];
WChar b;
- const int32 *argv_orig = argv;
+ const int64 *argv_orig = argv;
uint modifier = 0;
while ((b = Utf8Consume(&str)) != '\0') {
@@ -559,7 +560,7 @@
break;
case SCC_VELOCITY: {// {VELOCITY}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24, last);
@@ -568,7 +569,7 @@
}
case SCC_CURRENCY_COMPACT: /* {CURRCOMPACT} */
- buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true, last);
+ buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
break;
case SCC_REVISION: /* {REV} */
@@ -582,7 +583,7 @@
StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
switch (cargo_str) {
case STR_TONS: {
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last);
@@ -591,7 +592,7 @@
}
case STR_LITERS: {
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last);
@@ -613,12 +614,6 @@
}
} break;
- case SCC_CURRENCY_COMPACT_64: { /* {CURRCOMPACT64} */
- /* 64 bit compact currency-unit */
- buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
- break;
- }
-
case SCC_STRING1: { /* {STRING1} */
/* String that consumes ONE argument */
uint str = modifier + GetInt32(&argv);
@@ -666,7 +661,7 @@
case SCC_INDUSTRY_NAME: { /* {INDUSTRY} */
const Industry* i = GetIndustry(GetInt32(&argv));
- int32 args[2];
+ int64 args[2];
/* industry not valid anymore? */
if (!IsValidIndustry(i)) break;
@@ -681,7 +676,7 @@
}
case SCC_VOLUME: { // {VOLUME}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last);
@@ -715,7 +710,7 @@
}
case SCC_POWER: { // {POWER}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24, last);
@@ -724,7 +719,7 @@
}
case SCC_VOLUME_SHORT: { // {VOLUME_S}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24, last);
@@ -733,7 +728,7 @@
}
case SCC_WEIGHT: { // {WEIGHT}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last);
@@ -742,7 +737,7 @@
}
case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24, last);
@@ -751,7 +746,7 @@
}
case SCC_FORCE: { // {FORCE}
- int32 args[1];
+ int64 args[1];
assert(_opt_ptr->units < lengthof(units));
args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s;
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24, last);
@@ -800,11 +795,11 @@
break;
case SCC_CURRENCY: // {CURRENCY}
- buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false, last);
+ buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
break;
case SCC_WAYPOINT_NAME: { // {WAYPOINT}
- int32 temp[2];
+ int64 temp[2];
Waypoint *wp = GetWaypoint(GetInt32(&argv));
StringID str;
if (wp->string != STR_NULL) {
@@ -824,9 +819,10 @@
if (!st->IsValid()) { // station doesn't exist anymore
buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last);
} else {
- int32 temp[2];
- temp[0] = st->town->townnametype;
- temp[1] = st->town->townnameparts;
+ int64 temp[3];
+ temp[0] = STR_TOWN;
+ temp[1] = st->town->index;
+ temp[2] = st->index;
buff = GetStringWithArgs(buff, st->string_id, temp, last);
}
break;
@@ -834,29 +830,89 @@
case SCC_TOWN_NAME: { // {TOWN}
const Town* t = GetTown(GetInt32(&argv));
- int32 temp[1];
+ int64 temp[1];
assert(IsValidTown(t));
temp[0] = t->townnameparts;
- buff = GetStringWithArgs(buff, t->townnametype, temp, last);
+ uint32 grfid = t->townnamegrfid;
+
+ if (grfid == 0) {
+ /* Original town name */
+ buff = GetStringWithArgs(buff, t->townnametype, temp, last);
+ } else {
+ /* Newgrf town name */
+ if (GetGRFTownName(grfid) != NULL) {
+ /* The grf is loaded */
+ buff = GRFTownNameGenerate(buff, t->townnamegrfid, t->townnametype, t->townnameparts, last);
+ } else {
+ /* Fallback to english original */
+ buff = GetStringWithArgs(buff, SPECSTR_TOWNNAME_ENGLISH, temp, last);
+ }
+ }
break;
}
case SCC_GROUP_NAME: { // {GROUP}
const Group *g = GetGroup(GetInt32(&argv));
- int32 args[1];
+ int64 args[1];
assert(IsValidGroup(g));
args[0] = g->index;
- buff = GetStringWithArgs(buff, (g->string_id == STR_SV_GROUP_NAME) ? (StringID)STR_GROUP_NAME_FORMAT : g->string_id, args, last);
+ buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : (StringID)STR_GROUP_NAME_FORMAT, args, last);
break;
}
- case SCC_CURRENCY_64: { // {CURRENCY64}
- buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
+ case SCC_ENGINE_NAME: { // {ENGINE}
+ EngineID engine = (EngineID)GetInt32(&argv);
+
+ buff = GetString(buff, GetCustomEngineName(engine), last);
+ break;
+ }
+
+ case SCC_VEHICLE_NAME: { // {VEHICLE}
+ const Vehicle *v = GetVehicle(GetInt32(&argv));
+
+ int64 args[1];
+ args[0] = v->unitnumber;
+
+ buff = GetStringWithArgs(buff, v->string_id, args, last);
+ break;
+ }
+
+ case SCC_SIGN_NAME: { // {SIGN}
+ const Sign *si = GetSign(GetInt32(&argv));
+ buff = GetString(buff, si->str, last);
+ break;
+ }
+
+ case SCC_COMPANY_NAME: { // {COMPANY}
+ const Player *p = GetPlayer((PlayerID)GetInt32(&argv));
+ int64 args[1];
+ args[0] = p->name_2;
+ buff = GetStringWithArgs(buff, p->name_1, args, last);
+ break;
+ }
+
+ case SCC_COMPANY_NUM: { // {COMPANYNUM}
+ PlayerID player = (PlayerID)GetInt32(&argv);
+
+ /* Nothing is added for AI or inactive players */
+ if (IsHumanPlayer(player) && IsValidPlayer(player)) {
+ int64 args[1];
+ args[0] = player + 1;
+ buff = GetStringWithArgs(buff, STR_7002_PLAYER, args, last);
+ }
+ break;
+ }
+
+ case SCC_PLAYER_NAME: { // {PLAYERNAME}
+ const Player *p = GetPlayer((PlayerID)GetInt32(&argv));
+ int64 args[1];
+ args[0] = p->president_name_2;
+ buff = GetStringWithArgs(buff, p->president_name_1, args, last);
break;
}
@@ -1029,7 +1085,7 @@
return buff;
}
-static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last)
+static char *GetSpecialPlayerNameString(char *buff, int ind, const int64 *argv, const char* last)
{
switch (ind) {
case 1: // not used