OTOWNBLD.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OTOWNSE2.CPP
  21. //Description : Object TownZone
  22. #include <OVGA.h>
  23. #include <OGAME.h>
  24. #include <OINFO.h>
  25. #include <OTOWN.h>
  26. #include <OWORLD.h>
  27. #include <OTOWNRES.h>
  28. //------- Begin of function TownBuild::draw -----------//
  29. //
  30. // Draw the town building on the zoom map
  31. //
  32. // <int> absBaseX, absBaseY - the absolute base (center-bottom) coordination
  33. // of the building.
  34. //
  35. // <int> selectedFlag - whether the town of this building is currently selected or not.
  36. //
  37. void TownBuild::draw(int townRecno, int absBaseX, int absBaseY)
  38. {
  39. int absX1 = absBaseX - bitmap_width/2;
  40. int absY1 = absBaseY - bitmap_height;
  41. int absX2 = absX1 + bitmap_width - 1;
  42. int absY2 = absY1 + bitmap_height - 1;
  43. //-------- check if the firm is within the view area --------//
  44. int x1 = absX1 - World::view_top_x;
  45. if( x1 <= -bitmap_width || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area
  46. return;
  47. int y1 = absY1 - World::view_top_y;
  48. if( y1 <= -bitmap_height || y1 >= ZOOM_HEIGHT )
  49. return;
  50. //------- decide which approach to use for displaying -----//
  51. int x2 = absX2 - World::view_top_x;
  52. int y2 = absY2 - World::view_top_y;
  53. //------- get the color remap table for this sprite ------//
  54. Town* townPtr = town_array[townRecno];
  55. char* colorRemapTable = game.get_color_remap_table(townPtr->nation_recno, town_array.selected_recno==townRecno);
  56. //---- only portion of the sprite is inside the view area ------//
  57. if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
  58. {
  59. vga_back.put_bitmap_area_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr,
  60. max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, colorRemapTable );
  61. }
  62. //---- the whole bitmap is inside the view area ------//
  63. else
  64. {
  65. vga_back.put_bitmap_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, colorRemapTable );
  66. }
  67. }
  68. //--------- End of function TownBuild::draw -----------//