4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [PTB] in the subject of your mails.
25
* \file balloon_placement.hpp
26
* \brief A class that tries to place the balloons such that they don't overlap.
27
* \author Julien Jorge
29
#ifndef __PTB_BALLOON_PLACEMENT_HPP__
30
#define __PTB_BALLOON_PLACEMENT_HPP__
32
#include "universe/types.hpp"
41
* \brief A class that tries to place the balloons such that they don't
43
* \author Julien Jorge
45
class balloon_placement
48
/** \brief A character speaking in the scene. */
49
struct scene_character
53
( speaker_item& i, const bear::universe::rectangle_type& r, bool v );
55
bear::universe::size_box_type get_balloon_size() const;
57
/** \brief The bounding box of the character. */
58
const bear::universe::rectangle_type box;
60
/** \brief The speaking item. */
63
/** \brief Tell if the speaker is visible. */
66
}; // struct scene_character
69
typedef std::list<candidate*> candidate_group;
71
/** \brief A candidate position for a balloon. */
75
/** \brief This function object compares two candidates in decreasing
76
order of their quality. */
77
struct increasing_conflicts
79
bool operator()( const candidate* a, const candidate* b ) const;
80
}; // struct increasing_conflicts
84
( const bear::universe::rectangle_type& r, const scene_character& s,
87
void add_covered_area( double percent );
88
void set_in_conflict_with( candidate* c );
89
std::size_t get_conclicts_count() const;
91
/** \brief Get the candidates conflicting with this one. */
92
const candidate_group& get_conflicts() const { return m_conflicts; }
94
bool is_valid() const;
100
/** \brief The rectangle where the balloon would be. */
101
const bear::universe::rectangle_type rect;
103
/** \brief The character owning the balloon. */
104
const scene_character& speaker;
107
/** \brief The candidates in conflicts with this one. */
108
candidate_group m_conflicts;
110
/** \brief The size of m_conflicts. */
111
int m_conflicts_count;
113
/** \brief Tell if this candidate is still usable. */
116
/** \brief The score of this candidate. */
119
/** \brief Percentage of the area of the balloon covered by something
121
double m_covered_area;
123
}; // class candidate
125
/** \brief The list of candidates, where each group concerns the same
127
typedef std::list<candidate_group> candidate_group_list;
129
/** \brief This function object compares two groups in decreasing order of
130
the quality of their first candidate. */
131
struct group_ordering
134
( const candidate_group& a, const candidate_group& b ) const;
135
}; // struct group_ordering
137
/** \brief The type of the list in which we store the speakers. */
138
typedef std::list<scene_character> character_list_type;
142
( bear::universe::size_type w, bear::universe::size_type h );
145
( speaker_item& c, const bear::universe::rectangle_type& rect );
147
void place_balloons() const;
150
void sort_candidates( candidate_group_list& c ) const;
152
void create_candidates( candidate_group_list& c ) const;
154
check_conflicts( candidate_group& g, candidate_group_list& result ) const;
157
( const scene_character& c, candidate_group& result,
158
bear::universe::coordinate_type left,
159
bear::universe::coordinate_type bottom, int score ) const;
160
void create_candidate_visible
161
( const scene_character& c, candidate_group& result ) const;
162
void create_candidate_not_visible
163
( const scene_character& c, candidate_group& result ) const;
165
void repeat_candidate_horizontally
166
( const scene_character& c, candidate_group& result,
167
bear::universe::coordinate_type first,
168
bear::universe::coordinate_type last,
169
bear::universe::coordinate_type y ) const;
170
void repeat_candidate_vertically
171
( const scene_character& c, candidate_group& result,
172
bear::universe::coordinate_type first,
173
bear::universe::coordinate_type last,
174
bear::universe::coordinate_type x ) const;
175
void repeat_candidate_placed_horizontally
176
( const scene_character& c, candidate_group& result,
177
bear::universe::coordinate_type y ) const;
178
void repeat_candidate_placed_vertically
179
( const scene_character& c, candidate_group& result,
180
bear::universe::coordinate_type x ) const;
182
bool check_on_top( const candidate& c ) const;
183
bool check_on_right( const candidate& c ) const;
186
/** \brief The size of the view where the speakers are visible. */
187
bear::universe::rectangle_type m_view;
189
/** \brief The list of all speakers. */
190
character_list_type m_characters;
192
}; // class balloon_placement
195
#endif // __PTB_BALLOON_PLACEMENT_HPP__