custom walk filtering
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_challenge.c
index 5f22eaaedf9f724b495a9069cc61896a807c4674..b01e4902e20b49b901ade4ebb51ada83da720d67 100644 (file)
@@ -20,6 +20,47 @@ VG_STATIC void ent_challenge_pass( world_instance *world,
       vg_success( "NYU Film school graduate SUCKAH\n" );
       world->challenge_target = NULL;
       world->challenge_timer = 0.0f;
+
+      if( challenge->id_win ){
+         ent_call call;
+         call.data = NULL;
+         call.function = challenge->win_event;
+         call.id = challenge->id_win;
+         entity_call( world, &call );
+      }
+   }
+}
+
+VG_STATIC int ent_challenge_check_filter( ent_challenge *challenge ){
+   if( challenge->filter ){
+      struct player_skate_state *s = &localplayer._skate.state;
+      enum trick_type trick = s->trick_type;
+
+      u32 state = 0x00;
+
+      if( trick == k_trick_type_shuvit ) 
+         state |= k_ent_challenge_filter_trick_shuvit;
+      if( trick == k_trick_type_treflip )
+         state |= k_ent_challenge_filter_trick_treflip;
+      if( trick == k_trick_type_kickflip )
+         state |= k_ent_challenge_filter_trick_kickflip;
+      
+      if( s->flip_rate < -0.0001f ) state |= k_ent_challenge_filter_flip_back;
+      if( s->flip_rate >  0.0001f ) state |= k_ent_challenge_filter_flip_front;
+
+      if( s->activity == k_skate_activity_grind_5050 ||
+          s->activity == k_skate_activity_grind_back50 ||
+          s->activity == k_skate_activity_grind_front50 ) 
+         state |= k_ent_challenge_filter_grind_truck_any;
+
+      if( s->activity == k_skate_activity_grind_boardslide )
+         state |= k_ent_challenge_filter_grind_board_any;
+
+      return ((challenge->filter  & state) || !challenge->filter) && 
+             ((challenge->filter2 & state) || !challenge->filter2);
+   }
+   else {
+      return 1;
    }
 }
 
@@ -28,8 +69,11 @@ VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ){
    ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
 
    if( call->function == 0 ){
+      if( challenge->flags & k_ent_challenge_hidden ) return;
+
       if( world->challenge_target ){
-         if( world->challenge_target == challenge ){
+         if( (world->challenge_target == challenge) && 
+              ent_challenge_check_filter( challenge )){
             ent_challenge_pass( world, challenge );
          }
          else {
@@ -40,10 +84,18 @@ VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ){
       }
    }
    else if( call->function == 1 ){
+      if( challenge->flags & k_ent_challenge_hidden ) return;
+
       vg_info( "begin the challenge\n" );
       world->challenge_timer = 0.0f;
       ent_challenge_pass( world, challenge );
    }
+   else if( call->function == 2 ){
+      challenge->flags &= ~k_ent_challenge_hidden;
+   }
+   else if( call->function == 3 ){
+      challenge->flags |=  k_ent_challenge_hidden;
+   }
    else {
       vg_print_backtrace();
       vg_error( "Unhandled function id: %u\n", call->function );