Make challenges have a check before calling
authorhgn <hgodden00@gmail.com>
Tue, 25 Feb 2025 13:21:19 +0000 (13:21 +0000)
committerhgn <hgodden00@gmail.com>
Tue, 25 Feb 2025 13:21:19 +0000 (13:21 +0000)
src/ent_challenge.c

index 0d68dfbd1ce0292f2b82b93e4e59ede17d973049..c7d5bdcafc0eccfe79d1847b26d9caa250dda8e8 100644 (file)
@@ -4,6 +4,22 @@
 #include "gui.h"
 #include "audio.h"
 
+static bool ent_challenge_is_acceptable( world_instance *world, u32 challenge_index )
+{
+   ent_challenge *challenge = af_arritm( &world->ent_challenge, challenge_index );
+
+   if( challenge->flags & k_ent_challenge_is_story )
+   {
+      struct script_info *script = world->events[ challenge_index ].story_script;
+      if( script->viewed_time || !script->availible )
+      {
+         return 0;
+      }
+   }
+
+   return 1;
+}
+
 entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
 {
    u32 index = mdl_entity_id_id( call->id );
@@ -27,14 +43,17 @@ entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
    {
       if( localplayer.subsystem == k_player_subsystem_walk )
       {
-         if( world_set_event( k_world_event_challenge ) )
+         if( ent_challenge_is_acceptable( world, index ) )
          {
-            _world.challenge_state = k_challenge_state_none;
-            _world.active_challenge_id = call->id;
-            gui_helper_reset( 1 );
-            vg_str text;
-            if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
-               vg_strcat( &text, (challenge->flags & k_ent_challenge_is_story)? "Play video": "View Challenge" );
+            if( world_set_event( k_world_event_challenge ) )
+            {
+               _world.challenge_state = k_challenge_state_none;
+               _world.active_challenge_id = call->id;
+               gui_helper_reset( 1 );
+               vg_str text;
+               if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
+                  vg_strcat( &text, (challenge->flags & k_ent_challenge_is_story)? "Play video": "View Challenge" );
+            }
          }
       }
 
@@ -44,11 +63,14 @@ entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
    {
       if( _world.challenge_state != k_challenge_state_running )
       {
-         if( world_clear_event( k_world_event_challenge ) )
+         if( ent_challenge_is_acceptable( world, index ) )
          {
-            _world.challenge_state = k_challenge_state_none;
-            _world.active_challenge_id = 0;
-            gui_helper_reset( k_gui_helper_mode_clear );
+            if( world_clear_event( k_world_event_challenge ) )
+            {
+               _world.challenge_state = k_challenge_state_none;
+               _world.active_challenge_id = 0;
+               gui_helper_reset( k_gui_helper_mode_clear );
+            }
          }
       }
       return k_entity_call_result_OK;