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 #include "src/common/scopedptr.h"
28 
29 #include "src/aurora/ltrfile.h"
30 
31 #include "chargeninfo.h"
32 
33 namespace Engines {
34 
35 namespace KotOR2 {
36 
39  info->_gender = kGenderMale;
40  info->_class = kClassJediConsular;
41  info->_skin = Skin(std::rand() % kSkinMAX);
42  switch (info->_skin) {
43  case kSkinH:
44  info->_face = std::rand() % 2;
45  break;
46  default:
47  info->_face = std::rand() % 5;
48  break;
49  }
50 
51  Aurora::LTRFile humanMale("humanm");
52  Aurora::LTRFile humanLast("humanl");
53 
54  info->_name = humanMale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
55 
56  return info;
57 }
58 
61  info->_gender = kGenderFemale;
62  info->_class = kClassJediConsular;
63  info->_skin = Skin(std::rand() % kSkinMAX);
64  switch (info->_skin) {
65  case kSkinH:
66  info->_face = std::rand() % 2;
67  break;
68  default:
69  info->_face = std::rand() % 5;
70  break;
71  }
72 
73  Aurora::LTRFile humanFemale("humanf");
74  Aurora::LTRFile humanLast("humanl");
75 
76  info->_name = humanFemale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
77 
78  return info;
79 }
80 
83  info->_gender = kGenderMale;
84  info->_class = kClassJediGuardian;
85  info->_skin = Skin(std::rand() % kSkinMAX);
86  switch (info->_skin) {
87  case kSkinH:
88  info->_face = std::rand() % 2;
89  break;
90  default:
91  info->_face = std::rand() % 5;
92  break;
93  }
94 
95  Aurora::LTRFile humanMale("humanm");
96  Aurora::LTRFile humanLast("humanl");
97 
98  info->_name = humanMale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
99 
100  return info;
101 }
102 
105  info->_gender = kGenderFemale;
106  info->_class = kClassJediGuardian;
107  info->_skin = Skin(std::rand() % kSkinMAX);
108  switch (info->_skin) {
109  case kSkinH:
110  info->_face = std::rand() % 2;
111  break;
112  default:
113  info->_face = std::rand() % 5;
114  break;
115  }
116 
117  Aurora::LTRFile humanFemale("humanf");
118  Aurora::LTRFile humanLast("humanl");
119 
120  info->_name = humanFemale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
121 
122  return info;
123 }
124 
127  info->_gender = kGenderMale;
128  info->_class = kClassJediSentinel;
129  info->_skin = Skin(std::rand() % kSkinMAX);
130  switch (info->_skin) {
131  case kSkinH:
132  info->_face = std::rand() % 2;
133  break;
134  default:
135  info->_face = std::rand() % 5;
136  break;
137  }
138 
139  Aurora::LTRFile humanMale("humanm");
140  Aurora::LTRFile humanLast("humanl");
141 
142  info->_name = humanMale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
143 
144  return info;
145 }
146 
149  info->_gender = kGenderFemale;
150  info->_class = kClassJediSentinel;
151  info->_skin = Skin(std::rand() % kSkinMAX);
152  switch (info->_skin) {
153  case kSkinH:
154  info->_face = std::rand() % 2;
155  break;
156  default:
157  info->_face = std::rand() % 5;
158  break;
159  }
160 
161  Aurora::LTRFile humanFemale("humanf");
162  Aurora::LTRFile humanLast("humanl");
163 
164  info->_name = humanFemale.generateRandomName(8) + " " + humanLast.generateRandomName(8);
165 
166  return info;
167 }
168 
170 }
171 
173  return _name;
174 }
175 
177  return _skin;
178 }
179 
180 unsigned int CharacterGenerationInfo::getFace() const {
181  return _face;
182 }
183 
185  return _gender;
186 }
187 
189  return _class;
190 }
191 
193  _name = name;
194 }
195 
197  _skin = skin;
198 }
199 
200 void CharacterGenerationInfo::setFace(unsigned int face) {
201  _face = face;
202 }
203 
205  Common::UString body;
206 
207  body += "p";
208 
209  switch (_gender) {
210  case kGenderMale:
211  body += "m";
212  break;
213  case kGenderFemale:
214  body += "f";
215  break;
216  default:
217  throw Common::Exception("Invalid gender");
218  }
219 
220  body += "bam";
221 
222  return body;
223 }
224 
226  Common::UString body;
227 
228  body += "p";
229 
230  switch (_gender) {
231  case kGenderMale:
232  body += "m";
233  break;
234  case kGenderFemale:
235  body += "f";
236  break;
237  default:
238  throw Common::Exception("Invalid gender");
239  }
240 
241  body += "bam";
242 
243  switch (_skin) {
244  case kSkinA:
245  case kSkinH:
246  body += "a";
247  break;
248  case kSkinB:
249  body += "b";
250  break;
251  case kSkinC:
252  body += "c";
253  break;
254  default:
255  throw Common::Exception("Invalid skin");
256  }
257 
258  body += "01";
259 
260  return body;
261 }
262 
264  Common::UString head;
265 
266  head += "p";
267 
268  switch (_gender) {
269  case kGenderMale:
270  head += "m";
271  break;
272  case kGenderFemale:
273  head += "f";
274  break;
275  default:
276  throw Common::Exception("Invalid gender");
277  }
278 
279  head += "h";
280 
281  switch (_skin) {
282  case kSkinA:
283  head += "a";
284  break;
285  case kSkinB:
286  head += "b";
287  break;
288  case kSkinC:
289  head += "c";
290  break;
291  case kSkinH:
292  head += "h";
293  break;
294  default:
295  throw Common::Exception("Invalid skin");
296  }
297 
298  if (_face >= 10)
299  head += Common::composeString(getFaceId());
300  else
301  head += "0" + Common::composeString(getFaceId());
302 
303  return head;
304 }
305 
307  Common::UString portrait;
308  portrait += "po_p";
309 
310  switch (_gender) {
311  case kGenderMale:
312  portrait += "m";
313  break;
314  case kGenderFemale:
315  portrait += "f";
316  break;
317  default:
318  throw Common::Exception("Gender unknown for creating portrait string");
319  }
320 
321  portrait += "h";
322 
323  switch (_skin) {
324  case kSkinA:
325  switch (_face) {
326  case 0:
327  portrait += "a01";
328  break;
329  case 1:
330  portrait += "a03";
331  break;
332  case 2:
333  if (_gender == kGenderFemale)
334  portrait += "a04";
335  else if (_gender == kGenderMale)
336  portrait += "a05";
337  break;
338  case 3:
339  if (_gender == kGenderFemale)
340  portrait += "a05";
341  else if (_gender == kGenderMale)
342  portrait += "a06";
343  break;
344  case 4:
345  if (_gender == kGenderFemale)
346  portrait += "a06";
347  else if (_gender == kGenderMale)
348  portrait += "a07";
349  break;
350  default:
351  throw Common::Exception("invalid face id");
352  }
353  break;
354  case kSkinB:
355  portrait += "b";
356  if (_gender == kGenderFemale)
357  portrait += ("0" + Common::composeString(_face + 1));
358  else
359  if (_face + 6 >= 10)
360  portrait += Common::composeString(_face + 6);
361  else
362  portrait += ("0" + Common::composeString(_face + 6));
363  break;
364  case kSkinC:
365  switch (_face) {
366  case 0:
367  portrait += "c01";
368  break;
369  case 1:
370  if (_gender == kGenderFemale)
371  portrait += "c02";
372  else if (_gender == kGenderMale)
373  portrait += "c03";
374  break;
375  case 2:
376  if (_gender == kGenderFemale)
377  portrait += "c05";
378  else if (_gender == kGenderMale)
379  portrait += "c04";
380  break;
381  case 3:
382  portrait += "c06";
383  break;
384  case 4:
385  portrait += "c07";
386  break;
387  default:
388  throw Common::Exception("invalid face id");
389  }
390  break;
391  case kSkinH:
392  portrait += ("h0" + Common::composeString(_face + 1));
393  break;
394  default:
395  throw Common::Exception("invalid skin id");
396  }
397 
398  return portrait;
399 }
400 
402  Common::ScopedPtr<Creature> creature(new Creature());
403 
404  creature->createPC(*this);
405  return creature.release();
406 }
407 
409  switch (_skin) {
410  case kSkinA:
411  switch (_face) {
412  case 0: return 1;
413  case 1: return 3;
414  case 2:
415  if (_gender == kGenderFemale) return 4;
416  else if (_gender == kGenderMale) return 5;
417  else throw Common::Exception("invalid gender");
418  case 3:
419  if (_gender == kGenderFemale) return 5;
420  else if (_gender == kGenderMale) return 6;
421  else throw Common::Exception("invalid gender");
422  case 4:
423  if (_gender == kGenderFemale) return 6;
424  else if (_gender == kGenderMale) return 7;
425  else throw Common::Exception("invalid gender");
426  default:
427  throw Common::Exception("invalid face id");
428  }
429  case kSkinB:
430  if (_gender == kGenderFemale) return _face + 1;
431  else return _face + 6;
432  case kSkinC:
433  switch (_face) {
434  case 0: return 1;
435  case 1:
436  if (_gender == kGenderFemale) return 2;
437  else if (_gender == kGenderMale) return 3;
438  else throw Common::Exception("invalid gender");
439  case 2:
440  if (_gender == kGenderFemale) return 5;
441  else if (_gender == kGenderMale) return 4;
442  else throw Common::Exception("invalid gender");
443  case 3: return 6;
444  case 4: return 7;
445  default:
446  throw Common::Exception("invalid face id");
447  }
448  case kSkinH: return _face + 1;
449  default:
450  throw Common::Exception("invalid skin id");
451  }
452 }
453 
454 } // End of namespace KotOR2
455 
456 } // End of namespace Engines
const Common::UString & getName() const
Get the name of the character.
A class holding an UTF-8 string.
Definition: ustring.h:48
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
static CharacterGenerationInfo * createRandomMaleGuardian()
Definition: chargeninfo.cpp:81
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
Definition: strutil.cpp:276
The KotOR 2 character generation info.
Utility templates and functions for working with strings and streams.
void setFace(unsigned int face)
Set the face index of the character.
A simple scoped smart pointer template.
void setSkin(Skin skin)
Set the skin type of the Character.
static CharacterGenerationInfo * createRandomMaleSentinel()
Basic exceptions to throw.
Common::UString getHeadId() const
Get the Id for the head mesh.
Common::UString getBodyId() const
Get the Id for the body mesh.
unsigned int getFace() const
Get the current face index of the character.
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
static CharacterGenerationInfo * createRandomFemaleGuardian()
Skin getSkin() const
Get the skin type of the character.
StackException Exception
Definition: error.h:59
static CharacterGenerationInfo * createRandomMaleConsular()
Definition: chargeninfo.cpp:37
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
unsigned int getFaceId() const
Get the face id regarding the skin and gender.
static CharacterGenerationInfo * createRandomFemaleSentinel()
Common::UString getBodyTextureId() const
Get the Id for the body mesh texture.
void setName(const Common::UString &name)
Set the name of the Character.
static CharacterGenerationInfo * createRandomFemaleConsular()
Definition: chargeninfo.cpp:59
Creature * getCharacter() const
Create a creature object from the info.
File for creating random names in the character generation.