Skip to content
Browse files

Initial commit of src folder only from Battle for Wesnoth. Taken dire…

…ctly from the trunk repository, revision 49424. This is shortly before 1.9.9.
  • Loading branch information...
1 parent b863f27 commit d9f9a4336e44ae0ba02bfd990e06201184a6f271 @jnicholl jnicholl committed Oct 3, 2011
Showing with 19,689 additions and 0 deletions.
  1. +840 −0 src/CMakeLists.txt
  2. +557 −0 src/SConscript
  3. +4 −0 src/SConstruct
  4. +361 −0 src/about.cpp
  5. +36 −0 src/about.hpp
  6. +2,774 −0 src/actions.cpp
  7. +417 −0 src/actions.hpp
  8. +1,518 −0 src/addon/manager.cpp
  9. +76 −0 src/addon/manager.hpp
  10. +140 −0 src/addon/validation.cpp
  11. +66 −0 src/addon/validation.hpp
  12. +4 −0 src/ai/SConstruct
  13. +1,172 −0 src/ai/actions.cpp
  14. +404 −0 src/ai/actions.hpp
  15. +216 −0 src/ai/composite/ai.cpp
  16. +137 −0 src/ai/composite/ai.hpp
  17. +152 −0 src/ai/composite/aspect.cpp
  18. +433 −0 src/ai/composite/aspect.hpp
  19. +277 −0 src/ai/composite/component.cpp
  20. +101 −0 src/ai/composite/component.hpp
  21. +58 −0 src/ai/composite/contexts.cpp
  22. +156 −0 src/ai/composite/contexts.hpp
  23. +141 −0 src/ai/composite/engine.cpp
  24. +166 −0 src/ai/composite/engine.hpp
  25. +138 −0 src/ai/composite/engine_default.cpp
  26. +54 −0 src/ai/composite/engine_default.hpp
  27. +155 −0 src/ai/composite/engine_fai.cpp
  28. +53 −0 src/ai/composite/engine_fai.hpp
  29. +212 −0 src/ai/composite/engine_lua.cpp
  30. +76 −0 src/ai/composite/engine_lua.hpp
  31. +295 −0 src/ai/composite/goal.cpp
  32. +215 −0 src/ai/composite/goal.hpp
  33. +247 −0 src/ai/composite/property_handler.hpp
  34. +110 −0 src/ai/composite/rca.cpp
  35. +202 −0 src/ai/composite/rca.hpp
  36. +153 −0 src/ai/composite/stage.cpp
  37. +163 −0 src/ai/composite/stage.hpp
  38. +418 −0 src/ai/composite/value_translator.hpp
  39. +503 −0 src/ai/configuration.cpp
  40. +162 −0 src/ai/configuration.hpp
  41. +1,164 −0 src/ai/contexts.cpp
  42. +1,530 −0 src/ai/contexts.hpp
  43. +982 −0 src/ai/default/ai.cpp
  44. +156 −0 src/ai/default/ai.hpp
  45. +343 −0 src/ai/default/attack.cpp
  46. +313 −0 src/ai/default/contexts.cpp
  47. +299 −0 src/ai/default/contexts.hpp
  48. +1,050 −0 src/ai/formula/ai.cpp
  49. +164 −0 src/ai/formula/ai.hpp
  50. +326 −0 src/ai/formula/callable_objects.cpp
