From: Kenny G. <ken...@us...> - 2007-04-11 17:52:29
|
Update of /cvsroot/planeshift/planeshift/src/server/bulkobjects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18846/src/server/bulkobjects Modified Files: pscharacter.cpp pscharacter.h Log Message: - Refactor dropping, part 1: removed SlotManager::DropInWorld, updated psCharacter's DropItem to do everything needed. Index: pscharacter.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/pscharacter.cpp,v retrieving revision 1.473 retrieving revision 1.474 diff -C2 -d -r1.473 -r1.474 *** pscharacter.cpp 11 Apr 2007 02:45:21 -0000 1.473 --- pscharacter.cpp 11 Apr 2007 17:52:28 -0000 1.474 *************** *** 1202,1210 **** } ! void psCharacter::DropItem( psItem * & item, bool transient ) { if (!item) return; // If we're dropping from inventory, we should properly remove it. // No need to check the return value: we're removing the whole item and --- 1202,1236 ---- } ! void psCharacter::DropItem(psItem *item, csVector3 suggestedPos, bool transient) { if (!item) return; + // Handle position... + if (suggestedPos != 0) + { + // User-specified position...check if it's close enough to the character. + + csVector3 delta; + delta.x = location.loc_x - suggestedPos.x; + delta.y = location.loc_y - suggestedPos.y; + delta.z = location.loc_z - suggestedPos.z; + + float dist = delta.Norm(); + + // Future: Could make it drop in the direction specified, if not at the + // exact location... + if (dist > 2) // max drop distance is 15m + suggestedPos = 0; + } + + if (suggestedPos == 0) + { + // No position specified or it was invalid. + suggestedPos.x = location.loc_x - (DROP_DISTANCE * sin(location.loc_yrot)); + suggestedPos.y = location.loc_y; + suggestedPos.z = location.loc_z - (DROP_DISTANCE * cos(location.loc_yrot)); + } + // If we're dropping from inventory, we should properly remove it. // No need to check the return value: we're removing the whole item and *************** *** 1212,1234 **** inventory.RemoveItemID(item->GetUID()); ! item->SetOwningCharacter(NULL); ! item->SetLocationInWorld( location.worldInstance, ! location.loc_sector, ! location.loc_x - (DROP_DISTANCE * sin(location.loc_yrot)), ! location.loc_y, ! location.loc_z - (DROP_DISTANCE * cos(location.loc_yrot)), ! location.loc_yrot ); ! ! EntityManager::GetSingleton().CreateItem( item, transient ); // Play the drop item sound for this item psserver->GetCharManager()->SendOutPlaySoundMessage( actor->GetClientID(), item->GetSound(), "drop" ); ! item->Save(true); ! ! // Announce drop (disabled pending a drop animation) ! //psSystemMessage newmsg(actor->GetClientID(), MSG_INFO, "%s dropped %s", name.GetData(), item->GetQuantityName().GetData() ); ! //newmsg.Multicast(actor->GetMulticastClients(),0,RANGE_TO_SELECT); } --- 1238,1269 ---- inventory.RemoveItemID(item->GetUID()); ! gemObject* obj = EntityManager::GetSingleton().MoveItemToWorld(item, ! location.worldInstance, location.loc_sector, ! suggestedPos.x, suggestedPos.y, suggestedPos.z, ! location.loc_yrot, this, transient); ! // If a container, move its contents as well... ! gemContainer *cont = dynamic_cast<gemContainer*> (obj); ! if (cont) ! { ! for (size_t i=0; i < Inventory().GetInventoryIndexCount(); i++) ! { ! psItem *item = Inventory().GetInventoryIndexItem(i); ! if (item->GetContainerID() == cont->GetItem()->GetUID()) ! { ! // This item is in the dropped container ! Inventory().RemoveItemIndex(i); ! cont->AddToContainer(item); ! item->Save(false); ! } ! } ! } // Play the drop item sound for this item psserver->GetCharManager()->SendOutPlaySoundMessage( actor->GetClientID(), item->GetSound(), "drop" ); ! // Announce drop (in the future, there should be a drop animation) ! psSystemMessage newmsg(actor->GetClientID(), MSG_INFO, "%s dropped %s", name.GetData(), item->GetQuantityName().GetData() ); ! newmsg.Multicast(actor->GetMulticastClients(),0,RANGE_TO_SELECT); } Index: pscharacter.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/pscharacter.h,v retrieving revision 1.228 retrieving revision 1.229 diff -C2 -d -r1.228 -r1.229 *** pscharacter.h 2 Apr 2007 05:25:50 -0000 1.228 --- pscharacter.h 11 Apr 2007 17:52:28 -0000 1.229 *************** *** 826,830 **** * @param Transient flag (decay?) (default=true) */ ! void DropItem( psItem * & item, bool transient = true); void CreateGlyphList(bool purifiedOnly, csArray <glyphSlotInfo> & slots); --- 826,830 ---- * @param Transient flag (decay?) (default=true) */ ! void DropItem(psItem *item, csVector3 pos = 0, bool transient = true); void CreateGlyphList(bool purifiedOnly, csArray <glyphSlotInfo> & slots); |