forgot to lock!
[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 #include "steam.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 u32 world_completed = 1;
48 for( u32 i=0; i<mdl_arrcount(&world->ent_challenge); i++ ){
49 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, i );
50 if( !challenge->status ){
51 world_completed = 0;
52 break;
53 }
54 }
55
56 if( world_completed ){
57 const char *understate = "Understate DIY park";
58 if( mdl_pstreq( &world->meta, world->info.pstr_name,
59 understate, vg_strdjb2( understate ))){
60 steam_set_achievement( "CITY_COMPLETE" );
61 steam_store_achievements();
62 }
63 }
64 }
65 }
66
67 static int ent_objective_check_filter( ent_objective *objective ){
68 if( objective->filter ){
69 struct player_skate_state *s = &player_skate.state;
70 enum trick_type trick = s->trick_type;
71
72 u32 state = 0x00;
73
74 if( trick == k_trick_type_shuvit )
75 state |= k_ent_objective_filter_trick_shuvit;
76 if( trick == k_trick_type_treflip )
77 state |= k_ent_objective_filter_trick_treflip;
78 if( trick == k_trick_type_kickflip )
79 state |= k_ent_objective_filter_trick_kickflip;
80
81 if( s->flip_rate < -0.0001f ) state |= k_ent_objective_filter_flip_back;
82 if( s->flip_rate > 0.0001f ) state |= k_ent_objective_filter_flip_front;
83
84 if( s->activity == k_skate_activity_grind_5050 ||
85 s->activity == k_skate_activity_grind_back50 ||
86 s->activity == k_skate_activity_grind_front50 )
87 state |= k_ent_objective_filter_grind_truck_any;
88
89 if( s->activity == k_skate_activity_grind_boardslide )
90 state |= k_ent_objective_filter_grind_board_any;
91
92 return ((objective->filter & state) || !objective->filter) &&
93 ((objective->filter2 & state) || !objective->filter2);
94 }
95 else {
96 return 1;
97 }
98 }
99
100 static void ent_objective_call( world_instance *world, ent_call *call ){
101 u32 index = mdl_entity_id_id( call->id );
102 ent_objective *objective = mdl_arritm( &world->ent_objective, index );
103
104 if( call->function == 0 ){
105 if( objective->flags & (k_ent_objective_hidden|
106 k_ent_objective_passed)) return;
107
108 if( world_static.challenge_target ){
109 if( (world_static.challenge_target == objective) &&
110 ent_objective_check_filter( objective )){
111 ent_objective_pass( world, objective );
112 }
113 else {
114 audio_lock();
115 audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
116 30.0f, 1.0f );
117 audio_unlock();
118 vg_error( "challenge failed\n" );
119 world_static.challenge_target = NULL;
120 world_static.challenge_timer = 0.0f;
121 world_static.focused_entity = 0;
122 }
123 }
124 }
125 else if( call->function == 2 ){
126 objective->flags &= ~k_ent_objective_hidden;
127
128 if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
129 call->id = objective->id_next;
130 entity_call( world, call );
131 }
132 }
133 else if( call->function == 3 ){
134 objective->flags |= k_ent_objective_hidden;
135
136 if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
137 call->id = objective->id_next;
138 entity_call( world, call );
139 }
140 }
141 else {
142 vg_print_backtrace();
143 vg_error( "Unhandled function id: %u\n", call->function );
144 }
145 }
146
147 #endif /* ENT_OBJECTIVE_C */