void LootManager::parseLoot(std::string &val, EventComponent *e, std::vector<EventComponent> *ec_list) { if (e == NULL) return; std::string chance; bool first_is_filename = false; e->s = Parse::popFirstString(val); if (e->s == "currency") e->c = eset->misc.currency_id; else if (Parse::toInt(e->s, -1) != -1) e->c = Parse::toInt(e->s); else if (ec_list) { // load entire loot table std::string filename = e->s; // remove the last event component, since getLootTable() will create a new one if (e == &ec_list->back()) ec_list->pop_back(); getLootTable(filename, ec_list); first_is_filename = true; } if (!first_is_filename) { // make sure the type is "loot" e->type = EventComponent::LOOT; // drop chance chance = Parse::popFirstString(val); if (chance == "fixed") e->f = 0; else e->f = Parse::toFloat(chance); // quantity min/max e->a = std::max(Parse::popFirstInt(val), 1); e->b = std::max(Parse::popFirstInt(val), e->a); } // add repeating loot if (ec_list) { std::string repeat_val = Parse::popFirstString(val); while (repeat_val != "") { ec_list->push_back(EventComponent()); EventComponent *ec = &ec_list->back(); ec->type = EventComponent::LOOT; ec->s = repeat_val; if (ec->s == "currency") ec->c = eset->misc.currency_id; else if (Parse::toInt(ec->s, -1) != -1) ec->c = Parse::toInt(ec->s); else { // remove the last event component, since getLootTable() will create a new one ec_list->pop_back(); getLootTable(repeat_val, ec_list); repeat_val = Parse::popFirstString(val); continue; } chance = Parse::popFirstString(val); if (chance == "fixed") ec->f = 0; else ec->f = Parse::toFloat(chance); ec->a = std::max(Parse::popFirstInt(val), 1); ec->b = std::max(Parse::popFirstInt(val), ec->a); repeat_val = Parse::popFirstString(val); } } }
void LootManager::parseLoot(FileParser &infile, Event_Component *e, std::vector<Event_Component> *ec_list) { if (e == NULL) return; std::string chance; bool first_is_filename = false; e->s = infile.nextValue(); if (e->s == "currency") e->c = CURRENCY_ID; else if (toInt(e->s, -1) != -1) e->c = toInt(e->s); else if (ec_list) { // load entire loot table std::string filename = e->s; // remove the last event component, since getLootTable() will create a new one if (e == &ec_list->back()) ec_list->pop_back(); getLootTable(filename, ec_list); first_is_filename = true; } if (!first_is_filename) { // make sure the type is "loot" e->type = "loot"; // drop chance chance = infile.nextValue(); if (chance == "fixed") e->z = 0; else e->z = toInt(chance); // quantity min/max e->a = toInt(infile.nextValue()); clampFloor(e->a, 1); e->b = toInt(infile.nextValue()); clampFloor(e->b, e->a); } // add repeating loot if (ec_list) { std::string repeat_val = infile.nextValue(); while (repeat_val != "") { ec_list->push_back(Event_Component()); Event_Component *ec = &ec_list->back(); ec->type = infile.key; ec->s = repeat_val; if (ec->s == "currency") ec->c = CURRENCY_ID; else if (toInt(ec->s, -1) != -1) ec->c = toInt(ec->s); else { // remove the last event component, since getLootTable() will create a new one ec_list->pop_back(); getLootTable(repeat_val, ec_list); repeat_val = infile.nextValue(); continue; } chance = infile.nextValue(); if (chance == "fixed") ec->z = 0; else ec->z = toInt(chance); ec->a = toInt(infile.nextValue()); clampFloor(ec->a, 1); ec->b = toInt(infile.nextValue()); clampFloor(ec->b, ec->a); repeat_val = infile.nextValue(); } } }