Skip to content

Commit

Permalink
NWN2: Add item class
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshae authored and DrMcCoy committed Feb 25, 2019
1 parent edd15e1 commit 3ce4a8c
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/engines/nwn2/item.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos 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.
*
* xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* An item in a Neverwinter Nights 2 area.
*/

#include "src/common/scopedptr.h"

#include "src/aurora/gff3file.h"

#include "src/engines/aurora/util.h"

#include "src/engines/nwn2/item.h"

namespace Engines {

namespace NWN2 {

Item::Item(const Aurora::GFF3Struct &item) : Object(kObjectTypeItem),
_stackSize(1), _droppable(true), _identified(true), _pickpocketable(true) {

load(item);
}

Item::~Item() {
}

void Item::load(const Aurora::GFF3Struct &item) {
Common::UString temp = item.getString("TemplateResRef");

Common::ScopedPtr<Aurora::GFF3File> uti;
if (!temp.empty())
uti.reset(loadOptionalGFF3(temp, Aurora::kFileTypeUTD, MKTAG('U', 'T', 'I', ' ')));

load(item, uti ? &uti->getTopLevel() : 0);
}

void Item::load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struct *blueprint) {

if (blueprint)
loadProperties(*blueprint); // Blueprint
loadProperties(instance); // Instance
}

void Item::loadProperties(const Aurora::GFF3Struct &gff) {

// Object properties
_tag = gff.getString("Tag", _tag);
_name = gff.getString("LocalizedName", _name);
_description = gff.getString("Description", _description);

// Item properties
_icon = gff.getUint("Icon", _icon);
_cost = gff.getUint("Cost", _cost);
_modifyCost = gff.getSint("ModifyCost", _modifyCost);
_baseItem = (ItemType) gff.getUint("BaseItem", (uint) _baseItem);
_stackSize = gff.getUint("StackSize", _stackSize);

// Booleans
_plot = gff.getBool("Plot", _plot);
_cursed = gff.getBool("Cursed", _cursed);
_stolen = gff.getBool("Stolen", _stolen);
_droppable = gff.getBool("Dropable", _droppable);
_identified = gff.getBool("Identified", _identified);
_pickpocketable = gff.getBool("Pickpocketable", _pickpocketable);
}

} // End of namespace NWN2

} // End of namespace Engines
64 changes: 64 additions & 0 deletions src/engines/nwn2/item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos 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.
*
* xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* An item in a Neverwinter Nights 2 area.
*/

#ifndef ENGINES_NWN2_ITEM_H
#define ENGINES_NWN2_ITEM_H

#include "src/engines/nwn2/types.h"
#include "src/engines/nwn2/object.h"

namespace Engines {

namespace NWN2 {

class Item : public Object {
public:
Item(const Aurora::GFF3Struct &item);
~Item();

private:
uint32 _icon; ///< Icon number for inventory UI.
uint32 _cost; ///< Base price in gp.
int32 _modifyCost; ///< Adjustment to price in gp.
uint16 _stackSize; ///< Stack size.
ItemType _baseItem; ///< Base item type.

bool _plot; ///< Is this a plot item?
bool _cursed; ///< Is the item cursed?
bool _stolen; ///< Was the item stolen?
bool _droppable; ///< Is the item dropped as loot?
bool _identified; ///< Have the item's properties been identified?
bool _pickpocketable; ///< Can the item be pick-pocketed?

/* Load from an item instance. */
void load(const Aurora::GFF3Struct &item);
void load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struct *blueprint);
void loadProperties(const Aurora::GFF3Struct &gff);
};

} // End of namespace NWN2

} // End of namespace Engines

#endif // ENGINES_NWN2_ITEM_H
2 changes: 2 additions & 0 deletions src/engines/nwn2/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ src_engines_nwn2_libnwn2_la_SOURCES += \
src/engines/nwn2/trigger.h \
src/engines/nwn2/faction.h \
src/engines/nwn2/roster.h \
src/engines/nwn2/item.h \
$(EMPTY)

src_engines_nwn2_libnwn2_la_SOURCES += \
Expand Down Expand Up @@ -74,6 +75,7 @@ src_engines_nwn2_libnwn2_la_SOURCES += \
src/engines/nwn2/trigger.cpp \
src/engines/nwn2/faction.cpp \
src/engines/nwn2/roster.cpp \
src/engines/nwn2/item.cpp \
$(EMPTY)

