Reverted back to 42095.

This commit is contained in:
Fabian Müller 2010-04-10 17:30:45 +00:00
parent 183c40ba5b
commit 4a7e27d070
95 changed files with 700 additions and 8806 deletions

View file

@ -98,6 +98,8 @@ set(BINARY_PREFIX "" CACHE STRING "Prefix in front of all binaries")
# Handle options (set paths/definitions/etc...)
#
if(CMAKE_COMPILER_IS_GNUCXX)
# Set our own default flags at first run.
if(NOT CONFIGURED)

View file

@ -168,6 +168,7 @@ then
CPPFLAGS="$CPPFLAGS -DDEBUG_WINDOW_LAYOUT_GRAPHS"
fi
DATADIR=$PACKAGE
AC_ARG_WITH([datadir-name],
AS_HELP_STRING([--with-datadir-name@<:@=DIR@:>@], [change name of data directory @<:@wesnoth@:>@]),

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@
[scenario]
name=_ "Defend the Forest"
id="1_Defend_the_Forest"
# map##_data="{campaigns/An_Orcish_Incursion/maps/1_Defend_the_forest.map}"
map_data="{campaigns/An_Orcish_Incursion/maps/1_Defend_the_forest.map}"
turns=24
next_scenario=2_Assassins
{DEFAULT_SCHEDULE}
@ -17,47 +17,45 @@
{EXTRA_SCENARIO_MUSIC wanderer.ogg}
{EXTRA_SCENARIO_MUSIC sad.ogg}
{campaigns/An_Orcish_Incursion/maps/1_Defend_the_forest.map}
[side]
type="Elvish Lord"
id="Erlornas"
canrecruit=yes
name=_ "Erlornas"
# [side]
# type="Elvish Lord"
# id="Erlornas"
# canrecruit=yes
# name=_ "Erlornas"
side=1
controller=human
{GOLD 200 150 100}
income=0
team_name="Elves"
user_team_name=_ "Elves"
fog=no
shroud=no
recruit="Elvish Archer, Elvish Fighter, Elvish Scout, Elvish Shaman"
[/side]
# side=1
# controller=human
# {GOLD 200 150 100}
# income=0
# team_name="Elves"
# user_team_name=_ "Elves"
# fog=no
# shroud=no
# recruit="Elvish Archer, Elvish Fighter, Elvish Scout, Elvish Shaman"
# [/side]
{STARTING_VILLAGES 1 6}
# {STARTING_VILLAGES 1 6}
[side]
type="Orcish Warrior"
id="Urugha"
name=_ "Urugha"
canrecruit=yes
# [side]
# type="Orcish Warrior"
# id="Urugha"
# name=_ "Urugha"
# canrecruit=yes
# side=2
# {GOLD 100 125 150}
# team_name="Orcs"
# user_team_name=_ "Orcs"
# controller=ai
# fog=no
# shroud=no
# income=0
# recruit="Orcish Archer, Orcish Grunt, Wolf Rider"
# [ai]
# grouping=offensive
# attack_depth=5
# [/ai]
# [/side]
side=2
{GOLD 100 125 150}
team_name="Orcs"
user_team_name=_ "Orcs"
controller=ai
fog=no
shroud=no
income=0
recruit="Orcish Archer, Orcish Grunt, Wolf Rider"
[ai]
grouping=offensive
attack_depth=5
[/ai]
[/side]
[story]
[part]

View file

@ -69,6 +69,9 @@ This is the story of Kalenz, and of the Elves in the days of the humans in Wesno
#define PLAYER_GOLD
{GOLD 240 200 180}
#enddef
#define PLAYER_RECRUIT
recruit=Elvish Fighter, Elvish Archer
#enddef
[side]
side=1
@ -79,7 +82,7 @@ This is the story of Kalenz, and of the Elves in the days of the humans in Wesno
controller=human
team_name=player
user_team_name= _ "Player"
recruit={ELVES}
{PLAYER_RECRUIT}
{PLAYER_GOLD}
x=17
y=15
@ -325,7 +328,7 @@ This is the story of Kalenz, and of the Elves in the days of the humans in Wesno
controller=human
team_name=player
user_team_name= _ "Player"
recruit={ELVES}
{PLAYER_RECRUIT}
{PLAYER_GOLD}
x=16
y=15
@ -334,7 +337,7 @@ This is the story of Kalenz, and of the Elves in the days of the humans in Wesno
id=Landulias
generate_name=yes
unrenamable=yes
type=Elvish Archer
type=Elvish Shaman
gender=female
[modifications]
#TODO rethink them

View file

@ -44,14 +44,17 @@
#define PLAYER_GOLD
{GOLD 200 180 100}
#enddef
#define PLAYER_RECRUIT
recruit=Elvish Fighter, Elvish Archer
#enddef
[side]
{KALENZ}
controller=human
{PLAYER_GOLD}
{PLAYER_RECRUIT}
fog=no
# wmllint: recognize Kalenz
recruit={ELVES}
#ifndef MULTIPLAYER
[unit]
placement=leader
@ -457,9 +460,9 @@
save_id=Landar
{LANDAR}
{PLAYER_GOLD}
{PLAYER_RECRUIT}
fog=no
# wmllint: recognize Landar
recruit={ELVES}
[/side]
#wmllint: validate-on
#endif

View file

@ -10,8 +10,6 @@
# Ka'lian, but, instead, hold position and wait for their army to
# arrive"
#TODO make the ugly map border nicer
#ifdef MULTIPLAYER
[multiplayer]
random_start_time=no
@ -749,7 +747,16 @@
gold=$galdrid_gold
[/modify_side]
[set_recruit]
side=1
recruit=Elvish Fighter, Elvish Archer
[/set_recruit]
#ifdef MULTIPLAYER
[set_recruit]
side=6
recruit=Elvish Fighter, Elvish Archer
[/set_recruit]
[modify_side]
side=6
gold=$landar_gold

View file

@ -41,14 +41,17 @@
#define PLAYER_GOLD
{GOLD 280 250 220}
#enddef
#define PLAYER_RECRUIT
recruit=Elvish Fighter, Elvish Archer, Elvish Scout
#enddef
#wmllint: validate-off
[side]
{KALENZ}
{PLAYER_GOLD}
{PLAYER_RECRUIT}
fog=no
# wmllint: recognize Kalenz
recruit={ELVES}
#ifndef MULTIPLAYER
[unit]
{LANDAR}
@ -117,8 +120,8 @@
fog=no
{LANDAR}
{PLAYER_GOLD}
{PLAYER_RECRUIT}
# wmllint: recognize Landar
recruit={ELVES}
[/side]
#wmllint: validate-on
#endif

View file

@ -114,10 +114,6 @@
command="editor-tool-select"
key="s"
[/hotkey]
[hotkey]
command="editor-tool-map-label"
key="l"
[/hotkey]
[hotkey]
command="editor-brush-next"
key="b"

View file

@ -379,33 +379,6 @@ Any units adjacent to this unit will fight as if it were dusk when it is night,
female_name= _ "female^teleport"
description= _ "Teleport:
This unit may teleport between any two empty villages owned by its side using one of its moves."
[tunnel]
id=village_teleport
[source]
terrain=*^V*
owner_side=$teleport_unit.side
[not]
[filter]
[not]
id=$teleport_unit.id
[/not]
[/filter]
[/not]
[/source]
[target]
terrain=*^V*
owner_side=$teleport_unit.side
[not]
[filter]
[/filter]
[/not]
[/target]
[filter]
ability=teleport
[/filter]
[/tunnel]
[/teleport]
#enddef

File diff suppressed because it is too large Load diff

View file

@ -188,78 +188,6 @@ Xu , Xu , Qxu , Qxu , Ql , Ql
#endif
[/event]
[event]
name=prestart
{VARIABLE teleports_on no}
[/event]
[label]
x,y=20,13
text="Teleport switch"
[/label]
[event]
name=moveto
first_time_only=no
[filter]
x,y=20,13
[/filter]
[if]
[variable]
name=teleports_on
boolean_equals=no
[/variable]
[then]
[tunnel]
id="one"
bidirectional=yes
always_visible=yes
[source]
x=8
y=6
[/source]
[target]
x=20
y=12
[/target]
[filter]
[/filter]
[/tunnel]
[tunnel]
id="two"
bidirectional=no
[source]
x=20
y=14
[/source]
[target]
x=21
y=4
[/target]
[filter]
[/filter]
[/tunnel]
{VARIABLE teleports_on yes}
[message]
speaker=narrator
icon=wesnoth-icon.png
message="Teleporters activated"
[/message]
[/then]
[else]
[tunnel]
id="one,two"
remove=yes
[/tunnel]
{VARIABLE teleports_on no}
[message]
speaker=narrator
icon=wesnoth-icon.png
message="Teleporters deactivated"
[/message]
[/else]
[/if]
[/event]
[side]
type=Orcish Warlord
id="Urug-Telfar"

View file

@ -107,8 +107,6 @@
xanchor=right
yanchor=top
[/panel]
#TODO
#[panel]
# id=bottom-right-panel
# image=themes/rightside-bottom.png
@ -121,7 +119,7 @@
id=menu-editor-file
title= _ "File"
image=lite
items=editor-map-new,editor-side-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,editor-multiplayer-save,editor-multiplayer-save-as,preferences,editor-settings,editor-close-map,quit,editor-quit-to-desktop
items=editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,editor-settings,editor-close-map,quit,editor-quit-to-desktop
ref=top-panel
rect="=+3,=+1,+100,=-4"
xanchor=fixed
@ -132,7 +130,7 @@
id=menu-editor-edit
title= _ "Edit"
image=lite
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-selection-name,editor-export-selection-coords,editor-select-all,editor-select-inverse,editor-select-none, editor-selection-fill,editor-selection-rotate,editor-selection-flip, editor-selection-generate,editor-selection-randomize
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-export-selection-coords,editor-select-all,editor-select-inverse,editor-select-none, editor-selection-fill,editor-selection-rotate,editor-selection-flip, editor-selection-generate,editor-selection-randomize
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
@ -158,26 +156,6 @@
yanchor=fixed
[/menu]
[menu]
id=menu-editor-areas
title= _ "Areas"
image=lite
items=editor-switch-area
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
[/menu]
[menu]
id=menu-editor-side
title= _ "Side"
image=lite
items=editor-switch-side
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
[/menu]
[menu]
id=menu-editor-paste-context
is_context_menu=true
@ -239,62 +217,13 @@
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=unit_button_editor
image=units_button_editor
items=editor-tool-unit
ref=draw_button_editor
# wmllint: local spelling alt+number
#TODO correct
#TODO enable the translation some day
tooltip= _ "Left mouse button sets a new unit or moves a unit via drag and drop, right clears."
tooltip_name_prepend=yes
rect="=,+6,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=path_button_editor
image=start_position_button_editor
#image=path_button_editor
items=editor-tool-path
tooltip= _ "Left mouse button sets a new node in to the path, right clears the last."
tooltip_name_prepend=yes
rect="+6,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=village_button_editor
image=villages_button_editor
items=editor-tool-village
tooltip= _ "Left mouse button sets the village ownership to the current side, right clears."
tooltip_name_prepend=yes
rect="+6,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=label_button_editor
image=start_position_button_editor
items=editor-tool-map-label
tooltip= _ "Left mouse button sets or drages a label, right clears."
tooltip_name_prepend=yes
rect="+6,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=undo_button_editor
image=undo_button_editor
items=undo
auto_tooltip=yes
ref=unit_button_editor
rect="=,+39,+24,+24"
ref=draw_button_editor
rect="=,+42,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
@ -329,20 +258,12 @@
[panel]
id=villages-panel
image=themes/status-bg.png
ref=menu-editor-side
ref=menu-editor-window
rect="+5,=+1,+71,+19"
xanchor=fixed
yanchor=fixed
[/panel]
[panel]
id=units-panel
image=themes/status-bg.png
rect="+5,=,+71,="
xanchor=fixed
yanchor=fixed
[/panel]
[label]
id=villages-icon
icon=themes/villages.png
@ -353,19 +274,7 @@
yanchor=fixed
[/label]
[label]
id=units-icon
icon=themes/units.png
text= _ "units"
ref=units-panel
rect="=+5,=+1,+17,+17"
xanchor=fixed
yanchor=fixed
[/label]
[status]
#TODO comment or remove
#[editor_tool_hint]
# id=tool-hint
# font_size={DEFAULT_EDITOR_FONT_REALLYTINY}
@ -376,7 +285,7 @@
# prefix="" #wmllint: ignore
# prefix_literal=""
#[/editor_tool_hint]
#TODO comment or remove
# the time of day image
# [time_of_day]
# id=image-tod
@ -397,18 +306,6 @@
prefix_literal=""
[/villages]
[num_units]
id=num-units
font_size={DEFAULT_FONT_SMALL}
ref=units-icon
rect="+4,=,+55,+16"
xanchor=fixed
yanchor=fixed
prefix="" #wmllint: ignore
prefix_literal=""
[/num_units]
# This panel encloses the location information displays and the
# observer icon. This separate container is used so that we can
# make the terrain name display stretch to fill all available space

Binary file not shown.

Before

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1,004 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 990 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

View file

@ -337,7 +337,6 @@ set(wesnoth-main_SRC
gui/dialogs/game_delete.cpp
gui/dialogs/game_save.cpp
gui/dialogs/gamestate_inspector.cpp
gui/dialogs/icon_message.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/lobby/lobby_data.cpp
gui/dialogs/lobby/lobby_info.cpp
@ -402,8 +401,6 @@ set(wesnoth-main_SRC
multiplayer_create.cpp
network.cpp
network_worker.cpp
pathfind/pathfind.cpp
pathfind/teleport.cpp
playcampaign.cpp
play_controller.cpp
playmp_controller.cpp
@ -491,7 +488,6 @@ SET(libwesnoth-game_STAT_SRC
lobby_preferences.cpp
map_create.cpp
map_label.cpp
map_area.cpp
mapgen.cpp
mapgen_dialog.cpp
marked-up_text.cpp
@ -528,6 +524,11 @@ SET(libwesnoth-game_STAT_SRC
wml_exception.cpp
)
SET(libwesnoth-game_STAT_SRC
${libwesnoth-game_STAT_SRC}
pathfind/pathfind.cpp
)
if(ENABLE_GAME AND ENABLE_TESTS)
set(libwesnoth-game_STAT_SRC
${libwesnoth-game_STAT_SRC}

View file

@ -229,7 +229,6 @@ wesnoth_source = \
network.cpp \
network_worker.cpp \
pathfind/pathfind.cpp \
pathfind/teleport.cpp
playcampaign.cpp \
play_controller.cpp \
playmp_controller.cpp \
@ -273,6 +272,7 @@ wesnoth_source = \
widgets/drop_target.cpp \
widgets/scrollpane.cpp
# used with editor option in the wesnoth target
wesnoth_editor_SOURCES = \
gui/dialogs/editor_generate_map.cpp \

View file

@ -79,7 +79,6 @@ libwesnoth_sources = Split("""
loadscreen.cpp
map_create.cpp
map_label.cpp
map_area.cpp
mapgen.cpp
mapgen_dialog.cpp
marked-up_text.cpp
@ -219,7 +218,6 @@ wesnoth_sources = Split("""
multiplayer_create.cpp
multiplayer_connect.cpp
pathfind/pathfind.cpp
pathfind/teleport.cpp
playcampaign.cpp
play_controller.cpp
playmp_controller.cpp

View file

@ -1723,6 +1723,8 @@ struct unit_healing_struct {
void calculate_healing(int side, bool update_display)
{
DBG_NG << "beginning of healing calculations\n";
int heal_accel = unit_type::stat_accelerator::get_acceleration();
unit_map &units = *resources::units;
std::list<unit_healing_struct> l;
@ -1793,7 +1795,7 @@ void calculate_healing(int side, bool update_display)
}
unit_abilities::effect heal_effect(heal,0,false);
healing = heal_effect.get_composite_value();
healing = heal_effect.get_composite_value() * heal_accel;
for(std::vector<unit_abilities::individual_effect>::const_iterator heal_loc = heal_effect.begin(); heal_loc != heal_effect.end(); ++heal_loc) {
healers.push_back(&*units.find(heal_loc->loc));
@ -1807,7 +1809,7 @@ void calculate_healing(int side, bool update_display)
unit_ability_list regen = u.get_abilities("regenerate");
unit_abilities::effect regen_effect(regen,0,false);
if(regen_effect.get_composite_value() > healing) {
healing = regen_effect.get_composite_value();
healing = regen_effect.get_composite_value() * heal_accel;
healers.clear();
}
if(regen.cfgs.size()) {
@ -1823,7 +1825,7 @@ void calculate_healing(int side, bool update_display)
}
if (int h = resources::game_map->gives_healing(u.get_location())) {
if (h > healing) {
healing = h;
healing = h * heal_accel;
healers.clear();
}
/** @todo FIXME */
@ -1831,7 +1833,7 @@ void calculate_healing(int side, bool update_display)
curer = units.end();
}
if (u.resting() || u.is_healthy()) {
rest_healing = game_config::rest_heal_amount;
rest_healing = game_config::rest_heal_amount * heal_accel;
healing += rest_healing;
}
}
@ -1851,7 +1853,7 @@ void calculate_healing(int side, bool update_display)
healers.clear();
healing = rest_healing;
if (u.side() == side) {
healing -= game_config::poison_amount;
healing -= game_config::poison_amount * heal_accel;
}
}
}

View file

@ -41,7 +41,6 @@
#include "../game_preferences.hpp"
#include "../log.hpp"
#include "../mouse_handler_base.hpp"
#include "../pathfind/teleport.hpp"
#include "play_controller.hpp"
#include "../replay.hpp"
#include "resources.hpp"
@ -414,7 +413,8 @@ bool move_result::test_route(const unit &un, const team &my_team, const unit_map
}
const pathfind::shortest_path_calculator calc(un, my_team, units, teams,map);
pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(un, units, my_team, true);//@todo 1.9: see_all -> false
//allowed teleports
std::set<map_location> allowed_teleports = pathfind::get_teleport_locations(un, units, my_team, true);//@todo 1.9: see_all -> false
//do an A*-search
route_ = pathfind::a_star_search(un.get_location(), to_, 10000.0, &calc, map.w(), map.h(), &allowed_teleports);
@ -511,7 +511,7 @@ void move_result::do_execute()
if (from_ != to_) {
move_unit(
/*move_unit_spectator* move_spectator*/ &move_spectator_,
/*std::vector<map_location> pathfind::route*/ route_.steps,
/*std::vector<map_location> route*/ route_.steps,
/*replay* move_recorder*/ &recorder,
/*undo_list* undo_stack*/ NULL,
/*bool show_move*/ preferences::show_ai_moves(),

View file

@ -335,10 +335,11 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_
srcdst.insert(trivial_mv);
dstsrc.insert(trivial_mv);
}
bool teleports = un_it->get_ability_bool("teleport");
res.insert(std::pair<map_location,pathfind::paths>(
un_it->get_location(), pathfind::paths(get_info().map,
units, un_it->get_location() ,get_info().teams, false,
true, current_team(), 0, see_all)));
units, un_it->get_location(), get_info().teams, false,
teleports, current_team(), 0, see_all)));
}
// deactivate terrain filtering if it's just the dummy 'matches nothing'
@ -907,7 +908,8 @@ bool readonly_context_impl::leader_can_reach_keep() const
// Find where the leader can move
const pathfind::paths leader_paths(get_info().map, get_info().units,
leader->get_location(), get_info().teams, false, true, current_team());
leader->get_location(), get_info().teams, false, false, current_team());
return leader_paths.destinations.contains(start_pos);
}

View file

@ -526,7 +526,7 @@ bool ai_default::multistep_move_possible(const map_location& from,
unit temp_unit(*i);
temp_unit.set_movement(itor->move_left);
const temporary_unit_placer unit_placer(units_,via,temp_unit);
const pathfind::paths unit_paths(map_,units_,via,teams_,false,true,current_team());
const pathfind::paths unit_paths(map_,units_,via,teams_,false,false,current_team());
LOG_AI << "Found " << unit_paths.destinations.size() << " moves for temp leader.\n";
@ -1876,7 +1876,7 @@ void ai_default::move_leader_to_goals()
}
const pathfind::paths leader_paths(map_, units_, leader->get_location(),
teams_, false, true, current_team());
teams_, false, false, current_team());
std::map<map_location,pathfind::paths> possible_moves;
possible_moves.insert(std::pair<map_location,pathfind::paths>(leader->get_location(), leader_paths));
@ -1913,7 +1913,7 @@ void ai_default::move_leader_after_recruit()
const bool passive_leader = get_passive_leader()||passive_leader_shares_keep;
const pathfind::paths leader_paths(map_, units_, leader->get_location(),
teams_, false, true, current_team());
teams_, false, false, current_team());
std::map<map_location,pathfind::paths> possible_moves;
possible_moves.insert(std::make_pair(leader->get_location(), leader_paths));
@ -1949,7 +1949,7 @@ void ai_default::move_leader_after_recruit()
unit_map temp_units;
temp_units.add(current_loc, *leader);
const pathfind::paths p(map_, temp_units, current_loc, teams_, false,
true, current_team());
false, current_team());
if (p.destinations.contains(i->first))
{

View file

@ -124,7 +124,7 @@ bool default_ai_context_impl::multistep_move_possible(const map_location& from,
unit temp_unit(*i);
temp_unit.set_movement(itor->move_left);
const temporary_unit_placer unit_placer(units_,via,temp_unit);
const pathfind::paths unit_paths(get_info().map,units_,via,get_info().teams,false,true,current_team());
const pathfind::paths unit_paths(get_info().map,units_,via,get_info().teams,false,false,current_team());
LOG_AI << "Found " << unit_paths.destinations.size() << " moves for temp leader.\n";

View file

@ -734,7 +734,7 @@ void ai_default::move_leader_to_keep()
// Find where the leader can move
const pathfind::paths leader_paths(map_, units_, leader->get_location(),
teams_, false, true, current_team());
teams_, false, false, current_team());
const map_location& keep = suitable_keep(leader->get_location(), leader_paths);
std::map<map_location,pathfind::paths> possible_moves;

View file

@ -34,7 +34,6 @@
#include "../../formula_debugger.hpp"
#include "../../log.hpp"
#include "../../menu_events.hpp"
#include "../../pathfind/teleport.hpp"
#include "../../terrain_filter.hpp"
#include "../../tod_manager.hpp"
@ -178,7 +177,7 @@ variant formula_ai::make_action(game_logic::const_formula_ptr formula_, const ga
pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &src,
const map_location &dst, unit_map::iterator &unit_it,
pathfind::teleport_map& allowed_teleports) const
std::set<map_location> & allowed_teleports) const
{
map_location destination = dst;
@ -230,7 +229,7 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
return route;
}
pathfind::teleport_map formula_ai::get_allowed_teleports(unit_map::iterator& unit_it) const
std::set<map_location> formula_ai::get_allowed_teleports(unit_map::iterator& unit_it) const
{
return pathfind::get_teleport_locations(*unit_it, get_info().units, current_team(), true);
}
@ -243,7 +242,7 @@ map_location formula_ai::path_calculator(const map_location& src, const map_loca
//check if destination is within unit's reach, if not, calculate where to move
if (!path->second.destinations.contains(dst))
{
pathfind::teleport_map allowed_teleports = get_allowed_teleports(unit_it);
std::set<map_location> allowed_teleports = get_allowed_teleports(unit_it);
//destination is too far, check where unit can go
pathfind::plain_route route = shortest_path_calculator( src, dst, unit_it, allowed_teleports );

View file

@ -104,8 +104,8 @@ public:
void handle_exception(game_logic::formula_error& e) const;
void handle_exception(game_logic::formula_error& e, const std::string& failed_operation) const;
pathfind::teleport_map get_allowed_teleports(unit_map::iterator& unit_it) const;
pathfind::plain_route shortest_path_calculator(const map_location& src, const map_location& dst, unit_map::iterator& unit_it, pathfind::teleport_map& allowed_teleports) const;
std::set<map_location> get_allowed_teleports(unit_map::iterator& unit_it) const;
pathfind::plain_route shortest_path_calculator(const map_location& src, const map_location& dst, unit_map::iterator& unit_it, std::set<map_location>& allowed_teleports) const;
void store_outcome_position(const variant& var);

View file

@ -27,7 +27,6 @@
#include "../../log.hpp"
#include "../../map_label.hpp"
#include "../../menu_events.hpp"
#include "../../pathfind/teleport.hpp"
#include "../../replay.hpp"
#include "../../terrain_filter.hpp"
#include "../../unit.hpp"
@ -659,7 +658,7 @@ private:
if (ai_.get_info().units.find(loc)==ai_.get_info().units.end()){
return variant();
}
const pathfind::paths unit_paths(ai_.get_info().map, ai_.get_info().units, loc ,ai_.get_info().teams, false, true, ai_.current_team());
const pathfind::paths unit_paths(ai_.get_info().map, ai_.get_info().units, loc ,ai_.get_info().teams, false, false, ai_.current_team());
return variant(new location_callable(ai_.suitable_keep(loc,unit_paths)));
}
@ -973,7 +972,7 @@ private:
throw formula_error( str.str(), "", "", 0);
}
pathfind::teleport_map allowed_teleports = ai_.get_allowed_teleports(unit_it);
std::set<map_location> allowed_teleports = ai_.get_allowed_teleports(unit_it);
pathfind::plain_route route = ai_.shortest_path_calculator( src, dst, unit_it, allowed_teleports );
@ -1023,22 +1022,22 @@ private:
throw formula_error( str.str(), "", "", 0);
}
pathfind::teleport_map allowed_teleports = ai_.get_allowed_teleports(unit_it);
std::set<map_location> allowed_teleports = ai_.get_allowed_teleports(unit_it);
pathfind::emergency_path_calculator em_calc(*unit_it, ai_.get_info().map);
pathfind::plain_route route = pathfind::a_star_search(src, dst, 1000.0, &em_calc, ai_.get_info().map.w(), ai_.get_info().map.h(), &allowed_teleports);
pathfind::plain_route route = pathfind::a_star_search(src, dst, 1000.0, &em_calc, ai_.get_info().map.w(), ai_.get_info().map.h(), &allowed_teleports);
if( route.steps.size() < 2 ) {
return variant(&locations);
}
if( route.steps.size() < 2 ) {
return variant(&locations);
}
for (std::vector<map_location>::const_iterator loc_iter = route.steps.begin() + 1 ; loc_iter !=route.steps.end(); ++loc_iter) {
if (unit_it->movement_cost(ai_.get_info().map[*loc_iter]) < 99 )
locations.push_back( variant( new location_callable(*loc_iter) ));
else
break;
}
for (std::vector<map_location>::const_iterator loc_iter = route.steps.begin() + 1 ; loc_iter !=route.steps.end(); ++loc_iter) {
if (unit_it->movement_cost(ai_.get_info().map[*loc_iter]) < 99 )
locations.push_back( variant( new location_callable(*loc_iter) ));
else
break;
}
return variant(&locations);
}
@ -1077,13 +1076,13 @@ private:
throw formula_error( str.str(), "", "", 0);
}
pathfind::teleport_map allowed_teleports = ai_.get_allowed_teleports(unit_it);
std::set<map_location> allowed_teleports = ai_.get_allowed_teleports(unit_it);
pathfind::plain_route route = ai_.shortest_path_calculator( src, dst, unit_it, allowed_teleports );
if( route.steps.size() < 2 ) {
if( route.steps.size() < 2 ) {
return variant();
}
}
map_location loc = map_location::null_location;
const ai::moves_map &possible_moves = ai_.get_possible_moves();
@ -1243,15 +1242,15 @@ private:
}
void display_label(const map_location& location, const std::string& text) const {
// game_display* gui = game_display::get_singleton();
game_display* gui = game_display::get_singleton();
std::string team_name;
// SDL_Color colour = int_to_color(team::get_side_rgb(ai_.get_side()));
SDL_Color colour = int_to_color(team::get_side_rgb(ai_.get_side()));
// const terrain_label *res;
//// res = gui->labels().set_label(location, text, team_name, colour);
// if (res)
// recorder.add_label(res);
const terrain_label *res;
res = gui->labels().set_label(location, text, team_name, colour);
if (res)
recorder.add_label(res);
}
const formula_ai& ai_;

