1 #include "vg/vg_engine.h"
7 entity_call_result
ent_challenge_call( world_instance
*world
, ent_call
*call
)
9 u32 index
= mdl_entity_id_id( call
->id
);
10 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
12 if( call
->function
== 0 ) /* unlock() */
14 if( !challenge
->status
)
16 vg_info( "challenge( '%s' )\n",
17 mdl_pstr( &world
->meta
, challenge
->pstr_alias
) );
20 call
.function
= challenge
->target_event
;
21 call
.id
= challenge
->target
;
22 entity_call( world
, &call
);
24 challenge
->status
= 1;
25 return k_entity_call_result_OK
;
27 else if( call
->function
== 1 ) /* view() */
29 if( (localplayer
.subsystem
== k_player_subsystem_walk
) &&
30 (world_static
.challenge_target
== NULL
) )
32 world_static
.challenge_target
= NULL
;
33 world_entity_set_focus( call
->id
);
34 world_entity_focus_modal();
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" );
43 return k_entity_call_result_OK
;
46 return k_entity_call_result_unhandled
;
49 void ent_challenge_preupdate( ent_challenge
*challenge
, int active
)
51 world_instance
*world
= world_current_instance();
53 /* maximum distance from active challenge */
55 f32 min_dist2
= 999999.9f
;
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
;
64 f32 d2
= v3_dist2( localplayer
.rb
.co
, objective
->transform
.co
);
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();
76 audio_oneshot_3d( &audio_challenge
[6], localplayer
.rb
.co
,
83 world_entity_focus_camera( world
, challenge
->camera
);
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
,
90 world_static
.challenge_timer
= 0.0f
;
91 world_entity_exit_modal();
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
);
103 audio_oneshot( &audio_challenge
[5], 1.0f
, 0.0f
);
109 if( button_down( k_srbind_mback
) )
111 world_static
.challenge_target
= NULL
;
112 world_entity_exit_modal();
113 world_entity_clear_focus();
116 audio_oneshot( &audio_challenge
[4], 1.0f
, 0.0f
);
122 static void ent_challenge_render( ent_challenge
*challenge
){