bool clearTradesFunctor( CBaseObject *a, UI32 &b, void *extraData ) { bool retVal = true; if( ValidateObject( a ) && a->CanBeObjType( OT_ITEM ) ) { // Body of the functor goes here CItem *i = static_cast< CItem * >(a); if( ValidateObject( i ) ) { if( i->GetType() == IT_TRADEWINDOW ) { CChar *k = FindItemOwner( i ); if( ValidateObject( k ) ) { CItem *p = k->GetPackItem(); if( ValidateObject( p ) ) { CDataList< CItem * > *iCont = i->GetContainsList(); for( CItem *j = iCont->First(); !iCont->Finished(); j = iCont->Next() ) { if( ValidateObject( j ) ) j->SetCont( p ); } } } i->Delete(); ++b; // let's track how many we cleared } } } return retVal; }
//o---------------------------------------------------------------------------o //| Function : CItem *CreateTradeWindow( CSocket *mSock, CSocket *nSock, CChar *mChar ) //| Date : February 2, 2006 //| Programmer : giwo //o---------------------------------------------------------------------------o //| Purpose : Creates a TradeWindow and sends it to the clients //o---------------------------------------------------------------------------o CItem *CreateTradeWindow( CSocket *mSock, CSocket *nSock, CChar *mChar ) { CItem *mPack = mChar->GetPackItem(); if( !ValidateObject( mPack ) ) { mSock->sysmessage( 773 ); nSock->sysmessage( 1357, mChar->GetName().c_str() ); return NULL; } CItem *tradeWindow = Items->CreateItem( NULL, mChar, 0x1E5E, 1, 0, OT_ITEM, false ); if( !ValidateObject( tradeWindow ) ) return NULL; tradeWindow->SetType( IT_TRADEWINDOW ); tradeWindow->SetCont( mChar ); tradeWindow->SetX( 0 ); tradeWindow->SetY( 0 ); tradeWindow->SetZ( 0 ); tradeWindow->SetDye( false ); tradeWindow->SetTempVar( CITV_MOREZ, 0 ); tradeWindow->SetDecayable( false ); tradeWindow->SendPackItemToSocket( mSock ); tradeWindow->SendPackItemToSocket( nSock ); return tradeWindow; }
//o--------------------------------------------------------------------------o //| Function - Cleanup( void ) //| Date - 26th September, 2001 //| Programmer - Abaddon //| Modified - //o--------------------------------------------------------------------------o //| Purpose - Makes sure that any items and chars inside the multi //| are removed //o--------------------------------------------------------------------------o void CMultiObj::Cleanup( void ) { for( CItem *iRemove = itemInMulti.First(); !itemInMulti.Finished(); iRemove = itemInMulti.Next() ) { if( ValidateObject( iRemove ) ) { ItemTypes iType = iRemove->GetType(); if( iType == IT_DOOR || iType == IT_LOCKEDDOOR || iType == IT_HOUSESIGN ) iRemove->Delete(); else { if( iRemove->IsLockedDown() ) iRemove->SetMovable( 1 ); iRemove->SetMulti( INVALIDSERIAL ); iRemove->SetZ( GetZ() ); } } } for( CChar *cRemove = charInMulti.First(); !charInMulti.Finished(); cRemove = charInMulti.Next() ) { if( ValidateObject( cRemove ) ) { cRemove->SetMulti( INVALIDSERIAL ); cRemove->SetZ( GetZ() ); } } CItem::Cleanup(); }
//o---------------------------------------------------------------------------o //| Function : void restockNPC(CChar *i, bool stockAll) //| Date : Unknown //| Programmer : UOX3 DevTeam //o---------------------------------------------------------------------------o //| Purpose : Restock NPC Vendors //o---------------------------------------------------------------------------o void restockNPC(CChar& i, bool stockAll) { if (!i.IsShop()) return; // if we aren't a shopkeeper, why bother? CItem *ci = i.GetItemAtLayer(IL_SELLCONTAINER); if (ValidateObject(ci)) { CDataList< CItem * > *ciCont = ci->GetContainsList(); for (CItem *c = ciCont->First(); !ciCont->Finished(); c = ciCont->Next()) if (ValidateObject(c)) { if (stockAll) { c->IncAmount(c->GetRestock()); c->SetRestock(0); } else if (c->GetRestock()) { UI16 stockAmt = UOX_MIN(c->GetRestock(), static_cast<UI16>((c->GetRestock() / 2) + 1)); c->IncAmount(stockAmt); c->SetRestock(c->GetRestock() - stockAmt); } if (cwmWorldState->ServerData()->TradeSystemStatus()) { CTownRegion *tReg = calcRegionFromXY(i.GetX(), i.GetY(), i.WorldNumber()); Items->StoreItemRandomValue(c, tReg); } } } }
bool CPITradeMessage::Handle( void ) { CItem *tradeWindowOne = calcItemObjFromSer( tSock->GetDWord( 4 ) ); CItem *tradeWindowTwo = NULL; if( ValidateObject( tradeWindowOne ) ) { switch( tSock->GetByte( 3 ) ) { case 0://Start trade - Never happens, sent out by the server only. break; case 2://Change check marks. Possibly conclude trade tradeWindowTwo = calcItemObjFromSer( tradeWindowOne->GetTempVar( CITV_MOREX ) ); if( ValidateObject( tradeWindowTwo ) ) { tradeWindowOne->SetTempVar( CITV_MOREZ, tSock->GetByte( 11 ) ); sendTradeStatus( tradeWindowOne, tradeWindowTwo ); if( tradeWindowOne->GetTempVar( CITV_MOREZ ) && tradeWindowTwo->GetTempVar( CITV_MOREZ ) ) completeTrade( tradeWindowOne, tradeWindowTwo, true ); } break; case 1://Cancel trade. Send each person cancel messages, move items. cancelTrade( tradeWindowOne ); break; default: Console.Error( " Fallout of switch statement without default. trade.cpp, trademsg()" ); break; } } return true; }
//o--------------------------------------------------------------------------o //| Function - void CWeight::subtractItemWeight( CItem *pack, CItem *item ) //| Date - 2/23/2003 //| Developers - Zane //| Organization - UOX3 DevTeam //o--------------------------------------------------------------------------o //| Description - Subtracts an items weight from the total weight of the pack updating //| the packs container in the process //o--------------------------------------------------------------------------o void CWeight::subtractItemWeight( CItem *pack, CItem *item ) { SI32 totalWeight = pack->GetWeight(); if( calcSubtractWeight( item, totalWeight ) ) pack->SetWeight( totalWeight, false ); else pack->SetWeight( 0, false ); CBaseObject *pCont = pack->GetCont(); if( ValidateObject( pCont ) ) { if( pCont->CanBeObjType( OT_ITEM ) ) { CItem *pPack = static_cast<CItem *>(pCont); if( ValidateObject( pPack ) ) subtractItemWeight( pPack, item ); } else { CChar *packOwner = static_cast<CChar *>(pCont); if( ValidateObject( packOwner ) ) { if( IsWeightedContainer( pack ) ) subtractItemWeight( packOwner, item ); } } } }
//o---------------------------------------------------------------------------o //| Function - UI16 getDist( CBaseObject *a, CBaseObject *b ) //| Programmer - Unknown //o---------------------------------------------------------------------------o //| Purpose - Get the distance between two objects //o---------------------------------------------------------------------------o UI16 getDist( CBaseObject *a, CBaseObject *b ) { if( !ValidateObject( a ) || !ValidateObject( b ) ) return DIST_OUTOFRANGE; if( a == b ) return DIST_SAMETILE; if( a->WorldNumber() != b->WorldNumber() ) return DIST_OUTOFRANGE; return getDist( a->GetLocation(), b->GetLocation() ); }
UI16 getDist3D( CBaseObject *a, CBaseObject *b ) { if( !ValidateObject( a ) || !ValidateObject( b ) ) return DIST_OUTOFRANGE; if( a == b ) return DIST_SAMETILE; if( a->WorldNumber() != b->WorldNumber() ) return DIST_OUTOFRANGE; point3 difference = a->GetLocation() - b->GetLocation(); return static_cast<UI16>(difference.Mag3D()); }
void sendTradeStatus( CItem *tradeWindowOne, CItem *tradeWindowTwo ) { CChar *p1 = FindItemOwner( tradeWindowOne ); CChar *p2 = FindItemOwner( tradeWindowTwo ); if( !ValidateObject( p1 ) || !ValidateObject( p2 ) ) return; CSocket *s1 = p1->GetSocket(); CSocket *s2 = p2->GetSocket(); if( s1 != NULL && s2 != NULL ) sendTradeStatus( s1, s2, tradeWindowOne, tradeWindowTwo ); }
//o--------------------------------------------------------------------------o //| Function - bool HandleLine( UString &UTag, UString &data ) //| Date - Unknown //| Programmer - Abaddon //| Modified - //o--------------------------------------------------------------------------o //| Purpose - Processes a tag/data pair if it can. If it can, returns //| true. Otherwise, returns false. //o--------------------------------------------------------------------------o bool CMultiObj::HandleLine( UString &UTag, UString &data ) { bool rvalue = CItem::HandleLine( UTag, data ); if( !rvalue ) { switch( (UTag.data()[0]) ) { case 'B': if( UTag == "BANNED" ) { CChar *bList = calcCharObjFromSer( data.toULong() ); if( ValidateObject( bList ) ) AddToBanList( bList ); rvalue = true; } break; case 'C': if( UTag == "COOWNER" ) { CChar *cList = calcCharObjFromSer( data.toULong() ); if( ValidateObject( cList ) ) AddAsOwner( cList ); rvalue = true; } break; case 'D': if( UTag == "DEEDNAME" ) { SetDeed( data ); rvalue = true; } break; case 'L': if( UTag == "LOCKEDITEM" ) { CItem *iList = calcItemObjFromSer( data.toULong() ); if( ValidateObject( iList ) ) LockDownItem( iList ); rvalue = true; } break; case 'M': if( UTag == "MAXLOCKEDDOWN" ) { maxLockedDown = data.toUShort(); rvalue = true; } break; } } return rvalue; }
UI16 getOldDist( CBaseObject *a, CBaseObject *b ) { if( !ValidateObject( a ) || !ValidateObject( b ) ) return DIST_OUTOFRANGE; if( a == b ) return DIST_SAMETILE; if( a->WorldNumber() != b->WorldNumber() ) return DIST_OUTOFRANGE; point3 distA; point3 distB; distA = a->GetOldLocation(); distB = b->GetLocation(); point3 difference = distA - distB; return static_cast<UI16>(difference.Mag()); }
void WebGLContext::BindBuffer(GLenum target, WebGLBuffer* buffer) { const FuncScope funcScope(*this, "bindBuffer"); if (IsContextLost()) return; if (buffer && !ValidateObject("buffer", *buffer)) return; const auto& slot = ValidateBufferSlot(target); if (!slot) return; if (buffer && !buffer->ValidateCanBindToTarget(target)) return; gl->fBindBuffer(target, buffer ? buffer->mGLName : 0); WebGLBuffer::SetSlot(target, buffer, slot); if (buffer) { buffer->SetContentAfterBind(target); } switch (target) { case LOCAL_GL_PIXEL_PACK_BUFFER: case LOCAL_GL_PIXEL_UNPACK_BUFFER: gl->fBindBuffer(target, 0); break; } }
//o--------------------------------------------------------------------------o //| Function - SI32 CWeight::calcWeight( CItem *pack ) //| Date - 2/23/2003 //| Developers - Zane //| Organization - UOX3 DevTeam //o--------------------------------------------------------------------------o //| Description - Calculate the total weight of a pack based upon all items inside, //| their amounts, etc. This function should never need to be called //| but is available for bruteforce weight updating //o--------------------------------------------------------------------------o SI32 CWeight::calcWeight( CItem *pack ) { SI32 totalWeight = 0; SI32 contWeight = 0; CDataList< CItem * > *pCont = pack->GetContainsList(); for( CItem *i = pCont->First(); !pCont->Finished(); i = pCont->Next() ) { if( !ValidateObject( i ) ) continue; if( i->IsContType() ) // Item is a container { CTile& tile = Map->SeekTile( i->GetID() ); contWeight = static_cast<SI32>( tile.Weight() * 100); // Add the weight of the container contWeight += calcWeight( i ); // Find and add the weight of the items in the container i->SetWeight( contWeight, false ); // Also update the weight property of the container totalWeight += contWeight; if( totalWeight >= MAX_WEIGHT ) return MAX_WEIGHT; } else { if( !calcAddWeight( i, totalWeight ) ) return MAX_WEIGHT; } } return totalWeight; }
void WebGL2Context::GetUniformIndices(WebGLProgram* program, const dom::Sequence<nsString>& uniformNames, dom::Nullable< nsTArray<GLuint> >& retval) { retval.SetNull(); if (IsContextLost()) return; if (!ValidateObject("getUniformIndices: program", program)) return; if (!uniformNames.Length()) return; GLuint progname = program->mGLName; size_t count = uniformNames.Length(); nsTArray<GLuint>& arr = retval.SetValue(); MakeContextCurrent(); for (size_t n = 0; n < count; n++) { NS_LossyConvertUTF16toASCII name(uniformNames[n]); // const GLchar* glname = name.get(); const GLchar* glname = nullptr; name.BeginReading(glname); GLuint index = 0; gl->fGetUniformIndices(progname, 1, &glname, &index); arr.AppendElement(index); } }
//o--------------------------------------------------------------------------o //| Function - SI32 CWeight::calcCharWeight( CChar *mChar ) //| Date - 2/23/2003 //| Developers - Zane //| Organization - UOX3 DevTeam //o--------------------------------------------------------------------------o //| Description - Calculate the total weight of a character based upon all items he owns, //| This function should never need to be called but is available for //| bruteforce weight updating //o--------------------------------------------------------------------------o SI32 CWeight::calcCharWeight( CChar *mChar ) { SI32 totalWeight = 0; SI32 contWeight = 0; for( CItem *i = mChar->FirstItem(); !mChar->FinishedItems(); i = mChar->NextItem() ) { if( !ValidateObject( i ) ) continue; if( IsWeightedContainer( i ) ) { if( i->GetLayer() == IL_PACKITEM ) { CTile& tile = Map->SeekTile( i->GetID() ); contWeight = static_cast<SI32>( tile.Weight() * 100); // Add the weight of the container contWeight += calcWeight( i ); // Find and add the weight of the items in the container i->SetWeight( contWeight, false ); // Also update the weight property of the container totalWeight += contWeight; } else totalWeight += i->GetWeight(); // Normal item, just add its weight } if( totalWeight >= MAX_WEIGHT ) return MAX_WEIGHT; } return totalWeight; }
void WebGL2Context::GetActiveUniforms(WebGLProgram* program, const dom::Sequence<GLuint>& uniformIndices, GLenum pname, dom::Nullable< nsTArray<GLint> >& retval) { retval.SetNull(); if (IsContextLost()) return; if (pname == LOCAL_GL_UNIFORM_NAME_LENGTH) { ErrorInvalidEnumInfo("getActiveUniforms: pname", pname); return; } if (!ValidateObject("getActiveUniforms: program", program)) return; size_t count = uniformIndices.Length(); if (!count) return; GLuint progname = program->mGLName; nsTArray<GLint>& arr = retval.SetValue(); arr.SetLength(count); MakeContextCurrent(); gl->fGetActiveUniformsiv(progname, count, uniformIndices.Elements(), pname, arr.Elements()); }
void WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, WebGLProgram* program, GLuint uniformBlockIndex, GLenum pname, dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval, ErrorResult& rv) { retval.SetNull(); if (IsContextLost()) return; if (!ValidateObject("getActiveUniformBlockParameter: program", program)) return; MakeContextCurrent(); switch(pname) { case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: case LOCAL_GL_UNIFORM_BLOCK_BINDING: case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE: case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: program->GetActiveUniformBlockParam(uniformBlockIndex, pname, retval); return; case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: program->GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex, retval, rv); return; } ErrorInvalidEnumInfo("getActiveUniformBlockParameter: parameter", pname); }
void WebGLContext::BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer) { const FuncScope funcScope(*this, "bindBufferBase"); if (IsContextLost()) return; if (buffer && !ValidateObject("buffer", *buffer)) return; WebGLRefPtr<WebGLBuffer>* genericBinding; IndexedBufferBinding* indexedBinding; if (!ValidateIndexedBufferBinding(target, index, &genericBinding, &indexedBinding)) { return; } if (buffer && !buffer->ValidateCanBindToTarget(target)) return; //// gl->fBindBufferBase(target, index, buffer ? buffer->mGLName : 0); //// WebGLBuffer::SetSlot(target, buffer, genericBinding); WebGLBuffer::SetSlot(target, buffer, &indexedBinding->mBufferBinding); indexedBinding->mRangeStart = 0; indexedBinding->mRangeSize = 0; if (buffer) { buffer->SetContentAfterBind(target); } }
void WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, const WebGLProgram& program, GLuint uniformBlockIndex, GLenum pname, JS::MutableHandleValue out_retval, ErrorResult& out_error) { out_retval.setNull(); if (IsContextLost()) return; if (!ValidateObject("getActiveUniformBlockParameter: program", program)) return; MakeContextCurrent(); switch(pname) { case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: case LOCAL_GL_UNIFORM_BLOCK_BINDING: case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE: case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: out_retval.set(program.GetActiveUniformBlockParam(uniformBlockIndex, pname)); return; case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: out_retval.set(program.GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex, &out_error)); return; } ErrorInvalidEnumInfo("getActiveUniformBlockParameter: parameter", pname); }
GLuaVec_t *GLua_CheckVector(lua_State *L, int idx) { //GLuaVec_t *vec; if (!ValidateObject(L, idx, GO_VECTOR)) { luaL_typerror(L, idx, "Vector"); } return (GLuaVec_t *)lua_touserdata(L,idx); }
void WebGLContext::BindVertexArray(WebGLVertexArray* array) { if (IsContextLost()) return; if (array && !ValidateObject("bindVertexArrayObject", *array)) return; InvalidateBufferFetching(); MakeContextCurrent(); if (mBoundVertexArray) { mBoundVertexArray->AddBufferBindCounts(-1); } if (array == nullptr) { array = mDefaultVertexArray; } array->BindVertexArray(); MOZ_ASSERT(mBoundVertexArray == array); if (mBoundVertexArray) { mBoundVertexArray->AddBufferBindCounts(+1); } }
//o---------------------------------------------------------------------------o //| Function - bool charInRange( CChar *a, CChar *b ) //| Programmer - Unknown //o---------------------------------------------------------------------------o //| Purpose - Check if characters a and b are in visual range //o---------------------------------------------------------------------------o bool charInRange( CChar *a, CChar *b ) { if( !ValidateObject( a ) ) return false; SI16 visRange = MAX_VISRANGE + Races->VisRange( a->GetRace() ); return objInRange( a, b, static_cast<UI16>(visRange) ); }
int GLua_IsVector(lua_State *L, int idx) { //GLuaVec_t *vec; if (!ValidateObject(L, idx, GO_VECTOR)) { return 0; } return 1; }
void WebGLContext::BindVertexArray(WebGLVertexArray* array) { const FuncScope funcScope(*this, "bindVertexArray"); if (IsContextLost()) return; if (array && !ValidateObject("array", *array)) return; if (mBoundVertexArray) { mBoundVertexArray->AddBufferBindCounts(-1); } if (array == nullptr) { array = mDefaultVertexArray; } array->BindVertexArray(); MOZ_ASSERT(mBoundVertexArray == array); if (mBoundVertexArray) { mBoundVertexArray->AddBufferBindCounts(+1); mBoundVertexArray->mHasBeenBound = true; } }
//o---------------------------------------------------------------------------o //| Function : CItem *startTrade( CSocket *mSock, CChar *nChar ) //| Date : February 2, 2006 //| Programmer : giwo //o---------------------------------------------------------------------------o //| Purpose : Handles everything necesarry to start a secure trade //o---------------------------------------------------------------------------o CItem *startTrade( CSocket *mSock, CChar *nChar ) { if( mSock == NULL || !ValidateObject( nChar ) ) return NULL; CChar *mChar = mSock->CurrcharObj(); CSocket *nSock = nChar->GetSocket(); if( !ValidateObject( mChar ) || nSock == NULL ) return NULL; CItem *tradeWindowOne = CreateTradeWindow( mSock, nSock, mChar ); if( !ValidateObject( tradeWindowOne ) ) return NULL; CItem *tradeWindowTwo = CreateTradeWindow( nSock, mSock, nChar ); if( !ValidateObject( tradeWindowTwo ) ) { tradeWindowOne->Delete(); return NULL; } const SERIAL tw1Serial = tradeWindowOne->GetSerial(); const SERIAL tw2Serial = tradeWindowTwo->GetSerial(); tradeWindowOne->SetTempVar( CITV_MOREX, tw2Serial ); tradeWindowTwo->SetTempVar( CITV_MOREX, tw1Serial ); CPSecureTrading cpstOne( (*nChar), tw1Serial, tw2Serial ); cpstOne.Name( nChar->GetName() ); mSock->Send( &cpstOne ); CPSecureTrading cpstTwo( (*mChar), tw2Serial, tw1Serial ); cpstTwo.Name( mChar->GetName() ); nSock->Send( &cpstTwo ); CPWornItem toWear = (*tradeWindowOne); mSock->Send( &toWear ); nSock->Send( &toWear ); CPWornItem toWear2 = (*tradeWindowTwo); mSock->Send( &toWear2 ); nSock->Send( &toWear2 ); return tradeWindowOne; }
bool restockFunctor(CBaseObject *a, UI32 &b, void *extraData) { bool retVal = true; CChar *c = static_cast< CChar * >(a); if (ValidateObject(c)) restockNPC((*c), (b == 1)); return retVal; }
GLua_Bitstream_t *GLua_CheckBitStream(lua_State *L, int idx) { GLua_Bitstream_t *data; if (!ValidateObject(L, idx, GO_BITSTREAM)) { luaL_typerror(L, idx, "Bitstream"); } data = (GLua_Bitstream_t *)lua_touserdata(L, idx); return data; }
GLuint WebGL2Context::GetUniformBlockIndex(const WebGLProgram& program, const nsAString& uniformBlockName) { const FuncScope funcScope(*this, "getUniformBlockIndex"); if (IsContextLost()) return 0; if (!ValidateObject("program", program)) return 0; return program.GetUniformBlockIndex(uniformBlockName); }
//o--------------------------------------------------------------------------o //| Function - SetOwner( CChar *newOwner ) //| Date - Unknown //| Programmer - Abaddon //| Modified - //o--------------------------------------------------------------------------o //| Purpose - Ensures that newOwner is also on the house ownership //| list. //o--------------------------------------------------------------------------o void CMultiObj::SetOwner( CChar *newOwner ) { if( ValidateObject( newOwner ) ) { owner = newOwner->GetSerial(); AddAsOwner( newOwner ); } else owner = INVALIDSERIAL; }
void WebGL2Context::UniformBlockBinding(WebGLProgram& program, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { const FuncScope funcScope(*this, "uniformBlockBinding"); if (IsContextLost()) return; if (!ValidateObject("program", program)) return; program.UniformBlockBinding(uniformBlockIndex, uniformBlockBinding); }