Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions gui/citylist_frame_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const char citylist_frame_t::hist_type[karte_t::MAX_WORLD_COST][20] =
"sended",
"Post",
"Arrived",
"Goods"
"Goods",
"Halts"
};

const uint8 citylist_frame_t::hist_type_color[karte_t::MAX_WORLD_COST] =
Expand All @@ -61,7 +62,8 @@ const uint8 citylist_frame_t::hist_type_color[karte_t::MAX_WORLD_COST] =
COL_LIGHT_YELLOW,
COL_YELLOW,
COL_LIGHT_BROWN,
COL_BROWN
COL_BROWN,
COL_DARK_BLUE
};

const uint8 citylist_frame_t::hist_type_type[karte_t::MAX_WORLD_COST] =
Expand All @@ -77,6 +79,7 @@ const uint8 citylist_frame_t::hist_type_type[karte_t::MAX_WORLD_COST] =
PERCENT,
STANDARD,
PERCENT,
STANDARD,
STANDARD
};

Expand Down Expand Up @@ -173,7 +176,7 @@ citylist_frame_t::citylist_frame_t() :
chart.set_background(SYSCOL_CHART_BACKGROUND);
chart.set_min_size(scr_size(0, 8*LINESPACE));

container_year.add_table(4,3);
container_year.add_table(4,0);
for (int i = 0; i<karte_t::MAX_WORLD_COST; i++) {
sint16 curve = chart.add_curve(color_idx_to_rgb(hist_type_color[i]), welt->get_finance_history_year(), karte_t::MAX_WORLD_COST, i, MAX_WORLD_HISTORY_YEARS, hist_type_type[i], false, true, (i==1) ? 1 : 0 );
// add button
Expand All @@ -192,7 +195,7 @@ citylist_frame_t::citylist_frame_t() :
mchart.set_background(SYSCOL_CHART_BACKGROUND);
mchart.set_min_size(scr_size(0, 8*LINESPACE));

container_month.add_table(4,3);
container_month.add_table(4,0);
for (int i = 0; i<karte_t::MAX_WORLD_COST; i++) {
sint16 curve = mchart.add_curve(color_idx_to_rgb(hist_type_color[i]), welt->get_finance_history_month(), karte_t::MAX_WORLD_COST, i, MAX_WORLD_HISTORY_MONTHS, hist_type_type[i], false, true, (i==1) ? 1 : 0 );

Expand Down
31 changes: 29 additions & 2 deletions simworld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4496,6 +4496,7 @@ void karte_t::update_history()
{
finance_history_year[0][WORLD_CONVOIS] = finance_history_month[0][WORLD_CONVOIS] = convoi_array.get_count();
finance_history_year[0][WORLD_FACTORIES] = finance_history_month[0][WORLD_FACTORIES] = fab_list.get_count();
finance_history_year[0][WORLD_HALTS] = finance_history_month[0][WORLD_HALTS] = haltestelle_t::get_alle_haltestellen().get_count();

// now step all towns (to generate passengers)
sint64 bev=0;
Expand Down Expand Up @@ -4930,6 +4931,15 @@ DBG_MESSAGE("karte_t::save(loadsave_t *file)", "saved messages");
file->rdwr_longlong(finance_history_month[month][cost_type]);
}
}
// WORLD_HALTS added in OTRP v56
if( file->get_OTRP_version()>55 ) {
for(int year = 0; year < /*MAX_WORLD_HISTORY_YEARS*/12; year++) {
file->rdwr_longlong(finance_history_year[year][WORLD_HALTS]);
}
for(int month = 0; month < /*MAX_WORLD_HISTORY_MONTHS*/12; month++) {
file->rdwr_longlong(finance_history_month[month][WORLD_HALTS]);
}
}
}

// finally a possible scenario
Expand Down Expand Up @@ -5512,15 +5522,32 @@ DBG_MESSAGE("karte_t::load()", "%d factories loaded", fab_list.get_count());
}
else {
for (int year = 0; year</*MAX_WORLD_HISTORY_YEARS*/12; year++) {
for (int cost_type = 0; cost_type</*MAX_WORLD_COST*/12; cost_type++) {
for (int cost_type = 0; cost_type<WORLD_HALTS; cost_type++) {
file->rdwr_longlong(finance_history_year[year][cost_type]);
}
}
for (int month = 0;month</*MAX_WORLD_HISTORY_MONTHS*/12;month++) {
for (int cost_type = 0; cost_type</*MAX_WORLD_COST*/12; cost_type++) {
for (int cost_type = 0; cost_type<WORLD_HALTS; cost_type++) {
file->rdwr_longlong(finance_history_month[month][cost_type]);
}
}
// WORLD_HALTS added in OTRP v56; older files have no recorded data

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このコメントは「OTRP v56 で追加」と書いてありますが、save() 側(新 4934 行目付近)のコメントには「OTRP v55 で追加」と書かれており、矛盾しています。

上の > 55>= 55 に修正した場合、「v55 以降のファイルに記録されている」という意味になるので、こちらのコメントも「v55 で追加」に統一してください。

(Claude による自動レビュー)

if( file->get_OTRP_version() > 55 ) {

@teamhimeh teamhimeh May 16, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

セーブ/ロードのバージョン判定が不一致 — ファイル破壊バグ

save() 側では WORLD_HALTS の 24 個の sint64 値(年×12 + 月×12)を無条件に書き込んでいます。そのため現在の OTRP_VERSION_MAJOR == 55 でセーブしたファイルには、バージョンスタンプ 55 の状態で WORLD_HALTS データが含まれます。

しかし load() 側のこのガードは > 55(v56 以上)でしか読まないため、v55 のセーブファイルをロードすると 192 バイト分を読み飛ばしてしまい、以降のシナリオ・motd・チャットログ等のデータ読み込み位置がずれてゲームが破壊されます。

修正: > 55>= 55 に変更してください。これにより、現在の v55 バイナリが書いたファイルも正しく読めるようになります。

save側もguardしてください

(Claude による自動レビュー)

for(int year = 0; year < /*MAX_WORLD_HISTORY_YEARS*/12; year++) {
file->rdwr_longlong(finance_history_year[year][WORLD_HALTS]);
}
for(int month = 0; month < /*MAX_WORLD_HISTORY_MONTHS*/12; month++) {
file->rdwr_longlong(finance_history_month[month][WORLD_HALTS]);
}
}
else {
for(int year = 0; year < /*MAX_WORLD_HISTORY_YEARS*/12; year++) {
finance_history_year[year][WORLD_HALTS] = 0;
}
for(int month = 0; month < /*MAX_WORLD_HISTORY_MONTHS*/12; month++) {
finance_history_month[month][WORLD_HALTS] = 0;
}
}
last_month_bev = finance_history_month[1][WORLD_CITIZENS];

if (file->is_version_atleast(112, 5) && file->is_version_less(120, 6)) {
Expand Down
1 change: 1 addition & 0 deletions simworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class karte_t
WORLD_MAIL_GENERATED, ///< all letters generated
WORLD_GOODS_RATIO, ///< ratio of chain completeness
WORLD_TRANSPORTED_GOODS, ///< all transported goods
WORLD_HALTS, ///< total number of halts (recorded from OTRP v56)
MAX_WORLD_COST
};

Expand Down
Loading