~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/plee/code/plee.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
 
/*
2
 
  Plee the Bear
3
 
 
4
 
  Copyright (C) 2005-2009 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 plee.cpp
26
 
 * \brief Implementation of the ptb::plee class.
27
 
 * \author Julien Jorge
28
 
 */
29
 
#include "ptb/item/plee/plee.hpp"
30
 
 
31
 
#include <sstream>
32
 
 
33
 
#include "engine/game.hpp"
34
 
#include "engine/world.hpp"
35
 
#include "engine/message/transition_effect_message.hpp"
36
 
 
37
 
#include "ptb/defines.hpp"
38
 
#include "ptb/monster.hpp"
39
 
#include "ptb/player_action.hpp"
40
 
 
41
 
#include "ptb/item/shared_camera.hpp"
42
 
#include "ptb/item/small_honeypot.hpp"
43
 
#include "ptb/item/stone/air_fire_stone.hpp"
44
 
#include "ptb/item/stone/air_fire_water_stone.hpp"
45
 
#include "ptb/item/stone/air_water_stone.hpp"
46
 
#include "ptb/item/stone/air_stone.hpp"
47
 
#include "ptb/item/stone/water_fire_stone.hpp"
48
 
#include "ptb/item/stone/water_stone.hpp"
49
 
#include "ptb/item/stone/fire_stone.hpp"
50
 
#include "ptb/item/azelnut.hpp"
51
 
#include "ptb/item/plee/state_roar.hpp"
52
 
#include "ptb/item/plee/state_walk.hpp"
53
 
#include "ptb/item/plee/state_idle.hpp"
54
 
#include "ptb/item/plee/state_jump.hpp"
55
 
#include "ptb/item/plee/state_fall.hpp"
56
 
#include "ptb/item/plee/state_dead.hpp"
57
 
#include "ptb/item/plee/state_game_over.hpp"
58
 
#include "ptb/item/plee/state_run.hpp"
59
 
#include "ptb/item/plee/state_slap.hpp"
60
 
#include "ptb/item/plee/state_start_jump.hpp"
61
 
#include "ptb/item/plee/state_vertical_jump.hpp"
62
 
#include "ptb/item/plee/state_look_upward.hpp"
63
 
#include "ptb/item/plee/state_crouch.hpp"
64
 
#include "ptb/item/plee/state_captive.hpp"
65
 
#include "ptb/item/plee/state_throw.hpp"
66
 
#include "ptb/item/plee/state_maintain.hpp"
67
 
#include "ptb/item/plee/state_wait.hpp"
68
 
#include "ptb/item/plee/state_start_cling.hpp"
69
 
#include "ptb/item/plee/state_cling.hpp"
70
 
#include "ptb/item/plee/state_clung_jump.hpp"
71
 
#include "ptb/item/plee/state_start_hang.hpp"
72
 
#include "ptb/item/plee/state_hang.hpp"
73
 
#include "ptb/item/plee/state_sink.hpp"
74
 
#include "ptb/item/plee/state_swimming.hpp"
75
 
#include "ptb/item/plee/state_float.hpp"
76
 
#include "ptb/item/plee/state_injured.hpp"
77
 
 
78
 
#include "ptb/transition_effect/game_over_effect.hpp"
79
 
#include "ptb/transition_effect/invincibility_effect.hpp"
80
 
 
81
 
BASE_ITEM_IMPLEMENT( plee, ptb )
82
 
 
83
 
/*----------------------------------------------------------------------------*/
84
 
const double ptb::plee::s_max_oxygen = 10000;
85
 
const double ptb::plee::s_max_fire_gauge = 10000;
86
 
const double ptb::plee::s_max_ice_gauge = 10000;
87
 
const double ptb::plee::s_mass = 100;
88
 
const double ptb::plee::s_density = 2;
89
 
 
90
 
const unsigned int ptb::plee::s_states_cardinality = 26;
91
 
const unsigned int ptb::plee::s_gauges_cardinality = 3;
92
 
const int ptb::plee::s_speed_to_run = 580;
93
 
const double ptb::plee::s_oxygen_loss_speed = 200;
94
 
const double ptb::plee::s_oxygen_inspiration_speed = 1500;
95
 
const double ptb::plee::s_fire_loss_speed = 200;
96
 
const double ptb::plee::s_fire_increase_speed = 1500;
97
 
const double ptb::plee::s_ice_loss_speed = 200;
98
 
const double ptb::plee::s_ice_increase_speed = 1500;
99
 
 
100
 
const bear::universe::size_type ptb::plee::s_max_halo_height = 64;
101
 
const bear::universe::size_type ptb::plee::s_max_halo_hand_width = 35;
102
 
 
103
 
const bear::universe::time_type ptb::plee::s_time_to_crouch = 0.5;
104
 
const bear::universe::time_type ptb::plee::s_time_to_look_upward = 0.5;
105
 
const bear::universe::time_type ptb::plee::s_time_to_wait = 3;
106
 
const bear::universe::time_type ptb::plee::s_time_to_jump = 1;
107
 
const bear::universe::time_type ptb::plee::s_time_to_run = 1.2;
108
 
const bear::universe::time_type ptb::plee::s_time_to_start_throw = 0.34;
109
 
const bear::universe::time_type ptb::plee::s_max_time_to_cling = 0.3;
110
 
const bear::universe::time_type ptb::plee::s_max_time_to_hang = 1;
111
 
const bear::universe::time_type ptb::plee::s_max_time_air_float = 1;
112
 
 
113
 
/*----------------------------------------------------------------------------*/
114
 
/**
115
 
 * \brief Constructor.
116
 
 */
117
 
ptb::plee::get_instance_message::get_instance_message()
118
 
  : m_plee_instance(NULL)
119
 
{
120
 
 
121
 
} // get_instance_message::get_instance_message()
122
 
 
123
 
/*----------------------------------------------------------------------------*/
124
 
/**
125
 
 * \brief Re-initialise the message.
126
 
 */
127
 
void ptb::plee::get_instance_message::clear()
128
 
{
129
 
  m_plee_instance = NULL;
130
 
} // get_instance_message::clear()
131
 
 
132
 
/*----------------------------------------------------------------------------*/
133
 
/**
134
 
 * \brief Apply the message to a player.
135
 
 * \param that The player to apply the message to.
136
 
 */
137
 
bool ptb::plee::get_instance_message::apply_to( plee& that )
138
 
{
139
 
  m_plee_instance = &that;
140
 
  return true;
141
 
} // get_instance_message::apply_to()
142
 
 
143
 
/*----------------------------------------------------------------------------*/
144
 
/**
145
 
 * \brief Get the instance of the player.
146
 
 */
147
 
ptb::plee*
148
 
ptb::plee::get_instance_message::get_instance() const
149
 
{
150
 
  return m_plee_instance;
151
 
} // get_instance_message::get_instance()
152
 
 
153
 
 
154
 
 
155
 
 
156
 
 
157
 
 
158
 
/*----------------------------------------------------------------------------*/
159
 
/**
160
 
 * \brief Constructor.
161
 
 */
162
 
ptb::plee::plee()
163
 
  : m_current_state(roar_state), m_progress(&plee::progress_roar),
164
 
    m_last_visual_time(0),
165
 
    m_status_look_upward(false), m_status_crouch(false), m_can_cling(false),
166
 
    m_halo_animation(NULL), m_halo_hand_animation(NULL),  
167
 
    m_move_right(false), m_move_left(false),
168
 
    m_right_move_force(0),
169
 
    m_index(0), m_nb_bottom_contact(0),
170
 
    m_marionette(false), m_animation_to_throw(NULL),
171
 
    m_hot_spot_position(0, 0), m_hot_spot_minimum(0, 0),
172
 
    m_hot_spot_maximum(0, 0), m_hot_spot_balance_move(0, 0)
173
 
    
174
 
{
175
 
  set_speaker_item(this);
176
 
  set_mass(s_mass);
177
 
  set_density(s_density);
178
 
  set_size( 50, 110 );
179
 
  
180
 
  set_z_fixed(false);
181
 
 
182
 
  set_spot_minimum(-150, -250);
183
 
  set_spot_maximum(150, 300);
184
 
  set_spot_balance_move(3, 15);
185
 
 
186
 
  m_offensive_force = 10;
187
 
  m_energy = 100;
188
 
  if ( get_index() == 1 )
189
 
    m_monster_type = monster::player_1_monster;
190
 
  else
191
 
    m_monster_type = monster::player_2_monster;
192
 
  m_offensive_phase = false;
193
 
  m_offensive_coefficients[normal_attack] = 1;
194
 
  
195
 
  m_gauges.resize(s_gauges_cardinality);
196
 
  m_gauges[oxygen_gauge] = new gauge(s_max_oxygen);
197
 
  m_gauges[fire_gauge] = new gauge(s_max_fire_gauge);
198
 
  m_gauges[ice_gauge] = new gauge(s_max_ice_gauge);
199
 
 
200
 
  save_position( get_center_of_mass() );
201
 
  m_last_bottom_left = bear::universe::position_type(0,0);
202
 
 
203
 
  m_invincible_time = 0;
204
 
  m_run_time = 0;
205
 
 
206
 
  m_states.resize(s_states_cardinality);
207
 
  m_states[walk_state] = new state_walk(this);
208
 
  m_states[idle_state] = new state_idle(this);
209
 
  m_states[jump_state] = new state_jump(this);
210
 
  m_states[fall_state] = new state_fall(this);
211
 
  m_states[dead_state] = new state_dead(this);
212
 
  m_states[game_over_state] = new state_game_over(this);
213
 
  m_states[roar_state] = new state_roar(this);
214
 
  m_states[run_state] = new state_run(this);
215
 
  m_states[slap_state] = new state_slap(this);
216
 
  m_states[start_jump_state] = new state_start_jump(this);
217
 
  m_states[vertical_jump_state] = new state_vertical_jump(this);
218
 
  m_states[look_upward_state] = new state_look_upward(this);
219
 
  m_states[crouch_state] = new state_crouch(this);
220
 
  m_states[captive_state] = new state_captive(this);
221
 
  m_states[throw_state] = new state_throw(this);
222
 
  m_states[wait_state] = new state_wait(this);
223
 
  m_states[start_cling_state] = new state_start_cling(this);
224
 
  m_states[cling_state] = new state_cling(this);
225
 
  m_states[clung_jump_state] = new state_clung_jump(this);
226
 
  m_states[start_hang_state] = new state_start_hang(this);
227
 
  m_states[hang_state] = new state_hang(this);
228
 
  m_states[swimming_state] = new state_swimming(this);
229
 
  m_states[sink_state] = new state_sink(this);
230
 
  m_states[float_state] = new state_float(this);
231
 
  m_states[maintain_state] = new state_maintain(this);
232
 
  m_states[injured_state] = new state_injured(this);
233
 
} // plee::plee()
234
 
 
235
 
/*----------------------------------------------------------------------------*/
236
 
/**
237
 
 * \brief Destructor.
238
 
 */
239
 
ptb::plee::~plee()
240
 
{
241
 
  unsigned int i;
242
 
 
243
 
  for (i=0; i!=s_states_cardinality; ++i)
244
 
    delete m_states[i];
245
 
 
246
 
  for (i=0; i!=s_gauges_cardinality; ++i)
247
 
    delete m_gauges[i];
248
 
 
249
 
  if ( m_halo_animation )
250
 
    delete m_halo_animation;
251
 
 
252
 
  if ( m_halo_hand_animation )
253
 
    delete m_halo_hand_animation;
254
 
 
255
 
  if ( m_animation_to_throw ) 
256
 
    {
257
 
      delete m_animation_to_throw;
258
 
      m_animation_to_throw = NULL;
259
 
    }
260
 
} // plee::~plee()
261
 
 
262
 
/*---------------------------------------------------------------------------*/
263
 
/**
264
 
 * \brief Do one iteration in the progression of the item.
265
 
 * \param elapsed_time Elapsed time since the last call.
266
 
 */
267
 
void ptb::plee::progress( bear::universe::time_type elapsed_time )
268
 
{
269
 
  // THIS CONDITION MUST BE DONE IN FIRST
270
 
  if ( ! m_marionette ) 
271
 
    progress_input_reader(elapsed_time);
272
 
  
273
 
  super::progress(elapsed_time);
274
 
 
275
 
  m_state_time += elapsed_time;
276
 
  m_run_time += elapsed_time;
277
 
 
278
 
  if ( m_air_float )
279
 
    progress_air_float(elapsed_time);
280
 
  
281
 
  progress_invincibility(elapsed_time);
282
 
 
283
 
  if ( is_crushed() )
284
 
    apply_die();
285
 
  else
286
 
    {
287
 
      if ( m_progress != NULL )
288
 
        (this->*m_progress)(elapsed_time);
289
 
 
290
 
      update_powers();
291
 
      progress_spot( elapsed_time );
292
 
      progress_gauges( elapsed_time );
293
 
      update_orientation();
294
 
      m_can_cling = false;
295
 
 
296
 
      if ( ( m_current_state == plee::maintain_state ) ||
297
 
           ( m_current_state == plee::throw_state ) )
298
 
        m_halo_hand_animation->next(elapsed_time);
299
 
      
300
 
      if ( m_animation_to_throw != NULL )
301
 
        m_animation_to_throw->next(elapsed_time);
302
 
    }
303
 
 
304
 
  m_last_bottom_left = get_bottom_left();
305
 
  m_can_throw_power[air_attack] = true;
306
 
  m_can_throw_power[fire_attack] = true;
307
 
  m_can_throw_power[water_attack] = true;
308
 
} // plee::progress()
309
 
 
310
 
/*----------------------------------------------------------------------------*/
311
 
/**
312
 
 * \brief Get the sprite representing the item.
313
 
 * \param visuals (out) The sprites of the item, and their positions.
314
 
 */
315
 
void
316
 
ptb::plee::get_visual( std::list<bear::engine::scene_visual>& visuals ) const
317
 
{
318
 
  get_visuals_without_invincibility(visuals);
319
 
 
320
 
  std::list< std::list<bear::engine::scene_visual> >::const_iterator it;
321
 
  
322
 
  for ( it = m_last_visuals.begin(); it != m_last_visuals.end(); ++it )
323
 
    {
324
 
      std::list<bear::engine::scene_visual>::const_iterator it2;
325
 
      for (it2 = it->begin(); it2 != it->end(); ++it2 )
326
 
        visuals.push_front(*it2);
327
 
    }  
328
 
} // plee::get_visual()
329
 
 
330
 
/*----------------------------------------------------------------------------*/
331
 
/**
332
 
 * \brief Load the media required by this class.
333
 
 */
334
 
void ptb::plee::pre_cache()
335
 
{
336
 
  // plee
337
 
  get_level_globals().load_model("model/plee/plee.cm");
338
 
    
339
 
  // halo for vertical jump
340
 
  get_level_globals().load_animation("animation/plee/halo.canim");
341
 
  get_level_globals().load_animation("animation/plee/halo_hand.canim");
342
 
 
343
 
  // little_plee
344
 
  get_level_globals().load_animation("animation/powerup/life_bonus/run.canim");
345
 
  get_level_globals().load_animation
346
 
    ("animation/powerup/life_bonus/jump.canim");
347
 
 
348
 
  // small honeypot
349
 
  get_level_globals().load_animation("animation/powerup/small_fire.canim");
350
 
  get_level_globals().load_animation("animation/powerup/small_air.canim");
351
 
  get_level_globals().load_animation("animation/powerup/small_water.canim");
352
 
  
353
 
  // stones
354
 
  get_level_globals().load_model("model/stones/stone.cm");
355
 
  get_level_globals().load_model("model/stones/air_stone.cm");
356
 
  get_level_globals().load_model("model/stones/water_stone.cm");
357
 
  get_level_globals().load_model("model/stones/fire_stone.cm");
358
 
  get_level_globals().load_model("model/stones/air_fire_stone.cm");
359
 
  get_level_globals().load_model("model/stones/air_water_stone.cm");
360
 
  get_level_globals().load_model("model/stones/water_fire_stone.cm");
361
 
  get_level_globals().load_model("model/stones/air_fire_water_stone.cm");
362
 
  get_level_globals().load_animation("animation/stones/sliver_1.canim");
363
 
  get_level_globals().load_animation("animation/stones/sliver_2.canim");
364
 
  get_level_globals().load_animation("animation/stones/sliver_3.canim");
365
 
  get_level_globals().load_animation("animation/stones/sliver_4.canim");
366
 
  get_level_globals().load_animation("animation/stones/sliver_5.canim");
367
 
} // plee::pre_cache()
368
 
 
369
 
