Exemple #1
0
/**
 * load
 */
int MapIso::load(string filename) {
	ifstream infile;
	string line;
	string starts_with;
	string section;
	string key;
	string val;
	string cur_layer;
	string data_format;
  
	clearEvents();
  
    event_count = 0;
  
	infile.open(("maps/" + filename).c_str(), ios::in);

	if (infile.is_open()) {
		while (!infile.eof()) {

			line = getLine(infile);

			if (line.length() > 0) {
				starts_with = line.at(0);
				
				if (starts_with == "#") {
					// skip comments
				}
				else if (starts_with == "[") {
					section = trim(parse_section_title(line), ' ');
					
					data_format = "dec"; // default
					
					if (enemy_awaiting_queue) {
						enemies.push(new_enemy);
						enemy_awaiting_queue = false;
					}
					if (npc_awaiting_queue) {
						npcs.push(new_npc);
						npc_awaiting_queue = false;
					}
					
					// for sections that are stored in collections, add a new object here
					if (section == "enemy") {
						clearEnemy(new_enemy);
						enemy_awaiting_queue = true;
					}
					else if (section == "npc") {
						clearNPC(new_npc);
						npc_awaiting_queue = true;
					}
					else if (section == "event") {
						event_count++;
					}
					
				}
				else { // this is data.  treatment depends on section type
					parse_key_pair(line, key, val);          
					key = trim(key, ' ');
					val = trim(val, ' ');

					if (section == "header") {
						if (key == "title") {
							this->title = val;
						}
						else if (key == "width") {
							this->w = atoi(val.c_str());
						}
						else if (key == "height") {
							this->h = atoi(val.c_str());
						}
						else if (key == "tileset") {
							this->tileset = val;
						}
						else if (key == "music") {
							if (this->music_filename == val) {
								this->new_music = false;
							}
							else {
								this->music_filename = val;
								this->new_music = true;
							}
						}
						else if (key == "spawnpoint") {
							val = val + ",";
							spawn.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
							spawn.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
							spawn_dir = eatFirstInt(val, ',');
						}
					}
					else if (section == "layer") {
						if (key == "id") {
							cur_layer = val;
						}
						else if (key == "format") {
							data_format = val;
						}
						else if (key == "data") {
							// layer map data handled as a special case

							// The next h lines must contain layer data.  TODO: err
							if (data_format == "hex") {
								for (int j=0; j<h; j++) {
									line = getLine(infile);
									line = line + ',';
									for (int i=0; i<w; i++) {
										if (cur_layer == "background") background[i][j] = eatFirstHex(line, ',');
										else if (cur_layer == "object") object[i][j] = eatFirstHex(line, ',');
										else if (cur_layer == "collision") collision[i][j] = eatFirstHex(line, ',');
									}
								}
							}
							else if (data_format == "dec") {
								for (int j=0; j<h; j++) {
									line = getLine(infile);
									line = line + ',';
									for (int i=0; i<w; i++) {
										if (cur_layer == "background") background[i][j] = eatFirstInt(line, ',');
										else if (cur_layer == "object") object[i][j] = eatFirstInt(line, ',');
										else if (cur_layer == "collision") collision[i][j] = eatFirstInt(line, ',');
									}
								}
							}
						}
					}
					else if (section == "enemy") {
						
						if (key == "type") {
							new_enemy.type = val;
						}
						else if (key == "spawnpoint") {
							val = val + ",";
							new_enemy.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
							new_enemy.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
							new_enemy.direction = eatFirstInt(val, ',');
						}
					}
					else if (section == "npc") {
						if (key == "id") {
							new_npc.id = val;
						}
						else if (key == "position") {
							val = val + ",";
							new_npc.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
							new_npc.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
						}
					
					}
					else if (section == "event") {
						if (key == "type") {
							events[event_count-1].type = val;
						}
						else if (key == "location") {
							val = val + ",";
							events[event_count-1].location.x = eatFirstInt(val, ',');
							events[event_count-1].location.y = eatFirstInt(val, ',');
							events[event_count-1].location.w = eatFirstInt(val, ',');
							events[event_count-1].location.h = eatFirstInt(val, ',');							
						}
						else {
	
						
							// new event component
							Event_Component *e = &events[event_count-1].components[events[event_count-1].comp_num];
							e->type = key;
							
							if (key == "intermap") {
								val = val + ",";
								e->s = eatFirstString(val, ',');
								e->x = eatFirstInt(val, ',');
								e->y = eatFirstInt(val, ',');
							}
							else if (key == "mapmod") {
								val = val + ",";
								e->s = eatFirstString(val, ',');
								e->x = eatFirstInt(val, ',');
								e->y = eatFirstInt(val, ',');
								e->z = eatFirstInt(val, ',');
							}
							else if (key == "soundfx") {
								e->s = val;
							}
							else if (key == "loot") {
								val = val + ",";
								e->s = eatFirstString(val, ',');
								e->x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
								e->y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
								e->z = eatFirstInt(val, ',');
			
							}
							else if (key == "msg") {
								e->s = val;
							}
							else if (key == "shakycam") {
								e->x = atoi(val.c_str());
							}
							else if (key == "requires_status") {
								e->s = val;
							}
							else if (key == "requires_not") {
								e->s = val;
							}
							else if (key == "requires_item") {
								e->x = atoi(val.c_str());
							}
							else if (key == "set_status") {
								e->s = val;
							}
							else if (key == "unset_status") {
								e->s = val;
							}
							else if (key == "remove_item") {
								e->x = atoi(val.c_str());
							}
							else if (key == "reward_xp") {
								e->x = atoi(val.c_str());
							}
							
							events[event_count-1].comp_num++;
						}
							
					}
				}
			}
		}
		
		// reached end of file.  Handle any final sections.
		if (enemy_awaiting_queue) {
			enemies.push(new_enemy);
			enemy_awaiting_queue = false;
		}
		if (npc_awaiting_queue) {
			npcs.push(new_npc);
			npc_awaiting_queue = false;
		}
	}

	infile.close();

	collider.setmap(collision);
	collider.map_size.x = w;
	collider.map_size.y = h;
	
	if (this->new_music) {
		loadMusic();
		this->new_music = false;
	}
	tset.load(this->tileset);

	return 0;
}
Exemple #2
0
void ItemDatabase::load() {
	ifstream infile;
	string line;
	string key;
	string val;
	string starts_with;
	int id = 0;
	string s;
	
	infile.open("items/items.txt", ios::in);

	if (infile.is_open()) {
		while (!infile.eof()) {

			line = getLine(infile);

			if (line.length() > 0) {
				starts_with = line.at(0);
				
				if (starts_with == "#") {
					// skip comments
				}
				else if (starts_with == "[") {
					// skip headers
					// we expect the first entry after the header
					//   to be the new id
				}
				else { // this is data.  treatment depends on section type
					parse_key_pair(line, key, val);          
					key = trim(key, ' ');
					val = trim(val, ' ');
					//num = atoi(val.c_str());
					
					if (key == "id")
						id = atoi(val.c_str());
					else if (key == "name")
						items[id].name = val;
					else if (key == "level")
						items[id].level = atoi(val.c_str());
					else if (key == "icon") {
						val = val + ",";
						items[id].icon32 = eatFirstInt(val, ',');
						if (val.length() > 0)
							items[id].icon64 = eatFirstInt(val, ',');
					}
					else if (key == "quality") {
						if (val == "low")
							items[id].quality = ITEM_QUALITY_LOW;
						else if (val == "high")
							items[id].quality = ITEM_QUALITY_HIGH;
						else if (val == "epic")
							items[id].quality = ITEM_QUALITY_EPIC;
					}
					else if (key == "type") {
						if (val == "main")
							items[id].type = ITEM_TYPE_MAIN;
						else if (val == "body")
							items[id].type = ITEM_TYPE_BODY;
						else if (val == "off")
							items[id].type = ITEM_TYPE_OFF;
						else if (val == "artifact")
							items[id].type = ITEM_TYPE_ARTIFACT;
						else if (val == "consumable")
							items[id].type = ITEM_TYPE_CONSUMABLE;
						else if (val == "gem")
							items[id].type = ITEM_TYPE_GEM;
						else if (val == "quest")
							items[id].type = ITEM_TYPE_QUEST;
					}
					else if (key == "dmg") {
						val = val + ",";
						items[id].dmg_min = eatFirstInt(val, ',');
						if (val.length() > 0)
							items[id].dmg_max = eatFirstInt(val, ',');
						else
							items[id].dmg_max = items[id].dmg_min;
					}
					else if (key == "abs") {
						val = val + ",";
						items[id].abs_min = eatFirstInt(val, ',');
						if (val.length() > 0)
							items[id].abs_max = eatFirstInt(val, ',');
						else
							items[id].abs_max = items[id].abs_min;
					}
					else if (key == "req") {
						val = val + ",";
						s = eatFirstString(val, ',');
						items[id].req_val = eatFirstInt(val, ',');
						if (s == "p")
							items[id].req_stat = REQUIRES_PHYS;
						else if (s == "m")
							items[id].req_stat = REQUIRES_MENT;
						else if (s == "o")
							items[id].req_stat = REQUIRES_OFF;
						else if (s == "d")
							items[id].req_stat = REQUIRES_DEF;
					}
					else if (key == "bonus") {
						val = val + ",";
						items[id].bonus_stat = eatFirstString(val, ',');
						items[id].bonus_val = eatFirstInt(val, ',');
					}
					else if (key == "sfx") {
						if (val == "book")
							items[id].sfx = SFX_BOOK;
						else if (val == "cloth")
							items[id].sfx = SFX_CLOTH;
						else if (val == "coins")
							items[id].sfx = SFX_COINS;
						else if (val == "gem")
							items[id].sfx = SFX_GEM;
						else if (val == "leather")
							items[id].sfx = SFX_LEATHER;
						else if (val == "metal")
							items[id].sfx = SFX_METAL;
						else if (val == "page")
							items[id].sfx = SFX_PAGE;
						else if (val == "maille")
							items[id].sfx = SFX_MAILLE;
						else if (val == "object")
							items[id].sfx = SFX_OBJECT;
						else if (val == "heavy")
							items[id].sfx = SFX_HEAVY;
						else if (val == "wood")
							items[id].sfx = SFX_WOOD;
						else if (val == "potion")
							items[id].sfx = SFX_POTION;
					}
					else if (key == "gfx")
						items[id].gfx = val;
					else if (key == "loot")
						items[id].loot = val;
					else if (key == "power")
						items[id].power = atoi(val.c_str());
					else if (key == "power_mod")
						items[id].power_mod = atoi(val.c_str());
					else if (key == "power_desc")
						items[id].power_desc = val;
					else if (key == "price")
						items[id].price = atoi(val.c_str());
					else if (key == "max_quantity")
						items[id].max_quantity = atoi(val.c_str());
					else if (key == "rand_loot")
						items[id].rand_loot = atoi(val.c_str());
					else if (key == "rand_vendor")
						items[id].rand_vendor = atoi(val.c_str());
					else if (key == "pickup_status")
						items[id].pickup_status = val;
						
				}
			}
		}
	}
	infile.close();
}
Exemple #3
0
/**
 * load
 */
