1 | // SuperTux |
2 | // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmail.com> |
3 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
4 | // |
5 | // This program is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation, either version 3 of the License, or |
8 | // (at your option) any later version. |
9 | // |
10 | // This program is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | #include "worldmap/special_tile.hpp" |
19 | |
20 | #include "sprite/sprite.hpp" |
21 | #include "sprite/sprite_manager.hpp" |
22 | #include "util/log.hpp" |
23 | #include "util/reader_mapping.hpp" |
24 | |
25 | namespace worldmap { |
26 | |
27 | SpecialTile::SpecialTile(const ReaderMapping& mapping) : |
28 | m_pos(), |
29 | m_sprite(), |
30 | m_map_message(), |
31 | m_passive_message(false), |
32 | m_script(), |
33 | m_invisible(false), |
34 | m_apply_action_north(true), |
35 | m_apply_action_east(true), |
36 | m_apply_action_south(true), |
37 | m_apply_action_west(true) |
38 | { |
39 | if (!mapping.get("x" , m_pos.x)) { |
40 | log_warning << "X coordinate of special tile not set, defaulting to 0" << std::endl; |
41 | } |
42 | if (!mapping.get("y" , m_pos.y)) { |
43 | log_warning << "Y coordinate of special tile not set, defaulting to 0" << std::endl; |
44 | } |
45 | if (!mapping.get("invisible-tile" , m_invisible)) { |
46 | // Ignore attribute if it's not specified. Tile is visible. |
47 | } |
48 | |
49 | if (!m_invisible) { |
50 | std::string spritefile = "" ; |
51 | if (!mapping.get("sprite" , spritefile)) { |
52 | log_warning << "No sprite specified for visible special tile." << std::endl; |
53 | } |
54 | m_sprite = SpriteManager::current()->create(spritefile); |
55 | } |
56 | |
57 | if (!mapping.get("map-message" , m_map_message)) { |
58 | // Ignore attribute if it's not specified. No map message set. |
59 | } |
60 | if (!mapping.get("passive-message" , m_passive_message)) { |
61 | // Ignore attribute if it's not specified. No passive message set. |
62 | } |
63 | if (!mapping.get("script" , m_script)) { |
64 | // Ignore attribute if it's not specified. No script set. |
65 | } |
66 | |
67 | std::string apply_direction; |
68 | if (!mapping.get("apply-to-direction" , apply_direction)) { |
69 | // Ignore attribute if it's not specified. Applies to all directions. |
70 | } |
71 | if (!apply_direction.empty()) { |
72 | m_apply_action_north = false; |
73 | m_apply_action_south = false; |
74 | m_apply_action_east = false; |
75 | m_apply_action_west = false; |
76 | if (apply_direction.find("north" ) != std::string::npos) |
77 | m_apply_action_north = true; |
78 | if (apply_direction.find("south" ) != std::string::npos) |
79 | m_apply_action_south = true; |
80 | if (apply_direction.find("east" ) != std::string::npos) |
81 | m_apply_action_east = true; |
82 | if (apply_direction.find("west" ) != std::string::npos) |
83 | m_apply_action_west = true; |
84 | } |
85 | } |
86 | |
87 | SpecialTile::~SpecialTile() |
88 | { |
89 | } |
90 | |
91 | void |
92 | SpecialTile::draw(DrawingContext& context) |
93 | { |
94 | if (m_invisible) |
95 | return; |
96 | |
97 | m_sprite->draw(context.color(), m_pos*32 + Vector(16, 16), LAYER_OBJECTS - 1); |
98 | } |
99 | |
100 | void |
101 | SpecialTile::update(float ) |
102 | { |
103 | } |
104 | |
105 | } |
106 | |
107 | /* EOF */ |
108 | |