made game parameters work
This commit is contained in:
parent
5ffd0739eb
commit
8731cb810b
5 changed files with 139 additions and 111 deletions
BIN
images/terrain/flag.png
Normal file
BIN
images/terrain/flag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
|
@ -1505,63 +1505,8 @@ void display::blit_surface(int x, int y, SDL_Surface* surface)
|
|||
|
||||
SDL_Surface* display::getMinimap(int w, int h)
|
||||
{
|
||||
if(minimap_ == NULL) {
|
||||
const int scale = 4;
|
||||
SDL_Surface* const surface = screen_.getSurface();
|
||||
|
||||
minimap_ = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
map_.x()*scale,map_.y()*scale,
|
||||
surface->format->BitsPerPixel,
|
||||
surface->format->Rmask,
|
||||
surface->format->Gmask,
|
||||
surface->format->Bmask,
|
||||
surface->format->Amask);
|
||||
if(minimap_ == NULL)
|
||||
return NULL;
|
||||
|
||||
typedef std::map<gamemap::TERRAIN,SDL_Surface*> cache_map;
|
||||
cache_map cache;
|
||||
|
||||
SDL_Rect minirect = {0,0,scale,scale};
|
||||
for(int y = 0; y != map_.y(); ++y) {
|
||||
for(int x = 0; x != map_.x(); ++x) {
|
||||
const bool shrouded = team_valid() &&
|
||||
teams_[currentTeam_].shrouded(x,y);
|
||||
if(map_.on_board(gamemap::location(x,y)) && !shrouded) {
|
||||
const gamemap::TERRAIN terrain = map_[x][y];
|
||||
cache_map::iterator i = cache.find(terrain);
|
||||
|
||||
if(i == cache.end()) {
|
||||
SDL_Surface* const tile = getTerrain(terrain,
|
||||
image::UNSCALED,x,y);
|
||||
if(tile == NULL) {
|
||||
std::cerr << "Could not get image for terrrain '"
|
||||
<< terrain << "'\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_Surface* const minitile = scale_surface(tile,scale,
|
||||
scale);
|
||||
i = cache.insert(
|
||||
cache_map::value_type(terrain,minitile)).first;
|
||||
}
|
||||
|
||||
assert(i != cache.end());
|
||||
|
||||
SDL_Rect maprect = {x*scale,y*scale,0,0};
|
||||
SDL_BlitSurface(i->second, &minirect, minimap_, &maprect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear_surfaces(cache);
|
||||
}
|
||||
|
||||
if(minimap_->w != w || minimap_->h != h) {
|
||||
SDL_Surface* const surf = minimap_;
|
||||
minimap_ = scale_surface(surf,w,h);
|
||||
SDL_FreeSurface(surf);
|
||||
}
|
||||
if(minimap_ == NULL)
|
||||
minimap_ = image::getMinimap(w,h,map_,team_valid() ? &teams_[currentTeam_] : NULL);
|
||||
|
||||
return minimap_;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "image.hpp"
|
||||
#include "display.hpp"
|
||||
#include "sdl_utils.hpp"
|
||||
#include "team.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include "SDL_image.h"
|
||||
|
@ -21,10 +22,11 @@ SDL_PixelFormat* pixel_format = NULL;
|
|||
|
||||
double zoom = 70.0;
|
||||
|
||||
void clear_surfaces(image_map& surfaces)
|
||||
//we have to go through all this trickery on clear_surfaces because
|
||||
//some compilers don't support 'typename type::iterator'
|
||||
template<typename Map,typename FwIt>
|
||||
void clear_surfaces_internal(Map& surfaces, FwIt beg, FwIt end)
|
||||
{
|
||||
image_map::iterator beg = surfaces.begin();
|
||||
const image_map::iterator end = surfaces.end();
|
||||
for(; beg != end; ++beg) {
|
||||
SDL_FreeSurface(beg->second);
|
||||
}
|
||||
|
@ -32,6 +34,12 @@ void clear_surfaces(image_map& surfaces)
|
|||
surfaces.clear();
|
||||
}
|
||||
|
||||
template<typename Map>
|
||||
void clear_surfaces(Map& surfaces)
|
||||
{
|
||||
clear_surfaces_internal(surfaces,surfaces.begin(),surfaces.end());
|
||||
}
|
||||
|
||||
enum TINT { GREY_IMAGE, BRIGHTEN_IMAGE };
|
||||
|
||||
SDL_Surface* get_tinted(const std::string& filename, TINT tint)
|
||||
|
@ -252,17 +260,77 @@ SDL_Surface* get_image_dim(const std::string& filename, size_t x, size_t y)
|
|||
return surf;
|
||||
}
|
||||
|
||||
SDL_Surface* getMinimap(CVideo& video, int w, int h, gamemap& map_)
|
||||
SDL_Surface* getMinimap(int w, int h, const gamemap& map, const team* tm)
|
||||
{
|
||||
SDL_Surface* const surface = video.getSurface();
|
||||
SDL_Surface* minimap = NULL;
|
||||
if(minimap == NULL) {
|
||||
const int scale = 4;
|
||||
|
||||
minimap = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
map.x()*scale,map.y()*scale,
|
||||
pixel_format->BitsPerPixel,
|
||||
pixel_format->Rmask,
|
||||
pixel_format->Gmask,
|
||||
pixel_format->Bmask,
|
||||
pixel_format->Amask);
|
||||
if(minimap == NULL)
|
||||
return NULL;
|
||||
|
||||
typedef std::map<gamemap::TERRAIN,SDL_Surface*> cache_map;
|
||||
cache_map cache;
|
||||
|
||||
SDL_Rect minirect = {0,0,scale,scale};
|
||||
for(int y = 0; y != map.y(); ++y) {
|
||||
for(int x = 0; x != map.x(); ++x) {
|
||||
const bool shrouded = tm != NULL && tm->shrouded(x,y);
|
||||
if(map.on_board(gamemap::location(x,y)) && !shrouded) {
|
||||
const gamemap::TERRAIN terrain = map[x][y];
|
||||
cache_map::iterator i = cache.find(terrain);
|
||||
|
||||
if(i == cache.end()) {
|
||||
SDL_Surface* const tile =
|
||||
get_image("terrain/" + map.get_terrain_info(terrain).default_image() + ".png");
|
||||
|
||||
if(tile == NULL) {
|
||||
std::cerr << "Could not get image for terrrain '"
|
||||
<< terrain << "'\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_Surface* const minitile = scale_surface(tile,scale,scale);
|
||||
i = cache.insert(cache_map::value_type(terrain,minitile)).first;
|
||||
}
|
||||
|
||||
assert(i != cache.end());
|
||||
|
||||
SDL_Rect maprect = {x*scale,y*scale,0,0};
|
||||
SDL_BlitSurface(i->second, &minirect, minimap, &maprect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear_surfaces(cache);
|
||||
}
|
||||
|
||||
if(minimap->w != w || minimap->h != h) {
|
||||
SDL_Surface* const surf = minimap;
|
||||
minimap = scale_surface(surf,w,h);
|
||||
SDL_FreeSurface(surf);
|
||||
}
|
||||
|
||||
return minimap;
|
||||
|
||||
/*
|
||||
if(pixel_format == NULL)
|
||||
return NULL;
|
||||
|
||||
SDL_Surface *minimap_ = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
map_.x(),map_.y(),
|
||||
surface->format->BitsPerPixel,
|
||||
surface->format->Rmask,
|
||||
surface->format->Gmask,
|
||||
surface->format->Bmask,
|
||||
surface->format->Amask);
|
||||
pixel_format->BitsPerPixel,
|
||||
pixel_format->Rmask,
|
||||
pixel_format->Gmask,
|
||||
pixel_format->Bmask,
|
||||
pixel_format->Amask);
|
||||
if(minimap_ == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -274,7 +342,7 @@ SDL_Surface* getMinimap(CVideo& video, int w, int h, gamemap& map_)
|
|||
for(int x = 0; x != map_.x(); ++x) {
|
||||
|
||||
*data = map_.get_terrain_info(map_[x][y]).get_rgb().
|
||||
format(surface->format);
|
||||
format(pixel_format);
|
||||
++data;
|
||||
}
|
||||
data += xpad;
|
||||
|
@ -287,7 +355,7 @@ SDL_Surface* getMinimap(CVideo& video, int w, int h, gamemap& map_)
|
|||
}
|
||||
|
||||
return minimap_;
|
||||
}
|
||||
*/}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef IMAGE_HPP_INCLUDED
|
||||
#define IMAGE_HPP_INCLUDED
|
||||
|
||||
#include "video.hpp"
|
||||
#include "map.hpp"
|
||||
|
||||
#include "SDL.h"
|
||||
#include <string>
|
||||
|
||||
class team;
|
||||
|
||||
//this module manages the cache of images. With an image name, you can get
|
||||
//the surface corresponding to that image, and don't need to free the image.
|
||||
//Note that surfaces returned from here are invalidated whenever events::pump()
|
||||
|
@ -52,7 +53,7 @@ namespace image {
|
|||
//have the dimensions specified here.
|
||||
SDL_Surface* get_image_dim(const std::string& filename, size_t x, size_t y);
|
||||
|
||||
SDL_Surface* getMinimap(CVideo& video, int w, int h, gamemap& map_);
|
||||
SDL_Surface* getMinimap(int w, int h, const gamemap& map_, const team* tm=NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -316,6 +316,7 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
"Turns: 50",rect.x,rect.y);
|
||||
rect.y = (disp.y()-height)/2+100;
|
||||
rect.h = name_entry.width();
|
||||
|
||||
gui::slider turns_slider(disp,rect,0.38);
|
||||
|
||||
//Village Gold
|
||||
|
@ -330,9 +331,9 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
rect.h = name_entry.width();
|
||||
gui::slider villagegold_slider(disp,rect,0.1);
|
||||
|
||||
//FOG fo war
|
||||
//FOG of war
|
||||
gui::button fog_game(disp,"Fog Of War",gui::button::TYPE_CHECK);
|
||||
fog_game.set_check(true);
|
||||
fog_game.set_check(false);
|
||||
fog_game.set_xy(rect.x+6,rect.y+30);
|
||||
fog_game.draw();
|
||||
|
||||
|
@ -348,7 +349,6 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
launch_game.set_xy((disp.x()/2)-launch_game.width()*2-19,(disp.y()-height)/2+height-29);
|
||||
cancel_game.set_xy((disp.x()/2)+cancel_game.width()+19,(disp.y()-height)/2+height-29);
|
||||
|
||||
|
||||
update_whole_screen();
|
||||
|
||||
CKey key;
|
||||
|
@ -367,6 +367,7 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
if(launch_game.process(mousex,mousey,left_button)) {
|
||||
if(name_entry.text().empty() == false) {
|
||||
|
||||
// Send Initial information
|
||||
config response;
|
||||
config create_game;
|
||||
|
@ -382,6 +383,7 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
if(res == -1)
|
||||
break;
|
||||
|
||||
//if we're loading a saved game
|
||||
config loaded_level;
|
||||
if(size_t(res) == options.size()-1) {
|
||||
const std::vector<std::string>& games = get_saves_list();
|
||||
|
@ -432,8 +434,13 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
level_ptr->children["replay"].clear();
|
||||
level_ptr->add_child("replay") = state.replay_data;
|
||||
|
||||
} else {
|
||||
} else { //creating a new game
|
||||
level_ptr = levels[res];
|
||||
|
||||
//set the number of turns here
|
||||
std::stringstream turns;
|
||||
turns << new_turns;
|
||||
(*level_ptr)["turns"] = turns.str();
|
||||
}
|
||||
|
||||
assert(level_ptr != NULL);
|
||||
|
@ -449,23 +456,34 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
std::cerr << "no multiplayer sides found\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
for(std::vector<config*>::iterator sd = sides.begin();
|
||||
sd != sides.end(); ++sd) {
|
||||
if((*sd)->values["name"].empty())
|
||||
(*sd)->values["name"] = possible_sides.front()->values["name"];
|
||||
if((*sd)->values["type"].empty())
|
||||
(*sd)->values["type"] = possible_sides.front()->values["type"];
|
||||
if((*sd)->values["recruit"].empty())
|
||||
(*sd)->values["recruit"]=possible_sides.front()->values["recruit"];
|
||||
if((*sd)->values["music"].empty())
|
||||
(*sd)->values["music"]=possible_sides.front()->values["music"];
|
||||
if((*sd)->values["recruitment_pattern"].empty())
|
||||
(*sd)->values["recruitment_pattern"] =
|
||||
|
||||
if((**sd)["fog"].empty())
|
||||
(**sd)["fog"] = fog_game.checked() ? "yes" : "no";
|
||||
|
||||
if((**sd)["shroud"].empty())
|
||||
(**sd)["shroud"] = shroud_game.checked() ? "yes" : "no";
|
||||
|
||||
if((**sd)["name"].empty())
|
||||
(**sd)["name"] = possible_sides.front()->values["name"];
|
||||
|
||||
if((**sd)["type"].empty())
|
||||
(**sd)["type"] = possible_sides.front()->values["type"];
|
||||
|
||||
if((**sd)["recruit"].empty())
|
||||
(**sd)["recruit"]=possible_sides.front()->values["recruit"];
|
||||
|
||||
if((**sd)["music"].empty())
|
||||
(**sd)["music"] = possible_sides.front()->values["music"];
|
||||
|
||||
if((**sd)["recruitment_pattern"].empty())
|
||||
(**sd)["recruitment_pattern"] =
|
||||
possible_sides.front()->values["recruitment_pattern"];
|
||||
|
||||
if((*sd)->values["description"].empty())
|
||||
(*sd)->values["description"] = preferences::login();
|
||||
if((**sd)["description"].empty())
|
||||
(**sd)["description"] = preferences::login();
|
||||
}
|
||||
|
||||
res = 0;
|
||||
|
@ -596,26 +614,20 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
}
|
||||
}
|
||||
|
||||
if(fog_game.process(mousex,mousey,left_button))
|
||||
{
|
||||
}
|
||||
|
||||
if(shroud_game.process(mousex,mousey,left_button))
|
||||
{
|
||||
}
|
||||
|
||||
fog_game.process(mousex,mousey,left_button);
|
||||
shroud_game.process(mousex,mousey,left_button);
|
||||
name_entry.process();
|
||||
|
||||
//Game turns are 20 to 99
|
||||
//FIXME: Should never be a - number, but it is sometimes
|
||||
int check_turns=20+(int)(79*turns_slider.process(mousex,mousey,left_button));
|
||||
int check_turns=20+int(79*turns_slider.process(mousex,mousey,left_button));
|
||||
if(abs(check_turns) == check_turns)
|
||||
new_turns=check_turns;
|
||||
if(new_turns != cur_turns) {
|
||||
cur_turns = new_turns;
|
||||
rect.x = (disp.x()-width)/2+(int)(width*0.4)+maps_menu.width()+19;
|
||||
rect.x = (disp.x()-width)/2+int(width*0.4)+maps_menu.width()+19;
|
||||
rect.y = (disp.y()-height)/2+83;
|
||||
rect.w = ((disp.x()-width)/2+width)-((disp.x()-width)/2+(int)(width*0.4)+maps_menu.width()+19)-10;
|
||||
rect.w = ((disp.x()-width)/2+width)-((disp.x()-width)/2+int(width*0.4)+maps_menu.width()+19)-10;
|
||||
rect.h = 12;
|
||||
SDL_BlitSurface(village_bg, NULL, disp.video().getSurface(), &rect);
|
||||
sprintf(buf,"Turns: %d", cur_turns);
|
||||
|
@ -626,14 +638,14 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
//Villages can produce between 1 and 10 gold a turn
|
||||
//FIXME: Should never be a - number, but it is sometimes
|
||||
int check_villagegold=1+(int)(9*villagegold_slider.process(mousex,mousey,left_button));
|
||||
int check_villagegold=1+int(9*villagegold_slider.process(mousex,mousey,left_button));
|
||||
if(abs(check_villagegold) == check_villagegold)
|
||||
new_villagegold=check_villagegold;
|
||||
if(new_villagegold != cur_villagegold) {
|
||||
cur_villagegold = new_villagegold;
|
||||
rect.x = (disp.x()-width)/2+(int)(width*0.4)+maps_menu.width()+19;
|
||||
rect.x = (disp.x()-width)/2+int(width*0.4)+maps_menu.width()+19;
|
||||
rect.y = (disp.y()-height)/2+130;
|
||||
rect.w = ((disp.x()-width)/2+width)-((disp.x()-width)/2+(int)(width*0.4)+maps_menu.width()+19)-10;
|
||||
rect.w = ((disp.x()-width)/2+width)-((disp.x()-width)/2+int(width*0.4)+maps_menu.width()+19)-10;
|
||||
rect.h = 12;
|
||||
SDL_BlitSurface(village_bg, NULL, disp.video().getSurface(), &rect);
|
||||
sprintf(buf,"Village Gold: %d", cur_villagegold);
|
||||
|
@ -649,15 +661,17 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
gamemap map(cfg,read_file("data/maps/" + level_ptr->values["map"]));
|
||||
|
||||
SDL_Surface *mini = image::getMinimap(disp.video(),
|
||||
175,175, map);
|
||||
rect.x = ((disp.x()-width)/2+10)+20;
|
||||
rect.y = (disp.y()-height)/2+80;
|
||||
rect.w = 175;
|
||||
rect.h = 175;
|
||||
SDL_BlitSurface(mini, NULL, disp.video().getSurface(), &rect);
|
||||
SDL_FreeSurface(mini);
|
||||
update_rect(rect);
|
||||
SDL_Surface* const mini = image::getMinimap(175,175,map);
|
||||
|
||||
if(mini != NULL) {
|
||||
rect.x = ((disp.x()-width)/2+10)+20;
|
||||
rect.y = (disp.y()-height)/2+80;
|
||||
rect.w = 175;
|
||||
rect.h = 175;
|
||||
SDL_BlitSurface(mini, NULL, disp.video().getSurface(), &rect);
|
||||
SDL_FreeSurface(mini);
|
||||
update_rect(rect);
|
||||
}
|
||||
}else{
|
||||
//TODO: Load some other non-minimap
|
||||
// image, ie a floppy disk
|
||||
|
|
Loading…
Add table
Reference in a new issue