summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-02-20 22:09:21 +0000
committerpeter1138 <peter1138@openttd.org>2007-02-20 22:09:21 +0000
commitef2daa5060e251834e82df1ba3e081579ff84f2f (patch)
tree9caff20858ac3f06265e4f69d54b9cdb03a47004 /src
parent6621beb126c4bf1481b9d7826f3efd10c2bb8308 (diff)
downloadopenttd-ef2daa5060e251834e82df1ba3e081579ff84f2f.tar.xz
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
Diffstat (limited to 'src')
-rw-r--r--src/build_vehicle_gui.cpp3
-rw-r--r--src/cargotype.cpp46
-rw-r--r--src/cargotype.h42
-rw-r--r--src/economy.cpp13
-rw-r--r--src/graph_gui.cpp10
-rw-r--r--src/gui.h1
-rw-r--r--src/industry_cmd.cpp3
-rw-r--r--src/industry_gui.cpp7
-rw-r--r--src/misc.cpp27
-rw-r--r--src/misc_gui.cpp7
-rw-r--r--src/newgrf.cpp4
-rw-r--r--src/newgrf_engine.cpp42
-rw-r--r--src/order_gui.cpp3
-rw-r--r--src/station_cmd.cpp3
-rw-r--r--src/station_gui.cpp21
-rw-r--r--src/strings.cpp6
-rw-r--r--src/table/cargo_const.h142
-rw-r--r--src/table/landscape_const.h257
-rw-r--r--src/train_cmd.cpp3
-rw-r--r--src/variables.h13
-rw-r--r--src/vehicle_gui.cpp5
21 files changed, 294 insertions, 364 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 51058e47a..e9b4ff6f0 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -24,6 +24,7 @@
#include "newgrf_engine.h"
#include "date.h"
#include "strings.h"
+#include "cargotype.h"
enum BuildVehicleWidgets {
@@ -381,7 +382,7 @@ static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const
/* Wagon weight - (including cargo) */
SetDParam(0, rvi->weight);
- SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
+ SetDParam(1, (GetCargo(rvi->cargo_type)->weight * rvi->capacity >> 4) + rvi->weight);
DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
y += 10;
diff --git a/src/cargotype.cpp b/src/cargotype.cpp
new file mode 100644
index 000000000..e17bff0ef
--- /dev/null
+++ b/src/cargotype.cpp
@@ -0,0 +1,46 @@
+/* $Id$ */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "macros.h"
+#include "table/sprites.h"
+#include "table/strings.h"
+#include "newgrf_cargo.h"
+#include "cargotype.h"
+
+#include "table/cargo_const.h"
+
+static CargoSpec _cargo[NUM_CARGO];
+
+static const byte INVALID_CARGO = 0xFF;
+
+
+void SetupCargoForClimate(LandscapeID l)
+{
+ assert(l < lengthof(_default_climate_cargo));
+
+ /* Reset and disable all cargo types */
+ memset(_cargo, 0, sizeof(_cargo));
+ for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO;
+
+ for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
+ CargoLabel cl = _default_climate_cargo[l][i];
+
+ /* Loop through each of the default cargo types to see if
+ * the label matches */
+ for (uint j = 0; j < lengthof(_default_cargo); j++) {
+ if (_default_cargo[j].label == cl) {
+ _cargo[i] = _default_cargo[j];
+ break;
+ }
+ }
+ }
+}
+
+
+const CargoSpec *GetCargo(CargoID c)
+{
+ assert(c < lengthof(_cargo));
+ return &_cargo[c];
+}
+
diff --git a/src/cargotype.h b/src/cargotype.h
new file mode 100644
index 000000000..2e202f9de
--- /dev/null
+++ b/src/cargotype.h
@@ -0,0 +1,42 @@
+/* $Id$ */
+
+#ifndef CARGOTYPE_H
+#define CARGOTYPE_H
+
+
+typedef uint32 CargoLabel;
+
+
+typedef struct CargoSpec {
+ uint8 bitnum;
+ CargoLabel label;
+ uint32 grfid;
+ uint8 legend_colour;
+ uint8 rating_colour;
+ uint8 weight;
+ uint16 initial_payment;
+ uint8 transit_days[2];
+
+ bool is_freight;
+ uint8 substitutetowngrowth;
+ uint16 multipliertowngrowth;
+ uint8 callbackflags;
+
+ StringID name;
+ StringID name_plural;
+ StringID units_volume;
+ StringID quantifier;
+ StringID abbrev;
+
+ SpriteID sprite;
+
+ uint16 classes;
+} CargoSpec;
+
+
+/* Set up the default cargo types for the given landscape type */
+void SetupCargoForClimate(LandscapeID l);
+/* Retrieve cargo details for the given cargo ID */
+const CargoSpec *GetCargo(CargoID c);
+
+#endif /* CARGOTYPE_H */
diff --git a/src/economy.cpp b/src/economy.cpp
index 8ac68e8b9..85eb0367b 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -33,6 +33,7 @@
#include "newgrf_callbacks.h"
#include "unmovable.h"
#include "date.h"
+#include "cargotype.h"
// Score info
const ScoreInfo _score_info[] = {
@@ -807,7 +808,8 @@ Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode)
Pair tp;
/* if mode is false, use the singular form */
- SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode ? 0 : 32));
+ const CargoSpec *cs = GetCargo(s->cargo_type);
+ SetDParam(0, mode ? cs->name_plural : cs->name);
if (s->age < 12) {
if (s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL) {
@@ -1087,6 +1089,7 @@ static void Load_SUBS(void)
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
{
CargoID cargo = cargo_type;
+ const CargoSpec *cs = GetCargo(cargo_type);
byte f;
/* zero the distance if it's the bank and very short transport. */
@@ -1094,12 +1097,12 @@ int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
dist = 0;
f = 255;
- if (transit_days > _cargoc.transit_days_1[cargo]) {
- transit_days -= _cargoc.transit_days_1[cargo];
+ if (transit_days > cs->transit_days[0]) {
+ transit_days -= cs->transit_days[0];
f -= transit_days;
- if (transit_days > _cargoc.transit_days_2[cargo]) {
- transit_days -= _cargoc.transit_days_2[cargo];
+ if (transit_days > cs->transit_days[1]) {
+ transit_days -= cs->transit_days[1];
if (f < transit_days) {
f = 0;
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index 8188414eb..6f5693347 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -13,8 +13,7 @@
#include "variables.h"
#include "date.h"
#include "helpers.hpp"
-
-const byte _cargo_colours[NUM_CARGO] = {152, 32, 15, 174, 208, 194, 191, 84, 184, 10, 202, 48};
+#include "cargotype.h"
/* Bitmasks of player and cargo indices that shouldn't be drawn. */
static uint _legend_excluded_players;
@@ -749,13 +748,14 @@ static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
* clk_dif will move one pixel down and one pixel to the right
* when the button is clicked */
byte clk_dif = IsWindowWidgetLowered(w, i + 3) ? 1 : 0;
+ const CargoSpec *cs = GetCargo(i);
GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
- GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, _cargo_colours[i]);
- SetDParam(0, _cargoc.names_s[i]);
+ GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour);
+ SetDParam(0, cs->name != 0 ? cs->name : (StringID)STR_EMPTY);
DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, 0);
y += 8;
- gd.colors[i] = _cargo_colours[i];
+ gd.colors[i] = cs->legend_colour;
for (j = 0; j != 20; j++) {
gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, i);
}
diff --git a/src/gui.h b/src/gui.h
index 96660bb09..3559078b3 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -20,7 +20,6 @@ void ShowPatchesSelection(void);
void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right);
/* graph_gui.c */
-extern const byte _cargo_colours[NUM_CARGO];
void ShowOperatingProfitGraph(void);
void ShowIncomeGraph(void);
void ShowDeliveredCargoGraph(void);
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 0cb46211b..525177c2d 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -26,6 +26,7 @@
#include "date.h"
#include "water_map.h"
#include "tree_map.h"
+#include "cargotype.h"
void ShowIndustryViewWindow(int industry);
void BuildOilRig(TileIndex tile);
@@ -1624,7 +1625,7 @@ static void ExtChangeIndustryProduction(Industry *i)
mag = abs(percent);
if (mag >= 10) {
SetDParam(2, mag);
- SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]);
+ SetDParam(0, GetCargo(i->produced_cargo[j])->name);
SetDParam(1, i->index);
AddNewsItem(
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index aa308b721..9cbe0c3f2 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -17,6 +17,7 @@
#include "town.h"
#include "variables.h"
#include "helpers.hpp"
+#include "cargotype.h"
const byte _build_industry_types[4][12] = {
{ 1, 2, 4, 6, 8, 0, 3, 5, 9, 11, 18 },
@@ -303,13 +304,13 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
if (i->accepts_cargo[0] != CT_INVALID) {
StringID str;
- SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]);
+ SetDParam(0, GetCargo(i->accepts_cargo[0])->name);
str = STR_4827_REQUIRES;
if (i->accepts_cargo[1] != CT_INVALID) {
- SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]);
+ SetDParam(1, GetCargo(i->accepts_cargo[1])->name);
str = STR_4828_REQUIRES;
if (i->accepts_cargo[2] != CT_INVALID) {
- SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]);
+ SetDParam(2, GetCargo(i->accepts_cargo[2])->name);
str = STR_4829_REQUIRES;
}
}
diff --git a/src/misc.cpp b/src/misc.cpp
index 7f61191e4..afb5da538 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -16,8 +16,8 @@
#include "vehicle_gui.h"
#include "variables.h"
#include "ai/ai.h"
-#include "table/landscape_const.h"
#include "date.h"
+#include "cargotype.h"
char _name_array[512][32];
@@ -237,28 +237,11 @@ void ConvertNameArray(void)
// Calculate constants that depend on the landscape type.
void InitializeLandscapeVariables(bool only_constants)
{
- const CargoTypesValues *lpd;
- uint i;
- StringID str;
-
- lpd = &_cargo_types_base_values[_opt.landscape];
-
- for (i = 0; i != NUM_CARGO; i++) {
- _cargoc.sprites[i] = lpd->sprites[i];
-
- str = lpd->names[i];
- _cargoc.names_s[i] = str;
- _cargoc.names_long[i] = (str += 0x40);
- _cargoc.names_short[i] = (str += 0x20);
- _cargoc.weights[i] = lpd->weights[i];
-
- if (!only_constants) {
- _cargo_payment_rates[i] = lpd->initial_cargo_payment[i];
- _cargo_payment_rates_frac[i] = 0;
- }
+ if (only_constants) return;
- _cargoc.transit_days_1[i] = lpd->transit_days_table_1[i];
- _cargoc.transit_days_2[i] = lpd->transit_days_table_2[i];
+ for (CargoID i = 0; i != NUM_CARGO; i++) {
+ _cargo_payment_rates[i] = GetCargo(i)->initial_payment;
+ _cargo_payment_rates_frac[i] = 0;
}
}
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index c3f4dbf86..ccf6734b6 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -30,6 +30,7 @@
#include "tgp.h"
#include "settings.h"
#include "date.h"
+#include "cargotype.h"
#include "fios.h"
/* Variables to display file lists */
@@ -153,10 +154,10 @@ static void Place_LandInfo(TileIndex tile)
/* If the accepted value is less than 8, show it in 1/8:ths */
if (ac[i] < 8) {
SetDParam(0, ac[i]);
- SetDParam(1, _cargoc.names_s[i]);
+ SetDParam(1, GetCargo(i)->name);
p = GetString(p, STR_01D1_8, lastof(_landinfo_data[5]));
} else {
- p = GetString(p, _cargoc.names_s[i], lastof(_landinfo_data[5]));
+ p = GetString(p, GetCargo(i)->name, lastof(_landinfo_data[5]));
}
}
}
@@ -740,7 +741,7 @@ static void DrawStationCoverageText(const AcceptedCargo accepts,
*b++ = ',';
*b++ = ' ';
}
- b = InlineString(b, _cargoc.names_s[i]);
+ b = InlineString(b, GetCargo(i)->name);
}
}
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index b75c25b4c..5a32dad49 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -31,6 +31,7 @@
#include "newgrf_sound.h"
#include "newgrf_spritegroup.h"
#include "helpers.hpp"
+#include "cargotype.h"
/* TTDPatch extended GRF format codec
* (c) Petr Baudis 2004 (GPL'd)
@@ -3519,6 +3520,9 @@ static void ResetNewGRFData(void)
// Add engine type to engine data. This is needed for the refit precalculation.
AddTypeToEngines();
+ /* Set up the default cargo types */
+ SetupCargoForClimate(_opt.landscape);
+
/* Reset misc GRF features and train list display variables */
_misc_grf_features = 0;
_traininfo_vehicle_pitch = 0;
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 0a1183afb..2c3e0ac6a 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -18,44 +18,9 @@
#include "newgrf_cargo.h"
#include "date.h"
#include "helpers.hpp"
+#include "cargotype.h"
-
-/* Default cargo classes */
-static const uint16 _cargo_classes[NUM_GLOBAL_CID] = {
- CC_PASSENGERS,
- CC_BULK,
- CC_MAIL,
- CC_LIQUID,
- CC_PIECE_GOODS,
- CC_EXPRESS,
- CC_BULK,
- CC_PIECE_GOODS,
- CC_BULK,
- CC_PIECE_GOODS,
- CC_ARMOURED,
- CC_PIECE_GOODS,
- CC_REFRIGERATED | CC_EXPRESS,
- CC_REFRIGERATED | CC_EXPRESS,
- CC_BULK,
- CC_LIQUID,
- CC_LIQUID,
- CC_BULK,
- CC_PIECE_GOODS,
- CC_PIECE_GOODS,
- CC_EXPRESS,
- CC_BULK,
- CC_LIQUID,
- CC_BULK,
- CC_PIECE_GOODS,
- CC_LIQUID,
- CC_PIECE_GOODS,
- CC_PIECE_GOODS,
- CC_NOAVAILABLE,
- CC_NOAVAILABLE,
- CC_NOAVAILABLE,
-};
-
int _traininfo_vehicle_pitch = 0;
int _traininfo_vehicle_width = 29;
@@ -587,7 +552,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
if (u->cargo_cap == 0) continue;
/* Map from climate to global cargo ID */
cargo = _global_cargo_id[_opt.landscape][u->cargo_type];
- cargo_classes |= _cargo_classes[cargo];
+ cargo_classes |= GetCargo(cargo)->classes;
common_cargos[cargo]++;
user_def_data |= RailVehInfo(u->engine_type)->user_def_data;
}
@@ -644,8 +609,9 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
* cccc - the cargo class value of the cargo transported by the vehicle.
*/
CargoID cid = _global_cargo_id[_opt.landscape][v->cargo_type];
+ const CargoSpec *cs = GetCargo(v->cargo_type);
- return (_cargo_classes[cid] << 16) | (_cargoc.weights[v->cargo_type] << 8) | cid;
+ return (cs->classes << 16) | (cs->weight << 8) | cid;
}
case 0x48: return GetVehicleTypeInfo(v->engine_type); /* Vehicle Type Info */
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 7a2adcf5d..7cc9c9492 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -22,6 +22,7 @@
#include "train.h"
#include "water_map.h"
#include "vehicle_gui.h"
+#include "cargotype.h"
enum OrderWindowWidgets {
ORDER_WIDGET_CLOSEBOX = 0,
@@ -180,7 +181,7 @@ static void DrawOrdersWindow(Window *w)
SetDParam(1, s);
if (order->refit_cargo < NUM_CARGO) {
SetDParam(3, STR_REFIT_ORDER);
- SetDParam(4, _cargoc.names_s[order->refit_cargo]);
+ SetDParam(4, GetCargo(order->refit_cargo)->name);
} else {
SetDParam(3, STR_EMPTY);
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 4b06a7cbe..cd674d2d5 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -37,6 +37,7 @@
#include "helpers.hpp"
#include "misc/autoptr.hpp"
#include "road.h"
+#include "cargotype.h"
/**
* Called if a new block is added to the station-pool
@@ -361,7 +362,7 @@ static uint GetAcceptanceMask(const Station *st)
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
{
for (uint i = 0; i < num_items; i++) {
- SetDParam(i + 1, _cargoc.names_s[cargo[i]]);
+ SetDParam(i + 1, GetCargo(cargo[i])->name);
}
SetDParam(0, st->index);
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 9e4bcccad..cc9bcb65b 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -20,6 +20,7 @@
#include "vehicle.h"
#include "table/sprites.h"
#include "helpers.hpp"
+#include "cargotype.h"
enum StationListWidgets {
STATIONLIST_WIDGET_CLOSEBOX = 0,
@@ -57,7 +58,10 @@ static StationSortListingTypeFunction StationRatingMaxSorter;
* @param rating ratings data for that particular cargo */
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
{
- int colour = _cargo_colours[type];
+ const CargoSpec *cs = GetCargo(type);
+ if (cs->bitnum == 0xFF) return;
+
+ int colour = cs->rating_colour;
uint w = (minu(amount, 576) + 5) / 36;
/* Draw total cargo (limited) on station (fits into 16 pixels) */
@@ -73,7 +77,7 @@ static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount
}
}
- DrawString(x + 1, y, _cargoc.names_short[type], 0x10);
+ DrawString(x + 1, y, cs->abbrev, 0x10);
/* Draw green/red ratings bar (fits into 14 pixels) */
y += 8;
@@ -323,8 +327,11 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
for (i = 0; i < NUM_CARGO; i++) {
cg_ofst = IsWindowWidgetLowered(w, i + STATIONLIST_WIDGET_CARGOSTART) ? 2 : 1;
- GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, _cargo_colours[i]);
- DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, _cargoc.names_short[i], 0x10);
+ const CargoSpec *cs = GetCargo(i);
+ if (cs->bitnum != 0xFF) {
+ GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
+ DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, 0x10);
+ }
x += 14;
}
@@ -656,7 +663,7 @@ static void DrawStationViewWindow(Window *w)
int cur_x = x;
num = min(num, 23);
do {
- DrawSprite(_cargoc.sprites[i], PAL_NONE, cur_x, y);
+ DrawSprite(GetCargo(i)->sprite, PAL_NONE, cur_x, y);
cur_x += 10;
} while (--num);
}
@@ -701,7 +708,7 @@ static void DrawStationViewWindow(Window *w)
*b++ = ',';
*b++ = ' ';
}
- b = InlineString(b, _cargoc.names_s[i]);
+ b = InlineString(b, GetCargo(i)->name);
}
}
@@ -716,7 +723,7 @@ static void DrawStationViewWindow(Window *w)
y = 77;
for (i = 0; i != NUM_CARGO; i++) {
if (st->goods[i].enroute_from != INVALID_STATION) {
- SetDParam(0, _cargoc.names_s[i]);
+ SetDParam(0, GetCargo(i)->name);
SetDParam(2, st->goods[i].rating * 101 >> 8);
SetDParam(1, STR_3035_APPALLING + (st->goods[i].rating >> 5));
DrawString(8, y, STR_303D, 0);
diff --git a/src/strings.cpp b/src/strings.cpp
index 3c344239c..9b49b8929 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -17,12 +17,12 @@
#include "industry.h"
#include "variables.h"
#include "newgrf_text.h"
-#include "table/landscape_const.h"
#include "table/control_codes.h"
#include "music.h"
#include "date.h"
#include "industry.h"
#include "helpers.hpp"
+#include "cargotype.h"
/* for opendir/readdir/closedir */
# include "fios.h"
@@ -561,7 +561,7 @@ static char* FormatString(char* buff, const char* str, const int32* argv, uint c
// Short description of cargotypes. Layout:
// 8-bit = cargo type
// 16-bit = cargo count
- StringID cargo_str = _cargo_types_base_values[_opt_ptr->landscape].units_volume[GetInt32(&argv)];
+ StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
switch (cargo_str) {
case STR_TONS: {
int32 args[1];
@@ -685,7 +685,7 @@ static char* FormatString(char* buff, const char* str, const int32* argv, uint c
// 8bit - cargo type
// 16-bit - cargo count
CargoID cargo = GetInt32(&argv);
- StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : _cargoc.names_long[cargo];
+ StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : GetCargo(cargo)->quantifier;
buff = GetStringWithArgs(buff, cargo_str, argv++, last);
break;
}
diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h
new file mode 100644
index 000000000..4b617f8a6
--- /dev/null
+++ b/src/table/cargo_const.h
@@ -0,0 +1,142 @@
+/* $Id$ */
+
+/* Table of all default cargo types */
+
+#define MK(bt, label, c, e, f, g, h, fr, ks1, ks2, ks3, ks4, ks5, l, m) \
+ {bt, label, 0, c, c, e, f, {g, h}, fr, 0, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m}
+static const CargoSpec _default_cargo[] = {
+ MK( 0, 'PASS', 152, 1, 3185, 0, 24, false,
+ STR_000F_PASSENGERS, STR_002F_PASSENGER, STR_PASSENGERS, STR_QUANTITY_PASSENGERS, STR_ABBREV_PASSENGERS,
+ SPR_CARGO_PASSENGER, CC_PASSENGERS ),
+
+ MK( 1, 'COAL', 32, 16, 5916, 7, 255, true,
+ STR_0010_COAL, STR_0030_COAL, STR_TONS, STR_QUANTITY_COAL, STR_ABBREV_COAL,
+ SPR_CARGO_COAL, CC_BULK ),
+
+ MK( 2, 'MAIL', 15, 4, 4550, 20, 90, false,
+ STR_0011_MAIL, STR_0031_MAIL, STR_BAGS, STR_QUANTITY_MAIL, STR_ABBREV_MAIL,
+ SPR_CARGO_MAIL, CC_MAIL ),
+
+ MK( 3, 'OIL_', 174, 16, 4437, 25, 255, true,
+ STR_0012_OIL, STR_0032_OIL, STR_LITERS, STR_QUANTITY_OIL, STR_ABBREV_OIL,
+ SPR_CARGO_OIL, CC_LIQUID ),
+
+ MK( 4, 'LVST', 208, 3, 4322, 4, 18, true,
+ STR_0013_LIVESTOCK, STR_0033_LIVESTOCK, STR_ITEMS, STR_QUANTITY_LIVESTOCK, STR_ABBREV_LIVESTOCK,
+ SPR_CARGO_LIVESTOCK, CC_PIECE_GOODS ),
+
+ MK( 5, 'GOOD', 194, 8, 6144, 5, 28, true,
+ STR_0014_GOODS, STR_0034_GOODS, STR_CRATES, STR_QUANTITY_GOODS, STR_ABBREV_GOODS,
+ SPR_CARGO_GOODS, CC_EXPRESS ),
+
+ MK( 6, 'GRAI', 191, 16, 4778, 4, 40, true,
+ STR_0015_GRAIN, STR_0035_GRAIN, STR_TONS, STR_QUANTITY_GRAIN, STR_ABBREV_GRAIN,
+ SPR_CARGO_GRAIN, CC_BULK ),
+
+ MK( 6, 'WHEA', 191, 16, 4778, 4, 40, true,
+ STR_0022_WHEAT, STR_0042_WHEAT, STR_TONS, STR_QUANTITY_WHEAT, STR_ABBREV_WHEAT,
+ SPR_CARGO_GRAIN, CC_BULK ),
+
+ MK( 6, 'MAIZ', 191, 6, 4778, 4, 40, true,
+ STR_001B_MAIZE, STR_003B_MAIZE, STR_TONS, STR_QUANTITY_MAIZE, STR_ABBREV_MAIZE,
+ SPR_CARGO_GRAIN, CC_BULK ),
+
+ MK( 7, 'WOOD', 84, 16, 5005, 15, 255, true,
+ STR_0016_WOOD, STR_0036_WOOD, STR_TONS, STR_QUANTITY_WOOD, STR_ABBREV_WOOD,
+ SPR_CARGO_WOOD, CC_PIECE_GOODS ),
+
+ MK( 8, 'IORE', 184, 16, 5120, 9, 255, true,
+ STR_0017_IRON_ORE, STR_0037_IRON_ORE, STR_TONS, STR_QUANTITY_IRON_ORE, STR_ABBREV_IRON_ORE,
+ SPR_CARGO_IRON_ORE, CC_BULK ),
+
+ MK( 9, 'STEL', 10, 16, 5688, 7, 255, true,
+ STR_0018_STEEL, STR_0038_STEEL, STR_TONS, STR_QUANTITY_STEEL, STR_ABBREV_STEEL,
+ SPR_CARGO_STEEL, CC_PIECE_GOODS ),
+
+ MK( 10, 'VALU', 202, 2, 7509, 1, 32, true,
+ STR_0019_VALUABLES, STR_0039_VALUABLES, STR_BAGS, STR_QUANTITY_VALUABLES, STR_ABBREV_VALUABLES,
+ SPR_CARGO_VALUES_GOLD, CC_ARMOURED ),
+
+ MK( 10, 'GOLD', 202, 8, 7509, 10, 40, true,
+ STR_0020_GOLD, STR_0040_GOLD, STR_BAGS, STR_QUANTITY_GOLD, STR_ABBREV_GOLD,
+ SPR_CARGO_VALUES_GOLD, CC_ARMOURED ),
+
+ MK( 10, 'DIAM', 202, 2, 7509, 10, 255, true,
+ STR_001D_DIAMONDS, STR_003D_DIAMOND, STR_BAGS, STR_QUANTITY_DIAMONDS, STR_ABBREV_DIAMONDS,
+ SPR_CARGO_DIAMONDS, CC_ARMOURED ),
+
+ MK( 11, 'PAPR', 10, 16, 5688, 7, 60, true,
+ STR_001F_PAPER, STR_003F_PAPER, STR_TONS, STR_QUANTITY_PAPER, STR_ABBREV_PAPER,
+ SPR_CARGO_PAPER, CC_PIECE_GOODS ),
+
+ MK( 12, 'FOOD', 48, 16, 5688, 0, 30, true,
+ STR_001E_FOOD, STR_003E_FOOD, STR_TONS, STR_QUANTITY_FOOD, STR_ABBREV_FOOD,
+ SPR_CARGO_FOOD, CC_EXPRESS | CC_REFRIGERATED),
+
+ MK( 13, 'FRUT', 208, 6, 4322, 0, 15, true,
+ STR_001C_FRUIT, STR_003C_FRUIT, STR_TONS, STR_QUANTITY_FRUIT, STR_ABBREV_FRUIT,
+ SPR_CARGO_FRUIT, CC_BULK | CC_REFRIGERATED),
+
+ MK( 14, 'CORE', 184, 6, 5120, 12, 255, true,
+ STR_001A_COPPER_ORE, STR_003A_COPPER_ORE, STR_TONS, STR_QUANTITY_COPPER_ORE, STR_ABBREV_COPPER_ORE,
+ SPR_CARGO_COPPER_ORE, CC_BULK ),
+
+ MK( 15, 'WATR', 10, 6, 5688, 20, 80, true,
+ STR_0021_WATER, STR_0041_WATER, STR_LITERS, STR_QUANTITY_WATER, STR_ABBREV_WATER,
+ SPR_CARGO_WATERCOLA, CC_LIQUID ),
+
+ MK( 16, 'RUBR', 32, 6, 5916, 2, 20, true,
+ STR_0023_RUBBER, STR_0043_RUBBER, STR_LITERS, STR_QUANTITY_RUBBER, STR_ABBREV_RUBBER,
+ SPR_CARGO_RUBBER, CC_LIQUID ),
+
+ MK( 17, 'SUGR', 32, 16, 5916, 20, 255, true,
+ STR_0024_SUGAR, STR_0044_SUGAR, STR_TONS, STR_QUANTITY_SUGAR, STR_ABBREV_SUGAR,
+ SPR_CARGO_SUGAR, CC_BULK ),
+
+ MK( 18, 'TOYS', 174, 2, 4437, 25, 255, true,
+ STR_0025_TOYS, STR_0045_TOY, STR_NOTHING, STR_QUANTITY_TOYS, STR_ABBREV_TOYS,
+ SPR_CARGO_TOYS, CC_PIECE_GOODS ),
+
+ MK( 19, 'BATT', 208, 4, 4322, 2, 30, true,
+ STR_002B_BATTERIES, STR_004B_BATTERY, STR_NOTHING, STR_QUANTITY_BATTERIES, STR_ABBREV_BATTERIES,
+ SPR_CARGO_BATTERIES, CC_PIECE_GOODS ),
+
+ MK( 20, 'SWET', 194, 5, 6144, 8, 40, true,
+ STR_0026_CANDY, STR_0046_CANDY, STR_TONS, STR_QUANTITY_SWEETS, STR_ABBREV_SWEETS,
+ SPR_CARGO_CANDY, CC_EXPRESS ),
+
+ MK( 21, 'TOFF', 191, 16, 4778, 14, 60, true,
+ STR_002A_TOFFEE, STR_004A_TOFFEE, STR_TONS, STR_QUANTITY_TOFFEE, STR_ABBREV_TOFFEE,
+ SPR_CARGO_TOFFEE, CC_BULK ),
+
+ MK( 22, 'COLA', 84, 16, 5005, 5, 75, true,
+ STR_0027_COLA, STR_0047_COLA, STR_LITERS, STR_QUANTITY_COLA, STR_ABBREV_COLA,
+ SPR_CARGO_WATERCOLA, CC_LIQUID ),
+
+ MK( 23, 'CTCD', 184, 16, 5120, 10, 25, true,
+ STR_0028_COTTON_CANDY, STR_0048_COTTON_CANDY, STR_TONS, STR_QUANTITY_CANDYFLOSS, STR_ABBREV_CANDYFLOSS,
+ SPR_CARGO_COTTONCANDY, CC_BULK ),
+
+ MK( 24, 'BUBL', 10, 1, 5688, 20, 80, true,
+ STR_0029_BUBBLES, STR_0049_BUBBLE, STR_NOTHING, STR_QUANTITY_BUBBLES, STR_ABBREV_BUBBLES,
+ SPR_CARGO_BUBBLES, CC_PIECE_GOODS ),
+
+ MK( 25, 'PLST', 202, 16, 7509, 30, 255, true,
+ STR_002C_PLASTIC, STR_004C_PLASTIC, STR_LITERS, STR_QUANTITY_PLASTIC, STR_ABBREV_PLASTIC,
+ SPR_CARGO_PLASTIC, CC_LIQUID ),
+
+ MK( 26, 'FZDR', 48, 2, 5688, 30, 50, true,
+ STR_002D_FIZZY_DRINKS, STR_004D_FIZZY_DRINK, STR_NOTHING, STR_QUANTITY_FIZZY_DRINKS, STR_ABBREV_FIZZY_DRINKS,
+ SPR_CARGO_FIZZYDRINK, CC_PIECE_GOODS ),
+
+};
+
+
+/* Table of which cargo types are available in each climate, by default */
+static const CargoLabel _default_climate_cargo[NUM_LANDSCAPE][12] = {
+ { 'PASS', 'COAL', 'MAIL', 'OIL_', 'LVST', 'GOOD', 'GRAI', 'WOOD', 'IORE', 'STEL', 'VALU', 'VOID', },
+ { 'PASS', 'COAL', 'MAIL', 'OIL_', 'LVST', 'GOOD', 'WHEA', 'WOOD', 'VOID', 'PAPR', 'GOLD', 'FOOD', },
+ { 'PASS', 'RUBR', 'MAIL', 'OIL_', 'FRUT', 'GOOD', 'MAIZ', 'WOOD', 'CORE', 'WATR', 'DIAM', 'FOOD', },
+ { 'PASS', 'SUGR', 'MAIL', 'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL', 'PLST', 'FZDR', },
+};
+
diff --git a/src/table/landscape_const.h b/src/table/landscape_const.h
deleted file mode 100644
index 518a48047..000000000
--- a/src/table/landscape_const.h
+++ /dev/null
@@ -1,257 +0,0 @@
-/* $Id$ */
-
-#include "sprites.h"
-
-typedef struct CargoTypesValues {
- StringID names[NUM_CARGO];
- StringID units_volume[NUM_CARGO];
- byte weights[NUM_CARGO];
- SpriteID sprites[NUM_CARGO];
-
- uint16 initial_cargo_payment[NUM_CARGO];
- byte transit_days_table_1[NUM_CARGO];
- byte transit_days_table_2[NUM_CARGO];
-} CargoTypesValues;
-
-
-static const CargoTypesValues _cargo_types_base_values[4] = {
- {
- /* normal names */
- {
- STR_000F_PASSENGERS,
- STR_0010_COAL,
- STR_0011_MAIL,
- STR_0012_OIL,
- STR_0013_LIVESTOCK,
- STR_0014_GOODS,
- STR_0015_GRAIN,
- STR_0016_WOOD,
- STR_0017_IRON_ORE,
- STR_0018_STEEL,
- STR_0019_VALUABLES,
- STR_000E,
- },
-
- { /* normal units of volume */
- STR_PASSENGERS,
- STR_TONS,
- STR_BAGS,
- STR_LITERS,
- STR_ITEMS,
- STR_CRATES,
- STR_TONS,
- STR_TONS,
- STR_TONS,
- STR_TONS,
- STR_BAGS,
- STR_RES_OTHER
- },
-
- /* normal weights */
- {
- 1, 16, 4, 16, 3, 8, 16, 16, 16, 16, 2, 0,
- },
-
- /* normal sprites */
- {
- SPR_CARGO_PASSENGER, SPR_CARGO_COAL, SPR_CARGO_MAIL, SPR_CARGO_OIL, SPR_CARGO_LIVESTOCK,
- SPR_CARGO_GOODS, SPR_CARGO_GRAIN, SPR_CARGO_WOOD, SPR_CARGO_IRON_ORE, SPR_CARGO_STEEL,
- SPR_CARGO_VALUES_GOLD, SPR_ASCII_SPACE
- },
-
- /* normal initial cargo payment */
- {
- 3185, 5916, 4550, 4437, 4322, 6144, 4778, 5005, 5120, 5688, 7509, 5688
- },
-
- /* normal transit days table 1 */
- {
- 0, 7, 20, 25, 4, 5, 4, 15, 9, 7, 1, 0,
- },
-
- /* normal transit days table 2 */
- {
- 24, 255, 90, 255, 18, 28, 40, 255, 255, 255, 32, 30,
- },
- },
-
- {
- /* hilly names */
- {
- STR_000F_PASSENGERS,
- STR_0010_COAL,
- STR_0011_MAIL,
- STR_0012_OIL,
- STR_0013_LIVESTOCK,
- STR_0014_GOODS,
- STR_0022_WHEAT,
- STR_0016_WOOD,
- STR_000E,
- STR_001F_PAPER,
- STR_0020_GOLD,
- STR_001E_FOOD,
- },
-
- { /* hilly units of volume */
- STR_PASSENGERS,
- STR_TONS,
- STR_BAGS,
- STR_LITERS,
- STR_ITEMS,
- STR_CRATES,
- STR_TONS,
- STR_TONS,
- STR_RES_OTHER,
- STR_TONS,
- STR_BAGS,
- STR_TONS
- },
-
- /* hilly weights */
- {
- 1, 16, 4, 16, 3, 8, 16, 16, 0, 16, 8, 16
- },
-
- /* hilly sprites */
- {
- SPR_CARGO_PASSENGER, SPR_CARGO_COAL, SPR_CARGO_MAIL, SPR_CARGO_OIL, SPR_CARGO_LIVESTOCK,
- SPR_CARGO_GOODS, SPR_CARGO_GRAIN, SPR_CARGO_WOOD, SPR_ASCII_SPACE, SPR_CARGO_PAPER,
- SPR_CARGO_VALUES_GOLD, SPR_CARGO_FOOD
- },
-
- /* hilly initial cargo payment */
- {
- 3185, 5916, 4550, 4437, 4322, 6144, 4778, 5005, 5120, 5461, 5802, 5688
- },
-
- /* hilly transit days table 1 */
- {
- 0, 7, 20, 25, 4, 5, 4, 15, 9, 7, 10, 0,
- },
-
- /* hilly transit days table 2 */
- {
- 24, 255, 90, 255, 18, 28, 40, 255, 255, 60, 40, 30
- },
- },
-
- {
- /* desert names */
- {
- STR_000F_PASSENGERS,
- STR_0023_RUBBER,
- STR_0011_MAIL,
- STR_0012_OIL,
- STR_001C_FRUIT,
- STR_0014_GOODS,
- STR_001B_MAIZE,
- STR_0016_WOOD,
- STR_001A_COPPER_ORE,
- STR_0021_WATER,
- STR_001D_DIAMONDS,
- STR_001E_FOOD
- },
-
- { /* desert units of volume */
- STR_PASSENGERS,
- STR_LITERS,
- STR_BAGS,
- STR_LITERS,
- STR_TONS,
- STR_CRATES,
- STR_TONS,
- STR_TONS,
- STR_TONS,
- STR_LITERS,
- STR_BAGS,
- STR_TONS
- },
-
- /* desert weights */
- {
- 1, 16, 4, 16, 16, 8, 16, 16, 16, 16, 2, 16,
- },
-
- /* desert sprites */
- {
- SPR_CARGO_PASSENGER, SPR_CARGO_RUBBER, SPR_CARGO_MAIL, SPR_CARGO_OIL, SPR_CARGO_FRUIT,
- SPR_CARGO_GOODS, SPR_CARGO_GRAIN, SPR_CARGO_WOOD, SPR_CARGO_COPPER_ORE, SPR_CARGO_WATERCOLA,
- SPR_CARGO_DIAMONDS, SPR_CARGO_FOOD
- },
-
- /* desert initial cargo payment */
- {
- 3185, 4437, 4550, 4892, 4209, 6144, 4322, 7964, 4892, 4664, 5802, 5688
- },
-
- /* desert transit days table 1 */
- {
- 0, 2, 20, 25, 0, 5, 4, 15, 12, 20, 10, 0
- },
-
- /* desert transit days table 2 */
- {
- 24, 20, 90, 255, 15, 28, 40, 255, 255, 80, 255, 30
- },
- },
-
- {
- /* candy names */
- {
- STR_000F_PASSENGERS,
- STR_0024_SUGAR,
- STR_0011_MAIL,
- STR_0025_TOYS,
- STR_002B_BATTERIES,
- STR_0026_CANDY,
- STR_002A_TOFFEE,
- STR_0027_COLA,
- STR_0028_COTTON_CANDY,
- STR_0029_BUBBLES,
- STR_002C_PLASTIC,
- STR_002D_FIZZY_DRINKS,
- },
-
- { /* candy unitrs of volume */
- STR_PASSENGERS,
- STR_TONS,
- STR_BAGS,
- STR_NOTHING,
- STR_NOTHING,
- STR_TONS,
- STR_TONS,
- STR_LITERS,
- STR_TONS,
- STR_NOTHING,
- STR_LITERS,
- STR_NOTHING
- },
-
- /* candy weights */
- {
- 1, 16, 4, 2, 4, 5, 16, 16, 16, 1, 16, 2
- },
-
- /* candy sprites */
- {
- SPR_CARGO_PASSENGER, SPR_CARGO_SUGAR, SPR_CARGO_MAIL, SPR_CARGO_TOYS, SPR_CARGO_BATTERIES,
- SPR_CARGO_CANDY, SPR_CARGO_TOFFEE, SPR_CARGO_WATERCOLA, SPR_CARGO_COTTONCANDY, SPR_CARGO_BUBBLES,
- SPR_CARGO_PLASTIC, SPR_CARGO_FIZZYDRINK
- },
-
- /* candy initial cargo payment */
- {
- 3185, 4437, 4550, 5574, 4322, 6144, 4778, 4892, 5005, 5077, 4664, 6250
- },
-
- /* candy transit days table 1 */
- {
- 0, 20, 20, 25, 2, 8, 14, 5, 10, 20, 30, 30,
- },
-
- /* candy transit days table 2 */
- {
- 24, 255, 90, 255, 30, 40, 60, 75, 25, 80, 255, 50
- },
- }
-};
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 98bdb7be6..7dd31711e 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -33,6 +33,7 @@
#include "direction.h"
#include "yapf/yapf.h"
#include "date.h"
+#include "cargotype.h"
static bool TrainCheckIfLineEnds(Vehicle *v);
static void TrainController(Vehicle *v, bool update_image);
@@ -106,7 +107,7 @@ static void TrainCargoChanged(Vehicle* v)
for (u = v; u != NULL; u = u->next) {
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
- uint32 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count * FreightWagonMult(u->cargo_type)) / 16;
+ uint32 vweight = (GetCargo(u->cargo_type)->weight * u->cargo_count * FreightWagonMult(u->cargo_type)) / 16;
// Vehicle weight is not added for articulated parts.
if (!IsArticulatedPart(u)) {
diff --git a/src/variables.h b/src/variables.h
index ccc1fc92c..37da4c4fc 100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -337,19 +337,6 @@ VARDEF char *_config_file;
VARDEF char *_highscore_file;
VARDEF char *_log_file;
-// NOSAVE: These can be recalculated from InitializeLandscapeVariables
-typedef struct {
- StringID names_s[NUM_CARGO];
- StringID names_long[NUM_CARGO];
- StringID names_short[NUM_CARGO];
- byte weights[NUM_CARGO];
- SpriteID sprites[NUM_CARGO];
- byte transit_days_1[NUM_CARGO];
- byte transit_days_2[NUM_CARGO];
-} CargoConst;
-
-VARDEF CargoConst _cargoc;
-
static inline void SetDParamX(uint32 *s, uint n, uint32 v)
{
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 76fa24b50..6c92677d1 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -28,6 +28,7 @@
#include "roadveh.h"
#include "depot.h"
#include "helpers.hpp"
+#include "cargotype.h"
typedef struct Sorting {
Listing aircraft;
@@ -304,7 +305,7 @@ static RefitOption *DrawVehicleRefitWindow(const RefitList *list, int sel, uint
if (i >= pos && i < pos + rows) {
/* Draw the cargo name */
- int last_x = DrawString(2, y, _cargoc.names_s[refit[i].cargo], colour);
+ int last_x = DrawString(2, y, GetCargo(refit[i].cargo)->name, colour);
/* If the callback succeeded, draw the cargo suffix */
if (refit[i].value != CALLBACK_FAILED) {
@@ -521,7 +522,7 @@ uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
if (!HASBIT(cmask, 0)) continue;
- b = InlineString(b, _cargoc.names_s[_local_cargo_id_ctype[cid]]);
+ b = InlineString(b, GetCargo(_local_cargo_id_ctype[cid])->name);
if (cmask > 1) b = strecpy(b, ", ", lastof(_userstring));
}
}