本文整理汇总了C++中FileParser::nextValue方法的典型用法代码示例。如果您正苦于以下问题:C++ FileParser::nextValue方法的具体用法?C++ FileParser::nextValue怎么用?C++ FileParser::nextValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileParser
的用法示例。
在下文中一共展示了FileParser::nextValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadNPC
void Map::loadNPC(FileParser &infile) {
std::string s;
if (infile.key == "type") {
// @ATTR npc.type|string|Type of NPC
npcs.back().id = infile.val;
}
if (infile.key == "requires_status") {
// @ATTR npc.requires_status|string|Status required for NPC load. There can be multiple states, separated by comma
while ( (s = infile.nextValue()) != "")
npcs.back().requires_status.push_back(s);
}
if (infile.key == "requires_not_status") {
// @ATTR npc.requires_not|string|Status required to be missing for NPC load. There can be multiple states, separated by comma
while ( (s = infile.nextValue()) != "")
npcs.back().requires_not_status.push_back(s);
}
else if (infile.key == "location") {
// @ATTR npc.location|[x(integer), y(integer)]|Location of NPC
npcs.back().pos.x = toInt(infile.nextValue()) + 0.5f;
npcs.back().pos.y = toInt(infile.nextValue()) + 0.5f;
}
}
示例2: loadNPC
void Map::loadNPC(FileParser &infile) {
std::string s;
if (infile.key == "type") {
// @ATTR npc.type|string|Filename of an NPC definition.
npcs.back().id = infile.val;
}
else if (infile.key == "requires_status") {
// @ATTR npc.requires_status|string|Status required for NPC load. There can be multiple states, separated by comma
while ( (s = infile.nextValue()) != "")
npcs.back().requires_status.push_back(s);
}
else if (infile.key == "requires_not_status") {
// @ATTR npc.requires_not_status|string|Status required to be missing for NPC load. There can be multiple states, separated by comma
while ( (s = infile.nextValue()) != "")
npcs.back().requires_not_status.push_back(s);
}
else if (infile.key == "location") {
// @ATTR npc.location|[x(integer), y(integer)]|Location of NPC
npcs.back().pos.x = static_cast<float>(toInt(infile.nextValue())) + 0.5f;
npcs.back().pos.y = static_cast<float>(toInt(infile.nextValue())) + 0.5f;
// make sure this NPC has a collision tile
// otherwise, it becomes possible for the player to stand "inside" the npc, which will trigger their event infinitely
if (collision_layer != -1) {
unsigned tile_x = static_cast<unsigned>(npcs.back().pos.x);
unsigned tile_y = static_cast<unsigned>(npcs.back().pos.y);
if (tile_x < static_cast<unsigned>(w) && tile_y < static_cast<unsigned>(h)) {
short unsigned int& tile = layers[collision_layer][tile_x][tile_y];
if (tile == BLOCKS_NONE) {
logError("Map: NPC at (%d, %d) does not have a collision tile. Creating one now.", tile_x, tile_y);
tile = BLOCKS_MOVEMENT_HIDDEN;
}
}
}
}
else {
infile.error("Map: '%s' is not a valid key.", infile.key.c_str());
}
}
示例3: loadHeader
void Map::loadHeader(FileParser &infile) {
if (infile.key == "title") {
this->title = msg->get(infile.val);
}
else if (infile.key == "width") {
this->w = toInt(infile.val);
}
else if (infile.key == "height") {
this->h = toInt(infile.val);
}
else if (infile.key == "tileset") {
this->tileset = infile.val;
}
else if (infile.key == "music") {
music_filename = infile.val;
}
else if (infile.key == "location") {
spawn.x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
spawn.y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
spawn_dir = toInt(infile.nextValue());
}
}
示例4: loadSets
void ItemManager::loadSets(const string& filename) {
FileParser infile;
if (!infile.open(filename)) {
fprintf(stderr, "Unable to open %s!\n", filename.c_str());
return;
}
int id = 0;
bool id_line;
while (infile.next()) {
if (infile.key == "id") {
id_line = true;
id = toInt(infile.val);
if (id > 0 && id >= (int)item_sets.size()) {
// *2 to amortize the resizing to O(log(n)).
item_sets.resize((2*id) + 1);
}
} else id_line = false;
if (id < 1) {
if (id_line) fprintf(stderr, "Item set index out of bounds 1-%d, skipping\n", INT_MAX);
continue;
}
if (id_line) continue;
if (infile.key == "name") {
item_sets[id].name = msg->get(infile.val);
}
else if (infile.key == "items") {
string item_id = infile.nextValue();
while (item_id != "") {
if (toInt(item_id) > 0) {
items[toInt(item_id)].set = id;
item_sets[id].items.push_back(toInt(item_id));
item_id = infile.nextValue();
} else fprintf(stderr, "Item index inside item set %s definition out of bounds 1-%d, skipping item\n", item_sets[id].name.c_str(), INT_MAX);
}
}
else if (infile.key == "color") {
item_sets[id].color.r = toInt(infile.nextValue());
item_sets[id].color.g = toInt(infile.nextValue());
item_sets[id].color.b = toInt(infile.nextValue());
}
else if (infile.key == "bonus") {
Set_bonus bonus;
bonus.requirement = toInt(infile.nextValue());
bonus.bonus_stat = infile.nextValue();
bonus.bonus_val = toInt(infile.nextValue());
item_sets[id].bonus.push_back(bonus);
}
}
infile.close();
}
示例5: loadEnemyGroup
void Map::loadEnemyGroup(FileParser &infile, Map_Group *group) {
if (infile.key == "type") {
group->category = infile.val;
}
else if (infile.key == "level") {
group->levelmin = toInt(infile.nextValue());
group->levelmax = toInt(infile.nextValue());
}
else if (infile.key == "location") {
group->pos.x = toInt(infile.nextValue());
group->pos.y = toInt(infile.nextValue());
group->area.x = toInt(infile.nextValue());
group->area.y = toInt(infile.nextValue());
}
else if (infile.key == "number") {
group->numbermin = toInt(infile.nextValue());
group->numbermax = toInt(infile.nextValue());
}
else if (infile.key == "chance") {
float n = toInt(infile.nextValue()) / 100.0f;
group->chance = std::min(1.0f, std::max(0.0f, n));
}
}
示例6: getLanguagesList
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;
}
示例7: getLanguagesList
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;
}
示例8: readGameSlot
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 << "saves/save" << (slot+1) << ".txt";
if (!infile.open(filename.str())) return;
while (infile.next()) {
// load (key=value) pairs
if (infile.key == "name")
stats[slot].name = 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") {
equipped[slot][0] = atoi(infile.nextValue().c_str());
equipped[slot][1] = atoi(infile.nextValue().c_str());
equipped[slot][2] = atoi(infile.nextValue().c_str());
}
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);
}
示例9: loadEnemy
void Map::loadEnemy(FileParser &infile) {
if (infile.key == "type") {
// @ATTR enemy.type|string|Enemy type
enemies.back().type = infile.val;
}
else if (infile.key == "location") {
// @ATTR enemy.location|[x(integer), y(integer)]|Location of enemy
enemies.back().pos.x = toInt(infile.nextValue()) + 0.5f;
enemies.back().pos.y = toInt(infile.nextValue()) + 0.5f;
}
else if (infile.key == "direction") {
// @ATTR enemy.direction|integer|Direction of enemy
enemies.back().direction = toInt(infile.val);
}
else if (infile.key == "waypoints") {
// @ATTR enemy.waypoint|[x(integer), y(integer)]|Enemy waypoint
std::string none = "";
std::string a = infile.nextValue();
std::string b = infile.nextValue();
while (a != none) {
FPoint p;
p.x = toInt(a) + 0.5f;
p.y = toInt(b) + 0.5f;
enemies.back().waypoints.push(p);
a = infile.nextValue();
b = infile.nextValue();
}
}
else if (infile.key == "wander_area") {
// @ATTR enemy.wander_area|[x(integer),y(integer),w(integer),h(integer)]|Wander area for the enemy.
enemies.back().wander = true;
enemies.back().wander_area.x = toInt(infile.nextValue());
enemies.back().wander_area.y = toInt(infile.nextValue());
enemies.back().wander_area.w = toInt(infile.nextValue());
enemies.back().wander_area.h = toInt(infile.nextValue());
}
// @ATTR enemy.requires_status|string|Status required for enemy load
else if (infile.key == "requires_status")
enemies.back().requires_status.push_back(infile.nextValue());
// @ATTR enemy.requires_not_status|string|Status required to be missing for enemy load
else if (infile.key == "requires_not_status")
enemies.back().requires_not_status.push_back(infile.nextValue());
}
示例10: loadTilesetSettings
void loadTilesetSettings() {
FileParser infile;
// load tileset settings from engine config
if (infile.open(mods->locate("engine/tileset_config.txt").c_str())) {
while (infile.next()) {
if (infile.key == "units_per_tile") {
UNITS_PER_TILE = atoi(infile.val.c_str());
}
else if (infile.key == "tile_size") {
TILE_W = atoi(infile.nextValue().c_str());
TILE_H = atoi(infile.nextValue().c_str());
TILE_W_HALF = TILE_W /2;
TILE_H_HALF = TILE_H /2;
}
else if (infile.key == "orientation") {
if (infile.val == "isometric")
TILESET_ORIENTATION = TILESET_ISOMETRIC;
else if (infile.val == "orthogonal")
TILESET_ORIENTATION = TILESET_ORTHOGONAL;
}
}
infile.close();
}
else {
fprintf(stderr, "No tileset config found! Defaulting to 64x32 isometric tiles.\n");
}
// Init automatically calculated parameters
TILE_SHIFT = log2(UNITS_PER_TILE);
VIEW_W_HALF = VIEW_W / 2;
VIEW_H_HALF = VIEW_H / 2;
if (TILESET_ORIENTATION == TILESET_ISOMETRIC) {
UNITS_PER_PIXEL_X = UNITS_PER_TILE / TILE_W * 2;
UNITS_PER_PIXEL_Y = UNITS_PER_TILE / TILE_H * 2;
}
else { // TILESET_ORTHOGONAL
UNITS_PER_PIXEL_X = UNITS_PER_TILE / TILE_W;
UNITS_PER_PIXEL_Y = UNITS_PER_TILE / TILE_H;
}
}
示例11: parseEnemyFileAndStore
void EnemyGroupManager::parseEnemyFileAndStore(const string& filename) {
FileParser infile;
if (infile.open(mods->locate("enemies/" + filename))) {
Enemy_Level new_enemy;
new_enemy.type = filename.substr(0, filename.length()-4); //removes the ".txt" from the filename
while (infile.next()) {
if (infile.key == "level") {
new_enemy.level = atoi(infile.val.c_str());
}
else if (infile.key == "rarity") {
new_enemy.rarity = infile.val.c_str();
}
else if (infile.key == "categories") {
string cat;
while ( (cat = infile.nextValue()) != "") {
_categories[cat].push_back(new_enemy);
}
}
}
infile.close();
}
}
示例12: loadTilesetSettings
void loadTilesetSettings() {
FileParser infile;
// load tileset settings from engine config
if (infile.open("engine/tileset_config.txt", true, true, "Unable to open engine/tileset_config.txt! Defaulting to 64x32 isometric tiles.\n")) {
while (infile.next()) {
if (infile.key == "tile_size") {
TILE_W = toInt(infile.nextValue());
TILE_H = toInt(infile.nextValue());
TILE_W_HALF = TILE_W /2;
TILE_H_HALF = TILE_H /2;
}
else if (infile.key == "orientation") {
if (infile.val == "isometric")
TILESET_ORIENTATION = TILESET_ISOMETRIC;
else if (infile.val == "orthogonal")
TILESET_ORIENTATION = TILESET_ORTHOGONAL;
}
}
infile.close();
}
// Init automatically calculated parameters
VIEW_W_HALF = VIEW_W / 2;
VIEW_H_HALF = VIEW_H / 2;
if (TILESET_ORIENTATION == TILESET_ISOMETRIC) {
UNITS_PER_PIXEL_X = 2.0f / TILE_W;
UNITS_PER_PIXEL_Y = 2.0f / TILE_H;
}
else { // TILESET_ORTHOGONAL
UNITS_PER_PIXEL_X = 1.0f / TILE_W;
UNITS_PER_PIXEL_Y = 1.0f / TILE_H;
}
if (UNITS_PER_PIXEL_X == 0 || UNITS_PER_PIXEL_Y == 0) {
fprintf(stderr, "One of UNITS_PER_PIXEL values is zero! %dx%d\n", (int)UNITS_PER_PIXEL_X, (int)UNITS_PER_PIXEL_Y);
SDL_Quit();
exit(1);
}
}
示例13: parseEnemyFilesAndStore
void EnemyGroupManager::parseEnemyFilesAndStore() {
std::vector<std::string> enemy_paths = mods->list("enemies", false);
for (unsigned i=0; i<enemy_paths.size(); ++i) {
FileParser infile;
// @CLASS EnemyGroupManager|Description of enemies in enemies/
if (!infile.open(enemy_paths[i]))
return;
Enemy_Level new_enemy;
infile.new_section = true;
bool first = true;
while (infile.next()) {
if (infile.new_section || first) {
new_enemy.type = enemy_paths[i];
first = false;
}
if (infile.key == "level") {
// @ATTR level|integer|Level of the enemy
new_enemy.level = toInt(infile.val);
}
else if (infile.key == "rarity") {
// @ATTR rarity|[common,uncommon,rare]|Enemy rarity
new_enemy.rarity = infile.val;
}
else if (infile.key == "categories") {
// @ATTR categories|string,...|Comma separated list of enemy categories
string cat;
while ( (cat = infile.nextValue()) != "") {
_categories[cat].push_back(new_enemy);
}
}
}
infile.close();
}
}
示例14: parseEnemyFilesAndStore
void EnemyGroupManager::parseEnemyFilesAndStore() {
FileParser infile;
// @CLASS enemies|Describing enemies files in enemies/
if (!infile.open("enemies", true, false))
return;
Enemy_Level new_enemy;
infile.new_section = true;
bool first = true;
while (infile.next()) {
if (infile.new_section || first) {
const string fname = infile.getFileName();
const int firstpos = fname.rfind("/") + 1;
const int len = fname.length() - firstpos - 4; //removes the ".txt" from the filename
new_enemy.type = fname.substr(firstpos, len);
first = false;
}
if (infile.key == "level") {
// @ATTR level|integer|Level of the enemy
new_enemy.level = toInt(infile.val);
}
else if (infile.key == "rarity") {
// @ATTR rarity|[common,uncommon,rare]|Enemy rarity
new_enemy.rarity = infile.val;
}
else if (infile.key == "categories") {
// @ATTR categories|string,...|Comma separated list of enemy categories
string cat;
while ( (cat = infile.nextValue()) != "") {
_categories[cat].push_back(new_enemy);
}
}
}
infile.close();
}
示例15: load
/**
* load a statblock, typically for an enemy definition
*/
void StatBlock::load(const string& filename) {
FileParser infile;
int num = 0;
if (infile.open(mods->locate(filename))) {
while (infile.next()) {
if (isInt(infile.val)) num = toInt(infile.val);
if (infile.key == "name") name = msg->get(infile.val);
else if (infile.key == "humanoid") {
if (infile.val == "true") humanoid = true;
}
else if (infile.key == "sfx_prefix") sfx_prefix = infile.val;
else if (infile.key == "gfx_prefix") gfx_prefix = infile.val;
else if (infile.key == "level") level = num;
// enemy death rewards and events
else if (infile.key == "xp") xp = num;
else if (infile.key == "loot_chance") loot_chance = num;
else if (infile.key == "item_class") {
string str;
while ((str = infile.nextValue()) != "") {
if (!isInt(str)) {
item_classes.push_back(str);
item_class_prob.push_back(1);
item_class_prob_sum++;
}
else {
num = toInt(str);
item_class_prob[item_classes.size()-1] = num;
item_class_prob_sum += num - 1; // one was already added, so add one less
}
}
}
else if (infile.key == "defeat_status") defeat_status = infile.val;
else if (infile.key == "first_defeat_loot") first_defeat_loot = num;
else if (infile.key == "quest_loot") {
quest_loot_requires = infile.nextValue();
quest_loot_not = infile.nextValue();
quest_loot_id = toInt(infile.nextValue());
}
// combat stats
else if (infile.key == "hp") {
hp = num;
maxhp = num;
}
else if (infile.key == "mp") {
mp = num;
maxmp = num;
}
else if (infile.key == "cooldown") cooldown = num;
else if (infile.key == "accuracy") accuracy = num;
else if (infile.key == "avoidance") avoidance = num;
else if (infile.key == "dmg_melee_min") dmg_melee_min = num;
else if (infile.key == "dmg_melee_max") dmg_melee_max = num;
else if (infile.key == "dmg_ment_min") dmg_ment_min = num;
else if (infile.key == "dmg_ment_max") dmg_ment_max = num;
else if (infile.key == "dmg_ranged_min") dmg_ranged_min = num;
else if (infile.key == "dmg_ranged_max") dmg_ranged_max = num;
else if (infile.key == "absorb_min") absorb_min = num;
else if (infile.key == "absorb_max") absorb_max = num;
// behavior stats
else if (infile.key == "flying") {
if (num == 1) flying = true;
}
else if (infile.key == "intangible") {
if (num == 1) intangible = true;
}
else if (infile.key == "facing") {
if (num == 0) facing = false;
}
else if (infile.key == "waypoint_pause") waypoint_pause = num;
else if (infile.key == "speed") speed = num;
else if (infile.key == "dspeed") dspeed = num;
else if (infile.key == "turn_delay") turn_delay = num;
else if (infile.key == "chance_pursue") chance_pursue = num;
else if (infile.key == "chance_flee") chance_flee = num;
else if (infile.key == "chance_melee_phys") power_chance[MELEE_PHYS] = num;
else if (infile.key == "chance_melee_ment") power_chance[MELEE_MENT] = num;
else if (infile.key == "chance_ranged_phys") power_chance[RANGED_PHYS] = num;
else if (infile.key == "chance_ranged_ment") power_chance[RANGED_MENT] = num;
else if (infile.key == "power_melee_phys") power_index[MELEE_PHYS] = num;
else if (infile.key == "power_melee_ment") power_index[MELEE_MENT] = num;
else if (infile.key == "power_ranged_phys") power_index[RANGED_PHYS] = num;
else if (infile.key == "power_ranged_ment") power_index[RANGED_MENT] = num;
else if (infile.key == "power_beacon") power_index[BEACON] = num;
else if (infile.key == "cooldown_melee_phys") power_cooldown[MELEE_PHYS] = num;
else if (infile.key == "cooldown_melee_ment") power_cooldown[MELEE_MENT] = num;
else if (infile.key == "cooldown_ranged_phys") power_cooldown[RANGED_PHYS] = num;
else if (infile.key == "cooldown_ranged_ment") power_cooldown[RANGED_MENT] = num;
else if (infile.key == "power_on_hit") power_index[ON_HIT] = num;
else if (infile.key == "power_on_death") power_index[ON_DEATH] = num;
//.........这里部分代码省略.........