xoreos  0.0.5
functions_conversation.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 
27 #include "src/aurora/talkman.h"
28 
30 
31 #include "src/engines/nwn/game.h"
32 #include "src/engines/nwn/module.h"
34 #include "src/engines/nwn/object.h"
36 
38 
39 namespace Engines {
40 
41 namespace NWN {
42 
45 
46  if (object)
47  object->speakString(ctx.getParams()[0].getString(), ctx.getParams()[1].getInt());
48 }
49 
52  if (!object)
53  return;
54 
55  // TODO: Volume
56  const uint32 strRef = (uint32) ctx.getParams()[0].getInt();
57  const uint32 volume = (uint32) ctx.getParams()[1].getInt();
58 
59  object->speakString(TalkMan.getString(strRef).c_str(), volume);
60 }
61 
64  if (!object)
65  return;
66 
67  const Common::UString &dlg = ctx.getParams()[0].getString();
69 
70  object->speakOneLiner(dlg, tokenTarget);
71 }
72 
74  ctx.getReturn() = 0;
75 
76  // Get the script object parameters
77  Aurora::NWScript::Object *obj1 = ctx.getCaller();
79  if (!obj2)
80  obj2 = ctx.getTriggerer();
81  if (!obj2)
82  obj2 = _game->getModule().getPC();
83 
84  // Try to convert them to an NWN Creature and Object
87 
88  // Try the other way round, if necessary
89  if (!pc || !object) {
90  pc = NWN::ObjectContainer::toPC(obj1);
91  object = NWN::ObjectContainer::toObject(obj2);
92  }
93 
94  // Fail
95  if (!pc || !object)
96  return;
97 
98  if (object->getPCSpeaker()) {
99  if (object->getPCSpeaker() != pc) {
100  Creature *otherPC = NWN::ObjectContainer::toPC(object->getPCSpeaker());
101 
102  warning("Functions::beginConversation(): "
103  "Object \"%s\" already in conversation with PC \"%s\"",
104  object->getTag().c_str(), otherPC ? otherPC->getName().c_str() : "");
105  return;
106  }
107  }
108 
109  Common::UString conversation = ctx.getParams()[0].getString();
110  if (conversation.empty())
111  conversation = object->getConversation();
112 
113  ctx.getReturn() = _game->getModule().startConversation(conversation, *pc, *object);
114 }
115 
117  Aurora::NWScript::Object *speaker = 0;
118 
120  if (object)
121  speaker = object->getPCSpeaker();
122 
123  ctx.getReturn() = speaker;
124 }
125 
127  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
128 
130 }
131 
134 
135  ctx.getReturn() = object ? (object->getPCSpeaker() != 0) : 0;
136 }
137 
139  ctx.getReturn() = -1;
140 
142 }
143 
144 } // End of namespace NWN
145 
146 } // End of namespace Engines
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:298
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
A container of Neverwinter Nights objects.
A class holding an UTF-8 string.
Definition: ustring.h:48
const Common::UString & getConversation() const
Return the object&#39;s default conversation (DLG).
Definition: object.cpp:102
const Common::UString & getName() const
Return the object&#39;s name.
Definition: object.cpp:90
Context of an NWScript function.
void unimplementedFunction(Aurora::NWScript::FunctionContext &ctx)
Definition: functions.cpp:97
static NWN::Object * toObject(::Aurora::NWScript::Object *object)
void speakStringByStrRef(Aurora::NWScript::FunctionContext &ctx)
virtual void speakString(const Common::UString &string, uint32 volume)
Speak the specified string.
Definition: object.cpp:210
const Common::UString & getTag() const
Definition: object.h:49
The context needed to run a Neverwinter Nights module.
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:118
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Utility templates and functions.
static Creature * toPC(Aurora::NWScript::Object *object)
void isInConversation(Aurora::NWScript::FunctionContext &ctx)
Aurora::NWScript::Object * getPCSpeaker() const
Return the PC currently speaking with this object.
Definition: object.cpp:128
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void warning(const char *s,...)
Definition: util.cpp:33
An object in a Neverwinter Nights area.
void getLastSpeaker(Aurora::NWScript::FunctionContext &ctx)
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
A creature in a Neverwinter Nights area.
void getPCSpeaker(Aurora::NWScript::FunctionContext &ctx)
bool startConversation(const Common::UString &conv, Creature &pc, NWN::Object &obj, bool playHello=true)
Start a conversation.
Definition: module.cpp:683
void speakString(Aurora::NWScript::FunctionContext &ctx)
The context handling the gameplay in Neverwinter Nights.
void speakOneLinerConversation(Aurora::NWScript::FunctionContext &ctx)
void beginConversation(Aurora::NWScript::FunctionContext &ctx)
void getListenPatternNumber(Aurora::NWScript::FunctionContext &ctx)
Neverwinter Nights engine functions.
Module & getModule()
Return the module context.
Definition: game.cpp:70