fix ability defaults for affecting other sides

This commit is contained in:
Dominic Bolin 2006-05-01 14:03:44 +00:00
parent 248aa20d5f
commit 2168f1c1a8
2 changed files with 197 additions and 189 deletions

View File

@ -1,41 +1,41 @@
/*
/*
Copyright (C) 2005 by Joeri Melis <joeri_melis@hotmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "loadscreen.hpp"
#include "font.hpp"
#include "marked-up_text.hpp"
#include <iostream>
#define MIN_PERCENTAGE 0
#define MAX_PERCENTAGE 100
void loadscreen::set_progress(const int percentage, const std::string &text, const bool commit)
{
/* Saturate percentage. */
prcnt_ = percentage < MIN_PERCENTAGE ? MIN_PERCENTAGE: percentage > MAX_PERCENTAGE ? MAX_PERCENTAGE: percentage;
/* Set progress bar parameters. */
int fcr = 103, fcg = 11, fcb = 10; /* Finished piece. */
int lcr = 24, lcg = 22, lcb = 21; /* Leftover piece. */
int bcr = 188, bcg = 176, bcb = 136; /* Border color. */
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "loadscreen.hpp"
#include "font.hpp"
#include "marked-up_text.hpp"
#include <iostream>
#define MIN_PERCENTAGE 0
#define MAX_PERCENTAGE 100
void loadscreen::set_progress(const int percentage, const std::string &text, const bool commit)
{
/* Saturate percentage. */
prcnt_ = percentage < MIN_PERCENTAGE ? MIN_PERCENTAGE: percentage > MAX_PERCENTAGE ? MAX_PERCENTAGE: percentage;
/* Set progress bar parameters. */
int fcr = 103, fcg = 11, fcb = 10; /* Finished piece. */
int lcr = 24, lcg = 22, lcb = 21; /* Leftover piece. */
int bcr = 188, bcg = 176, bcb = 136; /* Border color. */
int bw = 1; /* Border width. */
int bispw = 1; /* Border inner spacing width. */
bw = 2*(bw+bispw) > screen_.getx() ? 0: 2*(bw+bispw) > screen_.gety() ? 0: bw;
int scrx = screen_.getx() - 2*(bw+bispw); /* Available width. */
int scry = screen_.gety() - 2*(bw+bispw); /* Available height. */
int pbw = scrx/2; /* Used width. */
int pbh = scry/16; /* Used heigth. */
surface const gdis = screen_.getSurface();
int bispw = 1; /* Border inner spacing width. */
bw = 2*(bw+bispw) > screen_.getx() ? 0: 2*(bw+bispw) > screen_.gety() ? 0: bw;
int scrx = screen_.getx() - 2*(bw+bispw); /* Available width. */
int scry = screen_.gety() - 2*(bw+bispw); /* Available height. */
int pbw = scrx/2; /* Used width. */
int pbh = scry/16; /* Used heigth. */
surface const gdis = screen_.getSurface();
SDL_Rect area;
/* Draw logo if it was succesfully loaded. */
if (logo_surface_ && !logo_drawn_) {
@ -55,148 +55,148 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
}
int pbx = (scrx - pbw)/2; /* Horizontal location. */
int pby = (scry - pbh)/2 + pby_offset_; /* Vertical location. */
/* Draw top border. */
area.x = pbx; area.y = pby;
area.w = pbw + 2*(bw+bispw); area.h = bw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw bottom border. */
area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
area.w = pbw + 2*(bw+bispw); area.h = bw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw left border. */
area.x = pbx; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw right border. */
area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw the finished bar area. */
area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
area.w = (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));
/* Draw the leftover bar area. */
area.x = pbx + bw + bispw + (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.y = pby + bw + bispw;
area.w = ((MAX_PERCENTAGE - prcnt_) * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));
/* Clear the last text and draw new if text is provided. */
if(text.length()>0)
{
SDL_FillRect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
textarea_ = font::line_size(text, font::SIZE_NORMAL);
textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
textarea_.y = pby + pbh + 4*(bw + bispw);
textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOUR,text,textarea_.x,textarea_.y);
}
/* Flip the double buffering so the change becomes visible */
if(commit)
{
SDL_Flip(gdis);
}
}
void loadscreen::increment_progress(const int percentage, const std::string &text, const bool commit) {
set_progress(prcnt_ + percentage, text, commit);
}
void loadscreen::clear_screen(const bool commit)
{
int scrx = screen_.getx(); /* Screen width. */
int scry = screen_.gety(); /* Screen height. */
SDL_Rect area = {0, 0, scrx, scry}; /* Screen area. */
surface const disp(screen_.getSurface()); /* Screen surface. */
/* Make everything black. */
SDL_FillRect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
if(commit)
{
SDL_Flip(disp); /* Flip the double buffering. */
}
}
loadscreen *loadscreen::global_loadscreen = 0;
#define CALLS_TO_FILESYSTEM 112
#define PRCNT_BY_FILESYSTEM 20
#define CALLS_TO_BINARYWML 9561
#define PRCNT_BY_BINARYWML 20
#define CALLS_TO_SETCONFIG 306
#define PRCNT_BY_SETCONFIG 30
#define CALLS_TO_PARSER 50448
#define PRCNT_BY_PARSER 20
void increment_filesystem_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->filesystem_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Verifying cache.");
}
oldpct = (PRCNT_BY_FILESYSTEM * loadscreen::global_loadscreen->filesystem_counter) / CALLS_TO_FILESYSTEM;
newpct = (PRCNT_BY_FILESYSTEM * ++(loadscreen::global_loadscreen->filesystem_counter)) / CALLS_TO_FILESYSTEM;
//std::cerr << "Calls " << num;
if(oldpct != newpct) {
//std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
void increment_binary_wml_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->binarywml_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Reading cache.");
}
oldpct = (PRCNT_BY_BINARYWML * loadscreen::global_loadscreen->binarywml_counter) / CALLS_TO_BINARYWML;
newpct = (PRCNT_BY_BINARYWML * ++(loadscreen::global_loadscreen->binarywml_counter)) / CALLS_TO_BINARYWML;
//std::cerr << "Calls " << num;
if(oldpct != newpct) {
//std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
void increment_set_config_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->setconfig_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Reading unit files.");
}
oldpct = (PRCNT_BY_SETCONFIG * loadscreen::global_loadscreen->setconfig_counter) / CALLS_TO_SETCONFIG;
newpct = (PRCNT_BY_SETCONFIG * ++(loadscreen::global_loadscreen->setconfig_counter)) / CALLS_TO_SETCONFIG;
//std::cerr << "Calls " << num;
if(oldpct != newpct) {
//std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
void increment_parser_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->parser_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Reading files and creating cache.");
}
oldpct = (PRCNT_BY_PARSER * loadscreen::global_loadscreen->parser_counter) / CALLS_TO_PARSER;
newpct = (PRCNT_BY_PARSER * ++(loadscreen::global_loadscreen->parser_counter)) / CALLS_TO_PARSER;
//std::cerr << "Calls " << loadscreen::global_loadscreen->parser_counter;
if(oldpct != newpct) {
// std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
/* Draw top border. */
area.x = pbx; area.y = pby;
area.w = pbw + 2*(bw+bispw); area.h = bw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw bottom border. */
area.x = pbx; area.y = pby + pbh + bw + 2*bispw;
area.w = pbw + 2*(bw+bispw); area.h = bw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw left border. */
area.x = pbx; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw right border. */
area.x = pbx + pbw + bw + 2*bispw; area.y = pby + bw;
area.w = bw; area.h = pbh + 2*bispw;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,bcr,bcg,bcb));
/* Draw the finished bar area. */
area.x = pbx + bw + bispw; area.y = pby + bw + bispw;
area.w = (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,fcr,fcg,fcb));
/* Draw the leftover bar area. */
area.x = pbx + bw + bispw + (prcnt_ * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.y = pby + bw + bispw;
area.w = ((MAX_PERCENTAGE - prcnt_) * pbw) / (MAX_PERCENTAGE - MIN_PERCENTAGE); area.h = pbh;
SDL_FillRect(gdis,&area,SDL_MapRGB(gdis->format,lcr,lcg,lcb));
/* Clear the last text and draw new if text is provided. */
if(text.length()>0)
{
SDL_FillRect(gdis,&textarea_,SDL_MapRGB(gdis->format,0,0,0));
textarea_ = font::line_size(text, font::SIZE_NORMAL);
textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
textarea_.y = pby + pbh + 4*(bw + bispw);
textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOUR,text,textarea_.x,textarea_.y);
}
/* Flip the double buffering so the change becomes visible */
if(commit)
{
SDL_Flip(gdis);
}
}
void loadscreen::increment_progress(const int percentage, const std::string &text, const bool commit) {
set_progress(prcnt_ + percentage, text, commit);
}
void loadscreen::clear_screen(const bool commit)
{
int scrx = screen_.getx(); /* Screen width. */
int scry = screen_.gety(); /* Screen height. */
SDL_Rect area = {0, 0, scrx, scry}; /* Screen area. */
surface const disp(screen_.getSurface()); /* Screen surface. */
/* Make everything black. */
SDL_FillRect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
if(commit)
{
SDL_Flip(disp); /* Flip the double buffering. */
}
}
loadscreen *loadscreen::global_loadscreen = 0;
#define CALLS_TO_FILESYSTEM 112
#define PRCNT_BY_FILESYSTEM 20
#define CALLS_TO_BINARYWML 9561
#define PRCNT_BY_BINARYWML 20
#define CALLS_TO_SETCONFIG 306
#define PRCNT_BY_SETCONFIG 30
#define CALLS_TO_PARSER 50448
#define PRCNT_BY_PARSER 20
void increment_filesystem_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->filesystem_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Verifying cache.");
}
oldpct = (PRCNT_BY_FILESYSTEM * loadscreen::global_loadscreen->filesystem_counter) / CALLS_TO_FILESYSTEM;
newpct = (PRCNT_BY_FILESYSTEM * ++(loadscreen::global_loadscreen->filesystem_counter)) / CALLS_TO_FILESYSTEM;
//std::cerr << "Calls " << num;
if(oldpct != newpct) {
//std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
void increment_binary_wml_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->binarywml_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Reading cache.");
}
oldpct = (PRCNT_BY_BINARYWML * loadscreen::global_loadscreen->binarywml_counter) / CALLS_TO_BINARYWML;
newpct = (PRCNT_BY_BINARYWML * ++(loadscreen::global_loadscreen->binarywml_counter)) / CALLS_TO_BINARYWML;
//std::cerr << "Calls " << num;
if(oldpct != newpct) {
//std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
void increment_set_config_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->setconfig_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Reading unit files.");
}
oldpct = (PRCNT_BY_SETCONFIG * loadscreen::global_loadscreen->setconfig_counter) / CALLS_TO_SETCONFIG;
newpct = (PRCNT_BY_SETCONFIG * ++(loadscreen::global_loadscreen->setconfig_counter)) / CALLS_TO_SETCONFIG;
//std::cerr << "Calls " << num;
if(oldpct != newpct) {
//std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}
void increment_parser_progress () {
unsigned newpct, oldpct;
// Only do something if the variable is filled in.
// I am assuming non parallel access here!
if (loadscreen::global_loadscreen != 0) {
if (loadscreen::global_loadscreen->parser_counter == 0) {
loadscreen::global_loadscreen->increment_progress(0, "Reading files and creating cache.");
}
oldpct = (PRCNT_BY_PARSER * loadscreen::global_loadscreen->parser_counter) / CALLS_TO_PARSER;
newpct = (PRCNT_BY_PARSER * ++(loadscreen::global_loadscreen->parser_counter)) / CALLS_TO_PARSER;
//std::cerr << "Calls " << loadscreen::global_loadscreen->parser_counter;
if(oldpct != newpct) {
// std::cerr << " percent " << newpct;
loadscreen::global_loadscreen->increment_progress(newpct - oldpct);
}
//std::cerr << std::endl;
}
}

View File

@ -94,6 +94,17 @@ A poisoned unit cannot be cured of its poison by a healer, and must seek the car
*
*/
namespace unit_abilities {
bool affects_side(const config& cfg, const std::vector<team>& teams, size_t side, size_t other_side)
{
return ((cfg["affect_allies"] == "" || utils::string_bool(cfg["affect_allies"])) && !teams[side-1].is_enemy(other_side))
|| (utils::string_bool(cfg["affect_enemies"]) && teams[side-1].is_enemy(other_side));
}
}
bool unit::get_ability_bool(const std::string& ability, const gamemap::location& loc) const
{
@ -119,9 +130,8 @@ bool unit::get_ability_bool(const std::string& ability, const gamemap::location&
if(adj_abilities) {
const config::child_list& list = adj_abilities->get_children(ability);
for(config::child_list::const_iterator j = list.begin(); j != list.end(); ++j) {
if((((**j)["affect_allies"] == "" || (utils::string_bool((**j)["affect_allies"]) && !(*teams_)[side()-1].is_enemy(it->second.side())))
|| (utils::string_bool((**j)["affect_enemies"]) && (*teams_)[side()-1].is_enemy(it->second.side()))) &&
it->second.ability_active(ability,**j,adjacent[i]) && ability_affects_adjacent(ability,**j,i,loc)) {
if(unit_abilities::affects_side(**j,*teams_,side(),it->second.side())
&& it->second.ability_active(ability,**j,adjacent[i]) && ability_affects_adjacent(ability,**j,i,loc)) {
return true;
}
}
@ -157,9 +167,8 @@ unit_ability_list unit::get_abilities(const std::string& ability, const gamemap:
if(adj_abilities) {
const config::child_list& list = adj_abilities->get_children(ability);
for(config::child_list::const_iterator j = list.begin(); j != list.end(); ++j) {
if((((**j)["affect_allies"] == "" || (utils::string_bool((**j)["affect_allies"]) && !(*teams_)[side()-1].is_enemy(it->second.side())))
|| (utils::string_bool((**j)["affect_enemies"]) && (*teams_)[side()-1].is_enemy(it->second.side()))) &&
it->second.ability_active(ability,**j,adjacent[i]) && ability_affects_adjacent(ability,**j,i,loc)) {
if(unit_abilities::affects_side(**j,*teams_,side(),it->second.side())
&& it->second.ability_active(ability,**j,adjacent[i]) && ability_affects_adjacent(ability,**j,i,loc)) {
res.cfgs.push_back(std::pair<config*,gamemap::location>(*j,adjacent[i]));
}
}
@ -226,8 +235,7 @@ std::vector<std::string> unit::ability_tooltips(const gamemap::location& loc) co
const config::child_map& adj_list_map = adj_abilities->all_children();
for(config::child_map::const_iterator k = adj_list_map.begin(); k != adj_list_map.end(); ++k) {
for(config::child_list::const_iterator j = k->second.begin(); j != k->second.end(); ++j) {
if((((**j)["affect_allies"] == "" || (utils::string_bool((**j)["affect_allies"]) && !(*teams_)[side()-1].is_enemy(it->second.side())))
|| (utils::string_bool((**j)["affect_enemies"]) && (*teams_)[side()-1].is_enemy(it->second.side())))) {
if(unit_abilities::affects_side(**j,*teams_,side(),it->second.side())) {
const config* adj_desc = (*j)->child("adjacent_description");
if(ability_affects_adjacent(k->first,**j,i,adjacent[i])) {
if(!adj_desc) {