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