Skip to content

Commit

Permalink
NWN2: Add GetGameDifficulty() script function
Browse files Browse the repository at this point in the history
This will remove a warning during startup about a TODO function.
  • Loading branch information
rjshae committed Feb 5, 2019
1 parent 5bbe8d9 commit 53db5ed
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/engines/nwn2/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Module &Game::getModule() {
return _campaign->getModule();
}

int32 Game::getGameDifficulty() {
return ConfigMan.getInt("difficulty");
}

void Game::run() {
_campaign.reset(new Campaign(*_console));

Expand Down
2 changes: 2 additions & 0 deletions src/engines/nwn2/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Game {
Campaign &getCampaign();
/** Return the module context. */
Module &getModule();
/** Return the game difficulty setting. */
int32 getGameDifficulty();

/** Overwrite all currently playing music. */
void playMusic(const Common::UString &music = "");
Expand Down
6 changes: 6 additions & 0 deletions src/engines/nwn2/nwn2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void NWN2Engine::init() {

progress.step("Loading user game config");
initConfig();
checkConfig();

initResources(progress);
if (EventMan.quitRequested())
Expand Down Expand Up @@ -358,6 +359,7 @@ void NWN2Engine::initCursors() {
void NWN2Engine::initConfig() {
// Enable/Disable the Proof-of-Concept software tinting
ConfigMan.setBool(Common::kConfigRealmDefault, "tint", true);
ConfigMan.setInt(Common::kConfigRealmDefault, "difficulty", 2);
}

void NWN2Engine::initGameConfig() {
Expand All @@ -375,6 +377,10 @@ void NWN2Engine::initGameConfig() {
Common::FilePath::findSubDirectory(_target, "servervault", true));
}

void NWN2Engine::checkConfig() {
checkConfigInt("difficulty", 0, 4);
}

void NWN2Engine::deinit() {
_game.reset();
}
Expand Down
2 changes: 2 additions & 0 deletions src/engines/nwn2/nwn2.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class NWN2Engine : public Engines::Engine {

void deinit();

void checkConfig();

void playIntroVideos();
};

Expand Down
2 changes: 1 addition & 1 deletion src/engines/nwn2/script/function_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ const Functions::FunctionPointer Functions::kFunctionPointers[] = {
{ 510, "EffectSwarm" , 0 },
{ 511, "GetWeaponRanged" , 0 },
{ 512, "DoSinglePlayerAutoSave" , 0 },
{ 513, "GetGameDifficulty" , 0 },
{ 513, "GetGameDifficulty" , &Functions::getGameDifficulty },
{ 514, "SetTileMainLightColor" , 0 },
{ 515, "SetTileSourceLightColor" , 0 },
{ 516, "RecomputeStaticLighting" , 0 },
Expand Down
4 changes: 4 additions & 0 deletions src/engines/nwn2/script/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Aurora::NWScript::Object *Functions::getParamObject(const Aurora::NWScript::Func
return object;
}

void Functions::getGameDifficulty(Aurora::NWScript::FunctionContext &ctx) {
ctx.getReturn() = (int32) _game->getGameDifficulty();
}

void Functions::jumpTo(NWN2::Object *object, Area *area, float x, float y, float z) {
// Sanity check
if (!object->getArea() || !area) {
Expand Down
2 changes: 2 additions & 0 deletions src/engines/nwn2/script/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Functions {
// .--- Utility methods
void jumpTo(NWN2::Object *object, Area *area, float x, float y, float z);

void getGameDifficulty(Aurora::NWScript::FunctionContext &ctx);

static int32 getRandom(int min, int max, int32 n = 1);

static Common::UString formatFloat(float f, int width = 18, int decimals = 9);
Expand Down

0 comments on commit 53db5ed

Please sign in to comment.