/*----------------------------------------------------------------------------*/
370
 
/**
371
 
 * \brief Do post creation actions.
372
 
 */
373
 
void ptb::plee::build()
374
 
{
375
 
  super::build();
376
 
 
377
 
  game_variables::set_lives_count(m_index, 3);
378
 
 
379
 
  set_model_actor( get_level_globals().get_model("model/plee/plee.cm") );
380
 
 
381
 
  if ( m_index == 1 )
382
 
    m_monster_type = monster::player_1_monster;
383
 
  else
384
 
    {
385
 
      m_monster_type = monster::player_2_monster;
386
 
      get_rendering_attributes().set_intensity(1, 1, 0.7);
387
 
    }
388
 
  
389
 
  m_air_float = false;
390
 
  save_position( get_center_of_mass() );
391
 
  start_action_model("idle");
392
 
  
393
 
  bear::engine::level_globals& glob = get_level_globals();
394
 
 
395
 
  m_halo_animation = new bear::visual::animation
396
 
    ( glob.get_animation("animation/plee/halo.canim") );
397
 
 
398
 
  m_halo_hand_animation = new bear::visual::animation
399
 
    ( glob.get_animation("animation/plee/halo_hand.canim") );
400
 
 
401
 
  get_level().add_interest_around(this);
402
 
 
403
 
  m_can_throw_power[air_attack] = true;
404
 
  m_can_throw_power[fire_attack] = true;
405
 
  m_can_throw_power[water_attack] = true;
406
 
} // plee::build()
407
 
 
408
 
/*----------------------------------------------------------------------------*/
409
 
/**
410
 
 * \brief Tell if the item is correctly initialized.
411
 
 */
412
 
bool ptb::plee::is_valid() const
413
 
{
414
 
  return (m_index != 0) && super::is_valid();
415
 
} // player::is_valid()
416
 
 
417
 
/*----------------------------------------------------------------------------*/
418
 
/**
419
 
 * \brief Set a field of type <unsigned integer>.
420
 
 * \param name The name of the field.
421
 
 * \param value The new value of the field.
422
 
 * \return false if the field "name" is unknow, true otherwise.
423
 
 */
424
 
bool ptb::plee::set_u_integer_field
425
 
( const std::string& name, unsigned int value )
426
 
{
427
 
  bool result = true;
428
 
 
429
 
  if (name == "index")
430
 
    set_index(value);
431
 
  else
432
 
    result = super::set_u_integer_field(name, value);
433
 
 
434
 
  return result;
435
 
} // player::set_u_integer_field()
436
 
 
437
 
/*----------------------------------------------------------------------------*/
438
 
/**
439
 
 * \brief Save the position of the plee.
440
 
 * \param p The center of mass to remember.
441
 
 */
442
 
void ptb::plee::save_position( const bear::universe::position_type& p )
443
 
{
444
 
  m_saved_position = p;
445
 
} // plee::save_position()
446
 
 
447
 
/*----------------------------------------------------------------------------*/
448
 
/**
449
 
 * \brief Tell to Plee to start an action.
450
 
 * \param a The action to start.
451
 
 */
452
 
void ptb::plee::start_action( player_action::value_type a )
453
 
{
454
 
  switch( a )
455
 
    {
456
 
    case player_action::idle : break;
457
 
    case player_action::move_left : break;
458
 
    case player_action::move_right : break;
459
 
    case player_action::jump :
460
 
      m_states[m_current_state]->do_jump(); break;
461
 
    case player_action::get_camera : do_get_camera(); break;
462
 
    case player_action::slap :
463
 
      m_states[m_current_state]->do_slap(); break;
464
 
    case player_action::look_upward : do_start_look_upward(); break;
465
 
    case player_action::crouch :  do_start_crouch(); break;
466
 
    case player_action::drop : do_start_drop(); break;
467
 
    case player_action::chain : break;
468
 
    case player_action::unchain : break;
469
 
    case player_action::throw_stone : do_start_throw(); break;
470
 
    case player_action::die : apply_die(); break;
471
 
    case player_action::roar : start_action_model("roar"); break;
472
 
    case player_action::action_null: break;
473
 
    default:
474
 
      claw::logger << claw::log_warning << "Action ignored (start): " << a
475
 
                   << std::endl;;
476
 
    }
477
 
} // plee::start_action()
478
 
 
479
 
/*----------------------------------------------------------------------------*/
480
 
/**
481
 
 * \brief Tell to the plee to do an action.
482
 
 * \param elapsed_time How long the action is done.
483
 
 * \param a The action to do.
484
 
 */
485
 
void ptb::plee::do_action
486
 
( bear::universe::time_type elapsed_time, player_action::value_type a )
487
 
{
488
 
  switch( a )
489
 
    {
490
 
    case player_action::idle : set_state(idle_state); break;
491
 
    case player_action::move_left :
492
 
      m_states[m_current_state]->do_move_left(); break;
493
 
    case player_action::move_right :
494
 
      m_states[m_current_state]->do_move_right(); break;
495
 
    case player_action::jump : break;
496
 
    case player_action::get_camera : break;
497
 
    case player_action::slap : break;
498
 
    case player_action::look_upward :
499
 
      m_states[m_current_state]->do_continue_look_upward(); break;
500
 
    case player_action::crouch :
501
 
      m_states[m_current_state]->do_continue_crouch(); break;
502
 
    case player_action::drop : break;
503
 
    case player_action::chain :
504
 
      m_states[m_current_state]->chain(); break;
505
 
    case player_action::unchain :
506
 
      m_states[m_current_state]->unchain(); break;
507
 
    case player_action::throw_stone : break;
508
 
    case player_action::die : break;
509
 
    case player_action::action_null: break;
510
 
    default:
511
 
      claw::logger << claw::log_warning << "Action ignored: " << a
512
 
                   << std::endl;
513
 
    }
514
 
} // plee::do_action()
515
 
 
516
 
/*----------------------------------------------------------------------------*/
517
 
/**
518
 
 * \brief Tell to plee to stop an action.
519
 
 * \param a The action to stop.
520
 
 */
521
 
void ptb::plee::stop_action( player_action::value_type a )
522
 
{
523
 
  switch( a )
524
 
    {
525
 
    case player_action::idle : break;
526
 
    case player_action::move_left : break;
527
 
    case player_action::move_right : break;
528
 
    case player_action::jump :
529
 
      m_states[m_current_state]->do_stop_vertical_jump(); break;
530
 
    case player_action::get_camera : break;
531
 
    case player_action::slap : break;
532
 
    case player_action::look_upward : do_stop_look_upward(); break;
533
 
    case player_action::crouch :
534
 
      do_stop_crouch(); break;
535
 
    case player_action::throw_stone :
536
 
      m_states[m_current_state]->do_stop_throw(); break;
537
 
    case player_action::drop : 
538
 
      m_states[m_current_state]->do_stop_throw(); break;
539
 
    case player_action::chain : break;
540
 
    case player_action::unchain : break;
541
 
    case player_action::die : break;
542
 
    case player_action::action_null: break;
543
 
    default:
544
 
      claw::logger << claw::log_warning << "Action ignored (stop): " << a
545
 
                   << std::endl;
546
 
    }
547
 
} // plee::stop_action()
548
 
 
549
 
/*----------------------------------------------------------------------------*/
550
 
/**
551
 
 * \brief Start a new action of model.
552
 
 */
553
 
void ptb::plee::start_action_model(const std::string& action)
554
 
{
555
 
  start_model_action(action);
556
 
} // plee::start_action_model()
557
 
 
558
 
/*----------------------------------------------------------------------------*/
559
 
/**
560
 
 * \brief Give a gauge.
561
 
 * \param t The type of the gauge
562
 
 */
563
 
const ptb::gauge* ptb::plee::get_gauge(gauge_type t) const
564
 
{
565
 
  if ( (unsigned int)t >= s_gauges_cardinality )
566
 
    {
567
 
      claw::logger << claw::log_verbose << "It is not a valid gauge_type."
568
 
                   << std::endl;
569
 
      return NULL;
570
 
    }
571
 
  else
572
 
    return m_gauges[t];
573
 
} // plee::get_gauge()
574
 
 
575
 
/*----------------------------------------------------------------------------*/
576
 
/**
577
 
 * \brief Give the ratio of the length of preparation of the jump.
578
 
 */
579
 
bear::universe::time_type ptb::plee::get_jump_time_ratio() const
580
 
{
581
 
  return m_jump_time_ratio;
582
 
} // plee::get_jump_time_ratio()
583
 
 
584
 
/*----------------------------------------------------------------------------*/
585
 
/**
586
 
 * \brief Updtae the ratio of the preparation of throw state.
587
 
 */
588
 
void ptb::plee::update_throw_time_ratio()
589
 
{
590
 
  m_throw_time_ratio = m_state_time / s_time_to_start_throw;
591
 
} // plee::update_throw_time_ratio()
592
 
 
593
 
/*----------------------------------------------------------------------------*/
594
 
/**
595
 
 * \brief Set the value of throw_down.
596
 
 * \param value The state of throw_down.
597
 
 */
598
 
void ptb::plee::set_throw_down(bool value)
599
 
{
600
 
  m_throw_down = value;
601
 
} // plee::set_throw_down()
602
 
 
603
 
/*----------------------------------------------------------------------------*/
604
 
/**
605
 
 * \brief Start to throw an azelnut
606
 
 */
607
 
void ptb::plee::throw_azelnut()
608
 
{
609
 
  m_current_object = azelnut_object;
610
 
  m_animation_to_throw = new bear::visual::animation
611
 
    ( get_level_globals().get_animation
612
 
      ("animation/owl/azelnut.canim") );
613
 
  m_states[m_current_state]->do_start_throw();
614
 
} // plee::throw_azelnut()
615
 
 
616
 
/*----------------------------------------------------------------------------*/
617
 
/**
618
 
 * \brief Set the value of throw_up.
619
 
 * \param value The state of throw_up.
620
 
 */
621
 
void ptb::plee::set_throw_up(bool value)
622
 
{
623
 
  m_throw_up = value;
624
 
} // plee::set_throw_up()
625
 
 
626
 
/*----------------------------------------------------------------------------*/
627
 
/**
628
 
 * \brief Indicates if Plee is a marionette.
629
 
 */
630
 
bool ptb::plee::is_a_marionette() const
631
 
{
632
 
  return m_marionette;
633
 
} // plee::is_a_marionette()
634
 
 
635
 
/*----------------------------------------------------------------------------*/
636
 
/**
637
 
 * \brief Turn on/off the marionette state of Plee.
638
 
 * \param b The new value of the state.
639
 
 */
640
 
void ptb::plee::set_marionette( bool b )
641
 
{
642
 
  m_marionette = b;
643
 
} // plee::set_marionette()
644
 
 
645
 
/*----------------------------------------------------------------------------*/
646
 
/**
647
 
 * \brief Turn on/off the air_float status of Plee.
648
 
 * \param b The new value of the state.
649
 
 */
650
 
void ptb::plee::set_air_float( bool b )
651
 
{
652
 
  m_air_float = b;
653
 
  m_air_float_time = 0; 
654
 
} // plee::set_air_float()
655
 
 
656
 
/*----------------------------------------------------------------------------*/
657
 
/**
658
 
 * \brief Set the look up status.
659
 
 */
660
 
void ptb::plee::set_status_look_upward(bool status)
661
 
{
662
 
  m_status_look_upward = status;
663
 
} // plee::set_status_look_upward()
664
 
 
665
 
/*----------------------------------------------------------------------------*/
666
 
/**
667
 
 * \brief Give the look up status.
668
 
 */
669
 
bool ptb::plee::get_status_look_upward() const
670
 
{
671
 
  return m_status_look_upward;
672
 
} // plee::get_status_look_upward()
673
 
 
674
 
/*----------------------------------------------------------------------------*/
675
 
/**
676
 
 * \brief Set the crouch status.
677
 
 */
678
 
void ptb::plee::set_status_crouch(bool status)
679
 
{
680
 
  m_status_crouch = status;
681
 
} // plee::set_status_crouch()
682
 
 
683
 
/*----------------------------------------------------------------------------*/
684
 
/**
685
 
 * \brief Give the crouch status.
686
 
 */
687
 
bool ptb::plee::get_status_crouch() const
688
 
{
689
 
  return m_status_crouch;
690
 
} // plee::get_status_crouch()
691
 
 
692
 
/*----------------------------------------------------------------------------*/
693
 
/**
694
 
 * \brief Make the plee start to look up.
695
 
 */
696
 
void ptb::plee::do_start_look_upward()
697
 
{
698
 
  m_status_look_upward = true;
699
 
  m_look_upward_time = 0;
700
 
  m_states[m_current_state]->do_look_upward();
701
 
} // plee::do_start_look_upward()
702
 
 
703
 
/*----------------------------------------------------------------------------*/
704
 
/**
705
 
 * \brief Make the plee start to crouch.
706
 
 */
707
 
void ptb::plee::do_start_crouch()
708
 
{
709
 
  m_status_crouch = true;
710
 
  m_crouch_time = 0;
711
 
  m_states[m_current_state]->do_crouch();
712
 
} // plee::do_start_crouch()
713
 
 
714
 
/*----------------------------------------------------------------------------*/
715
 
/**
716
 
 * \brief Make the plee start to crouch.
717
 
 */
718
 
void ptb::plee::do_start_throw()
719
 
{
720
 
  if ( ( game_variables::get_stones_count(m_index) > 0 ) 
721
 
       && m_air_stones.empty() )
722
 
    {
723
 
      m_current_object = stone_object;
724
 
 
725
 
      if ( game_variables::get_air_power(m_index) )
726
 
        if ( game_variables::get_fire_power(m_index) )
727
 
          if ( game_variables::get_water_power(m_index) )
728
 
            m_animation_to_throw = new bear::visual::animation
729
 
              ( get_level_globals().get_animation
730
 
                ("animation/stones/air_fire_water_stone.canim") );
731
 
          else
732
 
            m_animation_to_throw = new bear::visual::animation
733
 
              ( get_level_globals().get_animation
734
 
                ("animation/stones/air_fire_stone.canim") );
735
 
        else
736
 
          if ( game_variables::get_water_power(m_index) )
737
 
            m_animation_to_throw = new bear::visual::animation
738
 
              ( get_level_globals().get_animation
739
 
                ("animation/stones/air_water_stone.canim") );
740
 
          else
741
 
            m_animation_to_throw = new bear::visual::animation
742
 
              ( get_level_globals().get_animation
743
 
                ("animation/stones/air_stone.canim") );
744
 
      else
745
 
        if ( game_variables::get_fire_power(m_index) )
746
 
          if ( game_variables::get_water_power(m_index) )
747
 
            m_animation_to_throw = new bear::visual::animation
748
 
              ( get_level_globals().get_animation
749
 
                ("animation/stones/water_fire_stone.canim") );
750
 
          else
751
 
            m_animation_to_throw = new bear::visual::animation
752
 
              ( get_level_globals().get_animation
753
 
                ("animation/stones/fire_stone.canim") );
754
 
        else
755
 
          if ( game_variables::get_water_power(m_index) )
756
 
            m_animation_to_throw = new bear::visual::animation
757
 
              ( get_level_globals().get_animation
758
 
                ("animation/stones/water_stone.canim") );
759
 
          else
760
 
            m_animation_to_throw = new bear::visual::animation
761
 
              ( get_level_globals().get_animation
762
 
                ("animation/stones/stone.canim") );
763
 
 
764
 
      m_states[m_current_state]->do_start_throw();
765
 
    }
766
 
  else
767
 
    apply_blast_stone();
768
 
} // plee::do_start_throw()
769
 
 
770
 
/*----------------------------------------------------------------------------*/
771
 
/**
772
 
 * \brief Make the plee start to drop.
773
 
 */
774
 
void ptb::plee::do_start_drop()
775
 
{
776
 
  if ( has_a_power() )
777
 
    m_states[m_current_state]->do_start_drop();
778
 
} // plee::do_start_drop()
779
 
 
780
 
/*----------------------------------------------------------------------------*/
781
 
/**
782
 
 * \brief Set if Plee can cling.
783
 
 * \param status The new status.
784
 
 */
785
 
void ptb::plee::set_can_cling(bool status)
786
 
{
787
 
  m_can_cling = status;
788
 
} // plee::set_can_cling()
789
 
 
790
 
