1 #ifndef ENT_CHALLENGE_C
2 #define ENT_CHALLENGE_C
9 static void ent_challenge_call( world_instance
*world
, ent_call
*call
){
10 u32 index
= mdl_entity_id_id( call
->id
);
11 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, index
);
13 if( call
->function
== 0 ){ /* unlock() */
14 if( !challenge
->status
){
15 vg_info( "challenge( '%s' )\n",
16 mdl_pstr( &world
->meta
, challenge
->pstr_alias
) );
19 call
.function
= challenge
->target_event
;
20 call
.id
= challenge
->target
;
21 entity_call( world
, &call
);
23 challenge
->status
= 1;
25 else if( call
->function
== 1 ){ /* view() */
26 if( (localplayer
.subsystem
== k_player_subsystem_walk
) &&
27 (world_static
.challenge_target
== NULL
) ){
28 world_static
.challenge_target
= NULL
;
29 world_entity_focus( call
->id
);
34 vg_error( "Unhandled function id: %u\n", call
->function
);
38 static void ent_challenge_preupdate( ent_challenge
*challenge
, int active
){
39 world_instance
*world
= world_current_instance();
41 /* maximum distance from active challenge */
43 f32 min_dist2
= 999999.9f
;
45 if( mdl_entity_id_type( challenge
->first
) == k_ent_objective
){
46 u32 next
= challenge
->first
;
47 while( mdl_entity_id_type(next
) == k_ent_objective
){
48 u32 index
= mdl_entity_id_id( next
);
49 ent_objective
*objective
= mdl_arritm(&world
->ent_objective
,index
);
50 next
= objective
->id_next
;
52 f32 d2
= v3_dist2( localplayer
.rb
.co
, objective
->transform
.co
);
58 f32 max_dist
= 100.0f
;
59 if( min_dist2
> max_dist
*max_dist
){
60 world_static
.challenge_target
= NULL
;
61 world_static
.challenge_timer
= 0.0f
;
62 world_static
.focused_entity
= 0;
63 audio_oneshot_3d( &audio_challenge
[6], localplayer
.rb
.co
,
69 if( mdl_entity_id_type( challenge
->camera
) == k_ent_camera
){
70 u32 index
= mdl_entity_id_id( challenge
->camera
);
71 ent_camera
*cam
= mdl_arritm( &world
->ent_camera
, index
);
73 /* TODO COMPRESSION */
74 v3f dir
= {0.0f
,-1.0f
,0.0f
};
75 mdl_transform_vector( &cam
->transform
, dir
, dir
);
76 m3x3_mulv( localplayer
.invbasis
, dir
, dir
);
77 player_vector_angles( world_static
.focus_cam
.angles
, dir
, 1.0f
, 0.0f
);
78 v3_copy( cam
->transform
.co
, world_static
.focus_cam
.pos
);
79 world_static
.focus_cam
.fov
= cam
->fov
;
82 /* TODO COMPRESSION */
83 v3_copy( localplayer
.cam
.pos
, world_static
.focus_cam
.pos
);
84 v3_copy( localplayer
.cam
.angles
, world_static
.focus_cam
.angles
);
85 world_static
.focus_cam
.fov
= localplayer
.cam
.fov
;
86 world_static
.focus_cam
.nearz
= localplayer
.cam
.nearz
;
87 world_static
.focus_cam
.farz
= localplayer
.cam
.farz
;
90 gui_helper_action( button_display_string( k_srbind_maccept
), "start" );
91 gui_helper_action( button_display_string( k_srbind_mback
), "exit" );
93 if( mdl_entity_id_type( challenge
->first
) == k_ent_objective
){
94 if( button_down( k_srbind_maccept
) ){
95 u32 index
= mdl_entity_id_id( challenge
->first
);
96 world_static
.challenge_target
= mdl_arritm( &world
->ent_objective
,
98 world_static
.challenge_timer
= 0.0f
;
99 world_entity_unfocus();
101 u32 next
= challenge
->first
;
102 while( mdl_entity_id_type(next
) == k_ent_objective
){
103 u32 index
= mdl_entity_id_id( next
);
104 ent_objective
*objective
= mdl_arritm(&world
->ent_objective
,index
);
105 objective
->flags
&= ~k_ent_objective_passed
;
106 next
= objective
->id_next
;
107 v3_fill( objective
->transform
.s
, 1.0f
);
109 audio_oneshot( &audio_challenge
[5], 1.0f
, 0.0f
);
114 if( button_down( k_srbind_mback
) ){
115 world_static
.challenge_target
= NULL
;
116 world_entity_unfocus();
117 audio_oneshot( &audio_challenge
[4], 1.0f
, 0.0f
);
122 static void ent_challenge_render( ent_challenge
*challenge
){
126 #endif /* ENT_CHALLENGE_C */