Implement external default party configuration

Default party configuration, used when loading a module from the
main menu, can now be configured from defaultparty.2da resource.
This commit is contained in:
Vsevolod Kremianskii 2021-05-05 14:50:25 +07:00
parent 5f99775c50
commit 05ca0596e4
2 changed files with 53 additions and 24 deletions

View file

@ -0,0 +1,16 @@
{
"rows": [
{
"tsl": "0",
"partymember0": "p_carth",
"partymember1": "p_bastilla",
"partymember2": "****"
},
{
"tsl": "1",
"partymember0": "p_atton",
"partymember1": "p_kreia",
"partymember2": "****"
}
]
}

View file

@ -180,36 +180,49 @@ void MainMenu::onListBoxItemClick(const string &control, const string &item) {
} }
void MainMenu::onModuleSelected(const string &name) { void MainMenu::onModuleSelected(const string &name) {
string playerBlueprint; string member1Blueprint;
string companionBlueprint; string member2Blueprint;
string member3Blueprint;
if (isTSL(_gameId)) { if (isTSL(_gameId)) {
playerBlueprint = kBlueprintResRefAtton; member1Blueprint = kBlueprintResRefAtton;
companionBlueprint = kBlueprintResRefKreia; member2Blueprint = kBlueprintResRefKreia;
} else { } else {
playerBlueprint = kBlueprintResRefCarth; member1Blueprint = kBlueprintResRefCarth;
companionBlueprint = kBlueprintResRefBastila; member2Blueprint = kBlueprintResRefBastila;
}
shared_ptr<TwoDA> defaultParty(Resources::instance().get2DA("defaultparty"));
if (defaultParty) {
for (int row = 0; row < defaultParty->getRowCount(); ++row) {
if (defaultParty->getBool(row, "tsl") == isTSL(_gameId)) {
member1Blueprint = defaultParty->getString(row, "partymember0");
member2Blueprint = defaultParty->getString(row, "partymember1");
member3Blueprint = defaultParty->getString(row, "partymember2");
break;
}
}
} }
Party &party = _game->party(); Party &party = _game->party();
if (!member1Blueprint.empty()) {
shared_ptr<Creature> player(_game->objectFactory().newCreature()); shared_ptr<Creature> player(_game->objectFactory().newCreature());
player->loadFromBlueprint(playerBlueprint); player->loadFromBlueprint(member1Blueprint);
player->setTag(kObjectTagPlayer); player->setTag(kObjectTagPlayer);
player->setImmortal(true); player->setImmortal(true);
party.addMember(kNpcPlayer, player); party.addMember(kNpcPlayer, player);
party.setPlayer(player); party.setPlayer(player);
}
shared_ptr<Creature> companion(_game->objectFactory().newCreature()); if (!member2Blueprint.empty()) {
companion->loadFromBlueprint(companionBlueprint); shared_ptr<Creature> companion(_game->objectFactory().newCreature());
companion->setImmortal(true); companion->loadFromBlueprint(member2Blueprint);
party.addMember(0, companion); companion->setImmortal(true);
party.addMember(0, companion);
if (isTSL(_gameId)) { }
player->equip("w_blaste_01"); if (!member3Blueprint.empty()) {
companion->equip("w_melee_06"); shared_ptr<Creature> companion(_game->objectFactory().newCreature());
} else { companion->loadFromBlueprint(member3Blueprint);
companion->equip("g_w_dblsbr004"); companion->setImmortal(true);
party.addMember(1, companion);
} }
_game->loadModule(name); _game->loadModule(name);