WEATHER_TYPE CSector::GetWeatherCalc() const { ADDTOCALLSTACK("CSector::GetWeatherCalc"); // There is no weather in dungeons (or when the Sphere.ini setting prevents weather) if ( IsInDungeon() || g_Cfg.m_fNoWeather ) return( WEATHER_DRY ); // Rain chance also controls the chance of snow. If it isn't possible to rain then it cannot snow either int iPercentRoll = Calc_GetRandVal( 100 ); if ( iPercentRoll < GetRainChance() ) { // It is precipitating... but is it rain or snow? if ( GetColdChance() && Calc_GetRandVal(100) <= GetColdChance()) // Should it actually snow here? return WEATHER_SNOW; return WEATHER_RAIN; } // It is not precipitating, but is it cloudy or dry? if ( ( iPercentRoll / 2) < GetRainChance() ) return WEATHER_CLOUDY; return( WEATHER_DRY ); }
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); } }
bool CSector::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CSector::r_WriteVal"); EXC_TRY("WriteVal"); static const CValStr sm_ComplexityTitles[] = { { "HIGH", INT_MIN }, // speech can be very complex if low char count { "MEDIUM", 5 }, { "LOW", 10 }, { NULL, INT_MAX } }; switch ( FindTableHeadSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case SC_CLIENTS: sVal.FormatVal(m_Chars_Active.HasClients()); return true; case SC_COLDCHANCE: sVal.FormatVal( GetColdChance()); return( true ); case SC_COMPLEXITY: if ( pszKey[10] == '.' ) { pszKey += 11; sVal = ( ! strcmpi( pszKey, sm_ComplexityTitles->FindName( GetCharComplexity()))) ? "1" : "0"; return( true ); } sVal.FormatVal( GetCharComplexity()); return( true ); case SC_FLAGS: sVal.FormatHex(m_dwFlags); return( true ); case SC_LIGHT: sVal.FormatVal(GetLight()); return true; case SC_LOCALTIME: sVal = GetLocalGameTime(); return( true ); case SC_LOCALTOD: sVal.FormatVal( GetLocalTime()); return( true ); case SC_NUMBER: sVal.FormatVal(m_index); return( true ); case SC_ISDARK: sVal.FormatVal( IsDark() ); return( true ); case SC_ISNIGHTTIME: { int iMinutes = GetLocalTime(); sVal = ( iMinutes < 7*60 || iMinutes > (9+12)*60 ) ? "1" : "0"; } return( true ); case SC_RAINCHANCE: sVal.FormatVal( GetRainChance()); return( true ); case SC_ITEMCOUNT: sVal.FormatVal(GetItemComplexity()); return true; case SC_SEASON: sVal.FormatVal(static_cast<int>(GetSeason())); return true; case SC_WEATHER: sVal.FormatVal(static_cast<int>(GetWeather())); return true; } EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CSector::r_WriteVal( lpctstr pszKey, CSString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CSector::r_WriteVal"); EXC_TRY("WriteVal"); static const CValStr sm_ComplexityTitles[] = { { "HIGH", INT32_MIN }, // speech can be very complex if low char count { "MEDIUM", 5 }, { "LOW", 10 }, { nullptr, INT32_MAX } }; SC_TYPE key = (SC_TYPE)FindTableHead(pszKey, sm_szLoadKeys, CountOf(sm_szLoadKeys) - 1); switch ( key ) { case SC_CANSLEEP: { pszKey += 8; bool fCheckAdjacents = Exp_GetVal(pszKey); sVal.FormatBVal(CanSleep(fCheckAdjacents)); return true; } case SC_CLIENTS: sVal.FormatSTVal(m_Chars_Active.GetClientsNumber()); return true; case SC_COLDCHANCE: sVal.FormatVal( GetColdChance()); return true; case SC_COMPLEXITY: if ( pszKey[10] == '.' ) { pszKey += 11; sVal = ( ! strcmpi( pszKey, sm_ComplexityTitles->FindName( (int)GetCharComplexity() )) ) ? "1" : "0"; return true; } sVal.FormatSTVal( GetCharComplexity() ); return true; case SC_FLAGS: sVal.FormatHex(m_dwFlags); return true; case SC_LIGHT: sVal.FormatVal(GetLight()); return true; case SC_LOCALTIME: sVal = GetLocalGameTime(); return true; case SC_LOCALTOD: sVal.FormatVal( GetLocalTime()); return true; case SC_NUMBER: sVal.FormatVal(m_index); return true; case SC_ISDARK: sVal.FormatVal( IsDark() ); return true; case SC_ISNIGHTTIME: { int iMinutes = GetLocalTime(); sVal = ( iMinutes < 7*60 || iMinutes > (9+12)*60 ) ? "1" : "0"; } return true; case SC_ISSLEEPING: sVal.FormatVal(IsSleeping()); return true; case SC_RAINCHANCE: sVal.FormatVal( GetRainChance()); return true; case SC_ITEMCOUNT: sVal.FormatSTVal(GetItemComplexity()); return true; case SC_SEASON: sVal.FormatVal((int)GetSeason()); return true; case SC_WEATHER: sVal.FormatVal((int)GetWeather()); return true; } EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }