deactivate challenge on max dist
authorhgn <hgodden00@gmail.com>
Sun, 13 Aug 2023 10:32:03 +0000 (11:32 +0100)
committerhgn <hgodden00@gmail.com>
Sun, 13 Aug 2023 10:32:03 +0000 (11:32 +0100)
ent_challenge.c
ent_challenge.h
ent_objective.c
ent_skateshop.c
ent_skateshop.h
world_entity.c

index 73476c718bd6baaad23dcdc5d230fa6d6efc8765..e6c543b2163a37f673b4f1e67fd7c53cc283a303 100644 (file)
@@ -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 );
index 01068e8f888873ee8d4c52a0708d47a5ae4e03bf..0d185f9958a3518883d74169be34cc6e1334860d 100644 (file)
@@ -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 */
index ee52af7518ff12062a82380925cca437e57a1bb9..c037eaf5cbb5cb5afe1d55527a5c4c59317cc341 100644 (file)
@@ -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;
          }
       }
    }
index 56d8c01fe8557bcde628799fde5cb8c3d377f988..281548248c472b4fdf386b522eb273088065be5e 100644 (file)
@@ -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();
 
index 23e43c07fb2f6196eaa2b5cfca78822ccd556431..e12edb10de9830352fdaf3e4f99280d1ee9914a0 100644 (file)
@@ -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 */
index 82c9723f90c6459565bd7d0b2b80ed0eb14660b1..67db6afb16641465a64e94831db671aca465c0e5 100644 (file)
@@ -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 );
    }
 }