www.pudn.com > uoth_src.zip > Filter.cpp
//----------------------------------------------------------------------------- // // @doc // // @module Filter.cpp - Treasure and region filter class | // // This module contains the treasure and region filter class. // // Copyright (c) 2002 - Descartes Systems Sciences, Inc. // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // 2. Neither the name of Descartes Systems Sciences, Inc nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // @end // // $History: Cnf.cpp $ // //----------------------------------------------------------------------------- #include "stdafx.h" #include "Filter.h" #include "Region.h" #include "Treasure.h" #include "Character.h" #include "uoth.h" // // Debug NEW // #if defined (_DEBUG) #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Externals // extern HWND g_hWndMain; extern UINT g_umAppUpdate; //----------------------------------------------------------------------------- // // @mfuncconstructor. // // @rdesc None. // //----------------------------------------------------------------------------- CFilter::CFilter () { m_pfTreasureHasMap = NULL; m_nTreasures = 0; m_pfRegionHasMap = NULL; m_nRegions = 0; for (int i = 0; i < Max_Level; i++) m_afLevels [i] = true; m_fEnableMineFilter = false; m_fEnableLevelFilter = false; m_fEnableTackFilter = false; } //----------------------------------------------------------------------------- // // @mfunc destructor. // // @rdesc None. // //----------------------------------------------------------------------------- CFilter::~CFilter () { if (m_pfTreasureHasMap) delete [] m_pfTreasureHasMap; if (m_pfRegionHasMap) delete [] m_pfRegionHasMap; } //----------------------------------------------------------------------------- // // @mfunc Update the filter flags // // @rdesc None. // //----------------------------------------------------------------------------- void CFilter::Update () { // // If we need more treasures, then realloc // if (CTreasure::gm_vTreasures .GetCount () > m_nTreasures) { if (m_pfTreasureHasMap) delete [] m_pfTreasureHasMap; m_nTreasures = (int) CTreasure::gm_vTreasures .GetCount (); m_pfTreasureHasMap = new bool [m_nTreasures]; } // // If we need more regions, then realloc // if (CRegion::gm_vRegions .GetCount () > m_nRegions) { if (m_pfRegionHasMap) delete [] m_pfRegionHasMap; m_nRegions = (int) CRegion::gm_vRegions .GetCount (); m_pfRegionHasMap = new bool [m_nRegions]; } // // Initialize the flags // memset (m_pfTreasureHasMap, 0, sizeof (bool) * m_nTreasures); memset (m_pfRegionHasMap, 0, sizeof (bool) * m_nRegions); // // Loop through the character's maps // CCharacter *pCurrent = CCharacter::GetCurrent (); if (pCurrent) { for (int imc = 0; imc < pCurrent ->m_vMapCounts .GetCount (); ++imc) { CMapCounts *pMapCounts = &pCurrent ->m_vMapCounts [imc]; if (IsMapCountInFilter (pMapCounts)) { int nTreasure = pMapCounts ->m_nIndex; if (nTreasure > 0 && nTreasure < CTreasure::gm_vTreasures .GetCount ()) { m_pfTreasureHasMap [nTreasure] = true; int nRegion = CTreasure::gm_vTreasures [nTreasure] .m_nRegion; if (nRegion > 0 && nRegion < CRegion::gm_vRegions .GetCount ()) { m_pfRegionHasMap [nRegion] = true; } } } } } // // Notify the world // ::SendMessage (g_hWndMain, g_umAppUpdate, 0, 0); } //----------------------------------------------------------------------------- // // @mfunc Test to see if the map count is in the filter // // @parm const CMapCounts * | pCount | Map count array // // @rdesc True if the map count is in the filter // //----------------------------------------------------------------------------- bool CFilter::IsMapCountInFilter (const CMapCounts *pCount) const { for (int i = 0; i < Max_Level; ++i) { if (pCount ->m_anCounts [i] > 0 && (!m_fEnableLevelFilter || m_afLevels [i])) return true; } return false; }