xoreos  0.0.5
functions_object.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 // TODO: check what happens on using invalid objects.
26 
27 #include "src/common/util.h"
28 #include "src/common/scopedptr.h"
29 
31 
33 #include "src/engines/kotor/game.h"
38 #include "src/engines/kotor/area.h"
39 
41 
42 namespace Engines {
43 
44 namespace KotOR {
45 
47  ctx.getReturn() = ctx.getTriggerer();
48 }
49 
51  // TODO: This should return the *last* entered object, i.e. it should remember past triggerers.
52  ctx.getReturn() = ctx.getTriggerer();
53 }
54 
56  // TODO: This should return the *last* exited object, i.e. it should remember past triggerers.
57  ctx.getReturn() = ctx.getTriggerer();
58 }
59 
61  ctx.getReturn() = getParamObject(ctx, 0) != 0;
62 }
63 
66 }
67 
69  Common::UString name = ctx.getParams()[0].getString();
70  int nth = ctx.getParams()[1].getInt();
71 
73  for (int i = 0; i < nth; ++i) {
74  search->next();
75  }
76 
77  ctx.getReturn() = search->get();
78 }
79 
81  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
82 
83  Object *kotorObject = ObjectContainer::toObject(object);
84 
85  if (!kotorObject)
86  throw Common::Exception("Functions::getMinOneHP(): invalid object");
87 
88  ctx.getReturn() = kotorObject->getMinOneHitPoints();
89 }
90 
92  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
93  bool enabled = ctx.getParams()[1].getInt();
94 
95  Object *kotorObject = ObjectContainer::toObject(object);
96 
97  if (!kotorObject)
98  throw Common::Exception("Functions::setMinOneHP(): invalid object");
99 
100  kotorObject->setMinOneHitPoints(enabled);
101 }
102 
104  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
105 
106  Object *kotorObject = ObjectContainer::toObject(object);
107 
108  ctx.getReturn() = kotorObject ? kotorObject->getCurrentHitPoints() : 0;
109 }
110 
112  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
113 
114  Object *kotorObject = ObjectContainer::toObject(object);
115 
116  ctx.getReturn() = kotorObject ? kotorObject->getMaxHitPoints() : 0;
117 }
118 
120  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
121  int maxHitPoints = ctx.getParams()[1].getInt();
122 
123  if (maxHitPoints == 0)
124  maxHitPoints = 1;
125 
126  Object *kotorObject = ObjectContainer::toObject(object);
127  if (!kotorObject)
128  throw Common::Exception("Functions::setMaxHitPoints(): Invalid object");
129 
130  kotorObject->setCurrentHitPoints(maxHitPoints);
131  kotorObject->setMaxHitPoints(maxHitPoints);
132 }
133 
135  const Common::UString &itemTag = ctx.getParams()[0].getString();
136  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
137  int32 count = ctx.getParams()[2].getInt();
138 
139  Creature *creature = ObjectContainer::toCreature(object);
140  if (creature) {
141  creature->getInventory().addItem(itemTag, count);
142  return;
143  }
144 
145  Placeable *placeable = ObjectContainer::toPlaceable(object);
146  if (placeable) {
147  placeable->getInventory().addItem(itemTag, count);
148  return;
149  }
150 
151  throw Common::Exception("Functions::createItemOnObject(): Invalid object");
152 }
153 
155  // TODO: return current area of the specified object
157 }
158 
160  Engines::KotOR::Creature *creature = 0;
161 
162  Aurora::NWScript::Object *object = ctx.getParams()[1].getObject();
163  if (object)
164  creature = ObjectContainer::toCreature(object);
165  else
166  creature = _game->getModule().getPC();
167 
168  if (!creature)
169  throw Common::Exception("Functions::getItemInSlot(): Invalid creature");
170 
171  int slot = ctx.getParams()[0].getInt();
172  Item *item = creature->getEquipedItem(static_cast<EquipmentSlot>(1U << slot));
173  if (item)
174  ctx.getReturn() = item;
175 }
176 
178  Engines::KotOR::Object *object = ObjectContainer::toObject(ctx.getParams()[0].getObject());
179  if (object)
181 }
182 
183 } // End of namespace KotOR
184 
185 } // End of namespace Engines
void createItemOnObject(Aurora::NWScript::FunctionContext &ctx)
A class holding an UTF-8 string.
Definition: ustring.h:48
void getEnteringObject(Aurora::NWScript::FunctionContext &ctx)
void getIsPC(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
void getMinOneHP(Aurora::NWScript::FunctionContext &ctx)
void getObjectByTag(Aurora::NWScript::FunctionContext &ctx)
Inventory & getInventory()
Definition: creature.cpp:643
void destroyObject(Aurora::NWScript::FunctionContext &ctx)
void getCurrentHitPoints(Aurora::NWScript::FunctionContext &ctx)
A simple scoped smart pointer template.
void setMinOneHP(Aurora::NWScript::FunctionContext &ctx)
void setCurrentHitPoints(int hitpoints)
Set the current hitpoints.
Definition: object.cpp:103
int getCurrentHitPoints()
Return the objects current hitpoints.
Definition: object.cpp:110
The context handling the gameplay in Star Wars: Knights of the Old Republic.
Utility templates and functions.
A container of Star Wars: Knights of the Old Republic objects.
void getClickingObject(Aurora::NWScript::FunctionContext &ctx)
bool getMinOneHitPoints() const
Get if the object has a minimum of one hp.
Definition: object.cpp:118
int getMaxHitPoints()
Get the maximum hit points for the objects.
Definition: object.cpp:99
ObjectSearch * findObjectsByTag(const Common::UString &tag) const
Return a search context to iterate over all objects with this tag.
void setMinOneHitPoints(bool enabled)
Set if the object has a minimum of one hp.
Definition: object.cpp:114
StackException Exception
Definition: error.h:59
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
void getItemInSlot(Aurora::NWScript::FunctionContext &ctx)
Star Wars: Knights of the Old Republic engine functions.
The context holding a Star Wars: Knights of the Old Republic area.
Inventory & getInventory()
Definition: placeable.cpp:256
A placeable in a Star Wars: Knights of the Old Republic area.
void addItem(const Common::UString &tag, int count=1)
Definition: inventory.cpp:31
static KotOR::Object * toObject(::Aurora::NWScript::Object *object)
static Creature * toPC(Aurora::NWScript::Object *object)
void getExitingObject(Aurora::NWScript::FunctionContext &ctx)
void getIsObjectValid(Aurora::NWScript::FunctionContext &ctx)
static Placeable * toPlaceable(Aurora::NWScript::Object *object)
void setMaxHitPoints(Aurora::NWScript::FunctionContext &ctx)
static Creature * toCreature(Aurora::NWScript::Object *object)
Module & getModule()
Return the module context.
Definition: game.cpp:65
Item * getEquipedItem(EquipmentSlot slot) const
Definition: creature.cpp:647
void removeObject(KotOR::Object *object)
Definition: area.cpp:744
void getMaxHitPoints(Aurora::NWScript::FunctionContext &ctx)
An object in a Star Wars: Knights of the Old Republic area.
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:117
void setMaxHitPoints(int maxHP)
Set the maximum hit points for the objects.
Definition: object.cpp:95
The context needed to run a Star Wars: Knights of the Old Republic module.
Area * getCurrentArea()
Return the area the PC is currently in.
Definition: module.cpp:907
void getArea(Aurora::NWScript::FunctionContext &ctx)
Basic Star Wars: Knights of the Old Republic type definitions.
int32_t int32
Definition: types.h:203
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:181