Beispiel #1
0
string GameStateLoad::getMapName(const string& map_filename) {
	FileParser infile;
	if (!infile.open(mods->locate("maps/" + map_filename))) return "";
	string map_name = "";

	while (map_name == "" && infile.next()) {
		if (infile.key == "title")
			map_name = msg->get(infile.val);
	}

	infile.close();
	return map_name;
}
LootManager::LootManager(StatBlock *_hero)
	: sfx_loot(0)
	, tooltip_margin(0) {
	hero = _hero; // we need the player's position for dropping loot in a valid spot

	tip = new WidgetTooltip();

	FileParser infile;
	// load loot animation settings from engine config file
	// @CLASS Loot|Description of engine/loot.txt
	if (infile.open("engine/loot.txt")) {
		while (infile.next()) {
			if (infile.key == "loot_animation") {
				// @ATTR loot_animation|x(int), y(int), w(int), h(int)|
				animation_pos = toRect(infile.val);
			}
			else if (infile.key == "loot_animation_offset") {
				// @ATTR loot_animation_offset|x (integer), y (integer)|
				animation_offset = toPoint(infile.val);
			}
			else if (infile.key == "tooltip_margin") {
				// @ATTR tooltip_margin|integer|
				tooltip_margin = toInt(infile.val);
			}
			else if (infile.key == "autopickup_currency") {
				// @ATTR autopickup_currency|boolean|Enable autopickup for currency
				AUTOPICKUP_CURRENCY = toBool(infile.val);
			}
			else if (infile.key == "currency_name") {
				// @ATTR currenct_name|string|Define the name of currency in game
				CURRENCY = msg->get(infile.val);
			}
			else if (infile.key == "vendor_ratio") {
				// @ATTR vendor_ratio|integer|Prices ratio for vendors
				VENDOR_RATIO = toInt(infile.val) / 100.0f;
			}
			else if (infile.key == "sfx_loot") {
				// @ATTR sfx_loot|string|Sound effect for dropping loot.
				sfx_loot =  snd->load(infile.val, "LootManager dropping loot");
			}
		}
		infile.close();
	}

	// reset current map loot
	loot.clear();

	loadGraphics();

	full_msg = false;
}
Beispiel #3
0
void GameStateLoad::readGameSlot(int slot) {

	stringstream filename;
	FileParser infile;

	// abort if not a valid slot number
	if (slot < 0 || slot >= GAME_SLOT_MAX) return;

	// save slots are named save#.txt
	filename << "save" << (slot+1) << ".txt";

	if (!infile.open(PATH_USER + filename.str())) return;

	while (infile.next()) {

		// load (key=value) pairs
		if (infile.key == "name")
			stats[slot].name = infile.val;
		else if (infile.key == "class")
			stats[slot].character_class = infile.val;
		else if (infile.key == "xp")
			stats[slot].xp = atoi(infile.val.c_str());
		else if (infile.key == "build") {
			stats[slot].physical_character = atoi(infile.nextValue().c_str());
			stats[slot].mental_character = atoi(infile.nextValue().c_str());
			stats[slot].offense_character = atoi(infile.nextValue().c_str());
			stats[slot].defense_character = atoi(infile.nextValue().c_str());
		}
		else if (infile.key == "equipped") {
			string repeat_val = infile.nextValue();
			while (repeat_val != "") {
				equipped[slot].push_back(toInt(repeat_val));
				repeat_val = infile.nextValue();
			}
		}
		else if (infile.key == "option") {
			stats[slot].base = infile.nextValue();
			stats[slot].head = infile.nextValue();
			stats[slot].portrait = infile.nextValue();
		}
		else if (infile.key == "spawn") {
			current_map[slot] = getMapName(infile.nextValue());
		}
	}
	infile.close();

	stats[slot].recalc();
	loadPreview(slot);

}
bool GameStateConfig::getLanguagesList() {
	FileParser infile;
	if (infile.open("engine/languages.txt")) {
		unsigned int i=0;
		while (infile.next()) {
			language_ISO[i] = infile.key;
			language_full[i] = infile.nextValue();
			i += 1;
		}
		infile.close();
	}

	return true;
}
Beispiel #5
0
/**
 * Key bindings are found in config/keybindings.txt
 */
void InputState::loadKeyBindings() {

	FileParser infile;	
	int key1;
	int key2;
	int cursor;

	if (!infile.open("config/keybindings.txt")) return;
	
	while (infile.next()) {

		key1 = eatFirstInt(infile.val, ',');
		key2 = atoi(infile.val.c_str());
		
		cursor = -1;
		
		if (infile.key == "cancel") cursor = CANCEL;
		else if (infile.key == "accept") cursor = ACCEPT;
		else if (infile.key == "up") cursor = UP;
		else if (infile.key == "down") cursor = DOWN;
		else if (infile.key == "left") cursor = LEFT;
		else if (infile.key == "right") cursor = RIGHT;
		else if (infile.key == "bar1") cursor = BAR_1;
		else if (infile.key == "bar2") cursor = BAR_2;
		else if (infile.key == "bar3") cursor = BAR_3;
		else if (infile.key == "bar4") cursor = BAR_4;
		else if (infile.key == "bar5") cursor = BAR_5;
		else if (infile.key == "bar6") cursor = BAR_6;
		else if (infile.key == "bar7") cursor = BAR_7;
		else if (infile.key == "bar8") cursor = BAR_8;
		else if (infile.key == "bar9") cursor = BAR_9;
		else if (infile.key == "bar0") cursor = BAR_0;
		else if (infile.key == "main1") cursor = MAIN1;
		else if (infile.key == "main2") cursor = MAIN2;
		else if (infile.key == "character") cursor = CHARACTER;
		else if (infile.key == "inventory") cursor = INVENTORY;
		else if (infile.key == "powers") cursor = POWERS;
		else if (infile.key == "log") cursor = LOG;
		else if (infile.key == "ctrl") cursor = CTRL;
		else if (infile.key == "shift") cursor = SHIFT;
		else if (infile.key == "delete") cursor = DELETE;
		
		if (cursor != -1) {
			binding[cursor] = key1;
			binding_alt[cursor] = key2;
		}

	}
	infile.close();
}
/**
 * Load body type "base" and portrait/head "portrait" options from a config file
 *
 * @param filename File containing entries for option=base,look
 */
