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

Add: NewGRF road stops #10144

Merged
merged 1 commit into from Feb 26, 2023
Merged

Conversation

JGRennison
Copy link
Contributor

@JGRennison JGRennison commented Nov 6, 2022

Motivation / Problem

Add NewGRF road stops.
Loosely based on #7955. but with various things added, removed, changed, fixed, etc. The NewGRF interfaces do not match.

Description

The implementation and NewGRF interface broadly matches the implementation in the JGR patchpack branch.

However various things have been removed as they are not applicable to this branch:

  • Road waypoints (however the WAYP class ID is still reserved)
  • One way road stops support
  • Bridge over road stops support
  • Feature detection, name/ID mapping, etc.

The interface is as described here, except without all the JGR patchpack specific stuff, as described above.
The feature is allocated to the ID: 0x14.
Specifically the following have been removed with respect to the above interface description:

  • Bit 2 of property C
  • Bit 1 of property 12
  • Properties 13 and 14
  • Value 2 of variable 41
  • Variable 50
  • Bits 21 - 22 of variable 68
  • Variable 6B (can be added if interest exists)

The NML interface is described here, with the same set of items removed as listed above.
This corresponds to: RST_DRAW_FLAG_WAYPOINT_GROUND, RST_GENERAL_FLAG_NO_ONE_WAY_OVERLAY, minimum_bridge_height, disallowed_bridge_pillars, RST_TYPE_WAYPOINT, one_way_info, nearby_tile_one_way_info, nearby_tile_road/tram variables.

A branch which implements this can be found here: here (upstream-road-stops branch).

Limitations

This cannot be used with existing road stop GRFs which target the JGR patchpack branch.

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, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@JGRennison
Copy link
Contributor Author

roadstops_test_nml.zip

Test GRF with very ugly graphics

@2TallTyler 2TallTyler added the size: large This Pull Request is large in size; review will take a while label Nov 6, 2022
Copy link
Member

@PeterN PeterN left a comment

Choose a reason for hiding this comment

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

Quick initial skim...

src/saveload/station_sl.cpp Outdated Show resolved Hide resolved
src/saveload/station_sl.cpp Outdated Show resolved Hide resolved
src/station.cpp Outdated Show resolved Hide resolved
@michicc michicc added component: NewGRF This issue is related to NewGRFs needs review: NewGRF Review requested from a NewGRF expert labels Nov 6, 2022
@JGRennison JGRennison marked this pull request as ready for review December 15, 2022 18:07
@JGRennison JGRennison changed the title Add: NewGRF road stops Draft: Add: NewGRF road stops Dec 15, 2022
@JGRennison JGRennison marked this pull request as draft December 15, 2022 18:13
@JGRennison JGRennison force-pushed the upstream_road_stops branch 2 times, most recently from e2af225 to 7d9f480 Compare December 17, 2022 01:13
@JGRennison JGRennison changed the title Draft: Add: NewGRF road stops Add: NewGRF road stops Dec 17, 2022
@JGRennison JGRennison marked this pull request as ready for review December 17, 2022 01:20
src/cheat_gui.cpp Show resolved Hide resolved
/**
* Helper class for a unified approach to NewGRF animation.
* @tparam Tbase Instantiation of this class.
* @tparam Tspec NewGRF specification related to the animated tile.
* @tparam Tobj Object related to the animated tile.
* @tparam Textra Custom extra callback data.
* @tparam GetCallback The callback function pointer.
* @tparam Tframehelper The animation frame get/set helper.
Copy link
Contributor

Choose a reason for hiding this comment

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

It breaks the indentation. :)

@@ -4707,6 +4708,131 @@ static ChangeInfoResult AirportTilesChangeInfo(uint airtid, int numinfo, int pro
return ret;
}

/**
* Ignore properties for roadstops
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Ignore properties for roadstops
* Ignore properties for roadstops.

Although the period seems to be used mixed at the end of sentences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the other comments in this file and the wider codebase

GUIRoadStopClassList roadstop_classes; ///< Available road stop classes.
StringFilter string_filter; ///< Filter for available road stop classes.
QueryString filter_editbox; ///< Filter editbox.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are mixed signals above whether the comments should be aligned or not. :)

src/newgrf_roadstop.h Show resolved Hide resolved
@reldred
Copy link

reldred commented Dec 27, 2022

I'm not liable to compile this any time soon for this implementation, but I've coded up Fridaemons warehouses as roadstops in NML over here: https://github.com/reldred/re_foars

Code is nothing fancy, but removing the JGRPP specific code it should, I'm told, compile fine.

I know I haven't specified a license in the repo, but it inherits GPLv2 by virtue of Fridaemons sprites.

@JGRennison
Copy link
Contributor Author

re_foars.zip
Above GRF built for this PR

@glx22
Copy link
Contributor

glx22 commented Dec 27, 2022

I triggered a release build for this PR, will be available on https://www.openttd.org/downloads/openttd-branches/pr10144/latest when done.

src/economy.cpp Show resolved Hide resolved
enum RoadStopClassID : byte {
ROADSTOP_CLASS_BEGIN = 0, ///< The lowest valid value
ROADSTOP_CLASS_DFLT = 0, ///< Default road stop class.
ROADSTOP_CLASS_WAYP, ///< Waypoint class.
Copy link
Member

Choose a reason for hiding this comment

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

Are waypoints relevant for road? Reserved for future (and jgrpp) use I suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Road waypoints is already implemented with custom road stops support in my branch.
Not reserving the class ID would make adding this to vanilla in future a bit less straightforward.
I am not precious about removing that if it isn't wanted though.

Copy link
Member

Choose a reason for hiding this comment

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

Reserving it is fine imho, maybe with a note in the comment.


RoadStopScopeResolver(ResolverObject& ro, BaseStation* st, const RoadStopSpec *roadstopspec, TileIndex tile, RoadType roadtype, StationType type, uint8 view = 0)
: ScopeResolver(ro), tile(tile), st(st), roadstopspec(roadstopspec), type(type), view(view), roadtype(roadtype)
{
Copy link
Member

Choose a reason for hiding this comment

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

Indentation

RoadStopResolverObject(const RoadStopSpec* roadstopspec, BaseStation* st, TileIndex tile, RoadType roadtype, StationType type, uint8 view, CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
~RoadStopResolverObject();

ScopeResolver* GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override {
Copy link
Member

Choose a reason for hiding this comment

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

Newline before {


TileArea train_station; ///< Tile area the train 'station' part covers
StationRect rect; ///< NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions

std::vector<TileIndex> custom_road_stop_tiles; ///< List of custom road stop tiles
std::vector<uint16> custom_road_stop_data; ///< Custom road stop random bits (low) and animation byte (high) in same order as custom_road_stop_tiles
Copy link
Member

Choose a reason for hiding this comment

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

Would this be better as a single vector containing a struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes saveload with the new system a bit less straightforward, I should be able to do that later though.

src/station.cpp Show resolved Hide resolved
src/station_cmd.cpp Show resolved Hide resolved
@JGRennison
Copy link
Contributor Author

The savegame format has changed since the last update of this PR as per comments above.

Copy link
Member

@PeterN PeterN left a comment

Choose a reason for hiding this comment

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

Not completely reviewed, just some naming ideas.

return specindex < st->roadstop_speclist.size() ? st->roadstop_speclist[specindex].spec : nullptr;
}

int AllocateRoadStopSpecToStation(const RoadStopSpec *statspec, BaseStation *st, bool exec)
Copy link
Member

Choose a reason for hiding this comment

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

AllocateSpecToRoadStop might be less wordy?

return i;
}

void DeallocateRoadStopSpecFromStation(BaseStation *st, byte specindex)
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, DeallocateSpecFromRoadStop?

* Update the cached animation trigger bitmask for a station.
* @param st Station to update.
*/
void StationUpdateRoadStopCachedTriggers(BaseStation *st)
Copy link
Member

