xoreos  0.0.5
functions_module.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 
30 
31 #include "src/engines/nwn/game.h"
32 #include "src/engines/nwn/module.h"
35 
37 
38 namespace Engines {
39 
40 namespace NWN {
41 
44 }
45 
47  Location loc;
48 
49  loc.setArea (NWN::ObjectContainer::toArea(ctx.getParams()[0].getObject()));
50  loc.setFacing(ctx.getParams()[2].getFloat());
51 
52  float x, y, z;
53  ctx.getParams()[1].getVector(x, y, z);
54  loc.setPosition(x, y, z);
55 
56  ctx.getReturn() = loc;
57 }
58 
60  ctx.getReturn().setVector(0.0f, 0.0f, 0.0f);
61 
62  Location *loc = NWN::ObjectContainer::toLocation(ctx.getParams()[0].getEngineType());
63  if (!loc)
64  return;
65 
66  float x, y, z;
67  loc->getPosition(x, y, z);
68 
69  ctx.getReturn().setVector(x, y, z);
70 }
71 
73  Common::UString mod = ctx.getParams()[0].getString();
74 
75  if (!Game::hasModule(mod)) {
76  warning("Can't start module \"%s\": No such module", mod.c_str());
77  return;
78  }
79 
80  _game->getModule().load(mod);
81 }
82 
84  _game->getModule().exit();
85 
86  const Common::UString video = ctx.getParams()[0].getString();
87  if (!video.empty())
88  playVideo(video);
89 
90  playVideo("credits");
91 }
92 
95 }
96 
98  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
99 }
100 
101 } // End of namespace NWN
102 
103 } // End of namespace Engines
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:298
void playVideo(const Common::UString &video)
Play this video resource.
Definition: util.cpp:54
A container of Neverwinter Nights objects.
A class holding an UTF-8 string.
Definition: ustring.h:48
Context of an NWScript function.
void location(Aurora::NWScript::FunctionContext &ctx)
void getFirstPC(Aurora::NWScript::FunctionContext &ctx)
void exit()
Exit the currently running module.
Definition: module.cpp:440
void setArea(Area *area)
Set the location&#39;s area.
Definition: location.cpp:48
static Location * toLocation(Aurora::NWScript::EngineType *engineType)
static bool hasModule(Common::UString &module)
Does this module exist?
Definition: game.cpp:266
The context needed to run a Neverwinter Nights module.
void load(const Common::UString &module)
Load a module.
Definition: module.cpp:127
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Utility templates and functions.
void getNextPC(Aurora::NWScript::FunctionContext &ctx)
void setVector(float x, float y, float z)
Definition: variable.cpp:335
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void endGame(Aurora::NWScript::FunctionContext &ctx)
void setPosition(float x, float y, float z)
Set the location&#39;s position.
Definition: location.cpp:58
void warning(const char *s,...)
Definition: util.cpp:33
void setFacing(float facing)
Set the location&#39;s orientation.
Definition: location.cpp:68
void getModule(Aurora::NWScript::FunctionContext &ctx)
void getPosition(float &x, float &y, float &z) const
Return the location&#39;s position.
Definition: location.cpp:52
static Area * toArea(Aurora::NWScript::Object *object)
A location within a Neverwinter Nights area.
Generic Aurora engines utility functions.
The context handling the gameplay in Neverwinter Nights.
void getPositionFromLocation(Aurora::NWScript::FunctionContext &ctx)
void startNewModule(Aurora::NWScript::FunctionContext &ctx)
Neverwinter Nights engine functions.
Module & getModule()
Return the module context.
Definition: game.cpp:70