added fading effects between days

This commit is contained in:
Dave White 2004-03-25 17:40:47 +00:00
parent e5d8a9a845
commit 24f8e87217
9 changed files with 97 additions and 30 deletions

View file

@ -147,12 +147,14 @@ road_windiness=3
[village]
terrain=d
convert_to=v
chance=50
[/village]
#villages in forest are Elvish
[village]
terrain=f
convert_to=t
chance=75
[/village]
[village]
terrain=h
@ -161,31 +163,35 @@ road_windiness=3
[village]
terrain=m
convert_to=v
chance=60
[/village]
#villages in snow
[village]
terrain=S
convert_to=V
chance=75
[/village]
[village]
terrain=F
convert_to=V
chance=75
[/village]
#swamp villages
[village]
terrain=w
convert_to=Y
#chance=25
chance=25
[/village]
#mermen villages
#[village]
#terrain=c
#convert_to=Z
#[/village]
#mermen villages - give them low chance of appearing
[village]
terrain=c
convert_to=Z
chance=10
[/village]
[castle]
valid_terrain=g,f,h

View file

@ -3,8 +3,8 @@
id=dawn
name=Dawn
image=Dawn.png
red=-10
green=-10
red=-20
green=-20
[/time]
[illuminated_time]
id=morning
@ -49,8 +49,8 @@ lawful_bonus=25
id=dusk
name=Dusk
image=Dusk.png
green=-15
blue=-15
green=-30
blue=-30
[/time]
[illuminated_time]
id=afternoon
@ -66,8 +66,8 @@ id=first_watch
name=First Watch
image=FirstWatch.png
lawful_bonus=-25
red=-20
green=-20
red=-40
green=-40
blue=10
[/time]
[illuminated_time]
@ -85,8 +85,8 @@ id=second_watch
name=Second Watch
image=SecondWatch.png
lawful_bonus=-25
red=-20
green=-20
red=-40
green=-40
blue=10
[/time]
[illuminated_time]

View file

@ -503,6 +503,8 @@ swamp water="Swamp"
human village="Village"
underground village="Village"
snow village="Village"
swamp village="Village"
mermen village="Village"
tundra="Tundra"
road="Road"
dirt="Dirt"

View file

@ -60,7 +60,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
currentTeam_(0), activeTeam_(0), hideEnergy_(false),
deadAmount_(0.0), advancingAmount_(0.0), updatesLocked_(0),
turbo_(false), grid_(false), sidebarScaling_(1.0),
theme_(theme_cfg,screen_area())
theme_(theme_cfg,screen_area()), firstTurn_(true)
{
if(non_interactive())
updatesLocked_++;
@ -115,6 +115,31 @@ Uint32 display::rgb(Uint8 red, Uint8 green, Uint8 blue)
void display::new_turn()
{
int r,g,b;
image::get_colour_adjustment(&r,&g,&b);
const time_of_day& tod = status_.get_time_of_day();
const int red = tod.red - r;
const int green = tod.green - g;
const int blue = tod.blue - b;
const int niterations = firstTurn_ || (!red && !green && !blue) ? 0 : 10;
firstTurn_ = false;
const int frame_time = 30;
const int starting_ticks = SDL_GetTicks();
for(int i = 0; i != niterations; ++i) {
image::set_colour_adjustment(r+(i*red)/niterations,g+(i*green)/niterations,b+(i*blue)/niterations);
invalidate_all();
draw();
const int cur_ticks = SDL_GetTicks();
const int wanted_ticks = starting_ticks + i*frame_time;
if(cur_ticks < wanted_ticks) {
SDL_Delay(wanted_ticks - cur_ticks);
}
}
adjust_colours(0,0,0);
}
@ -383,7 +408,9 @@ void display::bounds_check_position()
zoom_ = max_zoom;
}
const double xend = zoom_*map_.x()*0.75 + zoom_*0.25;
const int tile_width = static_cast<int>(static_cast<int>(zoom_)*0.75) + 1;
const double xend = tile_width*map_.x();
const double yend = zoom_*map_.y() + zoom_/2.0;
if(xpos_ + static_cast<double>(map_area().w) > xend)
@ -1289,15 +1316,13 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
image_type = image::BRIGHTENED;
}
const scoped_sdl_surface surface(getTerrain(terrain,image_type,x,y));
scoped_sdl_surface surface(getTerrain(terrain,image_type,x,y));
if(surface == NULL) {
std::cerr << "Could not get terrain surface\n";
return;
}
std::vector<SDL_Surface*> overlaps;
update_rect(xpos,ypos,surface->w,surface->h);
//note that dstrect can be changed by SDL_BlitSurface and so a new instance should be
@ -1319,14 +1344,12 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
for(std::pair<Itor,Itor> overlays = overlays_.equal_range(loc);
overlays.first != overlays.second; ++overlays.first) {
//even though the scoped surface will fall out-of-scope and call
//SDL_FreeSurface() on the underlying surface, the surface will remain
//valid so long as the image cache isn't invalidated, which should not
//happen inside this function
const scoped_sdl_surface overlay_surface(image::get_image(overlays.first->second));
SDL_Rect dstrect = { xpos, ypos, 0, 0 };
SDL_BlitSurface(overlay_surface,NULL,dst,&dstrect);
scoped_sdl_surface overlay_surface(image::get_image(overlays.first->second));
if(overlay_surface != NULL) {
SDL_Rect dstrect = { xpos, ypos, 0, 0 };
SDL_BlitSurface(overlay_surface,NULL,dst,&dstrect);
}
}
}

