ran codeclean over all files and set them all to svn:eol-style 'native'

This commit is contained in:
Gunter Labes 2006-06-05 20:02:25 +00:00
parent 1190962ddd
commit 23ca57f01e
71 changed files with 3467 additions and 3467 deletions

View file

@ -210,7 +210,7 @@ void validate_recruit_unit()
gamemap::location under_leadership(const unit_map& units,
const gamemap::location& loc, int* bonus)
{
const unit_map::const_iterator un = units.find(loc);
if(un == units.end()) {
return gamemap::location::null_location;
@ -508,55 +508,55 @@ battle_context::unit_stats::unit_stats(const unit &u, const gamemap::location& u
backstab_pos = is_attacker && backstab_check(u_loc, opp_loc, units, teams);
rounds = weapon->get_specials("berserk").highest("value", 1).first;
firststrike = weapon->get_special_bool("firststrike");
// Handle plague.
unit_ability_list plague_specials = weapon->get_specials("plague");
plagues = !plague_specials.empty() && opp.get_state("not_living") != "yes" &&
strcmp(opp.undead_variation().c_str(), "null") && !map.is_village(opp_loc);
if (!plague_specials.empty()) {
if((*plague_specials.cfgs.front().first)["type"] == "")
plague_type = u.id();
else
plague_type = (*plague_specials.cfgs.front().first)["type"];
}
// Compute chance to hit.
chance_to_hit = opp.defense_modifier(map.get_terrain(opp_loc));
unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
unit_abilities::effect cth_effects(cth_specials, chance_to_hit, backstab_pos);
chance_to_hit = cth_effects.get_composite_value();
// Compute base damage done with the weapon.
int base_damage = weapon->damage();
unit_ability_list dmg_specials = weapon->get_specials("damage");
unit_abilities::effect dmg_effect(dmg_specials, base_damage, backstab_pos);
base_damage = dmg_effect.get_composite_value();
// Get the damage multiplier applied to the base damage of the weapon.
int damage_multiplier = 100;
// Time of day bonus.
damage_multiplier += combat_modifier(status, units, u_loc, u.alignment(), map);
// Leadership bonus.
int leader_bonus = 0;
if (under_leadership(units, u_loc, &leader_bonus).valid())
damage_multiplier += leader_bonus;
// Resistance modifier.
damage_multiplier *= opp.damage_from(*weapon, !attacking, opp_loc);
// Compute both the normal and slowed damage. For the record,
// drain = normal damage / 2 and slow_drain = slow_damage / 2.
damage = round_damage(base_damage, damage_multiplier, 10000);
slow_damage = round_damage(base_damage, damage_multiplier, 20000);
if (is_slowed)
damage = slow_damage;
// Compute the number of blows and handle swarm.
unit_ability_list swarm_specials = weapon->get_specials("attacks");
if (!swarm_specials.empty()) {
swarm = true;
swarm_min = swarm_specials.highest("attacks_min").first;
@ -578,13 +578,13 @@ battle_context::unit_stats::unit_stats(const unit &u, const gamemap::location& u
swarm = false;
rounds = 1;
firststrike = false;
chance_to_hit = 0;
damage = 0;
slow_damage = 0;
num_blows = 0;
swarm_min = 0;
swarm_max = 0;
swarm_max = 0;
}
}
@ -602,7 +602,7 @@ void battle_context::unit_stats::dump() const
printf("swarm: %d\n", (int) swarm);
printf("rounds: %d\n", (int) rounds);
printf("firststrike: %d\n", (int) firststrike);
printf("\n");
printf("\n");
printf("hp: %d\n", hp);
printf("max_hp: %d\n", max_hp);
printf("chance_to_hit: %d\n", chance_to_hit);
@ -640,7 +640,7 @@ void attack(display& gui, const gamemap& map,
{
//stop the user from issuing any commands while the units are fighting
const events::command_disabler disable_commands;
unit_map::iterator a = units.find(attacker);
unit_map::iterator d = units.find(defender);
@ -651,16 +651,16 @@ void attack(display& gui, const gamemap& map,
int attackerxp = d->second.level();
int defenderxp = a->second.level();
a->second.set_attacks(a->second.attacks_left()-1);
a->second.set_movement(a->second.movement_left()-a->second.attacks()[attack_with].movement_used());
a->second.set_resting(false);
d->second.set_resting(false);
//if the attacker was invisible, she isn't anymore!
static const std::string hides("hides");
a->second.set_state(hides,"");
config dat;
{
battle_context bc(map, teams, units, state, info, attacker, defender, attack_with);
@ -683,17 +683,17 @@ void attack(display& gui, const gamemap& map,
battle_context bc(map, teams, units, state, info, attacker, defender, attack_with);
const battle_context::unit_stats& a_stats = bc.get_attacker_stats();
const battle_context::unit_stats& d_stats = bc.get_defender_stats();
dat.clear();
dat.add_child("first");
dat.add_child("second");
(*(dat.child("first")))["weapon"]=a_stats.weapon->name();
(*(dat.child("second")))["weapon"]=d_stats.weapon != NULL ? d_stats.weapon->name() : "none";
LOG_NG << "getting attack statistics\n";
statistics::attack_context attack_stats(a->second, d->second, a_stats.chance_to_hit, d_stats.chance_to_hit);
int orig_attacks = a_stats.num_blows;
int orig_defends = d_stats.num_blows;
int n_attacks = orig_attacks;
@ -760,10 +760,10 @@ void attack(display& gui, const gamemap& map,
OOS_error = true;
}
}
bool dies = unit_display::unit_attack(gui,units,attacker,defender,
damage_defender_takes,
*a_stats.weapon,
*a_stats.weapon,
update_display);
LOG_NG << "defender took " << damage_defender_takes << (dies ? " and died" : "") << "\n";
if(hits) {
@ -839,7 +839,7 @@ void attack(display& gui, const gamemap& map,
if(dies || hits) {
int amount_drained = a_stats.drains ? attacker_damage / 2 : 0;
if(amount_drained > 0) {
char buf[50];
snprintf(buf,sizeof(buf),"%d",amount_drained);
@ -1003,7 +1003,7 @@ void attack(display& gui, const gamemap& map,
bool dies = unit_display::unit_attack(gui,units,defender,attacker,
damage_attacker_takes,
*d_stats.weapon,
*d_stats.weapon,
update_display);
LOG_NG << "attacker took " << damage_attacker_takes << (dies ? " and died" : "") << "\n";
if(hits) {
@ -1013,7 +1013,7 @@ void attack(display& gui, const gamemap& map,
game_events::fire("defender_hits",attacker,defender,dat);
a = units.find(attacker);
d = units.find(defender);
// FIXME: If the event removes this attack, we should stop attacking.
// The previous code checked if 'attack_with' and 'defend_with' were still within the bounds of
// the attack arrays, or -1, but it was incorrect. The attack used could be removed and '*_with'
@ -1076,7 +1076,7 @@ void attack(display& gui, const gamemap& map,
if(hits || dies){
int amount_drained = d_stats.drains ? defender_damage / 2 : 0;
if(amount_drained > 0) {
char buf[50];
snprintf(buf,sizeof(buf),"%d",amount_drained);
@ -1216,13 +1216,13 @@ void attack(display& gui, const gamemap& map,
gui.invalidate(defender);
gui.draw(true,true);
}
if(OOS_error) {
if (!game_config::ignore_replay_errors) {
throw replay::error();
}
}
}
int village_owner(const gamemap::location& loc, const std::vector<team>& teams)
@ -1320,10 +1320,10 @@ void calculate_healing(display& disp, const gamemap& map,
unit_map::iterator curer = units.end();
std::vector<unit_map::iterator> healers;
int healing = 0;
std::string curing;
unit_ability_list heal = i->second.get_abilities("heals",i->first);
// Only consider healers on side which is starting now
// remove all healers not on this side
@ -1336,10 +1336,10 @@ void calculate_healing(display& disp, const gamemap& map,
++h_it;
}
}
unit_abilities::effect heal_effect(heal,0,false);
healing = heal_effect.get_composite_value();
for(std::vector<std::pair<config*,gamemap::location> >::const_iterator heal_it = heal.cfgs.begin(); heal_it != heal.cfgs.end(); ++heal_it) {
if((*heal_it->first)["poison"] == "cured") {
curer = units.find(heal_it->second);
@ -1349,11 +1349,11 @@ void calculate_healing(display& disp, const gamemap& map,
curing = "slowed";
}
}
for(std::vector<unit_abilities::individual_effect>::const_iterator heal_loc = heal_effect.begin(); heal_loc != heal_effect.end(); ++heal_loc) {
healers.push_back(units.find(heal_loc->loc));
}
if(i->second.side() == side) {
unit_ability_list regen = i->second.get_abilities("regenerate",i->first);
unit_abilities::effect regen_effect(regen,0,false);
@ -1403,11 +1403,11 @@ void calculate_healing(display& disp, const gamemap& map,
}
}
}
if (curing == "" && healing==0) {
continue;
}
int pos_max = i->second.max_hitpoints() - i->second.hitpoints();
int neg_max = -(i->second.hitpoints() - 1);
if(healing > pos_max) {
@ -1421,7 +1421,7 @@ void calculate_healing(display& disp, const gamemap& map,
if (disp.turbo() || recorder.is_skipping()
|| disp.fogged(i->first.x, i->first.y)
|| !update_display
|| !update_display
|| (i->second.invisible(i->first,units,teams) &&
teams[disp.viewing_team()].is_enemy(side))) {
// Simple path.
@ -1437,7 +1437,7 @@ void calculate_healing(display& disp, const gamemap& map,
int start_time = 0;
disp.scroll_to_tile(i->first.x, i->first.y, display::ONSCREEN);
disp.select_hex(i->first);
for(std::vector<unit_map::iterator>::iterator heal_anim_it = healers.begin(); heal_anim_it != healers.end(); ++heal_anim_it) {
(*heal_anim_it)->second.set_facing((*heal_anim_it)->first.get_relative_dir(i->first));
(*heal_anim_it)->second.set_healing(disp,(*heal_anim_it)->first);
@ -1599,9 +1599,9 @@ time_of_day timeofday_at(const gamestatus& status,const unit_map& units,const ga
{
int lighten = maximum<int>(map.get_terrain_info(map.get_terrain(loc)).light_modification() , 0);
int darken = minimum<int>(map.get_terrain_info(map.get_terrain(loc)).light_modification() , 0);
time_of_day tod = status.get_time_of_day(lighten + darken,loc);
if(loc.valid()) {
gamemap::location locs[7];
locs[0] = loc;

View file

@ -59,8 +59,8 @@ public:
const attack_type *weapon; // The weapon used by the unit to attack the opponent, or NULL if there is none.
int attack_num; // Index into unit->attacks() or -1 for none.
bool is_attacker; // True if the unit is the attacker.
bool is_poisoned; // True if the unit is poisoned at the beginning of the battle.
bool is_slowed; // True if the unit is slowed at the beginning of the battle.
bool is_poisoned; // True if the unit is poisoned at the beginning of the battle.
bool is_slowed; // True if the unit is slowed at the beginning of the battle.
bool slows; // Attack slows opponent when it hits.
bool drains; // Attack drains opponent when it hits.
bool stones; // Attack turns opponent to stone when it hits.
@ -75,12 +75,12 @@ public:
unsigned int hp; // Hitpoints of the unit at the beginning of the battle.
unsigned int max_hp; // Maximum hitpoints of the unit.
unsigned int chance_to_hit; // Effective chance to hit as a percentage (all factors accounted for).
int damage; // Effective damage of the weapon (all factors accounted for).
int damage; // Effective damage of the weapon (all factors accounted for).
int slow_damage; // Effective damage if unit becomes slowed (== damage, if already slowed)
unsigned int num_blows; // Effective number of blows, takes swarm into account.
unsigned int swarm_min; // Minimum number of blows with swarm (equal to num_blows if swarm isn't used).
unsigned int swarm_max; // Maximum number of blows with swarm (equal to num_blows if swarm isn't used).
std::string plague_type; // The plague type used by the attack, if any.
unit_stats(const unit &u, const gamemap::location& u_loc,
@ -102,7 +102,7 @@ public:
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc,
int attacker_weapon = -1, double harm_weight = 1.0, const combatant *prev_def = NULL);
battle_context(const battle_context &other);
~battle_context() { delete attacker_stats_; delete defender_stats_; }
@ -110,7 +110,7 @@ public:
// This method returns the statistics of the attacker.
const unit_stats& get_attacker_stats() const { return *attacker_stats_; }
// This method returns the statistics of the defender.
const unit_stats& get_defender_stats() const { return *defender_stats_; }

View file

@ -840,8 +840,8 @@ void ai::do_move()
move_unit(ui->first,closest_move.first,possible_moves);
}
}
std::vector<attack_analysis> analysis;
LOG_AI << "combat phase\n";

View file

@ -106,7 +106,7 @@ protected:
struct attack_analysis
{
void analyze(const gamemap& map, unit_map& units,
void analyze(const gamemap& map, unit_map& units,
const std::vector<team>& teams,
const gamestatus& status, const game_data& gamedata,
class ai& ai_obj,

View file

@ -279,7 +279,7 @@ bool operator==(const battle_type& a, const battle_type& b)
std::set<battle_type> weapon_choice_cache;
void ai::attack_analysis::analyze(const gamemap& map, unit_map& units,
void ai::attack_analysis::analyze(const gamemap& map, unit_map& units,
const std::vector<team>& teams,
const gamestatus& status, const game_data& gamedata,
class ai& ai_obj,

View file

@ -136,7 +136,7 @@ static PyObject* wrapper_unittype_attacks( wesnoth_unittype* type, PyObject* arg
static PyMethodDef unittype_methods[] = {
{ "advances_to", (PyCFunction)python_ai::unittype_advances_to, METH_VARARGS,
"Returns: unittype[]\n"
"Returns a list of wesnoth.unittype of possible advancements."},
"Returns a list of wesnoth.unittype of possible advancements."},
{ "attacks", (PyCFunction)wrapper_unittype_attacks, METH_VARARGS,
"Returns: attacktype[]\n"
"Returns list of possible attack types.\n"},
@ -910,7 +910,7 @@ static PyObject* wrapper_team_side(wesnoth_team* team, void* /*closure*/)
}
return Py_BuildValue("i", side);
}
static int wrapper_team_internal_compare(wesnoth_team* left, wesnoth_team* right)
{
return (long)left->team_ - (long)right->team_;
@ -1405,7 +1405,7 @@ PyObject* python_ai::wrapper_unit_attack_statistics(wesnoth_unit* self, PyObject
return NULL;
if (!running_instance->is_unit_valid(self->unit_))
return NULL;
info& inf = running_instance->get_info();
// We need to temporarily move our unit to where the attack calculation is
@ -1432,19 +1432,19 @@ PyObject* python_ai::wrapper_unit_attack_statistics(wesnoth_unit* self, PyObject
if (attacker[i] > 0)
PyDict_SetItem(adict, PyInt_FromLong(i), PyFloat_FromDouble(attacker[i]));
}
std::vector<double>defender = bc.get_defender_combatant().hp_dist;
PyObject* ddict = PyDict_New();
for (i = 0; i < defender.size(); i++) {
if (defender[i] > 0)
PyDict_SetItem(ddict, PyInt_FromLong(i), PyFloat_FromDouble(defender[i]));
}
// restore old position again
temp = inf.units.extract(*from->location_);
if (backup)
inf.units.add(backup);
PyObject *ret = Py_BuildValue("(OO)", adict, ddict);
return ret;

View file

@ -41,7 +41,7 @@
#define debug(x)
#endif
namespace
namespace
{
// A matrix of A's hitpoints vs B's hitpoints.
struct prob_matrix
@ -102,7 +102,7 @@ private:
// Shift columns on this plane (b taking damage). Returns min col.
void shift_cols(unsigned dst, unsigned src,
unsigned damage, double prob, bool drain);
// Shift rows on this plane (a taking damage). Returns new min row.
void shift_rows(unsigned dst, unsigned src,
unsigned damage, double prob, bool drain);
@ -214,7 +214,7 @@ const double &prob_matrix::val(unsigned p, unsigned row, unsigned col) const
void prob_matrix::dump() const
{
unsigned int row, col, m;
const char *names[]
const char *names[]
= { "NEITHER_SLOWED", "A_SLOWED", "B_SLOWED", "BOTH_SLOWED" };
for (m = 0; m < 4; m++) {
@ -259,7 +259,7 @@ void prob_matrix::xfer(unsigned dst_plane, unsigned src_plane,
: src_plane == A_SLOWED ? "[A_SLOWED]"
: src_plane == B_SLOWED ? "[B_SLOWED]"
: src_plane == BOTH_SLOWED ? "[BOTH_SLOWED]" : "INVALID",
row_src, col_src,
row_src, col_src,
dst_plane == NEITHER_SLOWED ? ""
: dst_plane == A_SLOWED ? "[A_SLOWED]"
: dst_plane == B_SLOWED ? "[B_SLOWED]"
@ -320,7 +320,7 @@ void prob_matrix::receive_blow_b(unsigned damage, unsigned slow_damage, double h
if (!plane[src])
continue;
// If a slows us we go from 0=>2, 1=>3, 2=>2 3=>3.
// If a slows us we go from 0=>2, 1=>3, 2=>2 3=>3.
if (a_slows)
dst = (src|2);
else
@ -404,7 +404,7 @@ void prob_matrix::extract_results(std::vector<double> summary_a[2],
// A is slow in planes 1 and 3.
dst_a = (p & 1);
// B is slow in planes 2 and 3.
dst_b = !!(p & 2);
dst_b = !!(p & 2);
for (row = 0; row < rows; row++) {
for (col = 0; col < cols; col++) {
summary_a[dst_a][row] += val(p, row, col);
@ -496,7 +496,7 @@ combatant::combatant(const combatant &that, const battle_context::unit_stats &u)
summary[0] = that.summary[0];
summary[1] = that.summary[1];
}
// For swarm, whether we get an attack depends on HP distribution from
@ -648,7 +648,7 @@ double combatant::average_hp(unsigned int healing) const
// test each one against the others.
#define NUM_UNITS 50
// Stolen from glibc headers sys/time.h
// Stolen from glibc headers sys/time.h
#define timer_sub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
@ -736,7 +736,7 @@ static void run(unsigned specific_battle)
#ifdef BENCHMARK
printf("Total time for %i combats was %lu.%06lu\n",
NUM_UNITS*(NUM_UNITS-1)*(NUM_UNITS-2), total.tv_sec, total.tv_usec);
printf("Time per calc = %li us\n",
printf("Time per calc = %li us\n",
((end.tv_sec-start.tv_sec)*1000000 + (end.tv_usec-start.tv_usec))
/ (NUM_UNITS*(NUM_UNITS-1)*(NUM_UNITS-2)));
#else

View file

@ -22,11 +22,11 @@
std::vector<Uint32> string2rgb(std::string s){
std::vector<Uint32> out;
std::vector<std::string> rgb_vec = utils::split(s);
while(rgb_vec.size()%3) {
rgb_vec.push_back("0");
}
std::vector<std::string>::iterator c=rgb_vec.begin();
int r,g,b;

View file

@ -537,13 +537,13 @@ config config::merge_with(const config& c) const
const child_map& child_changes = c.all_children();
child_map::const_iterator i;
for(i = child_changes.begin(); i != child_changes.end(); ++i) {
child_map::iterator itor = n.children.find(i->first);
size_t index = 0;
size_t last_index = itor != n.children.end() ? itor->second.size() : 0;
for(const_child_iterator j = i->second.begin(); j != i->second.end();) {
const config* item = *j;
if(i->first.empty()) {
++j;
continue;
@ -605,7 +605,7 @@ void config::debug() const{
std::string config::hash() const
{
static const unsigned int hash_length = 128;
static const char hash_string[] =
static const char hash_string[] =
"+-,.<>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char hash_str[hash_length + 1];
std::string::const_iterator c;
@ -615,7 +615,7 @@ std::string config::hash() const
hash_str[i] = 'a';
}
hash_str[hash_length] = 0;
i = 0;
for(string_map::const_iterator val = values.begin(); val != values.end(); ++val) {
if(val->first.size() && val->second.size()) {
@ -656,11 +656,11 @@ std::string config::hash() const
}
}
}
for(i = 0; i != hash_length; ++i) {
hash_str[i] = hash_string[(unsigned)hash_str[i]%strlen(hash_string)];
}
return std::string(hash_str);
}

View file

@ -122,9 +122,9 @@ public:
config get_diff(const config& c) const;
void apply_diff(const config& diff); //throw error
config merge_with(const config& c) const;
//append data from another config object to this one. attributes in the
//latter config object will clobber attributes in this one.
void append(const config& cfg);

View file

@ -1,16 +1,16 @@
/*
Copyright (C) 2005 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2005 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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 "global.hpp"
#include <sstream>
@ -87,7 +87,7 @@ void get_player_info(const config& cfg, game_state& gamestate, std::string save_
//if this side tag describes the leader of the side
if(!utils::string_bool(cfg["no_leader"]) && cfg["controller"] != "null") {
unit new_unit(&gameinfo, &units, &map, &game_status, &teams,cfg);
//search the recall list for leader units, and if there is
//one, use it in place of the config-described unit
if(player != NULL) {

View file

@ -1,17 +1,17 @@
/* $Id: config.hpp 8785 2005-11-08 22:23:03Z jhinrichs $ */
/*
Copyright (C) 2005 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2005 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef CONFIG_ADAPTER_HPP_INCLUDED
#define CONFIG_ADAPTER_HPP_INCLUDED

View file

@ -768,7 +768,7 @@ void unit_preview_pane::draw_contents()
details << "\n" << at_it->name()
<< " (" << gettext(at_it->type().c_str()) << ")\n";
details << at_it->weapon_specials(true);
details << "\n"
<< at_it->damage() << "-" << at_it->num_attacks() << " -- "

View file

@ -87,7 +87,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
teams_(t), lastDraw_(0), drawSkips_(0),
invalidateAll_(true), invalidateUnit_(true),
invalidateGameStatus_(true), panelsDrawn_(false),
currentTeam_(0), activeTeam_(0),
currentTeam_(0), activeTeam_(0),
turbo_(false), grid_(false), sidebarScaling_(1.0),
theme_(theme_cfg,screen_area()), builder_(cfg, level, map),
first_turn_(true), in_game_(false), map_labels_(*this,map),
@ -1167,7 +1167,7 @@ void display::draw_report(reports::TYPE report_num)
area.w = minimum<int>(rect.w + rect.x - x, img->w);
area.h = minimum<int>(rect.h + rect.y - y, img->h);
draw_image_for_report(img, area);
// draw illuminated time
if(report_num == reports::TIME_OF_DAY && img != NULL) {
time_of_day tod = timeofday_at(status_,units_,mouseoverHex_,map_);
@ -2356,7 +2356,7 @@ void display::add_chat_message(const std::string& speaker, int side, const std::
}
}
}
if (!ignored){
bool action;
std::string msg;
@ -2369,7 +2369,7 @@ void display::add_chat_message(const std::string& speaker, int side, const std::
action = false;
}
msg = font::word_wrap_text(msg,font::SIZE_SMALL,mapx()*3/4);
int ypos = chat_message_x;
for(std::vector<chat_message>::const_iterator m = chat_messages_.begin(); m != chat_messages_.end(); ++m) {
ypos += font::get_floating_label_rect(m->handle).h;
@ -2409,7 +2409,7 @@ void display::add_chat_message(const std::string& speaker, int side, const std::
message_complete << timestring() << " ";
}
message_complete << str.str();
const SDL_Rect rect = map_area();
const int speaker_handle = font::add_floating_label(message_complete.str(),font::SIZE_SMALL,speaker_colour,
rect.x+chat_message_x,rect.y+ypos,

View file

@ -1,193 +1,193 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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 "floating_textbox.hpp"
#include "font.hpp"
#include "preferences.hpp"
namespace gui{
floating_textbox::floating_textbox() : box_(NULL), check_(NULL), mode_(TEXTBOX_NONE), label_(0)
{}
void floating_textbox::close(display& gui)
{
if(!active()) {
return;
}
if(check_ != NULL) {
if(mode_ == TEXTBOX_MESSAGE) {
preferences::set_message_private(check_->checked());
}
}
box_.assign(NULL);
check_.assign(NULL);
font::remove_floating_label(label_);
mode_ = TEXTBOX_NONE;
gui.invalidate_all();
}
void floating_textbox::update_location(display& gui)
{
if (box_ == NULL)
return;
const SDL_Rect& area = gui.map_area();
const int border_size = 10;
const int ypos = area.y+area.h-30 - (check_ != NULL ? check_->height() + border_size : 0);
if (label_ != 0)
font::remove_floating_label(label_);
label_ = font::add_floating_label(label_string_,font::SIZE_NORMAL,
font::YELLOW_COLOUR,area.x+border_size,ypos,0,0,-1, area,font::LEFT_ALIGN);
if (label_ == 0)
return;
const SDL_Rect& label_area = font::get_floating_label_rect(label_);
const int textbox_width = area.w - label_area.w - border_size*3;
if(textbox_width <= 0) {
font::remove_floating_label(label_);
return;
}
if(box_ != NULL) {
box_->set_volatile(true);
const SDL_Rect rect = {
area.x + label_area.w + border_size*2, ypos,
textbox_width, box_->height()
};
box_->set_location(rect);
}
if(check_ != NULL) {
check_->set_volatile(true);
check_->set_location(box_->location().x,box_->location().y + box_->location().h + border_size);
}
}
void floating_textbox::show(gui::TEXTBOX_MODE mode, const std::string& label,
const std::string& check_label, bool checked, display& gui)
{
close(gui);
label_string_ = label;
mode_ = mode;
if(check_label != "") {
check_.assign(new gui::button(gui.video(),check_label,gui::button::TYPE_CHECK));
check_->set_check(checked);
}
box_.assign(new gui::textbox(gui.video(),100,"",true,256,0.8,0.6));
update_location(gui);
}
void floating_textbox::tab(std::vector<team>& teams, const unit_map& units, display& gui)
{
if(active() == false) {
return;
}
switch(mode_) {
case gui::TEXTBOX_MESSAGE:
{
std::string text = box_->text();
std::string semiword;
bool beginning;
const size_t last_space = text.rfind(" ");
//if last character is a space return
if(last_space == text.size() -1) {
return;
}
if(last_space == std::string::npos) {
beginning = true;
semiword = text;
}else{
beginning = false;
semiword.assign(text,last_space+1,text.size());
}
std::vector<std::string> matches;
std::string best_match = semiword;
for(size_t n = 0; n != teams.size(); ++n) {
if(teams[n].is_empty()) {
continue;
}
const unit_map::const_iterator leader = team_leader(n+1,units);
if(leader != units.end()) {
const std::string& name = leader->second.description();
if( name.size() >= semiword.size() &&
std::equal(semiword.begin(),semiword.end(),name.begin(),chars_equal_insensitive)) {
if(matches.empty()) {
best_match = name;
} else {
int j= 0;;
while(best_match[j] == name[j]) j++;
best_match.erase(best_match.begin()+j,best_match.end());
}
matches.push_back(name);
}
}
}
if(matches.empty()) {
const std::set<std::string>& observers = gui.observers();
for(std::set<std::string>::const_iterator i = observers.begin(); i != observers.end(); ++i) {
if( i->size() >= semiword.size() &&
std::equal(semiword.begin(),semiword.end(),i->begin(),chars_equal_insensitive)) {
if(matches.empty()) {
best_match = *i;
} else {
int j = 0;
while(toupper(best_match[j]) == toupper((*i)[j])) j++;
best_match.erase(best_match.begin()+j,best_match.end());
}
matches.push_back(*i);
}
}
}
if(!matches.empty()) {
std::string add = beginning ? ": " : " ";
text.replace(last_space+1, semiword.size(), best_match);
if(matches.size() == 1) {
text.append(add);
} else {
std::string completion_list;
std::vector<std::string>::iterator it;
for(it =matches.begin();it!=matches.end();it++) {
completion_list += " ";
completion_list += *it;
}
gui.add_chat_message("",0,completion_list,display::MESSAGE_PRIVATE);
}
box_->set_text(text);
}
break;
}
default:
LOG_STREAM(err, display) << "unknown textbox mode\n";
}
}
}
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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 "floating_textbox.hpp"
#include "font.hpp"
#include "preferences.hpp"
namespace gui{
floating_textbox::floating_textbox() : box_(NULL), check_(NULL), mode_(TEXTBOX_NONE), label_(0)
{}
void floating_textbox::close(display& gui)
{
if(!active()) {
return;
}
if(check_ != NULL) {
if(mode_ == TEXTBOX_MESSAGE) {
preferences::set_message_private(check_->checked());
}
}
box_.assign(NULL);
check_.assign(NULL);
font::remove_floating_label(label_);
mode_ = TEXTBOX_NONE;
gui.invalidate_all();
}
void floating_textbox::update_location(display& gui)
{
if (box_ == NULL)
return;
const SDL_Rect& area = gui.map_area();
const int border_size = 10;
const int ypos = area.y+area.h-30 - (check_ != NULL ? check_->height() + border_size : 0);
if (label_ != 0)
font::remove_floating_label(label_);
label_ = font::add_floating_label(label_string_,font::SIZE_NORMAL,
font::YELLOW_COLOUR,area.x+border_size,ypos,0,0,-1, area,font::LEFT_ALIGN);
if (label_ == 0)
return;
const SDL_Rect& label_area = font::get_floating_label_rect(label_);
const int textbox_width = area.w - label_area.w - border_size*3;
if(textbox_width <= 0) {
font::remove_floating_label(label_);
return;
}
if(box_ != NULL) {
box_->set_volatile(true);
const SDL_Rect rect = {
area.x + label_area.w + border_size*2, ypos,
textbox_width, box_->height()
};
box_->set_location(rect);
}
if(check_ != NULL) {
check_->set_volatile(true);
check_->set_location(box_->location().x,box_->location().y + box_->location().h + border_size);
}
}
void floating_textbox::show(gui::TEXTBOX_MODE mode, const std::string& label,
const std::string& check_label, bool checked, display& gui)
{
close(gui);
label_string_ = label;
mode_ = mode;
if(check_label != "") {
check_.assign(new gui::button(gui.video(),check_label,gui::button::TYPE_CHECK));
check_->set_check(checked);
}
box_.assign(new gui::textbox(gui.video(),100,"",true,256,0.8,0.6));
update_location(gui);
}
void floating_textbox::tab(std::vector<team>& teams, const unit_map& units, display& gui)
{
if(active() == false) {
return;
}
switch(mode_) {
case gui::TEXTBOX_MESSAGE:
{
std::string text = box_->text();
std::string semiword;
bool beginning;
const size_t last_space = text.rfind(" ");
//if last character is a space return
if(last_space == text.size() -1) {
return;
}
if(last_space == std::string::npos) {
beginning = true;
semiword = text;
}else{
beginning = false;
semiword.assign(text,last_space+1,text.size());
}
std::vector<std::string> matches;
std::string best_match = semiword;
for(size_t n = 0; n != teams.size(); ++n) {
if(teams[n].is_empty()) {
continue;
}
const unit_map::const_iterator leader = team_leader(n+1,units);
if(leader != units.end()) {
const std::string& name = leader->second.description();
if( name.size() >= semiword.size() &&
std::equal(semiword.begin(),semiword.end(),name.begin(),chars_equal_insensitive)) {
if(matches.empty()) {
best_match = name;
} else {
int j= 0;;
while(best_match[j] == name[j]) j++;
best_match.erase(best_match.begin()+j,best_match.end());
}
matches.push_back(name);
}
}
}
if(matches.empty()) {
const std::set<std::string>& observers = gui.observers();
for(std::set<std::string>::const_iterator i = observers.begin(); i != observers.end(); ++i) {
if( i->size() >= semiword.size() &&
std::equal(semiword.begin(),semiword.end(),i->begin(),chars_equal_insensitive)) {
if(matches.empty()) {
best_match = *i;
} else {
int j = 0;
while(toupper(best_match[j]) == toupper((*i)[j])) j++;
best_match.erase(best_match.begin()+j,best_match.end());
}
matches.push_back(*i);
}
}
}
if(!matches.empty()) {
std::string add = beginning ? ": " : " ";
text.replace(last_space+1, semiword.size(), best_match);
if(matches.size() == 1) {
text.append(add);
} else {
std::string completion_list;
std::vector<std::string>::iterator it;
for(it =matches.begin();it!=matches.end();it++) {
completion_list += " ";
completion_list += *it;
}
gui.add_chat_message("",0,completion_list,display::MESSAGE_PRIVATE);
}
box_->set_text(text);
}
break;
}
default:
LOG_STREAM(err, display) << "unknown textbox mode\n";
}
}
}

View file

@ -1,55 +1,55 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef FLOATING_TEXTBOX_H_INCLUDED
#define FLOATING_TEXTBOX_H_INCLUDED
#include "global.hpp"
#include "display.hpp"
#include "scoped_resource.hpp"
#include "team.hpp"
#include "unit.hpp"
#include "widgets/textbox.hpp"
namespace gui{
enum TEXTBOX_MODE { TEXTBOX_NONE, TEXTBOX_SEARCH, TEXTBOX_MESSAGE,
TEXTBOX_COMMAND };
class floating_textbox{
public:
floating_textbox();
const TEXTBOX_MODE mode() const { return mode_; }
const util::scoped_ptr<gui::button>& check() const { return check_; }
const util::scoped_ptr<gui::textbox>& box() const { return box_; }
void close(display& gui);
void update_location(display& gui);
void show(gui::TEXTBOX_MODE mode, const std::string& label,
const std::string& check_label, bool checked, display& gui);
void tab(std::vector<team>& teams, const unit_map& units, display& gui);
bool active() const { return box_.get() != NULL; }
private:
util::scoped_ptr<gui::textbox> box_;
util::scoped_ptr<gui::button> check_;
TEXTBOX_MODE mode_;
std::string label_string_;
int label_;
};
}
#endif
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef FLOATING_TEXTBOX_H_INCLUDED
#define FLOATING_TEXTBOX_H_INCLUDED
#include "global.hpp"
#include "display.hpp"
#include "scoped_resource.hpp"
#include "team.hpp"
#include "unit.hpp"
#include "widgets/textbox.hpp"
namespace gui{
enum TEXTBOX_MODE { TEXTBOX_NONE, TEXTBOX_SEARCH, TEXTBOX_MESSAGE,
TEXTBOX_COMMAND };
class floating_textbox{
public:
floating_textbox();
const TEXTBOX_MODE mode() const { return mode_; }
const util::scoped_ptr<gui::button>& check() const { return check_; }
const util::scoped_ptr<gui::textbox>& box() const { return box_; }
void close(display& gui);
void update_location(display& gui);
void show(gui::TEXTBOX_MODE mode, const std::string& label,
const std::string& check_label, bool checked, display& gui);
void tab(std::vector<team>& teams, const unit_map& units, display& gui);
bool active() const { return box_.get() != NULL; }
private:
util::scoped_ptr<gui::textbox> box_;
util::scoped_ptr<gui::button> check_;
TEXTBOX_MODE mode_;
std::string label_string_;
int label_;
};
}
#endif

View file

@ -379,7 +379,7 @@ void text_surface::bidi_cvt()
int len = str_.length();
FriBidiChar *bidi_logical = new FriBidiChar[len + 2];
FriBidiChar *bidi_visual = new FriBidiChar[len + 2];
char *utf8str = new char[4*len + 1]; //assume worst case here (all 4 Byte characters)
char *utf8str = new char[4*len + 1]; //assume worst case here (all 4 Byte characters)
FriBidiCharType base_dir = FRIBIDI_TYPE_ON;
int n;

View file

@ -513,7 +513,7 @@ bool game_controller::play_multiplayer_mode()
std::cerr << "Could not find era '" << era << "'\n";
return false;
}
level["turns"] = turns;
const config* const side = era_cfg->child("multiplayer_side");
@ -1398,7 +1398,7 @@ void game_controller::read_game_cfg(const preproc_map& defines, config& cfg, boo
}
cfg.merge_children("units");
config& hashes = cfg.add_child("multiplayer_hashes");
for(config::child_list::const_iterator ch = cfg.get_children("multiplayer").begin(); ch != cfg.get_children("multiplayer").end(); ++ch) {
hashes[(**ch)["id"]] = (*ch)->hash();
@ -1703,13 +1703,13 @@ int play_game(int argc, char** argv)
loadscreen::global_loadscreen = new loadscreen(game.disp().video());
loadscreen::global_loadscreen->clear_screen();
res = game.init_language();
if(res == false) {
std::cerr << "could not initialize the language\n";
return 0;
}
loadscreen::global_loadscreen->increment_progress(5, "Loading game configuration.");
res = game.init_config();
if(res == false) {

View file

@ -236,9 +236,9 @@ public:
bool handle_event(const queued_event& event_info,
const vconfig cfg = vconfig());
bool& rebuild_screen() {return rebuild_screen_;}
private:
bool handle_event_command(const queued_event& event_info, const std::string& cmd, const vconfig cfg, bool& mutated);
@ -271,7 +271,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
{
log_scope2(engine, "handle_event_command");
LOG_NG << "handling command: '" << cmd << "'\n";
bool rval = true;
//sub commands that need to be handled in a guaranteed ordering
if(cmd == "command") {
@ -573,14 +573,14 @@ bool event_handler::handle_event_command(const queued_event& event_info,
wassert(state_of_game != NULL);
value = utils::interpolate_variables_into_string(value, *state_of_game);
add = utils::interpolate_variables_into_string(add, *state_of_game);
wassert(status_ptr != NULL);
if(add != "") {
status_ptr->modify_turns(add);
} else {
status_ptr->add_turns(lexical_cast_default<int>(value,0));
}
}
//command to store gold into a variable
else if(cmd == "store_gold") {
@ -617,7 +617,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
gender_string = utils::interpolate_variables_into_string(gender_string, *state_of_game);
x = utils::interpolate_variables_into_string(x, *state_of_game);
y = utils::interpolate_variables_into_string(y, *state_of_game);
size_t side_num = lexical_cast_default<int>(side,1)-1;
if (side_num >= teams->size()) side_num = 0;
@ -1018,7 +1018,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
std::string img = cfg["image"];
wassert(state_of_game != NULL);
img = utils::interpolate_variables_into_string(img, *state_of_game);
for(unit_map::iterator itor = units->begin(); itor != units->end(); ++itor) {
if(game_events::unit_matches_filter(itor,cfg)) {
itor->second.add_overlay(img);
@ -1084,7 +1084,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
std::string terrain_type = cfg["letter"];
wassert(state_of_game != NULL);
terrain_type = utils::interpolate_variables_into_string(terrain_type, *state_of_game);
for(std::vector<gamemap::location>::const_iterator loc = locs.begin(); loc != locs.end(); ++loc) {
preferences::encountered_terrains().insert(terrain_type);
if(terrain_type.size() > 0) {
@ -1286,7 +1286,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
std::string red_str = cfg["red"];
std::string green_str = cfg["green"];
std::string blue_str = cfg["blue"];
wassert(state_of_game != NULL);
text = utils::interpolate_variables_into_string(text, *state_of_game);
size_str = utils::interpolate_variables_into_string(size_str, *state_of_game);
@ -1294,7 +1294,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
red_str = utils::interpolate_variables_into_string(red_str, *state_of_game);
green_str = utils::interpolate_variables_into_string(green_str, *state_of_game);
blue_str = utils::interpolate_variables_into_string(blue_str, *state_of_game);
const int size = lexical_cast_default<int>(size_str,font::SIZE_SMALL);
const int lifetime = lexical_cast_default<int>(duration_str,50);
const int red = lexical_cast_default<int>(red_str,0);
@ -1319,11 +1319,11 @@ bool event_handler::handle_event_command(const queued_event& event_info,
//displaying a message dialog
else if(cmd == "message") {
unit_map::iterator speaker = units->end();
std::string speaker_str = cfg["speaker"];
wassert(state_of_game != NULL);
speaker_str = utils::interpolate_variables_into_string(speaker_str, *state_of_game);
if(speaker_str == "unit") {
speaker = units->find(event_info.loc1);
} else if(speaker_str == "second_unit") {
@ -1386,7 +1386,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
std::string msg_str = (*mi)["message"];
msg_str = utils::interpolate_variables_into_string(msg_str, *state_of_game);
options.push_back(msg_str);
option_events.push_back((*mi).get_children("command"));
}
@ -1589,10 +1589,10 @@ bool event_handler::handle_event_command(const queued_event& event_info,
units->erase(loc);
units->add(new std::pair<gamemap::location,unit>(loc,u));
std::string text = cfg["text"];
text = utils::interpolate_variables_into_string(text, *state_of_game);
if(!text.empty())
{
//Print floating label
@ -1775,7 +1775,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
cfg.get_attribute("text"), *state_of_game);
screen->labels().set_label(loc,text);
}
LOG_NG << "done handling command...\n";
return rval;
@ -1937,14 +1937,14 @@ bool process_event(event_handler& handler, const queued_event& ev)
//the event hasn't been filtered out, so execute the handler
const bool res = handler.handle_event(ev);
if(handler.rebuild_screen()) {
handler.rebuild_screen() = false;
screen->recalculate_minimap();
screen->invalidate_all();
screen->rebuild_all();
}
if(handler.first_time_only()) {
handler.disable();
}
@ -1966,7 +1966,7 @@ bool matches_special_filter(const config* cfg, const vconfig filter)
return false;
}
}
const vconfig::child_list& nots = filter.get_children("not");
for(vconfig::child_list::const_iterator i = nots.begin(); i != nots.end(); ++i) {
if(matches_special_filter(cfg,*i)) {
@ -2037,7 +2037,7 @@ manager::manager(const config& cfg, display& gui_, gamemap& map_,
status_ptr = &status;
used_items.clear();
const std::string& used = cfg["used_items"];
if(!used.empty()) {
const std::vector<std::string>& v = utils::split(used);
@ -2121,7 +2121,7 @@ bool pump()
return false;
bool result = false;
if(units != NULL) {
for(unit_map::const_iterator u_it = units->begin(); u_it != units->end(); ++u_it) {
if(std::find(unit_wml_ids.begin(),unit_wml_ids.end(),u_it->second.id()) == unit_wml_ids.end()) {

View file

@ -88,7 +88,7 @@ void parse_times(const config& cfg, std::vector<time_of_day>& normal_times)
for(t = times.begin(); t != times.end(); ++t) {
normal_times.push_back(time_of_day(**t));
}
}
}
@ -752,7 +752,7 @@ void game_state::clear_variable(const std::string& varname)
while(itor != key.end()) { // subvar access
std::string element=key.substr(0,dot_index);
key = key.substr(dot_index+1);
size_t index = 0;
const std::string::iterator index_start = std::find(element.begin(),element.end(),'[');
const bool explicit_index = index_start != element.end();
@ -767,7 +767,7 @@ void game_state::clear_variable(const std::string& varname)
}
element = std::string(element.begin(),index_start);
}
if(itor == key.end()) {
std::string last_element(key);
@ -819,7 +819,7 @@ void game_state::clear_variable(const std::string& varname)
}
key = std::string(key.begin(),index_start);
}
if(vars->get_children(key).size() <= index) {
return;
}

View file

@ -126,9 +126,9 @@ struct game_state : public variable_set
config& get_variable_cfg(const std::string& varname);
void set_variable(const std::string& varname, const t_string& value);
void clear_variable(const std::string& varname);
std::string difficulty; //the difficulty level the game is being played on.
//if the game is saved mid-level, we have a series of replay steps to

View file

@ -1,97 +1,97 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
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 "generic_event.hpp"
#include <algorithm>
namespace events{
observer::~observer() {
}
generic_event::generic_event(std::string name){
name_ = name;
change_handler_ = false;
notify_active_ = false;
}
generic_event::~generic_event() {
}
bool generic_event::attach_handler(observer* obs){
bool handler_attached = false;
//make sure observers are not notified right now
if (!notify_active_){
change_handler_ = true;
try{
std::vector<observer*>::const_iterator it = std::find(observers_.begin(), observers_.end(), obs);
if (it != observers_.end()){
handler_attached = false;
}
else{
observers_.push_back(obs);
handler_attached = true;
}
}
catch (std::exception&){
change_handler_ = false;
throw;
}
change_handler_ = false;
}
return handler_attached;
}
bool generic_event::detach_handler(observer* obs){
bool handler_detached = false;
//make sure observers are not notified right now
if (!notify_active_){
change_handler_ = true;
try{
std::vector<observer*>::iterator it = std::find(observers_.begin(), observers_.end(), obs);
if (it == observers_.end()){
handler_detached = false;
}
else{
observers_.erase(it);
handler_detached = true;
}
}
catch (std::exception&){
change_handler_ = false;
throw;
}
change_handler_ = false;
}
return handler_detached;
}
void generic_event::notify_observers(){
if (!change_handler_){
notify_active_ = true;
try{
for (std::vector<observer*>::const_iterator it = observers_.begin();
it != observers_.end(); it++){
(*it)->handle_generic_event(name_);
}
}
catch (std::exception&){
//reset the flag if event handlers throw exceptions and don't catch them
notify_active_ = false;
throw;
}
notify_active_ = false;
}
}
} //namespace events
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
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 "generic_event.hpp"
#include <algorithm>
namespace events{
observer::~observer() {
}
generic_event::generic_event(std::string name){
name_ = name;
change_handler_ = false;
notify_active_ = false;
}
generic_event::~generic_event() {
}
bool generic_event::attach_handler(observer* obs){
bool handler_attached = false;
//make sure observers are not notified right now
if (!notify_active_){
change_handler_ = true;
try{
std::vector<observer*>::const_iterator it = std::find(observers_.begin(), observers_.end(), obs);
if (it != observers_.end()){
handler_attached = false;
}
else{
observers_.push_back(obs);
handler_attached = true;
}
}
catch (std::exception&){
change_handler_ = false;
throw;
}
change_handler_ = false;
}
return handler_attached;
}
bool generic_event::detach_handler(observer* obs){
bool handler_detached = false;
//make sure observers are not notified right now
if (!notify_active_){
change_handler_ = true;
try{
std::vector<observer*>::iterator it = std::find(observers_.begin(), observers_.end(), obs);
if (it == observers_.end()){
handler_detached = false;
}
else{
observers_.erase(it);
handler_detached = true;
}
}
catch (std::exception&){
change_handler_ = false;
throw;
}
change_handler_ = false;
}
return handler_detached;
}
void generic_event::notify_observers(){
if (!change_handler_){
notify_active_ = true;
try{
for (std::vector<observer*>::const_iterator it = observers_.begin();
it != observers_.end(); it++){
(*it)->handle_generic_event(name_);
}
}
catch (std::exception&){
//reset the flag if event handlers throw exceptions and don't catch them
notify_active_ = false;
throw;
}
notify_active_ = false;
}
}
} //namespace events

View file

@ -1,67 +1,67 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
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.
*/
#ifndef GENERIC_EVENT_HPP_INCLUDED
#define GENERIC_EVENT_HPP_INCLUDED
#include "global.hpp"
#include <string>
#include <vector>
/*
This is the basic framework for generic events. In contrast to events.cpp
it does not concentrate on SDL events but events that wesnoth itself raises.
It is also different to game_events.cpp in that it does not work with
specific events but rather defines a generic framework.
*/
namespace events{
/*
This is the observer that gets notified, if a generic event takes place
Use this as base class for every class that is supposed to react on a
generic event.
*/
class observer{
public:
virtual void handle_generic_event(const std::string& event_name) = 0;
virtual ~observer();
};
/*
This is the class that notifies the observers and maintains a list of them.
*/
class generic_event{
public:
generic_event(std::string name);
virtual ~generic_event();
virtual bool attach_handler(observer* obs);
virtual bool detach_handler(observer* obs);
virtual void notify_observers();
private:
//Name of the event to help event handlers distinguish between several events
std::string name_;
//List of all subscribers waiting to react on this event
std::vector<observer*> observers_;
//This flag makes sure, that an event is not raised while the vector of
//observers is changed through attach_handler or detach_handler
bool change_handler_;
//This flag makes sure, that attaching/detaching event handlers does not
//take place during notify of observers to prevent iterator corruption.
bool notify_active_;
};
}
#endif
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
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.
*/
#ifndef GENERIC_EVENT_HPP_INCLUDED
#define GENERIC_EVENT_HPP_INCLUDED
#include "global.hpp"
#include <string>
#include <vector>
/*
This is the basic framework for generic events. In contrast to events.cpp
it does not concentrate on SDL events but events that wesnoth itself raises.
It is also different to game_events.cpp in that it does not work with
specific events but rather defines a generic framework.
*/
namespace events{
/*
This is the observer that gets notified, if a generic event takes place
Use this as base class for every class that is supposed to react on a
generic event.
*/
class observer{
public:
virtual void handle_generic_event(const std::string& event_name) = 0;
virtual ~observer();
};
/*
This is the class that notifies the observers and maintains a list of them.
*/
class generic_event{
public:
generic_event(std::string name);
virtual ~generic_event();
virtual bool attach_handler(observer* obs);
virtual bool detach_handler(observer* obs);
virtual void notify_observers();
private:
//Name of the event to help event handlers distinguish between several events
std::string name_;
//List of all subscribers waiting to react on this event
std::vector<observer*> observers_;
//This flag makes sure, that an event is not raised while the vector of
//observers is changed through attach_handler or detach_handler
bool change_handler_;
//This flag makes sure, that attaching/detaching event handlers does not
//take place during notify of observers to prevent iterator corruption.
bool notify_active_;
};
}
#endif

View file

@ -818,7 +818,7 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
std::back_inserter(sec.sections), create_section());
bool sort_topics = false;
bool sort_generated = true;
if ((*section_cfg)["sort_topics"] == "yes") {
sort_topics = true;
sort_generated = true; // Used for merge so not redundant
@ -833,10 +833,10 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
ss << "Invalid sort option: '" << (*section_cfg)["sort_topics"] << "'";
throw parse_error(ss.str());
}
const std::vector<std::string> topics_id = utils::quoted_split((*section_cfg)["topics"]);
std::vector<topic> topics;
// Find all topics in this section.
for (it = topics_id.begin(); it != topics_id.end(); it++) {
config const *topic_cfg = help_cfg->find_child("topic", "id", *it);
@ -858,13 +858,13 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
throw parse_error(ss.str());
}
}
const std::vector<topic> generated_topics =
generate_topics(sort_generated,(*section_cfg)["generator"]);
if (sort_topics) {
if (sort_topics) {
std::sort(topics.begin(),topics.end(), title_less());
std::merge(generated_topics.begin(),generated_topics.end()
,topics.begin(),topics.end()
,std::back_inserter(sec.topics),title_less());

View file

@ -171,7 +171,7 @@ void hotkey_item::load_from_config(const config& cfg)
keycode_ = num + SDLK_F1 - 1;
}
}
} else if (key == " " || shift_
} else if (key == " " || shift_
#ifdef __APPLE__
|| alt_
#endif

View file

@ -33,189 +33,189 @@ loadscreen::loadscreen(CVideo &screen, const int &percent):
prcnt_(percent)
{
std::string path = get_binary_file_location("images","misc/logo.png");
logo_surface_ = IMG_Load(path.c_str());
if (!logo_surface_) {
std::cerr << "loadscreen: Failed to load the logo: " << path << std::endl;
}
textarea_.x = textarea_.y = textarea_.w = textarea_.h = 0;
}
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 = 21, fcg = 53, fcb = 80; /* Finished piece. */
int lcr = 21, lcg = 22, lcb = 24; /* 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();
SDL_Rect area;
/* Draw logo if it was succesfully loaded. */
if (logo_surface_ && !logo_drawn_) {
area.x = (screen_.getx () - logo_surface_->w) / 2;
area.y = ((scry - logo_surface_->h) / 2) - pbh;
area.w = logo_surface_->w;
area.h = logo_surface_->h;
/* Check if we have enough pixels to display it. */
if (area.x > 0 && area.y > 0) {
pby_offset_ = (pbh + area.h)/2;
SDL_BlitSurface (logo_surface_, 0, gdis, &area);
}
else {
std::cerr << "loadscreen: Logo image is too big." << std::endl;
}
logo_drawn_ = true;
}
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;
}
}
logo_surface_ = IMG_Load(path.c_str());
if (!logo_surface_) {
std::cerr << "loadscreen: Failed to load the logo: " << path << std::endl;
}
textarea_.x = textarea_.y = textarea_.w = textarea_.h = 0;
}
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 = 21, fcg = 53, fcb = 80; /* Finished piece. */
int lcr = 21, lcg = 22, lcb = 24; /* 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();
SDL_Rect area;
/* Draw logo if it was succesfully loaded. */
if (logo_surface_ && !logo_drawn_) {
area.x = (screen_.getx () - logo_surface_->w) / 2;
area.y = ((scry - logo_surface_->h) / 2) - pbh;
area.w = logo_surface_->w;
area.h = logo_surface_->h;
/* Check if we have enough pixels to display it. */
if (area.x > 0 && area.y > 0) {
pby_offset_ = (pbh + area.h)/2;
SDL_BlitSurface (logo_surface_, 0, gdis, &area);
}
else {
std::cerr << "loadscreen: Logo image is too big." << std::endl;
}
logo_drawn_ = true;
}
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;
}
}

View file

@ -13,10 +13,10 @@
See the COPYING file for more details.
*/
#include "SDL.h"
#include "SDL.h"
#include "SDL_image.h"
#include "global.hpp"
#include "global.hpp"
#include "font.hpp"
#include "video.hpp"
@ -37,9 +37,9 @@ class loadscreen {
std::cerr << "loadscreen: binarywml counter = " << binarywml_counter << std::endl;
std::cerr << "loadscreen: setconfig counter = " << setconfig_counter << std::endl;
std::cerr << "loadscreen: parser counter = " << parser_counter << std::endl;
if (logo_surface_) {
SDL_FreeSurface (logo_surface_);
}
if (logo_surface_) {
SDL_FreeSurface (logo_surface_);
}
}
// Function to display a load progress bar.
@ -55,8 +55,8 @@ class loadscreen {
int setconfig_counter;
int parser_counter;
// A global loadscreen instance that can be used to avoid
// passing it on to functions that are many levels deep.
// A global loadscreen instance that can be used to avoid
// passing it on to functions that are many levels deep.
static loadscreen *global_loadscreen;
private:
// Prohibit default constructor
@ -64,9 +64,9 @@ class loadscreen {
// Data members
CVideo &screen_;
SDL_Rect textarea_;
SDL_Surface *logo_surface_;
bool logo_drawn_;
SDL_Rect textarea_;
SDL_Surface *logo_surface_;
bool logo_drawn_;
int pby_offset_;
int prcnt_;
};

View file

@ -387,7 +387,7 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
((xpos & 1) && (x1 & 1) ? 1 : 0);
if (y2 < 0 || y2 >= y()) {
continue;
}
}
const TERRAIN t = m[x1][y1];
const TERRAIN current = (*this)[x2][y2];
@ -573,7 +573,7 @@ bool gamemap::terrain_matches_filter(const gamemap::location& loc, const config&
}
}
}
static config const dummy_cfg;
time_of_day tod(dummy_cfg);
if(!tod_type.empty() || !tod_id.empty()) {
@ -613,7 +613,7 @@ bool gamemap::terrain_matches_filter(const gamemap::location& loc, const config&
}
}
}
return true;
}

View file

@ -1,16 +1,16 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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 "global.hpp"
#include "dialogs.hpp"
@ -88,7 +88,7 @@ namespace events{
menu_handler::menu_handler(display* gui, unit_map& units, std::vector<team>& teams,
const config& level, const game_data& gameinfo, const gamemap& map,
const config& game_config, const gamestatus& status, game_state& gamestate,
undo_list& undo_stack, undo_list& redo_stack) :
undo_list& undo_stack, undo_list& redo_stack) :
gui_(gui), units_(units), teams_(teams), level_(level), gameinfo_(gameinfo), map_(map),
game_config_(game_config), status_(status), gamestate_(gamestate), undo_stack_(undo_stack),
redo_stack_(redo_stack)
@ -507,7 +507,7 @@ namespace events{
void menu_handler::speak()
{
textbox_info_.show(gui::TEXTBOX_MESSAGE,_("Message:"),
textbox_info_.show(gui::TEXTBOX_MESSAGE,_("Message:"),
has_friends() ? _("Send to allies only") : "", preferences::message_private(), *gui_);
}
@ -732,7 +732,7 @@ namespace events{
i18n_symbols["cost"] = lexical_cast<std::string>(game_config::recall_cost);
msg << vgettext("You must have at least $cost gold pieces to recall a unit", i18n_symbols);
gui::show_dialog(*gui_,NULL,"",msg.str());
} else {
} else {
std::cerr << "recall index: " << res << "\n";
unit& un = recall_list[res];
gamemap::location loc = last_hex;
@ -1304,11 +1304,11 @@ namespace events{
//But since it makes the called method more generic, it is done anyway.
chat_handler::do_speak(textbox_info_.box()->text(),textbox_info_.check() != NULL ? textbox_info_.check()->checked() : false);
}
void menu_handler::add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type)
{
gui_->add_chat_message(speaker,side,message,type);
}
void menu_handler::add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type)
{
gui_->add_chat_message(speaker,side,message,type);
}
chat_handler::~chat_handler()
{
@ -1320,51 +1320,51 @@ namespace events{
return;
}
static const std::string query = "/query";
static const std::string query = "/query";
static const std::string whisper = "/whisper";
static const std::string whisper2 = "/msg";
static const std::string whisper2 = "/msg";
static const std::string ignore = "/ignore";
static const std::string help = "/help";
static const std::string emote = "/emote";
static const std::string emote2 = "/me";
static const std::string help = "/help";
static const std::string emote = "/emote";
static const std::string emote2 = "/me";
static const std::string add = "add";
static const std::string remove = "remove";
static const std::string list = "list";
static const std::string clear = "clear";
static const std::string help_chat_help = _("Commands: whisper ignore emote. Type /help [command] for more help.");
bool is_command = (message.at(0) == '/');
unsigned int argc = 0;
std::string cmd, arg1, arg2;
if(is_command){
std::string::size_type sp1 = message.find_first_of(' ');
cmd = message.substr(0,sp1);
if(sp1 != std::string::npos) {
std::string::size_type arg1_start = message.find_first_not_of(' ',sp1);
if(arg1_start != std::string::npos) {
++argc;
std::string::size_type substr_len, sp2;
sp2 = message.find(' ',arg1_start);
substr_len = (sp2 == std::string::npos) ? sp2 : sp2 - arg1_start;
arg1 = message.substr(arg1_start,substr_len);
if(sp2 != std::string::npos) {
std::string::size_type arg2_end = message.find_last_not_of(' ');
if(arg2_end > sp2) {
++argc;
arg2 = message.substr(sp2+1, arg2_end - sp2);
}
}
}
}
}
static const std::string clear = "clear";
if(cmd == query && argc > 0) {
const std::string args = (argc < 2) ? arg1 : arg1 + " " + arg2;
send_chat_query(args);
static const std::string help_chat_help = _("Commands: whisper ignore emote. Type /help [command] for more help.");
bool is_command = (message.at(0) == '/');
unsigned int argc = 0;
std::string cmd, arg1, arg2;
if(is_command){
std::string::size_type sp1 = message.find_first_of(' ');
cmd = message.substr(0,sp1);
if(sp1 != std::string::npos) {
std::string::size_type arg1_start = message.find_first_not_of(' ',sp1);
if(arg1_start != std::string::npos) {
++argc;
std::string::size_type substr_len, sp2;
sp2 = message.find(' ',arg1_start);
substr_len = (sp2 == std::string::npos) ? sp2 : sp2 - arg1_start;
arg1 = message.substr(arg1_start,substr_len);
if(sp2 != std::string::npos) {
std::string::size_type arg2_end = message.find_last_not_of(' ');
if(arg2_end > sp2) {
++argc;
arg2 = message.substr(sp2+1, arg2_end - sp2);
}
}
}
}
}
if(cmd == query && argc > 0) {
const std::string args = (argc < 2) ? arg1 : arg1 + " " + arg2;
send_chat_query(args);
} else if ((cmd == whisper || cmd == whisper2) && argc > 1 /*&& is_observer()*/) {
config cwhisper,data;
cwhisper["message"] = arg2;
@ -1372,70 +1372,70 @@ namespace events{
cwhisper["receiver"] = arg1;
data.add_child("whisper", cwhisper);
add_chat_message("whisper to "+cwhisper["receiver"],0,cwhisper["message"], display::MESSAGE_PRIVATE);
network::send_data(data);
network::send_data(data);
} else if (cmd == help) {
bool have_command = (argc > 0);
bool have_subcommand = (argc > 1);
const std::string command = arg1;
const std::string subcommand = arg2;
if (have_command) {
if (command == "whisper" || command == "msg") {
add_chat_message("help",0,_("Sends private message. You can't send messages to players that control any side in game. Usage: /whisper [nick] [message]"));
} else if (command == "ignore") {
if (have_subcommand) {
if (subcommand == "add"){
add_chat_message("help",0,_("Add player to your ignore list. Usage: /ignore add [argument]"));
} else if (subcommand == "remove") {
add_chat_message("help",0,_("Remove player from your ignore list. Usage: /ignore remove [argument]"));
} else if (subcommand == "clear") {
add_chat_message("help",0,_("Clear your ignore list. Usage: /ignore clear"));
} else if (subcommand == "list") {
add_chat_message("help",0,_("Show your ignore list. Usage: /ignore list"));
} else {
add_chat_message("help",0,_("Unknown subcommand"));
}
} else {
add_chat_message("help",0,_("Ignore messages from players on this list. Usage: /ignore [subcommand] [argument](optional) Subcommands: add remove list clear. Type /help ignore [subcommand] for more info."));
}
} else if (command == "emote" || command == "me") {
add_chat_message("help",0,_("Send an emotion or personal action in chat. Usage: /emote [message]"));
} else {
add_chat_message("help",0,_("Unknown command"));
}
} else {
add_chat_message("help",0,help_chat_help);
}
} else if (message.size() > ignore.size() && std::equal(ignore.begin(),ignore.end(), message.begin())) {
} else if (cmd == help) {
bool have_command = (argc > 0);
bool have_subcommand = (argc > 1);
const std::string command = arg1;
const std::string subcommand = arg2;
if (have_command) {
if (command == "whisper" || command == "msg") {
add_chat_message("help",0,_("Sends private message. You can't send messages to players that control any side in game. Usage: /whisper [nick] [message]"));
} else if (command == "ignore") {
if (have_subcommand) {
if (subcommand == "add"){
add_chat_message("help",0,_("Add player to your ignore list. Usage: /ignore add [argument]"));
} else if (subcommand == "remove") {
add_chat_message("help",0,_("Remove player from your ignore list. Usage: /ignore remove [argument]"));
} else if (subcommand == "clear") {
add_chat_message("help",0,_("Clear your ignore list. Usage: /ignore clear"));
} else if (subcommand == "list") {
add_chat_message("help",0,_("Show your ignore list. Usage: /ignore list"));
} else {
add_chat_message("help",0,_("Unknown subcommand"));
}
} else {
add_chat_message("help",0,_("Ignore messages from players on this list. Usage: /ignore [subcommand] [argument](optional) Subcommands: add remove list clear. Type /help ignore [subcommand] for more info."));
}
} else if (command == "emote" || command == "me") {
add_chat_message("help",0,_("Send an emotion or personal action in chat. Usage: /emote [message]"));
} else {
add_chat_message("help",0,_("Unknown command"));
}
} else {
add_chat_message("help",0,help_chat_help);
}
} else if (message.size() > ignore.size() && std::equal(ignore.begin(),ignore.end(), message.begin())) {
config* cignore;
if (arg1 == add){
if (!preferences::get_prefs()->child("ignore")){
preferences::get_prefs()->add_child("ignore");
}
cignore = preferences::get_prefs()->child("ignore");
if(utils::isvalid_username(arg2))
cignore = preferences::get_prefs()->child("ignore");
if(utils::isvalid_username(arg2))
{
(*cignore)[arg2] = "yes";
add_chat_message("ignores list",0, _("Added to ignore list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("ignores list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
add_chat_message("ignores list",0, _("Added to ignore list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("ignores list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
}
} else if (arg1 == remove){
if ((cignore = preferences::get_prefs()->child("ignore"))){
if(utils::isvalid_username(arg2))
{
if(utils::isvalid_username(arg2))
{
(*cignore)[arg2] = "no";
add_chat_message("ignores list",0, _("Removed from ignore list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("ignores list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
}
}
add_chat_message("ignores list",0, _("Removed from ignore list: ")+arg2,display::MESSAGE_PRIVATE);
} else {
add_chat_message("ignores list",0, _("Invalid username: ")+arg2,display::MESSAGE_PRIVATE);
}
}
} else if (arg1 == list){
std::string text;
if ((cignore = preferences::get_prefs()->child("ignore"))){
@ -1445,60 +1445,60 @@ namespace events{
text+=i->first+",";
}
}
if(!text.empty()){
text.erase(text.length()-1,1);
if(!text.empty()){
text.erase(text.length()-1,1);
}
}
}
add_chat_message("ignores list",0, text,display::MESSAGE_PRIVATE);
} else if (arg1 == clear){
if ((cignore = preferences::get_prefs()->child("ignore"))){
string_map::iterator nick;
for(nick= cignore->values.begin() ; nick!= cignore->values.end(); nick++) {
for(nick= cignore->values.begin() ; nick!= cignore->values.end(); nick++) {
if((*cignore)[nick->first] != "no") {
(*cignore)[nick->first] = "no";
add_chat_message("ignores list",0, _("Removed from ignore list: ")+nick->first,display::MESSAGE_PRIVATE);
add_chat_message("ignores list",0, _("Removed from ignore list: ")+nick->first,display::MESSAGE_PRIVATE);
}
}
}
} else {
add_chat_message("ignores list",0,_("Unknown command: ")+arg1,display::MESSAGE_PRIVATE);
}
} else {
add_chat_message("ignores list",0,_("Unknown command: ")+arg1,display::MESSAGE_PRIVATE);
}
} else if ((cmd == emote || cmd == emote2) && argc > 0) {
//emote message
send_chat_message("/me" + message.substr(cmd.size()), allies_only);
} else if (is_command) {
//command not accepted, show help chat help
add_chat_message("help",0,help_chat_help);
} else {
} else if ((cmd == emote || cmd == emote2) && argc > 0) {
//emote message
send_chat_message("/me" + message.substr(cmd.size()), allies_only);
} else if (is_command) {
//command not accepted, show help chat help
add_chat_message("help",0,help_chat_help);
} else {
//not a command, send as normal
send_chat_message(message, allies_only);
}
}
void menu_handler::send_chat_message(const std::string& message, bool allies_only)
{
config cfg;
cfg["description"] = preferences::login();
cfg["message"] = message;
const int side = is_observer() ? 0 : gui_->viewing_team()+1;
if(!is_observer()) {
cfg["side"] = lexical_cast<std::string>(side);
}
bool private_message = has_friends() && allies_only;
if(private_message) {
cfg["team_name"] = teams_[gui_->viewing_team()].team_name();
}
recorder.speak(cfg);
add_chat_message(cfg["description"],side,message,
private_message ? display::MESSAGE_PRIVATE : display::MESSAGE_PUBLIC);
}
}
void menu_handler::send_chat_message(const std::string& message, bool allies_only)
{
config cfg;
cfg["description"] = preferences::login();
cfg["message"] = message;
const int side = is_observer() ? 0 : gui_->viewing_team()+1;
if(!is_observer()) {
cfg["side"] = lexical_cast<std::string>(side);
}
bool private_message = has_friends() && allies_only;
if(private_message) {
cfg["team_name"] = teams_[gui_->viewing_team()].team_name();
}
recorder.speak(cfg);
add_chat_message(cfg["description"],side,message,
private_message ? display::MESSAGE_PRIVATE : display::MESSAGE_PUBLIC);
}
void menu_handler::do_search(const std::string& new_search)
@ -1582,13 +1582,13 @@ namespace events{
const size_t index = static_cast<size_t>(side - 1);
if (index >= teams_.size() || teams_[index].is_network()) {
//do nothing
} else if (teams_[index].is_human()) {
} else if (teams_[index].is_human()) {
//this is our side, so give it to AI
teams_[index].make_ai();
textbox_info_.close(*gui_);
if(team_num == side) {
//if it is our turn at the moment, we have to indicate to the
//play_controller, that we are no longer in control
if(team_num == side) {
//if it is our turn at the moment, we have to indicate to the
//play_controller, that we are no longer in control
throw end_turn_exception(side);
}
} else if (teams_[index].is_ai()) {
@ -1598,23 +1598,23 @@ namespace events{
preferences::show_theme_dialog(*gui_);
} else if(cmd == "ban" || cmd == "kick") {
config cfg;
config& ban = cfg.add_child(cmd);
ban["username"] = data;
config& ban = cfg.add_child(cmd);
ban["username"] = data;
network::send_data(cfg);
network::send_data(cfg);
} else if (cmd == "mute") {
config cfg;
config& mute = cfg.add_child(cmd);
if (!data.empty()) {
mute["username"] = data;
}
network::send_data(cfg);
} else if (cmd == "muteall") {
config cfg;
cfg.add_child(cmd);
network::send_data(cfg);
config cfg;
config& mute = cfg.add_child(cmd);
if (!data.empty()) {
mute["username"] = data;
}
network::send_data(cfg);
} else if (cmd == "muteall") {
config cfg;
cfg.add_child(cmd);
network::send_data(cfg);
} else if(cmd == "control") {
const std::string::const_iterator j = std::find(data.begin(),data.end(),' ');
if(j != data.end()) {
@ -1627,18 +1627,18 @@ namespace events{
return;
}
if(side_num > 0 && side_num <= teams_.size()) {
if(teams_[static_cast<size_t>(side_num - 1)].is_human()) {
if(teams_[static_cast<size_t>(side_num - 1)].is_human()) {
//if this is our side we are always allowed to change the controller
change_side_controller(side,player,true);
teams_[static_cast<size_t>(side_num - 1)].make_network();
textbox_info_.close(*gui_);
if(team_num == side_num) {
//if it is our turn at the moment, we have to indicate to the
teams_[static_cast<size_t>(side_num - 1)].make_network();
textbox_info_.close(*gui_);
if(team_num == side_num) {
//if it is our turn at the moment, we have to indicate to the
//play_controller, that we are no longer in control
throw end_turn_exception(side_num);
}
} else {
//it is not our side, the server will decide if we can change the
} else {
//it is not our side, the server will decide if we can change the
//controller (that is if we are host of the game)
change_side_controller(side,player);
}
@ -1647,7 +1647,7 @@ namespace events{
} else if(cmd == "clear") {
gui_->clear_chat_messages();
} else if(cmd == "w") {
save_game(data,gui::NULL_DIALOG);
save_game(data,gui::NULL_DIALOG);
} else if(cmd == "wq") {
save_game(data,gui::NULL_DIALOG);
throw end_level_exception(QUIT);

View file

@ -1,16 +1,16 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef MENU_EVENTS_H_INCLUDED
#define MENU_EVENTS_H_INCLUDED
@ -39,20 +39,20 @@ struct end_turn_exception {
unsigned int redo;
};
namespace events{
class chat_handler {
public:
chat_handler() {}
namespace events{
class chat_handler {
public:
chat_handler() {}
virtual ~chat_handler();
protected:
void do_speak(const std::string& message, bool allies_only=false);
//called from do_speak
virtual void add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type=display::MESSAGE_PRIVATE)=0;
virtual void send_chat_message(const std::string& message, bool allies_only=false)=0;
virtual void send_chat_query(const std::string& /*args*/) {}
protected:
void do_speak(const std::string& message, bool allies_only=false);
//called from do_speak
virtual void add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type=display::MESSAGE_PRIVATE)=0;
virtual void send_chat_message(const std::string& message, bool allies_only=false)=0;
virtual void send_chat_query(const std::string& /*args*/) {}
};
class menu_handler : private chat_handler {
@ -102,19 +102,19 @@ public:
unit_map::iterator current_unit(mouse_handler& mousehandler);
unit_map::const_iterator current_unit(const mouse_handler& mousehandler) const;
void move_unit_to_loc(const unit_map::const_iterator& ui, const gamemap::location& target,
void move_unit_to_loc(const unit_map::const_iterator& ui, const gamemap::location& target,
bool continue_move, const unsigned int team_num, mouse_handler& mousehandler);
void do_speak();
void do_search(const std::string& new_search);
void do_command(const std::string& str, const unsigned int team_num, mouse_handler& mousehandler);
void clear_undo_stack(const unsigned int team_num);
void clear_undo_stack(const unsigned int team_num);
void autosave(unsigned turn, const config &starting_pos) const;
protected:
void add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type=display::MESSAGE_PRIVATE);
void send_chat_message(const std::string& message, bool allies_only=false);
protected:
void add_chat_message(const std::string& speaker, int side, const std::string& message, display::MESSAGE_TYPE type=display::MESSAGE_PRIVATE);
void send_chat_message(const std::string& message, bool allies_only=false);
private:
//void do_speak(const std::string& message, bool allies_only);
//void do_speak(const std::string& message, bool allies_only);
void do_recruit(const std::string& name, const unsigned int team_num, const gamemap::location& last_hex);
std::vector<std::string> create_unit_table(const statistics::stats::str_int_map& m);
void write_game_snapshot(config& start) const;

View file

@ -55,23 +55,23 @@ namespace{
class battle_prediction_pane : public gui::preview_pane
{
public:
// Lengthy constructor.
battle_prediction_pane(display &disp, const battle_context& bc, const gamemap& map,
const std::vector<team>& teams, const unit_map& units,
const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc);
// This method is called to draw the dialog contents.
void draw_contents();
// Hack: pretend the preview pane goes to the left.
bool left_side() const { return 1; }
// Unused.
void set_selection(int) {}
private:
private:
display &disp_;
const battle_context& bc_;
const gamemap& map_;
@ -83,7 +83,7 @@ namespace{
const gamemap::location& defender_loc_;
const unit& attacker_;
const unit& defender_;
// Layout constants.
static const int inter_line_gap_;
static const int inter_column_gap_;
@ -108,14 +108,14 @@ namespace{
int attacker_width_, defender_width_, units_width_;
int dialog_width_, dialog_height_;
// This method builds the strings describing the unit damage modifiers.
// Read the code to understand the arguments.
void get_unit_strings(const battle_context::unit_stats& stats,
const unit& u, const gamemap::location& u_loc, float u_unscathed,
const unit& opp, const gamemap::location& opp_loc, const attack_type *opp_weapon,
std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
int& left_strings_width, int& right_strings_width, int& strings_width);
const unit& u, const gamemap::location& u_loc, float u_unscathed,
const unit& opp, const gamemap::location& opp_loc, const attack_type *opp_weapon,
std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
int& left_strings_width, int& right_strings_width, int& strings_width);
// Utility method that returns the length of the longest string in a vector of strings.
int get_strings_max_length(const std::vector<std::string>& strings);
@ -138,18 +138,18 @@ namespace{
// This method draws the image of the hitpoints distribution of a
// combatant after a fight. The method takes as input the
// "hp_prob_vector" computed above and the stats of the combatants.
// It draws the image in the surface 'surf' and set the width and
// It draws the image in the surface 'surf' and set the width and
// height of the image in the fields specified.
void get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
const battle_context::unit_stats& stats,
void get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
const battle_context::unit_stats& stats,
const battle_context::unit_stats& opp_stats,
surface& surf, int& width, int& height);
// This method blends a RGB color. The method takes as input a surface,
// the RGB color to blend and a value specifying how much blending to
// apply. The blended color is returned. Caution: if you use a
// apply. The blended color is returned. Caution: if you use a
// transparent color, make sure the resulting color is not equal to the
// transparent color.
// transparent color.
Uint32 blend_rgb(const surface& surf, unsigned char r, unsigned char g, unsigned char b, unsigned char drop);
};
@ -159,9 +159,9 @@ namespace{
const int battle_prediction_pane::max_hp_distrib_rows_ = 10;
battle_prediction_pane::battle_prediction_pane(display &disp, const battle_context& bc, const gamemap& map,
const std::vector<team>& teams, const unit_map& units,
const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc)
const gamemap::location& attacker_loc, const gamemap::location& defender_loc)
: gui::preview_pane(disp.video()), disp_(disp), bc_(bc), map_(map), teams_(teams), units_(units), status_(status),
gamedata_(gamedata), attacker_loc_(attacker_loc), defender_loc_(defender_loc),
attacker_(units.find(attacker_loc)->second), defender_(units.find(defender_loc)->second)
@ -181,8 +181,8 @@ namespace{
attacker_hp_distrib_width_, attacker_hp_distrib_height_);
get_hp_prob_vector(defender_combatant.hp_dist, hp_prob_vector);
get_hp_distrib_surface(hp_prob_vector, defender_stats, attacker_stats, defender_hp_distrib_,
defender_hp_distrib_width_, defender_hp_distrib_height_);
hp_distribs_height_ = maximum<int>(attacker_hp_distrib_height_, defender_hp_distrib_height_);
defender_hp_distrib_width_, defender_hp_distrib_height_);
hp_distribs_height_ = maximum<int>(attacker_hp_distrib_height_, defender_hp_distrib_height_);
// Build the strings and compute the layout.
std::stringstream str;
@ -194,9 +194,9 @@ namespace{
// Get the units strings.
get_unit_strings(attacker_stats, attacker_, attacker_loc_, attacker_combatant.untouched,
defender_, defender_loc_, defender_stats.weapon,
attacker_left_strings_, attacker_right_strings_,
attacker_left_strings_width_, attacker_right_strings_width_, attacker_strings_width_);
defender_, defender_loc_, defender_stats.weapon,
attacker_left_strings_, attacker_right_strings_,
attacker_left_strings_width_, attacker_right_strings_width_, attacker_strings_width_);
get_unit_strings(defender_stats, defender_, defender_loc_, defender_combatant.untouched,
attacker_, attacker_loc_, attacker_stats.weapon,
@ -225,15 +225,15 @@ namespace{
}
void battle_prediction_pane::get_unit_strings(const battle_context::unit_stats& stats,
const unit& u, const gamemap::location& u_loc, float u_unscathed,
const unit& opp, const gamemap::location& opp_loc, const attack_type *opp_weapon,
const unit& u, const gamemap::location& u_loc, float u_unscathed,
const unit& opp, const gamemap::location& opp_loc, const attack_type *opp_weapon,
std::vector<std::string>& left_strings, std::vector<std::string>& right_strings,
int& left_strings_width, int& right_strings_width, int& strings_width)
int& left_strings_width, int& right_strings_width, int& strings_width)
{
std::stringstream str;
char str_buf[10];
// With a weapon.
// With a weapon.
if(stats.weapon != NULL) {
// Set specials context (for safety, it should not have changed normally).
@ -266,7 +266,7 @@ namespace{
str << set_dmg_effect->value;
right_strings.push_back(str.str());
}
// Process the ADD damage modifiers.
for(i = dmg_effect.begin(); i != dmg_effect.end(); ++i) {
if(i->type == unit_abilities::ADD) {
@ -312,7 +312,7 @@ namespace{
left_strings.push_back(_("Slowed"));
right_strings.push_back("* 0.5");
}
// Time of day modifier.
int tod_modifier = combat_modifier(status_, units_, u_loc, u.alignment(), map_);
if(tod_modifier != 0) {
@ -322,9 +322,9 @@ namespace{
right_strings.push_back(str.str());
}
// Leadership bonus.
int leadership_bonus = 0;
under_leadership(units_, u_loc, &leadership_bonus);
// Leadership bonus.
int leadership_bonus = 0;
under_leadership(units_, u_loc, &leadership_bonus);
if(leadership_bonus != 0) {
left_strings.push_back(_("Leadership"));
str.str("");
@ -405,13 +405,13 @@ namespace{
{
// We must align both damage lines.
int damage_line_skip = maximum<int>(attacker_left_strings_.size(), defender_left_strings_.size()) - 2;
draw_unit(0, damage_line_skip,
attacker_left_strings_width_, attacker_left_strings_, attacker_right_strings_,
attacker_label_, attacker_label_width_, attacker_hp_distrib_, attacker_hp_distrib_width_);
draw_unit(0, damage_line_skip,
attacker_left_strings_width_, attacker_left_strings_, attacker_right_strings_,
attacker_label_, attacker_label_width_, attacker_hp_distrib_, attacker_hp_distrib_width_);
draw_unit(units_width_ + inter_units_gap_, damage_line_skip,
defender_left_strings_width_, defender_left_strings_, defender_right_strings_,
defender_left_strings_width_, defender_left_strings_, defender_right_strings_,
defender_label_, defender_label_width_, defender_hp_distrib_, defender_hp_distrib_width_);
}
@ -424,11 +424,11 @@ namespace{
CVideo& screen = disp_.video();
int i;
// NOTE. A preview pane is not made to be used alone and it is not
// NOTE. A preview pane is not made to be used alone and it is not
// centered in the middle of the dialog. We "fix" this problem by moving
// the clip rectangle 10 pixels to the right. This is a kludge and it
// should be removed by 1) writing a custom dialog handler, or
// 2) modify preview_pane so that it accepts {left, middle, right} as
// 2) modify preview_pane so that it accepts {left, middle, right} as
// layout possibilities.
// Get clip rectangle and center it
@ -454,7 +454,7 @@ namespace{
clip_rect.x + x_off + left_strings_width + inter_column_gap_,
clip_rect.y + y_off + (font::SIZE_NORMAL + inter_line_gap_) * i, 0, TTF_STYLE_NORMAL);
}
// Ensure both damage lines are aligned.
y_off += damage_line_skip * (font::SIZE_NORMAL + inter_line_gap_) + 14;
@ -471,7 +471,7 @@ namespace{
clip_rect.x + x_off + left_strings_width + inter_column_gap_,
clip_rect.y + y_off + (font::SIZE_NORMAL + inter_line_gap_) * i, 0, TTF_STYLE_NORMAL);
}
y_off += 2 * (font::SIZE_NORMAL + inter_line_gap_) + 14;
// Draw hitpoints distribution string.
@ -484,7 +484,7 @@ namespace{
video().blit_surface(clip_rect.x + x_off + (units_width_ - hp_distrib_width) / 2, clip_rect.y + y_off, hp_distrib);
}
void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<int, double> >& hp_prob_vector,
const battle_context::unit_stats& stats,
const battle_context::unit_stats& opp_stats,
surface& surf, int& width, int& height)
@ -507,11 +507,11 @@ namespace{
// Create the surface.
surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
image::pixel_format->BitsPerPixel,
image::pixel_format->Rmask,
image::pixel_format->Gmask,
image::pixel_format->Bmask,
image::pixel_format->Amask);
image::pixel_format->BitsPerPixel,
image::pixel_format->Rmask,
image::pixel_format->Gmask,
image::pixel_format->Bmask,
image::pixel_format->Amask);
SDL_Rect clip_rect = {0, 0, width, height};
Uint32 grey_color = SDL_MapRGB(surf->format, 0xb7, 0xc1, 0xc1);
@ -549,7 +549,7 @@ namespace{
double prob = hp_prob_vector[hp_prob_vector.size() - i - 1].second;
SDL_Color row_color;
// Death line is red.
if(hp == 0) {
SDL_Color color = {0xe5, 0, 0, 0};
@ -608,10 +608,10 @@ namespace{
str_buf[9] = '\0'; //prevents _snprintf error
int prob_width = font::line_width(str_buf, fs);
font::draw_text_line(surf, clip_rect, fs, font::NORMAL_COLOUR, str_buf,
width - prob_width - 4, 2 + (fs + 2) * i, 0, TTF_STYLE_NORMAL);
width - prob_width - 4, 2 + (fs + 2) * i, 0, TTF_STYLE_NORMAL);
}
}
Uint32 battle_prediction_pane::blend_rgb(const surface& surf, unsigned char r, unsigned char g, unsigned char b, unsigned char drop)
{
// We simply decrement each component.
@ -621,16 +621,16 @@ namespace{
return SDL_MapRGB(surf->format, r, g, b);
}
// This class is used when the user clicks on the button
// to show the "Damage Calculations" dialog.
class attack_prediction_displayer : public gui::dialog_button_action
{
public:
attack_prediction_displayer(display& disp, const std::vector<battle_context>& bc_vector, const gamemap& map,
const std::vector<team>& teams, const unit_map& units,
const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc)
const gamemap::location& attacker_loc, const gamemap::location& defender_loc)
: disp_(disp), bc_vector_(bc_vector), map_(map), teams_(teams), units_(units), status_(status),
gamedata_(gamedata), attacker_loc_(attacker_loc), defender_loc_(defender_loc) {}
@ -656,7 +656,7 @@ namespace{
display &disp_;
const std::vector<battle_context>& bc_vector_;
const gamemap& map_;
const std::vector<team>& teams_;
const std::vector<team>& teams_;
const unit_map& units_;
const gamestatus& status_;
const game_data& gamedata_;
@ -786,7 +786,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse)
unit_map::iterator un = find_unit(new_hex);
if(un != units_.end() && un->second.side() != team_num_ &&
if(un != units_.end() && un->second.side() != team_num_ &&
current_paths_.routes.empty() && !(*gui_).fogged(un->first.x,un->first.y)) {
unit_movement_resetter move_reset(un->second);
@ -1230,7 +1230,7 @@ bool mouse_handler::attack_enemy(unit_map::iterator attacker, unit_map::iterator
attack_prediction_displayer ap_displayer(*gui_, bc_vector, map_, teams_, units_, status_, gameinfo_, attacker_loc, defender_loc);
std::vector<gui::dialog_button> buttons;
buttons.push_back(gui::dialog_button(&ap_displayer, _("Damage Calculations")));
int res = 0;
{
@ -1409,9 +1409,9 @@ void mouse_handler::cycle_back_units()
}
}
void mouse_handler::set_current_paths(paths new_paths) {
void mouse_handler::set_current_paths(paths new_paths) {
gui_->unhighlight_reach();
current_paths_ = new_paths;
current_paths_ = new_paths;
current_route_.steps.clear();
gui_->set_route(NULL);
}

View file

@ -1,16 +1,16 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playturn Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef MOUSE_EVENTS_H_INCLUDED
#define MOUSE_EVENTS_H_INCLUDED
@ -34,7 +34,7 @@ struct command_disabler
class mouse_handler{
public:
mouse_handler(display* gui, std::vector<team>& teams, unit_map& units, gamemap& map,
mouse_handler(display* gui, std::vector<team>& teams, unit_map& units, gamemap& map,
gamestatus& status, const game_data& gameinfo, undo_list& undo_stack, undo_list& redo_stack);
void mouse_motion(const SDL_MouseMotionEvent& event, const int player_number, const bool browse);
void mouse_press(const SDL_MouseButtonEvent& event, const int player_number, const bool browse);
@ -51,7 +51,7 @@ public:
void set_path_turns(const int path_turns) { path_turns_ = path_turns; }
void set_current_paths(paths new_paths);
void set_selected_hex(gamemap::location hex) { selected_hex_ = hex; }
void set_gui(display* gui) { gui_ = gui; }
void set_gui(display* gui) { gui_ = gui; }
void set_undo(const bool undo) { undo_ = undo; }
unit_map::iterator selected_unit();

View file

@ -408,7 +408,7 @@ void enter_lobby_mode(display& disp, const config& game_config, game_data& data,
preferences::show_preferences_dialog(disp,game_config);
disp.redraw_everything();
}
break;
break;
default:
return;
}

View file

@ -1148,7 +1148,7 @@ void connect::load_game()
} else {
level_ = params_.scenario_data;
level_["hash"] = level_.hash();
level_["turns"] = lexical_cast_default<std::string>(params_.num_turns, "20");
level_["mp_countdown"] = params_.mp_countdown ? "yes" : "no";

View file

@ -454,7 +454,7 @@ void create::process_event()
nsides--;
}
}
std::stringstream players;
if(map.get() != NULL) {
players << _("Players: ") << nsides;

View file

@ -569,7 +569,7 @@ void lobby::process_event()
set_result(PREFERENCES);
return;
}
if(quit_game_.pressed()) {
recorder.set_skip(false);
set_result(QUIT);

View file

@ -66,7 +66,7 @@ private:
image::locator vision_icon_locator_;
image::locator time_limit_icon_locator_;
image::locator observer_icon_locator_;
const config* map_hashes_;
unsigned int item_height_;

View file

@ -266,7 +266,7 @@ void ui::send_chat_query(const std::string& args)
void ui::add_chat_message(const std::string& speaker, int /*side*/, const std::string& message, display::MESSAGE_TYPE /*type*/)
{
chat_.add_message(speaker,message);
chat_.add_message(speaker,message);
chat_.update_textbox(chat_textbox_);
}
@ -316,7 +316,7 @@ void ui::handle_key_event(const SDL_KeyboardEvent& event)
std::vector<std::string>& users = user_list_;
std::sort<std::vector<std::string>::iterator>(users.begin(), users.end());
for(std::vector<std::string>::const_iterator i = users.begin(); i != users.end(); ++i) {
if( i->size() >= semiword.size() &&
if( i->size() >= semiword.size() &&
std::equal(semiword.begin(),semiword.end(),i->begin(),chars_equal_insensitive)) {
if(matches.empty()) {
best_match = *i;
@ -369,18 +369,18 @@ void ui::process_network_data(const config& data, const network::connection /*so
}
}
}
if (!ignored){
sound::play_sound(game_config::sounds::receive_message);
chat_.add_message(msg["sender"], msg["message"]);
chat_.update_textbox(chat_textbox_);
}
}
if(data.child("whisper")){
sound::play_sound(game_config::sounds::receive_message);
const config& cwhisper = *data.child("whisper");
chat_.add_message("whisper: "+cwhisper["sender"], cwhisper["message"]);
chat_.update_textbox(chat_textbox_);

View file

@ -254,7 +254,7 @@ void wait::join_game(bool observe)
response["leader"] = leader_choice;
network::send_data(response);
}
}
generate_menu();
}
@ -279,7 +279,7 @@ void wait::start_game()
game_state& wait::request_snapshot(){
config cfg;
cfg.add_child("snapshot_request");
return state_;
@ -352,11 +352,11 @@ void wait::generate_menu()
const config::child_list& sides = level_.get_children("side");
for(config::child_list::const_iterator s = sides.begin(); s != sides.end(); ++s) {
const config& sd = **s;
if(sd["allow_player"] == "no") {
continue;
}
std::string description = sd["user_description"];
const std::string faction_id = sd["id"];

View file

@ -21,15 +21,15 @@
#define LOG_NG LOG_STREAM(info, engine)
play_controller::play_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
play_controller::play_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
int ticks, int num_turns, const config& game_config, CVideo& video,
bool skip_replay) :
bool skip_replay) :
verify_manager_(units_), team_manager_(teams_), labels_manager_(),
help_manager_(&game_config, &gameinfo, &map_),
mouse_handler_(gui_, teams_, units_, map_, status_, gameinfo, undo_stack_, redo_stack_),
menu_handler_(gui_, units_, teams_, level, gameinfo, map_, game_config, status_, state_of_game, undo_stack_, redo_stack_),
generator_setter(&recorder), statistics_context_(level["name"]), gameinfo_(gameinfo), level_(level), game_config_(game_config),
gamestate_(state_of_game), status_(level, num_turns),
gamestate_(state_of_game), status_(level, num_turns),
map_(game_config, level["map_data"]), ticks_(ticks),
xp_mod_(atoi(level["experience_modifier"].c_str()) > 0 ? atoi(level["experience_modifier"].c_str()) : 100),
loading_game_(level["playing_team"].empty() == false),
@ -295,7 +295,7 @@ void play_controller::init_side(const unsigned int team_index){
std::stringstream player_number_str;
player_number_str << player_number_;
gamestate_.set_variable("side_number",player_number_str.str());
if(first_turn_) {
if(gui_->viewing_team() == team_index && !team_manager_.is_observer()) {
recorder.add_event("turn 1");
@ -526,7 +526,7 @@ void play_controller::handle_event(const SDL_Event& event)
//intentionally fall-through
case SDL_KEYUP:
//if the user has pressed 1 through 9, we want to show how far
//the unit can move in that many turns
if(event.key.keysym.sym >= '1' && event.key.keysym.sym <= '7') {
@ -548,7 +548,7 @@ void play_controller::handle_event(const SDL_Event& event)
}
}
}
break;
case SDL_MOUSEMOTION:
// ignore old mouse motion events in the event queue

View file

@ -39,7 +39,7 @@
class play_controller : public hotkey::command_executor, public events::handler, public events::observer
{
public:
play_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
play_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
int ticks, int num_turns, const config& game_config, CVideo& video, bool skip_replay);
~play_controller();

View file

@ -1,16 +1,16 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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 "playmp_controller.hpp"
#include "game_errors.hpp"
@ -30,7 +30,7 @@ LEVEL_RESULT playmp_scenario(const game_data& gameinfo, const config& game_confi
return playcontroller.play_scenario(story, log, skip_replay);
}
playmp_controller::playmp_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
playmp_controller::playmp_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
const int ticks, const int num_turns, const config& game_config, CVideo& video,
bool skip_replay)
: playsingle_controller(level, gameinfo, state_of_game, ticks, num_turns, game_config, video, skip_replay)
@ -67,7 +67,7 @@ void playmp_controller::before_human_turn(){
turn_data_ = new turn_info(gameinfo_,gamestate_,status_,
*gui_,map_,teams_,player_number_,units_,replay_sender_, undo_stack_);
turn_data_->replay_error().attach_handler(this);
turn_data_->replay_error().attach_handler(this);
menu_handler_.autosave(status_.turn(), gamestate_.starting_pos);
}
@ -75,7 +75,7 @@ void playmp_controller::before_human_turn(){
void playmp_controller::play_human_turn(){
int cur_ticks = SDL_GetTicks();
gui_->enable_menu("endturn", true);
gui_->enable_menu("endturn", true);
while(!end_turn_) {
try {
@ -83,13 +83,13 @@ void playmp_controller::play_human_turn(){
const network::connection res = network::receive_data(cfg);
std::deque<config> backlog;
if(res != network::null_connection) {
if(res != network::null_connection) {
try{
turn_data_->process_network_data(cfg,res,backlog,skip_replay_);
}
catch (replay::error& e){
process_oos();
throw e;
turn_data_->process_network_data(cfg,res,backlog,skip_replay_);
}
catch (replay::error& e){
process_oos();
throw e;
}
}
@ -115,7 +115,7 @@ void playmp_controller::play_human_turn(){
// Clock time ended
// If no turn bonus or action bonus -> defeat
const int action_increment = lexical_cast_default<int>(level_["mp_countdown_action_bonus"],0);
if ( lexical_cast_default<int>(level_["mp_countdown_turn_bonus"],0) == 0
if ( lexical_cast_default<int>(level_["mp_countdown_turn_bonus"],0) == 0
&& (action_increment == 0 || current_team().action_bonus_count() == 0)) {
// Not possible to end level in MP with throw end_level_exception(DEFEAT);
// because remote players only notice network disconnection
@ -129,10 +129,10 @@ void playmp_controller::play_human_turn(){
secs = (secs > maxtime) ? maxtime : secs;
current_team().set_countdown_time(1000 * secs);
}
recorder.add_countdown_update(current_team().countdown_time(),player_number_);
recorder.end_turn();
turn_data_->send_data();
throw end_turn_exception();
recorder.add_countdown_update(current_team().countdown_time(),player_number_);
recorder.end_turn();
turn_data_->send_data();
throw end_turn_exception();
}
}
@ -142,25 +142,25 @@ void playmp_controller::play_human_turn(){
turn_data_->send_data();
}
menu_handler_.clear_undo_stack(player_number_);
menu_handler_.clear_undo_stack(player_number_);
}
void playmp_controller::after_human_turn(){
if ( level_["mp_countdown"] == "yes" ){
const int action_increment = lexical_cast_default<int>(level_["mp_countdown_action_bonus"],0);
const int maxtime = lexical_cast_default<int>(level_["mp_countdown_reservoir_time"],0);
int secs = (current_team().countdown_time() / 1000) + lexical_cast_default<int>(level_["mp_countdown_turn_bonus"],0);
secs += action_increment * current_team().action_bonus_count();
current_team().set_action_bonus_count(0);
secs = (secs > maxtime) ? maxtime : secs;
current_team().set_countdown_time(1000 * secs);
const int action_increment = lexical_cast_default<int>(level_["mp_countdown_action_bonus"],0);
const int maxtime = lexical_cast_default<int>(level_["mp_countdown_reservoir_time"],0);
int secs = (current_team().countdown_time() / 1000) + lexical_cast_default<int>(level_["mp_countdown_turn_bonus"],0);
secs += action_increment * current_team().action_bonus_count();
current_team().set_action_bonus_count(0);
secs = (secs > maxtime) ? maxtime : secs;
current_team().set_countdown_time(1000 * secs);
recorder.add_countdown_update(current_team().countdown_time(),player_number_);
}
//send one more time to make sure network is up-to-date.
turn_data_->send_data();
if (turn_data_ != NULL){
turn_data_->replay_error().detach_handler(this);
turn_data_->replay_error().detach_handler(this);
delete turn_data_;
turn_data_ = NULL;
}
@ -178,16 +178,16 @@ void playmp_controller::finish_side_turn(){
}
bool playmp_controller::play_network_turn(){
if(teams_[player_number_ - 1].is_empty() && team_units(units_,player_number_) == 0) {
return false;
}
if(teams_[player_number_ - 1].is_empty() && team_units(units_,player_number_) == 0) {
return false;
}
LOG_NG << "is networked...\n";
browse_ = true;
gui_->enable_menu("endturn", false);
gui_->enable_menu("endturn", false);
turn_info turn_data(gameinfo_,gamestate_,status_,*gui_,
map_,teams_,player_number_,units_, replay_sender_, undo_stack_);
map_,teams_,player_number_,units_, replay_sender_, undo_stack_);
turn_data.replay_error().attach_handler(this);
for(;;) {
@ -206,23 +206,23 @@ bool playmp_controller::play_network_turn(){
have_data = from != network::null_connection;
}
if(have_data) {
if(have_data) {
try{
const turn_info::PROCESS_DATA_RESULT result = turn_data.process_network_data(cfg,from,data_backlog_,skip_replay_);
if(result == turn_info::PROCESS_RESTART_TURN) {
return true;
} else if(result == turn_info::PROCESS_END_TURN) {
break;
}
}
catch (replay::error e){
process_oos();
throw e;
}
const turn_info::PROCESS_DATA_RESULT result = turn_data.process_network_data(cfg,from,data_backlog_,skip_replay_);
if(result == turn_info::PROCESS_RESTART_TURN) {
return true;
} else if(result == turn_info::PROCESS_END_TURN) {
break;
}
}
catch (replay::error e){
process_oos();
throw e;
}
}
else{
skip_replay_ = false;
}
else{
skip_replay_ = false;
}
play_slice();
@ -230,31 +230,31 @@ bool playmp_controller::play_network_turn(){
gui_->draw();
}
turn_data.replay_error().detach_handler(this);
turn_data.replay_error().detach_handler(this);
LOG_NG << "finished networked...\n";
return false;
}
void playmp_controller::process_oos(){
menu_handler_.save_game(_("The games are out of sync and will have to exit. Do you want to save an error log of your game?"),gui::YES_NO);
}
void playmp_controller::handle_generic_event(const std::string& name){
turn_info turn_data(gameinfo_,gamestate_,status_,*gui_,
map_,teams_,player_number_,units_, replay_sender_, undo_stack_);
if (name == "ai_user_interact"){
playsingle_controller::handle_generic_event(name);
turn_data.send_data();
}
else if ((name == "ai_unit_recruited") || (name == "ai_unit_moved")
|| (name == "ai_enemy_attacked")){
turn_data.sync_network();
}
else if (name == "network_replay_error"){
process_oos();
}
}
void playmp_controller::process_oos(){
menu_handler_.save_game(_("The games are out of sync and will have to exit. Do you want to save an error log of your game?"),gui::YES_NO);
}
void playmp_controller::handle_generic_event(const std::string& name){
turn_info turn_data(gameinfo_,gamestate_,status_,*gui_,
map_,teams_,player_number_,units_, replay_sender_, undo_stack_);
if (name == "ai_user_interact"){
playsingle_controller::handle_generic_event(name);
turn_data.send_data();
}
else if ((name == "ai_unit_recruited") || (name == "ai_unit_moved")
|| (name == "ai_enemy_attacked")){
turn_data.sync_network();
}
else if (name == "network_replay_error"){
process_oos();
}
}
bool playmp_controller::can_execute_command(hotkey::HOTKEY_COMMAND command) const
{

View file

@ -1,15 +1,15 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef PLAYMP_CONTROLLER_H_INCLUDED
#define PLAYMP_CONTROLLER_H_INCLUDED
@ -24,12 +24,12 @@
class playmp_controller : public playsingle_controller
{
public:
playmp_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
playmp_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
const int ticks, const int num_turns, const config& game_config, CVideo& video, bool skip_replay);
protected:
virtual void handle_generic_event(const std::string& name);
virtual void handle_generic_event(const std::string& name);
virtual void speak();
virtual void clear_labels();
virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command) const;
@ -38,13 +38,13 @@ protected:
virtual void before_human_turn();
virtual void play_human_turn();
virtual void after_human_turn();
virtual void finish_side_turn();
virtual void finish_side_turn();
bool play_network_turn();
turn_info* turn_data_;
int beep_warning_time_;
private:
private:
void process_oos();
};

File diff suppressed because it is too large Load diff

View file

@ -1,15 +1,15 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef PLAYSINGLE_CONTROLLER_H_INCLUDED
#define PLAYSINGLE_CONTROLLER_H_INCLUDED
@ -29,13 +29,13 @@
class playsingle_controller : public play_controller
{
public:
playsingle_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
playsingle_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
const int ticks, const int num_turns, const config& game_config, CVideo& video, bool skip_replay);
LEVEL_RESULT play_scenario(const std::vector<config*>& story, upload_log& log, bool skip_replay);
virtual void handle_generic_event(const std::string& name);
virtual void handle_generic_event(const std::string& name);
virtual void recruit();
virtual void repeat_recruit();
virtual void recall();
@ -50,7 +50,7 @@ public:
virtual void continue_move();
virtual void unit_hold_position();
virtual void end_unit_turn();
virtual void user_command();
virtual void user_command();
void playsingle_slice();
@ -60,7 +60,7 @@ protected:
virtual void before_human_turn();
virtual void play_human_turn();
virtual void after_human_turn();
void play_ai_turn();
void play_ai_turn();
virtual void init_gui();
void check_time_over();

View file

@ -71,7 +71,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
{
if(cfg.child("whisper") != NULL && is_observer()){
sound::play_sound(game_config::sounds::receive_message);
const config& cwhisper = *cfg.child("whisper");
gui_.add_chat_message("whisper: "+cwhisper["sender"],0,cwhisper["message"], display::MESSAGE_PRIVATE);
}

View file

@ -44,7 +44,7 @@ namespace preferences {
// low-level, should be seen only by preferences_display ?
void set(std::string key, std::string value);
std::string get(const std::string key);
config* get_prefs();
bool fullscreen();

View file

@ -364,7 +364,7 @@ void preferences_dialog::join()
sound_label_.join();
scroll_label_.join();
gamma_label_.join();
chat_lines_label_.join();
chat_lines_label_.join();
advanced_.join();
}

View file

@ -669,8 +669,8 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
continue;
}
}
//if there is nothing more in the records
if(cfg == NULL) {
//replayer.set_skip(false);
@ -734,7 +734,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
else if((child = cfg->child("recruit")) != NULL) {
const std::string& recruit_num = (*child)["value"];
const int val = atoi(recruit_num.c_str());
gamemap::location loc(*child);
const std::set<std::string>& recruits = current_team.recruits();

View file

@ -1,16 +1,16 @@
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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 "global.hpp"
#include "ai_interface.hpp"
@ -44,8 +44,8 @@ LEVEL_RESULT play_replay_level(const game_data& gameinfo, const config& game_con
const int num_turns = atoi((*level)["turns"].c_str());
LOG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << "\n";
replay_controller replaycontroller(*level, gameinfo, state_of_game, ticks, num_turns, game_config, video);
LOG_NG << "created objects... " << (SDL_GetTicks() - replaycontroller.get_ticks()) << "\n";
const events::command_disabler disable_commands;
LOG_NG << "created objects... " << (SDL_GetTicks() - replaycontroller.get_ticks()) << "\n";
const events::command_disabler disable_commands;
//replay event-loop
for (;;){
@ -62,9 +62,9 @@ LEVEL_RESULT play_replay_level(const game_data& gameinfo, const config& game_con
replay_controller::replay_controller(const config& level, const game_data& gameinfo, game_state& state_of_game,
const int ticks, const int num_turns, const config& game_config,
CVideo& video)
: play_controller(level, gameinfo, state_of_game, ticks, num_turns, game_config, video, false),
: play_controller(level, gameinfo, state_of_game, ticks, num_turns, game_config, video, false),
gamestate_start_(state_of_game), status_start_(level, num_turns)
{
{
current_turn_ = 1;
delay_ = 0;
is_playing_ = false;
@ -89,7 +89,7 @@ void replay_controller::init(){
fire_prestart(true);
init_gui();
LOG_NG << "first_time..." << (recorder.is_skipping() ? "skipping" : "no skip") << "\n";
fire_start(!loading_game_);
@ -141,17 +141,17 @@ const bool replay_controller::is_loading_game(){
void replay_controller::reset_replay(){
is_playing_ = false;
player_number_ = 1;
player_number_ = 1;
current_turn_ = 1;
recorder.start_replay();
units_ = *(new unit_map(units_start_));
status_ = *(new gamestatus(status_start_));
gamestate_ = *(new game_state(gamestate_start_));
teams_ = team_manager_.clone(teams_start_);
if (events_manager_ != NULL){
delete events_manager_;
events_manager_ = new game_events::manager(level_,*gui_,map_,units_,teams_,
gamestate_,status_,gameinfo_);
teams_ = team_manager_.clone(teams_start_);
if (events_manager_ != NULL){
delete events_manager_;
events_manager_ = new game_events::manager(level_,*gui_,map_,units_,teams_,
gamestate_,status_,gameinfo_);
}
(*gui_).invalidate_all();
(*gui_).draw();
@ -170,11 +170,11 @@ void replay_controller::replay_next_turn(){
void replay_controller::replay_next_side(){
is_playing_ = true;
play_side(player_number_ - 1);
if ((size_t)player_number_ > teams_.size()) {
player_number_ = 1;
current_turn_++;
}
if ((size_t)player_number_ > teams_.size()) {
player_number_ = 1;
current_turn_++;
}
is_playing_ = false;
}
@ -208,7 +208,7 @@ void replay_controller::play_replay(){
is_playing_ = true;
LOG_NG << "starting main loop\n" << (SDL_GetTicks() - ticks_) << "\n";
for(; !recorder.at_end() && is_playing_; first_player_ = 1
for(; !recorder.at_end() && is_playing_; first_player_ = 1
) {
play_turn();
play_slice();
@ -230,9 +230,9 @@ void replay_controller::play_turn(){
while ( ((size_t)player_number_ <= teams_.size()) && (!recorder.at_end()) ){
play_side(player_number_ - 1);
}
player_number_ = 1;
current_turn_++;
player_number_ = 1;
current_turn_++;
}
void replay_controller::play_side(const unsigned int team_index){
@ -261,7 +261,7 @@ void replay_controller::play_side(const unsigned int team_index){
if ((size_t)player_number_ > teams_.size()) {
status_.next_turn();
finish_turn();
finish_turn();
}
update_teams();
update_gui();

View file

@ -1,17 +1,17 @@
/* $Id: replay_controller.hpp 7396 2005-07-02 21:37:20Z ott $ */
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
/*
Copyright (C) 2006 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
wesnoth playlevel Copyright (C) 2003 by David White <davidnwhite@verizon.net>
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.
*/
#ifndef REPLAY_CONTROLLER_H_INCLUDED
#define REPLAY_CONTROLLER_H_INCLUDED
@ -23,7 +23,7 @@
#include "help.hpp"
#include "hotkeys.hpp"
#include "menu_events.hpp"
#include "mouse_events.hpp"
#include "mouse_events.hpp"
#include "play_controller.hpp"
#include "preferences_display.hpp"
#include "tooltips.hpp"
@ -38,14 +38,14 @@ public:
const int ticks, const int num_turns, const config& game_config, CVideo& video);
~replay_controller();
virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command) const;
virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command) const;
std::vector<team>& get_teams();
unit_map get_units();
display& get_gui();
gamemap& get_map();
const gamestatus& get_status();
const int get_player_number();
const int get_player_number();
const bool is_loading_game();
//event handlers
@ -58,10 +58,10 @@ public:
void replay_switch_shroud();
void replay_skip_animation();
std::vector<team> teams_start_;
protected:
virtual void init_gui();
std::vector<team> teams_start_;
protected:
virtual void init_gui();
private:
void init();
@ -73,7 +73,7 @@ private:
game_state& gamestate_start_;
gamestatus status_start_;
unit_map units_start_;
unsigned int current_turn_;
int delay_;
bool is_playing_;

View file

@ -232,9 +232,9 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
int swarm_min_attacks = swarm.highest("attacks_min").first;
int hitp = u->second.hitpoints();
int mhitp = u->second.max_hitpoints();
nattacks = swarm_min_attacks + swarm_max_attacks * hitp / mhitp;
} else {
nattacks = at_it->num_attacks();
}
@ -286,9 +286,9 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
res.add_text(str,tooltip);
const std::vector<std::string>& specials = at_it->special_tooltips();
if(! specials.empty()) {
for(std::vector<std::string>::const_iterator sp_it = specials.begin(); sp_it != specials.end(); ++sp_it) {
str << "<166,146,117> ";

View file

@ -117,7 +117,7 @@ public:
const user_vector all_game_users() const;
const player* find_player(network::connection sock) const;
const player* transfer_game_control();
private:
@ -149,7 +149,7 @@ private:
std::vector<bool> sides_taken_;
std::vector<std::string> side_controllers_;
bool started_;
config level_;
config history_;

View file

@ -130,11 +130,11 @@ private:
metrics metrics_;
const config& cfg_;
size_t default_max_messages_;
size_t default_time_period_;
size_t concurrent_connections_;
std::set<std::string> accepted_versions_;
std::map<std::string,config> redirected_versions_;
std::map<std::string,config> proxy_versions_;
@ -158,7 +158,7 @@ server::server(int port, input_stream& input, const config& cfg, size_t nthreads
version_query_response_.add_child("version");
login_response_.add_child("mustlogin");
if(cfg_["disallow_names"] == "") {
disallowed_names_.push_back("server");
disallowed_names_.push_back("ai");
@ -173,7 +173,7 @@ server::server(int port, input_stream& input, const config& cfg, size_t nthreads
default_max_messages_ = lexical_cast_default<int>(cfg_["max_messages"],4);
default_time_period_ = lexical_cast_default<int>(cfg_["messages_time_period"],10);
concurrent_connections_ = lexical_cast_default<int>(cfg_["connections_allowed"],5);
const std::string& versions = cfg_["versions_accepted"];
if(versions.empty() == false) {
const std::vector<std::string> accepted(utils::split(versions));
@ -505,7 +505,7 @@ void server::process_login(const network::connection sock, const config& data)
const config* const version = data.child("version");
if(version != NULL) {
const std::string& version_str = (*version)["version"];
bool accepted = false;
for(std::set<std::string>::const_iterator ver_it = accepted_versions_.begin(); ver_it != accepted_versions_.end(); ++ver_it) {
if(utils::wildcard_string_match(version_str,*ver_it)) {
@ -587,7 +587,7 @@ void server::process_login(const network::connection sock, const config& data)
"This username is too long"),sock);
return;
}
for(std::vector<std::string>::const_iterator d_it = disallowed_names_.begin(); d_it != disallowed_names_.end(); ++d_it) {
if(utils::wildcard_string_match(utils::lowercase(username),utils::lowercase(*d_it))) {
network::send_data(construct_error(
@ -684,7 +684,7 @@ void server::process_whisper(const network::connection sock, const config& whisp
std::vector<game>::iterator g;
if ((whisper["receiver"]!="") && (whisper["message"]!="") && (whisper["sender"]!="")){
for(player_map::const_iterator i = players_.begin(); i != players_.end(); ++i) {
if(i->second.name() == whisper["receiver"]) {
if(i->second.name() == whisper["receiver"]) {
for(g = games_.begin(); g != games_.end(); ++g) {
if(g->is_member(i->first)) {
do_send = false;
@ -701,16 +701,16 @@ void server::process_whisper(const network::connection sock, const config& whisp
break;
}
}
} else {
} else {
config msg;
config data;
msg["message"] = "Invalid number of arguments";
msg["sender"] = "server";
data.add_child("message", msg);
network::send_data(data,sock);
network::send_data(data,sock);
sent = true;
}
if (sent == false){
config msg;
config data;
@ -721,7 +721,7 @@ void server::process_whisper(const network::connection sock, const config& whisp
}
msg["sender"] = "server";
data.add_child("message", msg);
network::send_data(data,sock);
network::send_data(data,sock);
}
}
@ -734,7 +734,7 @@ void server::process_data_from_player_in_lobby(const network::connection sock, c
if(pl == players_.end()) {
std::cerr << "ERROR: Could not find player in map\n";
}
if(create_game != NULL) {
//std::cerr << "creating game...\n";
@ -907,7 +907,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
if (player != NULL){
const config& msg = construct_server_message("You have been muted",*g);
network::send_data(msg, pl->first);
const config& p_msg = construct_server_message(pl->second.name() + " has been muted",*g);
g->send_data(p_msg, pl->first);
}
@ -961,7 +961,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
g->ban_player(pl->first);
const config& msg = construct_server_message("You have been banned",*g);
network::send_data(msg, pl->first);
const config& p_msg = construct_server_message(pl->second.name() + " has been banned",*g);
g->send_data(p_msg);
} else {
@ -1172,7 +1172,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
} else {
std::cerr << "ERROR: Could not find player in map\n";
}
if (needed){
//transfer game control to another player
const player* player = g->transfer_game_control();
@ -1190,7 +1190,7 @@ void server::process_data_from_player_in_game(const network::connection sock, co
std::cerr << "ERROR: Could not find player in map\n";
}
lobby_players_.add_player(sock);
//send the player who has quit the game list
network::send_data(initial_response_,sock);

View file

@ -100,7 +100,7 @@ bool track_ok(const std::string &name)
// Timothy Pinkham says:
// 1) can't be repeated without 2 other pieces have already played
// since A was played.
// 2) cannot play more than 2 times without every other piece
// 2) cannot play more than 2 times without every other piece
// having played at least 1 time.
// Dammit, if our musicians keep coming up with algorithms, I'll
@ -423,7 +423,7 @@ void write_music_play_list(config& snapshot)
append = true;
}
}
void play_sound(const std::string& files)
{
if(preferences::sound_on() && mix_ok) {

View file

@ -44,7 +44,7 @@ void play_no_music();
// Start playing current music.
void play_music();
// Play sound, or random one of comma-separated sounds.
// Play sound, or random one of comma-separated sounds.
void play_sound(const std::string& files);
// Called from event loop to see if we need new music track.

View file

@ -58,7 +58,7 @@ namespace statistics
~disabler();
};
struct scenario_context
{
scenario_context(const std::string& name);

View file

@ -528,7 +528,7 @@ theme::menu::menu() : context_(false)
theme::menu::menu(const config& cfg) : object(cfg), context_(cfg["is_context_menu"] == "true"),
title_(cfg["title"].str() + cfg["title_literal"].str()),
tooltip_(cfg["tooltip"]),
tooltip_(cfg["tooltip"]),
image_(cfg["image"]), type_(cfg["type"]),
items_(utils::split(cfg["items"]))
{}

File diff suppressed because it is too large Load diff

View file

@ -79,8 +79,8 @@ unit::unit(const unit& u)
}
// Initilizes a unit from a config
unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
const gamestatus* game_status, const std::vector<team>* teams,const config& cfg) :
unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
const gamestatus* game_status, const std::vector<team>* teams,const config& cfg) :
movement_(0), hold_position_(false),resting_(false),state_(STATE_STANDING),
facing_(gamemap::location::NORTH_EAST),flying_(false),
anim_(NULL),unit_halo_(0),unit_anim_halo_(0),draw_bars_(false),gamedata_(gamedata), units_(unitmap), map_(map),
@ -124,9 +124,9 @@ unit_race::GENDER unit::generate_gender(const unit_type& type, bool gen)
}
// Initilizes a unit from a unit type
unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
const gamestatus* game_status, const std::vector<team>* teams, const unit_type* t,
int side, bool use_traits, bool dummy_unit, unit_race::GENDER gender) :
unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
const gamestatus* game_status, const std::vector<team>* teams, const unit_type* t,
int side, bool use_traits, bool dummy_unit, unit_race::GENDER gender) :
gender_(dummy_unit ? gender : generate_gender(*t,use_traits)), resting_(false), state_(STATE_STANDING), facing_(gamemap::location::NORTH_EAST),draw_bars_(false),
gamedata_(gamedata),units_(unitmap),map_(map),gamestatus_(game_status),teams_(teams)
{
@ -155,7 +155,7 @@ unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
unit_halo_ = 0;
unit_anim_halo_ = 0;
}
unit::unit(const unit_type* t, int side, bool use_traits, bool dummy_unit, unit_race::GENDER gender) :
unit::unit(const unit_type* t, int side, bool use_traits, bool dummy_unit, unit_race::GENDER gender) :
gender_(dummy_unit ? gender : generate_gender(*t,use_traits)),state_(STATE_STANDING),facing_(gamemap::location::NORTH_EAST),draw_bars_(false),
gamedata_(NULL), units_(NULL),map_(NULL),gamestatus_(NULL),teams_(NULL)
{
@ -220,7 +220,7 @@ void unit::generate_traits()
{
if(!traits_description_.empty())
return;
wassert(gamedata_ != NULL);
const game_data::unit_type_map::const_iterator type = gamedata_->unit_types.find(id());
//calculate the unit's traits
@ -256,16 +256,16 @@ void unit::advance_to(const unit_type* t)
cfg_.clear_children("abilities");
// clear cache of movement costs
movement_costs_.clear();
if(t->movement_type().get_parent()) {
cfg_ = cfg_.merge_with(t->movement_type().get_parent()->get_cfg());
}
cfg_ = cfg_.merge_with(t->cfg_);
cfg_.clear_children("male");
cfg_.clear_children("female");
advances_to_ = t->advances_to();
race_ = t->race_;
language_name_ = t->language_name();
cfg_["unit_description"] = t->unit_description();
@ -281,7 +281,7 @@ void unit::advance_to(const unit_type* t)
attacks_ = t->attacks();
unit_value_ = t->cost();
flying_ = t->movement_type().is_flying();
max_attacks_ = lexical_cast_default<int>(t->cfg_["attacks"],1);
defensive_animations_ = t->defensive_animations_;
teleport_animations_ = t->teleport_animations_;
@ -291,7 +291,7 @@ void unit::advance_to(const unit_type* t)
standing_animations_ = t->standing_animations_;
leading_animations_ = t->leading_animations_;
flag_rgb_ = t->flag_rgb();
backup_state();
//apply modifications etc, refresh the unit
apply_modifications();
@ -300,7 +300,7 @@ void unit::advance_to(const unit_type* t)
id_ = t->id();
cfg_["id"] = id_;
}
set_state("poisoned","");
set_state("slowed","");
set_state("stoned","");
@ -734,7 +734,7 @@ bool unit::matches_filter(const config& cfg,const gamemap::location& loc,bool us
if(speaker.empty() == false && speaker != this->underlying_description()) {
return false;
}
const config* filter_location = cfg.child("filter_location");
if(filter_location) {
wassert(map_ != NULL);
@ -745,7 +745,7 @@ bool unit::matches_filter(const config& cfg,const gamemap::location& loc,bool us
return false;
}
}
const std::string& this_type = id();
//the type could be a comma-seperated list of types
@ -862,14 +862,14 @@ void unit::read(const config& cfg)
}
validate_side(side_);
/* prevent un-initialized variables */
max_hit_points_=1;
hit_points_=1;
max_movement_=0;
max_experience_=0;
/* */
const std::string& gender = cfg["gender"];
if(gender == "female") {
gender_ = unit_race::FEMALE;
@ -878,12 +878,12 @@ void unit::read(const config& cfg)
}
variation_ = cfg["variation"];
wassert(gamedata_ != NULL);
description_ = cfg["description"];
custom_unit_description_ = cfg["user_description"];
std::string custom_unit_desc = cfg["unit_description"];
underlying_description_ = cfg["description"];
if(description_.empty()) {
description_ = underlying_description_;
@ -901,25 +901,25 @@ void unit::read(const config& cfg)
} else {
variables_.clear();
}
advances_to_ = utils::split(cfg["advances_to"]);
if(advances_to_.size() == 1 && advances_to_.front() == "") {
advances_to_.clear();
}
name_ = cfg["name"];
language_name_ = cfg["language_name"];
undead_variation_ = cfg["undead_variation"];
flag_rgb_ = string2rgb(cfg["flag_rgb"]);
alpha_ = lexical_cast_default<fixed_t>(cfg["alpha"]);
level_ = lexical_cast_default<int>(cfg["level"]);
unit_value_ = lexical_cast_default<int>(cfg["value"]);
facing_ = gamemap::location::parse_direction(cfg["facing"]);
if(facing_ == gamemap::location::NDIRECTIONS) facing_ = gamemap::location::NORTH_EAST;
recruits_ = utils::split(cfg["recruits"]);
if(recruits_.size() == 1 && recruits_.front() == "") {
recruits_.clear();
@ -937,7 +937,7 @@ void unit::read(const config& cfg)
modifications_ = *mods;
cfg_.remove_child("modifications",0);
}
bool type_set = false;
id_ = "";
if(cfg["type"] != "" && cfg["type"] != cfg["id"]) {
@ -1005,7 +1005,7 @@ void unit::read(const config& cfg)
if(status_flags) {
for(string_map::const_iterator st = status_flags->values.begin(); st != status_flags->values.end(); ++st) {
states_[st->first] = st->second;
// backwards compatibility
if(st->first == "stone") {
states_["stoned"] = st->second;
@ -1052,7 +1052,7 @@ void unit::read(const config& cfg)
custom_unit_description_ = generate_description();
cfg_["generate_description"] = "";
}
if(!type_set) {
const config::child_list& defends = cfg_.get_children("defend");
for(config::child_list::const_iterator d = defends.begin(); d != defends.end(); ++d) {
@ -1156,7 +1156,7 @@ void unit::write(config& cfg) const
for(std::map<std::string,std::string>::const_iterator st = states_.begin(); st != states_.end(); ++st) {
status_flags[st->first] = st->second;
}
cfg.clear_children("variables");
cfg.add_child("variables",variables_);
cfg.clear_children("status");
@ -1171,7 +1171,7 @@ void unit::write(config& cfg) const
cfg["canrecruit"] = "1";
cfg["facing"] = gamemap::location::write_direction(facing_);
cfg["goto_x"] = lexical_cast_default<std::string>(goto_.x+1);
cfg["goto_y"] = lexical_cast_default<std::string>(goto_.y+1);
@ -1179,9 +1179,9 @@ void unit::write(config& cfg) const
cfg["max_moves"] = lexical_cast_default<std::string>(max_movement_b_);
cfg["resting"] = resting_ ? "yes" : "no";
cfg["advances_to"] = utils::join(advances_to_);
cfg["race"] = race_->name();
cfg["name"] = name_;
cfg["language_name"] = language_name_;
@ -1215,7 +1215,7 @@ void unit::write(config& cfg) const
cfg["flag_rgb"] = flg_rgb.str();
cfg["unrenamable"] = unrenamable_ ? "yes" : "no";
cfg["alpha"] = lexical_cast_default<std::string>(alpha_);
cfg["recuits"] = utils::join(recruits_);
cfg["attacks_left"] = lexical_cast_default<std::string>(attacks_left_);
cfg["max_attacks"] = lexical_cast_default<std::string>(max_attacks_);
@ -1234,7 +1234,7 @@ void unit::write(config& cfg) const
cfg.add_child("modifications_description",mod_desc);
cfg.clear_children("modifications");
cfg.add_child("modifications",modifications_);
}
void unit::assign_role(const std::string& role)
@ -1297,7 +1297,7 @@ void unit::set_defending(const display &disp,const gamemap::location& loc, int d
hit_type = fighting_animation::MISS;
}
anim_ = new defensive_animation(defend_animation(disp.get_map().underlying_union_terrain(loc),hit_type,attack));
// add a blink on damage effect
int anim_time = anim_->get_last_frame_time();
const std::string my_image = anim_->get_last_frame().image;
@ -1334,10 +1334,10 @@ const unit_animation & unit::set_attacking(const display &disp,const gamemap::lo
{
state_ = STATE_ATTACKING;
draw_bars_ = false;
if(anim_) {
delete anim_;
anim_ = NULL;
}
if(anim_) {
delete anim_;
anim_ = NULL;
}
const attack_type::attack_animation &attack_anim = type.animation(hit,facing_) ;
anim_ = new unit_animation(attack_anim.animation);
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
@ -1377,7 +1377,7 @@ void unit::set_leveling_in(const display &disp,const gamemap::location& loc)
blend_ratio -=0.015;
anim_time += 10;
}
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
frame_begin_time = anim_->get_first_frame_time() -1;
anim_->update_current_frame();
@ -1401,7 +1401,7 @@ void unit::set_leveling_out(const display &disp,const gamemap::location& loc)
blend_ratio +=0.015;
anim_time += 10;
}
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
frame_begin_time = anim_->get_first_frame_time() -1;
anim_->update_current_frame();
@ -1536,7 +1536,7 @@ void unit::set_healing(const display &disp,const gamemap::location& loc)
void unit::set_walking(const display &disp,const gamemap::location& loc)
{
movement_animation* const anim = dynamic_cast<movement_animation*>(anim_);
movement_animation* const anim = dynamic_cast<movement_animation*>(anim_);
if(state_ == STATE_WALKING && anim != NULL && anim->matches(disp.get_map().underlying_union_terrain(loc),facing_) >=0) {
return; // finish current animation, don't start a new one
}
@ -1563,7 +1563,7 @@ void unit::restart_animation(const display& disp,int start_time) {
void unit::redraw_unit(display& disp,gamemap::location hex)
{
const gamemap & map = disp.get_map();
if(hidden_) {
if(hidden_) {
if(unit_halo_) halo::remove(unit_halo_);
unit_halo_ = 0;
if(unit_anim_halo_) halo::remove(unit_anim_halo_);
@ -1665,9 +1665,9 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
blend_ratio = 0.25;
}
surface ellipse_front(NULL);
surface ellipse_back(NULL);
if(preferences::show_side_colours() && draw_bars_) {
@ -1682,14 +1682,14 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
std::string ellipse=image_ellipse();
if(ellipse.empty()){
ellipse="misc/ellipse";
}
}
snprintf(buf,sizeof(buf),"%s-%stop.png",ellipse.c_str(),selected);
ellipse_back.assign(image::get_image(image::locator(buf,team_rgb_range(),temp_rgb)));
snprintf(buf,sizeof(buf),"%s-%sbottom.png",ellipse.c_str(),selected);
ellipse_front.assign(image::get_image(image::locator(buf,team_rgb_range(),temp_rgb)));
}
disp.draw_unit(x, y -height_adjust, image, false, highlight_ratio,
disp.draw_unit(x, y -height_adjust, image, false, highlight_ratio,
blend_with, blend_ratio, submerge,ellipse_back,ellipse_front);
if(!unit_halo_ && !image_halo().empty()) {
unit_halo_ = halo::add(0,0,image_halo());
@ -1831,12 +1831,12 @@ int unit::movement_cost(gamemap::TERRAIN terrain, int recurse_count) const
{
const int impassable = 10000000;
int slowed = utils::string_bool(get_state("slowed")) ? 2 : 1;
const std::map<gamemap::TERRAIN,int>::const_iterator i = movement_costs_.find(terrain);
if(i != movement_costs_.end()) {
return i->second * slowed;
}
wassert(map_ != NULL);
//if this is an alias, then select the best of all underlying terrains
const std::string& underlying = map_->underlying_mvt_terrain(terrain);
@ -1992,7 +1992,7 @@ bool unit::resistance_filter_matches(const config& cfg,bool attacker,const attac
int unit::resistance_against(const attack_type& damage_type,bool attacker,const gamemap::location& loc) const
{
int res = 100;
const std::string& damage_name = damage_type.type();
const config* const resistance = cfg_.child("resistance");
if(resistance != NULL) {
@ -2001,7 +2001,7 @@ int unit::resistance_against(const attack_type& damage_type,bool attacker,const
res = 100 - lexical_cast_default<int>(val);
}
}
unit_ability_list resistance_abilities = get_abilities("resistance",loc);
for(std::vector<std::pair<config*,gamemap::location> >::iterator i = resistance_abilities.cfgs.begin(); i != resistance_abilities.cfgs.end();) {
if(!resistance_filter_matches(*i->first,attacker,damage_type)) {
@ -2012,7 +2012,7 @@ int unit::resistance_against(const attack_type& damage_type,bool attacker,const
}
if(!resistance_abilities.empty()) {
unit_abilities::effect resist_effect(resistance_abilities,res,false);
res = minimum<int>(resist_effect.get_composite_value(),resistance_abilities.highest("max_value").first);
}
return 100 - res;
@ -2128,12 +2128,12 @@ config::child_list unit::get_modification_advances() const
bool requirements_done=true;
for(std::vector<std::string>::const_iterator ii = uniq.begin(); ii != uniq.end(); ii++){
int required_num = std::count(temp.begin(),temp.end(),*ii);
int mod_num = modification_count("advance",*ii);
if(required_num>mod_num){
requirements_done=false;
}
}
if(requirements_done){
int mod_num = modification_count("advance",*ii);
if(required_num>mod_num){
requirements_done=false;
}
}
if(requirements_done){
res.push_back(*i);
}
}else{
@ -2165,9 +2165,9 @@ void mod_mdr_merge(config& dst, const config& mod, bool delta)
string_map::const_iterator iter = mod.values.begin();
string_map::const_iterator end = mod.values.end();
for (; iter != end; iter++) {
dst[iter->first] =
dst[iter->first] =
lexical_cast_default<std::string>(
(delta == true)*lexical_cast_default<int>(dst[iter->first])
(delta == true)*lexical_cast_default<int>(dst[iter->first])
+ lexical_cast_default<int>(iter->second)
);
}
@ -2236,7 +2236,7 @@ void unit::add_modification(const std::string& type, const config& mod,
//if the hitpoints are allowed to end up greater than max hitpoints
const std::string& violate_max = (**i.first)["violate_maximum"];
if(set_hp.empty() == false) {
if(set_hp[set_hp.size()-1] == '%') {
hit_points_ = lexical_cast_default<int>(set_hp)*max_hit_points_/100;
@ -2251,7 +2251,7 @@ void unit::add_modification(const std::string& type, const config& mod,
max_hit_points_ = lexical_cast_default<int>(set_total);
}
}
if(increase_total.empty() == false) {
description += (increase_total[0] != '-' ? "+" : "") + increase_total +
" " + t_string(N_("HP"), "wesnoth");

View file

@ -32,15 +32,15 @@ class gamestatus;
class unit_ability_list
{
public:
bool empty() const;
std::pair<int,gamemap::location> highest(const std::string& key, int def=0) const;
std::pair<int,gamemap::location> lowest(const std::string& key, int def=100) const;
std::vector<std::pair<config*,gamemap::location> > cfgs;
private:
};
@ -57,14 +57,14 @@ class unit
unit(const unit_type* t, int side, bool use_traits=false, bool dummy_unit=false, unit_race::GENDER gender=unit_race::MALE);
unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map, const gamestatus* game_status, const std::vector<team>* teams, const unit_type* t, int side, bool use_traits=false, bool dummy_unit=false, unit_race::GENDER gender=unit_race::MALE);
virtual ~unit();
void set_game_context(const game_data* gamedata, unit_map* unitmap, const gamemap* map, const gamestatus* game_status, const std::vector<team>* teams);
void write_checksum(std::string& str) const;
// Advances this unit to another type
void advance_to(const unit_type* t);
const std::vector<std::string> advances_to() const;
// the current type id
const std::string& id() const;
const unit_type& type() const;
@ -80,9 +80,9 @@ class unit
const std::string& profile() const;
//information about the unit -- a detailed description of it
const std::string& unit_description() const;
const config::child_list wml_events() const;
int hitpoints() const;
int max_hitpoints() const;
int experience() const;
@ -100,7 +100,7 @@ class unit
unit_race::GENDER gender() const;
void set_side(unsigned int new_side);
fixed_t alpha() const;
bool can_recruit() const;
bool incapacitated() const;
const std::vector<std::string>& recruits() const;
@ -119,16 +119,16 @@ class unit
void end_turn();
void new_level();
void refresh() {if(anim_ && !refreshing_) anim_->update_current_frame(); }
bool take_hit(int damage);
void heal(int amount);
void heal_all();
bool resting() const;
void set_resting(bool rest);
const std::string get_state(const std::string& state) const;
void set_state(const std::string& state, const std::string& value);
bool has_moved() const;
bool has_goto() const;
int emits_zoc() const;
@ -144,17 +144,17 @@ class unit
*/
void read(const config& cfg);
void write(config& cfg) const;
void assign_role(const std::string& role);
const std::vector<attack_type>& attacks() const;
std::vector<attack_type>& attacks();
int damage_from(const attack_type& attack,bool attacker,const gamemap::location& loc) const;
// a sdl surface, ready for display for place where we need a fix image of the unit
const surface still_image() const;
void redraw_unit(display& disp,gamemap::location hex);
void set_standing(const display& disp,const gamemap::location& loc);
void set_defending(const display &disp,const gamemap::location& loc, int damage,const attack_type* attack);
void set_leading(const display& disp,const gamemap::location& loc);
@ -177,48 +177,48 @@ class unit
std::set<gamemap::location> overlaps(const gamemap::location &loc) const;
const t_string& traits_description() const;
int value() const;
int cost() const;
const gamemap::location& get_goto() const;
void set_goto(const gamemap::location& new_goto);
int upkeep() const;
void set_hidden(bool state) {hidden_ = state;};
bool is_flying() const;
int movement_cost(gamemap::TERRAIN terrain, int recurse_count=0) const;
int defense_modifier(gamemap::TERRAIN terrain, int recurse_count=0) const;
int resistance_against(const attack_type& damage_type,bool attacker,const gamemap::location& loc) const;
// std::map<gamemap::TERRAIN,int> movement_type() const;
bool can_advance() const;
bool advances() const;
std::map<std::string,std::string> advancement_icons() const;
std::vector<std::pair<std::string,std::string> > amla_icons() const;
config::child_list get_modification_advances() const;
const config::child_list& modification_advancements() const;
size_t modification_count(const std::string& type, const std::string& id) const;
void add_modification(const std::string& type, const config& modification,
bool no_add=false);
const t_string& modification_description(const std::string& type) const;
bool move_interrupted() const;
const gamemap::location& get_interrupted_move() const;
void set_interrupted_move(const gamemap::location& interrupted_move);
enum STATE { STATE_STANDING, STATE_ATTACKING, STATE_DEFENDING,
STATE_LEADING, STATE_HEALING, STATE_WALKING, STATE_LEVELIN,
STATE_LEVELOUT, STATE_DYING, STATE_EXTRA, STATE_TELEPORT,
STATE_RECRUITED, STATE_HEALED, STATE_POISONED};
STATE state() const;
//the name of the file to display (used in menus
const std::string& absolute_image() const;
const std::string& image_halo() const;
@ -229,11 +229,11 @@ class unit
const std::string& get_hit_sound() const;
const std::string& die_sound() const;
const std::string& image_ellipse() const;
const std::string& usage() const;
unit_type::ALIGNMENT alignment() const;
const std::string& race() const;
const defensive_animation& defend_animation(const std::string &terrain,
fighting_animation::hit_type hits,const attack_type* attack) const;
const unit_animation& teleport_animation() const;
@ -243,13 +243,13 @@ class unit
const movement_animation& move_animation(const std::string terrain,gamemap::location::DIRECTION) const;
const standing_animation& stand_animation(const std::string terrain,gamemap::location::DIRECTION) const;
const leading_animation& lead_animation(const std::string terrain,gamemap::location::DIRECTION) const;
bool get_ability_bool(const std::string& ability, const gamemap::location& loc) const;
unit_ability_list get_abilities(const std::string& ability, const gamemap::location& loc) const;
std::vector<std::string> ability_tooltips(const gamemap::location& loc) const;
std::vector<std::string> unit_ability_tooltips() const;
bool has_ability_type(const std::string& ability) const;
void reset_modifications();
void backup_state();
void apply_modifications();
@ -257,14 +257,14 @@ class unit
void generate_traits();
void generate_traits_description();
std::string generate_description() const;
bool invisible(const gamemap::location& loc,
const unit_map& units,const std::vector<team>& teams) const;
unit_race::GENDER generate_gender(const unit_type& type, bool gen);
private:
/*
* cfg: an ability WML structure
*/
@ -272,12 +272,12 @@ class unit
bool ability_affects_adjacent(const std::string& ability,const config& cfg,int dir,const gamemap::location& loc) const;
bool ability_affects_self(const std::string& ability,const config& cfg,const gamemap::location& loc) const;
bool resistance_filter_matches(const config& cfg,bool attacker,const attack_type& damage_type) const;
config cfg_;
config movement_b_;
config defense_b_;
config resistance_b_;
std::vector<std::string> advances_to_;
std::string id_;
const unit_race* race_;
@ -288,7 +288,7 @@ class unit
t_string language_name_;
std::string undead_variation_;
std::string variation_;
int hit_points_;
int max_hit_points_, max_hit_points_b_;
int experience_;
@ -296,15 +296,15 @@ class unit
int level_;
unit_type::ALIGNMENT alignment_;
std::vector<Uint32> flag_rgb_;
bool unrenamable_;
unsigned int side_;
unit_race::GENDER gender_;
fixed_t alpha_;
std::vector<std::string> recruits_;
int movement_;
int max_movement_, max_movement_b_;
mutable std::map<gamemap::TERRAIN,int> movement_costs_; // movement cost cache
@ -313,39 +313,39 @@ class unit
bool resting_;
int attacks_left_;
int max_attacks_;
std::map<std::string,std::string> states_;
config variables_;
int emit_zoc_;
STATE state_;
std::vector<std::string> overlays_;
std::string role_;
std::vector<attack_type> attacks_, attacks_b_;
gamemap::location::DIRECTION facing_;
t_string traits_description_;
int unit_value_;
gamemap::location goto_, interrupted_move_;
bool flying_;
// std::map<gamemap::TERRAIN,int> movement_costs_, movement_costs_b_;
// std::map<gamemap::TERRAIN,int> defense_mods_, defense_mods_b_;
string_map modification_descriptions_;
std::vector<defensive_animation> defensive_animations_;
std::vector<unit_animation> teleport_animations_;
std::multimap<std::string,unit_animation> extra_animations_;
std::vector<death_animation> death_animations_;
std::vector<movement_animation> movement_animations_;
std::vector<standing_animation> standing_animations_;
std::vector<leading_animation> leading_animations_;
unit_animation *anim_;
int frame_begin_time;
@ -356,16 +356,16 @@ class unit
bool refreshing_; // avoid infinite recursion
bool hidden_;
bool draw_bars_;
config modifications_;
friend void attack_type::set_specials_context(const gamemap::location& loc,const unit& un) const;
const game_data* gamedata_;
const unit_map* units_;
const gamemap* map_;
const gamestatus* gamestatus_;
const std::vector<team>* teams_;
};
//object which temporarily resets a unit's movement

View file

@ -24,80 +24,80 @@
*
* [abilities]
* ...
*
*
* [heals]
* value=4
* max_value=8
* cumulative=no
* affect_allies=yes
* name= _ "heals"
// * name_inactive=null
* description= _ "Heals:
* value=4
* max_value=8
* cumulative=no
* affect_allies=yes
* name= _ "heals"
// * name_inactive=null
* description= _ "Heals:
Allows the unit to heal adjacent friendly units at the beginning of each turn.
A unit cared for by a healer may heal up to 4 HP per turn.
A poisoned unit cannot be cured of its poison by a healer, and must seek the care of a village or a unit that can cure."
// * description_inactive=null
* icon="misc/..."
// * icon_inactive=null
* [adjacent_description]
* name= _ "heals"
// * name_inactive=null
* description= _ "Heals:
// * description_inactive=null
* icon="misc/..."
// * icon_inactive=null
* [adjacent_description]
* name= _ "heals"
// * name_inactive=null
* description= _ "Heals:
Allows the unit to heal adjacent friendly units at the beginning of each turn.
A unit cared for by a healer may heal up to 4 HP per turn.
A poisoned unit cannot be cured of its poison by a healer, and must seek the care of a village or a unit that can cure."
// * description_inactive=null
* icon="misc/..."
// * icon_inactive=null
* [/adjacent_description]
*
* affect_self=yes
* [filter] // SUF
* ...
* [/filter]
* [filter_location]
* terrain=f
* tod=lawful
* [/filter_location]
* [filter_self] // SUF
* ...
* [/filter_self]
* [filter_adjacent] // SUF
* adjacent=n,ne,nw
* ...
* [/filter_adjacent]
* [filter_adjacent_location]
* adjacent=n,ne,nw
* ...
* [/filter_adjacent]
* [affect_adjacent]
* adjacent=n,ne,nw
* [filter] // SUF
* ...
* [/filter]
* [/affect_adjacent]
* [affect_adjacent]
* adjacent=s,se,sw
* [filter] // SUF
* ...
* [/filter]
* [/affect_adjacent]
*
// * description_inactive=null
* icon="misc/..."
// * icon_inactive=null
* [/adjacent_description]
*
* affect_self=yes
* [filter] // SUF
* ...
* [/filter]
* [filter_location]
* terrain=f
* tod=lawful
* [/filter_location]
* [filter_self] // SUF
* ...
* [/filter_self]
* [filter_adjacent] // SUF
* adjacent=n,ne,nw
* ...
* [/filter_adjacent]
* [filter_adjacent_location]
* adjacent=n,ne,nw
* ...
* [/filter_adjacent]
* [affect_adjacent]
* adjacent=n,ne,nw
* [filter] // SUF
* ...
* [/filter]
* [/affect_adjacent]
* [affect_adjacent]
* adjacent=s,se,sw
* [filter] // SUF
* ...
* [/filter]
* [/affect_adjacent]
*
* [/heals]
*
*
* ...
* [/abilities]
*
*/
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"])) && side == other_side)
return ((cfg["affect_allies"] == "" || utils::string_bool(cfg["affect_allies"])) && side == other_side)
|| (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));
}
@ -116,14 +116,14 @@ bool unit::get_ability_bool(const std::string& ability, const gamemap::location&
}
}
}
wassert(units_ != NULL);
wassert(teams_ != NULL);
gamemap::location adjacent[6];
get_adjacent_tiles(loc,adjacent);
for(int i = 0; i != 6; ++i) {
const unit_map::const_iterator it = units_->find(adjacent[i]);
if(it != units_->end() &&
if(it != units_->end() &&
!it->second.incapacitated()) {
const config* adj_abilities = it->second.cfg_.child("abilities");
if(adj_abilities) {
@ -138,13 +138,13 @@ bool unit::get_ability_bool(const std::string& ability, const gamemap::location&
}
}
return false;
}
unit_ability_list unit::get_abilities(const std::string& ability, const gamemap::location& loc) const
{
unit_ability_list res;
const config* abilities = cfg_.child("abilities");
if(abilities) {
const config::child_list& list = abilities->get_children(ability);
@ -154,13 +154,13 @@ unit_ability_list unit::get_abilities(const std::string& ability, const gamemap:
}
}
}
wassert(units_ != NULL);
gamemap::location adjacent[6];
get_adjacent_tiles(loc,adjacent);
for(int i = 0; i != 6; ++i) {
const unit_map::const_iterator it = units_->find(adjacent[i]);
if(it != units_->end() &&
if(it != units_->end() &&
!it->second.incapacitated()) {
const config* adj_abilities = it->second.cfg_.child("abilities");
if(adj_abilities) {
@ -175,14 +175,14 @@ unit_ability_list unit::get_abilities(const std::string& ability, const gamemap:
}
}
return res;
}
std::vector<std::string> unit::unit_ability_tooltips() const
{
std::vector<std::string> res;
const config* abilities = cfg_.child("abilities");
if(abilities) {
const config::child_map& list_map = abilities->all_children();
@ -201,7 +201,7 @@ std::vector<std::string> unit::unit_ability_tooltips() const
std::vector<std::string> unit::ability_tooltips(const gamemap::location& loc) const
{
std::vector<std::string> res;
const config* abilities = cfg_.child("abilities");
if(abilities) {
const config::child_map& list_map = abilities->all_children();
@ -221,7 +221,7 @@ std::vector<std::string> unit::ability_tooltips(const gamemap::location& loc) co
}
}
}
wassert(units_ != NULL);
gamemap::location adjacent[6];
get_adjacent_tiles(loc,adjacent);
@ -269,8 +269,8 @@ std::vector<std::string> unit::ability_tooltips(const gamemap::location& loc) co
}
}
}
return res;
}
@ -295,7 +295,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const gam
config::child_list::const_iterator i;
for(i = adj_filt.begin(); i != adj_filt.end(); ++i) {
std::vector<std::string> dirs = utils::split((**i)["adjacent"]);
if(dirs.size()==1 && dirs.front()=="") {
if(dirs.size()==1 && dirs.front()=="") {
} else {
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
index = gamemap::location::parse_direction(*j);
@ -315,7 +315,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const gam
const config::child_list& adj_filt_loc = cfg.get_children("filter_adjacent_location");
for(i = adj_filt_loc.begin(); i != adj_filt_loc.end(); ++i) {
std::vector<std::string> dirs = utils::split((**i)["adjacent"]);
if(dirs.size()==1 && dirs.front()=="") {
if(dirs.size()==1 && dirs.front()=="") {
} else {
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
index = gamemap::location::parse_direction(*j);
@ -457,32 +457,32 @@ std::pair<int,gamemap::location> unit_ability_list::lowest(const std::string& ke
/*
*
/*
*
* [special]
* [swarm]
* name= _ "swarm"
* name_inactive= _ ""
* description= _ ""
* description_inactive= _ ""
* cumulative=no
* apply_to=self #self,opponent,defender,attacker
* #active_on=defend .. offense
*
* attacks_max=4
* attacks_min=2
*
* [filter_self] // SUF
* ...
* [/filter_self]
* [filter_opponent] // SUF
* [filter_attacker] // SUF
* [filter_defender] // SUF
* [filter_adjacent] // SAUF
* [filter_adjacent_location] // SAUF + locs
* name= _ "swarm"
* name_inactive= _ ""
* description= _ ""
* description_inactive= _ ""
* cumulative=no
* apply_to=self #self,opponent,defender,attacker
* #active_on=defend .. offense
*
* attacks_max=4
* attacks_min=2
*
* [filter_self] // SUF
* ...
* [/filter_self]
* [filter_opponent] // SUF
* [filter_attacker] // SUF
* [filter_defender] // SUF
* [filter_adjacent] // SAUF
* [filter_adjacent_location] // SAUF + locs
* [/swarm]
* [/special]
*
*
*/
@ -589,7 +589,7 @@ std::string attack_type::weapon_specials(bool force) const
}
}
}
return res.substr(0,res.size()-1);
}
@ -606,7 +606,7 @@ bool attack_type::special_active(const config& cfg,bool self,bool report) const
wassert(unitmap_ != NULL);
unit_map::const_iterator att = unitmap_->find(aloc_);
unit_map::const_iterator def = unitmap_->find(dloc_);
if(self) {
if(!special_affects_self(cfg)) {
return false;
@ -616,7 +616,7 @@ bool attack_type::special_active(const config& cfg,bool self,bool report) const
return false;
}
}
if(attacker_) {
if(!report && cfg["active_on"] != "" && cfg["active_on"] != "offense") {
return false;
@ -635,7 +635,7 @@ bool attack_type::special_active(const config& cfg,bool self,bool report) const
if(def == unitmap_->end() || !def->second.matches_filter(*cfg.child("filter_opponent"),dloc_)) {
return false;
}
if(cfg.child("filter_opponent")->child("filter_weapon") != NULL) {
if(!other_attack_ || !other_attack_->matches_filter(*cfg.child("filter_opponent")->child("filter_weapon"),true)) {
return false;
@ -714,7 +714,7 @@ bool attack_type::special_active(const config& cfg,bool self,bool report) const
config::child_list::const_iterator i;
for(i = adj_filt.begin(); i != adj_filt.end(); ++i) {
std::vector<std::string> dirs = utils::split((**i)["adjacent"]);
if(dirs.size()==1 && dirs.front()=="") {
if(dirs.size()==1 && dirs.front()=="") {
} else {
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
index = gamemap::location::parse_direction(*j);
@ -734,7 +734,7 @@ bool attack_type::special_active(const config& cfg,bool self,bool report) const
const config::child_list& adj_filt_loc = cfg.get_children("filter_adjacent_location");
for(i = adj_filt_loc.begin(); i != adj_filt_loc.end(); ++i) {
std::vector<std::string> dirs = utils::split((**i)["adjacent"]);
if(dirs.size()==1 && dirs.front()=="") {
if(dirs.size()==1 && dirs.front()=="") {
} else {
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
index = gamemap::location::parse_direction(*j);
@ -767,7 +767,7 @@ bool attack_type::special_affects_opponent(const config& cfg) const
if(cfg["apply_to"]!="") {
if(attacker_ && cfg["apply_to"] == "defender") {
return true;
}
}
if(!attacker_ && cfg["apply_to"] == "attacker") {
return true;
}
@ -790,15 +790,15 @@ bool attack_type::special_affects_self(const config& cfg) const
}
if(attacker_ && cfg["apply_to"] == "attacker") {
return true;
}
}
if(!attacker_ && cfg["apply_to"] == "defender") {
return true;
}
return false;
}
void attack_type::set_specials_context(const gamemap::location& aloc,const gamemap::location& dloc,
const game_data* gamedata, const unit_map* unitmap,
const gamemap* map, const gamestatus* game_status,
const game_data* gamedata, const unit_map* unitmap,
const gamemap* map, const gamestatus* game_status,
const std::vector<team>* teams, bool attacker,const attack_type* other_attack) const
{
aloc_ = aloc;
@ -848,17 +848,17 @@ void individual_effect::set(value_modifier t,int val,config* abil,const gamemap:
effect::effect(const unit_ability_list& list, int def, bool backstab)
{
int value_set = def; bool value_is_set = false;
std::map<std::string,individual_effect> values_add;
std::map<std::string,individual_effect> values_mul;
individual_effect set_effect(NOT_USED,0,NULL,gamemap::location());
for(std::vector<std::pair<config*,gamemap::location> >::const_iterator i = list.cfgs.begin(); i != list.cfgs.end(); ++i) {
const config& cfg = (*i->first);
const std::string& effect_id = cfg["id"] != "" ? cfg["id"] : cfg["name"];
if(utils::string_bool(cfg["backstab"]) && !backstab) {
continue;
}
@ -886,7 +886,7 @@ effect::effect(const unit_ability_list& list, int def, bool backstab)
int value = lexical_cast_default<int>(cfg["value"]);
int add = lexical_cast_default<int>(cfg["add"]);
int multiply = static_cast<int>(lexical_cast_default<float>(cfg["multiply"])*100);
if(!value_is_set && !utils::string_bool(cfg["cumulative"]) && cfg["value"] != "") {
value_is_set = true;
value_set = value;
@ -914,11 +914,11 @@ effect::effect(const unit_ability_list& list, int def, bool backstab)
}
}
}
if(value_is_set && set_effect.type != NOT_USED) {
effect_list_.push_back(set_effect);
}
int multiplier = 1;
int divisor = 1;
std::map<std::string,individual_effect>::const_iterator e;
@ -932,9 +932,9 @@ effect::effect(const unit_ability_list& list, int def, bool backstab)
addition += e->second.value;
effect_list_.push_back(e->second);
}
composite_value_ = (value_set + addition) * multiplier / divisor;
}

View file

@ -1,75 +1,75 @@
/* $Id$ */
/*
Copyright (C) 2006 by Dominic Bolin <dominic.bolin@exong.net>
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.
*/
#ifndef UNIT_ABILITIES_HPP_INCLUDED
#define UNIT_ABILITIES_HPP_INCLUDED
namespace unit_abilities
{
enum value_modifier {NOT_USED,SET,ADD,MUL};
struct individual_effect
{
individual_effect() {};
individual_effect(value_modifier t,int val,config* abil,const gamemap::location& l);
void set(value_modifier t,int val,config* abil,const gamemap::location& l);
value_modifier type;
int value;
config* ability;
gamemap::location loc;
};
typedef std::vector<individual_effect> effect_list;
class effect
{
public:
effect(const unit_ability_list& list, int def, bool backstab);
int get_composite_value() const;
effect_list::const_iterator begin() const;
effect_list::const_iterator end() const;
private:
effect_list effect_list_;
int composite_value_;
};
}
#endif
/* $Id$ */
/*
Copyright (C) 2006 by Dominic Bolin <dominic.bolin@exong.net>
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.
*/
#ifndef UNIT_ABILITIES_HPP_INCLUDED
#define UNIT_ABILITIES_HPP_INCLUDED
namespace unit_abilities
{
enum value_modifier {NOT_USED,SET,ADD,MUL};
struct individual_effect
{
individual_effect() {};
individual_effect(value_modifier t,int val,config* abil,const gamemap::location& l);
void set(value_modifier t,int val,config* abil,const gamemap::location& l);
value_modifier type;
int value;
config* ability;
gamemap::location loc;
};
typedef std::vector<individual_effect> effect_list;
class effect
{
public:
effect(const unit_ability_list& list, int def, bool backstab);
int get_composite_value() const;
effect_list::const_iterator begin() const;
effect_list::const_iterator end() const;
private:
effect_list effect_list_;
int composite_value_;
};
}
#endif

View file

@ -82,7 +82,7 @@ unit_frame::unit_frame(const config& cfg)
halo = prepare_halo(cfg["halo"],begin_time,end_time);
blend_with= 0;
blend_ratio = 0;
}
std::vector<std::pair<std::string,int> > unit_frame::prepare_halo(const std::string & halo,int begin, int end)

View file

@ -21,12 +21,12 @@
#include <string>
#include <vector>
#include "unit_frame.hpp"
#include "unit_frame.hpp"
class unit_animation:public animated<unit_frame>
class unit_animation:public animated<unit_frame>
{
public:
static config prepare_animation(const config &cfg,const std::string animation_tag);
@ -64,7 +64,7 @@ class fighting_animation:public unit_animation
std::vector<std::string> damage_type, special;
};
class defensive_animation:public fighting_animation
class defensive_animation:public fighting_animation
{
public:
explicit defensive_animation(const config& cfg):fighting_animation(cfg){};

View file

@ -396,8 +396,8 @@ bool unit_attack(display& disp, unit_map& units,
const bool hits = damage > 0;
int start_time = 500;
int end_time = 0;
attacker.set_attacking(disp,a,hits,attack);
start_time=minimum<int>(start_time,attacker.get_animation()->get_first_frame_time());
end_time=maximum<int>(end_time,attacker.get_animation()->get_last_frame_time());

View file

@ -1,56 +1,56 @@
/* $Id: unit_frame.hpp 9700 2006-01-15 12:00:53Z noyga $ */
/*
Copyright (C) 2006 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
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.
*/
#ifndef UNIT_FRAME_H_INCLUDED
#define UNIT_FRAME_H_INCLUDED
#include "animated.hpp"
#include "map.hpp"
#include "config.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
#include <string>
#include <vector>
//a class to describe a unit's animation sequence
struct unit_frame {
unit_frame() : xoffset(0), image(), image_diagonal(),halo(), sound(),
halo_x(0), halo_y(0), begin_time(0), end_time(0),
blend_with(0),blend_ratio(0),
highlight_ratio(ftofxp(1)){}
explicit unit_frame(const std::string& str, const std::string & diag ="",
int begin=0,int end = 0,
Uint32 blend_color = 0, double blend_rate = 0.0,
fixed_t highlight = ftofxp(1),
std::string in_halo = "",int halox = 0,int haloy = 0) :
xoffset(0), image(str),image_diagonal(diag),
halo_x(halox), halo_y(haloy),
begin_time(begin), end_time(end),
blend_with(blend_color), blend_ratio(blend_rate),
highlight_ratio(highlight) {halo = prepare_halo(in_halo,begin,end);};
explicit unit_frame(const config& cfg);
int xoffset;
std::string image;
std::string image_diagonal;
std::vector<std::pair<std::string,int> > halo;
std::string sound;
int halo_x, halo_y;
int begin_time, end_time;
Uint32 blend_with;
double blend_ratio;
fixed_t highlight_ratio;
static std::vector<std::pair<std::string,int> > prepare_halo(const std::string & halo,int begin, int end);
};
#endif
/* $Id: unit_frame.hpp 9700 2006-01-15 12:00:53Z noyga $ */
/*
Copyright (C) 2006 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
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.
*/
#ifndef UNIT_FRAME_H_INCLUDED
#define UNIT_FRAME_H_INCLUDED
#include "animated.hpp"
#include "map.hpp"
#include "config.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
#include <string>
#include <vector>
//a class to describe a unit's animation sequence
struct unit_frame {
unit_frame() : xoffset(0), image(), image_diagonal(),halo(), sound(),
halo_x(0), halo_y(0), begin_time(0), end_time(0),
blend_with(0),blend_ratio(0),
highlight_ratio(ftofxp(1)){}
explicit unit_frame(const std::string& str, const std::string & diag ="",
int begin=0,int end = 0,
Uint32 blend_color = 0, double blend_rate = 0.0,
fixed_t highlight = ftofxp(1),
std::string in_halo = "",int halox = 0,int haloy = 0) :
xoffset(0), image(str),image_diagonal(diag),
halo_x(halox), halo_y(haloy),
begin_time(begin), end_time(end),
blend_with(blend_color), blend_ratio(blend_rate),
highlight_ratio(highlight) {halo = prepare_halo(in_halo,begin,end);};
explicit unit_frame(const config& cfg);
int xoffset;
std::string image;
std::string image_diagonal;
std::vector<std::pair<std::string,int> > halo;
std::string sound;
int halo_x, halo_y;
int begin_time, end_time;
Uint32 blend_with;
double blend_ratio;
fixed_t highlight_ratio;
static std::vector<std::pair<std::string,int> > prepare_halo(const std::string & halo,int begin, int end);
};
#endif

View file

@ -69,20 +69,20 @@ attack_type::attack_type(const config& cfg,const std::string& id, const std::str
attack_weight_ = lexical_cast_default<double>(cfg["attack_weight"],1.0);
defense_weight_ = lexical_cast_default<double>(cfg["defense_weight"],1.0);
gamedata_=NULL;
unitmap_=NULL;
unitmap_=NULL;
map_=NULL;
game_status_=NULL;
teams_=NULL;
other_attack_=NULL;
// BACKWARDS COMPATIBILITY
const std::string& set_special = cfg["special"];
if(set_special != "") {
LOG_STREAM(err, config) << "[attack] uses special=" << set_special <<", which is now deprecated. Use the macros provided in abilities.cfg.\n";
config new_specials;
new_specials["set_special"] = set_special;
apply_modification(new_specials,NULL);
}
@ -696,7 +696,7 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
if(race_->uses_global_traits() == false) {
possibleTraits_.clear();
}
if(utils::string_bool(cfg["ignore_race_traits"])) {
possibleTraits_.clear();
} else {
@ -737,7 +737,7 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
LOG_STREAM(err, config) << "Invalid alignment found for " << id() << ": '" << align << "'\n";
alignment_ = NEUTRAL;
}
if(cfg_["zoc"] == "") {
zoc_ = lexical_cast_default<int>(cfg_["level"]) > 0;
} else {
@ -746,7 +746,7 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
zoc_ = true;
}
}
const std::string& alpha_blend = cfg_["alpha"];
if(alpha_blend.empty() == false) {

View file

@ -48,31 +48,31 @@ public:
int num_attacks() const;
double attack_weight() const;
double defense_weight() const;
bool get_special_bool(const std::string& special,bool force=false) const;
unit_ability_list get_specials(const std::string& special) const;
std::vector<std::string> special_tooltips(bool force=false) const;
std::string weapon_specials(bool force=false) const;
void set_specials_context(const gamemap::location& aloc,const gamemap::location& dloc,
const game_data* gamedata, const unit_map* unitmap,
const gamemap* map, const gamestatus* game_status,
const game_data* gamedata, const unit_map* unitmap,
const gamemap* map, const gamestatus* game_status,
const std::vector<team>* teams,bool attacker,const attack_type* other_attack) const;
void set_specials_context(const gamemap::location& loc,const unit& un) const;
bool has_special_by_id(const std::string& special) const;
//this function returns a random animation out of the possible
//animations for this attack. It will not return the same attack
//each time.
bool matches_filter(const config& cfg,bool self=false) const;
bool apply_modification(const config& cfg,std::string* description);
int movement_used() const;
const config& get_cfg() const;
mutable gamemap::location aloc_,dloc_;
mutable bool attacker_;
mutable const game_data* gamedata_;
mutable const unit_map* unitmap_;
mutable const unit_map* unitmap_;
mutable const gamemap* map_;
mutable const gamestatus* game_status_;
mutable const std::vector<team>* teams_;
@ -83,7 +83,7 @@ public:
bool special_active(const config& cfg,bool self,bool report=false) const;
bool special_affects_opponent(const config& cfg) const;
bool special_affects_self(const config& cfg) const;
struct attack_animation
{
typedef enum { HIT, MISS, HIT_OR_MISS } hit_type;
@ -139,7 +139,7 @@ public:
bool is_flying() const;
const std::map<gamemap::TERRAIN,int>& movement_costs() const;
const std::map<gamemap::TERRAIN,int>& defense_mods() const;
const config& get_cfg() const;
const unit_movement_type* get_parent() const;
private:
@ -185,7 +185,7 @@ public:
//where name() is always the user-visible, translated, name.
//language_name should eventually be renamed name()
// const std::string& name() const;
const std::string& image() const;
const std::string& image_profile() const;
const t_string& unit_description() const;
@ -263,7 +263,7 @@ private:
std::vector<std::string> advances_to_;
int experience_needed_;
ALIGNMENT alignment_;

View file

@ -22,7 +22,7 @@
#include "unit.hpp"
struct upload_log
{
{
public:
struct manager {
manager() { };

View file

@ -1,220 +1,220 @@
/*
wesnoth menu styles Copyright (C) 2006 by Patrick Parker <patrick_x99@hotmail.com>
wesnoth menu Copyright (C) 2003-5 by David White <davidnwhite@verizon.net>
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 "global.hpp"
#include "widgets/menu.hpp"
#include "language.hpp"
#include "font.hpp"
#include "image.hpp"
#include "marked-up_text.hpp"
#include "sdl_utils.hpp"
#include "SDL.h"
#include "SDL_image.h"
#include "util.hpp"
#include "video.hpp"
#include "wml_separators.hpp"
#include "serialization/string_utils.hpp"
#include <algorithm>
#include <cassert>
#include <numeric>
namespace gui {
//static initializations
menu::imgsel_style menu::slateborder_style("misc/selection", false,
0x000000, 0x4a4440, 0x999999,
0.9, 0.2, 0.2);
menu::imgsel_style menu::bluebg_style("misc/selection2", true,
0x000000, 0x000000, 0x333333,
0.2, 0.0, 0.3);
menu::style &menu::default_style = menu::bluebg_style;
//constructors
menu::style::style() : font_size_(font::SIZE_NORMAL),
cell_padding_(font::SIZE_NORMAL * 3/5), thickness_(0),
normal_rgb_(0x000000), selected_rgb_(0x000099), heading_rgb_(0x333333),
normal_alpha_(0.2), selected_alpha_(0.6), heading_alpha_(0.3)
{}
menu::style::~style()
{}
menu::imgsel_style::imgsel_style(const std::string &img_base, bool has_bg,
int normal_rgb, int selected_rgb, int heading_rgb,
double normal_alpha, double selected_alpha, double heading_alpha)
: img_base_(img_base), initialized_(false), load_failed_(false), has_background_(has_bg),
normal_rgb2_(normal_rgb), selected_rgb2_(selected_rgb), heading_rgb2_(heading_rgb),
normal_alpha2_(normal_alpha), selected_alpha2_(selected_alpha), heading_alpha2_(heading_alpha)
{}
menu::imgsel_style::~imgsel_style()
{}
size_t menu::style::get_font_size() const { return font_size_; }
size_t menu::style::get_cell_padding() const { return cell_padding_; }
size_t menu::style::get_thickness() const { return thickness_; }
bool menu::imgsel_style::load_image(const std::string &img_sub)
{
std::string path = img_base_ + "-" + img_sub + ".png";
const surface image = image::get_image(path,image::UNSCALED);
img_map_[img_sub] = image;
return(!image.null());
}
bool menu::imgsel_style::load_images()
{
if(!initialized_)
{
if( load_image("border-botleft")
&& load_image("border-botright")
&& load_image("border-topleft")
&& load_image("border-topright")
&& load_image("border-left")
&& load_image("border-right")
&& load_image("border-top")
&& load_image("border-bottom") )
{
thickness_ = minimum(
img_map_["border-top"]->h,
img_map_["border-left"]->w);
if(has_background_ && !load_image("background"))
{
load_failed_ = true;
}
else
{
normal_rgb_ = normal_rgb2_;
normal_alpha_ = normal_alpha2_;
selected_rgb_ = selected_rgb2_;
selected_alpha_ = selected_alpha2_;
heading_rgb_ = heading_rgb2_;
heading_alpha_ = heading_alpha2_;
load_failed_ = false;
}
initialized_ = true;
}
else
{
thickness_ = 0;
initialized_ = true;
load_failed_ = true;
}
}
return (!load_failed_);
}
void menu::imgsel_style::draw_row_bg(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
{
if(type == SELECTED_ROW && has_background_ && !load_failed_) {
//draw scaled background image
//scale image each time (to prevent loss of quality)
surface image = scale_surface(img_map_["background"], rect.w, rect.h);
SDL_Rect clip = rect;
menu_ref.video().blit_surface(rect.x,rect.y,image,NULL,&clip);
}
else {
style::draw_row_bg(menu_ref, row_index, rect, type);
}
}
void menu::imgsel_style::draw_row(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
{
if(!load_failed_) {
//draw item inside
style::draw_row(menu_ref, row_index, rect, type);
if(type == SELECTED_ROW) {
// draw border
surface image;
SDL_Rect area;
SDL_Rect clip = rect;
area.x = rect.x;
area.y = rect.y;
image = img_map_["border-top"];
area.x = rect.x;
area.y = rect.y;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.x += image->w;
} while( area.x < rect.x + rect.w );
image = img_map_["border-left"];
area.x = rect.x;
area.y = rect.y;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.y += image->h;
} while( area.y < rect.y + rect.h );
image = img_map_["border-right"];
area.x = rect.x + rect.w - thickness_;
area.y = rect.y;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.y += image->h;
} while( area.y < rect.y + rect.h );
image = img_map_["border-bottom"];
area.x = rect.x;
area.y = rect.y + rect.h - thickness_;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.x += image->w;
} while( area.x < rect.x + rect.w );
image = img_map_["border-topleft"];
area.x = rect.x;
area.y = rect.y;
menu_ref.video().blit_surface(area.x,area.y,image);
image = img_map_["border-topright"];
area.x = rect.x + rect.w - image->w;
area.y = rect.y;
menu_ref.video().blit_surface(area.x,area.y,image);
image = img_map_["border-botleft"];
area.x = rect.x;
area.y = rect.y + rect.h - image->h;
menu_ref.video().blit_surface(area.x,area.y,image);
image = img_map_["border-botright"];
area.x = rect.x + rect.w - image->w;
area.y = rect.y + rect.h - image->h;
menu_ref.video().blit_surface(area.x,area.y,image);
}
} else {
//default drawing
style::draw_row(menu_ref, row_index, rect, type);
}
}
SDL_Rect menu::imgsel_style::item_size(const std::string& item) const
{
SDL_Rect bounds = style::item_size(item);
bounds.w += 2 * thickness_;
bounds.h += 2 * thickness_;
return bounds;
}
} //namesapce gui
/*
wesnoth menu styles Copyright (C) 2006 by Patrick Parker <patrick_x99@hotmail.com>
wesnoth menu Copyright (C) 2003-5 by David White <davidnwhite@verizon.net>
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 "global.hpp"
#include "widgets/menu.hpp"
#include "language.hpp"
#include "font.hpp"
#include "image.hpp"
#include "marked-up_text.hpp"
#include "sdl_utils.hpp"
#include "SDL.h"
#include "SDL_image.h"
#include "util.hpp"
#include "video.hpp"
#include "wml_separators.hpp"
#include "serialization/string_utils.hpp"
#include <algorithm>
#include <cassert>
#include <numeric>
namespace gui {
//static initializations
menu::imgsel_style menu::slateborder_style("misc/selection", false,
0x000000, 0x4a4440, 0x999999,
0.9, 0.2, 0.2);
menu::imgsel_style menu::bluebg_style("misc/selection2", true,
0x000000, 0x000000, 0x333333,
0.2, 0.0, 0.3);
menu::style &menu::default_style = menu::bluebg_style;
//constructors
menu::style::style() : font_size_(font::SIZE_NORMAL),
cell_padding_(font::SIZE_NORMAL * 3/5), thickness_(0),
normal_rgb_(0x000000), selected_rgb_(0x000099), heading_rgb_(0x333333),
normal_alpha_(0.2), selected_alpha_(0.6), heading_alpha_(0.3)
{}
menu::style::~style()
{}
menu::imgsel_style::imgsel_style(const std::string &img_base, bool has_bg,
int normal_rgb, int selected_rgb, int heading_rgb,
double normal_alpha, double selected_alpha, double heading_alpha)
: img_base_(img_base), initialized_(false), load_failed_(false), has_background_(has_bg),
normal_rgb2_(normal_rgb), selected_rgb2_(selected_rgb), heading_rgb2_(heading_rgb),
normal_alpha2_(normal_alpha), selected_alpha2_(selected_alpha), heading_alpha2_(heading_alpha)
{}
menu::imgsel_style::~imgsel_style()
{}
size_t menu::style::get_font_size() const { return font_size_; }
size_t menu::style::get_cell_padding() const { return cell_padding_; }
size_t menu::style::get_thickness() const { return thickness_; }
bool menu::imgsel_style::load_image(const std::string &img_sub)
{
std::string path = img_base_ + "-" + img_sub + ".png";
const surface image = image::get_image(path,image::UNSCALED);
img_map_[img_sub] = image;
return(!image.null());
}
bool menu::imgsel_style::load_images()
{
if(!initialized_)
{
if( load_image("border-botleft")
&& load_image("border-botright")
&& load_image("border-topleft")
&& load_image("border-topright")
&& load_image("border-left")
&& load_image("border-right")
&& load_image("border-top")
&& load_image("border-bottom") )
{
thickness_ = minimum(
img_map_["border-top"]->h,
img_map_["border-left"]->w);
if(has_background_ && !load_image("background"))
{
load_failed_ = true;
}
else
{
normal_rgb_ = normal_rgb2_;
normal_alpha_ = normal_alpha2_;
selected_rgb_ = selected_rgb2_;
selected_alpha_ = selected_alpha2_;
heading_rgb_ = heading_rgb2_;
heading_alpha_ = heading_alpha2_;
load_failed_ = false;
}
initialized_ = true;
}
else
{
thickness_ = 0;
initialized_ = true;
load_failed_ = true;
}
}
return (!load_failed_);
}
void menu::imgsel_style::draw_row_bg(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
{
if(type == SELECTED_ROW && has_background_ && !load_failed_) {
//draw scaled background image
//scale image each time (to prevent loss of quality)
surface image = scale_surface(img_map_["background"], rect.w, rect.h);
SDL_Rect clip = rect;
menu_ref.video().blit_surface(rect.x,rect.y,image,NULL,&clip);
}
else {
style::draw_row_bg(menu_ref, row_index, rect, type);
}
}
void menu::imgsel_style::draw_row(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
{
if(!load_failed_) {
//draw item inside
style::draw_row(menu_ref, row_index, rect, type);
if(type == SELECTED_ROW) {
// draw border
surface image;
SDL_Rect area;
SDL_Rect clip = rect;
area.x = rect.x;
area.y = rect.y;
image = img_map_["border-top"];
area.x = rect.x;
area.y = rect.y;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.x += image->w;
} while( area.x < rect.x + rect.w );
image = img_map_["border-left"];
area.x = rect.x;
area.y = rect.y;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.y += image->h;
} while( area.y < rect.y + rect.h );
image = img_map_["border-right"];
area.x = rect.x + rect.w - thickness_;
area.y = rect.y;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.y += image->h;
} while( area.y < rect.y + rect.h );
image = img_map_["border-bottom"];
area.x = rect.x;
area.y = rect.y + rect.h - thickness_;
do {
menu_ref.video().blit_surface(area.x,area.y,image,NULL,&clip);
area.x += image->w;
} while( area.x < rect.x + rect.w );
image = img_map_["border-topleft"];
area.x = rect.x;
area.y = rect.y;
menu_ref.video().blit_surface(area.x,area.y,image);
image = img_map_["border-topright"];
area.x = rect.x + rect.w - image->w;
area.y = rect.y;
menu_ref.video().blit_surface(area.x,area.y,image);
image = img_map_["border-botleft"];
area.x = rect.x;
area.y = rect.y + rect.h - image->h;
menu_ref.video().blit_surface(area.x,area.y,image);
image = img_map_["border-botright"];
area.x = rect.x + rect.w - image->w;
area.y = rect.y + rect.h - image->h;
menu_ref.video().blit_surface(area.x,area.y,image);
}
} else {
//default drawing
style::draw_row(menu_ref, row_index, rect, type);
}
}
SDL_Rect menu::imgsel_style::item_size(const std::string& item) const
{
SDL_Rect bounds = style::item_size(item);
bounds.w += 2 * thickness_;
bounds.h += 2 * thickness_;
return bounds;
}
} //namesapce gui