View file

@ -661,7 +661,7 @@ double move_leader_to_goals_phase::evaluate()
}
const pathfind::paths leader_paths(get_info().map, get_info().units, leader->get_location(),
get_info().teams, false, true, current_team());
get_info().teams, false, false, current_team());
std::map<map_location,pathfind::paths> possible_moves;
possible_moves.insert(std::pair<map_location,pathfind::paths>(leader->get_location(), leader_paths));
@ -733,7 +733,7 @@ double move_leader_to_keep_phase::evaluate()
// Find where the leader can move
const pathfind::paths leader_paths(get_info().map, units_, leader->get_location(),
get_info().teams, false, true, current_team());
get_info().teams, false, false, current_team());
const map_location& keep = suitable_keep(leader->get_location(), leader_paths);
std::map<map_location,pathfind::paths> possible_moves;

View file

@ -80,6 +80,7 @@ namespace game_config {
#if defined(__APPLE__)
defines_map_["APPLE"] = preproc_define();
#endif
}
void config_cache::get_config(const std::string& path, config& cfg)

View file

@ -76,7 +76,7 @@ namespace {
int display::last_zoom_ = SmallZoom;
display::display(CVideo& video, gamemap* map, const config& theme_cfg, const config& level) :
display::display(CVideo& video, const gamemap* map, const config& theme_cfg, const config& level) :
screen_(video),
map_(map),
viewpoint_(NULL),
@ -154,7 +154,7 @@ void display::reload_map()
builder_->reload_map();
}
void display::change_map(gamemap* m)
void display::change_map(const gamemap* m)
{
map_ = m;
builder_->change_map(m);

View file

@ -63,7 +63,7 @@ class gamemap;
class display
{
public:
display(CVideo& video, gamemap* map, const config& theme_cfg,
display(CVideo& video, const gamemap* map, const config& theme_cfg,
const config& level);
virtual ~display();
@ -73,7 +73,7 @@ public:
*/
void reload_map();
virtual void change_map(gamemap* m);
void change_map(const gamemap* m);
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
{ return 0xFF000000 | (red << 16) | (green << 8) | blue; }
@ -312,7 +312,6 @@ public:
const gamemap& get_map() const { return *map_; }
gamemap& get_map() { return *map_; }
/**
* The last action in drawing a tile is adding the overlays.
@ -562,7 +561,7 @@ protected:
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type,bool force = true);
CVideo& screen_;
gamemap* map_;
const gamemap* map_;
const team *viewpoint_;
int xpos_, ypos_;
theme theme_;

View file

@ -19,15 +19,10 @@
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "action.hpp"
#include "map_context.hpp"
#include "../construct_dialog.hpp"
#include "../resources.hpp"
#include "../foreach.hpp"
#include "../gettext.hpp"
#include "../unit.hpp"
namespace editor {
int editor_action::next_id_ = 1;
@ -152,7 +147,6 @@ void editor_action_chain::perform_without_undo(map_context& mc) const
}
}
}
/* end of generic classes */
void editor_action_area::extend(const editor_map& /*map*/, const std::set<map_location>& locs)
{
@ -181,6 +175,7 @@ void editor_action_paste::perform_without_undo(map_context& mc) const
mc.set_needs_terrain_rebuild();
}
editor_action_paint_area* editor_action_paint_area::clone() const
{
return new editor_action_paint_area(*this);
@ -198,23 +193,6 @@ void editor_action_paint_area::perform_without_undo(map_context& mc) const
mc.set_needs_terrain_rebuild();
}
editor_action_name_area* editor_action_name_area::clone() const
{
return new editor_action_name_area(*this);
}
editor_action_paste* editor_action_name_area::perform(map_context& mc) const
{
//TODO undo
map_fragment mf(mc.get_map(), area_);
std::auto_ptr<editor_action_paste> undo(new editor_action_paste(mf));
perform_without_undo(mc);
return undo.release();
}
void editor_action_name_area::perform_without_undo(map_context& mc) const
{
mc.get_map().get_named_areas().add_area(area_id_,area_);
}
editor_action_fill* editor_action_fill::clone() const
{
return new editor_action_fill(*this);
@ -271,233 +249,6 @@ void editor_action_starting_position::perform_without_undo(map_context& mc) cons
}
editor_action_unit_replace* editor_action_unit_replace::clone() const
{
return new editor_action_unit_replace(*this);
}
editor_action_village* editor_action_village::clone() const
{
return new editor_action_village(*this);
}
editor_action_village_delete* editor_action_village_delete::clone() const
{
return new editor_action_village_delete(*this);
}
editor_action_unit* editor_action_unit::clone() const
{
return new editor_action_unit(*this);
}
editor_action_label_delete* editor_action_label_delete::clone() const
{
return new editor_action_label_delete(*this);
}
editor_action* editor_action_label_delete::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo;
std::vector<label> deleted = mc.get_map().get_game_labels().delete_labels(loc_);
editor_action_chain* undo_chain = new editor_action_chain();
for (std::vector<label>::const_iterator it = deleted.begin(); it != deleted.end(); it++) {
ERR_ED << it->text();
undo_chain->append_action(new editor_action_label(loc_,it->text(),it->team_name()));
}
undo.reset(undo_chain);
mc.set_needs_labels_reset();
//perform_without_undo(mc);
return undo.release();
}
void editor_action_label_delete::perform_without_undo(map_context& mc) const
{
}
editor_action_label* editor_action_label::clone() const
{
return new editor_action_label(*this);
}
editor_action* editor_action_label::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo;
const label* old_label = mc.get_map().get_game_labels().get_label(loc_);
if (old_label) {
undo.reset(new editor_action_label(loc_, old_label->text(), old_label->team_name()) );
} else {
undo.reset(new editor_action_label_delete(loc_));
}
perform_without_undo(mc);
return undo.release();
}
editor_action* editor_action_unit_replace::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo(new editor_action_unit_replace(new_loc_, loc_));
perform_without_undo(mc);
return undo.release();
}
void editor_action_unit_replace::perform_without_undo(map_context& mc) const
{
unit_map& units = mc.get_map().get_units();
units.move(loc_, new_loc_);
unit::clear_status_caches();
unit& u = *units.find(new_loc_);
u.set_standing();
mc.set_needs_labels_reset();
//TODO
// if (mc.get_map().is_village(new_loc_)) {
// (*(resources::teams))[u.side()].get_village(new_loc_);
// }
//TODO check if that is useful
// resources::screen->invalidate_unit_after_move(loc_, new_loc_);
// resources::screen->draw();
}
void editor_action_label::perform_without_undo(map_context& mc) const
{
mc.get_map().get_game_labels().set_label(loc_,text_);
mc.set_needs_labels_reset();
}
editor_action* editor_action_village::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo;
//TODO return undo.release() ?
if(!mc.get_map().is_village(loc_)) return NULL;
std::vector<team>& teams = mc.get_map().get_teams();
team *t = unsigned(side_number_) < teams.size() ? &teams[side_number_] : NULL;
if (t && t->owns_village(loc_)) {
return NULL;
}
undo.reset(new editor_action_village_delete(loc_));
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_))
undo.reset(new editor_action_village(loc_, i->side() -1));
}
perform_without_undo(mc);
return undo.release();
}
void editor_action_village::perform_without_undo(map_context& mc) const
{
std::vector<team>& teams = mc.get_map().get_teams();
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
i->lose_village(loc_);
}
teams[side_number_].get_village(loc_, false);
}
editor_action* editor_action_village_delete::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo;
//TODO can teams be const?
std::vector<team>& teams = mc.get_map().get_teams();
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_)) {
perform_without_undo(mc);
undo.reset(new editor_action_village(loc_, i->side() -1));
}
}
return undo.release();
}
void editor_action_village_delete::perform_without_undo(map_context& mc) const
{
std::vector<team>& teams = mc.get_map().get_teams();
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_)) {
i->lose_village(loc_);
}
}
}
editor_action* editor_action_unit_delete::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo;
unit_map& units = mc.get_units();
unit_map::const_unit_iterator unit_it = units.find(loc_);
if (unit_it != units.end()) {
undo.reset(new editor_action_unit(loc_, *unit_it));
perform_without_undo(mc);
}
return undo.release();
}
void editor_action_unit_delete::perform_without_undo(map_context& mc) const
{
unit_map& units = mc.get_units();
if (!units.erase(loc_)) {
ERR_ED << "Could not delete unit on " << loc_.x << "/" << loc_.y;
}
mc.set_needs_labels_reset();
}
editor_action* editor_action_unit::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo(new editor_action_unit_delete(loc_));
perform_without_undo(mc);
return undo.release();
}
void editor_action_unit::perform_without_undo(map_context& mc) const
{
mc.get_units().add(loc_,u_);
mc.get_units().find(loc_)->set_location(loc_);
//TODO may be useful
// chosen.new_turn();
mc.set_needs_labels_reset();
}
editor_action_unit_delete* editor_action_unit_delete::clone() const
{
return new editor_action_unit_delete(*this);
}
editor_action_select* editor_action_select::clone() const
{
return new editor_action_select(*this);
@ -646,7 +397,7 @@ editor_action_create_mask* editor_action_create_mask::clone() const
}
void editor_action_create_mask::perform_without_undo(map_context& mc) const
{
mc.get_map() = editor_map(mc.get_map().mask_to(target_), mc.get_map().get_level());
mc.get_map() = editor_map(mc.get_map().mask_to(target_));
mc.set_needs_terrain_rebuild();
}

View file

@ -31,11 +31,7 @@
#include "map_fragment.hpp"
#include "../map.hpp"
#include "../map_label.hpp"
#include "../terrain.hpp"
#include "../unit_types.hpp"
namespace editor {
/**
@ -265,25 +261,6 @@ class editor_action_paint_area : public editor_action_area
bool one_layer_;
};
/**
* Name the selected terrain.
*/
class editor_action_name_area : public editor_action_area
{
public:
editor_action_name_area(const std::set<map_location>& area, const std::string& area_id)
: editor_action_area(area), area_id_(area_id)
{
}
editor_action_name_area* clone() const;
editor_action_paste* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "name_area"; }
private:
const std::string area_id_;
};
/**
* Flood fill. Somewhat redundant with paint_area.
*/
@ -321,126 +298,6 @@ class editor_action_starting_position : public editor_action_location
int player_;
};
/**
* Set label action
*/
class editor_action_label : public editor_action_location
{
public:
editor_action_label(map_location loc, const std::string& text, const std::string& team_name)
: editor_action_location(loc), text_(text) , team_name_(team_name)
{
}
editor_action_label* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "label"; }
protected:
const std::string text_;
const std::string team_name_;
};
class editor_action_label_delete : public editor_action_location
{
public:
editor_action_label_delete(map_location loc)
: editor_action_location(loc)
{
}
editor_action_label_delete* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "label_delete"; }
};
/**
* place a new unit on the map
*/
class editor_action_unit : public editor_action_location
{
public:
editor_action_unit(map_location loc,
const unit& u)
: editor_action_location(loc), u_(u)
{
}
editor_action_unit* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "unit"; }
protected:
unit u_;
};
/**
* Remove a unit from the map.
*/
class editor_action_unit_delete : public editor_action_location
{
public:
editor_action_unit_delete(map_location loc)
: editor_action_location(loc)
{
}
editor_action_unit_delete* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "unit_delete"; }
};
/**
* Clears the ownership of a village.
*/
class editor_action_village_delete : public editor_action_location
{
public:
editor_action_village_delete(map_location loc)
: editor_action_location(loc)
{
}
editor_action_village_delete* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "village_delete"; }
};
/**
* Sets the ownership of a village to the current side.
*/
class editor_action_village : public editor_action_location
{
public:
editor_action_village(map_location loc, int side_number)
: editor_action_location(loc), side_number_(side_number)
{
}
editor_action_village* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "village"; }
private:
int side_number_;
};
class editor_action_unit_replace : public editor_action_location
{
public:
editor_action_unit_replace(map_location loc, map_location new_loc)
: editor_action_location(loc), new_loc_(new_loc)
{
}
editor_action_unit_replace* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "replace_unit"; }
protected:
map_location new_loc_;
};
/**
* Select the given locations

View file

@ -13,6 +13,7 @@
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "asserts.hpp"
#include "action.hpp"
#include "editor_controller.hpp"
#include "editor_palettes.hpp"
@ -27,8 +28,6 @@
#include "gui/dialogs/transient_message.hpp"
#include "gui/widgets/window.hpp"
#include "../resources.hpp"
#include "../asserts.hpp"
#include "../clipboard.hpp"
#include "../filechooser.hpp"
#include "../filesystem.hpp"
@ -66,7 +65,6 @@ public:
}
private:
editor_controller& ec_;
//TODO size_changed_ is private and not used in the class.
bool size_changed_;
bool refreshed_;
};
@ -74,13 +72,10 @@ private:
editor_controller::editor_controller(const config &game_config, CVideo& video, map_context* init_map_context /*=NULL*/)
: controller_base(SDL_GetTicks(), game_config, video)
, mouse_handler_base()
, halo_manager_()
, rng_(NULL)
, rng_setter_(NULL)
, map_contexts_()
, current_context_index_(0)
, current_area_index_(0)
, current_side_index_(0)
, gui_(NULL)
, map_generators_()
, tods_()
@ -113,7 +108,6 @@ editor_controller::editor_controller(const config &game_config, CVideo& video, m
if (default_dir_.empty()) {
default_dir_ = get_dir(get_dir(get_user_data_dir() + "/editor") + "/maps");
}
init_globals();
init_gui(video);
init_brushes(game_config);
init_mouse_actions(game_config);
@ -125,7 +119,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video, m
rng_.reset(new rand_rng::rng());
rng_setter_.reset(new rand_rng::set_random_generator(rng_.get()));
hotkey::get_hotkey(hotkey::HOTKEY_QUIT_GAME).set_description(_("Quit Editor"));
get_map_context().set_starting_position_labels(gui());
cursor::set(cursor::NORMAL);
image::set_colour_adjustment(preferences::editor::tod_r(), preferences::editor::tod_g(), preferences::editor::tod_b());
theme& theme = gui().get_theme();
@ -146,29 +140,16 @@ editor_controller::editor_controller(const config &game_config, CVideo& video, m
}
}
void editor_controller::init_globals()
{
resources::game_map = &(get_map());
resources::teams = &(get_map().get_teams());
resources::tod_manager = &(get_map().get_tod_manager());
resources::units = &(get_map().get_units());
resources::state_of_game = &(get_map().get_state());
}
void editor_controller::init_gui(CVideo& video)
{
const config &theme_cfg = get_theme(game_config_, "editor");
gui_.reset(new editor_display(video, &get_map(), theme_cfg, config()));
gui_.reset(new editor_display(video, get_map(), theme_cfg, config()));
gui_->set_grid(preferences::grid());
prefs_disp_manager_.reset(new preferences::display_manager(&gui()));
gui_->add_redraw_observer(boost::bind(&editor_controller::display_redraw_callback, this, _1));
floating_label_manager_.reset(new font::floating_label_context());
gui().set_draw_coordinates(preferences::editor::draw_hex_coordinates());
gui().set_draw_terrain_codes(preferences::editor::draw_terrain_codes());
halo_manager_.reset(new halo::manager(*gui_));
}
void editor_controller::init_sidebar(const config& game_config)
@ -203,16 +184,6 @@ void editor_controller::init_mouse_actions(const config& game_config)
new mouse_action_select(&brush_, key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION,
new mouse_action_starting_position(key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_LABEL,
new mouse_action_map_label(key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_UNIT,
new mouse_action_unit(key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_PATH,
new mouse_action_path(key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_VILLAGE,
new mouse_action_village(key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
new mouse_action_paste(clipboard_, key_)));
foreach (const theme::menu& menu, gui().get_theme().menus()) {
@ -357,7 +328,7 @@ int editor_controller::add_map_context(map_context* mc)
void editor_controller::create_default_context()
{
map_context* mc = new map_context(editor_map(game_config_, 44, 33, t_translation::GRASS_LAND, config()));
map_context* mc = new map_context(editor_map(game_config_, 44, 33, t_translation::GRASS_LAND));
add_map_context(mc);
}
@ -384,34 +355,8 @@ void editor_controller::switch_context(const int index)
WRN_ED << "Invalid index in switch map context: " << index << "\n";
return;
}
current_context_index_ = index;
current_side_index_ = 0;
current_area_index_ = 0;
map_context_refresher mcr(*this, *map_contexts_[index]);
}
void editor_controller::switch_area(const int index)
{
//TODO implement undo
const map_areas areas = get_map().get_named_areas();
const std::vector<std::string> ids = areas.get_area_ids();
current_area_index_ = index;
std::string area_id = ids[index];
map_area area = areas.get_area(area_id);
std::set<map_location> area_locs = area.get_simple_locations();
get_display().scroll_to_tile(*(area_locs.begin()),display::WARP);
perform_refresh(editor_action_select(area_locs));
}
void editor_controller::switch_side(const int index)
{
if (index < 0 || static_cast<size_t>(index) >= get_map_context().get_map().get_teams().size() +1) {
WRN_ED << "Invalid index in switch side context: " << index << "\n";
return;
}
get_display().set_team(index , false);
get_display().set_playing_team(index );
current_side_index_ = index;
current_context_index_ = index;
}
void editor_controller::replace_map_context(map_context* new_mc)
@ -503,35 +448,6 @@ void editor_controller::new_map_dialog()
}
}
void editor_controller::new_side_dialog()
{
if (!use_mdi_ && !confirm_discard()) return;
std::vector<team>& teams = get_map().get_teams();
int side = get_map().get_teams().size();
std::string side_str = lexical_cast<std::string>(side);
std::string new_str = lexical_cast<std::string>(side +1);
//TODO make that translatable.
gui2::show_message(gui().video(), "Side created" , "The side number " + side_str + " was created.");
config side_cfg;
side_cfg["no_leader"] = "yes";
side_cfg["side"] = new_str;
//TODO remove or comment.
//get_map().get_state().build_team(dummy, "", get_map().get_teams(), dummy, get_map()
// , get_map().get_units(), true);
team t(side_cfg, get_map(), 100);
//This may invalidate the teams vector
teams.push_back(t);
get_display().load_flags();
get_display().set_team(side -1, true);
get_display().set_playing_team(side -1);
get_map_context().clear_undo_redo();
current_side_index_ = side -1;
}
void editor_controller::save_map_as_dialog()
{
std::string input_name = get_map_context().get_filename();
@ -561,37 +477,6 @@ void editor_controller::save_map_as_dialog()
save_map_as(input_name);
}
//TODO avoid duplicate code.
void editor_controller::save_multiplayer_as_dialog()
{
std::string input_name = get_map_context().get_filename();
if (input_name.empty()) {
input_name = default_dir_;
}
const std::string old_input_name = input_name;
int res = 0;
int overwrite_res = 1;
do {
input_name = old_input_name;
res = dialogs::show_file_chooser_dialog_save(gui(), input_name, _("Save the Multiplayer Scenario As"));
if (res == 0) {
if (file_exists(input_name)) {
overwrite_res = gui::dialog(gui(), "",
_("The file already exists. Do you want to overwrite it?"),
gui::YES_NO).show();
} else {
overwrite_res = 0;
}
} else {
return; //cancel pressed
}
} while (overwrite_res != 0);
save_multiplayer_as(input_name);
}
void editor_controller::generate_map_dialog()
{
if (map_generators_.empty()) {
@ -615,7 +500,7 @@ void editor_controller::generate_map_dialog()
if (map_string.empty()) {
gui2::show_transient_message(gui().video(), "", _("Map creation failed."));
} else {
editor_map new_map(game_config_, map_string, config());
editor_map new_map(game_config_, map_string);
editor_action_whole_map a(new_map);
perform_refresh(a);
}
@ -751,30 +636,6 @@ bool editor_controller::save_map_as(const std::string& filename)
}
}
bool editor_controller::save_multiplayer_as(const std::string& filename)
{
size_t is_open = check_open_map(filename);
if (is_open < map_contexts_.size()
&& is_open != static_cast<unsigned>(current_context_index_)) {
gui::dialog(gui(), _("This map is already open."), filename).show();
return false;
}
std::string old_filename = get_map_context().get_filename();
bool embedded = get_map_context().is_embedded();
get_map_context().set_filename(filename);
get_map_context().set_embedded(false);
if (!save_multiplayer(true)) {
get_map_context().set_filename(old_filename);
get_map_context().set_embedded(embedded);
return false;
} else {
return true;
}
}
bool editor_controller::save_map(bool display_confirmation)
{
try {
@ -789,24 +650,6 @@ bool editor_controller::save_map(bool display_confirmation)
return true;
}
bool editor_controller::save_multiplayer(bool display_confirmation)
{
gui::dialog d(get_display(), _("Scenario ID?"), "", gui::OK_CANCEL);
d.set_textbox(_("ID: "), "");
d.show();
try {
get_map_context().save_multiplayer(d.textbox_text());
if (display_confirmation) {
gui2::show_transient_message(gui().video(), "", _("Multiplayer Scenario saved."));
}
} catch (editor_map_save_exception& e) {
gui2::show_transient_message(gui().video(), "", e.what());
return false;
}
return true;
}
size_t editor_controller::check_open_map(const std::string& fn) const
{
size_t i = 0;
@ -814,6 +657,7 @@ size_t editor_controller::check_open_map(const std::string& fn) const
return i;
}
bool editor_controller::check_switch_open_map(const std::string& fn)
{
size_t i = check_open_map(fn);
@ -861,7 +705,6 @@ void editor_controller::load_map(const std::string& filename, bool new_context)
}
}
}
} catch (editor_map_load_exception& e) {
gui2::show_transient_message(gui().video(), _("Error loading map"), e.what());
return;
@ -881,7 +724,7 @@ void editor_controller::revert_map()
void editor_controller::new_map(int width, int height, t_translation::t_terrain fill, bool new_context)
{
editor_map m(game_config_, width, height, fill, config());
editor_map m(game_config_, width, height, fill);
if (new_context) {
int new_id = add_map_context(new map_context(m));
switch_context(new_id);
@ -945,22 +788,15 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
{
using namespace hotkey; //reduce hotkey:: clutter
unsigned i = static_cast<unsigned>(index);
switch (command) {
case HOTKEY_NULL:
if (index < 0)
return false;
switch (menu_context_) {
case WINDOW:
//TODO Ilor -- here is the place to disable the one item menu.
return (i < map_contexts_.size());
case AREA:
return (i < get_map().get_named_areas().get_area_ids().size() +1);
case SIDE:
return (i < get_map().get_teams().size() +1);
if (index >= 0) {
unsigned i = static_cast<unsigned>(index);
if (i < map_contexts_.size()) {
return true;
}
}
return false;
case HOTKEY_ZOOM_IN:
case HOTKEY_ZOOM_OUT:
case HOTKEY_ZOOM_DEFAULT:
@ -983,45 +819,28 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
case HOTKEY_EDITOR_SETTINGS:
case HOTKEY_EDITOR_MAP_NEW:
case HOTKEY_EDITOR_SIDE_NEW:
case HOTKEY_EDITOR_MAP_LOAD:
case HOTKEY_EDITOR_MAP_SAVE_AS:
//TODO disable the multiplayer save options when no sides defined?
case HOTKEY_EDITOR_MULTIPLAYER_SAVE:
//TODO clean up.
// case HOTKEY_EDITOR_MULTIPLAYER_SAVE_AS:
case HOTKEY_EDITOR_BRUSH_NEXT:
case HOTKEY_EDITOR_TOOL_NEXT:
case HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP:
return true; //editor hotkeys we can always do
case HOTKEY_EDITOR_MAP_SAVE:
case HOTKEY_EDITOR_SWITCH_MAP:
case HOTKEY_EDITOR_SWITCH_AREA:
case HOTKEY_EDITOR_SWITCH_SIDE:
case HOTKEY_EDITOR_CLOSE_MAP:
return true;
case HOTKEY_EDITOR_MAP_REVERT:
return !get_map_context().get_filename().empty();
return true;
case HOTKEY_EDITOR_TOOL_PAINT:
case HOTKEY_EDITOR_TOOL_FILL:
case HOTKEY_EDITOR_TOOL_SELECT:
case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
return true; //tool selection always possible
case HOTKEY_EDITOR_TOOL_LABEL:
return true; //tool selection always possible
case HOTKEY_EDITOR_TOOL_UNIT:
return true; //tool selection always possible
case HOTKEY_EDITOR_TOOL_VILLAGE:
return true; //tool selection always possible
case HOTKEY_EDITOR_TOOL_PATH:
return true; //tool selection always possible
case HOTKEY_EDITOR_CUT:
case HOTKEY_EDITOR_COPY:
case HOTKEY_EDITOR_EXPORT_SELECTION_COORDS:
case HOTKEY_EDITOR_SELECTION_FILL:
case HOTKEY_EDITOR_SELECTION_NAME:
case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
return !get_map().selection().empty();
case HOTKEY_EDITOR_SELECTION_ROTATE:
@ -1063,10 +882,6 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case HOTKEY_EDITOR_TOOL_PAINT:
case HOTKEY_EDITOR_TOOL_FILL:
case HOTKEY_EDITOR_TOOL_SELECT:
case HOTKEY_EDITOR_TOOL_LABEL:
case HOTKEY_EDITOR_TOOL_UNIT:
case HOTKEY_EDITOR_TOOL_PATH:
case HOTKEY_EDITOR_TOOL_VILLAGE:
case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
return is_mouse_action_set(command) ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_DRAW_COORDINATES:
@ -1074,15 +889,8 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case HOTKEY_EDITOR_DRAW_TERRAIN_CODES:
return gui_->get_draw_terrain_codes() ? ACTION_ON : ACTION_OFF;
case HOTKEY_NULL:
switch (menu_context_) {
case WINDOW:
return index == current_context_index_ ? ACTION_ON : ACTION_OFF;
case AREA:
return index == current_area_index_ ? ACTION_ON : ACTION_OFF;
case SIDE:
return index == current_side_index_ ? ACTION_ON : ACTION_OFF;
}
default:
return index == current_context_index_ ? ACTION_ON : ACTION_OFF;
default:
return command_executor::get_action_state(command, index);
}
}
@ -1091,31 +899,16 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
{
SCOPE_ED;
using namespace hotkey;
unsigned i = static_cast<unsigned>(index);
switch (command) {
case HOTKEY_NULL:
if (index < 0) {
return false;
}
switch (menu_context_) {
case WINDOW:
if (index >= 0) {
unsigned i = static_cast<unsigned>(index);
if (i < map_contexts_.size()) {
switch_context(index);
return true;
}
case SIDE:
if (i < get_map().get_teams().size() +1) {
switch_side(index);
return true;
}
case AREA:
if (i < get_map().get_named_areas().get_area_ids().size() +1) {
switch_area(index);
return true;
}
}
return false;
case HOTKEY_QUIT_GAME:
quit_confirm(EXIT_NORMAL);
return true;
@ -1141,15 +934,8 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_TOOL_FILL:
case HOTKEY_EDITOR_TOOL_SELECT:
case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
case HOTKEY_EDITOR_TOOL_LABEL:
hotkey_set_mouse_action(command);
return true;
case HOTKEY_EDITOR_TOOL_VILLAGE:
case HOTKEY_EDITOR_TOOL_UNIT:
case HOTKEY_EDITOR_TOOL_PATH:
if (current_side_index_ != (signed)(get_map().get_teams().size() -1))
hotkey_set_mouse_action(command);
return true;
case HOTKEY_EDITOR_PASTE: //paste is somewhat different as it might be "one action then revert to previous mode"
hotkey_set_mouse_action(command);
return true;
@ -1194,9 +980,6 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_SELECTION_FILL:
fill_selection();
return true;
case HOTKEY_EDITOR_SELECTION_NAME:
name_selection();
return true;
case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
perform_refresh(editor_action_shuffle_area(get_map().selection()));
return true;
@ -1209,9 +992,6 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_MAP_REVERT:
revert_map();
return true;
case HOTKEY_EDITOR_SIDE_NEW:
new_side_dialog();
return true;
case HOTKEY_EDITOR_MAP_NEW:
new_map_dialog();
return true;
@ -1223,22 +1003,9 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
save_map();
}
return true;
case HOTKEY_EDITOR_MULTIPLAYER_SAVE:
//TODO clean up.
// if (get_map_context().get_filename().empty()
// || is_directory(get_map_context().get_filename())) {
// save_multiplayer_as_dialog();
// } else {
save_multiplayer();
// }
return true;
case HOTKEY_EDITOR_MAP_SAVE_AS:
save_map_as_dialog();
return true;
//TODO clean up.
// case HOTKEY_EDITOR_MULTIPLAYER_SAVE_AS:
// save_multiplayer_as_dialog();
// return true;
case HOTKEY_EDITOR_MAP_GENERATE:
generate_map_dialog();
return true;
@ -1305,41 +1072,6 @@ void editor_controller::expand_open_maps_menu(std::vector<std::string>& items)
break;
}
}
menu_context_ = WINDOW;
}
void editor_controller::expand_side_menu(std::vector<std::string>& items)
{
for (unsigned int i = 0 ; i < items.size(); ++i) {
if (items[i] == "editor-switch-side") {
items.erase(items.begin() + i);
//TODO "None" needs to be localized
for (unsigned int i = 1; i < get_map().get_teams().size(); ++i) {
std::string label = "[" + lexical_cast<std::string>(i) + "] "
+ lexical_cast<std::string>(get_map().get_teams()[i-1].side());
items.push_back(label);
}
std::string none_label = "[None] ";
items.push_back(none_label);
}
}
menu_context_ = SIDE;
}
void editor_controller::expand_named_area_menu(std::vector<std::string>& items)
{
for (unsigned int i = 0; i < items.size(); ++i) {
if (items[i] == "editor-switch-area") {
items.erase(items.begin() + i);
std::vector<std::string> areas = get_map().get_named_areas().get_area_ids();
items.insert(items.end(), areas.begin(), areas.end() );
std::string none_label = "[None] ";
items.push_back(none_label);
}
}
menu_context_ = AREA;
}
void editor_controller::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu)
@ -1390,14 +1122,6 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
expand_open_maps_menu(items);
context_menu = true; //FIXME hack to display a one-item menu
}
if (!items.empty() && items.front() == "editor-switch-area") {
expand_named_area_menu(items);
context_menu = true; //FIXME hack to display a one-item menu
}
if (!items.empty() && items.front() == "editor-switch-side") {
expand_side_menu(items);
context_menu = true; //FIXME hack to display a one-item menu
}
command_executor::show_menu(items, xloc, yloc, context_menu, gui());
}
@ -1460,37 +1184,6 @@ void editor_controller::fill_selection()
perform_refresh(editor_action_paint_area(get_map().selection(), foreground_terrain_));
}
void editor_controller::name_selection()
{
gui::dialog d(get_display(), _("Name Selected Area"), "", gui::OK_CANCEL);
//TODO think about map_labels::get_max_chars
d.set_textbox(_("Area Identity: "), "", map_labels::get_max_chars());
// d.set_textbox(_("Area Identity: "), (old_label ? old_label->text() : ""), map_labels::get_max_chars());
// //TODO note that gui1 does not support more than one textbox in a dialogue.
//// d.set_textbox(_("Team: "), (old_label ? old_label->team_name() : ""), map_labels::get_max_chars());
// d.add_option(_("Visible in Fog"), visible_in_fog, gui::dialog::BUTTON_CHECKBOX_LEFT);
// d.add_option(_("Visible in Shroud"), visible_in_shroud, gui::dialog::BUTTON_CHECKBOX_LEFT);
if(!d.show()) {
// SDL_Color colour = font::LABEL_COLOUR;
//TODO cleanup
// remove the old label if we changed the team_name
// if (d.option_checked() == (old_team_name == "")) {
// const terrain_label* old = gui_->labels().set_label(loc, "", old_team_name, colour);
// if (old) recorder.add_label(old);
// }
// const terrain_label* res = gui_->labels().set_label(loc, d.textbox_text(), team_name, colour);
// terrain_label label = new terrain_label(d.textbox_text(), "", hex, )
// const terrain_label* label = disp.labels().set_label(hex, d.textbox_text());
perform_refresh(editor_action_name_area(get_map().selection(), d.textbox_text()));
// a = new editor_action_label(hex, d.textbox_text());
// update_brush_highlights(disp, hex);
}
}
void editor_controller::hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
{
std::map<hotkey::HOTKEY_COMMAND, mouse_action*>::iterator i = mouse_actions_.find(command);

View file

@ -22,10 +22,6 @@
#include "editor_main.hpp"
#include "map_context.hpp"
#include "map_fragment.hpp"
#include "halo.hpp"
//#include "tod_manager.hpp"
//#include "soundsource.hpp"
#include "..//gamestatus.hpp"
#include "../controller_base.hpp"
#include "../events.hpp"
@ -116,9 +112,6 @@ class editor_controller : public controller_base,
/** Get the map from the current map context object */
editor_map& get_map() { return get_map_context().get_map(); }
/** Get the units from the current map context object */
unit_map& get_units() { return get_map_context().get_units(); }
/** Get the map from the current map context object - const version*/
const editor_map& get_map() const { return get_map_context().get_map(); }
@ -137,12 +130,6 @@ class editor_controller : public controller_base,
/** Switches the context to the one under the specified index. */
void switch_context(const int index);
/** Switches the side to the one under the specified index. */
void switch_area(const int index);
/** Switches the side to the one under the specified index. */
void switch_side(const int index);
/** Set the default dir (where the filebrowser is pointing at when there is no map file opened) */
void set_default_dir(const std::string& str);
@ -152,15 +139,9 @@ class editor_controller : public controller_base,
/** Display a new map dialog and process user input. */
void new_map_dialog();
/** Display a new map dialog and process user input. */
void new_side_dialog();
/** Display a save map as dialog and process user input. */
void save_map_as_dialog();
/** Display a save map as dialog and process user input. */
void save_multiplayer_as_dialog();
/** Display a generate random map dialog and process user input. */
void generate_map_dialog();
@ -185,18 +166,6 @@ class editor_controller : public controller_base,
*/
bool save_map(bool display_confirmation = false);
/**
* Save a multiplayer scenario under a given filename.
* @return true on success
*/
bool save_multiplayer_as(const std::string& filename);
/**
* Save the multiplayer scenario under a given filename. Displays an error message on failure.
* @return true on success
*/
bool save_multiplayer(bool display_confirmation = false);
/**
* Create a new map.
*/
@ -256,12 +225,6 @@ class editor_controller : public controller_base,
/** Menu expanding for open maps list */
void expand_open_maps_menu(std::vector<std::string>& items);
/** Menu expanding for defined locations list */
void expand_side_menu(std::vector<std::string>& items);
/** Menu expanding for defined locations list */
void expand_named_area_menu(std::vector<std::string>& items);
/** controller_base override */
void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu);
@ -286,9 +249,6 @@ class editor_controller : public controller_base,
/** Fill the selection with the foreground terrain */
void fill_selection();
/** Declare a named location on the selection */
void name_selection();
/**
* Set the current mouse action based on a hotkey id
*/
@ -356,9 +316,6 @@ class editor_controller : public controller_base,
/** init the display object and general set-up */
void init_gui(CVideo& video);
/** init the global singletons */
void init_globals();
/** init the sidebar objects */
void init_sidebar(const config& game_config);
@ -412,8 +369,6 @@ class editor_controller : public controller_base,
*/
void redo();
boost::scoped_ptr<halo::manager> halo_manager_;
boost::scoped_ptr<rand_rng::rng> rng_;
boost::scoped_ptr<rand_rng::set_random_generator> rng_setter_;
@ -424,12 +379,6 @@ class editor_controller : public controller_base,
/** Index into the map_contexts_ array */
int current_context_index_;
/** Index for the areas */
int current_area_index_;
/** Index for the sides */
int current_side_index_;
/** The display object used and owned by the editor. */
boost::scoped_ptr<editor_display> gui_;
@ -452,11 +401,6 @@ class editor_controller : public controller_base,
boost::scoped_ptr<preferences::display_manager> prefs_disp_manager_;
tooltips::manager tooltip_manager_;
boost::scoped_ptr<font::floating_label_context> floating_label_manager_;
//TODO clean up
// tod_manager tod_manager_;
// boost::scoped_ptr<soundsource::manager> soundsources_manager_;
/** Quit main loop flag */
bool do_quit_;
@ -498,18 +442,6 @@ class editor_controller : public controller_base,
/** Default directory for map load/save as dialogs */
std::string default_dir_;
enum menu_context {
WINDOW,
AREA,
SIDE,
};
menu_context menu_context_;
//TODO
game_state game_state_;
// std::vector<team> teams_;
};
} //end namespace editor

