[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src map.cpp pathutils.cpp unit_display....
From: |
David White |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src map.cpp pathutils.cpp unit_display.... |
Date: |
Sun, 06 Feb 2005 22:44:38 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: David White <address@hidden> 05/02/07 03:44:37
Modified files:
src : map.cpp pathutils.cpp unit_display.cpp
unit_types.cpp map.hpp pathutils.hpp
unit_types.hpp
Log message:
added ability to customize attack animations based on direction attack
takes place from
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.cpp.diff?tr1=1.47&tr2=1.48&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathutils.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.cpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.cpp.diff?tr1=1.76&tr2=1.77&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map.hpp.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathutils.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.hpp.diff?tr1=1.56&tr2=1.57&r1=text&r2=text
Patches:
Index: wesnoth/src/map.cpp
diff -u wesnoth/src/map.cpp:1.47 wesnoth/src/map.cpp:1.48
--- wesnoth/src/map.cpp:1.47 Thu Jan 20 21:59:52 2005
+++ wesnoth/src/map.cpp Mon Feb 7 03:44:37 2005
@@ -1,4 +1,4 @@
-/* $Id: map.cpp,v 1.47 2005/01/20 21:59:52 silene Exp $ */
+/* $Id: map.cpp,v 1.48 2005/02/07 03:44:37 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -83,6 +83,25 @@
{
return on_board(loc) && is_keep(get_terrain(loc));
}
+
+gamemap::location::DIRECTION gamemap::location::parse_direction(const
std::string& str)
+{
+ if(str == "n") {
+ return NORTH;
+ } else if(str == "ne") {
+ return NORTH_EAST;
+ } else if(str == "se") {
+ return SOUTH_EAST;
+ } else if(str == "s") {
+ return SOUTH;
+ } else if(str == "sw") {
+ return SOUTH_WEST;
+ } else if(str == "nw") {
+ return NORTH_WEST;
+ } else {
+ return NDIRECTIONS;
+ }
+}
gamemap::location::location(const config& cfg) : x(-1), y(-1)
{
Index: wesnoth/src/map.hpp
diff -u wesnoth/src/map.hpp:1.30 wesnoth/src/map.hpp:1.31
--- wesnoth/src/map.hpp:1.30 Fri Jan 21 22:21:54 2005
+++ wesnoth/src/map.hpp Mon Feb 7 03:44:37 2005
@@ -1,4 +1,4 @@
-/* $Id: map.hpp,v 1.30 2005/01/21 22:21:54 Sirp Exp $ */
+/* $Id: map.hpp,v 1.31 2005/02/07 03:44:37 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -52,7 +52,9 @@
struct location {
//any valid direction which can be moved in in our hexagonal
world.
enum DIRECTION { NORTH, NORTH_EAST, SOUTH_EAST, SOUTH,
- SOUTH_WEST, NORTH_WEST };
+ SOUTH_WEST, NORTH_WEST, NDIRECTIONS };
+
+ static DIRECTION parse_direction(const std::string& str);
location() : x(-1), y(-1) {}
location(int x, int y) : x(x), y(y) {}
Index: wesnoth/src/pathutils.cpp
diff -u wesnoth/src/pathutils.cpp:1.2 wesnoth/src/pathutils.cpp:1.3
--- wesnoth/src/pathutils.cpp:1.2 Thu Nov 18 04:08:32 2004
+++ wesnoth/src/pathutils.cpp Mon Feb 7 03:44:37 2005
@@ -34,6 +34,19 @@
++res;
res->x = a.x-1;
res->y = a.y - (is_even(a.x) ? 1:0);
+}
+
+gamemap::location::DIRECTION get_adjacent_direction(const gamemap::location&
from, const gamemap::location& to)
+{
+ gamemap::location adj[6];
+ get_adjacent_tiles(from,adj);
+ for(size_t n = 0; n != 6; ++n) {
+ if(adj[n] == to) {
+ return static_cast<gamemap::location::DIRECTION>(n);
+ }
+ }
+
+ return gamemap::location::NDIRECTIONS;
}
bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b)
Index: wesnoth/src/pathutils.hpp
diff -u wesnoth/src/pathutils.hpp:1.2 wesnoth/src/pathutils.hpp:1.3
--- wesnoth/src/pathutils.hpp:1.2 Fri Jan 21 20:16:43 2005
+++ wesnoth/src/pathutils.hpp Mon Feb 7 03:44:37 2005
@@ -1,4 +1,4 @@
-/* $Id: pathutils.hpp,v 1.2 2005/01/21 20:16:43 Sirp Exp $ */
+/* $Id: pathutils.hpp,v 1.3 2005/02/07 03:44:37 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -22,7 +22,11 @@
//function which, given a location, will place all adjacent locations in
//res. res must point to an array of 6 location objects.
-void get_adjacent_tiles(const gamemap::location& a, gamemap::location* res);
+void get_adjacent_tiles(const gamemap::location& a, gamemap::location* res);
+
+//function which returns the direction from 'from' to 'to'. If 'from' and 'to'
are not adjacent, then
+//the function will return 'NDIRECTIONS'.
+gamemap::location::DIRECTION get_adjacent_direction(const gamemap::location&
from, const gamemap::location& to);
//function which gives the number of hexes between two tiles (i.e. the minimum
//number of hexes that have to be traversed to get from one hex to the other)
Index: wesnoth/src/unit_display.cpp
diff -u wesnoth/src/unit_display.cpp:1.49 wesnoth/src/unit_display.cpp:1.50
--- wesnoth/src/unit_display.cpp:1.49 Sun Feb 6 10:40:12 2005
+++ wesnoth/src/unit_display.cpp Mon Feb 7 03:44:37 2005
@@ -317,7 +317,7 @@
leader->second.set_leading(true);
}
- unit_animation attack_anim = attack.animation();
+ unit_animation attack_anim =
attack.animation(get_adjacent_direction(a,b));
//the missile frames are based around the time when the missile impacts.
//the 'real' frames are based around the time when the missile launches.
@@ -641,7 +641,7 @@
return unit_attack_ranged(disp, units, a, b, damage, attack);
}
- unit_animation attack_anim = attack.animation();
+ unit_animation attack_anim =
attack.animation(get_adjacent_direction(a,b));
const bool hits = damage > 0;
const std::vector<unit_animation::sfx>& sounds =
attack_anim.sound_effects();
Index: wesnoth/src/unit_types.cpp
diff -u wesnoth/src/unit_types.cpp:1.76 wesnoth/src/unit_types.cpp:1.77
--- wesnoth/src/unit_types.cpp:1.76 Sun Feb 6 10:40:12 2005
+++ wesnoth/src/unit_types.cpp Mon Feb 7 03:44:37 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.cpp,v 1.76 2005/02/06 10:40:12 isaaccp Exp $ */
+/* $Id: unit_types.cpp,v 1.77 2005/02/07 03:44:37 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -141,8 +141,19 @@
attack_type::attack_type(const config& cfg)
{
const config::child_list& animations = cfg.get_children("animation");
- for(config::child_list::const_iterator an = animations.begin(); an !=
animations.end(); ++an) {
- animation_.push_back(unit_animation(**an));
+ for(config::child_list::const_iterator an = animations.begin(); an !=
animations.end(); ++an) {
+ const std::string& dir = (**an)["direction"];
+ if(dir == "") {
+ animation_.push_back(unit_animation(**an));
+ } else {
+ const std::vector<std::string>& directions =
config::split(dir);
+ for(std::vector<std::string>::const_iterator i =
directions.begin(); i != directions.end(); ++i) {
+ const gamemap::location::DIRECTION d =
gamemap::location::parse_direction(*i);
+ if(d != gamemap::location::NDIRECTIONS) {
+
direction_animation_[d].push_back(unit_animation(**an));
+ }
+ }
+ }
}
if(animation_.empty()) {
@@ -225,10 +236,16 @@
return slow_;
}
-const unit_animation& attack_type::animation() const
-{
- wassert(animation_.empty() == false);
- return animation_[rand()%animation_.size()];
+const unit_animation& attack_type::animation(const
gamemap::location::DIRECTION dir) const
+{
+ const std::vector<unit_animation>* animation = &animation_;
+ if(dir < sizeof(direction_animation_)/sizeof(*direction_animation_) &&
+ direction_animation_[dir].empty() == false) {
+ animation = &direction_animation_[dir];
+ }
+
+ wassert(animation->empty() == false);
+ return (*animation)[rand()%animation->size()];
}
bool attack_type::matches_filter(const config& cfg) const
Index: wesnoth/src/unit_types.hpp
diff -u wesnoth/src/unit_types.hpp:1.56 wesnoth/src/unit_types.hpp:1.57
--- wesnoth/src/unit_types.hpp:1.56 Sun Feb 6 10:40:12 2005
+++ wesnoth/src/unit_types.hpp Mon Feb 7 03:44:37 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.hpp,v 1.56 2005/02/06 10:40:12 isaaccp Exp $ */
+/* $Id: unit_types.hpp,v 1.57 2005/02/07 03:44:37 Sirp Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -94,12 +94,13 @@
//this function returns a random animation out of the possible
//animations for this attack. It will not return the same attack
//each time.
- const unit_animation& animation() const;
+ const unit_animation& animation(gamemap::location::DIRECTION
dir=gamemap::location::NDIRECTIONS) const;
bool matches_filter(const config& cfg) const;
bool apply_modification(const config& cfg,std::string* description);
private:
- std::vector<unit_animation> animation_;
+ std::vector<unit_animation> animation_;
+ std::vector<unit_animation> direction_animation_[6];
std::string name_;
std::string type_;
std::string special_;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src map.cpp pathutils.cpp unit_display....,
David White <=