xoreos  0.0.5
item.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/aurora/2dareg.h"
26 #include "src/aurora/2dafile.h"
27 #include "src/aurora/resman.h"
28 #include "src/aurora/gff3file.h"
29 #include "src/aurora/talkman.h"
30 
32 
33 #include "src/engines/kotor/item.h"
34 
35 namespace Engines {
36 
37 namespace KotOR {
38 
42 
43  load(uti->getTopLevel());
44 }
45 
46 void Item::load(const Aurora::GFF3Struct &gff) {
47  // Tag, name and description
48  _tag = gff.getString("Tag");
49  _name = gff.getString("LocalizedName");
50  _description = gff.getString("Description");
51 
52  // Base item
53  _baseItem = gff.getSint("BaseItem");
54  const Aurora::TwoDARow &twoDA = TwoDAReg.get2DA("baseitems").getRow(_baseItem);
55  _equipableSlots = static_cast<EquipmentSlot>(twoDA.getInt("equipableslots"));
56  _itemClass = twoDA.getString("itemclass");
57 
58  // Model, body and texture variations
59  _modelVariation = gff.getSint("ModelVariation");
60  _bodyVariation = gff.getSint("BodyVariation");
61  _textureVariation = gff.getSint("TextureVar");
62 }
63 
65  return _name;
66 }
67 
69  return _equipableSlots;
70 }
71 
73  return _bodyVariation;
74 }
75 
77  return _textureVariation;
78 }
79 
81  int variation = _modelVariation == 0 ? _textureVariation : _modelVariation;
82  if (variation == 0)
83  variation = 1;
84  return Common::UString::format("i%s_%03d", _itemClass.c_str(), variation);
85 }
86 
89 }
90 
91 } // End of namespace KotOR
92 
93 } // End of namespace Engines
int64 getSint(const Common::UString &field, int64 def=0) const
Definition: gff3file.cpp:473
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
const Common::UString getModelName() const
Definition: item.cpp:87
const Common::UString & getString(size_t column) const
Return the contents of a cell as a string.
Definition: 2dafile.cpp:59
A class holding an UTF-8 string.
Definition: ustring.h:48
int _bodyVariation
Definition: item.h:52
Common::UString _description
The object&#39;s description.
Definition: object.h:143
Common::UString _itemClass
Definition: item.h:48
int getTextureVariation() const
Definition: item.cpp:76
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
EquipmentSlot _equipableSlots
Definition: item.h:49
Item(const Common::UString &item)
Definition: item.cpp:39
Common::UString _name
The object&#39;s display name.
Definition: object.h:142
Handling BioWare&#39;s 2DAs (two-dimensional array).
A GFF (generic file format) V3.2/V3.3 file, found in all Aurora games except Sonic Chronicles: The Da...
Definition: gff3file.h:85
#define TwoDAReg
Shortcut for accessing the 2da registry.
Definition: 2dareg.h:101
The global 2DA registry.
int32 getInt(size_t column) const
Return the contents of a cell as an int.
Definition: 2dafile.cpp:75
void load(const Aurora::GFF3Struct &gff)
Definition: item.cpp:46
int _modelVariation
Definition: item.h:51
int _textureVariation
Definition: item.h:53
A struct within a GFF3.
Definition: gff3file.h:164
const Common::UString getIcon() const
Definition: item.cpp:80
The global talk manager for Aurora strings.
Item template (user), GFF.
Definition: types.h:91
Common::UString _tag
Definition: object.h:56
EquipmentSlot getEquipableSlots() const
Definition: item.cpp:68
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
int getBodyVariation() const
Definition: item.cpp:72
Generic Aurora engines utility functions.
An item in a Star Wars: Knights of the Old Republic area.
const Common::UString & getName() const
Definition: item.cpp:64
A row within a 2DA file.
Definition: 2dafile.h:61
The global resource manager for Aurora resources.