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 
27 #include "src/aurora/types.h"
28 #include "src/aurora/resman.h"
29 
33 
40 
42 
43 namespace Engines {
44 
45 namespace Witcher {
46 
48  Common::UString script = ctx.getScriptName();
49  if (script.empty())
50  throw Common::Exception("Functions::assignCommand(): Script needed");
51 
52  const Aurora::NWScript::ScriptState &state = ctx.getParams()[1].getScriptState();
53 
54  _game->getModule().delayScript(script, state, getParamObject(ctx, 0), ctx.getTriggerer(), 0);
55 }
56 
58  Common::UString script = ctx.getScriptName();
59  if (script.empty())
60  throw Common::Exception("Functions::assignCommand(): Script needed");
61 
62  uint32 delay = ctx.getParams()[0].getFloat() * 1000;
63 
64  const Aurora::NWScript::ScriptState &state = ctx.getParams()[1].getScriptState();
65 
66  _game->getModule().delayScript(script, state, ctx.getCaller(), ctx.getTriggerer(), delay);
67 }
68 
70  Common::UString script = ctx.getParams()[0].getString();
71 
72  // Max resource name length is 16, and ExecuteScript should truncate accordingly
73  script.truncate(16);
74 
75  if (!ResMan.hasResource(script, Aurora::kFileTypeNCS))
76  return;
77 
78  Aurora::NWScript::Object *object = getParamObject(ctx, 1);
79  try {
80  Aurora::NWScript::NCSFile ncs(script);
81 
82  // Let the child script inherit the environment of this parent script
84  if (env)
85  ncs.setEnvironment(*env);
86 
87  ncs.run(object);
88  } catch (...) {
89  Common::exceptionDispatcherWarning("Failed ExecuteScript(\"%s\", %s)",
90  script.c_str(), Aurora::NWScript::formatTag(object).c_str());
91  }
92 }
93 
94 // TODO: These functions need to assign an action, instead of simply delaying the script a bit.
95 
97  Common::UString script = ctx.getScriptName();
98  if (script.empty())
99  throw Common::Exception("Functions::actionDoCommand(): Script needed");
100 
101  const Aurora::NWScript::ScriptState &state = ctx.getParams()[0].getScriptState();
102 
103  _game->getModule().delayScript(script, state, ctx.getCaller(), ctx.getTriggerer(), 0);
104 }
105 
108  if (door)
110 }
111 
114  if (door)
116 }
117 
120 
121  if (object)
122  object->speakString(ctx.getParams()[0].getString(), ctx.getParams()[1].getInt());
123 }
124 
127  Witcher::Location *moveTo = Witcher::ObjectContainer::toLocation(ctx.getParams()[0].getEngineType());
128 
129  if (!object || !moveTo)
130  return;
131 
132  float x, y, z;
133  moveTo->getPosition(x, y, z);
134 
135  jumpTo(object, moveTo->getArea(), x, y, z);
136 }
137 
140  Witcher::Location *moveTo = Witcher::ObjectContainer::toLocation(ctx.getParams()[0].getEngineType());
141 
142  if (!object || !moveTo)
143  return;
144 
145  float x, y, z;
146  moveTo->getPosition(x, y, z);
147 
148  jumpTo(object, moveTo->getArea(), x, y, z);
149 
151 }
152 
154  // TODO: walkStraightLineToPoint
155  // bool walkStraightLineToPoint = ctx.getParams()[1].getInt() != 0;
156 
159 
160  if (!object || !moveTo)
161  return;
162 
163  float x, y, z;
164  moveTo->getPosition(x, y, z);
165 
166  jumpTo(object, moveTo->getArea(), x, y, z);
167 }
168 
172 
173  if (!object || !moveTo)
174  return;
175 
176  float x, y, z;
177  moveTo->getPosition(x, y, z);
178 
179  jumpTo(object, moveTo->getArea(), x, y, z);
180 
182 }
183 
184 } // End of namespace Witcher
185 
186 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
A container of The Witcher objects.
bool close(Object *closer)
The closer object closes this door.
Definition: door.cpp:167
void delayCommand(Aurora::NWScript::FunctionContext &ctx)
void actionCloseDoor(Aurora::NWScript::FunctionContext &ctx)
Common::UString formatTag(const Object *object)
Construct a string with the tag of this object.
Definition: util.cpp:34
A class holding an UTF-8 string.
Definition: ustring.h:48
An object within a Witcher area.
Definition: object.h:51
void actionOpenDoor(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
void truncate(const iterator &it)
Definition: ustring.cpp:343
Basic The Witcher type definitions.
void actionSpeakString(Aurora::NWScript::FunctionContext &ctx)
void assignCommand(Aurora::NWScript::FunctionContext &ctx)
void jumpTo(Witcher::Object *object, Area *area, float x, float y, float z)
Definition: functions.cpp:135
An NCS, BioWare&#39;s NWN Compile Script.
Definition: ncsfile.h:86
static Door * toDoor(Aurora::NWScript::Object *object)
Exception that provides a stack of explanations.
Definition: error.h:36
A door in a The Witcher area.
Module & getModule()
Return the module context.
Definition: game.cpp:67
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:124
Basic exceptions to throw.
A creature in a The Witcher area.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
void actionMoveToObject(Aurora::NWScript::FunctionContext &ctx)
const Variable & run(Object *owner=0, Object *triggerer=0)
Run the current script, from start to finish.
Definition: ncsfile.cpp:350
void unimplementedFunction(Aurora::NWScript::FunctionContext &ctx)
Definition: functions.cpp:98
void actionMoveToLocation(Aurora::NWScript::FunctionContext &ctx)
const Common::UString & getScriptName() const
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
VariableContainer * getCurrentEnvironment() const
void executeScript(Aurora::NWScript::FunctionContext &ctx)
Handling BioWare&#39;s NWN Compiled Scripts.
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
static Location * toLocation(Aurora::NWScript::EngineType *engineType)
void getPosition(float &x, float &y, float &z) const
Return the location&#39;s position.
Definition: location.cpp:52
Script, NWScript bytecode.
Definition: types.h:79
uint32_t uint32
Definition: types.h:204
The context needed to run a The Witcher module.
void actionDoCommand(Aurora::NWScript::FunctionContext &ctx)
void actionJumpToLocation(Aurora::NWScript::FunctionContext &ctx)
The Witcher engine functions.
void delayScript(const Common::UString &script, const Aurora::NWScript::ScriptState &state, Aurora::NWScript::Object *owner, Aurora::NWScript::Object *triggerer, uint32 delay)
Definition: module.cpp:505
The context handling the gameplay in The Witcher.
bool open(Object *opener)
The opener object opens this door.
Definition: door.cpp:145
NWScript utility functions.
void actionJumpToObject(Aurora::NWScript::FunctionContext &ctx)
The global resource manager for Aurora resources.
static Witcher::Object * toObject(::Aurora::NWScript::Object *object)
void setEnvironment(const VariableContainer &env)
Overwrite the environment.
Definition: ncsfile.cpp:302
void speakString(const Common::UString &string, uint32 volume)
Speak the specified string.
Definition: object.cpp:168