ent_challenge extra features
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_challenge.c
1 #ifndef ENT_CHALLENGE_C
2 #define ENT_CHALLENGE_C
3
4 #include "world.h"
5 #include "world_load.h"
6 #include "entity.h"
7
8 VG_STATIC void ent_challenge_pass( world_instance *world,
9 ent_challenge *challenge ){
10 if( challenge->id_next ){
11 world->challenge_timer += challenge->filter;
12
13 u32 index = mdl_entity_id_id( challenge->id_next );
14 ent_challenge *next = mdl_arritm( &world->ent_challenge, index );
15 world->challenge_target = next;
16
17 vg_info( "pass challenge point\n" );
18 }
19 else {
20 vg_success( "NYU Film school graduate SUCKAH\n" );
21 world->challenge_target = NULL;
22 world->challenge_timer = 0.0f;
23
24 if( challenge->id_win ){
25 ent_call call;
26 call.data = NULL;
27 call.function = challenge->win_event;
28 call.id = challenge->id_win;
29 entity_call( world, &call );
30 }
31 }
32 }
33
34 VG_STATIC int ent_challenge_check_filter( ent_challenge *challenge ){
35 if( challenge->filter ){
36 struct player_skate_state *s = &localplayer._skate.state;
37 enum trick_type trick = s->trick_type;
38
39 u32 state = 0x00;
40
41 if( trick == k_trick_type_shuvit )
42 state |= k_ent_challenge_filter_trick_shuvit;
43 if( trick == k_trick_type_treflip )
44 state |= k_ent_challenge_filter_trick_treflip;
45 if( trick == k_trick_type_kickflip )
46 state |= k_ent_challenge_filter_trick_kickflip;
47
48 if( s->flip_rate < -0.0001f ) state |= k_ent_challenge_filter_flip_back;
49 if( s->flip_rate > 0.0001f ) state |= k_ent_challenge_filter_flip_front;
50
51 if( s->activity == k_skate_activity_grind_5050 ||
52 s->activity == k_skate_activity_grind_back50 ||
53 s->activity == k_skate_activity_grind_front50 )
54 state |= k_ent_challenge_filter_grind_truck_any;
55
56 if( s->activity == k_skate_activity_grind_boardslide )
57 state |= k_ent_challenge_filter_grind_board_any;
58
59 return ((challenge->filter & state) || !challenge->filter) &&
60 ((challenge->filter2 & state) || !challenge->filter2);
61 }
62 else {
63 return 1;
64 }
65 }
66
67 VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ){
68 u32 index = mdl_entity_id_id( call->id );
69 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
70
71 if( call->function == 0 ){
72 if( challenge->flags & k_ent_challenge_hidden ) return;
73
74 if( world->challenge_target ){
75 if( (world->challenge_target == challenge) &&
76 ent_challenge_check_filter( challenge )){
77 ent_challenge_pass( world, challenge );
78 }
79 else {
80 vg_error( "womp womp\n" );
81 world->challenge_target = NULL;
82 world->challenge_timer = 0.0f;
83 }
84 }
85 }
86 else if( call->function == 1 ){
87 if( challenge->flags & k_ent_challenge_hidden ) return;
88
89 vg_info( "begin the challenge\n" );
90 world->challenge_timer = 0.0f;
91 ent_challenge_pass( world, challenge );
92 }
93 else if( call->function == 2 ){
94 challenge->flags &= ~k_ent_challenge_hidden;
95 }
96 else if( call->function == 3 ){
97 challenge->flags |= k_ent_challenge_hidden;
98 }
99 else {
100 vg_print_backtrace();
101 vg_error( "Unhandled function id: %u\n", call->function );
102 }
103 }
104
105 #endif /* ENT_CHALLENGE_C */