(50c0271)
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_challenge.c
1 #include "vg/vg_engine.h"
2 #include "entity.h"
3 #include "input.h"
4 #include "gui.h"
5 #include "audio.h"
6
7 entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
8 {
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 {
14 if( !challenge->status )
15 {
16 vg_info( "challenge( '%s' )\n",
17 mdl_pstr( &world->meta, challenge->pstr_alias) );
18 ent_call call;
19 call.data = NULL;
20 call.function = challenge->target_event;
21 call.id = challenge->target;
22 entity_call( world, &call );
23 }
24 challenge->status = 1;
25 return k_entity_call_result_OK;
26 }
27 else if( call->function == 1 ) /* view() */
28 {
29 if( (localplayer.subsystem == k_player_subsystem_walk) &&
30 (world_static.challenge_target == NULL) )
31 {
32 world_static.challenge_target = NULL;
33 world_entity_set_focus( call->id );
34 world_entity_focus_modal();
35
36 gui_helper_clear();
37 vg_str text;
38 if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
39 vg_strcat( &text, "start" );
40 if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
41 vg_strcat( &text, "exit" );
42 }
43 return k_entity_call_result_OK;
44 }
45 else
46 return k_entity_call_result_unhandled;
47 }
48
49 void ent_challenge_preupdate( ent_challenge *challenge, int active )
50 {
51 world_instance *world = world_current_instance();
52
53 /* maximum distance from active challenge */
54 if( !active ){
55 f32 min_dist2 = 999999.9f;
56
57 if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
58 u32 next = challenge->first;
59 while( mdl_entity_id_type(next) == k_ent_objective ){
60 u32 index = mdl_entity_id_id( next );
61 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
62 next = objective->id_next;
63
64 f32 d2 = v3_dist2( localplayer.rb.co, objective->transform.co );
65 if( d2 < min_dist2 )
66 min_dist2 = d2;
67 }
68 }
69
70 f32 max_dist = 100.0f;
71 if( min_dist2 > max_dist*max_dist ){
72 world_static.challenge_target = NULL;
73 world_static.challenge_timer = 0.0f;
74 world_entity_clear_focus();
75 audio_lock();
76 audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
77 30.0f, 1.0f );
78 audio_unlock();
79 }
80 return;
81 }
82
83 world_entity_focus_camera( world, challenge->camera );
84
85 if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
86 if( button_down( k_srbind_maccept ) ){
87 u32 index = mdl_entity_id_id( challenge->first );
88 world_static.challenge_target = mdl_arritm( &world->ent_objective,
89 index );
90 world_static.challenge_timer = 0.0f;
91 world_entity_exit_modal();
92 gui_helper_clear();
93
94 u32 next = challenge->first;
95 while( mdl_entity_id_type(next) == k_ent_objective ){
96 u32 index = mdl_entity_id_id( next );
97 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
98 objective->flags &= ~k_ent_objective_passed;
99 next = objective->id_next;
100 v3_fill( objective->transform.s, 1.0f );
101 }
102 audio_lock();
103 audio_oneshot( &audio_challenge[5], 1.0f, 0.0f );
104 audio_unlock();
105 return;
106 }
107 }
108
109 if( button_down( k_srbind_mback ) )
110 {
111 world_static.challenge_target = NULL;
112 world_entity_exit_modal();
113 world_entity_clear_focus();
114 gui_helper_clear();
115 audio_lock();
116 audio_oneshot( &audio_challenge[4], 1.0f, 0.0f );
117 audio_unlock();
118 return;
119 }
120 }
121
122 static void ent_challenge_render( ent_challenge *challenge ){
123
124 }