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