User:Celtic Minstrel/FormulaTests

From The Battle for Wesnoth Wiki

Comments explaining the algorithm:

### The formula language doesn't support variables so macros are used to
### emulate them. This makes the code what harder to read, so the algorithm for
### __GUI_IMAGE_WIDTH is described here:
###
### if gamemap_width <= TEXT_WIDTH_SATURATION
###     __GUI_IMAGE_WIDTH = gamemap_width / 3
### else
###     # Text reached it maximum width, take all space.
###     __GUI_IMAGE_WIDTH = gamemap_width - MAX_TEXT_WIDTH
### fi
###
### if __GUI_IMAGE_WIDTH < 250
###     __GUI_IMAGE_WIDTH = 250
### fi
###
### if __GUI_IMAGE_WIDTH > 500
###     __GUI_IMAGE_WIDTH = 500
### fi

Merged WFL version:

	if(best_size < 250, 250,
		if(best_size > 500, 500, best_size)
	)
where
	best_size = (
		if((best_width * aspect_ratio) > max_height,
			floor(max_height / aspect_ratio),
			best_width
		)
	where
		best_width = (
			if(gamemap_width > text_width_saturation,
				gamemap_width - max_text_width,
				(gamemap_width / size_factor)
			)
		where
			# gamemap_width width needed to reach the MAX_TEXT_WIDTH #
			text_width_saturation = (
				(3 * height_offset) / 2
			where
				# This might become global have to evaluate later. #
				height_offset = 25
			),
			# The maximum width of the text #
			max_text_width = 675,
			# helper convert the scale factor, since we use it in two places define it as
			helper value. (Two the not working and working version, but want to avoid
			surprises when the not working version is fixed). #
			size_factor = 3
		),
		aspect_ratio = (
			if(image_original_width > 0,
				(as_decimal(image_original_height) / image_original_width),
				0
			)
		),
		max_height = game_map_height - 4
	)
This page was last edited on 15 March 2016, at 21:16.