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/nwn2/types.h"
30 #include "src/engines/nwn2/game.h"
35 
37 
38 namespace Engines {
39 
40 namespace NWN2 {
41 
43  // TODO: nBaseAbilityScore
44 
46  Ability ability = (Ability) ctx.getParams()[1].getInt();
47 
48  ctx.getReturn() = creature ? (int32) creature->getAbility(ability) : 0;
49 }
50 
53 
54  ctx.getReturn() = creature ? creature->getSkillRank(ctx.getParams()[0].getInt()) : -1;
55 }
56 
59 
60  ctx.getReturn() = creature ? creature->hasFeat(ctx.getParams()[0].getInt()) : 0;
61 }
62 
64  ctx.getReturn() = (int32) kClassInvalid;
65 
67  if (!creature)
68  return;
69 
70  uint32 classID;
71  uint16 level;
72  creature->getClass(MAX<int32>(ctx.getParams()[0].getInt() - 1, 0), classID, level);
73 
74  ctx.getReturn() = (int32) classID;
75 }
76 
78  ctx.getReturn() = 0;
79 
81  if (!creature)
82  return;
83 
84  uint32 classID;
85  uint16 level;
86  creature->getClass(MAX<int32>(ctx.getParams()[0].getInt() - 1, 0), classID, 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) NWN2::getAlignmentLawChaos(creature->getLawChaos()) : -1;
151 }
152 
155 
156  ctx.getReturn() = creature ? (int32) NWN2::getAlignmentGoodEvil(creature->getGoodEvil()) : -1;
157 }
158 
161  Creature *pc = _game->getModule().getPC();
162 
163  ctx.getReturn() = (int32) ((creature && (creature == pc)) ? 1 : 0);
164 }
165 
168  Creature *pc = _game->getModule().getPC();
169 
170  ctx.getReturn() = (Aurora::NWScript::Object *) ((creature == pc) ? creature : (Creature *) 0);
171 }
172 
173 } // End of namespace NWN2
174 
175 } // End of namespace Engines
uint16 getClassLevel(uint32 classID) const
Get the creature&#39;s level for this class.
Definition: creature.cpp:539
void getIsPC(Aurora::NWScript::FunctionContext &ctx)
The context handling the gameplay in Neverwinter Nights 2.
bool hasFeat(uint32 feat) const
Does the creature have this feat?
Definition: creature.cpp:576
void getLevelByPosition(Aurora::NWScript::FunctionContext &ctx)
void getHitDice(Aurora::NWScript::FunctionContext &ctx)
void getRacialType(Aurora::NWScript::FunctionContext &ctx)
uint8 getGoodEvil() const
Definition: creature.cpp:551
void getClassByPosition(Aurora::NWScript::FunctionContext &ctx)
static const uint32 kClassInvalid
Definition: types.h:135
void getIsDM(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
void getFactionLeader(Aurora::NWScript::FunctionContext &ctx)
uint32 getGender() const
Get the creature&#39;s gender.
Definition: creature.cpp:170
static Creature * toCreature(Aurora::NWScript::Object *object)
uint8 getAbility(Ability ability) const
Return a creature&#39;s ability score.
Definition: creature.cpp:563
The context needed to run a Neverwinter Nights 2 module.
uint8 getHitDice() const
Returns the number of hit dice, which is effectively the total number of levels.
Definition: creature.cpp:559
Neverwinter Nights 2 engine functions.
A creature in a Neverwinter Nights 2 area.
A container of Neverwinter Nights 2 objects.
uint16_t uint16
Definition: types.h:202
void getSkillRank(Aurora::NWScript::FunctionContext &ctx)
Alignment getAlignmentGoodEvil(uint8 goodEvil)
Definition: types.cpp:40
uint32 getRace() const
Return the creature&#39;s race value.
Definition: creature.cpp:185
Utility templates and functions.
Basic Neverwinter Nights 2 type definitions.
void getIsRosterMember(Aurora::NWScript::FunctionContext &ctx)
void getAlignmentGoodEvil(Aurora::NWScript::FunctionContext &ctx)
int8 getSkillRank(uint32 skill) const
Return the creature&#39;s rank in this skill.
Definition: creature.cpp:569
Alignment getAlignmentLawChaos(uint8 lawChaos)
Definition: types.cpp:31
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:528
bool isDM() const
Is the creature a dungeon master?
Definition: creature.cpp:205
void getHasFeat(Aurora::NWScript::FunctionContext &ctx)
void getLevelByClass(Aurora::NWScript::FunctionContext &ctx)
void getIsDead(Aurora::NWScript::FunctionContext &ctx)
int32 getCurrentHP() const
Return the current HP this creature has.
Definition: creature.cpp:217
void getAlignmentLawChaos(Aurora::NWScript::FunctionContext &ctx)
uint32_t uint32
Definition: types.h:204
void getAbilityScore(Aurora::NWScript::FunctionContext &ctx)
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:118
An object in a Neverwinter Nights 2 area.
void getXP(Aurora::NWScript::FunctionContext &ctx)
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:78
void getLawChaosValue(Aurora::NWScript::FunctionContext &ctx)
Module & getModule()
Return the module context.
Definition: game.cpp:64
uint8 getLawChaos() const
Definition: creature.cpp:555
void getGender(Aurora::NWScript::FunctionContext &ctx)
void getGoodEvilValue(Aurora::NWScript::FunctionContext &ctx)
static Creature * toPC(Aurora::NWScript::Object *object)
int32_t int32
Definition: types.h:203
static const uint32 kRaceInvalid
Definition: types.h:133
uint32 getXP() const
Return the creature&#39;s XP.
Definition: creature.cpp:213