xoreos  0.0.5
chargeninfo.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/common/strutil.h"
26 #include "src/common/error.h"
27 
28 #include "src/aurora/ltrfile.h"
29 
31 
33 
34 namespace Engines {
35 
36 namespace KotOR {
37 
40  info->_gender = kGenderMale;
41  info->_class = kClassSoldier;
42  info->_face = std::rand() % 5;
43  info->_skin = Skin(std::rand() % kSkinMAX);
44 
45  Aurora::LTRFile humanMale("humanm");
46  Aurora::LTRFile humanLast("humanl");
47 
48  info->_name = humanMale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
49 
50  return info;
51 }
52 
55  info->_gender = kGenderMale;
56  info->_class = kClassScout;
57  info->_face = std::rand() % 5;
58  info->_skin = Skin(std::rand() % kSkinMAX);
59 
60  Aurora::LTRFile humanMale("humanm");
61  Aurora::LTRFile humanLast("humanl");
62 
63  info->_name = humanMale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
64 
65  return info;
66 }
67 
70  info->_gender = kGenderMale;
71  info->_class = kClassScoundrel;
72  info->_face = std::rand() % 5;
73  info->_skin = Skin(std::rand() % kSkinMAX);
74 
75  Aurora::LTRFile humanMale("humanm");
76  Aurora::LTRFile humanLast("humanl");
77 
78  info->_name = humanMale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
79 
80  return info;
81 }
82 
85  info->_gender = kGenderFemale;
86  info->_class = kClassSoldier;
87  info->_face = std::rand() % 5;
88  info->_skin = Skin(std::rand() % kSkinMAX);
89 
90  Aurora::LTRFile humanFemale("humanf");
91  Aurora::LTRFile humanLast("humanl");
92 
93  info->_name = humanFemale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
94 
95  return info;
96 }
97 
100  info->_gender = kGenderFemale;
101  info->_class = kClassScout;
102  info->_face = std::rand() % 5;
103  info->_skin = Skin(std::rand() % kSkinMAX);
104 
105  Aurora::LTRFile humanFemale("humanf");
106  Aurora::LTRFile humanLast("humanl");
107 
108  info->_name = humanFemale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
109 
110  return info;
111 }
112 
115  info->_gender = kGenderFemale;
116  info->_class = kClassScoundrel;
117  info->_face = std::rand() % 5;
118  info->_skin = Skin(std::rand() % kSkinMAX);
119 
120  Aurora::LTRFile humanFemale("humanf");
121  Aurora::LTRFile humanLast("humanl");
122 
123  info->_name = humanFemale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
124 
125  return info;
126 }
127 
129  return _name;
130 }
131 
133  Common::UString portrait = "po_p";
134 
135  switch (_gender) {
136  case kGenderMale:
137  portrait += "mh";
138  break;
139  case kGenderFemale:
140  portrait += "fh";
141  break;
142  default:
143  throw Common::Exception("Gender unknown for creating portrait string");
144  }
145 
146  switch (_skin) {
147  case kSkinA:
148  portrait += "a";
149  break;
150  case kSkinB:
151  portrait += "b";
152  break;
153  case kSkinC:
154  portrait += "c";
155  break;
156  default:
157  throw Common::Exception("Skin unknown for creating portrait string");
158  }
159 
160  portrait += Common::composeString(_face + 1);
161 
162  return portrait;
163 }
164 
166  return _skin;
167 }
168 
170  return _face;
171 }
172 
174  return _class;
175 }
176 
178  return _gender;
179 }
180 
182  _name = name;
183 }
184 
186  _skin = skin;
187 }
188 
190  _face = face;
191 }
192 
194  Common::ScopedPtr<Creature> creature(new Creature());
195 
196  creature->createPC(*this);
197  return creature.release();
198 }
199 
203 
204  GfxMan.lockFrame();
205 
206  _body->attachModel("headhook", _head);
207  delete head;
208 
209  GfxMan.unlockFrame();
210 
211  // Restart animation to apply it to the new head.
212  // TODO: Possibly there is another way of doing this, without restarting the animation?
213  _body->playAnimation("pause1", true, -1);
214 }
215 
217  if (_body)
218  return _body.get();
219 
221  if (!_body)
222  return 0;
223 
225  _body->attachModel("headhook", _head);
226 
227  return _body.get();
228 }
229 
231  _class = info._class;
232  _gender = info._gender;
233  _skin = info._skin;
234  _face = info._face;
235  _name = info._name;
236 }
237 
239  _class = info._class;
240  _gender = info._gender;
241  _skin = info._skin;
242  _face = info._face;
243  _name = info._name;
244 }
245 
247 
248 }
249 
250 } // End of namespace KotOR
251 
252 } // End of namespace Engines
static CharacterGenerationInfo * createRandomMaleScout()
Definition: chargeninfo.cpp:53
static CharacterGenerationInfo * createRandomMaleScoundrel()
Definition: chargeninfo.cpp:68
void operator=(const CharacterGenerationInfo &info)
A class holding an UTF-8 string.
Definition: ustring.h:48
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
Definition: strutil.cpp:276
uint8_t uint8
Definition: types.h:200
Skin getSkin() const
Get the skin type of the character.
void setName(const Common::UString &name)
Set the name of the Character.
Utility templates and functions for working with strings and streams.
Graphics::Aurora::Model * getModel()
Common::ScopedPtr< Graphics::Aurora::Model > _body
Definition: chargeninfo.h:91
Basic exceptions to throw.
static CharacterGenerationInfo * createRandomMaleSoldier()
Definition: chargeninfo.cpp:38
LTR File, which is used when generating player names.
Definition: ltrfile.h:44
Common::UString generateRandomName(size_t maxLetters) const
Generate a random name from the ltr file.
Definition: ltrfile.cpp:52
void info(const char *s,...)
Definition: util.cpp:69
StackException Exception
Definition: error.h:59
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
void setFace(uint8 face)
Set the face index of the character.
Graphics::Aurora::Model * _head
Definition: chargeninfo.h:90
static Common::UString getBodyMeshString(Gender gender, Class charClass, char state='b')
Generate a string for the body mesh.
Definition: creature.cpp:696
void setSkin(Skin)
Set the skin type of the Character.
PointerType get() const
Returns the plain pointer value.
Definition: scopedptr.h:96
static CharacterGenerationInfo * createRandomFemaleScoundrel()
static CharacterGenerationInfo * createRandomFemaleScout()
Definition: chargeninfo.cpp:98
Gender getGender() const
Get the gender of the Character.
Class getClass() const
Get the class of the character, defined in types.h.
Graphics::Aurora::Model * loadModelObject(const Common::UString &resref, const Common::UString &texture)
Definition: model.cpp:47
uint8_t getFace() const
Get the current face index of the character.
const Common::UString & getName() const
Get the name of the character.
static Common::UString getHeadMeshString(Gender gender, Skin skin, uint32 faceId)
Generate a string for the head mesh.
Definition: creature.cpp:731
The class for storing character information for generation.
static CharacterGenerationInfo * createRandomFemaleSoldier()
Definition: chargeninfo.cpp:83
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
File for creating random names in the character generation.
Common::UString getPortrait() const
Get the name of the portrait of this character.
Generic Aurora engines model functions.