Sorry, we could not display the entire diff because too many files (928) changed.
View
840 src/CMakeLists.txt
@@ -0,0 +1,840 @@
+## some includes ##
+if(MSVC)
+ # This seems to break on some Linux systems in combination with strict
+ # compilation, so disabled for now. The problem occurred on Gentoo with
+ # boost 1.37. Debian with boost 1.34, 1.35 and 1.38 works properly.
+ include_directories( ${Boost_INCLUDE_DIR} )
+
+ #additional MSVC includes
+ include_directories( ${PANGO_INCLUDE_DIR} )
+ include_directories( ${CAIRO_INCLUDE_DIR} )
+ include_directories( ${GLIB_INCLUDE_DIR} )
+ include_directories( ${GLIBCONFIG_INCLUDE_PATH} )
+else(MSVC)
+ include_directories( ${FONTCONFIG_INCLUDE_DIRS} )
+endif(MSVC)
+
+
+include_directories( ${SDL_INCLUDE_DIR} )
+include_directories( ${PANGOCAIRO_INCLUDE_DIRS} )
+include_directories( ${GETTEXT_INCLUDE_DIR} )
+include_directories( ${LIBDBUS_INCLUDE_DIRS} )
+include_directories( ${LIBINTL_INCLUDE_DIR} )
+
+#optional dependencies
+if(SDLIMAGE_INCLUDE_DIR)
+ include_directories( ${SDLIMAGE_INCLUDE_DIR} )
+endif()
+if(SDLMIXER_INCLUDE_DIR)
+ include_directories( ${SDLMIXER_INCLUDE_DIR} )
+endif()
+if(SDLNET_INCLUDE_DIR)
+ include_directories( ${SDLNET_INCLUDE_DIR} )
+endif()
+if(SDLTTF_INCLUDE_DIR)
+ include_directories( ${SDLTTF_INCLUDE_DIR} )
+endif()
+if(ZLIB_INCLUDE_DIR)
+ include_directories( ${ZLIB_INCLUDE_DIR} )
+endif()
+
+set(network_implementation_files network.cpp network_worker.cpp)
+
+if(USE_ANA_NETWORK)
+ set(network_implementation_files network_ana.cpp network_manager_ana.cpp)
+ message(STATUS "Compiling network module with ana: ${network_implementation_files}")
+
+ set(ANA_LIBRARIES ana-static)
+
+ add_subdirectory(ana/src)
+endif(USE_ANA_NETWORK)
+
+# needed to get include paths in the subfolders correct
+include_directories( ${CMAKE_SOURCE_DIR}/src/ )
+# needed to have the generated config.h used, too
+include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
+
+link_directories(${Boost_LIBRARY_DIRS})
+
+if(MSVC)
+ # Since MSVC does autolinking of boost adding those files will duplicate
+ # the includes and cause build errors.
+ set(common-external-libs
+ ${SDL_LIBRARY}
+ ${SDLMAIN_LIBRARY}
+ ${LIBINTL_LIBRARY}
+ ws2_32.lib
+ )
+else(MSVC)
+ set(common-external-libs
+ ${SDL_LIBRARY}
+ ${Boost_IOSTREAMS_LIBRARY}
+ ${Boost_REGEX_LIBRARY}
+ )
+endif(MSVC)
+
+set(game-external-libs
+ ${common-external-libs}
+ ${SDLIMAGE_LIBRARY}
+ ${SDLMIXER_LIBRARY}
+ ${ANA_LIBRARIES}
+ ${SDLTTF_LIBRARY}
+ ${PANGOCAIRO_LIBRARIES}
+ ${FONTCONFIG_LIBRARIES}
+ ${LIBDBUS_LIBRARIES}
+ ${LIBINTL_LIBRARIES}
+)
+
+if(MSVC)
+ set(game-external-libs
+ ${game-external-libs}
+ ${PANGO_LIBRARY}
+ ${PANGOCAIRO_LIBRARY}
+ ${CAIRO_LIBRARY}
+ ${GOBJECT_LIBRARY}
+ )
+else(MSVC)
+ set(game-external-libs
+ ${game-external-libs}
+ ${Boost_SYSTEM_LIBRARIES}
+ )
+endif(MSVC)
+
+if(USE_ANA_NETWORK)
+ set(server-external-libs
+ ${common-external-libs}
+ ${ANA_LIBRARIES}
+)
+else(USE_ANA_NETWORK)
+ set(server-external-libs
+ ${common-external-libs}
+ ${SDLNET_LIBRARY}
+ )
+ set(game-external-libs
+ ${game-external-libs}
+ ${SDLNET_LIBRARY}
+ )
+endif(USE_ANA_NETWORK)
+
+set(tools-external-libs
+ ${common-external-libs}
+ ${SDLIMAGE_LIBRARY}
+)
+
+if(ENABLE_FRIBIDI AND FRIBIDI_LIBRARIES)
+ include_directories( ${FRIBIDI_INCLUDE_DIR} )
+ set(game-external-libs ${game-external-libs} ${FRIBIDI_LIBRARIES})
+endif(ENABLE_FRIBIDI AND FRIBIDI_LIBRARIES)
+
+if(X11_FOUND)
+ include_directories( ${X11_INCLUDE_DIR} )
+ set(game-external-libs ${game-external-libs} ${X11_LIBRARIES})
+endif(X11_FOUND)
+#
+# Create targets for revision.hpp
+#
+
+find_program(SVNVERSION_EXECUTABLE "svnversion")
+
+set(REVISION_FILE)
+if(SVNVERSION_EXECUTABLE)
+ execute_process(COMMAND ${SVNVERSION_EXECUTABLE} -n ${CMAKE_SOURCE_DIR}
+ OUTPUT_VARIABLE SVN_VERSION)
+ if(SVN_VERSION MATCHES [0-9]+.*)
+ add_custom_target(update_revision ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DSVNVERSION_EXECUTABLE="${SVNVERSION_EXECUTABLE}"
+ -DSRC_DIR="${CMAKE_SOURCE_DIR}"
+ -P "${CMAKE_MODULE_PATH}/revision.cmake"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Updating revision")
+
+ set(REVISION_FILE revision.hpp)
+ set_source_files_properties(
+ revision.hpp
+ PROPERTIES GENERATED true)
+ add_definitions(-DHAVE_REVISION)
+ endif(SVN_VERSION MATCHES [0-9]+.*)
+endif(SVNVERSION_EXECUTABLE)
+
+if(MSVC)
+ SOURCE_GROUP("src" REGULAR_EXPRESSION ".*")
+ SOURCE_GROUP("src ai" REGULAR_EXPRESSION "ai/.*")
+ SOURCE_GROUP("src ai composite" REGULAR_EXPRESSION "ai/composite/.*")
+ SOURCE_GROUP("src ai default" REGULAR_EXPRESSION "ai/default/.*")
+ SOURCE_GROUP("src ai dfool" REGULAR_EXPRESSION "ai/dfool/.*")
+ SOURCE_GROUP("src ai formula" REGULAR_EXPRESSION "ai/formula/.*")
+ SOURCE_GROUP("src ai testing" REGULAR_EXPRESSION "ai/testing/.*")
+ SOURCE_GROUP("src campaign_server" REGULAR_EXPRESSION "campaign_server/.*")
+ SOURCE_GROUP("src editor" REGULAR_EXPRESSION "editor/.*")
+ SOURCE_GROUP("src gui" REGULAR_EXPRESSION "gui/.*")
+ SOURCE_GROUP("src gui auxiliary" REGULAR_EXPRESSION "gui/auxiliary/.*")
+ SOURCE_GROUP("src gui auxiliary event" REGULAR_EXPRESSION "gui/auxiliary/event/.*")
+ SOURCE_GROUP("src gui auxiliary widget_definition" REGULAR_EXPRESSION "gui/auxiliary/widget_definition/.*")
+ SOURCE_GROUP("src gui auxiliary window_builder" REGULAR_EXPRESSION "gui/auxiliary/window_builder/.*")
+ SOURCE_GROUP("src gui dialogs" REGULAR_EXPRESSION "gui/dialogs/.*")
+ SOURCE_GROUP("src gui dialogs lobby" REGULAR_EXPRESSION "gui/dialogs/lobby/.*")
+ SOURCE_GROUP("src lua" REGULAR_EXPRESSION "lua/.*")
+ SOURCE_GROUP("src widgets" REGULAR_EXPRESSION "widgets/.*")
+ SOURCE_GROUP("src gui widgets" REGULAR_EXPRESSION "gui/widgets/.*")
+ SOURCE_GROUP("src pathfind" REGULAR_EXPRESSION "pathfind/.*")
+ SOURCE_GROUP("src scripting" REGULAR_EXPRESSION "scripting/.*")
+ SOURCE_GROUP("src serialization" REGULAR_EXPRESSION "serialization/.*")
+ SOURCE_GROUP("src server" REGULAR_EXPRESSION "server/.*")
+ SOURCE_GROUP("src storyscreen" REGULAR_EXPRESSION "storyscreen/.*")
+ SOURCE_GROUP("src tests" REGULAR_EXPRESSION "tests/.*")
+ SOURCE_GROUP("src tests gui" REGULAR_EXPRESSION "tests/gui/.*")
+ SOURCE_GROUP("src tests utils" REGULAR_EXPRESSION "tests/utils/.*")
+ SOURCE_GROUP("src tools" REGULAR_EXPRESSION "tools/.*")
+ SOURCE_GROUP("src tools" REGULAR_EXPRESSION "tools/.*")
+ SOURCE_GROUP("src whiteboard" REGULAR_EXPRESSION "whiteboard/.*")
+
+endif(MSVC)
+
+
+########### libwesnoth-core ###############
+
+set(libwesnoth-core_STAT_SRC
+ color_range.cpp
+ config.cpp
+ filesystem.cpp
+ game_config.cpp
+ gettext.cpp
+ hash.cpp
+ log.cpp
+ map.cpp
+ map_location.cpp
+ md5.cpp
+ thread.cpp
+ tstring.cpp
+ util.cpp
+ version.cpp
+ serialization/binary_or_text.cpp
+ serialization/parser.cpp
+ serialization/preprocessor.cpp
+ serialization/string_utils.cpp
+ serialization/tokenizer.cpp
+ ${REVISION_FILE}
+)
+
+if(ENABLE_POOL_ALLOC AND NOT WIN32)
+ set(libwesnoth-core_STAT_SRC
+ ${libwesnoth-core_STAT_SRC}
+ malloc.c
+ poolalloc.c
+ )
+endif(ENABLE_POOL_ALLOC AND NOT WIN32)
+
+# a 'lib' is automatically set in front when creating the library (as in the filename)
+# internal reference is the name given here
+add_library(wesnoth-core STATIC EXCLUDE_FROM_ALL ${libwesnoth-core_STAT_SRC})
+
+if(SVNVERSION_EXECUTABLE)
+ add_dependencies(wesnoth-core update_revision)
+endif(SVNVERSION_EXECUTABLE)
+
+########### libwesnoth-lua ###############
+
+set(libwesnoth-lua_STAT_SRC
+ lua_jailbreak_exception.cpp
+ lua/lapi.c
+ lua/lcode.c
+ lua/ldebug.c
+ lua/ldo.c
+ lua/ldump.c
+ lua/lfunc.c
+ lua/lgc.c
+ lua/llex.c
+ lua/lmem.c
+ lua/lobject.c
+ lua/lopcodes.c
+ lua/lparser.c
+ lua/lstate.c
+ lua/lstring.c
+ lua/ltable.c
+ lua/ltm.c
+ lua/lundump.c
+ lua/lvm.c
+ lua/lzio.c
+ lua/lauxlib.c
+ lua/lbaselib.c
+ lua/ldblib.c
+ lua/liolib.c
+ lua/lmathlib.c
+ lua/loslib.c
+ lua/ltablib.c
+ lua/lstrlib.c
+ lua/loadlib.c
+ lua/linit.c
+)
+# We explicitly want lua compiled as C++ version, so this line is required:
+set_source_files_properties(${libwesnoth-lua_STAT_SRC} PROPERTIES LANGUAGE CXX)
+
+if(UNIX AND NOT CMAKE_COMPILER_IS_GNUCXX)
+ # Assume the compiler is the clang compiler.
+ # It needs the files to be forced as c++ manually, it might be a newer
+ # version of cmake will be able to this for us.
+ set_source_files_properties(${libwesnoth-lua_STAT_SRC} PROPERTIES COMPILE_FLAGS "-x c++")
+endif(UNIX AND NOT CMAKE_COMPILER_IS_GNUCXX)
+
+# a 'lib' is automatically set in front when creating the library (as in the filename)
+# internal reference is the name given here
+add_library(wesnoth-lua STATIC EXCLUDE_FROM_ALL ${libwesnoth-lua_STAT_SRC})
+
+
+########### Wesnoth main source files ###############
+
+# Depending on whether the game or the game and the tests are build the main
+# sources are compiled in the game library or not. If only one target is needed
+# the putting in the game library solution is slower. If both targets are build
+# the library is faster (especially if the user doesn't use ccache (or
+# something similar)).
+
+set(wesnoth-main_SRC
+ about.cpp
+ actions.cpp
+ addon/manager.cpp
+ addon/validation.cpp
+ ai/actions.cpp
+ ai/composite/ai.cpp
+ ai/composite/aspect.cpp
+ ai/composite/component.cpp
+ ai/composite/contexts.cpp
+ ai/composite/engine.cpp
+ ai/composite/engine_default.cpp
+ ai/composite/engine_fai.cpp
+ ai/composite/engine_lua.cpp
+ ai/composite/goal.cpp
+ ai/composite/rca.cpp
+ ai/composite/stage.cpp
+ ai/configuration.cpp
+ ai/contexts.cpp
+ ai/default/ai.cpp
+ ai/default/attack.cpp
+ ai/default/contexts.cpp
+ ai/formula/ai.cpp
+ ai/formula/callable_objects.cpp
+ ai/formula/candidates.cpp
+ ai/formula/function_table.cpp
+ ai/formula/stage_side_formulas.cpp
+ ai/formula/stage_unit_formulas.cpp
+ ai/game_info.cpp
+ ai/gamestate_observer.cpp
+ ai/interface.cpp
+ ai/lua/core.cpp
+ ai/manager.cpp
+ ai/registry.cpp
+ ai/testing.cpp
+ ai/testing/aspect_attacks.cpp
+ ai/testing/ca.cpp
+ ai/testing/ca_global_fallback.cpp
+ ai/testing/ca_testing_move_to_targets.cpp
+ ai/testing/ca_testing_recruitment.cpp
+ ai/testing/stage_fallback.cpp
+ ai/testing/stage_rca.cpp
+ animated_game.cpp
+ attack_prediction.cpp
+ attack_prediction_display.cpp
+ callable_objects.cpp
+ config_cache.cpp
+ controller_base.cpp
+ dialogs.cpp
+ editor/action.cpp
+ editor/brush.cpp
+ editor/editor_controller.cpp
+ editor/editor_display.cpp
+ editor/editor_layout.cpp
+ editor/editor_main.cpp
+ editor/editor_map.cpp
+ editor/editor_palettes.cpp
+ editor/editor_preferences.cpp
+ editor/map_context.cpp
+ editor/map_fragment.cpp
+ editor/mouse_action.cpp
+ floating_textbox.cpp
+ formula.cpp
+ formula_debugger.cpp
+ formula_debugger_fwd.cpp
+ formula_function.cpp
+ formula_string_utils.cpp
+ formula_tokenizer.cpp
+ game_display.cpp
+ game_errors.cpp
+ game_events.cpp
+ game_preferences.cpp
+ game_preferences_display.cpp
+ gamestatus.cpp
+ generic_event.cpp
+ gui/auxiliary/canvas.cpp
+ gui/auxiliary/event/dispatcher.cpp
+ gui/auxiliary/event/distributor.cpp
+ gui/auxiliary/event/handler.cpp
+ gui/auxiliary/iterator/iterator.cpp
+ gui/auxiliary/iterator/walker_grid.cpp
+ gui/auxiliary/iterator/walker_widget.cpp
+ gui/auxiliary/log.cpp
+ gui/auxiliary/old_markup.cpp
+ gui/auxiliary/timer.cpp
+ gui/auxiliary/tips.cpp
+ gui/auxiliary/widget_definition.cpp
+ gui/auxiliary/widget_definition/button.cpp
+ gui/auxiliary/widget_definition/drawing.cpp
+ gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
+ gui/auxiliary/widget_definition/image.cpp
+ gui/auxiliary/widget_definition/label.cpp
+ gui/auxiliary/widget_definition/listbox.cpp
+ gui/auxiliary/widget_definition/minimap.cpp
+ gui/auxiliary/widget_definition/multi_page.cpp
+ gui/auxiliary/widget_definition/panel.cpp
+ gui/auxiliary/widget_definition/progress_bar.cpp
+ gui/auxiliary/widget_definition/repeating_button.cpp
+ gui/auxiliary/widget_definition/scroll_label.cpp
+ gui/auxiliary/widget_definition/scrollbar_panel.cpp
+ gui/auxiliary/widget_definition/slider.cpp
+ gui/auxiliary/widget_definition/spacer.cpp
+ gui/auxiliary/widget_definition/stacked_widget.cpp
+ gui/auxiliary/widget_definition/text_box.cpp
+ gui/auxiliary/widget_definition/toggle_button.cpp
+ gui/auxiliary/widget_definition/toggle_panel.cpp
+ gui/auxiliary/widget_definition/tree_view.cpp
+ gui/auxiliary/widget_definition/vertical_scrollbar.cpp
+ gui/auxiliary/widget_definition/window.cpp
+ gui/auxiliary/window_builder.cpp
+ gui/auxiliary/window_builder/button.cpp
+ gui/auxiliary/window_builder/control.cpp
+ gui/auxiliary/window_builder/drawing.cpp
+ gui/auxiliary/window_builder/helper.cpp
+ gui/auxiliary/window_builder/horizontal_listbox.cpp
+ gui/auxiliary/window_builder/horizontal_scrollbar.cpp
+ gui/auxiliary/window_builder/image.cpp
+ gui/auxiliary/window_builder/label.cpp
+ gui/auxiliary/window_builder/listbox.cpp
+ gui/auxiliary/window_builder/minimap.cpp
+ gui/auxiliary/window_builder/multi_page.cpp
+ gui/auxiliary/window_builder/panel.cpp
+ gui/auxiliary/window_builder/password_box.cpp
+ gui/auxiliary/window_builder/progress_bar.cpp
+ gui/auxiliary/window_builder/repeating_button.cpp
+ gui/auxiliary/window_builder/scroll_label.cpp
+ gui/auxiliary/window_builder/scrollbar_panel.cpp
+ gui/auxiliary/window_builder/slider.cpp
+ gui/auxiliary/window_builder/spacer.cpp
+ gui/auxiliary/window_builder/stacked_widget.cpp
+ gui/auxiliary/window_builder/text_box.cpp
+ gui/auxiliary/window_builder/toggle_button.cpp
+ gui/auxiliary/window_builder/toggle_panel.cpp
+ gui/auxiliary/window_builder/tree_view.cpp
+ gui/auxiliary/window_builder/vertical_scrollbar.cpp
+ gui/dialogs/addon/description.cpp
+ gui/dialogs/addon_connect.cpp
+ gui/dialogs/addon_list.cpp
+ gui/dialogs/campaign_difficulty.cpp
+ gui/dialogs/campaign_selection.cpp
+ gui/dialogs/data_manage.cpp
+ gui/dialogs/debug_clock.cpp
+ gui/dialogs/dialog.cpp
+ gui/dialogs/edit_label.cpp
+ gui/dialogs/editor_generate_map.cpp
+ gui/dialogs/editor_new_map.cpp
+ gui/dialogs/editor_resize_map.cpp
+ gui/dialogs/editor_settings.cpp
+ gui/dialogs/formula_debugger.cpp
+ gui/dialogs/game_delete.cpp
+ gui/dialogs/game_load.cpp
+ gui/dialogs/game_save.cpp
+ gui/dialogs/gamestate_inspector.cpp
+ gui/dialogs/language_selection.cpp
+ gui/dialogs/lobby/lobby_data.cpp
+ gui/dialogs/lobby/lobby_info.cpp
+ gui/dialogs/lobby_main.cpp
+ gui/dialogs/lobby_player_info.cpp
+ gui/dialogs/message.cpp
+ gui/dialogs/mp_change_control.cpp
+ gui/dialogs/mp_cmd_wrapper.cpp
+ gui/dialogs/mp_connect.cpp
+ gui/dialogs/mp_create_game.cpp
+ gui/dialogs/mp_create_game_set_password.cpp
+ gui/dialogs/mp_login.cpp
+ gui/dialogs/mp_method_selection.cpp
+ gui/dialogs/popup.cpp
+ gui/dialogs/simple_item_selector.cpp
+ gui/dialogs/tip.cpp
+ gui/dialogs/title_screen.cpp
+ gui/dialogs/transient_message.cpp
+ gui/dialogs/unit_attack.cpp
+ gui/dialogs/unit_create.cpp
+ gui/dialogs/wml_message.cpp
+ gui/widgets/button.cpp
+ gui/widgets/container.cpp
+ gui/widgets/control.cpp
+ gui/widgets/debug.cpp
+ gui/widgets/drawing.cpp
+ gui/widgets/generator.cpp
+ gui/widgets/grid.cpp
+ gui/widgets/helper.cpp
+ gui/widgets/horizontal_scrollbar.cpp
+ gui/widgets/image.cpp
+ gui/widgets/label.cpp
+ gui/widgets/list.cpp
+ gui/widgets/listbox.cpp
+ gui/widgets/minimap.cpp
+ gui/widgets/multi_page.cpp
+ gui/widgets/panel.cpp
+ gui/widgets/password_box.cpp
+ gui/widgets/progress_bar.cpp
+ gui/widgets/repeating_button.cpp
+ gui/widgets/scroll_label.cpp
+ gui/widgets/scrollbar.cpp
+ gui/widgets/scrollbar_container.cpp
+ gui/widgets/scrollbar_panel.cpp
+ gui/widgets/settings.cpp
+ gui/widgets/slider.cpp
+ gui/widgets/spacer.cpp
+ gui/widgets/stacked_widget.cpp
+ gui/widgets/text.cpp
+ gui/widgets/text_box.cpp
+ gui/widgets/toggle_button.cpp
+ gui/widgets/toggle_panel.cpp
+ gui/widgets/tree_view.cpp
+ gui/widgets/tree_view_node.cpp
+ gui/widgets/vertical_scrollbar.cpp
+ gui/widgets/widget.cpp
+ gui/widgets/window.cpp
+ halo.cpp
+ help.cpp
+ intro.cpp
+ leader_list.cpp
+ menu_events.cpp
+ mouse_events.cpp
+ mouse_handler_base.cpp
+ mp_game_settings.cpp
+ multiplayer.cpp
+ multiplayer_connect.cpp
+ multiplayer_create.cpp
+ multiplayer_lobby.cpp
+ multiplayer_ui.cpp
+ multiplayer_wait.cpp
+ pathfind/pathfind.cpp
+ pathfind/teleport.cpp
+ persist_context.cpp
+ persist_manager.cpp
+ persist_var.cpp
+ play_controller.cpp
+ playcampaign.cpp
+ playmp_controller.cpp
+ playsingle_controller.cpp
+ playturn.cpp
+ portrait.cpp
+ replay.cpp
+ replay_controller.cpp
+ resources.cpp
+ save_blocker.cpp
+ savegame.cpp
+ savegame_config.cpp
+ scripting/lua.cpp
+ settings.cpp
+ sha1.cpp
+ side_filter.cpp
+ statistics.cpp
+ statistics_dialog.cpp
+ storyscreen/controller.cpp
+ storyscreen/interface.cpp
+ storyscreen/part.cpp
+ storyscreen/render.cpp
+ team.cpp
+ terrain_filter.cpp
+ tod_manager.cpp
+ tooltips.cpp
+ unit.cpp
+ unit_abilities.cpp
+ unit_animation.cpp
+ unit_display.cpp
+ unit_frame.cpp
+ unit_helper.cpp
+ unit_id.cpp
+ unit_map.cpp
+ unit_types.cpp
+ variable.cpp
+ variant.cpp
+ whiteboard/action.cpp
+ whiteboard/attack.cpp
+ whiteboard/highlight_visitor.cpp
+ whiteboard/manager.cpp
+ whiteboard/mapbuilder_visitor.cpp
+ whiteboard/move.cpp
+ whiteboard/recall.cpp
+ whiteboard/recruit.cpp
+ whiteboard/side_actions.cpp
+ whiteboard/suppose_dead.cpp
+ whiteboard/utility.cpp
+ whiteboard/validate_visitor.cpp
+ whiteboard/visitor.cpp
+ widgets/combo.cpp
+ widgets/combo_drag.cpp
+ widgets/drop_target.cpp
+ widgets/scrollpane.cpp
+ ${network_implementation_files} # network.cpp and network_worker.cpp are included by default (without USE_ANA_NETWORK)
+)
+
+########### libwesnoth-game ###############
+# rename libwesnoth.a to libwesnoth-game.a to have clearer targets
+
+set(libwesnoth-game_STAT_SRC
+ arrow.cpp
+ builder.cpp
+ cavegen.cpp
+ clipboard.cpp
+ construct_dialog.cpp
+ cursor.cpp
+ display.cpp
+ events.cpp
+ filechooser.cpp
+ font.cpp
+ hotkeys.cpp
+ image.cpp
+ image_modifications.cpp
+ key.cpp
+ language.cpp
+ loadscreen.cpp
+ lobby_preferences.cpp
+ map_create.cpp
+ map_label.cpp
+ mapgen.cpp
+ mapgen_dialog.cpp
+ marked-up_text.cpp
+ minimap.cpp
+ pathfind/astarsearch.cpp
+ pathutils.cpp
+ preferences.cpp
+ preferences_display.cpp
+ race.cpp
+ random.cpp
+ reports.cpp
+ sdl_utils.cpp
+ show_dialog.cpp
+ sound.cpp
+ soundsource.cpp
+ sound_music_track.cpp
+ terrain.cpp
+ terrain_translation.cpp
+ text.cpp
+ time_of_day.cpp
+ video.cpp
+ theme.cpp
+ widgets/button.cpp
+ widgets/file_menu.cpp
+ widgets/label.cpp
+ widgets/menu.cpp
+ widgets/menu_style.cpp
+ widgets/progressbar.cpp
+ widgets/scrollarea.cpp
+ widgets/scrollbar.cpp
+ widgets/slider.cpp
+ widgets/textbox.cpp
+ widgets/widget.cpp
+ wml_exception.cpp
+)
+
+if(ENABLE_GAME AND ENABLE_TESTS)
+ set(libwesnoth-game_STAT_SRC
+ ${libwesnoth-game_STAT_SRC}
+ ${wesnoth-main_SRC}
+ )
+endif(ENABLE_GAME AND ENABLE_TESTS)
+
+# a 'lib' is automatically set in front when creating the library (as in the filename)
+# internal reference is the name given here
+add_library(wesnoth-game STATIC EXCLUDE_FROM_ALL ${libwesnoth-game_STAT_SRC})
+
+if(ENABLE_GAME AND ENABLE_TESTS)
+ target_link_libraries(wesnoth-game
+ wesnoth-core
+ wesnoth-lua
+ )
+endif(ENABLE_GAME AND ENABLE_TESTS)
+
+########### Wesnoth ###############
+
+if(ENABLE_GAME)
+ if(ENABLE_TESTS)
+ set(wesnoth_SRC
+ game.cpp
+ )
+ set(wesnoth_LIB
+ wesnoth-game
+ )
+ else(ENABLE_TESTS)
+ set(wesnoth_SRC
+ game.cpp
+ ${wesnoth-main_SRC}
+ )
+ set(wesnoth_LIB
+ wesnoth-core
+ wesnoth-lua
+ wesnoth-game
+ )
+ endif(ENABLE_TESTS)
+
+ add_executable(wesnoth WIN32
+ ${wesnoth_SRC}
+ )
+
+ target_link_libraries(wesnoth
+ ${wesnoth_LIB}
+ ${game-external-libs}
+ )
+ set_target_properties(wesnoth
+ PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}
+ )
+
+ install(TARGETS wesnoth DESTINATION ${BINDIR})
+endif(ENABLE_GAME)
+
+########### Wesnothd Server ###############
+
+if(ENABLE_SERVER)
+
+set(wesnothd_SRC
+ server/ban.cpp
+ server/game.cpp
+ server/input_stream.cpp
+ server/metrics.cpp
+ server/player.cpp
+ server/player_network.cpp
+ server/proxy.cpp
+ server/room.cpp
+ server/room_manager.cpp
+ server/server.cpp
+ server/simple_wml.cpp
+ server/user_handler.cpp
+ server/forum_user_handler.cpp
+ server/sample_user_handler.cpp
+ ${network_implementation_files}
+ loadscreen_empty.cpp
+)
+
+add_executable(wesnothd WIN32
+ ${wesnothd_SRC}
+)
+
+target_link_libraries(wesnothd wesnoth-core ${server-external-libs})
+set_target_properties(wesnothd PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnothd${BINARY_SUFFIX})
+
+install(TARGETS wesnothd DESTINATION ${BINDIR})
+
+endif(ENABLE_SERVER)
+
+########### Campaign Server ###############
+
+if(ENABLE_CAMPAIGN_SERVER)
+
+set(campaignd_SRC
+ network_worker.cpp # NEEDED when compiling with ANA support
+ addon/validation.cpp
+ campaign_server/campaign_server.cpp
+ server/input_stream.cpp
+ ${network_implementation_files}
+ loadscreen_empty.cpp
+)
+
+add_executable(campaignd ${campaignd_SRC})
+target_link_libraries(campaignd
+ wesnoth-core
+ ${server-external-libs}
+ ${SDLNET_LIBRARY} # NEEDED with ANA
+ ${LIBINTL_LIBRARIES}
+ )
+set_target_properties(campaignd PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}campaignd${BINARY_SUFFIX})
+
+install(TARGETS campaignd DESTINATION ${BINDIR})
+
+endif(ENABLE_CAMPAIGN_SERVER)
+
+########### Castle building helpers ###############
+
+if(ENABLE_TOOLS)
+
+set(exploder_SRC
+ tools/exploder.cpp
+ tools/exploder_utils.cpp
+ tools/exploder_cutter.cpp
+ tools/exploder_composer.cpp
+ tools/dummy_video.cpp
+ sdl_utils.cpp
+ loadscreen_empty.cpp
+)
+
+add_executable(exploder ${exploder_SRC})
+target_link_libraries(exploder wesnoth-core png ${tools-external-libs})
+set_target_properties(exploder PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}exploder${BINARY_SUFFIX})
+
+install(TARGETS exploder DESTINATION ${BINDIR})
+
+set(cutter_SRC
+ tools/cutter.cpp
+ tools/exploder_utils.cpp
+ tools/exploder_cutter.cpp
+ tools/dummy_video.cpp
+ sdl_utils.cpp
+ loadscreen_empty.cpp
+)
+
+add_executable(cutter ${cutter_SRC})
+target_link_libraries(cutter wesnoth-core png ${tools-external-libs})
+set_target_properties(cutter PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}cutter${BINARY_SUFFIX})
+
+install(TARGETS cutter DESTINATION ${BINDIR})
+
+endif(ENABLE_TOOLS)
+
+########### Unit tests ###############
+
+if(ENABLE_TESTS)
+
+ add_definitions(-DBOOST_TEST_DYN_LINK)
+
+ set(test_SRC
+ tests/main.cpp
+ tests/utils/fake_display.cpp
+ tests/utils/fake_event_source.cpp
+ tests/utils/game_config_manager.cpp
+ tests/utils/play_scenario.cpp
+ tests/test_config_cache.cpp
+ tests/test_formula_ai.cpp
+ tests/test_formula_function.cpp
+ tests/test_image_modifications.cpp
+ tests/test_lexical_cast.cpp
+ tests/test_network_worker.cpp
+ tests/test_team.cpp
+ tests/test_util.cpp
+ tests/test_serialization.cpp
+ tests/test_version.cpp
+ tests/gui/iterator.cpp
+ tests/gui/fire_event.cpp
+ tests/gui/test_drop_target.cpp
+ tests/gui/test_gui2.cpp
+ tests/gui/visitor.cpp
+ tests/gui/test_save_dialog.cpp
+ )
+ if(NOT ENABLE_GAME)
+ set(test_SRC
+ ${test_SRC}
+ ${wesnoth-main_SRC}
+ )
+ endif(NOT ENABLE_GAME)
+
+ add_executable(test
+ ${test_SRC}
+ )
+ target_link_libraries(test
+ wesnoth-core
+ wesnoth-game
+ wesnoth-lua
+ ${game-external-libs}
+ boost_unit_test_framework
+ )
+ set_target_properties(test
+ PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}test${BINARY_SUFFIX}
+ )
+endif(ENABLE_TESTS)
+
View
557 src/SConscript
@@ -0,0 +1,557 @@
+# vi: syntax=python:et:ts=4
+
+import commands, os
+from subprocess import Popen, PIPE
+from glob import glob
+
+Import("*")
+
+for env in [test_env, client_env, env]:
+ env.Append(CPPDEFINES = "$EXTRA_DEFINE")
+
+#color_range.cpp should be removed, but game_config depends on it.
+#game_config has very few things that are needed elsewhere, it should be
+#removed. Requires moving path and version at least to other files.
+
+libwesnoth_core_sources = Split("""
+ color_range.cpp
+ config.cpp
+ gettext.cpp
+ hash.cpp
+ log.cpp
+ map.cpp
+ map_location.cpp
+ md5.cpp
+ thread.cpp
+ tstring.cpp
+ util.cpp
+ version.cpp
+ serialization/binary_or_text.cpp
+ serialization/parser.cpp
+ serialization/preprocessor.cpp
+ serialization/string_utils.cpp
+ serialization/tokenizer.cpp
+ """)
+if env["pool_alloc"]:
+ libwesnoth_core_sources.extend(Split("""
+ malloc.c
+ poolalloc.c
+ """))
+
+libwesnoth_core_sources.extend(env.Object("network_worker.cpp", EXTRA_DEFINE = env['raw_sockets'] and "NETWORK_USE_RAW_SOCKETS" or None))
+
+if env["use_network_ana"]:
+ client_env.Append(CPPPATH = ["#/src/ana/api"])
+ libwesnoth_core_sources.append("network_ana.cpp")
+ libwesnoth_core_sources.append("network_manager_ana.cpp")
+ ana = SConscript("ana/src/SConscript", exports = {"env" : client_env})
+else:
+ libwesnoth_core_sources.append("network.cpp")
+ ana = []
+
+game_config_env = env.Clone()
+filesystem_env = env.Clone()
+if env["PLATFORM"] != "win32":
+ game_config_env.Append(CPPDEFINES = "WESNOTH_PATH='\"$datadir\"'")
+ if env['localedirname']:
+ filesystem_env.Append(CPPDEFINES = "LOCALEDIR='\"$localedirname\"'")
+ if not os.path.isabs(env['localedirname']):
+ filesystem_env.Append(CPPDEFINES = "HAS_RELATIVE_LOCALEDIR")
+ if env['version_suffix'] and not env['prefsdir']:
+ filesystem_env['prefsdir'] = ".wesnoth$version_suffix"
+ if filesystem_env['prefsdir']:
+ filesystem_env.Append(CPPDEFINES = "PREFERENCES_DIR='\"$prefsdir\"'")
+
+libwesnoth_core_sources.extend([
+ game_config_env.Object("game_config.cpp"),
+ filesystem_env.Object("filesystem.cpp")
+ ])
+
+libwesnoth_core = [env.Library("wesnoth_core", libwesnoth_core_sources), ana]
+
+libwesnoth_sources = Split("""
+ arrow.cpp
+ pathfind/astarsearch.cpp
+ builder.cpp
+ cavegen.cpp
+ clipboard.cpp
+ construct_dialog.cpp
+ cursor.cpp
+ display.cpp
+ events.cpp
+ filechooser.cpp
+ generic_event.cpp
+ hotkeys.cpp
+ image.cpp
+ image_modifications.cpp
+ key.cpp
+ language.cpp
+ loadscreen.cpp
+ map_create.cpp
+ map_label.cpp
+ mapgen.cpp
+ mapgen_dialog.cpp
+ marked-up_text.cpp
+ minimap.cpp
+ pathutils.cpp
+ preferences.cpp
+ preferences_display.cpp
+ race.cpp
+ random.cpp
+ reports.cpp
+ show_dialog.cpp
+ sound.cpp
+ soundsource.cpp
+ sound_music_track.cpp
+ terrain.cpp
+ terrain_translation.cpp
+ text.cpp
+ time_of_day.cpp
+ tooltips.cpp
+ video.cpp
+ theme.cpp
+ widgets/button.cpp
+ widgets/file_menu.cpp
+ widgets/label.cpp
+ widgets/menu.cpp
+ widgets/menu_style.cpp
+ widgets/progressbar.cpp
+ widgets/scrollarea.cpp
+ widgets/scrollbar.cpp
+ widgets/slider.cpp
+ widgets/textbox.cpp
+ widgets/widget.cpp
+ wml_exception.cpp
+ """)
+libwesnoth_sources.extend([
+ client_env.Object("font.cpp", EXTRA_DEFINE = client_env['fribidi'] and "HAVE_FRIBIDI" or None),
+ ])
+
+libwesnoth = client_env.Library("wesnoth", libwesnoth_sources)
+
+libwesnothd_sources = Split("""
+ loadscreen_empty.cpp
+ tools/dummy_video.cpp
+ """)
+libwesnothd = env.Library("wesnothd", libwesnothd_sources)
+
+libcampaignd_sources = Split("""
+ addon/validation.cpp
+ """)
+libcampaignd = env.Library("campaignd", libcampaignd_sources, OBJPREFIX = "campaignd_")
+
+libwesnoth_sdl_sources = Split("""
+ sdl_utils.cpp
+ """)
+libwesnoth_sdl = client_env.Library("wesnoth_sdl", libwesnoth_sdl_sources)
+
+libcutter_sources = Split("""
+ tools/exploder_utils.cpp
+ tools/exploder_cutter.cpp
+ """)
+libcutter = client_env.Library("cutter", libcutter_sources)
+
+# Used by both 'wesnoth' and 'test' targets
+wesnoth_sources = Split("""
+ about.cpp
+ actions.cpp
+ addon/manager.cpp
+ addon/validation.cpp
+ ai/actions.cpp
+ ai/composite/ai.cpp
+ ai/composite/aspect.cpp
+ ai/composite/component.cpp
+ ai/composite/contexts.cpp
+ ai/composite/engine.cpp
+ ai/composite/engine_default.cpp
+ ai/composite/engine_fai.cpp
+ ai/composite/engine_lua.cpp
+ ai/composite/goal.cpp
+ ai/composite/rca.cpp
+ ai/composite/stage.cpp
+ ai/configuration.cpp
+ ai/contexts.cpp
+ ai/default/ai.cpp
+ ai/default/attack.cpp
+ ai/default/contexts.cpp
+ ai/formula/ai.cpp
+ ai/formula/callable_objects.cpp
+ ai/formula/candidates.cpp
+ ai/formula/function_table.cpp
+ ai/formula/stage_side_formulas.cpp
+ ai/formula/stage_unit_formulas.cpp
+ ai/game_info.cpp
+ ai/gamestate_observer.cpp
+ ai/interface.cpp
+ ai/lua/core.cpp
+ ai/manager.cpp
+ ai/registry.cpp
+ ai/testing.cpp
+ ai/testing/aspect_attacks.cpp
+ ai/testing/ca.cpp
+ ai/testing/ca_global_fallback.cpp
+ ai/testing/ca_testing_move_to_targets.cpp
+ ai/testing/ca_testing_recruitment.cpp
+ ai/testing/stage_fallback.cpp
+ ai/testing/stage_rca.cpp
+ animated_game.cpp
+ attack_prediction.cpp
+ attack_prediction_display.cpp
+ callable_objects.cpp
+ config_cache.cpp
+ controller_base.cpp
+ dialogs.cpp
+ editor/action.cpp
+ editor/brush.cpp
+ editor/editor_controller.cpp
+ editor/editor_display.cpp
+ editor/editor_layout.cpp
+ editor/editor_main.cpp
+ editor/editor_map.cpp
+ editor/editor_palettes.cpp
+ editor/editor_preferences.cpp
+ editor/map_context.cpp
+ editor/map_fragment.cpp
+ editor/mouse_action.cpp
+ floating_textbox.cpp
+ formula.cpp
+ formula_debugger.cpp
+ formula_debugger_fwd.cpp
+ formula_function.cpp
+ formula_string_utils.cpp
+ formula_tokenizer.cpp
+ game_display.cpp
+ game_errors.cpp
+ game_events.cpp
+ game_preferences.cpp
+ gamestatus.cpp
+ gui/auxiliary/canvas.cpp
+ gui/auxiliary/event/dispatcher.cpp
+ gui/auxiliary/event/distributor.cpp
+ gui/auxiliary/event/handler.cpp
+ gui/auxiliary/iterator/iterator.cpp
+ gui/auxiliary/iterator/walker_grid.cpp
+ gui/auxiliary/iterator/walker_widget.cpp
+ gui/auxiliary/log.cpp
+ gui/auxiliary/old_markup.cpp
+ gui/auxiliary/timer.cpp
+ gui/auxiliary/tips.cpp
+ gui/auxiliary/widget_definition.cpp
+ gui/auxiliary/widget_definition/button.cpp
+ gui/auxiliary/widget_definition/drawing.cpp
+ gui/auxiliary/widget_definition/horizontal_scrollbar.cpp
+ gui/auxiliary/widget_definition/image.cpp
+ gui/auxiliary/widget_definition/label.cpp
+ gui/auxiliary/widget_definition/listbox.cpp
+ gui/auxiliary/widget_definition/minimap.cpp
+ gui/auxiliary/widget_definition/multi_page.cpp
+ gui/auxiliary/widget_definition/panel.cpp
+ gui/auxiliary/widget_definition/progress_bar.cpp
+ gui/auxiliary/widget_definition/repeating_button.cpp
+ gui/auxiliary/widget_definition/scroll_label.cpp
+ gui/auxiliary/widget_definition/scrollbar_panel.cpp
+ gui/auxiliary/widget_definition/slider.cpp
+ gui/auxiliary/widget_definition/spacer.cpp
+ gui/auxiliary/widget_definition/stacked_widget.cpp
+ gui/auxiliary/widget_definition/text_box.cpp
+ gui/auxiliary/widget_definition/toggle_button.cpp
+ gui/auxiliary/widget_definition/toggle_panel.cpp
+ gui/auxiliary/widget_definition/tree_view.cpp
+ gui/auxiliary/widget_definition/vertical_scrollbar.cpp
+ gui/auxiliary/widget_definition/window.cpp
+ gui/auxiliary/window_builder.cpp
+ gui/auxiliary/window_builder/button.cpp
+ gui/auxiliary/window_builder/control.cpp
+ gui/auxiliary/window_builder/drawing.cpp
+ gui/auxiliary/window_builder/helper.cpp
+ gui/auxiliary/window_builder/horizontal_listbox.cpp
+ gui/auxiliary/window_builder/horizontal_scrollbar.cpp
+ gui/auxiliary/window_builder/image.cpp
+ gui/auxiliary/window_builder/label.cpp
+ gui/auxiliary/window_builder/listbox.cpp
+ gui/auxiliary/window_builder/minimap.cpp
+ gui/auxiliary/window_builder/multi_page.cpp
+ gui/auxiliary/window_builder/panel.cpp
+ gui/auxiliary/window_builder/password_box.cpp
+ gui/auxiliary/window_builder/progress_bar.cpp
+ gui/auxiliary/window_builder/repeating_button.cpp
+ gui/auxiliary/window_builder/scroll_label.cpp
+ gui/auxiliary/window_builder/scrollbar_panel.cpp
+ gui/auxiliary/window_builder/slider.cpp
+ gui/auxiliary/window_builder/spacer.cpp
+ gui/auxiliary/window_builder/stacked_widget.cpp
+ gui/auxiliary/window_builder/text_box.cpp
+ gui/auxiliary/window_builder/toggle_button.cpp
+ gui/auxiliary/window_builder/toggle_panel.cpp
+ gui/auxiliary/window_builder/tree_view.cpp
+ gui/auxiliary/window_builder/vertical_scrollbar.cpp
+ gui/dialogs/addon/description.cpp
+ gui/dialogs/addon_connect.cpp
+ gui/dialogs/addon_list.cpp
+ gui/dialogs/campaign_difficulty.cpp
+ gui/dialogs/campaign_selection.cpp
+ gui/dialogs/data_manage.cpp
+ gui/dialogs/debug_clock.cpp
+ gui/dialogs/dialog.cpp
+ gui/dialogs/edit_label.cpp
+ gui/dialogs/editor_generate_map.cpp
+ gui/dialogs/editor_new_map.cpp
+ gui/dialogs/editor_resize_map.cpp
+ gui/dialogs/editor_settings.cpp
+ gui/dialogs/formula_debugger.cpp
+ gui/dialogs/game_delete.cpp
+ gui/dialogs/game_load.cpp
+ gui/dialogs/game_save.cpp
+ gui/dialogs/gamestate_inspector.cpp
+ gui/dialogs/language_selection.cpp
+ gui/dialogs/lobby/lobby_data.cpp
+ gui/dialogs/lobby/lobby_info.cpp
+ gui/dialogs/lobby_main.cpp
+ gui/dialogs/lobby_player_info.cpp
+ gui/dialogs/message.cpp
+ gui/dialogs/mp_cmd_wrapper.cpp
+ gui/dialogs/mp_change_control.cpp
+ gui/dialogs/mp_connect.cpp
+ gui/dialogs/mp_create_game.cpp
+ gui/dialogs/mp_create_game_set_password.cpp
+ gui/dialogs/mp_login.cpp
+ gui/dialogs/mp_method_selection.cpp
+ gui/dialogs/popup.cpp
+ gui/dialogs/simple_item_selector.cpp
+ gui/dialogs/tip.cpp
+ gui/dialogs/title_screen.cpp
+ gui/dialogs/transient_message.cpp
+ gui/dialogs/unit_attack.cpp
+ gui/dialogs/unit_create.cpp
+ gui/dialogs/wml_message.cpp
+ gui/widgets/button.cpp
+ gui/widgets/container.cpp
+ gui/widgets/control.cpp
+ gui/widgets/drawing.cpp
+ gui/widgets/generator.cpp
+ gui/widgets/grid.cpp
+ gui/widgets/helper.cpp
+ gui/widgets/horizontal_scrollbar.cpp
+ gui/widgets/image.cpp
+ gui/widgets/label.cpp
+ gui/widgets/list.cpp
+ gui/widgets/listbox.cpp
+ gui/widgets/minimap.cpp
+ gui/widgets/multi_page.cpp
+ gui/widgets/panel.cpp
+ gui/widgets/password_box.cpp
+ gui/widgets/progress_bar.cpp
+ gui/widgets/repeating_button.cpp
+ gui/widgets/scroll_label.cpp
+ gui/widgets/scrollbar.cpp
+ gui/widgets/scrollbar_container.cpp
+ gui/widgets/scrollbar_panel.cpp
+ gui/widgets/settings.cpp
+ gui/widgets/slider.cpp
+ gui/widgets/spacer.cpp
+ gui/widgets/stacked_widget.cpp
+ gui/widgets/text.cpp
+ gui/widgets/text_box.cpp
+ gui/widgets/toggle_button.cpp
+ gui/widgets/toggle_panel.cpp
+ gui/widgets/tree_view.cpp
+ gui/widgets/tree_view_node.cpp
+ gui/widgets/vertical_scrollbar.cpp
+ gui/widgets/widget.cpp
+ gui/widgets/window.cpp
+ halo.cpp
+ help.cpp
+ intro.cpp
+ leader_list.cpp
+ lobby_preferences.cpp
+ menu_events.cpp
+ mouse_events.cpp
+ mouse_handler_base.cpp
+ mp_game_settings.cpp
+ multiplayer.cpp
+ multiplayer_connect.cpp
+ multiplayer_create.cpp
+ multiplayer_lobby.cpp
+ multiplayer_ui.cpp
+ multiplayer_wait.cpp
+ pathfind/pathfind.cpp
+ pathfind/teleport.cpp
+ persist_context.cpp
+ persist_manager.cpp
+ persist_var.cpp
+ play_controller.cpp
+ playcampaign.cpp
+ playmp_controller.cpp
+ playsingle_controller.cpp
+ playturn.cpp
+ portrait.cpp
+ replay.cpp
+ replay_controller.cpp
+ resources.cpp
+ save_blocker.cpp
+ savegame.cpp
+ savegame_config.cpp
+ scripting/lua.cpp
+ settings.cpp
+ sha1.cpp
+ side_filter.cpp
+ statistics.cpp
+ statistics_dialog.cpp
+ storyscreen/controller.cpp
+ storyscreen/interface.cpp
+ storyscreen/part.cpp
+ storyscreen/render.cpp
+ team.cpp
+ terrain_filter.cpp
+ tod_manager.cpp
+ unit.cpp
+ unit_abilities.cpp
+ unit_animation.cpp
+ unit_display.cpp
+ unit_frame.cpp
+ unit_helper.cpp
+ unit_id.cpp
+ unit_map.cpp
+ unit_types.cpp
+ variable.cpp
+ variant.cpp
+ whiteboard/action.cpp
+ whiteboard/attack.cpp
+ whiteboard/highlight_visitor.cpp
+ whiteboard/manager.cpp
+ whiteboard/mapbuilder_visitor.cpp
+ whiteboard/move.cpp
+ whiteboard/recall.cpp
+ whiteboard/recruit.cpp
+ whiteboard/side_actions.cpp
+ whiteboard/suppose_dead.cpp
+ whiteboard/utility.cpp
+ whiteboard/validate_visitor.cpp
+ whiteboard/visitor.cpp
+ widgets/combo.cpp
+ widgets/combo_drag.cpp
+ widgets/drop_target.cpp
+ widgets/scrollpane.cpp
+ """)
+
+wesnoth_sources.extend(client_env.Object("game_preferences_display.cpp", EXTRA_DEFINE = env["PLATFORM"] != "win32" and "WESNOTH_PREFIX='\"$prefix\"'" or None))
+
+libwesnoth_extras = client_env.Library("wesnoth_extras", wesnoth_sources)
+
+libwesnoth_extras.extend(SConscript("lua/SConscript"))
+
+#
+# Target declarations
+#
+
+def error_action(target, source, env):
+ from SCons.Errors import UserError
+ raise UserError, "Target disabled because its prerequisites are not met"
+
+def WesnothProgram(env, target, source, can_build, **kw):
+ if can_build:
+ if env["build"] == "base":
+ bin = env.Program(target, source, **kw)
+ else:
+ bin = env.Program("#/" + target + build_suffix, source, **kw)
+ env.Alias(target, bin)
+ else:
+ bin = env.Alias(target, [], error_action)
+ AlwaysBuild(bin)
+ exec target + " = bin"
+ Export(target)
+
+for env in [test_env, client_env, env]:
+ env.AddMethod(WesnothProgram)
+
+game_cpp = client_env.Object("game.cpp", EXTRA_DEFINE = not env["pool_alloc"] and "DISABLE_POOL_ALLOC" or None);
+
+client_env.WesnothProgram("wesnoth", [game_cpp] + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth, env["wesnoth_res"]], have_client_prereqs)
+
+campaignd_sources = Split("""
+ server/input_stream.cpp
+ """)
+
+if env["PLATFORM"] == "win32": env["fifodir"] = ""
+campaignd_sources.extend(env.Object("campaign_server/campaign_server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
+
+env.WesnothProgram("campaignd", campaignd_sources + [libwesnoth_core, libwesnothd, libcampaignd], have_server_prereqs)
+
+wesnothd_sources = Split("""
+ server/ban.cpp
+ server/forum_user_handler.cpp
+ server/game.cpp
+ server/input_stream.cpp
+ server/metrics.cpp
+ server/player.cpp
+ server/player_network.cpp
+ server/proxy.cpp
+ server/room.cpp
+ server/room_manager.cpp
+ server/sample_user_handler.cpp
+ server/simple_wml.cpp
+ server/user_handler.cpp
+ """)
+wesnothd_sources.extend(env.Object("server/server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
+
+env.WesnothProgram("wesnothd", wesnothd_sources + [libwesnoth_core, libwesnothd], have_server_prereqs)
+
+cutter_sources = Split("""
+ tools/cutter.cpp
+ """)
+client_env.WesnothProgram("cutter", cutter_sources + [libcutter, libwesnoth_core, libwesnoth_sdl, libwesnothd, libwesnoth], have_client_prereqs, LIBS = ["$LIBS", "png"])
+
+exploder_sources = Split("""
+ tools/exploder.cpp
+ tools/exploder_composer.cpp
+ """)
+client_env.WesnothProgram("exploder", exploder_sources + [libcutter, libwesnoth_core, libwesnoth_sdl, libwesnothd, libwesnoth], have_client_prereqs, LIBS = ["$LIBS", "png"])
+
+test_utils_sources = Split("""
+ tests/utils/game_config_manager.cpp
+ tests/utils/fake_event_source.cpp
+ tests/utils/fake_display.cpp
+ """)
+
+libtest_utils = test_env.Library("test_utils", test_utils_sources)
+
+test_sources = Split("""
+ tests/main.cpp
+ tests/test_formula_ai.cpp
+ tests/test_formula_function.cpp
+ tests/test_image_modifications.cpp
+ tests/test_lexical_cast.cpp
+ tests/test_network_worker.cpp
+ tests/test_team.cpp
+ tests/test_util.cpp
+ tests/test_serialization.cpp
+ tests/test_version.cpp
+ tests/gui/fire_event.cpp
+ tests/gui/iterator.cpp
+ tests/gui/test_drop_target.cpp
+ tests/gui/test_gui2.cpp
+ tests/gui/test_save_dialog.cpp
+ tests/gui/visitor.cpp
+ tests/utils/play_scenario.cpp
+ """)
+test_sources.extend(test_env.Object("tests/test_config_cache.cpp"))
+
+test = test_env.WesnothProgram("test", test_sources + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth, libwesnoth_extras, libtest_utils], have_test_prereqs)
+
+if env["svnrev"] != "" and env["svnrev"] != "exported":
+ revision_define = "#define REVISION \"%s\"\n" % env["svnrev"]
+ env.Command("#/src/revision.hpp", Value(env["svnrev"]), Action(
+ lambda target, source, env: open(str(target[0]), "w").write(revision_define),
+ "Generating revision.hpp..."
+ ))
+ game_config_env.Append(CPPDEFINES = 'HAVE_REVISION')
+
+sources = []
+if "TAGS" in COMMAND_LINE_TARGETS:
+ sources = [ Glob(os.path.join(dir, pattern)) for dir in ["", "*", "*/*"] for pattern in ["*.cpp", "*.hpp"] ]
+
+Export("sources")
+
+# Local variables:
+# mode: python
+# end:
View
4 src/SConstruct
@@ -0,0 +1,4 @@
+import sys
+from subprocess import call
+print "scons --directory=.. " + " ".join(sys.argv[1:])
+Exit(call(Split("scons --directory=..") + sys.argv[1:]))
View
361 src/about.cpp
@@ -0,0 +1,361 @@
+/* $Id: about.cpp 48153 2011-01-01 15:57:50Z mordante $ */
+/*
+ Copyright (C) 2003 - 2011 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 as published by
+ the Free Software Foundation; either version 2 of the License, 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.
+*/
+
+/**
+ * @file
+ * Show screen with scrolling credits.
+ */
+
+#include "about.hpp"
+
+#include "construct_dialog.hpp"
+#include "display.hpp"
+#include "foreach.hpp"
+#include "gettext.hpp"
+#include "marked-up_text.hpp"
+
+/**
+ * @namespace about
+ * Display credits %about all contributors.
+ *
+ * This module is used from the startup screen. \n
+ * When show_about() is called, a list of contributors
+ * to the game will be presented to the user.
+ */
+namespace about
+{
+ static config about_list = config();
+ static std::map<std::string , std::string> images;
+ static std::string images_default;
+
+/**
+ * Given a vector of strings, and a config representing an [about] section,
+ * add all the credits lines from the about section to the list of strings.
+ */
+static void add_lines(std::vector<std::string> &res, config const &c) {
+ std::string title = c["title"];
+ if (!title.empty()) {
+ title = "+" + title;
+ res.push_back(title);
+ }
+
+ std::vector<std::string> lines = utils::split(c["text"], '\n');
+ foreach (std::string &line, lines)
+ {
+ if (line.size() > 1 && line[0] == '+')
+ line = "+ " + line.substr(1);
+ else
+ line = "- " + line;
+
+ if (!line.empty())
+ {
+ if (line[0] == '_')
+ line = gettext(line.substr(1).c_str());
+ res.push_back(line);
+ }
+ }
+
+ foreach (const config &entry, c.child_range("entry")) {
+ res.push_back("- "+ entry["name"].str());
+ }
+}
+
+
+std::vector<std::string> get_text(const std::string &campaign)
+{
+ std::vector< std::string > res;
+
+ config::child_itors about_entries = about_list.child_range("about");
+
+ if (!campaign.empty()) {
+ foreach (const config &about, about_entries) {
+ // just finished a particular campaign
+ if (campaign == about["id"]) {
+ add_lines(res, about);
+ }
+ }
+ }
+
+ foreach (const config &about, about_entries) {
+ add_lines(res, about);
+ }
+
+ return res;
+}
+
+void set_about(const config &cfg)
+{
+ foreach (const config &about, cfg.child_range("about"))
+ {
+ about_list.add_child("about", about);
+ const std::string &im = about["images"];
+ if (!images.empty())
+ {
+ if (images_default.empty())
+ images_default = im;
+ else
+ images_default += ',' + im;
+ }
+ }
+
+ foreach (const config &campaign, cfg.child_range("campaign"))
+ {
+ config::const_child_itors abouts = campaign.child_range("about");
+ if (abouts.first == abouts.second) continue;
+
+ config temp;
+ std::ostringstream text;
+ const std::string &id = campaign["id"];
+ temp["title"] = campaign["name"];
+ temp["id"] = id;
+ std::string campaign_images;
+
+ foreach (const config &about, abouts)
+ {
+ const std::string &subtitle = about["title"];
+ if (!subtitle.empty())
+ {
+ text << '+';
+ if (subtitle[0] == '_')
+ text << gettext(subtitle.substr(1, subtitle.size() - 1).c_str());
+ else
+ text << subtitle;
+ text << '\n';
+ }
+
+ foreach (const std::string &line, utils::split(about["text"], '\n'))
+ {
+ text << " " << line << '\n';
+ }
+
+ foreach (const config &entry, about.child_range("entry"))
+ {
+ text << " " << entry["name"] << '\n';
+ }
+
+ const std::string &im = about["images"];
+ if (!im.empty())
+ {
+ if (campaign_images.empty())
+ campaign_images = im;
+ else
+ campaign_images += ',' + im;
+ }
+ }
+
+ images[id] = campaign_images;
+ temp["text"] = text.str();
+ about_list.add_child("about",temp);
+ }
+}
+
+/**
+ * Show credits with list of contributors.
+ *
+ * Names of people are shown scrolling up like in movie-credits.\n
+ * Uses map from wesnoth or campaign as background.
+ */
+void show_about(display &disp, const std::string &campaign)
+{
+ cursor::set(cursor::WAIT);
+ CVideo &video = disp.video();
+ surface screen = video.getSurface();
+ if (screen == NULL) return;
+
+ std::vector<std::string> text = about::get_text(campaign);
+ SDL_Rect screen_rect = create_rect(0, 0, screen->w, screen->h);
+
+ const surface_restorer restorer(&video, screen_rect);
+
+ cursor::set(cursor::NORMAL);
+
+ std::vector<std::string> image_list;
+ if(campaign.size() && !images[campaign].empty()){
+ image_list=utils::split(images[campaign]);
+ }else{
+ image_list=utils::split(images_default,',',utils::STRIP_SPACES);
+ }
+ surface map_image(scale_surface(image::get_image(image_list[0]), screen->w, screen->h));
+ if(! map_image){
+ image_list[0]=game_config::images::game_title;
+ map_image=surface(scale_surface(image::get_image(image_list[0]), screen->w, screen->h));
+ }
+
+ gui::button close(video,_("Close"));
+ close.set_location((screen->w/2)-(close.width()/2), screen->h - 30);
+ close.set_volatile(true);
+
+ const int def_size = font::SIZE_XLARGE;
+ const SDL_Color def_color = font::NORMAL_COLOR;
+
+ //substitute in the correct control characters for '+' and '-'
+ std::string before_header(2, ' ');
+ before_header[0] = font::LARGE_TEXT;
+ for(unsigned i = 0; i < text.size(); ++i) {
+ std::string &s = text[i];
+ if (s.empty()) continue;
+ char &first = s[0];
+ if (first == '-')
+ first = font::SMALL_TEXT;
+ else if (first == '+') {
+ first = font::LARGE_TEXT;
+ text.insert(text.begin() + i, before_header);
+ ++i;
+ }
+ }
+ text.insert(text.begin(), 10, before_header);
+
+ int startline = 0;
+
+ //TODO: use values proportionnal to screen ?
+ // distance from top of map image to top of scrolling text
+ const int top_margin = 60;
+ // distance from bottom of scrolling text to bottom of map image
+ const int bottom_margin = 40;
+ // distance from left of scrolling text to the frame border
+ const int text_left_padding = screen->w/32;
+
+ int offset = 0;
+ bool is_new_line = true;
+
+ int first_line_height = 0;
+
+ SDL_Rect frame_area = create_rect(
+ screen->w * 3 / 32
+ , top_margin
+ , screen->w * 13 / 16
+ , screen->h - top_margin - bottom_margin);
+
+ // we use a dialog to contains the text. Strange idea but at least the style
+ // will be consistent with the titlescreen
+ gui::dialog_frame f(video, "", gui::dialog_frame::titlescreen_style, false);
+
+ // set the layout and get the interior rectangle
+ SDL_Rect text_rect = f.layout(frame_area).interior;
+ text_rect.x += text_left_padding;
+ text_rect.w -= text_left_padding;
+ // make a copy to prevent SDL_blit to change its w and h
+ SDL_Rect text_rect_blit = text_rect;
+
+ CKey key;
+ bool last_escape;
+
+ surface text_surf = create_compatible_surface(screen, text_rect.w, text_rect.h);
+ SDL_SetAlpha(text_surf, SDL_RLEACCEL, SDL_ALPHA_OPAQUE);
+
+ int image_count = 0;
+ int scroll_speed = 4; // scroll_speed*50 = speed of scroll in pixel per second
+
+ // initialy redraw all
+ bool redraw_mapimage = true;
+ int max_text_width = text_rect.w;
+
+ do {
+ last_escape = key[SDLK_ESCAPE] != 0;
+
+ // check to see if background image has changed
+ if(text.size() && (image_count <
+ ((startline * static_cast<int>(image_list.size())) /
+ static_cast<int>(text.size())))){
+
+ image_count++;
+ surface temp=surface(scale_surface(image::get_image(image_list[image_count]), screen->w, screen->h));
+ map_image=temp?temp:map_image;
+ redraw_mapimage = true;
+ }
+
+ if (redraw_mapimage) {
+ // draw map to screen, thus erasing all text
+ sdl_blit(map_image, NULL, screen, NULL);
+ update_rect(screen_rect);
+
+ // redraw the dialog
+ f.draw_background();
+ f.draw_border();
+ // cache the dialog background (alpha blending + blurred map)
+ sdl_blit(screen, &text_rect, text_surf, NULL);
+ redraw_mapimage = false;
+ } else {
+ // redraw the saved part of the dialog where text scrolled
+ // thus erasing all text
+ SDL_Rect modified = create_rect(0, 0, max_text_width, text_rect.h);
+ sdl_blit(text_surf, &modified, screen, &text_rect_blit);
+ update_rect(text_rect);
+ }
+
+ const int line_spacing = 5;
+
+ int y = text_rect.y - offset;
+ int line = startline;
+ max_text_width = 0;
+
+ {
+ // clip to keep text into the frame (thus the new code block)
+ clip_rect_setter set_clip_rect(screen, &text_rect);
+ do {
+ // draw the text (with ellipsis if needed)
+ // update the max_text_width for future cleaning
+ int w = font::draw_text(&video, text_rect, def_size, def_color,
+ text[line], text_rect.x, y).w;
+ max_text_width = std::max<int>(max_text_width, w);
+ // since the real drawing on screen is clipped,
+ // we do a dummy one to get the height of the not clipped line.
+ // (each time because special format characters may change it)
+ const int line_height = font::draw_text(NULL, text_rect, def_size, def_color,
+ text[line], 0,0).h;
+
+ if(is_new_line) {
+ is_new_line = false;
+ first_line_height = line_height + line_spacing;
+ }
+ line++;
+ if(size_t(line) > text.size()-1)
+ line = 0;
+ y += line_height + line_spacing;
+ } while(y < text_rect.y + text_rect.h);
+ }
+
+ // performs the actual scrolling
+ offset += scroll_speed;
+ if (offset>=first_line_height) {
+ offset -= first_line_height;
+ is_new_line = true;
+ startline++;
+ if(size_t(startline) == text.size()){
+ startline = 0;
+ image_count = -1;
+ }
+ }
+
+ // handle events
+ if (key[SDLK_UP] && scroll_speed < 20) {
+ ++scroll_speed;
+ }
+ if (key[SDLK_DOWN] && scroll_speed > 0) {
+ --scroll_speed;
+ }
+
+ events::pump();
+ events::raise_process_event();
+ events::raise_draw_event();
+
+ // flip screen and wait, so the text does not scroll too fast
+ disp.flip();
+ disp.delay(20);
+
+ } while(!close.pressed() && (last_escape || !key[SDLK_ESCAPE]));
+}
+
+} // end namespace about
View
36 src/about.hpp
@@ -0,0 +1,36 @@
+/* $Id: about.hpp 48153 2011-01-01 15:57:50Z mordante $ */
+/*
+ Copyright (C) 2003 - 2011 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 as published by
+ the Free Software Foundation; either version 2 of the License, 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 ABOUT_H_INCLUDED
+#define ABOUT_H_INCLUDED
+
+#include "global.hpp"
+
+class display;
+class config;
+
+#include <vector>
+#include <string>
+
+namespace about
+{
+
+void show_about(display &disp, const std::string &campaign = std::string());
+void set_about(const config& cfg);
+std::vector<std::string> get_text(const std::string &campaign = std::string());
+
+}
+
+#endif
View
2,774 src/actions.cpp
@@ -0,0 +1,2774 @@
+/* $Id: actions.cpp 49241 2011-04-17 07:32:42Z mordante $ */
+/*
+ Copyright (C) 2003 - 2011 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 as published by
+ the Free Software Foundation; either version 2 of the License, 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.
+*/
+
+/**
+ * @file
+ * Recruiting, Fighting.
+ */
+
+#include "actions.hpp"
+
+#include "attack_prediction.hpp"
+#include "foreach.hpp"
+#include "game_display.hpp"
+#include "game_end_exceptions.hpp"
+#include "game_events.hpp"
+#include "game_preferences.hpp"
+#include "gettext.hpp"
+#include "hotkeys.hpp"
+#include "log.hpp"
+#include "map_label.hpp"
+#include "mouse_handler_base.hpp"
+#include "replay.hpp"
+#include "resources.hpp"
+#include "statistics.hpp"
+#include "unit_abilities.hpp"
+#include "unit_display.hpp"
+#include "wml_exception.hpp"
+#include "formula_string_utils.hpp"
+#include "tod_manager.hpp"
+#include "whiteboard/manager.hpp"
+
+#include <boost/bind.hpp>
+
+static lg::log_domain log_engine("engine");
+#define DBG_NG LOG_STREAM(debug, log_engine)
+#define LOG_NG LOG_STREAM(info, log_engine)
+#define ERR_NG LOG_STREAM(err, log_engine)
+
+static lg::log_domain log_config("config");
+#define LOG_CF LOG_STREAM(info, log_config)
+
+static lg::log_domain log_ai_testing("ai/testing");
+#define LOG_AI_TESTING LOG_STREAM(info, log_ai_testing)
+
+struct castle_cost_calculator : pathfind::cost_calculator
+{
+ castle_cost_calculator(const gamemap& map) : map_(map)
+ {}
+
+ virtual double cost(const map_location& loc, const double) const
+ {
+ if(!map_.is_castle(loc))
+ return 10000;
+
+ return 1;
+ }
+
+private:
+ const gamemap& map_;
+};
+
+void move_unit_spectator::add_seen_friend(const unit_map::const_iterator &u)
+{
+ seen_friends_.push_back(u);
+}
+
+
+void move_unit_spectator::add_seen_enemy(const unit_map::const_iterator &u)
+{
+ seen_enemies_.push_back(u);
+}
+
+
+const unit_map::const_iterator& move_unit_spectator::get_ambusher() const
+{
+ return ambusher_;
+}
+
+
+const unit_map::const_iterator& move_unit_spectator::get_failed_teleport() const
+{
+ return failed_teleport_;
+}
+
+
+const std::vector<unit_map::const_iterator>& move_unit_spectator::get_seen_enemies() const
+{
+ return seen_enemies_;
+}
+
+
+const std::vector<unit_map::const_iterator>& move_unit_spectator::get_seen_friends() const
+{
+ return seen_friends_;
+}
+
+
+const unit_map::const_iterator& move_unit_spectator::get_unit() const
+{
+ return unit_;
+}
+
+
+move_unit_spectator::move_unit_spectator(const unit_map &units)
+ : ambusher_(units.end()),failed_teleport_(units.end()),seen_enemies_(),seen_friends_(),unit_(units.end())
+{
+}
+
+
+move_unit_spectator::~move_unit_spectator()
+{
+}
+
+void move_unit_spectator::reset(const unit_map &units)
+{
+ ambusher_ = units.end();
+ failed_teleport_ = units.end();
+ seen_enemies_.clear();
+ seen_friends_.clear();
+ unit_ = units.end();
+}
+
+
+void move_unit_spectator::set_ambusher(const unit_map::const_iterator &u)
+{
+ ambusher_ = u;
+}
+
+
+void move_unit_spectator::set_failed_teleport(const unit_map::const_iterator &u)
+{
+ failed_teleport_ = u;
+}
+
+
+void move_unit_spectator::set_unit(const unit_map::const_iterator &u)
+{
+ unit_ = u;
+}
+
+
+unit_creator::unit_creator(team &tm, const map_location &start_pos)
+ : add_to_recall_(false),discover_(false),get_village_(false),invalidate_(false), rename_side_(false), show_(false), start_pos_(start_pos), team_(tm)
+{
+}
+
+
+unit_creator& unit_creator::allow_show(bool b)
+{
+ show_=b;
+ return *this;
+}
+
+
+unit_creator& unit_creator::allow_get_village(bool b)
+{
+ get_village_=b;
+ return *this;
+}
+
+
+unit_creator& unit_creator::allow_rename_side(bool b)
+{
+ rename_side_=b;
+ return *this;
+}
+
+unit_creator& unit_creator::allow_invalidate(bool b)
+{
+ invalidate_=b;
+ return *this;
+}
+
+
+unit_creator& unit_creator::allow_discover(bool b)
+{
+ discover_=b;
+ return *this;
+}
+
+
+unit_creator& unit_creator::allow_add_to_recall(bool b)
+{
+ add_to_recall_=b;
+ return *this;
+}
+
+
+map_location unit_creator::find_location(const config &cfg, const unit* pass_check)
+{
+
+ DBG_NG << "finding location for unit with id=["<<cfg["id"]<<"] placement=["<<cfg["placement"]<<"] x=["<<cfg["x"]<<"] y=["<<cfg["y"]<<"] for side " << team_.side() << "\n";
+
+ std::vector< std::string > placements = utils::split(cfg["placement"]);
+
+ placements.push_back("map");
+ placements.push_back("recall");
+
+ foreach(std::string place, placements) {
+ map_location loc;
+ bool pass((place == "leader_passable") || (place == "map_passable"));
+
+ if (place == "recall" ) {
+ return map_location::null_location;
+ }
+
+ if (place == "leader" || place == "leader_passable") {
+ unit_map::const_iterator leader = resources::units->find_leader(team_.side());
+ //todo: take 'leader in recall list' possibility into account
+ if (leader.valid()) {
+ loc = leader->get_location();
+ } else {
+ loc = start_pos_;
+ }
+ }
+
+ if (place=="map" || place == "map_passable") {
+ loc = map_location(cfg,resources::state_of_game);
+ }
+
+ if(loc.valid() && resources::game_map->on_board(loc)) {
+ if (pass) {
+ loc = find_vacant_tile(*resources::game_map, *resources::units, loc, pathfind::VACANT_ANY, pass_check);
+ } else {
+ loc = find_vacant_tile(*resources::game_map, *resources::units, loc, pathfind::VACANT_ANY);
+ }
+ if(loc.valid() && resources::game_map->on_board(loc)) {
+ return loc;
+ }
+ }
+ }
+
+ return map_location::null_location;
+
+}
+
+
+void unit_creator::add_unit(const config &cfg)
+{
+ config temp_cfg(cfg);
+ temp_cfg["side"] = team_.side();
+ temp_cfg.remove_attribute("player_id");
+ temp_cfg.remove_attribute("faction_from_recruit");
+
+ const std::string& id =(cfg)["id"];
+ bool animate = temp_cfg["animate"].to_bool();
+ temp_cfg.remove_attribute("animate");
+
+ std::vector<unit>::iterator recall_list_element = std::find_if(team_.recall_list().begin(), team_.recall_list().end(), boost::bind(&unit::matches_id, _1, id));
+
+ if(recall_list_element==team_.recall_list().end()) {
+ //make a temporary unit
+ boost::scoped_ptr<unit> temp_unit(new unit(temp_cfg, true, resources::state_of_game));
+ map_location loc = find_location(temp_cfg, temp_unit.get());
+ if(!loc.valid()) {
+ if(add_to_recall_) {
+ //add to recall list
+ unit *new_unit = temp_unit.get();
+ team_.recall_list().push_back(*new_unit);
+ DBG_NG << "inserting unit with id=["<<id<<"] on recall list for side " << (*new_unit).side() << "\n";
+ preferences::encountered_units().insert((*new_unit).type_id());
+ }
+ } else {
+ unit *new_unit = temp_unit.get();
+ //add temporary unit to map
+ assert( resources::units->find(loc) == resources::units->end() );
+ resources::units->add(loc, *new_unit);
+ LOG_NG << "inserting unit for side " << (*new_unit).side() << "\n";
+ post_create(loc,*(resources::units->find(loc)),animate);
+ }
+ } else {
+ //get unit from recall list
+ map_location loc = find_location(temp_cfg, &(*recall_list_element));
+ if(!loc.valid()) {
+ LOG_NG << "wanted to insert unit on recall list, but recall list for side " << (cfg)["side"] << "already contains id=" <<id<<"\n";
+ return;
+ } else {
+ resources::units->add(loc, *recall_list_element);
+ LOG_NG << "inserting unit from recall list for side " << (*recall_list_element).side()<< " with id="<< id << "\n";
+ post_create(loc,*(resources::units->find(loc)),animate);
+ //if id is not empty, delete units with this ID from recall list
+ std::vector<unit> &r = team_.recall_list();
+ r.erase(std::remove_if(r.begin(),r.end(),boost::bind(&unit::matches_id, _1, id)), r.end());
+ }
+ }
+}
+
+
+void unit_creator::post_create(const map_location &loc, const unit &new_unit, bool anim)
+{
+
+ if (discover_) {
+ preferences::encountered_units().insert(new_unit.type_id());
+ }
+
+ bool show = show_ && (resources::screen !=NULL) && !resources::screen->fogged(loc);
+ bool animate = show && anim;
+
+ if (get_village_) {
+ if (resources::game_map->is_village(loc)) {
+ get_village(loc, new_unit.side());
+ }
+ }
+
+ if (resources::screen!=NULL) {
+
+ if (invalidate_ ) {
+ resources::screen->invalidate(loc);
+ }
+
+ if (animate) {
+ unit_display::unit_recruited(loc);
+ } else if (show) {
+ resources::screen->draw();
+ }
+ }
+}
+
+
+bool can_recruit_on(const gamemap& map, const map_location& leader, const map_location& loc)
+{
+ if(!map.on_board(loc))
+ return false;
+
+ if(!map.is_castle(loc))
+ return false;
+
+ if(!map.is_keep(leader))
+ return false;
+
+ castle_cost_calculator calc(map);
+ // The limit computed in the third argument is more than enough for
+ // any convex castle on the map. Strictly speaking it could be
+ // reduced to sqrt(map.w()**2 + map.h()**2).
+ pathfind::plain_route rt = pathfind::a_star_search(leader, loc, map.w()+map.h(), &calc, map.w(), map.h());
+ return !rt.steps.empty();
+}
+
+std::string find_recruit_location(int side, map_location &recruit_loc)
+{
+ LOG_NG << "finding recruit location for side " << side << "\n";
+
+ unit_map::const_iterator u = resources::units->begin(),
+ u_end = resources::units->end(), leader = u_end, leader_keep = u_end;
+
+ for(; u != u_end; ++u) {
+ if (u->can_recruit() && u->side() == side) {
+ leader = u;
+ if (resources::game_map->is_keep(leader->get_location())) {
+ leader_keep = leader;
+ if (can_recruit_on(*resources::game_map, leader_keep->get_location(), recruit_loc))
+ break;
+ }
+ }
+ }
+
+ if (leader == u_end) {
+ return _("You don’t have a leader to recruit with.");
+ }
+
+ if (leader_keep == u_end) {
+ LOG_NG << "Leader not on start: leader is on " << leader->get_location() << '\n';
+ return _("You must have your leader on a keep to recruit or recall units.");
+ }
+
+ if (resources::units->find(recruit_loc) != resources::units->end() ||
+ !can_recruit_on(*resources::game_map, leader_keep->get_location(), recruit_loc))
+ {
+ recruit_loc = map_location();
+ }
+
+ if (!resources::game_map->on_board(recruit_loc)) {
+ recruit_loc = find_vacant_tile(*resources::game_map, *resources::units, leader_keep->get_location(),
+ pathfind::VACANT_CASTLE);
+ } else if (resources::units->count(recruit_loc) == 1) {
+ recruit_loc = find_vacant_tile(*resources::game_map, *resources::units, recruit_loc,
+ pathfind::VACANT_ANY);
+ }
+
+ if (!resources::game_map->on_board(recruit_loc)) {
+ return _("There are no vacant castle tiles in which to recruit a unit.");
+ }
+
+ return std::string();
+}
+
+void place_recruit(const unit &u, const map_location &recruit_location,
+ bool is_recall, bool show, bool fire_event, bool full_movement,
+ bool wml_triggered)
+{
+ LOG_NG << "placing new unit on location " << recruit_location << "\n";
+
+ assert(resources::units->count(recruit_location) == 0);
+
+ unit new_unit = u;
+ if (full_movement) {
+ new_unit.set_movement(new_unit.total_movement());
+ } else {
+ new_unit.set_movement(0);
+ new_unit.set_attacks(0);
+ }
+ new_unit.heal_all();
+ new_unit.set_hidden(true);
+
+ resources::units->add(recruit_location, new_unit);
+
+ if (is_recall)
+ {
+ if (fire_event) {
+ LOG_NG << "firing prerecall event\n";
+ game_events::fire("prerecall",recruit_location);
+ }
+ }
+ else
+ {
+ LOG_NG << "firing prerecruit event\n";
+ game_events::fire("prerecruit",recruit_location);
+ }
+ const unit_map::iterator new_unit_itor = resources::units->find(recruit_location);
+ if (new_unit_itor.valid()) new_unit_itor->set_hidden(false);
+ unit_map::iterator leader = resources::units->begin();
+ for(; leader != resources::units->end(); ++leader)
+ if (leader->can_recruit() &&
+ leader->side() == new_unit.side() &&
+ resources::game_map->is_keep(leader->get_location()) &&
+ can_recruit_on(*resources::game_map, leader->get_location(), recruit_location))
+ break;
+ if (show) {
+ if (leader.valid()) {
+ unit_display::unit_recruited(recruit_location, leader->get_location());
+ } else {
+ unit_display::unit_recruited(recruit_location);
+ }
+ }
+ if (is_recall)
+ {
+ if (fire_event) {
+ LOG_NG << "firing recall event\n";
+ game_events::fire("recall",recruit_location);
+ }
+ }
+ else
+ {
+ LOG_NG << "firing recruit event\n";
+ game_events::fire("recruit",recruit_location);
+ }
+
+ const std::string checksum = get_checksum(new_unit);
+
+ const config* ran_results = get_random_results();
+ if(ran_results != NULL) {
+ // When recalling from WML there should be no random results, if we use
+ // random we might get the replay out of sync.
+ assert(!wml_triggered);
+ const std::string rc = (*ran_results)["checksum"];
+ if(rc != checksum) {
+ std::stringstream error_msg;
+ error_msg << "SYNC: In recruit " << new_unit.type_id() <<
+ ": has checksum " << checksum <<
+ " while datasource has checksum " <<
+ rc << "\n";
+ ERR_NG << error_msg.str();
+
+ config cfg_unit1;
+ new_unit.write(cfg_unit1);
+ DBG_NG << cfg_unit1;
+ replay::process_error(error_msg.str());
+ }
+
+ } else if(wml_triggered == false) {
+ config cfg;
+ cfg["checksum"] = checksum;
+ set_random_results(cfg);
+ }
+
+ resources::whiteboard->on_gamestate_change();
+}
+
+map_location under_leadership(const unit_map& units,
+ const map_location& loc, int* bonus)
+{
+
+ const unit_map::const_iterator un = units.find(loc);
+ if(un == units.end()) {
+ return map_location::null_location;
+ }
+ unit_ability_list abil = un->get_abilities("leadership");
+ if(bonus) {
+ *bonus = abil.highest("value").first;
+ }
+ return abil.highest("value").second;
+}
+
+battle_context::battle_context(const unit_map& units,
+ const map_location& attacker_loc, const map_location& defender_loc,
+ int attacker_weapon, int defender_weapon, double aggression, const combatant *prev_def, const unit* attacker_ptr)
+: attacker_stats_(NULL), defender_stats_(NULL), attacker_combatant_(NULL), defender_combatant_(NULL)
+{
+ const unit &attacker = attacker_ptr ? *attacker_ptr : *units.find(attacker_loc);
+ const unit &defender = *units.find(defender_loc);
+ const double harm_weight = 1.0 - aggression;
+
+ if (attacker_weapon == -1 && attacker.attacks().size() == 1 && attacker.attacks()[0].attack_weight() > 0 )
+ attacker_weapon = 0;
+
+ if (attacker_weapon == -1) {
+ attacker_weapon = choose_attacker_weapon(attacker, defender, units,
+ attacker_loc, defender_loc,
+ harm_weight, &defender_weapon, prev_def);
+ } else if (defender_weapon == -1) {
+ defender_weapon = choose_defender_weapon(attacker, defender, attacker_weapon,
+ units, attacker_loc, defender_loc, prev_def);
+ }
+
+ // If those didn't have to generate statistics, do so now.
+ if (!attacker_stats_) {
+ const attack_type *adef = NULL;
+ const attack_type *ddef = NULL;
+ if (attacker_weapon >= 0) {
+ VALIDATE(attacker_weapon < static_cast<int>(attacker.attacks().size()),
+ _("An invalid attacker weapon got selected."));
+ adef = &attacker.attacks()[attacker_weapon];
+ }
+ if (defender_weapon >= 0) {
+ VALIDATE(defender_weapon < static_cast<int>(defender.attacks().size()),
+ _("An invalid defender weapon got selected."));
+ ddef = &defender.attacks()[defender_weapon];
+ }
+ assert(!defender_stats_ && !attacker_combatant_ && !defender_combatant_);
+ attacker_stats_ = new battle_context_unit_stats(attacker, attacker_loc, attacker_weapon,
+ true, defender, defender_loc, ddef, units);
+ defender_stats_ = new battle_context_unit_stats(defender, defender_loc, defender_weapon, false,
+ attacker, attacker_loc, adef, units);
+ }
+}
+
+ battle_context::battle_context(const battle_context &other)
+: attacker_stats_(NULL), defender_stats_(NULL), attacker_combatant_(NULL), defender_combatant_(NULL)
+{
+ *this = other;
+}
+
+battle_context::battle_context(const battle_context_unit_stats &att, const battle_context_unit_stats &def) :
+ attacker_stats_(new battle_context_unit_stats(att)),
+ defender_stats_(new battle_context_unit_stats(def)),
+ attacker_combatant_(0),
+ defender_combatant_(0)
+{
+}
+
+battle_context::~battle_context()
+{
+ delete attacker_stats_;
+ delete defender_stats_;
+ delete attacker_combatant_;
+ delete defender_combatant_;
+}
+battle_context& battle_context::operator=(const battle_context &other)
+{
+ if (&other != this) {
+ delete attacker_stats_;
+ delete defender_stats_;
+ delete attacker_combatant_;
+ delete defender_combatant_;
+ attacker_stats_ = new battle_context_unit_stats(*other.attacker_stats_);
+ defender_stats_ = new battle_context_unit_stats(*other.defender_stats_);
+ attacker_combatant_ = other.attacker_combatant_ ? new combatant(*other.attacker_combatant_, *attacker_stats_) : NULL;
+ defender_combatant_ = other.defender_combatant_ ? new combatant(*other.defender_combatant_, *defender_stats_) : NULL;
+ }
+ return *this;
+}
+
+/** @todo FIXME: Hand previous defender unit in here. */
+int battle_context::choose_defender_weapon(const unit &attacker, const unit &defender, unsigned attacker_weapon,
+ const unit_map& units,
+ const map_location& attacker_loc, const map_location& defender_loc,
+ const combatant *prev_def)
+{
+ VALIDATE(attacker_weapon < attacker.attacks().size(),
+ _("An invalid attacker weapon got selected."));
+ const attack_type &att = attacker.attacks()[attacker_weapon];
+ std::vector<unsigned int> choices;
+
+ // What options does defender have?
+ unsigned int i;
+ for (i = 0; i < defender.attacks().size(); ++i) {
+ const attack_type &def = defender.attacks()[i];
+ if (def.range() == att.range() && def.defense_weight() > 0) {
+ choices.push_back(i);
+ }
+ }
+ if (choices.empty())
+ return -1;
+ if (choices.size() == 1)
+ return choices[0];
+
+ // Multiple options:
+ // First pass : get the best weight and the minimum simple rating for this weight.
+ // simple rating = number of blows * damage per blows (resistance taken in account) * cth * weight
+ // Elligible attacks for defense should have a simple rating greater or equal to this weight.
+
+ double max_weight = 0.0;
+ int min_rating = 0;
+
+ for (i = 0; i < choices.size(); ++i) {
+ const attack_type &def = defender.attacks()[choices[i]];
+ if (def.defense_weight() >= max_weight) {
+ max_weight = def.defense_weight();
+ const battle_context_unit_stats def_stats(defender, defender_loc,
+ choices[i], false, attacker, attacker_loc, &att, units);
+ int rating = static_cast<int>(def_stats.num_blows * def_stats.damage *
+ def_stats.chance_to_hit * def.defense_weight());
+ if (def.defense_weight() > max_weight || rating < min_rating ) {
+ min_rating = rating;
+ }
+ }
+ }
+
+ // Multiple options: simulate them, save best.
+ for (i = 0; i < choices.size(); ++i) {
+ const attack_type &def = defender.attacks()[choices[i]];
+ battle_context_unit_stats *att_stats = new battle_context_unit_stats(attacker, attacker_loc, attacker_weapon,
+ true, defender, defender_loc, &def, units);
+ battle_context_unit_stats *def_stats = new battle_context_unit_stats(defender, defender_loc, choices[i], false,
+ attacker, attacker_loc, &att, units);
+
+ combatant *att_comb = new combatant(*att_stats);
+ combatant *def_comb = new combatant(*def_stats, prev_def);
+ att_comb->fight(*def_comb);
+
+ int simple_rating = static_cast<int>(def_stats->num_blows *
+ def_stats->damage * def_stats->chance_to_hit * def.defense_weight());
+
+ if (simple_rating >= min_rating &&
+ ( !attacker_combatant_ || better_combat(*def_comb, *att_comb, *defender_combatant_, *attacker_combatant_, 1.0) )
+ ) {
+ delete attacker_combatant_;
+ delete defender_combatant_;
+ delete attacker_stats_;
+ delete defender_stats_;
+ attacker_combatant_ = att_comb;
+ defender_combatant_ = def_comb;
+ attacker_stats_ = att_stats;
+ defender_stats_ = def_stats;
+ } else {
+ delete att_comb;
+ delete def_comb;
+ delete att_stats;
+ delete def_stats;
+ }
+ }
+
+ return defender_stats_->attack_num;
+}
+
+int battle_context::choose_attacker_weapon(const unit &attacker, const unit &defender,
+ const unit_map& units,
+ const map_location& attacker_loc, const map_location& defender_loc,
+ double harm_weight, int *defender_weapon, const combatant *prev_def)
+{
+ std::vector<unsigned int> choices;
+
+ // What options does attacker have?
+ unsigned int i;
+ for (i = 0; i < attacker.attacks().size(); ++i) {
+ const attack_type &att = attacker.attacks()[i];
+ if (att.attack_weight() > 0) {
+ choices.push_back(i);
+ }
+ }
+ if (choices.empty())
+ return -1;
+ if (choices.size() == 1) {
+ *defender_weapon = choose_defender_weapon(attacker, defender, choices[0], units,
+ attacker_loc, defender_loc, prev_def);
+ return choices[0];
+ }