bool ScriptManager::LoadScript(QString path, QString name) {
    QFileInfo&& info = ResourceManager::Get()->FindFile(path);
    QFile file(info.absoluteFilePath());

    if(!file.exists())
        return false;

    // check if file is open or open it
    if(!(file.isOpen() || file.open(QIODevice::ReadOnly | QIODevice::Text))) {
        Logger::Get().Error("Cannot open file <" + path + ">: " + file.errorString());
        return false;
    }

    QTextStream stream(&file);
    QString script = stream.readAll();
    file.close();

    if(name == "") {
        name = info.fileName();
    }

    return AddScript(script, name);
}
Beispiel #2
0
bool
Job::AddPostScript( const char *cmd, MyString &whynot )
{
	return AddScript( true, cmd, whynot );
}
Beispiel #3
0
bool
Job::AddPreScript( const char *cmd, MyString &whynot )
{
	return AddScript( false, cmd, whynot );
}
Beispiel #4
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdRegion::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(REGION)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(ACTIVE)
	TOKEN_TABLE(ZOOM)
	TOKEN_TABLE(SCALE)
	TOKEN_TABLE(BLOCKED)
	TOKEN_TABLE(DECORATION)
	TOKEN_TABLE(POINT)
	TOKEN_TABLE(ALPHA_COLOR)
	TOKEN_TABLE(ALPHA)
	TOKEN_TABLE(EDITOR_SELECTED_POINT)
	TOKEN_TABLE(EDITOR_SELECTED)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(CAPTION)
	TOKEN_TABLE(PROPERTY)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_REGION) {
			Game->LOG(0, "'REGION' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int i;

	for (i = 0; i < m_Points.GetSize(); i++) delete m_Points[i];
	m_Points.RemoveAll();

	int ar = 255, ag = 255, ab = 255, alpha = 255;

	while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_CAPTION:
			SetCaption((char *)params);
			break;

		case TOKEN_ACTIVE:
			parser.ScanStr((char *)params, "%b", &m_Active);
			break;

		case TOKEN_BLOCKED:
			parser.ScanStr((char *)params, "%b", &m_Blocked);
			break;

		case TOKEN_DECORATION:
			parser.ScanStr((char *)params, "%b", &m_Decoration);
			break;

		case TOKEN_ZOOM:
		case TOKEN_SCALE: {
			int i;
			parser.ScanStr((char *)params, "%d", &i);
			m_Zoom = (float)i;
		}
		break;

		case TOKEN_POINT: {
			int x, y;
			parser.ScanStr((char *)params, "%d,%d", &x, &y);
			m_Points.Add(new CBPoint(x, y));
		}
		break;

		case TOKEN_ALPHA_COLOR:
			parser.ScanStr((char *)params, "%d,%d,%d", &ar, &ag, &ab);
			break;

		case TOKEN_ALPHA:
			parser.ScanStr((char *)params, "%d", &alpha);
			break;

		case TOKEN_EDITOR_SELECTED:
			parser.ScanStr((char *)params, "%b", &m_EditorSelected);
			break;

		case TOKEN_EDITOR_SELECTED_POINT:
			parser.ScanStr((char *)params, "%d", &m_EditorSelectedPoint);
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_PROPERTY:
			ParseProperty(params, false);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in REGION definition");
		return E_FAIL;
	}

	CreateRegion();

	m_Alpha = DRGBA(ar, ag, ab, alpha);

	return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////
HRESULT CBSprite::LoadBuffer(BYTE* Buffer, bool Complete, int LifeTime, TSpriteCacheType CacheType)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (CONTINUOUS)
		TOKEN_TABLE (SPRITE)
		TOKEN_TABLE (LOOPING)
		TOKEN_TABLE (FRAME)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (PRECISE)
		TOKEN_TABLE (EDITOR_MUTED)
		TOKEN_TABLE (STREAMED_KEEP_LOADED)
		TOKEN_TABLE (STREAMED)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (EDITOR_BG_FILE)
		TOKEN_TABLE (EDITOR_BG_OFFSET_X)
		TOKEN_TABLE (EDITOR_BG_OFFSET_Y)
		TOKEN_TABLE (EDITOR_BG_ALPHA)
		TOKEN_TABLE (EDITOR_PROPERTY)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	Cleanup();


	if(Complete)
	{
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_SPRITE)
		{
			Game->LOG(0, "'SPRITE' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int frame_count = 1;
	CBFrame* frame;
	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_CONTINUOUS:
				parser.ScanStr((char*)params, "%b", &m_Continuous);
			break;

			case TOKEN_EDITOR_MUTED:
				parser.ScanStr((char*)params, "%b", &m_EditorMuted);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_LOOPING:
				parser.ScanStr((char*)params, "%b", &m_Looping);
			break;

			case TOKEN_PRECISE:
				parser.ScanStr((char*)params, "%b", &m_Precise);
			break;

			case TOKEN_STREAMED:
				parser.ScanStr((char*)params, "%b", &m_Streamed);				
				if(m_Streamed && LifeTime==-1)
				{
					LifeTime = 500;
					CacheType = CACHE_ALL;
				}
			break;

			case TOKEN_STREAMED_KEEP_LOADED:
				parser.ScanStr((char*)params, "%b", &m_StreamedKeepLoaded);
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_EDITOR_BG_FILE:
				if(Game->m_EditorMode)
				{
					SAFE_DELETE_ARRAY(m_EditorBgFile);
					m_EditorBgFile = new char[strlen((char*)params)+1];
					if(m_EditorBgFile) strcpy(m_EditorBgFile, (char*)params);
				}
			break;

			case TOKEN_EDITOR_BG_OFFSET_X:
				parser.ScanStr((char*)params, "%d", &m_EditorBgOffsetX);
			break;

			case TOKEN_EDITOR_BG_OFFSET_Y:
				parser.ScanStr((char*)params, "%d", &m_EditorBgOffsetY);
			break;

			case TOKEN_EDITOR_BG_ALPHA:
				parser.ScanStr((char*)params, "%d", &m_EditorBgAlpha);
				m_EditorBgAlpha = min(m_EditorBgAlpha, 255);
				m_EditorBgAlpha = max(m_EditorBgAlpha, 0);
			break;

			case TOKEN_FRAME:
			{
				int FrameLifeTime = LifeTime;
				if(CacheType==CACHE_HALF && frame_count%2!=1) FrameLifeTime = -1;

				frame = new CBFrame(Game);

				if(FAILED(frame->LoadBuffer(params, FrameLifeTime, m_StreamedKeepLoaded)))
				{
					delete frame;
					Game->LOG(0, "Error parsing frame %d", frame_count);
					return E_FAIL;
				}

				m_Frames.Add(frame);
				frame_count++;
				if(m_CurrentFrame==-1) m_CurrentFrame = 0;
			}
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}

	if (cmd == PARSERR_TOKENNOTFOUND)
	{
		Game->LOG(0, "Syntax error in SPRITE definition");
		return E_FAIL;
	}
	m_CanBreak = !m_Continuous;

	return S_OK;
}
Beispiel #6
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIEdit::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(DISABLED)
	TOKEN_TABLE(VISIBLE)
	TOKEN_TABLE(BACK)
	TOKEN_TABLE(IMAGE)
	TOKEN_TABLE(FONT_SELECTED)
	TOKEN_TABLE(FONT)
	TOKEN_TABLE(TEXT)
	TOKEN_TABLE(X)
	TOKEN_TABLE(Y)
	TOKEN_TABLE(WIDTH)
	TOKEN_TABLE(HEIGHT)
	TOKEN_TABLE(CURSOR_BLINK_RATE)
	TOKEN_TABLE(CURSOR)
	TOKEN_TABLE(FRAME_WIDTH)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(PARENT_NOTIFY)
	TOKEN_TABLE(MAX_LENGTH)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE(EDIT)
	TOKEN_TABLE(CAPTION)
	TOKEN_TABLE_END

	byte *params;
	int cmd = 2;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_EDIT) {
			Game->LOG(0, "'EDIT' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_BACK:
			delete m_Back;
			m_Back = new CUITiledImage(Game);
			if (!m_Back || FAILED(m_Back->LoadFile((char *)params))) {
				delete m_Back;
				m_Back = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE:
			delete m_Image;
			m_Image = new CBSprite(Game);
			if (!m_Image || FAILED(m_Image->LoadFile((char *)params))) {
				delete m_Image;
				m_Image = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_FONT:
			if (m_Font) Game->m_FontStorage->RemoveFont(m_Font);
			m_Font = Game->m_FontStorage->AddFont((char *)params);
			if (!m_Font) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_SELECTED:
			if (m_FontSelected) Game->m_FontStorage->RemoveFont(m_FontSelected);
			m_FontSelected = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontSelected) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_TEXT:
			SetText((char *)params);
			Game->m_StringTable->Expand(&m_Text);
			break;

		case TOKEN_X:
			parser.ScanStr((char *)params, "%d", &m_PosX);
			break;

		case TOKEN_Y:
			parser.ScanStr((char *)params, "%d", &m_PosY);
			break;

		case TOKEN_WIDTH:
			parser.ScanStr((char *)params, "%d", &m_Width);
			break;

		case TOKEN_HEIGHT:
			parser.ScanStr((char *)params, "%d", &m_Height);
			break;

		case TOKEN_MAX_LENGTH:
			parser.ScanStr((char *)params, "%d", &m_MaxLength);
			break;

		case TOKEN_CAPTION:
			SetCaption((char *)params);
			break;

		case TOKEN_CURSOR:
			delete m_Cursor;
			m_Cursor = new CBSprite(Game);
			if (!m_Cursor || FAILED(m_Cursor->LoadFile((char *)params))) {
				delete m_Cursor;
				m_Cursor = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_CURSOR_BLINK_RATE:
			parser.ScanStr((char *)params, "%d", &m_CursorBlinkRate);
			break;

		case TOKEN_FRAME_WIDTH:
			parser.ScanStr((char *)params, "%d", &m_FrameWidth);
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_PARENT_NOTIFY:
			parser.ScanStr((char *)params, "%b", &m_ParentNotify);
			break;

		case TOKEN_DISABLED:
			parser.ScanStr((char *)params, "%b", &m_Disable);
			break;

		case TOKEN_VISIBLE:
			parser.ScanStr((char *)params, "%b", &m_Visible);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in EDIT definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading EDIT definition");
		return E_FAIL;
	}

	CorrectSize();

	return S_OK;
}
Beispiel #7
0
void CQuestManager::GotoSelectItemState(QuestState& qs)
{
    qs.suspend_state = SUSPEND_STATE_SELECT_ITEM;
    AddScript("[SELECT_ITEM]");
    SendScript();
}
//////////////////////////////////////////////////////////////////////////
// high level scripting interface
//////////////////////////////////////////////////////////////////////////
HRESULT CBScriptHolder::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name)
{
	//////////////////////////////////////////////////////////////////////////
	// DEBUG_CrashMe
	//////////////////////////////////////////////////////////////////////////
	if(strcmp(Name, "DEBUG_CrashMe")==0)
	{
		Stack->CorrectParams(0);
		BYTE* p = 0;
		*p = 10;
		Stack->PushNULL();

		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// ApplyEvent
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "ApplyEvent")==0)
	{
		Stack->CorrectParams(1);
		CScValue* val = Stack->Pop();
		HRESULT ret;
		ret = ApplyEvent(val->GetString());

		if(SUCCEEDED(ret)) Stack->PushBool(true);
		else Stack->PushBool(false);

		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// CanHandleEvent
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "CanHandleEvent")==0)
	{
		Stack->CorrectParams(1);
		Stack->PushBool(CanHandleEvent(Stack->Pop()->GetString()));

		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// CanHandleMethod
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "CanHandleMethod")==0)
	{
		Stack->CorrectParams(1);
		Stack->PushBool(CanHandleMethod(Stack->Pop()->GetString()));

		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// AttachScript
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "AttachScript")==0)
	{
		Stack->CorrectParams(1);
		Stack->PushBool(SUCCEEDED(AddScript(Stack->Pop()->GetString())));
		
		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// DetachScript
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "DetachScript")==0)
	{
		Stack->CorrectParams(2);
		char* Filename = Stack->Pop()->GetString();
		bool KillThreads = Stack->Pop()->GetBool(false);
		bool ret = false;
		for(int i=0; i<m_Scripts.GetSize(); i++)
		{
			if(CBPlatform::stricmp(m_Scripts[i]->m_Filename, Filename)==0)
			{
				m_Scripts[i]->Finish(KillThreads);
				ret = true;
				break;
			}
		}
		Stack->PushBool(ret);

		return S_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// IsScriptRunning
	//////////////////////////////////////////////////////////////////////////
	else if(strcmp(Name, "IsScriptRunning")==0)
	{
		Stack->CorrectParams(1);
		char* Filename = Stack->Pop()->GetString();
		bool ret = false;
		for(int i=0; i<m_Scripts.GetSize(); i++)
		{
			if(CBPlatform::stricmp(m_Scripts[i]->m_Filename, Filename)==0 && m_Scripts[i]->m_State!=SCRIPT_FINISHED && m_Scripts[i]->m_State!=SCRIPT_ERROR)
			{
				ret = true;
				break;
			}
		}
		Stack->PushBool(ret);

		return S_OK;
	}
	else return CBScriptable::ScCallMethod(Script, Stack, ThisStack, Name);
}
//-----------------------------------------------------------------------------------------------------------------------------------
void Lesson1RacetrackScreen::AddInitialScripts()
{
  PlayerCar* playerCar = GetPlayerCar();
  assert(playerCar);

  AddScript(new AddTextBoxScript(L"Welcome to Lesson 1!"));
  AddScript(new AddTextBoxScript(L"Here you will learn the basics\nof handling and driving your car."));
  AddScript(new AddTextBoxScript(L"Lets get started!"));
  AddScript(new AddTextBoxScript(L"Hold the 'W' key to accelerate."));
  AddScript(new CheckAccelerateScript(playerCar), GetLastAddedScript());
  AddScript(new AddTextBoxScript(L"Good!  Now try deccelerating\nby holding the 'S' key."));
  AddScript(new CheckDeccelerateScript(playerCar), GetLastAddedScript());
  AddScript(new AddTextBoxScript(L"Awesome!  Now try turning left and right\nby using the 'A' and 'D' keys."));
  AddScript(new CheckLeftAndRightTurnScript(playerCar));
  AddScript(new AddTextBoxScript(L"Great!"));
  AddScript(new AddTextBoxScript(L"That's it for this lesson.\nFeel free to carry on driving,\nor press 'Enter' to go to the next lesson."));
  AddScript(new TransitionOnEnterScript(GetScreenManager(), RacetrackScreenFactory::CreateRacetrack(GetScreenManager(), "Lesson2RacetrackScreen.xml")));
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdLayer::LoadBuffer(BYTE * Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (LAYER)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (WIDTH)
		TOKEN_TABLE (HEIGHT)
		TOKEN_TABLE (MAIN)
		TOKEN_TABLE (ENTITY)
		TOKEN_TABLE (REGION)
		TOKEN_TABLE (ACTIVE)
		TOKEN_TABLE (EDITOR_SELECTED)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (CLOSE_UP)
		TOKEN_TABLE (EDITOR_PROPERTY)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	if(Complete){
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_LAYER){
			Game->LOG(0, "'LAYER' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_MAIN:
				parser.ScanStr((char*)params, "%b", &m_Main);
			break;

			case TOKEN_CLOSE_UP:
				parser.ScanStr((char*)params, "%b", &m_CloseUp);
			break;

			case TOKEN_WIDTH:
				parser.ScanStr((char*)params, "%d", &m_Width);
			break;

			case TOKEN_HEIGHT:
				parser.ScanStr((char*)params, "%d", &m_Height);
			break;

			case TOKEN_ACTIVE:
				parser.ScanStr((char*)params, "%b", &m_Active);
			break;

			case TOKEN_REGION:
			{
				CAdRegion* region = new CAdRegion(Game);
				CAdSceneNode* node = new CAdSceneNode(Game);
				if(!region || !node || FAILED(region->LoadBuffer(params, false))){
					cmd = PARSERR_GENERIC;
					SAFE_DELETE(region);
					SAFE_DELETE(node);
				}
				else{
					node->SetRegion(region);
					m_Nodes.Add(node);
				}
			}
			break;

			case TOKEN_ENTITY:
			{
				CAdEntity* entity = new CAdEntity(Game);
				CAdSceneNode* node = new CAdSceneNode(Game);
				if(entity) entity->m_Zoomable = false; // scene entites default to NOT zoom
				if(!entity || !node || FAILED(entity->LoadBuffer(params, false))){
					cmd = PARSERR_GENERIC;
					SAFE_DELETE(entity);
					SAFE_DELETE(node);
				}
				else{					
					node->SetEntity(entity);
					m_Nodes.Add(node);
				}
			}
			break;

			case TOKEN_EDITOR_SELECTED:
				parser.ScanStr((char*)params, "%b", &m_EditorSelected);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND){
		Game->LOG(0, "Syntax error in LAYER definition");
		return E_FAIL;
	}

	return S_OK;
}
Beispiel #11
0
//-----------------------------------------------------------------------------------------------------------------------------------
void BaseScreen::AddScript(Script* script)
{
  AddScript(script, GetLastAddedScript());
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdActor::LoadBuffer(BYTE * Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (ACTOR)
		TOKEN_TABLE (X)
		TOKEN_TABLE (Y)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (SCALABLE)
		TOKEN_TABLE (REGISTRABLE)
		TOKEN_TABLE (INTERACTIVE)
		TOKEN_TABLE (SHADOWABLE)
		TOKEN_TABLE (COLORABLE)
		TOKEN_TABLE (ACTIVE)
		TOKEN_TABLE (WALK)
		TOKEN_TABLE (STAND)
		TOKEN_TABLE (TALK_SPECIAL)
		TOKEN_TABLE (TALK)
		TOKEN_TABLE (TURN_LEFT)
		TOKEN_TABLE (TURN_RIGHT)
		TOKEN_TABLE (EVENTS)
		TOKEN_TABLE (FONT)
		TOKEN_TABLE (CURSOR)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (SOUND_VOLUME)
		TOKEN_TABLE (SOUND_PANNING)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (BLOCKED_REGION)
		TOKEN_TABLE (WAYPOINTS)
		TOKEN_TABLE (IGNORE_ITEMS)
		TOKEN_TABLE (ROTABLE)
		TOKEN_TABLE (ROTATABLE)
		TOKEN_TABLE (ALPHA_COLOR)
		TOKEN_TABLE (SCALE)
		TOKEN_TABLE (RELATIVE_SCALE)
		TOKEN_TABLE (ALPHA)
		TOKEN_TABLE (EDITOR_PROPERTY)
		TOKEN_TABLE (ANIMATION)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	if(Complete)
	{
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_ACTOR)
		{
			Game->LOG(0, "'ACTOR' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	CAdGame* AdGame = (CAdGame*)Game;
	CAdSpriteSet* spr = NULL;
	int ar=0, ag=0, ab=0, alpha=0;
	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_X:
				parser.ScanStr((char*)params, "%d", &m_PosX);
			break;

			case TOKEN_Y:
				parser.ScanStr((char*)params, "%d", &m_PosY);
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_FONT:
				SetFont((char*)params);
			break;

			case TOKEN_SCALABLE:
				parser.ScanStr((char*)params, "%b", &m_Zoomable);
			break;

			case TOKEN_ROTABLE:
			case TOKEN_ROTATABLE:
				parser.ScanStr((char*)params, "%b", &m_Rotatable);
			break;

			case TOKEN_REGISTRABLE:
			case TOKEN_INTERACTIVE:
				parser.ScanStr((char*)params, "%b", &m_Registrable);
			break;

			case TOKEN_SHADOWABLE:
			case TOKEN_COLORABLE:
				parser.ScanStr((char*)params, "%b", &m_Shadowable);
			break;

			case TOKEN_ACTIVE:
				parser.ScanStr((char*)params, "%b", &m_Active);
			break;

			case TOKEN_WALK:
				SAFE_DELETE(m_WalkSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC;
				else m_WalkSprite = spr;
			break;

			case TOKEN_TALK:
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSprites.Add(spr);
			break;

			case TOKEN_TALK_SPECIAL:
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSpritesEx.Add(spr);
			break;

			case TOKEN_STAND:
				SAFE_DELETE(m_StandSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexStandLifeTime))) cmd = PARSERR_GENERIC;
				else m_StandSprite = spr;
			break;

			case TOKEN_TURN_LEFT:
				SAFE_DELETE(m_TurnLeftSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true))) cmd = PARSERR_GENERIC;
				else m_TurnLeftSprite = spr;
			break;

			case TOKEN_TURN_RIGHT:
				SAFE_DELETE(m_TurnRightSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true))) cmd = PARSERR_GENERIC;
				else m_TurnRightSprite = spr;
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_CURSOR:
				SAFE_DELETE(m_Cursor);
				m_Cursor = new CBSprite(Game);
				if(!m_Cursor || FAILED(m_Cursor->LoadFile((char*)params)))
				{
					SAFE_DELETE(m_Cursor);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_SOUND_VOLUME:
				parser.ScanStr((char*)params, "%d", &m_SFXVolume);
			break;

			case TOKEN_SCALE:
			{
				int s;
				parser.ScanStr((char*)params, "%d", &s);
				m_Scale = (float)s;

			}
			break;

			case TOKEN_RELATIVE_SCALE:
			{
				int s;
				parser.ScanStr((char*)params, "%d", &s);
				m_RelativeScale = (float)s;

			}
			break;

			case TOKEN_SOUND_PANNING:
				parser.ScanStr((char*)params, "%b", &m_AutoSoundPanning);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_BLOCKED_REGION:
			{
				SAFE_DELETE(m_BlockRegion);
				SAFE_DELETE(m_CurrentBlockRegion);
				CBRegion* rgn = new CBRegion(Game);
				CBRegion* crgn = new CBRegion(Game);
				if(!rgn || !crgn || FAILED(rgn->LoadBuffer(params, false)))
				{
					SAFE_DELETE(m_BlockRegion);
					SAFE_DELETE(m_CurrentBlockRegion);
					cmd = PARSERR_GENERIC;
				}
				else{
					m_BlockRegion = rgn;
					m_CurrentBlockRegion = crgn;
					m_CurrentBlockRegion->Mimic(m_BlockRegion);
				}
			}
			break;

			case TOKEN_WAYPOINTS:
			{
				SAFE_DELETE(m_WptGroup);
				SAFE_DELETE(m_CurrentWptGroup);
				CAdWaypointGroup* wpt = new CAdWaypointGroup(Game);
				CAdWaypointGroup* cwpt = new CAdWaypointGroup(Game);
				if(!wpt || !cwpt || FAILED(wpt->LoadBuffer(params, false)))
				{
					SAFE_DELETE(m_WptGroup);
					SAFE_DELETE(m_CurrentWptGroup);
					cmd = PARSERR_GENERIC;
				}
				else{
					m_WptGroup = wpt;
					m_CurrentWptGroup = cwpt;
					m_CurrentWptGroup->Mimic(m_WptGroup);
				}
			}
			break;

			case TOKEN_IGNORE_ITEMS:
				parser.ScanStr((char*)params, "%b", &m_IgnoreItems);
			break;

			case TOKEN_ALPHA_COLOR:
				parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
			break;

			case TOKEN_ALPHA:
				parser.ScanStr((char*)params, "%d", &alpha);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;

			case TOKEN_ANIMATION:
			{
				CAdSpriteSet* Anim = new CAdSpriteSet(Game, this);
				if(!Anim || FAILED(Anim->LoadBuffer(params, false))) cmd = PARSERR_GENERIC;
				else m_Anims.Add(Anim);
			}
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND)
	{
		Game->LOG(0, "Syntax error in ACTOR definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC)
	{
		if(spr) delete spr;
		Game->LOG(0, "Error loading ACTOR definition");
		return E_FAIL;
	}
	
	if(alpha != 0 && ar==0 && ag == 0 && ab == 0)
	{
		ar = ag = ab = 255;
	}
	m_AlphaColor = DRGBA(ar, ag, ab, alpha);
	m_State = m_NextState = STATE_READY;

	return S_OK;
}
Beispiel #13
0
int dlgRepCluster::Go(bool modal)
{
	chkJoinCluster->SetValue(false);

	if (cluster)
	{
		// edit mode
		txtClusterName->SetValue(cluster->GetName());
		txtNodeID->SetValue(NumToStr(cluster->GetLocalNodeID()));
		txtClusterName->Disable();
		txtNodeID->Disable();
		txtNodeName->SetValue(cluster->GetLocalNodeName());
		txtNodeName->Disable();
		chkJoinCluster->Disable();

		txtAdminNodeID->Hide();
		txtAdminNodeName->Hide();

		wxString sql =
		    wxT("SELECT no_id, no_comment\n")
		    wxT("  FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n")
		    wxT("  JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_path ON no_id = pa_client\n")
		    wxT(" WHERE pa_server = ") + NumToStr(cluster->GetLocalNodeID()) +
		    wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%host=") + cluster->GetServer()->GetName() + wxT("%")) +
		    wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%dbname=") + cluster->GetDatabase()->GetName() + wxT("%"));

		if (cluster->GetServer()->GetPort() != 5432)
			sql += wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%port=") + NumToStr((long)cluster->GetServer()->GetPort()) + wxT("%"));

		sql += wxT(" ORDER BY no_id");

		pgSet *set = connection->ExecuteSet(sql);
		if (set)
		{
			while (!set->Eof())
			{
				long id = set->GetLong(wxT("no_id"));
				cbAdminNode->Append(IdAndName(id, set->GetVal(wxT("no_comment"))), (void *)id);
				if (id == cluster->GetAdminNodeID())
					cbAdminNode->SetSelection(cbAdminNode->GetCount() - 1);

				set->MoveNext();
			}
			delete set;
		}
		if (!cbAdminNode->GetCount())
		{
			cbAdminNode->Append(_("<none>"), (void *) - 1);
			cbAdminNode->SetSelection(0);
		}

		cbServer->Append(cluster->GetServer()->GetName());
		cbServer->SetSelection(0);
		cbDatabase->Append(cluster->GetDatabase()->GetName());
		cbDatabase->SetSelection(0);
		cbClusterName->Append(cluster->GetName());
		cbClusterName->SetSelection(0);
	}
	else
	{
		// create mode
		cbAdminNode->Hide();

		wxString scriptVersion = wxEmptyString;
		wxString xxidVersion = wxEmptyString;

		txtNodeID->SetValidator(numericValidator);
		txtAdminNodeID->SetValidator(numericValidator);
		txtClusterName->Hide();

		//We need to find the exact Slony Version.
		//NOTE: We are not supporting Slony versions less than 1.2.0

		wxString tempScript;
		AddScript(tempScript, wxT("slony1_funcs.sql"));

		if (tempScript.Contains(wxT("@MODULEVERSION@")) && slonyVersion.IsEmpty())
		{
			this->database->ExecuteVoid(wxT("CREATE OR REPLACE FUNCTION pgadmin_slony_version() returns text as '$libdir/slony1_funcs', '_Slony_I_getModuleVersion' LANGUAGE C"));
			slonyVersion = this->database->ExecuteScalar(wxT("SELECT pgadmin_slony_version();"));
			this->database->ExecuteVoid(wxT("DROP FUNCTION pgadmin_slony_version()"));

			if (slonyVersion.IsEmpty())
			{
				wxLogError(_("Couldn't test for the Slony version. Assuming 1.2.0"));
				slonyVersion = wxT("1.2.0");
			}
		}

		//Here we are finding the exact slony scripts version, which is based on Slony Version and PG Version.
		// For Slony 1.2.0 to 1.2.17 and 2.0.0 if PG 7.3 script version is v73
		// For Slony 1.2.0 to 1.2.17 and 2.0.0 if PG 7.4 script version is v74
		// For Slony 1.2.0 to 1.2.6 if PG 8.0+ script version is v80
		// For Slony 1.2.7 to 1.2.17 and 2.0.0 if PG 8.0 script version is v80
		// For Slony 1.2.7 to 1.2.17 and 2.0.0 if PG 8.1+ script version is v81
		// For Slony 2.0.1 and 2.0.2 if PG 8.3+ script version is v83. (These version onwards do not support PG Version less than 8.3)
		// For Slony 2.0.3 if PG 8.3 script version is v83.
		// For Slony 2.0.3 if PG 8.4+ script version is v84.

		//Since both 1.2 and 2.0 series is increasing, the following code needs to be updated with each Slony or PG update.


		if (!tempScript.IsEmpty())
		{
			//Set the slony_base and slony_funcs script version.
			if (SlonyMaximumVersion(wxT("1.2"), 6))
			{
				if (connection->BackendMinimumVersion(8, 0))
					scriptVersion = wxT("v80");
				else
				{
					if (connection->BackendMinimumVersion(7, 4))
						scriptVersion = wxT("v74");
					else
						scriptVersion = wxT("v73");
				}
			}
			else
			{
				if (SlonyMaximumVersion(wxT("1.2"), 17) || SlonyMaximumVersion(wxT("2.0"), 0))
				{
					if (connection->BackendMinimumVersion(8, 1))
						scriptVersion = wxT("v81");
					else
					{
						if (connection->BackendMinimumVersion(8, 0))
							scriptVersion = wxT("v80");
						else
						{
							if (connection->BackendMinimumVersion(7, 4))
								scriptVersion = wxT("v74");
							else
								scriptVersion = wxT("v73");
						}
					}
				}
				else
				{
					if (SlonyMaximumVersion(wxT("2.0"), 2))
						scriptVersion = wxT("v83");
					else
					{
						if (SlonyMaximumVersion(wxT("2.0"), 3))
						{
							if (connection->BackendMinimumVersion(8, 4))
								scriptVersion = wxT("v84");
						}
						else
							scriptVersion = wxT("v83");
					}
				}

			}

			//Set the correct xxid version if applicable
			// For Slony 1.2.0 to 1.2.17 and 2.0.0 if PG 7.3 xxid version is v73
			// For Slony 1.2.1 to 1.2.17 and 2.0.0 if PG 7.4+ xxid version is v74
			// For Slony 1.2.0 if PG 8.0 xxid version is v80
			// For Slony 2.0.1+ and PG8.4+ xxid is obsolete.

			if (SlonyMaximumVersion(wxT("1.2"), 0))
			{
				if (connection->BackendMinimumVersion(8, 0))
					xxidVersion = wxT("v80");
				else
				{
					if (connection->BackendMinimumVersion(7, 4))
						xxidVersion = wxT("v74");
					else
						xxidVersion = wxT("v73");
				}
			}
			else
			{
				if (SlonyMaximumVersion(wxT("1.2"), 17) || SlonyMaximumVersion(wxT("2.0"), 0))
				{
					if (!connection->BackendMinimumVersion(8, 4))
					{
						if (connection->BackendMinimumVersion(7, 4))
							xxidVersion = wxT("v74");
						else
							xxidVersion = wxT("v73");
					}
				}
			}


			wxString slonyBaseVersionFilename = wxT("slony1_base.") + scriptVersion + wxT(".sql");
			wxString slonyFuncsVersionFilename = wxT("slony1_funcs.") + scriptVersion + wxT(".sql");

			wxString xxidVersionFilename;

			if (!xxidVersion.IsEmpty())
				xxidVersionFilename = wxT("xxid.") + xxidVersion + wxT(".sql");

			if (((!xxidVersion.IsEmpty() && !AddScript(createScript, xxidVersionFilename)) ||
			        !AddScript(createScript, wxT("slony1_base.sql")) ||
			        !AddScript(createScript, slonyBaseVersionFilename) ||
			        !AddScript(createScript, wxT("slony1_funcs.sql")) ||
			        !AddScript(createScript, slonyFuncsVersionFilename)))
				createScript = wxEmptyString;

		}

		// Populate the server combo box
		ctlTree *browser = mainForm->GetBrowser();
		wxTreeItemIdValue foldercookie, servercookie;
		wxTreeItemId folderitem, serveritem;
		pgObject *object;
		pgServer *server;
		int sel = -1;

		folderitem = browser->GetFirstChild(browser->GetRootItem(), foldercookie);
		while (folderitem)
		{
			if (browser->ItemHasChildren(folderitem))
			{
				serveritem = browser->GetFirstChild(folderitem, servercookie);
				while (serveritem)
				{
					object = browser->GetObject(serveritem);
					if (object->IsCreatedBy(serverFactory))
					{
						server = (pgServer *)object;
						if (server == database->GetServer())
							sel = cbServer->GetCount();
						cbServer->Append(browser->GetItemText(server->GetId()), (void *)server);
					}
					serveritem = browser->GetNextChild(folderitem, servercookie);
				}
			}
			folderitem = browser->GetNextChild(browser->GetRootItem(), foldercookie);
		}

		if (sel >= 0)
			cbServer->SetSelection(sel);
	}

	wxCommandEvent ev;
	OnChangeJoin(ev);

	return dlgRepClusterBase::Go(modal);
}
Beispiel #14
0
clsScriptManager::clsScriptManager() : pRunningScriptE(NULL), pRunningScriptS(NULL), ppScriptTable(NULL), pActualUser(NULL), pTimerListS(NULL), pTimerListE(NULL), ui8ScriptCount(0), ui8BotsCount(0), bMoved(false) {
#ifdef _WIN32
    clsServerManager::hLuaHeap = ::HeapCreate(HEAP_NO_SERIALIZE, 0x80000, 0);
#endif

#ifdef _WIN32
    if(FileExist((clsServerManager::sPath + "\\cfg\\Scripts.pxt").c_str()) == false) {
#else
    if(FileExist((clsServerManager::sPath + "/cfg/Scripts.pxt").c_str()) == false) {
#endif
        LoadXML();

        return;
    }

#ifdef _WIN32
	FILE * fScriptsFile = fopen((clsServerManager::sPath + "\\cfg\\Scripts.pxt").c_str(), "rt");
#else
	FILE * fScriptsFile = fopen((clsServerManager::sPath + "/cfg/Scripts.pxt").c_str(), "rt");
#endif
    if(fScriptsFile == NULL) {
#ifdef _WIN32
        int imsgLen = sprintf(clsServerManager::pGlobalBuffer, "Error loading file Scripts.pxt %s (%d)", WSErrorStr(errno), errno);
#else
		int imsgLen = sprintf(clsServerManager::pGlobalBuffer, "Error loading file Scripts.pxt %s (%d)", ErrnoStr(errno), errno);
#endif
		CheckSprintf(imsgLen, clsServerManager::szGlobalBufferSize, "clsScriptManager::clsScriptManager");
#ifdef _BUILD_GUI
		::MessageBox(NULL, clsServerManager::pGlobalBuffer, g_sPtokaXTitle, MB_OK | MB_ICONERROR);
#else
		AppendLog(clsServerManager::pGlobalBuffer);
#endif
        exit(EXIT_FAILURE);
    }

	size_t szLen = 0;

	while(fgets(clsServerManager::pGlobalBuffer, (int)clsServerManager::szGlobalBufferSize, fScriptsFile) != NULL) {
		if(clsServerManager::pGlobalBuffer[0] == '#' || clsServerManager::pGlobalBuffer[0] == '\n') {
			continue;
		}

		szLen = strlen(clsServerManager::pGlobalBuffer)-1;

		if(szLen < 7) {
			continue;
		}

		clsServerManager::pGlobalBuffer[szLen] = '\0';

		for(size_t szi = szLen-1; szi != 0; szi--) {
			if(isspace(clsServerManager::pGlobalBuffer[szi-1]) != 0 || clsServerManager::pGlobalBuffer[szi-1] == '=') {
				clsServerManager::pGlobalBuffer[szi-1] = '\0';
				continue;
			}

			break;
		}

		if(clsServerManager::pGlobalBuffer[0] == '\0' || (clsServerManager::pGlobalBuffer[szLen-1] != '1' && clsServerManager::pGlobalBuffer[szLen-1] != '0')) {
			continue;
		}

		if(FileExist((clsServerManager::sScriptPath+string(clsServerManager::pGlobalBuffer)).c_str()) == false || FindScript(clsServerManager::pGlobalBuffer) != NULL) {
			continue;
		}

		AddScript(clsServerManager::pGlobalBuffer, clsServerManager::pGlobalBuffer[szLen-1] == '1' ? true : false, false);
	}

    fclose(fScriptsFile);
}
//------------------------------------------------------------------------------

clsScriptManager::~clsScriptManager() {
    pRunningScriptS = NULL;
    pRunningScriptE = NULL;

    for(uint8_t ui8i = 0; ui8i < ui8ScriptCount; ui8i++) {
		delete ppScriptTable[ui8i];
    }

#ifdef _WIN32
	if(HeapFree(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)ppScriptTable) == 0) {
		AppendDebugLog("%s - [MEM] Cannot deallocate ScriptTable in clsScriptManager::~clsScriptManager\n");
	}
#else
	free(ppScriptTable);
#endif

	ppScriptTable = NULL;

	ui8ScriptCount = 0;

    pActualUser = NULL;

    ui8BotsCount = 0;

#ifdef _WIN32
    ::HeapDestroy(clsServerManager::hLuaHeap);
#endif
}
//------------------------------------------------------------------------------

void clsScriptManager::Start() {
    ui8BotsCount = 0;
    pActualUser = NULL;

    
    // PPK ... first look for deleted and new scripts
    CheckForDeletedScripts();
    CheckForNewScripts();

    // PPK ... second start all enabled scripts
    for(uint8_t ui8i = 0; ui8i < ui8ScriptCount; ui8i++) {
		if(ppScriptTable[ui8i]->bEnabled == true) {
        	if(ScriptStart(ppScriptTable[ui8i]) == true) {
				AddRunningScript(ppScriptTable[ui8i]);
			} else {
                ppScriptTable[ui8i]->bEnabled = false;
            }
		}
	}

#ifdef _BUILD_GUI
    clsMainWindowPageScripts::mPtr->AddScriptsToList(true);
#endif
}
Beispiel #15
0
void CQuestManager::GotoPauseState(QuestState & qs)
{
    qs.suspend_state = SUSPEND_STATE_PAUSE;
    AddScript("[NEXT]");
    SendScript();
}
Beispiel #16
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIEntity::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(ENTITY_CONTAINER)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(DISABLED)
	TOKEN_TABLE(VISIBLE)
	TOKEN_TABLE(X)
	TOKEN_TABLE(Y)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(ENTITY)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd = 2;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_ENTITY_CONTAINER) {
			Game->LOG(0, "'ENTITY_CONTAINER' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_X:
			parser.ScanStr((char *)params, "%d", &m_PosX);
			break;

		case TOKEN_Y:
			parser.ScanStr((char *)params, "%d", &m_PosY);
			break;

		case TOKEN_DISABLED:
			parser.ScanStr((char *)params, "%b", &m_Disable);
			break;

		case TOKEN_VISIBLE:
			parser.ScanStr((char *)params, "%b", &m_Visible);
			break;

		case TOKEN_ENTITY:
			if (FAILED(SetEntity((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in ENTITY_CONTAINER definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading ENTITY_CONTAINER definition");
		return E_FAIL;
	}

	CorrectSize();

	if (Game->m_EditorMode) {
		m_Width = 50;
		m_Height = 50;
	}

	return S_OK;
}
Beispiel #17
0
void CQuestManager::GotoEndState(QuestState & qs)
{
    AddScript("[DONE]");
    SendScript();
}
Beispiel #18
0
void EngineActions::DuplicateEntity( ECS::Entity* p_entity )
{
	//Create new entity
	ECS::Entity* newEntity = CreateEntity();
	//Set position, scale and rotation of new entity to same as old entity + a little offset in X (to avoid clipping and confusion)
	SetPosition(newEntity, GetPosition(p_entity) + glm::vec3(10, 0, 0));
	SetOrientation(newEntity, GetOrientation(p_entity));
	SetScale(newEntity, GetScale(p_entity));

	//Get all components
	RootForce::Renderable*		renderable		= m_world->GetEntityManager()->GetComponent<RootForce::Renderable>(p_entity);
	RootForce::Physics*			physics			= m_world->GetEntityManager()->GetComponent<RootForce::Physics>(p_entity);
	RootForce::Collision*		collision		= m_world->GetEntityManager()->GetComponent<RootForce::Collision>(p_entity);
	RootForce::Script*			script			= m_world->GetEntityManager()->GetComponent<RootForce::Script>(p_entity);
	RootForce::WaterCollider*	watercollider	= m_world->GetEntityManager()->GetComponent<RootForce::WaterCollider>(p_entity);
	RootForce::ParticleEmitter* particleEmitter = m_world->GetEntityManager()->GetComponent<RootForce::ParticleEmitter>(p_entity);

	//Check if there's a renderable and copy data
	if(renderable != nullptr)
	{
		AddRenderable(newEntity);
		SetRenderableModelName(newEntity, GetRenderableModelName(p_entity));
		SetRenderableMaterialName(newEntity, GetRenderableMaterialName(p_entity));
	}

	//Check if there's a renderable and copy data
	if(collision != nullptr)
	{
		if(physics != nullptr)
		{
			AddPhysics(newEntity, true);
			SetMass(newEntity, GetMass(p_entity));
		}
		else
			AddPhysics(newEntity, false);

		SetPhysicsType(newEntity, GetPhysicsType(p_entity));
		SetPhysicsShape(newEntity, GetPhysicsShape(p_entity));
		SetShapeHeight(newEntity, GetShapeHeight(p_entity));
		SetShapeRadius(newEntity, GetShapeRadius(p_entity));
		SetPhysicsMesh(newEntity, GetPhysicsMesh(p_entity));
		SetCollideWithStatic(newEntity, GetCollideWithStatic(p_entity));
		SetCollideWithWorld(newEntity, GetCollideWithWorld(p_entity));
		SetGravity(newEntity, GetGravity(p_entity));	
	}

	//Check if there's a script and copy data
	if(script != nullptr)
	{
		AddScript(newEntity);
		SetScript(newEntity, GetScript(p_entity));
	}

	//Check if there's a water collider and copy data
	if(watercollider != nullptr)
	{
		AddWaterCollider(newEntity);
		SetWaterColliderInterval(newEntity, GetWaterColliderInterval(p_entity));
		SetWaterColliderPower(newEntity, GetWaterColliderPower(p_entity));
		SetWaterColliderRadius(newEntity, GetWaterColliderRadius(p_entity));
	}

	if(particleEmitter != nullptr)
	{
		AddParticle(newEntity);
		SetParticleEmitter(newEntity, GetParticleEmitter(p_entity));
	}
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIWindow::LoadBuffer(BYTE* Buffer, bool Complete)
{
    TOKEN_TABLE_START(commands)
    TOKEN_TABLE (WINDOW)
    TOKEN_TABLE (ALPHA_COLOR)
    TOKEN_TABLE (ALPHA)
    TOKEN_TABLE (TEMPLATE)
    TOKEN_TABLE (DISABLED)
    TOKEN_TABLE (VISIBLE)
    TOKEN_TABLE (BACK_INACTIVE)
    TOKEN_TABLE (BACK)
    TOKEN_TABLE (IMAGE_INACTIVE)
    TOKEN_TABLE (IMAGE)
    TOKEN_TABLE (FONT_INACTIVE)
    TOKEN_TABLE (FONT)
    TOKEN_TABLE (TITLE_ALIGN)
    TOKEN_TABLE (TITLE_RECT)
    TOKEN_TABLE (TITLE)
    TOKEN_TABLE (DRAG_RECT)
    TOKEN_TABLE (X)
    TOKEN_TABLE (Y)
    TOKEN_TABLE (WIDTH)
    TOKEN_TABLE (HEIGHT)
    TOKEN_TABLE (FADE_ALPHA)
    TOKEN_TABLE (FADE_COLOR)
    TOKEN_TABLE (CURSOR)
    TOKEN_TABLE (NAME)
    TOKEN_TABLE (BUTTON)
    TOKEN_TABLE (STATIC)
    TOKEN_TABLE (TRANSPARENT)
    TOKEN_TABLE (SCRIPT)
    TOKEN_TABLE (CAPTION)
    TOKEN_TABLE (PARENT_NOTIFY)
    TOKEN_TABLE (MENU)
    TOKEN_TABLE (IN_GAME)
    TOKEN_TABLE (CLIP_CONTENTS)
    TOKEN_TABLE (PAUSE_MUSIC)
    TOKEN_TABLE (EDITOR_PROPERTY)
    TOKEN_TABLE (EDIT)
    TOKEN_TABLE_END

    BYTE* params;
    int cmd=2;
    CBParser parser(Game);

    int FadeR=0, FadeG=0, FadeB=0, FadeA=0;
    int ar=0, ag=0, ab=0, alpha=0;

    if(Complete)
    {
        if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_WINDOW)
        {
            Game->LOG(0, "'WINDOW' keyword expected.");
            return E_FAIL;
        }
        Buffer = params;
    }

    while (cmd >= PARSERR_TOKENNOTFOUND && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) >= PARSERR_TOKENNOTFOUND)
    {
        switch (cmd)
        {
        case TOKEN_TEMPLATE:
            if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_NAME:
            SetName((char*)params);
            break;

        case TOKEN_CAPTION:
            SetCaption((char*)params);
            break;

        case TOKEN_BACK:
            SAFE_DELETE(m_Back);
            m_Back = new CUITiledImage(Game);
            if(!m_Back || FAILED(m_Back->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_Back);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_BACK_INACTIVE:
            SAFE_DELETE(m_BackInactive);
            m_BackInactive = new CUITiledImage(Game);
            if(!m_BackInactive || FAILED(m_BackInactive->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_BackInactive);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_IMAGE:
            SAFE_DELETE(m_Image);
            m_Image = new CBSprite(Game);
            if(!m_Image || FAILED(m_Image->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_Image);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_IMAGE_INACTIVE:
            SAFE_DELETE(m_ImageInactive);
            m_ImageInactive = new CBSprite(Game);
            if(!m_ImageInactive || FAILED(m_ImageInactive->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_ImageInactive);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_FONT:
            if(m_Font) Game->m_FontStorage->RemoveFont(m_Font);
            m_Font = Game->m_FontStorage->AddFont((char*)params);
            if(!m_Font) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_FONT_INACTIVE:
            if(m_FontInactive) Game->m_FontStorage->RemoveFont(m_FontInactive);
            m_FontInactive = Game->m_FontStorage->AddFont((char*)params);
            if(!m_FontInactive) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_TITLE:
            SetText((char*)params);
            Game->m_StringTable->Expand(&m_Text);
            break;

        case TOKEN_TITLE_ALIGN:
            if(CBPlatform::stricmp((char*)params, "left")==0) m_TitleAlign = TAL_LEFT;
            else if(CBPlatform::stricmp((char*)params, "right")==0) m_TitleAlign = TAL_RIGHT;
            else m_TitleAlign = TAL_CENTER;
            break;

        case TOKEN_TITLE_RECT:
            parser.ScanStr((char*)params, "%d,%d,%d,%d", &m_TitleRect.left, &m_TitleRect.top, &m_TitleRect.right, &m_TitleRect.bottom);
            break;

        case TOKEN_DRAG_RECT:
            parser.ScanStr((char*)params, "%d,%d,%d,%d", &m_DragRect.left, &m_DragRect.top, &m_DragRect.right, &m_DragRect.bottom);
            break;

        case TOKEN_X:
            parser.ScanStr((char*)params, "%d", &m_PosX);
            break;

        case TOKEN_Y:
            parser.ScanStr((char*)params, "%d", &m_PosY);
            break;

        case TOKEN_WIDTH:
            parser.ScanStr((char*)params, "%d", &m_Width);
            break;

        case TOKEN_HEIGHT:
            parser.ScanStr((char*)params, "%d", &m_Height);
            break;

        case TOKEN_CURSOR:
            SAFE_DELETE(m_Cursor);
            m_Cursor = new CBSprite(Game);
            if(!m_Cursor || FAILED(m_Cursor->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_Cursor);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_BUTTON:
        {
            CUIButton* btn = new CUIButton(Game);
            if(!btn || FAILED(btn->LoadBuffer(params, false)))
            {
                SAFE_DELETE(btn);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                btn->m_Parent = this;
                m_Widgets.Add(btn);
            }
        }
        break;

        case TOKEN_STATIC:
        {
            CUIText* text = new CUIText(Game);
            if(!text || FAILED(text->LoadBuffer(params, false)))
            {
                SAFE_DELETE(text);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                text->m_Parent = this;
                m_Widgets.Add(text);
            }
        }
        break;

        case TOKEN_EDIT:
        {
            CUIEdit* edit = new CUIEdit(Game);
            if(!edit || FAILED(edit->LoadBuffer(params, false)))
            {
                SAFE_DELETE(edit);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                edit->m_Parent = this;
                m_Widgets.Add(edit);
            }
        }
        break;

        case TOKEN_WINDOW:
        {
            CUIWindow* win = new CUIWindow(Game);
            if(!win || FAILED(win->LoadBuffer(params, false)))
            {
                SAFE_DELETE(win);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                win->m_Parent = this;
                m_Widgets.Add(win);
            }
        }
        break;


        case TOKEN_TRANSPARENT:
            parser.ScanStr((char*)params, "%b", &m_Transparent);
            break;

        case TOKEN_SCRIPT:
            AddScript((char*)params);
            break;

        case TOKEN_PARENT_NOTIFY:
            parser.ScanStr((char*)params, "%b", &m_ParentNotify);
            break;

        case TOKEN_PAUSE_MUSIC:
            parser.ScanStr((char*)params, "%b", &m_PauseMusic);
            break;

        case TOKEN_DISABLED:
            parser.ScanStr((char*)params, "%b", &m_Disable);
            break;

        case TOKEN_VISIBLE:
            parser.ScanStr((char*)params, "%b", &m_Visible);
            break;

        case TOKEN_MENU:
            parser.ScanStr((char*)params, "%b", &m_IsMenu);
            break;

        case TOKEN_IN_GAME:
            parser.ScanStr((char*)params, "%b", &m_InGame);
            break;

        case TOKEN_CLIP_CONTENTS:
            parser.ScanStr((char*)params, "%b", &m_ClipContents);
            break;

        case TOKEN_FADE_COLOR:
            parser.ScanStr((char*)params, "%d,%d,%d", &FadeR, &FadeG, &FadeB);
            m_FadeBackground = true;
            break;

        case TOKEN_FADE_ALPHA:
            parser.ScanStr((char*)params, "%d", &FadeA);
            m_FadeBackground = true;
            break;

        case TOKEN_EDITOR_PROPERTY:
            ParseEditorProperty(params, false);
            break;

        case TOKEN_ALPHA_COLOR:
            parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
            break;

        case TOKEN_ALPHA:
            parser.ScanStr((char*)params, "%d", &alpha);
            break;


        default:
            if(FAILED(Game->WindowLoadHook(this, (char**)&Buffer, (char**)params)))
            {
                cmd = PARSERR_GENERIC;
            }
        }
    }
    if (cmd == PARSERR_TOKENNOTFOUND)
    {
        Game->LOG(0, "Syntax error in WINDOW definition");
        return E_FAIL;
    }
    if (cmd == PARSERR_GENERIC)
    {
        Game->LOG(0, "Error loading WINDOW definition");
        return E_FAIL;
    }

    CorrectSize();

    if(alpha != 0 && ar==0 && ag == 0 && ab == 0)
    {
        ar = ag = ab = 255;
    }
    m_AlphaColor = DRGBA(ar, ag, ab, alpha);

    if(m_FadeBackground) m_FadeColor = DRGBA(FadeR, FadeG, FadeB, FadeA);

    m_FocusedWidget = NULL;

    return S_OK;
}
Beispiel #20
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIButton::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(BUTTON)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(DISABLED)
	TOKEN_TABLE(VISIBLE)
	TOKEN_TABLE(FOCUSABLE)
	TOKEN_TABLE(BACK_HOVER)
	TOKEN_TABLE(BACK_PRESS)
	TOKEN_TABLE(BACK_DISABLE)
	TOKEN_TABLE(BACK_FOCUS)
	TOKEN_TABLE(BACK)
	TOKEN_TABLE(CENTER_IMAGE)
	TOKEN_TABLE(IMAGE_HOVER)
	TOKEN_TABLE(IMAGE_PRESS)
	TOKEN_TABLE(IMAGE_DISABLE)
	TOKEN_TABLE(IMAGE_FOCUS)
	TOKEN_TABLE(IMAGE)
	TOKEN_TABLE(FONT_HOVER)
	TOKEN_TABLE(FONT_PRESS)
	TOKEN_TABLE(FONT_DISABLE)
	TOKEN_TABLE(FONT_FOCUS)
	TOKEN_TABLE(FONT)
	TOKEN_TABLE(TEXT_ALIGN)
	TOKEN_TABLE(TEXT)
	TOKEN_TABLE(X)
	TOKEN_TABLE(Y)
	TOKEN_TABLE(WIDTH)
	TOKEN_TABLE(HEIGHT)
	TOKEN_TABLE(CURSOR)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(EVENTS)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(CAPTION)
	TOKEN_TABLE(PARENT_NOTIFY)
	TOKEN_TABLE(PRESSED)
	TOKEN_TABLE(PIXEL_PERFECT)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd = 2;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_BUTTON) {
			Game->LOG(0, "'BUTTON' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_CAPTION:
			SetCaption((char *)params);
			break;

		case TOKEN_BACK:
			delete m_Back;
			m_Back = new CUITiledImage(Game);
			if (!m_Back || FAILED(m_Back->LoadFile((char *)params))) {
				delete m_Back;
				m_Back = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_HOVER:
			delete m_BackHover;
			m_BackHover = new CUITiledImage(Game);
			if (!m_BackHover || FAILED(m_BackHover->LoadFile((char *)params))) {
				delete m_BackHover;
				m_BackHover = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_PRESS:
			delete m_BackPress;
			m_BackPress = new CUITiledImage(Game);
			if (!m_BackPress || FAILED(m_BackPress->LoadFile((char *)params))) {
				delete m_BackPress;
				m_BackPress = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_DISABLE:
			delete m_BackDisable;
			m_BackDisable = new CUITiledImage(Game);
			if (!m_BackDisable || FAILED(m_BackDisable->LoadFile((char *)params))) {
				delete m_BackDisable;
				m_BackDisable = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_FOCUS:
			delete m_BackFocus;
			m_BackFocus = new CUITiledImage(Game);
			if (!m_BackFocus || FAILED(m_BackFocus->LoadFile((char *)params))) {
				delete m_BackFocus;
				m_BackFocus = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE:
			delete m_Image;
			m_Image = new CBSprite(Game);
			if (!m_Image || FAILED(m_Image->LoadFile((char *)params))) {
				delete m_Image;
				m_Image = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_HOVER:
			delete m_ImageHover;
			m_ImageHover = new CBSprite(Game);
			if (!m_ImageHover || FAILED(m_ImageHover->LoadFile((char *)params))) {
				delete m_ImageHover;
				m_ImageHover = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_PRESS:
			delete m_ImagePress;
			m_ImagePress = new CBSprite(Game);
			if (!m_ImagePress || FAILED(m_ImagePress->LoadFile((char *)params))) {
				delete m_ImagePress;
				m_ImagePress = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_DISABLE:
			delete m_ImageDisable;
			m_ImageDisable = new CBSprite(Game);
			if (!m_ImageDisable || FAILED(m_ImageDisable->LoadFile((char *)params))) {
				delete m_ImageDisable;
				m_ImageDisable = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_FOCUS:
			delete m_ImageFocus;
			m_ImageFocus = new CBSprite(Game);
			if (!m_ImageFocus || FAILED(m_ImageFocus->LoadFile((char *)params))) {
				delete m_ImageFocus;
				m_ImageFocus = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_FONT:
			if (m_Font) Game->m_FontStorage->RemoveFont(m_Font);
			m_Font = Game->m_FontStorage->AddFont((char *)params);
			if (!m_Font) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_HOVER:
			if (m_FontHover) Game->m_FontStorage->RemoveFont(m_FontHover);
			m_FontHover = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontHover) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_PRESS:
			if (m_FontPress) Game->m_FontStorage->RemoveFont(m_FontPress);
			m_FontPress = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontPress) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_DISABLE:
			if (m_FontDisable) Game->m_FontStorage->RemoveFont(m_FontDisable);
			m_FontDisable = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontDisable) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_FOCUS:
			if (m_FontFocus) Game->m_FontStorage->RemoveFont(m_FontFocus);
			m_FontFocus = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontFocus) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_TEXT:
			SetText((char *)params);
			Game->m_StringTable->Expand(&m_Text);
			break;

		case TOKEN_TEXT_ALIGN:
			if (scumm_stricmp((char *)params, "left") == 0) m_Align = TAL_LEFT;
			else if (scumm_stricmp((char *)params, "right") == 0) m_Align = TAL_RIGHT;
			else m_Align = TAL_CENTER;
			break;

		case TOKEN_X:
			parser.ScanStr((char *)params, "%d", &m_PosX);
			break;

		case TOKEN_Y:
			parser.ScanStr((char *)params, "%d", &m_PosY);
			break;

		case TOKEN_WIDTH:
			parser.ScanStr((char *)params, "%d", &m_Width);
			break;

		case TOKEN_HEIGHT:
			parser.ScanStr((char *)params, "%d", &m_Height);
			break;

		case TOKEN_CURSOR:
			delete m_Cursor;
			m_Cursor = new CBSprite(Game);
			if (!m_Cursor || FAILED(m_Cursor->LoadFile((char *)params))) {
				delete m_Cursor;
				m_Cursor = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_PARENT_NOTIFY:
			parser.ScanStr((char *)params, "%b", &m_ParentNotify);
			break;

		case TOKEN_DISABLED:
			parser.ScanStr((char *)params, "%b", &m_Disable);
			break;

		case TOKEN_VISIBLE:
			parser.ScanStr((char *)params, "%b", &m_Visible);
			break;

		case TOKEN_FOCUSABLE:
			parser.ScanStr((char *)params, "%b", &m_CanFocus);
			break;

		case TOKEN_CENTER_IMAGE:
			parser.ScanStr((char *)params, "%b", &m_CenterImage);
			break;

		case TOKEN_PRESSED:
			parser.ScanStr((char *)params, "%b", &m_StayPressed);
			break;

		case TOKEN_PIXEL_PERFECT:
			parser.ScanStr((char *)params, "%b", &m_PixelPerfect);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in BUTTON definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading BUTTON definition");
		return E_FAIL;
	}

	CorrectSize();

	return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::LoadBuffer(BYTE* Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (ITEM)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (CURSOR_HOVER)
		TOKEN_TABLE (CURSOR_COMBINED)
		TOKEN_TABLE (CURSOR)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (IMAGE_HOVER)
		TOKEN_TABLE (IMAGE)
		TOKEN_TABLE (EVENTS)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (EDITOR_PROPERTY)
		TOKEN_TABLE (FONT)
		TOKEN_TABLE (ALPHA_COLOR)
		TOKEN_TABLE (ALPHA)
		TOKEN_TABLE (TALK_SPECIAL)
		TOKEN_TABLE (TALK)
		TOKEN_TABLE (SPRITE_HOVER)
		TOKEN_TABLE (SPRITE)
		TOKEN_TABLE (DISPLAY_AMOUNT)
		TOKEN_TABLE (AMOUNT_OFFSET_X)
		TOKEN_TABLE (AMOUNT_OFFSET_Y)
		TOKEN_TABLE (AMOUNT_ALIGN)
		TOKEN_TABLE (AMOUNT_STRING)
		TOKEN_TABLE (AMOUNT)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd=2;
	CBParser parser(Game);

	if(Complete){
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_ITEM){
			Game->LOG(0, "'ITEM' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int ar=0, ag=0, ab=0, alpha=255;
	while (cmd>0 && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_FONT:
				SetFont((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_IMAGE:
			case TOKEN_SPRITE:
				SAFE_DELETE(m_Sprite);
				m_Sprite = new CBSprite(Game, this);
				if(!m_Sprite || FAILED(m_Sprite->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_Sprite);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_IMAGE_HOVER:
			case TOKEN_SPRITE_HOVER:
				SAFE_DELETE(m_SpriteHover);
				m_SpriteHover = new CBSprite(Game, this);
				if(!m_SpriteHover || FAILED(m_SpriteHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_SpriteHover);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_AMOUNT:
				parser.ScanStr((char*)params, "%d", &m_Amount);
			break;

			case TOKEN_DISPLAY_AMOUNT:
				parser.ScanStr((char*)params, "%b", &m_DisplayAmount);
			break;

			case TOKEN_AMOUNT_OFFSET_X:
				parser.ScanStr((char*)params, "%d", &m_AmountOffsetX);
			break;

			case TOKEN_AMOUNT_OFFSET_Y:
				parser.ScanStr((char*)params, "%d", &m_AmountOffsetY);
			break;

			case TOKEN_AMOUNT_ALIGN:
				if(CBPlatform::stricmp((char*)params, "left")==0) m_AmountAlign = TAL_LEFT;
				else if(CBPlatform::stricmp((char*)params, "right")==0) m_AmountAlign = TAL_RIGHT;
				else m_AmountAlign = TAL_CENTER;
			break;

			case TOKEN_AMOUNT_STRING:
				CBUtils::SetString(&m_AmountString, (char*)params);
			break;

			case TOKEN_TALK:
			{
				CBSprite* spr = new CBSprite(Game, this);
				if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSprites.Add(spr);
			}
			break;

			case TOKEN_TALK_SPECIAL:
			{
				CBSprite* spr = new CBSprite(Game, this);
				if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSpritesEx.Add(spr);
			}
			break;

			case TOKEN_CURSOR:
				SAFE_DELETE(m_CursorNormal);
				m_CursorNormal = new CBSprite(Game);
				if(!m_CursorNormal || FAILED(m_CursorNormal->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_CursorNormal);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_CURSOR_HOVER:
				SAFE_DELETE(m_CursorHover);
				m_CursorHover = new CBSprite(Game);
				if(!m_CursorHover || FAILED(m_CursorHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_CursorHover);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_CURSOR_COMBINED:
				parser.ScanStr((char*)params, "%b", &m_CursorCombined);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_ALPHA_COLOR:
				parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
				break;

			case TOKEN_ALPHA:
				parser.ScanStr((char*)params, "%d", &alpha);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND){
		Game->LOG(0, "Syntax error in ITEM definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC){
		Game->LOG(0, "Error loading ITEM definition");
		return E_FAIL;
	}

	if(alpha != 0 && ar==0 && ag == 0 && ab == 0){
		ar = ag = ab = 255;
	}
	m_AlphaColor = DRGBA(ar, ag, ab, alpha);

	return S_OK;
}