void GameStateNew::loadOptions(const string& filename) {
	FileParser fin;
	if (!fin.open("engine/" + filename, true, false)) return;

	while (fin.next()) {
		if (fin.key == "option") {
			base.push_back(fin.nextValue());
			head.push_back(fin.nextValue());
			portrait.push_back(fin.nextValue());
			name.push_back(msg->get(fin.nextValue()));
		}
	}
	fin.close();
}
Beispiel #7
0
bool GameStateConfig::getLanguagesList()
{
	FileParser infile;
	if (infile.open(mods->locate("engine/languages.txt"))) {
		unsigned int i=0;
		while (infile.next()) {
			   language_ISO[i] = infile.key;
			   language_full[i] = infile.nextValue();
			   i += 1;
			}
		} else fprintf(stderr, "Unable to open languages.txt!\n");
		infile.close();

	return true;
}
Beispiel #8
0
void GameSwitcher::loadBackgroundList() {
	background_list.clear();
	freeBackground();

	FileParser infile;
	// @CLASS GameSwitcher: Background images|Description of engine/menu_backgrounds.txt
	if (infile.open("engine/menu_backgrounds.txt", true, "")) {
		while (infile.next()) {
			// @ATTR background|string|Filename of a background image to be added to the pool of random menu backgrounds
			if (infile.key == "background") background_list.push_back(infile.val);
			else infile.error("GameSwitcher: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}
}
Beispiel #9
0
MenuPowers::MenuPowers(StatBlock *_stats, MenuActionBar *_action_bar)
	: stats(_stats)
	, action_bar(_action_bar)
	, skip_section(false)
	, powers_unlock(NULL)
	, overlay_disabled(NULL)
	, points_left(0)
	, default_background("")
	, tab_control(NULL)
	, tree_loaded(false)
	, prev_powers_list_size(0)
	, newPowerNotification(false)
{

	closeButton = new WidgetButton("images/menus/buttons/button_x.png");

	// Read powers data from config file
	FileParser infile;
	// @CLASS MenuPowers: Menu layout|Description of menus/powers.txt
	if (infile.open("menus/powers.txt")) {
		while (infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR label_title|label|Position of the "Powers" text.
			if (infile.key == "label_title") title = eatLabelInfo(infile.val);
			// @ATTR unspent_points|label|Position of the text that displays the amount of unused power points.
			else if (infile.key == "unspent_points") unspent_points = eatLabelInfo(infile.val);
			// @ATTR close|point|Position of the close button.
			else if (infile.key == "close") close_pos = toPoint(infile.val);
			// @ATTR tab_area|rectangle|Position and dimensions of the tree pages.
			else if (infile.key == "tab_area") tab_area = toRect(infile.val);

			else infile.error("MenuPowers: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}

	loadGraphics();

	menu_powers = this;

	color_bonus = font->getColor("menu_bonus");
	color_penalty = font->getColor("menu_penalty");
	color_flavor = font->getColor("item_flavor");

	align();
}
Beispiel #10
0
/**
 * Load body type "base" and portrait/head "portrait" options from a config file
 *
 * @param filename File containing entries for option=base,look
 */
void GameStateNew::loadOptions(const string& filename) {
	FileParser fin;
	// @CLASS GameStateNew: Hero options|Description of engine/hero_options.txt
	if (!fin.open("engine/" + filename, true, false)) return;

	while (fin.next()) {
		// @ATTR option|base (string), head (string), portrait (string), name (string)|A default body, head, portrait, and name for a hero.
		if (fin.key == "option") {
			base.push_back(fin.nextValue());
			head.push_back(fin.nextValue());
			portrait.push_back(fin.nextValue());
			name.push_back(msg->get(fin.nextValue()));
		}
	}
	fin.close();
}
Beispiel #11
0
WidgetTooltip::WidgetTooltip() {

	FileParser infile;
	// load tooltip settings from engine config file
	if (infile.open("engine/tooltips.txt")) {
		while (infile.next()) {
			if (infile.key == "tooltip_offset")
				offset = toInt(infile.val);
			else if (infile.key == "tooltip_width")
				width = toInt(infile.val);
			else if (infile.key == "tooltip_margin")
				margin = toInt(infile.val);
		}
		infile.close();
	}
}
Beispiel #12
0
FontEngine::FontEngine() {
	font_pt = 10;

	// Initiate SDL_ttf
	if(!TTF_WasInit() && TTF_Init()==-1) {
		printf("TTF_Init: %s\n", TTF_GetError());
		exit(2);
	}

	// load the font
	string font_path;
	FileParser infile;
	if (infile.open(mods->locate("engine/font_settings.txt"))) {
		while (infile.next()) {
			if (infile.key == "font_regular"){
				font_path = infile.val;
			}
			if (infile.key == "ptsize"){
				font_pt = atoi(infile.val.c_str());
			}
		}
	}
	font_path = mods->locate("fonts/" + font_path);
	ttfont = TTF_OpenFont(font_path.c_str(), font_pt);
	if(!ttfont) printf("TTF_OpenFont: %s\n", TTF_GetError());

	// calculate the optimal line height
	line_height = TTF_FontLineSkip(ttfont);
	font_height = TTF_FontHeight(ttfont); 

	// set the font colors
	// RGB values, the last value is 'unused'. For info,
	// see http://www.libsdl.org/cgi/docwiki.cgi/SDL_Color
	SDL_Color white = {255,255,255,0};
	SDL_Color red = {255,0,0,0};
	SDL_Color green = {0,255,0,0};
	SDL_Color blue = {0,0,255,0};
	SDL_Color grey = {128,128,128,0};
	SDL_Color black = {0,0,0,0};

	colors[FONT_WHITE] = white;
	colors[FONT_RED] = red;
	colors[FONT_GREEN] = green;
	colors[FONT_BLUE] = blue;
	colors[FONT_GREY] = grey;
	colors[FONT_BLACK] = black;
}
MenuVendor::MenuVendor(ItemManager *_items, StatBlock *_stats)
	: Menu()
	, items(_items)
	, stats(_stats)
	, closeButton(new WidgetButton("images/menus/buttons/button_x.png"))
	, tabControl(new WidgetTabControl(2))
	, activetab(VENDOR_BUY)
	, color_normal(font->getColor("menu_normal"))
	, npc(NULL)
	, buyback_stock()
	, talker_visible(false) {
	background = loadGraphicSurface("images/menus/vendor.png");

	tabControl->setTabTitle(VENDOR_BUY,msg->get("Inventory"));
	tabControl->setTabTitle(VENDOR_SELL,msg->get("Buyback"));

	loadMerchant("");

	// Load config settings
	FileParser infile;
	if(infile.open("menus/vendor.txt")) {
		while(infile.next()) {
			infile.val = infile.val + ',';

			if(infile.key == "close") {
				close_pos.x = eatFirstInt(infile.val,',');
				close_pos.y = eatFirstInt(infile.val,',');
			}
			else if(infile.key == "slots_area") {
				slots_area.x = eatFirstInt(infile.val,',');
				slots_area.y = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "vendor_cols") {
				slots_cols = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "vendor_rows") {
				slots_rows = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "caption") {
				title =  eatLabelInfo(infile.val);
			}
		}
		infile.close();
	}

	VENDOR_SLOTS = slots_cols * slots_rows;
}
void PowerManager::loadEffects() {
	FileParser infile;

	if (!infile.open("powers/effects.txt", true, false))
		return;

	std::string input_name = "";
	bool skippingEntry = false;

	while (infile.next()) {
		// name needs to be the first component of each power.  That is how we write
		// data to the correct power.
		if (infile.key == "name") {
			// @ATTR name|string|Uniq identifier for the effect definition.
			input_name = infile.val;
			skippingEntry = input_name == "";
			if (skippingEntry)
				fprintf(stderr, "Effect without a name, skipping\n");
			continue;
		}
		if (skippingEntry)
			continue;

		if (infile.key == "type") {
			// @ATTR type|string|Defines the type of effect
			effects[input_name].type = infile.val;
		}
		else if (infile.key == "icon") {
			// @ATTR icon|integer|The icon to visually represent the effect in the status area
			effects[input_name].icon = toInt(infile.val);
		}
		else if (infile.key == "animation") {
			// @ATTR animation|string|The name of effect animation.
			effects[input_name].animation = infile.val;
		}
		else if (infile.key == "additive") {
			// @ATTR additive|bool|Effect is additive
			effects[input_name].additive = toBool(infile.val);
		}
		else if (infile.key == "render_above") {
			// @ATTR render_above|bool|Effect is rendered above
			effects[input_name].render_above = toBool(infile.val);
		}
	}
	infile.close();
}
Beispiel #15
0
int Map::load(std::string fname) {
	FileParser infile;
	maprow *cur_layer = NULL;

	clearEvents();
	clearLayers();
	clearQueues();

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemies.push(Map_Enemy());
			else if (infile.section == "enemygroup")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile, &cur_layer);
		else if (infile.section == "enemy")
			loadEnemy(infile);
		else if (infile.section == "enemygroup")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	return 0;
}
MenuNPCActions::MenuNPCActions()
	: Menu()
	, npc(NULL)
	, is_selected(false)
	, is_empty(true)
	, first_dialog_node(-1)
	, current_action(-1)
	, action_menu(NULL)
	, vendor_label(msg->get("Trade"))
	, cancel_label(msg->get("Cancel"))
	, dialog_selected(false)
	, vendor_selected(false)
	, cancel_selected(false)
	, selected_dialog_node(-1) {
	// Load config settings
	FileParser infile;
	// @CLASS MenuNPCActions|Description of menus/npc.txt
	if (infile.open("menus/npc.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR background_color|r (integer), g (integer), b (integer), a (integer)|Color and alpha of the menu's background.
			if(infile.key == "background_color") background_color = toRGBA(infile.val);
			// @ATTR topic_normal_color|r (integer), g (integer), b (integer)|The normal color of a generic topic text.
			else if(infile.key == "topic_normal_color") topic_normal_color = toRGB(infile.val);
			// @ATTR topic_hilight_color|r (integer), g (integer), b (integer)|The color of generic topic text when it's hovered over or selected.
			else if(infile.key == "topic_hilight_color") topic_hilight_color = toRGB(infile.val);
			// @ATTR vendor_normal_color|r (integer), g (integer), b (integer)|The normal color of the vendor option text.
			else if(infile.key == "vendor_normal_color") vendor_normal_color = toRGB(infile.val);
			// @ATTR vendor_hilight_color|r (integer), g (integer), b (integer)|The color of vendor option text when it's hovered over or selected.
			else if(infile.key == "vendor_hilight_color") vendor_hilight_color = toRGB(infile.val);
			// @ATTR cancel_normal_color|r (integer), g (integer), b (integer)|The normal color of the option to close the menu.
			else if(infile.key == "cancel_normal_color") cancel_normal_color = toRGB(infile.val);
			// @ATTR cancel_hilight_color|r (integer), g (integer), b (integer)|The color of the option to close the menu when it's hovered over or selected.
			else if(infile.key == "cancel_hilight_color") cancel_hilight_color = toRGB(infile.val);

			else infile.error("MenuNPCActions: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}

	// save the x/y pos coordinates here, since we call align() during each update() call
	base_pos.x = window_area.x;
	base_pos.y = window_area.y;
}
Beispiel #17
0
/**
 * Load the quests in the specific quest file.
 * Searches for the last-defined such file in all mods
 *
 * @param filename The quest file name and extension, no path
 */
void QuestLog::load(const std::string& filename) {
	FileParser infile;
	if (!infile.open("quests/" + filename))
		return;

	while (infile.next()) {
		if (infile.new_section) {
			if (infile.section == "quest")
				quests.push_back(vector<Event_Component>());
		}
		Event_Component ev;
		ev.type = infile.key;
		ev.s = msg->get(infile.val);
		quests.back().push_back(ev);
	}
	infile.close();
}
Beispiel #18
0
MenuVendor::MenuVendor(ItemManager *_items, StatBlock *_stats) {
	items = _items;
	stats = _stats;

	visible = false;
	talker_visible = false;
	activetab = VENDOR_BUY;
	loadGraphics();

	closeButton = new WidgetButton(mods->locate("images/menus/buttons/button_x.png"));

	tabControl = new WidgetTabControl(2);
	tabControl->setTabTitle(VENDOR_BUY,msg->get("Inventory"));
	tabControl->setTabTitle(VENDOR_SELL,msg->get("Buyback"));

	loadMerchant("");


	// Load config settings
	FileParser infile;
	if(infile.open(mods->locate("menus/vendor.txt"))) {
		while(infile.next()) {
			infile.val = infile.val + ',';

			if(infile.key == "close") {
				close_pos.x = eatFirstInt(infile.val,',');
				close_pos.y = eatFirstInt(infile.val,',');
			} else if(infile.key == "slots_area") {
				slots_area.x = eatFirstInt(infile.val,',');
				slots_area.y = eatFirstInt(infile.val,',');
			} else if (infile.key == "vendor_cols"){
				slots_cols = eatFirstInt(infile.val,',');
			} else if (infile.key == "vendor_rows"){
				slots_rows = eatFirstInt(infile.val,',');
			} else if (infile.key == "caption"){
				title =  eatLabelInfo(infile.val);
			}
		}
		infile.close();
	} else fprintf(stderr, "Unable to open menus/vendor.txt!\n");

	VENDOR_SLOTS = slots_cols * slots_rows;

	color_normal = font->getColor("menu_normal");
}
Beispiel #19
0
FontEngine::FontEngine() {
	font_pt = 10;

	// Initiate SDL_ttf
	if(!TTF_WasInit() && TTF_Init()==-1) {
		printf("TTF_Init: %s\n", TTF_GetError());
		exit(2);
	}

	// load the font
	string font_path;
	FileParser infile;
	if (infile.open(PATH_DATA + "engine/font_settings.txt")) {
		while (infile.next()) {
			if (infile.key == "font_regular"){
				font_path = infile.val;
			}
			if (infile.key == "ptsize"){
				font_pt = atoi(infile.val.c_str());
			}
		}
	}
	font_path = PATH_DATA + "fonts/" + font_path;
	font = TTF_OpenFont(font_path.c_str(), font_pt);
	if(!font) printf("TTF_OpenFont: %s\n", TTF_GetError());

	// calculate the optimal line height
	line_height = TTF_FontLineSkip(font);
	font_height = TTF_FontHeight(font); 

	// set the font colors
	SDL_Color white = {255,255,255};
	SDL_Color red = {255,0,0};
	SDL_Color green = {0,255,0};
	SDL_Color blue = {0,0,255};
	SDL_Color grey = {128,128,128};
	SDL_Color black = {0,0,0};

	colors[FONT_WHITE] = white;
	colors[FONT_RED] = red;
	colors[FONT_GREEN] = green;
	colors[FONT_BLUE] = blue;
	colors[FONT_GREY] = grey;
	colors[FONT_BLACK] = black;
}
Beispiel #20
0
void ItemManager::loadTypes(const string& filename) {
	FileParser infile;
	string type,description;
	type = description = "";

	if (infile.open(filename)) {
		while (infile.next()) {
			if (infile.key == "name") type = infile.val;
			else if (infile.key == "description") description = infile.val;

			if (type != "" && description != "") {
				item_types[type] = description;
				type = description = "";
			}
		}
		infile.close();
	} else fprintf(stderr, "Unable to open %s!\n", filename.c_str());
}
Beispiel #21
0
void ItemManager::loadTypes() {
	FileParser infile;
	string type,description;
	type = description = "";

	if (infile.open("items/types.txt", true, false)) {
		while (infile.next()) {
			if (infile.key == "name") type = infile.val;
			else if (infile.key == "description") description = infile.val;

			if (type != "" && description != "") {
				item_types[type] = description;
				type = description = "";
			}
		}
		infile.close();
	}
}
Beispiel #22
0
MenuDevHUD::MenuDevHUD() : Menu() {

	// Load config settings
	FileParser infile;
	// @CLASS MenuDevHUD|Description of menus/devhud.txt
	if(infile.open("menus/devhud.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;
			else
				infile.error("MenuDevHUD: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}

	original_area = window_area;
	alignElements();
}
Beispiel #23
0
bool loadSettings() {

	FileParser infile;
	
	if (infile.open(PATH_CONF + "settings.txt")) {
		while (infile.next()) {
			if (infile.key == "fullscreen") {
				if (infile.val == "1") FULLSCREEN = true;
			}
			else if (infile.key == "resolution_w") {
				VIEW_W = atoi(infile.val.c_str());
				VIEW_W_HALF = VIEW_W/2;
			}
			else if (infile.key == "resolution_h") {
				VIEW_H = atoi(infile.val.c_str());
				VIEW_H_HALF = VIEW_H/2;
			}
			else if (infile.key == "music_volume") {
				MUSIC_VOLUME = atoi(infile.val.c_str());
			}
			else if (infile.key == "sound_volume") {
				SOUND_VOLUME = atoi(infile.val.c_str());
			}
			else if (infile.key == "mouse_move") {
				if (infile.val == "1") MOUSE_MOVE = true;
			}
			else if (infile.key == "hwsurface") {
				if (infile.val == "1") HWSURFACE = true;
			}
			else if (infile.key == "doublebuf") {
				if (infile.val == "1") DOUBLEBUF = true;
			}
			else if (infile.key == "frames_per_sec") {
				FRAMES_PER_SEC = atoi(infile.val.c_str());
			}
		}
		infile.close();
		return true;
	}
	else {
		saveSettings(); // write the default settings
	}
	return true;
}
MenuActiveEffects::MenuActiveEffects(SDL_Surface *_icons) {
	icons = _icons;
	orientation = 0; // horizontal

	// Load config settings
	FileParser infile;
	if(infile.open(mods->locate("menus/activeeffects.txt"))) {
		while(infile.next()) {
			infile.val = infile.val + ',';

			if(infile.key == "orientation") {
				orientation = eatFirstInt(infile.val,',');
			}
		}
		infile.close();
	} else fprintf(stderr, "Unable to open menus/activeeffects.txt!\n");

	loadGraphics();
}
Beispiel #25
0
NPCManager::NPCManager(MapRenderer *_map, LootManager *_loot, ItemManager *_items, StatBlock *_stats)
	: map(_map)
	, tip(new WidgetTooltip())
	, loot(_loot)
	, items(_items)
	, stats(_stats)
	, tip_buf(TooltipData())
 {
	FileParser infile;
	// load tooltip_margin from engine config file
	if (infile.open(mods->locate("engine/tooltips.txt").c_str())) {
		while (infile.next()) {
			if (infile.key == "npc_tooltip_margin") {
				tooltip_margin = atoi(infile.val.c_str());
			}
		}
		infile.close();
	} else fprintf(stderr, "Unable to open engine/tooltips.txt!\n");
}
Beispiel #26
0
void loadAutoPickupSettings() {
	FileParser infile;
	// load autopickup settings from engine config
	if (infile.open(mods->locate("engine/autopickup.txt").c_str())) {
		while (infile.next()) {
			if (infile.key == "range") {
				AUTOPICKUP_RANGE = atoi(infile.val.c_str());
			}
			else if (infile.key == "gold") {
				if (atoi(infile.val.c_str()) == 1) AUTOPICKUP_GOLD = true;
                else AUTOPICKUP_GOLD = false;
			}
		}
		infile.close();
	}
	else {
		fprintf(stderr, "No autopickup config found! Turning autopickup off by default.\n");
	}
}
Beispiel #27
0
/*
 * This is used to load the stash when starting a new game
 */
void GameStatePlay::loadStash() {
	// Load stash
	FileParser infile;
	stringstream ss;
	ss.str("");
	ss << PATH_USER << "stash.txt";

	if (infile.open(ss.str())) {
		while (infile.next()) {
			if (infile.key == "item") {
				menu->stash->stock.setItems(infile.val);
			}
			else if (infile.key == "quantity") {
				menu->stash->stock.setQuantities(infile.val);
			}
		}
		infile.close();
	}
}
Beispiel #28
0
/**
 * Load body type "base" and portrait/head "portrait" options from a config file
 *
 * @param filename File containing entries for option=base,look
 */
void GameStateNew::loadOptions(const string& filename) {
	FileParser fin;
	if (!fin.open(mods->locate("engine/" + filename))) return;
	
	while (fin.next()) {
	
		// if at the max allowed base+look options, skip the rest of the file
		// TODO: remove static array size limit
		if (option_count == PLAYER_OPTION_MAX-1) break;

		if (fin.key == "option") {
			base[option_count] = fin.nextValue();
			head[option_count] = fin.nextValue();
			portrait[option_count] = fin.nextValue();
			option_count++;
		}
	}
	fin.close();
}
MenuStash::MenuStash(StatBlock *_stats)
	: Menu()
	, stats(_stats)
	, closeButton(new WidgetButton("images/menus/buttons/button_x.png"))
	, color_normal(font->getColor("menu_normal"))
	, stock()
	, updated(false)

{
	background = loadGraphicSurface("images/menus/stash.png");

	// Load config settings
	FileParser infile;
	if (infile.open("menus/stash.txt")) {
		while(infile.next()) {
			infile.val = infile.val + ',';

			if (infile.key == "close") {
				close_pos.x = eatFirstInt(infile.val,',');
				close_pos.y = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "slots_area") {
				slots_area.x = eatFirstInt(infile.val,',');
				slots_area.y = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "stash_cols") {
				slots_cols = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "stash_rows") {
				slots_rows = eatFirstInt(infile.val,',');
			}
			else if (infile.key == "label_title") {
				title =  eatLabelInfo(infile.val);
			}
			else if (infile.key == "currency") {
				currency =  eatLabelInfo(infile.val);
			}
		}
		infile.close();
	}

	STASH_SLOTS = slots_cols * slots_rows;
}
Beispiel #30
0
/**
 * Load avatar sprite layer definitions into vector.
 */
void Avatar::loadLayerDefinitions() {
	layer_def = vector<vector<unsigned> >(8, vector<unsigned>());
	layer_reference_order = vector<string>();

	FileParser infile;
	// @CLASS Avatar: Hero layers|Description of engine/hero_layers.txt
	if (infile.open("engine/hero_layers.txt")) {
		while(infile.next()) {
			if (infile.key == "layer") {
				// @ATTR layer|direction (integer), string, ...]|Defines the hero avatar sprite layer
				unsigned dir = popFirstInt(infile.val);
				if (dir>7) {
					infile.error("Avatar: Hero layer direction must be in range [0,7]");
					SDL_Quit();
					exit(1);
				}
				string layer = popFirstString(infile.val);
				while (layer != "") {
					// check if already in layer_reference:
					unsigned ref_pos;
					for (ref_pos = 0; ref_pos < layer_reference_order.size(); ++ref_pos)
						if (layer == layer_reference_order[ref_pos])
							break;
					if (ref_pos == layer_reference_order.size())
						layer_reference_order.push_back(layer);
					layer_def[dir].push_back(ref_pos);

					layer = popFirstString(infile.val);
				}
			}
			else {
				infile.error("Avatar: '%s' is not a valid key.", infile.key.c_str());
			}
		}
		infile.close();
	}

	// There are the positions of the items relative to layer_reference_order
	// so if layer_reference_order=main,body,head,off
	// and we got a layer=3,off,body,head,main
	// then the layer_def[3] looks like (3,1,2,0)
}