wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src map.hpp map.cpp game_events.cpp


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src map.hpp map.cpp game_events.cpp
Date: Fri, 18 Mar 2005 23:26:53 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    05/03/19 04:26:53

Modified files:
        src            : map.hpp map.cpp game_events.cpp 

Log message:
        added new [terrain_mask] WML command

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.hpp.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.cpp.diff?tr1=1.54&tr2=1.55&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game_events.cpp.diff?tr1=1.126&tr2=1.127&r1=text&r2=text

Patches:
Index: wesnoth/src/game_events.cpp
diff -u wesnoth/src/game_events.cpp:1.126 wesnoth/src/game_events.cpp:1.127
--- wesnoth/src/game_events.cpp:1.126   Thu Mar 10 22:57:23 2005
+++ wesnoth/src/game_events.cpp Sat Mar 19 04:26:53 2005
@@ -1,4 +1,4 @@
-/* $Id: game_events.cpp,v 1.126 2005/03/10 22:57:23 ydirson Exp $ */
+/* $Id: game_events.cpp,v 1.127 2005/03/19 04:26:53 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -769,6 +769,32 @@
                screen->recalculate_minimap();
                screen->invalidate_all();
                screen->rebuild_all();
+       }
+
+       //creating a mask of the terrain
+       else if(cmd == "terrain_mask") {
+               gamemap::location loc(cfg);
+               if(loc.x == -1) {
+                       loc.x = 0;
+               }
+
+               if(loc.y == -1) {
+                       loc.y = 0;
+               }
+
+               gamemap mask(*game_map);
+
+               try {
+                       mask.read(cfg["mask"]);
+               } catch(gamemap::incorrect_format_exception&) {
+                       ERR_NG << "terrain mask is in the incorrect format, and 
couldn't be applied\n";
+                       return rval;
+               }
+
+               game_map->overlay(mask,cfg,loc.x,loc.y);
+               screen->recalculate_minimap();
+               screen->invalidate_all();
+               screen->rebuild_all();
        }
 
        //if we should spawn a new unit on the map somewhere
Index: wesnoth/src/map.cpp
diff -u wesnoth/src/map.cpp:1.54 wesnoth/src/map.cpp:1.55
--- wesnoth/src/map.cpp:1.54    Thu Mar 10 22:03:32 2005
+++ wesnoth/src/map.cpp Sat Mar 19 04:26:53 2005
@@ -1,4 +1,4 @@
-/* $Id: map.cpp,v 1.54 2005/03/10 22:03:32 ydirson Exp $ */
+/* $Id: map.cpp,v 1.55 2005/03/19 04:26:53 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -198,9 +198,15 @@
        tiles_.clear();
        villages_.clear();
        
std::fill(startingPositions_,startingPositions_+sizeof(startingPositions_)/sizeof(*startingPositions_),location());
+
+       //ignore leading newlines
+       std::string::const_iterator i = data.begin();
+       while(i != data.end() && (*i == '\r' || *i == '\n')) {
+               ++i;
+       }
 
        size_t x = 0, y = 0;
-       for(std::string::const_iterator i = data.begin(); i != data.end(); ++i) 
{
+       for(; i != data.end(); ++i) {
                char c = *i;
                if(c == '\r') {
                        continue;
@@ -265,6 +271,73 @@
        }
 
        return str.str();
+}
+
+void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int 
xpos, const int ypos)
+{
+       const config::child_list& rules = rules_cfg.get_children("rule");
+
+       const int xend = minimum<int>(xpos+m.x(),x());
+       const int yend = minimum<int>(ypos+m.y(),y());
+       for(int x = xpos; x < xend; ++x) {
+               for(int y = ypos; y < yend; ++y) {
+                       const TERRAIN t = m[x-xpos][y-ypos];
+                       const TERRAIN current = (*this)[x][y];
+
+                       if(t == FOGGED || t == VOID_TERRAIN) {
+                               continue;
+                       }
+
+                       //see if there is a matching rule
+                       config::child_list::const_iterator rule = rules.begin();
+                       for( ; rule != rules.end(); ++rule) {
+                               static const std::string src_key = "old", 
src_not_key = "old_not",
+                                                        dst_key = "new", 
dst_not_key = "new_not";
+                               const config& cfg = **rule;
+                               const std::string& src = cfg[src_key];
+                               if(src != "" && 
std::find(src.begin(),src.end(),current) == src.end()) {
+                                       continue;
+                               }
+
+                               const std::string& src_not = cfg[src_not_key];
+                               if(src_not != "" && 
std::find(src_not.begin(),src_not.end(),current) != src_not.end()) {
+                                       continue;
+                               }
+
+                               const std::string& dst = cfg[dst_key];
+                               if(dst != "" && 
std::find(dst.begin(),dst.end(),t) == dst.end()) {
+                                       continue;
+                               }
+
+                               const std::string& dst_not = cfg[dst_not_key];
+                               if(dst_not != "" && 
std::find(dst_not.begin(),dst_not.end(),t) != dst_not.end()) {
+                                       continue;
+                               }
+
+                               break;
+                       }
+
+
+                       if(rule != rules.end()) {
+                               const config& cfg = **rule;
+                               const std::string& terrain = cfg["terrain"];
+                               if(terrain != "") {
+                                       set_terrain(location(x,y),terrain[0]);
+                               } else if(cfg["use_old"] != "yes") {
+                                       set_terrain(location(x,y),t);
+                               }
+                       } else {
+                               set_terrain(location(x,y),t);
+                       }
+               }
+       }
+
+       for(const location* pos = m.startingPositions_; pos != 
m.startingPositions_ + 
sizeof(m.startingPositions_)/sizeof(*m.startingPositions_); ++pos) {
+               if(pos->valid()) {
+                       startingPositions_[pos - m.startingPositions_] = *pos;
+               }
+       }
+       
 }
 
 int gamemap::x() const { return tiles_.size(); }
@@ -381,6 +454,15 @@
 {
        if(!on_board(loc))
                return;
+
+       const bool old_village = is_village(loc);
+       const bool new_village = is_village(ter);
+
+       if(old_village && !new_village) {
+               
villages_.erase(std::remove(villages_.begin(),villages_.end(),loc),villages_.end());
+       } else if(!old_village && new_village) {
+               villages_.push_back(loc);
+       }
 
        tiles_[loc.x][loc.y] = ter;
 
Index: wesnoth/src/map.hpp
diff -u wesnoth/src/map.hpp:1.33 wesnoth/src/map.hpp:1.34
--- wesnoth/src/map.hpp:1.33    Thu Mar 10 01:47:57 2005
+++ wesnoth/src/map.hpp Sat Mar 19 04:26:53 2005
@@ -1,4 +1,4 @@
-/* $Id: map.hpp,v 1.33 2005/03/10 01:47:57 ydirson Exp $ */
+/* $Id: map.hpp,v 1.34 2005/03/19 04:26:53 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -109,7 +109,10 @@
        gamemap(const config& terrain_cfg, const std::string& data); 
//throw(incorrect_format_exception)
        void read(const std::string& data);
 
-       std::string write() const;
+       std::string write() const;
+
+       //overlays another map onto this one at the given position.
+       void overlay(const gamemap& m, const config& rules, int x=0, int y=0);
 
        //dimensions of the map.
        int x() const;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]