Skip to content

Commit

Permalink
KOTOR: Add race nwscript functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Dec 29, 2017
1 parent 372953e commit 8ae8b35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/engines/kotor/script/function_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const Functions::FunctionPointer Functions::kFunctionPointers[] = {
{ 104, "VectorMagnitude" , &Functions::vectorMagnitude },
{ 105, "GetMetaMagicFeat" , 0 },
{ 106, "GetObjectType" , 0 },
{ 107, "GetRacialType" , 0 },
{ 107, "GetRacialType" , &Functions::getRacialType },
{ 108, "FortitudeSave" , 0 },
{ 109, "ReflexSave" , 0 },
{ 110, "WillSave" , 0 },
Expand Down Expand Up @@ -615,7 +615,7 @@ const Functions::FunctionPointer Functions::kFunctionPointers[] = {
{ 494, "GetChallengeRating" , 0 },
{ 495, "GetFoundEnemyCreature" , 0 },
{ 496, "GetMovementRate" , 0 },
{ 497, "GetSubRace" , 0 },
{ 497, "GetSubRace" , &Functions::getSubRace },
{ 498, "GetStealthXPDecrement" , 0 },
{ 499, "SetStealthXPDecrement" , 0 },
{ 500, "DuplicateHeadAppearance" , 0 },
Expand Down
3 changes: 3 additions & 0 deletions src/engines/kotor/script/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class Functions {
// .--- Creatures, functions_creatures.cpp
void getGender(Aurora::NWScript::FunctionContext &ctx);
void getLevelByClass(Aurora::NWScript::FunctionContext &ctx);

void getRacialType(Aurora::NWScript::FunctionContext &ctx);
void getSubRace(Aurora::NWScript::FunctionContext &ctx);
// '---
};

Expand Down
25 changes: 25 additions & 0 deletions src/engines/kotor/script/functions_creatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ void Functions::getLevelByClass(Aurora::NWScript::FunctionContext &ctx) {
ctx.getReturn() = creature->getLevel(creatureClass);
}

void Functions::getRacialType(Aurora::NWScript::FunctionContext &ctx) {
Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();

Creature *creature = ObjectContainer::toCreature(object);

Race race;
if (!creature)
race = kRaceInvalid;
else
race = creature->getRace();

ctx.getReturn() = race;
}

void Functions::getSubRace(Aurora::NWScript::FunctionContext &ctx) {
Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();

Creature *creature = ObjectContainer::toCreature(object);

if (!creature)
throw Common::Exception("Functions::getSubRace(): Object is not a creature");

ctx.getReturn() = creature->getSubRace();
}

} // End of namespace KotOR

} // End of namespace Engines

0 comments on commit 8ae8b35

Please sign in to comment.