//---------------------------------------------------------------------------------------------------------------------- // FIND TARGET //---------------------------------------------------------------------------------------------------------------------- mojo::cTarget * mojo::cArrayTarget :: find_target ( mojo::cTarget * a ) { for ( unsigned i = 0; i < qty(); i++ ) { mojo::cTarget * p = &(*this)[i]; #if 0 if ( a->hMach == 1 && a->bLaunchByMojo == true ) { if ( p->dwID == a->dwID ) return p; } #endif if ( a->bLaunchByMojo == true ) { if ( p->hMach == a->hMach && p->dwID == a->dwID ) return p; } else { if ( a->hwnd == p->hwnd && a->hMach == p->hMach && a->dwProcessID == p->dwProcessID ) return p; } } return NULL; }
int main (int argc __attribute__((unused)), char const* argv[]) { boost::iostreams::mapped_file_source file; assert(argc > 1); auto fileSize = boost::filesystem::file_size (argv[1]); file.open (argv[1], fileSize); assert(file.is_open ()); // 1 : timestamp // 2 : id (if add) // 3 : side (if add) // 4 : price (if add) // 5 : qty (if add) // 6 : id (if reduce) // 7 : qty (if reduce) boost::regex re ("(\\d{8}) (?:A ([a-z]+) ([BS]) (\\d+(?:\\.\\d+)?) (\\d+)|R ([a-z]+) (\\d+))"); stink::orderbook::OrderBook orderBook; char const* begin = static_cast<char const*> (file.data ()); char const* end = begin + fileSize; std::for_each (boost::cregex_iterator (begin, end, re), boost::cregex_iterator (), [&](boost::cmatch const& m) { if(m[2].matched) { // add std::uint32_t id = orderId(m[2]); char side = *m[3].first; std::uint32_t p = price(m[4]); std::uint32_t q = qty(m[5]); orderBook.add(id, side, p, q); } else { // reduce assert(m[6].matched); std::uint32_t id = orderId(m[6]); std::uint32_t q = qty(m[7]); orderBook.reduce(id, q); } }); orderBook.clear (); }
//---------------------------------------------------------------------------------------------------------------------- // FIND HWND //---------------------------------------------------------------------------------------------------------------------- mojo::cTarget * mojo::cArrayTarget :: find_hwnd ( HWND hwnd ) { for ( unsigned i = 0; i < qty(); i++ ) { if ( hwnd == (*this)[i].hwnd ) return &(*this)[i]; } return false; }
//---------------------------------------------------------------------------------------------------------------------- // FIND TARGET //---------------------------------------------------------------------------------------------------------------------- mojo::cTarget * mojo::cArrayTarget :: find_target ( DWORD hMach, HWND hwnd, DWORD dwProcessID ) { for ( unsigned i = 0; i < qty(); i++ ) { if ( hMach == (*this)[i].hMach && hwnd == (*this)[i].hwnd && dwProcessID == (*this)[i].dwProcessID ) return &(*this)[i]; } return false; }
int Storage::getMaxStore(const good::Product goodType) { int freeRoom = 0; if( !isDevastation() ) { int globalFreeRoom = capacity() - qty(); // current free capacity int goodFreeRoom = _gsd->stocks[ goodType ]->freeQty(); // remove all storage reservations for( auto& reserved : _getStoreReservations() ) { globalFreeRoom -= reserved.qty(); if( reserved.type() == goodType ) goodFreeRoom -= reserved.qty(); } freeRoom = math::clamp( goodFreeRoom, 0, globalFreeRoom ); } return freeRoom; }