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