src/tunnelbridge_cmd.cpp
changeset 8491 97fcf662c3c3
parent 8489 28bedfca9e27
child 8519 fe61d7aa3053
equal deleted inserted replaced
8490:c4db66ce864d 8491:97fcf662c3c3
    97 	return (tileh != SLOPE_FLAT);
    97 	return (tileh != SLOPE_FLAT);
    98 }
    98 }
    99 
    99 
   100 static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
   100 static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
   101 {
   101 {
   102 	const Bridge *bridge = &_bridge[index];
   102 	const Bridge *bridge = GetBridgeSpec(index);
   103 	assert(table < 7);
   103 	assert(table < 7);
   104 	if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
   104 	if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
   105 		return _bridge_sprite_table[index][table];
   105 		return _bridge_sprite_table[index][table];
   106 	} else {
   106 	} else {
   107 		return bridge->sprite_table[table];
   107 		return bridge->sprite_table[table];
   108 	}
   108 	}
   109 }
   109 }
   110 
       
   111 static inline byte GetBridgeFlags(int index) { return _bridge[index].flags;}
       
   112 
   110 
   113 
   111 
   114 /**
   112 /**
   115  * Determines the foundation for the north bridge head, and tests if the resulting slope is valid.
   113  * Determines the foundation for the north bridge head, and tests if the resulting slope is valid.
   116  *
   114  *
   153 	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
   151 	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
   154 }
   152 }
   155 
   153 
   156 bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
   154 bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
   157 {
   155 {
   158 	const Bridge *b = &_bridge[bridge_type];
   156 	const Bridge *b = GetBridgeSpec(bridge_type);
   159 	uint max; // max possible length of a bridge (with patch 100)
   157 	uint max; // max possible length of a bridge (with patch 100)
   160 
   158 
   161 	if (bridge_type >= MAX_BRIDGES) return false;
   159 	if (bridge_type >= MAX_BRIDGES) return false;
   162 	if (b->avail_year > _cur_year) return false;
   160 	if (b->avail_year > _cur_year) return false;
   163 
   161 
   264 			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
   262 			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
   265 		}
   263 		}
   266 
   264 
   267 		/* Do not replace town bridges with lower speed bridges. */
   265 		/* Do not replace town bridges with lower speed bridges. */
   268 		if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
   266 		if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
   269 				_bridge[bridge_type].speed < _bridge[GetBridgeType(tile_start)].speed) {
   267 				GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed) {
   270 			Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
   268 			Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
   271 
   269 
   272 			if (t == NULL) {
   270 			if (t == NULL) {
   273 				return CMD_ERROR;
   271 				return CMD_ERROR;
   274 			} else {
   272 			} else {
   414 	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
   412 	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
   415 	 * It's unnecessary to execute this command every time for every bridge. So it is done only
   413 	 * It's unnecessary to execute this command every time for every bridge. So it is done only
   416 	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
   414 	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
   417 	 */
   415 	 */
   418 	if (!(flags & DC_QUERY_COST)) {
   416 	if (!(flags & DC_QUERY_COST)) {
   419 		const Bridge *b = &_bridge[bridge_type];
       
   420 
       
   421 		bridge_len += 2; // begin and end tiles/ramps
   417 		bridge_len += 2; // begin and end tiles/ramps
   422 
   418 
   423 		if (IsValidPlayer(_current_player) && !_is_old_ai_player)
   419 		if (IsValidPlayer(_current_player) && !_is_old_ai_player)
   424 			bridge_len = CalcBridgeLenCostFactor(bridge_len);
   420 			bridge_len = CalcBridgeLenCostFactor(bridge_len);
   425 
   421 
   426 		cost.AddCost((int64)bridge_len * _price.build_bridge * b->price >> 8);
   422 		cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8);
   427 	}
   423 	}
   428 
   424 
   429 	return cost;
   425 	return cost;
   430 }
   426 }
   431 
   427 
   698  */
   694  */
   699 static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z_bridge)
   695 static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z_bridge)
   700 {
   696 {
   701 	SpriteID image = psid->sprite;
   697 	SpriteID image = psid->sprite;
   702 	if (image != 0) {
   698 	if (image != 0) {
   703 		bool drawfarpillar = !HasBit(GetBridgeFlags(type), 0);
   699 		bool drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0);
   704 
   700 
   705 		/* "side" specifies the side the pillars stand on.
   701 		/* "side" specifies the side the pillars stand on.
   706 		 * The length of the pillars is then set to the height of the bridge over the corners of this edge.
   702 		 * The length of the pillars is then set to the height of the bridge over the corners of this edge.
   707 		 *
   703 		 *
   708 		 *                axis==AXIS_X  axis==AXIS_Y
   704 		 *                axis==AXIS_X  axis==AXIS_Y
  1128 {
  1124 {
  1129 	if (IsTunnel(tile)) {
  1125 	if (IsTunnel(tile)) {
  1130 		td->str = (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ?
  1126 		td->str = (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ?
  1131 			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
  1127 			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
  1132 	} else { //so it must be a bridge
  1128 	} else { //so it must be a bridge
  1133 		int brtype = GetBridgeType(tile);
  1129 		const Bridge *brspc = GetBridgeSpec(GetBridgeType(tile));
  1134 		td->str = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL ? _bridge[brtype].name_rail : _bridge[brtype].name_road;
  1130 		td->str = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL ? brspc->name_rail : brspc->name_road;
  1135 	}
  1131 	}
  1136 	td->owner = GetTileOwner(tile);
  1132 	td->owner = GetTileOwner(tile);
  1137 }
  1133 }
  1138 
  1134 
  1139 
  1135 
  1287 	} else { // IsBridge(tile)
  1283 	} else { // IsBridge(tile)
  1288 		DiagDirection dir;
  1284 		DiagDirection dir;
  1289 
  1285 
  1290 		if (v->IsPrimaryVehicle()) {
  1286 		if (v->IsPrimaryVehicle()) {
  1291 			/* modify speed of vehicle */
  1287 			/* modify speed of vehicle */
  1292 			uint16 spd = _bridge[GetBridgeType(tile)].speed;
  1288 			uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
  1293 
  1289 
  1294 			if (v->type == VEH_ROAD) spd *= 2;
  1290 			if (v->type == VEH_ROAD) spd *= 2;
  1295 			if (v->cur_speed > spd) v->cur_speed = spd;
  1291 			if (v->cur_speed > spd) v->cur_speed = spd;
  1296 		}
  1292 		}
  1297 
  1293