netpanzer.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Pingus - A free Lemmings clone
  2. // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_SCRIPTING_NETPANZER_HXX
  17. #define HEADER_SCRIPTING_NETPANZER_HXX
  18. #include <string>
  19. #include <ClanLib/Display/palette.h>
  20. #include <ClanLib/Display/surface.h>
  21. #include <ClanLib/Display/sprite.h>
  22. #include "../lib/tileset.hpp"
  23. #include "../lib/tilemap_layer.hpp"
  24. class NetPanzerFileStructImpl;
  25. struct NetPanzerTileHeader
  26. {
  27. public:
  28. char attrib;
  29. char move_value;
  30. char avg_color;
  31. };
  32. struct NetPanzerTileGroup
  33. {
  34. int start;
  35. int width;
  36. int height;
  37. CL_Surface get_surface();
  38. private:
  39. /** Surface holding the tilegroups image */
  40. CL_Surface surface;
  41. };
  42. class NetPanzerData
  43. {
  44. private:
  45. static NetPanzerData* instance_;
  46. public:
  47. static NetPanzerData* instance()
  48. {
  49. if (instance_)
  50. return (instance_);
  51. else
  52. return (instance_ = new NetPanzerData());
  53. }
  54. private:
  55. std::string datadir;
  56. CL_Palette palette;
  57. Tileset tileset;
  58. unsigned char* tiledata;
  59. typedef std::vector<NetPanzerTileGroup> TileGroups;
  60. TileGroups tilegroups;
  61. std::vector<NetPanzerTileHeader> tile_headers;
  62. public:
  63. NetPanzerData();
  64. /** Register a tilegroup, ie. a section of tiles that belong
  65. together and form an building, lake, a section of trees, etc.
  66. \param start the tile-id for the upper/left tile
  67. \param width the width of tilegroup
  68. \param height the height of the tilegroup
  69. */
  70. void register_tilegroup(int start, int width, int height);
  71. void load_data(const std::string& datadir_);
  72. const CL_Palette& get_palette() const;
  73. const Tileset& get_tileset() const;
  74. const std::vector<NetPanzerTileHeader>& get_tile_headers() const;
  75. unsigned char* get_tiledata() const;
  76. CL_Palette load_palette(const std::string& filename);
  77. CL_Sprite get_tilegroup_sprite(int index);
  78. /** Locate the tilegroup in which the tile with \a tileindex is
  79. located */
  80. NetPanzerTileGroup& find_tilegroup(int tileindex);
  81. private:
  82. void load_tileset(const std::string& filename);
  83. };
  84. class NetPanzerFileStruct
  85. {
  86. public:
  87. NetPanzerFileStruct(Tileset tileset, int w, int h);
  88. NetPanzerFileStruct(Tileset tileset, const std::string& filename);
  89. std::string get_id_header();
  90. std::string get_name();
  91. std::string get_description();
  92. TilemapLayer get_tilemap();
  93. void set_id_header(const std::string& id);
  94. void set_name(const std::string& name);
  95. void set_description(const std::string& description);
  96. void set_tilemap(TilemapLayer l);
  97. void save(const std::string& filename);
  98. private:
  99. std::shared_ptr<NetPanzerFileStructImpl> impl;
  100. };
  101. #endif
  102. /* EOF */