added support for different images when a unit is moving

This commit is contained in:
Dave White 2004-05-25 14:48:14 +00:00
parent fee5840ce2
commit d0873ea1b8
8 changed files with 71 additions and 27 deletions

View file

@ -230,6 +230,8 @@ Any units adjacent to this unit will fight as if it were dusk when it is night,
skirmisher_description="Skirmisher:
This unit is skilled in moving past enemies quickly, and ignores all Enemy Zones of Control."
loyal_description="Never more than 1 upkeep"
no_leader_to_recruit="You don't have a leader to recruit with."
leader_not_on_start="You must have your leader on a keep to recruit or recall units."
no_recruit_location="There are no vacant castle tiles in which to recruit a unit."
@ -416,6 +418,8 @@ xp="XP"
moves="Moves"
location="Location"
level="level"
dmg="Dmg"
nattacks="strikes"
message="Message"
describe_unit="Describe Unit"

View file

@ -470,8 +470,6 @@ void ai::do_move()
{
log_scope("doing ai move");
game_config::debug = true;
invalidate_defensive_position_cache();
user_interact();

View file

@ -210,7 +210,7 @@ void read_game_cfg(preproc_map& defines, std::vector<line_source>& line_src, con
{
log_scope("read_game_cfg");
if(defines.size() < 4 && use_cache) {
if(defines.size() < 4) {
bool is_valid = true;
std::stringstream str;
for(preproc_map::const_iterator i = defines.begin(); i != defines.end(); ++i) {
@ -226,7 +226,7 @@ void read_game_cfg(preproc_map& defines, std::vector<line_source>& line_src, con
const std::string& cache = get_cache_dir();
if(cache != "") {
const std::string fname = cache + "/game.cfg-cache" + str.str();
if(file_exists(fname) && file_create_time(fname) > data_tree_modified_time()) {
if(use_cache && file_exists(fname) && file_create_time(fname) > data_tree_modified_time()) {
std::cerr << "found valid cache at '" << fname << "' using it\n";
log_scope("read cache");
compression_schema schema;

View file

@ -503,9 +503,11 @@ int show_dialog(display& disp, SDL_Surface* image,
const std::string& title = image == NULL ? caption : "";
draw_dialog(xloc,yloc,total_width,total_height,disp,title,dialog_style,&buttons_ptr,&restorer);
if(menu_.height() > 0)
menu_.set_loc(xloc+total_image_width+left_padding+image_h_padding,
yloc+top_padding+text_size.h+menu_hpadding);
const int menu_xpos = xloc+total_image_width+left_padding+image_h_padding;
const int menu_ypos = yloc+top_padding+text_size.h+menu_hpadding;
if(menu_.height() > 0) {
menu_.set_loc(menu_xpos,menu_ypos);
}
if(image != NULL) {
const int x = xloc + left_padding;
@ -673,7 +675,8 @@ int show_dialog(display& disp, SDL_Surface* image,
events::raise_process_event();
events::raise_draw_event();
if(buttons.empty() && (new_left_button && !left_button ||
const SDL_Rect menu_rect = {menu_xpos,menu_ypos,menu_.width(),menu_.height()};
if(buttons.empty() && (new_left_button && !left_button && !point_in_rect(mousex,mousey,menu_rect) ||
new_right_button && !right_button) ||
buttons.size() < 2 && new_key_down && !key_down &&
menu_.height() == 0)

View file

@ -891,9 +891,22 @@ void unit::add_modification(const std::string& type,
if(apply_to == "new_attack") {
attacks_.push_back(attack_type(**i.first));
} else if(apply_to == "attack") {
bool first_attack = true;
for(std::vector<attack_type>::iterator a = attacks_.begin();
a != attacks_.end(); ++a) {
a->apply_modification(**i.first);
std::string desc;
const bool affected = a->apply_modification(**i.first,&desc);
if(affected && desc != "") {
if(first_attack) {
first_attack = false;
} else {
description << "; ";
}
description << translate_string(a->name()) << " " << desc;
}
}
} else if(apply_to == "hitpoints") {
std::cerr << "applying hitpoint mod...." << hitpoints_ << "/" << maxHitpoints_ << "\n";
@ -977,7 +990,6 @@ void unit::add_modification(const std::string& type,
maxExperience_ = 1;
}
} else if(apply_to == "loyal") {
description << string_table["loyal_description"];
if(upkeep_ > UPKEEP_LOYAL)
upkeep_ = UPKEEP_LOYAL;
} else if(apply_to == "status") {

View file

@ -47,13 +47,13 @@ void move_unit_between(display& disp, const gamemap& map, const gamemap::locatio
for(int i = 0; i < nsteps; ++i) {
events::pump();
scoped_sdl_surface image(image::get_image(u.type().image()));
scoped_sdl_surface image(image::get_image(u.type().image_moving()));
if(!face_left) {
image.assign(image::reverse_image(image));
}
if(image == NULL) {
std::cerr << "failed to get image " << u.type().image() << "\n";
std::cerr << "failed to get image " << u.type().image_moving() << "\n";
return;
}

View file

@ -217,18 +217,19 @@ bool attack_type::matches_filter(const config& cfg) const
return true;
}
void attack_type::apply_modification(const config& cfg)
bool attack_type::apply_modification(const config& cfg, std::string* description)
{
if(!matches_filter(cfg))
return;
return false;
const std::string& set_name = cfg["set_name"];
const std::string& set_type = cfg["set_type"];
const std::string& set_special = cfg["set_special"];
const std::string& increase_damage = cfg["increase_damage"];
const std::string& multiply_damage = cfg["multiply_damage"];
const std::string& increase_attacks = cfg["increase_attacks"];
std::stringstream desc;
if(set_name.empty() == false) {
name_ = set_name;
}
@ -242,18 +243,23 @@ void attack_type::apply_modification(const config& cfg)
}
if(increase_damage.empty() == false) {
const int increase = atoi(increase_damage.c_str());
damage_ += increase;
if(damage_ < 1)
damage_ = 1;
}
int increase = 0;
if(increase_damage[increase_damage.size()-1] == '%') {
const std::string inc(increase_damage.begin(),increase_damage.end()-1);
const int percent = atoi(inc.c_str());
increase = (damage_*percent)/100;
} else {
increase = atoi(increase_damage.c_str());
}
if(multiply_damage.empty() == false) {
const double multiply = atof(increase_damage.c_str());
if(multiply != 0.0) {
damage_ = int(double(damage_)*multiply);
if(damage_ < 1)
damage_ = 1;
damage_ += increase;
if(damage_ < 1) {
damage_ = 1;
}
if(description != NULL) {
desc << (increase_damage[0] == '-' ? "" : "+") << increase_damage << translate_string("dmg");
}
}
@ -263,7 +269,17 @@ void attack_type::apply_modification(const config& cfg)
if(num_attacks_ < 1) {
num_attacks_ = 1;
}
if(description != NULL) {
desc << (increase > 0 ? "+" : "") << increase << translate_string("strikes");
}
}
if(description != NULL) {
*description = desc.str();
}
return true;
}
unit_movement_type::unit_movement_type(const config& cfg, const unit_movement_type* parent)
@ -559,6 +575,16 @@ const std::string& unit_type::image() const
return cfg_["image"];
}
const std::string& unit_type::image_moving() const
{
const std::string& res = cfg_["image_moving"];
if(res.empty()) {
return image();
} else {
return res;
}
}
const std::string& unit_type::image_fighting(attack_type::RANGE range) const
{
static const std::string short_range("image_short");

View file

@ -63,7 +63,7 @@ public:
const std::vector<sfx>& sound_effects() const;
bool matches_filter(const config& cfg) const;
void apply_modification(const config& cfg);
bool apply_modification(const config& cfg,std::string* description);
private:
std::string name_;
std::string type_;
@ -155,6 +155,7 @@ public:
std::string id() const;
const std::string& name() const;
const std::string& image() const;
const std::string& image_moving() const;
const std::string& image_profile() const;
const std::string& image_fighting(attack_type::RANGE range) const;
const std::string& image_defensive(attack_type::RANGE range) const;