/*----------------------------------------------------------------------------*/
791
 
/**
792
 
 * \brief Plee receives energy.
793
 
 *
794
 
 * \param energy The energy received.
795
 
 */
796
 
void ptb::plee::receive_energy(double energy)
797
 
{
798
 
  m_energy += energy;
799
 
 
800
 
  if ( m_energy > game_variables::get_max_energy(m_index) )
801
 
    m_energy = game_variables::get_max_energy(m_index);
802
 
} // plee::receive_energy()
803
 
 
804
 
/*----------------------------------------------------------------------------*/
805
 
/**
806
 
 * \brief Set the invincible status.
807
 
 * \param invincible The new invincible status.
808
 
 */
809
 
void ptb::plee::set_invincible(const bool invincible)
810
 
{
811
 
  super::set_invincible(invincible);
812
 
  
813
 
  if ( m_invincible )
814
 
    {
815
 
      m_invincible_time = 0;
816
 
      m_last_visual_time = 0;
817
 
      m_last_visuals.clear();
818
 
 
819
 
      bear::engine::transition_effect_message<invincibility_effect> msg;
820
 
      get_level_globals().send_message
821
 
        ( PTB_TRANSITION_EFFECT_DEFAULT_TARGET_NAME, msg );
822
 
    }
823
 
} // plee::set_invincible()
824
 
 
825
 
/*----------------------------------------------------------------------------*/
826
 
/**
827
 
 * \brief Plee receives oxygen.
828
 
 *
829
 
 * \param oxygen The oxygen received.
830
 
 */
831
 
void ptb::plee::receive_oxygen(double oxygen)
832
 
{
833
 
  m_gauges[oxygen_gauge]->add_value(oxygen);
834
 
} // plee::receive_oxygen()
835
 
 
836
 
/*----------------------------------------------------------------------------*/
837
 
/**
838
 
 * \brief Add a air_stone in the air stone set.
839
 
 *
840
 
 * \param s The stone to add.
841
 
 */
842
 
void ptb::plee::add_air_stone(ptb::stone* s)
843
 
{
844
 
  m_air_stones.insert(s);
845
 
} // plee::add_air_stone()
846
 
 
847
 
/*----------------------------------------------------------------------------*/
848
 
/**
849
 
 * \brief Remove a air_stone in the air stone set.
850
 
 *
851
 
 * \param s The stone to remove.
852
 
 */
853
 
void ptb::plee::remove_air_stone( ptb::stone* s)
854
 
{
855
 
  std::set< ptb::stone* >::iterator it;
856
 
  it = m_air_stones.find(s);
857
 
 
858
 
  if ( it != m_air_stones.end() )
859
 
    m_air_stones.erase(it);
860
 
} // plee::remove_air_stone()
861
 
 
862
 
/*----------------------------------------------------------------------------*/
863
 
/**
864
 
 * \brief Indicates if Plee can throw a given power.
865
 
 * \param p The status.
866
 
 * \param a The corresponding attack
867
 
 */
868
 
void ptb::plee::can_throw_power( bool b, monster::attack_type a)
869
 
{
870
 
  m_can_throw_power[a] = b;
871
 
} // plee::can_throw_power()
872
 
 
873
 
/*----------------------------------------------------------------------------*/
874
 
/**
875
 
 * \brief Get the coordinates of the point to target to (for camera or active
876
 
 *        region).
877
 
 */
878
 
bear::universe::position_type ptb::plee::hot_spot() const
879
 
{
880
 
  bear::universe::position_type p;
881
 
  
882
 
  bear::universe::size_type w,h;
883
 
  get_action("idle")->get_max_size(w,h);
884
 
  const bear::universe::size_box_type half_plee( w / 2, h / 2 );
885
 
 
886
 
  if ( get_rendering_attributes().is_mirrored() )
887
 
    {
888
 
      p = get_bottom_right();
889
 
      p.x -= half_plee.x;
890
 
    }
891
 
  else
892
 
    {
893
 
      p = get_bottom_left();
894
 
      p.x += half_plee.x;
895
 
    }
896
 
 
897
 
  p.y += half_plee.y;
898
 
 
899
 
  return p + m_hot_spot_position;
900
 
} // player::hot_spot()
901
 
 
902
 
/*----------------------------------------------------------------------------*/
903
 
/**
904
 
 * \brief Get the index of this player.
905
 
 */
906
 
unsigned int ptb::plee::get_index() const
907
 
{
908
 
  return m_index;
909
 
} // player::get_index()
910
 
 
911
 
/*----------------------------------------------------------------------------*/
912
 
/**
913
 
 * \brief Set the index of this player.
914
 
 * \param index The index of the player.
915
 
 */
916
 
void ptb::plee::set_index( unsigned int index )
917
 
{
918
 
  m_index = index;
919
 
  set_name( player_name(index) );
920
 
  set_player_index(index);
921
 
} // player::set_index()
922
 
 
923
 
/*----------------------------------------------------------------------------*/
924
 
/**
925
 
 * \brief Get the name of the player associated to an index.
926
 
 * \param player_index The index of the player.
927
 
 */
928
 
std::string ptb::plee::player_name( unsigned int player_index )
929
 
{
930
 
  std::ostringstream oss;
931
 
  oss << "player_" << player_index;
932
 
 
933
 
  return oss.str();
934
 
} // player::player_name()
935
 
 
936
 
/*----------------------------------------------------------------------------*/
937
 
/**
938
 
 * \brief Set the minimum acceptable value for the position of the hot spot.
939
 
 * \param x Minimum value on the X-axis.
940
 
 * \param y Minimum value on the Y-axis.
941
 
 */
942
 
void ptb::plee::set_spot_minimum
943
 
( bear::universe::coordinate_type x, bear::universe::coordinate_type y )
944
 
{
945
 
  m_hot_spot_minimum.set
946
 
    ( std::min(x, m_hot_spot_maximum.x), std::min(y, m_hot_spot_maximum.y) );
947
 
} // player::set_spot_minimum()
948
 
 
949
 
/*----------------------------------------------------------------------------*/
950
 
/**
951
 
 * \brief Set the maximum acceptable value for the position of the hot spot.
952
 
 * \param x Maximum value on the X-axis.
953
 
 * \param y Maximum value on the Y-axis.
954
 
 */
955
 
void ptb::plee::set_spot_maximum
956
 
( bear::universe::coordinate_type x, bear::universe::coordinate_type y )
957
 
{
958
 
  m_hot_spot_maximum.set
959
 
    ( std::max(x, m_hot_spot_minimum.x), std::max(y, m_hot_spot_minimum.y) );
960
 
} // player::set_spot_maximum()
961
 
 
962
 
/*----------------------------------------------------------------------------*/
963
 
/**
964
 
 * \brief Set the maximum movement allowed when balancing the hot spot.
965
 
 * \param x Maximum movement on the X-axis.
966
 
 * \param y Maximum movement on the Y-axis.
967
 
 */
968
 
void ptb::plee::set_spot_balance_move
969
 
( bear::universe::coordinate_type x, bear::universe::coordinate_type y )
970
 
{
971
 
  m_hot_spot_balance_move.set(std::abs(x), std::abs(y));
972
 
} // player::set_spot_balance_move()
973
 
 
974
 
/*----------------------------------------------------------------------------*/
975
 
/**
976
 
 * \brief Change the gap of the spot.
977
 
 * \param gap The vector of gap.
978
 
 */
979
 
void ptb::plee::add_spot_gap( const bear::universe::position_type& gap )
980
 
{
981
 
  m_hot_spot_position += gap;
982
 
 
983
 
  if ( m_hot_spot_position.x > m_hot_spot_maximum.x )
984
 
    m_hot_spot_position.x = m_hot_spot_maximum.x;
985
 
  else if ( m_hot_spot_position.x < m_hot_spot_minimum.x )
986
 
    m_hot_spot_position.x = m_hot_spot_minimum.x;
987
 
 
988
 
  if ( m_hot_spot_position.y > m_hot_spot_maximum.y )
989
 
    m_hot_spot_position.y = m_hot_spot_maximum.y;
990
 
  else if ( m_hot_spot_position.y < m_hot_spot_minimum.y )
991
 
    m_hot_spot_position.y = m_hot_spot_minimum.y;
992
 
} // player::add_spot_gap()
993
 
 
994
 
/*----------------------------------------------------------------------------*/
995
 
/**
996
 
 * \brief Balance the gap of the spot.
997
 
 * \param x Tell if we balance on the X-axis.
998
 
 * \param y Tell if we balance on the Y-axis.
999
 
 */
1000
 
void ptb::plee::balance_spot(bool x, bool y)
1001
 
{
1002
 
  if ( x )
1003
 
    {
1004
 
      if ( m_hot_spot_position.x > m_hot_spot_balance_move.x )
1005
 
        m_hot_spot_position.x -= m_hot_spot_balance_move.x;
1006
 
      else if ( m_hot_spot_position.x < -m_hot_spot_balance_move.x)
1007
 
        m_hot_spot_position.x += m_hot_spot_balance_move.x;
1008
 
      else
1009
 
        m_hot_spot_position.x = 0;
1010
 
    }
1011
 
 
1012
 
  if ( y )
1013
 
    {
1014
 
      if ( m_hot_spot_position.y > m_hot_spot_balance_move.y )
1015
 
        m_hot_spot_position.y -= m_hot_spot_balance_move.y;
1016
 
      else if ( m_hot_spot_position.y < -m_hot_spot_balance_move.y)
1017
 
        m_hot_spot_position.y += m_hot_spot_balance_move.y;
1018
 
      else
1019
 
        m_hot_spot_position.y = 0;
1020
 
    }
1021
 
} // player::balance_spot()
1022
 
 
1023
 
/*----------------------------------------------------------------------------*/
1024
 
/**
1025
 
 * \brief Drops one power.
1026
 
 */
1027
 
void ptb::plee::apply_drop()
1028
 
{
1029
 
  std::vector<std::string> powers;
1030
 
  
1031
 
  if ( game_variables::get_air_power(m_index) && 
1032
 
       m_can_throw_power[monster::air_attack] )
1033
 
    powers.push_back("air");
1034
 
  
1035
 
  if ( game_variables::get_fire_power(m_index) && 
1036
 
       m_can_throw_power[monster::air_attack] )
1037
 
    powers.push_back("fire");
1038
 
  
1039
 
  if ( game_variables::get_water_power(m_index) && 
1040
 
       m_can_throw_power[monster::air_attack] )
1041
 
    powers.push_back("water");
1042
 
  
1043
 
  if ( ! powers.empty() ) 
1044
 
    {
1045
 
      unsigned int a = (unsigned int)(powers.size() * rand() / RAND_MAX);
1046
 
      std::string drop_power;
1047
 
      
1048
 
      if ( a < powers.size() )
1049
 
        drop_power = powers[a];
1050
 
      else
1051
 
        drop_power = powers[0];
1052
 
      
1053
 
      if ( drop_power == "air" )
1054
 
        {
1055
 
          m_current_object = air_honeypot_object;
1056
 
          m_animation_to_throw = new bear::visual::animation
1057
 
            ( get_level_globals().get_animation
1058
 
              ("animation/powerup/small_air.canim") );
1059
 
          game_variables::set_air_power(m_index, false);
1060
 
          m_air_float = false;
1061
 
        }
1062
 
      else if ( drop_power == "fire" )
1063
 
        {
1064
 
          m_current_object = fire_honeypot_object;
1065
 
          m_animation_to_throw = new bear::visual::animation
1066
 
            ( get_level_globals().get_animation
1067
 
              ("animation/powerup/small_fire.canim") );
1068
 
          game_variables::set_fire_power(m_index, false);
1069
 
        }
1070
 
      else if ( drop_power == "water" )
1071
 
        {
1072
 
          m_current_object = water_honeypot_object;
1073
 
          m_animation_to_throw = new bear::visual::animation
1074
 
            ( get_level_globals().get_animation
1075
 
              ("animation/powerup/small_water.canim") );
1076
 
          game_variables::set_water_power(m_index, false);
1077
 
        }
1078
 
 
1079
 
      update_powers();
1080
 
      m_states[m_current_state]->do_start_throw();
1081
 
    }
1082
 
  else
1083
 
    start_action_model("idle");
1084
 
} // plee::apply_drop()
1085
 
 
1086
 
/*----------------------------------------------------------------------------*/
1087
 
/**
1088
 
 * \brief Apply the action move_right.
1089
 
 */
1090
 
void ptb::plee::apply_move_right()
1091
 
{
1092
 
  m_move_right = true;
1093
 
  add_internal_force( bear::universe::force_type(m_right_move_force, 0) );
1094
 
} // plee::apply_move_right()
1095
 
 
1096
 
/*----------------------------------------------------------------------------*/
1097
 
/**
1098
 
 * \brief Apply the action move_left.
1099
 
 */
1100
 
void ptb::plee::apply_move_left()
1101
 
{
1102
 
  m_move_left = true;
1103
 
  add_internal_force( bear::universe::force_type(-m_right_move_force, 0) );
1104
 
} // plee::apply_move_left()
1105
 
 
1106
 
/*----------------------------------------------------------------------------*/
1107
 
/**
1108
 
 * \brief Apply impulsion of a jump.
1109
 
 */
1110
 
void ptb::plee::apply_impulse_jump()
1111
 
{
1112
 
  if ( m_current_state == float_state )
1113
 
    add_internal_force( bear::universe::force_type(0, 7500000) );
1114
 
  else
1115
 
    {
1116
 
      add_external_force( bear::universe::force_type(0, 5750000) );
1117
 
      add_internal_force( bear::universe::force_type(0, 5750000) );
1118
 
    }
1119
 
} // plee::apply_impulse_jump()
1120
 
 
1121
 
 
1122
 
/*----------------------------------------------------------------------------*/
1123
 
/**
1124
 
 * \brief Apply the action jump.
1125
 
 */
1126
 
void ptb::plee::apply_jump()
1127
 
{
1128
 
  m_right_move_force = 100000;
1129
 
  set_state(plee::jump_state);
1130
 
  m_progress = &plee::progress_jump;
1131
 
} // plee::apply_jump()
1132
 
 
1133
 
/*----------------------------------------------------------------------------*/
1134
 
/**
1135
 
 * \brief Apply the action start_jump.
1136
 
 */
1137
 
void ptb::plee::apply_start_jump()
1138
 
{
1139
 
  set_state(plee::start_jump_state);
1140
 
  m_progress = &plee::progress_start_jump;
1141
 
  m_halo_animation->reset();
1142
 
} // plee::apply_start_jump()
1143
 
 
1144
 
/*----------------------------------------------------------------------------*/
1145
 
/**
1146
 
 * \brief Apply the action vertical_jump.
1147
 
 *
1148
 
 */
1149
 
void ptb::plee::apply_vertical_jump()
1150
 
{
1151
 
  m_right_move_force = 50000;
1152
 
  m_run_time = 0;
1153
 
 
1154
 
  if ( m_state_time >= s_time_to_jump )
1155
 
    m_jump_time_ratio = 1;
1156
 
  else
1157
 
    m_jump_time_ratio = m_state_time / s_time_to_jump;
1158
 
 
1159
 
  set_state(plee::vertical_jump_state);
1160
 
  m_progress = &plee::progress_vertical_jump;
1161
 
} // plee::apply_vertical_jump()
1162
 
 
1163
 
/*----------------------------------------------------------------------------*/
1164
 
/**
1165
 
 * \brief Apply the action fall.
1166
 
 *
1167
 
 */
1168
 
void ptb::plee::apply_fall()
1169
 
{
1170
 
  m_right_move_force = 100000;
1171
 
  set_state(plee::fall_state);
1172
 
  m_progress = &plee::progress_fall;
1173
 
} // plee::apply_fall()
1174
 
 
1175
 
/*----------------------------------------------------------------------------*/
1176
 
/**
1177
 
 * \brief Apply the action idle.
1178
 
 *
1179
 
 */
1180
 
void ptb::plee::apply_idle()
1181
 
{
1182
 
  m_right_move_force = 200000;
1183
 
  set_state(plee::idle_state);
1184
 
  m_progress = &plee::progress_idle;
1185
 
} // plee::apply_idle()
1186
 
 
1187
 
/*----------------------------------------------------------------------------*/
1188
 
/**
1189
 
 * \brief Apply the action walk.
1190
 
 *
1191
 
 */
1192
 
void ptb::plee::apply_walk()
1193
 
