[Wesnoth-commits] r9933 - in /trunk/src: gamestatus.cpp gamestatus.hpp unit_types.cpp (February 02, 2006 - 18:26)

Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Headers

 

Author: xan
Date: Thu Feb  2 18:24:51 2006
New Revision: 9933

URL: http://svn.gna.org/viewcvs/wesnoth?rev=9933&view=rev
Log:
New method for illuminates.

Modified:
    trunk/src/gamestatus.cpp
    trunk/src/gamestatus.hpp
    trunk/src/unit_types.cpp

Modified: trunk/src/gamestatus.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=9933&r1=9932&r2=9933&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Thu Feb  2 18:24:51 2006
@@ -50,7 +50,7 @@
 time_of_day::time_of_day(const config& cfg)
                  : lawful_bonus(atoi(cfg["lawful_bonus"].c_str())),
                    image(cfg["image"]), name(cfg["name"]), id(cfg["id"]),
-		   image_mask(cfg["mask"]),
+		   image_mask(cfg["mask"]),lighter_id(cfg["lighter"]),darker_id(cfg["darker"]),
                    red(atoi(cfg["red"].c_str())),
                    green(atoi(cfg["green"].c_str())),
                    blue(atoi(cfg["blue"].c_str()))
@@ -75,6 +75,8 @@
 	cfg["image"] = image;
 	cfg["name"] = name;
 	cfg["id"] = id;
+	cfg["lighter"] = lighter_id;
+	cfg["darker"] = darker_id;
 	cfg["mask"] = image_mask;
 }
 
@@ -87,16 +89,57 @@
 	for(t = times.begin(); t != times.end(); ++t) {
 		normal_times.push_back(time_of_day(**t));
 	}
