rework scene format
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
index 3501c72b5d0e39b6c2f9acb434154da38b0816a9..bd7304dc614550c8978345c08cce9fb893a363ae 100644 (file)
--- a/player.h
+++ b/player.h
@@ -66,15 +66,49 @@ static void player_transform_update(void)
 
 static int reset_player( int argc, char const *argv[] )
 {
-   v3_copy( world.tutorial, player.co );
-   if( argc == 1 )
+   struct respawn_point *rp = NULL, *r;
+
+   if( argc > 1 )
    {
-      if( !strcmp( argv[0], "tutorial" ))
-         v3_copy( world.tutorial, player.co );
+      for( int i=0; i<world.spawn_count; i++ )
+      {
+         r = &world.spawns[i];
+         if( !strcmp( r->name, argv[0] ) )
+         {
+            rp = r;
+            break;
+         }
+      }
+
+      if( !rp )
+         vg_warn( "No spawn named '%s'\n", argv[0] );
    }
 
-   v3_copy( (v3f){ 0.0f, 0.0f, -0.2f }, player.v );
-   q_identity( player.rot );
+   if( !rp )
+   {
+      float min_dist = INFINITY;
+      for( int i=0; i<world.spawn_count; i++ )
+      {
+         r = &world.spawns[i];
+         float d = v3_dist2( r->co, player.co );
+
+         if( d < min_dist )
+         {
+            min_dist = d;
+            rp = r;
+         }
+      }
+   }
+
+   if( !rp )
+   {
+      vg_error( "No spawn found\n" );
+      return 0;
+   }
+
+   v4_copy( r->q, player.rot );
+   v3_copy( r->co, player.co );
+
    player.vswitch = 1.0f;
    player.slip_last = 0.0f;
    player.is_dead = 0;
@@ -85,7 +119,8 @@ static int reset_player( int argc, char const *argv[] )
    player.mdl.shoes[1] = 1;
 
    player_transform_update();
-   return 0;
+   m3x3_mulv( player.to_world, (v3f){ 0.0f, 0.0f, -0.2f }, player.v );
+   return 1;
 }
 
 static void player_mouseview(void)
@@ -597,7 +632,7 @@ static void player_do_motion(void)
 
 static int player_walkgrid_tri_walkable( u32 tri[3] )
 {
-   return tri[0] < world.sm_road.vertex_count;
+   return tri[0] < world.sm_surface.vertex_count;
 }
 
 #define WALKGRID_SIZE 16