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 CItem::Spawn_GenerateItem( CResourceDef * pDef ) { // Count how many items are here already. // This could be in a container. RESOURCE_ID_BASE rid = pDef->GetResourceID(); ITEMID_TYPE id = (ITEMID_TYPE) rid.GetResIndex(); int iDistMax = m_itSpawnItem.m_DistMax; int iAmountPile = m_itSpawnItem.m_pile; int iCount = 0; CItemContainer * pCont = dynamic_cast <CItemContainer *>( GetParent()); if ( pCont != NULL ) { iCount = pCont->ContentCount( rid ); } else { // If is equipped this will produce the item where you are standing. CPointMap pt = GetTopLevelObj()->GetTopPoint(); CWorldSearch AreaItems( pt, iDistMax ); while (true) { CItem * pItem = AreaItems.GetItem(); if ( pItem == NULL ) break; if ( pItem->IsType(IT_SPAWN_ITEM)) continue; if ( pItem->IsAttr( ATTR_INVIS )) continue; if ( pItem->GetID() != id ) continue; // if ( pItem->m_uidLink != GetUID()) continue; iCount += pItem->GetAmount(); } } if ( iCount >= GetAmount()) return; CItem * pItem = CreateTemplate( id ); if ( pItem == NULL ) return; pItem->SetAttr( m_Attr & ( ATTR_OWNED | ATTR_MOVE_ALWAYS )); if ( iAmountPile > 1 ) { CItemBase * pItemDef = pItem->Item_GetDef(); ASSERT(pItemDef); if ( pItemDef->IsStackableType()) { if ( iAmountPile == 0 || iAmountPile > GetAmount()) iAmountPile = GetAmount(); pItem->SetAmount( Calc_GetRandVal(iAmountPile) + 1 ); } } // pItem->m_uidLink = GetUID(); // This might be dangerous ? pItem->SetDecayTime( g_Cfg.m_iDecay_Item ); // It will decay eventually to be replaced later. pItem->MoveNearObj( this, iDistMax ); }