Choose a reason for hiding this comment

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

RoadStopUpdateCachedTriggers?

src/station_cmd.cpp Fixed Show fixed Hide fixed
src/road_gui.cpp Fixed Show fixed Hide fixed
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

A few things, but nothing merge-blocking

Comment on lines +98 to +102
/* Road type */
case 0x43: return get_road_type_variable(RTT_ROAD);

/* Tram type */
case 0x44: return get_road_type_variable(RTT_TRAM);
Copy link
Member

Choose a reason for hiding this comment

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

I'd be tempted to use fallthrough & a RoadTramType rtt = 0x43 ? RTT_ROAD : RTT_TRAM variable personally, but eh

Comment on lines +1242 to +1246
/** Sort classes by RoadStopClassID. */
static bool RoadStopClassIDSorter(RoadStopClassID const &a, RoadStopClassID const &b)
{
return a < b;
}
Copy link
Member

Choose a reason for hiding this comment

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

is this function even needed? Seems pretty trivial...

Comment on lines +645 to +650
bool IsInspectable(uint index) const override { return GetRoadStopSpec(index) != nullptr; }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, BaseStation::GetByTile(index)->town->index); }
const void *GetInstance(uint index)const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetRoadStopSpec(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(index)->grf_prop.grffile->grfid : 0; }
Copy link
Member

Choose a reason for hiding this comment

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

some unusual alignment here :)

@andythenorth
Copy link
Contributor

@andythenorth
Copy link
Contributor

andythenorth commented Sep 16, 2023

Plan for updating newgrf docs, based on https://jgrennison.github.io/OpenTTD-patches/newgrf-roadstops.html#a0roadstops

This is based initially on the the list of differences in the description for this PR. I haven't read the actual diff or the subsequent review comments in this PR (can do if needed).

Action 0

  • Copy except for
    • prop 0C, drop the entry for bit 2 (road waypoints)
    • prop 12, bits 1, 7, 8 are not implemented, mark as such in the table
    • prop 13 - drop
    • prop 14 - drop
    • prop 16 - drop

Action 1

Nothing needed specific to roadstops.

Action 2

Roadstops entry in newgrf index page already links to relevant sprite layout page https://newgrf-specs.tt-wiki.net/wiki/Action2/Sprite_Layout

No other action needed.

Varaction 2

  • Copy except for
    • Var 41, drop the entry for bit 2 (tile is road waypoint)
    • Var 50, drop (miscellaneous roadstop info)
    • Var 68, bits 21-22 and 24-31 are not implemented, mark as such
    • Var 6B, drop (road info of nearby plain road tiles)
  • do roadstops use BaseStation vars? If so, also link https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/BaseStation

Random Action 2

Action 3

Roadstops entry in newgrf index page already links to relevant sprite layout page https://newgrf-specs.tt-wiki.net/wiki/Action3

No other action needed?

@JGRennison
Copy link
Contributor Author

Additions to the above:
Action 0 property 12, bits 1, 7, 8 are not implemented
Action 0 property 16 is not implemented
Action 2 variable 68, bits 21-22 and 24-31 are not implemented

@JGRennison JGRennison deleted the upstream_road_stops branch January 9, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: NewGRF This issue is related to NewGRFs needs review: NewGRF Review requested from a NewGRF expert size: large This Pull Request is large in size; review will take a while
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants