comparison src/terraform_cmd.cpp @ 16760:9e31dde37aed draft

(svn r21493) -Codechange: don't use the full 32 bits of the level land command to tell whether to raise, lower or keep the level of the first selected tile
author rubidium <rubidium@openttd.org>
date Mon, 13 Dec 2010 11:21:53 +0000
parents 7ca019b56d4e
children c0ddbaaeb487
comparison
equal deleted inserted replaced
16759:aa34ba5a7da1 16760:9e31dde37aed
376 /** 376 /**
377 * Levels a selected (rectangle) area of land 377 * Levels a selected (rectangle) area of land
378 * @param tile end tile of area-drag 378 * @param tile end tile of area-drag
379 * @param flags for this command type 379 * @param flags for this command type
380 * @param p1 start tile of area drag 380 * @param p1 start tile of area drag
381 * @param p2 height difference; eg raise (+1), lower (-1) or level (0) 381 * @param p2 various bitstuffed data.
382 * bits 1 - 2: Mode of leveling \c LevelMode.
382 * @param text unused 383 * @param text unused
383 * @return the cost of this operation or an error 384 * @return the cost of this operation or an error
384 */ 385 */
385 CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) 386 CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
386 { 387 {
390 391
391 /* remember level height */ 392 /* remember level height */
392 uint oldh = TileHeight(p1); 393 uint oldh = TileHeight(p1);
393 394
394 /* compute new height */ 395 /* compute new height */
395 uint h = oldh + (int8)p2; 396 uint h = oldh;
397 LevelMode lm = (LevelMode)GB(p2, 1, 2);
398 switch (lm) {
399 case LM_LEVEL: break;
400 case LM_RAISE: h++; break;
401 case LM_LOWER: h--; break;
402 default: return CMD_ERROR;
403 }
396 404
397 /* Check range of destination height */ 405 /* Check range of destination height */
398 if (h > MAX_TILE_HEIGHT) return_cmd_error((oldh == 0) ? STR_ERROR_ALREADY_AT_SEA_LEVEL : STR_ERROR_TOO_HIGH); 406 if (h > MAX_TILE_HEIGHT) return_cmd_error((oldh == 0) ? STR_ERROR_ALREADY_AT_SEA_LEVEL : STR_ERROR_TOO_HIGH);
399 407
400 Money money = GetAvailableMoneyForCommand(); 408 Money money = GetAvailableMoneyForCommand();
401 CommandCost cost(EXPENSES_CONSTRUCTION); 409 CommandCost cost(EXPENSES_CONSTRUCTION);
402 CommandCost last_error((p2 == 0) ? STR_ERROR_ALREADY_LEVELLED : INVALID_STRING_ID); 410 CommandCost last_error(lm == LM_LEVEL ? STR_ERROR_ALREADY_LEVELLED : INVALID_STRING_ID);
403 bool had_success = false; 411 bool had_success = false;
404 412
405 TileArea ta(tile, p1); 413 TileArea ta(tile, p1);
406 TILE_AREA_LOOP(tile, ta) { 414 TILE_AREA_LOOP(tile, ta) {
407 uint curh = TileHeight(tile); 415 uint curh = TileHeight(tile);