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 
32 
33 #include "src/engines/jade/types.h"
35 #include "src/engines/jade/game.h"
40 
42 
43 namespace Engines {
44 
45 namespace Jade {
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()[1].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, 0);
79  try {
80  Aurora::NWScript::NCSFile ncs(script);
81 
82  ncs.run(object);
83  } catch (Common::Exception &e) {
84  e.add("Failed ExecuteScript(\"%s\", %s)", script.c_str(), formatTag(object).c_str());
85 
86  Common::printException(e, "WARNING: ");
87  }
88 }
89 
90 // TODO: These functions need to assign an action, instead of simply delaying the script a bit.
91 
93  Common::UString script = ctx.getScriptName();
94  if (script.empty())
95  throw Common::Exception("Functions::actionDoCommand(): Script needed");
96 
97  const Aurora::NWScript::ScriptState &state = ctx.getParams()[0].getScriptState();
98 
99  _game->getModule().delayScript(script, state, ctx.getCaller(), ctx.getTriggerer(), 0);
100 }
101 
104  if (door)
106 }
107 
110  if (door)
112 }
113 
116 
117  if (object)
118  object->speakString(ctx.getParams()[0].getInt());
119 }
120 
124  if (!source || !target)
125  return;
126 
128  if (!pc) {
129  warning("TODO: ActionStartConversation: Non-PC target \"%s\"", target->getTag().c_str());
130  return;
131  }
132 
133  if (source->getPCSpeaker()) {
134  if (source->getPCSpeaker() != pc) {
135  Creature *otherPC = Jade::ObjectContainer::toPC(source->getPCSpeaker());
136 
137  warning("Functions::actionStartConversation(): "
138  "Object \"%s\" already in conversation with PC \"%s\"",
139  source->getTag().c_str(), otherPC ? otherPC->getName().c_str() : "");
140  return;
141  }
142  }
143 
144  Common::UString conversation = ctx.getParams()[1].getString();
145  if (conversation.empty())
146  conversation = source->getConversation();
147 
148  /* TODO
149  const int32 range = ctx.getParams()[2].getInt();
150  const int32 delay = ctx.getParams()[3].getInt();
151  const bool ignoreLOS = ctx.getParams()[4].getInt() != 0;
152  */
153  const bool noWidescreen = ctx.getParams()[5].getInt() != 0;
154  const bool resetZoom = ctx.getParams()[6].getInt() != 0;
155 
156  _game->getModule().startConversation(conversation, *pc, *source, noWidescreen, resetZoom);
157 }
158 
161  if (!object)
162  return;
163 
164  Animation animation = (Animation) ctx.getParams()[0].getInt();
165 
166  // TODO: speed, second
167  // float speed = ctx.getParams()[1].getFloat();
168  // float seconds = ctx.getParams()[2].getFloat();
169 
170  object->playAnimation(animation);
171 }
172 
174  // TODO: walkStraightLineToPoint
175  // bool walkStraightLineToPoint = ctx.getParams()[1].getInt() != 0;
176 
178  Jade::Location *moveTo = Jade::ObjectContainer::toLocation(ctx.getParams()[0].getEngineType());
179 
180  if (!object || !moveTo)
181  return;
182 
183  float x, y, z;
184  moveTo->getPosition(x, y, z);
185 
186  jumpTo(object, moveTo->getArea(), x, y, z);
187 }
188 
190  // TODO: runType
191  // int32 runType = ctx.getParams()[1].getInt();
192  // int32 moveAnim = ctx.getParams()[2].getInt();
193 
195  Jade::Location *moveTo = Jade::ObjectContainer::toLocation(ctx.getParams()[0].getEngineType());
196 
197  if (!object || !moveTo)
198  return;
199 
200  float x, y, z;
201  moveTo->getPosition(x, y, z);
202 
203  jumpTo(object, moveTo->getArea(), x, y, z);
204 
206 }
207 
209  // TODO: walkStraightLineToPoint
210  // bool walkStraightLineToPoint = ctx.getParams()[1].getInt() != 0;
211 
214 
215  if (!object || !moveTo)
216  return;
217 
218  float x, y, z;
219  moveTo->getPosition(x, y, z);
220 
221  jumpTo(object, moveTo->getArea(), x, y, z);
222 }
223 
225  // TODO: runType and range
226  // int32 runType = ctx.getParams()[1].getInt();
227  // int32 range = ctx.getParams()[2].getInt();
228  // int32 moveAnim = ctx.getParams()[3].getInt();
229 
232 
233  if (!object || !moveTo)
234  return;
235 
236  float x, y, z;
237  moveTo->getPosition(x, y, z);
238 
239  jumpTo(object, moveTo->getArea(), x, y, z);
240 
242 }
243 
244 } // End of namespace Jade
245 
246 } // End of namespace Engines
An object within a Jade Empire area.
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
void actionSpeakStringByStrRef(Aurora::NWScript::FunctionContext &ctx)
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
bool startConversation(const Common::UString &conv, Creature &pc, Object &obj, bool noWidescreen=false, bool resetZoom=true)
Start a conversation.
Definition: module.cpp:127
void actionCloseDoor(Aurora::NWScript::FunctionContext &ctx)
Module & getModule()
Return the module context.
Definition: game.cpp:61
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
void assignCommand(Aurora::NWScript::FunctionContext &ctx)
void jumpTo(Jade::Object *object, Area *area, float x, float y, float z)
Definition: functions.cpp:129
Context of an NWScript function.
Jade Empire engine functions.
void truncate(const iterator &it)
Definition: ustring.cpp:343
A placeable in a Jade Empire area.
void executeScript(Aurora::NWScript::FunctionContext &ctx)
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:118
The context handling the gameplay in Jade Empire.
static Placeable * toPlaceable(Aurora::NWScript::Object *object)
void getPosition(float &x, float &y, float &z) const
Return the location&#39;s position.
Definition: location.cpp:52
Aurora::NWScript::Object * getPCSpeaker() const
Return the PC currently speaking with this object.
Definition: object.cpp:114
static Creature * toPC(Aurora::NWScript::Object *object)
void actionStartConversation(Aurora::NWScript::FunctionContext &ctx)
An NCS, BioWare&#39;s NWN Compile Script.
Definition: ncsfile.h:86
Exception that provides a stack of explanations.
Definition: error.h:36
const Common::UString & getTag() const
Definition: object.h:49
bool close(Object *closer)
The closer object closes this placeable.
Definition: placeable.cpp:200
A container of Jade Empire objects.
const Common::UString & getConversation() const
Return the object&#39;s default conversation (DLG).
Definition: object.cpp:82
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
static Jade::Object * toObject(::Aurora::NWScript::Object *object)
Basic Jade Empire type definitions.
const Variable & run(Object *owner=0, Object *triggerer=0)
Run the current script, from start to finish.
Definition: ncsfile.cpp:350
void delayCommand(Aurora::NWScript::FunctionContext &ctx)
void actionJumpToLocation(Aurora::NWScript::FunctionContext &ctx)
void speakString(int32 resref)
Speak the specified string.
Definition: object.cpp:195
const Common::UString & getScriptName() const
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
bool open(Object *opener)
The opener object opens this placeable.
Definition: placeable.cpp:183
void warning(const char *s,...)
Definition: util.cpp:33
An object within a Jade area.
Definition: object.h:53
Handling BioWare&#39;s NWN Compiled Scripts.
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
void actionJumpToObject(Aurora::NWScript::FunctionContext &ctx)
Script, NWScript bytecode.
Definition: types.h:79
void actionDoCommand(Aurora::NWScript::FunctionContext &ctx)
uint32_t uint32
Definition: types.h:204
void actionMoveToObject(Aurora::NWScript::FunctionContext &ctx)
A module.
void actionOpenDoor(Aurora::NWScript::FunctionContext &ctx)
static Location * toLocation(Aurora::NWScript::EngineType *engineType)
void actionMoveToLocation(Aurora::NWScript::FunctionContext &ctx)
void actionPlayAnimation(Aurora::NWScript::FunctionContext &ctx)
void unimplementedFunction(Aurora::NWScript::FunctionContext &ctx)
Definition: functions.cpp:97
void printException(Exception &e, const UString &prefix)
Print a whole exception stack to stderr and the log.
Definition: error.cpp:95
const Common::UString & getName() const
Return the object&#39;s name.
Definition: object.cpp:74
The global resource manager for Aurora resources.
A creature in a Jade Empire area.
void delayScript(const Common::UString &script, const Aurora::NWScript::ScriptState &state, Aurora::NWScript::Object *owner, Aurora::NWScript::Object *triggerer, uint32 delay)
Definition: module.cpp:342