unlockables basics
[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 void ent_challenge_call( world_instance *world, ent_call *call ){
35 u32 index = mdl_entity_id_id( call->id );
36 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
37
38 if( call->function == 0 ){
39 if( world->challenge_target ){
40 if( world->challenge_target == challenge ){
41 ent_challenge_pass( world, challenge );
42 }
43 else {
44 vg_error( "womp womp\n" );
45 world->challenge_target = NULL;
46 world->challenge_timer = 0.0f;
47 }
48 }
49 }
50 else if( call->function == 1 ){
51 vg_info( "begin the challenge\n" );
52 world->challenge_timer = 0.0f;
53 ent_challenge_pass( world, challenge );
54 }
55 else {
56 vg_print_backtrace();
57 vg_error( "Unhandled function id: %u\n", call->function );
58 }
59 }
60
61 #endif /* ENT_CHALLENGE_C */