/** * Advance to the next key pair * Take note if a new section header is encountered * * @return false if EOF, otherwise true */ bool FileParser::next() { string starts_with; new_section = false; while (!infile.eof()) { line = getLine(infile); // skip ahead if this line is empty if (line.length() == 0) continue; starts_with = line.at(0); // skip ahead if this line is a comment if (starts_with == "#") continue; // set new section if this line is a section declaration if (starts_with == "[") { new_section = true; section = parse_section_title(line); // keep searching for a key-pair continue; } // this is a keypair. Perform basic parsing and return parse_key_pair(line, key, val); return true; } // hit the end of file return false; }
/** * Load the quests in the specific quest file */ void QuestLog::load(string filename) { ifstream infile; string line; string key; string val; string starts_with; string section = ""; int event_count = 0; infile.open(("quests/" + 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 = parse_section_title(line); if (section == "quest") { quest_count++; event_count = 0; } } else { // this is data. treatment depends on key parse_key_pair(line, key, val); key = trim(key, ' '); val = trim(val, ' '); quests[quest_count-1][event_count].type = key; quests[quest_count-1][event_count].s = val; event_count++; // requires_status=s // requires_not=s // quest_text=s } } } } infile.close(); }
bool ezFileParser::next() { std::string starts_with; new_section = false; while (!infile.eof()) { line = getLine(infile); if (line.length() == 0) continue; starts_with = line.at(0); if (starts_with == "#") continue; if (starts_with == "[") { new_section = true; section = parse_section_title(line); continue; } parse_key_pair(line, key, val); return true; } return false; }
/** * 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; }
/** * Advance to the next key pair * Take note if a new section header is encountered * * @return false if EOF, otherwise true */ bool FileParser::next() { std::string starts_with; new_section = false; while (current_index < filenames.size()) { while (infile.good()) { if (include_fp) { if (include_fp->next()) { new_section = include_fp->new_section; section = include_fp->section; key = include_fp->key; val = include_fp->val; return true; } else { include_fp->close(); delete include_fp; include_fp = NULL; continue; } } line = trim(getLine(infile)); line_number++; // skip ahead if this line is empty if (line.length() == 0) continue; starts_with = line.at(0); // skip ahead if this line is a comment if (starts_with == "#") continue; // set new section if this line is a section declaration if (starts_with == "[") { new_section = true; section = parse_section_title(line); // keep searching for a key-pair continue; } // skip the string used to combine files if (line == "APPEND") continue; // read from a separate file std::size_t first_space = line.find(' '); if (first_space != std::string::npos) { std::string directive = line.substr(0, first_space); if (directive == "INCLUDE") { std::string tmp = line.substr(first_space+1); include_fp = new FileParser(); if (!include_fp || !include_fp->open(tmp)) { delete include_fp; include_fp = NULL; } continue; } } // this is a keypair. Perform basic parsing and return parse_key_pair(line, key, val); return true; } infile.close(); infile.clear(); current_index++; if (current_index == filenames.size()) return false; line_number = 0; const std::string current_filename = filenames[current_index]; infile.open(current_filename.c_str(), std::ios::in); if (!infile.is_open()) { if (!errormessage.empty()) logError("FileParser: %s: %s", errormessage.c_str(), current_filename.c_str()); infile.clear(); return false; } // a new file starts a new section new_section = true; } // hit the end of file return false; }
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(); }
/** * All powers are defined in powers/powers.txt */ void PowerManager::loadPowers() { ifstream infile; string line; string key; string val; string starts_with; int input_id = 0; infile.open("powers/powers.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 } if (starts_with == "[") { // not actually necessary. We know we're at a new power when // we see a new id key. } else { // this is data. treatment depends on key parse_key_pair(line, key, val); key = trim(key, ' '); val = trim(val, ' '); // id needs to be the first component of each power. That is how we write // data to the correct power. if (key == "id") { input_id = atoi(val.c_str()); } else if (key == "type") { if (val == "single") powers[input_id].type = POWTYPE_SINGLE; else if (val == "effect") powers[input_id].type = POWTYPE_EFFECT; else if (val == "missile") powers[input_id].type = POWTYPE_MISSILE; else if (val == "repeater") powers[input_id].type = POWTYPE_REPEATER; } else if (key == "name") { powers[input_id].name = val; } else if (key == "description") { powers[input_id].description = val; } else if (key == "icon") { powers[input_id].icon = atoi(val.c_str()); } else if (key == "new_state") { if (val == "swing") powers[input_id].new_state = POWSTATE_SWING; else if (val == "shoot") powers[input_id].new_state = POWSTATE_SHOOT; else if (val == "cast") powers[input_id].new_state = POWSTATE_CAST; else if (val == "block") powers[input_id].new_state = POWSTATE_BLOCK; } else if (key == "face") { if (val == "true") powers[input_id].face = true; } // power requirements else if (key == "requires_physical_weapon") { if (val == "true") powers[input_id].requires_physical_weapon = true; } else if (key == "requires_mental_weapon") { if (val == "true") powers[input_id].requires_mental_weapon = true; } else if (key == "requires_offense_weapon") { if (val == "true") powers[input_id].requires_offense_weapon = true; } else if (key == "requires_mp") { powers[input_id].requires_mp = atoi(val.c_str()); } else if (key == "requires_los") { if (val == "true") powers[input_id].requires_los = true; } else if (key == "requires_empty_target") { if (val == "true") powers[input_id].requires_empty_target = true; } else if (key == "requires_item") { powers[input_id].requires_item = atoi(val.c_str()); } // animation info else if (key == "gfx") { powers[input_id].gfx_index = loadGFX(val); } else if (key == "sfx") { powers[input_id].sfx_index = loadSFX(val); } else if (key == "rendered") { if (val == "true") powers[input_id].rendered = true; } else if (key == "directional") { if (val == "true") powers[input_id].directional = true; } else if (key == "visual_random") { powers[input_id].visual_random = atoi(val.c_str()); } else if (key == "visual_option") { powers[input_id].visual_option = atoi(val.c_str()); } else if (key == "aim_assist") { powers[input_id].aim_assist = atoi(val.c_str()); } else if (key == "speed") { powers[input_id].speed = atoi(val.c_str()); } else if (key == "lifespan") { powers[input_id].lifespan = atoi(val.c_str()); } else if (key == "frame_loop") { powers[input_id].frame_loop = atoi(val.c_str()); } else if (key == "frame_duration") { powers[input_id].frame_duration = atoi(val.c_str()); } else if (key == "frame_size") { val = val + ","; powers[input_id].frame_size.x = eatFirstInt(val, ','); powers[input_id].frame_size.y = eatFirstInt(val, ','); } else if (key == "frame_offset") { val = val + ","; powers[input_id].frame_offset.x = eatFirstInt(val, ','); powers[input_id].frame_offset.y = eatFirstInt(val, ','); } else if (key == "floor") { if (val == "true") powers[input_id].floor = true; } else if (key == "active_frame") { powers[input_id].active_frame = atoi(val.c_str()); } else if (key == "complete_animation") { if (val == "true") powers[input_id].complete_animation = true; } // hazard traits else if (key == "use_hazard") { if (val == "true") powers[input_id].use_hazard = true; } else if (key == "no_attack") { if (val == "true") powers[input_id].no_attack = true; } else if (key == "radius") { powers[input_id].radius = atoi(val.c_str()); } else if (key == "base_damage") { if (val == "none") powers[input_id].base_damage = BASE_DAMAGE_NONE; else if (val == "melee") powers[input_id].base_damage = BASE_DAMAGE_MELEE; else if (val == "ranged") powers[input_id].base_damage = BASE_DAMAGE_RANGED; else if (val == "ment") powers[input_id].base_damage = BASE_DAMAGE_MENT; } else if (key == "damage_multiplier") { powers[input_id].damage_multiplier = atoi(val.c_str()); } else if (key == "starting_pos") { if (val == "source") powers[input_id].starting_pos = STARTING_POS_SOURCE; else if (val == "target") powers[input_id].starting_pos = STARTING_POS_TARGET; else if (val == "melee") powers[input_id].starting_pos = STARTING_POS_MELEE; } else if (key == "multitarget") { if (val == "true") powers[input_id].multitarget = true; } else if (key == "trait_armor_penetration") { if (val == "true") powers[input_id].trait_armor_penetration = true; } else if (key == "trait_crits_impaired") { powers[input_id].trait_crits_impaired = atoi(val.c_str()); } else if (key == "trait_elemental") { if (val == "wood") powers[input_id].trait_elemental = ELEMENT_WOOD; else if (val == "metal") powers[input_id].trait_elemental = ELEMENT_METAL; else if (val == "wind") powers[input_id].trait_elemental = ELEMENT_WIND; else if (val == "water") powers[input_id].trait_elemental = ELEMENT_WATER; else if (val == "earth") powers[input_id].trait_elemental = ELEMENT_EARTH; else if (val == "fire") powers[input_id].trait_elemental = ELEMENT_FIRE; else if (val == "shadow") powers[input_id].trait_elemental = ELEMENT_SHADOW; else if (val == "light") powers[input_id].trait_elemental = ELEMENT_LIGHT; } //steal effects else if (key == "hp_steal") { powers[input_id].hp_steal = atoi(val.c_str()); } else if (key == "mp_steal") { powers[input_id].mp_steal = atoi(val.c_str()); } //missile modifiers else if (key == "missile_num") { powers[input_id].missile_num = atoi(val.c_str()); } else if (key == "missile_angle") { powers[input_id].missile_angle = atoi(val.c_str()); } else if (key == "angle_variance") { powers[input_id].angle_variance = atoi(val.c_str()); } else if (key == "speed_variance") { powers[input_id].speed_variance = atoi(val.c_str()); } //repeater modifiers else if (key == "delay") { powers[input_id].delay = atoi(val.c_str()); } else if (key == "start_frame") { powers[input_id].start_frame = atoi(val.c_str()); } else if (key == "repeater_num") { powers[input_id].repeater_num = atoi(val.c_str()); } // buff/debuff durations else if (key == "bleed_duration") { powers[input_id].bleed_duration = atoi(val.c_str()); } else if (key == "stun_duration") { powers[input_id].stun_duration = atoi(val.c_str()); } else if (key == "slow_duration") { powers[input_id].slow_duration = atoi(val.c_str()); } else if (key == "immobilize_duration") { powers[input_id].immobilize_duration = atoi(val.c_str()); } else if (key == "immunity_duration") { powers[input_id].immunity_duration = atoi(val.c_str()); } else if (key == "haste_duration") { powers[input_id].haste_duration = atoi(val.c_str()); } else if (key == "hot_duration") { powers[input_id].hot_duration = atoi(val.c_str()); } else if (key == "hot_value") { powers[input_id].hot_value = atoi(val.c_str()); } // buffs else if (key == "buff_heal") { if (val == "true") powers[input_id].buff_heal = true; } else if (key == "buff_shield") { if (val == "true") powers[input_id].buff_shield = true; } else if (key == "buff_teleport") { if (val == "true") powers[input_id].buff_teleport = true; } else if (key == "buff_immunity") { if (val == "true") powers[input_id].buff_immunity = true; } else if (key == "buff_restore_hp") { powers[input_id].buff_restore_hp = atoi(val.c_str()); } else if (key == "buff_restore_mp") { powers[input_id].buff_restore_mp = atoi(val.c_str()); } // pre and post power effects else if (key == "post_power") { powers[input_id].post_power = atoi(val.c_str()); } else if (key == "wall_power") { powers[input_id].wall_power = atoi(val.c_str()); } else if (key == "allow_power_mod") { if (val == "true") powers[input_id].allow_power_mod = true; } } } } } infile.close(); }