NewGRF: Allow using Action 2/3 for custom signal sprites

This is mostly the same format as the railtype custom signal mechanism
This commit is contained in:
Jonathan G Rennison
2021-08-20 00:49:48 +01:00
parent a6b0d0cde4
commit 322a046f49
10 changed files with 300 additions and 18 deletions

View File

@@ -33,6 +33,7 @@
#include "newgrf_airporttiles.h"
#include "newgrf_airport.h"
#include "newgrf_object.h"
#include "newgrf_newsignals.h"
#include "rev.h"
#include "fios.h"
#include "strings_func.h"
@@ -4058,6 +4059,39 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, c
return ret;
}
/**
* Define properties for signals
* @param id Local ID (unused).
* @param numinfo Number of subsequent IDs to change the property for.
* @param prop The property to change.
* @param buf The property value.
* @return ChangeInfoResult.
*/
static ChangeInfoResult SignalsChangeInfo(uint id, int numinfo, int prop, const GRFFilePropertyRemapEntry *mapping_entry, ByteReader *buf)
{
/* Properties which are handled per item */
ChangeInfoResult ret = CIR_SUCCESS;
for (int i = 0; i < numinfo; i++) {
switch (prop) {
case A0RPI_SIGNALS_ENABLE_PROGRAMMABLE_SIGNALS:
if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break;
SB(_cur.grffile->new_signal_ctrl_flags, NSCF_PROGSIG, 1, (buf->ReadByte() != 0 ? 1 : 0));
break;
case A0RPI_SIGNALS_ENABLE_RESTRICTED_SIGNALS:
if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break;
SB(_cur.grffile->new_signal_ctrl_flags, NSCF_RESTRICTEDSIG, 1, (buf->ReadByte() != 0 ? 1 : 0));
break;
default:
ret = HandleAction0PropertyDefault(buf, prop);
break;
}
}
return ret;
}
/**
* Ignore properties for objects
* @param prop The property to ignore.
@@ -4886,7 +4920,7 @@ static void FeatureChangeInfo(ByteReader *buf)
/* GSF_CARGOES */ nullptr, // Cargo is handled during reservation
/* GSF_SOUNDFX */ SoundEffectChangeInfo,
/* GSF_AIRPORTS */ AirportChangeInfo,
/* GSF_SIGNALS */ nullptr,
/* GSF_SIGNALS */ SignalsChangeInfo,
/* GSF_OBJECTS */ ObjectChangeInfo,
/* GSF_RAILTYPES */ RailTypeChangeInfo,
/* GSF_AIRPORTTILES */ AirportTilesChangeInfo,
@@ -5301,6 +5335,7 @@ static void NewSpriteGroup(ByteReader *buf)
case GSF_RAILTYPES:
case GSF_ROADTYPES:
case GSF_TRAMTYPES:
case GSF_SIGNALS:
{
byte num_loaded = type;
byte num_loading = buf->ReadByte();
@@ -5789,6 +5824,39 @@ static void CargoMapSpriteGroup(ByteReader *buf, uint8 idcount)
}
}
static void SignalsMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
uint8 *ids = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
ids[i] = buf->ReadByte();
}
/* Skip the cargo type section, we only care about the default group */
uint8 cidcount = buf->ReadByte();
buf->Skip(cidcount * 3);
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "SignalsMapSpriteGroup")) return;
for (uint i = 0; i < idcount; i++) {
uint8 id = ids[i];
switch (id) {
case NSA3ID_CUSTOM_SIGNALS:
_cur.grffile->new_signals_group = _cur.spritegroups[groupid];
if (!HasBit(_cur.grffile->new_signal_ctrl_flags, NSCF_GROUPSET)) {
SetBit(_cur.grffile->new_signal_ctrl_flags, NSCF_GROUPSET);
_new_signals_grfs.push_back(_cur.grffile);
}
break;
default:
grfmsg(1, "SignalsMapSpriteGroup: ID not implemented: %d", id);
break;
}
}
}
static void ObjectMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->objectspec == nullptr) {
@@ -6050,6 +6118,10 @@ static void FeatureMapSpriteGroup(ByteReader *buf)
AirportMapSpriteGroup(buf, idcount);
return;
case GSF_SIGNALS:
SignalsMapSpriteGroup(buf, idcount);
break;
case GSF_OBJECTS:
ObjectMapSpriteGroup(buf, idcount);
break;
@@ -8398,6 +8470,9 @@ static const GRFFeatureInfo _grf_feature_list[] = {
GRFFeatureInfo("action0_railtype_disable_realistic_braking", 1),
GRFFeatureInfo("action0_roadtype_extra_flags", 1),
GRFFeatureInfo("action0_global_extra_station_names", 1),
GRFFeatureInfo("action0_signals_programmable_signals", 1),
GRFFeatureInfo("action0_signals_restricted_signals", 1),
GRFFeatureInfo("action3_signals_custom_signal_sprites", 1),
GRFFeatureInfo(),
};
@@ -8520,6 +8595,8 @@ static const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = {
GRFPropertyMapDefinition(GSF_ROADTYPES, A0RPI_ROADTYPE_EXTRA_FLAGS, "roadtype_extra_flags"),
GRFPropertyMapDefinition(GSF_TRAMTYPES, A0RPI_ROADTYPE_EXTRA_FLAGS, "roadtype_extra_flags"),
GRFPropertyMapDefinition(GSF_GLOBALVAR, A0RPI_GLOBALVAR_EXTRA_STATION_NAMES, "global_extra_station_names"),
GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_ENABLE_PROGRAMMABLE_SIGNALS, "signals_enable_programmable_signals"),
GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_ENABLE_RESTRICTED_SIGNALS, "signals_enable_restricted_signals"),
GRFPropertyMapDefinition(),
};
@@ -9140,6 +9217,7 @@ static void ResetNewGRF()
_grf_files.clear();
_cur.grffile = nullptr;
_new_signals_grfs.clear();
}
/** Clear all NewGRF errors */
@@ -9314,6 +9392,9 @@ GRFFile::GRFFile(const GRFConfig *config)
this->traininfo_vehicle_pitch = 0;
this->traininfo_vehicle_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
this->new_signals_group = nullptr;
this->new_signal_ctrl_flags = 0;
/* Mark price_base_multipliers as 'not set' */
for (Price i = PR_BEGIN; i < PR_END; i++) {
this->price_base_multipliers[i] = INVALID_PRICE_MODIFIER;