/
player.cpp
3957 lines (3480 loc) · 120 KB
/
player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2012 Stuffomatic Ltd. <contact@stuff-o-matic.com>
All rights reserved.
See the accompanying license file for details about usage, modification and
distribution of this file.
*/
/**
* \file
* \brief Implementation of the ptb::player class.
* \author Sebastien Angibaud
*/
#include "ptb/player.hpp"
#include <sstream>
#include "engine/game.hpp"
#include "engine/level.hpp"
#include "engine/world.hpp"
#include "engine/message/transition_effect_message.hpp"
#include "engine/message/transition_effect_erase_message.hpp"
#include "generic_items/tweener_item.hpp"
#include "generic_items/camera_shaker.hpp"
#include "generic_items/decorative_effect.hpp"
#include "generic_items/star.hpp"
#include "universe/forced_movement/forced_tracking.hpp"
#include "ptb/defines.hpp"
#include "ptb/gauge.hpp"
#include "ptb/level_variables.hpp"
#include "ptb/item_brick/monster.hpp"
#include "ptb/item_brick/sniffable.hpp"
#include "ptb/player_action.hpp"
#include "ptb/player_signals.hpp"
#include "ptb/throwable_item/air_honeypot_throwable_item.hpp"
#include "ptb/throwable_item/corrupting_item_throwable_item.hpp"
#include "ptb/throwable_item/fire_honeypot_throwable_item.hpp"
#include "ptb/throwable_item/hazelnut_throwable_item.hpp"
#include "ptb/throwable_item/stone_throwable_item.hpp"
#include "ptb/throwable_item/water_honeypot_throwable_item.hpp"
#include "ptb/item/air_bubble.hpp"
#include "ptb/item/bonus_box.hpp"
#include "ptb/item/floating_score.hpp"
#include "ptb/item/power_effect.hpp"
#include "ptb/item/shared_camera.hpp"
#include "ptb/item/small_honeypot.hpp"
#include "ptb/item/stone/air_fire_stone.hpp"
#include "ptb/item/stone/air_fire_water_stone.hpp"
#include "ptb/item/stone/air_water_stone.hpp"
#include "ptb/item/stone/air_stone.hpp"
#include "ptb/item/stone/water_fire_stone.hpp"
#include "ptb/item/stone/water_stone.hpp"
#include "ptb/item/stone/fire_stone.hpp"
#include "ptb/item/hazelnut.hpp"
#include "ptb/item/corrupting_bonus_attractor.hpp"
#include "ptb/message/status_layer_notification_message.hpp"
#include "ptb/player_state/state_player.hpp"
#include "ptb/player_state/state_roar.hpp"
#include "ptb/player_state/state_walk.hpp"
#include "ptb/player_state/state_idle.hpp"
#include "ptb/player_state/state_jump.hpp"
#include "ptb/player_state/state_fall.hpp"
#include "ptb/player_state/state_dead.hpp"
#include "ptb/player_state/state_game_over.hpp"
#include "ptb/player_state/state_run.hpp"
#include "ptb/player_state/state_slap.hpp"
#include "ptb/player_state/state_start_jump.hpp"
#include "ptb/player_state/state_vertical_jump.hpp"
#include "ptb/player_state/state_look_upward.hpp"
#include "ptb/player_state/state_crouch.hpp"
#include "ptb/player_state/state_captive.hpp"
#include "ptb/player_state/state_throw.hpp"
#include "ptb/player_state/state_maintain.hpp"
#include "ptb/player_state/state_wait.hpp"
#include "ptb/player_state/state_start_cling.hpp"
#include "ptb/player_state/state_cling.hpp"
#include "ptb/player_state/state_clung_jump.hpp"
#include "ptb/player_state/state_start_hang.hpp"
#include "ptb/player_state/state_hang.hpp"
#include "ptb/player_state/state_sink.hpp"
#include "ptb/player_state/state_swimming.hpp"
#include "ptb/player_state/state_float.hpp"
#include "ptb/player_state/state_injured.hpp"
#include "ptb/player_state/state_paralyze.hpp"
#include "ptb/transition_effect/game_over_effect.hpp"
#include "ptb/transition_effect/contest_result_effect.hpp"
#include "ptb/transition_effect/invincibility_effect.hpp"
#include "ptb/util/player_util.hpp"
#include <claw/tween/easing/easing_linear.hpp>
/*----------------------------------------------------------------------------*/
const double ptb::player::s_max_oxygen_gauge = 10000;
const double ptb::player::s_max_heat_gauge = 10000;
const double ptb::player::s_max_cold_gauge = 10000;
const double ptb::player::s_oxygen_loss_speed = 200;
const double ptb::player::s_oxygen_inspiration_speed = 1500;
const double ptb::player::s_fire_loss_speed = 200;
const double ptb::player::s_fire_increase_speed = 1500;
const double ptb::player::s_ice_loss_speed = 200;
const double ptb::player::s_ice_increase_speed = 1500;
const bear::universe::size_type ptb::player::s_max_halo_height = 64;
const bear::universe::size_type ptb::player::s_max_halo_hand_width = 35;
const bear::universe::time_type ptb::player::s_time_to_crouch = 0.5;
const bear::universe::time_type ptb::player::s_time_to_look_upward = 0.5;
const bear::universe::time_type ptb::player::s_time_to_wait = 3;
const bear::universe::time_type ptb::player::s_time_to_jump = 1;
const bear::universe::time_type ptb::player::s_time_to_start_throw = 0.17;
const bear::universe::time_type ptb::player::s_max_time_to_cling = 0.3;
const bear::universe::time_type ptb::player::s_max_time_to_hang = 1;
const bear::universe::time_type ptb::player::s_max_time_air_float = 1;
const bear::universe::time_type ptb::player::s_max_time_continue_jump = 0.28;
/*----------------------------------------------------------------------------*/
/**
* \brief Constructor.
* \param physics The physics constants defining the behavior of the player.
*/
ptb::player::player( const player_physics& physics )
: m_current_state(roar_state),
m_physics( physics ),
m_last_visual_time(0),
m_oxygen_gauge(s_max_oxygen_gauge), m_cold_gauge(s_max_cold_gauge),
m_heat_gauge(s_max_heat_gauge), m_status_look_upward(false),
m_status_crouch(false), m_can_cling(false),
m_cling_orientation(false), m_halo_animation(NULL),
m_halo_hand_animation(NULL), m_move_right(false), m_move_left(false),
m_force_orientation_right(false), m_force_orientation_left(false),
m_index(0), m_nb_bottom_contact(0),
m_controller_number(0),
m_air_float(false), m_injured_orientation(true),
m_hot_spot_position(0, 0),
m_hot_spot_minimum(0, 0), m_hot_spot_maximum(0, 0),
m_hot_spot_balance_move(0, 0), m_corrupting_bonus_attractor(NULL)
{
init();
m_offensive_force = 10;
m_energy = 100;
m_offensive_phase = false;
m_offensive_coefficients[normal_attack] = 1;
} // player::player()
/*----------------------------------------------------------------------------*/
/**
* \brief Constructor.
*/
ptb::player::player( const player& p )
: super(p),
m_current_state(p.roar_state),
m_physics( p.m_physics ),
m_last_visual_time(0),
m_oxygen_gauge(s_max_oxygen_gauge), m_cold_gauge(s_max_cold_gauge),
m_heat_gauge(s_max_heat_gauge),
m_status_look_upward(p. m_status_look_upward),
m_status_crouch(p.m_status_crouch), m_can_cling(p. m_can_cling),
m_cling_orientation(p.m_cling_orientation),
m_halo_animation(NULL), m_halo_hand_animation(NULL),
m_move_right(p. m_move_right), m_move_left(p.m_move_left),
m_force_orientation_right(p. m_force_orientation_right),
m_force_orientation_left(p.m_force_orientation_left),
m_index(0), m_nb_bottom_contact(0), m_controller_number(0),
m_injured_orientation(true),
m_hot_spot_position(0, 0),
m_hot_spot_minimum(0, 0), m_hot_spot_maximum(0, 0),
m_hot_spot_balance_move(0, 0), m_corrupting_bonus_attractor(NULL)
{
init();
set_index(p.get_index());
if ( m_defensive_powers[monster::air_attack] )
game_variables::set_air_power(get_index(), true);
if ( m_defensive_powers[monster::fire_attack] )
game_variables::set_fire_power(get_index(), true);
if ( m_defensive_powers[monster::water_attack] )
game_variables::set_water_power(get_index(), true);
} // player::player()
/*----------------------------------------------------------------------------*/
/**
* \brief Init member variables.
*/
void ptb::player::init()
{
set_z_fixed(false);
set_weak_collisions(false);
m_offensive_phase = false;
set_spot_minimum(-200, -250);
set_spot_maximum(200, 220);
set_spot_balance_move(3, 15);
set_air_float(false);
save_current_position();
m_last_bottom_left = bear::universe::position_type(0, 0);
m_monster_type = monster::player_monster;
m_invincible_time = 0;
m_states.resize(27);
m_states[walk_state] = new state_walk(this);
m_states[idle_state] = new state_idle(this);
m_states[jump_state] = new state_jump(this);
m_states[fall_state] = new state_fall(this);
m_states[dead_state] = new state_dead(this);
m_states[game_over_state] = new state_game_over(this);
m_states[roar_state] = new state_roar(this);
m_states[run_state] = new state_run(this);
m_states[slap_state] = new state_slap(this);
m_states[start_jump_state] = new state_start_jump(this);
m_states[vertical_jump_state] = new state_vertical_jump(this);
m_states[look_upward_state] = new state_look_upward(this);
m_states[crouch_state] = new state_crouch(this);
m_states[captive_state] = new state_captive(this);
m_states[throw_state] = new state_throw(this);
m_states[wait_state] = new state_wait(this);
m_states[start_cling_state] = new state_start_cling(this);
m_states[cling_state] = new state_cling(this);
m_states[clung_jump_state] = new state_clung_jump(this);
m_states[start_hang_state] = new state_start_hang(this);
m_states[hang_state] = new state_hang(this);
m_states[swimming_state] = new state_swimming(this);
m_states[sink_state] = new state_sink(this);
m_states[float_state] = new state_float(this);
m_states[maintain_state] = new state_maintain(this);
m_states[injured_state] = new state_injured(this);
m_states[paralyze_state] = new state_paralyze(this);
m_progress = &player::progress_roar;
} // player::init()
/*----------------------------------------------------------------------------*/
/**
* \brief Destructor.
*/
ptb::player::~player()
{
unsigned int i;
for (i=0; i!=m_states.size(); ++i)
delete m_states[i];
if ( m_halo_animation )
delete m_halo_animation;
if ( m_halo_hand_animation )
delete m_halo_hand_animation;
} // player::~player()
/*---------------------------------------------------------------------------*/
/**
* \brief Do one iteration in the progression of the item.
* \param elapsed_time Elapsed time since the last call.
*/
void ptb::player::progress( bear::universe::time_type elapsed_time )
{
super::progress(elapsed_time);
if ( is_a_marionette() )
dummy_progress_input_actions(elapsed_time);
else
progress_input_actions(elapsed_time);
counter_slope_reaction();
m_state_time += elapsed_time;
m_jump_time += elapsed_time;
progress_corrupting_bonus_attractor(elapsed_time);
if ( m_air_float )
progress_air_float(elapsed_time);
m_jump_force = get_mass() * 7500 *
(1 - (m_jump_time / s_max_time_continue_jump)
* (m_jump_time / s_max_time_continue_jump) );
if (m_jump_force <= 0)
m_jump_force = 0;
progress_invincibility(elapsed_time);
m_throwable_items.progress(elapsed_time);
if ( is_crushed() && (m_current_state != player::dead_state) )
apply_die();
else
{
if ( m_progress != NULL )
(this->*m_progress)(elapsed_time);
if ( is_only_in_environment(bear::universe::water_environment) )
progress_in_water(elapsed_time);
update_powers();
progress_spot( elapsed_time );
progress_gauges( elapsed_time );
update_orientation();
m_can_cling = false;
if ( ( m_current_state == player::maintain_state ) ||
( m_current_state == player::throw_state ) )
m_halo_hand_animation->next(elapsed_time);
m_animation_to_throw.next(elapsed_time);
}
m_last_bottom_left = get_bottom_left();
m_can_throw_power[air_attack] = true;
m_can_throw_power[fire_attack] = true;
m_can_throw_power[water_attack] = true;
if ( m_throwable_items.get_current_throwable_item()->is_empty() )
m_throwable_items.next();
m_move_right = false;
m_move_left = false;
m_force_orientation_right = false;
m_force_orientation_left = false;
} // player::progress()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the sprite representing the item.
* \param visuals (out) The sprites of the item, and their positions.
*/
void
ptb::player::get_visual( std::list<bear::engine::scene_visual>& visuals ) const
{
get_visuals_without_invincibility(visuals);
std::list< std::list<bear::engine::scene_visual> >::const_iterator it;
for ( it = m_last_visuals.begin(); it != m_last_visuals.end(); ++it )
{
std::list<bear::engine::scene_visual>::const_iterator it2;
for (it2 = it->begin(); it2 != it->end(); ++it2 )
visuals.push_front(*it2);
}
} // player::get_visual()
/*----------------------------------------------------------------------------*/
/**
* \brief Load the media required by this class.
*/
void ptb::player::pre_cache()
{
super::pre_cache();
// halo for vertical jump
get_level_globals().load_animation("animation/plee/halo.canim");
get_level_globals().load_animation("animation/plee/halo_hand.canim");
// small honeypot
get_level_globals().load_animation("animation/powerup/small_fire.canim");
get_level_globals().load_animation("animation/powerup/small_air.canim");
get_level_globals().load_animation("animation/powerup/small_water.canim");
// stones
get_level_globals().load_model("model/stones/stone.cm");
get_level_globals().load_model("model/stones/air_stone.cm");
get_level_globals().load_model("model/stones/water_stone.cm");
get_level_globals().load_model("model/stones/fire_stone.cm");
get_level_globals().load_model("model/stones/air_fire_stone.cm");
get_level_globals().load_model("model/stones/air_water_stone.cm");
get_level_globals().load_model("model/stones/water_fire_stone.cm");
get_level_globals().load_model("model/stones/air_fire_water_stone.cm");
get_level_globals().load_animation("animation/stones/sliver_1.canim");
get_level_globals().load_animation("animation/stones/sliver_2.canim");
get_level_globals().load_animation("animation/stones/sliver_3.canim");
get_level_globals().load_animation("animation/stones/sliver_4.canim");
get_level_globals().load_animation("animation/stones/sliver_5.canim");
get_level_globals().load_animation("animation/steam.canim");
// musics
get_level_globals().load_sound("music/1-up.ogg");
get_level_globals().load_sound("music/game-over.ogg");
get_level_globals().load_sound("music/invincibility.ogg");
// sounds
get_level_globals().load_sound("sound/grr.wav");
get_level_globals().load_sound("sound/plee/snore.ogg");
} // player::pre_cache()
/*----------------------------------------------------------------------------*/
/**
* \brief Do post creation actions.
*/
void ptb::player::on_enters_layer()
{
super::on_enters_layer();
if ( m_defensive_powers[monster::air_attack] )
game_variables::set_air_power(get_index(), true);
if ( m_defensive_powers[monster::fire_attack] )
game_variables::set_fire_power(get_index(), true);
if ( m_defensive_powers[monster::water_attack] )
game_variables::set_water_power(get_index(), true);
m_authorized_action.resize(player_action::max_value + 1);
for ( unsigned int i=0; i <= player_action::max_value; ++i)
m_authorized_action[i] = true;
m_energy = game_variables::get_max_energy(m_index);
set_air_float(false);
m_injured_orientation = true;
fill_throwable_items();
save_current_position();
m_wait_state_number = 0;
m_want_clung_jump = false;
bear::engine::level_globals& glob = get_level_globals();
m_halo_animation = new bear::visual::animation
( glob.get_animation("animation/plee/halo.canim") );
m_halo_hand_animation = new bear::visual::animation
( glob.get_animation("animation/plee/halo_hand.canim") );
if ( ( m_index == 1 ) || ( m_index == 2 ) )
get_level().add_interest_around(this);
m_can_throw_power[air_attack] = true;
m_can_throw_power[fire_attack] = true;
m_can_throw_power[water_attack] = true;
create_power_effect();
} // player::on_enters_layer()
/*----------------------------------------------------------------------------*/
/**
* \brief Tell if the item is correctly initialized.
*/
bool ptb::player::is_valid() const
{
return (m_index != 0) && super::is_valid();
} // player::is_valid()
/*----------------------------------------------------------------------------*/
/**
* \brief Set a field of type unsigned integer.
* \param name The name of the field.
* \param value The new value of the field.
* \return false if the field "name" is unknow, true otherwise.
*/
bool ptb::player::set_u_integer_field
( const std::string& name, unsigned int value )
{
bool result = true;
if (name == "player.index")
set_index(value);
else
result = super::set_u_integer_field(name, value);
return result;
} // player::set_u_integer_field()
/*----------------------------------------------------------------------------*/
/**
* \brief Save the position of the player.
* \param p The center of mass to remember.
*/
void ptb::player::save_position( const bear::universe::position_type& p )
{
m_saved_position = p;
} // player::save_position()
/*----------------------------------------------------------------------------*/
/**
* \brief Save the current position of the player.
*/
void ptb::player::save_current_position()
{
save_position( get_center_of_mass() );
} // player::save_current_position()
/*----------------------------------------------------------------------------*/
/**
* \brief Tell to Player to start an action.
* \param a The action to start.
*/
void ptb::player::start_action( player_action::value_type a )
{
if ( m_authorized_action[a] )
switch( a )
{
case player_action::idle : break;
case player_action::move_left : break;
case player_action::move_right : break;
case player_action::jump :
m_states[m_current_state]->do_jump(); break;
case player_action::get_camera : do_get_camera(); break;
case player_action::slap :
m_states[m_current_state]->do_slap(); break;
case player_action::look_upward : do_start_look_upward(); break;
case player_action::crouch : do_start_crouch(); break;
case player_action::change_object :
m_states[m_current_state]->do_start_change_object(); break;
case player_action::captive : break;
case player_action::release : break;
case player_action::throw_stone : do_start_throw(); break;
case player_action::die : apply_die(); break;
case player_action::roar : start_action_model("roar"); break;
case player_action::disappear : start_action_model("disappear"); break;
case player_action::action_null: break;
default:
claw::logger << claw::log_warning << "Action ignored (start): " << a
<< std::endl;;
}
} // player::start_action()
/*----------------------------------------------------------------------------*/
/**
* \brief Tell to the player to do an action.
* \param elapsed_time How long the action is done.
* \param a The action to do.
*/
void ptb::player::do_action
( bear::universe::time_type elapsed_time, player_action::value_type a )
{
switch( a )
{
case player_action::move_left :
if ( !get_rendering_attributes().is_mirrored() )
m_injured_orientation = true;
m_states[m_current_state]->do_move_left(); break;
case player_action::move_right :
if ( get_rendering_attributes().is_mirrored() )
m_injured_orientation = true;
m_states[m_current_state]->do_move_right(); break;
default:
if ( m_authorized_action[a] )
switch( a )
{
case player_action::idle : choose_idle_state(); break;
case player_action::jump :
m_states[m_current_state]->do_continue_jump(); break;
case player_action::get_camera : break;
case player_action::slap : break;
case player_action::look_upward :
m_states[m_current_state]->do_continue_look_upward(); break;
case player_action::crouch :
m_states[m_current_state]->do_continue_crouch(); break;
case player_action::change_object : break;
case player_action::captive :
m_states[m_current_state]->captive(); break;
case player_action::release :
m_states[m_current_state]->release(); break;
case player_action::throw_stone : break;
case player_action::die : break;
case player_action::action_null: break;
default:
claw::logger << claw::log_warning << "Action ignored: " << a
<< std::endl;
}
}
} // player::do_action()
/*----------------------------------------------------------------------------*/
/**
* \brief Tell to player to stop an action.
* \param a The action to stop.
*/
void ptb::player::stop_action( player_action::value_type a )
{
if ( m_authorized_action[a] )
switch( a )
{
case player_action::idle : break;
case player_action::move_left :
m_want_clung_jump = false; break;
case player_action::move_right :
m_want_clung_jump = false; break;
case player_action::jump :
m_states[m_current_state]->do_stop_vertical_jump(); break;
case player_action::get_camera : break;
case player_action::slap : break;
case player_action::look_upward : do_stop_look_upward(); break;
case player_action::crouch :
do_stop_crouch(); break;
case player_action::throw_stone :
m_states[m_current_state]->do_stop_throw(); break;
case player_action::change_object : break;
case player_action::captive : break;
case player_action::release : break;
case player_action::die : break;
case player_action::action_null: break;
default:
claw::logger << claw::log_warning << "Action ignored (stop): " << a
<< std::endl;
}
} // player::stop_action()
/*----------------------------------------------------------------------------*/
/**
* \brief Start a new action of model.
* \param action The action to start.
*/
void ptb::player::start_action_model(const std::string& action)
{
start_model_action(action);
} // player::start_action_model()
/*----------------------------------------------------------------------------*/
/**
* \brief Set if a given action is authorized.
* \param a Tha action to set.
* \param value The new state of the action (true if authorized).
*/
void ptb::player::set_authorized_action(player_action::value_type a, bool value)
{
m_authorized_action[a] = value;
} // player::set_authorized_action()
/*----------------------------------------------------------------------------*/
/**
* \brief Authorize a given action.
* \param a The name of the action to authorize.
*/
void ptb::player::authorize_action( const std::string& a )
{
const player_action::value_type c = player_action::from_string(a);
if ( c != player_action::action_null )
m_authorized_action[c] = true;
} // player::authorize_action()
/*----------------------------------------------------------------------------*/
/**
* \brief Authorize all the actions.
*/
void ptb::player::authorize_all_actions()
{
for ( std::size_t i=0; i!=m_authorized_action.size(); ++i )
m_authorized_action[i] = true;
} // player::authorize_all_actions()
/*----------------------------------------------------------------------------*/
/**
* \brief Disable all the actions.
*/
void ptb::player::disable_all_actions()
{
for ( std::size_t i=0; i!=m_authorized_action.size(); ++i )
m_authorized_action[i] = false;
} // player::disable_all_actions()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the gauge of the oxygen.
*/
const ptb::gauge& ptb::player::get_oxygen_gauge() const
{
return m_oxygen_gauge;
} // player::get_oxygen_gauge()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the gauge of the cold.
*/
const ptb::gauge& ptb::player::get_cold_gauge() const
{
return m_cold_gauge;
} // player::get_cold_gauge()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the gauge of the heat.
*/
const ptb::gauge& ptb::player::get_heat_gauge() const
{
return m_heat_gauge;
} // player::get_heat_gauge()
/*----------------------------------------------------------------------------*/
/**
* \brief Get player's signals.
*/
ptb::player_signals& ptb::player::get_signals()
{
return m_signals;
} // player::get_signals()
/*----------------------------------------------------------------------------*/
/**
* \brief Give the ratio of the length of preparation of the jump.
*/
bear::universe::time_type ptb::player::get_jump_time_ratio() const
{
return m_jump_time_ratio;
} // player::get_jump_time_ratio()
/*----------------------------------------------------------------------------*/
/**
* \brief Update the ratio of the preparation of throw state.
*/
void ptb::player::update_throw_time_ratio()
{
m_throw_time_ratio = m_state_time / s_time_to_start_throw;
} // player::update_throw_time_ratio()
/*----------------------------------------------------------------------------*/
/**
* \brief Set the value of throw_down.
* \param value The state of throw_down.
*/
void ptb::player::set_throw_down(bool value)
{
m_throw_down = value;
} // player::set_throw_down()
/*----------------------------------------------------------------------------*/
/**
* \brief Start to throw an hazelnut
*/
void ptb::player::throw_hazelnut()
{
m_throwable_items.select(hazelnut_throwable_item::s_name);
start_action(player_action::throw_stone);
apply_maintain();
m_state_time = 0.01;
stop_action(player_action::throw_stone);
set_state(player::maintain_state);
} // player::throw_hazelnut()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the set of throwable_items.
*/
const ptb::throwable_items_container& ptb::player::get_throwable_items() const
{
return m_throwable_items;
} // player::get_throwable_items()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the set of throwable_items.
*/
ptb::throwable_items_container& ptb::player::get_throwable_items()
{
return m_throwable_items;
} // player::get_throwable_items()
/*----------------------------------------------------------------------------*/
/**
* \brief Set the value of throw_up.
* \param value The state of throw_up.
*/
void ptb::player::set_throw_up(bool value)
{
m_throw_up = value;
} // player::set_throw_up()
/*----------------------------------------------------------------------------*/
/**
* \brief Indicates if Player is a marionette.
*/
bool ptb::player::is_a_marionette() const
{
return (m_controller_number != 0);
} // player::is_a_marionette()
/*----------------------------------------------------------------------------*/
/**
* \brief Turn on/off the marionette state of Player.
* \param b The new value of the state.
*/
void ptb::player::set_marionette( bool b )
{
if ( b )
++m_controller_number;
else
{
CLAW_PRECOND( m_controller_number >= 1 );
--m_controller_number;
}
} // player::set_marionette()
/*----------------------------------------------------------------------------*/
/**
* \brief Turn on/off the air_float status of Player.
* \param b The new value of the state.
*/
void ptb::player::set_air_float( bool b )
{
m_air_float = b;
m_air_float_time = 0;
} // player::set_air_float()
/*----------------------------------------------------------------------------*/
/**
* \brief Set the look up status.
*/
void ptb::player::set_status_look_upward(bool status)
{
m_status_look_upward = status;
} // player::set_status_look_upward()
/*----------------------------------------------------------------------------*/
/**
* \brief Give the look up status.
*/
bool ptb::player::get_status_look_upward() const
{
return m_status_look_upward;
} // player::get_status_look_upward()
/*----------------------------------------------------------------------------*/
/**
* \brief Set the crouch status.
*/
void ptb::player::set_status_crouch(bool status)
{
m_status_crouch = status;
} // player::set_status_crouch()
/*----------------------------------------------------------------------------*/
/**
* \brief Give the crouch status.
*/
bool ptb::player::get_status_crouch() const
{
return m_status_crouch;
} // player::get_status_crouch()
/*----------------------------------------------------------------------------*/
/**
* \brief Make the player start to look up.
*/
void ptb::player::do_start_look_upward()
{
m_status_look_upward = true;
m_look_upward_time = 0;
m_states[m_current_state]->do_look_upward();
} // player::do_start_look_upward()
/*----------------------------------------------------------------------------*/
/**
* \brief Make the player start to crouch.
*/
void ptb::player::do_start_crouch()
{
m_status_crouch = true;
m_crouch_time = 0;
m_states[m_current_state]->do_crouch();
} // player::do_start_crouch()
/*----------------------------------------------------------------------------*/
/**
* \brief Make the player start to throw.
*/
void ptb::player::do_start_throw()
{
if ( m_throwable_items.get_current_throwable_item()->can_throw()
&& m_air_stones.empty() )
{
m_animation_to_throw =
get_level_globals().get_animation
( m_throwable_items.get_current_throwable_item()->get_animation() );
m_states[m_current_state]->do_start_throw();
}
else if ( ! m_air_stones.empty() )
apply_blast_stone();
else
m_throwable_items.throwable_item_no_stock();
} // player::do_start_throw()
/*----------------------------------------------------------------------------*/
/**
* \brief Set if Player can cling.
* \param status The new status.
*/
void ptb::player::set_can_cling(bool status)
{
m_can_cling = status;
} // player::set_can_cling()
/*----------------------------------------------------------------------------*/
/**
* \brief Indicates if the player is clung.
*/
bool ptb::player::is_clung() const
{
return ( m_current_state == cling_state );
} // player::is_clung()
/*----------------------------------------------------------------------------*/
/**
* \brief Set if Player want to do a clumb jump.
* \param status The new status.
*/
void ptb::player::set_want_clung_jump(bool status)
{
m_want_clung_jump = status;
} // player::set_want_clung_jump()
/*----------------------------------------------------------------------------*/
/**
* \brief Indicates if the player want to do a clung jump.
*/
bool ptb::player::want_clung_jump() const
{
return m_want_clung_jump;
} // player::want_clung_jump()
/*----------------------------------------------------------------------------*/
/**
* \brief Player receives energy.
*
* \param energy The energy received.
*/
void ptb::player::receive_energy(double energy)
{
bool signal( ( m_energy < game_variables::get_max_energy(m_index) ) &&
( energy != 0 ) );
m_energy += energy;
if ( m_energy > game_variables::get_max_energy(m_index) )
m_energy = game_variables::get_max_energy(m_index);
if ( signal )
m_signals.energy_added(m_energy);
create_soul_decoration();
} // player::receive_energy()
/*----------------------------------------------------------------------------*/
/**
* \brief We remove some energy of the item..
*
* \param attacker The attacker monster.
* \param energy The quantity of energy removed.
*/
void ptb::player::remove_energy(const monster& attacker, double energy )
{
double last_energy(m_energy);
super::remove_energy(attacker, energy);
if ( m_energy != last_energy )
m_signals.energy_removed(m_energy);
} // player::remove_energy()
/*----------------------------------------------------------------------------*/
/**
* \brief The item has attacked.
* \param other The monster that is attacked.
*/
void ptb::player::has_attacked(const monster& other)
{
super::has_attacked(other);
if ( ( other.get_monster_type() == monster::player_monster ) &&
( ! level_variables::get_friendly_fire( get_level() ) ) )
{
status_layer_notification_message msg;
bear::visual::sprite sp;
msg.set_notification
( get_monster_index(), sp, gettext("snake in the grass"));
get_level_globals().send_message
( PTB_STATUS_LAYER_DEFAULT_TARGET_NAME, msg );
}
} // player::has_attacked()
/*----------------------------------------------------------------------------*/
/**
* \brief Set the invincible status.
* \param invincible The new invincible status.
*/
void ptb::player::set_invincible(const bool invincible)
{
super::set_invincible(invincible);
if ( m_invincible )
{
m_invincible_time = 0;
m_last_visual_time = 0;
m_last_visuals.clear();