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