Skip to content

Commit

Permalink
KOTOR: Implement weapon drawing for all weapon types
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii authored and DrMcCoy committed Mar 3, 2019
1 parent b202a1a commit 58fb1f3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/engines/kotorbase/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,39 @@ void Creature::playDefaultHeadAnimation() {
headChannel->playDefaultAnimation();
}

void Creature::playDrawWeaponAnimation() {
if (!_model)
return;

Item *item = _equipment[kInventorySlotRightWeapon];
if (!item)
return;

switch (item->getWeaponWield()) {
case kWeaponWieldBaton:
_model->playAnimation("g1w1");
break;
case kWeaponWieldSword:
_model->playAnimation("g2w1");
break;
case kWeaponWieldStaff:
_model->playAnimation("g3w1");
break;
case kWeaponWieldPistol:
_model->playAnimation("g5w1");
break;
case kWeaponWieldHeavy:
_model->playAnimation("g6w1");
break;
case kWeaponWieldRifle:
_model->playAnimation("g7w1");
break;
default:
// TODO: two swords (g4w1)
break;
}
}

void Creature::playAnimation(const Common::UString &anim, bool restart, float length, float speed) {
if (_model)
_model->playAnimation(anim, restart, length, speed);
Expand Down
1 change: 1 addition & 0 deletions src/engines/kotorbase/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Creature : public Object {

void playDefaultAnimation();
void playDefaultHeadAnimation();
void playDrawWeaponAnimation();

void playAnimation(const Common::UString &anim,
bool restart = true,
Expand Down
5 changes: 5 additions & 0 deletions src/engines/kotorbase/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void Item::load(const Aurora::GFF3Struct &gff) {
const Aurora::TwoDARow &twoDA = TwoDAReg.get2DA("baseitems").getRow(_baseItem);
_equipableSlotsMask = twoDA.getInt("equipableslots");
_itemClass = twoDA.getString("itemclass");
_weaponWield = static_cast<WeaponWield>(twoDA.getInt("weaponwield"));

// Model, body and texture variations
_modelVariation = gff.getSint("ModelVariation");
Expand All @@ -60,6 +61,10 @@ const Common::UString &Item::getName() const {
return _name;
}

WeaponWield Item::getWeaponWield() const {
return _weaponWield;
}

bool Item::isSlotEquipable(InventorySlot slot) const {
if (slot > 31)
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/engines/kotorbase/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Item : public Object {
// Basic properties

const Common::UString &getName() const;
WeaponWield getWeaponWield() const;

bool isSlotEquipable(InventorySlot slot) const;

// Visual properties
Expand All @@ -51,6 +53,7 @@ class Item : public Object {
int _baseItem;
Common::UString _itemClass;
int32 _equipableSlotsMask;
WeaponWield _weaponWield;

int _modelVariation;
int _bodyVariation;
Expand Down
5 changes: 5 additions & 0 deletions src/engines/kotorbase/partyleader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ bool PartyLeaderController::handleEvent(const Events::Event &e) {
} else if (e.key.keysym.scancode == SDL_SCANCODE_S) {
_backwardMovementWanted = (e.type == Events::kEventKeyDown);
return true;
} else if ((e.key.keysym.scancode == SDL_SCANCODE_X) && (e.type == Events::kEventKeyUp)) {
if (!_moving)
_module->getPartyLeader()->playDrawWeaponAnimation();

return true;
}
return false;

Expand Down
9 changes: 9 additions & 0 deletions src/engines/kotorbase/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ enum Perception {
kPerceptionSeen = 7
};

enum WeaponWield {
kWeaponWieldBaton = 1,
kWeaponWieldSword = 2,
kWeaponWieldStaff = 3,
kWeaponWieldPistol = 4,
kWeaponWieldRifle = 5,
kWeaponWieldHeavy = 6
};

} // End of namespace KotORBase

} // End of namespace Engines
Expand Down

0 comments on commit 58fb1f3

Please sign in to comment.