{
1194
 
  m_right_move_force = 200000;
1195
 
  set_state(plee::walk_state);
1196
 
  m_progress = &plee::progress_walk;
1197
 
} // plee::apply_walk()
1198
 
 
1199
 
/*----------------------------------------------------------------------------*/
1200
 
/**
1201
 
 * \brief Apply the action run.
1202
 
 *
1203
 
 */
1204
 
void ptb::plee::apply_run()
1205
 
{
1206
 
  m_right_move_force = 450000;
1207
 
  set_state(plee::run_state);
1208
 
  m_progress = &plee::progress_run;
1209
 
} // plee::apply_run()
1210
 
 
1211
 
/*----------------------------------------------------------------------------*/
1212
 
/**
1213
 
 * \brief Apply the action slap.
1214
 
 *
1215
 
 */
1216
 
void ptb::plee::apply_slap()
1217
 
{
1218
 
  m_right_move_force = 200000;
1219
 
  set_state(plee::slap_state);
1220
 
  m_progress = &plee::progress_slap;
1221
 
} // plee::apply_slap()
1222
 
 
1223
 
/*----------------------------------------------------------------------------*/
1224
 
/**
1225
 
 * \brief Turn the attack mode.
1226
 
 *
1227
 
 */
1228
 
void ptb::plee::apply_attack()
1229
 
{
1230
 
  set_offensive_phase(true);
1231
 
  set_defensive_power(monster::normal_attack,true);
1232
 
} // plee::apply_attack()
1233
 
 
1234
 
/*----------------------------------------------------------------------------*/
1235
 
/**
1236
 
 * \brief Apply the action chain.
1237
 
 *
1238
 
 */
1239
 
void ptb::plee::apply_chain()
1240
 
{
1241
 
  set_state(plee::captive_state);
1242
 
  m_progress = &plee::progress_captive;
1243
 
} // plee::apply_chain()
1244
 
 
1245
 
/*----------------------------------------------------------------------------*/
1246
 
/**
1247
 
 * \brief Apply the action unchain.
1248
 
 *
1249
 
 */
1250
 
void ptb::plee::apply_unchain()
1251
 
{
1252
 
  set_state(plee::idle_state);
1253
 
  m_progress = &plee::progress_idle;
1254
 
} // plee::apply_unchain()
1255
 
 
1256
 
/*----------------------------------------------------------------------------*/
1257
 
/**
1258
 
 * \brief Apply the action throw.
1259
 
 *
1260
 
 */
1261
 
void ptb::plee::apply_throw()
1262
 
{
1263
 
  if ( get_current_action_name() == "throw_and_fall" )
1264
 
    m_right_move_force = 100000;
1265
 
  else
1266
 
    m_right_move_force = 200000;
1267
 
  
1268
 
  set_state(plee::throw_state);
1269
 
  m_progress = &plee::progress_throw;
1270
 
} // plee::apply_throw()
1271
 
 
1272
 
/*----------------------------------------------------------------------------*/
1273
 
/**
1274
 
 * \brief Apply the action maintain.
1275
 
 *
1276
 
 */
1277
 
void ptb::plee::apply_maintain()
1278
 
{
1279
 
   if ( get_current_action_name() == "maintain_and_fall" )
1280
 
    m_right_move_force = 100000;
1281
 
  else
1282
 
    m_right_move_force = 200000;
1283
 
 
1284
 
  m_throw_time_ratio = 0;
1285
 
  set_state(plee::maintain_state);
1286
 
  m_progress = &plee::progress_maintain;
1287
 
} // plee::apply_maintain()
1288
 
 
1289
 
/*----------------------------------------------------------------------------*/
1290
 
/**
1291
 
 * \brief Throw an object.
1292
 
 *
1293
 
 */
1294
 
void ptb::plee::apply_throw_object()
1295
 
{
1296
 
  if ( m_throw_time_ratio == 0 )
1297
 
    m_throw_time_ratio = 1;
1298
 
 
1299
 
  if ( m_current_object == stone_object ) 
1300
 
    create_stone( get_stone_force() );
1301
 
  else if ( m_current_object == air_honeypot_object ) 
1302
 
    create_small_honeypot( get_stone_force() );
1303
 
  else if ( m_current_object == fire_honeypot_object ) 
1304
 
    create_small_honeypot( get_stone_force() );
1305
 
  else if ( m_current_object == water_honeypot_object ) 
1306
 
    create_small_honeypot( get_stone_force() );
1307
 
  else if (  m_current_object == azelnut_object )
1308
 
    create_azelnut();
1309
 
 
1310
 
  m_current_object = none_object;
1311
 
  if ( m_animation_to_throw != NULL )
1312
 
    {
1313
 
      delete m_animation_to_throw;
1314
 
      m_animation_to_throw = NULL;
1315
 
    }
1316
 
} // plee::apply_throw_object()
1317
 
 
1318
 
/*----------------------------------------------------------------------------*/
1319
 
/**
1320
 
 * \brief Apply the action blast_stone.
1321
 
 *
1322
 
 */
1323
 
void ptb::plee::apply_blast_stone()
1324
 
{
1325
 
  if ( ! m_air_stones.empty() )
1326
 
    {
1327
 
      std::set<ptb::stone*> save_stones(m_air_stones);
1328
 
      std::set<ptb::stone*>::iterator it;
1329
 
      for ( it = save_stones.begin(); it != save_stones.end(); ++it )
1330
 
        {
1331
 
          // the call can change the set m_air_stones
1332
 
          (*it)->inform_new_stone();
1333
 
        }
1334
 
    }
1335
 
} // plee::apply_blast_stone()
1336
 
 
1337
 
/*----------------------------------------------------------------------------*/
1338
 
/**
1339
 
 * \brief Apply the action wait. *
1340
 
 */
1341
 
void ptb::plee::apply_wait()
1342
 
{
1343
 
  set_state(plee::wait_state);
1344
 
  m_progress = &plee::progress_wait;
1345
 
} // plee::apply_wait()
1346
 
 
1347
 
/*----------------------------------------------------------------------------*/
1348
 
/**
1349
 
 * \brief Apply the action crouch.
1350
 
 *
1351
 
 */
1352
 
void ptb::plee::apply_crouch()
1353
 
{
1354
 
  m_right_move_force = 200000;
1355
 
  set_state(plee::crouch_state);
1356
 
  m_progress = &plee::progress_crouch;
1357
 
} // plee::apply_crouch()
1358
 
 
1359
 
/*----------------------------------------------------------------------------*/
1360
 
/**
1361
 
 * \brief Apply the action look_upward.
1362
 
 *
1363
 
 */
1364
 
void ptb::plee::apply_look_upward()
1365
 
{
1366
 
  m_right_move_force = 200000;
1367
 
  set_state(plee::look_upward_state);
1368
 
  m_progress = &plee::progress_look_upward;
1369
 
} // plee::apply_look_upward()
1370
 
 
1371
 
/*----------------------------------------------------------------------------*/
1372
 
/**
1373
 
 * \brief Die.
1374
 
 */
1375
 
void ptb::plee::apply_die()
1376
 
{
1377
 
  game_variables::set_lives_count
1378
 
    ( m_index, game_variables::get_lives_count(m_index) - 1);
1379
 
 
1380
 
  if ( game_variables::get_lives_count( m_index ) == 0 )
1381
 
    {
1382
 
      bear::engine::transition_effect_message<game_over_effect> msg;
1383
 
      get_level_globals().send_message
1384
 
        ( PTB_TRANSITION_EFFECT_DEFAULT_TARGET_NAME, msg );
1385
 
      start_action_model("game_over");
1386
 
      apply_game_over();
1387
 
    }
1388
 
  else
1389
 
    {
1390
 
      bear::engine::transition_effect_message<bear::engine::fade_effect> msg;
1391
 
      msg.get_effect().set_duration(0, 0.25, 0.75);
1392
 
      msg.get_effect().set_color( 1, 1, 1 );
1393
 
      get_level_globals().send_message
1394
 
        ( PTB_TRANSITION_EFFECT_DEFAULT_TARGET_NAME, msg );
1395
 
      set_state(dead_state);
1396
 
      m_progress = &plee::progress_dead;
1397
 
    }
1398
 
} // plee::apply_die()
1399
 
 
1400
 
/*----------------------------------------------------------------------------*/
1401
 
/**
1402
 
 * \brief Roar.
1403
 
 */
1404
 
void ptb::plee::apply_roar()
1405
 
{
1406
 
  set_state(roar_state);
1407
 
  m_progress = &plee::progress_roar;
1408
 
} // plee::apply_roar()
1409
 
 
1410
 
/*----------------------------------------------------------------------------*/
1411
 
/**
1412
 
 * \brief Start the state "game over".
1413
 
 */
1414
 
void ptb::plee::apply_game_over()
1415
 
{
1416
 
  m_right_move_force = 0;
1417
 
  set_state(game_over_state);
1418
 
  m_progress = &plee::progress_game_over;
1419
 
} // plee::apply_game_over()
1420
 
 
1421
 
/*----------------------------------------------------------------------------*/
1422
 
/**
1423
 
 * \brief Start to cling.
1424
 
 */
1425
 
void ptb::plee::apply_start_cling()
1426
 
{
1427
 
  set_state(start_cling_state);
1428
 
  m_progress = &plee::progress_start_cling;
1429
 
} // plee::apply_start_cling()
1430
 
 
1431
 
/*----------------------------------------------------------------------------*/
1432
 
/**
1433
 
 * \brief Plee cling.
1434
 
 */
1435
 
void ptb::plee::apply_cling()
1436
 
{
1437
 
  m_run_time = 0;
1438
 
  set_state(cling_state);
1439
 
  m_progress = &plee::progress_cling;
1440
 
} // plee::apply_cling()
1441
 
 
1442
 
/*----------------------------------------------------------------------------*/
1443
 
/**
1444
 
 * \brief Plee is clung and jump.
1445
 
 */
1446
 
void ptb::plee::apply_clung_jump()
1447
 
{
1448
 
  if ( get_rendering_attributes().is_mirrored() )
1449
 
    add_internal_force( bear::universe::force_type(5000000, 10000000) );
1450
 
  else
1451
 
    add_internal_force( bear::universe::force_type(-5000000, 10000000) );
1452
 
} // plee::apply_clung_jump()
1453
 
 
1454
 
/*----------------------------------------------------------------------------*/
1455
 
/**
1456
 
 * \brief Start to hang.
1457
 
 */
1458
 
void ptb::plee::apply_start_hang()
1459
 
{
1460
 
  set_state(start_hang_state);
1461
 
  m_progress = &plee::progress_start_hang;
1462
 
} // plee::apply_start_hang()
1463
 
 
1464
 
/*----------------------------------------------------------------------------*/
1465
 
/**
1466
 
 * \brief Plee hang.
1467
 
 */
1468
 
void ptb::plee::apply_hang()
1469
 
{
1470
 
  set_state(hang_state);
1471
 
  m_progress = &plee::progress_hang;
1472
 
} // plee::apply_hang()
1473
 
 
1474
 
/*----------------------------------------------------------------------------*/
1475
 
/**
1476
 
 * \brief Plee swim.
1477
 
 */
1478
 
void ptb::plee::apply_swimming()
1479
 
{
1480
 
  m_right_move_force = 150000;
1481
 
  set_state(swimming_state);
1482
 
  m_progress = &plee::progress_swimming;
1483
 
} // plee::apply_swimming()
1484
 
 
1485
 
/*----------------------------------------------------------------------------*/
1486
 
/**
1487
 
 * \brief Plee sink.
1488
 
 */
1489
 
void ptb::plee::apply_sink()
1490
 
{
1491
 
  m_right_move_force = 150000;
1492
 
  set_state(sink_state);
1493
 
  m_progress = &plee::progress_sink;
1494
 
} // plee::apply_swimming()
1495
 
 
1496
 
/*----------------------------------------------------------------------------*/
1497
 
/**
1498
 
 * \brief Apply the action swim_up.
1499
 
 *
1500
 
 */
1501
 
void ptb::plee::apply_swim_up()
1502
 
{
1503
 
  add_internal_force( bear::universe::force_type(0, 300000) );
1504
 
} // plee::apply_swim_up()
1505
 
 
1506
 
/*----------------------------------------------------------------------------*/
1507
 
/**
1508
 
 * \brief Apply the action swim_down.
1509
 
 *
1510
 
 */
1511
 
void ptb::plee::apply_swim_down()
1512
 
{
1513
 
  add_internal_force( bear::universe::force_type(0,-50000) );
1514
 
} // plee::apply_swim_down()
1515
 
 
1516
 
 
1517
 
/*----------------------------------------------------------------------------*/
1518
 
/**
1519
 
 * \brief Apply the action swim_down.
1520
 
 *
1521
 
 */
1522
 
void ptb::plee::apply_swim_jump()
1523
 
{
1524
 
  if ( get_rendering_attributes().is_mirrored() )
1525
 
    add_internal_force( bear::universe::force_type(-4000000, 7000000));
1526
 
  else
1527
 
    add_internal_force( bear::universe::force_type(4000000, 7000000));
1528
 
} // plee::apply_swim_down()
1529
 
 
1530
 
/*----------------------------------------------------------------------------*/
1531
 
/**
1532
 
 * \brief Apply the action float.
1533
 
 *
1534
 
 */
1535
 
void ptb::plee::apply_float()
1536
 
{
1537
 
  m_right_move_force = 150000;
1538
 
  set_state(float_state);
1539
 
  m_progress = &plee::progress_float;
1540
 
} // plee::apply_float()
1541
 
 
1542
 
/*----------------------------------------------------------------------------*/
1543
 
/**
1544
 
 * \brief Apply the action dive.
1545
 
 *
1546
 
 */
1547
 
void ptb::plee::apply_dive()
1548
 
{
1549
 
  add_internal_force( bear::universe::force_type(0, -200000));
1550
 
} // plee::apply_float()
1551
 
 
1552
 
/*----------------------------------------------------------------------------*/
1553
 
/**
1554
 
 * \brief Apply the action injured.
1555
 
 */
1556
 
void ptb::plee::apply_injured()
1557
 
{
1558
 
  m_right_move_force = 0;
1559
 
  m_nb_bottom_contact = 0;
1560
 
  set_state(plee::injured_state);
1561
 
  m_progress = &plee::progress_injured;
1562
 
} // plee::apply_injured()
1563
 
 
1564
 
/*----------------------------------------------------------------------------*/
1565
 
/**
1566
 
 * \brief Call a function.
1567
 
 * \param name The function to call.
1568
 
 */
1569
 
void ptb::plee::execute_function( const std::string& name )
1570
 
{
1571
 
  if ( name == "start_roar" )
1572
 
    apply_roar();
1573
 
  if ( name == "start_game_over" )
1574
 
    apply_game_over();
1575
 
  if ( name == "start_captive" )
1576
 
    apply_chain();
1577
 
  else if ( name == "start_crouch" )
1578
 
    apply_crouch();
1579
 
  else if ( name == "start_fall" )
1580
 
    apply_fall();
1581
 
  else if ( name == "start_float" )
1582
 
    apply_float();
1583
 
  else if ( name == "start_idle" )
1584
 
    apply_idle();
1585
 
  else if ( name == "start_jump" )
1586
 
    apply_jump();
1587
 
  else if ( name == "start_look_upward" )
1588
 
    apply_look_upward();
1589
 
  else if ( name == "start_run" )
1590
 
    apply_run();
1591
 
  else if ( name == "start_sink" )
1592
 
    apply_sink();
1593
 
  else if ( name == "start_slap" )
1594
 
    apply_slap();
1595
 
  else if ( name == "start_attack" )
1596
 
    apply_attack();
1597
 
  else if ( name == "start_start_cling" )
1598
 
    apply_start_cling();
1599
 
  else if ( name == "start_start_hang" )
1600
 
    apply_start_hang();
1601
 
  else if ( name == "start_cling" )
1602
 
    apply_cling();
1603
 
  else if ( name == "start_hang" )
1604
 
    apply_hang();
1605
 
  else if ( name == "start_clung_jump" )
1606
 
    apply_clung_jump();
1607
 
  else if ( name == "start_throw" )
1608
 
    apply_throw();
1609
 
  else if ( name == "start_maintain" )
1610
 
    apply_maintain();
1611
 
  else if ( name == "start_start_jump" )
1612
 
    apply_start_jump();
1613
 
  else if ( name == "start_swimming" )
1614
 
    apply_swimming();
1615
 
  else if ( name == "start_vertical_jump" )
1616
 
    apply_vertical_jump(); 
1617
 
  else if ( name == "wait" )
1618
 
    apply_wait();
1619
 
  else if ( name == "start_walk" )
1620
 
    apply_walk();
1621
 
  else if ( name == "throw" )
1622
 
    apply_throw_object();
1623
 
  else if ( name == "start_injured" )
1624
 
    apply_injured();
1625
 
  else 
1626
 
    super::execute_function(name);
1627
 
} // plee::execute_function()
1628
 
 
1629
 
