本文整理汇总了C++中FileParser::close方法的典型用法代码示例。如果您正苦于以下问题:C++ FileParser::close方法的具体用法?C++ FileParser::close怎么用?C++ FileParser::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileParser
的用法示例。
在下文中一共展示了FileParser::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadTilesetSettings
void loadTilesetSettings() {
// reset defaults
UNITS_PER_PIXEL_X = 2;
UNITS_PER_PIXEL_Y = 4;
TILE_W = 64;
TILE_H = 32;
TILE_W_HALF = TILE_W/2;
TILE_H_HALF = TILE_H/2;
TILESET_ISOMETRIC = 0;
TILESET_ORTHOGONAL = 1;
TILESET_ORIENTATION = TILESET_ISOMETRIC;
FileParser infile;
// load tileset settings from engine config
// @CLASS Settings: Tileset config|Description of engine/tileset_config.txt
if (infile.open("engine/tileset_config.txt", true, "Unable to open engine/tileset_config.txt! Defaulting to 64x32 isometric tiles.")) {
while (infile.next()) {
if (infile.key == "tile_size") {
// @ATTR tile_size|w (integet), h (integer)|The width and height of a tile.
TILE_W = static_cast<unsigned short>(toInt(infile.nextValue()));
TILE_H = static_cast<unsigned short>(toInt(infile.nextValue()));
TILE_W_HALF = TILE_W /2;
TILE_H_HALF = TILE_H /2;
}
else if (infile.key == "orientation") {
// @ATTR orientation|[isometric, orthogonal]|The perspective of tiles; isometric or orthogonal.
if (infile.val == "isometric")
TILESET_ORIENTATION = TILESET_ISOMETRIC;
else if (infile.val == "orthogonal")
TILESET_ORIENTATION = TILESET_ORTHOGONAL;
}
else {
infile.error("Settings: '%s' is not a valid key.", infile.key.c_str());
}
}
infile.close();
}
// Init automatically calculated parameters
if (TILESET_ORIENTATION == TILESET_ISOMETRIC) {
if (TILE_W > 0 && TILE_H > 0) {
UNITS_PER_PIXEL_X = 2.0f / TILE_W;
UNITS_PER_PIXEL_Y = 2.0f / TILE_H;
}
else {
logError("Settings: Tile dimensions must be greater than 0. Resetting to the default size of 64x32.");
TILE_W = 64;
TILE_H = 32;
}
}
else { // TILESET_ORTHOGONAL
if (TILE_W > 0 && TILE_H > 0) {
UNITS_PER_PIXEL_X = 1.0f / TILE_W;
UNITS_PER_PIXEL_Y = 1.0f / TILE_H;
}
else {
logError("Settings: Tile dimensions must be greater than 0. Resetting to the default size of 64x32.");
TILE_W = 64;
TILE_H = 32;
}
}
if (UNITS_PER_PIXEL_X == 0 || UNITS_PER_PIXEL_Y == 0) {
logError("Settings: One of UNITS_PER_PIXEL values is zero! %dx%d", static_cast<int>(UNITS_PER_PIXEL_X), static_cast<int>(UNITS_PER_PIXEL_Y));
Exit(1);
}
}
示例2: loadGame
//.........这里部分代码省略.........
else if (infile.key == "currency") {
currency = toInt(infile.val);
}
else if (infile.key == "equipped") {
menu->inv->inventory[EQUIPMENT].setItems(infile.val);
}
else if (infile.key == "equipped_quantity") {
menu->inv->inventory[EQUIPMENT].setQuantities(infile.val);
}
else if (infile.key == "carried") {
menu->inv->inventory[CARRIED].setItems(infile.val);
}
else if (infile.key == "carried_quantity") {
menu->inv->inventory[CARRIED].setQuantities(infile.val);
}
else if (infile.key == "spawn") {
mapr->teleport_mapname = infile.nextValue();
if (fileExists(mods->locate(mapr->teleport_mapname))) {
mapr->teleport_destination.x = toInt(infile.nextValue()) + 0.5f;
mapr->teleport_destination.y = toInt(infile.nextValue()) + 0.5f;
mapr->teleportation = true;
// prevent spawn.txt from putting us on the starting map
mapr->clearEvents();
}
else {
fprintf(stderr, "Unable to find %s, loading maps/spawn.txt\n", mapr->teleport_mapname.c_str());
mapr->teleport_mapname = "maps/spawn.txt";
mapr->teleport_destination.x = 1;
mapr->teleport_destination.y = 1;
mapr->teleportation = true;
}
}
else if (infile.key == "actionbar") {
for (int i=0; i<12; i++) {
hotkeys[i] = toInt(infile.nextValue());
if (hotkeys[i] < 0) {
fprintf(stderr, "Hotkey power on position %d has negative id, skipping\n", i);
hotkeys[i] = 0;
}
else if ((unsigned)hotkeys[i] > powers->powers.size()-1) {
fprintf(stderr, "Hotkey power id (%d) out of bounds 1-%d, skipping\n", hotkeys[i], (int)powers->powers.size());
hotkeys[i] = 0;
}
else if (hotkeys[i] != 0 && powers->powers[hotkeys[i]].name == "") {
fprintf(stderr, "Hotkey power with id=%d, found on position %d does not exist, skipping\n", hotkeys[i], i);
hotkeys[i] = 0;
}
}
menu->act->set(hotkeys);
}
else if (infile.key == "transformed") {
pc->stats.transform_type = infile.nextValue();
if (pc->stats.transform_type != "") {
pc->stats.transform_duration = -1;
pc->stats.manual_untransform = toBool(infile.nextValue());
}
}
else if (infile.key == "powers") {
string power;
while ( (power = infile.nextValue()) != "") {
if (toInt(power) > 0)
pc->stats.powers_list.push_back(toInt(power));
}
}
else if (infile.key == "campaign") camp->setAll(infile.val);
}
infile.close();
}
else fprintf(stderr, "Unable to open %s!\n", ss.str().c_str());
// add legacy currency to inventory
menu->inv->addCurrency(currency);
// apply stats, inventory, and powers
applyPlayerData();
// trigger passive effects here? Saved HP/MP values might depend on passively boosted HP/MP
// powers->activatePassives(pc->stats);
if (SAVE_HPMP) {
if (saved_hp < 0 || saved_hp > pc->stats.get(STAT_HP_MAX)) {
fprintf(stderr, "HP value is out of bounds, setting to maximum\n");
pc->stats.hp = pc->stats.get(STAT_HP_MAX);
}
else pc->stats.hp = saved_hp;
if (saved_mp < 0 || saved_mp > pc->stats.get(STAT_MP_MAX)) {
fprintf(stderr, "MP value is out of bounds, setting to maximum\n");
pc->stats.mp = pc->stats.get(STAT_MP_MAX);
}
else pc->stats.mp = saved_mp;
}
else {
pc->stats.hp = pc->stats.get(STAT_HP_MAX);
pc->stats.mp = pc->stats.get(STAT_MP_MAX);
}
// reset character menu
menu->chr->refreshStats();
}
示例3: if
MenuTalker::MenuTalker(MenuManager *_menu)
: Menu()
, menu(_menu)
, portrait(NULL)
, dialog_node(0)
, event_cursor(0)
, font_who("font_regular")
, font_dialog("font_regular")
, color_normal(font->getColor("menu_normal"))
, npc(NULL)
, advanceButton(new WidgetButton("images/menus/buttons/right.png"))
, closeButton(new WidgetButton("images/menus/buttons/button_x.png")) {
setBackground("images/menus/dialog_box.png");
// Load config settings
FileParser infile;
// @CLASS MenuTalker|Description of menus/talker.txt
if(infile.open("menus/talker.txt")) {
while(infile.next()) {
if (parseMenuKey(infile.key, infile.val))
continue;
// @ATTR close|x (integer), y (integer)|Position of the close button.
if(infile.key == "close") {
Point pos = toPoint(infile.val);
closeButton->setBasePos(pos.x, pos.y);
}
// @ATTR advance|x (integer), y (integer)|Position of the button to advance dialog.
else if(infile.key == "advance") {
Point pos = toPoint(infile.val);
advanceButton->setBasePos(pos.x, pos.y);
}
// @ATTR dialogbox|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the text box graphics.
else if (infile.key == "dialogbox") dialog_pos = toRect(infile.val);
// @ATTR dialogtext|x (integer), y (integer), w (integer), h (integer)|Rectangle where the dialog text is placed.
else if (infile.key == "dialogtext") text_pos = toRect(infile.val);
// @ATTR text_offset|x (integer), y (integer)|Margins for the left/right and top/bottom of the dialog text.
else if (infile.key == "text_offset") text_offset = toPoint(infile.val);
// @ATTR portrait_he|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the NPC portrait graphics.
else if (infile.key == "portrait_he") portrait_he = toRect(infile.val);
// @ATTR portrait_you|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the player's portrait graphics.
else if (infile.key == "portrait_you") portrait_you = toRect(infile.val);
// @ATTR font_who|string|Font style to use for the name of the currently talking person.
else if (infile.key == "font_who") font_who = infile.val;
// @ATTR font_dialog|string|Font style to use for the dialog text.
else if (infile.key == "font_dialog") font_dialog = infile.val;
else infile.error("MenuTalker: '%s' is not a valid key.", infile.key.c_str());
}
infile.close();
}
label_name = new WidgetLabel();
label_name->setBasePos(text_pos.x + text_offset.x, text_pos.y + text_offset.y);
textbox = new WidgetScrollBox(text_pos.w, text_pos.h-(text_offset.y*2));
textbox->setBasePos(text_pos.x, text_pos.y + text_offset.y);
tablist.add(advanceButton);
tablist.add(closeButton);
tablist.add(textbox);
align();
}
示例4: load
//.........这里部分代码省略.........
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "requires_item") {
e->x = atoi(infile.nextValue().c_str());
// add repeating requires_item
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events[event_count-1].comp_num++;
e = &events[event_count-1].components[events[event_count-1].comp_num];
e->type = infile.key;
e->x = atoi(repeat_val.c_str());
repeat_val = infile.nextValue();
}
}
else if (infile.key == "set_status") {
e->s = infile.nextValue();
// add repeating set_status
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events[event_count-1].comp_num++;
e = &events[event_count-1].components[events[event_count-1].comp_num];
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "unset_status") {
e->s = infile.nextValue();
// add repeating unset_status
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events[event_count-1].comp_num++;
e = &events[event_count-1].components[events[event_count-1].comp_num];
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "remove_item") {
e->x = atoi(infile.nextValue().c_str());
// add repeating remove_item
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events[event_count-1].comp_num++;
e = &events[event_count-1].components[events[event_count-1].comp_num];
e->type = infile.key;
e->x = atoi(repeat_val.c_str());
repeat_val = infile.nextValue();
}
}
else if (infile.key == "reward_xp") {
e->x = atoi(infile.val.c_str());
}
else if (infile.key == "power") {
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;
}
if (group_awaiting_queue){
push_enemy_group(new_group);
group_awaiting_queue = false;
}
}
if (this->new_music) {
loadMusic();
this->new_music = false;
}
tset.load(this->tileset);
return 0;
}
示例5: readConfig
//.........这里部分代码省略.........
else if (infile.key == "dbuf_note") {
dbuf_note_lb->setX(frame.x + x1);
dbuf_note_lb->setY(frame.y + y1);
dbuf_note_lb->set(msg->get("Disable for performance"));
child_widget.push_back(dbuf_note_lb);
optiontab[child_widget.size()-1] = 0;
}
else if (infile.key == "test_note") {
test_note_lb->setX(frame.x + x1);
test_note_lb->setY(frame.y + y1);
test_note_lb->set(msg->get("Experimental"));
child_widget.push_back(test_note_lb);
optiontab[child_widget.size()-1] = 0;
}
else if (infile.key == "handheld_note") {
handheld_note_lb->setX(frame.x + x1);
handheld_note_lb->setY(frame.y + y1);
handheld_note_lb->set(msg->get("For handheld devices"));
child_widget.push_back(handheld_note_lb);
optiontab[child_widget.size()-1] = 3;
}
//buttons
else if (infile.key == "activemods_shiftup") {
activemods_shiftup_btn->pos.x = frame.x + x1;
activemods_shiftup_btn->pos.y = frame.y + y1;
activemods_shiftup_btn->refresh();
child_widget.push_back(activemods_shiftup_btn);
optiontab[child_widget.size()-1] = 5;
}
else if (infile.key == "activemods_shiftdown") {
activemods_shiftdown_btn->pos.x = frame.x + x1;
activemods_shiftdown_btn->pos.y = frame.y + y1;
activemods_shiftdown_btn->refresh();
child_widget.push_back(activemods_shiftdown_btn);
optiontab[child_widget.size()-1] = 5;
}
else if (infile.key == "activemods_deactivate") {
activemods_deactivate_btn->label = msg->get("<< Disable");
activemods_deactivate_btn->pos.x = frame.x + x1;
activemods_deactivate_btn->pos.y = frame.y + y1;
activemods_deactivate_btn->refresh();
child_widget.push_back(activemods_deactivate_btn);
optiontab[child_widget.size()-1] = 5;
}
else if (infile.key == "inactivemods_activate") {
inactivemods_activate_btn->label = msg->get("Enable >>");
inactivemods_activate_btn->pos.x = frame.x + x1;
inactivemods_activate_btn->pos.y = frame.y + y1;
inactivemods_activate_btn->refresh();
child_widget.push_back(inactivemods_activate_btn);
optiontab[child_widget.size()-1] = 5;
}
else if (infile.key == "secondary_offset") {
offset_x = x1;
offset_y = y1;
}
else if (infile.key == "keybinds_bg_color") {
// background color for keybinds scrollbox
scrollpane_color.r = x1;
scrollpane_color.g = y1;
scrollpane_color.b = x2;
}
else if (infile.key == "scrollpane") {
scrollpane.x = x1;
scrollpane.y = y1;
scrollpane.w = x2;
scrollpane.h = y2;
}
else if (infile.key == "scrollpane_contents") {
scrollpane_contents = x1;
}
if (setting_num > -1 && setting_num < 29) {
//keybindings
settings_lb[setting_num]->setX(x1);
settings_lb[setting_num]->setY(y1);
settings_key[setting_num]->pos.x = x2;
settings_key[setting_num]->pos.y = y2;
}
}
infile.close();
}
// Allocate KeyBindings ScrollBox
input_scrollbox = new WidgetScrollBox(scrollpane.w, scrollpane.h);
input_scrollbox->pos.x = scrollpane.x + frame.x;
input_scrollbox->pos.y = scrollpane.y + frame.y;
input_scrollbox->bg.r = scrollpane_color.r;
input_scrollbox->bg.g = scrollpane_color.g;
input_scrollbox->bg.b = scrollpane_color.b;
input_scrollbox->transparent = false;
input_scrollbox->resize(scrollpane_contents);
// Set positions of secondary key bindings
for (unsigned int i = 29; i < 58; i++) {
settings_key[i]->pos.x = settings_key[i-29]->pos.x + offset_x;
settings_key[i]->pos.y = settings_key[i-29]->pos.y + offset_y;
}
}
示例6: load
//.........这里部分代码省略.........
}
Event_Component e;
e.type = infile.key;
if (infile.key == "requires_status")
e.s = infile.val;
else if (infile.key == "requires_not")
e.s = infile.val;
else if (infile.key == "requires_level")
e.x = toInt(infile.val);
else if (infile.key == "requires_not_level")
e.x = toInt(infile.val);
else if (infile.key == "requires_item")
e.x = toInt(infile.val);
else if (infile.key == "him" || infile.key == "her")
e.s = msg->get(infile.val);
else if (infile.key == "you")
e.s = msg->get(infile.val);
else if (infile.key == "reward_item") {
// id,count
e.x = toInt(infile.nextValue());
e.y = toInt(infile.val);
}
else if (infile.key == "reward_xp")
e.x = toInt(infile.val);
else if (infile.key == "restore")
e.s = infile.val;
else if (infile.key == "reward_currency")
e.x = toInt(infile.val);
else if (infile.key == "remove_item")
e.x = toInt(infile.val);
else if (infile.key == "set_status")
e.s = infile.val;
else if (infile.key == "unset_status")
e.s = infile.val;
else if (infile.key == "voice") {
e.x = loadSound(infile.val, NPC_VOX_QUEST);
}
else if (infile.key == "topic") {
e.s = msg->get(infile.val);
}
else if (infile.key == "group") {
e.s = infile.val;
}
dialog.back().push_back(e);
}
else {
filename = npc_id;
if (infile.key == "name") {
name = msg->get(infile.val);
}
else if (infile.key == "level") {
if (infile.val == "hero")
level = hero_level;
else
level = toInt(infile.val);
}
else if (infile.key == "gfx") {
gfx = infile.val;
}
// handle talkers
else if (infile.key == "talker") {
if (infile.val == "true") talker = true;
}
else if (infile.key == "portrait") {
filename_portrait = infile.val;
}
// handle vendors
else if (infile.key == "vendor") {
if (infile.val == "true") vendor = true;
}
else if (infile.key == "constant_stock") {
stack.quantity = 1;
while (infile.val != "") {
stack.item = toInt(infile.nextValue());
stock.add(stack);
}
}
else if (infile.key == "status_stock") {
if (camp->checkStatus(infile.nextValue())) {
stack.quantity = 1;
while (infile.val != "") {
stack.item = toInt(infile.nextValue());
stock.add(stack);
}
}
}
// handle vocals
else if (infile.key == "vox_intro") {
loadSound(infile.val, NPC_VOX_INTRO);
}
}
}
infile.close();
}
loadGraphics(filename_portrait);
}
示例7: load
//.........这里部分代码省略.........
// combat stats
else if (infile.key == "hp") hp = hp_base = maxhp = num;
else if (infile.key == "mp") mp = mp_base = maxmp = num;
else if (infile.key == "cooldown") cooldown = parse_duration(infile.val);
else if (infile.key == "accuracy") accuracy = accuracy_base = num;
else if (infile.key == "avoidance") avoidance = avoidance_base = 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;
else if (infile.key == "poise") poise = poise_base = 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 = speed_default = num;
else if (infile.key == "dspeed") dspeed = dspeed_default = 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] = parse_duration(infile.val);
else if (infile.key == "cooldown_melee_ment") power_cooldown[MELEE_MENT] = parse_duration(infile.val);
else if (infile.key == "cooldown_ranged_phys") power_cooldown[RANGED_PHYS] = parse_duration(infile.val);
else if (infile.key == "cooldown_ranged_ment") power_cooldown[RANGED_MENT] = parse_duration(infile.val);
else if (infile.key == "power_on_hit") power_index[ON_HIT] = num;
else if (infile.key == "power_on_death") power_index[ON_DEATH] = num;
else if (infile.key == "power_on_half_dead") power_index[ON_HALF_DEAD] = num;
else if (infile.key == "power_on_debuff") power_index[ON_DEBUFF] = num;
else if (infile.key == "power_on_join_combat") power_index[ON_JOIN_COMBAT] = num;
else if (infile.key == "chance_on_hit") power_chance[ON_HIT] = num;
else if (infile.key == "chance_on_death") power_chance[ON_DEATH] = num;
else if (infile.key == "chance_on_half_dead") power_chance[ON_HALF_DEAD] = num;
else if (infile.key == "chance_on_debuff") power_chance[ON_DEBUFF] = num;
else if (infile.key == "chance_on_join_combat") power_chance[ON_JOIN_COMBAT] = num;
else if (infile.key == "cooldown_hit") cooldown_hit = num;
else if (infile.key == "passive_powers") {
std::string p = infile.nextValue();
while (p != "") {
powers_list.push_back(toInt(p));
p = infile.nextValue();
}
}
else if (infile.key == "melee_range") melee_range = num;
else if (infile.key == "threat_range") threat_range = num;
// animation stats
else if (infile.key == "melee_weapon_power") melee_weapon_power = num;
else if (infile.key == "mental_weapon_power") mental_weapon_power = num;
else if (infile.key == "ranged_weapon_power") ranged_weapon_power = num;
else if (infile.key == "animations") animations = infile.val;
// hide enemy HP bar
else if (infile.key == "suppress_hp") {
if (num == 1)
suppress_hp = true;
else
suppress_hp = false;
}
// these are only used for EnemyGroupManager
// we check for them here so that we don't get an error saying they are invalid
else if (infile.key == "categories") valid = true;
else if (infile.key == "rarity") valid = true;
else if (!valid) {
fprintf(stderr, "%s=%s not a valid StatBlock parameter\n", infile.key.c_str(), infile.val.c_str());
}
}
infile.close();
// sort loot table
std::sort(loot.begin(), loot.end(), sortLoot);
}
示例8: if
//.........这里部分代码省略.........
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]
npc = new MenuNPCActions();
menus.push_back(npc); // menus[16]
tip = new WidgetTooltip();
// Load the menu layout and sound effects from menus/menus.txt
FileParser infile;
if (infile.open(mods->locate("menus/menus.txt"))) {
int menu_index = -1;
while (infile.next()) {
if (infile.key == "id") {
/* finalize previously parsed menu */
if (menu_index != -1)
menus[menu_index]->align();
if (infile.val == "hp") menu_index = 0;
else if (infile.val == "mp") menu_index = 1;
else if (infile.val == "xp") menu_index = 2;
else if (infile.val == "effects") menu_index = 3;
else if (infile.val == "hudlog") menu_index = 4;
else if (infile.val == "actionbar") menu_index = 5;
else if (infile.val == "enemy") menu_index = 6;
else if (infile.val == "vendor") menu_index = 7;
else if (infile.val == "talker") menu_index = 8;
else if (infile.val == "exit") menu_index = 9;
else if (infile.val == "minimap") menu_index = 10;
else if (infile.val == "character") menu_index = 11;
else if (infile.val == "inventory") menu_index = 12;
else if (infile.val == "powers") menu_index = 13;
else if (infile.val == "log") menu_index = 14;
else if (infile.val == "stash") menu_index = 15;
else if (infile.val == "npc") menu_index = 16;
else menu_index = -1;
}
if (menu_index == -1)
continue;
if (infile.key == "layout") {
infile.val = infile.val + ',';
int x = eatFirstInt(infile.val, ',');
int y = eatFirstInt(infile.val, ',');
int w = eatFirstInt(infile.val, ',');
int h = eatFirstInt(infile.val, ',');
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;
} else if (infile.key == "align") {
menus[menu_index]->alignment = infile.val;
} else if (infile.key == "soundfx_open") {
menus[menu_index]->sfx_open = snd->load(infile.val, "MenuManager open tab");
} else if (infile.key == "soundfx_close") {
menus[menu_index]->sfx_close = snd->load(infile.val, "MenuManager close tab");
}
}
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;
done = false;
closeAll(); // make sure all togglable menus start closed
}
示例9: loadPowerTree
/**
* Loads a given power tree and sets up the menu accordingly
*/
void MenuPowers::loadPowerTree(const std::string &filename) {
// only load the power tree once per instance
if (tree_loaded) return;
// First, parse the power tree file
FileParser infile;
// @CLASS MenuPowers: Power tree layout|Description of powers/trees/
if (infile.open(filename)) {
while (infile.next()) {
if (infile.new_section) {
// for sections that are stored in collections, add a new object here
if (infile.section == "power") {
slots.push_back(NULL);
upgradeButtons.push_back(NULL);
power_cell.push_back(Power_Menu_Cell());
}
else if (infile.section == "upgrade")
power_cell_upgrade.push_back(Power_Menu_Cell());
else if (infile.section == "tab")
tabs.push_back(Power_Menu_Tab());
}
if (infile.section == "") {
// @ATTR background|string|Filename of the default background image
if (infile.key == "background") default_background = infile.val;
}
else if (infile.section == "tab")
loadTab(infile);
else if (infile.section == "power")
loadPower(infile);
else if (infile.section == "upgrade")
loadUpgrade(infile);
}
infile.close();
}
// save a copy of the base level powers, as they get overwritten during upgrades
power_cell_base = power_cell;
// store the appropriate level for all upgrades
for (unsigned i=0; i<power_cell_upgrade.size(); ++i) {
for (unsigned j=0; j<power_cell_base.size(); j++) {
std::vector<short>::iterator it = std::find(power_cell_base[j].upgrades.begin(), power_cell_base[j].upgrades.end(), power_cell_upgrade[i].id);
if (it != power_cell_base[j].upgrades.end()) {
power_cell_upgrade[i].upgrade_level = static_cast<short>(std::distance(power_cell_base[j].upgrades.begin(), it) + 2);
break;
}
}
}
// combine base and upgrade powers into a single list
for (unsigned i=0; i<power_cell_base.size(); ++i) {
power_cell_all.push_back(power_cell_base[i]);
}
for (unsigned i=0; i<power_cell_upgrade.size(); ++i) {
power_cell_all.push_back(power_cell_upgrade[i]);
}
// load any specified graphics into the tree_surf vector
Image *graphics;
if (tabs.empty() && default_background != "") {
graphics = render_device->loadImage(default_background);
if (graphics) {
tree_surf.push_back(graphics->createSprite());
graphics->unref();
}
}
else {
for (unsigned int i = 0; i < tabs.size(); ++i) {
if (tabs[i].background == "")
tabs[i].background = default_background;
if (tabs[i].background == "") {
tree_surf.push_back(NULL);
continue;
}
graphics = render_device->loadImage(tabs[i].background);
if (graphics) {
tree_surf.push_back(graphics->createSprite());
graphics->unref();
}
else {
tree_surf.push_back(NULL);
}
}
}
// If we have more than one tab, create tab_control
if (!tabs.empty()) {
tab_control = new WidgetTabControl();
if (tab_control) {
// Initialize the tab control.
tab_control->setMainArea(window_area.x+tab_area.x, window_area.y+tab_area.y, tab_area.w, tab_area.h);
//.........这里部分代码省略.........
示例10: load
//.........这里部分代码省略.........
e->s = infile.nextValue();
// add repeating set_status
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().comp_num++;
e = &events.back().components[events.back().comp_num];
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "unset_status") {
e->s = infile.nextValue();
// add repeating unset_status
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().comp_num++;
e = &events.back().components[events.back().comp_num];
e->type = infile.key;
e->s = repeat_val;
repeat_val = infile.nextValue();
}
}
else if (infile.key == "remove_item") {
e->x = toInt(infile.nextValue());
// add repeating remove_item
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().comp_num++;
e = &events.back().components[events.back().comp_num];
e->type = infile.key;
e->x = toInt(repeat_val);
repeat_val = infile.nextValue();
}
}
else if (infile.key == "reward_xp") {
e->x = toInt(infile.val);
}
else if (infile.key == "power") {
e->x = toInt(infile.val);
}
else if (infile.key == "spawn") {
e->s = infile.nextValue();
e->x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
e->y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
// add repeating spawn
string repeat_val = infile.nextValue();
while (repeat_val != "") {
events.back().comp_num++;
e = &events.back().components[events.back().comp_num];
e->type = infile.key;
e->s = repeat_val;
e->x = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
e->y = toInt(infile.nextValue()) * UNITS_PER_TILE + UNITS_PER_TILE/2;
repeat_val = infile.nextValue();
}
}
events.back().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;
}
if (group_awaiting_queue){
push_enemy_group(new_group);
group_awaiting_queue = false;
}
if (this->new_music) {
loadMusic();
this->new_music = false;
}
tset.load(this->tileset);
// some events automatically trigger when the map loads
// e.g. change map state based on campaign status
executeOnLoadEvents();
return 0;
}
示例11: load
//.........这里部分代码省略.........
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;
else if (infile.key == "power_on_half_dead") power_index[ON_HALF_DEAD] = num;
else if (infile.key == "power_on_debuff") power_index[ON_DEBUFF] = num;
else if (infile.key == "power_on_join_combat") power_index[ON_JOIN_COMBAT] = num;
else if (infile.key == "chance_on_hit") power_chance[ON_HIT] = num;
else if (infile.key == "chance_on_death") power_chance[ON_DEATH] = num;
else if (infile.key == "chance_on_half_dead") power_chance[ON_HALF_DEAD] = num;
else if (infile.key == "chance_on_debuff") power_chance[ON_DEBUFF] = num;
else if (infile.key == "chance_on_join_combat") power_chance[ON_JOIN_COMBAT] = num;
else if (infile.key == "melee_range") melee_range = num;
else if (infile.key == "threat_range") threat_range = num;
// animation stats
else if (infile.key == "melee_weapon_power") melee_weapon_power = num;
else if (infile.key == "mental_weapon_power") mental_weapon_power = num;
else if (infile.key == "ranged_weapon_power") ranged_weapon_power = num;
else if (infile.key == "animations") animations = infile.val;
else if (infile.key == "animation_speed") animationSpeed = num;
// hp countdown
else if (infile.key == "hp_countdown_ticks") hp_countdown_ticks = num;
// hide enemy HP bar
else if (infile.key == "suppress_hp") suppress_hp = num;
for (unsigned int i=0; i<ELEMENTS.size(); i++) {
if (infile.key == "vulnerable_" + ELEMENTS[i].name) vulnerable[i] = num;
}
}
infile.close();
} else fprintf(stderr, "Unable to open %s!\n", filename.c_str());
}
示例12: loadMiscSettings
//.........这里部分代码省略.........
SOUND_FALLOFF = toInt(infile.val);
// @ATTR party_exp_percentage|integer|The percentage of XP given to allies.
else if (infile.key == "party_exp_percentage")
PARTY_EXP_PERCENTAGE = toInt(infile.val);
// @ATTR enable_ally_collision|boolean|Allows allies to block the player's path.
else if (infile.key == "enable_ally_collision")
ENABLE_ALLY_COLLISION = toBool(infile.val);
// @ATTR enable_ally_collision_ai|boolean|Allows allies to block the path of other AI creatures.
else if (infile.key == "enable_ally_collision_ai")
ENABLE_ALLY_COLLISION_AI = toBool(infile.val);
else if (infile.key == "currency_id") {
// @ATTR currency_id|integer|An item id that will be used as currency.
CURRENCY_ID = toInt(infile.val);
if (CURRENCY_ID < 1) {
CURRENCY_ID = 1;
logError("Settings: Currency ID below the minimum allowed value. Resetting it to %d", CURRENCY_ID);
}
}
// @ATTR interact_range|float|Distance where the player can interact with objects and NPCs.
else if (infile.key == "interact_range")
INTERACT_RANGE = toFloat(infile.val);
// @ATTR menus_pause|boolean|Opening any menu will pause the game.
else if (infile.key == "menus_pause")
MENUS_PAUSE = toBool(infile.val);
// @ATTR save_onload|boolean|Save the game upon changing maps.
else if (infile.key == "save_onload")
SAVE_ONLOAD = toBool(infile.val);
// @ATTR save_onexit|boolean|Save the game upon quitting to the title screen or desktop.
else if (infile.key == "save_onexit")
SAVE_ONEXIT = toBool(infile.val);
else infile.error("Settings: '%s' is not a valid key.", infile.key.c_str());
}
infile.close();
}
if (SAVE_PREFIX == "") {
logError("Settings: save_prefix not found in engine/misc.txt, setting to 'default'. This may cause save file conflicts between games that have no save_prefix.");
SAVE_PREFIX = "default";
}
// @CLASS Settings: Resolution|Description of engine/resolutions.txt
if (infile.open("engine/resolutions.txt")) {
while (infile.next()) {
// @ATTR menu_frame_width|integer|Width of frame for New Game, Configuration, etc. menus.
if (infile.key == "menu_frame_width")
FRAME_W = static_cast<unsigned short>(toInt(infile.val));
// @ATTR menu_frame_height|integer|Height of frame for New Game, Configuration, etc. menus.
else if (infile.key == "menu_frame_height")
FRAME_H = static_cast<unsigned short>(toInt(infile.val));
// @ATTR icon_size|integer|Size of icons.
else if (infile.key == "icon_size")
ICON_SIZE = static_cast<unsigned short>(toInt(infile.val));
// @ATTR required_width|integer|Minimum window/screen resolution width.
else if (infile.key == "required_width") {
MIN_SCREEN_W = static_cast<unsigned short>(toInt(infile.val));
}
// @ATTR required_height|integer|Minimum window/screen resolution height.
else if (infile.key == "required_height") {
MIN_SCREEN_H = static_cast<unsigned short>(toInt(infile.val));
}
// @ATTR virtual_height|integer|The height (in pixels) of the game's actual rendering area. The width will be resized to match the window's aspect ration, and everything will be scaled up to fill the window.
else if (infile.key == "virtual_height") {
VIEW_H = static_cast<unsigned short>(toInt(infile.val));
VIEW_H_HALF = VIEW_H / 2;
}
示例13: Entity
Avatar::Avatar()
: Entity()
, lockAttack(false)
, path()
, prev_target()
, target_visible(false)
, target_anim(NULL)
, target_animset(NULL)
, lock_cursor(false)
, hero_stats(NULL)
, charmed_stats(NULL)
, act_target()
, drag_walking(false)
, respawn(false)
, close_menus(false)
, allow_movement(true)
, enemy_pos(FPoint(-1,-1)) {
init();
// load the hero's animations from hero definition file
anim->increaseCount("animations/hero.txt");
animationSet = anim->getAnimationSet("animations/hero.txt");
activeAnimation = animationSet->getAnimation();
// set cooldown_hit to duration of hit animation if undefined
if (stats.cooldown_hit == -1) {
Animation *hit_anim = animationSet->getAnimation("hit");
if (hit_anim) {
stats.cooldown_hit = hit_anim->getDuration();
delete hit_anim;
}
else {
stats.cooldown_hit = 0;
}
}
loadLayerDefinitions();
// load target animation
if (SHOW_TARGET) {
anim->increaseCount("animations/target.txt");
target_animset = anim->getAnimationSet("animations/target.txt");
target_anim = target_animset->getAnimation();
}
// load foot-step definitions
// @CLASS Avatar: Step sounds|Description of items/step_sounds.txt
FileParser infile;
if (infile.open("items/step_sounds.txt", true, "")) {
while (infile.next()) {
if (infile.key == "id") {
// @ATTR id|string|An identifier name for a set of step sounds.
step_def.push_back(Step_sfx());
step_def.back().id = infile.val;
}
if (step_def.empty()) continue;
if (infile.key == "step") {
// @ATTR step|filename|Filename of a step sound effect.
step_def.back().steps.push_back(infile.val);
}
}
infile.close();
}
loadStepFX(stats.sfx_step);
}
示例14: if
GameStateLoad::GameStateLoad() : GameState()
, background(NULL)
, selection(NULL)
, portrait_border(NULL)
, portrait(NULL) {
items = new ItemManager();
loading_requested = false;
loading = false;
loaded = false;
label_loading = new WidgetLabel();
for (int i = 0; i < GAME_SLOT_MAX; i++) {
label_name[i] = new WidgetLabel();
label_level[i] = new WidgetLabel();
label_map[i] = new WidgetLabel();
}
// Confirmation box to confirm deleting
confirm = new MenuConfirm(msg->get("Delete Save"), msg->get("Delete this save?"));
button_exit = new WidgetButton("images/menus/buttons/button_default.png");
button_exit->label = msg->get("Exit to Title");
button_exit->pos.x = VIEW_W_HALF - button_exit->pos.w/2;
button_exit->pos.y = VIEW_H - button_exit->pos.h;
button_exit->refresh();
button_action = new WidgetButton("images/menus/buttons/button_default.png");
button_action->label = msg->get("Choose a Slot");
button_action->enabled = false;
button_alternate = new WidgetButton("images/menus/buttons/button_default.png");
button_alternate->label = msg->get("Delete Save");
button_alternate->enabled = false;
// Set up tab list
tablist = TabList(HORIZONTAL);
tablist.add(button_exit);
// Read positions from config file
FileParser infile;
if (infile.open("menus/gameload.txt")) {
while (infile.next()) {
if (infile.key == "action_button") {
button_action->pos.x = popFirstInt(infile.val);
button_action->pos.y = popFirstInt(infile.val);
}
else if (infile.key == "alternate_button") {
button_alternate->pos.x = popFirstInt(infile.val);
button_alternate->pos.y = popFirstInt(infile.val);
}
else if (infile.key == "portrait") {
portrait_dest = toRect(infile.val);
portrait_dest.x += (VIEW_W - FRAME_W) / 2;
portrait_dest.y += (VIEW_H - FRAME_H) / 2;
}
else if (infile.key == "gameslot") {
gameslot_pos = toRect(infile.val);
}
else if (infile.key == "preview") {
preview_pos = toRect(infile.val);
// label positions within each slot
}
else if (infile.key == "name") {
name_pos = eatLabelInfo(infile.val);
}
else if (infile.key == "level") {
level_pos = eatLabelInfo(infile.val);
}
else if (infile.key == "map") {
map_pos = eatLabelInfo(infile.val);
}
else if (infile.key == "loading_label") {
loading_pos = eatLabelInfo(infile.val);
// Position for the avatar preview image in each slot
}
else if (infile.key == "sprite") {
sprites_pos = toPoint(infile.val);
}
}
infile.close();
}
// get displayable types list
bool found_layer = false;
if (infile.open("engine/hero_layers.txt")) {
while(infile.next()) {
if (infile.key == "layer") {
unsigned dir = popFirstInt(infile.val);
if (dir != 6) continue;
else found_layer = true;
string layer = popFirstString(infile.val);
while (layer != "") {
preview_layer.push_back(layer);
layer = popFirstString(infile.val);
}
}
}
infile.close();
//.........这里部分代码省略.........
示例15: if
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;
if(infile.open(mods->locate("menus/npc.txt"))) {
while(infile.next()) {
infile.val = infile.val + ',';
if(infile.key == "background_color") {
background_color.r = eatFirstInt(infile.val,',');
background_color.g = eatFirstInt(infile.val,',');
background_color.b = eatFirstInt(infile.val,',');
background_alpha = eatFirstInt(infile.val,',');
}
else if(infile.key == "topic_normal_color") {
topic_normal_color.r = eatFirstInt(infile.val,',');
topic_normal_color.g = eatFirstInt(infile.val,',');
topic_normal_color.b = eatFirstInt(infile.val,',');
}
else if(infile.key == "topic_hilight_color") {
topic_hilight_color.r = eatFirstInt(infile.val,',');
topic_hilight_color.g = eatFirstInt(infile.val,',');
topic_hilight_color.b = eatFirstInt(infile.val,',');
}
else if(infile.key == "vendor_normal_color") {
vendor_normal_color.r = eatFirstInt(infile.val,',');
vendor_normal_color.g = eatFirstInt(infile.val,',');
vendor_normal_color.b = eatFirstInt(infile.val,',');
}
else if(infile.key == "vendor_hilight_color") {
vendor_hilight_color.r = eatFirstInt(infile.val,',');
vendor_hilight_color.g = eatFirstInt(infile.val,',');
vendor_hilight_color.b = eatFirstInt(infile.val,',');
}
else if(infile.key == "cancel_normal_color") {
cancel_normal_color.r = eatFirstInt(infile.val,',');
cancel_normal_color.g = eatFirstInt(infile.val,',');
cancel_normal_color.b = eatFirstInt(infile.val,',');
}
else if(infile.key == "cancel_hilight_color") {
cancel_hilight_color.r = eatFirstInt(infile.val,',');
cancel_hilight_color.g = eatFirstInt(infile.val,',');
cancel_hilight_color.b = eatFirstInt(infile.val,',');
}
}
infile.close();
}
}