View file

@ -15,13 +15,12 @@
#include "editor_display.hpp"
#include "builder.hpp"
#include "resources.hpp"
namespace editor {
editor_display::editor_display(CVideo& video, editor_map* map,
editor_display::editor_display(CVideo& video, const editor_map& map,
const config& theme_cfg, const config& level)
: game_display(&map->get_units(), video, map, &map->get_tod_manager(), &map->get_teams(), theme_cfg, level)
: display(video, &map, theme_cfg, level)
, brush_locations_()
, toolbar_hint_()
{
@ -57,33 +56,10 @@ void editor_display::rebuild_terrain(const map_location &loc) {
builder_->rebuild_terrain(loc);
}
//TODO clean up.
//void editor_display::pre_draw()
//{
//}
void editor_display::change_map(editor_map* m)
void editor_display::pre_draw()
{
map_ = m;
teams_ = &m->get_teams();
units_ = &m->get_units();
tod_manager_ = &m->get_tod_manager();
builder_->change_map(m);
resources::game_map = map_;
resources::teams = &m->get_teams();
resources::tod_manager = &m->get_tod_manager();
resources::units = &m->get_units();
resources::state_of_game = &m->get_state();
load_flags();
set_playing_team(0);
set_team(0, true);
}
image::TYPE editor_display::get_image_type(const map_location& loc)
{
if (brush_locations_.find(loc) != brush_locations_.end()) {
@ -94,19 +70,19 @@ image::TYPE editor_display::get_image_type(const map_location& loc)
return image::SCALED_TO_HEX;
}
//void editor_display::draw_hex(const map_location& loc)
//{
// int xpos = get_location_x(loc);
// int ypos = get_location_y(loc);
// tblit blit(xpos, ypos);
// display::draw_hex(loc);
// if (map().on_board_with_border(loc)) {
// if (map().in_selection(loc)) {
// drawing_buffer_add(LAYER_FOG_SHROUD, loc, tblit(xpos, ypos,
// image::get_image("editor/selection-overlay.png", image::SCALED_TO_HEX)));
// }
// }
//}
void editor_display::draw_hex(const map_location& loc)
{
int xpos = get_location_x(loc);
int ypos = get_location_y(loc);
tblit blit(xpos, ypos);
display::draw_hex(loc);
if (map().on_board_with_border(loc)) {
if (map().in_selection(loc)) {
drawing_buffer_add(LAYER_FOG_SHROUD, loc, tblit(xpos, ypos,
image::get_image("editor/selection-overlay.png", image::SCALED_TO_HEX)));
}
}
}
const SDL_Rect& editor_display::get_clip_rect()
{
@ -120,46 +96,7 @@ void editor_display::draw_sidebar()
refresh_report(reports::TERRAIN, reports::report(get_map().get_terrain_string(mouseoverHex_)));
refresh_report(reports::POSITION, reports::report(lexical_cast<std::string>(mouseoverHex_)));
}
//TODO cleanup.
// const team_data data = calculate_team_data(current_team, current_side, units_);
// if (current_side != playing_side)
// str << span_color(font::GRAY_COLOUR);
// str << data.villages << '/';
// if (current_team.uses_shroud()) {
// int unshrouded_villages = 0;
// std::vector<map_location>::const_iterator i = map.villages().begin();
// for (; i != map.villages().end(); ++i) {
// if (!current_team.shrouded(*i))
// ++unshrouded_villages;
// }
// str << unshrouded_villages;
// } else {
// str << map.villages().size();
// }
// if (current_side != playing_side)
// str << naps;
std::ostringstream village_report;
village_report << lexical_cast<std::string>(map().get_teams()[viewing_side() -1].villages().size())
<< "/" << lexical_cast<std::string>(get_map().villages().size());
refresh_report(reports::VILLAGES, reports::report(village_report.str()));
std::ostringstream unit_report;
unit_report << lexical_cast<std::string>(side_units(map().get_units(), viewing_side()))
<< "/" << lexical_cast<std::string>(map().get_units().size());
//TODO cleanup.
// case NUM_UNITS: {
// if (current_side != playing_side)
// str << span_color(font::GRAY_COLOUR);
// str << side_units(units, current_side);
// if (current_side != playing_side)
// str << naps;
// break;
refresh_report(reports::NUM_UNITS, reports::report(unit_report.str()));
refresh_report(reports::VILLAGES, reports::report(lexical_cast<std::string>(get_map().villages().size())));
refresh_report(reports::EDITOR_TOOL_HINT, reports::report(toolbar_hint_));
}

View file

@ -16,15 +16,15 @@
#define EDITOR_EDITOR_DISPLAY_HPP_INCLUDED
#include "editor_map.hpp"
#include "../game_display.hpp"
#include "../display.hpp"
namespace editor {
class editor_display : public game_display
class editor_display : public display
{
public:
editor_display(CVideo& video, editor_map* map,
const config& theme_cfg, const config& level);
editor_display(CVideo& video, const editor_map& map, const config& theme_cfg,
const config& level);
bool in_editor() const { return true; }
@ -32,22 +32,18 @@ public:
void set_brush_locs(const std::set<map_location>& hexes);
void clear_brush_locs();
void remove_brush_loc(const map_location& hex);
const editor_map& const_map() const { return static_cast<const editor_map&>(get_map()); }
editor_map& map() { return static_cast<editor_map&>(get_map()); }
const editor_map& map() const { return static_cast<const editor_map&>(get_map()); }
void rebuild_terrain(const map_location &loc);
void set_toolbar_hint(const std::string& value) { toolbar_hint_ = value; }
void change_map(editor_map* m);
protected:
//TODO
//void pre_draw();
void pre_draw();
/**
* The editor uses different rules for terrain highligting (e.g. selections)
*/
image::TYPE get_image_type(const map_location& loc);
//void draw_hex(const map_location& loc);
void draw_hex(const map_location& loc);
const SDL_Rect& get_clip_rect();
void draw_sidebar();

View file

@ -48,7 +48,7 @@ size_specs::size_specs()
void adjust_sizes(const display &disp, size_specs &sizes) {
/** @todo Hardcoded coordinates for brush selection, make it themeable. */
sizes.brush_x = disp.map_outside_area().w + 10;
sizes.brush_y = 242;
sizes.brush_y = 212;
/** @todo Hardcoded coordinates for terrain palette, make it themeable. */
sizes.palette_x = disp.map_outside_area().w + 16;
sizes.palette_y = sizes.brush_y + 72;

View file

@ -16,8 +16,6 @@
#include "action_base.hpp"
#include "editor_map.hpp"
#include "formula_string_utils.hpp"
#include "resources.hpp"
#include "map_location.hpp"
#include "../display.hpp"
#include "../filesystem.hpp"
@ -42,38 +40,23 @@ editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, c
return editor_map_load_exception(filename, msg);
}
editor_map::editor_map(const config& terrain_cfg, const config& level)
editor_map::editor_map(const config& terrain_cfg)
: gamemap(terrain_cfg, gamemap::default_map_header)
, selection_()
, units_()
, game_labels_(level)
, named_areas_(level)
, tod_manager_(level, 1)
, teams_()
, cfg_(level)
, state_()
{
setup(level);
}
editor_map::editor_map(const config& terrain_cfg, const std::string& data, const config& level)
editor_map::editor_map(const config& terrain_cfg, const std::string& data)
: gamemap(terrain_cfg, data)
, selection_()
, units_()
, game_labels_(level)
, named_areas_(level)
, tod_manager_(level, 1)
, teams_()
, cfg_(level)
{
setup(level);
sanity_check();
}
editor_map editor_map::from_string(const config& terrain_cfg, const std::string& data, const config& level)
editor_map editor_map::from_string(const config& terrain_cfg, const std::string& data)
{
try {
return editor_map(terrain_cfg, data, level);
return editor_map(terrain_cfg, data);
} catch (incorrect_map_format_exception& e) {
throw wrap_exc("format", e.msg_, "");
} catch (twml_exception& e) {
@ -83,34 +66,18 @@ editor_map editor_map::from_string(const config& terrain_cfg, const std::string&
}
}
editor_map::editor_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler, const config& level)
editor_map::editor_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler)
: gamemap(terrain_cfg, gamemap::default_map_header + t_translation::write_game_map(
t_translation::t_map(width + 2, t_translation::t_list(height + 2, filler))))
, selection_()
, units_()
, game_labels_(level)
, named_areas_(level)
, tod_manager_(level, 1)
, teams_()
, cfg_(level)
, state_()
{
setup(level);
sanity_check();
}
editor_map::editor_map(const gamemap& map, const config& level)
editor_map::editor_map(const gamemap& map)
: gamemap(map)
, selection_()
, units_()
, game_labels_(level)
, named_areas_(level)
, tod_manager_(level, 1)
, teams_()
, cfg_(level)
, state_()
{
setup(level);
sanity_check();
}
@ -183,8 +150,7 @@ std::set<map_location> editor_map::set_starting_position_labels(display& disp)
label += " ";
for (int i = 1; i <= gamemap::MAX_PLAYERS; i++) {
if (startingPositions_[i].valid()) {
disp.labels().set_label(startingPositions_[i],
label + lexical_cast<std::string>(i), "", font::LABEL_COLOUR, true, true, false);
disp.labels().set_label(startingPositions_[i], label + lexical_cast<std::string>(i));
label_locs.insert(startingPositions_[i]);
}
}
@ -419,34 +385,6 @@ void editor_map::shrink_bottom(int count)
total_height_ -= count;
}
void editor_map::setup(const config& level)
{
resources::game_map = this;
resources::units = &units_;
resources::teams = &teams_;
resources::state_of_game = &state_;
//TODO make the controller available?
// resources::controller = this;
resources::tod_manager = &tod_manager_;
foreach (const config &side, level.child_range("side"))
{
//TODO clean up.
// state_.build_team(side, "", teams_, level, *this
// , units_, false);
teams_.push_back(team(side,*this,100));
foreach (const config &a_unit, side.child_range("unit")) {
map_location loc(a_unit, NULL);
units_.add(loc,
unit(a_unit, true, &state_) );
}
}
config dummy;
dummy["no_leader"] = "yes";
dummy["side"] = "1";
//// state_.build_team(dummy, "", teams_, level, *this
//// , units_, false);
teams_.push_back(team(dummy,*this,100));
}
} //end namespace editor

View file

@ -18,13 +18,6 @@
#include "editor_common.hpp"
#include "../map.hpp"
#include "../map_label.hpp"
#include "../map_area.hpp"
#include "../unit_map.hpp"
#include "tod_manager.hpp"
#include "soundsource.hpp"
#include "gamestatus.hpp"
#include <deque>
#include <set>
@ -82,29 +75,29 @@ public:
/**
* Empty map constructor
*/
explicit editor_map(const config& terrain_cfg, const config& level);
explicit editor_map(const config& terrain_cfg);
/**
* Create an editor map from a map data string
*/
editor_map(const config& terrain_cfg, const std::string& data, const config& level);
editor_map(const config& terrain_cfg, const std::string& data);
/**
* Wrapper around editor_map(cfg, data) that catches possible exceptions
* and wraps them in a editor_map_load_exception
*/
static editor_map from_string(const config& terrain_cfg, const std::string& data, const config& level);
static editor_map from_string(const config& terrain_cfg, const std::string& data);
/**
* Create an editor map with the given dimensions and filler terrain
*/
editor_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler, const config& level);
editor_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler);
/**
* Create an editor_map by upgrading an existing gamemap. The map data is
* copied. Marked "explicit" to avoid potentially harmful automatic conversions.
* copied. Marked "explicit" to avoid potentially harmful autmatic conversions.
*/
explicit editor_map(const gamemap& map, const config& level);
explicit editor_map(const gamemap& map);
/**
* editor_map destructor
@ -117,45 +110,12 @@ public:
void sanity_check();
/**
* Get a contiguous set of tiles having the same terrain as the starting location.
* Get a contigious set of tiles having the same terrain as the starting location.
* Useful for flood fill or magic wand selection
* @return a contiguous set of locations that will always contain at least the starting element
* @return a contigious set of locations that will always contain at least the starting element
*/
std::set<map_location> get_contigious_terrain_tiles(const map_location& start) const;
/**
* Unit map accessor
*/
unit_map& get_units() { return units_; };
const unit_map& get_const_units() const { return units_; };
//TODO
// unit_map& get_units() const { return units_; };
labels& get_game_labels() { return game_labels_; }
map_areas& get_named_areas() { return named_areas_; }
const map_areas& get_named_areas() const { return named_areas_; }
const labels& get_game_labels() const { return game_labels_; }
tod_manager& get_tod_manager() { return tod_manager_; }
const config& get_level() { return cfg_; }
//TODO
// soundsource::manager* get_sound_source_manager() { return soundsources_manager_; }
std::vector<team>& get_teams() { return teams_; }
const std::vector<team>& get_teams() const { return teams_; }
game_state& get_state() { return state_; }
const game_state& get_state() const { return state_; }
/**
* Set labels for staring positions in the given display object.
* @return the locations where the labels were added
@ -240,36 +200,6 @@ protected:
* The selected hexes
*/
std::set<map_location> selection_;
/**
* The unit_map that contains the unit objects of the map.
*/
unit_map units_;
/**
* The map labels from inside [map]
*
*/
labels game_labels_;
/**
* the named locations
*/
map_areas named_areas_;
tod_manager tod_manager_;
//TODO
// boost::scoped_ptr<soundsource::manager> soundsources_manager_;
std::vector<team> teams_;
config cfg_;
game_state state_;
private:
void setup(const config& level);
};

View file

