810 return CMD_ERROR; |
810 return CMD_ERROR; |
811 } |
811 } |
812 } |
812 } |
813 |
813 |
814 |
814 |
815 static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z) |
815 /** |
|
816 * Draws the pillars under high bridges. |
|
817 * |
|
818 * @param psid Image and palette of a bridge pillar. |
|
819 * @param ti #TileInfo of current bridge-middle-tile. |
|
820 * @param axis Orientation of bridge. |
|
821 * @param type Bridge type. |
|
822 * @param x Sprite X position of front pillar. |
|
823 * @param y Sprite Y position of front pillar. |
|
824 * @param z_bridge Absolute height of bridge bottom. |
|
825 */ |
|
826 static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z_bridge) |
816 { |
827 { |
817 SpriteID image = psid->sprite; |
828 SpriteID image = psid->sprite; |
818 if (image != 0) { |
829 if (image != 0) { |
819 bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0); |
830 bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0); |
820 int back_height, front_height; |
831 |
821 int i = z; |
832 /* "side" specifies the side the pillars stand on. |
822 const byte *p; |
833 * The length of the pillars is then set to the height of the bridge over the corners of this edge. |
823 |
834 * |
824 static const byte _tileh_bits[4][8] = { |
835 * axis==AXIS_X axis==AXIS_Y |
825 { 2, 1, 8, 4, 16, 2, 0, 9 }, |
836 * side==false SW NW |
826 { 1, 8, 4, 2, 2, 16, 9, 0 }, |
837 * side==true NE SE |
827 { 4, 8, 1, 2, 16, 2, 0, 9 }, |
838 * |
828 { 2, 4, 8, 1, 2, 16, 9, 0 } |
839 * I have no clue, why this was done this way. |
829 }; |
840 */ |
830 |
841 bool side = HASBIT(image, 0); |
831 p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)]; |
842 |
832 front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0); |
843 /* "dir" means the edge the pillars stand on */ |
833 back_height = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0); |
844 DiagDirection dir = AxisToDiagDir(axis); |
834 |
845 if (side != (axis == AXIS_Y)) dir = ReverseDiagDir(dir); |
835 if (IsSteepSlope(ti->tileh)) { |
846 |
836 if (!(ti->tileh & p[2])) front_height += TILE_HEIGHT; |
847 /* Determine ground height under pillars */ |
837 if (!(ti->tileh & p[3])) back_height += TILE_HEIGHT; |
848 int front_height = ti->z; |
838 } |
849 int back_height = ti->z; |
839 |
850 GetSlopeZOnEdge(ti->tileh, dir, &front_height, &back_height); |
840 for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) { |
851 |
841 /* HACK set height of the BB of pillars to 1, because the origin of the |
852 /* x and y size of bounding-box of pillars */ |
842 * sprites is at the top |
853 int w = (axis == AXIS_X ? 16 : 2); |
843 */ |
854 int h = (axis == AXIS_X ? 2 : 16); |
844 if (z >= front_height) { // front facing pillar |
855 /* sprite position of back facing pillar */ |
845 AddSortableSpriteToDraw(image, psid->pal, x, y, p[4], p[5], BB_HEIGHT_UNDER_BRIDGE - 5, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5); |
856 int x_back = x - (axis == AXIS_X ? 0 : 9); |
846 } |
857 int y_back = y - (axis == AXIS_X ? 9 : 0); |
847 |
858 |
848 if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar |
859 for (int cur_z = z_bridge; cur_z >= front_height || cur_z >= back_height; cur_z -= TILE_HEIGHT) { |
849 AddSortableSpriteToDraw(image, psid->pal, x - p[6], y - p[7], p[4], p[5], BB_HEIGHT_UNDER_BRIDGE - 5, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5); |
860 /* Draw front facing pillar */ |
|
861 if (cur_z >= front_height) { |
|
862 AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5); |
|
863 } |
|
864 |
|
865 /* Draw back facing pillar, but not the highest part directly under the bridge-floor */ |
|
866 if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - TILE_HEIGHT) { |
|
867 AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5); |
850 } |
868 } |
851 } |
869 } |
852 } |
870 } |
853 } |
871 } |
854 |
872 |