xoreos  0.0.5
functions_event.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 #include "src/common/error.h"
27 
31 
34 
37 
38 namespace Engines {
39 
40 namespace DragonAge2 {
41 
43  ctx.getReturn() = (const Aurora::NWScript::EngineType *) 0;
44 
46  if (!env || !env->hasVariable("Event"))
47  return;
48 
49  ctx.getReturn() = env->getVariable("Event");
50 }
51 
54 
56  if (!env || !env->hasVariable("Event"))
57  return;
58 
60  if (!event)
61  return;
62 
63  ctx.getReturn() = (int32) event->getType();
64 }
65 
67  const Event *event = DragonAge2::ObjectContainer::toEvent(ctx.getParams()[0].getEngineType());
68 
69  ctx.getReturn() = event && (event->getType() != kEventTypeInvalid);
70 }
71 
74 
75  const Event *event = DragonAge2::ObjectContainer::toEvent(ctx.getParams()[0].getEngineType());
76  if (!event)
77  return;
78 
79  ctx.getReturn() = (int32) event->getType();
80 }
81 
83  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
84 
85  const Event *event = DragonAge2::ObjectContainer::toEvent(ctx.getParams()[0].getEngineType());
86  if (!event)
87  return;
88 
89  ctx.getReturn() = event->getCreator();
90 }
91 
93  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
94 
95  const Event *event = DragonAge2::ObjectContainer::toEvent(ctx.getParams()[0].getEngineType());
96  if (!event)
97  return;
98 
99  ctx.getReturn() = event->getTarget();
100 }
101 
103  ctx.getReturn() = ctx.getParams()[0].getEngineType();
104 
106  if (!event)
107  return;
108 
109  event->setType((EventType) ctx.getParams()[1].getInt());
110 }
111 
113  ctx.getReturn() = ctx.getParams()[0].getEngineType();
114 
116  if (!event)
117  return;
118 
119  event->setCreator(ctx.getParams()[1].getObject());
120 }
121 
124 
125  const Aurora::NWScript::Variable *variable = ctx.getParams()[0].getReference();
126  if (!variable)
127  return;
128 
129  const Event *event = DragonAge2::ObjectContainer::toEvent(variable->getEngineType());
130  if (!event)
131  return;
132 
133  ctx.getReturn() = (int32) event->getType();
134 }
135 
137  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
138 
139  const Aurora::NWScript::Variable *variable = ctx.getParams()[0].getReference();
140  if (!variable)
141  return;
142 
143  const Event *event = DragonAge2::ObjectContainer::toEvent(variable->getEngineType());
144  if (!event)
145  return;
146 
147  ctx.getReturn() = event->getCreator();
148 }
149 
151  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
152 
153  const Aurora::NWScript::Variable *variable = ctx.getParams()[0].getReference();
154  if (!variable)
155  return;
156 
157  const Event *event = DragonAge2::ObjectContainer::toEvent(variable->getEngineType());
158  if (!event)
159  return;
160 
161  ctx.getReturn() = event->getCreator();
162 }
163 
165  Aurora::NWScript::Variable *variable = ctx.getParams()[0].getReference();
166  if (!variable)
167  return;
168 
170  if (!event)
171  return;
172 
173  event->setType((EventType) ctx.getParams()[1].getInt());
174 }
175 
177  Aurora::NWScript::Variable *variable = ctx.getParams()[0].getReference();
178  if (!variable)
179  return;
180 
182  if (!event)
183  return;
184 
185  event->setCreator(ctx.getParams()[1].getObject());
186 }
187 
189  Event invalidEvent;
190 
191  Event *event = DragonAge2::ObjectContainer::toEvent(ctx.getParams()[0].getEngineType());
192  if (!event)
193  event = &invalidEvent;
194 
195  // TODO: According to the Dragon Age wiki, "The maximum level of event rerouteing is 8".
196 
197  DragonAge2::ScriptContainer::runScript(ctx.getParams()[1].getString(), *event);
198 }
199 
201  Aurora::NWScript::Variable *variable = ctx.getParams()[0].getReference();
202  if (!variable)
203  throw Common::Exception("Functions::handleEventRef(): Empty reference");
204 
206  if (!event)
207  throw Common::Exception("Functions::handleEventRef(): Reference is not an event");
208 
209  // TODO: Maximum level of event rerouteing?
210 
211  DragonAge2::ScriptContainer::runScript(ctx.getParams()[1].getString(), *event);
212 }
213 
214 } // End of namespace DragonAge2
215 
216 } // End of namespace Engines
void getCurrentEvent(Aurora::NWScript::FunctionContext &ctx)
void getEventTypeRef(Aurora::NWScript::FunctionContext &ctx)
void setType(EventType type)
Definition: event.cpp:50
void isEventValid(Aurora::NWScript::FunctionContext &ctx)
A container of Dragon Age II objects.
Context of an NWScript function.
An object containing scripts.
bool hasVariable(const Common::UString &var) const
bool runScript(EventType event, const Aurora::NWScript::ObjectReference owner=Aurora::NWScript::ObjectReference(), const Aurora::NWScript::ObjectReference triggerer=Aurora::NWScript::ObjectReference())
Definition: container.cpp:100
An NWScript engine type.
Basic exceptions to throw.
EngineType * getEngineType() const
Definition: variable.cpp:328
void getEventCreator(Aurora::NWScript::FunctionContext &ctx)
Utility templates and functions.
static Event * toEvent(Aurora::NWScript::EngineType *engineType)
void getEventTargetRef(Aurora::NWScript::FunctionContext &ctx)
void setEventCreator(Aurora::NWScript::FunctionContext &ctx)
Variable & getVariable(const Common::UString &var, Type type=kTypeVoid)
void handleEventRef(Aurora::NWScript::FunctionContext &ctx)
void getEventTarget(Aurora::NWScript::FunctionContext &ctx)
StackException Exception
Definition: error.h:59
VariableContainer * getCurrentEnvironment() const
An NWScript variable container.
void getEventType(Aurora::NWScript::FunctionContext &ctx)
A scripting event.
void setCreator(const Aurora::NWScript::ObjectReference &creator)
Definition: event.cpp:58
void getCurrentEventType(Aurora::NWScript::FunctionContext &ctx)
EventType
Types for script events.
Definition: types.h:114
Dragon Age II engine functions.
void handleEvent(Aurora::NWScript::FunctionContext &ctx)
void setEventTypeRef(Aurora::NWScript::FunctionContext &ctx)
void setEventCreatorRef(Aurora::NWScript::FunctionContext &ctx)
void setEventType(Aurora::NWScript::FunctionContext &ctx)
int32_t int32
Definition: types.h:203
void getEventCreatorRef(Aurora::NWScript::FunctionContext &ctx)