Skip to content

Commit

Permalink
Add: NewGRF road stops
Browse files Browse the repository at this point in the history
  • Loading branch information
JGRennison committed Dec 17, 2022
1 parent aa4975e commit e675907
Show file tree
Hide file tree
Showing 33 changed files with 2,046 additions and 123 deletions.
1 change: 1 addition & 0 deletions docs/landscape.html
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ <h3><a name="Landscape">Landscape</a></h3>
<li>m7: animation frame (railway stations/waypoints, airports)</li>
<li>m8 bits 11..6: <a href="#TramType">Tramtype</a></li>
<li>m8 bits 5..0: <a href="#TrackType">track type</a> for railway stations/waypoints</li>
<li>m8 bits 5..0: custom road stop id; 0 means standard graphics</li>
</ul>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/landscape_grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ <h3 style="font-weight: bold;">Landscape</h3>
<td class="bits"><span class="usable" title="Graphics index">OOOO O</span><span class="used" title="Graphics index: 00 (exit towards NE), 01 (exit towards SE), 02 (exit towards SW), 03 (exit towards NW), 04 (drive through X), 05 (drive through Y)">XXX</span></td>
<td class="bits" rowspan=5><span class="free">OO</span><span class="used" title="Station type">XX X</span><span class="free">OOO</span></td>
<td class="bits"><span class="free">OOO</span><span class="used" title="Owner of road">X XXXX</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="used" title="Tram type">XXXX XX<span class="free">OO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="used" title="Tram type">XXXX XX</span> <span class="used" title="Custom road stops specifications ID">XXXXXX</span></td>
</tr>
<tr>
<td class="caption">airport</td>
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ add_files(
newgrf_properties.h
newgrf_railtype.cpp
newgrf_railtype.h
newgrf_roadstop.cpp
newgrf_roadstop.h
newgrf_roadtype.cpp
newgrf_roadtype.h
newgrf_sound.cpp
Expand Down
43 changes: 40 additions & 3 deletions src/base_station_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ struct StationSpecList {
uint8 localidx; ///< Station ID within GRF of station
};

struct RoadStopSpecList {
const RoadStopSpec *spec;
uint32 grfid; ///< GRF ID of this custom road stop
uint8 localidx; ///< Station ID within GRF of road stop
};

/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
struct StationRect : public Rect {
Expand Down Expand Up @@ -62,18 +67,24 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
Owner owner; ///< The owner of this station
StationFacility facilities; ///< The facilities that this station has

std::vector<StationSpecList> speclist; ///< List of rail station specs of this station.
std::vector<StationSpecList> speclist; ///< List of rail station specs of this station.
std::vector<RoadStopSpecList> roadstop_speclist; ///< List of road stop specs of this station

Date build_date; ///< Date of construction

uint16 random_bits; ///< Random bits assigned to this station
byte waiting_triggers; ///< Waiting triggers (NewGRF) for this station
uint8 cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
CargoTypes cached_cargo_triggers; ///< NOSAVE: Combined cargo trigger bitmask
uint8 cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
uint8 cached_roadstop_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
CargoTypes cached_cargo_triggers; ///< NOSAVE: Combined cargo trigger bitmask
CargoTypes cached_roadstop_cargo_triggers; ///< NOSAVE: Combined cargo trigger bitmask for road stops

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

/**
* Initialize the base station.
* @param tile The location of the station sign
Expand Down Expand Up @@ -167,6 +178,32 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
return (this->facilities & ~FACIL_WAYPOINT) != 0;
}

inline uint GetRoadStopData(TileIndex tile) const
{
for (size_t i = 0; i < this->custom_road_stop_tiles.size(); i++) {
if (this->custom_road_stop_tiles[i] == tile) return this->custom_road_stop_data[i];
}
return 0;
}

inline byte GetRoadStopRandomBits(TileIndex tile) const
{
return GB(this->GetRoadStopData(tile), 0, 8);
}

inline byte GetRoadStopAnimationFrame(TileIndex tile) const
{
return GB(this->GetRoadStopData(tile), 8, 8);
}

private:
void SetRoadStopTileData(TileIndex tile, byte data, byte offset);

public:
inline void SetRoadStopRandomBits(TileIndex tile, byte random_bits) { this->SetRoadStopTileData(tile, random_bits, 0); }
inline void SetRoadStopAnimationFrame(TileIndex tile, byte frame) { this->SetRoadStopTileData(tile, frame, 8); }
void RemoveRoadStopTileData(TileIndex tile);

static void PostDestructor(size_t index);

private:
Expand Down
2 changes: 2 additions & 0 deletions src/cheat_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
EnginesMonthlyLoop();
SetWindowDirty(WC_STATUS_BAR, 0);
InvalidateWindowClassesData(WC_BUILD_STATION, 0);
InvalidateWindowClassesData(WC_BUS_STATION, 0);
InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
ResetSignalVariant();
return _cur_year;
Expand Down
2 changes: 2 additions & 0 deletions src/date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ static void OnNewYear()
VehiclesYearlyLoop();
TownsYearlyLoop();
InvalidateWindowClassesData(WC_BUILD_STATION);
InvalidateWindowClassesData(WC_BUS_STATION);
InvalidateWindowClassesData(WC_TRUCK_STATION);
if (_network_server) NetworkServerYearlyLoop();

if (_cur_year == _settings_client.gui.semaphore_build_before) ResetSignalVariant();
Expand Down
6 changes: 6 additions & 0 deletions src/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "newgrf_industrytiles.h"
#include "newgrf_station.h"
#include "newgrf_airporttiles.h"
#include "newgrf_roadstop.h"
#include "object.h"
#include "strings_func.h"
#include "date_func.h"
Expand Down Expand Up @@ -1813,6 +1814,8 @@ static void LoadUnloadVehicle(Vehicle *front)
TriggerStationRandomisation(st, st->xy, SRT_CARGO_TAKEN, v->cargo_type);
TriggerStationAnimation(st, st->xy, SAT_CARGO_TAKEN, v->cargo_type);
AirportAnimationTrigger(st, AAT_STATION_CARGO_TAKEN, v->cargo_type);
TriggerRoadStopAnimation(st, st->xy, SAT_NEW_CARGO, v->cargo_type);
TriggerRoadStopRandomisation(st, st->xy, RSRT_CARGO_TAKEN, v->cargo_type);
}

new_load_unload_ticks += loaded;
Expand All @@ -1833,6 +1836,9 @@ static void LoadUnloadVehicle(Vehicle *front)
if (front->type == VEH_TRAIN) {
TriggerStationRandomisation(st, front->tile, SRT_TRAIN_LOADS);
TriggerStationAnimation(st, front->tile, SAT_TRAIN_LOADS);
} else if (front->type == VEH_ROAD) {
TriggerRoadStopRandomisation(st, front->tile, RSRT_VEH_LOADS);
TriggerRoadStopAnimation(st, front->tile, SAT_TRAIN_LOADS);
}
}

Expand Down

0 comments on commit e675907

Please sign in to comment.