Ejemplo n.º 1
0
void ComposerEngine::onKeyDown(uint16 keyCode) {
	runEvent(kEventKeyDown, keyCode, 0, 0);
	runEvent(kEventChar, keyCode, 0, 0);

	for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++) {
		for (Common::List<KeyboardHandler>::iterator j = i->_keyboardHandlers.begin(); j != i->_keyboardHandlers.end(); j++) {
			const KeyboardHandler &handler = *j;
			if (keyCode != handler.keyId)
				continue;

			int modifiers = g_system->getEventManager()->getModifierState();
			switch (handler.modifierId) {
			case 0x10: // shift
				if (!(modifiers & Common::KBD_SHIFT))
					continue;
				break;
			case 0x11: // control
				if (!(modifiers & Common::KBD_CTRL))
					continue;
				break;
			case 0:
				break;
			default:
				warning("unknown keyb modifier %d", handler.modifierId);
				continue;
			}

			runScript(handler.scriptId);
		}
	}
}
Ejemplo n.º 2
0
void MenuCreateTower::onActivate( Ref * sender, bool availebledButton )
{
	if( _disabled )return;
	hideConfirmButton();

	auto node = dynamic_cast<MenuItem*>(sender);
	if( !node ) return;
	_hidenButton.reset( node );
	//_hidenButton->setVisible( false );

	std::string name = _hidenButton->getName();

	if( availebledButton )
	{
		_confirmButton->setPosition( node->getPosition() );
		_confirmButton->setVisible( true );
	}
	else
	{
		name.erase( name.begin() + name.size() - 3, name.end() );
		_confirmButtonUn->setName( name );
		_confirmButtonUn->setPosition( node->getPosition() );
		_confirmButtonUn->setVisible( true );
	}

	_selectedTower = name;

	runEvent( "onclick" );
	runEvent( "onclickby_" + _selectedTower );
	buildDescription();

	//float rate = mlTowersInfo::shared( ).rate( name );
	float radius = mlTowersInfo::shared().radiusInPixels( name, 1 );
	showRadius( _centerPoint, radius /** rate*/ );
}
Ejemplo n.º 3
0
void MenuCreateTower::appearance()
{
	setVisible( true );
	hideConfirmButton();
	runEvent( "appearance" );
	_disabled = false;
	ScoreCounter::shared().observer( kScoreLevel ).add( _ID, std::bind( &MenuCreateTower::onChangeMoney, this, std::placeholders::_1 ) );
	changeCost();
	onChangeMoney( ScoreCounter::shared().getMoney( kScoreLevel ) );
	scheduleUpdate();
}
Ejemplo n.º 4
0
void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventParam) {
	// First, we check if this animation is already playing,
	// and if it is, we sabotage that running one first.
	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;
		if (anim->_id != animId)
			continue;

		stopAnimation(*i);
	}

	Common::SeekableReadStream *stream = NULL;
	Pipe *newPipe = NULL;

	// First, check the existing pipes.
	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		Pipe *pipe = *j;
		if (!pipe->hasResource(ID_ANIM, animId))
			continue;
		stream = pipe->getResource(ID_ANIM, animId, false);
		break;
	}

	// If we didn't find it, try the libraries.
	if (!stream) {
		if (!hasResource(ID_ANIM, animId)) {
			warning("ignoring attempt to play invalid anim %d", animId);
			return;
		}
		stream = getResource(ID_ANIM, animId);

		uint32 type = 0;
		for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++)
			if (i->_archive->hasResource(ID_ANIM, animId)) {
				type = i->_archive->getResourceFlags(ID_ANIM, animId);
				break;
			}

		// If the resource is a pipe itself, then load the pipe
		// and then fish the requested animation out of it.
		if (type != 1) {
			newPipe = new Pipe(stream);
			_pipes.push_front(newPipe);
			stream = newPipe->getResource(ID_ANIM, animId, false);
		}
	}

	Animation *anim = new Animation(stream, animId, Common::Point(x, y), eventParam);
	_anims.push_back(anim);
	runEvent(kEventAnimStarted, animId, eventParam, 0);
	if (newPipe)
		newPipe->_anim = anim;
}
Ejemplo n.º 5
0
void MenuCreateTower::disappearance()
{
	if( _disabled == false )
	{
		hideConfirmButton();
		runEvent( "disappearance" );
		_disabled = true;

		hideRadius();
		ScoreCounter::shared().observer( kScoreLevel ).remove( _ID );
		unscheduleUpdate();
	}
}
Ejemplo n.º 6
0
void runTrigger(int id){
    if(event[id].eValue){
        switch(event[id].event)
        {
            case 1:
                //int alt = 0;
                // read altitude
            if(alt > event[id].eValue){ runEvent(id); }
            break;
            case 2:
                //int time = 0;
                //read time
            if((hour*60+minute) > event[id].eValue){ runEvent(id); }
            break;
            case 3:
                //int pos = 0;
                // read pos
                //if(pos > event[id].eValue){ runEvent(id); }
            break;
            default:
            break;
        }
    }
}
Ejemplo n.º 7
0
void ComposerEngine::playAnimation(uint16 animId, int16 x, int16 y, int16 eventParam) {
	// First, we check if this animation is already playing,
	// and if it is, we sabotage that running one first.
	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;
		if (anim->_id != animId)
			continue;

		stopAnimation(*i);
	}

	Animation *anim = NULL;
	loadAnimation(anim, animId, x, y, eventParam);
	_anims.push_back(anim);
	runEvent(kEventAnimStarted, animId, eventParam, 0);
}
Ejemplo n.º 8
0
/**
 Author: 	Joel Denke
 Description: 	Reads data from buffers and run it
 */
