<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Iceiceice</id>
	<title>The Battle for Wesnoth Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Iceiceice"/>
	<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/Special:Contributions/Iceiceice"/>
	<updated>2026-04-22T11:51:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=56376</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=56376"/>
		<updated>2015-05-11T01:19:02Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: bce5fb22e59f467973ad27c22a6d8101e930f92b&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
If you get configuration errors, a good way to trouble shoot is to check your /build/config.log&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
=== Note ===&lt;br /&gt;
&lt;br /&gt;
When I finally compiled I get these warnings on linking:&lt;br /&gt;
&lt;br /&gt;
  /usr/bin/ccache i686-w64-mingw32-g++ -o wesnoth.exe -static-libgcc -static-libstdc++ -mwindows -mthreads build/release/wesnoth.o build/release/libwesnoth_extras.a build/release/lua/liblua.a build/release/libwesnoth_core.a build/release/libwesnoth.a build/release/libwesnoth_sdl.a build/release/libwesnoth_extras.a build/release/lua/liblua.a packaging/windows/wesnoth.o -L/home/chris/w-deps/lib -L/home/chris/w-deps/lib -L/home/chris/old_boost/boost_1_52_0/stage/lib -lmingw32 -lSDLmain -lSDL -lSDL_net -lboost_iostreams -lz -lbz2 -lboost_system -lboost_filesystem -lboost_locale -lSDL_ttf -lSDL_mixer -lSDL_image -lws2_32 -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lfreetype -lpango-1.0 -lm -lgobject-2.0 -lglib-2.0 -lintl -lfontconfig -lboost_program_options -lboost_regex -lvorbisfile -lwsock32 -lintl -lz&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(gzip.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_9iostreams10gzip_errorEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_9iostreams10gzip_errorEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(gzip.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(gzip.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(file_descriptor.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINSt8ios_base7failureEEE[__ZTSN5boost16exception_detail19error_info_injectorINSt8ios_base7failureEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(file_descriptor.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(file_descriptor.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_filesystem.a(operations.o): duplicate section `.rdata$_ZTSN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEEE[__ZTSN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_locale.a(message.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_locale.a(message.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_locale.a(message.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(convert.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(convert.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(convert.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(cmdline.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(cmdline.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(cmdline.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  scons: done building targets.&lt;br /&gt;
&lt;br /&gt;
We don't know what these warnings are exactly but it seems they can be ignored.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
Besides the libs like SDL, pango, etc., you also need a .dll specific to mingw (I guess this is the mingw run time library). I found that I needed this dll:&lt;br /&gt;
&lt;br /&gt;
  /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc_s_sjlj-1.dll&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;br /&gt;
&lt;br /&gt;
=== Tip ===&lt;br /&gt;
&lt;br /&gt;
As I learned later, a better way to handle this is to just copy all of the .dll files you need into the root of your repo, next to wesnoth.exe. This will make wine find them first, for wesnoth only, and our .gitignore file includes *.dll so they won't get into the repo.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
A helpful thing I found is, if you have problems running wesnoth with the DLL's, you can sanity check  by running the little executables generated by scons for the configuration tests. E.g.&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine build/sconf_temp/conftest_20.exe&lt;br /&gt;
&lt;br /&gt;
If the test works it should give no output, otherwise if it's not linking right it should give you an error.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56289</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56289"/>
		<updated>2015-04-17T10:23:22Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* ADJUST_ALPHA */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is either a %, or an integer from 0 to 255, in which case it is divided by 255 and reinterpretted as a %.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56244</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56244"/>
		<updated>2015-04-17T05:03:01Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
{{devfeature1.11}}&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
{{DevFeature1.11}}&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is a number from 0 to 255 -- the factor is ''n/255''.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=56243</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=56243"/>
		<updated>2015-04-17T04:41:44Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Events and WML actions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.2] language.&lt;br /&gt;
&lt;br /&gt;
It is also possible to put this tag inside a [scenario] [[ScenarioWML]], those tags will be executed immideately when the lua engine loads which is even before the scenario preload event is fired.&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). For instance, a function defined in an event can be used in all the events that happen after it.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now local, since its name does not have to be&lt;br /&gt;
             -- visible outside this Lua scripts.&lt;br /&gt;
             local function handler(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
             -- Create a new tag named [narrator].&lt;br /&gt;
             wesnoth.register_wml_action(&amp;quot;narrator&amp;quot;, handler)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea (unless it has been redirected to WML variables, see [[LuaWML:Variables#set_wml_var_metatable|helper.set_wml_var_metatable]]). The only time assigning global variables (including function definitions) makes sense is during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.1/manual.html#5.1 basic] (no name), [http://www.lua.org/manual/5.1/manual.html#5.4 string], [http://www.lua.org/manual/5.1/manual.html#5.5 table], and [http://www.lua.org/manual/5.1/manual.html#5.6 math]. {{DevFeature1.13|0}} The [http://www.lua.org/manual/5.2/manual.html#6.7 bit32] library is supported as well. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Additionally, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library (keep in mind that they aren't multiplayer- and replay-safe), as well as traceback from the [http://www.lua.org/manual/5.1/manual.html#5.9 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if V.target_hex.is_set and&lt;br /&gt;
                (event_data.x1 ~= V.target_hex.x or event_data.y1 ~= V.target_hex.y)&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
 local event_data = wesnoth.current.event_context&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
 if V.target_hex.is_set and&lt;br /&gt;
    (event_data.x1 ~= V.target_hex.x or event_data.y1 ~= V.target_hex.y)&lt;br /&gt;
&lt;br /&gt;
whether the variable ''V.target_hex'' matches the event parameters. Since ''V'' is not a local variable, it is taken from the global environment. Usually, variables from the global environment are not persistent (they get lost on reloading), so it shouldn't be used to store data. In order to have an easy way to access the usual persistent Wml variables, the global variable ''V''  was mapped to the storage of WML variables by the following ''preload'' event.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             -- skipping some other initializations&lt;br /&gt;
             -- ...&lt;br /&gt;
             V = H.set_wml_var_metatable {}&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Without a prelude redirecting ''V'', the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
 if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
 W.redraw()&lt;br /&gt;
&lt;br /&gt;
Again, this short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
 W = H.set_wml_action_metatable {}&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
 function narrator_says(m)&lt;br /&gt;
     W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                 message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions contained in the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_all_vars|wesnoth.get_all_vars]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_conditionals]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_markup|wesnoth.set_dialog_markup]] {{DevFeature1.11|9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.add_dialog_tree_node|wesnoth.add_dialog_tree_node]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type_ids|wesnoth.get_unit_type_ids]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type|wesnoth.get_unit_type]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_side|wesnoth.get_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_cost_map|wesnoth.find_cost_map]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_era|wesnoth.get_era]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.have_file|wesnoth.have_file]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_time_stamp|wesnoth.get_time_stamp]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.set_wml_tag_metatable|helper.set_wml_tag_metatable]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.shuffle|helper.shuffle]] {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     a_bool = true,&lt;br /&gt;
     an_int = 42,&lt;br /&gt;
     a_float = 1.25,&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
     an_int = &amp;quot;42&amp;quot;&lt;br /&gt;
     a_float = &amp;quot;1.25&amp;quot;&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form {[1] = &amp;quot;tag_name&amp;quot;, [2] = {}} which is equivalent to {&amp;quot;tag_name&amp;quot;, {}}. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
     { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     foo = 42&lt;br /&gt;
     [bar]&lt;br /&gt;
         v = 1&lt;br /&gt;
         w = 2&lt;br /&gt;
     [/bar]&lt;br /&gt;
     [foo]&lt;br /&gt;
         x = no&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [bar]&lt;br /&gt;
         y = foo&lt;br /&gt;
     [bar]&lt;br /&gt;
     [foobar]&lt;br /&gt;
         z = 5&lt;br /&gt;
         [barfoo]&lt;br /&gt;
         [/barfoo]&lt;br /&gt;
     [/foobar]&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
     [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
     [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
 a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
 a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
 a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaWML:Variables#helper.get_child|helper.get_child]] and [[LuaWML:Variables#helper.child_range|helper.child_range]] to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
Functions registered by [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]] receive their data in a userdata object which has the exact same structure as above. It is read-only however. Accessing fields or children performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain tables (therefore writable). '''__literal''' returns the original text of the data (including dollar symbols in attributes and [insert_tag] children), while '''__parsed''' performs a variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
 local old_event_handler&lt;br /&gt;
 old_event_handler = register_wml_action(&amp;quot;event&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Get the plain text from the user.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
         -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
         -- reference variables.&lt;br /&gt;
         local first = cfg.first_time_only&lt;br /&gt;
         -- Modify the default behavior of first_time_only.&lt;br /&gt;
         if first == nil then first = false end&lt;br /&gt;
         new_cfg.first_time_only = first&lt;br /&gt;
         -- Call the engine handler.&lt;br /&gt;
         old_event_handler(new_cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that, since the object is a userdata and not a table, '''pairs''' and '''ipairs''' are unfortunately not usable on it. So scripts have to work at a lower level. For instance, the following function returns the first sub-tag with a given name and it works both on WML tables and WML userdata:&lt;br /&gt;
&lt;br /&gt;
 function get_child(cfg, name)&lt;br /&gt;
     for i = 1, #cfg do&lt;br /&gt;
         local v = cfg[i]&lt;br /&gt;
         if v[1] == name then return v[2] end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand:&lt;br /&gt;
&lt;br /&gt;
 if getmetatable(cfg) == &amp;quot;wml object&amp;quot; then cfg = cfg.__parsed end&lt;br /&gt;
&lt;br /&gt;
The WML userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a preload event ==&lt;br /&gt;
&lt;br /&gt;
The following event is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua and a table ''W'' that serves as a proxy for firing WML actions. It sets up a table ''T'' so be used for easier creation of valid WML tables. It also sets up a table ''V'' so that any access to it is redirected to the persistent WML storage.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             T = H.set_wml_tag_metatable {}&lt;br /&gt;
             V = H.set_wml_var_metatable {}&lt;br /&gt;
             _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global constants here.&lt;br /&gt;
             -- ...&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
             -- Define your global functions here.&lt;br /&gt;
             -- ...&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the ''preload'' event load it:&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should rely on the [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] tag to synchronize random values.&lt;br /&gt;
&lt;br /&gt;
 function random(min, max)&lt;br /&gt;
   if not max then min, max = 1, min end&lt;br /&gt;
   wesnoth.fire(&amp;quot;set_variable&amp;quot;, { name = &amp;quot;LUA_random&amp;quot;, rand = string.format(&amp;quot;%d..%d&amp;quot;, min, max) })&lt;br /&gt;
   local res = wesnoth.get_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   wesnoth.set_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   return res&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56218</id>
		<title>LuaWML/Events</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56218"/>
		<updated>2015-04-10T16:52:45Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* wesnoth.wml_conditionals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for interacting with events and action handlers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire ====&lt;br /&gt;
&lt;br /&gt;
Fires a [[ActionWML|WML action]]. Argument 1 is the name of the action. Argument 2 is the WML table describing the action. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;message&amp;quot;, { speaker=&amp;quot;narrator&amp;quot;, message=_ &amp;quot;Hello World!&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.register_wml_action ====&lt;br /&gt;
{{DevFeature1.11}}: This function is deprecated; directly write into [[#wesnoth.wml_actions]] instead.&lt;br /&gt;
&lt;br /&gt;
Registers the second argument as a handler for the given action tag. When the game encounters this tag when executing [[ActionWML]] (for example in an event), it fires the action handler and passes the content of the WML object as the first argument. Thus, this function creates new types of [[ActionWML]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the registered function raises an error with a message starting with ''~wml:'', it will not be displayed as a Lua error with a backtrace but as a standard WML error. (See also [[#helper.wml_error]].) The following script defines a [freeze_unit] tag that sets to 0 the move points of the unit with the given id.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.register_wml_action(&amp;quot;freeze_unit&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         local unit_id = cfg.id or error(&amp;quot;~wml:[freeze_unit] expects an id= attribute.&amp;quot;, 0)&lt;br /&gt;
         helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # The new tag can now be used in plain WML code.&lt;br /&gt;
 [freeze_unit]&lt;br /&gt;
     id=Delfador&lt;br /&gt;
 [/freeze_unit]&lt;br /&gt;
&lt;br /&gt;
The function returns the previous action handler. Its metatable appears as '''&amp;quot;wml action handler&amp;quot;'''. This handler can be called to delegate part of the action, if needed. For instance, the following script modifies the [[InterfaceActionsWML#Other interface tags|[print]]] tag so that messages are displayed with a bigger font.&lt;br /&gt;
&lt;br /&gt;
 local old_print_handler&lt;br /&gt;
 old_print_handler = wesnoth.register_wml_action(&amp;quot;print&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Do not perform variable substitution.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- Modify the size field and call the previous handler.&lt;br /&gt;
         new_cfg.size = (cfg.size or 12) + 10&lt;br /&gt;
         old_print_handler(cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that the data coming from the WML tag are stored in a read-only object and variable substitution happens on the fly when accessing attributes and children. The metatable of this proxy object appears as '''&amp;quot;wml object&amp;quot;'''. See [[LuaWML#Encoding WML objects into Lua tables]] for more details.&lt;br /&gt;
&lt;br /&gt;
If the name of a tag starts as ''filter'', it is ignored when the actions of an event are executed. These names are indeed reserved for event filtering, e.g. [filter], [filter_weapon], and so on. It is therefore useless to define action tags with such names.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_actions ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by WML action names. It contains functions performing the corresponding actions. Using these functions is similar to calling [[#wesnoth.fire]], while setting entries of the table is similar to calling [[#wesnoth.register_wml_action]].&lt;br /&gt;
&lt;br /&gt;
 function wesnoth.wml_actions.freeze_unit(cfg)&lt;br /&gt;
     local unit_id = cfg.id or helper.wml_error &amp;quot;[freeze_unit] expects an id= attribute.&amp;quot;&lt;br /&gt;
     helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: When calling an action handler directly through its function stored in ''wesnoth.wml_actions'', the engine is not involved. As a consequence, whether variable substitution will happen is up to the handler. In particular, if the argument is a plain table, the caller should have substituted WML variables beforehand to be on the safe side. Moreover, table arguments might be modified by the action handler, so they should usually not be reused for consecutive calls. If variable substitution should happen and/or table content should be preserved, one can call [[#wesnoth.tovconfig]] and pass its result to the handler. Calling [[#wesnoth.fire]] is another possibility.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_conditionals ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
This is an associative table like wesnoth.wml_actions. You can use it to define new conditional wml tags that will be recognized in WML when using [if], [show_if], [while], etc., or more generally when '''wesnoth.eval_conditional''' is run.&lt;br /&gt;
&lt;br /&gt;
Use it like&lt;br /&gt;
&lt;br /&gt;
  function wesnoth.wml_conditionals.foo(cfg)&lt;br /&gt;
      local bar = cfg.bar or error(&amp;quot;[foo] tag did not have 'bar' attribute&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
      return (bar == &amp;quot;baz&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
If this lua code is executed, it would make the following syntax be valid WML in your add-on:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
     [foo]&lt;br /&gt;
        bar = $X&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           ...&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
You cannot override the meaning of any core conditional tags.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_events ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by engine action names. It contains function hooks the engine calls whenever it performs a particular action.&lt;br /&gt;
&lt;br /&gt;
* '''on_save''': function called when the engine (auto)saves a scenario file; it should return a WML table and the children of this table are added to the savefile.&lt;br /&gt;
* '''on_load''': function called when the engine loads a scenario file; its argument is a WML table that contains all the children of the savefile that the engine did not handle.&lt;br /&gt;
* '''on_event''': function called before each WML event is executed; its argument is the event name; other event arguments can be recovered from [[LuaWML:Misc#wesnoth.current|wesnoth.current.event_context]].&lt;br /&gt;
&lt;br /&gt;
The ''on_save'' and ''on_load'' hooks can be used to manipulate data that are neither meant to be forwarded to the next level nor substituted on the fly. (For either of these two purposes, WML variables are the best choice.) For instance, toplevel tags like [item], [event], [time_area], and so on, could typically be handled by such hooks.&lt;br /&gt;
&lt;br /&gt;
 -- some value that survives save/load cycles, but that is not forwarded to the next level&lt;br /&gt;
 local level_local_data = 0&lt;br /&gt;
 &lt;br /&gt;
 local old_on_load = wesnoth.game_event.on_load&lt;br /&gt;
 function wesnoth.game_event.on_load(cfg)&lt;br /&gt;
     for i = 1,#cfg do&lt;br /&gt;
         if cfg[i][1] == &amp;quot;my_data&amp;quot; then&lt;br /&gt;
             -- recover the value stored in the savefile&lt;br /&gt;
             level_local_data = cfg[i][2].value&lt;br /&gt;
             -- erase the child, since it has been handled&lt;br /&gt;
             table.remove(cfg, i)&lt;br /&gt;
             break&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     -- call the previous hook, in case there are still some containers in the savefile&lt;br /&gt;
     old_on_load(cfg)&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local old_on_save = wesnoth.game_events.on_save&lt;br /&gt;
 function wesnoth.game_events.on_save()&lt;br /&gt;
     -- call the previous hook, in case it had some containers to store&lt;br /&gt;
     local cfg = old_on_save()&lt;br /&gt;
     -- add our own container to them&lt;br /&gt;
     table.insert(cfg, { &amp;quot;my_data&amp;quot;, { value = level_local_data } })&lt;br /&gt;
     -- tell the engine to store them in the savefile&lt;br /&gt;
     return cfg&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: since the ''on_load'' hook is called very early in the scenario, it cannot be set inside a [lua] tag in an [event], not even a ''preload'' one. It has to be set inside a [lua] tag outside or at [scenario] level.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: Some tag names are reserved for engine use and should not be modified using the above on_save/on_load method. These tag names are:&lt;br /&gt;
 &amp;quot;color_palette&amp;quot;, &amp;quot;color_range&amp;quot;, &amp;quot;era&amp;quot;, &amp;quot;event&amp;quot;, &amp;quot;generator&amp;quot;,&lt;br /&gt;
 &amp;quot;label&amp;quot;, &amp;quot;lua&amp;quot;, &amp;quot;menu_item&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;side&amp;quot;, &amp;quot;sound_source&amp;quot;, &amp;quot;story&amp;quot;,&lt;br /&gt;
 &amp;quot;terrain_graphics&amp;quot;, &amp;quot;time&amp;quot;, &amp;quot;time_area&amp;quot;, &amp;quot;tunnel&amp;quot;, &amp;quot;variables&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire_event ====&lt;br /&gt;
&lt;br /&gt;
Fires all the WML events with the given name. Optional parameters allow passing two locations and two tables. These parameters will be matched against the [filter], [filter_second], [filter_attack], and [filter_second_attack] of any event handler, and are used to fill the WML variables &amp;quot;unit&amp;quot;, &amp;quot;second_unit&amp;quot;, &amp;quot;weapon&amp;quot;, and &amp;quot;second_weapon&amp;quot;. These parameters can also be read through ''current.event_context''. The function returns a boolean indicating whether the game state was modified.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire_event(&amp;quot;explosion&amp;quot;, 17, 42, { damage = &amp;quot;fire&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.eval_conditional ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the conditional described by the WML table passes. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.eval_conditional {&lt;br /&gt;
   { &amp;quot;have_unit&amp;quot;, { id = &amp;quot;hero&amp;quot; } },&lt;br /&gt;
   { &amp;quot;variable&amp;quot;, { name = &amp;quot;counter&amp;quot;, numerical_equals = &amp;quot;$old_counter&amp;quot; } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.tovconfig ====&lt;br /&gt;
&lt;br /&gt;
Converts a WML table into a proxy object which performs variable substitution on the fly.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;varname&amp;quot;, &amp;quot;to_be_deleted&amp;quot;)&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;to_be_deleted&amp;quot; }              -- correct&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;$varname&amp;quot; }                    -- error: try to delete a variable literally called &amp;quot;$varname&amp;quot;&lt;br /&gt;
 wesnoth.wml_actions.clear_variable(wesnoth.tovconfig { name = &amp;quot;$varname&amp;quot; }) -- correct: &amp;quot;$varname&amp;quot; is replaced by &amp;quot;to_be_deleted&amp;quot; at the right time&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_action_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to fire WML actions. Returns the table. The fields of the table are then simple wrappers around a call to [[#wesnoth.fire]].&lt;br /&gt;
&lt;br /&gt;
 local W = helper.set_wml_action_metatable {}&lt;br /&gt;
 W.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
==== helper.wml_error ====&lt;br /&gt;
&lt;br /&gt;
Interrupts the current execution and displays a chat message that looks like a WML error.&lt;br /&gt;
&lt;br /&gt;
 local names = cfg.name or helper.wml_error(&amp;quot;[clear_variable] missing required name= attribute.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== helper.literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__literal'' field of its argument if it is a userdata, the argument itself otherwise. This function is meant to be called when a WML action handler can be called indifferently from WML (hence receiving a userdata) or from Lua (hence possibly receiving a table).&lt;br /&gt;
&lt;br /&gt;
 function wml_actions.display_literal_value(cfg)&lt;br /&gt;
    cfg = helper.literal(cfg)&lt;br /&gt;
    wesnoth.message(tostring(cfg.value)) &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: when the argument is a plain table, the function returns it as is. In particular, modifying the fields of the returned table causes the original table to be modified too.&lt;br /&gt;
&lt;br /&gt;
==== helper.parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_literal'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56217</id>
		<title>LuaWML/Events</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56217"/>
		<updated>2015-04-10T16:50:52Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* wesnoth.wml_conditionals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for interacting with events and action handlers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire ====&lt;br /&gt;
&lt;br /&gt;
Fires a [[ActionWML|WML action]]. Argument 1 is the name of the action. Argument 2 is the WML table describing the action. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;message&amp;quot;, { speaker=&amp;quot;narrator&amp;quot;, message=_ &amp;quot;Hello World!&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.register_wml_action ====&lt;br /&gt;
{{DevFeature1.11}}: This function is deprecated; directly write into [[#wesnoth.wml_actions]] instead.&lt;br /&gt;
&lt;br /&gt;
Registers the second argument as a handler for the given action tag. When the game encounters this tag when executing [[ActionWML]] (for example in an event), it fires the action handler and passes the content of the WML object as the first argument. Thus, this function creates new types of [[ActionWML]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the registered function raises an error with a message starting with ''~wml:'', it will not be displayed as a Lua error with a backtrace but as a standard WML error. (See also [[#helper.wml_error]].) The following script defines a [freeze_unit] tag that sets to 0 the move points of the unit with the given id.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.register_wml_action(&amp;quot;freeze_unit&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         local unit_id = cfg.id or error(&amp;quot;~wml:[freeze_unit] expects an id= attribute.&amp;quot;, 0)&lt;br /&gt;
         helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # The new tag can now be used in plain WML code.&lt;br /&gt;
 [freeze_unit]&lt;br /&gt;
     id=Delfador&lt;br /&gt;
 [/freeze_unit]&lt;br /&gt;
&lt;br /&gt;
The function returns the previous action handler. Its metatable appears as '''&amp;quot;wml action handler&amp;quot;'''. This handler can be called to delegate part of the action, if needed. For instance, the following script modifies the [[InterfaceActionsWML#Other interface tags|[print]]] tag so that messages are displayed with a bigger font.&lt;br /&gt;
&lt;br /&gt;
 local old_print_handler&lt;br /&gt;
 old_print_handler = wesnoth.register_wml_action(&amp;quot;print&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Do not perform variable substitution.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- Modify the size field and call the previous handler.&lt;br /&gt;
         new_cfg.size = (cfg.size or 12) + 10&lt;br /&gt;
         old_print_handler(cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that the data coming from the WML tag are stored in a read-only object and variable substitution happens on the fly when accessing attributes and children. The metatable of this proxy object appears as '''&amp;quot;wml object&amp;quot;'''. See [[LuaWML#Encoding WML objects into Lua tables]] for more details.&lt;br /&gt;
&lt;br /&gt;
If the name of a tag starts as ''filter'', it is ignored when the actions of an event are executed. These names are indeed reserved for event filtering, e.g. [filter], [filter_weapon], and so on. It is therefore useless to define action tags with such names.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_actions ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by WML action names. It contains functions performing the corresponding actions. Using these functions is similar to calling [[#wesnoth.fire]], while setting entries of the table is similar to calling [[#wesnoth.register_wml_action]].&lt;br /&gt;
&lt;br /&gt;
 function wesnoth.wml_actions.freeze_unit(cfg)&lt;br /&gt;
     local unit_id = cfg.id or helper.wml_error &amp;quot;[freeze_unit] expects an id= attribute.&amp;quot;&lt;br /&gt;
     helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: When calling an action handler directly through its function stored in ''wesnoth.wml_actions'', the engine is not involved. As a consequence, whether variable substitution will happen is up to the handler. In particular, if the argument is a plain table, the caller should have substituted WML variables beforehand to be on the safe side. Moreover, table arguments might be modified by the action handler, so they should usually not be reused for consecutive calls. If variable substitution should happen and/or table content should be preserved, one can call [[#wesnoth.tovconfig]] and pass its result to the handler. Calling [[#wesnoth.fire]] is another possibility.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_conditionals ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
This is an associative table like wesnoth.wml_actions. You can use it to define new conditional wml tags that will be recognized in WML when using [if], [show_if], [while], etc., or more generally when '''wesnoth.eval_conditional''' is run.&lt;br /&gt;
&lt;br /&gt;
Use it like&lt;br /&gt;
&lt;br /&gt;
  function wesnoth.wml_conditionals.foo(cfg)&lt;br /&gt;
      local bar = cfg.bar or error(&amp;quot;[foo] tag did not have 'bar' attribute&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
      return (bar == &amp;quot;baz&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
If this lua code is placed in a preload event, it would make the following syntax be valid WML in your add-on:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
     [foo]&lt;br /&gt;
        bar = $X&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           ...&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
You cannot override the meaning of any core conditional tags.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_events ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by engine action names. It contains function hooks the engine calls whenever it performs a particular action.&lt;br /&gt;
&lt;br /&gt;
* '''on_save''': function called when the engine (auto)saves a scenario file; it should return a WML table and the children of this table are added to the savefile.&lt;br /&gt;
* '''on_load''': function called when the engine loads a scenario file; its argument is a WML table that contains all the children of the savefile that the engine did not handle.&lt;br /&gt;
* '''on_event''': function called before each WML event is executed; its argument is the event name; other event arguments can be recovered from [[LuaWML:Misc#wesnoth.current|wesnoth.current.event_context]].&lt;br /&gt;
&lt;br /&gt;
The ''on_save'' and ''on_load'' hooks can be used to manipulate data that are neither meant to be forwarded to the next level nor substituted on the fly. (For either of these two purposes, WML variables are the best choice.) For instance, toplevel tags like [item], [event], [time_area], and so on, could typically be handled by such hooks.&lt;br /&gt;
&lt;br /&gt;
 -- some value that survives save/load cycles, but that is not forwarded to the next level&lt;br /&gt;
 local level_local_data = 0&lt;br /&gt;
 &lt;br /&gt;
 local old_on_load = wesnoth.game_event.on_load&lt;br /&gt;
 function wesnoth.game_event.on_load(cfg)&lt;br /&gt;
     for i = 1,#cfg do&lt;br /&gt;
         if cfg[i][1] == &amp;quot;my_data&amp;quot; then&lt;br /&gt;
             -- recover the value stored in the savefile&lt;br /&gt;
             level_local_data = cfg[i][2].value&lt;br /&gt;
             -- erase the child, since it has been handled&lt;br /&gt;
             table.remove(cfg, i)&lt;br /&gt;
             break&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     -- call the previous hook, in case there are still some containers in the savefile&lt;br /&gt;
     old_on_load(cfg)&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local old_on_save = wesnoth.game_events.on_save&lt;br /&gt;
 function wesnoth.game_events.on_save()&lt;br /&gt;
     -- call the previous hook, in case it had some containers to store&lt;br /&gt;
     local cfg = old_on_save()&lt;br /&gt;
     -- add our own container to them&lt;br /&gt;
     table.insert(cfg, { &amp;quot;my_data&amp;quot;, { value = level_local_data } })&lt;br /&gt;
     -- tell the engine to store them in the savefile&lt;br /&gt;
     return cfg&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: since the ''on_load'' hook is called very early in the scenario, it cannot be set inside a [lua] tag in an [event], not even a ''preload'' one. It has to be set inside a [lua] tag outside or at [scenario] level.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: Some tag names are reserved for engine use and should not be modified using the above on_save/on_load method. These tag names are:&lt;br /&gt;
 &amp;quot;color_palette&amp;quot;, &amp;quot;color_range&amp;quot;, &amp;quot;era&amp;quot;, &amp;quot;event&amp;quot;, &amp;quot;generator&amp;quot;,&lt;br /&gt;
 &amp;quot;label&amp;quot;, &amp;quot;lua&amp;quot;, &amp;quot;menu_item&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;side&amp;quot;, &amp;quot;sound_source&amp;quot;, &amp;quot;story&amp;quot;,&lt;br /&gt;
 &amp;quot;terrain_graphics&amp;quot;, &amp;quot;time&amp;quot;, &amp;quot;time_area&amp;quot;, &amp;quot;tunnel&amp;quot;, &amp;quot;variables&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire_event ====&lt;br /&gt;
&lt;br /&gt;
Fires all the WML events with the given name. Optional parameters allow passing two locations and two tables. These parameters will be matched against the [filter], [filter_second], [filter_attack], and [filter_second_attack] of any event handler, and are used to fill the WML variables &amp;quot;unit&amp;quot;, &amp;quot;second_unit&amp;quot;, &amp;quot;weapon&amp;quot;, and &amp;quot;second_weapon&amp;quot;. These parameters can also be read through ''current.event_context''. The function returns a boolean indicating whether the game state was modified.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire_event(&amp;quot;explosion&amp;quot;, 17, 42, { damage = &amp;quot;fire&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.eval_conditional ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the conditional described by the WML table passes. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.eval_conditional {&lt;br /&gt;
   { &amp;quot;have_unit&amp;quot;, { id = &amp;quot;hero&amp;quot; } },&lt;br /&gt;
   { &amp;quot;variable&amp;quot;, { name = &amp;quot;counter&amp;quot;, numerical_equals = &amp;quot;$old_counter&amp;quot; } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.tovconfig ====&lt;br /&gt;
&lt;br /&gt;
Converts a WML table into a proxy object which performs variable substitution on the fly.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;varname&amp;quot;, &amp;quot;to_be_deleted&amp;quot;)&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;to_be_deleted&amp;quot; }              -- correct&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;$varname&amp;quot; }                    -- error: try to delete a variable literally called &amp;quot;$varname&amp;quot;&lt;br /&gt;
 wesnoth.wml_actions.clear_variable(wesnoth.tovconfig { name = &amp;quot;$varname&amp;quot; }) -- correct: &amp;quot;$varname&amp;quot; is replaced by &amp;quot;to_be_deleted&amp;quot; at the right time&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_action_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to fire WML actions. Returns the table. The fields of the table are then simple wrappers around a call to [[#wesnoth.fire]].&lt;br /&gt;
&lt;br /&gt;
 local W = helper.set_wml_action_metatable {}&lt;br /&gt;
 W.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
==== helper.wml_error ====&lt;br /&gt;
&lt;br /&gt;
Interrupts the current execution and displays a chat message that looks like a WML error.&lt;br /&gt;
&lt;br /&gt;
 local names = cfg.name or helper.wml_error(&amp;quot;[clear_variable] missing required name= attribute.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== helper.literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__literal'' field of its argument if it is a userdata, the argument itself otherwise. This function is meant to be called when a WML action handler can be called indifferently from WML (hence receiving a userdata) or from Lua (hence possibly receiving a table).&lt;br /&gt;
&lt;br /&gt;
 function wml_actions.display_literal_value(cfg)&lt;br /&gt;
    cfg = helper.literal(cfg)&lt;br /&gt;
    wesnoth.message(tostring(cfg.value)) &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: when the argument is a plain table, the function returns it as is. In particular, modifying the fields of the returned table causes the original table to be modified too.&lt;br /&gt;
&lt;br /&gt;
==== helper.parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_literal'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56216</id>
		<title>LuaWML/Events</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56216"/>
		<updated>2015-04-10T16:50:26Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for interacting with events and action handlers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire ====&lt;br /&gt;
&lt;br /&gt;
Fires a [[ActionWML|WML action]]. Argument 1 is the name of the action. Argument 2 is the WML table describing the action. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;message&amp;quot;, { speaker=&amp;quot;narrator&amp;quot;, message=_ &amp;quot;Hello World!&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.register_wml_action ====&lt;br /&gt;
{{DevFeature1.11}}: This function is deprecated; directly write into [[#wesnoth.wml_actions]] instead.&lt;br /&gt;
&lt;br /&gt;
Registers the second argument as a handler for the given action tag. When the game encounters this tag when executing [[ActionWML]] (for example in an event), it fires the action handler and passes the content of the WML object as the first argument. Thus, this function creates new types of [[ActionWML]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the registered function raises an error with a message starting with ''~wml:'', it will not be displayed as a Lua error with a backtrace but as a standard WML error. (See also [[#helper.wml_error]].) The following script defines a [freeze_unit] tag that sets to 0 the move points of the unit with the given id.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.register_wml_action(&amp;quot;freeze_unit&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         local unit_id = cfg.id or error(&amp;quot;~wml:[freeze_unit] expects an id= attribute.&amp;quot;, 0)&lt;br /&gt;
         helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # The new tag can now be used in plain WML code.&lt;br /&gt;
 [freeze_unit]&lt;br /&gt;
     id=Delfador&lt;br /&gt;
 [/freeze_unit]&lt;br /&gt;
&lt;br /&gt;
The function returns the previous action handler. Its metatable appears as '''&amp;quot;wml action handler&amp;quot;'''. This handler can be called to delegate part of the action, if needed. For instance, the following script modifies the [[InterfaceActionsWML#Other interface tags|[print]]] tag so that messages are displayed with a bigger font.&lt;br /&gt;
&lt;br /&gt;
 local old_print_handler&lt;br /&gt;
 old_print_handler = wesnoth.register_wml_action(&amp;quot;print&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Do not perform variable substitution.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- Modify the size field and call the previous handler.&lt;br /&gt;
         new_cfg.size = (cfg.size or 12) + 10&lt;br /&gt;
         old_print_handler(cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that the data coming from the WML tag are stored in a read-only object and variable substitution happens on the fly when accessing attributes and children. The metatable of this proxy object appears as '''&amp;quot;wml object&amp;quot;'''. See [[LuaWML#Encoding WML objects into Lua tables]] for more details.&lt;br /&gt;
&lt;br /&gt;
If the name of a tag starts as ''filter'', it is ignored when the actions of an event are executed. These names are indeed reserved for event filtering, e.g. [filter], [filter_weapon], and so on. It is therefore useless to define action tags with such names.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_actions ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by WML action names. It contains functions performing the corresponding actions. Using these functions is similar to calling [[#wesnoth.fire]], while setting entries of the table is similar to calling [[#wesnoth.register_wml_action]].&lt;br /&gt;
&lt;br /&gt;
 function wesnoth.wml_actions.freeze_unit(cfg)&lt;br /&gt;
     local unit_id = cfg.id or helper.wml_error &amp;quot;[freeze_unit] expects an id= attribute.&amp;quot;&lt;br /&gt;
     helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: When calling an action handler directly through its function stored in ''wesnoth.wml_actions'', the engine is not involved. As a consequence, whether variable substitution will happen is up to the handler. In particular, if the argument is a plain table, the caller should have substituted WML variables beforehand to be on the safe side. Moreover, table arguments might be modified by the action handler, so they should usually not be reused for consecutive calls. If variable substitution should happen and/or table content should be preserved, one can call [[#wesnoth.tovconfig]] and pass its result to the handler. Calling [[#wesnoth.fire]] is another possibility.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_conditionals ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
This is an associative table like wesnoth.wml_actions. You can use it to define new conditional wml tags that will be recognized in WML when using [if], [show_if], [while], etc., or more generally when '''wesnoth.eval_conditional''' is run.&lt;br /&gt;
&lt;br /&gt;
Use it like&lt;br /&gt;
&lt;br /&gt;
  function wesnoth.wml_conditionals.foo(cfg&lt;br /&gt;
      local bar = cfg.bar or error(&amp;quot;[foo] tag did not have 'bar' attribute&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
      return (bar == &amp;quot;baz&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
If this lua code is placed in a preload event, it would make the following syntax be valid WML in your add-on:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
     [foo]&lt;br /&gt;
        bar = $X&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           ...&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
You cannot override the meaning of any core conditional tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_events ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by engine action names. It contains function hooks the engine calls whenever it performs a particular action.&lt;br /&gt;
&lt;br /&gt;
* '''on_save''': function called when the engine (auto)saves a scenario file; it should return a WML table and the children of this table are added to the savefile.&lt;br /&gt;
* '''on_load''': function called when the engine loads a scenario file; its argument is a WML table that contains all the children of the savefile that the engine did not handle.&lt;br /&gt;
* '''on_event''': function called before each WML event is executed; its argument is the event name; other event arguments can be recovered from [[LuaWML:Misc#wesnoth.current|wesnoth.current.event_context]].&lt;br /&gt;
&lt;br /&gt;
The ''on_save'' and ''on_load'' hooks can be used to manipulate data that are neither meant to be forwarded to the next level nor substituted on the fly. (For either of these two purposes, WML variables are the best choice.) For instance, toplevel tags like [item], [event], [time_area], and so on, could typically be handled by such hooks.&lt;br /&gt;
&lt;br /&gt;
 -- some value that survives save/load cycles, but that is not forwarded to the next level&lt;br /&gt;
 local level_local_data = 0&lt;br /&gt;
 &lt;br /&gt;
 local old_on_load = wesnoth.game_event.on_load&lt;br /&gt;
 function wesnoth.game_event.on_load(cfg)&lt;br /&gt;
     for i = 1,#cfg do&lt;br /&gt;
         if cfg[i][1] == &amp;quot;my_data&amp;quot; then&lt;br /&gt;
             -- recover the value stored in the savefile&lt;br /&gt;
             level_local_data = cfg[i][2].value&lt;br /&gt;
             -- erase the child, since it has been handled&lt;br /&gt;
             table.remove(cfg, i)&lt;br /&gt;
             break&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     -- call the previous hook, in case there are still some containers in the savefile&lt;br /&gt;
     old_on_load(cfg)&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local old_on_save = wesnoth.game_events.on_save&lt;br /&gt;
 function wesnoth.game_events.on_save()&lt;br /&gt;
     -- call the previous hook, in case it had some containers to store&lt;br /&gt;
     local cfg = old_on_save()&lt;br /&gt;
     -- add our own container to them&lt;br /&gt;
     table.insert(cfg, { &amp;quot;my_data&amp;quot;, { value = level_local_data } })&lt;br /&gt;
     -- tell the engine to store them in the savefile&lt;br /&gt;
     return cfg&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: since the ''on_load'' hook is called very early in the scenario, it cannot be set inside a [lua] tag in an [event], not even a ''preload'' one. It has to be set inside a [lua] tag outside or at [scenario] level.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: Some tag names are reserved for engine use and should not be modified using the above on_save/on_load method. These tag names are:&lt;br /&gt;
 &amp;quot;color_palette&amp;quot;, &amp;quot;color_range&amp;quot;, &amp;quot;era&amp;quot;, &amp;quot;event&amp;quot;, &amp;quot;generator&amp;quot;,&lt;br /&gt;
 &amp;quot;label&amp;quot;, &amp;quot;lua&amp;quot;, &amp;quot;menu_item&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;side&amp;quot;, &amp;quot;sound_source&amp;quot;, &amp;quot;story&amp;quot;,&lt;br /&gt;
 &amp;quot;terrain_graphics&amp;quot;, &amp;quot;time&amp;quot;, &amp;quot;time_area&amp;quot;, &amp;quot;tunnel&amp;quot;, &amp;quot;variables&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire_event ====&lt;br /&gt;
&lt;br /&gt;
Fires all the WML events with the given name. Optional parameters allow passing two locations and two tables. These parameters will be matched against the [filter], [filter_second], [filter_attack], and [filter_second_attack] of any event handler, and are used to fill the WML variables &amp;quot;unit&amp;quot;, &amp;quot;second_unit&amp;quot;, &amp;quot;weapon&amp;quot;, and &amp;quot;second_weapon&amp;quot;. These parameters can also be read through ''current.event_context''. The function returns a boolean indicating whether the game state was modified.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire_event(&amp;quot;explosion&amp;quot;, 17, 42, { damage = &amp;quot;fire&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.eval_conditional ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the conditional described by the WML table passes. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.eval_conditional {&lt;br /&gt;
   { &amp;quot;have_unit&amp;quot;, { id = &amp;quot;hero&amp;quot; } },&lt;br /&gt;
   { &amp;quot;variable&amp;quot;, { name = &amp;quot;counter&amp;quot;, numerical_equals = &amp;quot;$old_counter&amp;quot; } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.tovconfig ====&lt;br /&gt;
&lt;br /&gt;
Converts a WML table into a proxy object which performs variable substitution on the fly.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;varname&amp;quot;, &amp;quot;to_be_deleted&amp;quot;)&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;to_be_deleted&amp;quot; }              -- correct&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;$varname&amp;quot; }                    -- error: try to delete a variable literally called &amp;quot;$varname&amp;quot;&lt;br /&gt;
 wesnoth.wml_actions.clear_variable(wesnoth.tovconfig { name = &amp;quot;$varname&amp;quot; }) -- correct: &amp;quot;$varname&amp;quot; is replaced by &amp;quot;to_be_deleted&amp;quot; at the right time&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_action_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to fire WML actions. Returns the table. The fields of the table are then simple wrappers around a call to [[#wesnoth.fire]].&lt;br /&gt;
&lt;br /&gt;
 local W = helper.set_wml_action_metatable {}&lt;br /&gt;
 W.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
==== helper.wml_error ====&lt;br /&gt;
&lt;br /&gt;
Interrupts the current execution and displays a chat message that looks like a WML error.&lt;br /&gt;
&lt;br /&gt;
 local names = cfg.name or helper.wml_error(&amp;quot;[clear_variable] missing required name= attribute.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== helper.literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__literal'' field of its argument if it is a userdata, the argument itself otherwise. This function is meant to be called when a WML action handler can be called indifferently from WML (hence receiving a userdata) or from Lua (hence possibly receiving a table).&lt;br /&gt;
&lt;br /&gt;
 function wml_actions.display_literal_value(cfg)&lt;br /&gt;
    cfg = helper.literal(cfg)&lt;br /&gt;
    wesnoth.message(tostring(cfg.value)) &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: when the argument is a plain table, the function returns it as is. In particular, modifying the fields of the returned table causes the original table to be modified too.&lt;br /&gt;
&lt;br /&gt;
==== helper.parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_literal'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56215</id>
		<title>LuaWML/Events</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Events&amp;diff=56215"/>
		<updated>2015-04-10T16:50:03Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for interacting with events and action handlers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire ====&lt;br /&gt;
&lt;br /&gt;
Fires a [[ActionWML|WML action]]. Argument 1 is the name of the action. Argument 2 is the WML table describing the action. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;message&amp;quot;, { speaker=&amp;quot;narrator&amp;quot;, message=_ &amp;quot;Hello World!&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.register_wml_action ====&lt;br /&gt;
{{DevFeature1.11}}: This function is deprecated; directly write into [[#wesnoth.wml_actions]] instead.&lt;br /&gt;
&lt;br /&gt;
Registers the second argument as a handler for the given action tag. When the game encounters this tag when executing [[ActionWML]] (for example in an event), it fires the action handler and passes the content of the WML object as the first argument. Thus, this function creates new types of [[ActionWML]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the registered function raises an error with a message starting with ''~wml:'', it will not be displayed as a Lua error with a backtrace but as a standard WML error. (See also [[#helper.wml_error]].) The following script defines a [freeze_unit] tag that sets to 0 the move points of the unit with the given id.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.register_wml_action(&amp;quot;freeze_unit&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         local unit_id = cfg.id or error(&amp;quot;~wml:[freeze_unit] expects an id= attribute.&amp;quot;, 0)&lt;br /&gt;
         helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
 # The new tag can now be used in plain WML code.&lt;br /&gt;
 [freeze_unit]&lt;br /&gt;
     id=Delfador&lt;br /&gt;
 [/freeze_unit]&lt;br /&gt;
&lt;br /&gt;
The function returns the previous action handler. Its metatable appears as '''&amp;quot;wml action handler&amp;quot;'''. This handler can be called to delegate part of the action, if needed. For instance, the following script modifies the [[InterfaceActionsWML#Other interface tags|[print]]] tag so that messages are displayed with a bigger font.&lt;br /&gt;
&lt;br /&gt;
 local old_print_handler&lt;br /&gt;
 old_print_handler = wesnoth.register_wml_action(&amp;quot;print&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Do not perform variable substitution.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- Modify the size field and call the previous handler.&lt;br /&gt;
         new_cfg.size = (cfg.size or 12) + 10&lt;br /&gt;
         old_print_handler(cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that the data coming from the WML tag are stored in a read-only object and variable substitution happens on the fly when accessing attributes and children. The metatable of this proxy object appears as '''&amp;quot;wml object&amp;quot;'''. See [[LuaWML#Encoding WML objects into Lua tables]] for more details.&lt;br /&gt;
&lt;br /&gt;
If the name of a tag starts as ''filter'', it is ignored when the actions of an event are executed. These names are indeed reserved for event filtering, e.g. [filter], [filter_weapon], and so on. It is therefore useless to define action tags with such names.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_actions ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by WML action names. It contains functions performing the corresponding actions. Using these functions is similar to calling [[#wesnoth.fire]], while setting entries of the table is similar to calling [[#wesnoth.register_wml_action]].&lt;br /&gt;
&lt;br /&gt;
 function wesnoth.wml_actions.freeze_unit(cfg)&lt;br /&gt;
     local unit_id = cfg.id or helper.wml_error &amp;quot;[freeze_unit] expects an id= attribute.&amp;quot;&lt;br /&gt;
     helper.modify_unit({ id = unit_id }, { moves = 0 })&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: When calling an action handler directly through its function stored in ''wesnoth.wml_actions'', the engine is not involved. As a consequence, whether variable substitution will happen is up to the handler. In particular, if the argument is a plain table, the caller should have substituted WML variables beforehand to be on the safe side. Moreover, table arguments might be modified by the action handler, so they should usually not be reused for consecutive calls. If variable substitution should happen and/or table content should be preserved, one can call [[#wesnoth.tovconfig]] and pass its result to the handler. Calling [[#wesnoth.fire]] is another possibility.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.wml_conditionals ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
This is an associative table like wesnoth.wml_actions. You can use it to define new conditional wml tags that will be recognized in WML when using [if], [show_if], [while], etc., or more generally when '''wesnoth.eval_conditional''' is run.&lt;br /&gt;
&lt;br /&gt;
Use it like&lt;br /&gt;
&lt;br /&gt;
  function wesnoth.wml_conditionals.foo(cfg&lt;br /&gt;
      local bar = cfg.bar or error(&amp;quot;[foo] tag did not have 'bar' attribute&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      return (bar == &amp;quot;baz&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
If this lua code is placed in a preload event, it would make the following syntax be valid WML in your add-on:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
     [foo]&lt;br /&gt;
        bar = $X&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           ...&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
You cannot override the meaning of any core conditional tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_events ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but an associative table indexed by engine action names. It contains function hooks the engine calls whenever it performs a particular action.&lt;br /&gt;
&lt;br /&gt;
* '''on_save''': function called when the engine (auto)saves a scenario file; it should return a WML table and the children of this table are added to the savefile.&lt;br /&gt;
* '''on_load''': function called when the engine loads a scenario file; its argument is a WML table that contains all the children of the savefile that the engine did not handle.&lt;br /&gt;
* '''on_event''': function called before each WML event is executed; its argument is the event name; other event arguments can be recovered from [[LuaWML:Misc#wesnoth.current|wesnoth.current.event_context]].&lt;br /&gt;
&lt;br /&gt;
The ''on_save'' and ''on_load'' hooks can be used to manipulate data that are neither meant to be forwarded to the next level nor substituted on the fly. (For either of these two purposes, WML variables are the best choice.) For instance, toplevel tags like [item], [event], [time_area], and so on, could typically be handled by such hooks.&lt;br /&gt;
&lt;br /&gt;
 -- some value that survives save/load cycles, but that is not forwarded to the next level&lt;br /&gt;
 local level_local_data = 0&lt;br /&gt;
 &lt;br /&gt;
 local old_on_load = wesnoth.game_event.on_load&lt;br /&gt;
 function wesnoth.game_event.on_load(cfg)&lt;br /&gt;
     for i = 1,#cfg do&lt;br /&gt;
         if cfg[i][1] == &amp;quot;my_data&amp;quot; then&lt;br /&gt;
             -- recover the value stored in the savefile&lt;br /&gt;
             level_local_data = cfg[i][2].value&lt;br /&gt;
             -- erase the child, since it has been handled&lt;br /&gt;
             table.remove(cfg, i)&lt;br /&gt;
             break&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
     -- call the previous hook, in case there are still some containers in the savefile&lt;br /&gt;
     old_on_load(cfg)&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local old_on_save = wesnoth.game_events.on_save&lt;br /&gt;
 function wesnoth.game_events.on_save()&lt;br /&gt;
     -- call the previous hook, in case it had some containers to store&lt;br /&gt;
     local cfg = old_on_save()&lt;br /&gt;
     -- add our own container to them&lt;br /&gt;
     table.insert(cfg, { &amp;quot;my_data&amp;quot;, { value = level_local_data } })&lt;br /&gt;
     -- tell the engine to store them in the savefile&lt;br /&gt;
     return cfg&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: since the ''on_load'' hook is called very early in the scenario, it cannot be set inside a [lua] tag in an [event], not even a ''preload'' one. It has to be set inside a [lua] tag outside or at [scenario] level.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: Some tag names are reserved for engine use and should not be modified using the above on_save/on_load method. These tag names are:&lt;br /&gt;
 &amp;quot;color_palette&amp;quot;, &amp;quot;color_range&amp;quot;, &amp;quot;era&amp;quot;, &amp;quot;event&amp;quot;, &amp;quot;generator&amp;quot;,&lt;br /&gt;
 &amp;quot;label&amp;quot;, &amp;quot;lua&amp;quot;, &amp;quot;menu_item&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;side&amp;quot;, &amp;quot;sound_source&amp;quot;, &amp;quot;story&amp;quot;,&lt;br /&gt;
 &amp;quot;terrain_graphics&amp;quot;, &amp;quot;time&amp;quot;, &amp;quot;time_area&amp;quot;, &amp;quot;tunnel&amp;quot;, &amp;quot;variables&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.fire_event ====&lt;br /&gt;
&lt;br /&gt;
Fires all the WML events with the given name. Optional parameters allow passing two locations and two tables. These parameters will be matched against the [filter], [filter_second], [filter_attack], and [filter_second_attack] of any event handler, and are used to fill the WML variables &amp;quot;unit&amp;quot;, &amp;quot;second_unit&amp;quot;, &amp;quot;weapon&amp;quot;, and &amp;quot;second_weapon&amp;quot;. These parameters can also be read through ''current.event_context''. The function returns a boolean indicating whether the game state was modified.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire_event(&amp;quot;explosion&amp;quot;, 17, 42, { damage = &amp;quot;fire&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.eval_conditional ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the conditional described by the WML table passes. Note: WML variables are substituted.&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.eval_conditional {&lt;br /&gt;
   { &amp;quot;have_unit&amp;quot;, { id = &amp;quot;hero&amp;quot; } },&lt;br /&gt;
   { &amp;quot;variable&amp;quot;, { name = &amp;quot;counter&amp;quot;, numerical_equals = &amp;quot;$old_counter&amp;quot; } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.tovconfig ====&lt;br /&gt;
&lt;br /&gt;
Converts a WML table into a proxy object which performs variable substitution on the fly.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;varname&amp;quot;, &amp;quot;to_be_deleted&amp;quot;)&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;to_be_deleted&amp;quot; }              -- correct&lt;br /&gt;
 wesnoth.wml_actions.clear_variable { name = &amp;quot;$varname&amp;quot; }                    -- error: try to delete a variable literally called &amp;quot;$varname&amp;quot;&lt;br /&gt;
 wesnoth.wml_actions.clear_variable(wesnoth.tovconfig { name = &amp;quot;$varname&amp;quot; }) -- correct: &amp;quot;$varname&amp;quot; is replaced by &amp;quot;to_be_deleted&amp;quot; at the right time&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_action_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to fire WML actions. Returns the table. The fields of the table are then simple wrappers around a call to [[#wesnoth.fire]].&lt;br /&gt;
&lt;br /&gt;
 local W = helper.set_wml_action_metatable {}&lt;br /&gt;
 W.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
==== helper.wml_error ====&lt;br /&gt;
&lt;br /&gt;
Interrupts the current execution and displays a chat message that looks like a WML error.&lt;br /&gt;
&lt;br /&gt;
 local names = cfg.name or helper.wml_error(&amp;quot;[clear_variable] missing required name= attribute.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== helper.literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__literal'' field of its argument if it is a userdata, the argument itself otherwise. This function is meant to be called when a WML action handler can be called indifferently from WML (hence receiving a userdata) or from Lua (hence possibly receiving a table).&lt;br /&gt;
&lt;br /&gt;
 function wml_actions.display_literal_value(cfg)&lt;br /&gt;
    cfg = helper.literal(cfg)&lt;br /&gt;
    wesnoth.message(tostring(cfg.value)) &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note: when the argument is a plain table, the function returns it as is. In particular, modifying the fields of the returned table causes the original table to be modified too.&lt;br /&gt;
&lt;br /&gt;
==== helper.parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_literal ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_literal'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
==== helper.shallow_parsed ====&lt;br /&gt;
&lt;br /&gt;
Returns the ''__shallow_parsed'' field of its argument if it is a userdata, the argument itself otherwise. See also [[#helper.literal]].&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ScenarioWML&amp;diff=56214</id>
		<title>ScenarioWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ScenarioWML&amp;diff=56214"/>
		<updated>2015-04-09T05:04:53Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* The [scenario] tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== the toplevel tags [multiplayer], [test], [tutorial], [scenario] ==&lt;br /&gt;
&lt;br /&gt;
The top level tags '''[multiplayer]''', '''[test]''', '''[tutorial]''' and '''[scenario]''' are all formatted the same way.&lt;br /&gt;
The difference between these tags is the way that the scenarios they describe are accessed.&lt;br /&gt;
&lt;br /&gt;
The keys '''id''' and '''next_scenario''' affect how scenarios can be accessed.&lt;br /&gt;
Whenever a scenario is won, the scenario with id=''next_scenario'' of the same tag type will be played.&lt;br /&gt;
Units from the first scenario will be available for recall in the second.&lt;br /&gt;
&lt;br /&gt;
Some scenarios can be played without playing other scenarios first&lt;br /&gt;
(in this case there is nothing on the recall list).&lt;br /&gt;
These scenarios are called ''initial scenario''s.&lt;br /&gt;
&lt;br /&gt;
A list of initial scenarios, and how to access them:&lt;br /&gt;
&lt;br /&gt;
* All '''[multiplayer]''' scenarios (without ''allow_new_game=no'') are initial scenarios listed in the multiplayer scenario selector screen (accessed by the &amp;quot;multiplayer&amp;quot; button).&lt;br /&gt;
&lt;br /&gt;
* The '''[test]''' scenario with the attribute '''id=test''' is an initial scenario. This test scenario can be accessed by running the game in test mode. (note: this is NOT the same as debug mode. It can be accessed using -t or --test)&lt;br /&gt;
&lt;br /&gt;
* The '''[tutorial]''' scenario with the attribute '''id=tutorial''' is an initial scenario. The tutorial is accessed by clicking on the &amp;quot;tutorial&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
* Any '''[scenario]''' scenario with an id listed in the value of ''first_scenario'' in a campaign tag (see [[CampaignWML]]) is an initial scenario accessed by selecting that campaign after clicking on the &amp;quot;campaign&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
== The [scenario] tag ==&lt;br /&gt;
&lt;br /&gt;
The following keys and tags are recognized in '''[scenario]''' tags:&lt;br /&gt;
&lt;br /&gt;
* '''id''': A unique identifier for this scenario. All scenarios must have an id. Can't clash with '''id''' used in '''[multiplayer]''' tags.&lt;br /&gt;
&lt;br /&gt;
* '''next_scenario''': The id of the scenario to load when the current one is won. This can be changed dynamically, to build non-linear campaigns.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) only for multiplayer maps. Will show up as a tooltip when mousing over the minimap in the multiplayer setup screen.&lt;br /&gt;
&lt;br /&gt;
* '''name''': (translatable) is shown in several places in the level, including the intro screen. It is also the default name for saves on the level.&lt;br /&gt;
&lt;br /&gt;
* '''map_data''': inputs valid Wesnoth map data. See [[BuildingMaps]] for a description of the Wesnoth map syntax.&lt;br /&gt;
&lt;br /&gt;
* '''turns''': sets an event on turn ''turns'' causing the player to lose. Use ''-1'' to have no turn limit (default). See also [[EventWML]]&lt;br /&gt;
&lt;br /&gt;
* '''turn_at''': the turn to start on (default=1)&lt;br /&gt;
&lt;br /&gt;
: Note that none of the regular start-of-turn behavior, including poison damage, healing, income and refreshing unit movement and status, will occur before the start of turn 2.  All start-of-turn [[EventWML|WML events]] will still be fired, however.&lt;br /&gt;
&lt;br /&gt;
* '''random_start_time''': controls random starting time of day. Possible values are yes and no or list of possible start times; starting from 1 to number of times. for example ''random_start_time=2,3,5,6'' (default=no)&lt;br /&gt;
&lt;br /&gt;
* '''music''': the music file relative to ''./music/'' to play during the scenario&lt;br /&gt;
&lt;br /&gt;
* '''[music]''': specifies the music tracks to play during this scenario, see [[MusicListWML]].&lt;br /&gt;
&lt;br /&gt;
* '''defeat_music''': specifies a comma-separated list of music tracks which may be chosen to play on defeat. If not provided, the default in [[GameConfigWML]] is used instead. May be overridden by [[DirectActionsWML|endlevel]] clauses.&lt;br /&gt;
&lt;br /&gt;
* '''victory_music''': specifies a comma-separated list of music tracks which may be chosen to play on victory. If not provided, the default in [[GameConfigWML]] is used instead. May be overridden by [[DirectActionsWML|endlevel]] clauses.&lt;br /&gt;
&lt;br /&gt;
* '''theme''': the name of the UI theme that should be used when playing this scenario.&lt;br /&gt;
&lt;br /&gt;
* '''victory_when_enemies_defeated''': when this is set to '''yes''' (default), the player wins once all non-allied units with '''canrecruit=yes''' (aka leaders) are killed. (Currently this only controls the win condition for when all enemies are defeated; it does not prevent the player from losing if he has no leader.) See Also [[SideWML]]. When this value is true the following keys can be used:&lt;br /&gt;
** '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
** '''carryover_add''': if true the gold will be added to the starting gold the next scenario, if false the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is false.&lt;br /&gt;
* '''remove_from_carryover_on_leaders_loss''': {{DevFeature1.11}} when this is set to '''yes''' (default), for sides who lost all their leaders, carryover will be removed. {{DevFeature1.11|15}} this was renamed to '''remove_from_carryover_on_defeat'''&lt;br /&gt;
&lt;br /&gt;
* '''remove_from_carryover_on_defeat''': {{DevFeature1.11|15}} when this is set to '''yes''' (default), for sides who got defeated (according to the side.defeat_condition), carryover will be removed.&lt;br /&gt;
&lt;br /&gt;
* '''disallow_recall''': when this is set to 'no'(default), the player is allowed to recall units from previous scenarios.&lt;br /&gt;
&lt;br /&gt;
* '''experience_modifier''': the percentage that required XP to level up (for all units in the scenario) is multiplied by. Default 100. Note that when used in a campaign, weird things (like units being above the required XP to level up) can happen if this value is different for different scenarios.&lt;br /&gt;
&lt;br /&gt;
* '''[story]''': describes the intro screen. See [[IntroWML]]&lt;br /&gt;
&lt;br /&gt;
* '''[label]''': sets a label&lt;br /&gt;
** '''x''', '''y''': location to set label&lt;br /&gt;
** '''text''': the label&lt;br /&gt;
&lt;br /&gt;
* '''[item]''': places an item on map. See [[InterfaceActionsWML#.5Bitem.5D|InterfaceActionsWML]].&lt;br /&gt;
&lt;br /&gt;
* '''[time]''': how a day should progress. See [[TimeWML]]&lt;br /&gt;
* '''current_tod''': The time of day slot number (starting from zero) active at scenario start.&lt;br /&gt;
&lt;br /&gt;
* '''[time_area]''': how a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag&lt;br /&gt;
** takes x and y coordinates.&lt;br /&gt;
** '''[time]''': how a day should progress in those locations. See [[TimeWML]]&lt;br /&gt;
** '''current_time''': The time slot number (starting with zero) active at the creation of the area.{{DevFeature1.11}}&lt;br /&gt;
** time areas can be used in events, assigned identifiers, and removed at discretion. They also accept complete Standard Location Filters. See [[DirectActionsWML]].&lt;br /&gt;
&lt;br /&gt;
* '''[side]''': describes one player. See [[SideWML]]&lt;br /&gt;
&lt;br /&gt;
* '''[event]''': describes an event that may be triggered at a certain point of the scenario. See [[EventWML]]&lt;br /&gt;
&lt;br /&gt;
* '''map_generation''': another way to generate a map. The map will be generated randomly&lt;br /&gt;
** '''default''': the default random map generator&lt;br /&gt;
&lt;br /&gt;
* '''[generator]''' if this is present, the map and scenario will be generated randomly. See [[MapGeneratorWML]]&lt;br /&gt;
&lt;br /&gt;
The following keys and subtags are additionally recognized in '''[multiplayer]''' scenarios:&lt;br /&gt;
* '''force_lock_settings''': {{DevFeature1.11}} provides a default value for [[SideWML]] ''lock'' attributes and forces the &amp;quot;Use map settings&amp;quot; to be checked and disabled. This is useful if author wants to limit game customization in order to keep the scenario/campaign balanced. Individual options can still be enabled if this key is set to '''yes'''. E.g. color selection can be enabled by explicitly setting ''color_lock=yes'' in [[SideWML]].&lt;br /&gt;
* '''new_game_title''': {{DevFeature1.11}} if provided will be used instead of '''name''' for campaign entry points.&lt;br /&gt;
* '''allow_new_game''': (default=yes) allow/prevent the scenario to be listed in the game configuration screen. This is intended for multiplayer campaigns with multiple entry points.&lt;br /&gt;
* '''allow_era''': {{DevFeature1.11}} a list of era ids. Only the eras with matching ids will be allowed to be played with this scenario.&lt;br /&gt;
* '''disallow_era''': {{DevFeature1.11}} a list of era ids. Only the eras with matching ids will not be allowed to be played with this scenario. Cannot be used in parallel with allow_era.&lt;br /&gt;
* '''ignore_incompatible_era''': {{DevFeature1.11}} a list of era ids. The eras with matching ids will be considered compatible with this scenario regardless their dependencies.&lt;br /&gt;
* '''allow_modification''': {{DevFeature1.11}} same as allow_era, but for modifications.&lt;br /&gt;
* '''disallow_modification''': {{DevFeature1.11}} same as disallow_era, but for modifications. Cannot be used in parallel with allow_modification.&lt;br /&gt;
* '''ignore_incompatible_modification''': {{DevFeature1.11}} same as ignore_incompatible_era, but for modifications.&lt;br /&gt;
* '''force_modification''': {{DevFeature1.11}} a list of modification ids. The specified modifications must be enabled to play this scenario.&lt;br /&gt;
* '''[options]''': {{DevFeature1.11}} custom options. See [[OptionWML]] for details.&lt;br /&gt;
* '''require_scenario''': {{DevFeature1.13|0}} In a multiplayer scenario, this indicates that the scenario file is not enough (you have custom assets like terrain or additional unit art) and other player must download the full add-on not just the scenario WML to join a game. This will also mean that the '''addon_min_version''' attribute will control the minimum version number of your add-on which is compatible with this version.&lt;br /&gt;
&lt;br /&gt;
== Scenario End Conditions ==&lt;br /&gt;
&lt;br /&gt;
In this section we will give a more precise explanation of things that can cause a scenario to end. This information applies to {{DevFeature1.11|15}}.&lt;br /&gt;
&lt;br /&gt;
* At the '''end of every turn''', the turn number will be compared with the turn limit. &lt;br /&gt;
** If we pass the limit, the ''time over'' event will fire. If turns are not added by WML in response to this event, then the scenario will immediately end in defeat. [[EventWML#The_.27name.27_Key_.28Mandatory.29]]&lt;br /&gt;
* At the '''beginning of any turn''', and at '''the end of any user or ai action''', the victory conditions will be checked. This will result either in the scenario ending or continuing. The procedure for this is as follows:&lt;br /&gt;
** Every side will have its ''defeat_condition'' evaluated based on the units it currently has on the board. [[SideWML]]&lt;br /&gt;
*** At this time, villages of defeated sides will be unflagged, and if ''remove_from_carryover_on_defeat = yes'' then their carryover will be cleared as well.&lt;br /&gt;
** If any two not-defeated sides are enemies, the scenario will continue.&lt;br /&gt;
*** At this time, the ''enemies defeated'' event will fire.&lt;br /&gt;
** Furthermore, if ''victory_when_enemies_defated=no'' and there exists a human controlled side, then the scenario will continue.&lt;br /&gt;
*** The human controlled side may be local or remote, for networked mp play.&lt;br /&gt;
** If neither of these conditions is met then the scenario will end. &lt;br /&gt;
***In victory of defeat according to whether a local human-controlled side is not defeated.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=SideWML&amp;diff=56213</id>
		<title>SideWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=SideWML&amp;diff=56213"/>
		<updated>2015-04-09T04:45:42Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* the [side] tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== the [side] tag ==&lt;br /&gt;
&lt;br /&gt;
The [side] tag is used to describe a side in a particular scenario.&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized:&lt;br /&gt;
&lt;br /&gt;
* '''side''': a number. The leader of this side is placed on the tile represented by this number (see [[BuildingMaps]]). When defining sides, they must be defined in order since the side number is checked against the number of sides seen so far. Currently, the Multiplayer server rejects entering a scenario with more than 9 sides, even if those extra sides are AI sides. &lt;br /&gt;
&lt;br /&gt;
* '''controller''': how moves for this side should be inputted.&lt;br /&gt;
** '''ai''': the Wesnoth AI makes this side's moves. This is the default setting.&lt;br /&gt;
** '''human''': a player controls this side's moves.&lt;br /&gt;
** '''null''': the side doesn't get a turn to move and doesn't have a leader generated from the contents of the [side] tag. (It still can get units from [unit] tags in the [side] tag.) Events that would usually occur on the side's turn will not take place. This includes healing (ability, villages and rest) and ''side turn'' events.&lt;br /&gt;
** '''a number''': {{DevFeature1.11}} gives this side's control to a side with '''side''' matching the number (multiplayer only).&lt;br /&gt;
&lt;br /&gt;
* '''no_leader''': if &amp;quot;no&amp;quot; (default), then keys describing a unit which will begin on the side's keep will be the remainder of the '''[side]''' tag, See [[SingleUnitWML]]. Note that if the keys '''x''', '''y''' are included, the leader will begin there regardless of keep location. If this side has a recall list from a previous level, then the recall list will be searched for a leader (using '''canrecruit=yes''') and if one is found it will be used instead of the one described in the '''[side]''' tag. Typical keys used for defining the leader unit are '''type''' (mandatory), '''id''', '''name''' and '''unrenamable=yes''', see [[SingleUnitWML]].&lt;br /&gt;
&lt;br /&gt;
* '''recruit''': a list of unit types. At the beginning of the scenario, the side gains recruitment of these units.&lt;br /&gt;
&lt;br /&gt;
* '''gold''': the starting gold for this side. Default 100. (If gold is carried over from a previous scenario, this value is the minimum starting gold.)&lt;br /&gt;
&lt;br /&gt;
* '''income''': the base income for this side, default 0. This is added to ''base_income'', '''[game_config]''' to determine the side's base income. (see [[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''hidden''': if 'yes', side is not shown in status table.&lt;br /&gt;
&lt;br /&gt;
* '''fog''': if 'yes', this side cannot see any tiles it is not within vision of, except at the start. Please note that the AI currently ignores the fog.&lt;br /&gt;
&lt;br /&gt;
* '''fog_data''': describes the area which this team has de-fogged, using the same format as shroud_data. (This is not particularly useful when defining a side, though, as the game will recalculate fog as turns begin and end. {{DevFeature1.11}}It is used in saved games.)&lt;br /&gt;
&lt;br /&gt;
* '''[fog_override]''' {{DevFeature1.11}} With keys x= and y=, this records the hexes that have been cleared (multiturn) with {{tag|DirectActionsWML|lift_fog}}.&lt;br /&gt;
&lt;br /&gt;
* '''shroud''': if 'yes', this side cannot see any tiles it has not moved within sight of. Please note that the AI currently ignores the shroud. NOTE: with shroud=no, this team *ignores* shroud, so it is not possible to modify it using place_shroud and remove_shroud tags. If you want to do so, use &amp;quot;shroud=yes&amp;quot; and place_shroud/remove_shroud tags.&lt;br /&gt;
&lt;br /&gt;
* '''shroud_data''': describes the area which this team has de-shrouded. An example:&lt;br /&gt;
 |&lt;br /&gt;
 |00011111000&lt;br /&gt;
:This would leave the first column on the map unaltered and would change the second column for 11 tiles. A '0' means: shrouded, '1' means unshrouded. You can either call an external file using {@filename}  (see [[PreprocessorRef]]) or place the data in quotes. For making an external file see [[BuildingScenariosShroudData]].&lt;br /&gt;
&lt;br /&gt;
* '''persistent''': whether the side exists in any other scenarios. If ''yes'', then ''save_id'' (see below) is used to identify the side in other scenarios. Defaults to ''yes'' for sides with a human controller, and ''no'' for ai controlled sides.&lt;br /&gt;
&lt;br /&gt;
* '''save_id''': defaults to the leader's ''id'' if available, 'Unknown' otherwise. The ID of the side with respect to the previous and next scenarios. Used to carry over the side's recall list (including the side's leader), recruitment list, and starting gold from scenario to scenario. Also used for the side's displayed name in the victory gold-calculation dialog.&lt;br /&gt;
&lt;br /&gt;
* '''team_name''': a non translatable string representing the team's description. Sides with the same team_name are allied. Default ''side''. ''team_name'' is now a comma-separated list of teams that the side is on.&lt;br /&gt;
&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Default ''team_name''.&lt;br /&gt;
&lt;br /&gt;
* '''current_player''': a translatable string representing the player's or leader's name. Defaults to the leader's id; if the side's leader is a human player in multiplayer, the default is the player's username.&lt;br /&gt;
&lt;br /&gt;
* '''color''': May be either a numeric color index or a color name (e.g. 'blue', 'purple', 'orange', etc.).  The numeric form is deprecated. The default list of numbers and corresponding colors can be found in data/core/team_colors.cfg.&lt;br /&gt;
&lt;br /&gt;
* '''flag''': a custom flag animation to use instead of the default one to mark captured villages. An automatic side-coloring is applied.&lt;br /&gt;
** Example animation that has three frames and loops every 750ms: ''flag=misc/myflag-1.png:250,misc/myflag-2.png:250,misc/myflag-3.png:250''&lt;br /&gt;
&lt;br /&gt;
* '''flag_icon''': a custom flag icon to indicate the side playing in the statusbar (a size of 24x16 is recommended). An automatic side-coloring is applied.&lt;br /&gt;
&lt;br /&gt;
* '''village_gold''': the amount of gold given to this side per village it controls per turn. Default specified in ''village_income'', '''[game_config]''' ([[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''village_support''': {{DevFeature1.11}} the number of unit levels this side is able to support (does not pay upkeep on) per village it controls. Default specified in ''village_support'', '''[game_config]''' ([[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''recall_cost''': the amount of gold it costs to recall a unit. Default specified in ''recall_cost'', '''[game_config]''' ([[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''share_maps''': whether sides allied with this side see all terrains that this side sees, if they are on shroud.&lt;br /&gt;
&lt;br /&gt;
* '''share_view''': whether sides allied with this side see the units that this side sees, if they are on FoW (fog).&lt;br /&gt;
&lt;br /&gt;
* '''scroll_to_leader''': optional. If 'no', scroll to the leader is not performed on the start of each turn. (default: yes)&lt;br /&gt;
&lt;br /&gt;
* '''suppress_end_turn_confirmation''': {{DevFeature1.11}} If &amp;quot;yes&amp;quot;, then the player will not be asked to confirm ending their turn even if they have not done anything. This is provided for some (probably few) user-made scenarios in which players often skip their turns. (default: no)&lt;br /&gt;
&lt;br /&gt;
* '''[ai]''' if '''controller=ai''', gives parameters to the AI. See [[AiWML]].&lt;br /&gt;
&lt;br /&gt;
* '''[village]''' describes a village the side begins in control of.&lt;br /&gt;
** ''x'', ''y'' the location of the village. If the pair of coordinates is not a village or is duplicated in another [village] tag, behaviour is undefined. Recent game engine or wmllint should warn about these.&lt;br /&gt;
&lt;br /&gt;
* '''[unit]''' describes a unit which begins on the side. See [[SingleUnitWML]]. If the side has a recall list and the unit is not given a location, it will start on the recall list. Note that the ''side'' attribute under '''[unit]''' will be ignored, as the side will come from the ''side'' attribute of '''[side]'''.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;s&amp;gt;'''fight_on_without_leader'''&amp;lt;/s&amp;gt;: {{DevFeature1.11|13}} this side will not be considered &amp;quot;defeated&amp;quot; until they have no units, for the purposes of determining whether the scenario ends or not. {{DevFeature1.11|15}} This attribute was replaced with defeat_condition&lt;br /&gt;
&lt;br /&gt;
* '''defeat_condition''' {{DevFeature1.11|15}} Specifies when a side is considered ''defeated'' this is checked ''for all sides'', after every player action and at the beginning of every turn.&lt;br /&gt;
** '''no_leader_left''': (default) The side is considered defeated if it has no units with canrecruit=yes&lt;br /&gt;
** '''no_units_left''': The side is defeated as soon as it has no units left.&lt;br /&gt;
** '''never''': The side is never considered defeated.&lt;br /&gt;
** '''always''': The side is always considered defeated.&lt;br /&gt;
&lt;br /&gt;
:  For the meaning and significance of ''defeated'', see [[ScenarioWML#Scenario_End_Conditions]]&lt;br /&gt;
&lt;br /&gt;
The following keys are multiplayer only:&lt;br /&gt;
&lt;br /&gt;
* '''allow_player''': if false then this side will not be allowed to be modified and will be hidden during game creation. False also prevents this side from being included in shuffle sides. Defaults to yes.&lt;br /&gt;
&lt;br /&gt;
* '''disallow_observers''': prevents observers from seeing this side turn. (default: no)&lt;br /&gt;
&lt;br /&gt;
* '''disallow_shuffle''': {{DevFeature1.13|0}} do not shuffle this side if the &amp;quot;shuffle sides&amp;quot; option is used. (Usually all playable sides are shuffled.) (default: no)&lt;br /&gt;
&lt;br /&gt;
* '''chose_random''': {{DevFeature1.13|0}} indicates if a side chose a random faction during creation &lt;br /&gt;
&lt;br /&gt;
* '''controller_lock''': {{DevFeature1.11}} if true then this side's controller (&amp;quot;Player/Type&amp;quot;) modification is limited. It is bound to the '''controller''' attribute in [[SideWML]].&lt;br /&gt;
&lt;br /&gt;
* '''team_lock''': if true then this side's team is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''color_lock''': if true then this side's color is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''gold_lock''': if true then this side's gold is not allowed to be modified. &lt;br /&gt;
&lt;br /&gt;
* '''income_lock''': if true then this side's income is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''faction_lock''': {{DevFeature1.11|16}} if true then this side's faction is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''leader_lock''': {{DevFeature1.11|16}} if true then this side's leader (type or gender) is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''faction''': if valid faction id is provided then this side's faction will default to it.&lt;br /&gt;
&lt;br /&gt;
* '''faction_from_recruit''': if true then this side will be locked to the faction that matches the recruits better.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} N.B. the ''lock'' attributes use [[ScenarioWML]] '''force_lock_settings''' as their default value. I.e. if no value to ''lock'' was set, it will take '''force_lock_settings''' value.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[EraWML]]&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=SideWML&amp;diff=56212</id>
		<title>SideWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=SideWML&amp;diff=56212"/>
		<updated>2015-04-09T04:44:45Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* the [side] tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== the [side] tag ==&lt;br /&gt;
&lt;br /&gt;
The [side] tag is used to describe a side in a particular scenario.&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized:&lt;br /&gt;
&lt;br /&gt;
* '''side''': a number. The leader of this side is placed on the tile represented by this number (see [[BuildingMaps]]). When defining sides, they must be defined in order since the side number is checked against the number of sides seen so far. Currently, the Multiplayer server rejects entering a scenario with more than 9 sides, even if those extra sides are AI sides. &lt;br /&gt;
&lt;br /&gt;
* '''controller''': how moves for this side should be inputted.&lt;br /&gt;
** '''ai''': the Wesnoth AI makes this side's moves. This is the default setting.&lt;br /&gt;
** '''human''': a player controls this side's moves.&lt;br /&gt;
** '''null''': the side doesn't get a turn to move and doesn't have a leader generated from the contents of the [side] tag. (It still can get units from [unit] tags in the [side] tag.) Events that would usually occur on the side's turn will not take place. This includes healing (ability, villages and rest) and ''side turn'' events.&lt;br /&gt;
** '''a number''': {{DevFeature1.11}} gives this side's control to a side with '''side''' matching the number (multiplayer only).&lt;br /&gt;
&lt;br /&gt;
* '''no_leader''': if &amp;quot;no&amp;quot; (default), then keys describing a unit which will begin on the side's keep will be the remainder of the '''[side]''' tag, See [[SingleUnitWML]]. Note that if the keys '''x''', '''y''' are included, the leader will begin there regardless of keep location. If this side has a recall list from a previous level, then the recall list will be searched for a leader (using '''canrecruit=yes''') and if one is found it will be used instead of the one described in the '''[side]''' tag. Typical keys used for defining the leader unit are '''type''' (mandatory), '''id''', '''name''' and '''unrenamable=yes''', see [[SingleUnitWML]].&lt;br /&gt;
&lt;br /&gt;
* '''recruit''': a list of unit types. At the beginning of the scenario, the side gains recruitment of these units.&lt;br /&gt;
&lt;br /&gt;
* '''gold''': the starting gold for this side. Default 100. (If gold is carried over from a previous scenario, this value is the minimum starting gold.)&lt;br /&gt;
&lt;br /&gt;
* '''income''': the base income for this side, default 0. This is added to ''base_income'', '''[game_config]''' to determine the side's base income. (see [[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''hidden''': if 'yes', side is not shown in status table.&lt;br /&gt;
&lt;br /&gt;
* '''fog''': if 'yes', this side cannot see any tiles it is not within vision of, except at the start. Please note that the AI currently ignores the fog.&lt;br /&gt;
&lt;br /&gt;
* '''fog_data''': describes the area which this team has de-fogged, using the same format as shroud_data. (This is not particularly useful when defining a side, though, as the game will recalculate fog as turns begin and end. {{DevFeature1.11}}It is used in saved games.)&lt;br /&gt;
&lt;br /&gt;
* '''[fog_override]''' {{DevFeature1.11}} With keys x= and y=, this records the hexes that have been cleared (multiturn) with {{tag|DirectActionsWML|lift_fog}}.&lt;br /&gt;
&lt;br /&gt;
* '''shroud''': if 'yes', this side cannot see any tiles it has not moved within sight of. Please note that the AI currently ignores the shroud. NOTE: with shroud=no, this team *ignores* shroud, so it is not possible to modify it using place_shroud and remove_shroud tags. If you want to do so, use &amp;quot;shroud=yes&amp;quot; and place_shroud/remove_shroud tags.&lt;br /&gt;
&lt;br /&gt;
* '''shroud_data''': describes the area which this team has de-shrouded. An example:&lt;br /&gt;
 |&lt;br /&gt;
 |00011111000&lt;br /&gt;
:This would leave the first column on the map unaltered and would change the second column for 11 tiles. A '0' means: shrouded, '1' means unshrouded. You can either call an external file using {@filename}  (see [[PreprocessorRef]]) or place the data in quotes. For making an external file see [[BuildingScenariosShroudData]].&lt;br /&gt;
&lt;br /&gt;
* '''persistent''': whether the side exists in any other scenarios. If ''yes'', then ''save_id'' (see below) is used to identify the side in other scenarios. Defaults to ''yes'' for sides with a human controller, and ''no'' for ai controlled sides.&lt;br /&gt;
&lt;br /&gt;
* '''save_id''': defaults to the leader's ''id'' if available, 'Unknown' otherwise. The ID of the side with respect to the previous and next scenarios. Used to carry over the side's recall list (including the side's leader), recruitment list, and starting gold from scenario to scenario. Also used for the side's displayed name in the victory gold-calculation dialog.&lt;br /&gt;
&lt;br /&gt;
* '''team_name''': a non translatable string representing the team's description. Sides with the same team_name are allied. Default ''side''. ''team_name'' is now a comma-separated list of teams that the side is on.&lt;br /&gt;
&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Default ''team_name''.&lt;br /&gt;
&lt;br /&gt;
* '''current_player''': a translatable string representing the player's or leader's name. Defaults to the leader's id; if the side's leader is a human player in multiplayer, the default is the player's username.&lt;br /&gt;
&lt;br /&gt;
* '''color''': May be either a numeric color index or a color name (e.g. 'blue', 'purple', 'orange', etc.).  The numeric form is deprecated. The default list of numbers and corresponding colors can be found in data/core/team_colors.cfg.&lt;br /&gt;
&lt;br /&gt;
* '''flag''': a custom flag animation to use instead of the default one to mark captured villages. An automatic side-coloring is applied.&lt;br /&gt;
** Example animation that has three frames and loops every 750ms: ''flag=misc/myflag-1.png:250,misc/myflag-2.png:250,misc/myflag-3.png:250''&lt;br /&gt;
&lt;br /&gt;
* '''flag_icon''': a custom flag icon to indicate the side playing in the statusbar (a size of 24x16 is recommended). An automatic side-coloring is applied.&lt;br /&gt;
&lt;br /&gt;
* '''village_gold''': the amount of gold given to this side per village it controls per turn. Default specified in ''village_income'', '''[game_config]''' ([[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''village_support''': {{DevFeature1.11}} the number of unit levels this side is able to support (does not pay upkeep on) per village it controls. Default specified in ''village_support'', '''[game_config]''' ([[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''recall_cost''': the amount of gold it costs to recall a unit. Default specified in ''recall_cost'', '''[game_config]''' ([[GameConfigWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''share_maps''': whether sides allied with this side see all terrains that this side sees, if they are on shroud.&lt;br /&gt;
&lt;br /&gt;
* '''share_view''': whether sides allied with this side see the units that this side sees, if they are on FoW (fog).&lt;br /&gt;
&lt;br /&gt;
* '''scroll_to_leader''': optional. If 'no', scroll to the leader is not performed on the start of each turn. (default: yes)&lt;br /&gt;
&lt;br /&gt;
* '''suppress_end_turn_confirmation''': {{DevFeature1.11}} If &amp;quot;yes&amp;quot;, then the player will not be asked to confirm ending their turn even if they have not done anything. This is provided for some (probably few) user-made scenarios in which players often skip their turns. (default: no)&lt;br /&gt;
&lt;br /&gt;
* '''[ai]''' if '''controller=ai''', gives parameters to the AI. See [[AiWML]].&lt;br /&gt;
&lt;br /&gt;
* '''[village]''' describes a village the side begins in control of.&lt;br /&gt;
** ''x'', ''y'' the location of the village. If the pair of coordinates is not a village or is duplicated in another [village] tag, behaviour is undefined. Recent game engine or wmllint should warn about these.&lt;br /&gt;
&lt;br /&gt;
* '''[unit]''' describes a unit which begins on the side. See [[SingleUnitWML]]. If the side has a recall list and the unit is not given a location, it will start on the recall list. Note that the ''side'' attribute under '''[unit]''' will be ignored, as the side will come from the ''side'' attribute of '''[side]'''.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;s&amp;gt;'''fight_on_without_leader'''&amp;lt;/s&amp;gt;: {{DevFeature1.11|13}} this side will not be considered &amp;quot;defeated&amp;quot; until they have no units, for the purposes of determining whether the scenario ends or not. {{DevFeature1.11|15}} This attribute was replaced with defeat_condition&lt;br /&gt;
&lt;br /&gt;
* '''defeat_condition''' {{DevFeature1.11|15}} Specifies when a side is considered ''defeated'' this is checked ''for all sides'', after every player action and at the beginning of every turn.&lt;br /&gt;
** '''no_leader_left''': (default) The side is considered defeated if it has no units with canrecruit=yes&lt;br /&gt;
** '''no_units_left''': The side is defeated as soon as it has no units left.&lt;br /&gt;
** '''never''': The side is never considered defeated.&lt;br /&gt;
** '''always''': The side is always considered defeated.&lt;br /&gt;
&lt;br /&gt;
:  For the meaning and significance of ''defeated'', see [[ScenarioWML#Scenario_End_Conditions]]&lt;br /&gt;
&lt;br /&gt;
The following keys are multiplayer only:&lt;br /&gt;
&lt;br /&gt;
* '''allow_player''': if false then this side will not be allowed to be modified and will be hidden during game creation. False also prevents this side from being included in shuffle sides. Defaults to yes.&lt;br /&gt;
&lt;br /&gt;
* '''disallow_observers''': prevents observers from seeing this side turn. (default: no)&lt;br /&gt;
&lt;br /&gt;
* '''disallow_shuffle''': {{DevFeature1.13|0}} do not shuffle this side if the &amp;quot;shuffle sides&amp;quot; option is used. (Usually all playable sides are shuffled.) (deault: no)&lt;br /&gt;
&lt;br /&gt;
* '''chose_random''': {{DevFeature1.13|0}} indicates if a side chose a random faction during creation &lt;br /&gt;
&lt;br /&gt;
* '''controller_lock''': {{DevFeature1.11}} if true then this side's controller (&amp;quot;Player/Type&amp;quot;) modification is limited. It is bound to the '''controller''' attribute in [[SideWML]].&lt;br /&gt;
&lt;br /&gt;
* '''team_lock''': if true then this side's team is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''color_lock''': if true then this side's color is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''gold_lock''': if true then this side's gold is not allowed to be modified. &lt;br /&gt;
&lt;br /&gt;
* '''income_lock''': if true then this side's income is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''faction_lock''': {{DevFeature1.11|16}} if true then this side's faction is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''leader_lock''': {{DevFeature1.11|16}} if true then this side's leader (type or gender) is not allowed to be modified.&lt;br /&gt;
&lt;br /&gt;
* '''faction''': if valid faction id is provided then this side's faction will default to it.&lt;br /&gt;
&lt;br /&gt;
* '''faction_from_recruit''': if true then this side will be locked to the faction that matches the recruits better.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} N.B. the ''lock'' attributes use [[ScenarioWML]] '''force_lock_settings''' as their default value. I.e. if no value to ''lock'' was set, it will take '''force_lock_settings''' value.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[EraWML]]&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=EraWML&amp;diff=56159</id>
		<title>EraWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=EraWML&amp;diff=56159"/>
		<updated>2015-03-15T18:08:29Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* The [era] top level tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [era] top level tag ==&lt;br /&gt;
&lt;br /&gt;
This tag describes one era. An era is a set of teams to play in multiplayer.&lt;br /&gt;
&lt;br /&gt;
In the multiplayer game creation screen, an era is chosen by the host by the 'Era' option button.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[era]'''&lt;br /&gt;
* '''id''': ID of the era - must be unique. No gameplay effect&lt;br /&gt;
* '''name''': displayed name of the era.&lt;br /&gt;
* '''description''': {{DevFeature1.11}} a short description of the era.&lt;br /&gt;
* &amp;lt;span id=&amp;quot;require_era&amp;quot;&amp;gt;'''require_era'''&amp;lt;/span&amp;gt;: whether clients are required to have this era installed beforehand to be allowed join a game using this era. Possible values 'yes' (the default) and 'no'.&lt;br /&gt;
* '''allow_scenario''': {{DevFeature1.11}} a list of scenario ids. Only the scenarios with matching ids will be allowed to be played with this era.&lt;br /&gt;
* '''disallow_scenario''': {{DevFeature1.11}} a list of scenario ids. Only the scenarios with matching ids will not be allowed to be played with this era. Cannot be used in parallel with allow_scenario.&lt;br /&gt;
* '''ignore_incompatible_scenario''': {{DevFeature1.11}} a list of scenario ids. The scenarios with matching ids will be considered compatible with this era regardless their dependencies.&lt;br /&gt;
* '''allow_modification''': {{DevFeature1.11}} same as allow_scenario, but for modifications.&lt;br /&gt;
* '''disallow_modification''': {{DevFeature1.11}} same as disallow_scenario, but for modifications. Cannot be used in parallel with allow_modification.&lt;br /&gt;
* '''ignore_incompatible_modification''': {{DevFeature1.11}} same as ignore_incompatible_scenario, but for modifications.&lt;br /&gt;
* '''force_modification''': {{DevFeature1.11}} a list of modification ids. The specified modifications must be enabled to play this era.&lt;br /&gt;
* '''addon_min_version''': {{DevFeature1.13|0}} the minimum version of your add-on with which this content is backwards compatible. Compare with the version string given in [[PblWML]]. Clients in multiplayer must have add-on versions agreeing with the ''addon_min_versions'' of eachothers content in order to play, and will be prompted to update otherwise.&lt;br /&gt;
* '''[multiplayer_side]''': a faction in the era. This tag contains many of the same keys as a [side] tag (A description of the [side] tag can be found in [[SideWML]]). When a multiplayer game is played, then the [side] tag for the scenario is merged with the keys(currently, not tags) of the [multiplayer_side] tag of the faction which the side chose.&lt;br /&gt;
** '''id''': faction ID - must be unique to your era. No gameplay effect&lt;br /&gt;
** '''name''': a description that Wesnoth displays as the option selecting that faction; see [[DescriptionWML]]. Any image in this description will ''not'' use the team color.&lt;br /&gt;
** '''image''': an image to display in the option. This image will use the team color.&lt;br /&gt;
** '''flag_rgb''': often set by [http://www.wesnoth.org/macro-reference.xhtml#MAGENTA_IS_THE_TEAM_COLOR MAGENTA_IS_THE_TEAM_COLOR]&lt;br /&gt;
** '''leader''': a list of unit types. Must be present. When this faction is chosen, the side can choose any of these unit types to be the side's leader (i.e. &amp;quot;Choose your Leader&amp;quot;). They will also have the option of having one of these types being chosen randomly.&lt;br /&gt;
** '''random_leader''': if this list of types is present, it would use this list to instead to choose a random leader. If not it would use '''leader'''&lt;br /&gt;
** '''random_faction''': default 'no'. If 'yes', then when this faction is chosen, another non random faction will be randomly chosen instead. The leader will also be chosen randomly.&lt;br /&gt;
** '''choices''': Empty by default. If non-empty and the faction has '''random_faction=yes''', it is the list of the IDs of the non random factions that will be choosen randomly. If empty, any faction can be chosen.&lt;br /&gt;
** '''except''': Empty by default. If the faction has random_faction=yes, it is the list of the IDs of the non random factions that will not be choosen randomly.&lt;br /&gt;
** '''type''': the unit type of the default leader for the side. This must be present. 'random' is a valid value here and will cause a random leader choice by default.&lt;br /&gt;
** '''recruit''': a comma-separated list of unit types this faction can recruit.&lt;br /&gt;
** '''extra_recruit''': a comma-separated list of unit types appended to the leader recruitlist (see [[SingleUnitWML]]).&lt;br /&gt;
** '''terrain_liked''': an unseparated list of terrains (see [[TerrainCodesWML]]). On random maps, these terrains will determine which keep the side is assigned, attempting to put it near the listed terrains.&lt;br /&gt;
* '''[event]''': any [event]s written inside the [era] tag will get included into scenarios that are played using this era. See [[EventWML]].&lt;br /&gt;
* '''[options]''': {{DevFeature1.11}} custom options. See [[OptionWML]] for details.&lt;br /&gt;
* '''[ai]''': See [[AiWML]] for details.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[SideWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ModificationWML&amp;diff=56158</id>
		<title>ModificationWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ModificationWML&amp;diff=56158"/>
		<updated>2015-03-15T18:08:00Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* The [modification] toplevel tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [modification] toplevel tag ==&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} This tag describes a multiplayer modification. A modification is practically a bunch of events which get included into the scenario if the modification is enabled.&lt;br /&gt;
&lt;br /&gt;
The following keys/tags are recognized for '''[modification]''':&lt;br /&gt;
&lt;br /&gt;
* '''id''': identifier for the modification. Must be unique.&lt;br /&gt;
* '''name''': the name of the modification, as displayed to the user.&lt;br /&gt;
* '''description''': a brief description for the modification.&lt;br /&gt;
* '''allow_scenario''': a list of scenario ids. Only the scenarios with matching ids will be allowed to be played with this modification.&lt;br /&gt;
* '''disallow_scenario''': a list of scenario ids. Only the scenarios with matching ids will not be allowed to be played with this modification. Cannot be used in parallel with allow_scenario.&lt;br /&gt;
* '''allow_era''': same as allow_scenario, but for eras.&lt;br /&gt;
* '''disallow_era''': same as disallow_scenario, but for eras. Can't be used with allow_era.&lt;br /&gt;
* '''allow_modification''': same as allow_scenario, but for modifications.&lt;br /&gt;
* '''disallow_modification''': same as disallow_scenario, but for modifications. Can't be used with allow_modification.&lt;br /&gt;
* '''ignore_incompatible_scenario''': a list of scenario ids. The scenarios with matching ids will be considered compatible with this modification regardless their dependencies.&lt;br /&gt;
* '''ignore_incompatible_era''': same as ignore_incompatible_scenario, but for eras.&lt;br /&gt;
* '''ignore_incompatible_modification''': same as ignore_incompatible_scenario, but for modifications.&lt;br /&gt;
* '''require_modification''': a boolean value; if set to yes, all players have to have this modification installed to join the game. Default no.&lt;br /&gt;
* '''addon_min_version''': {{DevFeature1.13|0}} the minimum version of your add-on with which this content is backwards compatible. Compare with the version string given in [[PblWML]]. Clients in multiplayer must have add-on versions agreeing with the ''addon_min_versions'' of eachothers content in order to play, and will be prompted to update otherwise.&lt;br /&gt;
* '''[event]''': any [event] children written inside the [modification] tag will get included into scenarios that are played with this modification enabled. See [[EventWML]].&lt;br /&gt;
* '''[options]''': custom options. See [[OptionWML]] for details.&lt;br /&gt;
* '''[ai]''': See [[AiWML]] for details.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ModificationWML&amp;diff=56157</id>
		<title>ModificationWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ModificationWML&amp;diff=56157"/>
		<updated>2015-03-15T18:07:41Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* The [modification] toplevel tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [modification] toplevel tag ==&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} This tag describes a multiplayer modification. A modification is practically a bunch of events which get included into the scenario if the modification is enabled.&lt;br /&gt;
&lt;br /&gt;
The following keys/tags are recognized for '''[modification]''':&lt;br /&gt;
&lt;br /&gt;
* '''id''': identifier for the modification. Must be unique.&lt;br /&gt;
* '''name''': the name of the modification, as displayed to the user.&lt;br /&gt;
* '''description''': a brief description for the modification.&lt;br /&gt;
* '''allow_scenario''': a list of scenario ids. Only the scenarios with matching ids will be allowed to be played with this modification.&lt;br /&gt;
* '''disallow_scenario''': a list of scenario ids. Only the scenarios with matching ids will not be allowed to be played with this modification. Cannot be used in parallel with allow_scenario.&lt;br /&gt;
* '''allow_era''': same as allow_scenario, but for eras.&lt;br /&gt;
* '''disallow_era''': same as disallow_scenario, but for eras. Can't be used with allow_era.&lt;br /&gt;
* '''allow_modification''': same as allow_scenario, but for modifications.&lt;br /&gt;
* '''disallow_modification''': same as disallow_scenario, but for modifications. Can't be used with allow_modification.&lt;br /&gt;
* '''ignore_incompatible_scenario''': a list of scenario ids. The scenarios with matching ids will be considered compatible with this modification regardless their dependencies.&lt;br /&gt;
* '''ignore_incompatible_era''': same as ignore_incompatible_scenario, but for eras.&lt;br /&gt;
* '''ignore_incompatible_modification''': same as ignore_incompatible_scenario, but for modifications.&lt;br /&gt;
* '''require_modification''': a boolean value; if set to yes, all players have to have this modification installed to join the game. Default no.&lt;br /&gt;
* '''addon_min_version''': {{DevFeature1.13}} the minimum version of your add-on with which this content is backwards compatible. Compare with the version string given in [[PblWML]]. Clients in multiplayer must have add-on versions agreeing with the ''addon_min_versions'' of eachothers content in order to play, and will be prompted to update otherwise.&lt;br /&gt;
* '''[event]''': any [event] children written inside the [modification] tag will get included into scenarios that are played with this modification enabled. See [[EventWML]].&lt;br /&gt;
* '''[options]''': custom options. See [[OptionWML]] for details.&lt;br /&gt;
* '''[ai]''': See [[AiWML]] for details.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=EraWML&amp;diff=56156</id>
		<title>EraWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=EraWML&amp;diff=56156"/>
		<updated>2015-03-15T18:05:19Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* The [era] top level tag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [era] top level tag ==&lt;br /&gt;
&lt;br /&gt;
This tag describes one era. An era is a set of teams to play in multiplayer.&lt;br /&gt;
&lt;br /&gt;
In the multiplayer game creation screen, an era is chosen by the host by the 'Era' option button.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[era]'''&lt;br /&gt;
* '''id''': ID of the era - must be unique. No gameplay effect&lt;br /&gt;
* '''name''': displayed name of the era.&lt;br /&gt;
* '''description''': {{DevFeature1.11}} a short description of the era.&lt;br /&gt;
* &amp;lt;span id=&amp;quot;require_era&amp;quot;&amp;gt;'''require_era'''&amp;lt;/span&amp;gt;: whether clients are required to have this era installed beforehand to be allowed join a game using this era. Possible values 'yes' (the default) and 'no'.&lt;br /&gt;
* '''allow_scenario''': {{DevFeature1.11}} a list of scenario ids. Only the scenarios with matching ids will be allowed to be played with this era.&lt;br /&gt;
* '''disallow_scenario''': {{DevFeature1.11}} a list of scenario ids. Only the scenarios with matching ids will not be allowed to be played with this era. Cannot be used in parallel with allow_scenario.&lt;br /&gt;
* '''ignore_incompatible_scenario''': {{DevFeature1.11}} a list of scenario ids. The scenarios with matching ids will be considered compatible with this era regardless their dependencies.&lt;br /&gt;
* '''allow_modification''': {{DevFeature1.11}} same as allow_scenario, but for modifications.&lt;br /&gt;
* '''disallow_modification''': {{DevFeature1.11}} same as disallow_scenario, but for modifications. Cannot be used in parallel with allow_modification.&lt;br /&gt;
* '''ignore_incompatible_modification''': {{DevFeature1.11}} same as ignore_incompatible_scenario, but for modifications.&lt;br /&gt;
* '''force_modification''': {{DevFeature1.11}} a list of modification ids. The specified modifications must be enabled to play this era.&lt;br /&gt;
* '''addon_min_version''': {{DevFeature1.13}} the minimum version of your add-on with which this content is backwards compatible. Compare with the version string given in [[PBLWML]]. Clients in multiplayer must have add-on versions agreeing with the ''addon_min_versions'' of eachothers content in order to play, and will be prompted to update otherwise.&lt;br /&gt;
* '''[multiplayer_side]''': a faction in the era. This tag contains many of the same keys as a [side] tag (A description of the [side] tag can be found in [[SideWML]]). When a multiplayer game is played, then the [side] tag for the scenario is merged with the keys(currently, not tags) of the [multiplayer_side] tag of the faction which the side chose.&lt;br /&gt;
** '''id''': faction ID - must be unique to your era. No gameplay effect&lt;br /&gt;
** '''name''': a description that Wesnoth displays as the option selecting that faction; see [[DescriptionWML]]. Any image in this description will ''not'' use the team color.&lt;br /&gt;
** '''image''': an image to display in the option. This image will use the team color.&lt;br /&gt;
** '''flag_rgb''': often set by [http://www.wesnoth.org/macro-reference.xhtml#MAGENTA_IS_THE_TEAM_COLOR MAGENTA_IS_THE_TEAM_COLOR]&lt;br /&gt;
** '''leader''': a list of unit types. Must be present. When this faction is chosen, the side can choose any of these unit types to be the side's leader (i.e. &amp;quot;Choose your Leader&amp;quot;). They will also have the option of having one of these types being chosen randomly.&lt;br /&gt;
** '''random_leader''': if this list of types is present, it would use this list to instead to choose a random leader. If not it would use '''leader'''&lt;br /&gt;
** '''random_faction''': default 'no'. If 'yes', then when this faction is chosen, another non random faction will be randomly chosen instead. The leader will also be chosen randomly.&lt;br /&gt;
** '''choices''': Empty by default. If non-empty and the faction has '''random_faction=yes''', it is the list of the IDs of the non random factions that will be choosen randomly. If empty, any faction can be chosen.&lt;br /&gt;
** '''except''': Empty by default. If the faction has random_faction=yes, it is the list of the IDs of the non random factions that will not be choosen randomly.&lt;br /&gt;
** '''type''': the unit type of the default leader for the side. This must be present. 'random' is a valid value here and will cause a random leader choice by default.&lt;br /&gt;
** '''recruit''': a comma-separated list of unit types this faction can recruit.&lt;br /&gt;
** '''extra_recruit''': a comma-separated list of unit types appended to the leader recruitlist (see [[SingleUnitWML]]).&lt;br /&gt;
** '''terrain_liked''': an unseparated list of terrains (see [[TerrainCodesWML]]). On random maps, these terrains will determine which keep the side is assigned, attempting to put it near the listed terrains.&lt;br /&gt;
* '''[event]''': any [event]s written inside the [era] tag will get included into scenarios that are played using this era. See [[EventWML]].&lt;br /&gt;
* '''[options]''': {{DevFeature1.11}} custom options. See [[OptionWML]] for details.&lt;br /&gt;
* '''[ai]''': See [[AiWML]] for details.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[SideWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55982</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55982"/>
		<updated>2014-12-17T03:48:52Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Destructors must not throw exceptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
In C++11, any destructor which throws an exception causes the program to be immediately terminated (except in special cases).&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
Similarly, avoid writing &amp;lt;tt&amp;gt;delete&amp;lt;/tt&amp;gt; explicitly in your code. Oftentimes using a smart pointer or similar instead will improve the readability of your code, by making it obvious that you are managing memory correctly even if an exception is thrown. If you were deleting a pointer which is a member variable of an object, using a smart pointer instead may simplify your code by eliminating the need to write an explicit destructor in some cases.&lt;br /&gt;
&lt;br /&gt;
For more information, you can read about the (important) RAII idiom: http://c2.com/cgi/wiki?ResourceAcquisitionIsInitialization&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55981</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55981"/>
		<updated>2014-12-17T03:48:20Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Destructors must not throw exceptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
In C++11, any destructor which throws an exception causes the program to be immediately terminated. (Except in special cases.)&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
Similarly, avoid writing &amp;lt;tt&amp;gt;delete&amp;lt;/tt&amp;gt; explicitly in your code. Oftentimes using a smart pointer or similar instead will improve the readability of your code, by making it obvious that you are managing memory correctly even if an exception is thrown. If you were deleting a pointer which is a member variable of an object, using a smart pointer instead may simplify your code by eliminating the need to write an explicit destructor in some cases.&lt;br /&gt;
&lt;br /&gt;
For more information, you can read about the (important) RAII idiom: http://c2.com/cgi/wiki?ResourceAcquisitionIsInitialization&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55978</id>
		<title>NotSoEasyCoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55978"/>
		<updated>2014-12-14T00:13:03Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Fix a longstanding bug concerning failure to initialize a side in networked mp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Foreword ==&lt;br /&gt;
This page shows projects which are considered a good idea by the developers but which have nobody working on them so far. If you think you've got the required skill for a task go on, implement it and you've got a high chance that it'll be accepted. The remaining barrier will only be that it's done well. :-)&lt;br /&gt;
&lt;br /&gt;
If you are such a person, you should feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
If you're not, you should post a feature request and discuss your idea on the forum or IRC. A coder with better knowledge of the code might give you the green light to add your feature here.&lt;br /&gt;
&lt;br /&gt;
Anybody should feel free to add &amp;quot;clues&amp;quot; to any tasks, that is entry points, traps to avoid, person to contact to discuss and so on.&lt;br /&gt;
&lt;br /&gt;
If you plan to work on a feature, write your name at the bottom of the feature, with the date. Note that if you are too long at working on a feature I'll &amp;quot;free&amp;quot; it back (that is if you're not working on it. If you have problems implementing it, just tell us....)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Game Engine ==&lt;br /&gt;
=== add a mode to improve OOS detection in MP ===&lt;br /&gt;
We really need an optional 'pedantic mode' for MP which detects OOSes immediately, by comparing all game state information after each action and printing any mismatches. This mode will be optional because of the extra overhead it adds, and it would be very useful for debugging.&lt;br /&gt;
&lt;br /&gt;
=== Make a &amp;quot;replay actions since my last turn&amp;quot; button ===&lt;br /&gt;
&lt;br /&gt;
It would be very convenient if there an ability to replay everything your opponents just did at the &lt;br /&gt;
start of your turn, since sometimes things go out of vision or are confusing. &lt;br /&gt;
&lt;br /&gt;
The feature would be like a &amp;quot;replay since my last turn&amp;quot; menu option or button -- most likely, the best approach to implement it is to store a copy of the game_state object in playcontroller.cpp or even in resources, and to refactor the backlog object so that we can hold a &amp;quot;bookmark&amp;quot;, i.e. a pointer, to the last position in the replay that we might look to jump back to. The replay process would work by swapping out for the old gamestate, then replaying through the actions since the bookmark until we get back up to speed. The difficult part would be making sure that scenarios with scripted WML events don't break when we do this. For debugging purposes, it might be good to check that at this point we have the same gamestate we did before we clicked the button. The bookmark should only be advanced when we end our turn, and there might be perhaps need to be multiple bookmarks, one for each side, to handle what happens when a side disconnects or is reassigned.&lt;br /&gt;
&lt;br /&gt;
It would be especially helpful for MP play to have this, where special tactics with ambush units are quite common. Part of the design criteria of wesnoth is that it should be a high-level, thoughtful turn based strategy game, but you should be able to play asynchronously and not necessarily give attention to the game until your turn bell rings if you don't want to. Having ambush units and no ability to replay their movements during the opponents turn harms that goal.&lt;br /&gt;
&lt;br /&gt;
For MP play, it will require special attention to make sure that events like &amp;quot;synchronize_choice&amp;quot; are handled correctly so as not to cause out of sync errors, and also that the timer is handled correctly.&lt;br /&gt;
&lt;br /&gt;
Feature request: https://gna.org/bugs/?15334&lt;br /&gt;
&lt;br /&gt;
=== Improve WML error reporting ===&lt;br /&gt;
&lt;br /&gt;
There are many programming bugs that give very unclear or cryptic error messages when using WML. Here are some examples:&lt;br /&gt;
&lt;br /&gt;
-- When calling a macro with the wrong number of arguments, wesnoth tells the number it expected, and the number it got, and at which line number it was instantiated. However, it would be helpful if it would also tell the line number of the definition of the macro. This might be helpful if someone is redefining macros.&lt;br /&gt;
&lt;br /&gt;
-- For places where a standard unit filter is expected, if one is not found, the game should point out a problem. For places where such a filter is expected but [filter] child should not appear, if one does it should report an error and a line number. Many users have a hard time with this kind of thing.&lt;br /&gt;
&lt;br /&gt;
-- When doing scenario transitions in a campaign, if the side definitions don't matchup exactly the game tends to give unintelligible error messages. For instance, if one is transitioning and there is an AI side which does not have a leader (but it has a starting location in the map) it must have &amp;quot;no_leader = yes&amp;quot; in its [side] tag, or else when the team_builder objects enter stage two, the game will try to create a unit with an empty type, and the constructor of class unit will fail giving the error message &amp;quot;game::game_error tried to create unit with empty type&amp;quot;. This really needs to be much better. For instance, giving a line number of a problem, or suggesting that no_leader should be used. (Note that, it is often possible to debug problems like this by turning on --log-debug=team_construction at commandline but I doubt that there are any users that know about this, you would only learn from reading the C++... without such debug info, fixing things like this can literally take hours.) For that matter it's some question why the team_builder doesn't just stop trying to build a unit when it sees it doesn't have enough info...&lt;br /&gt;
&lt;br /&gt;
-- Recursive macros break the game, and not by stack overflow but by exhausting the heap. It would be nice if we could catch this and report an error.&lt;br /&gt;
&lt;br /&gt;
Many of the users of WML are students or beginners to programming, it is a big help to them to improve the error reporting of this nature -- not to mention that many veterans would appreciate as well. In part we need fixits here and there but more broadly we need a smarter system that can figure out what's really wrong when things go wrong and give helpful suggestions.&lt;br /&gt;
&lt;br /&gt;
=== Map label &amp;quot;groups&amp;quot; which can be selectively turned on and off by the user ===&lt;br /&gt;
&lt;br /&gt;
It would be nice if the user could have more control over how map labels are displayed, for instance to be able to check on / off labels made by certain players, and for custom scenarios, to be able to make custom classes which the use can turn on or off. This might be helpful for custom scenarios esp. which might have some technical info they want to show, but which it might be messy to display all of the time. The hard part of this is that there should ideally be a gui to work with the map labels, although maybe this need could be worked around or simplified somehow.&lt;br /&gt;
&lt;br /&gt;
=== Add a new damage stats calculation mode to support scenarios with extremely high stats ===&lt;br /&gt;
&lt;br /&gt;
Most players use the damage calculation window constantly when they play so that they can see what to expect from various attacks. The way the game is currently set up, when a unit is selected, as soon as another unit is moused over the stats for an attack will be calculated, whether or not the user actually brings up the window.&lt;br /&gt;
&lt;br /&gt;
The probabilities for the various outcomes are calculated by explicitly calculating the distribution of attacker and defender hp / slowed status after each swing by either party, one swing at a time. Thus at the end we get exact probabilities of the possible outcomes.&lt;br /&gt;
&lt;br /&gt;
However, this comes at a cost -- the running time of the calculation can in the worst case be something like O( attacker_hp * defender_hp * total_number_of_strikes). In default era wesnoth (and in much of UMC) this is fine because units don't get extremely high hp values. However in some UMC units do get extremely high hp, and many will also have specials like drain and berzerk, and may have many different weapons as well. At some point these scenarios become unplayable even on a machine of moderate specs because mousing over any unit causes &amp;gt; 10 seconds of lag during which the game becomes unresponsive, trying to calculate attack outcomes.&lt;br /&gt;
&lt;br /&gt;
In these cases, it would be better to give an &amp;quot;inexact&amp;quot; damage prediction, based on just simulating a few thousand attacks and plotting the results. Since it's a monte carlo algorithm rather than an exact algorithm, there will be some error, but if it makes the game playable then it's clearly an improvement, and anyways for &amp;quot;extreme stats&amp;quot; battles with high strikes and damage, the outcome is in a sense less random anyways because the outcomes with inordinate amounts of hits and misses are more and more rare (law of large numbers), so the error shouldn't actually be terribly significant.&lt;br /&gt;
&lt;br /&gt;
If there were an advanced preference that caused the predictions to use such an algorithm instead of the current one, so that the user could turn it on if they start to get problems, it would eliminate a significant headache for some UMC.&lt;br /&gt;
&lt;br /&gt;
== MP Related ==&lt;br /&gt;
&lt;br /&gt;
=== Automatically resolve add-on dependencies ===&lt;br /&gt;
&lt;br /&gt;
In 1.11 add-ons may declare dependencies. A related easy coding task is to allow the user to force breaking dependencies.&lt;br /&gt;
&lt;br /&gt;
A related goal which would be greatly beneficial would be that wesnoth can automatically resolve the dependencies by fetching the add-ons from the download server, when in the MP-lobby the user tries to join a game with a dependency they don't meet. A dialog would ideally be provided as well, or perhaps a preference.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?21705&lt;br /&gt;
&lt;br /&gt;
Even older: https://gna.org/bugs/?9683&lt;br /&gt;
&lt;br /&gt;
=== Gold graph ===&lt;br /&gt;
&lt;br /&gt;
Make a graph feature, presumably in a dialog, that helps depict the history of the game. For example it could display army value, army + bank value, number of villages tagged, luck swings... the purpose would be to assist spectators of a live game / spectators of a replay to understand the history of the game. It would be particularly helpful with AI development, by helping AI developers to identify key points where one of the AI is making a big mistake. &lt;br /&gt;
&lt;br /&gt;
A possible nice feature for this purpose would be to allow the user to click on the graph at key points which would trigger the &amp;quot;back to turn&amp;quot; mechanism to jump back in the replay, or automatically play the replay forwards from the beginning to that point... etc.&lt;br /&gt;
&lt;br /&gt;
Related email on dev-talk: https://mail.gna.org/public/wesnoth-dev/2014-02/msg00089.html&lt;br /&gt;
&lt;br /&gt;
=== Automatically link up to wesnothd server on a local network ===&lt;br /&gt;
&lt;br /&gt;
The feature request was to use ZeroConf technology, if available, to publish info of a running wesnothd instance to other machines on a local network. Then when they are searching to connect to an unofficial server, they won't have to learn the IP address.&lt;br /&gt;
&lt;br /&gt;
The extra code should be guarded with preprocessor flags so that ZeroConf does not become a build dependency of wesnoth.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?13703&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a set of &amp;quot;common&amp;quot; mp messages which players can use when they don't share a language ===&lt;br /&gt;
&lt;br /&gt;
Most users speak english, however, wesnoth also has large Polish and Hungarian communities, and many Brazilian players, not all of whom speak english. It would be nice we could have a set of messages that could be chatted, but which will be translated by our translators and displayed always in the current locale on each client, to make it easier to communicate in mp games / on the mp server.&lt;br /&gt;
&lt;br /&gt;
The hard part is that if you don't already know about the gettext translation system, you will have to learn about it. The messages should be stored in a .cfg file in the data folder so that they can be easily modified and can be handled in the same way that other in-game text is translated -- they should perhaps go in their own gettext-domain however. Ideally there would be a gui dialog of some kind to select from them.&lt;br /&gt;
&lt;br /&gt;
=== Improve server wml processing ===&lt;br /&gt;
&lt;br /&gt;
The wesver uses an alternative implementation to store and process wml objects see http://wiki.wesnoth.org/WesnothdDesign#simple_wml. This is for performance. However, the simple_wml sometimes messes up translation for mp scenarios / campaigns, resulting in mp scenarios/campaigns beeing untranslated for non-hosts in networked mp (http://gna.org/bugs/?22989). Fixing this is not easy becasue of the performance requirements.&lt;br /&gt;
&lt;br /&gt;
== Improvements to AI ==&lt;br /&gt;
=== Move and targeting phase ===&lt;br /&gt;
AI needs to move units which are not within range of the enemy. This is generally a sequence of moves (some interesting things like 'ambush!' or 'WML event' might happen as a result of those moves, which should interrupt this phase). The problem is that simply doing those moves 1-by-1 is very slow, for two reasons:&lt;br /&gt;
&lt;br /&gt;
#movement maps are invalidated after each move, and are recalculated from the start. yet, if we are doing just a sequence of moves, we can just 'remove moved unit from moves' after each move and avoid expensive recalculation of the movement map.&lt;br /&gt;
#* Note that WML could mess with the game state at any time, so at the very least, movement will need to be recalculated after a WML event blocks undo (that is, indicates that it changed game state). --[[User:Brilliand|Brilliand]] 01:30, 28 May 2012 (UTC)&lt;br /&gt;
#most tasks need devoting more than one unit to execute (i.e., it's meaningless to go for the enemy position with just 1 unit). So, making individual decisions just does some repeating calculations, which is slow.&lt;br /&gt;
&lt;br /&gt;
A practical demonstration of these concerns are LoW 2 (dwarf ai is slow due to large avoid aspect) and NR:Showdown (orc AIs there are slow because of huge number of units)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we need a fast and effective 'move and targeting stage' - both ideas and implementations are wanted.&lt;br /&gt;
Here's Sirp's idea (more in 2009-aug-15 irclog):&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Eval-based AI ===&lt;br /&gt;
The AI system would be based around an 'eval' function -- a formula which is given a position, and returns a number saying how attractive that position is.&lt;br /&gt;
&lt;br /&gt;
There would also be a 'candidate_moves' function -- a formula which is given a unit and returns a list of 'candidate moves' -- i.e. moves for that unit that the AI should consider making.&lt;br /&gt;
&lt;br /&gt;
The aim of the system is to come up with the combination of candidate moves that gives the best possible evaluation. By doing this, the AI will work in a team, since the 'eval' function can give bonuses for units being close together, protecting each other, etc.&lt;br /&gt;
&lt;br /&gt;
There are likely to be, of course, a very large combination of possible moves, and not every one can possibly be evaluated. Instead, we take a monte carlo approach.&lt;br /&gt;
&lt;br /&gt;
If an AI has N units that it can move, that is an N-dimension matrix of possible moves. We would choose some cells in this matrix at random and then evaluate them. Then, of these cells evaluated we would choose cells that evaluated well, and discard those that did not evaluate well. Then, we would begin with those cells that evaluated well, and choose a scattering of 'close by' cells -- i.e. cells where we only vary some of the dimensions, at random. We would continue to evaluate cells at random, starting with those cells that evaluated well, and evaluating cells nearby. After several iterations, we would hope to arrive at a cell that evaluates very well, and we would use this as our set of moves.&lt;br /&gt;
&lt;br /&gt;
Of course, this system will be made more complex by the uncertainty of attacks. There are a number of ways to handle attacks, probably the easiest being to consider attacks as types of moves, and then if a move combination involving an attack is chosen, perform the attack and then re-run the entire AI algorithm before moving again. (Something similar to what the current AI does).&lt;br /&gt;
&lt;br /&gt;
This is effectively an AI framework, not an AI in itself. How well it performs will correlate strongly with how good an eval() function one can write, and is also based on the notion that generally certain combinations of moves are 'similar' to other combinations.&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Village grabbing ===&lt;br /&gt;
&lt;br /&gt;
Improve AI village grabbing algorithm to assign villages that are farther than one turn from current unit location.&lt;br /&gt;
Idea how to do would be value villages so that it can filter out villages that belongs to enemies/allies sides.  Those villages are stored in memory and used in 2nd pass that determines how AI should dispatch units to get villages if it should at all in this turn. This should be close to optimal solution with currently available units but performance limits should be taken into account.&lt;br /&gt;
Good solution would be that village grabbing value could be calculated with attack ratings and if some village has high value it would make unit go for that village instead &lt;br /&gt;
&lt;br /&gt;
This should help AI in begin of scenario. Currently AI might not grab all of villages that belong to its area which results quite large incoming loses.&lt;br /&gt;
In later game enemy might have large number of units in one part of map so village grabbing should be avoided in that are. Single unit would be easy pray for enemy so moving there would result just to loses.&lt;br /&gt;
&lt;br /&gt;
== Data Structures ==&lt;br /&gt;
=== Config Writer ===&lt;br /&gt;
&lt;br /&gt;
The speed of saving Wesnoth games is dominated by the time to marshall all the config structures.  This involves deep copying them many times as each subsystem returns its config bundle; far better would be to have a &amp;quot;config_writer&amp;quot; class which is handed to each subsystem which iterates through its structures and does the writing (to file or network) directly to the config_writer instance.&lt;br /&gt;
&lt;br /&gt;
Stop by #wesnoth-dev on freenode irc if you want to help with this, or post in the Coder's Corner.&lt;br /&gt;
&lt;br /&gt;
=== Config memory optimisation ===&lt;br /&gt;
&lt;br /&gt;
Right now, most of the memory used by wesnoth when using '''low_memory''' configuration flag is used by the config object trees. It would be possible to drop unused &amp;quot;branches&amp;quot; of that trees by using boost smart pointers in the config structure&lt;br /&gt;
&lt;br /&gt;
come and discuss that change on #wesnoth-dev. Sirp is the one that knows the most about that...&lt;br /&gt;
&lt;br /&gt;
=== Improvements to Unit Map ===&lt;br /&gt;
&lt;br /&gt;
As described here: [http://www.wesnoth.org/forum/viewtopic.php?p=236063#236063] (cjhopman has submitted a patch on that already)&lt;br /&gt;
&lt;br /&gt;
=== Make the lua state persistent ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth is designed to make all data files as simple and human-readable as possible, including savefiles. WML is designed so that it is always very easy to write the entire WML state as plaintext and reload it correctly. There are many benefits of this, but especially &lt;br /&gt;
&lt;br /&gt;
* It makes it easy for beginners / students to read the files and see what's going on&lt;br /&gt;
* It makes it easy for us to debug problems without needing special tools to read the savefiles&lt;br /&gt;
* It makes it easy to edit save files to work around any possible bugs. Users have even reported opening savefiles from version 1.10 in microsoft word (!) to correct minor bugs in mp and resaving them, as a policy for tournament games.&lt;br /&gt;
&lt;br /&gt;
This was unfortunately somewhat lost when we added lua. If you use lua in your scenarios, things become more complicated because we can't save the lua state at all. If you rely on lua variables to save information, then when your scenario is saved and reloaded those variables will get wiped. The wesnoth engine provides places for lua to hook into &amp;quot;onsave&amp;quot; and &amp;quot;onload&amp;quot; so that the scenario developer can write their own serialization routines, but this is just punting the problem to scenario developers.&lt;br /&gt;
&lt;br /&gt;
We also provide the &amp;quot;preload&amp;quot; event type specifically to work around the issue -- unlike all other events, preload is called exactly once for every time the scenario is loaded. The purpose is to give another way that lua users can initialize a table of lua functions used by their addon and guarantee that this happens before the functions are called. But to non-lua users this event is basically unsafe for normal use otherwise -- if there is a preload event which e.g. increments a WML variable, then the WML state now depends on how many times the scenario is saved or reloaded. In a normal scenario, save / reload events should be invisible, and normally if this isn't the case it indicates a bug similar to an OOS.&lt;br /&gt;
&lt;br /&gt;
A nice solution to this would be if we properly serialized the lua state alongside the WML in a savefile. The most suitable solution is probably this library: https://github.com/fnuecke/eris&lt;br /&gt;
It would require significant additional work as well to find a good way to serialize the C functions that we expose to lua, and the userdata like units held by lua.&lt;br /&gt;
&lt;br /&gt;
More info here: http://lua-users.org/wiki/PlutoLibrary&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
=== Frequently Proposed Good Ideas ===&lt;br /&gt;
&lt;br /&gt;
Check the [http://www.wesnoth.org/forum/viewtopic.php?f=12&amp;amp;t=9054&amp;amp;start=0&amp;amp;st=0&amp;amp;sk=t&amp;amp;sd=a B.W.H. list] in the Ideas Forum. Be aware that some entries there are old and have already been implemented, so you will need to investigate that before beginning work.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Future]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55975</id>
		<title>NotSoEasyCoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55975"/>
		<updated>2014-12-13T00:35:13Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Make a &amp;quot;replay actions since my last turn&amp;quot; button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Foreword ==&lt;br /&gt;
This page shows projects which are considered a good idea by the developers but which have nobody working on them so far. If you think you've got the required skill for a task go on, implement it and you've got a high chance that it'll be accepted. The remaining barrier will only be that it's done well. :-)&lt;br /&gt;
&lt;br /&gt;
If you are such a person, you should feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
If you're not, you should post a feature request and discuss your idea on the forum or IRC. A coder with better knowledge of the code might give you the green light to add your feature here.&lt;br /&gt;
&lt;br /&gt;
Anybody should feel free to add &amp;quot;clues&amp;quot; to any tasks, that is entry points, traps to avoid, person to contact to discuss and so on.&lt;br /&gt;
&lt;br /&gt;
If you plan to work on a feature, write your name at the bottom of the feature, with the date. Note that if you are too long at working on a feature I'll &amp;quot;free&amp;quot; it back (that is if you're not working on it. If you have problems implementing it, just tell us....)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Game Engine ==&lt;br /&gt;
=== add a mode to improve OOS detection in MP ===&lt;br /&gt;
We really need an optional 'pedantic mode' for MP which detects OOSes immediately, by comparing all game state information after each action and printing any mismatches. This mode will be optional because of the extra overhead it adds, and it would be very useful for debugging.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Fix a longstanding bug concerning failure to initialize a side in networked mp&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
(Actually we may have a fix for this now... will post reference)&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/index.php?21397&lt;br /&gt;
&lt;br /&gt;
The problem itself is quite simple -- when the server tells a client that their turn has begun, the client immediately broadcasts [init_side] to all the other players via the server, performing the initial upkeep, healing, and movement point reset actions. However, if this player disconnects / blocks the action by opening a dialog during the prior turn and never closing it, [init_side] is never broadcast. And if the game is then saved by one of the other clients, nothing in the current mechanism detects that this has been overlooked when the game is reloaded. The consequence is that in the reloaded game, that side's turn is *never* initialized -- they get no gold, their units don't heal, and they don't get full move points at the start of the turn.&lt;br /&gt;
&lt;br /&gt;
Propose a mechanism to fix this -- perhaps games which have been loaded should be scanned to see if the current turn failed to initialize. Perhaps a flag in game_state could be used and saved. Perhaps a completely different approach. Check that your mechanism works whether the save is loaded from [snapshot] or [replay_start] and [replay].&lt;br /&gt;
&lt;br /&gt;
This bug has existed since at least Wesnoth 1.8&lt;br /&gt;
&lt;br /&gt;
=== Make a &amp;quot;replay actions since my last turn&amp;quot; button ===&lt;br /&gt;
&lt;br /&gt;
It would be very convenient if there an ability to replay everything your opponents just did at the &lt;br /&gt;
start of your turn, since sometimes things go out of vision or are confusing. &lt;br /&gt;
&lt;br /&gt;
The feature would be like a &amp;quot;replay since my last turn&amp;quot; menu option or button -- most likely, the best approach to implement it is to store a copy of the game_state object in playcontroller.cpp or even in resources, and to refactor the backlog object so that we can hold a &amp;quot;bookmark&amp;quot;, i.e. a pointer, to the last position in the replay that we might look to jump back to. The replay process would work by swapping out for the old gamestate, then replaying through the actions since the bookmark until we get back up to speed. The difficult part would be making sure that scenarios with scripted WML events don't break when we do this. For debugging purposes, it might be good to check that at this point we have the same gamestate we did before we clicked the button. The bookmark should only be advanced when we end our turn, and there might be perhaps need to be multiple bookmarks, one for each side, to handle what happens when a side disconnects or is reassigned.&lt;br /&gt;
&lt;br /&gt;
It would be especially helpful for MP play to have this, where special tactics with ambush units are quite common. Part of the design criteria of wesnoth is that it should be a high-level, thoughtful turn based strategy game, but you should be able to play asynchronously and not necessarily give attention to the game until your turn bell rings if you don't want to. Having ambush units and no ability to replay their movements during the opponents turn harms that goal.&lt;br /&gt;
&lt;br /&gt;
For MP play, it will require special attention to make sure that events like &amp;quot;synchronize_choice&amp;quot; are handled correctly so as not to cause out of sync errors, and also that the timer is handled correctly.&lt;br /&gt;
&lt;br /&gt;
Feature request: https://gna.org/bugs/?15334&lt;br /&gt;
&lt;br /&gt;
=== Improve WML error reporting ===&lt;br /&gt;
&lt;br /&gt;
There are many programming bugs that give very unclear or cryptic error messages when using WML. Here are some examples:&lt;br /&gt;
&lt;br /&gt;
-- When calling a macro with the wrong number of arguments, wesnoth tells the number it expected, and the number it got, and at which line number it was instantiated. However, it would be helpful if it would also tell the line number of the definition of the macro. This might be helpful if someone is redefining macros.&lt;br /&gt;
&lt;br /&gt;
-- For places where a standard unit filter is expected, if one is not found, the game should point out a problem. For places where such a filter is expected but [filter] child should not appear, if one does it should report an error and a line number. Many users have a hard time with this kind of thing.&lt;br /&gt;
&lt;br /&gt;
-- When doing scenario transitions in a campaign, if the side definitions don't matchup exactly the game tends to give unintelligible error messages. For instance, if one is transitioning and there is an AI side which does not have a leader (but it has a starting location in the map) it must have &amp;quot;no_leader = yes&amp;quot; in its [side] tag, or else when the team_builder objects enter stage two, the game will try to create a unit with an empty type, and the constructor of class unit will fail giving the error message &amp;quot;game::game_error tried to create unit with empty type&amp;quot;. This really needs to be much better. For instance, giving a line number of a problem, or suggesting that no_leader should be used. (Note that, it is often possible to debug problems like this by turning on --log-debug=team_construction at commandline but I doubt that there are any users that know about this, you would only learn from reading the C++... without such debug info, fixing things like this can literally take hours.) For that matter it's some question why the team_builder doesn't just stop trying to build a unit when it sees it doesn't have enough info...&lt;br /&gt;
&lt;br /&gt;
-- Recursive macros break the game, and not by stack overflow but by exhausting the heap. It would be nice if we could catch this and report an error.&lt;br /&gt;
&lt;br /&gt;
Many of the users of WML are students or beginners to programming, it is a big help to them to improve the error reporting of this nature -- not to mention that many veterans would appreciate as well. In part we need fixits here and there but more broadly we need a smarter system that can figure out what's really wrong when things go wrong and give helpful suggestions.&lt;br /&gt;
&lt;br /&gt;
=== Map label &amp;quot;groups&amp;quot; which can be selectively turned on and off by the user ===&lt;br /&gt;
&lt;br /&gt;
It would be nice if the user could have more control over how map labels are displayed, for instance to be able to check on / off labels made by certain players, and for custom scenarios, to be able to make custom classes which the use can turn on or off. This might be helpful for custom scenarios esp. which might have some technical info they want to show, but which it might be messy to display all of the time. The hard part of this is that there should ideally be a gui to work with the map labels, although maybe this need could be worked around or simplified somehow.&lt;br /&gt;
&lt;br /&gt;
=== Add a new damage stats calculation mode to support scenarios with extremely high stats ===&lt;br /&gt;
&lt;br /&gt;
Most players use the damage calculation window constantly when they play so that they can see what to expect from various attacks. The way the game is currently set up, when a unit is selected, as soon as another unit is moused over the stats for an attack will be calculated, whether or not the user actually brings up the window.&lt;br /&gt;
&lt;br /&gt;
The probabilities for the various outcomes are calculated by explicitly calculating the distribution of attacker and defender hp / slowed status after each swing by either party, one swing at a time. Thus at the end we get exact probabilities of the possible outcomes.&lt;br /&gt;
&lt;br /&gt;
However, this comes at a cost -- the running time of the calculation can in the worst case be something like O( attacker_hp * defender_hp * total_number_of_strikes). In default era wesnoth (and in much of UMC) this is fine because units don't get extremely high hp values. However in some UMC units do get extremely high hp, and many will also have specials like drain and berzerk, and may have many different weapons as well. At some point these scenarios become unplayable even on a machine of moderate specs because mousing over any unit causes &amp;gt; 10 seconds of lag during which the game becomes unresponsive, trying to calculate attack outcomes.&lt;br /&gt;
&lt;br /&gt;
In these cases, it would be better to give an &amp;quot;inexact&amp;quot; damage prediction, based on just simulating a few thousand attacks and plotting the results. Since it's a monte carlo algorithm rather than an exact algorithm, there will be some error, but if it makes the game playable then it's clearly an improvement, and anyways for &amp;quot;extreme stats&amp;quot; battles with high strikes and damage, the outcome is in a sense less random anyways because the outcomes with inordinate amounts of hits and misses are more and more rare (law of large numbers), so the error shouldn't actually be terribly significant.&lt;br /&gt;
&lt;br /&gt;
If there were an advanced preference that caused the predictions to use such an algorithm instead of the current one, so that the user could turn it on if they start to get problems, it would eliminate a significant headache for some UMC.&lt;br /&gt;
&lt;br /&gt;
== MP Related ==&lt;br /&gt;
&lt;br /&gt;
=== Automatically resolve add-on dependencies ===&lt;br /&gt;
&lt;br /&gt;
In 1.11 add-ons may declare dependencies. A related easy coding task is to allow the user to force breaking dependencies.&lt;br /&gt;
&lt;br /&gt;
A related goal which would be greatly beneficial would be that wesnoth can automatically resolve the dependencies by fetching the add-ons from the download server, when in the MP-lobby the user tries to join a game with a dependency they don't meet. A dialog would ideally be provided as well, or perhaps a preference.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?21705&lt;br /&gt;
&lt;br /&gt;
Even older: https://gna.org/bugs/?9683&lt;br /&gt;
&lt;br /&gt;
=== Gold graph ===&lt;br /&gt;
&lt;br /&gt;
Make a graph feature, presumably in a dialog, that helps depict the history of the game. For example it could display army value, army + bank value, number of villages tagged, luck swings... the purpose would be to assist spectators of a live game / spectators of a replay to understand the history of the game. It would be particularly helpful with AI development, by helping AI developers to identify key points where one of the AI is making a big mistake. &lt;br /&gt;
&lt;br /&gt;
A possible nice feature for this purpose would be to allow the user to click on the graph at key points which would trigger the &amp;quot;back to turn&amp;quot; mechanism to jump back in the replay, or automatically play the replay forwards from the beginning to that point... etc.&lt;br /&gt;
&lt;br /&gt;
Related email on dev-talk: https://mail.gna.org/public/wesnoth-dev/2014-02/msg00089.html&lt;br /&gt;
&lt;br /&gt;
=== Automatically link up to wesnothd server on a local network ===&lt;br /&gt;
&lt;br /&gt;
The feature request was to use ZeroConf technology, if available, to publish info of a running wesnothd instance to other machines on a local network. Then when they are searching to connect to an unofficial server, they won't have to learn the IP address.&lt;br /&gt;
&lt;br /&gt;
The extra code should be guarded with preprocessor flags so that ZeroConf does not become a build dependency of wesnoth.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?13703&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a set of &amp;quot;common&amp;quot; mp messages which players can use when they don't share a language ===&lt;br /&gt;
&lt;br /&gt;
Most users speak english, however, wesnoth also has large Polish and Hungarian communities, and many Brazilian players, not all of whom speak english. It would be nice we could have a set of messages that could be chatted, but which will be translated by our translators and displayed always in the current locale on each client, to make it easier to communicate in mp games / on the mp server.&lt;br /&gt;
&lt;br /&gt;
The hard part is that if you don't already know about the gettext translation system, you will have to learn about it. The messages should be stored in a .cfg file in the data folder so that they can be easily modified and can be handled in the same way that other in-game text is translated -- they should perhaps go in their own gettext-domain however. Ideally there would be a gui dialog of some kind to select from them.&lt;br /&gt;
&lt;br /&gt;
=== Improve server wml processing ===&lt;br /&gt;
&lt;br /&gt;
The wesver uses an alternative implementation to store and process wml objects see http://wiki.wesnoth.org/WesnothdDesign#simple_wml. This is for performance. However, the simple_wml sometimes messes up translation for mp scenarios / campaigns, resulting in mp scenarios/campaigns beeing untranslated for non-hosts in networked mp (http://gna.org/bugs/?22989). Fixing this is not easy becasue of the performance requirements.&lt;br /&gt;
&lt;br /&gt;
== Improvements to AI ==&lt;br /&gt;
=== Move and targeting phase ===&lt;br /&gt;
AI needs to move units which are not within range of the enemy. This is generally a sequence of moves (some interesting things like 'ambush!' or 'WML event' might happen as a result of those moves, which should interrupt this phase). The problem is that simply doing those moves 1-by-1 is very slow, for two reasons:&lt;br /&gt;
&lt;br /&gt;
#movement maps are invalidated after each move, and are recalculated from the start. yet, if we are doing just a sequence of moves, we can just 'remove moved unit from moves' after each move and avoid expensive recalculation of the movement map.&lt;br /&gt;
#* Note that WML could mess with the game state at any time, so at the very least, movement will need to be recalculated after a WML event blocks undo (that is, indicates that it changed game state). --[[User:Brilliand|Brilliand]] 01:30, 28 May 2012 (UTC)&lt;br /&gt;
#most tasks need devoting more than one unit to execute (i.e., it's meaningless to go for the enemy position with just 1 unit). So, making individual decisions just does some repeating calculations, which is slow.&lt;br /&gt;
&lt;br /&gt;
A practical demonstration of these concerns are LoW 2 (dwarf ai is slow due to large avoid aspect) and NR:Showdown (orc AIs there are slow because of huge number of units)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we need a fast and effective 'move and targeting stage' - both ideas and implementations are wanted.&lt;br /&gt;
Here's Sirp's idea (more in 2009-aug-15 irclog):&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Eval-based AI ===&lt;br /&gt;
The AI system would be based around an 'eval' function -- a formula which is given a position, and returns a number saying how attractive that position is.&lt;br /&gt;
&lt;br /&gt;
There would also be a 'candidate_moves' function -- a formula which is given a unit and returns a list of 'candidate moves' -- i.e. moves for that unit that the AI should consider making.&lt;br /&gt;
&lt;br /&gt;
The aim of the system is to come up with the combination of candidate moves that gives the best possible evaluation. By doing this, the AI will work in a team, since the 'eval' function can give bonuses for units being close together, protecting each other, etc.&lt;br /&gt;
&lt;br /&gt;
There are likely to be, of course, a very large combination of possible moves, and not every one can possibly be evaluated. Instead, we take a monte carlo approach.&lt;br /&gt;
&lt;br /&gt;
If an AI has N units that it can move, that is an N-dimension matrix of possible moves. We would choose some cells in this matrix at random and then evaluate them. Then, of these cells evaluated we would choose cells that evaluated well, and discard those that did not evaluate well. Then, we would begin with those cells that evaluated well, and choose a scattering of 'close by' cells -- i.e. cells where we only vary some of the dimensions, at random. We would continue to evaluate cells at random, starting with those cells that evaluated well, and evaluating cells nearby. After several iterations, we would hope to arrive at a cell that evaluates very well, and we would use this as our set of moves.&lt;br /&gt;
&lt;br /&gt;
Of course, this system will be made more complex by the uncertainty of attacks. There are a number of ways to handle attacks, probably the easiest being to consider attacks as types of moves, and then if a move combination involving an attack is chosen, perform the attack and then re-run the entire AI algorithm before moving again. (Something similar to what the current AI does).&lt;br /&gt;
&lt;br /&gt;
This is effectively an AI framework, not an AI in itself. How well it performs will correlate strongly with how good an eval() function one can write, and is also based on the notion that generally certain combinations of moves are 'similar' to other combinations.&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Village grabbing ===&lt;br /&gt;
&lt;br /&gt;
Improve AI village grabbing algorithm to assign villages that are farther than one turn from current unit location.&lt;br /&gt;
Idea how to do would be value villages so that it can filter out villages that belongs to enemies/allies sides.  Those villages are stored in memory and used in 2nd pass that determines how AI should dispatch units to get villages if it should at all in this turn. This should be close to optimal solution with currently available units but performance limits should be taken into account.&lt;br /&gt;
Good solution would be that village grabbing value could be calculated with attack ratings and if some village has high value it would make unit go for that village instead &lt;br /&gt;
&lt;br /&gt;
This should help AI in begin of scenario. Currently AI might not grab all of villages that belong to its area which results quite large incoming loses.&lt;br /&gt;
In later game enemy might have large number of units in one part of map so village grabbing should be avoided in that are. Single unit would be easy pray for enemy so moving there would result just to loses.&lt;br /&gt;
&lt;br /&gt;
== Data Structures ==&lt;br /&gt;
=== Config Writer ===&lt;br /&gt;
&lt;br /&gt;
The speed of saving Wesnoth games is dominated by the time to marshall all the config structures.  This involves deep copying them many times as each subsystem returns its config bundle; far better would be to have a &amp;quot;config_writer&amp;quot; class which is handed to each subsystem which iterates through its structures and does the writing (to file or network) directly to the config_writer instance.&lt;br /&gt;
&lt;br /&gt;
Stop by #wesnoth-dev on freenode irc if you want to help with this, or post in the Coder's Corner.&lt;br /&gt;
&lt;br /&gt;
=== Config memory optimisation ===&lt;br /&gt;
&lt;br /&gt;
Right now, most of the memory used by wesnoth when using '''low_memory''' configuration flag is used by the config object trees. It would be possible to drop unused &amp;quot;branches&amp;quot; of that trees by using boost smart pointers in the config structure&lt;br /&gt;
&lt;br /&gt;
come and discuss that change on #wesnoth-dev. Sirp is the one that knows the most about that...&lt;br /&gt;
&lt;br /&gt;
=== Improvements to Unit Map ===&lt;br /&gt;
&lt;br /&gt;
As described here: [http://www.wesnoth.org/forum/viewtopic.php?p=236063#236063] (cjhopman has submitted a patch on that already)&lt;br /&gt;
&lt;br /&gt;
=== Make the lua state persistent ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth is designed to make all data files as simple and human-readable as possible, including savefiles. WML is designed so that it is always very easy to write the entire WML state as plaintext and reload it correctly. There are many benefits of this, but especially &lt;br /&gt;
&lt;br /&gt;
* It makes it easy for beginners / students to read the files and see what's going on&lt;br /&gt;
* It makes it easy for us to debug problems without needing special tools to read the savefiles&lt;br /&gt;
* It makes it easy to edit save files to work around any possible bugs. Users have even reported opening savefiles from version 1.10 in microsoft word (!) to correct minor bugs in mp and resaving them, as a policy for tournament games.&lt;br /&gt;
&lt;br /&gt;
This was unfortunately somewhat lost when we added lua. If you use lua in your scenarios, things become more complicated because we can't save the lua state at all. If you rely on lua variables to save information, then when your scenario is saved and reloaded those variables will get wiped. The wesnoth engine provides places for lua to hook into &amp;quot;onsave&amp;quot; and &amp;quot;onload&amp;quot; so that the scenario developer can write their own serialization routines, but this is just punting the problem to scenario developers.&lt;br /&gt;
&lt;br /&gt;
We also provide the &amp;quot;preload&amp;quot; event type specifically to work around the issue -- unlike all other events, preload is called exactly once for every time the scenario is loaded. The purpose is to give another way that lua users can initialize a table of lua functions used by their addon and guarantee that this happens before the functions are called. But to non-lua users this event is basically unsafe for normal use otherwise -- if there is a preload event which e.g. increments a WML variable, then the WML state now depends on how many times the scenario is saved or reloaded. In a normal scenario, save / reload events should be invisible, and normally if this isn't the case it indicates a bug similar to an OOS.&lt;br /&gt;
&lt;br /&gt;
A nice solution to this would be if we properly serialized the lua state alongside the WML in a savefile. The most suitable solution is probably this library: https://github.com/fnuecke/eris&lt;br /&gt;
It would require significant additional work as well to find a good way to serialize the C functions that we expose to lua, and the userdata like units held by lua.&lt;br /&gt;
&lt;br /&gt;
More info here: http://lua-users.org/wiki/PlutoLibrary&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
=== Frequently Proposed Good Ideas ===&lt;br /&gt;
&lt;br /&gt;
Check the [http://www.wesnoth.org/forum/viewtopic.php?f=12&amp;amp;t=9054&amp;amp;start=0&amp;amp;st=0&amp;amp;sk=t&amp;amp;sd=a B.W.H. list] in the Ideas Forum. Be aware that some entries there are old and have already been implemented, so you will need to investigate that before beginning work.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Future]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55970</id>
		<title>NotSoEasyCoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55970"/>
		<updated>2014-12-09T03:01:30Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Make the lua state persistent */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Foreword ==&lt;br /&gt;
This page shows projects which are considered a good idea by the developers but which have nobody working on them so far. If you think you've got the required skill for a task go on, implement it and you've got a high chance that it'll be accepted. The remaining barrier will only be that it's done well. :-)&lt;br /&gt;
&lt;br /&gt;
If you are such a person, you should feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
If you're not, you should post a feature request and discuss your idea on the forum or IRC. A coder with better knowledge of the code might give you the green light to add your feature here.&lt;br /&gt;
&lt;br /&gt;
Anybody should feel free to add &amp;quot;clues&amp;quot; to any tasks, that is entry points, traps to avoid, person to contact to discuss and so on.&lt;br /&gt;
&lt;br /&gt;
If you plan to work on a feature, write your name at the bottom of the feature, with the date. Note that if you are too long at working on a feature I'll &amp;quot;free&amp;quot; it back (that is if you're not working on it. If you have problems implementing it, just tell us....)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Game Engine ==&lt;br /&gt;
=== add a mode to improve OOS detection in MP ===&lt;br /&gt;
We really need an optional 'pedantic mode' for MP which detects OOSes immediately, by comparing all game state information after each action and printing any mismatches. This mode will be optional because of the extra overhead it adds, and it would be very useful for debugging.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Fix a longstanding bug concerning failure to initialize a side in networked mp&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
(Actually we may have a fix for this now... will post reference)&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/index.php?21397&lt;br /&gt;
&lt;br /&gt;
The problem itself is quite simple -- when the server tells a client that their turn has begun, the client immediately broadcasts [init_side] to all the other players via the server, performing the initial upkeep, healing, and movement point reset actions. However, if this player disconnects / blocks the action by opening a dialog during the prior turn and never closing it, [init_side] is never broadcast. And if the game is then saved by one of the other clients, nothing in the current mechanism detects that this has been overlooked when the game is reloaded. The consequence is that in the reloaded game, that side's turn is *never* initialized -- they get no gold, their units don't heal, and they don't get full move points at the start of the turn.&lt;br /&gt;
&lt;br /&gt;
Propose a mechanism to fix this -- perhaps games which have been loaded should be scanned to see if the current turn failed to initialize. Perhaps a flag in game_state could be used and saved. Perhaps a completely different approach. Check that your mechanism works whether the save is loaded from [snapshot] or [replay_start] and [replay].&lt;br /&gt;
&lt;br /&gt;
This bug has existed since at least Wesnoth 1.8&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Make a &amp;quot;replay actions since my last turn&amp;quot; button&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
It would be very convenient if there an ability to replay everything your opponents just did at the &lt;br /&gt;
start of your turn, since sometimes things go out of vision or are confusing. &lt;br /&gt;
&lt;br /&gt;
The feature would be like a &amp;quot;replay since my last turn&amp;quot; menu option or button -- most likely, the best approach to implement it is to store a copy of the game_state object in playcontroller.cpp or even in resources, and to refactor the backlog object so that we can hold a &amp;quot;bookmark&amp;quot;, i.e. a pointer, to the last position in the replay that we might look to jump back to. The replay process would work by swapping out for the old gamestate, then replaying through the actions since the bookmark until we get back up to speed. The difficult part would be making sure that scenarios with scripted WML events don't break when we do this. For debugging purposes, it might be good to check that at this point we have the same gamestate we did before we clicked the button. The bookmark should only be advanced when we end our turn, and there might be perhaps need to be multiple bookmarks, one for each side, to handle what happens when a side disconnects or is reassigned.&lt;br /&gt;
&lt;br /&gt;
It would be especially helpful for MP play to have this, where special tactics with ambush units are quite common. Part of the design criteria of wesnoth is that it should be a high-level, thoughtful turn based strategy game, but you should be able to play asynchronously and not necessarily give attention to the game until your turn bell rings if you don't want to. Having ambush units and no ability to replay their movements during the opponents turn harms that goal.&lt;br /&gt;
&lt;br /&gt;
For MP play, it will require special attention to make sure that events like &amp;quot;synchronize_choice&amp;quot; are handled correctly so as not to cause out of sync errors, and also that the timer is handled correctly.&lt;br /&gt;
&lt;br /&gt;
Feature request: https://gna.org/bugs/?15334&lt;br /&gt;
&lt;br /&gt;
Thanks to Zappaman for this. https://github.com/wesnoth/wesnoth/pull/270&lt;br /&gt;
&lt;br /&gt;
=== Improve WML error reporting ===&lt;br /&gt;
&lt;br /&gt;
There are many programming bugs that give very unclear or cryptic error messages when using WML. Here are some examples:&lt;br /&gt;
&lt;br /&gt;
-- When calling a macro with the wrong number of arguments, wesnoth tells the number it expected, and the number it got, and at which line number it was instantiated. However, it would be helpful if it would also tell the line number of the definition of the macro. This might be helpful if someone is redefining macros.&lt;br /&gt;
&lt;br /&gt;
-- For places where a standard unit filter is expected, if one is not found, the game should point out a problem. For places where such a filter is expected but [filter] child should not appear, if one does it should report an error and a line number. Many users have a hard time with this kind of thing.&lt;br /&gt;
&lt;br /&gt;
-- When doing scenario transitions in a campaign, if the side definitions don't matchup exactly the game tends to give unintelligible error messages. For instance, if one is transitioning and there is an AI side which does not have a leader (but it has a starting location in the map) it must have &amp;quot;no_leader = yes&amp;quot; in its [side] tag, or else when the team_builder objects enter stage two, the game will try to create a unit with an empty type, and the constructor of class unit will fail giving the error message &amp;quot;game::game_error tried to create unit with empty type&amp;quot;. This really needs to be much better. For instance, giving a line number of a problem, or suggesting that no_leader should be used. (Note that, it is often possible to debug problems like this by turning on --log-debug=team_construction at commandline but I doubt that there are any users that know about this, you would only learn from reading the C++... without such debug info, fixing things like this can literally take hours.) For that matter it's some question why the team_builder doesn't just stop trying to build a unit when it sees it doesn't have enough info...&lt;br /&gt;
&lt;br /&gt;
-- Recursive macros break the game, and not by stack overflow but by exhausting the heap. It would be nice if we could catch this and report an error.&lt;br /&gt;
&lt;br /&gt;
Many of the users of WML are students or beginners to programming, it is a big help to them to improve the error reporting of this nature -- not to mention that many veterans would appreciate as well. In part we need fixits here and there but more broadly we need a smarter system that can figure out what's really wrong when things go wrong and give helpful suggestions.&lt;br /&gt;
&lt;br /&gt;
=== Map label &amp;quot;groups&amp;quot; which can be selectively turned on and off by the user ===&lt;br /&gt;
&lt;br /&gt;
It would be nice if the user could have more control over how map labels are displayed, for instance to be able to check on / off labels made by certain players, and for custom scenarios, to be able to make custom classes which the use can turn on or off. This might be helpful for custom scenarios esp. which might have some technical info they want to show, but which it might be messy to display all of the time. The hard part of this is that there should ideally be a gui to work with the map labels, although maybe this need could be worked around or simplified somehow.&lt;br /&gt;
&lt;br /&gt;
=== Add a new damage stats calculation mode to support scenarios with extremely high stats ===&lt;br /&gt;
&lt;br /&gt;
Most players use the damage calculation window constantly when they play so that they can see what to expect from various attacks. The way the game is currently set up, when a unit is selected, as soon as another unit is moused over the stats for an attack will be calculated, whether or not the user actually brings up the window.&lt;br /&gt;
&lt;br /&gt;
The probabilities for the various outcomes are calculated by explicitly calculating the distribution of attacker and defender hp / slowed status after each swing by either party, one swing at a time. Thus at the end we get exact probabilities of the possible outcomes.&lt;br /&gt;
&lt;br /&gt;
However, this comes at a cost -- the running time of the calculation can in the worst case be something like O( attacker_hp * defender_hp * total_number_of_strikes). In default era wesnoth (and in much of UMC) this is fine because units don't get extremely high hp values. However in some UMC units do get extremely high hp, and many will also have specials like drain and berzerk, and may have many different weapons as well. At some point these scenarios become unplayable even on a machine of moderate specs because mousing over any unit causes &amp;gt; 10 seconds of lag during which the game becomes unresponsive, trying to calculate attack outcomes.&lt;br /&gt;
&lt;br /&gt;
In these cases, it would be better to give an &amp;quot;inexact&amp;quot; damage prediction, based on just simulating a few thousand attacks and plotting the results. Since it's a monte carlo algorithm rather than an exact algorithm, there will be some error, but if it makes the game playable then it's clearly an improvement, and anyways for &amp;quot;extreme stats&amp;quot; battles with high strikes and damage, the outcome is in a sense less random anyways because the outcomes with inordinate amounts of hits and misses are more and more rare (law of large numbers), so the error shouldn't actually be terribly significant.&lt;br /&gt;
&lt;br /&gt;
If there were an advanced preference that caused the predictions to use such an algorithm instead of the current one, so that the user could turn it on if they start to get problems, it would eliminate a significant headache for some UMC.&lt;br /&gt;
&lt;br /&gt;
== MP Related ==&lt;br /&gt;
&lt;br /&gt;
=== Automatically resolve add-on dependencies ===&lt;br /&gt;
&lt;br /&gt;
In 1.11 add-ons may declare dependencies. A related easy coding task is to allow the user to force breaking dependencies.&lt;br /&gt;
&lt;br /&gt;
A related goal which would be greatly beneficial would be that wesnoth can automatically resolve the dependencies by fetching the add-ons from the download server, when in the MP-lobby the user tries to join a game with a dependency they don't meet. A dialog would ideally be provided as well, or perhaps a preference.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?21705&lt;br /&gt;
&lt;br /&gt;
Even older: https://gna.org/bugs/?9683&lt;br /&gt;
&lt;br /&gt;
=== Gold graph ===&lt;br /&gt;
&lt;br /&gt;
Make a graph feature, presumably in a dialog, that helps depict the history of the game. For example it could display army value, army + bank value, number of villages tagged, luck swings... the purpose would be to assist spectators of a live game / spectators of a replay to understand the history of the game. It would be particularly helpful with AI development, by helping AI developers to identify key points where one of the AI is making a big mistake. &lt;br /&gt;
&lt;br /&gt;
A possible nice feature for this purpose would be to allow the user to click on the graph at key points which would trigger the &amp;quot;back to turn&amp;quot; mechanism to jump back in the replay, or automatically play the replay forwards from the beginning to that point... etc.&lt;br /&gt;
&lt;br /&gt;
Related email on dev-talk: https://mail.gna.org/public/wesnoth-dev/2014-02/msg00089.html&lt;br /&gt;
&lt;br /&gt;
=== Automatically link up to wesnothd server on a local network ===&lt;br /&gt;
&lt;br /&gt;
The feature request was to use ZeroConf technology, if available, to publish info of a running wesnothd instance to other machines on a local network. Then when they are searching to connect to an unofficial server, they won't have to learn the IP address.&lt;br /&gt;
&lt;br /&gt;
The extra code should be guarded with preprocessor flags so that ZeroConf does not become a build dependency of wesnoth.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?13703&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a set of &amp;quot;common&amp;quot; mp messages which players can use when they don't share a language ===&lt;br /&gt;
&lt;br /&gt;
Most users speak english, however, wesnoth also has large Polish and Hungarian communities, and many Brazilian players, not all of whom speak english. It would be nice we could have a set of messages that could be chatted, but which will be translated by our translators and displayed always in the current locale on each client, to make it easier to communicate in mp games / on the mp server.&lt;br /&gt;
&lt;br /&gt;
The hard part is that if you don't already know about the gettext translation system, you will have to learn about it. The messages should be stored in a .cfg file in the data folder so that they can be easily modified and can be handled in the same way that other in-game text is translated -- they should perhaps go in their own gettext-domain however. Ideally there would be a gui dialog of some kind to select from them.&lt;br /&gt;
&lt;br /&gt;
=== Improve server wml processing ===&lt;br /&gt;
&lt;br /&gt;
The wesver uses an alternative implementation to store and process wml objects see http://wiki.wesnoth.org/WesnothdDesign#simple_wml. This is for performance. However, the simple_wml sometimes messes up translation for mp scenarios / campaigns, resulting in mp scenarios/campaigns beeing untranslated for non-hosts in networked mp (http://gna.org/bugs/?22989). Fixing this is not easy becasue of the performance requirements.&lt;br /&gt;
&lt;br /&gt;
== Improvements to AI ==&lt;br /&gt;
=== Move and targeting phase ===&lt;br /&gt;
AI needs to move units which are not within range of the enemy. This is generally a sequence of moves (some interesting things like 'ambush!' or 'WML event' might happen as a result of those moves, which should interrupt this phase). The problem is that simply doing those moves 1-by-1 is very slow, for two reasons:&lt;br /&gt;
&lt;br /&gt;
#movement maps are invalidated after each move, and are recalculated from the start. yet, if we are doing just a sequence of moves, we can just 'remove moved unit from moves' after each move and avoid expensive recalculation of the movement map.&lt;br /&gt;
#* Note that WML could mess with the game state at any time, so at the very least, movement will need to be recalculated after a WML event blocks undo (that is, indicates that it changed game state). --[[User:Brilliand|Brilliand]] 01:30, 28 May 2012 (UTC)&lt;br /&gt;
#most tasks need devoting more than one unit to execute (i.e., it's meaningless to go for the enemy position with just 1 unit). So, making individual decisions just does some repeating calculations, which is slow.&lt;br /&gt;
&lt;br /&gt;
A practical demonstration of these concerns are LoW 2 (dwarf ai is slow due to large avoid aspect) and NR:Showdown (orc AIs there are slow because of huge number of units)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we need a fast and effective 'move and targeting stage' - both ideas and implementations are wanted.&lt;br /&gt;
Here's Sirp's idea (more in 2009-aug-15 irclog):&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Eval-based AI ===&lt;br /&gt;
The AI system would be based around an 'eval' function -- a formula which is given a position, and returns a number saying how attractive that position is.&lt;br /&gt;
&lt;br /&gt;
There would also be a 'candidate_moves' function -- a formula which is given a unit and returns a list of 'candidate moves' -- i.e. moves for that unit that the AI should consider making.&lt;br /&gt;
&lt;br /&gt;
The aim of the system is to come up with the combination of candidate moves that gives the best possible evaluation. By doing this, the AI will work in a team, since the 'eval' function can give bonuses for units being close together, protecting each other, etc.&lt;br /&gt;
&lt;br /&gt;
There are likely to be, of course, a very large combination of possible moves, and not every one can possibly be evaluated. Instead, we take a monte carlo approach.&lt;br /&gt;
&lt;br /&gt;
If an AI has N units that it can move, that is an N-dimension matrix of possible moves. We would choose some cells in this matrix at random and then evaluate them. Then, of these cells evaluated we would choose cells that evaluated well, and discard those that did not evaluate well. Then, we would begin with those cells that evaluated well, and choose a scattering of 'close by' cells -- i.e. cells where we only vary some of the dimensions, at random. We would continue to evaluate cells at random, starting with those cells that evaluated well, and evaluating cells nearby. After several iterations, we would hope to arrive at a cell that evaluates very well, and we would use this as our set of moves.&lt;br /&gt;
&lt;br /&gt;
Of course, this system will be made more complex by the uncertainty of attacks. There are a number of ways to handle attacks, probably the easiest being to consider attacks as types of moves, and then if a move combination involving an attack is chosen, perform the attack and then re-run the entire AI algorithm before moving again. (Something similar to what the current AI does).&lt;br /&gt;
&lt;br /&gt;
This is effectively an AI framework, not an AI in itself. How well it performs will correlate strongly with how good an eval() function one can write, and is also based on the notion that generally certain combinations of moves are 'similar' to other combinations.&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Village grabbing ===&lt;br /&gt;
&lt;br /&gt;
Improve AI village grabbing algorithm to assign villages that are farther than one turn from current unit location.&lt;br /&gt;
Idea how to do would be value villages so that it can filter out villages that belongs to enemies/allies sides.  Those villages are stored in memory and used in 2nd pass that determines how AI should dispatch units to get villages if it should at all in this turn. This should be close to optimal solution with currently available units but performance limits should be taken into account.&lt;br /&gt;
Good solution would be that village grabbing value could be calculated with attack ratings and if some village has high value it would make unit go for that village instead &lt;br /&gt;
&lt;br /&gt;
This should help AI in begin of scenario. Currently AI might not grab all of villages that belong to its area which results quite large incoming loses.&lt;br /&gt;
In later game enemy might have large number of units in one part of map so village grabbing should be avoided in that are. Single unit would be easy pray for enemy so moving there would result just to loses.&lt;br /&gt;
&lt;br /&gt;
== Data Structures ==&lt;br /&gt;
=== Config Writer ===&lt;br /&gt;
&lt;br /&gt;
The speed of saving Wesnoth games is dominated by the time to marshall all the config structures.  This involves deep copying them many times as each subsystem returns its config bundle; far better would be to have a &amp;quot;config_writer&amp;quot; class which is handed to each subsystem which iterates through its structures and does the writing (to file or network) directly to the config_writer instance.&lt;br /&gt;
&lt;br /&gt;
Stop by #wesnoth-dev on freenode irc if you want to help with this, or post in the Coder's Corner.&lt;br /&gt;
&lt;br /&gt;
=== Config memory optimisation ===&lt;br /&gt;
&lt;br /&gt;
Right now, most of the memory used by wesnoth when using '''low_memory''' configuration flag is used by the config object trees. It would be possible to drop unused &amp;quot;branches&amp;quot; of that trees by using boost smart pointers in the config structure&lt;br /&gt;
&lt;br /&gt;
come and discuss that change on #wesnoth-dev. Sirp is the one that knows the most about that...&lt;br /&gt;
&lt;br /&gt;
=== Improvements to Unit Map ===&lt;br /&gt;
&lt;br /&gt;
As described here: [http://www.wesnoth.org/forum/viewtopic.php?p=236063#236063] (cjhopman has submitted a patch on that already)&lt;br /&gt;
&lt;br /&gt;
=== Make the lua state persistent ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth is designed to make all data files as simple and human-readable as possible, including savefiles. WML is designed so that it is always very easy to write the entire WML state as plaintext and reload it correctly. There are many benefits of this, but especially &lt;br /&gt;
&lt;br /&gt;
* It makes it easy for beginners / students to read the files and see what's going on&lt;br /&gt;
* It makes it easy for us to debug problems without needing special tools to read the savefiles&lt;br /&gt;
* It makes it easy to edit save files to work around any possible bugs. Users have even reported opening savefiles from version 1.10 in microsoft word (!) to correct minor bugs in mp and resaving them, as a policy for tournament games.&lt;br /&gt;
&lt;br /&gt;
This was unfortunately somewhat lost when we added lua. If you use lua in your scenarios, things become more complicated because we can't save the lua state at all. If you rely on lua variables to save information, then when your scenario is saved and reloaded those variables will get wiped. The wesnoth engine provides places for lua to hook into &amp;quot;onsave&amp;quot; and &amp;quot;onload&amp;quot; so that the scenario developer can write their own serialization routines, but this is just punting the problem to scenario developers.&lt;br /&gt;
&lt;br /&gt;
We also provide the &amp;quot;preload&amp;quot; event type specifically to work around the issue -- unlike all other events, preload is called exactly once for every time the scenario is loaded. The purpose is to give another way that lua users can initialize a table of lua functions used by their addon and guarantee that this happens before the functions are called. But to non-lua users this event is basically unsafe for normal use otherwise -- if there is a preload event which e.g. increments a WML variable, then the WML state now depends on how many times the scenario is saved or reloaded. In a normal scenario, save / reload events should be invisible, and normally if this isn't the case it indicates a bug similar to an OOS.&lt;br /&gt;
&lt;br /&gt;
A nice solution to this would be if we properly serialized the lua state alongside the WML in a savefile. The most suitable solution is probably this library: https://github.com/fnuecke/eris&lt;br /&gt;
It would require significant additional work as well to find a good way to serialize the C functions that we expose to lua, and the userdata like units held by lua.&lt;br /&gt;
&lt;br /&gt;
More info here: http://lua-users.org/wiki/PlutoLibrary&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
=== Frequently Proposed Good Ideas ===&lt;br /&gt;
&lt;br /&gt;
Check the [http://www.wesnoth.org/forum/viewtopic.php?f=12&amp;amp;t=9054&amp;amp;start=0&amp;amp;st=0&amp;amp;sk=t&amp;amp;sd=a B.W.H. list] in the Ideas Forum. Be aware that some entries there are old and have already been implemented, so you will need to investigate that before beginning work.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Future]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55969</id>
		<title>NotSoEasyCoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55969"/>
		<updated>2014-12-09T02:58:25Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Data Structures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Foreword ==&lt;br /&gt;
This page shows projects which are considered a good idea by the developers but which have nobody working on them so far. If you think you've got the required skill for a task go on, implement it and you've got a high chance that it'll be accepted. The remaining barrier will only be that it's done well. :-)&lt;br /&gt;
&lt;br /&gt;
If you are such a person, you should feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
If you're not, you should post a feature request and discuss your idea on the forum or IRC. A coder with better knowledge of the code might give you the green light to add your feature here.&lt;br /&gt;
&lt;br /&gt;
Anybody should feel free to add &amp;quot;clues&amp;quot; to any tasks, that is entry points, traps to avoid, person to contact to discuss and so on.&lt;br /&gt;
&lt;br /&gt;
If you plan to work on a feature, write your name at the bottom of the feature, with the date. Note that if you are too long at working on a feature I'll &amp;quot;free&amp;quot; it back (that is if you're not working on it. If you have problems implementing it, just tell us....)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Game Engine ==&lt;br /&gt;
=== add a mode to improve OOS detection in MP ===&lt;br /&gt;
We really need an optional 'pedantic mode' for MP which detects OOSes immediately, by comparing all game state information after each action and printing any mismatches. This mode will be optional because of the extra overhead it adds, and it would be very useful for debugging.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Fix a longstanding bug concerning failure to initialize a side in networked mp&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
(Actually we may have a fix for this now... will post reference)&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/index.php?21397&lt;br /&gt;
&lt;br /&gt;
The problem itself is quite simple -- when the server tells a client that their turn has begun, the client immediately broadcasts [init_side] to all the other players via the server, performing the initial upkeep, healing, and movement point reset actions. However, if this player disconnects / blocks the action by opening a dialog during the prior turn and never closing it, [init_side] is never broadcast. And if the game is then saved by one of the other clients, nothing in the current mechanism detects that this has been overlooked when the game is reloaded. The consequence is that in the reloaded game, that side's turn is *never* initialized -- they get no gold, their units don't heal, and they don't get full move points at the start of the turn.&lt;br /&gt;
&lt;br /&gt;
Propose a mechanism to fix this -- perhaps games which have been loaded should be scanned to see if the current turn failed to initialize. Perhaps a flag in game_state could be used and saved. Perhaps a completely different approach. Check that your mechanism works whether the save is loaded from [snapshot] or [replay_start] and [replay].&lt;br /&gt;
&lt;br /&gt;
This bug has existed since at least Wesnoth 1.8&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Make a &amp;quot;replay actions since my last turn&amp;quot; button&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
It would be very convenient if there an ability to replay everything your opponents just did at the &lt;br /&gt;
start of your turn, since sometimes things go out of vision or are confusing. &lt;br /&gt;
&lt;br /&gt;
The feature would be like a &amp;quot;replay since my last turn&amp;quot; menu option or button -- most likely, the best approach to implement it is to store a copy of the game_state object in playcontroller.cpp or even in resources, and to refactor the backlog object so that we can hold a &amp;quot;bookmark&amp;quot;, i.e. a pointer, to the last position in the replay that we might look to jump back to. The replay process would work by swapping out for the old gamestate, then replaying through the actions since the bookmark until we get back up to speed. The difficult part would be making sure that scenarios with scripted WML events don't break when we do this. For debugging purposes, it might be good to check that at this point we have the same gamestate we did before we clicked the button. The bookmark should only be advanced when we end our turn, and there might be perhaps need to be multiple bookmarks, one for each side, to handle what happens when a side disconnects or is reassigned.&lt;br /&gt;
&lt;br /&gt;
It would be especially helpful for MP play to have this, where special tactics with ambush units are quite common. Part of the design criteria of wesnoth is that it should be a high-level, thoughtful turn based strategy game, but you should be able to play asynchronously and not necessarily give attention to the game until your turn bell rings if you don't want to. Having ambush units and no ability to replay their movements during the opponents turn harms that goal.&lt;br /&gt;
&lt;br /&gt;
For MP play, it will require special attention to make sure that events like &amp;quot;synchronize_choice&amp;quot; are handled correctly so as not to cause out of sync errors, and also that the timer is handled correctly.&lt;br /&gt;
&lt;br /&gt;
Feature request: https://gna.org/bugs/?15334&lt;br /&gt;
&lt;br /&gt;
Thanks to Zappaman for this. https://github.com/wesnoth/wesnoth/pull/270&lt;br /&gt;
&lt;br /&gt;
=== Improve WML error reporting ===&lt;br /&gt;
&lt;br /&gt;
There are many programming bugs that give very unclear or cryptic error messages when using WML. Here are some examples:&lt;br /&gt;
&lt;br /&gt;
-- When calling a macro with the wrong number of arguments, wesnoth tells the number it expected, and the number it got, and at which line number it was instantiated. However, it would be helpful if it would also tell the line number of the definition of the macro. This might be helpful if someone is redefining macros.&lt;br /&gt;
&lt;br /&gt;
-- For places where a standard unit filter is expected, if one is not found, the game should point out a problem. For places where such a filter is expected but [filter] child should not appear, if one does it should report an error and a line number. Many users have a hard time with this kind of thing.&lt;br /&gt;
&lt;br /&gt;
-- When doing scenario transitions in a campaign, if the side definitions don't matchup exactly the game tends to give unintelligible error messages. For instance, if one is transitioning and there is an AI side which does not have a leader (but it has a starting location in the map) it must have &amp;quot;no_leader = yes&amp;quot; in its [side] tag, or else when the team_builder objects enter stage two, the game will try to create a unit with an empty type, and the constructor of class unit will fail giving the error message &amp;quot;game::game_error tried to create unit with empty type&amp;quot;. This really needs to be much better. For instance, giving a line number of a problem, or suggesting that no_leader should be used. (Note that, it is often possible to debug problems like this by turning on --log-debug=team_construction at commandline but I doubt that there are any users that know about this, you would only learn from reading the C++... without such debug info, fixing things like this can literally take hours.) For that matter it's some question why the team_builder doesn't just stop trying to build a unit when it sees it doesn't have enough info...&lt;br /&gt;
&lt;br /&gt;
-- Recursive macros break the game, and not by stack overflow but by exhausting the heap. It would be nice if we could catch this and report an error.&lt;br /&gt;
&lt;br /&gt;
Many of the users of WML are students or beginners to programming, it is a big help to them to improve the error reporting of this nature -- not to mention that many veterans would appreciate as well. In part we need fixits here and there but more broadly we need a smarter system that can figure out what's really wrong when things go wrong and give helpful suggestions.&lt;br /&gt;
&lt;br /&gt;
=== Map label &amp;quot;groups&amp;quot; which can be selectively turned on and off by the user ===&lt;br /&gt;
&lt;br /&gt;
It would be nice if the user could have more control over how map labels are displayed, for instance to be able to check on / off labels made by certain players, and for custom scenarios, to be able to make custom classes which the use can turn on or off. This might be helpful for custom scenarios esp. which might have some technical info they want to show, but which it might be messy to display all of the time. The hard part of this is that there should ideally be a gui to work with the map labels, although maybe this need could be worked around or simplified somehow.&lt;br /&gt;
&lt;br /&gt;
=== Add a new damage stats calculation mode to support scenarios with extremely high stats ===&lt;br /&gt;
&lt;br /&gt;
Most players use the damage calculation window constantly when they play so that they can see what to expect from various attacks. The way the game is currently set up, when a unit is selected, as soon as another unit is moused over the stats for an attack will be calculated, whether or not the user actually brings up the window.&lt;br /&gt;
&lt;br /&gt;
The probabilities for the various outcomes are calculated by explicitly calculating the distribution of attacker and defender hp / slowed status after each swing by either party, one swing at a time. Thus at the end we get exact probabilities of the possible outcomes.&lt;br /&gt;
&lt;br /&gt;
However, this comes at a cost -- the running time of the calculation can in the worst case be something like O( attacker_hp * defender_hp * total_number_of_strikes). In default era wesnoth (and in much of UMC) this is fine because units don't get extremely high hp values. However in some UMC units do get extremely high hp, and many will also have specials like drain and berzerk, and may have many different weapons as well. At some point these scenarios become unplayable even on a machine of moderate specs because mousing over any unit causes &amp;gt; 10 seconds of lag during which the game becomes unresponsive, trying to calculate attack outcomes.&lt;br /&gt;
&lt;br /&gt;
In these cases, it would be better to give an &amp;quot;inexact&amp;quot; damage prediction, based on just simulating a few thousand attacks and plotting the results. Since it's a monte carlo algorithm rather than an exact algorithm, there will be some error, but if it makes the game playable then it's clearly an improvement, and anyways for &amp;quot;extreme stats&amp;quot; battles with high strikes and damage, the outcome is in a sense less random anyways because the outcomes with inordinate amounts of hits and misses are more and more rare (law of large numbers), so the error shouldn't actually be terribly significant.&lt;br /&gt;
&lt;br /&gt;
If there were an advanced preference that caused the predictions to use such an algorithm instead of the current one, so that the user could turn it on if they start to get problems, it would eliminate a significant headache for some UMC.&lt;br /&gt;
&lt;br /&gt;
== MP Related ==&lt;br /&gt;
&lt;br /&gt;
=== Automatically resolve add-on dependencies ===&lt;br /&gt;
&lt;br /&gt;
In 1.11 add-ons may declare dependencies. A related easy coding task is to allow the user to force breaking dependencies.&lt;br /&gt;
&lt;br /&gt;
A related goal which would be greatly beneficial would be that wesnoth can automatically resolve the dependencies by fetching the add-ons from the download server, when in the MP-lobby the user tries to join a game with a dependency they don't meet. A dialog would ideally be provided as well, or perhaps a preference.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?21705&lt;br /&gt;
&lt;br /&gt;
Even older: https://gna.org/bugs/?9683&lt;br /&gt;
&lt;br /&gt;
=== Gold graph ===&lt;br /&gt;
&lt;br /&gt;
Make a graph feature, presumably in a dialog, that helps depict the history of the game. For example it could display army value, army + bank value, number of villages tagged, luck swings... the purpose would be to assist spectators of a live game / spectators of a replay to understand the history of the game. It would be particularly helpful with AI development, by helping AI developers to identify key points where one of the AI is making a big mistake. &lt;br /&gt;
&lt;br /&gt;
A possible nice feature for this purpose would be to allow the user to click on the graph at key points which would trigger the &amp;quot;back to turn&amp;quot; mechanism to jump back in the replay, or automatically play the replay forwards from the beginning to that point... etc.&lt;br /&gt;
&lt;br /&gt;
Related email on dev-talk: https://mail.gna.org/public/wesnoth-dev/2014-02/msg00089.html&lt;br /&gt;
&lt;br /&gt;
=== Automatically link up to wesnothd server on a local network ===&lt;br /&gt;
&lt;br /&gt;
The feature request was to use ZeroConf technology, if available, to publish info of a running wesnothd instance to other machines on a local network. Then when they are searching to connect to an unofficial server, they won't have to learn the IP address.&lt;br /&gt;
&lt;br /&gt;
The extra code should be guarded with preprocessor flags so that ZeroConf does not become a build dependency of wesnoth.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?13703&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a set of &amp;quot;common&amp;quot; mp messages which players can use when they don't share a language ===&lt;br /&gt;
&lt;br /&gt;
Most users speak english, however, wesnoth also has large Polish and Hungarian communities, and many Brazilian players, not all of whom speak english. It would be nice we could have a set of messages that could be chatted, but which will be translated by our translators and displayed always in the current locale on each client, to make it easier to communicate in mp games / on the mp server.&lt;br /&gt;
&lt;br /&gt;
The hard part is that if you don't already know about the gettext translation system, you will have to learn about it. The messages should be stored in a .cfg file in the data folder so that they can be easily modified and can be handled in the same way that other in-game text is translated -- they should perhaps go in their own gettext-domain however. Ideally there would be a gui dialog of some kind to select from them.&lt;br /&gt;
&lt;br /&gt;
=== Improve server wml processing ===&lt;br /&gt;
&lt;br /&gt;
The wesver uses an alternative implementation to store and process wml objects see http://wiki.wesnoth.org/WesnothdDesign#simple_wml. This is for performance. However, the simple_wml sometimes messes up translation for mp scenarios / campaigns, resulting in mp scenarios/campaigns beeing untranslated for non-hosts in networked mp (http://gna.org/bugs/?22989). Fixing this is not easy becasue of the performance requirements.&lt;br /&gt;
&lt;br /&gt;
== Improvements to AI ==&lt;br /&gt;
=== Move and targeting phase ===&lt;br /&gt;
AI needs to move units which are not within range of the enemy. This is generally a sequence of moves (some interesting things like 'ambush!' or 'WML event' might happen as a result of those moves, which should interrupt this phase). The problem is that simply doing those moves 1-by-1 is very slow, for two reasons:&lt;br /&gt;
&lt;br /&gt;
#movement maps are invalidated after each move, and are recalculated from the start. yet, if we are doing just a sequence of moves, we can just 'remove moved unit from moves' after each move and avoid expensive recalculation of the movement map.&lt;br /&gt;
#* Note that WML could mess with the game state at any time, so at the very least, movement will need to be recalculated after a WML event blocks undo (that is, indicates that it changed game state). --[[User:Brilliand|Brilliand]] 01:30, 28 May 2012 (UTC)&lt;br /&gt;
#most tasks need devoting more than one unit to execute (i.e., it's meaningless to go for the enemy position with just 1 unit). So, making individual decisions just does some repeating calculations, which is slow.&lt;br /&gt;
&lt;br /&gt;
A practical demonstration of these concerns are LoW 2 (dwarf ai is slow due to large avoid aspect) and NR:Showdown (orc AIs there are slow because of huge number of units)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we need a fast and effective 'move and targeting stage' - both ideas and implementations are wanted.&lt;br /&gt;
Here's Sirp's idea (more in 2009-aug-15 irclog):&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Eval-based AI ===&lt;br /&gt;
The AI system would be based around an 'eval' function -- a formula which is given a position, and returns a number saying how attractive that position is.&lt;br /&gt;
&lt;br /&gt;
There would also be a 'candidate_moves' function -- a formula which is given a unit and returns a list of 'candidate moves' -- i.e. moves for that unit that the AI should consider making.&lt;br /&gt;
&lt;br /&gt;
The aim of the system is to come up with the combination of candidate moves that gives the best possible evaluation. By doing this, the AI will work in a team, since the 'eval' function can give bonuses for units being close together, protecting each other, etc.&lt;br /&gt;
&lt;br /&gt;
There are likely to be, of course, a very large combination of possible moves, and not every one can possibly be evaluated. Instead, we take a monte carlo approach.&lt;br /&gt;
&lt;br /&gt;
If an AI has N units that it can move, that is an N-dimension matrix of possible moves. We would choose some cells in this matrix at random and then evaluate them. Then, of these cells evaluated we would choose cells that evaluated well, and discard those that did not evaluate well. Then, we would begin with those cells that evaluated well, and choose a scattering of 'close by' cells -- i.e. cells where we only vary some of the dimensions, at random. We would continue to evaluate cells at random, starting with those cells that evaluated well, and evaluating cells nearby. After several iterations, we would hope to arrive at a cell that evaluates very well, and we would use this as our set of moves.&lt;br /&gt;
&lt;br /&gt;
Of course, this system will be made more complex by the uncertainty of attacks. There are a number of ways to handle attacks, probably the easiest being to consider attacks as types of moves, and then if a move combination involving an attack is chosen, perform the attack and then re-run the entire AI algorithm before moving again. (Something similar to what the current AI does).&lt;br /&gt;
&lt;br /&gt;
This is effectively an AI framework, not an AI in itself. How well it performs will correlate strongly with how good an eval() function one can write, and is also based on the notion that generally certain combinations of moves are 'similar' to other combinations.&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Village grabbing ===&lt;br /&gt;
&lt;br /&gt;
Improve AI village grabbing algorithm to assign villages that are farther than one turn from current unit location.&lt;br /&gt;
Idea how to do would be value villages so that it can filter out villages that belongs to enemies/allies sides.  Those villages are stored in memory and used in 2nd pass that determines how AI should dispatch units to get villages if it should at all in this turn. This should be close to optimal solution with currently available units but performance limits should be taken into account.&lt;br /&gt;
Good solution would be that village grabbing value could be calculated with attack ratings and if some village has high value it would make unit go for that village instead &lt;br /&gt;
&lt;br /&gt;
This should help AI in begin of scenario. Currently AI might not grab all of villages that belong to its area which results quite large incoming loses.&lt;br /&gt;
In later game enemy might have large number of units in one part of map so village grabbing should be avoided in that are. Single unit would be easy pray for enemy so moving there would result just to loses.&lt;br /&gt;
&lt;br /&gt;
== Data Structures ==&lt;br /&gt;
=== Config Writer ===&lt;br /&gt;
&lt;br /&gt;
The speed of saving Wesnoth games is dominated by the time to marshall all the config structures.  This involves deep copying them many times as each subsystem returns its config bundle; far better would be to have a &amp;quot;config_writer&amp;quot; class which is handed to each subsystem which iterates through its structures and does the writing (to file or network) directly to the config_writer instance.&lt;br /&gt;
&lt;br /&gt;
Stop by #wesnoth-dev on freenode irc if you want to help with this, or post in the Coder's Corner.&lt;br /&gt;
&lt;br /&gt;
=== Config memory optimisation ===&lt;br /&gt;
&lt;br /&gt;
Right now, most of the memory used by wesnoth when using '''low_memory''' configuration flag is used by the config object trees. It would be possible to drop unused &amp;quot;branches&amp;quot; of that trees by using boost smart pointers in the config structure&lt;br /&gt;
&lt;br /&gt;
come and discuss that change on #wesnoth-dev. Sirp is the one that knows the most about that...&lt;br /&gt;
&lt;br /&gt;
=== Improvements to Unit Map ===&lt;br /&gt;
&lt;br /&gt;
As described here: [http://www.wesnoth.org/forum/viewtopic.php?p=236063#236063] (cjhopman has submitted a patch on that already)&lt;br /&gt;
&lt;br /&gt;
=== Make the lua state persistent ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth is designed to make all data files as simple and human-readable as possible, including savefiles. WML is designed so that it is always very easy to write the entire WML state as plaintext and reload it correctly. There are many benefits of this, but especially &lt;br /&gt;
&lt;br /&gt;
* It makes it easy for beginners / students to read the files and see what's going on&lt;br /&gt;
* It makes it easy for us to debug problems without needing special tools to read the savefiles&lt;br /&gt;
* It makes it easy to edit save files to work around any possible bugs. Users have even reported opening savefiles from version 1.10 in microsoft word (!) to correct minor bugs in mp and resaving them, as a policy for tournament games.&lt;br /&gt;
&lt;br /&gt;
This was unfortunately somewhat lost when we added lua. If you use lua in your scenarios, things become more complicated because we can't save the lua state at all. If you rely on lua variables to save information, then when your scenario is saved and reloaded those variables will get wiped. The wesnoth engine provides places for lua to hook into &amp;quot;onsave&amp;quot; and &amp;quot;onload&amp;quot; so that the scenario developer can write their own serialization routines, but this is just punting the problem to scenario developers.&lt;br /&gt;
&lt;br /&gt;
We also provide the &amp;quot;preload&amp;quot; event type specifically to work around the issue -- unlike all other events, preload is called exactly once for every time the scenario is loaded. The purpose is to give another way that lua users can initialize a table of lua functions used by their addon and guarantee that this happens before the functions are called. But to non-lua users this event is basically unsafe for normal use otherwise -- if there is a preload event which e.g. increments a WML variable, then the WML state now depends on how many times the scenario is saved or reloaded. In a normal scenario, save / reload events should be invisible, and normally if this isn't the case it indicates a bug similar to an OOS.&lt;br /&gt;
&lt;br /&gt;
A nice solution to this would be if we properly serialized the lua state alongside the WML in a savefile. The most suitable solution is probably this library: https://github.com/fnuecke/eris&lt;br /&gt;
It would require significant additional work as well to find a good way to serialize the C functions that we expose to lua, and the userdata like units held by lua.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
=== Frequently Proposed Good Ideas ===&lt;br /&gt;
&lt;br /&gt;
Check the [http://www.wesnoth.org/forum/viewtopic.php?f=12&amp;amp;t=9054&amp;amp;start=0&amp;amp;st=0&amp;amp;sk=t&amp;amp;sd=a B.W.H. list] in the Ideas Forum. Be aware that some entries there are old and have already been implemented, so you will need to investigate that before beginning work.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Future]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=EasyCoding&amp;diff=55968</id>
		<title>EasyCoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=EasyCoding&amp;diff=55968"/>
		<updated>2014-12-09T02:32:26Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* GUI related features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Foreword ==&lt;br /&gt;
&lt;br /&gt;
'''We are permanently updating this page. Parts marked by &amp;lt;s&amp;gt;strikeout&amp;lt;/s&amp;gt; will likely be deleted shortly.&lt;br /&gt;
&lt;br /&gt;
This page is here to document easy to do coding tasks. It is not here to double the feature request database, and should only be filled by people that know the code well enough to judge the difficulty of a given task. &lt;br /&gt;
&lt;br /&gt;
If you are such a person, you should feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
If you're not, you should post a feature request and discuss your idea on the forum or IRC. A coder with better knowledge of the code might give you the green light to add your feature here.&lt;br /&gt;
&lt;br /&gt;
Anybody should feel free to add &amp;quot;clues&amp;quot; to any tasks, that is entry points, traps to avoid, person to contact to discuss and so on.&lt;br /&gt;
&lt;br /&gt;
If you plan to work on a feature, write your name at the bottom of the feature, with the date. Note that if you are too long at working on a feature I'll &amp;quot;free&amp;quot; it back (that is if you're not working on it. If you have problems implementing it, just tell us....)&lt;br /&gt;
&lt;br /&gt;
--[[User:Boucman|Boucman]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If none of these are to your liking, feel free to check our [http://gna.org/bugs/?group=wesnoth bug tracker] with a broad spectrum of tasks.&lt;br /&gt;
&lt;br /&gt;
== Engine related features ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt; Make a context menu option for command mode &amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Make an alternate pathway to the command mode, normally activated with `:`. Some players have trouble getting used to this, a right click menu option may be easier for them.&lt;br /&gt;
&lt;br /&gt;
See forum discussion here: http://forums.wesnoth.org/viewtopic.php?f=12&amp;amp;t=40300&lt;br /&gt;
&lt;br /&gt;
Zappaman - 10/07/2014&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt; Make a preference to disable the &amp;quot;automatic moves&amp;quot; at the beginning of a turn &amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
There is already an option in the loadgame dialog to cancel all &amp;quot;planned&amp;quot; actions before loading your turn in SP. However it would also be nice esp. for MP to have a preference that would disable this behavior entirely, as for some players it can be quite frustrating. &lt;br /&gt;
&lt;br /&gt;
See feature request here: https://gna.org/bugs/?9906&lt;br /&gt;
https://gna.org/bugs/?17195&lt;br /&gt;
&lt;br /&gt;
Thanks to LovCAPONE for this.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt; Make a &amp;quot;play single move&amp;quot; button in the replay viewer &amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
This is an often requested feature. The idea is to have a third `play` button which plays until a move or attack command appears, then stops again. &lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?9354&lt;br /&gt;
&lt;br /&gt;
Thanks to Zappaman for this.&lt;br /&gt;
&lt;br /&gt;
=== Make a &amp;quot;map diff&amp;quot; tool to visualizes changes between two version of a map ===&lt;br /&gt;
&lt;br /&gt;
Maintainers of maps often make small tweaks for balance purposes. For someone who doesn't know the map like the back of their hand it may be very difficult to spot exactly what changed. There isn't any really good way to do this right now -- using the 'diff' tool at command line doesn't give good results for .map files.&lt;br /&gt;
&lt;br /&gt;
Such a tool would be helpful for someone who maintains a map pool containing maps made by others, also for someone who wants to browse a repository and examine balance changes on several maps, which could be instructive for someone who wants to make and balance their own maps.&lt;br /&gt;
&lt;br /&gt;
There's any number of ways to actually do this, one might be to have a feature in the map editor that takes the name of another map and adds map labels to indicate what hexes changed. It could also be a command accessible in debug mode when playing the game, or it could be an additional command-line argument (--diff [map1] [map2] ?) for the game. (It could be a standalone application but that's probably going to end up with much more work for you.)&lt;br /&gt;
&lt;br /&gt;
=== Make a GUI method to activate loggers ===&lt;br /&gt;
&lt;br /&gt;
One of the tricks of the trade of wml programming is that you can turn on many helpful loggers to assist sometimes. For instance, there are many pitfalls related to carryover / transitioning scenarios that don't really generate sensible error messages, or give you a good idea of where to look to fix it. However, turning on ''--log-debug=engine/team_construction'' can provide you with the info that you need.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, this requires you to pass command-line arguments to the program, and is really most comfortable for linux users. For mac / windows it is of course possible but many users will end up modifying a shortcut to achieve this, if they even know how to do it, and it's fairly awkward.&lt;br /&gt;
&lt;br /&gt;
It would be nice if we had a page of checkboxes or radiobuttons that could be reached from the main page, or from preferences, that could enable / disable the loggers for various channels, this would make it alot easier for the typical user to take advantage of the logger output.&lt;br /&gt;
&lt;br /&gt;
== MP related features ==&lt;br /&gt;
&lt;br /&gt;
=== Add possibility to switch off dependency checking ===&lt;br /&gt;
MP add-ons can define dependencies. Currently there's no way to force a &amp;quot;broken&amp;quot; configuration, although overzealous use of the system by UMC authors could make this feature useful. Add an option to the MP game creation screen to switch on/off dependency checking. Ask lipk (forum)/lipkab (IRC).&lt;br /&gt;
&lt;br /&gt;
=== Make a header for the add-on when we organize scenarios by add-on in the mp create dialog ===&lt;br /&gt;
&lt;br /&gt;
Using an established gui technique to signal when one block of scenarios for an add-on ends and the next begins would make it much easier to use this dialog, if the user has several add-ons.&lt;br /&gt;
&lt;br /&gt;
See one proposal here:&lt;br /&gt;
https://gna.org/bugs/?21653&lt;br /&gt;
&lt;br /&gt;
=== Make it possible to host a game which only registered players are allowed to join ===&lt;br /&gt;
&lt;br /&gt;
See feature request here:&lt;br /&gt;
https://gna.org/bugs/?14138&lt;br /&gt;
&lt;br /&gt;
=== Timer Pause Button ===&lt;br /&gt;
&lt;br /&gt;
Longstanding feature request here:&lt;br /&gt;
https://gna.org/bugs/?16733&lt;br /&gt;
&lt;br /&gt;
Request is for either a button, or a simple chat command like :pause, :unpause, to allow players to put the timer on hold if they are interrupted.&lt;br /&gt;
&lt;br /&gt;
Ideally would be accompanied with a multiplayer-only scenario attribute &amp;quot;number_of_pauses&amp;quot; which decreases each time a client pauses the game. Pause should use a blindfold object to black out the screen, and send a chat message automatically when it occurs / resume occurs. For an example of how it might look, start a local hotseat mp game and enable the Preferences-&amp;gt;General-&amp;gt;Turn Dialog option. (This behavior introduced in this commit: https://github.com/wesnoth/wesnoth/commit/bab03d554bea92f1ce6f585ef1123202173a3491)&lt;br /&gt;
&lt;br /&gt;
Wintermute also has other ideas about how the timer should / could work. For example, instead of their client ending their turn, the networked opponents could be required to &amp;quot;confirm&amp;quot; the time out. (This is probably a networked mp-only idea.)&lt;br /&gt;
&lt;br /&gt;
A very fancy implementation might instead of a counter, allow the other players to vote on whether a pause request is granted.&lt;br /&gt;
&lt;br /&gt;
Make sure that the paused client still responds to network commands, so that it is possible to kick a person who pauses and then doesn't ever unpause.&lt;br /&gt;
&lt;br /&gt;
=== Add a &amp;quot;concede&amp;quot; button ===&lt;br /&gt;
&lt;br /&gt;
Often times in mp, players concede the game before their leader is actually killed. When the game ends 'officially' the map is revealed, which can sometimes be instructive for the losing player. Additionally, it makes it easier to analyze the results of many games, for purposes of balancing, or for maintaining a ladder. So while it may seem small, this would actually be a pretty useful feature.&lt;br /&gt;
&lt;br /&gt;
== WML related features ==&lt;br /&gt;
&lt;br /&gt;
=== Side-specific results ===&lt;br /&gt;
Giving result=defeat or result=victory for specific sides. ([http://gna.org/bugs/index.php?4960 FR #4960]) -- [[User:dlr365|dlr365]] -- patch submitted [https://gna.org/bugs/index.php?4960]&lt;br /&gt;
&lt;br /&gt;
--[[User:Boucman|Boucman]] 08:58, 28 February 2010 (UTC) Patch seems abandonned, but can be used for further work feel free to take over the FR&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Support for leaderless multiplayergames&amp;lt;/s&amp;gt; ===&lt;br /&gt;
Add support for the WML key victory_when_enemies_defeated= in the scenario tag during multiplayergames. ([https://gna.org/bugs/index.php?8106 FR #8106])&lt;br /&gt;
&lt;br /&gt;
Actually this was solved... will put a reference soon.&lt;br /&gt;
&lt;br /&gt;
=== Support variable village healing, variable poison properties ===&lt;br /&gt;
&lt;br /&gt;
See a feature request here:&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/index.php?20919&lt;br /&gt;
&lt;br /&gt;
Suggested approach -- new read/writeable values in wesnoth.game_config:&lt;br /&gt;
&lt;br /&gt;
http://wiki.wesnoth.org/LuaWML:Misc#wesnoth.game_config&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt; Support shuffled music playlist &amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?19653&lt;br /&gt;
&lt;br /&gt;
Zappaman - 20/07/2014&lt;br /&gt;
&lt;br /&gt;
=== Support variable recall cost in wml ===&lt;br /&gt;
see https://gna.org/bugs/?16538&lt;br /&gt;
&lt;br /&gt;
the syntax needs to be discussed and refined, but the overall idea is good&lt;br /&gt;
&lt;br /&gt;
make sure to update whiteboard to handle this correctly&lt;br /&gt;
&lt;br /&gt;
Ask Boucman&lt;br /&gt;
&lt;br /&gt;
Aishiko 5 Mar 2014&lt;br /&gt;
&lt;br /&gt;
=== Support menu items available off turn ===&lt;br /&gt;
&lt;br /&gt;
Add an attribute named something like &amp;quot;available_off_of_turn&amp;quot; to the [set_menu_item] tag, which allows the player to use the menu item at any time in an mp game. The action should contain only things like messages, if the scenario coder doesn't respect that then OOS is a reasonable outcome.&lt;br /&gt;
&lt;br /&gt;
The main purpose of this is to allow players of umc scenarios to look at wml-defined info screens even when it's not their turn, which they currently can't do.&lt;br /&gt;
&lt;br /&gt;
=== Allow umc to query the viewing player ===&lt;br /&gt;
&lt;br /&gt;
Many theme / status items, for instance the gold and the countdown timer, display differently depending on whether the current player is also the viewing player. Using wesnoth.current we can determine the current player in lua, but we apparently can't determine the viewing player. Even though such info is not consistent across clients (and therefore can cause OOS if misused), it is useful for purposes of themes and status items.&lt;br /&gt;
&lt;br /&gt;
=== Enhancements to Existing Actions ===&lt;br /&gt;
&lt;br /&gt;
*[fire_event] id=X - allow firing an event by id instead of by name&lt;br /&gt;
*[allow_undo] {contents} - perform {contents} when move is undone.&lt;br /&gt;
''[allow_undo] will probably need a method to re-fire the event on redo.''&lt;br /&gt;
&lt;br /&gt;
=== Events Manipulation ===&lt;br /&gt;
&lt;br /&gt;
*[event] persistent=&amp;quot;yes&amp;quot; - creates an event that lasts for the rest of the campaign&lt;br /&gt;
* [disable_event][/disable_event] disables the event within which it appears (useful with conditionals). A more complex take on first_time_only=yes/no.&lt;br /&gt;
''This is largely possible with event IDs, but could be useful when multiple copies of an event should be floating around''&lt;br /&gt;
&lt;br /&gt;
=== Game Information ===&lt;br /&gt;
&lt;br /&gt;
*[query_location] - queries a location from the user&lt;br /&gt;
**variable&lt;br /&gt;
**[filter_location]&lt;br /&gt;
''Regarding [query_location]: probably a better name would be choose_location. This is used when a wml event is running and needs to get a target location hex from the user. For example, you right click on a catapult unit and choose the menu item &amp;quot;fire Catapult.&amp;quot; Now a [message] says to click on any target within 5 hexes. Now [choose_location] is encountered and the mouse cursor changes to a target sign (possibly customizable). If the user's mouse drifts outside of the allowed locations it changes to a cancel icon. If the operation is cancelled then the variable is cleared and no location stored. --Sapient''&lt;br /&gt;
&lt;br /&gt;
==== Automatically stored variables ====&lt;br /&gt;
&lt;br /&gt;
*$side_info - auto-stored side information&lt;br /&gt;
*$game_info - auto-stored game information&lt;br /&gt;
*$map_info - auto-stored map information&lt;br /&gt;
&lt;br /&gt;
== Improvements to AI ==&lt;br /&gt;
&lt;br /&gt;
Note: not all of these might be simple tasks.  Talk to Crab or mattsc.&lt;br /&gt;
&lt;br /&gt;
* Add a cost function to the C++ path finding code that takes avoided hexes into account, that is, hexes defined in an [ai][avoid] tag onto which the AI never moves.  Also add an option to the Lua wesnoth.find_path() function with which using this cost functions can be turned on and off.&lt;br /&gt;
**The background behind this task is the way how the default AI's move-to-targets candidate action works.  It does path finding for units without taking avoided hexes into account, and ''afterwards'' eliminates moves for which the end point falls onto an avoided hex.  As a result, some units might not move at all, even if it is, in principle, easily possible to move around an avoided area.  The inclusion of the new path-finding in the AI's move-to-targets phase could therefore be a follow-up task.&lt;br /&gt;
&lt;br /&gt;
* Make the (old) simple aspect syntax work when the Lua engine is defined for a side.  Setting aspects in the [side] tag like this:&lt;br /&gt;
 [ai]&lt;br /&gt;
     aggression=0.123&lt;br /&gt;
 [/ai]&lt;br /&gt;
does not work if the Lua engine is defined. You either need to use the [aspect] tag in the [side] tag with 'engine=lua', or use the code above in a [modify_side] tag in an event.  Making the above syntax available (as it is with the c++ engine) would be nice.  The same also applies to the FAI engine and to aspects set for AI sides in MP games.&lt;br /&gt;
&lt;br /&gt;
* Add a Lua function ai.get_individual_attacks() that returns all the single attacks the side can do (as opposed to attack combinations).  This needs to include an option to recalculate and take the current situation on the map into account (making the function believe that the game state has changed).&lt;br /&gt;
&lt;br /&gt;
* Set up an option the allows us to exclude units from the move-to-targets phase similar to [filter_own] for the combat phase (other than setting ai_special=guardian, which has a number of other side effects). Actually, having this option for all CA's would be nice.&lt;br /&gt;
&lt;br /&gt;
* Change the aspects &amp;quot;passive_leader&amp;quot;, &amp;quot;passive_leader_shares_keep&amp;quot;, &amp;quot;leader_ignores_keep&amp;quot; to work with multiple leaders. The idea is to change the type of those aspects from yes/no to string so both &amp;quot;passive_leader=yes&amp;quot; and &amp;quot;passive_leader=leader_id_1,leader_id_2&amp;quot; is possible.&lt;br /&gt;
&lt;br /&gt;
* ai.get_new_enemy_dst_src and related functions have several problems:&lt;br /&gt;
** They use the current moves of the enemy units, which generally are all zero.&lt;br /&gt;
** Hexes occupied by other enemy units count as not reachable.&lt;br /&gt;
**Units with zero moves are not listed at all, not even for the hex they are on.&lt;br /&gt;
**Working around this with a Lua wrapper makes this actually slower than ai_helper.get_enemy_dst_src, which makes the functions pretty much useless, as speed is the only thing speaking for them.&lt;br /&gt;
&lt;br /&gt;
* Add new options (keys or tags) to the Micro AIs.  As an example, some (but certainly not all) Micro AIs might benefit from taking some (but certainly not all) of the default AI aspects into account.&lt;br /&gt;
&lt;br /&gt;
* Write a script that automatically changes WML from the deprecated [ai][target] to the new [ai][goal] syntax.  Ideally, this would be part of wmllint.&lt;br /&gt;
** There are [http://wiki.wesnoth.org/AiWML#Deprecated_AI_Targeting_Aspects more deprecated AI aspect] which should eventually be added to this, but the [target] -&amp;gt; [goal] change would be a good and important start.&lt;br /&gt;
&lt;br /&gt;
== GUI related features ==&lt;br /&gt;
&lt;br /&gt;
Although Mordante developed the new GUI system GUI2, some dialogs still use the older GUI1 and could be improved or transferred. You should contact Mordante on IRC before starting to work on these.&lt;br /&gt;
&lt;br /&gt;
=== Theme Changes ===&lt;br /&gt;
&lt;br /&gt;
* hide the hourglass item from the statusbar when there is no timer&lt;br /&gt;
&lt;br /&gt;
=== Widget Changes ===&lt;br /&gt;
* make games sortable in the lobby (open slots, total number of players, era, XP modifier, gold per village, fog/shroud)&amp;lt;br&amp;gt;a GUI2 lobby is currently being developed, ask mordante whether this is still relevant&lt;br /&gt;
* input history (chat, commands, ..)&lt;br /&gt;
&lt;br /&gt;
== GUI2 related features ==&lt;br /&gt;
GUI2 is the new gui engine Mordante/SkeletonCrew is working on. &lt;br /&gt;
* Information on the wiki can be found here http://www.wesnoth.org/wiki/GUIToolkit&lt;br /&gt;
* The source code is under src/gui/&lt;br /&gt;
* The configuration config files are under data/gui/default&lt;br /&gt;
&lt;br /&gt;
Some tasks need the --new-widgets since the code is only shown in the experimental mode. Tasks which need this switch have the * in the title.&lt;br /&gt;
&lt;br /&gt;
=== Port the random map generator dialog to GUI2 ===&lt;br /&gt;
The map generator currently doesn't use the GUI2 framework, but there's no reason why it couldn't. Ask lipk (forum)/lipkab (IRC).&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;More powerful village naming&amp;lt;/s&amp;gt; ===&lt;br /&gt;
'''Adding mountain names and other features to village names, having a second random name in village names'''&lt;br /&gt;
&lt;br /&gt;
Currently the village naming engine has a very good structure that could allow more powerful names to be generated. &lt;br /&gt;
Understanding how it works should be quite easy, and a few useful improvements could be added.&lt;br /&gt;
&lt;br /&gt;
* Currently villages can use lake names and river names, this should be extended to other features like bridges, swamps, mountains etc...&lt;br /&gt;
* It would be nice to have a separate list of &amp;quot;first syllabus&amp;quot; and &amp;quot;last syllabus&amp;quot; for naming. That's not really needed in English, but some translations could use it&lt;br /&gt;
* Again, it is common to have villages with more than one &amp;quot;random&amp;quot; word in them. having a $name2 variable would be nice&lt;br /&gt;
&lt;br /&gt;
Turns out this was already done, and should be removed.&lt;br /&gt;
&lt;br /&gt;
=== Use friends list as a fallback for tab completion ===&lt;br /&gt;
&lt;br /&gt;
Currently wesnoth will use the list of current players, lobby members, as candidates for tab completion of names when whispering. The OP requests that the friends list also be merged in, in case one of your friends whispered you. Even better, could also remember names of anyone who whispered you in the last hour.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?9742&lt;br /&gt;
&lt;br /&gt;
=== Debug Mode ===&lt;br /&gt;
* New debug command functionality (setting additional status.variables, possibly terrain)&lt;br /&gt;
&lt;br /&gt;
=== wesnoth-optipng ===&lt;br /&gt;
For lossless png compression we use wesnoth-optipng, a script using an external toolchain (ImageMagick, OptiPNG, Advdef). Perhaps the performance could be improved by using PNGOut instead of advdef. This task includes&lt;br /&gt;
* a quick profiling of compression ratio and decompression speed for both tools&lt;br /&gt;
* if it provides a higher compression while not significantly slowing down decompression, adapt wesnoth-optipng to use PNGOut&lt;br /&gt;
&lt;br /&gt;
== Bugs ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[NotSoEasyCoding]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Future]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55965</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55965"/>
		<updated>2014-12-07T00:03:05Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Write exception-safe code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
In C++11, any destructor which throws an exception causes the program to be immediately terminated.&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
Similarly, avoid writing &amp;lt;tt&amp;gt;delete&amp;lt;/tt&amp;gt; explicitly in your code. Oftentimes using a smart pointer or similar instead will improve the readability of your code, by making it obvious that you are managing memory correctly even if an exception is thrown. If you were deleting a pointer which is a member variable of an object, using a smart pointer instead may simplify your code by eliminating the need to write an explicit destructor in some cases.&lt;br /&gt;
&lt;br /&gt;
For more information, you can read about the (important) RAII idiom: http://c2.com/cgi/wiki?ResourceAcquisitionIsInitialization&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55964</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55964"/>
		<updated>2014-12-06T23:22:52Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Write exception-safe code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
In C++11, any destructor which throws an exception causes the program to be immediately terminated.&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
Similarly, avoid writing &amp;lt;tt&amp;gt;delete&amp;lt;/tt&amp;gt; explicitly in your code. Oftentimes using a smart pointer or similar instead will improve the readability of your code, by making it obvious that you are managing memory correctly even if an exception is thrown. If you were deleting a pointer which is a member variable of an object, using a smart pointer instead may simplify your code by eliminating the need to write an explicit destructor in some cases.&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55961</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55961"/>
		<updated>2014-12-05T02:36:17Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Destructors must not throw exceptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
In C++11, any destructor which throws an exception causes the program to be immediately terminated.&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55960</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55960"/>
		<updated>2014-12-05T02:00:07Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Destructors must not throw exceptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes. In C++11, any destructor which throws an exception causes the program to be immediately terminated.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55959</id>
		<title>CodingStandards</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CodingStandards&amp;diff=55959"/>
		<updated>2014-12-05T01:58:23Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Destructors must not throw exceptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wesnoth uses C++ that is portable to C++ compilers targeting various commonly used platforms.&lt;br /&gt;
&lt;br /&gt;
== C++ version ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth uses C++ conforming to C++98/03. At the moment C++11 compiler support is still not widely available, therefore C++11 is not allowed.&lt;br /&gt;
&lt;br /&gt;
== Formatting ==&lt;br /&gt;
&lt;br /&gt;
When working on C++ for Wesnoth, indent your code with a tab character. After fully indenting, if you still need to line up the text with a specific character on the line above, you may further align it using space characters.&lt;br /&gt;
&lt;br /&gt;
You may use long lines.&lt;br /&gt;
&lt;br /&gt;
== Evil things to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Avoid implicit conversions ===&lt;br /&gt;
&lt;br /&gt;
Make all constructors which only take one argument that is of a different type to the class &amp;lt;tt&amp;gt;explicit&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;lt;tt&amp;gt;operator T()&amp;lt;/tt&amp;gt; (where &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; is a type) to allow an implicit conversion to a different type. For example:&lt;br /&gt;
&lt;br /&gt;
 t_string(const std::string&amp;amp;);&lt;br /&gt;
&lt;br /&gt;
This can cause many situations where a temporary t_string is implicitly created and then gets destroyed unexpectedly (reference [https://gna.org/bugs/index.php?20360 bug #20360]).&lt;br /&gt;
&lt;br /&gt;
=== Do not declare class data members as non-private ===&lt;br /&gt;
&lt;br /&gt;
It's okay to have a ''struct'' with only public members, if that's what you want.&lt;br /&gt;
&lt;br /&gt;
However, once something is a ''class'' with private data members, do not add public (or even protected) data members to the class. Doing this breaks encapsulation and can cause all kinds of confusing and evil things to happen.&lt;br /&gt;
&lt;br /&gt;
=== Destructors must not throw exceptions ===&lt;br /&gt;
&lt;br /&gt;
Do not allow exceptions to propogate from a destructor. Doing that is always bad in C++. Any code which does it should be treated as a bug and fixed. Doing this is a very easy way to cause memory leaks and crashes.&lt;br /&gt;
&lt;br /&gt;
It's okay to have exceptions thrown inside a destructor, just as long as you catch() them inside the destructor too and don't allow them to propagate out.&lt;br /&gt;
&lt;br /&gt;
You can read more about the issue here: http://c2.com/cgi/wiki?BewareOfExceptionsInTheDestructor&lt;br /&gt;
&lt;br /&gt;
== Naming ==&lt;br /&gt;
&lt;br /&gt;
=== End non-public class data members with an underscore ===&lt;br /&gt;
&lt;br /&gt;
All non-public data members of classes should have their names terminated with an underscore, to show that they are a class member. This makes for more readable code, once one is familiar with the convention.&lt;br /&gt;
&lt;br /&gt;
== Idioms ==&lt;br /&gt;
&lt;br /&gt;
=== Use references when a value may not be NULL ===&lt;br /&gt;
&lt;br /&gt;
If a value passed to a function can never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, use a reference instead of a pointer. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
rather than&lt;br /&gt;
&lt;br /&gt;
 void my_function(T* obj);&lt;br /&gt;
&lt;br /&gt;
This more clearly shows prospective users of the function that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; may never be &amp;lt;tt&amp;gt;NULL&amp;lt;/tt&amp;gt;, without them having to consult documentation or the implementation of the function.&lt;br /&gt;
&lt;br /&gt;
=== Use the const keyword ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; keyword in C++ allows interfaces to more clearly specify how they treat objects. &lt;br /&gt;
Always use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; when you are not going to modify an object. For example:&lt;br /&gt;
&lt;br /&gt;
 void my_function(const T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
This shows to the caller that &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt; will not be modified. If &amp;lt;tt&amp;gt;my_function()&amp;lt;/tt&amp;gt; may modify &amp;lt;tt&amp;gt;obj&amp;lt;/tt&amp;gt;, then use the following instead:&lt;br /&gt;
&lt;br /&gt;
 void my_function(T&amp;amp; obj);&lt;br /&gt;
&lt;br /&gt;
Likewise, if a variable is not changed after initialization, make it &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;, and mark member functions as &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; if they do not modify their object.&lt;br /&gt;
&lt;br /&gt;
=== Know the behavior of const references when types differ ===&lt;br /&gt;
&lt;br /&gt;
If you assign something to a &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; reference of a different type, if necessary (if the type is different but there is a conversion) the compiler will create a temporary and guarantee it lasts for the lifetime of the reference. So&lt;br /&gt;
&lt;br /&gt;
 char c = 0;&lt;br /&gt;
 const int&amp;amp; i = c;&lt;br /&gt;
 c = 5;&lt;br /&gt;
&lt;br /&gt;
will result in c == 5 and i == 0, which may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=== Write exception-safe code ===&lt;br /&gt;
&lt;br /&gt;
Wesnoth code should be exception-safe, even if you do not use exceptions directly. That is, you should be able to assume that an exception is thrown almost anywhere from within the code, with well-defined results (i.e. no resource leaks).&lt;br /&gt;
&lt;br /&gt;
Code that uses a pattern like the following is bad:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     SDL_Surface* image = IMG_Load(&amp;quot;image.bmp&amp;quot;);&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
     SDL_FreeSurface(image);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The code may throw an exception, and &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; will never be freed. Instead, use wrapper objects which free the object in their destructor.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;tt&amp;gt;SDL_Surface&amp;lt;/tt&amp;gt; objects, the &amp;lt;tt&amp;gt;surface&amp;lt;/tt&amp;gt; type is used throughout the Wesnoth source code to achieve this purpose. So you could rewrite the above code as follows:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     surface image(IMG_Load(&amp;quot;image.bmp&amp;quot;));&lt;br /&gt;
     ...some code, which uses 'image'...&lt;br /&gt;
 } ''the image is automatically freed here when 'image' is destroyed&lt;br /&gt;
&lt;br /&gt;
Instead of allocating memory directly using &amp;lt;tt&amp;gt;new[]&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;malloc()&amp;lt;/tt&amp;gt;, use language-provided containers, such as vector.&lt;br /&gt;
&lt;br /&gt;
=== Do not use sprintf ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; function does not check whether or not it is writing past the end of the space allocated.  This is a security problem if someone other than the person running the game can cause &amp;lt;tt&amp;gt;sprintf()&amp;lt;/tt&amp;gt; to write very long strings. In Wesnoth, this untrusted data could come potentially from other players in a multiplayer game, or from downloaded add-ons. Instead you should use &amp;lt;tt&amp;gt;snprintf()&amp;lt;/tt&amp;gt; with the second argument being the &amp;lt;tt&amp;gt;sizeof&amp;lt;/tt&amp;gt; of the buffer that will hold the result.&lt;br /&gt;
&lt;br /&gt;
== Standard C++ to avoid ==&lt;br /&gt;
&lt;br /&gt;
=== Do not use wstring ===&lt;br /&gt;
&lt;br /&gt;
The standard C++ &amp;lt;tt&amp;gt;std::wstring&amp;lt;/tt&amp;gt; class (defined as a &amp;lt;tt&amp;gt;std::basic_string&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;) does not exist in some platforms supported by Wesnoth. Use &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; instead (defined in &amp;lt;tt&amp;gt;language.hpp&amp;lt;/tt&amp;gt;). The &amp;lt;tt&amp;gt;wide_string&amp;lt;/tt&amp;gt; type is actually defined as &amp;lt;tt&amp;gt;std::vector&amp;lt; wchar_t &amp;gt;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may use std::wstring in an #if that guarantees that wstring is supported on all supported plattforms that don't get filtered out by the #if.&lt;br /&gt;
&lt;br /&gt;
=== Do not use 0 when you mean NULL ===&lt;br /&gt;
&lt;br /&gt;
Several Wesnoth developers, including Dave, find the number 0 to be very ambiguous when used in a non-numeric context. In keeping with the precedent that has already been established in the Wesnoth source code, you should avoid using literal zero for initializing and/or comparing null pointers.&lt;br /&gt;
&lt;br /&gt;
== C legacy to be avoided ==&lt;br /&gt;
&lt;br /&gt;
=== Use util::array instead of C-style Arrays ===&lt;br /&gt;
&lt;br /&gt;
C-style arrays are very efficient, but their interface is ugly. Use &amp;lt;tt&amp;gt;util::array&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;array.hpp&amp;lt;/tt&amp;gt; instead. It is a wrapper for an array which has a C++ container-style interface. If you need to, extend it to make it fit your needs.&lt;br /&gt;
&lt;br /&gt;
=== Do not use C-style casts ===&lt;br /&gt;
&lt;br /&gt;
The following code,&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == (size_t)player_number_) {&lt;br /&gt;
&lt;br /&gt;
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of &amp;lt;tt&amp;gt;static_cast&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reinterpret_cast&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;const_cast&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Good programming style is to use the least powerful tool available that does what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 if(i-&amp;gt;second.side() == static_cast&amp;lt;size_t&amp;gt;(player_number_)) {&lt;br /&gt;
&lt;br /&gt;
Alternatively, a constructor call may be used for non-built-in types.&lt;br /&gt;
&lt;br /&gt;
''Note: there may be some obscure cases where a C-style cast is desirable, such as converting a pointer to an integer type of unspecified size.''&lt;br /&gt;
&lt;br /&gt;
=== Do not use #define for constants ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;define foo X&amp;lt;/tt&amp;gt; is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.&lt;br /&gt;
&lt;br /&gt;
 namespace {&lt;br /&gt;
     const T foo = X;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
=== Document config preconditions and postconditions ===&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth code you will commonly encounter a data container type known as &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt;, which contains hierarchical string data (such as WML contents or game settings). The tagged ''children'' of the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object and their string ''attributes'' are arranged in an ordered and mapped format, internally implemented using the C++ STL.&lt;br /&gt;
&lt;br /&gt;
Because &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; data is utilized in so many ways and places, it can be difficult to track across the scope of the entire program. Thus, you should document all public functions that take/return &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; objects, specifying content expectations and updating any related entries in the [[ReferenceWML]] wiki pages. In particular, if your function requires a &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; parameter, specify where/how the &amp;lt;tt&amp;gt;config&amp;lt;/tt&amp;gt; object should be created. This will be a great help to any future coders who need to call or modify your function.&lt;br /&gt;
&lt;br /&gt;
=== Doxygen ===&lt;br /&gt;
&lt;br /&gt;
See [[Doxygen]] for tips on how to comment the code, so that Doxygen can nicely document it.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[HackingWesnoth]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Display&amp;diff=55958</id>
		<title>LuaWML/Display</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Display&amp;diff=55958"/>
		<updated>2014-12-05T00:25:56Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* wesnoth.theme_items */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for interfacing with the user.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.message ====&lt;br /&gt;
&lt;br /&gt;
Displays a string in the chat window and dumps it to the lua/info log domain (''--log-info=scripting/lua'' on the command-line).&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The chat line header is &amp;quot;&amp;lt;Lua&amp;gt;&amp;quot; by default, but it can be changed by passing a string before the message.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(&amp;quot;Big Brother&amp;quot;, &amp;quot;I'm watching you.&amp;quot;) -- will result in &amp;quot;&amp;amp;lt;Big Brother&amp;amp;gt; I'm watching you.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
See also [[LuaWML:Events#helper.wml_error|helper.wml_error]] for displaying error messages.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.clear_messages ====&lt;br /&gt;
&lt;br /&gt;
Removes all messages from the chat window. No argument or returned values.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.textdomain ====&lt;br /&gt;
&lt;br /&gt;
Creates a function proxy for lazily translating strings from the given domain.&lt;br /&gt;
&lt;br /&gt;
 -- #textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 -- the comment above ensures the subsequent strings will be extracted to the proper domain&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;my_unit.description&amp;quot;, _ &amp;quot;the unit formerly known as Hero&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The metatable of the function proxy appears as '''&amp;quot;message domain&amp;quot;'''. The metatable of the translatable strings (results of the proxy) appears as '''&amp;quot;translatable string&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
The translatable strings can be appended to other strings/numbers with the standard '''..''' operator. Translation can be forced with the standard '''tostring''' operator in order to get a plain string.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(string.format(tostring(_ &amp;quot;You gain %d gold.&amp;quot;), amount))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.delay ====&lt;br /&gt;
&lt;br /&gt;
Delays the engine like the [delay] tag. one argument: time to delay in milliseconds&lt;br /&gt;
&lt;br /&gt;
 wesnoth.delay(500)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.float_label ====&lt;br /&gt;
&lt;br /&gt;
Pops some text above a map tile.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.float_label(unit.x, unit.y, &amp;quot;&amp;amp;lt;span color='#ff0000'&amp;amp;gt;Ouch&amp;amp;lt;/span&amp;amp;gt;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_of_day ====&lt;br /&gt;
&lt;br /&gt;
Returns schedule information. First parameter (optional) is the turn number for which to return the information, if unspecified: the current turn ($turn_number). Second argument is an optional table. If present, first and second fields must be valid on-map coordinates and all current time_areas in the scenario are taken into account (if a time area happens to contain the passed hex). If the table isn't present, the scenario main schedule is returned. The table has an optional third parameter (boolean). If true (default: false), time of day modifying units and terrain (such as Mages of Light or lava) are taken into account (if the passed hex happens to be affected). The units' placement being considered is always the current one.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.get_time_of_day(2, { 37, 3, true })&lt;br /&gt;
&lt;br /&gt;
The function returns a table with these named fields:&lt;br /&gt;
* '''id''': string (as in [time])&lt;br /&gt;
* '''lawful_bonus''': integer (as in [time])&lt;br /&gt;
* '''bonus_modified''': integer (bonus change by units)&lt;br /&gt;
* '''image''': string (tod image in sidebar)&lt;br /&gt;
* '''name''': translatable string&lt;br /&gt;
* '''red, green, blue''': integers (color adjustment for this time)&lt;br /&gt;
&lt;br /&gt;
The optional first parameter does not work if there is no turn limit in 1.11.0 and earlier.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.select_hex ====&lt;br /&gt;
&lt;br /&gt;
Selects the given location in the game map as if the player would have clicked onto it.&lt;br /&gt;
Argument 3: boolean, whether to show the movement range of any unit on that location (def: true)&lt;br /&gt;
Argument 4: boolean, whether to fire any select events (def: false)&lt;br /&gt;
&lt;br /&gt;
 wesnoth.select_hex(14,6, true, true)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.scroll_to_tile ====&lt;br /&gt;
&lt;br /&gt;
Scrolls the map to the given location. If true is passed as the third parameter, scrolling is disabled if the tile is hidden under the fog. If true is passed as the fourth parameter {{DevFeature1.11}}, the view instantly warps to the location regardless of the scroll speed setting in Preferences.&lt;br /&gt;
&lt;br /&gt;
 local u = wesnoth.get_units({ id = &amp;quot;hero&amp;quot; })[1]&lt;br /&gt;
 wesnoth.scroll_to_tile(u.x, u.y)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.lock_view ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} Locks or unlocks gamemap view scrolling for human players. If true is passed as the first parameter, the view is locked; pass false to unlock.&lt;br /&gt;
&lt;br /&gt;
Human players cannot scroll the gamemap view as long as it is locked, but Lua or WML actions such as wesnoth.scroll_to_tile still can; the locked/unlocked state is preserved when saving the current game. This feature is generally intended to be used in cutscenes to prevent the player scrolling away from scripted actions.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.lock_view(true)&lt;br /&gt;
 wesnoth.scroll_to_tile(12, 14, false, true)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.view_locked ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} Returns a boolean indicating whether gamemap view scrolling is currently locked.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.play_sound ====&lt;br /&gt;
&lt;br /&gt;
Plays the given sound file once, optionally repeating it one or more more times if an integer value is provided as a second argument (note that the sound is ''repeated'' the number of times specified in the second argument, i.e. a second argument of 4 will cause the sound to be played once and then repeated four more times for a total of 5 plays. See the example below).&lt;br /&gt;
&lt;br /&gt;
 wesnoth.play_sound &amp;quot;ambient/birds1.ogg&amp;quot;&lt;br /&gt;
 wesnoth.play_sound(&amp;quot;magic-holy-miss-3.ogg&amp;quot;, 4) -- played 1 + 4 = 5 times&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_music ====&lt;br /&gt;
&lt;br /&gt;
Sets the given table as an entry into the music list. See [[MusicListWML]] for the recognized attributes.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_music { name = &amp;quot;traveling_minstrels.ogg&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
Passing no argument forces the engine to take into account all the recent changes to the music list. (Note: this is done automatically when sequences of WML commands end, so it is useful only for long events.)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.show_dialog ====&lt;br /&gt;
&lt;br /&gt;
Displays a dialog box described by a WML table and returns:&lt;br /&gt;
* if the dialog was dismissed by a button click, the integer value associated to the button via the &amp;quot;return_value&amp;quot; keyword.&lt;br /&gt;
* if the dialog was closed with the enter key, -1.&lt;br /&gt;
* if the dialog was closed with the escape key, -2.&lt;br /&gt;
&lt;br /&gt;
The dialog box is equivalent to the resolution section of a GUI window as described in [[GUIToolkitWML#Window_definition|GUIToolkitWML]] and must therefore contain at least the following children: '''[tooltip]''', '''[helptip]''', and '''[grid]'''. The [grid] must contain nested [row], [column] and [grid] tags which describe the layout of the window. (More information can be found in [[GUILayout]]; suffice to say that the basic structure is grid -&amp;gt; row -&amp;gt; column -&amp;gt; widget, where the widget is considered to be in a cell defined by the row and column of the grid. A list of widgets can be found at [[GUIWidgetInstanceWML]].)&lt;br /&gt;
&lt;br /&gt;
Two optional functions can be passed as second and third arguments; the first one is called once the dialog is created and before it is shown; the second one is called once the dialog is closed. These functions are helpful in setting the initial values of the fields and in recovering the final user values. These functions can call the [[#wesnoth.set_dialog_value]], [[#wesnoth.get_dialog_value]], and [[#wesnoth.set_dialog_callback]] functions for this purpose.&lt;br /&gt;
&lt;br /&gt;
This function should be called in conjunction with [[LuaWML:Misc#wesnoth.synchronize_choice|#wesnoth.synchronize_choice]], in order to ensure that only one client displays the dialog and that the other ones recover the same input values from this single client.&lt;br /&gt;
&lt;br /&gt;
The example below defines a dialog with a list and two buttons on the left, and a big image on the right. The ''preshow'' function fills the list and defines a callback on it. This ''select'' callback changes the displayed image whenever a new list item is selected. The ''postshow'' function recovers the selected item before the dialog is destroyed.&lt;br /&gt;
&lt;br /&gt;
 local helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
 local T = helper.set_wml_tag_metatable {}&lt;br /&gt;
 local _ = wesnoth.textdomain &amp;quot;wesnoth&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 local dialog = {&lt;br /&gt;
   T.tooltip { id = &amp;quot;tooltip_large&amp;quot; },&lt;br /&gt;
   T.helptip { id = &amp;quot;tooltip_large&amp;quot; },&lt;br /&gt;
   T.grid { T.row {&lt;br /&gt;
     T.column { T.grid {&lt;br /&gt;
       T.row { T.column { horizontal_grow = true, T.listbox { id = &amp;quot;the_list&amp;quot;,&lt;br /&gt;
         T.list_definition { T.row { T.column { horizontal_grow = true,&lt;br /&gt;
           T.toggle_panel { T.grid { T.row {&lt;br /&gt;
             T.column { horizontal_alignment = &amp;quot;left&amp;quot;, T.label { id = &amp;quot;the_label&amp;quot; } },&lt;br /&gt;
             T.column { T.image { id = &amp;quot;the_icon&amp;quot; } }&lt;br /&gt;
           } } }&lt;br /&gt;
         } } }&lt;br /&gt;
       } } },&lt;br /&gt;
       T.row { T.column { T.grid { T.row {&lt;br /&gt;
         T.column { T.button { id = &amp;quot;ok&amp;quot;, label = _&amp;quot;OK&amp;quot; } },&lt;br /&gt;
         T.column { T.button { id = &amp;quot;cancel&amp;quot;, label = _&amp;quot;Cancel&amp;quot; } }&lt;br /&gt;
       } } } }&lt;br /&gt;
     } },&lt;br /&gt;
     T.column { T.image { id = &amp;quot;the_image&amp;quot; } }&lt;br /&gt;
   } }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 local function preshow()&lt;br /&gt;
     local t = { &amp;quot;Ancient Lich&amp;quot;, &amp;quot;Ancient Wose&amp;quot;, &amp;quot;Elvish Avenger&amp;quot; }&lt;br /&gt;
     local function select()&lt;br /&gt;
         local i = wesnoth.get_dialog_value &amp;quot;the_list&amp;quot;&lt;br /&gt;
         local ut = wesnoth.unit_types[t[i]].__cfg&lt;br /&gt;
         wesnoth.set_dialog_value(string.gsub(ut.profile, &amp;quot;([^/]+)$&amp;quot;, &amp;quot;transparent/%1&amp;quot;), &amp;quot;the_image&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
     wesnoth.set_dialog_callback(select, &amp;quot;the_list&amp;quot;)&lt;br /&gt;
     for i,v in ipairs(t) do&lt;br /&gt;
         local ut = wesnoth.unit_types[v].__cfg&lt;br /&gt;
         wesnoth.set_dialog_value(ut.name, &amp;quot;the_list&amp;quot;, i, &amp;quot;the_label&amp;quot;)&lt;br /&gt;
         wesnoth.set_dialog_value(ut.image, &amp;quot;the_list&amp;quot;, i, &amp;quot;the_icon&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
     wesnoth.set_dialog_value(2, &amp;quot;the_list&amp;quot;)&lt;br /&gt;
     select()&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local li = 0&lt;br /&gt;
 local function postshow()&lt;br /&gt;
     li = wesnoth.get_dialog_value &amp;quot;the_list&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local r = wesnoth.show_dialog(dialog, preshow, postshow)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Button %d pressed. Item %d selected.&amp;quot;, r, li))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_value ====&lt;br /&gt;
&lt;br /&gt;
Sets the value of a widget on the current dialog. The value is given by the first argument; its semantic depends on the type of widget it is applied to. The last argument is the ''id'' of the widget. If it does not point to a unique widget in the dialog, some discriminating parents should be given on its left, making a path that is read from left to right by the engine. The row of a list is specified by giving the ''id' of the list as a first argument and the 1-based row number as the next argument.&lt;br /&gt;
&lt;br /&gt;
 -- sets the value of a widget &amp;quot;bar&amp;quot; in the 7th row of the list &amp;quot;foo&amp;quot;&lt;br /&gt;
 wesnoth.set_value(_&amp;quot;Hello world&amp;quot;, &amp;quot;foo&amp;quot;, 7, &amp;quot;bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Notes: When the row of a list does not exist, it is created. The value associated to a list is the selected row.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_dialog_value ====&lt;br /&gt;
&lt;br /&gt;
Gets the value of a widget on the current dialog. The arguments described the path for reaching the widget (see [[#wesnoth.set_dialog_value]]).&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_active ====&lt;br /&gt;
&lt;br /&gt;
Enables or disables a widget.  The first argument is a boolean specifying whether the widget should be active (true) or inactive (false).  The remaining arguments are the path to locate the widget in question (see [[#wesnoth.set_dialog_value]]).&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_callback ====&lt;br /&gt;
&lt;br /&gt;
Sets the first argument as a callback function for the widget obtained by following the path of the other arguments (see [[#wesnoth.set_dialog_value]]). This function will be called whenever the user modifies something about the widget, so that the dialog can react to it.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_markup ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11|9}}&lt;br /&gt;
&lt;br /&gt;
Sets the flag associated to a widget to enable or disable Pango markup. The new flag value is passed as the first argument (boolean), and the widget to modify is obtained by following the path of the other arguments (see [[#wesnoth.set_dialog_value]]). Most widgets start with Pango markup disabled unless this function is used to set their flag to true.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_dialog_markup(true, &amp;quot;notice_label&amp;quot;)&lt;br /&gt;
 wesnoth.set_dialog_value(&amp;quot;&amp;amp;lt;big&amp;amp;gt;NOTICE!&amp;amp;lt;/big&amp;amp;gt;&amp;quot;, &amp;quot;notice_label&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_canvas ====&lt;br /&gt;
&lt;br /&gt;
Sets the WML passed as the second argument as the canvas content (index given by the first argument) of the widget obtained by following the path of the other arguments (see [[#wesnoth.set_dialog_value]]). The content of the WML table is described at [[GUICanvasWML]].&lt;br /&gt;
&lt;br /&gt;
 -- draw two rectangles in the upper-left corner of the window (empty path = window widget)&lt;br /&gt;
 wesnoth.set_dialog_canvas(2, {&lt;br /&gt;
     T.rectangle { x = 20, y = 20, w = 20, h = 20, fill_color= &amp;quot;0,0,255,255&amp;quot; },&lt;br /&gt;
     T.rectangle { x = 30, y = 30, w = 20, h = 20, fill_color = &amp;quot;255,0,0,255&amp;quot; }&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
The meaning of the canvas index depends on the chosen widget. It may be the disabled / enabled states of the widget, or its background / foreground planes, or... For instance, overwriting canvas 1 of the window with an empty canvas causes the window to become transparent.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_displayed_unit ====&lt;br /&gt;
&lt;br /&gt;
Returns a proxy to the unit currently displayed in the side pane of the user interface, if any.&lt;br /&gt;
&lt;br /&gt;
 local name = tostring(wesnoth.get_displayed_unit().name)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.theme_items ====&lt;br /&gt;
&lt;br /&gt;
This field is not a function but an associative table. It links item names to the functions that describe their content. These functions are called whenever the user interface is refreshed. The description of an item is a WML table containing '''[element]''' children. Each subtag shall contain either a '''text''' or an '''image''' field that is displayed to the user. It can also contain a '''tooltip''' field that is displayed to the user when moused over, and a &amp;quot;help&amp;quot; field that points to the help section that is displayed when the user clicks on the theme item.&lt;br /&gt;
&lt;br /&gt;
Note that the ''wesnoth.theme_items'' table is originally empty and using ''pairs'' or ''next'' on it will not return the items from the current theme. Its metatable ensures that the drawing functions of existing items can be recovered though, as long as their name is known. The example below shows how to modify the ''unit_status'' item to display a custom status:&lt;br /&gt;
&lt;br /&gt;
 local old_unit_status = wesnoth.theme_items.unit_status&lt;br /&gt;
 function wesnoth.theme_items.unit_status()&lt;br /&gt;
     local u = wesnoth.get_displayed_unit()&lt;br /&gt;
     if not u then return {} end&lt;br /&gt;
         local s = old_unit_status()&lt;br /&gt;
         if u.status.entangled then&lt;br /&gt;
             table.insert(s, { &amp;quot;element&amp;quot;, {&lt;br /&gt;
                 image = &amp;quot;entangled.png&amp;quot;,&lt;br /&gt;
                 tooltip = _&amp;quot;entangled: This unit is entangled. It cannot move but it can still attack.&amp;quot;&lt;br /&gt;
             } })&lt;br /&gt;
         end&lt;br /&gt;
     return s&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following is a list of valid entries in wesnoth.theme_items which will have an effect in the game. Unfortunately when this feature was created the full range of capabilities of the feature was never properly documented. The following list is automatically generated. To find out what each entry will do, you will have to make guesses and experiment, or read the source code at src/reports.cpp. If you find out what an entry does, you are more than welcome to edit the wiki and give a proper description to any of these fields.&lt;br /&gt;
&lt;br /&gt;
* '''unit_name'''&lt;br /&gt;
* '''selected_unit_name'''&lt;br /&gt;
* '''unit_type'''&lt;br /&gt;
* '''selected_unit_type'''&lt;br /&gt;
* '''unit_race'''&lt;br /&gt;
* '''selected_unit_race'''&lt;br /&gt;
* '''unit_side'''&lt;br /&gt;
* '''selected_unit_side'''&lt;br /&gt;
* '''unit_level'''&lt;br /&gt;
* '''selected_unit_level'''&lt;br /&gt;
* '''unit_amla'''&lt;br /&gt;
* '''unit_traits'''&lt;br /&gt;
* '''selected_unit_traits'''&lt;br /&gt;
* '''unit_status'''&lt;br /&gt;
* '''selected_unit_status'''&lt;br /&gt;
* '''unit_alignment'''&lt;br /&gt;
* '''selected_unit_alignment'''&lt;br /&gt;
* '''unit_abilities'''&lt;br /&gt;
* '''selected_unit_abilities'''&lt;br /&gt;
* '''unit_hp'''&lt;br /&gt;
* '''selected_unit_hp'''&lt;br /&gt;
* '''unit_xp'''&lt;br /&gt;
* '''selected_unit_xp'''&lt;br /&gt;
* '''unit_advancement_options'''&lt;br /&gt;
* '''selected_unit_advancement_options'''&lt;br /&gt;
* '''unit_defense'''&lt;br /&gt;
* '''selected_unit_defense'''&lt;br /&gt;
* '''unit_vision'''&lt;br /&gt;
* '''selected_unit_vision'''&lt;br /&gt;
* '''unit_moves'''&lt;br /&gt;
* '''selected_unit_moves'''&lt;br /&gt;
* '''unit_weapons'''&lt;br /&gt;
* '''highlighted_unit_weapons'''&lt;br /&gt;
* '''selected_unit_weapons'''&lt;br /&gt;
* '''unit_image'''&lt;br /&gt;
* '''selected_unit_image'''&lt;br /&gt;
* '''selected_unit_profile'''&lt;br /&gt;
* '''unit_profile'''&lt;br /&gt;
* '''tod_stats'''&lt;br /&gt;
* '''time_of_day'''&lt;br /&gt;
* '''unit_box'''&lt;br /&gt;
* '''turn'''&lt;br /&gt;
* '''gold'''&lt;br /&gt;
* '''villages'''&lt;br /&gt;
* '''num_units'''&lt;br /&gt;
* '''upkeep'''&lt;br /&gt;
* '''expenses'''&lt;br /&gt;
* '''income'''&lt;br /&gt;
* '''terrain_info'''&lt;br /&gt;
* '''terrain'''&lt;br /&gt;
* '''zoom_level'''&lt;br /&gt;
* '''position'''&lt;br /&gt;
* '''side_playing'''&lt;br /&gt;
* '''observers'''&lt;br /&gt;
* '''selected_terrain'''&lt;br /&gt;
* '''edit_left_button_function'''&lt;br /&gt;
* '''report_clock'''&lt;br /&gt;
* '''report_countdown'''&lt;br /&gt;
&lt;br /&gt;
==== helper.get_user_choice ====&lt;br /&gt;
&lt;br /&gt;
Displays a WML message box querying a choice from the user. Attributes and options are taken from given tables (see [[InterfaceActionsWML#.5Bmessage.5D|[message]]]). The index of the selected option is returned.&lt;br /&gt;
&lt;br /&gt;
 local result = helper.get_user_choice({ speaker = &amp;quot;narrator&amp;quot; }, { &amp;quot;Choice 1&amp;quot;, &amp;quot;Choice 2&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Display&amp;diff=55957</id>
		<title>LuaWML/Display</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Display&amp;diff=55957"/>
		<updated>2014-12-05T00:17:17Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* wesnoth.theme_items */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for interfacing with the user.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.message ====&lt;br /&gt;
&lt;br /&gt;
Displays a string in the chat window and dumps it to the lua/info log domain (''--log-info=scripting/lua'' on the command-line).&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The chat line header is &amp;quot;&amp;lt;Lua&amp;gt;&amp;quot; by default, but it can be changed by passing a string before the message.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(&amp;quot;Big Brother&amp;quot;, &amp;quot;I'm watching you.&amp;quot;) -- will result in &amp;quot;&amp;amp;lt;Big Brother&amp;amp;gt; I'm watching you.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
See also [[LuaWML:Events#helper.wml_error|helper.wml_error]] for displaying error messages.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.clear_messages ====&lt;br /&gt;
&lt;br /&gt;
Removes all messages from the chat window. No argument or returned values.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.textdomain ====&lt;br /&gt;
&lt;br /&gt;
Creates a function proxy for lazily translating strings from the given domain.&lt;br /&gt;
&lt;br /&gt;
 -- #textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 -- the comment above ensures the subsequent strings will be extracted to the proper domain&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;my_unit.description&amp;quot;, _ &amp;quot;the unit formerly known as Hero&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The metatable of the function proxy appears as '''&amp;quot;message domain&amp;quot;'''. The metatable of the translatable strings (results of the proxy) appears as '''&amp;quot;translatable string&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
The translatable strings can be appended to other strings/numbers with the standard '''..''' operator. Translation can be forced with the standard '''tostring''' operator in order to get a plain string.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(string.format(tostring(_ &amp;quot;You gain %d gold.&amp;quot;), amount))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.delay ====&lt;br /&gt;
&lt;br /&gt;
Delays the engine like the [delay] tag. one argument: time to delay in milliseconds&lt;br /&gt;
&lt;br /&gt;
 wesnoth.delay(500)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.float_label ====&lt;br /&gt;
&lt;br /&gt;
Pops some text above a map tile.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.float_label(unit.x, unit.y, &amp;quot;&amp;amp;lt;span color='#ff0000'&amp;amp;gt;Ouch&amp;amp;lt;/span&amp;amp;gt;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_of_day ====&lt;br /&gt;
&lt;br /&gt;
Returns schedule information. First parameter (optional) is the turn number for which to return the information, if unspecified: the current turn ($turn_number). Second argument is an optional table. If present, first and second fields must be valid on-map coordinates and all current time_areas in the scenario are taken into account (if a time area happens to contain the passed hex). If the table isn't present, the scenario main schedule is returned. The table has an optional third parameter (boolean). If true (default: false), time of day modifying units and terrain (such as Mages of Light or lava) are taken into account (if the passed hex happens to be affected). The units' placement being considered is always the current one.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.get_time_of_day(2, { 37, 3, true })&lt;br /&gt;
&lt;br /&gt;
The function returns a table with these named fields:&lt;br /&gt;
* '''id''': string (as in [time])&lt;br /&gt;
* '''lawful_bonus''': integer (as in [time])&lt;br /&gt;
* '''bonus_modified''': integer (bonus change by units)&lt;br /&gt;
* '''image''': string (tod image in sidebar)&lt;br /&gt;
* '''name''': translatable string&lt;br /&gt;
* '''red, green, blue''': integers (color adjustment for this time)&lt;br /&gt;
&lt;br /&gt;
The optional first parameter does not work if there is no turn limit in 1.11.0 and earlier.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.select_hex ====&lt;br /&gt;
&lt;br /&gt;
Selects the given location in the game map as if the player would have clicked onto it.&lt;br /&gt;
Argument 3: boolean, whether to show the movement range of any unit on that location (def: true)&lt;br /&gt;
Argument 4: boolean, whether to fire any select events (def: false)&lt;br /&gt;
&lt;br /&gt;
 wesnoth.select_hex(14,6, true, true)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.scroll_to_tile ====&lt;br /&gt;
&lt;br /&gt;
Scrolls the map to the given location. If true is passed as the third parameter, scrolling is disabled if the tile is hidden under the fog. If true is passed as the fourth parameter {{DevFeature1.11}}, the view instantly warps to the location regardless of the scroll speed setting in Preferences.&lt;br /&gt;
&lt;br /&gt;
 local u = wesnoth.get_units({ id = &amp;quot;hero&amp;quot; })[1]&lt;br /&gt;
 wesnoth.scroll_to_tile(u.x, u.y)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.lock_view ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} Locks or unlocks gamemap view scrolling for human players. If true is passed as the first parameter, the view is locked; pass false to unlock.&lt;br /&gt;
&lt;br /&gt;
Human players cannot scroll the gamemap view as long as it is locked, but Lua or WML actions such as wesnoth.scroll_to_tile still can; the locked/unlocked state is preserved when saving the current game. This feature is generally intended to be used in cutscenes to prevent the player scrolling away from scripted actions.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.lock_view(true)&lt;br /&gt;
 wesnoth.scroll_to_tile(12, 14, false, true)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.view_locked ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}} Returns a boolean indicating whether gamemap view scrolling is currently locked.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.play_sound ====&lt;br /&gt;
&lt;br /&gt;
Plays the given sound file once, optionally repeating it one or more more times if an integer value is provided as a second argument (note that the sound is ''repeated'' the number of times specified in the second argument, i.e. a second argument of 4 will cause the sound to be played once and then repeated four more times for a total of 5 plays. See the example below).&lt;br /&gt;
&lt;br /&gt;
 wesnoth.play_sound &amp;quot;ambient/birds1.ogg&amp;quot;&lt;br /&gt;
 wesnoth.play_sound(&amp;quot;magic-holy-miss-3.ogg&amp;quot;, 4) -- played 1 + 4 = 5 times&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_music ====&lt;br /&gt;
&lt;br /&gt;
Sets the given table as an entry into the music list. See [[MusicListWML]] for the recognized attributes.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_music { name = &amp;quot;traveling_minstrels.ogg&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
Passing no argument forces the engine to take into account all the recent changes to the music list. (Note: this is done automatically when sequences of WML commands end, so it is useful only for long events.)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.show_dialog ====&lt;br /&gt;
&lt;br /&gt;
Displays a dialog box described by a WML table and returns:&lt;br /&gt;
* if the dialog was dismissed by a button click, the integer value associated to the button via the &amp;quot;return_value&amp;quot; keyword.&lt;br /&gt;
* if the dialog was closed with the enter key, -1.&lt;br /&gt;
* if the dialog was closed with the escape key, -2.&lt;br /&gt;
&lt;br /&gt;
The dialog box is equivalent to the resolution section of a GUI window as described in [[GUIToolkitWML#Window_definition|GUIToolkitWML]] and must therefore contain at least the following children: '''[tooltip]''', '''[helptip]''', and '''[grid]'''. The [grid] must contain nested [row], [column] and [grid] tags which describe the layout of the window. (More information can be found in [[GUILayout]]; suffice to say that the basic structure is grid -&amp;gt; row -&amp;gt; column -&amp;gt; widget, where the widget is considered to be in a cell defined by the row and column of the grid. A list of widgets can be found at [[GUIWidgetInstanceWML]].)&lt;br /&gt;
&lt;br /&gt;
Two optional functions can be passed as second and third arguments; the first one is called once the dialog is created and before it is shown; the second one is called once the dialog is closed. These functions are helpful in setting the initial values of the fields and in recovering the final user values. These functions can call the [[#wesnoth.set_dialog_value]], [[#wesnoth.get_dialog_value]], and [[#wesnoth.set_dialog_callback]] functions for this purpose.&lt;br /&gt;
&lt;br /&gt;
This function should be called in conjunction with [[LuaWML:Misc#wesnoth.synchronize_choice|#wesnoth.synchronize_choice]], in order to ensure that only one client displays the dialog and that the other ones recover the same input values from this single client.&lt;br /&gt;
&lt;br /&gt;
The example below defines a dialog with a list and two buttons on the left, and a big image on the right. The ''preshow'' function fills the list and defines a callback on it. This ''select'' callback changes the displayed image whenever a new list item is selected. The ''postshow'' function recovers the selected item before the dialog is destroyed.&lt;br /&gt;
&lt;br /&gt;
 local helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
 local T = helper.set_wml_tag_metatable {}&lt;br /&gt;
 local _ = wesnoth.textdomain &amp;quot;wesnoth&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 local dialog = {&lt;br /&gt;
   T.tooltip { id = &amp;quot;tooltip_large&amp;quot; },&lt;br /&gt;
   T.helptip { id = &amp;quot;tooltip_large&amp;quot; },&lt;br /&gt;
   T.grid { T.row {&lt;br /&gt;
     T.column { T.grid {&lt;br /&gt;
       T.row { T.column { horizontal_grow = true, T.listbox { id = &amp;quot;the_list&amp;quot;,&lt;br /&gt;
         T.list_definition { T.row { T.column { horizontal_grow = true,&lt;br /&gt;
           T.toggle_panel { T.grid { T.row {&lt;br /&gt;
             T.column { horizontal_alignment = &amp;quot;left&amp;quot;, T.label { id = &amp;quot;the_label&amp;quot; } },&lt;br /&gt;
             T.column { T.image { id = &amp;quot;the_icon&amp;quot; } }&lt;br /&gt;
           } } }&lt;br /&gt;
         } } }&lt;br /&gt;
       } } },&lt;br /&gt;
       T.row { T.column { T.grid { T.row {&lt;br /&gt;
         T.column { T.button { id = &amp;quot;ok&amp;quot;, label = _&amp;quot;OK&amp;quot; } },&lt;br /&gt;
         T.column { T.button { id = &amp;quot;cancel&amp;quot;, label = _&amp;quot;Cancel&amp;quot; } }&lt;br /&gt;
       } } } }&lt;br /&gt;
     } },&lt;br /&gt;
     T.column { T.image { id = &amp;quot;the_image&amp;quot; } }&lt;br /&gt;
   } }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 local function preshow()&lt;br /&gt;
     local t = { &amp;quot;Ancient Lich&amp;quot;, &amp;quot;Ancient Wose&amp;quot;, &amp;quot;Elvish Avenger&amp;quot; }&lt;br /&gt;
     local function select()&lt;br /&gt;
         local i = wesnoth.get_dialog_value &amp;quot;the_list&amp;quot;&lt;br /&gt;
         local ut = wesnoth.unit_types[t[i]].__cfg&lt;br /&gt;
         wesnoth.set_dialog_value(string.gsub(ut.profile, &amp;quot;([^/]+)$&amp;quot;, &amp;quot;transparent/%1&amp;quot;), &amp;quot;the_image&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
     wesnoth.set_dialog_callback(select, &amp;quot;the_list&amp;quot;)&lt;br /&gt;
     for i,v in ipairs(t) do&lt;br /&gt;
         local ut = wesnoth.unit_types[v].__cfg&lt;br /&gt;
         wesnoth.set_dialog_value(ut.name, &amp;quot;the_list&amp;quot;, i, &amp;quot;the_label&amp;quot;)&lt;br /&gt;
         wesnoth.set_dialog_value(ut.image, &amp;quot;the_list&amp;quot;, i, &amp;quot;the_icon&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
     wesnoth.set_dialog_value(2, &amp;quot;the_list&amp;quot;)&lt;br /&gt;
     select()&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local li = 0&lt;br /&gt;
 local function postshow()&lt;br /&gt;
     li = wesnoth.get_dialog_value &amp;quot;the_list&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local r = wesnoth.show_dialog(dialog, preshow, postshow)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Button %d pressed. Item %d selected.&amp;quot;, r, li))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_value ====&lt;br /&gt;
&lt;br /&gt;
Sets the value of a widget on the current dialog. The value is given by the first argument; its semantic depends on the type of widget it is applied to. The last argument is the ''id'' of the widget. If it does not point to a unique widget in the dialog, some discriminating parents should be given on its left, making a path that is read from left to right by the engine. The row of a list is specified by giving the ''id' of the list as a first argument and the 1-based row number as the next argument.&lt;br /&gt;
&lt;br /&gt;
 -- sets the value of a widget &amp;quot;bar&amp;quot; in the 7th row of the list &amp;quot;foo&amp;quot;&lt;br /&gt;
 wesnoth.set_value(_&amp;quot;Hello world&amp;quot;, &amp;quot;foo&amp;quot;, 7, &amp;quot;bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Notes: When the row of a list does not exist, it is created. The value associated to a list is the selected row.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_dialog_value ====&lt;br /&gt;
&lt;br /&gt;
Gets the value of a widget on the current dialog. The arguments described the path for reaching the widget (see [[#wesnoth.set_dialog_value]]).&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_active ====&lt;br /&gt;
&lt;br /&gt;
Enables or disables a widget.  The first argument is a boolean specifying whether the widget should be active (true) or inactive (false).  The remaining arguments are the path to locate the widget in question (see [[#wesnoth.set_dialog_value]]).&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_callback ====&lt;br /&gt;
&lt;br /&gt;
Sets the first argument as a callback function for the widget obtained by following the path of the other arguments (see [[#wesnoth.set_dialog_value]]). This function will be called whenever the user modifies something about the widget, so that the dialog can react to it.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_markup ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11|9}}&lt;br /&gt;
&lt;br /&gt;
Sets the flag associated to a widget to enable or disable Pango markup. The new flag value is passed as the first argument (boolean), and the widget to modify is obtained by following the path of the other arguments (see [[#wesnoth.set_dialog_value]]). Most widgets start with Pango markup disabled unless this function is used to set their flag to true.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_dialog_markup(true, &amp;quot;notice_label&amp;quot;)&lt;br /&gt;
 wesnoth.set_dialog_value(&amp;quot;&amp;amp;lt;big&amp;amp;gt;NOTICE!&amp;amp;lt;/big&amp;amp;gt;&amp;quot;, &amp;quot;notice_label&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_dialog_canvas ====&lt;br /&gt;
&lt;br /&gt;
Sets the WML passed as the second argument as the canvas content (index given by the first argument) of the widget obtained by following the path of the other arguments (see [[#wesnoth.set_dialog_value]]). The content of the WML table is described at [[GUICanvasWML]].&lt;br /&gt;
&lt;br /&gt;
 -- draw two rectangles in the upper-left corner of the window (empty path = window widget)&lt;br /&gt;
 wesnoth.set_dialog_canvas(2, {&lt;br /&gt;
     T.rectangle { x = 20, y = 20, w = 20, h = 20, fill_color= &amp;quot;0,0,255,255&amp;quot; },&lt;br /&gt;
     T.rectangle { x = 30, y = 30, w = 20, h = 20, fill_color = &amp;quot;255,0,0,255&amp;quot; }&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
The meaning of the canvas index depends on the chosen widget. It may be the disabled / enabled states of the widget, or its background / foreground planes, or... For instance, overwriting canvas 1 of the window with an empty canvas causes the window to become transparent.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_displayed_unit ====&lt;br /&gt;
&lt;br /&gt;
Returns a proxy to the unit currently displayed in the side pane of the user interface, if any.&lt;br /&gt;
&lt;br /&gt;
 local name = tostring(wesnoth.get_displayed_unit().name)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.theme_items ====&lt;br /&gt;
&lt;br /&gt;
This field is not a function but an associative table. It links item names to the functions that describe their content. These functions are called whenever the user interface is refreshed. The description of an item is a WML table containing '''[element]''' children. Each subtag shall contain either a '''text''' or an '''image''' field that is displayed to the user. It can also contain a '''tooltip''' field that is displayed to the user when moused over, and a &amp;quot;help&amp;quot; field that points to the help section that is displayed when the user clicks on the theme item.&lt;br /&gt;
&lt;br /&gt;
Note that the ''wesnoth.theme_items'' table is originally empty and using ''pairs'' or ''next'' on it will not return the items from the current theme. Its metatable ensures that the drawing functions of existing items can be recovered though, as long as their name is known. The example below shows how to modify the ''unit_status'' item to display a custom status:&lt;br /&gt;
&lt;br /&gt;
 local old_unit_status = wesnoth.theme_items.unit_status&lt;br /&gt;
 function wesnoth.theme_items.unit_status()&lt;br /&gt;
     local u = wesnoth.get_displayed_unit()&lt;br /&gt;
     if not u then return {} end&lt;br /&gt;
         local s = old_unit_status()&lt;br /&gt;
         if u.status.entangled then&lt;br /&gt;
             table.insert(s, { &amp;quot;element&amp;quot;, {&lt;br /&gt;
                 image = &amp;quot;entangled.png&amp;quot;,&lt;br /&gt;
                 tooltip = _&amp;quot;entangled: This unit is entangled. It cannot move but it can still attack.&amp;quot;&lt;br /&gt;
             } })&lt;br /&gt;
         end&lt;br /&gt;
     return s&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following is a list of valid entries in wesnoth.theme_items which will have an effect in the game. Unfortunately when this feature was created the full range of capabilities of the feature was never properly documented. The following list is automatically generated. To find out what each entry will do, you will have to make guesses and experiment, or read the source code at src/reports.cpp&lt;br /&gt;
&lt;br /&gt;
* '''unit_name'''&lt;br /&gt;
* '''selected_unit_name'''&lt;br /&gt;
* '''unit_type'''&lt;br /&gt;
* '''selected_unit_type'''&lt;br /&gt;
* '''unit_race'''&lt;br /&gt;
* '''selected_unit_race'''&lt;br /&gt;
* '''unit_side'''&lt;br /&gt;
* '''selected_unit_side'''&lt;br /&gt;
* '''unit_level'''&lt;br /&gt;
* '''selected_unit_level'''&lt;br /&gt;
* '''unit_amla'''&lt;br /&gt;
* '''unit_traits'''&lt;br /&gt;
* '''selected_unit_traits'''&lt;br /&gt;
* '''unit_status'''&lt;br /&gt;
* '''selected_unit_status'''&lt;br /&gt;
* '''unit_alignment'''&lt;br /&gt;
* '''selected_unit_alignment'''&lt;br /&gt;
* '''unit_abilities'''&lt;br /&gt;
* '''selected_unit_abilities'''&lt;br /&gt;
* '''unit_hp'''&lt;br /&gt;
* '''selected_unit_hp'''&lt;br /&gt;
* '''unit_xp'''&lt;br /&gt;
* '''selected_unit_xp'''&lt;br /&gt;
* '''unit_advancement_options'''&lt;br /&gt;
* '''selected_unit_advancement_options'''&lt;br /&gt;
* '''unit_defense'''&lt;br /&gt;
* '''selected_unit_defense'''&lt;br /&gt;
* '''unit_vision'''&lt;br /&gt;
* '''selected_unit_vision'''&lt;br /&gt;
* '''unit_moves'''&lt;br /&gt;
* '''selected_unit_moves'''&lt;br /&gt;
* '''unit_weapons'''&lt;br /&gt;
* '''highlighted_unit_weapons'''&lt;br /&gt;
* '''selected_unit_weapons'''&lt;br /&gt;
* '''unit_image'''&lt;br /&gt;
* '''selected_unit_image'''&lt;br /&gt;
* '''selected_unit_profile'''&lt;br /&gt;
* '''unit_profile'''&lt;br /&gt;
* '''tod_stats'''&lt;br /&gt;
* '''time_of_day'''&lt;br /&gt;
* '''unit_box'''&lt;br /&gt;
* '''turn'''&lt;br /&gt;
* '''gold'''&lt;br /&gt;
* '''villages'''&lt;br /&gt;
* '''num_units'''&lt;br /&gt;
* '''upkeep'''&lt;br /&gt;
* '''expenses'''&lt;br /&gt;
* '''income'''&lt;br /&gt;
* '''terrain_info'''&lt;br /&gt;
* '''terrain'''&lt;br /&gt;
* '''zoom_level'''&lt;br /&gt;
* '''position'''&lt;br /&gt;
* '''side_playing'''&lt;br /&gt;
* '''observers'''&lt;br /&gt;
* '''selected_terrain'''&lt;br /&gt;
* '''edit_left_button_function'''&lt;br /&gt;
* '''report_clock'''&lt;br /&gt;
* '''report_countdown'''&lt;br /&gt;
&lt;br /&gt;
==== helper.get_user_choice ====&lt;br /&gt;
&lt;br /&gt;
Displays a WML message box querying a choice from the user. Attributes and options are taken from given tables (see [[InterfaceActionsWML#.5Bmessage.5D|[message]]]). The index of the selected option is returned.&lt;br /&gt;
&lt;br /&gt;
 local result = helper.get_user_choice({ speaker = &amp;quot;narrator&amp;quot; }, { &amp;quot;Choice 1&amp;quot;, &amp;quot;Choice 2&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55944</id>
		<title>NotSoEasyCoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=NotSoEasyCoding&amp;diff=55944"/>
		<updated>2014-12-02T00:31:07Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: remove stuff about random map generation, since the lua map generation is finished now&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Foreword ==&lt;br /&gt;
This page shows projects which are considered a good idea by the developers but which have nobody working on them so far. If you think you've got the required skill for a task go on, implement it and you've got a high chance that it'll be accepted. The remaining barrier will only be that it's done well. :-)&lt;br /&gt;
&lt;br /&gt;
If you are such a person, you should feel free to edit this page.&lt;br /&gt;
&lt;br /&gt;
If you're not, you should post a feature request and discuss your idea on the forum or IRC. A coder with better knowledge of the code might give you the green light to add your feature here.&lt;br /&gt;
&lt;br /&gt;
Anybody should feel free to add &amp;quot;clues&amp;quot; to any tasks, that is entry points, traps to avoid, person to contact to discuss and so on.&lt;br /&gt;
&lt;br /&gt;
If you plan to work on a feature, write your name at the bottom of the feature, with the date. Note that if you are too long at working on a feature I'll &amp;quot;free&amp;quot; it back (that is if you're not working on it. If you have problems implementing it, just tell us....)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Game Engine ==&lt;br /&gt;
=== add a mode to improve OOS detection in MP ===&lt;br /&gt;
We really need an optional 'pedantic mode' for MP which detects OOSes immediately, by comparing all game state information after each action and printing any mismatches. This mode will be optional because of the extra overhead it adds, and it would be very useful for debugging.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Fix a longstanding bug concerning failure to initialize a side in networked mp&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
(Actually we may have a fix for this now... will post reference)&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/index.php?21397&lt;br /&gt;
&lt;br /&gt;
The problem itself is quite simple -- when the server tells a client that their turn has begun, the client immediately broadcasts [init_side] to all the other players via the server, performing the initial upkeep, healing, and movement point reset actions. However, if this player disconnects / blocks the action by opening a dialog during the prior turn and never closing it, [init_side] is never broadcast. And if the game is then saved by one of the other clients, nothing in the current mechanism detects that this has been overlooked when the game is reloaded. The consequence is that in the reloaded game, that side's turn is *never* initialized -- they get no gold, their units don't heal, and they don't get full move points at the start of the turn.&lt;br /&gt;
&lt;br /&gt;
Propose a mechanism to fix this -- perhaps games which have been loaded should be scanned to see if the current turn failed to initialize. Perhaps a flag in game_state could be used and saved. Perhaps a completely different approach. Check that your mechanism works whether the save is loaded from [snapshot] or [replay_start] and [replay].&lt;br /&gt;
&lt;br /&gt;
This bug has existed since at least Wesnoth 1.8&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;s&amp;gt;Make a &amp;quot;replay actions since my last turn&amp;quot; button&amp;lt;/s&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
It would be very convenient if there an ability to replay everything your opponents just did at the &lt;br /&gt;
start of your turn, since sometimes things go out of vision or are confusing. &lt;br /&gt;
&lt;br /&gt;
The feature would be like a &amp;quot;replay since my last turn&amp;quot; menu option or button -- most likely, the best approach to implement it is to store a copy of the game_state object in playcontroller.cpp or even in resources, and to refactor the backlog object so that we can hold a &amp;quot;bookmark&amp;quot;, i.e. a pointer, to the last position in the replay that we might look to jump back to. The replay process would work by swapping out for the old gamestate, then replaying through the actions since the bookmark until we get back up to speed. The difficult part would be making sure that scenarios with scripted WML events don't break when we do this. For debugging purposes, it might be good to check that at this point we have the same gamestate we did before we clicked the button. The bookmark should only be advanced when we end our turn, and there might be perhaps need to be multiple bookmarks, one for each side, to handle what happens when a side disconnects or is reassigned.&lt;br /&gt;
&lt;br /&gt;
It would be especially helpful for MP play to have this, where special tactics with ambush units are quite common. Part of the design criteria of wesnoth is that it should be a high-level, thoughtful turn based strategy game, but you should be able to play asynchronously and not necessarily give attention to the game until your turn bell rings if you don't want to. Having ambush units and no ability to replay their movements during the opponents turn harms that goal.&lt;br /&gt;
&lt;br /&gt;
For MP play, it will require special attention to make sure that events like &amp;quot;synchronize_choice&amp;quot; are handled correctly so as not to cause out of sync errors, and also that the timer is handled correctly.&lt;br /&gt;
&lt;br /&gt;
Feature request: https://gna.org/bugs/?15334&lt;br /&gt;
&lt;br /&gt;
Thanks to Zappaman for this. https://github.com/wesnoth/wesnoth/pull/270&lt;br /&gt;
&lt;br /&gt;
=== Improve WML error reporting ===&lt;br /&gt;
&lt;br /&gt;
There are many programming bugs that give very unclear or cryptic error messages when using WML. Here are some examples:&lt;br /&gt;
&lt;br /&gt;
-- When calling a macro with the wrong number of arguments, wesnoth tells the number it expected, and the number it got, and at which line number it was instantiated. However, it would be helpful if it would also tell the line number of the definition of the macro. This might be helpful if someone is redefining macros.&lt;br /&gt;
&lt;br /&gt;
-- For places where a standard unit filter is expected, if one is not found, the game should point out a problem. For places where such a filter is expected but [filter] child should not appear, if one does it should report an error and a line number. Many users have a hard time with this kind of thing.&lt;br /&gt;
&lt;br /&gt;
-- When doing scenario transitions in a campaign, if the side definitions don't matchup exactly the game tends to give unintelligible error messages. For instance, if one is transitioning and there is an AI side which does not have a leader (but it has a starting location in the map) it must have &amp;quot;no_leader = yes&amp;quot; in its [side] tag, or else when the team_builder objects enter stage two, the game will try to create a unit with an empty type, and the constructor of class unit will fail giving the error message &amp;quot;game::game_error tried to create unit with empty type&amp;quot;. This really needs to be much better. For instance, giving a line number of a problem, or suggesting that no_leader should be used. (Note that, it is often possible to debug problems like this by turning on --log-debug=team_construction at commandline but I doubt that there are any users that know about this, you would only learn from reading the C++... without such debug info, fixing things like this can literally take hours.) For that matter it's some question why the team_builder doesn't just stop trying to build a unit when it sees it doesn't have enough info...&lt;br /&gt;
&lt;br /&gt;
-- Recursive macros break the game, and not by stack overflow but by exhausting the heap. It would be nice if we could catch this and report an error.&lt;br /&gt;
&lt;br /&gt;
Many of the users of WML are students or beginners to programming, it is a big help to them to improve the error reporting of this nature -- not to mention that many veterans would appreciate as well. In part we need fixits here and there but more broadly we need a smarter system that can figure out what's really wrong when things go wrong and give helpful suggestions.&lt;br /&gt;
&lt;br /&gt;
=== Map label &amp;quot;groups&amp;quot; which can be selectively turned on and off by the user ===&lt;br /&gt;
&lt;br /&gt;
It would be nice if the user could have more control over how map labels are displayed, for instance to be able to check on / off labels made by certain players, and for custom scenarios, to be able to make custom classes which the use can turn on or off. This might be helpful for custom scenarios esp. which might have some technical info they want to show, but which it might be messy to display all of the time. The hard part of this is that there should ideally be a gui to work with the map labels, although maybe this need could be worked around or simplified somehow.&lt;br /&gt;
&lt;br /&gt;
=== Add a new damage stats calculation mode to support scenarios with extremely high stats ===&lt;br /&gt;
&lt;br /&gt;
Most players use the damage calculation window constantly when they play so that they can see what to expect from various attacks. The way the game is currently set up, when a unit is selected, as soon as another unit is moused over the stats for an attack will be calculated, whether or not the user actually brings up the window.&lt;br /&gt;
&lt;br /&gt;
The probabilities for the various outcomes are calculated by explicitly calculating the distribution of attacker and defender hp / slowed status after each swing by either party, one swing at a time. Thus at the end we get exact probabilities of the possible outcomes.&lt;br /&gt;
&lt;br /&gt;
However, this comes at a cost -- the running time of the calculation can in the worst case be something like O( attacker_hp * defender_hp * total_number_of_strikes). In default era wesnoth (and in much of UMC) this is fine because units don't get extremely high hp values. However in some UMC units do get extremely high hp, and many will also have specials like drain and berzerk, and may have many different weapons as well. At some point these scenarios become unplayable even on a machine of moderate specs because mousing over any unit causes &amp;gt; 10 seconds of lag during which the game becomes unresponsive, trying to calculate attack outcomes.&lt;br /&gt;
&lt;br /&gt;
In these cases, it would be better to give an &amp;quot;inexact&amp;quot; damage prediction, based on just simulating a few thousand attacks and plotting the results. Since it's a monte carlo algorithm rather than an exact algorithm, there will be some error, but if it makes the game playable then it's clearly an improvement, and anyways for &amp;quot;extreme stats&amp;quot; battles with high strikes and damage, the outcome is in a sense less random anyways because the outcomes with inordinate amounts of hits and misses are more and more rare (law of large numbers), so the error shouldn't actually be terribly significant.&lt;br /&gt;
&lt;br /&gt;
If there were an advanced preference that caused the predictions to use such an algorithm instead of the current one, so that the user could turn it on if they start to get problems, it would eliminate a significant headache for some UMC.&lt;br /&gt;
&lt;br /&gt;
== MP Related ==&lt;br /&gt;
&lt;br /&gt;
=== Automatically resolve add-on dependencies ===&lt;br /&gt;
&lt;br /&gt;
In 1.11 add-ons may declare dependencies. A related easy coding task is to allow the user to force breaking dependencies.&lt;br /&gt;
&lt;br /&gt;
A related goal which would be greatly beneficial would be that wesnoth can automatically resolve the dependencies by fetching the add-ons from the download server, when in the MP-lobby the user tries to join a game with a dependency they don't meet. A dialog would ideally be provided as well, or perhaps a preference.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?21705&lt;br /&gt;
&lt;br /&gt;
Even older: https://gna.org/bugs/?9683&lt;br /&gt;
&lt;br /&gt;
=== Gold graph ===&lt;br /&gt;
&lt;br /&gt;
Make a graph feature, presumably in a dialog, that helps depict the history of the game. For example it could display army value, army + bank value, number of villages tagged, luck swings... the purpose would be to assist spectators of a live game / spectators of a replay to understand the history of the game. It would be particularly helpful with AI development, by helping AI developers to identify key points where one of the AI is making a big mistake. &lt;br /&gt;
&lt;br /&gt;
A possible nice feature for this purpose would be to allow the user to click on the graph at key points which would trigger the &amp;quot;back to turn&amp;quot; mechanism to jump back in the replay, or automatically play the replay forwards from the beginning to that point... etc.&lt;br /&gt;
&lt;br /&gt;
Related email on dev-talk: https://mail.gna.org/public/wesnoth-dev/2014-02/msg00089.html&lt;br /&gt;
&lt;br /&gt;
=== Automatically link up to wesnothd server on a local network ===&lt;br /&gt;
&lt;br /&gt;
The feature request was to use ZeroConf technology, if available, to publish info of a running wesnothd instance to other machines on a local network. Then when they are searching to connect to an unofficial server, they won't have to learn the IP address.&lt;br /&gt;
&lt;br /&gt;
The extra code should be guarded with preprocessor flags so that ZeroConf does not become a build dependency of wesnoth.&lt;br /&gt;
&lt;br /&gt;
https://gna.org/bugs/?13703&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a set of &amp;quot;common&amp;quot; mp messages which players can use when they don't share a language ===&lt;br /&gt;
&lt;br /&gt;
Most users speak english, however, wesnoth also has large Polish and Hungarian communities, and many Brazilian players, not all of whom speak english. It would be nice we could have a set of messages that could be chatted, but which will be translated by our translators and displayed always in the current locale on each client, to make it easier to communicate in mp games / on the mp server.&lt;br /&gt;
&lt;br /&gt;
The hard part is that if you don't already know about the gettext translation system, you will have to learn about it. The messages should be stored in a .cfg file in the data folder so that they can be easily modified and can be handled in the same way that other in-game text is translated -- they should perhaps go in their own gettext-domain however. Ideally there would be a gui dialog of some kind to select from them.&lt;br /&gt;
&lt;br /&gt;
=== Improve server wml processing ===&lt;br /&gt;
&lt;br /&gt;
The wesver uses an alternative implementation to store and process wml objects see http://wiki.wesnoth.org/WesnothdDesign#simple_wml. This is for performance. However, the simple_wml sometimes messes up translation for mp scenarios / campaigns, resulting in mp scenarios/campaigns beeing untranslated for non-hosts in networked mp (http://gna.org/bugs/?22989). Fixing this is not easy becasue of the performance requirements.&lt;br /&gt;
&lt;br /&gt;
== Improvements to AI ==&lt;br /&gt;
=== Move and targeting phase ===&lt;br /&gt;
AI needs to move units which are not within range of the enemy. This is generally a sequence of moves (some interesting things like 'ambush!' or 'WML event' might happen as a result of those moves, which should interrupt this phase). The problem is that simply doing those moves 1-by-1 is very slow, for two reasons:&lt;br /&gt;
&lt;br /&gt;
#movement maps are invalidated after each move, and are recalculated from the start. yet, if we are doing just a sequence of moves, we can just 'remove moved unit from moves' after each move and avoid expensive recalculation of the movement map.&lt;br /&gt;
#* Note that WML could mess with the game state at any time, so at the very least, movement will need to be recalculated after a WML event blocks undo (that is, indicates that it changed game state). --[[User:Brilliand|Brilliand]] 01:30, 28 May 2012 (UTC)&lt;br /&gt;
#most tasks need devoting more than one unit to execute (i.e., it's meaningless to go for the enemy position with just 1 unit). So, making individual decisions just does some repeating calculations, which is slow.&lt;br /&gt;
&lt;br /&gt;
A practical demonstration of these concerns are LoW 2 (dwarf ai is slow due to large avoid aspect) and NR:Showdown (orc AIs there are slow because of huge number of units)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we need a fast and effective 'move and targeting stage' - both ideas and implementations are wanted.&lt;br /&gt;
Here's Sirp's idea (more in 2009-aug-15 irclog):&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Eval-based AI ===&lt;br /&gt;
The AI system would be based around an 'eval' function -- a formula which is given a position, and returns a number saying how attractive that position is.&lt;br /&gt;
&lt;br /&gt;
There would also be a 'candidate_moves' function -- a formula which is given a unit and returns a list of 'candidate moves' -- i.e. moves for that unit that the AI should consider making.&lt;br /&gt;
&lt;br /&gt;
The aim of the system is to come up with the combination of candidate moves that gives the best possible evaluation. By doing this, the AI will work in a team, since the 'eval' function can give bonuses for units being close together, protecting each other, etc.&lt;br /&gt;
&lt;br /&gt;
There are likely to be, of course, a very large combination of possible moves, and not every one can possibly be evaluated. Instead, we take a monte carlo approach.&lt;br /&gt;
&lt;br /&gt;
If an AI has N units that it can move, that is an N-dimension matrix of possible moves. We would choose some cells in this matrix at random and then evaluate them. Then, of these cells evaluated we would choose cells that evaluated well, and discard those that did not evaluate well. Then, we would begin with those cells that evaluated well, and choose a scattering of 'close by' cells -- i.e. cells where we only vary some of the dimensions, at random. We would continue to evaluate cells at random, starting with those cells that evaluated well, and evaluating cells nearby. After several iterations, we would hope to arrive at a cell that evaluates very well, and we would use this as our set of moves.&lt;br /&gt;
&lt;br /&gt;
Of course, this system will be made more complex by the uncertainty of attacks. There are a number of ways to handle attacks, probably the easiest being to consider attacks as types of moves, and then if a move combination involving an attack is chosen, perform the attack and then re-run the entire AI algorithm before moving again. (Something similar to what the current AI does).&lt;br /&gt;
&lt;br /&gt;
This is effectively an AI framework, not an AI in itself. How well it performs will correlate strongly with how good an eval() function one can write, and is also based on the notion that generally certain combinations of moves are 'similar' to other combinations.&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
=== Village grabbing ===&lt;br /&gt;
&lt;br /&gt;
Improve AI village grabbing algorithm to assign villages that are farther than one turn from current unit location.&lt;br /&gt;
Idea how to do would be value villages so that it can filter out villages that belongs to enemies/allies sides.  Those villages are stored in memory and used in 2nd pass that determines how AI should dispatch units to get villages if it should at all in this turn. This should be close to optimal solution with currently available units but performance limits should be taken into account.&lt;br /&gt;
Good solution would be that village grabbing value could be calculated with attack ratings and if some village has high value it would make unit go for that village instead &lt;br /&gt;
&lt;br /&gt;
This should help AI in begin of scenario. Currently AI might not grab all of villages that belong to its area which results quite large incoming loses.&lt;br /&gt;
In later game enemy might have large number of units in one part of map so village grabbing should be avoided in that are. Single unit would be easy pray for enemy so moving there would result just to loses.&lt;br /&gt;
&lt;br /&gt;
== Data Structures ==&lt;br /&gt;
=== Config Writer ===&lt;br /&gt;
&lt;br /&gt;
The speed of saving Wesnoth games is dominated by the time to marshall all the config structures.  This involves deep copying them many times as each subsystem returns its config bundle; far better would be to have a &amp;quot;config_writer&amp;quot; class which is handed to each subsystem which iterates through its structures and does the writing (to file or network) directly to the config_writer instance.&lt;br /&gt;
&lt;br /&gt;
Stop by #wesnoth-dev on freenode irc if you want to help with this, or post in the Coder's Corner.&lt;br /&gt;
&lt;br /&gt;
=== Config memory optimisation ===&lt;br /&gt;
&lt;br /&gt;
Right now, most of the memory used by wesnoth when using '''low_memory''' configuration flag is used by the config object trees. It would be possible to drop unused &amp;quot;branches&amp;quot; of that trees by using boost smart pointers in the config structure&lt;br /&gt;
&lt;br /&gt;
come and discuss that change on #wesnoth-dev. Sirp is the one that knows the most about that...&lt;br /&gt;
&lt;br /&gt;
=== Improvements to Unit Map ===&lt;br /&gt;
&lt;br /&gt;
As described here: [http://www.wesnoth.org/forum/viewtopic.php?p=236063#236063] (cjhopman has submitted a patch on that already)&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
=== Frequently Proposed Good Ideas ===&lt;br /&gt;
&lt;br /&gt;
Check the [http://www.wesnoth.org/forum/viewtopic.php?f=12&amp;amp;t=9054&amp;amp;start=0&amp;amp;st=0&amp;amp;sk=t&amp;amp;sd=a B.W.H. list] in the Ideas Forum. Be aware that some entries there are old and have already been implemented, so you will need to investigate that before beginning work.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Future]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Download&amp;diff=55843</id>
		<title>Download</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Download&amp;diff=55843"/>
		<updated>2014-11-09T21:09:38Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Download/Translations}}&lt;br /&gt;
Welcome to the ''Battle for Wesnoth'' downloads page. The BfW project team officially releases the source code and builds for Windows, OS X, OpenPandora, and various Linux distros. Torrents are unofficial.&lt;br /&gt;
&lt;br /&gt;
If the latest binaries are not currently available for your OS, please check back in a few days to see if they have been placed here. Packagers have been informed of the release, please be patient.  In the meantime, read the [[FAQ#A_new_version_is_out.2C_but_where_is_the_download_for_.5BWindows.2C_Mac_OS_X.2C_etc..5D.3F|FAQ]].&lt;br /&gt;
&lt;br /&gt;
Wesnoth is also available for OS X from [http://brew.sh/ Homebrew] and [http://www.macports.org/ Macports]. Macports carries only the stable version. Homebrew carries stable release, development release, and can also build the &amp;quot;bleeding edge&amp;quot; master branch.&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
== Stable (1.10 branch) ==&lt;br /&gt;
The stable files are meant to be used as a stable and rather balanced version of the game. Each version of the 1.10 branch is compatible to each other.&lt;br /&gt;
&lt;br /&gt;
Version &amp;lt;b&amp;gt;1.10.7&amp;lt;/b&amp;gt; is the latest stable version. This version is recommended for most players since the 1.10 online multiplayer community is very large and user-made campaign server has a robust content selection. &lt;br /&gt;
&lt;br /&gt;
==== Source code ====&lt;br /&gt;
* [[CompilingWesnoth|Compiling Guide]] - How to compile the source code&lt;br /&gt;
{{StableDownload}}&lt;br /&gt;
&lt;br /&gt;
==== GNU/Linux ====&lt;br /&gt;
* There are binaries for many different GNU/Linux distributions. Not all are always up to date with the current release. Please have a look at the [[WesnothBinariesLinux|Linux binary page]] for more information about the binaries for your distribution.&lt;br /&gt;
&lt;br /&gt;
==== Miscellaneous ====&lt;br /&gt;
* [http://www.wesnoth.org/wiki/Download_Xdeltas#Stable_Version_1.10.x Xdelta for the source code]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/ SourceForge page for current and all previous versions]&lt;br /&gt;
&lt;br /&gt;
== Development (1.11 branch) ==&lt;br /&gt;
Version 1.11.x is the latest development version, boasting updated graphics and new exciting features. However, there may be occasional bugs or performance problems in the development versions since heavy changes are taking place all the time. For balanced and stable gaming, it is recommended you use the latest version of the 1.10.x branch. This version is recommended for coders and campaign developers, as well as those who want to preview the future of Wesnoth. People familiar with version control systems  and compiling can follow the latest development by checking [[WesnothRepository]].&lt;br /&gt;
&lt;br /&gt;
==== Source code ====&lt;br /&gt;
* [[CompilingWesnoth|Compiling Guide]] - How to compile the source code&lt;br /&gt;
{{DevDownload}}&lt;br /&gt;
&lt;br /&gt;
==== GNU/Linux ====&lt;br /&gt;
* There are binaries for many different GNU/Linux distributions. Not all are always up to date with the current release. Please have a look at the [[WesnothBinariesLinux|Linux binary page]] for more information about the binaries for your distribution.&lt;br /&gt;
&lt;br /&gt;
==== Miscellaneous ====&lt;br /&gt;
* [http://wiki.wesnoth.org/Download_Xdeltas#Development_Version_1.11.x Xdelta for the source code]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/ SourceForge page for current and all previous versions]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/unofficial/Mac%20Compile%20Stuff/wesnoth_compile_mac_1.9.zip/download MacCompileStuff for 1.9]&lt;br /&gt;
&lt;br /&gt;
== License ==&lt;br /&gt;
''Main article: [[Wesnoth:Copyrights]]''&lt;br /&gt;
&lt;br /&gt;
This program is free software; you can redistribute it and/or modify it under the terms of the [http://www.fsf.org/copyleft/gpl.html GNU General Public License version 2], as published by the [http://www.fsf.org Free Software Foundation].&lt;br /&gt;
	&lt;br /&gt;
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.&lt;br /&gt;
	&lt;br /&gt;
== UMC Editor ==&lt;br /&gt;
	&lt;br /&gt;
This is available with Wesnoth 1.9.x and greater (including Wesnoth 1.10.x). Details and installation steps can be found at: http://eclipse.wesnoth.org&lt;br /&gt;
	&lt;br /&gt;
== See also ==	&lt;br /&gt;
* [http://changelog.wesnoth.org Changelog]	&lt;br /&gt;
* [[WesnothRepository]] - bleeding edge version from the repository	&lt;br /&gt;
	&lt;br /&gt;
[[Category:Building and Installing]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Download&amp;diff=55842</id>
		<title>Download</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Download&amp;diff=55842"/>
		<updated>2014-11-09T21:07:11Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Download/Translations}}&lt;br /&gt;
Welcome to the ''Battle for Wesnoth'' downloads page. The BfW project team officially releases the source code and builds for Windows, OS X, OpenPandora, and various Linux distros. Torrents are unofficial.&lt;br /&gt;
&lt;br /&gt;
If the latest binaries are not currently available for your OS, please check back in a few days to see if they have been placed here. Packagers have been informed of the release, please be patient.  In the meantime, read the [[FAQ#A_new_version_is_out.2C_but_where_is_the_download_for_.5BWindows.2C_Mac_OS_X.2C_etc..5D.3F|FAQ]].&lt;br /&gt;
&lt;br /&gt;
Wesnoth is also available for OS X from [[http://brew.sh|Homebrew]] and [[https://www.macports.org/|Macports]]. Macports carries only the stable version. Homebrew carries stable release, development release, and can also build the &amp;quot;bleeding edge&amp;quot; master branch.&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
== Stable (1.10 branch) ==&lt;br /&gt;
The stable files are meant to be used as a stable and rather balanced version of the game. Each version of the 1.10 branch is compatible to each other.&lt;br /&gt;
&lt;br /&gt;
Version &amp;lt;b&amp;gt;1.10.7&amp;lt;/b&amp;gt; is the latest stable version. This version is recommended for most players since the 1.10 online multiplayer community is very large and user-made campaign server has a robust content selection. &lt;br /&gt;
&lt;br /&gt;
==== Source code ====&lt;br /&gt;
* [[CompilingWesnoth|Compiling Guide]] - How to compile the source code&lt;br /&gt;
{{StableDownload}}&lt;br /&gt;
&lt;br /&gt;
==== GNU/Linux ====&lt;br /&gt;
* There are binaries for many different GNU/Linux distributions. Not all are always up to date with the current release. Please have a look at the [[WesnothBinariesLinux|Linux binary page]] for more information about the binaries for your distribution.&lt;br /&gt;
&lt;br /&gt;
==== Miscellaneous ====&lt;br /&gt;
* [http://www.wesnoth.org/wiki/Download_Xdeltas#Stable_Version_1.10.x Xdelta for the source code]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/ SourceForge page for current and all previous versions]&lt;br /&gt;
&lt;br /&gt;
== Development (1.11 branch) ==&lt;br /&gt;
Version 1.11.x is the latest development version, boasting updated graphics and new exciting features. However, there may be occasional bugs or performance problems in the development versions since heavy changes are taking place all the time. For balanced and stable gaming, it is recommended you use the latest version of the 1.10.x branch. This version is recommended for coders and campaign developers, as well as those who want to preview the future of Wesnoth. People familiar with version control systems  and compiling can follow the latest development by checking [[WesnothRepository]].&lt;br /&gt;
&lt;br /&gt;
==== Source code ====&lt;br /&gt;
* [[CompilingWesnoth|Compiling Guide]] - How to compile the source code&lt;br /&gt;
{{DevDownload}}&lt;br /&gt;
&lt;br /&gt;
==== GNU/Linux ====&lt;br /&gt;
* There are binaries for many different GNU/Linux distributions. Not all are always up to date with the current release. Please have a look at the [[WesnothBinariesLinux|Linux binary page]] for more information about the binaries for your distribution.&lt;br /&gt;
&lt;br /&gt;
==== Miscellaneous ====&lt;br /&gt;
* [http://wiki.wesnoth.org/Download_Xdeltas#Development_Version_1.11.x Xdelta for the source code]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/ SourceForge page for current and all previous versions]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/unofficial/Mac%20Compile%20Stuff/wesnoth_compile_mac_1.9.zip/download MacCompileStuff for 1.9]&lt;br /&gt;
&lt;br /&gt;
== License ==&lt;br /&gt;
''Main article: [[Wesnoth:Copyrights]]''&lt;br /&gt;
&lt;br /&gt;
This program is free software; you can redistribute it and/or modify it under the terms of the [http://www.fsf.org/copyleft/gpl.html GNU General Public License version 2], as published by the [http://www.fsf.org Free Software Foundation].&lt;br /&gt;
	&lt;br /&gt;
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.&lt;br /&gt;
	&lt;br /&gt;
== UMC Editor ==&lt;br /&gt;
	&lt;br /&gt;
This is available with Wesnoth 1.9.x and greater (including Wesnoth 1.10.x). Details and installation steps can be found at: http://eclipse.wesnoth.org&lt;br /&gt;
	&lt;br /&gt;
== See also ==	&lt;br /&gt;
* [http://changelog.wesnoth.org Changelog]	&lt;br /&gt;
* [[WesnothRepository]] - bleeding edge version from the repository	&lt;br /&gt;
	&lt;br /&gt;
[[Category:Building and Installing]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Download&amp;diff=55840</id>
		<title>Download</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Download&amp;diff=55840"/>
		<updated>2014-11-09T20:43:11Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Download/Translations}}&lt;br /&gt;
Welcome to the ''Battle for Wesnoth'' downloads page. The BfW project team officially releases the source code and builds for Windows, OS X, OpenPandora, and various Linux distros. Torrents are unofficial.&lt;br /&gt;
&lt;br /&gt;
If the latest binaries are not currently available for your OS, please check back in a few days to see if they have been placed here. Packagers have been informed of the release, please be patient.  In the meantime, read the [[FAQ#A_new_version_is_out.2C_but_where_is_the_download_for_.5BWindows.2C_Mac_OS_X.2C_etc..5D.3F|FAQ]].&lt;br /&gt;
__NOTOC__&lt;br /&gt;
== Stable (1.10 branch) ==&lt;br /&gt;
The stable files are meant to be used as a stable and rather balanced version of the game. Each version of the 1.10 branch is compatible to each other.&lt;br /&gt;
&lt;br /&gt;
Version &amp;lt;b&amp;gt;1.10.7&amp;lt;/b&amp;gt; is the latest stable version. This version is recommended for most players since the 1.10 online multiplayer community is very large and user-made campaign server has a robust content selection. &lt;br /&gt;
&lt;br /&gt;
==== Source code ====&lt;br /&gt;
* [[CompilingWesnoth|Compiling Guide]] - How to compile the source code&lt;br /&gt;
{{StableDownload}}&lt;br /&gt;
&lt;br /&gt;
==== GNU/Linux ====&lt;br /&gt;
* There are binaries for many different GNU/Linux distributions. Not all are always up to date with the current release. Please have a look at the [[WesnothBinariesLinux|Linux binary page]] for more information about the binaries for your distribution.&lt;br /&gt;
&lt;br /&gt;
==== Miscellaneous ====&lt;br /&gt;
* [http://www.wesnoth.org/wiki/Download_Xdeltas#Stable_Version_1.10.x Xdelta for the source code]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/ SourceForge page for current and all previous versions]&lt;br /&gt;
&lt;br /&gt;
== Development (1.11 branch) ==&lt;br /&gt;
Version 1.11.x is the latest development version, boasting updated graphics and new exciting features. However, there may be occasional bugs or performance problems in the development versions since heavy changes are taking place all the time. For balanced and stable gaming, it is recommended you use the latest version of the 1.10.x branch. This version is recommended for coders and campaign developers, as well as those who want to preview the future of Wesnoth. People familiar with version control systems  and compiling can follow the latest development by checking [[WesnothRepository]].&lt;br /&gt;
&lt;br /&gt;
==== Source code ====&lt;br /&gt;
* [[CompilingWesnoth|Compiling Guide]] - How to compile the source code&lt;br /&gt;
{{DevDownload}}&lt;br /&gt;
&lt;br /&gt;
==== GNU/Linux ====&lt;br /&gt;
* There are binaries for many different GNU/Linux distributions. Not all are always up to date with the current release. Please have a look at the [[WesnothBinariesLinux|Linux binary page]] for more information about the binaries for your distribution.&lt;br /&gt;
&lt;br /&gt;
==== Miscellaneous ====&lt;br /&gt;
* [http://wiki.wesnoth.org/Download_Xdeltas#Development_Version_1.11.x Xdelta for the source code]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/ SourceForge page for current and all previous versions]&lt;br /&gt;
* [http://sourceforge.net/projects/wesnoth/files/unofficial/Mac%20Compile%20Stuff/wesnoth_compile_mac_1.9.zip/download MacCompileStuff for 1.9]&lt;br /&gt;
&lt;br /&gt;
== License ==&lt;br /&gt;
''Main article: [[Wesnoth:Copyrights]]''&lt;br /&gt;
&lt;br /&gt;
This program is free software; you can redistribute it and/or modify it under the terms of the [http://www.fsf.org/copyleft/gpl.html GNU General Public License version 2], as published by the [http://www.fsf.org Free Software Foundation].&lt;br /&gt;
	&lt;br /&gt;
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.&lt;br /&gt;
	&lt;br /&gt;
== UMC Editor ==&lt;br /&gt;
	&lt;br /&gt;
This is available with Wesnoth 1.9.x and greater (including Wesnoth 1.10.x). Details and installation steps can be found at: http://eclipse.wesnoth.org&lt;br /&gt;
	&lt;br /&gt;
== See also ==	&lt;br /&gt;
* [http://changelog.wesnoth.org Changelog]	&lt;br /&gt;
* [[WesnothRepository]] - bleeding edge version from the repository	&lt;br /&gt;
	&lt;br /&gt;
[[Category:Building and Installing]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=55837</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=55837"/>
		<updated>2014-11-09T03:38:38Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Map Generator WML is used to create scenarios which are randomly generated. Of course, any scenario may reconfigure itself during a start / prestart event as much as it likes, using randomness, but the Map Generator WML has the following advantages:&lt;br /&gt;
&lt;br /&gt;
* Wesnoth has several built-in map generators which can be configured with options, and these are much better developed than any existing pure WML options.&lt;br /&gt;
* Map generation occurs before the scenario is even loaded, something which is not possible for WML events. In an mp game, the map generator code will run only on the host, side-stepping any synchronization issues, and keeping your scenario code as simple as possible.&lt;br /&gt;
* For scenarios with &amp;quot;allow_new_game=yes&amp;quot; and which use map generators, the generator may be reconfigured in the mp create screen (assuming that someone has coded a dialog for it). The user can also select to regenerate the map and get instant feedback from the minimap display.&lt;br /&gt;
&lt;br /&gt;
== Scenario vs map generation ==&lt;br /&gt;
&lt;br /&gt;
Every map generator can be used in either '''scenario_generation''' mode or '''map_generation''' mode. In map_generation mode, the generator is only used to replace the map_data of your scenario. In scenario_generation mode, the entire [scenario] tag is replaced.&lt;br /&gt;
&lt;br /&gt;
To select a map generator and mode, in your [scenario] tag you must place '''one of'''&lt;br /&gt;
* '''scenario_generation=algorithm'''&lt;br /&gt;
* '''map_generation=algorithm'''&lt;br /&gt;
where '''algorithm''' is the generator algorithm you want to use. Note that not every algorithm is designed to be use with both of these options.&lt;br /&gt;
&lt;br /&gt;
You must additionally place a [generator] tag in your scenario, which contains the options to the map generator.&lt;br /&gt;
&lt;br /&gt;
== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The exact things that should be placed in [generator] depend on what algorithm you pick. There are three kinds of generators, `default`, `cave`, `lua` {DevFeature1.13|0}, and `yamg` {DevFeature1.13|0}.&lt;br /&gt;
&lt;br /&gt;
For which key to use and what value, see the section for the generator you want to use.&lt;br /&gt;
&lt;br /&gt;
===The lua generator===&lt;br /&gt;
The lua generator type specifies a custom map generator, which you provide via lua scripts.&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for '''[generator]''' when the lua generator is used:&lt;br /&gt;
* '''create_map''' : A lua routine which returns a string containing the new map_data. The entire contents of the '''[generator]''' are passed to the script in a lua table (see [[LuaWML]]), via the argument '''...''' (see http://www.lua.org/pil/5.2.html).&lt;br /&gt;
* '''create_scenario''' : The same, but returning a '''[scenario]''' tag for the new scenario, as a lua table.&lt;br /&gt;
&lt;br /&gt;
Any other keys are used only by the lua script.&lt;br /&gt;
&lt;br /&gt;
The following keys of the output [scenario] are specifically watched by the mp create screen:&lt;br /&gt;
* '''id'''&lt;br /&gt;
* '''name'''&lt;br /&gt;
* '''description'''&lt;br /&gt;
* '''error_message'''&lt;br /&gt;
&lt;br /&gt;
====Available Lua API====&lt;br /&gt;
The usual in-game API, in the table '''wesnoth''', is not available to lua scripts. However the usual standard lua libs are available, and a random number generator object is available from the Rng table. This is an instance of the Mersenne Twister 19937 random number generator from the C++11 standard.&lt;br /&gt;
&lt;br /&gt;
* '''rng = Rng:create()''' : creates a new rng object&lt;br /&gt;
* '''rng:seed()''' : seed an rng, expects a string in hexadecimal format&lt;br /&gt;
* '''rng:draw()''' : draw a 32-bit random integer from the rng&lt;br /&gt;
&lt;br /&gt;
===The Default Generator===&lt;br /&gt;
The default generator can be used to generate map data for any scenario. The data in this section is inferred from “data/multiplayer/scenarios/Random_Scenario.cfg”, usage in add-on content, and inspection of mapgen.cpp&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
To use the default '''[generator]''' your '''[scenario]''' tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation=default'''&lt;br /&gt;
* '''map_generation=default'''&lt;br /&gt;
If ‘scenario_generation’ is used, the engine will expect for your entire '''[scenario]''' sub tags to be inside a '''[scenario]''' tag inside '''[generator]'''. Tags outside of this will be ignored.  There may be value in this, but at this writing, it’s not clear.&lt;br /&gt;
‘map_generation=default’ is simpler and more commonly used.  It is also necessary to use this key so that you can regenerate a map in MP game creation.&lt;br /&gt;
In its use only generator data is in the '''[generator]''' tag, all other '''[scenario]''' data is placed outside of it. The exception is if you are making an initial MP scenario available in MP game creation, for this a '''[scenario]''' tag must appear inside of '''[generator]''', containing the '''[scenario]''' subtags you want to use. See “data/multiplayer/scenarios/Random_Scenario.cfg” for an example.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''' when the default generator is used:&lt;br /&gt;
* '''[scenario]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default'''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size''&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers&lt;br /&gt;
&lt;br /&gt;
* '''villages''': villages per 1,000 hexes&lt;br /&gt;
* '''players''': Number of starting locations for the map.&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map. (Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads''': number of roads the generator will attempt to make&lt;br /&gt;
* '''road_windiness''': Use 1 for the road to be made using the cheapest path (based on [road_cost] tags), higher values introduce randomness to make the road wind a bit.&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types that come in at different heights, from highest to lowest. Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions. For example, water becomes ice at low temperatures, grass snow, etc. If the terrain is between the min_x and max_x it will be converted. If min_x is not defined it will default to a large negative number. If max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance''': all castles generated must be this number of hexes apart from each other&lt;br /&gt;
* '''[naming]''': The names used to label landscape features (forests, lakes, etc.). This controls, for example, the &amp;quot;Fox&amp;quot; part of &amp;quot;Foxwood&amp;quot;. If this tag is empty, those labels should be suppressed. (Due to a bug, they are not suppressed prior to 1.11.1.) The predefined macro VILLAGE_NAMES is one option for the contents of this tag. If that macro is not used, this tag takes one key.&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]''': The names used to label villages. This controls, for example, the &amp;quot;Fox&amp;quot; part of &amp;quot;Foxham&amp;quot;. If this tag is empty, those labels should be suppressed. (Due to a bug, they are not suppressed prior to 1.11.1.) The predefined macro VILLAGE_NAMES is one option for the contents of this tag. If that macro is not used, this tag takes one key.&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
&lt;br /&gt;
===The Cave Generator===&lt;br /&gt;
The cave generator does not appear to have been written for multiplayer scenario game creation like the default generator was.  It is used in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg''' &amp;amp; '''campaigns\Heir_To_The_Throne\scenarios\ 17_Scepter_of_Fire.cfg '''. The data here is inferred from those scenarios and an inspection of cavegen.cpp&lt;br /&gt;
&lt;br /&gt;
To use the cave '''[generator]''' your '''[scenario]'''  tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation=cave'''&lt;br /&gt;
* '''map_generation=cave'''&lt;br /&gt;
Here it is recommend you use ‘scenario_generation’ as there are examples to follow, though it may be possible to use’ map_generation’.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''' when the cave generator is used:&lt;br /&gt;
* '''[settings]''':  behaves as if '''[scenario]''', See [[ScenarioWML]]&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''village_density''': influences number of villages&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth.&lt;br /&gt;
* '''flipy_chance''': Chance to flip y coordinates, that meens the map is mirrored at the horizontal axis in its midth.&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''chance''': chance for the chamber to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''laziness''':&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== YAMG generator ===&lt;br /&gt;
&lt;br /&gt;
*** Please document me! ***&lt;br /&gt;
&lt;br /&gt;
== Infrastructure ==&lt;br /&gt;
&lt;br /&gt;
* The default generator settings are loaded from a scenario file under data/multiplayer/scenarios.&lt;br /&gt;
* mapgen_dialog overwrites these values if necessary.&lt;br /&gt;
* The create_map / create_scenario function is called by one of the following&lt;br /&gt;
** multiplayer_create_engine.cpp:394&lt;br /&gt;
** context_manager.cpp:648&lt;br /&gt;
** map_create.cpp:56&lt;br /&gt;
* A map buffer is written to res[&amp;quot;map_data&amp;quot;]&lt;br /&gt;
* the config res is passed to the calling function.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=55836</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=55836"/>
		<updated>2014-11-09T03:28:16Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Map Generator WML is used to create scenarios which are randomly generated. Of course, any scenario may reconfigure itself during a start / prestart event as much as it likes, using randomness, but the Map Generator WML has the following advantages:&lt;br /&gt;
&lt;br /&gt;
* Wesnoth has several built-in map generators which can be configured with options, and these are much better developed than any existing pure WML options.&lt;br /&gt;
* Map generation occurs before the scenario is even loaded, something which is not possible for WML events. In an mp game, the map generator code will run only on the host, side-stepping any synchronization issues, and keeping your scenario code as simple as possible.&lt;br /&gt;
* For scenarios with &amp;quot;allow_new_game=yes&amp;quot; and which use map generators, the generator may be reconfigured in the mp create screen (assuming that someone has coded a dialog for it). The user can also select to regenerate the map and get instant feedback from the minimap display.&lt;br /&gt;
&lt;br /&gt;
== Scenario vs map generation ==&lt;br /&gt;
&lt;br /&gt;
Every map generator can be used in either '''scenario_generation''' mode or '''map_generation''' mode. In map_generation mode, the generator is only used to replace the map_data of your scenario. In scenario_generation mode, the entire [scenario] tag is replaced.&lt;br /&gt;
&lt;br /&gt;
To select a map generator and mode, in your [scenario] tag you must place '''one of'''&lt;br /&gt;
* '''scenario_generation=algorithm'''&lt;br /&gt;
* '''map_generation=algorithm'''&lt;br /&gt;
where '''algorithm''' is the generator algorithm you want to use. Note that not every algorithm is designed to be use with both of these options.&lt;br /&gt;
&lt;br /&gt;
You must additionally place a [generator] tag in your scenario, which contains the options to the map generator.&lt;br /&gt;
&lt;br /&gt;
== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The exact things that should be placed in [generator] depend on what algorithm you pick. There are three kinds of generators, `default`, `cave`, `lua` {DevFeature1.13|0}, and `yamg` {DevFeature1.13|0}.&lt;br /&gt;
&lt;br /&gt;
For which key to use and what value, see the section for the generator you want to use.&lt;br /&gt;
&lt;br /&gt;
===The lua generator===&lt;br /&gt;
The lua generator type specifies a custom map generator, which you provide via lua scripts.&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for '''[generator]''' when the lua generator is used:&lt;br /&gt;
* '''create_map''' : A lua routine which returns a string containing the new map_data. The entire contents of the '''[generator]''' are passed to the script in a lua table (see [[LuaWML]]), via the argument '''...''' (see http://www.lua.org/pil/5.2.html).&lt;br /&gt;
* '''create_scenario''' : The same, but returning a '''[scenario]''' tag for the new scenario, as a lua table.&lt;br /&gt;
&lt;br /&gt;
Any other keys are used only by the lua script.&lt;br /&gt;
&lt;br /&gt;
The following keys of the output [scenario] are specifically watched by the mp create screen:&lt;br /&gt;
* '''id'''&lt;br /&gt;
* '''name'''&lt;br /&gt;
* '''description'''&lt;br /&gt;
* '''error_message'''&lt;br /&gt;
&lt;br /&gt;
====Available Lua API====&lt;br /&gt;
The usual in-game API, in the table '''wesnoth''', is not available to lua scripts. However the usual standard lua libs are available, and a random number generator object is available from the Rng table. This is an instance of the Mersenne Twister 19937 random number generator from the C++11 standard.&lt;br /&gt;
&lt;br /&gt;
'''rng = Rng:create()''' : creates a new rng object&lt;br /&gt;
'''rng:seed()''' : seed an rng, expects a string in hexadecimal format&lt;br /&gt;
'''rng:draw()''' : draw a 32-bit random integer from the rng&lt;br /&gt;
&lt;br /&gt;
===The Default Generator===&lt;br /&gt;
The default generator can be used to generate map data for any scenario. The data in this section is inferred from “data/multiplayer/scenarios/Random_Scenario.cfg”, usage in add-on content, and inspection of mapgen.cpp&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
To use the default '''[generator]''' your '''[scenario]''' tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation=default'''&lt;br /&gt;
* '''map_generation=default'''&lt;br /&gt;
If ‘scenario_generation’ is used, the engine will expect for your entire '''[scenario]''' sub tags to be inside a '''[scenario]''' tag inside '''[generator]'''. Tags outside of this will be ignored.  There may be value in this, but at this writing, it’s not clear.&lt;br /&gt;
‘map_generation=default’ is simpler and more commonly used.  It is also necessary to use this key so that you can regenerate a map in MP game creation.&lt;br /&gt;
In its use only generator data is in the '''[generator]''' tag, all other '''[scenario]''' data is placed outside of it. The exception is if you are making an initial MP scenario available in MP game creation, for this a '''[scenario]''' tag must appear inside of '''[generator]''', containing the '''[scenario]''' subtags you want to use. See “data/multiplayer/scenarios/Random_Scenario.cfg” for an example.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''' when the default generator is used:&lt;br /&gt;
* '''[scenario]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default'''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size''&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers&lt;br /&gt;
&lt;br /&gt;
* '''villages''': villages per 1,000 hexes&lt;br /&gt;
* '''players''': Number of starting locations for the map.&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map. (Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads''': number of roads the generator will attempt to make&lt;br /&gt;
* '''road_windiness''': Use 1 for the road to be made using the cheapest path (based on [road_cost] tags), higher values introduce randomness to make the road wind a bit.&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types that come in at different heights, from highest to lowest. Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions. For example, water becomes ice at low temperatures, grass snow, etc. If the terrain is between the min_x and max_x it will be converted. If min_x is not defined it will default to a large negative number. If max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance''': all castles generated must be this number of hexes apart from each other&lt;br /&gt;
* '''[naming]''': The names used to label landscape features (forests, lakes, etc.). This controls, for example, the &amp;quot;Fox&amp;quot; part of &amp;quot;Foxwood&amp;quot;. If this tag is empty, those labels should be suppressed. (Due to a bug, they are not suppressed prior to 1.11.1.) The predefined macro VILLAGE_NAMES is one option for the contents of this tag. If that macro is not used, this tag takes one key.&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]''': The names used to label villages. This controls, for example, the &amp;quot;Fox&amp;quot; part of &amp;quot;Foxham&amp;quot;. If this tag is empty, those labels should be suppressed. (Due to a bug, they are not suppressed prior to 1.11.1.) The predefined macro VILLAGE_NAMES is one option for the contents of this tag. If that macro is not used, this tag takes one key.&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
&lt;br /&gt;
===The Cave Generator===&lt;br /&gt;
The cave generator does not appear to have been written for multiplayer scenario game creation like the default generator was.  It is used in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg''' &amp;amp; '''campaigns\Heir_To_The_Throne\scenarios\ 17_Scepter_of_Fire.cfg '''. The data here is inferred from those scenarios and an inspection of cavegen.cpp&lt;br /&gt;
&lt;br /&gt;
To use the cave '''[generator]''' your '''[scenario]'''  tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation=cave'''&lt;br /&gt;
* '''map_generation=cave'''&lt;br /&gt;
Here it is recommend you use ‘scenario_generation’ as there are examples to follow, though it may be possible to use’ map_generation’.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''' when the cave generator is used:&lt;br /&gt;
* '''[settings]''':  behaves as if '''[scenario]''', See [[ScenarioWML]]&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''village_density''': influences number of villages&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth.&lt;br /&gt;
* '''flipy_chance''': Chance to flip y coordinates, that meens the map is mirrored at the horizontal axis in its midth.&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''chance''': chance for the chamber to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''laziness''':&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== YAMG generator ===&lt;br /&gt;
&lt;br /&gt;
*** Please document me! ***&lt;br /&gt;
&lt;br /&gt;
== Infrastructure ==&lt;br /&gt;
&lt;br /&gt;
* The default generator settings are loaded from a scenario file under data/multiplayer/scenarios.&lt;br /&gt;
* mapgen_dialog overwrites these values if necessary.&lt;br /&gt;
* The create_map / create_scenario function is called by one of the following&lt;br /&gt;
** multiplayer_create_engine.cpp:394&lt;br /&gt;
** context_manager.cpp:648&lt;br /&gt;
** map_create.cpp:56&lt;br /&gt;
* A map buffer is written to res[&amp;quot;map_data&amp;quot;]&lt;br /&gt;
* the config res is passed to the calling function.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55793</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55793"/>
		<updated>2014-10-25T22:11:30Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Compile wesnoth */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
If you get configuration errors, a good way to trouble shoot is to check your /build/config.log&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
=== Note ===&lt;br /&gt;
&lt;br /&gt;
When I finally compiled I get these warnings on linking:&lt;br /&gt;
&lt;br /&gt;
  /usr/bin/ccache i686-w64-mingw32-g++ -o wesnoth.exe -static-libgcc -static-libstdc++ -mwindows -mthreads build/release/wesnoth.o build/release/libwesnoth_extras.a build/release/lua/liblua.a build/release/libwesnoth_core.a build/release/libwesnoth.a build/release/libwesnoth_sdl.a build/release/libwesnoth_extras.a build/release/lua/liblua.a packaging/windows/wesnoth.o -L/home/chris/w-deps/lib -L/home/chris/w-deps/lib -L/home/chris/old_boost/boost_1_52_0/stage/lib -lmingw32 -lSDLmain -lSDL -lSDL_net -lboost_iostreams -lz -lbz2 -lboost_system -lboost_filesystem -lboost_locale -lSDL_ttf -lSDL_mixer -lSDL_image -lws2_32 -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lfreetype -lpango-1.0 -lm -lgobject-2.0 -lglib-2.0 -lintl -lfontconfig -lboost_program_options -lboost_regex -lvorbisfile -lwsock32 -lintl -lz&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(gzip.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_9iostreams10gzip_errorEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_9iostreams10gzip_errorEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(gzip.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(gzip.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9iostreams10gzip_errorEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(file_descriptor.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINSt8ios_base7failureEEE[__ZTSN5boost16exception_detail19error_info_injectorINSt8ios_base7failureEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(file_descriptor.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_iostreams.a(file_descriptor.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINSt8ios_base7failureEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_filesystem.a(operations.o): duplicate section `.rdata$_ZTSN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEEE[__ZTSN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_locale.a(message.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_locale.a(message.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_locale.a(message.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(value_semantic.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(convert.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(convert.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(convert.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(cmdline.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE[__ZTSN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(cmdline.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_program_options.a(cmdline.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size&lt;br /&gt;
  /home/chris/old_boost/boost_1_52_0/stage/lib/libboost_regex.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size&lt;br /&gt;
  scons: done building targets.&lt;br /&gt;
&lt;br /&gt;
We don't know what these warnings are exactly but it seems they can be ignored.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
Besides the libs like SDL, pango, etc., you also need a .dll specific to mingw (I guess this is the mingw run time library). I found that I needed this dll:&lt;br /&gt;
&lt;br /&gt;
  /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc_s_sjlj-1.dll&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;br /&gt;
&lt;br /&gt;
=== Tip ===&lt;br /&gt;
&lt;br /&gt;
As I learned later, a better way to handle this is to just copy all of the .dll files you need into the root of your repo, next to wesnoth.exe. This will make wine find them first, for wesnoth only, and our .gitignore file includes *.dll so they won't get into the repo.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
A helpful thing I found is, if you have problems running wesnoth with the DLL's, you can sanity check  by running the little executables generated by scons for the configuration tests. E.g.&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine build/sconf_temp/conftest_20.exe&lt;br /&gt;
&lt;br /&gt;
If the test works it should give no output, otherwise if it's not linking right it should give you an error.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55789</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55789"/>
		<updated>2014-10-25T06:06:08Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* WINE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
If you get configuration errors, a good way to trouble shoot is to check your /build/config.log&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
Besides the libs like SDL, pango, etc., you also need a .dll specific to mingw (I guess this is the mingw run time library). I found that I needed this dll:&lt;br /&gt;
&lt;br /&gt;
  /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc_s_sjlj-1.dll&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;br /&gt;
&lt;br /&gt;
=== Tip ===&lt;br /&gt;
&lt;br /&gt;
As I learned later, a better way to handle this is to just copy all of the .dll files you need into the root of your repo, next to wesnoth.exe. This will make wine find them first, for wesnoth only, and our .gitignore file includes *.dll so they won't get into the repo.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
A helpful thing I found is, if you have problems running wesnoth with the DLL's, you can sanity check  by running the little executables generated by scons for the configuration tests. E.g.&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine build/sconf_temp/conftest_20.exe&lt;br /&gt;
&lt;br /&gt;
If the test works it should give no output, otherwise if it's not linking right it should give you an error.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55784</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55784"/>
		<updated>2014-10-24T16:30:42Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Compile wesnoth */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
If you get configuration errors, a good way to trouble shoot is to check your /build/config.log&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
Besides the libs like SDL, pango, etc., you also need a .dll specific to mingw (I guess this is the mingw run time library). I found that I needed this dll:&lt;br /&gt;
&lt;br /&gt;
  /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc_s_sjlj-1.dll&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
A helpful thing I found is, if you have problems running wesnoth with the DLL's, you can sanity check  by running the little executables generated by scons for the configuration tests. E.g.&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine build/sconf_temp/conftest_20.exe&lt;br /&gt;
&lt;br /&gt;
If the test works it should give no output, otherwise if it's not linking right it should give you an error.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55783</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55783"/>
		<updated>2014-10-24T16:29:49Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* WINE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
Besides the libs like SDL, pango, etc., you also need a .dll specific to mingw (I guess this is the mingw run time library). I found that I needed this dll:&lt;br /&gt;
&lt;br /&gt;
  /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc_s_sjlj-1.dll&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
A helpful thing I found is, if you have problems running wesnoth with the DLL's, you can sanity check  by running the little executables generated by scons for the configuration tests. E.g.&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine build/sconf_temp/conftest_20.exe&lt;br /&gt;
&lt;br /&gt;
If the test works it should give no output, otherwise if it's not linking right it should give you an error.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55782</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55782"/>
		<updated>2014-10-24T16:14:21Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* WINE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
Besides the libs like SDL, pango, etc., you also need a .dll specific to mingw (I guess this is the mingw run time library). I found that I needed this dll:&lt;br /&gt;
&lt;br /&gt;
  /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc_s_sjlj-1.dll&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55781</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55781"/>
		<updated>2014-10-24T16:07:13Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Download boost */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55780</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55780"/>
		<updated>2014-10-24T16:07:00Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Download boost */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at sourceforge, e.g.&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.52.0/&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.48.0/&lt;br /&gt;
http://sourceforge.net/projects/boost/files/boost/1.44.0/&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55779</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55779"/>
		<updated>2014-10-24T16:06:13Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Get mingw */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw32 == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55778</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55778"/>
		<updated>2014-10-24T16:05:01Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Compile wesnoth */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: First directory that boost reported to you above (or for whatever boost version you want to use)&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Second directory that boost reported to you above (Wherever the boost libraries ended up for you.)&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55777</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55777"/>
		<updated>2014-10-24T16:02:21Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Compile boost */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32 address-model=32 architecture=x86 instruction-set=i686&lt;br /&gt;
   link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Discussion of flags&lt;br /&gt;
; toolset=gcc-w64mingw32&lt;br /&gt;
: Tells to use the compiler I choose for 32 bit windows. Could also have tried e.g. gcc-w64mingw64, for 64-bit windows, based on my user-config.jam, or gcc-4.6 for g++-4.6 compiler (see my user-config.jam above)&lt;br /&gt;
; -d+2&lt;br /&gt;
; --debug-configuration&lt;br /&gt;
: These are debugging output options that make boost tell you about the configuration, and show you what compiler commands it is running.&lt;br /&gt;
; -a&lt;br /&gt;
; --reconfigure&lt;br /&gt;
: -a makes sure that all targets are rebuilt, and reconfigure makes sure that it reconfigures based on new options. If you are changing things around these options prevent you from getting screwed over by stale options.&lt;br /&gt;
; --with-iostreams&lt;br /&gt;
; --with-locale&lt;br /&gt;
; --with-regex&lt;br /&gt;
; --with-filesystem&lt;br /&gt;
; --with-system&lt;br /&gt;
; --with-program_options&lt;br /&gt;
: Select what libraries you want. It's better to use --with than --without because otherwise you get a bunch of random crap. You can't use both kinds.&lt;br /&gt;
; target-os=windows&lt;br /&gt;
; threading=multi&lt;br /&gt;
; threadapi=win32&lt;br /&gt;
: You need these to make it build dll's, and that will work for you.&lt;br /&gt;
; address-model=32&lt;br /&gt;
; architecture=x86&lt;br /&gt;
; instruction-set=i686&lt;br /&gt;
: I added these out of paranoia at some point but they might not really be necessary&lt;br /&gt;
; link=static&lt;br /&gt;
; runtime-link=static&lt;br /&gt;
: This is the only reasonable option here&lt;br /&gt;
; -j 2&lt;br /&gt;
: Parallelize the build over 2 cores&lt;br /&gt;
; -sBZIP2_BINARY=libbz2&lt;br /&gt;
; -sBZIP2_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sBZIP2_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find bzip2 binary and header. I earlier tried to do this just with cxxflags and linker flags, but it got confused with my system-installed bzip2 and caused me a lot of pain. This fixed it.&lt;br /&gt;
; -sZLIB_BINARY=zlib&lt;br /&gt;
; -sZLIB_INCLUDE=/home/chris/w-deps/include&lt;br /&gt;
; -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
: Tell boost exactly where to find zlib binary and header.&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: Or corresponding, whereever the root is for the boost that you want to use.&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Wherever the boost libraries ended up for you.&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55776</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55776"/>
		<updated>2014-10-24T15:50:32Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at 32-bit windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32    link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: Or corresponding, whereever the root is for the boost that you want to use.&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Wherever the boost libraries ended up for you.&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55775</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55775"/>
		<updated>2014-10-24T15:44:19Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32    link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: Or corresponding, whereever the root is for the boost that you want to use.&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Wherever the boost libraries ended up for you.&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;br /&gt;
&lt;br /&gt;
== WINE ==&lt;br /&gt;
&lt;br /&gt;
To get wine to run I did the following. You must make sure you are using a 32 bit environment.&lt;br /&gt;
&lt;br /&gt;
  env WINEPREFIX=~/prefix32 WINEARCH=win32 wine cmd&lt;br /&gt;
&lt;br /&gt;
All the online instructions say that you need to update wine's path, using regedit, to point to your dll's. I couldn't actually get this to work, so I ended up putting symlinks in my prefix 32 C:\windows\system32 directory:&lt;br /&gt;
&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s ~/w-deps/bin&lt;br /&gt;
  ~/prefix32/drive_c/windows/system32 $ ln -s /usr/lib/gcc/i686-w64-mingw32/4.9-win32/&lt;br /&gt;
&lt;br /&gt;
If I got errors like this:&lt;br /&gt;
&lt;br /&gt;
  $ env WINEPREFIX=~/prefix32 WINEARCH=win32 wine wesnoth&lt;br /&gt;
  err:module:import_dll Library libpangoft2-1.0-0.dll (which is needed by L&amp;quot;C:\\windows\\system32\\libpangocairo-1.0-0.dll&amp;quot;) not found&lt;br /&gt;
  err:module:import_dll Library libpangocairo-1.0-0.dll (which is needed by L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot;) not found&lt;br /&gt;
  err:module:LdrInitializeThunk Main exe initialization for L&amp;quot;Z:\\home\\chris\\wesnoth-src\\clone\\wesnoth\\wesnoth.exe&amp;quot; failed, status c0000135&lt;br /&gt;
&lt;br /&gt;
I fixed it by adding a symlink to ~/w-deps/bin/libpangoft2-1.0-0.dll in the folder prefix32/drive_c/windows/system32.&lt;br /&gt;
&lt;br /&gt;
And so on and so forth... Eventually it worked.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55774</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55774"/>
		<updated>2014-10-24T07:28:47Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Make a boost config file (tell it what compiler you want to use) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
(And make sure its the only w64mingw32 line of course.)&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32    link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: Or corresponding, whereever the root is for the boost that you want to use.&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Wherever the boost libraries ended up for you.&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55773</id>
		<title>User:Iceiceice/Cross-compiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=User:Iceiceice/Cross-compiling&amp;diff=55773"/>
		<updated>2014-10-24T07:23:15Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: Created page with &amp;quot;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it a...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some instructions I created the first time I managed to cross compile wesnoth. It's as much a &amp;quot;post-mortem&amp;quot; as a guide, I leave it here in case I ever want to do it again later, or if it might help someone.&lt;br /&gt;
&lt;br /&gt;
These instructions refer to using mingw to cross-compile wesnoth 1.13.0-dev on Linux Mint Qiana 17 , targeted at windows.&lt;br /&gt;
&lt;br /&gt;
Last tested at commit: 1385ab3791088d7c9bfa3bc439fcf49b23563535&lt;br /&gt;
&lt;br /&gt;
== Get mingw == &lt;br /&gt;
&lt;br /&gt;
It might seem as simple as &amp;quot;sudo apt-get install mingw32&amp;quot;, but after you do this, you need to make sure that you have a 32 bit compiler which is good enough to compile wesnoth. This required some trial and error, the version I got automatically from the distribution was only gcc 4.2, as you can see:&lt;br /&gt;
&lt;br /&gt;
   $ i586-mingw32msvc-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  Target: i586-mingw32msvc&lt;br /&gt;
  Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.2.1-sjlj (mingw32-2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Furthermore it was broken, and had some bugs about ::swprintf not defined, which caused boost iostreams to break... google this for some stories of pain. [http://www.gaia-gis.it/spatialite-2.4.0-3/mingw_how_to.html] [http://cboard.cprogramming.com/windows-programming/126629-error-'-swprintf'-has-not-been-declared.html] [http://qt-project.org/forums/viewthread/8055]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Therefore to get a more recent version of mingw I added a package from utopic universe :&lt;br /&gt;
&lt;br /&gt;
  $ sudo add-apt-repository -y &amp;quot;deb http://archive.ubuntu.com/ubuntu/ utopic main universe&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And I install&lt;br /&gt;
&lt;br /&gt;
  $ sudo apt-get install g++-mingw-w64-i686&lt;br /&gt;
&lt;br /&gt;
(Launchpad page: http://packages.ubuntu.com/utopic/g++-mingw-w64-x86-64)&lt;br /&gt;
Now I get this instead&lt;br /&gt;
&lt;br /&gt;
  $ i686-w64-mingw32-g++ -v&lt;br /&gt;
  Using built-in specs.&lt;br /&gt;
  COLLECT_GCC=i686-w64-mingw32-g++&lt;br /&gt;
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.9-win32/lto-wrapper&lt;br /&gt;
  Target: i686-w64-mingw32&lt;br /&gt;
  Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld&lt;br /&gt;
  Thread model: win32&lt;br /&gt;
  gcc version 4.9.1 (GCC)&lt;br /&gt;
&lt;br /&gt;
With gcc 4.9, now we are in business.&lt;br /&gt;
&lt;br /&gt;
== Download loonycyborg's wesnoth deps collection ==&lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/projects/wesnoth/files/SDK/wesnoth-deps-1.11.zip/download&lt;br /&gt;
&lt;br /&gt;
I'm going to assume henceforth that you extract this to the folder &amp;quot;~/w-deps&amp;quot;, and that inside is &amp;quot;include&amp;quot;, &amp;quot;bin&amp;quot; etc. directories.&lt;br /&gt;
&lt;br /&gt;
== Download boost ==&lt;br /&gt;
&lt;br /&gt;
I wanted to test our stated boost dependencies, so I actually make a folder &amp;quot;~/old-boost/&amp;quot; where I hold several versions of boost. You can find any old version of boost at source forge, e.g.&lt;br /&gt;
&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.52.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.48.0/]&lt;br /&gt;
[http://sourceforge.net/projects/boost/files/boost/1.44.0/]&lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
&lt;br /&gt;
Download one of these and extract it to ~/old-boost/, or take from w-deps folder.&lt;br /&gt;
&lt;br /&gt;
I'm going to assume that you picked boost 1.52.0, so your boost directory is ~/old_boost/boost_1_52_0/.&lt;br /&gt;
&lt;br /&gt;
== Make a boost config file (tell it what compiler you want to use) ==&lt;br /&gt;
&lt;br /&gt;
In your home directory, make a text file called user_config.jam.&lt;br /&gt;
&lt;br /&gt;
Here's some sample contents:&lt;br /&gt;
&lt;br /&gt;
  $ cat user-config.jam &lt;br /&gt;
  using gcc ;&lt;br /&gt;
  using gcc : 4.6 : g++-4.6 ;&lt;br /&gt;
  using gcc : w64mingw32 : i586-mingw32msvc-g++ ;&lt;br /&gt;
  using gcc : w64mingw64 : x86_64-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When boost has a file like this, it means that e.g. &amp;quot;toolset=gcc-4.6&amp;quot; will cause it to use the compiler g++-4.6, and &amp;quot;toolset=gcc-w64mingw32&amp;quot; will cause it to use the compiler i586-mingw32msvc-g++.&lt;br /&gt;
&lt;br /&gt;
Make a line like this:&lt;br /&gt;
&lt;br /&gt;
  using gcc : w64mingw32 : i686-w64-mingw32-g++ ;&lt;br /&gt;
&lt;br /&gt;
To register our new compiler.&lt;br /&gt;
&lt;br /&gt;
== Compile boost ==&lt;br /&gt;
&lt;br /&gt;
Navigate to your boost directory, ~/old_boost/boost_1_52_0/&lt;br /&gt;
&lt;br /&gt;
First, run the &amp;quot;bootstrap&amp;quot; program,&lt;br /&gt;
&lt;br /&gt;
  ./bootstrap.sh&lt;br /&gt;
&lt;br /&gt;
You don't need to give it any arguments, it doesn't really matter what it builds with. It is just building the boost jam program which will actually orchestrate the boost build.&lt;br /&gt;
&lt;br /&gt;
Now, run boost jam (called &amp;quot;b2&amp;quot;). I recommend to put the actual command in shell script, for ease of use in case you have to modify it (and so you don't forget it...)&lt;br /&gt;
&lt;br /&gt;
I used the following recipe:&lt;br /&gt;
&lt;br /&gt;
  $ cat recipe&lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
 ./b2 toolset=gcc-w64mingw32 -d+2 -a --reconfigure --debug-configuration --with-iostreams --with-locale --with-regex --with-filesystem --with-system --with-program_options target-os=windows variant=release threading=multi threadapi=win32    link=static runtime-link=static -j 2 -sBZIP2_BINARY=libbz2 -sBZIP2_INCLUDE=/home/chris/w-deps/include -sBZIP2_LIBPATH=/home/chris/w-deps/bin -sZLIB_BINARY=zlib -sZLIB_INCLUDE=/home/chris/w-deps/include -sZLIB_LIBPATH=/home/chris/w-deps/bin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now run the recipe (don't forget to &amp;quot;chmod +x&amp;quot; it):&lt;br /&gt;
&lt;br /&gt;
  $ ./recipe&lt;br /&gt;
&lt;br /&gt;
If you would like to suppress the warnings, you can use cxxflags=&amp;quot;-w&amp;quot; as an additional argument.&lt;br /&gt;
&lt;br /&gt;
You should get this at the end:&lt;br /&gt;
&lt;br /&gt;
  The Boost C++ Libraries were successfully built!&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to compiler include paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0&lt;br /&gt;
  &lt;br /&gt;
  The following directory should be added to linker library paths:&lt;br /&gt;
  &lt;br /&gt;
      /home/chris/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you did not, check that all of your paths are matching correctly, that you actually have a libbz2.a and zlib.a in your ~/w-deps/bin, (and that they *match* the associated headers... if in doubt, try downloading again, or even compile the c libraries yourself, it doesn't matter what compiler you use for c libraries). Check that the compiler name is correct. You could use cxxflags to try to get additional diagnostics. The -d+2 command causes boost to output much additional diagnostics as well.&lt;br /&gt;
&lt;br /&gt;
== Compile wesnoth ==&lt;br /&gt;
&lt;br /&gt;
Now, you need to craft an scons command that will properly tell it to cross compile, to use the cross compiling compiler, and point it to your fresh boost compile, and all the deps. I prefer to in this case as well store the recipe in a shell script:&lt;br /&gt;
&lt;br /&gt;
  $ cat build_mingw_boost_1_52.sh &lt;br /&gt;
  #!/bin/bash&lt;br /&gt;
  rm .scons-option-cache&lt;br /&gt;
  scons default_targets=wesnoth build=release extra_flags_config=&amp;quot;-DBOOST_THREAD_USE_LIB -Wno-unused-local-typedefs&amp;quot; prefix=~/w-deps boostdir=~/old_boost/boost_1_52_0 boostlibdir=~/old_boost/boost_1_52_0/stage/lib gettextdir=~/w-deps gtkdir=~/w-deps  host=i686-w64-mingw32&lt;br /&gt;
&lt;br /&gt;
Some discussion&lt;br /&gt;
; rm .scons-option-cache&lt;br /&gt;
: So that stale settings can't screw up my build and confuse me&lt;br /&gt;
; default_targets=wesnoth&lt;br /&gt;
: This could also be wesnoth, wesnothd, campaignd. I think it can't include &amp;quot;test&amp;quot; atm because we didn't compile the boost unit testing system.&lt;br /&gt;
; build=release&lt;br /&gt;
: Unless you want to make a debug build&lt;br /&gt;
; extra_flags_config:&lt;br /&gt;
: Add -Wno-unused-local-typedefs or your log will be unreadable with pointless warnings.&lt;br /&gt;
: Add -DBOOST_THREAD_USE_LIB because loonycyborg said so&lt;br /&gt;
; prefix=~/w-deps&lt;br /&gt;
: This is pretty handy, this will cause scons to add ~/w-deps/include to be included as a cxx flag, and also to add ~/w-deps/bin to be linked. So it saves you some typing.&lt;br /&gt;
; boostdir=~/old_boost/boost_1_52_0&lt;br /&gt;
: Or corresponding, whereever the root is for the boost that you want to use.&lt;br /&gt;
; boostlibdir=~/old_boost/boost_1_52_0/stage/lib&lt;br /&gt;
: Wherever the boost libraries ended up for you.&lt;br /&gt;
; gettextdir=~/w-deps&lt;br /&gt;
; gtkdir=~/w-deps&lt;br /&gt;
: These point scons to find compiled versions of these, and not your system version (which will not be binary compatible in case of C++ libs).&lt;br /&gt;
: Note that I don't add sdldir=~/w-deps, because it shouldn't be necessary as SDL is a c lib, so my system version is fine. But if you get a problem finding or linking SDL, then add that in also.&lt;br /&gt;
; host=i686-w64-mingw32&lt;br /&gt;
: This is where we select the compiler, actually. scons will prepend the &amp;quot;host&amp;quot; followed by -, followed by g++, if no cxxtool argument is given. (I'm not sure how &amp;quot;host&amp;quot; and &amp;quot;cxxtool&amp;quot; arguments interact.) So this selection results in the compiler, i686-w64-mingw32-g++, as desired.&lt;br /&gt;
&lt;br /&gt;
That's all there is to it. Good luck.&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DeveloperGuide&amp;diff=55706</id>
		<title>DeveloperGuide</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DeveloperGuide&amp;diff=55706"/>
		<updated>2014-10-19T14:09:10Z</updated>

		<summary type="html">&lt;p&gt;Iceiceice: /* Dependencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Commits ==&lt;br /&gt;
* Setting up developer access to the repository: [[WesnothRepository#Commit_access]]&lt;br /&gt;
* Register to commit mailing list: https://mail.gna.org/listinfo/wesnoth-commits or get the list moderator to approve commit messages from you otherwise&lt;br /&gt;
* Trunk should compile and work after commit -- we use travis-ci, which will report any build failures on master to the irc channel. https://travis-ci.org/wesnoth/wesnoth&lt;br /&gt;
* All unit tests should pass after commit -- travis will also test this. To run the C++ unit tests, compile the &amp;quot;test&amp;quot; executable and run it. To run the WML unit tests, run &amp;quot;run_wml_tests -u&amp;quot; in the root of the repo.&lt;br /&gt;
** If a test times out spuriously on travis, you can restart the build by &lt;br /&gt;
*** clicking on the link posted to irc by the travis bot&lt;br /&gt;
***: 20141009 20:40:27-!- travis-ci [~travis-ci@ec2-184-73-55-78.compute-1.amazonaws.com] has joined #wesnoth-dev&lt;br /&gt;
***: 20141009 20:40:27&amp;lt; travis-ci&amp;gt; wesnoth/wesnoth#4154 (master - c91604a : Ignacio R. Morelle): The build was broken.&lt;br /&gt;
***: 20141009 20:40:27&amp;lt; travis-ci&amp;gt; Build details : http://travis-ci.org/wesnoth/wesnoth/builds/37536345&lt;br /&gt;
***: 20141009 20:40:27-!- travis-ci [~travis-ci@ec2-184-73-55-78.compute-1.amazonaws.com] has left #wesnoth-dev []&lt;br /&gt;
*** clicking on the [http://i.imgur.com/mxwVKJP.png restart button]&lt;br /&gt;
** Do not disable unit tests without a very good reason!&lt;br /&gt;
* Few small commits are better than a big one (hard to review), so when possible split it in working parts with info about where you are going&lt;br /&gt;
* Be on #wesnoth-dev IRC channel and coordinate with other developers. Bots report commits and some devs may ask you a question about it.&lt;br /&gt;
* Don't forget changelogs: ''changelog'' for any (significant enough) changes and ''player_changelog'' for changes visible to users.&lt;br /&gt;
* Always check your changes before commit (see [[WesnothRepository#Reviewing your changes]]).&lt;br /&gt;
* Commit message:&lt;br /&gt;
** Mention any change, especially if some are unrelated to the main one (but you should use separated commits for this).&lt;br /&gt;
** Mention &amp;quot;bug #1234&amp;quot; for automatic cc to that gna bug number&lt;br /&gt;
** Mention a developer's IRC name will ping him on IRC (when the bot report it), and if he's not there, he may see it on the IRC logs&lt;br /&gt;
&lt;br /&gt;
== Bugs management ==&lt;br /&gt;
* Change status of fixed bugs to &amp;quot;Fixed&amp;quot; when committed&lt;br /&gt;
* Change status of fixed bugs to &amp;quot;Closed&amp;quot; when released, see [[ReportingBugs#Bug_protocol]] for details&lt;br /&gt;
* Check if there is new bugs relevant to your code and if any, assign them to you.&lt;br /&gt;
&lt;br /&gt;
== Dependencies ==&lt;br /&gt;
* Any change in dependencies to build the project must be discussed on the mailing list (dev-talk).&lt;br /&gt;
* Update SConstruct (and ideally cmake recipe also) to check for the dependency.&lt;br /&gt;
* Note any change (added or removed deps, or increased version requirements) in the RELEASE_NOTES file. These will be announced in the forum announcement and in the emails to packagers.&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* If you build with scons, use clang rather than gcc, as it is 2-3x faster to compile wesnoth.&lt;br /&gt;
Set your choice permanently with &lt;br /&gt;
&lt;br /&gt;
 scons cxxtool=clang++&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Project#Developers]]&lt;br /&gt;
* [[WesnothRepository]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Iceiceice</name></author>
		
	</entry>
</feed>