Load feats from 2DA

This commit is contained in:
Vsevolod Kremianskii 2021-05-19 10:10:55 +07:00
parent 20879ccb7d
commit 081b4877b8
7 changed files with 176 additions and 2 deletions

View file

@ -488,6 +488,8 @@ set(GAME_HEADERS
src/engine/game/d20/attributes.h
src/engine/game/d20/class.h
src/engine/game/d20/classes.h
src/engine/game/d20/feat.h
src/engine/game/d20/feats.h
src/engine/game/d20/savingthrows.h
src/engine/game/savedgame.h
src/engine/game/script/objectutil.h
@ -521,6 +523,7 @@ set(GAME_SOURCES
src/engine/game/d20/attributes_skills.cpp
src/engine/game/d20/class.cpp
src/engine/game/d20/classes.cpp
src/engine/game/d20/feats.cpp
src/engine/game/dialog.cpp
src/engine/game/footstepsounds.cpp
src/engine/game/game.cpp

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include "../../graphics/texture/texture.h"
#include "../types.h"
namespace reone {
namespace game {
struct Feat {
std::string name;
std::string description;
std::shared_ptr<graphics::Texture> icon;
uint32_t minCharLevel { 0 };
FeatType preReqFeat1 { FeatType::Invalid };
FeatType preReqFeat2 { FeatType::Invalid };
FeatType successor { FeatType::Invalid };
uint32_t pips { 1 }; // 1-3, position in a feat chain
};
} // namespace game
} // namespace reone

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "feats.h"
#include <functional>
#include <string>
#include "../../common/collectionutil.h"
#include "../../graphics/texture/textures.h"
#include "../../resource/resources.h"
#include "../../resource/strings.h"
using namespace std;
using namespace reone::graphics;
using namespace reone::resource;
namespace reone {
namespace game {
Feats &Feats::instance() {
static Feats instance;
return instance;
}
void Feats::init() {
shared_ptr<TwoDA> feats(Resources::instance().get2DA("feat"));
if (!feats) return;
for (int row = 0; row < feats->getRowCount(); ++row) {
string name(Strings::instance().get(feats->getInt(row, "name", -1)));
string description(Strings::instance().get(feats->getInt(row, "description", -1)));
shared_ptr<Texture> icon(Textures::instance().get(feats->getString(row, "icon"), TextureUsage::GUI));
uint32_t minCharLevel = feats->getUint(row, "mincharlevel");
auto preReqFeat1 = static_cast<FeatType>(feats->getUint(row, "prereqfeat1"));
auto preReqFeat2 = static_cast<FeatType>(feats->getUint(row, "prereqfeat2"));
auto successor = static_cast<FeatType>(feats->getUint(row, "successor"));
uint32_t pips = feats->getUint(row, "pips");
auto feat = make_shared<Feat>();
feat->name = move(name);
feat->description = move(description);
feat->icon = move(icon);
feat->minCharLevel = minCharLevel;
feat->preReqFeat1 = preReqFeat1;
feat->preReqFeat2 = preReqFeat2;
feat->successor = successor;
feat->pips = pips;
_feats.insert(make_pair(static_cast<FeatType>(row), move(feat)));
}
}
shared_ptr<Feat> Feats::get(FeatType type) const {
return getFromLookupOrNull(_feats, type);
}
} // namespace game
} // namespace reone

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <unordered_map>
#include <boost/noncopyable.hpp>
#include "../types.h"
#include "feat.h"
namespace reone {
namespace game {
class Feats : boost::noncopyable {
public:
static Feats &instance();
void init();
std::shared_ptr<Feat> get(FeatType type) const;
private:
Feats() = default;
std::unordered_map<FeatType, std::shared_ptr<Feat>> _feats;
};
} // namespace game
} // namespace reone

View file

@ -43,6 +43,7 @@
#include "../video/video.h"
#include "cursors.h"
#include "d20/feats.h"
#include "gameidutil.h"
#include "gui/sounds.h"
#include "portraits.h"
@ -121,6 +122,7 @@ void Game::initSubsystems() {
Surfaces::instance().init();
Portraits::instance().init();
Walkmeshes::instance().init(Surfaces::instance().getWalkableSurfaceIndices());
Feats::instance().init();
Cursors::instance().init(_gameId);
setCursorType(CursorType::Default);

View file

@ -470,7 +470,7 @@ Variable Routines::actionSpeakStringByStrRef(const VariablesList &args, Executio
Variable Routines::actionUseFeat(const VariablesList &args, ExecutionContext &ctx) {
// TODO: pass all arguments to an action
auto feat = getEnum<Feat>(args, 0);
auto feat = getEnum<FeatType>(args, 0);
auto target = getObject(args, 1, ctx);
if (target) {

View file

@ -510,7 +510,8 @@ enum class Skill {
TreatInjury = 7
};
enum class Feat {
enum class FeatType {
Invalid = 0,
AdvancedJediDefense = 1,
AdvancedGuardStance = 2,
Ambidexterity = 3,