From 99199c39ed744bf40e3fa60e26ba64c29c014ddc Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Wed, 1 Nov 2006 04:14:17 +0000 Subject: [PATCH] Addded property to Worldmap Spawnpoint to let Tux automatically start walking (or sailing) in a certain direction SVN-Revision: 4431 --- src/worldmap/direction.hpp | 28 +++++++++++++++++++ src/worldmap/spawn_point.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/worldmap/spawn_point.hpp | 43 +++++++++++++++++++++++++++++ src/worldmap/worldmap.cpp | 7 ++++- src/worldmap/worldmap.hpp | 5 ++-- 5 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/worldmap/direction.hpp create mode 100644 src/worldmap/spawn_point.cpp create mode 100644 src/worldmap/spawn_point.hpp diff --git a/src/worldmap/direction.hpp b/src/worldmap/direction.hpp new file mode 100644 index 000000000..9e1b223f4 --- /dev/null +++ b/src/worldmap/direction.hpp @@ -0,0 +1,28 @@ +// $Id$ +// +// SuperTux - Worldmap Direction +// Copyright (C) 2006 Christoph Sommer +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef __WORLDMAP_DIRECTION_HPP__ +#define __WORLDMAP_DIRECTION_HPP__ + +namespace WorldMapNS { + +enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH }; + +} + +#endif diff --git a/src/worldmap/spawn_point.cpp b/src/worldmap/spawn_point.cpp new file mode 100644 index 000000000..431ee4ce8 --- /dev/null +++ b/src/worldmap/spawn_point.cpp @@ -0,0 +1,64 @@ +// $Id$ +// +// SuperTux - Worldmap Spawnpoint +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include + +#include +#include +#include "spawn_point.hpp" +#include "lisp/lisp.hpp" +#include "lisp/list_iterator.hpp" +#include "log.hpp" + +namespace WorldMapNS +{ + +// from worldmap.cpp +Direction string_to_direction(const std::string& directory); + +SpawnPoint::SpawnPoint(const lisp::Lisp* slisp) : auto_dir(D_NONE) +{ + pos.x = -1; + pos.y = -1; + lisp::ListIterator iter(slisp); + while(iter.next()) { + const std::string& token = iter.item(); + if(token == "name") { + iter.value()->get(name); + } else if(token == "x") { + iter.value()->get(pos.x); + } else if(token == "y") { + iter.value()->get(pos.y); + } else if(token == "auto-dir") { + std::string s = ""; + iter.value()->get(s); + auto_dir = string_to_direction(s); + } else { + log_warning << "unknown token '" << token << "' in SpawnPoint" << std::endl; + } + } + + if(name == "") + throw std::runtime_error("No name specified for spawnpoint"); + if(pos.x < 0 || pos.y < 0) + throw std::runtime_error("Invalid coordinates for spawnpoint"); +} + +} + diff --git a/src/worldmap/spawn_point.hpp b/src/worldmap/spawn_point.hpp new file mode 100644 index 000000000..9d0d62521 --- /dev/null +++ b/src/worldmap/spawn_point.hpp @@ -0,0 +1,43 @@ +// $Id$ +// +// SuperTux - Worldmap Spawnpoint +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef __WORLDMAP_SPAWN_POINT_H__ +#define __WORLDMAP_SPAWN_POINT_H__ + +#include +#include "math/vector.hpp" +#include "lisp/lisp.hpp" +#include "game_object.hpp" +#include "worldmap/direction.hpp" + +namespace WorldMapNS +{ + +class SpawnPoint +{ +public: + SpawnPoint(const lisp::Lisp* lisp); + + std::string name; + Vector pos; + Direction auto_dir; /**< automatically start walking in this direction */ +}; + +} + +#endif diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 920cf8cca..a47c628b0 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -122,8 +122,12 @@ string_to_direction(const std::string& directory) return D_NORTH; else if (directory == "south") return D_SOUTH; - else + else if (directory == "none") + return D_NONE; + else { + log_warning << "unknown direction: \"" << directory << "\"" << std::endl; return D_NONE; + } } //--------------------------------------------------------------------------- @@ -216,6 +220,7 @@ WorldMap::move_to_spawnpoint(const std::string& spawnpoint) if(sp->name == spawnpoint) { Vector p = sp->pos; tux->set_tile_pos(p); + tux->set_direction(sp->auto_dir); return; } } diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index 9263307eb..acbbedb66 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -36,10 +36,11 @@ #include "worldmap/special_tile.hpp" #include "worldmap/sprite_change.hpp" #include "worldmap/teleporter.hpp" +#include "worldmap/spawn_point.hpp" +#include "worldmap/direction.hpp" class Sprite; class Menu; -class SpawnPoint; class GameObject; class TileMap; @@ -59,8 +60,6 @@ enum { WEST_EAST_WAY }; -enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH }; - std::string direction_to_string(Direction d); Direction string_to_direction(const std::string& d); Direction reverse_dir(Direction d); -- 2.11.0