bool Keys::SelectKeys( vector<Char *> arr ) { // Проверка на комментарии int all = CheckComment( arr ); if( all == -1 ) all = arr.size(); // Проверяем на дерективы препроцессора if( CheckDerective( arr, all ) ) return true; // Проверка на строку commas.clear(); CheckCommas( arr, all ); // Обработка оставшегося массива int pos,left; string str = GetString( arr, all ); string str2; // До конца ключевых символов for( unsigned int i = 0; i < keys.size(); i++ ) { CheckLast( arr, all, keys[i].str ); // Проверка всех допустимых символов for( unsigned int j = 0; j < keys[i].crn.length(); j++ ) { str2 = str; pos = 0; left = 0; // Пока есть ключевые слова while( pos >= 0 ) { pos = str2.find( keys[i].str + keys[i].crn[j] ); // Если позиция найденна if( pos >= 0 ) { int posReal = GetPos( pos + left, arr ); if( !CheckPosCommas( posReal ) ) { // Задание параметров KeysArrayPos newKord; newKord.begin = posReal; newKord.end = newKord.begin + keys[i].str.length(); newKord.font = 1; newKord.color = BLUE; keysArrPos.push_back( newKord ); } // Обрезка строки str2.erase(0, pos + keys[i].str.length() + 1 ); left += pos + keys[i].str.length() + 1; } } } } if( !keysArrPos.size() ) return false; return true; }
bool CImportFile::ImportSCP( CScript & s, word wModeFlags ) { ADDTOCALLSTACK("CImportFile::ImportSCP"); // Import a SPHERE format SCP file. while ( s.FindNextSection()) { CheckLast(); if ( s.IsSectionType( "ACCOUNT" )) { g_Cfg.LoadResourceSection( &s ); continue; } else if ( s.IsSectionType( "WORLDCHAR" ) || s.IsSectionType("WC")) { ImportFix(); if ( wModeFlags & IMPFLAGS_CHARS ) { m_pCurObj = CChar::CreateBasic(static_cast<CREID_TYPE>(g_Cfg.ResourceGetIndexType(RES_CHARDEF, s.GetArgStr()))); } } else if ( s.IsSectionType( "WORLDITEM" ) || s.IsSectionType("WI")) { if ( wModeFlags & IMPFLAGS_ITEMS ) { m_pCurObj = CItem::CreateTemplate(static_cast<ITEMID_TYPE>(g_Cfg.ResourceGetIndexType(RES_ITEMDEF, s.GetArgStr()))); } } else { continue; } if ( m_pCurObj == NULL ) continue; while ( s.ReadKeyParse()) { if ( s.IsKey( "SERIAL")) { if ( m_pCurSer != NULL ) return false; m_pCurSer = new CImportSer( s.GetArgVal()); m_pCurSer->m_pObj = m_pCurObj; m_ListSer.InsertHead( m_pCurSer ); continue; } if ( m_pCurSer == NULL ) continue; if ( s.IsKey( "CONT" )) { m_pCurSer->m_dwContSer = s.GetArgVal(); } else if ( s.IsKey( "LAYER" )) { m_pCurSer->m_layer = static_cast<LAYER_TYPE>(s.GetArgVal()); } else { m_pCurObj->r_LoadVal( s ); } } } return true; }
bool CImportFile::ImportWSC( CScript & s, word wModeFlags ) { ADDTOCALLSTACK("CImportFile::ImportWSC"); // This file is a WSC or UOX world script file. IMPFLAGS_TYPE mode = IMPFLAGS_NOTHING; CSString sName; CItem * pItem = NULL; CChar * pChar = NULL; while ( s.ReadTextLine(true)) { if ( s.IsKeyHead( "SECTION WORLDITEM", 17 )) { CheckLast(); mode = IMPFLAGS_ITEMS; continue; } else if ( s.IsKeyHead( "SECTION CHARACTER", 17 )) { CheckLast(); mode = ( wModeFlags & IMPFLAGS_CHARS ) ? IMPFLAGS_CHARS : IMPFLAGS_NOTHING; continue; } else if ( s.GetKey()[0] == '{' ) { CheckLast(); continue; } else if ( s.GetKey()[0] == '}' ) { CheckLast(); mode = IMPFLAGS_NOTHING; continue; } else if ( mode == IMPFLAGS_NOTHING ) continue; else if ( s.GetKey()[0] == '\\' ) continue; // Parse the line. tchar* pKey = const_cast<tchar*>(strchr(s.GetKey(), ' ')); lpctstr pArg = NULL; if (pKey != NULL) { *pKey++ = '\0'; GETNONWHITESPACE(pKey); pArg = pKey; } else { pArg = ""; } if ( s.IsKey("SERIAL" )) { if ( m_pCurSer != NULL ) return false; dword dwSerial = ATOI( pArg ); if ( dwSerial == UID_UNUSED ) { DEBUG_ERR(( "Import:Bad serial number\n" )); break; } m_pCurSer = new CImportSer( dwSerial ); m_ListSer.InsertHead( m_pCurSer ); continue; } if ( s.IsKey("NAME" )) { sName = ( pArg[0] == '#' ) ? "" : pArg; if ( mode == IMPFLAGS_ITEMS ) continue; } if ( m_pCurSer == NULL ) { DEBUG_ERR(( "Import:No serial number\n" )); break; } if ( mode == IMPFLAGS_ITEMS ) // CItem. { if ( s.IsKey("ID" )) { if ( m_pCurObj != NULL ) return false; pItem = CItem::CreateTemplate(static_cast<ITEMID_TYPE>(ATOI(pArg))); pItem->SetName( sName ); m_pCurObj = pItem; m_pCurSer->m_pObj = pItem; continue; } if ( m_pCurObj == NULL ) { DEBUG_ERR(( "Import:Bad Item Key '%s'\n", s.GetKey())); break; } else if ( s.IsKey("CONT" )) { m_pCurSer->m_dwContSer = ATOI(pArg); } else if ( s.IsKey("LAYER" )) { m_pCurSer->m_layer = static_cast<LAYER_TYPE>(ATOI(pArg)); continue; } else if (pItem == NULL) { DEBUG_ERR(( "Import:Found '%s' before ID.\n", s.GetKey())); continue; } if ( s.IsKey("X" )) { CPointMap pt = pItem->GetUnkPoint(); pt.m_x = (short)( ATOI(pArg) ); pItem->SetUnkPoint(pt); continue; } else if ( s.IsKey("Y" )) { CPointMap pt = pItem->GetUnkPoint(); pt.m_y = (short)( ATOI(pArg) ); pItem->SetUnkPoint(pt); continue; } else if ( s.IsKey("Z" )) { CPointMap pt = pItem->GetUnkPoint(); pt.m_z = (char)( ATOI(pArg) ); pItem->SetUnkPoint(pt); continue; } else if ( s.IsKey("COLOR" )) { pItem->SetHue( static_cast<HUE_TYPE>( ATOI(pArg) ) ); continue; } else if ( s.IsKey("AMOUNT" )) { pItem->SetAmount( (word)ATOI(pArg) ); continue; } else if ( s.IsKey("MOREX" )) { pItem->m_itNormal.m_morep.m_x = (short)(ATOI(pArg)); continue; } else if ( s.IsKey("MOREY" )) { pItem->m_itNormal.m_morep.m_y = (short)(ATOI(pArg)); continue; } else if ( s.IsKey("MOREZ" )) { pItem->m_itNormal.m_morep.m_z = (char)( ATOI(pArg) ); continue; } else if ( s.IsKey("MORE" )) { pItem->m_itNormal.m_more1 = ATOI(pArg); continue; } else if ( s.IsKey("MORE2" )) { pItem->m_itNormal.m_more2 = ATOI(pArg); continue; } else if ( s.IsKey("DYEABLE" )) { //if ( ATOI(pArg)) // pItem->m_pDef->m_Can |= CAN_I_DYE; continue; } else if ( s.IsKey("ATT" )) { // pItem->m_pDef->m_attackBase = ATOI(pArg); } else if ( s.IsKey("TYPE" )) { // ??? translate the type field. //int i = ATOI(pArg); } } if ( mode == IMPFLAGS_CHARS ) { if ( s.IsKey("NAME" )) { if ( m_pCurObj != NULL ) return false; pChar = CChar::CreateBasic( CREID_MAN ); pChar->SetName( sName ); m_pCurObj = pChar; m_pCurSer->m_pObj = pChar; continue; } if ( m_pCurObj == NULL ) { DEBUG_ERR(( "Import:Bad Item Key '%s'\n", s.GetKey())); break; } else if (pChar == NULL) { DEBUG_ERR(( "Import:Found '%s' before NAME.\n", s.GetKey())); continue; } if ( s.IsKey("X" )) { CPointMap pt = pChar->GetUnkPoint(); pt.m_x = (short)(ATOI(pArg)); pChar->SetUnkPoint(pt); continue; } else if ( s.IsKey("Y" )) { CPointMap pt = pChar->GetUnkPoint(); pt.m_y = (short)(ATOI(pArg)); pChar->SetUnkPoint(pt); continue; } else if ( s.IsKey("Z" )) { CPointMap pt = pChar->GetUnkPoint(); pt.m_z = (char)(ATOI(pArg)); pChar->SetUnkPoint(pt); continue; } else if ( s.IsKey("BODY" )) { pChar->SetID(static_cast<CREID_TYPE>(ATOI(pArg))); continue; } else if ( s.IsKey("SKIN" )) { pChar->SetHue( static_cast<HUE_TYPE>( ATOI(pArg) )); continue; } else if ( s.IsKey("DIR" )) { pChar->m_dirFace = static_cast<DIR_TYPE>(ATOI(pArg)); if ( pChar->m_dirFace < 0 || pChar->m_dirFace >= DIR_QTY ) pChar->m_dirFace = DIR_SE; continue; } else if ( s.IsKey("XBODY" )) { pChar->m_prev_id = static_cast<CREID_TYPE>(ATOI(pArg)); continue; } else if ( s.IsKey("XSKIN" )) { pChar->m_prev_Hue = static_cast<HUE_TYPE>( ATOI(pArg) ); continue; } else if ( s.IsKey("FONT" )) { pChar->m_fonttype = static_cast<FONT_TYPE>(ATOI(pArg)); continue; } else if ( s.IsKey("KARMA" )) { pChar->Stat_SetBase(STAT_KARMA, (short)(ATOI(pArg))); continue; } else if ( s.IsKey("FAME" )) { pChar->Stat_SetBase(STAT_FAME, (short)(ATOI(pArg))); continue; } else if ( s.IsKey("TITLE" )) { pChar->m_sTitle = pArg; continue; } else if ( s.IsKey("STRENGTH" )) { pChar->Stat_SetBase(STAT_STR, (short)(ATOI(pArg))); } else if ( s.IsKey("DEXTERITY" )) { pChar->Stat_SetBase(STAT_DEX, (short)(ATOI(pArg))); } else if ( s.IsKey("INTELLIGENCE" )) { pChar->Stat_SetBase(STAT_INT, (short)(ATOI(pArg))); } else if ( s.IsKey("HITPOINTS" )) { pChar->Stat_SetVal(STAT_STR,(short)(ATOI(pArg))); } else if ( s.IsKey("STAMINA" )) { pChar->Stat_SetVal(STAT_DEX,(short)(ATOI(pArg))); } else if ( s.IsKey( "MANA" )) { pChar->Stat_SetVal(STAT_INT,(short)(ATOI(pArg))); } else if ( s.IsKeyHead( "SKILL", 5 )) { SKILL_TYPE skill = static_cast<SKILL_TYPE>(ATOI( &(s.GetKey()[5]))); if ( pChar->IsSkillBase(skill) && g_Cfg.m_SkillIndexDefs.IsValidIndex(skill) ) { pChar->Skill_SetBase( skill, ATOI(pArg)); } } else if ( s.IsKey("ACCOUNT" )) { // What if the account does not exist ? pChar->SetPlayerAccount( pArg ); } else if ( s.IsKey("KILLS" ) && pChar->m_pPlayer ) { pChar->m_pPlayer->m_wMurders = (word)(ATOI(pArg)); } else if ( s.IsKey("NPCAITYPE" )) { // Convert to proper NPC type. int i = ATOI( pArg ); switch ( i ) { case 0x01: pChar->SetNPCBrain( NPCBRAIN_HEALER ); break; case 0x02: pChar->SetNPCBrain( NPCBRAIN_MONSTER ); break; case 0x04: case 0x40: pChar->SetNPCBrain( NPCBRAIN_GUARD ); break; case 0x08: pChar->SetNPCBrain( NPCBRAIN_BANKER ); break; default: pChar->SetNPCBrain( pChar->GetNPCBrain( false )); break; } } continue; } } return true; }
void CImportFile::ImportFix() { ADDTOCALLSTACK("CImportFile::ImportFix"); // adjust all the containered items and eliminate duplicates. CheckLast(); int iRemoved = 0; CImportSer * pSerNext; m_pCurSer = static_cast <CImportSer*> ( m_ListSer.GetHead()); for ( ; m_pCurSer != NULL; m_pCurSer = pSerNext ) { pSerNext = static_cast <CImportSer*> ( m_pCurSer->GetNext()); if ( m_pCurSer->m_pObj == NULL ) // NEver created correctly { delete m_pCurSer; continue; } // Make sure this item is not a dupe ? CItem * pItemTest; if ( m_pCurSer->IsTopLevel()) // top level only { if ( m_pCurSer->m_pObj->IsItem()) { CItem * pItemCheck = dynamic_cast <CItem*>( m_pCurSer->m_pObj ); ASSERT(pItemCheck); pItemCheck->SetAttr(ATTR_MOVE_NEVER); CWorldSearch AreaItems( m_pCurSer->m_pObj->GetTopPoint()); for (;;) { CItem * pItem = AreaItems.GetItem(); if ( pItem == NULL ) break; if ( ! pItem->IsSameType( m_pCurSer->m_pObj )) continue; pItem->SetName( m_pCurSer->m_pObj->GetName()); if ( ! ( m_pCurSer->m_pObj->GetTopZ() == pItem->GetTopZ())) continue; goto item_delete; } } else { // dupe char ? } // Make sure the top level object is placed correctly. m_pCurSer->m_pObj->MoveTo( m_pCurSer->m_pObj->GetTopPoint()); m_pCurSer->m_pObj->Update(); if ( ! m_pCurSer->m_pObj->IsContainer()) delete m_pCurSer; continue; } pItemTest = dynamic_cast <CItem*> (m_pCurSer->m_pObj); if ( pItemTest == NULL ) { item_delete: delete m_pCurSer->m_pObj; delete m_pCurSer; iRemoved ++; continue; } // Find it's container. CImportSer* pSerCont = static_cast <CImportSer*> ( m_ListSer.GetHead()); CObjBase * pObjCont = NULL; for ( ; pSerCont != NULL; pSerCont = static_cast <CImportSer*> ( pSerCont->GetNext())) { if ( pSerCont->m_pObj == NULL ) continue; if ( pSerCont->m_dwSer == m_pCurSer->m_dwContSer ) { pObjCont = pSerCont->m_pObj; if ( ! pItemTest->LoadSetContainer( pObjCont->GetUID(), m_pCurSer->m_layer )) { goto item_delete; // not in a cont ? } m_pCurSer->m_dwContSer = UID_UNUSED; // found it. break; } } if ( ! m_pCurSer->IsTopLevel() || pObjCont == NULL) { goto item_delete; } // Is it a dupe in the container or equipped ? for ( CItem *pItem = dynamic_cast<CContainer*>(pObjCont)->GetContentHead(); pItem != NULL; pItem = pItem->GetNext() ) { if ( pItemTest == pItem ) continue; if ( pItemTest->IsItemEquipped()) { if ( pItemTest->GetEquipLayer() != pItem->GetEquipLayer()) continue; } else { if ( ! pItemTest->GetContainedPoint().IsSame2D( pItem->GetContainedPoint())) continue; } if ( ! pItemTest->IsSameType( pItem )) continue; goto item_delete; } // done with it if not a container. if ( ! pItemTest->IsContainer()) delete m_pCurSer; } if ( iRemoved ) { DEBUG_ERR(( "Import: removed %d bad items\n", iRemoved )); } m_ListSer.DeleteAll(); // done with the list now. }
void CImportFile::MergeDupes() { ADDTOCALLSTACK("CImportFile::MergeDupes"); // place all items and eliminate duplicates. CheckLast(); int iRemoved = 0; CImportSer *pSerNext; m_pCurSer = static_cast<CImportSer *>(m_ListSer.GetHead()); for ( ; m_pCurSer != NULL; m_pCurSer = pSerNext ) { pSerNext = static_cast<CImportSer *>(m_pCurSer->GetNext()); if ( m_pCurSer->m_pObj == NULL ) // never created correctly { delete m_pCurSer; continue; } // Make sure this item is not a dupe ? CItem *pItemTest; if ( m_pCurSer->IsTopLevel() ) // top level only { if ( m_pCurSer->m_pObj->IsItem() ) { CItem *pItemCheck = dynamic_cast<CItem *>(m_pCurSer->m_pObj); ASSERT(pItemCheck); pItemCheck->SetAttr(ATTR_MOVE_NEVER); CWorldSearch AreaItems(m_pCurSer->m_pObj->GetTopPoint()); for (;;) { CItem *pItem = AreaItems.GetItem(); if ( pItem == NULL ) break; if ( !pItem->IsIdentical(m_pCurSer->m_pObj )) continue; pItem->SetName(m_pCurSer->m_pObj->GetName()); if ( !(m_pCurSer->m_pObj->GetTopZ() == pItem->GetTopZ()) ) continue; goto item_delete; } } // Make sure the top level object is placed correctly. m_pCurSer->m_pObj->MoveTo(m_pCurSer->m_pObj->GetTopPoint()); m_pCurSer->m_pObj->Update(); if ( !m_pCurSer->m_pObj->IsContainer() ) delete m_pCurSer; continue; } pItemTest = dynamic_cast <CItem*> (m_pCurSer->m_pObj); if ( pItemTest == NULL ) { item_delete: delete m_pCurSer->m_pObj; delete m_pCurSer; iRemoved ++; continue; } delete m_pCurSer; } if ( iRemoved ) { DEBUG_ERR(( "Import: removed %d bad items\n", iRemoved )); } m_ListSer.DeleteAll(); // done with the list now. }
void CImportFile::Migrate() { ADDTOCALLSTACK("CImportFile::Migrate"); // place and adjust all the containered items CheckLast(); int iRemoved = 0; CImportSer * pSerNext; m_pCurSer = static_cast <CImportSer*> ( m_ListSer.GetHead()); for ( ; m_pCurSer != NULL; m_pCurSer = pSerNext ) { pSerNext = static_cast <CImportSer*> ( m_pCurSer->GetNext()); if ( m_pCurSer->m_pObj == NULL ) // NEver created correctly { delete m_pCurSer; continue; } CItem * pItemTest; if ( m_pCurSer->IsTopLevel()) // top level only { // Make sure the top level object is placed correctly. m_pCurSer->m_pObj->MoveTo( m_pCurSer->m_pObj->GetTopPoint()); m_pCurSer->m_pObj->Update(); if ( ! m_pCurSer->m_pObj->IsContainer()) delete m_pCurSer; continue; } pItemTest = dynamic_cast <CItem*> (m_pCurSer->m_pObj); if ( pItemTest == NULL ) { item_delete: delete m_pCurSer->m_pObj; delete m_pCurSer; iRemoved ++; continue; } // Find it's container and add it to the correct container CImportSer *pSerCont = static_cast<CImportSer *>(m_ListSer.GetHead()); CObjBase *pObjCont = NULL; for ( ; pSerCont != NULL; pSerCont = static_cast<CImportSer *>(pSerCont->GetNext()) ) { if ( pSerCont->m_pObj == NULL ) continue; if ( pSerCont->m_dwSer == m_pCurSer->m_dwContSer ) { pObjCont = pSerCont->m_pObj; if ( !pItemTest->LoadSetContainer(pObjCont->GetUID(), m_pCurSer->m_layer) ) goto item_delete; // not in a cont ? m_pCurSer->m_dwContSer = UID_UNUSED; // found it. break; } } // If neither top level nor in an existing container remove the item if ( !m_pCurSer->IsTopLevel() || pObjCont == NULL ) goto item_delete; /* Commented by Ares because this may causes errors while restoring player characters Example: - Items placed at the same positon in a container. // Is it a dupe in the container or equipped ? for ( CItem *pItem = dynamic_cast<CContainer *>(pObjCont)->GetContentHead(); pItem != NULL; pItem = pItem->GetNext() ) { if ( pItemTest == pItem ) continue; if ( pItemTest->IsItemEquipped() ) { if ( pItemTest->GetEquipLayer() != pItem->GetEquipLayer() ) continue; } else { if ( !pItemTest->GetContainedPoint().IsSame2D(pItem->GetContainedPoint()) ) continue; } if ( !pItemTest->IsIdentical(pItem) ) continue; goto item_delete; }*/ // done with it if not a container. if ( !pItemTest->IsContainer() ) delete m_pCurSer; } if ( iRemoved ) { DEBUG_ERR(( "Import: removed %d bad items\n", iRemoved )); } m_ListSer.DeleteAll(); // done with the list now. }
bool MockFrameSink::CheckLastWithDFC(FuncCodes aCode, bool aIsMaster, bool aIsRcvBuffFull, boost::uint16_t aDest, boost::uint16_t aSrc) { return (mIsRcvBuffFull == aIsRcvBuffFull) && CheckLast(aCode, aIsMaster, aDest, aSrc); }
bool MockFrameSink::CheckLastWithFCB(FuncCodes aCode, bool aIsMaster, bool aFcb, boost::uint16_t aDest, boost::uint16_t aSrc) { return (mFcb == aFcb) && CheckLast(aCode, aIsMaster, aDest, aSrc); }