src/worldmap/direction.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "direction.hpp"
00018 
00019 #include "util/log.hpp"
00020 
00021 namespace worldmap {
00022 
00023 Direction reverse_dir(Direction direction)
00024 {
00025   switch(direction)
00026   {
00027     case D_WEST:
00028       return D_EAST;
00029     case D_EAST:
00030       return D_WEST;
00031     case D_NORTH:
00032       return D_SOUTH;
00033     case D_SOUTH:
00034       return D_NORTH;
00035     case D_NONE:
00036       return D_NONE;
00037   }
00038   return D_NONE;
00039 }
00040 
00041 std::string
00042 direction_to_string(Direction direction)
00043 {
00044   switch(direction)
00045   {
00046     case D_WEST:
00047       return "west";
00048     case D_EAST:
00049       return "east";
00050     case D_NORTH:
00051       return "north";
00052     case D_SOUTH:
00053       return "south";
00054     default:
00055       return "none";
00056   }
00057 }
00058 
00059 Direction
00060 string_to_direction(const std::string& directory)
00061 {
00062   if (directory == "west")
00063     return D_WEST;
00064   else if (directory == "east")
00065     return D_EAST;
00066   else if (directory == "north")
00067     return D_NORTH;
00068   else if (directory == "south")
00069     return D_SOUTH;
00070   else if (directory == "none")
00071     return D_NONE;
00072   else {
00073     log_warning << "unknown direction: \"" << directory << "\"" << std::endl;
00074     return D_NONE;
00075   }
00076 }
00077 
00078 } // namespace worldmap
00079 
00080 /* EOF */

Generated on Mon Jun 9 03:38:22 2014 for SuperTux by  doxygen 1.5.1