@ -14,10 +14,7 @@
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "action.hpp"
#include "map_context.hpp"
#include "../serialization/parser.hpp"
#include "../serialization/preprocessor.hpp"
#include "../display.hpp"
#include "../filesystem.hpp"
@ -57,7 +54,7 @@ map_context::map_context(const config& game_config, const std::string& filename)
: filename_(filename)
, map_data_key_()
, embedded_(false)
, map_(game_config, config())
, map_(game_config)
, undo_stack_()
, redo_stack_()
, actions_since_save_(0)
@ -68,15 +65,6 @@ map_context::map_context(const config& game_config, const std::string& filename)
, changed_locations_()
, everything_changed_(false)
{
//TODO
std::cerr << "\n map_context constructor "<< this << "\n";
config level;
read(level, *(preprocess_file(filename_)));
// ERR_ED << level.debug();
log_scope2(log_editor, "Loading map " + filename);
if (!file_exists(filename) || is_directory(filename)) {
throw editor_map_load_exception(filename, _("File not found"));
@ -94,8 +82,8 @@ map_context::map_context(const config& game_config, const std::string& filename)
std::string new_filename = get_wml_location(m2[1], directory_name(m2[1]));
if (new_filename.empty()) {
std::string message = _("The map file looks like a scenario, "
"but the map_data value does not point to an existing file")
+ std::string("\n") + m2[1];
"but the map_data value does not point to an existing file")
+ std::string("\n") + m2[1];
throw editor_map_load_exception(filename, message);
}
LOG_ED << "New filename is: " << new_filename << "\n";
@ -111,12 +99,11 @@ map_context::map_context(const config& game_config, const std::string& filename)
std::string message = _("Empty map file");
throw editor_map_load_exception(filename, message);
}
map_ = editor_map::from_string(game_config, map_string, level); //throws on error
map_ = editor_map::from_string(game_config, map_string); //throws on error
}
map_context::~map_context()
{
std::cerr << "\n map context destructor : "<< this << "\n";
clear_stack(undo_stack_);
clear_stack(redo_stack_);
}
@ -203,38 +190,6 @@ void map_context::set_starting_position_labels(display& disp)
{
std::set<map_location> new_label_locs = map_.set_starting_position_labels(disp);
starting_position_label_locs_.insert(new_label_locs.begin(), new_label_locs.end());
const labels::team_label_map& labels = map_.get_game_labels().get_team_label_map();
for(labels::team_label_map::const_iterator i = labels.begin(); i != labels.end(); ++i)
{
for (labels::label_map::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
{
const label* old_label = disp.labels().get_label(j->second->location());
std::string new_text;
//TODO enable translation.
// new_text += *(_("Label:")) + " " + j->second->text();
new_text = "Label: ";
new_text += j->second->text();
if (old_label)
new_text += "\n" + old_label->text();
disp.labels().set_label((j->second)->location(), new_text, "", font::LABEL_COLOUR, true, true, false);
// j->second->scroll(xmove, ymove);
}
}
const unit_map& units = map_.get_units();
for(unit_map::const_unit_iterator it = units.begin(); it != units.end(); it++) {
const label* old_label = disp.labels().get_label(it->get_location());
std::string new_text;
// new_text += *(_("Label:")) + " " + j->second->text();
new_text = "<span size=\"larger\">id:</span>"; //<< j->second->text();
// new_text = "Id: "; //<< j->second->text();
new_text += it->id();
if (old_label)
new_text += "\n" + old_label->text();
disp.labels().set_label(it->get_location(), new_text, "", font::LABEL_COLOUR, true, true, false);
}
}
void map_context::reset_starting_position_labels(display& disp)
@ -244,92 +199,33 @@ void map_context::reset_starting_position_labels(display& disp)
set_needs_labels_reset(false);
}
void map_context::write_cfg(config& cfg)
{
cfg["map_data"] = map_.write();
// std::string data = map_.write();
// map_cfg["map_data"] = data;
config& label_event = cfg.add_child("event");
label_event["name"] = "prestart";
map_.get_game_labels().write(label_event);
map_.get_named_areas().write(cfg);
std::stringstream buf;
for(std::vector<team>::const_iterator t = map_.get_teams().begin(); t != map_.get_teams().end() -1; ++t) {
int side_num = t - map_.get_teams().begin() + 1;
config& side = cfg.add_child("side");
t->write(side);
side["no_leader"] = "yes";
buf.str(std::string());
buf << side_num;
side["side"] = buf.str();
//current visible units
for(unit_map::const_iterator i = map_.get_units().begin(); i != map_.get_units().end(); ++i) {
if(i->side() == side_num) {
config& u = side.add_child("unit");
i->get_location().write(u); // TODO: Needed?
i->write(u);
}
}
}
}
bool map_context::save_multiplayer(const std::string& id)
{
config scenario_cfg;
config& multiplayer = scenario_cfg.add_child("multiplayer");
multiplayer["id"] = id;
multiplayer["name"] = id;
write_cfg(multiplayer);
return save(scenario_cfg, get_user_data_dir() + "/data/add-ons/" + id + ".cfg" );
}
bool map_context::save()
{
config cfg;
write_cfg(cfg);
return save(cfg, get_filename());
}
bool map_context::save(config& map_cfg, const std::string& filename)
{
//TODO
// try {
// if (!is_embedded()) {
// write_file(get_filename(), data);
//
// } else {
// std::string map_string = read_file(get_filename());
// boost::regex re("(.*map_data\\s*=\\s*\")(.+?)(\".*)");
// boost::smatch m;
// if (boost::regex_search(map_string, m, re, boost::regex_constants::match_not_dot_null)) {
// std::stringstream ss;
// ss << m[1];
// ss << data;
// ss << m[3];
// write_file(get_filename(), ss.str());
// } else {
// throw editor_map_save_exception(_("Could not save into scenario"));
// }
// }
std::string data = map_.write();
try {
scoped_ostream map_file = ostream_file(filename);
write(*map_file, map_cfg);
if (!is_embedded()) {
write_file(get_filename(), data);
} else {
std::string map_string = read_file(get_filename());
boost::regex re("(.*map_data\\s*=\\s*\")(.+?)(\".*)");
boost::smatch m;
if (boost::regex_search(map_string, m, re, boost::regex_constants::match_not_dot_null)) {
std::stringstream ss;
ss << m[1];
ss << data;
ss << m[3];
write_file(get_filename(), ss.str());
} else {
throw editor_map_save_exception(_("Could not save into scenario"));
}
}
clear_modified();
} catch (io_exception& e) {
utils::string_map symbols;
symbols["msg"] = e.what();
const std::string msg = vgettext("Could not save the file: $msg", symbols);
const std::string msg = vgettext("Could not save the map: $msg", symbols);
throw editor_map_save_exception(msg);
}
clear_modified();
return true;
}
@ -375,7 +271,6 @@ void map_context::perform_partial_action(const editor_action& action)
undo_chain->prepend_action(undo);
clear_stack(redo_stack_);
}
bool map_context::modified() const
{
return actions_since_save_ != 0;

View file

@ -17,8 +17,6 @@
#include "editor_common.hpp"
#include "editor_map.hpp"
#include "../unit_map.hpp"
#include "../map_label.hpp"
#include <boost/utility.hpp>
@ -63,11 +61,6 @@ public:
*/
editor_map& get_map() { return map_; };
/**
* Unit map accesor
*/
unit_map& get_units() { return map_.get_units(); };
/**
* Map accesor - const version
*/
@ -135,8 +128,6 @@ public:
void set_starting_position_labels(display& disp);
// void set_map_labels(display& disp);
void reset_starting_position_labels(display& disp);
const std::string& get_filename() const { return filename_; }
@ -145,8 +136,6 @@ public:
const std::string& get_map_data_key() const { return map_data_key_; }
bool is_embedded() const { return embedded_; }
void set_embedded(bool v) { embedded_ = v; }
@ -157,14 +146,8 @@ public:
*/
bool save();
bool save(config& cfg, const std::string& filename);
bool save_multiplayer(const std::string& id = "test");
void set_map(const editor_map& map);
void write_cfg(config& cfg);
/**
* Performs an action (thus modyfying the map). An appropriate undo action is added to
* the undo stack. The redo stack is cleared. Note that this may throw, use caution
@ -234,8 +217,6 @@ protected:
*/
std::string map_data_key_;
/**
* Whether the map context refers to a map embedded in a scenario file.
* This distinction is important in order to avoid overwriting the scenario.
@ -247,8 +228,6 @@ protected:
*/
editor_map map_;
/**
* Container type used to store actions in the undo and redo stacks
*/

View file

@ -18,15 +18,10 @@
#include "editor_display.hpp"
#include "mouse_action.hpp"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "../construct_dialog.hpp"
#include "../gettext.hpp"
#include "map_label.hpp"
#include "gui/dialogs/unit_create.hpp"
//#include "resources.hpp"
namespace editor {
bool mouse_action::has_context_menu() const
@ -416,238 +411,6 @@ void mouse_action_fill::set_mouse_overlay(editor_display& disp)
set_terrain_mouse_overlay(disp, terrain_left_, terrain_right_);
}
editor_action* mouse_action_village::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
{
return NULL;
}
editor_action* mouse_action_village::click_left(editor_display& /*disp*/, int /*x*/, int /*y*/)
{
return NULL;
}
editor_action* mouse_action_village::up_left(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
return new editor_action_village(hex, disp.playing_team());
}
editor_action* mouse_action_village::up_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
return new editor_action_village_delete(hex);
}
editor_action* mouse_action_unit::click_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
const unit_map& units = disp.map().get_const_units();
last_hex_ = hex;
const unit_map::const_unit_iterator unit_it = units.find(hex);
if (unit_it != units.end()) {
// surface image = unit_it->second.still_image();
// Uint8 alpha = 196;
// int size = image->w;
// int zoom = static_cast<int>(size * disp.get_zoom_factor());
// // Add the alpha factor and scale the image
// image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
// disp.set_mouseover_hex_overlay(image);
temp_unit_ = &*unit_it;
//TODO set the mouse pointer to a draging one.
} else { temp_unit_ = NULL; }
click_ = true;
return NULL;
}
editor_action* mouse_action_unit::drag_right(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo)
{
map_location hex = disp.hex_clicked_on(x, y);
if (last_hex_ != hex) {
last_hex_ = hex;
if (temp_unit_) {
for (map_location::DIRECTION direction = map_location::NORTH;
direction <= map_location::NORTH_WEST;
direction = map_location::DIRECTION(direction +1)){
if (temp_unit_->get_location().get_direction(direction, 1) == hex) {
unit& u = *disp.map().get_units().find(temp_unit_->get_location());
u.set_facing(direction);
u.set_standing();
}
}
}
}
return NULL;
}
editor_action* mouse_action_unit::up_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
return new editor_action_unit_delete(hex);
}
editor_action* mouse_action_unit::click_left(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
const unit_map& units = disp.map().get_const_units();
const unit_map::const_unit_iterator unit_it = units.find(hex);
if (unit_it != units.end()) {
surface image = unit_it->still_image();
Uint8 alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
temp_unit_ = &*unit_it;
//TODO set the mouse pointer to a draging one.
} else { temp_unit_ = NULL; }
click_ = true;
return NULL;
}
editor_action* mouse_action_map_label::click_left(editor_display& disp, int x, int y)
{
click_ = true;
map_location hex = disp.hex_clicked_on(x, y);
clicked_on_ = hex;
last_draged_ = hex;
return NULL;
}
editor_action* mouse_action_map_label::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
{
return NULL;
}
editor_action* mouse_action_map_label::up_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
return new editor_action_label_delete(hex);
}
editor_action* mouse_action_map_label::drag_left(editor_display& disp, int x, int y
, bool& partial, editor_action* last_undo)
{
map_location hex = disp.hex_clicked_on(x, y);
if (hex == last_draged_)
return NULL;
//TODO this is somewhat hacky.
disp.labels().clear_all();
//TODO How can they be redrawn?
last_draged_ = hex;
const label* clicked_label = disp.map().get_game_labels().get_label(clicked_on_);
if (clicked_label) {
std::string text = clicked_label->text() + "\n";
const label* hex_label = disp.labels().get_label(hex);
//TODO the stacking is not working because we don't redraw all the labels.
if (hex_label)
text += hex_label->text();
terrain_label* onscreen = new terrain_label(text, "", hex, disp.labels(),
font::LABEL_COLOUR, true, true, false);
disp.labels().add_label(hex, onscreen);
}
return NULL;
}
editor_action* mouse_action_map_label::drag_end(editor_display& disp, int x, int y)
{
//don't bring up the new label box.
click_ = false;
map_location hex = disp.hex_clicked_on(x, y);
editor_action_chain* chain = NULL;
if (clicked_on_.valid()) {
// This is not a onscreen label but belongs to the editor_map.
const label& label_clicked = *(disp.map().get_game_labels().get_label(clicked_on_));
chain = new editor_action_chain();
chain->append_action(new editor_action_label(hex, label_clicked.text(), label_clicked.team_name()));
chain->append_action(new editor_action_label_delete(clicked_on_));
}
return chain;
}
editor_action* mouse_action_map_label::up_left(editor_display& disp, int x, int y)
{
if (!click_) return NULL;
click_ = false;
map_location hex = disp.hex_clicked_on(x, y);
if (!disp.map().on_board(hex)) {
return NULL;
}
const label* old_label = disp.map().get_game_labels().get_label(hex);
bool visible_in_fog = true;
bool visible_in_shroud = true;
//TODO gui2
gui::dialog d(disp, _("Place Label"), "", gui::OK_CANCEL);
d.set_textbox(_("Label: "), (old_label ? old_label->text() : ""), map_labels::get_max_chars());
//TODO note that gui1 does not support more than one textbox in a dialogue.
// d.set_textbox(_("Team: "), (old_label ? old_label->team_name() : ""), map_labels::get_max_chars());
d.add_option(_("Visible in Fog"), visible_in_fog, gui::dialog::BUTTON_CHECKBOX_LEFT);
d.add_option(_("Visible in Shroud"), visible_in_shroud, gui::dialog::BUTTON_CHECKBOX_LEFT);
//color can be adjusted as well
// d.add_option(_("Team only"), team_only, gui::dialog::BUTTON_CHECKBOX_LEFT);
//TODO
const std::string team_name = "";
editor_action* a = NULL;
if(!d.show()) {
a = new editor_action_label(hex, d.textbox_text(), team_name);
update_brush_highlights(disp, hex);
}
return a;
}
void mouse_action_map_label::set_mouse_overlay(editor_display& disp)
{
surface image = image::get_image("editor/tool-overlay-starting-position.png");
Uint8 alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}
void mouse_action_village::set_mouse_overlay(editor_display& disp)
{
surface image = image::get_image("editor/tool-overlay-village.png");
Uint8 alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}
void mouse_action_unit::set_mouse_overlay(editor_display& disp)
{
//TODO change to a new image.
surface image = image::get_image("editor/tool-overlay-starting-position.png");
Uint8 alpha = 196;
int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}
editor_action* mouse_action_starting_position::up_left(editor_display& disp, int x, int y)
@ -682,93 +445,6 @@ editor_action* mouse_action_starting_position::up_left(editor_display& disp, int
return a;
}
editor_action* mouse_action_unit::drag_end(editor_display& disp, int x, int y) {
if (!click_) return NULL;
click_ = false;
editor_action* a = NULL;
if(temp_unit_) {
map_location hex = disp.hex_clicked_on(x, y);
if (!disp.map().on_board(hex))
return NULL;
unit u = *temp_unit_;
a = new editor_action_unit_replace(u.get_location(), hex);
}
// ERR_ED << "\n Drag end at " << hex.x << "/" << hex.y;
return a;
}
editor_action* mouse_action_unit::up_left(editor_display& disp, int x, int y)
{
if (!click_) return NULL;
click_ = false;
map_location hex = disp.hex_clicked_on(x, y);
if (!disp.map().on_board(hex)) {
return NULL;
}
if (temp_unit_) {
config u;
temp_unit_->write(u);
// TODO: see the comments below
//vconfig cfg;
//gui2::tconfig_inspector inspect_dialog(cfg, u);
//inspect_dialog.show(disp.video());
}
//TODO the gui1 dialog works better.
//
// The unit creation dialog makes sure unit types
// are properly cached.
//
gui2::tunit_create create_dlg;
create_dlg.show(disp.video());
if(create_dlg.no_choice()) {
return NULL;
}
const std::string& ut_id = create_dlg.choice();
const unit_type *utp = unit_types.find(ut_id);
if (!utp) {
ERR_ED << "create unit dialog returned inexistent or unusable unit_type id '" << ut_id << "'\n";
return NULL;
}
const unit_type &ut = *utp;
unit_race::GENDER gender = create_dlg.gender();
//TODO
// const bool generate_name = create_dlg.generate_name();
// Do not try to set bad genders, may mess up l10n
// FIXME: is this actually necessary?
if(ut.genders().end() == std::find(ut.genders().begin(), ut.genders().end(), gender)) {
gender = ut.genders().front();
}
bool canrecruit = disp.map().get_teams()[disp.get_playing_team() ].no_leader();
if (canrecruit) disp.map().get_teams()[disp.get_playing_team() ].have_leader(true);
// FIXME: This may NOT work as intended, as the unit_map to add the unit to cannot be specified.
// Blame silene for removing that argument from unit's constructors
//unit u(&disp.map().get_units(), utp, disp.get_playing_team() +1, false, gender, canrecruit);
unit u(utp, disp.get_playing_team() +1, false, gender, canrecruit);
editor_action* a = new editor_action_unit(hex, u);
return a;
}
editor_action* mouse_action_starting_position::click_left(editor_display& /*disp*/, int /*x*/, int /*y*/)
{
click_ = true;
@ -777,24 +453,13 @@ editor_action* mouse_action_starting_position::click_left(editor_display& /*disp
editor_action* mouse_action_starting_position::up_right(editor_display& disp, int x, int y)
{
//TODO
// map_location hex = disp.hex_clicked_on(x, y);
// int player_starting_at_hex = disp.map().is_starting_position(hex) + 1;
// if (player_starting_at_hex != -1) {
// config side;
//// disp.get_teams()[player_starting_at_hex].write(side);
// disp.get_teams()[1].write(side);
// //const config const_side = side;
// vconfig vside(side, true);
// ERR_ED << vside.get_config().debug();
// gui2::tgamestate_inspector inspect_dialog(vside);
// inspect_dialog.show(disp.video());
//// inspect_dialog.show(resources::screen->video());
// return NULL;
// //return new editor_action_side_config(map_location(), player_starting_at_hex);
// } else {
map_location hex = disp.hex_clicked_on(x, y);
int player_starting_at_hex = disp.map().is_starting_position(hex) + 1;
if (player_starting_at_hex != -1) {
return new editor_action_starting_position(map_location(), player_starting_at_hex);
} else {
return NULL;
// }
}
}
editor_action* mouse_action_starting_position::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)

View file

@ -30,7 +30,7 @@ namespace editor {
* an appropriate editor_action object. Mouse actions may store some temporary data
* such as the last clicked hex for better handling of click-drag. They should *not* modify
* the map or trigger refreshes, but may set brush locations and similar overlays that
* should be visible around the mouse cursor, hence the display references are no constants.
* should be visible around the mouse cursor, hence the display references are not const.
*/
class mouse_action
{
@ -47,7 +47,7 @@ public:
virtual bool has_context_menu() const;
/**
* Mouse move (not a drag). Never changes anything (other than temporary highlights and similar)
* Mouse move (not a drag). Never changes anything (other than temporary highlihts and similar)
*/
void move(editor_display& disp, const map_location& hex);
@ -57,7 +57,7 @@ public:
void update_brush_highlights(editor_display& disp, const map_location& hex);
/**
* Locations that would be affected by a click, used by move to update highlights. Defaults to highlight the mouseover hex.
* Locations that would be affected by a click, used by move to update highlights. Defauts to higlight the mouseover hex.
* Maybe also used for actually performing the action in click() or drag().
*/
virtual std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
@ -246,15 +246,15 @@ public:
*/
editor_action* click_left(editor_display& disp, int x, int y);
/**
* Handle terrain sampling before calling generic handler
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Create an appropriate editor_action and return it
*/
editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes);
/**
* Handle terrain sampling before calling generic handler
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Create an appropriate editor_action and return it
@ -279,16 +279,6 @@ public:
{
}
/**
* Left click/drag selects
*/
editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes);
/**
* Right click/drag deselects
*/
editor_action* click_perform_right(editor_display& disp, const std::set<map_location>& hexes);
/**
* Overriden to allow special behaviour based on modifier keys
*/
@ -299,6 +289,16 @@ public:
*/
editor_action* key_event(editor_display& disp, const SDL_Event& e);
/**
* Left click/drag selects
*/
editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes);
/**
* Right click/drag deselects
*/
editor_action* click_perform_right(editor_display& disp, const std::set<map_location>& hexes);
virtual void set_mouse_overlay(editor_display& disp);
};
@ -313,6 +313,13 @@ public:
{
}
bool has_context_menu() const;
/**
* Show an outline of where the paste will go
*/
std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
/**
* Return a paste with offset action
*/
@ -323,15 +330,8 @@ public:
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Show an outline of where the paste will go
*/
std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
virtual void set_mouse_overlay(editor_display& disp);
bool has_context_menu() const;
protected:
/**
* Reference to the buffer used for pasting (e.g. the clipboard)
@ -353,6 +353,11 @@ public:
{
}
/**
* Tiles that will be painted to, possibly use modifier keys here
*/
std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
/**
* Left / right click fills with the respective terrain
*/
@ -363,11 +368,6 @@ public:
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Tiles that will be painted to, possibly use modifier keys here
*/
std::set<map_location> affected_hexes(editor_display& disp, const map_location& hex);
virtual void set_mouse_overlay(editor_display& disp);
protected:
@ -386,8 +386,6 @@ public:
{
}
editor_action* click_left(editor_display& disp, int x, int y);
/**
* Left click displays a player-number-selector dialog and then creates an action
* or returns NULL if cancel was pressed or there would be no change.
@ -395,185 +393,22 @@ public:
*/
editor_action* up_left(editor_display& disp, int x, int y);
editor_action* click_right(editor_display& disp, int x, int y);
editor_action* click_left(editor_display& disp, int x, int y);
/**
* Right click only erases the starting position if there is one.
* Do this on mouse up to avoid drag issue,
*/
editor_action* up_right(editor_display& disp, int x, int y);
editor_action* click_right(editor_display& disp, int x, int y);
virtual void set_mouse_overlay(editor_display& disp);
private:
bool click_;
};
/**
* TODO
*/
class mouse_action_unit : public mouse_action
{
public:
mouse_action_unit(const CKey& key)
: mouse_action(key), click_(false), temp_unit_(), last_hex_()
{
}
/**
* TODO
*/
editor_action* click_left(editor_display& disp, int x, int y);
/**
* TODO
*/
editor_action* up_left(editor_display& disp, int x, int y);
/**
* TODO
*/
editor_action* click_right(editor_display& disp, int x, int y);
editor_action* drag_right(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
/**
* Right click only erases the starting position if there is one.
* Do this on mouse up to avoid drag issue,
*/
editor_action* up_right(editor_display& disp, int x, int y);
/**
* TODO
*/
editor_action* drag_end(editor_display& disp, int x, int y);
virtual void set_mouse_overlay(editor_display& disp);
private:
bool click_;
const unit* temp_unit_;
map_location last_hex_;
};
/**
* TODO
*/
class mouse_action_path : public mouse_action
{
public:
mouse_action_path(const CKey& key)
: mouse_action(key)
{
}
/**
* TODO
*/
editor_action* click_left(editor_display& disp, int x, int y) { return NULL; };
/**
* TODO
*/
editor_action* up_left(editor_display& disp, int x, int y) { return NULL; };
/**
* TODO
*/
editor_action* click_right(editor_display& disp, int x, int y) { return NULL; };
/**
* Right click only erases the starting position if there is one.
* Do this on mouse up to avoid drag issue,
*/
editor_action* up_right(editor_display& disp, int x, int y) { return NULL; };
virtual void set_mouse_overlay(editor_display& disp) {};
};
/**
* TODO
*/
class mouse_action_village : public mouse_action
{
public:
mouse_action_village(const CKey& key)
: mouse_action(key)
{
}
/**
* TODO
*/
editor_action* click_left(editor_display& disp, int x, int y);
/**
* TODO
*/
editor_action* up_left(editor_display& disp, int x, int y);
/**
* TODO
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Right click only erases the starting position if there is one.
* Do this on mouse up to avoid drag issue,
*/
editor_action* up_right(editor_display& disp, int x, int y);
virtual void set_mouse_overlay(editor_display& disp);
};
/**
* Set map label action.
*/
class mouse_action_map_label : public mouse_action
{
public:
mouse_action_map_label(const CKey& key)
: mouse_action(key), click_(false), clicked_on_(), last_draged_()
{
}
editor_action* click_left(editor_display& disp, int x, int y);
/**
* Left click displays a dialog that is used for entering the label string.
*/
editor_action* up_left(editor_display& disp, int x, int y);
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Right click erases the label under the mouse.
*/
editor_action* up_right(editor_display& disp, int x, int y);
/**
* Drag operation. A click should have occured earlier. Defaults to no action.
*/
editor_action* drag_left(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
/**
* TODO
*/
editor_action* drag_end(editor_display& disp, int x, int y);
virtual void set_mouse_overlay(editor_display& disp);
private:
bool click_;
map_location clicked_on_;
map_location last_draged_;
};
} //end namespace editor

View file

@ -254,7 +254,7 @@ private:
}
void display_float(const map_location& location, const std::string& text) const{
// game_display::get_singleton()->float_label(location,text,255,0,0);
game_display::get_singleton()->float_label(location,text,255,0,0);
}
};

View file

