2022-06-13 01:53:27 +00:00
|
|
|
/*
|
|
|
|
* 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 newgrf_newlandscape.cpp NewGRF handling of new landscape. */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "newgrf_newlandscape.h"
|
|
|
|
#include "newgrf_extension.h"
|
|
|
|
#include "map_func.h"
|
|
|
|
#include "clear_map.h"
|
|
|
|
#include "core/hash_func.hpp"
|
2022-12-12 19:15:19 +00:00
|
|
|
#include "string_func.h"
|
2022-06-13 01:53:27 +00:00
|
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
|
|
std::vector<const GRFFile *> _new_landscape_rocks_grfs;
|
|
|
|
|
|
|
|
/* virtual */ uint32 NewLandscapeScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const
|
|
|
|
{
|
|
|
|
if (unlikely(this->ti->tile == INVALID_TILE)) {
|
|
|
|
switch (variable) {
|
|
|
|
case 0x40: return 0;
|
|
|
|
case 0x41: return 0;
|
|
|
|
case 0x42: return 0;
|
|
|
|
case 0x43: return 0;
|
|
|
|
case 0x44: return this->landscape_type;
|
|
|
|
case 0x60: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
case 0x40:
|
|
|
|
return GetTerrainType(this->ti->tile, TCX_NORMAL);
|
|
|
|
|
|
|
|
case 0x41:
|
|
|
|
return this->ti->tileh;
|
|
|
|
|
|
|
|
case 0x42:
|
|
|
|
return this->ti->z / TILE_HEIGHT;
|
|
|
|
|
|
|
|
case 0x43:
|
|
|
|
return SimpleHash32(this->ti->tile);
|
|
|
|
|
|
|
|
case 0x44:
|
|
|
|
return this->landscape_type;
|
|
|
|
|
2022-12-12 23:19:44 +00:00
|
|
|
case 0x45:
|
|
|
|
return GetClearDensity(this->ti->tile) | (IsSnowTile(this->ti->tile) ? 0x10 : 0);
|
|
|
|
|
2022-06-13 01:53:27 +00:00
|
|
|
case 0x60: {
|
|
|
|
TileIndex tile = this->ti->tile;
|
|
|
|
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
|
|
|
|
uint32 result = 0;
|
2022-12-12 19:15:19 +00:00
|
|
|
if (extra->mask & ~0x100) result |= GetNearbyTileInformation(tile, this->ro.grffile == nullptr || this->ro.grffile->grf_version >= 8, extra->mask);
|
2022-06-13 01:53:27 +00:00
|
|
|
if (extra->mask & 0x100) {
|
|
|
|
switch (this->landscape_type) {
|
|
|
|
case NEW_LANDSCAPE_ROCKS:
|
|
|
|
if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_ROCKS)) result |= 0x100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(grf, 1, "Unhandled new landscape tile variable 0x%X", variable);
|
|
|
|
|
|
|
|
extra->available = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ const SpriteGroup *NewLandscapeResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
|
|
|
{
|
|
|
|
if (!group->loading.empty()) return group->loading[0];
|
|
|
|
if (!group->loaded.empty()) return group->loaded[0];
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrfSpecFeature NewLandscapeResolverObject::GetFeature() const
|
|
|
|
{
|
|
|
|
return GSF_NEWLANDSCAPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewLandscapeResolverObject::NewLandscapeResolverObject(const GRFFile *grffile, const TileInfo *ti, NewLandscapeType landscape_type, uint32 param1, uint32 param2)
|
|
|
|
: ResolverObject(grffile, CBID_NO_CALLBACK, param1, param2), newlandscape_scope(*this, ti, landscape_type)
|
|
|
|
{
|
|
|
|
if (grffile != nullptr) {
|
|
|
|
switch (landscape_type) {
|
|
|
|
case NEW_LANDSCAPE_ROCKS:
|
|
|
|
this->root_spritegroup = grffile->new_rocks_group;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
this->root_spritegroup = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this->root_spritegroup = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2022-12-12 19:15:19 +00:00
|
|
|
|
|
|
|
void DumpNewLandscapeRocksSpriteGroups(DumpSpriteGroupPrinter print)
|
|
|
|
{
|
|
|
|
SpriteGroupDumper dumper(print);
|
|
|
|
bool first = true;
|
|
|
|
for (const GRFFile *grf : _new_landscape_rocks_grfs) {
|
|
|
|
if (!first) print(nullptr, DSGPO_PRINT, 0, "");
|
|
|
|
char buffer[64];
|
|
|
|
seprintf(buffer, lastof(buffer), "GRF: %08X", BSWAP32(grf->grfid));
|
|
|
|
print(nullptr, DSGPO_PRINT, 0, buffer);
|
|
|
|
first = false;
|
|
|
|
dumper.DumpSpriteGroup(grf->new_rocks_group, 0);
|
|
|
|
}
|
|
|
|
}
|