#include "stdafx.h" #include "Logger.h" #include "GIArray.h" #include "DBLayer.h" void GIArray::Init() { giArray_updateHWND = NULL; giArray_updateMSG = 0; giArray_count = 0; InitializeCriticalSection( &cs_gi_array ); int i; for( i=0; iisUnused() ) log_error( LOG_ERROR, "GIArray_UpdateGIInfo(): idx[%d] is unused!\n", idx ); memcpy( gi_array[idx], pItemInfo, sizeof(class GroundItem) ); Unlock(); PostUpdateMessage(); //log_error( LOG_OK, "GIArray: Updated[%d]: [%S] [%S] (%d,%d,%d) tpml %u, oid %u\n", // idx, // name, title, x,y,z, templateID, objectID ); } void GIArray::DelGIByArrayIdx( int idx ) { if( idx<0 || (idx>=GA_MAX_ITEMS) ) return; Lock(); if( gi_array[idx] ) { gi_array[idx]->setUnused(); giArray_count--; //log_error( LOG_OK, "GIArray: deleted %u from index OK\n", objectID, idx ); } Unlock(); PostUpdateMessage(); } void GIArray::DeleteAll() { Lock(); int i; for( i=0; isetUnused(); } giArray_count = 0; Unlock(); PostUpdateMessage(); } void GIArray::Lock() { EnterCriticalSection( &cs_gi_array ); } void GIArray::Unlock() { LeaveCriticalSection( &cs_gi_array ); } int GIArray::FindGIByObjectID( unsigned int objectID ) { int ret = -1; int i; Lock(); for( i=0; iobjectID == objectID ) { ret = i; break; } } Unlock(); return ret; } int GIArray::FindFreeIndex() { int i; Lock(); for( i=0; isetUnused(); // and set as unused Unlock(); return i; } if( gi_array[i]->isUnused() ) { Unlock(); return i; } } Unlock(); log_error( LOG_ERROR, "GIArray_FindFreeIndex(): canot find free index, limit is %d!\n", GA_MAX_ITEMS ); return -1; } void GIArray::SetUpdateCommand( HWND hWnd, UINT uMsg ) { giArray_updateHWND = hWnd; giArray_updateMSG = uMsg; } void GIArray::PostUpdateMessage() { if( !giArray_updateHWND ) return; if( giArray_updateMSG < WM_USER ) return; PostMessage( giArray_updateHWND, giArray_updateMSG, 0, 0 ); } void GIArray::DisplayToConsole() { int i = 0; unsigned int nDisplayed = 0; log_error( LOG_USERAI, "=== Ground items: %d ===\n", giArray_count ); if( giArray_count > 0 ) { Lock(); for( i=0; iisUnused() ) log_error( LOG_USERAI, "GI: %2d: \n", i ); else { wchar_t itemName[256] = {0}; DBLayer_getItemName( gi_array[i]->itemID, itemName, 255 ); log_error( LOG_USERAI, "GI: %2d: itemID %u, objectID %u, count %d [%s]\n", i, gi_array[i]->itemID, gi_array[i]->objectID, gi_array[i]->count, itemName ); nDisplayed++; } if( nDisplayed >= giArray_count ) break; } Unlock(); } log_error( LOG_USERAI, "=== Ground items End ===\n" ); }