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_focus_context
*ctx
)
51 world_instance
*world
= ctx
->world
;
52 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, ctx
->index
);
54 /* maximum distance from active challenge */
57 f32 min_dist2
= 999999.9f
;
59 if( mdl_entity_id_type( challenge
->first
) == k_ent_objective
)
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
;
67 f32 d2
= v3_dist2( localplayer
.rb
.co
, objective
->transform
.co
);
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();
79 audio_oneshot_3d( &audio_challenge
[6], localplayer
.rb
.co
,
86 world_entity_focus_camera( world
, challenge
->camera
);
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
,
93 world_static
.challenge_timer
= 0.0f
;
94 world_entity_exit_modal();
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
);
106 audio_oneshot( &audio_challenge
[5], 1.0f
, 0.0f
);
112 if( button_down( k_srbind_mback
) )
114 world_static
.challenge_target
= NULL
;
115 world_entity_exit_modal();
116 world_entity_clear_focus();
119 audio_oneshot( &audio_challenge
[4], 1.0f
, 0.0f
);
125 static void ent_challenge_render( ent_challenge
*challenge
){