Network: Include town noise levels in network game saves
Don't recalculate on load for network clients
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
static bool _town_zone_radii_no_update = false;
|
static bool _town_zone_radii_no_update = false;
|
||||||
|
|
||||||
|
extern bool _town_noise_no_update;
|
||||||
extern bool IsGetTownZonesCallbackHandlerPresent();
|
extern bool IsGetTownZonesCallbackHandlerPresent();
|
||||||
|
|
||||||
HouseID SLGetCleanHouseType(TileIndex t, bool old_map_position)
|
HouseID SLGetCleanHouseType(TileIndex t, bool old_map_position)
|
||||||
@@ -372,6 +373,7 @@ static void Ptrs_TOWN()
|
|||||||
|
|
||||||
void SlResetTNNC()
|
void SlResetTNNC()
|
||||||
{
|
{
|
||||||
|
_town_noise_no_update = false;
|
||||||
_town_zone_radii_no_update = false;
|
_town_zone_radii_no_update = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,22 +381,34 @@ void Save_TNNC()
|
|||||||
{
|
{
|
||||||
assert(_sl_xv_feature_versions[XSLFI_TNNC_CHUNK] != 0);
|
assert(_sl_xv_feature_versions[XSLFI_TNNC_CHUNK] != 0);
|
||||||
|
|
||||||
if (!IsNetworkServerSave() || !IsGetTownZonesCallbackHandlerPresent()) {
|
if (!IsNetworkServerSave()) {
|
||||||
SlSetLength(0);
|
SlSetLength(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlSetLength(4 + (Town::GetNumItems() * (1 + lengthof(TownCache::squared_town_zone_radius)) * 4));
|
size_t length = 8 + (Town::GetNumItems() * 6);
|
||||||
|
uint32 flags = 0;
|
||||||
|
|
||||||
|
if (IsGetTownZonesCallbackHandlerPresent()) {
|
||||||
|
flags |= 1;
|
||||||
|
length += lengthof(TownCache::squared_town_zone_radius) * 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
SlSetLength(length);
|
||||||
|
|
||||||
|
SlWriteUint32(flags);
|
||||||
SlWriteUint32((uint32)Town::GetNumItems());
|
SlWriteUint32((uint32)Town::GetNumItems());
|
||||||
|
|
||||||
for (const Town *t : Town::Iterate()) {
|
for (const Town *t : Town::Iterate()) {
|
||||||
SlWriteUint32(t->index);
|
SlWriteUint32(t->index);
|
||||||
|
SlWriteUint16(t->noise_reached);
|
||||||
|
if (flags & 2) {
|
||||||
for (uint i = 0; i < lengthof(TownCache::squared_town_zone_radius); i++) {
|
for (uint i = 0; i < lengthof(TownCache::squared_town_zone_radius); i++) {
|
||||||
SlWriteUint32(t->cache.squared_town_zone_radius[i]);
|
SlWriteUint32(t->cache.squared_town_zone_radius[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Load_TNNC()
|
void Load_TNNC()
|
||||||
{
|
{
|
||||||
@@ -405,16 +419,22 @@ void Load_TNNC()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_town_zone_radii_no_update = true;
|
const uint32 flags = SlReadUint32();
|
||||||
|
|
||||||
const uint32 count = SlReadUint32();
|
const uint32 count = SlReadUint32();
|
||||||
|
|
||||||
|
_town_noise_no_update = true;
|
||||||
|
_town_zone_radii_no_update = (flags & 1);
|
||||||
|
|
||||||
for (uint32 idx = 0; idx < count; idx++) {
|
for (uint32 idx = 0; idx < count; idx++) {
|
||||||
Town *t = Town::Get(SlReadUint32());
|
Town *t = Town::Get(SlReadUint32());
|
||||||
|
t->noise_reached = SlReadUint16();
|
||||||
|
if (flags & 1) {
|
||||||
for (uint i = 0; i < lengthof(TownCache::squared_town_zone_radius); i++) {
|
for (uint i = 0; i < lengthof(TownCache::squared_town_zone_radius); i++) {
|
||||||
t->cache.squared_town_zone_radius[i] = SlReadUint32();
|
t->cache.squared_town_zone_radius[i] = SlReadUint32();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static ChunkSaveLoadSpecialOpResult Special_TNNC(uint32 chunk_id, ChunkSaveLoadSpecialOp op)
|
static ChunkSaveLoadSpecialOpResult Special_TNNC(uint32 chunk_id, ChunkSaveLoadSpecialOp op)
|
||||||
{
|
{
|
||||||
|
@@ -70,6 +70,8 @@
|
|||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
bool _town_noise_no_update = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given tile is a hangar.
|
* Check whether the given tile is a hangar.
|
||||||
* @param t the tile to of whether it is a hangar.
|
* @param t the tile to of whether it is a hangar.
|
||||||
@@ -2639,6 +2641,8 @@ Town *AirportGetNearestTown(const AirportSpec *as, TileIndex tile, const TileIte
|
|||||||
/** Recalculate the noise generated by the airports of each town */
|
/** Recalculate the noise generated by the airports of each town */
|
||||||
void UpdateAirportsNoise()
|
void UpdateAirportsNoise()
|
||||||
{
|
{
|
||||||
|
if (_town_noise_no_update) return;
|
||||||
|
|
||||||
for (Town *t : Town::Iterate()) t->noise_reached = 0;
|
for (Town *t : Town::Iterate()) t->noise_reached = 0;
|
||||||
|
|
||||||
for (const Station *st : Station::Iterate()) {
|
for (const Station *st : Station::Iterate()) {
|
||||||
|
Reference in New Issue
Block a user