+ for( int i=0; i<route->checkpoints_count; i++ ){
+ int i0 = route->checkpoints_start+i,
+ i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
+
+ ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
+ *c1 = mdl_arritm(&world->ent_checkpoint, i1);
+
+ ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
+ start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
+
+ ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index ),
+ *collector = mdl_arritm( &world->ent_gate, end_gate->target );
+
+ v4f p[3];
+
+ v3_add( (v3f){0.0f,0.1f,0.0f}, start_gate->co[0], p[0] );
+ p[0][3] = start_gate->ref_count;
+ p[0][3] -= (float)start_gate->route_count * 0.5f;
+ start_gate->ref_count ++;
+
+ if( !c0->path_count )
+ continue;
+
+ /* this is so that we get nice flow through the gates */
+ v3f temp_alignments[2];
+ ent_gate *both[] = { start_gate, end_gate };
+
+ for( int j=0; j<2; j++ ){
+ int pi = c0->path_start + ((j==1)? c0->path_count-1: 0);
+
+ ent_path_index *index = mdl_arritm( &world->ent_path_index, pi );
+ ent_route_node *rn = mdl_arritm( &world->ent_route_node,
+ index->index );
+ v3f v0;
+ v3_sub( rn->co, both[j]->co[0], v0 );
+ float d = v3_dot( v0, both[j]->to_world[2] );
+
+ v3_muladds( both[j]->co[0], both[j]->to_world[2], d,
+ temp_alignments[j] );
+ v3_add( (v3f){0.0f,0.1f,0.0f}, temp_alignments[j], temp_alignments[j]);
+ }
+
+
+ for( int j=0; j<c0->path_count; j ++ ){
+ ent_path_index *index = mdl_arritm( &world->ent_path_index,
+ c0->path_start+j );
+ ent_route_node *rn = mdl_arritm( &world->ent_route_node,
+ index->index );
+ if( j==0 || j==c0->path_count-1 )
+ if( j == 0 )
+ v3_copy( temp_alignments[0], p[1] );
+ else
+ v3_copy( temp_alignments[1], p[1] );
+ else
+ v3_copy( rn->co, p[1] );
+
+ p[1][3] = rn->ref_count;
+ p[1][3] -= (float)rn->ref_total * 0.5f;
+ rn->ref_count ++;
+
+ if( j+1 < c0->path_count ){
+ index = mdl_arritm( &world->ent_path_index,
+ c0->path_start+j+1 );
+ rn = mdl_arritm( &world->ent_route_node, index->index );
+
+ if( j+1 == c0->path_count-1 )
+ v3_lerp( p[1], temp_alignments[1], 0.5f, p[2] );
+ else
+ v3_lerp( p[1], rn->co, 0.5f, p[2] );
+
+ p[2][3] = rn->ref_count;
+ p[2][3] -= (float)rn->ref_total * 0.5f;
+ }
+ else{
+ v3_copy( end_gate->co[0], p[2] );
+ v3_add( (v3f){0.0f,0.1f,0.0f}, p[2], p[2] );
+ p[2][3] = collector->ref_count;
+
+ if( i == route->checkpoints_count-1)
+ p[2][3] -= 1.0f;
+
+ p[2][3] -= (float)collector->route_count * 0.5f;
+ //collector->ref_count ++;
+ }
+
+ /* p0,p1,p2 bezier patch is complete
+ * --------------------------------------*/
+ v3f surf0, surf2, n0, n2;
+
+ if( bh_closest_point( world->geo_bh, p[0], surf0, 5.0f ) == -1 )
+ v3_add( (v3f){0.0f,-0.1f,0.0f}, p[0], surf0 );
+
+ if( bh_closest_point( world->geo_bh, p[2], surf2, 5.0f ) == -1 )
+ v3_add( (v3f){0.0f,-0.1f,0.0f}, p[2], surf2 );
+
+ v3_sub( surf0, p[0], n0 );
+ v3_sub( surf2, p[2], n2 );
+ v3_normalize( n0 );
+ v3_normalize( n2 );
+
+ world_routes_place_curve( world, route, p, n0, n2, sc, pcbuf );
+
+ /* --- */
+ v4_copy( p[2], p[0] );
+ }
+ }
+
+ scene_copy_slice( sc, &route->sm );