npcs and tutorial stuff
[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 void 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 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_set_focus( call->id );
29 world_entity_focus_modal();
30
31 gui_helper_clear();
32 vg_str text;
33 if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
34 vg_strcat( &text, "start" );
35 if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
36 vg_strcat( &text, "exit" );
37 }
38 }
39 else {
40 vg_print_backtrace();
41 vg_error( "Unhandled function id: %u\n", call->function );
42 }
43 }
44
45 void ent_challenge_preupdate( ent_challenge *challenge, int active )
46 {
47 world_instance *world = world_current_instance();
48
49 /* maximum distance from active challenge */
50 if( !active ){
51 f32 min_dist2 = 999999.9f;
52
53 if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
54 u32 next = challenge->first;
55 while( mdl_entity_id_type(next) == k_ent_objective ){
56 u32 index = mdl_entity_id_id( next );
57 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
58 next = objective->id_next;
59
60 f32 d2 = v3_dist2( localplayer.rb.co, objective->transform.co );
61 if( d2 < min_dist2 )
62 min_dist2 = d2;
63 }
64 }
65
66 f32 max_dist = 100.0f;
67 if( min_dist2 > max_dist*max_dist ){
68 world_static.challenge_target = NULL;
69 world_static.challenge_timer = 0.0f;
70 world_entity_clear_focus();
71 audio_lock();
72 audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
73 30.0f, 1.0f );
74 audio_unlock();
75 }
76 return;
77 }
78
79 world_entity_focus_camera( world, challenge->camera );
80
81 if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
82 if( button_down( k_srbind_maccept ) ){
83 u32 index = mdl_entity_id_id( challenge->first );
84 world_static.challenge_target = mdl_arritm( &world->ent_objective,
85 index );
86 world_static.challenge_timer = 0.0f;
87 world_entity_exit_modal();
88 gui_helper_clear();
89
90 u32 next = challenge->first;
91 while( mdl_entity_id_type(next) == k_ent_objective ){
92 u32 index = mdl_entity_id_id( next );
93 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
94 objective->flags &= ~k_ent_objective_passed;
95 next = objective->id_next;
96 v3_fill( objective->transform.s, 1.0f );
97 }
98 audio_lock();
99 audio_oneshot( &audio_challenge[5], 1.0f, 0.0f );
100 audio_unlock();
101 return;
102 }
103 }
104
105 if( button_down( k_srbind_mback ) )
106 {
107 world_static.challenge_target = NULL;
108 world_entity_exit_modal();
109 world_entity_clear_focus();
110 gui_helper_clear();
111 audio_lock();
112 audio_oneshot( &audio_challenge[4], 1.0f, 0.0f );
113 audio_unlock();
114 return;
115 }
116 }
117
118 static void ent_challenge_render( ent_challenge *challenge ){
119
120 }