Author: dragonking
Date: Wed Jun 24 13:49:55 2009
New Revision: 36385
URL: http://svn.gna.org/viewcvs/wesnoth?rev=36385&view=rev
Log:
Fixed bugs #13430 and #13431
Modified:
trunk/src/callable_objects.cpp
trunk/src/callable_objects.hpp
Modified: trunk/src/callable_objects.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/callable_objects.cpp?rev=36385&r1=36384&r2=36385&view=diff
==============================================================================
--- trunk/src/callable_objects.cpp (original)
+++ trunk/src/callable_objects.cpp Wed Jun 24 13:49:55 2009
@@ -138,6 +138,31 @@
inputs->push_back(game_logic::formula_input("damage",
FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("number_of_attacks",
FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("special",
FORMULA_READ_ONLY));
+}
+
+int attack_type_callable::do_compare(const formula_callable* callable) const
+{
+ const attack_type_callable* att_callable = dynamic_cast<const
attack_type_callable*>(callable);
+ if(att_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ if (att_.damage() != att_callable->att_.damage() )
+ return att_.damage() - att_callable->att_.damage();
+
+ if (att_.num_attacks() != att_callable->att_.num_attacks() )
+ return att_.num_attacks() - att_callable->att_.num_attacks();
+
+ if ( att_.id() != att_callable->att_.id() )
+ return att_.id().compare(att_callable->att_.id());
+
+ if ( att_.type() != att_callable->att_.type() )
+ return att_.type().compare(att_callable->att_.type());
+
+ if ( att_.range() != att_callable->att_.range() )
+ return att_.range().compare(att_callable->att_.range());
+
+ return
att_.weapon_specials().compare(att_callable->att_.weapon_specials());
}
variant unit_callable::get_value(const std::string& key) const
@@ -255,6 +280,16 @@
inputs->push_back(game_logic::formula_input("vars", FORMULA_READ_ONLY));
}
+int unit_callable::do_compare(const formula_callable* callable) const
+{
+ const unit_callable* u_callable = dynamic_cast<const
unit_callable*>(callable);
+ if(u_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ return u_.underlying_id() - u_callable->u_.underlying_id();
+}
+
variant unit_type_callable::get_value(const std::string& key) const
{
if(key == "id") {
@@ -315,6 +350,16 @@
inputs->push_back(game_logic::formula_input("cost", FORMULA_READ_ONLY));
}
+int unit_type_callable::do_compare(const formula_callable* callable) const
+{
+ const unit_type_callable* u_callable = dynamic_cast<const
unit_type_callable*>(callable);
+ if(u_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ return u_.id().compare(u_callable->u_.id());
+}
+
variant terrain_callable::get_value(const std::string& key) const
{
if(key == "x") {
@@ -338,3 +383,68 @@
inputs->push_back(game_logic::formula_input("id", FORMULA_READ_ONLY));
}
+int terrain_callable::do_compare(const formula_callable* callable) const
+{
+ const terrain_callable* terr_callable = dynamic_cast<const
terrain_callable*>(callable);
+ if(terr_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ const map_location& other_loc = terr_callable->loc_;
+ if(other_loc.x != loc_.x) {
+ return loc_.x - other_loc.x;
+ }
+
+ return loc_.y - other_loc.y;
+}
+
+int move_callable::do_compare(const formula_callable* callable) const
+{
+ const move_callable* mv_callable = dynamic_cast<const
move_callable*>(callable);
+ if(mv_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ const map_location& other_src = mv_callable->src_;
+ const map_location& other_dst = mv_callable->dst_;
+
+ if(other_src.x != src_.x) {
+ return src_.x - other_src.x;
+ }
+
+ if(other_src.y != src_.y) {
+ return src_.y - other_src.y;
+ }
+
+ if(other_dst.x != dst_.x) {
+ return dst_.x - other_dst.x;
+ }
+
+ return dst_.y - other_dst.y;
+}
+
+int move_partial_callable::do_compare(const formula_callable* callable) const
+{
+ const move_partial_callable* mv_callable = dynamic_cast<const
move_partial_callable*>(callable);
+ if(mv_callable == NULL) {
+ return formula_callable::do_compare(callable);
+ }
+
+ const map_location& other_src = mv_callable->src_;
+ const map_location& other_dst = mv_callable->dst_;
+
+ if(other_src.x != src_.x) {
+ return src_.x - other_src.x;
+ }
+
+ if(other_src.y != src_.y) {
+ return src_.y - other_src.y;
+ }
+
+ if(other_dst.x != dst_.x) {
+ return dst_.x - other_dst.x;
+ }
+
+ return dst_.y - other_dst.y;
+}
+
Modified: trunk/src/callable_objects.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/callable_objects.hpp?rev=36385&r1=36384&r2=36385&view=diff
==============================================================================
--- trunk/src/callable_objects.hpp (original)
+++ trunk/src/callable_objects.hpp Wed Jun 24 13:49:55 2009
@@ -72,6 +72,8 @@
variant get_value(const std::string& key) const;
void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
private:
+ int do_compare(const formula_callable* callable) const;
+
const location loc_;
const terrain_type &t_;
};
@@ -131,6 +133,8 @@
inputs->push_back(game_logic::formula_input("src",
game_logic::FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("dst",
game_logic::FORMULA_READ_ONLY));
}
+
+ int do_compare(const formula_callable* callable) const;
public:
move_callable(const map_location& src, const map_location& dst) :
src_(src), dst_(dst)
@@ -155,6 +159,8 @@
inputs->push_back(game_logic::formula_input("src",
game_logic::FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("dst",
game_logic::FORMULA_READ_ONLY));
}
+
+ int do_compare(const formula_callable* callable) const;
public:
move_partial_callable(const map_location& src, const map_location& dst)
:
src_(src), dst_(dst)
@@ -191,6 +197,8 @@
const attack_type& get_attack_type() const { return att_; }
variant get_value(const std::string& key) const;
void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
+
+ int do_compare(const formula_callable* callable) const;
private:
const attack_type att_;
};
@@ -206,6 +214,8 @@
const location& get_location() const { return loc_; }
variant get_value(const std::string& key) const;
void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
+
+ int do_compare(const formula_callable* callable) const;
private:
const location& loc_;
const unit& u_;
@@ -220,6 +230,8 @@
const unit_type& get_unit_type() const { return u_; }
variant get_value(const std::string& key) const;
void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
+
+ int do_compare(const formula_callable* callable) const;
private:
const unit_type& u_;
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits