Index: common/WorldMap.cpp
===================================================================
--- common/WorldMap.cpp	(revision a6066e8fba1a901cdcaa9bd6ca01ab8945a4b14e)
+++ common/WorldMap.cpp	(revision e4c60ba35ab71c7d35960b98212214ce43dd724c)
@@ -63,4 +63,23 @@
 {
    (*(*vctStructures)[x])[y] = t;
+}
+
+POSITION WorldMap::getStructureLocation(StructureType t)
+{
+   POSITION pos;
+   pos.x = 0;
+   pos.y = 0;
+
+   for (int x=0; x<vctStructures->size(); x++) {
+      for (int y=0; y<(*vctStructures)[x]->size(); y++) {
+        if ((*(*vctStructures)[x])[y] == t) {
+           pos.x = x;
+           pos.y = y;
+           return pos;
+        } 
+      }
+   }
+
+   return pos;
 }
 
Index: common/WorldMap.h
===================================================================
--- common/WorldMap.h	(revision a6066e8fba1a901cdcaa9bd6ca01ab8945a4b14e)
+++ common/WorldMap.h	(revision e4c60ba35ab71c7d35960b98212214ce43dd724c)
@@ -60,4 +60,5 @@
    StructureType getStructure(int x, int y);
    void setStructure(int x, int y, StructureType type);
+   POSITION getStructureLocation(StructureType type);
 
    vector<Object>* getObjects();
Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision a6066e8fba1a901cdcaa9bd6ca01ab8945a4b14e)
+++ server/server.cpp	(revision e4c60ba35ab71c7d35960b98212214ce43dd724c)
@@ -151,4 +151,5 @@
                   case WorldMap::TERRAIN_OCEAN:
                   case WorldMap::TERRAIN_ROCK:
+                  {
                      it->second.pos = oldPos;
                      it->second.target.x = it->second.pos.x;
@@ -156,6 +157,56 @@
                      broadcastMove = true;
                      break;
+                  }
                   default:
                      // if there are no obstacles, do nothing
+                     break;
+               }
+
+               WorldMap::ObjectType flagType;
+               POSITION pos;
+               switch(gameMap->getStructure(it->second.pos.x/25, it->second.pos.y/25)) {
+                  case WorldMap::STRUCTURE_BLUE_FLAG:
+                  {
+                     if (!it->second.team == 0 || !it->second.hasRedFlag)
+                        break;
+                     else {
+                        it->second.hasRedFlag = false;
+                        flagType = WorldMap::OBJECT_RED_FLAG;
+                        pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
+                     }
+                  }
+                  case WorldMap::STRUCTURE_RED_FLAG:
+                  {
+                     if (!it->second.team == 1 || !it->second.hasBlueFlag)
+                        break;
+                     else {
+                        it->second.hasBlueFlag = false;
+                        flagType = WorldMap::OBJECT_BLUE_FLAG;
+                        pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
+                     }
+
+                     // all code from here to the break is executed for both cases of the switch
+
+                     // send an OBJECT message to add the flag back to its spawn point
+                     pos.x = pos.x*25+12;
+                     pos.y = pos.y*25+12;
+                     gameMap->addObject(flagType, pos.x, pos.y);
+
+                     serverMsg.type = MSG_TYPE_OBJECT;
+                     gameMap->getObjects()->back().serialize(serverMsg.buffer);
+
+                     map<unsigned int, Player>::iterator it2;
+                     for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
+                     {
+                        if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                           error("sendMessage");
+                     }
+
+                     // this means a PLAYER message will be send
+                     broadcastMove = true;
+
+                     break;
+                  }
+                  default:
                      break;
                }
