void CRegionWorld::r_Write( CScript &s ) { ADDTOCALLSTACK_INTENSIVE("CRegionWorld::r_Write"); s.WriteSection( "AREADEF %s", GetResourceName()); r_WriteBase( s ); }
void CVarDefMap::r_WritePrefix( CScript & s, LPCTSTR pszPrefix, LPCTSTR pszKeyExclude ) { ADDTOCALLSTACK_INTENSIVE("CVarDefMap::r_WritePrefix"); TemporaryString z; LPCTSTR pszVal; bool bHasPrefix = (pszPrefix && *pszPrefix); bool bHasExclude = (pszKeyExclude && *pszKeyExclude); // Write with any prefix. for ( DefSet::const_iterator i = m_Container.begin(); i != m_Container.end(); ++i ) { const CVarDefCont * pVar = (*i); if ( !pVar ) { // This should not happen, a warning maybe? continue; } if ( bHasExclude && !strcmpi(pszKeyExclude, pVar->GetKey())) continue; if ( bHasPrefix ) sprintf(z, "%s.%s", pszPrefix, pVar->GetKey()); else sprintf(z, "%s", pVar->GetKey()); pszVal = pVar->GetValStr(); const CVarDefContStr * pVarStr = dynamic_cast <const CVarDefContStr *>(pVar); if ( pVarStr ) // IsSpace(pszVal[0]) || IsSpace( pszVal[strlen(pszVal)-1] ) s.WriteKeyFormat(z, "\"%s\"", pszVal); else s.WriteKey(z, pszVal); } }
void CItemMap::r_Write(CScript & s) { ADDTOCALLSTACK_INTENSIVE("CItemMap::r_Write"); CItemVendable::r_Write(s); for ( size_t i = 0; i < m_Pins.GetCount(); i++ ) s.WriteKeyFormat("PIN", "%i,%i", m_Pins[i].m_x, m_Pins[i].m_y); }
bool CSector::CanSleep(bool fCheckAdjacents) const { ADDTOCALLSTACK_INTENSIVE("CSector::CanSleep"); if ( (g_Cfg._iSectorSleepDelay == 0) || IsFlagSet(SECF_NoSleep) ) return false; // never sleep if (m_Chars_Active.GetClientsNumber() > 0) return false; // has at least one client, no sleep if ( IsFlagSet(SECF_InstaSleep) ) return true; // no active client inside, instant sleep if (fCheckAdjacents) { for (int i = 0; i < (int)DIR_QTY; ++i)// Check for adjacent's sectors sleeping allowance. { const CSector *pAdjacent = GetAdjacentSector((DIR_TYPE)i); // set this as the last sector to avoid this code in the adjacent one and return if it can sleep or not instead of searching its adjacents. /* * Only check if this sector exist and it's not the last checked (sectors in the edges of the map doesn't have adjacent on those directions) * && Only check if the sector isn't sleeping (IsSleeping()) and then check if CanSleep(). */ if (!pAdjacent) { continue; } if (!pAdjacent->IsSleeping() || !pAdjacent->CanSleep(false)) { return false; // assume the base sector can't sleep. } } } //default behaviour; return ((g_World.GetCurrentTime().GetTimeRaw() - GetLastClientTime()) > g_Cfg._iSectorSleepDelay); // Sector Sleep timeout. }
void CResourceRefArray::r_Write( CScript & s, LPCTSTR pszKey ) const { ADDTOCALLSTACK_INTENSIVE("CResourceRefArray::r_Write"); for ( size_t j = 0; j < GetCount(); j++ ) { s.WriteKey( pszKey, GetResourceName( j )); } }
void _cdecl CScript::WriteKeyFormat( LPCTSTR pszKey, LPCTSTR pszVal, ... ) { ADDTOCALLSTACK_INTENSIVE("CScript::WriteKeyFormat"); TemporaryString pszTemp; va_list vargs; va_start( vargs, pszVal ); _vsnprintf(pszTemp, pszTemp.realLength(), pszVal, vargs); WriteKey(pszKey, pszTemp); va_end( vargs ); }
bool CScript::WriteKey( LPCTSTR pszKey, LPCTSTR pszVal ) { ADDTOCALLSTACK_INTENSIVE("CScript::WriteKey"); if ( pszKey == NULL || pszKey[0] == '\0' ) { return false; } TCHAR ch = '\0'; TCHAR * pszSep; if ( pszVal == NULL || pszVal[0] == '\0' ) { pszSep = const_cast<TCHAR*>(strchr( pszKey, '\n' )); if ( pszSep == NULL ) pszSep = const_cast<TCHAR*>(strchr( pszKey, '\r' )); // acts like const_cast if ( pszSep != NULL ) { g_Log.Event( LOGL_WARN|LOGM_CHEAT, "carriage return in key (book?) - truncating\n" ); ch = *pszSep; *pszSep = '\0'; } // Books are like this. No real keys. Printf( "%s\n", pszKey ); if ( pszSep != NULL ) *pszSep = ch; } else { pszSep = const_cast<TCHAR*>(strchr( pszVal, '\n' )); if ( pszSep == NULL ) pszSep = const_cast<TCHAR*>(strchr( pszVal, '\r' )); // acts like const_cast if ( pszSep != NULL ) { g_Log.Event( LOGL_WARN|LOGM_CHEAT, "carriage return in key value - truncating\n" ); ch = *pszSep; *pszSep = '\0'; } Printf( "%s=%s\n", pszKey, pszVal ); if ( pszSep != NULL ) *pszSep = ch; } return( true ); }
void CItemMessage::r_Write(CScript & s) { ADDTOCALLSTACK_INTENSIVE("CItemMessage::r_Write"); CItemVendable::r_Write(s); s.WriteKey("AUTHOR", m_sAuthor); // Store the message body lines. MAX_BOOK_PAGES TemporaryString pszTemp; for ( size_t i = 0; i < GetPageCount(); ++i ) { sprintf(pszTemp, "BODY.%" FMTSIZE_T, i); LPCTSTR pszText = GetPageText(i); s.WriteKey(pszTemp, pszText != NULL ? pszText : ""); } }
bool _cdecl CScript::WriteSection( LPCTSTR pszSection, ... ) { ADDTOCALLSTACK_INTENSIVE("CScript::WriteSection"); // Write out the section header. va_list vargs; va_start( vargs, pszSection ); // EndSection(); // End any previous section. Printf( "\n["); VPrintf( pszSection, vargs ); Printf( "]\n" ); va_end( vargs ); return( true ); }
void CItemVendable::r_Write(CScript &s) { ADDTOCALLSTACK_INTENSIVE("CItemVendable::r_Write"); CItem::r_Write(s); if ( GetQuality() != 0 ) { s.WriteKeyVal( "QUALITY", GetQuality()); } // am i on a vendor right now ? if ( m_price > 0 ) { s.WriteKeyVal( "PRICE", m_price ); } return; }
inline bool CSector::IsSectorSleeping() const { ADDTOCALLSTACK_INTENSIVE("CSector::IsSectorSleeping"); if ( IsFlagSet(SECF_NoSleep) ) return false; // never sleep if ( IsFlagSet(SECF_InstaSleep) ) { if ( m_Chars_Active.HasClients() > 0 ) return false; // has at least one client, no sleep else return true; // no active client inside, instant sleep } //default behaviour return (-g_World.GetTimeDiff(GetLastClientTime()) > 10 * 60 * TICK_PER_SEC); }
TCHAR * CPointBase::WriteUsed( TCHAR * pszBuffer ) const { ADDTOCALLSTACK_INTENSIVE("CPointBase::WriteUsed"); if ( m_map ) { sprintf(pszBuffer, "%d,%d,%d,%d", m_x, m_y, m_z, m_map); } else if ( m_z ) { sprintf(pszBuffer, "%d,%d,%d", m_x, m_y, m_z); } else { sprintf(pszBuffer, "%d,%d", m_x, m_y); } return pszBuffer; }
void CItemStone::r_Write( CScript & s ) { ADDTOCALLSTACK_INTENSIVE("CItemStone::r_Write"); CItem::r_Write( s ); s.WriteKeyVal( "ALIGN", GetAlignType()); if ( ! m_sAbbrev.IsEmpty()) { s.WriteKey( "ABBREV", m_sAbbrev ); } TemporaryString pszTemp; for ( unsigned int i = 0; i < COUNTOF(m_sCharter); i++ ) { if ( ! m_sCharter[i].IsEmpty()) { sprintf(pszTemp, "CHARTER%u", i); s.WriteKey(pszTemp, m_sCharter[i] ); } } if ( ! m_sWebPageURL.IsEmpty()) { s.WriteKey( "WEBPAGE", GetWebPageURL() ); } // s.WriteKey( "//", "uid,title,priv,loyaluid,abbr&theydecl,wedecl"); CStoneMember * pMember = STATIC_CAST <CStoneMember *>(GetHead()); for ( ; pMember != NULL; pMember = pMember->GetNext()) { if (pMember->GetLinkUID().IsValidUID()) // To protect against characters that were deleted! { s.WriteKeyFormat( "MEMBER", "0%lx,%s,%i,0%lx,%i,%i,%i", (DWORD) pMember->GetLinkUID() | (pMember->GetLinkUID().IsItem() ? UID_F_ITEM : 0), static_cast<LPCTSTR>(pMember->GetTitle()), pMember->GetPriv(), static_cast<DWORD>(pMember->GetLoyalToUID()), pMember->m_UnDef.m_Val1, pMember->m_UnDef.m_Val2, pMember->GetAccountGold()); } } }
void CSector::OnTick(int iPulseCount) { ADDTOCALLSTACK_INTENSIVE("CSector::OnTick"); // CWorld gives OnTick() to all CSectors. EXC_TRY("Tick"); EXC_SET("light change"); // do not tick sectors on maps not supported by server if ( !g_MapList.m_maps[m_map] ) return; // Check for light change before putting the sector to sleep, since in other case the // world light levels will be shitty bool fEnvironChange = false; bool fLightChange = false; bool fSleeping = false; if ( ! ( iPulseCount & 0x7f )) // 30 seconds or so. { // check for local light level change ? BYTE blightprv = m_Env.m_Light; m_Env.m_Light = GetLightCalc( false ); if ( m_Env.m_Light != blightprv ) { fEnvironChange = true; fLightChange = true; } } EXC_SET("sector sleeping?"); size_t clients = m_Chars_Active.HasClients(); if ( clients <= 0 ) // having no clients inside { // Put the sector to sleep if no clients been here in a while. fSleeping = IsSectorSleeping(); if ( fSleeping ) { if ( !g_Cfg.m_iSectorSleepMask ) return; if (( iPulseCount & g_Cfg.m_iSectorSleepMask ) != ( GetIndex() & g_Cfg.m_iSectorSleepMask )) return; } } EXC_SET("sound effects"); // random weather noises and effects. SOUND_TYPE sound = 0; bool fWeatherChange = false; int iRegionPeriodic = 0; if ( ! ( iPulseCount & 0x7f )) // 30 seconds or so. { // Only do this every x minutes or so (TICK_PER_SEC) // check for local weather change ? WEATHER_TYPE weatherprv = m_Env.m_Weather; if ( ! Calc_GetRandVal( 30 )) // change less often { m_Env.m_Weather = GetWeatherCalc(); if ( weatherprv != m_Env.m_Weather ) { fWeatherChange = true; fEnvironChange = true; } } // Random area noises. Only do if clients about. if ( clients > 0 ) { iRegionPeriodic = 2; static const SOUND_TYPE sm_SfxRain[] = { 0x10, 0x11 }; static const SOUND_TYPE sm_SfxWind[] = { 0x14, 0x15, 0x16 }; static const SOUND_TYPE sm_SfxThunder[] = { 0x28, 0x29 , 0x206 }; // Lightning ? // wind, rain, switch ( GetWeather() ) { case WEATHER_CLOUDY: break; case WEATHER_SNOW: if ( ! Calc_GetRandVal(5) ) sound = sm_SfxWind[ Calc_GetRandVal( COUNTOF( sm_SfxWind )) ]; break; case WEATHER_RAIN: { int iVal = Calc_GetRandVal(30); if ( iVal < 5 ) { // Mess up the light levels for a sec.. LightFlash(); sound = sm_SfxThunder[ Calc_GetRandVal( COUNTOF( sm_SfxThunder )) ]; } else if ( iVal < 10 ) sound = sm_SfxRain[ Calc_GetRandVal( COUNTOF( sm_SfxRain )) ]; else if ( iVal < 15 ) sound = sm_SfxWind[ Calc_GetRandVal( COUNTOF( sm_SfxWind )) ]; } break; default: break; } } } // regen all creatures and do AI ProfileTask charactersTask(PROFILE_CHARS); //pChar = STATIC_CAST <CChar*>( m_Chars_Active.GetHead()); CChar * pCharNext = NULL; CChar * pChar = dynamic_cast <CChar*>( m_Chars_Active.GetHead()); for ( ; pChar != NULL; pChar = pCharNext ) { EXC_TRYSUB("TickChar"); pCharNext = pChar->GetNext(); if (( fEnvironChange ) && ( IsTrigUsed(TRIGGER_ENVIRONCHANGE) )) pChar->OnTrigger(CTRIG_EnvironChange, pChar); if ( pChar->IsClient()) { CClient * pClient = pChar->GetClient(); ASSERT( pClient ); if ( sound ) pClient->addSound(sound, pChar); if ( fLightChange && ! pChar->IsStatFlag( STATF_DEAD | STATF_NightSight )) pClient->addLight(); if ( fWeatherChange ) pClient->addWeather(GetWeather()); if ( iRegionPeriodic && pChar->m_pArea ) { if (( iRegionPeriodic == 2 )&&( IsTrigUsed(TRIGGER_REGPERIODIC) )) { pChar->m_pArea->OnRegionTrigger( pChar, RTRIG_REGPERIODIC ); iRegionPeriodic--; } if ( IsTrigUsed(TRIGGER_CLIPERIODIC) ) pChar->m_pArea->OnRegionTrigger( pChar, RTRIG_CLIPERIODIC ); } } // Can only die on your own tick. if ( !pChar->OnTick() ) pChar->Delete(); EXC_CATCHSUB("Sector"); EXC_DEBUGSUB_START; CPointMap pt = GetBasePoint(); g_Log.EventDebug("char 0%lx '%s'\n", static_cast<DWORD>(pChar->GetUID()), pChar->GetName()); g_Log.EventDebug("sector #%d [%d,%d,%d,%d]\n", GetIndex(), pt.m_x, pt.m_y, pt.m_z, pt.m_map); EXC_DEBUGSUB_END; } // decay items on ground = time out spells / gates etc.. etc.. // No need to check these so often ! ProfileTask itemsTask(PROFILE_ITEMS); CItem * pItemNext = NULL; CItem * pItem = dynamic_cast <CItem*>( m_Items_Timer.GetHead()); for ( ; pItem != NULL; pItem = pItemNext ) { EXC_TRYSUB("TickItem"); pItemNext = pItem->GetNext(); EXC_SETSUB("TimerExpired"); if ( pItem->IsTimerExpired() ) { EXC_SETSUB("ItemTick"); if ( !pItem->OnTick() ) { EXC_SETSUB("ItemDelete"); pItem->Delete(); } else { EXC_SETSUB("TimerExpired2"); if ( pItem->IsTimerExpired() ) // forgot to clear the timer.? strange. { EXC_SETSUB("SetTimeout"); pItem->SetTimeout(-1); } } } EXC_SETSUB("UpdateFlags"); pItem->OnTickStatusUpdate(); #ifdef _WIN32 EXC_CATCHSUB("Sector"); EXC_DEBUGSUB_START; CPointMap pt = GetBasePoint(); g_Log.EventError("item 0%lx '%s' [timer=%lld, type=%lld]\n", static_cast<DWORD>(pItem->GetUID()), pItem->GetName(), pItem->GetTimerAdjusted(), static_cast<int>(pItem->GetType())); g_Log.EventError("sector #%d [%d,%d,%d,%d]\n", GetIndex(), pt.m_x, pt.m_y, pt.m_z, pt.m_map); EXC_DEBUGSUB_END; #else } #ifndef _DEBUG catch ( const CGrayError& e )
void CSector::r_Write() { ADDTOCALLSTACK_INTENSIVE("CSector::r_Write"); if ( m_fSaveParity == g_World.m_fSaveParity ) return; // already saved. CPointMap pt = GetBasePoint(); m_fSaveParity = g_World.m_fSaveParity; bool bHeaderCreated = false; if ( m_dwFlags > 0) { g_World.m_FileWorld.WriteSection("SECTOR %d,%d,0,%d", pt.m_x, pt.m_y, pt.m_map ); g_World.m_FileWorld.WriteKeyHex("FLAGS", m_dwFlags); bHeaderCreated = true; } if (g_Cfg.m_bAllowLightOverride && IsLightOverriden()) { if ( bHeaderCreated == false ) { g_World.m_FileWorld.WriteSection("SECTOR %d,%d,0,%d", pt.m_x, pt.m_y, pt.m_map); bHeaderCreated = true; } g_World.m_FileWorld.WriteKeyVal("LIGHT", GetLight()); } if (!g_Cfg.m_fNoWeather && (IsRainOverriden() || IsColdOverriden())) { if ( bHeaderCreated == false ) { g_World.m_FileWorld.WriteSection("SECTOR %d,%d,0,%d", pt.m_x, pt.m_y, pt.m_map); bHeaderCreated = true; } if ( IsRainOverriden() ) g_World.m_FileWorld.WriteKeyVal("RAINCHANCE", GetRainChance()); if ( IsColdOverriden() ) g_World.m_FileWorld.WriteKeyVal("COLDCHANCE", GetColdChance()); } if (GetSeason() != SEASON_Summer) { if ( bHeaderCreated == false ) g_World.m_FileWorld.WriteSection("SECTOR %d,%d,0,%d", pt.m_x, pt.m_y, pt.m_map); g_World.m_FileWorld.WriteKeyVal("SEASON", GetSeason()); } // Chars in the sector. CChar *pCharNext = NULL; for ( CChar *pChar = static_cast<CChar*>(m_Chars_Active.GetHead()); pChar != NULL; pChar = pCharNext ) { pCharNext = pChar->GetNext(); pChar->r_WriteParity(pChar->m_pPlayer ? g_World.m_FilePlayers : g_World.m_FileWorld); } // Inactive Client Chars, ridden horses and dead NPCs (NOTE: Push inactive player chars out to the account files here?) for ( CChar *pChar = static_cast<CChar*>(m_Chars_Disconnect.GetHead()); pChar != NULL; pChar = pCharNext ) { pCharNext = pChar->GetNext(); pChar->r_WriteParity(pChar->m_pPlayer ? g_World.m_FilePlayers : g_World.m_FileWorld); } // Items on the ground. CItem *pItemNext = NULL; for ( CItem *pItem = static_cast<CItem*>(m_Items_Inert.GetHead()); pItem != NULL; pItem = pItemNext ) { pItemNext = pItem->GetNext(); if ( pItem->IsType(IT_MULTI_CUSTOM) ) pItem->r_WriteSafe(g_World.m_FileMultis); else if ( !pItem->IsAttr(ATTR_STATIC) ) pItem->r_WriteSafe(g_World.m_FileWorld); } for ( CItem *pItem = static_cast<CItem*>(m_Items_Timer.GetHead()); pItem != NULL; pItem = pItemNext ) { pItemNext = pItem->GetNext(); if ( pItem->IsType(IT_MULTI_CUSTOM) ) pItem->r_WriteSafe(g_World.m_FileMultis); else if ( !pItem->IsAttr(ATTR_STATIC) ) pItem->r_WriteSafe(g_World.m_FileWorld); } }
void CItemScript::r_Write(CScript & s) { ADDTOCALLSTACK_INTENSIVE("CItemScript::r_Write"); CItemVendable::r_Write(s); }
void CItemCommCrystal::r_Write(CScript & s) { ADDTOCALLSTACK_INTENSIVE("CItemCommCrystal::r_Write"); CItemVendable::r_Write(s); m_Speech.r_Write(s, "SPEECH"); }
void CItemContainer::r_Write( CScript & s ) { ADDTOCALLSTACK_INTENSIVE("CItemContainer::r_Write"); CItemVendable::r_Write(s); r_WriteContent(s); }