/*----------------------------------------------------------------------------*/
1630
 
/**
1631
 
 * \brief  Inform the item that he have no energy now.
1632
 
 * \param attacker The attacker monster.
1633
 
 */
1634
 
void ptb::plee::inform_no_energy(const monster& attacker)
1635
 
{
1636
 
  apply_die();
1637
 
} // plee::inform_no_energy()
1638
 
 
1639
 
/*----------------------------------------------------------------------------*/
1640
 
/**
1641
 
 * \brief The monster is injured.
1642
 
 * \param attacker The monster attacking me.
1643
 
 */
1644
 
void ptb::plee::injure
1645
 
(const monster& attacker, const bear::universe::collision_info& info)
1646
 
{
1647
 
  double orientation = -1;
1648
 
 
1649
 
  if ( ( info.get_collision_side() == 
1650
 
         bear::universe::zone::middle_right_zone ) || 
1651
 
       ( info.get_collision_side() == 
1652
 
         bear::universe::zone::top_right_zone ) || 
1653
 
       ( info.get_collision_side() == 
1654
 
         bear::universe::zone::bottom_right_zone ) )
1655
 
    orientation = 1;
1656
 
    
1657
 
  set_speed(bear::universe::speed_type(0,0));
1658
 
  add_external_force
1659
 
    ( bear::universe::force_type(orientation * 4000000, 5500000) );
1660
 
 
1661
 
  super::injure(attacker,info);
1662
 
 
1663
 
  m_states[m_current_state]->do_injured();
1664
 
} // ptb::plee::injure()
1665
 
 
1666
 
/*----------------------------------------------------------------------------*/
1667
 
/**
1668
 
 * \brief The monster isn't injure any more.
1669
 
 */
1670
 
void ptb::plee::finish_injure()
1671
 
{
1672
 
  super::finish_injure();
1673
 
 
1674
 
  m_states[m_current_state]->do_finish_injured();
1675
 
} // ptb::monster_item::finish_injure()
1676
 
 
1677
 
/*----------------------------------------------------------------------------*/
1678
 
/**
1679
 
 * \brief Get a given offensive coefficient.
1680
 
 * param index The index of the attack.
1681
 
 * param other The other monster.
1682
 
 * param info Information on collision.
1683
 
 */
1684
 
unsigned int ptb::plee::get_offensive_coefficient
1685
 
( unsigned int index,
1686
 
  const monster& other,
1687
 
  const bear::universe::collision_info& info ) const
1688
 
{
1689
 
  unsigned int result = super::get_offensive_coefficient(index,other,info);
1690
 
  
1691
 
  const base_item* item = dynamic_cast<const base_item*>(&other);
1692
 
  
1693
 
  if ( ( item != NULL ) && ( result != 0 ) )
1694
 
    {
1695
 
      if ( get_rendering_attributes().is_mirrored() )
1696
 
        {
1697
 
          if ( item->get_left() >= get_left() )
1698
 
            result = 0;
1699
 
        }
1700
 
      else if ( item->get_right() <= get_right() )
1701
 
        result = 0;
1702
 
    }
1703
 
  
1704
 
  return result;
1705
 
} // plee::get_offensive_coefficient()
1706
 
 
1707
 
/*----------------------------------------------------------------------------*/
1708
 
/**
1709
 
 * \brief Give a string representation of the item.
1710
 
 * \param str (out) The result of the convertion.
1711
 
 */
1712
 
void ptb::plee::to_string( std::string& str ) const
1713
 
{
1714
 
  std::ostringstream oss;
1715
 
 
1716
 
  super::to_string(str);
1717
 
 
1718
 
  oss << "oxygen_gauge: ";
1719
 
  if ( m_gauges[oxygen_gauge]->is_activated() )
1720
 
    oss << "active : ";
1721
 
  else
1722
 
    oss << "not active : ";
1723
 
  oss << m_gauges[oxygen_gauge]->get_value() << "/"
1724
 
      << m_gauges[oxygen_gauge]->get_max_value() << "\n";
1725
 
 
1726
 
  oss << "fire_gauge: ";
1727
 
  if ( m_gauges[fire_gauge]->is_activated() )
1728
 
    oss << "active : ";
1729
 
  else
1730
 
    oss << "not active : ";
1731
 
  oss << m_gauges[fire_gauge]->get_value() << "/"
1732
 
      << m_gauges[fire_gauge]->get_max_value() << "\n";
1733
 
 
1734
 
  oss << "ice_gauge: ";
1735
 
  if ( m_gauges[ice_gauge]->is_activated() )
1736
 
    oss << "active : ";
1737
 
  else
1738
 
    oss << "not active : ";
1739
 
  oss << m_gauges[ice_gauge]->get_value() << "/"
1740
 
      << m_gauges[ice_gauge]->get_max_value() << "\n";
1741
 
 
1742
 
  oss << "state: ";
1743
 
  oss << m_states[m_current_state]->get_name();
1744
 
  oss << "\n";
1745
 
  oss << "action: ";
1746
 
  oss << get_current_action_name();
1747
 
  oss << "\n";
1748
 
  oss << "can_cling: " << m_can_cling << "\n";
1749
 
  oss << "status_look_upward: " << m_status_look_upward << "\n";
1750
 
  oss << "status_crouch: " << m_status_crouch << "\n";
1751
 
  oss << "powers: " << " : ";
1752
 
  if ( game_variables::get_air_power(m_index) )
1753
 
    oss << "air  ";
1754
 
  if ( game_variables::get_fire_power(m_index) )
1755
 
    oss << "fire  ";
1756
 
  if ( game_variables::get_water_power(m_index) )
1757
 
    oss << "water  ";
1758
 
  oss << "\n";
1759
 
  oss << "air_float: ";
1760
 
  if ( m_air_float )
1761
 
    oss << "y";
1762
 
  else
1763
 
    oss << "n"; 
1764
 
  oss << " : " << m_air_float_time;
1765
 
  oss << "\n";
1766
 
 
1767
 
  str += oss.str();
1768
 
} // plee::to_string()
1769
 
 
1770
 
/*---------------------------------------------------------------------------*/
1771
 
/**
1772
 
 * \brief Do one iteration in the state .
1773
 
 * \param elapsed_time Elapsed time since the last call.
1774
 
 */
1775
 
void ptb::plee::progress_walk( bear::universe::time_type elapsed_time )
1776
 
{
1777
 
  brake();
1778
 
 
1779
 
  if ( has_bottom_contact() )
1780
 
    {
1781
 
      if ( m_last_bottom_left == get_bottom_left() )
1782
 
        start_action_model("idle");
1783
 
      else
1784
 
        {
1785
 
          bear::universe::speed_type speed( get_speed() );
1786
 
          // calculate the speed in the intern axis
1787
 
          bear::universe::coordinate_type speed_x =
1788
 
            speed.dot_product(get_x_axis());
1789
 
 
1790
 
          if( std::abs(speed_x) >= s_speed_to_run )
1791
 
            {
1792
 
              if ( m_run_time >= s_time_to_run ) 
1793
 
                start_action_model("run");
1794
 
            }
1795
 
          else if ( speed_x == 0 )
1796
 
            start_action_model("idle");
1797
 
          else
1798
 
            m_right_move_force = 
1799
 
              50000 + std::min(m_run_time,s_time_to_run)*(300000-50000) 
1800
 
              / s_time_to_run;
1801
 
        }
1802
 
    }
1803
 
  else
1804
 
    test_in_sky_or_swimm();
1805
 
} // plee::progress_walk()
1806
 
 
1807
 
/*---------------------------------------------------------------------------*/
1808
 
/**
1809
 
 * \brief Do one iteration in the state .
1810
 
 * \param elapsed_time Elapsed time since the last call.
1811
 
 */
1812
 
void ptb::plee::progress_idle( bear::universe::time_type elapsed_time )
1813
 
{
1814
 
  brake();
1815
 
 
1816
 
  if ( has_bottom_contact() )
1817
 
    {
1818
 
      m_run_time = 0;
1819
 
  
1820
 
      if ( m_state_time >= s_time_to_wait )
1821
 
        {
1822
 
          std::ostringstream s;
1823
 
          s << "wait" << (rand() % 3 + 1);
1824
 
          start_action_model(s.str());
1825
 
        }
1826
 
    }
1827
 
  else
1828
 
    test_in_sky_or_swimm();
1829
 
} // plee::progress_idle()
1830
 
 
1831
 
/*---------------------------------------------------------------------------*/
1832
 
/**
1833
 
 * \brief Do one iteration in the state .
1834
 
 * \param elapsed_time Elapsed time since the last call.
1835
 
 */
1836
 
void ptb::plee::progress_jump( bear::universe::time_type elapsed_time )
1837
 
{
1838
 
  if ( !test_bottom_contact() )
1839
 
    {
1840
 
      if ( is_only_in_environment(bear::universe::water_environment) )
1841
 
        {
1842
 
          if( get_speed().y <= 0 )
1843
 
            start_action_model("sink");
1844
 
          else
1845
 
            start_action_model("swimming");
1846
 
        }
1847
 
      else if ( is_in_floating() )
1848
 
        start_action_model("float");
1849
 
      else if( get_speed().y <= 0 )
1850
 
        start_action_model("fall");
1851
 
    }
1852
 
} // plee::progress_jump()
1853
 
 
1854
 
/*---------------------------------------------------------------------------*/
1855
 
/**
1856
 
 * \brief Do one iteration in the state .
1857
 
 * \param elapsed_time Elapsed time since the last call.
1858
 
 */
1859
 
void ptb::plee::progress_fall( bear::universe::time_type elapsed_time )
1860
 
{
1861
 
  if ( !test_bottom_contact() )
1862
 
    {
1863
 
      if ( is_only_in_environment(bear::universe::water_environment) )
1864
 
        if( get_speed().y <= 0 )
1865
 
          start_action_model("sink");
1866
 
        else
1867
 
          start_action_model("swimming");
1868
 
      else if ( is_in_floating() )
1869
 
        start_action_model("float");
1870
 
      if( get_speed().y > 0 )
1871
 
        start_action_model("jump");
1872
 
    }
1873
 
} // plee::progress_fall()
1874
 
 
1875
 
/*---------------------------------------------------------------------------*/
1876
 
/**
1877
 
 * \brief Do one iteration in the state .
1878
 
 * \param elapsed_time Elapsed time since the last call.
1879
 
 */
1880
 
void ptb::plee::progress_dead( bear::universe::time_type elapsed_time )
1881
 
{
1882
 
  regenerate();
1883
 
 
1884
 
  start_action_model("roar");
1885
 
} // plee::progress_dead()
1886
 
 
1887
 
 
1888
 
/*---------------------------------------------------------------------------*/
1889
 
/**
1890
 
 * \brief Do one iteration in the state .
1891
 
 * \param elapsed_time Elapsed time since the last call.
1892
 
 */
1893
 
void ptb::plee::progress_game_over( bear::universe::time_type elapsed_time )
1894
 
{
1895
 
  set_status_look_upward(false);
1896
 
  set_status_crouch(false);
1897
 
} // plee::progress_game_over()
1898
 
 
1899
 
/*---------------------------------------------------------------------------*/
1900
 
/**
1901
 
 * \brief Do one iteration in the state .
1902
 
 * \param elapsed_time Elapsed time since the last call.
1903
 
 */
1904
 
void ptb::plee::progress_roar( bear::universe::time_type elapsed_time )
1905
 
{
1906
 
  // do_nothing
1907
 
} // plee::progress_roar()
1908
 
 
1909
 
/*---------------------------------------------------------------------------*/
1910
 
/**
1911
 
 * \brief Do one iteration in the state .
1912
 
 * \param elapsed_time Elapsed time since the last call.
1913
 
 */
1914
 
void ptb::plee::progress_run( bear::universe::time_type elapsed_time )
1915
 
{
1916
 
  if ( has_bottom_contact() )
1917
 
    {
1918
 
      bear::universe::speed_type speed;
1919
 
      speed = get_speed();
1920
 
 
1921
 
      // calculate the speed in the intern axis
1922
 
      bear::universe::coordinate_type speed_x =
1923
 
        speed.dot_product(get_x_axis());
1924
 
 
1925
 
      if( std::abs(speed_x) < s_speed_to_run )
1926
 
        {
1927
 
          if( speed_x == 0 )
1928
 
            start_action_model("idle");
1929
 
          else
1930
 
            start_action_model("walk");
1931
 
        }
1932
 
    }
1933
 
  else
1934
 
    test_in_sky_or_swimm();
1935
 
} // plee::progress_run()
1936
 
 
1937
 
/*---------------------------------------------------------------------------*/
1938
 
/**
1939
 
 * \brief Do one iteration in the state .
1940
 
 * \param elapsed_time Elapsed time since the last call.
1941
 
 */
1942
 
void ptb::plee::progress_slap( bear::universe::time_type elapsed_time )
1943
 
{
1944
 
  brake();
1945
 
 
1946
 
  bear::universe::speed_type speed(get_speed());
1947
 
  bear::universe::coordinate_type speed_x = speed.dot_product(get_x_axis());
1948
 
  
1949
 
  if ( get_current_action_name() == "slap" )
1950
 
    {
1951
 
      if ( std::abs(speed_x) != 0 )
1952
 
        switch_to_model_action("slap_and_walk");
1953
 
    }
1954
 
  else if ( get_current_action_name() == "slap_and_walk") 
1955
 
    {
1956
 
      if( std::abs(speed_x) == 0 )
1957
 
        switch_to_model_action("slap");
1958
 
    }
1959
 
 
1960
 
  if ( has_right_contact() ) 
1961
 
    apply_move_right();
1962
 
  else if ( has_left_contact() ) 
1963
 
    apply_move_left();
1964
 
} // plee::progress_slap()
1965
 
 
1966
 
/*---------------------------------------------------------------------------*/
1967
 
/**
1968
 
 * \brief Do one iteration in the state .
1969
 
 * \param elapsed_time Elapsed time since the last call.
1970
 
 */
1971
 
void ptb::plee::progress_start_jump( bear::universe::time_type elapsed_time )
1972
 
{
1973
 
  m_halo_animation->next(elapsed_time);
1974
 
 
1975
 
  brake();
1976
 
 
1977
 
  if ( ! has_bottom_contact() )
1978
 
    test_in_sky_or_swimm();
1979
 
} // plee::progress_start_jump()
1980
 
 
1981
 
/*---------------------------------------------------------------------------*/
1982
 
/**
1983
 
 * \brief Do one iteration in the state .
1984
 
 * \param elapsed_time Elapsed time since the last call.
1985
 
 */
1986
 
void ptb::plee::progress_vertical_jump
1987
 
( bear::universe::time_type elapsed_time )
1988
 
{
1989
 
  if ( !test_bottom_contact() )
1990
 
    if( get_speed().y <= 0 )
1991
 
      start_action_model("fall");
1992
 
} // plee::progress_vertical_jump()
1993
 
 
1994
 
/*---------------------------------------------------------------------------*/
1995
 
/**
1996
 
 * \brief Do one iteration in the state .
1997
 
 * \param elapsed_time Elapsed time since the last call.
1998
 
 */
1999
 
void ptb::plee::progress_crouch( bear::universe::time_type elapsed_time )
2000
 
{
2001
 
  brake();
2002
 
 
2003
 
  if ( ! has_bottom_contact() )
2004
 
    test_in_sky_or_swimm();
2005
 
} // plee::progress_crouch()
2006
 
 
2007
 
/*---------------------------------------------------------------------------*/
2008
 
/**
2009
 
 * \brief Do one iteration in the state .
2010
 
 * \param elapsed_time Elapsed time since the last call.
2011
 
 */
2012
 
void ptb::plee::progress_look_upward( bear::universe::time_type elapsed_time )
2013
 
{
2014
 
  brake();
2015
 
 
2016
 
  if ( ! has_bottom_contact() )
2017
 
    test_in_sky_or_swimm();
2018
 
} // plee::progress_look_upward()
2019
 
 
2020
 
