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

WIP Feature: NewGRF Road Stops (Feature 14) #7955

Open
wants to merge 1 commit into
base: master
from

Conversation

@spnda
Copy link
Contributor

spnda commented Jan 22, 2020

Hey all,
After 3 years of playing OpenTTD I very appreciated the addition of Road- and Tramtypes with NRT. Now, I feel like having the same bus and truck stops everywhere looks bad and plain. Now with Feature 14, this opens up the possibility of having custom bus and truck stops. I call this NotRoadStops or for short NRS. I would guess that this would be a very appreciated addition and would bring more customizability to the game.

Status

Currently I have Action0 and Action4 "done". There's still some properties that could be added to Action0. Action2 and Action3 are uncompleted, as I still don't really understand how they work yet :( I'll work on those tomorrow.
I have already updated the GUI for building bus and trucks stops. In this current build it is possible to select between classes and between different stops, though sprites are not shown correctly. I have tried to make it look like the Rail Station GUI, or atleast as far as I could. This is not done at all and might take me a bit longer to do aswell. I just want to put this draft here, to track my own progress (I have some checkmarks at the bottom) and have some feedback and reviews.

Properties & Writing GRFs

As of now, I only have properties 08 and 09 implemented. This feature has the ID 14. (There's still more to come like animations etc.)

  • 08: DWord; The Station's Class ID. This is the same system as for example Stations.
  • 09: Byte; The Station's "type". There's 2 different types.
    • 00: Passenger, this stop is available to both bus and tram stops.
    • 01: Freight, this stop is available to both truck and freight tram stops.
    • 02: All, this stop is available to all 4 road stops.

Progress Tracking

I'm constantly posting new stuff on my discord server or on the r/OpenTTD discord.

  • Fix my own NFO code.
  • Action2 and Action3 for adding Sprites
  • Fix NRT compatibility
  • Fix and finish GUI
  • Sprite layouts and proper sprite rendering
  • Allow building of custom road stops
  • Add more Action0 properties
  • Update NML (seperate PR)

image

Test GRF File

examplegrf.zip

@spnda spnda changed the title Feature: NewGRF Road Stops (Feature 14) WIP Feature: NewGRF Road Stops (Feature 14) Jan 22, 2020
@James103
Copy link
Contributor

James103 commented Jan 22, 2020

Do you want the interface to be similar to that for NewGRF rail station building (near-exact same layout in case of trams, or similar layout with 6 buttons in 3x2 layout for roads)? If so, that would be fine and ideal by me.

@spnda
Copy link
Contributor Author

spnda commented Jan 23, 2020

Do you want the interface to be similar to that for NewGRF rail station building (near-exact same layout in case of trams, or similar layout with 6 buttons in 3x2 layout for roads)? If so, that would be fine and ideal by me.

I'm trying to come as close as I can to the rail station building GUI. Of course I can't do this new GUI exactly the same, though it will only have slight changes. Trams will of course only have 2 directions selectable while busses and trucks have 6 views to select from.

On another note, I will upload a test GRF file today... I think I might have made some mistakes in the NFO code of that file, therefore it isn't showing in the build menus...

@nielsmh nielsmh added the NewGRF label Jan 24, 2020
@nielsmh
Copy link
Contributor

nielsmh commented Jan 24, 2020

Check if you need to bump the savegame version, even if you don't require any conversion to the new map data. Basically, that an OTTD version without NRS can load a savegame with NRS without anything breaking.

@spnda spnda force-pushed the spnda:roadstops branch from fb41d4e to feb306e Feb 2, 2020
@spnda
Copy link
Contributor Author

spnda commented Feb 6, 2020

So, I've thought instead of having the trams just use bus and truck stations, give them their own stops. That way there'd be Bus, Truck, Tram and Freight Tram Stations.
This could allow for a bit more realism or variety, if someone wanted to have different stops for their trams entirely.
Is this a good idea or should it just be left as is, as a user can switch between the stations anyway?

@nielsmh
Copy link
Contributor

nielsmh commented Feb 6, 2020

I think that's definitely one of the things requested, stations specific for trams or roads.
Also consider whether you're shooting too low and should support special multi-tile stations with custom movements, and perhaps diagonal platforms support.

@spnda
Copy link
Contributor Author

spnda commented Feb 6, 2020

I kinda feel like having the stops differentiated by passenger or freight stops might be better, so that bus stops can also be used as tram stops.
I don't know, maybe we should have them split up for bus/trucks/trams/freight trams, but that would mean that a GRF might have to define multiple stations. For that, we could have a stop have define flags to be mapped onto one, some or all stops.

@spnda
Copy link
Contributor Author

spnda commented Feb 6, 2020

There's now 6 different types of RoadStops, I guess. These types define if the RoadStop is available for multiple different combinations. I've listed them in the first post. I think this is quite a optimal solution to this.

@spnda
Copy link
Contributor Author

spnda commented Feb 16, 2020

As I have been stuck on this for ~9 days now, I'll ask all here.
In my DrawRoadStopTile function (newgrf_roadstop.cpp) I just can't figure out how to draw the sprites from the NewGRF. I have checked my variables and they seem correct. I see ground_relocation/relocation have the value of the beginning of the sprite sheet I want to use as sprites. I'm pretty much completely lost here...
I'll push my changes so far in a minute.

@spnda spnda force-pushed the spnda:roadstops branch from feb306e to 97c728a Feb 16, 2020
src/newgrf_roadstop.cpp Outdated Show resolved Hide resolved
@@ -503,7 +503,7 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject &object, byte variable,
cargo += st->goods[cargo_type].cargo.TotalCount();
}
break;

This comment has been minimized.

Copy link
@planetmaker

planetmaker Feb 17, 2020

Contributor

whitespace change / addition to EOL?

This comment has been minimized.

Copy link
@spnda

spnda Feb 17, 2020

Author Contributor

I don't know where that's from. It's also a thing above and below that switch/case statement. Might be because of Visual Studio auto formatting files? Don't know.

@spnda
Copy link
Contributor Author

spnda commented Feb 17, 2020

In my case relocation is 6A6B, or 27243, which points exactly to the beginning of my sprite sheets.

DrawRailTileSeqInGUI(x, y, sprites, total_offset, relocation, palette);

When passing relocation into where total_offset is passed now, I get a SpriteID ~37000, which is obviously completely off.

Do I need to maybe calculate another value? Do I need to call DrawSprite with another SpriteID? From what I see the DrawRailTileSeqInGUI() function takes a sequence of sprites and draws them, though they don't take the newgrf offset into account, which obviously needs to happen.

@spnda spnda force-pushed the spnda:roadstops branch from 97c728a to abfe065 Feb 28, 2020
@spnda
Copy link
Contributor Author

spnda commented Feb 28, 2020

Just updated to post some newer code, which makes feature 14 use spritelayout.
Custom sprite drawing STILL doesn't work but I'll do a massive deep dive into it today.

@spnda spnda force-pushed the spnda:roadstops branch 3 times, most recently from 5fb03d2 to e27250c Jun 17, 2020
src/rev.cpp Outdated
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file rev.cpp Autogenerated file with the revision and such of OpenTTD. */

#include "stdafx.h"
#include "core/bitmath_func.hpp"
#include "rev.h"

#include "safeguards.h"

/**
* Is this version of OpenTTD a release version?
* @return True if it is a release version.
*/
bool IsReleasedVersion()
{
return HasBit(_openttd_newgrf_version, 19);
}

/**
* The text version of OpenTTD's revision.
* This will be either
* - "<tag>", like "<major>.<minor>.<build>[-RC<rc>]",
* - "<commitdate>-g<shorthash><modified>" in "master",
* - "<commitdate>-<branch>-g<shorthash><modified>" in other branches, or
* - "norev000", if the version is unknown.
*
* The major, minor and build are the numbers that describe releases of
* OpenTTD (like 0.5.3). "-RC" is used to flag release candidates.
*
* <modified> shows a "M", if the binary is made from modified source code.
*/
const char _openttd_revision[] = "20200609-roadstops-g9ec9d83f1f";

/**
* The text version of OpenTTD's build date.
* Updating the build date in this file is the safest as it generally gets
* updated for each revision in contrary to most other files that only see
* updates when they are actually changed themselves.
*/
const char _openttd_build_date[] = __DATE__ " " __TIME__;

/**
* The git revision hash of this version.
*/
const char _openttd_revision_hash[] = "9ec9d83f1fa2c8e0b47f02d7de08c6447ba6f462";

/**
* Let us know if current build was modified. This detection
* works even in the case when revision string is overridden by
* --revision argument.
* Value 0 means no modification, 1 is for unknown state
* (compiling from sources without any version control software)
* and 2 is for modified revision.
*/
const byte _openttd_revision_modified = 0;

/**
* Indicate whether this is a tagged version.
* If this is non-0, then _openttd_revision is the name of the tag,
* and the version is likely a beta, release candidate, or real release.
*/
const byte _openttd_revision_tagged = 0;

/**
* The NewGRF revision of OTTD:
* bits meaning.
* 28-31 major version
* 24-27 minor version
* 20-23 build
* 19 1 if it is a release, 0 if it is not.
* 0-18 used to be the SVN revision, now just last revision before switch to git
*
* The 19th bit is there so the development/betas/alpha, etc. leading to a
* final release will always have a lower version number than the released
* version, thus making comparisons on specific revisions easy.
*/
const uint32 _openttd_newgrf_version = 1 << 28 | 10 << 24 | 0 << 20 | 0 << 19 | 28004;
Comment on lines 1 to 83

This comment has been minimized.

Copy link
@glx22

glx22 Jun 17, 2020

Contributor

Delete this file :)