include src/engines/nwn2/script/rules.mk
128 changes: 128 additions & 0 deletions src/engines/nwn2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,134 @@ enum Script {
kScriptMAX
};

enum ItemType {
kItemTypeShortSword = 0,
kItemTypeLongSword ,
kItemTypeBattleAxe ,
kItemTypeBastardSword ,
kItemTypeLightFlail ,
kItemTypeWarhammer ,
kItemTypeHeavyCrossbow ,
kItemTypeLightCrossbow ,
kItemTypeLongbow ,
kItemTypeMace ,
kItemTypeHalberd ,
kItemTypeShortbow ,

kItemTypeGreatsword = 13,
kItemTypeSmallShield ,
kItemTypeTorch ,
kItemTypeArmor ,
kItemTypeHelmet ,
kItemTypeGreataxe ,
kItemTypeAmulet ,
kItemTypeArrow ,
kItemTypeDagger ,

kItemTypeMiscSmall = 24,
kItemTypeBolt ,
kItemTypeBoots ,
kItemTypeBullet ,
kItemTypeClub ,
kItemTypeMiscMedium ,

kItemTypeDart = 31,

kItemTypeMiscLarge = 34,

kItemTypeGloves = 36,
kItemTypeLightHammer ,
kItemTypeHandaxe ,
kItemTypeHealersKit ,
kItemTypeKama ,
kItemTypeKatana ,
kItemTypeKukri ,

kItemTypeMagicRod = 44,
kItemTypeMagicStaff ,
kItemTypeMagicWand ,
kItemTypeMorningstar ,

kItemTypePotions = 49,
kItemTypeQuarterstaff ,
kItemTypeRapier ,
kItemTypeRing ,
kItemTypeScimitar ,

kItemTypeScythe = 55,
kItemTypeLargeShield ,
kItemTypeTowerShield ,

kItemTypeShuriken = 59,
kItemTypeSickle ,
kItemTypeSling ,
kItemTypeThievesTools ,
kItemTypeThrowingAxe ,
kItemTypeTrapKit ,
kItemTypeKey ,
kItemTypeLargeBox ,

kItemTypeCSlashWeapon = 69,
kItemTypeCPiercWeapon ,
kItemTypeCBludgWeapon ,
kItemTypeCSlshPrcWeapon ,
kItemTypeCreatureItem ,
kItemTypeBook ,
kItemTypeSpellScroll ,
kItemTypeGold ,
kItemTypeGem ,
kItemTypeBracer ,
kItemTypeMiscThin ,
kItemTypeCloak ,
kItemTypeGrenade ,
kItemTypeBalorSword ,
kItemTypeBalorFalchion ,

kItemTypeEmptyPotion = 101,
kItemTypeBlankScroll ,
kItemTypeBlankMagicWand ,
kItemTypeCraftedPotion ,
kItemTypeCraftedScroll ,
kItemTypeCraftedMagicWand ,

kItemTypeDwarvenWaraxe = 108,
kItemTypeCraftCompBase ,
kItemTypeCraftCompSmall ,
kItemTypeWhip ,
kItemTypeCraftBase ,

kItemTypeFalchion = 114,

kItemTypeFlail = 116,

kItemTypeSpear = 119,
kItemTypeGreatClub ,

kItemTypeTrainingClub = 124,
kItemTypeSoftBundle ,
kItemTypeWarmace ,
kItemTypeStein ,
kItemTypeDrum ,
kItemTypeFlute ,
kItemTypeInkwell ,
kItemTypeBag ,
kItemTypeMandolin ,
kItemTypePan ,
kItemTypePot ,
kItemTypeRake ,
kItemTypeShovel ,
kItemTypeSmithyHammer ,
kItemTypeSpoon ,
kItemTypeBottle ,
kItemTypeCGiantSword ,
kItemTypeCGiantAxe ,
kItemTypeAllUseSword ,
kItemTypeMiscStack ,
kItemTypeBountyItem ,
kItemTypeRecipe ,
kItemTypeIncantation ,
};

enum Ability {
kAbilityStrength = 0,
kAbilityDexterity = 1,
Expand Down

0 comments on commit 3ce4a8c

Please sign in to comment.