cool
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_challenge.c
1 #ifndef ENT_CHALLENGE_C
2 #define ENT_CHALLENGE_C
3
4 #include "entity.h"
5 #include "input.h"
6 #include "gui.h"
7 #include "audio.h"
8
9 VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ){
10 u32 index = mdl_entity_id_id( call->id );
11 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
12
13 if( call->function == 0 ){ /* unlock() */
14 if( !challenge->status ){
15 vg_info( "challenge( '%s' )\n",
16 mdl_pstr( &world->meta, challenge->pstr_alias) );
17 ent_call call;
18 call.data = NULL;
19 call.function = challenge->target_event;
20 call.id = challenge->target;
21 entity_call( world, &call );
22 }
23 challenge->status = 1;
24 }
25 else if( call->function == 1 ){ /* view() */
26 if( (localplayer.subsystem == k_player_subsystem_walk) &&
27 (world_static.challenge_target == NULL) ){
28 world_static.challenge_target = NULL;
29 world_entity_focus( call->id );
30 }
31 }
32 else {
33 vg_print_backtrace();
34 vg_error( "Unhandled function id: %u\n", call->function );
35 }
36 }
37
38 VG_STATIC void ent_challenge_preupdate( ent_challenge *challenge ){
39 world_instance *world = world_current_instance();
40
41 if( mdl_entity_id_type( challenge->camera ) == k_ent_camera ){
42 u32 index = mdl_entity_id_id( challenge->camera );
43 ent_camera *cam = mdl_arritm( &world->ent_camera, index );
44
45 /* TODO COMPRESSION */
46 v3f dir = {0.0f,-1.0f,0.0f};
47 mdl_transform_vector( &cam->transform, dir, dir );
48 m3x3_mulv( localplayer.invbasis, dir, dir );
49 player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f );
50 v3_copy( cam->transform.co, world_static.focus_cam.pos );
51 world_static.focus_cam.fov = cam->fov;
52 }
53 else {
54 /* TODO COMPRESSION */
55 v3_copy( localplayer.cam.pos, world_static.focus_cam.pos );
56 v3_copy( localplayer.cam.angles, world_static.focus_cam.angles );
57 world_static.focus_cam.fov = localplayer.cam.fov;
58 world_static.focus_cam.nearz = localplayer.cam.nearz;
59 world_static.focus_cam.farz = localplayer.cam.farz;
60 }
61
62 gui_helper_action( button_display_string( k_srbind_maccept ), "start" );
63 gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
64
65 if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
66 if( button_down( k_srbind_maccept ) ){
67 u32 index = mdl_entity_id_id( challenge->first );
68 world_static.challenge_target = mdl_arritm( &world->ent_objective,
69 index );
70 world_static.challenge_timer = 0.0f;
71 world_entity_unfocus();
72
73 u32 next = challenge->first;
74 while( mdl_entity_id_type(next) == k_ent_objective ){
75 u32 index = mdl_entity_id_id( next );
76 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
77 objective->flags &= ~k_ent_objective_passed;
78 next = objective->id_next;
79 v3_fill( objective->transform.s, 1.0f );
80 }
81 audio_oneshot( &audio_challenge[5], 1.0f, 0.0f );
82 return;
83 }
84 }
85
86 if( button_down( k_srbind_mback ) ){
87 world_static.challenge_target = NULL;
88 world_entity_unfocus();
89 audio_oneshot( &audio_challenge[4], 1.0f, 0.0f );
90 return;
91 }
92 }
93
94 VG_STATIC void ent_challenge_render( ent_challenge *challenge ){
95
96 }
97
98 #endif /* ENT_CHALLENGE_C */