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

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

[Wesnoth-cvs-commits] wesnoth/src playturn.cpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src playturn.cpp
Date: Sun, 12 Dec 2004 17:20:17 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    04/12/12 22:02:01

Modified files:
        src            : playturn.cpp 

Log message:
        Enhance default weapon selection (patch #3570).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.309&tr2=1.310&r1=text&r2=text

Patches:
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.309 wesnoth/src/playturn.cpp:1.310
--- wesnoth/src/playturn.cpp:1.309      Sun Dec  5 22:14:29 2004
+++ wesnoth/src/playturn.cpp    Sun Dec 12 22:02:01 2004
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.309 2004/12/05 22:14:29 silene Exp $ */
+/* $Id: playturn.cpp,v 1.310 2004/12/12 22:02:01 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -406,7 +406,39 @@
        return event.button == SDL_BUTTON_RIGHT || event.button == 
SDL_BUTTON_LEFT && command_active();
 }
 
-}
+//which attack is the better one to select for the player by default
+//(the player can change the selected weapon if desired)
+class simple_attack_rating
+{
+public:
+       simple_attack_rating() : attacker_weapon_rating_(0), 
defender_weapon_rating_(0) {}
+
+       simple_attack_rating(const battle_stats& stats) : 
+               attacker_weapon_rating_(stats.chance_to_hit_defender *
+                               stats.damage_defender_takes * stats.nattacks),
+               defender_weapon_rating_(stats.chance_to_hit_attacker *
+                               stats.damage_attacker_takes * stats.ndefends) {}
+
+       bool operator<(const simple_attack_rating& a) const
+       {
+               //if our weapon does less damage, it's worse
+               if(attacker_weapon_rating_ < a.attacker_weapon_rating_)
+                       return true;
+
+               //if both weapons are the same but 
+               //ours makes the enemy retaliate for more damage, it's worse
+               else if(attacker_weapon_rating_ == a.attacker_weapon_rating_ &&
+                  defender_weapon_rating_ > a.defender_weapon_rating_)
+                       return true;
+
+               //otherwise, ours is at least as good a default weapon
+               return false;
+       }
+private:
+       int attacker_weapon_rating_, defender_weapon_rating_;
+};
+
+} //end anonymous namespace
 
 void turn_info::mouse_press(const SDL_MouseButtonEvent& event)
 {
@@ -544,7 +576,7 @@
        std::vector<int> attacks_in_range;
 
        int best_weapon_index = -1;
-       int best_weapon_rating = 0;
+       simple_attack_rating best_weapon_rating;
 
        attack_calculations_displayer::stats_vector stats;
 
@@ -559,13 +591,13 @@
                                                        a, units_, status_, 0, 
&sts);
                stats.push_back(sts);
 
-               int weapon_rating = st.chance_to_hit_defender * 
st.damage_defender_takes * st.nattacks;
-               
+               simple_attack_rating weapon_rating(st);
+
                if (best_weapon_index < 0 || best_weapon_rating < 
weapon_rating) {
                        best_weapon_index = items.size();
                        best_weapon_rating = weapon_rating;
                }
-               
+
                //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 = (sts.attack_special.empty() && 
sts.defend_special.empty()) ? "" : " ";




reply via email to

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