From bd3a7e904be0fc97e70761cc957a28609d366586 Mon Sep 17 00:00:00 2001 From: hgn Date: Sun, 13 Aug 2023 11:32:03 +0100 Subject: [PATCH] deactivate challenge on max dist --- ent_challenge.c | 30 +++++++++++++++++++++++++++++- ent_challenge.h | 2 +- ent_objective.c | 3 ++- ent_skateshop.c | 4 +++- ent_skateshop.h | 2 +- world_entity.c | 9 ++------- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/ent_challenge.c b/ent_challenge.c index 73476c7..e6c543b 100644 --- a/ent_challenge.c +++ b/ent_challenge.c @@ -35,9 +35,37 @@ VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ){ } } -VG_STATIC void ent_challenge_preupdate( ent_challenge *challenge ){ +VG_STATIC void ent_challenge_preupdate( ent_challenge *challenge, int active ){ world_instance *world = world_current_instance(); + /* maximum distance from active challenge */ + if( !active ){ + f32 min_dist2 = 999999.9f; + + if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){ + u32 next = challenge->first; + while( mdl_entity_id_type(next) == k_ent_objective ){ + u32 index = mdl_entity_id_id( next ); + ent_objective *objective = mdl_arritm(&world->ent_objective,index); + next = objective->id_next; + + f32 d2 = v3_dist2( localplayer.rb.co, objective->transform.co ); + if( d2 < min_dist2 ) + min_dist2 = d2; + } + } + + f32 max_dist = 100.0f; + if( min_dist2 > max_dist*max_dist ){ + world_static.challenge_target = NULL; + world_static.challenge_timer = 0.0f; + world_static.focused_entity = 0; + audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, + 30.0f, 1.0f ); + } + return; + } + if( mdl_entity_id_type( challenge->camera ) == k_ent_camera ){ u32 index = mdl_entity_id_id( challenge->camera ); ent_camera *cam = mdl_arritm( &world->ent_camera, index ); diff --git a/ent_challenge.h b/ent_challenge.h index 01068e8..0d185f9 100644 --- a/ent_challenge.h +++ b/ent_challenge.h @@ -3,7 +3,7 @@ #include "entity.h" -VG_STATIC void ent_challenge_preupdate( ent_challenge *challenge ); +VG_STATIC void ent_challenge_preupdate( ent_challenge *challenge, int active ); VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ); #endif /* ENT_CHALLENGE_H */ diff --git a/ent_objective.c b/ent_objective.c index ee52af7..c037eaf 100644 --- a/ent_objective.c +++ b/ent_objective.c @@ -89,9 +89,10 @@ VG_STATIC void ent_objective_call( world_instance *world, ent_call *call ){ else { audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f ); - vg_error( "challenge fialed\n" ); + vg_error( "challenge failed\n" ); world_static.challenge_target = NULL; world_static.challenge_timer = 0.0f; + world_static.focused_entity = 0; } } } diff --git a/ent_skateshop.c b/ent_skateshop.c index 56d8c01..2815482 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -163,7 +163,9 @@ VG_STATIC void skateshop_load_world_preview( addon_reg *reg ){ * VG event preupdate */ void temp_update_playermodel(void); -VG_STATIC void ent_skateshop_preupdate( ent_skateshop *shop ){ +VG_STATIC void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ + if( !active ) return; + /* input filter */ world_instance *world = world_current_instance(); diff --git a/ent_skateshop.h b/ent_skateshop.h index 23e43c0..e12edb1 100644 --- a/ent_skateshop.h +++ b/ent_skateshop.h @@ -41,7 +41,7 @@ struct{ } static global_skateshop={.render={.reg_id=0xffffffff,.world_reg=0xffffffff}}; -VG_STATIC void ent_skateshop_preupdate( ent_skateshop *shop ); +VG_STATIC void ent_skateshop_preupdate( ent_skateshop *shop, int active ); VG_STATIC void skateshop_render( ent_skateshop *shop ); #endif /* ENT_SKATESHOP_H */ diff --git a/world_entity.c b/world_entity.c index 82c9723..67db6af 100644 --- a/world_entity.c +++ b/world_entity.c @@ -39,22 +39,17 @@ VG_STATIC void world_entity_focus_preupdate(void){ vg_slewf( &world_static.focus_strength, active, vg.time_frame_delta * (1.0f/0.5f) ); - if( !active ) return; - u32 type = mdl_entity_id_type( world_static.focused_entity ), index = mdl_entity_id_id( world_static.focused_entity ); world_instance *world = world_current_instance(); if( type == k_ent_skateshop ){ ent_skateshop *skateshop = mdl_arritm( &world->ent_skateshop, index ); - ent_skateshop_preupdate( skateshop ); + ent_skateshop_preupdate( skateshop, active ); } else if( type == k_ent_challenge ){ ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index ); - ent_challenge_preupdate( challenge ); - } - else { - vg_fatal_error( "Programming error\n" ); + ent_challenge_preupdate( challenge, active ); } } -- 2.25.1