2009-05-20 13:08:56 +03:00
# include "../stdafx.h"
2008-08-02 18:08:03 +03:00
# include "CPreGame.h"
2009-05-20 13:08:56 +03:00
# include "../hch/CDefHandler.h"
2009-01-12 22:05:56 +02:00
# include <ctime>
2008-12-21 21:17:35 +02:00
# include <SDL.h>
# include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
# include <boost/algorithm/string.hpp>
2008-08-02 18:08:03 +03:00
//#include "boost/foreach.hpp"
2008-12-21 21:17:35 +02:00
# include <zlib.h>
2009-05-20 13:08:56 +03:00
# include "../timeHandler.h"
2008-08-02 18:08:03 +03:00
# include <sstream>
# include "SDL_Extensions.h"
# include "CGameInfo.h"
2009-05-20 13:08:56 +03:00
# include "../hch/CGeneralTextHandler.h"
2008-08-02 18:08:03 +03:00
# include "CCursorHandler.h"
2009-05-20 13:08:56 +03:00
# include "../hch/CLodHandler.h"
# include "../hch/CTownHandler.h"
# include "../hch/CHeroHandler.h"
2008-08-02 18:08:03 +03:00
# include <cmath>
2009-05-20 13:08:56 +03:00
# include "Graphics.h"
2008-08-02 18:08:03 +03:00
# include <boost/thread.hpp>
# include <boost/bind.hpp>
2008-12-21 21:17:35 +02:00
# include <cstdlib>
2009-05-20 13:08:56 +03:00
# include "../lib/Connection.h"
# include "../hch/CMusicHandler.h"
2009-04-15 17:03:31 +03:00
/*
* CPreGame . cpp , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
2008-08-02 18:08:03 +03:00
extern SDL_Surface * screen ;
extern SDL_Color tytulowy , tlo , zwykly ;
extern TTF_Font * TNRB16 , * TNR , * GEOR13 , * GEORXX , * GEORM ;
2008-12-21 21:17:35 +02:00
2008-08-04 18:56:36 +03:00
# ifdef min
# undef min
# endif
# ifdef max
# undef max
# endif
2008-08-02 18:08:03 +03:00
CPreGame * CPG ;
namespace fs = boost : : filesystem ;
namespace s = CSDL_Ext ;
2009-05-24 01:57:39 +03:00
static int getNextCastle ( int current , PlayerInfo * ourInf , bool next = true ) //next=flase => previous castle
2009-02-06 13:15:39 +02:00
{
int dir = next ? 1 : - 1 ;
if ( current = = - 2 ) //no castle - no change
return current ;
else if ( current = = - 1 ) //random => first/last available
{
int pom = ( next ) ? ( 0 ) : ( F_NUMBER - 1 ) ; // last or first
for ( ; pom > = 0 & & pom < F_NUMBER ; pom + = dir )
{
if ( ( ( int ) pow ( ( double ) 2 , pom ) ) & ourInf - > allowedFactions )
{
current = pom ;
break ;
}
else continue ;
}
}
else // next/previous available
{
for ( ; ; )
{
current + = dir ;
if ( ( ( int ) pow ( ( double ) 2 , ( int ) current ) ) & ourInf - > allowedFactions )
{
break ;
}
if ( current > = F_NUMBER | | current < 0 )
{
double p1 = log ( ( double ) ourInf - > allowedFactions ) / log ( 2.0f ) + 0.000001f ;
double check = p1 - ( ( int ) p1 ) ;
if ( check < 0.001 )
current = ( int ) p1 ;
else
current = - 1 ;
break ;
}
}
}
return current ;
}
2008-08-06 01:11:32 +03:00
HighButton : : HighButton ( SDL_Rect Pos , CDefHandler * Imgs , bool Sel , int id )
{
type = 0 ;
imgs = Imgs ;
selectable = Sel ;
selected = false ;
state = 0 ;
pos = Pos ;
ID = id ;
highlightable = false ;
2009-01-25 18:19:34 +02:00
freeimgs = false ;
2008-08-06 01:11:32 +03:00
} ;
HighButton : : HighButton ( )
{
2009-01-25 18:19:34 +02:00
freeimgs = true ;
2008-08-06 01:11:32 +03:00
state = 0 ;
}
2009-01-25 18:19:34 +02:00
HighButton : : ~ HighButton ( )
{
if ( freeimgs )
delete imgs ;
}
2008-08-02 18:08:03 +03:00
void HighButton : : show ( )
{
blitAt ( imgs - > ourImages [ state ] . bitmap , pos . x , pos . y ) ;
updateRect ( & pos ) ;
}
2009-01-25 18:19:34 +02:00
void HighButton : : hover ( bool on )
{
if ( ! highlightable ) return ;
int i ;
if ( on )
{
state = i = 3 ;
highlighted = true ;
}
else
{
state = i = 0 ;
highlighted = false ;
}
SDL_BlitSurface ( imgs - > ourImages [ i ] . bitmap , NULL , screen , & pos ) ;
updateRect ( & pos ) ;
}
2008-08-02 18:08:03 +03:00
void HighButton : : press ( bool down )
{
int i ;
if ( down ) state = i = 1 ;
else state = i = 0 ;
SDL_BlitSurface ( imgs - > ourImages [ i ] . bitmap , NULL , screen , & pos ) ;
updateRect ( & pos ) ;
}
2008-08-06 01:11:32 +03:00
Button : : Button ( SDL_Rect Pos , boost : : function < void ( ) > Fun , CDefHandler * Imgs , bool Sel , CGroup * gr , int id )
: HighButton ( Pos , Imgs , Sel , id ) , ourGroup ( gr ) , fun ( Fun )
{
type = 1 ;
} ;
Button : : Button ( )
{
ourGroup = NULL ; type = 1 ;
} ;
2008-08-02 18:08:03 +03:00
2008-08-06 01:11:32 +03:00
SetrButton : : SetrButton ( )
{
type = 1 ;
selectable = false ;
selected = false ;
state = 0 ;
highlightable = false ;
}
void SetrButton : : press ( bool down )
2008-08-02 18:08:03 +03:00
{
if ( ! down & & state = = 1 )
* poin = key ;
HighButton : : press ( down ) ;
}
2008-08-06 01:11:32 +03:00
void Button : : hover ( bool on )
2008-08-02 18:08:03 +03:00
{
HighButton : : hover ( on ) ;
}
2008-08-06 01:11:32 +03:00
void Button : : select ( bool on )
2008-08-02 18:08:03 +03:00
{
int i ;
if ( on ) state = i = 3 ;
else state = i = 0 ;
SDL_BlitSurface ( imgs - > ourImages [ i ] . bitmap , NULL , screen , & pos ) ;
updateRect ( & pos ) ;
if ( ourGroup & & on & & ourGroup - > type = = 1 )
{
if ( ourGroup - > selected & & ourGroup - > selected ! = this )
ourGroup - > selected - > select ( false ) ;
ourGroup - > selected = this ;
}
}
2008-08-06 01:11:32 +03:00
void Slider : : updateSlid ( )
2008-08-02 18:08:03 +03:00
{
2009-05-30 19:00:26 +03:00
float perc = - 1.0f ;
if ( positionsAmnt > capacity )
perc = ( ( float ) whereAreWe ) / ( ( float ) positionsAmnt - capacity ) ;
else
perc = 0 ;
2008-08-02 18:08:03 +03:00
float myh ;
if ( vertical )
{
myh = perc * ( ( float ) pos . h - 48 ) + pos . y + 16 ;
SDL_FillRect ( screen , & genRect ( pos . h - 32 , pos . w , pos . x , pos . y + 16 ) , 0 ) ;
2008-11-16 03:06:15 +02:00
blitAt ( slider - > imgs - > ourImages [ 0 ] . bitmap , pos . x , ( int ) myh ) ;
slider - > pos . y = ( int ) myh ;
2008-08-02 18:08:03 +03:00
}
else
{
myh = perc * ( ( float ) pos . w - 48 ) + pos . x + 16 ;
SDL_FillRect ( screen , & genRect ( pos . h , pos . w - 32 , pos . x + 16 , pos . y ) , 0 ) ;
2008-11-16 03:06:15 +02:00
blitAt ( slider - > imgs - > ourImages [ 0 ] . bitmap , ( int ) myh , pos . y ) ;
slider - > pos . x = ( int ) myh ;
2008-08-02 18:08:03 +03:00
}
updateRect ( & pos ) ;
}
2008-08-06 01:11:32 +03:00
void Slider : : moveDown ( )
2008-08-02 18:08:03 +03:00
{
if ( whereAreWe < positionsAmnt - capacity )
2008-08-06 01:11:32 +03:00
fun ( + + whereAreWe ) ;
2008-08-02 18:08:03 +03:00
updateSlid ( ) ;
}
2008-08-06 01:11:32 +03:00
void Slider : : moveUp ( )
2008-08-02 18:08:03 +03:00
{
if ( whereAreWe > 0 )
2008-08-06 01:11:32 +03:00
fun ( - - whereAreWe ) ;
2008-08-02 18:08:03 +03:00
updateSlid ( ) ;
}
2008-08-06 01:11:32 +03:00
Slider : : Slider ( int x , int y , int h , int amnt , int cap , bool ver )
2008-08-02 18:08:03 +03:00
{
vertical = ver ;
positionsAmnt = amnt ;
capacity = cap ;
if ( ver )
{
pos = genRect ( h , 16 , x , y ) ;
2008-11-16 03:06:15 +02:00
down = new Button ( genRect ( 16 , 16 , x , y + h - 16 ) , boost : : bind ( & Slider : : moveDown , this ) , CDefHandler : : giveDef ( " SCNRBDN.DEF " ) , false ) ;
up = new Button ( genRect ( 16 , 16 , x , y ) , boost : : bind ( & Slider : : moveUp , this ) , CDefHandler : : giveDef ( " SCNRBUP.DEF " ) , false ) ;
slider = new Button ( genRect ( 16 , 16 , x , y + 16 ) , boost : : function < void ( ) > ( ) , CDefHandler : : giveDef ( " SCNRBSL.DEF " ) , false ) ;
2008-08-02 18:08:03 +03:00
}
else
{
pos = genRect ( 16 , h , x , y ) ;
2008-11-16 03:06:15 +02:00
down = new Button ( genRect ( 16 , 16 , x + h - 16 , y ) , boost : : bind ( & Slider : : moveDown , this ) , CDefHandler : : giveDef ( " SCNRBRT.DEF " ) , false ) ;
up = new Button ( genRect ( 16 , 16 , x , y ) , boost : : bind ( & Slider : : moveUp , this ) , CDefHandler : : giveDef ( " SCNRBLF.DEF " ) , false ) ;
slider = new Button ( genRect ( 16 , 16 , x + 16 , y ) , boost : : function < void ( ) > ( ) , CDefHandler : : giveDef ( " SCNRBSL.DEF " ) , false ) ;
2008-08-02 18:08:03 +03:00
}
moving = false ;
whereAreWe = 0 ;
}
2008-08-06 01:11:32 +03:00
void Slider : : deactivate ( )
2008-08-02 18:08:03 +03:00
{
CPG - > interested . erase ( std : : find ( CPG - > interested . begin ( ) , CPG - > interested . end ( ) , this ) ) ;
}
2008-08-06 01:11:32 +03:00
void Slider : : activate ( )
2008-08-02 18:08:03 +03:00
{
SDL_FillRect ( screen , & pos , 0 ) ;
2008-11-16 03:06:15 +02:00
up - > show ( ) ;
down - > show ( ) ;
slider - > show ( ) ;
2008-08-02 18:08:03 +03:00
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
CPG - > interested . push_back ( this ) ;
}
2008-08-06 01:11:32 +03:00
void Slider : : handleIt ( SDL_Event sEvent )
2008-08-02 18:08:03 +03:00
{
if ( ( sEvent . type = = SDL_MOUSEBUTTONDOWN ) & & ( sEvent . button . button = = SDL_BUTTON_LEFT ) )
{
2008-11-16 03:06:15 +02:00
if ( isItIn ( & down - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
down - > press ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
else if ( isItIn ( & up - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
up - > press ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
else if ( isItIn ( & slider - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
//slider->press();
2008-08-02 18:08:03 +03:00
moving = true ;
}
else if ( isItIn ( & pos , sEvent . motion . x , sEvent . motion . y ) )
{
float dy ;
float pe ;
if ( vertical )
{
dy = sEvent . motion . y - pos . y - 16 ;
pe = dy / ( ( float ) ( pos . h - 32 ) ) ;
if ( pe > 1 ) pe = 1 ;
if ( pe < 0 ) pe = 0 ;
}
else
{
dy = sEvent . motion . x - pos . x - 16 ;
pe = dy / ( ( float ) ( pos . w - 32 ) ) ;
if ( pe > 1 ) pe = 1 ;
if ( pe < 0 ) pe = 0 ;
}
whereAreWe = pe * ( positionsAmnt - capacity ) ;
if ( whereAreWe < 0 ) whereAreWe = 0 ;
updateSlid ( ) ;
2008-08-06 01:11:32 +03:00
fun ( whereAreWe ) ;
2008-08-02 18:08:03 +03:00
}
}
else if ( ( sEvent . type = = SDL_MOUSEBUTTONUP ) & & ( sEvent . button . button = = SDL_BUTTON_LEFT ) )
{
2008-11-16 03:06:15 +02:00
if ( ( down - > state = = 1 ) & & isItIn ( & down - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
this - > down - > fun ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
if ( ( up - > state = = 1 ) & & isItIn ( & up - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
this - > up - > fun ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
if ( down - > state = = 1 ) down - > press ( false ) ;
if ( up - > state = = 1 ) up - > press ( false ) ;
2008-08-02 18:08:03 +03:00
if ( moving )
{
2008-11-16 03:06:15 +02:00
//slider->press();
2008-08-02 18:08:03 +03:00
moving = false ;
}
}
else if ( sEvent . type = = SDL_KEYDOWN )
{
switch ( sEvent . key . keysym . sym )
{
case ( SDLK_UP ) :
2009-05-29 04:50:33 +03:00
CPG - > ourScenSel - > mapsel . moveByX ( - 1 ) ;
2008-08-02 18:08:03 +03:00
break ;
case ( SDLK_DOWN ) :
2009-05-29 04:50:33 +03:00
CPG - > ourScenSel - > mapsel . moveByX ( + 1 ) ;
2008-08-02 18:08:03 +03:00
break ;
2009-05-29 04:50:33 +03:00
case SDLK_PAGEUP :
CPG - > ourScenSel - > mapsel . moveByX ( - CPG - > ourScenSel - > mapsel . slid - > capacity ) ;
break ;
case SDLK_PAGEDOWN :
CPG - > ourScenSel - > mapsel . moveByX ( + CPG - > ourScenSel - > mapsel . slid - > capacity ) ;
break ;
2009-05-29 05:39:12 +03:00
case SDLK_HOME :
CPG - > ourScenSel - > mapsel . moveByX ( - CPG - > ourScenSel - > mapsel . slid - > positionsAmnt ) ;
break ;
case SDLK_END :
CPG - > ourScenSel - > mapsel . moveByX ( + CPG - > ourScenSel - > mapsel . slid - > positionsAmnt ) ;
break ;
2009-05-29 04:50:33 +03:00
default :
//TODO do something nasty here like logs entry..
break ;
}
2008-08-02 18:08:03 +03:00
}
else if ( moving & & sEvent . type = = SDL_MOUSEMOTION )
{
if ( isItIn ( & genRect ( pos . h , pos . w + 64 , pos . x - 32 , pos . y ) , sEvent . motion . x , sEvent . motion . y ) )
{
int my ;
int all ;
float ile ;
if ( vertical )
{
my = sEvent . motion . y - ( pos . y + 16 ) ;
all = pos . h - 48 ;
ile = ( float ) my / ( float ) all ;
if ( ile > 1 ) ile = 1 ;
if ( ile < 0 ) ile = 0 ;
}
else
{
my = sEvent . motion . x - ( pos . x + 16 ) ;
all = pos . w - 48 ;
ile = ( float ) my / ( float ) all ;
if ( ile > 1 ) ile = 1 ;
if ( ile < 0 ) ile = 0 ;
}
int ktory = ile * ( positionsAmnt - capacity ) ;
if ( ktory ! = whereAreWe )
{
whereAreWe = ktory ;
updateSlid ( ) ;
2009-05-01 19:14:29 +03:00
fun ( whereAreWe ) ;
2008-08-02 18:08:03 +03:00
}
}
}
/*else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
if ( ourScenSel - > pressed )
{
ourScenSel - > pressed - > press ( false ) ;
ourScenSel - > pressed = NULL ;
}
for ( int i = 0 ; i < btns . size ( ) ; i + + )
{
if ( isItIn ( & btns [ i ] - > pos , sEvent . motion . x , sEvent . motion . y ) )
{
if ( btns [ i ] - > selectable )
btns [ i ] - > select ( true ) ;
if ( btns [ i ] - > fun )
( this - > * ( btns [ i ] - > fun ) ) ( ) ;
return ;
}
}
2008-11-16 03:06:15 +02:00
if ( isItIn ( & down - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
( this - > * down - > fun ) ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
if ( isItIn ( & up - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
( this - > * up - > fun ) ( ) ;
2008-08-02 18:08:03 +03:00
}
2008-11-16 03:06:15 +02:00
if ( isItIn ( & slider - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-02 18:08:03 +03:00
{
2008-11-16 03:06:15 +02:00
( this - > * slider - > fun ) ( ) ;
2008-08-02 18:08:03 +03:00
}
} */
}
2008-11-16 03:06:15 +02:00
Slider : : ~ Slider ( )
{
delete up ;
delete down ;
delete slider ;
}
2008-08-06 01:11:32 +03:00
IntBut : : IntBut ( )
{
type = 2 ;
fun = NULL ;
highlightable = false ;
}
void IntBut : : set ( )
{
* what = key ;
}
void CPoinGroup : : setYour ( IntSelBut * your )
{
* gdzie = your - > key ;
} ;
IntSelBut : : IntSelBut ( SDL_Rect Pos , boost : : function < void ( ) > Fun , CDefHandler * Imgs , bool Sel , CPoinGroup * gr , int My )
: Button ( Pos , Fun , Imgs , Sel , gr ) , key ( My )
{
ourPoinGroup = gr ;
} ;
void IntSelBut : : select ( bool on )
{
Button : : select ( on ) ;
ourPoinGroup - > setYour ( this ) ;
CPG - > printRating ( ) ;
}
2008-08-02 18:08:03 +03:00
/********************************************************************************************/
void PreGameTab : : show ( )
{
if ( CPG - > currentTab )
CPG - > currentTab - > hide ( ) ;
showed = true ;
CPG - > currentTab = this ;
}
void PreGameTab : : hide ( )
{
showed = false ;
CPG - > currentTab = NULL ;
}
PreGameTab : : PreGameTab ( )
{
showed = false ;
}
/********************************************************************************************/
Options : : PlayerOptions : : PlayerOptions ( int serial , int player )
2009-04-15 13:20:47 +03:00
: flag ( genRect ( 50 , 42 , 14 , 130 + serial * 50 ) , CPG - > ourOptions - > flags [ player ] , player ) ,
Cleft ( genRect ( 24 , 11 , 164 , 133 + serial * 50 ) , CPG - > ourOptions - > left , true , - 1 ) , //left castle arrow
2008-08-02 18:08:03 +03:00
Cright ( genRect ( 24 , 11 , 225 , 133 + serial * 50 ) , CPG - > ourOptions - > right , false , - 1 ) , //right castle arrow
Hleft ( genRect ( 24 , 11 , 240 , 133 + serial * 50 ) , CPG - > ourOptions - > left , true , 0 ) , //left hero arrow
Hright ( genRect ( 24 , 11 , 301 , 133 + serial * 50 ) , CPG - > ourOptions - > right , false , 0 ) , //right hero arrow
Bleft ( genRect ( 24 , 11 , 316 , 133 + serial * 50 ) , CPG - > ourOptions - > left , true , 1 ) , //left bonus arrow
2009-04-15 13:20:47 +03:00
Bright ( genRect ( 24 , 11 , 377 , 133 + serial * 50 ) , CPG - > ourOptions - > right , false , 1 ) //right bonus arrow
2008-08-02 18:08:03 +03:00
{
Bleft . playerID = Bright . playerID = Hleft . playerID = Hright . playerID = Cleft . playerID = Cright . playerID = player ;
Bleft . serialID = Bright . serialID = Hleft . serialID = Hright . serialID = Cleft . serialID = Cright . serialID = serial ;
}
bool Options : : canUseThisHero ( int ID )
{
//TODO: check if hero is allowed on selected map
for ( int i = 0 ; i < CPG - > ret . playerInfos . size ( ) ; i + + )
if ( CPG - > ret . playerInfos [ i ] . hero = = ID )
return false ;
return ( usedHeroes . find ( ID ) = = usedHeroes . end ( ) ) ;
}
int Options : : nextAllowedHero ( int min , int max , int incl , int dir ) //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania
{
if ( dir > 0 )
{
for ( int i = min + incl ; i < = max - incl ; i + + )
{
if ( canUseThisHero ( i ) )
return i ;
}
}
else
{
for ( int i = max - incl ; i > = min + incl ; i - - )
{
if ( canUseThisHero ( i ) )
return i ;
}
}
return - 1 ;
}
2009-02-06 13:15:39 +02:00
2008-08-02 18:08:03 +03:00
void Options : : OptionSwitch : : press ( bool down )
{
HighButton : : press ( down ) ;
2009-02-08 08:42:15 +02:00
PlayerSettings * ourOpt = & CPG - > ret . playerInfos [ serialID ] ;
2009-05-29 04:50:33 +03:00
PlayerInfo * ourInf = & CPG - > ourScenSel - > mapsel . selMaps [ CPG - > ourScenSel - > mapsel . selected ] - > players [ playerID ] ;
2008-08-02 18:08:03 +03:00
int dir = ( left ) ? ( - 1 ) : ( 1 ) ;
if ( down ) return ;
switch ( which ) //which button is this?
{
case - 1 : //castle change
{
2009-02-06 13:15:39 +02:00
int nCas = getNextCastle ( ourOpt - > castle , ourInf , ! left ) ;
if ( nCas ! = ourOpt - > castle ) //changed castle
2008-08-02 18:08:03 +03:00
{
2009-02-06 13:15:39 +02:00
ourOpt - > castle = nCas ;
if ( ourOpt - > hero ! = - 2 )
2008-08-02 18:08:03 +03:00
{
2009-02-06 13:15:39 +02:00
ourOpt - > hero = - 1 ;
CPG - > ourOptions - > showIcon ( 0 , serialID , false ) ;
2008-08-02 18:08:03 +03:00
}
2009-02-08 19:19:42 +02:00
if ( nCas < 0 & & ourOpt - > bonus = = bresource )
2008-08-02 18:08:03 +03:00
{
2009-02-06 13:15:39 +02:00
ourOpt - > bonus = brandom ;
2008-08-02 18:08:03 +03:00
}
2009-02-08 19:19:42 +02:00
CPG - > ourOptions - > showIcon ( 1 , serialID , false ) ;
2008-08-02 18:08:03 +03:00
}
break ;
}
case 0 : //hero change
{
2009-02-11 19:03:30 +02:00
if ( ourOpt - > castle < 0
| | ! ourOpt - > human
)
2008-08-02 18:08:03 +03:00
{
break ;
}
if ( ourOpt - > hero = = - 2 ) //no hero - no change
return ;
else if ( ourOpt - > hero = = - 1 ) //random => first/last available
{
int max = ( ourOpt - > castle * HEROES_PER_TYPE * 2 + 15 ) ,
min = ( ourOpt - > castle * HEROES_PER_TYPE * 2 ) ;
ourOpt - > hero = CPG - > ourOptions - > nextAllowedHero ( min , max , 0 , dir ) ;
}
else
{
if ( dir > 0 )
ourOpt - > hero = CPG - > ourOptions - > nextAllowedHero ( ourOpt - > hero , ( ourOpt - > castle * HEROES_PER_TYPE * 2 + 16 ) , 1 , dir ) ;
else
ourOpt - > hero = CPG - > ourOptions - > nextAllowedHero ( ourOpt - > castle * HEROES_PER_TYPE * 2 - 1 , ourOpt - > hero , 1 , dir ) ;
}
break ;
}
case 1 : //bonus change
{
2009-02-08 19:19:42 +02:00
ourOpt - > bonus + = dir ;
if ( ourOpt - > hero = = - 2 & & ! ourInf - > heroesNames . size ( ) & & ourOpt - > bonus = = bartifact ) //no hero - can't be artifact
2008-08-02 18:08:03 +03:00
{
2009-02-08 19:19:42 +02:00
if ( dir < 0 )
2008-08-02 18:08:03 +03:00
ourOpt - > bonus = brandom ;
else ourOpt - > bonus = bgold ;
}
2009-02-08 19:19:42 +02:00
if ( ourOpt - > bonus > bresource )
ourOpt - > bonus = brandom ;
if ( ourOpt - > bonus < brandom )
ourOpt - > bonus = bresource ;
if ( ourOpt - > castle = = - 1 & & ourOpt - > bonus = = bresource ) //random castle - can't be resource
2008-08-02 18:08:03 +03:00
{
if ( dir < 0 )
ourOpt - > bonus = bgold ;
else ourOpt - > bonus = brandom ;
}
2009-02-08 19:19:42 +02:00
2008-08-02 18:08:03 +03:00
break ;
}
}
CPG - > ourOptions - > showIcon ( which , serialID , false ) ;
}
void Options : : PlayerFlag : : press ( bool down )
{
HighButton : : press ( down ) ;
2008-12-21 21:17:35 +02:00
size_t i = 0 ;
2008-08-02 18:08:03 +03:00
for ( ; i < CPG - > ret . playerInfos . size ( ) ; i + + )
if ( CPG - > ret . playerInfos [ i ] . color = = color )
break ;
2009-05-29 04:50:33 +03:00
if ( CPG - > ret . playerInfos [ i ] . human | | ( ! CPG - > ourScenSel - > mapsel . selMaps [ CPG - > ourScenSel - > mapsel . selected ] - > players [ CPG - > ret . playerInfos [ i ] . color ] . canHumanPlay ) )
2008-08-02 18:08:03 +03:00
return ; //if this is already human player, or if human is forbidden
2008-12-21 21:17:35 +02:00
size_t j = 0 ;
2008-08-02 18:08:03 +03:00
for ( ; j < CPG - > ret . playerInfos . size ( ) ; j + + )
if ( CPG - > ret . playerInfos [ j ] . human )
break ;
CPG - > ret . playerInfos [ i ] . human = true ;
CPG - > ret . playerInfos [ j ] . human = false ;
2009-02-11 19:03:30 +02:00
if ( CPG - > ret . playerInfos [ j ] . hero > = 0 )
{
CPG - > ret . playerInfos [ j ] . hero = - 1 ;
CPG - > ourOptions - > showIcon ( 0 , j , false ) ;
}
2008-08-02 18:08:03 +03:00
std : : string pom = CPG - > ret . playerInfos [ i ] . name ;
CPG - > ret . playerInfos [ i ] . name = CPG - > ret . playerInfos [ j ] . name ;
CPG - > ret . playerInfos [ j ] . name = pom ;
SDL_BlitSurface ( CPG - > ourOptions - > bgs [ CPG - > ret . playerInfos [ i ] . color ] , & genRect ( 19 , 99 , 5 , 1 ) , screen , & genRect ( 19 , 99 , 62 , 129 + i * 50 ) ) ;
SDL_UpdateRect ( screen , 62 , 129 + 50 * i , 99 , 19 ) ;
SDL_BlitSurface ( CPG - > ourOptions - > bgs [ CPG - > ret . playerInfos [ j ] . color ] , & genRect ( 19 , 99 , 5 , 1 ) , screen , & genRect ( 19 , 99 , 62 , 129 + j * 50 ) ) ;
SDL_UpdateRect ( screen , 62 , 129 + 50 * j , 99 , 19 ) ;
CSDL_Ext : : printAtMiddle ( CPG - > ret . playerInfos [ i ] . name , 111 , 137 + i * 50 , GEOR13 , zwykly ) ;
CSDL_Ext : : printAtMiddle ( CPG - > ret . playerInfos [ j ] . name , 111 , 137 + j * 50 , GEOR13 , zwykly ) ;
CPG - > playerColor = CPG - > ret . playerInfos [ i ] . color ;
CPG - > ourScenSel - > mapsel . printFlags ( ) ;
} ;
void Options : : PlayerFlag : : hover ( bool on )
{
HighButton : : hover ( on ) ;
}
void Options : : showIcon ( int what , int nr , bool abs ) //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
{
if ( what = = - 2 )
{
showIcon ( - 1 , nr , abs ) ;
showIcon ( 0 , nr , abs ) ;
showIcon ( 1 , nr , abs ) ;
}
int ab , se ;
if ( ! abs )
{
ab = CPG - > ret . playerInfos [ nr ] . color ;
se = nr ;
}
else
{
ab = nr ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < CPG - > ret . playerInfos . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( CPG - > ret . playerInfos [ i ] . color = = nr )
{
se = i ;
break ;
}
}
}
2009-02-08 08:42:15 +02:00
PlayerSettings * ourOpt = & CPG - > ret . playerInfos [ se ] ;
2008-08-02 18:08:03 +03:00
switch ( what )
{
case - 1 :
{
int pom = ourOpt - > castle ;
if ( ourOpt - > castle < F_NUMBER & & ourOpt - > castle > = 0 )
{
blitAtWR ( graphics - > getPic ( ourOpt - > castle , true , false ) , 176 , 130 + 50 * se ) ;
}
else if ( ourOpt - > castle = = - 1 )
{
blitAtWR ( CPG - > ourOptions - > rCastle , 176 , 130 + 50 * se ) ;
}
else if ( ourOpt - > castle = = - 2 )
{
blitAtWR ( CPG - > ourOptions - > nCastle , 176 , 130 + 50 * se ) ;
}
break ;
}
case 0 :
{
int pom = ourOpt - > hero ;
if ( ourOpt - > hero = = - 1 )
{
blitAtWR ( CPG - > ourOptions - > rHero , 252 , 130 + 50 * se ) ;
}
else if ( ourOpt - > hero = = - 2 )
{
if ( ourOpt - > heroPortrait > = 0 )
{
2008-08-25 13:25:16 +03:00
blitAtWR ( graphics - > portraitSmall [ ourOpt - > heroPortrait ] , 252 , 130 + 50 * se ) ;
2008-08-02 18:08:03 +03:00
}
else
{
blitAtWR ( CPG - > ourOptions - > nHero , 252 , 130 + 50 * se ) ;
}
}
else
{
2008-08-25 13:25:16 +03:00
blitAtWR ( graphics - > portraitSmall [ pom ] , 252 , 130 + 50 * se ) ;
2008-08-02 18:08:03 +03:00
}
break ;
}
case 1 :
{
int pom ;
switch ( ourOpt - > bonus )
{
case - 1 :
pom = 10 ;
break ;
case 0 :
pom = 9 ;
break ;
case 1 :
pom = 8 ;
break ;
case 2 :
pom = CGI - > townh - > towns [ ourOpt - > castle ] . bonus ;
break ;
}
blitAtWR ( bonuses - > ourImages [ pom ] . bitmap , 328 , 130 + 50 * se ) ;
break ;
}
}
}
Options : : ~ Options ( )
{
2008-12-21 21:17:35 +02:00
if ( ! inited ) {
return ;
}
for ( size_t i = 0 ; i < bgs . size ( ) ; i + + ) {
2008-08-02 18:08:03 +03:00
SDL_FreeSurface ( bgs [ i ] ) ;
2008-12-21 21:17:35 +02:00
}
for ( size_t i = 0 ; i < flags . size ( ) ; i + + ) {
2008-08-02 18:08:03 +03:00
delete flags [ i ] ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
SDL_FreeSurface ( bg ) ;
SDL_FreeSurface ( rHero ) ;
SDL_FreeSurface ( rCastle ) ;
SDL_FreeSurface ( nHero ) ;
SDL_FreeSurface ( nCastle ) ;
delete turnLength ;
delete left ;
delete right ;
delete bonuses ;
}
void Options : : init ( )
{
inited = true ;
bg = BitmapHandler : : loadBitmap ( " ADVOPTBK.bmp " ) ;
SDL_SetColorKey ( bg , SDL_SRCCOLORKEY , SDL_MapRGB ( bg - > format , 0 , 255 , 255 ) ) ;
left = CDefHandler : : giveDef ( " ADOPLFA.DEF " ) ;
right = CDefHandler : : giveDef ( " ADOPRTA.DEF " ) ;
bonuses = CDefHandler : : giveDef ( " SCNRSTAR.DEF " ) ;
rHero = BitmapHandler : : loadBitmap ( " HPSRAND1.bmp " ) ;
rCastle = BitmapHandler : : loadBitmap ( " HPSRAND0.bmp " ) ;
nHero = BitmapHandler : : loadBitmap ( " HPSRAND6.bmp " ) ;
nCastle = BitmapHandler : : loadBitmap ( " HPSRAND5.bmp " ) ;
2008-08-06 01:11:32 +03:00
turnLength = new Slider ( 57 , 557 , 195 , 11 , 1 , false ) ;
turnLength - > fun = boost : : bind ( & CPreGame : : setTurnLength , CPG , _1 ) ;
2008-08-02 18:08:03 +03:00
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBR.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBB.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBY.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBG.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBO.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBP.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBT.DEF " ) ) ;
flags . push_back ( CDefHandler : : giveDef ( " AOFLGBS.DEF " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPRPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPBPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPYPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPGPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPOPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPPPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPTPNL.bmp " ) ) ;
bgs . push_back ( BitmapHandler : : loadBitmap ( " ADOPSPNL.bmp " ) ) ;
}
void Options : : show ( )
{
if ( showed ) return ;
PreGameTab : : show ( ) ;
MapSel & ms = CPG - > ourScenSel - > mapsel ;
blitAt ( bg , 3 , 6 ) ;
CPG - > ourScenSel - > listShowed = false ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < CPG - > btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( CPG - > btns [ i ] - > ID ! = 10 ) //leave only right panel buttons
{
CPG - > btns . erase ( CPG - > btns . begin ( ) + i ) ;
i - - ;
}
}
CPG - > interested . clear ( ) ;
CSDL_Ext : : printAtMiddle ( " Advanced Options " , 225 , 35 , GEORXX ) ;
CSDL_Ext : : printAtMiddle ( CGI - > generaltexth - > allTexts [ 521 ] , 224 , 544 , GEOR13 ) ; // Player Turn Duration
int playersSoFar = 0 ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < PLAYER_LIMIT ; + + i )
2008-08-02 18:08:03 +03:00
{
2009-05-29 04:50:33 +03:00
if ( ! ( ms . selMaps [ ms . selected ] - > players [ i ] . canComputerPlay | | ms . selMaps [ ms . selected ] - > players [ i ] . canComputerPlay ) )
2008-08-02 18:08:03 +03:00
continue ;
2009-05-29 04:50:33 +03:00
for ( size_t hi = 0 ; hi < ms . selMaps [ ms . selected ] - > players [ i ] . heroesNames . size ( ) ; hi + + ) {
usedHeroes . insert ( ms . selMaps [ ms . selected ] - > players [ i ] . heroesNames [ hi ] . heroID ) ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
blitAt ( bgs [ i ] , 57 , 128 + playersSoFar * 50 ) ;
poptions . push_back ( new PlayerOptions ( playersSoFar , i ) ) ;
poptions [ poptions . size ( ) - 1 ] - > nr = playersSoFar ;
poptions [ poptions . size ( ) - 1 ] - > color = ( Ecolor ) i ;
2009-02-06 13:15:39 +02:00
2009-02-08 19:19:42 +02:00
if ( CPG - > ret . playerInfos [ playersSoFar ] . hero = = - 1 )
2009-02-06 13:15:39 +02:00
{
poptions [ poptions . size ( ) - 1 ] - > Hleft . show ( ) ;
poptions [ poptions . size ( ) - 1 ] - > Hright . show ( ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > Hleft ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > Hright ) ;
}
2009-05-29 04:50:33 +03:00
if ( getNextCastle ( CPG - > ret . playerInfos [ playersSoFar ] . castle , & ms . selMaps [ ms . selected ] - > players [ i ] ) ! = CPG - > ret . playerInfos [ playersSoFar ] . castle )
2009-02-06 13:15:39 +02:00
{
poptions [ poptions . size ( ) - 1 ] - > Cleft . show ( ) ;
poptions [ poptions . size ( ) - 1 ] - > Cright . show ( ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > Cleft ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > Cright ) ;
}
2008-08-02 18:08:03 +03:00
poptions [ poptions . size ( ) - 1 ] - > Bleft . show ( ) ;
poptions [ poptions . size ( ) - 1 ] - > Bright . show ( ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > Bleft ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > Bright ) ;
2009-02-06 13:15:39 +02:00
2008-08-02 18:08:03 +03:00
CSDL_Ext : : printAtMiddle ( CPG - > ret . playerInfos [ playersSoFar ] . name , 111 , 137 + playersSoFar * 50 , GEOR13 , zwykly ) ;
2009-05-29 04:50:33 +03:00
if ( ms . selMaps [ ms . selected ] - > players [ i ] . canHumanPlay )
2008-08-02 18:08:03 +03:00
{
poptions [ poptions . size ( ) - 1 ] - > flag . show ( ) ;
CPG - > btns . push_back ( & poptions [ poptions . size ( ) - 1 ] - > flag ) ;
2009-05-29 04:50:33 +03:00
if ( ms . selMaps [ ms . selected ] - > players [ i ] . canComputerPlay ) {
2008-08-02 18:08:03 +03:00
CSDL_Ext : : printAtMiddleWB ( " Human or CPU " , 86 , 163 + playersSoFar * 50 , GEORM , 7 , zwykly ) ;
2008-12-21 21:17:35 +02:00
}
else {
2008-08-02 18:08:03 +03:00
CSDL_Ext : : printAtMiddleWB ( " Human " , 86 , 163 + playersSoFar * 50 , GEORM , 6 , zwykly ) ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
}
2008-12-21 21:17:35 +02:00
else {
2008-08-02 18:08:03 +03:00
CSDL_Ext : : printAtMiddleWB ( " CPU " , 86 , 163 + playersSoFar * 50 , GEORM , 6 , zwykly ) ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
playersSoFar + + ;
}
CSDL_Ext : : printAtMiddleWB ( CGI - > generaltexth - > allTexts [ 516 ] , 221 , 63 , GEOR13 , 55 , zwykly ) ;
2008-11-28 03:36:34 +02:00
CSDL_Ext : : printAtMiddleWB ( CGI - > generaltexth - > getTitle ( CGI - > generaltexth - > zelp [ 256 ] . second ) , 109 , 109 , GEOR13 , 14 ) ;
CSDL_Ext : : printAtMiddleWB ( CGI - > generaltexth - > getTitle ( CGI - > generaltexth - > zelp [ 259 ] . second ) , 201 , 109 , GEOR13 , 10 ) ;
CSDL_Ext : : printAtMiddleWB ( CGI - > generaltexth - > getTitle ( CGI - > generaltexth - > zelp [ 260 ] . second ) , 275 , 109 , GEOR13 , 10 ) ;
CSDL_Ext : : printAtMiddleWB ( CGI - > generaltexth - > getTitle ( CGI - > generaltexth - > zelp [ 261 ] . second ) , 354 , 109 , GEOR13 , 10 ) ;
2008-08-02 18:08:03 +03:00
turnLength - > activate ( ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < poptions . size ( ) ; + + i ) {
2008-08-02 18:08:03 +03:00
showIcon ( - 2 , i , false ) ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
for ( int i = 0 ; i < 12 ; i + + )
turnLength - > moveDown ( ) ;
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
}
void Options : : hide ( )
{
2008-12-21 21:17:35 +02:00
if ( ! showed ) {
return ;
}
2008-08-02 18:08:03 +03:00
PreGameTab : : hide ( ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < CPG - > btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
if ( CPG - > btns [ i ] - > ID = = 7 )
CPG - > btns . erase ( CPG - > btns . begin ( ) + i - - ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < poptions . size ( ) ; i + + ) {
2008-08-02 18:08:03 +03:00
delete poptions [ i ] ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
poptions . clear ( ) ;
turnLength - > deactivate ( ) ;
}
MapSel : : ~ MapSel ( )
{
SDL_FreeSurface ( bg ) ;
2009-01-11 00:08:18 +02:00
for ( size_t i = 0 ; i < scenImgs . size ( ) ; + + i )
{
2008-08-02 18:08:03 +03:00
SDL_FreeSurface ( scenImgs [ i ] ) ;
2009-01-11 00:08:18 +02:00
}
2008-08-02 18:08:03 +03:00
delete sFlags ;
}
2009-05-04 02:38:08 +03:00
// Display the tab with the scenario names
//
// elemIdx is the index of the maps or saved game to display on line 0
// slid->capacity contains the number of available screen lines
// slid->positionsAmnt is the number of elements after filtering
void MapSel : : printMaps ( int elemIdx )
2008-08-02 18:08:03 +03:00
{
2009-05-04 02:38:08 +03:00
// Display all elements if there's enough space
2009-01-25 00:17:49 +02:00
if ( slid - > positionsAmnt < slid - > capacity )
2009-05-04 02:38:08 +03:00
elemIdx = 0 ;
2008-08-02 18:08:03 +03:00
SDL_Surface * scenin = CSDL_Ext : : newSurface ( 351 , 25 ) ;
SDL_Color nasz ;
2009-05-04 02:38:08 +03:00
for ( int line = 0 ; line < slid - > capacity ; elemIdx + + )
2008-08-02 18:08:03 +03:00
{
2009-05-29 04:50:33 +03:00
if ( elemIdx > = selMaps . size ( ) ) {
2009-05-04 02:38:08 +03:00
// No elements left to display, so it's an empty line.
SDL_BlitSurface ( bg , & genRect ( 25 , 351 , 22 , 115 + line * 25 ) , scenin , NULL ) ;
blitAt ( scenin , 25 , 121 + line * 25 ) ;
line + + ;
2008-08-02 18:08:03 +03:00
continue ;
}
2009-05-04 02:38:08 +03:00
2009-05-29 04:50:33 +03:00
CMapInfo * curMap = selMaps [ elemIdx ] ;
2009-05-04 02:38:08 +03:00
2009-05-29 04:50:33 +03:00
// Build the line to display.
2009-05-04 02:38:08 +03:00
if ( elemIdx = = selected )
2008-08-02 18:08:03 +03:00
nasz = tytulowy ;
2009-05-04 02:38:08 +03:00
else
nasz = zwykly ;
SDL_BlitSurface ( bg , & genRect ( 25 , 351 , 22 , line * 25 + 115 ) , scenin , NULL ) ;
std : : ostringstream ostr ( std : : ostringstream : : out ) ;
ostr < < curMap - > playerAmnt < < " / " < < curMap - > humenPlayers ;
2008-08-02 18:08:03 +03:00
CSDL_Ext : : printAt ( ostr . str ( ) , 6 , 4 , GEOR13 , nasz , scenin , 2 ) ;
2009-05-04 02:38:08 +03:00
2008-08-02 18:08:03 +03:00
std : : string temp2 ;
2009-05-04 02:38:08 +03:00
switch ( curMap - > width )
2008-08-02 18:08:03 +03:00
{
case 36 :
temp2 = " S " ;
break ;
case 72 :
temp2 = " M " ;
break ;
case 108 :
temp2 = " L " ;
break ;
case 144 :
temp2 = " XL " ;
break ;
default :
temp2 = " C " ;
break ;
}
CSDL_Ext : : printAtMiddle ( temp2 , 50 , 13 , GEOR13 , nasz , scenin , 2 ) ;
2009-05-04 02:38:08 +03:00
int temp = - 1 ;
switch ( curMap - > version )
2008-08-02 18:08:03 +03:00
{
2009-05-07 20:20:41 +03:00
case CMapHeader : : RoE :
2008-08-02 18:08:03 +03:00
temp = 0 ;
break ;
2009-05-07 20:20:41 +03:00
case CMapHeader : : AB :
2008-08-02 18:08:03 +03:00
temp = 1 ;
break ;
2009-05-07 20:20:41 +03:00
case CMapHeader : : SoD :
2008-08-02 18:08:03 +03:00
temp = 2 ;
break ;
2009-05-07 20:20:41 +03:00
case CMapHeader : : WoG :
2008-08-02 18:08:03 +03:00
temp = 3 ;
break ;
2009-05-04 02:38:08 +03:00
default :
// Unknown version. Be safe and ignore that map
tlog2 < < " Warning: " < < curMap - > filename < < " has wrong version! \n " ;
continue ;
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
blitAt ( Dtypes - > ourImages [ temp ] . bitmap , 67 , 2 , scenin ) ;
2009-01-11 00:08:18 +02:00
2009-05-04 02:38:08 +03:00
if ( CPG - > fromMenu = = CPG - > newGame )
2009-01-11 00:08:18 +02:00
{
2009-05-04 02:38:08 +03:00
if ( ! ( curMap - > name . length ( ) ) )
curMap - > name = " Unnamed " ;
CSDL_Ext : : printAtMiddle ( curMap - > name , 192 , 13 , GEOR13 , nasz , scenin , 2 ) ;
2009-01-11 00:08:18 +02:00
}
else
{
2009-05-04 02:38:08 +03:00
std : : string & name = curMap - > filename ;
2009-03-28 02:38:48 +02:00
CSDL_Ext : : printAtMiddle ( name . substr ( 6 , name . size ( ) - 12 ) , 192 , 13 , GEOR13 , nasz , scenin , 2 ) ;
2009-01-11 00:08:18 +02:00
}
2009-05-04 02:38:08 +03:00
if ( curMap - > victoryCondition . condition = = winStandard )
2008-08-02 18:08:03 +03:00
temp = 11 ;
2009-01-06 20:42:20 +02:00
else
2009-05-04 02:38:08 +03:00
temp = curMap - > victoryCondition . condition ;
2008-08-02 18:08:03 +03:00
blitAt ( Dvic - > ourImages [ temp ] . bitmap , 285 , 2 , scenin ) ;
2009-01-06 20:42:20 +02:00
2009-05-04 02:38:08 +03:00
if ( curMap - > lossCondition . typeOfLossCon = = lossStandard )
2008-08-02 18:08:03 +03:00
temp = 3 ;
2009-01-06 20:42:20 +02:00
else
2009-05-04 02:38:08 +03:00
temp = curMap - > lossCondition . typeOfLossCon ;
2008-08-02 18:08:03 +03:00
blitAt ( Dloss - > ourImages [ temp ] . bitmap , 318 , 2 , scenin ) ;
2009-05-04 02:38:08 +03:00
blitAt ( scenin , 25 , 121 + line * 25 ) ;
line + + ;
2008-08-02 18:08:03 +03:00
}
SDL_FreeSurface ( scenin ) ;
2009-05-01 19:14:29 +03:00
SDL_UpdateRect ( screen , 25 , 121 , 351 , 19 * 25 ) ;
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
2008-08-02 18:08:03 +03:00
void MapSel : : hide ( )
{
if ( ! showed ) return ;
PreGameTab : : hide ( ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & small ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & medium ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & large ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & xlarge ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & all ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & nrplayer ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & mapsize ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & type ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & name ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & viccon ) ) ;
CPG - > btns . erase ( std : : find ( CPG - > btns . begin ( ) , CPG - > btns . end ( ) , & loscon ) ) ;
slid - > deactivate ( ) ;
CPG - > currentTab = NULL ;
} ;
void MapSel : : show ( )
{
if ( showed ) return ;
PreGameTab : : show ( ) ;
//blit bg
blitAt ( bg , 3 , 6 ) ;
CSDL_Ext : : printAt ( " Map Sizes " , 55 , 60 , GEOR13 ) ;
2009-05-04 02:38:08 +03:00
CSDL_Ext : : printAt ( CGI - > generaltexth - > arraytxt [ CPG - > fromMenu = = CPG - > newGame ? 229 : 230 ] , 110 , 25 , TNRB16 ) ; //Select a Scenario to Play : Load a Saved Game
2008-08-02 18:08:03 +03:00
//size buttons
small . show ( ) ;
medium . show ( ) ;
large . show ( ) ;
xlarge . show ( ) ;
all . show ( ) ;
CPG - > btns . push_back ( & small ) ;
CPG - > btns . push_back ( & medium ) ;
CPG - > btns . push_back ( & large ) ;
CPG - > btns . push_back ( & xlarge ) ;
CPG - > btns . push_back ( & all ) ;
//sort by buttons
nrplayer . show ( ) ;
mapsize . show ( ) ;
type . show ( ) ;
name . show ( ) ;
viccon . show ( ) ;
loscon . show ( ) ;
CPG - > btns . push_back ( & nrplayer ) ;
CPG - > btns . push_back ( & mapsize ) ;
CPG - > btns . push_back ( & type ) ;
CPG - > btns . push_back ( & name ) ;
CPG - > btns . push_back ( & viccon ) ;
CPG - > btns . push_back ( & loscon ) ;
//print scenario list
2009-05-04 02:38:08 +03:00
printMaps ( ) ;
2008-08-02 18:08:03 +03:00
2009-03-28 02:38:48 +02:00
slid - > whereAreWe = 0 ;
2008-08-02 18:08:03 +03:00
slid - > activate ( ) ;
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
}
2009-02-08 08:42:15 +02:00
void MapSel : : processMaps ( const std : : vector < std : : string > & pliczkiTemp , int start , int threads )
2008-08-02 18:08:03 +03:00
{
2009-02-08 08:42:15 +02:00
int read = 0 ;
2008-11-16 03:06:15 +02:00
unsigned char sss [ 1000 ] ;
2008-11-28 03:36:34 +02:00
while ( true )
2008-08-02 18:08:03 +03:00
{
2009-02-08 08:42:15 +02:00
if ( start > = ourMaps . size ( ) )
2008-08-02 18:08:03 +03:00
break ;
2009-02-08 08:42:15 +02:00
ourMaps [ start ] = NULL ;
gzFile tempf = gzopen ( pliczkiTemp [ start ] . c_str ( ) , " rb " ) ;
2008-11-28 03:36:34 +02:00
read = gzread ( tempf , sss , 1000 ) ;
2008-08-02 18:08:03 +03:00
gzclose ( tempf ) ;
2008-11-28 03:36:34 +02:00
if ( read < 50 )
2008-11-16 03:06:15 +02:00
{
2009-02-08 08:42:15 +02:00
tlog3 < < " \t \t Warning: corrupted map file: " < < pliczkiTemp [ start ] < < std : : endl ;
2008-11-16 03:06:15 +02:00
}
2009-02-08 08:42:15 +02:00
else if ( sss [ 4 ] ) //valid map
2008-11-16 03:06:15 +02:00
{
2009-02-08 08:42:15 +02:00
CMapInfo * mi = new CMapInfo ( pliczkiTemp [ start ] , sss ) ;
ourMaps [ start ] = mi ;
2008-11-16 03:06:15 +02:00
}
2009-02-08 08:42:15 +02:00
start + = threads ;
2008-08-02 18:08:03 +03:00
}
}
2009-02-08 08:42:15 +02:00
void MapSel : : processGames ( const std : : vector < std : : string > & pliczkiTemp )
2009-01-11 00:08:18 +02:00
{
ourGames . resize ( pliczkiTemp . size ( ) ) ;
2009-02-01 16:11:41 +02:00
ui32 hlp ;
2009-01-11 00:08:18 +02:00
for ( int i = 0 ; i < pliczkiTemp . size ( ) ; i + + )
{
CLoadFile lf ( pliczkiTemp [ i ] ) ;
ui8 sign [ 8 ] ;
2009-02-08 08:42:15 +02:00
lf > > sign > > hlp ;
2009-02-01 16:11:41 +02:00
if ( hlp ! = version )
{
2009-02-12 16:44:58 +02:00
tlog3 < < " \t \t " < < pliczkiTemp [ i ] < < " seems to be too " < < ( ( hlp > version ) ? " new " : " old " ) < < " and will be ommited. \n " ;
2009-02-08 08:42:15 +02:00
ourGames [ i ] = NULL ;
2009-02-01 16:11:41 +02:00
continue ;
}
2009-02-08 08:42:15 +02:00
ourGames [ i ] = new CMapInfo ( ) ;
lf > > static_cast < CMapHeader & > ( * ourGames [ i ] ) > > ourGames [ i ] - > seldiff ;
ourGames [ i ] - > filename = pliczkiTemp [ i ] ;
ourGames [ i ] - > countPlayers ( ) ;
2009-01-11 00:08:18 +02:00
}
}
2009-02-08 08:42:15 +02:00
2009-05-24 01:57:39 +03:00
static bool isNull ( CMapInfo * mi )
2009-02-08 08:42:15 +02:00
{
return mi = = NULL ;
}
2008-08-02 18:08:03 +03:00
void MapSel : : init ( )
{
//get map files names
std : : vector < std : : string > pliczkiTemp ;
2009-02-14 17:00:29 +02:00
if ( ! boost : : filesystem : : exists ( " Maps " ) )
{
tlog1 < < " Cannot find /Maps directory! \n " ;
}
fs : : path tie ( ( fs : : initial_path < fs : : path > ( ) ) / " Maps " ) ;
2008-08-02 18:08:03 +03:00
fs : : directory_iterator end_iter ;
for ( fs : : directory_iterator dir ( tie ) ; dir ! = end_iter ; + + dir )
{
2008-11-28 03:36:34 +02:00
if ( fs : : is_regular_file ( dir - > status ( ) ) ) ;
2008-08-02 18:08:03 +03:00
{
2008-11-28 03:36:34 +02:00
if ( boost : : ends_with ( dir - > path ( ) . filename ( ) , " .h3m " ) )
2008-08-02 18:08:03 +03:00
pliczkiTemp . push_back ( " Maps/ " + ( dir - > path ( ) . leaf ( ) ) ) ;
}
}
2009-02-08 08:42:15 +02:00
ourMaps . resize ( pliczkiTemp . size ( ) ) ;
2008-08-02 18:08:03 +03:00
boost : : thread_group group ;
2009-05-01 19:14:29 +03:00
if ( pliczkiTemp . size ( ) )
{
int threads = std : : max ( ( unsigned int ) 1 , boost : : thread : : hardware_concurrency ( ) ) ;
for ( int ti = 0 ; ti < threads ; ti + + )
group . create_thread ( boost : : bind ( & MapSel : : processMaps , this , boost : : ref ( pliczkiTemp ) , ti , threads ) ) ;
}
else
{
tlog1 < < " No maps in the /Maps directory! \n " ;
}
2008-08-02 18:08:03 +03:00
bg = BitmapHandler : : loadBitmap ( " SCSELBCK.bmp " ) ;
SDL_SetColorKey ( bg , SDL_SRCCOLORKEY , SDL_MapRGB ( bg - > format , 0 , 255 , 255 ) ) ;
small . imgs = CDefHandler : : giveDef ( " SCSMBUT.DEF " ) ;
small . fun = NULL ;
small . pos = genRect ( small . imgs - > ourImages [ 0 ] . bitmap - > h , small . imgs - > ourImages [ 0 ] . bitmap - > w , 161 , 52 ) ;
small . ourGroup = NULL ;
medium . imgs = CDefHandler : : giveDef ( " SCMDBUT.DEF " ) ;
medium . fun = NULL ;
medium . pos = genRect ( medium . imgs - > ourImages [ 0 ] . bitmap - > h , medium . imgs - > ourImages [ 0 ] . bitmap - > w , 208 , 52 ) ;
medium . ourGroup = NULL ;
large . imgs = CDefHandler : : giveDef ( " SCLGBUT.DEF " ) ;
large . fun = NULL ;
large . pos = genRect ( large . imgs - > ourImages [ 0 ] . bitmap - > h , large . imgs - > ourImages [ 0 ] . bitmap - > w , 255 , 52 ) ;
large . ourGroup = NULL ;
xlarge . imgs = CDefHandler : : giveDef ( " SCXLBUT.DEF " ) ;
xlarge . fun = NULL ;
xlarge . pos = genRect ( xlarge . imgs - > ourImages [ 0 ] . bitmap - > h , xlarge . imgs - > ourImages [ 0 ] . bitmap - > w , 302 , 52 ) ;
xlarge . ourGroup = NULL ;
all . imgs = CDefHandler : : giveDef ( " SCALBUT.DEF " ) ;
all . fun = NULL ;
all . pos = genRect ( all . imgs - > ourImages [ 0 ] . bitmap - > h , all . imgs - > ourImages [ 0 ] . bitmap - > w , 349 , 52 ) ;
all . ourGroup = NULL ;
all . selectable = xlarge . selectable = large . selectable = medium . selectable = small . selectable = false ;
small . what = medium . what = large . what = xlarge . what = all . what = & sizeFilter ;
small . key = 36 ; medium . key = 72 ; large . key = 108 ; xlarge . key = 144 ; all . key = 0 ;
//Button<> nrplayer, mapsize, type, name, viccon, loscon;
nrplayer . imgs = CDefHandler : : giveDef ( " SCBUTT1.DEF " ) ;
nrplayer . fun = NULL ;
nrplayer . pos = genRect ( nrplayer . imgs - > ourImages [ 0 ] . bitmap - > h , nrplayer . imgs - > ourImages [ 0 ] . bitmap - > w , 26 , 92 ) ;
nrplayer . key = _playerAm ;
mapsize . imgs = CDefHandler : : giveDef ( " SCBUTT2.DEF " ) ;
mapsize . fun = NULL ;
mapsize . pos = genRect ( mapsize . imgs - > ourImages [ 0 ] . bitmap - > h , mapsize . imgs - > ourImages [ 0 ] . bitmap - > w , 58 , 92 ) ;
mapsize . key = _size ;
type . imgs = CDefHandler : : giveDef ( " SCBUTCP.DEF " ) ;
type . fun = NULL ;
type . pos = genRect ( type . imgs - > ourImages [ 0 ] . bitmap - > h , type . imgs - > ourImages [ 0 ] . bitmap - > w , 91 , 92 ) ;
type . key = _format ;
name . imgs = CDefHandler : : giveDef ( " SCBUTT3.DEF " ) ;
name . fun = NULL ;
name . pos = genRect ( name . imgs - > ourImages [ 0 ] . bitmap - > h , name . imgs - > ourImages [ 0 ] . bitmap - > w , 124 , 92 ) ;
name . key = _name ;
viccon . imgs = CDefHandler : : giveDef ( " SCBUTT4.DEF " ) ;
viccon . fun = NULL ;
viccon . pos = genRect ( viccon . imgs - > ourImages [ 0 ] . bitmap - > h , viccon . imgs - > ourImages [ 0 ] . bitmap - > w , 309 , 92 ) ;
viccon . key = _viccon ;
loscon . imgs = CDefHandler : : giveDef ( " SCBUTT5.DEF " ) ;
loscon . fun = NULL ;
loscon . pos = genRect ( loscon . imgs - > ourImages [ 0 ] . bitmap - > h , loscon . imgs - > ourImages [ 0 ] . bitmap - > w , 342 , 92 ) ;
loscon . key = _loscon ;
nrplayer . poin = mapsize . poin = type . poin = name . poin = viccon . poin = loscon . poin = ( int * ) ( & sortBy ) ;
2008-08-06 01:11:32 +03:00
nrplayer . fun = mapsize . fun = type . fun = name . fun = viccon . fun = loscon . fun = boost : : bind ( & CPreGame : : sortMaps , CPG ) ;
2008-08-02 18:08:03 +03:00
Dtypes = CDefHandler : : giveDef ( " SCSELC.DEF " ) ;
Dvic = CDefHandler : : giveDef ( " SCNRVICT.DEF " ) ;
Dloss = CDefHandler : : giveDef ( " SCNRLOSS.DEF " ) ;
//Dsizes = CPG->slh->giveDef("SCNRMPSZ.DEF");
Dsizes = CDefHandler : : giveDef ( " SCNRMPSZ.DEF " ) ;
sFlags = CDefHandler : : giveDef ( " ITGFLAGS.DEF " ) ;
2009-02-08 08:42:15 +02:00
2009-05-04 02:38:08 +03:00
slid = new Slider ( 375 , 92 , 480 , ourMaps . size ( ) , - 1 , true ) ;
2008-08-06 01:11:32 +03:00
slid - > fun = boost : : bind ( & CPreGame : : printMapsFrom , CPG , _1 ) ;
2009-01-11 00:08:18 +02:00
group . join_all ( ) ;
2009-02-08 08:42:15 +02:00
std : : vector < CMapInfo * > : : iterator maps = std : : remove_if ( ourMaps . begin ( ) , ourMaps . end ( ) , isNull ) ;
ourMaps . erase ( maps , ourMaps . end ( ) ) ;
std : : sort ( ourMaps . begin ( ) , ourMaps . end ( ) , mapSorter ( _name ) ) ;
2009-01-11 00:08:18 +02:00
pliczkiTemp . clear ( ) ;
2009-01-12 22:05:56 +02:00
std : : vector < std : : string > datestemp ;
2009-02-14 17:00:29 +02:00
if ( ! boost : : filesystem : : exists ( " Games " ) )
{
tlog1 < < " Cannot find /Games directory! \n " ;
}
2009-01-11 00:08:18 +02:00
tie = fs : : path ( ( fs : : initial_path < fs : : path > ( ) ) / " /Games " ) ;
for ( fs : : directory_iterator dir ( tie ) ; dir ! = end_iter ; + + dir )
{
if ( fs : : is_regular_file ( dir - > status ( ) ) ) ;
{
if ( boost : : ends_with ( dir - > path ( ) . filename ( ) , " .vlgm1 " ) )
2009-01-12 22:05:56 +02:00
{
2009-01-25 18:19:34 +02:00
if ( fs : : file_size ( dir - > path ( ) ) < 16000 )
{
2009-01-26 00:56:37 +02:00
tlog3 < < " \t \t Warning: savegame " < < dir - > path ( ) . filename ( ) < < " seems to be corrupted and will be ommited. \n " ;
2009-01-25 18:19:34 +02:00
continue ;
}
2009-01-11 00:08:18 +02:00
pliczkiTemp . push_back ( " Games/ " + ( dir - > path ( ) . leaf ( ) ) ) ;
2009-01-12 22:05:56 +02:00
std : : time_t time = fs : : last_write_time ( dir - > path ( ) ) ;
datestemp . push_back ( std : : asctime ( std : : gmtime ( & time ) ) ) ;
}
2009-01-11 00:08:18 +02:00
}
}
2009-02-08 08:42:15 +02:00
processGames ( pliczkiTemp ) ;
2009-01-12 22:05:56 +02:00
for ( int i = 0 ; i < ourGames . size ( ) ; i + + )
{
2009-02-12 16:44:58 +02:00
if ( ourGames [ i ] )
ourGames [ i ] - > date = datestemp [ i ] ;
2009-01-12 22:05:56 +02:00
}
2009-02-12 16:44:58 +02:00
maps = std : : remove_if ( ourGames . begin ( ) , ourGames . end ( ) , isNull ) ;
ourGames . erase ( maps , ourGames . end ( ) ) ;
std : : sort ( ourGames . begin ( ) , ourGames . end ( ) , mapSorter ( _name ) ) ;
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
2009-05-29 04:50:33 +03:00
// Move the list up or down by a specified amount (positive or negative).
void MapSel : : moveByX ( int nlines )
{
selected + = nlines ;
2009-05-04 02:38:08 +03:00
2009-05-29 04:50:33 +03:00
// Adjust selected
if ( selected < 0 )
selected = 0 ;
else if ( selected > = selMaps . size ( ) )
selected = selMaps . size ( ) - 1 ;
// Since we want the selection to appear, we may have to change which
// maps are to be displayed
if ( selected < slid - > whereAreWe )
slid - > whereAreWe = selected ;
else if ( selected > = slid - > whereAreWe + slid - > capacity ) {
slid - > whereAreWe = selected - slid - > capacity + 1 ;
if ( slid - > whereAreWe > = slid - > positionsAmnt )
slid - > whereAreWe = slid - > positionsAmnt - 1 ;
2008-08-02 18:08:03 +03:00
}
2009-05-04 02:38:08 +03:00
2009-05-29 04:50:33 +03:00
select ( selected ) ;
2008-08-02 18:08:03 +03:00
slid - > updateSlid ( ) ;
}
2009-05-29 04:50:33 +03:00
2008-08-06 01:11:32 +03:00
void MapSel : : select ( int which , bool updateMapsList , bool forceSettingsUpdate )
2008-08-02 18:08:03 +03:00
{
2009-05-29 04:50:33 +03:00
if ( which < 0 | | which > = selMaps . size ( ) )
2009-05-04 02:38:08 +03:00
// Empty list
2009-01-11 00:08:18 +02:00
return ;
2009-05-04 02:38:08 +03:00
// If there's currently no default selection, make one
2009-05-29 04:50:33 +03:00
if ( selected = = - 1 & & selMaps . size ( ) )
2009-05-04 02:38:08 +03:00
selected = 0 ;
2008-08-06 01:11:32 +03:00
bool dontSaveSettings = ( ( selected ! = which ) | | ( CPG - > ret . playerInfos . size ( ) = = 0 ) | | forceSettingsUpdate ) ;
2009-05-10 01:19:41 +03:00
if ( selected > = 0 )
{
2009-05-04 02:38:08 +03:00
selected = which ;
2009-05-29 04:50:33 +03:00
CPG - > ret . mapname = selMaps [ selected ] - > filename ;
2009-05-04 02:38:08 +03:00
}
2008-08-02 18:08:03 +03:00
if ( updateMapsList )
2009-05-04 02:38:08 +03:00
printMaps ( slid - > whereAreWe ) ;
2008-08-02 18:08:03 +03:00
int serialC = 0 ;
2009-05-04 02:38:08 +03:00
if ( selected > = 0 & & dontSaveSettings )
2008-08-02 18:08:03 +03:00
{
CPG - > ret . playerInfos . clear ( ) ;
bool wasntpl = true ;
for ( int i = 0 ; i < PLAYER_LIMIT ; i + + )
{
2009-05-29 04:50:33 +03:00
if ( ! ( selMaps [ selected ] - > players [ i ] . canComputerPlay
| | selMaps [ selected ] - > players [ i ] . canComputerPlay )
2009-01-11 00:08:18 +02:00
)
2008-08-02 18:08:03 +03:00
continue ; // this caused some serious problems becouse of lack of simple bijection between two sets of player's numbers (one is returned by CPreGame, second is used in h3m)
2009-02-08 08:42:15 +02:00
PlayerSettings pset ;
2008-08-02 18:08:03 +03:00
pset . color = ( Ecolor ) i ;
pset . serial = serialC ;
serialC + + ;
pset . bonus = brandom ;
pset . castle = - 2 ;
2009-05-29 04:50:33 +03:00
if ( selMaps [ which ] - > players [ i ] . canHumanPlay & & wasntpl )
2008-08-02 18:08:03 +03:00
{
pset . name = CGI - > generaltexth - > allTexts [ 434 ] ; //Player
pset . human = true ;
CPG - > playerColor = i ;
wasntpl = false ;
}
else
{
pset . name = CGI - > generaltexth - > allTexts [ 468 ] ; //Computer
pset . human = false ;
}
for ( int j = 0 ; j < F_NUMBER ; j + + )
{
2009-05-29 04:50:33 +03:00
if ( ( ( int ) pow ( ( double ) 2 , j ) ) & selMaps [ selected ] - > players [ i ] . allowedFactions )
2008-08-02 18:08:03 +03:00
{
if ( pset . castle > = 0 )
pset . castle = - 1 ;
if ( pset . castle = = - 2 )
pset . castle = j ;
}
}
pset . heroPortrait = - 1 ;
2009-01-11 00:08:18 +02:00
if ( !
2009-05-29 04:50:33 +03:00
( ( ( selMaps [ which ] - > players [ i ] . generateHeroAtMainTown | | selMaps [ which ] - > version = = CMapHeader : : RoE )
& & selMaps [ which ] - > players [ i ] . hasMainTown )
| | selMaps [ which ] - > players [ i ] . p8 )
2009-01-11 00:08:18 +02:00
)
2008-08-02 18:08:03 +03:00
pset . hero = - 2 ;
else
pset . hero = - 1 ;
2009-05-29 04:50:33 +03:00
if ( selMaps [ which ] - > players [ i ] . mainHeroName . length ( ) )
2008-08-02 18:08:03 +03:00
{
2009-05-29 04:50:33 +03:00
pset . heroName = selMaps [ which ] - > players [ i ] . mainHeroName ;
if ( ( pset . heroPortrait = selMaps [ which ] - > players [ i ] . mainHeroPortrait ) = = 255 )
pset . heroPortrait = selMaps [ which ] - > players [ i ] . p9 ;
2008-08-02 18:08:03 +03:00
}
pset . handicap = 0 ;
CPG - > ret . playerInfos . push_back ( pset ) ;
}
}
printSelectedInfo ( ) ;
}
2009-05-04 02:38:08 +03:00
MapSel : : MapSel ( ) : selected ( - 1 ) , sizeFilter ( 0 )
2008-08-02 18:08:03 +03:00
{
}
void MapSel : : printSelectedInfo ( )
{
SDL_BlitSurface ( CPG - > ourScenSel - > scenInf , & genRect ( 399 , 337 , 17 , 23 ) , screen , & genRect ( 399 , 337 , 413 , 29 ) ) ;
SDL_BlitSurface ( CPG - > ourScenSel - > scenInf , & genRect ( 50 , 91 , 18 , 447 ) , screen , & genRect ( 50 , 91 , 414 , 453 ) ) ;
2009-05-04 02:38:08 +03:00
2008-08-02 18:08:03 +03:00
//blit texts
2008-11-28 03:36:34 +02:00
CSDL_Ext : : printAt ( CGI - > generaltexth - > zelp [ 21 ] . second , 420 , 25 , GEOR13 ) ;
2008-08-02 18:08:03 +03:00
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 496 ] , 420 , 135 , GEOR13 ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 497 ] , 420 , 285 , GEOR13 ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 498 ] , 420 , 340 , GEOR13 ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 390 ] , 420 , 406 , GEOR13 , zwykly ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 391 ] , 585 , 406 , GEOR13 , zwykly ) ;
2009-05-04 02:38:08 +03:00
if ( CPG - > fromMenu = = CPG - > newGame )
{
SDL_BlitSurface ( CPG - > ourScenSel - > bScens . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & CPG - > ourScenSel - > bScens . pos ) ;
SDL_BlitSurface ( CPG - > ourScenSel - > bOptions . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & CPG - > ourScenSel - > bOptions . pos ) ;
SDL_BlitSurface ( CPG - > ourScenSel - > bRandom . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & CPG - > ourScenSel - > bRandom . pos ) ;
}
2008-08-02 18:08:03 +03:00
2009-05-04 02:38:08 +03:00
if ( selected > = 0 )
{
2009-05-29 04:50:33 +03:00
CMapInfo & selMap = * selMaps [ selected ] ;
2009-05-04 02:38:08 +03:00
if ( CPG - > fromMenu ! = CPG - > newGame )
{
CPG - > ourScenSel - > bEasy . state = 2 + ( selMap . seldiff = = 0 ) ;
CPG - > ourScenSel - > bNormal . state = 2 + ( selMap . seldiff = = 1 ) ;
CPG - > ourScenSel - > bHard . state = 2 + ( selMap . seldiff = = 2 ) ;
CPG - > ourScenSel - > bExpert . state = 2 + ( selMap . seldiff = = 3 ) ;
CPG - > ourScenSel - > bImpossible . state = 2 + ( selMap . seldiff = = 4 ) ;
CPG - > ourScenSel - > bEasy . show ( ) ;
CPG - > ourScenSel - > bNormal . show ( ) ;
CPG - > ourScenSel - > bHard . show ( ) ;
CPG - > ourScenSel - > bExpert . show ( ) ;
CPG - > ourScenSel - > bImpossible . show ( ) ;
}
2008-08-02 18:08:03 +03:00
2009-05-04 02:38:08 +03:00
int temp = selMap . victoryCondition . condition + 1 ;
if ( temp > 20 ) temp = 0 ;
std : : string sss = CGI - > generaltexth - > victoryConditions [ temp ] ;
if ( temp & & selMap . victoryCondition . allowNormalVictory ) sss + = " / " + CGI - > generaltexth - > victoryConditions [ 0 ] ;
CSDL_Ext : : printAt ( sss , 452 , 310 , GEOR13 , zwykly ) ;
2008-08-02 18:08:03 +03:00
2009-05-04 02:38:08 +03:00
temp = selMap . lossCondition . typeOfLossCon + 1 ;
if ( temp > 20 ) temp = 0 ;
sss = CGI - > generaltexth - > lossCondtions [ temp ] ;
CSDL_Ext : : printAt ( sss , 452 , 370 , GEOR13 , zwykly ) ;
2008-08-02 18:08:03 +03:00
2009-05-29 04:50:33 +03:00
//blit description
2009-05-04 02:38:08 +03:00
std : : vector < std : : string > desc = * CMessage : : breakText ( selMap . description , 50 ) ;
for ( int i = 0 ; i < desc . size ( ) ; i + + )
CSDL_Ext : : printAt ( desc [ i ] , 417 , 152 + i * 13 , GEOR13 , zwykly ) ;
2009-01-12 22:05:56 +02:00
2009-05-29 04:50:33 +03:00
if ( ( selected < 0 ) | | ( selected > = selMaps . size ( ) ) )
2009-05-04 02:38:08 +03:00
return ;
if ( selMap . name . length ( ) )
CSDL_Ext : : printAt ( selMap . name , 420 , 41 , GEORXX ) ;
else CSDL_Ext : : printAt ( " Unnamed " , 420 , 41 , GEORXX ) ;
std : : string diff ;
switch ( selMap . difficulty )
{
case 0 :
diff = gdiff ( CGI - > generaltexth - > zelp [ 24 ] . second ) ;
break ;
case 1 :
diff = gdiff ( CGI - > generaltexth - > zelp [ 25 ] . second ) ;
break ;
case 2 :
diff = gdiff ( CGI - > generaltexth - > zelp [ 26 ] . second ) ;
break ;
case 3 :
diff = gdiff ( CGI - > generaltexth - > zelp [ 27 ] . second ) ;
break ;
case 4 :
diff = gdiff ( CGI - > generaltexth - > zelp [ 28 ] . second ) ;
break ;
}
temp = - 1 ;
switch ( selMap . width )
{
case 36 :
temp = 0 ;
break ;
case 72 :
temp = 1 ;
break ;
case 108 :
temp = 2 ;
break ;
case 144 :
temp = 3 ;
break ;
default :
temp = 4 ;
break ;
}
blitAt ( Dsizes - > ourImages [ temp ] . bitmap , 714 , 28 ) ;
temp = selMap . victoryCondition . condition ;
if ( temp > 12 ) temp = 11 ;
blitAt ( Dvic - > ourImages [ temp ] . bitmap , 420 , 308 ) ; //v
temp = selMap . lossCondition . typeOfLossCon ;
if ( temp > 12 ) temp = 3 ;
blitAt ( Dloss - > ourImages [ temp ] . bitmap , 420 , 366 ) ; //l
CSDL_Ext : : printAtMiddle ( diff , 458 , 477 , GEOR13 , zwykly ) ;
CSDL_Ext : : printTo ( selMap . date , 704 , 40 , GEOR13 , zwykly ) ;
printFlags ( ) ;
}
2008-08-02 18:08:03 +03:00
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
}
void MapSel : : printFlags ( )
{
2009-05-29 04:50:33 +03:00
CMapInfo & selMap = * selMaps [ selected ] ;
2008-08-02 18:08:03 +03:00
int hy = 405 , fx = 460 , ex = 640 , myT ;
2009-01-11 00:08:18 +02:00
if ( selMap . howManyTeams )
myT = selMap . players [ CPG - > playerColor ] . team ;
2008-08-02 18:08:03 +03:00
else myT = - 1 ;
for ( int i = 0 ; i < CPG - > ret . playerInfos . size ( ) ; i + + )
{
if ( myT > = 0 )
{
2009-01-11 00:08:18 +02:00
if ( selMap . players [ CPG - > ret . playerInfos [ i ] . color ] . team = = myT )
2008-08-02 18:08:03 +03:00
{
blitAtWR ( sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap , fx , hy ) ;
fx + = sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap - > w ;
}
else
{
blitAtWR ( sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap , ex , hy ) ;
ex + = sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap - > w ;
}
}
else
{
if ( CPG - > ret . playerInfos [ i ] . color = = CPG - > playerColor )
{
blitAtWR ( sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap , fx , hy ) ;
fx + = sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap - > w ;
}
else
{
blitAtWR ( sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap , ex , hy ) ;
ex + = sFlags - > ourImages [ CPG - > ret . playerInfos [ i ] . color ] . bitmap - > w ;
}
}
}
}
std : : string MapSel : : gdiff ( std : : string ss )
{
std : : string ret ;
for ( int i = 2 ; i < ss . length ( ) ; i + + )
{
if ( ss [ i ] = = ' ' )
break ;
ret + = ss [ i ] ;
}
return ret ;
}
2009-01-11 00:08:18 +02:00
2009-05-29 04:50:33 +03:00
// A new size filter (Small, Medium, ...) has been selected. Populate
// selMaps with the relevant data.
void MapSel : : updateSelection ( )
2009-01-11 00:08:18 +02:00
{
2009-05-29 04:50:33 +03:00
std : : vector < CMapInfo * > & maps = CPG - > fromMenu = = CPG - > newGame ? ourMaps : ourGames ;
2009-01-11 00:08:18 +02:00
2009-05-29 04:50:33 +03:00
selMaps . clear ( ) ;
2009-01-11 00:08:18 +02:00
2009-05-29 04:50:33 +03:00
if ( sizeFilter ) {
// Filter in effect. Add only maps that matches.
for ( int i = 0 ; i < maps . size ( ) ; i + + ) {
if ( maps [ i ] - > width = = sizeFilter ) {
selMaps . push_back ( maps [ i ] ) ;
}
}
} else {
// No size filter. Copy all maps pointers.
selMaps = maps ;
}
2009-01-11 00:08:18 +02:00
}
2009-05-29 04:50:33 +03:00
2008-08-02 18:08:03 +03:00
void CPreGame : : printRating ( )
{
SDL_BlitSurface ( CPG - > ourScenSel - > scenInf , & genRect ( 47 , 83 , 271 , 449 ) , screen , & genRect ( 47 , 83 , 666 , 455 ) ) ;
updateRect ( & genRect ( 47 , 83 , 666 , 455 ) ) ;
std : : string tob ;
switch ( ourScenSel - > selectedDiff )
{
case 0 :
tob = " 80% " ;
break ;
case 1 :
tob = " 100% " ;
break ;
case 2 :
tob = " 130% " ;
break ;
case 3 :
tob = " 160% " ;
break ;
case 4 :
tob = " 200% " ;
break ;
}
CSDL_Ext : : printAtMiddle ( tob , 703 , 477 , GEOR13 , zwykly ) ;
}
void CPreGame : : printMapsFrom ( int from )
{
ourScenSel - > mapsel . printMaps ( from ) ;
}
void CPreGame : : showScenList ( )
{
2009-05-30 19:00:26 +03:00
if ( currentTab ! = & ourScenSel - > mapsel )
2008-08-02 18:08:03 +03:00
{
ourScenSel - > listShowed = true ;
ourScenSel - > mapsel . show ( ) ;
}
else
{
currentTab - > hide ( ) ;
showScenSel ( ) ;
}
}
CPreGame : : CPreGame ( )
{
2008-11-16 03:06:15 +02:00
CPG = this ;
2008-08-02 18:08:03 +03:00
highlighted = NULL ;
currentTab = NULL ;
run = true ;
timeHandler tmh ; tmh . getDif ( ) ;
tytulowy . r = 229 ; tytulowy . g = 215 ; tytulowy . b = 123 ; tytulowy . unused = 0 ;
zwykly . r = 255 ; zwykly . g = 255 ; zwykly . b = 255 ; zwykly . unused = 0 ; //gbr
tlo . r = 66 ; tlo . g = 44 ; tlo . b = 24 ; tlo . unused = 0 ;
currentMessage = NULL ;
behindCurMes = NULL ;
initMainMenu ( ) ;
2008-09-19 11:16:19 +03:00
tlog0 < < " \t CPreGame: main menu initialization: " < < tmh . getDif ( ) < < std : : endl ;
2008-08-02 18:08:03 +03:00
initNewMenu ( ) ;
2008-09-19 11:16:19 +03:00
tlog0 < < " \t CPreGame: newgame menu initialization: " < < tmh . getDif ( ) < < std : : endl ;
2008-11-16 03:06:15 +02:00
initLoadMenu ( ) ;
tlog0 < < " \t CPreGame: loadgame menu initialization: " < < tmh . getDif ( ) < < std : : endl ;
2008-08-02 18:08:03 +03:00
initScenSel ( ) ;
2008-09-19 11:16:19 +03:00
tlog0 < < " \t CPreGame: scenario choice initialization: " < < tmh . getDif ( ) < < std : : endl ;
2008-08-02 18:08:03 +03:00
initOptions ( ) ;
2008-09-19 11:16:19 +03:00
tlog0 < < " \t CPreGame: scenario options initialization: " < < tmh . getDif ( ) < < std : : endl ;
2008-08-02 18:08:03 +03:00
showMainMenu ( ) ;
2008-09-19 11:16:19 +03:00
tlog0 < < " \t CPreGame: displaying main menu: " < < tmh . getDif ( ) < < std : : endl ;
2008-08-02 18:08:03 +03:00
playerName = " Player " ;
}
void CPreGame : : initOptions ( )
{
ourOptions = new Options ( ) ;
ourOptions - > init ( ) ;
}
void CPreGame : : initScenSel ( )
{
ourScenSel = new ScenSel ( ) ;
2008-09-29 23:57:35 +03:00
tlog5 < < " \t \t Loaded graphics \n " ;
2008-08-02 18:08:03 +03:00
ourScenSel - > mapsel . init ( ) ;
2008-09-29 23:57:35 +03:00
tlog5 < < " \t \t Loaded maps \n " ;
2008-08-02 18:08:03 +03:00
}
2009-05-29 04:50:33 +03:00
// New Game or Load Game seletion..
2008-08-02 18:08:03 +03:00
void CPreGame : : showScenSel ( )
{
state = ScenarioList ;
2009-05-29 04:50:33 +03:00
ourScenSel - > mapsel . updateSelection ( ) ;
ourScenSel - > mapsel . slid - > positionsAmnt = ourScenSel - > mapsel . selMaps . size ( ) ;
2008-08-02 18:08:03 +03:00
SDL_BlitSurface ( ourScenSel - > background , NULL , screen , NULL ) ;
SDL_BlitSurface ( ourScenSel - > scenInf , NULL , screen , & genRect ( ourScenSel - > scenInf - > h , ourScenSel - > scenInf - > w , 396 , 6 ) ) ;
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 494 ] , 427 , 438 , GEOR13 ) ; //"Map Diff:"
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 492 ] , 527 , 438 , GEOR13 ) ; //player difficulty
CSDL_Ext : : printAt ( CGI - > generaltexth - > allTexts [ 218 ] , 685 , 438 , GEOR13 ) ; //"Rating:"
//blit buttons
SDL_BlitSurface ( ourScenSel - > bEasy . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bEasy . pos ) ;
SDL_BlitSurface ( ourScenSel - > bNormal . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bNormal . pos ) ;
SDL_BlitSurface ( ourScenSel - > bHard . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bHard . pos ) ;
SDL_BlitSurface ( ourScenSel - > bExpert . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bExpert . pos ) ;
SDL_BlitSurface ( ourScenSel - > bImpossible . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bImpossible . pos ) ;
2009-05-04 02:38:08 +03:00
SDL_BlitSurface ( ( fromMenu = = newGame ? ourScenSel - > bBegin : ourScenSel - > bLoad ) . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bBegin . pos ) ;
2008-08-02 18:08:03 +03:00
SDL_BlitSurface ( ourScenSel - > bBack . imgs - > ourImages [ 0 ] . bitmap , NULL , screen , & ourScenSel - > bBack . pos ) ;
//blitAt(ourScenSel->bScens.imgs->ourImages[0].bitmap,ourScenSel->bScens.pos.x,ourScenSel->bScens.pos.y);
//blitAt(ourScenSel->bRandom.imgs->ourImages[0].bitmap,414,105);
//blitAt(ourScenSel->bOptions.imgs->ourImages[0].bitmap,414,509);
//blitAt(ourScenSel->bBegin.imgs->ourImages[0].bitmap,414,535);
//blitAt(ourScenSel->bBack.imgs->ourImages[0].bitmap,584,535);
//add buttons info
if ( first )
{
2009-05-04 02:38:08 +03:00
if ( fromMenu = = newGame )
2009-01-11 00:08:18 +02:00
{
btns . push_back ( & ourScenSel - > bEasy ) ;
btns . push_back ( & ourScenSel - > bNormal ) ;
btns . push_back ( & ourScenSel - > bHard ) ;
btns . push_back ( & ourScenSel - > bExpert ) ;
btns . push_back ( & ourScenSel - > bImpossible ) ;
btns . push_back ( & ourScenSel - > bScens ) ;
btns . push_back ( & ourScenSel - > bRandom ) ;
btns . push_back ( & ourScenSel - > bOptions ) ;
}
else
ourScenSel - > mapsel . show ( ) ;
2009-05-04 02:38:08 +03:00
btns . push_back ( & ( fromMenu = = newGame ? ourScenSel - > bBegin : ourScenSel - > bLoad ) ) ;
2008-08-02 18:08:03 +03:00
btns . push_back ( & ourScenSel - > bBack ) ;
ourScenSel - > selectedDiff = 1 ;
ourScenSel - > bNormal . select ( true ) ;
handleOther = & CPreGame : : scenHandleEv ;
ourScenSel - > mapsel . select ( 0 , false ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
btns [ i ] - > pos . w = btns [ i ] - > imgs - > ourImages [ 0 ] . bitmap - > w ;
btns [ i ] - > pos . h = btns [ i ] - > imgs - > ourImages [ 0 ] . bitmap - > h ;
btns [ i ] - > ID = 10 ;
}
}
else
{
ourScenSel - > mapsel . select ( ourScenSel - > mapsel . selected , false ) ;
switch ( ourScenSel - > selectedDiff )
{
case 0 :
ourScenSel - > bEasy . select ( true ) ;
break ;
case 1 :
ourScenSel - > bNormal . select ( true ) ;
break ;
case 2 :
ourScenSel - > bHard . select ( true ) ;
break ;
case 3 :
ourScenSel - > bExpert . select ( true ) ;
break ;
case 4 :
ourScenSel - > bImpossible . select ( true ) ;
break ;
}
}
//ourScenSel->mapsel.printSelectedInfo(); // this is already called in select()
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
first = false ;
}
void CPreGame : : showOptions ( )
{
2009-05-04 02:38:08 +03:00
if ( ourScenSel - > mapsel . selected = = - 1 )
return ;
2009-05-01 19:14:29 +03:00
if ( currentTab ! = ourOptions )
ourOptions - > show ( ) ;
else
{
currentTab - > hide ( ) ;
showScenSel ( ) ;
}
2008-08-02 18:08:03 +03:00
}
void CPreGame : : initNewMenu ( )
{
ourNewMenu = new menuItems ( ) ;
ourNewMenu - > bgAd = BitmapHandler : : loadBitmap ( " ZNEWGAM.bmp " ) ;
ourNewMenu - > background = BitmapHandler : : loadBitmap ( " ZPIC1005.bmp " ) ;
blitAt ( ourNewMenu - > bgAd , 114 , 312 , ourNewMenu - > background ) ;
//loading menu buttons
ourNewMenu - > newGame = CDefHandler : : giveDef ( " ZTSINGL.DEF " ) ;
ourNewMenu - > loadGame = CDefHandler : : giveDef ( " ZTMULTI.DEF " ) ;
ourNewMenu - > highScores = CDefHandler : : giveDef ( " ZTCAMPN.DEF " ) ;
ourNewMenu - > credits = CDefHandler : : giveDef ( " ZTTUTOR.DEF " ) ;
ourNewMenu - > quit = CDefHandler : : giveDef ( " ZTBACK.DEF " ) ;
// single scenario
ourNewMenu - > lNewGame . h = ourNewMenu - > newGame - > ourImages [ 0 ] . bitmap - > h ;
ourNewMenu - > lNewGame . w = ourNewMenu - > newGame - > ourImages [ 0 ] . bitmap - > w ;
ourNewMenu - > lNewGame . x = 545 ;
ourNewMenu - > lNewGame . y = 4 ;
ourNewMenu - > fNewGame = & CPreGame : : showScenSel ;
//multiplayer
ourNewMenu - > lLoadGame . h = ourNewMenu - > loadGame - > ourImages [ 0 ] . bitmap - > h ;
ourNewMenu - > lLoadGame . w = ourNewMenu - > loadGame - > ourImages [ 0 ] . bitmap - > w ;
ourNewMenu - > lLoadGame . x = 568 ;
ourNewMenu - > lLoadGame . y = 120 ;
2009-01-30 23:28:02 +02:00
ourNewMenu - > fLoadGame = NULL ;
2008-08-02 18:08:03 +03:00
//campaign
ourNewMenu - > lHighScores . h = ourNewMenu - > highScores - > ourImages [ 0 ] . bitmap - > h ;
ourNewMenu - > lHighScores . w = ourNewMenu - > highScores - > ourImages [ 0 ] . bitmap - > w ;
ourNewMenu - > lHighScores . x = 541 ;
ourNewMenu - > lHighScores . y = 233 ;
2009-01-30 23:28:02 +02:00
ourNewMenu - > fHighScores = NULL ;
2008-08-02 18:08:03 +03:00
//tutorial
ourNewMenu - > lCredits . h = ourNewMenu - > credits - > ourImages [ 0 ] . bitmap - > h ;
ourNewMenu - > lCredits . w = ourNewMenu - > credits - > ourImages [ 0 ] . bitmap - > w ;
ourNewMenu - > lCredits . x = 545 ;
ourNewMenu - > lCredits . y = 358 ;
2009-01-30 23:28:02 +02:00
ourNewMenu - > fCredits = NULL ;
2008-08-02 18:08:03 +03:00
//back
ourNewMenu - > lQuit . h = ourNewMenu - > quit - > ourImages [ 0 ] . bitmap - > h ;
ourNewMenu - > lQuit . w = ourNewMenu - > quit - > ourImages [ 0 ] . bitmap - > w ;
ourNewMenu - > lQuit . x = 582 ;
ourNewMenu - > lQuit . y = 464 ;
ourNewMenu - > fQuit = & CPreGame : : showMainMenu ;
ourNewMenu - > highlighted = 0 ;
}
void CPreGame : : showNewMenu ( )
{
2009-05-04 02:38:08 +03:00
if ( state = = ScenarioList & & fromMenu = = loadGame )
2009-01-11 00:08:18 +02:00
{
showLoadMenu ( ) ;
return ;
}
2008-08-02 18:08:03 +03:00
if ( currentTab /*==&ourScenSel->mapsel*/ )
currentTab - > hide ( ) ;
btns . clear ( ) ;
interested . clear ( ) ;
handleOther = NULL ;
state = newGame ;
2009-05-04 02:38:08 +03:00
fromMenu = newGame ;
ourScenSel - > mapsel . slid - > capacity = 18 ;
2008-08-02 18:08:03 +03:00
SDL_BlitSurface ( ourNewMenu - > background , NULL , screen , NULL ) ;
SDL_BlitSurface ( ourNewMenu - > newGame - > ourImages [ 0 ] . bitmap , NULL , screen , & ourNewMenu - > lNewGame ) ;
SDL_BlitSurface ( ourNewMenu - > loadGame - > ourImages [ 0 ] . bitmap , NULL , screen , & ourNewMenu - > lLoadGame ) ;
SDL_BlitSurface ( ourNewMenu - > highScores - > ourImages [ 0 ] . bitmap , NULL , screen , & ourNewMenu - > lHighScores ) ;
SDL_BlitSurface ( ourNewMenu - > credits - > ourImages [ 0 ] . bitmap , NULL , screen , & ourNewMenu - > lCredits ) ;
SDL_BlitSurface ( ourNewMenu - > quit - > ourImages [ 0 ] . bitmap , NULL , screen , & ourNewMenu - > lQuit ) ;
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
first = true ;
}
void CPreGame : : initMainMenu ( )
{
ourMainMenu = new menuItems ( ) ;
ourMainMenu - > background = BitmapHandler : : loadBitmap ( " ZPIC1005.bmp " ) ; //SDL_LoadBMP("h3bitmap.lod\\ZPIC1005.bmp");
//loading menu buttons
ourMainMenu - > newGame = CDefHandler : : giveDef ( " ZMENUNG.DEF " ) ;
ourMainMenu - > loadGame = CDefHandler : : giveDef ( " ZMENULG.DEF " ) ;
ourMainMenu - > highScores = CDefHandler : : giveDef ( " ZMENUHS.DEF " ) ;
ourMainMenu - > credits = CDefHandler : : giveDef ( " ZMENUCR.DEF " ) ;
ourMainMenu - > quit = CDefHandler : : giveDef ( " ZMENUQT.DEF " ) ;
ok = CDefHandler : : giveDef ( " IOKAY.DEF " ) ;
cancel = CDefHandler : : giveDef ( " ICANCEL.DEF " ) ;
// new game button location
ourMainMenu - > lNewGame . h = ourMainMenu - > newGame - > ourImages [ 0 ] . bitmap - > h ;
ourMainMenu - > lNewGame . w = ourMainMenu - > newGame - > ourImages [ 0 ] . bitmap - > w ;
ourMainMenu - > lNewGame . x = 540 ;
ourMainMenu - > lNewGame . y = 10 ;
ourMainMenu - > fNewGame = & CPreGame : : showNewMenu ;
//load game location
ourMainMenu - > lLoadGame . h = ourMainMenu - > loadGame - > ourImages [ 0 ] . bitmap - > h ;
ourMainMenu - > lLoadGame . w = ourMainMenu - > loadGame - > ourImages [ 0 ] . bitmap - > w ;
ourMainMenu - > lLoadGame . x = 532 ;
ourMainMenu - > lLoadGame . y = 132 ;
2008-11-16 03:06:15 +02:00
ourMainMenu - > fLoadGame = & CPreGame : : showLoadMenu ;
2008-08-02 18:08:03 +03:00
//high scores
ourMainMenu - > lHighScores . h = ourMainMenu - > highScores - > ourImages [ 0 ] . bitmap - > h ;
ourMainMenu - > lHighScores . w = ourMainMenu - > highScores - > ourImages [ 0 ] . bitmap - > w ;
ourMainMenu - > lHighScores . x = 524 ;
ourMainMenu - > lHighScores . y = 251 ;
2009-01-30 23:28:02 +02:00
ourMainMenu - > fHighScores = NULL ;
2008-08-02 18:08:03 +03:00
//credits
ourMainMenu - > lCredits . h = ourMainMenu - > credits - > ourImages [ 0 ] . bitmap - > h ;
ourMainMenu - > lCredits . w = ourMainMenu - > credits - > ourImages [ 0 ] . bitmap - > w ;
ourMainMenu - > lCredits . x = 557 ;
ourMainMenu - > lCredits . y = 359 ;
2009-01-30 23:28:02 +02:00
ourMainMenu - > fCredits = NULL ;
2008-08-02 18:08:03 +03:00
//quit
ourMainMenu - > lQuit . h = ourMainMenu - > quit - > ourImages [ 0 ] . bitmap - > h ;
ourMainMenu - > lQuit . w = ourMainMenu - > quit - > ourImages [ 0 ] . bitmap - > w ;
ourMainMenu - > lQuit . x = 586 ;
ourMainMenu - > lQuit . y = 468 ;
ourMainMenu - > fQuit = & CPreGame : : quitAskBox ;
ourMainMenu - > highlighted = 0 ;
}
void CPreGame : : showMainMenu ( )
{
state = mainMenu ;
SDL_BlitSurface ( ourMainMenu - > background , NULL , screen , NULL ) ;
SDL_BlitSurface ( ourMainMenu - > newGame - > ourImages [ 0 ] . bitmap , NULL , screen , & ourMainMenu - > lNewGame ) ;
SDL_BlitSurface ( ourMainMenu - > loadGame - > ourImages [ 0 ] . bitmap , NULL , screen , & ourMainMenu - > lLoadGame ) ;
SDL_BlitSurface ( ourMainMenu - > highScores - > ourImages [ 0 ] . bitmap , NULL , screen , & ourMainMenu - > lHighScores ) ;
SDL_BlitSurface ( ourMainMenu - > credits - > ourImages [ 0 ] . bitmap , NULL , screen , & ourMainMenu - > lCredits ) ;
SDL_BlitSurface ( ourMainMenu - > quit - > ourImages [ 0 ] . bitmap , NULL , screen , & ourMainMenu - > lQuit ) ;
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
}
void CPreGame : : highlightButton ( int which , int on )
{
menuItems * current = currentItems ( ) ;
switch ( which )
{
case 1 :
{
SDL_BlitSurface ( current - > newGame - > ourImages [ on ] . bitmap , NULL , screen , & current - > lNewGame ) ;
break ;
}
case 2 :
{
SDL_BlitSurface ( current - > loadGame - > ourImages [ on ] . bitmap , NULL , screen , & current - > lLoadGame ) ;
break ;
}
case 3 :
{
SDL_BlitSurface ( current - > highScores - > ourImages [ on ] . bitmap , NULL , screen , & current - > lHighScores ) ;
break ;
}
case 4 :
{
SDL_BlitSurface ( current - > credits - > ourImages [ on ] . bitmap , NULL , screen , & current - > lCredits ) ;
break ;
}
case 5 :
{
SDL_BlitSurface ( current - > quit - > ourImages [ on ] . bitmap , NULL , screen , & current - > lQuit ) ;
break ;
}
}
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
}
void CPreGame : : showCenBox ( std : : string data )
{
CMessage * cmh = new CMessage ( ) ;
2008-11-28 03:36:34 +02:00
SDL_Surface * infoBox = cmh - > genMessage ( CGI - > generaltexth - > getTitle ( data ) , CGI - > generaltexth - > getDescr ( data ) ) ;
2008-08-02 18:08:03 +03:00
behindCurMes = CSDL_Ext : : newSurface ( infoBox - > w , infoBox - > h , screen ) ;
SDL_Rect pos = genRect ( infoBox - > h , infoBox - > w ,
( screen - > w / 2 ) - ( infoBox - > w / 2 ) , ( screen - > h / 2 ) - ( infoBox - > h / 2 ) ) ;
SDL_BlitSurface ( screen , & pos , behindCurMes , NULL ) ;
SDL_BlitSurface ( infoBox , NULL , screen , & pos ) ;
SDL_UpdateRect ( screen , pos . x , pos . y , pos . w , pos . h ) ;
SDL_FreeSurface ( infoBox ) ;
currentMessage = new SDL_Rect ( pos ) ;
delete cmh ;
}
void CPreGame : : showAskBox ( std : : string data , void ( * f1 ) ( ) , void ( * f2 ) ( ) )
{
CMessage * cmh = new CMessage ( ) ;
std : : vector < CDefHandler * > * przyciski = new std : : vector < CDefHandler * > ( 0 ) ;
std : : vector < SDL_Rect > * btnspos = new std : : vector < SDL_Rect > ( 0 ) ;
przyciski - > push_back ( ok ) ;
przyciski - > push_back ( cancel ) ;
2008-11-28 03:36:34 +02:00
SDL_Surface * infoBox = cmh - > genMessage ( CGI - > generaltexth - > getTitle ( data ) , CGI - > generaltexth - > getDescr ( data ) , yesOrNO , przyciski , btnspos ) ;
2008-08-02 18:08:03 +03:00
behindCurMes = CSDL_Ext : : newSurface ( infoBox - > w , infoBox - > h , screen ) ;
SDL_Rect pos = genRect ( infoBox - > h , infoBox - > w ,
( screen - > w / 2 ) - ( infoBox - > w / 2 ) , ( screen - > h / 2 ) - ( infoBox - > h / 2 ) ) ;
SDL_BlitSurface ( screen , & pos , behindCurMes , NULL ) ;
SDL_BlitSurface ( infoBox , NULL , screen , & pos ) ;
SDL_UpdateRect ( screen , pos . x , pos . y , pos . w , pos . h ) ;
SDL_FreeSurface ( infoBox ) ;
currentMessage = new SDL_Rect ( pos ) ;
( * btnspos ) [ 0 ] . x + = pos . x ;
( * btnspos ) [ 0 ] . y + = pos . y ;
( * btnspos ) [ 1 ] . x + = pos . x ;
( * btnspos ) [ 1 ] . y + = pos . y ;
2008-08-06 01:11:32 +03:00
btns . push_back ( new Button ( ( * btnspos ) [ 0 ] , boost : : bind ( & CPreGame : : quit , this ) , ok , false , NULL , 2 ) ) ;
btns . push_back ( new Button ( ( * btnspos ) [ 1 ] , boost : : bind ( & CPreGame : : hideBox , this ) , cancel , false , NULL , 2 ) ) ;
2008-08-02 18:08:03 +03:00
delete cmh ;
delete przyciski ;
delete btnspos ;
}
void CPreGame : : hideBox ( )
{
SDL_BlitSurface ( behindCurMes , NULL , screen , currentMessage ) ;
SDL_UpdateRect
( screen , currentMessage - > x , currentMessage - > y , currentMessage - > w , currentMessage - > h ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( btns [ i ] - > ID = = 2 )
{
delete btns [ i ] ;
btns . erase ( btns . begin ( ) + i ) ;
i - - ;
}
}
SDL_FreeSurface ( behindCurMes ) ;
delete currentMessage ;
currentMessage = NULL ;
behindCurMes = NULL ;
}
CPreGame : : menuItems * CPreGame : : currentItems ( )
{
switch ( state )
{
case mainMenu :
return ourMainMenu ;
case newGame :
return ourNewMenu ;
2008-11-16 03:06:15 +02:00
case loadGame :
return ourLoadMenu ;
2008-08-02 18:08:03 +03:00
default :
return NULL ;
}
}
void CPreGame : : scenHandleEv ( SDL_Event & sEvent )
{
2009-02-11 20:14:39 +02:00
if ( currentTab = = & ourScenSel - > mapsel )
2009-02-11 19:48:40 +02:00
{
2009-02-11 20:14:39 +02:00
if ( sEvent . button . button = = SDL_BUTTON_WHEELUP )
{
ourScenSel - > mapsel . slid - > moveUp ( ) ;
return ;
}
else if ( sEvent . button . button = = SDL_BUTTON_WHEELDOWN )
{
ourScenSel - > mapsel . slid - > moveDown ( ) ;
return ;
}
2009-02-11 19:48:40 +02:00
}
2008-08-02 18:08:03 +03:00
if ( sEvent . type = = SDL_MOUSEMOTION )
{
CGI - > curh - > cursorMove ( sEvent . motion . x , sEvent . motion . y ) ;
}
if ( ( sEvent . type = = SDL_MOUSEBUTTONDOWN ) & & ( sEvent . button . button = = SDL_BUTTON_LEFT ) )
{
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( isItIn ( & btns [ i ] - > pos , sEvent . motion . x , sEvent . motion . y ) )
{
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( soundBase : : button ) ;
2008-08-02 18:08:03 +03:00
btns [ i ] - > press ( true ) ;
2008-08-06 01:11:32 +03:00
ourScenSel - > pressed = ( Button * ) btns [ i ] ;
2008-08-02 18:08:03 +03:00
}
}
if ( ( currentTab = = & ourScenSel - > mapsel ) & & ( sEvent . button . y > 121 ) & & ( sEvent . button . y < 570 )
& & ( sEvent . button . x > 55 ) & & ( sEvent . button . x < 372 ) )
{
2009-05-29 04:50:33 +03:00
// New selection. py is the index in selMaps.
2008-08-02 18:08:03 +03:00
int py = ( ( sEvent . button . y - 121 ) / 25 ) + ourScenSel - > mapsel . slid - > whereAreWe ;
2009-05-29 04:50:33 +03:00
if ( py < ourScenSel - > mapsel . slid - > positionsAmnt ) {
CGI - > soundh - > playSound ( soundBase : : button ) ;
ourScenSel - > mapsel . select ( py ) ;
}
}
2008-08-02 18:08:03 +03:00
}
else if ( ( sEvent . type = = SDL_MOUSEBUTTONUP ) & & ( sEvent . button . button = = SDL_BUTTON_LEFT ) )
{
2008-08-06 01:11:32 +03:00
Button * prnr = ourScenSel - > pressed ;
2008-08-02 18:08:03 +03:00
if ( ourScenSel - > pressed & & ourScenSel - > pressed - > state = = 1 )
{
ourScenSel - > pressed - > press ( false ) ;
ourScenSel - > pressed = NULL ;
}
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( isItIn ( & btns [ i ] - > pos , sEvent . motion . x , sEvent . motion . y ) )
{
if ( btns [ i ] - > selectable )
btns [ i ] - > select ( true ) ;
2008-08-06 01:11:32 +03:00
if ( btns [ i ] - > type = = 1 & & ( ( Button * ) btns [ i ] ) - > fun )
( ( Button * ) btns [ i ] ) - > fun ( ) ;
2008-08-02 18:08:03 +03:00
int zz = btns . size ( ) ;
if ( i > = zz )
break ;
if ( btns [ i ] = = prnr & & btns [ i ] - > type = = 2 )
{
2008-08-06 01:11:32 +03:00
( ( IntBut * ) ( btns [ i ] ) ) - > set ( ) ;
2009-05-29 04:50:33 +03:00
ourScenSel - > mapsel . updateSelection ( ) ;
2008-08-02 18:08:03 +03:00
ourScenSel - > mapsel . slid - > whereAreWe = 0 ;
2009-05-29 04:50:33 +03:00
ourScenSel - > mapsel . slid - > positionsAmnt = ourScenSel - > mapsel . selMaps . size ( ) ;
2008-08-02 18:08:03 +03:00
ourScenSel - > mapsel . slid - > updateSlid ( ) ;
2009-05-29 04:50:33 +03:00
ourScenSel - > mapsel . select ( 0 ) ;
2008-08-02 18:08:03 +03:00
ourScenSel - > mapsel . printMaps ( 0 ) ;
}
}
}
}
else if ( sEvent . type = = SDL_MOUSEMOTION )
{
if ( highlighted )
{
if ( isItIn ( & highlighted - > pos , sEvent . motion . x , sEvent . motion . y ) )
return ;
else
{
highlighted - > hover ( false ) ;
highlighted = NULL ;
}
}
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( ! btns [ i ] - > highlightable )
continue ;
if ( isItIn ( & btns [ i ] - > pos , sEvent . motion . x , sEvent . motion . y ) )
{
btns [ i ] - > hover ( true ) ;
highlighted = btns [ i ] ;
return ;
}
else if ( btns [ i ] - > highlighted )
btns [ i ] - > hover ( false ) ;
}
}
}
StartInfo CPreGame : : runLoop ( )
{
SDL_Event sEvent ;
2009-05-01 19:14:29 +03:00
ret . turnTime = 0 ;
2008-08-02 18:08:03 +03:00
while ( run )
{
try
{
2009-02-11 19:03:30 +02:00
while ( SDL_PollEvent ( & sEvent ) ) //handle all events
2008-08-02 18:08:03 +03:00
{
menuItems * current = currentItems ( ) ;
if ( sEvent . type = = SDL_QUIT )
{
2008-12-21 21:17:35 +02:00
exit ( EXIT_SUCCESS ) ;
2008-08-02 18:08:03 +03:00
return ret ;
}
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < interested . size ( ) ; + + i ) {
2008-08-02 18:08:03 +03:00
interested [ i ] - > handleIt ( sEvent ) ;
2008-12-21 21:17:35 +02:00
}
2008-08-02 18:08:03 +03:00
if ( ! current )
{
( this - > * handleOther ) ( sEvent ) ;
}
else if ( sEvent . type = = SDL_KEYDOWN )
{
if ( sEvent . key . keysym . sym = = SDLK_q )
2008-09-19 15:09:15 +03:00
{
2008-12-21 21:17:35 +02:00
exit ( EXIT_SUCCESS ) ;
2008-09-19 15:09:15 +03:00
}
if ( sEvent . key . keysym . sym = = SDLK_F4 & & ( sEvent . key . keysym . mod & KMOD_LALT ) ) //Alt+F4
{
2008-12-21 21:17:35 +02:00
exit ( EXIT_SUCCESS ) ;
2008-09-19 15:09:15 +03:00
}
2008-08-02 18:08:03 +03:00
/*if (state==EState::newGame)
{
switch ( sEvent . key . keysym . sym )
{
case SDLK_LEFT :
{
if ( currentItems ( ) - > lNewGame . x > 0 )
currentItems ( ) - > lNewGame . x - - ;
break ;
}
case ( SDLK_RIGHT ) :
{
currentItems ( ) - > lNewGame . x + + ;
break ;
}
case ( SDLK_UP ) :
{
if ( currentItems ( ) - > lNewGame . y > 0 )
currentItems ( ) - > lNewGame . y - - ;
break ;
}
case ( SDLK_DOWN ) :
{
currentItems ( ) - > lNewGame . y + + ;
break ;
}
}
showNewMenu ( ) ;
} */
}
else if ( sEvent . type = = SDL_MOUSEMOTION )
{
CGI - > curh - > cursorMove ( sEvent . motion . x , sEvent . motion . y ) ; //for graphical mouse
if ( currentMessage ) continue ;
if ( current - > highlighted )
{
switch ( current - > highlighted )
{
case 1 :
{
if ( isItIn ( & current - > lNewGame , sEvent . motion . x , sEvent . motion . y ) )
continue ;
else
{
current - > highlighted = 0 ;
highlightButton ( 1 , 0 ) ;
}
break ;
}
case 2 :
{
if ( isItIn ( & current - > lLoadGame , sEvent . motion . x , sEvent . motion . y ) )
continue ;
else
{
current - > highlighted = 0 ;
highlightButton ( 2 , 0 ) ;
}
break ;
}
case 3 :
{
if ( isItIn ( & current - > lHighScores , sEvent . motion . x , sEvent . motion . y ) )
continue ;
else
{
current - > highlighted = 0 ;
highlightButton ( 3 , 0 ) ;
}
break ;
}
case 4 :
{
if ( isItIn ( & current - > lCredits , sEvent . motion . x , sEvent . motion . y ) )
continue ;
else
{
current - > highlighted = 0 ;
highlightButton ( 4 , 0 ) ;
}
break ;
}
case 5 :
{
if ( isItIn ( & current - > lQuit , sEvent . motion . x , sEvent . motion . y ) )
continue ;
else
{
current - > highlighted = 0 ;
highlightButton ( 5 , 0 ) ;
}
break ;
}
} //switch (current->highlighted)
} // if (current->highlighted)
if ( isItIn ( & current - > lNewGame , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 1 , 2 ) ;
current - > highlighted = 1 ;
}
else if ( isItIn ( & current - > lLoadGame , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 2 , 2 ) ;
current - > highlighted = 2 ;
}
else if ( isItIn ( & current - > lHighScores , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 3 , 2 ) ;
current - > highlighted = 3 ;
}
else if ( isItIn ( & current - > lCredits , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 4 , 2 ) ;
current - > highlighted = 4 ;
}
else if ( isItIn ( & current - > lQuit , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 5 , 2 ) ;
current - > highlighted = 5 ;
}
}
else if ( ( sEvent . type = = SDL_MOUSEBUTTONDOWN ) & & ( sEvent . button . button = = SDL_BUTTON_LEFT ) )
{
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( isItIn ( & btns [ i ] - > pos , sEvent . motion . x , sEvent . motion . y ) )
{
btns [ i ] - > press ( true ) ;
//SDL_BlitSurface((btns[i].imgs)->ourImages[1].bitmap,NULL,screen,&btns[i].pos);
//updateRect(&btns[i].pos);
}
}
if ( currentMessage ) continue ;
if ( isItIn ( & current - > lNewGame , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 1 , 1 ) ;
current - > highlighted = 1 ;
}
else if ( isItIn ( & current - > lLoadGame , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 2 , 1 ) ;
current - > highlighted = 2 ;
}
else if ( isItIn ( & current - > lHighScores , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 3 , 1 ) ;
current - > highlighted = 3 ;
}
else if ( isItIn ( & current - > lCredits , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 4 , 1 ) ;
current - > highlighted = 4 ;
}
else if ( isItIn ( & current - > lQuit , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 5 , 1 ) ;
current - > highlighted = 5 ;
}
2009-04-22 21:48:56 +03:00
if ( current - > highlighted )
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( soundBase : : button ) ;
2008-08-02 18:08:03 +03:00
}
else if ( ( sEvent . type = = SDL_MOUSEBUTTONUP ) & & ( sEvent . button . button = = SDL_BUTTON_LEFT ) )
{
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < btns . size ( ) ; + + i )
2008-08-02 18:08:03 +03:00
{
if ( isItIn ( & btns [ i ] - > pos , sEvent . motion . x , sEvent . motion . y ) )
2008-08-06 01:11:32 +03:00
( ( Button * ) btns [ i ] ) - > fun ( ) ;
2008-08-02 18:08:03 +03:00
else
{
btns [ i ] - > press ( false ) ;
//SDL_BlitSurface((btns[i].imgs)->ourImages[0].bitmap,NULL,screen,&btns[i].pos);
//updateRect(&btns[i].pos);
}
}
if ( currentMessage ) continue ;
if ( isItIn ( & current - > lNewGame , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 1 , 2 ) ;
current - > highlighted = 1 ;
2009-02-01 16:11:41 +02:00
if ( current - > fNewGame )
( this - > * ( current - > fNewGame ) ) ( ) ;
2008-08-02 18:08:03 +03:00
}
else if ( isItIn ( & current - > lLoadGame , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 2 , 2 ) ;
current - > highlighted = 2 ;
2009-02-01 16:11:41 +02:00
if ( current - > fLoadGame )
( this - > * ( current - > fLoadGame ) ) ( ) ;
2008-08-02 18:08:03 +03:00
}
else if ( isItIn ( & current - > lHighScores , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 3 , 2 ) ;
current - > highlighted = 3 ;
}
else if ( isItIn ( & current - > lCredits , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 4 , 2 ) ;
current - > highlighted = 4 ;
}
else if ( isItIn ( & current - > lQuit , sEvent . motion . x , sEvent . motion . y ) )
{
highlightButton ( 5 , 2 ) ;
current - > highlighted = 5 ;
2009-02-01 16:11:41 +02:00
if ( current - > fQuit )
( this - > * ( current - > fQuit ) ) ( ) ;
2008-08-02 18:08:03 +03:00
}
}
else if ( ( sEvent . type = = SDL_MOUSEBUTTONDOWN ) & & ( sEvent . button . button = = SDL_BUTTON_RIGHT ) )
{
if ( currentMessage ) continue ;
if ( isItIn ( & current - > lNewGame , sEvent . motion . x , sEvent . motion . y ) )
{
showCenBox ( buttonText ( 0 ) ) ;
}
else if ( isItIn ( & current - > lLoadGame , sEvent . motion . x , sEvent . motion . y ) )
{
showCenBox ( buttonText ( 1 ) ) ;
}
else if ( isItIn ( & current - > lHighScores , sEvent . motion . x , sEvent . motion . y ) )
{
showCenBox ( buttonText ( 2 ) ) ;
}
else if ( isItIn ( & current - > lCredits , sEvent . motion . x , sEvent . motion . y ) )
{
showCenBox ( buttonText ( 3 ) ) ;
}
else if ( isItIn ( & ourMainMenu - > lQuit , sEvent . motion . x , sEvent . motion . y ) )
{
showCenBox ( buttonText ( 4 ) ) ;
}
}
else if ( ( sEvent . type = = SDL_MOUSEBUTTONUP ) & & ( sEvent . button . button = = SDL_BUTTON_RIGHT ) & & currentMessage )
{
hideBox ( ) ;
}
}
2009-02-11 19:03:30 +02:00
} HANDLE_EXCEPTION
2008-08-02 18:08:03 +03:00
CGI - > curh - > draw1 ( ) ;
SDL_Flip ( screen ) ;
CGI - > curh - > draw2 ( ) ;
SDL_Delay ( 20 ) ; //give time for other apps
}
2009-05-04 02:38:08 +03:00
ret . mode = ( fromMenu = = newGame ) ? 0 : 1 ;
2008-08-02 18:08:03 +03:00
return ret ;
}
std : : string CPreGame : : buttonText ( int which )
{
if ( state = = mainMenu )
{
switch ( which )
{
case 0 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 3 ] . second ;
2008-08-02 18:08:03 +03:00
case 1 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 4 ] . second ;
2008-08-02 18:08:03 +03:00
case 2 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 5 ] . second ;
2008-08-02 18:08:03 +03:00
case 3 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 6 ] . second ;
2008-08-02 18:08:03 +03:00
case 4 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 7 ] . second ;
2008-08-02 18:08:03 +03:00
}
}
2008-11-16 03:06:15 +02:00
else if ( state = = newGame | | state = = loadGame )
2008-08-02 18:08:03 +03:00
{
switch ( which )
{
case 0 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 10 ] . second ;
2008-08-02 18:08:03 +03:00
case 1 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 11 ] . second ;
2008-08-02 18:08:03 +03:00
case 2 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 12 ] . second ;
2008-08-02 18:08:03 +03:00
case 3 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 13 ] . second ;
2008-08-02 18:08:03 +03:00
case 4 :
2008-11-28 03:36:34 +02:00
return CGI - > generaltexth - > zelp [ 14 ] . second ;
2008-08-02 18:08:03 +03:00
}
}
return std : : string ( ) ;
}
void CPreGame : : quitAskBox ( )
{
showAskBox ( " \" {} Are you sure you want to quit? \" " , NULL , NULL ) ;
}
2009-05-29 04:54:45 +03:00
// Sort the maps on the new key (map size, map name, ...)
2008-08-02 18:08:03 +03:00
void CPreGame : : sortMaps ( )
{
2009-05-29 04:54:45 +03:00
std : : vector < CMapInfo * > & sm = ourScenSel - > mapsel . selMaps ;
std : : sort ( sm . begin ( ) , sm . end ( ) , mapSorter ( _name ) ) ;
if ( ourScenSel - > mapsel . sortBy ! = _name )
std : : stable_sort ( sm . begin ( ) , sm . end ( ) , mapSorter ( ourScenSel - > mapsel . sortBy ) ) ;
2009-05-29 04:50:33 +03:00
ourScenSel - > mapsel . select ( 0 , false , true ) ;
2008-08-06 01:11:32 +03:00
ourScenSel - > mapsel . slid - > whereAreWe = 0 ;
ourScenSel - > mapsel . slid - > updateSlid ( ) ;
2008-08-02 18:08:03 +03:00
printMapsFrom ( 0 ) ;
}
2009-05-29 04:54:45 +03:00
2008-08-02 18:08:03 +03:00
void CPreGame : : setTurnLength ( int on )
{
int min ;
switch ( on )
{
case 0 :
min = 1 ;
break ;
case 1 :
min = 2 ;
break ;
case 2 :
min = 4 ;
break ;
case 3 :
min = 6 ;
break ;
case 4 :
min = 8 ;
break ;
case 5 :
min = 10 ;
break ;
case 6 :
min = 15 ;
break ;
case 7 :
min = 20 ;
break ;
case 8 :
min = 25 ;
break ;
case 9 :
min = 30 ;
break ;
case 10 :
min = 0 ;
break ;
default :
min = 0 ;
break ;
}
SDL_BlitSurface ( ourOptions - > bg , & genRect ( 23 , 134 , 256 , 547 ) , screen , & genRect ( 23 , 134 , 258 , 553 ) ) ;
updateRect ( & genRect ( 23 , 134 , 258 , 553 ) ) ;
if ( min )
{
std : : ostringstream os ;
os < < min < < " Minutes " ;
CSDL_Ext : : printAtMiddle ( os . str ( ) , 323 , 563 , GEOR13 ) ;
}
else CSDL_Ext : : printAtMiddle ( " Unlimited " , 323 , 563 , GEOR13 ) ;
}
2008-11-16 03:06:15 +02:00
void CPreGame : : showLoadMenu ( )
{
if ( currentTab /*==&ourScenSel->mapsel*/ )
currentTab - > hide ( ) ;
btns . clear ( ) ;
interested . clear ( ) ;
handleOther = NULL ;
state = loadGame ;
2009-05-04 02:38:08 +03:00
fromMenu = loadGame ;
ourScenSel - > mapsel . slid - > capacity = 18 ;
2008-11-16 03:06:15 +02:00
SDL_BlitSurface ( ourLoadMenu - > background , NULL , screen , NULL ) ;
SDL_BlitSurface ( ourLoadMenu - > newGame - > ourImages [ 0 ] . bitmap , NULL , screen , & ourLoadMenu - > lNewGame ) ;
SDL_BlitSurface ( ourLoadMenu - > loadGame - > ourImages [ 0 ] . bitmap , NULL , screen , & ourLoadMenu - > lLoadGame ) ;
SDL_BlitSurface ( ourLoadMenu - > highScores - > ourImages [ 0 ] . bitmap , NULL , screen , & ourLoadMenu - > lHighScores ) ;
SDL_BlitSurface ( ourLoadMenu - > credits - > ourImages [ 0 ] . bitmap , NULL , screen , & ourLoadMenu - > lCredits ) ;
SDL_BlitSurface ( ourLoadMenu - > quit - > ourImages [ 0 ] . bitmap , NULL , screen , & ourLoadMenu - > lQuit ) ;
//SDL_Flip(screen);
CSDL_Ext : : update ( screen ) ;
first = true ;
}
void CPreGame : : initLoadMenu ( )
{
ourLoadMenu = new menuItems ( ) ;
ourLoadMenu - > bgAd = BitmapHandler : : loadBitmap ( " ZLOADGAM.bmp " ) ;
ourLoadMenu - > background = BitmapHandler : : loadBitmap ( " ZPIC1005.bmp " ) ;
blitAt ( ourLoadMenu - > bgAd , 114 , 312 , ourLoadMenu - > background ) ;
//loading menu buttons
ourLoadMenu - > newGame = CDefHandler : : giveDef ( " ZTSINGL.DEF " ) ;
ourLoadMenu - > loadGame = CDefHandler : : giveDef ( " ZTMULTI.DEF " ) ;
ourLoadMenu - > highScores = CDefHandler : : giveDef ( " ZTCAMPN.DEF " ) ;
ourLoadMenu - > credits = CDefHandler : : giveDef ( " ZTTUTOR.DEF " ) ;
ourLoadMenu - > quit = CDefHandler : : giveDef ( " ZTBACK.DEF " ) ;
// single scenario
ourLoadMenu - > lNewGame . h = ourLoadMenu - > newGame - > ourImages [ 0 ] . bitmap - > h ;
ourLoadMenu - > lNewGame . w = ourLoadMenu - > newGame - > ourImages [ 0 ] . bitmap - > w ;
ourLoadMenu - > lNewGame . x = 545 ;
ourLoadMenu - > lNewGame . y = 4 ;
ourLoadMenu - > fNewGame = & CPreGame : : showScenSel ;
//multiplayer
ourLoadMenu - > lLoadGame . h = ourLoadMenu - > loadGame - > ourImages [ 0 ] . bitmap - > h ;
ourLoadMenu - > lLoadGame . w = ourLoadMenu - > loadGame - > ourImages [ 0 ] . bitmap - > w ;
ourLoadMenu - > lLoadGame . x = 568 ;
ourLoadMenu - > lLoadGame . y = 120 ;
2009-02-01 16:11:41 +02:00
ourLoadMenu - > fLoadGame = NULL ;
2008-11-16 03:06:15 +02:00
//campaign
ourLoadMenu - > lHighScores . h = ourLoadMenu - > highScores - > ourImages [ 0 ] . bitmap - > h ;
ourLoadMenu - > lHighScores . w = ourLoadMenu - > highScores - > ourImages [ 0 ] . bitmap - > w ;
ourLoadMenu - > lHighScores . x = 541 ;
ourLoadMenu - > lHighScores . y = 233 ;
2009-02-01 16:11:41 +02:00
ourLoadMenu - > fHighScores = NULL ;
2008-11-16 03:06:15 +02:00
//tutorial
ourLoadMenu - > lCredits . h = ourLoadMenu - > credits - > ourImages [ 0 ] . bitmap - > h ;
ourLoadMenu - > lCredits . w = ourLoadMenu - > credits - > ourImages [ 0 ] . bitmap - > w ;
ourLoadMenu - > lCredits . x = 545 ;
ourLoadMenu - > lCredits . y = 358 ;
2009-02-01 16:11:41 +02:00
ourLoadMenu - > fCredits = NULL ;
2008-11-16 03:06:15 +02:00
//back
ourLoadMenu - > lQuit . h = ourLoadMenu - > quit - > ourImages [ 0 ] . bitmap - > h ;
ourLoadMenu - > lQuit . w = ourLoadMenu - > quit - > ourImages [ 0 ] . bitmap - > w ;
ourLoadMenu - > lQuit . x = 582 ;
ourLoadMenu - > lQuit . y = 464 ;
ourLoadMenu - > fQuit = & CPreGame : : showMainMenu ;
ourLoadMenu - > highlighted = 0 ;
}
CPreGame : : ~ CPreGame ( )
{
delete ourMainMenu ;
delete ourNewMenu ;
delete ourLoadMenu ;
delete ok ;
delete cancel ;
}
2009-05-10 01:19:41 +03:00
void CPreGame : : begin ( )
{
if ( ! ret . mapname . size ( ) ) //empty mapname (savename) - do nothing (no map/game selected)
return ;
run = false ;
ret . difficulty = ourScenSel - > selectedDiff ;
}
2008-11-16 03:06:15 +02:00
CPreGame : : menuItems : : menuItems ( )
{
}
CPreGame : : menuItems : : ~ menuItems ( )
{
delete this - > newGame ;
delete this - > loadGame ;
delete this - > highScores ;
delete this - > credits ;
delete this - > quit ;
SDL_FreeSurface ( bgAd ) ;
SDL_FreeSurface ( background ) ;
}
ScenSel : : ScenSel ( )
:
difficulty ( new CPoinGroup ( ) ) ,
2009-04-15 13:20:47 +03:00
bScens ( genRect ( 0 , 0 , 414 , 81 ) , boost : : bind ( & CPreGame : : showScenList , CPG ) , CDefHandler : : giveDef ( " GSPBUTT.DEF " ) ) ,
bOptions ( genRect ( 0 , 0 , 414 , 509 ) , boost : : bind ( & CPreGame : : showOptions , CPG ) , CDefHandler : : giveDef ( " GSPBUTT.DEF " ) ) ,
bRandom ( genRect ( 0 , 0 , 414 , 105 ) , boost : : bind ( & CPreGame : : showScenList , CPG ) , CDefHandler : : giveDef ( " GSPBUTT.DEF " ) ) ,
bBegin ( genRect ( 0 , 0 , 414 , 535 ) , boost : : bind ( & CPreGame : : begin , CPG ) , CDefHandler : : giveDef ( " SCNRBEG.DEF " ) ) ,
bLoad ( genRect ( 0 , 0 , 414 , 535 ) , boost : : bind ( & CPreGame : : begin , CPG ) , CDefHandler : : giveDef ( " SCNRLOD.DEF " ) ) ,
bBack ( genRect ( 0 , 0 , 584 , 535 ) , boost : : bind ( & CPreGame : : showNewMenu , CPG ) , CDefHandler : : giveDef ( " SCNRBACK.DEF " ) ) ,
2008-11-16 03:06:15 +02:00
bEasy ( genRect ( 0 , 0 , 506 , 456 ) , NULL , CDefHandler : : giveDef ( " GSPBUT3.DEF " ) , true , difficulty , 0 ) ,
bNormal ( genRect ( 0 , 0 , 538 , 456 ) , NULL , CDefHandler : : giveDef ( " GSPBUT4.DEF " ) , true , difficulty , 1 ) ,
bHard ( genRect ( 0 , 0 , 570 , 456 ) , NULL , CDefHandler : : giveDef ( " GSPBUT5.DEF " ) , true , difficulty , 2 ) ,
bExpert ( genRect ( 0 , 0 , 602 , 456 ) , NULL , CDefHandler : : giveDef ( " GSPBUT6.DEF " ) , true , difficulty , 3 ) ,
2009-04-15 13:20:47 +03:00
bImpossible ( genRect ( 0 , 0 , 634 , 456 ) , NULL , CDefHandler : : giveDef ( " GSPBUT7.DEF " ) , true , difficulty , 4 )
2008-11-16 03:06:15 +02:00
{
pressed = NULL ;
listShowed = false ;
if ( rand ( ) % 2 )
background = BitmapHandler : : loadBitmap ( " ZPIC1000.bmp " ) ;
else
background = BitmapHandler : : loadBitmap ( " ZPIC1001.bmp " ) ;
2009-02-03 07:28:05 +02:00
savenameStrip = BitmapHandler : : loadBitmap ( " GSSTRIP.bmp " ) ;
2008-11-16 03:06:15 +02:00
scenInf = BitmapHandler : : loadBitmap ( " GSELPOP1.bmp " ) ;
randMap = BitmapHandler : : loadBitmap ( " RANMAPBK.bmp " ) ;
options = BitmapHandler : : loadBitmap ( " ADVOPTBK.bmp " ) ;
SDL_SetColorKey ( scenInf , SDL_SRCCOLORKEY , SDL_MapRGB ( scenInf - > format , 0 , 255 , 255 ) ) ;
SDL_SetColorKey ( randMap , SDL_SRCCOLORKEY , SDL_MapRGB ( randMap - > format , 0 , 255 , 255 ) ) ;
SDL_SetColorKey ( options , SDL_SRCCOLORKEY , SDL_MapRGB ( options - > format , 0 , 255 , 255 ) ) ;
difficulty - > type = 1 ;
selectedDiff = - 77 ;
difficulty - > gdzie = & selectedDiff ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < bScens . imgs - > ourImages . size ( ) ; + + i ) {
CSDL_Ext : : printAt (
CGI - > generaltexth - > allTexts [ 500 ] ,
25 + i ,
2 + i ,
GEOR13 ,
zwykly ,
bScens . imgs - > ourImages [ i ] . bitmap
) ; //"Show Available Scenarios"
}
for ( size_t i = 0 ; i < bRandom . imgs - > ourImages . size ( ) ; + + i ) {
CSDL_Ext : : printAt (
CGI - > generaltexth - > allTexts [ 740 ] ,
25 + i ,
2 + i ,
GEOR13 ,
zwykly ,
bRandom . imgs - > ourImages [ i ] . bitmap
) ;
}
for ( size_t i = 0 ; i < bOptions . imgs - > ourImages . size ( ) ; + + i ) {
CSDL_Ext : : printAt (
CGI - > generaltexth - > allTexts [ 501 ] ,
25 + i ,
2 + i ,
GEOR13 ,
zwykly ,
bOptions . imgs - > ourImages [ i ] . bitmap
) ; //"Show Advanced Options"
}
2008-11-16 03:06:15 +02:00
}
ScenSel : : ~ ScenSel ( )
{
delete difficulty ;
SDL_FreeSurface ( scenInf ) ;
SDL_FreeSurface ( randMap ) ;
SDL_FreeSurface ( background ) ;
SDL_FreeSurface ( options ) ;
2009-05-06 05:32:36 +03:00
}