Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -112,7 +112,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
|
||||
if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) {
|
||||
uint16_t res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile);
|
||||
if (res != CALLBACK_FAILED) {
|
||||
if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res);
|
||||
if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_COLOUR, res);
|
||||
o->colour = GB(res, 0, 8);
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,8 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
|
||||
assert(o->town != nullptr);
|
||||
|
||||
for (TileIndex t : ta) {
|
||||
if (IsWaterTile(t)) ClearNeighbourNonFloodingStates(t);
|
||||
if (HasTileWaterGround(t)) InvalidateWaterRegion(t);
|
||||
WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID);
|
||||
/* Update company infrastructure counts for objects build on canals owned by nobody. */
|
||||
if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(t, OWNER_NONE) || IsTileOwner(t, OWNER_WATER))) {
|
||||
@@ -163,7 +165,7 @@ void UpdateCompanyHQ(TileIndex tile, uint score)
|
||||
{
|
||||
if (tile == INVALID_TILE) return;
|
||||
|
||||
byte val = 0;
|
||||
uint8_t val = 0;
|
||||
if (score >= 170) val++;
|
||||
if (score >= 350) val++;
|
||||
if (score >= 520) val++;
|
||||
@@ -218,14 +220,14 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
if ((spec->flags & OBJECT_FLAG_ONLY_IN_GAME) != 0 && (_generating_world || _game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;
|
||||
if (view >= spec->views) return CMD_ERROR;
|
||||
|
||||
if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS);
|
||||
if (Town::GetNumItems() == 0) return_cmd_error(STR_ERROR_MUST_FOUND_TOWN_FIRST);
|
||||
if (!Object::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_OBJECTS);
|
||||
if (Town::GetNumItems() == 0) return CommandCost(STR_ERROR_MUST_FOUND_TOWN_FIRST);
|
||||
|
||||
int size_x = GB(spec->size, HasBit(view, 0) ? 4 : 0, 4);
|
||||
int size_y = GB(spec->size, HasBit(view, 0) ? 0 : 4, 4);
|
||||
TileArea ta(tile, size_x, size_y);
|
||||
for (TileIndex t : ta) {
|
||||
if (!IsValidTile(t)) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map
|
||||
if (!IsValidTile(t)) return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map
|
||||
}
|
||||
|
||||
if (type == OBJECT_OWNED_LAND) {
|
||||
@@ -239,7 +241,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
|
||||
for (TileIndex t : ta) {
|
||||
if (HasTileWaterGround(t)) {
|
||||
if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
if (!allow_water) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
if (!IsWaterTile(t)) {
|
||||
/* Normal water tiles don't have to be cleared. For all other tile types clear
|
||||
* the tile but leave the water. */
|
||||
@@ -253,7 +255,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
cost.AddCost(EnsureNoVehicleOnGround(t));
|
||||
}
|
||||
} else {
|
||||
if (!allow_ground) return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
|
||||
if (!allow_ground) return CommandCost(STR_ERROR_MUST_BE_BUILT_ON_WATER);
|
||||
/* For non-water tiles, we'll have to clear it before building. */
|
||||
|
||||
/* When relocating HQ, allow it to be relocated (partial) on itself. */
|
||||
@@ -267,8 +269,8 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
}
|
||||
|
||||
/* So, now the surface is checked... check the slope of said surface. */
|
||||
int allowed_z;
|
||||
if (GetTileSlope(tile, &allowed_z) != SLOPE_FLAT) allowed_z++;
|
||||
auto [slope, allowed_z] = GetTileSlopeZ(tile);
|
||||
if (slope != SLOPE_FLAT) allowed_z++;
|
||||
|
||||
for (TileIndex t : ta) {
|
||||
uint16_t callback = CALLBACK_FAILED;
|
||||
@@ -308,7 +310,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
if (IsBridgeAbove(t) && (
|
||||
!(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) ||
|
||||
(GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,14 +319,14 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
switch (type) {
|
||||
case OBJECT_TRANSMITTER:
|
||||
case OBJECT_LIGHTHOUSE:
|
||||
if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
|
||||
if (!IsTileFlat(tile)) return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
|
||||
break;
|
||||
|
||||
case OBJECT_OWNED_LAND:
|
||||
if (IsTileType(tile, MP_OBJECT) &&
|
||||
IsTileOwner(tile, _current_company) &&
|
||||
IsObjectType(tile, OBJECT_OWNED_LAND)) {
|
||||
return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
|
||||
return CommandCost(STR_ERROR_YOU_ALREADY_OWN_IT);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -332,7 +334,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
Company *c = Company::Get(_current_company);
|
||||
if (c->location_of_HQ != INVALID_TILE) {
|
||||
/* Don't relocate HQ on the same location. */
|
||||
if (c->location_of_HQ == tile) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
if (c->location_of_HQ == tile) return CommandCost(STR_ERROR_ALREADY_BUILT);
|
||||
/* We need to persuade a bit harder to remove the old HQ. */
|
||||
_current_company = OWNER_WATER;
|
||||
cost.AddCost(ClearTile_Object(c->location_of_HQ, flags));
|
||||
@@ -360,12 +362,11 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type,
|
||||
/* Don't allow building more objects if the company has reached its limit. */
|
||||
Company *c = Company::GetIfValid(_current_company);
|
||||
if (c != nullptr && GB(c->build_object_limit, 16, 16) < build_object_size) {
|
||||
return_cmd_error(STR_ERROR_BUILD_OBJECT_LIMIT_REACHED);
|
||||
return CommandCost(STR_ERROR_BUILD_OBJECT_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
BuildObject(type, tile, _current_company == OWNER_DEITY ? OWNER_NONE : _current_company, nullptr, view);
|
||||
for (TileIndex t : ta) InvalidateWaterRegion(t);
|
||||
|
||||
/* Make sure the HQ starts at the right size. */
|
||||
if (type == OBJECT_HQ) UpdateCompanyHQ(tile, hq_score);
|
||||
@@ -493,8 +494,7 @@ static void DrawTile_Object(TileInfo *ti)
|
||||
static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y, bool)
|
||||
{
|
||||
if (IsObjectType(tile, OBJECT_OWNED_LAND)) {
|
||||
int z;
|
||||
Slope tileh = GetTilePixelSlope(tile, &z);
|
||||
auto [tileh, z] = GetTilePixelSlope(tile);
|
||||
|
||||
return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
|
||||
} else {
|
||||
@@ -559,10 +559,10 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
||||
if (_current_company != OWNER_WATER) {
|
||||
if ((flags & DC_NO_WATER) && IsTileOnWater(tile)) {
|
||||
/* There is water under the object, treat it as water tile. */
|
||||
return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
} else if (!(spec->flags & OBJECT_FLAG_AUTOREMOVE) && (flags & DC_AUTO)) {
|
||||
/* No automatic removal by overbuilding stuff. */
|
||||
return_cmd_error(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY);
|
||||
return CommandCost(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY);
|
||||
} else if (_game_mode == GM_EDITOR) {
|
||||
/* No further limitations for the editor. */
|
||||
} else if (GetTileOwner(tile) == OWNER_NONE) {
|
||||
@@ -570,11 +570,11 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
||||
if (!_cheats.magic_bulldozer.value && (spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0) return CMD_ERROR;
|
||||
} else if (CheckTileOwnership(tile).Failed()) {
|
||||
/* We don't own it!. */
|
||||
return_cmd_error(STR_ERROR_OWNED_BY);
|
||||
return CommandCost(STR_ERROR_OWNED_BY);
|
||||
} else if ((spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0 && (spec->flags & OBJECT_FLAG_AUTOREMOVE) == 0) {
|
||||
/* In the game editor or with cheats we can remove, otherwise we can't. */
|
||||
if (!_cheats.magic_bulldozer.value) {
|
||||
if (type == OBJECT_HQ) return_cmd_error(STR_ERROR_COMPANY_HEADQUARTERS_IN);
|
||||
if (type == OBJECT_HQ) return CommandCost(STR_ERROR_COMPANY_HEADQUARTERS_IN);
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
||||
return cost;
|
||||
}
|
||||
|
||||
static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
|
||||
static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
|
||||
{
|
||||
if (!IsObjectType(tile, OBJECT_HQ)) return;
|
||||
|
||||
@@ -634,7 +634,7 @@ static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, Carg
|
||||
CargoID pass = GetCargoIDByLabel(CT_PASSENGERS);
|
||||
if (IsValidCargoID(pass)) {
|
||||
acceptance[pass] += std::max(1U, level);
|
||||
SetBit(*always_accepted, pass);
|
||||
SetBit(always_accepted, pass);
|
||||
}
|
||||
|
||||
/* Top town building generates 4, HQ can make up to 8. The
|
||||
@@ -644,7 +644,7 @@ static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, Carg
|
||||
CargoID mail = GetCargoIDByLabel(CT_MAIL);
|
||||
if (IsValidCargoID(mail)) {
|
||||
acceptance[mail] += std::max(1U, level / 2);
|
||||
SetBit(*always_accepted, mail);
|
||||
SetBit(always_accepted, mail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,8 +666,8 @@ static void GetTileDesc_Object(TileIndex tile, TileDesc *td)
|
||||
td->owner[0] = GetTileOwner(tile);
|
||||
td->build_date = Object::GetByTile(tile)->build_date;
|
||||
|
||||
if (spec->grf_prop.grffile != nullptr) {
|
||||
td->grf = GetGRFConfig(spec->grf_prop.grffile->grfid)->GetName();
|
||||
if (spec->grf_prop.HasGrfFile()) {
|
||||
td->grf = GetGRFConfig(spec->grf_prop.grfid)->GetName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,6 +882,10 @@ static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_ow
|
||||
ObjectType type = GetObjectType(tile);
|
||||
if ((type == OBJECT_OWNED_LAND || type >= NEW_OBJECT_OFFSET) && new_owner != INVALID_OWNER) {
|
||||
SetTileOwner(tile, new_owner);
|
||||
if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
|
||||
Company::Get(old_owner)->infrastructure.water--;
|
||||
Company::Get(new_owner)->infrastructure.water++;
|
||||
}
|
||||
} else if (type == OBJECT_STATUE) {
|
||||
Town *t = Object::GetByTile(tile)->town;
|
||||
ClrBit(t->statues, old_owner);
|
||||
|
||||
Reference in New Issue
Block a user