~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to plee-the-bear/src/ptb/layer/balloon_placement/balloon_placement.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Plee the Bear
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
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.
 
10
 
 
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
 
14
  more details.
 
15
 
 
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
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [PTB] in the subject of your mails.
 
23
*/
 
24
/**
 
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
 
28
 */
 
29
#ifndef __PTB_BALLOON_PLACEMENT_HPP__
 
30
#define __PTB_BALLOON_PLACEMENT_HPP__
 
31
 
 
32
#include "universe/types.hpp"
 
33
 
 
34
#include <list>
 
35
 
 
36
namespace ptb
 
37
{
 
38
  class speaker_item;
 
39
 
 
40
  /**
 
41
   * \brief A class that tries to place the balloons such that they don't
 
42
   *        overlap.
 
43
   * \author Julien Jorge
 
44
   */
 
45
  class balloon_placement
 
46
  {
 
47
  private:
 
48
    /** \brief A character speaking in the scene. */
 
49
    struct scene_character
 
50
    {
 
51
    public:
 
52
      scene_character
 
53
      ( speaker_item& i, const bear::universe::rectangle_type& r, bool v );
 
54
 
 
55
      bear::universe::size_box_type get_balloon_size() const;
 
56
 
 
57
      /** \brief The bounding box of the character. */
 
58
      const bear::universe::rectangle_type box;
 
59
 
 
60
      /** \brief The speaking item. */
 
61
      speaker_item& item;
 
62
 
 
63
      /** \brief Tell if the speaker is visible. */
 
64
      bool visible;
 
65
 
 
66
    }; // struct scene_character
 
67
 
 
68
    class candidate;
 
69
    typedef std::list<candidate*> candidate_group;
 
70
 
 
71
    /** \brief A candidate position for a balloon. */
 
72
    class candidate
 
73
    {
 
74
    public:
 
75
      /** \brief This function object compares two candidates in decreasing
 
76
          order of their quality. */
 
77
      struct increasing_conflicts
 
78
      {
 
79
        bool operator()( const candidate* a, const candidate* b ) const;
 
80
      }; // struct increasing_conflicts
 
81
 
 
82
    public:
 
83
      candidate
 
84
      ( const bear::universe::rectangle_type& r, const scene_character& s,
 
85
        int score );
 
86
 
 
87
      void add_covered_area( double percent );
 
88
      void set_in_conflict_with( candidate* c );
 
89
      std::size_t get_conclicts_count() const;
 
90
 
 
91
      /** \brief Get the candidates conflicting with this one. */
 
92
      const candidate_group& get_conflicts() const { return m_conflicts; }
 
93
 
 
94
      bool is_valid() const;
 
95
      void invalidate();
 
96
 
 
97
      int eval() const;
 
98
 
 
99
    public:
 
100
      /** \brief The rectangle where the balloon would be. */
 
101
      const bear::universe::rectangle_type rect;
 
102
 
 
103
      /** \brief The character owning the balloon. */
 
104
      const scene_character& speaker;
 
105
 
 
106
    private:
 
107
      /** \brief The candidates in conflicts with this one. */
 
108
      candidate_group m_conflicts;
 
109
 
 
110
      /** \brief The size of m_conflicts. */
 
111
      int m_conflicts_count;
 
112
 
 
113
      /** \brief Tell if this candidate is still usable. */
 
114
      bool m_is_valid;
 
115
 
 
116
      /** \brief The score of this candidate. */
 
117
      int m_score;
 
118
 
 
119
      /** \brief Percentage of the area of the balloon covered by something
 
120
          else. */
 
121
      double m_covered_area;
 
122
 
 
123
    }; // class candidate
 
124
 
 
125
    /** \brief The list of candidates, where each group concerns the same
 
126
        speaker. */
 
127
    typedef std::list<candidate_group> candidate_group_list;
 
128
 
 
129
    /** \brief This function object compares two groups in decreasing order of
 
130
        the quality of their first candidate. */
 
131
    struct group_ordering
 
132
    {
 
133
      bool operator()
 
134
      ( const candidate_group& a, const candidate_group& b ) const;
 
135
    }; // struct group_ordering
 
136
 
 
137
    /** \brief The type of the list in which we store the speakers. */
 
138
    typedef std::list<scene_character> character_list_type;
 
139
 
 
140
  public:
 
141
    balloon_placement
 
142
    ( bear::universe::size_type w, bear::universe::size_type h );
 
143
 
 
144
    void add_speaker
 
145
    ( speaker_item& c, const bear::universe::rectangle_type& rect );
 
146
 
 
147
    void place_balloons() const;
 
148
 
 
149
  private:
 
150
    void sort_candidates( candidate_group_list& c ) const;
 
151
 
 
152
    void create_candidates( candidate_group_list& c ) const;
 
153
    void
 
154
    check_conflicts( candidate_group& g, candidate_group_list& result ) const;
 
155
 
 
156
    void new_candidate
 
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;
 
164
 
 
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;
 
181
 
 
182
    bool check_on_top( const candidate& c ) const;
 
183
    bool check_on_right( const candidate& c ) const;
 
184
 
 
185
  private:
 
186
    /** \brief The size of the view where the speakers are visible. */
 
187
    bear::universe::rectangle_type m_view;
 
188
 
 
189
    /** \brief The list of all speakers. */
 
190
    character_list_type m_characters;
 
191
 
 
192
  }; // class balloon_placement
 
193
} // namespace ptb
 
194
 
 
195
#endif // __PTB_BALLOON_PLACEMENT_HPP__