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