This comment has been minimized.

Copy link
@spnda

spnda Jun 18, 2020

Author Contributor

oops, I guess this is a leftover from some old version...

bool type = HasBit(p2, 0);
bool is_drive_through = HasBit(p2, 1);
RoadType rt = Extract<RoadType, 5, 6>(p2);
bool is_drive_through = HasBit(p2, 23);
RoadType rt = Extract<RoadType, 16, 6>(p2);
//RoadType rt = Extract<RoadType, 5, 6>(p2);
Comment on lines -1837 to +1840

This comment has been minimized.

Copy link
@glx22

glx22 Jun 17, 2020

Contributor

I guess regression fails because the changes here are not applied to script API.

This comment has been minimized.

Copy link
@spnda

spnda Jun 18, 2020

Author Contributor

In which way have these to be documented or implemented?

This comment has been minimized.

Copy link
@nielsmh

nielsmh Jun 19, 2020

Contributor

The code in the script API implementation that packs the parameters is separate from the code in the GUI that packs the parameters. make sure the script API packs parameters the correctly. Probably this:
https://github.com/spnda/OpenTTD/blob/e27250c4ee38708c860d513ba09266b43dc8c173/src/script/api/script_road.cpp#L534-L559

@spnda spnda force-pushed the spnda:roadstops branch from e27250c to 268383a Jun 27, 2020
@spnda spnda force-pushed the spnda:roadstops branch from 268383a to 99757b8 Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.