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

« back to all changes in this revision

Viewing changes to plee-the-bear/src/ptb/item/code/hideout_revealing.cpp

  • 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
1
/*
2
 
  Bear Engine
 
2
  Plee the Bear
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
19
19
 
20
20
  contact: plee-the-bear@gamned.org
21
21
 
22
 
  Please add the tag [Bear] in the subject of your mails.
 
22
  Please add the tag [PTB] in the subject of your mails.
23
23
*/
24
24
/**
25
25
 * \file hideout_revealing.cpp
27
27
 * \author S�bastien Angibaud
28
28
 */
29
29
#include "ptb/item/hideout_revealing.hpp"
 
30
 
30
31
#include "generic_items/decorative_item.hpp"
 
32
#include "ptb/player.hpp"
 
33
#include "ptb/util.hpp"
31
34
 
32
35
BASE_ITEM_EXPORT( hideout_revealing, ptb )
33
36
 
39
42
  : m_player_in_zone(false), m_definitive_disclosure(false),
40
43
    m_revealing_opacity(0), m_hideout_opacity(1),
41
44
    m_current_revealed(false), m_last_revealed(false),
42
 
    m_hideout_found(false),
 
45
    m_hideout_found(false), m_revelation_duration(0.25), m_last_modification(0),
43
46
    m_first_player(NULL), m_second_player(NULL)
44
47
{
45
48
  set_phantom(true);
56
59
{
57
60
  super::progress(elapsed_time);
58
61
 
 
62
  bool player_in_zone = false;
 
63
 
59
64
  if ( !m_current_revealed && !m_hideout_found )
60
65
    {
61
 
      bool player_in_zone = false;
62
66
      search_players();
63
 
 
 
67
 
64
68
      if ( m_first_player.get() != NULL )
65
69
        player_in_zone =
66
70
          m_first_player->get_bounding_box().intersects(get_bounding_box());
75
79
 
76
80
      if ( player_in_zone )
77
81
        {
78
 
          reveal();
 
82
          if ( !m_last_revealed )
 
83
            m_last_modification = 0;
 
84
          m_current_revealed = true;
79
85
          m_hideout_found = m_definitive_disclosure;
80
 
        } 
 
86
        }
81
87
    }
82
88
 
83
89
  if ( !m_hideout_found )
84
90
    {
85
91
      if ( !m_current_revealed && m_last_revealed )
86
 
        hide();
 
92
        m_last_modification = 0;
87
93
 
88
94
      m_last_revealed = m_current_revealed;
89
95
      m_current_revealed = false;
90
96
    }
 
97
 
 
98
  if ( m_last_modification <= m_revelation_duration )
 
99
    {
 
100
       m_last_modification += elapsed_time;
 
101
      if ( player_in_zone )
 
102
        reveal();
 
103
      else
 
104
        hide();
 
105
    }
91
106
} // hideout_revealing::progress()
92
107
 
93
108
/*----------------------------------------------------------------------------*/
99
114
  super::build();
100
115
 
101
116
  search_players();
 
117
  m_last_modification = m_revelation_duration;
102
118
  hide();
103
119
} // hideout_revealing::build()
104
120
 
118
134
    {
119
135
      m_items.clear();
120
136
      unsigned int index;
121
 
      for ( index = 0; index != value.size(); index++ )
 
137
      for ( index = 0; index != value.size(); ++index )
122
138
        m_items.push_back(value[index]);
123
139
      result = true;
124
140
    }
161
177
bool ptb::hideout_revealing::set_real_field
162
178
( const std::string& name, double value )
163
179
{
164
 
  bool result = false;
 
180
  bool result = true;
165
181
 
166
182
  if ( name == "hideout_revealing.revealing_opacity" )
167
183
    m_revealing_opacity = value;
179
195
 */
180
196
void ptb::hideout_revealing::search_players()
181
197
{
182
 
  plee::get_instance_message msg;
183
 
  
184
 
  if ( m_first_player.get() == NULL )
185
 
    {
186
 
      get_level_globals().send_message(plee::player_name(1),msg);
187
 
      m_first_player = msg.get_instance();
188
 
    }
189
 
  
190
 
  if ( ( game_variables::get_players_count() == 2 ) && 
191
 
       ( m_second_player.get() == NULL ) )
192
 
    {
193
 
      get_level_globals().send_message(plee::player_name(2),msg);
194
 
      m_second_player = msg.get_instance();
195
 
    }
 
198
  if ( m_first_player == (player*)NULL )
 
199
    m_first_player = util::find_player( get_level_globals(), 1 );
 
200
 
 
201
  if ( m_second_player == (player*)NULL )
 
202
    m_second_player = util::find_player( get_level_globals(), 2 );
196
203
} // hideout_revealing::search_players()
197
204
 
198
205
/*----------------------------------------------------------------------------*/
201
208
 */
202
209
void ptb::hideout_revealing::reveal()
203
210
{
204
 
  m_current_revealed = true;
 
211
  double opacity
 
212
    (m_hideout_opacity + (m_revealing_opacity-m_hideout_opacity) *
 
213
     m_last_modification / m_revelation_duration );
 
214
 
 
215
  if ( opacity <= 0 )
 
216
    opacity = 0;
 
217
  else if ( opacity >= 1 )
 
218
    opacity = 1;
205
219
 
206
220
  std::vector<bear::universe::item_handle>::iterator it;
207
221
  for (it = m_items.begin(); it != m_items.end(); ++it)
208
222
    {
209
223
      if ( *it != NULL )
210
 
        {
211
 
          bear::decorative_item*
212
 
            deco = dynamic_cast<bear::decorative_item*>(it->get());
213
 
          if ( deco != NULL )
214
 
            deco->get_rendering_attributes().set_opacity(m_revealing_opacity);
215
 
        }
 
224
        {
 
225
          bear::decorative_item*
 
226
            deco = dynamic_cast<bear::decorative_item*>(it->get());
 
227
          if ( deco != NULL )
 
228
            deco->get_rendering_attributes().set_opacity(opacity) ;
 
229
        }
216
230
    }
217
231
} // hideout_revealing::reveal()
218
232
 
222
236
 */
223
237
void ptb::hideout_revealing::hide()
224
238
{
 
239
  double opacity =
 
240
    m_revealing_opacity + (m_hideout_opacity-m_revealing_opacity) *
 
241
    m_last_modification / m_revelation_duration ;
 
242
 
 
243
  if ( opacity <= 0 )
 
244
    opacity = 0;
 
245
  else if ( opacity >= 1 )
 
246
    opacity = 1;
 
247
 
225
248
  std::vector<bear::universe::item_handle>::iterator it;
226
249
  for (it = m_items.begin(); it != m_items.end(); ++it)
227
250
    {
230
253
          bear::decorative_item*
231
254
            deco = dynamic_cast<bear::decorative_item*>(it->get());
232
255
          if ( deco != NULL )
233
 
            deco->get_rendering_attributes().set_opacity(m_hideout_opacity);
 
256
            deco->get_rendering_attributes().set_opacity( opacity);
234
257
        }
235
258
    }
236
259
} // hideout_revealing::hide()