xoreos  0.0.5
functions_creatures.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/error.h"
26 
28 
32 
34 
35 namespace Engines {
36 
37 namespace KotOR {
38 
40  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
41 
42  Creature *creature = ObjectContainer::toCreature(object);
43 
44  if (!creature)
45  throw Common::Exception("Functions::getGender(): Object is not a creature");
46 
47  ctx.getReturn() = creature->getGender();
48 }
49 
51  Class creatureClass = Class(ctx.getParams()[0].getInt());
52  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
53 
54  Creature *creature = ObjectContainer::toCreature(object);
55 
56  if (!creature)
57  throw Common::Exception("Functions::getLevelByClass(): Object is not a creature");
58 
59  ctx.getReturn() = creature->getLevel(creatureClass);
60 }
61 
63  int position = ctx.getParams()[0].getInt();
64  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
65 
66  Creature *creature = ObjectContainer::toCreature(object);
67 
68  if (!creature)
69  throw Common::Exception("Functions::getLevelByPosition(): Object is not a creature");
70 
71  ctx.getReturn() = creature->getLevelByPosition(position - 1);
72 }
73 
75  int position = ctx.getParams()[0].getInt();
76  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
77 
78  Creature *creature = ObjectContainer::toCreature(object);
79 
80  if (!creature)
81  throw Common::Exception("Functions::getClassByPosition(): Object is not a creature");
82 
83  ctx.getReturn() = creature->getClassByPosition(position - 1);
84 }
85 
87  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
88 
89  Creature *creature = ObjectContainer::toCreature(object);
90 
91  Race race;
92  if (!creature)
93  race = kRaceInvalid;
94  else
95  race = creature->getRace();
96 
97  ctx.getReturn() = race;
98 }
99 
101  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
102 
103  Creature *creature = ObjectContainer::toCreature(object);
104 
105  if (!creature)
106  throw Common::Exception("Functions::getSubRace(): Object is not a creature");
107 
108  ctx.getReturn() = creature->getSubRace();
109 }
110 
111 } // End of namespace KotOR
112 
113 } // End of namespace Engines
A creature in a Star Wars: Knights of the Old Republic area.
void getRacialType(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
Class getClassByPosition(int position) const
Get the class by its position in the level vector.
Definition: creature.cpp:153
void getClassByPosition(Aurora::NWScript::FunctionContext &ctx)
Race getRace() const
Get the race of the creature.
Definition: creature.cpp:160
Basic exceptions to throw.
A container of Star Wars: Knights of the Old Republic objects.
void getGender(Aurora::NWScript::FunctionContext &ctx)
Gender getGender() const
Get the gender of the creature.
Definition: creature.cpp:133
StackException Exception
Definition: error.h:59
int getLevelByPosition(int position) const
Get the level by its position in the level vector.
Definition: creature.cpp:146
void getSubRace(Aurora::NWScript::FunctionContext &ctx)
Star Wars: Knights of the Old Republic engine functions.
void getLevelByPosition(Aurora::NWScript::FunctionContext &ctx)
static Creature * toCreature(Aurora::NWScript::Object *object)
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:117
SubRace getSubRace() const
Get the subrace of the creature.
Definition: creature.cpp:164
int getLevel(const Class &c) const
Get the level of the creature regarding a specific class.
Definition: creature.cpp:137
Basic Star Wars: Knights of the Old Republic type definitions.
void getLevelByClass(Aurora::NWScript::FunctionContext &ctx)