CVSROOT: /cvsroot/wesnoth Module name: wesnoth Branch: Changes by: Guillaume Melquiond <[EMAIL PROTECTED]> 05/05/02 19:42:05
Modified files: src : actions.cpp ai.cpp ai_attack.cpp ai_move.cpp builder.cpp map.cpp map.hpp pathfind.cpp playlevel.cpp playturn.cpp replay.cpp reports.cpp unit_display.cpp Log message: Fix a lot of off-by-one gamemap::location logging errors. Also force the correct ones to go through the appropriate functions. CVSWeb URLs: http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.213&tr2=1.214&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/ai.cpp.diff?tr1=1.148&tr2=1.149&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/ai_attack.cpp.diff?tr1=1.61&tr2=1.62&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/ai_move.cpp.diff?tr1=1.60&tr2=1.61&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/builder.cpp.diff?tr1=1.50&tr2=1.51&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.cpp.diff?tr1=1.58&tr2=1.59&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.hpp.diff?tr1=1.37&tr2=1.38&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.cpp.diff?tr1=1.65&tr2=1.66&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.203&tr2=1.204&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.365&tr2=1.366&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/replay.cpp.diff?tr1=1.110&tr2=1.111&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/reports.cpp.diff?tr1=1.64&tr2=1.65&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.cpp.diff?tr1=1.57&tr2=1.58&r1=text&r2=text Patches: Index: wesnoth/src/actions.cpp diff -u wesnoth/src/actions.cpp:1.213 wesnoth/src/actions.cpp:1.214 --- wesnoth/src/actions.cpp:1.213 Sat Apr 30 12:31:20 2005 +++ wesnoth/src/actions.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: actions.cpp,v 1.213 2005/04/30 12:31:20 silene Exp $ */ +/* $Id: actions.cpp,v 1.214 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -108,7 +108,7 @@ return _("You don't have a leader to recruit with."); if(map.is_keep(u->first) == false) { - LOG_NG << "Leader not on start: leader is on " << (u->first.x+1) << "," << (u->first.y+1) << "\n"; + LOG_NG << "Leader not on start: leader is on " << u->first << '\n'; return _("You must have your leader on a keep to recruit or recall units."); } Index: wesnoth/src/ai.cpp diff -u wesnoth/src/ai.cpp:1.148 wesnoth/src/ai.cpp:1.149 --- wesnoth/src/ai.cpp:1.148 Sat Apr 30 15:23:37 2005 +++ wesnoth/src/ai.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: ai.cpp,v 1.148 2005/04/30 15:23:37 ott Exp $ */ +/* $Id: ai.cpp,v 1.149 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -278,7 +278,7 @@ LOG_AI << "trying recruit: team=" << (info_.team_num) << " type=" << unit_name << " cost=" << u->second.cost() << - " loc=(" << (1+loc.x) << ',' << (1+loc.y) << ')' << + " loc=(" << loc << ')' << " gold=" << (current_team().gold()) << " (-> " << (current_team().gold()-u->second.cost()) << ")\n"; @@ -383,8 +383,7 @@ gamemap::location ai_interface::move_unit_partial(location from, location to, std::map<location,paths>& possible_moves) { - LOG_AI << "ai_interface::move_unit " << (from.x + 1) << "," << (from.y + 1) - << " -> " << (to.x + 1) << "," << (to.y + 1) << "\n"; + LOG_AI << "ai_interface::move_unit " << from << " -> " << to << '\n'; //stop the user from issuing any commands while the unit is moving const command_disabler disable_commands; @@ -396,13 +395,13 @@ log_scope2(ai, "move_unit"); unit_map::iterator u_it = info_.units.find(from); if(u_it == info_.units.end()) { - LOG_STREAM(err, ai) << "Could not find unit at " << from.x << ", " << from.y << "\n"; + LOG_STREAM(err, ai) << "Could not find unit at " << from << '\n'; wassert(false); return location(); } if(from == to) { - LOG_AI << "moving unit at " << (from.x+1) << "," << (from.y+1) << " on spot. resetting moves\n"; + LOG_AI << "moving unit at " << from << " on spot. resetting moves\n"; return to; } @@ -507,8 +506,8 @@ if(i != units_.end()) { if(from != via && to != via && units_.count(via) == 0) { LOG_AI << "when seeing if leader can move from " - << (from.x + 1) << "," << (from.y + 1) << " -> " << (to.x + 1) << "," << (to.y + 1) - << " seeing if can detour to keep at " << (via.x + 1) << "," << (via.y + 1) << "\n"; + << from << " -> " << to + << " seeing if can detour to keep at " << via << '\n'; const std::map<location,paths>::const_iterator moves = possible_moves.find(from); if(moves != possible_moves.end()) { @@ -934,9 +933,8 @@ const location arrived_at = move_unit(from,to,possible_moves); if(arrived_at != to) { LOG_STREAM(warn, ai) << "unit moving to attack has ended up unexpectedly at " - << (arrived_at.x + 1) << "," << (arrived_at.y + 1) << " when moving to " - << (to.x + 1) << "," << (to.y + 1) << " moved from " - << (from.x + 1) << "," << (from.y + 1) << "\n"; + << arrived_at << " when moving to " << to << " moved from " + << from << '\n'; return true; } @@ -1178,7 +1176,7 @@ if(vuln < best_vulnerability || best_loc == it.second) { best_vulnerability = vuln; best_loc = it.first; - LOG_AI << "chose village " << (dst.x+1) << "," << (dst.y+1) << "\n"; + LOG_AI << "chose village " << dst << '\n'; } } @@ -1291,8 +1289,8 @@ } if(best_pos.valid()) { - LOG_AI << "retreating '" << i->second.type().id() << "' " << i->first.x << "," - << i->first.y << " -> " << best_pos.x << "," << best_pos.y << "\n"; + LOG_AI << "retreating '" << i->second.type().id() << "' " << i->first + << " -> " << best_pos << '\n'; move_unit(i->first,best_pos,possible_moves); return true; } @@ -1331,7 +1329,7 @@ return true; } - LOG_AI << "move: " << move.first.x << ", " << move.first.y << " - " << move.second.x << ", " << move.second.y << "\n"; + LOG_AI << "move: " << move.first << " -> " << move.second << '\n'; //search to see if there are any enemy units next //to the tile which really should be attacked once the move is done. Index: wesnoth/src/ai_attack.cpp diff -u wesnoth/src/ai_attack.cpp:1.61 wesnoth/src/ai_attack.cpp:1.62 --- wesnoth/src/ai_attack.cpp:1.61 Sat Mar 26 17:10:32 2005 +++ wesnoth/src/ai_attack.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: ai_attack.cpp,v 1.61 2005/03/26 17:10:32 silene Exp $ */ +/* $Id: ai_attack.cpp,v 1.62 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -592,7 +592,7 @@ value *= 5.0; } - LOG_AI << "attack on " << (target.x+1) << "," << (target.y+1) << ": attackers: " << movements.size() + LOG_AI << "attack on " << target << ": attackers: " << movements.size() << " value: " << value << " chance to kill: " << chance_to_kill << " damage inflicted: " << avg_damage_inflicted << " damage taken: " << avg_damage_taken << " vulnerability: " << vulnerability << " support: " << support << " quality: " << terrain_quality Index: wesnoth/src/ai_move.cpp diff -u wesnoth/src/ai_move.cpp:1.60 wesnoth/src/ai_move.cpp:1.61 --- wesnoth/src/ai_move.cpp:1.60 Sun Mar 27 23:06:16 2005 +++ wesnoth/src/ai_move.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: ai_move.cpp,v 1.60 2005/03/27 23:06:16 gruikya Exp $ */ +/* $Id: ai_move.cpp,v 1.61 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -558,7 +558,7 @@ u = units_.end(); } - LOG_AI << "best unit: " << (best->first.x+1) << "," << (best->first.y+1) << "\n"; + LOG_AI << "best unit: " << best->first << '\n'; wassert(best_target >= targets.begin() && best_target < targets.end()); Index: wesnoth/src/builder.cpp diff -u wesnoth/src/builder.cpp:1.50 wesnoth/src/builder.cpp:1.51 --- wesnoth/src/builder.cpp:1.50 Wed Apr 13 20:36:59 2005 +++ wesnoth/src/builder.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: builder.cpp,v 1.50 2005/04/13 20:36:59 gruikya Exp $ */ +/* $Id: builder.cpp,v 1.51 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2004 by Philippe Plantier <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://www.wesnoth.org @@ -757,7 +757,8 @@ for(constraint_set::const_iterator constraint = rule->second.constraints.begin(); constraint != rule->second.constraints.end(); ++constraint) { - std::cerr << ">>>> New constraint: location = (" << constraint->second.loc.x << ", " << constraint->second.loc.y << "), terrain types = " << constraint->second.terrain_types << "\n"; + std::cerr << ">>>> New constraint: location = (" << constraint->second.loc + << "), terrain types = " << constraint->second.terrain_types << "\n"; std::vector<std::string>::const_iterator flag; Index: wesnoth/src/map.cpp diff -u wesnoth/src/map.cpp:1.58 wesnoth/src/map.cpp:1.59 --- wesnoth/src/map.cpp:1.58 Sat Mar 26 17:10:32 2005 +++ wesnoth/src/map.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: map.cpp,v 1.58 2005/03/26 17:10:32 silene Exp $ */ +/* $Id: map.cpp,v 1.59 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -30,6 +30,11 @@ #define ERR_CF LOG_STREAM(err, config) #define LOG_G LOG_STREAM(info, general) +std::ostream &operator<<(std::ostream &s, gamemap::location const &l) { + s << (l.x + 1) << ',' << (l.y + 1); + return s; +} + gamemap::location gamemap::location::null_location; const std::string& gamemap::underlying_terrain(TERRAIN terrain) const Index: wesnoth/src/map.hpp diff -u wesnoth/src/map.hpp:1.37 wesnoth/src/map.hpp:1.38 --- wesnoth/src/map.hpp:1.37 Mon Mar 28 12:29:10 2005 +++ wesnoth/src/map.hpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: map.hpp,v 1.37 2005/03/28 12:29:10 gruikya Exp $ */ +/* $Id: map.hpp,v 1.38 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -18,6 +18,7 @@ #include "terrain.hpp" +#include <iostream> #include <map> #include <string> #include <vector> @@ -190,5 +191,7 @@ //into a vector of locations std::vector<gamemap::location> parse_location_range(const std::string& xvals, const std::string& yvals); +//dump a position on a stream for debug purposes +std::ostream &operator<<(std::ostream &s, gamemap::location const &l); #endif Index: wesnoth/src/pathfind.cpp diff -u wesnoth/src/pathfind.cpp:1.65 wesnoth/src/pathfind.cpp:1.66 --- wesnoth/src/pathfind.cpp:1.65 Sat Mar 26 17:10:32 2005 +++ wesnoth/src/pathfind.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: pathfind.cpp,v 1.65 2005/03/26 17:10:32 silene Exp $ */ +/* $Id: pathfind.cpp,v 1.66 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -240,7 +240,7 @@ wassert(aStarGameWorld.empty()); assertParanoAstar(aStarGameWorld.reallyEmpty()); - LOG_PF << "A* search: " << src.x << ", " << src.y << " -> " << dst.x << ", " << dst.y << "\n"; + LOG_PF << "A* search: " << src << " -> " << dst << '\n'; if ( (src.valid(int(parWidth), int(parHeight)) == false) || (dst.valid(int(parWidth), int(parHeight)) == false) || Index: wesnoth/src/playlevel.cpp diff -u wesnoth/src/playlevel.cpp:1.203 wesnoth/src/playlevel.cpp:1.204 --- wesnoth/src/playlevel.cpp:1.203 Wed Apr 27 21:11:44 2005 +++ wesnoth/src/playlevel.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: playlevel.cpp,v 1.203 2005/04/27 21:11:44 gruikya Exp $ */ +/* $Id: playlevel.cpp,v 1.204 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -104,7 +104,7 @@ placed.insert(i->side); positions_taken.insert(i->pos); map.set_starting_position(i->side,i->pos); - LOG_NG << "placing side " << i->side << " at " << i->pos.x << "," << i->pos.y << "\n"; + LOG_NG << "placing side " << i->side << " at " << i->pos << '\n'; } } } @@ -300,7 +300,7 @@ if(has_loc.empty()) { start_pos = map.starting_position(side); LOG_NG << "initializing side '" << (**ui)["side"] << "' at " - << start_pos.x << "," << start_pos.y << "\n"; + << start_pos << '\n'; } if(map.empty()) { Index: wesnoth/src/playturn.cpp diff -u wesnoth/src/playturn.cpp:1.365 wesnoth/src/playturn.cpp:1.366 --- wesnoth/src/playturn.cpp:1.365 Fri Apr 29 21:37:26 2005 +++ wesnoth/src/playturn.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: playturn.cpp,v 1.365 2005/04/29 21:37:26 silene Exp $ */ +/* $Id: playturn.cpp,v 1.366 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -2167,7 +2167,7 @@ << i->second.traits_description() << COLUMN_SEPARATOR << i->second.movement_left() << "/" << i->second.total_movement() << COLUMN_SEPARATOR - << (i->first.x + 1) << "-" << (i->first.y + 1); + << i->first; items.push_back(row.str()); Index: wesnoth/src/replay.cpp diff -u wesnoth/src/replay.cpp:1.110 wesnoth/src/replay.cpp:1.111 --- wesnoth/src/replay.cpp:1.110 Sat Apr 30 15:23:37 2005 +++ wesnoth/src/replay.cpp Mon May 2 19:42:04 2005 @@ -1,4 +1,4 @@ -/* $Id: replay.cpp,v 1.110 2005/04/30 15:23:37 ott Exp $ */ +/* $Id: replay.cpp,v 1.111 2005/05/02 19:42:04 silene Exp $ */ /* Copyright (C) 2003 by David White <[EMAIL PROTECTED]> Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net @@ -44,11 +44,6 @@ //functions to verify that the unit structure on both machines is identical namespace { - std::ostream &operator<<(std::ostream &s, gamemap::location const &l) { - s << (l.x + 1) << ',' << (l.y + 1); - return s; - } - void verify(const unit_map& units, const config& cfg) { LOG_NW << "verifying unit structure...\n"; @@ -87,8 +82,7 @@ if(u == units.end()) { ERR_NW << "SYNC VERIFICATION FAILED: data source says there is a '" << (**i)["type"] << "' (side " << (**i)["side"] << ") at " - << (**i)["x"] << ',' << (**i)["y"] - << " but there is no local record of it\n"; + << loc << " but there is no local record of it\n"; if (!game_config::ignore_replay_errors) throw replay::error(); } @@ -100,8 +94,7 @@ for(const std::string* str = fields; str->empty() == false; ++str) { if(cfg[*str] != (**i)[*str]) { ERR_NW << "ERROR IN FIELD '" << *str << "' for unit at " - << (**i)["x"] << ',' << (**i)["y"] - << " data source: '" << (**i)[*str] + << loc << " data source: '" << (**i)[*str] << "' local: '" << cfg[*str] << "'\n"; is_ok = false; } @@ -244,11 +237,7 @@ sprintf(buf,"%d",value); val["value"] = buf; - sprintf(buf,"%d",loc.x+1); - val["x"] = buf; - - sprintf(buf,"%d",loc.y+1); - val["y"] = buf; + loc.write(val); cmd->add_child("recruit",val); } @@ -263,11 +252,7 @@ sprintf(buf,"%d",value); val["value"] = buf; - sprintf(buf,"%d",loc.x+1); - val["x"] = buf; - - sprintf(buf,"%d",loc.y+1); - val["y"] = buf; + loc.write(val); cmd->add_child("recall",val); } @@ -304,16 +289,8 @@ config* const cmd = add_command(); config move, src, dst; - - char buf[100]; - sprintf(buf,"%d",a.x+1); - src["x"] = buf; - sprintf(buf,"%d",a.y+1); - src["y"] = buf; - sprintf(buf,"%d",b.x+1); - dst["x"] = buf; - sprintf(buf,"%d",b.y+1); - dst["y"] = buf; + a.write(src); + b.write(dst); move.add_child("source",src); move.add_child("destination",dst); @@ -701,7 +678,8 @@ << u_type->second.cost() << "/" << current_team.gold() << "\n"; if (!game_config::ignore_replay_errors) throw replay::error(); } - LOG_NW << "recruit: team=" << team_num << " '" << u_type->second.id() << "' at (" << (1+loc.x) << ',' << (1+loc.y) << ") cost=" << (u_type->second.cost()) << " from gold=" << (current_team.gold()) << ' '; + LOG_NW << "recruit: team=" << team_num << " '" << u_type->second.id() << "' at (" << loc + << ") cost=" << u_type->second.cost() << " from gold=" << current_team.gold() << ' '; statistics::recruit_unit(new_unit); @@ -778,7 +756,7 @@ u = units.find(src); if(u == units.end()) { ERR_NW << "unfound location for source of movement: " - << src << '-' << dst << '\n'; + << src << " -> " << dst << '\n'; if (!game_config::ignore_replay_errors) throw replay::error(); } @@ -794,11 +772,11 @@ if(rt == paths_list.routes.end()) { for(rt = paths_list.routes.begin(); rt != paths_list.routes.end(); ++rt) { - ERR_NW << "can get to: " << rt->first.y << '\n'; + ERR_NW << "can get to: " << rt->first << '\n'; } ERR_NW << "src cannot get to dst: " << current_unit.movement_left() << ' ' - << paths_list.routes.size() << ' ' << src << '-' << dst << '\n'; + << paths_list.routes.size() << ' ' << src << " -> " << dst << '\n'; if (!game_config::ignore_replay_errors) throw replay::error(); } Index: wesnoth/src/reports.cpp diff -u wesnoth/src/reports.cpp:1.64 wesnoth/src/reports.cpp:1.65 --- wesnoth/src/reports.cpp:1.64 Thu Apr 21 19:36:34 2005 +++ wesnoth/src/reports.cpp Mon May 2 19:42:04 2005 @@ -339,7 +339,7 @@ break; } - str << (mouseover.x+1) << ", " << (mouseover.y+1); + str << mouseover; if(u == units.end() || current_team.shrouded(mouseover.x,mouseover.y)) break; Index: wesnoth/src/unit_display.cpp diff -u wesnoth/src/unit_display.cpp:1.57 wesnoth/src/unit_display.cpp:1.58 --- wesnoth/src/unit_display.cpp:1.57 Sat Mar 26 17:10:32 2005 +++ wesnoth/src/unit_display.cpp Mon May 2 19:42:04 2005 @@ -685,7 +685,7 @@ const gamemap::location leader_loc = under_leadership(units,a); unit_map::iterator leader = units.end(); if(leader_loc.valid()){ - LOG_DP << "found leader at " << (leader_loc.x+1) << "," << (leader_loc.y+1) << "\n"; + LOG_DP << "found leader at " << leader_loc << '\n'; leader = units.find(leader_loc); wassert(leader != units.end()); leader->second.set_leading(true); _______________________________________________ Wesnoth-cvs-commits mailing list Wesnoth-cvs-commits@nongnu.org http://lists.nongnu.org/mailman/listinfo/wesnoth-cvs-commits