made sword of fire short range. Fixed 'right column inaccessible' bug.

This commit is contained in:
Dave White 2004-04-01 23:07:35 +00:00
parent e8cec32284
commit 30568d6ef2
6 changed files with 260 additions and 32 deletions

View file

@ -638,19 +638,14 @@ What would you like to wish for?"
apply_to=new_attack
name=flaming sword
type=fire
range=long
range=short
special=magical
damage=18
number=3
damage=15
number=4
[sound]
time=-200
sound=fire.wav
[/sound]
[missile_frame]
begin=-100
end=0
image=fireball.png
[/missile_frame]
[/effect]
[/object]
[/event]

View file

@ -270,6 +270,25 @@ void ai_interface::calculate_possible_moves(std::map<location,paths>& res, move_
const location& src = m->first;
const location& dst = rtit->first;
bool friend_owns = false;
//don't take friendly villages
if(!enemy && info_.map.underlying_terrain(info_.map[dst.x][dst.y]) == gamemap::TOWER) {
for(size_t n = 0; n != info_.teams.size(); ++n) {
if(info_.teams[n].owns_tower(dst)) {
if(n+1 != info_.team_num && current_team().is_enemy(n+1) == false) {
friend_owns = true;
}
break;
}
}
}
if(friend_owns) {
continue;
}
if(src != dst && info_.units.find(dst) == info_.units.end()) {
srcdst.insert(std::pair<location,location>(src,dst));
dstsrc.insert(std::pair<location,location>(dst,src));

View file

@ -410,7 +410,7 @@ void display::bounds_check_position()
const int tile_width = static_cast<int>(static_cast<int>(zoom_)*0.75) + 1;
const double xend = tile_width*map_.x();
const double xend = tile_width*map_.x() + tile_width/3;
const double yend = zoom_*map_.y() + zoom_/2.0;
if(xpos_ + static_cast<double>(map_area().w) > xend)
@ -2089,6 +2089,14 @@ bool display::unit_attack(const gamemap::location& a,
Uint32 defender_colour = 0;
double defender_alpha = 1.0;
if(damage > 0 && i == 0) {
char buf[50];
sprintf(buf,"%d",damage);
const SDL_Color colour = {255,0,0,255};
font::add_floating_label(buf,20,colour,get_location_x(b)+zoom_*0.5,get_location_y(b),
0,-3,40,screen_area());
}
if(damage > 0 && i >= 0) {
if(def->second.gets_hit(minimum<int>(drain_speed,damage))) {
dead = true;

View file

@ -18,6 +18,7 @@
#include "game_config.hpp"
#include "language.hpp"
#include "log.hpp"
#include "sdl_utils.hpp"
#include "tooltips.hpp"
#include <cstdio>
@ -461,3 +462,165 @@ namespace font {
}
}
//floating labels
namespace {
class floating_label
{
public:
floating_label(const std::string& text, int font_size, const SDL_Color& colour,
int xpos, int ypos, int xmove, int ymove, int lifetime, const SDL_Rect& clip_rect)
: surf_(NULL), buf_(NULL), text_(text), font_size_(font_size), colour_(colour), xpos_(xpos), ypos_(ypos),
xmove_(xmove), ymove_(ymove), lifetime_(lifetime), clip_rect_(clip_rect)
{}
void move(int xmove, int ymove);
void draw(SDL_Surface* screen);
void undraw(SDL_Surface* screen);
bool expired() const;
private:
shared_sdl_surface surf_, buf_;
std::string text_;
int font_size_;
SDL_Color colour_;
int xpos_, ypos_, xmove_, ymove_;
int lifetime_;
SDL_Rect clip_rect_;
};
typedef std::map<int,floating_label> label_map;
label_map labels;
int label_id = 0;
bool hide_floating_labels = false;
void floating_label::move(int xmove, int ymove)
{
xpos_ += xmove;
ypos_ += ymove;
}
void floating_label::draw(SDL_Surface* screen)
{
if(surf_ == NULL) {
TTF_Font* const font = get_font(font_size_);
if(font == NULL) {
return;
}
surf_.assign(font::render_text(font,text_,colour_));
if(surf_ == NULL) {
return;
}
}
if(buf_ == NULL) {
buf_.assign(SDL_CreateRGBSurface(SDL_SWSURFACE,surf_->w,surf_->h,surf_->format->BitsPerPixel,
surf_->format->Rmask,surf_->format->Gmask,surf_->format->Bmask,surf_->format->Amask));
if(buf_ == NULL) {
return;
}
}
if(screen == NULL) {
return;
}
SDL_Rect rect = {xpos_-surf_->w/2,ypos_,surf_->w,surf_->h};
const clip_rect_setter clip_setter(screen,clip_rect_);
SDL_BlitSurface(screen,&rect,buf_,NULL);
SDL_BlitSurface(surf_,NULL,screen,&rect);
update_rect(rect);
}
void floating_label::undraw(SDL_Surface* screen)
{
if(screen == NULL || buf_ == NULL) {
return;
}
SDL_Rect rect = {xpos_-surf_->w/2,ypos_,surf_->w,surf_->h};
const clip_rect_setter clip_setter(screen,clip_rect_);
SDL_BlitSurface(buf_,NULL,screen,&rect);
update_rect(rect);
move(xmove_,ymove_);
if(lifetime_ > 0) {
--lifetime_;
}
}
bool floating_label::expired() const { return lifetime_ == 0; }
}
namespace font {
int add_floating_label(const std::string& text, int font_size, const SDL_Color& colour,
int xpos, int ypos, int xmove, int ymove, int lifetime, const SDL_Rect& clip_rect)
{
labels.insert(std::pair<int,floating_label>(label_id++,floating_label(text,font_size,colour,xpos,ypos,xmove,ymove,lifetime,clip_rect)));
return label_id-1;
}
void move_floating_label(int handle, int xmove, int ymove)
{
const label_map::iterator i = labels.find(handle);
if(i != labels.end()) {
i->second.move(xmove,ymove);
}
}
void remove_floating_label(int handle)
{
const label_map::iterator i = labels.find(handle);
if(i != labels.end()) {
labels.erase(i);
}
}
floating_label_manager::floating_label_manager()
{
}
floating_label_manager::~floating_label_manager()
{
labels.clear();
}
floating_label_hider::floating_label_hider() : old_(hide_floating_labels)
{
hide_floating_labels = true;
}
floating_label_hider::~floating_label_hider()
{
hide_floating_labels = old_;
}
void draw_floating_labels(SDL_Surface* screen)
{
//draw the labels in reverse order, so we can clear them in-order
//to make sure the draw-undraw order is LIFO
for(label_map::reverse_iterator i = labels.rbegin(); i != labels.rend(); ++i) {
i->second.draw(screen);
}
}
void undraw_floating_labels(SDL_Surface* screen)
{
for(label_map::iterator i = labels.begin(); i != labels.end(); ) {
i->second.undraw(screen);
if(i->second.expired()) {
i = labels.erase(i);
} else {
++i;
}
}
}
}

View file

@ -70,32 +70,72 @@ SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
bool is_format_char(char c);
///
/// Determine the width of a line of text given a certain font size.
/// The font type used is the default wesnoth font type.
///
int line_width(const std::string line, int font_size);
///
/// If the text exceedes the specified max width, wrap it one a word basis.
/// If the is not possible, e.g. the word is too big to fit, wrap it on a
/// char basis.
///
std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int max_width);
///
/// Determine the width of a line of text given a certain font size.
/// The font type used is the default wesnoth font type.
///
int line_width(const std::string line, int font_size);
///
/// Draw text on the screen. This method makes sure that the text
/// fits within a given maximum width. If a line exceedes this width it
/// will be wrapped on a word basis if possible, otherwise on a char
/// basis. This method is otherwise similar to the draw_text method,
/// but it doesn't support special markup or tooltips.
///
/// @return a bounding rectangle of the text.
///
SDL_Rect draw_wrapped_text(display* gui, const SDL_Rect& area, int font_size,
///
/// If the text exceedes the specified max width, wrap it one a word basis.
/// If the is not possible, e.g. the word is too big to fit, wrap it on a
/// char basis.
///
std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int max_width);
///
/// Draw text on the screen. This method makes sure that the text
/// fits within a given maximum width. If a line exceedes this width it
/// will be wrapped on a word basis if possible, otherwise on a char
/// basis. This method is otherwise similar to the draw_text method,
/// but it doesn't support special markup or tooltips.
///
/// @return a bounding rectangle of the text.
///
SDL_Rect draw_wrapped_text(display* gui, const SDL_Rect& area, int font_size,
const SDL_Color& colour, const std::string& text,
int x, int y, int max_width, SDL_Surface* bg = NULL);
/// structure which manages floating labels. All floating labels on the screen
/// will be removed when this object is destroyed
struct floating_label_manager
{
floating_label_manager();
~floating_label_manager();
};
/// structure which will hide floating labels for its lifetime
struct floating_label_hider
{
floating_label_hider();
~floating_label_hider();
private:
bool old_;
};
/// add a label floating on the screen above everything else.
/// 'text': the text to display
/// 'font_size': the size to display the text in
/// 'colour': the colour of the text
/// 'xpos,ypos': the location on the screen to display the text.
/// 'xmove,ymove': the amount to move the text each frame
/// 'lifetime': the number of frames to display the text for, or -1 to display until removed
/// 'clip_rect': the rectangle to clip the label to.
///
/// @returns a handle to the label which can be used with other label functions
int add_floating_label(const std::string& text, int font_size, const SDL_Color& colour,
int xpos, int ypos, int xmove, int ymove, int lifetime, const SDL_Rect& clip_rect);
/// moves the floating label given by 'handle' by (xmove,ymove)
void move_floating_label(int handle, int xmove, int ymove);
/// removes the floating label given by 'handle' from the screen
void remove_floating_label(int handle);
void draw_floating_labels(SDL_Surface* screen);
void undraw_floating_labels(SDL_Surface* screen);
}
#endif

View file

@ -15,6 +15,7 @@
#include <vector>
#include "cursor.hpp"
#include "font.hpp"
#include "image.hpp"
#include "mouse.hpp"
#include "preferences.hpp"
@ -277,6 +278,7 @@ void CVideo::flip()
if(fake_screen)
return;
font::draw_floating_labels(frameBuffer);
cursor::draw(frameBuffer);
if(update_all) {
::SDL_Flip(frameBuffer);
@ -287,6 +289,7 @@ void CVideo::flip()
clear_updates();
cursor::undraw(frameBuffer);
font::undraw_floating_labels(frameBuffer);
}
void CVideo::lock()