Skip to content

Commit

Permalink
KOTOR: Add support for scripted events
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii committed Jun 24, 2018
1 parent 379411e commit a0c1526
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 4 deletions.
56 changes: 56 additions & 0 deletions src/engines/kotor/script/event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Star Wars: Knights of the Old Republic event engine type.
*/

#include "src/engines/kotor/script/event.h"

namespace Engines {

namespace KotOR {

Event::Event(EventType type)
: _type(type),
_userDefinedNumber(0) {
}

void Event::setUserDefinedNumber(int number) {
_userDefinedNumber = number;
}

EventType Event::getType() const {
return _type;
}

int Event::getUserDefinedNumber() const {
return _userDefinedNumber;
}

Aurora::NWScript::EngineType *Event::clone() const {
Event *e = new Event(_type);
e->_userDefinedNumber = _userDefinedNumber;
return e;
}

} // End of namespace KotOR

} // End of namespace Engines
58 changes: 58 additions & 0 deletions src/engines/kotor/script/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Star Wars: Knights of the Old Republic event engine type.
*/

#ifndef ENGINES_KOTOR_SCRIPT_EVENT_H
#define ENGINES_KOTOR_SCRIPT_EVENT_H

#include "src/aurora/nwscript/enginetype.h"

namespace Engines {

namespace KotOR {

enum EventType {
kEventUserDefined = 0
};

class Event : public Aurora::NWScript::EngineType {
public:
Event(EventType type);

void setUserDefinedNumber(int number);

EventType getType() const;
int getUserDefinedNumber() const;

Aurora::NWScript::EngineType *clone() const;

private:
EventType _type;
int _userDefinedNumber;
};

} // End of namespace KotOR

} // End of namespace Engines

#endif // ENGINES_KOTOR_SCRIPT_EVENT_H
6 changes: 3 additions & 3 deletions src/engines/kotor/script/function_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ const Functions::FunctionPointer Functions::kFunctionPointers[] = {
{ 128, "GetFirstObjectInShape" , 0 },
{ 129, "GetNextObjectInShape" , 0 },
{ 130, "EffectEntangle" , 0 },
{ 131, "SignalEvent" , 0 },
{ 132, "EventUserDefined" , 0 },
{ 131, "SignalEvent" , &Functions::signalEvent },
{ 132, "EventUserDefined" , &Functions::eventUserDefined },
{ 133, "EffectDeath" , 0 },
{ 134, "EffectKnockdown" , 0 },
{ 135, "ActionGiveItem" , 0 },
Expand Down Expand Up @@ -365,7 +365,7 @@ const Functions::FunctionPointer Functions::kFunctionPointers[] = {
{ 244, "EventSpellCastAt" , 0 },
{ 245, "GetLastSpellCaster" , 0 },
{ 246, "GetLastSpell" , 0 },
{ 247, "GetUserDefinedEventNumber" , 0 },
{ 247, "GetUserDefinedEventNumber" , &Functions::getUserDefinedEventNumber },
{ 248, "GetSpellId" , 0 },
{ 249, "RandomName" , 0 },
{ 250, "EffectPoison" , 0 },
Expand Down
4 changes: 3 additions & 1 deletion src/engines/kotor/script/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ namespace Engines {

namespace KotOR {

Functions::Functions(Game &game) : _game(&game) {
Functions::Functions(Game &game)
: _game(&game),
_lastEvent(0) {
registerFunctions();
}

Expand Down
8 changes: 8 additions & 0 deletions src/engines/kotor/script/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace KotOR {
class Game;
class Area;
class Object;
class Event;

class Functions {
public:
Expand Down Expand Up @@ -73,6 +74,7 @@ class Functions {


Game *_game;
Event *_lastEvent;

void registerFunctions();

Expand Down Expand Up @@ -256,6 +258,12 @@ class Functions {
// .--- Party, functions_party.cpp
void isObjectPartyMember(Aurora::NWScript::FunctionContext &ctx);
// '---

// .--- Events, functions_events.cpp
void signalEvent(Aurora::NWScript::FunctionContext &ctx);
void eventUserDefined(Aurora::NWScript::FunctionContext &ctx);
void getUserDefinedEventNumber(Aurora::NWScript::FunctionContext &ctx);
// '---
};

} // End of namespace KotOR
Expand Down
68 changes: 68 additions & 0 deletions src/engines/kotor/script/functions_events.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Star Wars: Knights of the Old Republic engine functions for handling events.
*/

#include "src/aurora/nwscript/functioncontext.h"

#include "src/engines/kotor/objectcontainer.h"
#include "src/engines/kotor/game.h"
#include "src/engines/kotor/module.h"

#include "src/engines/kotor/script/functions.h"
#include "src/engines/kotor/script/event.h"

namespace Engines {

namespace KotOR {

void Functions::signalEvent(Aurora::NWScript::FunctionContext &ctx) {
Engines::KotOR::Object *object = ObjectContainer::toObject(ctx.getParams()[0].getObject());
if (!object)
object = _game->getModule().getPC();

Event *e = static_cast<Event *>(ctx.getParams()[1].getEngineType());
if (!e)
throw Common::Exception("Functions::signalEvent(): Invalid event");

switch (e->getType()) {
case kEventUserDefined:
_lastEvent = e;
object->runScript(kScriptUserdefined, object);
break;
}
}

void Functions::eventUserDefined(Aurora::NWScript::FunctionContext &ctx) {
Event e(kEventUserDefined);
e.setUserDefinedNumber(ctx.getParams()[0].getInt());
ctx.getReturn() = e;
}

void Functions::getUserDefinedEventNumber(Aurora::NWScript::FunctionContext &ctx) {
if (_lastEvent && _lastEvent->getType() == kEventUserDefined)
ctx.getReturn() = _lastEvent->getUserDefinedNumber();
}

} // End of namespace KotOR

} // End of namespace Engines
3 changes: 3 additions & 0 deletions src/engines/kotor/script/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ src_engines_kotor_libkotor_la_SOURCES += \
src/engines/kotor/script/container.h \
src/engines/kotor/script/functions.h \
src/engines/kotor/script/function_tables.h \
src/engines/kotor/script/event.h \
$(EMPTY)

src_engines_kotor_libkotor_la_SOURCES += \
Expand All @@ -40,4 +41,6 @@ src_engines_kotor_libkotor_la_SOURCES += \
src/engines/kotor/script/functions_global.cpp \
src/engines/kotor/script/functions_local.cpp \
src/engines/kotor/script/functions_party.cpp \
src/engines/kotor/script/functions_events.cpp \
src/engines/kotor/script/event.cpp \
$(EMPTY)

0 comments on commit a0c1526

Please sign in to comment.