View file

@ -402,6 +402,8 @@ private:
void create_buttons();
std::vector<gui::button> buttons_;
bool firstTurn_;
//for debug mode
static std::map<gamemap::location,double> debugHighlights_;
};

View file

@ -111,6 +111,21 @@ void set_colour_adjustment(int r, int g, int b)
}
}
void get_colour_adjustment(int *r, int *g, int *b)
{
if(r != NULL) {
*r = red_adjust;
}
if(g != NULL) {
*g = green_adjust;
}
if(b != NULL) {
*b = blue_adjust;
}
}
void set_zoom(double amount)
{
if(amount != zoom) {

View file

@ -41,6 +41,9 @@ namespace image {
//for representing day/night. Invalidates all scaled images.
void set_colour_adjustment(int r, int g, int b);
//function to get back the current colour adjustment values
void get_colour_adjustment(int *r, int *g, int *b);
//sets the pixel format used by the images. Is called every time the
//video mode changes. Invalidates all images.
void set_pixel_format(SDL_PixelFormat* format);

View file

@ -456,6 +456,11 @@ std::string default_generate_map(size_t width, size_t height,
size_t max_lakes, size_t nvillages, size_t nplayers,
const config& cfg)
{
//odd widths are nasty, so make them even
if(is_odd(width)) {
++width;
}
//find out what the 'flatland' on this map is. i.e. grassland.
std::string flatland = cfg["default_flatland"];
if(flatland == "") {
@ -689,15 +694,26 @@ std::string default_generate_map(size_t width, size_t height,
//[village] tag is found for the terrain type (e.g. deep water) no village
//will be placed.
std::set<location> villages;
for(size_t village = 0; village != nvillages; ++village) {
size_t village = 0, village_tries = 0;
while(village != nvillages && village_tries != nvillages*3) {
++village_tries;
const int x = rand()%width/3+width/3;
const int y = rand()%height/3+height/3;
const std::string str(1,terrain[x][y]);
const config* const child = cfg.find_child("village","terrain",str);
if(child != NULL) {
if((*child)["chance"] != "" && (rand()%100) >= atoi((*child)["chance"].c_str())) {
continue;
}
const std::string& convert_to = (*child)["convert_to"];
if(convert_to.empty() == false)
if(convert_to.empty() == false) {
terrain[x][y] = convert_to[0];
villages.insert(gamemap::location(x,y));
++village;
}
}
}

View file

@ -241,7 +241,7 @@ std::string default_map_generator::name() const { return "default"; }
std::string default_map_generator::create_map(const std::vector<std::string>& args)
{
if(cfg_ != NULL)
return default_generate_map(width_,height_,iterations_,hill_size_,max_lakes_,nvillages_*width_*height_/1000,nplayers_,*cfg_);
return default_generate_map(width_,height_,iterations_,hill_size_,max_lakes_,(nvillages_*width_*height_)/1000,nplayers_,*cfg_);
else
return "";
}