/*---------------------------------------------------------------------------*/
2021
 
/**
2022
 
 * \brief Do one iteration in the state .
2023
 
 * \param elapsed_time Elapsed time since the last call.
2024
 
 */
2025
 
void ptb::plee::progress_captive( bear::universe::time_type elapsed_time )
2026
 
{
2027
 
  // do nothing
2028
 
} // plee::progress_captive()
2029
 
 
2030
 
/*---------------------------------------------------------------------------*/
2031
 
/**
2032
 
 * \brief Do one iteration in the state .
2033
 
 * \param elapsed_time Elapsed time since the last call.
2034
 
 */
2035
 
void ptb::plee::progress_throw( bear::universe::time_type elapsed_time )
2036
 
{
2037
 
  brake();
2038
 
 
2039
 
  bear::universe::speed_type speed(get_speed());
2040
 
  bear::universe::coordinate_type speed_x = speed.dot_product(get_x_axis());
2041
 
  
2042
 
  if ( get_current_action_name() == "throw" )
2043
 
    {
2044
 
      if ( ! has_bottom_contact() )
2045
 
        switch_to_model_action("throw_and_fall");
2046
 
      else if( std::abs(speed_x) != 0 )
2047
 
        switch_to_model_action("throw_and_walk");
2048
 
    }
2049
 
  else if ( get_current_action_name() == "throw_and_walk") 
2050
 
    {
2051
 
      if ( ! has_bottom_contact() )
2052
 
        switch_to_model_action("throw_and_fall");
2053
 
      else if( std::abs(speed_x) == 0 )
2054
 
        switch_to_model_action("throw");
2055
 
    }
2056
 
  else if ( get_current_action_name() == "throw_and_fall") 
2057
 
    {
2058
 
      if ( has_bottom_contact() )
2059
 
        {
2060
 
          if( std::abs(speed_x) == 0 )
2061
 
            switch_to_model_action("throw");
2062
 
          else 
2063
 
            switch_to_model_action("throw_and_walk");
2064
 
        }
2065
 
    }
2066
 
 
2067
 
  if ( ( m_current_object == air_honeypot_object ) && 
2068
 
       ! m_can_throw_power[monster::air_attack] )
2069
 
    {
2070
 
      game_variables::set_air_power(m_index, true);      
2071
 
      start_action_model("idle");
2072
 
    }
2073
 
  if ( ( m_current_object == fire_honeypot_object ) && 
2074
 
       ! m_can_throw_power[monster::fire_attack] )
2075
 
    {
2076
 
      game_variables::set_fire_power(m_index, true); 
2077
 
      start_action_model("idle");
2078
 
    }
2079
 
  if ( ( m_current_object == water_honeypot_object ) && 
2080
 
       ! m_can_throw_power[monster::water_attack] )
2081
 
    {
2082
 
      game_variables::set_water_power(m_index, true); 
2083
 
      start_action_model("idle");
2084
 
    }
2085
 
} // plee::progress_throw()
2086
 
 
2087
 
/*---------------------------------------------------------------------------*/
2088
 
/**
2089
 
 * \brief Do one iteration in the state .
2090
 
 * \param elapsed_time Elapsed time since the last call.
2091
 
 */
2092
 
void ptb::plee::progress_maintain( bear::universe::time_type elapsed_time )
2093
 
{
2094
 
  brake();
2095
 
 
2096
 
  bear::universe::speed_type speed(get_speed());
2097
 
  bear::universe::coordinate_type speed_x = speed.dot_product(get_x_axis());
2098
 
  
2099
 
  if ( get_current_action_name() == "maintain" )
2100
 
    {
2101
 
      if ( ! has_bottom_contact() )
2102
 
        switch_to_model_action("maintain_and_fall");
2103
 
      else if( std::abs(speed_x) != 0 )
2104
 
        switch_to_model_action("maintain_and_walk");
2105
 
    }
2106
 
  else if ( get_current_action_name() == "maintain_and_walk") 
2107
 
    {
2108
 
      if ( ! has_bottom_contact() )
2109
 
        switch_to_model_action("maintain_and_fall");
2110
 
      else if( std::abs(speed_x) == 0 )
2111
 
        switch_to_model_action("maintain");
2112
 
    }
2113
 
  else if ( get_current_action_name() == "maintain_and_fall") 
2114
 
    {
2115
 
      if ( has_bottom_contact() )
2116
 
        {
2117
 
          if( std::abs(speed_x) == 0 )
2118
 
            switch_to_model_action("maintain");
2119
 
          else 
2120
 
            switch_to_model_action("maintain_and_walk");
2121
 
        }
2122
 
    }
2123
 
} // plee::progress_maintain()
2124
 
 
2125
 
/*---------------------------------------------------------------------------*/
2126
 
/**
2127
 
 * \brief Do one iteration in the state .
2128
 
 * \param elapsed_time Elapsed time since the last call.
2129
 
 */
2130
 
void ptb::plee::progress_wait( bear::universe::time_type elapsed_time )
2131
 
{
2132
 
  brake();
2133
 
 
2134
 
  if ( ! has_bottom_contact() )
2135
 
    test_in_sky_or_swimm();
2136
 
} // plee::progress_wait()
2137
 
 
2138
 
/*---------------------------------------------------------------------------*/
2139
 
/**
2140
 
 * \brief Do one iteration in the state .
2141
 
 * \param elapsed_time Elapsed time since the last call.
2142
 
 */
2143
 
void ptb::plee::progress_start_cling
2144
 
( bear::universe::time_type elapsed_time )
2145
 
{
2146
 
  if ( !test_bottom_contact() )
2147
 
    {
2148
 
      if ( ( !get_rendering_attributes().is_mirrored() 
2149
 
            && has_right_contact() ) ||
2150
 
           ( get_rendering_attributes().is_mirrored() && has_left_contact() ) )
2151
 
        {
2152
 
          // test if the wall can be clung
2153
 
          if ( m_can_cling )
2154
 
            start_action_model("cling");
2155
 
          else
2156
 
            start_action_model("idle");
2157
 
        }
2158
 
    }
2159
 
} // plee::progress_start_cling()
2160
 
 
2161
 
/*---------------------------------------------------------------------------*/
2162
 
/**
2163
 
 * \brief Do one iteration in the state .
2164
 
 * \param elapsed_time Elapsed time since the last call.
2165
 
 */
2166
 
void ptb::plee::progress_cling( bear::universe::time_type elapsed_time )
2167
 
{
2168
 
  if ( ! test_bottom_contact() )
2169
 
    {
2170
 
      if ( has_top_contact() || ( ! m_can_cling  ) )
2171
 
        start_action_model("fall");
2172
 
      else
2173
 
        {
2174
 
          bear::universe::speed_type speed = get_speed();
2175
 
          speed.x = 0;
2176
 
          if ( speed.y > 0 )
2177
 
            speed.y = 0;
2178
 
          else
2179
 
            speed.y *= 0.9;
2180
 
          
2181
 
          set_speed(speed);
2182
 
 
2183
 
          
2184
 
          bear::universe::force_type force
2185
 
            ( - get_mass() * get_owner().get_gravity() );
2186
 
  
2187
 
          if ( (get_density() != 0) &&
2188
 
           ( get_mass() != std::numeric_limits<double>::infinity() )  )
2189
 
            force += get_owner().get_gravity() * get_mass() *
2190
 
              get_owner().get_average_density(get_bounding_box()) / 
2191
 
              get_density();
2192
 
 
2193
 
          add_external_force(force);
2194
 
        }
2195
 
    }
2196
 
} // plee::progress_cling()
2197
 
 
2198
 
/*---------------------------------------------------------------------------*/
2199
 
/**
2200
 
 * \brief Do one iteration in the state .
2201
 
 * \param elapsed_time Elapsed time since the last call.
2202
 
 */
2203
 
void ptb::plee::progress_clung_jump
2204
 
( bear::universe::time_type elapsed_time )
2205
 
{
2206
 
  if ( !test_bottom_contact() )
2207
 
    if( get_speed().y <= 0 )
2208
 
      start_action_model("fall");
2209
 
} // plee::progress_clung_jump()
2210
 
 
2211
 
/*---------------------------------------------------------------------------*/
2212
 
/**
2213
 
 * \brief Do one iteration in the state .
2214
 
 * \param elapsed_time Elapsed time since the last call.
2215
 
 */
2216
 
void ptb::plee::progress_start_hang
2217
 
( bear::universe::time_type elapsed_time )
2218
 
{
2219
 
  if ( !test_bottom_contact() )
2220
 
    {
2221
 
      if ( ( !get_rendering_attributes().is_mirrored() && 
2222
 
             has_right_contact() ) ||
2223
 
           ( get_rendering_attributes().is_mirrored() && has_left_contact() ) )
2224
 
        start_action_model("hang");
2225
 
      else
2226
 
        if ( m_state_time >= s_max_time_to_hang )
2227
 
          start_action_model("idle");
2228
 
    }
2229
 
} // plee::progress_start_hang()
2230
 
 
2231
 
/*---------------------------------------------------------------------------*/
2232
 
/**
2233
 
 * \brief Do one iteration in the state .
2234
 
 * \param elapsed_time Elapsed time since the last call.
2235
 
 */
2236
 
void ptb::plee::progress_hang( bear::universe::time_type elapsed_time )
2237
 
{
2238
 
  if ( ! test_bottom_contact() )
2239
 
    {
2240
 
      if ( has_top_contact() )
2241
 
        start_action_model("fall");
2242
 
      else
2243
 
        add_external_force(- get_mass() * get_owner().get_gravity());
2244
 
    }
2245
 
} // plee::progress_hang()
2246
 
 
2247
 
/*---------------------------------------------------------------------------*/
2248
 
/**
2249
 
 * \brief Do one iteration in the state .
2250
 
 * \param elapsed_time Elapsed time since the last call.
2251
 
 */
2252
 
void ptb::plee::progress_swimming( bear::universe::time_type elapsed_time )
2253
 
{
2254
 
  if ( !test_bottom_contact() )
2255
 
    {
2256
 
      if ( is_only_in_environment(bear::universe::water_environment) )
2257
 
        {
2258
 
          if( get_speed().y <= 0 )
2259
 
            start_action_model("sink");
2260
 
        }
2261
 
      else if ( is_in_floating() )
2262
 
        start_action_model("float");
2263
 
      else if( get_speed().y <= 0 )
2264
 
        start_action_model("fall");
2265
 
      else
2266
 
        start_action_model("jump");
2267
 
    }
2268
 
} // plee::progress_swimming()
2269
 
 
2270
 
/*---------------------------------------------------------------------------*/
2271
 
/**
2272
 
 * \brief Do one iteration in the state .
2273
 
 * \param elapsed_time Elapsed time since the last call.
2274
 
 */
2275
 
void ptb::plee::progress_sink( bear::universe::time_type elapsed_time )
2276
 
{
2277
 
  if ( !test_bottom_contact() )
2278
 
    {
2279
 
      if ( is_only_in_environment(bear::universe::water_environment) )
2280
 
        {
2281
 
          if( get_speed().y > 0 )
2282
 
            start_action_model("swimming");
2283
 
        }
2284
 
      else if ( is_in_floating() )
2285
 
        start_action_model("float");
2286
 
      else if( get_speed().y > 0 )
2287
 
        start_action_model("jump");
2288
 
      else
2289
 
        start_action_model("fall");
2290
 
    }
2291
 
} // plee::progress_sink()
2292
 
 
2293
 
/*---------------------------------------------------------------------------*/
2294
 
/**
2295
 
 * \brief Do one iteration in the state .
2296
 
 * \param elapsed_time Elapsed time since the last call.
2297
 
 */
2298
 
void ptb::plee::progress_float( bear::universe::time_type elapsed_time )
2299
 
{
2300
 
  if ( !test_bottom_contact() )
2301
 
    {
2302
 
      if ( is_only_in_environment(bear::universe::water_environment) )
2303
 
        {
2304
 
          if( get_speed().y > 0 )
2305
 
            start_action_model("swimming");
2306
 
          else
2307
 
            start_action_model("sink");
2308
 
        }
2309
 
      else if ( ! is_in_floating() )
2310
 
        {
2311
 
          if( get_speed().y > 0 )
2312
 
            start_action_model("jump");
2313
 
          else
2314
 
            start_action_model("fall");
2315
 
        }
2316
 
    }
2317
 
} // plee::progress_float()
2318
 
 
2319
 
/*---------------------------------------------------------------------------*/
2320
 
/**
2321
 
 * \brief Do one iteration in the state .
2322
 
 * \param elapsed_time Elapsed time since the last call.
2323
 
 */
2324
 
void ptb::plee::progress_injured( bear::universe::time_type elapsed_time )
2325
 
{
2326
 
  brake();
2327
 
 
2328
 
  if ( has_bottom_contact() )
2329
 
    {
2330
 
      m_nb_bottom_contact++;
2331
 
 
2332
 
      if ( m_nb_bottom_contact > 2 ) 
2333
 
        {
2334
 
          if ( m_last_bottom_left == get_bottom_left() )
2335
 
            start_action_model("idle");
2336
 
          else
2337
 
            {
2338
 
              bear::universe::speed_type speed( get_speed() );
2339
 
              // calculate the speed in the intern axis
2340
 
              bear::universe::coordinate_type speed_x =
2341
 
                speed.dot_product(get_x_axis());
2342
 
              
2343
 
              if( std::abs(speed_x) >= s_speed_to_run )
2344
 
                start_action_model("run");
2345
 
              else if ( speed_x == 0 )
2346
 
                start_action_model("idle");
2347
 
              else 
2348
 
                start_action_model("walk");
2349
 
            }
2350
 
        }
2351
 
    }
2352
 
} // plee::progress_injured()
2353
 
 
2354
 
/*----------------------------------------------------------------------------*/
2355
 
/**
2356
 
 * \brief Set the state of Plee.
2357
 
 */
2358
 
void ptb::plee::set_state(plee_state_name state)
2359
 
{
2360
 
  if ( state != m_current_state )
2361
 
    {
2362
 
      m_states[m_current_state]->stop();
2363
 
      m_current_state = state;
2364
 
      m_states[m_current_state]->start();
2365
 
      m_state_time = 0;
2366
 
    }
2367
 
} // plee::set_state()
2368
 
 
2369
 
/*----------------------------------------------------------------------------*/
2370
 
/**
2371
 
 * \brief Test if Plee is crushed.
2372
 
 */
2373
 
bool ptb::plee::is_crushed() const
2374
 
{
2375
 
  return ( ( has_bottom_contact() && has_top_contact() ) ||
2376
 
           ( has_right_contact() && has_left_contact() ) );
2377
 
     // &&   has_contact_after_collision() );
2378
 
} // plee::is_crushed()
2379
 
 
2380
 
/*----------------------------------------------------------------------------*/
2381
 
/**
2382
 
 * \brief Spawn the plee after his death.
2383
 
 * \todo Game over if the plee has no more lifes.
2384
 
 * \todo Update lifes and any other counters.
2385
 
 */
2386
 
void ptb::plee::regenerate()
2387
 
{
2388
 
  set_center_of_mass( m_saved_position );
2389
 
  set_speed( bear::universe::speed_type(0, 0) );
2390
 
  set_internal_force(bear::universe::force_type(0, 0));
2391
 
  set_external_force(bear::universe::force_type(0, 0));
2392
 
  m_energy = game_variables::get_max_energy(m_index);
2393
 
  m_invincible_time = 0;
2394
 
  set_invincible(false);
2395
 
  m_last_visual_time = 0;
2396
 
  m_last_visuals.clear();
2397
 
  m_run_time = 0;
2398
 
  m_can_cling = false;
2399
 
  m_air_float = false;
2400
 
  finish_injure();
2401
 
  game_variables::set_air_power(m_index,false);
2402
 
  game_variables::set_fire_power(m_index,false);
2403
 
  game_variables::set_water_power(m_index,false);
2404
 
  update_powers();
2405
 
  m_gauges[oxygen_gauge]->set_value(s_max_oxygen);
2406
 
  m_gauges[fire_gauge]->set_value(s_max_fire_gauge);
2407
 
  m_gauges[ice_gauge]->set_value(s_max_ice_gauge);
2408
 
  m_air_stones.clear();
2409
 
  m_move_right = false;
2410
 
  m_move_left = false;
2411
 
  m_last_bottom_left = bear::universe::position_type(0,0);
2412
 
  get_rendering_attributes().mirror(false);
2413
 
  stop_to_speak();
2414
 
  if ( m_animation_to_throw ) 
2415
 
    {
2416
 
      delete m_animation_to_throw;
2417
 
      m_animation_to_throw = NULL;
2418
 
    }
2419
 
  remove_all_links();
2420
 
} // plee::regenerate()
2421
 
 
2422
 
