Esempio n. 1
0
void load_recipes (){
	char fname[128];
	FILE *fp;

	init_recipe_names();

	if (recipes_loaded) {
		/*
		 * save existing recipes instead of loading them if we are already logged in
		 * this will take place when relogging after disconnection
		 */
		save_recipes();
		return;
	}

	recipes_loaded=1;
	memset (recipes, 0, sizeof (recipes));

	safe_snprintf(fname, sizeof(fname), "recipes_%s.dat",username_str);
	my_tolower(fname);
	fp = open_file_config(fname,"rb");
	if(fp == NULL){
		LOG_ERROR("%s: %s \"%s\"\n", reg_error_str, cant_open_file, fname);
		return;
	}

	if (fread (recipes,sizeof(recipes),1, fp) != 1)
		LOG_ERROR("%s() read failed for file [%s]\n", __FUNCTION__, fname);
	fclose (fp);

	load_recipe_names();
}
Esempio n. 2
0
static int recipe_controls_click_handler(int mx, int my, Uint32 flags){

	int wpx=SLOT_SIZE*NUM_MIX_SLOTS+2;
	int wpy=manufacture_menu_y_len-37;
	int lpx=18;
	int lpy=SLOT_SIZE;

	if (mx>wpx&&mx<wpx+lpx&&my>wpy+lpy-10&&my<wpy+lpy){
		//arrow
		if (flags & ELW_WHEEL_UP) {
			cur_recipe=(cur_recipe-1+num_recipe_entries)%num_recipe_entries;
			use_recipe(cur_recipe);
		} else
		if (flags & ELW_WHEEL_DOWN) {
			cur_recipe=(cur_recipe+1)%num_recipe_entries;
			use_recipe(cur_recipe);
		} else {
			//normal click
			toggle_recipe_window();
		}

		build_manufacture_list();
		do_click_sound();
	} else
	if (mx>wpx+3&&mx<wpx+lpx-3&&my>wpy&&my<wpy+15){
		//+ button
		copy_recipe_from_manu_list(recipes_store[cur_recipe].items);
		clear_recipe_name(cur_recipe);
		build_manufacture_list();
		do_click_sound();
		// save recipes to disk to avoid loss on disconnects/crashes
		save_recipes();
	}
	return 0;
}
Esempio n. 3
0
int save_local_data(char * text, int len){
	save_bin_cfg();
	//Save the quickbar spells
	save_quickspells();
	//Save recipes
	save_recipes();
	// save el.ini if asked
	if (write_ini_on_exit) write_el_ini ();
	// save notepad contents if the file was loaded
	if (notepad_loaded) notepad_save_file();
	save_exploration_map();
	flush_counters();
	// for the new questlog, this actually just saves any pending changes
	// should be renamed when NEW_QUESTLOG #def is removed
	unload_questlog();
	save_item_lists();
	LOG_TO_CONSOLE(c_green1, "Local files saved, asking server to save too...");
	return 0;
}
Esempio n. 4
0
int recipe_controls_click_handler(int mx, int my, Uint32 flags){

	int i;
	int wpx=33*6+2;
	int wpy=manufacture_menu_y_len-37;
	int lpx=18;
	int lpy=33;	

	if (mx>wpx&&mx<wpx+lpx&&my>wpy+lpy-10&&my<wpy+lpy){
		//arrow
		if (flags & ELW_WHEEL_UP) {
			cur_recipe=(cur_recipe-1+SHOW_MAX_RECIPE)%SHOW_MAX_RECIPE;			
			use_recipe(cur_recipe);
		} else
		if (flags & ELW_WHEEL_DOWN) {
			cur_recipe=(cur_recipe+1)%SHOW_MAX_RECIPE;			
			use_recipe(cur_recipe);
		} else {
			//normal click	
			recipes_shown=!recipes_shown;
		}
		
		build_manufacture_list();
		if (recipes_shown) show_window(recipe_win);
		else hide_window(recipe_win);
		do_click_sound();
	} else
	if (mx>wpx+3&&mx<wpx+lpx-3&&my>wpy&&my<wpy+15){
		//+ button
		//copy the recipe
		for(i=36;i<36+6;i++)
			recipes[cur_recipe][i-36]=manufacture_list[i];
		clear_recipe_name(cur_recipe);
		build_manufacture_list();
		do_click_sound();
		// save recipes to disk to avoid loss on disconnects/crashes
		save_recipes();
	}
	return 0;
}
Esempio n. 5
0
static int recipe_controls_click_handler(window_info *win, int mx, int my, Uint32 flags){

	int wpx=pipeline_x + SLOT_SIZE*NUM_MIX_SLOTS;
	int wpy=manufacture_menu_y_len-recipe_y_offset;
	int lpx=PIPE_CONTROL_X;
	int lpy=SLOT_SIZE;

	if (!recipes_loaded)
		return 0;

	if (mx>wpx && mx<wpx+lpx && my>wpy+lpy-control_elem_size*2 && my<wpy+lpy){
		//arrow
		if (flags & ELW_WHEEL_UP) {
			cur_recipe=(cur_recipe-1+num_recipe_entries)%num_recipe_entries;
			use_recipe(cur_recipe);
		} else
		if (flags & ELW_WHEEL_DOWN) {
			cur_recipe=(cur_recipe+1)%num_recipe_entries;
			use_recipe(cur_recipe);
		} else {
			//normal click
			toggle_recipe_window();
		}

		build_manufacture_list();
		do_click_sound();
	} else
	if (mx>wpx+win->small_font_len_x/2 && mx<wpx+lpx-win->small_font_len_x/2 && my>wpy && my<wpy+win->small_font_len_y){
		//+ button
		copy_recipe_from_manu_list(recipes_store[cur_recipe].items);
		clear_recipe_name(cur_recipe);
		build_manufacture_list();
		do_click_sound();
		// save recipes to disk to avoid loss on disconnects/crashes
		save_recipes();
	}
	return 0;
}
Esempio n. 6
0
/* load recipes, done just after login when we have the player name */
void load_recipes (){
	char fname[128];
	FILE *fp;
	size_t i;
	int logged = 0;
	off_t file_size;
	const size_t recipe_size = sizeof(item)*NUM_MIX_SLOTS;

	if (recipes_loaded) {
		/*
		 * save existing recipes instead of loading them if we are already logged in
		 * this will take place when relogging after disconnection
		 */
		save_recipes();
		save_recipe_names();
		return;
	}

	safe_snprintf(fname, sizeof(fname), "recipes_%s.dat",get_lowercase_username());

	/* get file length, if a valid length adjust the number of recipe slots if required */
	file_size = get_file_size_config(fname);
	if ((file_size > 0) && (file_size % recipe_size == 0))
	{
		int num_recipes_in_file = file_size / recipe_size - 1; // -1 as last is current in pipline
		if ((num_recipes_in_file > wanted_num_recipe_entries) && (num_recipes_in_file < max_num_recipe_entries))
		{
			wanted_num_recipe_entries = num_recipes_in_file;
			set_var_OPT_INT("wanted_num_recipe_entries", wanted_num_recipe_entries);
		}
	}

	/* allocate and initialise the recipe store */
	num_recipe_entries = max_prev_num_recipe_entries = wanted_num_recipe_entries;
	recipes_store = (recipe_entry *)calloc(num_recipe_entries, sizeof(recipe_entry));
	if (recipes_store == NULL)
	{
		max_prev_num_recipe_entries = num_recipe_entries = 0;
		return;
	}
	recipes_loaded=1;
	init_recipe_names();

	/* if the file exists but is not a valid size, don't use it */
	if ((file_size > 0) && (file_size % recipe_size != 0))
	{
		LOG_ERROR("%s: Invalid format (size mismatch) \"%s\"\n", reg_error_str, fname);
		return;
	}

	/* sliently ignore non existing file */
	if (file_exists_config(fname)!=1)
		return;

	fp = open_file_config(fname,"rb");
	if(fp == NULL){
		LOG_ERROR("%s: %s \"%s\": %s\n", reg_error_str, cant_open_file, fname, strerror(errno));
		return;
	}

	/* attempt to read all the recipies we're expecting */
	for (i=0; !feof(fp) && i<num_recipe_entries; i++)
	{
		if (fread (recipes_store[i].items,recipe_size,1, fp) != 1)
		{
			if (!logged)
			{
				LOG_ERROR("%s() fail during read of file [%s] : %s\n", __FUNCTION__, fname, strerror(errno));
				logged = 1;
			}
			memset(recipes_store[i].items, 0, recipe_size);
			break;
		}
		fix_recipe_uids(recipes_store[i].items);
	}

	/* if there is another, use it as the current recipe in the manufacturing pipeline */
	if (!feof(fp))
	{
		if (fread (manu_recipe.items,recipe_size,1, fp) != 1)
			memset(manu_recipe.items, 0, recipe_size);
		else
			fix_recipe_uids(manu_recipe.items);
	}
	fclose (fp);

	load_recipe_names();
}