|
|
|
@ -430,6 +430,71 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|
|
|
|
return had_success ? cost : last_error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct multiple objects in an area
|
|
|
|
|
* @param tile end tile of area dragging
|
|
|
|
|
* @param flags of operation to conduct
|
|
|
|
|
* @param p1 start tile of area dragging
|
|
|
|
|
* @param p2 various bitstuffed data.
|
|
|
|
|
* - p2 = (bit 0) - Whether to use the Orthogonal (0) or Diagonal (1) iterator.
|
|
|
|
|
* - p2 = (bit 1 - 2) - Object view
|
|
|
|
|
* - p2 = (bit 3 - 19) - Object type
|
|
|
|
|
* @param text unused
|
|
|
|
|
* @return the cost of this operation or an error
|
|
|
|
|
*/
|
|
|
|
|
CommandCost CmdBuildObjectArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
|
|
{
|
|
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
|
|
|
|
if (!_settings_game.construction.build_object_area_permitted) return_cmd_error(STR_BUILD_OBJECT_NOT_PERMITTED_BULK);
|
|
|
|
|
|
|
|
|
|
ObjectType type = (ObjectType)GB(p2, 3, 16);
|
|
|
|
|
if (type >= NUM_OBJECTS) return CMD_ERROR;
|
|
|
|
|
uint8 view = GB(p2, 1, 2);
|
|
|
|
|
const ObjectSpec *spec = ObjectSpec::Get(type);
|
|
|
|
|
if (view >= spec->views) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
if (spec->size != 0x11) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
Money money = GetAvailableMoneyForCommand();
|
|
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
|
|
CommandCost last_error = CMD_ERROR;
|
|
|
|
|
bool had_success = false;
|
|
|
|
|
|
|
|
|
|
const Company *c = Company::GetIfValid(_current_company);
|
|
|
|
|
int limit = (c == nullptr ? INT32_MAX : GB(c->build_object_limit, 16, 16));
|
|
|
|
|
|
|
|
|
|
TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(tile, p1);
|
|
|
|
|
for (; *iter != INVALID_TILE; ++(*iter)) {
|
|
|
|
|
TileIndex t = *iter;
|
|
|
|
|
CommandCost ret = DoCommand(t, type, view, flags & ~DC_EXEC, CMD_BUILD_OBJECT);
|
|
|
|
|
if (ret.Failed()) {
|
|
|
|
|
last_error = ret;
|
|
|
|
|
|
|
|
|
|
/* We may not clear more tiles. */
|
|
|
|
|
if (c != nullptr && GB(c->build_object_limit, 16, 16) < 1) break;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
had_success = true;
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
|
money -= ret.GetCost();
|
|
|
|
|
if (ret.GetCost() > 0 && money < 0) {
|
|
|
|
|
_additional_cash_required = ret.GetCost();
|
|
|
|
|
delete iter;
|
|
|
|
|
return cost;
|
|
|
|
|
}
|
|
|
|
|
DoCommand(t, type, view, flags, CMD_BUILD_OBJECT);
|
|
|
|
|
} else {
|
|
|
|
|
/* When we're at the clearing limit we better bail (unneed) testing as well. */
|
|
|
|
|
if (ret.GetCost() != 0 && --limit <= 0) break;
|
|
|
|
|
}
|
|
|
|
|
cost.AddCost(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete iter;
|
|
|
|
|
return had_success ? cost : last_error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Foundation GetFoundation_Object(TileIndex tile, Slope tileh);
|
|
|
|
|
|
|
|
|
|