[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-dev] [PATCH] Show number of enemies who can reach each hex in "
From: |
Rusty Russell |
Subject: |
[Wesnoth-dev] [PATCH] Show number of enemies who can reach each hex in "Show Enemy Moves" |
Date: |
Sun, 29 May 2005 17:26:02 +1000 |
I wanted this, because I thought my unit was only reachable by the enemy
in front of it, and didn't see the damn goblin rider offscreen.
The code isn't especially neat (even for C++), but it's fairly simple.
Cheers!
Rusty.
Index: src/display.cpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/display.cpp,v
retrieving revision 1.321
diff -u -r1.321 display.cpp
--- src/display.cpp 16 May 2005 22:44:19 -0000 1.321
+++ src/display.cpp 29 May 2005 06:38:41 -0000
@@ -76,7 +76,7 @@
screen_(video), xpos_(0), ypos_(0),
zoom_(DefaultZoom), map_(map), units_(units),
minimap_(NULL), redrawMinimap_(false),
- pathsList_(NULL), status_(status),
+ pathsList_(NULL), enemy_reach_(NULL), status_(status),
teams_(t), lastDraw_(0), drawSkips_(0),
invalidateAll_(true), invalidateUnit_(true),
invalidateGameStatus_(true), panelsDrawn_(false),
@@ -1514,6 +1514,9 @@
pathsList_->routes.end()) {
image_type = image::GREYED;
}
+ if(enemy_reach_ != NULL && enemy_reach_->find(loc) ==
enemy_reach_->end()) {
+ image_type = image::GREYED;
+ }
unit_map::iterator un = find_visible_unit(units_, loc, map_,
status_.get_time_of_day().lawful_bonus,teams_,teams_[currentTeam_]);
@@ -1551,6 +1554,8 @@
}
}
draw_footstep(loc,xpos,ypos);
+ if (enemy_reach_ != NULL)
+ draw_enemies_reach(loc,xpos,ypos);
} else {
//FIXME: shouldn't void.png and fog.png be in the program
configuration?
surface surface(image::get_image("terrain/void.png"));
@@ -1618,6 +1623,40 @@
update_rect(xpos,ypos,zoom_,zoom_);
}
+void display::draw_enemies_reach(const gamemap::location& loc, int xloc, int
yloc)
+{
+ const reach_map::const_iterator reach_it = enemy_reach_->find(loc);
+
+ // not reachable, leave greyed out.
+ if (reach_it == enemy_reach_->end())
+ return;
+
+ // only one can reach, leave highlighted.
+ if (reach_it->second == 1)
+ return;
+
+ // multiple can reach: print number
+ std::stringstream text;
+ text << reach_it->second;
+ const std::string &str = text.str();
+ const SDL_Rect& rect = map_area();
+
+ const SDL_Rect& text_area = font::text_area(str,font::SIZE_LARGE);
+ const int x = xloc + zoom_/2 - text_area.w/2;
+ const int y = yloc + zoom_/2 - text_area.h/2;
+
+ //draw the text with a black outline
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x-1,y-1);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x-1,y);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x-1,y+1);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x,y-1);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x+1,y-1);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x+1,y);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x+1,y+1);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::DARK_COLOUR,str,x,y+1);
+
font::draw_text(&screen_,rect,font::SIZE_LARGE,font::YELLOW_COLOUR,str,x,y);
+}
+
void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
{
std::vector<gamemap::location>::const_iterator i =
@@ -1910,6 +1949,14 @@
void display::set_paths(const paths* paths_list)
{
pathsList_ = paths_list;
+ enemy_reach_ = NULL;
+ invalidate_all();
+}
+
+void display::set_reach_map(const reach_map *reach_map)
+{
+ pathsList_ = NULL;
+ enemy_reach_ = reach_map;
invalidate_all();
}
Index: src/display.hpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/display.hpp,v
retrieving revision 1.103
diff -u -r1.103 display.hpp
--- src/display.hpp 17 Apr 2005 20:42:10 -0000 1.103
+++ src/display.hpp 29 May 2005 06:38:43 -0000
@@ -161,6 +161,11 @@
//paths_list must remain valid until it is set again
void set_paths(const paths* paths_list);
+ //variation of set_paths which shows how many units can reach each tile.
+ //Setting the reach_map clears the paths_list, and vice-versa.
+ typedef std::map<gamemap::location,unsigned int> reach_map;
+ void set_reach_map(const reach_map *reach_map);
+
//sets the route along which footsteps are drawn to show movement of a
//unit. If NULL, no route is displayed.
//route does not have to remain valid after being set
@@ -200,6 +205,7 @@
// void draw_tile_adjacent(int x, int y, image::TYPE image_type,
ADJACENT_TERRAIN_TYPE type);
+ void draw_enemies_reach(const gamemap::location& loc, int xloc, int
yloc);
public:
//function to draw a footstep for the given location, on screen at
@@ -490,6 +496,8 @@
typedef std::map<gamemap::location,int> halo_map;
halo_map haloes_;
+ const reach_map *enemy_reach_;
+
//for debug mode
static std::map<gamemap::location,fixed_t> debugHighlights_;
Index: src/playturn.cpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/playturn.cpp,v
retrieving revision 1.372
diff -u -r1.372 playturn.cpp
--- src/playturn.cpp 18 May 2005 14:06:30 -0000 1.372
+++ src/playturn.cpp 29 May 2005 06:38:46 -0000
@@ -2637,10 +2637,10 @@
return false;
}
-// Highlights squares that an enemy could move to on their turn
+// Highlights squares that an enemy could move to on their turn, showing how
many can reach each square.
void turn_info::show_enemy_moves(bool ignore_units)
{
- all_paths_ = paths();
+ reach_map_ = display::reach_map();
// Compute enemy movement positions
for(unit_map::iterator u = units_.begin(); u != units_.end(); ++u) {
@@ -2654,14 +2654,12 @@
u->first,teams_,is_skirmisher,teleports);
for (paths::routes_map::const_iterator route =
path.routes.begin(); route != path.routes.end(); ++route) {
- // map<...>::operator[](const key_type& key)
inserts key into
- // the map with a default instance of value_type
- all_paths_.routes[route->first];
+ reach_map_[route->first]++;
}
}
}
-
- gui_.set_paths(&all_paths_);
+
+ gui_.set_reach_map(&reach_map_);
}
void turn_info::toggle_shroud_updates() {
Index: src/playturn.hpp
===================================================================
RCS file: /cvsroot/wesnoth/wesnoth/src/playturn.hpp,v
retrieving revision 1.68
diff -u -r1.68 playturn.hpp
--- src/playturn.hpp 18 May 2005 14:06:30 -0000 1.68
+++ src/playturn.hpp 29 May 2005 06:38:46 -0000
@@ -226,6 +226,7 @@
gamemap::location next_unit_;
paths current_paths_, all_paths_;
paths::route current_route_;
+ display::reach_map reach_map_;
bool enemy_paths_;
gamemap::location last_hex_;
gamemap::location::DIRECTION last_nearest_, last_second_nearest_;
--
A bad analogy is like a leaky screwdriver -- Richard Braakman
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-dev] [PATCH] Show number of enemies who can reach each hex in "Show Enemy Moves",
Rusty Russell <=