@@ -542,12 +542,10 @@ bool GameActivity::CreateDelivery(int player, int mode, Vector& waypoint, Actor*
542542 totalCost = pDeliveryCraft->GetGoldValue (nativeModule, foreignCostMult, nativeCostMult);
543543 }
544544
545- // Go through the list of things ordered, and give any actors all the items that is present after them,
546- // until the next actor. Also, the first actor gets all stuff in the list above him.
547- MovableObject* pInventoryObject = 0 ;
548- Actor* pPassenger = 0 ;
549- Actor* pLastPassenger = 0 ;
550- std::list<MovableObject*> cargoItems;
545+ // Go through the list of things ordered, and give any actors all the items that is present after them, until the next actor.
546+ MovableObject* pInventoryObject = nullptr ;
547+ Actor* pPassenger = nullptr ;
548+ Actor* pLastPassenger = nullptr ;
551549
552550 for (std::list<const SceneObject*>::iterator itr = purchaseList.begin (); itr != purchaseList.end (); ++itr) {
553551 bool purchaseItem = true ;
@@ -568,66 +566,37 @@ bool GameActivity::CreateDelivery(int player, int mode, Vector& waypoint, Actor*
568566 if (purchaseItem) {
569567 // Make copy of the preset instance in the list
570568 pInventoryObject = dynamic_cast <MovableObject*>((*itr)->Clone ());
571- // See if it's actually a passenger, as opposed to a regular item
569+
570+ if (pPassenger) {
571+ pLastPassenger = pPassenger;
572+ }
573+
572574 pPassenger = dynamic_cast <Actor*>(pInventoryObject);
575+
573576 // If it's an actor, then set its team and add it to the Craft's inventory!
574577 if (pPassenger) {
575- if (dynamic_cast <AHuman*>(pPassenger)) {
576- // If this is the first passenger, then give him all the shit found in the list before him
577- if (!pLastPassenger) {
578- for (std::list<MovableObject*>::iterator iItr = cargoItems.begin (); iItr != cargoItems.end (); ++iItr)
579- pPassenger->AddInventoryItem (*iItr);
580- }
581- // This isn't the first passenger, so give the previous guy all the stuff that was found since processing him
582- else {
583- for (std::list<MovableObject*>::iterator iItr = cargoItems.begin (); iItr != cargoItems.end (); ++iItr)
584- pLastPassenger->AddInventoryItem (*iItr);
585- }
586-
587- // Now set the current passenger as the 'last passenger' so he'll eventually get everything found after him.
588- pLastPassenger = pPassenger;
589- } else if (pLastPassenger) {
590- for (MovableObject* cargoItem: cargoItems) {
591- pLastPassenger->AddInventoryItem (cargoItem);
592- }
593- pLastPassenger = nullptr ;
594- }
595- // Clear out the temporary cargo list since we've assign all the stuff in it to a passenger
596- cargoItems.clear ();
597578 // Set the team etc for the current passenger and stuff him into the craft
598579 pPassenger->SetTeam (team);
599580 pPassenger->SetControllerMode (Controller::CIM_AI);
600581 pPassenger->SetAIMode ((Actor::AIMode)mode);
601582
602- if (pTargetMO != NULL ) {
603- Actor* pTarget = dynamic_cast <Actor*>(pTargetMO);
604- if (pTarget)
605- pPassenger->AddAIMOWaypoint (pTarget);
583+ if (Actor* pTarget = dynamic_cast <Actor*>(pTargetMO)) {
584+ pPassenger->AddAIMOWaypoint (pTarget);
606585 } else if (waypoint.m_X > 0 && waypoint.m_Y > 0 ) {
607586 pPassenger->AddAISceneWaypoint (waypoint);
608587 }
609588
610589 pDeliveryCraft->AddInventoryItem (pPassenger);
590+ } else if (dynamic_cast <AHuman*>(pLastPassenger)) {
591+ // Add ourselves to the last passenger's inventory
592+ pLastPassenger->AddInventoryItem (pInventoryObject);
593+ } else {
594+ // No valid AHuman actor before us, just add ourself to the craft inventory
595+ pDeliveryCraft->AddInventoryItem (pInventoryObject);
611596 }
612- // If not, then add it to the temp list of items which will be added to the last passenger's inventory
613- else
614- cargoItems.push_back (pInventoryObject);
615597 }
616598 }
617599
618- pPassenger = 0 ;
619-
620- // If there was a last passenger and things after him, stuff all the items into his inventory
621- if (pLastPassenger) {
622- for (std::list<MovableObject*>::iterator iItr = cargoItems.begin (); iItr != cargoItems.end (); ++iItr)
623- pLastPassenger->AddInventoryItem (*iItr);
624- }
625- // Otherwise, stuff it all stuff directly into the craft instead
626- else {
627- for (std::list<MovableObject*>::iterator iItr = cargoItems.begin (); iItr != cargoItems.end (); ++iItr)
628- pDeliveryCraft->AddInventoryItem (*iItr);
629- }
630-
631600 float spawnY = 0 .0f ;
632601 if (g_SceneMan.GetTerrain () && g_SceneMan.GetTerrain ()->GetOrbitDirection () == Directions::Down) {
633602 spawnY = g_SceneMan.GetSceneHeight ();
0 commit comments