/*----------------------------------------------------------------------------*/
2423
 
/**
2424
 
 * \brief Indicates if Plee has a power.
2425
 
 */
2426
 
bool ptb::plee::has_a_power() const
2427
 
{
2428
 
  return game_variables::get_air_power(m_index) ||
2429
 
    game_variables::get_fire_power(m_index) ||
2430
 
    game_variables::get_water_power(m_index);
2431
 
} // plee::has_power()
2432
 
 
2433
 
/*----------------------------------------------------------------------------*/
2434
 
/**
2435
 
 * \brief Indicates if Plee is in the water and in the air.
2436
 
 *
2437
 
 */
2438
 
bool ptb::plee::is_in_floating() const
2439
 
{
2440
 
  bool result = false;
2441
 
 
2442
 
  if ( has_owner() )
2443
 
    {
2444
 
      std::set<bear::universe::environment_type> environments;
2445
 
      get_owner().get_environments(get_bounding_box(), environments);
2446
 
      result =
2447
 
        (environments.find(bear::universe::water_environment) !=
2448
 
         environments.end()) &&
2449
 
        ( environments.size() >= 1 );
2450
 
    }
2451
 
 
2452
 
  return result;
2453
 
} // plee::is_only_in_floatting()
2454
 
 
2455
 
/*----------------------------------------------------------------------------*/
2456
 
/**
2457
 
 * \brief Update the orientation.
2458
 
 */
2459
 
void ptb::plee::update_orientation()
2460
 
{
2461
 
  if ( get_speed().x < 0 )
2462
 
    {
2463
 
      if ( get_current_action_name()!= "injured" ) 
2464
 
        get_rendering_attributes().mirror(true);
2465
 
      else        
2466
 
        get_rendering_attributes().mirror(false);
2467
 
    }
2468
 
  else if ( get_speed().x > 0 )
2469
 
    {
2470
 
      if ( get_current_action_name()!= "injured" )
2471
 
        get_rendering_attributes().mirror(false);
2472
 
      else
2473
 
        get_rendering_attributes().mirror(true);
2474
 
    }
2475
 
} // plee::update_orientation()
2476
 
 
2477
 
/*----------------------------------------------------------------------------*/
2478
 
/**
2479
 
 * \brief Update the offensive and defensive parameters according to
2480
 
 * a power.
2481
 
 * \param p The power status.
2482
 
 * \param a The corresponding attack
2483
 
 */
2484
 
void ptb::plee::update_power( bool b, monster::attack_type a)
2485
 
{
2486
 
  if ( b )
2487
 
    {
2488
 
      m_defensive_powers[a] = true;
2489
 
      m_offensive_coefficients[a] = 1;
2490
 
    }
2491
 
  else
2492
 
    {
2493
 
      m_defensive_powers[a] = false;
2494
 
      m_offensive_coefficients[a] = 0;
2495
 
    }
2496
 
} // plee::update_power()
2497
 
 
2498
 
/*----------------------------------------------------------------------------*/
2499
 
/**
2500
 
 * \brief Update the offensive and defensive parameters according to
2501
 
 * the powers.
2502
 
 */
2503
 
void ptb::plee::update_powers()
2504
 
{
2505
 
  update_power(game_variables::get_air_power(m_index),monster::air_attack);
2506
 
  update_power(game_variables::get_fire_power(m_index),monster::fire_attack);
2507
 
  update_power(game_variables::get_water_power(m_index),monster::water_attack);
2508
 
 
2509
 
  if ( has_a_power() && ( m_halo_hand_animation != NULL ) )
2510
 
    {
2511
 
      if ( game_variables::get_air_power(m_index) )
2512
 
        if ( game_variables::get_fire_power(m_index) )
2513
 
          if ( game_variables::get_water_power(m_index) )
2514
 
            m_halo_hand_animation->set_intensity(0.5, 0.5, 0.5);
2515
 
          else
2516
 
            m_halo_hand_animation->set_intensity(1, 0, 0);
2517
 
        else
2518
 
          if ( game_variables::get_water_power(m_index) )
2519
 
            m_halo_hand_animation->set_intensity(0.19, 0.78, 0.94);
2520
 
          else
2521
 
            m_halo_hand_animation->set_intensity(1, 1, 1);
2522
 
      else
2523
 
        if ( game_variables::get_fire_power(m_index) )
2524
 
          if ( game_variables::get_water_power(m_index) )
2525
 
            m_halo_hand_animation->set_intensity(1, 0.5, 0);
2526
 
          else
2527
 
            m_halo_hand_animation->set_intensity(0.66, 0.13, 0);
2528
 
        else
2529
 
          if ( game_variables::get_water_power(m_index) )
2530
 
            m_halo_hand_animation->set_intensity(0, 0, 1);
2531
 
    }
2532
 
} // plee::update_powers()
2533
 
 
2534
 
/*----------------------------------------------------------------------------*/
2535
 
/**
2536
 
 * \brief Set the camera on the current plee.
2537
 
 */
2538
 
void ptb::plee::do_get_camera()
2539
 
{
2540
 
  shared_camera::placement_mode mode;
2541
 
 
2542
 
  if ( get_name() == player_name(1) )
2543
 
    mode = shared_camera::lock_first_player;
2544
 
  else
2545
 
    mode = shared_camera::lock_second_player;
2546
 
 
2547
 
  shared_camera::set_placement_message msg(mode);
2548
 
  bear::engine::level_globals& glob = get_level_globals();
2549
 
 
2550
 
  glob.send_message( "camera", msg );
2551
 
} // plee::do_get_camera()
2552
 
 
2553
 
/*----------------------------------------------------------------------------*/
2554
 
/**
2555
 
 * \brief Stop to look up.
2556
 
 */
2557
 
void ptb::plee::do_stop_look_upward()
2558
 
{
2559
 
  m_status_look_upward = false;
2560
 
  m_states[m_current_state]->do_stop_look_upward();
2561
 
} // state_plee::do_stop_look_upward()
2562
 
 
2563
 
/*----------------------------------------------------------------------------*/
2564
 
/**
2565
 
 * \brief Stop to crouch.
2566
 
 */
2567
 
void ptb::plee::do_stop_crouch()
2568
 
{
2569
 
  m_status_crouch = false;
2570
 
  m_states[m_current_state]->do_stop_crouch();
2571
 
} // state_plee::do_stop_crouch()
2572
 
 
2573
 
/*----------------------------------------------------------------------------*/
2574
 
/**
2575
 
 * \brief Progress the gauges.
2576
 
 * \param elapsed_time Elapsed time since the last call.
2577
 
 */
2578
 
void ptb::plee::progress_gauges( bear::universe::time_type elapsed_time )
2579
 
{
2580
 
  progress_oxygen_gauge(elapsed_time);
2581
 
  progress_fire_gauge(elapsed_time);
2582
 
  progress_ice_gauge(elapsed_time);
2583
 
} // plee::progress_gauges()
2584
 
 
2585
 
/*----------------------------------------------------------------------------*/
2586
 
/**
2587
 
 * \brief Progress the oxygen_gauge.
2588
 
 * \param elapsed_time Elapsed time since the last call.
2589
 
 */
2590
 
void ptb::plee::progress_oxygen_gauge( bear::universe::time_type elapsed_time )
2591
 
{
2592
 
  m_gauges[oxygen_gauge]->set_activated
2593
 
    (is_in_environment(bear::universe::water_environment));
2594
 
 
2595
 
  bear::engine::model_mark_placement m;
2596
 
  
2597
 
  if ( is_in_environment(bear::universe::water_environment) )
2598
 
    if ( get_mark_placement("mouth",m) ) 
2599
 
      {
2600
 
        if ( get_owner().is_in_environment
2601
 
             (m.get_position(), bear::universe::water_environment) )
2602
 
          m_gauges[oxygen_gauge]->remove_value
2603
 
            (s_oxygen_loss_speed*elapsed_time);
2604
 
        else
2605
 
          m_gauges[oxygen_gauge]->add_value
2606
 
            (s_oxygen_inspiration_speed*elapsed_time);
2607
 
      }
2608
 
    else
2609
 
      m_gauges[oxygen_gauge]->remove_value(s_oxygen_loss_speed*elapsed_time);
2610
 
  else
2611
 
    m_gauges[oxygen_gauge]->fill();
2612
 
  
2613
 
  if ( m_gauges[oxygen_gauge]->get_value() == 0 )
2614
 
    remove_energy(*this,0.1);
2615
 
} // plee::progress_oxygen_gauge()
2616
 
 
2617
 
/*----------------------------------------------------------------------------*/
2618
 
/**
2619
 
 * \brief Progress the fire_gauge.
2620
 
 * \param elapsed_time Elapsed time since the last call.
2621
 
 */
2622
 
void ptb::plee::progress_fire_gauge( bear::universe::time_type elapsed_time )
2623
 
{
2624
 
  m_gauges[fire_gauge]->set_activated
2625
 
    (is_in_environment(bear::universe::fire_environment));
2626
 
 
2627
 
  if ( is_only_in_environment(bear::universe::fire_environment) )
2628
 
    m_gauges[fire_gauge]->remove_value(s_fire_loss_speed*elapsed_time);
2629
 
  else
2630
 
    m_gauges[fire_gauge]->add_value(s_fire_increase_speed*elapsed_time);
2631
 
 
2632
 
  if ( m_gauges[fire_gauge]->get_value() == 0 )
2633
 
    remove_energy(*this,0.1);
2634
 
} // plee::progress_fire_gauge()
2635
 
 
2636
 
/*----------------------------------------------------------------------------*/
2637
 
/**
2638
 
 * \brief Progress the ice_gauge.
2639
 
 * \param elapsed_time Elapsed time since the last call.
2640
 
 */
2641
 
void ptb::plee::progress_ice_gauge( bear::universe::time_type elapsed_time )
2642
 
{
2643
 
  m_gauges[ice_gauge]->set_activated
2644
 
    (is_in_environment(bear::universe::ice_environment));
2645
 
 
2646
 
  if ( is_only_in_environment(bear::universe::ice_environment) )
2647
 
    m_gauges[ice_gauge]->remove_value(s_ice_loss_speed*elapsed_time);
2648
 
  else
2649
 
    m_gauges[ice_gauge]->add_value(s_ice_increase_speed*elapsed_time);
2650
 
 
2651
 
  if ( m_gauges[ice_gauge]->get_value() == 0 )
2652
 
    remove_energy(*this,0.1);
2653
 
} // plee::progress_ice_gauge()
2654
 
 
2655
 
/*----------------------------------------------------------------------------*/
2656
 
/**
2657
 
 * \brief Progress the spot.
2658
 
 * \param elapsed_time Elapsed time since the last call.
2659
 
 */
2660
 
void ptb::plee::progress_spot( bear::universe::time_type elapsed_time )
2661
 
{
2662
 
  bool balance_x(true);
2663
 
  bool balance_y(true);
2664
 
 
2665
 
  if ( m_status_look_upward )
2666
 
    {
2667
 
      m_look_upward_time += elapsed_time;
2668
 
 
2669
 
      if ( m_look_upward_time >= s_time_to_look_upward )
2670
 
        {
2671
 
          balance_y = false;
2672
 
          add_spot_gap( bear::universe::position_type(0, 5) );
2673
 
        }
2674
 
    }
2675
 
 
2676
 
  if ( m_status_crouch )
2677
 
    {
2678
 
      m_crouch_time += elapsed_time;
2679
 
 
2680
 
      if ( m_crouch_time >= s_time_to_crouch )
2681
 
        {
2682
 
          balance_y = false;
2683
 
          add_spot_gap( bear::universe::position_type(0, -5) );
2684
 
        }
2685
 
    }
2686
 
 
2687
 
  if ( get_speed().x > s_speed_to_run )
2688
 
    {
2689
 
      balance_x = false;
2690
 
      add_spot_gap( bear::universe::position_type(3, 0) );
2691
 
    }
2692
 
  else if ( get_speed().x < -s_speed_to_run )
2693
 
    {
2694
 
      balance_x = false;
2695
 
      add_spot_gap( bear::universe::position_type(-3, 0) );
2696
 
    }
2697
 
 
2698
 
  balance_spot(balance_x, balance_y);
2699
 
} // plee::progress_spot()
2700
 
 
2701
 
 
2702
 
/*---------------------------------------------------------------------------*/
2703
 
/**
2704
 
 * \brief Teste if Plee walk and change state thereof.
2705
 
 *         Return true if Plee walk.
2706
 
 */
2707
 
bool ptb::plee::test_walk()
2708
 
{
2709
 
  bool result = false;
2710
 
 
2711
 
  if ( has_bottom_contact() )
2712
 
    {
2713
 
      bear::universe::speed_type speed;
2714
 
      speed = get_speed();
2715
 
      // calculate the speed in the intern axis
2716
 
      bear::universe::coordinate_type speed_x =
2717
 
        speed.dot_product(get_x_axis());
2718
 
 
2719
 
      if( std::abs(speed_x) >= s_speed_to_run )
2720
 
        {
2721
 
          result = true;
2722
 
          start_action_model("run");
2723
 
        }
2724
 
      else if ( ( speed_x != 0 ) &&
2725
 
                ( get_bottom_left() != m_last_bottom_left ) )
2726
 
        {
2727
 
          result = true;
2728
 
          start_action_model("walk");
2729
 
        }
2730
 
    }
2731
 
 
2732
 
  return result;
2733
 
} // plee::test_walk()
2734
 
 
2735
 
/*---------------------------------------------------------------------------*/
2736
 
/**
2737
 
 * \brief Teste if Plee walk, run or is idle and change state thereof.
2738
 
 *         Return true if Plee has a bottom contact.
2739
 
 */
2740
 
bool ptb::plee::test_bottom_contact()
2741
 
{
2742
 
  bool result = false;
2743
 
 
2744
 
  if ( has_bottom_contact() )
2745
 
    {
2746
 
      bear::universe::speed_type speed;
2747
 
      speed = get_speed();
2748
 
 
2749
 
      // calculate the speed in the intern axis
2750
 
      bear::universe::coordinate_type speed_x =
2751
 
        speed.dot_product(get_x_axis());
2752
 
 
2753
 
      if( std::abs(speed_x) >= s_speed_to_run )
2754
 
        start_action_model("run");
2755
 
      else if( speed_x != 0 )
2756
 
        start_action_model("walk");
2757
 
      else
2758
 
        start_action_model("idle");
2759
 
 
2760
 
      result = true;
2761
 
    }
2762
 
 
2763
 
  return result;
2764
 
} // plee::test_bottom_contact()
2765
 
 
2766
 
/*---------------------------------------------------------------------------*/
2767
 
/**
2768
 
 * \brief Teste if Plee is in the sky or swimm and change state thereof.
2769
 
 *         Return true if Plee is in the sky.
2770
 
 */
2771
 
bool ptb::plee::test_in_sky_or_swimm()
2772
 
{
2773
 
  bool result = false;
2774
 
 
2775
 
  if ( !has_bottom_contact() )
2776
 
    {
2777
 
      result = true;
2778
 
 
2779
 
      if ( is_only_in_environment(bear::universe::water_environment) )
2780
 
        if( get_speed().y <= 0 )
2781
 
          start_action_model("sink");
2782
 
        else
2783
 
          start_action_model("swimming");
2784
 
      else if ( is_in_floating() )
2785
 
        start_action_model("float");
2786
 
      else if( get_speed().y <= 0 )
2787
 
        start_action_model("fall");
2788
 
      else
2789
 
        start_action_model("jump");
2790
 
    }
2791
 
 
2792
 
  return result;
2793
 
} // plee::test_in_sky_or_swimm()
2794
 
 
2795
 
/*---------------------------------------------------------------------------*/
2796
 
/**
2797
 
 * \brief Brake on x axis if Player has no direction.
2798
 
 */
2799
 
void ptb::plee::brake()
2800
 
