codeclean run
set svn:eol-style to native where missing
This commit is contained in:
parent
80f7551397
commit
ae9e10f260
174 changed files with 2518 additions and 2518 deletions
|
@ -87,7 +87,7 @@ instantiated, it will be associated with the active event_context
|
|||
be instructed to join a later context). As long as its event_context
|
||||
remains active, and only then, it will receive all system events.
|
||||
|
||||
@note Multiple handler objects will receive the same events,
|
||||
@note Multiple handler objects will receive the same events,
|
||||
including key events.
|
||||
|
||||
*/
|
||||
|
@ -98,7 +98,7 @@ including key events.
|
|||
|
||||
/**
|
||||
|
||||
@namespace font Graphical text output.
|
||||
@namespace font Graphical text output.
|
||||
|
||||
This module is used to display and measure text.
|
||||
Text can optionally contain special characters, which may
|
||||
|
@ -115,7 +115,7 @@ they can be escaped, C-style, using backslashes.
|
|||
|
||||
/**
|
||||
|
||||
@namespace game_config Game configuration data as global variables.
|
||||
@namespace game_config Game configuration data as global variables.
|
||||
|
||||
This module can be used to load various high level
|
||||
game configuration data from a .cfg file.
|
||||
|
@ -130,7 +130,7 @@ global variables.
|
|||
|
||||
/**
|
||||
|
||||
@namespace game_events Domain specific events
|
||||
@namespace game_events Domain specific events
|
||||
|
||||
This module defines the game's event mechanism. Events might be units
|
||||
moving or fighting, or when victory or defeat occurs. A scenario's
|
||||
|
@ -149,7 +149,7 @@ These kinds of system events can be handled using namespace @ref events
|
|||
|
||||
/**
|
||||
|
||||
@namespace gui General purpose widgets.
|
||||
@namespace gui General purpose widgets.
|
||||
|
||||
This module primarily contains a number of common, general purpose
|
||||
widgets for the construction of composite user interfaces.
|
||||
|
@ -162,7 +162,7 @@ widgets for the construction of composite user interfaces.
|
|||
|
||||
/**
|
||||
|
||||
@namespace hotkey Keyboard shortcuts for game actions.
|
||||
@namespace hotkey Keyboard shortcuts for game actions.
|
||||
|
||||
Hotkey commands can be loaded from configuration objects.
|
||||
When a keyboard event corresponding to a hotkey occurs,
|
||||
|
@ -177,7 +177,7 @@ For this to work, key_event() must be called whenever a keyboard event happens.
|
|||
|
||||
/* - already documented
|
||||
|
||||
@namespace image Cache of images.
|
||||
@namespace image Cache of images.
|
||||
|
||||
This module manages the cache of images. With an image name, you can get
|
||||
the surface corresponding to that image, and don't need to free the image.
|
||||
|
@ -199,10 +199,10 @@ images come in a number of varieties:
|
|||
|
||||
/**
|
||||
|
||||
@namespace mp Multiplayer meeting place and game creation.
|
||||
@namespace mp Multiplayer meeting place and game creation.
|
||||
|
||||
This module controls the multiplayer lobby.
|
||||
The lobby is a section on the server which allows players
|
||||
This module controls the multiplayer lobby.
|
||||
The lobby is a section on the server which allows players
|
||||
to chat, create games, and join games.
|
||||
|
||||
*/
|
||||
|
@ -213,15 +213,15 @@ to chat, create games, and join games.
|
|||
|
||||
/**
|
||||
|
||||
@namespace network High level network layer for config object transport.
|
||||
@namespace network High level network layer for config object transport.
|
||||
|
||||
This module provides high level network access using an API similiar
|
||||
to sockets, but primarily for the transport of @ref config objects.
|
||||
This is how the games protocols work - data is sent via config objects.
|
||||
|
||||
A client would create a @ref manager object to initialize
|
||||
the network layer, connect(), and then send_data().
|
||||
A server would create a @ref server_manager object,
|
||||
A client would create a @ref manager object to initialize
|
||||
the network layer, connect(), and then send_data().
|
||||
A server would create a @ref server_manager object,
|
||||
then accept_connection(), and finally receive_data().
|
||||
|
||||
*/
|
||||
|
@ -232,7 +232,7 @@ then accept_connection(), and finally receive_data().
|
|||
|
||||
/**
|
||||
|
||||
@namespace preferences Modify, read and display user preferences.
|
||||
@namespace preferences Modify, read and display user preferences.
|
||||
|
||||
This module contain GUI code to display dialogs regarding
|
||||
user preferences, and functions which read and modify the preferences.
|
||||
|
@ -245,7 +245,7 @@ user preferences, and functions which read and modify the preferences.
|
|||
|
||||
/**
|
||||
|
||||
@namespace reports Unit and team statistics.
|
||||
@namespace reports Unit and team statistics.
|
||||
|
||||
This module can provide statistics and information, such as these
|
||||
presented in the in-game windows rightmost and upper borders.
|
||||
|
@ -259,7 +259,7 @@ This is primarily characteristics of units and teams.
|
|||
|
||||
/**
|
||||
|
||||
@namespace sound Audio output for sound and music.
|
||||
@namespace sound Audio output for sound and music.
|
||||
|
||||
This module provides the ability to play music and sounds.
|
||||
Setting music volume to 0 will stop the music.
|
||||
|
@ -272,11 +272,11 @@ Setting music volume to 0 will stop the music.
|
|||
|
||||
/**
|
||||
|
||||
@namespace tooltips tooltips.
|
||||
@namespace tooltips tooltips.
|
||||
|
||||
This module can be used to register tooltips,
|
||||
which will be shown provided @ref process()
|
||||
is called every time mouse motion events
|
||||
This module can be used to register tooltips,
|
||||
which will be shown provided @ref process()
|
||||
is called every time mouse motion events
|
||||
are received from the @ref events system.
|
||||
If tooltips::draw_text() is used instead of font::draw_text(),
|
||||
the text will also be registered as a tooltip.
|
||||
|
@ -289,14 +289,14 @@ the text will also be registered as a tooltip.
|
|||
|
||||
/**
|
||||
|
||||
@page get_involved Get Involved
|
||||
@page get_involved Get Involved
|
||||
|
||||
Apart from development, there are
|
||||
<a href="http://www.wesnoth.org/wiki/FAQ">other ways to contribute</a>
|
||||
to the project.
|
||||
|
||||
Before you can join the development team, your work
|
||||
needs to be reviewed by a current developer.
|
||||
Before you can join the development team, your work
|
||||
needs to be reviewed by a current developer.
|
||||
It works like this:
|
||||
you first get the
|
||||
<a href="http://gna.org/svn/?group=wesnoth">latest source code</a>
|
||||
|
@ -319,26 +319,26 @@ When adding new features, keep in mind the project philosophy,
|
|||
which is that of
|
||||
<a href="http://www.wesnoth.org/wiki/WesnothPhilosophy">KISS</a>.
|
||||
|
||||
Other than at the forum, developers may also hang out
|
||||
Other than at the forum, developers may also hang out
|
||||
in IRC #wesnoth-dev at irc.freenode.net
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@page howto_document Document your code
|
||||
@page howto_document Document your code
|
||||
|
||||
@section motivation Motivation
|
||||
@section motivation Motivation
|
||||
|
||||
The document you are reading now was generated using
|
||||
<a href="http://www.doxygen.org/">Doxygen</a>.
|
||||
It follows in the tradition of
|
||||
<a href="http://www.literateprogramming.com/">literal programming</a>,
|
||||
the goal of which is to keep documentation in the source code,
|
||||
when practical.
|
||||
the goal of which is to keep documentation in the source code,
|
||||
when practical.
|
||||
This way, the documentation will not be outdated or unmaintained.
|
||||
|
||||
@section interfaces Commenting interfaces
|
||||
@section interfaces Commenting interfaces
|
||||
|
||||
Concise comments are prefered, as long as the explanation
|
||||
is correct, is not open to interpretation and does not
|
||||
|
@ -349,13 +349,13 @@ is available from a C++ source file, and could result in
|
|||
compile errors if removed.
|
||||
When you comment a header file, you need to take care
|
||||
of a few, minor things in order to produce readable
|
||||
documentation using Doxygen.
|
||||
documentation using Doxygen.
|
||||
The basic guidelines for this project are:
|
||||
|
||||
- When commenting part of an interface, use two slashes followed by
|
||||
- When commenting part of an interface, use two slashes followed by
|
||||
an exclamation sign, followed by a space and then the actual comment.
|
||||
The first sentence you write, terminated by a period,
|
||||
will be the brief description.
|
||||
will be the brief description.
|
||||
After that, you can write a longer, more detailed description.
|
||||
The brief description will be shown in overviews,
|
||||
so it should be no more than a single line.
|
||||
|
@ -368,7 +368,7 @@ Example:
|
|||
/ / !
|
||||
/ / ! The display is divided into two main sections: the game area,
|
||||
/ / ! which displays the tiles of the game board, and units on them,
|
||||
/ / ! and the side bar, which appears on the right hand side.
|
||||
/ / ! and the side bar, which appears on the right hand side.
|
||||
/ / ! The side bar display is divided into three sections.
|
||||
class display {
|
||||
...
|
||||
|
@ -377,13 +377,13 @@ class display {
|
|||
|
||||
- Do not refer to multiple objects of the type "Manager"
|
||||
as "Managers" or "manager". Instead, say "Manager objects".
|
||||
Doxygen will automatically link to class documentation
|
||||
Doxygen will automatically link to class documentation
|
||||
whenever it finds class names in comments,
|
||||
but will not do so if you do not use their proper names.
|
||||
|
||||
- Many <a href="http://www.stack.nl/~dimitri/doxygen/commands.html">Doxygen commands</a>
|
||||
can be used in comments to enhance the generated documentation and structure the comments.
|
||||
- There is a balance between readable autogenerated documentation and readable code,
|
||||
- There is a balance between readable autogenerated documentation and readable code,
|
||||
so beware of overdoing it.
|
||||
|
||||
Example:
|
||||
|
@ -409,7 +409,7 @@ int divide(int a,int b) {
|
|||
// ===========================================================================
|
||||
|
||||
/**
|
||||
@defgroup unnamed_namespace Unnamed Namespace
|
||||
@defgroup unnamed_namespace Unnamed Namespace
|
||||
|
||||
@{
|
||||
*/
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file about.cpp
|
||||
//! @file about.cpp
|
||||
//! Show screen with scrolling credits.
|
||||
|
||||
#include "about.hpp"
|
||||
|
@ -25,9 +25,9 @@
|
|||
#include "video.hpp"
|
||||
#include "show_dialog.hpp"
|
||||
|
||||
//! @namespace about
|
||||
//! @namespace about
|
||||
//! Display credits about all contributors.
|
||||
//!
|
||||
//!
|
||||
//! This module is used from the startup screen. \n
|
||||
//! When show_about() is called, a list of contributors
|
||||
//! to the game will be presented to the user.
|
||||
|
@ -43,7 +43,7 @@ namespace about
|
|||
void add_lines(std::vector<std::string> &res, config const &c) {
|
||||
std::string title=c["title"];
|
||||
if(title.size()) {
|
||||
title = N_("+" + title);
|
||||
title = N_("+" + title);
|
||||
res.push_back(title);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ std::vector<std::string> get_text(std::string campaign) {
|
|||
for(config::child_list::const_iterator cc = children.begin(); cc != children.end(); ++cc) {
|
||||
// just finished a particular campaign
|
||||
if(campaign.size() && campaign == (**cc)["id"]){
|
||||
add_lines(res, **cc);
|
||||
add_lines(res, **cc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ void set_about(const config& cfg){
|
|||
line != lines.end(); line++){
|
||||
text+=" "+(*line)+"\n";
|
||||
}
|
||||
|
||||
|
||||
config::child_list entries = AA.get_children("entry");
|
||||
config::child_list::const_iterator entry;
|
||||
for(entry = entries.begin(); entry != entries.end(); entry++) {
|
||||
|
@ -162,7 +162,7 @@ void show_about(display &disp, std::string campaign)
|
|||
// Clear the screen
|
||||
draw_solid_tinted_rectangle(0,0,video.getx()-1,video.gety()-1,
|
||||
0,0,0,1.0,video.getSurface());
|
||||
update_whole_screen();
|
||||
update_whole_screen();
|
||||
cursor::set(cursor::NORMAL);
|
||||
|
||||
std::vector<std::string> image_list;
|
||||
|
@ -231,8 +231,8 @@ void show_about(display &disp, std::string campaign)
|
|||
last_escape = key[SDLK_ESCAPE] != 0;
|
||||
|
||||
// check to see if background image has changed
|
||||
if(text.size() && (image_count <
|
||||
((startline * static_cast<int>(image_list.size())) /
|
||||
if(text.size() && (image_count <
|
||||
((startline * static_cast<int>(image_list.size())) /
|
||||
static_cast<int>(text.size())))){
|
||||
|
||||
image_count++;
|
||||
|
@ -246,7 +246,7 @@ void show_about(display &disp, std::string campaign)
|
|||
map_rect.x + map_rect.w * 3/32,
|
||||
map_rect.y + top_margin,
|
||||
map_rect.w * 13 / 16,
|
||||
map_rect.h - top_margin - bottom_margin
|
||||
map_rect.h - top_margin - bottom_margin
|
||||
};
|
||||
gui::dialog_frame f(disp.video(), "", gui::dialog_frame::titlescreen_style, false);
|
||||
f.layout(frame_area);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file actions.cpp
|
||||
//! @file actions.cpp
|
||||
//! Recruiting, Fighting.
|
||||
|
||||
#include "actions.hpp"
|
||||
|
@ -105,7 +105,7 @@ std::string recruit_unit(const gamemap& map, int side,
|
|||
unit_map::const_iterator u = units.begin();
|
||||
|
||||
for(; u != units.end(); ++u) {
|
||||
if(u->second.can_recruit() &&
|
||||
if(u->second.can_recruit() &&
|
||||
static_cast<int>(u->second.side()) == side) {
|
||||
|
||||
break;
|
||||
|
@ -169,11 +169,11 @@ std::string recruit_unit(const gamemap& map, int side,
|
|||
" while datasource has checksum " <<
|
||||
rc << "\n";
|
||||
|
||||
config cfg_unit1;
|
||||
config cfg_unit1;
|
||||
new_unit.write(cfg_unit1);
|
||||
::write(std::cerr, cfg_unit1);
|
||||
//! @todo FIXME enabling this exception will trigger an assertion failure
|
||||
// in display.cpp:1010 when loading a map (the cause of that OOS
|
||||
// in display.cpp:1010 when loading a map (the cause of that OOS
|
||||
// will be fixed soon). (Only tested in SP for bug #9728)
|
||||
// if (!game_config::ignore_replay_errors) {
|
||||
// throw replay::error("OOS while recruiting.");
|
||||
|
@ -186,13 +186,13 @@ std::string recruit_unit(const gamemap& map, int side,
|
|||
set_random_results(cfg);
|
||||
}
|
||||
|
||||
// If an OOS happens, this option allows to write
|
||||
// If an OOS happens, this option allows to write
|
||||
// the debug info about the recruited unit.
|
||||
if(!lg::info.dont_log(lg::engine)) {
|
||||
config cfg_unit;
|
||||
config cfg_unit;
|
||||
new_unit.write(cfg_unit);
|
||||
|
||||
LOG_NG << "recruit unit\nChecksum = "
|
||||
LOG_NG << "recruit unit\nChecksum = "
|
||||
<< checksum << "\n-----[start data]-----\n";
|
||||
|
||||
::write(lg::info(lg::engine), cfg_unit);
|
||||
|
@ -229,7 +229,7 @@ battle_context::battle_context(const gamemap& map, const std::vector<team>& team
|
|||
const double harm_weight = 1.0 - aggression;
|
||||
|
||||
// A Python AI can send an invalid weapon and crash Wesnoth.
|
||||
// Haven't found a way for the Python API to prevent this problem.
|
||||
// Haven't found a way for the Python API to prevent this problem.
|
||||
// So instead of segfaulting it sends an assertion failure.
|
||||
wassert(attacker_weapon < static_cast<int>(attacker.attacks().size()));
|
||||
|
||||
|
@ -326,15 +326,15 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
return -1;
|
||||
if (choices.size() == 1)
|
||||
return choices[0];
|
||||
|
||||
// Multiple options:
|
||||
|
||||
// Multiple options:
|
||||
// First pass : get the best weight and the minimum simple rating for this weight.
|
||||
// simple rating = number of blows * damage per blows (resistance taken in account) * cth * weight
|
||||
// Elligible attacks for defense should have a simple rating greater or equal to this weight.
|
||||
|
||||
|
||||
double max_weight = 0.0;
|
||||
int min_rating = 0;
|
||||
|
||||
|
||||
for (i = 0; i < choices.size(); i++) {
|
||||
const attack_type &def = defender.attacks()[choices[i]];
|
||||
if (def.defense_weight() > max_weight) {
|
||||
|
@ -342,16 +342,16 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att,
|
||||
units, teams, status, map, gamedata);
|
||||
min_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
min_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
def_stats->chance_to_hit * def.defense_weight());
|
||||
|
||||
delete def_stats;
|
||||
}
|
||||
}
|
||||
else if (def.defense_weight() == max_weight) {
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att,
|
||||
units, teams, status, map, gamedata);
|
||||
int simple_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
int simple_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
def_stats->chance_to_hit * def.defense_weight());
|
||||
|
||||
if (simple_rating < min_rating )
|
||||
|
@ -374,9 +374,9 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
combatant *def_comb = new combatant(*def_stats, prev_def);
|
||||
att_comb->fight(*def_comb);
|
||||
|
||||
int simple_rating = static_cast<int>(def_stats->num_blows *
|
||||
int simple_rating = static_cast<int>(def_stats->num_blows *
|
||||
def_stats->damage * def_stats->chance_to_hit * def.defense_weight());
|
||||
|
||||
|
||||
if (simple_rating >= min_rating &&
|
||||
( !attacker_combatant_ || better_combat(*def_comb, *att_comb, *defender_combatant_, *attacker_combatant_, 1.0) )
|
||||
) {
|
||||
|
@ -738,10 +738,10 @@ void attack::fire_event(const std::string& n)
|
|||
a_ = units_.find(attacker_);
|
||||
d_ = units_.find(defender_);
|
||||
//! @todo 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' variables
|
||||
// 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' variables
|
||||
// could still be in bounds but point to a different attack.
|
||||
if(a_ == units_.end() || d_ == units_.end()) {
|
||||
if (update_display_){
|
||||
|
@ -762,7 +762,7 @@ void attack::refresh_bc()
|
|||
if(a_ == units_.end() || d_ == units_.end()) {
|
||||
return;
|
||||
}
|
||||
*bc_ = battle_context(map_, teams_, units_, state_, info_, attacker_, defender_, attack_with_, defend_with_);
|
||||
*bc_ = battle_context(map_, teams_, units_, state_, info_, attacker_, defender_, attack_with_, defend_with_);
|
||||
a_stats_ = &bc_->get_attacker_stats();
|
||||
d_stats_ = &bc_->get_defender_stats();
|
||||
attacker_cth_ = a_stats_->chance_to_hit;
|
||||
|
@ -1454,7 +1454,7 @@ void calculate_healing(game_display& disp, const gamemap& map,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// For heal amounts, only consider healers on side which is starting now.
|
||||
// Remove all healers not on this side.
|
||||
for(std::vector<std::pair<config*,gamemap::location> >::iterator h_it = heal.cfgs.begin(); h_it != heal.cfgs.end();) {
|
||||
|
@ -1724,7 +1724,7 @@ bool clear_shroud_loc(const gamemap& map, team& tm,
|
|||
if(map.on_board(adj[i]) || map.on_board(loc)) {
|
||||
const bool res = tm.clear_shroud(adj[i].x,adj[i].y) ||
|
||||
tm.clear_fog(adj[i].x,adj[i].y);
|
||||
|
||||
|
||||
if(res && cleared != NULL) {
|
||||
cleared->push_back(adj[i]);
|
||||
}
|
||||
|
@ -1765,7 +1765,7 @@ bool clear_shroud_unit(const gamemap& map,
|
|||
// Clear the location the unit is at
|
||||
clear_shroud_loc(map,teams[team],loc,&cleared_locations);
|
||||
|
||||
// Remove all redundant location.
|
||||
// Remove all redundant location.
|
||||
// If a unit is on this location, the sighed event is called twice.
|
||||
std::unique(cleared_locations.begin(),cleared_locations.end());
|
||||
|
||||
|
@ -1898,8 +1898,8 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
moves_left = 0;
|
||||
}
|
||||
|
||||
// If we use fog or shroud, see if we have sighted an enemy unit,
|
||||
// in which case we should stop immediately.
|
||||
// If we use fog or shroud, see if we have sighted an enemy unit,
|
||||
// in which case we should stop immediately.
|
||||
// Cannot use check shroud, because also need to check if delay shroud is on.
|
||||
if(should_clear_shroud && (team.uses_shroud() || team.uses_fog())) {
|
||||
if(units.count(*step) == 0 && !map.is_village(*step)) {
|
||||
|
@ -1908,7 +1908,7 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
// Temporarily reset the unit's moves to full
|
||||
const unit_movement_resetter move_resetter(ui->second);
|
||||
|
||||
// We have to swap out any unit that is already in the hex,
|
||||
// We have to swap out any unit that is already in the hex,
|
||||
// so we can put our unit there, then we'll swap back at the end.
|
||||
const temporary_unit_placer unit_placer(units,*step,ui->second);
|
||||
if( team.auto_shroud_updates()) {
|
||||
|
@ -1923,11 +1923,11 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
}
|
||||
}
|
||||
}
|
||||
// Check to see if the unit was deleted
|
||||
// Check to see if the unit was deleted
|
||||
// during a sighted event in clear_shroud_unit()
|
||||
ui = units.find(route.front());
|
||||
if(ui == units.end()) {
|
||||
//! @todo FIXME: the correct behavior for sighted event would be
|
||||
//! @todo FIXME: the correct behavior for sighted event would be
|
||||
// to halt movement, then fire "sighted" after firing "moveto" (see below).
|
||||
// However, since we have fired "sighted" during movement calculations
|
||||
// this is a workaround to prevent a crash.
|
||||
|
@ -1951,7 +1951,7 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
it->second.invisible(it->first,units,teams)) {
|
||||
discovered_unit = true;
|
||||
unit_ability_list hides = it->second.get_abilities("hides",it->first);
|
||||
for(std::vector<std::pair<config*,gamemap::location> >::const_iterator hide_it = hides.cfgs.begin();
|
||||
for(std::vector<std::pair<config*,gamemap::location> >::const_iterator hide_it = hides.cfgs.begin();
|
||||
hide_it != hides.cfgs.end(); ++hide_it) {
|
||||
ambushed_string =(*hide_it->first)["alert"];
|
||||
}
|
||||
|
@ -1994,8 +1994,8 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
if (next_unit != NULL)
|
||||
*next_unit = steps.back();
|
||||
|
||||
// Move the unit on the screen. Hide the unit in its current location,
|
||||
// but don't actually remove it until the move is done,
|
||||
// Move the unit on the screen. Hide the unit in its current location,
|
||||
// but don't actually remove it until the move is done,
|
||||
// so that while the unit is moving status etc.
|
||||
// will still display the correct number of units.
|
||||
unit_display::move_unit(map,steps,ui->second,teams);
|
||||
|
@ -2057,7 +2057,7 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
}
|
||||
|
||||
if(continue_move == false && seen_units.empty() == false) {
|
||||
// The message depends on how many units have been sighted,
|
||||
// The message depends on how many units have been sighted,
|
||||
// and whether they are allies or enemies, so calculate that out here
|
||||
int nfriends = 0, nenemies = 0;
|
||||
for(std::set<gamemap::location>::const_iterator i = seen_units.begin(); i != seen_units.end(); ++i) {
|
||||
|
@ -2080,8 +2080,8 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
|
|||
teams[team_num].see(u->second.side()-1);
|
||||
}
|
||||
|
||||
// The message we display is different depending on
|
||||
// whether the units sighted were enemies or friends,
|
||||
// The message we display is different depending on
|
||||
// whether the units sighted were enemies or friends,
|
||||
// and their respective number.
|
||||
utils::string_map symbols;
|
||||
symbols["friends"] = lexical_cast<std::string>(nfriends);
|
||||
|
@ -2188,7 +2188,7 @@ void apply_shroud_changes(undo_list& undos, game_display* disp, const gamestatus
|
|||
|
||||
std::vector<gamemap::location>::const_iterator step;
|
||||
for(step = un->route.begin(); step != un->route.end(); ++step) {
|
||||
// We have to swap out any unit that is already in the hex,
|
||||
// We have to swap out any unit that is already in the hex,
|
||||
// so we can put our unit there, then we'll swap back at the end.
|
||||
const temporary_unit_placer unit_placer(units,*step,un->affected_unit);
|
||||
clear_shroud_unit(map,status,gamedata,units,*step,teams,team,NULL,NULL);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file actions.hpp
|
||||
//! @file actions.hpp
|
||||
//! Various functions which implement in-game events and commands.
|
||||
|
||||
#ifndef ACTIONS_H_INCLUDED
|
||||
|
@ -40,17 +40,17 @@ class game_data;
|
|||
|
||||
bool can_recruit_on(const gamemap& map, const gamemap::location& leader, const gamemap::location loc);
|
||||
|
||||
//! Function which recruits a unit into the game.
|
||||
//! Function which recruits a unit into the game.
|
||||
// A copy of u will be created and inserted as the new recruited unit.
|
||||
// If need_castle is true, then the new unit must be on the same castle
|
||||
// as the leader of the team is on the keep of.
|
||||
//
|
||||
// If preferred_location is in a valid location, it will be used,
|
||||
// otherwise a valid location will be arbitrarily chosen.
|
||||
// If preferred_location is in a valid location, it will be used,
|
||||
// otherwise a valid location will be arbitrarily chosen.
|
||||
// If disp is not NULL, the new unit will be faded in.
|
||||
//
|
||||
// If the unit cannot be recruited, then a human-readable message
|
||||
// describing the reason will be returned.
|
||||
// describing the reason will be returned.
|
||||
// On success, the return string is empty.
|
||||
std::string recruit_unit(const gamemap& map, int team, unit_map& units,
|
||||
unit u, gamemap::location& recruit_location,bool show=false,
|
||||
|
@ -103,9 +103,9 @@ public:
|
|||
void dump() const;
|
||||
};
|
||||
|
||||
// If no attacker_weapon is given, we select the best one,
|
||||
// based on harm_weight (1.0 means 1 hp lost counters 1 hp damage,
|
||||
// 0.0 means we ignore harm weight).
|
||||
// If no attacker_weapon is given, we select the best one,
|
||||
// based on harm_weight (1.0 means 1 hp lost counters 1 hp damage,
|
||||
// 0.0 means we ignore harm weight).
|
||||
// prev_def is for predicting multiple attacks against a defender.
|
||||
battle_context(const gamemap& map, const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status, const game_data& gamedata,
|
||||
|
@ -191,7 +191,7 @@ class attack {
|
|||
battle_context* bc_;
|
||||
const battle_context::unit_stats* a_stats_;
|
||||
const battle_context::unit_stats* d_stats_;
|
||||
|
||||
|
||||
int orig_attacks_,orig_defends_;
|
||||
int n_attacks_,n_defends_;
|
||||
int attacker_cth_,defender_cth_;
|
||||
|
@ -199,12 +199,12 @@ class attack {
|
|||
int attackerxp_,defenderxp_;
|
||||
};
|
||||
|
||||
//! Given the location of a village, will return the 0-based index
|
||||
//! Given the location of a village, will return the 0-based index
|
||||
//! of the team that currently owns it, and -1 if it is unowned.
|
||||
int village_owner(const gamemap::location& loc, const std::vector<team>& teams);
|
||||
|
||||
//! Makes it so the village at the given location
|
||||
//! is owned by the given 0-based team number.
|
||||
//! Makes it so the village at the given location
|
||||
//! is owned by the given 0-based team number.
|
||||
//! Returns true if getting the village triggered a mutating event.
|
||||
bool get_village(const gamemap::location& loc, std::vector<team>& teams,
|
||||
size_t team_num, const unit_map& units, int *time_bonus = NULL);
|
||||
|
@ -219,51 +219,51 @@ unit_map::const_iterator find_leader(const unit_map& units, int side);
|
|||
//! @todo FIXME: Try moving this to unit::new_turn, then move it above calculate_healing().
|
||||
void reset_resting(unit_map& units, unsigned int side);
|
||||
|
||||
//! Calculates healing for all units for the given side.
|
||||
//! Calculates healing for all units for the given side.
|
||||
//! Should be called at the beginning of a side's turn.
|
||||
void calculate_healing(game_display& disp, const gamemap& map,
|
||||
unit_map& units, unsigned int side,
|
||||
const std::vector<team>& teams, bool update_display);
|
||||
|
||||
//! Function which, given the location of a unit that is advancing,
|
||||
//! and the name of the unit it is advancing to,
|
||||
//! Will return the advanced version of this unit.
|
||||
//! Function which, given the location of a unit that is advancing,
|
||||
//! and the name of the unit it is advancing to,
|
||||
//! Will return the advanced version of this unit.
|
||||
//! (with traits and items retained).
|
||||
unit get_advanced_unit(const game_data& info,
|
||||
unit_map& units,
|
||||
const gamemap::location& loc, const std::string& advance_to);
|
||||
|
||||
//! Function which will advance the unit at loc to 'advance_to'.
|
||||
// Note that 'loc' is not a reference, because if it were a reference,
|
||||
// we couldn't safely pass in a reference to the item in the map
|
||||
// Note that 'loc' is not a reference, because if it were a reference,
|
||||
// we couldn't safely pass in a reference to the item in the map
|
||||
// that we're going to delete, since deletion would invalidate the reference.
|
||||
void advance_unit(const game_data& info,
|
||||
unit_map& units,
|
||||
gamemap::location loc, const std::string& advance_to);
|
||||
|
||||
//! function which tests if the unit at loc is currently affected by leadership.
|
||||
//! function which tests if the unit at loc is currently affected by leadership.
|
||||
//! (i.e. has a higher-level 'leadership' unit next to it).
|
||||
//! If it does, then the location of the leader unit will be returned,
|
||||
//! If it does, then the location of the leader unit will be returned,
|
||||
//! Otherwise gamemap::location::null_location will be returned.
|
||||
//! If 'bonus' is not NULL, the % bonus will be stored in it.
|
||||
gamemap::location under_leadership(const unit_map& units,
|
||||
const gamemap::location& loc, int* bonus=NULL);
|
||||
|
||||
//! Checks to see if a side has won, and will throw
|
||||
//! an end_level_exception if one has.
|
||||
//! Checks to see if a side has won, and will throw
|
||||
//! an end_level_exception if one has.
|
||||
//! Will also remove control of villages from sides with dead leaders.
|
||||
void check_victory(unit_map& units, std::vector<team>& teams);
|
||||
|
||||
//! Gets the time of day at a certain tile.
|
||||
//! Certain tiles may have a time of day that differs
|
||||
//! from 'the' time of day, if a unit that illuminates
|
||||
//! Gets the time of day at a certain tile.
|
||||
//! Certain tiles may have a time of day that differs
|
||||
//! from 'the' time of day, if a unit that illuminates
|
||||
//! is in that tile or adjacent.
|
||||
time_of_day timeofday_at(const gamestatus& status,
|
||||
const unit_map& units,
|
||||
const gamemap::location& loc,
|
||||
const gamemap& map);
|
||||
|
||||
//! Returns the amount that a unit's damage should be multiplied by
|
||||
//! Returns the amount that a unit's damage should be multiplied by
|
||||
//! due to the current time of day.
|
||||
int combat_modifier(const gamestatus& status,
|
||||
const unit_map& units,
|
||||
|
@ -291,10 +291,10 @@ struct undo_action {
|
|||
|
||||
typedef std::deque<undo_action> undo_list;
|
||||
|
||||
//! function which moves a unit along the sequence of locations given by steps.
|
||||
//! function which moves a unit along the sequence of locations given by steps.
|
||||
//! If the unit cannot make it completely along the path this turn,
|
||||
//! a goto order will be set.
|
||||
//! If move_recorder is not NULL, the move will be recorded in it.
|
||||
//! a goto order will be set.
|
||||
//! If move_recorder is not NULL, the move will be recorded in it.
|
||||
//! If undos is not NULL, undo information will be added.
|
||||
size_t move_unit(game_display* disp, const game_data& gamedata,
|
||||
const gamestatus& status, const gamemap& map,
|
||||
|
@ -309,8 +309,8 @@ void recalculate_fog(const gamemap& map, const gamestatus& status,
|
|||
const game_data& gamedata,
|
||||
unit_map& units, std::vector<team>& teams, int team);
|
||||
|
||||
//! Function which will clear shroud away for the given 0-based team
|
||||
//! based on current unit positions.
|
||||
//! Function which will clear shroud away for the given 0-based team
|
||||
//! based on current unit positions.
|
||||
//! Returns true if some shroud is actually cleared away.
|
||||
bool clear_shroud(game_display& disp, const gamestatus& status,
|
||||
const gamemap& map, const game_data& gamedata,
|
||||
|
@ -321,7 +321,7 @@ bool clear_shroud(game_display& disp, const gamestatus& status,
|
|||
void apply_shroud_changes(undo_list& undos, game_display* disp, const gamestatus& status, const gamemap& map,
|
||||
const game_data& gamedata, unit_map& units, std::vector<team>& teams, int team);
|
||||
|
||||
//! Will return true iff the unit at 'loc' has any possible moves
|
||||
//! Will return true iff the unit at 'loc' has any possible moves
|
||||
//! it can do (including attacking etc).
|
||||
bool unit_can_move(const gamemap::location& loc, const unit_map& units,
|
||||
const gamemap& map, const std::vector<team>& teams);
|
||||
|
@ -332,14 +332,14 @@ namespace victory_conditions {
|
|||
}
|
||||
|
||||
//! Function to check if an attack will satisfy the requirements for backstab.
|
||||
//! Input:
|
||||
//! - the location from which the attack will occur,
|
||||
//! - the defending unit location,
|
||||
//! - the list of units on the map and
|
||||
//! Input:
|
||||
//! - the location from which the attack will occur,
|
||||
//! - the defending unit location,
|
||||
//! - the list of units on the map and
|
||||
//! - the list of teams.
|
||||
//! The defender and opposite units should be in place already.
|
||||
//! The attacking unit doesn't need to be, but if it isn't,
|
||||
//! an external check should be made to make sure the opposite unit
|
||||
//! The defender and opposite units should be in place already.
|
||||
//! The attacking unit doesn't need to be, but if it isn't,
|
||||
//! an external check should be made to make sure the opposite unit
|
||||
//! isn't also the attacker.
|
||||
bool backstab_check(const gamemap::location& attacker_loc,
|
||||
const gamemap::location& defender_loc,
|
||||
|
|
216
src/ai.cpp
216
src/ai.cpp
|
@ -4,7 +4,7 @@
|
|||
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 version
|
||||
it under the terms of the GNU General Public License version
|
||||
or at your option any later version2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
|
||||
//! @file ai.cpp
|
||||
//! @file ai.cpp
|
||||
//! Artificial intelligence - The computer commands the enemy.
|
||||
|
||||
#include "ai.hpp"
|
||||
|
@ -160,7 +160,7 @@ protected:
|
|||
|
||||
void do_recruitment() {
|
||||
const std::set<std::string>& options = current_team().recruits();
|
||||
if (!options.empty()) {
|
||||
if (!options.empty()) {
|
||||
const int choice = (rand()%options.size());
|
||||
std::set<std::string>::const_iterator i = options.begin();
|
||||
std::advance(i,choice);
|
||||
|
@ -190,8 +190,8 @@ std::vector<std::string> get_available_ais()
|
|||
ai_interface* create_ai(const std::string& name, ai_interface::info& info)
|
||||
{
|
||||
// To add an AI of your own, put
|
||||
// if(name == "my_ai")
|
||||
// return new my_ai(info);
|
||||
// if(name == "my_ai")
|
||||
// return new my_ai(info);
|
||||
// at the top of this function
|
||||
|
||||
if(name == "sample_ai")
|
||||
|
@ -237,7 +237,7 @@ bool ai::recruit_usage(const std::string& usage)
|
|||
|
||||
std::vector<std::string> options;
|
||||
|
||||
// Find an available unit that can be recruited,
|
||||
// Find an available unit that can be recruited,
|
||||
// matches the desired usage type, and comes in under budget.
|
||||
const std::set<std::string>& recruits = current_team().recruits();
|
||||
for(std::map<std::string,unit_type>::const_iterator i =
|
||||
|
@ -275,11 +275,11 @@ bool ai_interface::recruit(const std::string& unit_name, location loc)
|
|||
|
||||
const int num = std::distance(recruits.begin(),i);
|
||||
|
||||
// We have to add the recruit command now, because when the unit
|
||||
// is created it has to have the recruit command in the recorder
|
||||
// to be able to put random numbers into to generate unit traits.
|
||||
// We have to add the recruit command now, because when the unit
|
||||
// is created it has to have the recruit command in the recorder
|
||||
// to be able to put random numbers into to generate unit traits.
|
||||
// However, we're not sure if the transaction will be successful,
|
||||
// so use a replay_undo object to cancel it if we don't get
|
||||
// so use a replay_undo object to cancel it if we don't get
|
||||
// a confirmation for the transaction.
|
||||
recorder.add_recruit(num,loc);
|
||||
replay_undo replay_guard(recorder);
|
||||
|
@ -361,7 +361,7 @@ void ai_interface::log_message(const std::string& msg)
|
|||
}
|
||||
|
||||
|
||||
gamemap::location ai_interface::move_unit(location from, location to,
|
||||
gamemap::location ai_interface::move_unit(location from, location to,
|
||||
std::map<location,paths>& possible_moves)
|
||||
{
|
||||
const location loc = move_unit_partial(from,to,possible_moves);
|
||||
|
@ -421,7 +421,7 @@ gamemap::location ai_interface::move_unit_partial(location from, location to,
|
|||
}
|
||||
}
|
||||
|
||||
if(rt != p.routes.end()) {
|
||||
if(rt != p.routes.end()) {
|
||||
u_it->second.set_movement(rt->second.move_left);
|
||||
|
||||
std::vector<location> steps = rt->second.steps;
|
||||
|
@ -441,7 +441,7 @@ gamemap::location ai_interface::move_unit_partial(location from, location to,
|
|||
LOG_STREAM(err, ai) << "AI tried to move onto existing enemy unit at"<<*(steps.begin())<<"\n";
|
||||
// return(from);
|
||||
}
|
||||
|
||||
|
||||
// Check if there are any invisible units that we uncover
|
||||
for(std::vector<location>::iterator i = steps.begin()+1; i != steps.end(); ++i) {
|
||||
location adj[6];
|
||||
|
@ -450,9 +450,9 @@ gamemap::location ai_interface::move_unit_partial(location from, location to,
|
|||
size_t n;
|
||||
for(n = 0; n != 6; ++n) {
|
||||
|
||||
// See if there is an enemy unit next to this tile.
|
||||
// If it's invisible, we need to stop: we're ambushed.
|
||||
// If it's not, we must be a skirmisher, otherwise AI wouldn't try.
|
||||
// See if there is an enemy unit next to this tile.
|
||||
// If it's invisible, we need to stop: we're ambushed.
|
||||
// If it's not, we must be a skirmisher, otherwise AI wouldn't try.
|
||||
|
||||
// Or would it? If it doesn't cheat, it might...
|
||||
const unit_map::const_iterator u = info_.units.find(adj[n]);
|
||||
|
@ -522,7 +522,7 @@ gamemap::location ai_interface::move_unit_partial(location from, location to,
|
|||
|
||||
game_events::fire("moveto",to);
|
||||
|
||||
if((info_.teams.front().uses_fog() || info_.teams.front().uses_shroud()) &&
|
||||
if((info_.teams.front().uses_fog() || info_.teams.front().uses_shroud()) &&
|
||||
!info_.teams.front().fogged(to.x,to.y)) {
|
||||
game_events::fire("sighted",to);
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ bool ai::multistep_move_possible(location from, location to, location via,
|
|||
|
||||
int move_left = 0;
|
||||
|
||||
// See if the unit can make it to 'via', and if it can,
|
||||
// See if the unit can make it to 'via', and if it can,
|
||||
// how much movement it will have left when it gets there.
|
||||
const paths::routes_map::const_iterator itor = moves->second.routes.find(via);
|
||||
if(itor != moves->second.routes.end()) {
|
||||
|
@ -583,7 +583,7 @@ gamemap::location ai::move_unit(location from, location to, std::map<location,pa
|
|||
const unit_map::const_iterator i = units_.find(from);
|
||||
if(i != units_.end() && i->second.can_recruit()) {
|
||||
|
||||
// If the leader isn't on its keep, and we can move to the keep
|
||||
// If the leader isn't on its keep, and we can move to the keep
|
||||
// and still make our planned movement, then try doing that.
|
||||
const gamemap::location& start_pos = nearest_keep(i->first);
|
||||
|
||||
|
@ -596,7 +596,7 @@ gamemap::location ai::move_unit(location from, location to, std::map<location,pa
|
|||
|
||||
const unit_map::iterator itor = units_.find(from);
|
||||
if(itor != units_.end()) {
|
||||
// Just set the movement to one less than the maximum possible, since we know
|
||||
// Just set the movement to one less than the maximum possible, since we know
|
||||
// we can reach the destination, and we're going to move there immediately.
|
||||
itor->second.set_movement(itor->second.total_movement()-1);
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ bool ai::attack_close(const gamemap::location& loc) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void ai::attack_enemy(const location& attacking_unit, const location& target,
|
||||
void ai::attack_enemy(const location& attacking_unit, const location& target,
|
||||
int att_weapon, int def_weapon)
|
||||
{
|
||||
attacks_.insert(attacking_unit);
|
||||
|
@ -660,7 +660,7 @@ void ai_interface::calculate_possible_moves(std::map<location,paths>& res, move_
|
|||
|
||||
void ai_interface::calculate_moves(const unit_map& units, std::map<location,paths>& res, move_map& srcdst,
|
||||
move_map& dstsrc, bool enemy, bool assume_full_movement,
|
||||
const std::set<gamemap::location>* remove_destinations,
|
||||
const std::set<gamemap::location>* remove_destinations,
|
||||
bool see_all
|
||||
)
|
||||
{
|
||||
|
@ -753,7 +753,7 @@ namespace {
|
|||
|
||||
//! A structure for storing an item we're trying to protect.
|
||||
struct protected_item {
|
||||
protected_item(double value, int radius, const gamemap::location& loc) :
|
||||
protected_item(double value, int radius, const gamemap::location& loc) :
|
||||
value(value), radius(radius), loc(loc) {}
|
||||
|
||||
double value;
|
||||
|
@ -808,7 +808,7 @@ void ai::find_threats()
|
|||
}
|
||||
}
|
||||
|
||||
// Iterate over all protected locations, and if enemy units
|
||||
// Iterate over all protected locations, and if enemy units
|
||||
// are within the protection radius, set them as hostile targets.
|
||||
for(std::vector<protected_item>::const_iterator k = items.begin(); k != items.end(); ++k) {
|
||||
const protected_item& item = *k;
|
||||
|
@ -816,7 +816,7 @@ void ai::find_threats()
|
|||
for(unit_map::const_iterator u = units_.begin(); u != units_.end(); ++u) {
|
||||
const int distance = distance_between(u->first,item.loc);
|
||||
if(current_team().is_enemy(u->second.side()) && distance < item.radius) {
|
||||
add_target(target(u->first, item.value * double(item.radius-distance) /
|
||||
add_target(target(u->first, item.value * double(item.radius-distance) /
|
||||
double(item.radius),target::THREAT));
|
||||
}
|
||||
}
|
||||
|
@ -827,7 +827,7 @@ void ai::play_turn()
|
|||
{
|
||||
// Protect against a memory over commitment:
|
||||
//! @todo Not in the mood to figure out the exact cause:
|
||||
// For some reason -1 hitpoints cause a segmentation fault.
|
||||
// For some reason -1 hitpoints cause a segmentation fault.
|
||||
// If -1 hitpoints are sent, we crash :/
|
||||
try {
|
||||
consider_combat_ = true;
|
||||
|
@ -858,10 +858,10 @@ void ai::do_move()
|
|||
|
||||
const bool passive_leader = utils::string_bool(current_team().ai_parameters()["passive_leader"]);
|
||||
|
||||
if (passive_leader) {
|
||||
unit_map::iterator leader = find_leader(units_,team_num_);
|
||||
if(leader != units_.end()) {
|
||||
remove_unit_from_moves(leader->first,srcdst,dstsrc);
|
||||
if (passive_leader) {
|
||||
unit_map::iterator leader = find_leader(units_,team_num_);
|
||||
if(leader != units_.end()) {
|
||||
remove_unit_from_moves(leader->first,srcdst,dstsrc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1008,14 +1008,14 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
|
|||
double choice_rating = -1000.0;
|
||||
for(std::vector<attack_analysis>::iterator it = analysis.begin();
|
||||
it != analysis.end(); ++it) {
|
||||
|
||||
|
||||
if(skip_num > 0 && ((it - analysis.begin())%skip_num) && it->movements.size() > 1)
|
||||
continue;
|
||||
|
||||
const double rating = it->rating(current_team().aggression(),*this);
|
||||
LOG_AI << "attack option rated at " << rating << " ("
|
||||
LOG_AI << "attack option rated at " << rating << " ("
|
||||
<< current_team().aggression() << ")\n";
|
||||
|
||||
|
||||
if(rating > choice_rating) {
|
||||
choice_it = it;
|
||||
choice_rating = rating;
|
||||
|
@ -1043,7 +1043,7 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
|
|||
|
||||
// Recalc appropriate weapons here: AI uses approximations.
|
||||
battle_context bc(map_, teams_, units_, state_,
|
||||
gameinfo_, to, target_loc, -1, -1,
|
||||
gameinfo_, to, target_loc, -1, -1,
|
||||
current_team().aggression());
|
||||
attack_enemy(to, target_loc, bc.get_attacker_stats().attack_num,
|
||||
bc.get_defender_stats().attack_num);
|
||||
|
@ -1086,7 +1086,7 @@ void ai_interface::attack_enemy(const location& u, const location& target, int w
|
|||
if(defender != info_.units.end()) {
|
||||
const size_t defender_team = size_t(defender->second.side()) - 1;
|
||||
if(defender_team < info_.teams.size()) {
|
||||
dialogs::advance_unit(info_.gameinfo, info_.map, info_.units,
|
||||
dialogs::advance_unit(info_.gameinfo, info_.map, info_.units,
|
||||
target, info_.disp, !info_.teams[defender_team].is_human());
|
||||
}
|
||||
}
|
||||
|
@ -1101,7 +1101,7 @@ std::vector<std::pair<gamemap::location,gamemap::location> > ai::get_village_com
|
|||
std::map<gamemap::location,paths>& possible_moves, const move_map& srcdst,
|
||||
const move_map& dstsrc, const move_map& enemy_srcdst,
|
||||
const move_map& enemy_dstsrc, unit_map::const_iterator leader,
|
||||
std::set<gamemap::location>& taken_villages,
|
||||
std::set<gamemap::location>& taken_villages,
|
||||
std::set<gamemap::location>& moved_units,
|
||||
const std::vector<std::pair<gamemap::location,gamemap::location> >& village_moves,
|
||||
std::vector<std::pair<gamemap::location,
|
||||
|
@ -1113,7 +1113,7 @@ std::vector<std::pair<gamemap::location,gamemap::location> > ai::get_village_com
|
|||
|
||||
for(std::vector<std::pair<location,location> >::const_iterator i = start_at;
|
||||
i != village_moves.end(); ++i) {
|
||||
|
||||
|
||||
if(taken_villages.count(i->first) || moved_units.count(i->second)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1132,12 +1132,12 @@ std::vector<std::pair<gamemap::location,gamemap::location> > ai::get_village_com
|
|||
possible_moves, srcdst, dstsrc, enemy_srcdst, enemy_dstsrc, leader,
|
||||
taken_villages, moved_units, village_moves, i+1);
|
||||
|
||||
// The result is better if it results in getting more villages,
|
||||
// or if it results in the same number of villages,
|
||||
// The result is better if it results in getting more villages,
|
||||
// or if it results in the same number of villages,
|
||||
// but the leader ends closer to their keep.
|
||||
const bool result_better = res.size() >= result.size() ||
|
||||
res.size()+1 == result.size() &&
|
||||
distance != -1 &&
|
||||
const bool result_better = res.size() >= result.size() ||
|
||||
res.size()+1 == result.size() &&
|
||||
distance != -1 &&
|
||||
distance < leader_distance_from_keep;
|
||||
|
||||
if(result_better) {
|
||||
|
@ -1157,7 +1157,7 @@ std::vector<std::pair<gamemap::location,gamemap::location> > ai::get_village_com
|
|||
}
|
||||
|
||||
|
||||
bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves,
|
||||
bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc, const move_map& enemy_srcdst,
|
||||
const move_map& enemy_dstsrc, unit_map::iterator &leader)
|
||||
{
|
||||
|
@ -1171,13 +1171,13 @@ bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves,
|
|||
|
||||
std::map<location,double> vulnerability;
|
||||
|
||||
// We want to build up a list of possible moves we can make
|
||||
// We want to build up a list of possible moves we can make
|
||||
// that will capture villages.
|
||||
// Limit the moves to 'max_village_moves' to make sure
|
||||
// Limit the moves to 'max_village_moves' to make sure
|
||||
// things don't get out of hand.
|
||||
const size_t max_village_moves = 50;
|
||||
std::vector<std::pair<location,location> > village_moves;
|
||||
for(move_map::const_iterator j = dstsrc.begin();
|
||||
for(move_map::const_iterator j = dstsrc.begin();
|
||||
j != dstsrc.end() && village_moves.size() < max_village_moves; ++j) {
|
||||
|
||||
if(map_.is_village(j->first) == false) {
|
||||
|
@ -1200,20 +1200,20 @@ bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves,
|
|||
continue;
|
||||
}
|
||||
|
||||
// If it is a neutral village, and we have no leader,
|
||||
// If it is a neutral village, and we have no leader,
|
||||
// then the village is of no use to us, and we don't want it.
|
||||
if(!owned && leader == units_.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we have a decent amount of gold, and the leader can't access
|
||||
// the keep this turn if they get this village,
|
||||
// If we have a decent amount of gold, and the leader can't access
|
||||
// the keep this turn if they get this village,
|
||||
// then don't get this village with them.
|
||||
if(want_village &&
|
||||
leader != units_.end() &&
|
||||
current_team().gold() > 20 &&
|
||||
if(want_village &&
|
||||
leader != units_.end() &&
|
||||
current_team().gold() > 20 &&
|
||||
leader->first == j->second &&
|
||||
leader->first != start_pos &&
|
||||
leader->first != start_pos &&
|
||||
multistep_move_possible(j->second,j->first,start_pos,possible_moves) == false) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1246,17 +1246,17 @@ bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves,
|
|||
const std::vector<std::pair<location,location> >& moves = get_village_combinations(
|
||||
possible_moves, srcdst, dstsrc, enemy_srcdst, enemy_dstsrc, leader,
|
||||
taken_villages, moved_units, village_moves, village_moves.begin());
|
||||
|
||||
|
||||
LOG_AI << "get_villages() done: " << (SDL_GetTicks() - ticks) << "\n";
|
||||
|
||||
// Move all the units to get villages, however move the leader last,
|
||||
// Move all the units to get villages, however move the leader last,
|
||||
// so that the castle will be cleared if it wants to stop to recruit along the way.
|
||||
std::pair<location,location> leader_move;
|
||||
|
||||
int moves_made = 0;
|
||||
for(std::vector<std::pair<location,location> >::const_iterator i = moves.begin();
|
||||
for(std::vector<std::pair<location,location> >::const_iterator i = moves.begin();
|
||||
i != moves.end(); ++i) {
|
||||
|
||||
|
||||
if(leader != units_.end() && leader->first == i->second) {
|
||||
leader_move = *i;
|
||||
} else {
|
||||
|
@ -1272,7 +1272,7 @@ bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves,
|
|||
|
||||
const unit_map::const_iterator new_unit = units_.find(loc);
|
||||
|
||||
if(new_unit != units_.end() &&
|
||||
if(new_unit != units_.end() &&
|
||||
power_projection(i->first,enemy_dstsrc) >= new_unit->second.hitpoints()/4) {
|
||||
add_target(target(new_unit->first,1.0,target::SUPPORT));
|
||||
}
|
||||
|
@ -1300,8 +1300,8 @@ bool ai::get_healing(std::map<gamemap::location,paths>& possible_moves,
|
|||
for(; u_it != units_.end(); ++u_it) {
|
||||
unit& u = u_it->second;
|
||||
|
||||
// If the unit is on our side, has lost as many or more than
|
||||
// 1/2 round worth of healing, and doesn't regenerate itself,
|
||||
// If the unit is on our side, has lost as many or more than
|
||||
// 1/2 round worth of healing, and doesn't regenerate itself,
|
||||
// then try to find a vacant village for it to rest in.
|
||||
if(u.side() == team_num_ &&
|
||||
u.max_hitpoints() - u.hitpoints() >= game_config::poison_amount/2 &&
|
||||
|
@ -1351,12 +1351,12 @@ bool ai::should_retreat(const gamemap::location& loc, const unit_map::const_iter
|
|||
return false;
|
||||
}
|
||||
|
||||
const double optimal_terrain = best_defensive_position(un->first, dstsrc,
|
||||
const double optimal_terrain = best_defensive_position(un->first, dstsrc,
|
||||
srcdst, enemy_dstsrc).chance_to_hit/100.0;
|
||||
const double proposed_terrain =
|
||||
const double proposed_terrain =
|
||||
un->second.defense_modifier(map_.get_terrain(loc))/100.0;
|
||||
|
||||
// The 'exposure' is the additional % chance to hit
|
||||
// The 'exposure' is the additional % chance to hit
|
||||
// this unit receives from being on a sub-optimal defensive terrain.
|
||||
const double exposure = proposed_terrain - optimal_terrain;
|
||||
|
||||
|
@ -1382,22 +1382,22 @@ bool ai::retreat_units(std::map<gamemap::location,paths>& possible_moves,
|
|||
}
|
||||
|
||||
for(unit_map::iterator i = units_.begin(); i != units_.end(); ++i) {
|
||||
if(i->second.side() == team_num_ &&
|
||||
i->second.movement_left() == i->second.total_movement() &&
|
||||
unit_map::const_iterator(i) != leader &&
|
||||
if(i->second.side() == team_num_ &&
|
||||
i->second.movement_left() == i->second.total_movement() &&
|
||||
unit_map::const_iterator(i) != leader &&
|
||||
!i->second.incapacitated()) {
|
||||
|
||||
// This unit still has movement left, and is a candidate to retreat.
|
||||
// We see the amount of power of each side on the situation,
|
||||
// This unit still has movement left, and is a candidate to retreat.
|
||||
// We see the amount of power of each side on the situation,
|
||||
// and decide whether it should retreat.
|
||||
if(should_retreat(i->first, i, fullmove_srcdst, fullmove_dstsrc,
|
||||
enemy_dstsrc, current_team().caution())) {
|
||||
|
||||
bool can_reach_leader = false;
|
||||
|
||||
// Time to retreat. Look for the place where the power balance
|
||||
// Time to retreat. Look for the place where the power balance
|
||||
// is most in our favor.
|
||||
// If we can't find anywhere where we like the power balance,
|
||||
// If we can't find anywhere where we like the power balance,
|
||||
// just try to get to the best defensive hex.
|
||||
typedef move_map::const_iterator Itor;
|
||||
std::pair<Itor,Itor> itors = srcdst.equal_range(i->first);
|
||||
|
@ -1414,8 +1414,8 @@ bool ai::retreat_units(std::map<gamemap::location,paths>& possible_moves,
|
|||
break;
|
||||
}
|
||||
|
||||
// We rate the power balance of a hex based on our power projection
|
||||
// compared to theirs, multiplying their power projection by their
|
||||
// We rate the power balance of a hex based on our power projection
|
||||
// compared to theirs, multiplying their power projection by their
|
||||
// chance to hit us on the hex we're planning to flee to.
|
||||
const gamemap::location& hex = itors.first->second;
|
||||
const int defense = i->second.defense_modifier(map_.get_terrain(hex));
|
||||
|
@ -1438,7 +1438,7 @@ bool ai::retreat_units(std::map<gamemap::location,paths>& possible_moves,
|
|||
++itors.first;
|
||||
}
|
||||
|
||||
// If the unit is in range of its leader, it should
|
||||
// If the unit is in range of its leader, it should
|
||||
// never retreat -- it has to defend the leader instead.
|
||||
if(can_reach_leader) {
|
||||
continue;
|
||||
|
@ -1488,7 +1488,7 @@ bool ai::move_to_targets(std::map<gamemap::location, paths>& possible_moves,
|
|||
LOG_AI << "choosing move...\n";
|
||||
std::pair<location,location> move = choose_move(targets, srcdst,
|
||||
dstsrc, enemy_dstsrc);
|
||||
|
||||
|
||||
for(std::vector<target>::const_iterator ittg = targets.begin();
|
||||
ittg != targets.end(); ++ittg) {
|
||||
wassert(map_.on_board(ittg->loc));
|
||||
|
@ -1506,8 +1506,8 @@ bool ai::move_to_targets(std::map<gamemap::location, paths>& possible_moves,
|
|||
|
||||
const location arrived_at = move_unit(move.first,move.second,possible_moves);
|
||||
|
||||
// We didn't arrive at our intended destination.
|
||||
// We return true, meaning that the AI algorithm
|
||||
// We didn't arrive at our intended destination.
|
||||
// We return true, meaning that the AI algorithm
|
||||
// should be recalculated from the start.
|
||||
if(arrived_at != move.second) {
|
||||
LOG_STREAM(warn, ai) << "didn't arrive at destination\n";
|
||||
|
@ -1519,7 +1519,7 @@ bool ai::move_to_targets(std::map<gamemap::location, paths>& possible_moves,
|
|||
if (u_it == units_.end() || u_it->second.incapacitated()) {
|
||||
LOG_STREAM(warn, ai) << "stolen or incapacitated\n";
|
||||
} else {
|
||||
// Search to see if there are any enemy units next to the tile
|
||||
// Search to see if there are any enemy units next to the tile
|
||||
// which really should be attacked now the move is done.
|
||||
gamemap::location adj[6];
|
||||
get_adjacent_tiles(arrived_at,adj);
|
||||
|
@ -1543,7 +1543,7 @@ bool ai::move_to_targets(std::map<gamemap::location, paths>& possible_moves,
|
|||
}
|
||||
}
|
||||
|
||||
// Don't allow any other units to move onto the tile
|
||||
// Don't allow any other units to move onto the tile
|
||||
// our unit just moved onto
|
||||
typedef move_map::iterator Itor;
|
||||
std::pair<Itor,Itor> del = dstsrc.equal_range(arrived_at);
|
||||
|
@ -1556,7 +1556,7 @@ bool ai::move_to_targets(std::map<gamemap::location, paths>& possible_moves,
|
|||
int ai::average_resistance_against(const unit_type& a, const unit_type& b) const
|
||||
{
|
||||
int weighting_sum = 0, defense = 0;
|
||||
const std::map<t_translation::t_letter, size_t>& terrain =
|
||||
const std::map<t_translation::t_letter, size_t>& terrain =
|
||||
map_.get_weighted_terrain_frequencies();
|
||||
|
||||
for (std::map<t_translation::t_letter, size_t>::const_iterator j = terrain.begin(),
|
||||
|
@ -1570,10 +1570,10 @@ int ai::average_resistance_against(const unit_type& a, const unit_type& b) const
|
|||
}
|
||||
|
||||
if (weighting_sum == 0) {
|
||||
// This unit can't move on this map, so just get the average weighted
|
||||
// of all available terrains. This still is a kind of silly
|
||||
// This unit can't move on this map, so just get the average weighted
|
||||
// of all available terrains. This still is a kind of silly
|
||||
// since the opponent probably can't recruit this unit and it's a static unit.
|
||||
for (std::map<t_translation::t_letter, size_t>::const_iterator jj = terrain.begin(),
|
||||
for (std::map<t_translation::t_letter, size_t>::const_iterator jj = terrain.begin(),
|
||||
jj_end = terrain.end(); jj != jj_end; ++jj)
|
||||
{
|
||||
defense += a.movement_type().defense_modifier(map_, jj->first) * jj->second;
|
||||
|
@ -1611,7 +1611,7 @@ int ai::average_resistance_against(const unit_type& a, const unit_type& b) const
|
|||
prob = prob * (100 - cth) / 100;
|
||||
// Assume poison works one turn.
|
||||
int poison_damage = game_config::poison_amount * (10000 - prob);
|
||||
// As poison works irrespective of the resistance, its relative damage
|
||||
// As poison works irrespective of the resistance, its relative damage
|
||||
// (and hence weight) is "poison_damage / (cth * resistance)".
|
||||
sum += poison_damage;
|
||||
weight_sum += poison_damage / (cth * resistance);
|
||||
|
@ -1686,8 +1686,8 @@ void ai::analyze_potential_recruit_combat()
|
|||
}
|
||||
}
|
||||
|
||||
// Recommend not to use units of a certain usage type
|
||||
// if they have a score more than 1000 below
|
||||
// Recommend not to use units of a certain usage type
|
||||
// if they have a score more than 1000 below
|
||||
// the best unit of that usage type.
|
||||
for(i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
const game_data::unit_type_map::const_iterator info = gameinfo_.unit_types.find(*i);
|
||||
|
@ -1772,7 +1772,7 @@ void ai::analyze_potential_recruit_movements()
|
|||
LOG_AI << "analyzing '" << *i << "' getting to target...\n";
|
||||
const paths::route& route = a_star_search(start, t->loc, 100.0, &calc,
|
||||
get_info().map.w(), get_info().map.h());
|
||||
|
||||
|
||||
if(route.steps.empty() == false) {
|
||||
LOG_AI << "made it: " << route.move_left << "\n";
|
||||
cost += route.move_left;
|
||||
|
@ -1798,12 +1798,12 @@ void ai::analyze_potential_recruit_movements()
|
|||
}
|
||||
}
|
||||
|
||||
for(std::map<std::string,int>::iterator j = unit_movement_scores_.begin();
|
||||
for(std::map<std::string,int>::iterator j = unit_movement_scores_.begin();
|
||||
j != unit_movement_scores_.end(); ++j) {
|
||||
|
||||
|
||||
const game_data::unit_type_map::const_iterator info =
|
||||
gameinfo_.unit_types.find(j->first);
|
||||
|
||||
|
||||
if(info == gameinfo_.unit_types.end()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1839,8 +1839,8 @@ void ai::do_recruitment()
|
|||
|
||||
size_t neutral_villages = 0;
|
||||
|
||||
// We recruit the initial allocation of scouts
|
||||
// based on how many neutral villages there are
|
||||
// We recruit the initial allocation of scouts
|
||||
// based on how many neutral villages there are
|
||||
// that are closer to us than to other keeps.
|
||||
const std::vector<location>& villages = map_.villages();
|
||||
for(std::vector<location>::const_iterator v = villages.begin(); v != villages.end(); ++v) {
|
||||
|
@ -1864,9 +1864,9 @@ void ai::do_recruitment()
|
|||
}
|
||||
}
|
||||
|
||||
// The villages per scout is for a two-side battle,
|
||||
// accounting for all neutral villages on the map.
|
||||
// We only look at villages closer to us, so we halve it,
|
||||
// The villages per scout is for a two-side battle,
|
||||
// accounting for all neutral villages on the map.
|
||||
// We only look at villages closer to us, so we halve it,
|
||||
// making us get twice as many scouts.
|
||||
const int villages_per_scout = current_team().villages_per_scout()/2;
|
||||
|
||||
|
@ -1948,7 +1948,7 @@ void ai::move_leader_to_goals( const move_map& enemy_dstsrc)
|
|||
gamemap::location loc;
|
||||
for(std::vector<gamemap::location>::const_iterator itor = route.steps.begin();
|
||||
itor != route.steps.end(); ++itor) {
|
||||
|
||||
|
||||
if(leader_paths.routes.count(*itor) == 1 &&
|
||||
power_projection(*itor,enemy_dstsrc) < double(leader->second.hitpoints()/2)) {
|
||||
loc = *itor;
|
||||
|
@ -1982,27 +1982,27 @@ void ai::move_leader_to_keep(const move_map& enemy_dstsrc)
|
|||
if(itor != leader_paths.routes.end() && units_.count(start_pos) == 0) {
|
||||
move_unit(leader->first,start_pos,possible_moves);
|
||||
} else {
|
||||
// Make a map of the possible locations the leader can move to,
|
||||
// Make a map of the possible locations the leader can move to,
|
||||
// ordered by the distance from the keep.
|
||||
std::multimap<int,gamemap::location> moves_toward_keep;
|
||||
|
||||
// The leader can't move to his keep, try to move to the closest location
|
||||
// The leader can't move to his keep, try to move to the closest location
|
||||
// to the keep where there are no enemies in range.
|
||||
const int current_distance = distance_between(leader->first,start_pos);
|
||||
for(paths::routes_map::const_iterator i = leader_paths.routes.begin();
|
||||
i != leader_paths.routes.end(); ++i) {
|
||||
|
||||
|
||||
const int new_distance = distance_between(i->first,start_pos);
|
||||
if(new_distance < current_distance) {
|
||||
moves_toward_keep.insert(std::pair<int,gamemap::location>(new_distance,i->first));
|
||||
}
|
||||
}
|
||||
|
||||
// Find the first location which we can move to,
|
||||
// Find the first location which we can move to,
|
||||
// without the threat of enemies.
|
||||
for(std::multimap<int,gamemap::location>::const_iterator j = moves_toward_keep.begin();
|
||||
j != moves_toward_keep.end(); ++j) {
|
||||
|
||||
|
||||
if(enemy_dstsrc.count(j->second) == 0) {
|
||||
move_unit(leader->first,j->second,possible_moves);
|
||||
break;
|
||||
|
@ -2032,7 +2032,7 @@ void ai::move_leader_after_recruit(const move_map& /*srcdst*/,
|
|||
// See if we want to ward any enemy units off from getting our villages.
|
||||
for(move_map::const_iterator i = enemy_dstsrc.begin(); i != enemy_dstsrc.end(); ++i) {
|
||||
|
||||
// If this is a village of ours, that an enemy can capture
|
||||
// If this is a village of ours, that an enemy can capture
|
||||
// on their turn, and which we might be able to reach in two turns.
|
||||
if(map_.is_village(i->first) && current_team().owns_village(i->first) &&
|
||||
int(distance_between(i->first,leader->first)) <= leader->second.total_movement()*2) {
|
||||
|
@ -2042,7 +2042,7 @@ void ai::move_leader_after_recruit(const move_map& /*srcdst*/,
|
|||
|
||||
for(paths::routes_map::const_iterator j = leader_paths.routes.begin();
|
||||
j != leader_paths.routes.end(); ++j) {
|
||||
|
||||
|
||||
const int distance = distance_between(i->first,j->first);
|
||||
if(distance < current_distance && is_accessible(j->first,enemy_dstsrc) == false) {
|
||||
current_distance = distance;
|
||||
|
@ -2050,7 +2050,7 @@ void ai::move_leader_after_recruit(const move_map& /*srcdst*/,
|
|||
}
|
||||
}
|
||||
|
||||
// If this location is in range of the village,
|
||||
// If this location is in range of the village,
|
||||
// then we consider moving to it
|
||||
if(current_loc.valid()) {
|
||||
LOG_AI << "considering movement to " << str_cast(current_loc.x + 1)
|
||||
|
@ -2067,7 +2067,7 @@ void ai::move_leader_after_recruit(const move_map& /*srcdst*/,
|
|||
}
|
||||
}
|
||||
|
||||
// See if any friendly leaders can make it to our keep.
|
||||
// See if any friendly leaders can make it to our keep.
|
||||
// If they can, then move off it, so that they can recruit if they want.
|
||||
if(nearest_keep(leader->first) == leader->first) {
|
||||
const location keep = leader->first;
|
||||
|
@ -2097,12 +2097,12 @@ void ai::move_leader_after_recruit(const move_map& /*srcdst*/,
|
|||
location adj[6];
|
||||
get_adjacent_tiles(keep,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
// Vacate to the first location found that is on the board,
|
||||
// Vacate to the first location found that is on the board,
|
||||
// our leader can move to, and no enemies can reach.
|
||||
if(map_.on_board(adj[n]) &&
|
||||
leader_paths.routes.count(adj[n]) != 0 &&
|
||||
is_accessible(adj[n],enemy_dstsrc) == false) {
|
||||
|
||||
|
||||
move_unit(keep,adj[n],possible_moves);
|
||||
return;
|
||||
}
|
||||
|
@ -2190,7 +2190,7 @@ const ai::defensive_position& ai::best_defensive_position(const gamemap::locatio
|
|||
|
||||
const std::map<location,defensive_position>::const_iterator position =
|
||||
defensive_position_cache_.find(loc);
|
||||
|
||||
|
||||
if(position != defensive_position_cache_.end()) {
|
||||
return position->second;
|
||||
}
|
||||
|
@ -2240,7 +2240,7 @@ bool ai::is_accessible(const location& loc, const move_map& dstsrc) const
|
|||
const std::set<gamemap::location>& ai::keeps()
|
||||
{
|
||||
if(keeps_.empty()) {
|
||||
// Generate the list of keeps:
|
||||
// Generate the list of keeps:
|
||||
// iterate over the entire map and find all keeps.
|
||||
for(size_t x = 0; x != size_t(map_.w()); ++x) {
|
||||
for(size_t y = 0; y != size_t(map_.h()); ++y) {
|
||||
|
|
90
src/ai.hpp
90
src/ai.hpp
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file ai.hpp
|
||||
//! @file ai.hpp
|
||||
//!
|
||||
|
||||
#ifndef AI_HPP_INCLUDED
|
||||
|
@ -64,24 +64,24 @@ protected:
|
|||
|
||||
virtual void do_move();
|
||||
|
||||
virtual bool do_combat(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc,
|
||||
virtual bool do_combat(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc,
|
||||
const move_map& enemy_srcdst, const move_map& enemy_dstsrc);
|
||||
virtual bool get_villages(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc,
|
||||
const move_map& enemy_srcdst, const move_map& enemy_dstsrc,
|
||||
virtual bool get_villages(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc,
|
||||
const move_map& enemy_srcdst, const move_map& enemy_dstsrc,
|
||||
unit_map::iterator &leader);
|
||||
virtual bool get_healing(std::map<gamemap::location,paths>& possible_moves,
|
||||
virtual bool get_healing(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& enemy_dstsrc);
|
||||
virtual bool retreat_units(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc,
|
||||
virtual bool retreat_units(std::map<gamemap::location,paths>& possible_moves,
|
||||
const move_map& srcdst, const move_map& dstsrc,
|
||||
const move_map& enemy_dstsrc, unit_map::const_iterator leader);
|
||||
virtual bool move_to_targets(std::map<gamemap::location,paths>& possible_moves,
|
||||
move_map& srcdst, move_map& dstsrc, const move_map& enemy_dstsrc,
|
||||
virtual bool move_to_targets(std::map<gamemap::location,paths>& possible_moves,
|
||||
move_map& srcdst, move_map& dstsrc, const move_map& enemy_dstsrc,
|
||||
unit_map::const_iterator leader);
|
||||
|
||||
virtual bool should_retreat(const gamemap::location& loc,
|
||||
const unit_map::const_iterator un, const move_map& srcdst,
|
||||
virtual bool should_retreat(const gamemap::location& loc,
|
||||
const unit_map::const_iterator un, const move_map& srcdst,
|
||||
const move_map& dstsrc, const move_map& enemy_dstsrc, double caution);
|
||||
|
||||
virtual void do_recruitment();
|
||||
|
@ -89,10 +89,10 @@ protected:
|
|||
virtual void move_leader_to_keep(const move_map& enemy_dstsrc);
|
||||
virtual void move_leader_after_recruit(const move_map& srcdst,
|
||||
const move_map& dstsrc, const move_map& enemy_dstsrc);
|
||||
|
||||
|
||||
virtual void move_leader_to_goals(const move_map& enemy_dstsrc);
|
||||
|
||||
|
||||
|
||||
virtual bool recruit_usage(const std::string& usage);
|
||||
|
||||
virtual bool desperate_attack(const gamemap::location &loc);
|
||||
|
@ -106,26 +106,26 @@ protected:
|
|||
|
||||
//! Calculate which movements should be made to get an optimal number of villages.
|
||||
std::vector<std::pair<gamemap::location,gamemap::location> > get_village_combinations(
|
||||
std::map<gamemap::location,paths>& possible_moves, const move_map& srcdst,
|
||||
const move_map& dstsrc, const move_map& enemy_srcdst,
|
||||
std::map<gamemap::location,paths>& possible_moves, const move_map& srcdst,
|
||||
const move_map& dstsrc, const move_map& enemy_srcdst,
|
||||
const move_map& enemy_dstsrc, unit_map::const_iterator leader,
|
||||
std::set<location>& taken_villages, std::set<location>& moved_units,
|
||||
const std::vector<std::pair<gamemap::location,gamemap::location> >& village_moves,
|
||||
std::vector<std::pair<gamemap::location,gamemap::location> >::const_iterator start_at);
|
||||
|
||||
|
||||
//! Our own version of 'move_unit'. It is like the version in ai_interface,
|
||||
//! Our own version of 'move_unit'. It is like the version in ai_interface,
|
||||
//! however if it is the leader moving, it will first attempt recruitment.
|
||||
location move_unit(location from, location to, std::map<location,paths>& possible_moves);
|
||||
|
||||
//! Our own version of 'attack_enemy'. We record all attacks to support group attacking.
|
||||
void attack_enemy(const location& attacking_unit, const location& target,
|
||||
void attack_enemy(const location& attacking_unit, const location& target,
|
||||
int att_weapon, int def_weapon);
|
||||
|
||||
std::set<location> attacks_;
|
||||
|
||||
//! Sees if it's possible for a unit to move 'from' -> 'via' -> 'to' all in one turn.
|
||||
bool multistep_move_possible(location from, location to, location via,
|
||||
bool multistep_move_possible(location from, location to, location via,
|
||||
std::map<location,paths>& possible_moves);
|
||||
|
||||
struct attack_analysis
|
||||
|
@ -196,16 +196,16 @@ protected:
|
|||
);
|
||||
|
||||
|
||||
//! Function which finds how much 'power' a side can attack a certain location with.
|
||||
//! This is basically the maximum hp of damage that can be inflicted upon a unit on loc
|
||||
//! by full-health units, multiplied by the defense these units will have.
|
||||
//! Function which finds how much 'power' a side can attack a certain location with.
|
||||
//! This is basically the maximum hp of damage that can be inflicted upon a unit on loc
|
||||
//! by full-health units, multiplied by the defense these units will have.
|
||||
//! (if 'use_terrain' is false, then it will be multiplied by 0.5)
|
||||
//
|
||||
// Example: 'loc' can be reached by two units, one of whom has a 10-3 attack
|
||||
// and has 48/48 hp, and can defend at 40% on the adjacent grassland.
|
||||
// The other has a 8-2 attack, and has 30/40 hp, and can defend at 60% on the adjacent mountain.
|
||||
// Example: 'loc' can be reached by two units, one of whom has a 10-3 attack
|
||||
// and has 48/48 hp, and can defend at 40% on the adjacent grassland.
|
||||
// The other has a 8-2 attack, and has 30/40 hp, and can defend at 60% on the adjacent mountain.
|
||||
// The rating will be 10*3*1.0*0.4 + 8*2*0.75*0.6 = 19.2
|
||||
virtual double power_projection(const gamemap::location& loc, const move_map& dstsrc,
|
||||
virtual double power_projection(const gamemap::location& loc, const move_map& dstsrc,
|
||||
bool use_terrain=true) const;
|
||||
|
||||
virtual std::vector<attack_analysis> analyze_targets(
|
||||
|
@ -215,7 +215,7 @@ protected:
|
|||
|
||||
bool is_accessible(const location& loc, const move_map& dstsrc) const;
|
||||
|
||||
virtual std::vector<target> find_targets(unit_map::const_iterator leader,
|
||||
virtual std::vector<target> find_targets(unit_map::const_iterator leader,
|
||||
const move_map& enemy_dstsrc);
|
||||
|
||||
//! Function to form a group of units suitable for moving along the route, 'route'.
|
||||
|
@ -235,7 +235,7 @@ protected:
|
|||
const std::vector<location>& battlefield) const;
|
||||
|
||||
virtual double compare_groups(const std::set<location>& our_group,
|
||||
const std::set<location>& enemy_groups,
|
||||
const std::set<location>& enemy_groups,
|
||||
const std::vector<location>& battlefield) const;
|
||||
|
||||
virtual std::pair<location,location> choose_move(std::vector<target>& targets,
|
||||
|
@ -256,33 +256,33 @@ protected:
|
|||
|
||||
void add_target(const target& tgt) { additional_targets_.push_back(tgt); }
|
||||
|
||||
//! Analyze all the units that this side can recruit
|
||||
//! and rate their movement types.
|
||||
//! Ratings will be placed in 'unit_movement_scores_',
|
||||
//! with lower scores being better,
|
||||
//! Analyze all the units that this side can recruit
|
||||
//! and rate their movement types.
|
||||
//! Ratings will be placed in 'unit_movement_scores_',
|
||||
//! with lower scores being better,
|
||||
//! and the lowest possible rating being '10'.
|
||||
virtual void analyze_potential_recruit_movements();
|
||||
|
||||
std::map<std::string,int> unit_movement_scores_;
|
||||
std::set<std::string> not_recommended_units_;
|
||||
|
||||
//! Analyze all the units that this side can recruit
|
||||
//! and rate their fighting suitability against enemy units.
|
||||
//! Ratings will be placed in 'unit_combat_scores_',
|
||||
//! with a '0' rating indicating that the unit is 'average' against enemy units,
|
||||
//! negative ratings meaning they are poorly suited,
|
||||
//! Analyze all the units that this side can recruit
|
||||
//! and rate their fighting suitability against enemy units.
|
||||
//! Ratings will be placed in 'unit_combat_scores_',
|
||||
//! with a '0' rating indicating that the unit is 'average' against enemy units,
|
||||
//! negative ratings meaning they are poorly suited,
|
||||
//! and positive ratings meaning they are well suited.
|
||||
virtual void analyze_potential_recruit_combat();
|
||||
|
||||
std::map<std::string,int> unit_combat_scores_;
|
||||
|
||||
//! Rates two unit types for their suitability against each other.
|
||||
// Returns 0 if the units are equally matched,
|
||||
// a positive number if a is suited against b,
|
||||
// Returns 0 if the units are equally matched,
|
||||
// a positive number if a is suited against b,
|
||||
// and a negative number if b is suited against a.
|
||||
virtual int compare_unit_types(const unit_type& a, const unit_type& b) const;
|
||||
|
||||
//! calculates the average resistance unit type a has
|
||||
//! calculates the average resistance unit type a has
|
||||
//! against the attacks of unit type b.
|
||||
virtual int average_resistance_against(const unit_type& a, const unit_type& b) const;
|
||||
|
||||
|
@ -292,14 +292,14 @@ protected:
|
|||
|
||||
std::set<location> keeps_;
|
||||
|
||||
//! Function which, given a unit position,
|
||||
//! and a position the unit wants to get to in two turns,
|
||||
//! will return all possible positions the unit can move to,
|
||||
//! Function which, given a unit position,
|
||||
//! and a position the unit wants to get to in two turns,
|
||||
//! will return all possible positions the unit can move to,
|
||||
//! that will make the destination position accessible next turn.
|
||||
void access_points(const move_map& srcdst, const location& u,
|
||||
const location& dst, std::vector<location>& out);
|
||||
|
||||
//! Function which gets the areas of the map
|
||||
//! Function which gets the areas of the map
|
||||
//! that this AI has been instructed to avoid.
|
||||
const std::set<location>& avoided_locations();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
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 version
|
||||
it under the terms of the GNU General Public License version
|
||||
or at your option any later version2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
@ -77,7 +77,7 @@ void ai::do_attack_analysis(
|
|||
wassert(unit_itor != units_.end());
|
||||
|
||||
// See if the unit has the backstab ability.
|
||||
// Units with backstab will want to try to have a
|
||||
// Units with backstab will want to try to have a
|
||||
// friendly unit opposite the position they move to.
|
||||
//
|
||||
// See if the unit has the slow ability -- units with slow only attack first.
|
||||
|
@ -99,10 +99,10 @@ void ai::do_attack_analysis(
|
|||
continue;
|
||||
}
|
||||
|
||||
// Check if the friendly unit is surrounded,
|
||||
// A unit is surrounded if it is flanked by enemy units
|
||||
// and at least one other enemy unit is nearby
|
||||
// or if the unit is totaly surrounded by enemies
|
||||
// Check if the friendly unit is surrounded,
|
||||
// A unit is surrounded if it is flanked by enemy units
|
||||
// and at least one other enemy unit is nearby
|
||||
// or if the unit is totaly surrounded by enemies
|
||||
// with max. one tile to escape.
|
||||
bool is_surrounded = false;
|
||||
bool is_flanked = false;
|
||||
|
@ -182,12 +182,12 @@ void ai::do_attack_analysis(
|
|||
if(tiles[(j+3)%6] != current_unit) {
|
||||
const unit_map::const_iterator itor = units_.find(tiles[(j+3)%6]);
|
||||
|
||||
// Note that we *could* also check if a unit plans to move there
|
||||
// before we're at this stage, but we don't because, since the
|
||||
// attack calculations don't actually take backstab into account (too complicated),
|
||||
// Note that we *could* also check if a unit plans to move there
|
||||
// before we're at this stage, but we don't because, since the
|
||||
// attack calculations don't actually take backstab into account (too complicated),
|
||||
// this could actually make our analysis look *worse* instead of better.
|
||||
// So we only check for 'concrete' backstab opportunities.
|
||||
// That would also break backstab_check, since it assumes
|
||||
// That would also break backstab_check, since it assumes
|
||||
// the defender is in place.
|
||||
if(itor != units_.end() &&
|
||||
backstab_check(tiles[j], loc, units_, teams_)) {
|
||||
|
@ -210,12 +210,12 @@ void ai::do_attack_analysis(
|
|||
// Find out how vulnerable we are to attack from enemy units in this hex.
|
||||
const double vulnerability = power_projection(tiles[j],enemy_dstsrc);
|
||||
|
||||
// Calculate how much support we have on this hex from allies.
|
||||
// Support does not take into account terrain, because we don't want
|
||||
// Calculate how much support we have on this hex from allies.
|
||||
// Support does not take into account terrain, because we don't want
|
||||
// to move into a hex that is surrounded by good defensive terrain.
|
||||
const double support = power_projection(tiles[j],fullmove_dstsrc,false);
|
||||
|
||||
// If this is a position with equal defense to another position,
|
||||
// If this is a position with equal defense to another position,
|
||||
// but more vulnerability then we don't want to use it.
|
||||
if(cur_position >= 0 && rating == best_rating && vulnerability/surround_bonus - support*surround_bonus >= best_vulnerability - best_support) {
|
||||
continue;
|
||||
|
@ -229,7 +229,7 @@ void ai::do_attack_analysis(
|
|||
|
||||
if(cur_position != -1) {
|
||||
units.erase(units.begin() + i);
|
||||
|
||||
|
||||
cur_analysis.movements.push_back(std::pair<location,location>(current_unit,tiles[cur_position]));
|
||||
|
||||
cur_analysis.vulnerability += best_vulnerability;
|
||||
|
@ -346,8 +346,8 @@ void ai::attack_analysis::analyze(const gamemap& map, unit_map& units,
|
|||
usc = ai_obj.unit_stats_cache_.end();
|
||||
}
|
||||
// Just check this attack is valid for this attacking unit (may be modified)
|
||||
if (usc != ai_obj.unit_stats_cache_.end() &&
|
||||
usc->second.first.attack_num <
|
||||
if (usc != ai_obj.unit_stats_cache_.end() &&
|
||||
usc->second.first.attack_num <
|
||||
static_cast<int>(up->second.attacks().size())) {
|
||||
|
||||
from_cache = true;
|
||||
|
@ -413,16 +413,16 @@ void ai::attack_analysis::analyze(const gamemap& map, unit_map& units,
|
|||
advance_prob = prob_killed;
|
||||
avg_losses -= up->second.cost() * advance_prob;
|
||||
|
||||
// The reward for getting a unit closer to advancement
|
||||
// (if it didn't advance) is to get the proportion of
|
||||
// remaining experience needed, and multiply it by
|
||||
// a quarter of the unit cost.
|
||||
// This will cause the AI to heavily favor
|
||||
// The reward for getting a unit closer to advancement
|
||||
// (if it didn't advance) is to get the proportion of
|
||||
// remaining experience needed, and multiply it by
|
||||
// a quarter of the unit cost.
|
||||
// This will cause the AI to heavily favor
|
||||
// getting xp for close-to-advance units.
|
||||
avg_losses -= (up->second.cost()*fight_xp)/(xp_for_advance*4) * (prob_fought - prob_killed);
|
||||
avg_losses -= (up->second.cost()*kill_xp)/(xp_for_advance*4) * prob_killed;
|
||||
|
||||
// The reward for killing with a unit that plagues
|
||||
// The reward for killing with a unit that plagues
|
||||
// is to get a 'negative' loss of that unit.
|
||||
if (bc->get_attacker_stats().plagues) {
|
||||
avg_losses -= prob_killed * up->second.cost();
|
||||
|
@ -479,8 +479,8 @@ double ai::attack_analysis::rating(double aggression, ai& ai_obj) const
|
|||
double value = chance_to_kill*target_value - avg_losses*(1.0-aggression);
|
||||
|
||||
if(terrain_quality > alternative_terrain_quality) {
|
||||
// This situation looks like it might be a bad move:
|
||||
// we are moving our attackers out of their optimal terrain
|
||||
// This situation looks like it might be a bad move:
|
||||
// we are moving our attackers out of their optimal terrain
|
||||
// into sub-optimal terrain.
|
||||
// Calculate the 'exposure' of our units to risk.
|
||||
|
||||
|
@ -495,8 +495,8 @@ double ai::attack_analysis::rating(double aggression, ai& ai_obj) const
|
|||
value -= exposure*(1.0-aggression);
|
||||
}
|
||||
|
||||
// If this attack uses our leader, and the leader can reach the keep,
|
||||
// and has gold to spend, reduce the value to reflect the leader's
|
||||
// If this attack uses our leader, and the leader can reach the keep,
|
||||
// and has gold to spend, reduce the value to reflect the leader's
|
||||
// lost recruitment opportunity in the case of an attack.
|
||||
if(uses_leader && ai_obj.leader_can_reach_keep() && ai_obj.current_team().gold() > 20) {
|
||||
value -= double(ai_obj.current_team().gold())*0.5;
|
||||
|
@ -506,15 +506,15 @@ double ai::attack_analysis::rating(double aggression, ai& ai_obj) const
|
|||
value += ((target_starting_damage/3 + avg_damage_inflicted) - (1.0-aggression)*avg_damage_taken)/10.0;
|
||||
|
||||
// If the unit is surrounded and there is no support,
|
||||
// or if the unit is surrounded and the average damage is 0,
|
||||
// or if the unit is surrounded and the average damage is 0,
|
||||
// the unit skips its sanity check and tries to break free as good as possible.
|
||||
if(!is_surrounded || (support != 0 && avg_damage_taken != 0))
|
||||
{
|
||||
// Sanity check: if we're putting ourselves at major risk,
|
||||
// and have no chance to kill, and we're not aiding our allies
|
||||
// Sanity check: if we're putting ourselves at major risk,
|
||||
// and have no chance to kill, and we're not aiding our allies
|
||||
// who are also attacking, then don't do it.
|
||||
if(vulnerability > 50.0 && vulnerability > support*2.0
|
||||
&& chance_to_kill < 0.02 && aggression < 0.75
|
||||
if(vulnerability > 50.0 && vulnerability > support*2.0
|
||||
&& chance_to_kill < 0.02 && aggression < 0.75
|
||||
&& !ai_obj.attack_close(target)) {
|
||||
return -1.0;
|
||||
}
|
||||
|
@ -531,11 +531,11 @@ double ai::attack_analysis::rating(double aggression, ai& ai_obj) const
|
|||
}
|
||||
|
||||
LOG_AI << "attack on " << target << ": attackers: " << movements.size()
|
||||
<< " value: " << value << " chance to kill: " << chance_to_kill
|
||||
<< " damage inflicted: " << avg_damage_inflicted
|
||||
<< " damage taken: " << avg_damage_taken
|
||||
<< " vulnerability: " << vulnerability
|
||||
<< " support: " << support
|
||||
<< " value: " << value << " chance to kill: " << chance_to_kill
|
||||
<< " damage inflicted: " << avg_damage_inflicted
|
||||
<< " damage taken: " << avg_damage_taken
|
||||
<< " vulnerability: " << vulnerability
|
||||
<< " support: " << support
|
||||
<< " quality: " << terrain_quality
|
||||
<< " alternative quality: " << alternative_terrain_quality << "\n";
|
||||
|
||||
|
@ -569,7 +569,7 @@ std::vector<ai::attack_analysis> ai::analyze_targets(
|
|||
|
||||
for(unit_map::const_iterator j = units_.begin(); j != units_.end(); ++j) {
|
||||
|
||||
// Attack anyone who is on the enemy side,
|
||||
// Attack anyone who is on the enemy side,
|
||||
// and who is not invisible or turned to stone.
|
||||
if(current_team().is_enemy(j->second.side()) && !j->second.incapacitated() &&
|
||||
j->second.invisible(j->first,units_,teams_) == false) {
|
||||
|
@ -612,7 +612,7 @@ double ai::power_projection(const gamemap::location& loc, const move_map& dstsr
|
|||
for (int i = 0;; ++i) {
|
||||
if (i == 6) {
|
||||
if (!changed) break;
|
||||
// Loop once again, in case a unit found a better spot
|
||||
// Loop once again, in case a unit found a better spot
|
||||
// and freed the place for another unit.
|
||||
changed = false;
|
||||
i = 0;
|
||||
|
@ -683,7 +683,7 @@ double ai::power_projection(const gamemap::location& loc, const move_map& dstsr
|
|||
else if (best_rating == ratings[index])
|
||||
continue;
|
||||
else {
|
||||
// The unit was in another spot already, so remove its older rating
|
||||
// The unit was in another spot already, so remove its older rating
|
||||
// from the final result, and require a new run to fill its old spot.
|
||||
res -= ratings[index];
|
||||
changed = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
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 version
|
||||
it under the terms of the GNU General Public License version
|
||||
or at your option any later version2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
@ -28,7 +28,7 @@ namespace dfool {
|
|||
int team_num=get_info().team_num;
|
||||
const config& parms = current_team().ai_parameters();
|
||||
config ai_mem = current_team().ai_memory();
|
||||
|
||||
|
||||
const config::child_list& orders = parms.get_children("order");
|
||||
LOG_STREAM(info, ai)<<"dfool side:"<<team_num<<" of "<<current_team().nteams()<<std::endl;
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace dfool {
|
|||
side_filter["side"]=buf;
|
||||
|
||||
LOG_STREAM(info, ai)<<"dfool sees:"<<std::endl;
|
||||
|
||||
|
||||
// for(unit_map::iterator ua = get_info().units.begin(); ua != get_info().units.end(); ++ua) {
|
||||
// std::string t = ua->second.get_ai_special();
|
||||
// LOG_STREAM(info, ai)<<"ua:"<<ua->second.underlying_description()<<"\t"<<t<<std::endl;
|
||||
|
@ -48,7 +48,7 @@ namespace dfool {
|
|||
unit_list all = all_units();
|
||||
unit_list my_units=filter_units(side_filter, all,get_info().units);
|
||||
unit_list v_units=visible_units();
|
||||
|
||||
|
||||
// LOG_STREAM(info, ai)<<"My Units"<<std::endl;
|
||||
// for(unit_list::iterator ui = all.begin(); ui != all.end(); ++ui) {
|
||||
// LOG_STREAM(info, ai)<<"\t....."<<*ui<<"........"<<std::endl;
|
||||
|
@ -60,7 +60,7 @@ namespace dfool {
|
|||
// LOG_STREAM(info, ai)<<"\t\t\t"<<u->first.x<<","<<u->first.y<<std::endl;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
LOG_STREAM(info, ai)<<"Visible Units"<<std::endl;
|
||||
for(unit_list::iterator ui = v_units.begin(); ui != v_units.end(); ++ui) {
|
||||
unit_map::iterator u = unit(*ui,get_info().units);
|
||||
|
@ -69,7 +69,7 @@ namespace dfool {
|
|||
LOG_STREAM(info, ai)<<"\t\t"<<u->second.underlying_description()<<std::endl;
|
||||
// LOG_STREAM(info, ai)<<"\t\t\t"<<u->second.get_ai_special()<<std::endl;
|
||||
// LOG_STREAM(info, ai)<<"\t\t\t"<<u->first.x<<","<<u->first.y<<std::endl;
|
||||
|
||||
|
||||
unit_memory_.add_unit_sighting(u->second, u->first, get_info().state.turn());
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ namespace dfool {
|
|||
unit_list order_units = filter_units(order_filter,my_units,get_info().units);
|
||||
if(num > order_units.size()){
|
||||
// Need to populate orders
|
||||
// Find units that match any filter.
|
||||
// If no filters, then accept all units.
|
||||
// Find units that match any filter.
|
||||
// If no filters, then accept all units.
|
||||
if(filter.size()){
|
||||
for(config::child_list::const_iterator f = filter.begin(); f != filter.end(); ++f) {
|
||||
config ff=**f;
|
||||
|
@ -97,21 +97,21 @@ namespace dfool {
|
|||
unit_list filtered_units=filter_units(ff,my_units,get_info().units);
|
||||
|
||||
//! @todo FIXME: add sorting
|
||||
|
||||
|
||||
for(unit_list::iterator i = filtered_units.begin(); i != filtered_units.end() && (num > order_units.size()); ++i) {
|
||||
unit_map::iterator ui=unit(*i,get_info().units);
|
||||
if(ui!=get_info().units.end()){
|
||||
std::string ais=ui->second.get_ai_special();
|
||||
|
||||
// LOG_STREAM(info, ai)<<"\t match: "<<ui->second.underlying_description()<<"\t"<<ais<<":::"<<std::endl;
|
||||
|
||||
|
||||
// LOG_STREAM(info, ai)<<"\t match: "<<ui->second.underlying_description()<<"\t"<<ais<<":::"<<std::endl;
|
||||
|
||||
bool used=(ais.size() > 0);
|
||||
if(used){
|
||||
// LOG_STREAM(info, ai)<<"\t\talready assigned: "<<ui->second.underlying_description()<<"\t"<<ais<<std::endl;
|
||||
}else{
|
||||
ui->second.assign_ai_special(order_id);
|
||||
order_units.push_back(*i);
|
||||
|
||||
|
||||
// LOG_STREAM(info, ai)<<"\t\tmatching: "<<ui->second.underlying_description()<<" to order: "<<order_id<<"\t"<<ui->second.get_ai_special()<<std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ namespace dfool {
|
|||
order_units=my_units;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Execute commands
|
||||
for(unit_list::iterator ou = order_units.begin(); ou != order_units.end(); ou++){
|
||||
const config::child_list& commands = (**o).get_children("command");
|
||||
|
@ -174,10 +174,10 @@ namespace dfool {
|
|||
}
|
||||
}
|
||||
|
||||
unit_memory_.write(ai_mem);
|
||||
unit_memory_.write(ai_mem);
|
||||
current_team().set_ai_memory(ai_mem);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
unit_list dfool_ai::filter_units(const config& filter, unit_list& ul, unit_map& um)
|
||||
|
@ -213,7 +213,7 @@ namespace dfool {
|
|||
visible_units.push_back(i->second.underlying_description());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOG_STREAM(info, ai) << "number of visible units: " << visible_units.size() << "\n";
|
||||
return visible_units;
|
||||
}
|
||||
|
@ -224,8 +224,8 @@ namespace dfool {
|
|||
for(unit_map::const_iterator i = um.begin(); i != um.end(); ++i) {
|
||||
// LOG_STREAM(info, ai)<<"all:"<<i->second.underlying_description()<<std::endl;
|
||||
all.push_back(i->second.underlying_description());
|
||||
}
|
||||
return(all);
|
||||
}
|
||||
return(all);
|
||||
}
|
||||
|
||||
bool dfool_ai::moveto(config::child_list::const_iterator o, unit_map::const_iterator m){
|
||||
|
@ -235,7 +235,7 @@ namespace dfool {
|
|||
std::map<location,paths> possible_moves;
|
||||
move_map srcdst, dstsrc;
|
||||
unit_map known_units;
|
||||
|
||||
|
||||
// unit_memory_.known_map(known_units, get_info().state.turn());
|
||||
unit_memory_.known_map(known_units, 0);
|
||||
|
||||
|
@ -254,30 +254,30 @@ namespace dfool {
|
|||
// Must restrict move_map to only unit that is moving.
|
||||
if(i->second==m->first){
|
||||
const int distance = distance_between(target,i->first);
|
||||
// int distance=10000;
|
||||
// int distance=10000;
|
||||
// std::cout<<"got here\n";
|
||||
// const shortest_path_calculator calc(m->second, current_team(),known_units,get_info().teams,get_info().map);
|
||||
//std::cout<<"got here2\n";
|
||||
//paths::route route = a_star_search(m->first, target, 1000.0, &calc,
|
||||
//get_info().map.x(), get_info().map.y());
|
||||
// std::cout<<"got here3\n";
|
||||
|
||||
|
||||
// distance = route_turns_to_complete(m->second, get_info().map, route, known_units, get_info().teams) + distance_between(target,i->first)/100;
|
||||
|
||||
|
||||
if(closest_distance == -1 || distance < closest_distance) {
|
||||
closest_distance = distance;
|
||||
closest_move = *i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOG_STREAM(info, ai)<<"\tmoving : "<< m->second.underlying_description() <<" "<<" from ("<<closest_move.first.x<<","<<closest_move.first.y<<")"<<" to ("<<target.x<<","<<target.y<<")"<<std::endl;
|
||||
LOG_STREAM(info, ai)<<"\tdistance: "<<closest_distance<<"\n";
|
||||
|
||||
if(closest_distance != -1) {
|
||||
gamemap::location to = move_unit_partial(closest_move.second,closest_move.first,possible_moves);
|
||||
if(to != closest_move.second)
|
||||
return(false); // Something unexpected happened
|
||||
return(false); // Something unexpected happened
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
|
@ -311,13 +311,13 @@ namespace dfool {
|
|||
|
||||
void unit_memory::add_unit_sighting(unit u, gamemap::location l, size_t t){
|
||||
std::string unit_id= u.underlying_description();
|
||||
// Check if this unit has already been seen
|
||||
// Check if this unit has already been seen
|
||||
size_t i,j;
|
||||
for(i=0; i < ids_.size();i++){
|
||||
if(unit_id == ids_[i]){break;}
|
||||
}
|
||||
|
||||
if(i == ids_.size()){
|
||||
if(i == ids_.size()){
|
||||
// Unit has not been seen
|
||||
units_.push_back(u);
|
||||
ids_.push_back(unit_id);
|
||||
|
@ -328,9 +328,9 @@ namespace dfool {
|
|||
units_[i]=u;
|
||||
turns_[i]=t;
|
||||
locations_[i]=l;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove units that are co-located units
|
||||
// Remove units that are co-located units
|
||||
std::set<size_t> remove_list;
|
||||
for(j=0; j < ids_.size();j++){
|
||||
if(j!=i && locations_[j] == locations_[i]){
|
||||
|
@ -348,7 +348,7 @@ namespace dfool {
|
|||
if(id == ids_[i]){break;}
|
||||
}
|
||||
|
||||
if(i == ids_.size()){
|
||||
if(i == ids_.size()){
|
||||
// Unit not in memory
|
||||
}else{
|
||||
// Remove unit info
|
||||
|
@ -377,7 +377,7 @@ namespace dfool {
|
|||
temp["x"] = xs.str();
|
||||
ys << locations_[i].y;
|
||||
temp["y"] = ys.str();
|
||||
units_[i].write(temp_unit);
|
||||
units_[i].write(temp_unit);
|
||||
temp.add_child("unit",temp_unit);
|
||||
// std::cout<<"ai write: "<<temp_unit["description"]<<"\n";
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ namespace dfool {
|
|||
std::map<gamemap::location,size_t> turn_used;
|
||||
for(i=0;i<units_.size();i++){
|
||||
gamemap::location l = locations_[i];
|
||||
size_t t = turn_used[l];
|
||||
size_t t = turn_used[l];
|
||||
if(turns_[i] >= turn && turns_[i] >= t){
|
||||
// std::cout<<"turn_used: "<< t <<"\n";
|
||||
// std::cout<<"turn: "<< turns_[i] <<"\n";
|
||||
|
@ -405,7 +405,7 @@ namespace dfool {
|
|||
|
||||
std::string evaluator::value(const std::string& val_string){
|
||||
std::string temp_string = val_string;
|
||||
|
||||
|
||||
std::vector<std::string> p = utils::paranthetical_split(val_string,0,"(",")");
|
||||
|
||||
// Find function calls designated by @ and evaluate values inside ()
|
||||
|
@ -418,7 +418,7 @@ namespace dfool {
|
|||
if(i%2){
|
||||
if(function){
|
||||
std::cout<<"function: "<<func<<"\n";
|
||||
std::map<std::string, evaluator*>::iterator fmi =
|
||||
std::map<std::string, evaluator*>::iterator fmi =
|
||||
function_map_->find(func);
|
||||
if(fmi != function_map_->end()){ // evaluate function
|
||||
std::cout<<"function ::: "<<func<<" ::: "<<fmi->first<<"\n";
|
||||
|
@ -449,7 +449,7 @@ namespace dfool {
|
|||
std::cout<<"evaluator syntax error:\n\t" << val_string << std::endl;
|
||||
}
|
||||
std::cout<<"eval size:"<<temp.size()<<"\n";
|
||||
|
||||
|
||||
if(function && temp.size()>0){
|
||||
std::cout<<"temp "<<temp[0]<<"\n";
|
||||
if(temp.size()==2){
|
||||
|
@ -506,22 +506,22 @@ namespace dfool {
|
|||
std::cout<<"atb:"<<*token<<"\n";
|
||||
// std::cout<<"atb:"<<*a<<*token<<*b<<"\n";
|
||||
if((*token)[0]=='*'){
|
||||
temp= atof((*a).c_str()) * atof((*b).c_str());
|
||||
temp= atof((*a).c_str()) * atof((*b).c_str());
|
||||
}
|
||||
if((*token)[0]=='/'){
|
||||
temp= atof((*a).c_str()) / atof((*b).c_str());
|
||||
temp= atof((*a).c_str()) / atof((*b).c_str());
|
||||
}
|
||||
if((*token)[0]=='%'){
|
||||
temp= fmod(atof((*a).c_str()), atof((*b).c_str()));
|
||||
temp= fmod(atof((*a).c_str()), atof((*b).c_str()));
|
||||
}
|
||||
if((*token)[0]=='+'){
|
||||
temp= atof((*a).c_str()) + atof((*b).c_str());
|
||||
temp= atof((*a).c_str()) + atof((*b).c_str());
|
||||
}
|
||||
if((*token)[0]=='-'){
|
||||
temp= atof((*a).c_str()) - atof((*b).c_str());
|
||||
temp= atof((*a).c_str()) - atof((*b).c_str());
|
||||
}
|
||||
if((*token)[0]=='^'){
|
||||
temp= pow(atof((*a).c_str()),atof((*b).c_str()));
|
||||
temp= pow(atof((*a).c_str()),atof((*b).c_str()));
|
||||
}
|
||||
std::cout<<"got here token2:"<<temp<<"\n";
|
||||
std::stringstream r;
|
||||
|
@ -551,13 +551,13 @@ namespace dfool {
|
|||
std::string parenthesis="()";
|
||||
int count=0;
|
||||
size_t i;
|
||||
|
||||
|
||||
for(i=0;i!=s.size();i++){ // strip out spaces
|
||||
if(s[i]!=' '){
|
||||
str+=s[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
i=0;
|
||||
while(i!=str.size()){
|
||||
std::cout<<"i:"<<i<<"\n";
|
||||
|
@ -566,7 +566,7 @@ namespace dfool {
|
|||
}
|
||||
char c=str[i];
|
||||
bool dpfound=false;
|
||||
bool found=false;
|
||||
bool found=false;
|
||||
for(size_t j=0;j!=digits.size();j++){
|
||||
if(c==digits[j]){
|
||||
found=true;
|
||||
|
@ -589,7 +589,7 @@ namespace dfool {
|
|||
found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found){
|
||||
ret.push_back("");
|
||||
ret.back()+=c;
|
||||
|
@ -612,7 +612,7 @@ namespace dfool {
|
|||
found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found){
|
||||
ret.push_back("");
|
||||
ret.back()+=c;
|
||||
|
@ -638,7 +638,7 @@ namespace dfool {
|
|||
|
||||
std::string distance_evaluator::value(const std::string& val_string){
|
||||
std::cout<<"got distance:"<<val_string<<"\n";
|
||||
std::vector<std::string> vals = utils::split(val_string,',');
|
||||
std::vector<std::string> vals = utils::split(val_string,',');
|
||||
if(vals.size()<4){
|
||||
std::cout<<"error in distance parameters\n";
|
||||
return("ERR");
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace dfool {
|
|||
// config terrain_filter_;
|
||||
// std::string hex_val_;
|
||||
// std::string number;
|
||||
// std::string id;
|
||||
// std::string id;
|
||||
// };
|
||||
|
||||
class unit_memory{
|
||||
|
@ -54,8 +54,8 @@ namespace dfool {
|
|||
//void purge(int turn = -1); // Clean outdated entries
|
||||
void write(config& temp);
|
||||
// Create a map based upon units seen since turn
|
||||
void known_map(unit_map& units, size_t turn=0);
|
||||
private:
|
||||
void known_map(unit_map& units, size_t turn=0);
|
||||
private:
|
||||
void write_element(int i, config& temp);
|
||||
// Could replace these with a single vector of memory elements
|
||||
std::vector<unit> units_;
|
||||
|
@ -92,7 +92,7 @@ namespace dfool {
|
|||
std::string evaluate_tokens(std::list<std::string>&);
|
||||
};
|
||||
|
||||
//! An ai that keeps track of what it has "seen",
|
||||
//! An ai that keeps track of what it has "seen",
|
||||
//! does not target units that it has not "seen",
|
||||
//! and does not make decisions based on unseen units.
|
||||
class dfool_ai : public ai_interface {
|
||||
|
|
|
@ -57,8 +57,8 @@ public:
|
|||
//! A list of the teams in the game.
|
||||
std::vector<team>& teams;
|
||||
|
||||
//! The number of the team the AI is.
|
||||
//! Note: this number is 1-based, so 1 must be subtracted
|
||||
//! The number of the team the AI is.
|
||||
//! Note: this number is 1-based, so 1 must be subtracted
|
||||
//! for using it as index of 'teams'.
|
||||
unsigned int team_num;
|
||||
|
||||
|
@ -73,15 +73,15 @@ public:
|
|||
class game_state& game_state_;
|
||||
};
|
||||
|
||||
//! The constructor.
|
||||
//! All derived classes should take an argument of type info&
|
||||
//! The constructor.
|
||||
//! All derived classes should take an argument of type info&
|
||||
//! which they should pass to this constructor.
|
||||
ai_interface(info& arg) : info_(arg), last_interact_(0), user_interact_("ai_user_interact"),
|
||||
unit_recruited_("ai_unit_recruited"), unit_moved_("ai_unit_moved"),
|
||||
enemy_attacked_("ai_enemy_attacked") {}
|
||||
virtual ~ai_interface() {}
|
||||
|
||||
//! Function that is called when the AI must play its turn.
|
||||
//! Function that is called when the AI must play its turn.
|
||||
//! Derived classes should implement their AI algorithm in this function.
|
||||
virtual void play_turn() = 0;
|
||||
|
||||
|
@ -103,61 +103,61 @@ public:
|
|||
|
||||
protected:
|
||||
//! This function should be called to attack an enemy.
|
||||
//! 'attacking_unit': the location of the attacking unit
|
||||
//! 'target': the location of the target unit.
|
||||
//! 'attacking_unit': the location of the attacking unit
|
||||
//! 'target': the location of the target unit.
|
||||
// This unit must be in range of the attacking unit's weapon
|
||||
//! 'att_weapon': the number of the weapon (0-based) which should be used in the attack.
|
||||
//! This must be a valid weapon of the attacking unit.
|
||||
//! 'att_weapon': the number of the weapon (0-based) which should be used in the attack.
|
||||
//! This must be a valid weapon of the attacking unit.
|
||||
void attack_enemy(const location& attacking_unit, const location& target, int att_weapon, int def_weapon);
|
||||
|
||||
//! This function should be called to move a unit.
|
||||
//! This function should be called to move a unit.
|
||||
//! Once the unit has been moved, its movement allowance is set to 0.
|
||||
//! 'from': the location of the unit being moved.
|
||||
//! 'to': the location to be moved to. This must be a valid move for the unit.
|
||||
//! 'possible_moves': the map of possible moves, as obtained from 'calculate_possible_moves'.
|
||||
//! 'from': the location of the unit being moved.
|
||||
//! 'to': the location to be moved to. This must be a valid move for the unit.
|
||||
//! 'possible_moves': the map of possible moves, as obtained from 'calculate_possible_moves'.
|
||||
location move_unit(location from, location to, std::map<location,paths>& possible_moves);
|
||||
|
||||
//! Identical to 'move_unit', except that the unit's movement
|
||||
//! Identical to 'move_unit', except that the unit's movement
|
||||
//! isn't set to 0 after the move is complete.
|
||||
location move_unit_partial(location from, location t, std::map<location,paths>& possible_moves);
|
||||
|
||||
//! Calculate the moves units may possibly make.
|
||||
//! 'possible_moves': a map which will be filled with the paths each unit can take
|
||||
//! to get to every possible destination.
|
||||
//! 'possible_moves': a map which will be filled with the paths each unit can take
|
||||
//! to get to every possible destination.
|
||||
//! You probably don't want to use this object at all, except to pass to 'move_unit'.
|
||||
//! 'srcdst': a map of units to all their possible destinations
|
||||
//! 'dstsrc': a map of destinations to all the units that can move to that destination
|
||||
//! 'enemy': if true, a map of possible moves for enemies will be calculated.
|
||||
//! If false, a map of possible moves for units on the AI's side will be calculated.
|
||||
//! 'srcdst': a map of units to all their possible destinations
|
||||
//! 'dstsrc': a map of destinations to all the units that can move to that destination
|
||||
//! 'enemy': if true, a map of possible moves for enemies will be calculated.
|
||||
//! If false, a map of possible moves for units on the AI's side will be calculated.
|
||||
//! The AI's own leader will not be included in this map.
|
||||
//! 'assume_full_movement': if true, the function will operate on the assumption
|
||||
//! 'assume_full_movement': if true, the function will operate on the assumption
|
||||
//! that all units can move their full movement allotment.
|
||||
//! 'remove_destinations': a pointer to a set of possible destinations to omit.
|
||||
//! 'remove_destinations': a pointer to a set of possible destinations to omit.
|
||||
void calculate_possible_moves(std::map<location,paths>& possible_moves, move_map& srcdst, move_map& dstsrc, bool enemy, bool assume_full_movement=false,
|
||||
const std::set<location>* remove_destinations=NULL);
|
||||
|
||||
//! A more fundamental version of calculate_possible_moves
|
||||
//! A more fundamental version of calculate_possible_moves
|
||||
//! which allows the use of a speculative unit map.
|
||||
void calculate_moves(const unit_map& units, std::map<location,paths>& possible_moves, move_map& srcdst, move_map& dstsrc, bool enemy, bool assume_full_movement=false,
|
||||
const std::set<location>* remove_destinations=NULL, bool see_all=false);
|
||||
|
||||
//! Recruit a unit. It will recruit the unit with the given name,
|
||||
//! at the given location, or at an available location to recruit units
|
||||
//! at the given location, or at an available location to recruit units
|
||||
//! if 'loc' is not a valid recruiting location.
|
||||
//!
|
||||
//! @retval false if recruitment cannot be performed,
|
||||
//! because there are no available tiles,
|
||||
//! or not enough money.
|
||||
//! @retval false if recruitment cannot be performed,
|
||||
//! because there are no available tiles,
|
||||
//! or not enough money.
|
||||
bool recruit(const std::string& unit_name, location loc=location());
|
||||
|
||||
//! functions to retrieve the 'info' object.
|
||||
//! functions to retrieve the 'info' object.
|
||||
//! Used by derived classes to discover all necessary game information.
|
||||
info& get_info() { return info_; }
|
||||
const info& get_info() const { return info_; }
|
||||
|
||||
//! Function which should be called frequently to allow the user
|
||||
//! Function which should be called frequently to allow the user
|
||||
//! to interact with the interface.
|
||||
//! This function will make sure that interaction doesn't occur too often,
|
||||
//! This function will make sure that interaction doesn't occur too often,
|
||||
//! so there is no problem with calling it very regularly.
|
||||
void raise_user_interact();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
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 version
|
||||
it under the terms of the GNU General Public License version
|
||||
or at your option any later version2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
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 version
|
||||
it under the terms of the GNU General Public License version
|
||||
or at your option any later version2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
@ -673,8 +673,8 @@ static int location_internal_compare(wesnoth_location* left, wesnoth_location* r
|
|||
|
||||
static long location_internal_hash(wesnoth_location* obj)
|
||||
{
|
||||
// Never return -1, which is reserved for raising an exception.
|
||||
// Note that both x and y can get values < 0,
|
||||
// Never return -1, which is reserved for raising an exception.
|
||||
// Note that both x and y can get values < 0,
|
||||
// e.g. when checking all positions in a certain radius at the map border.
|
||||
unsigned char x = (unsigned)obj->location_->x;
|
||||
unsigned char y = (unsigned)obj->location_->y;
|
||||
|
@ -986,7 +986,7 @@ PyObject *python_ai::wrapper_team_targets(PyObject *, PyObject *args)
|
|||
|
||||
PyObject* dict = PyDict_New();
|
||||
|
||||
//! @todo FIXME: There should be a C++ method to return all targets instead,
|
||||
//! @todo FIXME: There should be a C++ method to return all targets instead,
|
||||
// for now it's just copy&pasted.
|
||||
std::vector<team::target>& team_targets =
|
||||
running_instance->current_team().targets();
|
||||
|
@ -1381,8 +1381,8 @@ PyObject* python_ai::wrapper_attack_unit(PyObject* /*self*/, PyObject* args)
|
|||
&wesnoth_location_type, &to, &weapon ) )
|
||||
return NULL;
|
||||
|
||||
//! @todo FIXME: Remove this check and let the C++ code do the check
|
||||
// if the attack is valid at all (there may be ranged attacks or similar later,
|
||||
//! @todo FIXME: Remove this check and let the C++ code do the check
|
||||
// if the attack is valid at all (there may be ranged attacks or similar later,
|
||||
// and then the code below will horribly fail).
|
||||
if (!tiles_adjacent(*from->location_, *to->location_))
|
||||
return_none;
|
||||
|
@ -1500,7 +1500,7 @@ PyObject* python_ai::wrapper_unit_attack_statistics(wesnoth_unit* self, PyObject
|
|||
|
||||
info& inf = running_instance->get_info();
|
||||
|
||||
// We need to temporarily move our unit to where the attack calculation
|
||||
// We need to temporarily move our unit to where the attack calculation
|
||||
// is supposed to take place.
|
||||
std::pair<gamemap::location,unit> *temp = inf.units.extract(*from->location_);
|
||||
std::pair<gamemap::location,unit> *backup = temp;
|
||||
|
@ -1716,7 +1716,7 @@ python_ai::~python_ai()
|
|||
void python_ai::play_turn()
|
||||
{
|
||||
game_events::fire("ai turn");
|
||||
|
||||
|
||||
std::string script_name = current_team().ai_parameters()["python_script"];
|
||||
if (script_name.substr(script_name.length() - 3) != ".py") {
|
||||
// Make sure the script ends in .py here - Wesnoth will not execute any
|
||||
|
@ -1771,7 +1771,7 @@ void python_ai::play_turn()
|
|||
std::string("internal error (wrong python version?)")) <<
|
||||
std::endl;
|
||||
}
|
||||
// Otherwise, re-throw the exception here,
|
||||
// Otherwise, re-throw the exception here,
|
||||
// so it will get handled properly further up.
|
||||
else {
|
||||
LOG_AI << "Python script has been interrupted.\n";
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file ai_python.hpp
|
||||
//! @file ai_python.hpp
|
||||
//!
|
||||
|
||||
#ifndef AI_PYTHON_HPP_INCLUDED
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file animated.hpp
|
||||
//! @file animated.hpp
|
||||
//! Animate units.
|
||||
|
||||
#ifndef ANIMATED_IMAGE_H_INCLUDED
|
||||
|
@ -50,8 +50,8 @@ public:
|
|||
//! Adds a frame to an animation.
|
||||
void add_frame(int duration, const T& value,bool force_change =false);
|
||||
|
||||
//! Starts an animation cycle.
|
||||
//! The first frame of the animation to start may be set
|
||||
//! Starts an animation cycle.
|
||||
//! The first frame of the animation to start may be set
|
||||
//! to any value by using a start_time different to 0.
|
||||
void start_animation(int start_time, bool cycles=false, double acceleration=1);
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ paths::route a_star_search(gamemap::location const &src, gamemap::location const
|
|||
}
|
||||
|
||||
a_star_init(src, dst, openList, aStarGameWorld, parWidth, parHeight, vectLocation, teleports, locNbTeleport);
|
||||
|
||||
|
||||
bool routeSolved = false;
|
||||
while (!routeSolved && !openList.empty())
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ paths::route a_star_search(gamemap::location const &src, gamemap::location const
|
|||
|
||||
//if we have found a solution
|
||||
if (locCurNode->loc == dst)
|
||||
{
|
||||
{
|
||||
routeSolved = true;
|
||||
} else {
|
||||
std::pop_heap(openList.begin(), openList.end(), compare_lt_a_star_node);
|
||||
|
@ -185,41 +185,41 @@ paths::route a_star_search(gamemap::location const &src, gamemap::location const
|
|||
wassert(locCurNode->isInCloseList == false);
|
||||
locCurNode->isInCloseList = true;
|
||||
|
||||
a_star_explore_neighbours(dst, stop_at, costCalculator, parWidth, parHeight,
|
||||
teleports, vectLocation, openList, aStarGameWorld, locCurNode, locNbTeleport);
|
||||
a_star_explore_neighbours(dst, stop_at, costCalculator, parWidth, parHeight,
|
||||
teleports, vectLocation, openList, aStarGameWorld, locCurNode, locNbTeleport);
|
||||
}
|
||||
}
|
||||
if(routeSolved) {
|
||||
locDestNode = locCurNode;
|
||||
|
||||
LOG_PF << "found solution; calculating it...\n";
|
||||
while (locCurNode != NULL)
|
||||
{
|
||||
locRoute.steps.push_back(locCurNode->loc);
|
||||
locCurNode = locCurNode->nodeParent;
|
||||
}
|
||||
std::reverse(locRoute.steps.begin(), locRoute.steps.end());
|
||||
locRoute.move_left = int(locDestNode->g);
|
||||
|
||||
wassert(locRoute.steps.front() == src);
|
||||
wassert(locRoute.steps.back() == dst);
|
||||
|
||||
LOG_PF << "exiting a* search (solved)\n";
|
||||
} else {
|
||||
}
|
||||
if(routeSolved) {
|
||||
locDestNode = locCurNode;
|
||||
|
||||
LOG_PF << "found solution; calculating it...\n";
|
||||
while (locCurNode != NULL)
|
||||
{
|
||||
locRoute.steps.push_back(locCurNode->loc);
|
||||
locCurNode = locCurNode->nodeParent;
|
||||
}
|
||||
std::reverse(locRoute.steps.begin(), locRoute.steps.end());
|
||||
locRoute.move_left = int(locDestNode->g);
|
||||
|
||||
wassert(locRoute.steps.front() == src);
|
||||
wassert(locRoute.steps.back() == dst);
|
||||
|
||||
LOG_PF << "exiting a* search (solved)\n";
|
||||
} else {
|
||||
//route not solved
|
||||
LOG_PF << "aborted a* search\n";
|
||||
locRoute.move_left = int(costCalculator->getNoPathValue());
|
||||
locRoute.move_left = int(costCalculator->getNoPathValue());
|
||||
}
|
||||
openList.clear();
|
||||
aStarGameWorld.clear();
|
||||
return locRoute;
|
||||
}
|
||||
|
||||
static void get_tiles_radius_internal(const gamemap::location& a, size_t radius,
|
||||
|
||||
static void get_tiles_radius_internal(const gamemap::location& a, size_t radius,
|
||||
std::set<gamemap::location>& res, std::map<gamemap::location,int>& visited)
|
||||
{
|
||||
visited[a] = radius;
|
||||
res.insert(a);
|
||||
visited[a] = radius;
|
||||
res.insert(a);
|
||||
|
||||
if(radius == 0) {
|
||||
return;
|
||||
|
@ -228,22 +228,22 @@ static void get_tiles_radius_internal(const gamemap::location& a, size_t radius,
|
|||
gamemap::location adj[6];
|
||||
get_adjacent_tiles(a,adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
if(visited.count(adj[i]) == 0 || visited[adj[i]] < int(radius)-1) {
|
||||
get_tiles_radius_internal(adj[i],radius-1,res,visited);
|
||||
if(visited.count(adj[i]) == 0 || visited[adj[i]] < int(radius)-1) {
|
||||
get_tiles_radius_internal(adj[i],radius-1,res,visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_tiles_radius(const gamemap::location& a, size_t radius,
|
||||
void get_tiles_radius(const gamemap::location& a, size_t radius,
|
||||
std::set<gamemap::location>& res)
|
||||
{
|
||||
std::map<gamemap::location,int> visited;
|
||||
std::map<gamemap::location,int> visited;
|
||||
get_tiles_radius_internal(a,radius,res,visited);
|
||||
}
|
||||
|
||||
void get_tiles_radius(gamemap const &map, std::vector<gamemap::location> const &locs,
|
||||
size_t radius, std::set<gamemap::location> &res, xy_pred *pred)
|
||||
{
|
||||
{
|
||||
typedef std::set<gamemap::location> location_set;
|
||||
location_set not_visited(locs.begin(), locs.end()), must_visit, filtered_out;
|
||||
++radius;
|
||||
|
@ -256,11 +256,11 @@ void get_tiles_radius(gamemap const &map, std::vector<gamemap::location> const &
|
|||
get_adjacent_tiles(*it, adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
gamemap::location const &loc = adj[i];
|
||||
if(map.on_board(loc) && !res.count(loc) && !filtered_out.count(loc)) {
|
||||
if(map.on_board(loc) && !res.count(loc) && !filtered_out.count(loc)) {
|
||||
if(!pred || (*pred)(loc)) {
|
||||
must_visit.insert(loc);
|
||||
} else {
|
||||
filtered_out.insert(loc);
|
||||
must_visit.insert(loc);
|
||||
} else {
|
||||
filtered_out.insert(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
|
||||
Full algorithm by Yogin. Typing and optimization by Rusty.
|
||||
|
||||
This code has lots of debugging. It is there for a reason:
|
||||
This code has lots of debugging. It is there for a reason:
|
||||
this code is kinda tricky. Do not remove it.
|
||||
*/
|
||||
|
||||
//! @file attack_prediction.cpp
|
||||
//! @file attack_prediction.cpp
|
||||
//! Simulate combat to calculate attacks. Standalone program, benchmark.
|
||||
|
||||
#include "attack_prediction.hpp"
|
||||
|
@ -27,8 +27,8 @@
|
|||
|
||||
#include "wassert.hpp"
|
||||
|
||||
// Compile with -O3 -DBENCHMARK for speed testing,
|
||||
// -DCHECK for testing correctness
|
||||
// Compile with -O3 -DBENCHMARK for speed testing,
|
||||
// -DCHECK for testing correctness
|
||||
// (run tools/wesnoth-attack-sim.c --check on output)
|
||||
#if !defined(BENCHMARK) && !defined(CHECK)
|
||||
#include "util.hpp"
|
||||
|
@ -320,7 +320,7 @@ void prob_matrix::shift_rows(unsigned dst, unsigned src,
|
|||
}
|
||||
}
|
||||
|
||||
// Shift prob_matrix to reflect probability 'hit_chance'
|
||||
// Shift prob_matrix to reflect probability 'hit_chance'
|
||||
// that damage (up to) 'damage' is done to 'b'.
|
||||
void prob_matrix::receive_blow_b(unsigned damage, unsigned slow_damage, double hit_chance,
|
||||
bool a_slows, bool a_drains)
|
||||
|
@ -446,7 +446,7 @@ double prob_matrix::dead_prob() const
|
|||
return prob;
|
||||
}
|
||||
|
||||
// Shift matrix to reflect probability 'hit_chance'
|
||||
// Shift matrix to reflect probability 'hit_chance'
|
||||
// that damage (up to) 'damage' is done to 'a'.
|
||||
void prob_matrix::receive_blow_a(unsigned damage, unsigned slow_damage, double hit_chance,
|
||||
bool b_slows, bool b_drains)
|
||||
|
@ -527,8 +527,8 @@ combatant::combatant(const combatant &that, const battle_context::unit_stats &u)
|
|||
|
||||
|
||||
|
||||
// For swarm, whether we get an attack depends on HP distribution
|
||||
// from previous combat. So we roll this into our P(hitting),
|
||||
// For swarm, whether we get an attack depends on HP distribution
|
||||
// from previous combat. So we roll this into our P(hitting),
|
||||
// since no attack is equivalent to missing.
|
||||
void combatant::adjust_hitchance()
|
||||
{
|
||||
|
@ -551,7 +551,7 @@ void combatant::adjust_hitchance()
|
|||
}
|
||||
if (!summary[1].empty())
|
||||
prob += summary[1][i];
|
||||
for (unsigned int j = 0; j < u_.swarm_min + (u_.swarm_max -
|
||||
for (unsigned int j = 0; j < u_.swarm_min + (u_.swarm_max -
|
||||
static_cast<double>(u_.swarm_min)) * u_.hp / u_.max_hp; j++)
|
||||
|
||||
hit_chances_[j] += prob * u_.chance_to_hit / 100.0 / alive_prob;
|
||||
|
@ -719,8 +719,8 @@ void combatant::complex_fight(combatant &opp, unsigned int rounds)
|
|||
}
|
||||
|
||||
// Two man enter. One man leave!
|
||||
// ... Or maybe two. But definitely not three.
|
||||
// Of course, one could be a woman. Or both.
|
||||
// ... Or maybe two. But definitely not three.
|
||||
// Of course, one could be a woman. Or both.
|
||||
// And neither could be human, too.
|
||||
// Um, ok, it was a stupid thing to say.
|
||||
void combatant::fight(combatant &opp)
|
||||
|
@ -799,8 +799,8 @@ void combatant::fight(combatant &opp)
|
|||
opp.hp_dist[i] = opp.summary[0][i] + opp.summary[1][i];
|
||||
}
|
||||
|
||||
// Make sure we don't try to access the vectors out of bounds,
|
||||
// drain increases HPs so we determine the number of HP here
|
||||
// Make sure we don't try to access the vectors out of bounds,
|
||||
// drain increases HPs so we determine the number of HP here
|
||||
// and make sure it stays within bounds
|
||||
const unsigned int hp = minimum<unsigned int>(u_.hp, hp_dist.size() - 1);
|
||||
const unsigned int opp_hp = minimum<unsigned int>(opp.u_.hp, opp.hp_dist.size() - 1);
|
||||
|
@ -835,7 +835,7 @@ double combatant::average_hp(unsigned int healing) const
|
|||
}
|
||||
|
||||
#if defined(BENCHMARK) || defined(CHECK)
|
||||
// We create a significant number of nasty-to-calculate units,
|
||||
// We create a significant number of nasty-to-calculate units,
|
||||
// and test each one against the others.
|
||||
#define NUM_UNITS 50
|
||||
|
||||
|
@ -906,7 +906,7 @@ static void run(unsigned specific_battle)
|
|||
if (specific_battle && battle != specific_battle)
|
||||
continue;
|
||||
u[j]->fight(*u[i]);
|
||||
// We need this here, because swarm means
|
||||
// We need this here, because swarm means
|
||||
// out num hits can change.
|
||||
u[i]->set_effectiveness((i % 7) + 2, 0.3 + (i % 6)*0.1,
|
||||
(i % 8) == 0);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file attack_prediction.hpp
|
||||
//! @file attack_prediction.hpp
|
||||
//!
|
||||
|
||||
#ifndef ATTACK_PREDICTION_H_INCLUDED
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file boilerplate-header.cpp
|
||||
//! @file boilerplate-header.cpp
|
||||
//! Template for new cpp-files.
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file builder.cpp
|
||||
//! @file builder.cpp
|
||||
//! Terrain builder.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -29,7 +29,7 @@
|
|||
#include <climits>
|
||||
|
||||
#define ERR_NG LOG_STREAM(err, engine)
|
||||
#define DEBUG_NG LOG_STREAM(info, engine)
|
||||
#define DEBUG_NG LOG_STREAM(info, engine)
|
||||
|
||||
/** The tile width used when using basex and basey. This is not,
|
||||
* necessarily, the tile width in pixels, this is totally
|
||||
|
@ -42,7 +42,7 @@ static const int TILEWIDTH = 72;
|
|||
* considered foreground.
|
||||
*/
|
||||
static const int UNITPOS = 36 + 18;
|
||||
/** The allowed interval for the base-y position. The possible values are from
|
||||
/** The allowed interval for the base-y position. The possible values are from
|
||||
* -BASE_Y_INTERVAL to BASE_Y_INTERVAL-1
|
||||
*/
|
||||
static const int BASE_Y_INTERVAL = 100000;
|
||||
|
@ -131,11 +131,11 @@ const terrain_builder::tile& terrain_builder::tilemap::operator[] (const gamemap
|
|||
return map_[(loc.x+1) + (loc.y+1)*(x_+2)];
|
||||
}
|
||||
|
||||
terrain_builder::terrain_builder(const config& cfg, const config& level,
|
||||
terrain_builder::terrain_builder(const config& cfg, const config& level,
|
||||
const gamemap& map, const std::string& offmap_image) :
|
||||
map_(map), tile_map_(map.w(), map.h())
|
||||
{
|
||||
// Make sure there's nothing left in the cache,
|
||||
// Make sure there's nothing left in the cache,
|
||||
// since it might give problems (or not?)
|
||||
//image::flush_cache();
|
||||
|
||||
|
@ -334,7 +334,7 @@ terrain_builder::terrain_constraint terrain_builder::rotate(const terrain_builde
|
|||
// r = [[ 1/2 -3/4 ]
|
||||
// [ 1 1/2 ]]
|
||||
//
|
||||
// And the following array contains I(2), r, r^2, r^3, r^4, r^5
|
||||
// And the following array contains I(2), r, r^2, r^3, r^4, r^5
|
||||
// (with r^3 == -I(2)), which are the successive rotations.
|
||||
static const struct {
|
||||
double xx;
|
||||
|
@ -553,7 +553,7 @@ void terrain_builder::add_constraints(
|
|||
add_images_from_config(constraints[loc].images, global_images, true, x, y);
|
||||
}
|
||||
|
||||
void terrain_builder::add_constraints(terrain_builder::constraint_set &constraints,
|
||||
void terrain_builder::add_constraints(terrain_builder::constraint_set &constraints,
|
||||
const gamemap::location& loc, const config& cfg, const config& global_images)
|
||||
|
||||
{
|
||||
|
@ -582,9 +582,9 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
|
|||
{
|
||||
|
||||
const t_translation::t_map map = t_translation::read_builder_map(mapstring);
|
||||
|
||||
|
||||
// If there is an empty map leave directly.
|
||||
// Determine after conversion, since a
|
||||
// Determine after conversion, since a
|
||||
// non-empty string can return an empty map.
|
||||
if(map.empty()) {
|
||||
return;
|
||||
|
@ -599,7 +599,7 @@ void terrain_builder::parse_mapstring(const std::string &mapstring,
|
|||
const t_translation::t_letter terrain = map[y_off][x_off];
|
||||
|
||||
if(terrain.base == t_translation::TB_DOT) {
|
||||
// Dots are simple placeholders,
|
||||
// Dots are simple placeholders,
|
||||
// which do not represent actual terrains.
|
||||
} else if (terrain.overlay != 0 ) {
|
||||
anchors.insert(std::pair<int, gamemap::location>(terrain.overlay, gamemap::location(x, y)));
|
||||
|
@ -630,7 +630,7 @@ void terrain_builder::add_rule(building_ruleset& rules, building_rule &rule)
|
|||
}
|
||||
}
|
||||
|
||||
void terrain_builder::add_rotated_rules(building_ruleset& rules, building_rule& tpl, const std::string &rotations)
|
||||
void terrain_builder::add_rotated_rules(building_ruleset& rules, building_rule& tpl, const std::string &rotations)
|
||||
{
|
||||
if(rotations.empty()) {
|
||||
// Adds the parsed built terrain to the list
|
||||
|
@ -674,7 +674,7 @@ void terrain_builder::parse_config(const config &cfg)
|
|||
config::child_list tcs((*br)->get_children("tile"));
|
||||
|
||||
for(config::child_list::const_iterator tc = tcs.begin(); tc != tcs.end(); tc++) {
|
||||
// Adds the terrain constraint to the current built terrain's list
|
||||
// Adds the terrain constraint to the current built terrain's list
|
||||
// of terrain constraints, if it does not exist.
|
||||
gamemap::location loc;
|
||||
if((**tc)["x"].size()) {
|
||||
|
@ -735,8 +735,8 @@ void terrain_builder::parse_config(const config &cfg)
|
|||
|
||||
}
|
||||
|
||||
// Debug output for the terrain rules
|
||||
#if 0
|
||||
// Debug output for the terrain rules
|
||||
#if 0
|
||||
std::cerr << "Built terrain rules: \n";
|
||||
|
||||
building_ruleset::const_iterator rule;
|
||||
|
@ -791,7 +791,7 @@ void terrain_builder::add_off_map_rule(const std::string& image)
|
|||
parse_config(cfg);
|
||||
}
|
||||
|
||||
bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
bool terrain_builder::rule_matches(const terrain_builder::building_rule &rule,
|
||||
const gamemap::location &loc, const int rule_index, const bool check_loc) const
|
||||
{
|
||||
if(rule.location_constraints.valid() && rule.location_constraints != loc) {
|
||||
|
@ -870,7 +870,7 @@ void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, con
|
|||
|
||||
tile& btile = tile_map_[tloc];
|
||||
|
||||
// We want to order the images by layer first and base-y second,
|
||||
// We want to order the images by layer first and base-y second,
|
||||
// so we sort by layer*BASE_Y_INTERVAL + BASE_Y_INTERVAL/2 + basey
|
||||
// Thus, allowed values for basey are from -50000 to 49999
|
||||
for(img = constraint->second.images.begin(); img != constraint->second.images.end(); ++img) {
|
||||
|
@ -903,8 +903,8 @@ int terrain_builder::get_constraint_adjacents(const building_rule& rule, const g
|
|||
return res;
|
||||
}
|
||||
|
||||
// Returns the "size" of a constraint: that is, the number of map tiles
|
||||
// on which this constraint may possibly match.
|
||||
// Returns the "size" of a constraint: that is, the number of map tiles
|
||||
// on which this constraint may possibly match.
|
||||
// INT_MAX means "I don't know / all of them".
|
||||
int terrain_builder::get_constraint_size(const building_rule& rule, const terrain_constraint& constraint, bool& border)
|
||||
{
|
||||
|
@ -916,7 +916,7 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
|||
if(types.front() == t_translation::NOT) {
|
||||
return INT_MAX;
|
||||
}
|
||||
if(std::find(types.begin(), types.end(), t_translation::STAR) != types.end()) {
|
||||
if(std::find(types.begin(), types.end(), t_translation::STAR) != types.end()) {
|
||||
return INT_MAX;
|
||||
}
|
||||
// As soon as the list has 1 wildcard we bail out.
|
||||
|
@ -935,12 +935,12 @@ int terrain_builder::get_constraint_size(const building_rule& rule, const terrai
|
|||
// the "border" flag can be set.
|
||||
for(int i = 0; i < 6; ++i) {
|
||||
if(rule.constraints.find(adj[i]) != rule.constraints.end()) {
|
||||
const t_translation::t_list& atypes =
|
||||
const t_translation::t_list& atypes =
|
||||
rule.constraints.find(adj[i])->second.terrain_types_match.terrain;
|
||||
|
||||
|
||||
t_translation::t_list::const_iterator itor = types.begin();
|
||||
for(; itor != types.end(); ++itor) {
|
||||
if(!terrain_matches(*itor, atypes)) {
|
||||
if(!terrain_matches(*itor, atypes)) {
|
||||
border = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1001,7 +1001,7 @@ void terrain_builder::build_terrains()
|
|||
|
||||
int rule_index = 0;
|
||||
building_ruleset::const_iterator rule;
|
||||
|
||||
|
||||
for(rule = building_rules_.begin(); rule != building_rules_.end(); ++rule) {
|
||||
|
||||
if (rule->second.location_constraints.valid()) {
|
||||
|
@ -1057,7 +1057,7 @@ void terrain_builder::build_terrains()
|
|||
const gamemap::location loc = smallest_constraint->second.loc;
|
||||
const gamemap::location aloc = constraint_most_adjacents->second.loc;
|
||||
|
||||
for(t_translation::t_list::const_iterator c = types.begin();
|
||||
for(t_translation::t_list::const_iterator c = types.begin();
|
||||
c != types.end(); ++c) {
|
||||
|
||||
const std::vector<gamemap::location>* locations;
|
||||
|
@ -1088,7 +1088,7 @@ void terrain_builder::build_terrains()
|
|||
continue;
|
||||
}
|
||||
|
||||
if(rule_matches(rule->second, *itor - loc, rule_index,
|
||||
if(rule_matches(rule->second, *itor - loc, rule_index,
|
||||
static_cast<size_t>
|
||||
(biggest_constraint_adjacent + 1) !=
|
||||
rule->second.constraints.size())) {
|
||||
|
@ -1099,9 +1099,9 @@ void terrain_builder::build_terrains()
|
|||
}
|
||||
} else {
|
||||
//! @todo
|
||||
// Some overlays fail but (probably their map size) this is
|
||||
// fixed by changing the start position from -1 to -2.
|
||||
// So it's no real fix but a hack, so still need
|
||||
// Some overlays fail but (probably their map size) this is
|
||||
// fixed by changing the start position from -1 to -2.
|
||||
// So it's no real fix but a hack, so still need
|
||||
// to figure out the best number -- Mordante
|
||||
for(int x = -2; x <= map_.w(); ++x) {
|
||||
for(int y = -2; y <= map_.h(); ++y) {
|
||||
|
|
230
src/builder.hpp
230
src/builder.hpp
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file builder.hpp
|
||||
//! @file builder.hpp
|
||||
//! Definitions for the terrain builder.
|
||||
|
||||
#ifndef BUILDER_H_INCLUDED
|
||||
|
@ -28,12 +28,12 @@
|
|||
class config;
|
||||
|
||||
/**
|
||||
* The class terrain_builder is constructed from a config object, and a
|
||||
* gamemap object. On construction, it parses the configuration and extracts
|
||||
* the list of [terrain_graphics] rules. Each terrain_graphics rule attaches
|
||||
* The class terrain_builder is constructed from a config object, and a
|
||||
* gamemap object. On construction, it parses the configuration and extracts
|
||||
* the list of [terrain_graphics] rules. Each terrain_graphics rule attaches
|
||||
* one or more images to a specific terrain pattern.
|
||||
* It then applies the rules loaded from the configuration to the current map,
|
||||
* and calculates the list of images that must be associated to each hex of
|
||||
* and calculates the list of images that must be associated to each hex of
|
||||
* the map.
|
||||
*
|
||||
* The get_terrain_at method can then be used to obtain the list of images
|
||||
|
@ -43,12 +43,12 @@ class terrain_builder
|
|||
{
|
||||
public:
|
||||
//! Used as a parameter for the get_terrain_at function.
|
||||
enum ADJACENT_TERRAIN_TYPE {
|
||||
ADJACENT_BACKGROUND, //!< Represents terrains which are to be drawn behind unit sprites
|
||||
ADJACENT_FOREGROUND //!< Represents terrains which are to be drawn in front of them.
|
||||
enum ADJACENT_TERRAIN_TYPE {
|
||||
ADJACENT_BACKGROUND, //!< Represents terrains which are to be drawn behind unit sprites
|
||||
ADJACENT_FOREGROUND //!< Represents terrains which are to be drawn in front of them.
|
||||
};
|
||||
|
||||
/** A shorthand typedef for a list of animated image locators,
|
||||
/** A shorthand typedef for a list of animated image locators,
|
||||
* the base data type returned by the get_terrain_at method.
|
||||
*/
|
||||
typedef std::vector<animated<image::locator> > imagelist;
|
||||
|
@ -56,27 +56,27 @@ public:
|
|||
/** Constructor for the terrain_builder class.
|
||||
*
|
||||
* @param cfg The main grame configuration object, where the
|
||||
* [terrain_graphics] rule reside.
|
||||
* @param level A level (scenario)-specific configuration file,
|
||||
* containing scenario-specific [terrain_graphics] rules.
|
||||
* @param map A properly-initialized gamemap object representing
|
||||
* the current terrain map.
|
||||
* [terrain_graphics] rule reside.
|
||||
* @param level A level (scenario)-specific configuration file,
|
||||
* containing scenario-specific [terrain_graphics] rules.
|
||||
* @param map A properly-initialized gamemap object representing
|
||||
* the current terrain map.
|
||||
* @param offmap_image The filename of the image which will be used as
|
||||
* off map image (see add_off_map_rule()).
|
||||
* This image automatically gets the 'terrain/' prefix
|
||||
* and '.png' suffix
|
||||
* off map image (see add_off_map_rule()).
|
||||
* This image automatically gets the 'terrain/' prefix
|
||||
* and '.png' suffix
|
||||
*/
|
||||
terrain_builder(const config& cfg, const config &level,
|
||||
terrain_builder(const config& cfg, const config &level,
|
||||
const gamemap& map, const std::string& offmap_image);
|
||||
|
||||
/** Returns a vector of strings representing the images to load & blit
|
||||
* together to get the built content for this tile.
|
||||
*
|
||||
* @param loc The location relative the the terrain map,
|
||||
* where we ask for the image list
|
||||
* @param tod The string representing the current time-of day.
|
||||
* Will be used if some images specify several
|
||||
* time-of-day- related variants.
|
||||
* @param loc The location relative the the terrain map,
|
||||
* where we ask for the image list
|
||||
* @param tod The string representing the current time-of day.
|
||||
* Will be used if some images specify several
|
||||
* time-of-day- related variants.
|
||||
* @param terrain_type ADJACENT_BACKGROUND or ADJACENT_FOREGROUND,
|
||||
* depending on wheter we ask for the terrain which is
|
||||
* before, or after the unit sprite.
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
const imagelist *get_terrain_at(const gamemap::location &loc,
|
||||
const std::string &tod, ADJACENT_TERRAIN_TYPE const terrain_type);
|
||||
|
||||
/** Updates the animation at a given tile.
|
||||
/** Updates the animation at a given tile.
|
||||
* Returns true if something has changed, and must be redrawn.
|
||||
*
|
||||
* @param loc the location to update
|
||||
|
@ -96,9 +96,9 @@ public:
|
|||
*/
|
||||
bool update_animation(const gamemap::location &loc);
|
||||
|
||||
/** Performs a "quick-rebuild" of the terrain in a given location.
|
||||
* The "quick-rebuild" is no proper rebuild: it only clears the
|
||||
* terrain cache for a given location, and replaces it with a single,
|
||||
/** Performs a "quick-rebuild" of the terrain in a given location.
|
||||
* The "quick-rebuild" is no proper rebuild: it only clears the
|
||||
* terrain cache for a given location, and replaces it with a single,
|
||||
* default image for this terrain.
|
||||
*
|
||||
* @param loc the location where to rebuild terrains
|
||||
|
@ -106,14 +106,14 @@ public:
|
|||
void rebuild_terrain(const gamemap::location &loc);
|
||||
|
||||
/** Performs a complete rebuild of the list of terrain graphics
|
||||
* attached to a map.
|
||||
* attached to a map.
|
||||
* Should be called when a terrain is changed in the map.
|
||||
*/
|
||||
void rebuild_all();
|
||||
|
||||
/**
|
||||
* An image variant. The in-memory representation of the [variant]
|
||||
* WML tag of the [image] WML tag. When an image only has one variant,
|
||||
* An image variant. The in-memory representation of the [variant]
|
||||
* WML tag of the [image] WML tag. When an image only has one variant,
|
||||
* the [variant] tag may be omitted.
|
||||
*/
|
||||
struct rule_image_variant {
|
||||
|
@ -133,27 +133,27 @@ public:
|
|||
*
|
||||
* <timed_image> ::= <image_name> [ ":" <timing> ]
|
||||
*
|
||||
* Where <image_name> represents the actual filename of an image,
|
||||
* and <timing> the number of milliseconds this image will last
|
||||
* Where <image_name> represents the actual filename of an image,
|
||||
* and <timing> the number of milliseconds this image will last
|
||||
* in the animation.
|
||||
*@endverbatim
|
||||
*/
|
||||
std::string image_string;
|
||||
|
||||
/** An animated image locator built according to the image string.
|
||||
/** An animated image locator built according to the image string.
|
||||
* This will be the image locator which will actually
|
||||
* be returned to the user.
|
||||
*/
|
||||
animated<image::locator> image;
|
||||
/**
|
||||
* The time-of-day to which this variant applies.
|
||||
* The time-of-day to which this variant applies.
|
||||
* Set to the empty string, this variant applies to all TODs.
|
||||
*/
|
||||
std::string tod;
|
||||
};
|
||||
|
||||
/**
|
||||
* A map associating a rule_image_variant to a string representing
|
||||
* A map associating a rule_image_variant to a string representing
|
||||
* the time of day.
|
||||
*/
|
||||
typedef std::map<std::string, rule_image_variant> rule_image_variantlist;
|
||||
|
@ -167,7 +167,7 @@ public:
|
|||
*/
|
||||
struct rule_image {
|
||||
rule_image(int layer, int x, int y, bool global_image=false);
|
||||
|
||||
|
||||
/** The layer of the image for horizontal layering */
|
||||
int layer;
|
||||
/** The position of the image base (that is, the point where
|
||||
|
@ -191,7 +191,7 @@ public:
|
|||
typedef std::vector<rule_image> rule_imagelist;
|
||||
|
||||
/**
|
||||
* The in-memory representation of a [tile] WML rule
|
||||
* The in-memory representation of a [tile] WML rule
|
||||
* inside of a [terrain_graphics] WML rule.
|
||||
*/
|
||||
struct terrain_constraint
|
||||
|
@ -234,7 +234,7 @@ public:
|
|||
void add_image_to_cache(const std::string &tod, ordered_ri_list::const_iterator itor);
|
||||
|
||||
/** Rebuilds the whole image cache, for a given time-of-day.
|
||||
* Must be called when the time-of-day has changed,
|
||||
* Must be called when the time-of-day has changed,
|
||||
* to select the correct images.
|
||||
*
|
||||
* @param tod The current time-of-day
|
||||
|
@ -247,18 +247,18 @@ public:
|
|||
/** The list of flags present in this tile */
|
||||
std::set<std::string> flags;
|
||||
|
||||
/** The list of images associated to this tile, ordered by
|
||||
/** The list of images associated to this tile, ordered by
|
||||
* their layer first and base-y position second.
|
||||
*/
|
||||
ordered_ri_list images;
|
||||
|
||||
/** The list of images which are in front of the unit sprites,
|
||||
* attached to this tile. This member is considered a cache:
|
||||
* attached to this tile. This member is considered a cache:
|
||||
* it is built once, and on-demand.
|
||||
*/
|
||||
imagelist images_foreground;
|
||||
/** The list of images which are behind the unit sprites,
|
||||
* attached to this tile. This member is considered a cache:
|
||||
* attached to this tile. This member is considered a cache:
|
||||
* it is built once, and on-demand.
|
||||
*/
|
||||
imagelist images_background;
|
||||
|
@ -268,7 +268,7 @@ public:
|
|||
std::string last_tod;
|
||||
|
||||
/**
|
||||
* The 6 adjacent terrains of this tile,
|
||||
* The 6 adjacent terrains of this tile,
|
||||
* and the terrain on this tile.
|
||||
*/
|
||||
t_translation::t_letter adjacents[7];
|
||||
|
@ -292,8 +292,8 @@ private:
|
|||
constraint_set constraints;
|
||||
|
||||
/**
|
||||
* The location on which this map may match.
|
||||
* Set to a valid gamemap::location if the "x" and "y" parameters
|
||||
* The location on which this map may match.
|
||||
* Set to a valid gamemap::location if the "x" and "y" parameters
|
||||
* of the [terrain_graphics] rule are set.
|
||||
*/
|
||||
gamemap::location location_constraints;
|
||||
|
@ -307,8 +307,8 @@ private:
|
|||
|
||||
/**
|
||||
* The precedence of this rule. Used to order rules differently
|
||||
* that the order in which they appear.
|
||||
* Defined if the "precedence" parameter of the
|
||||
* that the order in which they appear.
|
||||
* Defined if the "precedence" parameter of the
|
||||
* [terrain_graphics] element is set.
|
||||
*/
|
||||
int precedence;
|
||||
|
@ -331,7 +331,7 @@ private:
|
|||
*
|
||||
* @param loc The location of the tile
|
||||
*
|
||||
* @return A reference to the tile at this location.
|
||||
* @return A reference to the tile at this location.
|
||||
*
|
||||
*/
|
||||
tile &operator[](const gamemap::location &loc);
|
||||
|
@ -345,7 +345,7 @@ private:
|
|||
*
|
||||
* @param loc The location to test
|
||||
*
|
||||
* @return true if loc is on the map, false otherwise.
|
||||
* @return true if loc is on the map, false otherwise.
|
||||
*/
|
||||
bool on_map(const gamemap::location &loc) const;
|
||||
|
||||
|
@ -363,7 +363,7 @@ private:
|
|||
};
|
||||
|
||||
/**
|
||||
* A set of building rules. In-memory representation
|
||||
* A set of building rules. In-memory representation
|
||||
* of the whole set of [terrain_graphics] rules.
|
||||
*/
|
||||
typedef std::multimap<int, building_rule> building_ruleset;
|
||||
|
@ -375,7 +375,7 @@ private:
|
|||
*
|
||||
* @param rule The rule to test for validity
|
||||
*
|
||||
* @return true if the rule is valid, false if it is not.
|
||||
* @return true if the rule is valid, false if it is not.
|
||||
*/
|
||||
bool rule_valid(const building_rule &rule) const;
|
||||
|
||||
|
@ -384,25 +384,25 @@ private:
|
|||
*
|
||||
* @param rule The rule on which ot start animations
|
||||
*
|
||||
* @return true
|
||||
* @return true
|
||||
*/
|
||||
bool start_animation(building_rule &rule);
|
||||
|
||||
/**
|
||||
* "Rotates" a constraint from a rule.
|
||||
* Takes a template constraint from a template rule, and creates
|
||||
* "Rotates" a constraint from a rule.
|
||||
* Takes a template constraint from a template rule, and creates
|
||||
* a constraint from this template, rotated to the given angle.
|
||||
*
|
||||
* On a constraint, the relative position of each rule, and the "base"
|
||||
* of each vertical images, are rotated according to the given angle.
|
||||
*
|
||||
* Template terrain constraints are defined like normal terrain
|
||||
* constraints, except that, flags, and image filenames,
|
||||
* may contain template strings of the form
|
||||
* constraints, except that, flags, and image filenames,
|
||||
* may contain template strings of the form
|
||||
*@verbatim
|
||||
* <code>@Rn</code>,
|
||||
* <code>@Rn</code>,
|
||||
*@endverbatim
|
||||
* n being a number from 0 to 5.
|
||||
* n being a number from 0 to 5.
|
||||
* See the rotate_rule method for more info.
|
||||
*
|
||||
* @param constraint A template constraint to rotate
|
||||
|
@ -421,7 +421,7 @@ private:
|
|||
const std::string& replacement);
|
||||
|
||||
/**
|
||||
* Replaces, in a given rule_image, a token with its value.
|
||||
* Replaces, in a given rule_image, a token with its value.
|
||||
* The actual substitution is done in all variants of the given image.
|
||||
*
|
||||
* @param image The rule_image in which to do the replacement
|
||||
|
@ -432,8 +432,8 @@ private:
|
|||
const std::string& replacement);
|
||||
|
||||
/**
|
||||
* Replaces, in a given rule_variant_image, a token with its value.
|
||||
* The actual substitution is done in the "image_string" parameter
|
||||
* Replaces, in a given rule_variant_image, a token with its value.
|
||||
* The actual substitution is done in the "image_string" parameter
|
||||
* of this rule_variant_image.
|
||||
*
|
||||
* @param variant The rule_variant_image in which to do the replacement
|
||||
|
@ -445,22 +445,22 @@ private:
|
|||
{ replace_token(variant.image_string, token, replacement); }
|
||||
|
||||
/**
|
||||
* Replaces, in a given rule_imagelist, a token with its value.
|
||||
* The actual substitution is done in all rule_images contained
|
||||
* Replaces, in a given rule_imagelist, a token with its value.
|
||||
* The actual substitution is done in all rule_images contained
|
||||
* in the rule_imagelist.
|
||||
*
|
||||
* @param & The rule_imagelist in which to do the replacement
|
||||
* @param token The token to substitute
|
||||
* @param replacement The replacement string
|
||||
* @param token The token to substitute
|
||||
* @param replacement The replacement string
|
||||
*/
|
||||
void replace_token(rule_imagelist &, const std::string &token,
|
||||
const std::string& replacement);
|
||||
|
||||
/**
|
||||
* Replaces, in a given building_rule, a token with its value.
|
||||
* The actual substitution is done in the rule_imagelists contained
|
||||
* in all constraints of the building_rule, and in the flags
|
||||
* (has_flag, set_flag and no_flag) contained in all constraints
|
||||
* Replaces, in a given building_rule, a token with its value.
|
||||
* The actual substitution is done in the rule_imagelists contained
|
||||
* in all constraints of the building_rule, and in the flags
|
||||
* (has_flag, set_flag and no_flag) contained in all constraints
|
||||
* of the building_rule.
|
||||
*
|
||||
* @param s The building_rule in which to do the replacement
|
||||
|
@ -479,38 +479,38 @@ private:
|
|||
* <code>@Rn</code>, n being a number from 0 to 5.
|
||||
*@endverbatim
|
||||
* * The rule contains the rotations=r0,r1,r2,r3,r4,r5, with r0 to r5
|
||||
* being strings describing the 6 different positions, typically,
|
||||
* being strings describing the 6 different positions, typically,
|
||||
* n, ne, se, s, sw, and nw (but maybe anything else.)
|
||||
*
|
||||
* A template rule will generate 6 rules, which are similar
|
||||
* A template rule will generate 6 rules, which are similar
|
||||
* to the template, except that:
|
||||
*
|
||||
* * The map of constraints ( [tile]s ) of this rule will be
|
||||
* * The map of constraints ( [tile]s ) of this rule will be
|
||||
* rotated by an angle, of 0 to 5 pi / 6
|
||||
*
|
||||
* * On the rule which is rotated to 0rad, the template strings
|
||||
* * On the rule which is rotated to 0rad, the template strings
|
||||
*@verbatim
|
||||
* @R0, @R1, @R2, @R3, @R4, @R5,
|
||||
* @R0, @R1, @R2, @R3, @R4, @R5,
|
||||
*@endverbatim
|
||||
* will be replaced by the corresponding r0, r1, r2, r3, r4, r5
|
||||
* will be replaced by the corresponding r0, r1, r2, r3, r4, r5
|
||||
* variables given in the rotations= element.
|
||||
*
|
||||
* * On the rule which is rotated to pi/3 rad, the template strings
|
||||
*@verbatim
|
||||
* @R0, @R1, @R2 etc.
|
||||
* @R0, @R1, @R2 etc.
|
||||
*@endverbatim
|
||||
* will be replaced by the corresponding
|
||||
* will be replaced by the corresponding
|
||||
* <strong>r1, r2, r3, r4, r5, r0</strong> (note the shift in indices).
|
||||
*
|
||||
* * On the rule rotated 2pi/3, those will be replaced by
|
||||
* * On the rule rotated 2pi/3, those will be replaced by
|
||||
* r2, r3, r4, r5, r0, r1 and so on.
|
||||
*
|
||||
*/
|
||||
building_rule rotate_rule(const building_rule &rule, int angle,
|
||||
building_rule rotate_rule(const building_rule &rule, int angle,
|
||||
const std::vector<std::string>& angle_name);
|
||||
|
||||
/**
|
||||
* Parses a "config" object, which should contains [image] children,
|
||||
* Parses a "config" object, which should contains [image] children,
|
||||
* and adds the corresponding parsed rule_images to a rule_imagelist.
|
||||
*
|
||||
* @param images The rule_imagelist into which to add the parsed images.
|
||||
|
@ -544,7 +544,7 @@ private:
|
|||
const config& global_images);
|
||||
|
||||
/**
|
||||
* Creates a rule constraint object from a config object and
|
||||
* Creates a rule constraint object from a config object and
|
||||
* adds it to the list of constraints of a rule.
|
||||
*
|
||||
* @param constraints The constraint set to which to add the constraint.
|
||||
|
@ -583,14 +583,14 @@ private:
|
|||
void add_rule(building_ruleset& rules, building_rule &rule);
|
||||
|
||||
/**
|
||||
* Adds a set of rules to a ruleset, from a template rule which spans
|
||||
* Adds a set of rules to a ruleset, from a template rule which spans
|
||||
* 6 rotations (or less if some of the rotated rules are invalid).
|
||||
*
|
||||
* @param rules The ruleset into which to add the rules.
|
||||
* @param tpl The template rule
|
||||
* @param rotations A comma-separated string containing the
|
||||
* 6 values for replacing rotation
|
||||
* template strings @verbatim (@Rn) @endverbatim
|
||||
* @param rotations A comma-separated string containing the
|
||||
* 6 values for replacing rotation
|
||||
* template strings @verbatim (@Rn) @endverbatim
|
||||
*/
|
||||
void add_rotated_rules(building_ruleset& rules, building_rule& tpl, const std::string &rotations);
|
||||
|
||||
|
@ -599,7 +599,7 @@ private:
|
|||
* and fills the building_rules_ member of the current class according
|
||||
* to those.
|
||||
*
|
||||
* @param cfg The configuration object to parse.
|
||||
* @param cfg The configuration object to parse.
|
||||
*/
|
||||
void parse_config(const config &cfg);
|
||||
|
||||
|
@ -613,27 +613,27 @@ private:
|
|||
/**
|
||||
* Checks whether a terrain letter matches a given list of terrain letters.
|
||||
*
|
||||
* @param letter The terrain to check
|
||||
* @param terrains The terrain list agains which to check the terrain.
|
||||
* May contain the metacharacters
|
||||
* - '*' STAR, meaning "all terrains"
|
||||
* - '!' NOT, meaning "all terrains except those present in the list."
|
||||
* @param letter The terrain to check
|
||||
* @param terrains The terrain list agains which to check the terrain.
|
||||
* May contain the metacharacters
|
||||
* - '*' STAR, meaning "all terrains"
|
||||
* - '!' NOT, meaning "all terrains except those present in the list."
|
||||
*
|
||||
* @return returns true if "letter" matches the list or the list is empty,
|
||||
* else false.
|
||||
* @return returns true if "letter" matches the list or the list is empty,
|
||||
* else false.
|
||||
*/
|
||||
bool terrain_matches(t_translation::t_letter letter, const t_translation::t_list& terrains) const
|
||||
bool terrain_matches(t_translation::t_letter letter, const t_translation::t_list& terrains) const
|
||||
{ return terrains.empty()? true : t_translation::terrain_matches(letter, terrains); }
|
||||
|
||||
/**
|
||||
* Checks whether a terrain letter matches a given list of terrain letters.
|
||||
*
|
||||
* @param letter The terrain to check
|
||||
* @param terrain The terrain match structure which to check the terrain.
|
||||
* See previous definition for more details.
|
||||
* @param letter The terrain to check
|
||||
* @param terrain The terrain match structure which to check the terrain.
|
||||
* See previous definition for more details.
|
||||
*
|
||||
* @return returns true if "letter" matches the list or the list is empty,
|
||||
* else false.
|
||||
* @return returns true if "letter" matches the list or the list is empty,
|
||||
* else false.
|
||||
*/
|
||||
bool terrain_matches(t_translation::t_letter letter, const t_translation::t_match &terrain) const
|
||||
{ return terrain.is_empty ? true : t_translation::terrain_matches(letter, terrain); }
|
||||
|
@ -651,15 +651,15 @@ private:
|
|||
* @param check_loc If this parameter is set to false, the "location"
|
||||
* of the rule (ie, whether all constraints's terrain
|
||||
* types do actually match) will be assumed to be
|
||||
* already checked, only flags and probability
|
||||
* already checked, only flags and probability
|
||||
* will be checked.
|
||||
*/
|
||||
bool rule_matches(const building_rule &rule, const gamemap::location &loc,
|
||||
const int rule_index, const bool check_loc) const;
|
||||
|
||||
/**
|
||||
* Applies a rule at a given location: applies the result of a
|
||||
* matching rule at a given location: attachs the images corresponding
|
||||
* Applies a rule at a given location: applies the result of a
|
||||
* matching rule at a given location: attachs the images corresponding
|
||||
* to the rule, and sets the flags corresponding to the rule.
|
||||
*
|
||||
* @param rule The rule to apply
|
||||
|
@ -668,8 +668,8 @@ private:
|
|||
void apply_rule(const building_rule &rule, const gamemap::location &loc);
|
||||
|
||||
/**
|
||||
* Returns the number of constraints adjacent to a given constraint
|
||||
* in a rule.
|
||||
* Returns the number of constraints adjacent to a given constraint
|
||||
* in a rule.
|
||||
* For example, if the rule map is something like that
|
||||
* 1 .
|
||||
* 2
|
||||
|
@ -678,30 +678,30 @@ private:
|
|||
* to the "3", will each have 1 adjacent contraint, whereas the
|
||||
* constraint corresponding to the "2" will have 2.
|
||||
*
|
||||
* @param rule The rule this applies to
|
||||
* @param loc The location of the constraint to check for
|
||||
* adjacent constraints
|
||||
* @param rule The rule this applies to
|
||||
* @param loc The location of the constraint to check for
|
||||
* adjacent constraints
|
||||
*
|
||||
* @return the number of constraints adjacent to the location loc
|
||||
* @return the number of constraints adjacent to the location loc
|
||||
*/
|
||||
int get_constraint_adjacents(const building_rule& rule, const gamemap::location& loc);
|
||||
|
||||
/**
|
||||
* Returns the "size" of a constraint, that is, the number of tiles,
|
||||
* in the current map, on which this constraint may possibly match.
|
||||
* This is used to exclude positions where the rule has
|
||||
* Returns the "size" of a constraint, that is, the number of tiles,
|
||||
* in the current map, on which this constraint may possibly match.
|
||||
* This is used to exclude positions where the rule has
|
||||
* no change to match from being checked for.
|
||||
*
|
||||
* The terrain_by_type_border_ and terrain_by_type_ arrays
|
||||
* The terrain_by_type_border_ and terrain_by_type_ arrays
|
||||
* must be initialized before this method is called.
|
||||
*
|
||||
* @param rule The rule to check for
|
||||
* @param constraint The constraint to check for
|
||||
* @param border (out) Set to true if this constraint applies to a non-isolated tile
|
||||
*
|
||||
* @return The number of tiles in the current map, on which
|
||||
* the current constraint may match.
|
||||
* INT_MAX means "all of them" or "unable to determine".
|
||||
* @return The number of tiles in the current map, on which
|
||||
* the current constraint may match.
|
||||
* INT_MAX means "all of them" or "unable to determine".
|
||||
*/
|
||||
int get_constraint_size(const building_rule& rule, const terrain_constraint& constraint,
|
||||
bool& border);
|
||||
|
@ -733,7 +733,7 @@ private:
|
|||
*/
|
||||
terrain_by_type_map terrain_by_type_;
|
||||
/**
|
||||
* A map representing all locations whose terrain
|
||||
* A map representing all locations whose terrain
|
||||
* is adjacent to a terrain of a given type.
|
||||
*/
|
||||
terrain_by_type_map terrain_by_type_border_;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <map>
|
||||
|
||||
|
||||
// the fork execute is unix specific only tested on Linux quite sure it won't
|
||||
// the fork execute is unix specific only tested on Linux quite sure it won't
|
||||
// work on Windows not sure which other platforms have a problem with it.
|
||||
#if !(defined(_WIN32))
|
||||
#include <errno.h>
|
||||
|
@ -85,7 +85,7 @@ namespace {
|
|||
bool campaign_server::fire(const std::string& hook)
|
||||
{
|
||||
out_.resize(0);
|
||||
|
||||
|
||||
const std::map<std::string, std::string>::const_iterator itor = hooks_.find(hook);
|
||||
if(itor == hooks_.end()) return true;
|
||||
|
||||
|
@ -95,17 +95,17 @@ namespace {
|
|||
#if (defined(_WIN32))
|
||||
construct_error("Tried to execute a script on a not supporting platform");
|
||||
return false;
|
||||
#else
|
||||
#else
|
||||
|
||||
int fd_out[2], fd_err[2];
|
||||
pid_t childpid;
|
||||
|
||||
pipe(fd_out);
|
||||
pipe(fd_err);
|
||||
|
||||
|
||||
if((childpid = fork()) == -1) {
|
||||
construct_error("fork failed");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(childpid == 0) {
|
||||
|
@ -145,7 +145,7 @@ namespace {
|
|||
|
||||
while (read(fd_err[0], &buf, 1) > 0) error += buf;
|
||||
if(!error.empty()) construct_error(error);
|
||||
|
||||
|
||||
// read the message for the user
|
||||
while (read(fd_out[0], &buf, 1) > 0) out_ += buf;
|
||||
|
||||
|
@ -384,7 +384,7 @@ namespace {
|
|||
network::send_data(construct_error("The name of the add-on is invalid"),sock);
|
||||
} else if(check_names_legal(*data) == false) {
|
||||
network::send_data(construct_error("The add-on contains an illegal file or directory name."),sock);
|
||||
} else if(! fire("hook_pre_upload")) {
|
||||
} else if(! fire("hook_pre_upload")) {
|
||||
if(out_ == "") {
|
||||
network::send_data(construct_error("The add-on failed with unknown error in pre-upload hook."),sock);
|
||||
} else {
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
|
||||
#define LOG_NG LOG_STREAM(info, engine)
|
||||
|
||||
cave_map_generator::cave_map_generator(const config* cfg) : wall_(t_translation::CAVE_WALL),
|
||||
clear_(t_translation::CAVE), village_(t_translation::UNDERGROUND_VILLAGE),
|
||||
castle_(t_translation::DWARVEN_CASTLE), keep_(t_translation::DWARVEN_KEEP),
|
||||
cfg_(cfg), width_(50), height_(50),
|
||||
cave_map_generator::cave_map_generator(const config* cfg) : wall_(t_translation::CAVE_WALL),
|
||||
clear_(t_translation::CAVE), village_(t_translation::UNDERGROUND_VILLAGE),
|
||||
castle_(t_translation::DWARVEN_CASTLE), keep_(t_translation::DWARVEN_KEEP),
|
||||
cfg_(cfg), width_(50), height_(50),
|
||||
village_density_(0), flipx_(false), flipy_(false)
|
||||
{
|
||||
if(cfg_ == NULL) {
|
||||
|
@ -101,7 +101,7 @@ config cave_map_generator::create_scenario(const std::vector<std::string>& /*arg
|
|||
LOG_NG << "outputting map....\n";
|
||||
|
||||
res_["map_data"] = t_translation::write_game_map(map_, starting_positions_);
|
||||
|
||||
|
||||
LOG_NG << "returning result...\n";
|
||||
|
||||
return res_;
|
||||
|
@ -280,8 +280,8 @@ void cave_map_generator::place_items(const chamber& c, config::all_children_iter
|
|||
|
||||
struct passage_path_calculator : cost_calculator
|
||||
{
|
||||
passage_path_calculator(const t_translation::t_map& mapdata,
|
||||
t_translation::t_letter wall, double laziness, size_t windiness):
|
||||
passage_path_calculator(const t_translation::t_map& mapdata,
|
||||
t_translation::t_letter wall, double laziness, size_t windiness):
|
||||
map_(mapdata), wall_(wall), laziness_(laziness), windiness_(windiness)
|
||||
{}
|
||||
|
||||
|
@ -341,7 +341,7 @@ void cave_map_generator::place_passage(const passage& p)
|
|||
void cave_map_generator::set_terrain(gamemap::location loc, t_translation::t_letter t)
|
||||
{
|
||||
if(on_board(loc)) {
|
||||
if(t == clear_ &&
|
||||
if(t == clear_ &&
|
||||
(rand() % 1000) < static_cast<long>(village_density_)) {
|
||||
|
||||
t = village_;
|
||||
|
@ -361,7 +361,7 @@ void cave_map_generator::place_castle(const std::string& side, gamemap::location
|
|||
set_terrain(loc, keep_);
|
||||
|
||||
const struct t_translation::coordinate coord = {loc.x, loc.y};
|
||||
starting_positions_[starting_position] = coord;
|
||||
starting_positions_[starting_position] = coord;
|
||||
}
|
||||
|
||||
gamemap::location adj[6];
|
||||
|
|
|
@ -59,8 +59,8 @@ private:
|
|||
void place_passage(const passage& p);
|
||||
|
||||
bool on_board(const gamemap::location& loc) const
|
||||
{ return loc.x >= 0 && loc.y >= 0 &&
|
||||
loc.x < static_cast<long>(width_) &&
|
||||
{ return loc.x >= 0 && loc.y >= 0 &&
|
||||
loc.x < static_cast<long>(width_) &&
|
||||
loc.y < static_cast<long>(height_); }
|
||||
|
||||
void set_terrain(gamemap::location loc, t_translation::t_letter t);
|
||||
|
|
|
@ -63,7 +63,7 @@ std::map<Uint32, Uint32> recolor_range(const color_range& new_range, const std::
|
|||
new_g=Uint32( old_rat * new_green + (1 - old_rat) * min_green);
|
||||
new_b=Uint32( old_rat * new_blue + (1 - old_rat) * min_blue);
|
||||
}else if(255 - reference_avg){
|
||||
float old_rat = (255.0 - static_cast<float>(old_avg)) /
|
||||
float old_rat = (255.0 - static_cast<float>(old_avg)) /
|
||||
(255.0 - reference_avg);
|
||||
|
||||
new_r=static_cast<Uint32>( old_rat * new_red + (1 - old_rat) * max_red);
|
||||
|
@ -135,7 +135,7 @@ std::vector<Uint32> palette(color_range cr){
|
|||
}
|
||||
|
||||
// Use recolor function to generate list of possible colors.
|
||||
// Could use a special function, would be more efficient,
|
||||
// Could use a special function, would be more efficient,
|
||||
// but harder to maintain.
|
||||
std::map<Uint32,Uint32> cmap = recolor_range(cr,temp);
|
||||
for(std::map<Uint32,Uint32>::const_iterator k=cmap.begin(); k!=cmap.end();k++){
|
||||
|
@ -153,7 +153,7 @@ std::string rgb2highlight(Uint32 rgb)
|
|||
{
|
||||
std::stringstream h("");
|
||||
// Must match what the escape interpreter for marked-up-text expects
|
||||
h << "<" << ((rgb & 0xFF0000) >> 16)
|
||||
h << "<" << ((rgb & 0xFF0000) >> 16)
|
||||
<< "," << ((rgb & 0x00FF00) >> 8)
|
||||
<< "," << (rgb & 0x0000FF) << ">";
|
||||
return h.str();
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*/
|
||||
|
||||
//! @file color_range.hpp
|
||||
//!
|
||||
//!
|
||||
|
||||
#ifndef COLOR_RANGE_H_INCLUDED
|
||||
#define COLOR_RANGE_H_INCLUDED
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file config.cpp
|
||||
//! @file config.cpp
|
||||
//! Routines related to configuration-files / WML.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -211,7 +211,7 @@ void config::remove_child(const std::string& key, size_t index)
|
|||
const child_pos pos(children.find(key),index);
|
||||
ordered_children.erase(std::remove(ordered_children.begin(),ordered_children.end(),pos),ordered_children.end());
|
||||
|
||||
// Decrement all indices in the ordering that are above this index,
|
||||
// Decrement all indices in the ordering that are above this index,
|
||||
// since everything is getting shifted back by 1.
|
||||
for(std::vector<child_pos>::iterator i = ordered_children.begin(); i != ordered_children.end(); ++i) {
|
||||
if(i->pos->first == key && i->index > index) {
|
||||
|
@ -266,7 +266,7 @@ private:
|
|||
const std::string name_, value_;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
config* config::find_child(const std::string& key,
|
||||
const std::string& name,
|
||||
|
@ -429,7 +429,7 @@ config config::get_diff(const config& c) const
|
|||
// delete, insert, or change is the best to get b[bi] looking like a[ai].
|
||||
std::stringstream buf;
|
||||
|
||||
// If b has more elements than a, then we assume this element
|
||||
// If b has more elements than a, then we assume this element
|
||||
// is an element that needs deleting.
|
||||
if(b.size() - bi > a.size() - ai) {
|
||||
config& new_delete = res.add_child("delete_child");
|
||||
|
@ -441,7 +441,7 @@ config config::get_diff(const config& c) const
|
|||
++bi;
|
||||
}
|
||||
|
||||
// If b has less elements than a, then we assume this element
|
||||
// If b has less elements than a, then we assume this element
|
||||
// is an element that needs inserting.
|
||||
else if(b.size() - bi < a.size() - ai) {
|
||||
config& new_insert = res.add_child("insert_child");
|
||||
|
@ -452,7 +452,7 @@ config config::get_diff(const config& c) const
|
|||
++ai;
|
||||
}
|
||||
|
||||
// Otherwise, they have the same number of elements,
|
||||
// Otherwise, they have the same number of elements,
|
||||
// so try just changing this element to match.
|
||||
else {
|
||||
config& new_change = res.add_child("change_child");
|
||||
|
@ -561,7 +561,7 @@ void config::merge_with(const config& c)
|
|||
}
|
||||
/*
|
||||
// Create a new config tree as a copy of 'this' overridden by 'c'.
|
||||
// Nodes are matched up by name and with name by order.
|
||||
// Nodes are matched up by name and with name by order.
|
||||
// Nodes in 'c', but not in 'this' are added at the end,
|
||||
// in the order they appeared in 'c'.
|
||||
config config::merge_with(const config& c) const
|
||||
|
@ -571,7 +571,7 @@ config config::merge_with(const config& c) const
|
|||
j != this->values.end(); ++j) {
|
||||
n.values[j->first] = j->second;
|
||||
}
|
||||
// This ends up copying values twice (in config initialization
|
||||
// This ends up copying values twice (in config initialization
|
||||
// and append), but is simpler than dealing with the guts of m.
|
||||
config m(c);
|
||||
for(all_children_iterator i = this->ordered_begin();
|
||||
|
@ -594,7 +594,7 @@ bool config::matches(const config &filter) const
|
|||
{
|
||||
// First match values. all values should match.
|
||||
for(string_map::const_iterator j = filter.values.begin(); j != filter.values.end(); ++j) {
|
||||
if(!this->values.count(j->first)) return false;
|
||||
if(!this->values.count(j->first)) return false;
|
||||
const t_string& test_val = this->values.find(j->first)->second;
|
||||
if(test_val != j->second) {
|
||||
const std::string& boolcheck = j->second.base_str();
|
||||
|
@ -611,7 +611,7 @@ bool config::matches(const config &filter) const
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now, match the kids
|
||||
for(all_children_iterator i2 = filter.ordered_begin(); i2 != filter.ordered_end(); ++i2) {
|
||||
if(*(*i2).first == "not") continue;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file config.hpp
|
||||
//! @file config.hpp
|
||||
//! Definitions for the interface to Wesnoth Markup Language (WML).
|
||||
|
||||
#ifndef CONFIG_HPP_INCLUDED
|
||||
|
@ -29,11 +29,11 @@
|
|||
|
||||
|
||||
// This module defines the interface to Wesnoth Markup Language (WML).
|
||||
// WML is a simple hierarchical text-based file format.
|
||||
// WML is a simple hierarchical text-based file format.
|
||||
// The format is defined in Wiki, under BuildingScenariosWML
|
||||
//
|
||||
// All configuration files are stored in this format,
|
||||
// and data is sent across the network in this format.
|
||||
// All configuration files are stored in this format,
|
||||
// and data is sent across the network in this format.
|
||||
// It is thus used extensively throughout the game.
|
||||
|
||||
typedef std::map<std::string,t_string> string_map;
|
||||
|
@ -129,9 +129,9 @@ public:
|
|||
all_children_iterator ordered_begin() const;
|
||||
all_children_iterator ordered_end() const;
|
||||
|
||||
//! A function to get the differences between this object,
|
||||
//! and 'c', as another config object.
|
||||
//! I.e. calling cfg2.apply_diff(cfg1.get_diff(cfg2))
|
||||
//! A function to get the differences between this object,
|
||||
//! and 'c', as another config object.
|
||||
//! I.e. calling cfg2.apply_diff(cfg1.get_diff(cfg2))
|
||||
//! will make cfg1 identical to cfg2.
|
||||
config get_diff(const config& c) const;
|
||||
|
||||
|
@ -144,11 +144,11 @@ public:
|
|||
//! Removes keys with empty values.
|
||||
void prune();
|
||||
|
||||
//! Append data from another config object to this one.
|
||||
//! 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);
|
||||
|
||||
//! All children with the given key will be merged
|
||||
//! All children with the given key will be merged
|
||||
//! into the first element with that key.
|
||||
void merge_children(const std::string& key);
|
||||
|
||||
|
|
|
@ -81,13 +81,13 @@ std::vector<std::string> empty_string_vector;
|
|||
|
||||
namespace gui {
|
||||
|
||||
dialog::dimension_measurements::dimension_measurements() :x(-1), y(-1), interior(empty_rect),
|
||||
message(empty_rect), textbox(empty_rect), menu_height(-1)
|
||||
dialog::dimension_measurements::dimension_measurements() :x(-1), y(-1), interior(empty_rect),
|
||||
message(empty_rect), textbox(empty_rect), menu_height(-1)
|
||||
{
|
||||
//note: this is not defined in the header file to C++ ODR (one-definition rule)
|
||||
//since each inclusion of the header file uses a different version of empty_rect
|
||||
//(unnamed namespace and/or const object defined at declaration time).
|
||||
}
|
||||
//since each inclusion of the header file uses a different version of empty_rect
|
||||
//(unnamed namespace and/or const object defined at declaration time).
|
||||
}
|
||||
|
||||
dialog::dialog(display &disp, const std::string& title, const std::string& message,
|
||||
const DIALOG_TYPE type, const style& dialog_style) : disp_(disp), image_(NULL),
|
||||
|
@ -811,5 +811,5 @@ void message_dialog::action(gui::dialog_process_info &dp_info)
|
|||
message_dialog::~message_dialog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}//end namespace gui
|
||||
|
|
|
@ -178,10 +178,10 @@ public:
|
|||
//Constructor & destructor
|
||||
//dialog - throws button::error() if standard buttons fail to initialize
|
||||
// throws utils::invalid_utf8_exception() if message is invalid
|
||||
dialog(display &disp,
|
||||
const std::string& title="",
|
||||
dialog(display &disp,
|
||||
const std::string& title="",
|
||||
const std::string& message="",
|
||||
const DIALOG_TYPE type=MESSAGE,
|
||||
const DIALOG_TYPE type=MESSAGE,
|
||||
const style& dialog_style=default_style);
|
||||
virtual ~dialog();
|
||||
|
||||
|
@ -253,7 +253,7 @@ private:
|
|||
display &disp_;
|
||||
dialog_image *image_;
|
||||
const std::string title_;
|
||||
const style& style_;
|
||||
const style& style_;
|
||||
label *title_widget_, *message_;
|
||||
const DIALOG_TYPE type_;
|
||||
gui::menu *menu_;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file cursor.cpp
|
||||
//! @file cursor.cpp
|
||||
//! Support for different cursors-shapes.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -55,7 +55,7 @@ static SDL_Cursor* create_cursor(surface surf)
|
|||
std::vector<Uint8> data((cursor_width*nsurf->h)/8,0);
|
||||
std::vector<Uint8> mask(data.size(),0);
|
||||
|
||||
// See http://sdldoc.csn.ul.ie/sdlcreatecursor.php for documentation
|
||||
// See http://sdldoc.csn.ul.ie/sdlcreatecursor.php for documentation
|
||||
// on the format that data has to be in to pass to SDL_CreateCursor
|
||||
surface_lock lock(nsurf);
|
||||
const Uint32* const pixels = reinterpret_cast<Uint32*>(lock.pixels());
|
||||
|
@ -168,16 +168,16 @@ void set(CURSOR_TYPE type)
|
|||
// Except if the current one is also invalid.
|
||||
// In this case, change to a valid one.
|
||||
current_cursor = NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
const CURSOR_TYPE new_cursor = use_colour_cursors() && colour_ready ? cursor::NO_CURSOR : current_cursor;
|
||||
|
||||
SDL_Cursor * cursor_image = get_cursor(new_cursor);
|
||||
|
||||
|
||||
// Causes problem on Mac:
|
||||
//if (cursor_image != NULL && cursor_image != SDL_GetCursor())
|
||||
SDL_SetCursor(cursor_image);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void set_dragging(bool drag)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file cursor.hpp
|
||||
//! @file cursor.hpp
|
||||
//!
|
||||
|
||||
#ifndef CURSOR_HPP_INCLUDED
|
||||
|
|
|
@ -43,8 +43,8 @@ void advance_unit(const game_data& info,
|
|||
const gamemap& map,
|
||||
unit_map& units,
|
||||
gamemap::location loc,
|
||||
game_display& gui,
|
||||
bool random_choice,
|
||||
game_display& gui,
|
||||
bool random_choice,
|
||||
const bool add_replay_event)
|
||||
{
|
||||
unit_map::iterator u = units.find(loc);
|
||||
|
@ -118,8 +118,8 @@ void advance_unit(const game_data& info,
|
|||
|
||||
LOG_DP << "animating advancement...\n";
|
||||
animate_unit_advancement(info,units,loc,gui,size_t(res));
|
||||
|
||||
// in some rare cases the unit can have enough XP to advance again so try to do that,
|
||||
|
||||
// in some rare cases the unit can have enough XP to advance again so try to do that,
|
||||
// make sure that we're no entering an infinite level loop
|
||||
u = units.find(loc);
|
||||
if(u != units.end()) {
|
||||
|
@ -127,7 +127,7 @@ void advance_unit(const game_data& info,
|
|||
if(u->second.experience() < 81) {
|
||||
advance_unit(info, map, units, loc, gui, random_choice, add_replay_event);
|
||||
} else {
|
||||
LOG_STREAM(err, config) << "Unit has an too high amount of " << u->second.experience()
|
||||
LOG_STREAM(err, config) << "Unit has an too high amount of " << u->second.experience()
|
||||
<< " XP left, cascade leveling disabled\n";
|
||||
}
|
||||
} else {
|
||||
|
@ -394,7 +394,7 @@ void save_preview_pane::draw_contents()
|
|||
const config* const scenario = game_config_->find_child(summary["campaign_type"],"id",summary["scenario"]);
|
||||
if(scenario != NULL && scenario->find_child("side","shroud","yes") == NULL) {
|
||||
map_data = (*scenario)["map_data"];
|
||||
if(map_data.empty() && (*scenario)["map"].empty() == false) {
|
||||
if(map_data.empty() && (*scenario)["map"].empty() == false) {
|
||||
try {
|
||||
map_data = read_map((*scenario)["map"]);
|
||||
} catch(io_exception& e) {
|
||||
|
@ -402,7 +402,7 @@ void save_preview_pane::draw_contents()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
surface map_surf(NULL);
|
||||
|
||||
|
@ -587,7 +587,7 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
|
|||
//create an option for whether the replay should be shown or not
|
||||
if(show_replay != NULL)
|
||||
lmenu.add_option(_("Show replay"), false);
|
||||
lmenu.add_button(delete_button);
|
||||
lmenu.add_button(delete_button);
|
||||
const int res = lmenu.show();
|
||||
|
||||
write_save_index();
|
||||
|
@ -680,9 +680,9 @@ void unit_preview_pane::draw_contents()
|
|||
const clip_rect_setter clipper(screen,clip_area);
|
||||
|
||||
surface unit_image = u.still_image();
|
||||
if (!left_)
|
||||
if (!left_)
|
||||
unit_image = image::reverse_image(unit_image);
|
||||
|
||||
|
||||
SDL_Rect image_rect = {area.x,area.y,0,0};
|
||||
|
||||
if(unit_image != NULL) {
|
||||
|
|
|
@ -28,7 +28,7 @@ class game_display;
|
|||
#include "file_chooser.hpp"
|
||||
|
||||
namespace dialogs {
|
||||
|
||||
|
||||
//function to handle an advancing unit. If there is only one choice to advance
|
||||
//to, the unit will be automatically advanced. If there is a choice, and 'random_choice'
|
||||
//is true, then a unit will be selected at random. Otherwise, a dialog will be displayed
|
||||
|
|
142
src/display.cpp
142
src/display.cpp
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file display.cpp
|
||||
//! @file display.cpp
|
||||
//! Routines to set up the display, scroll and zoom the map.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -65,7 +65,7 @@ namespace {
|
|||
|
||||
}
|
||||
|
||||
display::display(CVideo& video, const gamemap& map, const config& theme_cfg, const config& cfg, const config& level) :
|
||||
display::display(CVideo& video, const gamemap& map, const config& theme_cfg, const config& cfg, const config& level) :
|
||||
screen_(video), map_(map), viewpoint_(NULL), xpos_(0), ypos_(0),
|
||||
theme_(theme_cfg,screen_area()),
|
||||
zoom_(DefaultZoom), last_zoom_(SmallZoom),
|
||||
|
@ -73,7 +73,7 @@ display::display(CVideo& video, const gamemap& map, const config& theme_cfg, con
|
|||
minimap_(NULL), redrawMinimap_(false), redraw_background_(true),
|
||||
invalidateAll_(true), grid_(false),
|
||||
diagnostic_label_(0), panelsDrawn_(false),
|
||||
turbo_speed_(2), turbo_(false),
|
||||
turbo_speed_(2), turbo_(false),
|
||||
invalidateGameStatus_(true),
|
||||
map_labels_(*this,map, 0),
|
||||
_scroll_event("scrolled"),
|
||||
|
@ -92,19 +92,19 @@ display::~display()
|
|||
{
|
||||
}
|
||||
|
||||
const SDL_Rect& display::map_area() const
|
||||
const SDL_Rect& display::map_area() const
|
||||
{
|
||||
static SDL_Rect res = {0, 0, 0, 0};
|
||||
res = map_outside_area();
|
||||
|
||||
// hex_size() is always a multiple of 4
|
||||
// hex_size() is always a multiple of 4
|
||||
// and hex_width() a multiple of 3,
|
||||
// so there shouldn't be off-by-one-errors
|
||||
// so there shouldn't be off-by-one-errors
|
||||
// due to rounding.
|
||||
// To display a hex fully on screen,
|
||||
// To display a hex fully on screen,
|
||||
// a little bit extra space is needed.
|
||||
// Also added the border two times.
|
||||
const int width = static_cast<int>((map_.w() + 2 * theme_.border().size + 1.0/3.0) * hex_width());
|
||||
const int width = static_cast<int>((map_.w() + 2 * theme_.border().size + 1.0/3.0) * hex_width());
|
||||
const int height = static_cast<int>((map_.h() + 2 * theme_.border().size + 0.5) * hex_size());
|
||||
|
||||
if(width < res.w) {
|
||||
|
@ -131,8 +131,8 @@ bool display::outside_area(const SDL_Rect& area, const int x, const int y) const
|
|||
}
|
||||
|
||||
// This function use the screen as reference
|
||||
const gamemap::location display::hex_clicked_on(int xclick, int yclick,
|
||||
gamemap::location::DIRECTION* nearest_hex,
|
||||
const gamemap::location display::hex_clicked_on(int xclick, int yclick,
|
||||
gamemap::location::DIRECTION* nearest_hex,
|
||||
gamemap::location::DIRECTION* second_nearest_hex) const
|
||||
{
|
||||
const SDL_Rect& rect = map_area();
|
||||
|
@ -148,8 +148,8 @@ const gamemap::location display::hex_clicked_on(int xclick, int yclick,
|
|||
|
||||
|
||||
// This function use the rect of map_area as reference
|
||||
const gamemap::location display::pixel_position_to_hex(int x, int y,
|
||||
gamemap::location::DIRECTION* nearest_hex,
|
||||
const gamemap::location display::pixel_position_to_hex(int x, int y,
|
||||
gamemap::location::DIRECTION* nearest_hex,
|
||||
gamemap::location::DIRECTION* second_nearest_hex) const
|
||||
{
|
||||
// adjust for the border
|
||||
|
@ -267,12 +267,12 @@ const gamemap::location display::pixel_position_to_hex(int x, int y,
|
|||
|
||||
void display::get_rect_hex_bounds(SDL_Rect rect, gamemap::location &topleft, gamemap::location &bottomright) const
|
||||
{
|
||||
// Change the coordinates of the rect send
|
||||
// Change the coordinates of the rect send
|
||||
// to be relative to the map area, instead of the screen area.
|
||||
const SDL_Rect& map_rect = map_area();
|
||||
rect.x -= map_rect.x;
|
||||
rect.y -= map_rect.y;
|
||||
// Only move the left side.
|
||||
// Only move the left side.
|
||||
// The right side should remain
|
||||
// at the same coordinates, so fix that
|
||||
rect.w += map_rect.x;
|
||||
|
@ -308,13 +308,13 @@ void display::get_rect_hex_bounds(SDL_Rect rect, gamemap::location &topleft, gam
|
|||
}
|
||||
|
||||
int display::get_location_x(const gamemap::location& loc) const
|
||||
{
|
||||
return static_cast<int>(map_area().x + (loc.x + theme_.border().size) * hex_width() - xpos_);
|
||||
{
|
||||
return static_cast<int>(map_area().x + (loc.x + theme_.border().size) * hex_width() - xpos_);
|
||||
}
|
||||
|
||||
int display::get_location_y(const gamemap::location& loc) const
|
||||
{
|
||||
return static_cast<int>(map_area().y + (loc.y + theme_.border().size) * zoom_ - ypos_ + (is_odd(loc.x) ? zoom_/2 : 0));
|
||||
{
|
||||
return static_cast<int>(map_area().y + (loc.y + theme_.border().size) * zoom_ - ypos_ + (is_odd(loc.x) ? zoom_/2 : 0));
|
||||
}
|
||||
|
||||
gamemap::location display::minimap_location_on(int x, int y)
|
||||
|
@ -418,8 +418,8 @@ std::vector<std::string> display::get_fog_shroud_graphics(const gamemap::locatio
|
|||
gamemap::location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
t_translation::t_letter tiles[6];
|
||||
|
||||
static const t_translation::t_letter terrain_types[] =
|
||||
|
||||
static const t_translation::t_letter terrain_types[] =
|
||||
{ t_translation::FOGGED, t_translation::VOID_TERRAIN, t_translation::NONE_TERRAIN };
|
||||
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
|
@ -428,12 +428,12 @@ std::vector<std::string> display::get_fog_shroud_graphics(const gamemap::locatio
|
|||
} else if(!fogged(loc) && fogged(adjacent[i])) {
|
||||
tiles[i] = t_translation::FOGGED;
|
||||
} else {
|
||||
tiles[i] = t_translation::NONE_TERRAIN;
|
||||
tiles[i] = t_translation::NONE_TERRAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(const t_translation::t_letter *terrain = terrain_types;
|
||||
for(const t_translation::t_letter *terrain = terrain_types;
|
||||
*terrain != t_translation::NONE_TERRAIN; terrain ++) {
|
||||
|
||||
// Find somewhere that doesn't have overlap to use as a starting point
|
||||
|
@ -486,9 +486,9 @@ std::vector<std::string> display::get_fog_shroud_graphics(const gamemap::locatio
|
|||
return res;
|
||||
}
|
||||
|
||||
std::vector<surface> display::get_terrain_images(const gamemap::location &loc,
|
||||
std::vector<surface> display::get_terrain_images(const gamemap::location &loc,
|
||||
const std::string timeid,
|
||||
image::TYPE image_type,
|
||||
image::TYPE image_type,
|
||||
ADJACENT_TERRAIN_TYPE terrain_type)
|
||||
{
|
||||
std::vector<surface> res;
|
||||
|
@ -518,22 +518,22 @@ std::vector<surface> display::get_terrain_images(const gamemap::location &loc,
|
|||
timeid, builder_terrain_type);
|
||||
|
||||
if(terrains != NULL) {
|
||||
// Cache the offmap name.
|
||||
// Cache the offmap name.
|
||||
// Since it is themabel it can change,
|
||||
// so don't make it static.
|
||||
const std::string off_map_name = "terrain/" + theme_.border().tile_image + ".png";
|
||||
for(std::vector<animated<image::locator> >::const_iterator it =
|
||||
for(std::vector<animated<image::locator> >::const_iterator it =
|
||||
terrains->begin(); it != terrains->end(); ++it) {
|
||||
|
||||
image::locator image = it->get_current_frame();
|
||||
|
||||
// We prevent ToD colouring and brightening of off-map tiles,
|
||||
// except if we are not in_game and so in the editor.
|
||||
// We need to test for the tile to be rendered and
|
||||
// not the location, since the transitions are rendered
|
||||
// We need to test for the tile to be rendered and
|
||||
// not the location, since the transitions are rendered
|
||||
// over the offmap-terrain and these need a ToD colouring.
|
||||
const bool off_map = (image.get_filename() == off_map_name);
|
||||
const surface surface(image::get_image(image,
|
||||
const surface surface(image::get_image(image,
|
||||
off_map ? image::UNMASKED : image_type));
|
||||
|
||||
if (!surface.null()) {
|
||||
|
@ -545,7 +545,7 @@ std::vector<surface> display::get_terrain_images(const gamemap::location &loc,
|
|||
return res;
|
||||
}
|
||||
|
||||
void display::tile_stack_append(const surface surf)
|
||||
void display::tile_stack_append(const surface surf)
|
||||
{
|
||||
if (surf)
|
||||
tile_stack_.push_back(surf);
|
||||
|
@ -566,8 +566,8 @@ void display::tile_stack_render(int x, int y)
|
|||
|
||||
std::vector<surface>::const_iterator itor;
|
||||
for(itor=tile_stack_.begin(); itor!=tile_stack_.end(); ++itor) {
|
||||
// Note that dstrect can be changed by SDL_BlitSurface
|
||||
// and so a new instance should be initialized
|
||||
// Note that dstrect can be changed by SDL_BlitSurface
|
||||
// and so a new instance should be initialized
|
||||
// to pass to each call to SDL_BlitSurface.
|
||||
SDL_Rect dstrect = { x, y, 0, 0 };
|
||||
SDL_BlitSurface(*itor, NULL, dst, &dstrect);
|
||||
|
@ -674,13 +674,13 @@ static void draw_panel(CVideo& video, const theme::panel& panel, std::vector<gui
|
|||
if(rects_overlap(b->location(),loc)) {
|
||||
b->set_dirty(true);
|
||||
if (first_time){
|
||||
//! @todo FixMe YogiHH:
|
||||
// This is only made to have the buttons store
|
||||
// their background information, otherwise
|
||||
// the background will appear completely black.
|
||||
//! @todo FixMe YogiHH:
|
||||
// This is only made to have the buttons store
|
||||
// their background information, otherwise
|
||||
// the background will appear completely black.
|
||||
// It would more straightforward to call bg_update,
|
||||
// but that is not public and there seems to be
|
||||
// no other way atm to call it.
|
||||
// but that is not public and there seems to be
|
||||
// no other way atm to call it.
|
||||
// I will check if bg_update can be made public.
|
||||
b->hide(true);
|
||||
b->hide(false);
|
||||
|
@ -777,7 +777,7 @@ void display::draw_text_in_hex(const gamemap::location& loc, const std::string&
|
|||
|
||||
const size_t font_sz = static_cast<size_t>(font_size * get_zoom_factor()
|
||||
#ifdef USE_TINY_GUI
|
||||
/ 2 // the hex is only half size
|
||||
/ 2 // the hex is only half size
|
||||
#endif
|
||||
);
|
||||
|
||||
|
@ -902,7 +902,7 @@ void display::set_diagnostic(const std::string& msg)
|
|||
}
|
||||
}
|
||||
|
||||
//! Initiate a redraw.
|
||||
//! Initiate a redraw.
|
||||
//! May require redrawing panels and background.
|
||||
bool display::draw_init()
|
||||
{
|
||||
|
@ -970,21 +970,21 @@ void display::draw_wrap(bool update,bool force,bool changed)
|
|||
}
|
||||
update_display();
|
||||
}
|
||||
|
||||
|
||||
// Set the theortical next draw time
|
||||
nextDraw_ += time_between_draws;
|
||||
|
||||
|
||||
|
||||
// If the next draw already should have been finished,
|
||||
// we'll enter an update frenzy, so make sure that the
|
||||
// too late value doesn't keep growing.
|
||||
// Note: if force is used too often,
|
||||
// too late value doesn't keep growing.
|
||||
// Note: if force is used too often,
|
||||
// we can also get the opposite effect.
|
||||
nextDraw_ = maximum<int>(nextDraw_, SDL_GetTicks());
|
||||
}
|
||||
}
|
||||
|
||||
//! Delay routines: use these instead of SDL_Delay (for --nogui).
|
||||
//! Delay routines: use these instead of SDL_Delay (for --nogui).
|
||||
void display::delay(unsigned int milliseconds) const
|
||||
{
|
||||
if (!game_config::no_delay)
|
||||
|
@ -1021,9 +1021,9 @@ void display::enable_menu(const std::string& item, bool enable)
|
|||
}
|
||||
}
|
||||
|
||||
void display::add_highlighted_loc(const gamemap::location &hex)
|
||||
void display::add_highlighted_loc(const gamemap::location &hex)
|
||||
{
|
||||
// Only invalidate and insert if this is a new addition,
|
||||
// Only invalidate and insert if this is a new addition,
|
||||
// for efficiency.
|
||||
if (highlighted_locations_.find(hex) == highlighted_locations_.end()) {
|
||||
highlighted_locations_.insert(hex);
|
||||
|
@ -1031,7 +1031,7 @@ void display::add_highlighted_loc(const gamemap::location &hex)
|
|||
}
|
||||
}
|
||||
|
||||
void display::clear_highlighted_locs()
|
||||
void display::clear_highlighted_locs()
|
||||
{
|
||||
for (std::set<gamemap::location>::const_iterator it = highlighted_locations_.begin();
|
||||
it != highlighted_locations_.end(); it++) {
|
||||
|
@ -1040,7 +1040,7 @@ void display::clear_highlighted_locs()
|
|||
highlighted_locations_.clear();
|
||||
}
|
||||
|
||||
void display::remove_highlighted_loc(const gamemap::location &hex)
|
||||
void display::remove_highlighted_loc(const gamemap::location &hex)
|
||||
{
|
||||
std::set<gamemap::location>::iterator it = highlighted_locations_.find(hex);
|
||||
// Only invalidate and remove if the hex was found, for efficiency.
|
||||
|
@ -1078,8 +1078,8 @@ surface display::get_minimap(int w, int h)
|
|||
void display::draw_border(const gamemap::location& loc, const int xpos, const int ypos)
|
||||
{
|
||||
/**
|
||||
* at the moment the border must be between 0.0 and 0.5
|
||||
* and the image should always be prepared for a 0.5 border.
|
||||
* at the moment the border must be between 0.0 and 0.5
|
||||
* and the image should always be prepared for a 0.5 border.
|
||||
* This way this code doesn't need modifications for other border sizes.
|
||||
*/
|
||||
|
||||
|
@ -1095,7 +1095,7 @@ void display::draw_border(const gamemap::location& loc, const int xpos, const in
|
|||
if(loc.x%2 == 0) {
|
||||
rect.y = ypos + zoom_/2;
|
||||
rect.h = zoom_/2;
|
||||
// We use the map idea of odd and even,
|
||||
// We use the map idea of odd and even,
|
||||
// and map coords are internal coords + 1
|
||||
border = image::get_image(theme_.border().corner_image_top_right_odd, image::SCALED_TO_ZOOM);
|
||||
} else {
|
||||
|
@ -1111,7 +1111,7 @@ void display::draw_border(const gamemap::location& loc, const int xpos, const in
|
|||
const surface border(image::get_image(theme_.border().corner_image_bottom_left, image::SCALED_TO_ZOOM));
|
||||
|
||||
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
|
||||
|
||||
|
||||
} else if(loc.x == map_.w() && loc.y == map_.h()) { // bottom right corner
|
||||
SDL_Rect rect = { xpos, ypos, 3 * zoom_/4, zoom_/2 } ;
|
||||
surface border;
|
||||
|
@ -1195,7 +1195,7 @@ void display::draw_minimap(int x, int y, int w, int h)
|
|||
|
||||
// The magic numbers experimentally determined, like in display::map_area()
|
||||
const int wbox = static_cast<int>(xscaling*(map_area().w+(4.0/3.0)*tile_width)/tile_width - xscaling);
|
||||
const int hbox = static_cast<int>(yscaling*(map_area().h+1.5*zoom_)/zoom_ - yscaling);
|
||||
const int hbox = static_cast<int>(yscaling*(map_area().h+1.5*zoom_)/zoom_ - yscaling);
|
||||
|
||||
const Uint32 boxcolour = SDL_MapRGB(surf->format,0xFF,0xFF,0xFF);
|
||||
const surface screen(screen_.getSurface());
|
||||
|
@ -1221,9 +1221,9 @@ void display::scroll(int xmove, int ymove)
|
|||
|
||||
map_labels_.scroll(dx, dy);
|
||||
font::scroll_floating_labels(dx, dy);
|
||||
|
||||
|
||||
surface screen(screen_.getSurface());
|
||||
|
||||
|
||||
SDL_Rect dstrect = map_area();
|
||||
dstrect.x += dx;
|
||||
dstrect.y += dy;
|
||||
|
@ -1232,9 +1232,9 @@ void display::scroll(int xmove, int ymove)
|
|||
SDL_Rect srcrect = dstrect;
|
||||
srcrect.x -= dx;
|
||||
srcrect.y -= dy;
|
||||
|
||||
|
||||
SDL_BlitSurface(screen,&srcrect,screen,&dstrect);
|
||||
|
||||
|
||||
// Invalidate locations in the newly visible rects
|
||||
|
||||
if (dy != 0) {
|
||||
|
@ -1280,7 +1280,7 @@ void display::set_zoom(int amount)
|
|||
redraw_background_ = true;
|
||||
invalidate_all();
|
||||
|
||||
// Forces a redraw after zooming.
|
||||
// Forces a redraw after zooming.
|
||||
// This prevents some graphic glitches from occurring.
|
||||
draw();
|
||||
}
|
||||
|
@ -1349,11 +1349,11 @@ void display::scroll_to_tile(const gamemap::location& loc, SCROLL_TYPE scroll_ty
|
|||
double dist_moved = 0.0;
|
||||
|
||||
int t_prev = SDL_GetTicks();
|
||||
|
||||
|
||||
double velocity = 0.0;
|
||||
while (dist_moved < dist_total) {
|
||||
events::pump();
|
||||
|
||||
|
||||
int t = SDL_GetTicks();
|
||||
double dt = (t - t_prev) / 1000.0;
|
||||
if (dt > 0.200) {
|
||||
|
@ -1365,7 +1365,7 @@ void display::scroll_to_tile(const gamemap::location& loc, SCROLL_TYPE scroll_ty
|
|||
//std::cout << t << " " << hypot(x_old, y_old) << "\n";
|
||||
|
||||
//! @todo Those values might need some fine-tuning:
|
||||
const double accel_time = 0.3 / turbo_speed(); // seconds until full speed is reached
|
||||
const double accel_time = 0.3 / turbo_speed(); // seconds until full speed is reached
|
||||
const double decel_time = 0.4 / turbo_speed(); // seconds from full speed to stop
|
||||
|
||||
double velocity_max = preferences::scroll_speed() * 60.0;
|
||||
|
@ -1415,14 +1415,14 @@ void display::scroll_to_tiles(const gamemap::location& loc1, const gamemap::loca
|
|||
const int diffx = maxx - minx;
|
||||
const int diffy = maxy - miny;
|
||||
|
||||
// If rectangle formed by corners loc1 and loc2
|
||||
// If rectangle formed by corners loc1 and loc2
|
||||
// is larger than map area, then just scroll to loc1.
|
||||
if(diffx > map_area().w || diffy > map_area().h) {
|
||||
scroll_to_tile(loc1,scroll_type,check_fogged);
|
||||
} else {
|
||||
// Only scroll if rectangle is not completely inside map area.
|
||||
// Assume most paths are within rectangle.
|
||||
// Sometimes with rugged terrain this is not true -- but use
|
||||
// Assume most paths are within rectangle.
|
||||
// Sometimes with rugged terrain this is not true -- but use
|
||||
// common cases to determine behaviour instead of exceptions.
|
||||
if (outside_area(map_area(),minx,miny) ||
|
||||
outside_area(map_area(),maxx,maxy)) {
|
||||
|
@ -1455,7 +1455,7 @@ void display::bounds_check_position(int& xpos, int& ypos)
|
|||
{
|
||||
const int tile_width = hex_width();
|
||||
|
||||
// Adjust for the border 2 times
|
||||
// Adjust for the border 2 times
|
||||
const int xend = static_cast<int>(tile_width * (map_.w() + 2 * theme_.border().size) + tile_width/3);
|
||||
const int yend = static_cast<int>(zoom_ * (map_.h() + 2 * theme_.border().size) + zoom_/2);
|
||||
|
||||
|
@ -1604,9 +1604,9 @@ void display::refresh_report(reports::TYPE report_num, reports::report report,
|
|||
surf.assign(NULL);
|
||||
rect = new_rect;
|
||||
|
||||
// If the rectangle is present, and we are blitting text,
|
||||
// then we need to backup the surface.
|
||||
// (Images generally won't need backing up,
|
||||
// If the rectangle is present, and we are blitting text,
|
||||
// then we need to backup the surface.
|
||||
// (Images generally won't need backing up,
|
||||
// unless they are transperant, but that is done later).
|
||||
if(rect.w > 0 && rect.h > 0) {
|
||||
surf.assign(get_surface_portion(screen_.getSurface(),rect));
|
||||
|
@ -1625,8 +1625,8 @@ void display::refresh_report(reports::TYPE report_num, reports::report report,
|
|||
int x = rect.x, y = rect.y;
|
||||
|
||||
if(!report.empty()) {
|
||||
// Add prefix, postfix elements.
|
||||
// Make sure that they get the same tooltip
|
||||
// Add prefix, postfix elements.
|
||||
// Make sure that they get the same tooltip
|
||||
// as the guys around them.
|
||||
std::stringstream temp;
|
||||
Uint32 RGB = item->font_rgb();
|
||||
|
|
120
src/display.hpp
120
src/display.hpp
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file display.hpp
|
||||
//! @file display.hpp
|
||||
//!
|
||||
|
||||
#ifndef DISPLAY_H_INCLUDED
|
||||
|
@ -42,18 +42,18 @@ class unit_map;
|
|||
#include <set>
|
||||
#include <string>
|
||||
|
||||
// map_display and display: classes which take care of
|
||||
// map_display and display: classes which take care of
|
||||
// displaying the map and game-data on the screen.
|
||||
//
|
||||
// The display is divided into two main sections:
|
||||
//
|
||||
// The display is divided into two main sections:
|
||||
// - the game area, which displays the tiles of the game board, and units on them,
|
||||
// - and the side bar, which appears on the right hand side.
|
||||
// - and the side bar, which appears on the right hand side.
|
||||
// The side bar display is divided into three sections:
|
||||
// - the minimap, which is displayed at the top right
|
||||
// - the game status, which includes the day/night image,
|
||||
// the turn number, information about the current side,
|
||||
// - the game status, which includes the day/night image,
|
||||
// the turn number, information about the current side,
|
||||
// and information about the hex currently moused over (highlighted)
|
||||
// - the unit status, which displays an image and stats
|
||||
// - the unit status, which displays an image and stats
|
||||
// for the current unit.
|
||||
|
||||
class display
|
||||
|
@ -71,14 +71,14 @@ public:
|
|||
|
||||
virtual bool in_game() const { return false; }
|
||||
|
||||
// the dimensions of the display. x and y are width/height.
|
||||
// mapx is the width of the portion of the display which shows the game area.
|
||||
// the dimensions of the display. x and y are width/height.
|
||||
// mapx is the width of the portion of the display which shows the game area.
|
||||
// Between mapx and x is the sidebar region.
|
||||
int w() const { return screen_.getx(); } //!< width
|
||||
int h() const { return screen_.gety(); } //!< height
|
||||
const SDL_Rect& minimap_area() const
|
||||
const SDL_Rect& minimap_area() const
|
||||
{ return theme_.mini_map_location(screen_area()); }
|
||||
const SDL_Rect& unit_image_area() const
|
||||
const SDL_Rect& unit_image_area() const
|
||||
{ return theme_.unit_image_location(screen_area()); }
|
||||
|
||||
SDL_Rect screen_area() const
|
||||
|
@ -90,8 +90,8 @@ public:
|
|||
const SDL_Rect& map_area() const;
|
||||
|
||||
/**
|
||||
* Returns the available area for a map, this may differ
|
||||
* from the above. This area will get the background area
|
||||
* Returns the available area for a map, this may differ
|
||||
* from the above. This area will get the background area
|
||||
* applied to it.
|
||||
*/
|
||||
const SDL_Rect& map_outside_area() const
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
|
||||
//! Function which returns the width of a hex in pixels,
|
||||
//! up to where the next hex starts.
|
||||
//! (i.e. not entirely from tip to tip -- use hex_size()
|
||||
//! (i.e. not entirely from tip to tip -- use hex_size()
|
||||
//! to get the distance from tip to tip)
|
||||
int hex_width() const { return (zoom_*3)/4; }
|
||||
|
||||
|
@ -114,17 +114,17 @@ public:
|
|||
double get_zoom_factor() { return double(zoom_)/double(image::tile_size); }
|
||||
|
||||
// given x,y co-ordinates of an onscreen pixel, will return the
|
||||
// location of the hex that this pixel corresponds to.
|
||||
// location of the hex that this pixel corresponds to.
|
||||
// Returns an invalid location if the mouse isn't over any valid location.
|
||||
const gamemap::location hex_clicked_on(int x, int y,
|
||||
gamemap::location::DIRECTION* nearest_hex=NULL,
|
||||
const gamemap::location hex_clicked_on(int x, int y,
|
||||
gamemap::location::DIRECTION* nearest_hex=NULL,
|
||||
gamemap::location::DIRECTION* second_nearest_hex=NULL) const;
|
||||
|
||||
// given x,y co-ordinates of a pixel on the map, will return the
|
||||
// location of the hex that this pixel corresponds to.
|
||||
// location of the hex that this pixel corresponds to.
|
||||
// Returns an invalid location if the mouse isn't over any valid location.
|
||||
const gamemap::location pixel_position_to_hex(int x, int y,
|
||||
gamemap::location::DIRECTION* nearest_hex=NULL,
|
||||
const gamemap::location pixel_position_to_hex(int x, int y,
|
||||
gamemap::location::DIRECTION* nearest_hex=NULL,
|
||||
gamemap::location::DIRECTION* second_nearest_hex=NULL) const;
|
||||
|
||||
// given x,y co-ordinates of the mouse, will return the location of the
|
||||
|
@ -158,7 +158,7 @@ public:
|
|||
//! (to more clearly show where hexes are)
|
||||
void set_grid(const bool grid) { grid_ = grid; }
|
||||
|
||||
//! Returns the locations of 2 hexes
|
||||
//! Returns the locations of 2 hexes
|
||||
//! that bind the visible area of the map.
|
||||
void get_visible_hex_bounds(gamemap::location &topleft, gamemap::location &bottomright) const;
|
||||
|
||||
|
@ -174,7 +174,7 @@ public:
|
|||
void create_buttons();
|
||||
void invalidate_theme() { panelsDrawn_ = false; }
|
||||
|
||||
void refresh_report(reports::TYPE report_num, reports::report report,
|
||||
void refresh_report(reports::TYPE report_num, reports::report report,
|
||||
bool brightened = false);
|
||||
|
||||
// Will be overridden in the display subclass
|
||||
|
@ -187,25 +187,25 @@ public:
|
|||
|
||||
// The last action in drawing a tile is adding the overlays.
|
||||
// These overlays are drawn in the following order:
|
||||
// hex_overlay_ if the drawn location is in the map
|
||||
// hex_overlay_ if the drawn location is in the map
|
||||
// selected_hex_overlay_ if the drawn location is selected
|
||||
// mouseover_hex_overlay_ if the drawn location is underneath the mouse
|
||||
//
|
||||
// These functions require a prerendered surface.
|
||||
// These functions require a prerendered surface.
|
||||
// Since they are drawn at the top, they are not influenced by TOD, shroud etc.
|
||||
void set_hex_overlay(const gamemap::location& loc, surface image) { hex_overlay_[loc] = image; }
|
||||
void clear_hex_overlay(const gamemap::location& loc);
|
||||
|
||||
|
||||
void set_selected_hex_overlay(const surface& image) { selected_hex_overlay_ = image; }
|
||||
void clear_selected_hex_overlay() { selected_hex_overlay_ = NULL; }
|
||||
|
||||
void set_mouseover_hex_overlay(const surface& image) { mouseover_hex_overlay_ = image; }
|
||||
void clear_mouseover_hex_overlay() { mouseover_hex_overlay_ = NULL; }
|
||||
|
||||
//! Debug function to toggle the "sunset" mode.
|
||||
//! The map area become progressively darker,
|
||||
|
||||
//! Debug function to toggle the "sunset" mode.
|
||||
//! The map area become progressively darker,
|
||||
//! except where hexes are refreshed.
|
||||
//! delay is the number of frames between each darkening
|
||||
//! delay is the number of frames between each darkening
|
||||
//! (0 to toggle).
|
||||
void sunset(const size_t delay = 0);
|
||||
|
||||
|
@ -217,7 +217,7 @@ public:
|
|||
//! and divided by 2 for tiny-gui.
|
||||
void draw_text_in_hex(const gamemap::location& loc, const std::string& text,
|
||||
size_t font_size, SDL_Color color, double x_in_hex=0.5, double y_in_hex=0.5);
|
||||
|
||||
|
||||
void flip();
|
||||
|
||||
//! Copy the backbuffer to the framebuffer.
|
||||
|
@ -233,7 +233,7 @@ public:
|
|||
//! greyscale: used when the unit is stoned
|
||||
//! alpha: the merging to use with the background
|
||||
//! blendto: blend to this colour using blend_ratio
|
||||
//! submerged: the amount of the unit out of 1.0 that is submerged
|
||||
//! submerged: the amount of the unit out of 1.0 that is submerged
|
||||
//! (presumably under water) and thus shouldn't be drawn
|
||||
void render_unit_image(int x, int y, surface image,
|
||||
bool reverse=false, bool greyscale=false,
|
||||
|
@ -242,7 +242,7 @@ public:
|
|||
|
||||
const theme::menu* menu_pressed();
|
||||
|
||||
//! Finds the menu which has a given item in it,
|
||||
//! Finds the menu which has a given item in it,
|
||||
//! and enables or disables it.
|
||||
void enable_menu(const std::string& item, bool enable);
|
||||
|
||||
|
@ -251,7 +251,7 @@ public:
|
|||
// Delay routines: use these not SDL_Delay (for --nogui).
|
||||
void delay(unsigned int milliseconds) const;
|
||||
|
||||
//! Set/Get whether 'turbo' mode is on.
|
||||
//! Set/Get whether 'turbo' mode is on.
|
||||
//! When turbo mode is on, everything moves much faster.
|
||||
void set_turbo(const bool turbo) { turbo_ = turbo; }
|
||||
|
||||
|
@ -259,9 +259,9 @@ public:
|
|||
|
||||
void set_turbo_speed(const double speed) { turbo_speed_ = speed; }
|
||||
|
||||
//! Add a location to highlight.
|
||||
//! Note that this has nothing to do with selecting hexes,
|
||||
//! it is pure highlighting. These hexes will be highlighted
|
||||
//! Add a location to highlight.
|
||||
//! Note that this has nothing to do with selecting hexes,
|
||||
//! it is pure highlighting. These hexes will be highlighted
|
||||
//! slightly darker than the currently selected hex.
|
||||
void add_highlighted_loc(const gamemap::location &hex);
|
||||
|
||||
|
@ -275,14 +275,14 @@ public:
|
|||
//! Function to invalidate all tiles.
|
||||
void invalidate_all();
|
||||
|
||||
//! Scrolls the display by xmov,ymov pixels.
|
||||
//! Scrolls the display by xmov,ymov pixels.
|
||||
//! Invalidation and redrawing will be scheduled.
|
||||
void scroll(int xmov, int ymov);
|
||||
|
||||
//! Zooms the display by the specified amount.
|
||||
//! Negative values zoom out.
|
||||
//! Zooms the display by the specified amount.
|
||||
//! Negative values zoom out.
|
||||
//! Note the amount should be a multiple of four,
|
||||
//! otherwise the images might start to look odd
|
||||
//! otherwise the images might start to look odd
|
||||
//! (hex_width() gets rounding errors).
|
||||
void set_zoom(int amount);
|
||||
|
||||
|
@ -305,8 +305,8 @@ public:
|
|||
//! Expose the event, so observers can be notified about map scrolling.
|
||||
events::generic_event &scroll_event() const { return _scroll_event; }
|
||||
|
||||
//! Draws invalidated items.
|
||||
//! If update is true, will also copy the display to the frame buffer.
|
||||
//! Draws invalidated items.
|
||||
//! If update is true, will also copy the display to the frame buffer.
|
||||
//! If force is true, will not skip frames, even if running behind.
|
||||
virtual void draw(bool update=true,bool force=false) = 0;
|
||||
|
||||
|
@ -314,20 +314,20 @@ public:
|
|||
const map_labels& labels() const { return map_labels_; }
|
||||
|
||||
//! Announce a message prominently.
|
||||
void announce(const std::string msg,
|
||||
void announce(const std::string msg,
|
||||
const SDL_Color& colour = font::GOOD_COLOUR);
|
||||
|
||||
//! Schedule the minimap for recalculation.
|
||||
//! Schedule the minimap for recalculation.
|
||||
//! Useful if any terrain in the map has changed.
|
||||
void recalculate_minimap();
|
||||
|
||||
//! Schedule the minimap to be redrawn.
|
||||
//! Schedule the minimap to be redrawn.
|
||||
//! Useful if units have moved about on the map.
|
||||
void redraw_minimap() { redrawMinimap_ = true; }
|
||||
|
||||
//! Set what will be shown for the report with type which_report.
|
||||
//! Note that this only works for some reports,
|
||||
//! i.e. reports that can not be deducted
|
||||
//! i.e. reports that can not be deducted
|
||||
//! from the supplied arguments to generate_report,
|
||||
//! currently: SELECTED_TERRAIN, EDIT_LEFT_BUTTON_FUNCTION
|
||||
void set_report_content(const reports::TYPE which_report, const std::string &content);
|
||||
|
@ -336,8 +336,8 @@ public:
|
|||
protected:
|
||||
|
||||
/**
|
||||
* Draws the border tile overlay.
|
||||
* The routine determines by itself which border it is on
|
||||
* Draws the border tile overlay.
|
||||
* The routine determines by itself which border it is on
|
||||
* and draws an overlay accordingly. The definition of the
|
||||
* border is stored in the 'main_map_border' part of the theme.
|
||||
*
|
||||
|
@ -345,7 +345,7 @@ protected:
|
|||
* @param xpos the on-screen pixels x coordinate of the tile
|
||||
* @param ypos the on-screen pixels y coordinate of the tile
|
||||
*/
|
||||
virtual void draw_border(const gamemap::location& loc,
|
||||
virtual void draw_border(const gamemap::location& loc,
|
||||
const int xpos, const int ypos);
|
||||
|
||||
void draw_minimap(int x, int y, int w, int h);
|
||||
|
@ -354,9 +354,9 @@ protected:
|
|||
|
||||
enum ADJACENT_TERRAIN_TYPE { ADJACENT_BACKGROUND, ADJACENT_FOREGROUND, ADJACENT_FOGSHROUD };
|
||||
|
||||
std::vector<surface> get_terrain_images(const gamemap::location &loc,
|
||||
std::vector<surface> get_terrain_images(const gamemap::location &loc,
|
||||
const std::string timeid,
|
||||
image::TYPE type,
|
||||
image::TYPE type,
|
||||
ADJACENT_TERRAIN_TYPE terrain_type);
|
||||
|
||||
std::vector<std::string> get_fog_shroud_graphics(const gamemap::location& loc);
|
||||
|
@ -388,7 +388,7 @@ protected:
|
|||
//! Drawing shouldn't occur before this time.
|
||||
int nextDraw_;
|
||||
|
||||
// Not set by the initializer:
|
||||
// Not set by the initializer:
|
||||
SDL_Rect reportRects_[reports::NUM_REPORTS];
|
||||
surface reportSurfaces_[reports::NUM_REPORTS];
|
||||
reports::report reports_[reports::NUM_REPORTS];
|
||||
|
@ -414,8 +414,8 @@ protected:
|
|||
|
||||
void invalidate_locations_in_rect(SDL_Rect r);
|
||||
|
||||
//! Strict weak ordering to sort a STL-set of hexes
|
||||
//! for drawing using the z-order.
|
||||
//! Strict weak ordering to sort a STL-set of hexes
|
||||
//! for drawing using the z-order.
|
||||
//! (1000 are just to weight the y compare to x)
|
||||
struct ordered_draw : public std::binary_function<gamemap::location, gamemap::location, bool> {
|
||||
bool operator()(gamemap::location a, gamemap::location b) {
|
||||
|
@ -423,15 +423,15 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
//! Invalidate controls and panels when changed
|
||||
//! after they have been drawn initially.
|
||||
//! Invalidate controls and panels when changed
|
||||
//! after they have been drawn initially.
|
||||
//! Useful for dynamic theme modification.
|
||||
bool draw_init();
|
||||
void draw_wrap(bool update,bool force,bool changed);
|
||||
|
||||
private:
|
||||
//! Tile stack for terrain rendering.
|
||||
std::vector<surface> tile_stack_;
|
||||
std::vector<surface> tile_stack_;
|
||||
//! Handle for the label which displays frames per second.
|
||||
int fps_handle_;
|
||||
};
|
||||
|
@ -444,12 +444,12 @@ public:
|
|||
editor_display(CVideo& video, const gamemap& map, const config& theme_cfg,
|
||||
const config& cfg, const config& level);
|
||||
|
||||
//! draw() for the editor display.
|
||||
//! draw() for the editor display.
|
||||
//! It only has to know about terrain.
|
||||
void draw(bool update=true,bool force=false);
|
||||
|
||||
//! Rebuild the dynamic terrain at the given location.
|
||||
void rebuild_terrain(const gamemap::location &loc)
|
||||
void rebuild_terrain(const gamemap::location &loc)
|
||||
{ builder_.rebuild_terrain(loc); }
|
||||
};
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace {
|
|||
const std::string prefs_filename = get_dir(get_user_data_dir() + "/editor")
|
||||
+ "/preferences";
|
||||
|
||||
// Return the side that has it's starting position at hex,
|
||||
// Return the side that has it's starting position at hex,
|
||||
// or -1 if none has.
|
||||
int starting_side_at(const gamemap& map, const gamemap::location hex) {
|
||||
int start_side = -1;
|
||||
|
@ -98,9 +98,9 @@ bool check_data(std::string &data, std::string &filename, bool &from_scenario, c
|
|||
newfilename.erase(newfilename.begin());
|
||||
newfilename.erase(newfilename.end() - 1);
|
||||
|
||||
// If the filename begins with a '~', then look in the user's data directory.
|
||||
// If the filename begins with a '@' then we look in the user's data directory,
|
||||
// but default to the standard data directory if it's not found there.
|
||||
// If the filename begins with a '~', then look in the user's data directory.
|
||||
// If the filename begins with a '@' then we look in the user's data directory,
|
||||
// but default to the standard data directory if it's not found there.
|
||||
if(newfilename != "" && (newfilename[0] == '~' || newfilename[0] == '@')) {
|
||||
nfname = newfilename;
|
||||
nfname.erase(nfname.begin(),nfname.begin()+1);
|
||||
|
@ -114,8 +114,8 @@ bool check_data(std::string &data, std::string &filename, bool &from_scenario, c
|
|||
} else
|
||||
if(newfilename.size() >= 2 && newfilename[0] == '.' &&
|
||||
newfilename[1] == '/' ) {
|
||||
// If the filename begins with a "./",
|
||||
// then look in the same directory
|
||||
// If the filename begins with a "./",
|
||||
// then look in the same directory
|
||||
// as the file currrently being preprocessed
|
||||
nfname = newfilename;
|
||||
nfname.erase(nfname.begin(),nfname.begin()+2);
|
||||
|
@ -139,14 +139,14 @@ bool check_data(std::string &data, std::string &filename, bool &from_scenario, c
|
|||
// the whole map takes place. It may not be the most beautiful solution,
|
||||
// but it is the way the least interference with the game system is
|
||||
// needed. That is the reason we need some static variables to handle
|
||||
// things that should be permanent through the program's life time.
|
||||
// things that should be permanent through the program's life time.
|
||||
// Of course, the functionality of this assumes that no more than one
|
||||
// map_editor object will exist, but that is a reasonable restriction imho.
|
||||
bool map_editor::first_time_created_ = true;
|
||||
int map_editor::num_operations_since_save_ = 0;
|
||||
config map_editor::prefs_;
|
||||
config map_editor::hotkeys_;
|
||||
// Do not init the l_button_func_ to DRAW, since it should be changed
|
||||
// Do not init the l_button_func_ to DRAW, since it should be changed
|
||||
// in the constructor to update the report the first time.
|
||||
map_editor::LEFT_BUTTON_FUNC map_editor::l_button_func_ = PASTE;
|
||||
t_translation::t_letter map_editor::old_fg_terrain_;
|
||||
|
@ -185,7 +185,7 @@ map_editor::map_editor(editor_display &gui, editormap &map, config &theme, confi
|
|||
//! @todo FIXME: saved hotkeys don't reload correctly,
|
||||
//! so we just reread the theme hotkeys every time
|
||||
hotkey::load_hotkeys(theme_);
|
||||
|
||||
|
||||
palette_.select_fg_terrain(old_fg_terrain_);
|
||||
palette_.select_bg_terrain(old_bg_terrain_);
|
||||
brush_.select_brush_size(old_brush_size_);
|
||||
|
@ -205,10 +205,10 @@ map_editor::map_editor(editor_display &gui, editormap &map, config &theme, confi
|
|||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
* This should be replaced by a WML tag called 'tooltip='
|
||||
* in the data/themes/editor.cfg file.
|
||||
* The theme and display classes should then load
|
||||
* @todo
|
||||
* This should be replaced by a WML tag called 'tooltip='
|
||||
* in the data/themes/editor.cfg file.
|
||||
* The theme and display classes should then load
|
||||
* the given tooltip in the button.
|
||||
*/
|
||||
void map_editor::load_tooltips()
|
||||
|
@ -261,8 +261,8 @@ void map_editor::load_tooltips()
|
|||
if(text != "")
|
||||
tooltips::add_tooltip(tooltip_rect, text);
|
||||
}
|
||||
|
||||
// Tooltips for the groups
|
||||
|
||||
// Tooltips for the groups
|
||||
palette_.load_tooltips();
|
||||
}
|
||||
|
||||
|
@ -302,8 +302,8 @@ void map_editor::handle_keyboard_event(const SDL_KeyboardEvent &event,
|
|||
const int /*mousex*/, const int /*mousey*/) {
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
const SDLKey sym = event.keysym.sym;
|
||||
// We must intercept escape-presses here,
|
||||
// because we don't want the default shutdown behavior,
|
||||
// We must intercept escape-presses here,
|
||||
// because we don't want the default shutdown behavior,
|
||||
// we want to ask for saving.
|
||||
if (sym == SDLK_ESCAPE) {
|
||||
set_abort();
|
||||
|
@ -312,9 +312,9 @@ void map_editor::handle_keyboard_event(const SDL_KeyboardEvent &event,
|
|||
const bool old_fullscreen = preferences::fullscreen();
|
||||
const std::pair<int, int> old_resolution = preferences::resolution();
|
||||
hotkey::key_event(gui_, event, this);
|
||||
// A key event may change the video mode.
|
||||
// The redraw functionality inside the preferences module
|
||||
// does not redraw our palettes, so we need to check
|
||||
// A key event may change the video mode.
|
||||
// The redraw functionality inside the preferences module
|
||||
// does not redraw our palettes, so we need to check
|
||||
// if the mode has changed and if so redraw everything.
|
||||
if (preferences::fullscreen() != old_fullscreen
|
||||
|| old_resolution != preferences::resolution()) {
|
||||
|
@ -349,9 +349,9 @@ void map_editor::handle_mouse_button_event(const SDL_MouseButtonEvent &event,
|
|||
right_click(hex_clicked);
|
||||
}
|
||||
}
|
||||
// Mimic the game's behavior on middle click and mouse wheel movement.
|
||||
// It would be nice to have had these in functions provided from the game,
|
||||
// but I don't want to interfer too much with the game code
|
||||
// Mimic the game's behavior on middle click and mouse wheel movement.
|
||||
// It would be nice to have had these in functions provided from the game,
|
||||
// but I don't want to interfer too much with the game code
|
||||
// and it's fairly simple stuff to rip.
|
||||
if (button == SDL_BUTTON_MIDDLE) {
|
||||
const SDL_Rect& rect = gui_.map_area();
|
||||
|
@ -382,7 +382,7 @@ void map_editor::handle_mouse_button_event(const SDL_MouseButtonEvent &event,
|
|||
else
|
||||
gui_.scroll(scrollx,scrolly);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
// If we miss the mouse up event, we need to perform the actual
|
||||
|
@ -416,7 +416,7 @@ void map_editor::left_click(const gamemap::location hex_clicked) {
|
|||
selection_move_start_ = hex_clicked;
|
||||
}
|
||||
else if (!selected_hexes_.empty()) {
|
||||
// If hexes are selected, clear them
|
||||
// If hexes are selected, clear them
|
||||
// and do not draw anything.
|
||||
selected_hexes_.clear();
|
||||
clear_highlighted_hexes_in_gui();
|
||||
|
@ -450,7 +450,7 @@ void map_editor::right_click(const gamemap::location hex_clicked ) {
|
|||
void map_editor::change_language() {
|
||||
std::vector<language_def> langdefs = get_languages();
|
||||
|
||||
// This only works because get_languages() returns a fresh vector
|
||||
// This only works because get_languages() returns a fresh vector
|
||||
// at each calls unless show_gui cleans the "*" flag.
|
||||
const std::vector<language_def>::iterator current = std::find(langdefs.begin(),langdefs.end(),get_language());
|
||||
if(current != langdefs.end()) {
|
||||
|
@ -536,22 +536,22 @@ void map_editor::edit_save_as() {
|
|||
|
||||
void map_editor::perform_set_starting_pos() {
|
||||
std::vector<std::string> players;
|
||||
|
||||
|
||||
std::stringstream none_str;
|
||||
none_str << _("None");
|
||||
players.push_back(none_str.str());
|
||||
|
||||
|
||||
for (int i = 0; i < num_players; i++) {
|
||||
std::stringstream str;
|
||||
str << _("Player") << " " << i + 1;
|
||||
players.push_back(str.str());
|
||||
}
|
||||
gui::dialog pmenu = gui::dialog(gui_,
|
||||
gui::dialog pmenu = gui::dialog(gui_,
|
||||
_("Which Player?"),
|
||||
_("Which player should start here?"),
|
||||
gui::OK_CANCEL);
|
||||
pmenu.set_menu(players);
|
||||
int res = pmenu.show();
|
||||
int res = pmenu.show();
|
||||
if (res >= 0) {
|
||||
// We erase previous starting position on this hex.
|
||||
// This will prevent to cause a "stack" of these.
|
||||
|
@ -710,10 +710,10 @@ void map_editor::edit_resize() {
|
|||
int x_offset = 0, y_offset = 0;
|
||||
bool do_expand = true;
|
||||
if(resize_dialog(gui_, width, height, x_offset, y_offset, do_expand)) {
|
||||
|
||||
|
||||
try {
|
||||
const std::string resized_map =
|
||||
resize_map(map_, width, height, x_offset, y_offset,
|
||||
resize_map(map_, width, height, x_offset, y_offset,
|
||||
do_expand, palette_.selected_bg_terrain());
|
||||
|
||||
if (resized_map != "") {
|
||||
|
@ -792,7 +792,7 @@ void map_editor::insert_selection_in_clipboard() {
|
|||
}
|
||||
gamemap::location offset_hex = *(selected_hexes_.begin());
|
||||
std::set<gamemap::location>::const_iterator it;
|
||||
// Find the hex that is closest to the selected one,
|
||||
// Find the hex that is closest to the selected one,
|
||||
// use this as the one to calculate the offset from.
|
||||
for (it = selected_hexes_.begin(); it != selected_hexes_.end(); it++) {
|
||||
if (distance_between(selected_hex_, *it) <
|
||||
|
@ -963,15 +963,15 @@ void map_editor::clear_highlighted_hexes_in_gui() {
|
|||
void map_editor::set_mouseover_overlay()
|
||||
{
|
||||
surface image_fg(image::get_image("terrain/" + map_.get_terrain_info(
|
||||
palette_.selected_fg_terrain()).editor_image() +
|
||||
palette_.selected_fg_terrain()).editor_image() +
|
||||
".png"));
|
||||
surface image_bg(image::get_image("terrain/" + map_.get_terrain_info(
|
||||
palette_.selected_bg_terrain()).editor_image() +
|
||||
palette_.selected_bg_terrain()).editor_image() +
|
||||
".png"));
|
||||
|
||||
// For efficiency the size of the tile is cached.
|
||||
// We assume all tiles are of the same size.
|
||||
// The zoom factor can change, so it's not cached.
|
||||
// For efficiency the size of the tile is cached.
|
||||
// We assume all tiles are of the same size.
|
||||
// The zoom factor can change, so it's not cached.
|
||||
// NOTE: when zooming and not moving the mouse, there are glitches.
|
||||
// Since the optimal alpha factor is unknown, it has to be calculated
|
||||
// on the fly, and caching the surfaces makes no sense yet.
|
||||
|
@ -983,20 +983,20 @@ void map_editor::set_mouseover_overlay()
|
|||
static const int new_size = half_size - 2;
|
||||
const int zoom = static_cast<int>(size * gui_.get_zoom_factor());
|
||||
|
||||
// Create a transparent surface of the right size.
|
||||
// Not sure what's the best way, but this works
|
||||
// Create a transparent surface of the right size.
|
||||
// Not sure what's the best way, but this works
|
||||
// (but is probably not efficient).
|
||||
surface image = adjust_surface_alpha(image_fg, 0);
|
||||
|
||||
// Blit left side
|
||||
image_fg = scale_surface(image_fg, new_size, new_size);
|
||||
SDL_Rect rcDestLeft = { offset, quarter_size, 0, 0 };
|
||||
SDL_BlitSurface ( image_fg, NULL, image, &rcDestLeft );
|
||||
SDL_Rect rcDestLeft = { offset, quarter_size, 0, 0 };
|
||||
SDL_BlitSurface ( image_fg, NULL, image, &rcDestLeft );
|
||||
|
||||
// Blit left side
|
||||
image_bg = scale_surface(image_bg, new_size, new_size);
|
||||
SDL_Rect rcDestRight = { half_size, quarter_size, 0, 0 };
|
||||
SDL_BlitSurface ( image_bg, NULL, image, &rcDestRight );
|
||||
SDL_Rect rcDestRight = { half_size, quarter_size, 0, 0 };
|
||||
SDL_BlitSurface ( image_bg, NULL, image, &rcDestRight );
|
||||
|
||||
// Add the alpha factor and scale the image
|
||||
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
|
||||
|
@ -1012,14 +1012,14 @@ bool map_editor::changed_since_save() const {
|
|||
void map_editor::set_starting_position(const int player, const gamemap::location loc) {
|
||||
if(map_.on_board(loc)) {
|
||||
map_undo_action action;
|
||||
|
||||
|
||||
action.add_starting_location(player, player, map_.starting_position(player), loc);
|
||||
map_.set_starting_position(player, loc);
|
||||
save_undo_action(action);
|
||||
recalculate_starting_pos_labels();
|
||||
}
|
||||
else {
|
||||
// If you selected an off-board hex,
|
||||
// If you selected an off-board hex,
|
||||
// we just use the standard invalid location
|
||||
map_undo_action action;
|
||||
action.add_starting_location(player, player, map_.starting_position(player), gamemap::location());
|
||||
|
@ -1187,8 +1187,8 @@ void map_editor::perform_selection_move() {
|
|||
save_undo_action(undo_action);
|
||||
}
|
||||
|
||||
void map_editor::draw_terrain(const t_translation::t_letter terrain,
|
||||
const gamemap::location hex)
|
||||
void map_editor::draw_terrain(const t_translation::t_letter terrain,
|
||||
const gamemap::location hex)
|
||||
{
|
||||
const t_translation::t_letter current_terrain = map_.get_terrain(hex);
|
||||
map_undo_action undo_action;
|
||||
|
@ -1199,13 +1199,13 @@ void map_editor::draw_terrain(const t_translation::t_letter terrain,
|
|||
save_undo_action(undo_action);
|
||||
}
|
||||
|
||||
void map_editor::terrain_changed(const gamemap::location &hex)
|
||||
void map_editor::terrain_changed(const gamemap::location &hex)
|
||||
{
|
||||
std::vector<gamemap::location> v(1, hex);
|
||||
terrain_changed(v);
|
||||
}
|
||||
|
||||
void map_editor::terrain_changed(const std::vector<gamemap::location> &hexes)
|
||||
void map_editor::terrain_changed(const std::vector<gamemap::location> &hexes)
|
||||
{
|
||||
invalidate_all_and_adjacent(hexes);
|
||||
}
|
||||
|
@ -1256,7 +1256,7 @@ void map_editor::invalidate_all_and_adjacent(const std::set<gamemap::location> &
|
|||
}
|
||||
|
||||
void map_editor::right_button_down(const int /*mousex*/, const int /*mousey*/) {
|
||||
// Draw with the background terrain on rightclick,
|
||||
// Draw with the background terrain on rightclick,
|
||||
// no matter what operations are wanted with the left button.
|
||||
//! @todo TODO evaluate if this is what is the smartest thing to do.
|
||||
draw_on_mouseover_hexes(palette_.selected_bg_terrain());
|
||||
|
@ -1299,8 +1299,8 @@ bool map_editor::save_map(const std::string fn, const bool display_confirmation)
|
|||
filename_ = filename;
|
||||
}
|
||||
|
||||
// Check if the filename is correct before saving.
|
||||
// We do this twice (also in the 'save as' routine),
|
||||
// Check if the filename is correct before saving.
|
||||
// We do this twice (also in the 'save as' routine),
|
||||
// because a file might already contain illegal characters if loaded.
|
||||
if(!verify_filename(filename, display_confirmation)) {
|
||||
return false;
|
||||
|
@ -1402,15 +1402,15 @@ void map_editor::recalculate_starting_pos_labels() {
|
|||
}
|
||||
}
|
||||
|
||||
void map_editor::update_mouse_over_hexes(const gamemap::location mouse_over_hex)
|
||||
void map_editor::update_mouse_over_hexes(const gamemap::location mouse_over_hex)
|
||||
{
|
||||
const int size = (l_button_func_ == DRAW) ? brush_.selected_brush_size() : 1;
|
||||
std::vector<gamemap::location> curr_locs = get_tiles(map_, mouse_over_hex, size);
|
||||
|
||||
|
||||
std::set<gamemap::location>::iterator it;
|
||||
for (it = mouse_over_hexes_.begin(); it != mouse_over_hexes_.end(); it++) {
|
||||
if (selected_hexes_.find(*it) == selected_hexes_.end()) {
|
||||
// Only remove highlightning if the hex is not selected
|
||||
// Only remove highlightning if the hex is not selected
|
||||
// in an other way.
|
||||
gui_.remove_highlighted_loc(*it);
|
||||
}
|
||||
|
@ -1424,7 +1424,7 @@ void map_editor::update_mouse_over_hexes(const gamemap::location mouse_over_hex)
|
|||
gui_.add_highlighted_loc(*itv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gui_.highlight_hex(mouse_over_hex);
|
||||
|
||||
if(l_button_func_ == DRAW || l_button_func_ == FLOOD_FILL) {
|
||||
|
@ -1565,8 +1565,8 @@ void map_editor::main_loop() {
|
|||
gui_.draw(false);
|
||||
events::raise_draw_event();
|
||||
|
||||
// When the map has changed, wait until the left mouse button
|
||||
// is not held down, and then update the minimap and
|
||||
// When the map has changed, wait until the left mouse button
|
||||
// is not held down, and then update the minimap and
|
||||
// the starting position labels.
|
||||
if (map_dirty_ && auto_update_) {
|
||||
if (!l_button_down && !r_button_down) {
|
||||
|
@ -1596,6 +1596,6 @@ void map_editor::main_loop() {
|
|||
mouse_moved_ = false;
|
||||
}
|
||||
}
|
||||
} // end namespace map_editor
|
||||
} // end namespace map_editor
|
||||
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ private:
|
|||
|
||||
// Sets the special overlay with the selection of fore and background
|
||||
void set_mouseover_overlay();
|
||||
// Clears the special overlay
|
||||
// Clears the special overlay
|
||||
void reset_mouseover_overlay() { gui_.clear_mouseover_hex_overlay(); }
|
||||
|
||||
/// Terrain has changed at the specified hex through user drawing
|
||||
|
@ -321,7 +321,7 @@ private:
|
|||
gamemap::location selected_hex_;
|
||||
// When map_dirty_ is true, schedule redraw of the minimap and
|
||||
// perform some updates like recalculating labels of starting
|
||||
// positions. But only it the option auto_update is enabled
|
||||
// positions. But only it the option auto_update is enabled
|
||||
bool map_dirty_;
|
||||
bool auto_update_;
|
||||
bool l_button_palette_dirty_;
|
||||
|
|
|
@ -276,7 +276,7 @@ void preferences_dialog(display &disp, config &prefs) {
|
|||
scroll_slider.set_min(1);
|
||||
scroll_slider.set_max(100);
|
||||
scroll_slider.set_value(preferences::scroll_speed());
|
||||
|
||||
|
||||
gui::button fullscreen_button(disp.video(),_("Toggle Full Screen"),
|
||||
gui::button::TYPE_CHECK);
|
||||
|
||||
|
@ -299,7 +299,7 @@ void preferences_dialog(display &disp, config &prefs) {
|
|||
scroll_pos + 80 + 50);
|
||||
|
||||
bool redraw_all = true;
|
||||
|
||||
|
||||
for(;;) {
|
||||
if(close_button.pressed()) {
|
||||
break;
|
||||
|
@ -401,7 +401,7 @@ bool resize_dialog(display &disp, unsigned& width, unsigned& height,
|
|||
|
||||
// store the width of all labels in an array to determine the maximum
|
||||
const int label_arr_size = 4;
|
||||
int label_arr[label_arr_size] =
|
||||
int label_arr[label_arr_size] =
|
||||
{ width_rect.w, height_rect.w, x_offset_rect.w, y_offset_rect.w };
|
||||
|
||||
// use the biggest label to deterimine the right side for the labels
|
||||
|
@ -495,7 +495,7 @@ bool resize_dialog(display &disp, unsigned& width, unsigned& height,
|
|||
font::NORMAL_COLOUR, _("Resize Map"),
|
||||
xpos + (dlg_width - title_rect.w) / 2, ypos + 10);
|
||||
|
||||
font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
|
||||
font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
|
||||
width_label, width_rect.x, width_rect.y);
|
||||
|
||||
font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
|
||||
|
@ -507,19 +507,19 @@ bool resize_dialog(display &disp, unsigned& width, unsigned& height,
|
|||
font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
|
||||
y_offset_label, y_offset_rect.x, y_offset_rect.y);
|
||||
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::NORMAL_COLOUR, lexical_cast<std::string>(width),
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::NORMAL_COLOUR, lexical_cast<std::string>(width),
|
||||
slider_right + horz_margin, width_rect.y);
|
||||
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::NORMAL_COLOUR, lexical_cast<std::string>(height),
|
||||
slider_right + horz_margin, height_rect.y);
|
||||
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::NORMAL_COLOUR, lexical_cast<std::string>(x_offset),
|
||||
slider_right + horz_margin, x_offset_rect.y);
|
||||
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::draw_text(&disp.video(), screen_area(), 14,
|
||||
font::NORMAL_COLOUR, lexical_cast<std::string>(y_offset),
|
||||
slider_right + horz_margin, y_offset_rect.y);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "SDL_image.h"
|
||||
|
||||
editor_display::editor_display(CVideo& video, const gamemap& map,
|
||||
const config& theme_cfg, const config& cfg,
|
||||
const config& theme_cfg, const config& cfg,
|
||||
const config& level) :
|
||||
display(video, map, theme_cfg, cfg, level)
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ void editor_display::draw(bool update,bool force)
|
|||
//int simulate_delay = 0;
|
||||
if(!map_.empty() && !invalidated_.empty()) {
|
||||
changed = true;
|
||||
|
||||
|
||||
SDL_Rect clip_rect = map_outside_area();
|
||||
surface const dst(screen_.getSurface());
|
||||
clip_rect_setter set_clip_rect(dst, clip_rect);
|
||||
|
@ -81,7 +81,7 @@ void editor_display::draw(bool update,bool force)
|
|||
tile_stack_append(get_terrain_images(*it,nodarken,image_type,ADJACENT_BACKGROUND));
|
||||
tile_stack_append(get_terrain_images(*it,nodarken,image_type,ADJACENT_FOREGROUND));
|
||||
|
||||
// draw the grid, if that's been enabled
|
||||
// draw the grid, if that's been enabled
|
||||
if(grid_ && map_.on_board(*it)) {
|
||||
tile_stack_append(image::get_image(game_config::grid_image, image::SCALED_TO_HEX));
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ void editor_display::draw(bool update,bool force)
|
|||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
str << " (";
|
||||
|
||||
for(t_translation::t_list::const_iterator i =
|
||||
for(t_translation::t_list::const_iterator i =
|
||||
underlying.begin(); i != underlying.end(); ++i) {
|
||||
|
||||
str << map_.get_terrain_info(*i).name();
|
||||
|
|
|
@ -69,7 +69,7 @@ int main(int argc, char** argv)
|
|||
<< " --logdomains List defined log domains and exit.\n";
|
||||
return 0;
|
||||
} else if(val == "--version" || val == "-v") {
|
||||
std::cout << "Battle for Wesnoth "
|
||||
std::cout << "Battle for Wesnoth "
|
||||
<< game_config::version
|
||||
#if defined(SVNREV) && defined(DO_DISPLAY_REVISION)
|
||||
<< " (" << game_config::svnrev << ")"
|
||||
|
|
|
@ -35,14 +35,14 @@ bool is_invalid_terrain(t_translation::t_letter c) {
|
|||
}
|
||||
|
||||
terrain_group::terrain_group(const config& cfg, display& gui):
|
||||
id(cfg["id"]), name(cfg["name"]),
|
||||
id(cfg["id"]), name(cfg["name"]),
|
||||
button(gui.video(), "", gui::button::TYPE_CHECK, cfg["icon"])
|
||||
{
|
||||
}
|
||||
|
||||
terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
|
||||
const gamemap &map, const config& cfg)
|
||||
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), tstart_(0),
|
||||
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), tstart_(0),
|
||||
checked_group_btn_(0), map_(map),
|
||||
top_button_(gui.video(), "", gui::button::TYPE_PRESS, "uparrow-button"),
|
||||
bot_button_(gui.video(), "", gui::button::TYPE_PRESS, "downarrow-button")
|
||||
|
@ -72,19 +72,19 @@ terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
|
|||
t_translation::t_list::const_iterator t_itor = terrains_.begin();
|
||||
for(; t_itor != terrains_.end(); ++t_itor) {
|
||||
// add the terrain to the requested groups
|
||||
const std::vector<std::string>& key =
|
||||
const std::vector<std::string>& key =
|
||||
utils::split(map_.get_terrain_info(*t_itor).editor_group());
|
||||
|
||||
for(std::vector<std::string>::const_iterator k_itor = key.begin();
|
||||
|
||||
for(std::vector<std::string>::const_iterator k_itor = key.begin();
|
||||
k_itor != key.end(); ++k_itor)
|
||||
{
|
||||
terrain_map_[*k_itor].push_back(*t_itor);
|
||||
}
|
||||
|
||||
|
||||
// add the terrain to the default group
|
||||
terrain_map_["all"].push_back(*t_itor);
|
||||
}
|
||||
|
||||
|
||||
// set the default group
|
||||
terrains_ = terrain_map_["all"];
|
||||
|
||||
|
@ -127,8 +127,8 @@ void terrain_palette::adjust_size() {
|
|||
rect.y = terrain_start_;
|
||||
rect.h = space_for_terrains;
|
||||
bg_register(rect);
|
||||
const unsigned terrains_fitting =
|
||||
static_cast<unsigned> (space_for_terrains / size_specs_.terrain_space) *
|
||||
const unsigned terrains_fitting =
|
||||
static_cast<unsigned> (space_for_terrains / size_specs_.terrain_space) *
|
||||
size_specs_.terrain_width;
|
||||
const unsigned total_terrains = num_terrains();
|
||||
nterrains_ = minimum<int>(terrains_fitting, total_terrains);
|
||||
|
@ -148,7 +148,7 @@ void terrain_palette::adjust_size() {
|
|||
left += group_button_height + group_button_padding;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
@ -211,17 +211,17 @@ void terrain_palette::set_group(const std::string& id)
|
|||
scroll_top();
|
||||
}
|
||||
|
||||
t_translation::t_letter terrain_palette::selected_fg_terrain() const
|
||||
t_translation::t_letter terrain_palette::selected_fg_terrain() const
|
||||
{
|
||||
return selected_fg_terrain_;
|
||||
}
|
||||
|
||||
t_translation::t_letter terrain_palette::selected_bg_terrain() const
|
||||
t_translation::t_letter terrain_palette::selected_bg_terrain() const
|
||||
{
|
||||
return selected_bg_terrain_;
|
||||
}
|
||||
|
||||
void terrain_palette::select_fg_terrain(t_translation::t_letter terrain)
|
||||
void terrain_palette::select_fg_terrain(t_translation::t_letter terrain)
|
||||
{
|
||||
if (selected_fg_terrain_ != terrain) {
|
||||
set_dirty();
|
||||
|
@ -230,7 +230,7 @@ void terrain_palette::select_fg_terrain(t_translation::t_letter terrain)
|
|||
}
|
||||
}
|
||||
|
||||
void terrain_palette::select_bg_terrain(t_translation::t_letter terrain)
|
||||
void terrain_palette::select_bg_terrain(t_translation::t_letter terrain)
|
||||
{
|
||||
if (selected_bg_terrain_ != terrain) {
|
||||
set_dirty();
|
||||
|
@ -242,13 +242,13 @@ void terrain_palette::select_bg_terrain(t_translation::t_letter terrain)
|
|||
/**
|
||||
* After the language is changed, the selected terrains needs an update.
|
||||
*/
|
||||
void terrain_palette::update_selected_terrains(void)
|
||||
void terrain_palette::update_selected_terrains(void)
|
||||
{
|
||||
set_dirty();
|
||||
update_report();
|
||||
}
|
||||
|
||||
std::string terrain_palette::get_terrain_string(const t_translation::t_letter t)
|
||||
std::string terrain_palette::get_terrain_string(const t_translation::t_letter t)
|
||||
{
|
||||
std::stringstream str;
|
||||
const std::string& name = map_.get_terrain_info(t).name();
|
||||
|
@ -374,10 +374,10 @@ void terrain_palette::draw(bool force) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(static_cast<unsigned>(image->w) != size_specs_.terrain_size ||
|
||||
if(static_cast<unsigned>(image->w) != size_specs_.terrain_size ||
|
||||
static_cast<unsigned>(image->h) != size_specs_.terrain_size) {
|
||||
|
||||
image.assign(scale_surface(image,
|
||||
image.assign(scale_surface(image,
|
||||
size_specs_.terrain_size, size_specs_.terrain_size));
|
||||
}
|
||||
|
||||
|
@ -533,7 +533,7 @@ void brush_bar::draw(bool force) {
|
|||
std::cerr << "Image " << filename.str() << " not found." << std::endl;
|
||||
continue;
|
||||
}
|
||||
if (static_cast<unsigned>(image->w) != size_ ||
|
||||
if (static_cast<unsigned>(image->w) != size_ ||
|
||||
static_cast<unsigned>(image->h) != size_) {
|
||||
|
||||
image.assign(scale_surface(image, size_, size_));
|
||||
|
@ -558,7 +558,7 @@ int brush_bar::selected_index(const int x, const int y) const {
|
|||
const int bar_x = size_specs_.brush_x;
|
||||
const int bar_y = size_specs_.brush_y;
|
||||
|
||||
if ((x < bar_x || static_cast<unsigned>(x) > bar_x + size_ * total_brush_ +
|
||||
if ((x < bar_x || static_cast<unsigned>(x) > bar_x + size_ * total_brush_ +
|
||||
total_brush_ * size_specs_.brush_padding) ||
|
||||
(y < bar_y || static_cast<unsigned>(y) > bar_y + size_)) {
|
||||
|
||||
|
@ -568,7 +568,7 @@ int brush_bar::selected_index(const int x, const int y) const {
|
|||
for(int i = 0; i < total_brush_; i++) {
|
||||
const int px = bar_x + size_ * i + i * size_specs_.brush_padding;
|
||||
|
||||
if(x >= px && static_cast<unsigned>(x) <= px + size_ &&
|
||||
if(x >= px && static_cast<unsigned>(x) <= px + size_ &&
|
||||
y >= bar_y && static_cast<unsigned>(y) <= bar_y + size_) {
|
||||
|
||||
return i;
|
||||
|
|
|
@ -32,7 +32,7 @@ class config;
|
|||
namespace map_editor {
|
||||
|
||||
// a helper struct which for some reason can't be moved to
|
||||
// the cpp file. Stores the info about the data in
|
||||
// the cpp file. Stores the info about the data in
|
||||
// editor-groups.cfg in a nice format
|
||||
struct terrain_group
|
||||
{
|
||||
|
@ -117,25 +117,25 @@ private:
|
|||
const size_specs &size_specs_;
|
||||
display &gui_;
|
||||
unsigned int tstart_;
|
||||
|
||||
|
||||
//this map contains all editor_group as defined in terrain.cfg and
|
||||
//associate with the group there. The group all is added automatically
|
||||
//and all terrains are also automatically stored in this group
|
||||
std::map<std::string, t_translation::t_list> terrain_map_;
|
||||
|
||||
|
||||
// a copy from the terrain_map_->second for the current active group
|
||||
t_translation::t_list terrains_;
|
||||
t_translation::t_list terrains_;
|
||||
|
||||
//the editor_groups as defined in editor-groups.cfg, note the
|
||||
//user must make sure the id's here are the same as the
|
||||
//user must make sure the id's here are the same as the
|
||||
//editor_group in terrain.cfg
|
||||
std::vector<terrain_group> terrain_groups_;
|
||||
|
||||
//the group buttons behave like a radio group this one points to the
|
||||
//the group buttons behave like a radio group this one points to the
|
||||
//selected button, this value should not be 0 otherwise things will
|
||||
//fail. Thus should be set in constructor
|
||||
gui::button *checked_group_btn_;
|
||||
|
||||
|
||||
t_translation::t_letter selected_fg_terrain_, selected_bg_terrain_;
|
||||
const gamemap &map_;
|
||||
gui::button top_button_, bot_button_;
|
||||
|
|
|
@ -30,12 +30,12 @@ map_undo_action::map_undo_action() {
|
|||
starting_locations_set_ = false;
|
||||
}
|
||||
|
||||
const std::map<gamemap::location, t_translation::t_letter>& map_undo_action::undo_terrains() const
|
||||
const std::map<gamemap::location, t_translation::t_letter>& map_undo_action::undo_terrains() const
|
||||
{
|
||||
return old_terrain_;
|
||||
}
|
||||
|
||||
const std::map<gamemap::location, t_translation::t_letter>& map_undo_action::redo_terrains() const
|
||||
const std::map<gamemap::location, t_translation::t_letter>& map_undo_action::redo_terrains() const
|
||||
{
|
||||
return new_terrain_;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ const std::map<gamemap::location, int>& map_undo_action::redo_starting_locations
|
|||
|
||||
void map_undo_action::add_terrain(const t_translation::t_letter& old_tr,
|
||||
const t_translation::t_letter& new_tr,
|
||||
const gamemap::location& lc)
|
||||
const gamemap::location& lc)
|
||||
{
|
||||
old_terrain_[lc] = old_tr;
|
||||
new_terrain_[lc] = new_tr;
|
||||
|
|
|
@ -53,32 +53,32 @@ std::string editormap::resize(const size_t width, const size_t height,
|
|||
const int right_resize = (width - old_w) + x_offset;
|
||||
const int top_resize = -y_offset;
|
||||
const int bottom_resize = (height - old_h) + y_offset;
|
||||
|
||||
// std::cerr << "resize y " << left_resize << " x " << right_resize
|
||||
|
||||
// std::cerr << "resize y " << left_resize << " x " << right_resize
|
||||
// << " top " << top_resize << " bottom " << bottom_resize << '\n';
|
||||
|
||||
if(right_resize > 0) {
|
||||
add_tiles_right(right_resize, filler);
|
||||
add_tiles_right(right_resize, filler);
|
||||
} else if(right_resize < 0) {
|
||||
remove_tiles_right(-right_resize);
|
||||
remove_tiles_right(-right_resize);
|
||||
}
|
||||
|
||||
if(bottom_resize > 0) {
|
||||
add_tiles_bottom(bottom_resize, filler);
|
||||
add_tiles_bottom(bottom_resize, filler);
|
||||
} else if(bottom_resize < 0) {
|
||||
remove_tiles_bottom(-bottom_resize);
|
||||
remove_tiles_bottom(-bottom_resize);
|
||||
}
|
||||
|
||||
if(left_resize > 0) {
|
||||
add_tiles_left(left_resize, filler);
|
||||
add_tiles_left(left_resize, filler);
|
||||
} else if(left_resize < 0) {
|
||||
remove_tiles_left(-left_resize);
|
||||
remove_tiles_left(-left_resize);
|
||||
}
|
||||
|
||||
if(top_resize > 0) {
|
||||
add_tiles_top(top_resize, filler);
|
||||
add_tiles_top(top_resize, filler);
|
||||
} else if(top_resize < 0) {
|
||||
remove_tiles_top(-top_resize);
|
||||
remove_tiles_top(-top_resize);
|
||||
}
|
||||
|
||||
return write();
|
||||
|
@ -101,7 +101,7 @@ std::string editormap::flip(const map_editor::FLIP_AXIS axis)
|
|||
if(x % 2) {
|
||||
// odd lines
|
||||
tiles_[x].resize(tiles_[x].size() + 1, tiles_[x][0]);
|
||||
|
||||
|
||||
for(size_t y1 = 0, y2 = end; y1 < middle; ++y1, --y2) {
|
||||
swap_starting_position(x, y1, x, y2);
|
||||
std::swap(tiles_[x][y1], tiles_[x][y2]);
|
||||
|
@ -109,7 +109,7 @@ std::string editormap::flip(const map_editor::FLIP_AXIS axis)
|
|||
} else {
|
||||
// even lines
|
||||
tiles_[x].resize(tiles_[x].size() + 1, tiles_[x][end]);
|
||||
|
||||
|
||||
for(size_t y1 = 0, y2 = end + 1; y1 < middle; ++y1, --y2) {
|
||||
swap_starting_position(x, y1, x, y2);
|
||||
std::swap(tiles_[x][y1], tiles_[x][y2]);
|
||||
|
@ -146,7 +146,7 @@ void editormap::swap_starting_position(const size_t x1, const size_t y1,
|
|||
if(pos1 != -1) {
|
||||
set_starting_position(pos1 + 1, location(x2, y2));
|
||||
}
|
||||
|
||||
|
||||
if(pos2 != -1) {
|
||||
set_starting_position(pos2 + 1, location(x1, y1));
|
||||
}
|
||||
|
@ -160,8 +160,8 @@ void editormap::add_tiles_right(
|
|||
for(size_t x = 1; x <= count; ++x) {
|
||||
t_translation::t_list one_row(h());
|
||||
for(size_t y = 0; y < tiles_[1].size(); ++y) {
|
||||
one_row[y] =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
one_row[y] =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
filler :
|
||||
get_terrain(gamemap::location(x - 1, y));
|
||||
|
||||
|
@ -179,8 +179,8 @@ void editormap::add_tiles_left(
|
|||
for(size_t i = 1; i <= count; ++i) {
|
||||
t_translation::t_list one_row(h());
|
||||
for(size_t y = 0; y < tiles_[1].size(); ++y) {
|
||||
one_row[y] =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
one_row[y] =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
filler :
|
||||
get_terrain(gamemap::location(-1, y));
|
||||
|
||||
|
@ -198,7 +198,7 @@ void editormap::remove_tiles_right(const unsigned count)
|
|||
if(count > tiles_.size()) {
|
||||
std::stringstream sstr;
|
||||
sstr << _("Can't resize the map, the requested size is bigger "
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
<< tiles_.size();
|
||||
|
||||
throw incorrect_format_exception(sstr.str().c_str());
|
||||
|
@ -214,7 +214,7 @@ void editormap::remove_tiles_left(const unsigned count)
|
|||
if(count > tiles_.size()) {
|
||||
std::stringstream sstr;
|
||||
sstr << _("Can't resize the map, the requested size is bigger "
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
<< tiles_.size();
|
||||
|
||||
throw incorrect_format_exception(sstr.str().c_str());
|
||||
|
@ -230,8 +230,8 @@ void editormap::add_tiles_top(
|
|||
|
||||
for(size_t i = 1; i <= count; ++i) {
|
||||
for(size_t y = 0; y < tiles_.size(); ++y) {
|
||||
t_translation::t_letter terrain =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
t_translation::t_letter terrain =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
filler :
|
||||
get_terrain(gamemap::location(y, -1));
|
||||
|
||||
|
@ -249,8 +249,8 @@ void editormap::add_tiles_bottom(
|
|||
|
||||
for(size_t i = 1; i <= count; ++i) {
|
||||
for(size_t x = 0; x < tiles_.size(); ++x) {
|
||||
t_translation::t_letter terrain =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
t_translation::t_letter terrain =
|
||||
filler != t_translation::NONE_TERRAIN ?
|
||||
filler :
|
||||
get_terrain(gamemap::location(x, i - 1));
|
||||
|
||||
|
@ -267,7 +267,7 @@ void editormap::remove_tiles_top(const unsigned count)
|
|||
if(count > tiles_[0].size()) {
|
||||
std::stringstream sstr;
|
||||
sstr << _("Can't resize the map, the requested size is bigger "
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
<< tiles_[0].size();
|
||||
|
||||
throw incorrect_format_exception(sstr.str().c_str());
|
||||
|
@ -285,7 +285,7 @@ void editormap::remove_tiles_bottom(const unsigned count)
|
|||
if(count > tiles_[0].size()) {
|
||||
std::stringstream sstr;
|
||||
sstr << _("Can't resize the map, the requested size is bigger "
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
"than the maximum, size=") << count << _(" maximum=")
|
||||
<< tiles_[0].size();
|
||||
|
||||
throw incorrect_format_exception(sstr.str().c_str());
|
||||
|
@ -329,7 +329,7 @@ std::vector<gamemap::location> get_tiles(const gamemap &map,
|
|||
}
|
||||
|
||||
void flood_fill(gamemap &map, const gamemap::location &start_loc,
|
||||
const t_translation::t_letter fill_with, terrain_log *log)
|
||||
const t_translation::t_letter fill_with, terrain_log *log)
|
||||
{
|
||||
t_translation::t_letter terrain_to_fill = map.get_terrain(start_loc);
|
||||
if (fill_with == terrain_to_fill) {
|
||||
|
@ -346,16 +346,16 @@ void flood_fill(gamemap &map, const gamemap::location &start_loc,
|
|||
}
|
||||
}
|
||||
|
||||
std::set<gamemap::location> get_component(const gamemap &map,
|
||||
const gamemap::location &start_loc)
|
||||
std::set<gamemap::location> get_component(const gamemap &map,
|
||||
const gamemap::location &start_loc)
|
||||
{
|
||||
t_translation::t_letter terrain_to_fill = map.get_terrain(start_loc);
|
||||
std::set<gamemap::location> to_fill;
|
||||
std::set<gamemap::location> filled;
|
||||
std::set<gamemap::location>::iterator it;
|
||||
// Insert the start location in a set.
|
||||
// Chose an element in the set, mark this element,
|
||||
// and add all adjacent elements that are not marked.
|
||||
// Insert the start location in a set.
|
||||
// Chose an element in the set, mark this element,
|
||||
// and add all adjacent elements that are not marked.
|
||||
// Continue until the set is empty.
|
||||
to_fill.insert(start_loc);
|
||||
while (!to_fill.empty()) {
|
||||
|
@ -363,7 +363,7 @@ std::set<gamemap::location> get_component(const gamemap &map,
|
|||
gamemap::location loc = *it;
|
||||
to_fill.erase(it);
|
||||
filled.insert(loc);
|
||||
// Find all adjacent tiles with the terrain that should
|
||||
// Find all adjacent tiles with the terrain that should
|
||||
// be filled and add these to the to_fill vector.
|
||||
std::vector<gamemap::location> adj = get_tiles(map, loc, 2);
|
||||
for (std::vector<gamemap::location>::iterator it2 = adj.begin();
|
||||
|
@ -395,7 +395,7 @@ bool valid_mapdata(const std::string &data, const config &cfg) {
|
|||
// but simple as things are implemented now.
|
||||
try {
|
||||
const gamemap m(cfg, data);
|
||||
// Having a zero size map may cause floating point exceptions
|
||||
// Having a zero size map may cause floating point exceptions
|
||||
// at some places later on.
|
||||
res = m.w() != 0 && m.h() != 0;
|
||||
}
|
||||
|
@ -411,8 +411,8 @@ std::string new_map(const size_t width, const size_t height, const t_translation
|
|||
const t_translation::t_map map(width, column);
|
||||
|
||||
return t_translation::write_game_map(map);
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // end namespace map_editor
|
||||
} // end namespace map_editor
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace map_editor {
|
|||
enum FLIP_AXIS {NO_FLIP, FLIP_X, FLIP_Y};
|
||||
}
|
||||
|
||||
// This object modifies the internal structure of a map,
|
||||
// most of the time this is done on the real map data.
|
||||
// This means that the display and mapdata are heavily out of sync.
|
||||
// This object modifies the internal structure of a map,
|
||||
// most of the time this is done on the real map data.
|
||||
// This means that the display and mapdata are heavily out of sync.
|
||||
// Our callers throw a new_map_exception which will invalide the entire
|
||||
// map object. These callers expect a string with the new raw map data.
|
||||
// So it's "save" but really not clean. -- Mordante
|
||||
|
@ -44,35 +44,35 @@ public:
|
|||
/**
|
||||
* Resizes the map.
|
||||
*
|
||||
* @param width the new width
|
||||
* @param width the new width
|
||||
* @param height the new height
|
||||
* @param x_offset the offset in x direction (the x coordinate specified will be the new 0 location)
|
||||
* @param y_offset the offset in y direction (the y coordinate specified will be the new 0 location)
|
||||
* @param do_expand try to expand the map depending on the current tiles
|
||||
* @param filler if the map is enlarged the new tiles are set to this terrain,
|
||||
* unless expand is set
|
||||
* unless expand is set
|
||||
*
|
||||
* @return if there's been a modification to the map: the new map data as string,
|
||||
* else an empty string
|
||||
* else an empty string
|
||||
*/
|
||||
std::string resize(const size_t width, const size_t height,
|
||||
const int x_offset, const int y_offset,
|
||||
const bool do_expand, t_translation::t_letter filler);
|
||||
const bool do_expand, t_translation::t_letter filler);
|
||||
|
||||
/**
|
||||
* Flips the map over an axis
|
||||
*
|
||||
* @param axis the axis to flip the map over
|
||||
* @param axis the axis to flip the map over
|
||||
*
|
||||
* @return if there's been a modification to the map the new map data as string
|
||||
* else an empty string
|
||||
* else an empty string
|
||||
*/
|
||||
std::string flip(const map_editor::FLIP_AXIS axis);
|
||||
|
||||
/**
|
||||
* Sets the starting position of a player
|
||||
*
|
||||
* @param pos the starting position, 1 = player 1
|
||||
* @param pos the starting position, 1 = player 1
|
||||
* @param loc a location (same as gamemap location)
|
||||
*/
|
||||
void set_starting_position(const int pos, const location loc);
|
||||
|
@ -80,9 +80,9 @@ public:
|
|||
private:
|
||||
|
||||
/**
|
||||
* Exchanges starting positions,
|
||||
* If there's a starting location on x1, y1 it will be moved to x2, y2.
|
||||
* If x2, y2 contains a starting location this is moved to x1, y1.
|
||||
* Exchanges starting positions,
|
||||
* If there's a starting location on x1, y1 it will be moved to x2, y2.
|
||||
* If x2, y2 contains a starting location this is moved to x1, y1.
|
||||
* The function also works if both locations contain
|
||||
* a starting position.
|
||||
*/
|
||||
|
@ -93,9 +93,9 @@ private:
|
|||
/**
|
||||
* Adds column(s) at the right side.
|
||||
*
|
||||
* @param count the number of columns to add
|
||||
* @param count the number of columns to add
|
||||
* @param filler the terrain to draw, if equal to NONE_TERRAIN
|
||||
* the enigne will determine the terrain by itself
|
||||
* the enigne will determine the terrain by itself
|
||||
*/
|
||||
void add_tiles_right(const unsigned count,
|
||||
const t_translation::t_letter& filler);
|
||||
|
@ -103,9 +103,9 @@ private:
|
|||
/**
|
||||
* Adds column(s) at the left side
|
||||
*
|
||||
* @param count the number of columns to add
|
||||
* @param count the number of columns to add
|
||||
* @param filler the terrain to draw, if equal to NONE_TERRAIN
|
||||
* the enigne will determine the terrain by itself
|
||||
* the enigne will determine the terrain by itself
|
||||
*/
|
||||
void add_tiles_left(const unsigned count,
|
||||
const t_translation::t_letter& filler);
|
||||
|
@ -113,23 +113,23 @@ private:
|
|||
/**
|
||||
* Removes column(s) at the right side.
|
||||
*
|
||||
* @param count the number of columns to remove
|
||||
* @param count the number of columns to remove
|
||||
*/
|
||||
void remove_tiles_right(const unsigned count);
|
||||
|
||||
/**
|
||||
* Removes column(s) at the left side.
|
||||
*
|
||||
* @param count the number of columns to remove
|
||||
* @param count the number of columns to remove
|
||||
*/
|
||||
void remove_tiles_left(const unsigned count);
|
||||
|
||||
/**
|
||||
* Adds row(s) at the top side.
|
||||
*
|
||||
* @param count the number of rows to add
|
||||
* @param count the number of rows to add
|
||||
* @param filler the terrain to draw, if equal to NONE_TERRAIN
|
||||
* the enigne will determine the terrain by itself
|
||||
* the enigne will determine the terrain by itself
|
||||
*/
|
||||
void add_tiles_top(const unsigned count,
|
||||
const t_translation::t_letter& filler);
|
||||
|
@ -137,24 +137,24 @@ private:
|
|||
/**
|
||||
* Adds row(s) at the bottom side.
|
||||
*
|
||||
* @param count the number of rows to add
|
||||
* @param count the number of rows to add
|
||||
* @param filler the terrain to draw, if equal to NONE_TERRAIN
|
||||
* the enigne will determine the terrain by itself
|
||||
* the enigne will determine the terrain by itself
|
||||
*/
|
||||
void add_tiles_bottom(const unsigned count,
|
||||
void add_tiles_bottom(const unsigned count,
|
||||
const t_translation::t_letter& filler);
|
||||
|
||||
/**
|
||||
* Removes row(s) at the top side.
|
||||
*
|
||||
* @param count the number of rows to remove
|
||||
* @param count the number of rows to remove
|
||||
*/
|
||||
void remove_tiles_top(const unsigned count);
|
||||
|
||||
/**
|
||||
* Removes row(s) at the bottom side.
|
||||
*
|
||||
* @param count the number of rows to remove
|
||||
* @param count the number of rows to remove
|
||||
*/
|
||||
void remove_tiles_bottom(const unsigned count);
|
||||
};
|
||||
|
@ -168,14 +168,14 @@ std::vector<gamemap::location> get_tiles(const gamemap &map,
|
|||
|
||||
typedef std::vector<std::pair<gamemap::location, t_translation::t_letter> > terrain_log;
|
||||
|
||||
/// Flood fill the map with the terrain fill_with
|
||||
/// starting from the location start_loc.
|
||||
/// If log is non-null it will contain the positions of the changed tiles
|
||||
/// Flood fill the map with the terrain fill_with
|
||||
/// starting from the location start_loc.
|
||||
/// If log is non-null it will contain the positions of the changed tiles
|
||||
/// and the terrains they had before the filling started.
|
||||
void flood_fill(gamemap &map, const gamemap::location &start_loc,
|
||||
const t_translation::t_letter fill_with, terrain_log *log = NULL);
|
||||
|
||||
/// Return the area that would be flood filled
|
||||
/// Return the area that would be flood filled
|
||||
/// if a flood fill was requested.
|
||||
std::set<gamemap::location>
|
||||
get_component(const gamemap &map, const gamemap::location &start_loc);
|
||||
|
@ -190,11 +190,11 @@ std::string resize_map(editormap &map, const unsigned new_w,
|
|||
const unsigned new_h, const int off_x, const int off_y,
|
||||
const bool do_expand, const t_translation::t_letter fill_with);
|
||||
|
||||
/// Return the string representation of the map
|
||||
/// Return the string representation of the map
|
||||
/// after it has been flipped around the axis.
|
||||
std::string flip_map(editormap &map, const FLIP_AXIS axis);
|
||||
|
||||
//! Return true if the data is valid to create a map with,
|
||||
//! Return true if the data is valid to create a map with,
|
||||
//! othwerwise false.
|
||||
bool valid_mapdata(const std::string &data, const config &cfg);
|
||||
|
||||
|
@ -203,7 +203,7 @@ bool valid_mapdata(const std::string &data, const config &cfg);
|
|||
//! of width by height of the terrain filler
|
||||
std::string new_map(const size_t width, const size_t height, const t_translation::t_letter filler);
|
||||
|
||||
} // end namespace map_editor
|
||||
} // end namespace map_editor
|
||||
|
||||
|
||||
#endif // MAP_MANIP_H_INCLUDED
|
||||
|
|
|
@ -255,7 +255,7 @@ bool has_focus(const handler* hand, const SDL_Event* event)
|
|||
handler *const thief_hand = event_contexts.back().handlers[i];
|
||||
if(i != foc_i && thief_hand->requires_event_focus(event)) {
|
||||
//steal focus
|
||||
focus_handler(thief_hand);
|
||||
focus_handler(thief_hand);
|
||||
if(foc_i < back_i) {
|
||||
//position the previously focused handler to allow stealing back
|
||||
event_contexts.back().delete_handler_index(foc_i);
|
||||
|
@ -473,7 +473,7 @@ int discard(Uint32 event_mask)
|
|||
}
|
||||
|
||||
//FIXME: there is a chance new events are added before kept events are replaced
|
||||
for (unsigned int i=0; i < keepers.size(); ++i)
|
||||
for (unsigned int i=0; i < keepers.size(); ++i)
|
||||
{
|
||||
if(SDL_PushEvent(&keepers[i]) != 0) {
|
||||
ERR_GEN << "failed to return an event to the queue.";
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace dialogs
|
|||
class file_dialog : public gui::dialog {
|
||||
public:
|
||||
file_dialog(display &disp, const std::string& file_path, const std::string& title);
|
||||
|
||||
|
||||
virtual gui::dialog::dimension_measurements layout(int xloc=-1, int yloc=-1);
|
||||
|
||||
/// Return the chosen file.
|
||||
|
|
|
@ -183,7 +183,7 @@ void file_dialog::action(gui::dialog_process_info &dp_info) {
|
|||
}
|
||||
|
||||
//update the chosen file
|
||||
if(dp_info.selection != last_selection_
|
||||
if(dp_info.selection != last_selection_
|
||||
|| dp_info.first_time
|
||||
|| dp_info.double_clicked)
|
||||
{
|
||||
|
|
|
@ -240,7 +240,7 @@ namespace {
|
|||
|
||||
#ifndef S_IFMT
|
||||
#define S_IFMT (S_IFDIR|S_IFREG)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef S_ISREG
|
||||
#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
@ -300,13 +300,13 @@ namespace {
|
|||
#include <CoreFoundation/CFBase.h>
|
||||
#endif
|
||||
|
||||
static bool ends_with(const std::string& str, const std::string& suffix)
|
||||
static bool ends_with(const std::string& str, const std::string& suffix)
|
||||
{
|
||||
return str.size() >= suffix.size() && std::equal(suffix.begin(),suffix.end(),str.end()-suffix.size());
|
||||
}
|
||||
|
||||
// These are the filenames that get special processing
|
||||
#define MAINCFG "_main.cfg"
|
||||
#define MAINCFG "_main.cfg"
|
||||
#define FINALCFG "_final.cfg"
|
||||
|
||||
void get_files_in_dir(const std::string& directory,
|
||||
|
@ -369,10 +369,10 @@ void get_files_in_dir(const std::string& directory,
|
|||
characters. Try to get the precomposed form.
|
||||
*/
|
||||
char basename[MAXNAMLEN+1];
|
||||
CFStringRef cstr = CFStringCreateWithCString(NULL,
|
||||
CFStringRef cstr = CFStringCreateWithCString(NULL,
|
||||
entry->d_name,
|
||||
kCFStringEncodingUTF8);
|
||||
CFMutableStringRef mut_str = CFStringCreateMutableCopy(NULL,
|
||||
CFMutableStringRef mut_str = CFStringCreateMutableCopy(NULL,
|
||||
0, cstr);
|
||||
CFStringNormalize(mut_str, kCFStringNormalizationFormC);
|
||||
CFStringGetCString(mut_str,
|
||||
|
@ -404,8 +404,8 @@ void get_files_in_dir(const std::string& directory,
|
|||
files->push_back(basename);
|
||||
}
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
if (reorder == DO_REORDER &&
|
||||
::stat((fullname+"/"+MAINCFG).c_str(), &st)!=-1 &&
|
||||
if (reorder == DO_REORDER &&
|
||||
::stat((fullname+"/"+MAINCFG).c_str(), &st)!=-1 &&
|
||||
S_ISREG(st.st_mode)) {
|
||||
LOG_FS << "_main.cfg found : ";
|
||||
if (files != NULL) {
|
||||
|
@ -415,9 +415,9 @@ void get_files_in_dir(const std::string& directory,
|
|||
} else {
|
||||
files->push_back(std::string(basename) + "/" + MAINCFG);
|
||||
LOG_FS << std::string(basename) << "/" << MAINCFG << '\n';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// show what I consider strange
|
||||
// show what I consider strange
|
||||
LOG_FS << fullname << "/" << MAINCFG << " not used now but skip the directory \n";
|
||||
}
|
||||
} else if (dirs != NULL) {
|
||||
|
|
|
@ -129,7 +129,7 @@ namespace gui{
|
|||
semiword.assign(text,last_space+1,text.size());
|
||||
}
|
||||
|
||||
std::set<std::string> matches;
|
||||
std::set<std::string> matches;
|
||||
std::string best_match = semiword;
|
||||
|
||||
for(size_t n = 0; n != teams.size(); ++n) {
|
||||
|
@ -154,7 +154,7 @@ namespace gui{
|
|||
matches.insert(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Searching in observers list
|
||||
const std::set<std::string>& observers = gui.observers();
|
||||
for(std::set<std::string>::const_iterator i = observers.begin(); i != observers.end(); ++i) {
|
||||
|
|
30
src/font.cpp
30
src/font.cpp
|
@ -534,16 +534,16 @@ private:
|
|||
text_cache::text_list text_cache::cache_;
|
||||
unsigned int text_cache::max_size_ = 50;
|
||||
|
||||
void text_cache::resize(unsigned int size)
|
||||
void text_cache::resize(unsigned int size)
|
||||
{
|
||||
LOG_FT << "Text cache: resize from: " << max_size_ << " to: "
|
||||
LOG_FT << "Text cache: resize from: " << max_size_ << " to: "
|
||||
<< size << " items in cache: " << cache_.size() << '\n';
|
||||
|
||||
while(size < cache_.size()) {
|
||||
cache_.pop_back();
|
||||
}
|
||||
max_size_ = size;
|
||||
}
|
||||
|
||||
while(size < cache_.size()) {
|
||||
cache_.pop_back();
|
||||
}
|
||||
max_size_ = size;
|
||||
}
|
||||
|
||||
|
||||
text_surface &text_cache::find(text_surface const &t)
|
||||
|
@ -1161,14 +1161,14 @@ bool load_font_config()
|
|||
return true;
|
||||
}
|
||||
|
||||
void cache_mode(CACHE mode)
|
||||
void cache_mode(CACHE mode)
|
||||
{
|
||||
if(mode == CACHE_LOBBY) {
|
||||
text_cache::resize(1000);
|
||||
} else {
|
||||
text_cache::resize(50);
|
||||
}
|
||||
}
|
||||
if(mode == CACHE_LOBBY) {
|
||||
text_cache::resize(1000);
|
||||
} else {
|
||||
text_cache::resize(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -152,8 +152,8 @@ void undraw_floating_labels(surface screen);
|
|||
|
||||
bool load_font_config();
|
||||
|
||||
enum CACHE { CACHE_LOBBY, CACHE_GAME };
|
||||
void cache_mode(CACHE mode);
|
||||
enum CACHE { CACHE_LOBBY, CACHE_GAME };
|
||||
void cache_mode(CACHE mode);
|
||||
|
||||
}
|
||||
|
||||
|
|
26
src/game.cpp
26
src/game.cpp
|
@ -692,19 +692,19 @@ bool game_controller::load_game()
|
|||
}
|
||||
|
||||
const std::vector<std::string> campaign_xtra_defines = utils::split(cfg["campaign_extra_defines"]);
|
||||
|
||||
|
||||
for(std::vector<std::string>::const_iterator i = campaign_xtra_defines.begin(); i != campaign_xtra_defines.end(); ++i) {
|
||||
defines_map_[*i] = preproc_define();
|
||||
}
|
||||
|
||||
|
||||
refresh_game_cfg();
|
||||
|
||||
state_ = game_state(units_data_,cfg);
|
||||
|
||||
if(state_.version != game_config::version) {
|
||||
// do not load if too old, if either the savegame or the current game
|
||||
// do not load if too old, if either the savegame or the current game
|
||||
// has the version 'test' allow loading
|
||||
if(state_.version < game_config::min_savegame_version &&
|
||||
if(state_.version < game_config::min_savegame_version &&
|
||||
game_config::test_version.full != state_.version &&
|
||||
game_config::test_version.full != game_config::version) {
|
||||
|
||||
|
@ -884,7 +884,7 @@ static std::string format_file_size(const std::string& size_str)
|
|||
|
||||
std::ostringstream stream;
|
||||
#ifdef _MSC_VER
|
||||
// Visual C++ makes 'precision' set the number of decimal places.
|
||||
// Visual C++ makes 'precision' set the number of decimal places.
|
||||
// Other platforms make it set the number of significant figures
|
||||
stream.precision(1);
|
||||
stream << std::fixed << size << size_postfix;
|
||||
|
@ -949,17 +949,17 @@ namespace
|
|||
{
|
||||
gui::show_error_message(disp(), _("You have no Add-ons installed."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(1);
|
||||
|
||||
|
||||
int index = 0;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
gui::dialog addon_dialog(disp(),
|
||||
gui::dialog addon_dialog(disp(),
|
||||
_("Remove Add-ons"), _("Choose the add-on to remove."),
|
||||
gui::OK_CANCEL);
|
||||
gui::menu::imgsel_style &addon_style = gui::menu::bluebg_style;
|
||||
|
@ -1147,7 +1147,7 @@ void game_controller::download_campaigns(std::string host)
|
|||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(1).set_alpha_sort(2).set_alpha_sort(3).set_numeric_sort(4).set_position_sort(5,sizes);
|
||||
|
||||
gui::dialog addon_dialog(disp(), _("Get Add-ons"),
|
||||
gui::dialog addon_dialog(disp(), _("Get Add-ons"),
|
||||
_("Choose the add-on to download."),
|
||||
gui::OK_CANCEL);
|
||||
gui::menu::imgsel_style addon_style(gui::menu::bluebg_style);
|
||||
|
@ -1190,11 +1190,11 @@ void game_controller::download_campaigns(std::string host)
|
|||
// TODO: Somehow offer to automatically download
|
||||
// the missing dependencies.
|
||||
if (!missing.empty()) {
|
||||
if (gui::dialog(disp(),
|
||||
if (gui::dialog(disp(),
|
||||
_("Dependencies"),
|
||||
std::string(_("This add-on requires the following additional dependencies:")) +
|
||||
"\n" + missing +
|
||||
"\n" + _("Do you still want to download it?"), gui::OK_CANCEL).show())
|
||||
"\n" + missing +
|
||||
"\n" + _("Do you still want to download it?"), gui::OK_CANCEL).show())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1704,7 +1704,7 @@ void game_controller::reset_game_cfg()
|
|||
#if defined(__APPLE__)
|
||||
defines_map_["APPLE"] = preproc_define();
|
||||
#endif
|
||||
|
||||
|
||||
if(multiplayer_mode_) {
|
||||
defines_map_["MULTIPLAYER"] = preproc_define();
|
||||
} else {
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace game_config
|
|||
std::string ally_ball_image = "misc/ball-ally.png";
|
||||
std::string flag_image = "flags/flag-1.png:150,flags/flag-2.png:150,flags/flag-3.png:150,flags/flag-4.png:150";
|
||||
std::string flag_icon_image = "flags/flag_icon.png";
|
||||
std::string flag_rgb = "flag_green";
|
||||
std::string flag_rgb = "flag_green";
|
||||
std::vector<Uint32> defense_color_scale;
|
||||
|
||||
std::string cross_image = "misc/cross.png";
|
||||
|
@ -79,11 +79,11 @@ namespace game_config
|
|||
|
||||
std::map<std::string, color_range > team_rgb_range;
|
||||
std::map<std::string, t_string > team_rgb_name;
|
||||
|
||||
|
||||
std::map<std::string, std::vector<Uint32> > team_rgb_colors;
|
||||
|
||||
const struct game_version wesnoth_version(VERSION);
|
||||
const struct game_version min_savegame_version(MIN_SAVEGAME_VERSION);
|
||||
const struct game_version min_savegame_version(MIN_SAVEGAME_VERSION);
|
||||
const struct game_version test_version("test");
|
||||
|
||||
const std::string observer_team_name = "observer";
|
||||
|
@ -94,7 +94,7 @@ namespace game_config
|
|||
receive_message = "receive.wav",
|
||||
user_arrive = "arrive.wav",
|
||||
user_leave = "leave.wav";
|
||||
|
||||
|
||||
const std::string button_press = "button.wav",
|
||||
checkbox_release = "checkbox.wav",
|
||||
slider_adjust = "slider.wav",
|
||||
|
@ -191,26 +191,26 @@ namespace game_config
|
|||
server_list.push_back(sinf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const void add_color_info(const config& v){
|
||||
const config::child_list& team_colors = v.get_children("color_range");
|
||||
for(config::child_list::const_iterator teamC = team_colors.begin(); teamC != team_colors.end(); ++teamC) {
|
||||
if(!(**teamC)["id"].empty() && !(**teamC)["rgb"].empty()){
|
||||
std::string id = (**teamC)["id"];
|
||||
std::vector<Uint32> temp = string2rgb((**teamC)["rgb"]);
|
||||
team_rgb_range.insert(std::make_pair(id,color_range(temp)));
|
||||
team_rgb_name[id] = (**teamC)["name"];
|
||||
std::string id = (**teamC)["id"];
|
||||
std::vector<Uint32> temp = string2rgb((**teamC)["rgb"]);
|
||||
team_rgb_range.insert(std::make_pair(id,color_range(temp)));
|
||||
team_rgb_name[id] = (**teamC)["name"];
|
||||
//generate palette of same name;
|
||||
std::vector<Uint32> tp = palette(team_rgb_range[id]);
|
||||
if(tp.size()){
|
||||
team_rgb_colors.insert(std::make_pair(id,tp));
|
||||
//if this is being used, output log of palette for artists use.
|
||||
LOG_NG << "color palette creation:\n";
|
||||
LOG_NG << "color palette creation:\n";
|
||||
std::stringstream str;
|
||||
str << id <<" = ";
|
||||
for(std::vector<Uint32>::const_iterator r=tp.begin();r!=tp.end();r++){
|
||||
int red = ((*r) & 0x00FF0000)>>16;
|
||||
int green = ((*r) & 0x0000FF00)>>8;
|
||||
int green = ((*r) & 0x0000FF00)>>8;
|
||||
int blue = ((*r) & 0x000000FF);
|
||||
if(r!=tp.begin()) {
|
||||
str<<",";
|
||||
|
@ -220,13 +220,13 @@ namespace game_config
|
|||
LOG_NG << str.str() <<"\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const config::child_list& colors = v.get_children("color_palette");
|
||||
for(config::child_list::const_iterator cp = colors.begin(); cp != colors.end(); ++cp) {
|
||||
for(string_map::const_iterator rgb_it = (*cp)->values.begin(); rgb_it != (*cp)->values.end(); ++rgb_it) {
|
||||
try {
|
||||
team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
|
||||
team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
|
||||
} catch(bad_lexical_cast&) {
|
||||
//throw config::error(_("Invalid team color: ") + rgb_it->second);
|
||||
ERR_NG << "Invalid team color: " << rgb_it->second;
|
||||
|
@ -234,7 +234,7 @@ namespace game_config
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const color_range& color_info(const std::string& name)
|
||||
{
|
||||
std::map<std::string, color_range>::const_iterator i = team_rgb_range.find(name);
|
||||
|
@ -268,8 +268,8 @@ namespace game_config
|
|||
return i->second;
|
||||
}
|
||||
|
||||
game_version::game_version(std::string str) :
|
||||
major_nr(0), minor_nr(0), patch(0), full(str)
|
||||
game_version::game_version(std::string str) :
|
||||
major_nr(0), minor_nr(0), patch(0), full(str)
|
||||
{
|
||||
|
||||
size_t offset = str.find_first_not_of("0123456789");
|
||||
|
|
|
@ -73,17 +73,17 @@ namespace game_config
|
|||
extern const std::string button_press, checkbox_release, slider_adjust,
|
||||
menu_expand, menu_contract, menu_select;
|
||||
}
|
||||
|
||||
|
||||
void load_config(const config* cfg);
|
||||
|
||||
|
||||
const void add_color_info(const config& v);
|
||||
const std::vector<Uint32>& tc_info(const std::string& name);
|
||||
const color_range& color_info(const std::string& name);
|
||||
|
||||
struct game_version {
|
||||
game_version(std::string str);
|
||||
|
||||
//Note gcc 4.1.2(prerelease) as shipped in Debian etch doesn't
|
||||
|
||||
//Note gcc 4.1.2(prerelease) as shipped in Debian etch doesn't
|
||||
//like the name major and minor :( so make gcc happy
|
||||
unsigned int major_nr;
|
||||
unsigned int minor_nr;
|
||||
|
@ -95,10 +95,10 @@ namespace game_config
|
|||
|
||||
// Note the < <= > and >= operator ignore the extra version the == and != do
|
||||
// use the extra version.
|
||||
bool operator<(const struct game_version& a, const struct game_version& b);
|
||||
bool operator<=(const struct game_version& a, const struct game_version& b);
|
||||
bool operator>(const struct game_version& a, const struct game_version& b);
|
||||
bool operator>=(const struct game_version& a, const struct game_version& b);
|
||||
bool operator<(const struct game_version& a, const struct game_version& b);
|
||||
bool operator<=(const struct game_version& a, const struct game_version& b);
|
||||
bool operator>(const struct game_version& a, const struct game_version& b);
|
||||
bool operator>=(const struct game_version& a, const struct game_version& b);
|
||||
bool operator==(const struct game_version& a, const struct game_version& b);
|
||||
bool operator!=(const struct game_version& a, const struct game_version& b);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file game_display.cpp
|
||||
//! @file game_display.cpp
|
||||
//! During a game, show map & info-panels at top+right.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -66,7 +66,7 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
invalidateUnit_(true),
|
||||
currentTeam_(0), activeTeam_(0),
|
||||
sidebarScaling_(1.0),
|
||||
first_turn_(true), in_game_(false),
|
||||
first_turn_(true), in_game_(false),
|
||||
tod_hex_mask1(NULL), tod_hex_mask2(NULL), reach_map_changed_(true)
|
||||
{
|
||||
singleton_ = this;
|
||||
|
@ -216,7 +216,7 @@ void game_display::scroll_to_leader(unit_map& units, int side)
|
|||
const unit_map::iterator leader = find_leader(units,side);
|
||||
|
||||
if(leader != units_.end()) {
|
||||
// YogiHH: I can't see why we need another key_handler here,
|
||||
// YogiHH: I can't see why we need another key_handler here,
|
||||
// therefore I will comment it out :
|
||||
/*
|
||||
const hotkey::basic_handler key_events_handler(gui_);
|
||||
|
@ -239,8 +239,8 @@ void game_display::draw(bool update,bool force)
|
|||
|
||||
process_reachmap_changes();
|
||||
|
||||
//! @todo FIXME: must modify changed, but best to do it
|
||||
//! at the floating_label level
|
||||
//! @todo FIXME: must modify changed, but best to do it
|
||||
//! at the floating_label level
|
||||
prune_chat_messages();
|
||||
|
||||
if(map_.empty()) {
|
||||
|
@ -262,7 +262,7 @@ void game_display::draw(bool update,bool force)
|
|||
map_.get_terrain_info(t_translation::VOID_TERRAIN).minimap_image() + ".png";
|
||||
const std::string fog_image = "terrain/" +
|
||||
map_.get_terrain_info(t_translation::FOGGED).minimap_image() + ".png";
|
||||
|
||||
|
||||
SDL_Rect clip_rect = map_area();
|
||||
surface const dst(screen_.getSurface());
|
||||
clip_rect_setter set_clip_rect(dst, clip_rect);
|
||||
|
@ -282,21 +282,21 @@ void game_display::draw(bool update,bool force)
|
|||
continue;
|
||||
}
|
||||
|
||||
// If the terrain is off the map,
|
||||
// it shouldn't be included for reachmap,
|
||||
// fog, shroud and the grid.
|
||||
// In the future it may not depend on
|
||||
// whether the location is on the map,
|
||||
// but whether it's an _off^* terrain.
|
||||
// (atm not too happy with how the grid looks)
|
||||
// (the shroud has some glitches due to
|
||||
// If the terrain is off the map,
|
||||
// it shouldn't be included for reachmap,
|
||||
// fog, shroud and the grid.
|
||||
// In the future it may not depend on
|
||||
// whether the location is on the map,
|
||||
// but whether it's an _off^* terrain.
|
||||
// (atm not too happy with how the grid looks)
|
||||
// (the shroud has some glitches due to
|
||||
// commented out code, but enabling it looks worse).
|
||||
const bool on_map = map_.on_board(*it);
|
||||
const bool is_shrouded = shrouded(*it);
|
||||
|
||||
image::TYPE image_type = image::SCALED_TO_HEX;
|
||||
|
||||
// We highlight hex under the mouse,
|
||||
// We highlight hex under the mouse,
|
||||
// origin of attack or under a selected unit.
|
||||
if (on_map && (*it == mouseoverHex_ || *it == attack_indicator_src_)) {
|
||||
image_type = image::BRIGHTENED;
|
||||
|
@ -347,7 +347,7 @@ void game_display::draw(bool update,bool force)
|
|||
tile_stack_append(image::get_image(tod_hex_mask,image::UNMASKED));
|
||||
}
|
||||
|
||||
// Draw the grid, if that's been enabled
|
||||
// Draw the grid, if that's been enabled
|
||||
if(grid_ && !is_shrouded) {
|
||||
tile_stack_append(image::get_image(game_config::grid_image, image::SCALED_TO_HEX));
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ void game_display::draw(bool update,bool force)
|
|||
|
||||
// Apply shroud and fog
|
||||
if(is_shrouded) {
|
||||
// We apply void also on off-map tiles
|
||||
// We apply void also on off-map tiles
|
||||
// to shroud the half-hexes too
|
||||
tile_stack_append(image::get_image(shroud_image, image::SCALED_TO_HEX));
|
||||
} else if(fogged(*it)) {
|
||||
|
@ -408,14 +408,14 @@ void game_display::draw(bool update,bool force)
|
|||
draw_movement_info(*it);
|
||||
}
|
||||
//simulate_delay += 1;
|
||||
|
||||
|
||||
// If the tile is at the border, we start to blend it
|
||||
if(!on_map && map_.get_terrain(*it) != t_translation::OFF_MAP_USER) {
|
||||
draw_border(*it, xpos, ypos);
|
||||
}
|
||||
}
|
||||
|
||||
// Units can overlap multiple hexes, so we need
|
||||
// Units can overlap multiple hexes, so we need
|
||||
// to redraw them last and in the good sequence.
|
||||
std::set<gamemap::location, struct display::ordered_draw>::const_iterator it2;
|
||||
for(it2 = unit_invals.begin(); it2 != unit_invals.end(); ++it2) {
|
||||
|
@ -438,7 +438,7 @@ void game_display::draw(bool update,bool force)
|
|||
|
||||
draw_sidebar();
|
||||
//! @todo FIXME: This changed can probably be smarter
|
||||
changed = true;
|
||||
changed = true;
|
||||
|
||||
// Simulate slow PC:
|
||||
//SDL_Delay(2*simulate_delay + rand() % 20);
|
||||
|
@ -464,7 +464,7 @@ void game_display::draw_report(reports::TYPE report_num)
|
|||
if(report_num == reports::TIME_OF_DAY) {
|
||||
time_of_day tod = timeofday_at(status_,units_,mouseoverHex_,map_);
|
||||
// Don't show illuminated time on fogged/shrouded tiles
|
||||
if (teams_[viewing_team()].fogged(mouseoverHex_.x, mouseoverHex_.y) ||
|
||||
if (teams_[viewing_team()].fogged(mouseoverHex_.x, mouseoverHex_.y) ||
|
||||
teams_[viewing_team()].shrouded(mouseoverHex_.x, mouseoverHex_.y)) {
|
||||
|
||||
tod = status_.get_time_of_day(false,mouseoverHex_);
|
||||
|
@ -558,7 +558,7 @@ void game_display::draw_bar(const std::string& image, int xpos, int ypos, size_t
|
|||
surface surf(image::get_image(image,image::UNMASKED));
|
||||
|
||||
// We use UNSCALED because scaling (and bilinear interpolaion)
|
||||
// is bad for calculate_energy_bar.
|
||||
// is bad for calculate_energy_bar.
|
||||
// But we will do a geometric scaling later.
|
||||
surface bar_surf(image::get_image(image));
|
||||
if(surf == NULL || bar_surf == NULL) {
|
||||
|
@ -680,9 +680,9 @@ std::vector<surface> game_display::footsteps_images(const gamemap::location& loc
|
|||
int image_number = minimum<int>(move_cost, game_config::foot_speed_prefix.size());
|
||||
if (image_number < 1) {
|
||||
return res; // Invalid movement cost or no images
|
||||
}
|
||||
}
|
||||
const std::string foot_speed_prefix = game_config::foot_speed_prefix[image_number-1];
|
||||
|
||||
|
||||
// We draw 2 half-hex (with possibly different directions),
|
||||
// but skip the first for the first step.
|
||||
const int first_half = (i == route_.steps.begin()) ? 1 : 0;
|
||||
|
@ -930,7 +930,7 @@ void game_display::invalidate_animations()
|
|||
gamemap::location topleft;
|
||||
gamemap::location bottomright;
|
||||
get_visible_hex_bounds(topleft, bottomright);
|
||||
|
||||
|
||||
for(int x = topleft.x; x <= bottomright.x; ++x) {
|
||||
for(int y = topleft.y; y <= bottomright.y; ++y) {
|
||||
const gamemap::location loc(x,y);
|
||||
|
@ -1004,7 +1004,7 @@ void game_display::clear_attack_indicator()
|
|||
|
||||
void game_display::add_overlay(const gamemap::location& loc, const std::string& img, const std::string& halo)
|
||||
{
|
||||
const int halo_handle = halo::add(get_location_x(loc) + hex_size() / 2,
|
||||
const int halo_handle = halo::add(get_location_x(loc) + hex_size() / 2,
|
||||
get_location_y(loc) + hex_size() / 2, halo, loc);
|
||||
|
||||
const overlay item(img,halo,halo_handle);
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file game_display.hpp
|
||||
//!
|
||||
//! @file game_display.hpp
|
||||
//!
|
||||
|
||||
#ifndef GAME_DISPLAY_H_INCLUDED
|
||||
#define GAME_DISPLAY_H_INCLUDED
|
||||
|
@ -34,7 +34,7 @@ class unit_map;
|
|||
#include <string>
|
||||
|
||||
// This needs to be separate from display.h because of the static
|
||||
// singleton member, which will otherwise trigger link failure
|
||||
// singleton member, which will otherwise trigger link failure
|
||||
// when building the editor.
|
||||
|
||||
class game_display : public display
|
||||
|
@ -48,34 +48,34 @@ public:
|
|||
static game_display* get_singleton() { return singleton_ ;}
|
||||
|
||||
//! Update lighting settings.
|
||||
//! Should be called on every new turn,
|
||||
//! Should be called on every new turn,
|
||||
void new_turn();
|
||||
|
||||
//! Add r,g,b to the colours for all images displayed on the map.
|
||||
//! Add r,g,b to the colours for all images displayed on the map.
|
||||
//! Used for special effects like flashes.
|
||||
void adjust_colours(int r, int g, int b);
|
||||
|
||||
//! Scrolls to the leader of a certain side.
|
||||
//! Scrolls to the leader of a certain side.
|
||||
//! This will normally be the playing team.
|
||||
void scroll_to_leader(unit_map& units, int side);
|
||||
|
||||
//! Draw for the game display has to know about units
|
||||
//! Draw for the game display has to know about units
|
||||
void draw(bool update=true,bool force=false);
|
||||
|
||||
//! Function to display a location as selected.
|
||||
//! If a unit is in the location, and there is no unit
|
||||
//! in the currently highlighted hex,
|
||||
//! Function to display a location as selected.
|
||||
//! If a unit is in the location, and there is no unit
|
||||
//! in the currently highlighted hex,
|
||||
//! the unit will be displayed in the sidebar.
|
||||
virtual void select_hex(gamemap::location hex);
|
||||
|
||||
//! Function to highlight a location.
|
||||
//! If a unit is in the location, it will be displayed in the sidebar.
|
||||
//! Selection is used when a unit has been clicked on,
|
||||
//! Function to highlight a location.
|
||||
//! If a unit is in the location, it will be displayed in the sidebar.
|
||||
//! Selection is used when a unit has been clicked on,
|
||||
//! while highlighting is used when a location has been moused over.
|
||||
virtual void highlight_hex(gamemap::location hex);
|
||||
|
||||
//! Sets the paths that are currently displayed as available
|
||||
//! for the unit to move along.
|
||||
//! Sets the paths that are currently displayed as available
|
||||
//! for the unit to move along.
|
||||
//! All other paths will be greyed out.
|
||||
void highlight_reach(const paths &paths_list);
|
||||
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
//! Reset highlighting of paths.
|
||||
void unhighlight_reach();
|
||||
|
||||
//! Sets the route along which footsteps are drawn to show movement of a unit.
|
||||
//! Sets the route along which footsteps are drawn to show movement of a unit.
|
||||
//! If NULL, no route is displayed. route does not have to remain valid after being set.
|
||||
void set_route(const paths::route* route);
|
||||
|
||||
|
@ -133,9 +133,9 @@ public:
|
|||
{ return gamemap::location::write_direction(
|
||||
attack_indicator_src_.get_relative_dir(attack_indicator_dst_)); }
|
||||
|
||||
//! Functions to add and remove overlays from locations.
|
||||
//! An overlay is an image that is displayed on top of the tile.
|
||||
//! One tile may have multiple overlays.
|
||||
//! Functions to add and remove overlays from locations.
|
||||
//! An overlay is an image that is displayed on top of the tile.
|
||||
//! One tile may have multiple overlays.
|
||||
void add_overlay(const gamemap::location& loc, const std::string& image, const std::string& halo="");
|
||||
//! remove_overlay will remove all overlays on a tile.
|
||||
void remove_overlay(const gamemap::location& loc);
|
||||
|
@ -159,12 +159,12 @@ public:
|
|||
unit_map& get_units() {return units_;};
|
||||
const unit_map& get_const_units() const {return units_;};
|
||||
|
||||
//! Draws a cross on a tile to emphasize something there.
|
||||
//! Draws a cross on a tile to emphasize something there.
|
||||
//! It is used in debug mode, typically to show AI plans.
|
||||
static void debug_highlight(const gamemap::location& loc, fixed_t amount);
|
||||
static void clear_debug_highlights() { debugHighlights_.clear(); }
|
||||
|
||||
//! The viewing team is the team currently viewing the game.
|
||||
//! The viewing team is the team currently viewing the game.
|
||||
size_t viewing_team() const { return currentTeam_; }
|
||||
//! The playing team is the team whose turn it is.
|
||||
size_t playing_team() const { return activeTeam_; }
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file game_events.cpp
|
||||
//! @file game_events.cpp
|
||||
//! Processing of WML-events.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -100,17 +100,17 @@ public:
|
|||
#endif
|
||||
|
||||
/**
|
||||
* Shows a summary of the errors encountered in WML thusfar,
|
||||
* to avoid a lot of the same messages to be shown.
|
||||
* Shows a summary of the errors encountered in WML thusfar,
|
||||
* to avoid a lot of the same messages to be shown.
|
||||
* Identical messages are shown once, with (between braces)
|
||||
* the number of times that message was encountered.
|
||||
* The order in which the messages are shown does not need
|
||||
* the number of times that message was encountered.
|
||||
* The order in which the messages are shown does not need
|
||||
* to be the order in which these messages are encountered.
|
||||
* Messages are always written to std::cerr.
|
||||
*/
|
||||
static void show_wml_errors()
|
||||
{
|
||||
// Get all unique messages in messages,
|
||||
// Get all unique messages in messages,
|
||||
// with the number of encounters for these messages
|
||||
std::map<std::string, int> messages;
|
||||
while(true) {
|
||||
|
@ -120,8 +120,8 @@ static void show_wml_errors()
|
|||
if(lg::wml_error.eof()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(msg == "") {
|
||||
|
||||
if(msg == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -138,13 +138,13 @@ static void show_wml_errors()
|
|||
std::string caption = "Deprecated WML found";
|
||||
for(std::map<std::string, int>::const_iterator itor = messages.begin();
|
||||
itor != messages.end(); ++itor) {
|
||||
|
||||
std::stringstream msg;
|
||||
|
||||
std::stringstream msg;
|
||||
msg << itor->first;
|
||||
if(itor->second > 1) {
|
||||
msg << " (" << itor->second << ")";
|
||||
}
|
||||
|
||||
|
||||
screen->add_chat_message(caption, 0, msg.str(), game_display::MESSAGE_PUBLIC, false);
|
||||
std::cerr << caption << ": " << msg.str() << '\n';
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ bool internal_conditional_passed(const unit_map* units,
|
|||
const vconfig cond, bool& backwards_compat)
|
||||
{
|
||||
|
||||
// If the if statement requires we have a certain unit,
|
||||
// If the if statement requires we have a certain unit,
|
||||
// then check for that.
|
||||
const vconfig::child_list& have_unit = cond.get_children("have_unit");
|
||||
backwards_compat = backwards_compat && have_unit.empty();
|
||||
|
@ -185,7 +185,7 @@ bool internal_conditional_passed(const unit_map* units,
|
|||
}
|
||||
}
|
||||
|
||||
// If the if statement requires we have a certain location,
|
||||
// If the if statement requires we have a certain location,
|
||||
// then check for that.
|
||||
const vconfig::child_list& have_location = cond.get_children("have_location");
|
||||
backwards_compat = backwards_compat && have_location.empty();
|
||||
|
@ -198,7 +198,7 @@ bool internal_conditional_passed(const unit_map* units,
|
|||
}
|
||||
}
|
||||
|
||||
// Check against each variable statement,
|
||||
// Check against each variable statement,
|
||||
// to see if the variable matches the conditions or not.
|
||||
const vconfig::child_list& variables = cond.get_children("variable");
|
||||
backwards_compat = backwards_compat && variables.empty();
|
||||
|
@ -251,7 +251,7 @@ bool internal_conditional_passed(const unit_map* units,
|
|||
return false;
|
||||
}
|
||||
const std::string boolean_equals = values["boolean_equals"];
|
||||
if(values.get_attribute("boolean_equals") != ""
|
||||
if(values.get_attribute("boolean_equals") != ""
|
||||
&& (utils::string_bool(value) != utils::string_bool(boolean_equals))) {
|
||||
return false;
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ bool internal_conditional_passed(const unit_map* units,
|
|||
bool conditional_passed(const unit_map* units,
|
||||
const vconfig cond, bool backwards_compat)
|
||||
{
|
||||
bool allow_backwards_compat = backwards_compat = backwards_compat &&
|
||||
bool allow_backwards_compat = backwards_compat = backwards_compat &&
|
||||
utils::string_bool(cond["backwards_compat"],true);
|
||||
bool matches = internal_conditional_passed(units, cond, allow_backwards_compat);
|
||||
|
||||
|
@ -320,10 +320,10 @@ std::set<std::string> used_items;
|
|||
/*
|
||||
jhinrichs, 12.11.2006:
|
||||
This variable controls the maximum number of hexes in a map, that can be parsed by an event.
|
||||
It was set to 1024 before and for larger maps this could become a problem. So it is raised to
|
||||
It was set to 1024 before and for larger maps this could become a problem. So it is raised to
|
||||
65536 now, which can feature a map of size 256*256 (maps really shouldn't be bigger than that :-).
|
||||
This constant also controls the maximum number of loops for a WML while loop (hence its name).
|
||||
If this is felt to be too high now, we must split it into two constants,
|
||||
If this is felt to be too high now, we must split it into two constants,
|
||||
but i don't feel the need at the moment.
|
||||
*/
|
||||
const size_t MaxLoop = 65536;
|
||||
|
@ -514,7 +514,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
if(utils::string_bool(cfg["clear_shroud"],true)) {
|
||||
clear_shroud(*screen,*status_ptr,*game_map,*game_data_ptr,*units,*teams,side-1);
|
||||
}
|
||||
|
||||
|
||||
screen->invalidate(dst);
|
||||
screen->draw();
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
state_of_game->get_variable(var_name) = lexical_cast_default<std::string>(turns,"");
|
||||
}
|
||||
|
||||
// Moving a 'unit' - i.e. a dummy unit
|
||||
// Moving a 'unit' - i.e. a dummy unit
|
||||
// that is just moving for the visual effect
|
||||
else if(cmd == "move_unit_fake") {
|
||||
std::string type = cfg["type"];
|
||||
|
@ -857,8 +857,8 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
//
|
||||
// If side is set to 0, the new objectives are added to each player.
|
||||
//
|
||||
// The new objectives will be automatically displayed,
|
||||
// but only to the player whose objectives did change,
|
||||
// The new objectives will be automatically displayed,
|
||||
// but only to the player whose objectives did change,
|
||||
// and only when it's this player's turn.
|
||||
else if(cmd == "objectives") {
|
||||
const std::string win_str = "@";
|
||||
|
@ -939,7 +939,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
const std::string name = cfg["name"];
|
||||
t_string& var = state_of_game->get_variable(name);
|
||||
|
||||
const t_string& literal = cfg.get_attribute("literal"); // no $var substitution
|
||||
const t_string& literal = cfg.get_attribute("literal"); // no $var substitution
|
||||
if(literal.empty() == false) {
|
||||
var = literal;
|
||||
}
|
||||
|
@ -1137,7 +1137,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
std::vector<std::string> sides = utils::split(cfg["side"]);
|
||||
|
||||
// Iterate over all the types, and for each type,
|
||||
// Iterate over all the types, and for each type,
|
||||
// try to find a unit that matches
|
||||
std::vector<std::string>::iterator ti;
|
||||
for(ti = types.begin(); ti != types.end(); ++ti) {
|
||||
|
@ -1295,7 +1295,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
if(play_fogged.empty())
|
||||
soundsources->add(id, sounds, lexical_cast<int>(delay), lexical_cast<int>(chance));
|
||||
else
|
||||
soundsources->add(id, sounds, lexical_cast<int>(delay),
|
||||
soundsources->add(id, sounds, lexical_cast<int>(delay),
|
||||
lexical_cast<int>(chance), utils::string_bool(play_fogged));
|
||||
|
||||
for(unsigned int i = 0; i < minimum(vx.size(), vy.size()); ++i) {
|
||||
|
@ -1312,18 +1312,18 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
// Changing the terrain
|
||||
else if(cmd == "terrain") {
|
||||
const std::vector<gamemap::location> locs = multiple_locs(cfg);
|
||||
|
||||
|
||||
std::string terrain_type = cfg["letter"];
|
||||
wassert(state_of_game != NULL);
|
||||
|
||||
|
||||
t_translation::t_letter terrain = t_translation::read_letter(terrain_type);
|
||||
|
||||
if(terrain != t_translation::NONE_TERRAIN) {
|
||||
|
||||
|
||||
for(std::vector<gamemap::location>::const_iterator loc = locs.begin(); loc != locs.end(); ++loc) {
|
||||
preferences::encountered_terrains().insert(terrain);
|
||||
const bool old_village = game_map->is_village(*loc);
|
||||
const bool new_village = game_map->is_village(terrain);
|
||||
const bool new_village = game_map->is_village(terrain);
|
||||
|
||||
if(old_village && !new_village) {
|
||||
int owner = village_owner(*loc, *teams);
|
||||
|
@ -1332,7 +1332,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
}
|
||||
}
|
||||
|
||||
game_map->set_terrain(*loc,terrain);
|
||||
game_map->set_terrain(*loc,terrain);
|
||||
}
|
||||
rebuild_screen_ = true;
|
||||
}
|
||||
|
@ -1343,7 +1343,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
gamemap::location loc = cfg_to_loc(cfg, 1, 1);
|
||||
|
||||
gamemap mask(*game_map);
|
||||
|
||||
|
||||
try {
|
||||
mask.read(cfg["mask"]);
|
||||
} catch(gamemap::incorrect_format_exception&) {
|
||||
|
@ -1429,7 +1429,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
if(game_events::unit_matches_filter(*u, &unit_filter, gamemap::location())) {
|
||||
gamemap::location loc = cfg_to_loc(cfg);
|
||||
unit to_recruit(*u);
|
||||
avail.erase(u); // Erase before recruiting, since recruiting can fire more events
|
||||
avail.erase(u); // Erase before recruiting, since recruiting can fire more events
|
||||
unit_mutations++;
|
||||
recruit_unit(*game_map,index+1,*units,to_recruit,loc,utils::string_bool(cfg["show"],true),false,true);
|
||||
unit_recalled = true;
|
||||
|
@ -1543,7 +1543,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
0.0,0.0,lifetime,rect,font::CENTER_ALIGN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if(cmd == "deprecated_message") {
|
||||
// Note: no need to translate the string, since only used for deprecated things.
|
||||
const std::string message = cfg["message"];
|
||||
|
@ -1625,7 +1625,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
for(vconfig::child_list::const_iterator mi = menu_items.begin();
|
||||
mi != menu_items.end(); ++mi) {
|
||||
std::string msg_str = (*mi)["message"];
|
||||
if(!(*mi).has_child("show_if")
|
||||
if(!(*mi).has_child("show_if")
|
||||
|| game_events::conditional_passed(units,(*mi).child("show_if"))) {
|
||||
options.push_back(msg_str);
|
||||
option_events.push_back((*mi).get_children("command"));
|
||||
|
@ -1641,7 +1641,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
LOG_DP << "showing dialog...\n";
|
||||
|
||||
// If we're not replaying, or if we are replaying
|
||||
// If we're not replaying, or if we are replaying
|
||||
// and there is no choice to be made, show the dialog.
|
||||
if(get_replay_source().at_end() || options.empty()) {
|
||||
const t_string msg = cfg["message"];
|
||||
|
@ -1735,7 +1735,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
}
|
||||
}
|
||||
|
||||
// If the filter doesn't contain positional information,
|
||||
// If the filter doesn't contain positional information,
|
||||
// then it may match units on all recall lists.
|
||||
if(cfg["x"].empty() && cfg["y"].empty()) {
|
||||
std::map<std::string, player_info>& players=state_of_game->players;
|
||||
|
@ -1764,7 +1764,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
// Setting of menu items
|
||||
else if(cmd == "set_menu_item") {
|
||||
/*
|
||||
/*
|
||||
[set_menu_item]
|
||||
id=test1
|
||||
image="buttons/group_all.png"
|
||||
|
@ -1876,7 +1876,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
}
|
||||
varinfo.vars->append(to_store);
|
||||
}
|
||||
|
||||
|
||||
else if(cmd == "unstore_unit") {
|
||||
wassert(state_of_game != NULL);
|
||||
const config& var = state_of_game->get_variable_cfg(cfg["variable"]);
|
||||
|
@ -1965,7 +1965,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
* Keys:
|
||||
* - variable (mandatory): variable to store in
|
||||
* - side: if present, the village should be owned by this side (0=unowned villages)
|
||||
* - terrain: if present, filter the village types against this list of terrain types
|
||||
* - terrain: if present, filter the village types against this list of terrain types
|
||||
*/
|
||||
else if(cmd == "store_villages" ) {
|
||||
log_scope("store_villages");
|
||||
|
@ -1980,7 +1980,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
for(std::vector<gamemap::location>::const_iterator j = locs.begin(); j != locs.end(); ++j) {
|
||||
bool matches = false;
|
||||
if(cfg.has_attribute("side")) { // deprecated, use owner_side instead
|
||||
if(cfg.has_attribute("side")) { // deprecated, use owner_side instead
|
||||
lg::wml_error << "side key is no longer accepted in [store_villages],"
|
||||
<< " use owner_side instead.\n";
|
||||
config temp_cfg(cfg.get_config());
|
||||
|
@ -2023,7 +2023,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
std::string side = cfg["side"];
|
||||
wassert(state_of_game != NULL);
|
||||
const int side_num = lexical_cast_default<int>(side);
|
||||
// If 'side' is 0, then it will become an invalid index,
|
||||
// If 'side' is 0, then it will become an invalid index,
|
||||
// and so the village will become neutral.
|
||||
const size_t team_num = size_t(side_num-1);
|
||||
|
||||
|
@ -2083,7 +2083,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
unit_map::iterator u = units->find(event_info.loc1);
|
||||
|
||||
// Search for a valid unit filter,
|
||||
// Search for a valid unit filter,
|
||||
// and if we have one, look for the matching unit
|
||||
const vconfig filter = cfg.child("filter");
|
||||
if(!filter.null()) {
|
||||
|
@ -2111,11 +2111,11 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
events::pump();
|
||||
}
|
||||
} else if(cmd == "label") {
|
||||
|
||||
|
||||
terrain_label label(screen->labels(),
|
||||
cfg.get_config(),
|
||||
game_events::get_state_of_game());
|
||||
|
||||
|
||||
screen->labels().set_label(label.location(),
|
||||
label.text(),
|
||||
label.team_name(),
|
||||
|
@ -2149,7 +2149,7 @@ static void commit_wmi_commands() {
|
|||
if(!mref->command.empty()) {
|
||||
mref->command["name"] = mref->name;
|
||||
mref->command["first_time_only"] = "no";
|
||||
event_handler new_handler(mref->command);
|
||||
event_handler new_handler(mref->command);
|
||||
events_map.insert(std::pair<std::string,event_handler>(
|
||||
new_handler.name(), new_handler));
|
||||
}
|
||||
|
@ -2179,7 +2179,7 @@ bool event_handler::handle_event(const queued_event& event_info, const vconfig c
|
|||
|
||||
const std::pair<const std::string*,const config*> item = *i;
|
||||
|
||||
// If the user pressed escape, we skip any message
|
||||
// If the user pressed escape, we skip any message
|
||||
// that doesn't require them to make a choice.
|
||||
if ((skip_messages) && (*item.first == "message")) {
|
||||
if ((item.second)->get_children("option").size() == 0) {
|
||||
|
@ -2303,7 +2303,7 @@ namespace game_events {
|
|||
|
||||
bool matches_special_filter(const config* cfg, const vconfig filter)
|
||||
{
|
||||
//! @todo FIXME: This filter should be deprecated and removed,
|
||||
//! @todo FIXME: This filter should be deprecated and removed,
|
||||
// instead we should just auto-store $attacker_weapon and check it in a conditional
|
||||
|
||||
if(!cfg) {
|
||||
|
@ -2399,7 +2399,7 @@ manager::manager(const config& cfg, game_display& gui_, gamemap& map_,
|
|||
std::map<std::string, wml_menu_item *>::iterator itor = state_of_game->wml_menu_items.begin();
|
||||
while(itor != state_of_game->wml_menu_items.end()) {
|
||||
if(!itor->second->command.empty()) {
|
||||
event_handler new_handler(itor->second->command);
|
||||
event_handler new_handler(itor->second->command);
|
||||
events_map.insert(std::pair<std::string,event_handler>(
|
||||
new_handler.name(), new_handler));
|
||||
}
|
||||
|
@ -2500,7 +2500,7 @@ bool pump()
|
|||
|
||||
while(events_queue.empty() == false) {
|
||||
queued_event ev = events_queue.front();
|
||||
events_queue.pop_front(); // pop now for exception safety
|
||||
events_queue.pop_front(); // pop now for exception safety
|
||||
const std::string& event_name = ev.name;
|
||||
typedef std::multimap<std::string,event_handler>::iterator itor;
|
||||
|
||||
|
@ -2555,17 +2555,17 @@ entity_location::entity_location(gamemap::location loc, const std::string& id)
|
|||
: location(loc), id_(id)
|
||||
{}
|
||||
|
||||
entity_location::entity_location(unit_map::iterator itor)
|
||||
entity_location::entity_location(unit_map::iterator itor)
|
||||
: location(itor->first), id_(itor->second.underlying_description())
|
||||
{}
|
||||
|
||||
bool entity_location::matches_unit(const unit& u) const
|
||||
{
|
||||
{
|
||||
return id_ == u.underlying_description();
|
||||
}
|
||||
|
||||
bool entity_location::requires_unit() const
|
||||
{
|
||||
{
|
||||
return !id_.empty();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,27 +31,27 @@ class game_state;
|
|||
#include <map>
|
||||
|
||||
|
||||
//! @file game_events.hpp
|
||||
//! Define the game's events mechanism.
|
||||
//! @file game_events.hpp
|
||||
//! Define the game's events mechanism.
|
||||
//
|
||||
// Events might be units moving or fighting, or when victory or defeat occurs.
|
||||
// A scenario's configuration file will define actions to take when certain events occur.
|
||||
// Events might be units moving or fighting, or when victory or defeat occurs.
|
||||
// A scenario's configuration file will define actions to take when certain events occur.
|
||||
// This module is responsible for making sure that when the events occur, the actions take place.
|
||||
//
|
||||
// Note that game events have nothing to do with SDL events,
|
||||
// like mouse movement, keyboard events, etc.
|
||||
// Note that game events have nothing to do with SDL events,
|
||||
// like mouse movement, keyboard events, etc.
|
||||
// See events.hpp for how they are handled.
|
||||
|
||||
namespace game_events
|
||||
{
|
||||
// The game event manager loads the scenario configuration object,
|
||||
// and ensures that events are handled according to the
|
||||
// The game event manager loads the scenario configuration object,
|
||||
// and ensures that events are handled according to the
|
||||
// scenario configuration for its lifetime.
|
||||
//
|
||||
// Thus, a manager object should be created when a scenario is played,
|
||||
// Thus, a manager object should be created when a scenario is played,
|
||||
// and destroyed at the end of the scenario.
|
||||
struct manager {
|
||||
// Note that references will be maintained,
|
||||
// Note that references will be maintained,
|
||||
// and must remain valid for the life of the object.
|
||||
manager(const config& scenario_cfg, game_display& disp, gamemap& map,
|
||||
soundsource::manager& sndsources, unit_map& units, std::vector<team>& teams,
|
||||
|
@ -76,7 +76,7 @@ void add_events(const config::child_list& cfgs,const std::string& id);
|
|||
|
||||
bool unit_matches_filter(unit_map::const_iterator itor, const vconfig filter);
|
||||
|
||||
//! Function to fire an event.
|
||||
//! Function to fire an event.
|
||||
// Events may have up to two arguments, both of which must be locations.
|
||||
bool fire(const std::string& event,
|
||||
const entity_location& loc1=gamemap::location::null_location,
|
||||
|
|
|
@ -69,7 +69,7 @@ manager::manager()
|
|||
|
||||
const t_translation::t_list terrain =
|
||||
t_translation::read_list(preferences::get("encountered_terrain_list"));
|
||||
std::copy(terrain.begin(), terrain.end(),
|
||||
std::copy(terrain.begin(), terrain.end(),
|
||||
std::inserter(encountered_terrains_set, encountered_terrains_set.begin()));
|
||||
}
|
||||
|
||||
|
|
|
@ -99,29 +99,29 @@ private:
|
|||
void set_friends_menu();
|
||||
std::vector<std::string> friends_names_;
|
||||
|
||||
//
|
||||
//
|
||||
// change
|
||||
gui::slider music_slider_, sound_slider_, UI_sound_slider_, bell_slider_, scroll_slider_,
|
||||
gamma_slider_, chat_lines_slider_, buffer_size_slider_;
|
||||
gui::list_slider<double> turbo_slider_;
|
||||
gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
|
||||
show_grid_button_, save_replays_button_, delete_autosaves_button_,
|
||||
show_lobby_joins_button1_,
|
||||
show_lobby_joins_button2_,
|
||||
show_lobby_joins_button3_,
|
||||
sort_list_by_group_button_, iconize_list_button_,
|
||||
friends_list_button_, friends_back_button_,
|
||||
gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_,
|
||||
show_grid_button_, save_replays_button_, delete_autosaves_button_,
|
||||
show_lobby_joins_button1_,
|
||||
show_lobby_joins_button2_,
|
||||
show_lobby_joins_button3_,
|
||||
sort_list_by_group_button_, iconize_list_button_,
|
||||
friends_list_button_, friends_back_button_,
|
||||
friends_add_friend_button_, friends_add_ignore_button_,
|
||||
friends_remove_button_, show_floating_labels_button_,
|
||||
turn_dialog_button_, turn_bell_button_,
|
||||
friends_remove_button_, show_floating_labels_button_,
|
||||
turn_dialog_button_, turn_bell_button_,
|
||||
show_team_colours_button_, show_colour_cursors_button_,
|
||||
show_haloing_button_, video_mode_button_,
|
||||
show_haloing_button_, video_mode_button_,
|
||||
theme_button_, hotkeys_button_, gamma_button_,
|
||||
flip_time_button_, advanced_button_, sound_button_,
|
||||
flip_time_button_, advanced_button_, sound_button_,
|
||||
music_button_, chat_timestamp_button_,
|
||||
advanced_sound_button_, normal_sound_button_,
|
||||
UI_sound_button_, sample_rate_button1_,
|
||||
sample_rate_button2_, sample_rate_button3_,
|
||||
advanced_sound_button_, normal_sound_button_,
|
||||
UI_sound_button_, sample_rate_button1_,
|
||||
sample_rate_button2_, sample_rate_button3_,
|
||||
confirm_sound_button_;
|
||||
gui::label music_label_, sound_label_, UI_sound_label_, bell_label_, scroll_label_,
|
||||
gamma_label_, chat_lines_label_, turbo_slider_label_,
|
||||
|
@ -149,7 +149,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
|
|||
music_slider_(disp.video()), sound_slider_(disp.video()), UI_sound_slider_(disp.video()),
|
||||
bell_slider_(disp.video()),
|
||||
scroll_slider_(disp.video()), gamma_slider_(disp.video()), chat_lines_slider_(disp.video()),
|
||||
buffer_size_slider_(disp.video()), turbo_slider_(disp.video()),
|
||||
buffer_size_slider_(disp.video()), turbo_slider_(disp.video()),
|
||||
|
||||
fullscreen_button_(disp.video(), _("Toggle Full Screen"), gui::button::TYPE_CHECK),
|
||||
turbo_button_(disp.video(), _("Accelerated Speed"), gui::button::TYPE_CHECK),
|
||||
|
@ -203,7 +203,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
|
|||
slider_label_width_(0),
|
||||
advanced_(disp.video(),std::vector<std::string>(),false,-1,-1,NULL,&gui::menu::bluebg_style),
|
||||
friends_(disp.video(),std::vector<std::string>(),false,-1,-1,NULL,&gui::menu::bluebg_style),
|
||||
|
||||
|
||||
advanced_selection_(-1),
|
||||
friends_selection_(-1),
|
||||
|
||||
|
@ -296,8 +296,8 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
|
|||
|
||||
turbo_button_.set_check(turbo());
|
||||
turbo_button_.set_help_string(_("Make units move and fight faster"));
|
||||
|
||||
//0.25 0.5 1 2 4 8 16
|
||||
|
||||
//0.25 0.5 1 2 4 8 16
|
||||
std::vector< double > turbo_items;
|
||||
turbo_items.push_back(0.25);
|
||||
turbo_items.push_back(0.5);
|
||||
|
@ -335,7 +335,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
|
|||
show_lobby_joins_button2_.set_help_string(_("Show messages about your friends joining the multiplayer lobby"));
|
||||
show_lobby_joins_button3_.set_check(lobby_joins() == SHOW_ALL);
|
||||
show_lobby_joins_button3_.set_help_string(_("Show messages about all players joining the multiplayer lobby"));
|
||||
|
||||
|
||||
friends_list_button_.set_help_string(_("View and edit your friends and ignores list"));
|
||||
friends_back_button_.set_help_string(_("Back to the multiplayer options"));
|
||||
friends_add_friend_button_.set_help_string(_("Add this username to your friends list"));
|
||||
|
@ -403,7 +403,7 @@ handler_vector preferences_dialog::handler_members()
|
|||
h.push_back(&friends_add_friend_button_);
|
||||
h.push_back(&friends_add_ignore_button_);
|
||||
h.push_back(&friends_remove_button_);
|
||||
h.push_back(&friends_input_);
|
||||
h.push_back(&friends_input_);
|
||||
h.push_back(&show_floating_labels_button_);
|
||||
h.push_back(&turn_dialog_button_);
|
||||
h.push_back(&turn_bell_button_);
|
||||
|
@ -574,33 +574,33 @@ void preferences_dialog::update_location(SDL_Rect const &rect)
|
|||
ypos += item_interline; chat_timestamp_button_.set_location(rect.x, ypos);
|
||||
ypos += item_interline; sort_list_by_group_button_.set_location(rect.x, ypos);
|
||||
ypos += item_interline; iconize_list_button_.set_location(rect.x, ypos);
|
||||
|
||||
|
||||
ypos += item_interline; show_lobby_joins_button1_.set_location(rect.x, ypos);
|
||||
ypos += short_interline; show_lobby_joins_button2_.set_location(rect.x, ypos);
|
||||
ypos += short_interline; show_lobby_joins_button3_.set_location(rect.x, ypos);
|
||||
|
||||
|
||||
friends_list_button_.set_location(rect.x, bottom_row_y - friends_list_button_.height());
|
||||
|
||||
//Friends tab
|
||||
ypos = rect.y + top_border;
|
||||
friends_input_.set_location(rect.x,ypos);
|
||||
|
||||
|
||||
friends_.set_location(rect.x,ypos + item_interline);
|
||||
friends_.set_max_height(height() - 100 - friends_back_button_.height());
|
||||
|
||||
|
||||
int friends_xpos;
|
||||
|
||||
|
||||
if (friends_.width() > friends_input_.width()) {
|
||||
friends_xpos = rect.x+ friends_.width() + 20;
|
||||
} else {
|
||||
friends_xpos = rect.x+ friends_input_.width() + 20;
|
||||
}
|
||||
|
||||
|
||||
friends_add_friend_button_.set_location(friends_xpos,ypos);
|
||||
ypos += short_interline+3; friends_add_ignore_button_.set_location(friends_xpos,ypos);
|
||||
ypos += short_interline+3; friends_remove_button_.set_location(friends_xpos,ypos);
|
||||
friends_back_button_.set_location(rect.x, bottom_row_y - friends_back_button_.height());
|
||||
|
||||
|
||||
//Advanced tab
|
||||
ypos = rect.y + top_border;
|
||||
advanced_.set_location(rect.x,ypos);
|
||||
|
@ -812,8 +812,8 @@ void preferences_dialog::process_event()
|
|||
}
|
||||
|
||||
if (tab_ == FRIENDS_TAB) {
|
||||
if(friends_.selection() != friends_selection_) {
|
||||
friends_selection_ = friends_.selection();
|
||||
if(friends_.selection() != friends_selection_) {
|
||||
friends_selection_ = friends_.selection();
|
||||
std::stringstream ss;
|
||||
ss << friends_names_[friends_.selection()];
|
||||
if (ss.str() != "(empty list)") friends_input_.set_text(ss.str());
|
||||
|
@ -826,7 +826,7 @@ void preferences_dialog::process_event()
|
|||
friends_input_.clear();
|
||||
set_friends_menu();
|
||||
} else {
|
||||
friends_input_.set_text("Invalid username");
|
||||
friends_input_.set_text("Invalid username");
|
||||
}
|
||||
}
|
||||
if (friends_add_ignore_button_.pressed()) {
|
||||
|
@ -834,7 +834,7 @@ void preferences_dialog::process_event()
|
|||
friends_input_.clear();
|
||||
set_friends_menu();
|
||||
} else {
|
||||
friends_input_.set_text("Invalid username");
|
||||
friends_input_.set_text("Invalid username");
|
||||
}
|
||||
}
|
||||
if (friends_remove_button_.pressed()) {
|
||||
|
@ -842,11 +842,11 @@ void preferences_dialog::process_event()
|
|||
friends_input_.clear();
|
||||
set_friends_menu();
|
||||
} else {
|
||||
friends_input_.set_text("Invalid username");
|
||||
friends_input_.set_text("Invalid username");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (tab_ == ADVANCED_TAB) {
|
||||
if(advanced_.selection() != advanced_selection_) {
|
||||
|
@ -1024,7 +1024,7 @@ void preferences_dialog::set_selection(int index)
|
|||
show_lobby_joins_button2_.hide(hide_multiplayer);
|
||||
show_lobby_joins_button3_.hide(hide_multiplayer);
|
||||
friends_list_button_.hide(hide_multiplayer);
|
||||
|
||||
|
||||
const bool hide_friends = tab_ != FRIENDS_TAB;
|
||||
friends_.hide(hide_friends);
|
||||
friends_back_button_.hide(hide_friends);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file gamestatus.cpp
|
||||
//! @file gamestatus.cpp
|
||||
//! Maintain status of a game, load&save games.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -186,19 +186,19 @@ gamestatus::gamestatus(const config& time_cfg, int num_turns, game_state* s_o_g)
|
|||
std::string turn_at = time_cfg["turn_at"];
|
||||
std::string current_tod = time_cfg["current_tod"];
|
||||
std::string random_start_time = time_cfg["random_start_time"];
|
||||
if (s_o_g)
|
||||
if (s_o_g)
|
||||
{
|
||||
turn_at = utils::interpolate_variables_into_string(turn_at, *s_o_g);
|
||||
current_tod = utils::interpolate_variables_into_string(current_tod, *s_o_g);
|
||||
|
||||
}
|
||||
|
||||
if(turn_at.empty() == false)
|
||||
|
||||
if(turn_at.empty() == false)
|
||||
{
|
||||
turn_ = atoi(turn_at.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
parse_times(time_cfg,times_);
|
||||
|
||||
set_start_ToD(const_cast<config&>(time_cfg),s_o_g);
|
||||
|
@ -249,9 +249,9 @@ void gamestatus::write(config& cfg) const
|
|||
time_of_day gamestatus::get_time_of_day_turn(int nturn) const
|
||||
{
|
||||
wassert(!times_.empty());
|
||||
|
||||
|
||||
int time = (currentTime_ + nturn - turn())% times_.size();
|
||||
|
||||
|
||||
if (time < 0)
|
||||
{
|
||||
time += times_.size();
|
||||
|
@ -271,16 +271,16 @@ time_of_day gamestatus::get_previous_time_of_day() const
|
|||
return get_time_of_day_turn(turn()-1);
|
||||
}
|
||||
|
||||
//! Returns time of day object in the turn.
|
||||
//! It first tries to look for specified.
|
||||
//! Returns time of day object in the turn.
|
||||
//! It first tries to look for specified.
|
||||
//! If no area time specified in location, it returns global time.
|
||||
time_of_day gamestatus::get_time_of_day(int illuminated, const gamemap::location& loc, int n_turn) const
|
||||
{
|
||||
time_of_day res = get_time_of_day_turn(n_turn);
|
||||
|
||||
|
||||
for(std::vector<area_time_of_day>::const_iterator i = areas_.begin(); i != areas_.end(); ++i) {
|
||||
if(i->hexes.count(loc) == 1) {
|
||||
|
||||
|
||||
wassert(!i->times.empty());
|
||||
|
||||
res = i->times[(n_turn-1)%i->times.size()];
|
||||
|
@ -306,12 +306,12 @@ time_of_day gamestatus::get_time_of_day(int illuminated, const gamemap::location
|
|||
bool gamestatus::set_time_of_day(int newTime)
|
||||
{
|
||||
// newTime can come from network so have to take run time test
|
||||
if( newTime >= static_cast<int>(times_.size())
|
||||
if( newTime >= static_cast<int>(times_.size())
|
||||
|| newTime < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
currentTime_ = newTime;
|
||||
|
||||
return true;
|
||||
|
@ -334,10 +334,10 @@ void gamestatus::set_start_ToD(config &level, game_state* s_o_g)
|
|||
if (s_o_g)
|
||||
{
|
||||
random_start_time = utils::interpolate_variables_into_string(random_start_time, *s_o_g);
|
||||
}
|
||||
}
|
||||
if (gamestatus::is_start_ToD(random_start_time))
|
||||
{
|
||||
std::vector<std::string> start_strings =
|
||||
std::vector<std::string> start_strings =
|
||||
utils::split(random_start_time, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
|
||||
|
||||
if (utils::string_bool(random_start_time,false))
|
||||
|
@ -352,8 +352,8 @@ void gamestatus::set_start_ToD(config &level, game_state* s_o_g)
|
|||
}
|
||||
else
|
||||
{
|
||||
// We have to set right ToD for oldsaves
|
||||
|
||||
// We have to set right ToD for oldsaves
|
||||
|
||||
set_time_of_day((turn() - 1) % times_.size());
|
||||
}
|
||||
// Setting ToD to level data
|
||||
|
@ -370,7 +370,7 @@ void gamestatus::next_time_of_day()
|
|||
|
||||
currentTime_ = (currentTime_ + 1)%times_.size();
|
||||
}
|
||||
|
||||
|
||||
size_t gamestatus::turn() const
|
||||
{
|
||||
return turn_;
|
||||
|
@ -421,7 +421,7 @@ static player_info read_player(const game_data& data, const config* cfg)
|
|||
return res;
|
||||
}
|
||||
|
||||
game_state::game_state(const game_data& data, const config& cfg)
|
||||
game_state::game_state(const game_data& data, const config& cfg)
|
||||
: difficulty("NORMAL"), last_selected(gamemap::location::null_location)
|
||||
{
|
||||
log_scope("read_game");
|
||||
|
@ -585,7 +585,7 @@ void write_game(const game_state& gamestate, config& cfg, WRITE_GAME_MODE mode)
|
|||
|
||||
cfg["campaign_define"] = gamestate.campaign_define;
|
||||
cfg["campaign_extra_defines"] = utils::join(gamestate.campaign_xtra_defines);
|
||||
|
||||
|
||||
cfg.add_child("variables",gamestate.get_variables());
|
||||
|
||||
for(std::map<std::string, wml_menu_item *>::const_iterator j=gamestate.wml_menu_items.begin();
|
||||
|
@ -678,9 +678,9 @@ void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE
|
|||
//! If the times are equal, will order based on the name.
|
||||
struct save_info_less_time {
|
||||
bool operator()(const save_info& a, const save_info& b) const {
|
||||
if (a.time_modified > b.time_modified) {
|
||||
if (a.time_modified > b.time_modified) {
|
||||
return true;
|
||||
} else if (a.time_modified < b.time_modified) {
|
||||
} else if (a.time_modified < b.time_modified) {
|
||||
return false;
|
||||
// Special funky case; for files created in the same second,
|
||||
// a replay file sorts less than a non-replay file. Prevents
|
||||
|
@ -782,7 +782,7 @@ void load_game_summary(const std::string& name, config& cfg_summary, std::string
|
|||
scoped_ostream open_save_game(const std::string &label)
|
||||
{
|
||||
std::string name = label;
|
||||
replace_space2underbar(name);
|
||||
replace_space2underbar(name);
|
||||
|
||||
try {
|
||||
return scoped_ostream(ostream_file(get_saves_dir() + "/" + name));
|
||||
|
@ -1106,7 +1106,7 @@ game_state& game_state::operator=(const game_state& state)
|
|||
completion = state.completion;
|
||||
players = state.players;
|
||||
scoped_variables = state.scoped_variables;
|
||||
|
||||
|
||||
clear_wmi(wml_menu_items);
|
||||
std::map<std::string, wml_menu_item*>::const_iterator itor;
|
||||
for (itor = state.wml_menu_items.begin(); itor != state.wml_menu_items.end(); ++itor) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file gamestatus.hpp
|
||||
//! @file gamestatus.hpp
|
||||
//!
|
||||
|
||||
#ifndef GAME_STATUS_HPP_INCLUDED
|
||||
|
@ -35,7 +35,7 @@ struct time_of_day
|
|||
explicit time_of_day(const config& cfg);
|
||||
void write(config& cfg) const;
|
||||
|
||||
// The % bonus lawful units receive.
|
||||
// The % bonus lawful units receive.
|
||||
// Chaotic units will receive -lawful_bonus.
|
||||
int lawful_bonus;
|
||||
int bonus_modified;
|
||||
|
@ -45,11 +45,11 @@ struct time_of_day
|
|||
t_string name;
|
||||
std::string id;
|
||||
|
||||
// The image that is to be laid over all images
|
||||
// The image that is to be laid over all images
|
||||
// while this time of day lasts.
|
||||
std::string image_mask;
|
||||
|
||||
// The colour modifications that should be made
|
||||
// The colour modifications that should be made
|
||||
// to the game board to reflect the time of day.
|
||||
int red, green, blue;
|
||||
|
||||
|
@ -75,9 +75,9 @@ struct player_info
|
|||
{
|
||||
player_info():gold(-1) {}
|
||||
|
||||
std::string name; /** < Stores the current_player name */
|
||||
int gold; /** < Amount of gold the player has saved */
|
||||
std::vector<unit> available_units; /** < Units the player may recall */
|
||||
std::string name; /** < Stores the current_player name */
|
||||
int gold; /** < Amount of gold the player has saved */
|
||||
std::vector<unit> available_units; /** < Units the player may recall */
|
||||
std::set<std::string> can_recruit; /** < Units the player has the ability to recruit */
|
||||
};
|
||||
|
||||
|
@ -91,20 +91,20 @@ public:
|
|||
~game_state();
|
||||
game_state& operator=(const game_state& state);
|
||||
|
||||
std::string label; //!< Name of the game (e.g. name of save file).
|
||||
std::string version; //!< Version game was created with.
|
||||
std::string campaign_type; //!< Type of the game - campaign, multiplayer etc.
|
||||
std::string label; //!< Name of the game (e.g. name of save file).
|
||||
std::string version; //!< Version game was created with.
|
||||
std::string campaign_type; //!< Type of the game - campaign, multiplayer etc.
|
||||
|
||||
std::string campaign_define; //! If there is a define the campaign uses to customize data
|
||||
std::vector<std::string> campaign_xtra_defines; // more customization of data
|
||||
|
||||
std::string campaign; //!< the campaign being played
|
||||
std::string scenario; //!< the scenario being played
|
||||
std::string campaign; //!< the campaign being played
|
||||
std::string scenario; //!< the scenario being played
|
||||
std::string completion; //!< running. victory, or defeat
|
||||
|
||||
//! Information about campaign players who carry resources
|
||||
//! from previous levels, indexed by a string identifier
|
||||
// (which is the leader name by default, but can be set
|
||||
//! Information about campaign players who carry resources
|
||||
//! from previous levels, indexed by a string identifier
|
||||
// (which is the leader name by default, but can be set
|
||||
// with the "id" attribute of the "side" tag).
|
||||
std::map<std::string, player_info> players;
|
||||
|
||||
|
@ -133,17 +133,17 @@ public:
|
|||
|
||||
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
|
||||
//! If the game is saved mid-level, we have a series of replay steps
|
||||
//! to take the game up to the position it was saved at.
|
||||
config replay_data;
|
||||
|
||||
//! Saved starting state of the game.
|
||||
//! For multiplayer games, the position the game started in
|
||||
//! may be different to the scenario,
|
||||
//! For multiplayer games, the position the game started in
|
||||
//! may be different to the scenario,
|
||||
config starting_pos;
|
||||
|
||||
//! Snapshot of the game's current contents.
|
||||
//! i.e. unless the player selects to view a replay,
|
||||
//! Snapshot of the game's current contents.
|
||||
//! i.e. unless the player selects to view a replay,
|
||||
//! the game's settings are read in from this object.
|
||||
config snapshot;
|
||||
|
||||
|
@ -156,7 +156,7 @@ private:
|
|||
};
|
||||
|
||||
|
||||
//! Contains the global status of the game.
|
||||
//! Contains the global status of the game.
|
||||
//! Namely the current turn, the number of turns, and the time of day.
|
||||
class gamestatus
|
||||
{
|
||||
|
@ -174,13 +174,13 @@ public:
|
|||
void modify_turns(const std::string& mod);
|
||||
void add_turns(int num);
|
||||
|
||||
//! function to move to the next turn.
|
||||
//! function to move to the next turn.
|
||||
//! Returns true iff time has expired.
|
||||
bool next_turn();
|
||||
|
||||
|
||||
static bool is_start_ToD(const std::string&);
|
||||
|
||||
//! @todo FIXME: since gamestatus may be constructed with NULL game_state* (by default),
|
||||
//! @todo FIXME: since gamestatus may be constructed with NULL game_state* (by default),
|
||||
//! you should not rely on this function to return the current game_state.
|
||||
const game_state& sog() const{return(*state_of_game_);}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file generate_report.cpp
|
||||
//! @file generate_report.cpp
|
||||
//! Formatted output of various stats about units and the game.
|
||||
//! Used for the right sidebar and the top line of the main game-display.
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
namespace reports {
|
||||
|
||||
report generate_report(TYPE type,
|
||||
report generate_report(TYPE type,
|
||||
std::map<reports::TYPE, std::string> report_contents,
|
||||
const gamemap& map, unit_map& units,
|
||||
const std::vector<team>& teams, const team& current_team,
|
||||
|
@ -205,7 +205,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
if(utils::string_bool(u->second.get_state("stoned"))){
|
||||
x = 128;
|
||||
}else{
|
||||
x = static_cast<int>(128 + (255-128) *
|
||||
x = static_cast<int>(128 + (255-128) *
|
||||
(static_cast<float>(movement_left)/u->second.total_movement()));
|
||||
}
|
||||
str << "<" << x << "," << x << "," << x <<">";
|
||||
|
@ -270,7 +270,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
|
||||
tooltip << _("weapon range: ") << range <<"\n";
|
||||
tooltip << _("damage type: ") << lang_type << "\n";
|
||||
// Find all the unit types on the map, and
|
||||
// Find all the unit types on the map, and
|
||||
// show this weapon's bonus against all the different units.
|
||||
// Don't show invisible units, except if they are in our team or allied.
|
||||
std::set<std::string> seen_units;
|
||||
|
@ -323,7 +323,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
case UNIT_IMAGE:
|
||||
{
|
||||
// const std::vector<Uint32>& old_rgb = u->second.team_rgb_range();
|
||||
// color_range new_rgb = team::get_side_color_range(u->second.side());
|
||||
// color_range new_rgb = team::get_side_color_range(u->second.side());
|
||||
return report("",image::locator(u->second.absolute_image(),u->second.image_mods()),"");
|
||||
}
|
||||
case UNIT_PROFILE:
|
||||
|
@ -331,7 +331,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
case TIME_OF_DAY: {
|
||||
time_of_day tod = timeofday_at(status,units,mouseover,map);
|
||||
const std::string tod_image = tod.image + (preferences::flip_time() ? "~FL(horiz)" : "");
|
||||
|
||||
|
||||
// Don't show illuminated time on fogged/shrouded tiles
|
||||
if (current_team.fogged(mouseover.x,mouseover.y) || current_team.shrouded(mouseover.x,mouseover.y)) {
|
||||
tod = status.get_time_of_day(false,mouseover);
|
||||
|
@ -356,7 +356,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
|
||||
str << "\n";
|
||||
break;
|
||||
// For the following status reports, show them in gray text
|
||||
// For the following status reports, show them in gray text
|
||||
// when it is not the active player's turn.
|
||||
case GOLD:
|
||||
str << (current_side != playing_side ? font::GRAY_TEXT : (current_team.gold() < 0 ? font::BAD_TEXT : font::NULL_MARKUP)) << current_team.gold();
|
||||
|
@ -425,7 +425,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
if(underlying.size() != 1 || underlying.front() != terrain) {
|
||||
str << " (";
|
||||
|
||||
for(t_translation::t_list::const_iterator i =
|
||||
for(t_translation::t_list::const_iterator i =
|
||||
underlying.begin(); i != underlying.end(); ++i) {
|
||||
|
||||
str << map.get_terrain_info(*i).name();
|
||||
|
@ -460,7 +460,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
} else if (mouseover_unit) {
|
||||
str << " (" << defense << "%,-)";
|
||||
} else {
|
||||
str << " (-)";
|
||||
str << " (-)";
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -534,9 +534,9 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
}
|
||||
str << sec;
|
||||
break;
|
||||
} // Intentional fall-through to REPORT_CLOCK
|
||||
// if the time countdown isn't valid.
|
||||
// If there is no turn time limit,
|
||||
} // Intentional fall-through to REPORT_CLOCK
|
||||
// if the time countdown isn't valid.
|
||||
// If there is no turn time limit,
|
||||
// then we display the clock instead.
|
||||
}
|
||||
case REPORT_CLOCK: {
|
||||
|
|
36
src/halo.cpp
36
src/halo.cpp
|
@ -47,7 +47,7 @@ public:
|
|||
bool expired() const { return images_.animation_finished(); }
|
||||
bool need_update() const { return images_.need_update(); }
|
||||
bool does_change() const { return !images_.does_not_change(); }
|
||||
bool on_location(const std::set<gamemap::location>& locations) const;
|
||||
bool on_location(const std::set<gamemap::location>& locations) const;
|
||||
|
||||
void add_overlay_location(std::set<gamemap::location>& locations);
|
||||
private:
|
||||
|
@ -72,10 +72,10 @@ private:
|
|||
std::map<int, effect> haloes;
|
||||
int halo_id = 1;
|
||||
|
||||
// Upon unrendering an invalidation list is send. All haloes in that area and the
|
||||
// Upon unrendering an invalidation list is send. All haloes in that area and the
|
||||
// other invalidated haloes are stored in this set. Then there'll be tested which
|
||||
// haloes overlap and they're also stored in this set.
|
||||
std::set<int> invalidated_haloes;
|
||||
// haloes overlap and they're also stored in this set.
|
||||
std::set<int> invalidated_haloes;
|
||||
|
||||
// A newly added halo will be added to this list, these haloes don't need to
|
||||
// be unrendered but do not to be rendered regardless which tiles are invalidated.
|
||||
|
@ -90,7 +90,7 @@ std::set<int> deleted_haloes;
|
|||
// Haloes that have an animation or expiration time need to be checked every frame
|
||||
// and are stored in this set.
|
||||
std::set<int> changing_haloes;
|
||||
|
||||
|
||||
effect::effect(int xpos, int ypos, const animated<std::string>::anim_description& img,
|
||||
const gamemap::location& loc, ORIENTATION orientation, bool infinite) :
|
||||
images_(img), orientation_(orientation), x_(xpos), y_(ypos),
|
||||
|
@ -125,7 +125,7 @@ bool effect::render()
|
|||
if(disp == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(loc_.x != -1 && loc_.y != -1 && disp->shrouded(loc_)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ void effect::unrender()
|
|||
update_rect(rect_);
|
||||
}
|
||||
|
||||
bool effect::on_location(const std::set<gamemap::location>& locations) const
|
||||
bool effect::on_location(const std::set<gamemap::location>& locations) const
|
||||
{
|
||||
for(std::vector<gamemap::location>::const_iterator itor = overlayed_hexes_.begin();
|
||||
itor != overlayed_hexes_.end(); ++itor) {
|
||||
|
@ -242,7 +242,7 @@ manager::manager(display& screen) : old(disp)
|
|||
manager::~manager()
|
||||
{
|
||||
haloes.clear();
|
||||
invalidated_haloes.clear();
|
||||
invalidated_haloes.clear();
|
||||
new_haloes.clear();
|
||||
deleted_haloes.clear();
|
||||
changing_haloes.clear();
|
||||
|
@ -290,12 +290,12 @@ void set_location(int handle, int x, int y)
|
|||
|
||||
void remove(int handle)
|
||||
{
|
||||
// silently ignore invalid haloes, this happens when Wesnoth is being
|
||||
// silently ignore invalid haloes, this happens when Wesnoth is being
|
||||
// terminated as well.
|
||||
if(handle == NO_HALO || haloes.find(handle) == haloes.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
deleted_haloes.insert(handle);
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ void unrender(std::set<gamemap::location> invalidated_locations)
|
|||
invalidated_haloes.insert(*set_itor);
|
||||
haloes.find(*set_itor)->second.add_overlay_location(invalidated_locations);
|
||||
}
|
||||
|
||||
|
||||
// test the multi-frame haloes whether they need an update
|
||||
for(set_itor = changing_haloes.begin();
|
||||
set_itor != changing_haloes.end(); ++set_itor) {
|
||||
|
@ -339,9 +339,9 @@ void unrender(std::set<gamemap::location> invalidated_locations)
|
|||
halo_count = invalidated_haloes.size();
|
||||
for(itor = haloes.begin(); itor != haloes.end(); ++itor) {
|
||||
// test all haloes not yet in the set which match one of the locations
|
||||
if(invalidated_haloes.find(itor->first) == invalidated_haloes.end() &&
|
||||
if(invalidated_haloes.find(itor->first) == invalidated_haloes.end() &&
|
||||
itor->second.on_location(invalidated_locations)) {
|
||||
|
||||
|
||||
// if found add all locations which the halo invalidates
|
||||
// and add it to the set
|
||||
itor->second.add_overlay_location(invalidated_locations);
|
||||
|
@ -353,7 +353,7 @@ void unrender(std::set<gamemap::location> invalidated_locations)
|
|||
if(halo_count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// render the haloes iterate through all the haloes and invalidate if in set
|
||||
for(std::map<int, effect>::reverse_iterator ritor = haloes.rbegin(); ritor != haloes.rend(); ++ritor) {
|
||||
if(invalidated_haloes.find(ritor->first) != invalidated_haloes.end()) {
|
||||
|
@ -365,7 +365,7 @@ void unrender(std::set<gamemap::location> invalidated_locations)
|
|||
for(set_itor = deleted_haloes.begin(); set_itor != deleted_haloes.end(); ++set_itor) {
|
||||
// it can happen a delete halo hasn't been rendered yet, invalidate them as well
|
||||
new_haloes.erase(*set_itor);
|
||||
|
||||
|
||||
changing_haloes.erase(*set_itor);
|
||||
invalidated_haloes.erase(*set_itor);
|
||||
haloes.erase(*set_itor);
|
||||
|
@ -386,12 +386,12 @@ void render()
|
|||
std::set<int> unrendered_new_haloes;
|
||||
|
||||
// render the haloes iterate through all the haloes and draw if in either set
|
||||
for(std::map<int, effect>::iterator itor = haloes.begin();
|
||||
for(std::map<int, effect>::iterator itor = haloes.begin();
|
||||
itor != haloes.end(); ++itor) {
|
||||
|
||||
if(new_haloes.find(itor->first) != new_haloes.end() &&
|
||||
if(new_haloes.find(itor->first) != new_haloes.end() &&
|
||||
! itor->second.render()) {
|
||||
|
||||
|
||||
unrendered_new_haloes.insert(itor->first);
|
||||
} else if(invalidated_haloes.find(itor->first) != invalidated_haloes.end()) {
|
||||
itor->second.render();
|
||||
|
|
|
@ -60,7 +60,7 @@ struct remover
|
|||
void operator()(int handle) const { remove(handle); }
|
||||
};
|
||||
|
||||
///functions to render and unrender haloes. Which haloes are rendered
|
||||
///functions to render and unrender haloes. Which haloes are rendered
|
||||
// is determined by invalidated_locations and the internal state in
|
||||
// the control sets (in halo.cpp)
|
||||
void unrender(std::set<gamemap::location> invalidated_locations);
|
||||
|
|
38
src/help.cpp
38
src/help.cpp
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file help.cpp
|
||||
//! @file help.cpp
|
||||
//! Routines for showing the help-dialog.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -907,7 +907,7 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
|
|||
generate_topics(sort_generated,(*section_cfg)["generator"]);
|
||||
|
||||
if (sort_topics) {
|
||||
std::sort(topics.begin(),topics.end(), title_less());
|
||||
std::sort(topics.begin(),topics.end(), title_less());
|
||||
std::sort(generated_topics.begin(),
|
||||
generated_topics.end(), title_less());
|
||||
std::merge(generated_topics.begin(),
|
||||
|
@ -957,7 +957,7 @@ std::string generate_topic_text(const std::string &generator)
|
|||
return empty_string;
|
||||
} else if (generator == "about") {
|
||||
return generate_about_text();
|
||||
}
|
||||
}
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
|
@ -1125,7 +1125,7 @@ std::vector<topic> generate_ability_topics(const bool sort_generated)
|
|||
|
||||
topics.push_back( topic(name, id, text.str()) );
|
||||
}
|
||||
|
||||
|
||||
if (sort_generated)
|
||||
std::sort(topics.begin(), topics.end(), title_less());
|
||||
return topics;
|
||||
|
@ -1347,7 +1347,7 @@ public:
|
|||
std::vector<item> row;
|
||||
int resistance = 100 - atoi((*dam_it).second.c_str());
|
||||
char resi[16];
|
||||
snprintf(resi,sizeof(resi),"% 4d%%",resistance); // range: -100% .. +70%
|
||||
snprintf(resi,sizeof(resi),"% 4d%%",resistance); // range: -100% .. +70%
|
||||
//FIXME: "white" is currently not a supported color key
|
||||
//so the default grey-white will be used
|
||||
std::string color;
|
||||
|
@ -1415,7 +1415,7 @@ public:
|
|||
else if (defense <= 30)
|
||||
color = "yellow";
|
||||
else if (defense <= 50)
|
||||
color = "white";
|
||||
color = "white";
|
||||
else
|
||||
color = "green";
|
||||
|
||||
|
@ -1428,9 +1428,9 @@ public:
|
|||
|
||||
//movement - range: 1 .. 5, 99=impassable
|
||||
str.str(clear_stringstream);
|
||||
if (moves > type_.movement() ) // cannot move in this terrain
|
||||
if (moves > type_.movement() ) // cannot move in this terrain
|
||||
color = "red";
|
||||
else if (moves > 1)
|
||||
else if (moves > 1)
|
||||
color = "yellow";
|
||||
else
|
||||
color = "white";
|
||||
|
@ -1690,7 +1690,7 @@ void help_menu::select_topic(const topic &t)
|
|||
int help_menu::process()
|
||||
{
|
||||
int res = menu::process();
|
||||
if (!visible_items_.empty() &&
|
||||
if (!visible_items_.empty() &&
|
||||
static_cast<size_t>(res) < visible_items_.size()) {
|
||||
|
||||
selected_item_ = visible_items_[res];
|
||||
|
@ -1986,7 +1986,7 @@ void help_text_area::handle_jump_cfg(const config &cfg)
|
|||
}
|
||||
jump_to = to;
|
||||
}
|
||||
if (jump_to != 0 && static_cast<int>(jump_to) <
|
||||
if (jump_to != 0 && static_cast<int>(jump_to) <
|
||||
get_max_x(curr_loc_.first, curr_row_height_)) {
|
||||
|
||||
curr_loc_.first = jump_to;
|
||||
|
@ -2578,9 +2578,9 @@ std::string convert_to_wml(const std::string &element_name, const std::string &c
|
|||
bool last_char_escape = false;
|
||||
const char escape_char = '\\';
|
||||
std::vector<std::string> attributes;
|
||||
// Find the different attributes.
|
||||
// No checks are made for the equal sign or something like that.
|
||||
// Attributes are just separated by spaces or newlines.
|
||||
// Find the different attributes.
|
||||
// No checks are made for the equal sign or something like that.
|
||||
// Attributes are just separated by spaces or newlines.
|
||||
// Attributes that contain spaces must be in single quotes.
|
||||
for (size_t pos = 0; pos < contents.size(); pos++) {
|
||||
const char c = contents[pos];
|
||||
|
@ -2706,7 +2706,7 @@ std::string get_first_word(const std::string &s)
|
|||
if (first_word_start == std::string::npos) {
|
||||
return s;
|
||||
}
|
||||
size_t first_word_end = s.find_first_of(" \n", first_word_start);
|
||||
size_t first_word_end = s.find_first_of(" \n", first_word_start);
|
||||
if( first_word_end == first_word_start ) {
|
||||
// This word is '\n'.
|
||||
first_word_end = first_word_start+1;
|
||||
|
@ -2722,13 +2722,13 @@ void show_help(display &disp, std::string show_topic, int xloc, int yloc)
|
|||
show_help(disp, toplevel, show_topic, xloc, yloc);
|
||||
}
|
||||
|
||||
//! Open a help dialog using a toplevel other than the default.
|
||||
//! Open a help dialog using a toplevel other than the default.
|
||||
//!
|
||||
//! This allows for complete customization of the contents,
|
||||
//! This allows for complete customization of the contents,
|
||||
//! although not in a very easy way.
|
||||
void show_help(display &disp, const section &toplevel_sec,
|
||||
void show_help(display &disp, const section &toplevel_sec,
|
||||
const std::string show_topic,
|
||||
int xloc, int yloc)
|
||||
int xloc, int yloc)
|
||||
{
|
||||
const events::event_context dialog_events_context;
|
||||
const gui::dialog_manager manager;
|
||||
|
@ -2758,7 +2758,7 @@ void show_help(display &disp, const section &toplevel_sec,
|
|||
true, &buttons_ptr);
|
||||
f.layout(xloc, yloc, width, height);
|
||||
f.draw();
|
||||
|
||||
|
||||
if (preferences::encountered_units().size() != size_t(last_num_encountered_units) ||
|
||||
preferences::encountered_terrains().size() != size_t(last_num_encountered_terrains) ||
|
||||
last_debug_state != game_config::debug ||
|
||||
|
|
|
@ -92,11 +92,11 @@ const struct {
|
|||
{ hotkey::HOTKEY_STOP_REPLAY, "stopreplay", N_("Stop"), false },
|
||||
{ hotkey::HOTKEY_REPLAY_NEXT_TURN, "replaynextturn", N_("Next Turn"), false },
|
||||
{ hotkey::HOTKEY_REPLAY_NEXT_SIDE, "replaynextside", N_("Next Side"), false },
|
||||
{ hotkey::HOTKEY_REPLAY_SHOW_EVERYTHING, "replayshoweverything",
|
||||
{ hotkey::HOTKEY_REPLAY_SHOW_EVERYTHING, "replayshoweverything",
|
||||
N_("Full map"), false },
|
||||
{ hotkey::HOTKEY_REPLAY_SHOW_EACH, "replayshoweach",
|
||||
{ hotkey::HOTKEY_REPLAY_SHOW_EACH, "replayshoweach",
|
||||
N_("Each team"), false },
|
||||
{ hotkey::HOTKEY_REPLAY_SHOW_TEAM1, "replayshowteam1",
|
||||
{ hotkey::HOTKEY_REPLAY_SHOW_TEAM1, "replayshowteam1",
|
||||
N_("Team 1"), false },
|
||||
{ hotkey::HOTKEY_REPLAY_SKIP_ANIMATION, "replayskipanimation", N_("Skip animation"), false },
|
||||
|
||||
|
@ -259,7 +259,7 @@ void hotkey_item::set_key(int character, int keycode, bool shift, bool ctrl, boo
|
|||
character += 96;
|
||||
INFO_C << "Mapped to character " << lexical_cast<std::string>(character) << "\n";
|
||||
}
|
||||
|
||||
|
||||
// For some reason on Mac OS, if cmd and shift are down, the character doesn't get upper-cased
|
||||
if (cmd && character > 96 && character < 123 && shift)
|
||||
character -= 32;
|
||||
|
@ -392,7 +392,7 @@ hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl, bool
|
|||
character += 96;
|
||||
INFO_C << "Mapped to character " << lexical_cast<std::string>(character) << "\n";
|
||||
}
|
||||
|
||||
|
||||
// For some reason on Mac OS, if cmd and shift are down, the character doesn't get upper-cased
|
||||
if (cmd && character > 96 && character < 123 && shift)
|
||||
character -= 32;
|
||||
|
|
|
@ -45,8 +45,8 @@ enum HOTKEY_COMMAND {
|
|||
HOTKEY_SEARCH, HOTKEY_SPEAK_ALLY, HOTKEY_SPEAK_ALL, HOTKEY_HELP,
|
||||
HOTKEY_CHAT_LOG, HOTKEY_LANGUAGE,
|
||||
HOTKEY_PLAY_REPLAY, HOTKEY_RESET_REPLAY, HOTKEY_STOP_REPLAY, HOTKEY_REPLAY_NEXT_TURN,
|
||||
HOTKEY_REPLAY_NEXT_SIDE, HOTKEY_REPLAY_SHOW_EVERYTHING,
|
||||
HOTKEY_REPLAY_SHOW_EACH, HOTKEY_REPLAY_SHOW_TEAM1,
|
||||
HOTKEY_REPLAY_NEXT_SIDE, HOTKEY_REPLAY_SHOW_EVERYTHING,
|
||||
HOTKEY_REPLAY_SHOW_EACH, HOTKEY_REPLAY_SHOW_TEAM1,
|
||||
HOTKEY_REPLAY_SKIP_ANIMATION,
|
||||
|
||||
//editing specific commands
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file image.cpp
|
||||
//! @file image.cpp
|
||||
//! Routines for images: load, scale, re-color, etc.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -62,10 +62,10 @@ std::string image_mask;
|
|||
int zoom = image::tile_size;
|
||||
int cached_zoom = 0;
|
||||
|
||||
// The "pointer to surfaces" vector is not cleared anymore
|
||||
// (the surface are still freed, of course).
|
||||
// I do not think it is a problem, as the number of different surfaces
|
||||
// the program may lookup has an upper limit, so its memory usage
|
||||
// The "pointer to surfaces" vector is not cleared anymore
|
||||
// (the surface are still freed, of course).
|
||||
// I do not think it is a problem, as the number of different surfaces
|
||||
// the program may lookup has an upper limit, so its memory usage
|
||||
// won't grow indefinitely over time.
|
||||
template<typename T>
|
||||
void reset_cache(std::vector<image::cache_item<T> >& cache)
|
||||
|
@ -128,7 +128,7 @@ void locator::parse_arguments()
|
|||
return;
|
||||
}
|
||||
size_t markup_field = fn.find('~');
|
||||
|
||||
|
||||
if(markup_field != std::string::npos) {
|
||||
val_.type_ = SUB_FILE;
|
||||
val_.modifications_ = fn.substr(markup_field, fn.size() - markup_field);
|
||||
|
@ -235,7 +235,7 @@ bool locator::value::operator==(const value& a) const
|
|||
} else if(type_ == FILE) {
|
||||
return filename_ == a.filename_;
|
||||
} else if(type_ == SUB_FILE) {
|
||||
return filename_ == a.filename_ && loc_ == a.loc_ && modifications_ == a.modifications_;
|
||||
return filename_ == a.filename_ && loc_ == a.loc_ && modifications_ == a.modifications_;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -320,14 +320,14 @@ surface locator::load_image_sub_file() const
|
|||
std::string function=*j++;
|
||||
if(j==tmpmod.end()){
|
||||
if(function.size()){
|
||||
ERR_DP << "error parsing image modifications: "
|
||||
ERR_DP << "error parsing image modifications: "
|
||||
<< val_.modifications_<< "\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
std::string field = *j++;
|
||||
|
||||
if("TC" == function){ // Deprecated team coloring syntax
|
||||
if("TC" == function){ // Deprecated team coloring syntax
|
||||
//! @todo replace with proper RC syntax
|
||||
std::string::size_type pos = 0;
|
||||
pos = field.find(',');
|
||||
|
@ -342,10 +342,10 @@ surface locator::load_image_sub_file() const
|
|||
if(game_config::tc_info(f2).size()){
|
||||
function="RC";
|
||||
field= f2 + ">" + f1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if("RC" == function){ // Re-color function
|
||||
if("RC" == function){ // Re-color function
|
||||
std::vector<std::string> recolor=utils::split(field,'>');
|
||||
if(recolor.size()>1){
|
||||
std::map<Uint32, Uint32> tmp_map;
|
||||
|
@ -356,20 +356,20 @@ surface locator::load_image_sub_file() const
|
|||
} catch (config::error& e) {
|
||||
ERR_DP << "caught config::error... " << e.message << std::endl;
|
||||
}
|
||||
for(std::map<Uint32, Uint32>::const_iterator tmp = tmp_map.begin(); tmp!= tmp_map.end(); tmp++){
|
||||
for(std::map<Uint32, Uint32>::const_iterator tmp = tmp_map.begin(); tmp!= tmp_map.end(); tmp++){
|
||||
recolor_map[tmp->first] = tmp->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
if("FL" == function){ // Flip layer
|
||||
}
|
||||
if("FL" == function){ // Flip layer
|
||||
if(field.empty() || field.find("horiz") != std::string::npos) {
|
||||
xflip = !xflip;
|
||||
}
|
||||
if(field.find("vert") != std::string::npos) {
|
||||
yflip = !yflip;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
surf = recolor_image(surf,recolor_map);
|
||||
if(xflip) {
|
||||
|
@ -471,7 +471,7 @@ void set_image_mask(const std::string& /*image*/)
|
|||
|
||||
// image_mask are blitted in display.cpp
|
||||
// so no need to flush the cache here
|
||||
/*
|
||||
/*
|
||||
if(image_mask != image) {
|
||||
image_mask = image;
|
||||
reset_cache(scaled_to_hex_images_);
|
||||
|
@ -624,7 +624,7 @@ surface get_image(const image::locator& i_locator, TYPE type, bool add_to_cache
|
|||
if(i_locator.in_cache(*imap))
|
||||
return i_locator.locate_in_cache(*imap);
|
||||
|
||||
// If type is unscaled, directly load the image from the disk.
|
||||
// If type is unscaled, directly load the image from the disk.
|
||||
// Else, create it from the unscaled image.
|
||||
if(is_unscaled) {
|
||||
res = i_locator.load_from_disk();
|
||||
|
@ -706,5 +706,5 @@ bool exists(const image::locator& i_locator)
|
|||
}
|
||||
|
||||
|
||||
} // end namespace image
|
||||
} // end namespace image
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace image {
|
|||
value(const char *filename);
|
||||
value(const char *filename, const std::string& modifications);
|
||||
value(const std::string& filename);
|
||||
value(const std::string& filename, const std::string& modifications);
|
||||
value(const std::string& filename, const std::string& modifications);
|
||||
value(const std::string& filename, const gamemap::location& loc, const std::string& modifications);
|
||||
|
||||
bool operator==(const value& a) const;
|
||||
|
|
|
@ -155,7 +155,7 @@ bool show_intro_part(display &disp, const config& part,
|
|||
textx = 200;
|
||||
xbuttons = video.getx() - 200 - 40;
|
||||
}
|
||||
|
||||
|
||||
texty = dstrect.y + dstrect.h - 200;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ void leader_list_manager::populate_combo(int selected_index) {
|
|||
if (utypes.find(*itor) != utypes.end()) {
|
||||
const std::string name = utypes.find(*itor)->second.language_name();
|
||||
const std::string image = utypes.find(*itor)->second.image();
|
||||
|
||||
|
||||
#ifdef LOW_MEM
|
||||
leader_strings.push_back(IMAGE_PREFIX + image + COLUMN_SEPARATOR + name);
|
||||
#else
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file loadscreen.cpp
|
||||
//! @file loadscreen.cpp
|
||||
//! Screen with logo and "Loading ..."-progressbar during program-startup.
|
||||
|
||||
#include "loadscreen.hpp"
|
||||
|
@ -52,13 +52,13 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
|
|||
int fcr = 21, fcg = 53, fcb = 80; // RGB-values for 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.
|
||||
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.
|
||||
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.
|
||||
|
@ -77,7 +77,7 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
|
|||
logo_drawn_ = true;
|
||||
SDL_UpdateRect(gdis, area.x, area.y, area.w, area.h);
|
||||
}
|
||||
int pbx = (scrx - pbw)/2; // Horizontal location.
|
||||
int pbx = (scrx - pbw)/2; // Horizontal location.
|
||||
int pby = (scry - pbh)/2 + pby_offset_; // Vertical location.
|
||||
|
||||
// Draw top border.
|
||||
|
@ -100,7 +100,7 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
|
|||
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.
|
||||
// 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));
|
||||
|
@ -119,7 +119,7 @@ void loadscreen::set_progress(const int percentage, const std::string &text, con
|
|||
oldarea.h = maximum<int>(textarea_.h, oldarea.h);
|
||||
SDL_UpdateRect(gdis, oldarea.x, oldarea.y, oldarea.w, oldarea.h);
|
||||
}
|
||||
// Update the rectangle if needed
|
||||
// Update the rectangle if needed
|
||||
if(commit)
|
||||
{
|
||||
SDL_UpdateRect(gdis, pbx, pby, pbw + 2*(bw + bispw), pbh + 2*(bw + bispw));
|
||||
|
@ -132,15 +132,15 @@ void loadscreen::increment_progress(const int percentage, const std::string &tex
|
|||
|
||||
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.
|
||||
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.
|
||||
SDL_Flip(disp); // Flip the double buffering.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id$ */
|
||||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2005 - 2007 by Joeri Melis <joeri_melis@hotmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file loadscreen.hpp
|
||||
//! @file loadscreen.hpp
|
||||
//!
|
||||
|
||||
#ifndef JM_LOADSCREEN_HPP
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file loadscreen_empty.cpp
|
||||
//! @file loadscreen_empty.cpp
|
||||
//!
|
||||
|
||||
#include "loadscreen.hpp"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file log.cpp
|
||||
//! @file log.cpp
|
||||
//! Logger for debugging.
|
||||
//! See also wesnoth-commandline-params --logdomains and --log-error="".
|
||||
|
||||
|
@ -55,8 +55,8 @@ namespace lg {
|
|||
void timestamps(bool t) { timestamp = t; }
|
||||
|
||||
logger err("error", 0), warn("warning", 1), info("info", 2);
|
||||
log_domain general("general"), ai("ai"), config("config"), display("display"),
|
||||
engine("engine"), network("network"), filesystem("filesystem"),
|
||||
log_domain general("general"), ai("ai"), config("config"), display("display"),
|
||||
engine("engine"), network("network"), filesystem("filesystem"),
|
||||
audio("audio"), paths("paths");
|
||||
|
||||
log_domain::log_domain(char const *name) : domain_(log_domains.size())
|
||||
|
@ -89,7 +89,7 @@ std::string list_logdomains()
|
|||
it_begin = log_domains.begin(),
|
||||
it_end = log_domains.end(),
|
||||
it;
|
||||
std::string domainlist = "";
|
||||
std::string domainlist = "";
|
||||
for(it = it_begin; it != it_end; ++it) {
|
||||
if (it != it_begin)
|
||||
domainlist += ", ";
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file log.hpp
|
||||
//!
|
||||
//! @file log.hpp
|
||||
//!
|
||||
|
||||
#ifndef LOG_HPP_INCLUDED
|
||||
#define LOG_HPP_INCLUDED
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
void do_indent() const;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Use this logger to send errors due to deprecated WML.
|
||||
* The preferred format is:
|
||||
* xxx is deprecated, support will be removed in version X. or
|
||||
|
|
52
src/map.cpp
52
src/map.cpp
|
@ -40,7 +40,7 @@ gamemap::location gamemap::location::null_location;
|
|||
|
||||
const t_translation::t_list& gamemap::underlying_mvt_terrain(t_translation::t_letter terrain) const
|
||||
{
|
||||
const std::map<t_translation::t_letter,terrain_type>::const_iterator i =
|
||||
const std::map<t_translation::t_letter,terrain_type>::const_iterator i =
|
||||
letterToTerrain_.find(terrain);
|
||||
|
||||
if(i == letterToTerrain_.end()) {
|
||||
|
@ -54,7 +54,7 @@ const t_translation::t_list& gamemap::underlying_mvt_terrain(t_translation::t_le
|
|||
|
||||
const t_translation::t_list& gamemap::underlying_def_terrain(t_translation::t_letter terrain) const
|
||||
{
|
||||
const std::map<t_translation::t_letter, terrain_type>::const_iterator i =
|
||||
const std::map<t_translation::t_letter, terrain_type>::const_iterator i =
|
||||
letterToTerrain_.find(terrain);
|
||||
|
||||
if(i == letterToTerrain_.end()) {
|
||||
|
@ -63,14 +63,14 @@ const t_translation::t_list& gamemap::underlying_def_terrain(t_translation::t_le
|
|||
return result;
|
||||
} else {
|
||||
return i->second.def_type();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const t_translation::t_list& gamemap::underlying_union_terrain(t_translation::t_letter terrain) const
|
||||
{
|
||||
const std::map<t_translation::t_letter,terrain_type>::const_iterator i =
|
||||
const std::map<t_translation::t_letter,terrain_type>::const_iterator i =
|
||||
letterToTerrain_.find(terrain);
|
||||
|
||||
|
||||
if(i == letterToTerrain_.end()) {
|
||||
static t_translation::t_list result(1);
|
||||
result[0] = terrain;
|
||||
|
@ -245,7 +245,7 @@ gamemap::location::DIRECTION gamemap::location::get_opposite_dir(gamemap::locati
|
|||
}
|
||||
}
|
||||
|
||||
gamemap::gamemap(const config& cfg, const std::string& data) :
|
||||
gamemap::gamemap(const config& cfg, const std::string& data) :
|
||||
tiles_(1), w_(-1), h_(-1)
|
||||
{
|
||||
LOG_G << "loading map: '" << data << "'\n";
|
||||
|
@ -265,28 +265,28 @@ void gamemap::read(const std::string& data)
|
|||
try {
|
||||
tiles_ = t_translation::read_game_map(data, starting_positions);
|
||||
} catch(t_translation::error& e) {
|
||||
// we re-throw the error but as map error, since all codepaths test
|
||||
// we re-throw the error but as map error, since all codepaths test
|
||||
// for this, it's the least work
|
||||
throw incorrect_format_exception(e.message.c_str());
|
||||
}
|
||||
|
||||
//convert the starting positions to the array
|
||||
std::map<int, t_translation::coordinate>::const_iterator itor =
|
||||
std::map<int, t_translation::coordinate>::const_iterator itor =
|
||||
starting_positions.begin();
|
||||
|
||||
for(; itor != starting_positions.end(); ++itor) {
|
||||
|
||||
// check for valid position, the first valid position is
|
||||
// 1 so the offset 0 in the array is never used
|
||||
if(itor->first < 1 || itor->first >= STARTING_POSITIONS) {
|
||||
ERR_CF << "Starting position " << itor->first << " out of range\n";
|
||||
if(itor->first < 1 || itor->first >= STARTING_POSITIONS) {
|
||||
ERR_CF << "Starting position " << itor->first << " out of range\n";
|
||||
throw incorrect_format_exception("Illegal starting position found in map. The scenario cannot be loaded.");
|
||||
}
|
||||
|
||||
// add to the starting position array
|
||||
startingPositions_[itor->first] = location(itor->second.x, itor->second.y);
|
||||
}
|
||||
|
||||
|
||||
// post processing on the map
|
||||
const int width = tiles_.size();
|
||||
const int height = width > 0 ? tiles_[0].size() : 0;
|
||||
|
@ -294,14 +294,14 @@ void gamemap::read(const std::string& data)
|
|||
h_ = height;
|
||||
for(int x = 0; x < width; ++x) {
|
||||
for(int y = 0; y < height; ++y) {
|
||||
|
||||
// is the terrain valid?
|
||||
|
||||
// is the terrain valid?
|
||||
if(letterToTerrain_.count(tiles_[x][y]) == 0) {
|
||||
ERR_CF << "Illegal character in map: (" << t_translation::write_letter(tiles_[x][y])
|
||||
<< ") '" << tiles_[x][y] << "'\n";
|
||||
ERR_CF << "Illegal character in map: (" << t_translation::write_letter(tiles_[x][y])
|
||||
<< ") '" << tiles_[x][y] << "'\n";
|
||||
throw incorrect_format_exception("Illegal character found in map. The scenario cannot be loaded.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// is it a village
|
||||
if(is_village(tiles_[x][y])) {
|
||||
villages_.push_back(location(x, y));
|
||||
|
@ -316,14 +316,14 @@ std::string gamemap::write() const
|
|||
|
||||
// convert the starting positions to a map
|
||||
for(int i = 0; i < STARTING_POSITIONS; ++i) {
|
||||
if(on_board(startingPositions_[i])) {
|
||||
const struct t_translation::coordinate position =
|
||||
if(on_board(startingPositions_[i])) {
|
||||
const struct t_translation::coordinate position =
|
||||
{startingPositions_[i].x, startingPositions_[i].y};
|
||||
|
||||
|
||||
starting_positions.insert(std::pair<int, t_translation::coordinate>(i, position));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// let the low level convertor do the conversion
|
||||
return t_translation::write_game_map(tiles_, starting_positions);
|
||||
}
|
||||
|
@ -400,8 +400,8 @@ void gamemap::overlay(const gamemap& m, const config& rules_cfg, const int xpos,
|
|||
}
|
||||
}
|
||||
|
||||
for(const location* pos = m.startingPositions_;
|
||||
pos != m.startingPositions_ + sizeof(m.startingPositions_)/sizeof(*m.startingPositions_);
|
||||
for(const location* pos = m.startingPositions_;
|
||||
pos != m.startingPositions_ + sizeof(m.startingPositions_)/sizeof(*m.startingPositions_);
|
||||
++pos) {
|
||||
|
||||
if(pos->valid()) {
|
||||
|
@ -440,11 +440,11 @@ t_translation::t_letter gamemap::get_terrain(const gamemap::location& loc) const
|
|||
// but the border tiles will be deterimined in the future so then
|
||||
// this will no longer be used in the game (the editor will use
|
||||
// this feature to expand maps in a better way).
|
||||
std::map<location, t_translation::t_letter>::const_iterator itor =
|
||||
std::map<location, t_translation::t_letter>::const_iterator itor =
|
||||
borderCache_.find(adj[n]);
|
||||
|
||||
// only add if it's in the cache and a valid terrain
|
||||
if(itor != borderCache_.end() &&
|
||||
if(itor != borderCache_.end() &&
|
||||
itor->second != t_translation::NONE_TERRAIN) {
|
||||
|
||||
items[nitems] = itor->second;
|
||||
|
@ -597,7 +597,7 @@ void gamemap::set_terrain(const gamemap::location& loc, const t_translation::t_l
|
|||
tiles_[loc.x][loc.y] = terrain;
|
||||
|
||||
// temp hack, since the border can have multiple tiles depending on
|
||||
// eachother every change has to invalidate the cache. Once the
|
||||
// eachother every change has to invalidate the cache. Once the
|
||||
// border tiles are part of the map, this hack is no longer required.
|
||||
borderCache_.clear();
|
||||
return;
|
||||
|
|
|
@ -138,7 +138,7 @@ public:
|
|||
int h() const { return h_; }
|
||||
|
||||
//allows lookup of terrain at a particular location.
|
||||
const t_translation::t_list& operator[](int index) const
|
||||
const t_translation::t_list& operator[](int index) const
|
||||
{ return tiles_[index]; }
|
||||
|
||||
//looks up terrain at a particular location. Hexes off the map
|
||||
|
@ -206,7 +206,7 @@ public:
|
|||
protected:
|
||||
t_translation::t_map tiles_;
|
||||
location startingPositions_[STARTING_POSITIONS];
|
||||
|
||||
|
||||
/**
|
||||
* Clears the border cache, needed for the editor
|
||||
*/
|
||||
|
|
|
@ -35,21 +35,21 @@ static bool is_shrouded(const display& disp, const gamemap::location& loc)
|
|||
return disp.shrouded(loc) || disp.shrouded(gamemap::location(loc.x,loc.y+1));
|
||||
}
|
||||
|
||||
map_labels::map_labels(const display& disp,
|
||||
const gamemap& map,
|
||||
const team* team) :
|
||||
disp_(disp),
|
||||
map_labels::map_labels(const display& disp,
|
||||
const gamemap& map,
|
||||
const team* team) :
|
||||
disp_(disp),
|
||||
team_(team),
|
||||
map_(map)
|
||||
{
|
||||
}
|
||||
|
||||
map_labels::map_labels(const display& disp,
|
||||
const config& cfg,
|
||||
map_labels::map_labels(const display& disp,
|
||||
const config& cfg,
|
||||
const gamemap& map,
|
||||
const team* team,
|
||||
const variable_set *variables) :
|
||||
disp_(disp),
|
||||
const variable_set *variables) :
|
||||
disp_(disp),
|
||||
team_(team),
|
||||
map_(map)
|
||||
{
|
||||
|
@ -68,8 +68,8 @@ void map_labels::write(config& res) const
|
|||
for(label_map::const_iterator i = labs->second.begin(); i != labs->second.end(); ++i) {
|
||||
config item;
|
||||
i->second->write(item);
|
||||
|
||||
|
||||
|
||||
|
||||
res.add_child("label",item);
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ void map_labels::read(const config& cfg, const variable_set *variables)
|
|||
}
|
||||
|
||||
|
||||
size_t map_labels::get_max_chars()
|
||||
size_t map_labels::get_max_chars()
|
||||
{
|
||||
return max_label_size;
|
||||
}
|
||||
|
@ -124,8 +124,8 @@ const display& map_labels::disp() const
|
|||
{
|
||||
return disp_;
|
||||
}
|
||||
|
||||
const std::string& map_labels::team_name() const
|
||||
|
||||
const std::string& map_labels::team_name() const
|
||||
{
|
||||
if (team_)
|
||||
{
|
||||
|
@ -134,7 +134,7 @@ const std::string& map_labels::team_name() const
|
|||
static const std::string empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
void map_labels::set_team(const team* team)
|
||||
{
|
||||
if ( team_ != team )
|
||||
|
@ -144,17 +144,17 @@ void map_labels::set_team(const team* team)
|
|||
}
|
||||
|
||||
|
||||
const terrain_label* map_labels::set_label(const gamemap::location& loc,
|
||||
const std::string& text,
|
||||
const std::string team_name,
|
||||
const terrain_label* map_labels::set_label(const gamemap::location& loc,
|
||||
const std::string& text,
|
||||
const std::string team_name,
|
||||
const SDL_Color colour)
|
||||
{
|
||||
terrain_label* res = 0;
|
||||
const team_label_map::const_iterator current_label_map = labels_.find(team_name);
|
||||
label_map::const_iterator current_label;
|
||||
|
||||
|
||||
if ( current_label_map != labels_.end()
|
||||
&& (current_label = current_label_map->second.find(loc)) != current_label_map->second.end() )
|
||||
&& (current_label = current_label_map->second.find(loc)) != current_label_map->second.end() )
|
||||
{
|
||||
// Found old checking if need to erase it
|
||||
if(text.empty())
|
||||
|
@ -163,7 +163,7 @@ const terrain_label* map_labels::set_label(const gamemap::location& loc,
|
|||
res = new terrain_label("",team_name,loc,*this,colour);
|
||||
delete current_label->second;
|
||||
const_cast<label_map&>(current_label_map->second).erase(loc);
|
||||
|
||||
|
||||
team_label_map::iterator global_label_map = labels_.find("");
|
||||
label_map::iterator itor;
|
||||
bool update = false;
|
||||
|
@ -175,7 +175,7 @@ const terrain_label* map_labels::set_label(const gamemap::location& loc,
|
|||
{
|
||||
const_cast<terrain_label*>(itor->second)->recalculate();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -201,9 +201,9 @@ const terrain_label* map_labels::set_label(const gamemap::location& loc,
|
|||
*this,
|
||||
colour);
|
||||
add_label(loc,label);
|
||||
|
||||
|
||||
res = label;
|
||||
|
||||
|
||||
if (update)
|
||||
{
|
||||
const_cast<terrain_label*>(itor->second)->recalculate();
|
||||
|
@ -221,12 +221,12 @@ const terrain_label* new_label)
|
|||
{
|
||||
labels_.insert(std::pair<std::string,label_map>(new_label->team_name(), label_map()));
|
||||
labs = labels_.find(new_label->team_name());
|
||||
|
||||
|
||||
wassert(labs != labels_.end());
|
||||
}
|
||||
|
||||
|
||||
const_cast<label_map&>(labs->second).insert(std::pair<gamemap::location,const terrain_label*>(loc,new_label));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void map_labels::clear(const std::string& team_name)
|
||||
|
@ -236,7 +236,7 @@ void map_labels::clear(const std::string& team_name)
|
|||
{
|
||||
clear_map(i->second);
|
||||
}
|
||||
|
||||
|
||||
i = labels_.find("");
|
||||
if (i != labels_.end())
|
||||
{
|
||||
|
@ -255,7 +255,7 @@ void map_labels::clear_map(const label_map& m)
|
|||
|
||||
void map_labels::clear_all()
|
||||
{
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
{
|
||||
clear_map(i->second);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void map_labels::clear_all()
|
|||
|
||||
void map_labels::scroll(double xmove, double ymove)
|
||||
{
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
{
|
||||
for (label_map::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ void map_labels::scroll(double xmove, double ymove)
|
|||
|
||||
void map_labels::recalculate_labels()
|
||||
{
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
{
|
||||
for (label_map::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
|
||||
{
|
||||
|
@ -287,13 +287,13 @@ void map_labels::recalculate_labels()
|
|||
bool map_labels::visible_global_label(const gamemap::location& loc) const
|
||||
{
|
||||
const team_label_map::const_iterator glabels = labels_.find(team_name());
|
||||
return glabels == labels_.end()
|
||||
return glabels == labels_.end()
|
||||
|| glabels->second.find(loc) == glabels->second.end();
|
||||
}
|
||||
|
||||
void map_labels::recalculate_shroud()
|
||||
{
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
|
||||
{
|
||||
for (label_map::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
|
||||
{
|
||||
|
@ -352,8 +352,8 @@ void terrain_label::read(const config& cfg, const variable_set *variables)
|
|||
{
|
||||
loc_ = gamemap::location(cfg, variables);
|
||||
SDL_Color colour = font::LABEL_COLOUR;
|
||||
std::string tmp_colour = cfg["colour"];
|
||||
|
||||
std::string tmp_colour = cfg["colour"];
|
||||
|
||||
text_ = cfg["text"];
|
||||
team_name_ = cfg["team_name"];
|
||||
|
||||
|
@ -387,7 +387,7 @@ void terrain_label::write(config& cfg) const
|
|||
cfg["text"] = text();
|
||||
cfg["team_name"] = (this->team_name());
|
||||
cfg["colour"] = cfg_colour();
|
||||
|
||||
|
||||
}
|
||||
|
||||
const std::string& terrain_label::text() const
|
||||
|
@ -440,13 +440,13 @@ void terrain_label::update_info(const std::string& text,
|
|||
draw();
|
||||
}
|
||||
|
||||
void terrain_label::scroll(const double xmove,
|
||||
void terrain_label::scroll(const double xmove,
|
||||
const double ymove) const
|
||||
{
|
||||
if(handle_)
|
||||
{
|
||||
font::move_floating_label(handle_,
|
||||
xmove,
|
||||
font::move_floating_label(handle_,
|
||||
xmove,
|
||||
ymove);
|
||||
}
|
||||
}
|
||||
|
@ -472,15 +472,15 @@ void terrain_label::draw()
|
|||
clear();
|
||||
if (visible())
|
||||
{
|
||||
|
||||
|
||||
const gamemap::location loc_nextx(loc_.x+1,loc_.y);
|
||||
const gamemap::location loc_nexty(loc_.x,loc_.y+1);
|
||||
const int xloc = (parent_->disp().get_location_x(loc_) +
|
||||
parent_->disp().get_location_x(loc_nextx)*2)/3;
|
||||
const int yloc = parent_->disp().get_location_y(loc_nexty) - font::SIZE_NORMAL;
|
||||
|
||||
|
||||
cfg_colour();
|
||||
|
||||
|
||||
handle_ = font::add_floating_label(text_,
|
||||
font::SIZE_NORMAL,
|
||||
colour_,
|
||||
|
@ -488,7 +488,7 @@ void terrain_label::draw()
|
|||
0,0,
|
||||
-1,
|
||||
parent_->disp().map_outside_area());
|
||||
|
||||
|
||||
calculate_shroud();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class map_labels
|
|||
public:
|
||||
typedef std::map<gamemap::location,const terrain_label*> label_map;
|
||||
typedef std::map<std::string,label_map> team_label_map;
|
||||
|
||||
|
||||
map_labels(const display& disp, const gamemap& map, const team*);
|
||||
map_labels(const display& disp, const config& cfg, const gamemap& map, const team*, const variable_set *variables);
|
||||
~map_labels();
|
||||
|
@ -46,14 +46,14 @@ public:
|
|||
static size_t get_max_chars();
|
||||
|
||||
const terrain_label* get_label(const gamemap::location& loc);
|
||||
const terrain_label* set_label(const gamemap::location& loc,
|
||||
const terrain_label* set_label(const gamemap::location& loc,
|
||||
const std::string& text,
|
||||
const std::string team = "",
|
||||
const SDL_Color colour = font::NORMAL_COLOUR);
|
||||
|
||||
|
||||
void add_label(const gamemap::location&,
|
||||
const terrain_label*);
|
||||
|
||||
|
||||
void clear(const std::string&);
|
||||
|
||||
void scroll(double xmove, double ymove);
|
||||
|
@ -64,9 +64,9 @@ public:
|
|||
void recalculate_shroud();
|
||||
|
||||
const display& disp() const;
|
||||
|
||||
|
||||
const std::string& team_name() const;
|
||||
|
||||
|
||||
void set_team(const team*);
|
||||
|
||||
private:
|
||||
|
@ -89,33 +89,33 @@ class terrain_label
|
|||
{
|
||||
public:
|
||||
terrain_label(const std::string&,
|
||||
const std::string&,
|
||||
const gamemap::location&,
|
||||
const map_labels&,
|
||||
const std::string&,
|
||||
const gamemap::location&,
|
||||
const map_labels&,
|
||||
const SDL_Color colour = font::NORMAL_COLOUR);
|
||||
|
||||
terrain_label(const map_labels&,
|
||||
|
||||
terrain_label(const map_labels&,
|
||||
const config&,
|
||||
const variable_set *variables);
|
||||
|
||||
|
||||
terrain_label(const map_labels&);
|
||||
|
||||
|
||||
~terrain_label();
|
||||
|
||||
|
||||
void write(config& res) const;
|
||||
void read(const config& cfg, const variable_set *variables);
|
||||
|
||||
|
||||
const std::string& text() const;
|
||||
const std::string& team_name() const;
|
||||
const gamemap::location& location() const;
|
||||
const SDL_Colour& colour() const;
|
||||
|
||||
|
||||
void set_text(const std::string&);
|
||||
|
||||
|
||||
void update_info(const std::string&,
|
||||
const std::string&,
|
||||
const SDL_Color);
|
||||
|
||||
const SDL_Color);
|
||||
|
||||
void scroll(double xmove, double ymove) const;
|
||||
|
||||
void recalculate();
|
||||
|
@ -129,16 +129,16 @@ private:
|
|||
bool visible() const;
|
||||
void check_text_length();
|
||||
const std::string cfg_colour() const;
|
||||
|
||||
|
||||
int handle_;
|
||||
|
||||
|
||||
std::string text_;
|
||||
std::string team_name_;
|
||||
SDL_Color colour_;
|
||||
|
||||
|
||||
const map_labels* parent_;
|
||||
gamemap::location loc_;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
230
src/mapgen.cpp
230
src/mapgen.cpp
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file mapgen.cpp
|
||||
//! @file mapgen.cpp
|
||||
//! Map-generator, with standalone testprogram.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -54,16 +54,16 @@ typedef t_translation::t_map terrain_map;
|
|||
typedef gamemap::location location;
|
||||
|
||||
//! Generate a height-map.
|
||||
//! Basically we generate alot of hills,
|
||||
//! each hill being centered at a certain point,
|
||||
//! Basically we generate alot of hills,
|
||||
//! each hill being centered at a certain point,
|
||||
//! with a certain radius - being a half sphere.
|
||||
//! Hills are combined additively to form a bumpy surface.
|
||||
//! The size of each hill varies randomly from 1-hill_size.
|
||||
//! We generate 'iterations' hills in total.
|
||||
//! The range of heights is normalized to 0-1000.
|
||||
//! 'island_size' controls whether or not the map should tend toward an island shape,
|
||||
//! and if so, how large the island should be.
|
||||
//! Hills with centers that are more than 'island_size' away from
|
||||
//! 'island_size' controls whether or not the map should tend toward an island shape,
|
||||
//! and if so, how large the island should be.
|
||||
//! Hills with centers that are more than 'island_size' away from
|
||||
//! the center of the map will be inverted (i.e. be valleys).
|
||||
//! 'island_size' as 0 indicates no island.
|
||||
static height_map generate_height_map(size_t width, size_t height,
|
||||
|
@ -102,13 +102,13 @@ static height_map generate_height_map(size_t width, size_t height,
|
|||
|
||||
for(size_t i = 0; i != iterations; ++i) {
|
||||
|
||||
// (x1,y1) is the location of the hill,
|
||||
// (x1,y1) is the location of the hill,
|
||||
// and 'radius' is the radius of the hill.
|
||||
// We iterate over all points, (x2,y2).
|
||||
// We iterate over all points, (x2,y2).
|
||||
// The formula for the amount the height is increased by is:
|
||||
// radius - sqrt((x2-x1)^2 + (y2-y1)^2) with negative values ignored.
|
||||
//
|
||||
// Rather than iterate over every single point, we can reduce the points
|
||||
// Rather than iterate over every single point, we can reduce the points
|
||||
// to a rectangle that contains all the positive values for this formula --
|
||||
// the rectangle is given by min_x,max_x,min_y,max_y.
|
||||
|
||||
|
@ -183,11 +183,11 @@ static height_map generate_height_map(size_t width, size_t height,
|
|||
return res;
|
||||
}
|
||||
|
||||
//! Generate a lake.
|
||||
//! It will create water at (x,y), and then have 'lake_fall_off' % chance
|
||||
//! Generate a lake.
|
||||
//! It will create water at (x,y), and then have 'lake_fall_off' % chance
|
||||
//! to make another water tile in each of the directions n,s,e,w.
|
||||
//! In each of the directions it does make another water tile,
|
||||
//! it will have 'lake_fall_off'/2 % chance to make another water tile
|
||||
//! In each of the directions it does make another water tile,
|
||||
//! it will have 'lake_fall_off'/2 % chance to make another water tile
|
||||
//! in each of the directions. This will continue recursively.
|
||||
static bool generate_lake(terrain_map& terrain, int x, int y, int lake_fall_off, std::set<location>& locs_touched)
|
||||
{
|
||||
|
@ -220,36 +220,36 @@ static bool generate_lake(terrain_map& terrain, int x, int y, int lake_fall_off,
|
|||
typedef gamemap::location location;
|
||||
|
||||
//! River generation.
|
||||
//! Rivers have a source, and then keep on flowing
|
||||
//! until they meet another body of water, which they flow into,
|
||||
//! or until they reach the edge of the map.
|
||||
//! Rivers will always flow downhill, except that they can flow
|
||||
//! Rivers have a source, and then keep on flowing
|
||||
//! until they meet another body of water, which they flow into,
|
||||
//! or until they reach the edge of the map.
|
||||
//! Rivers will always flow downhill, except that they can flow
|
||||
//! a maximum of 'river_uphill' uphill.
|
||||
//! This is to represent the water eroding the higher ground lower.
|
||||
//!
|
||||
//! Every possible path for a river will be attempted, in random order,
|
||||
//! and the first river path that can be found that makes the river flow
|
||||
//! into another body of water or off the map will be used.
|
||||
//! Every possible path for a river will be attempted, in random order,
|
||||
//! and the first river path that can be found that makes the river flow
|
||||
//! into another body of water or off the map will be used.
|
||||
//!
|
||||
//! If no path can be found, then the river's generation will be aborted,
|
||||
//! and false will be returned.
|
||||
//! If no path can be found, then the river's generation will be aborted,
|
||||
//! and false will be returned.
|
||||
//! true is returned if the river is generated successfully.
|
||||
static bool generate_river_internal(const height_map& heights,
|
||||
terrain_map& terrain, int x, int y, std::vector<location>& river,
|
||||
static bool generate_river_internal(const height_map& heights,
|
||||
terrain_map& terrain, int x, int y, std::vector<location>& river,
|
||||
std::set<location>& seen_locations, int river_uphill)
|
||||
{
|
||||
const bool on_map = x >= 0 && y >= 0 &&
|
||||
x < static_cast<long>(heights.size()) &&
|
||||
const bool on_map = x >= 0 && y >= 0 &&
|
||||
x < static_cast<long>(heights.size()) &&
|
||||
y < static_cast<long>(heights.back().size());
|
||||
|
||||
if(on_map && !river.empty() && heights[x][y] >
|
||||
if(on_map && !river.empty() && heights[x][y] >
|
||||
heights[river.back().x][river.back().y] + river_uphill) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we're at the end of the river
|
||||
if(!on_map || terrain[x][y] == t_translation::SHALLOW_WATER ||
|
||||
if(!on_map || terrain[x][y] == t_translation::SHALLOW_WATER ||
|
||||
terrain[x][y] == t_translation::DEEP_WATER) {
|
||||
|
||||
LOG_NG << "generating river...\n";
|
||||
|
@ -302,7 +302,7 @@ static std::vector<location> generate_river(const height_map& heights, terrain_m
|
|||
return river;
|
||||
}
|
||||
|
||||
//! Return a random tile at one of the borders of a map
|
||||
//! Return a random tile at one of the borders of a map
|
||||
//! that is of the given dimensions.
|
||||
static location random_point_at_side(size_t width, size_t height)
|
||||
{
|
||||
|
@ -319,11 +319,11 @@ static location random_point_at_side(size_t width, size_t height)
|
|||
}
|
||||
|
||||
//! Function which, given the map will output it in a valid format.
|
||||
static std::string output_map(const terrain_map& terrain,
|
||||
static std::string output_map(const terrain_map& terrain,
|
||||
std::map<int, t_translation::coordinate> starting_positions)
|
||||
{
|
||||
// Remember that we only want the middle 1/9th of the map.
|
||||
// All other segments of the map are there only to give
|
||||
// Remember that we only want the middle 1/9th of the map.
|
||||
// All other segments of the map are there only to give
|
||||
// the important middle part some context.
|
||||
const size_t begin_x = terrain.size()/3;
|
||||
const size_t end_x = begin_x*2;
|
||||
|
@ -341,7 +341,7 @@ static std::string output_map(const terrain_map& terrain,
|
|||
}
|
||||
}
|
||||
|
||||
// Since the map has been resized,
|
||||
// Since the map has been resized,
|
||||
// the starting locations also need to be fixed
|
||||
std::map<int, t_translation::coordinate>::iterator itor = starting_positions.begin();
|
||||
for(; itor != starting_positions.end(); ++itor) {
|
||||
|
@ -372,14 +372,14 @@ private:
|
|||
const config& cfg_;
|
||||
int windiness_;
|
||||
mutable std::map<location, double> loc_cache_;
|
||||
mutable std::map<t_translation::t_letter, double> cache_;
|
||||
mutable std::map<t_translation::t_letter, double> cache_;
|
||||
};
|
||||
|
||||
double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
||||
double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
||||
const double /*so_far*/, const bool /*isDst*/) const
|
||||
{
|
||||
++calls;
|
||||
if (loc.x < 0 || loc.y < 0 || loc.x >= static_cast<long>(map_.size()) ||
|
||||
if (loc.x < 0 || loc.y < 0 || loc.x >= static_cast<long>(map_.size()) ||
|
||||
loc.y >= static_cast<long>(map_.front().size())) {
|
||||
|
||||
return (getNoPathValue());
|
||||
|
@ -390,11 +390,11 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
return val->second;
|
||||
}
|
||||
|
||||
// We multiply the cost by a random amount,
|
||||
// depending upon how 'windy' the road should be.
|
||||
// If windiness is 1, that will mean that the cost is always genuine,
|
||||
// and so the road always takes the shortest path.
|
||||
// If windiness is greater than 1, we sometimes over-report costs
|
||||
// We multiply the cost by a random amount,
|
||||
// depending upon how 'windy' the road should be.
|
||||
// If windiness is 1, that will mean that the cost is always genuine,
|
||||
// and so the road always takes the shortest path.
|
||||
// If windiness is greater than 1, we sometimes over-report costs
|
||||
// for some segments, to make the road wind a little.
|
||||
const double windiness = windiness_ > 0 ? (double(rand()%windiness_) + 1.0) : 1.0;
|
||||
|
||||
|
@ -404,7 +404,7 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
return itor->second*windiness;
|
||||
}
|
||||
|
||||
static std::string terrain;
|
||||
static std::string terrain;
|
||||
terrain = t_translation::write_letter(c);
|
||||
const config* const child = cfg_.find_child("road_cost","terrain",terrain);
|
||||
double res = getNoPathValue();
|
||||
|
@ -420,7 +420,7 @@ double road_path_calculator::cost(const location& /*src*/, const location& loc,
|
|||
//!
|
||||
struct is_valid_terrain
|
||||
{
|
||||
is_valid_terrain(const t_translation::t_map& map,
|
||||
is_valid_terrain(const t_translation::t_map& map,
|
||||
const t_translation::t_list& terrain_list);
|
||||
bool operator()(int x, int y) const;
|
||||
private:
|
||||
|
@ -428,19 +428,19 @@ private:
|
|||
const t_translation::t_list& terrain_;
|
||||
};
|
||||
|
||||
is_valid_terrain::is_valid_terrain(const t_translation::t_map& map,
|
||||
is_valid_terrain::is_valid_terrain(const t_translation::t_map& map,
|
||||
const t_translation::t_list& terrain_list)
|
||||
: map_(map), terrain_(terrain_list)
|
||||
{}
|
||||
|
||||
bool is_valid_terrain::operator()(int x, int y) const
|
||||
{
|
||||
if(x < 0 || x >= static_cast<long>(map_.size()) ||
|
||||
if(x < 0 || x >= static_cast<long>(map_.size()) ||
|
||||
y < 0 || y >= static_cast<long>(map_[x].size())) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return std::find(terrain_.begin(),terrain_.end(),map_[x][y]) != terrain_.end();
|
||||
}
|
||||
|
||||
|
@ -521,10 +521,10 @@ static gamemap::location place_village(const t_translation::t_map& map,
|
|||
get_tiles_radius(loc,radius,locs);
|
||||
gamemap::location best_loc;
|
||||
size_t best_rating = 0;
|
||||
for(std::set<gamemap::location>::const_iterator i = locs.begin();
|
||||
for(std::set<gamemap::location>::const_iterator i = locs.begin();
|
||||
i != locs.end(); ++i) {
|
||||
|
||||
if(i->x < 0 || i->y < 0 || i->x >= static_cast<long>(map.size()) ||
|
||||
if(i->x < 0 || i->y < 0 || i->x >= static_cast<long>(map.size()) ||
|
||||
i->y >= static_cast<long>(map[i->x].size())) {
|
||||
|
||||
continue;
|
||||
|
@ -537,15 +537,15 @@ static gamemap::location place_village(const t_translation::t_map& map,
|
|||
gamemap::location adj[6];
|
||||
get_adjacent_tiles(gamemap::location(i->x,i->y),adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
if(adj[n].x < 0 || adj[n].y < 0 ||
|
||||
adj[n].x >= static_cast<long>(map.size()) ||
|
||||
if(adj[n].x < 0 || adj[n].y < 0 ||
|
||||
adj[n].x >= static_cast<long>(map.size()) ||
|
||||
adj[n].y >= static_cast<long>(map[adj[n].x].size())) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const t_translation::t_letter t = map[adj[n].x][adj[n].y];
|
||||
const t_translation::t_list& adjacent_liked =
|
||||
const t_translation::t_list& adjacent_liked =
|
||||
t_translation::read_list((*child)["adjacent_liked"]);
|
||||
|
||||
rating += std::count(adjacent_liked.begin(),adjacent_liked.end(),t);
|
||||
|
@ -599,8 +599,8 @@ namespace {
|
|||
// height=n
|
||||
// terrain=x
|
||||
// [/height]
|
||||
// These should be in descending order of n.
|
||||
// They are checked sequentially, and if height is greater than n for that tile,
|
||||
// These should be in descending order of n.
|
||||
// They are checked sequentially, and if height is greater than n for that tile,
|
||||
// then the tile is set to terrain type x.
|
||||
class terrain_height_mapper
|
||||
{
|
||||
|
@ -615,8 +615,8 @@ private:
|
|||
t_translation::t_letter to;
|
||||
};
|
||||
|
||||
terrain_height_mapper::terrain_height_mapper(const config& cfg) :
|
||||
terrain_height(lexical_cast_default<int>(cfg["height"],0)),
|
||||
terrain_height_mapper::terrain_height_mapper(const config& cfg) :
|
||||
terrain_height(lexical_cast_default<int>(cfg["height"],0)),
|
||||
to(t_translation::GRASS_LAND)
|
||||
{
|
||||
const std::string& terrain = cfg["terrain"];
|
||||
|
@ -649,9 +649,9 @@ private:
|
|||
t_translation::t_letter to;
|
||||
};
|
||||
|
||||
terrain_converter::terrain_converter(const config& cfg) : min_temp(-1),
|
||||
max_temp(-1), min_height(-1), max_height(-1),
|
||||
from(t_translation::read_list(cfg["from"])),
|
||||
terrain_converter::terrain_converter(const config& cfg) : min_temp(-1),
|
||||
max_temp(-1), min_height(-1), max_height(-1),
|
||||
from(t_translation::read_list(cfg["from"])),
|
||||
to(t_translation::NONE_TERRAIN)
|
||||
{
|
||||
min_temp = lexical_cast_default<int>(cfg["min_temperature"],-100000);
|
||||
|
@ -665,7 +665,7 @@ terrain_converter::terrain_converter(const config& cfg) : min_temp(-1),
|
|||
}
|
||||
}
|
||||
|
||||
bool terrain_converter::convert_terrain(const t_translation::t_letter terrain,
|
||||
bool terrain_converter::convert_terrain(const t_translation::t_letter terrain,
|
||||
const int height, const int temperature) const
|
||||
{
|
||||
return std::find(from.begin(),from.end(),terrain) != from.end() && height >= min_height && height <= max_height &&
|
||||
|
@ -677,7 +677,7 @@ t_translation::t_letter terrain_converter::convert_to() const
|
|||
return to;
|
||||
}
|
||||
|
||||
} // end anon namespace
|
||||
} // end anon namespace
|
||||
|
||||
//! Generate the map.
|
||||
std::string default_generate_map(size_t width, size_t height, size_t island_size, size_t island_off_center,
|
||||
|
@ -696,15 +696,15 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
std::string flatland = cfg["default_flatland"];
|
||||
if(flatland == "") {
|
||||
flatland = t_translation::write_letter(t_translation::GRASS_LAND);
|
||||
}
|
||||
}
|
||||
|
||||
const t_translation::t_letter grassland = t_translation::read_letter(flatland);
|
||||
|
||||
// We want to generate a map that is 9 times bigger
|
||||
// than the actual size desired.
|
||||
// Only the middle part of the map will be used,
|
||||
// but the rest is so that the map we end up using
|
||||
// can have a context (e.g. rivers flowing from
|
||||
// We want to generate a map that is 9 times bigger
|
||||
// than the actual size desired.
|
||||
// Only the middle part of the map will be used,
|
||||
// but the rest is so that the map we end up using
|
||||
// can have a context (e.g. rivers flowing from
|
||||
// out of the map into the map, same for roads, etc.)
|
||||
width *= 3;
|
||||
height *= 3;
|
||||
|
@ -748,17 +748,17 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
LOG_NG << "placed land forms\n";
|
||||
LOG_NG << (SDL_GetTicks() - ticks) << "\n"; ticks = SDL_GetTicks();
|
||||
|
||||
// Now that we have our basic set of flatland/hills/mountains/water,
|
||||
// we can place lakes and rivers on the map.
|
||||
// All rivers are sourced at a lake.
|
||||
// Lakes must be in high land - at least 'min_lake_height'.
|
||||
// (Note that terrain below a certain altitude may be made
|
||||
// into bodies of water in the code above - i.e. 'sea',
|
||||
// but these are not considered 'lakes', because
|
||||
// Now that we have our basic set of flatland/hills/mountains/water,
|
||||
// we can place lakes and rivers on the map.
|
||||
// All rivers are sourced at a lake.
|
||||
// Lakes must be in high land - at least 'min_lake_height'.
|
||||
// (Note that terrain below a certain altitude may be made
|
||||
// into bodies of water in the code above - i.e. 'sea',
|
||||
// but these are not considered 'lakes', because
|
||||
// they are not sources of rivers).
|
||||
//
|
||||
// We attempt to place 'max_lakes' lakes.
|
||||
// Each lake will be placed at a random location,
|
||||
// We attempt to place 'max_lakes' lakes.
|
||||
// Each lake will be placed at a random location,
|
||||
// if that random location meets the minimum terrain requirements for a lake.
|
||||
// We will also attempt to source a river from each lake.
|
||||
std::set<location> lake_locs;
|
||||
|
@ -804,7 +804,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
|
||||
std::set<location>::const_iterator i;
|
||||
|
||||
// Only generate a name if the lake hasn't touched any other lakes,
|
||||
// Only generate a name if the lake hasn't touched any other lakes,
|
||||
// so that we don't end up with one big lake with multiple names.
|
||||
for(i = locs.begin(); i != locs.end(); ++i) {
|
||||
if(lake_locs.count(*i) != 0) {
|
||||
|
@ -844,9 +844,9 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
const size_t default_dimensions = 40*40*9;
|
||||
|
||||
//! Convert grassland terrain to other types of flat terrain.
|
||||
//! We generate a 'temperature map' which uses the height generation algorithm
|
||||
//! to generate the temperature levels all over the map.
|
||||
//! Then we can use a combination of height and terrain
|
||||
//! We generate a 'temperature map' which uses the height generation algorithm
|
||||
//! to generate the temperature levels all over the map.
|
||||
//! Then we can use a combination of height and terrain
|
||||
//! to divide terrain up into more interesting types than the default.
|
||||
const height_map temperature_map = generate_height_map(width,height,
|
||||
(atoi(cfg["temperature_iterations"].c_str())*width*height)/default_dimensions,
|
||||
|
@ -865,7 +865,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
LOG_NG << (SDL_GetTicks() - ticks) << "\n"; ticks = SDL_GetTicks();
|
||||
|
||||
|
||||
// Iterate over every flatland tile, and determine
|
||||
// Iterate over every flatland tile, and determine
|
||||
// what type of flatland it is, based on our [convert] tags.
|
||||
for(x = 0; x != width; ++x) {
|
||||
for(y = 0; y != height; ++y) {
|
||||
|
@ -881,8 +881,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
LOG_NG << "placing villages...\n";
|
||||
LOG_NG << (SDL_GetTicks() - ticks) << "\n"; ticks = SDL_GetTicks();
|
||||
|
||||
//! Place villages in a 'grid', to make placing fair,
|
||||
//! but with villages displaced from their position
|
||||
//! Place villages in a 'grid', to make placing fair,
|
||||
//! but with villages displaced from their position
|
||||
//! according to terrain and randomness, to add some variety.
|
||||
std::set<location> villages;
|
||||
|
||||
|
@ -895,19 +895,19 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
return "";
|
||||
}
|
||||
|
||||
//! Castle configuration tag contains a 'valid_terrain' attribute
|
||||
//! Castle configuration tag contains a 'valid_terrain' attribute
|
||||
//! which is a list of terrains that the castle may appear on.
|
||||
const t_translation::t_list list =
|
||||
const t_translation::t_list list =
|
||||
t_translation::read_list((*castle_config)["valid_terrain"]);
|
||||
|
||||
const is_valid_terrain terrain_tester(terrain, list);
|
||||
|
||||
//! Attempt to place castles at random.
|
||||
//! Once we have placed castles, we run a sanity check
|
||||
//! to make sure that the castles are well-placed.
|
||||
//! If the castles are not well-placed, we try again.
|
||||
//! Definition of 'well-placed' is if no two castles
|
||||
//! are closer than 'min_distance' hexes from each other,
|
||||
//! Attempt to place castles at random.
|
||||
//! Once we have placed castles, we run a sanity check
|
||||
//! to make sure that the castles are well-placed.
|
||||
//! If the castles are not well-placed, we try again.
|
||||
//! Definition of 'well-placed' is if no two castles
|
||||
//! are closer than 'min_distance' hexes from each other,
|
||||
//! and the castles appear on a terrain listed in 'valid_terrain'.
|
||||
std::vector<location> castles;
|
||||
std::set<location> failed_locs;
|
||||
|
@ -948,8 +948,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
LOG_NG << "placing roads...\n";
|
||||
LOG_NG << (SDL_GetTicks() - ticks) << "\n"; ticks = SDL_GetTicks();
|
||||
|
||||
// Place roads.
|
||||
// We select two tiles at random locations on the borders
|
||||
// Place roads.
|
||||
// We select two tiles at random locations on the borders
|
||||
// of the map, and try to build roads between them.
|
||||
size_t nroads = atoi(cfg["roads"].c_str());
|
||||
if(roads_between_castles) {
|
||||
|
@ -962,8 +962,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
for(size_t road = 0; road != nroads; ++road) {
|
||||
log_scope("creating road");
|
||||
|
||||
//! We want the locations to be on the portion of the map
|
||||
//! we're actually going to use, since roads on other parts of the map
|
||||
//! We want the locations to be on the portion of the map
|
||||
//! we're actually going to use, since roads on other parts of the map
|
||||
//! won't have any influence, and doing it like this will be quicker.
|
||||
location src = random_point_at_side(width/3 + 2,height/3 + 2);
|
||||
location dst = random_point_at_side(width/3 + 2,height/3 + 2);
|
||||
|
@ -1002,15 +1002,15 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
|
||||
bool on_bridge = false;
|
||||
|
||||
// Draw the road.
|
||||
// Draw the road.
|
||||
// If the search failed, rt.steps will simply be empty.
|
||||
for(std::vector<location>::const_iterator step = rt.steps.begin();
|
||||
for(std::vector<location>::const_iterator step = rt.steps.begin();
|
||||
step != rt.steps.end(); ++step) {
|
||||
|
||||
const int x = step->x;
|
||||
const int y = step->y;
|
||||
|
||||
if(x < 0 || y < 0 || x >= static_cast<long>(width) ||
|
||||
if(x < 0 || y < 0 || x >= static_cast<long>(width) ||
|
||||
y >= static_cast<long>(height)) {
|
||||
|
||||
continue;
|
||||
|
@ -1018,19 +1018,19 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
|
||||
calc.terrain_changed(*step);
|
||||
|
||||
// Find the configuration which tells us
|
||||
// Find the configuration which tells us
|
||||
// what to convert this tile to, to make it into a road.
|
||||
const config* const child = cfg.find_child("road_cost", "terrain",
|
||||
const config* const child = cfg.find_child("road_cost", "terrain",
|
||||
t_translation::write_letter(terrain[x][y]));
|
||||
if(child != NULL) {
|
||||
// Convert to bridge means that we want to convert
|
||||
// Convert to bridge means that we want to convert
|
||||
// depending upon the direction the road is going.
|
||||
// Typically it will be in a format like,
|
||||
// convert_to_bridge=\,|,/
|
||||
// '|' will be used if the road is going north-south
|
||||
// '/' will be used if the road is going south west-north east
|
||||
// '\' will be used if the road is going south east-north west
|
||||
// The terrain will be left unchanged otherwise
|
||||
// The terrain will be left unchanged otherwise
|
||||
// (if there is no clear direction).
|
||||
const std::string& convert_to_bridge = (*child)["convert_to_bridge"];
|
||||
if(convert_to_bridge.empty() == false) {
|
||||
|
@ -1083,7 +1083,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
// Just a plain terrain substitution for a road
|
||||
const std::string& convert_to = (*child)["convert_to"];
|
||||
if(convert_to.empty() == false) {
|
||||
const t_translation::t_letter letter =
|
||||
const t_translation::t_letter letter =
|
||||
t_translation::read_letter(convert_to);
|
||||
if(labels != NULL && terrain[x][y] != letter && name_count++ == name_frequency && on_bridge == false) {
|
||||
labels->insert(std::pair<gamemap::location,std::string>(gamemap::location(x-width/3,y-height/3),name));
|
||||
|
@ -1112,7 +1112,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
const struct t_translation::coordinate coord = {x, y};
|
||||
starting_positions.insert(std::pair<int, t_translation::coordinate>(player, coord));
|
||||
terrain[x][y] = t_translation::HUMAN_KEEP;
|
||||
|
||||
|
||||
const int castles[13][2] = {
|
||||
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}, {-1, 1},
|
||||
{-2, 1}, {-2, 0}, {-2, -1}, {-1, -2}, {0, -2}, {1, -2}
|
||||
|
@ -1150,8 +1150,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
const size_t tiles_per_village = ((width*height)/9)/nvillages;
|
||||
size_t village_x = 1, village_y = 1;
|
||||
|
||||
// Alternate between incrementing the x and y value.
|
||||
// When they are high enough to equal or exceed the tiles_per_village,
|
||||
// Alternate between incrementing the x and y value.
|
||||
// When they are high enough to equal or exceed the tiles_per_village,
|
||||
// then we have them to the value we want them at.
|
||||
while(village_x*village_y < tiles_per_village) {
|
||||
if(village_x < village_y) {
|
||||
|
@ -1174,19 +1174,19 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
|
||||
const gamemap::location res = place_village(terrain,x,y,2,cfg);
|
||||
|
||||
if(res.x >= static_cast<long>(width) / 3 &&
|
||||
res.x < static_cast<long>(width * 2) / 3 &&
|
||||
res.y >= static_cast<long>(height) / 3 &&
|
||||
if(res.x >= static_cast<long>(width) / 3 &&
|
||||
res.x < static_cast<long>(width * 2) / 3 &&
|
||||
res.y >= static_cast<long>(height) / 3 &&
|
||||
res.y < static_cast<long>(height * 2) / 3) {
|
||||
|
||||
const std::string str =
|
||||
const std::string str =
|
||||
t_translation::write_letter(terrain[res.x][res.y]);
|
||||
const config* const child =
|
||||
const config* const child =
|
||||
cfg.find_child("village","terrain",str);
|
||||
if(child != NULL) {
|
||||
const std::string& convert_to = (*child)["convert_to"];
|
||||
if(convert_to != "") {
|
||||
terrain[res.x][res.y] =
|
||||
terrain[res.x][res.y] =
|
||||
t_translation::read_letter(convert_to);
|
||||
|
||||
villages.insert(res);
|
||||
|
@ -1198,7 +1198,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
get_adjacent_tiles(loc,adj);
|
||||
|
||||
std::string name_type = "village_name";
|
||||
const t_translation::t_list
|
||||
const t_translation::t_list
|
||||
field = t_translation::t_list(1, t_translation::GRASS_LAND),
|
||||
forest = t_translation::t_list(1, t_translation::FOREST),
|
||||
mountain = t_translation::t_list(1, t_translation::MOUNTAIN),
|
||||
|
@ -1229,9 +1229,9 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
break;
|
||||
}
|
||||
|
||||
const t_translation::t_letter terr =
|
||||
const t_translation::t_letter terr =
|
||||
terrain[adj[n].x+width/3][adj[n].y+height/3];
|
||||
|
||||
|
||||
if(std::count(field.begin(),field.end(),terr) > 0) {
|
||||
++field_count;
|
||||
} else if(std::count(forest.begin(),forest.end(),terr) > 0) {
|
||||
|
@ -1289,7 +1289,7 @@ generator_map generators;
|
|||
//! Standalone testprogram for the mapgenerator.
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int x = 50, y = 50, iterations = 50,
|
||||
int x = 50, y = 50, iterations = 50,
|
||||
hill_size = 50, lakes=3,
|
||||
nvillages = 25, nplayers = 2;
|
||||
if(argc >= 2) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file mapgen.hpp
|
||||
//! @file mapgen.hpp
|
||||
//!
|
||||
|
||||
#ifndef MAP_GEN_HPP_INCLUDED
|
||||
|
@ -36,16 +36,16 @@ public:
|
|||
//! which allows the user to modify how the generator behaves.
|
||||
virtual bool allow_user_config() const = 0;
|
||||
|
||||
//! Display the interactive screen, which allows the user
|
||||
//! to modify how the generator behaves.
|
||||
//! Display the interactive screen, which allows the user
|
||||
//! to modify how the generator behaves.
|
||||
//! (This function will not be called if allow_user_config() returns false).
|
||||
virtual void user_config(display& disp) = 0;
|
||||
|
||||
//! Returns a string identifying the generator by name.
|
||||
//! Returns a string identifying the generator by name.
|
||||
//! The name should not contain spaces.
|
||||
virtual std::string name() const = 0;
|
||||
|
||||
//! Creates a new map and returns it.
|
||||
//! Creates a new map and returns it.
|
||||
//! args may contain arguments to the map generator.
|
||||
virtual std::string create_map(const std::vector<std::string>& args) = 0;
|
||||
|
||||
|
|
|
@ -374,11 +374,11 @@ config default_map_generator::create_scenario(const std::vector<std::string>& ar
|
|||
res["map_data"] = generate_map(args,&labels);
|
||||
std::cerr << "done generating map..\n";
|
||||
|
||||
for(std::map<gamemap::location,std::string>::const_iterator i =
|
||||
for(std::map<gamemap::location,std::string>::const_iterator i =
|
||||
labels.begin(); i != labels.end(); ++i) {
|
||||
|
||||
if(i->first.x >= 0 && i->first.y >= 0 &&
|
||||
i->first.x < static_cast<long>(width_) &&
|
||||
if(i->first.x >= 0 && i->first.y >= 0 &&
|
||||
i->first.x < static_cast<long>(width_) &&
|
||||
i->first.y < static_cast<long>(height_)) {
|
||||
|
||||
config& label = res.add_child("label");
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file marked-up_text.cpp
|
||||
//! @file marked-up_text.cpp
|
||||
//! Support for simple markup in text (fonts, colors, images).
|
||||
//! E.g. "@Victory" will be shown in green.
|
||||
|
||||
|
@ -26,19 +26,19 @@
|
|||
|
||||
namespace font {
|
||||
|
||||
const char LARGE_TEXT='*', SMALL_TEXT='`',
|
||||
BOLD_TEXT='~', NORMAL_TEXT='{',
|
||||
NULL_MARKUP='^',
|
||||
const char LARGE_TEXT='*', SMALL_TEXT='`',
|
||||
BOLD_TEXT='~', NORMAL_TEXT='{',
|
||||
NULL_MARKUP='^',
|
||||
BLACK_TEXT='}', GRAY_TEXT='|',
|
||||
GOOD_TEXT='@', BAD_TEXT='#',
|
||||
GREEN_TEXT='@', RED_TEXT='#',
|
||||
COLOR_TEXT='<', IMAGE='&';
|
||||
|
||||
//! Parses the markup-tags at the front of a string.
|
||||
static std::string::const_iterator parse_markup(std::string::const_iterator i1,
|
||||
std::string::const_iterator i2,
|
||||
int* font_size,
|
||||
SDL_Color* colour, int* style)
|
||||
static std::string::const_iterator parse_markup(std::string::const_iterator i1,
|
||||
std::string::const_iterator i2,
|
||||
int* font_size,
|
||||
SDL_Color* colour, int* style)
|
||||
{
|
||||
if(font_size == NULL || colour == NULL) {
|
||||
return i1;
|
||||
|
@ -154,7 +154,7 @@ SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
|
|||
const SDL_Color& colour, const std::string& txt,
|
||||
int x, int y, bool use_tooltips, int style)
|
||||
{
|
||||
// Make sure there's always at least a space,
|
||||
// Make sure there's always at least a space,
|
||||
// so we can ensure that we can return a rectangle for height
|
||||
static const std::string blank_text(" ");
|
||||
const std::string& text = txt.empty() ? blank_text : txt;
|
||||
|
@ -303,7 +303,7 @@ inline bool break_after(wchar_t ch)
|
|||
(ch >= 0xff00 && ch < 0xfff0);
|
||||
}
|
||||
|
||||
} // end of anon namespace
|
||||
} // end of anon namespace
|
||||
|
||||
std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int max_width, int max_height, int max_lines)
|
||||
{
|
||||
|
@ -328,7 +328,7 @@ std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int
|
|||
if(start_of_line) {
|
||||
line_width = 0;
|
||||
format_string = "";
|
||||
while(ch != end && *ch < static_cast<wchar_t>(0x100)
|
||||
while(ch != end && *ch < static_cast<wchar_t>(0x100)
|
||||
&& is_format_char(*ch) && !ch.next_is_end()) {
|
||||
|
||||
format_string.append(ch.substr().first, ch.substr().second);
|
||||
|
@ -384,7 +384,7 @@ std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int
|
|||
|
||||
if(static_cast<long>(line_width) > max_width) {
|
||||
if(static_cast<long>(word_width) > max_width) {
|
||||
cut_word(current_line,
|
||||
cut_word(current_line,
|
||||
current_word, font_sz, style, max_width);
|
||||
}
|
||||
if(current_word == " ")
|
||||
|
|
|
@ -22,14 +22,14 @@ class CVideo;
|
|||
namespace font {
|
||||
|
||||
// Standard markups
|
||||
extern const char LARGE_TEXT, SMALL_TEXT, BOLD_TEXT, NORMAL_TEXT, NULL_MARKUP, BLACK_TEXT, GRAY_TEXT,
|
||||
extern const char LARGE_TEXT, SMALL_TEXT, BOLD_TEXT, NORMAL_TEXT, NULL_MARKUP, BLACK_TEXT, GRAY_TEXT,
|
||||
GOOD_TEXT, BAD_TEXT, GREEN_TEXT, RED_TEXT, COLOR_TEXT, YELLOW_TEXT, IMAGE;
|
||||
|
||||
|
||||
//Function to draw text on the screen. The text will be clipped to area.
|
||||
//If the text runs outside of area horizontally, an ellipsis will be displayed
|
||||
//at the end of it.
|
||||
//If use_tooltips is true, then text with an ellipsis will have a tooltip
|
||||
//If use_tooltips is true, then text with an ellipsis will have a tooltip
|
||||
//set for it equivalent to the entire contents of the text.
|
||||
//
|
||||
//Some very basic 'markup' will be done on the text:
|
||||
|
@ -51,7 +51,7 @@ SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
|
|||
// Function which returns the size of text if it were to be drawn.
|
||||
SDL_Rect text_area(const std::string& text, int size, int style=0);
|
||||
|
||||
// Copy string but without tags at the begining
|
||||
// Copy string but without tags at the begining
|
||||
std::string del_tags(const std::string& text);
|
||||
|
||||
bool is_format_char(char c);
|
||||
|
|
|
@ -376,7 +376,7 @@ namespace events{
|
|||
if(i->second.can_advance()) {
|
||||
row << i->second.max_experience();
|
||||
} else {
|
||||
row << "-";
|
||||
row << "-";
|
||||
}
|
||||
row << COLUMN_SEPARATOR;
|
||||
|
||||
|
@ -407,10 +407,10 @@ namespace events{
|
|||
row << IMAGE_PREFIX << "misc/poisoned.png" << IMG_TEXT_SEPARATOR;
|
||||
|
||||
//! @todo FIXME: condition for "invisible" does not work
|
||||
//if(utils::string_bool(i->second.get_state("hides"))) // "hides" gives ability, not status
|
||||
//if(utils::string_bool(i->second.get_state("hides"))) // "hides" gives ability, not status
|
||||
if(utils::string_bool(i->second.get_state("invisible")))
|
||||
row << IMAGE_PREFIX << "misc/invisible.png";
|
||||
//%%
|
||||
//%%
|
||||
items.push_back(row.str());
|
||||
|
||||
locations_list.push_back(i->first);
|
||||
|
@ -533,8 +533,8 @@ private:
|
|||
<< data.teamname << COLUMN_SEPARATOR;
|
||||
|
||||
if(!known && !game_config::debug) {
|
||||
// We don't spare more info (only name)
|
||||
// so let's go on next side ...
|
||||
// We don't spare more info (only name)
|
||||
// so let's go on next side ...
|
||||
items.push_back(str.str());
|
||||
continue;
|
||||
}
|
||||
|
@ -756,7 +756,7 @@ private:
|
|||
}
|
||||
//recall list
|
||||
{
|
||||
for(std::map<std::string, player_info>::const_iterator i=gamestate_.players.begin();
|
||||
for(std::map<std::string, player_info>::const_iterator i=gamestate_.players.begin();
|
||||
i!=gamestate_.players.end(); ++i) {
|
||||
for(std::vector<unit>::const_iterator j = i->second.available_units.begin();
|
||||
j != i->second.available_units.end(); ++j) {
|
||||
|
@ -953,7 +953,7 @@ private:
|
|||
|
||||
gui::dialog rmenu(*gui_,_("Recruit"),
|
||||
_("Select unit:") + std::string("\n"),
|
||||
gui::OK_CANCEL,
|
||||
gui::OK_CANCEL,
|
||||
gui::dialog::default_style);
|
||||
rmenu.add_button(new help::help_button(*gui_,"recruit_and_recall"),
|
||||
gui::dialog::BUTTON_HELP);
|
||||
|
@ -1102,7 +1102,7 @@ private:
|
|||
dialogs::unit_preview_pane unit_preview(*gui_,&map_,recall_list);
|
||||
gui::dialog rmenu(*gui_,_("Recall"),
|
||||
_("Select unit:") + std::string("\n"),
|
||||
gui::OK_CANCEL,
|
||||
gui::OK_CANCEL,
|
||||
gui::dialog::default_style);
|
||||
rmenu.add_button(new help::help_button(*gui_,"recruit_and_recall"),
|
||||
gui::dialog::BUTTON_HELP);
|
||||
|
@ -1141,7 +1141,7 @@ private:
|
|||
clear_undo_stack(team_num);
|
||||
} else {
|
||||
undo_stack_.push_back(undo_action(un,loc,res));
|
||||
}
|
||||
}
|
||||
|
||||
redo_stack_.clear();
|
||||
|
||||
|
|
|
@ -402,7 +402,7 @@ namespace{
|
|||
// We store a few of the highest probability hitpoint values.
|
||||
int nb_elem = minimum<int>(max_hp_distrib_rows_, prob_hp_vector.size());
|
||||
|
||||
for(i = prob_hp_vector.size() - nb_elem;
|
||||
for(i = prob_hp_vector.size() - nb_elem;
|
||||
i < static_cast<int>(prob_hp_vector.size()); i++) {
|
||||
|
||||
hp_prob_vector.push_back(std::pair<int, double>
|
||||
|
@ -799,7 +799,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
|
|||
|
||||
// show (or cancel) the attack direction indicator
|
||||
if (attack_from.valid() && !browse) {
|
||||
gui_->set_attack_indicator(attack_from, new_hex);
|
||||
gui_->set_attack_indicator(attack_from, new_hex);
|
||||
} else {
|
||||
gui_->clear_attack_indicator();
|
||||
}
|
||||
|
@ -822,7 +822,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
|
|||
dest = attack_from;
|
||||
dest_un = find_unit(dest);
|
||||
} else {
|
||||
dest = new_hex;
|
||||
dest = new_hex;
|
||||
dest_un = mouseover_unit;
|
||||
}
|
||||
|
||||
|
@ -943,7 +943,7 @@ paths::route mouse_handler::get_route(unit_map::const_iterator un, gamemap::loca
|
|||
// The pathfinder will check unit visibility (fogged/stealthy).
|
||||
unit u = un->second;
|
||||
const shortest_path_calculator calc(u,team,units_,teams_,map_);
|
||||
|
||||
|
||||
const std::set<gamemap::location>* teleports = NULL;
|
||||
std::set<gamemap::location> allowed_teleports;
|
||||
if(u.get_ability_bool("teleport",un->first)) {
|
||||
|
@ -951,9 +951,9 @@ paths::route mouse_handler::get_route(unit_map::const_iterator un, gamemap::loca
|
|||
teleports = &allowed_teleports;
|
||||
if(team.villages().count(un->first))
|
||||
allowed_teleports.insert(un->first);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
paths::route route = a_star_search(un->first, go_to, 10000.0, &calc, map_.w(), map_.h(), teleports);
|
||||
route.move_left = route_turns_to_complete(u,map_,route,units_,teams_);
|
||||
|
||||
|
@ -1032,12 +1032,12 @@ void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool br
|
|||
scrolly = - preferences::scroll_speed();
|
||||
} else if (event.button == SDL_BUTTON_WHEELDOWN) {
|
||||
scrolly = preferences::scroll_speed();
|
||||
} else if (event.button == SDL_BUTTON_WHEELLEFT) {
|
||||
} else if (event.button == SDL_BUTTON_WHEELLEFT) {
|
||||
scrollx = - preferences::scroll_speed();
|
||||
} else if (event.button == SDL_BUTTON_WHEELRIGHT) {
|
||||
} else if (event.button == SDL_BUTTON_WHEELRIGHT) {
|
||||
scrollx = preferences::scroll_speed();
|
||||
}
|
||||
|
||||
|
||||
if (scrollx != 0 || scrolly != 0) {
|
||||
CKey pressed;
|
||||
// Alt + mousewheel do an 90° rotation on the scroll direction
|
||||
|
@ -1046,7 +1046,7 @@ void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool br
|
|||
else
|
||||
gui_->scroll(scrollx,scrolly);
|
||||
}
|
||||
|
||||
|
||||
if (!dragging_ && dragging_started_) {
|
||||
dragging_started_ = false;
|
||||
cursor::set_dragging(false);
|
||||
|
@ -1190,7 +1190,7 @@ void mouse_handler::left_click(const SDL_MouseButtonEvent& event, const bool bro
|
|||
clear_undo_stack();
|
||||
}
|
||||
} else {
|
||||
// we select a (maybe empty) hex
|
||||
// we select a (maybe empty) hex
|
||||
gui_->unhighlight_reach();
|
||||
gui_->clear_attack_indicator();
|
||||
current_paths_ = paths();
|
||||
|
@ -1300,7 +1300,7 @@ bool mouse_handler::attack_enemy(unit_map::iterator attacker, unit_map::iterator
|
|||
lg::wml_error << "Memory exhausted a unit has either a lot hitpoints or a negative amount.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterator defender)
|
||||
|
@ -1422,7 +1422,7 @@ bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
|
|||
|
||||
check_victory(units_,teams_);
|
||||
|
||||
gui_->draw();
|
||||
gui_->draw();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -1168,7 +1168,7 @@ void connect::lists_init()
|
|||
{
|
||||
user_team_name = team_name;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string>::const_iterator itor = std::find(team_names_.begin(), team_names_.end(), team_name);
|
||||
if(itor == team_names_.end()) {
|
||||
team_names_.push_back(team_name);
|
||||
|
@ -1184,7 +1184,7 @@ void connect::lists_init()
|
|||
|
||||
if(team_name.empty())
|
||||
team_name = side_num;
|
||||
|
||||
|
||||
std::vector<std::string>::const_iterator itor = std::find(map_team_names.begin(), map_team_names.end(), team_name);
|
||||
if(itor == map_team_names.end()) {
|
||||
map_team_names.push_back(team_name);
|
||||
|
@ -1257,9 +1257,9 @@ void connect::load_game()
|
|||
}
|
||||
|
||||
if(state_.version != game_config::version) {
|
||||
// do not load if too old, if either the savegame or the current game
|
||||
// do not load if too old, if either the savegame or the current game
|
||||
// has the version 'test' allow loading
|
||||
if(state_.version < game_config::min_savegame_version &&
|
||||
if(state_.version < game_config::min_savegame_version &&
|
||||
game_config::test_version.full != state_.version &&
|
||||
game_config::test_version.full != game_config::version) {
|
||||
|
||||
|
@ -1314,7 +1314,7 @@ void connect::load_game()
|
|||
level_["mp_countdown_turn_bonus"] = lexical_cast_default<std::string>(params_.mp_countdown_turn_bonus, "35");
|
||||
level_["mp_countdown_reservoir_time"] = lexical_cast_default<std::string>(params_.mp_countdown_reservoir_time, "330");
|
||||
level_["mp_countdown_action_bonus"] = lexical_cast_default<std::string>(params_.mp_countdown_action_bonus, "13");
|
||||
|
||||
|
||||
if (params_.random_start_time)
|
||||
{
|
||||
if (!gamestatus::is_start_ToD(level_["random_start_time"]))
|
||||
|
@ -1392,14 +1392,14 @@ void connect::update_and_send_diff(bool update_time_of_day)
|
|||
{
|
||||
config old_level = level_;
|
||||
update_level();
|
||||
|
||||
|
||||
if (update_time_of_day)
|
||||
{
|
||||
// Set random start ToD
|
||||
// Set random start ToD
|
||||
gamestatus game_status(level_,atoi(level_["turns"].c_str()),&state_);
|
||||
|
||||
}
|
||||
|
||||
|
||||
config diff;
|
||||
diff.add_child("scenario_diff",level_.get_diff(old_level));
|
||||
network::send_data(diff);
|
||||
|
|
|
@ -411,7 +411,7 @@ void create::process_event()
|
|||
if(map_data.empty() && parameters_.scenario_data["map"] != "") {
|
||||
map_data = read_map(parameters_.scenario_data["map"]);
|
||||
}
|
||||
|
||||
|
||||
//if the map should be randomly generated
|
||||
if(parameters_.scenario_data["map_generation"] != "") {
|
||||
generator_.assign(create_map_generator(parameters_.scenario_data["map_generation"],parameters_.scenario_data.child("generator")));
|
||||
|
@ -519,30 +519,30 @@ void create::process_event()
|
|||
|
||||
// if the map settings are wanted use them if not properly defined
|
||||
// fall back to the default settings
|
||||
turns_slider_.set_value(map_settings ?
|
||||
turns_slider_.set_value(map_settings ?
|
||||
settings::get_turns(parameters_.scenario_data["turns"]) :
|
||||
preferences::turns());
|
||||
|
||||
xp_modifier_slider_.set_value(map_settings ?
|
||||
|
||||
xp_modifier_slider_.set_value(map_settings ?
|
||||
settings::get_xp_modifier(parameters_.scenario_data["experience_modifier"]) :
|
||||
preferences::xp_modifier());
|
||||
|
||||
random_start_time_.set_check(map_settings ?
|
||||
settings::use_random_start_time(parameters_.scenario_data["random_start_time"]) :
|
||||
preferences::random_start_time());
|
||||
|
||||
|
||||
// These are per player, always show of player 1 this might not be 100% correct,
|
||||
// but at the moment it's not possible to show the fog and shroud per player.
|
||||
// This might change in the future.
|
||||
// NOTE when 'load game' is selected there are no sides
|
||||
if(parameters_.scenario_data.get_children("side").size()) {
|
||||
|
||||
village_gold_slider_.set_value(map_settings ?
|
||||
village_gold_slider_.set_value(map_settings ?
|
||||
settings::get_village_gold((*parameters_.
|
||||
scenario_data.get_children("side").front())["village_gold"]) :
|
||||
preferences::village_gold());
|
||||
|
||||
fog_game_.set_check(map_settings ?
|
||||
fog_game_.set_check(map_settings ?
|
||||
settings::use_fog((*parameters_.
|
||||
scenario_data.get_children("side").front())["fog"]) :
|
||||
preferences::fog());
|
||||
|
@ -552,7 +552,7 @@ void create::process_event()
|
|||
scenario_data.get_children("side").front())["shroud"]) :
|
||||
preferences::shroud());
|
||||
}
|
||||
|
||||
|
||||
// set the widget states
|
||||
turns_slider_.enable(!map_settings);
|
||||
village_gold_slider_.enable(!map_settings);
|
||||
|
@ -639,7 +639,7 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
|
||||
const int border_size = 6;
|
||||
const int column_border_size = 10;
|
||||
|
||||
|
||||
int xpos = ca.x;
|
||||
int ypos = ca.y;
|
||||
|
||||
|
@ -657,9 +657,9 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
|
||||
// First column: minimap & random map options
|
||||
std::pair<int,int> resolution = preferences::resolution();
|
||||
|
||||
|
||||
const int resolution_for_small_minimap = 880;
|
||||
|
||||
|
||||
const int minimap_width = resolution.first > resolution_for_small_minimap ? 200 : 130;
|
||||
|
||||
SDL_Rect mmrect = { xpos, ypos, minimap_width, minimap_width };
|
||||
|
@ -777,7 +777,7 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
|
||||
const int border_size = 2;
|
||||
const int column_border_size = 5;
|
||||
|
||||
|
||||
int xpos = ca.x;
|
||||
int ypos = ca.y;
|
||||
|
||||
|
@ -804,16 +804,16 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
// First column: map list, era, generator
|
||||
num_players_label_.set_location(xpos, ypos);
|
||||
ypos += num_players_label_.height() + border_size;
|
||||
|
||||
|
||||
map_size_label_.set_location(xpos, ypos);
|
||||
ypos += map_size_label_.height() + border_size;
|
||||
|
||||
|
||||
map_label_.set_location(xpos, ypos);
|
||||
ypos += map_label_.height() + border_size;
|
||||
|
||||
maps_menu_.set_max_width(100);
|
||||
maps_menu_.set_max_height(50);
|
||||
|
||||
|
||||
maps_menu_.set_location(xpos, ypos);
|
||||
// Menu dimensions are only updated when items are set. So do this now.
|
||||
int mapsel_save = maps_menu_.selection();
|
||||
|
@ -831,12 +831,12 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
ypos += regenerate_map_.height() + border_size;
|
||||
generator_settings_.set_location(xpos, ypos);
|
||||
ypos += generator_settings_.height() + border_size;
|
||||
|
||||
|
||||
use_map_settings_.set_location(xpos, ypos);
|
||||
ypos += use_map_settings_.height() + border_size;
|
||||
random_start_time_.set_location(xpos, ypos);
|
||||
ypos += random_start_time_.height() + border_size;
|
||||
|
||||
|
||||
#ifdef MP_VISION_OPTIONAL
|
||||
vision_combo_.set_location(xpos, ypos);
|
||||
ypos += vision_combo_.height() + border_size;
|
||||
|
@ -881,7 +881,7 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
countdown_reservoir_time_slider_.set_width(32);
|
||||
countdown_reservoir_time_slider_.set_location(xpos, ypos);
|
||||
ypos += countdown_reservoir_time_slider_.height() + border_size;
|
||||
|
||||
|
||||
ypos = ypos_columntop;
|
||||
xpos += 75;
|
||||
|
||||
|
@ -896,7 +896,7 @@ void create::layout_children(const SDL_Rect& rect)
|
|||
|
||||
observers_game_.set_location(xpos, ypos);
|
||||
ypos += observers_game_.height() + border_size;
|
||||
|
||||
|
||||
countdown_turn_bonus_label_.set_location(xpos, ypos);
|
||||
ypos += countdown_turn_bonus_label_.height() + border_size;
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ namespace {
|
|||
public:
|
||||
user_menu_style() : gui::menu::imgsel_style("misc/selection", false,
|
||||
0x000000, 0x4a4440, 0x999999,
|
||||
0.0, 0.2, 0.2),
|
||||
item_size_(empty_rect)
|
||||
0.0, 0.2, 0.2),
|
||||
item_size_(empty_rect)
|
||||
{}
|
||||
virtual void init();
|
||||
virtual SDL_Rect item_size(const std::string& /*item*/) { return item_size_; }
|
||||
|
@ -53,7 +53,7 @@ namespace {
|
|||
{
|
||||
imgsel_style::init();
|
||||
item_size_.h = font::get_max_height(font_size_);
|
||||
scale_images(-1, item_size_.h);
|
||||
scale_images(-1, item_size_.h);
|
||||
item_size_.h += 2 * thickness_;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ void level_to_gamestate(config& level, game_state& state, bool saved_game)
|
|||
const config::child_list& level_sides = level.get_children("side");
|
||||
for(config::child_list::const_iterator side = snapshot_sides.begin(); side != snapshot_sides.end(); ++side) {
|
||||
for(config::child_list::const_iterator lside = level_sides.begin(); lside != level_sides.end(); ++lside) {
|
||||
if ( ((**side)["side"] == (**lside)["side"])
|
||||
if ( ((**side)["side"] == (**lside)["side"])
|
||||
&& ((**side)["current_player"] != (**lside)["current_player"]) ){
|
||||
(**side)["current_player"] = (**lside)["current_player"];
|
||||
(**side)["description"] = (**lside)["description"];
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file network.cpp
|
||||
//! @file network.cpp
|
||||
//! Networking
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -60,7 +60,7 @@
|
|||
namespace {
|
||||
|
||||
// We store the details of a connection in a map that must be looked up by its handle.
|
||||
// This allows a connection to be disconnected and then recovered,
|
||||
// This allows a connection to be disconnected and then recovered,
|
||||
// but the handle remains the same, so it's all seamless to the user.
|
||||
struct connection_details {
|
||||
connection_details(TCPsocket sock, const std::string& host, int port)
|
||||
|
@ -85,7 +85,7 @@ connection_map connections;
|
|||
|
||||
network::connection connection_id = 1;
|
||||
|
||||
} // end anon namespace
|
||||
} // end anon namespace
|
||||
|
||||
static int create_connection(TCPsocket sock, const std::string& host, int port)
|
||||
{
|
||||
|
@ -157,7 +157,7 @@ std::set<network::connection> bad_sockets;
|
|||
|
||||
network_worker_pool::manager* worker_pool_man = NULL;
|
||||
|
||||
} // end anon namespace
|
||||
} // end anon namespace
|
||||
|
||||
namespace network {
|
||||
|
||||
|
@ -296,7 +296,7 @@ namespace {
|
|||
IPaddress localAddress;
|
||||
int sflag;
|
||||
};
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
void connect_operation::run()
|
||||
{
|
||||
|
@ -386,7 +386,7 @@ void connect_operation::run()
|
|||
while(!notify_finished());
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
connection connect(const std::string& host, int port)
|
||||
{
|
||||
|
@ -415,10 +415,10 @@ connection accept_connection()
|
|||
}
|
||||
|
||||
// A connection isn't considered 'accepted' until it has sent its initial handshake.
|
||||
// The initial handshake is a 4 byte value, which is 0 for a new connection,
|
||||
// The initial handshake is a 4 byte value, which is 0 for a new connection,
|
||||
// or the handle of the connection if it's trying to recover a lost connection.
|
||||
|
||||
//! A list of all the sockets which have connected,
|
||||
//! A list of all the sockets which have connected,
|
||||
//! but haven't had their initial handshake received.
|
||||
static std::vector<TCPsocket> pending_sockets;
|
||||
static SDLNet_SocketSet pending_socket_set = 0;
|
||||
|
@ -452,7 +452,7 @@ connection accept_connection()
|
|||
continue;
|
||||
}
|
||||
|
||||
// Receive the 4 bytes telling us if they're a new connection
|
||||
// Receive the 4 bytes telling us if they're a new connection
|
||||
// or trying to recover a connection
|
||||
char buf[4];
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file network.hpp
|
||||
//! @file network.hpp
|
||||
//!
|
||||
|
||||
#ifndef NETWORK_HPP_INCLUDED
|
||||
|
@ -36,12 +36,12 @@ namespace network {
|
|||
// A network manager must be created before networking can be used.
|
||||
// It must be destroyed only after all networking activity stops.
|
||||
|
||||
// min_threads is the maximum number we allow to wait,
|
||||
// min_threads is the maximum number we allow to wait,
|
||||
// of more threads attempt to wait, they will die.
|
||||
// If min_threads == 0 no thread will ever be destroyed,
|
||||
// If min_threads == 0 no thread will ever be destroyed,
|
||||
// and we will stay at the max number of threads ever needed.
|
||||
|
||||
// max_threads is the overall max number of helper threads.
|
||||
// max_threads is the overall max number of helper threads.
|
||||
// If we have that many threads already running, we will never create more.
|
||||
// If max_threads == 0 we will always create a thread if we need it.
|
||||
struct manager {
|
||||
|
@ -55,14 +55,14 @@ private:
|
|||
void operator=(const manager&);
|
||||
};
|
||||
|
||||
//! A server manager causes listening on a given port
|
||||
//! A server manager causes listening on a given port
|
||||
//! to occur for the duration of its lifetime.
|
||||
struct server_manager {
|
||||
|
||||
//! Parameter to pass to the constructor.
|
||||
enum CREATE_SERVER { MUST_CREATE_SERVER, //!< Will throw exception on failure
|
||||
TRY_CREATE_SERVER, //!< Will swallow failure
|
||||
NO_SERVER }; //!< Won't try to create a server at all
|
||||
//! Parameter to pass to the constructor.
|
||||
enum CREATE_SERVER { MUST_CREATE_SERVER, //!< Will throw exception on failure
|
||||
TRY_CREATE_SERVER, //!< Will swallow failure
|
||||
NO_SERVER }; //!< Won't try to create a server at all
|
||||
|
||||
// Throws error.
|
||||
server_manager(int port, CREATE_SERVER create_server=MUST_CREATE_SERVER);
|
||||
|
@ -84,54 +84,54 @@ size_t nconnections();
|
|||
//! If we are currently accepting connections.
|
||||
bool is_server();
|
||||
|
||||
//! Function to attempt to connect to a remote host.
|
||||
//! Function to attempt to connect to a remote host.
|
||||
//! Returns the new connection on success, or 0 on failure.
|
||||
//! Throws error.
|
||||
connection connect(const std::string& host, int port=15000);
|
||||
|
||||
connection connect(const std::string& host, int port, threading::waiter& waiter);
|
||||
|
||||
//! Function to accept a connection from a remote host.
|
||||
//! Function to accept a connection from a remote host.
|
||||
//! If no host is attempting to connect, it will return 0 immediately.
|
||||
//! Otherwise returns the new connection.
|
||||
//! Throws error.
|
||||
connection accept_connection();
|
||||
|
||||
//! Function to disconnect from a certain host,
|
||||
//! Function to disconnect from a certain host,
|
||||
//! or close all connections if connection_num is 0.
|
||||
//! Returns true if the connection was disconnected.
|
||||
//! Returns false on failure to disconnect, since the socket is
|
||||
//! in the middle of sending/receiving data.
|
||||
//! in the middle of sending/receiving data.
|
||||
//! The socket will be closed when it has finished its send/receive.
|
||||
bool disconnect(connection connection_num=0);
|
||||
|
||||
//! Function to queue a disconnection.
|
||||
//! Next time receive_data is called, it will generate an error
|
||||
//! on the given connection (and presumably then the handling of the error
|
||||
//! Function to queue a disconnection.
|
||||
//! Next time receive_data is called, it will generate an error
|
||||
//! on the given connection (and presumably then the handling of the error
|
||||
//! will include closing the connection).
|
||||
void queue_disconnect(connection connection_num);
|
||||
|
||||
//! Function to receive data from either a certain connection,
|
||||
//! or all connections if connection_num is 0.
|
||||
//! Will store the data received in cfg.
|
||||
//! Times out after timeout milliseconds.
|
||||
//! Returns the connection that data was received from,
|
||||
//! or 0 if timeout occurred.
|
||||
//! Function to receive data from either a certain connection,
|
||||
//! or all connections if connection_num is 0.
|
||||
//! Will store the data received in cfg.
|
||||
//! Times out after timeout milliseconds.
|
||||
//! Returns the connection that data was received from,
|
||||
//! or 0 if timeout occurred.
|
||||
//! Throws error if an error occurred.
|
||||
connection receive_data(config& cfg, connection connection_num=0);
|
||||
connection receive_data(config& cfg, connection connection_num, int timeout);
|
||||
|
||||
//! Function to send data down a given connection,
|
||||
//! or broadcast to all peers if connection_num is 0.
|
||||
//! Function to send data down a given connection,
|
||||
//! or broadcast to all peers if connection_num is 0.
|
||||
//! Throws error.
|
||||
void send_data(const config& cfg, connection connection_num=0);
|
||||
|
||||
//! Function to queue data to be sent.
|
||||
//! Function to queue data to be sent.
|
||||
//! queue_data(cfg,sock) is equivalent to send_data(cfg,sock,0,QUEUE_ONLY)
|
||||
void queue_data(const config& cfg, connection connection_num=0);
|
||||
|
||||
//! Function to send any data that is in a connection's send_queue,
|
||||
//! up to a maximum of 'max_size' bytes --
|
||||
//! Function to send any data that is in a connection's send_queue,
|
||||
//! up to a maximum of 'max_size' bytes --
|
||||
//! or the entire send queue if 'max_size' bytes is 0.
|
||||
void process_send_queue(connection connection_num=0, size_t max_size=0);
|
||||
|
||||
|
|
|
@ -413,7 +413,7 @@ static int process_queue(void*)
|
|||
} catch(config::error &e) {
|
||||
//throw back the error in the parent thread
|
||||
received_data_queue.back().config_error =e.message;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ but WITHOUT ANY WARRANTY.
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file pathfind.cpp
|
||||
//! @file pathfind.cpp
|
||||
//! Various pathfinding functions and utilities.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -66,9 +66,9 @@ static gamemap::location find_vacant(const gamemap& map,
|
|||
}
|
||||
}
|
||||
|
||||
gamemap::location find_vacant_tile(const gamemap& map,
|
||||
const unit_map& units,
|
||||
const gamemap::location& loc,
|
||||
gamemap::location find_vacant_tile(const gamemap& map,
|
||||
const unit_map& units,
|
||||
const gamemap::location& loc,
|
||||
VACANT_TILE_TYPE vacancy)
|
||||
{
|
||||
for(int i = 1; i != 50; ++i) {
|
||||
|
@ -90,7 +90,7 @@ bool enemy_zoc(gamemap const &map,
|
|||
const team ¤t_team = teams[side-1];
|
||||
get_adjacent_tiles(loc,locs);
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
unit_map::const_iterator it;
|
||||
unit_map::const_iterator it;
|
||||
it = find_visible_unit(units, locs[i], map, teams, viewing_team,see_all);
|
||||
|
||||
if (it != units.end() && it->second.side() != side &&
|
||||
|
@ -123,8 +123,8 @@ static void find_routes(const gamemap& map, const gamestatus& status,
|
|||
std::vector<gamemap::location> locs(6);
|
||||
get_adjacent_tiles(loc,&locs[0]);
|
||||
|
||||
// Check for teleporting units -- we must be on a vacant village
|
||||
// (or occupied by this unit), that is controlled by our team
|
||||
// Check for teleporting units -- we must be on a vacant village
|
||||
// (or occupied by this unit), that is controlled by our team
|
||||
// to be able to teleport.
|
||||
if (allow_teleport && map.is_village(loc) &&
|
||||
current_team.owns_village(loc) &&
|
||||
|
@ -132,7 +132,7 @@ static void find_routes(const gamemap& map, const gamestatus& status,
|
|||
teams, viewing_team,see_all) == units.end())) {
|
||||
const std::vector<gamemap::location>& villages = map.villages();
|
||||
|
||||
// If we are on a village, see all friendly villages
|
||||
// If we are on a village, see all friendly villages
|
||||
// that we can teleport to
|
||||
for(std::vector<gamemap::location>::const_iterator t = villages.begin();
|
||||
t != villages.end(); ++t) {
|
||||
|
@ -221,7 +221,7 @@ paths::paths(gamemap const &map, gamestatus const &status,
|
|||
allow_teleport,additional_turns,true,viewing_team, see_all);
|
||||
}
|
||||
|
||||
int route_turns_to_complete(const unit &u, const gamemap &map, paths::route &rt,
|
||||
int route_turns_to_complete(const unit &u, const gamemap &map, paths::route &rt,
|
||||
const unit_map &units, const std::vector<team>& teams)
|
||||
{
|
||||
if(rt.steps.empty())
|
||||
|
@ -257,7 +257,7 @@ int route_turns_to_complete(const unit &u, const gamemap &map, paths::route &rt,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add "end-of-path" to waypoints.
|
||||
if (turns > 0) {
|
||||
|
@ -286,10 +286,10 @@ double shortest_path_calculator::cost(const gamemap::location& /*src*/,const gam
|
|||
// The location is not valid
|
||||
// 1. if the loc is shrouded, or
|
||||
// 2. if moving in it costs more than the total movement of the unit, or
|
||||
// 3. if there is a visible enemy on the hex, or
|
||||
// 4. if the unit is not a skirmisher and there is a visible enemy
|
||||
// 3. if there is a visible enemy on the hex, or
|
||||
// 4. if the unit is not a skirmisher and there is a visible enemy
|
||||
// with a ZoC on an adjacent hex in the middle of the route
|
||||
// #4 is a bad criteria! It should be that moving into a ZOC
|
||||
// #4 is a bad criteria! It should be that moving into a ZOC
|
||||
// uses up the rest of your moves
|
||||
|
||||
if (team_.shrouded(loc.x, loc.y))
|
||||
|
@ -307,22 +307,22 @@ double shortest_path_calculator::cost(const gamemap::location& /*src*/,const gam
|
|||
if (enemy_unit != units_end && team_.is_enemy(enemy_unit->second.side()))
|
||||
return getNoPathValue();
|
||||
|
||||
// Compute how many movement points are left in the game turn
|
||||
// Compute how many movement points are left in the game turn
|
||||
// needed to reach the previous hex.
|
||||
// total_movement_ is not zero, thanks to the pathfinding heuristic
|
||||
int remaining_movement = movement_left_ - static_cast<int>(so_far);
|
||||
if (remaining_movement < 0)
|
||||
remaining_movement = total_movement_ - (-remaining_movement) % total_movement_;
|
||||
|
||||
// Supposing we had 2 movement left, and wanted to move onto a hex
|
||||
// which takes 3 movement, it's going to cost us 5 movement in total,
|
||||
// Supposing we had 2 movement left, and wanted to move onto a hex
|
||||
// which takes 3 movement, it's going to cost us 5 movement in total,
|
||||
// since we sacrifice this turn's movement. Take that into account here.
|
||||
int additional_cost = base_cost > remaining_movement ? remaining_movement : 0;
|
||||
|
||||
if (!isDst && !unit_.get_ability_bool("skirmisher",loc)) {
|
||||
gamemap::location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
|
||||
|
||||
for (size_t i = 0; i != 6; ++i) {
|
||||
enemy_unit = find_visible_unit(units_, adj[i], map_, teams_, team_);
|
||||
if (enemy_unit != units_end && team_.is_enemy(enemy_unit->second.side()) &&
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file pathfind.hpp
|
||||
//!
|
||||
//! @file pathfind.hpp
|
||||
//!
|
||||
|
||||
#ifndef PATHFIND_H_INCLUDED
|
||||
#define PATHFIND_H_INCLUDED
|
||||
|
@ -58,9 +58,9 @@ void get_tiles_radius(const gamemap& map, const std::vector<gamemap::location>&
|
|||
|
||||
enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
|
||||
|
||||
//! Function which will find a location on the board that is
|
||||
//! as near to loc as possible, but which is unoccupied by any units.
|
||||
//! If terrain is not 0, then the location found must be of the given terrain type,
|
||||
//! Function which will find a location on the board that is
|
||||
//! as near to loc as possible, but which is unoccupied by any units.
|
||||
//! If terrain is not 0, then the location found must be of the given terrain type,
|
||||
//! and must have a path of that terrain type to loc.
|
||||
//! If no valid location can be found, it will return a null location.
|
||||
gamemap::location find_vacant_tile(const gamemap& map,
|
||||
|
@ -81,18 +81,18 @@ struct cost_calculator
|
|||
inline double getNoPathValue(void) const { return (42424242.0); }
|
||||
};
|
||||
|
||||
//! Object which contains all the possible locations a unit can move to,
|
||||
//! Object which contains all the possible locations a unit can move to,
|
||||
//! with associated best routes to those locations.
|
||||
struct paths
|
||||
{
|
||||
paths() {}
|
||||
|
||||
// Construct a list of paths for the unit at loc.
|
||||
// - force_ignore_zocs: find the path ignoring ZOC entirely,
|
||||
// - force_ignore_zocs: find the path ignoring ZOC entirely,
|
||||
// if false, will use the unit on the loc's ability
|
||||
// - allow_teleport: indicates whether unit teleports between villages
|
||||
// - additional_turns: if 0, paths for how far the unit can move this turn will be calculated.
|
||||
// If 1, paths for how far the unit can move by the end of next turn
|
||||
// - additional_turns: if 0, paths for how far the unit can move this turn will be calculated.
|
||||
// If 1, paths for how far the unit can move by the end of next turn
|
||||
// will be calculated, and so forth.
|
||||
// viewing_team is usually current team, except for Show Enemy Moves etc.
|
||||
paths(gamemap const &map, gamestatus const &status,
|
||||
|
@ -121,9 +121,9 @@ paths::route a_star_search(gamemap::location const &src, gamemap::location const
|
|||
const size_t parWidth, const size_t parHeight,
|
||||
std::set<gamemap::location> const *teleports = NULL);
|
||||
|
||||
//! Function which, given a unit and a route the unit can move on,
|
||||
//! Function which, given a unit and a route the unit can move on,
|
||||
//! will return the number of turns it will take the unit to traverse the route.
|
||||
//! adds "turn waypoints" to rt.turn_waypoints.
|
||||
//! adds "turn waypoints" to rt.turn_waypoints.
|
||||
//! Note that "end of path" is also added.
|
||||
int route_turns_to_complete(const unit& u, const gamemap& map,
|
||||
paths::route& rt, const unit_map& units,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file pathutils.cpp
|
||||
//! @file pathutils.cpp
|
||||
//! Various pathfinding functions and utilities.
|
||||
|
||||
#include "global.hpp"
|
||||
|
@ -60,8 +60,8 @@ void get_adjacent_tiles(const gamemap::location& a, gamemap::location* res)
|
|||
bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b)
|
||||
{
|
||||
// Two tiles are adjacent:
|
||||
// if y is different by 1, and x by 0,
|
||||
// or if x is different by 1 and y by 0,
|
||||
// if y is different by 1, and x by 0,
|
||||
// or if x is different by 1 and y by 0,
|
||||
// or if x and y are each different by 1,
|
||||
// and the x value of the hex with the greater y value is even.
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ but WITHOUT ANY WARRANTY.
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file pathutils.hpp
|
||||
//! @file pathutils.hpp
|
||||
//!
|
||||
|
||||
#ifndef PATHUTILS_H_INCLUDED
|
||||
|
@ -23,12 +23,12 @@ See the COPYING file for more details.
|
|||
//! Function which tells if two locations are adjacent.
|
||||
bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b);
|
||||
|
||||
//! Function which, given a location, will place all adjacent locations in res.
|
||||
//! Function which, given a location, will place all adjacent locations in res.
|
||||
//! res must point to an array of 6 location objects.
|
||||
void get_adjacent_tiles(const gamemap::location& a, gamemap::location* res);
|
||||
|
||||
//! Function which gives the number of hexes between two tiles
|
||||
//! (i.e. the minimum number of hexes that have to be traversed
|
||||
//! Function which gives the number of hexes between two tiles
|
||||
//! (i.e. the minimum number of hexes that have to be traversed
|
||||
//! to get from one hex to the other).
|
||||
size_t distance_between(const gamemap::location& a, const gamemap::location& b);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ play_controller::play_controller(const config& level, const game_data& gameinfo,
|
|||
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),
|
||||
first_human_team_(-1), player_number_(1),
|
||||
first_human_team_(-1), player_number_(1),
|
||||
first_player_ (lexical_cast_default<unsigned int,std::string>(level_["playing_team"], 0) + 1),
|
||||
start_turn_(status_.turn()), skip_replay_(skip_replay), browse_(false), linger_(false), scrolling_(false)
|
||||
{
|
||||
|
@ -124,7 +124,7 @@ void play_controller::init_managers(){
|
|||
|
||||
//this *needs* to be created before the show_intro and show_map_scene
|
||||
//as that functions use the manager state_of_game
|
||||
events_manager_ = new game_events::manager(level_,*gui_,map_, *soundsources_manager_,
|
||||
events_manager_ = new game_events::manager(level_,*gui_,map_, *soundsources_manager_,
|
||||
units_,teams_, gamestate_,status_,gameinfo_);
|
||||
|
||||
halo_manager_ = new halo::manager(*gui_);
|
||||
|
@ -135,7 +135,7 @@ static int placing_score(const config& side, const gamemap& map, const gamemap::
|
|||
{
|
||||
int positions = 0, liked = 0;
|
||||
const t_translation::t_list terrain = t_translation::read_list(side["terrain_liked"]);
|
||||
|
||||
|
||||
for(int i = pos.x-8; i != pos.x+8; ++i) {
|
||||
for(int j = pos.y-8; j != pos.y+8; ++j) {
|
||||
const gamemap::location pos(i,j);
|
||||
|
@ -315,12 +315,12 @@ void play_controller::init_side(const unsigned int team_index, bool /*is_replay*
|
|||
gamestate_.set_variable("side_number",player_number_str.str());
|
||||
gamestate_.last_selected = gamemap::location::null_location;
|
||||
|
||||
/*
|
||||
normally, events must not be actively fired through replays, because they have been
|
||||
/*
|
||||
normally, events must not be actively fired through replays, because they have been
|
||||
recorded previously and therefore will get executed anyway. Firing them in the normal
|
||||
code would lead to double execution.
|
||||
However, the following events are different in that they need to be executed _now_
|
||||
(before calculation of income and healing) or we will risk OOS errors if we manipulate
|
||||
However, the following events are different in that they need to be executed _now_
|
||||
(before calculation of income and healing) or we will risk OOS errors if we manipulate
|
||||
these informations inside the events and in the replay have a different order of execution.
|
||||
*/
|
||||
if(first_turn_) {
|
||||
|
@ -718,7 +718,7 @@ void play_controller::play_slice()
|
|||
if (!scrolling_) {
|
||||
if (was_scrolling) {
|
||||
// scrolling ended, update the cursor and the brightened hex
|
||||
mouse_handler_.mouse_update(browse_);
|
||||
mouse_handler_.mouse_update(browse_);
|
||||
}
|
||||
gui_->delay(20);
|
||||
}
|
||||
|
@ -797,9 +797,9 @@ void play_controller::expand_wml_commands(std::vector<std::string>& items)
|
|||
&& newitems.size() < MAX_WML_COMMANDS; ++itor) {
|
||||
config& show_if = itor->second->show_if;
|
||||
config filter_location = itor->second->filter_location;
|
||||
if ((show_if.empty()
|
||||
if ((show_if.empty()
|
||||
|| game_events::conditional_passed(&units_, &show_if))
|
||||
&& (filter_location.empty()
|
||||
&& (filter_location.empty()
|
||||
|| terrain_matches_filter(map_, hex, &filter_location, status_, units_))
|
||||
&& (!itor->second->needs_select
|
||||
|| gamestate_.last_selected.valid()))
|
||||
|
@ -808,7 +808,7 @@ void play_controller::expand_wml_commands(std::vector<std::string>& items)
|
|||
std::string newitem = itor->second->description;
|
||||
|
||||
//prevent accidental hotkey binding by appending a space
|
||||
push_back<std::string, char>(newitem, ' ');
|
||||
push_back<std::string, char>(newitem, ' ');
|
||||
newitems.push_back(newitem);
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue