{
	menu_main(0);
	return;
	}
    }

fp=fopen("server.last","wt");
if(fp)
    {
    fputs(menu_server_ip,fp);
    fclose(fp);
    }

for(i=0;i<4;i++)
    game_state.scores[i]=DEFAULT_SCORE;

create_kart();
invin_time=0;
have_bonus=0;
boost_time=0;
weight_time=0;
oil_time=0;
replace_time=0;
in_game=1;
smoke_time=0;
game_over=0;
drop_bonus(0);
}


char draw_element_before(int elem)
{
int team;

if(is_kart(elem))
    {
    team=raydium_ode_element_tag_get(elem)-TAG_KART;
    raydium_rendering_rgb_force(TEAM_COL(team));
    }

return 1; // draw element
}

void draw_element_after(int elem)
{
raydium_rendering_rgb_normal();
}


void draw_game(void)
{
dReal speed,direct,accel,slip;
int i;

if(raydium_key_last==1027)
    exit(0); // too "hard"

if(raydium_ode_object_find("KART")<0)
    {
    in_game=0;
    raydium_camera_look_at(0.1,0.1,0,0,1,0);
    raydium_osd_color_ega('f');
    raydium_osd_draw_name("BOXfront.tga",0,100,100,0);
    }
else
    {
    in_game=1;
    
    raydium_joy_key_emul();

    if(game_over)
	{
	raydium_joy_x=raydium_joy_y=raydium_key_last=0;
	}
        
    if(raydium_key_last==1032)
	bonus_fire();

    if(replace_time>REPLACE_TIME)
	{
	create_kart();
	replace_time=0;
	}

    speed=direct=0;
    accel=0.03;

    if(oil_time>0)
	slip=RAYDIUM_ODE_SLIP_ICE;
    else
	slip=RAYDIUM_ODE_SLIP_DEFAULT;

    raydium_ode_element_slip_name("kart_pneu_ag",slip);
    raydium_ode_element_slip_name("kart_pneu_ad",slip);
    raydium_ode_element_slip_name("kart_pneu_rg",slip);
    raydium_ode_element_slip_name("kart_pneu_rd",slip);
    
    if(raydium_joy_y>0.3 || raydium_key[GLUT_KEY_INSERT]) // "insert" is a hack
	{
        speed=raydium_joy_y*25;
	if(boost_time>0) 
	    {
	    speed*=2;
	    accel*=2;
	    }

	if(weight_time>0) 
	    {
	    speed/=2;
	    accel/=2;
	    }
	raydium_ode_motor_power_max_name("kart_moteur",accel);
	raydium_ode_motor_power_max_name("kart_frein",0);
	}
    else
	{
	raydium_ode_motor_power_max_name("kart_moteur",0);
	raydium_ode_motor_power_max_name("kart_frein",0.1 * -raydium_joy_y);
	}

    direct=raydium_joy_x*0.3;
    
    if(raydium_key[GLUT_KEY_END])
	raydium_ode_element_camera_inboard_name("kart_corps",-0.15,0,0.07,-2,0,0);
    else
	raydium_ode_element_camera_inboard_name("kart_corps",0,0,0.15,2,0,0);

    raydium_ode_motor_speed_name("kart_moteur",-speed);
    raydium_ode_motor_angle_name("kart_direction",direct);
    speed=raydium_ode_motor_speed_get_name("kart_moteur",1);
    speed*=0.1; // wheel radius
    speed/=2;
    speed+=0.5; // lower speed
    speed=raydium_trigo_abs(speed);
    if(speed>2) speed=2;
    raydium_sound_SetSourcePitch(sounds[SOUND_ENGINE],speed);
    raydium_ode_element_sound_update_name("kart_corps",sounds[SOUND_ENGINE]);
    
    raydium_ode_draw_all(0);
    //raydium_ode_draw_all(1);
    manage_bonus();
    
    // Here, we test scores <=0 !
    for(i=0;i<4;i++)
	{
	raydium_osd_color_change(TEAM_COL(i));
	if(game_state.scores[i]<=0)
	    {
	    raydium_osd_printf(30,60-(i*5),30,0.5,"font2.tga","%s looses !",teams[i].name);
	    game_over=1;
	    }
	}	
    }
raydium_ode_network_element_send_iterative(RAYDIUM_ODE_NETWORK_OPTIMAL);
}

void display(void)
{
int i;

raydium_background_color_change(sun[0],sun[1],sun[2],sun[3]);
raydium_light_position[0][0]=50;
raydium_light_position[0][1]=150;
raydium_light_position[0][2]=200;
raydium_light_position[0][3]=1.0;

raydium_clear_frame();
glLoadIdentity();

draw_game();

if(menu) MenuItem_draw();

for(i=0;i<4;i++)
    {
    raydium_osd_color_change(TEAM_COL(i));
    raydium_osd_printf(2,90-(i*5),20,0.5,"font2.tga","%s: %i",teams[i].name,game_state.scores[i]);
    }    

raydium_osd_printf(90,2,20,0.4,"font2.tga","^c%i FPS",raydium_render_fps);
//raydium_osd_network_stat_draw(5,5,10);
raydium_osd_logo("logo.tga");
raydium_rendering_finish();
}

int main(int argc, char **argv)
{
raydium_init_args(argc,argv);
raydium_window_create(800,600,RAYDIUM_RENDERING_WINDOW,version);
raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_TRILINEAR);
raydium_projection_near=0.05;
raydium_projection_far=1000;
raydium_projection_fov=70;
raydium_fog_disable();
raydium_light_on(0);
memcpy(raydium_light_color[0],sun,raydium_internal_size_vector_float_4);
raydium_light_intensity[0]=1000000;
raydium_light_update_all(0);

memcpy(raydium_light_color[1],amb,raydium_internal_size_vector_float_4);
raydium_light_intensity[1]=10000;
raydium_light_update_all(1);
raydium_window_view_update();

strcpy(raydium_console_config_texture,"logo_console.tga");
raydium_osd_cursor_set("BOXcursor.tga",4,4);
raydium_sky_box_cache();

conf_init();
bonus_init();
sound_init();
menu_main(0);
net_init();

raydium_timecall_add(frame_step,-1);
raydium_ode_ground_set_name("laby1.tri");
raydium_ode_CollideCallback=collide;
raydium_ode_ExplosionCallback=explo;
raydium_ode_BeforeElementDrawCallback=draw_element_before;
raydium_ode_AfterElementDrawCallback=draw_element_after;

//raydium_ode_element_slip_name("ground",RAYDIUM_ODE_SLIP_ICE/5.f);

raydium_callback(&display);
return 0;
}