made it so flop() works properly
This commit is contained in:
parent
fda6022ab5
commit
bd66afd324
3 changed files with 51 additions and 45 deletions
|
@ -44,6 +44,7 @@ public:
|
|||
};
|
||||
|
||||
ai_interface(info& arg) : info_(arg) {}
|
||||
virtual ~ai_interface() {}
|
||||
|
||||
virtual void play_turn() = 0;
|
||||
|
||||
|
|
|
@ -1264,8 +1264,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
|
|||
|
||||
std::vector<SDL_Surface*> overlaps;
|
||||
|
||||
scoped_sdl_surface flag(NULL);
|
||||
|
||||
update_rect(xpos,ypos,surface->w,surface->h);
|
||||
|
||||
//note that dstrect can be changed by SDL_BlitSurface and so a new instance should be
|
||||
|
@ -1274,7 +1272,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
|
|||
SDL_BlitSurface(surface,NULL,dst,&dstrect);
|
||||
|
||||
if(!is_shrouded) {
|
||||
flag.assign(getFlag(terrain,x,y));
|
||||
scoped_sdl_surface flag(getFlag(terrain,x,y));
|
||||
if(flag != NULL) {
|
||||
SDL_Rect dstrect = { xpos, ypos, 0, 0 };
|
||||
SDL_BlitSurface(flag,NULL,dst,&dstrect);
|
||||
|
@ -1555,7 +1553,7 @@ SDL_Surface* display::getFlag(gamemap::TERRAIN terrain, int x, int y)
|
|||
const gamemap::location loc(x,y);
|
||||
|
||||
for(size_t i = 0; i != teams_.size(); ++i) {
|
||||
if(teams_[i].owns_tower(loc) && (!fogged(x,y) || i == currentTeam_)) {
|
||||
if(teams_[i].owns_tower(loc) && (!fogged(x,y) || !shrouded(x,y) && !teams_[currentTeam_].is_enemy(i+1))) {
|
||||
char buf[50];
|
||||
sprintf(buf,"terrain/flag-team%d.png",i+1);
|
||||
return image::get_image(buf);
|
||||
|
@ -1790,7 +1788,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
draw_tile(a.x,a.y,image);
|
||||
}
|
||||
|
||||
Uint16 defensive_colour = 0;
|
||||
Uint32 defensive_colour = 0;
|
||||
double defensive_alpha = 1.0;
|
||||
|
||||
if(damage > 0 && i >= missile_impact) {
|
||||
|
@ -1863,37 +1861,6 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
return dead;
|
||||
}
|
||||
|
||||
void display::unit_die(const gamemap::location& loc, SDL_Surface* image)
|
||||
{
|
||||
if(update_locked() || fogged(loc.x,loc.y)
|
||||
|| preferences::show_combat() == false)
|
||||
return;
|
||||
|
||||
const unit_map::const_iterator u = units_.find(loc);
|
||||
assert(u != units_.end());
|
||||
|
||||
const std::string& die_sound = u->second.type().die_sound();
|
||||
if(die_sound != "" && die_sound != "null") {
|
||||
sound::play_sound(die_sound);
|
||||
}
|
||||
|
||||
const int frame_time = 30;
|
||||
int ticks = SDL_GetTicks();
|
||||
|
||||
for(double alpha = 1.0; alpha > 0.0; alpha -= 0.05) {
|
||||
draw_tile(loc.x,loc.y,image,alpha);
|
||||
|
||||
const int wait_time = ticks + frame_time - SDL_GetTicks();
|
||||
|
||||
if(wait_time > 0 && !turbo())
|
||||
SDL_Delay(wait_time);
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
update_display();
|
||||
}
|
||||
}
|
||||
|
||||
bool display::unit_attack(const gamemap::location& a,
|
||||
const gamemap::location& b, int damage,
|
||||
const attack_type& attack)
|
||||
|
@ -2026,7 +1993,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
draw_tile(update_tiles[j].x,update_tiles[j].y);
|
||||
}
|
||||
|
||||
int defender_colour = 0;
|
||||
Uint32 defender_colour = 0;
|
||||
double defender_alpha = 1.0;
|
||||
|
||||
if(damage > 0 && i >= 0) {
|
||||
|
@ -2088,6 +2055,37 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
return dead;
|
||||
}
|
||||
|
||||
void display::unit_die(const gamemap::location& loc, SDL_Surface* image)
|
||||
{
|
||||
if(update_locked() || fogged(loc.x,loc.y)
|
||||
|| preferences::show_combat() == false)
|
||||
return;
|
||||
|
||||
const unit_map::const_iterator u = units_.find(loc);
|
||||
assert(u != units_.end());
|
||||
|
||||
const std::string& die_sound = u->second.type().die_sound();
|
||||
if(die_sound != "" && die_sound != "null") {
|
||||
sound::play_sound(die_sound);
|
||||
}
|
||||
|
||||
const int frame_time = 30;
|
||||
int ticks = SDL_GetTicks();
|
||||
|
||||
for(double alpha = 1.0; alpha > 0.0; alpha -= 0.05) {
|
||||
draw_tile(loc.x,loc.y,image,alpha);
|
||||
|
||||
const int wait_time = ticks + frame_time - SDL_GetTicks();
|
||||
|
||||
if(wait_time > 0 && !turbo())
|
||||
SDL_Delay(wait_time);
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
update_display();
|
||||
}
|
||||
}
|
||||
|
||||
void display::move_unit_between(const gamemap::location& a,
|
||||
const gamemap::location& b,
|
||||
const unit& u)
|
||||
|
|
|
@ -464,20 +464,27 @@ SDL_Surface* flop_surface(SDL_Surface* surface)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SDL_Surface* dest = clone_surface(surface);
|
||||
scoped_sdl_surface surf(make_neutral_surface(surface));
|
||||
|
||||
if(dest == NULL) {
|
||||
std::cerr << "could not make cloned surface...\n";
|
||||
if(surf == NULL) {
|
||||
std::cerr << "could not make neutral surface...\n";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(size_t y = 0; y != surface->h; ++y) {
|
||||
SDL_Rect srcrect = {0,y,surface->w,1};
|
||||
SDL_Rect dstrect = {0,surface->h-y-1,surface->w,1};
|
||||
sdl_safe_blit(surface,&srcrect,dest,&dstrect);
|
||||
{
|
||||
surface_lock lock(surf);
|
||||
Uint32* const pixels = lock.pixels();
|
||||
|
||||
for(size_t x = 0; x != surf->w; ++x) {
|
||||
for(size_t y = 0; y != surf->h/2; ++y) {
|
||||
const size_t index1 = y*surf->w + x;
|
||||
const size_t index2 = (surf->h-y-1)*surf->w + x;
|
||||
std::swap(pixels[index1],pixels[index2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
return clone_surface(surf);
|
||||
}
|
||||
|
||||
SDL_Surface* get_surface_portion(SDL_Surface* src, SDL_Rect& area)
|
||||
|
|
Loading…
Add table
Reference in a new issue