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

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

[Wesnoth-cvs-commits] wesnoth src/game.cpp src/game_events.cpp src/ga...


From: Isaac Clerencia
Subject: [Wesnoth-cvs-commits] wesnoth src/game.cpp src/game_events.cpp src/ga...
Date: Sat, 04 Dec 2004 18:50:29 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Isaac Clerencia <address@hidden>        04/12/04 23:44:10

Modified files:
        src            : game.cpp game_events.cpp gamestatus.cpp 
                         gamestatus.hpp playturn.cpp playturn.hpp 
        po/wesnoth     : de.po 

Log message:
        Run dos2unix

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.172&tr2=1.173&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game_events.cpp.diff?tr1=1.114&tr2=1.115&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.cpp.diff?tr1=1.50&tr2=1.51&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.hpp.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.305&tr2=1.306&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.hpp.diff?tr1=1.56&tr2=1.57&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/po/wesnoth/de.po.diff?tr1=1.27&tr2=1.28&r1=text&r2=text

Patches:
Index: wesnoth/po/wesnoth/de.po
diff -u wesnoth/po/wesnoth/de.po:1.27 wesnoth/po/wesnoth/de.po:1.28
--- wesnoth/po/wesnoth/de.po:1.27       Sat Dec  4 17:41:39 2004
+++ wesnoth/po/wesnoth/de.po    Sat Dec  4 23:44:10 2004
@@ -1,8 +1,8 @@
-# German translations for Battle for Wesnoth package.
-# Copyright (C) 2004 Wesnoth development team
-# This file is distributed under the same license as the Battle for Wesnoth 
package.
-# Automatically generated, 2004.
-# 
+# German translations for Battle for Wesnoth package.
+# Copyright (C) 2004 Wesnoth development team
+# This file is distributed under the same license as the Battle for Wesnoth 
package.
+# Automatically generated, 2004.
+# 
 msgid ""
 msgstr ""
 "Project-Id-Version: Battle for Wesnoth 0.8.2-CVS\n"
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.172 wesnoth/src/game.cpp:1.173
--- wesnoth/src/game.cpp:1.172  Sat Dec  4 18:38:30 2004
+++ wesnoth/src/game.cpp        Sat Dec  4 23:44:09 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.172 2004/12/04 18:38:30 silene Exp $ */
+/* $Id: game.cpp,v 1.173 2004/12/04 23:44:09 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -331,15 +331,15 @@
        bool new_campaign();
        bool play_multiplayer();
        bool change_language();
-
+
        enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
        void play_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
 
 private:
        game_controller(const game_controller&);
        void operator=(const game_controller&);
-
-       void refresh_game_cfg();
+
+       void refresh_game_cfg();
 
        void download_campaigns();
        void upload_campaign(const std::string& campaign, network::connection 
sock);
@@ -797,27 +797,27 @@
                return false;
        }
 
-       try {
-               //to load a save file, we first load the file in, then we 
re-parse game
-               //data with the save's #defines, and then we finally parse the 
save file,
-               //with the game data ready to go.
-               config cfg;
-               read_save_file(game,cfg);
-
-               defines_map_.clear();
-               defines_map_[cfg["difficulty"]] = preproc_define();
-
-               if(defines_map_.count("NORMAL")) {
-                       defines_map_["MEDIUM"] = preproc_define();
-               }
-
-               const std::string& campaign_define = cfg["campaign_define"];
-               if(campaign_define.empty() == false) {
-                       defines_map_[campaign_define] = preproc_define();
-               }
-
-               refresh_game_cfg();
-
+       try {
+               //to load a save file, we first load the file in, then we 
re-parse game
+               //data with the save's #defines, and then we finally parse the 
save file,
+               //with the game data ready to go.
+               config cfg;
+               read_save_file(game,cfg);
+
+               defines_map_.clear();
+               defines_map_[cfg["difficulty"]] = preproc_define();
+
+               if(defines_map_.count("NORMAL")) {
+                       defines_map_["MEDIUM"] = preproc_define();
+               }
+
+               const std::string& campaign_define = cfg["campaign_define"];
+               if(campaign_define.empty() == false) {
+                       defines_map_[campaign_define] = preproc_define();
+               }
+
+               refresh_game_cfg();
+
                state_ = read_game(units_data_,&cfg);
                
                if(state_.version != game_config::version) {
@@ -1247,7 +1247,7 @@
        }
        
        try {
-               defines_map_[state_.campaign_define] = preproc_define();
+               defines_map_[state_.campaign_define] = preproc_define();
                refresh_game_cfg();
                
                if(res >= 2) {
@@ -1337,33 +1337,33 @@
 
        return false;
 }
-
-void game_controller::refresh_game_cfg()
-{
-       try {
-               if(old_defines_map_.empty() || defines_map_ != 
old_defines_map_) {
-
-                       units_data_.clear();
-                       game_config_.clear();
-
-                       std::vector<line_source> line_src;
-                       
read_game_cfg(defines_map_,line_src,game_config_,use_caching_);
-
-                       const config* const units = game_config_.child("units");
-                       if(units != NULL) {
-                               units_data_.set_config(*units);
-                       }
-
-                       old_defines_map_ = defines_map_;
-               }
-       } catch(config::error& e) {
-               gui::show_dialog(disp(),NULL,"","Error loading game 
configuration files: '" + e.message + "' (The game will now exit)", 
gui::MESSAGE);
-               throw e;
-       }
-}
+
+void game_controller::refresh_game_cfg()
+{
+       try {
+               if(old_defines_map_.empty() || defines_map_ != 
old_defines_map_) {
+
+                       units_data_.clear();
+                       game_config_.clear();
+
+                       std::vector<line_source> line_src;
+                       
read_game_cfg(defines_map_,line_src,game_config_,use_caching_);
+
+                       const config* const units = game_config_.child("units");
+                       if(units != NULL) {
+                               units_data_.set_config(*units);
+                       }
+
+                       old_defines_map_ = defines_map_;
+               }
+       } catch(config::error& e) {
+               gui::show_dialog(disp(),NULL,"","Error loading game 
configuration files: '" + e.message + "' (The game will now exit)", 
gui::MESSAGE);
+               throw e;
+       }
+}
 
 void game_controller::play_game(RELOAD_GAME_DATA reload)
-{
+{
        if(reload == RELOAD_DATA) {
                if(state_.campaign_define.empty() == false) {
                        defines_map_[state_.campaign_define] = preproc_define();
@@ -1372,8 +1372,8 @@
                if(defines_map_.count("NORMAL")) {
                        defines_map_["MEDIUM"] = preproc_define();
                }
-       
-               refresh_game_cfg();
+       
+               refresh_game_cfg();
        }
 
        const binary_paths_manager bin_paths_manager(game_config_);
@@ -1541,7 +1541,7 @@
                        res = gui::show_title(game.disp(),tips_of_day,&ntip);
                }
                tips_of_day.clear();
-
+
                game_controller::RELOAD_GAME_DATA should_reload = 
game_controller::RELOAD_DATA;
                std::cerr << "title screen returned result\n";
                if(res == gui::QUIT_GAME) {
@@ -1550,8 +1550,8 @@
                } else if(res == gui::LOAD_GAME) {
                        if(game.load_game() == false) {
                                continue;
-                       }
-
+                       }
+
                        should_reload = game_controller::NO_RELOAD_DATA;
                } else if(res == gui::TUTORIAL) {
                        game.set_tutorial();
Index: wesnoth/src/game_events.cpp
diff -u wesnoth/src/game_events.cpp:1.114 wesnoth/src/game_events.cpp:1.115
--- wesnoth/src/game_events.cpp:1.114   Tue Nov 30 00:54:46 2004
+++ wesnoth/src/game_events.cpp Sat Dec  4 23:44:09 2004
@@ -1,4 +1,4 @@
-/* $Id: game_events.cpp,v 1.114 2004/11/30 00:54:46 Sirp Exp $ */
+/* $Id: game_events.cpp,v 1.115 2004/12/04 23:44:09 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -217,10 +217,10 @@
        if(cmd == "command") {
                handle_event(event_info,&cfg);
        }
-
-       //allow undo sets the flag saying whether the event has mutated the 
game to false
-       else if(cmd == "allow_undo") {
-               mutated = false;
+
+       //allow undo sets the flag saying whether the event has mutated the 
game to false
+       else if(cmd == "allow_undo") {
+               mutated = false;
        }
        //change shroud settings for portions of the map
        else if(cmd == "remove_shroud" || cmd == "place_shroud") {
@@ -1249,8 +1249,8 @@
 bool event_handler::handle_event(const queued_event& event_info, const config* 
cfg)
 {
        if(cfg == NULL)
-               cfg = cfg_;
-
+               cfg = cfg_;
+
        bool mutated = true;
 
        bool skip_messages = false;
@@ -1272,8 +1272,8 @@
                else { 
                        skip_messages = false;
                }
-       }
-
+       }
+
        return mutated;
 }
 
Index: wesnoth/src/gamestatus.cpp
diff -u wesnoth/src/gamestatus.cpp:1.50 wesnoth/src/gamestatus.cpp:1.51
--- wesnoth/src/gamestatus.cpp:1.50     Fri Dec  3 04:33:56 2004
+++ wesnoth/src/gamestatus.cpp  Sat Dec  4 23:44:09 2004
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.cpp,v 1.50 2004/12/03 04:33:56 Sirp Exp $ */
+/* $Id: gamestatus.cpp,v 1.51 2004/12/04 23:44:09 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -405,32 +405,32 @@
        remove((get_saves_dir() + "/" + name).c_str());
        remove((get_saves_dir() + "/" + modified_name).c_str());
 }
-
-void read_save_file(const std::string& name, config& cfg)
-{
-       std::string modified_name = name;
-       std::replace(modified_name.begin(),modified_name.end(),' ','_');
-
-       //try reading the file both with and without underscores
-       std::string file_data = read_file(get_saves_dir() + "/" + 
modified_name);
-       if(file_data.empty()) {
-               file_data = read_file(get_saves_dir() + "/" + name);
-       }
-
-       cfg.clear();
-       cfg.read(file_data);
-
-       if(cfg.empty()) {
-               std::cerr << "Could not parse file data into config\n";
-               throw gamestatus::load_game_failed();
-       }
-}
+
+void read_save_file(const std::string& name, config& cfg)
+{
+       std::string modified_name = name;
+       std::replace(modified_name.begin(),modified_name.end(),' ','_');
+
+       //try reading the file both with and without underscores
+       std::string file_data = read_file(get_saves_dir() + "/" + 
modified_name);
+       if(file_data.empty()) {
+               file_data = read_file(get_saves_dir() + "/" + name);
+       }
+
+       cfg.clear();
+       cfg.read(file_data);
+
+       if(cfg.empty()) {
+               std::cerr << "Could not parse file data into config\n";
+               throw gamestatus::load_game_failed();
+       }
+}
 
 void load_game(const game_data& data, const std::string& name, game_state& 
state)
 {
-       log_scope("load_game");
-
-       config cfg;
+       log_scope("load_game");
+
+       config cfg;
        read_save_file(name,cfg);
        
        state = read_game(data,&cfg);
Index: wesnoth/src/gamestatus.hpp
diff -u wesnoth/src/gamestatus.hpp:1.35 wesnoth/src/gamestatus.hpp:1.36
--- wesnoth/src/gamestatus.hpp:1.35     Sat Dec  4 15:14:09 2004
+++ wesnoth/src/gamestatus.hpp  Sat Dec  4 23:44:09 2004
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.hpp,v 1.35 2004/12/04 15:14:09 silene Exp $ */
+/* $Id: gamestatus.hpp,v 1.36 2004/12/04 23:44:09 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -188,8 +188,8 @@
 std::vector<save_info> get_saves_list();
 
 enum WRITE_GAME_MODE { WRITE_SNAPSHOT_ONLY, WRITE_FULL_GAME };
-
-void read_save_file(const std::string& name, config& cfg);
+
+void read_save_file(const std::string& name, config& cfg);
 
 game_state read_game(const game_data& data, const config* cfg);
 void write_game(const game_state& game, config& cfg, WRITE_GAME_MODE 
mode=WRITE_FULL_GAME);
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.305 wesnoth/src/playturn.cpp:1.306
--- wesnoth/src/playturn.cpp:1.305      Fri Dec  3 01:19:29 2004
+++ wesnoth/src/playturn.cpp    Sat Dec  4 23:44:09 2004
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.305 2004/12/03 01:19:29 Sirp Exp $ */
+/* $Id: playturn.cpp,v 1.306 2004/12/04 23:44:09 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -299,14 +299,14 @@
                //the attack cursor
 
                const unit_map::const_iterator selected_unit = 
find_unit(selected_hex_);
-               const unit_map::const_iterator mouseover_unit = 
find_unit(new_hex);
-
-               gamemap::location attack_from;
-               if(selected_unit != units_.end() && mouseover_unit != 
units_.end()) {
-                       attack_from = current_unit_attacks_from(new_hex);
-               }
+               const unit_map::const_iterator mouseover_unit = 
find_unit(new_hex);
 
-               if(selected_unit != units_.end() && 
(current_paths_.routes.count(new_hex) ||
+               gamemap::location attack_from;
+               if(selected_unit != units_.end() && mouseover_unit != 
units_.end()) {
+                       attack_from = current_unit_attacks_from(new_hex);
+               }
+
+               if(selected_unit != units_.end() && 
(current_paths_.routes.count(new_hex) ||
                                                     attack_from.valid())) {
                        if(mouseover_unit == units_.end()) {
                                cursor::set(cursor::MOVE);
@@ -330,8 +330,8 @@
                        gui_.set_route(NULL);
                } else if(new_hex != last_hex_ &&
                   !current_paths_.routes.empty() && 
map_.on_board(selected_hex_) &&
-                  map_.on_board(new_hex)) {
-
+                  map_.on_board(new_hex)) {
+
                        const gamemap::location& dest = attack_from.valid() ? 
attack_from : new_hex;
 
                        unit_map::const_iterator un = find_unit(selected_hex_);
@@ -529,208 +529,208 @@
 }
 
 }
-
-bool turn_info::attack_enemy(unit_map::iterator attacker, unit_map::iterator 
defender)
-{
-       //we must get locations by value instead of by references, because the 
iterators
-       //may become invalidated later
-       const gamemap::location attacker_loc = attacker->first;
-       const gamemap::location defender_loc = defender->first;
-
-       const std::vector<attack_type>& attacks = attacker->second.attacks();
-       std::vector<std::string> items;
-
-       const int range = distance_between(attacker->first,defender->first);
-       std::vector<int> attacks_in_range;
-
-       int best_weapon_index = -1;
-       int best_weapon_rating = 0;
-
-       std::vector<battle_stats> stats;
-
-       for(size_t a = 0; a != attacks.size(); ++a) {
-               if(attacks[a].hexes() < range)
-                       continue;
-
-               attacks_in_range.push_back(a);
-
-               stats.push_back(evaluate_battle_stats(map_, attacker_loc, 
defender_loc,
-                                                     a, units_, status_));
-
-               int weapon_rating = stats.back().chance_to_hit_defender *
-                               stats.back().damage_defender_takes * 
stats.back().nattacks;
-               
-               if (best_weapon_index < 0 || best_weapon_rating < 
weapon_rating) {
-                       best_weapon_index = items.size();
-                       best_weapon_rating = weapon_rating;
-               }
-               
-               const battle_stats& st = stats.back();
-
-               const std::string& attack_name = st.attack_name;
-               const std::string& attack_special = st.attack_special.empty() ? 
"" : gettext(st.attack_special.c_str());
-               const std::string& defend_name = st.defend_name;
-               const std::string& defend_special = st.defend_special.empty() ? 
"" : gettext(st.defend_special.c_str());
-
-               const std::string& range = gettext(st.range == "Melee" ? 
N_("melee") : N_("ranged"));
-
-               //if there is an attack special or defend special, we output a 
single space for the other unit, to make sure
-               //that the attacks line up nicely.
-               std::string special_pad = (attack_special.empty() == false || 
defend_special.empty() == false) ? " " : "";
-
-               std::stringstream att;
-               att << IMAGE_PREFIX << stats.back().attack_icon << 
COLUMN_SEPARATOR
-                   << font::BOLD_TEXT << attack_name
-                   << "\n" << stats.back().damage_defender_takes << "-"
-                       << stats.back().nattacks << " " << range << " ("
-                       << stats.back().chance_to_hit_defender << "%)\n"
-                       << attack_special << special_pad;
-
-               att << COLUMN_SEPARATOR << _("vs") << COLUMN_SEPARATOR;
-               att << font::BOLD_TEXT << defend_name << "\n" << 
stats.back().damage_attacker_takes << "-"
-                       << stats.back().ndefends << " " << range << " ("
-                       << stats.back().chance_to_hit_attacker
-                   << "%)\n" << defend_special << special_pad << 
COLUMN_SEPARATOR
-                   << IMAGE_PREFIX << stats.back().defend_icon;
-
-               items.push_back(att.str());
-       }
-       
-       if (best_weapon_index >= 0) {
-               items[best_weapon_index] = "*" + items[best_weapon_index];
-       }
-               
-       //make it so that when we attack an enemy, the attacking unit
-       //is again shown in the status bar, so that we can easily
-       //compare between the attacking and defending unit
-       gui_.highlight_hex(gamemap::location());
-       gui_.draw(true,true);
-
-       attack_calculations_displayer calc_displayer(gui_,stats);
-       std::vector<gui::dialog_button> buttons;
-       buttons.push_back(gui::dialog_button(&calc_displayer,_("Damage 
Calculations")));
-
-       int res = 0;
-
-       {
-               const events::event_context dialog_events_context;
-               dialogs::unit_preview_pane 
attacker_preview(gui_,&map_,attacker->second,dialogs::unit_preview_pane::SHOW_BASIC,true);
-               dialogs::unit_preview_pane 
defender_preview(gui_,&map_,defender->second,dialogs::unit_preview_pane::SHOW_BASIC,false);
-               std::vector<gui::preview_pane*> preview_panes;
-               preview_panes.push_back(&attacker_preview);
-               preview_panes.push_back(&defender_preview);
-
-               res = gui::show_dialog(gui_,NULL,_("Attack Enemy"),
-                               _("Choose weapon")+std::string(":\n"),
-                               
gui::OK_CANCEL,&items,&preview_panes,"",NULL,-1,NULL,NULL,-1,-1,
-                               NULL,&buttons);
-       }
-
-       cursor::set(cursor::NORMAL);
-
-       if(size_t(res) < attacks_in_range.size()) {
-               res = attacks_in_range[res];
-
-               attacker->second.set_goto(gamemap::location());
-               clear_undo_stack();
-               redo_stack_.clear();
-
-               current_paths_ = paths();
-               gui_.set_paths(NULL);
-
-               game_events::fire("attack",attacker_loc,defender_loc);
-
-               //the event could have killed either the attacker or
-               //defender, so we have to make sure they still exist
-               attacker = units_.find(attacker_loc);
-               defender = units_.find(defender_loc);
-
-               if(attacker == units_.end() || defender == units_.end() || 
size_t(res) >= attacks.size()) {
-                       return true;
-               }
-
-               gui_.invalidate_all();
-               gui_.draw();
-
-               const bool defender_human = 
teams_[defender->second.side()-1].is_human();
-
-               recorder.add_attack(attacker_loc,defender_loc,res);
-
-               try {
-                       
attack(gui_,map_,teams_,attacker_loc,defender_loc,res,units_,status_,gameinfo_);
-               } catch(end_level_exception&) {
-                       //if the level ends due to a unit being killed, still 
see if
-                       //either the attacker or defender should advance
-                       
dialogs::advance_unit(gameinfo_,map_,units_,attacker_loc,gui_);
-                       
dialogs::advance_unit(gameinfo_,map_,units_,defender_loc,gui_,!defender_human);
-                       throw;
-               }
-
-               dialogs::advance_unit(gameinfo_,map_,units_,attacker_loc,gui_);
-               
dialogs::advance_unit(gameinfo_,map_,units_,defender_loc,gui_,!defender_human);
-
-               selected_hex_ = gamemap::location();
-               current_route_.steps.clear();
-               gui_.set_route(NULL);
-
-               check_victory(units_,teams_);
-
-               gui_.invalidate_all();
-               gui_.draw(); //clear the screen
-
-               return true;
-       } else {
-               return false;
-       }
-}
-
-bool turn_info::move_unit_along_current_route(bool check_shroud)
-{
-       const std::vector<gamemap::location> steps = current_route_.steps;
-       const size_t moves = 
::move_unit(&gui_,gameinfo_,status_,map_,units_,teams_,
-                          
steps,&recorder,&undo_stack_,&next_unit_,false,check_shroud);
-
-       cursor::set(cursor::NORMAL);
-
-       gui_.invalidate_game_status();
-
-       selected_hex_ = gamemap::location();
-       gui_.select_hex(gamemap::location());
-       
-       gui_.set_route(NULL);
-       gui_.set_paths(NULL);
-       current_paths_ = paths();
-
-       if(moves == 0)
-               return false;
-
-       redo_stack_.clear();
-
-       assert(moves <= steps.size());
-       const gamemap::location& dst = steps[moves-1];
-       const unit_map::const_iterator u = units_.find(dst);
-
-       //u may be equal to units_.end() in the case of e.g. a [teleport]
-       if(u != units_.end()) {
-               //Reselect the unit if the move was interrupted
-               if(dst != steps.back()) {
-                       selected_hex_ = dst;
-                       gui_.select_hex(dst);
-               }
-               
-               current_route_.steps.clear();
-               show_attack_options(u);
-               
-               if(current_paths_.routes.empty() == false) {
-                       current_paths_.routes[dst] = paths::route();
-                       selected_hex_ = dst;
-                       gui_.select_hex(dst);
-                       gui_.set_paths(&current_paths_);
-               }
-       }
-
-       return moves == steps.size();
-}
+
+bool turn_info::attack_enemy(unit_map::iterator attacker, unit_map::iterator 
defender)
+{
+       //we must get locations by value instead of by references, because the 
iterators
+       //may become invalidated later
+       const gamemap::location attacker_loc = attacker->first;
+       const gamemap::location defender_loc = defender->first;
+
+       const std::vector<attack_type>& attacks = attacker->second.attacks();
+       std::vector<std::string> items;
+
+       const int range = distance_between(attacker->first,defender->first);
+       std::vector<int> attacks_in_range;
+
+       int best_weapon_index = -1;
+       int best_weapon_rating = 0;
+
+       std::vector<battle_stats> stats;
+
+       for(size_t a = 0; a != attacks.size(); ++a) {
+               if(attacks[a].hexes() < range)
+                       continue;
+
+               attacks_in_range.push_back(a);
+
+               stats.push_back(evaluate_battle_stats(map_, attacker_loc, 
defender_loc,
+                                                     a, units_, status_));
+
+               int weapon_rating = stats.back().chance_to_hit_defender *
+                               stats.back().damage_defender_takes * 
stats.back().nattacks;
+               
+               if (best_weapon_index < 0 || best_weapon_rating < 
weapon_rating) {
+                       best_weapon_index = items.size();
+                       best_weapon_rating = weapon_rating;
+               }
+               
+               const battle_stats& st = stats.back();
+
+               const std::string& attack_name = st.attack_name;
+               const std::string& attack_special = st.attack_special.empty() ? 
"" : gettext(st.attack_special.c_str());
+               const std::string& defend_name = st.defend_name;
+               const std::string& defend_special = st.defend_special.empty() ? 
"" : gettext(st.defend_special.c_str());
+
+               const std::string& range = gettext(st.range == "Melee" ? 
N_("melee") : N_("ranged"));
+
+               //if there is an attack special or defend special, we output a 
single space for the other unit, to make sure
+               //that the attacks line up nicely.
+               std::string special_pad = (attack_special.empty() == false || 
defend_special.empty() == false) ? " " : "";
+
+               std::stringstream att;
+               att << IMAGE_PREFIX << stats.back().attack_icon << 
COLUMN_SEPARATOR
+                   << font::BOLD_TEXT << attack_name
+                   << "\n" << stats.back().damage_defender_takes << "-"
+                       << stats.back().nattacks << " " << range << " ("
+                       << stats.back().chance_to_hit_defender << "%)\n"
+                       << attack_special << special_pad;
+
+               att << COLUMN_SEPARATOR << _("vs") << COLUMN_SEPARATOR;
+               att << font::BOLD_TEXT << defend_name << "\n" << 
stats.back().damage_attacker_takes << "-"
+                       << stats.back().ndefends << " " << range << " ("
+                       << stats.back().chance_to_hit_attacker
+                   << "%)\n" << defend_special << special_pad << 
COLUMN_SEPARATOR
+                   << IMAGE_PREFIX << stats.back().defend_icon;
+
+               items.push_back(att.str());
+       }
+       
+       if (best_weapon_index >= 0) {
+               items[best_weapon_index] = "*" + items[best_weapon_index];
+       }
+               
+       //make it so that when we attack an enemy, the attacking unit
+       //is again shown in the status bar, so that we can easily
+       //compare between the attacking and defending unit
+       gui_.highlight_hex(gamemap::location());
+       gui_.draw(true,true);
+
+       attack_calculations_displayer calc_displayer(gui_,stats);
+       std::vector<gui::dialog_button> buttons;
+       buttons.push_back(gui::dialog_button(&calc_displayer,_("Damage 
Calculations")));
+
+       int res = 0;
+
+       {
+               const events::event_context dialog_events_context;
+               dialogs::unit_preview_pane 
attacker_preview(gui_,&map_,attacker->second,dialogs::unit_preview_pane::SHOW_BASIC,true);
+               dialogs::unit_preview_pane 
defender_preview(gui_,&map_,defender->second,dialogs::unit_preview_pane::SHOW_BASIC,false);
+               std::vector<gui::preview_pane*> preview_panes;
+               preview_panes.push_back(&attacker_preview);
+               preview_panes.push_back(&defender_preview);
+
+               res = gui::show_dialog(gui_,NULL,_("Attack Enemy"),
+                               _("Choose weapon")+std::string(":\n"),
+                               
gui::OK_CANCEL,&items,&preview_panes,"",NULL,-1,NULL,NULL,-1,-1,
+                               NULL,&buttons);
+       }
+
+       cursor::set(cursor::NORMAL);
+
+       if(size_t(res) < attacks_in_range.size()) {
+               res = attacks_in_range[res];
+
+               attacker->second.set_goto(gamemap::location());
+               clear_undo_stack();
+               redo_stack_.clear();
+
+               current_paths_ = paths();
+               gui_.set_paths(NULL);
+
+               game_events::fire("attack",attacker_loc,defender_loc);
+
+               //the event could have killed either the attacker or
+               //defender, so we have to make sure they still exist
+               attacker = units_.find(attacker_loc);
+               defender = units_.find(defender_loc);
+
+               if(attacker == units_.end() || defender == units_.end() || 
size_t(res) >= attacks.size()) {
+                       return true;
+               }
+
+               gui_.invalidate_all();
+               gui_.draw();
+
+               const bool defender_human = 
teams_[defender->second.side()-1].is_human();
+
+               recorder.add_attack(attacker_loc,defender_loc,res);
+
+               try {
+                       
attack(gui_,map_,teams_,attacker_loc,defender_loc,res,units_,status_,gameinfo_);
+               } catch(end_level_exception&) {
+                       //if the level ends due to a unit being killed, still 
see if
+                       //either the attacker or defender should advance
+                       
dialogs::advance_unit(gameinfo_,map_,units_,attacker_loc,gui_);
+                       
dialogs::advance_unit(gameinfo_,map_,units_,defender_loc,gui_,!defender_human);
+                       throw;
+               }
+
+               dialogs::advance_unit(gameinfo_,map_,units_,attacker_loc,gui_);
+               
dialogs::advance_unit(gameinfo_,map_,units_,defender_loc,gui_,!defender_human);
+
+               selected_hex_ = gamemap::location();
+               current_route_.steps.clear();
+               gui_.set_route(NULL);
+
+               check_victory(units_,teams_);
+
+               gui_.invalidate_all();
+               gui_.draw(); //clear the screen
+
+               return true;
+       } else {
+               return false;
+       }
+}
+
+bool turn_info::move_unit_along_current_route(bool check_shroud)
+{
+       const std::vector<gamemap::location> steps = current_route_.steps;
+       const size_t moves = 
::move_unit(&gui_,gameinfo_,status_,map_,units_,teams_,
+                          
steps,&recorder,&undo_stack_,&next_unit_,false,check_shroud);
+
+       cursor::set(cursor::NORMAL);
+
+       gui_.invalidate_game_status();
+
+       selected_hex_ = gamemap::location();
+       gui_.select_hex(gamemap::location());
+       
+       gui_.set_route(NULL);
+       gui_.set_paths(NULL);
+       current_paths_ = paths();
+
+       if(moves == 0)
+               return false;
+
+       redo_stack_.clear();
+
+       assert(moves <= steps.size());
+       const gamemap::location& dst = steps[moves-1];
+       const unit_map::const_iterator u = units_.find(dst);
+
+       //u may be equal to units_.end() in the case of e.g. a [teleport]
+       if(u != units_.end()) {
+               //Reselect the unit if the move was interrupted
+               if(dst != steps.back()) {
+                       selected_hex_ = dst;
+                       gui_.select_hex(dst);
+               }
+               
+               current_route_.steps.clear();
+               show_attack_options(u);
+               
+               if(current_paths_.routes.empty() == false) {
+                       current_paths_.routes[dst] = paths::route();
+                       selected_hex_ = dst;
+                       gui_.select_hex(dst);
+                       gui_.set_paths(&current_paths_);
+               }
+       }
+
+       return moves == steps.size();
+}
 
 void turn_info::left_click(const SDL_MouseButtonEvent& event)
 {
@@ -763,30 +763,30 @@
                        route = enemy_paths_ ? current_paths_.routes.end() :
                                       current_paths_.routes.find(hex);
 
-       unit_map::iterator enemy = find_unit(hex);
-
-       //see if we're trying to do a move-and-attack
-       if(!browse_ && u != units_.end() && enemy != units_.end()) {
-               const gamemap::location& attack_from = 
current_unit_attacks_from(hex);
-               if(attack_from.valid()) {
-                       if(move_unit_along_current_route(false)) { //move the 
unit without updating shroud
-                               u = find_unit(attack_from);
-                               enemy = find_unit(hex);
-                               if(u != units_.end() && u->second.side() == 
team_num_ &&
-                                  enemy != units_.end() && 
current_team().is_enemy(enemy->second.side())) {
-                                       if(attack_enemy(u,enemy) == false) {
-                                               undo();
-                                               return;
-                                       }
-                               }
-                       }
-
-                       if(clear_shroud()) {
-                               clear_undo_stack();
-                       }
-
-                       return;
-               }
+       unit_map::iterator enemy = find_unit(hex);
+
+       //see if we're trying to do a move-and-attack
+       if(!browse_ && u != units_.end() && enemy != units_.end()) {
+               const gamemap::location& attack_from = 
current_unit_attacks_from(hex);
+               if(attack_from.valid()) {
+                       if(move_unit_along_current_route(false)) { //move the 
unit without updating shroud
+                               u = find_unit(attack_from);
+                               enemy = find_unit(hex);
+                               if(u != units_.end() && u->second.side() == 
team_num_ &&
+                                  enemy != units_.end() && 
current_team().is_enemy(enemy->second.side())) {
+                                       if(attack_enemy(u,enemy) == false) {
+                                               undo();
+                                               return;
+                                       }
+                               }
+                       }
+
+                       if(clear_shroud()) {
+                               clear_undo_stack();
+                       }
+
+                       return;
+               }
        }
 
        //see if we're trying to attack an enemy
@@ -802,9 +802,9 @@
                     units_.count(selected_hex_) && !enemy_paths_ &&
                     enemy == units_.end() && !current_route_.steps.empty() &&
                     current_route_.steps.front() == selected_hex_) {
-               move_unit_along_current_route();
-               if(clear_shroud()) {
-                       clear_undo_stack();
+               move_unit_along_current_route();
+               if(clear_shroud()) {
+                       clear_undo_stack();
                }
        } else {
                gui_.set_paths(NULL);
@@ -869,47 +869,47 @@
                        current_paths_.routes[target->first] = paths::route();
                }
        }
-}
-
-gamemap::location turn_info::current_unit_attacks_from(const 
gamemap::location& loc) const
-{
-       const unit_map::const_iterator current = find_unit(selected_hex_);
-       if(current == units_.end() || current->second.side() != team_num_) {
-               return gamemap::location();
-       }
-
-       const unit_map::const_iterator enemy = find_unit(loc);
-       if(enemy == units_.end() || 
current_team().is_enemy(enemy->second.side()) == false) {
-               return gamemap::location();
-       }
-
-       int best_defense = 100;
-       gamemap::location res;
-       gamemap::location adj[6];
-       get_adjacent_tiles(loc,adj);
-       for(size_t n = 0; n != 6; ++n) {
-               if(map_.on_board(adj[n]) == false) {
-                       continue;
-               }
-
-               if(adj[n] == selected_hex_) {
-                       return gamemap::location();
-               }
-
-               if(find_unit(adj[n]) != units_.end()) {
-                       continue;
-               }
-
-               if(current_paths_.routes.count(adj[n])) {
-                       const int defense = 
current->second.defense_modifier(map_,map_.get_terrain(loc));
-                       if(defense < best_defense || res.valid() == false) {
-                               best_defense = defense;
-                               res = adj[n];
-                       }
-               }
-       }
-
-       return res;
+}
+
+gamemap::location turn_info::current_unit_attacks_from(const 
gamemap::location& loc) const
+{
+       const unit_map::const_iterator current = find_unit(selected_hex_);
+       if(current == units_.end() || current->second.side() != team_num_) {
+               return gamemap::location();
+       }
+
+       const unit_map::const_iterator enemy = find_unit(loc);
+       if(enemy == units_.end() || 
current_team().is_enemy(enemy->second.side()) == false) {
+               return gamemap::location();
+       }
+
+       int best_defense = 100;
+       gamemap::location res;
+       gamemap::location adj[6];
+       get_adjacent_tiles(loc,adj);
+       for(size_t n = 0; n != 6; ++n) {
+               if(map_.on_board(adj[n]) == false) {
+                       continue;
+               }
+
+               if(adj[n] == selected_hex_) {
+                       return gamemap::location();
+               }
+
+               if(find_unit(adj[n]) != units_.end()) {
+                       continue;
+               }
+
+               if(current_paths_.routes.count(adj[n])) {
+                       const int defense = 
current->second.defense_modifier(map_,map_.get_terrain(loc));
+                       if(defense < best_defense || res.valid() == false) {
+                               best_defense = defense;
+                               res = adj[n];
+                       }
+               }
+       }
+
+       return res;
 }
 
 void turn_info::move_unit_to_loc(const unit_map::const_iterator& ui, const 
gamemap::location& target, bool continue_move)
@@ -1292,10 +1292,10 @@
                                << ", which has no recall list!\n";
                } else {
                        // Undo a recall action
-                       team& current_team = teams_[team_num_-1];
-                       if(units_.count(action.recall_loc) == 0) {
-                               return;
-                       }
+                       team& current_team = teams_[team_num_-1];
+                       if(units_.count(action.recall_loc) == 0) {
+                               return;
+                       }
 
                        const unit& un = units_.find(action.recall_loc)->second;
                        statistics::un_recall_unit(un);
@@ -1313,7 +1313,7 @@
                std::reverse(route.begin(),route.end());
                const unit_map::iterator u = units_.find(route.front());
                if(u == units_.end()) {
-                       //this can actually happen if the scenario designer has 
abused the [allow_undo] command
+                       //this can actually happen if the scenario designer has 
abused the [allow_undo] command
                        lg::err(lg::engine) << "Illegal 'undo' found. Possible 
abuse of [allow_undo]?\n";
                        return;
                }
@@ -2341,7 +2341,7 @@
                const std::string::const_iterator j = 
std::find(data.begin(),data.end(),' ');
                if(j != data.end()) {
                        const std::string side(data.begin(),j);
-                       const std::string player(j+1,data.end());
+                       const std::string player(j+1,data.end());
 
                        change_side_controller(side,player);
                }
@@ -2382,10 +2382,10 @@
        config cfg;
        config& change = cfg.add_child("change_controller");
        change["side"] = side;
-       change["player"] = player;
-
-       if(orphan_side) {
-               change["orphan_side"] = "yes";
+       change["player"] = player;
+
+       if(orphan_side) {
+               change["orphan_side"] = "yes";
        }
 
        network::send_data(cfg);
Index: wesnoth/src/playturn.hpp
diff -u wesnoth/src/playturn.hpp:1.56 wesnoth/src/playturn.hpp:1.57
--- wesnoth/src/playturn.hpp:1.56       Fri Dec  3 01:19:29 2004
+++ wesnoth/src/playturn.hpp    Sat Dec  4 23:44:09 2004
@@ -1,4 +1,4 @@
-/* $Id: playturn.hpp,v 1.56 2004/12/03 01:19:29 Sirp Exp $ */
+/* $Id: playturn.hpp,v 1.57 2004/12/04 23:44:09 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -184,14 +184,14 @@
        void left_click(const SDL_MouseButtonEvent& event);
        void show_menu(const std::vector<std::string>& items, int xloc, int 
yloc, bool context_menu);
 
-       void show_attack_options(unit_map::const_iterator u);
-
-       //function which, given the location of a potential enemy to attack, 
will return the location
-       //that the currently selected unit would move to and attack it from 
this turn. Returns an
-       //invalid location if not possible.
-       gamemap::location current_unit_attacks_from(const gamemap::location& 
loc) const;
-
-       bool attack_enemy(unit_map::iterator attacker, unit_map::iterator 
defender);
+       void show_attack_options(unit_map::const_iterator u);
+
+       //function which, given the location of a potential enemy to attack, 
will return the location
+       //that the currently selected unit would move to and attack it from 
this turn. Returns an
+       //invalid location if not possible.
+       gamemap::location current_unit_attacks_from(const gamemap::location& 
loc) const;
+
+       bool attack_enemy(unit_map::iterator attacker, unit_map::iterator 
defender);
        bool move_unit_along_current_route(bool check_shroud=true);
 
        bool clear_shroud();




reply via email to

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