From b9e8b54a69fa44117a8760dff2632113fdfb2698 Mon Sep 17 00:00:00 2001
From: Daniel Bradshaw <daniel+commits@the-cell.co.uk>
Date: Wed, 27 Jan 2010 02:08:53 +0000
Subject: [PATCH 1/2] Instead of just picking up what is below and infront of you, pick up anything adjecent to you, and walk over to anything near you to pick it up

---
 src/flooritemmanager.cpp |   27 +++++++++++++++++++++++++++
 src/flooritemmanager.h   |    1 +
 src/game.cpp             |   21 +--------------------
 3 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp
index 9bfd02a..502504c 100644
--- a/src/flooritemmanager.cpp
+++ b/src/flooritemmanager.cpp
@@ -76,3 +76,30 @@ FloorItem *FloorItemManager::findByCoordinates(int x, int y)
 
     return NULL;
 }
+
+FloorItem *FloorItemManager::findCloseToCoordinates(int x, int y)
+{
+    FloorItemIterator i;
+    for (i = mFloorItems.begin(); i != mFloorItems.end(); i++)
+    {
+        switch ((*i)->getX() - x)
+        {
+            case -2:
+            case -1:
+            case 0:
+            case 1:
+            case 2:
+                switch ((*i)->getY() - y)
+                {
+                    case -2:
+                    case -1:
+                    case 0:
+                    case 1:
+                    case 2:
+                        return *i;
+                }
+        }
+    }
+
+    return NULL;
+}
diff --git a/src/flooritemmanager.h b/src/flooritemmanager.h
index 704b39f..dee18ab 100644
--- a/src/flooritemmanager.h
+++ b/src/flooritemmanager.h
@@ -40,6 +40,7 @@ class FloorItemManager
 
         FloorItem* findById(int id);
         FloorItem* findByCoordinates(int x, int y);
+        FloorItem* findCloseToCoordinates(int x, int y);
 
     private:
         typedef std::list<FloorItem*> FloorItems;
diff --git a/src/game.cpp b/src/game.cpp
index 0cc59ff..59227eb 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -753,26 +753,7 @@ void Game::handleInput()
                             Uint16 y = (int) pos.y / 32;
 
                             FloorItem *item =
-                                floorItemManager->findByCoordinates(x, y);
-
-                            // If none below the player, try the tile in front
-                            // of the player
-                            if (!item)
-                            {
-                                // Temporary until tile-based picking is
-                                // removed.
-                                switch (player_node->getSpriteDirection())
-                                {
-                                    case DIRECTION_UP   : --y; break;
-                                    case DIRECTION_DOWN : ++y; break;
-                                    case DIRECTION_LEFT : --x; break;
-                                    case DIRECTION_RIGHT: ++x; break;
-                                    default: break;
-                                }
-
-                                item = floorItemManager->findByCoordinates(
-                                        x, y);
-                            }
+                                floorItemManager->findCloseToCoordinates(x, y);
 
                             if (item)
                                 player_node->pickUp(item);
-- 
1.6.3.3

