Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138465 additions and 70987 deletions

View File

@@ -22,12 +22,11 @@
/**
* Callback for building wagons.
* @param cmd Unused.
* @param result The result of the command.
* @param new_veh_id ID of the ne vehicle.
* @param tile The tile the command was executed on.
*/
void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
{
if (result.Failed()) return;
@@ -96,64 +95,63 @@ void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineIm
bool rtl = _current_text_dir == TD_RTL;
Direction dir = rtl ? DIR_E : DIR_W;
DrawPixelInfo tmp_dpi, *old_dpi;
DrawPixelInfo tmp_dpi;
/* Position of highlight box */
int highlight_l = 0;
int highlight_r = 0;
int max_width = r.Width();
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) return;
if (!FillDrawPixelInfo(&tmp_dpi, r)) return;
old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
{
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
int px = rtl ? max_width + skip : -skip;
int y = r.Height() / 2;
bool sel_articulated = false;
bool dragging = (drag_dest != INVALID_VEHICLE);
bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
/* Highlight the drag-and-drop destination inside the train. */
int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
px += rtl ? -drag_hlight_width : drag_hlight_width;
}
Point offset;
int width = Train::From(v)->GetDisplayImageWidth(&offset);
if (rtl ? px + width > 0 : px - width < max_width) {
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
VehicleSpriteSeq seq;
v->GetImage(dir, image_type, &seq);
seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0);
}
if (!v->IsArticulatedPart()) sel_articulated = false;
if (v->index == selection) {
/* Set the highlight position */
highlight_l = rtl ? px - width : px;
highlight_r = rtl ? px - 1 : px + width - 1;
sel_articulated = true;
} else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
if (rtl) {
highlight_l -= width;
} else {
highlight_r += width;
int px = rtl ? max_width + skip : -skip;
int y = r.Height() / 2;
bool sel_articulated = false;
bool dragging = (drag_dest != INVALID_VEHICLE);
bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
/* Highlight the drag-and-drop destination inside the train. */
int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
px += rtl ? -drag_hlight_width : drag_hlight_width;
}
Point offset;
int width = Train::From(v)->GetDisplayImageWidth(&offset);
if (rtl ? px + width > 0 : px - width < max_width) {
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
VehicleSpriteSeq seq;
v->GetImage(dir, image_type, &seq);
seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0);
}
if (!v->IsArticulatedPart()) sel_articulated = false;
if (v->index == selection) {
/* Set the highlight position */
highlight_l = rtl ? px - width : px;
highlight_r = rtl ? px - 1 : px + width - 1;
sel_articulated = true;
} else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
if (rtl) {
highlight_l -= width;
} else {
highlight_r += width;
}
}
px += rtl ? -width : width;
}
px += rtl ? -width : width;
if (dragging && drag_at_end_of_train) {
/* Highlight the drag-and-drop destination at the end of the train. */
HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
}
}
if (dragging && drag_at_end_of_train) {
/* Highlight the drag-and-drop destination at the end of the train. */
HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
}
_cur_dpi = old_dpi;
if (highlight_l != highlight_r) {
/* Draw the highlight. Now done after drawing all the engines, as
* the next engine after the highlight could overlap it. */
@@ -210,11 +208,10 @@ static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int rig
SetDParam(3, _settings_game.vehicle.freight_trains);
str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM;
} else {
SetDParam(0, STR_QUANTITY_N_A);
str = item->cargo == INVALID_CARGO ? STR_LTBLUE_STRING : STR_VEHICLE_DETAILS_CARGO_EMPTY;
str = !IsValidCargoID(item->cargo) ? STR_QUANTITY_N_A : STR_VEHICLE_DETAILS_CARGO_EMPTY;
}
DrawString(left, right, y, str);
DrawString(left, right, y, str, TC_LIGHT_BLUE);
}
/**
@@ -250,7 +247,7 @@ static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
{
StringID str;
if (item->cargo != INVALID_CARGO) {
if (IsValidCargoID(item->cargo)) {
SetDParam(0, item->cargo);
SetDParam(1, item->capacity);
SetDParam(4, item->subtype);
@@ -269,21 +266,20 @@ static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int
* @param v Vehicle to process
* @param summary Space for the result
*/
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *summary)
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
{
summary->clear();
summary.clear();
do {
if (!v->GetEngine()->CanCarryCargo()) continue;
CargoSummaryItem new_item;
new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
new_item.subtype = GetCargoSubtypeText(v);
if (new_item.cargo == INVALID_CARGO && new_item.subtype == STR_EMPTY) continue;
if (!IsValidCargoID(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;
auto item = std::find(summary->begin(), summary->end(), new_item);
if (item == summary->end()) {
summary->emplace_back();
item = summary->end() - 1;
auto item = std::find(std::begin(summary), std::end(summary), new_item);
if (item == std::end(summary)) {
item = summary.emplace(std::end(summary));
item->cargo = new_item.cargo;
item->subtype = new_item.subtype;
item->capacity = 0;
@@ -293,7 +289,7 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *su
item->capacity += v->cargo_cap;
item->amount += v->cargo.StoredCount();
if (item->source == INVALID_STATION) item->source = v->cargo.Source();
if (item->source == INVALID_STATION) item->source = v->cargo.GetFirstStation();
} while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
}
@@ -324,23 +320,16 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
int num = 0;
if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
CargoArray act_cargo;
CargoArray max_cargo;
CargoArray max_cargo{};
for (const Vehicle *v = Vehicle::Get(veh_id); v != nullptr; v = v->Next()) {
act_cargo[v->cargo_type] += v->cargo.StoredCount();
max_cargo[v->cargo_type] += v->cargo_cap;
}
/* Set scroll-amount separately from counting, as to not compute num double
* for more carriages of the same type
*/
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (max_cargo[i] > 0) num++; // only count carriages that the train has
}
num = max_cargo.GetCount();
num++; // needs one more because first line is description string
} else {
for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
num += std::max(1u, (unsigned)_cargo_summary.size());
uint length = GetLengthOfArticulatedVehicle(v);
@@ -360,19 +349,19 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
* @param vscroll_cap Number of lines currently displayed
* @param det_tab Selected details tab
*/
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
{
bool rtl = _current_text_dir == TD_RTL;
int line_height = r.Height();
int sprite_y_offset = line_height / 2;
int text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
/* draw the first 3 details tabs */
if (det_tab != TDW_TAB_TOTALS) {
Direction dir = rtl ? DIR_E : DIR_W;
int x = rtl ? r.right : r.left;
for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
GetCargoSummaryOfArticulatedVehicle(v, &_cargo_summary);
GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
/* Draw sprites */
uint dx = 0;
@@ -387,7 +376,7 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16 vsc
if (e->GetGRF() != nullptr) {
pitch = ScaleSpriteTrad(e->GetGRF()->traininfo_vehicle_pitch);
}
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
VehicleSpriteSeq seq;
u->GetImage(dir, EIT_IN_DETAILS, &seq);
seq.Draw(px + (rtl ? -offset.x : offset.x), r.top - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->vehstatus & VS_CRASHED) != 0);
@@ -442,14 +431,14 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16 vsc
}
} else {
int y = r.top;
CargoArray act_cargo;
CargoArray max_cargo;
CargoArray act_cargo{};
CargoArray max_cargo{};
Money feeder_share = 0;
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
act_cargo[u->cargo_type] += u->cargo.StoredCount();
max_cargo[u->cargo_type] += u->cargo_cap;
feeder_share += u->cargo.FeederShare();
feeder_share += u->cargo.GetFeederShare();
}
/* draw total cargo tab */
@@ -458,14 +447,15 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16 vsc
/* Indent the total cargo capacity details */
Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
SetDParam(0, i); // {CARGO} #1
SetDParam(1, act_cargo[i]); // {CARGO} #2
SetDParam(2, i); // {SHORTCARGO} #1
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
for (const CargoSpec *cs : _sorted_cargo_specs) {
CargoID cid = cs->Index();
if (max_cargo[cid] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
SetDParam(0, cid); // {CARGO} #1
SetDParam(1, act_cargo[cid]); // {CARGO} #2
SetDParam(2, cid); // {SHORTCARGO} #1
SetDParam(3, max_cargo[cid]); // {SHORTCARGO} #2
SetDParam(4, _settings_game.vehicle.freight_trains);
DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(cid) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
y += line_height;
}
}