{
2801
 
  if ( ( ! m_move_right ) && ( ! m_move_left ) )
2802
 
    {
2803
 
      bear::universe::speed_type speed = get_speed();
2804
 
      speed.x *= 0.9;
2805
 
      set_speed(speed);
2806
 
    }
2807
 
  m_move_right = false;
2808
 
  m_move_left = false;
2809
 
} // plee::brake()
2810
 
 
2811
 
/*----------------------------------------------------------------------------*/
2812
 
/**
2813
 
 * \brief Compute the ejection force of stone.
2814
 
 */
2815
 
bear::universe::force_type ptb::plee::get_stone_force() const
2816
 
{
2817
 
  double force;
2818
 
  bear::universe::force_type result;
2819
 
 
2820
 
  if ( m_throw_up && ! m_throw_down)
2821
 
    {
2822
 
      force = 4 + 4 * m_throw_time_ratio;
2823
 
      result.x = 1;
2824
 
      result.y = 5;
2825
 
    }
2826
 
  else if ( ! m_throw_up && m_throw_down)
2827
 
    {
2828
 
      force = 1 + 6 * m_throw_time_ratio;
2829
 
      result.x = 4;
2830
 
      result.y = -1;
2831
 
    }
2832
 
  else
2833
 
    {
2834
 
      force = 3 + 5 * m_throw_time_ratio;
2835
 
      result.x = 3;
2836
 
      result.y = 3;
2837
 
    }
2838
 
 
2839
 
  result *= 3500;
2840
 
 
2841
 
  if ( get_rendering_attributes().is_mirrored() )
2842
 
    result.x = -result.x;
2843
 
 
2844
 
  result.x = result.x * force + 100*get_speed().x;
2845
 
  result.y = result.y * force + get_speed().y;
2846
 
 
2847
 
  return result;
2848
 
} // plee::get_stone_force()
2849
 
 
2850
 
/*----------------------------------------------------------------------------*/
2851
 
/**
2852
 
 * \brief Create a stone.
2853
 
 *
2854
 
 * \param a The force applied to thes stone.
2855
 
 */
2856
 
void ptb::plee::create_stone( const bear::universe::force_type& a )
2857
 
{
2858
 
  if ( ! m_air_stones.empty() )
2859
 
    {
2860
 
      std::set<ptb::stone*> save_stones(m_air_stones);
2861
 
      std::set<ptb::stone*>::iterator it;
2862
 
      for ( it = save_stones.begin(); it != save_stones.end(); ++it )
2863
 
        {
2864
 
          // the call can change the set m_air_stones
2865
 
          (*it)->inform_new_stone();
2866
 
        }
2867
 
    }
2868
 
  else if ( game_variables::get_stones_count(m_index) > 0 )
2869
 
    {
2870
 
      game_variables::set_stones_count
2871
 
        ( m_index, game_variables::get_stones_count(m_index) - 1);
2872
 
 
2873
 
      stone* new_stone;
2874
 
      if ( game_variables::get_air_power(m_index) )
2875
 
        if ( game_variables::get_fire_power(m_index) )
2876
 
          if ( game_variables::get_water_power(m_index) )
2877
 
            new_stone= new air_fire_water_stone(get_id());
2878
 
          else
2879
 
            new_stone= new air_fire_stone(get_id());
2880
 
        else
2881
 
          if ( game_variables::get_water_power(m_index) )
2882
 
            new_stone= new air_water_stone(get_id());
2883
 
          else
2884
 
            new_stone= new air_stone(get_id());
2885
 
      else
2886
 
        if ( game_variables::get_fire_power(m_index) )
2887
 
          if ( game_variables::get_water_power(m_index) )
2888
 
            new_stone= new water_fire_stone(get_id());
2889
 
          else
2890
 
            new_stone= new fire_stone(get_id());
2891
 
        else
2892
 
          if ( game_variables::get_water_power(m_index) )
2893
 
            new_stone= new water_stone(get_id());
2894
 
          else
2895
 
            new_stone= new stone(get_id());
2896
 
 
2897
 
      
2898
 
      bear::engine::model_mark_placement m;
2899
 
      if ( get_mark_placement("hand",m) ) 
2900
 
        new_stone->set_center_of_mass(m.get_position());
2901
 
      else
2902
 
        new_stone->set_center_of_mass(get_center_of_mass());
2903
 
 
2904
 
      new_stone->set_z_position(get_z_position() + 2);
2905
 
      if ( m_index == 1 )
2906
 
        new_stone->set_monster_type(monster::stone_1_monster);
2907
 
      else
2908
 
        new_stone->set_monster_type(monster::stone_2_monster);
2909
 
      new_item( *new_stone );
2910
 
 
2911
 
      new_stone->add_external_force(a);
2912
 
    }
2913
 
} // ptb::plee::create_stone()
2914
 
 
2915
 
/*----------------------------------------------------------------------------*/
2916
 
/**
2917
 
 * \brief Create a honeypot.
2918
 
 *
2919
 
 * \param a The force to give at the honeypot.
2920
 
 */
2921
 
void ptb::plee::create_small_honeypot( const bear::universe::force_type& a)
2922
 
{
2923
 
  small_honeypot* new_small_honeypot = new small_honeypot();
2924
 
 
2925
 
  bear::engine::model_mark_placement m;
2926
 
  if ( get_mark_placement("hand",m) ) 
2927
 
    {
2928
 
      new_small_honeypot->set_z_position(m.get_depth_position());
2929
 
      new_small_honeypot->set_center_of_mass(m.get_position());
2930
 
    }
2931
 
  else
2932
 
    {
2933
 
      new_small_honeypot->set_z_position(get_z_position() + 1);
2934
 
      new_small_honeypot->set_center_of_mass(get_center_of_mass());
2935
 
    }
2936
 
 
2937
 
  if ( m_current_object == air_honeypot_object )
2938
 
    new_small_honeypot->set_type(base_bonus::air_power);
2939
 
  else if ( m_current_object == fire_honeypot_object )
2940
 
    new_small_honeypot->set_type(base_bonus::fire_power);
2941
 
  else
2942
 
    new_small_honeypot->set_type(base_bonus::water_power);
2943
 
    
2944
 
  new_item( *new_small_honeypot );
2945
 
 
2946
 
  new_small_honeypot->add_external_force(a);
2947
 
} // ptb::plee::create_honeypot()
2948
 
 
2949
 
 
2950
 
/*----------------------------------------------------------------------------*/
2951
 
/**
2952
 
 * \brief Create an azelnut.
2953
 
 */
2954
 
void ptb::plee::create_azelnut()
2955
 
{
2956
 
  azelnut* new_azelnut = new azelnut();
2957
 
 
2958
 
  bear::engine::model_mark_placement m;
2959
 
  if ( get_mark_placement("hand",m) ) 
2960
 
    {
2961
 
      new_azelnut->set_z_position(m.get_depth_position());
2962
 
      new_azelnut->set_center_of_mass(m.get_position());
2963
 
    }
2964
 
  else
2965
 
    {
2966
 
      new_azelnut->set_z_position(get_z_position() + 1);
2967
 
      new_azelnut->set_center_of_mass(get_center_of_mass());
2968
 
    }
2969
 
 
2970
 
  new_item( *new_azelnut );
2971
 
 
2972
 
  bear::universe::force_type force(600000,600000);
2973
 
      
2974
 
  if ( get_rendering_attributes().is_mirrored() )
2975
 
    force.x = -force.x;
2976
 
 
2977
 
  force.x = force.x + 2000*get_speed().x;
2978
 
  force.y = force.y + 20*get_speed().y;
2979
 
 
2980
 
  new_azelnut->add_external_force(force);
2981
 
} // ptb::plee::create_azelnut()
2982
 
 
2983
 
/*----------------------------------------------------------------------------*/
2984
 
/**
2985
 
 * \brief Render halos.
2986
 
 * \param visuals (out) The sprites of the item, and their positions.
2987
 
 */
2988
 
void ptb::plee::render_halos
2989
 
( std::list<bear::engine::scene_visual>& visuals ) const
2990
 
{
2991
 
  render_jump_halo(visuals);
2992
 
  render_hand_halo(visuals);
2993
 
} // plee::render_halos()
2994
 
 
2995
 
/*----------------------------------------------------------------------------*/
2996
 
/**
2997
 
 * \brief Render jump halo.
2998
 
 * \param visuals (out) The sprites of the item, and their positions.
2999
 
 */
3000
 
void ptb::plee::render_jump_halo
3001
 
( std::list<bear::engine::scene_visual>& visuals ) const
3002
 
{
3003
 
  if ( m_current_state == plee::start_jump_state )
3004
 
    {
3005
 
      bear::universe::size_type height
3006
 
        ( s_max_halo_height * (m_state_time / s_time_to_jump) );
3007
 
 
3008
 
      bear::visual::sprite current_sprite(m_halo_animation->get_sprite());
3009
 
      current_sprite.set_height((unsigned int)height);
3010
 
      current_sprite.set_angle
3011
 
        ( current_sprite.get_angle() + get_visual_angle() );
3012
 
 
3013
 
      visuals.push_front
3014
 
        ( bear::engine::scene_visual
3015
 
          ( get_bottom_middle().x - current_sprite.width() / 2,
3016
 
            get_bottom() + current_sprite.height() - 2,
3017
 
            current_sprite, get_z_position()+1 ) );
3018
 
    }
3019
 
} // plee::render_jump_halo()
3020
 
 
3021
 
/*----------------------------------------------------------------------------*/
3022
 
/**
3023
 
 * \brief Render halos.
3024
 
 * \param visuals (out) The sprites of the item, and their positions.
3025
 
 */
3026
 
void
3027
 
ptb::plee::render_hand_halo
3028
 
( std::list<bear::engine::scene_visual>& visuals ) const
3029
 
{
3030
 
  if ( has_a_power() && 
3031
 
       ( ( m_current_state == plee::maintain_state ) || 
3032
 
         ( m_current_state == plee::throw_state ) ) )
3033
 
    {
3034
 
      bear::visual::sprite current_sprite(m_halo_hand_animation->get_sprite());
3035
 
      double angle(current_sprite.get_angle() + get_visual_angle() );
3036
 
      bear::universe::position_type pos(get_center_of_mass());
3037
 
      bear::engine::model_mark_placement m;
3038
 
  
3039
 
      if ( get_mark_placement("hand_over",m) ) 
3040
 
        if ( m.is_visible() ) 
3041
 
          {
3042
 
            angle += m.get_angle(); 
3043
 
            pos = m.get_position();
3044
 
            
3045
 
            current_sprite.set_angle(angle);      
3046
 
            visuals.push_front
3047
 
              ( bear::engine::scene_visual
3048
 
                ( pos.x - current_sprite.width() / 2,
3049
 
                  pos.y + current_sprite.height() / 2,
3050
 
                  current_sprite, get_z_position()+1 ) );
3051
 
          }
3052
 
    }
3053
 
} // plee::render_hand_halo()
3054
 
 
3055
 
/*----------------------------------------------------------------------------*/
3056
 
/**
3057
 
 * \brief Render the throw state.
3058
 
 * \param visuals (out) The sprites of the item, and their positions.
3059
 
 */
3060
 
void
3061
 
ptb::plee::render_throw
3062
 
( std::list<bear::engine::scene_visual>& visuals ) const
3063
 
{
3064
 
  if ( m_current_state == plee::throw_state )
3065
 
    if ( m_animation_to_throw != NULL )
3066
 
      {
3067
 
        bear::engine::model_mark_placement m;
3068
 
            
3069
 
        if ( get_mark_placement("hand",m) ) 
3070
 
          if ( m.is_visible() )
3071
 
            {
3072
 
              bear::visual::sprite current_sprite
3073
 
                (m_animation_to_throw->get_sprite());
3074
 
              
3075
 
              double angle(current_sprite.get_angle() + 
3076
 
                           get_visual_angle() + m.get_angle() );
3077
 
              bear::universe::position_type pos = m.get_position();            
3078
 
              current_sprite.set_angle(angle);  
3079
 
              
3080
 
              visuals.push_front
3081
 
                ( bear::engine::scene_visual
3082
 
                  ( pos.x - current_sprite.width() / 2,
3083
 
                    pos.y + current_sprite.height() / 2,
3084
 
                    current_sprite, m.get_depth_position() ) );
3085
 
            }
3086
 
      }
3087
 
} // plee::render_throw()
3088
 
 
3089
 
/*----------------------------------------------------------------------------*/
3090
 
/**
3091
 
 * \brief Get the sprite representing the item without invincible visuals.
3092
 
 * \param visuals (out) The sprites of the item, and their positions.
3093
 
 */
3094
 
void
3095
 
ptb::plee::get_visuals_without_invincibility
3096
 
( std::list<bear::engine::scene_visual>& visuals ) const
3097
 
{
3098
 
  super::get_visual(visuals);
3099
 
 
3100
 
  render_halos(visuals);
3101
 
  render_throw(visuals);
3102
 
} // plee::get_visuals_without_invincibility()
3103
 
 
3104
 
/*---------------------------------------------------------------------------*/
3105
 
/**
3106
 
 * \brief Progress the invincibility statut.
3107
 
 * \param elapsed_time Elapsed time since the last call.
3108
 
 */
3109
 
void ptb::plee::progress_invincibility
3110
 
( bear::universe::time_type elapsed_time )
3111
 
{
3112
 
  m_last_visual_time += elapsed_time;
3113
 
 
3114
 
  if ( is_invincible() )
3115
 
    {
3116
 
      m_invincible_time += elapsed_time;
3117
 
      if ( m_invincible_time >= invincibility_effect::get_total_duration() )
3118
 
        set_invincible(false);
3119
 
    }
3120
 
 
3121
 
  if ( m_last_visual_time > 0.03 ) 
3122
 
    {
3123
 
      m_last_visual_time = 0;
3124
 
 
3125
 
      if ( is_invincible() )
3126
 
        {
3127
 
          if ( m_last_visuals.size() > 6 ) 
3128
 
            m_last_visuals.pop_front();
3129
 
          
3130
 
          std::list<bear::engine::scene_visual> visuals;
3131
 
          get_visuals_without_invincibility(visuals);
3132
 
          
3133
 
          std::list<bear::engine::scene_visual>::iterator it;
3134
 
          for ( it = visuals.begin(); it != visuals.end(); ++it )
3135
 
            it->scene_element.get_rendering_attributes().set_intensity
3136
 
              (1,0.5,0.5);
3137
 
          
3138
 
          m_last_visuals.push_back(visuals);
3139
 
        }
3140
 
      else if ( ! m_last_visuals.empty() ) 
3141
 
        m_last_visuals.pop_front();
3142
 
      
3143
 
      std::list< std::list<bear::engine::scene_visual> >::iterator it;
3144
 
      
3145
 
      for ( it = m_last_visuals.begin(); it != m_last_visuals.end(); ++it )
3146
 
        {
3147
 
          std::list<bear::engine::scene_visual>::iterator it2;
3148
 
          
3149
 
          for (it2 = it->begin(); it2 != it->end(); ++it2 )
3150
 
            it2->scene_element.get_rendering_attributes().set_opacity
3151
 
              ( 0.8 * 
3152
 
                it2->scene_element.get_rendering_attributes().get_opacity());
3153
 
        }  
3154
 
    }
3155
 
} // plee::progress_invincibilty()
3156
 
 
3157
 
/*---------------------------------------------------------------------------*/
3158
 
/**
3159
 
 * \brief Progress the air_float movement.
3160
 
 * \param elapsed_time Elapsed time since the last call.
3161
 
 */
3162
 
void ptb::plee::progress_air_float
3163
 
( bear::universe::time_type elapsed_time )
3164
 
{
3165
 
  m_air_float_time += elapsed_time;
3166
 
  
3167
 
  if ( m_air_float_time >= s_max_time_air_float )
3168
 
    m_air_float = false;
3169
 
  else
3170
 
    {
3171
 
      if ( get_speed().y < 0 )
3172
 
        {
3173
 
          double r=(double)rand()/(double)RAND_MAX; 
3174
 
          
3175
 
          bear::universe::force_type force
3176
 
            ( -(0.5+r/2)*get_mass() * get_owner().get_gravity() );
3177
 
          
3178
 
          if ( (get_density() != 0) &&
3179
 
               ( get_mass() != std::numeric_limits<double>::infinity() )  )
3180
 
            force += get_owner().get_gravity() * get_mass() *
3181
 
              get_owner().get_average_density(get_bounding_box()) / 
3182
 
              get_density();
3183
 
          
3184
 
          add_external_force(force);
3185
 
        }
3186
 
    }
3187
 
} // progress_air_float()