Beispiel #1
0
Common::Error SaveManager::loadGame(const Common::String &saveName) {
	Common::File *saveFile = _engine->getSearchManager()->openFile(saveName);
	if (saveFile == NULL) {
		saveFile = new Common::File;
		if (!saveFile->open(saveName)) {
			delete saveFile;
			return Common::kPathDoesNotExist;
		}
	}

	// Read the header
	SaveGameHeader header;
	if (!readSaveGameHeader(saveFile, header)) {
		return Common::kUnknownError;
	}

	ScriptManager *scriptManager = _engine->getScriptManager();
	// Update the state table values
	scriptManager->deserialize(saveFile);

	delete saveFile;
	if (header.thumbnail)
		delete header.thumbnail;

	return Common::kNoError;
}
void ScriptController::createState()
{
	Engine* engine = GetEngine();	
	
	ScriptManager* scripts = engine->getScriptManager();
	state = scripts->createScriptInstance(script.Resolve());
}
//----------------------------------------------------------------------------
bool Object::RegistToScriptSystem()
{
	ScriptManager *sm = ScriptManager::GetSingletonPtr();
	if (!sm) return false;

	const std::string &rttiName = GetRttiType().GetName();
	const std::string spaceName = "PX2.";
	size_t nameLength = rttiName.size() - spaceName.length();
	std::string className = rttiName.substr(spaceName.length(), nameLength);

	if (!mUserScriptName.empty())
	{
		mScriptName = mUserScriptName;
	}
	else
	{
		mScriptName = className + "_ScriptID_"
			+ StringHelp::IntToString(sm->GetNextRegistObjectID());
	}

	PX2_SM.AddGlobalName(mScriptName, this);
	PX2_SM.SetUserTypePointer(mScriptName.c_str(), className.c_str(), this);

	return true;
}
Beispiel #4
0
Common::Error SaveManager::loadGame(uint slot) {
	// The games only support 20 slots
	//assert(slot <= 1 && slot <= 20);

	Common::SeekableReadStream *saveFile = getSlotFile(slot);
	if (saveFile == 0) {
		return Common::kPathDoesNotExist;
	}

	// Read the header
	SaveGameHeader header;
	if (!readSaveGameHeader(saveFile, header)) {
		return Common::kUnknownError;
	}

	ScriptManager *scriptManager = _engine->getScriptManager();
	// Update the state table values
	scriptManager->deserialize(saveFile);

	delete saveFile;
	if (header.thumbnail)
		delete header.thumbnail;

	return Common::kNoError;
}
Beispiel #5
0
void shouldRunChaiScript()
{
	ScriptManager scriptManager;
	scriptManager.engine().eval("print(\"hello world from chai\")");
	double d = scriptManager.engine().eval<double>("3 + 4.75;");

	cout << "Chai simple add (3 + 4.75): " << d << endl ;
}
Beispiel #6
0
static MainRenderer* getMainRenderer(lua_State* l)
{
	LuaBinder* binder = nullptr;
	lua_getallocf(l, reinterpret_cast<void**>(&binder));

	ScriptManager* scriptManager = reinterpret_cast<ScriptManager*>(binder->getParent());

	return &scriptManager->getMainRenderer();
}
Beispiel #7
0
bool PanTrackNode::process(uint32 deltaTimeInMillis) {
	ScriptManager * scriptManager = _engine->getScriptManager();
	ScriptingEffect *fx = scriptManager->getSideFX(_slot);
	if (fx && fx->getType() == SCRIPTING_EFFECT_AUDIO) {
		MusicNodeBASE *mus = (MusicNodeBASE *)fx;

		int curPos = scriptManager->getStateValue(StateKey_ViewPos);
		int16 _width = _engine->getRenderManager()->getBkgSize().x;
		int16 _halfWidth = _width / 2;
		int16 _quarterWidth = _width / 4;

		int tmp = 0;
		if (curPos <= _position)
			tmp = _position - curPos;
		else
			tmp = _position - curPos + _width;

		int balance = 0;

		if (tmp > _halfWidth)
			tmp -= _width;

		if (tmp > _quarterWidth) {
			balance = 1;
			tmp = _halfWidth - tmp;
		} else if (tmp < -_quarterWidth) {
			balance = -1;
			tmp = -_halfWidth - tmp;
		}

		// Originally it's value -90...90 but we use -127...127 and therefore 360 replaced by 508
		mus->setBalance( (508 * tmp) / _width );

		tmp = (360 * tmp) / _width;

		int deltaVol = balance;

		// This value sets how fast volume goes off than sound source back of you
		// By this value we can hack some "bugs" have place in originall game engine like beat sound in ZGI-dc10
		int volumeCorrection = 2;

		if (_engine->getGameId() == GID_GRANDINQUISITOR) {
			if (scriptManager->getCurrentLocation() == "dc10")
				volumeCorrection = 5;
		}

		if (deltaVol != 0)
			deltaVol = (mus->getVolume() * volumeCorrection) * (90 - tmp * balance) / 90;
		if (deltaVol > 255)
			deltaVol = 255;

		mus->setDeltaVolume(deltaVol);
	}
	return false;
}
Token *Scanner::scanSingleLineComment(LexContext *ctx)
{
	Token *ret = NULL;
	ScriptManager *smgr = ctx->smgr;
	TokenManager *tmgr = ctx->tmgr;
	if (ctx->existsBuffer()) tmgr->add(scanPrevSymbol(ctx, '#'));
	Token *prev_tk = ctx->tmgr->lastToken();
	TokenType::Type prev_type = (prev_tk) ?  prev_tk->info.type : TokenType::Undefined;
	if (isRegexStarted || prev_type == TokenType::RegExp || prev_type ==  TokenType::RegReplaceTo) {
		ctx->writeBuffer('#');
		ret = ctx->tmgr->new_Token(ctx->buffer(), ctx->finfo);
		ret->info = tmgr->getTokenInfo(TokenType::RegDelim);
		ctx->clearBuffer();
	} else {
		if (verbose) {
			for (; smgr->currentChar() != '\n' && !smgr->end(); smgr->next()) {
				ctx->writeBuffer(smgr->currentChar());
			}
			Token *tk = tmgr->new_Token(ctx->buffer(), ctx->finfo);
			tk->info = tmgr->getTokenInfo(TokenType::Comment);
			ctx->clearBuffer();
			tmgr->add(tk);
		} else {
			for (; smgr->currentChar() != '\n' && !smgr->end(); smgr->next()) {}
		}
		tmgr->add(scanWhiteSpace(ctx));
		ctx->finfo.start_line_num++;
	}
	return ret;
}
Beispiel #9
0
void Hill::receiveEvent(Event* event) {
    using namespace boost::python;
    ScriptManager* sm = ScriptManager::getInstance();
    if (event->getEventType() == ETYPE_IN_RADIUS) {
        GameObjectArrivesInRadius* new_event = static_cast<GameObjectArrivesInRadius*>(event);
        sm->registerGameObject("ant", new_event->getObjectInRadius());
        sm->registerGameObject("self", new_event->getCenterObject());
        sm->startScript("ant_arrives_in_radius_of_hill");
    } else if (event->getEventType() == ETYPE_LEAVES_RADIUS) {
      // sm->startScript("ant_leaves_from_radius");
    } else {
        std::cout << "GameObject received unspecified event" << std::endl;
    }
}
Beispiel #10
0
int ScriptManager::luaUnregisterSubst(lua_State *state) {
	assert(state);

	Aurora::Lua::Stack stack(*state);
	assert(stack.getSize() == 2);

	ScriptManager* scriptMan = stack.getUserTypeAt<ScriptManager>(1);
	assert(scriptMan == &LuaScriptMan);
	void* object = stack.getRawUserTypeAt(2);
	assert(object);

	scriptMan->unsetLuaInstanceForObject(object);
	return 0;
}
Token *Scanner::scanSymbol(LexContext *ctx)
{
	Token *ret = NULL;
	ScriptManager *smgr = ctx->smgr;
	char symbol = smgr->currentChar();
	char next_ch = smgr->nextChar();
	char after_next_ch = smgr->afterNextChar();
	if (ctx->existsBuffer()) ctx->tmgr->add(scanPrevSymbol(ctx, symbol));
	if (!isRegexStarted) {
		ret = scanTripleCharacterOperator(ctx, symbol, next_ch, after_next_ch);
		if (!ret) ret = scanDoubleCharacterOperator(ctx, symbol, next_ch);
	}
	if (!ret) ret = scanCurSymbol(ctx, symbol);
	return ret;
}
Beispiel #12
0
void DryonBot::onBotJoined(const string &channel, const vector<string> &userlist)
{
	chan_Info *ch;
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onBotJoined", "cv", ch, &userlist);
}
void GameObject::AttachScript( const tstring_symbol& behaviorName )
{
	ScriptManager* scriptManager = ScriptManager::GetInstance();

	ScriptClassObject* classObject = scriptManager->GetClassObject( behaviorName );
	if( classObject == NULL )
	{
		return;
	}

	ScriptBehavior* behavior = classObject->CreateBehavior();

	behavior->Awake();

	m_scriptBehaviors.push_back( behavior );
}
Token *Scanner::scanWhiteSpace(LexContext *ctx)
{
	TokenManager *tmgr = ctx->tmgr;
	Token *prev_tk = tmgr->lastToken();
	TokenType::Type prev_type = (prev_tk) ? prev_tk->info.type : TokenType::Undefined;

	if (prev_type == TokenType::Comment || prev_type == TokenType::Pod) {
		// Add WhiteSpace token (data: '\n') for Comment or Pod token
		// Because the newline character is not on the trailing of those tokens
		ctx->writeBuffer('\n');
		ctx->finfo.start_line_num = prev_tk->finfo.start_line_num;
	} else {
		bool does_ws_continue = false;
		ScriptManager *smgr = ctx->smgr;
		for (; !smgr->end(); smgr->next()) {
			char ch = smgr->currentChar();
			if (ch == ' ' || ch == '\t') {
				// For normal whitespace.
				// It collects into one token when a whitespace continues.
				ctx->writeBuffer(ch);
				does_ws_continue = true;
				continue;
			} else if (!does_ws_continue && ch == '\n') {
				// For newline character.
				// It should be on the same line to before token.
				ctx->writeBuffer(ch);
				if (verbose && prev_type != TokenType::HereDocumentEnd) {
					ctx->finfo.start_line_num = prev_tk->finfo.start_line_num;
				}
				break;
			}
			smgr->back();
			break;
		}
	}

	if (!verbose) {
		ctx->clearBuffer();
		return NULL;
	}

	Token *token = tmgr->new_Token(ctx->buffer(), ctx->finfo);
	token->info = tmgr->getTokenInfo(TokenType::WhiteSpace);
	ctx->clearBuffer();
	return token;
}
Beispiel #15
0
void DryonBot::onQuit(const string &nick, const string &msg)
{
	user_Info *u;
	GET_USR(u, nick);

	PMgr.callEvent("event_onQuit", "u", u);
	destroyUserData(nick);
}
Beispiel #16
0
void DryonBot::onCTCPAction(const string &action, const string &user, const string &channel)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, user);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onAction", "usc", u, action.c_str(), ch);
}
Beispiel #17
0
void DryonBot::onChanModeChanged(const string &sender, const string &channel, const string &mode)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, sender);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onChanMode", "ucs", u, ch, mode.c_str());
}
Beispiel #18
0
void DryonBot::onChanKeySet(const string &channel, const string &sender, const string &key)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, sender);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onChanKeySet", "cus", ch, u, key.c_str());
}
Beispiel #19
0
void DryonBot::onChanKeyRemoved(const string &channel, const string &sender)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, sender);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onChanKeyRemoved", "cu", ch, u);
}
Beispiel #20
0
void DryonBot::onBotLostVoice(const string &channel, const string &sender)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, sender);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onBotDevoiced", "cu", ch, u);
}
Beispiel #21
0
void DryonBot::onUnBan(const string &channel, const string &sender, const string &banmask)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, sender);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onUnBan", "cus", ch, u, banmask.c_str());
}
Beispiel #22
0
void DryonBot::onServerRemoveVoice(const string &channel, const string &target)
{
	user_Info *t;
	chan_Info *ch;
	GET_USR(t, target);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onServerRemoveVoice", "cu", ch, t);
}
Beispiel #23
0
void DryonBot::onPart(const string &nick, const string &chan)
{
	chan_Info *ch;
	user_Info *u;
	GET_CHAN(ch, chan);
	GET_USR(u, nick);

	if( nick == getNick() )
	{
		clearBotChanFlags(chan);
		PMgr.callEvent("event_onBotPart", "c", ch);
	}
	else
	{
		clearChanFlags(nick, chan);
		PMgr.callEvent("event_onPart", "uc", u, ch);
	}
}
Beispiel #24
0
void DryonBot::onLostVoice(const string &channel, const string &sender, const string &target)
{
	user_Info *u, *t;
	chan_Info *ch;
	GET_USR(u, sender);
	GET_USR(t, target);
	GET_CHAN(ch, channel);

	PMgr.callEvent("event_onDeVoice", "cuu", ch, u, t);
}
Beispiel #25
0
void DryonBot::onJoin(const string &nick, const string &chan)
{
	user_Info *u;
	chan_Info *ch;

	GET_USR(u, nick);
	GET_CHAN(ch, chan);

	checkUserFlags(u, chan);
	PMgr.callEvent("event_onJoin", "uc", u, ch);
}
Beispiel #26
0
void DryonBot::onKick(const string &kicker, const string &chan, const string &kicked, const string &msg)
{
	user_Info *u1;
	user_Info *u2;
	chan_Info *ch;
	GET_USR(u1, kicker);
	GET_USR(u2, kicked);
	GET_CHAN(ch, chan);

	if( kicked == getNick() )
	{
		clearBotChanFlags(chan);
		PMgr.callEvent("event_onBotKicked", "ucs", u1, ch, msg.c_str());
	}
	else
	{
		clearChanFlags(kicked, chan);
		PMgr.callEvent("event_onKick", "ucus", u1, ch, u2, msg.c_str());
	}
}
Beispiel #27
0
void DryonBot::onTopicChange(const string &nick, const string &chan, const string &new_topic)
{
	user_Info *u;
	chan_Info *ch;
	GET_USR(u, nick);
	GET_CHAN(ch, chan);

	string oldtopic= ch->topic;
	ch->topic= new_topic;
	PMgr.callEvent("event_onTopicChange", "ucss", u, ch, oldtopic.c_str(), new_topic.c_str());
}
void YuiRegisterScripts(ScriptManager & scriptmanager)
{
   std::unique_ptr<ScriptRegistrator> registrator(scriptmanager.getRegistrator());

   registrator->addClass(UTEXT("ui.Yui"));
   registrator->addFunction(UTEXT("load(String)"), yui_load);

   registrator->addClass(UTEXT("ui.YuiWindow"));

   registrator->registerCallbacks();
}
Beispiel #29
0
void DryonBot::onNickChange(const string &oldnick, const string &newnick)
{
	user_Info *usr;
	GET_USR(usr, oldnick);

	createUserData(newnick, usr);
	destroyUserData(oldnick);

	GET_USR(usr, newnick);

	PMgr.callEvent("event_onNickChange", "su", oldnick.c_str(), usr);
}
Beispiel #30
0
Common::Error SaveManager::loadGame(int slot) {
	Common::SeekableReadStream *saveFile = NULL;

	if (slot >= 0) {
		saveFile = getSlotFile(slot);
	} else {
		saveFile = _engine->getSearchManager()->openFile("r.svr");
		if (!saveFile) {
			Common::File *restoreFile = new Common::File();
			if (!restoreFile->open("r.svr")) {
				delete restoreFile;
				return Common::kPathDoesNotExist;
			}

			saveFile = restoreFile;
		}
	}

	if (!saveFile)
		return Common::kPathDoesNotExist;

	// Read the header
	SaveGameHeader header;
	if (!readSaveGameHeader(saveFile, header)) {
		return Common::kUnknownError;
	}

	ScriptManager *scriptManager = _engine->getScriptManager();
	// Update the state table values
	scriptManager->deserialize(saveFile);

	delete saveFile;
	if (header.thumbnail)
		delete header.thumbnail;

	if (_engine->getGameId() == GID_NEMESIS && scriptManager->getCurrentLocation() == "tv2f") {
		// WORKAROUND for script bug #6793: location tv2f (stairs) has two states:
		// one at the top of the stairs, and one at the bottom. When the player
		// goes to the bottom of the stairs, the screen changes, and hotspot
		// 4652 (exit opposite the stairs) is enabled. However, the variable that
		// controls the state (2408) is reset when the player goes down the stairs.
		// Furthermore, the room's initialization script disables the stair exit
		// control (4652). This leads to an impossible situation, where all the
		// exit controls are disabled, and the player can't more anywhere. Thus,
		// when loading a game in that room, we check for that impossible
		// situation, which only occurs after the player has moved down the stairs,
		// and fix it here by setting the correct background, and enabling the
		// stair exit hotspot.
		if ((scriptManager->getStateFlag(2411) & Puzzle::DISABLED) &&
			(scriptManager->getStateFlag(2408) & Puzzle::DISABLED) &&
			(scriptManager->getStateFlag(4652) & Puzzle::DISABLED)) {
			_engine->getRenderManager()->setBackgroundImage("tv2fb21c.tga");
			scriptManager->unsetStateFlag(4652, Puzzle::DISABLED);
		}
	}

	return Common::kNoError;
}