v0.6.1rc1
This commit is contained in:
parent
9b8c265f6f
commit
7299c63e74
51 changed files with 1660 additions and 676 deletions
198
MANUAL.norwegian
Normal file
198
MANUAL.norwegian
Normal file
|
@ -0,0 +1,198 @@
|
|||
Kontroller
|
||||
|
||||
|
||||
|
||||
* Piltaster: Panorer
|
||||
|
||||
* Venstreklikk: Velg enhet/flytt enhet
|
||||
|
||||
* Høyreklikk: Hovedmeny, avbryt handling
|
||||
|
||||
* Escape: Avslutt spill
|
||||
|
||||
* z: Zoom inn
|
||||
|
||||
* x: Zoom ut
|
||||
|
||||
* c: Standard zoom-nivå
|
||||
|
||||
* u: Angre siste trekk (bare deterministiske flytt kan omgjøres)
|
||||
|
||||
* r: Gjenta trekk
|
||||
|
||||
* n: Gå gjennom alle enheter som kan flytte
|
||||
|
||||
* l: Gå til lederenhet
|
||||
|
||||
* space: Avslutt runden for denne enheten, og gå videre til neste enhet som kan flytte
|
||||
|
||||
* ctrl-f: Bytt mellom fullskjerm- og vindumodus
|
||||
|
||||
* ctrl-r: Rekrutter enhet
|
||||
|
||||
* ctrl-c: Tilbakekall enhet
|
||||
|
||||
* ctrl-a: Skru på/av akselerert spillmodus
|
||||
|
||||
* d: Beskriv valgte enhet
|
||||
|
||||
* ctrl-d: Studer den valgte enhets motstand mot angrep
|
||||
|
||||
* ctrl-t: Studer hvordan den valgte enhet takler forskjellige typer terreng
|
||||
|
||||
* ctrl-s: Lagre spill
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Lyskuler
|
||||
|
||||
|
||||
|
||||
Hvordan kan jeg se om en enhet er venn eller fiende? På toppen av energiindikatoren som finnes ved siden av hver enhet er det en lyskule. Denne lyskulen forteller:
|
||||
|
||||
|
||||
|
||||
* grønn hvis du kontrollerer enheten og den ikke har flyttet denne runden
|
||||
|
||||
* gul hvis du kontrollerer enheten og den har flyttet denne runden, men fremdeles kan flytte videre
|
||||
|
||||
* rød hvis du kontrollerer denne enheten og den har brukt alle sine flytt denne runden
|
||||
|
||||
* blå hvis enheten tilhører en alliert, men ikke er kontrollert av deg
|
||||
|
||||
* svart hvis enheten er fiendtlig
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Spillbeskrivelse
|
||||
|
||||
|
||||
|
||||
Spillet skjer gjennom en serie kamper, eller scenario. Hvert scenario setter dine tropper opp mot en motstander. Hver side begynner med en leder i hver sin festning.
|
||||
|
||||
|
||||
|
||||
Gull
|
||||
|
||||
|
||||
|
||||
Hver side blir gitt et beløp gull i begynnelsen, og mottar så 2 gullstykker per runde, pluss 2 gullstykker for hver landsby som kontrolleres. Hver side må betale 1 gullstykke i underhold hver runde per enhet på slagmarken.
|
||||
|
||||
|
||||
|
||||
Rekruttering og tilbakekalling
|
||||
|
||||
|
||||
|
||||
Enheter kan rekrutteres for et gitt beløp, så lenge lederen er i sin festning, og det er minst en ledig plass i borgen der lederen befinner seg. Høyreklikk og velg Rekrutter for å rekruttere nye tropper.
|
||||
|
||||
|
||||
|
||||
Når du er ferdig med et scenario, vil alle enheter som har overlevd være tilgjengelige i neste scenario. Høyreklikk og velg Tilbakekall for å re-rekruttere enheter fra tidligere scenario. Tilbakekalling koster 20 gullstykker.
|
||||
|
||||
|
||||
|
||||
Du kan først velge en ledig plass i borgen og så rekruttere. Slik kan du velge på hvilken plass den nyrekrutterte enheten skal dukke opp. Dette virker både for rekruttering og tilbakekalling.
|
||||
|
||||
|
||||
|
||||
Enhetsspesialiteter
|
||||
|
||||
|
||||
|
||||
Enhetsspesialiteter er beskrevet under Beskrivelse i hovedmenyen.
|
||||
|
||||
|
||||
|
||||
Flytting
|
||||
|
||||
|
||||
|
||||
Når en enhet blir valgt (ved venstreklikk), lyser alle plassene den kan bevege seg opp, mens stedene den ikke kan bevege seg til er grå. Du kan så klikke på den neste plassen du vil flytte enheten til. Hvis du flytter til en landsby som enten er nøytral eller kontrollert av en motstander, vil du ta kontroll over den. Hvis du velger å gå et sted du ikke kan nå denne runden, vil enheten gå over i 'gå-til' modus og fortsette mot sin destinasjon hver runde. Du kan angre gå-til flytt i begynnelsen av din runde. Gå-til modus kan avsluttes ved å velge enheten og så velge en ny destinasjon.
|
||||
|
||||
|
||||
|
||||
Kamp
|
||||
|
||||
|
||||
|
||||
Hvis du flytter ved siden av en motstander, kan du angripe. Klikk på enheten din som er ved siden av en motstander, og klikk så på motstanderen du ønsker å angripe. Hver enhet har ett eller flere våpen de kan angripe med. Noen våpen, for eksempel sverd, er nærkampvåpen, mens andre, for eksempel buer, er avstandsvåpen.
|
||||
|
||||
|
||||
|
||||
Hvis du velger nærkamp, vil fienden kunne slå tilbake med sitt nærkampvåpen. Hvis du angriper med et avstandsvåpen, vil fienden eventuelt kunne slå tilbake med sitt avstandsvåpen, hvis han har et i sitt arsenal.
|
||||
|
||||
|
||||
|
||||
Forskjellige typer angrep gjør forskjellig grad av skade, og et visst antall utfall kan gjøres med hvert våpen. For eksempel gjør en Alvisk Kriger 5 poeng skade med sitt sverd hver gang han treffer, og han kan gjøre 4 utfall med sverdet i et angrep. Dette blir betegnet med 5-4.
|
||||
|
||||
|
||||
|
||||
Hver enhet har en viss sjanse for å bli truffet, basert på hvilken type terreng de er i. Enheter i landsbyer og i borger har lavere sjanse for å bli truffet. Alver i skog har liten sjanse for å bli truffet.
|
||||
|
||||
|
||||
|
||||
Holdning
|
||||
|
||||
|
||||
|
||||
Hver enhet har en holdning: lovlydig, nøytral eller kaotisk. Holdningen har betydning for hvordan de presterer til forskjellige tider av dagen. Den følgende tabellen illustrerer dagens forskjellige tider:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
| runde | tid |
|
||||
|
||||
-------------------------
|
||||
|
||||
| 1 | morgengry |
|
||||
|
||||
| 2 | formiddag |
|
||||
|
||||
| 3 | ettermiddag |
|
||||
|
||||
| 4 | skumring |
|
||||
|
||||
| 5 | kveld |
|
||||
|
||||
| 6 | natt |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Lovlydige enheter gjør 25% mer skade om dagen, og 25% mindre om natten. Kaotiske enheter gjør 25% mer skade om natten, og 25% mindre om dagen. Nøytrale enheter blir ikke påvirket av dag/natt syklusen.
|
||||
|
||||
|
||||
|
||||
Helbredelse
|
||||
|
||||
|
||||
|
||||
Skadde enheter i landsbyer vil heles 8 livspoeng hver runde. Skadde enheter ved siden av enheter med 'helbrede' eller 'kurere' egenskaper vil også bli helbredet. Enheter ved siden av enheter som har 'helbrede' som egenskap vil heles maksimum 4 livspoeng per runde, og 8 livspoeng per runde for enheter som har 'kurere' som egenskap. Jo flere enheter det er rundt en helbredende enhet, jo mindre vil hver bli helbredet.
|
||||
|
||||
|
||||
|
||||
Erfaring
|
||||
|
||||
|
||||
|
||||
Enheter får erfaring gjennom kamp, og ved å oppnå nok erfaring vil de avansere et nivå, og dermed bli mektigere.
|
||||
|
||||
|
||||
|
||||
/* $Id$ */
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
AUTOMAKE_OPTIONS = foreign
|
||||
SUBDIRS = src
|
||||
pkgdatadir=$(datadir)/@DATADIR@
|
||||
|
||||
dist_noinst_DATA = @MANUAL_FILES@ copyright changelog @UTIL_FILES@
|
||||
nobase_dist_pkgdata_DATA = @DATA_FILES@ @FONT_FILES@ @IMAGE_FILES@ @MUSIC_FILES@ @SOUND_FILES@
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = .
|
||||
|
@ -35,6 +34,7 @@ POST_INSTALL = :
|
|||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
pkgdatadir = $(datadir)/@DATADIR@
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
|
@ -52,6 +52,7 @@ CXX = @CXX@
|
|||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DATADIR = @DATADIR@
|
||||
DATA_FILES = @DATA_FILES@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
Version 0.6.1:
|
||||
* fixed bug causing crash on scenario completion
|
||||
* fixed 'Storm Trident' mislocation on 'Bay of Pearls'
|
||||
* fixed resetting player starting gold, gold per village, player race, and player type when loading multiplayer game
|
||||
* change to the way images are handled to fix resizing (and other potential) bugs
|
||||
* enabled changing datadir name with ./configure
|
||||
* code cleanups
|
||||
|
||||
Version 0.6:
|
||||
* radical storyline changes, this breaks saves from older versions
|
||||
* fog of war
|
||||
|
|
25
config.h.in
25
config.h.in
|
@ -15,11 +15,6 @@
|
|||
header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/*
|
||||
Define to 1 if you have the `SDL'
|
||||
library (-lSDL). */
|
||||
#undef HAVE_LIBSDL
|
||||
|
||||
/*
|
||||
Define to 1 if you have the <memory.h>
|
||||
header file. */
|
||||
|
@ -30,26 +25,6 @@
|
|||
header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/*
|
||||
Define to 1 if you have the <SDL_image.h>
|
||||
header file. */
|
||||
#undef HAVE_SDL_IMAGE_H
|
||||
|
||||
/*
|
||||
Define to 1 if you have the <SDL_mixer.h>
|
||||
header file. */
|
||||
#undef HAVE_SDL_MIXER_H
|
||||
|
||||
/*
|
||||
Define to 1 if you have the <SDL_net.h>
|
||||
header file. */
|
||||
#undef HAVE_SDL_NET_H
|
||||
|
||||
/*
|
||||
Define to 1 if you have the <SDL_ttf.h>
|
||||
header file. */
|
||||
#undef HAVE_SDL_TTF_H
|
||||
|
||||
/*
|
||||
Define to 1 if you have the `socket'
|
||||
function. */
|
||||
|
|
91
configure.ac
91
configure.ac
|
@ -1,13 +1,13 @@
|
|||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT(wesnoth, 0.5, davidnwhite@optusnet.com.au, Battle for Wesnoth)
|
||||
AC_INIT(wesnoth, 0.7, davidnwhite@optusnet.com.au, Battle for Wesnoth)
|
||||
|
||||
AC_REVISION($Version: 0.5$)
|
||||
AC_REVISION($Version: 0.7$)
|
||||
PACKAGE=wesnoth
|
||||
MAJOR_VERSION="0"
|
||||
MINOR_VERSION="6"
|
||||
MICRO_VERSION=""
|
||||
MICRO_VERSION="1RC1"
|
||||
|
||||
if test "x$MICRO_VERSION" = "x"; then
|
||||
VERSION=$MAJOR_VERSION.$MINOR_VERSION
|
||||
|
@ -40,14 +40,37 @@ fi
|
|||
SDL_LIBS=`$SDL_CONFIG --libs`
|
||||
OLD_LIBS=$LIBS
|
||||
LIBS="$LIBS $SDL_LIBS"
|
||||
AC_CHECK_LIB([SDL], [SDL_Init])
|
||||
AC_CHECK_LIB([SDL_image], [IMG_Load], SDL_IMAGE_LIBS=-lSDL_image)
|
||||
AC_CHECK_LIB([SDL_mixer], [Mix_OpenAudio], SDL_MIXER_LIBS=-lSDL_mixer)
|
||||
AC_CHECK_LIB([SDL_net], [SDLNet_Init], SDL_NET_LIBS=-lSDL_net)
|
||||
AC_CHECK_LIB([SDL_ttf], [TTF_OpenFont], SDL_TTF_LIBS=-lSDL_ttf)
|
||||
|
||||
# There's no need for this, $SDL_CONFIG comes with libsdl and
|
||||
# it doesn't find it in FreeBSD
|
||||
# AC_CHECK_LIB([SDL], [SDL_Init])
|
||||
|
||||
AC_CHECK_LIB([SDL_image],
|
||||
[IMG_Load],
|
||||
[SDL_IMAGE_LIBS=-lSDL_image],
|
||||
[AC_MSG_ERROR([*** SDL_image lib not found! Get SDL_image from
|
||||
http://www.libsdl.org/projects/SDL_image/index.html])])
|
||||
|
||||
AC_CHECK_LIB([SDL_mixer],
|
||||
[Mix_OpenAudio],
|
||||
[SDL_MIXER_LIBS=-lSDL_mixer],
|
||||
[AC_MSG_ERROR([*** SDL_mixer lib not found! Get SDL_mixer from
|
||||
http://www.libsdl.org/projects/SDL_mixer/index.html])])
|
||||
|
||||
AC_CHECK_LIB([SDL_net],
|
||||
[SDLNet_Init],
|
||||
[SDL_NET_LIBS=-lSDL_net],
|
||||
[AC_MSG_ERROR([*** SDL_net lib not found! Get SDL_net from
|
||||
http://www.libsdl.org/projects/SDL_net/index.html])])
|
||||
|
||||
AC_CHECK_LIB([SDL_ttf],
|
||||
[TTF_OpenFont],
|
||||
[SDL_TTF_LIBS=-lSDL_ttf],
|
||||
[AC_MSG_ERROR([*** SDL_ttf lib not found! Get SDL_ttf from
|
||||
http://www.libsdl.org/projects/SDL_ttf/index.html])])
|
||||
|
||||
LIBS=$OLD_LIBS
|
||||
|
||||
echo "$SDL_LIBS"
|
||||
AC_SUBST([SDL_LIBS])
|
||||
AC_SUBST([SDL_IMAGE_LIBS])
|
||||
AC_SUBST([SDL_MIXER_LIBS])
|
||||
|
@ -65,13 +88,39 @@ SDL_CFLAGS=`$SDL_CONFIG --cflags`
|
|||
CPPFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
CXXFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
|
||||
AC_CHECK_HEADERS([stdlib.h unistd.h SDL_image.h SDL_mixer.h SDL_net.h SDL_ttf.h])
|
||||
|
||||
|
||||
AC_CHECK_HEADER([SDL.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([*** SDL include files not found!
|
||||
You should install SDL development package.])])
|
||||
|
||||
AC_CHECK_HEADER([SDL_image.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([*** SDL_image include files not found!
|
||||
You should install development package.])])
|
||||
|
||||
AC_CHECK_HEADER([SDL_mixer.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([*** SDL_mixer include files not found!
|
||||
You should install development package.])])
|
||||
|
||||
AC_CHECK_HEADER([SDL_net.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([*** SDL_net include files not found!
|
||||
You should install development package.])])
|
||||
|
||||
AC_CHECK_HEADER([SDL_ttf.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([*** SDL_ttf include files not found!
|
||||
You should install development package.])])
|
||||
|
||||
CPPFLAGS=$OLD_CPPFLAGS
|
||||
CXXFLAGS=$OLD_CXXFLAGS
|
||||
|
||||
AC_SUBST([SDL_CFLAGS])
|
||||
|
||||
AC_CHECK_HEADERS([stdlib.h unistd.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_HEADER_STDBOOL
|
||||
AC_C_CONST
|
||||
|
@ -86,14 +135,26 @@ AC_FUNC_STAT
|
|||
AC_FUNC_STRFTIME
|
||||
AC_CHECK_FUNCS([floor socket strtoul])
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --debug Enable debug in wesnoth],
|
||||
CXXFLAGS="$CXXFLAGS -DDEBUG -ggdb3")
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --enable-debug Enable debug in wesnoth],
|
||||
CXXFLAGS="$CXXFLAGS -DDEBUG -ggdb3")
|
||||
|
||||
AC_ARG_ENABLE(datadir-name,
|
||||
[ --datadir-name[[=dir]] Change name of data directory. Default with this option: wesnoth-data],
|
||||
[case "${enableval}" in
|
||||
yes)
|
||||
DATADIR="wesnoth-data"
|
||||
;;
|
||||
no)
|
||||
DATADIR=$PACKAGE
|
||||
;;
|
||||
*)
|
||||
DATADIR="${enableval}"
|
||||
;;
|
||||
esac])
|
||||
|
||||
AC_SUBST(DATADIR)
|
||||
|
||||
# Default behaviour
|
||||
server=no
|
||||
editor=no
|
||||
|
|
|
@ -6,6 +6,14 @@
|
|||
id=Crossroads
|
||||
next_scenario=The_Princess_of_Wesnoth
|
||||
|
||||
scenario_objectives="
|
||||
Victory:
|
||||
@Defeat both enemy leaders
|
||||
Defeat
|
||||
#Death of Konrad
|
||||
#Death of Delfador
|
||||
#Death of Kalenz"
|
||||
|
||||
[bigmap]
|
||||
image=misc/map.png
|
||||
{DOT 128 297}
|
||||
|
@ -241,4 +249,6 @@
|
|||
{TRAP1 17 25 2}
|
||||
{TRAP2 21 29 3}
|
||||
|
||||
{deaths.cfg}
|
||||
|
||||
[/scenario]
|
||||
|
|
|
@ -31,7 +31,7 @@ Defeat:
|
|||
canrecruit=1
|
||||
controller=human
|
||||
recruit= Dark Adept,Ghost,Walking Corpse,Skeleton,Skeleton Archer
|
||||
enemy=2
|
||||
enemy=2,3,4
|
||||
gold=120
|
||||
[/side]
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ advanceto=null
|
|||
cost=80
|
||||
ability=ambush
|
||||
usage=scout
|
||||
unit_description="Extremely skillful and extremely quick, the Elvish Avenger is powerful in all forms of combat. The avenger is considered the best of all woodmen in Wesnoth. Able to see well at night with his keen eyes, the Elvish Avenger does not suffer any penalty when fighting at night."
|
||||
unit_description="Extremely skillful and extremely quick, the Elvish Avenger is powerful in all forms of combat. The avenger is considered the best of all woodmen in Wesnoth. He cannot ambush his foes in the forest: he cannot be seen when in the woods, until after he has just attacked."
|
||||
get_hit_sound=groan.wav
|
||||
[attack]
|
||||
name=sword
|
||||
|
|
|
@ -12,7 +12,7 @@ advanceto=Elvish Avenger
|
|||
cost=40
|
||||
usage=scout
|
||||
ability=ambush
|
||||
unit_description="The Elvish Ranger is quick and powerful. Skilled in both short and long range combat, the ranger is truly and all-round fighter. Able to see well at night with his keen eyes, the Ranger does not suffer the combat penalties at night that other lawful units do."
|
||||
unit_description="The Elvish Ranger is quick and powerful. Skilled in both short and long range combat, the ranger is truly and all-round fighter. The best of all woodmen, the ranger cannot be seen by enemies while he is in forest, unless he has just attacked."
|
||||
get_hit_sound=groan.wav
|
||||
[attack]
|
||||
name=sword
|
||||
|
|
|
@ -13,6 +13,7 @@ endif
|
|||
SUBDIRS = . $(SSUBDIRS) $(TSUBDIRS)
|
||||
bin_PROGRAMS = wesnoth $(EPROGRAMS)
|
||||
|
||||
pkgdatadir=$(datadir)/@DATADIR@
|
||||
AM_CXXFLAGS = @SDL_CFLAGS@ -DWESNOTH_PATH=\"$(pkgdatadir)\"
|
||||
AM_LDFLAGS = @SDL_LIBS@ @SDL_IMAGE_LIBS@ @SDL_MIXER_LIBS@ @SDL_NET_LIBS@ @SDL_TTF_LIBS@
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ..
|
||||
|
@ -35,6 +34,8 @@ POST_INSTALL = :
|
|||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
|
||||
pkgdatadir = $(datadir)/@DATADIR@
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
|
@ -52,6 +53,7 @@ CXX = @CXX@
|
|||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DATADIR = @DATADIR@
|
||||
DATA_FILES = @DATA_FILES@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
|
@ -137,7 +139,6 @@ target_alias = @target_alias@
|
|||
|
||||
SUBDIRS = . $(SSUBDIRS) $(TSUBDIRS)
|
||||
bin_PROGRAMS = wesnoth $(EPROGRAMS)
|
||||
|
||||
AM_CXXFLAGS = @SDL_CFLAGS@ -DWESNOTH_PATH=\"$(pkgdatadir)\"
|
||||
AM_LDFLAGS = @SDL_LIBS@ @SDL_IMAGE_LIBS@ @SDL_MIXER_LIBS@ @SDL_NET_LIBS@ @SDL_TTF_LIBS@
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void show_about(display& disp)
|
|||
0,0,0,1.0,disp.video().getSurface());
|
||||
update_whole_screen();
|
||||
|
||||
SDL_Surface* const map_image = image::get_image("misc/map.png",image::UNSCALED);
|
||||
const scoped_sdl_surface map_image(image::get_image("misc/map.png",image::UNSCALED));
|
||||
SDL_Rect map_rect;
|
||||
map_rect.x = disp.x()/2 - map_image->w/2;
|
||||
map_rect.y = disp.y()/2 - map_image->h/2;
|
||||
|
|
|
@ -31,11 +31,16 @@ bool operator<(const line_source& a, const line_source& b)
|
|||
|
||||
namespace {
|
||||
|
||||
bool isnewline(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n';
|
||||
}
|
||||
|
||||
//make sure that we can use Mac, DOS, or Unix style text files on any system
|
||||
//and they will work, by making sure the definition of whitespace is consistent
|
||||
bool portable_isspace(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n' || isspace(c);
|
||||
return isnewline(c) || isspace(c);
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,7 +202,7 @@ void internal_preprocess_data(const std::string& data,
|
|||
|
||||
i = std::find_if(i,data.end(),isgraph);
|
||||
|
||||
const std::string::const_iterator end = std::find(i,data.end(),'\n');
|
||||
const std::string::const_iterator end = std::find_if(i,data.end(),isnewline);
|
||||
|
||||
if(end == data.end())
|
||||
break;
|
||||
|
@ -251,7 +256,7 @@ void internal_preprocess_data(const std::string& data,
|
|||
++i;
|
||||
}
|
||||
|
||||
i = std::find(i,data.end(),'\n');
|
||||
i = std::find_if(i,data.end(),isnewline);
|
||||
if(i == data.end())
|
||||
break;
|
||||
} else {
|
||||
|
@ -268,13 +273,12 @@ void internal_preprocess_data(const std::string& data,
|
|||
++i;
|
||||
}
|
||||
|
||||
i = std::find(i,data.end(),'\n');
|
||||
i = std::find_if(i,data.end(),isnewline);
|
||||
if(i == data.end())
|
||||
break;
|
||||
}
|
||||
|
||||
for(; i != data.end() && *i != '\n'; ++i) {
|
||||
}
|
||||
i = std::find_if(i,data.end(),isnewline);
|
||||
|
||||
if(i == data.end())
|
||||
break;
|
||||
|
@ -605,6 +609,13 @@ config& config::add_child(const std::string& key)
|
|||
return *v.back();
|
||||
}
|
||||
|
||||
config& config::add_child(const std::string& key, const config& val)
|
||||
{
|
||||
std::vector<config*>& v = children[key];
|
||||
v.push_back(new config(val));
|
||||
return *v.back();
|
||||
}
|
||||
|
||||
std::string& config::operator[](const std::string& key)
|
||||
{
|
||||
return values[key];
|
||||
|
@ -666,6 +677,7 @@ std::vector<std::string> config::split(const std::string& val, char c)
|
|||
while(i2 != val.end()) {
|
||||
if(*i2 == c) {
|
||||
std::string new_val(i1,i2);
|
||||
strip(new_val);
|
||||
if(!new_val.empty())
|
||||
res.push_back(new_val);
|
||||
++i2;
|
||||
|
@ -679,6 +691,7 @@ std::vector<std::string> config::split(const std::string& val, char c)
|
|||
}
|
||||
|
||||
std::string new_val(i1,i2);
|
||||
strip(new_val);
|
||||
if(!new_val.empty())
|
||||
res.push_back(new_val);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -92,12 +93,6 @@ struct config
|
|||
typedef std::vector<config*> child_list;
|
||||
typedef std::map<std::string,child_list> child_map;
|
||||
|
||||
//a list of all children of this node.
|
||||
child_map children;
|
||||
|
||||
//all the attributes of this node.
|
||||
string_map values;
|
||||
|
||||
typedef std::vector<config*>::iterator child_iterator;
|
||||
typedef std::vector<config*>::const_iterator const_child_iterator;
|
||||
|
||||
|
@ -113,6 +108,7 @@ struct config
|
|||
config* child(const std::string& key);
|
||||
const config* child(const std::string& key) const;
|
||||
config& add_child(const std::string& key);
|
||||
config& add_child(const std::string& key, const config& val);
|
||||
std::string& operator[](const std::string& key);
|
||||
const std::string& operator[](const std::string& key) const;
|
||||
|
||||
|
@ -121,6 +117,13 @@ struct config
|
|||
const config* find_child(const std::string& key, const std::string& name,
|
||||
const std::string& value) const;
|
||||
|
||||
void clear_children(const std::string& key) { children.erase(key); }
|
||||
void remove_child(const std::string& key, size_t index) {
|
||||
child_list& v = children[key];
|
||||
assert(index < v.size());
|
||||
v.erase(v.begin()+index);
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(const std::string& val, char c=',');
|
||||
static std::string& strip(std::string& str);
|
||||
static bool has_value(const std::string& values, const std::string& val);
|
||||
|
@ -131,6 +134,12 @@ struct config
|
|||
error(const std::string& msg) : message(msg) {}
|
||||
std::string message;
|
||||
};
|
||||
|
||||
//all the attributes of this node.
|
||||
string_map values;
|
||||
|
||||
//a list of all children of this node.
|
||||
child_map children;
|
||||
};
|
||||
|
||||
struct config_has_value {
|
||||
|
|
|
@ -91,14 +91,14 @@ void advance_unit(const game_data& info,
|
|||
void show_objectives(display& disp, config& level_info)
|
||||
{
|
||||
static const std::string no_objectives(string_table["no_objectives"]);
|
||||
const std::string& id = level_info.values["id"];
|
||||
const std::string& id = level_info["id"];
|
||||
const std::string& lang_name = string_table[id];
|
||||
const std::string& name = lang_name.empty() ? level_info.values["name"] :
|
||||
const std::string& name = lang_name.empty() ? level_info["name"] :
|
||||
lang_name;
|
||||
const std::string& lang_objectives = string_table[id + "_objectives"];
|
||||
|
||||
const std::string& objectives = lang_objectives.empty() ?
|
||||
level_info.values["objectives"] : lang_objectives;
|
||||
level_info["objectives"] : lang_objectives;
|
||||
gui::show_dialog(disp, NULL, "", "+" + name + "\n" +
|
||||
(objectives.empty() ? no_objectives : objectives), gui::OK_ONLY);
|
||||
|
||||
|
|
|
@ -424,12 +424,10 @@ void display::draw(bool update,bool force)
|
|||
{
|
||||
if(!sideBarBgDrawn_ && !teams_.empty()) {
|
||||
SDL_Surface* const screen = screen_.getSurface();
|
||||
SDL_Surface* image_top = image::get_image(RightSideTop,image::UNSCALED);
|
||||
const scoped_sdl_surface image_top(image::get_image(RightSideTop,image::UNSCALED));
|
||||
|
||||
|
||||
SDL_Surface* image = image_top != NULL ?
|
||||
image::get_image_dim(RightSideBot,image_top->w,screen->h-image_top->h)
|
||||
: NULL;
|
||||
const scoped_sdl_surface image(image_top != NULL ?
|
||||
image::get_image_dim(RightSideBot,image_top->w,screen->h-image_top->h) : NULL);
|
||||
if(image_top != NULL && image != NULL && image_top->h < screen->h) {
|
||||
|
||||
SDL_Rect dstrect;
|
||||
|
@ -545,7 +543,7 @@ void display::draw_game_status(int x, int y)
|
|||
|
||||
const time_of_day& tod = timeofday_at(status_,units_,mouseoverHex_);
|
||||
|
||||
SDL_Surface* const tod_surface = image::get_image(tod.image,image::UNSCALED);
|
||||
const scoped_sdl_surface tod_surface(image::get_image(tod.image,image::UNSCALED));
|
||||
|
||||
if(tod_surface != NULL) {
|
||||
//hardcoded values as to where the time of day image appears
|
||||
|
@ -555,7 +553,7 @@ void display::draw_game_status(int x, int y)
|
|||
|
||||
if(gameStatusRect_.w > 0) {
|
||||
SDL_Surface* const screen = screen_.getSurface();
|
||||
SDL_Surface* const background = image::get_image(RightSideTop,image::UNSCALED);
|
||||
const scoped_sdl_surface background(image::get_image(RightSideTop,image::UNSCALED));
|
||||
|
||||
if(background == NULL)
|
||||
return;
|
||||
|
@ -655,8 +653,8 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
|
||||
SDL_Rect clipRect = clip_rect != NULL ? *clip_rect : screen_area();
|
||||
|
||||
SDL_Surface* const background = image::get_image(RightSideTop,image::UNSCALED);
|
||||
SDL_Surface* const background_bot = image::get_image(RightSideBot,image::UNSCALED);
|
||||
const scoped_sdl_surface background(image::get_image(RightSideTop,image::UNSCALED));
|
||||
const scoped_sdl_surface background_bot(image::get_image(RightSideBot,image::UNSCALED));
|
||||
|
||||
if(background == NULL || background_bot == NULL)
|
||||
return;
|
||||
|
@ -749,7 +747,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
|
||||
y += description_rect.h;
|
||||
|
||||
SDL_Surface* const profile = image::get_image(u.type().image(),image::UNSCALED);
|
||||
const scoped_sdl_surface profile(image::get_image(u.type().image(),image::UNSCALED));
|
||||
|
||||
if(profile == NULL)
|
||||
return;
|
||||
|
@ -771,7 +769,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
|
||||
void display::draw_minimap(int x, int y, int w, int h)
|
||||
{
|
||||
SDL_Surface* const surface = getMinimap(w,h);
|
||||
const scoped_sdl_surface surface(getMinimap(w,h));
|
||||
if(surface == NULL)
|
||||
return;
|
||||
|
||||
|
@ -814,7 +812,7 @@ void display::draw_terrain_palette(int x, int y, gamemap::TERRAIN selected)
|
|||
std::vector<gamemap::TERRAIN> terrains = map_.get_terrain_precedence();
|
||||
for(std::vector<gamemap::TERRAIN>::const_iterator i = terrains.begin();
|
||||
i != terrains.end(); ++i) {
|
||||
SDL_Surface* const image = getTerrain(*i,image::SCALED,-1,-1);
|
||||
const scoped_sdl_surface image(getTerrain(*i,image::SCALED,-1,-1));
|
||||
if(image == NULL) {
|
||||
std::cerr << "image for terrain '" << *i << "' not found\n";
|
||||
return;
|
||||
|
@ -865,7 +863,7 @@ gamemap::TERRAIN display::get_terrain_on(int palx, int paly, int x, int y)
|
|||
return terrains[index];
|
||||
}
|
||||
|
||||
void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
||||
void display::draw_tile(int x, int y, SDL_Surface* unit_image_override,
|
||||
double highlight_ratio, Pixel blend_with)
|
||||
|
||||
{
|
||||
|
@ -922,7 +920,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
image_type = image::BRIGHTENED;
|
||||
}
|
||||
|
||||
SDL_Surface* surface = getTerrain(terrain,image_type,x,y);
|
||||
const scoped_sdl_surface surface(getTerrain(terrain,image_type,x,y));
|
||||
|
||||
if(surface == NULL) {
|
||||
std::cerr << "Could not get terrain surface\n";
|
||||
|
@ -931,8 +929,10 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
|
||||
std::vector<SDL_Surface*> overlaps;
|
||||
|
||||
scoped_sdl_surface flag(NULL);
|
||||
|
||||
if(!is_shrouded) {
|
||||
SDL_Surface* const flag = getFlag(terrain,x,y);
|
||||
flag.assign(getFlag(terrain,x,y));
|
||||
if(flag != NULL)
|
||||
overlaps.push_back(flag);
|
||||
|
||||
|
@ -946,8 +946,12 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
for(std::pair<Itor,Itor> overlays =
|
||||
overlays_.equal_range(gamemap::location(x,y));
|
||||
overlays.first != overlays.second; ++overlays.first) {
|
||||
SDL_Surface* const overlay_surface =
|
||||
image::get_image(overlays.first->second);
|
||||
|
||||
//event though the scoped surface will fall out-of-scope and call
|
||||
//SDL_FreeSurface on the underlying surface, the surface will remain
|
||||
//valid so long as the image cache isn't invalidated, which should not
|
||||
//happen inside this function
|
||||
const scoped_sdl_surface overlay_surface(image::get_image(overlays.first->second));
|
||||
|
||||
if(overlay_surface != NULL) {
|
||||
overlaps.push_back(overlay_surface);
|
||||
|
@ -977,8 +981,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
|
||||
update_rect(xpos,ypos,xend-xpos,yend-ypos);
|
||||
|
||||
SDL_Surface* energy_image = NULL;
|
||||
|
||||
double unit_energy = 0.0;
|
||||
|
||||
const short energy_loss_colour = 0;
|
||||
|
@ -988,11 +990,18 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
double energy_size = 1.0;
|
||||
bool face_left = true;
|
||||
|
||||
if(unit_image_override != NULL)
|
||||
sdl_add_ref(unit_image_override);
|
||||
|
||||
scoped_sdl_surface unit_image(unit_image_override);
|
||||
scoped_sdl_surface energy_image(NULL);
|
||||
|
||||
//see if there is a unit on this tile
|
||||
const unit_map::const_iterator it = units_.find(gamemap::location(x,y));
|
||||
if(it != units_.end()) {
|
||||
if(unit_image == NULL)
|
||||
unit_image = image::get_image(it->second.image());
|
||||
unit_image.assign(image::get_image(it->second.image()));
|
||||
|
||||
const int unit_move = it->second.movement_left();
|
||||
const int unit_total_move = it->second.total_movement();
|
||||
|
||||
|
@ -1015,7 +1024,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
}
|
||||
}
|
||||
|
||||
energy_image = image::get_image(energy_file);
|
||||
energy_image.assign(image::get_image(energy_file));
|
||||
unit_energy = double(it->second.hitpoints()) /
|
||||
double(it->second.max_hitpoints());
|
||||
|
||||
|
@ -1186,7 +1195,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
}
|
||||
|
||||
if(game_config::debug && debugHighlights_.count(gamemap::location(x,y))) {
|
||||
SDL_Surface* const cross = image::get_image("cross.png");
|
||||
const scoped_sdl_surface cross(image::get_image("cross.png"));
|
||||
if(cross != NULL)
|
||||
draw_unit(xpos-xsrc,ypos-ysrc,cross,face_left,false,
|
||||
debugHighlights_[loc],0);
|
||||
|
@ -1330,7 +1339,7 @@ void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
|
|||
}
|
||||
}
|
||||
|
||||
SDL_Surface* const image = image::get_image(*image_str);
|
||||
const scoped_sdl_surface image(image::get_image(*image_str));
|
||||
if(image == NULL) {
|
||||
std::cerr << "Could not find image: " << *image_str << "\n";
|
||||
return;
|
||||
|
@ -1424,8 +1433,8 @@ std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
|
|||
std::ostringstream stream;
|
||||
for(int n = 0; tiles[i] == *terrain && n!=6; i = (i+1)%6, ++n) {
|
||||
stream << get_direction(i);
|
||||
SDL_Surface* const new_surface = getTerrain(
|
||||
*terrain,image_type,x,y,stream.str());
|
||||
const scoped_sdl_surface new_surface(getTerrain(
|
||||
*terrain,image_type,x,y,stream.str()));
|
||||
|
||||
if(new_surface == NULL) {
|
||||
//if we don't have any surface at all,
|
||||
|
@ -1466,6 +1475,7 @@ SDL_Surface* display::getTerrain(gamemap::TERRAIN terrain,image::TYPE image_type
|
|||
const time_of_day& tod = status_.get_time_of_day();
|
||||
const std::string tod_image = image + "-" + tod.id + ".png";
|
||||
SDL_Surface* const im = image::get_image(tod_image,image_type);
|
||||
|
||||
if(im != NULL) {
|
||||
return im;
|
||||
}
|
||||
|
@ -1554,6 +1564,7 @@ SDL_Surface* display::getMinimap(int w, int h)
|
|||
if(minimap_ == NULL)
|
||||
minimap_ = image::getMinimap(w,h,map_,team_valid() ? &teams_[currentTeam_] : NULL);
|
||||
|
||||
sdl_add_ref(minimap_);
|
||||
return minimap_;
|
||||
}
|
||||
|
||||
|
@ -1750,7 +1761,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
missile_image = &default_diag_missile;
|
||||
}
|
||||
|
||||
SDL_Surface* const img = image::get_image(*missile_image);
|
||||
const scoped_sdl_surface img(image::get_image(*missile_image));
|
||||
if(img != NULL) {
|
||||
double pos = double(missile_impact - i)/double(missile_impact);
|
||||
if(pos < 0.0)
|
||||
|
@ -1964,8 +1975,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
if(unit_image == NULL)
|
||||
unit_image = &attacker.image();
|
||||
|
||||
SDL_Surface* const image = (unit_image == NULL) ?
|
||||
NULL : image::get_image(*unit_image);
|
||||
const scoped_sdl_surface image((unit_image == NULL) ? NULL : image::get_image(*unit_image));
|
||||
|
||||
const double pos = double(i)/double(i < 0 ? begin_at : end_at);
|
||||
const int posx = int(pos*xsrc + (1.0-pos)*xdst) + xoffset;
|
||||
|
@ -2023,9 +2033,7 @@ void display::move_unit_between(const gamemap::location& a,
|
|||
for(double i = 0.0; i < nsteps; i += 1.0) {
|
||||
events::pump();
|
||||
|
||||
//checking keys may have invalidated all images (if they have
|
||||
//zoomed in or out), so reget the image here
|
||||
SDL_Surface* const image = image::get_image(u.type().image());
|
||||
const scoped_sdl_surface image(image::get_image(u.type().image()));
|
||||
if(image == NULL) {
|
||||
std::cerr << "failed to get image " << u.type().image() << "\n";
|
||||
return;
|
||||
|
@ -2222,7 +2230,7 @@ const std::pair<int,int>& display::calculate_energy_bar()
|
|||
int first_row = -1;
|
||||
int last_row = -1;
|
||||
|
||||
SDL_Surface* const image = image::get_image("unmoved-energy.png");
|
||||
const scoped_sdl_surface image(image::get_image("unmoved-energy.png"));
|
||||
|
||||
surface_lock image_lock(image);
|
||||
const short* const begin = image_lock.pixels();
|
||||
|
|
|
@ -278,11 +278,15 @@ private:
|
|||
void bounds_check_position();
|
||||
|
||||
std::vector<SDL_Surface*> getAdjacentTerrain(int x, int y, image::TYPE type);
|
||||
|
||||
//this surface must be freed by the caller
|
||||
SDL_Surface* getTerrain(gamemap::TERRAIN, image::TYPE type,
|
||||
int x, int y, const std::string& dir="");
|
||||
|
||||
//this surface must be freed by the caller
|
||||
SDL_Surface* getFlag(gamemap::TERRAIN, int x, int y);
|
||||
|
||||
//this surface must be freed by the caller
|
||||
SDL_Surface* getMinimap(int w, int h);
|
||||
|
||||
void clearImageCache();
|
||||
|
|
|
@ -251,11 +251,10 @@ void drawbar(display& disp)
|
|||
const std::string RightSideBot = "misc/rightside-bottom.png";
|
||||
const std::string RightSideTop = "misc/rightside-editor.png";
|
||||
SDL_Surface* const screen = disp.video().getSurface();
|
||||
SDL_Surface* image_top = image::get_image(RightSideTop,image::UNSCALED);
|
||||
const scoped_sdl_surface image_top(image::get_image(RightSideTop,image::UNSCALED));
|
||||
|
||||
SDL_Surface* image = image_top != NULL ?
|
||||
image::get_image_dim(RightSideBot,image_top->w,screen->h-image_top->h)
|
||||
: NULL;
|
||||
const scoped_sdl_surface image(image_top != NULL ?
|
||||
image::get_image_dim(RightSideBot,image_top->w,screen->h-image_top->h) : NULL);
|
||||
if(image_top != NULL && image != NULL && image_top->h < screen->h) {
|
||||
SDL_Rect dstrect;
|
||||
dstrect.x = disp.mapx();
|
||||
|
@ -309,7 +308,7 @@ bool drawterrainpalette(display& disp, int start, gamemap::TERRAIN selected, gam
|
|||
|
||||
for(int counter = starting; counter < ending; counter++){
|
||||
const gamemap::TERRAIN terrain = terrains[counter];
|
||||
SDL_Surface* const image = image::get_image("terrain/" + map.get_terrain_info(terrain).default_image() + ".png");
|
||||
const scoped_sdl_surface image(image::get_image("terrain/" + map.get_terrain_info(terrain).default_image() + ".png"));
|
||||
|
||||
if(image == NULL) {
|
||||
std::cerr << "image for terrain '" << counter << "' not found\n";
|
||||
|
|
|
@ -58,7 +58,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
|
|||
config* scenario = game_config.find_child(type,"id",state.scenario);
|
||||
while(scenario != NULL) {
|
||||
|
||||
std::vector<config*>& story = scenario->children["story"];
|
||||
const config::child_list& story = scenario->get_children("story");
|
||||
const std::string current_scenario = state.scenario;
|
||||
|
||||
try {
|
||||
|
@ -205,7 +205,7 @@ int play_game(int argc, char** argv)
|
|||
//clear game_cfg so it doesn't take up memory
|
||||
std::string().swap(game_cfg);
|
||||
|
||||
const std::vector<config*>& units = game_config.children["units"];
|
||||
const config::child_list& units = game_config.get_children("units");
|
||||
if(units.empty()) {
|
||||
std::cerr << "Could not find units configuration\n";
|
||||
std::cerr << game_config.write();
|
||||
|
@ -472,7 +472,7 @@ int play_game(int argc, char** argv)
|
|||
//make a new game config item based on the difficulty level
|
||||
config game_config(preprocess_file("data/game.cfg", &defines_map));
|
||||
|
||||
const std::vector<config*>& units = game_config.children["units"];
|
||||
const config::child_list& units = game_config.get_children("units");
|
||||
if(units.empty()) {
|
||||
std::cerr << "Could not find units configuration\n";
|
||||
std::cerr << game_config.write();
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace game_config
|
|||
const int cure_amount = 8;
|
||||
const int curer_heals_per_turn = 18;
|
||||
const int recall_cost = 20;
|
||||
const std::string version = "0.6";
|
||||
const std::string version = "0.6.1RC1";
|
||||
bool debug = false;
|
||||
|
||||
#ifdef WESNOTH_PATH
|
||||
|
|
|
@ -31,13 +31,13 @@ namespace game_events {
|
|||
|
||||
bool conditional_passed(game_state& state_of_game,
|
||||
const std::map<gamemap::location,unit>* units,
|
||||
config& cond)
|
||||
const config& cond)
|
||||
{
|
||||
//if the if statement requires we have a certain unit, then
|
||||
//check for that.
|
||||
std::vector<config*>& have_unit = cond.children["have_unit"];
|
||||
const config::child_list& have_unit = cond.get_children("have_unit");
|
||||
|
||||
for(std::vector<config*>::iterator u = have_unit.begin();
|
||||
for(config::child_list::const_iterator u = have_unit.begin();
|
||||
u != have_unit.end(); ++u) {
|
||||
|
||||
if(units == NULL)
|
||||
|
@ -57,19 +57,23 @@ bool conditional_passed(game_state& state_of_game,
|
|||
|
||||
//check against each variable statement to see if the variable
|
||||
//matches the conditions or not
|
||||
std::vector<config*>& variables = cond.children["variable"];
|
||||
for(std::vector<config*>::iterator var = variables.begin();
|
||||
const config::child_list& variables = cond.get_children("variable");
|
||||
for(config::child_list::const_iterator var = variables.begin();
|
||||
var != variables.end(); ++var) {
|
||||
string_map& values = (*var)->values;
|
||||
const string_map& values = (*var)->values;
|
||||
string_map& vars = state_of_game.variables;
|
||||
const std::string& name = values["name"];
|
||||
|
||||
string_map::const_iterator itor = values.find("name");
|
||||
if(itor == values.end())
|
||||
return false;
|
||||
|
||||
const std::string& name = itor->second;
|
||||
|
||||
//if we don't have a record of the variable, then the statement
|
||||
//is not true, unless it's a not equals statement, in which it's
|
||||
//automatically true
|
||||
if(vars.find(name) == vars.end()) {
|
||||
if(values.find("not_equals") == values.end() &&
|
||||
values.find("numerical_not_equals") == values.end()) {
|
||||
if(values.count("not_equals") == 0 && values.count("numerical_not_equals") == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -79,8 +83,6 @@ bool conditional_passed(game_state& state_of_game,
|
|||
const std::string& value = vars[name];
|
||||
const double num_value = atof(value.c_str());
|
||||
|
||||
string_map::iterator itor;
|
||||
|
||||
itor = values.find("equals");
|
||||
if(itor != values.end() && itor->second != value) {
|
||||
return false;
|
||||
|
@ -167,12 +169,12 @@ public:
|
|||
void disable() { disabled_ = true; }
|
||||
bool disabled() const { return disabled_; }
|
||||
|
||||
std::vector<config*>& first_arg_filters() {
|
||||
return cfg_->children["filter"];
|
||||
const config::child_list& first_arg_filters() {
|
||||
return cfg_->get_children("filter");
|
||||
}
|
||||
|
||||
std::vector<config*>& second_arg_filters() {
|
||||
return cfg_->children["filter_second"];
|
||||
const config::child_list& second_arg_filters() {
|
||||
return cfg_->get_children("filter_second");
|
||||
}
|
||||
|
||||
void handle_event(const queued_event& event_info, const config* cfg=NULL);
|
||||
|
@ -225,7 +227,7 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
if(cfg == NULL)
|
||||
cfg = cfg_;
|
||||
|
||||
std::vector<config*>::const_iterator i;
|
||||
config::child_list::const_iterator i;
|
||||
|
||||
//sub commands that need to be handled in a guaranteed ordering
|
||||
const config::child_list& commands = cfg->get_children("command");
|
||||
|
@ -439,8 +441,8 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
|
||||
//if the if statement passed, then execute all 'then' statements,
|
||||
//otherwise execute 'else' statements
|
||||
const std::vector<config*>& commands = (*i)->get_children(type);
|
||||
for(std::vector<config*>::const_iterator cmd = commands.begin();
|
||||
const config::child_list& commands = (*i)->get_children(type);
|
||||
for(config::child_list::const_iterator cmd = commands.begin();
|
||||
cmd != commands.end(); ++cmd) {
|
||||
handle_event(event_info,*cmd);
|
||||
}
|
||||
|
@ -617,10 +619,10 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
text = values["cannot_use_message"];
|
||||
}
|
||||
|
||||
scoped_sdl_surface surface(NULL);
|
||||
|
||||
SDL_Surface* surface = NULL;
|
||||
if(image.empty() == false) {
|
||||
surface = image::get_image(image,image::UNSCALED);
|
||||
surface.assign(image::get_image(image,image::UNSCALED));
|
||||
}
|
||||
|
||||
gui::show_dialog(*screen,surface,caption,text);
|
||||
|
@ -685,21 +687,21 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
}
|
||||
|
||||
std::vector<std::string> options;
|
||||
std::vector<std::vector<config*>*> option_events;
|
||||
std::vector<config::const_child_itors> option_events;
|
||||
|
||||
std::cerr << "building menu items...\n";
|
||||
|
||||
const std::vector<config*>& menu_items = (*i)->get_children("option");
|
||||
for(std::vector<config*>::const_iterator mi = menu_items.begin();
|
||||
const config::child_list& menu_items = (*i)->get_children("option");
|
||||
for(config::child_list::const_iterator mi = menu_items.begin();
|
||||
mi != menu_items.end(); ++mi) {
|
||||
const std::string& msg = translate_string_default((**mi)["id"],(**mi)["message"]);
|
||||
options.push_back(msg);
|
||||
option_events.push_back(&(*mi)->children["command"]);
|
||||
option_events.push_back((*mi)->child_range("command"));
|
||||
}
|
||||
|
||||
SDL_Surface* surface = NULL;
|
||||
scoped_sdl_surface surface(NULL);
|
||||
if(image.empty() == false) {
|
||||
surface = image::get_image(image,image::UNSCALED);
|
||||
surface.assign(image::get_image(image,image::UNSCALED));
|
||||
}
|
||||
|
||||
const std::string& lang_message = string_table[id];
|
||||
|
@ -709,8 +711,8 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
options.empty() ? NULL : &options);
|
||||
|
||||
if(screen->update_locked() && options.empty() == false) {
|
||||
config* const cfg = recorder.get_next_action();
|
||||
if(cfg == NULL || cfg->children["choose"].empty()) {
|
||||
const config* const cfg = recorder.get_next_action();
|
||||
if(cfg == NULL || cfg->get_children("choose").empty()) {
|
||||
std::cerr << "choice expected but none found\n";
|
||||
throw replay::error();
|
||||
}
|
||||
|
@ -719,7 +721,7 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
option_chosen = 0;
|
||||
}
|
||||
|
||||
const std::string& val = cfg->children["choose"].front()->values["value"];
|
||||
const std::string& val = (*(cfg->get_children("choose").front()))["value"];
|
||||
option_chosen = atol(val.c_str());
|
||||
|
||||
} else if(options.empty() == false) {
|
||||
|
@ -728,10 +730,10 @@ void event_handler::handle_event(const queued_event& event_info, const config* c
|
|||
|
||||
if(options.empty() == false) {
|
||||
assert(size_t(option_chosen) < menu_items.size());
|
||||
const std::vector<config*>& events = *option_events[option_chosen];
|
||||
for(std::vector<config*>::const_iterator ev = events.begin();
|
||||
ev != events.end(); ++ev) {
|
||||
handle_event(event_info,*ev);
|
||||
|
||||
for(config::const_child_itors events = option_events[option_chosen];
|
||||
events.first != events.second; ++events.first) {
|
||||
handle_event(event_info,*events.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -856,8 +858,8 @@ bool process_event(event_handler& handler, const queued_event& ev)
|
|||
std::map<gamemap::location,unit>::iterator unit1 = units->find(ev.loc1);
|
||||
std::map<gamemap::location,unit>::iterator unit2 = units->find(ev.loc2);
|
||||
|
||||
std::vector<config*>& first_filters = handler.first_arg_filters();
|
||||
for(std::vector<config*>::iterator ffi = first_filters.begin();
|
||||
const config::child_list& first_filters = handler.first_arg_filters();
|
||||
for(config::child_list::const_iterator ffi = first_filters.begin();
|
||||
ffi != first_filters.end(); ++ffi) {
|
||||
if(!filter_loc(ev.loc1,**ffi))
|
||||
return false;
|
||||
|
@ -867,8 +869,8 @@ bool process_event(event_handler& handler, const queued_event& ev)
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<config*>& second_filters = handler.second_arg_filters();
|
||||
for(std::vector<config*>::iterator sfi = second_filters.begin();
|
||||
const config::child_list& second_filters = handler.second_arg_filters();
|
||||
for(config::child_list::const_iterator sfi = second_filters.begin();
|
||||
sfi != second_filters.end(); ++sfi) {
|
||||
if(!filter_loc(ev.loc2,**sfi))
|
||||
return false;
|
||||
|
@ -896,8 +898,8 @@ manager::manager(config& cfg, display& gui_, gamemap& map_,
|
|||
std::vector<team>& teams_,
|
||||
game_state& state_of_game_, game_data& game_data_)
|
||||
{
|
||||
std::vector<config*>& events_list = cfg.children["event"];
|
||||
for(std::vector<config*>::iterator i = events_list.begin();
|
||||
const config::child_list& events_list = cfg.get_children("event");
|
||||
for(config::child_list::const_iterator i = events_list.begin();
|
||||
i != events_list.end(); ++i) {
|
||||
event_handler new_handler(*i);
|
||||
events_map.insert(std::pair<std::string,event_handler>(
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
time_of_day::time_of_day(config& cfg)
|
||||
time_of_day::time_of_day(const config& cfg)
|
||||
: lawful_bonus(atoi(cfg["lawful_bonus"].c_str())),
|
||||
image(cfg["image"]), name(cfg["name"]), id(cfg["id"]),
|
||||
red(atoi(cfg["red"].c_str())),
|
||||
|
@ -36,14 +36,14 @@ time_of_day::time_of_day(config& cfg)
|
|||
gamestatus::gamestatus(config& time_cfg, int num_turns) :
|
||||
turn_(1),numTurns_(num_turns)
|
||||
{
|
||||
std::vector<config*>& times = time_cfg.children["time"];
|
||||
std::vector<config*>::iterator t;
|
||||
const config::child_list& times = time_cfg.get_children("time");
|
||||
config::child_list::const_iterator t;
|
||||
for(t = times.begin(); t != times.end(); ++t) {
|
||||
times_.push_back(time_of_day(**t));
|
||||
}
|
||||
|
||||
std::vector<config*>& times_illum = time_cfg.children["illuminated_time"];
|
||||
std::vector<config*>& illum = times_illum.empty() ? times : times_illum;
|
||||
const config::child_list& times_illum = time_cfg.get_children("illuminated_time");
|
||||
const config::child_list& illum = times_illum.empty() ? times : times_illum;
|
||||
|
||||
for(t = illum.begin(); t != illum.end(); ++t) {
|
||||
illuminatedTimes_.push_back(time_of_day(**t));
|
||||
|
@ -96,26 +96,24 @@ game_state read_game(game_data& data, config* cfg)
|
|||
if(res.campaign_type.empty())
|
||||
res.campaign_type = "scenario";
|
||||
|
||||
std::vector<config*>& units = cfg->children["unit"];
|
||||
for(std::vector<config*>::iterator i = units.begin();
|
||||
i != units.end(); ++i) {
|
||||
log_scope("loading unit");
|
||||
const config::child_list& units = cfg->get_children("unit");
|
||||
for(config::child_list::const_iterator i = units.begin(); i != units.end(); ++i) {
|
||||
res.available_units.push_back(unit(data,**i));
|
||||
}
|
||||
|
||||
std::vector<config*>& vars = cfg->children["variables"];
|
||||
if(vars.empty() == false) {
|
||||
res.variables = vars[0]->values;
|
||||
const config* const vars = cfg->child("variables");
|
||||
if(vars != NULL) {
|
||||
res.variables = vars->values;
|
||||
}
|
||||
|
||||
std::vector<config*>& replays = cfg->children["replay"];
|
||||
if(replays.empty() == false) {
|
||||
res.replay_data = *replays[0];
|
||||
const config* const replay = cfg->child("replay");
|
||||
if(replay != NULL) {
|
||||
res.replay_data = *replay;
|
||||
}
|
||||
|
||||
std::vector<config*>& starts = cfg->children["start"];
|
||||
if(starts.empty() == false) {
|
||||
res.starting_pos = *starts[0];
|
||||
const config* starting_pos = cfg->child("start");
|
||||
if(starting_pos != NULL) {
|
||||
res.starting_pos = *starting_pos;
|
||||
}
|
||||
|
||||
res.can_recruit.clear();
|
||||
|
@ -144,22 +142,20 @@ void write_game(const game_state& game, config& cfg)
|
|||
|
||||
cfg["difficulty"] = game.difficulty;
|
||||
|
||||
config* vars = new config();
|
||||
vars->values = game.variables;
|
||||
cfg.children["variables"].push_back(vars);
|
||||
cfg.add_child("variables").values = game.variables;
|
||||
|
||||
for(std::vector<unit>::const_iterator i = game.available_units.begin();
|
||||
i != game.available_units.end(); ++i) {
|
||||
config* const new_cfg = new config;
|
||||
i->write(*new_cfg);
|
||||
cfg.children["unit"].push_back(new_cfg);
|
||||
config new_cfg;
|
||||
i->write(new_cfg);
|
||||
cfg.add_child("unit",new_cfg);
|
||||
}
|
||||
|
||||
if(game.replay_data.children.empty() == false) {
|
||||
cfg.children["replay"].push_back(new config(game.replay_data));
|
||||
cfg.add_child("replay",game.replay_data);
|
||||
}
|
||||
|
||||
cfg.children["start"].push_back(new config(game.starting_pos));
|
||||
cfg.add_child("start",game.starting_pos);
|
||||
|
||||
std::stringstream can_recruit;
|
||||
std::copy(game.can_recruit.begin(),game.can_recruit.end(),std::ostream_iterator<std::string>(can_recruit,","));
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
//an object which defines the current time of day
|
||||
struct time_of_day
|
||||
{
|
||||
explicit time_of_day(config& cfg);
|
||||
explicit time_of_day(const config& cfg);
|
||||
|
||||
//the % bonus lawful units receive. chaotic units will
|
||||
//receive -lawful_bonus.
|
||||
|
|
|
@ -77,15 +77,14 @@ std::string command_to_string(const HOTKEY_COMMAND &command)
|
|||
}
|
||||
|
||||
|
||||
hotkey_item::hotkey_item(config& cfg) : lastres(false)
|
||||
hotkey_item::hotkey_item(const config& cfg) : lastres(false)
|
||||
{
|
||||
std::map<std::string,std::string>& m = cfg.values;
|
||||
action = string_to_command(m["command"]);
|
||||
action = string_to_command(cfg["command"]);
|
||||
|
||||
keycode = m["key"].empty() ? 0 : m["key"][0];
|
||||
alt = (m["alt"] == "yes");
|
||||
ctrl = (m["ctrl"] == "yes");
|
||||
shift = (m["shift"] == "yes");
|
||||
keycode = cfg["key"].empty() ? 0 : cfg["key"][0];
|
||||
alt = (cfg["alt"] == "yes");
|
||||
ctrl = (cfg["ctrl"] == "yes");
|
||||
shift = (cfg["shift"] == "yes");
|
||||
}
|
||||
|
||||
bool operator==(const hotkey_item& a, const hotkey_item& b)
|
||||
|
@ -129,16 +128,18 @@ bool hotkey_pressed::operator()(const hotkey::hotkey_item& hk) const
|
|||
|
||||
namespace {
|
||||
|
||||
void add_hotkey(config& cfg,bool overwrite)
|
||||
void add_hotkey(const config& cfg,bool overwrite)
|
||||
{
|
||||
const hotkey::hotkey_item new_hotkey(cfg);
|
||||
std::vector<hotkey::hotkey_item>::iterator i;
|
||||
for(i=hotkeys.begin();i!=hotkeys.end();i++)
|
||||
|
||||
for(std::vector<hotkey::hotkey_item>::iterator i = hotkeys.begin();
|
||||
i != hotkeys.end(); ++i) {
|
||||
if(i->action == new_hotkey.action) {
|
||||
if (overwrite)
|
||||
*i=new_hotkey;
|
||||
if(overwrite)
|
||||
*i = new_hotkey;
|
||||
return;
|
||||
};
|
||||
}
|
||||
}
|
||||
hotkeys.push_back(new_hotkey);
|
||||
}
|
||||
|
||||
|
@ -167,40 +168,27 @@ void basic_handler::handle_event(const SDL_Event& event)
|
|||
|
||||
void add_hotkeys(config& cfg,bool overwrite)
|
||||
{
|
||||
std::vector<config*>& children = cfg.children["hotkey"];
|
||||
for(std::vector<config*>::iterator i = children.begin();
|
||||
i != children.end(); ++i) {
|
||||
const config::child_list& children = cfg.get_children("hotkey");
|
||||
for(config::child_list::const_iterator i = children.begin(); i != children.end(); ++i) {
|
||||
add_hotkey(**i,overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
void save_hotkeys(config& cfg)
|
||||
{
|
||||
std::vector<config*> children = cfg.children["hotkey"];
|
||||
for(std::vector<hotkey_item>::iterator i = hotkeys.begin();
|
||||
i != hotkeys.end();i++)
|
||||
{
|
||||
const config::child_list children = cfg.get_children("hotkey");
|
||||
for(std::vector<hotkey_item>::iterator i = hotkeys.begin(); i != hotkeys.end(); ++i) {
|
||||
std::string action_name = command_to_string(i->action);
|
||||
std::vector<config*>::iterator i2;
|
||||
for(i2= children.begin();
|
||||
i2!=children.end();i2++)
|
||||
{
|
||||
if((**i2)["command"]==action_name)
|
||||
{
|
||||
(*i2)->clear();
|
||||
break;
|
||||
};
|
||||
|
||||
}
|
||||
config * i3;
|
||||
if (i2==children.end())
|
||||
i3 = &cfg.add_child("hotkey");
|
||||
else i3 = *i2;
|
||||
(*i3)["command"]=action_name;
|
||||
(*i3)["key"]=i->keycode;
|
||||
if (i->alt) (*i3)["alt"]="yes";
|
||||
if (i->ctrl) (*i3)["ctrl"]="yes";
|
||||
if (i->shift) (*i3)["shift"]="yes";
|
||||
|
||||
config* item = cfg.find_child("hotkey","command",action_name);
|
||||
if(item == NULL)
|
||||
item = &cfg.add_child("command");
|
||||
|
||||
(*item)["command"] = action_name;
|
||||
(*item)["key"] = i->keycode;
|
||||
(*item)["alt"] = (i->alt) ? "yes" : "no";
|
||||
(*item)["ctrl"] = (i->ctrl) ? "yes" : "no";
|
||||
(*item)["shift"] = (i->shift) ? "yes" : "no";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
|
|||
HOTKEY_NULL };
|
||||
|
||||
struct hotkey_item {
|
||||
explicit hotkey_item(config& cfg);
|
||||
explicit hotkey_item(const config& cfg);
|
||||
|
||||
HOTKEY_COMMAND action;
|
||||
int keycode;
|
||||
|
|
142
src/image.cpp
142
src/image.cpp
|
@ -51,7 +51,7 @@ SDL_Surface* get_tinted(const std::string& filename, TINT tint)
|
|||
if(itor != images.end())
|
||||
return itor->second;
|
||||
|
||||
SDL_Surface* const base = image::get_image(filename,image::SCALED);
|
||||
scoped_sdl_surface base(image::get_image(filename,image::SCALED));
|
||||
if(base == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -135,7 +135,7 @@ manager::~manager()
|
|||
void set_wm_icon()
|
||||
{
|
||||
//this code seems to only display the top part of the icon in Windows XP
|
||||
SDL_Surface* const icon = get_image("icon.png",UNSCALED);
|
||||
scoped_sdl_surface icon(get_image("icon.png",UNSCALED));
|
||||
if(icon != NULL) {
|
||||
std::cerr << "setting icon...\n";
|
||||
::SDL_WM_SetIcon(icon,NULL);
|
||||
|
@ -174,84 +174,92 @@ void set_zoom(double amount)
|
|||
|
||||
SDL_Surface* get_image(const std::string& filename,TYPE type)
|
||||
{
|
||||
SDL_Surface* result = NULL;
|
||||
if(type == GREYED) {
|
||||
return get_tinted(filename,GREY_IMAGE);
|
||||
result = get_tinted(filename,GREY_IMAGE);
|
||||
} else if(type == BRIGHTENED) {
|
||||
return get_tinted(filename,BRIGHTEN_IMAGE);
|
||||
result = get_tinted(filename,BRIGHTEN_IMAGE);
|
||||
} else if(type == FOGGED) {
|
||||
const image_map::iterator i = foggedImages_.find(filename);
|
||||
if(i != foggedImages_.end())
|
||||
return i->second;
|
||||
if(i != foggedImages_.end()) {
|
||||
result = i->second;
|
||||
sdl_add_ref(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_Surface* const surf = get_image(filename,SCALED);
|
||||
const scoped_sdl_surface surf(get_image(filename,SCALED));
|
||||
if(surf == NULL)
|
||||
return NULL;
|
||||
|
||||
SDL_Surface* const image = scale_surface(surf,surf->w,surf->h);
|
||||
adjust_surface_colour(image,-50,-50,-50);
|
||||
foggedImages_.insert(std::pair<std::string,SDL_Surface*>(filename,
|
||||
image));
|
||||
return image;
|
||||
}
|
||||
result = scale_surface(surf,surf->w,surf->h);
|
||||
adjust_surface_colour(result,-50,-50,-50);
|
||||
foggedImages_.insert(std::pair<std::string,SDL_Surface*>(filename,result));
|
||||
} else {
|
||||
|
||||
image_map::iterator i;
|
||||
image_map::iterator i;
|
||||
|
||||
if(type == SCALED) {
|
||||
i = scaledImages_.find(filename);
|
||||
if(i != scaledImages_.end())
|
||||
return i->second;
|
||||
}
|
||||
|
||||
i = images_.find(filename);
|
||||
|
||||
if(i == images_.end()) {
|
||||
const std::string images_path = "images/";
|
||||
const std::string images_filename = images_path + filename;
|
||||
SDL_Surface* surf = NULL;
|
||||
|
||||
if(game_config::path.empty() == false) {
|
||||
const std::string& fullpath = game_config::path + "/" +
|
||||
images_filename;
|
||||
surf = IMG_Load(fullpath.c_str());
|
||||
if(type == SCALED) {
|
||||
i = scaledImages_.find(filename);
|
||||
if(i != scaledImages_.end()) {
|
||||
result = i->second;
|
||||
sdl_add_ref(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if(surf == NULL)
|
||||
surf = IMG_Load(images_filename.c_str());
|
||||
i = images_.find(filename);
|
||||
|
||||
if(surf == NULL) {
|
||||
images_.insert(std::pair<std::string,SDL_Surface*>(filename,NULL));
|
||||
if(i == images_.end()) {
|
||||
const std::string images_path = "images/";
|
||||
const std::string images_filename = images_path + filename;
|
||||
SDL_Surface* surf = NULL;
|
||||
|
||||
if(game_config::path.empty() == false) {
|
||||
const std::string& fullpath = game_config::path + "/" +
|
||||
images_filename;
|
||||
surf = IMG_Load(fullpath.c_str());
|
||||
}
|
||||
|
||||
if(surf == NULL) {
|
||||
surf = IMG_Load(images_filename.c_str());
|
||||
}
|
||||
|
||||
if(surf == NULL) {
|
||||
images_.insert(std::pair<std::string,SDL_Surface*>(filename,NULL));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(pixel_format != NULL) {
|
||||
SDL_Surface* const conv = SDL_ConvertSurface(surf,
|
||||
pixel_format,SDL_SWSURFACE);
|
||||
SDL_FreeSurface(surf);
|
||||
surf = conv;
|
||||
}
|
||||
|
||||
i = images_.insert(std::pair<std::string,SDL_Surface*>(filename,surf)).first;
|
||||
}
|
||||
|
||||
if(i->second == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(pixel_format != NULL) {
|
||||
SDL_Surface* const conv = SDL_ConvertSurface(surf,
|
||||
pixel_format,SDL_SWSURFACE);
|
||||
SDL_FreeSurface(surf);
|
||||
surf = conv;
|
||||
}
|
||||
if(type == UNSCALED) {
|
||||
result = i->second;
|
||||
} else {
|
||||
|
||||
i = images_.insert(std::pair<std::string,SDL_Surface*>(filename,surf))
|
||||
.first;
|
||||
const int z = static_cast<int>(zoom);
|
||||
result = scale_surface(i->second,z,z);
|
||||
|
||||
if(result == NULL)
|
||||
return NULL;
|
||||
|
||||
adjust_surface_colour(result,red_adjust,green_adjust,blue_adjust);
|
||||
|
||||
scaledImages_.insert(std::pair<std::string,SDL_Surface*>(filename,result));
|
||||
}
|
||||
}
|
||||
|
||||
if(i->second == NULL)
|
||||
return NULL;
|
||||
|
||||
if(type == UNSCALED) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
const int z = static_cast<int>(zoom);
|
||||
SDL_Surface* const new_surface = scale_surface(i->second,z,z);
|
||||
|
||||
if(new_surface == NULL)
|
||||
return NULL;
|
||||
|
||||
adjust_surface_colour(new_surface,red_adjust,green_adjust,blue_adjust);
|
||||
|
||||
scaledImages_.insert(std::pair<std::string,SDL_Surface*>(filename,
|
||||
new_surface));
|
||||
return new_surface;
|
||||
sdl_add_ref(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_Surface* get_image_dim(const std::string& filename, size_t x, size_t y)
|
||||
|
@ -260,8 +268,15 @@ SDL_Surface* get_image_dim(const std::string& filename, size_t x, size_t y)
|
|||
if(surf != NULL && (size_t(surf->w) != x || size_t(surf->h) != y)) {
|
||||
SDL_Surface* const new_image = scale_surface(surf,x,y);
|
||||
images_.erase(filename);
|
||||
|
||||
//free surf twice: once because calling get_image adds a reference.
|
||||
//again because we also want to remove the cache reference, since
|
||||
//we're removing it from the cache
|
||||
SDL_FreeSurface(surf);
|
||||
SDL_FreeSurface(surf);
|
||||
|
||||
images_[filename] = new_image;
|
||||
sdl_add_ref(new_image);
|
||||
return new_image;
|
||||
}
|
||||
|
||||
|
@ -296,8 +311,7 @@ SDL_Surface* getMinimap(int w, int h, const gamemap& map, const team* tm)
|
|||
cache_map::iterator i = cache.find(terrain);
|
||||
|
||||
if(i == cache.end()) {
|
||||
SDL_Surface* const tile =
|
||||
get_image("terrain/" + map.get_terrain_info(terrain).default_image() + ".png");
|
||||
scoped_sdl_surface tile(get_image("terrain/" + map.get_terrain_info(terrain).default_image() + ".png"));
|
||||
|
||||
if(tile == NULL) {
|
||||
std::cerr << "Could not get image for terrrain '"
|
||||
|
|
|
@ -51,13 +51,17 @@ namespace image {
|
|||
enum TYPE { UNSCALED, SCALED, FOGGED, GREYED, BRIGHTENED };
|
||||
|
||||
//function to get the surface corresponding to an image.
|
||||
//note that this surface must be freed by the user by calling
|
||||
//SDL_FreeSurface
|
||||
SDL_Surface* get_image(const std::string& filename,TYPE type=SCALED);
|
||||
|
||||
//function to get a scaled image, but scale it to specific dimensions.
|
||||
//if you later try to get the same image using get_image() the image will
|
||||
//have the dimensions specified here.
|
||||
//Note that this surface must be freed by the user by calling SDL_FreeSurface
|
||||
SDL_Surface* get_image_dim(const std::string& filename, size_t x, size_t y);
|
||||
|
||||
//the surface returned must be freed by the user
|
||||
SDL_Surface* getMinimap(int w, int h, const gamemap& map_, const team* tm=NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
void show_intro(display& screen, config& data)
|
||||
void show_intro(display& screen, const config& data)
|
||||
{
|
||||
//stop the screen being resized while we're in this function
|
||||
const events::resize_lock stop_resizing;
|
||||
|
@ -40,15 +40,16 @@ void show_intro(display& screen, config& data)
|
|||
skip_button.set_x(700);
|
||||
skip_button.set_y(550);
|
||||
|
||||
std::vector<config*>& parts = data.children["part"];
|
||||
const config::child_list& parts = data.get_children("part");
|
||||
|
||||
for(std::vector<config*>::iterator i = parts.begin(); i != parts.end();++i){
|
||||
for(config::child_list::const_iterator i = parts.begin(); i != parts.end(); ++i){
|
||||
gui::draw_solid_tinted_rectangle(0,0,screen.x()-1,screen.y()-1,
|
||||
0,0,0,1.0,screen.video().getSurface());
|
||||
const std::string& image_name = (*i)->values["image"];
|
||||
SDL_Surface* image = NULL;
|
||||
const std::string& image_name = (**i)["image"];
|
||||
|
||||
scoped_sdl_surface image(NULL);
|
||||
if(image_name.empty() == false) {
|
||||
image = image::get_image(image_name,image::UNSCALED);
|
||||
image.assign(image::get_image(image_name,image::UNSCALED));
|
||||
}
|
||||
|
||||
int textx = 200;
|
||||
|
@ -77,10 +78,9 @@ void show_intro(display& screen, config& data)
|
|||
update_whole_screen();
|
||||
screen.video().flip();
|
||||
|
||||
const std::string& id = (*i)->values["id"];
|
||||
const std::string& id = (**i)["id"];
|
||||
const std::string& lang_story = string_table[id];
|
||||
const std::string& story = lang_story.empty() ? (*i)->values["story"] :
|
||||
lang_story;
|
||||
const std::string& story = lang_story.empty() ? (**i)["story"] : lang_story;
|
||||
|
||||
const int max_length = 60;
|
||||
int cur_length = 0;
|
||||
|
@ -171,22 +171,20 @@ void show_map_scene(display& screen, config& data)
|
|||
screen.video().getSurface());
|
||||
|
||||
|
||||
std::vector<config*>& sequence = data.children["bigmap"];
|
||||
if(sequence.empty()) {
|
||||
const config* const cfg_item = data.child("bigmap");
|
||||
if(cfg_item == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
config& cfg = *sequence[0];
|
||||
const config& cfg = *cfg_item;
|
||||
|
||||
std::vector<config*>& dots = cfg.children["dot"];
|
||||
const config::child_list& dots = cfg.get_children("dot");
|
||||
|
||||
const std::string& image_file = cfg.values["image"];
|
||||
const std::string& image_file = cfg["image"];
|
||||
|
||||
SDL_Surface* const image = image::get_image(image_file,image::UNSCALED);
|
||||
SDL_Surface* const dot_image =
|
||||
image::get_image("misc/dot.png",image::UNSCALED);
|
||||
SDL_Surface* const cross_image =
|
||||
image::get_image("misc/cross.png",image::UNSCALED);
|
||||
const scoped_sdl_surface image(image::get_image(image_file,image::UNSCALED));
|
||||
const scoped_sdl_surface dot_image(image::get_image("misc/dot.png",image::UNSCALED));
|
||||
const scoped_sdl_surface cross_image(image::get_image("misc/cross.png",image::UNSCALED));
|
||||
if(image == NULL || dot_image == NULL || cross_image == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -209,17 +207,16 @@ void show_map_scene(display& screen, config& data)
|
|||
|
||||
CKey key;
|
||||
|
||||
|
||||
for(std::vector<config*>::iterator d = dots.begin(); d != dots.end(); ++d){
|
||||
const std::string& xloc = (*d)->values["x"];
|
||||
const std::string& yloc = (*d)->values["y"];
|
||||
for(std::vector<config*>::const_iterator d = dots.begin(); d != dots.end(); ++d){
|
||||
const std::string& xloc = (**d)["x"];
|
||||
const std::string& yloc = (**d)["y"];
|
||||
const int x = atoi(xloc.c_str());
|
||||
const int y = atoi(yloc.c_str());
|
||||
if(x < 0 || x >= image->w || y < 0 || y >= image->w)
|
||||
continue;
|
||||
|
||||
SDL_Surface* img = dot_image;
|
||||
if((*d)->values["type"] == "cross") {
|
||||
if((**d)["type"] == "cross") {
|
||||
img = cross_image;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
//
|
||||
//each part of the sequence will be displayed in turn, with the
|
||||
//user able to go to the next part, or skip it entirely.
|
||||
void show_intro(display& screen, config& data);
|
||||
void show_intro(display& screen, const config& data);
|
||||
|
||||
//function to show the map before each scenario.
|
||||
//data is in a format that looks like,
|
||||
|
|
|
@ -46,10 +46,9 @@ std::vector<std::string> get_languages(config& cfg)
|
|||
{
|
||||
std::vector<std::string> res;
|
||||
|
||||
const std::vector<config*>& lang = cfg.children["language"];
|
||||
for(std::vector<config*>::const_iterator i = lang.begin();
|
||||
i != lang.end(); ++i) {
|
||||
res.push_back((*i)->values["language"]);
|
||||
const config::child_list& lang = cfg.get_children("language");
|
||||
for(config::child_list::const_iterator i = lang.begin(); i != lang.end(); ++i) {
|
||||
res.push_back((**i)["language"]);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -58,10 +57,9 @@ std::vector<std::string> get_languages(config& cfg)
|
|||
namespace {
|
||||
bool internal_set_language(const std::string& locale, config& cfg)
|
||||
{
|
||||
const std::vector<config*>& lang = cfg.children["language"];
|
||||
for(std::vector<config*>::const_iterator i = lang.begin();
|
||||
i != lang.end(); ++i) {
|
||||
if((*i)->values["id"] == locale || (*i)->values["language"] == locale) {
|
||||
const config::child_list& lang = cfg.get_children("language");
|
||||
for(config::child_list::const_iterator i = lang.begin(); i != lang.end(); ++i) {
|
||||
if((**i)["id"] == locale || (**i)["language"] == locale) {
|
||||
|
||||
const std::string& enc = (**i)["encoding"];
|
||||
if(enc == "UTF-8") {
|
||||
|
@ -74,8 +72,7 @@ bool internal_set_language(const std::string& locale, config& cfg)
|
|||
charset_used = CHARSET_LATIN1;
|
||||
}
|
||||
|
||||
for(std::map<std::string,std::string>::const_iterator j =
|
||||
(*i)->values.begin(); j != (*i)->values.end(); ++j) {
|
||||
for(string_map::const_iterator j = (*i)->values.begin(); j != (*i)->values.end(); ++j) {
|
||||
string_table[j->first] = j->second;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ gamemap::location gamemap::location::get_direction(
|
|||
|
||||
gamemap::gamemap(config& cfg, const std::string& data) : tiles_(1)
|
||||
{
|
||||
std::vector<config*>& terrains = cfg.children["terrain"];
|
||||
const config::child_list& terrains = cfg.get_children("terrain");
|
||||
create_terrain_maps(terrains,terrainPrecedence_,letterToTerrain_,terrain_);
|
||||
|
||||
size_t x = 0, y = 0;
|
||||
|
|
|
@ -68,10 +68,9 @@ private:
|
|||
connection_acceptor::connection_acceptor(config& players)
|
||||
: players_(players)
|
||||
{
|
||||
std::vector<config*>& sides = players.children["side"];
|
||||
for(std::vector<config*>::const_iterator i = sides.begin();
|
||||
i != sides.end(); ++i) {
|
||||
if((*i)->values["controller"] == "network") {
|
||||
const config::child_list& sides = players.get_children("side");
|
||||
for(config::child_list::const_iterator i = sides.begin(); i != sides.end(); ++i) {
|
||||
if((**i)["controller"] == "network") {
|
||||
positions_[*i] = 0;
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +89,7 @@ int connection_acceptor::do_action()
|
|||
|
||||
config cfg;
|
||||
|
||||
std::vector<config*>& sides = players_.children["side"];
|
||||
const config::child_list& sides = players_.get_children("side");
|
||||
|
||||
try {
|
||||
sock = network::receive_data(cfg);
|
||||
|
@ -240,7 +239,7 @@ bool accept_network_connections(display& disp, config& players)
|
|||
}
|
||||
|
||||
config start_game;
|
||||
start_game.children["start_game"].push_back(new config());
|
||||
start_game.add_child("start_game");
|
||||
network::send_data(start_game);
|
||||
|
||||
return true;
|
||||
|
@ -294,9 +293,9 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
string_table["map_to_play"] + ":",(disp.x()-width)/2+(int)(width*0.4),
|
||||
(disp.y()-height)/2+83);
|
||||
std::vector<std::string> options;
|
||||
std::vector<config*>& levels = cfg.children["multiplayer"];
|
||||
const config::child_list& levels = cfg.get_children("multiplayer");
|
||||
std::map<int,std::string> res_to_id;
|
||||
for(std::vector<config*>::iterator i = levels.begin(); i!=levels.end();++i){
|
||||
for(config::child_list::const_iterator i = levels.begin(); i != levels.end(); ++i){
|
||||
const std::string& id = (**i)["id"];
|
||||
res_to_id[i - levels.begin()] = id;
|
||||
|
||||
|
@ -380,13 +379,10 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
// Send Initial information
|
||||
config response;
|
||||
config create_game;
|
||||
config& create_game = response.add_child("create_game");
|
||||
create_game["name"] = name_entry.text();
|
||||
response.children["create_game"].push_back(
|
||||
new config(create_game));
|
||||
network::send_data(response);
|
||||
|
||||
|
||||
// Setup the game
|
||||
int res = maps_menu.selection();
|
||||
|
||||
|
@ -397,7 +393,9 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
//if we're loading a saved game
|
||||
config loaded_level;
|
||||
bool loading = false;
|
||||
if(size_t(res) == options.size()-1) {
|
||||
loading = true;
|
||||
const std::string game = dialogs::load_game_dialog(disp,&show_replay);
|
||||
if(game == "")
|
||||
break;
|
||||
|
@ -434,7 +432,7 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
//add the replay data under the level data so clients can
|
||||
//receive it
|
||||
level_ptr->children["replay"].clear();
|
||||
level_ptr->clear_children("replay");
|
||||
level_ptr->add_child("replay") = state.replay_data;
|
||||
|
||||
} else { //creating a new game
|
||||
|
@ -453,19 +451,23 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
state.scenario = res_to_id[res];
|
||||
|
||||
std::vector<config*>& sides = level.children["side"];
|
||||
std::vector<config*>& possible_sides = cfg.children["multiplayer_side"];
|
||||
if(sides.empty() || possible_sides.empty()) {
|
||||
const config::child_itors sides = level.child_range("side");
|
||||
|
||||
const config::child_list& possible_sides = cfg.get_children("multiplayer_side");
|
||||
if(sides.first == sides.second || possible_sides.empty()) {
|
||||
std::cerr << "no multiplayer sides found\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<config*>::iterator sd;
|
||||
for(sd = sides.begin(); sd != sides.end(); ++sd) {
|
||||
config::child_iterator sd;
|
||||
for(sd = sides.first; sd != sides.second; ++sd) {
|
||||
|
||||
std::stringstream village_gold;
|
||||
village_gold << cur_villagegold;
|
||||
(**sd)["village_gold"] = village_gold.str();
|
||||
if(!loading)
|
||||
{
|
||||
std::stringstream village_gold;
|
||||
village_gold << cur_villagegold;
|
||||
(**sd)["village_gold"] = village_gold.str();
|
||||
}
|
||||
|
||||
if((**sd)["fog"].empty())
|
||||
(**sd)["fog"] = fog_game.checked() ? "yes" : "no";
|
||||
|
@ -474,16 +476,16 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
(**sd)["shroud"] = shroud_game.checked() ? "yes" : "no";
|
||||
|
||||
if((**sd)["name"].empty())
|
||||
(**sd)["name"] = possible_sides.front()->values["name"];
|
||||
(**sd)["name"] = (*possible_sides.front())["name"];
|
||||
|
||||
if((**sd)["type"].empty())
|
||||
(**sd)["type"] = possible_sides.front()->values["type"];
|
||||
(**sd)["type"] = (*possible_sides.front())["type"];
|
||||
|
||||
if((**sd)["recruit"].empty())
|
||||
(**sd)["recruit"]=possible_sides.front()->values["recruit"];
|
||||
(**sd)["recruit"] = (*possible_sides.front())["recruit"];
|
||||
|
||||
if((**sd)["music"].empty())
|
||||
(**sd)["music"] = possible_sides.front()->values["music"];
|
||||
(**sd)["music"] = (*possible_sides.front())["music"];
|
||||
|
||||
if((**sd)["recruitment_pattern"].empty())
|
||||
(**sd)["recruitment_pattern"] =
|
||||
|
@ -556,8 +558,8 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
std::vector<std::string> player_team;
|
||||
|
||||
for(sd = sides.begin(); sd != sides.end(); ++sd) {
|
||||
const int team_num = sd - sides.begin();
|
||||
for(sd = sides.first; sd != sides.second; ++sd) {
|
||||
const int team_num = sd - sides.first;
|
||||
|
||||
std::stringstream str;
|
||||
str << string_table["team"] << " " << team_num+1;
|
||||
|
@ -580,9 +582,8 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
std::vector<gui::combo> combo_color;
|
||||
std::vector<gui::slider> slider_gold;
|
||||
|
||||
int n = 0;
|
||||
for(sd = sides.begin(); sd != sides.end(); ++sd) {
|
||||
const int side_num = sd - sides.begin();
|
||||
for(sd = sides.first; sd != sides.second; ++sd) {
|
||||
const int side_num = sd - sides.first;
|
||||
|
||||
font::draw_text(&disp,disp.screen_area(),24,font::GOOD_COLOUR,
|
||||
(*sd)->values["side"],(disp.x()-width)/2+10,
|
||||
|
@ -591,15 +592,24 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
combo_type.back().set_xy((disp.x()-width)/2+30,
|
||||
(disp.y()-height)/2+55+(30*side_num));
|
||||
|
||||
if(side_num>0) {
|
||||
sides[n]->values["controller"] = "network";
|
||||
sides[n]->values["description"] = "";
|
||||
combo_type.back().set_selected(1);
|
||||
}else{
|
||||
sides[n]->values["controller"] = "human";
|
||||
sides[n]->values["description"] = preferences::login();
|
||||
if(loading) {
|
||||
if((**sd)["controller"] == "network") {
|
||||
combo_type.back().set_selected(1);
|
||||
}else if((**sd)["controller"] == "human") {
|
||||
combo_type.back().set_selected(0);
|
||||
}else if((**sd)["controller"] == "ai") {
|
||||
combo_type.back().set_selected(2);
|
||||
}
|
||||
} else {
|
||||
if(side_num > 0) {
|
||||
(**sd)["controller"] = "network";
|
||||
(**sd)["description"] = "";
|
||||
combo_type.back().set_selected(1);
|
||||
} else {
|
||||
(**sd)["controller"] = "human";
|
||||
(**sd)["description"] = preferences::login();
|
||||
}
|
||||
}
|
||||
sides[n]->values["gold"] = "100";
|
||||
|
||||
combo_race.push_back(gui::combo(disp,player_race));
|
||||
combo_race.back().set_xy((disp.x()-width)/2+145,
|
||||
|
@ -621,8 +631,8 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
combo_team.push_back(gui::combo(disp,player_team));
|
||||
combo_team.back().set_xy((disp.x()-width)/2+260,
|
||||
(disp.y()-height)/2+55+(30*side_num));
|
||||
|
||||
combo_team.back().set_selected(side_num);
|
||||
|
||||
combo_color.push_back(gui::combo(disp,player_color));
|
||||
combo_color.back().set_xy((disp.x()-width)/2+375,
|
||||
(disp.y()-height)/2+55+(30*side_num));
|
||||
|
@ -634,16 +644,18 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
rect.w = launch2_game.width()-5;
|
||||
rect.h = launch2_game.height();
|
||||
int intgold;
|
||||
std::stringstream streamgold;
|
||||
streamgold << sides[n]->values["gold"];
|
||||
streamgold >> intgold;
|
||||
slider_gold.push_back(gui::slider(disp,rect,0.0+(intgold-20)/979));
|
||||
if(loading) {
|
||||
intgold = atoi ((**sd)["gold"].c_str());
|
||||
} else {
|
||||
intgold = 100;
|
||||
(**sd)["gold"] = "100";
|
||||
}
|
||||
slider_gold.push_back(gui::slider(disp,rect,0.0+((intgold-20.0)/979.0)));
|
||||
rect.w = 30;
|
||||
rect.x = (disp.x()-width)/2+603;
|
||||
village_bg=get_surface_portion(disp.video().getSurface(), rect);
|
||||
font::draw_text(&disp,disp.screen_area(),12,font::GOOD_COLOUR,
|
||||
sides[n]->values["gold"],rect.x,rect.y);
|
||||
n++;
|
||||
(**sd)["gold"],rect.x,rect.y);
|
||||
}
|
||||
|
||||
update_whole_screen();
|
||||
|
@ -657,16 +669,18 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
// change the combo_type of another network
|
||||
// player that has already joined the game.
|
||||
|
||||
config& side = **(sides.first+n);
|
||||
|
||||
if(combo_type[n].process(mousex,mousey,left_button)) {
|
||||
if(combo_type[n].selected() == 0) {
|
||||
sides[n]->values["controller"] = "human";
|
||||
sides[n]->values["description"] = preferences::login();
|
||||
side["controller"] = "human";
|
||||
side["description"] = preferences::login();
|
||||
}else if(combo_type[n].selected() == 1){
|
||||
sides[n]->values["controller"] = "network";
|
||||
sides[n]->values["description"] = "";
|
||||
side["controller"] = "network";
|
||||
side["description"] = "";
|
||||
}else if(combo_type[n].selected() == 2){
|
||||
sides[n]->values["controller"] = "ai";
|
||||
sides[n]->values["description"] = string_table["ai_controlled"];
|
||||
side["controller"] = "ai";
|
||||
side["description"] = string_table["ai_controlled"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -675,21 +689,24 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
const string_map& values = possible_sides[combo_race[n].selected()]->values;
|
||||
|
||||
for(string_map::const_iterator i = values.begin(); i != values.end(); ++i) {
|
||||
(*sides[n])[i->first] = i->second;
|
||||
side[i->first] = i->second;
|
||||
}
|
||||
}
|
||||
|
||||
if(combo_team[n].process(mousex,mousey,left_button))
|
||||
{
|
||||
for(size_t l = 0; l != sides.size(); ++l) {
|
||||
const size_t nsides = sides.second - sides.first;
|
||||
for(size_t t = 0; t != nsides; ++t) {
|
||||
std::stringstream myenemy;
|
||||
for(size_t m = 0; m != sides.size(); ++m) {
|
||||
if(combo_team[m].selected() != combo_team[l].selected()) {
|
||||
myenemy << sides[m]->values["side"] << ",";
|
||||
for(size_t m = 0; m != nsides; ++m) {
|
||||
if(combo_team[m].selected() != combo_team[t].selected()) {
|
||||
myenemy << (*sides.first[m])["side"];
|
||||
if(m != nsides-1)
|
||||
myenemy << ",";
|
||||
}
|
||||
}
|
||||
myenemy << "\b";
|
||||
sides[l]->values["enemy"] = myenemy.str();
|
||||
myenemy << "\n";
|
||||
(*sides.first[t])["enemy"] = myenemy.str();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -702,14 +719,14 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
cur_playergold = new_playergold;
|
||||
std::stringstream playergold;
|
||||
playergold << cur_playergold;
|
||||
sides[n]->values["gold"] = playergold.str();
|
||||
(*sides.first[n])["gold"] = playergold.str();
|
||||
rect.x = (disp.x()-width)/2+603;
|
||||
rect.y = (disp.y()-height)/2+55+(30*n);
|
||||
rect.w = 30;
|
||||
rect.h = launch2_game.height();
|
||||
SDL_BlitSurface(village_bg, NULL, disp.video().getSurface(), &rect);
|
||||
font::draw_text(&disp,disp.screen_area(),12,font::GOOD_COLOUR,
|
||||
sides[n]->values["gold"],rect.x,rect.y);
|
||||
(*sides.first[n])["gold"],rect.x,rect.y);
|
||||
update_rect(rect);
|
||||
}
|
||||
}
|
||||
|
@ -739,7 +756,7 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
//any replay data isn't meant to hang around under the level,
|
||||
//it was just there to tell clients about the replay data
|
||||
level.children["replay"].clear();
|
||||
level.clear_children("replay");
|
||||
|
||||
std::vector<config*> story;
|
||||
play_level(units_data,cfg,&level,disp.video(),state,story);
|
||||
|
@ -824,7 +841,7 @@ int play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
|
||||
gamemap map(cfg,map_data);
|
||||
|
||||
SDL_Surface* const mini = image::getMinimap(175,175,map);
|
||||
const scoped_sdl_surface mini(image::getMinimap(175,175,map));
|
||||
|
||||
if(mini != NULL) {
|
||||
rect.x = ((disp.x()-width)/2+10)+20;
|
||||
|
|
|
@ -59,10 +59,9 @@ GAME_LIST_RESULT manage_game_list(display& disp, const config* gamelist)
|
|||
gui::OK_CANCEL,NULL,NULL,"Name:",&name);
|
||||
if(res == 0) {
|
||||
config response;
|
||||
config create_game;
|
||||
config& create_game = response.add_child("create_game");;
|
||||
create_game["name"] = name;
|
||||
response.children["create_game"].push_back(
|
||||
new config(create_game));
|
||||
|
||||
network::send_data(response);
|
||||
|
||||
return CREATE_GAME;
|
||||
|
@ -75,9 +74,10 @@ GAME_LIST_RESULT manage_game_list(display& disp, const config* gamelist)
|
|||
assert(i.second - i.first > int(index));
|
||||
const std::string& id = (**(i.first+index))["id"];
|
||||
|
||||
config response, join;
|
||||
config response;
|
||||
config& join = response.add_child("join");
|
||||
join["id"] = id;
|
||||
response.children["join"].push_back(new config(join));
|
||||
|
||||
network::send_data(response);
|
||||
|
||||
return JOIN_GAME;
|
||||
|
@ -271,18 +271,16 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
std::vector<bool> changes_allowed;
|
||||
choices.push_back(string_table["observer"]);
|
||||
|
||||
std::vector<config*>& sides_list = sides.children["side"];
|
||||
for(std::vector<config*>::iterator s = sides_list.begin();
|
||||
s != sides_list.end(); ++s) {
|
||||
if((*s)->values["controller"] == "network" &&
|
||||
(*s)->values["taken"] != "yes") {
|
||||
const config::child_list& sides_list = sides.get_children("side");
|
||||
for(config::child_list::const_iterator s = sides_list.begin(); s != sides_list.end(); ++s) {
|
||||
if((**s)["controller"] == "network" &&
|
||||
(**s)["taken"] != "yes") {
|
||||
choice_map[choices.size()] = 1 + s - sides_list.begin();
|
||||
choices.push_back((*s)->values["name"] + " - " +
|
||||
(*s)->values["type"]);
|
||||
choices.push_back((**s)["name"] + " - " + (**s)["type"]);
|
||||
}
|
||||
|
||||
race_names.push_back((*s)->values["name"]);
|
||||
changes_allowed.push_back((*s)->values["allow_changes"] != "no");
|
||||
race_names.push_back((**s)["name"]);
|
||||
changes_allowed.push_back((**s)["allow_changes"] != "no");
|
||||
}
|
||||
|
||||
const int choice = gui::show_dialog(disp,NULL,"","Choose side:",
|
||||
|
@ -306,8 +304,7 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
response["side"] = stream.str();
|
||||
response["description"] = preferences::login();
|
||||
|
||||
const std::vector<config*>& possible_sides =
|
||||
cfg.children["multiplayer_side"];
|
||||
const config::child_list& possible_sides = cfg.get_children("multiplayer_side");
|
||||
if(possible_sides.empty()) {
|
||||
std::cerr << "no multiplayer sides found\n";
|
||||
return;
|
||||
|
@ -316,7 +313,7 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
size_t choice = 0;
|
||||
|
||||
std::vector<std::string> choices;
|
||||
for(std::vector<config*>::const_iterator side =
|
||||
for(config::child_list::const_iterator side =
|
||||
possible_sides.begin(); side != possible_sides.end(); ++side) {
|
||||
choices.push_back((**side)["name"]);
|
||||
|
||||
|
@ -361,14 +358,12 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
//we want to make the network/human players look right from our
|
||||
//perspective
|
||||
{
|
||||
std::vector<config*>& sides_list = sides.children["side"];
|
||||
for(std::vector<config*>::iterator side = sides_list.begin();
|
||||
side != sides_list.end(); ++side) {
|
||||
string_map& values = (*side)->values;
|
||||
const config::child_list& sides_list = sides.get_children("side");
|
||||
for(config::child_list::const_iterator side = sides_list.begin(); side != sides_list.end(); ++side) {
|
||||
if(team_num-1 == side - sides_list.begin())
|
||||
values["controller"] = preferences::client_type();
|
||||
(**side)["controller"] = preferences::client_type();
|
||||
else
|
||||
values["controller"] = "network";
|
||||
(**side)["controller"] = "network";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,7 +389,7 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
}
|
||||
}
|
||||
|
||||
sides.children["replay"].clear();
|
||||
sides.clear_children("replay");
|
||||
}
|
||||
|
||||
std::cerr << "starting game\n";
|
||||
|
|
|
@ -24,8 +24,7 @@ RESULT enter(display& disp, config& game_data)
|
|||
|
||||
gui::textbox message_entry(disp,500);
|
||||
|
||||
SDL_Surface* const background = image::get_image("misc/lobby.png",
|
||||
image::UNSCALED);
|
||||
const scoped_sdl_surface background(image::get_image("misc/lobby.png",image::UNSCALED));
|
||||
|
||||
update_whole_screen();
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
||||
config* level, CVideo& video,
|
||||
game_state& state_of_game,
|
||||
std::vector<config*>& story)
|
||||
const std::vector<config*>& story)
|
||||
{
|
||||
const int num_turns = atoi(level->values["turns"].c_str());
|
||||
gamestatus status(*level,num_turns);
|
||||
|
@ -49,13 +49,11 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
|
||||
int first_human_team = -1;
|
||||
|
||||
std::vector<config*>& unit_cfg = level->children["side"];
|
||||
for(std::vector<config*>::iterator ui = unit_cfg.begin();
|
||||
ui != unit_cfg.end(); ++ui) {
|
||||
const config::child_list& unit_cfg = level->get_children("side");
|
||||
for(config::child_list::const_iterator ui = unit_cfg.begin(); ui != unit_cfg.end(); ++ui) {
|
||||
unit new_unit(gameinfo, **ui);
|
||||
if(ui == unit_cfg.begin()) {
|
||||
for(std::vector<unit>::iterator it =
|
||||
state_of_game.available_units.begin();
|
||||
for(std::vector<unit>::iterator it = state_of_game.available_units.begin();
|
||||
it != state_of_game.available_units.end(); ++it) {
|
||||
if(it->can_recruit()) {
|
||||
new_unit = *it;
|
||||
|
@ -103,12 +101,12 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
}
|
||||
|
||||
//if there are additional starting units on this side
|
||||
std::vector<config*>& starting_units = (*ui)->children["unit"];
|
||||
for(std::vector<config*>::iterator su = starting_units.begin();
|
||||
const config::child_list& starting_units = (*ui)->get_children("unit");
|
||||
for(config::child_list::const_iterator su = starting_units.begin();
|
||||
su != starting_units.end(); ++su) {
|
||||
unit new_unit(gameinfo,**su);
|
||||
const std::string& x = (*su)->values["x"];
|
||||
const std::string& y = (*su)->values["y"];
|
||||
const std::string& x = (**su)["x"];
|
||||
const std::string& y = (**su)["y"];
|
||||
|
||||
const gamemap::location loc(**su);
|
||||
if(x.size() == 0 || y.size() == 0 || !map.on_board(loc)) {
|
||||
|
@ -129,7 +127,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
const tooltips::manager tooltips_manager(gui);
|
||||
|
||||
if(recorder.skipping() == false) {
|
||||
for(std::vector<config*>::iterator story_i = story.begin();
|
||||
for(std::vector<config*>::const_iterator story_i = story.begin();
|
||||
story_i != story.end(); ++story_i) {
|
||||
show_intro(gui,**story_i);
|
||||
}
|
||||
|
@ -146,11 +144,9 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
state_of_game,gameinfo);
|
||||
|
||||
//find a list of 'items' (i.e. overlays) on the level, and add them
|
||||
std::vector<config*>& overlays = level->children["item"];
|
||||
for(std::vector<config*>::iterator overlay = overlays.begin();
|
||||
overlay != overlays.end(); ++overlay) {
|
||||
gui.add_overlay(gamemap::location(**overlay),
|
||||
(*overlay)->values["image"]);
|
||||
const config::child_list& overlays = level->get_children("item");
|
||||
for(config::child_list::const_iterator overlay = overlays.begin(); overlay != overlays.end(); ++overlay) {
|
||||
gui.add_overlay(gamemap::location(**overlay),(**overlay)["image"]);
|
||||
}
|
||||
|
||||
for(unit_map::iterator i = units.begin(); i != units.end(); ++i) {
|
||||
|
@ -269,9 +265,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
|
||||
if(network::nconnections() > 0) {
|
||||
config cfg;
|
||||
cfg.children["turn"].push_back(
|
||||
new config(recorder.get_data_range(start_command,
|
||||
recorder.ncommands())));
|
||||
cfg.add_child("turn",recorder.get_data_range(start_command,recorder.ncommands()));
|
||||
network::send_data(cfg);
|
||||
}
|
||||
|
||||
|
@ -294,13 +288,12 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
map,teams,player_number,units,true);
|
||||
|
||||
for(;;) {
|
||||
network::connection res =
|
||||
network::receive_data(cfg);
|
||||
network::connection res = network::receive_data(cfg);
|
||||
if(res && cfg.child("leave_game")) {
|
||||
throw network::error("");
|
||||
}
|
||||
|
||||
if(res && cfg.children["turn"].empty() == false) {
|
||||
if(res && cfg.child("turn") != NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -308,8 +301,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
gui.draw();
|
||||
}
|
||||
|
||||
std::cerr << "replay: '" << cfg.children["turn"].front()->write() << "'\n";
|
||||
replay replay_obj(*cfg.children["turn"].front());
|
||||
replay replay_obj(*cfg.child("turn"));
|
||||
replay_obj.start_replay();
|
||||
|
||||
try {
|
||||
|
@ -328,7 +320,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
return QUIT;
|
||||
}
|
||||
|
||||
recorder.add_config(*cfg.children["turn"].front());
|
||||
recorder.add_config(*cfg.child("turn"));
|
||||
|
||||
gui.invalidate_all();
|
||||
gui.draw();
|
||||
|
|
|
@ -47,6 +47,6 @@ struct end_level_exception {
|
|||
LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
||||
config* level, CVideo& video,
|
||||
game_state& state_of_game,
|
||||
std::vector<config*>& story);
|
||||
const std::vector<config*>& story);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -171,9 +171,7 @@ int turn_info::send_data(int first_command)
|
|||
if(network::nconnections() > 0 && (undo_stack_.empty() || end_turn_) &&
|
||||
first_command < recorder.ncommands()) {
|
||||
config cfg;
|
||||
cfg.children["turn"].push_back(
|
||||
new config(recorder.get_data_range(first_command,
|
||||
recorder.ncommands())));
|
||||
cfg.add_child("turn",recorder.get_data_range(first_command,recorder.ncommands()));
|
||||
network::send_data(cfg);
|
||||
return recorder.ncommands();
|
||||
} else {
|
||||
|
@ -932,8 +930,7 @@ void turn_info::terrain_table()
|
|||
}
|
||||
|
||||
const std::vector<unit> units_list(items.size(),un->second);
|
||||
SDL_Surface* const unit_image =
|
||||
image::get_image(un->second.type().image_profile(),image::UNSCALED);
|
||||
const scoped_sdl_surface unit_image(image::get_image(un->second.type().image_profile(),image::UNSCALED));
|
||||
gui::show_dialog(gui_,unit_image,un->second.type().language_name(),
|
||||
string_table["terrain_info"],
|
||||
gui::MESSAGE,&items,&units_list);
|
||||
|
@ -972,8 +969,7 @@ void turn_info::attack_resistance()
|
|||
}
|
||||
|
||||
const std::vector<unit> units_list(items.size(), un->second);
|
||||
SDL_Surface* const unit_image =
|
||||
image::get_image(un->second.type().image_profile(),image::UNSCALED);
|
||||
const scoped_sdl_surface unit_image(image::get_image(un->second.type().image_profile(),image::UNSCALED));
|
||||
gui::show_dialog(gui_,unit_image,
|
||||
un->second.type().language_name(),
|
||||
string_table["unit_resistance_table"],
|
||||
|
@ -995,8 +991,7 @@ void turn_info::unit_description()
|
|||
options.push_back(string_table["attack_resistance"]);
|
||||
options.push_back(string_table["close_window"]);
|
||||
|
||||
SDL_Surface* const unit_image = image::get_image(
|
||||
un->second.type().image_profile(), image::UNSCALED);
|
||||
const scoped_sdl_surface unit_image(image::get_image(un->second.type().image_profile(), image::UNSCALED));
|
||||
|
||||
const int res = gui::show_dialog(gui_,unit_image,
|
||||
un->second.type().language_name(),
|
||||
|
|
108
src/replay.cpp
108
src/replay.cpp
|
@ -119,38 +119,38 @@ void replay::add_recruit(int value, const gamemap::location& loc)
|
|||
{
|
||||
config* const cmd = add_command();
|
||||
|
||||
config* const val = new config();
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
val->values["value"] = buf;
|
||||
val["value"] = buf;
|
||||
|
||||
sprintf(buf,"%d",loc.x+1);
|
||||
val->values["x"] = buf;
|
||||
val["x"] = buf;
|
||||
|
||||
sprintf(buf,"%d",loc.y+1);
|
||||
val->values["y"] = buf;
|
||||
val["y"] = buf;
|
||||
|
||||
cmd->children["recruit"].push_back(val);
|
||||
cmd->add_child("recruit",val);
|
||||
}
|
||||
|
||||
void replay::add_recall(int value, const gamemap::location& loc)
|
||||
{
|
||||
config* const cmd = add_command();
|
||||
|
||||
config* const val = new config();
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
val->values["value"] = buf;
|
||||
val["value"] = buf;
|
||||
|
||||
sprintf(buf,"%d",loc.x+1);
|
||||
val->values["x"] = buf;
|
||||
val["x"] = buf;
|
||||
|
||||
sprintf(buf,"%d",loc.y+1);
|
||||
val->values["y"] = buf;
|
||||
val["y"] = buf;
|
||||
|
||||
cmd->children["recall"].push_back(val);
|
||||
cmd->add_child("recall",val);
|
||||
}
|
||||
|
||||
void replay::add_movement(const gamemap::location& a,const gamemap::location& b)
|
||||
|
@ -165,30 +165,29 @@ void replay::add_attack(const gamemap::location& a, const gamemap::location& b,
|
|||
add_pos("attack",a,b);
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",weapon);
|
||||
current_->children["attack"][0]->values["weapon"] = buf;
|
||||
current_->child("attack")->values["weapon"] = buf;
|
||||
}
|
||||
|
||||
void replay::add_pos(const std::string& type,
|
||||
const gamemap::location& a, const gamemap::location& b)
|
||||
{
|
||||
config* const cmd = add_command();
|
||||
config* const move = new config();
|
||||
config* const src = new config();
|
||||
config* const dst = new config();
|
||||
|
||||
config move, src, dst;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",a.x+1);
|
||||
src->values["x"] = buf;
|
||||
src["x"] = buf;
|
||||
sprintf(buf,"%d",a.y+1);
|
||||
src->values["y"] = buf;
|
||||
src["y"] = buf;
|
||||
sprintf(buf,"%d",b.x+1);
|
||||
dst->values["x"] = buf;
|
||||
dst["x"] = buf;
|
||||
sprintf(buf,"%d",b.y+1);
|
||||
dst->values["y"] = buf;
|
||||
dst["y"] = buf;
|
||||
|
||||
move->children["source"].push_back(src);
|
||||
move->children["destination"].push_back(dst);
|
||||
cmd->children[type].push_back(move);
|
||||
move.add_child("source",src);
|
||||
move.add_child("destination",dst);
|
||||
cmd->add_child(type,move);
|
||||
|
||||
current_ = cmd;
|
||||
}
|
||||
|
@ -197,13 +196,13 @@ void replay::add_value(const std::string& type, int value)
|
|||
{
|
||||
config* const cmd = add_command();
|
||||
|
||||
config* const val = new config();
|
||||
config val;
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",value);
|
||||
val->values["value"] = buf;
|
||||
val["value"] = buf;
|
||||
|
||||
cmd->children[type].push_back(val);
|
||||
cmd->add_child(type,val);
|
||||
}
|
||||
|
||||
void replay::choose_option(int index)
|
||||
|
@ -214,8 +213,7 @@ void replay::choose_option(int index)
|
|||
void replay::end_turn()
|
||||
{
|
||||
config* const cmd = add_command();
|
||||
|
||||
cmd->children["end_turn"].push_back(new config());
|
||||
cmd->add_child("end_turn");
|
||||
}
|
||||
|
||||
config replay::get_data_range(int cmd_start, int cmd_end)
|
||||
|
@ -224,9 +222,9 @@ config replay::get_data_range(int cmd_start, int cmd_end)
|
|||
|
||||
config res;
|
||||
|
||||
std::vector<config*>& cmd = commands();
|
||||
const config::child_list& cmd = commands();
|
||||
while(cmd_start < cmd_end) {
|
||||
res.children["command"].push_back(new config(*cmd[cmd_start]));
|
||||
res.add_child("command",*cmd[cmd_start]);
|
||||
++cmd_start;
|
||||
}
|
||||
|
||||
|
@ -235,16 +233,16 @@ config replay::get_data_range(int cmd_start, int cmd_end)
|
|||
|
||||
void replay::undo()
|
||||
{
|
||||
std::vector<config*>& cmd = commands();
|
||||
if(!cmd.empty()) {
|
||||
delete cmd.back();
|
||||
cmd.pop_back();
|
||||
const config::child_itors& cmd = cfg_.child_range("command");
|
||||
if(cmd.first != cmd.second) {
|
||||
delete *(cmd.second-1);
|
||||
cfg_.remove_child("command",cmd.second - cmd.first - 1);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<config*>& replay::commands()
|
||||
const config::child_list& replay::commands()
|
||||
{
|
||||
return cfg_.children["command"];
|
||||
return cfg_.get_children("command");
|
||||
}
|
||||
|
||||
int replay::ncommands()
|
||||
|
@ -261,10 +259,7 @@ void replay::mark_current()
|
|||
|
||||
config* replay::add_command()
|
||||
{
|
||||
config* const cmd = new config();
|
||||
commands().push_back(cmd);
|
||||
current_ = cmd;
|
||||
return cmd;
|
||||
return current_ = &cfg_.add_child("command");
|
||||
}
|
||||
|
||||
int replay::get_random()
|
||||
|
@ -279,20 +274,19 @@ int replay::get_random()
|
|||
//the end of the list. Generating a new random number means
|
||||
//nesting a new node inside the current node, and making
|
||||
//the current node the new node
|
||||
std::vector<config*>& random = current_->children["random"];
|
||||
if(random.empty()) {
|
||||
config* const random = current_->child("random");
|
||||
if(random == NULL) {
|
||||
const int res = rand();
|
||||
current_ = ¤t_->add_child("random");
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",res);
|
||||
|
||||
current_ = new config();
|
||||
current_->values["value"] = buf;
|
||||
random.push_back(current_);
|
||||
(*current_)["value"] = buf;
|
||||
|
||||
return res;
|
||||
} else {
|
||||
const int res = atol(random.front()->values["value"].c_str());
|
||||
current_ = random.front();
|
||||
const int res = atol((*random)["value"].c_str());
|
||||
current_ = random;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -306,8 +300,8 @@ const config* replay::get_random_results() const
|
|||
void replay::set_random_results(const config& cfg)
|
||||
{
|
||||
assert(current_ != NULL);
|
||||
current_->children["results"].clear();
|
||||
current_->children["results"].push_back(new config(cfg));
|
||||
current_->clear_children("results");
|
||||
current_->add_child("results",cfg);
|
||||
}
|
||||
|
||||
void replay::start_replay()
|
||||
|
@ -344,7 +338,7 @@ void replay::add_config(const config& cfg)
|
|||
{
|
||||
for(config::const_child_itors i = cfg.child_range("command");
|
||||
i.first != i.second; ++i.first) {
|
||||
commands().push_back(new config(**i.first));
|
||||
cfg_.add_child("command",**i.first);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -460,11 +454,11 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
|
||||
config* const move = it->second.front();
|
||||
|
||||
assert(!move->children["destination"].empty());
|
||||
assert(!move->children["source"].empty());
|
||||
assert(move->child("destination") != NULL);
|
||||
assert(move->child("source") != NULL);
|
||||
|
||||
const gamemap::location src(*(move->children["source"][0]));
|
||||
const gamemap::location dst(*(move->children["destination"][0]));
|
||||
const gamemap::location src(*(move->child("source")));
|
||||
const gamemap::location dst(*(move->child("destination")));
|
||||
|
||||
const std::map<gamemap::location,unit>::iterator u=units.find(src);
|
||||
if(u == units.end()) {
|
||||
|
@ -537,11 +531,11 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
|
||||
config* const move = it->second.front();
|
||||
|
||||
assert(!move->children["destination"].empty());
|
||||
assert(!move->children["source"].empty());
|
||||
assert(move->child("destination") != NULL);
|
||||
assert(move->child("source") != NULL);
|
||||
|
||||
const gamemap::location src(*(move->children["source"][0]));
|
||||
const gamemap::location dst(*(move->children["destination"][0]));
|
||||
const gamemap::location src(*(move->child("source")));
|
||||
const gamemap::location dst(*(move->child("destination")));
|
||||
|
||||
const std::string& weapon = move->values["weapon"];
|
||||
const int weapon_num = atoi(weapon.c_str());
|
||||
|
|
|
@ -77,7 +77,7 @@ private:
|
|||
|
||||
void add_value(const std::string& type, int value);
|
||||
|
||||
std::vector<config*>& commands();
|
||||
const config::child_list& commands();
|
||||
config* add_command();
|
||||
config cfg_;
|
||||
unsigned int pos_;
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
#include "util.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
int sdl_add_ref(SDL_Surface* surface)
|
||||
{
|
||||
if(surface != NULL)
|
||||
return surface->refcount++;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
|
||||
{
|
||||
if(surface == NULL)
|
||||
|
|
|
@ -37,6 +37,8 @@ struct free_sdl_surface {
|
|||
void operator()(SDL_Surface* surface) const { SDL_FreeSurface(surface); }
|
||||
};
|
||||
|
||||
int sdl_add_ref(SDL_Surface* surface);
|
||||
|
||||
typedef util::scoped_resource<SDL_Surface*,free_sdl_surface> scoped_sdl_surface;
|
||||
|
||||
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h);
|
||||
|
|
|
@ -52,6 +52,7 @@ CXX = @CXX@
|
|||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DATADIR = @DATADIR@
|
||||
DATA_FILES = @DATA_FILES@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
config construct_error(const std::string& msg)
|
||||
{
|
||||
config cfg;
|
||||
config* const err = new config();
|
||||
(*err)["message"] = msg;
|
||||
cfg.children["error"].push_back(err);
|
||||
cfg.add_child("error")["message"] = msg;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
@ -30,12 +28,11 @@ void run_server()
|
|||
const network::server_manager server;
|
||||
|
||||
config login_response;
|
||||
login_response.children["mustlogin"].push_back(new config());
|
||||
login_response.add_child("mustlogin");
|
||||
login_response["version"] = game_config::version;
|
||||
|
||||
config initial_response;
|
||||
initial_response.children["gamelist"].push_back(new config());
|
||||
config& gamelist = *initial_response.children["gamelist"].back();
|
||||
config& gamelist = initial_response.add_child("gamelist");
|
||||
|
||||
typedef std::map<network::connection,player> player_map;
|
||||
player_map players;
|
||||
|
@ -93,11 +90,9 @@ void run_server()
|
|||
continue;
|
||||
}
|
||||
|
||||
config* const player_cfg = new config();
|
||||
config* const player_cfg = &initial_response.add_child("user");
|
||||
const player new_player(username,*player_cfg);
|
||||
players.insert(std::pair<network::connection,player>(
|
||||
sock,new_player));
|
||||
initial_response.children["user"].push_back(player_cfg);
|
||||
players.insert(std::pair<network::connection,player>(sock,new_player));
|
||||
|
||||
//remove player from the not-logged-in list and place
|
||||
//the player in the lobby
|
||||
|
@ -185,11 +180,10 @@ void run_server()
|
|||
if(!is_init) {
|
||||
|
||||
//update our config object which describes the
|
||||
//open games
|
||||
gamelist.children["game"].push_back(
|
||||
new config(g->level()));
|
||||
g->set_description(
|
||||
gamelist.children["game"].back());
|
||||
//open games, and notifies the game of where its description
|
||||
//is located at
|
||||
config& desc = gamelist.add_child("game",g->level());
|
||||
g->set_description(&desc);
|
||||
|
||||
//send all players in the lobby the list of games
|
||||
lobby_players.send_data(initial_response);
|
||||
|
@ -235,16 +229,14 @@ void run_server()
|
|||
g->send_data(cfg);
|
||||
|
||||
//delete the game's description
|
||||
config* const gamelist =
|
||||
initial_response.child("gamelist");
|
||||
config* const gamelist = initial_response.child("gamelist");
|
||||
assert(gamelist != NULL);
|
||||
std::vector<config*>& vg =
|
||||
gamelist->children["game"];
|
||||
std::vector<config*>::iterator desc =
|
||||
std::find(vg.begin(),vg.end(),g->description());
|
||||
if(desc != vg.end()) {
|
||||
const config::child_itors vg = gamelist->child_range("game");
|
||||
|
||||
const config::child_iterator desc = std::find(vg.first,vg.second,g->description());
|
||||
if(desc != vg.second) {
|
||||
delete *desc;
|
||||
vg.erase(desc);
|
||||
gamelist->remove_child("game",desc - vg.first);
|
||||
}
|
||||
|
||||
//put the players back in the lobby and send
|
||||
|
@ -282,10 +274,11 @@ void run_server()
|
|||
const std::map<network::connection,player>::iterator pl_it =
|
||||
players.find(e.socket);
|
||||
if(pl_it != players.end()) {
|
||||
std::vector<config*>& users =
|
||||
initial_response.children["user"];
|
||||
users.erase(std::find(users.begin(),users.end(),
|
||||
pl_it->second.config_address()));
|
||||
const config::child_list& users = initial_response.get_children("user");
|
||||
const size_t index = std::find(users.begin(),users.end(),pl_it->second.config_address()) - users.begin();
|
||||
if(index < users.size())
|
||||
initial_response.remove_child("user",index);
|
||||
|
||||
players.erase(pl_it);
|
||||
}
|
||||
|
||||
|
@ -299,12 +292,12 @@ void run_server()
|
|||
config* const gamelist =
|
||||
initial_response.child("gamelist");
|
||||
assert(gamelist != NULL);
|
||||
std::vector<config*>& vg = gamelist->children["game"];
|
||||
std::vector<config*>::iterator g =
|
||||
std::find(vg.begin(),vg.end(),i->description());
|
||||
if(g != vg.end()) {
|
||||
const config::child_itors vg = gamelist->child_range("game");
|
||||
const config::child_list::iterator g = std::find(vg.first,vg.second,i->description());
|
||||
if(g != vg.second) {
|
||||
const size_t index = g - vg.first;
|
||||
delete *g;
|
||||
vg.erase(g);
|
||||
gamelist->remove_child("game",index);
|
||||
}
|
||||
|
||||
i->disconnect();
|
||||
|
|
|
@ -44,14 +44,10 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp)
|
|||
{
|
||||
draw_dialog_background(x,y,w,h,disp);
|
||||
|
||||
SDL_Surface* const top = image::get_image("misc/menu-border-top.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const bot = image::get_image("misc/menu-border-bottom.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const left = image::get_image("misc/menu-border-left.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const right = image::get_image("misc/menu-border-right.png",
|
||||
image::UNSCALED);
|
||||
const scoped_sdl_surface top(image::get_image("misc/menu-border-top.png",image::UNSCALED));
|
||||
const scoped_sdl_surface bot(image::get_image("misc/menu-border-bottom.png",image::UNSCALED));
|
||||
const scoped_sdl_surface left(image::get_image("misc/menu-border-left.png",image::UNSCALED));
|
||||
const scoped_sdl_surface right(image::get_image("misc/menu-border-right.png",image::UNSCALED));
|
||||
|
||||
if(top == NULL || bot == NULL || left == NULL || right == NULL)
|
||||
return;
|
||||
|
@ -82,14 +78,10 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp)
|
|||
|
||||
update_rect(x-left->w,y-top->h,w+left->w+right->w,h+top->h+bot->h);
|
||||
|
||||
SDL_Surface* const top_left = image::get_image("misc/menu-border-topleft.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const bot_left = image::get_image("misc/menu-border-botleft.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const top_right = image::get_image("misc/menu-border-topright.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const bot_right = image::get_image("misc/menu-border-botright.png",
|
||||
image::UNSCALED);
|
||||
const scoped_sdl_surface top_left(image::get_image("misc/menu-border-topleft.png",image::UNSCALED));
|
||||
const scoped_sdl_surface bot_left(image::get_image("misc/menu-border-botleft.png",image::UNSCALED));
|
||||
const scoped_sdl_surface top_right(image::get_image("misc/menu-border-topright.png",image::UNSCALED));
|
||||
const scoped_sdl_surface bot_right(image::get_image("misc/menu-border-botright.png",image::UNSCALED));
|
||||
if(top_left == NULL || bot_left == NULL || top_right == NULL ||
|
||||
bot_right == NULL)
|
||||
return;
|
||||
|
@ -104,7 +96,7 @@ void draw_dialog_background(int x, int y, int w, int h, display& disp)
|
|||
{
|
||||
static const std::string menu_background = "misc/menu-background.png";
|
||||
|
||||
SDL_Surface* const bg = image::get_image(menu_background,image::UNSCALED);
|
||||
const scoped_sdl_surface bg(image::get_image(menu_background,image::UNSCALED));
|
||||
|
||||
for(int i = 0; i < w; i += bg->w) {
|
||||
for(int j = 0; j < h; j += bg->h) {
|
||||
|
@ -646,8 +638,7 @@ TITLE_RESULT show_title(display& screen)
|
|||
{
|
||||
const events::resize_lock prevent_resizing;
|
||||
|
||||
SDL_Surface* const title_surface = image::get_image("title.png",
|
||||
image::UNSCALED);
|
||||
const scoped_sdl_surface title_surface(image::get_image("title.png",image::UNSCALED));
|
||||
|
||||
if(title_surface == NULL) {
|
||||
std::cerr << "Could not find title image 'title.png'\n";
|
||||
|
|
|
@ -52,6 +52,7 @@ CXX = @CXX@
|
|||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DATADIR = @DATADIR@
|
||||
DATA_FILES = @DATA_FILES@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
|
|
|
@ -46,7 +46,7 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::vector<config*> translations = cfg.children["language"];
|
||||
config::child_list translations = cfg.get_children("language");
|
||||
if(translations.empty()) {
|
||||
std::cerr << "no translation data found in '" << argv[1] << "'\n";
|
||||
return 0;
|
||||
|
@ -66,7 +66,7 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
translations = cfg.children["language"];
|
||||
translations = cfg.get_children("language");
|
||||
if(translations.empty()) {
|
||||
std::cerr << "no translation data found in '" << argv[2] << "'\n";
|
||||
return 0;
|
||||
|
|
20
src/unit.cpp
20
src/unit.cpp
|
@ -99,6 +99,9 @@ unit::unit(const unit_type* t, const unit& u) :
|
|||
{
|
||||
//apply modifications etc, refresh the unit
|
||||
new_level();
|
||||
|
||||
//generate traits for the unit if it doesn't already have some
|
||||
generate_traits();
|
||||
}
|
||||
|
||||
void unit::generate_traits()
|
||||
|
@ -393,13 +396,11 @@ bool unit::has_flag(const std::string& flag) const
|
|||
|
||||
void unit::read(game_data& data, const config& cfg)
|
||||
{
|
||||
std::map<std::string,unit_type>::iterator i = data.unit_types.find(
|
||||
cfg["type"]);
|
||||
std::map<std::string,unit_type>::iterator i = data.unit_types.find(cfg["type"]);
|
||||
if(i != data.unit_types.end())
|
||||
type_ = &i->second;
|
||||
else
|
||||
throw gamestatus::load_game_failed("Unit not found: '"
|
||||
+ cfg["type"] + "'");
|
||||
throw gamestatus::load_game_failed("Unit not found: '" + cfg["type"] + "'" + " : " + cfg.write() + "'\n");
|
||||
|
||||
assert(type_ != NULL);
|
||||
|
||||
|
@ -501,7 +502,7 @@ void unit::write(config& cfg) const
|
|||
status_flags[*st] = "on";
|
||||
}
|
||||
|
||||
cfg.children["status"].push_back(new config(status_flags));
|
||||
cfg.add_child("status",status_flags);
|
||||
|
||||
cfg["user_description"] = description_;
|
||||
cfg["description"] = underlying_description_;
|
||||
|
@ -511,7 +512,7 @@ void unit::write(config& cfg) const
|
|||
if(can_recruit())
|
||||
cfg["canrecruit"] = "1";
|
||||
|
||||
cfg.children["modifications"].push_back(new config(modifications_));
|
||||
cfg.add_child("modifications",modifications_);
|
||||
|
||||
cfg["facing"] = facingLeft_ ? "normal" : "reverse";
|
||||
|
||||
|
@ -670,7 +671,7 @@ void unit::add_modification(const std::string& type,
|
|||
const std::string& span = mod["duration"];
|
||||
|
||||
if(no_add == false && (span.empty() || span == "forever"))
|
||||
modifications_.children[type].push_back(new config(mod));
|
||||
modifications_.add_child(type,mod);
|
||||
|
||||
for(config::const_child_itors i = mod.child_range("effect");
|
||||
i.first != i.second; ++i.first) {
|
||||
|
@ -768,9 +769,8 @@ void unit::apply_modifications()
|
|||
log_scope("apply mods");
|
||||
for(int i = 0; i != NumModificationTypes; ++i) {
|
||||
const std::string& mod = ModificationTypes[i];
|
||||
const std::vector<config*>& mods = modifications_.children[mod];
|
||||
for(std::vector<config*>::const_iterator j = mods.begin();
|
||||
j != mods.end(); ++j) {
|
||||
const config::child_list& mods = modifications_.get_children(mod);
|
||||
for(config::child_list::const_iterator j = mods.begin(); j != mods.end(); ++j) {
|
||||
log_scope("add mod");
|
||||
add_modification(ModificationTypes[i],**j,true);
|
||||
}
|
||||
|
|
|
@ -31,27 +31,26 @@ button::button(display& disp, const std::string& label, button::TYPE type,
|
|||
x_(0), y_(0), button_(true),
|
||||
state_(UNINIT), type_(type)
|
||||
{
|
||||
SDL_Surface* button_image =
|
||||
image::get_image("buttons/button.png",image::UNSCALED);
|
||||
SDL_Surface* pressed_image =
|
||||
image::get_image("buttons/button-pressed.png", image::UNSCALED);
|
||||
SDL_Surface* active_image =
|
||||
image::get_image("buttons/button-active.png", image::UNSCALED);
|
||||
scoped_sdl_surface button_image(image::get_image("buttons/button.png",image::UNSCALED));
|
||||
scoped_sdl_surface pressed_image(image::get_image("buttons/button-pressed.png", image::UNSCALED));
|
||||
scoped_sdl_surface active_image(image::get_image("buttons/button-active.png", image::UNSCALED));
|
||||
|
||||
if(!button_image_name.empty()) {
|
||||
button_image = image::get_image("buttons/" + button_image_name +
|
||||
"-button.png", image::UNSCALED);
|
||||
pressed_image = image::get_image("buttons/" + button_image_name +
|
||||
"-button-pressed.png",image::UNSCALED);
|
||||
active_image = image::get_image("buttons/" + button_image_name +
|
||||
"-button-active.png",image::UNSCALED);
|
||||
button_image.assign(image::get_image("buttons/" + button_image_name +
|
||||
"-button.png", image::UNSCALED));
|
||||
pressed_image.assign(image::get_image("buttons/" + button_image_name +
|
||||
"-button-pressed.png",image::UNSCALED));
|
||||
active_image.assign(image::get_image("buttons/" + button_image_name +
|
||||
"-button-active.png",image::UNSCALED));
|
||||
}
|
||||
|
||||
if(pressed_image == NULL)
|
||||
pressed_image = button_image;
|
||||
if(pressed_image == NULL) {
|
||||
pressed_image.assign(image::get_image("buttons/button.png",image::UNSCALED));
|
||||
}
|
||||
|
||||
if(active_image == NULL)
|
||||
active_image = button_image;
|
||||
if(active_image == NULL) {
|
||||
active_image.assign(image::get_image("buttons/button.png",image::UNSCALED));
|
||||
}
|
||||
|
||||
if(button_image == NULL)
|
||||
throw error();
|
||||
|
|
|
@ -59,7 +59,7 @@ slider& slider::operator=(const slider& o)
|
|||
|
||||
int slider::height(display& disp)
|
||||
{
|
||||
SDL_Surface* const image = image::get_image(slider_image,image::UNSCALED);
|
||||
const scoped_sdl_surface image(image::get_image(slider_image,image::UNSCALED));
|
||||
if(image != NULL)
|
||||
return image->h;
|
||||
else
|
||||
|
@ -70,7 +70,7 @@ void slider::draw()
|
|||
{
|
||||
drawn_ = true;
|
||||
|
||||
SDL_Surface* const image = image::get_image(highlight_ ? selected_image : slider_image,image::UNSCALED);
|
||||
const scoped_sdl_surface image(image::get_image(highlight_ ? selected_image : slider_image,image::UNSCALED));
|
||||
if(image == NULL || buffer_ == NULL)
|
||||
return;
|
||||
|
||||
|
@ -96,7 +96,7 @@ void slider::draw()
|
|||
|
||||
double slider::process(int mousex, int mousey, bool button)
|
||||
{
|
||||
SDL_Surface* const img = image::get_image(slider_image,image::UNSCALED);
|
||||
const scoped_sdl_surface img(image::get_image(slider_image,image::UNSCALED));
|
||||
if(img == NULL)
|
||||
return 0.0;
|
||||
|
||||
|
@ -148,7 +148,7 @@ double slider::process(int mousex, int mousey, bool button)
|
|||
SDL_Rect slider::slider_area() const
|
||||
{
|
||||
static const SDL_Rect default_value = {0,0,0,0};
|
||||
SDL_Surface* const img = image::get_image(slider_image,image::UNSCALED);
|
||||
const scoped_sdl_surface img(image::get_image(slider_image,image::UNSCALED));
|
||||
if(img == NULL)
|
||||
return default_value;
|
||||
|
||||
|
@ -164,7 +164,7 @@ SDL_Rect slider::slider_area() const
|
|||
|
||||
void slider::background_changed()
|
||||
{
|
||||
SDL_Surface* const img = image::get_image(slider_image,image::UNSCALED);
|
||||
const scoped_sdl_surface img(image::get_image(slider_image,image::UNSCALED));
|
||||
if(img != NULL) {
|
||||
area_.h = img->h;
|
||||
buffer_.assign(get_surface_portion(disp_->video().getSurface(),area_));
|
||||
|
|
Loading…
Add table
Reference in a new issue