yed
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
index 529fdefcccfcf2bfbf416fdb6c94e264b290829a..56e6e4b6c8bbae9dbcb50e3208a845668385366e 100644 (file)
@@ -14,6 +14,7 @@
 #include "font.h"
 #include "pointcloud.h"
 #include "gui.h"
+#include "steam.h"
 
 #include "shaders/scene_route.h"
 #include "shaders/routeui.h"
@@ -21,7 +22,7 @@
 
 VG_STATIC 
 void world_routes_local_set_record( world_instance *world, ent_route *route,
-                                    double lap_time )
+                                    f64 lap_time )
 {
    vg_success( "  NEW LAP TIME: %f\n", lap_time );
 
@@ -30,25 +31,18 @@ void world_routes_local_set_record( world_instance *world, ent_route *route,
       if( time_centiseconds > (float)0xfffe )   /* skill issue */
          return;
 
-      highscore_record temp;
-      temp.trackid  = route->official_track_id;
-      temp.datetime = time(NULL);
-      temp.playerid = 0;
-      temp.points   = 0;
-      temp.time     = time_centiseconds;
-
-#if 0
-      highscores_push_record( &temp );
-#endif
-
       struct track_info *ti = &track_infos[ route->official_track_id ];
+      highscore_record *record = &ti->record;
+      record->trackid  = route->official_track_id;
+      record->datetime = time(NULL);
+      record->playerid = 0;
+      record->points   = 0;
+      record->time     = time_centiseconds;
       ti->push = 1;
       
       if( ti->achievement_id ){
-#if 0
          steam_set_achievement( ti->achievement_id );
          steam_store_achievements();
-#endif
       }
    }
    else{
@@ -773,6 +767,33 @@ VG_STATIC void world_routes_surface_grid( world_instance *world,
    }
 }
 
+VG_STATIC void world_write_preview( pointcloud_buffer *pcbuf ){
+   char path_buf[4096];
+   vg_str path;
+   vg_strnull( &path, path_buf, 4096 );
+
+   if( world_loader.reg ){
+      /* Don't want to override the one we get from the workshop */
+      if( world_loader.reg->workshop_id ) return;
+
+      addon_get_content_folder( world_loader.reg, &path );
+   }
+   else{
+      vg_strcat( &path, "maps/" );
+      vg_strcat( &path, world_loader.override_name );
+   }
+
+   vg_strcat( &path, "/preview.bin" );
+
+   if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
+   FILE *fp = fopen( path_buf, "wb" );
+   if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf );
+   
+   fwrite( pcbuf, sizeof(struct pointcloud_buffer) + 
+                  sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
+   fclose( fp );
+}
+
 /* 
  * Create the strips of colour that run through the world along course paths
  */
@@ -867,23 +888,7 @@ VG_STATIC void world_gen_routes_generate(void)
       vg_info( "Distrubuted %u points over %fkm^2!\n", 
                 pcbuf->count, area/1e6f );
 
-      if( world_loader.location == k_world_load_type_local ){
-         char path_buf[4096];
-         vg_str path;
-         vg_strnull( &path, path_buf, 4096 );
-         vg_strcat( &path, "maps/" );
-         vg_strcat( &path, world_loader.name );
-         vg_strcat( &path, "/preview.bin" );
-
-         if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
-         FILE *fp = fopen( path_buf, "wb" );
-         if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf );
-         
-         fwrite( pcbuf, sizeof(pcbuf) + 
-                        sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
-         fclose( fp );
-      }
-
+      world_write_preview( pcbuf );
       vg_async_dispatch( call_pointcloud, async_pointcloud_sub );
    }