bool Events::delay(uint32 time, bool interruptable) { // Different handling for really short versus extended times if (time < 10) { // For really short periods, simply delay by the desired amount pollEvents(); g_system->delayMillis(time); bool result = !(interruptable && (kbHit() || _pressed || _vm->shouldQuit())); clearEvents(); return result; } else { // For long periods go into a loop where we delay by 10ms at a time and then // check for events. This ensures for longer delays that responsiveness is // maintained uint32 delayEnd = g_system->getMillis() + time; while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd) { pollEventsAndWait(); if (interruptable && (kbHit() || _mouseButtons)) { clearEvents(); return false; } } return !_vm->shouldQuit(); } }
MapIso::MapIso(SDL_Surface *_screen, CampaignManager *_camp) { screen = _screen; camp = _camp; // cam(x,y) is where on the map the camera is pointing // units found in Settings.h (UNITS_PER_TILE) cam.x = 0; cam.y = 0; new_music = false; clearEvents(); enemy_awaiting_queue = false; npc_awaiting_queue = false; clearEnemy(new_enemy); clearNPC(new_npc); sfx = NULL; sfx_filename = ""; music = NULL; log_msg = ""; shaky_cam_ticks = 0; // spawn is a special map that defines where the campaign begins // load("spawn.txt"); }
Keyboard::Keyboard() { SDL_GetKeyboardState(&m_numKeys); m_justPressedKeys = new bool[m_numKeys]; m_justReleasedKeys = new bool[m_numKeys]; clearEvents(); }
MapIso::MapIso(SDL_Surface *_screen, CampaignManager *_camp, InputState *_inp, FontEngine *_font) { inp = _inp; screen = _screen; camp = _camp; font = _font; tip = new MenuTooltip(font, screen); // cam(x,y) is where on the map the camera is pointing // units found in Settings.h (UNITS_PER_TILE) cam.x = 0; cam.y = 0; new_music = false; clearEvents(); enemy_awaiting_queue = false; npc_awaiting_queue = false; clearEnemy(new_enemy); clearNPC(new_npc); sfx = NULL; sfx_filename = ""; music = NULL; log_msg = ""; shaky_cam_ticks = 0; }
bool EventsManager::isKeyMousePressed() { bool result = _leftButton || _rightButton || isKeyPending(); debounceMouse(); clearEvents(); return result; }
void update(Window& window) noexcept { sf::Event event; clearEvents(); while(window.pollEvent(event)) { pushEvents(event); } }
// Simple setting and getting of properties for scripts and the set command. stError *cUObject::setProperty( const QString &name, const cVariant &value ) { changed( SAVE|TOOLTIP ); SET_STR_PROPERTY( "bindmenu", bindmenu_ ) else SET_INT_PROPERTY( "serial", serial_ ) else SET_INT_PROPERTY( "multi", multis_ ) else SET_BOOL_PROPERTY( "free", free ) else SET_STR_PROPERTY( "name", this->name_ ) else if( name == "pos" ) { Coord_cl pos; if( !parseCoordinates( value.toString(), pos ) ) PROPERTY_ERROR( -3, QString( "Invalid coordinate value: '%1'" ).arg( value.toString() ) ) moveTo( pos ); return 0; } // Trying to set new Eventlist else if( name == "eventlist" ) { clearEvents(); QStringList list = QStringList::split( ",", value.toString() ); for( QStringList::const_iterator it = list.begin(); it != list.end(); ++it ) { WPDefaultScript *script = ScriptManager->find( *it ); if( script ) addEvent( script ); else PROPERTY_ERROR( -3, QString( "Script not found: '%1'" ).arg( *it ) ) } return 0; }
EventsMngr::EventsMngr() { m_ParseVault = NULL; m_ParseVaultSize = 0; m_ParseMsgType = -1; m_ReadVault = NULL; m_ReadVaultSize = 0; m_ReadPos = -1; m_ReadMsgType = -1; clearEvents(); }
/*! Removes an event handler from the object */ void cUObject::removeEvent( const QString& name ) { cPythonScript *event = 0; if( scriptChain && hasEvent( name ) ) { unsigned int count = reinterpret_cast< unsigned int >( scriptChain[0] ); if( count == 1 ) { clearEvents(); } else { unsigned int pos = 1; cPythonScript **newScriptChain = new cPythonScript*[ count ]; newScriptChain[0] = reinterpret_cast< cPythonScript* >( count - 1 ); for( unsigned int i = 1; i < count; ++i ) { if( scriptChain[i]->name() != name ) { newScriptChain[pos++] = scriptChain[i]; } else { event = scriptChain[i]; } } delete [] scriptChain; scriptChain = newScriptChain; } } if( eventList_ != QString::null ) { QStringList eventList = QStringList::split( ",", eventList_ ); eventList.remove( name ); eventList_ = eventList.join( "," ); if( eventList_.isEmpty() ) eventList_ = QString::null; } changed_ = true; if (event && event->canHandleEvent(EVENT_ATTACH)) { PyObject *args = Py_BuildValue("(N)", getPyObject()); event->callEvent(EVENT_ATTACH, args); Py_DECREF(args); } }
void OMXMLReaderExpat::reset() { TRACE("OMXMLReaderExpat::reset"); XML_ParserFree(_parser); if (_workBuffer != 0) { delete [] _workBuffer; } OMListIterator<OMXMLAttribute*> iter(_attributes, OMBefore); while (++iter) { delete iter.value(); } _attributes.clear(); OMUInt32 elementCount = _startNmspaceDecls.count(); for (OMUInt32 i = 0; i < elementCount; i++) { delete _startNmspaceDecls.getAt(i); } _startNmspaceDecls.clear(); _endNmspaceDecls.clear(); clearEvents(); _parser = XML_ParserCreateNS(0, NAMESPACE_SEPARATOR); XML_SetNotationDeclHandler(_parser, ::expat_NotationDeclHandler); XML_SetEntityDeclHandler(_parser, ::expat_EntityDeclHandler); XML_SetStartNamespaceDeclHandler(_parser, ::expat_StartNamespaceDeclHandler); XML_SetEndNamespaceDeclHandler(_parser, ::expat_EndNamespaceDeclHandler); XML_SetStartElementHandler(_parser, ::expat_StartElementHandler); XML_SetEndElementHandler(_parser, ::expat_EndElementHandler); XML_SetCharacterDataHandler(_parser, ::expat_CharacterDataHandler); XML_SetUserData(_parser, this); _workBuffer = new wchar_t[WORK_BUFFER_MIN_SIZE]; _workBufferSize = WORK_BUFFER_MIN_SIZE; _readNextChunk = true; _status = true; _numInBuffer = 0; _xmlStream->setPosition(0); }
int __attribute__((noreturn)) main(void) { uint16_t idlePolls = 0; /* initialize */ wdt_disable(); /* main app may have enabled watchdog */ tiny85FlashInit(); bootLoaderInit(); if (bootLoaderCondition()) { initForUsbConnectivity(); do { usbPoll(); _delay_us(100); idlePolls++; if (events) idlePolls = 0; // these next two freeze the chip for ~ 4.5ms, breaking usb protocol // and usually both of these will activate in the same loop, so host // needs to wait > 9ms before next usb request if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication(); if (isEvent(EVENT_WRITE_PAGE)) tiny85FlashWrites(); if (isEvent(EVENT_FINISH)) { // || AUTO_EXIT_CONDITION()) { tiny85FinishWriting(); # if BOOTLOADER_CAN_EXIT _delay_ms(10); // removing delay causes USB errors break; # endif } // # if BOOTLOADER_CAN_EXIT // // exit if requested by the programming app, or if we timeout waiting for the pc with a valid app // if (isEvent(EVENT_EXIT_BOOTLOADER) || AUTO_EXIT_CONDITION()) { // //_delay_ms(10); // break; // } // # endif clearEvents(); } while(bootLoaderCondition()); /* main event loop */ } leaveBootloader(); }
int Map::load(std::string fname) { FileParser infile; maprow *cur_layer = NULL; clearEvents(); clearLayers(); clearQueues(); // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemies.push(Map_Enemy()); else if (infile.section == "enemygroup") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile, &cur_layer); else if (infile.section == "enemy") loadEnemy(infile); else if (infile.section == "enemygroup") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); return 0; }
MapRenderer::~MapRenderer() { if (music != NULL) { Mix_HaltMusic(); Mix_FreeMusic(music); } tip_buf.clear(); clearLayers(); clearEvents(); clearQueues(); delete tip; /* unload sounds */ snd->reset(); while (!sids.empty()) { snd->unload(sids.back()); sids.pop_back(); } }
// Simple setting and getting of properties for scripts and the set command. stError *cUObject::setProperty( const QString &name, const cVariant &value ) { changed( TOOLTIP ); changed_ = true; // \property object.bindmenu This string property contains a comma separated list of context menu ids for this object. SET_STR_PROPERTY( "bindmenu", bindmenu_ ) // \rproperty object.serial This integer property contains the serial for this object. Read Only else SET_INT_PROPERTY( "serial", serial_ ) // \property object.multi This integer property contains the serial of the multi object this object is in. else SET_INT_PROPERTY( "multi", multis_ ) // \property object.direction This is the integer direction of this object. else SET_INT_PROPERTY( "direction", dir_ ) // \property object.free This boolean property indicates that the object has been freed and is awaiting deletion. else SET_BOOL_PROPERTY( "free", free ) // \property object.name This string property contains the name of the object. else SET_STR_PROPERTY( "name", this->name_ ) // \property object.pos This string property is the string representation of the position of the object. else if( name == "pos" ) { Coord_cl pos; if( !parseCoordinates( value.toString(), pos ) ) PROPERTY_ERROR( -3, QString( "Invalid coordinate value: '%1'" ).arg( value.toString() ) ) moveTo( pos ); return 0; } // \property object.pos This string property contains a comma separated list of the names of the scripts that are assigned to this object. else if( name == "eventlist" ) { clearEvents(); QStringList list = QStringList::split( ",", value.toString() ); for( QStringList::const_iterator it = list.begin(); it != list.end(); ++it ) { cPythonScript *script = ScriptManager::instance()->find( (*it).latin1() ); if( script ) addEvent( script ); else PROPERTY_ERROR( -3, QString( "Script not found: '%1'" ).arg( *it ) ) } return 0; }
OMXMLReaderExpat::OMXMLReaderExpat(OMRawStorage* xmlStream) : _appendData(false), _xmlStream(xmlStream), _parser(0) { TRACE("OMXMLReaderExpat::OMXMLReaderExpat"); clearEvents(); _parser = XML_ParserCreateNS(0, NAMESPACE_SEPARATOR); XML_SetNotationDeclHandler(_parser, ::expat_NotationDeclHandler); XML_SetEntityDeclHandler(_parser, ::expat_EntityDeclHandler); XML_SetStartNamespaceDeclHandler(_parser, ::expat_StartNamespaceDeclHandler); XML_SetEndNamespaceDeclHandler(_parser, ::expat_EndNamespaceDeclHandler); XML_SetStartElementHandler(_parser, ::expat_StartElementHandler); XML_SetEndElementHandler(_parser, ::expat_EndElementHandler); XML_SetCharacterDataHandler(_parser, ::expat_CharacterDataHandler); XML_SetUserData(_parser, this); _workBuffer = new wchar_t[WORK_BUFFER_MIN_SIZE]; _workBufferSize = WORK_BUFFER_MIN_SIZE; _readNextChunk = true; _status = true; _numInBuffer = 0; }
BSDSocketEvents::~BSDSocketEvents() { clearEvents(); }
int main(void) { /* initialize */ #ifdef RESTORE_OSCCAL uint8_t osccal_default = OSCCAL; #endif #if (!SET_CLOCK_PRESCALER) && LOW_POWER_MODE uint8_t prescaler_default = CLKPR; #endif wdt_disable(); /* main app may have enabled watchdog */ tiny85FlashInit(); bootLoaderInit(); if (bootLoaderStartCondition()) { #if LOW_POWER_MODE // turn off clock prescalling - chip must run at full speed for usb // if you might run chip at lower voltages, detect that in bootLoaderStartCondition CLKPR = 1 << CLKPCE; CLKPR = 0; #endif initForUsbConnectivity(); do { usbPoll(); _delay_us(100); idlePolls++; // these next two freeze the chip for ~ 4.5ms, breaking usb protocol // and usually both of these will activate in the same loop, so host // needs to wait > 9ms before next usb request if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication(); if (isEvent(EVENT_WRITE_PAGE)) tiny85FlashWrites(); # if BOOTLOADER_CAN_EXIT if (isEvent(EVENT_EXECUTE)) { // when host requests device run uploaded program break; } # endif clearEvents(); } while(bootLoaderCondition()); /* main event loop runs so long as bootLoaderCondition remains truthy */ } // set clock prescaler to desired clock speed (changing from clkdiv8, or no division, depending on fuses) #if LOW_POWER_MODE #ifdef SET_CLOCK_PRESCALER CLKPR = 1 << CLKPCE; CLKPR = SET_CLOCK_PRESCALER; #else CLKPR = 1 << CLKPCE; CLKPR = prescaler_default; #endif #endif // slowly bring down OSCCAL to it's original value before launching in to user program #ifdef RESTORE_OSCCAL while (OSCCAL > osccal_default) { OSCCAL -= 1; } #endif leaveBootloader(); }
EventsMngr::~EventsMngr() { clearEvents(); }
CTournament::~CTournament() { clearEvents(); delete state_; state_ = NULL; }
/** * load */ int MapIso::load(string filename) { FileParser infile; string val; string cur_layer; string data_format; clearEvents(); event_count = 0; if (infile.open(("maps/" + filename).c_str())) { while (infile.next()) { if (infile.new_section) { data_format = "dec"; // default if (enemy_awaiting_queue) { enemies.push(new_enemy); enemy_awaiting_queue = false; } if (npc_awaiting_queue) { npcs.push(new_npc); npc_awaiting_queue = false; } // for sections that are stored in collections, add a new object here if (infile.section == "enemy") { clearEnemy(new_enemy); enemy_awaiting_queue = true; } else if (infile.section == "npc") { clearNPC(new_npc); npc_awaiting_queue = true; } else if (infile.section == "event") { event_count++; } } if (infile.section == "header") { if (infile.key == "title") { this->title = infile.val; } else if (infile.key == "width") { this->w = atoi(infile.val.c_str()); } else if (infile.key == "height") { this->h = atoi(infile.val.c_str()); } else if (infile.key == "tileset") { this->tileset = infile.val; } else if (infile.key == "music") { if (this->music_filename == infile.val) { this->new_music = false; } else { this->music_filename = infile.val; this->new_music = true; } } else if (infile.key == "spawnpoint") { val = infile.val + ","; spawn.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; spawn.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; spawn_dir = eatFirstInt(val, ','); } } else if (infile.section == "layer") { if (infile.key == "id") { cur_layer = infile.val; } else if (infile.key == "format") { data_format = infile.val; } else if (infile.key == "data") { // layer map data handled as a special case // The next h lines must contain layer data. TODO: err if (data_format == "hex") { for (int j=0; j<h; j++) { val = infile.getRawLine() + ','; for (int i=0; i<w; i++) { if (cur_layer == "background") background[i][j] = eatFirstHex(val, ','); else if (cur_layer == "object") object[i][j] = eatFirstHex(val, ','); else if (cur_layer == "collision") collision[i][j] = eatFirstHex(val, ','); } } } else if (data_format == "dec") { for (int j=0; j<h; j++) { val = infile.getRawLine() + ','; for (int i=0; i<w; i++) { if (cur_layer == "background") background[i][j] = eatFirstInt(val, ','); else if (cur_layer == "object") object[i][j] = eatFirstInt(val, ','); else if (cur_layer == "collision") collision[i][j] = eatFirstInt(val, ','); } } } } } else if (infile.section == "enemy") { if (infile.key == "type") { new_enemy.type = infile.val; } else if (infile.key == "spawnpoint") { val = infile.val + ","; new_enemy.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; new_enemy.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; new_enemy.direction = eatFirstInt(val, ','); } } else if (infile.section == "npc") { if (infile.key == "id") { new_npc.id = infile.val; } else if (infile.key == "position") { val = infile.val + ","; new_npc.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; new_npc.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; } } else if (infile.section == "event") { if (infile.key == "type") { events[event_count-1].type = infile.val; } else if (infile.key == "location") { val = infile.val + ","; events[event_count-1].location.x = eatFirstInt(val, ','); events[event_count-1].location.y = eatFirstInt(val, ','); events[event_count-1].location.w = eatFirstInt(val, ','); events[event_count-1].location.h = eatFirstInt(val, ','); } else { // new event component Event_Component *e = &events[event_count-1].components[events[event_count-1].comp_num]; e->type = infile.key; if (infile.key == "intermap") { val = infile.val + ","; e->s = eatFirstString(val, ','); e->x = eatFirstInt(val, ','); e->y = eatFirstInt(val, ','); } else if (infile.key == "mapmod") { val = infile.val + ","; e->s = eatFirstString(val, ','); e->x = eatFirstInt(val, ','); e->y = eatFirstInt(val, ','); e->z = eatFirstInt(val, ','); } else if (infile.key == "soundfx") { e->s = infile.val; } else if (infile.key == "loot") { val = infile.val + ","; e->s = eatFirstString(val, ','); e->x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; e->y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; e->z = eatFirstInt(val, ','); } else if (infile.key == "msg") { e->s = infile.val; } else if (infile.key == "shakycam") { e->x = atoi(infile.val.c_str()); } else if (infile.key == "requires_status") { e->s = infile.val; } else if (infile.key == "requires_not") { e->s = infile.val; } else if (infile.key == "requires_item") { e->x = atoi(infile.val.c_str()); } else if (infile.key == "set_status") { e->s = infile.val; } else if (infile.key == "unset_status") { e->s = infile.val; } else if (infile.key == "remove_item") { e->x = atoi(infile.val.c_str()); } else if (infile.key == "reward_xp") { e->x = atoi(infile.val.c_str()); } events[event_count-1].comp_num++; } } } infile.close(); // reached end of file. Handle any final sections. if (enemy_awaiting_queue) { enemies.push(new_enemy); enemy_awaiting_queue = false; } if (npc_awaiting_queue) { npcs.push(new_npc); npc_awaiting_queue = false; } } collider.setmap(collision); collider.map_size.x = w; collider.map_size.y = h; if (this->new_music) { loadMusic(); this->new_music = false; } tset.load(this->tileset); return 0; }
//----[ destroy ]------------------------------------------------------------ void EventManager::destroy() { clearEvents(); special_fx_manager_ = NULL; }
EventQueue::~EventQueue() { clearEvents(); }
/** * load */ int MapIso::load(string filename) { ifstream infile; string line; string starts_with; string section; string key; string val; string cur_layer; string data_format; clearEvents(); event_count = 0; infile.open(("maps/" + filename).c_str(), ios::in); if (infile.is_open()) { while (!infile.eof()) { line = getLine(infile); if (line.length() > 0) { starts_with = line.at(0); if (starts_with == "#") { // skip comments } else if (starts_with == "[") { section = trim(parse_section_title(line), ' '); data_format = "dec"; // default if (enemy_awaiting_queue) { enemies.push(new_enemy); enemy_awaiting_queue = false; } if (npc_awaiting_queue) { npcs.push(new_npc); npc_awaiting_queue = false; } // for sections that are stored in collections, add a new object here if (section == "enemy") { clearEnemy(new_enemy); enemy_awaiting_queue = true; } else if (section == "npc") { clearNPC(new_npc); npc_awaiting_queue = true; } else if (section == "event") { event_count++; } } else { // this is data. treatment depends on section type parse_key_pair(line, key, val); key = trim(key, ' '); val = trim(val, ' '); if (section == "header") { if (key == "title") { this->title = val; } else if (key == "width") { this->w = atoi(val.c_str()); } else if (key == "height") { this->h = atoi(val.c_str()); } else if (key == "tileset") { this->tileset = val; } else if (key == "music") { if (this->music_filename == val) { this->new_music = false; } else { this->music_filename = val; this->new_music = true; } } else if (key == "spawnpoint") { val = val + ","; spawn.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; spawn.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; spawn_dir = eatFirstInt(val, ','); } } else if (section == "layer") { if (key == "id") { cur_layer = val; } else if (key == "format") { data_format = val; } else if (key == "data") { // layer map data handled as a special case // The next h lines must contain layer data. TODO: err if (data_format == "hex") { for (int j=0; j<h; j++) { line = getLine(infile); line = line + ','; for (int i=0; i<w; i++) { if (cur_layer == "background") background[i][j] = eatFirstHex(line, ','); else if (cur_layer == "object") object[i][j] = eatFirstHex(line, ','); else if (cur_layer == "collision") collision[i][j] = eatFirstHex(line, ','); } } } else if (data_format == "dec") { for (int j=0; j<h; j++) { line = getLine(infile); line = line + ','; for (int i=0; i<w; i++) { if (cur_layer == "background") background[i][j] = eatFirstInt(line, ','); else if (cur_layer == "object") object[i][j] = eatFirstInt(line, ','); else if (cur_layer == "collision") collision[i][j] = eatFirstInt(line, ','); } } } } } else if (section == "enemy") { if (key == "type") { new_enemy.type = val; } else if (key == "spawnpoint") { val = val + ","; new_enemy.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; new_enemy.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; new_enemy.direction = eatFirstInt(val, ','); } } else if (section == "npc") { if (key == "id") { new_npc.id = val; } else if (key == "position") { val = val + ","; new_npc.pos.x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; new_npc.pos.y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; } } else if (section == "event") { if (key == "type") { events[event_count-1].type = val; } else if (key == "location") { val = val + ","; events[event_count-1].location.x = eatFirstInt(val, ','); events[event_count-1].location.y = eatFirstInt(val, ','); events[event_count-1].location.w = eatFirstInt(val, ','); events[event_count-1].location.h = eatFirstInt(val, ','); } else { // new event component Event_Component *e = &events[event_count-1].components[events[event_count-1].comp_num]; e->type = key; if (key == "intermap") { val = val + ","; e->s = eatFirstString(val, ','); e->x = eatFirstInt(val, ','); e->y = eatFirstInt(val, ','); } else if (key == "mapmod") { val = val + ","; e->s = eatFirstString(val, ','); e->x = eatFirstInt(val, ','); e->y = eatFirstInt(val, ','); e->z = eatFirstInt(val, ','); } else if (key == "soundfx") { e->s = val; } else if (key == "loot") { val = val + ","; e->s = eatFirstString(val, ','); e->x = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; e->y = eatFirstInt(val, ',') * UNITS_PER_TILE + UNITS_PER_TILE/2; e->z = eatFirstInt(val, ','); } else if (key == "msg") { e->s = val; } else if (key == "shakycam") { e->x = atoi(val.c_str()); } else if (key == "requires_status") { e->s = val; } else if (key == "requires_not") { e->s = val; } else if (key == "requires_item") { e->x = atoi(val.c_str()); } else if (key == "set_status") { e->s = val; } else if (key == "unset_status") { e->s = val; } else if (key == "remove_item") { e->x = atoi(val.c_str()); } else if (key == "reward_xp") { e->x = atoi(val.c_str()); } events[event_count-1].comp_num++; } } } } } // reached end of file. Handle any final sections. if (enemy_awaiting_queue) { enemies.push(new_enemy); enemy_awaiting_queue = false; } if (npc_awaiting_queue) { npcs.push(new_npc); npc_awaiting_queue = false; } } infile.close(); collider.setmap(collision); collider.map_size.x = w; collider.map_size.y = h; if (this->new_music) { loadMusic(); this->new_music = false; } tset.load(this->tileset); return 0; }
int Map::load(const std::string& fname) { FileParser infile; clearEvents(); clearLayers(); clearQueues(); music_filename = ""; collision_layer = -1; w = 1; h = 1; hero_pos_enabled = false; hero_pos.x = 0; hero_pos.y = 0; // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; logInfo("Map: Loading map '%s'", fname.c_str()); this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile); else if (infile.section == "enemy") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); // create StatBlocks for events that need powers for (unsigned i=0; i<events.size(); ++i) { Event_Component *ec_power = events[i].getComponent(EC_POWER); if (ec_power) { // store the index of this StatBlock so that we can find it when the event is activated ec_power->y = addEventStatBlock(events[i]); } } // ensure that our map contains a collision layer if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) { layernames.push_back("collision"); layers.resize(layers.size()+1); layers.back().resize(w); for (size_t i=0; i<layers.back().size(); ++i) { layers.back()[i].resize(h, 0); } collision_layer = static_cast<int>(layers.size())-1; } if (!hero_pos_enabled) { logError("Map: Hero spawn position (hero_pos) not defined in map header. Defaulting to (0,0)."); } return 0; }
void Input::handleKeyPress(const KeyboardReadReturnData& d) { //----------------------------------------MOVEMENT if(d.sdlKey_ == SDLK_RIGHT || d.key_ == '6') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); if(d.isShiftHeld_) { eng->player->moveDir(dirUpRight); } else if(d.isCtrlHeld_) { eng->player->moveDir(dirDownRight); } else { eng->player->moveDir(dirRight); } } clearEvents(); return; } else if(d.sdlKey_ == SDLK_DOWN || d.key_ == '2') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirDown); } clearEvents(); return; } else if(d.sdlKey_ == SDLK_LEFT || d.key_ == '4') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); if(d.isShiftHeld_) { eng->player->moveDir(dirUpLeft); } else if(d.isCtrlHeld_) { eng->player->moveDir(dirDownLeft); } else { eng->player->moveDir(dirLeft); } } clearEvents(); return; } else if(d.sdlKey_ == SDLK_UP || d.key_ == '8') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirUp); } clearEvents(); return; } else if(d.sdlKey_ == SDLK_PAGEUP || d.key_ == '9') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirUpRight); } clearEvents(); return; } else if(d.sdlKey_ == SDLK_PAGEUP || d.key_ == '3') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirDownRight); } clearEvents(); return; } else if(d.sdlKey_ == SDLK_PAGEUP || d.key_ == '1') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirDownLeft); } clearEvents(); return; } else if(d.sdlKey_ == SDLK_PAGEUP || d.key_ == '7') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirUpLeft); } clearEvents(); return; } else if(d.key_ == '5' || d.key_ == '.') { if(eng->player->deadState == actorDeadState_alive) { clearLogMessages(); eng->player->moveDir(dirCenter); if(eng->playerBonHandler->isBonPicked(playerBon_marksman)) { eng->player->getPropHandler()->tryApplyProp( new PropStill(eng, propTurnsSpecified, 1)); } } clearEvents(); return; } //----------------------------------------DESCEND else if(d.key_ == '>') { trace << "Input: User pressed '>'" << endl; clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { trace << "Input: Calling DungeonClimb::tryUseDownStairs()" << endl; eng->dungeonClimb->tryUseDownStairs(); } clearEvents(); return; } //----------------------------------------EXAMINE else if(d.key_ == 'a') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { if(eng->player->getPropHandler()->allowSee()) { eng->examine->playerExamine(); eng->renderer->drawMapAndInterface(); } else { eng->log->addMsg("Not while blind."); eng->renderer->drawMapAndInterface(); } } clearEvents(); return; } //----------------------------------------RELOAD else if(d.key_ == 'r') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->reload->reloadWieldedWpn(*(eng->player)); } clearEvents(); return; } //----------------------------------------BASH else if(d.key_ == 'b') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->bash->playerBash(); eng->renderer->drawMapAndInterface(); } clearEvents(); return; } //----------------------------------------CLOSE else if(d.key_ == 'c') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->close->playerClose(); eng->renderer->drawMapAndInterface(); } clearEvents(); return; } //----------------------------------------JAM else if(d.key_ == 'j') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->jamWithSpike->playerJam(); eng->renderer->drawMapAndInterface(); } clearEvents(); return; } //----------------------------------------DISARM // else if(d.key_ == 'd') { // clearLogMessages(); // if(eng->player->deadState == actorDeadState_alive) { // if(eng->player->getPropHandler()->allowSee()) { // eng->disarm->playerDisarm(); // eng->renderer->drawMapAndInterface(); // } else { // } // } // clearEvents(); // return; // } //----------------------------------------UNLOAD AMMO FROM GROUND else if(d.key_ == 'u') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->itemPickup->tryUnloadWeaponOrPickupAmmoFromGround(); } clearEvents(); return; } //----------------------------------------AIM/FIRE FIREARM else if(d.key_ == 'f') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { if(eng->player->getPropHandler()->allowAttackRanged(true)) { Item* const item = eng->player->getInventory()->getItemInSlot(slot_wielded); Weapon* wpn = NULL; if(item == NULL) { eng->log->addMsg("I am not wielding a weapon."); } else { wpn = dynamic_cast<Weapon*>(item); if( wpn->nrAmmoLoaded >= 1 || wpn->getData().rangedHasInfiniteAmmo ) { eng->marker->run(markerTask_aimRangedWeapon, NULL); } else if(eng->config->useRangedWpnAutoReload) { eng->reload->reloadWieldedWpn(*(eng->player)); } else { eng->log->addMsg("There is no ammo loaded."); } } } } clearEvents(); return; } //----------------------------------------GET else if(d.key_ == 'g') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { Item* const itemAtPlayer = eng->map->items[eng->player->pos.x][eng->player->pos.y]; if(itemAtPlayer != NULL) { if(itemAtPlayer->getData().id == item_trapezohedron) { eng->dungeonMaster->winGame(); *quitToMainMenu_ = true; } } if(*quitToMainMenu_ == false) { eng->itemPickup->tryPick(); } } clearEvents(); return; } //----------------------------------------SLOTS SCREEN else if(d.key_ == 'w') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->inventoryHandler->runSlotsScreen(); } clearEvents(); return; } //----------------------------------------INVENTORY else if(d.key_ == 'i') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->inventoryHandler->runBrowseInventoryMode(); } clearEvents(); return; } //----------------------------------------USE else if(d.key_ == 'e') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { if( eng->player->dynamiteFuseTurns > 0 || eng->player->flareFuseTurns > 0 || eng->player->molotovFuseTurns > 0) { eng->marker->run(markerTask_aimLitExplosive, NULL); } else { eng->inventoryHandler->runUseScreen(); } } clearEvents(); return; } //----------------------------------------SWAP TO PREPARED ITEM else if(d.key_ == 'z') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { const bool IS_FREE_TURN = false; //eng->playerBonHandler->isBonPicked(playerBon_nimble); const string swiftStr = IS_FREE_TURN ? " swiftly" : ""; Item* const itemWielded = eng->player->getInventory()->getItemInSlot(slot_wielded); Item* const itemAlt = eng->player->getInventory()->getItemInSlot(slot_wieldedAlt); const string ITEM_WIELDED_NAME = itemWielded == NULL ? "" : eng->itemDataHandler->getItemRef(*itemWielded, itemRef_a); const string ITEM_ALT_NAME = itemAlt == NULL ? "" : eng->itemDataHandler->getItemRef(*itemAlt, itemRef_a); if(itemWielded == NULL && itemAlt == NULL) { eng->log->addMsg("I have neither a wielded nor a prepared weapon."); } else { if(itemWielded == NULL) { eng->log->addMsg( "I" + swiftStr + " wield my prepared weapon (" + ITEM_ALT_NAME + ")."); } else { if(itemAlt == NULL) { eng->log->addMsg( "I" + swiftStr + " put away my weapon (" + ITEM_WIELDED_NAME + ")."); } else { eng->log->addMsg( "I" + swiftStr + " swap to my prepared weapon (" + ITEM_ALT_NAME + ")."); } } eng->player->getInventory()->swapWieldedAndPrepared(IS_FREE_TURN == false, eng); } } clearEvents(); return; } //----------------------------------------SEARCH (REALLY JUST A WAIT BUTTON) else if(d.key_ == 's') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { vector<Actor*> spotedEnemies; eng->player->getSpotedEnemies(spotedEnemies); if(spotedEnemies.empty()) { const int TURNS_TO_APPLY = 10; const string TURNS_STR = toString(TURNS_TO_APPLY); eng->log->addMsg("I pause for a while (" + TURNS_STR + " turns)."); eng->player->waitTurnsLeft = TURNS_TO_APPLY - 1; eng->gameTime->endTurnOfCurrentActor(); } else { eng->log->addMsg("Not while an enemy is near."); eng->renderer->drawMapAndInterface(); } } clearEvents(); return; } //----------------------------------------THROW ITEM else if(d.key_ == 't') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { if(eng->player->getPropHandler()->allowAttackRanged(true)) { Inventory* const playerInv = eng->player->getInventory(); Item* itemStack = playerInv->getItemInSlot(slot_missiles); if(itemStack == NULL) { eng->log->addMsg( "I have no missiles chosen for throwing (press 'w')."); } else { Item* itemToThrow = eng->itemFactory->copyItem(itemStack); itemToThrow->nrItems = 1; const MarkerReturnData markerReturnData = eng->marker->run(markerTask_aimThrownWeapon, itemToThrow); if(markerReturnData.didThrowMissile) { playerInv->decreaseItemInSlot(slot_missiles); } else { delete itemToThrow; } } } } clearEvents(); return; } //---------------------------------------- LOOK AROUND else if(d.key_ == 'l') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { if(eng->player->getPropHandler()->allowSee()) { eng->marker->run(markerTask_look, NULL); } else { eng->log->addMsg("I am blind."); } } clearEvents(); return; } //----------------------------------------AUTO MELEE else if(d.sdlKey_ == SDLK_TAB) { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { eng->player->autoMelee(); } clearEvents(); return; } //----------------------------------------POWERS - MEMORIZED else if(d.key_ == 'x') { clearLogMessages(); if(eng->player->deadState == actorDeadState_alive) { if(eng->player->getPropHandler()->allowRead(true)) { eng->playerSpellsHandler->run(); } } clearEvents(); return; } //----------------------------------------MANUAL else if(d.key_ == '?') { eng->manual->run(); eng->renderer->drawMapAndInterface(); clearEvents(); return; } //----------------------------------------CHARACTER INFO else if(d.key_ == '@') { eng->characterDescr->run(); clearEvents(); return; } //----------------------------------------LOG HISTORY else if(d.key_ == 'L') { eng->log->displayHistory(); clearEvents(); return; } //----------------------------------------QUIT else if(d.sdlKey_ == SDLK_ESCAPE || d.key_ == 'Q') { if(eng->player->deadState == actorDeadState_alive) { eng->log->clearLog(); eng->log->addMsg( "Quit the current game (y/n)? Save and highscore are not kept.", clrWhiteHigh); eng->renderer->drawMapAndInterface(); if(eng->query->yesOrNo()) { *quitToMainMenu_ = true; } else { eng->log->clearLog(); eng->renderer->drawMapAndInterface(); } } else { *quitToMainMenu_ = true; } clearEvents(); return; } //----------------------------------------SAVE AND QUIT else if(d.key_ == 'S') { if(eng->player->deadState == actorDeadState_alive) { if(eng->map->featuresStatic[eng->player->pos.x][eng->player->pos.y]->getId() == feature_stairsDown) { eng->log->clearLog(); eng->log->addMsg("Save and quit (y/n)?", clrWhiteHigh); eng->renderer->drawMapAndInterface(); if(eng->query->yesOrNo()) { eng->saveHandler->save(); *quitToMainMenu_ = true; } else { eng->log->clearLog(); eng->renderer->drawMapAndInterface(); } } else { eng->log->clearLog(); eng->renderer->drawMapAndInterface(); } } else { eng->log->addMsg("Saving can only be done on stairs."); eng->renderer->drawMapAndInterface(); } clearEvents(); return; } //----------------------------------------DESCEND CHEAT else if(d.sdlKey_ == SDLK_F2) { if(IS_DEBUG_MODE) { eng->dungeonClimb->travelDown(1); clearEvents(); } return; } //----------------------------------------XP CHEAT else if(d.sdlKey_ == SDLK_F3) { if(IS_DEBUG_MODE) { eng->dungeonMaster->playerGainXp(100); clearEvents(); } return; } //----------------------------------------VISION CHEAT else if(d.sdlKey_ == SDLK_F4) { if(IS_DEBUG_MODE) { if(eng->isCheatVisionEnabled) { for(int y = 0; y < MAP_Y_CELLS; y++) { for(int x = 0; x < MAP_X_CELLS; x++) { eng->map->explored[x][y] = false; } } eng->isCheatVisionEnabled = false; } else { eng->isCheatVisionEnabled = true; } } clearEvents(); } //----------------------------------------INSANITY CHEAT else if(d.sdlKey_ == SDLK_F5) { if(IS_DEBUG_MODE) { eng->player->incrShock(50); clearEvents(); } return; } //----------------------------------------MTH CHEAT else if(d.sdlKey_ == SDLK_F6) { if(IS_DEBUG_MODE) { eng->player->incrMth(8); clearEvents(); } return; } //----------------------------------------DROP ALL SCROLLS AND POTIONS ON PLAYER else if(d.sdlKey_ == SDLK_F7) { if(IS_DEBUG_MODE) { for(unsigned int i = 1; i < endOfItemIds; i++) { const ItemData* const data = eng->itemDataHandler->dataList[i]; if( data->isIntrinsic == false && (data->isPotion || data->isScroll)) { eng->itemFactory->spawnItemOnMap((ItemId_t)(i), eng->player->pos); } } clearEvents(); } return; } //----------------------------------------TELEPORT else if(d.sdlKey_ == SDLK_F8) { if(IS_DEBUG_MODE) { eng->player->teleport(false); clearEvents(); } return; } //----------------------------------------INFECTED else if(d.sdlKey_ == SDLK_F9) { if(IS_DEBUG_MODE) { eng->player->getPropHandler()->tryApplyProp( new PropInfected(eng, propTurnsStandard)); clearEvents(); } return; } //----------------------------------------UNDEFINED COMMANDS else if(d.key_ != -1) { string cmdTried = " "; cmdTried.at(0) = d.key_; eng->log->clearLog(); eng->log->addMsg( "Unknown command '" + cmdTried + "'. Press '?' for commands."); clearEvents(); return; } }
KeyboardReadReturnData Input::readKeysUntilFound() { while(true) { eng->sleep(1); while(SDL_PollEvent(&event_)) { if(event_.type == SDL_KEYDOWN) { // ASCII char entered? // Decimal unicode: // '!' = 33 // '~' = 126 if(event_.key.keysym.unicode >= 33 && event_.key.keysym.unicode < 126) { return KeyboardReadReturnData(static_cast<char>(event_.key.keysym.unicode)); clearEvents(); } else { // Other key pressed? (escape, return, space, etc) const SDLKey sdlKey = event_.key.keysym.sym; // Don't register shift, control or alt as actual key events if( sdlKey == SDLK_LSHIFT || sdlKey == SDLK_RSHIFT || sdlKey == SDLK_LCTRL || sdlKey == SDLK_RCTRL || sdlKey == SDLK_LALT || sdlKey == SDLK_RALT) { continue; } SDLMod mod = SDL_GetModState(); const bool IS_SHIFT_HELD = mod & KMOD_SHIFT; const bool IS_CTRL_HELD = mod & KMOD_CTRL; const bool IS_ALT_HELD = mod & KMOD_ALT; KeyboardReadReturnData ret(-1, sdlKey, IS_SHIFT_HELD, IS_CTRL_HELD); if(sdlKey >= SDLK_F1 && sdlKey <= SDLK_F15) { // F-keys return ret; } else { switch(sdlKey) { case SDLK_RETURN: case SDLK_KP_ENTER: { if(IS_ALT_HELD) { eng->config->toggleFullscreen(); clearEvents(); continue; } else { ret.sdlKey_ = SDLK_RETURN; return ret; } } break; case SDLK_MENU: continue; break; case SDLK_PAUSE: continue; break; case SDLK_SPACE: return ret; break; case SDLK_BACKSPACE: return ret; break; case SDLK_TAB: return ret; break; case SDLK_PAGEUP: return ret; break; case SDLK_PAGEDOWN: return ret; break; case SDLK_END: return ret; break; case SDLK_HOME: return ret; break; case SDLK_INSERT: return ret; break; case SDLK_DELETE: return ret; break; case SDLK_LEFT: return ret; break; case SDLK_RIGHT: return ret; break; case SDLK_UP: return ret; break; case SDLK_DOWN: return ret; break; case SDLK_ESCAPE: return ret; break; default: continue; break; } } } } } } }
int Map::load(const std::string& fname) { FileParser infile; clearEvents(); clearLayers(); clearQueues(); music_filename = ""; // @CLASS Map|Description of maps/ if (!infile.open(fname)) return 0; this->filename = fname; while (infile.next()) { if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "enemy") enemy_groups.push(Map_Group()); else if (infile.section == "npc") npcs.push(Map_NPC()); else if (infile.section == "event") events.push_back(Event()); } if (infile.section == "header") loadHeader(infile); else if (infile.section == "layer") loadLayer(infile); else if (infile.section == "enemy") loadEnemyGroup(infile, &enemy_groups.back()); else if (infile.section == "npc") loadNPC(infile); else if (infile.section == "event") EventManager::loadEvent(infile, &events.back()); } infile.close(); // create a temporary EffectDef for immunity; will be used for map StatBlocks EffectDef immunity_effect; immunity_effect.id = "MAP_EVENT_IMMUNITY"; immunity_effect.type = "immunity"; // create StatBlocks for events that need powers for (unsigned i=0; i<events.size(); ++i) { Event_Component *ec_power = events[i].getComponent(EC_POWER); if (ec_power) { statblocks.push_back(StatBlock()); StatBlock *statb = &statblocks.back(); if (!statb) { logError("Map: Could not create StatBlock for Event."); continue; } // store the index of this StatBlock so that we can find it when the event is activated ec_power->y = static_cast<int>(statblocks.size())-1; statb->starting[STAT_ACCURACY] = 1000; // always hit the target Event_Component *ec_path = events[i].getComponent(EC_POWER_PATH); if (ec_path) { // source is power path start statb->pos.x = static_cast<float>(ec_path->x) + 0.5f; statb->pos.y = static_cast<float>(ec_path->y) + 0.5f; } else { // source is event location statb->pos.x = static_cast<float>(events[i].location.x) + 0.5f; statb->pos.y = static_cast<float>(events[i].location.y) + 0.5f; } Event_Component *ec_damage = events[i].getComponent(EC_POWER_DAMAGE); if (ec_damage) { statb->starting[STAT_DMG_MELEE_MIN] = statb->starting[STAT_DMG_RANGED_MIN] = statb->starting[STAT_DMG_MENT_MIN] = ec_damage->a; statb->starting[STAT_DMG_MELEE_MAX] = statb->starting[STAT_DMG_RANGED_MAX] = statb->starting[STAT_DMG_MENT_MAX] = ec_damage->b; } // this is used to store cooldown ticks for a map power // the power id, type, etc are not used statb->powers_ai.resize(1); // make this StatBlock immune to negative status effects // this is mostly to prevent a player with a damage return bonus from damaging this StatBlock statb->effects.addEffect(immunity_effect, 0, 0, false, -1, 0, SOURCE_TYPE_ENEMY); } } // ensure that our map contains a collison layer if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) { layernames.push_back("collision"); layers.resize(layers.size()+1); layers.back().resize(w); for (size_t i=0; i<layers.back().size(); ++i) { layers.back()[i].resize(h, 0); } collision_layer = static_cast<int>(layers.size())-1; } return 0; }
void EventQueue::reinit() { clearEvents(); listeners.clear(); }