#include "common/Ikari.h"
#include "common/Inventory.h"
#include "common/Item.h"
+#include "common/Script.h"
#include "common/Spell.h"
#include "common/Stats.h"
#include "geometry/Vector.h"
using common::Ikari;
using common::Inventory;
using common::Item;
+using common::Script;
using common::Spell;
using common::Stats;
using geometry::Vector;
map2.SetWidth(1);
map2.SetBattleBackground(bg);
- triggers1[0].map = &map2;
- triggers1[0].target = Vector<int>(6, 2);
-
- triggers2[0].map = &map1;
- triggers2[0].target = Vector<int>(8, 3);
+ unsigned char transition1text[4 + sizeof(int) + sizeof(Map *) + sizeof(Vector<int>)];
+ int i(0);
+ transition1text[i++] = Script::CODE_MOVE_I0;
+ *reinterpret_cast<int *>(transition1text + i) = 1;
+ i += sizeof(int);
+ transition1text[i++] = Script::CODE_MOVE_A0;
+ *reinterpret_cast<Map **>(transition1text + i) = &map2;
+ i += sizeof(Map *);
+ transition1text[i++] = Script::CODE_MOVE_V0;
+ *reinterpret_cast<Vector<int> *>(transition1text + i) = Vector<int>(6, 2);
+ i += sizeof(Vector<int>);
+ transition1text[i++] = Script::CODE_SYSCALL;
+
+ Script transition1;
+ transition1.text = transition1text;
+ transition1.textlen = sizeof(transition1text);
+
+ triggers1[0].SetScript(&transition1);
+
+ unsigned char transition2text[4 + sizeof(int) + sizeof(Map *) + sizeof(Vector<int>)];
+ i = 0;
+ transition2text[i++] = Script::CODE_MOVE_I0;
+ *reinterpret_cast<int *>(transition2text + i) = 1;
+ i += sizeof(int);
+ transition2text[i++] = Script::CODE_MOVE_A0;
+ *reinterpret_cast<Map **>(transition2text + i) = &map1;
+ i += sizeof(Map *);
+ transition2text[i++] = Script::CODE_MOVE_V0;
+ *reinterpret_cast<Vector<int> *>(transition2text + i) = Vector<int>(8, 3);
+ i += sizeof(Vector<int>);
+ transition2text[i++] = Script::CODE_SYSCALL;
+
+ Script transition2;
+ transition2.text = transition2text;
+ transition2.textlen = sizeof(transition2text);
+
+ triggers2[0].SetScript(&transition2);
gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
}
void MapState::RunTrigger(Trigger &trigger) {
- // TODO: run trigger script
- if (trigger.map) {
- ctrl->PushState(new ColorFade(this, 0, 500, true));
- ctrl->PushState(new TransitionState(this, trigger.map, trigger.target));
- ColorFade *fadeOut(new ColorFade(this, 0, 500, false));
- fadeOut->SetLeadOutTime(500);
- ctrl->PushState(fadeOut);
- }
+ if (!trigger.HasScript()) return;
+ runner.Run(*this, trigger.GetScript());
}
void MapState::UpdateFollower(Entity &e) {
return lhs->Position().Y() < rhs->Position().Y();
}
+
+void MapState::HandleSyscall(common::ScriptRunner &r) {
+ switch (r.Integer0()) {
+ case TRANSITION: {
+ ctrl->PushState(new ColorFade(this, 0, 500, true));
+ ctrl->PushState(new TransitionState(this, reinterpret_cast<Map *>(r.Address0()), r.Vector0()));
+ ColorFade *fadeOut(new ColorFade(this, 0, 500, false));
+ fadeOut->SetLeadOutTime(500);
+ ctrl->PushState(fadeOut);
+ break;
+ }
+ }
+}
+
}
#include "fwd.h"
#include "../app/State.h"
#include "../common/fwd.h"
+#include "../common/ScriptHost.h"
+#include "../common/ScriptRunner.h"
#include "../geometry/Vector.h"
#include "../graphics/Camera.h"
namespace map {
class MapState
-: public app::State {
+: public app::State
+, public common::ScriptHost {
public:
explicit MapState(common::GameConfig *, Map *);
void Transition(Map *, const geometry::Vector<int> &coordinates);
+ virtual void HandleSyscall(common::ScriptRunner &);
+
private:
static bool ZCompare(const Entity *lhs, const Entity *rhs);
bool CheckMoveTrigger();
void RunTrigger(Trigger &);
+ enum Syscalls {
+ TRANSITION = 1,
+ WARP = 2,
+ };
+
private:
common::GameConfig *game;
app::Application *ctrl;
Map *map;
Entity *controlled;
Entity *pushed;
+ common::ScriptRunner runner;
app::Timer<float> moveTimer;
geometry::Vector<int> lastLock;
graphics::Camera camera;
namespace map {
Trigger::Trigger()
-: type(TYPE_CONTACT)
-, map(0) {
+: script(0)
+, type(TYPE_CONTACT) {
}
#include "Entity.h"
#include "fwd.h"
+#include "../common/Script.h"
#include "../geometry/Vector.h"
namespace map {
public:
const geometry::Vector<int> &TilePosition() const { return tilePosition; }
Type GetType() const { return type; }
+ bool HasScript() const { return script; }
+ common::Script &GetScript() { return *script; }
+ const common::Script &GetScript() const { return *script; }
// temporary setters
public:
void SetTilePosition(const geometry::Vector<int> &p) { tilePosition = p; }
void SetType(Type t) { type = t; }
+ void SetScript(common::Script *s) { script = s; }
private:
+ common::Script *script;
geometry::Vector<int> tilePosition;
Type type;
-// temporary members until scripting is implemented
-public:
- Map *map;
- geometry::Vector<int> target;
-
};
}