int MapIso::load(string filename) {
	FileParser infile;
	string val;
	string cur_layer;
	string data_format;
  
	clearEvents();
  
    event_count = 0;
  
	if (infile.open(("maps/" + filename).c_str())) {
		while (infile.next()) {
			if (infile.new_section) {
				data_format = "dec"; // default
				
				if (enemy_awaiting_queue) {
					enemies.push(new_enemy);
					enemy_awaiting_queue = false;
				}
				if (npc_awaiting_queue) {
					npcs.push(new_npc);
					npc_awaiting_queue = false;
				}
				
				// for sections that are stored in collections, add a new object here
				if (infile.section == "enemy") {
					clearEnemy(new_enemy);
					enemy_awaiting_queue = true;
				}
				else if (infile.section == "npc") {
					clearNPC(new_npc);
					npc_awaiting_queue = true;
				}
				else if (infile.section == "event") {
					event_count++;
				}
				
			}
			if (infile.section == "header") {
				if (infile.key == "title") {
					this->title = infile.val;
				}
				else if (infile.key == "width") {
					this->w = atoi(infile.val.c_str());
				}
				else if (infile.key == "height") {
					this->h = atoi(infile.val.c_str());
				}
				else if (infile.key == "tileset") {
					this->tileset = infile.val;
				}
				else if (infile.key == "music") {
					if (this->music_filename == infile.val) {
						this->new_music = false;
					}
					else {
						this->music_filename = infile.val;
						this->new_music = true;
					}
				}
				else if (infile.key == "spawnpoint") {
					val = infile.val + ",";
					spawn.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
					spawn.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
					spawn_dir = eatFirstInt(val, ',');
				}
			}
			else if (infile.section == "layer") {
				if (infile.key == "id") {
					cur_layer = infile.val;
				}
				else if (infile.key == "format") {
					data_format = infile.val;
				}
				else if (infile.key == "data") {
					// layer map data handled as a special case

					// The next h lines must contain layer data.  TODO: err
					if (data_format == "hex") {
						for (int j=0; j<h; j++) {
							val = infile.getRawLine() + ',';
							for (int i=0; i<w; i++) {
								if (cur_layer == "background") background[i][j] = eatFirstHex(val, ',');
								else if (cur_layer == "object") object[i][j] = eatFirstHex(val, ',');
								else if (cur_layer == "collision") collision[i][j] = eatFirstHex(val, ',');
							}
						}
					}
					else if (data_format == "dec") {
						for (int j=0; j<h; j++) {
							val = infile.getRawLine() + ',';
							for (int i=0; i<w; i++) {
								if (cur_layer == "background") background[i][j] = eatFirstInt(val, ',');
								else if (cur_layer == "object") object[i][j] = eatFirstInt(val, ',');
								else if (cur_layer == "collision") collision[i][j] = eatFirstInt(val, ',');
							}
						}
					}
				}
			}
			else if (infile.section == "enemy") {
				
				if (infile.key == "type") {
					new_enemy.type = infile.val;
				}
				else if (infile.key == "spawnpoint") {
					val = infile.val + ",";
					new_enemy.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
					new_enemy.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
					new_enemy.direction = eatFirstInt(val, ',');
				}
			}
			else if (infile.section == "npc") {
				if (infile.key == "id") {
					new_npc.id = infile.val;
				}
				else if (infile.key == "position") {
					val = infile.val + ",";
					new_npc.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
					new_npc.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
				}
			
			}
			else if (infile.section == "event") {
				if (infile.key == "type") {
					events[event_count-1].type = infile.val;
				}
				else if (infile.key == "location") {
					val = infile.val + ",";
					events[event_count-1].location.x = eatFirstInt(val, ',');
					events[event_count-1].location.y = eatFirstInt(val, ',');
					events[event_count-1].location.w = eatFirstInt(val, ',');
					events[event_count-1].location.h = eatFirstInt(val, ',');
				}
				else {
					// new event component
					Event_Component *e = &events[event_count-1].components[events[event_count-1].comp_num];
					e->type = infile.key;
					
					if (infile.key == "intermap") {
						val = infile.val + ",";
						e->s = eatFirstString(val, ',');
						e->x = eatFirstInt(val, ',');
						e->y = eatFirstInt(val, ',');
					}
					else if (infile.key == "mapmod") {
						val = infile.val + ",";
						e->s = eatFirstString(val, ',');
						e->x = eatFirstInt(val, ',');
						e->y = eatFirstInt(val, ',');
						e->z = eatFirstInt(val, ',');
					}
					else if (infile.key == "soundfx") {
						e->s = infile.val;
					}
					else if (infile.key == "loot") {
						val = infile.val + ",";
						e->s = eatFirstString(val, ',');
						e->x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
						e->y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2;
						e->z = eatFirstInt(val, ',');
	
					}
					else if (infile.key == "msg") {
						e->s = infile.val;
					}
					else if (infile.key == "shakycam") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "requires_status") {
						e->s = infile.val;
					}
					else if (infile.key == "requires_not") {
						e->s = infile.val;
					}
					else if (infile.key == "requires_item") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "set_status") {
						e->s = infile.val;
					}
					else if (infile.key == "unset_status") {
						e->s = infile.val;
					}
					else if (infile.key == "remove_item") {
						e->x = atoi(infile.val.c_str());
					}
					else if (infile.key == "reward_xp") {
						e->x = atoi(infile.val.c_str());
					}
					
					events[event_count-1].comp_num++;
				}
			}
		}

		infile.close();
		
		// reached end of file.  Handle any final sections.
		if (enemy_awaiting_queue) {
			enemies.push(new_enemy);
			enemy_awaiting_queue = false;
		}
		if (npc_awaiting_queue) {
			npcs.push(new_npc);
			npc_awaiting_queue = false;
		}
	}

	collider.setmap(collision);
	collider.map_size.x = w;
	collider.map_size.y = h;
	
	if (this->new_music) {
		loadMusic();
		this->new_music = false;
	}
	tset.load(this->tileset);

	return 0;
}
MenuManager::MenuManager(PowerManager *_powers, StatBlock *_stats, CampaignManager *_camp, ItemManager *_items) {
	powers = _powers;
	stats = _stats;
	powers = _powers;
	camp = _camp;
	items = _items;

	loadIcons();

	hp = new MenuStatBar("hp");
	menus.push_back(hp); // menus[0]
	mp = new MenuStatBar("mp");
	menus.push_back(mp); // menus[1]
	xp = new MenuStatBar("xp");
	menus.push_back(xp); // menus[2]
	effects = new MenuActiveEffects(icons);
	menus.push_back(effects); // menus[3]
	hudlog = new MenuHUDLog();
	menus.push_back(hudlog); // menus[4]
	act = new MenuActionBar(powers, stats, icons);
	menus.push_back(act); // menus[5]
	enemy = new MenuEnemy();
	menus.push_back(enemy); // menus[6]
	vendor = new MenuVendor(items, stats);
	menus.push_back(vendor); // menus[7]
	talker = new MenuTalker(camp);
	menus.push_back(talker); // menus[8]
	exit = new MenuExit();
	menus.push_back(exit); // menus[9]
	mini = new MenuMiniMap();
	menus.push_back(mini); // menus[10]
	chr = new MenuCharacter(stats);
	menus.push_back(chr); // menus[11]
	inv = new MenuInventory(items, stats, powers);
	menus.push_back(inv); // menus[12]
	pow = new MenuPowers(stats, powers, icons);
	menus.push_back(pow); // menus[13]
	log = new MenuLog();
	menus.push_back(log); // menus[14]
	stash = new MenuStash(items, stats);
	menus.push_back(stash); // menus[15]
	tip = new WidgetTooltip();

	// Load the menu positions and alignments from menus/menus.txt
	int x,y,w,h;
	std::string align;
	int menu_index;
	FileParser infile;
	if (infile.open(mods->locate("menus/menus.txt"))) {
		while (infile.next()) {
			infile.val = infile.val + ',';
			x = eatFirstInt(infile.val, ',');
			y = eatFirstInt(infile.val, ',');
			w = eatFirstInt(infile.val, ',');
			h = eatFirstInt(infile.val, ',');
			align = eatFirstString(infile.val, ',');

			menu_index = -1;

			if (infile.key == "hp") menu_index = 0;
			else if (infile.key == "mp") menu_index = 1;
			else if (infile.key == "xp") menu_index = 2;
			else if (infile.key == "effects") menu_index = 3;
			else if (infile.key == "hudlog") menu_index = 4;
			else if (infile.key == "actionbar") menu_index = 5;
			else if (infile.key == "enemy") menu_index = 6;
			else if (infile.key == "vendor") menu_index = 7;
			else if (infile.key == "talker") menu_index = 8;
			else if (infile.key == "exit") menu_index = 9;
			else if (infile.key == "minimap") menu_index = 10;
			else if (infile.key == "character") menu_index = 11;
			else if (infile.key == "inventory") menu_index = 12;
			else if (infile.key == "powers") menu_index = 13;
			else if (infile.key == "log") menu_index = 14;
			else if (infile.key == "stash") menu_index = 15;

			if (menu_index != -1) {
				menus[menu_index]->window_area.x = x;
				menus[menu_index]->window_area.y = y;
				menus[menu_index]->window_area.w = w;
				menus[menu_index]->window_area.h = h;
				menus[menu_index]->alignment = align;
				menus[menu_index]->align();
			}

		}
		infile.close();
	} else fprintf(stderr, "Unable to open menus/menus.txt!\n");

	// Some menus need to be updated to apply their new dimensions
	act->update();
	vendor->update();
	vendor->buyback_stock.init(NPC_VENDOR_MAX_STOCK, items);
	talker->update();
	exit->update();
	chr->update();
	inv->update();
	pow->update();
	log->update();
	stash->update();

	pause = false;
	dragging = false;
	drag_stack.item = 0;
	drag_stack.quantity = 0;
	drag_power = 0;
	drag_src = 0;
	drop_stack.item = 0;
	drop_stack.quantity = 0;


	loadSounds();

	done = false;

	closeAll(false); // make sure all togglable menus start closed
}