1 #include "vg/vg_engine.h"
7 void 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() */
13 if( !challenge
->status
){
14 vg_info( "challenge( '%s' )\n",
15 mdl_pstr( &world
->meta
, challenge
->pstr_alias
) );
18 call
.function
= challenge
->target_event
;
19 call
.id
= challenge
->target
;
20 entity_call( world
, &call
);
22 challenge
->status
= 1;
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();
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" );
41 vg_error( "Unhandled function id: %u\n", call
->function
);
45 void ent_challenge_preupdate( ent_challenge
*challenge
, int active
)
47 world_instance
*world
= world_current_instance();
49 /* maximum distance from active challenge */
51 f32 min_dist2
= 999999.9f
;
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
;
60 f32 d2
= v3_dist2( localplayer
.rb
.co
, objective
->transform
.co
);
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();
72 audio_oneshot_3d( &audio_challenge
[6], localplayer
.rb
.co
,
79 world_entity_focus_camera( world
, challenge
->camera
);
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
,
86 world_static
.challenge_timer
= 0.0f
;
87 world_entity_exit_modal();
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
);
99 audio_oneshot( &audio_challenge
[5], 1.0f
, 0.0f
);
105 if( button_down( k_srbind_mback
) )
107 world_static
.challenge_target
= NULL
;
108 world_entity_exit_modal();
109 world_entity_clear_focus();
112 audio_oneshot( &audio_challenge
[4], 1.0f
, 0.0f
);
118 static void ent_challenge_render( ent_challenge
*challenge
){