cool
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_objective.c
1 #ifndef ENT_OBJECTIVE_C
2 #define ENT_OBJECTIVE_C
3
4 #include "world.h"
5 #include "world_load.h"
6 #include "entity.h"
7 #include "audio.h"
8
9 VG_STATIC void ent_objective_pass( world_instance *world,
10 ent_objective *objective ){
11 if( objective->id_next ){
12 world_static.challenge_timer += objective->filter;
13
14 u32 index = mdl_entity_id_id( objective->id_next );
15 ent_objective *next = mdl_arritm( &world->ent_objective, index );
16 world_static.challenge_target = next;
17 objective->flags |= k_ent_objective_passed;
18
19 if( next->filter & k_ent_objective_filter_passthrough )
20 ent_objective_pass( world, next );
21 else{
22 vg_info( "pass challenge point\n" );
23 audio_oneshot_3d( &audio_challenge[0], localplayer.rb.co,
24 30.0f, 1.0f );
25 }
26 }
27 else {
28 vg_success( "challenge win\n" );
29 audio_oneshot( &audio_challenge[2], 1.0f, 0.0f );
30 world_static.challenge_target = NULL;
31 world_static.challenge_timer = 0.0f;
32
33 if( objective->id_win ){
34 ent_call call;
35 call.data = NULL;
36 call.function = objective->win_event;
37 call.id = objective->id_win;
38 entity_call( world, &call );
39 }
40 }
41 }
42
43 VG_STATIC int ent_objective_check_filter( ent_objective *objective ){
44 if( objective->filter ){
45 struct player_skate_state *s = &localplayer._skate.state;
46 enum trick_type trick = s->trick_type;
47
48 u32 state = 0x00;
49
50 if( trick == k_trick_type_shuvit )
51 state |= k_ent_objective_filter_trick_shuvit;
52 if( trick == k_trick_type_treflip )
53 state |= k_ent_objective_filter_trick_treflip;
54 if( trick == k_trick_type_kickflip )
55 state |= k_ent_objective_filter_trick_kickflip;
56
57 if( s->flip_rate < -0.0001f ) state |= k_ent_objective_filter_flip_back;
58 if( s->flip_rate > 0.0001f ) state |= k_ent_objective_filter_flip_front;
59
60 if( s->activity == k_skate_activity_grind_5050 ||
61 s->activity == k_skate_activity_grind_back50 ||
62 s->activity == k_skate_activity_grind_front50 )
63 state |= k_ent_objective_filter_grind_truck_any;
64
65 if( s->activity == k_skate_activity_grind_boardslide )
66 state |= k_ent_objective_filter_grind_board_any;
67
68 return ((objective->filter & state) || !objective->filter) &&
69 ((objective->filter2 & state) || !objective->filter2);
70 }
71 else {
72 return 1;
73 }
74 }
75
76 VG_STATIC void ent_objective_call( world_instance *world, ent_call *call ){
77 u32 index = mdl_entity_id_id( call->id );
78 ent_objective *objective = mdl_arritm( &world->ent_objective, index );
79
80 if( call->function == 0 ){
81 if( objective->flags & (k_ent_objective_hidden|
82 k_ent_objective_passed)) return;
83
84 if( world_static.challenge_target ){
85 if( (world_static.challenge_target == objective) &&
86 ent_objective_check_filter( objective )){
87 ent_objective_pass( world, objective );
88 }
89 else {
90 audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
91 30.0f, 1.0f );
92 vg_error( "challenge fialed\n" );
93 world_static.challenge_target = NULL;
94 world_static.challenge_timer = 0.0f;
95 }
96 }
97 }
98 else if( call->function == 2 ){
99 objective->flags &= ~k_ent_objective_hidden;
100
101 if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
102 call->id = objective->id_next;
103 entity_call( world, call );
104 }
105 }
106 else if( call->function == 3 ){
107 objective->flags |= k_ent_objective_hidden;
108
109 if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
110 call->id = objective->id_next;
111 entity_call( world, call );
112 }
113 }
114 else {
115 vg_print_backtrace();
116 vg_error( "Unhandled function id: %u\n", call->function );
117 }
118 }
119
120 #endif /* ENT_OBJECTIVE_C */