xoreos  0.0.5
functions_creature.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/util.h"
26 
28 
29 #include "src/engines/nwn/types.h"
31 #include "src/engines/nwn/object.h"
33 
35 
36 namespace Engines {
37 
38 namespace NWN {
39 
41  // TODO: nBaseAbilityScore
42 
44  Ability ability = (Ability) ctx.getParams()[1].getInt();
45 
46  ctx.getReturn() = creature ? (int32) creature->getAbility(ability) : 0;
47 }
48 
51 
52  ctx.getReturn() = creature ? creature->getSkillRank(ctx.getParams()[0].getInt()) : -1;
53 }
54 
57 
58  ctx.getReturn() = creature ? creature->hasFeat(ctx.getParams()[0].getInt()) : 0;
59 }
60 
62  ctx.getReturn() = (int32) kClassInvalid;
63 
65  if (!creature)
66  return;
67 
68  uint32 classID;
69  uint16 level;
70  creature->getClass(MAX<int32>(ctx.getParams()[0].getInt() - 1, 0), classID, level);
71 
72  ctx.getReturn() = (int32) classID;
73 }
74 
76  ctx.getReturn() = 0;
77 
79  if (!creature)
80  return;
81 
82  uint32 classID;
83  uint16 level;
84  creature->getClass(MAX<int32>(ctx.getParams()[0].getInt() - 1, 0), classID, level);
85 
86  ctx.getReturn() = (int32) level;
87 }
88 
91 
92  ctx.getReturn() = creature ? creature->getClassLevel(ctx.getParams()[0].getInt()) : 0;
93 }
94 
97 
98  ctx.getReturn() = (int32) (creature ? creature->getXP() : 0);
99 }
100 
103 
104  ctx.getReturn() = creature ? (creature->getCurrentHP() <= 0) : false;
105 }
106 
109 }
110 
113 
114  ctx.getReturn() = creature && creature->isDM();
115 }
116 
119 
120  ctx.getReturn() = (int32) (creature ? creature->getGender() : kGenderNone);
121 }
122 
125 
126  ctx.getReturn() = (int32) (creature ? creature->getRace() : kRaceInvalid);
127 }
128 
131 
132  ctx.getReturn() = creature ? creature->getHitDice() : 0;
133 }
134 
137 
138  ctx.getReturn() = creature ? (int32) creature->getLawChaos() : -1;
139 }
140 
143 
144  ctx.getReturn() = creature ? (int32) creature->getGoodEvil() : -1;
145 }
146 
149 
150  ctx.getReturn() = creature ? (int32) NWN::getAlignmentLawChaos(creature->getLawChaos()) : -1;
151 }
152 
155 
156  ctx.getReturn() = creature ? (int32) NWN::getAlignmentGoodEvil(creature->getGoodEvil()) : -1;
157 }
158 
161 
162  ctx.getReturn() = (int32) (creature ? creature->isCommandable() : false);
163 }
164 
167 
168  if (creature)
169  creature->setCommandable(ctx.getParams()[0].getInt() != 0);
170 }
171 
174 
175  ctx.getReturn() = (Aurora::NWScript::Object *) (creature ? creature->getMaster() : 0);
176 }
177 
179  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
180 
182  if (!creature)
183  return;
184 
185  const int type = ctx.getParams()[0].getInt();
186  const int nth = ctx.getParams()[2].getInt();
187 
188  ctx.getReturn() = creature->getAssociate((AssociateType) type, nth);
189 }
190 
192  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
193 
195  if (!creature)
196  return;
197 
198  ctx.getReturn() = creature->getAssociate(kAssociateTypeHenchman, ctx.getParams()[1].getInt());
199 }
200 
204  if (!master || !henchman)
205  return;
206 
207  master->addAssociate(*henchman, kAssociateTypeHenchman);
208 }
209 
213  if (!master || !henchman)
214  return;
215 
216  master->removeAssociate(*henchman);
217 }
218 
219 } // End of namespace NWN
220 
221 } // End of namespace Engines
uint8 getHitDice() const
Returns the number of hit dice, which is effectively the total number of levels.
Definition: creature.cpp:1031
A container of Neverwinter Nights objects.
void removeHenchman(Aurora::NWScript::FunctionContext &ctx)
static Creature * toCreature(Aurora::NWScript::Object *object)
Context of an NWScript function.
bool hasFeat(uint32 feat) const
Does the creature have this feat?
Definition: creature.cpp:1068
void getAssociate(Aurora::NWScript::FunctionContext &ctx)
Basic Neverwinter Nights type definitions.
void setCommandable(Aurora::NWScript::FunctionContext &ctx)
void removeAssociate(Creature &ssociate)
Remove an associate (henchman, familiar, ...).
Definition: creature.cpp:388
uint8 getAbility(Ability ability) const
Return a creature&#39;s ability score.
Definition: creature.cpp:1035
uint8 getGoodEvil() const
Get the creature&#39;s good-evil alignment.
Definition: creature.cpp:1003
static const uint32 kClassInvalid
Definition: types.h:279
void getCommandable(Aurora::NWScript::FunctionContext &ctx)
void getXP(Aurora::NWScript::FunctionContext &ctx)
uint32 getXP() const
Return the creature&#39;s XP.
Definition: creature.cpp:238
void getGender(Aurora::NWScript::FunctionContext &ctx)
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:118
void getAlignmentGoodEvil(Aurora::NWScript::FunctionContext &ctx)
int8 getSkillRank(uint32 skill) const
Return the creature&#39;s rank in this skill.
Definition: creature.cpp:1047
void getMaster(Aurora::NWScript::FunctionContext &ctx)
uint16_t uint16
Definition: types.h:202
Utility templates and functions.
Creature * getAssociate(AssociateType type, size_t nth=1) const
Get this creature&#39;s nth&#39;s associate of a specific type.
Definition: creature.cpp:400
bool isCommandable() const
Is this creature commandable (has a modifiable action queue)?
Definition: creature.cpp:428
void setCommandable(bool commandable)
Set whether this creature commandable (has a modifiable action queue).
Definition: creature.cpp:432
static Creature * toPC(Aurora::NWScript::Object *object)
uint16 getClassLevel(uint32 classID) const
Get the creature&#39;s level for this class.
Definition: creature.cpp:949
void getLevelByClass(Aurora::NWScript::FunctionContext &ctx)
Alignment getAlignmentGoodEvil(uint8 goodEvil)
Definition: types.cpp:42
void getHitDice(Aurora::NWScript::FunctionContext &ctx)
static const uint32 kRaceInvalid
Definition: types.h:278
void getClass(uint32 position, uint32 &classID, uint16 &level) const
Get the creature&#39;s class and level at that class slot position.
Definition: creature.cpp:938
An object in a Neverwinter Nights area.
void getAbilityScore(Aurora::NWScript::FunctionContext &ctx)
void getGoodEvilValue(Aurora::NWScript::FunctionContext &ctx)
uint32 getRace() const
Return the creature&#39;s race value.
Definition: creature.cpp:205
void getAlignmentLawChaos(Aurora::NWScript::FunctionContext &ctx)
void getLawChaosValue(Aurora::NWScript::FunctionContext &ctx)
uint8 getLawChaos() const
Get the creature&#39;s law-chaos alignment.
Definition: creature.cpp:1011
void getClassByPosition(Aurora::NWScript::FunctionContext &ctx)
void addAssociate(Creature &associate, AssociateType type)
Add an associate (henchman, familiar, ...).
Definition: creature.cpp:379
uint32_t uint32
Definition: types.h:204
int32 getCurrentHP() const
Return the current HP this creature has.
Definition: creature.cpp:242
Gender getGender() const
Get the creature&#39;s gender.
Definition: creature.cpp:190
A creature in a Neverwinter Nights area.
void addHenchman(Aurora::NWScript::FunctionContext &ctx)
void getRacialType(Aurora::NWScript::FunctionContext &ctx)
Creature * getMaster() const
Return the creature&#39;s master.
Definition: creature.cpp:424
void getHasFeat(Aurora::NWScript::FunctionContext &ctx)
void getIsDead(Aurora::NWScript::FunctionContext &ctx)
void getIsPC(Aurora::NWScript::FunctionContext &ctx)
bool isDM() const
Is the creature a dungeon master?
Definition: creature.cpp:230
Alignment getAlignmentLawChaos(uint8 lawChaos)
Definition: types.cpp:33
void getIsDM(Aurora::NWScript::FunctionContext &ctx)
void getLevelByPosition(Aurora::NWScript::FunctionContext &ctx)
void getHenchman(Aurora::NWScript::FunctionContext &ctx)
void getSkillRank(Aurora::NWScript::FunctionContext &ctx)
Neverwinter Nights engine functions.
int32_t int32
Definition: types.h:203