@ -53,17 +53,17 @@ static lg::log_domain log_engine("engine");
std::map<map_location,fixed_t> game_display::debugHighlights_;
game_display::game_display(unit_map* units, CVideo& video, gamemap* map,
tod_manager* tod, std::vector<team>* t,
game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
const tod_manager& tod, const std::vector<team>& t,
const config& theme_cfg, const config& level) :
display(video, map, theme_cfg, level),
display(video, &map, theme_cfg, level),
units_(units),
tod_manager_(tod),
temp_unit_(NULL),
attack_indicator_src_(),
attack_indicator_dst_(),
energy_bar_rects_(),
route_(),
tod_manager_(tod),
teams_(t),
level_(level),
invalidateUnit_(true),
@ -86,69 +86,16 @@ game_display::game_display(unit_map* units, CVideo& video, gamemap* map,
{
singleton_ = this;
load_flags();
clear_screen();
// flags_.reserve(teams_->size());
//
// std::vector<std::string> side_colors;
// side_colors.reserve(teams_->size());
//
// for(size_t i = 0; i != teams_->size(); ++i) {
// std::string side_color = team::get_side_colour_index(i+1);
// side_colors.push_back(side_color);
// std::string flag = (*teams_)[i].flag();
// std::string old_rgb = game_config::flag_rgb;
// std::string new_rgb = side_color;
//
// if(flag.empty()) {
// flag = game_config::flag_image;
// }
//
// LOG_DP << "Adding flag for team " << i << " from animation " << flag << "\n";
//
// // Must recolor flag image
// animated<image::locator> temp_anim;
//
// std::vector<std::string> items = utils::split(flag);
// std::vector<std::string>::const_iterator itor = items.begin();
// for(; itor != items.end(); ++itor) {
// const std::vector<std::string>& items = utils::split(*itor, ':');
// std::string str;
// int time;
//
// if(items.size() > 1) {
// str = items.front();
// time = atoi(items.back().c_str());
// } else {
// str = *itor;
// time = 100;
// }
// std::stringstream temp;
// temp << str << "~RC(" << old_rgb << ">"<< new_rgb << ")";
// image::locator flag_image(temp.str());
// temp_anim.add_frame(time, flag_image);
// }
// flags_.push_back(temp_anim);
//
// flags_.back().start_animation(rand()%flags_.back().get_end_time(), true);
// }
// image::set_team_colors(&side_colors);
// clear_screen();
}
void game_display::load_flags() {
// Inits the flag list and the team colors used by ~TC
flags_.clear();
flags_.reserve(teams_->size());
flags_.reserve(teams_.size());
std::vector<std::string> side_colors;
side_colors.reserve(teams_->size());
side_colors.reserve(teams_.size());
for(size_t i = 0; i != teams_->size(); ++i) {
for(size_t i = 0; i != teams_.size(); ++i) {
std::string side_color = team::get_side_colour_index(i+1);
side_colors.push_back(side_color);
std::string flag = (*teams_)[i].flag();
std::string flag = teams_[i].flag();
std::string old_rgb = game_config::flag_rgb;
std::string new_rgb = side_color;
@ -185,9 +132,9 @@ void game_display::load_flags() {
flags_.back().start_animation(rand()%flags_.back().get_end_time(), true);
}
image::set_team_colors(&side_colors);
clear_screen();
}
game_display* game_display::create_dummy_display(CVideo& video)
{
static unit_map dummy_umap;
@ -195,8 +142,8 @@ game_display* game_display::create_dummy_display(CVideo& video)
static gamemap dummy_map(dummy_cfg, "");
static tod_manager dummy_tod(dummy_cfg, 0);
static std::vector<team> dummy_teams;
return new game_display(&dummy_umap, video, &dummy_map, &dummy_tod,
&dummy_teams, dummy_cfg, dummy_cfg);
return new game_display(dummy_umap, video, dummy_map, dummy_tod,
dummy_teams, dummy_cfg, dummy_cfg);
}
game_display::~game_display()
@ -208,10 +155,10 @@ game_display::~game_display()
void game_display::new_turn()
{
const time_of_day& tod = tod_manager_->get_time_of_day();
const time_of_day& tod = tod_manager_.get_time_of_day();
if( !first_turn_) {
const time_of_day& old_tod = tod_manager_->get_previous_time_of_day();
const time_of_day& old_tod = tod_manager_.get_previous_time_of_day();
if(old_tod.image_mask != tod.image_mask) {
const surface old_mask(image::get_image(old_tod.image_mask,image::UNMASKED));
@ -257,7 +204,7 @@ void game_display::new_turn()
void game_display::adjust_colours(int r, int g, int b)
{
const time_of_day& tod = tod_manager_->get_time_of_day();
const time_of_day& tod = tod_manager_.get_time_of_day();
image::set_colour_adjustment(tod.red+r,tod.green+g,tod.blue+b);
}
@ -273,15 +220,15 @@ void game_display::select_hex(map_location hex)
void game_display::highlight_hex(map_location hex)
{
const unit *u = get_visible_unit(*units_, hex, (*teams_)[viewing_team()], !viewpoint_);
const unit *u = get_visible_unit(units_, hex, teams_[viewing_team()], !viewpoint_);
if (u) {
displayedUnitHex_ = hex;
invalidate_unit();
} else {
u = get_visible_unit(*units_, mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_);
u = get_visible_unit(units_, mouseoverHex_, teams_[viewing_team()], !viewpoint_);
if (u) {
// mouse moved from unit hex to non-unit hex
if (units_->count(selectedHex_)) {
if (units_.count(selectedHex_)) {
displayedUnitHex_ = selectedHex_;
invalidate_unit();
}
@ -295,7 +242,7 @@ void game_display::highlight_hex(map_location hex)
void game_display::display_unit_hex(map_location hex)
{
const unit *u = get_visible_unit(*units_, hex, (*teams_)[viewing_team()], !viewpoint_);
const unit *u = get_visible_unit(units_, hex, teams_[viewing_team()], !viewpoint_);
if (u) {
displayedUnitHex_ = hex;
invalidate_unit();
@ -314,8 +261,7 @@ void game_display::scroll_to_leader(unit_map& units, int side, SCROLL_TYPE scrol
{
unit_map::const_iterator leader = units.find_leader(side);
if(leader != units_->end()) {
//TODO remove someday.
if(leader != units_.end()) {
// YogiHH: I can't see why we need another key_handler here,
// therefore I will comment it out :
/*
@ -338,7 +284,7 @@ std::vector<map_location> game_display::get_invalidated_unit_locations() {
std::vector<map_location> unit_locations;
foreach (const map_location& loc, invalidated_) {
if ((temp_unit_ && temp_unit_->get_location() == loc) ||
units_->find(loc) != units_->end())
units_.find(loc) != units_.end())
{
unit_locations.push_back(loc);
}
@ -354,7 +300,7 @@ image::TYPE game_display::get_image_type(const map_location& loc) {
if (loc == mouseoverHex_ || loc == attack_indicator_src_) {
return image::BRIGHTENED;
} else if (loc == selectedHex_) {
const unit *un = get_visible_unit(*units_, loc, (*teams_)[currentTeam_], !viewpoint_);
const unit *un = get_visible_unit(units_, loc, teams_[currentTeam_], !viewpoint_);
if (un && !un->get_hidden()) {
return image::BRIGHTENED;
}
@ -395,7 +341,7 @@ void game_display::draw_hex(const map_location& loc)
std::pair<Itor,Itor> overlays = overlays_.equal_range(loc);
for( ; overlays.first != overlays.second; ++overlays.first) {
if ((overlays.first->second.team_name == "" ||
overlays.first->second.team_name.find((*teams_)[playing_team()].team_name()) != std::string::npos)
overlays.first->second.team_name.find(teams_[playing_team()].team_name()) != std::string::npos)
&& !(is_fogged && !overlays.first->second.visible_in_fog))
{
drawing_buffer_add(LAYER_TERRAIN_BG, loc, tblit(xpos, ypos,
@ -408,7 +354,7 @@ void game_display::draw_hex(const map_location& loc)
// Draw the time-of-day mask on top of the terrain in the hex.
// tod may differ from tod if hex is illuminated.
const std::string& tod_hex_mask = tod_manager_->get_time_of_day(0, loc).image_mask;
const std::string& tod_hex_mask = tod_manager_.get_time_of_day(0, loc).image_mask;
if(tod_hex_mask1 != NULL || tod_hex_mask2 != NULL) {
drawing_buffer_add(LAYER_TERRAIN_FG, loc, tblit(xpos, ypos, tod_hex_mask1));
drawing_buffer_add(LAYER_TERRAIN_FG, loc, tblit(xpos, ypos, tod_hex_mask2));
@ -462,7 +408,7 @@ void game_display::draw_hex(const map_location& loc)
void game_display::update_time_of_day()
{
tod_ = tod_manager_->get_time_of_day();
tod_ = tod_manager_.get_time_of_day();
}
void game_display::redraw_units(const std::vector<map_location>& invalidated_unit_locations)
@ -470,8 +416,8 @@ void game_display::redraw_units(const std::vector<map_location>& invalidated_uni
// Units can overlap multiple hexes, so we need
// to redraw them last and in the good sequence.
foreach (map_location loc, invalidated_unit_locations) {
unit_map::iterator u_it = units_->find(loc);
if (u_it != units_->end()) {
unit_map::iterator u_it = units_.find(loc);
if (u_it != units_.end()) {
u_it->redraw_unit();
//simulate_delay += 1;
}
@ -489,7 +435,7 @@ void game_display::draw_report(reports::TYPE report_num)
}
reports::report report = reports::generate_report(report_num, report_,
(*teams_)[viewing_team()],
teams_[viewing_team()],
size_t(currentTeam_+1),size_t(activeTeam_+1),
selectedHex_, mouseoverHex_, displayedUnitHex_,
observers_, level_, !viewpoint_);
@ -499,7 +445,7 @@ void game_display::draw_report(reports::TYPE report_num)
void game_display::draw_game_status()
{
if(teams_->empty()) {
if(teams_.empty()) {
return;
}
@ -513,7 +459,7 @@ void game_display::draw_sidebar()
draw_report(reports::REPORT_CLOCK);
draw_report(reports::REPORT_COUNTDOWN);
if(teams_->empty()) {
if(teams_.empty()) {
return;
}
@ -538,14 +484,10 @@ void game_display::draw_minimap_units()
double xscaling = 1.0 * minimap_location_.w / get_map().w();
double yscaling = 1.0 * minimap_location_.h / get_map().h();
for(unit_map::const_iterator u = units_->begin(); u != units_->end(); ++u) {
//TODO remove debug code.
config debug;
u->write(debug);
ERR_DP << "\n" << debug.debug() << "\n";
for(unit_map::const_iterator u = units_.begin(); u != units_.end(); ++u) {
if (fogged(u->get_location()) ||
((*teams_)[currentTeam_].is_enemy(u->side()) &&
u->invisible(u->get_location(), *units_, *teams_))) {
(teams_[currentTeam_].is_enemy(u->side()) &&
u->invisible(u->get_location(), units_,teams_))) {
continue;
}
@ -609,7 +551,6 @@ void game_display::draw_bar(const std::string& image, int xpos, int ypos,
height = bar_loc.h;
}
//TODO comment or remove the cruft.
//if(alpha != ftofxp(1.0)) {
// surf.assign(adjust_surface_alpha(surf,alpha));
// if(surf == NULL) {
@ -653,8 +594,8 @@ void game_display::draw_movement_info(const map_location& loc)
// Don't use empty route or the first step (the unit will be there)
if(w != route_.marks.end()
&& !route_.steps.empty() && route_.steps.front() != loc) {
const unit_map::const_iterator un = units_->find(route_.steps.front());
if(un != units_->end()) {
const unit_map::const_iterator un = units_.find(route_.steps.front());
if(un != units_.end()) {
// Display the def% of this terrain
int def = 100 - un->defense_modifier(get_map().get_terrain(loc));
std::stringstream def_text;
@ -727,8 +668,8 @@ std::vector<surface> game_display::footsteps_images(const map_location& loc)
// Check which footsteps images of game_config we will use
int move_cost = 1;
const unit_map::const_iterator u = units_->find(route_.steps.front());
if(u != units_->end()) {
const unit_map::const_iterator u = units_.find(route_.steps.front());
if(u != units_.end()) {
move_cost = u->movement_cost(get_map().get_terrain(loc));
}
int image_number = std::min<int>(move_cost, game_config::foot_speed_prefix.size());
@ -786,9 +727,9 @@ surface game_display::get_flag(const map_location& loc)
return surface(NULL);
}
for(size_t i = 0; i != teams_->size(); ++i) {
if((*teams_)[i].owns_village(loc) &&
(!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(i+1)))
for(size_t i = 0; i != teams_.size(); ++i) {
if(teams_[i].owns_village(loc) &&
(!fogged(loc) || !teams_[currentTeam_].is_enemy(i+1)))
{
flags_[i].update_last_draw_time();
const image::locator& image_flag = preferences::animate_map() ?
@ -944,7 +885,7 @@ void game_display::invalidate_animations_location(const map_location& loc) {
if (get_map().is_village(loc)) {
const int owner = player_teams::village_owner(loc);
if (owner >= 0 && flags_[owner].need_update()
&& (!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(owner+1))) {
&& (!fogged(loc) || !teams_[currentTeam_].is_enemy(owner+1))) {
invalidate(loc);
}
}
@ -955,14 +896,14 @@ void game_display::invalidate_animations()
new_animation_frame();
display::invalidate_animations();
unit_map::iterator unit;
for(unit=units_->begin() ; unit != units_->end() ; ++unit)
for(unit=units_.begin() ; unit != units_.end() ; ++unit)
unit->refresh();
if (temp_unit_ )
temp_unit_->refresh();
bool new_inval = true;
while(new_inval) {
new_inval = false;
for(unit=units_->begin() ; unit != units_->end() ; ++unit) {
for(unit=units_.begin() ; unit != units_.end() ; ++unit) {
new_inval |= unit->invalidate(unit->get_location());
}
if (temp_unit_ ) {
@ -1068,8 +1009,8 @@ void game_display::write_overlays(config& cfg) const
void game_display::parse_team_overlays()
{
const team& curr_team = (*teams_)[playing_team()];
const team& prev_team = (*teams_)[playing_team()-1 < teams_->size() ? playing_team()-1 : teams_->size()-1];
const team& curr_team = teams_[playing_team()];
const team& prev_team = teams_[playing_team()-1 < teams_.size() ? playing_team()-1 : teams_.size()-1];
foreach (const game_display::overlay_map::value_type i, overlays_) {
const overlay& ov = i.second;
if (!ov.team_name.empty() &&
@ -1085,7 +1026,7 @@ std::string game_display::current_team_name() const
{
if (team_valid())
{
return (*teams_)[currentTeam_].team_name();
return teams_[currentTeam_].team_name();
}
return std::string();
}
@ -1286,12 +1227,12 @@ void game_display::send_notification(const std::string& /*owner*/, const std::st
void game_display::set_team(size_t teamindex, bool show_everything)
{
assert(teamindex < teams_->size());
assert(teamindex < teams_.size());
currentTeam_ = teamindex;
if (!show_everything)
{
labels().set_team(&(*teams_)[teamindex]);
viewpoint_ = &(*teams_)[teamindex];
labels().set_team(&teams_[teamindex]);
viewpoint_ = &teams_[teamindex];
}
else
{
@ -1303,7 +1244,7 @@ void game_display::set_team(size_t teamindex, bool show_everything)
void game_display::set_playing_team(size_t teamindex)
{
assert(teamindex < teams_->size());
assert(teamindex < teams_.size());
activeTeam_ = teamindex;
invalidate_game_status();
}

View file

@ -42,16 +42,13 @@ class unit_map;
class game_display : public display
{
public:
game_display(unit_map* units, CVideo& video,
gamemap* map, tod_manager* tod_manager,
std::vector<team>* t, const config& theme_cfg,
game_display(unit_map& units, CVideo& video,
const gamemap& map, const tod_manager& tod_manager,
const std::vector<team>& t, const config& theme_cfg,
const config& level);
static game_display* create_dummy_display(CVideo& video);
//TODO sort in
void load_flags();
~game_display();
static game_display* get_singleton() { return singleton_ ;}
@ -243,10 +240,10 @@ public:
void set_team(size_t team, bool observe=false);
void set_playing_team(size_t team);
size_t get_playing_team() const {return activeTeam_;}
const std::vector<team>& get_teams() {return *teams_;}
const std::vector<team>& get_teams() {return teams_;}
virtual unit_map& get_units() {return *units_;}
virtual const unit_map& get_const_units() const {return *units_;}
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.
@ -263,7 +260,7 @@ public:
/** The playing team is the team whose turn it is. */
size_t playing_team() const { return activeTeam_; }
bool team_valid() const { return currentTeam_ < teams_->size(); }
bool team_valid() const { return currentTeam_ < teams_.size(); }
std::string current_team_name() const;
void add_observer(const std::string& name) { observers_.insert(name); }
@ -307,11 +304,8 @@ private:
// This surface must be freed by the caller
surface get_flag(const map_location& loc);
protected:
unit_map* units_;
tod_manager* tod_manager_;
unit_map& units_;
private:
unit *temp_unit_;
// Locations of the attack direction indicator's parts
@ -328,11 +322,10 @@ private:
pathfind::marked_route route_;
const tod_manager& tod_manager_;
protected:
std::vector<team>* teams_;
const std::vector<team>& teams_;
private:
const config& level_;
void invalidate_route();

View file

@ -35,7 +35,6 @@
#include "map.hpp"
#include "map_label.hpp"
#include "map_exception.hpp"
#include "pathfind/teleport.hpp"
#include "replay.hpp"
#include "resources.hpp"
#include "scripting/lua.hpp"
@ -621,30 +620,6 @@ WML_HANDLER_FUNCTION(place_shroud, /*event_info*/,cfg)
toggle_shroud(false,cfg );
}
WML_HANDLER_FUNCTION(tunnel, /*event_info*/, cfg)
{
const bool remove = utils::string_bool(cfg["remove"], false);
if (remove) {
const std::vector<std::string> ids = utils::split(cfg["id"]);
foreach(const std::string &id, ids) {
resources::tunnels->remove(id);
}
} else if (cfg.get_children("source").empty() ||
cfg.get_children("target").empty() ||
cfg.get_children("filter").empty()) {
ERR_WML << "[tunnel] is missing a mandatory tag:\n"
<< cfg.get_config().debug();
} else {
pathfind::teleport_group tunnel(cfg, false);
resources::tunnels->add(tunnel);
if (utils::string_bool(cfg["bidirectional"], true)) {
tunnel = pathfind::teleport_group(cfg, true);
resources::tunnels->add(tunnel);
}
}
}
WML_HANDLER_FUNCTION(teleport, event_info, cfg)
{
unit_map::iterator u = resources::units->find(event_info.loc1);

View file

@ -581,11 +581,21 @@ int xp_modifier()
return settings::get_xp_modifier(preferences::get("mp_xp_modifier"));
}
int stat_modifier()
{
return settings::get_stat_modifier(preferences::get("mp_stat_modifier"));
}
void set_xp_modifier(int value)
{
preferences::set("mp_xp_modifier", lexical_cast<std::string>(value));
}
void set_stat_modifier(int value)
{
preferences::set("mp_stat_modifier", lexical_cast<std::string>(value));
}
int era()
{
return lexical_cast_default<int>(preferences::get("mp_era"), 0);

View file

@ -142,6 +142,9 @@ namespace preferences {
int xp_modifier();
void set_xp_modifier(int value);
int stat_modifier();
void set_stat_modifier(int value);
int era();
void set_era(int value);

View file

@ -19,479 +19,3 @@
* markup and what kind of markup. These fixes will be post 1.6.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/icon_message.hpp"
//#include "gettext.hpp"
#include "font.hpp"
#include "unit.hpp"
#include "foreach.hpp"
#include "resources.hpp"
#include "game_display.hpp"
#include "map.hpp"
#include "help.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/settings.hpp"
#include <boost/bind.hpp>
namespace gui2 {
/*
void trecall_message_::recall_pressed(twindow& window) {
tlistbox& input_list = find_widget<tlistbox> (&window, "unit_list", false);
game_menu_handler_->do_recall(chosen_unit_);
input_list.remove_row(input_list.get_selected_row());
if (unit_list_.empty()) {
window.close();
}
unit_list_.erase(unit_list_.begin() + input_list.get_selected_row());
chosen_unit_ = &unit_list_[0];
update_unit_list(window);
input_list.set_dirty();
window.set_dirty();
}
*/
void tunit_message_::profile_pressed() {
const unit_type& t = *chosen_unit_->type();
help::show_unit_help(*resources::screen, t.id(), t.hide_help());
}
void tunit_message_::help_pressed() {
help::show_help(*resources::screen, "recruit_and_recall");
}
void trecall_message_::remove_pressed(CVideo& video, twindow& window) {
tlistbox& unit_listbox =
find_widget<tlistbox> (&window, "unit_list", false);
//If the unit is of level > 1, or is close to advancing,
//we warn the player about it
std::stringstream message;
if (chosen_unit_->loyal()) {
message
<< /*_*/("My lord, this unit is loyal and requires no upkeep! ")
<< (chosen_unit_->gender() == unit_race::MALE ? /*_*/("Do you really want to dismiss him?")
: /*_*/("Do you really want to dismiss her?"));
} else if (chosen_unit_->level() > 1) {
message
<< /*_*/("My lord, this unit is an experienced one, having advanced levels! ")
<< (chosen_unit_->gender() == unit_race::MALE ? /*_*/("Do you really want to dismiss him?")
: /*_*/("Do you really want to dismiss her?"));
} else if (chosen_unit_->experience() > chosen_unit_->max_experience() / 2) {
message << /*_*/("My lord, this unit is close to advancing a level! ")
<< (chosen_unit_->gender() == unit_race::MALE ? /*_*/("Do you really want to dismiss him?")
: /*_*/("Do you really want to dismiss her?"));
}
if (!message.str().empty()) {
const int res = gui2::show_message(video, "", message.str(),
tmessage::yes_no_buttons, false, false);
if (res == gui2::twindow::CANCEL) {
return;
}
}
game_menu_handler_->do_delete_recall(chosen_unit_);
// assert(unit_)
int selected_row = unit_listbox.get_selected_row();
unit_listbox.remove_row(selected_row);
window.invalidate_layout();
unit_list_.erase(unit_list_.begin() + selected_row);
if (unit_list_.empty()) {
window.close();
return;
}
*chosen_unit_ = unit_list_[0];
unit_listbox.select_row(0, true);
update_unit_list(window);
unit_listbox.set_dirty();
window.set_dirty();
}
void tunit_message_::update_unit_list(twindow& window) {
tlistbox& unit_listbox =
find_widget<tlistbox> (&window, "unit_list", false);
*chosen_unit_ = unit_list_[unit_listbox.get_selected_row()];
if (resources::game_map->on_board(chosen_unit_->get_location())) {
resources::screen->highlight_hex(chosen_unit_->get_location());
//TODO is false better?
resources::screen->scroll_to_tile(chosen_unit_->get_location(),
game_display::SCROLL, true);
} else {
//TODO
// chosen_unit_->draw_report();
}
window.canvas(1).set_variable("portrait_image", variant(
chosen_unit_->transparent()));
window.set_dirty();
}
void toption_message_::pre_show(CVideo& video, twindow& window) {
ticon_message_::pre_show(video, window);
// Find the option list related fields.
tlistbox& options = find_widget<tlistbox> (&window, "input_list", true);
/*
* The options have some special markup:
* A line starting with a * means select that line.
* A line starting with a & means more special markup.
* - The part until the = is the name of an image.
* - The part until the second = is the first column.
* - The rest is the third column (the wiki only specifies two columns
* so only implement two of them).
*/
/**
* @todo This syntax looks like a bad hack, it would be nice to write
* a new syntax which doesn't use those hacks (also avoids the problem
* with special meanings for certain characters.
*/
assert(!option_list_.empty());
// Avoid negetive and 0 since item 0 is already selected.
if (*chosen_option_ > 0 && static_cast<size_t> (*chosen_option_)
< option_list_.size()) {
options.select_row(*chosen_option_);
}
std::map<std::string, string_map> data;
for (size_t i = 0; i < option_list_.size(); ++i) {
std::string icon = "";
std::string label = option_list_[i];
std::string description = "";
// Handle selection.
if (!label.empty() && label[0] == '*') {
// Number of items hasn't been increased yet so i is ok.
*chosen_option_ = i;
label.erase(0, 1);
}
// Handle the special case with an image.
if (label.find('=') != std::string::npos) {
// We always assume the first item is an image if not it's
// still handled as an image. This is a hack but the code
// should be rewritten anyway.
if (label[0] == '&') {
label.erase(0, 1);
}
std::vector<std::string> row_data = utils::split(label, '=', 0);
label = "";
assert(!row_data.empty());
icon = row_data[0];
if (row_data.size() > 1) {
label = row_data[1];
for (size_t j = 2; j < row_data.size(); ++j) {
description += row_data[j];
if (j + 1 < row_data.size()) {
description += '=';
}
}
}
}
// Add the data.
data["icon"]["label"] = icon;
data["label"]["label"] = label;
data["label"]["use_markup"] = "true";
data["description"]["label"] = description;
data["description"]["use_markup"] = "true";
options.add_row(data);
}
window.set_click_dismiss(false);
window.set_escape_disabled(true);
}
void trecall_message_::pre_show(CVideo& video, twindow& window) {
tunit_message_::pre_show(video, window);
/*
tbutton* recall_button = find_widget<tbutton> (&window, "recall", false,
false);
recall_button->connect_signal_mouse_left_click(boost::bind(
&trecall_message_::recall_pressed, this, boost::ref(window)));
*/
tbutton* help_button = find_widget<tbutton> (&window, "help", false, false);
help_button->connect_signal_mouse_left_click(boost::bind(
&tunit_message_::help_pressed, this));
tbutton* remove_button = find_widget<tbutton> (&window, "remove", false,
false);
remove_button->connect_signal_mouse_left_click(boost::bind(
&trecall_message_::remove_pressed, this, boost::ref(video),
boost::ref(window)));
}
void tunit_message_::pre_show(CVideo& video, twindow& window) {
ticon_message_::pre_show(video, window);
tbutton* profile_button = find_widget<tbutton> (&window, "profile", false,
false);
profile_button->connect_signal_mouse_left_click(boost::bind(
&trecall_message_::profile_pressed, this));
// Find the unit list related fields.
// TODO what does the boolean has to be?
tlistbox& units = find_widget<tlistbox> (&window, "unit_list", true);
units.set_callback_value_change(dialog_callback<tunit_message_,
&tunit_message_::update_unit_list> );
std::map<std::string, string_map> data;
for (size_t i = 0; i < unit_list_.size(); i++) {
unit& unit = unit_list_[i];
bool affordable = unit.cost() <= gold_;
std::string unit_mod = affordable ? unit.image_mods() : "~GS()";
std::string icon = (unit.absolute_image() + unit_mod);
std::string type = unit.type_name();
std::string name = unit.name();
std::string traits = unit.traits_description();
std::ostringstream level;
std::ostringstream xp;
xp << unit.experience() << "/" << unit.max_experience();
// Show units of level (0=gray, 1 normal, 2 bold, 2+ bold&wbright)
const int level_number = unit.level();
//TODO enabe the switch construct after replacing the font::NORMAL_TEXT etc.
// switch(level_number)
// {
// case 0: level << "<150,150,150>";
// break;
// case 1: level << font::NORMAL_TEXT;
// break;
// case 2: level << font::BOLD_TEXT;
// break;
// default: level << font::BOLD_TEXT << "<255,255,255>";
// }
level << level_number;
std::string gold_color;
gold_color = affordable ? "green" : "red";
std::ostringstream cost;
cost << "<span color=\"" << gold_color << "\">" << unit.cost() << " "
<< /*_*/("Gold") << "</span>";
// Add the data.
data["cost"]["label"] = cost.str();
data["cost"]["use_markup"] = "true";
data["usage"]["label"] = unit.usage();
data["icon"]["label"] = icon;
data["icon"]["use_markup"] = "true";
data["name"]["label"] = name;
data["type"]["label"] = type;
data["label"]["use_markup"] = "true";
data["level"]["label"] = level.str();
data["xp"]["label"] = xp.str();
data["traits"]["label"] = unit.traits_description();
units.add_row(data);
}
update_unit_list(window);
}
void trecruit_message_::pre_show(CVideo& video, twindow& window) {
tunit_message_::pre_show(video, window);
tbutton* help_button = find_widget<tbutton> (&window, "help", false, false);
help_button->connect_signal_mouse_left_click(boost::bind(
&tunit_message_::help_pressed, this));
window.set_click_dismiss(false);
}
void tinput_message_::pre_show(CVideo& video, twindow& window) {
ticon_message_::pre_show(video, window);
ttext_box& input = find_widget<ttext_box> (&window, "input", true);
tlabel& caption = find_widget<tlabel> (&window, "input_caption", false);
caption.set_label(input_caption_);
caption.set_use_markup(true);
input.set_value(*input_text_);
input.set_maximum_length(input_maximum_lenght_);
window.keyboard_capture(&input);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
}
void ticon_message_::pre_show(CVideo& video, twindow& window) {
window.canvas(1).set_variable("portrait_image", variant(portrait_));
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
// Set the markup
tlabel& title = find_widget<tlabel> (&window, "title", false);
title.set_label(title_);
title.set_use_markup(true);
tcontrol& message = find_widget<tcontrol> (&window, "message", false);
message.set_label(message_);
message.set_use_markup(true);
// The message label might not always be a scroll_label but the capturing
// shouldn't hurt.
window.keyboard_capture(&message);
window.set_click_dismiss(true);
}
void tinput_message_::post_show(twindow& window) {
*input_text_ = find_widget<ttext_box> (&window, "input", true).get_value();
}
void toption_message_::post_show(twindow& window) {
*chosen_option_
= find_widget<tlistbox> (&window, "input_list", true).get_selected_row();
}
void tunit_message_::post_show(twindow& window) {
if (!unit_list_.empty()) {
*chosen_unit_ = unit_list_[find_widget<tlistbox> (&window, "unit_list",
true).get_selected_row()];
}
}
void trecruit_message_::post_show(twindow& window) {
tunit_message_::post_show(window);
chosen_type_ = chosen_unit_->type_id();
}
REGISTER_WINDOW(icon_message_left)
REGISTER_WINDOW(icon_message_right)
REGISTER_WINDOW(option_message_left)
REGISTER_WINDOW(option_message_right)
REGISTER_WINDOW(input_message_left)
REGISTER_WINDOW(input_message_right)
REGISTER_WINDOW(recall_message_left)
REGISTER_WINDOW(recall_message_right)
REGISTER_WINDOW(recruit_message_right)
REGISTER_WINDOW(recruit_message_left)
REGISTER_WINDOW(unit_message_left)
REGISTER_WINDOW(unit_message_right)
//begin of the wrapper functions
int show_icon_message(const bool left_side, CVideo& video,
const std::string& title, const std::string& message,
const std::string& portrait, const bool mirror) {
std::auto_ptr<ticon_message_> dlg;
if (left_side) {
dlg.reset(new ticon_message_left(title, message, portrait, mirror));
} else {
dlg.reset(new ticon_message_right(title, message, portrait, mirror));
}
assert(dlg.get());
dlg->show(video);
return dlg->get_retval();
}
int show_input_message(const bool left_side, CVideo& video,
const std::string& title, const std::string& message,
const std::string& portrait, const bool mirror,
const std::string& input_caption, std::string* input_text,
const unsigned maximum_length) {
std::auto_ptr<tinput_message_> dlg;
if (left_side) {
dlg.reset(new tinput_message_left(title, message, portrait, mirror,
input_caption, input_text, maximum_length));
} else {
dlg.reset(new tinput_message_right(title, message, portrait, mirror,
input_caption, input_text, maximum_length));
}
assert(dlg.get());
dlg->show(video);
return dlg->get_retval();
}
int show_option_message(const bool left_side, CVideo& video,
const std::string& title, const std::string& message,
const std::string& portrait, const bool mirror, const std::vector<
std::string>& option_list, int* chosen_option) {
std::auto_ptr<toption_message_> dlg;
if (left_side) {
dlg.reset(new toption_message_left(title, message, portrait, mirror,
option_list, chosen_option));
} else {
dlg.reset(new toption_message_right(title, message, portrait, mirror,
option_list, chosen_option));
}
assert(dlg.get());
dlg->show(video);
return dlg->get_retval();
}
int show_unit_message(const bool left_side, CVideo& video,
const std::string& title, const std::string& message,
const std::string& portrait, const bool mirror,
const std::vector<unit>& unit_list, unit* chosen_unit) {
std::auto_ptr<tunit_message_> dlg;
if (left_side) {
dlg.reset(new tunit_message_left(title, message, portrait, mirror,
unit_list, chosen_unit));
} else {
dlg.reset(new tunit_message_right(title, message, portrait, mirror,
unit_list, chosen_unit));
}
assert(dlg.get());
dlg->show(video);
return dlg->get_retval();
}
int show_recall_message(const bool left_side, CVideo& video, const bool mirror,
const std::vector<unit>& unit_list, unit* chosen_unit,
events::menu_handler* game_menu_handler) {
std::auto_ptr<trecall_message_> dlg;
if (left_side) {
dlg.reset(new trecall_message_left(mirror, unit_list, chosen_unit,
game_menu_handler));
} else {
dlg.reset(new trecall_message_right(mirror, unit_list, chosen_unit,
game_menu_handler));
}
assert(dlg.get());
dlg->show(video);
return dlg->get_retval();
}
int show_recruit_message(const bool left_side, CVideo& video,
const bool mirror, const std::vector<const unit_type*> type_list,
int side_num, int gold) {
std::string chosen_type_id;
std::auto_ptr<trecruit_message_> dlg;
if (left_side) {
dlg.reset(new trecruit_message_left(mirror, type_list, chosen_type_id,
side_num, gold));
} else {
dlg.reset(new trecruit_message_right(mirror, type_list, chosen_type_id,
side_num, gold));
}
assert(dlg.get());
dlg->show(video);
return dlg->get_retval();
}
} // namespace gui2

View file

@ -61,6 +61,14 @@ private:
/** Mirror the portrait? */
bool mirror_;
/**
* Inherited from tdialog.
*
* The subclasses need to implement the left or right definition.
*/
twindow* build_window(CVideo& /*video*/) = 0;
};
/** Shows a dialog with the portrait on the left side. */
@ -71,8 +79,8 @@ public:
ticon_message_(title, message, portrait, mirror) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
/** Shows a dialog with the portrait on the right side. */
@ -83,8 +91,8 @@ public:
ticon_message_(title, message, portrait, mirror) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class toption_message_: public ticon_message_ {
@ -120,8 +128,8 @@ public:
chosen_option) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
/** Shows a dialog with the portrait on the right side. */
@ -134,8 +142,8 @@ public:
chosen_option) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class tinput_message_: public ticon_message_ {
@ -176,8 +184,8 @@ public:
input_text, maximum_length) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
/** Shows a dialog with the portrait on the right side. */
@ -191,8 +199,8 @@ public:
input_text, maximum_length) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class tunit_message_: public ticon_message_ {
@ -213,7 +221,7 @@ public:
it = type_list.begin();
for (it = type_list.begin(); it != type_list.end(); it++) {
unit new_unit(*it, side_num, false);
unit new_unit(resources::units, *it, side_num, false);
unit_list_.push_back(new_unit);
}
}
@ -251,7 +259,7 @@ public:
std::string& chosen_type, int side_num, int gold) :
tunit_message_(/*_*/("Recruit"), /*_*/("Select unit:"), mirror,
type_list, &unit_, side_num, gold), chosen_type_(chosen_type),
unit_(type_list.front(), false, side_num) {
unit_(resources::units, type_list.front(), false, side_num) {
}
/** Inherited from tdialog. */
@ -276,8 +284,8 @@ public:
trecruit_message_(mirror, type_list, chosen_type, side_num, gold) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class trecruit_message_right: public trecruit_message_ {
@ -288,8 +296,8 @@ public:
trecruit_message_(mirror, type_list, chosen_type, side_num, gold) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class tunit_message_left: public tunit_message_ {
@ -300,8 +308,8 @@ public:
tunit_message_(title, message, mirror, unit_list, chosen_unit) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class tunit_message_right: public tunit_message_ {
@ -312,8 +320,8 @@ public:
tunit_message_(title, message, mirror, unit_list, chosen_unit) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class trecall_message_: public tunit_message_ {
@ -348,8 +356,8 @@ public:
trecall_message_(mirror, unit_list, chosen_unit, game_menu_handler) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
class trecall_message_right: public trecall_message_ {
@ -360,8 +368,8 @@ public:
trecall_message_(mirror, unit_list, chosen_unit, game_menu_handler) {
}
private:
/** Inherited from tdialog, implemented by REGISTER_WINDOW */
virtual const std::string& window_id() const;
/** Inherited from twml_message_. */
twindow* build_window(CVideo& video);
};
//TODO find a way to reference to this documentation in the other methods.

View file

@ -105,21 +105,14 @@ const struct {
{ hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", N_("Quit to Desktop"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_CLOSE_MAP, "editor-close-map", N_("Close Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SWITCH_MAP, "editor-switch-map", N_("Switch Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SWITCH_SIDE, "editor-switch-side", N_("Switch Side"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SWITCH_AREA, "editor-switch-area", N_("Switch Area"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SETTINGS, "editor-settings", N_("Editor Settings"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_PARTIAL_UNDO, "editor-partial-undo", N_("Partial Undo"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_NEW, "editor-map-new", N_("New Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SIDE_NEW, "editor-side-new", N_("New Side"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_LOAD, "editor-map-load", N_("Load Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_SAVE, "editor-map-save", N_("Save Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_SAVE_AS, "editor-map-save-as", N_("Save Map As"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_REVERT, "editor-map-revert", N_("Revert All Changes"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_INFO, "editor-map-info", N_("Map Information"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MULTIPLAYER_SAVE, "editor-multiplayer-save", N_("Save Multiplayer Scenario"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MULTIPLAYER_SAVE_AS, "editor-multiplayer-save-as", N_("Save Multiplayer Scenario As"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP, "editor-terrain-palette-swap",
N_("Swap fore- and background terrains"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TOOL_NEXT, "editor-tool-next", N_("Next Tool"), false, hotkey::SCOPE_EDITOR },
@ -128,16 +121,6 @@ const struct {
{ hotkey::HOTKEY_EDITOR_TOOL_SELECT, "editor-tool-select", N_("Selection Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION, "editor-tool-starting-position",
N_("Set Starting Positions Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TOOL_LABEL, "editor-tool-map-label",
N_("Set Map Label Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TOOL_UNIT, "editor-tool-unit",
N_("Place Unit Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TOOL_VILLAGE, "editor-tool-village",
N_("Village Ownership Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_TOOL_PATH, "editor-tool-path",
N_("Unit Path Tool"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_NEXT, "editor-brush-next", N_("Next Brush"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_BRUSH_DEFAULT, "editor-brush-default", N_("Default Brush"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_CUT, "editor-cut", N_("Cut"), false, hotkey::SCOPE_EDITOR },
@ -164,8 +147,6 @@ const struct {
N_("Flip Selection"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECTION_FILL, "editor-selection-fill",
N_("Fill Selection"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECTION_NAME, "editor-selection-name",
N_("Name Selection"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECTION_GENERATE, "editor-selection-generate",
N_("Generate Tiles In Selection"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECTION_RANDOMIZE, "editor-selection-randomize",

View file

@ -64,21 +64,13 @@ enum HOTKEY_COMMAND {
#ifndef DISABLE_EDITOR
HOTKEY_EDITOR_QUIT_TO_DESKTOP,
HOTKEY_EDITOR_CLOSE_MAP, HOTKEY_EDITOR_SWITCH_MAP,
HOTKEY_EDITOR_SWITCH_AREA, HOTKEY_EDITOR_SWITCH_SIDE,
HOTKEY_EDITOR_SETTINGS,
HOTKEY_EDITOR_PARTIAL_UNDO,
HOTKEY_EDITOR_MAP_NEW, HOTKEY_EDITOR_MAP_LOAD, HOTKEY_EDITOR_MAP_SAVE,
HOTKEY_EDITOR_MULTIPLAYER_SAVE, HOTKEY_EDITOR_MULTIPLAYER_SAVE_AS,
HOTKEY_EDITOR_SIDE_NEW,
HOTKEY_EDITOR_MAP_SAVE_AS, HOTKEY_EDITOR_MAP_REVERT, HOTKEY_EDITOR_MAP_INFO,
HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP,
HOTKEY_EDITOR_TOOL_NEXT, HOTKEY_EDITOR_TOOL_PAINT, HOTKEY_EDITOR_TOOL_FILL,
HOTKEY_EDITOR_TOOL_SELECT, HOTKEY_EDITOR_TOOL_STARTING_POSITION,
HOTKEY_EDITOR_TOOL_LABEL,
HOTKEY_EDITOR_TOOL_UNIT,
HOTKEY_EDITOR_TOOL_VILLAGE,
HOTKEY_EDITOR_TOOL_PATH,
HOTKEY_EDITOR_BRUSH_NEXT, HOTKEY_EDITOR_BRUSH_DEFAULT,
HOTKEY_EDITOR_CUT, HOTKEY_EDITOR_COPY, HOTKEY_EDITOR_PASTE,
HOTKEY_EDITOR_EXPORT_SELECTION_COORDS,
@ -88,7 +80,6 @@ enum HOTKEY_COMMAND {
HOTKEY_EDITOR_CLIPBOARD_FLIP_HORIZONTAL, HOTKEY_EDITOR_CLIPBOARD_FLIP_VERTICAL,
HOTKEY_EDITOR_SELECTION_ROTATE, HOTKEY_EDITOR_SELECTION_FLIP,
HOTKEY_EDITOR_SELECTION_FILL,
HOTKEY_EDITOR_SELECTION_NAME,
HOTKEY_EDITOR_SELECTION_GENERATE, HOTKEY_EDITOR_SELECTION_RANDOMIZE,
HOTKEY_EDITOR_MAP_RESIZE, HOTKEY_EDITOR_MAP_ROTATE,
HOTKEY_EDITOR_MAP_GENERATE, HOTKEY_EDITOR_MAP_APPLY_MASK,

View file

@ -1,196 +0,0 @@
/* $Id: map_label.cpp 41350 2010-02-22 06:14:34Z fendrin $ */
/*
Copyright (C) 2003 - 2010 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "global.hpp"
#include "foreach.hpp"
#include "map_area.hpp"
#include "serialization/string_utils.hpp"
//map_areas::map_areas(const config& cfg)
//{
// read(cfg);
//}
//map_areas::map_areas()
//{
//
//}
map_areas::~map_areas()
{
}
void map_areas::read(const config &cfg)
{
// clear_all();
foreach (const config &i, cfg.child_range("named_area"))
{
map_area* area = new map_area(i);
add_area(*area);
}
}
//TODO think about the const
void map_areas::write(config& res) const
{
for (area_map::const_iterator area_it = areas_.begin(); area_it != areas_.end(); ++area_it)
{
area_it->second.write(res);
}
}
config map_areas::to_config() const
{
config res;
write(res);
return res;
}
void map_areas::add_area(const map_area& area)
{
map_area area_ = area;
areas_[area_.get_area_id()] = area_;
}
void map_areas::add_area(const std::string& area_id, const std::set<map_location>& locations)
{
map_area* area = new map_area(area_id, locations);
add_area(*area);
}
const map_area& map_areas::get_area(const std::string& area_id) const
{
const map_area* res = new map_area();
area_map::const_iterator areas_it = areas_.find(area_id);
if (areas_it != areas_.end()) {
res = &(areas_it->second);
}
return *res;
}
const std::vector<std::string> map_areas::get_area_ids() const
{
std::vector<std::string> res;
for(area_map::const_iterator it = areas_.begin(); it != areas_.end(); ++it) {
res.push_back(it->first);
// cout << it->first << "\n";
}
return res;
}
void map_areas::clear()
{
areas_.clear();
}
//TODO reuse code to implement map transformations
//void map_labels::scroll(double xmove, double ymove)
//{
// 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)
// {
// j->second->scroll(xmove, ymove);
// }
// }
//}
map_area::map_area(const config& cfg) : slf_(cfg)
{
area_id_ = cfg["area_id"];
}
map_area::map_area(const map_area& area) : area_id_(area.area_id_), slf_(area.slf_)
{
}
map_area::map_area(std::string area_id, std::set<map_location> locs)
: area_id_(area_id), slf_()
{
std::stringstream ssx, ssy;
std::set<map_location>::const_iterator i = locs.begin();
if (i != locs.end()) {
// ssx << "x = " << i->x + 1;
// ssy << "y = " << i->y + 1;
ssx << i->x + 1;
ssy << i->y + 1;
++i;
while (i != locs.end()) {
ssx << ", " << i->x + 1;
ssy << ", " << i->y + 1;
++i;
}
slf_["x"] = ssx.str();
slf_["y"] = ssy.str();
// ssx << "\n" << ssy.str() << "\n";
// copy_to_clipboard(ssx.str(), false);
}
}
//void map_area::operator=(const map_area&)
//{
//// this->
//}
map_area::~map_area()
{
}
config map_area::to_config() const
{
config res;
write(res);
return res;
}
void map_area::write(config& res) const
{
config item = slf_;
item["area_id"] = area_id_;
res.add_child("named_area", item);
}
void map_area::read(const config &cfg)
{
area_id_ = cfg["area_id"];
slf_ = cfg;
}
const std::set<map_location> map_area::get_simple_locations()
{
std::string x = slf_["x"];
std::string y = slf_["y"];
const std::vector<std::string> xvals = utils::split(x);
const std::vector<std::string> yvals = utils::split(y);
std::set<map_location> locations;
map_location loc;
for(size_t i = 0; i != std::min(xvals.size(),yvals.size()); ++i) {
// if(i==0){
loc.x = atoi(xvals[i].c_str())-1;
loc.y = atoi(yvals[i].c_str())-1;
// if (!game_map->on_board(src)) {
// ERR_CF << "invalid move_unit_fake source: " << src << '\n';
// break;
// }
locations.insert(loc);
}
return locations;
}

View file

@ -1,90 +0,0 @@
/* $Id: map_label.hpp 41350 2010-02-22 06:14:34Z fendrin $ */
/*
Copyright (C) 2003 - 2010 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef MAP_AREA_HPP_INCLUDED
#define MAP_AREA_HPP_INCLUDED
#include "savegame_config.hpp"
#include "map_location.hpp"
#include "config.hpp"
#include <map>
#include <set>
#include <string>
class config;
class map_area;
class map_areas : public savegame::savegame_config
{
public:
map_areas() : areas_() {}
map_areas(const config& cfg) : areas_() { read(cfg); }
~map_areas();
config to_config() const;
void read(const config &cfg);
void write(config& res) const;
void add_area(const map_area& area);
void add_area(const std::string& area_id, const std::set<map_location>& locations);
const map_area& get_area(const std::string& area_id) const;
const std::vector<std::string> get_area_ids() const;
void clear();
// void operator=(const labels&);
private:
typedef std::map<std::string, map_area> area_map;
area_map areas_;
};
class map_area : public savegame::savegame_config
{
public:
// map_area(const std::string& area_id,
// const std::set<map_location>& locations);
map_area() : area_id_(), slf_() {};
// void operator=(const map_area&);
map_area(const config& cfg);
map_area(const map_area& area);
map_area(std::string area_id, std::set<map_location> locs);
~map_area();
config to_config() const;
void write(config& res) const;
void read(const config &cfg);
const std::string& get_area_id() { return area_id_; };
const config& get_slf() { return slf_; };
const std::set<map_location> get_simple_locations();
private:
//TODO make the privates const
std::string area_id_;
config slf_;
};
#endif

View file

@ -23,8 +23,7 @@
namespace {
const size_t max_ingame_label_size = 32;
const size_t max_label_size = 128;
const size_t max_label_size = 32;
}
//our definition of map labels being obscured is if the tile is obscured,
@ -37,63 +36,46 @@ static bool is_shrouded(const display& disp, const map_location& loc)
}
map_labels::map_labels(const display &disp, const team *team) :
labels(), disp_(disp), team_(team)
disp_(disp), team_(team), labels_()
{
// std::cerr << "\n constructor labels :" << this;
}
//labels::labels() :
// labels_()
//{
//}
//labels::~labels()
//{
// clear_all();
//}
map_labels::~map_labels()
{
clear_all();
}
void labels::write(config& res) const
void map_labels::write(config& res) const
{
for (team_label_map::const_iterator labs = labels_.begin(); labs != labels_.end(); ++labs)
{
for(label_map::const_iterator i = labs->second.begin(); i != labs->second.end(); ++i) {
config item;
std::cerr << "\n log in write labels:" << &(*i->second) << "\n";
i->second->write(item);
res.add_child("label",item);
}
}
}
void labels::read(const config &cfg)
void map_labels::read(const config &cfg)
{
clear_all();
foreach (const config &i, cfg.child_range("label"))
{
const map_location loc(i, resources::state_of_game);
label *new_label = new label(*this, i);
add_label(loc, new_label);
terrain_label *label = new terrain_label(*this, i);
add_label(loc, label);
}
}
void map_labels::read(const config &cfg)
{
labels::read(cfg);
recalculate_labels();
}
size_t labels::get_max_chars(bool ingame)
size_t map_labels::get_max_chars()
{
// return max_ingame_label_size;
return (ingame ? max_ingame_label_size : max_label_size);
return max_label_size;
}
const terrain_label* map_labels::get_label(const map_location& loc, const std::string& team_name)
@ -107,34 +89,6 @@ const terrain_label* map_labels::get_label(const map_location& loc, const std::s
return NULL;
}
std::vector<label> labels::delete_labels(const map_location& loc) {
std::vector<label> res;
team_label_map::const_iterator it = labels_.begin();
for(; it != labels_.end(); it++) {
labels::label_map::const_iterator labelit = it->second.find(loc);
if (labelit != it->second.end())
res.push_back(*labelit->second.get());
}
for(std::vector<label>::iterator it = res.begin(); it != res.end(); it++) {
// labels_.find(it->team_name())->second.erase(loc);
labels_[it->team_name()].erase(loc);
}
return res;
}
const label* labels::get_label(const map_location& loc) const
{
team_label_map::const_iterator label_map = labels_.find("");
if (label_map != labels_.end()) {
labels::label_map::const_iterator itor = label_map->second.find(loc);;
if (itor != label_map->second.end())
return (itor->second).get();
}
return NULL;
}
const terrain_label* map_labels::get_label(const map_location& loc)
{
const terrain_label* res = get_label(loc, team_name());
@ -171,84 +125,12 @@ void map_labels::set_team(const team* team)
}
const label* labels::set_label(const map_location& loc,
const std::string& text,
const std::string& team_name,
const SDL_Color colour,
const bool visible_in_fog,
const bool visible_in_shroud)
{
label* res = 0;
team_label_map::iterator current_label_map = labels_.find(team_name);
label_map::iterator current_label;
if ( current_label_map != labels_.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())
{
current_label->second->set_text("");
res = new label("",team_name,loc,*this,colour,visible_in_fog,visible_in_shroud);
// delete current_label->second;
current_label_map->second.erase(loc);
team_label_map::iterator global_label_map = labels_.find("");
label_map::iterator itor;
bool update = false;
if(global_label_map != labels_.end()) {
itor = global_label_map->second.find(loc);
update = itor != global_label_map->second.end();
}
// if (update)
// {
// itor->second->recalculate();
// }
}
else
{
current_label->second->update_info(text, team_name, colour);
res = current_label->second.get();
}
}
else if(!text.empty())
{
team_label_map::iterator global_label_map = labels_.find("");
label_map::iterator itor;
bool update = false;
if(global_label_map != labels_.end()) {
itor = global_label_map->second.find(loc);
update = itor != global_label_map->second.end();
}
label* new_label = new label(text,
team_name,
loc,
*this,
colour,
visible_in_fog,
visible_in_shroud);
add_label(loc,new_label);
res = new_label;
// if (update)
// {
// itor->second->recalculate();
// }
}
return res;
}
const terrain_label* map_labels::set_label(const map_location& loc,
const std::string& text,
const std::string& team_name,
const SDL_Color colour,
const bool visible_in_fog,
const bool visible_in_shroud,
const bool ingame)
const bool visible_in_shroud)
{
terrain_label* res = 0;
team_label_map::iterator current_label_map = labels_.find(team_name);
@ -261,7 +143,7 @@ const terrain_label* map_labels::set_label(const map_location& loc,
if(text.empty())
{
current_label->second->set_text("");
res = new terrain_label("",team_name,loc,*this,colour,visible_in_fog,visible_in_shroud, ingame);
res = new terrain_label("",team_name,loc,*this,colour,visible_in_fog,visible_in_shroud);
delete current_label->second;
current_label_map->second.erase(loc);
@ -294,17 +176,16 @@ const terrain_label* map_labels::set_label(const map_location& loc,
update = itor != global_label_map->second.end();
}
terrain_label* new_label = new terrain_label(text,
terrain_label* label = new terrain_label(text,
team_name,
loc,
*this,
colour,
visible_in_fog,
visible_in_shroud,
ingame);
add_label(loc,new_label);
visible_in_shroud);
add_label(loc,label);
res = new_label;
res = label;
if (update)
{
@ -315,11 +196,6 @@ const terrain_label* map_labels::set_label(const map_location& loc,
return res;
}
void labels::add_label(const map_location &loc, label *new_label)
{
labels_[new_label->team_name()][loc] = boost::shared_ptr<label>(new_label);
}
void map_labels::add_label(const map_location &loc, terrain_label *new_label)
{
labels_[new_label->team_name()][loc] = new_label;
@ -349,37 +225,6 @@ void map_labels::clear_map(label_map &m)
m.clear();
}
void labels::clear_map(label_map &m)
{
//TODO clean up
// foreach (label_map::value_type &v, m)
// {
// delete v.second.get();
// }
m.clear();
}
//TODO clean up
//void map_labels::clear_map(label_map &m)
//{
//// foreach (label_map::value_type &v, m)
//// {
//// delete v.second.get();
//// }
// m.clear();
//}
void labels::clear_all()
{
foreach (team_label_map::value_type &m, labels_)
{
clear_map(m.second);
}
labels_.clear();
}
void map_labels::clear_all()
{
foreach (team_label_map::value_type &m, labels_)
@ -389,7 +234,6 @@ void map_labels::clear_all()
labels_.clear();
}
void map_labels::scroll(double xmove, double ymove)
{
for(team_label_map::const_iterator i = labels_.begin(); i != labels_.end(); ++i)
@ -431,11 +275,11 @@ void map_labels::recalculate_shroud()
}
// creating new label
label::label(const std::string& text,
/// creating new label
terrain_label::terrain_label(const std::string& text,
const std::string& team_name,
const map_location& loc,
const labels& parent,
const map_labels& parent,
const SDL_Color colour,
const bool visible_in_fog,
const bool visible_in_shroud) :
@ -448,87 +292,33 @@ label::label(const std::string& text,
parent_(&parent),
loc_(loc)
{
std::cerr << "\n constructor label item :" << this << "\n";
check_text_length();
}
terrain_label::terrain_label(const std::string& text,
const std::string& team_name,
const map_location& loc,
const map_labels& parent,
const SDL_Color colour,
const bool visible_in_fog,
const bool visible_in_shroud,
const bool ingame) :
label(text, team_name, loc, parent, colour, visible_in_fog, visible_in_shroud)
, parent_(&parent), ingame_(ingame)
{
draw();
}
label::label(const label& other) : handle_(other.handle_)
, text_(other.text_)
, team_name_(other.team_name_)
, visible_in_fog_(other.visible_in_fog_)
, visible_in_shroud_(other.visible_in_shroud_)
, colour_(other.colour_)
, parent_(other.parent_)
, loc_(other.loc_)
{
}
label::label(const labels &parent, const config &cfg) :
handle_(0),
text_(),
team_name_(),
visible_in_fog_(true),
visible_in_shroud_(false),
colour_(),
parent_(&parent),
loc_()
/// Load label from config
terrain_label::terrain_label(const map_labels &parent, const config &cfg) :
handle_(0),
text_(),
team_name_(),
visible_in_fog_(true),
visible_in_shroud_(false),
colour_(),
parent_(&parent),
loc_()
{
read(cfg);
check_text_length();
std::cerr << "\n constructor label item :" << this << "\n";
}
/* Load label from config */
terrain_label::terrain_label(const map_labels &parent, const config &cfg, const bool ingame) :
label(parent, cfg), parent_(&parent), ingame_(ingame)
//TODO clean up.
// handle_(0),
// text_(),
// team_name_(),
// visible_in_fog_(true),
// visible_in_shroud_(false),
// colour_(),
// parent_(&parent),
// loc_()
{
// std::cerr << "\n constructor label item :" << this << "\n";
// read(cfg);
// check_text_length();
}
terrain_label::~terrain_label()
{
clear();
}
label::~label()
void terrain_label::read(const config &cfg)
{
std::cerr << "\n destructor label item :" << this << "\n";
clear();
}
void label::read(const config &cfg)
{
const variable_set &vs = *resources::state_of_game;
loc_ = map_location(cfg, &vs);
SDL_Color colour = font::LABEL_COLOUR;
@ -548,7 +338,6 @@ void label::read(const config &cfg)
try {
temp_rgb = string2rgb(tmp_colour);
} catch(bad_lexical_cast&) {
//TODO comment or remove.
//throw config::error(_("Invalid color range: ") + name);
}
if(!temp_rgb.empty()) {
@ -558,47 +347,47 @@ void label::read(const config &cfg)
colour_ = colour;
}
void label::write(config& cfg) const
void terrain_label::write(config& cfg) const
{
loc_.write(cfg);
cfg["text"] = text();
cfg["team_name"] = (this->team_name());
cfg["colour"] = cfg_colour();
cfg["visible_in_fog"] = visible_in_fog();
cfg["visible_in_shroud"] = visible_in_shroud();
cfg["visible_in_fog"] = visible_in_fog_;
cfg["visible_in_shroud"] = visible_in_shroud_;
}
const std::string& label::text() const
const std::string& terrain_label::text() const
{
return text_;
}
const std::string& label::team_name() const
const std::string& terrain_label::team_name() const
{
return team_name_;
}
bool label::visible_in_fog() const
bool terrain_label::visible_in_fog() const
{
return visible_in_fog_;
}
bool label::visible_in_shroud() const
bool terrain_label::visible_in_shroud() const
{
return visible_in_shroud_;
}
const map_location& label::location() const
const map_location& terrain_label::location() const
{
return loc_;
}
const SDL_Colour& label::colour() const
const SDL_Colour& terrain_label::colour() const
{
return colour_;
}
std::string label::cfg_colour() const
std::string terrain_label::cfg_colour() const
{
std::stringstream buf;
const unsigned int red = static_cast<unsigned int>(colour_.r);
@ -612,12 +401,12 @@ std::string label::cfg_colour() const
return buf.str();
}
void label::set_text(const std::string& text)
void terrain_label::set_text(const std::string& text)
{
text_ = text;
}
void label::update_info(const std::string& text,
void terrain_label::update_info(const std::string& text,
const std::string& team_name,
const SDL_Color colour)
{
@ -625,17 +414,9 @@ void label::update_info(const std::string& text,
text_ = text;
check_text_length();
team_name_ = team_name;
}
void terrain_label::update_info(const std::string& text,
const std::string& team_name,
const SDL_Color colour)
{
label::update_info(text, team_name, colour);
draw();
}
void terrain_label::scroll(const double xmove,
const double ymove) const
{
@ -669,6 +450,7 @@ void terrain_label::draw()
clear();
if (visible())
{
const map_location loc_nextx(loc_.x+1,loc_.y);
const map_location loc_nexty(loc_.x,loc_.y+1);
const int xloc = (parent_->disp().get_location_x(loc_) +
@ -701,7 +483,7 @@ bool terrain_label::visible() const
|| (team_name_.empty() && parent_->visible_global_label(loc_)));
}
void label::check_text_length()
void terrain_label::check_text_length()
{
// The actual data is wide_strings so test in wide_string mode
// also cutting a wide_string at an arbritary place gives odd
@ -709,16 +491,7 @@ void label::check_text_length()
utils::truncate_as_wstring(text_, parent_->get_max_chars());
}
void terrain_label::check_text_length()
{
// The actual data is wide_strings so test in wide_string mode
// also cutting a wide_string at an arbritary place gives odd
// problems.
utils::truncate_as_wstring(text_, parent_->get_max_chars(ingame_));
}
void label::clear()
void terrain_label::clear()
{
if (handle_)
{

View file

@ -17,167 +17,72 @@
#include "map_location.hpp"
#include "font.hpp"
#include "team.hpp"
#include <iostream>
#include <map>
#include <string>
class config;
class display;
class team;
class terrain_label;
class label;
class labels
class map_labels
{
public:
typedef std::map<map_location, boost::shared_ptr<label> > label_map;
typedef std::map<map_location, terrain_label *> label_map;
typedef std::map<std::string,label_map> team_label_map;
labels() : labels_() { std::cerr << "\n constructor labels :" << this << "\n"; };
labels(const config& cfg) : labels_() { read(cfg); std::cerr << "\n constructor labels :" << this << "\n"; };
~labels( ) {
clear_all();
std::cerr << "\n destructor labels :" << this << "\n"; };
std::vector<label> delete_labels(const map_location& loc);
const label* get_label(const map_location& loc) const;
virtual const team_label_map& get_team_label_map() { return labels_; }
map_labels(const display& disp, const team*);
~map_labels();
void write(config& res) const;
void read(const config& cfg);
void read(const config &cfg);
static size_t get_max_chars(bool ingame = true);
static size_t get_max_chars();
const label* set_label(const map_location& loc,
const terrain_label* get_label(const map_location& loc, const std::string& team_name);
// search a team-only label, if fails then try public labels
const terrain_label* get_label(const map_location& loc);
const terrain_label* set_label(const map_location& loc,
const std::string& text,
const std::string& team = "",
const SDL_Color colour = font::NORMAL_COLOUR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false);
void add_label(const map_location &, label *);
virtual void clear_all();
virtual void clear_map(label_map &);
private:
team_label_map labels_;
};
class map_labels : public labels
{
public:
typedef std::map<map_location, terrain_label *> label_map;
// typedef std::map<map_location, terrain_label *> label_map;
// typedef std::map<std::string,label_map> team_label_map;
typedef std::map<std::string,label_map> team_label_map;
map_labels(const display& disp, const team*);
~map_labels();
// search a team-only label, if fails then try public labels
const terrain_label* get_label(const map_location& loc, const std::string& team_name);
const terrain_label* get_label(const map_location& loc);
const terrain_label* set_label(const map_location& loc,
const std::string& text,
const std::string& team = "",
const SDL_Color colour = font::NORMAL_COLOUR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false,
const bool ingame = true);
void add_label(const map_location &, terrain_label *);
void read(const config &cfg);
void clear(const std::string&);
void clear_all();
void clear_map(label_map &);
void scroll(double xmove, double ymove);
void recalculate_labels();
bool visible_global_label(const map_location&) const;
void recalculate_shroud();
const display& disp() const;
void recalculate_labels();
const std::string& team_name() const;
void set_team(const team*);
void clear_all();
private:
void clear_map(label_map &);
map_labels(const map_labels&);
// void clear_map(label_map &);
void operator=(const map_labels&);
const display& disp_;
const team* team_;
team_label_map labels_;
};
class label
{
public:
label(const std::string& text,
const std::string& team_name,
const map_location& loc,
const labels& parent,
const SDL_Color colour = font::NORMAL_COLOUR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false);
label(const labels &, const config &);
~label();
void write(config& res) const;
void read(const config &cfg);
const std::string& team_name() const;
bool visible_in_fog() const;
bool visible_in_shroud() const;
const map_location& location() const;
const SDL_Colour& colour() const;
const std::string& text() const;
void set_text(const std::string&);
void update_info(const std::string&,
const std::string&,
const SDL_Color);
label(const label&);
protected:
void clear();
int handle_;
std::string text_;
std::string team_name_;
bool visible_in_fog_;
bool visible_in_shroud_;
SDL_Color colour_;
std::string cfg_colour() const;
virtual void check_text_length();
const labels* parent_;
map_location loc_;
};
/// To store label data
/// Class implements logic for rendering
class terrain_label : public label
class terrain_label
{
public:
terrain_label(const std::string&,
@ -186,31 +91,53 @@ public:
const map_labels&,
const SDL_Color colour = font::NORMAL_COLOUR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false,
const bool ingame = true);
const bool visible_in_shroud = false);
terrain_label(const map_labels &, const config &, const bool ingame = true);
terrain_label(const map_labels &, const config &);
~terrain_label();
void write(config& res) const;
void read(const config &cfg);
const std::string& text() const;
const std::string& team_name() const;
bool visible_in_fog() const;
bool visible_in_shroud() const;
const map_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);
void scroll(double xmove, double ymove) const;
void recalculate();
void calculate_shroud() const;
void update_info(const std::string&,
const std::string&,
const SDL_Color);
void check_text_length();
private:
terrain_label(const terrain_label&);
const terrain_label& operator=(const terrain_label&);
void clear();
void draw();
bool visible() const;
void check_text_length();
std::string cfg_colour() const;
int handle_;
std::string text_;
std::string team_name_;
bool visible_in_fog_;
bool visible_in_shroud_;
SDL_Color colour_;
const map_labels* parent_;
const bool ingame_;
map_location loc_;
};

View file

@ -75,7 +75,7 @@ struct map_location {
// Adds an absolute location to a "delta" location
// This is not the mathematically correct behaviour, it is neither
// commutative nor associative. Negative coordinates may give strange
// results. It is retained because terrain builder code relies in this
// results. It is retained because terain builder code relies in this
// broken behaviour. Best avoid.
map_location legacy_negation() const;
map_location legacy_sum(const map_location &a) const;

View file

@ -31,7 +31,6 @@
#include "gettext.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/dialogs/wml_message.hpp"
#include "gui/dialogs/icon_message.hpp"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/dialogs/unit_create.hpp"
#include "gui/widgets/settings.hpp"
@ -713,33 +712,28 @@ void menu_handler::recruit(bool browse, int side_num, const map_location &last_h
int recruit_res = 0;
bool left_side = true;
//recruit_res = gui2::show_recruit_message()
recruit_res = gui2::show_recruit_message(left_side, gui_->video(), false, sample_units, side_num, current_team.gold());
{
dialogs::unit_types_preview_pane unit_preview(
sample_units, NULL, side_num);
std::vector<gui::preview_pane*> preview_panes;
preview_panes.push_back(&unit_preview);
gui::dialog rmenu(*gui_, _("Recruit") + get_title_suffix(side_num),
_("Select unit:") + std::string("\n"),
gui::OK_CANCEL,
gui::dialog::default_style);
rmenu.add_button(new help::help_button(*gui_,"recruit_and_recall"),
gui::dialog::BUTTON_HELP);
rmenu.set_menu(items);
rmenu.set_panes(preview_panes);
recruit_res = rmenu.show();
}
if(recruit_res != -1) {
do_recruit(item_keys[recruit_res], side_num, last_hex);
}
}
void menu_handler::do_delete_recall(unit* un)
{
//int side_num = un->side();
//TODO
// team &current_team = teams_[side_num - 1];
//add dismissal to the undo stack
undo_stack_.push_back(undo_action(*un, map_location(),
undo_action::DISMISS));
//remove the unit from the recall list
//TODO
//current_team.remove_from_recall(un->underlying_id());
recorder.add_disband(un->id());
//clear the redo stack to avoid duplication of dismissals
redo_stack_.clear();
}
void menu_handler::repeat_recruit(int side_num, const map_location &last_hex)
{
@ -845,8 +839,6 @@ void menu_handler::recall(int side_num, const map_location &last_hex)
return;
}
//TODO
std::vector<std::string> options, options_to_filter;
std::ostringstream heading;
@ -1268,8 +1260,9 @@ void menu_handler::show_enemy_moves(bool ignore_units, int side_num)
!gui_->fogged(u->get_location()) && !u->incapacitated() && !invisible)
{
const unit_movement_resetter move_reset(*u);
bool teleports = u->get_ability_bool("teleport");
const pathfind::paths& path = pathfind::paths(map_,units_,
u->get_location(), teams_, false, true,
u->get_location(), teams_, false, teleports,
teams_[gui_->viewing_team()], 0, false, ignore_units);
gui_->highlight_another_reach(path);

View file

@ -99,7 +99,6 @@ public:
void do_search(const std::string& new_search);
void do_command(const std::string &str, int side_num, mouse_handler &mousehandler);
void do_ai_formula(const std::string &str, int side_num, mouse_handler &mousehandler);
void do_delete_recall(unit* un);
void clear_undo_stack(int side_num);
protected:
void add_chat_message(const time_t& time, const std::string& speaker,

View file

@ -27,7 +27,6 @@
#include "map.hpp"
#include "marked-up_text.hpp"
#include "menu_events.hpp"
#include "pathfind/teleport.hpp"
#include "play_controller.hpp"
#include "sound.hpp"
#include "replay.hpp"
@ -233,8 +232,9 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
//unit under cursor is not on our team, highlight reach
unit_movement_resetter move_reset(*un);
bool teleport = un->get_ability_bool("teleport");
current_paths_ = pathfind::paths(map_,units_,new_hex,teams_,
false,true,viewing_team(),path_turns_);
false,teleport,viewing_team(),path_turns_);
gui().highlight_reach(current_paths_);
enemy_paths_ = true;
} else {
@ -343,7 +343,7 @@ pathfind::marked_route mouse_handler::get_route(unit_map::const_iterator un, map
// The pathfinder will check unit visibility (fogged/stealthy).
const pathfind::shortest_path_calculator calc(*un, team, units_, teams_, map_);
pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*un, units_, viewing_team());
std::set<map_location> allowed_teleports = pathfind::get_teleport_locations(*un, units_, viewing_team());
pathfind::plain_route route;
@ -533,8 +533,9 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse) {
// if it's not the unit's turn, we reset its moves
// and we restore them before the "select" event is raised
unit_movement_resetter move_reset(*u, u->side() != side_num_);
bool teleport = u->get_ability_bool("teleport");
current_paths_ = pathfind::paths(map_, units_, hex, teams_,
false, true, viewing_team(), path_turns_);
false, teleport, viewing_team(), path_turns_);
}
show_attack_options(u);
gui().highlight_reach(current_paths_);

View file

@ -31,6 +31,7 @@ mp_game_settings::mp_game_settings() :
mp_scenario(),
village_gold(0),
xp_modifier(0),
stat_modifier(0),
mp_countdown_init_time(0),
mp_countdown_reservoir_time(0),
mp_countdown_turn_bonus(0),
@ -57,6 +58,7 @@ mp_game_settings::mp_game_settings(const config& cfg) :
mp_scenario(),
village_gold(0),
xp_modifier(0),
stat_modifier(0),
mp_countdown_init_time(0),
mp_countdown_reservoir_time(0),
mp_countdown_turn_bonus(0),
@ -84,6 +86,7 @@ mp_game_settings::mp_game_settings(const mp_game_settings& settings)
, mp_scenario(settings.mp_scenario)
, village_gold(settings.village_gold)
, xp_modifier(settings.xp_modifier)
, stat_modifier(settings.stat_modifier)
, mp_countdown_init_time(settings.mp_countdown_init_time)
, mp_countdown_reservoir_time(settings.mp_countdown_reservoir_time)
, mp_countdown_turn_bonus(settings.mp_countdown_turn_bonus)
@ -112,6 +115,7 @@ void mp_game_settings::set_from_config(const config& game_cfg)
mp_era = cfg["mp_era"];
mp_scenario = cfg["mp_scenario"];
xp_modifier = lexical_cast_default<int>(cfg["experience_modifier"]);
stat_modifier = lexical_cast_default<int>(cfg["stat_modifier"]);
use_map_settings = utils::string_bool(cfg["mp_use_map_settings"]);
fog_game = utils::string_bool(cfg["mp_fog"]);
shroud_game = utils::string_bool(cfg["mp_shroud"]);
@ -134,6 +138,7 @@ void mp_game_settings::reset()
mp_scenario = "";
village_gold = 0;
xp_modifier = 0;
stat_modifier = 0;
mp_countdown_init_time=0;
mp_countdown_reservoir_time=0;
mp_countdown_turn_bonus=0;
@ -153,6 +158,7 @@ config mp_game_settings::to_config() const
cfg["mp_era"] = mp_era;
cfg["mp_scenario"] = mp_scenario;
cfg["experience_modifier"] = lexical_cast<std::string>(xp_modifier);
cfg["stat_modifier"] = lexical_cast<std::string>(stat_modifier);
cfg["mp_countdown"] = mp_countdown;
cfg["mp_countdown_init_time"] = lexical_cast_default<std::string>(mp_countdown_init_time, "270");
cfg["mp_countdown_turn_bonus"] = lexical_cast_default<std::string>(mp_countdown_turn_bonus, "35");

View file

@ -1,6 +1,6 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2010 by Jörg Hinrichs
Copyright (C) 2003 - 2010 by J<EFBFBD>rg Hinrichs
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
@ -41,6 +41,7 @@ struct mp_game_settings : public savegame::savegame_config
int village_gold;
int xp_modifier;
int stat_modifier;
int mp_countdown_init_time;
int mp_countdown_reservoir_time;
int mp_countdown_turn_bonus;

View file

@ -1579,7 +1579,7 @@ void connect::load_game()
{
level_["random_start_time"] = false;
}
level_["stat_modifier"] = lexical_cast<std::string>(params_.stat_modifier);
level_["experience_modifier"] = params_.xp_modifier;
level_["random_seed"] = state_.rng().get_random_seed();
}

View file

@ -73,6 +73,8 @@ create::create(game_display& disp, const config &cfg, chat& c, config& gamelist)
village_gold_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOUR),
xp_modifier_slider_(disp.video()),
xp_modifier_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOUR),
stat_modifier_slider_(disp.video()),
stat_modifier_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOUR),
name_entry_label_(disp.video(), _("Name of game:"), font::SIZE_PLUS, font::LOBBY_COLOUR),
num_players_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOUR),
map_size_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOUR),
@ -180,6 +182,12 @@ create::create(game_display& disp, const config &cfg, chat& c, config& gamelist)
xp_modifier_slider_.set_increment(10);
xp_modifier_slider_.set_help_string(_("The amount of experience a unit needs to advance"));
stat_modifier_slider_.set_min(1);
stat_modifier_slider_.set_max(3);
xp_modifier_slider_.set_value(preferences::stat_modifier());
xp_modifier_slider_.set_increment(1);
xp_modifier_slider_.set_help_string(_("The factor the units' statistics are multiplied with"));
use_map_settings_.set_check(preferences::use_map_settings());
use_map_settings_.set_help_string(_("Use scenario specific settings"));
@ -258,6 +266,7 @@ create::~create()
preferences::set_random_start_time(parameters_.random_start_time);
preferences::set_village_gold(parameters_.village_gold);
preferences::set_xp_modifier(parameters_.xp_modifier);
preferences::set_stat_modifier(parameters_.stat_modifier);
}
}
@ -298,6 +307,7 @@ mp_game_settings& create::get_parameters()
parameters_.mp_countdown = countdown_game_.checked();
parameters_.village_gold = village_gold_slider_.value();
parameters_.xp_modifier = xp_modifier_slider_.value();
parameters_.stat_modifier = stat_modifier_slider_.value();
parameters_.use_map_settings = use_map_settings_.checked();
parameters_.random_start_time = random_start_time_.checked();
parameters_.fog_game = fog_game_.checked();
@ -415,6 +425,15 @@ void create::process_event()
xp_modifier_label_.set_text(buf.str());
// Stat modifier
const int statmod = stat_modifier_slider_.value();
buf.str("");
//TODO tiny not tiny?
buf << N_("Statistics Modifier: ") << statmod << "x";
stat_modifier_label_.set_text(buf.str());
bool map_changed = map_selection_ != maps_menu_.selection();
map_selection_ = maps_menu_.selection();
@ -568,6 +587,10 @@ void create::process_event()
settings::get_xp_modifier(parameters_.scenario_data["experience_modifier"]) :
preferences::xp_modifier());
stat_modifier_slider_.set_value(map_settings ?
settings::get_stat_modifier(parameters_.scenario_data["stat_modifier"]) :
preferences::stat_modifier());
random_start_time_.set_check(map_settings ?
settings::use_random_start_time(parameters_.scenario_data["random_start_time"]) :
preferences::random_start_time());
@ -601,6 +624,7 @@ void create::process_event()
turns_slider_.enable(!map_settings);
village_gold_slider_.enable(!map_settings);
xp_modifier_slider_.enable(!map_settings);
stat_modifier_slider_.enable(!map_settings);
random_start_time_.enable(!map_settings);
fog_game_.enable(!map_settings);
shroud_game_.enable(!map_settings);
@ -629,6 +653,8 @@ void create::hide_children(bool hide)
village_gold_label_.hide(hide);
xp_modifier_slider_.hide(hide);
xp_modifier_label_.hide(hide);
stat_modifier_slider_.hide(hide);
stat_modifier_label_.hide(hide);
name_entry_label_.hide(hide);
num_players_label_.hide(hide);
@ -768,6 +794,12 @@ void create::layout_children(const SDL_Rect& rect)
xp_modifier_slider_.set_location(xpos, ypos);
ypos += xp_modifier_slider_.height() + border_size;
stat_modifier_label_.set_location(xpos, ypos);
ypos += stat_modifier_label_.height() + border_size;
stat_modifier_slider_.set_width(ca.w - xpos);
stat_modifier_slider_.set_location(xpos, ypos);
ypos += stat_modifier_slider_.height() + border_size;
use_map_settings_.set_location(xpos, ypos);
fog_game_.set_location(xpos + (ca.w - xpos)/2 + 5, ypos);
ypos += use_map_settings_.height() + border_size;

View file

@ -75,6 +75,8 @@ private:
gui::label village_gold_label_;
gui::slider xp_modifier_slider_;
gui::label xp_modifier_label_;
gui::slider stat_modifier_slider_;
gui::label stat_modifier_label_;
gui::label name_entry_label_;
gui::label num_players_label_;

View file

@ -18,7 +18,6 @@
#include "log.hpp"
#include "map.hpp"
#include "pathfind/pathfind.hpp"
#include "pathfind/teleport.hpp"
#include "foreach.hpp"
#include <queue>
@ -79,34 +78,24 @@ struct node {
, in(bad_search_counter)
{
}
node(double s, const map_location &c, const map_location &p, const map_location &dst, bool i, const pathfind::teleport_map* teleports):
node(double s, const map_location &c, const map_location &p, const map_location &dst, bool i, const std::set<map_location>* teleports):
g(s), h(heuristic(c, dst)), t(g + h), curr(c), prev(p), in(search_counter + i)
{
if (teleports && !teleports->empty()) {
double new_srch = 1.0;
std::set<map_location> sources;
teleports->get_sources(sources);
std::set<map_location>::const_iterator it = sources.begin();
for(; it != sources.end(); ++it) {
const double tmp_srch = heuristic(c, *it);
if (tmp_srch < new_srch) { new_srch = tmp_srch; }
if (teleports != NULL) {
double srch = h, dsth = h;
std::set<map_location>::const_iterator i;
for(i = teleports->begin(); i != teleports->end(); ++i) {
const double new_srch = heuristic(c, *i);
const double new_dsth = heuristic(*i, dst);
if(new_srch < srch) {
srch = new_srch;
}
if(new_dsth < dsth) {
dsth = new_dsth;
}
}
double new_dsth = 1.0;
std::set<map_location> targets;
teleports->get_targets(targets);
for(it = targets.begin(); it != targets.end(); ++it) {
const double tmp_dsth = heuristic(*it, dst);
if (tmp_dsth < new_dsth) { new_dsth = tmp_dsth; }
}
double new_h = new_srch + new_dsth + 1.0;
if (new_h < h) {
h = new_h;
if(srch + dsth + 1.0 < h) {
h = srch + dsth + 1.0;
t = g + h;
}
}
@ -140,9 +129,8 @@ public:
pathfind::plain_route pathfind::a_star_search(const map_location& src, const map_location& dst,
double stop_at, const cost_calculator *calc, const size_t width,
const size_t height,
const teleport_map *teleports) {
double stop_at, const pathfind::cost_calculator *calc, const size_t width,
const size_t height, const std::set<map_location>* teleports) {
//----------------- PRE_CONDITIONS ------------------
assert(src.valid(width, height));
assert(dst.valid(width, height));
@ -159,6 +147,13 @@ pathfind::plain_route pathfind::a_star_search(const map_location& src, const map
return locRoute;
}
if (teleports && teleports->empty()) teleports = NULL;
std::vector<map_location> locs(teleports ? 6 + teleports->size() : 6 );
if (teleports) {
std::copy(teleports->begin(), teleports->end(), locs.begin() + 6);
}
// increment search_counter but skip the range equivalent to uninitialized
search_counter += 2;
if (search_counter - bad_search_counter <= 1u)
@ -186,26 +181,12 @@ pathfind::plain_route pathfind::a_star_search(const map_location& src, const map
if (n.t >= nodes[index(dst)].g) break;
std::vector<map_location> locs;
int i;
if (teleports && !teleports->empty()) {
std::set<map_location> allowed_teleports;
teleports->get_adjacents(allowed_teleports, n.curr);
i = allowed_teleports.size() +6;
locs = std::vector<map_location>(i);
std::copy(allowed_teleports.begin(), allowed_teleports.end(), locs.begin() + 6);
} else
{ locs = std::vector<map_location>(6); i = 6;}
get_adjacent_tiles(n.curr, &locs[0]);
int i = teleports && teleports->count(n.curr) ? locs.size() : 6;
for (; i-- > 0;) {
if (!locs[i].valid(width, height)) continue;
if (locs[i] == n.curr) continue;
node& next = nodes[index(locs[i])];
double thresh = (next.in - search_counter <= 1u) ? next.g : stop_at + 1;

View file

@ -21,7 +21,6 @@
#include "global.hpp"
#include "pathfind/pathfind.hpp"
#include "pathfind/teleport.hpp"
#include "foreach.hpp"
#include "gettext.hpp"
@ -104,6 +103,29 @@ bool pathfind::enemy_zoc(unit_map const &units, std::vector<team> const &teams,
return false;
}
std::set<map_location> pathfind::get_teleport_locations(const unit &u,
const unit_map &units, const team &viewing_team,
bool see_all, bool ignore_units)
{
std::set<map_location> res;
if (!u.get_ability_bool("teleport")) return res;
const team &current_team = (*resources::teams)[u.side() - 1];
const map_location &loc = u.get_location();
foreach (const map_location &l, current_team.villages())
{
// This must be a vacant village (or occupied by the unit)
// to be able to teleport.
if (!see_all && viewing_team.is_enemy(u.side()) && viewing_team.fogged(l))
continue;
if (!ignore_units && l != loc &&
get_visible_unit(units, l, viewing_team, see_all))
continue;
res.insert(l);
}
return res;
}
static unsigned search_counter;
namespace {
@ -170,13 +192,16 @@ static void find_routes(const gamemap& map, const unit_map& units,
bool see_all, bool ignore_units)
{
const team& current_team = teams[u.side() - 1];
pathfind::teleport_map teleports;
std::set<map_location> teleports;
if (allow_teleport) {
teleports = pathfind::get_teleport_locations(u, units, viewing_team, see_all, ignore_units);
}
const int total_movement = u.total_movement();
std::vector<map_location> locs(6 + teleports.size());
std::copy(teleports.begin(), teleports.end(), locs.begin() + 6);
search_counter += 2;
if (search_counter == 0) search_counter = 2;
@ -198,16 +223,10 @@ static void find_routes(const gamemap& map, const unit_map& units,
pq.pop_back();
n.in = search_counter;
std::set<map_location> allowed_teleports;
teleports.get_adjacents(allowed_teleports, n.curr);
std::vector<map_location> locs(6 + allowed_teleports.size());
std::copy(allowed_teleports.begin(), allowed_teleports.end(), locs.begin() + 6);
get_adjacent_tiles(n.curr, &locs[0]);
for (int i = locs.size(); i-- > 0; ) {
for (int i = teleports.count(n.curr) ? locs.size() : 6; i-- > 0; ) {
if (!locs[i].valid(map.w(), map.h())) continue;
if (locs[i] == n.curr) continue;
node& next = nodes[index(locs[i])];
bool next_visited = next.in - search_counter <= 1u;

View file

@ -35,7 +35,7 @@ class unit_movement_type;
namespace pathfind {
class teleport_map;
typedef std::set<map_location> teleport_map;
enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
@ -55,6 +55,9 @@ bool enemy_zoc(unit_map const &units,
std::vector<team> const &teams, map_location const &loc,
team const &viewing_team, int side, bool see_all=false);
std::set<map_location> get_teleport_locations(const unit &u,
const unit_map &units, const team &viewing_team,
bool see_all = false, bool ignore_units = false);
struct cost_calculator
{
@ -80,7 +83,7 @@ struct paths
// Construct a list of paths for the unit at loc.
// - force_ignore_zocs: find the path ignoring ZOC entirely,
// if false, will use the unit on the loc's ability
// - allow_teleport: indicates whether the paths should include teleportation (false for sight)
// - 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
// will be calculated, and so forth.
@ -147,7 +150,7 @@ struct plain_route
plain_route a_star_search(map_location const &src, map_location const &dst,
double stop_at, const cost_calculator* costCalculator,
const size_t parWidth, const size_t parHeight,
const teleport_map* teleports = NULL);
std::set<map_location> const *teleports = NULL);
/**
* Add marks on a route @a rt assuming that a @unit u travels along it.

View file

@ -1,230 +0,0 @@
/* $Id: teleport.cpp $ */
/*
Copyright (C) 2010 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "pathfind/teleport.hpp"
#include "serialization/string_utils.hpp"
#include "unit.hpp"
#include "log.hpp"
#include "resources.hpp"
#include "foreach.hpp"
static lg::log_domain log_engine("engine");
#define ERR_PF LOG_STREAM(err, log_engine)
namespace {
const std::string reversed_suffix = "-__REVERSED__";
}
// This constructor is *only* meant for loading from saves
pathfind::teleport_group::teleport_group(const config cfg) : cfg_(cfg, true), reversed_(utils::string_bool(cfg["reversed"], false)), id_(cfg["id"])
{
assert(cfg.has_attribute("id"));
assert(cfg.has_attribute("reversed"));
assert(!cfg_.get_children("source").empty());
assert(!cfg_.get_children("target").empty());
assert(!cfg_.get_children("filter").empty());
}
pathfind::teleport_group::teleport_group(vconfig cfg, bool reversed) : cfg_(cfg), reversed_(reversed), id_()
{
assert(!cfg_.get_children("source").empty());
assert(!cfg_.get_children("target").empty());
assert(!cfg_.get_children("filter").empty());
if (cfg["id"].empty()) {
id_ = resources::tunnels->next_unique_id();
} else {
id_ = cfg["id"];
if (reversed_) // Differentiate the reverse tunnel from the forward one
id_ += reversed_suffix;
}
}
void pathfind::teleport_group::get_teleport_pair(teleport_pair& loc_pair, const unit& u, bool ignore_units)
{
const map_location &loc = u.get_location();
static unit_map empty_unit_map;
unit_map *units;
if (ignore_units) {
units = &empty_unit_map;
} else {
units = resources::units;
}
if (u.matches_filter(cfg_.child("filter"), loc)) {
scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, *resources::units);
terrain_filter source_filter(cfg_.child("source"), *units);
source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first);
terrain_filter target_filter(cfg_.child("target"), *units);
target_filter.get_locations(reversed_ ? loc_pair.first : loc_pair.second);
}
}
const std::string& pathfind::teleport_group::get_teleport_id() const {
return id_;
}
bool pathfind::teleport_group::always_visible() const {
return utils::string_bool(cfg_["always_visible"], false);
}
config pathfind::teleport_group::to_config() const {
config retval = cfg_.get_config();
retval["reversed"] = reversed_ ? "yes" : "no";
retval["id"] = id_;
return retval;
}
pathfind::teleport_map::teleport_map(std::vector<teleport_group> groups, const unit& u, const unit_map &/*units*/, const team &viewing_team, bool see_all, bool ignore_units)
: teleport_map_(), sources_(), targets_() {
for (std::vector<teleport_group>::iterator it = groups.begin(); it != groups.end(); ++it) {
teleport_pair locations;
it->get_teleport_pair(locations, u, ignore_units);
if (!see_all && !it->always_visible() && viewing_team.is_enemy(u.side())) {
teleport_pair filter_locs;
foreach(const map_location &loc, locations.first)
if(!viewing_team.fogged(loc))
filter_locs.first.insert(loc);
foreach(const map_location &loc, locations.second)
if(!viewing_team.fogged(loc))
filter_locs.second.insert(loc);
locations.first.swap(filter_locs.first);
locations.second.swap(filter_locs.second);
}
std::string teleport_id = it->get_teleport_id();
std::set<map_location>::iterator source_it = locations.first.begin();
for (; source_it != locations.first.end(); ++source_it ) {
if(teleport_map_.count(*source_it) == 0) {
std::set<std::string> id_set;
id_set.insert(teleport_id);
teleport_map_.insert(std::make_pair(*source_it, id_set));
} else {
(teleport_map_.find(*source_it)->second).insert(teleport_id);
}
}
sources_.insert(std::make_pair(teleport_id, locations.first));
targets_.insert(std::make_pair(teleport_id, locations.second));
}
}
void pathfind::teleport_map::get_adjacents(std::set<map_location>& adjacents, map_location loc) const {
if (teleport_map_.count(loc) == 0) {
return;
} else {
const std::set<std::string>& keyset = (teleport_map_.find(loc)->second);
for(std::set<std::string>::const_iterator it = keyset.begin(); it != keyset.end(); ++it) {
const std::set<map_location>& target = targets_.find(*it)->second;
adjacents.insert(target.begin(), target.end());
}
}
}
void pathfind::teleport_map::get_sources(std::set<map_location>& sources) const {
std::map<std::string, std::set<map_location> >::const_iterator it;
for(it = sources_.begin(); it != sources_.end(); ++it) {
sources.insert(it->second.begin(), it->second.end());
}
}
void pathfind::teleport_map::get_targets(std::set<map_location>& targets) const {
std::map<std::string, std::set<map_location> >::const_iterator it;
for(it = targets_.begin(); it != targets_.end(); ++it) {
targets.insert(it->second.begin(), it->second.end());
}
}
const pathfind::teleport_map pathfind::get_teleport_locations(const unit &u,
const unit_map &units, const team &viewing_team,
bool see_all, bool ignore_units)
{
std::vector<teleport_group> groups;
if (u.get_ability_bool("teleport")) {
unit_ability_list teleport_list = u.get_abilities("teleport");
std::vector<std::pair<const config *, map_location> > teleports = teleport_list.cfgs;
std::vector<std::pair<const config *, map_location> >::const_iterator it = teleports.begin();
for(; it != teleports.end(); ++it) {
const int tunnel_count = (it->first)->child_count("tunnel");
for(int i = 0; i < tunnel_count; ++i) {
config teleport_group_cfg = (it->first)->child("tunnel", i);
teleport_group group = teleport_group(vconfig(teleport_group_cfg, true), false);
groups.push_back(group);
}
}
}
const std::vector<teleport_group>& global_groups = resources::tunnels->get();
groups.insert(groups.end(), global_groups.begin(), global_groups.end());
return teleport_map(groups, u, units, viewing_team, see_all, ignore_units);
}
pathfind::manager::manager(const config &cfg) : tunnels_(), id_(lexical_cast_default<int>(cfg["next_teleport_group_id"], 0)) {
const int tunnel_count = cfg.child_count("tunnel");
for(int i = 0; i < tunnel_count; ++i) {
const config& t = cfg.child("tunnel", i);
const pathfind::teleport_group tunnel(t);
this->add(tunnel);
}
}
void pathfind::manager::add(const teleport_group &group) {
tunnels_.push_back(group);
}
void pathfind::manager::remove(const std::string &id) {
std::vector<pathfind::teleport_group>::iterator t = tunnels_.begin();
for(;t != tunnels_.end();) {
if (t->get_teleport_id() == id || t->get_teleport_id() == id + reversed_suffix) {
t = tunnels_.erase(t);
} else {
++t;
}
}
}
const std::vector<pathfind::teleport_group>& pathfind::manager::get() const {
return tunnels_;
}
config pathfind::manager::to_config() const {
config store;
std::vector<pathfind::teleport_group>::const_iterator tunnel = tunnels_.begin();
for(; tunnel != tunnels_.end(); ++tunnel) {
store.add_child("tunnel", tunnel->to_config());
}
store["next_teleport_group_id"] = str_cast(id_);
return store;
}
std::string pathfind::manager::next_unique_id() {
return str_cast(++id_);
}

View file

@ -1,119 +0,0 @@
/* $Id: teleport.hpp $ */
/*
Copyright (C) 2010 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef TELEPORT_H_INCLUDED
#define TELEPORT_H_INCLUDED
#include "map.hpp"
#include "config.hpp"
#include "terrain_filter.hpp"
#include "savegame_config.hpp"
#include "pathfind/pathfind.hpp"
namespace pathfind {
typedef std::pair<std::set<map_location>, std::set<map_location> >
teleport_pair;
/*
* Represents the tunnel wml tag.
*/
class teleport_group: public savegame::savegame_config {
public:
/*
* Used to create the object from a saved file.
*/
teleport_group(const config cfg);
/*
*
*/
teleport_group(vconfig cfg, bool way_back = false);
/*
* Fills the argument loc_pair if the unit u matches the groups filter.
*/
void get_teleport_pair(teleport_pair& loc_pair, const unit& u, bool ignore_units);
/*
* Returns the unique id of the teleport group.
* Can be set by the id attribute or is randomly chosen.
*/
const std::string& get_teleport_id() const;
/*
* Returns whether the group should always be visible,
* even for enemy movement under shroud.
*/
bool always_visible() const;
config to_config() const;
private:
vconfig cfg_;
bool reversed_;
std::string id_;
};
class teleport_map {
public:
teleport_map(std::vector<teleport_group> teleport_groups, const unit& u,
const unit_map &units, const team &viewing_team, bool see_all,
bool ignore_units);
teleport_map() :
teleport_map_(), sources_(), targets_() {
}
;
void get_adjacents(std::set<map_location>& adjacents, map_location loc) const;
void get_sources(std::set<map_location>& sources) const;
void get_targets(std::set<map_location>& targets) const;
bool empty() const {
return sources_.empty();
}
private:
std::map<map_location, std::set<std::string> > teleport_map_;
std::map<std::string, std::set<map_location> > sources_;
std::map<std::string, std::set<map_location> > targets_;
};
//TODO clean up the interface
const teleport_map get_teleport_locations(const unit &u, const unit_map &units,
const team &viewing_team, bool see_all = false, bool ignore_units =
false);
class manager: public savegame::savegame_config {
public:
manager(const config &cfg);
void add(const teleport_group &group);
void remove(const std::string &id);
const std::vector<teleport_group>& get() const;
config to_config() const;
// For unique tunnel IDs
std::string next_unique_id();
private:
std::vector<teleport_group> tunnels_;
int id_;
};
}
#endif /* TELEPORT_H_INCLUDED */

View file

@ -26,7 +26,6 @@
#include "halo.hpp"
#include "loadscreen.hpp"
#include "log.hpp"
#include "pathfind/teleport.hpp"
#include "resources.hpp"
#include "savegame.hpp"
#include "sound.hpp"
@ -66,7 +65,6 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
menu_handler_(NULL, units_, teams_, level, map_, game_config, tod_manager_, state_of_game, undo_stack_, redo_stack_),
soundsources_manager_(),
tod_manager_(level, num_turns, &state_of_game),
pathfind_manager_(),
gui_(),
statistics_context_(level["name"]),
level_(level),
@ -77,6 +75,7 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
undo_stack_(),
redo_stack_(),
xp_mod_(atoi(level["experience_modifier"].c_str()) > 0 ? atoi(level["experience_modifier"].c_str()) : 100),
stat_mod_(atoi(level["stat_modifier"].c_str()) > 0 ? atoi(level["stat_modifier"].c_str()) : 1),
loading_game_(level["playing_team"].empty() == false),
first_human_team_(-1),
player_number_(1),
@ -121,7 +120,6 @@ play_controller::~play_controller()
resources::screen = NULL;
resources::soundsources = NULL;
resources::tod_manager = NULL;
resources::tunnels = NULL;
}
void play_controller::init(CVideo& video){
@ -198,7 +196,7 @@ void play_controller::init(CVideo& video){
LOG_NG << "initializing display... " << (SDL_GetTicks() - ticks_) << "\n";
const config &theme_cfg = get_theme(game_config_, level_["theme"]);
gui_.reset(new game_display(&units_, video, &map_, &tod_manager_, &teams_, theme_cfg, level_));
gui_.reset(new game_display(units_, video, map_, tod_manager_, teams_, theme_cfg, level_));
if (!gui_->video().faked()) {
if (gamestate_.mp_settings().mp_countdown)
gui_->get_theme().modify_label("time-icon", _ ("time left for current turn"));
@ -250,10 +248,8 @@ void play_controller::init_managers(){
prefs_disp_manager_.reset(new preferences::display_manager(gui_.get()));
tooltips_manager_.reset(new tooltips::manager(gui_->video()));
soundsources_manager_.reset(new soundsource::manager(*gui_));
pathfind_manager_.reset(new pathfind::manager(level_));
resources::soundsources = soundsources_manager_.get();
resources::tunnels = pathfind_manager_.get();
halo_manager_.reset(new halo::manager(*gui_));
LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks_) << "\n";
@ -615,7 +611,6 @@ config play_controller::to_config() const
//write out the current state of the map
cfg["map_data"] = map_.write();
cfg.merge_with(pathfind_manager_->to_config());
return cfg;
}
@ -902,11 +897,13 @@ void play_controller::process_keyup_event(const SDL_Event& event) {
const unit_map::iterator u = mouse_handler_.selected_unit();
if(u != units_.end()) {
bool teleport = u->get_ability_bool("teleport");
// if it's not the unit's turn, we reset its moves
unit_movement_resetter move_reset(*u, u->side() != player_number_);
mouse_handler_.set_current_paths(pathfind::paths(map_, units_, u->get_location(),
teams_,false,true, teams_[gui_->viewing_team()],
teams_,false,teleport, teams_[gui_->viewing_team()],
mouse_handler_.get_path_turns()));
gui_->highlight_reach(mouse_handler_.current_paths());

View file

@ -53,9 +53,6 @@ namespace soundsource {
class manager;
} // namespace soundsource
namespace pathfind {
class manager;
}
namespace tooltips {
struct manager;
@ -198,7 +195,6 @@ protected:
events::menu_handler menu_handler_;
boost::scoped_ptr<soundsource::manager> soundsources_manager_;
tod_manager tod_manager_;
boost::scoped_ptr<pathfind::manager> pathfind_manager_;
//other objects
boost::scoped_ptr<game_display> gui_;
@ -212,6 +208,7 @@ protected:
undo_list redo_stack_;
const unit_type::experience_accelerator xp_mod_;
const unit_type::stat_accelerator stat_mod_;
//if a team is specified whose turn it is, it means we're loading a game
//instead of starting a fresh one. Gets reset to false after init_side
bool loading_game_;

View file

@ -559,11 +559,17 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
gamestate.write_snapshot(next_cfg);
next_cfg["next_scenario"] = (*scenario)["next_scenario"];
next_cfg.add_child("snapshot");
gamestate.starting_pos = *scenario;
//move the player information into the hosts gamestate
write_players(gamestate, gamestate.starting_pos, true, true);
write_players(gamestate, starting_pos, true, true);
gamestate.starting_pos = *scenario;
next_cfg.add_child("multiplayer", gamestate.mp_settings().to_config());
next_cfg.add_child("replay_start", gamestate.starting_pos);
//move side information from gamestate into the config that is sent to the other clients
next_cfg.clear_children("side");
foreach (config& side, gamestate.starting_pos.child_range("side"))
next_cfg.add_child("side", side);
network::send_data(cfg, 0, true);
}
}

View file

@ -25,5 +25,4 @@ namespace resources
LuaKernel *lua_kernel;
play_controller *controller;
::tod_manager *tod_manager;
pathfind::manager *tunnels;
}

View file

@ -28,9 +28,6 @@ class unit_map;
namespace soundsource { class manager; }
namespace pathfind { class manager; }
namespace resources
{
extern game_display *screen;
@ -42,7 +39,6 @@ namespace resources
extern LuaKernel *lua_kernel;
extern play_controller *controller;
extern tod_manager *tod_manager;
extern pathfind::manager *tunnels;
}
#endif

View file

@ -49,7 +49,6 @@ extern "C" {
#include "log.hpp"
#include "map.hpp"
#include "pathfind/pathfind.hpp"
#include "pathfind/teleport.hpp"
#include "play_controller.hpp"
#include "resources.hpp"
#include "terrain_translation.hpp"

View file

@ -49,6 +49,11 @@ int get_xp_modifier(const std::string& value)
return lexical_cast_in_range<int>(value, 70, 30, 200);
}
int get_stat_modifier(const std::string& value)
{
return lexical_cast_in_range<int>(value, 1, 1, 3);
}
bool use_fog(const std::string& value)
{
return utils::string_bool(value, true);

View file

@ -70,6 +70,20 @@ namespace settings {
*/
int get_xp_modifier(const std::string& value);
/**
* Gets the stat modifier.
* If no valid value supplied, it will return a default.
* The value is also range checked.
* When out of bounds, it will be set to the nearest bound.
*
* @param value string containing the stat modifier
*
* @returns the stat modifier
*/
int get_stat_modifier(const std::string& value);
/**
* Returns whether the fog of war should be used.
* If no valid value is supplied, it will return a default.

View file

@ -302,13 +302,10 @@ void team::write(config& cfg) const
cfg["action_bonus_count"] = action_bonus_count_;
}
bool team::get_village(const map_location& loc, const bool fire_event)
bool team::get_village(const map_location& loc)
{
villages_.insert(loc);
if (fire_event)
return game_events::fire("capture",loc);
//TODO better false? Or is that a hack at all?
return true;
return game_events::fire("capture",loc);
}
void team::lose_village(const map_location& loc)

View file

@ -118,7 +118,7 @@ public:
void write(config& cfg) const;
bool get_village(const map_location&, const bool fire_event = true);
bool get_village(const map_location&);
void lose_village(const map_location&);
void clear_villages() { villages_.clear(); }
const std::set<map_location>& villages() const { return villages_; }

View file

@ -64,8 +64,8 @@ namespace test_utils {
dummy_tod_(dummy_cfg_, 0),
dummy_teams_(),
main_event_context_(),
disp_(&dummy_umap_, video_, &dummy_map_, &dummy_tod_,
&dummy_teams_, dummy_cfg_, dummy_cfg_)
disp_(dummy_umap_, video_, dummy_map_, dummy_tod_,
dummy_teams_, dummy_cfg_, dummy_cfg_)
{
}

View file

@ -287,8 +287,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
side_ = 1;
}
//TODO enable agian
// validate_side(side_);
validate_side(side_);
underlying_id_ = lexical_cast_default<size_t>(cfg["underlying_id"],0);
set_underlying_id();
@ -551,7 +550,7 @@ void unit::clear_status_caches()
}
unit::unit(const unit_type *t, int side, bool real_unit,
unit_race::GENDER gender, bool canrecruit) :
unit_race::GENDER gender) :
cfg_(),
loc_(),
advances_to_(),
@ -568,7 +567,7 @@ unit::unit(const unit_type *t, int side, bool real_unit,
experience_(0),
max_experience_(0),
level_(0),
canrecruit_(canrecruit),
canrecruit_(false),
alignment_(),
flag_rgb_(),
image_mods_(),

View file

@ -71,7 +71,7 @@ public:
* (to prevent OOS caused by RNG calls)
*/
unit(const unit_type* t, int side, bool real_unit,
unit_race::GENDER gender=unit_race::NUM_GENDERS, bool canrecruit = false);
unit_race::GENDER gender = unit_race::NUM_GENDERS);
virtual ~unit();
unit& operator=(const unit&);

View file

@ -46,7 +46,7 @@ class effect
effect(const unit_ability_list& list, int def, bool backstab);
int get_composite_value() const
{ return composite_value_; }
{ return composite_value_ ;}
effect_list::const_iterator begin() const
{ return effect_list_.begin(); }
effect_list::const_iterator end() const

View file

@ -34,7 +34,6 @@ unit_map::unit_map(const unit_map& that) :
num_invalid_(0)
{
for (const_unit_iterator i = that.begin(); i != that.end(); i++) {
i->set_game_context(this);
add(i->get_location(), *i);
}
}
@ -43,14 +42,6 @@ unit_map &unit_map::operator=(const unit_map &that)
{
unit_map temp(that);
swap(temp);
for (unit_iterator i = begin(); i != end(); i++) {
//TODO
// unit u = *i;
i->set_game_context(this);
// add(i->get_location(), *i);
// add(i->get_location(), u);
}
return *this;
}

View file

@ -252,9 +252,6 @@ public:
void swap(unit_map& o);
//TODO move to the right location and comment!
void write(config& cfg) const;
private:
/** Removes invalid entries in map_ if safe and needed. */
void clean_invalid();

View file

@ -39,6 +39,11 @@ static lg::log_domain log_config("config");
static lg::log_domain log_unit("unit");
#define DBG_UT LOG_STREAM(debug, log_unit)
namespace {
int stat_modifier = 1;
}
attack_type::attack_type(const config& cfg) :
aloc_(),
dloc_(),
@ -95,6 +100,12 @@ std::string attack_type::accuracy_parry_description() const
return s.str();
}
int attack_type::num_attacks() const
{
int attacks = (num_attacks_ * stat_modifier);
return attacks;
}
bool attack_type::matches_filter(const config& cfg,bool self) const
{
const std::vector<std::string>& filter_range = utils::split(cfg["range"]);
@ -994,6 +1005,33 @@ int unit_type::experience_needed(bool with_acceleration) const
return experience_needed_;
}
unit_type::stat_accelerator::stat_accelerator(int modifier) : old_value_(stat_modifier)
{
stat_modifier = modifier;
}
unit_type::stat_accelerator::~stat_accelerator()
{
stat_modifier = old_value_;
}
int unit_type::stat_accelerator::get_acceleration()
{
return stat_modifier;
}
int unit_type::hitpoints() const
{
int hp = (hitpoints_ * stat_modifier);
return hp;
}
const char* unit_type::alignment_description(unit_type::ALIGNMENT align, unit_race::GENDER gender)
{
static const char* aligns[] = { N_("lawful"), N_("neutral"), N_("chaotic") };

View file

@ -46,7 +46,7 @@ public:
int accuracy() const { return accuracy_; }
int parry() const { return parry_; }
int damage() const { return damage_; }
int num_attacks() const { return num_attacks_; }
int num_attacks() const;// { return num_attacks_; }
double attack_weight() const { return attack_weight_; }
double defense_weight() const { return defense_weight_; }
@ -204,7 +204,7 @@ public:
// NOTE: this used to be a const object reference, but it messed up with the
// translation engine upon changing the language in the same session.
const t_string unit_description() const;
int hitpoints() const { return hitpoints_; }
int hitpoints() const;
int level() const { return level_; }
int movement() const { return movement_; }
int max_attacks() const { return max_attacks_; }
@ -230,6 +230,14 @@ public:
int old_value_;
};
struct stat_accelerator {
stat_accelerator(int modifier);
~stat_accelerator();
static int get_acceleration();
private:
int old_value_;
};
enum ALIGNMENT { LAWFUL, NEUTRAL, CHAOTIC };
ALIGNMENT alignment() const { return alignment_; }