-
-	illuminated_times.assign(normal_times.begin(),normal_times.end());
-	if(illuminated_times.empty() == false) {
-		std::sort(illuminated_times.begin(),illuminated_times.end());
-		std::vector<time_of_day>::iterator i=illuminated_times.begin();
-		while(i < illuminated_times.end()-1) {
-			if(i->lawful_bonus == (i+1)->lawful_bonus) {
-				illuminated_times.erase(i+1);
-			} else {
-				i++;
+	
+	const config::child_list& illum_times = cfg.get_children("illuminated_time");
+	for(t = illum_times.begin(); t != illum_times.end(); ++t) {
+		illuminated_times.push_back(time_of_day(**t));
+	}
+	
+	// Find pointers to lighter and darker times of day
+	std::vector<time_of_day>::iterator d;
+	for(d = normal_times.begin(); d != normal_times.end(); ++d) {
+		const std::string& lt_id = d->lighter_id;
+		const std::string& dk_id = d->darker_id;
+		d->lighter=NULL;
+		d->darker=NULL;
+		std::vector<time_of_day>::iterator f;
+		for(f = normal_times.begin(); f!= normal_times.end(); ++f) {
+			if(lt_id == f->id) {
+				d->lighter = &(*f);
+			}
+			if(dk_id == f->id) {
+				d->darker = &(*f);
+			}
+		}
+		for(f = illuminated_times.begin(); f!= illuminated_times.end(); ++f) {
+			if(lt_id == f->id) {
+				d->lighter = &(*f);
+			}
+			if(dk_id == f->id) {
+				d->darker = &(*f);
+			}
+		}
+	}
+	for(d = illuminated_times.begin(); d != illuminated_times.end(); ++d) {
+		const std::string& lt_id = d->lighter_id;
+		const std::string& dk_id = d->darker_id;
+		d->lighter=NULL;
+		d->darker=NULL;
+		std::vector<time_of_day>::iterator f;
+		for(f = normal_times.begin(); f!= normal_times.end(); ++f) {
+			if(lt_id == f->id) {
+				d->lighter = &(*f);
+			}
+			if(dk_id == f->id) {
+				d->darker = &(*f);
+			}
+		}
+		for(f = illuminated_times.begin(); f!= illuminated_times.end(); ++f) {
+			if(lt_id == f->id) {
+				d->lighter = &(*f);
+			}
+			if(dk_id == f->id) {
+				d->darker = &(*f);
 			}
 		}
 	}
@@ -174,70 +217,39 @@
 	return get_time_of_day_turn(turn()-1);
 }
 
-bool time_of_day::operator <(const time_of_day& o) const
-{
-	return lawful_bonus < o.lawful_bonus;
-}
-
 
 const time_of_day& gamestatus::get_time_of_day(int illuminated, const gamemap::location& loc, int n_turn) const
 {
 	for(std::vector<area_time_of_day>::const_iterator i = areas_.begin(); i != areas_.end(); ++i) {
 		if(i->hexes.count(loc) == 1) {
-			if(illuminated && i->illuminated_times.empty() == false) {
-				int bonus = i->times[(n_turn-1)%i->times.size()].lawful_bonus;
-				std::vector<time_of_day>::const_iterator t = i->illuminated_times.begin();
-				while(t->lawful_bonus != bonus) {
-					t++;
+			if(illuminated) {
+				const time_of_day* cur = &i->times[(n_turn-1)%i->times.size()];
+				while(illuminated>0 && cur->lighter) {
+					cur = cur->lighter;
+					illuminated--;
 				}
-				t += illuminated;
-				if(t < i->illuminated_times.begin()) {
-					t = i->illuminated_times.begin();
-				} else if(t >= i->illuminated_times.end()) {
-					t = i->illuminated_times.end()-1;
+				while(illuminated<0 && cur->darker) {
+					cur = cur->darker;
+					illuminated++;
 				}
-				int final_bonus = t->lawful_bonus;
-				unsigned int find_t=n_turn-1;
-				unsigned int find_tr=n_turn-1;
-				while(1) {
-					if(i->times[(find_t++)%i->times.size()].lawful_bonus == final_bonus) {
-						return i->times[(find_t-1)%i->times.size()];
-					}
-					if(i->times[(find_tr--)%i->times.size()].lawful_bonus == final_bonus) {
-						return i->times[(find_tr+1)%i->times.size()];
-					}
-				}
-				return *t;
+				return *cur;
 			} else if(i->times.empty() == false) {
 				return i->times[(n_turn-1)%i->times.size()];
 			}
 		}
 	}
 
-	if(illuminated && illuminatedTimes_.empty() == false) {
-		int bonus = times_[(n_turn-1)%times_.size()].lawful_bonus;
-		std::vector<time_of_day>::const_iterator t = illuminatedTimes_.begin();
-		while(t->lawful_bonus != bonus) {
-			t++;
-		}
-		t += illuminated;
-		if(t < illuminatedTimes_.begin()) {
-			t = illuminatedTimes_.begin();
-		} else if(t >= illuminatedTimes_.end()) {
-			t = illuminatedTimes_.end()-1;
-		}
-		int final_bonus = t->lawful_bonus;
-		unsigned int find_t=n_turn-1;
-		unsigned int find_tr=n_turn-1;
-		while(1) {
-			if(times_[(find_t++)%times_.size()].lawful_bonus == final_bonus) {
-				return times_[(find_t-1)%times_.size()];
-			}
-			if(times_[(find_tr--)%times_.size()].lawful_bonus == final_bonus) {
-				return times_[(find_tr+1)%times_.size()];
-			}
-		}
-		return *t;
+	if(illuminated) {
+		const time_of_day* cur = &times_[(n_turn-1)%times_.size()];
+		while(illuminated>0 && cur->lighter) {
+			cur = cur->lighter;
+			illuminated--;
+		}
+		while(illuminated<0 && cur->darker) {
+			cur = cur->darker;
+			illuminated++;
+		}
+		return *cur;
 	} else if(times_.empty() == false) {
 		return times_[(n_turn-1)%times_.size()];
 	}

Modified: trunk/src/gamestatus.hpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=9933&r1=9932&r2=9933&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Thu Feb  2 18:24:51 2006
@@ -26,8 +26,6 @@
 	explicit time_of_day(const config& cfg);
 	void write(config& cfg) const;
 
-	bool operator <(const time_of_day& o) const;
-
 	//the % bonus lawful units receive. chaotic units will
 	//receive -lawful_bonus.
 	int lawful_bonus;
@@ -36,6 +34,10 @@
 	std::string image;
 	t_string name;
 	std::string id;
+	std::string lighter_id;
+	std::string darker_id;
+	time_of_day* lighter;
+	time_of_day* darker;
 
 	//the image that is to be laid over all images while it's this
 	//time of day

Modified: trunk/src/unit_types.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=9933&r1=9932&r2=9933&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Thu Feb  2 18:24:51 2006
@@ -861,7 +861,7 @@
 				} else {
 					ability_tooltips_.push_back("illuminates");
 				}
-				illuminates_ = maximum<int>(illuminates_,lexical_cast_default<int>((**ab)["level"],1));
+				illuminates_ += lexical_cast_default<int>((**ab)["level"],1);
 				illuminates_filter_.add_filters((*ab)->child("filter"));
 			}
 		}



Related Mails




Powered by MHonArc, Updated Thu Feb 02 19:00:12 2006