From 895367162ca140d32b3ac6a03a4c98542a2803ea Mon Sep 17 00:00:00 2001 From: Wanne Date: Sun, 24 May 2009 20:50:18 +0000 Subject: [PATCH] - Bugfix: New Airport code was not working correctly for multiplayer version (merged changes from MP branch) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2883 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Laptop/BobbyRMailOrder.cpp | 6 +- Laptop/PostalService.cpp | 181 ++++++++++++++++++++++++++++++++++++- Laptop/PostalService.h | 2 + ja2_2005Express.vcproj | 6 +- ja2_VS2008.vcproj | 4 +- 5 files changed, 191 insertions(+), 8 deletions(-) diff --git a/Laptop/BobbyRMailOrder.cpp b/Laptop/BobbyRMailOrder.cpp index 12f4213e..11660424 100644 --- a/Laptop/BobbyRMailOrder.cpp +++ b/Laptop/BobbyRMailOrder.cpp @@ -342,7 +342,9 @@ void BobbyRDeliveryCallback(RefToCShipmentManipulator ShipmentManipulator) { // ScreenMsg(FONT_MCOLOR_RED, MSG_DEBUG, L"Shipment from Bobby Ray has arrived at %s!", ShipmentManipulator.GetDestination().wstrName.c_str()); gusCurShipmentDestinationID = ShipmentManipulator.GetDestination().usID; - AddEmail( BOBBYR_SHIPMENT_ARRIVED, BOBBYR_SHIPMENT_ARRIVED_LENGTH, BOBBY_R, GetWorldTotalMin(), -1 ); + // WANNE - MP: Do not send email notification from Bobby Ray in a multiplayer game + if (!is_networked) + AddEmail( BOBBYR_SHIPMENT_ARRIVED, BOBBYR_SHIPMENT_ARRIVED_LENGTH, BOBBY_R, GetWorldTotalMin(), -1 ); } @@ -821,7 +823,7 @@ void BtnBobbyRAcceptOrderCallback(GUI_BUTTON *btn,INT32 reason) if( (gDestinationTable[gbSelectedCity]->ubMapX >= 0 || gDestinationTable[gbSelectedCity]->ubMapY >= 0 || gDestinationTable[gbSelectedCity]->sGridNo >= 0) && - !StrategicMap[ CALCULATE_STRATEGIC_INDEX(gDestinationTable[gbSelectedCity]->ubMapX, gDestinationTable[gbSelectedCity]->ubMapY) ].fEnemyControlled ) + !StrategicMap[ CALCULATE_STRATEGIC_INDEX(gDestinationTable[gbSelectedCity]->ubMapX, gDestinationTable[gbSelectedCity]->ubMapY) ].fEnemyControlled || is_client) //End Dealtar's Code. { //Quick hack to bypass the confirmation box diff --git a/Laptop/PostalService.cpp b/Laptop/PostalService.cpp index b6d6199f..fae8bf50 100644 --- a/Laptop/PostalService.cpp +++ b/Laptop/PostalService.cpp @@ -11,6 +11,9 @@ #include #include +// WANNE - MP: Used for multiplayer +#include "connect.h" +#include "Strategic Event Handler.h" using namespace std; /************************************************************************************/ @@ -82,6 +85,15 @@ OBJECTTYPE CPostalService::tempObject; CPostalService::CPostalService() { } +void CPostalService::Clear() +{ + _Shipments.clear(); + _UsedShipmentIDList.clear();; + _DeliveryCallbacks.clear(); + _Destinations.clear(); + _UsedDestinationIDList.clear(); + _DeliveryMethods.clear(); +} UINT16 CPostalService::CreateNewShipment(UINT16 usDestinationID, UINT8 ubDeliveryMethodIndex, INT16 sSenderID) { @@ -201,8 +213,18 @@ BOOLEAN CPostalService::SendShipment(UINT16 usShipmentID) SHIPMENT(sli).ShipmentStatus = SHIPMENT_INTRANSIT; - AddFutureDayStrategicEvent( EVENT_POSTAL_SERVICE_SHIPMENT, (8 + Random(4) ) * 60, usShipmentID, + if (is_networked) + { + if (is_client) + { + this->DeliverShipmentForMultiplayer(usShipmentID); + } + } + else + { + AddFutureDayStrategicEvent( EVENT_POSTAL_SERVICE_SHIPMENT, (8 + Random(4) ) * 60, usShipmentID, SHIPMENT(sli).pDestinationDeliveryInfo->bDaysAhead); + } return TRUE; } @@ -369,6 +391,163 @@ BOOLEAN CPostalService::DeliverShipment(UINT16 usShipmentID) return FALSE; } +BOOLEAN CPostalService::DeliverShipmentForMultiplayer(UINT16 usShipmentID) +{ + if( usShipmentID > _UsedShipmentIDList.size() || + !_UsedShipmentIDList[usShipmentID]) + { + Assert(0); + return FALSE; + } + + RefToShipmentListIterator sli = _Shipments.begin(); + + while(SHIPMENT(sli).usID != usShipmentID) + { + if(sli == _Shipments.end()) + { + Assert(0); + return FALSE; + } + sli++; + } + + if(SHIPMENT(sli).ShipmentStatus == SHIPMENT_STATIONARY) + { + return FALSE; + } + + PCShipmentManipulator ShipmentManipulator = new CShipmentManipulator(this, &SHIPMENT(sli)); + + // Delivery callback code goes here + if(_DeliveryCallbacks[0].DeliveryCallbackFunc) + { + _DeliveryCallbacks[0].DeliveryCallbackFunc(*ShipmentManipulator); + } + + if(ShipmentManipulator->_fContinueCallbackChain) + { + if( SHIPMENT(sli).sSenderID + 2 <= (INT16)_DeliveryCallbacks.size() && + _DeliveryCallbacks[SHIPMENT(sli).sSenderID + 1].DeliveryCallbackFunc) + { + _DeliveryCallbacks[SHIPMENT(sli).sSenderID + 1].DeliveryCallbackFunc(*ShipmentManipulator); + } + } + + + if(SHIPMENT(sli).ShipmentStatus == SHIPMENT_CANCEL_DELIVERY) + { + SHIPMENT(sli).ShipmentStatus = SHIPMENT_STATIONARY; + return FALSE; + } + + + RefToShipmentStruct shs = SHIPMENT(sli); + + if( (shs.pDestination->ubMapX > 0) && + (shs.pDestination->ubMapX < MAP_WORLD_X - 1) && + (shs.pDestination->ubMapY > 0) && + (shs.pDestination->ubMapY < MAP_WORLD_Y - 1) && + GridNoOnVisibleWorldTile(shs.pDestination->sGridNo) ) + { + BOOLEAN fSectorLoaded = ( gWorldSectorX == shs.pDestination->ubMapX ) && + ( gWorldSectorY == shs.pDestination->ubMapY ) && + ( gbWorldSectorZ == shs.pDestination->ubMapZ); + + if(fSectorLoaded) + { + SetOpenableStructureToClosed( shs.pDestination->sGridNo, 0 ); + } + else + { + ChangeStatusOfOpenableStructInUnloadedSector( shs.pDestination->ubMapX, shs.pDestination->ubMapY, + shs.pDestination->ubMapZ, shs.pDestination->sGridNo, FALSE ); + } + + UINT16 usNumberOfItems=0; + for(int i = 0; i < (int)shs.ShipmentPackages.size(); i++) + { + usNumberOfItems += shs.ShipmentPackages[i].ubNumber; + } + + OBJECTTYPE *pObject; + if(!fSectorLoaded) + { + pObject = new OBJECTTYPE[usNumberOfItems]; + + if(!pObject) + { + Assert(0); + return FALSE; + } + } + + UINT uiCount=0; + UINT8 ubItemsDelivered, ubTempNumItems; + UINT16 usItem; + + for(int i=0; i < (int)shs.ShipmentPackages.size(); i++) + { + ubItemsDelivered = shs.ShipmentPackages[i].ubNumber; + usItem = shs.ShipmentPackages[i].usItemIndex; + + CreateItem(usItem, 100, &tempObject); + + while ( ubItemsDelivered ) + { + //ubTempNumItems = __min( ubItemsDelivered, ItemSlotLimit(usItem, BIGPOCK1POS) ); + + if (UsingNewInventorySystem() == false) + { + ubTempNumItems = __min( ubItemsDelivered, ItemSlotLimit(&tempObject, BIGPOCK1POS) ); + } + else + { + ubTempNumItems = __min( ubItemsDelivered, ItemSlotLimit(&tempObject, STACK_SIZE_LIMIT) ); + } + + CreateItems( usItem, shs.ShipmentPackages[i].bItemQuality, ubTempNumItems, &tempObject ); + + if( fSectorLoaded ) + { + AddItemToPool( 12880, &tempObject, 1, 0, WOLRD_ITEM_FIND_SWEETSPOT_FROM_GRIDNO | WORLD_ITEM_REACHABLE, 0 ); + } + else + { + pObject[ uiCount ] = tempObject; + uiCount++; + } + + ubItemsDelivered -= ubTempNumItems; + } + } + + if( !fSectorLoaded ) + { + if( !AddItemsToUnLoadedSector( gsMercArriveSectorX, gsMercArriveSectorY, + 0, 12880, uiCount, pObject, 0, WOLRD_ITEM_FIND_SWEETSPOT_FROM_GRIDNO | WORLD_ITEM_REACHABLE, 0, 1, FALSE ) ) + { + Assert( 0 ); + } + delete[]( pObject ); + pObject = NULL; + } + + shs.ShipmentPackages.clear(); + shs.pDestination = NULL; + shs.pDestinationDeliveryInfo = NULL; + shs.ShipmentStatus = SHIPMENT_STATIONARY; + _UsedShipmentIDList[usShipmentID] = FALSE; + + _Shipments.erase(sli); + + return TRUE; + } + else + Assert(0); + + return FALSE; +} BOOLEAN CPostalService::RegisterDeliveryCallback(INT16 sSenderID, PtrToDeliveryCallbackFunc DeliveryCallbackFunc) { if(sSenderID < - 1 || !DeliveryCallbackFunc) diff --git a/Laptop/PostalService.h b/Laptop/PostalService.h index 27779a28..6297e40d 100644 --- a/Laptop/PostalService.h +++ b/Laptop/PostalService.h @@ -205,6 +205,7 @@ public: BOOLEAN AddPackageToShipment(UINT16 usShipmentID, UINT16 usItemIndex, UINT8 ubNumber, INT8 bItemQuality); BOOLEAN SendShipment(UINT16 usShipmentID); BOOLEAN DeliverShipment(UINT16 usShipmentID); + BOOLEAN DeliverShipmentForMultiplayer(UINT16 usShipmentID); BOOLEAN RegisterDeliveryCallback(INT16 sSenderID, PtrToDeliveryCallbackFunc DeliveryCallbackFunc); // Interfaces @@ -228,6 +229,7 @@ public: UINT16 GetDestinationFee(UINT8 ubDeliveryMethodIndex, UINT16 usDestinationID); RefToDeliveryMethodStruct GetDeliveryMethod(UINT8 ubDeliveryMethodIndex) const; + void Clear(); CPostalService(); private: ShipmentList _Shipments; diff --git a/ja2_2005Express.vcproj b/ja2_2005Express.vcproj index 257e0a06..5c991e4b 100644 --- a/ja2_2005Express.vcproj +++ b/ja2_2005Express.vcproj @@ -17,7 +17,7 @@