int runData(int i)
{
	char * elem = malloc(sizeof(char) * MESSAGE_SIZE);
	
	SDL_mutexP(b_lock[i]);
	if (!slotsEmpty(cb[i])) {
		elem = readSlot(cb[i]);
		
		printf("Get data %s from slot %d\n", elem, i+1);
		
		if (elem != NULL) {
			runEvent(i+1, elem);
		}
	}
	SDL_mutexV(b_lock[i]);
}
Ejemplo n.º 9
0
void ComposerEngine::unloadLibrary(uint id) {
	for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++) {
		if (i->_id != id)
			continue;

		for (Common::List<Animation *>::iterator j = _anims.begin(); j != _anims.end(); j++) {
			delete *j;
		}
		_anims.clear();
		stopPipes();

		_randomEvents.clear();

		for (Common::List<Sprite>::iterator j = _sprites.begin(); j != _sprites.end(); j++) {
			j->_surface.free();
		}
		_sprites.clear();
		i->_buttons.clear();

		_lastButton = NULL;

		_mixer->stopAll();
		_audioStream = NULL;

		for (uint j = 0; j < _queuedScripts.size(); j++) {
			_queuedScripts[j]._count = 0;
			_queuedScripts[j]._scriptId = 0;
		}

		delete i->_archive;
		_libraries.erase(i);

		runEvent(kEventUnload, id, 0, 0);

		return;
	}

	error("tried to unload library %d, which isn't loaded", id);
}
Ejemplo n.º 10
0
void MenuCreateTower::confirmSelect( Ref * sender, bool availebledButton )
{
	if( _disabled )return;
	if( availebledButton )
	{
		assert( _hidenButton );
		std::string towername = _hidenButton->getName();
		if(towername.find("_un") != std::string::npos )
		{
			towername = towername.substr( 0, towername.find("_un") );
		}
		hideConfirmButton();
		runEvent( "onconfirm" );

		GameGS::getInstance()->getGameBoard().createTower( towername );
		disappearance();
	}
	else
	{
		if(k::configuration::useInapps && TutorialManager::shared().dispatch( "level_haventgear_build" ) )
			disappearance();
	}
}
Ejemplo n.º 11
0
void ComposerEngine::processAnimFrame() {
	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;

		anim->seekToCurrPos();

		if (anim->_state <= 1) {
			bool normalEnd = (anim->_state == 1);
			if (normalEnd) {
				runEvent(kEventAnimDone, anim->_id, anim->_eventParam, 0);
			}
			stopAnimation(anim, true, normalEnd);
			delete anim;
			i = _anims.reverse_erase(i);

			continue;
		}

		for (uint j = 0; j < anim->_entries.size(); j++) {
			AnimationEntry &entry = anim->_entries[j];
			if (entry.op != kAnimOpEvent)
				break;
			if (entry.counter) {
				entry.counter--;
			} else {
				if ((anim->_state > 1) && (anim->_stream->pos() + 2 > anim->_stream->size())) {
					warning("anim with id %d ended too soon", anim->_id);
					anim->_state = 0;
					break;
				}

				uint16 event = anim->_stream->readUint16LE();
				anim->_offset += 2;
				if (event == 0xffff) {
					entry.counter = anim->_stream->readUint16LE() - 1;
					anim->_offset += 2;
				} else {
					debug(4, "anim: event %d", event);
					runEvent(event, anim->_id, 0, 0);
				}
			}
		}
	}

	for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
		Animation *anim = *i;

		// did the anim get disabled?
		if (anim->_state == 0) {
			stopAnimation(anim, true, false);
			delete anim;
			i = _anims.reverse_erase(i);
			continue;
		}

		anim->_state--;

		bool foundWait = false;
		for (uint j = 0; j < anim->_entries.size(); j++) {
			AnimationEntry &entry = anim->_entries[j];

			// only skip these at the start
			if (!foundWait && (entry.op == kAnimOpEvent))
				continue;
			foundWait = true;

			if (entry.counter) {
				entry.counter--;
				if ((entry.op == kAnimOpPlayWave) && entry.prevValue) {
					debug(4, "anim: continue play wave %d", entry.prevValue);
					playWaveForAnim(entry.prevValue, entry.priority, true);
				}
			} else {
				anim->seekToCurrPos();
				if ((anim->_state > 1) && (anim->_stream->pos() + 2 > anim->_stream->size())) {
					warning("anim with id %d ended too soon", anim->_id);
					anim->_state = 0;
					break;
				}

				uint16 data = anim->_stream->readUint16LE();
				anim->_offset += 2;
				if (data == 0xffff) {
					entry.counter = anim->_stream->readUint16LE() - 1;
					anim->_offset += 2;
				} else {
					switch (entry.op) {
					case kAnimOpEvent:
						debug(4, "anim: event %d", data);
						runEvent(data, anim->_id, 0, 0);
						break;
					case kAnimOpPlayWave:
						debug(4, "anim: play wave %d", data);
						playWaveForAnim(data, entry.priority, false);
						break;
					case kAnimOpPlayAnim:
						debug(4, "anim: play anim %d", data);
						playAnimation(data, anim->_basePos.x, anim->_basePos.y, 1);
						break;
					case kAnimOpDrawSprite:
						if (!data || (entry.prevValue && (data != entry.prevValue))) {
							debug(4, "anim: erase sprite %d", entry.prevValue);
							removeSprite(entry.prevValue, anim->_id);
						}
						if (data) {
							int16 x = anim->_stream->readSint16LE();
							int16 y = anim->_stream->readSint16LE();
							Common::Point pos(x, y);
							anim->_offset += 4;
							uint16 animId = anim->_id;
							if (anim->_state == entry.state)
								animId = 0;
							debug(4, "anim: draw sprite %d at (relative) %d,%d", data, x, y);
							bool wasVisible = spriteVisible(data, animId);
							addSprite(data, animId, entry.priority, anim->_basePos + pos);
							if (wasVisible) {
								// make sure modified sprite isn't removed by another entry
								for (uint k = 0; k < anim->_entries.size(); k++) {
									if (anim->_entries[k].op != kAnimOpDrawSprite)
										continue;
									if (anim->_entries[k].prevValue == data)
										anim->_entries[k].prevValue = 1;
								}
							}
						}
						break;
					default:
						warning("unknown anim op %d", entry.op);
					}

					entry.prevValue = data;
				}
			}
		}
	}

	for (Common::List<Pipe *>::iterator j = _pipes.begin(); j != _pipes.end(); j++) {
		Pipe *pipe = *j;
		pipe->nextFrame();

		// V1 pipe audio; see OldPipe
		if (pipe->hasResource(ID_WAVE, 0xffff))
			playWaveForAnim(0xffff, 0, false);
	}
}
Ejemplo n.º 12
0
void ComposerEngine::loadLibrary(uint id) {
	if (getGameType() == GType_ComposerV1 && !_libraries.empty()) {
		// kill the previous page, starting with any scripts running on it

		for (Common::List<OldScript *>::iterator i = _oldScripts.begin(); i != _oldScripts.end(); i++)
			delete *i;
		_oldScripts.clear();

		Library *library = &_libraries.front();
		unloadLibrary(library->_id);
	}

	Common::String filename;

	if (getGameType() == GType_ComposerV1) {
		if (!id || _bookGroup.empty())
			filename = getStringFromConfig("Common", "StartPage");
		else
			filename = getStringFromConfig(_bookGroup, Common::String::format("%d", id));
		filename = mangleFilename(filename);

		// bookGroup is the basename of the path.
		// TODO: tidy this up.
		_bookGroup.clear();
		for (uint i = 0; i < filename.size(); i++) {
			if (filename[i] == '~' || filename[i] == '/' || filename[i] == ':')
				continue;
			for (uint j = 0; j < filename.size(); j++) {
				if (filename[j] == '/') {
					_bookGroup.clear();
					continue;
				}
				if (filename[j] == '.')
					break;
				_bookGroup += filename[j];
			}
			break;
		}
	} else {
		if (!id)
			id = atoi(getStringFromConfig("Common", "StartUp").c_str());
		filename = getFilename("Libs", id);
	}

	Library library;

	library._id = id;
	library._archive = new ComposerArchive();
	if (!library._archive->openFile(filename))
		error("failed to open '%s'", filename.c_str());
	_libraries.push_front(library);

	Library &newLib = _libraries.front();

	Common::Array<uint16> buttonResources = library._archive->getResourceIDList(ID_BUTN);
	for (uint i = 0; i < buttonResources.size(); i++) {
		uint16 buttonId = buttonResources[i];
		Common::SeekableReadStream *stream = library._archive->getResource(ID_BUTN, buttonId);
		Button button(stream, buttonId, getGameType());

		bool inserted = false;
		for (Common::List<Button>::iterator b = newLib._buttons.begin(); b != newLib._buttons.end(); b++) {
			if (button._zorder < b->_zorder)
				continue;
			newLib._buttons.insert(b, button);
			inserted = true;
			break;
		}
		if (!inserted)
			newLib._buttons.push_back(button);
	}

	Common::Array<uint16> ambientResources = library._archive->getResourceIDList(ID_AMBI);
	for (uint i = 0; i < ambientResources.size(); i++) {
		Common::SeekableReadStream *stream = library._archive->getResource(ID_AMBI, ambientResources[i]);
		Button button(stream);
		newLib._buttons.insert(newLib._buttons.begin(), button);
	}

	Common::Array<uint16> accelResources = library._archive->getResourceIDList(ID_ACEL);
	for (uint i = 0; i < accelResources.size(); i++) {
		Common::SeekableReadStream *stream = library._archive->getResource(ID_ACEL, accelResources[i]);
		KeyboardHandler handler;
		handler.keyId = stream->readUint16LE();
		handler.modifierId = stream->readUint16LE();
		handler.scriptId = stream->readUint16LE();
		newLib._keyboardHandlers.push_back(handler);
	}

	Common::Array<uint16> randResources = library._archive->getResourceIDList(ID_RAND);
	for (uint i = 0; i < randResources.size(); i++) {
		Common::SeekableReadStream *stream = library._archive->getResource(ID_RAND, randResources[i]);
		Common::Array<RandomEvent> &events = _randomEvents[randResources[i]];
		uint16 count = stream->readUint16LE();
		for (uint j = 0; j < count; j++) {
			RandomEvent random;
			random.scriptId = stream->readUint16LE();
			random.weight = stream->readUint16LE();
			events.push_back(random);
		}
		delete stream;
	}

	// add background sprite, if it exists
	if (hasResource(ID_BMAP, 1000))
		setBackground(1000);

	// TODO: better CTBL logic
	loadCTBL(1000, 100);

	// Run the startup script.
	runScript(1000, 0, 0, 0);

	_mouseEnabled = true;
	onMouseMove(_lastMousePos);

	runEvent(kEventLoad, id, 0, 0);
}
Ejemplo n.º 13
0
e_scriptresult TScript::loadScript2(QString includeFile, QString parent)
{
    QString fn = filename;
    if (includeFile.isEmpty()) {
        qDebug() << "Running loadScript() on" << filename;
        scriptstr.clear();
        errorKeyword.clear();
        curLine = 1;
        loadIntLine = 1;
        include.clear();
        command.clear();
        tevent.clear();
        lineMap.clear();

        QHashIterator<QString,TCustomScriptDialog*> i(dialogs);
        while (i.hasNext()) {
            i.next();
            delete i.value();
        }
        dialogs.clear();

    }
    else {
        fn = setRelativePath(parent, includeFile);
        qDebug() << "Including" << fn;
    }

    qDebug() << "attempt:" << fn;

    if (QFile::exists(fn) == false)
    return se_FileNotExist;

    QFile f(fn);
    bool fo = f.open(QIODevice::ReadOnly | QIODevice::Text);
    if (fo == false)
        return se_FileCannotOpen;

    QString ba = f.readAll();
    if (ba.length() < 1)
        return se_FileEmpty;

    // Remove comments, keep newlines:
    QString tmp;
    bool isCommented = false;

    QString lineFile = includeFile;
    if (lineFile.isEmpty())
        lineFile = filename;

    int cLine = 1;

    for (int i = 0; i <= ba.length()-1; ++i) {
        QChar c = ba[i];

        if (c == '\n') { // newline
            delWhitespace(&tmp);

            lineMap.insert(loadIntLine, QString("%1:%2")
                                          .arg(cLine)
                                          .arg(lineFile)
                           );

            if (tmp.length() > 0) {
                scriptstr.push_back(tmp + '\n');
                loadIntLine++;
            }

            cLine++;

            isCommented = false;
            tmp.clear();
            continue;
        }

        if (isCommented) // part of a comment, ignore.
            continue;

        if (c == ';') { // comment, skip anything after.
            isCommented = true;
            continue;
        }

        tmp.append(c);
    }

    if (tmp.length() > 0) // insert anything missing from very last line.
        scriptstr.push_back(tmp + '\n');

    // This was an include, the first instance of loadScript() will take care of retreiving the rest.
    if (includeFile.length() > 0)
        return se_None;


    // Search script for functions and parse the meta.
    QString keyword;
    bool getKeyword = true; // Always begin with getting keyword.
    bool comment = false;

    enum { // Expecting
        ex_Unknown = 0, // If we use this we must pose an error too.
        ex_Block,
        ex_Brace,
        ex_Statement,
        ex_Ignore, // ignore until next block (still handles nesting levels)
        ex_Include = 5,
        ex_Command,
        ex_Event,
        ex_Timer,
        ex_ScriptName,
        ex_FunctionName = 10,
        ex_MenuType,
        ex_MenuTitle,
        ex_MenuFunction,
        ex_DialogName,
        ex_DialogTitle = 15,
        ex_DialogGeometry,
        ex_DialogEmbed,
        ex_DialogIcon,
        ex_DialogLabel,
        ex_DialogButton = 20,
        ex_DialogEditBox,
        ex_DialogTextBox,
        ex_DialogListBox,
        ex_DialogPaint,
        ex_DialogText = 25
    };

    enum {
        st_None = 0, // used when waiting for block name keyword
        st_Meta,
        st_Function,
        st_Menu,
        st_Dialog
    };

    int state = st_None;
    int ex = ex_Block; // We expect to find a script block to begin with. either function, script or menu.
    int n = 0; // Nesting level. 0 is where script blocks are at (script, function, menu, etc.)

    QString temp[3];
    TCustomScriptDialog *dialog = NULL;

    // Reset the custom menues, they'll be set up later on in here...
    resetMenu(customNicklistMenu);
    resetMenu(customChannelMenu);
    resetMenu(customQueryMenu);
    resetMenu(customStatusMenu);

    fnindex.clear(); // re-load function index

    for (int i = 0; i <= scriptstr.length()-1; ++i) {
        QChar cc = scriptstr[i];

        errorKeyword = keyword + cc;

        if (cc == '\n')
            curLine++;

        if (ex != ex_Ignore) {
            if (cc == '\\') { // Escape, skip completely and add to keyword
                if ((i == scriptstr.length()-1) || (scriptstr[i+1] == '\n'))
                    return se_EscapeOnEndLine;

                keyword += scriptstr[i+1];
                i++;
                continue;
            }

            /* Comment handling */
            /* Put ; anywhere but must end with newline. */
            if (cc == '\n')
                comment = false;
            if (comment)
                continue;
            if (cc == ';') {
                comment = true;
                continue;
            }
            /* **************** */
        }



        if (cc == '{') {
            if ((ex != ex_Brace) && (ex != ex_Ignore) && (n == 0))
                return se_UnexpectedToken;
            n++;
        }
        if (cc == '}') {
            if (n == 0)
                return se_UnexpectedToken;

            n--;

            if (state == st_Dialog) {
                dialogs.insert( dialog->getName(), dialog );
                connect(dialog, SIGNAL(runEvent(e_iircevent,QStringList)),
                this, SLOT(runEvent(e_iircevent,QStringList)));
                state = st_None;
            }

            if (n == 0)
            ex = ex_Block;
        }

        if (ex == ex_Brace) {
            if ((cc != ' ') && (cc != '\t') && (cc != '\n') && (cc != '{') && (cc != '}'))
                return se_UnexpectedToken;

            if ((cc == ' ') || (cc == '\t') || (cc == '\n'))
                continue;

            ex = ex_Statement;
            continue;
        }

        if (cc == '}')
            continue;

        if (ex == ex_FunctionName) {
            // Stop this one at (
            // If we encounter \n first, pose error.

            if (cc == '\n')
                return se_UnexpectedNewline;
            if (i == scriptstr.length()-1)
                return se_UnexpectedFinish;

            if (cc == '(') {
                fnindex.insert(keyword.toUpper(), i);
                ex = ex_Ignore;
                continue;
            }

            if (cc == ' ') {
                QChar cc2 = scriptstr[i+1];
                if (cc2 == '(')
                    continue;
                else
                    return se_UnexpectedToken;
            }
        }

        // Newline, receiving keyword but keyword got is none. ignore.
        if ((cc == '\n') && (getKeyword == true) && (keyword.length() == 0))
            continue;

        // Newline, space receiving keyword and got a keyword. parse.
        if (((cc == '\n') || (cc == ' ')) && (getKeyword == true) && (keyword.length() >= 0)) {
            QString keywup = keyword.toUpper();

            if (n == 0) { // Here we always expect script blocks.
                if (ex == ex_Block) {

                    if (keywup == "SCRIPT") {
                        ex = ex_ScriptName;
                        state = st_Meta;
                        keyword.clear();
                        continue;
                    }

                    else if (keywup == "META") {
                        ex = ex_Brace;
                        state = st_Meta;
                        keyword.clear();
                        continue;
                    }

                    else if (keywup == "FUNCTION") {
                        ex = ex_FunctionName;
                        state = st_Function;
                        keyword.clear();
                        continue;
                    }

                    else if (keywup == "MENU") {
                        ex = ex_MenuType;
                        state = st_Menu;
                        keyword.clear();
                        continue;
                    }

                    else if (keywup == "DIALOG") {
                        ex = ex_DialogName;
                        state = st_Dialog;
                        keyword.clear();
                        continue;
                    }

                    else
                        return se_InvalidBlockType;
                }

                if (ex == ex_ScriptName) {
                    name = keyword;
                    ex = ex_Brace;
                    keyword.clear();
                    continue;
                }

                if (ex == ex_DialogName) {
                    dialog =  new TCustomScriptDialog(this, keyword, dlgParent);
                    ex = ex_Brace;
                    keyword.clear();
                    continue;
                }

                if (ex == ex_MenuType) {
                    temp[0] = keyword.toUpper();
                    state = st_Menu;
                    ex = ex_Brace;
                    continue;
                }

            }

            if (n > 0) {

                if (state == st_Meta) {

                    if (ex == ex_Statement) {
                        keyword.clear(); // this is safe here.
                        if (keywup == "INCLUDE") {
                            ex = ex_Include;
                            continue;
                        }
                        else if (keywup == "COMMAND") {
                            ex = ex_Command;
                            continue;
                        }
                        else if (keywup == "EVENT") {
                            ex = ex_Event;
                            continue;
                        }
                        else if (keywup == "TIMER") {
                            ex = ex_Timer;
                            continue;
                        }
                        else
                            return se_InvalidMetaCommand;
                    }

                    if (ex == ex_Include) {
                        if (cc == ' ') {
                            keyword += cc;
                            continue;
                        }
                        include.push_back(keyword);
                        e_scriptresult r = loadScript2(keyword, fn);
                        keyword.clear();
                        ex = ex_Statement;

                        if (r != se_None)
                            return r;

                        continue;
                    }

                    if ((ex == ex_Command) || (ex == ex_Event) || (ex == ex_Timer)) {

                        if (temp[0].length() == 0)
                            temp[0] = keyword; // command name
                        else
                            temp[1] = keyword; // function
                        keyword.clear();

                        if (((temp[0].length() == 0) || (temp[1].length() == 0)) && (cc == '\n'))
                            return se_UnexpectedNewline;

                        if (cc == '\n') {
                            // this one will run if both temp are filled.

                            if (ex == ex_Command)
                            command.insert(temp[0].toUpper(), temp[1]);

                            if (ex == ex_Event) {
                                e_iircevent evt = getEvent(temp[0]);

                                if (evt == te_noevent)
                                    return se_InvalidEvent;

                                tevent.insertMulti(evt, temp[1]);
                            }


                            if (ex == ex_Timer) {
                                if (timers.contains(temp[0].toUpper()) == true)
                                    goto loadScript__ex_TimerAdd_Cleanup;


                                TTimer *tmr = new TTimer(temp[1].toUpper(), this);
                                connect(tmr, SIGNAL(timeout(QString)),
                                this, SLOT(timerTimeout(QString)));

                                timers.insert(temp[0].toUpper(), tmr);
                            }

                            loadScript__ex_TimerAdd_Cleanup:

                            ex = ex_Statement;
                            temp[0].clear();
                            temp[1].clear();

                            keyword.clear();
                            continue;
                        }

                        keyword.clear();
                        continue;
                    }

                }

                if (state == st_Dialog) {

                    if (ex == ex_Statement) {
                        keyword.clear();

                        if (keywup == "TITLE")
                            ex = ex_DialogTitle;

                        else if (keywup == "GEOMETRY")
                            ex = ex_DialogGeometry;

                        else if (keywup == "EMBED") {
                            // embed c|l|p|s
                            // channel, listbox, pm, status
                            ex = ex_DialogEmbed;
                        }

                        else if (keywup == "PAINT") {
                            // paint @wname x y w h
                        }

                        else if (keywup == "TEXT") {
                            // text @name x y w h
                        }

                        else if (keywup == "LABEL")
                            ex = ex_DialogLabel;

                        else if (keywup == "BUTTON")
                            ex = ex_DialogButton;

                        else if (keywup == "EDITBOX")
                            ex = ex_DialogEditBox;

                        else if (keywup == "TEXTBOX")
                            ex = ex_DialogTextBox;

                        else if (keywup == "LISTBOX")
                            ex = ex_DialogListBox;

                        else
                            return se_UnexpectedToken;

                        continue;
                    }

                    if (ex == ex_DialogTitle) {
                        for (; i <= scriptstr.length()-1; i++) {
                            QChar c = scriptstr[i];
                            if (c == '\n')
                                break;
                            keyword += c;
                        }
                        dialog->setTitle(keyword);
                        keyword.clear();
                        ex = ex_Statement;
                        continue;
                    }

                    if (ex == ex_DialogGeometry) {
                        int param = 2; // 1X 2Y 3W 4H
                        int X, Y, W, H;
                        X = keyword.toInt();
                        keyword.clear();
                        for (i++; i <= scriptstr.length()-1; i++) {
                            QChar c = scriptstr[i];

                            if ((c == ' ') || (c == '\n')) {
                                if (param == 2)
                                    Y = keyword.toInt();
                                if (param == 3)
                                    W = keyword.toInt();
                                if (param == 4)
                                    H = keyword.toInt();
                                keyword.clear();
                                param++;
                            }

                            if (c == '\n')
                                break;


                            if (param == 5)
                                break;

                            keyword += c;
                        }

                        if (param != 5)
                            return se_InvalidParamCount;

                        dialog->setGeometry(X, Y, W, H);
                        keyword.clear();
                        ex = ex_Statement;
                        continue;
                    }
                    
                    if (ex == ex_DialogEmbed) {
                        
                    }

                    if (ex >= ex_DialogLabel) {
                        int param = 2;
                        int X, Y, W, H = 0;
                        QString oname = keyword;
                        QString arg;
                        keyword.clear();
                        for (i++; i <= scriptstr.length()-1; i++) {
                            QChar c = scriptstr[i];

                            if (param < 6) {
                                if ((c == ' ') || (c == '\n')) {
                                    if (param == 2)
                                        X = keyword.toInt();
                                    if (param == 3)
                                        Y = keyword.toInt();
                                    if (param == 4)
                                        W = keyword.toInt();
                                    if (param == 5)
                                        H = keyword.toInt();
                                    keyword.clear();
                                    param++;
                                }

                            }
                            if (c == '\n')
                                break;

                            if (param >= 6)
                                arg += c;
                            else
                                keyword += c;
                        }

                        if (param != 6)
                            return se_InvalidParamCount;

                        arg = arg.mid(1);


                        if (ex == ex_DialogLabel)
                            dialog->addLabel(oname, X, Y, W, H, arg);

                        if (ex == ex_DialogButton)
                            dialog->addButton(oname, X, Y, W, H, arg);

                        if (ex == ex_DialogEditBox)
                            dialog->addEditbox(oname, X, Y, W, H);

                        if (ex == ex_DialogTextBox)
                            dialog->addTextbox(oname, X, Y, W, H);

                        if (ex == ex_DialogListBox)
                            dialog->addListbox(oname, X, Y, W, H);


                        keyword.clear();
                        ex = ex_Statement;
                        continue;
                    }

                }

                if (state == st_Menu) {
                    if (ex == ex_Statement) {
                        if (temp[0] == "NICKLIST")
                            createMenu(i, 'n');
                        if (temp[0] == "CHANNEL")
                            createMenu(i, 'c');
                        if (temp[0] == "QUERY")
                            createMenu(i, 'q');
                        if (temp[0] == "STATUS")
                            createMenu(i, 's');

                        --i;
                        temp[0].clear();
                        state = st_None;
                        ex = ex_Brace;
                    }
                }
            }

            keyword.clear();

            continue;
        }

        keyword += cc;
    }

    if (n > 0)
    return se_UnexpectedFinish;

    qDebug() << "Script" << name << "(re)loaded with:";
    qDebug() << " -" << fnindex.count() << "functions.";
    qDebug() << " -" << tevent.count() << "events.";
    qDebug() << " -" << include.count() << "includes.";
    qDebug() << " -" << command.count() << "commands.";
    qDebug() << " -" << timers.count() << "timers.";
    qDebug() << " -" << dialogs.count() << "dialogs.";
    qDebug() << "---";

    return se_None;
}
Ejemplo n.º 14
0
void fillHistos(TTree* tree, 
                TH1F *hMass, 
                TH1F *hPt,
                TH1F *hPt20B,
                TH1F *hRapidity,
                TH1F *hVertex,
                double mLow,
                double mHigh,
                double ptLow,
                double ptHigh,
                int mode) {

  
  typedef std::pair<int,int> pairOfInt;
  set<pairOfInt> uniqueSelectedEvents;

  typedef std::pair<int,int> pairOfInt;
  set<pairOfInt> uniqueEventsReco;


  _EventInfo eventInfo;
  tree->SetBranchAddress("eventInfo", &eventInfo);

  _MuonInfo reco1, reco2;

  tree->SetBranchAddress("reco1", &reco1);
  tree->SetBranchAddress("reco2", &reco2);

  float recoCandMass, recoCandPt, recoCandY;

  tree->SetBranchAddress("recoCandMass", &recoCandMass);
  tree->SetBranchAddress("recoCandPt"  , &recoCandPt );
  tree->SetBranchAddress("recoCandY"  ,  &recoCandY );

  float vertexNormChiSquare, angleDiMuons;

  tree->SetBranchAddress("vertexNormChiSquare", &vertexNormChiSquare);
  tree->SetBranchAddress("angleDiMuons"       , &angleDiMuons );

  _VertexInfo vertexInfo;
  tree->SetBranchAddress("vertexInfo", &vertexInfo);

  cout<<"Loop over the " << tree->GetEntries() << " entries ...\n";
  for (int iEvt=0; iEvt < tree->GetEntries(); iEvt++) {
 
    if ( (iEvt % 500000)==0 ) cout << "event " << iEvt << endl;
    tree -> GetEntry(iEvt);

    // additional selection cuts
    if (reco1.charge == reco2.charge) continue;

    if (recoCandMass <  mLow) continue;
    if (recoCandMass > mHigh) continue;

     if (reco1.pt < 20 || reco2.pt < 20) continue;
     
     if (fabs(reco1.eta) > 2.1 || fabs(reco2.eta) > 2.1) continue;

       //if (vertexNormChiSquare > 10) continue; 
     if (angleDiMuons > TMath::Pi()-0.02) continue;

    // both muons tight
    //if( !isKinTight_2012WZ(reco1) || !isKinTight_2012WZ(reco2) ) continue; 
     if( !isKinTight_2012(reco1) || !isKinTight_2012(reco2) ) continue; 

     if( !reco1.isHltMatched[0] && !reco2.isHltMatched[0]) continue; 
   
    // remove duplicates
    pairOfInt runEvent(eventInfo.run,eventInfo.event);
    if( !uniqueEventsReco.insert( runEvent ).second ) continue;

    hMass     -> Fill( recoCandMass); 
    hPt       -> Fill( recoCandPt );
    hPt20B     -> Fill( recoCandPt );
    hRapidity -> Fill( recoCandY );
    hVertex   -> Fill( vertexInfo.nVertices );
    /*
    if ( recoCandPt > 200 ){
    
     cout  << "run = "   << eventInfo.run      << "  " 
           << "event = " << eventInfo.event    << "  "
           << "lumi = "  << eventInfo.lumi     << " "
           << "Mass(dimuon) = " << recoCandMass << " "
           << "Pt(dimuon) = " << recoCandPt     << std::endl; }
    */
      
  
  }


  std::cout << " DONE!" << std::endl;
  return;
}