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