server loopback tool
[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_focus_context *ctx )
50 {
51 world_instance *world = ctx->world;
52 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, ctx->index );
53
54 /* maximum distance from active challenge */
55 if( !ctx->active )
56 {
57 f32 min_dist2 = 999999.9f;
58
59 if( mdl_entity_id_type( challenge->first ) == k_ent_objective )
60 {
61 u32 next = challenge->first;
62 while( mdl_entity_id_type(next) == k_ent_objective ){
63 u32 index = mdl_entity_id_id( next );
64 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
65 next = objective->id_next;
66
67 f32 d2 = v3_dist2( localplayer.rb.co, objective->transform.co );
68 if( d2 < min_dist2 )
69 min_dist2 = d2;
70 }
71 }
72
73 f32 max_dist = 100.0f;
74 if( min_dist2 > max_dist*max_dist ){
75 world_static.challenge_target = NULL;
76 world_static.challenge_timer = 0.0f;
77 world_entity_clear_focus();
78 audio_lock();
79 audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
80 30.0f, 1.0f );
81 audio_unlock();
82 }
83 return;
84 }
85
86 world_entity_focus_camera( world, challenge->camera );
87
88 if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
89 if( button_down( k_srbind_maccept ) ){
90 u32 index = mdl_entity_id_id( challenge->first );
91 world_static.challenge_target = mdl_arritm( &world->ent_objective,
92 index );
93 world_static.challenge_timer = 0.0f;
94 world_entity_exit_modal();
95 gui_helper_clear();
96
97 u32 next = challenge->first;
98 while( mdl_entity_id_type(next) == k_ent_objective ){
99 u32 index = mdl_entity_id_id( next );
100 ent_objective *objective = mdl_arritm(&world->ent_objective,index);
101 objective->flags &= ~k_ent_objective_passed;
102 next = objective->id_next;
103 v3_fill( objective->transform.s, 1.0f );
104 }
105 audio_lock();
106 audio_oneshot( &audio_challenge[5], 1.0f, 0.0f );
107 audio_unlock();
108 return;
109 }
110 }
111
112 if( button_down( k_srbind_mback ) )
113 {
114 world_static.challenge_target = NULL;
115 world_entity_exit_modal();
116 world_entity_clear_focus();
117 gui_helper_clear();
118 audio_lock();
119 audio_oneshot( &audio_challenge[4], 1.0f, 0.0f );
120 audio_unlock();
121 return;
122 }
123 }
124
125 static void ent_challenge_render( ent_challenge *challenge ){
126
127 }