Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group vehicle list #12

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft

Group vehicle list #12

wants to merge 29 commits into from

Conversation

SamuXarick
Copy link
Owner

Motivation / Problem

Description

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@SamuXarick SamuXarick force-pushed the group-vehicle-list branch 3 times, most recently from bb8f4bd to 38f0bdc Compare January 4, 2024 23:27
* dummy orders. They should just vanish. Also check the actual order
* type as ot is currently OT_GOTO_STATION. */
if (order->IsType(OT_IMPLICIT)) {
order = order->next; // DeleteOrder() invalidates current order

Check notice

Code scanning / CodeQL

For loop variable changed in body Note

Loop counters should not be modified in the body of the
loop
.
src/strings.cpp Outdated
Comment on lines 924 to 1711
case VEH_AIRCRAFT: string_id = STR_SV_AIRCRAFT_NAME; break;
case SCC_WAYPOINT_NAME: { // {WAYPOINT}
Waypoint *wp = Waypoint::GetIfValid(args.GetNextParameter<StationID>());
if (wp == nullptr) break;

if (!wp->name.empty()) {
auto tmp_params = MakeParameters(wp->name);
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
} else {
auto tmp_params = MakeParameters(wp->town->index, wp->town_cn + 1);
StringID string_id = ((wp->string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
if (wp->town_cn != 0) string_id++;
GetStringWithArgs(builder, string_id, tmp_params);
}
break;
}

GetStringWithArgs(builder, string_id, tmp_params);
case SCC_VEHICLE_NAME: { // {VEHICLE}
const Vehicle *v = Vehicle::GetIfValid(args.GetNextParameter<VehicleID>());
if (v == nullptr) break;

if (!v->name.empty()) {
auto tmp_params = MakeParameters(v->name);
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
} else if (v->group_id != DEFAULT_GROUP) {
/* The vehicle has no name, but is member of a group, so print group name */
auto tmp_params = MakeParameters(v->group_id, v->unitnumber);
GetStringWithArgs(builder, STR_FORMAT_GROUP_VEHICLE_NAME, tmp_params);
} else {
auto tmp_params = MakeParameters(v->unitnumber);

StringID string_id;
switch (v->type) {
default: string_id = STR_INVALID_VEHICLE; break;
case VEH_TRAIN: string_id = STR_SV_TRAIN_NAME; break;
case VEH_ROAD: string_id = STR_SV_ROAD_VEHICLE_NAME; break;
case VEH_SHIP: string_id = STR_SV_SHIP_NAME; break;
case VEH_AIRCRAFT: string_id = STR_SV_AIRCRAFT_NAME; break;
}

GetStringWithArgs(builder, string_id, tmp_params);
}
break;
}
break;
}

case SCC_SIGN_NAME: { // {SIGN}
const Sign *si = Sign::GetIfValid(args.GetNextParameter<SignID>());
if (si == nullptr) break;
case SCC_SIGN_NAME: { // {SIGN}
const Sign *si = Sign::GetIfValid(args.GetNextParameter<SignID>());
if (si == nullptr) break;

if (!si->name.empty()) {
auto tmp_params = MakeParameters(si->name);
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
} else {
auto tmp_params = ArrayStringParameters<0>();
GetStringWithArgs(builder, STR_DEFAULT_SIGN_NAME, tmp_params);
if (!si->name.empty()) {
auto tmp_params = MakeParameters(si->name);
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
} else {
auto tmp_params = ArrayStringParameters<0>();
GetStringWithArgs(builder, STR_DEFAULT_SIGN_NAME, tmp_params);
}
break;
}
break;
}

case SCC_STATION_FEATURES: { // {STATIONFEATURES}
StationGetSpecialString(builder, args.GetNextParameter<StationFacility>());
break;
}
case SCC_STATION_FEATURES: { // {STATIONFEATURES}
StationGetSpecialString(builder, args.GetNextParameter<StationFacility>());
break;
}

case SCC_COLOUR: { // {COLOUR}
StringControlCode scc = (StringControlCode)(SCC_BLUE + args.GetNextParameter<Colours>());
if (IsInsideMM(scc, SCC_BLUE, SCC_COLOUR)) builder.Utf8Encode(scc);
break;
}
case SCC_COLOUR: { // {COLOUR}
StringControlCode scc = (StringControlCode)(SCC_BLUE + args.GetNextParameter<Colours>());
if (IsInsideMM(scc, SCC_BLUE, SCC_COLOUR)) builder.Utf8Encode(scc);
break;
}

default:
builder.Utf8Encode(b);
break;
default:
builder.Utf8Encode(b);
break;
}

Check notice

Code scanning / CodeQL

Long switch case Note

Switch has at least one case that is too long:
SCC_ENCODED (81 lines)
.
Switch has at least one case that is too long:
SCC_GENDER_LIST (32 lines)
.
Switch has at least one case that is too long:
SCC_CARGO_SHORT (33 lines)
.
Switch has at least one case that is too long:
SCC_ENGINE_NAME (31 lines)
.
Switch has at least one case that is too long:
SCC_STATION_NAME (39 lines)
.
@SamuXarick SamuXarick force-pushed the group-vehicle-list branch 4 times, most recently from 3777fed to 892a6e8 Compare January 7, 2024 10:03
@SamuXarick SamuXarick force-pushed the group-vehicle-list branch 2 times, most recently from e3aaf82 to 0d88873 Compare February 11, 2024 17:51
Use std::vector<const Vehicle *> VehicleList for these lists.
This commit prefaces the next incoming set of commit changes in order to have the vehicle lists already generated as an attempt to prevent AfterLoad actions accessing them empty.
…, ScriptVehicleList_Depot, ScriptVehicleList_Group and ScriptVehicleList_DefaultGroup
…Tick_Big_Ufo

As a compromise, the result of this change differs from the original. The iteration order changed from lowest to highest vehicle index to lowest to highest company index plus the order at which each vehicle was added to each list regardless of their indexes.
…cleAvailable

As a compromise, the result of this change differs from the original. Since the list only contains primary vehicles, free wagons aren't taken into consideration.
Additionally make the function receive one parameter more with the owner of the destination, to help it perform faster.
…UpdateServiceInterval, TrainAccelerationModelChanged, TrainSlopeSteepnessChanged, RoadVehAccelerationModelChanged, RoadVehSlopeSteepnessChanged, CheckFreeformEdges and InvalidateShipPathCache
As a compromise, the result of this change differs from the original. The VehiclePool was being iterated twice. Do it only once and assume only primary vehicles make use of last_station_visited and last_loading_station.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant