From: Christoph Sommer Date: Wed, 21 Jun 2006 13:47:25 +0000 (+0000) Subject: New stay_group of SpriteChange objects ensures in_stay_action is synchronized, i... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=087de4c9139b8f91b0d863468cde5ce4b9e2c133;p=supertux.git New stay_group of SpriteChange objects ensures in_stay_action is synchronized, i.e. worldmap boat is only displayed in one place at a time SVN-Revision: 3686 --- diff --git a/data/levels/world1/worldmap.stwm b/data/levels/world1/worldmap.stwm index d63db50b4..7fe019eeb 100644 --- a/data/levels/world1/worldmap.stwm +++ b/data/levels/world1/worldmap.stwm @@ -201,6 +201,7 @@ (change-on-touch #t) (stay-action "") (initial-stay-action #f) + (stay-group "world2-boat") (x 38) (y 21) (sprite "images/worldmap/common/boat/boat.sprite") @@ -209,6 +210,7 @@ (change-on-touch #f) (stay-action "empty") (initial-stay-action #t) + (stay-group "world2-boat") (x 34) (y 15) (sprite "images/worldmap/common/boat/boat.sprite") diff --git a/data/levels/world2/worldmap.stwm b/data/levels/world2/worldmap.stwm index 7c85b36c7..3633d6ef4 100644 --- a/data/levels/world2/worldmap.stwm +++ b/data/levels/world2/worldmap.stwm @@ -191,7 +191,8 @@ (sprite-change (change-on-touch #f) (stay-action "empty") - (initial-stay-action #f) + (initial-stay-action #t) + (stay-group "world1-boat") (x 19) (y 42) (sprite "images/worldmap/common/boat/boat.sprite") @@ -207,6 +208,7 @@ (change-on-touch #t) (stay-action "") (initial-stay-action #f) + (stay-group "world1-boat") (x 10) (y 45) (sprite "images/worldmap/common/boat/boat.sprite") diff --git a/src/worldmap/sprite_change.cpp b/src/worldmap/sprite_change.cpp index 9ac536ecd..ef32fb251 100644 --- a/src/worldmap/sprite_change.cpp +++ b/src/worldmap/sprite_change.cpp @@ -39,10 +39,15 @@ SpriteChange::SpriteChange(const lisp::Lisp* lisp) lisp->get("stay-action", stay_action); lisp->get("initial-stay-action", in_stay_action); + + lisp->get("stay-group", stay_group); + + all_sprite_changes.push_back(this); } SpriteChange::~SpriteChange() { + all_sprite_changes.remove(this); } void @@ -59,4 +64,27 @@ SpriteChange::update(float ) { } +void +SpriteChange::set_stay_action() +{ + in_stay_action = true; +} + +void +SpriteChange::clear_stay_action() +{ + in_stay_action = false; + + // if we are in a stay_group, also clear all stay actions in this group + if (stay_group != "") { + for (std::list::iterator i = all_sprite_changes.begin(); i != all_sprite_changes.end(); i++) { + SpriteChange* sc = *i; + if (sc->stay_group != stay_group) continue; + sc->in_stay_action = false; + } + } +} + +std::list SpriteChange::all_sprite_changes; + } diff --git a/src/worldmap/sprite_change.hpp b/src/worldmap/sprite_change.hpp index 7bf2f8cd3..b48787db5 100644 --- a/src/worldmap/sprite_change.hpp +++ b/src/worldmap/sprite_change.hpp @@ -21,6 +21,7 @@ #include #include +#include #include "game_object.hpp" #include "lisp/lisp.hpp" #include "math/vector.hpp" @@ -50,13 +51,34 @@ public: * another SpriteChange object. */ std::string stay_action; + /** - * should the stayaction be displayed + * name of a group in which only one SpriteChange will ever have its stay_action displayed. + * Leave empty if you don't care. */ - bool in_stay_action; + std::string stay_group; virtual void draw(DrawingContext& context); virtual void update(float elapsed_time); + + /** + * Activates the SpriteChange's stay action, if applicable + */ + void set_stay_action(); + + /** + * Deactivates the SpriteChange's stay action, if applicable + */ + void clear_stay_action(); + +private: + /** + * should the stayaction be displayed + */ + bool in_stay_action; + + static std::list all_sprite_changes; + }; } diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index 0e51bdafe..7f5c50a1f 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -170,7 +170,7 @@ Tux::tryContinueWalking(float elapsed_time) SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos); if(sprite_change != NULL) { sprite.reset(new Sprite( *(sprite_change->sprite.get()) )); - sprite_change->in_stay_action = false; + sprite_change->clear_stay_action(); } // if this is a special_tile with passive_message, display it @@ -259,12 +259,12 @@ Tux::tryContinueWalking(float elapsed_time) SpriteChange* next_sprite = worldmap->at_sprite_change(next_tile); if(next_sprite != NULL && next_sprite->change_on_touch) { sprite.reset(new Sprite( *(next_sprite->sprite.get()) )); - next_sprite->in_stay_action = false; + next_sprite->clear_stay_action(); } SpriteChange* last_sprite = worldmap->at_sprite_change(tile_pos); if(last_sprite != NULL && next_sprite != NULL) { log_debug << "Old: " << tile_pos << " New: " << next_tile << std::endl; - last_sprite->in_stay_action = true; + last_sprite->set_stay_action(); } tile_pos = next_tile; @@ -300,7 +300,7 @@ Tux::setup() SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos); if(sprite_change != NULL) { sprite.reset(new Sprite( *(sprite_change->sprite.get()) )); - sprite_change->in_stay_action = false; + sprite_change->clear_stay_action(); } }