Skip to content

Commit

Permalink
KOTOR: Add getPartyMemberByIndex nwscript function
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius committed Sep 13, 2018
1 parent 9a9b5ee commit 8182ecc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/engines/kotor/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,15 @@ bool Module::isObjectPartyMember(Creature *creature) {
return std::find(_party.begin(), _party.end(), creature) != _party.end();
}

Creature *Module::getPartyMember(int index) {
if (index >= static_cast<int>(_party.size()) || index < 0)
throw Common::Exception("Module::getPartyMember() Invalid index");

std::list<Creature *>::iterator iter = _party.begin();
std::advance(iter, index);
return *iter;
}

void Module::switchPlayerCharacter(int npc) {
std::list<Creature *>::iterator iter = _party.begin();
if (npc != -1)
Expand Down
2 changes: 2 additions & 0 deletions src/engines/kotor/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class Module : public KotOR::Object, public KotOR::ObjectContainer {
void addToParty(Creature *creature);
/** Check if the specified creature is a party member. */
bool isObjectPartyMember(Creature *creature);
/** Get a party member by index. */
Creature *getPartyMember(int index);
/** Switch the player character. */
void switchPlayerCharacter(int npc);
/** Show the party selection GUI. */
Expand Down
2 changes: 1 addition & 1 deletion src/engines/kotor/script/function_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ const Functions::FunctionPointer Functions::kFunctionPointers[] = {
{ 574, "AddPartyMember" , 0 },
{ 575, "RemovePartyMember" , 0 },
{ 576, "IsObjectPartyMember" , &Functions::isObjectPartyMember },
{ 577, "GetPartyMemberByIndex" , 0 },
{ 577, "GetPartyMemberByIndex" , &Functions::getPartyMemberByIndex },
{ 578, "GetGlobalBoolean" , &Functions::getGlobalBoolean },
{ 579, "SetGlobalBoolean" , &Functions::setGlobalBoolean },
{ 580, "GetGlobalNumber" , &Functions::getGlobalNumber },
Expand Down
1 change: 1 addition & 0 deletions src/engines/kotor/script/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class Functions {

// .--- Party, functions_party.cpp
void isObjectPartyMember(Aurora::NWScript::FunctionContext &ctx);
void getPartyMemberByIndex(Aurora::NWScript::FunctionContext &ctx);
void showPartySelectionGUI(Aurora::NWScript::FunctionContext &ctx);
void isAvailableCreature(Aurora::NWScript::FunctionContext &ctx);
void addAvailableNPCByTemplate(Aurora::NWScript::FunctionContext &ctx);
Expand Down
6 changes: 6 additions & 0 deletions src/engines/kotor/script/functions_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ void Functions::isObjectPartyMember(Aurora::NWScript::FunctionContext &ctx) {
ctx.getReturn() = _game->getModule().isObjectPartyMember(creature);
}

void Functions::getPartyMemberByIndex(Aurora::NWScript::FunctionContext &ctx) {
int index = ctx.getParams()[0].getInt();

ctx.getReturn() = _game->getModule().getPartyMember(index);
}

void Functions::showPartySelectionGUI(Aurora::NWScript::FunctionContext &ctx) {
const Common::UString &exitScript = ctx.getParams()[0].getString();
int forceNPC1 = ctx.getParams()[1].getInt();
Expand Down

0 comments on commit 8182ecc

Please sign in to comment.