#include #include #include #ifdef __GNUC__ #include #include #endif #include #include #include #include "global.h" #include "elwindows.h" #include "keys.h" #include "loading_win.h" #include "update.h" #include "misc.h" #ifdef EYE_CANDY #include "eye_candy_wrapper.h" #endif //EYE_CANDY #define CFG_VERSION 7 // change this when critical changes to el.cfg are made that will break it #ifndef DATA_DIR #define DATA_DIR "./" #endif int ini_file_size=0; int disconnected= 1; #ifdef AUTO_UPDATE int auto_update= 1; #ifdef CUSTOM_UPDATE int custom_update= 0; #endif //CUSTOM_UPDATE #endif //AUTO_UPDATE int exit_now=0; int restart_required=0; int allow_restart=1; int have_url=0; char current_url[160]; char browser_name[120]; int poor_man=0; #ifdef ANTI_ALIAS int anti_alias=0; #endif //ANTI_ALIAS #ifdef SFX int special_effects=0; #endif //SFX int isometric=1; int mouse_limit=15; int no_adjust_shadows=0; int clouds_shadows=1; int item_window_on_drop=1; int compass_direction=1; int buddy_log_notice=1; char configdir[256]="./"; char datadir[256]=DATA_DIR; char lang[10]={"en"}; int video_mode_set=0; extern windows_info windows_list; typedef struct{ int id; char *fn; }e3d_list; e3d_list *e3dlist=NULL; int e3dlistsize=0; void read_command_line(); //from main.c void unload_e3d_list() { int i; for(i=0;i0) { if((quickbar_x=cfg_mem.quickbar_x)>window_width||quickbar_x<=0)quickbar_x=34; if((quickbar_y=cfg_mem.quickbar_y)>window_height||quickbar_y<=0)quickbar_y=64; if((quickbar_dir=cfg_mem.quickbar_flags&0xFF)!=HORIZONTAL)quickbar_dir=VERTICAL; if((quickbar_draggable=(cfg_mem.quickbar_flags&0xFF00)>>8)!=1)quickbar_draggable=0; } watch_this_stat=cfg_mem.watch_this_stat; if(watch_this_stat<0 || watch_this_stat>=NUM_WATCH_STAT) watch_this_stat=0; has_accepted=cfg_mem.has_accepted_rules; rx=cfg_mem.camera_x; ry=cfg_mem.camera_y; rz=cfg_mem.camera_z; new_zoom_level=zoom_level=cfg_mem.zoom_level; view_health_bar=cfg_mem.view_health_bar; view_names=cfg_mem.view_names; view_hp=cfg_mem.view_hp; quantities.selected=cfg_mem.quantity_selected; for(i=0;i<6;i++){ if(cfg_mem.quantity[i]){ quantities.quantity[i].val=cfg_mem.quantity[i]; safe_snprintf(quantities.quantity[i].str, sizeof(quantities.quantity[i].str),"%d", cfg_mem.quantity[i]); quantities.quantity[i].len=strlen(quantities.quantity[i].str); } } if(zoom_level != 0.0f) resize_root_window(); } void save_bin_cfg() { FILE *f = NULL; bin_cfg cfg_mem; char el_cfg[256]; int i; safe_snprintf(el_cfg, sizeof(el_cfg), "%sel.cfg", configdir); f=my_fopen(el_cfg,"wb"); if(!f)return;//blah, whatever memset(&cfg_mem, 0, sizeof(cfg_mem)); // make sure its clean cfg_mem.cfg_version_num=CFG_VERSION; // set the version number //good, retrive the data /* // TODO: move window save/restore into the window handler cfg_mem.items_menu_x=items_menu_x; cfg_mem.items_menu_y=items_menu_y; cfg_mem.ground_items_menu_x=ground_items_menu_x; cfg_mem.ground_items_menu_y=ground_items_menu_y; cfg_mem.trade_menu_x=trade_menu_x; cfg_mem.trade_menu_y=trade_menu_y; cfg_mem.sigil_menu_x=sigil_menu_x; cfg_mem.sigil_menu_y=sigil_menu_y; cfg_mem.dialogue_menu_x=dialogue_menu_x; cfg_mem.dialogue_menu_y=dialogue_menu_y; cfg_mem.manufacture_menu_x=manufacture_menu_x; cfg_mem.manufacture_menu_y=manufacture_menu_y; cfg_mem.attrib_menu_x=attrib_menu_x; cfg_mem.attrib_menu_y=attrib_menu_y; cfg_mem.elconfig_menu_x=elconfig_menu_x; cfg_mem.elconfig_menu_y=elconfig_menu_y; cfg_mem.knowledge_menu_x=knowledge_menu_x; cfg_mem.knowledge_menu_y=knowledge_menu_y; cfg_mem.encyclopedia_menu_x=encyclopedia_menu_x; cfg_mem.encyclopedia_menu_y=encyclopedia_menu_y; cfg_mem.questlog_menu_x=questlog_menu_x; cfg_mem.questlog_menu_y=questlog_menu_y; */ if(tab_help_win >= 0) { cfg_mem.tab_help_x=windows_list.window[tab_help_win].cur_x; cfg_mem.tab_help_y=windows_list.window[tab_help_win].cur_y; } else { cfg_mem.tab_help_x=tab_help_x; cfg_mem.tab_help_y=tab_help_y; } if(items_win >= 0) { cfg_mem.items_menu_x=windows_list.window[items_win].cur_x; cfg_mem.items_menu_y=windows_list.window[items_win].cur_y; } else { cfg_mem.items_menu_x=items_menu_x; cfg_mem.items_menu_y=items_menu_y; } if(ground_items_win >= 0) { cfg_mem.ground_items_menu_x=windows_list.window[ground_items_win].cur_x; cfg_mem.ground_items_menu_y=windows_list.window[ground_items_win].cur_y; } else { cfg_mem.ground_items_menu_x=ground_items_menu_x; cfg_mem.ground_items_menu_y=ground_items_menu_y; } if(trade_win >= 0) { cfg_mem.trade_menu_x=windows_list.window[trade_win].cur_x; cfg_mem.trade_menu_y=windows_list.window[trade_win].cur_y; } else { cfg_mem.trade_menu_x=trade_menu_x; cfg_mem.trade_menu_y=trade_menu_y; } if(sigil_win >= 0) { cfg_mem.sigil_menu_x=windows_list.window[sigil_win].cur_x; cfg_mem.sigil_menu_y=windows_list.window[sigil_win].cur_y; } else { cfg_mem.sigil_menu_x=sigil_menu_x; cfg_mem.sigil_menu_y=sigil_menu_y; } if(dialogue_win >= 0) { cfg_mem.dialogue_menu_x=windows_list.window[dialogue_win].cur_x; cfg_mem.dialogue_menu_y=windows_list.window[dialogue_win].cur_y; } else { cfg_mem.dialogue_menu_x=dialogue_menu_x; cfg_mem.dialogue_menu_y=dialogue_menu_y; } if(manufacture_win >= 0) { cfg_mem.manufacture_menu_x=windows_list.window[manufacture_win].cur_x; cfg_mem.manufacture_menu_y=windows_list.window[manufacture_win].cur_y; } else { cfg_mem.manufacture_menu_x=manufacture_menu_x; cfg_mem.manufacture_menu_y=manufacture_menu_y; } if(elconfig_win >= 0) { cfg_mem.elconfig_menu_x=windows_list.window[elconfig_win].cur_x; cfg_mem.elconfig_menu_y=windows_list.window[elconfig_win].cur_y; } else { cfg_mem.elconfig_menu_x=elconfig_menu_x; cfg_mem.elconfig_menu_y=elconfig_menu_y; } if(storage_win >= 0) { cfg_mem.storage_win_x=windows_list.window[storage_win].cur_x; cfg_mem.storage_win_y=windows_list.window[storage_win].cur_y; } else { cfg_mem.storage_win_x=storage_win_x; cfg_mem.storage_win_y=storage_win_y; } if(tab_stats_win >= 0) { cfg_mem.tab_stats_x=windows_list.window[tab_stats_win].cur_x; cfg_mem.tab_stats_y=windows_list.window[tab_stats_win].cur_y; } else { cfg_mem.tab_stats_x=tab_stats_x; cfg_mem.tab_stats_y=tab_stats_y; } if(buddy_win >= 0) { cfg_mem.buddy_menu_x=windows_list.window[buddy_win].cur_x; cfg_mem.buddy_menu_y=windows_list.window[buddy_win].cur_y; } else { cfg_mem.buddy_menu_x=buddy_menu_x; cfg_mem.buddy_menu_y=buddy_menu_y; } #ifdef MINIMAP if(minimap_win >= 0) { cfg_mem.minimap_win_x=windows_list.window[minimap_win].cur_x; cfg_mem.minimap_win_y=windows_list.window[minimap_win].cur_y; } else { cfg_mem.minimap_win_x=minimap_win_x; cfg_mem.minimap_win_y=minimap_win_y; } #endif //MINIMAP cfg_mem.view_health_bar=view_health_bar; cfg_mem.view_names=view_names; cfg_mem.view_hp=view_hp; cfg_mem.quantity_selected=quantities.selected; if(quickbar_relocatable>0) { if(quickbar_win >= 0){ cfg_mem.quickbar_x=window_width-windows_list.window[quickbar_win].cur_x; cfg_mem.quickbar_y=windows_list.window[quickbar_win].cur_y; cfg_mem.quickbar_flags=quickbar_dir|(quickbar_draggable<<8); } else { cfg_mem.quickbar_x=quickbar_x; cfg_mem.quickbar_y=quickbar_y; cfg_mem.quickbar_flags=VERTICAL; } } cfg_mem.watch_this_stat=watch_this_stat; cfg_mem.has_accepted_rules=has_accepted; cfg_mem.camera_x=rx; cfg_mem.camera_y=ry; cfg_mem.camera_z=rz; cfg_mem.zoom_level=zoom_level; for(i=0;i<6;i++){ cfg_mem.quantity[i]=quantities.quantity[i].val; } fwrite(&cfg_mem,sizeof(cfg_mem),1,f); fclose(f); } void init_texture_cache() { memset(texture_cache, 0, sizeof(texture_cache)); } void init_e3d_cache() { //cache_e3d= cache_init(1000, &destroy_e3d); //TODO: autofree the name as well cache_e3d= cache_init(1000, NULL); //no aut- free permitted cache_set_name(cache_system, "E3D cache", cache_e3d); cache_set_compact(cache_e3d, &free_e3d_va); // to compact, free VA arrays cache_set_time_limit(cache_e3d, 5*60*1000); cache_set_size_limit(cache_e3d, 8*1024*1024); } void init_2d_obj_cache() { memset(obj_2d_def_cache, 0, sizeof(obj_2d_def_cache)); } void init_stuff() { int seed; char file_name[250]; int i; //TODO: process command line options chdir(DATA_DIR); #ifdef WRITE_XML load_translatables();//Write to the current working directory - hopefully we'll have write rights here... #endif // initialize the text buffers init_text_buffers (); // XXX FIXME (Grum): actually this should only be done when windowed // chat is not used (which we don't know yet at this point), but let's // leave it here until we're certain that the chat channel buffers are // never used otherwise, then move it down till after the configuration // is read. init_chat_channels (); // initialize the fonts, but don't load the textures yet. Do that here // because the messages need the font widths. init_fonts(); //read the config file read_config(); //Parse command line options read_command_line(); options_set= 1; //OK, we have the video mode settings... setup_video_mode(full_screen,video_mode); //now you may set the video mode using the % in-game video_mode_set=1; //Good, we should be in the right working directory - load all translatables from their files load_translatables(); init_video(); //Init the caches here, as the loading window needs them cache_system_init(MAX_CACHE_SYSTEM); init_texture_cache(); init_e3d_cache(); init_2d_obj_cache(); //now load the font textures load_font_textures (); CHECK_GL_ERRORS(); init_colors(); // read the continent map info read_mapinfo(); // now create the root window // XXX FIXME (Grum): Maybe we should do this at a later time, after // we're logged in? create_game_root_window (window_width, window_height); create_console_root_window (window_width, window_height); create_map_root_window (window_width, window_height); create_login_root_window (window_width, window_height); //create the loading window create_loading_win (window_width, window_height, 0); show_window(loading_win); update_loading_win(init_opengl_str, 5); init_gl_extensions(); // Setup the new eye candy system #ifdef EYE_CANDY ec_init(); #endif //EYE_CANDY // check for invalid combinations check_options(); update_loading_win(init_random_str, 4); seed= time (NULL); srand(seed); update_loading_win(load_ignores_str, 1); load_ignores(); update_loading_win(load_filters_str, 2); load_filters(); update_loading_win(load_lists_str, 2); load_harvestable_list(); load_e3d_list(); load_entrable_list(); load_knowledge_list(); update_loading_win(load_cursors_str, 5); load_cursors(); build_cursors(); change_cursor(CURSOR_ARROW); update_loading_win(bld_glow_str, 3); build_glow_color_table(); update_loading_win(init_lists_str, 2); init_actors_lists(); update_loading_win(NULL, 4); memset(tile_list, 0, sizeof(tile_list)); memset(lights_list, 0, sizeof(lights_list)); #ifdef NEW_FRUSTUM main_bbox_tree = build_bbox_tree(); #endif init_particles_list(); update_loading_win(init_actor_defs_str, 4); memset(actors_defs, 0, sizeof(actors_defs)); init_actor_defs(); update_loading_win(load_map_tiles_str, 4); load_map_tiles(); update_loading_win(init_lights_str, 4); //lights setup build_global_light_table(); build_sun_pos_table(); reset_material(); init_lights(); disable_local_lights(); update_loading_win(init_logs_str, 5); clear_error_log(); clear_conn_log(); update_loading_win(read_config_str, 2); read_bin_cfg(); #ifndef NEW_WEATHER update_loading_win(init_weather_str, 3); init_weather(); // initialize the weather system #endif //NEW_WEATHER build_levels_table();//for some HUD stuff // Sound initialisation is done when loading the config and setting the no_sound/no_music variables // if(!no_sound || !no_music) { // update_loading_win(init_audio_str, 0); // init_sound(SOUND_CONFIG_PATH); // } update_loading_win(load_icons_str, 4); //load the necesary textures //font_text= load_texture_cache("./textures/font.bmp",0); #ifdef NEW_ALPHA icons_text= load_texture_cache("./textures/gamebuttons.bmp", -1); hud_text= load_texture_cache("./textures/gamebuttons2.bmp", -1); #else //NEW_ALPHA icons_text= load_texture_cache("./textures/gamebuttons.bmp",0); hud_text= load_texture_cache("./textures/gamebuttons2.bmp",0); #endif //NEW_ALPHA update_loading_win(load_textures_str, 4); cons_text= load_texture_cache("./textures/console.bmp",255); for(i=0; i