xoreos  0.0.5
functions_action.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 
30 #include "src/engines/kotor/game.h"
33 #include "src/engines/kotor/door.h"
34 
36 
37 namespace Engines {
38 
39 namespace KotOR {
40 
42  Common::UString script = ctx.getScriptName();
43  if (script.empty())
44  throw Common::Exception("Functions::assignCommand(): Script needed");
45 
46  const Aurora::NWScript::ScriptState &state = ctx.getParams()[1].getScriptState();
47 
48  _game->getModule().delayScript(script, state, getParamObject(ctx, 0), ctx.getTriggerer(), 0);
49 }
50 
52  Common::UString script = ctx.getScriptName();
53  if (script.empty())
54  throw Common::Exception("Functions::assignCommand(): Script needed");
55 
56  uint32 delay = ctx.getParams()[0].getFloat() * 1000;
57 
58  const Aurora::NWScript::ScriptState &state = ctx.getParams()[1].getScriptState();
59 
60  _game->getModule().delayScript(script, state, ctx.getCaller(), ctx.getTriggerer(), delay);
61 }
62 
64  const Common::UString &convName = ctx.getParams()[1].getString();
65  _game->getModule().startConversation(convName, ctx.getCaller());
66 }
67 
69  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
70  Door *door = ObjectContainer::toDoor(object);
71  if (!door)
72  throw Common::Exception("Functions::actionOpenDoor(): Object is not a door");
73 
74  door->open(0);
75 }
76 
78  Aurora::NWScript::Object *object = ctx.getParams()[0].getObject();
79  Door *door = ObjectContainer::toDoor(object);
80  if (!door)
81  throw Common::Exception("Functions::actionCloseDoor(): Object is not a door");
82 
83  door->close(0);
84 }
85 
88  if (!caller)
89  throw Common::Exception("Functions::actionMoveToObject(): Invalid caller");
90 
91  Engines::KotOR::Object *object = ObjectContainer::toObject(ctx.getParams()[0].getObject());
92  if (!object)
93  object = _game->getModule().getPC();
94 
95  float range = ctx.getParams()[2].getFloat();
96 
97  float x, y, z;
98  object->getPosition(x, y, z);
99 
100  Action action(kActionMoveToPoint);
101  action.setRange(range);
102  action.setPoint(x, y, z);
103 
104  caller->clearActionQueue();
105  caller->enqueueAction(action);
106 }
107 
110  if (!caller)
111  caller = _game->getModule().getPC();
112 
113  caller->clearActionQueue();
114 }
115 
116 } // End of namespace KotOR
117 
118 } // End of namespace Engines
void actionCloseDoor(Aurora::NWScript::FunctionContext &ctx)
void delayScript(const Common::UString &script, const Aurora::NWScript::ScriptState &state, Aurora::NWScript::Object *owner, Aurora::NWScript::Object *triggerer, uint32 delay)
Definition: module.cpp:911
static Door * toDoor(Aurora::NWScript::Object *object)
A class holding an UTF-8 string.
Definition: ustring.h:48
void assignCommand(Aurora::NWScript::FunctionContext &ctx)
void enqueueAction(const Action &action)
Append action to the character&#39;s action queue.
Definition: creature.cpp:772
bool close(Object *closer)
The closer object closes this door.
Definition: door.cpp:199
void clearAllActions(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
void setPoint(float x, float y, float z)
Definition: action.cpp:44
void setRange(float range)
Definition: action.cpp:54
Exception that provides a stack of explanations.
Definition: error.h:36
Basic exceptions to throw.
void actionStartConversation(Aurora::NWScript::FunctionContext &ctx)
The context handling the gameplay in Star Wars: Knights of the Old Republic.
A container of Star Wars: Knights of the Old Republic objects.
A door in a Star Wars: Knights of the Old Republic area.
const Common::UString & getScriptName() const
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void delayCommand(Aurora::NWScript::FunctionContext &ctx)
StackException Exception
Definition: error.h:59
void startConversation(const Common::UString &name, Aurora::NWScript::Object *owner=0)
Definition: module.cpp:987
Star Wars: Knights of the Old Republic engine functions.
static KotOR::Object * toObject(::Aurora::NWScript::Object *object)
void actionOpenDoor(Aurora::NWScript::FunctionContext &ctx)
uint32_t uint32
Definition: types.h:204
static Creature * toCreature(Aurora::NWScript::Object *object)
Module & getModule()
Return the module context.
Definition: game.cpp:65
void actionMoveToObject(Aurora::NWScript::FunctionContext &ctx)
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:117
The context needed to run a Star Wars: Knights of the Old Republic module.
bool open(Object *opener)
The opener object opens this door.
Definition: door.cpp:174
Basic Star Wars: Knights of the Old Republic type definitions.
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:181