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