2012-06-26 20:23:05 +00:00
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
2012-09-15 13:33:08 +00:00
# include "object/robotmain.h"
2012-06-26 20:23:05 +00:00
# include "CBot/CBotDll.h"
2012-09-15 13:33:08 +00:00
# include "app/app.h"
2012-09-20 18:37:37 +00:00
2012-06-26 20:23:05 +00:00
# include "common/event.h"
2012-09-15 13:33:08 +00:00
# include "common/global.h"
# include "common/iman.h"
2012-09-29 23:51:37 +00:00
# include "common/logger.h"
2012-06-26 20:23:05 +00:00
# include "common/misc.h"
# include "common/profile.h"
# include "common/restext.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "graphics/engine/camera.h"
# include "graphics/engine/cloud.h"
# include "graphics/engine/engine.h"
# include "graphics/engine/lightman.h"
# include "graphics/engine/lightning.h"
2013-03-31 11:06:38 +00:00
# include "graphics/engine/modelmanager.h"
2012-09-15 13:33:08 +00:00
# include "graphics/engine/particle.h"
# include "graphics/engine/planet.h"
# include "graphics/engine/pyro.h"
# include "graphics/engine/terrain.h"
# include "graphics/engine/text.h"
# include "graphics/engine/water.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "math/const.h"
# include "math/geometry.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "object/auto/auto.h"
# include "object/auto/autobase.h"
# include "object/brain.h"
# include "object/mainmovie.h"
2012-06-26 20:23:05 +00:00
# include "object/motion/motion.h"
# include "object/motion/motionhuman.h"
2012-09-15 13:33:08 +00:00
# include "object/motion/motiontoto.h"
# include "object/object.h"
2012-06-26 20:23:05 +00:00
# include "object/task/task.h"
# include "object/task/taskbuild.h"
2012-09-15 13:33:08 +00:00
# include "object/task/taskmanip.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "physics/physics.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "script/cbottoken.h"
# include "script/cmdtoken.h"
# include "script/script.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "sound/sound.h"
2012-09-20 18:37:37 +00:00
2012-09-15 13:33:08 +00:00
# include "ui/button.h"
2012-06-26 20:23:05 +00:00
# include "ui/displayinfo.h"
2012-09-15 13:33:08 +00:00
# include "ui/displaytext.h"
# include "ui/edit.h"
2012-06-26 20:23:05 +00:00
# include "ui/interface.h"
# include "ui/label.h"
# include "ui/maindialog.h"
# include "ui/mainmap.h"
2012-09-15 13:33:08 +00:00
# include "ui/mainshort.h"
# include "ui/map.h"
# include "ui/shortcut.h"
# include "ui/slider.h"
# include "ui/window.h"
2013-05-26 17:34:05 +00:00
# include <iomanip>
2012-09-15 13:33:08 +00:00
2013-02-16 21:37:43 +00:00
template < > CRobotMain * CSingleton < CRobotMain > : : m_instance = nullptr ;
2012-09-19 16:32:18 +00:00
2012-09-15 13:33:08 +00:00
// TODO: remove once using std::string
const int MAX_FNAME = 255 ;
2012-06-26 20:23:05 +00:00
# define CBOT_STACK true // saves the stack of programs CBOT
const float UNIT = 4.0f ;
// Global variables.
long g_id ; // unique identifier
2012-09-17 22:01:00 +00:00
int g_build ; // constructible buildings
int g_researchDone ; // research done
2012-06-26 20:23:05 +00:00
long g_researchEnable ; // research available
float g_unit ; // conversion factor
2012-06-30 23:00:27 +00:00
// Static variables
static CBotClass * m_pClassFILE ;
2013-10-12 16:48:28 +00:00
//static CBotProgram* m_pFuncFile;
2012-06-30 23:00:27 +00:00
static int m_CompteurFileOpen = 0 ;
2012-09-26 20:57:43 +00:00
static std : : string m_filesDir ;
2012-06-30 23:00:27 +00:00
// Prepares a file name.
void PrepareFilename ( CBotString & filename )
{
2012-09-22 12:40:13 +00:00
int pos = filename . ReverseFind ( ' / ' ) ;
2012-06-30 23:00:27 +00:00
if ( pos > 0 )
{
filename = filename . Mid ( pos + 1 ) ; // Remove files with
}
pos = filename . ReverseFind ( ' / ' ) ;
if ( pos > 0 )
{
filename = filename . Mid ( pos + 1 ) ; // also with /
}
pos = filename . ReverseFind ( ' : ' ) ;
if ( pos > 0 )
{
filename = filename . Mid ( pos + 1 ) ; // also removes the drive letter C:
}
2012-09-26 20:57:43 +00:00
filename = CBotString ( m_filesDir . c_str ( ) ) + CBotString ( " / " ) + filename ;
2012-06-30 23:00:27 +00:00
}
// constructor of the class
// get the filename as a parameter
// execution
bool rfconstruct ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
CBotString mode ;
// accepts no parameters
if ( pVar = = NULL ) return true ;
// must be a character string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString ) { Exception = CBotErrBadString ; return false ; }
2012-06-30 23:00:27 +00:00
2012-08-11 18:59:35 +00:00
CBotString filename = pVar - > GetValString ( ) ;
2012-06-30 23:00:27 +00:00
PrepareFilename ( filename ) ;
// there may be a second parameter
2012-08-11 18:59:35 +00:00
pVar = pVar - > GetNext ( ) ;
2012-06-30 23:00:27 +00:00
if ( pVar ! = NULL )
{
// recover mode
2012-08-11 18:59:35 +00:00
mode = pVar - > GetValString ( ) ;
2012-06-30 23:00:27 +00:00
if ( mode ! = " r " & & mode ! = " w " ) { Exception = CBotErrBadParam ; return false ; }
// no third parameter
2012-08-11 18:59:35 +00:00
if ( pVar - > GetNext ( ) ! = NULL ) { Exception = CBotErrOverParam ; return false ; }
2012-06-30 23:00:27 +00:00
}
// saves the file name
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " filename " ) ;
2012-06-30 23:00:27 +00:00
pVar - > SetValString ( filename ) ;
if ( ! mode . IsEmpty ( ) )
{
// opens the requested file
FILE * pFile = fopen ( filename , mode ) ;
if ( pFile = = NULL ) { Exception = CBotErrFileOpen ; return false ; }
m_CompteurFileOpen + + ;
// save the channel file
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-09-17 22:01:00 +00:00
pVar - > SetValInt ( reinterpret_cast < long > ( pFile ) ) ;
2012-06-30 23:00:27 +00:00
}
return true ;
}
// compilation
CBotTypResult cfconstruct ( CBotVar * pThis , CBotVar * & pVar )
{
// accepts no parameters
if ( pVar = = NULL ) return CBotTypResult ( 0 ) ;
// must be a character string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString )
2012-06-30 23:00:27 +00:00
return CBotTypResult ( CBotErrBadString ) ;
// there may be a second parameter
2012-08-11 18:59:35 +00:00
pVar = pVar - > GetNext ( ) ;
2012-06-30 23:00:27 +00:00
if ( pVar ! = NULL )
{
// which must be a string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString )
2012-06-30 23:00:27 +00:00
return CBotTypResult ( CBotErrBadString ) ;
// no third parameter
2012-08-11 18:59:35 +00:00
if ( pVar - > GetNext ( ) ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
2012-06-30 23:00:27 +00:00
}
// the result is void (constructor)
return CBotTypResult ( 0 ) ;
}
// destructor of the class
// execution
bool rfdestruct ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
// retrieve the item "handle"
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-06-30 23:00:27 +00:00
// don't open? no problem :)
2012-08-11 18:59:35 +00:00
if ( pVar - > GetInit ( ) ! = IS_DEF ) return true ;
2012-06-30 23:00:27 +00:00
2012-09-17 22:01:00 +00:00
FILE * pFile = reinterpret_cast < FILE * > ( pVar - > GetValInt ( ) ) ;
2012-06-30 23:00:27 +00:00
fclose ( pFile ) ;
m_CompteurFileOpen - - ;
pVar - > SetInit ( IS_NAN ) ;
return true ;
}
// process FILE :: open
// get the r/w mode as a parameter
// execution
bool rfopen ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
// there must be a parameter
if ( pVar = = NULL ) { Exception = CBotErrLowParam ; return false ; }
// which must be a character string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString ) { Exception = CBotErrBadString ; return false ; }
2012-06-30 23:00:27 +00:00
// There may be a second parameter
2012-08-11 18:59:35 +00:00
if ( pVar - > GetNext ( ) ! = NULL )
2012-06-30 23:00:27 +00:00
{
// if the first parameter is the file name
2012-08-11 18:59:35 +00:00
CBotString filename = pVar - > GetValString ( ) ;
2012-06-30 23:00:27 +00:00
PrepareFilename ( filename ) ;
// saves the file name
2012-08-11 18:59:35 +00:00
CBotVar * pVar2 = pThis - > GetItem ( " filename " ) ;
2012-06-30 23:00:27 +00:00
pVar2 - > SetValString ( filename ) ;
// next parameter is the mode
2012-08-11 18:59:35 +00:00
pVar = pVar - > GetNext ( ) ;
2012-06-30 23:00:27 +00:00
}
2012-08-11 18:59:35 +00:00
CBotString mode = pVar - > GetValString ( ) ;
2012-06-30 23:00:27 +00:00
if ( mode ! = " r " & & mode ! = " w " ) { Exception = CBotErrBadParam ; return false ; }
// no third parameter
2012-08-11 18:59:35 +00:00
if ( pVar - > GetNext ( ) ! = NULL ) { Exception = CBotErrOverParam ; return false ; }
2012-06-30 23:00:27 +00:00
// retrieve the item "handle"
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-06-30 23:00:27 +00:00
// which must not be initialized
2012-08-11 18:59:35 +00:00
if ( pVar - > GetInit ( ) = = IS_DEF ) { Exception = CBotErrFileOpen ; return false ; }
2012-06-30 23:00:27 +00:00
// file contains the name
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " filename " ) ;
CBotString filename = pVar - > GetValString ( ) ;
2012-06-30 23:00:27 +00:00
PrepareFilename ( filename ) ; // if the name was h.filename attribute = "...";
// opens the requested file
FILE * pFile = fopen ( filename , mode ) ;
if ( pFile = = NULL )
{
pResult - > SetValInt ( false ) ;
return true ;
}
m_CompteurFileOpen + + ;
// Registered the channel file
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-09-17 22:01:00 +00:00
pVar - > SetValInt ( reinterpret_cast < long > ( pFile ) ) ;
2012-06-30 23:00:27 +00:00
pResult - > SetValInt ( true ) ;
return true ;
}
// compilation
CBotTypResult cfopen ( CBotVar * pThis , CBotVar * & pVar )
{
// there must be a parameter
if ( pVar = = NULL ) return CBotTypResult ( CBotErrLowParam ) ;
// which must be a string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString )
2012-06-30 23:00:27 +00:00
return CBotTypResult ( CBotErrBadString ) ;
// there may be a second parameter
2012-08-11 18:59:35 +00:00
pVar = pVar - > GetNext ( ) ;
2012-06-30 23:00:27 +00:00
if ( pVar ! = NULL )
{
// which must be a string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString )
2012-06-30 23:00:27 +00:00
return CBotTypResult ( CBotErrBadString ) ;
// no third parameter
2012-08-11 18:59:35 +00:00
if ( pVar - > GetNext ( ) ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
2012-06-30 23:00:27 +00:00
}
// the result is bool
return CBotTypResult ( CBotTypBoolean ) ;
}
// process FILE :: close
// execeution
bool rfclose ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
// it shouldn't be any parameters
if ( pVar ! = NULL ) return CBotErrOverParam ;
// retrieve the item "handle"
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-06-30 23:00:27 +00:00
2012-08-11 18:59:35 +00:00
if ( pVar - > GetInit ( ) ! = IS_DEF ) { Exception = CBotErrNotOpen ; return false ; }
2012-06-30 23:00:27 +00:00
2012-09-17 22:01:00 +00:00
FILE * pFile = reinterpret_cast < FILE * > ( pVar - > GetValInt ( ) ) ;
2012-06-30 23:00:27 +00:00
fclose ( pFile ) ;
m_CompteurFileOpen - - ;
pVar - > SetInit ( IS_NAN ) ;
return true ;
}
// compilation
CBotTypResult cfclose ( CBotVar * pThis , CBotVar * & pVar )
{
// it shouldn't be any parameters
if ( pVar ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
// function returns a result "void"
return CBotTypResult ( 0 ) ;
}
// process FILE :: writeln
// execution
bool rfwrite ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
// there must be a parameter
if ( pVar = = NULL ) { Exception = CBotErrLowParam ; return false ; }
// which must be a character string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString ) { Exception = CBotErrBadString ; return false ; }
2012-06-30 23:00:27 +00:00
2012-08-11 18:59:35 +00:00
CBotString param = pVar - > GetValString ( ) ;
2012-06-30 23:00:27 +00:00
// retrieve the item "handle"
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-06-30 23:00:27 +00:00
2012-08-11 18:59:35 +00:00
if ( pVar - > GetInit ( ) ! = IS_DEF ) { Exception = CBotErrNotOpen ; return false ; }
2012-06-30 23:00:27 +00:00
2012-09-17 22:01:00 +00:00
FILE * pFile = reinterpret_cast < FILE * > ( pVar - > GetValInt ( ) ) ;
2012-06-30 23:00:27 +00:00
int res = fputs ( param + CBotString ( " \n " ) , pFile ) ;
// if an error occurs generate an exception
if ( res < 0 ) { Exception = CBotErrWrite ; return false ; }
return true ;
}
// compilation
CBotTypResult cfwrite ( CBotVar * pThis , CBotVar * & pVar )
{
// there must be a parameter
if ( pVar = = NULL ) return CBotTypResult ( CBotErrLowParam ) ;
// which must be a character string
2012-08-11 18:59:35 +00:00
if ( pVar - > GetType ( ) ! = CBotTypString ) return CBotTypResult ( CBotErrBadString ) ;
2012-06-30 23:00:27 +00:00
// no other parameter
2012-08-11 18:59:35 +00:00
if ( pVar - > GetNext ( ) ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
2012-06-30 23:00:27 +00:00
// the function returns a void result
return CBotTypResult ( 0 ) ;
}
// process FILE :: readln
// execution
bool rfread ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
// it shouldn't be any parameters
if ( pVar ! = NULL ) { Exception = CBotErrOverParam ; return false ; }
// retrieve the item "handle"
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-06-30 23:00:27 +00:00
2012-08-11 18:59:35 +00:00
if ( pVar - > GetInit ( ) ! = IS_DEF ) { Exception = CBotErrNotOpen ; return false ; }
2012-06-30 23:00:27 +00:00
2012-09-17 22:01:00 +00:00
FILE * pFile = reinterpret_cast < FILE * > ( pVar - > GetValInt ( ) ) ;
2012-06-30 23:00:27 +00:00
char chaine [ 2000 ] ;
int i ;
for ( i = 0 ; i < 2000 ; i + + ) chaine [ i ] = 0 ;
fgets ( chaine , 1999 , pFile ) ;
for ( i = 0 ; i < 2000 ; i + + ) if ( chaine [ i ] = = ' \n ' ) chaine [ i ] = 0 ;
// if an error occurs generate an exception
if ( ferror ( pFile ) ) { Exception = CBotErrRead ; return false ; }
pResult - > SetValString ( chaine ) ;
return true ;
}
// compilation
CBotTypResult cfread ( CBotVar * pThis , CBotVar * & pVar )
{
// it should not be any parameter
if ( pVar ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
// function returns a result "string"
return CBotTypResult ( CBotTypString ) ;
}
// process FILE :: readln
// execution
bool rfeof ( CBotVar * pThis , CBotVar * pVar , CBotVar * pResult , int & Exception )
{
// it should not be any parameter
if ( pVar ! = NULL ) { Exception = CBotErrOverParam ; return false ; }
// retrieve the item "handle"
2012-08-11 18:59:35 +00:00
pVar = pThis - > GetItem ( " handle " ) ;
2012-06-30 23:00:27 +00:00
2012-08-11 18:59:35 +00:00
if ( pVar - > GetInit ( ) ! = IS_DEF ) { Exception = CBotErrNotOpen ; return false ; }
2012-06-30 23:00:27 +00:00
2012-09-17 22:01:00 +00:00
FILE * pFile = reinterpret_cast < FILE * > ( pVar - > GetValInt ( ) ) ;
2012-06-30 23:00:27 +00:00
pResult - > SetValInt ( feof ( pFile ) ) ;
return true ;
}
// compilation
CBotTypResult cfeof ( CBotVar * pThis , CBotVar * & pVar )
{
// it shouldn't be any parameter
if ( pVar ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
// the function returns a boolean result
return CBotTypResult ( CBotTypBoolean ) ;
}
void InitClassFILE ( )
{
// create a class for file management
// the use is as follows:
// file canal( "NomFichier.txt" )
// canal.open( "r" ); // open for read
// s = canal.readln( ); // reads a line
// canal.close(); // close the file
// create the class FILE
m_pClassFILE = new CBotClass ( " file " , NULL ) ;
// adds the component ".filename"
m_pClassFILE - > AddItem ( " filename " , CBotTypString ) ;
// adds the component ".handle"
m_pClassFILE - > AddItem ( " handle " , CBotTypInt , PR_PRIVATE ) ;
// define a constructor and a destructor
m_pClassFILE - > AddFunction ( " file " , rfconstruct , cfconstruct ) ;
m_pClassFILE - > AddFunction ( " ~file " , rfdestruct , NULL ) ;
// end of the methods associated
m_pClassFILE - > AddFunction ( " open " , rfopen , cfopen ) ;
m_pClassFILE - > AddFunction ( " close " , rfclose , cfclose ) ;
m_pClassFILE - > AddFunction ( " writeln " , rfwrite , cfwrite ) ;
m_pClassFILE - > AddFunction ( " readln " , rfread , cfread ) ;
m_pClassFILE - > AddFunction ( " eof " , rfeof , cfeof ) ;
2013-10-12 16:48:28 +00:00
//m_pFuncFile = new CBotProgram( );
//CBotStringArray ListFonctions;
//m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
//m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function
2012-06-30 23:00:27 +00:00
}
2012-06-26 20:23:05 +00:00
// Compilation of class "point".
CBotTypResult cPoint ( CBotVar * pThis , CBotVar * & var )
{
if ( ! pThis - > IsElemOfClass ( " point " ) ) return CBotTypResult ( CBotErrBadNum ) ;
if ( var = = NULL ) return CBotTypResult ( 0 ) ; // ok if no parameter
// First parameter (x):
2012-08-11 18:59:35 +00:00
if ( var - > GetType ( ) > CBotTypDouble ) return CBotTypResult ( CBotErrBadNum ) ;
var = var - > GetNext ( ) ;
2012-06-26 20:23:05 +00:00
// Second parameter (y):
if ( var = = NULL ) return CBotTypResult ( CBotErrLowParam ) ;
2012-08-11 18:59:35 +00:00
if ( var - > GetType ( ) > CBotTypDouble ) return CBotTypResult ( CBotErrBadNum ) ;
var = var - > GetNext ( ) ;
2012-06-26 20:23:05 +00:00
// Third parameter (z):
if ( var = = NULL ) // only 2 parameters?
{
return CBotTypResult ( 0 ) ; // this function returns void
}
2012-08-11 18:59:35 +00:00
if ( var - > GetType ( ) > CBotTypDouble ) return CBotTypResult ( CBotErrBadNum ) ;
var = var - > GetNext ( ) ;
2012-06-26 20:23:05 +00:00
if ( var ! = NULL ) return CBotTypResult ( CBotErrOverParam ) ;
return CBotTypResult ( 0 ) ; // this function returns void
}
//Execution of the class "point".
bool rPoint ( CBotVar * pThis , CBotVar * var , CBotVar * pResult , int & Exception )
{
CBotVar * pX , * pY , * pZ ;
if ( var = = NULL ) return true ; // constructor with no parameters is ok
2012-08-11 18:59:35 +00:00
if ( var - > GetType ( ) > CBotTypDouble )
2012-06-26 20:23:05 +00:00
{
Exception = CBotErrBadNum ; return false ;
}
2012-08-11 18:59:35 +00:00
pX = pThis - > GetItem ( " x " ) ;
2012-06-26 20:23:05 +00:00
if ( pX = = NULL )
{
Exception = CBotErrUndefItem ; return false ;
}
2012-08-11 18:59:35 +00:00
pX - > SetValFloat ( var - > GetValFloat ( ) ) ;
var = var - > GetNext ( ) ;
2012-06-26 20:23:05 +00:00
2012-06-26 21:01:17 +00:00
if ( var = = NULL )
2012-06-26 20:23:05 +00:00
{
Exception = CBotErrLowParam ; return false ;
}
2012-08-11 18:59:35 +00:00
if ( var - > GetType ( ) > CBotTypDouble )
2012-06-26 20:23:05 +00:00
{
Exception = CBotErrBadNum ; return false ;
}
2012-08-11 18:59:35 +00:00
pY = pThis - > GetItem ( " y " ) ;
2012-06-26 20:23:05 +00:00
if ( pY = = NULL )
{
Exception = CBotErrUndefItem ; return false ;
}
2012-08-11 18:59:35 +00:00
pY - > SetValFloat ( var - > GetValFloat ( ) ) ;
var = var - > GetNext ( ) ;
2012-06-26 20:23:05 +00:00
if ( var = = NULL )
{
return true ; // ok with only two parameters
}
2012-08-11 18:59:35 +00:00
pZ = pThis - > GetItem ( " z " ) ;
2012-06-26 20:23:05 +00:00
if ( pZ = = NULL )
{
Exception = CBotErrUndefItem ; return false ;
}
2012-08-11 18:59:35 +00:00
pZ - > SetValFloat ( var - > GetValFloat ( ) ) ;
var = var - > GetNext ( ) ;
2012-06-26 20:23:05 +00:00
if ( var ! = NULL )
{
Exception = CBotErrOverParam ; return false ;
}
return true ; // no interruption
}
2012-09-15 13:33:08 +00:00
//! Constructor of robot application
2013-05-04 09:56:03 +00:00
CRobotMain : : CRobotMain ( CApplication * app , bool loadProfile )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_app = app ;
2013-02-16 21:37:43 +00:00
m_eventQueue = m_app - > GetEventQueue ( ) ;
m_sound = m_app - > GetSound ( ) ;
m_engine = Gfx : : CEngine : : GetInstancePointer ( ) ;
m_lightMan = m_engine - > GetLightManager ( ) ;
m_particle = m_engine - > GetParticle ( ) ;
m_water = m_engine - > GetWater ( ) ;
m_cloud = m_engine - > GetCloud ( ) ;
m_lightning = m_engine - > GetLightning ( ) ;
m_planet = m_engine - > GetPlanet ( ) ;
2012-09-15 13:33:08 +00:00
m_interface = new Ui : : CInterface ( ) ;
2013-02-16 21:37:43 +00:00
m_terrain = new Gfx : : CTerrain ( ) ;
m_camera = new Gfx : : CCamera ( ) ;
2012-09-15 13:33:08 +00:00
m_displayText = new Ui : : CDisplayText ( ) ;
2013-02-16 21:37:43 +00:00
m_movie = new CMainMovie ( ) ;
m_dialog = new Ui : : CMainDialog ( ) ;
2012-09-15 13:33:08 +00:00
m_short = new Ui : : CMainShort ( ) ;
m_map = new Ui : : CMainMap ( ) ;
m_displayInfo = nullptr ;
2012-06-26 20:23:05 +00:00
m_engine - > SetTerrain ( m_terrain ) ;
2012-09-15 13:33:08 +00:00
m_filesDir = m_dialog - > GetFilesDir ( ) ;
2012-06-26 20:23:05 +00:00
m_time = 0.0f ;
m_gameTime = 0.0f ;
m_checkEndTime = 0.0f ;
m_phase = PHASE_NAME ;
m_cameraRank = - 1 ;
m_visitLast = EVENT_NULL ;
m_visitObject = 0 ;
m_visitArrow = 0 ;
2013-04-13 14:35:35 +00:00
m_audioTrack = " " ;
2012-09-15 13:33:08 +00:00
m_audioRepeat = true ;
2012-06-26 20:23:05 +00:00
m_delayWriteMessage = 0 ;
m_selectObject = 0 ;
m_infoUsed = 0 ;
2013-03-23 18:04:41 +00:00
m_beginObject = false ;
m_terrainGenerate = false ;
m_terrainInit = false ;
m_terrainInitTextures = false ;
m_terrainCreate = false ;
m_version = 1 ;
2013-04-29 15:26:32 +00:00
m_controller = nullptr ;
2013-03-23 18:04:41 +00:00
m_retroStyle = false ;
2012-09-16 18:00:25 +00:00
m_immediatSatCom = false ;
2012-09-15 13:33:08 +00:00
m_beginSatCom = false ;
2013-03-27 21:20:50 +00:00
m_lockedSatCom = false ;
2012-09-15 13:33:08 +00:00
m_movieLock = false ;
m_satComLock = false ;
m_editLock = false ;
m_editFull = false ;
m_pause = false ;
m_hilite = false ;
m_freePhoto = false ;
m_showPos = false ;
m_selectInsect = false ;
m_showSoluce = false ;
2013-06-21 23:11:37 +00:00
# if DEV_BUILD
2012-09-22 15:36:10 +00:00
m_showAll = true ; // for development
2013-06-21 23:11:37 +00:00
# else
m_showAll = false ;
2013-03-09 14:28:36 +00:00
# endif
2013-06-21 23:11:37 +00:00
2012-09-15 13:33:08 +00:00
m_cheatRadar = false ;
m_fixScene = false ;
m_trainerPilot = false ;
m_suspend = false ;
m_friendAim = false ;
m_resetCreate = false ;
m_shortCut = true ;
m_engine - > SetMovieLock ( m_movieLock ) ;
2012-06-26 20:23:05 +00:00
m_movie - > Flush ( ) ;
m_movieInfoIndex = - 1 ;
m_tooltipPos = Math : : Point ( 0.0f , 0.0f ) ;
2013-12-02 23:11:26 +00:00
m_tooltipName . clear ( ) ;
2012-06-26 20:23:05 +00:00
m_tooltipTime = 0.0f ;
m_endingWinRank = 0 ;
m_endingLostRank = 0 ;
2012-09-15 13:33:08 +00:00
m_winTerminate = false ;
2013-12-26 20:54:05 +00:00
2013-12-26 21:13:04 +00:00
m_exitAfterMission = false ;
2012-06-26 20:23:05 +00:00
2012-09-19 19:23:42 +00:00
m_joystickDeadzone = 0.2f ;
SetDefaultInputBindings ( ) ;
2012-06-26 20:23:05 +00:00
FlushDisplayInfo ( ) ;
m_fontSize = 9.0f ;
m_windowPos = Math : : Point ( 0.15f , 0.17f ) ;
m_windowDim = Math : : Point ( 0.70f , 0.66f ) ;
2013-05-01 19:02:43 +00:00
float fValue ;
int iValue ;
2012-09-15 13:33:08 +00:00
2013-05-26 15:47:54 +00:00
if ( loadProfile )
{
2013-05-04 09:56:03 +00:00
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " FontSize " , fValue ) ) m_fontSize = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " WindowPosX " , fValue ) ) m_windowPos . x = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " WindowPosY " , fValue ) ) m_windowPos . y = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " WindowDimX " , fValue ) ) m_windowDim . x = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " WindowDimY " , fValue ) ) m_windowDim . y = fValue ;
}
2012-06-26 21:01:17 +00:00
2012-06-26 20:23:05 +00:00
m_IOPublic = false ;
m_IODim = Math : : Point ( 320.0f / 640.0f , ( 121.0f + 18.0f * 8 ) / 480.0f ) ;
m_IOPos . x = ( 1.0f - m_IODim . x ) / 2.0f ; // in the middle
m_IOPos . y = ( 1.0f - m_IODim . y ) / 2.0f ;
2012-06-26 21:01:17 +00:00
2013-05-26 15:47:54 +00:00
if ( loadProfile )
{
2013-05-04 09:56:03 +00:00
if ( GetProfile ( ) . GetLocalProfileInt ( " Edit " , " IOPublic " , iValue ) ) m_IOPublic = iValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " IOPosX " , fValue ) ) m_IOPos . x = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " IOPosY " , fValue ) ) m_IOPos . y = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " IODimX " , fValue ) ) m_IODim . x = fValue ;
if ( GetProfile ( ) . GetLocalProfileFloat ( " Edit " , " IODimY " , fValue ) ) m_IODim . y = fValue ;
}
2012-06-26 21:01:17 +00:00
2012-06-26 20:23:05 +00:00
m_short - > FlushShortcuts ( ) ;
InitEye ( ) ;
m_engine - > SetTracePrecision ( 1.0f ) ;
m_cameraPan = 0.0f ;
m_cameraZoom = 0.0f ;
g_id = 0 ;
g_build = 0 ;
g_researchDone = 0 ; // no research done
g_researchEnable = 0 ;
2012-10-05 18:37:20 +00:00
g_unit = UNIT ;
2012-06-26 20:23:05 +00:00
2013-05-01 19:02:43 +00:00
m_gamerName = " " ;
2013-05-04 09:56:03 +00:00
if ( loadProfile ) GetProfile ( ) . GetLocalProfileString ( " Gamer " , " LastName " , m_gamerName ) ;
2012-06-26 20:23:05 +00:00
SetGlobalGamerName ( m_gamerName ) ;
ReadFreeParam ( ) ;
2013-05-04 09:56:03 +00:00
if ( loadProfile ) m_dialog - > SetupRecall ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < MAXSHOWLIMIT ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_showLimit [ i ] . used = false ;
2012-06-26 20:23:05 +00:00
m_showLimit [ i ] . total = 0 ;
m_showLimit [ i ] . link = 0 ;
}
CBotProgram : : SetTimer ( 100 ) ;
CBotProgram : : Init ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < OBJECT_MAX ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-17 22:01:00 +00:00
ObjectType type = static_cast < ObjectType > ( i ) ;
2012-09-15 13:33:08 +00:00
const char * token = GetObjectName ( type ) ;
if ( token [ 0 ] ! = 0 )
2012-06-26 20:23:05 +00:00
CBotProgram : : DefineNum ( token , type ) ;
2012-09-15 13:33:08 +00:00
token = GetObjectAlias ( type ) ;
if ( token [ 0 ] ! = 0 )
2012-06-26 20:23:05 +00:00
CBotProgram : : DefineNum ( token , type ) ;
}
CBotProgram : : DefineNum ( " White " , 0 ) ;
CBotProgram : : DefineNum ( " Black " , 1 ) ;
CBotProgram : : DefineNum ( " Gray " , 2 ) ;
CBotProgram : : DefineNum ( " LightGray " , 3 ) ;
CBotProgram : : DefineNum ( " Red " , 4 ) ;
CBotProgram : : DefineNum ( " Pink " , 5 ) ;
CBotProgram : : DefineNum ( " Purple " , 6 ) ;
CBotProgram : : DefineNum ( " Orange " , 7 ) ;
CBotProgram : : DefineNum ( " Yellow " , 8 ) ;
CBotProgram : : DefineNum ( " Beige " , 9 ) ;
CBotProgram : : DefineNum ( " Brown " , 10 ) ;
CBotProgram : : DefineNum ( " Skin " , 11 ) ;
CBotProgram : : DefineNum ( " Green " , 12 ) ;
CBotProgram : : DefineNum ( " LightGreen " , 13 ) ;
CBotProgram : : DefineNum ( " Blue " , 14 ) ;
CBotProgram : : DefineNum ( " LightBlue " , 15 ) ;
CBotProgram : : DefineNum ( " BlackArrow " , 16 ) ;
CBotProgram : : DefineNum ( " RedArrow " , 17 ) ;
CBotProgram : : DefineNum ( " Metal " , OM_METAL ) ;
CBotProgram : : DefineNum ( " Plastic " , OM_PLASTIC ) ;
CBotProgram : : DefineNum ( " InFront " , TMA_FFRONT ) ;
CBotProgram : : DefineNum ( " Behind " , TMA_FBACK ) ;
CBotProgram : : DefineNum ( " EnergyCell " , TMA_POWER ) ;
2012-09-15 13:33:08 +00:00
CBotProgram : : DefineNum ( " DisplayError " , Ui : : TT_ERROR ) ;
CBotProgram : : DefineNum ( " DisplayWarning " , Ui : : TT_WARNING ) ;
CBotProgram : : DefineNum ( " DisplayInfo " , Ui : : TT_INFO ) ;
CBotProgram : : DefineNum ( " DisplayMessage " , Ui : : TT_MESSAGE ) ;
2012-06-26 20:23:05 +00:00
CBotProgram : : DefineNum ( " FilterNone " , FILTER_NONE ) ;
CBotProgram : : DefineNum ( " FilterOnlyLanding " , FILTER_ONLYLANDING ) ;
CBotProgram : : DefineNum ( " FilterOnlyFliying " , FILTER_ONLYFLYING ) ;
2013-05-05 18:10:36 +00:00
CBotProgram : : DefineNum ( " ExploNone " , 0 ) ;
CBotProgram : : DefineNum ( " ExploBoum " , EXPLO_BOUM ) ;
CBotProgram : : DefineNum ( " ExploBurn " , EXPLO_BURN ) ;
2013-03-31 10:04:12 +00:00
CBotProgram : : DefineNum ( " ExploWater " , EXPLO_WATER ) ;
2013-05-05 18:10:36 +00:00
CBotProgram : : DefineNum ( " ResultNotEnded " , ERR_MISSION_NOTERM ) ;
CBotProgram : : DefineNum ( " ResultLost " , INFO_LOST ) ;
2013-04-30 19:43:59 +00:00
CBotProgram : : DefineNum ( " ResultLostQuick " , INFO_LOSTq ) ;
2013-05-05 18:10:36 +00:00
CBotProgram : : DefineNum ( " ResultWin " , ERR_OK ) ;
CBotProgram : : DefineNum ( " BuildBotFactory " , BUILD_FACTORY ) ;
CBotProgram : : DefineNum ( " BuildDerrick " , BUILD_DERRICK ) ;
CBotProgram : : DefineNum ( " BuildConverter " , BUILD_CONVERT ) ;
CBotProgram : : DefineNum ( " BuildRadarStation " , BUILD_RADAR ) ;
CBotProgram : : DefineNum ( " BuildPowerPlant " , BUILD_ENERGY ) ;
CBotProgram : : DefineNum ( " BuildNuclearPlant " , BUILD_NUCLEAR ) ;
CBotProgram : : DefineNum ( " BuildPowerStation " , BUILD_STATION ) ;
CBotProgram : : DefineNum ( " BuildRepairCenter " , BUILD_REPAIR ) ;
CBotProgram : : DefineNum ( " BuildDefenseTower " , BUILD_TOWER ) ;
CBotProgram : : DefineNum ( " BuildResearchCenter " , BUILD_RESEARCH ) ;
CBotProgram : : DefineNum ( " BuildAutoLab " , BUILD_LABO ) ;
CBotProgram : : DefineNum ( " BuildPowerCaptor " , BUILD_PARA ) ;
CBotProgram : : DefineNum ( " BuildExchangePost " , BUILD_INFO ) ;
CBotProgram : : DefineNum ( " BuildDestroyer " , BUILD_DESTROYER ) ;
CBotProgram : : DefineNum ( " FlatGround " , BUILD_GFLAT ) ;
CBotProgram : : DefineNum ( " UseFlags " , BUILD_FLAG ) ;
CBotProgram : : DefineNum ( " ResearchTracked " , RESEARCH_TANK ) ;
CBotProgram : : DefineNum ( " ResearchWinged " , RESEARCH_FLY ) ;
CBotProgram : : DefineNum ( " ResearchShooter " , RESEARCH_CANON ) ;
CBotProgram : : DefineNum ( " ResearchDefenseTower " , RESEARCH_TOWER ) ;
CBotProgram : : DefineNum ( " ResearchNuclearPlant " , RESEARCH_ATOMIC ) ;
CBotProgram : : DefineNum ( " ResearchThumper " , RESEARCH_THUMP ) ;
CBotProgram : : DefineNum ( " ResearchShielder " , RESEARCH_SHIELD ) ;
CBotProgram : : DefineNum ( " ResearchPhazerShooter " , RESEARCH_PHAZER ) ;
CBotProgram : : DefineNum ( " ResearchLegged " , RESEARCH_iPAW ) ;
CBotProgram : : DefineNum ( " ResearchOrgaShooter " , RESEARCH_iGUN ) ;
CBotProgram : : DefineNum ( " ResearchRecycler " , RESEARCH_RECYCLER ) ;
CBotProgram : : DefineNum ( " ResearchSubber " , RESEARCH_SUBM ) ;
CBotProgram : : DefineNum ( " ResearchSniffer " , RESEARCH_SNIFFER ) ;
2013-05-18 14:44:22 +00:00
//? CBotProgram::
2013-04-30 19:43:59 +00:00
2012-09-29 23:51:37 +00:00
CBotProgram : : DefineNum ( " PolskiPortalColobota " , 1337 ) ;
2012-06-26 20:23:05 +00:00
CBotClass * bc ;
2012-09-15 13:33:08 +00:00
// Add the class Point.
2012-06-26 20:23:05 +00:00
bc = new CBotClass ( " point " , NULL , true ) ; // intrinsic class
bc - > AddItem ( " x " , CBotTypFloat ) ;
bc - > AddItem ( " y " , CBotTypFloat ) ;
bc - > AddItem ( " z " , CBotTypFloat ) ;
bc - > AddFunction ( " point " , rPoint , cPoint ) ;
// Adds the class Object.
bc = new CBotClass ( " object " , NULL ) ;
bc - > AddItem ( " category " , CBotTypResult ( CBotTypInt ) , PR_READ ) ;
bc - > AddItem ( " position " , CBotTypResult ( CBotTypClass , " point " ) , PR_READ ) ;
bc - > AddItem ( " orientation " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " pitch " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " roll " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " energyLevel " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " shieldLevel " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " temperature " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " altitude " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " lifeTime " , CBotTypResult ( CBotTypFloat ) , PR_READ ) ;
bc - > AddItem ( " material " , CBotTypResult ( CBotTypInt ) , PR_READ ) ;
bc - > AddItem ( " energyCell " , CBotTypResult ( CBotTypPointer , " object " ) , PR_READ ) ;
bc - > AddItem ( " load " , CBotTypResult ( CBotTypPointer , " object " ) , PR_READ ) ;
2013-03-31 08:21:22 +00:00
bc - > AddItem ( " id " , CBotTypResult ( CBotTypInt ) , PR_READ ) ;
2013-05-19 19:48:29 +00:00
bc - > AddFunction ( " busy " , CScript : : rBusy , CScript : : cBusy ) ;
bc - > AddFunction ( " factory " , CScript : : rFactory , CScript : : cFactory ) ;
bc - > AddFunction ( " research " , CScript : : rResearch , CScript : : cClassOneFloat ) ;
2013-12-26 17:50:05 +00:00
bc - > AddFunction ( " takeoff " , CScript : : rTakeOff , CScript : : cClassNull ) ;
2013-05-19 19:48:29 +00:00
bc - > AddFunction ( " destroy " , CScript : : rDestroy , CScript : : cClassNull ) ;
2012-06-26 20:23:05 +00:00
// Initializes the class FILE.
InitClassFILE ( ) ;
CScript : : InitFonctions ( ) ;
}
2012-09-15 13:33:08 +00:00
//! Destructor of robot application
2012-06-26 20:23:05 +00:00
CRobotMain : : ~ CRobotMain ( )
{
2012-09-16 18:00:25 +00:00
delete m_displayText ;
m_displayText = nullptr ;
delete m_interface ;
m_interface = nullptr ;
delete m_terrain ;
m_terrain = nullptr ;
delete m_camera ;
m_camera = nullptr ;
delete m_displayText ;
m_displayText = nullptr ;
2012-06-26 20:23:05 +00:00
delete m_movie ;
2012-09-16 18:00:25 +00:00
m_movie = nullptr ;
2012-06-26 20:23:05 +00:00
delete m_dialog ;
2012-09-16 18:00:25 +00:00
m_dialog = nullptr ;
2012-06-26 20:23:05 +00:00
delete m_short ;
2012-09-16 18:00:25 +00:00
m_short = nullptr ;
2012-06-26 20:23:05 +00:00
delete m_map ;
2012-09-16 18:00:25 +00:00
m_map = nullptr ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_app = nullptr ;
}
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
Gfx : : CCamera * CRobotMain : : GetCamera ( )
{
return m_camera ;
}
Gfx : : CTerrain * CRobotMain : : GetTerrain ( )
{
return m_terrain ;
}
Ui : : CInterface * CRobotMain : : GetInterface ( )
{
return m_interface ;
}
Ui : : CDisplayText * CRobotMain : : GetDisplayText ( )
{
return m_displayText ;
}
2013-06-16 19:39:21 +00:00
void CRobotMain : : LoadSceneOnStart ( const std : : string & name , int rank )
{
2013-12-26 20:54:05 +00:00
m_exitAfterMission = true ;
2013-06-16 19:39:21 +00:00
// TODO: fix this ugly dependency :(
m_dialog - > SetSceneName ( name . c_str ( ) ) ;
m_dialog - > SetSceneRank ( rank ) ;
ChangePhase ( PHASE_LOADING ) ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
//! Creates the file colobot.ini at the first time
2012-06-26 20:23:05 +00:00
void CRobotMain : : CreateIni ( )
{
2013-05-04 09:56:03 +00:00
m_dialog - > SetupMemorize ( ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " FontSize " , m_fontSize ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowPosX " , m_windowPos . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowPosY " , m_windowPos . y ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowDimX " , m_windowDim . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowDimY " , m_windowDim . y ) ;
GetProfile ( ) . SetLocalProfileInt ( " Edit " , " IOPublic " , m_IOPublic ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IOPosX " , m_IOPos . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IOPosY " , m_IOPos . y ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IODimX " , m_IODim . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IODimY " , m_IODim . y ) ;
GetProfile ( ) . SaveCurrentDirectory ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-19 16:32:18 +00:00
void CRobotMain : : SetDefaultInputBindings ( )
{
for ( int i = 0 ; i < INPUT_SLOT_MAX ; i + + )
{
2012-10-06 22:46:46 +00:00
m_inputBindings [ i ] . primary = m_inputBindings [ i ] . secondary = KEY_INVALID ;
2012-09-19 16:32:18 +00:00
}
2012-09-19 19:23:42 +00:00
for ( int i = 0 ; i < JOY_AXIS_SLOT_MAX ; i + + )
{
m_joyAxisBindings [ i ] . axis = AXIS_INVALID ;
m_joyAxisBindings [ i ] . invert = false ;
}
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_LEFT ] . primary = KEY ( LEFT ) ;
m_inputBindings [ INPUT_SLOT_RIGHT ] . primary = KEY ( RIGHT ) ;
m_inputBindings [ INPUT_SLOT_UP ] . primary = KEY ( UP ) ;
m_inputBindings [ INPUT_SLOT_DOWN ] . primary = KEY ( DOWN ) ;
2013-12-25 18:34:34 +00:00
m_inputBindings [ INPUT_SLOT_LEFT ] . secondary = KEY ( a ) ;
m_inputBindings [ INPUT_SLOT_RIGHT ] . secondary = KEY ( d ) ;
m_inputBindings [ INPUT_SLOT_UP ] . secondary = KEY ( w ) ;
m_inputBindings [ INPUT_SLOT_DOWN ] . secondary = KEY ( s ) ;
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_GUP ] . primary = VIRTUAL_KMOD ( SHIFT ) ;
m_inputBindings [ INPUT_SLOT_GDOWN ] . primary = VIRTUAL_KMOD ( CTRL ) ;
m_inputBindings [ INPUT_SLOT_CAMERA ] . primary = KEY ( SPACE ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_CAMERA ].secondary = VIRTUAL_JOY(2);
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_DESEL ] . primary = KEY ( KP0 ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_DESEL ].secondary = VIRTUAL_JOY(6);
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_ACTION ] . primary = KEY ( RETURN ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_ACTION ].secondary = VIRTUAL_JOY(1);
m_inputBindings [ INPUT_SLOT_ACTION ] . secondary = KEY ( e ) ;
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_NEAR ] . primary = KEY ( KP_PLUS ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_NEAR ].secondary = VIRTUAL_JOY(5);
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_AWAY ] . primary = KEY ( KP_MINUS ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_AWAY ].secondary = VIRTUAL_JOY(4);
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_NEXT ] . primary = KEY ( TAB ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_NEXT ].secondary = VIRTUAL_JOY(3);
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_HUMAN ] . primary = KEY ( HOME ) ;
2013-12-25 18:43:11 +00:00
// m_inputBindings[INPUT_SLOT_HUMAN ].secondary = VIRTUAL_JOY(7);
2012-10-06 22:46:46 +00:00
m_inputBindings [ INPUT_SLOT_QUIT ] . primary = KEY ( ESCAPE ) ;
m_inputBindings [ INPUT_SLOT_HELP ] . primary = KEY ( F1 ) ;
m_inputBindings [ INPUT_SLOT_PROG ] . primary = KEY ( F2 ) ;
m_inputBindings [ INPUT_SLOT_CBOT ] . primary = KEY ( F3 ) ;
m_inputBindings [ INPUT_SLOT_VISIT ] . primary = KEY ( KP_PERIOD ) ;
m_inputBindings [ INPUT_SLOT_SPEED10 ] . primary = KEY ( F4 ) ;
m_inputBindings [ INPUT_SLOT_SPEED15 ] . primary = KEY ( F5 ) ;
m_inputBindings [ INPUT_SLOT_SPEED20 ] . primary = KEY ( F6 ) ;
2012-09-19 19:23:42 +00:00
m_joyAxisBindings [ JOY_AXIS_SLOT_X ] . axis = 0 ;
m_joyAxisBindings [ JOY_AXIS_SLOT_Y ] . axis = 1 ;
m_joyAxisBindings [ JOY_AXIS_SLOT_Z ] . axis = 2 ;
2012-09-19 16:32:18 +00:00
}
void CRobotMain : : SetInputBinding ( InputSlot slot , InputBinding binding )
{
unsigned int index = static_cast < unsigned int > ( slot ) ;
m_inputBindings [ index ] = binding ;
}
const InputBinding & CRobotMain : : GetInputBinding ( InputSlot slot )
{
unsigned int index = static_cast < unsigned int > ( slot ) ;
return m_inputBindings [ index ] ;
}
2012-06-26 20:23:05 +00:00
2012-09-19 19:23:42 +00:00
void CRobotMain : : SetJoyAxisBinding ( JoyAxisSlot slot , JoyAxisBinding binding )
{
unsigned int index = static_cast < unsigned int > ( slot ) ;
m_joyAxisBindings [ index ] = binding ;
}
const JoyAxisBinding & CRobotMain : : GetJoyAxisBinding ( JoyAxisSlot slot )
{
unsigned int index = static_cast < unsigned int > ( slot ) ;
return m_joyAxisBindings [ index ] ;
}
void CRobotMain : : SetJoystickDeadzone ( float zone )
{
m_joystickDeadzone = zone ;
}
float CRobotMain : : GetJoystickDeadzone ( )
{
return m_joystickDeadzone ;
}
void CRobotMain : : ResetKeyStates ( )
{
m_keyMotion = Math : : Vector ( 0.0f , 0.0f , 0.0f ) ;
m_joyMotion = Math : : Vector ( 0.0f , 0.0f , 0.0f ) ;
}
2012-09-15 13:33:08 +00:00
//! Changes phase
2012-06-26 20:23:05 +00:00
void CRobotMain : : ChangePhase ( Phase phase )
{
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL ) // ends a simulation?
2012-06-26 20:23:05 +00:00
{
SaveAllScript ( ) ;
2013-12-28 11:30:46 +00:00
m_sound - > StopMusic ( 0.0f ) ;
2012-09-17 18:47:27 +00:00
m_camera - > SetControllingObject ( 0 ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
/* TODO: #if _SCHOOL
2012-06-26 20:23:05 +00:00
if ( true )
2012-09-15 13:33:08 +00:00
# else* /
if ( m_gameTime > 10.0f ) // did you play at least 10 seconds?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int rank = m_dialog - > GetSceneRank ( ) ;
int numTry = m_dialog - > GetGamerInfoTry ( rank ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetGamerInfoTry ( rank , numTry + 1 ) ;
m_dialog - > WriteGamerInfo ( ) ;
}
}
2012-09-15 13:33:08 +00:00
if ( phase = = PHASE_WIN ) // wins a simulation?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int rank = m_dialog - > GetSceneRank ( ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetGamerInfoPassed ( rank , true ) ;
m_dialog - > NextMission ( ) ; // passes to the next mission
m_dialog - > WriteGamerInfo ( ) ;
}
2012-09-20 18:37:37 +00:00
m_app - > SetLowCPU ( true ) ; // doesn't use much CPU in interface phases
2012-06-26 20:23:05 +00:00
DeleteAllObjects ( ) ; // removes all the current 3D Scene
m_phase = phase ;
m_winDelay = 0.0f ;
m_lostDelay = 0.0f ;
2012-09-15 13:33:08 +00:00
m_beginSatCom = false ;
m_movieLock = false ;
m_satComLock = false ;
m_editLock = false ;
m_freePhoto = false ;
m_resetCreate = false ;
m_engine - > SetMovieLock ( m_movieLock ) ;
2012-06-26 20:23:05 +00:00
ChangePause ( false ) ;
FlushDisplayInfo ( ) ;
m_engine - > SetRankView ( 0 ) ;
2013-10-13 12:44:12 +00:00
m_terrain - > FlushRelief ( ) ;
2012-12-26 19:58:02 +00:00
m_engine - > DeleteAllObjects ( ) ;
2013-03-31 11:06:38 +00:00
Gfx : : CModelManager : : GetInstancePointer ( ) - > DeleteAllModelCopies ( ) ;
2012-09-15 13:33:08 +00:00
m_engine - > SetWaterAddColor ( Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ;
2012-06-26 20:23:05 +00:00
m_engine - > SetBackground ( " " ) ;
m_engine - > SetBackForce ( false ) ;
2012-09-15 13:33:08 +00:00
m_engine - > SetForegroundName ( " " ) ;
2012-06-26 20:23:05 +00:00
m_engine - > SetOverColor ( ) ;
2012-09-15 13:33:08 +00:00
m_engine - > DeleteGroundMark ( 0 ) ;
2012-06-26 20:23:05 +00:00
SetSpeed ( 1.0f ) ;
m_terrain - > SetWind ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_terrain - > FlushBuildingLevel ( ) ;
m_terrain - > FlushFlyingLimit ( ) ;
2012-09-15 13:33:08 +00:00
m_lightMan - > FlushLights ( ) ;
m_particle - > FlushParticle ( ) ;
2012-06-26 20:23:05 +00:00
m_water - > Flush ( ) ;
m_cloud - > Flush ( ) ;
2012-09-15 13:33:08 +00:00
m_lightning - > Flush ( ) ;
2012-06-26 20:23:05 +00:00
m_planet - > Flush ( ) ;
m_interface - > Flush ( ) ;
ClearInterface ( ) ;
FlushNewScriptName ( ) ;
m_sound - > SetListener ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) , Math : : Vector ( 0.0f , 0.0f , 1.0f ) ) ;
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_DIALOG ) ;
2012-06-26 20:23:05 +00:00
m_movie - > Flush ( ) ;
m_movieInfoIndex = - 1 ;
m_cameraPan = 0.0f ;
m_cameraZoom = 0.0f ;
2012-09-15 13:33:08 +00:00
m_shortCut = true ;
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
iMan - > Flush ( CLASS_OBJECT ) ;
iMan - > Flush ( CLASS_PHYSICS ) ;
iMan - > Flush ( CLASS_BRAIN ) ;
iMan - > Flush ( CLASS_PYRO ) ;
2012-09-15 13:33:08 +00:00
Math : : Point dim , pos ;
2012-06-26 20:23:05 +00:00
// Creates and hide the command console.
dim . x = 200.0f / 640.0f ;
dim . y = 18.0f / 480.0f ;
pos . x = 50.0f / 640.0f ;
pos . y = 452.0f / 480.0f ;
2012-10-17 19:48:40 +00:00
Ui : : CEdit * pe = static_cast < Ui : : CEdit * > ( m_interface - > CreateEdit ( pos , dim , 0 , EVENT_CMD ) ) ;
2012-09-15 13:33:08 +00:00
if ( pe = = nullptr ) return ;
pe - > ClearState ( Ui : : STATE_VISIBLE ) ;
m_cmdEdit = false ; // hidden for now
2012-06-26 20:23:05 +00:00
// Creates the speedometer.
2012-09-15 13:33:08 +00:00
/* TODO: #if _TEEN
2012-06-26 20:23:05 +00:00
dim . x = 30.0f / 640.0f ;
dim . y = 20.0f / 480.0f ;
pos . x = 4.0f / 640.0f ;
pos . y = 454.0f / 480.0f ;
2012-09-15 13:33:08 +00:00
# else* /
2012-06-26 20:23:05 +00:00
dim . x = 30.0f / 640.0f ;
dim . y = 20.0f / 480.0f ;
pos . x = 4.0f / 640.0f ;
pos . y = 426.0f / 480.0f ;
2012-09-15 13:33:08 +00:00
Ui : : CButton * pb = m_interface - > CreateButton ( pos , dim , 0 , EVENT_SPEED ) ;
if ( pb = = nullptr ) return ;
pb - > SetState ( Ui : : STATE_SIMPLY ) ;
pb - > ClearState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > ChangePhase ( m_phase ) ;
dim . x = 32.0f / 640.0f ;
dim . y = 32.0f / 480.0f ;
2012-09-15 13:33:08 +00:00
float ox = 3.0f / 640.0f ;
float oy = 3.0f / 480.0f ;
float sx = ( 32.0f + 2.0f ) / 640.0f ;
float sy = ( 32.0f + 2.0f ) / 480.0f ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( m_phase ! = PHASE_PERSO )
2012-06-26 20:23:05 +00:00
{
m_engine - > SetDrawWorld ( true ) ;
m_engine - > SetDrawFront ( false ) ;
2012-09-15 13:33:08 +00:00
m_fixScene = false ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_INIT )
2012-06-26 20:23:05 +00:00
{
2012-09-20 18:37:37 +00:00
m_engine - > DeleteTexture ( " generic.png " ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
{
2012-09-20 18:37:37 +00:00
m_engine - > DeleteTexture ( " interface.png " ) ;
m_app - > SetLowCPU ( false ) ; // high CPU for simulation
2012-06-26 20:23:05 +00:00
2012-09-26 20:57:43 +00:00
bool loading = ( m_dialog - > GetSceneRead ( ) [ 0 ] ! = 0 ) ;
2012-06-26 20:23:05 +00:00
m_map - > CreateMap ( ) ;
2012-09-15 13:33:08 +00:00
CreateScene ( m_dialog - > GetSceneSoluce ( ) , false , false ) ; // interactive scene
if ( m_mapImage )
2012-06-26 20:23:05 +00:00
m_map - > SetFixImage ( m_mapFilename ) ;
2012-09-15 13:33:08 +00:00
2013-06-13 15:25:58 +00:00
m_app - > ResetTimeAfterLoading ( ) ;
2013-03-27 19:38:36 +00:00
/*Math::Point ddim;
2012-06-26 20:23:05 +00:00
pos . x = 620.0f / 640.0f ;
pos . y = 460.0f / 480.0f ;
ddim . x = 20.0f / 640.0f ;
ddim . y = 20.0f / 480.0f ;
2013-03-27 19:38:36 +00:00
m_interface - > CreateButton ( pos , ddim , 11 , EVENT_BUTTON_QUIT ) ; */
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( m_immediatSatCom & & ! loading & &
m_infoFilename [ SATCOM_HUSTON ] [ 0 ] ! = 0 )
2012-06-26 20:23:05 +00:00
StartDisplayInfo ( SATCOM_HUSTON , false ) ; // shows the instructions
2013-12-28 11:30:46 +00:00
m_sound - > StopMusic ( 0.0f ) ;
2012-09-15 13:33:08 +00:00
if ( ! m_base | | loading ) StartMusic ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_WIN )
2012-06-26 20:23:05 +00:00
{
2013-03-14 20:30:32 +00:00
m_sound - > StopAll ( ) ;
2012-09-15 13:33:08 +00:00
if ( m_endingWinRank = = - 1 )
2012-06-26 20:23:05 +00:00
{
ChangePhase ( PHASE_TERM ) ;
}
else
{
2012-09-15 13:33:08 +00:00
/* TODO: #if _TEEN
m_winTerminate = ( m_endingWinRank = = 900 ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetSceneName ( " teenw " ) ;
2012-09-15 13:33:08 +00:00
# else* /
m_winTerminate = ( m_endingWinRank = = 904 ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetSceneName ( " win " ) ;
2012-09-15 13:33:08 +00:00
2012-06-26 20:23:05 +00:00
m_dialog - > SetSceneRank ( m_endingWinRank ) ;
CreateScene ( false , true , false ) ; // sets scene
pos . x = ox + sx * 1 ; pos . y = oy + sy * 1 ;
2012-09-15 13:33:08 +00:00
Math : : Point ddim ;
2012-06-26 20:23:05 +00:00
ddim . x = dim . x * 2 ; ddim . y = dim . y * 2 ;
m_interface - > CreateButton ( pos , ddim , 16 , EVENT_BUTTON_OK ) ;
2012-09-15 13:33:08 +00:00
if ( m_winTerminate )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
/* TODO: #if _TEEN
2012-06-26 20:23:05 +00:00
pos . x = ox + sx * 3 ; pos . y = oy + sy * 1 ;
ddim . x = dim . x * 15 ; ddim . y = dim . y * 2 ;
pe = m_interface - > CreateEdit ( pos , ddim , 0 , EVENT_EDIT0 ) ;
pe - > SetFontType ( FONT_COLOBOT ) ;
pe - > SetEditCap ( false ) ;
pe - > SetHiliteCap ( false ) ;
2012-09-22 12:40:13 +00:00
pe - > ReadText ( " help/teenw.txt " ) ;
2012-09-15 13:33:08 +00:00
# else* /
2012-06-26 20:23:05 +00:00
pos . x = ox + sx * 3 ; pos . y = oy + sy * 0.2f ;
ddim . x = dim . x * 15 ; ddim . y = dim . y * 3.0f ;
pe = m_interface - > CreateEdit ( pos , ddim , 0 , EVENT_EDIT0 ) ;
pe - > SetGenericMode ( true ) ;
2012-09-15 13:33:08 +00:00
pe - > SetFontType ( Gfx : : FONT_COLOBOT ) ;
2012-06-26 20:23:05 +00:00
pe - > SetEditCap ( false ) ;
2013-03-20 20:50:44 +00:00
pe - > SetHighlightCap ( false ) ;
2013-03-29 09:03:35 +00:00
pe - > ReadText ( std : : string ( " help/ " ) + m_app - > GetLanguageChar ( ) + std : : string ( " /win.txt " ) ) ;
2012-06-26 20:23:05 +00:00
}
else
{
m_displayText - > DisplayError ( INFO_WIN , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 15.0f , 60.0f , 1000.0f ) ;
}
2013-03-14 20:30:32 +00:00
StartMusic ( ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_LOST )
2012-06-26 20:23:05 +00:00
{
2013-03-14 20:30:32 +00:00
m_sound - > StopAll ( ) ;
2012-09-15 13:33:08 +00:00
if ( m_endingLostRank = = - 1 )
2012-06-26 20:23:05 +00:00
{
ChangePhase ( PHASE_TERM ) ;
}
else
{
2012-09-15 13:33:08 +00:00
m_winTerminate = false ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetSceneName ( " lost " ) ;
m_dialog - > SetSceneRank ( m_endingLostRank ) ;
CreateScene ( false , true , false ) ; // sets scene
pos . x = ox + sx * 1 ; pos . y = oy + sy * 1 ;
2012-09-15 13:33:08 +00:00
Math : : Point ddim ;
2012-06-26 20:23:05 +00:00
ddim . x = dim . x * 2 ; ddim . y = dim . y * 2 ;
m_interface - > CreateButton ( pos , ddim , 16 , EVENT_BUTTON_OK ) ;
m_displayText - > DisplayError ( INFO_LOST , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 15.0f , 60.0f , 1000.0f ) ;
2013-05-26 15:47:54 +00:00
2013-03-14 20:30:32 +00:00
StartMusic ( ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_LOADING )
2012-09-20 18:37:37 +00:00
m_app - > SetMouseMode ( MOUSE_NONE ) ;
2012-06-26 20:23:05 +00:00
else
2012-09-20 18:37:37 +00:00
m_app - > SetMouseMode ( MOUSE_ENGINE ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_engine - > LoadAllTextures ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Processes an event
2013-06-16 19:39:21 +00:00
bool CRobotMain : : ProcessEvent ( Event & event )
2012-06-26 20:23:05 +00:00
{
2012-09-19 19:23:42 +00:00
/* Motion vector management */
if ( event . type = = EVENT_KEY_DOWN )
{
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_UP ) . primary ) m_keyMotion . y = 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_UP ) . secondary ) m_keyMotion . y = 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_DOWN ) . primary ) m_keyMotion . y = - 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_DOWN ) . secondary ) m_keyMotion . y = - 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_LEFT ) . primary ) m_keyMotion . x = - 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_LEFT ) . secondary ) m_keyMotion . x = - 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . primary ) m_keyMotion . x = 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . secondary ) m_keyMotion . x = 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GUP ) . primary ) m_keyMotion . z = 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GUP ) . secondary ) m_keyMotion . z = 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GDOWN ) . primary ) m_keyMotion . z = - 1.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GDOWN ) . secondary ) m_keyMotion . z = - 1.0f ;
2012-09-19 19:23:42 +00:00
}
else if ( event . type = = EVENT_KEY_UP )
{
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_UP ) . primary ) m_keyMotion . y = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_UP ) . secondary ) m_keyMotion . y = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_DOWN ) . primary ) m_keyMotion . y = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_DOWN ) . secondary ) m_keyMotion . y = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_LEFT ) . primary ) m_keyMotion . x = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_LEFT ) . secondary ) m_keyMotion . x = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . primary ) m_keyMotion . x = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . secondary ) m_keyMotion . x = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GUP ) . primary ) m_keyMotion . z = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GUP ) . secondary ) m_keyMotion . z = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GDOWN ) . primary ) m_keyMotion . z = 0.0f ;
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_GDOWN ) . secondary ) m_keyMotion . z = 0.0f ;
2012-09-19 19:23:42 +00:00
}
else if ( event . type = = EVENT_JOY_AXIS )
{
if ( event . joyAxis . axis = = GetJoyAxisBinding ( JOY_AXIS_SLOT_X ) . axis )
{
m_joyMotion . x = Math : : Neutral ( event . joyAxis . value / 32768.0f , m_joystickDeadzone ) ;
if ( GetJoyAxisBinding ( JOY_AXIS_SLOT_X ) . invert )
m_joyMotion . x * = - 1.0f ;
}
if ( event . joyAxis . axis = = GetJoyAxisBinding ( JOY_AXIS_SLOT_Y ) . axis )
{
m_joyMotion . y = Math : : Neutral ( event . joyAxis . value / 32768.0f , m_joystickDeadzone ) ;
if ( GetJoyAxisBinding ( JOY_AXIS_SLOT_Y ) . invert )
m_joyMotion . y * = - 1.0f ;
}
if ( event . joyAxis . axis = = GetJoyAxisBinding ( JOY_AXIS_SLOT_Z ) . axis )
{
m_joyMotion . z = Math : : Neutral ( event . joyAxis . value / 32768.0f , m_joystickDeadzone ) ;
if ( GetJoyAxisBinding ( JOY_AXIS_SLOT_Z ) . invert )
m_joyMotion . z * = - 1.0f ;
}
}
event . motionInput = Math : : Clamp ( m_joyMotion + m_keyMotion , Math : : Vector ( - 1.0f , - 1.0f , - 1.0f ) , Math : : Vector ( 1.0f , 1.0f , 1.0f ) ) ;
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_FRAME )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! m_movie - > EventProcess ( event ) ) // end of the movie?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
MainMovieType type = m_movie - > GetStopType ( ) ;
if ( type = = MM_SATCOMopen )
2012-06-26 20:23:05 +00:00
{
ChangePause ( false ) ;
SelectObject ( m_infoObject , false ) ; // hands over the command buttons
2012-09-15 13:33:08 +00:00
m_map - > ShowMap ( m_mapShow ) ;
2012-06-26 20:23:05 +00:00
m_displayText - > HideText ( false ) ;
2012-09-15 13:33:08 +00:00
int i = m_movieInfoIndex ;
2012-06-26 20:23:05 +00:00
StartDisplayInfo ( m_movieInfoIndex , false ) ;
m_movieInfoIndex = i ;
}
}
m_dialog - > EventProcess ( event ) ;
m_displayText - > EventProcess ( event ) ;
RemoteCamera ( m_cameraPan , m_cameraZoom , event . rTime ) ;
m_interface - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
if ( m_displayInfo ! = nullptr ) // current edition?
2012-06-26 20:23:05 +00:00
m_displayInfo - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
2012-06-26 20:23:05 +00:00
return EventFrame ( event ) ;
}
// Management of the console.
2012-09-15 13:33:08 +00:00
if ( m_phase ! = PHASE_NAME & &
! m_movie - > IsExist ( ) & &
2013-03-30 15:03:25 +00:00
! m_movieLock & & ! m_editLock & & ! m_engine - > GetPause ( ) & &
2012-09-15 13:33:08 +00:00
event . type = = EVENT_KEY_DOWN & &
event . key . key = = KEY ( PAUSE ) ) // Pause ?
{
2012-10-17 19:48:40 +00:00
Ui : : CEdit * pe = static_cast < Ui : : CEdit * > ( m_interface - > SearchControl ( EVENT_CMD ) ) ;
2012-09-15 13:33:08 +00:00
if ( pe = = nullptr ) return false ;
pe - > SetState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
pe - > SetFocus ( true ) ;
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL ) ChangePause ( true ) ;
m_cmdEdit = true ;
2012-06-26 20:23:05 +00:00
return false ;
}
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_KEY_DOWN & &
event . key . key = = KEY ( RETURN ) & & m_cmdEdit )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char cmd [ 50 ] ;
2012-10-17 19:48:40 +00:00
Ui : : CEdit * pe = static_cast < Ui : : CEdit * > ( m_interface - > SearchControl ( EVENT_CMD ) ) ;
2012-09-15 13:33:08 +00:00
if ( pe = = nullptr ) return false ;
2012-06-26 20:23:05 +00:00
pe - > GetText ( cmd , 50 ) ;
pe - > SetText ( " " ) ;
2012-09-15 13:33:08 +00:00
pe - > ClearState ( Ui : : STATE_VISIBLE ) ;
if ( m_phase = = PHASE_SIMUL ) ChangePause ( false ) ;
2012-06-26 20:23:05 +00:00
ExecuteCmd ( cmd ) ;
2012-09-15 13:33:08 +00:00
m_cmdEdit = false ;
2012-06-26 20:23:05 +00:00
return false ;
}
// Management of the speed change.
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_SPEED )
2012-06-26 20:23:05 +00:00
SetSpeed ( 1.0f ) ;
2012-09-15 13:33:08 +00:00
if ( ! m_dialog - > EventProcess ( event ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_MOUSE_MOVE )
2012-06-26 20:23:05 +00:00
{
2012-09-21 22:38:17 +00:00
m_lastMousePos = event . mousePos ;
HiliteObject ( event . mousePos ) ;
2012-06-26 20:23:05 +00:00
}
return false ;
}
2012-09-15 13:33:08 +00:00
if ( ! m_displayText - > EventProcess ( event ) )
2012-06-26 20:23:05 +00:00
return false ;
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_MOUSE_MOVE )
2012-06-26 20:23:05 +00:00
{
2012-09-21 22:38:17 +00:00
m_lastMousePos = event . mousePos ;
HiliteObject ( event . mousePos ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_displayInfo ! = nullptr ) // current info?
2012-06-26 20:23:05 +00:00
{
m_displayInfo - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_KEY_DOWN )
2012-06-26 20:23:05 +00:00
{
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_HELP ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_HELP ) . secondary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_PROG ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_PROG ) . secondary | |
2012-09-15 13:33:08 +00:00
event . key . key = = KEY ( ESCAPE ) )
2012-06-26 20:23:05 +00:00
{
StopDisplayInfo ( ) ;
}
}
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_OBJECT_INFOOK )
2012-06-26 20:23:05 +00:00
StopDisplayInfo ( ) ;
2012-09-15 13:33:08 +00:00
2012-06-26 20:23:05 +00:00
return false ;
}
2012-09-15 13:33:08 +00:00
CObject * obj ;
2012-06-26 20:23:05 +00:00
// Simulation phase of the game
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
{
UpdateInfoText ( ) ;
2012-09-15 13:33:08 +00:00
if ( ! m_editFull )
2012-06-26 20:23:05 +00:00
m_camera - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
switch ( event . type )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
case EVENT_KEY_DOWN :
KeyCamera ( event . type , event . key . key ) ;
2012-06-26 20:23:05 +00:00
HiliteClear ( ) ;
2012-09-15 13:33:08 +00:00
if ( event . key . key = = KEY ( F11 ) )
2012-06-26 20:23:05 +00:00
{
2012-09-22 12:40:13 +00:00
m_particle - > WriteWheelTrace ( " Savegame/t.png " , 256 , 256 , Math : : Vector ( 16.0f , 0.0f , - 368.0f ) , Math : : Vector ( 140.0f , 0.0f , - 248.0f ) ) ;
2012-06-26 20:23:05 +00:00
return false ;
}
2012-09-15 13:33:08 +00:00
if ( m_editLock ) // current edition?
2012-06-26 20:23:05 +00:00
{
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_HELP ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_HELP ) . secondary )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_HUSTON , false ) ;
return false ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_PROG ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_PROG ) . secondary )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_PROG , false ) ;
return false ;
}
break ;
}
2012-09-15 13:33:08 +00:00
if ( m_movieLock ) // current movie?
2012-06-26 20:23:05 +00:00
{
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_QUIT ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_QUIT ) . secondary | |
2012-09-15 13:33:08 +00:00
event . key . key = = KEY ( ESCAPE ) )
2012-06-26 20:23:05 +00:00
{
AbortMovie ( ) ;
}
return false ;
}
2012-09-15 13:33:08 +00:00
if ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_VISIT )
2012-06-26 20:23:05 +00:00
{
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_VISIT ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_VISIT ) . secondary )
2012-06-26 20:23:05 +00:00
{
StartDisplayVisit ( EVENT_NULL ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_QUIT ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_QUIT ) . secondary | |
2012-09-15 13:33:08 +00:00
event . key . key = = KEY ( ESCAPE ) )
2012-06-26 20:23:05 +00:00
{
StopDisplayVisit ( ) ;
}
return false ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_QUIT ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_QUIT ) . secondary )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_movie - > IsExist ( ) )
2012-06-26 20:23:05 +00:00
StartDisplayInfo ( SATCOM_HUSTON , false ) ;
2012-09-15 13:33:08 +00:00
else if ( m_winDelay > 0.0f )
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_WIN ) ;
2012-09-15 13:33:08 +00:00
else if ( m_lostDelay > 0.0f )
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_LOST ) ;
2013-05-26 15:47:54 +00:00
else if ( ! m_cmdEdit )
2012-06-26 20:23:05 +00:00
m_dialog - > StartAbort ( ) ; // do you want to leave?
}
2012-09-15 13:33:08 +00:00
if ( event . key . key = = KEY ( PAUSE ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! m_movieLock & & ! m_editLock & & ! m_cmdEdit & &
m_camera - > GetType ( ) ! = Gfx : : CAM_TYPE_VISIT & &
! m_movie - > IsExist ( ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
ChangePause ( ! m_engine - > GetPause ( ) ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_CAMERA ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_CAMERA ) . secondary )
2012-06-26 20:23:05 +00:00
{
ChangeCamera ( ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_DESEL ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_DESEL ) . secondary )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_shortCut )
2012-06-26 20:23:05 +00:00
DeselectObject ( ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_HUMAN ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_HUMAN ) . secondary )
2012-06-26 20:23:05 +00:00
{
SelectHuman ( ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_NEXT ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_NEXT ) . secondary )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_shortCut )
2012-06-26 20:23:05 +00:00
m_short - > SelectNext ( ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_HELP ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_HELP ) . secondary )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_HUSTON , true ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_PROG ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_PROG ) . secondary )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_PROG , true ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_VISIT ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_VISIT ) . secondary )
2012-06-26 20:23:05 +00:00
{
StartDisplayVisit ( EVENT_NULL ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_SPEED10 ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_SPEED10 ) . secondary )
2012-06-26 20:23:05 +00:00
{
SetSpeed ( 1.0f ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_SPEED15 ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_SPEED15 ) . secondary )
2012-06-26 20:23:05 +00:00
{
SetSpeed ( 1.5f ) ;
}
2012-10-06 22:46:46 +00:00
if ( event . key . key = = GetInputBinding ( INPUT_SLOT_SPEED20 ) . primary | |
event . key . key = = GetInputBinding ( INPUT_SLOT_SPEED20 ) . secondary )
2012-06-26 20:23:05 +00:00
{
SetSpeed ( 2.0f ) ;
}
break ;
2012-09-15 13:33:08 +00:00
case EVENT_KEY_UP :
KeyCamera ( event . type , event . key . key ) ;
2012-06-26 20:23:05 +00:00
break ;
2012-09-15 13:33:08 +00:00
case EVENT_MOUSE_BUTTON_DOWN :
2012-09-29 17:29:51 +00:00
if ( event . mouseButton . button ! = MOUSE_BUTTON_LEFT ) // only left mouse button
2012-09-15 13:33:08 +00:00
break ;
2012-09-21 22:38:17 +00:00
obj = DetectObject ( event . mousePos ) ;
2012-09-15 13:33:08 +00:00
if ( ! m_shortCut ) obj = nullptr ;
if ( obj ! = nullptr & & obj - > GetType ( ) = = OBJECT_TOTO )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_displayInfo ! = nullptr ) // current info?
2012-06-26 20:23:05 +00:00
{
StopDisplayInfo ( ) ;
}
else
{
2012-09-15 13:33:08 +00:00
if ( ! m_editLock )
2012-06-26 20:23:05 +00:00
StartDisplayInfo ( SATCOM_HUSTON , true ) ;
}
}
else
2012-09-15 13:33:08 +00:00
SelectObject ( obj ) ;
2012-06-26 20:23:05 +00:00
break ;
2012-09-15 13:33:08 +00:00
case EVENT_MOUSE_BUTTON_UP :
2012-09-29 17:29:51 +00:00
if ( event . mouseButton . button ! = MOUSE_BUTTON_LEFT ) // only left mouse button
2012-09-15 13:33:08 +00:00
break ;
2012-06-26 20:23:05 +00:00
m_cameraPan = 0.0f ;
m_cameraZoom = 0.0f ;
break ;
case EVENT_BUTTON_QUIT :
2012-09-15 13:33:08 +00:00
if ( m_movie - > IsExist ( ) )
2012-06-26 20:23:05 +00:00
StartDisplayInfo ( SATCOM_HUSTON , false ) ;
2012-09-15 13:33:08 +00:00
else if ( m_winDelay > 0.0f )
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_WIN ) ;
2012-09-15 13:33:08 +00:00
else if ( m_lostDelay > 0.0f )
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_LOST ) ;
else
m_dialog - > StartAbort ( ) ; // do you want to leave?
break ;
case EVENT_OBJECT_LIMIT :
StartShowLimit ( ) ;
break ;
case EVENT_OBJECT_DESELECT :
2012-09-15 13:33:08 +00:00
if ( m_shortCut )
2012-06-26 20:23:05 +00:00
DeselectObject ( ) ;
break ;
case EVENT_OBJECT_HELP :
HelpObject ( ) ;
break ;
case EVENT_OBJECT_CAMERA :
ChangeCamera ( ) ;
break ;
case EVENT_OBJECT_CAMERAleft :
m_cameraPan = - 1.0f ;
break ;
case EVENT_OBJECT_CAMERAright :
m_cameraPan = 1.0f ;
break ;
case EVENT_OBJECT_CAMERAnear :
m_cameraZoom = - 1.0f ;
break ;
case EVENT_OBJECT_CAMERAaway :
m_cameraZoom = 1.0f ;
break ;
case EVENT_OBJECT_DELETE :
m_dialog - > StartDeleteObject ( ) ; // do you want to destroy it?
break ;
case EVENT_OBJECT_BHELP :
StartDisplayInfo ( SATCOM_HUSTON , true ) ;
break ;
case EVENT_OBJECT_SOLUCE :
StartDisplayInfo ( SATCOM_SOLUCE , true ) ;
break ;
case EVENT_OBJECT_MAPZOOM :
m_map - > ZoomMap ( ) ;
break ;
case EVENT_DT_VISIT0 :
case EVENT_DT_VISIT1 :
case EVENT_DT_VISIT2 :
case EVENT_DT_VISIT3 :
case EVENT_DT_VISIT4 :
2012-09-15 13:33:08 +00:00
StartDisplayVisit ( event . type ) ;
2012-06-26 20:23:05 +00:00
break ;
case EVENT_DT_END :
StopDisplayVisit ( ) ;
break ;
case EVENT_OBJECT_SHORTCUT00 :
case EVENT_OBJECT_SHORTCUT01 :
case EVENT_OBJECT_SHORTCUT02 :
case EVENT_OBJECT_SHORTCUT03 :
case EVENT_OBJECT_SHORTCUT04 :
case EVENT_OBJECT_SHORTCUT05 :
case EVENT_OBJECT_SHORTCUT06 :
case EVENT_OBJECT_SHORTCUT07 :
case EVENT_OBJECT_SHORTCUT08 :
case EVENT_OBJECT_SHORTCUT09 :
case EVENT_OBJECT_SHORTCUT10 :
case EVENT_OBJECT_SHORTCUT11 :
case EVENT_OBJECT_SHORTCUT12 :
case EVENT_OBJECT_SHORTCUT13 :
case EVENT_OBJECT_SHORTCUT14 :
case EVENT_OBJECT_SHORTCUT15 :
case EVENT_OBJECT_SHORTCUT16 :
case EVENT_OBJECT_SHORTCUT17 :
case EVENT_OBJECT_SHORTCUT18 :
case EVENT_OBJECT_SHORTCUT19 :
2012-09-15 13:33:08 +00:00
m_short - > SelectShortcut ( event . type ) ;
2012-06-26 20:23:05 +00:00
break ;
case EVENT_OBJECT_MOVIELOCK :
AbortMovie ( ) ;
break ;
case EVENT_WIN :
ChangePhase ( PHASE_WIN ) ;
2013-12-26 20:54:05 +00:00
if ( m_exitAfterMission )
m_eventQueue - > AddEvent ( Event ( EVENT_QUIT ) ) ;
2012-06-26 20:23:05 +00:00
break ;
case EVENT_LOST :
ChangePhase ( PHASE_LOST ) ;
2013-12-26 20:54:05 +00:00
if ( m_exitAfterMission )
m_eventQueue - > AddEvent ( Event ( EVENT_QUIT ) ) ;
2012-06-26 20:23:05 +00:00
break ;
2012-09-15 13:33:08 +00:00
default :
break ;
2012-06-26 20:23:05 +00:00
}
EventObject ( event ) ;
return false ;
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_PERSO )
2012-06-26 20:23:05 +00:00
EventObject ( event ) ;
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_WIN | |
m_phase = = PHASE_LOST )
2012-06-26 20:23:05 +00:00
{
EventObject ( event ) ;
2012-09-15 13:33:08 +00:00
switch ( event . type )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
case EVENT_KEY_DOWN :
if ( event . key . key = = KEY ( ESCAPE ) | |
event . key . key = = KEY ( RETURN ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_winTerminate )
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_INIT ) ;
else
ChangePhase ( PHASE_TERM ) ;
}
break ;
case EVENT_BUTTON_OK :
2012-09-15 13:33:08 +00:00
if ( m_winTerminate )
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_INIT ) ;
else
ChangePhase ( PHASE_TERM ) ;
2013-12-26 20:54:05 +00:00
2012-06-26 20:23:05 +00:00
break ;
2012-09-15 13:33:08 +00:00
default :
2012-06-26 20:23:05 +00:00
break ;
}
}
return true ;
}
2012-09-15 13:33:08 +00:00
//! Executes a command
2012-06-26 20:23:05 +00:00
void CRobotMain : : ExecuteCmd ( char * cmd )
{
2012-09-15 13:33:08 +00:00
if ( cmd [ 0 ] = = 0 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " winmission " ) = = 0 )
m_eventQueue - > AddEvent ( Event ( EVENT_WIN ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " lostmission " ) = = 0 )
m_eventQueue - > AddEvent ( Event ( EVENT_LOST ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " trainerpilot " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_trainerPilot = ! m_trainerPilot ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " fly " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
g_researchDone | = RESEARCH_FLY ;
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " allresearch " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
g_researchDone = - 1 ; // all research are done
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2013-04-12 20:52:32 +00:00
if ( strcmp ( cmd , " allbuildings " ) = = 0 )
{
g_build = - 1 ; // all buildings are available
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
return ;
}
if ( strcmp ( cmd , " all " ) = = 0 )
{
g_researchDone = - 1 ; // all research are done
g_build = - 1 ; // all buildings are available
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " nolimit " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
m_terrain - > SetFlyingMaxHeight ( 280.0f ) ;
return ;
}
2013-04-29 15:26:32 +00:00
if ( strcmp ( cmd , " controller " ) = = 0 )
{
2013-05-26 15:47:54 +00:00
if ( m_controller ! = nullptr )
{
2013-04-29 15:26:32 +00:00
// Don't use SelectObject because it checks if the object is selectable
if ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_VISIT )
StopDisplayVisit ( ) ;
CObject * prev = DeselectAll ( ) ;
if ( prev ! = nullptr & & prev ! = m_controller )
m_controller - > AddDeselList ( prev ) ;
SelectOneObject ( m_controller , true ) ;
m_short - > UpdateShortcuts ( ) ;
}
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " photo1 " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_freePhoto = ! m_freePhoto ;
if ( m_freePhoto )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_FREE ) ;
2012-06-26 20:23:05 +00:00
ChangePause ( true ) ;
}
else
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_BACK ) ;
2012-06-26 20:23:05 +00:00
ChangePause ( false ) ;
}
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " photo2 " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_freePhoto = ! m_freePhoto ;
if ( m_freePhoto )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_FREE ) ;
2012-06-26 20:23:05 +00:00
ChangePause ( true ) ;
DeselectAll ( ) ; // removes the control buttons
m_map - > ShowMap ( false ) ;
m_displayText - > HideText ( true ) ;
}
else
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_BACK ) ;
2012-06-26 20:23:05 +00:00
ChangePause ( false ) ;
2012-09-15 13:33:08 +00:00
m_map - > ShowMap ( m_mapShow ) ;
2012-06-26 20:23:05 +00:00
m_displayText - > HideText ( false ) ;
}
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " noclip " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
object - > SetClip ( false ) ;
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " clip " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
object - > SetClip ( true ) ;
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " addhusky " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
object - > SetMagnifyDamage ( object - > GetMagnifyDamage ( ) * 0.1f ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " addfreezer " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
object - > SetRange ( object - > GetRange ( ) * 10.0f ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2013-05-26 15:47:54 +00:00
2012-09-29 23:51:37 +00:00
if ( strcmp ( cmd , " \155 \157 \157 " ) = = 0 )
{
// VGhpcyBpcyBlYXN0ZXItZWdnIGFuZCBzbyBpdCBzaG91bGQgYmUgb2JmdXNjYXRlZCEgRG8gbm90
// IGNsZWFuLXVwIHRoaXMgY29kZSEK
GetLogger ( ) - > Info ( " _________________________ \n " ) ;
GetLogger ( ) - > Info ( " < \x50 \x6F \x6C \x73 \x6B \x69 \x50 \x6F \x72 \x74 \x61 \x6C C \x6F \x6C \x6F \x62 \x6F \x74 \x61 ! \x3E \n " ) ;
GetLogger ( ) - > Info ( " ------------------------- \n " ) ;
GetLogger ( ) - > Info ( " \x5C \x20 \x20 \x20 \x5E \x5F \x5F \x5E \n " ) ;
GetLogger ( ) - > Info ( " \x20 \x5C \x20 \x20 \x28 \x6F \x6F \x29 \x5C \x5F \x5F \x5F \x5F \x5F \x5F \x5F \n " ) ;
GetLogger ( ) - > Info ( " \x28 \x5F \x5F \x29 \x5C \x20 \x20 \x20 \x20 \x29 \x5C \x2F \x5C \n " ) ;
GetLogger ( ) - > Info ( " \x20 \x20 \x20 \x20 \x7C | \x2D \x2D \x2D \x2D \x77 \x20 \x7C \n " ) ;
GetLogger ( ) - > Info ( " \x20 \x20 \x7C \x7C \x20 \x20 \x20 \x20 || \n " ) ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " fullpower " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * power = object - > GetPower ( ) ;
if ( power ! = nullptr )
2012-06-26 20:23:05 +00:00
power - > SetEnergy ( 1.0f ) ;
2012-09-15 13:33:08 +00:00
2012-06-26 20:23:05 +00:00
object - > SetShield ( 1.0f ) ;
2012-09-15 13:33:08 +00:00
CPhysics * physics = object - > GetPhysics ( ) ;
if ( physics ! = nullptr )
2012-06-26 20:23:05 +00:00
physics - > SetReactorRange ( 1.0f ) ;
}
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " fullenergy " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * power = object - > GetPower ( ) ;
if ( power ! = nullptr )
2012-06-26 20:23:05 +00:00
power - > SetEnergy ( 1.0f ) ;
}
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " fullshield " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
object - > SetShield ( 1.0f ) ;
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " fullrange " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CPhysics * physics = object - > GetPhysics ( ) ;
if ( physics ! = nullptr )
2012-06-26 20:23:05 +00:00
physics - > SetReactorRange ( 1.0f ) ;
}
return ;
}
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " debugmode " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2013-06-16 19:39:21 +00:00
if ( m_app - > IsDebugModeActive ( DEBUG_ALL ) )
{
m_app - > SetDebugModeActive ( DEBUG_ALL , false ) ;
}
else
{
m_app - > SetDebugModeActive ( DEBUG_ALL , true ) ;
}
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " showstat " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetShowStats ( ! m_engine - > GetShowStats ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invshadow " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetShadow ( ! m_engine - > GetShadow ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invdirty " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetDirty ( ! m_engine - > GetDirty ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invfog " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetFog ( ! m_engine - > GetFog ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invlens " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetLensMode ( ! m_engine - > GetLensMode ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invwater " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetWaterMode ( ! m_engine - > GetWaterMode ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invsky " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetSkyMode ( ! m_engine - > GetSkyMode ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invplanet " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetPlanetMode ( ! m_engine - > GetPlanetMode ( ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " showpos " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_showPos = ! m_showPos ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " selectinsect " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_selectInsect = ! m_selectInsect ;
2012-06-26 20:23:05 +00:00
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " showsoluce " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_showSoluce = ! m_showSoluce ;
2012-06-26 20:23:05 +00:00
m_dialog - > ShowSoluceUpdate ( ) ;
return ;
}
2012-09-15 13:33:08 +00:00
/* TODO: #if _TEEN
if ( strcmp ( cmd , " allteens " ) = = 0 )
# else* /
if ( strcmp ( cmd , " allmission " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_showAll = ! m_showAll ;
2012-06-26 20:23:05 +00:00
m_dialog - > AllMissionUpdate ( ) ;
return ;
}
2012-09-15 13:33:08 +00:00
if ( strcmp ( cmd , " invradar " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_cheatRadar = ! m_cheatRadar ;
2012-06-26 20:23:05 +00:00
return ;
}
2013-05-26 15:47:54 +00:00
if ( strcmp ( cmd , " speed4 " ) = = 0 )
{
2012-10-06 21:35:27 +00:00
SetSpeed ( 4.0f ) ;
UpdateSpeedLabel ( ) ;
2013-05-26 15:47:54 +00:00
return ;
2012-10-06 21:35:27 +00:00
}
2013-05-26 15:47:54 +00:00
if ( strcmp ( cmd , " speed8 " ) = = 0 )
{
2012-10-06 21:35:27 +00:00
SetSpeed ( 8.0f ) ;
UpdateSpeedLabel ( ) ;
2013-05-26 15:47:54 +00:00
return ;
2012-10-06 21:35:27 +00:00
}
2013-05-26 15:47:54 +00:00
if ( strcmp ( cmd , " crazy " ) = = 0 )
{
2013-04-12 20:52:32 +00:00
SetSpeed ( 1000.0f ) ;
UpdateSpeedLabel ( ) ;
2013-05-26 15:47:54 +00:00
return ;
2013-04-12 20:52:32 +00:00
}
2012-10-06 21:35:27 +00:00
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
m_displayText - > DisplayError ( ERR_CMD , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
}
2012-09-15 13:33:08 +00:00
//! Returns the type of current movie
MainMovieType CRobotMain : : GetMainMovie ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_movie - > GetType ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Clears the display of instructions
2012-06-26 20:23:05 +00:00
void CRobotMain : : FlushDisplayInfo ( )
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < SATCOM_MAX ; i + + )
2012-06-26 20:23:05 +00:00
{
m_infoFilename [ i ] [ 0 ] = 0 ;
m_infoPos [ i ] = 0 ;
}
2013-05-26 09:34:53 +00:00
strcpy ( m_infoFilename [ SATCOM_OBJECT ] , " objects.txt " ) ;
2012-06-26 20:23:05 +00:00
m_infoIndex = 0 ;
}
2012-09-15 13:33:08 +00:00
//! Beginning of the displaying of instructions.
//! index: SATCOM_*
void CRobotMain : : StartDisplayInfo ( int index , bool movie )
2012-06-26 20:23:05 +00:00
{
2013-03-27 21:20:50 +00:00
if ( m_cmdEdit | | m_satComLock | | m_lockedSatCom ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
bool human = obj ! = nullptr & & obj - > GetType ( ) = = OBJECT_HUMAN ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! m_editLock & & movie & & ! m_movie - > IsExist ( ) & & human )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CMotion * motion = obj - > GetMotion ( ) ;
if ( motion ! = nullptr & & motion - > GetAction ( ) = = - 1 )
2012-06-26 20:23:05 +00:00
{
m_movieInfoIndex = index ;
m_movie - > Start ( MM_SATCOMopen , 2.5f ) ;
ChangePause ( true ) ;
m_infoObject = DeselectAll ( ) ; // removes the control buttons
m_displayText - > HideText ( true ) ;
return ;
}
}
2012-09-15 13:33:08 +00:00
if ( m_movie - > IsExist ( ) )
2012-06-26 20:23:05 +00:00
{
m_movie - > Stop ( ) ;
ChangePause ( false ) ;
SelectObject ( m_infoObject , false ) ; // hands over the command buttons
m_displayText - > HideText ( false ) ;
}
StartDisplayInfo ( m_infoFilename [ index ] , index ) ;
}
2012-09-15 13:33:08 +00:00
//! Beginning of the displaying of instructions
2012-09-17 22:01:00 +00:00
void CRobotMain : : StartDisplayInfo ( const char * filename , int index )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_cmdEdit ) return ;
2012-06-26 20:23:05 +00:00
m_movieInfoIndex = - 1 ;
ClearInterface ( ) ; // removes setting evidence and tooltip
2012-09-15 13:33:08 +00:00
if ( ! m_editLock )
2012-06-26 20:23:05 +00:00
{
m_infoObject = DeselectAll ( ) ; // removes the control buttons
m_displayText - > HideText ( true ) ;
m_sound - > MuteAll ( true ) ;
}
2012-10-17 19:48:40 +00:00
Ui : : CButton * pb = static_cast < Ui : : CButton * > ( m_interface - > SearchControl ( EVENT_BUTTON_QUIT ) ) ;
2012-09-15 13:33:08 +00:00
if ( pb ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
pb - > ClearState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool soluce = m_dialog - > GetSceneSoluce ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_displayInfo = new Ui : : CDisplayInfo ( ) ;
m_displayInfo - > StartDisplayInfo ( filename , index , soluce ) ;
2012-06-26 20:23:05 +00:00
m_infoIndex = index ;
2012-09-15 13:33:08 +00:00
if ( index ! = - 1 )
2012-06-26 20:23:05 +00:00
m_displayInfo - > SetPosition ( m_infoPos [ index ] ) ;
}
2012-09-15 13:33:08 +00:00
//! End of displaying of instructions
2012-06-26 20:23:05 +00:00
void CRobotMain : : StopDisplayInfo ( )
{
2013-03-23 19:33:14 +00:00
if ( m_cmdEdit ) return ;
2013-05-26 15:47:54 +00:00
2012-09-15 13:33:08 +00:00
if ( m_movieInfoIndex ! = - 1 ) // film to read the SatCom?
2012-06-26 20:23:05 +00:00
m_movie - > Start ( MM_SATCOMclose , 2.0f ) ;
2012-09-15 13:33:08 +00:00
if ( m_infoIndex ! = - 1 )
m_infoPos [ m_infoIndex ] = m_displayInfo - > GetPosition ( ) ;
2012-06-26 20:23:05 +00:00
m_displayInfo - > StopDisplayInfo ( ) ;
delete m_displayInfo ;
2012-09-15 13:33:08 +00:00
m_displayInfo = nullptr ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! m_editLock )
2012-06-26 20:23:05 +00:00
{
2012-10-17 19:48:40 +00:00
Ui : : CButton * pb = static_cast < Ui : : CButton * > ( m_interface - > SearchControl ( EVENT_BUTTON_QUIT ) ) ;
2012-09-15 13:33:08 +00:00
if ( pb ! = nullptr )
pb - > SetState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
SelectObject ( m_infoObject , false ) ; // gives the command buttons
m_displayText - > HideText ( false ) ;
m_sound - > MuteAll ( false ) ;
}
2012-09-15 13:33:08 +00:00
if ( m_infoUsed = = 0 )
2012-06-26 20:23:05 +00:00
m_displayText - > ClearText ( ) ; // removes message "see SatCom ..."
m_infoUsed + + ;
}
2012-09-15 13:33:08 +00:00
//! Returns the name of the text display
char * CRobotMain : : GetDisplayInfoName ( int index )
2012-06-26 20:23:05 +00:00
{
return m_infoFilename [ index ] ;
}
2012-09-15 13:33:08 +00:00
//! Returns the name of the text display
int CRobotMain : : GetDisplayInfoPosition ( int index )
2012-06-26 20:23:05 +00:00
{
return m_infoPos [ index ] ;
}
2012-09-15 13:33:08 +00:00
//! Returns the name of the text display
2012-06-26 20:23:05 +00:00
void CRobotMain : : SetDisplayInfoPosition ( int index , int pos )
{
m_infoPos [ index ] = pos ;
}
2012-09-15 13:33:08 +00:00
//! Beginning of a dialogue during the game
2012-06-26 20:23:05 +00:00
void CRobotMain : : StartSuspend ( )
{
m_map - > ShowMap ( false ) ;
m_infoObject = DeselectAll ( ) ; // removes the control buttons
m_displayText - > HideText ( true ) ;
2012-10-17 19:48:40 +00:00
Ui : : CButton * pb = static_cast < Ui : : CButton * > ( m_interface - > SearchControl ( EVENT_BUTTON_QUIT ) ) ;
2012-09-15 13:33:08 +00:00
if ( pb ! = nullptr )
pb - > ClearState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_suspend = true ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! End of dialogue during the game
2012-06-26 20:23:05 +00:00
void CRobotMain : : StopSuspend ( )
{
2012-10-17 19:48:40 +00:00
Ui : : CButton * pb = static_cast < Ui : : CButton * > ( m_interface - > SearchControl ( EVENT_BUTTON_QUIT ) ) ;
2012-09-15 13:33:08 +00:00
if ( pb ! = nullptr )
pb - > SetState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
SelectObject ( m_infoObject , false ) ; // gives the command buttons
2012-09-15 13:33:08 +00:00
m_map - > ShowMap ( m_mapShow ) ;
2012-06-26 20:23:05 +00:00
m_displayText - > HideText ( false ) ;
2012-09-15 13:33:08 +00:00
m_suspend = false ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the absolute time of the game
float CRobotMain : : GetGameTime ( )
2012-06-26 20:23:05 +00:00
{
return m_gameTime ;
}
2012-09-15 13:33:08 +00:00
//! Managing the size of the default fonts
2012-06-26 20:23:05 +00:00
void CRobotMain : : SetFontSize ( float size )
{
m_fontSize = size ;
2013-05-01 19:02:43 +00:00
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " FontSize " , m_fontSize ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
float CRobotMain : : GetFontSize ( )
2012-06-26 20:23:05 +00:00
{
return m_fontSize ;
}
2012-09-15 13:33:08 +00:00
//! Managing the size of the default window
2012-06-26 20:23:05 +00:00
void CRobotMain : : SetWindowPos ( Math : : Point pos )
{
m_windowPos = pos ;
2013-05-03 19:39:02 +00:00
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowPosX " , m_windowPos . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowPosY " , m_windowPos . y ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
Math : : Point CRobotMain : : GetWindowPos ( )
2012-06-26 20:23:05 +00:00
{
return m_windowPos ;
}
void CRobotMain : : SetWindowDim ( Math : : Point dim )
{
m_windowDim = dim ;
2013-05-03 19:39:02 +00:00
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowDimX " , m_windowDim . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " WindowDimY " , m_windowDim . y ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
Math : : Point CRobotMain : : GetWindowDim ( )
2012-06-26 20:23:05 +00:00
{
return m_windowDim ;
}
2012-09-15 13:33:08 +00:00
//! Managing windows open/save
void CRobotMain : : SetIOPublic ( bool mode )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_IOPublic = mode ;
2013-05-01 19:02:43 +00:00
GetProfile ( ) . SetLocalProfileInt ( " Edit " , " IOPublic " , m_IOPublic ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetIOPublic ( )
2012-06-26 20:23:05 +00:00
{
return m_IOPublic ;
}
void CRobotMain : : SetIOPos ( Math : : Point pos )
{
m_IOPos = pos ;
2013-05-03 19:39:02 +00:00
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IOPosX " , m_IOPos . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IOPosY " , m_IOPos . y ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
Math : : Point CRobotMain : : GetIOPos ( )
2012-06-26 20:23:05 +00:00
{
return m_IOPos ;
}
void CRobotMain : : SetIODim ( Math : : Point dim )
{
m_IODim = dim ;
2013-05-03 19:39:02 +00:00
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IODimX " , m_IODim . x ) ;
GetProfile ( ) . SetLocalProfileFloat ( " Edit " , " IODimY " , m_IODim . y ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
Math : : Point CRobotMain : : GetIODim ( )
2012-06-26 20:23:05 +00:00
{
return m_IODim ;
}
2012-09-15 13:33:08 +00:00
//! Start of the visit instead of an error
void CRobotMain : : StartDisplayVisit ( EventType event )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_editLock ) return ;
2012-06-26 20:23:05 +00:00
2012-10-17 19:48:40 +00:00
Ui : : CWindow * pw = static_cast < Ui : : CWindow * > ( m_interface - > SearchControl ( EVENT_WINDOW2 ) ) ;
2012-09-15 13:33:08 +00:00
if ( pw = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( event = = EVENT_NULL ) // visit by keyboard shortcut?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int i ;
if ( m_visitLast ! = EVENT_NULL ) // already a current visit?
2012-06-26 20:23:05 +00:00
i = m_visitLast - EVENT_DT_VISIT0 ;
else
2012-09-15 13:33:08 +00:00
i = Ui : : MAXDTLINE ;
2012-06-26 20:23:05 +00:00
// Seeks the last.
2012-09-15 13:33:08 +00:00
for ( int j = 0 ; j < Ui : : MAXDTLINE ; j + + )
2012-06-26 20:23:05 +00:00
{
i - - ;
2012-09-15 13:33:08 +00:00
if ( i < 0 ) i = Ui : : MAXDTLINE - 1 ;
2012-06-26 20:23:05 +00:00
2012-10-17 19:48:40 +00:00
Ui : : CButton * button = static_cast < Ui : : CButton * > ( pw - > SearchControl ( static_cast < EventType > ( EVENT_DT_VISIT0 + i ) ) ) ;
2012-09-15 13:33:08 +00:00
if ( button = = nullptr | | ! button - > TestState ( Ui : : STATE_ENABLE ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-10-17 19:48:40 +00:00
Ui : : CGroup * group = static_cast < Ui : : CGroup * > ( pw - > SearchControl ( static_cast < EventType > ( EVENT_DT_GROUP0 + i ) ) ) ;
2012-09-15 13:33:08 +00:00
if ( group ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
event = static_cast < EventType > ( EVENT_DT_VISIT0 + i ) ;
2012-06-26 20:23:05 +00:00
break ;
}
}
}
2012-09-15 13:33:08 +00:00
if ( event = = EVENT_NULL )
2012-06-26 20:23:05 +00:00
{
m_sound - > Play ( SOUND_TZOING ) ; // nothing to do!
return ;
}
m_visitLast = event ;
ClearInterface ( ) ; // removes setting evidence and tooltip
2012-09-15 13:33:08 +00:00
if ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_VISIT ) // already a current visit?
2012-06-26 20:23:05 +00:00
{
m_camera - > StopVisit ( ) ;
m_displayText - > ClearVisit ( ) ;
}
else
{
m_visitObject = DeselectAll ( ) ; // removes the control buttons
}
// Creates the "continue" button.
2012-09-15 13:33:08 +00:00
if ( m_interface - > SearchControl ( EVENT_DT_END ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Point pos , dim ;
2012-06-26 20:23:05 +00:00
pos . x = 10.0f / 640.0f ;
pos . y = 10.0f / 480.0f ;
dim . x = 50.0f / 640.0f ;
dim . y = 50.0f / 480.0f ;
m_interface - > CreateButton ( pos , dim , 16 , EVENT_DT_END ) ;
}
// Creates the arrow to show the place.
2012-09-15 13:33:08 +00:00
if ( m_visitArrow ! = 0 )
2012-06-26 20:23:05 +00:00
{
m_visitArrow - > DeleteObject ( ) ;
delete m_visitArrow ;
m_visitArrow = 0 ;
}
2012-09-15 13:33:08 +00:00
Math : : Vector goal = m_displayText - > GetVisitGoal ( event ) ;
2013-12-29 11:08:59 +00:00
m_visitArrow = CObjectManager : : GetInstancePointer ( ) - > CreateObject ( goal , 0.0f , OBJECT_SHOW , - 1.0f , 1.0f , 10.0f ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_visitPos = m_visitArrow - > GetPosition ( 0 ) ;
2012-06-26 20:23:05 +00:00
m_visitPosArrow = m_visitPos ;
2012-09-15 13:33:08 +00:00
m_visitPosArrow . y + = m_displayText - > GetVisitHeight ( event ) ;
2012-06-26 20:23:05 +00:00
m_visitArrow - > SetPosition ( 0 , m_visitPosArrow ) ;
m_visitTime = 0.0 ;
2012-09-15 13:33:08 +00:00
m_visitParticle = 0.0f ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_particle - > DeleteParticle ( Gfx : : PARTISHOW ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_camera - > StartVisit ( m_displayText - > GetVisitGoal ( event ) ,
m_displayText - > GetVisitDist ( event ) ) ;
2012-06-26 20:23:05 +00:00
m_displayText - > SetVisit ( event ) ;
ChangePause ( true ) ;
}
2012-09-15 13:33:08 +00:00
//! Move the arrow to visit
2012-06-26 20:23:05 +00:00
void CRobotMain : : FrameVisit ( float rTime )
{
2012-09-15 13:33:08 +00:00
if ( m_visitArrow = = 0 ) return ;
2012-06-26 20:23:05 +00:00
// Moves the arrow.
m_visitTime + = rTime ;
2012-09-15 13:33:08 +00:00
Math : : Vector pos = m_visitPosArrow ;
2012-06-26 20:23:05 +00:00
pos . y + = 1.5f + sinf ( m_visitTime * 4.0f ) * 4.0f ;
m_visitArrow - > SetPosition ( 0 , pos ) ;
m_visitArrow - > SetAngleY ( 0 , m_visitTime * 2.0f ) ;
// Manages the particles "arrows".
2012-09-15 13:33:08 +00:00
m_visitParticle - = rTime ;
if ( m_visitParticle < = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_visitParticle = 1.5f ;
2012-06-26 20:23:05 +00:00
pos = m_visitPos ;
2012-09-15 13:33:08 +00:00
float level = m_terrain - > GetFloorLevel ( pos ) + 2.0f ;
if ( pos . y < level ) pos . y = level ; // not below the ground
Math : : Vector speed ( 0.0f , 0.0f , 0.0f ) ;
Math : : Point dim ;
2012-06-26 20:23:05 +00:00
dim . x = 30.0f ;
dim . y = dim . x ;
2012-09-15 13:33:08 +00:00
m_particle - > CreateParticle ( pos , speed , dim , Gfx : : PARTISHOW , 2.0f ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! End of the visit instead of an error
2012-06-26 20:23:05 +00:00
void CRobotMain : : StopDisplayVisit ( )
{
m_visitLast = EVENT_NULL ;
// Removes the button.
m_interface - > DeleteControl ( EVENT_DT_END ) ;
// Removes the arrow.
2012-09-15 13:33:08 +00:00
if ( m_visitArrow ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_visitArrow - > DeleteObject ( ) ;
delete m_visitArrow ;
2012-09-15 13:33:08 +00:00
m_visitArrow = nullptr ;
2012-06-26 20:23:05 +00:00
}
// Removes particles "arrows".
2012-09-15 13:33:08 +00:00
m_particle - > DeleteParticle ( Gfx : : PARTISHOW ) ;
2012-06-26 20:23:05 +00:00
m_camera - > StopVisit ( ) ;
m_displayText - > ClearVisit ( ) ;
ChangePause ( false ) ;
2012-09-15 13:33:08 +00:00
if ( m_visitObject ! = 0 )
2012-06-26 20:23:05 +00:00
{
SelectObject ( m_visitObject , false ) ; // gives the command buttons
m_visitObject = 0 ;
}
}
2012-09-15 13:33:08 +00:00
//! Updates all the shortcuts
2012-06-26 20:23:05 +00:00
void CRobotMain : : UpdateShortcuts ( )
{
m_short - > UpdateShortcuts ( ) ;
}
2012-09-15 13:33:08 +00:00
//! Returns the object that default was select after the creation of a scene
CObject * CRobotMain : : GetSelectObject ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_selectObject ! = nullptr ) return m_selectObject ;
2012-06-26 20:23:05 +00:00
return SearchHuman ( ) ;
}
2012-09-15 13:33:08 +00:00
//! Deselects everything, and returns the object that was selected
2012-06-26 20:23:05 +00:00
CObject * CRobotMain : : DeselectAll ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
CObject * prev = nullptr ;
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetSelect ( ) ) prev = obj ;
obj - > SetSelect ( false ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
return prev ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Selects an object, without attending to deselect the rest
void CRobotMain : : SelectOneObject ( CObject * obj , bool displayError )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetSelect ( true , displayError ) ;
2012-09-17 18:47:27 +00:00
m_camera - > SetControllingObject ( obj ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
2012-06-26 20:23:05 +00:00
if ( type = = OBJECT_HUMAN | |
type = = OBJECT_MOBILEfa | |
type = = OBJECT_MOBILEta | |
type = = OBJECT_MOBILEwa | |
type = = OBJECT_MOBILEia | |
type = = OBJECT_MOBILEfc | |
type = = OBJECT_MOBILEtc | |
type = = OBJECT_MOBILEwc | |
type = = OBJECT_MOBILEic | |
type = = OBJECT_MOBILEfi | |
type = = OBJECT_MOBILEti | |
type = = OBJECT_MOBILEwi | |
type = = OBJECT_MOBILEii | |
type = = OBJECT_MOBILEfs | |
type = = OBJECT_MOBILEts | |
type = = OBJECT_MOBILEws | |
type = = OBJECT_MOBILEis | |
type = = OBJECT_MOBILErt | |
type = = OBJECT_MOBILErc | |
type = = OBJECT_MOBILErr | |
type = = OBJECT_MOBILErs | |
type = = OBJECT_MOBILEsa | |
type = = OBJECT_MOBILEft | |
type = = OBJECT_MOBILEtt | |
type = = OBJECT_MOBILEwt | |
type = = OBJECT_MOBILEit | |
type = = OBJECT_MOBILEdr | |
type = = OBJECT_APOLLO2 )
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( obj - > GetCameraType ( ) ) ;
m_camera - > SetDist ( obj - > GetCameraDist ( ) ) ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_BACK ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
CObject * toto = SearchToto ( ) ;
if ( toto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-10-17 19:48:40 +00:00
CMotionToto * mt = static_cast < CMotionToto * > ( toto - > GetMotion ( ) ) ;
2012-09-15 13:33:08 +00:00
if ( mt ! = nullptr )
2012-06-26 20:23:05 +00:00
mt - > SetLinkType ( type ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Selects the object aimed by the mouse
bool CRobotMain : : SelectObject ( CObject * obj , bool displayError )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_VISIT )
2012-06-26 20:23:05 +00:00
StopDisplayVisit ( ) ;
2012-09-15 13:33:08 +00:00
if ( m_movieLock | | m_editLock | | m_pause ) return false ;
if ( m_movie - > IsExist ( ) ) return false ;
if ( obj = = nullptr | | ! IsSelectable ( obj ) ) return false ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CObject * prev = DeselectAll ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( prev ! = nullptr & & prev ! = obj )
obj - > AddDeselList ( prev ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
SelectOneObject ( obj , displayError ) ;
2012-06-26 20:23:05 +00:00
m_short - > UpdateShortcuts ( ) ;
return true ;
}
2012-09-15 13:33:08 +00:00
//! Deselects the selected object
2012-06-26 20:23:05 +00:00
bool CRobotMain : : DeselectObject ( )
{
2012-09-15 13:33:08 +00:00
CObject * obj = nullptr ;
CObject * prev = DeselectAll ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( prev = = nullptr )
obj = SearchHuman ( ) ;
2012-06-26 20:23:05 +00:00
else
2012-09-15 13:33:08 +00:00
obj = prev - > SubDeselList ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr )
obj = SearchHuman ( ) ;
if ( obj ! = nullptr )
SelectOneObject ( obj ) ;
2012-06-26 20:23:05 +00:00
else
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_FREE ) ;
2012-06-26 20:23:05 +00:00
m_short - > UpdateShortcuts ( ) ;
return true ;
}
2012-09-15 13:33:08 +00:00
//! Quickly removes all objects
2012-06-26 20:23:05 +00:00
void CRobotMain : : DeleteAllObjects ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-06-26 20:23:05 +00:00
// Removes all pyrotechnic effects in progress.
2012-09-15 13:33:08 +00:00
while ( true )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
Gfx : : CPyro * pyro = static_cast < Gfx : : CPyro * > ( iMan - > SearchInstance ( CLASS_PYRO , 0 ) ) ;
2012-09-15 13:33:08 +00:00
if ( pyro = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
pyro - > DeleteObject ( ) ;
delete pyro ;
}
// Removes the arrow.
2012-09-15 13:33:08 +00:00
if ( m_visitArrow ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_visitArrow - > DeleteObject ( ) ;
delete m_visitArrow ;
2012-09-15 13:33:08 +00:00
m_visitArrow = nullptr ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < MAXSHOWLIMIT ; i + + )
2012-06-26 20:23:05 +00:00
FlushShowLimit ( i ) ;
2012-09-15 13:33:08 +00:00
while ( true )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , 0 ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > DeleteObject ( true ) ; // destroys rapidly
delete obj ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! Selects the human
2012-06-26 20:23:05 +00:00
void CRobotMain : : SelectHuman ( )
{
SelectObject ( SearchHuman ( ) ) ;
}
2012-09-15 13:33:08 +00:00
//! Returns the object human
2012-06-26 20:23:05 +00:00
CObject * CRobotMain : : SearchHuman ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = 0 ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN )
return obj ;
2012-06-26 20:23:05 +00:00
}
return 0 ;
}
2012-09-15 13:33:08 +00:00
//! Returns the object toto
2012-06-26 20:23:05 +00:00
CObject * CRobotMain : : SearchToto ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_TOTO )
return obj ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
return nullptr ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the nearest selectable object from a given position
CObject * CRobotMain : : SearchNearest ( Math : : Vector pos , CObject * exclu )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
float min = 100000.0f ;
CObject * best = 0 ;
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj = = exclu ) continue ;
if ( ! IsSelectable ( obj ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_TOTO ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Vector oPos = obj - > GetPosition ( 0 ) ;
float dist = Math : : DistanceProjected ( oPos , pos ) ;
if ( dist < min )
2012-06-26 20:23:05 +00:00
{
min = dist ;
2012-09-15 13:33:08 +00:00
best = obj ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
return best ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the selected object
CObject * CRobotMain : : GetSelect ( )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetSelect ( ) )
return obj ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
return nullptr ;
2012-06-26 20:23:05 +00:00
}
CObject * CRobotMain : : SearchObject ( ObjectType type )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = type )
return obj ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
return nullptr ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Detects the object aimed by the mouse
2012-06-26 20:23:05 +00:00
CObject * CRobotMain : : DetectObject ( Math : : Point pos )
{
2012-09-15 13:33:08 +00:00
int objRank = m_engine - > DetectObject ( pos ) ;
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! obj - > GetActif ( ) ) continue ;
2013-04-20 09:17:21 +00:00
CObject * truck = obj - > GetTruck ( ) ;
if ( truck ! = nullptr ) if ( ! truck - > GetActif ( ) ) continue ;
2012-09-15 13:33:08 +00:00
if ( obj - > GetProxyActivate ( ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CObject * target = nullptr ;
ObjectType type = obj - > GetType ( ) ;
2012-06-26 20:23:05 +00:00
if ( type = = OBJECT_PORTICO | |
type = = OBJECT_BASE | |
type = = OBJECT_DERRICK | |
type = = OBJECT_FACTORY | |
type = = OBJECT_REPAIR | |
type = = OBJECT_DESTROYER | |
type = = OBJECT_STATION | |
type = = OBJECT_CONVERT | |
type = = OBJECT_TOWER | |
type = = OBJECT_RESEARCH | |
type = = OBJECT_RADAR | |
type = = OBJECT_INFO | |
type = = OBJECT_ENERGY | |
type = = OBJECT_LABO | |
type = = OBJECT_NUCLEAR | |
type = = OBJECT_PARA | |
type = = OBJECT_SAFE | |
type = = OBJECT_HUSTON | |
type = = OBJECT_TARGET1 | |
type = = OBJECT_TARGET2 | |
type = = OBJECT_START | |
type = = OBJECT_END | |
type = = OBJECT_STONE | |
type = = OBJECT_URANIUM | |
type = = OBJECT_BULLET | |
type = = OBJECT_METAL | |
type = = OBJECT_BBOX | |
type = = OBJECT_KEYa | |
type = = OBJECT_KEYb | |
type = = OBJECT_KEYc | |
type = = OBJECT_KEYd | |
type = = OBJECT_TNT | |
type = = OBJECT_SCRAP1 | |
type = = OBJECT_SCRAP2 | |
type = = OBJECT_SCRAP3 | |
type = = OBJECT_SCRAP4 | |
type = = OBJECT_SCRAP5 | |
type = = OBJECT_BOMB | |
type = = OBJECT_BAG | |
type = = OBJECT_WAYPOINT | |
type = = OBJECT_FLAGb | |
type = = OBJECT_FLAGr | |
type = = OBJECT_FLAGg | |
type = = OBJECT_FLAGy | |
type = = OBJECT_FLAGv | |
type = = OBJECT_MARKPOWER | |
type = = OBJECT_MARKSTONE | |
type = = OBJECT_MARKURANIUM | |
type = = OBJECT_MARKKEYa | |
type = = OBJECT_MARKKEYb | |
type = = OBJECT_MARKKEYc | |
type = = OBJECT_MARKKEYd | |
type = = OBJECT_HUMAN | |
type = = OBJECT_TECH | |
type = = OBJECT_TOTO | |
type = = OBJECT_MOBILEfa | |
type = = OBJECT_MOBILEta | |
type = = OBJECT_MOBILEwa | |
type = = OBJECT_MOBILEia | |
type = = OBJECT_MOBILEfc | |
type = = OBJECT_MOBILEtc | |
type = = OBJECT_MOBILEwc | |
type = = OBJECT_MOBILEic | |
type = = OBJECT_MOBILEfi | |
type = = OBJECT_MOBILEti | |
type = = OBJECT_MOBILEwi | |
type = = OBJECT_MOBILEii | |
type = = OBJECT_MOBILEfs | |
type = = OBJECT_MOBILEts | |
type = = OBJECT_MOBILEws | |
type = = OBJECT_MOBILEis | |
type = = OBJECT_MOBILErt | |
type = = OBJECT_MOBILErc | |
type = = OBJECT_MOBILErr | |
type = = OBJECT_MOBILErs | |
type = = OBJECT_MOBILEsa | |
type = = OBJECT_MOBILEtg | |
type = = OBJECT_MOBILEft | |
type = = OBJECT_MOBILEtt | |
type = = OBJECT_MOBILEwt | |
type = = OBJECT_MOBILEit | |
type = = OBJECT_MOBILEdr | |
type = = OBJECT_MOTHER | |
type = = OBJECT_ANT | |
type = = OBJECT_SPIDER | |
type = = OBJECT_BEE | |
type = = OBJECT_WORM | |
type = = OBJECT_EGG | |
type = = OBJECT_RUINmobilew1 | |
type = = OBJECT_RUINmobilew2 | |
type = = OBJECT_RUINmobilet1 | |
type = = OBJECT_RUINmobilet2 | |
type = = OBJECT_RUINmobiler1 | |
type = = OBJECT_RUINmobiler2 | |
type = = OBJECT_RUINfactory | |
type = = OBJECT_RUINdoor | |
type = = OBJECT_RUINsupport | |
type = = OBJECT_RUINradar | |
type = = OBJECT_RUINconvert | |
type = = OBJECT_RUINbase | |
type = = OBJECT_RUINhead | |
type = = OBJECT_APOLLO1 | |
type = = OBJECT_APOLLO2 | |
type = = OBJECT_APOLLO3 | |
type = = OBJECT_APOLLO4 | |
type = = OBJECT_APOLLO5 )
{
2012-09-15 13:33:08 +00:00
target = obj ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
else if ( ( type = = OBJECT_POWER | |
type = = OBJECT_ATOMIC ) & &
obj - > GetTruck ( ) ! = nullptr ) // battery used?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
target = obj - > GetTruck ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
else if ( type = = OBJECT_POWER | |
type = = OBJECT_ATOMIC )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
target = obj ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
for ( int j = 0 ; j < OBJECTMAXPART ; j + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int rank = obj - > GetObjectRank ( j ) ;
if ( rank = = - 1 ) continue ;
if ( rank ! = objRank ) continue ;
return target ;
2012-06-26 20:23:05 +00:00
}
}
return 0 ;
}
2012-09-15 13:33:08 +00:00
//! Indicates whether an object is selectable
bool CRobotMain : : IsSelectable ( CObject * obj )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! obj - > GetSelectable ( ) ) return false ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
2012-06-26 20:23:05 +00:00
if ( type = = OBJECT_HUMAN | |
type = = OBJECT_TOTO | |
type = = OBJECT_MOBILEfa | |
type = = OBJECT_MOBILEta | |
type = = OBJECT_MOBILEwa | |
type = = OBJECT_MOBILEia | |
type = = OBJECT_MOBILEfc | |
type = = OBJECT_MOBILEtc | |
type = = OBJECT_MOBILEwc | |
type = = OBJECT_MOBILEic | |
type = = OBJECT_MOBILEfi | |
type = = OBJECT_MOBILEti | |
type = = OBJECT_MOBILEwi | |
type = = OBJECT_MOBILEii | |
type = = OBJECT_MOBILEfs | |
type = = OBJECT_MOBILEts | |
type = = OBJECT_MOBILEws | |
type = = OBJECT_MOBILEis | |
type = = OBJECT_MOBILErt | |
type = = OBJECT_MOBILErc | |
type = = OBJECT_MOBILErr | |
type = = OBJECT_MOBILErs | |
type = = OBJECT_MOBILEsa | |
type = = OBJECT_MOBILEft | |
type = = OBJECT_MOBILEtt | |
type = = OBJECT_MOBILEwt | |
type = = OBJECT_MOBILEit | |
type = = OBJECT_MOBILEdr | |
type = = OBJECT_APOLLO2 | |
type = = OBJECT_BASE | |
type = = OBJECT_DERRICK | |
type = = OBJECT_FACTORY | |
type = = OBJECT_REPAIR | |
type = = OBJECT_DESTROYER | |
type = = OBJECT_STATION | |
type = = OBJECT_CONVERT | |
type = = OBJECT_TOWER | |
type = = OBJECT_RESEARCH | |
type = = OBJECT_RADAR | |
type = = OBJECT_INFO | |
type = = OBJECT_ENERGY | |
type = = OBJECT_LABO | |
type = = OBJECT_NUCLEAR | |
type = = OBJECT_PARA | |
type = = OBJECT_SAFE | |
type = = OBJECT_HUSTON )
{
return true ;
}
2012-09-15 13:33:08 +00:00
if ( m_selectInsect )
2012-06-26 20:23:05 +00:00
{
if ( type = = OBJECT_MOTHER | |
type = = OBJECT_ANT | |
type = = OBJECT_SPIDER | |
type = = OBJECT_BEE | |
type = = OBJECT_WORM | |
type = = OBJECT_MOBILEtg )
{
return true ;
}
}
return false ;
}
2012-09-15 13:33:08 +00:00
//! Deletes the selected object
2012-06-26 20:23:05 +00:00
bool CRobotMain : : DeleteObject ( )
{
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj = = nullptr ) return false ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
Gfx : : CPyro * pyro = new Gfx : : CPyro ( ) ;
2012-09-15 13:33:08 +00:00
pyro - > Create ( Gfx : : PT_FRAGT , obj ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > SetSelect ( false ) ; // deselects the object
m_camera - > SetType ( Gfx : : CAM_TYPE_EXPLO ) ;
2012-06-26 20:23:05 +00:00
DeselectAll ( ) ;
2012-09-15 13:33:08 +00:00
obj - > DeleteDeselList ( obj ) ;
2012-06-26 20:23:05 +00:00
return true ;
}
2012-09-15 13:33:08 +00:00
//! Removes setting evidence of the object with the mouse hovers over
2012-06-26 20:23:05 +00:00
void CRobotMain : : HiliteClear ( )
{
ClearTooltip ( ) ;
2013-12-02 23:11:26 +00:00
m_tooltipName . clear ( ) ; // really removes the tooltip
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! m_hilite ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int rank = - 1 ;
m_engine - > SetHighlightRank ( & rank ) ; // nothing more selected
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > SetHilite ( false ) ;
m_map - > SetHighlight ( 0 ) ;
m_short - > SetHighlight ( 0 ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
m_hilite = false ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Highlights the object with the mouse hovers over
2012-06-26 20:23:05 +00:00
void CRobotMain : : HiliteObject ( Math : : Point pos )
{
2012-09-15 13:33:08 +00:00
if ( m_fixScene & & m_phase ! = PHASE_PERSO ) return ;
if ( m_movieLock ) return ;
if ( m_movie - > IsExist ( ) ) return ;
2012-09-20 18:37:37 +00:00
if ( m_app - > GetMouseMode ( ) = = MOUSE_NONE ) return ;
2012-06-26 20:23:05 +00:00
ClearInterface ( ) ; // removes setting evidence and tooltip
2012-09-15 13:33:08 +00:00
CObject * obj = m_short - > DetectShort ( pos ) ;
2013-12-02 23:11:26 +00:00
std : : string interfaceTooltipName ;
if ( m_dialog - > GetTooltip ( ) & & m_interface - > GetTooltip ( pos , interfaceTooltipName ) )
2012-06-26 20:23:05 +00:00
{
m_tooltipPos = pos ;
2013-12-02 23:11:26 +00:00
m_tooltipName = interfaceTooltipName ;
2012-06-26 20:23:05 +00:00
m_tooltipTime = 0.0f ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_suspend ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-16 18:00:25 +00:00
bool inMap = false ;
2012-09-15 13:33:08 +00:00
obj = m_map - > DetectMap ( pos , inMap ) ;
if ( obj = = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( inMap ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj = DetectObject ( pos ) ;
2012-06-26 20:23:05 +00:00
2012-09-17 18:47:27 +00:00
if ( ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_ONBOARD ) & &
( m_camera - > GetControllingObject ( ) = = obj ) )
2012-06-26 20:23:05 +00:00
return ;
}
}
2012-09-15 13:33:08 +00:00
if ( obj ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2013-12-02 23:11:26 +00:00
std : : string objectTooltipName ;
if ( m_dialog - > GetTooltip ( ) & & obj - > GetTooltipName ( objectTooltipName ) )
2012-06-26 20:23:05 +00:00
{
m_tooltipPos = pos ;
2013-12-02 23:11:26 +00:00
m_tooltipName = objectTooltipName ;
2012-06-26 20:23:05 +00:00
m_tooltipTime = 0.0f ;
}
2012-09-15 13:33:08 +00:00
if ( IsSelectable ( obj ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetHilite ( true ) ;
2012-09-15 19:47:19 +00:00
m_map - > SetHighlight ( obj ) ;
m_short - > SetHighlight ( obj ) ;
2012-09-15 13:33:08 +00:00
m_hilite = true ;
2012-06-26 20:23:05 +00:00
}
}
}
2012-09-15 13:33:08 +00:00
//! Highlights the object with the mouse hovers over
2012-06-26 20:23:05 +00:00
void CRobotMain : : HiliteFrame ( float rTime )
{
2012-09-15 13:33:08 +00:00
if ( m_fixScene & & m_phase ! = PHASE_PERSO ) return ;
if ( m_movieLock ) return ;
if ( m_movie - > IsExist ( ) ) return ;
2012-06-26 20:23:05 +00:00
m_tooltipTime + = rTime ;
ClearTooltip ( ) ;
2013-12-02 23:11:26 +00:00
if ( m_tooltipTime > = 0.2f & & ! m_tooltipName . empty ( ) )
2012-06-26 20:23:05 +00:00
{
CreateTooltip ( m_tooltipPos , m_tooltipName ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Creates a tooltip
2013-12-02 23:11:26 +00:00
void CRobotMain : : CreateTooltip ( Math : : Point pos , const std : : string & text )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Point corner ;
2012-06-26 20:23:05 +00:00
corner . x = pos . x + 0.022f ;
corner . y = pos . y - 0.052f ;
2012-09-15 13:33:08 +00:00
Math : : Point start , end ;
m_engine - > GetText ( ) - > SizeText ( text , Gfx : : FONT_COLOBOT , Gfx : : FONT_SIZE_SMALL ,
corner , Gfx : : TEXT_ALIGN_LEFT ,
start , end ) ;
2012-06-26 20:23:05 +00:00
start . x - = 0.010f ;
2013-11-19 16:22:25 +00:00
start . y - = 0.006f ;
2012-06-26 20:23:05 +00:00
end . x + = 0.010f ;
2013-11-19 16:22:25 +00:00
end . y + = 0.008f ; // small'ish margin
2012-06-26 20:23:05 +00:00
pos . x = start . x ;
pos . y = start . y ;
2012-09-15 13:33:08 +00:00
Math : : Point dim ;
2012-06-26 20:23:05 +00:00
dim . x = end . x - start . x ;
dim . y = end . y - start . y ;
2012-09-15 13:33:08 +00:00
Math : : Point offset ;
2012-06-26 20:23:05 +00:00
offset . x = 0.0f ;
offset . y = 0.0f ;
2012-09-15 13:33:08 +00:00
if ( pos . x + dim . x > 1.0f ) offset . x = 1.0f - ( pos . x + dim . x ) ;
if ( pos . y < 0.0f ) offset . y = - pos . y ;
2012-06-26 20:23:05 +00:00
corner . x + = offset . x ;
corner . y + = offset . y ;
pos . x + = offset . x ;
pos . y + = offset . y ;
m_interface - > CreateWindows ( pos , dim , 1 , EVENT_TOOLTIP ) ;
2012-10-17 19:48:40 +00:00
Ui : : CWindow * pw = static_cast < Ui : : CWindow * > ( m_interface - > SearchControl ( EVENT_TOOLTIP ) ) ;
2012-09-15 13:33:08 +00:00
if ( pw ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
pw - > SetState ( Ui : : STATE_SHADOW ) ;
2012-06-26 20:23:05 +00:00
pw - > SetTrashEvent ( false ) ;
2012-09-15 13:33:08 +00:00
pos . y - = m_engine - > GetText ( ) - > GetHeight ( Gfx : : FONT_COLOBOT , Gfx : : FONT_SIZE_SMALL ) / 2.0f ;
2012-06-26 20:23:05 +00:00
pw - > CreateLabel ( pos , dim , - 1 , EVENT_LABEL2 , text ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Clears the previous tooltip
2012-06-26 20:23:05 +00:00
void CRobotMain : : ClearTooltip ( )
{
m_interface - > DeleteControl ( EVENT_TOOLTIP ) ;
}
2012-09-15 13:33:08 +00:00
//! Displays help for an object
2012-06-26 20:23:05 +00:00
void CRobotMain : : HelpObject ( )
{
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2013-03-29 09:03:35 +00:00
const char * filename = GetHelpFilename ( obj - > GetType ( ) ) . c_str ( ) ;
2012-09-15 13:33:08 +00:00
if ( filename [ 0 ] = = 0 ) return ;
2012-06-26 20:23:05 +00:00
StartDisplayInfo ( filename , - 1 ) ;
}
2012-09-15 13:33:08 +00:00
//! Change the mode of the camera
2012-06-26 20:23:05 +00:00
void CRobotMain : : ChangeCamera ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetSelect ( ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetCameraLock ( ) ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType oType = obj - > GetType ( ) ;
Gfx : : CameraType type = obj - > GetCameraType ( ) ;
2012-06-26 20:23:05 +00:00
if ( oType ! = OBJECT_MOBILEfa & &
oType ! = OBJECT_MOBILEta & &
oType ! = OBJECT_MOBILEwa & &
oType ! = OBJECT_MOBILEia & &
oType ! = OBJECT_MOBILEfc & &
oType ! = OBJECT_MOBILEtc & &
oType ! = OBJECT_MOBILEwc & &
oType ! = OBJECT_MOBILEic & &
oType ! = OBJECT_MOBILEfi & &
oType ! = OBJECT_MOBILEti & &
oType ! = OBJECT_MOBILEwi & &
oType ! = OBJECT_MOBILEii & &
oType ! = OBJECT_MOBILEfs & &
oType ! = OBJECT_MOBILEts & &
oType ! = OBJECT_MOBILEws & &
oType ! = OBJECT_MOBILEis & &
oType ! = OBJECT_MOBILErt & &
oType ! = OBJECT_MOBILErc & &
oType ! = OBJECT_MOBILErr & &
oType ! = OBJECT_MOBILErs & &
oType ! = OBJECT_MOBILEsa & &
oType ! = OBJECT_MOBILEtg & &
oType ! = OBJECT_MOBILEft & &
oType ! = OBJECT_MOBILEtt & &
oType ! = OBJECT_MOBILEwt & &
oType ! = OBJECT_MOBILEit & &
oType ! = OBJECT_MOBILEdr & &
oType ! = OBJECT_APOLLO2 ) return ;
2012-09-15 13:33:08 +00:00
if ( oType = = OBJECT_MOBILEdr ) // designer?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( type = = Gfx : : CAM_TYPE_PLANE ) type = Gfx : : CAM_TYPE_BACK ;
else if ( type = = Gfx : : CAM_TYPE_BACK ) type = Gfx : : CAM_TYPE_PLANE ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
else if ( obj - > GetTrainer ( ) ) // trainer?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( type = = Gfx : : CAM_TYPE_ONBOARD ) type = Gfx : : CAM_TYPE_FIX ;
else if ( type = = Gfx : : CAM_TYPE_FIX ) type = Gfx : : CAM_TYPE_PLANE ;
else if ( type = = Gfx : : CAM_TYPE_PLANE ) type = Gfx : : CAM_TYPE_BACK ;
else if ( type = = Gfx : : CAM_TYPE_BACK ) type = Gfx : : CAM_TYPE_ONBOARD ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-09-15 13:33:08 +00:00
if ( type = = Gfx : : CAM_TYPE_ONBOARD ) type = Gfx : : CAM_TYPE_BACK ;
else if ( type = = Gfx : : CAM_TYPE_BACK ) type = Gfx : : CAM_TYPE_ONBOARD ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
obj - > SetCameraType ( type ) ;
2012-06-26 20:23:05 +00:00
m_camera - > SetType ( type ) ;
}
}
}
2012-09-15 13:33:08 +00:00
//! Remote control the camera using the arrow keys
2012-09-17 22:01:00 +00:00
void CRobotMain : : KeyCamera ( EventType type , unsigned int key )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
// TODO: rewrite key handling to input bindings
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( type = = EVENT_KEY_UP )
2012-06-26 20:23:05 +00:00
{
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_LEFT ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_LEFT ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraPan = 0.0f ;
}
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraPan = 0.0f ;
}
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_UP ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_UP ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraZoom = 0.0f ;
}
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_DOWN ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_DOWN ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraZoom = 0.0f ;
}
}
2012-09-15 13:33:08 +00:00
if ( m_phase ! = PHASE_SIMUL ) return ;
if ( m_editLock ) return ; // current edition?
if ( m_trainerPilot ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj = = nullptr ) return ;
if ( ! obj - > GetTrainer ( ) ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( type = = EVENT_KEY_DOWN )
2012-06-26 20:23:05 +00:00
{
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_LEFT ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_LEFT ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraPan = - 1.0f ;
}
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_RIGHT ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraPan = 1.0f ;
}
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_UP ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_UP ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraZoom = - 1.0f ;
}
2012-10-06 22:46:46 +00:00
if ( key = = GetInputBinding ( INPUT_SLOT_DOWN ) . primary | |
key = = GetInputBinding ( INPUT_SLOT_DOWN ) . secondary )
2012-06-26 20:23:05 +00:00
{
m_cameraZoom = 1.0f ;
}
}
}
2012-09-15 13:33:08 +00:00
//! Panned with the camera if a button is pressed
2012-06-26 20:23:05 +00:00
void CRobotMain : : RemoteCamera ( float pan , float zoom , float rTime )
{
2012-09-15 13:33:08 +00:00
if ( pan ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = m_camera - > GetRemotePan ( ) ;
2012-06-26 20:23:05 +00:00
value + = pan * rTime * 1.5f ;
m_camera - > SetRemotePan ( value ) ;
}
2012-09-15 13:33:08 +00:00
if ( zoom ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = m_camera - > GetRemoteZoom ( ) ;
2012-06-26 20:23:05 +00:00
value + = zoom * rTime * 0.3f ;
m_camera - > SetRemoteZoom ( value ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Cancels the current movie
2012-06-26 20:23:05 +00:00
void CRobotMain : : AbortMovie ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CAuto * automat = obj - > GetAuto ( ) ;
if ( automat ! = 0 )
2012-06-26 20:23:05 +00:00
automat - > Abort ( ) ;
}
2012-09-20 18:37:37 +00:00
m_app - > SetMouseMode ( MOUSE_ENGINE ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Updates the text information
2012-06-26 20:23:05 +00:00
void CRobotMain : : UpdateInfoText ( )
{
2012-09-15 13:33:08 +00:00
if ( m_showPos )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector pos = obj - > GetPosition ( 0 ) ;
char info [ 100 ] ;
2012-06-26 20:23:05 +00:00
sprintf ( info , " Pos = %.2f ; %.2f " , pos . x / g_unit , pos . z / g_unit ) ;
2012-09-15 13:33:08 +00:00
//TODO: m_engine->SetInfoText(4, info);
2012-06-26 20:23:05 +00:00
}
}
}
2012-09-15 13:33:08 +00:00
//! Initializes the view
2012-06-26 20:23:05 +00:00
void CRobotMain : : InitEye ( )
{
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
m_camera - > Init ( Math : : Vector ( 0.0f , 10.0f , 0.0f ) ,
Math : : Vector ( 10.0f , 5.0f , 0.0f ) , 0.0f ) ;
}
2012-09-15 13:33:08 +00:00
//! Advances the entire scene
2012-06-26 20:23:05 +00:00
bool CRobotMain : : EventFrame ( const Event & event )
{
m_time + = event . rTime ;
2012-09-15 13:33:08 +00:00
if ( ! m_movieLock ) m_gameTime + = event . rTime ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! m_immediatSatCom & & ! m_beginSatCom & &
m_gameTime > 0.1f & & m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
{
m_displayText - > DisplayError ( INFO_BEGINSATCOM , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
2012-09-15 13:33:08 +00:00
m_beginSatCom = true ; // message appears
2012-06-26 20:23:05 +00:00
}
m_water - > EventProcess ( event ) ;
m_cloud - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
m_lightning - > EventProcess ( event ) ;
2012-06-26 20:23:05 +00:00
m_planet - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
Ui : : CMap * pm = nullptr ;
2012-10-17 19:48:40 +00:00
Ui : : CWindow * pw = static_cast < Ui : : CWindow * > ( m_interface - > SearchControl ( EVENT_WINDOW1 ) ) ;
2012-09-15 13:33:08 +00:00
if ( pw = = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
pm = nullptr ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-10-17 19:48:40 +00:00
pm = static_cast < Ui : : CMap * > ( pw - > SearchControl ( EVENT_OBJECT_MAP ) ) ;
2012-09-15 13:33:08 +00:00
if ( pm ! = nullptr ) pm - > FlushObject ( ) ;
2012-06-26 20:23:05 +00:00
}
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
CObject * toto = nullptr ;
if ( ! m_freePhoto )
2012-06-26 20:23:05 +00:00
{
// Advances all the robots, but not toto.
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
if ( pm ! = nullptr ) pm - > UpdateObject ( obj ) ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_TOTO )
toto = obj ;
2012-06-26 20:23:05 +00:00
else
2012-09-15 13:33:08 +00:00
obj - > EventProcess ( event ) ;
2012-06-26 20:23:05 +00:00
}
// Advances all objects transported by robots.
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
if ( obj - > GetTruck ( ) = = nullptr ) continue ;
obj - > EventProcess ( event ) ;
2012-06-26 20:23:05 +00:00
}
// Advances pyrotechnic effects.
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
Gfx : : CPyro * pyro = static_cast < Gfx : : CPyro * > ( iMan - > SearchInstance ( CLASS_PYRO , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( pyro = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
pyro - > EventProcess ( event ) ;
if ( pyro - > IsEnded ( ) ! = ERR_CONTINUE )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
pyro - > DeleteObject ( ) ;
delete pyro ;
2012-06-26 20:23:05 +00:00
}
}
}
// The camera follows the object, because its position
2012-09-15 13:33:08 +00:00
// may depend on the selected object (Gfx::CAM_TYPE_ONBOARD or Gfx::CAM_TYPE_BACK).
if ( m_phase = = PHASE_SIMUL & & ! m_editFull )
2012-06-26 20:23:05 +00:00
{
m_camera - > EventProcess ( event ) ;
2012-09-15 13:33:08 +00:00
if ( m_engine - > GetFog ( ) )
m_camera - > SetOverBaseColor ( m_particle - > GetFogColor ( m_engine - > GetEyePt ( ) ) ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_PERSO | |
m_phase = = PHASE_WIN | |
m_phase = = PHASE_LOST )
2012-06-26 20:23:05 +00:00
{
m_camera - > EventProcess ( event ) ;
}
// Advances toto following the camera, because its position depends on the camera.
2012-09-15 13:33:08 +00:00
if ( toto ! = nullptr )
2012-06-26 20:23:05 +00:00
toto - > EventProcess ( event ) ;
HiliteFrame ( event . rTime ) ;
// Moves the film indicator.
2012-09-15 13:33:08 +00:00
if ( m_movieLock & & ! m_editLock ) // movie in progress?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Ui : : CControl * pc = m_interface - > SearchControl ( EVENT_OBJECT_MOVIELOCK ) ;
if ( pc ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Point pos , dim ;
2012-06-26 20:23:05 +00:00
dim . x = 32.0f / 640.0f ;
dim . y = 32.0f / 480.0f ;
pos . x = 20.0f / 640.0f ;
pos . y = ( 480.0f - 24.0f ) / 480.0f ;
2012-09-15 13:33:08 +00:00
float zoom = 1.0f + sinf ( m_time * 6.0f ) * 0.1f ; // 0.9 .. 1.1
2012-06-26 20:23:05 +00:00
dim . x * = zoom ;
dim . y * = zoom ;
pos . x - = dim . x / 2.0f ;
pos . y - = dim . y / 2.0f ;
pc - > SetPos ( pos ) ;
pc - > SetDim ( dim ) ;
}
}
// Moves edition indicator.
2012-09-15 13:33:08 +00:00
if ( m_editLock | | m_pause ) // edition in progress?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Ui : : CControl * pc = m_interface - > SearchControl ( EVENT_OBJECT_EDITLOCK ) ;
if ( pc ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Point pos , dim ;
if ( m_editFull | | m_editLock )
2012-06-26 20:23:05 +00:00
{
dim . x = 10.0f / 640.0f ;
dim . y = 10.0f / 480.0f ;
pos . x = - 20.0f / 640.0f ;
pos . y = - 20.0f / 480.0f ; // invisible!
}
else
{
dim . x = 32.0f / 640.0f ;
dim . y = 32.0f / 480.0f ;
pos . x = 20.0f / 640.0f ;
pos . y = ( 480.0f - 24.0f ) / 480.0f ;
2012-09-15 13:33:08 +00:00
float zoom = 1.0f + sinf ( m_time * 6.0f ) * 0.1f ; // 0.9 .. 1.1
2012-06-26 20:23:05 +00:00
dim . x * = zoom ;
dim . y * = zoom ;
pos . x - = dim . x / 2.0f ;
pos . y - = dim . y / 2.0f ;
}
pc - > SetPos ( pos ) ;
pc - > SetDim ( dim ) ;
}
}
// Will move the arrow to visit.
2012-09-15 13:33:08 +00:00
if ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_VISIT )
2012-06-26 20:23:05 +00:00
FrameVisit ( event . rTime ) ;
// Moves the boundaries.
FrameShowLimit ( event . rTime ) ;
2012-09-15 13:33:08 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! m_editLock & & m_checkEndTime + 1.0f < m_time )
2012-06-26 20:23:05 +00:00
{
m_checkEndTime = m_time ;
CheckEndMission ( true ) ;
2013-04-13 13:07:08 +00:00
UpdateAudio ( true ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_winDelay > 0.0f & & ! m_editLock )
2012-06-26 20:23:05 +00:00
{
m_winDelay - = event . rTime ;
2012-09-15 13:33:08 +00:00
if ( m_winDelay < = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_movieLock )
2012-06-26 20:23:05 +00:00
m_winDelay = 1.0f ;
else
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_WIN ) ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
if ( m_lostDelay > 0.0f & & ! m_editLock )
2012-06-26 20:23:05 +00:00
{
m_lostDelay - = event . rTime ;
2012-09-15 13:33:08 +00:00
if ( m_lostDelay < = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_movieLock )
2012-06-26 20:23:05 +00:00
m_winDelay = 1.0f ;
else
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_LOST ) ) ;
2012-06-26 20:23:05 +00:00
}
}
}
2012-09-15 13:33:08 +00:00
if ( m_delayWriteMessage > 0 )
2012-06-26 20:23:05 +00:00
{
m_delayWriteMessage - - ;
2012-09-15 13:33:08 +00:00
if ( m_delayWriteMessage = = 0 )
2012-06-26 20:23:05 +00:00
{
m_displayText - > DisplayError ( INFO_WRITEOK , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
}
}
2012-09-15 13:33:08 +00:00
return true ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Makes the event for all robots
2012-06-26 20:23:05 +00:00
bool CRobotMain : : EventObject ( const Event & event )
{
2012-09-15 13:33:08 +00:00
if ( m_freePhoto ) return true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_resetCreate = false ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > EventProcess ( event ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( m_resetCreate )
2012-06-26 20:23:05 +00:00
ResetCreate ( ) ;
2012-09-15 13:33:08 +00:00
return true ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Calculates the point of arrival of the camera
2012-06-26 20:23:05 +00:00
Math : : Vector CRobotMain : : LookatPoint ( Math : : Vector eye , float angleH , float angleV ,
float length )
{
2012-09-15 13:33:08 +00:00
Math : : Vector lookat = eye ;
2012-06-26 20:23:05 +00:00
lookat . z + = length ;
RotatePoint ( eye , angleH , angleV , lookat ) ;
return lookat ;
}
char * SkipNum ( char * p )
{
2012-09-15 13:33:08 +00:00
while ( * p = = ' ' | | * p = = ' . ' | | * p = = ' - ' | | ( * p > = ' 0 ' & & * p < = ' 9 ' ) )
2012-06-26 20:23:05 +00:00
{
p + + ;
}
return p ;
}
2012-09-15 13:33:08 +00:00
//! Conversion of units
2012-06-26 20:23:05 +00:00
void CRobotMain : : Convert ( )
{
2012-09-15 13:33:08 +00:00
char * base = m_dialog - > GetSceneName ( ) ;
int rank = m_dialog - > GetSceneRank ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-26 20:57:43 +00:00
//TODO change line to string
2012-09-15 13:33:08 +00:00
char line [ 500 ] ;
2012-09-26 20:57:43 +00:00
std : : string tempLine ;
2012-06-26 20:23:05 +00:00
2012-09-26 20:57:43 +00:00
m_dialog - > BuildSceneName ( tempLine , base , rank ) ;
strcpy ( line , tempLine . c_str ( ) ) ;
2012-09-15 13:33:08 +00:00
FILE * file = fopen ( line , " r " ) ;
if ( file = = NULL ) return ;
2012-06-26 20:23:05 +00:00
strcpy ( line + strlen ( line ) - 4 , " .new " ) ;
2012-09-15 13:33:08 +00:00
FILE * fileNew = fopen ( line , " w " ) ;
if ( fileNew = = NULL ) return ;
char lineNew [ 500 ] ;
char s [ 200 ] ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
while ( fgets ( line , 500 , file ) ! = NULL )
2012-06-26 20:23:05 +00:00
{
strcpy ( lineNew , line ) ;
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " DeepView " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char * p = strstr ( line , " air= " ) ;
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = OpFloat ( line , " air " , 500.0f ) ;
2012-06-26 20:23:05 +00:00
value / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 4 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " air= " ) ;
sprintf ( s , " %.2f " , value ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
strcpy ( line , lineNew ) ;
p = strstr ( line , " water= " ) ;
2012-09-15 13:33:08 +00:00
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = OpFloat ( line , " water " , 100.0f ) ;
2012-06-26 20:23:05 +00:00
value / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 6 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " water= " ) ;
sprintf ( s , " %.2f " , value ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
strcpy ( line , lineNew ) ;
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainGenerate " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char * p = strstr ( line , " vision= " ) ;
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = OpFloat ( line , " vision " , 500.0f ) ;
2012-06-26 20:23:05 +00:00
value / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 7 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " vision= " ) ;
sprintf ( s , " %.2f " , value ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateObject " ) | |
Cmd ( line , " CreateSpot " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char * p = strstr ( line , " pos= " ) ;
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector pos = OpPos ( line , " pos " ) ;
2012-06-26 20:23:05 +00:00
pos . x / = g_unit ;
pos . y / = g_unit ;
pos . z / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 4 ) ;
p = SkipNum ( p + 1 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " pos= " ) ;
sprintf ( s , " %.2f " , pos . x ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " ; " ) ;
sprintf ( s , " %.2f " , pos . z ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
}
2013-04-13 13:07:08 +00:00
if ( Cmd ( line , " EndMissionTake " ) | | Cmd ( line , " AudioChange " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char * p = strstr ( line , " pos= " ) ;
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector pos = OpPos ( line , " pos " ) ;
2012-06-26 20:23:05 +00:00
pos . x / = g_unit ;
pos . y / = g_unit ;
pos . z / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 4 ) ;
p = SkipNum ( p + 1 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " pos= " ) ;
sprintf ( s , " %.2f " , pos . x ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " ; " ) ;
sprintf ( s , " %.2f " , pos . z ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
strcpy ( line , lineNew ) ;
p = strstr ( line , " dist= " ) ;
2012-09-15 13:33:08 +00:00
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = OpFloat ( line , " dist " , 32.0f ) ;
2012-06-26 20:23:05 +00:00
value / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 5 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " dist= " ) ;
sprintf ( s , " %.2f " , value ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
strcpy ( line , lineNew ) ;
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Camera " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char * p = strstr ( line , " pos= " ) ;
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector pos = OpPos ( line , " pos " ) ;
2012-06-26 20:23:05 +00:00
pos . x / = g_unit ;
pos . y / = g_unit ;
pos . z / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 4 ) ;
p = SkipNum ( p + 1 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " pos= " ) ;
sprintf ( s , " %.2f " , pos . x ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " ; " ) ;
sprintf ( s , " %.2f " , pos . z ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
strcpy ( line , lineNew ) ;
p = strstr ( line , " h= " ) ;
2012-09-15 13:33:08 +00:00
if ( p ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = OpFloat ( line , " h " , 32.0f ) ;
2012-06-26 20:23:05 +00:00
value / = g_unit ;
p [ 0 ] = 0 ;
p = SkipNum ( p + 2 ) ;
strcpy ( lineNew , line ) ;
strcat ( lineNew , " h= " ) ;
sprintf ( s , " %.2f " , value ) ;
strcat ( lineNew , s ) ;
strcat ( lineNew , " " ) ;
strcat ( lineNew , p ) ;
}
strcpy ( line , lineNew ) ;
}
fputs ( lineNew , fileNew ) ;
}
fclose ( fileNew ) ;
fclose ( file ) ;
}
2012-09-15 13:33:08 +00:00
//! Load the scene for the character
2012-06-26 20:23:05 +00:00
void CRobotMain : : ScenePerso ( )
{
DeleteAllObjects ( ) ; // removes all the current 3D Scene
2013-10-13 12:44:12 +00:00
m_terrain - > FlushRelief ( ) ;
2012-12-26 19:58:02 +00:00
m_engine - > DeleteAllObjects ( ) ;
2013-03-31 11:06:38 +00:00
Gfx : : CModelManager : : GetInstancePointer ( ) - > DeleteAllModelCopies ( ) ;
2012-06-26 20:23:05 +00:00
m_terrain - > FlushBuildingLevel ( ) ;
m_terrain - > FlushFlyingLimit ( ) ;
2012-09-15 13:33:08 +00:00
m_lightMan - > FlushLights ( ) ;
m_particle - > FlushParticle ( ) ;
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
iMan - > Flush ( CLASS_OBJECT ) ;
iMan - > Flush ( CLASS_PHYSICS ) ;
iMan - > Flush ( CLASS_BRAIN ) ;
iMan - > Flush ( CLASS_PYRO ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetSceneName ( " perso " ) ;
m_dialog - > SetSceneRank ( 0 ) ;
CreateScene ( false , true , false ) ; // sets scene
m_engine - > SetDrawWorld ( false ) ; // does not draw anything on the interface
m_engine - > SetDrawFront ( true ) ; // draws on the human interface
2012-09-15 13:33:08 +00:00
CObject * obj = SearchHuman ( ) ;
if ( obj ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetDrawFront ( true ) ; // draws the interface
2012-06-26 20:23:05 +00:00
2012-09-17 22:01:00 +00:00
CMotionHuman * mh = static_cast < CMotionHuman * > ( obj - > GetMotion ( ) ) ;
2012-09-15 13:33:08 +00:00
if ( mh ! = nullptr )
2012-06-26 20:23:05 +00:00
mh - > StartDisplayPerso ( ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Creates the whole scene
void CRobotMain : : CreateScene ( bool soluce , bool fixScene , bool resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-26 20:57:43 +00:00
char * base = m_dialog - > GetSceneName ( ) ;
int rank = m_dialog - > GetSceneRank ( ) ;
const char * read = m_dialog - > GetSceneRead ( ) . c_str ( ) ;
const char * stack = m_dialog - > GetStackRead ( ) . c_str ( ) ;
2012-06-26 20:23:05 +00:00
m_dialog - > SetUserDir ( base , rank ) ;
2012-09-22 15:36:10 +00:00
/*
* TODO : original code relying on UserDir ( ) was removed .
* A new way of providing custom data file paths will need to be devised .
*/
2012-09-15 13:33:08 +00:00
m_fixScene = fixScene ;
2012-06-26 20:23:05 +00:00
g_id = 0 ;
2012-09-15 13:33:08 +00:00
m_base = false ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! resetObject )
2012-06-26 20:23:05 +00:00
{
g_build = 0 ;
g_researchDone = 0 ; // no research done
g_researchEnable = 0 ;
FlushDisplayInfo ( ) ;
2012-09-15 13:33:08 +00:00
m_terrain - > FlushMaterials ( ) ;
2013-04-13 14:35:35 +00:00
m_audioTrack = " " ;
2012-09-15 13:33:08 +00:00
m_audioRepeat = true ;
2012-06-26 20:23:05 +00:00
m_displayText - > SetDelay ( 1.0f ) ;
m_displayText - > SetEnable ( true ) ;
2012-09-15 13:33:08 +00:00
m_immediatSatCom = false ;
2013-03-27 21:20:50 +00:00
m_lockedSatCom = false ;
2012-06-26 20:23:05 +00:00
m_endingWinRank = 0 ;
m_endingLostRank = 0 ;
2013-04-13 09:44:16 +00:00
m_audioChangeTotal = 0 ;
2012-06-26 20:23:05 +00:00
m_endTakeTotal = 0 ;
m_endTakeResearch = 0 ;
2013-04-28 16:33:59 +00:00
m_endTakeNever = false ;
2012-06-26 20:23:05 +00:00
m_endTakeWinDelay = 2.0f ;
m_endTakeLostDelay = 2.0f ;
m_obligatoryTotal = 0 ;
m_prohibitedTotal = 0 ;
2012-09-15 13:33:08 +00:00
m_mapShow = true ;
m_mapImage = false ;
2012-06-26 20:23:05 +00:00
m_mapFilename [ 0 ] = 0 ;
2013-04-29 15:26:32 +00:00
m_controller = nullptr ;
2012-06-26 20:23:05 +00:00
m_colorRefBot . r = 10.0f / 256.0f ;
m_colorRefBot . g = 166.0f / 256.0f ;
m_colorRefBot . b = 254.0f / 256.0f ; // blue
m_colorRefBot . a = 0.0f ;
m_colorNewBot = m_colorRefBot ;
m_colorRefAlien . r = 135.0f / 256.0f ;
m_colorRefAlien . g = 170.0f / 256.0f ;
m_colorRefAlien . b = 13.0f / 256.0f ; // green
m_colorRefAlien . a = 0.0f ;
m_colorNewAlien = m_colorRefAlien ;
m_colorRefGreen . r = 135.0f / 256.0f ;
m_colorRefGreen . g = 170.0f / 256.0f ;
m_colorRefGreen . b = 13.0f / 256.0f ; // green
m_colorRefGreen . a = 0.0f ;
m_colorNewGreen = m_colorRefGreen ;
m_colorRefWater . r = 25.0f / 256.0f ;
m_colorRefWater . g = 255.0f / 256.0f ;
m_colorRefWater . b = 240.0f / 256.0f ; // cyan
m_colorRefWater . a = 0.0f ;
m_colorNewWater = m_colorRefWater ;
m_dialog - > BuildResumeName ( m_title , base , rank ) ;
m_dialog - > BuildResumeName ( m_resume , base , rank ) ;
2013-12-02 23:11:26 +00:00
std : : string scriptNameStr ;
GetResource ( RES_TEXT , RT_SCRIPT_NEW , scriptNameStr ) ;
strcpy ( m_scriptName , scriptNameStr . c_str ( ) ) ;
2012-06-26 20:23:05 +00:00
m_scriptFile [ 0 ] = 0 ;
2013-03-23 18:04:41 +00:00
m_beginObject = false ;
m_terrainGenerate = false ;
m_terrainInit = false ;
m_terrainInitTextures = false ;
m_terrainCreate = false ;
2013-03-24 15:35:00 +00:00
m_version = 1 ;
2013-03-23 18:04:41 +00:00
m_retroStyle = false ;
2013-04-30 19:43:59 +00:00
m_missionResult = ERR_MISSION_NOTERM ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
char line [ 500 ] ;
char name [ 200 ] ;
char dir [ 100 ] ;
char op [ 100 ] ;
2013-03-23 18:04:41 +00:00
char filename [ 500 ] ;
int lineNum = 0 ;
2012-09-15 13:33:08 +00:00
2012-09-20 22:01:03 +00:00
memset ( line , 0 , 500 ) ;
memset ( name , 0 , 200 ) ;
memset ( dir , 0 , 100 ) ;
memset ( op , 0 , 100 ) ;
2013-03-23 18:04:41 +00:00
memset ( filename , 0 , 500 ) ;
2012-09-26 20:57:43 +00:00
std : : string tempLine ;
m_dialog - > BuildSceneName ( tempLine , base , rank ) ;
2013-03-23 18:04:41 +00:00
strcpy ( filename , tempLine . c_str ( ) ) ;
FILE * file = fopen ( filename , " r " ) ;
2012-09-15 13:33:08 +00:00
if ( file = = NULL ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int rankObj = 0 ;
int rankGadget = 0 ;
CObject * sel = 0 ;
2013-02-28 21:56:44 +00:00
2013-04-01 16:24:12 +00:00
SetNumericLocale ( ) ;
2012-06-26 20:23:05 +00:00
2013-05-05 18:33:49 +00:00
/*
* NOTE : Moving frequently used lines to the top
* may speed up loading
*/
2012-09-15 13:33:08 +00:00
while ( fgets ( line , 500 , file ) ! = NULL )
2012-06-26 20:23:05 +00:00
{
2013-03-23 18:04:41 +00:00
lineNum + + ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 500 ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( line [ i ] = = ' \t ' ) line [ i ] = ' ' ; // replace tab by space
if ( line [ i ] = = ' / ' & & line [ i + 1 ] = = ' / ' )
2012-06-26 20:23:05 +00:00
{
line [ i ] = 0 ;
break ;
}
}
2013-03-23 18:04:41 +00:00
if ( Cmd ( line , " MissionFile " ) & & ! resetObject )
m_version = OpInt ( line , " version " , 1 ) ;
2012-12-28 22:06:12 +00:00
// TODO: Fallback to an non-localized entry
sprintf ( op , " Title.%c " , m_app - > GetLanguageChar ( ) ) ;
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , op ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
OpString ( line , " text " , m_title ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-12-28 22:06:12 +00:00
sprintf ( op , " Resume.%c " , m_app - > GetLanguageChar ( ) ) ;
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , op ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
OpString ( line , " text " , m_resume ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-12-28 22:06:12 +00:00
sprintf ( op , " ScriptName.%c " , m_app - > GetLanguageChar ( ) ) ;
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , op ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
OpString ( line , " text " , m_scriptName ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2013-05-05 18:51:08 +00:00
if ( Cmd ( line , " Title " ) ) continue ; // Ignore
if ( Cmd ( line , " Resume " ) ) continue ; // Ignore
if ( Cmd ( line , " ScriptName " ) ) continue ; // Ignore
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " ScriptFile " ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
OpString ( line , " name " , m_scriptFile ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Instructions " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " name " , name ) ;
2012-09-22 15:36:10 +00:00
std : : string path = m_app - > GetDataFilePath ( DIR_HELP , name ) ;
strcpy ( m_infoFilename [ SATCOM_HUSTON ] , path . c_str ( ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_immediatSatCom = OpInt ( line , " immediat " , 0 ) ;
2013-05-26 15:47:54 +00:00
if ( m_version > = 2 ) m_beginSatCom = m_lockedSatCom = OpInt ( line , " lock " , 0 ) ;
2013-12-26 21:33:17 +00:00
if ( m_app - > GetSceneTestMode ( ) ) m_immediatSatCom = false ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Satellite " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " name " , name ) ;
2012-09-22 15:36:10 +00:00
std : : string path = m_app - > GetDataFilePath ( DIR_HELP , name ) ;
strcpy ( m_infoFilename [ SATCOM_SAT ] , path . c_str ( ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Loading " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " name " , name ) ;
2012-09-22 15:36:10 +00:00
std : : string path = m_app - > GetDataFilePath ( DIR_HELP , name ) ;
strcpy ( m_infoFilename [ SATCOM_LOADING ] , path . c_str ( ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " HelpFile " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " name " , name ) ;
2012-09-22 15:36:10 +00:00
std : : string path = m_app - > GetDataFilePath ( DIR_HELP , name ) ;
strcpy ( m_infoFilename [ SATCOM_PROG ] , path . c_str ( ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " SoluceFile " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " name " , name ) ;
2012-09-22 15:36:10 +00:00
std : : string path = m_app - > GetDataFilePath ( DIR_HELP , name ) ;
strcpy ( m_infoFilename [ SATCOM_SOLUCE ] , path . c_str ( ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " EndingFile " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
m_endingWinRank = OpInt ( line , " win " , 0 ) ;
m_endingLostRank = OpInt ( line , " lost " , 0 ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " MessageDelay " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
m_displayText - > SetDelay ( OpFloat ( line , " factor " , 1.0f ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-02 08:53:18 +00:00
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " CacheAudio " ) & & ! resetObject & & m_version > = 2 )
2013-05-02 08:53:18 +00:00
{
2013-06-10 13:44:25 +00:00
OpString ( line , " filename " , name ) ;
m_sound - > CacheMusic ( name ) ;
2013-05-02 08:53:18 +00:00
continue ;
}
2013-05-26 15:47:54 +00:00
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " AudioChange " ) & & ! resetObject & & m_version > = 2 & & m_controller = = nullptr )
2013-04-13 09:44:16 +00:00
{
int i = m_audioChangeTotal ;
if ( i < 10 )
{
2013-04-20 10:08:48 +00:00
m_audioChange [ i ] . pos = OpPos ( line , " pos " ) * g_unit ;
2013-12-25 17:53:32 +00:00
m_audioChange [ i ] . dist = OpFloat ( line , " dist " , 1000.0f ) * g_unit ;
2013-04-20 10:08:48 +00:00
m_audioChange [ i ] . type = OpTypeObject ( line , " type " , OBJECT_NULL ) ;
m_audioChange [ i ] . min = OpInt ( line , " min " , 1 ) ;
m_audioChange [ i ] . max = OpInt ( line , " max " , 9999 ) ;
2013-12-25 17:53:32 +00:00
m_audioChange [ i ] . powermin = OpFloat ( line , " powermin " , - 1 ) ;
m_audioChange [ i ] . powermax = OpFloat ( line , " powermax " , 100 ) ;
2013-12-29 14:03:21 +00:00
m_audioChange [ i ] . tool = OpTool ( line , " tool " ) ;
m_audioChange [ i ] . drive = OpDrive ( line , " drive " ) ;
2013-04-13 09:44:16 +00:00
OpString ( line , " filename " , m_audioChange [ i ] . music ) ;
2013-04-20 10:08:48 +00:00
m_audioChange [ i ] . repeat = OpInt ( line , " repeat " , 1 ) ;
m_audioChange [ i ] . changed = false ;
2013-04-13 14:06:35 +00:00
m_sound - > CacheMusic ( m_audioChange [ i ] . music ) ;
2013-04-13 09:44:16 +00:00
m_audioChangeTotal + + ;
}
2013-04-26 13:55:06 +00:00
continue ;
2013-04-13 09:44:16 +00:00
}
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " Audio " ) & & ! resetObject & & m_controller = = nullptr )
2013-04-26 13:34:02 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_version < 2 )
{
2013-04-26 13:34:02 +00:00
int trackid = OpInt ( line , " track " , 0 ) ;
2013-05-26 15:47:54 +00:00
if ( trackid ! = 0 )
{
2013-05-27 20:26:44 +00:00
std : : stringstream filenameStr ;
filenameStr < < " music " < < std : : setfill ( ' 0 ' ) < < std : : setw ( 3 ) < < trackid < < " .ogg " ;
m_audioTrack = filenameStr . str ( ) ;
2013-04-26 13:34:02 +00:00
}
2013-05-26 15:47:54 +00:00
}
else
{
2013-04-26 13:34:02 +00:00
char trackname [ 100 ] ;
OpString ( line , " filename " , trackname ) ;
m_audioTrack = trackname ;
}
m_audioRepeat = OpInt ( line , " repeat " , 1 ) ;
2013-05-26 15:47:54 +00:00
if ( m_audioTrack ! = " " ) m_sound - > CacheMusic ( m_audioTrack ) ;
2013-05-05 18:33:49 +00:00
continue ;
2013-04-26 13:34:02 +00:00
}
2013-04-13 09:44:16 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " AmbientColor " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetAmbientColor ( OpColor ( line , " air " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 0 ) ;
m_engine - > SetAmbientColor ( OpColor ( line , " water " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 1 ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " FogColor " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_engine - > SetFogColor ( OpColor ( line , " air " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 0 ) ;
m_engine - > SetFogColor ( OpColor ( line , " water " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 1 ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " VehicleColor " ) & & ! resetObject )
{
2012-09-15 13:33:08 +00:00
m_colorNewBot = OpColor ( line , " color " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " InsectColor " ) & & ! resetObject )
{
2012-09-15 13:33:08 +00:00
m_colorNewAlien = OpColor ( line , " color " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " GreeneryColor " ) & & ! resetObject )
{
2012-09-15 13:33:08 +00:00
m_colorNewGreen = OpColor ( line , " color " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " DeepView " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-10-05 18:37:20 +00:00
m_engine - > SetDeepView ( OpFloat ( line , " air " , 500.0f ) * g_unit , 0 , true ) ;
m_engine - > SetDeepView ( OpFloat ( line , " water " , 100.0f ) * g_unit , 1 , true ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " FogStart " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
m_engine - > SetFogStart ( OpFloat ( line , " air " , 0.5f ) , 0 ) ;
m_engine - > SetFogStart ( OpFloat ( line , " water " , 0.5f ) , 1 ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " SecondTexture " ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
m_engine - > SetSecondTexture ( OpInt ( line , " rank " , 1 ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Background " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " image " , name ) ;
2012-09-22 15:36:10 +00:00
m_engine - > SetBackground ( name ,
2012-09-15 13:33:08 +00:00
OpColor ( line , " up " , Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ,
OpColor ( line , " down " , Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ,
OpColor ( line , " cloudUp " , Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ,
OpColor ( line , " cloudDown " , Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ,
2012-06-26 20:23:05 +00:00
OpInt ( line , " full " , 0 ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Planet " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
Math : : Vector ppos , uv1 , uv2 ;
ppos = OpPos ( line , " pos " ) ;
uv1 = OpPos ( line , " uv1 " ) ;
uv2 = OpPos ( line , " uv2 " ) ;
OpString ( line , " image " , name ) ;
m_planet - > Create ( OpInt ( line , " mode " , 0 ) ,
Math : : Point ( ppos . x , ppos . z ) ,
OpFloat ( line , " dim " , 0.2f ) ,
OpFloat ( line , " speed " , 0.0f ) ,
OpFloat ( line , " dir " , 0.0f ) ,
2012-09-22 15:36:10 +00:00
name ,
2012-06-26 20:23:05 +00:00
Math : : Point ( uv1 . x , uv1 . z ) ,
2012-09-26 21:18:57 +00:00
Math : : Point ( uv2 . x , uv2 . z ) ,
strstr ( name , " planet " ) ! = nullptr // TODO: add transparent op or modify textures
) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-27 18:36:52 +00:00
if ( Cmd ( line , " ForegroundName " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " image " , name ) ;
2012-09-22 15:36:10 +00:00
m_engine - > SetForegroundName ( name ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-03-23 18:04:41 +00:00
if ( ( ( m_version = = 1 & & Cmd ( line , " Global " ) ) | | ( m_version > = 2 & & Cmd ( line , " Mission " ) ) ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
g_unit = OpFloat ( line , " unitScale " , 4.0f ) ;
m_engine - > SetTracePrecision ( OpFloat ( line , " traceQuality " , 1.0f ) ) ;
2012-09-15 13:33:08 +00:00
m_shortCut = OpInt ( line , " shortcut " , 1 ) ;
2013-05-26 15:47:54 +00:00
if ( m_version > = 2 )
{
2013-03-23 18:04:41 +00:00
m_retroStyle = OpInt ( line , " retro " , 0 ) ;
2013-05-26 15:47:54 +00:00
if ( m_retroStyle ) GetLogger ( ) - > Info ( " Retro mode enabled. \n " ) ;
2013-03-23 18:04:41 +00:00
}
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainGenerate " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_terrainCreate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainGenerate after TerrainCreate \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainGenerate after TerrainInit \n " , filename , lineNum ) ;
continue ;
}
2012-06-26 20:23:05 +00:00
m_terrain - > Generate ( OpInt ( line , " mosaic " , 20 ) ,
OpInt ( line , " brick " , 3 ) ,
OpFloat ( line , " size " , 20.0f ) ,
2012-10-05 18:37:20 +00:00
OpFloat ( line , " vision " , 500.0f ) * g_unit ,
2012-06-26 20:23:05 +00:00
OpInt ( line , " depth " , 2 ) ,
OpFloat ( line , " hard " , 0.5f ) ) ;
2013-03-23 18:04:41 +00:00
m_terrainGenerate = true ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " TerrainWind " ) & & ! resetObject )
{
if ( m_terrainCreate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainWind after TerrainCreate \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainWind after TerrainInit \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( ! m_terrainGenerate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainWind before TerrainGenerate \n " , filename , lineNum ) ;
continue ;
}
2012-06-26 20:23:05 +00:00
m_terrain - > SetWind ( OpPos ( line , " speed " ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2013-03-23 18:04:41 +00:00
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainRelief " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_terrainCreate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainRelief after TerrainCreate \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainRelief after TerrainInit \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( ! m_terrainGenerate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainRelief before TerrainGenerate \n " , filename , lineNum ) ;
continue ;
}
2012-06-26 20:23:05 +00:00
OpString ( line , " image " , name ) ;
2012-09-22 15:36:10 +00:00
m_terrain - > LoadRelief ( name , OpFloat ( line , " factor " , 1.0f ) , OpInt ( line , " border " , 1 ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainResource " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_terrainCreate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainResource after TerrainCreate \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainResource after TerrainInit \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( ! m_terrainGenerate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainResource before TerrainGenerate \n " , filename , lineNum ) ;
continue ;
}
2012-06-26 20:23:05 +00:00
OpString ( line , " image " , name ) ;
2012-09-22 15:36:10 +00:00
m_terrain - > LoadResources ( name ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainWater " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " image " , name ) ;
2012-09-15 13:33:08 +00:00
Math : : Vector pos ;
2012-06-26 20:23:05 +00:00
pos . x = OpFloat ( line , " moveX " , 0.0f ) ;
pos . y = OpFloat ( line , " moveY " , 0.0f ) ;
pos . z = pos . x ;
2012-09-15 13:33:08 +00:00
m_water - > Create ( OpTypeWater ( line , " air " , Gfx : : WATER_TT ) ,
OpTypeWater ( line , " water " , Gfx : : WATER_TT ) ,
2012-09-22 15:36:10 +00:00
name ,
2012-09-15 13:33:08 +00:00
OpColor ( line , " diffuse " , Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
2012-09-27 18:36:52 +00:00
OpColor ( line , " ambient " , Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
2012-10-05 18:37:20 +00:00
OpFloat ( line , " level " , 100.0f ) * g_unit ,
2012-06-26 20:23:05 +00:00
OpFloat ( line , " glint " , 1.0f ) ,
pos ) ;
2012-09-15 13:33:08 +00:00
m_colorNewWater = OpColor ( line , " color " , m_colorRefWater ) ;
2012-06-26 20:23:05 +00:00
m_colorShiftWater = OpFloat ( line , " brightness " , 0.0f ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " TerrainLava " ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
m_water - > SetLava ( OpInt ( line , " mode " , 0 ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainCloud " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " image " , name ) ;
2012-09-22 15:36:10 +00:00
m_cloud - > Create ( name ,
2012-09-15 13:33:08 +00:00
OpColor ( line , " diffuse " , Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
2012-09-27 18:36:52 +00:00
OpColor ( line , " ambient " , Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
2012-10-05 18:37:20 +00:00
OpFloat ( line , " level " , 500.0f ) * g_unit ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainBlitz " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_lightning - > Create ( OpFloat ( line , " sleep " , 0.0f ) ,
2012-06-26 20:23:05 +00:00
OpFloat ( line , " delay " , 3.0f ) ,
2012-10-05 18:37:20 +00:00
OpFloat ( line , " magnetic " , 50.0f ) * g_unit ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainInitTextures " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainInitTextures and TerrainInit at same time \n " , filename , lineNum ) ;
continue ;
}
2012-06-26 20:23:05 +00:00
OpString ( line , " image " , name ) ;
2012-09-15 13:33:08 +00:00
AddExt ( name , " .png " ) ;
int dx = OpInt ( line , " dx " , 1 ) ;
int dy = OpInt ( line , " dy " , 1 ) ;
2013-05-27 20:26:44 +00:00
char * opTable = SearchOp ( line , " table " ) ;
2012-09-15 13:33:08 +00:00
int tt [ 100 ] ;
for ( int i = 0 ; i < dx * dy ; i + + )
2013-05-27 20:26:44 +00:00
tt [ i ] = GetInt ( opTable , i , 0 ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( strstr ( name , " %user% " ) ! = 0 )
2012-06-26 20:23:05 +00:00
CopyFileListToTemp ( name , tt , dx * dy ) ;
m_terrain - > InitTextures ( name , tt , dx , dy ) ;
2013-03-23 18:04:41 +00:00
m_terrainInitTextures = true ;
2013-04-27 11:43:01 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " TerrainInit " ) & & ! resetObject )
{
if ( m_terrainInitTextures )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainInit and TerrainInitTextures at same time \n " , filename , lineNum ) ;
continue ;
}
2012-09-15 13:33:08 +00:00
m_terrain - > InitMaterials ( OpInt ( line , " id " , 1 ) ) ;
2013-03-23 18:04:41 +00:00
m_terrainInit = true ;
2013-05-05 18:33:49 +00:00
continue ;
2013-03-23 18:04:41 +00:00
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainMaterial " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_terrainCreate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainMaterial after TerrainCreate \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainMaterial after TerrainInit \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInitTextures )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainMaterial and TerrainInitTextures at same time \n " , filename , lineNum ) ;
continue ;
}
2012-06-26 20:23:05 +00:00
OpString ( line , " image " , name ) ;
2012-09-15 13:33:08 +00:00
AddExt ( name , " .png " ) ;
2013-05-26 15:47:54 +00:00
if ( strstr ( name , " %user% " ) ! = 0 )
{
2013-03-17 18:01:32 +00:00
GetProfile ( ) . CopyFileToTemp ( std : : string ( name ) ) ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_terrain - > AddMaterial ( OpInt ( line , " id " , 0 ) ,
name ,
Math : : Point ( OpFloat ( line , " u " , 0.0f ) ,
OpFloat ( line , " v " , 0.0f ) ) ,
OpInt ( line , " up " , 1 ) ,
OpInt ( line , " right " , 1 ) ,
OpInt ( line , " down " , 1 ) ,
OpInt ( line , " left " , 1 ) ,
OpFloat ( line , " hard " , 0.5f ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " TerrainLevel " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_terrainCreate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainLevel after TerrainCreate \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( ! m_terrainInit )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainLevel before TerrainInit \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( m_terrainInitTextures )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainLevel and TerrainInitTextures at same time \n " , filename , lineNum ) ;
continue ;
}
2013-05-26 15:47:54 +00:00
if ( ! m_terrainGenerate )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): TerrainLevel before TerrainGenerate \n " , filename , lineNum ) ;
continue ;
}
2013-05-27 20:26:44 +00:00
char * opId = SearchOp ( line , " id " ) ;
2012-09-15 13:33:08 +00:00
int id [ 50 ] ;
int i = 0 ;
while ( i < 50 )
2012-06-26 20:23:05 +00:00
{
2013-05-27 20:26:44 +00:00
id [ i ] = GetInt ( opId , i , 0 ) ;
2012-09-15 13:33:08 +00:00
if ( id [ i + + ] = = 0 ) break ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
m_terrain - > GenerateMaterials ( id ,
2012-10-05 18:37:20 +00:00
OpFloat ( line , " min " , 0.0f ) * g_unit ,
OpFloat ( line , " max " , 100.0f ) * g_unit ,
2012-09-15 13:33:08 +00:00
OpFloat ( line , " slope " , 5.0f ) ,
OpFloat ( line , " freq " , 100.0f ) ,
OpPos ( line , " center " ) * g_unit ,
OpFloat ( line , " radius " , 0.0f ) * g_unit ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " TerrainCreate " ) & & ! resetObject )
{
2012-09-15 13:33:08 +00:00
m_terrain - > CreateObjects ( ) ;
2013-03-23 18:04:41 +00:00
m_terrainCreate = true ;
2013-05-05 18:33:49 +00:00
continue ;
2013-03-23 18:04:41 +00:00
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " BeginObject " ) )
2012-06-26 20:23:05 +00:00
{
InitEye ( ) ;
SetMovieLock ( false ) ;
2012-09-15 13:33:08 +00:00
if ( read [ 0 ] ! = 0 ) // loading file ?
sel = IOReadScene ( read , stack ) ;
2013-03-23 18:04:41 +00:00
m_beginObject = true ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " MissionController " ) & & read [ 0 ] = = 0 & & m_version > = 2 )
2013-04-28 18:05:19 +00:00
{
2013-12-29 11:08:59 +00:00
m_controller = CObjectManager : : GetInstancePointer ( ) - > CreateObject ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 0.0f , OBJECT_CONTROLLER , 100.0f ) ;
2013-04-29 15:26:32 +00:00
m_controller - > SetMagnifyDamage ( 100.0f ) ;
CBrain * brain = m_controller - > GetBrain ( ) ;
2013-04-28 18:05:19 +00:00
if ( brain ! = nullptr )
{
OpString ( line , " script " , name ) ;
if ( name [ 0 ] ! = 0 )
2013-04-29 15:26:32 +00:00
brain - > SetScriptName ( 0 , name ) ;
brain - > SetScriptRun ( 0 ) ;
2013-04-28 18:05:19 +00:00
}
2013-05-05 18:33:49 +00:00
continue ;
2013-04-28 18:05:19 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateObject " ) & & read [ 0 ] = = 0 )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( ! m_beginObject )
{
2013-03-23 18:04:41 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): CreateObject before BeginObject \n " , filename , lineNum ) ;
continue ;
}
2012-09-15 13:33:08 +00:00
ObjectType type = OpTypeObject ( line , " type " , OBJECT_NULL ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int gadget = OpInt ( line , " gadget " , - 1 ) ;
2012-06-26 20:23:05 +00:00
if ( gadget = = - 1 )
{
gadget = 0 ;
if ( type = = OBJECT_TECH | |
( type > = OBJECT_PLANT0 & &
type < = OBJECT_PLANT19 ) | |
( type > = OBJECT_TREE0 & &
type < = OBJECT_TREE9 ) | |
( type > = OBJECT_TEEN0 & &
type < = OBJECT_TEEN49 ) | |
( type > = OBJECT_QUARTZ0 & &
type < = OBJECT_QUARTZ9 ) | |
( type > = OBJECT_ROOT0 & &
type < = OBJECT_ROOT4 ) ) // not ROOT5!
{
if ( type ! = OBJECT_TEEN11 & & // lamp?
type ! = OBJECT_TEEN12 & & // coke?
type ! = OBJECT_TEEN20 & & // wall?
type ! = OBJECT_TEEN21 & & // wall?
type ! = OBJECT_TEEN22 & & // wall?
type ! = OBJECT_TEEN26 & & // lamp?
type ! = OBJECT_TEEN28 & & // bottle?
type ! = OBJECT_TEEN34 ) // stone?
{
gadget = 1 ;
}
}
}
2012-09-15 13:33:08 +00:00
if ( gadget ! = 0 ) // is this a gadget?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! TestGadgetQuantity ( rankGadget + + ) ) continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
Math : : Vector pos = OpPos ( line , " pos " ) * g_unit ;
2013-05-27 20:26:44 +00:00
float dirAngle = OpFloat ( line , " dir " , 0.0f ) * Math : : PI ;
2013-12-29 11:08:59 +00:00
bool trainer ;
CObject * obj = CObjectManager : : GetInstancePointer ( ) - > CreateObject (
pos , dirAngle ,
2012-09-15 13:33:08 +00:00
type ,
OpFloat ( line , " power " , 1.0f ) ,
2013-12-29 11:08:59 +00:00
OpFloat ( line , " z " , 1.0f ) ,
OpFloat ( line , " h " , 0.0f ) ,
trainer = OpInt ( line , " trainer " , 0 ) ,
2012-09-15 13:33:08 +00:00
OpInt ( line , " toy " , 0 ) ,
OpInt ( line , " option " , 0 ) ) ;
if ( obj ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetDefRank ( rankObj ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( type = = OBJECT_BASE ) m_base = true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Gfx : : CameraType cType = OpCamera ( line , " camera " ) ;
if ( cType ! = Gfx : : CAM_TYPE_NULL )
obj - > SetCameraType ( cType ) ;
obj - > SetCameraDist ( OpFloat ( line , " cameraDist " , 50.0f ) ) ;
obj - > SetCameraLock ( OpInt ( line , " cameraLock " , 0 ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Gfx : : PyroType pType = OpPyro ( line , " pyro " ) ;
if ( pType ! = Gfx : : PT_NULL )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
Gfx : : CPyro * pyro = new Gfx : : CPyro ( ) ;
2012-09-15 13:33:08 +00:00
pyro - > Create ( pType , obj ) ;
2012-06-26 20:23:05 +00:00
}
// Puts information in terminal (OBJECT_INFO).
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < OBJECTMAXINFO ; i + + )
2012-06-26 20:23:05 +00:00
{
sprintf ( op , " info%d " , i + 1 ) ;
2012-09-15 13:33:08 +00:00
char text [ 100 ] ;
2012-06-26 20:23:05 +00:00
OpString ( line , op , text ) ;
2012-09-15 13:33:08 +00:00
if ( text [ 0 ] = = 0 ) break ;
char * p = strchr ( text , ' = ' ) ;
if ( p = = 0 ) break ;
2012-06-26 20:23:05 +00:00
* p = 0 ;
2012-09-15 13:33:08 +00:00
Info info ;
2012-06-26 20:23:05 +00:00
strcpy ( info . name , text ) ;
sscanf ( p + 1 , " %f " , & info . value ) ;
2012-09-15 13:33:08 +00:00
obj - > SetInfo ( i , info ) ;
2012-06-26 20:23:05 +00:00
}
// Sets the parameters of the command line.
2012-09-15 13:33:08 +00:00
char * p = SearchOp ( line , " cmdline " ) ;
for ( int i = 0 ; i < OBJECTMAXCMDLINE ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float value = GetFloat ( p , i , NAN ) ;
if ( value = = NAN ) break ;
obj - > SetCmdLine ( i , value ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( OpInt ( line , " select " , 0 ) = = 1 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
sel = obj ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 11:43:05 +00:00
bool selectable = OpInt ( line , " selectable " , 1 ) ;
obj - > SetSelectable ( selectable ) ;
2012-09-15 13:33:08 +00:00
obj - > SetEnable ( OpInt ( line , " enable " , 1 ) ) ;
obj - > SetProxyActivate ( OpInt ( line , " proxyActivate " , 0 ) ) ;
obj - > SetProxyDistance ( OpFloat ( line , " proxyDistance " , 15.0f ) * g_unit ) ;
obj - > SetRange ( OpFloat ( line , " range " , 30.0f ) ) ;
obj - > SetShield ( OpFloat ( line , " shield " , 1.0f ) ) ;
obj - > SetMagnifyDamage ( OpFloat ( line , " magnifyDamage " , 1.0f ) ) ;
obj - > SetClip ( OpInt ( line , " clip " , 1 ) ) ;
2013-05-05 11:43:05 +00:00
obj - > SetCheckToken ( m_version > = 2 ? trainer | | ! selectable : OpInt ( line , " checkToken " , 1 ) ) ;
2013-04-27 11:43:01 +00:00
// SetManual will affect bot speed
2013-05-26 15:47:54 +00:00
if ( type = = OBJECT_MOBILEdr )
{
2013-04-27 11:43:01 +00:00
obj - > SetManual ( m_version > = 2 ? ! trainer : OpInt ( line , " manual " , 0 ) ) ;
}
2012-09-15 13:33:08 +00:00
2013-05-26 15:47:54 +00:00
if ( m_version > = 2 )
{
2013-03-27 18:55:27 +00:00
Math : : Vector zoom = OpDir ( line , " zoom " ) ;
if ( zoom . x ! = 0.0f | | zoom . y ! = 0.0f | | zoom . z ! = 0.0f )
obj - > SetZoom ( 0 , zoom ) ;
}
2013-03-25 15:12:18 +00:00
2012-09-15 13:33:08 +00:00
CMotion * motion = obj - > GetMotion ( ) ;
if ( motion ! = nullptr )
2012-06-26 20:23:05 +00:00
{
p = SearchOp ( line , " param " ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 10 ; i + + )
2012-06-26 20:23:05 +00:00
{
float value ;
value = GetFloat ( p , i , NAN ) ;
2012-09-15 13:33:08 +00:00
if ( value = = NAN ) break ;
2012-06-26 20:23:05 +00:00
motion - > SetParam ( i , value ) ;
}
}
2012-09-15 13:33:08 +00:00
int run = - 1 ;
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 10 ; i + + )
2012-06-26 20:23:05 +00:00
{
sprintf ( op , " script%d " , i + 1 ) ; // script1..script10
OpString ( line , op , name ) ;
2012-09-15 13:33:08 +00:00
/* TODO: #if _SCHOOL
if ( ! m_dialog - > GetSoluce4 ( ) & & i = = 3 ) continue ;
# endif* /
if ( name [ 0 ] ! = 0 )
brain - > SetScriptName ( i , name ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
int i = OpInt ( line , " run " , 0 ) ;
if ( i ! = 0 )
2012-06-26 20:23:05 +00:00
{
run = i - 1 ;
2012-09-15 13:33:08 +00:00
brain - > SetScriptRun ( run ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
CAuto * automat = obj - > GetAuto ( ) ;
if ( automat ! = nullptr )
2012-06-26 20:23:05 +00:00
{
type = OpTypeObject ( line , " autoType " , OBJECT_NULL ) ;
2012-09-15 13:33:08 +00:00
automat - > SetType ( type ) ;
for ( int i = 0 ; i < 5 ; i + + )
2012-06-26 20:23:05 +00:00
{
sprintf ( op , " autoValue%d " , i + 1 ) ; // autoValue1..autoValue5
2012-09-15 13:33:08 +00:00
automat - > SetValue ( i , OpFloat ( line , op , 0.0f ) ) ;
2012-06-26 20:23:05 +00:00
}
OpString ( line , " autoString " , name ) ;
2012-09-15 13:33:08 +00:00
automat - > SetString ( name ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int i = OpInt ( line , " run " , - 1 ) ;
if ( i ! = - 1 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( i ! = PARAM_FIXSCENE & &
! m_dialog - > GetMovies ( ) ) i = 0 ;
automat - > Start ( i ) ; // starts the film
2012-06-26 20:23:05 +00:00
}
}
OpString ( line , " soluce " , name ) ;
2012-09-15 13:33:08 +00:00
if ( soluce & & brain ! = 0 & & name [ 0 ] ! = 0 )
brain - > SetSoluceName ( name ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > SetResetPosition ( obj - > GetPosition ( 0 ) ) ;
obj - > SetResetAngle ( obj - > GetAngle ( 0 ) ) ;
obj - > SetResetRun ( run ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( OpInt ( line , " reset " , 0 ) = = 1 )
obj - > SetResetCap ( RESET_MOVE ) ;
2012-06-26 20:23:05 +00:00
}
rankObj + + ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateFog " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Gfx : : ParticleType type = static_cast < Gfx : : ParticleType > ( ( Gfx : : PARTIFOG0 + OpInt ( line , " type " , 0 ) ) ) ;
Math : : Vector pos = OpPos ( line , " pos " ) * g_unit ;
float height = OpFloat ( line , " height " , 1.0f ) * g_unit ;
float ddim = OpFloat ( line , " dim " , 50.0f ) * g_unit ;
float delay = OpFloat ( line , " delay " , 2.0f ) ;
m_terrain - > AdjustToFloor ( pos ) ;
2012-06-26 20:23:05 +00:00
pos . y + = height ;
2012-09-15 13:33:08 +00:00
Math : : Point dim ;
2012-06-26 20:23:05 +00:00
dim . x = ddim ;
dim . y = dim . x ;
2012-09-10 21:29:38 +00:00
m_particle - > CreateParticle ( pos , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , dim , type , delay , 0.0f , 0.0f ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateLight " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Gfx : : EngineObjectType type ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int lightRank = CreateLight ( OpDir ( line , " dir " ) ,
OpColor ( line , " color " , Gfx : : Color ( 0.5f , 0.5f , 0.5f , 1.0f ) ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
type = OpTypeTerrain ( line , " type " , Gfx : : ENG_OBJTYPE_NULL ) ;
if ( type = = Gfx : : ENG_OBJTYPE_TERRAIN )
2013-06-20 21:14:37 +00:00
{
m_lightMan - > SetLightPriority ( lightRank , Gfx : : LIGHT_PRI_HIGHEST ) ;
2012-09-15 13:33:08 +00:00
m_lightMan - > SetLightIncludeType ( lightRank , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2013-06-20 21:14:37 +00:00
}
2012-09-15 13:33:08 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_QUARTZ )
m_lightMan - > SetLightIncludeType ( lightRank , Gfx : : ENG_OBJTYPE_QUARTZ ) ;
if ( type = = Gfx : : ENG_OBJTYPE_METAL )
m_lightMan - > SetLightIncludeType ( lightRank , Gfx : : ENG_OBJTYPE_METAL ) ;
if ( type = = Gfx : : ENG_OBJTYPE_FIX )
m_lightMan - > SetLightExcludeType ( lightRank , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateSpot " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Gfx : : EngineObjectType type ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int rankLight = CreateSpot ( OpDir ( line , " pos " ) * g_unit ,
OpColor ( line , " color " , Gfx : : Color ( 0.5f , 0.5f , 0.5f , 1.0f ) ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
type = OpTypeTerrain ( line , " type " , Gfx : : ENG_OBJTYPE_NULL ) ;
if ( type = = Gfx : : ENG_OBJTYPE_TERRAIN )
m_lightMan - > SetLightIncludeType ( rankLight , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
if ( type = = Gfx : : ENG_OBJTYPE_QUARTZ )
m_lightMan - > SetLightIncludeType ( rankLight , Gfx : : ENG_OBJTYPE_QUARTZ ) ;
if ( type = = Gfx : : ENG_OBJTYPE_METAL )
m_lightMan - > SetLightIncludeType ( rankLight , Gfx : : ENG_OBJTYPE_METAL ) ;
if ( type = = Gfx : : ENG_OBJTYPE_FIX )
m_lightMan - > SetLightExcludeType ( rankLight , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " GroundSpot " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
rank = m_engine - > CreateGroundSpot ( ) ;
if ( rank ! = - 1 )
2012-06-26 20:23:05 +00:00
{
m_engine - > SetObjectGroundSpotPos ( rank , OpPos ( line , " pos " ) * g_unit ) ;
m_engine - > SetObjectGroundSpotRadius ( rank , OpFloat ( line , " radius " , 10.0f ) * g_unit ) ;
2012-09-15 13:33:08 +00:00
m_engine - > SetObjectGroundSpotColor ( rank , OpColor ( line , " color " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ) ;
2012-06-26 20:23:05 +00:00
m_engine - > SetObjectGroundSpotSmooth ( rank , OpFloat ( line , " smooth " , 1.0f ) ) ;
m_engine - > SetObjectGroundSpotMinMax ( rank , OpFloat ( line , " min " , 0.0f ) * g_unit ,
OpFloat ( line , " max " , 0.0f ) * g_unit ) ;
}
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " WaterColor " ) & & ! resetObject )
{
2012-09-15 13:33:08 +00:00
m_engine - > SetWaterAddColor ( OpColor ( line , " color " , Gfx : : Color ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " MapColor " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_map - > FloorColorMap ( OpColor ( line , " floor " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ,
OpColor ( line , " water " , Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ) ;
m_mapShow = OpInt ( line , " show " , 1 ) ;
m_map - > ShowMap ( m_mapShow ) ;
2012-06-26 20:23:05 +00:00
m_map - > SetToy ( OpInt ( line , " toyIcon " , 0 ) ) ;
2012-09-15 13:33:08 +00:00
m_mapImage = OpInt ( line , " image " , 0 ) ;
if ( m_mapImage )
2012-06-26 20:23:05 +00:00
{
Math : : Vector offset ;
OpString ( line , " filename " , m_mapFilename ) ;
offset = OpPos ( line , " offset " ) ;
m_map - > SetFixParam ( OpFloat ( line , " zoom " , 1.0f ) ,
offset . x , offset . z ,
OpFloat ( line , " angle " , 0.0f ) * Math : : PI / 180.0f ,
OpInt ( line , " mode " , 0 ) ,
OpInt ( line , " debug " , 0 ) ) ;
}
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 18:33:49 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " MapZoom " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
m_map - > ZoomMap ( OpFloat ( line , " factor " , 2.0f ) ) ;
m_map - > MapEnable ( OpInt ( line , " enable " , 1 ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " MaxFlyingHeight " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
m_terrain - > SetFlyingMaxHeight ( OpFloat ( line , " max " , 280.0f ) * g_unit ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 18:33:49 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " AddFlyingHeight " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
m_terrain - > AddFlyingLimit ( OpPos ( line , " center " ) * g_unit ,
OpFloat ( line , " extRadius " , 20.0f ) * g_unit ,
OpFloat ( line , " intRadius " , 10.0f ) * g_unit ,
OpFloat ( line , " maxHeight " , 200.0f ) ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Camera " ) )
2012-06-26 20:23:05 +00:00
{
m_camera - > Init ( OpDir ( line , " eye " ) * g_unit ,
OpDir ( line , " lookat " ) * g_unit ,
2012-09-15 13:33:08 +00:00
resetObject ? 0.0f : OpFloat ( line , " delay " , 0.0f ) ) ;
if ( OpInt ( line , " fadeIn " , 0 ) = = 1 )
m_camera - > StartOver ( Gfx : : CAM_OVER_EFFECT_FADEIN_WHITE , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 1.0f ) ;
2012-06-26 20:23:05 +00:00
m_camera - > SetFixDirection ( OpFloat ( line , " fixDirection " , 0.25f ) * Math : : PI ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " EndMissionTake " ) & & ! resetObject & & m_controller = = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int i = m_endTakeTotal ;
if ( i < 10 )
2012-06-26 20:23:05 +00:00
{
2013-04-20 10:08:48 +00:00
m_endTake [ i ] . pos = OpPos ( line , " pos " ) * g_unit ;
2013-12-25 17:53:32 +00:00
m_endTake [ i ] . dist = OpFloat ( line , " dist " , ( m_version < 2 ? 8.0f : 100.0f ) ) * g_unit ;
2013-04-20 10:08:48 +00:00
m_endTake [ i ] . type = OpTypeObject ( line , " type " , OBJECT_NULL ) ;
m_endTake [ i ] . min = OpInt ( line , " min " , 1 ) ;
m_endTake [ i ] . max = OpInt ( line , " max " , 9999 ) ;
2013-05-26 15:47:54 +00:00
if ( m_version > = 2 )
{
2013-12-25 17:53:32 +00:00
m_endTake [ i ] . powermin = OpFloat ( line , " powermin " , - 1 ) ;
m_endTake [ i ] . powermax = OpFloat ( line , " powermax " , 100 ) ;
2013-12-29 14:03:21 +00:00
m_endTake [ i ] . tool = OpTool ( line , " tool " ) ;
m_endTake [ i ] . drive = OpDrive ( line , " drive " ) ;
2013-05-26 15:47:54 +00:00
}
else
{
m_endTake [ i ] . powermin = - 1 ;
m_endTake [ i ] . powermax = 100 ;
2013-12-29 14:03:21 +00:00
m_endTake [ i ] . tool = TOOL_OTHER ;
m_endTake [ i ] . drive = DRIVE_OTHER ;
2013-04-20 10:08:48 +00:00
}
m_endTake [ i ] . lost = OpInt ( line , " lost " , - 1 ) ;
2012-09-15 13:33:08 +00:00
m_endTake [ i ] . immediat = OpInt ( line , " immediat " , 0 ) ;
2012-06-26 20:23:05 +00:00
OpString ( line , " message " , m_endTake [ i ] . message ) ;
m_endTakeTotal + + ;
}
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " EndMissionDelay " ) & & ! resetObject & & m_controller = = nullptr )
2012-06-26 20:23:05 +00:00
{
m_endTakeWinDelay = OpFloat ( line , " win " , 2.0f ) ;
m_endTakeLostDelay = OpFloat ( line , " lost " , 2.0f ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " EndMissionResearch " ) & & ! resetObject & & m_controller = = nullptr )
2012-06-26 20:23:05 +00:00
{
m_endTakeResearch | = OpResearch ( line , " type " ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 11:43:05 +00:00
if ( Cmd ( line , " EndMissionNever " ) & & ! resetObject & & m_controller = = nullptr )
2013-04-28 16:33:59 +00:00
{
m_endTakeNever = true ;
2013-05-05 18:33:49 +00:00
continue ;
2013-04-28 16:33:59 +00:00
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " ObligatoryToken " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int i = m_obligatoryTotal ;
if ( i < 100 )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " text " , m_obligatoryToken [ i ] ) ;
m_obligatoryTotal + + ;
}
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " ProhibitedToken " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int i = m_prohibitedTotal ;
if ( i < 100 )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " text " , m_prohibitedToken [ i ] ) ;
m_prohibitedTotal + + ;
}
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " EnableBuild " ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
g_build | = OpBuild ( line , " type " ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " EnableResearch " ) & & ! resetObject )
{
2012-06-26 20:23:05 +00:00
g_researchEnable | = OpResearch ( line , " type " ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-09-15 13:33:08 +00:00
2013-05-26 15:47:54 +00:00
if ( Cmd ( line , " DoneResearch " ) & & read [ 0 ] = = 0 & & ! resetObject ) // not loading file?
{
2012-06-26 20:23:05 +00:00
g_researchDone | = OpResearch ( line , " type " ) ;
2013-05-05 18:33:49 +00:00
continue ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " NewScript " ) & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
OpString ( line , " name " , name ) ;
AddNewScriptName ( OpTypeObject ( line , " type " , OBJECT_NULL ) , name ) ;
2013-05-05 18:33:49 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2013-05-05 18:51:08 +00:00
if ( line [ 0 ] = = ' \n ' ) continue ; // Ignore empty lines
2013-05-26 15:47:54 +00:00
if ( line [ 0 ] = = ' \0 ' ) continue ; // Ignore empty lines
2013-05-05 18:51:08 +00:00
if ( read [ 0 ] ! = 0 ) continue ; // Ignore when loading saved game
2013-05-12 11:05:32 +00:00
GetLogger ( ) - > Error ( " Syntax error in file '%s' (line %d): Unknown command: %s " , filename , lineNum , line ) ; // Don't add \n at the end of log message - it's included in line variable
2012-06-26 20:23:05 +00:00
}
fclose ( file ) ;
2012-09-15 13:33:08 +00:00
if ( read [ 0 ] = = 0 )
CompileScript ( soluce ) ; // compiles all scripts
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( strcmp ( base , " scene " ) = = 0 & & ! resetObject ) // mission?
2012-06-26 20:23:05 +00:00
WriteFreeParam ( ) ;
2012-09-15 13:33:08 +00:00
if ( strcmp ( base , " free " ) = = 0 & & ! resetObject ) // free play?
2012-06-26 20:23:05 +00:00
{
g_researchDone = m_freeResearch ;
g_build = m_freeBuild ;
g_build & = ~ BUILD_RESEARCH ;
g_build & = ~ BUILD_LABO ;
g_build | = BUILD_FACTORY ;
g_build | = BUILD_GFLAT ;
g_build | = BUILD_FLAG ;
}
2012-09-15 13:33:08 +00:00
if ( ! resetObject )
2012-06-26 20:23:05 +00:00
{
ChangeColor ( ) ; // changes the colors of texture
m_short - > SetMode ( false ) ; // vehicles?
}
CreateShortcuts ( ) ;
m_map - > UpdateMap ( ) ;
2012-09-15 13:33:08 +00:00
// TODO: m_engine->TimeInit(); ??
2012-09-15 19:47:19 +00:00
m_app - > ResetKeyStates ( ) ;
2012-06-26 20:23:05 +00:00
m_time = 0.0f ;
m_gameTime = 0.0f ;
m_checkEndTime = 0.0f ;
m_infoUsed = 0 ;
2012-09-15 13:33:08 +00:00
m_selectObject = sel ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! m_base & & // no main base?
! m_fixScene ) // interractive scene?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * obj ;
if ( sel = = nullptr )
obj = SearchHuman ( ) ;
2012-06-26 20:23:05 +00:00
else
2012-09-15 13:33:08 +00:00
obj = sel ;
if ( obj ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
SelectObject ( obj ) ;
2012-09-17 18:47:27 +00:00
m_camera - > SetControllingObject ( obj ) ;
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( obj - > GetCameraType ( ) ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
if ( m_fixScene )
m_camera - > SetType ( Gfx : : CAM_TYPE_SCRIPT ) ;
if ( read [ 0 ] ! = 0 & & sel ! = 0 ) // loading file?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector pos = sel - > GetPosition ( 0 ) ;
2012-06-26 20:23:05 +00:00
m_camera - > Init ( pos , pos , 0.0f ) ;
m_camera - > FixCamera ( ) ;
2012-09-15 13:33:08 +00:00
SelectObject ( sel ) ;
2012-09-17 18:47:27 +00:00
m_camera - > SetControllingObject ( sel ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_beginSatCom = true ; // message already displayed
2012-06-26 20:23:05 +00:00
}
m_dialog - > SetSceneRead ( " " ) ;
m_dialog - > SetStackRead ( " " ) ;
2013-02-28 21:56:44 +00:00
2013-04-01 16:24:12 +00:00
RestoreNumericLocale ( ) ;
2013-12-26 21:13:04 +00:00
if ( m_app - > GetSceneTestMode ( ) )
m_eventQueue - > AddEvent ( Event ( EVENT_WIN ) ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Creates a directional light
int CRobotMain : : CreateLight ( Math : : Vector direction , Gfx : : Color color )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( direction . x = = 0.0f & &
direction . y = = 0.0f & &
direction . z = = 0.0f )
2012-06-26 20:23:05 +00:00
{
direction . y = - 1.0f ;
}
2012-09-15 13:33:08 +00:00
Gfx : : Light light ;
light . type = Gfx : : LIGHT_DIRECTIONAL ;
light . diffuse = color ;
2013-02-28 20:26:09 +00:00
light . ambient = color * 0.1f ;
2012-09-15 13:33:08 +00:00
light . direction = direction ;
2012-09-26 21:18:57 +00:00
int obj = m_lightMan - > CreateLight ( Gfx : : LIGHT_PRI_HIGH ) ;
2012-09-15 13:33:08 +00:00
m_lightMan - > SetLight ( obj , light ) ;
2012-06-26 20:23:05 +00:00
return obj ;
}
2012-09-15 13:33:08 +00:00
//! Creates a light spot
int CRobotMain : : CreateSpot ( Math : : Vector pos , Gfx : : Color color )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! m_engine - > GetLightMode ( ) ) return - 1 ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
pos . y + = m_terrain - > GetFloorLevel ( pos ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Gfx : : Light light ;
light . type = Gfx : : LIGHT_SPOT ;
light . diffuse = color ;
2013-02-28 20:26:09 +00:00
light . ambient = color * 0.1f ;
2012-09-15 13:33:08 +00:00
light . position = pos ;
light . direction = Math : : Vector ( 0.0f , - 1.0f , 0.0f ) ;
light . spotIntensity = 1.0f ;
light . spotAngle = 90.0f * Math : : PI / 180.0f ;
light . attenuation0 = 2.0f ;
light . attenuation1 = 0.0f ;
light . attenuation2 = 0.0f ;
2012-09-26 21:18:57 +00:00
int obj = m_lightMan - > CreateLight ( Gfx : : LIGHT_PRI_HIGH ) ;
2012-09-15 13:33:08 +00:00
m_lightMan - > SetLight ( obj , light ) ;
2012-06-26 20:23:05 +00:00
return obj ;
}
2012-09-15 13:33:08 +00:00
//! Change the colors and textures
2012-06-26 20:23:05 +00:00
void CRobotMain : : ChangeColor ( )
{
2012-09-15 13:33:08 +00:00
Math : : Point ts = Math : : Point ( 0.0f , 0.0f ) ;
Math : : Point ti = Math : : Point ( 1.0f , 1.0f ) ; // the entire image
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Gfx : : Color colorRef1 , colorNew1 , colorRef2 , colorNew2 ;
2012-06-26 20:23:05 +00:00
colorRef1 . a = 0.0f ;
colorRef2 . a = 0.0f ;
colorRef1 . r = 206.0f / 256.0f ;
colorRef1 . g = 206.0f / 256.0f ;
colorRef1 . b = 204.0f / 256.0f ; // ~white
2012-09-15 13:33:08 +00:00
colorNew1 = m_dialog - > GetGamerColorCombi ( ) ;
2012-06-26 20:23:05 +00:00
colorRef2 . r = 255.0f / 256.0f ;
colorRef2 . g = 132.0f / 256.0f ;
colorRef2 . b = 1.0f / 256.0f ; // orange
2012-09-15 13:33:08 +00:00
colorNew2 = m_dialog - > GetGamerColorBand ( ) ;
Math : : Point exclu [ 6 ] ;
2012-06-26 20:23:05 +00:00
exclu [ 0 ] = Math : : Point ( 192.0f / 256.0f , 0.0f / 256.0f ) ;
exclu [ 1 ] = Math : : Point ( 256.0f / 256.0f , 64.0f / 256.0f ) ; // crystals + cylinders
exclu [ 2 ] = Math : : Point ( 208.0f / 256.0f , 224.0f / 256.0f ) ;
exclu [ 3 ] = Math : : Point ( 256.0f / 256.0f , 256.0f / 256.0f ) ; // SatCom screen
exclu [ 4 ] = Math : : Point ( 0.0f , 0.0f ) ;
exclu [ 5 ] = Math : : Point ( 0.0f , 0.0f ) ; // terminator
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " human.png " , colorRef1 , colorNew1 , colorRef2 , colorNew2 , 0.30f , 0.01f , ts , ti , exclu ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
float tolerance ;
int face = GetGamerFace ( ) ;
if ( face = = 0 ) // normal?
2012-06-26 20:23:05 +00:00
{
colorRef1 . r = 90.0f / 256.0f ;
colorRef1 . g = 95.0f / 256.0f ;
colorRef1 . b = 85.0f / 256.0f ; // black
tolerance = 0.15f ;
}
2012-09-15 13:33:08 +00:00
if ( face = = 1 ) // bald?
2012-06-26 20:23:05 +00:00
{
colorRef1 . r = 74.0f / 256.0f ;
colorRef1 . g = 58.0f / 256.0f ;
colorRef1 . b = 46.0f / 256.0f ; // brown
tolerance = 0.20f ;
}
2012-09-15 13:33:08 +00:00
if ( face = = 2 ) // carlos?
2012-06-26 20:23:05 +00:00
{
colorRef1 . r = 70.0f / 256.0f ;
colorRef1 . g = 40.0f / 256.0f ;
colorRef1 . b = 8.0f / 256.0f ; // brown
tolerance = 0.30f ;
}
2012-09-15 13:33:08 +00:00
if ( face = = 3 ) // blonde?
2012-06-26 20:23:05 +00:00
{
colorRef1 . r = 74.0f / 256.0f ;
colorRef1 . g = 16.0f / 256.0f ;
colorRef1 . b = 0.0f / 256.0f ; // yellow
tolerance = 0.20f ;
}
2012-09-15 13:33:08 +00:00
colorNew1 = m_dialog - > GetGamerColorHair ( ) ;
2012-06-26 20:23:05 +00:00
colorRef2 . r = 0.0f ;
colorRef2 . g = 0.0f ;
colorRef2 . b = 0.0f ;
colorNew2 . r = 0.0f ;
colorNew2 . g = 0.0f ;
colorNew2 . b = 0.0f ;
2012-09-15 13:33:08 +00:00
char name [ 100 ] ;
sprintf ( name , " face%.2d.png " , face + 1 ) ;
2012-06-26 20:23:05 +00:00
exclu [ 0 ] = Math : : Point ( 105.0f / 256.0f , 47.0f / 166.0f ) ;
exclu [ 1 ] = Math : : Point ( 153.0f / 256.0f , 79.0f / 166.0f ) ; // blue canister
exclu [ 2 ] = Math : : Point ( 0.0f , 0.0f ) ;
exclu [ 3 ] = Math : : Point ( 0.0f , 0.0f ) ; // terminator
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( name , colorRef1 , colorNew1 , colorRef2 , colorNew2 , tolerance , 0.00f , ts , ti , exclu ) ;
2012-06-26 20:23:05 +00:00
colorRef2 . r = 0.0f ;
colorRef2 . g = 0.0f ;
colorRef2 . b = 0.0f ;
colorNew2 . r = 0.0f ;
colorNew2 . g = 0.0f ;
colorNew2 . b = 0.0f ;
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " base1.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
m_engine - > ChangeTextureColor ( " convert.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
m_engine - > ChangeTextureColor ( " derrick.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
m_engine - > ChangeTextureColor ( " factory.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
m_engine - > ChangeTextureColor ( " lemt.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
m_engine - > ChangeTextureColor ( " roller.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
m_engine - > ChangeTextureColor ( " search.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , 0 , 0 , true ) ;
2012-06-26 20:23:05 +00:00
exclu [ 0 ] = Math : : Point ( 0.0f / 256.0f , 160.0f / 256.0f ) ;
exclu [ 1 ] = Math : : Point ( 256.0f / 256.0f , 256.0f / 256.0f ) ; // pencils
exclu [ 2 ] = Math : : Point ( 0.0f , 0.0f ) ;
exclu [ 3 ] = Math : : Point ( 0.0f , 0.0f ) ; // terminator
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " drawer.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , exclu , 0 , true ) ;
2012-06-26 20:23:05 +00:00
exclu [ 0 ] = Math : : Point ( 237.0f / 256.0f , 176.0f / 256.0f ) ;
exclu [ 1 ] = Math : : Point ( 256.0f / 256.0f , 220.0f / 256.0f ) ; // blue canister
exclu [ 2 ] = Math : : Point ( 106.0f / 256.0f , 150.0f / 256.0f ) ;
exclu [ 3 ] = Math : : Point ( 130.0f / 256.0f , 214.0f / 256.0f ) ; // safe location
exclu [ 4 ] = Math : : Point ( 0.0f , 0.0f ) ;
exclu [ 5 ] = Math : : Point ( 0.0f , 0.0f ) ; // terminator
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " subm.png " , m_colorRefBot , m_colorNewBot , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , exclu , 0 , true ) ;
2012-06-26 20:23:05 +00:00
exclu [ 0 ] = Math : : Point ( 128.0f / 256.0f , 160.0f / 256.0f ) ;
exclu [ 1 ] = Math : : Point ( 256.0f / 256.0f , 256.0f / 256.0f ) ; // SatCom
exclu [ 2 ] = Math : : Point ( 0.0f , 0.0f ) ;
exclu [ 3 ] = Math : : Point ( 0.0f , 0.0f ) ; // terminator
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " ant.png " , m_colorRefAlien , m_colorNewAlien , colorRef2 , colorNew2 , 0.50f , - 1.0f , ts , ti , exclu ) ;
m_engine - > ChangeTextureColor ( " mother.png " , m_colorRefAlien , m_colorNewAlien , colorRef2 , colorNew2 , 0.50f , - 1.0f , ts , ti ) ;
2012-06-26 20:23:05 +00:00
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " plant.png " , m_colorRefGreen , m_colorNewGreen , colorRef2 , colorNew2 , 0.50f , - 1.0f , ts , ti ) ;
2012-06-26 20:23:05 +00:00
// PARTIPLOUF0 and PARTIDROP :
ts = Math : : Point ( 0.500f , 0.500f ) ;
ti = Math : : Point ( 0.875f , 0.750f ) ;
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " effect00.png " , m_colorRefWater , m_colorNewWater , colorRef2 , colorNew2 , 0.20f , - 1.0f , ts , ti , 0 , m_colorShiftWater , true ) ;
2012-06-26 20:23:05 +00:00
// PARTIFLIC :
ts = Math : : Point ( 0.00f , 0.75f ) ;
ti = Math : : Point ( 0.25f , 1.00f ) ;
2012-09-29 21:37:38 +00:00
m_engine - > ChangeTextureColor ( " effect02.png " , m_colorRefWater , m_colorNewWater , colorRef2 , colorNew2 , 0.20f , - 1.0f , ts , ti , 0 , m_colorShiftWater , true ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Updates the number of unnecessary objects
2012-06-26 20:23:05 +00:00
bool CRobotMain : : TestGadgetQuantity ( int rank )
{
static int table10 [ 10 ] = { 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
static int table20 [ 10 ] = { 0 , 1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 } ;
static int table30 [ 10 ] = { 0 , 1 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 } ;
static int table40 [ 10 ] = { 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 0 } ;
static int table50 [ 10 ] = { 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 } ;
static int table60 [ 10 ] = { 0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 } ;
static int table70 [ 10 ] = { 0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 1 , 1 } ;
static int table80 [ 10 ] = { 0 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 } ;
static int table90 [ 10 ] = { 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } ;
2012-09-15 13:33:08 +00:00
float percent = m_engine - > GetGadgetQuantity ( ) ;
if ( percent = = 0.0f ) return false ;
if ( percent = = 1.0f ) return true ;
int * table ;
if ( percent < = 0.15f ) table = table10 ;
else if ( percent < = 0.25f ) table = table20 ;
else if ( percent < = 0.35f ) table = table30 ;
else if ( percent < = 0.45f ) table = table40 ;
else if ( percent < = 0.55f ) table = table50 ;
else if ( percent < = 0.65f ) table = table60 ;
else if ( percent < = 0.75f ) table = table70 ;
else if ( percent < = 0.85f ) table = table80 ;
else table = table90 ;
2012-06-26 20:23:05 +00:00
return table [ rank % 10 ] ;
}
2012-09-15 13:33:08 +00:00
//! Calculates the distance to the nearest object
2012-06-26 20:23:05 +00:00
float CRobotMain : : SearchNearestObject ( Math : : Vector center , CObject * exclu )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
float min = 100000.0f ;
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! obj - > GetActif ( ) ) continue ; // inactive?
if ( obj - > GetTruck ( ) ! = nullptr ) continue ; // object carries?
if ( obj = = exclu ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( type = = OBJECT_BASE )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector oPos = obj - > GetPosition ( 0 ) ;
if ( oPos . x ! = center . x | |
oPos . z ! = center . z )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float dist = Math : : Distance ( center , oPos ) - 80.0f ;
if ( dist < 0.0f ) dist = 0.0f ;
2012-06-26 20:23:05 +00:00
min = Math : : Min ( min , dist ) ;
continue ;
}
}
2012-09-15 13:33:08 +00:00
if ( type = = OBJECT_STATION | |
type = = OBJECT_REPAIR | |
type = = OBJECT_DESTROYER )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector oPos = obj - > GetPosition ( 0 ) ;
float dist = Math : : Distance ( center , oPos ) - 8.0f ;
if ( dist < 0.0f ) dist = 0.0f ;
2012-06-26 20:23:05 +00:00
min = Math : : Min ( min , dist ) ;
}
2012-09-15 13:33:08 +00:00
int j = 0 ;
Math : : Vector oPos ;
float oRadius ;
while ( obj - > GetCrashSphere ( j + + , oPos , oRadius ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float dist = Math : : Distance ( center , oPos ) - oRadius ;
if ( dist < 0.0f ) dist = 0.0f ;
2012-06-26 20:23:05 +00:00
min = Math : : Min ( min , dist ) ;
}
}
return min ;
}
2012-09-15 13:33:08 +00:00
//! Calculates a free space
2012-06-26 20:23:05 +00:00
bool CRobotMain : : FreeSpace ( Math : : Vector & center , float minRadius , float maxRadius ,
float space , CObject * exclu )
{
2012-09-15 13:33:08 +00:00
if ( minRadius < maxRadius ) // from internal to external?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( float radius = minRadius ; radius < = maxRadius ; radius + = space )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float ia = space / radius ;
for ( float angle = 0.0f ; angle < Math : : PI * 2.0f ; angle + = ia )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Point p ;
2012-06-26 20:23:05 +00:00
p . x = center . x + radius ;
p . y = center . z ;
p = Math : : RotatePoint ( Math : : Point ( center . x , center . z ) , angle , p ) ;
2012-09-15 13:33:08 +00:00
Math : : Vector pos ;
2012-06-26 20:23:05 +00:00
pos . x = p . x ;
pos . z = p . y ;
pos . y = 0.0f ;
2012-09-15 13:33:08 +00:00
m_terrain - > AdjustToFloor ( pos , true ) ;
float dist = SearchNearestObject ( pos , exclu ) ;
if ( dist > = space )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float flat = m_terrain - > GetFlatZoneRadius ( pos , dist / 2.0f ) ;
if ( flat > = dist / 2.0f )
2012-06-26 20:23:05 +00:00
{
center = pos ;
return true ;
}
}
}
}
}
else // from external to internal?
{
2012-09-15 13:33:08 +00:00
for ( float radius = maxRadius ; radius > = minRadius ; radius - = space )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float ia = space / radius ;
for ( float angle = 0.0f ; angle < Math : : PI * 2.0f ; angle + = ia )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Point p ;
2012-06-26 20:23:05 +00:00
p . x = center . x + radius ;
p . y = center . z ;
p = Math : : RotatePoint ( Math : : Point ( center . x , center . z ) , angle , p ) ;
2012-09-15 13:33:08 +00:00
Math : : Vector pos ;
2012-06-26 20:23:05 +00:00
pos . x = p . x ;
pos . z = p . y ;
pos . y = 0.0f ;
2012-09-15 13:33:08 +00:00
m_terrain - > AdjustToFloor ( pos , true ) ;
float dist = SearchNearestObject ( pos , exclu ) ;
if ( dist > = space )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float flat = m_terrain - > GetFlatZoneRadius ( pos , dist / 2.0f ) ;
if ( flat > = dist / 2.0f )
2012-06-26 20:23:05 +00:00
{
center = pos ;
return true ;
}
}
}
}
}
return false ;
}
2012-09-15 13:33:08 +00:00
//! Calculates the maximum radius of a free space
float CRobotMain : : GetFlatZoneRadius ( Math : : Vector center , float maxRadius ,
2012-06-26 20:23:05 +00:00
CObject * exclu )
{
2012-09-15 13:33:08 +00:00
float dist = SearchNearestObject ( center , exclu ) ;
if ( dist = = 0.0f ) return 0.0f ;
if ( dist < maxRadius )
2012-06-26 20:23:05 +00:00
maxRadius = dist ;
2012-09-15 13:33:08 +00:00
return m_terrain - > GetFlatZoneRadius ( center , maxRadius ) ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
//! Hides buildable area when a cube of metal is taken up
2012-06-26 20:23:05 +00:00
void CRobotMain : : HideDropZone ( CObject * metal )
{
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ 1 ] . used & &
m_showLimit [ 1 ] . link = = metal )
2012-06-26 20:23:05 +00:00
{
FlushShowLimit ( 1 ) ;
}
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ 2 ] . used & &
m_showLimit [ 2 ] . link = = metal )
2012-06-26 20:23:05 +00:00
{
FlushShowLimit ( 2 ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Shows the buildable area when a cube of metal is deposited
2012-06-26 20:23:05 +00:00
void CRobotMain : : ShowDropZone ( CObject * metal , CObject * truck )
{
2012-09-15 13:33:08 +00:00
if ( metal = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Vector center = metal - > GetPosition ( 0 ) ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-06-26 20:23:05 +00:00
// Calculates the maximum radius possible depending on other items.
2012-09-15 13:33:08 +00:00
float oMax = 30.0f ; // radius to build the biggest building
float tMax ;
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
if ( ! obj - > GetActif ( ) ) continue ; // inactive?
if ( obj - > GetTruck ( ) ! = nullptr ) continue ; // object carried?
if ( obj = = metal ) continue ;
if ( obj = = truck ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Vector oPos ;
float oRadius ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_BASE )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
oPos = obj - > GetPosition ( 0 ) ;
float dist = Math : : Distance ( center , oPos ) - 80.0f ;
2012-06-26 20:23:05 +00:00
oMax = Math : : Min ( oMax , dist ) ;
}
else
{
2012-09-15 13:33:08 +00:00
int j = 0 ;
while ( obj - > GetCrashSphere ( j + + , oPos , oRadius ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float dist = Math : : Distance ( center , oPos ) - oRadius ;
2012-06-26 20:23:05 +00:00
oMax = Math : : Min ( oMax , dist ) ;
}
}
if ( type = = OBJECT_DERRICK | |
type = = OBJECT_FACTORY | |
type = = OBJECT_STATION | |
type = = OBJECT_CONVERT | |
type = = OBJECT_REPAIR | |
type = = OBJECT_DESTROYER | |
type = = OBJECT_TOWER | |
type = = OBJECT_RESEARCH | |
type = = OBJECT_RADAR | |
type = = OBJECT_ENERGY | |
type = = OBJECT_LABO | |
type = = OBJECT_NUCLEAR | |
type = = OBJECT_START | |
type = = OBJECT_END | |
type = = OBJECT_INFO | |
type = = OBJECT_PARA | |
type = = OBJECT_SAFE | |
type = = OBJECT_HUSTON ) // building?
{
2012-09-15 13:33:08 +00:00
int j = 0 ;
while ( obj - > GetCrashSphere ( j + + , oPos , oRadius ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float dist = Math : : Distance ( center , oPos ) - oRadius - BUILDMARGIN ;
2012-06-26 20:23:05 +00:00
oMax = Math : : Min ( oMax , dist ) ;
}
}
}
// Calculates the maximum possible radius depending on terrain.
2012-09-15 13:33:08 +00:00
if ( oMax > = 2.0f )
tMax = m_terrain - > GetFlatZoneRadius ( center , 30.0f ) ;
2012-06-26 20:23:05 +00:00
else
tMax = 0.0f ;
2012-09-15 13:33:08 +00:00
float radius = Math : : Min ( oMax , tMax ) ;
if ( radius > = 2.0f )
SetShowLimit ( 1 , Gfx : : PARTILIMIT2 , metal , center , radius , 10.0f ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Erases the boundaries shown
2012-06-26 20:23:05 +00:00
void CRobotMain : : FlushShowLimit ( int i )
{
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ i ] . link ! = 0 )
2012-06-26 20:23:05 +00:00
{
m_showLimit [ i ] . link - > StopShowLimit ( ) ;
}
2012-09-15 13:33:08 +00:00
for ( int j = 0 ; j < m_showLimit [ i ] . total ; j + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ i ] . parti [ j ] = = 0 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_particle - > DeleteParticle ( m_showLimit [ i ] . parti [ j ] ) ;
2012-06-26 20:23:05 +00:00
m_showLimit [ i ] . parti [ j ] = 0 ;
}
m_showLimit [ i ] . total = 0 ;
m_showLimit [ i ] . link = 0 ;
2012-09-15 13:33:08 +00:00
m_showLimit [ i ] . used = false ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Specifies the boundaries to show
void CRobotMain : : SetShowLimit ( int i , Gfx : : ParticleType parti , CObject * obj ,
2012-06-26 20:23:05 +00:00
Math : : Vector pos , float radius , float duration )
{
FlushShowLimit ( i ) ; // erases the current boundaries
2012-09-15 13:33:08 +00:00
if ( radius < = 0.0f ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Point dim ;
float dist ;
if ( radius < = 50.0f )
2012-06-26 20:23:05 +00:00
{
dim = Math : : Point ( 0.3f , 0.3f ) ;
dist = 2.5f ;
}
else
{
dim = Math : : Point ( 1.5f , 1.5f ) ;
dist = 10.0f ;
}
2012-09-15 13:33:08 +00:00
m_showLimit [ i ] . used = true ;
m_showLimit [ i ] . link = obj ;
2012-06-26 20:23:05 +00:00
m_showLimit [ i ] . pos = pos ;
m_showLimit [ i ] . radius = radius ;
m_showLimit [ i ] . duration = duration ;
2012-09-17 22:01:00 +00:00
m_showLimit [ i ] . total = static_cast < int > ( ( radius * 2.0f * Math : : PI ) / dist ) ;
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ i ] . total > MAXSHOWPARTI ) m_showLimit [ i ] . total = MAXSHOWPARTI ;
2012-06-26 20:23:05 +00:00
m_showLimit [ i ] . time = 0.0f ;
2012-09-15 13:33:08 +00:00
for ( int j = 0 ; j < m_showLimit [ i ] . total ; j + + )
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
m_showLimit [ i ] . parti [ j ] = m_particle - > CreateParticle ( pos , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , dim , parti , duration ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! Adjusts the boundaries to show
2012-06-26 20:23:05 +00:00
void CRobotMain : : AdjustShowLimit ( int i , Math : : Vector pos )
{
m_showLimit [ i ] . pos = pos ;
}
2012-09-15 13:33:08 +00:00
//! Mount the boundaries of the selected object
2012-06-26 20:23:05 +00:00
void CRobotMain : : StartShowLimit ( )
{
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > StartShowLimit ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Advances the boundaries shown
2012-06-26 20:23:05 +00:00
void CRobotMain : : FrameShowLimit ( float rTime )
{
2012-09-15 13:33:08 +00:00
if ( m_engine - > GetPause ( ) ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < MAXSHOWLIMIT ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! m_showLimit [ i ] . used ) continue ;
2012-06-26 20:23:05 +00:00
m_showLimit [ i ] . time + = rTime ;
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ i ] . time > = m_showLimit [ i ] . duration )
2012-06-26 20:23:05 +00:00
{
FlushShowLimit ( i ) ;
continue ;
}
2012-09-15 13:33:08 +00:00
float factor ;
if ( m_showLimit [ i ] . time < 1.0f )
2012-06-26 20:23:05 +00:00
factor = m_showLimit [ i ] . time ;
2012-09-15 13:33:08 +00:00
else if ( m_showLimit [ i ] . time > m_showLimit [ i ] . duration - 1.0f )
2012-06-26 20:23:05 +00:00
factor = m_showLimit [ i ] . duration - m_showLimit [ i ] . time ;
else
factor = 1.0f ;
2012-09-15 13:33:08 +00:00
float speed = 0.4f - m_showLimit [ i ] . radius * 0.001f ;
if ( speed < 0.1f ) speed = 0.1f ;
float angle = m_showLimit [ i ] . time * speed ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int j = 0 ; j < m_showLimit [ i ] . total ; j + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_showLimit [ i ] . parti [ j ] = = 0 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Point center ;
2012-06-26 20:23:05 +00:00
center . x = m_showLimit [ i ] . pos . x ;
center . y = m_showLimit [ i ] . pos . z ;
2012-09-15 13:33:08 +00:00
Math : : Point rotate ;
2012-06-26 20:23:05 +00:00
rotate . x = center . x + m_showLimit [ i ] . radius * factor ;
rotate . y = center . y ;
rotate = Math : : RotatePoint ( center , angle , rotate ) ;
2012-09-15 13:33:08 +00:00
Math : : Vector pos ;
2012-06-26 20:23:05 +00:00
pos . x = rotate . x ;
pos . z = rotate . y ;
pos . y = 0.0f ;
2012-09-15 13:33:08 +00:00
m_terrain - > AdjustToFloor ( pos , true ) ;
if ( m_showLimit [ i ] . radius < = 50.0f ) pos . y + = 0.5f ;
else pos . y + = 2.0f ;
2012-09-10 21:29:38 +00:00
m_particle - > SetPosition ( m_showLimit [ i ] . parti [ j ] , pos ) ;
2012-06-26 20:23:05 +00:00
angle + = ( 2.0f * Math : : PI ) / m_showLimit [ i ] . total ;
}
}
}
2012-10-11 21:09:29 +00:00
//! Returns a pointer to the last slash in a filename.
2012-06-26 20:23:05 +00:00
char * SearchLastDir ( char * filename )
{
2012-09-15 13:33:08 +00:00
char * p = filename ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
while ( * p + + ! = 0 ) ;
2012-06-26 20:23:05 +00:00
p - - ; // ^on the zero terminator
2012-09-15 13:33:08 +00:00
while ( p ! = filename )
2012-06-26 20:23:05 +00:00
{
2013-04-20 08:57:42 +00:00
if ( * ( - - p ) = = ' / ' | | * p = = ' \\ ' ) return p ;
2012-06-26 20:23:05 +00:00
}
return 0 ;
}
2012-09-15 13:33:08 +00:00
//! Compiles all scripts of robots
void CRobotMain : : CompileScript ( bool soluce )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int nbError = 0 ;
int lastError = 0 ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-06-26 20:23:05 +00:00
do
{
lastError = nbError ;
nbError = 0 ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int j = 0 ; j < 10 ; j + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( brain - > GetCompile ( j ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char * name = brain - > GetScriptName ( j ) ;
if ( name [ 0 ] ! = 0 )
2012-06-26 20:23:05 +00:00
{
2013-12-26 18:36:17 +00:00
if ( ! brain - > ReadProgram ( j , name ) ) {
2013-12-26 18:39:32 +00:00
CLogger : : GetInstancePointer ( ) - > Error ( " Unable to read script from file \" %s \" \n " , name ) ;
2013-12-26 18:36:17 +00:00
}
2012-09-15 13:33:08 +00:00
if ( ! brain - > GetCompile ( j ) ) nbError + + ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
LoadOneScript ( obj , nbError ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
while ( nbError > 0 & & nbError ! = lastError ) ;
2012-06-26 20:23:05 +00:00
// Load all solutions.
2012-09-15 13:33:08 +00:00
if ( soluce )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = 0 ) break ;
if ( obj - > GetTruck ( ) ! = 0 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = 0 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char * name = brain - > GetSoluceName ( ) ;
if ( name [ 0 ] ! = 0 )
2012-06-26 20:23:05 +00:00
{
brain - > ReadSoluce ( name ) ; // load solution
}
}
}
// Start all programs according to the command "run".
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int run = brain - > GetScriptRun ( ) ;
if ( run ! = - 1 )
2012-06-26 20:23:05 +00:00
{
brain - > RunProgram ( run ) ; // starts the program
}
}
}
2012-09-15 13:33:08 +00:00
//! Load all programs of the robot
void CRobotMain : : LoadOneScript ( CObject * obj , int & nbError )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! IsSelectable ( obj ) ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int objRank = obj - > GetDefRank ( ) ;
if ( objRank = = - 1 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char * name = m_dialog - > GetSceneName ( ) ;
int rank = m_dialog - > GetSceneRank ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < BRAINMAXSCRIPT ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( brain - > GetCompile ( i ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char filename [ MAX_FNAME ] ;
2012-09-22 12:40:13 +00:00
sprintf ( filename , " %s/%s/%c%.3d%.3d%.1d.txt " ,
2013-05-01 19:02:43 +00:00
GetSavegameDir ( ) , m_gamerName . c_str ( ) , name [ 0 ] , rank , objRank , i ) ;
2012-06-26 20:23:05 +00:00
brain - > ReadProgram ( i , filename ) ;
2012-09-15 13:33:08 +00:00
if ( ! brain - > GetCompile ( i ) ) nbError + + ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! Load all programs of the robot
2012-09-26 20:57:43 +00:00
void CRobotMain : : LoadFileScript ( CObject * obj , const char * filename , int objRank ,
2012-06-26 20:23:05 +00:00
int & nbError )
{
2012-09-15 13:33:08 +00:00
if ( objRank = = - 1 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char fn [ MAX_FNAME ] ;
2012-06-26 20:23:05 +00:00
strcpy ( fn , filename ) ;
2012-09-15 13:33:08 +00:00
char * ldir = SearchLastDir ( fn ) ;
if ( ldir = = 0 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < BRAINMAXSCRIPT ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( brain - > GetCompile ( i ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-22 12:40:13 +00:00
sprintf ( ldir , " /prog%.3d%.1d.txt " , objRank , i ) ;
2012-06-26 20:23:05 +00:00
brain - > ReadProgram ( i , fn ) ;
2012-09-15 13:33:08 +00:00
if ( ! brain - > GetCompile ( i ) ) nbError + + ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! Saves all programs of all the robots
2012-06-26 20:23:05 +00:00
void CRobotMain : : SaveAllScript ( )
{
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
SaveOneScript ( obj ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! Saves all programs of the robot.
//! If a program does not exist, the corresponding file is destroyed.
void CRobotMain : : SaveOneScript ( CObject * obj )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! IsSelectable ( obj ) ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
int objRank = obj - > GetDefRank ( ) ;
if ( objRank = = - 1 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char * name = m_dialog - > GetSceneName ( ) ;
int rank = m_dialog - > GetSceneRank ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < BRAINMAXSCRIPT ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
char filename [ MAX_FNAME ] ;
2012-09-22 12:40:13 +00:00
sprintf ( filename , " %s/%s/%c%.3d%.3d%.1d.txt " ,
2013-05-01 19:02:43 +00:00
GetSavegameDir ( ) , m_gamerName . c_str ( ) , name [ 0 ] , rank , objRank , i ) ;
2012-06-26 20:23:05 +00:00
brain - > WriteProgram ( i , filename ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Saves all programs of the robot.
//! If a program does not exist, the corresponding file is destroyed.
2012-09-26 20:57:43 +00:00
void CRobotMain : : SaveFileScript ( CObject * obj , const char * filename , int objRank )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( objRank = = - 1 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char fn [ MAX_FNAME ] ;
2012-06-26 20:23:05 +00:00
strcpy ( fn , filename ) ;
2012-09-15 13:33:08 +00:00
char * ldir = SearchLastDir ( fn ) ;
if ( ldir = = 0 ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < BRAINMAXSCRIPT ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-22 12:40:13 +00:00
sprintf ( ldir , " /prog%.3d%.1d.txt " , objRank , i ) ;
2012-06-26 20:23:05 +00:00
brain - > WriteProgram ( i , fn ) ;
}
}
2012-09-15 13:33:08 +00:00
//! Saves the stack of the program in execution of a robot
bool CRobotMain : : SaveFileStack ( CObject * obj , FILE * file , int objRank )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( objRank = = - 1 ) return true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) return true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN ) return true ;
2012-06-26 20:23:05 +00:00
return brain - > WriteStack ( file ) ;
}
2012-09-15 13:33:08 +00:00
//! Resumes the execution stack of the program in a robot
bool CRobotMain : : ReadFileStack ( CObject * obj , FILE * file , int objRank )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( objRank = = - 1 ) return true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain = = nullptr ) return true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_HUMAN ) return true ;
2012-06-26 20:23:05 +00:00
return brain - > ReadStack ( file ) ;
}
2012-09-15 13:33:08 +00:00
//! Empty the list
2012-06-26 20:23:05 +00:00
bool CRobotMain : : FlushNewScriptName ( )
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < MAXNEWSCRIPTNAME ; i + + )
m_newScriptName [ i ] . used = false ;
2012-06-26 20:23:05 +00:00
return true ;
}
2012-09-15 13:33:08 +00:00
//! Adds a script name
2012-06-26 20:23:05 +00:00
bool CRobotMain : : AddNewScriptName ( ObjectType type , char * name )
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < MAXNEWSCRIPTNAME ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( ! m_newScriptName [ i ] . used )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_newScriptName [ i ] . used = true ;
2012-06-26 20:23:05 +00:00
m_newScriptName [ i ] . type = type ;
strcpy ( m_newScriptName [ i ] . name , name ) ;
return true ;
}
}
return false ;
}
2012-09-15 13:33:08 +00:00
//! Seeks a script name for a given type
char * CRobotMain : : GetNewScriptName ( ObjectType type , int rank )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < MAXNEWSCRIPTNAME ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_newScriptName [ i ] . used & &
( m_newScriptName [ i ] . type = = type | |
m_newScriptName [ i ] . type = = OBJECT_NULL ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( rank = = 0 ) return m_newScriptName [ i ] . name ;
else rank - - ;
2012-06-26 20:23:05 +00:00
}
}
return 0 ;
}
2012-09-15 13:33:08 +00:00
//! Seeks if an object occupies in a spot, to prevent a backup of the game
2012-06-26 20:23:05 +00:00
bool CRobotMain : : IsBusy ( )
{
2012-09-15 13:33:08 +00:00
if ( m_CompteurFileOpen > 0 ) return true ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( brain - > IsBusy ( ) ) return true ;
2012-06-26 20:23:05 +00:00
}
}
return false ;
}
2012-09-15 13:33:08 +00:00
//! Writes an object into the backup file
2012-09-17 22:01:00 +00:00
void CRobotMain : : IOWriteObject ( FILE * file , CObject * obj , const char * cmd )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_FIX ) return ;
2013-05-26 15:47:54 +00:00
2013-04-01 16:24:12 +00:00
SetNumericLocale ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char line [ 3000 ] ;
char name [ 100 ] ;
2012-06-26 20:23:05 +00:00
strcpy ( line , cmd ) ;
2012-09-15 13:33:08 +00:00
sprintf ( name , " type=%s " , GetTypeObject ( obj - > GetType ( ) ) ) ;
2012-06-26 20:23:05 +00:00
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
sprintf ( name , " id=%d " , obj - > GetID ( ) ) ;
2012-06-26 20:23:05 +00:00
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
Math : : Vector pos ;
pos = obj - > GetPosition ( 0 ) / g_unit ;
2012-06-26 20:23:05 +00:00
sprintf ( name , " pos=%.2f;%.2f;%.2f " , pos . x , pos . y , pos . z ) ;
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
pos = obj - > GetAngle ( 0 ) / ( Math : : PI / 180.0f ) ;
2012-06-26 20:23:05 +00:00
sprintf ( name , " angle=%.2f;%.2f;%.2f " , pos . x , pos . y , pos . z ) ;
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
pos = obj - > GetZoom ( 0 ) ;
2012-06-26 20:23:05 +00:00
sprintf ( name , " zoom=%.2f;%.2f;%.2f " , pos . x , pos . y , pos . z ) ;
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
for ( int i = 1 ; i < OBJECTMAXPART ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetObjectRank ( i ) = = - 1 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
pos = obj - > GetPosition ( i ) ;
if ( pos . x ! = 0.0f | | pos . y ! = 0.0f | | pos . z ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
pos / = g_unit ;
sprintf ( name , " p%d=%.2f;%.2f;%.2f " , i , pos . x , pos . y , pos . z ) ;
strcat ( line , name ) ;
}
2012-09-15 13:33:08 +00:00
pos = obj - > GetAngle ( i ) ;
if ( pos . x ! = 0.0f | | pos . y ! = 0.0f | | pos . z ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
pos / = ( Math : : PI / 180.0f ) ;
sprintf ( name , " a%d=%.2f;%.2f;%.2f " , i , pos . x , pos . y , pos . z ) ;
strcat ( line , name ) ;
}
2012-09-15 13:33:08 +00:00
pos = obj - > GetZoom ( i ) ;
if ( pos . x ! = 1.0f | | pos . y ! = 1.0f | | pos . z ! = 1.0f )
2012-06-26 20:23:05 +00:00
{
sprintf ( name , " z%d=%.2f;%.2f;%.2f " , i , pos . x , pos . y , pos . z ) ;
strcat ( line , name ) ;
}
}
2012-09-15 13:33:08 +00:00
sprintf ( name , " trainer=%d " , obj - > GetTrainer ( ) ) ;
2012-06-26 20:23:05 +00:00
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
sprintf ( name , " option=%d " , obj - > GetOption ( ) ) ;
2012-06-26 20:23:05 +00:00
strcat ( line , name ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = m_infoObject ) // selects object?
2012-06-26 20:23:05 +00:00
{
sprintf ( name , " select=1 " ) ;
strcat ( line , name ) ;
}
2012-09-15 13:33:08 +00:00
obj - > Write ( line ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_BASE )
2012-06-26 20:23:05 +00:00
{
sprintf ( name , " run=3 " ) ; // stops and open (PARAM_FIXSCENE)
strcat ( line , name ) ;
}
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
int run = brain - > GetProgram ( ) ;
if ( run ! = - 1 )
2012-06-26 20:23:05 +00:00
{
sprintf ( name , " run=%d " , run + 1 ) ;
strcat ( line , name ) ;
}
}
strcat ( line , " \n " ) ;
fputs ( line , file ) ;
2013-05-26 15:47:54 +00:00
2013-04-01 16:24:12 +00:00
RestoreNumericLocale ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Saves the current game
2012-09-26 20:57:43 +00:00
bool CRobotMain : : IOWriteScene ( const char * filename , const char * filecbot , char * info )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
FILE * file = fopen ( filename , " w " ) ;
if ( file = = NULL ) return false ;
2013-05-26 15:47:54 +00:00
2013-04-01 16:24:12 +00:00
SetNumericLocale ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char line [ 500 ] ;
2012-06-26 20:23:05 +00:00
sprintf ( line , " Title text= \" %s \" \n " , info ) ;
fputs ( line , file ) ;
2012-06-26 21:01:17 +00:00
2012-06-26 20:23:05 +00:00
sprintf ( line , " Version maj=%d min=%d \n " , 0 , 1 ) ;
fputs ( line , file ) ;
2012-06-26 21:01:17 +00:00
2012-09-15 13:33:08 +00:00
char * name = m_dialog - > GetSceneName ( ) ;
if ( strcmp ( name , " user " ) = = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
sprintf ( line , " Mission base= \" %s \" rank=%.3d dir= \" %s \" \n " , name , m_dialog - > GetSceneRank ( ) , m_dialog - > GetSceneDir ( ) ) ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-09-15 13:33:08 +00:00
sprintf ( line , " Mission base= \" %s \" rank=%.3d \n " , name , m_dialog - > GetSceneRank ( ) ) ;
2012-06-26 20:23:05 +00:00
}
fputs ( line , file ) ;
2012-09-15 13:33:08 +00:00
sprintf ( line , " Map zoom=%.2f \n " , m_map - > GetZoomMap ( ) ) ;
2012-06-26 20:23:05 +00:00
fputs ( line , file ) ;
2012-09-17 22:01:00 +00:00
sprintf ( line , " DoneResearch bits=%d \n " , static_cast < int > ( g_researchDone ) ) ;
2012-06-26 20:23:05 +00:00
fputs ( line , file ) ;
2012-09-15 13:33:08 +00:00
float sleep , delay , magnetic , progress ;
if ( m_lightning - > GetStatus ( sleep , delay , magnetic , progress ) )
2012-06-26 20:23:05 +00:00
{
sprintf ( line , " BlitzMode sleep=%.2f delay=%.2f magnetic=%.2f progress=%.2f \n " , sleep , delay , magnetic / g_unit , progress ) ;
fputs ( line , file ) ;
}
2012-06-26 21:01:17 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
int objRank = 0 ;
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_TOTO ) continue ;
if ( obj - > GetType ( ) = = OBJECT_FIX ) continue ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
if ( obj - > GetBurn ( ) ) continue ;
if ( obj - > GetDead ( ) ) continue ;
if ( obj - > GetExplo ( ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CObject * power = obj - > GetPower ( ) ;
CObject * fret = obj - > GetFret ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( fret ! = nullptr ) // object transported?
IOWriteObject ( file , fret , " CreateFret " ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( power ! = nullptr ) // battery transported?
IOWriteObject ( file , power , " CreatePower " ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
IOWriteObject ( file , obj , " CreateObject " ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
SaveFileScript ( obj , filename , objRank + + ) ;
2012-06-26 20:23:05 +00:00
}
fclose ( file ) ;
2013-05-26 15:47:54 +00:00
2013-04-01 16:24:12 +00:00
RestoreNumericLocale ( ) ;
2012-06-26 20:23:05 +00:00
# if CBOT_STACK
// Writes the file of stacks of execution.
file = fOpen ( filecbot , " wb " ) ;
2012-09-15 13:33:08 +00:00
if ( file = = NULL ) return false ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
long version = 1 ;
2012-06-26 20:23:05 +00:00
fWrite ( & version , sizeof ( long ) , 1 , file ) ; // version of COLOBOT
2012-08-11 18:59:35 +00:00
version = CBotProgram : : GetVersion ( ) ;
2012-06-26 20:23:05 +00:00
fWrite ( & version , sizeof ( long ) , 1 , file ) ; // version of CBOT
objRank = 0 ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_TOTO ) continue ;
if ( obj - > GetType ( ) = = OBJECT_FIX ) continue ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
if ( obj - > GetBurn ( ) ) continue ;
if ( obj - > GetDead ( ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! SaveFileStack ( obj , file , objRank + + ) ) break ;
2012-06-26 20:23:05 +00:00
}
CBotClass : : SaveStaticState ( file ) ;
fClose ( file ) ;
# endif
m_delayWriteMessage = 4 ; // displays message in 3 frames
return true ;
}
2012-09-15 13:33:08 +00:00
//! Resumes the game
2012-09-26 20:57:43 +00:00
CObject * CRobotMain : : IOReadObject ( char * line , const char * filename , int objRank )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
Math : : Vector pos = OpDir ( line , " pos " ) * g_unit ;
Math : : Vector dir = OpDir ( line , " angle " ) * ( Math : : PI / 180.0f ) ;
Math : : Vector zoom = OpDir ( line , " zoom " ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ObjectType type = OpTypeObject ( line , " type " , OBJECT_NULL ) ;
int id = OpInt ( line , " id " , 0 ) ;
if ( type = = OBJECT_NULL )
return nullptr ;
2012-06-26 20:23:05 +00:00
2013-04-01 16:24:12 +00:00
SetNumericLocale ( ) ;
2013-05-26 15:47:54 +00:00
2012-09-15 13:33:08 +00:00
int trainer = OpInt ( line , " trainer " , 0 ) ;
int toy = OpInt ( line , " toy " , 0 ) ;
int option = OpInt ( line , " option " , 0 ) ;
2012-06-26 20:23:05 +00:00
2013-12-29 11:08:59 +00:00
CObject * obj = CObjectManager : : GetInstancePointer ( ) - > CreateObject ( pos , dir . y , type , 0.0f , 1.0f , 0.0f , trainer , toy , option ) ;
2012-09-15 13:33:08 +00:00
obj - > SetDefRank ( objRank ) ;
obj - > SetPosition ( 0 , pos ) ;
obj - > SetAngle ( 0 , dir ) ;
obj - > SetID ( id ) ;
if ( g_id < id ) g_id = id ;
if ( zoom . x ! = 0.0f | | zoom . y ! = 0.0f | | zoom . z ! = 0.0f )
obj - > SetZoom ( 0 , zoom ) ;
for ( int i = 1 ; i < OBJECTMAXPART ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetObjectRank ( i ) = = - 1 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char op [ 10 ] ;
2012-06-26 20:23:05 +00:00
sprintf ( op , " p%d " , i ) ;
2012-09-15 13:33:08 +00:00
pos = OpDir ( line , op ) ;
if ( pos . x ! = 0.0f | | pos . y ! = 0.0f | | pos . z ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetPosition ( i , pos * g_unit ) ;
2012-06-26 20:23:05 +00:00
}
sprintf ( op , " a%d " , i ) ;
2012-09-15 13:33:08 +00:00
dir = OpDir ( line , op ) ;
if ( dir . x ! = 0.0f | | dir . y ! = 0.0f | | dir . z ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetAngle ( i , dir * ( Math : : PI / 180.0f ) ) ;
2012-06-26 20:23:05 +00:00
}
sprintf ( op , " z%d " , i ) ;
zoom = OpDir ( line , op ) ;
2012-09-15 13:33:08 +00:00
if ( zoom . x ! = 0.0f | | zoom . y ! = 0.0f | | zoom . z ! = 0.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetZoom ( i , zoom ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
if ( type = = OBJECT_BASE ) m_base = true ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
obj - > Read ( line ) ;
2012-06-26 20:23:05 +00:00
# if CBOT_STACK
# else
2012-09-15 13:33:08 +00:00
LoadFileScript ( obj , filename , objRank , i ) ;
2012-06-26 20:23:05 +00:00
# endif
2012-06-26 21:01:17 +00:00
2012-09-15 13:33:08 +00:00
int run = OpInt ( line , " run " , - 1 ) ;
if ( run ! = - 1 )
2012-06-26 20:23:05 +00:00
{
# if CBOT_STACK
# else
2012-09-15 13:33:08 +00:00
CBrain * brain = obj - > GetBrain ( ) ;
if ( brain ! = nullptr )
brain - > RunProgram ( run - 1 ) ; // starts the program
2012-06-26 20:23:05 +00:00
# endif
2012-09-15 13:33:08 +00:00
CAuto * automat = obj - > GetAuto ( ) ;
if ( automat ! = nullptr )
automat - > Start ( run ) ; // starts the film
2012-06-26 20:23:05 +00:00
}
2013-04-01 16:24:12 +00:00
RestoreNumericLocale ( ) ;
2013-05-26 15:47:54 +00:00
2012-09-15 13:33:08 +00:00
return obj ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Resumes some part of the game
2012-09-26 20:57:43 +00:00
CObject * CRobotMain : : IOReadScene ( const char * filename , const char * filecbot )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_base = false ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
FILE * file = fopen ( filename , " r " ) ;
if ( file = = NULL ) return 0 ;
2013-05-26 15:47:54 +00:00
2013-04-01 16:24:12 +00:00
SetNumericLocale ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CObject * fret = nullptr ;
CObject * power = nullptr ;
CObject * sel = nullptr ;
int objRank = 0 ;
char line [ 3000 ] ;
while ( fgets ( line , 3000 , file ) ! = NULL )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 3000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( line [ i ] = = ' \t ' ) line [ i ] = ' ' ; // replace tab by space
if ( line [ i ] = = ' / ' & & line [ i + 1 ] = = ' / ' )
2012-06-26 20:23:05 +00:00
{
line [ i ] = 0 ;
break ;
}
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " Map " ) )
2012-06-26 20:23:05 +00:00
m_map - > ZoomMap ( OpFloat ( line , " zoom " , 1.0f ) ) ;
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " DoneResearch " ) )
2012-06-26 20:23:05 +00:00
g_researchDone = OpInt ( line , " bits " , 0 ) ;
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " BlitzMode " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float sleep = OpFloat ( line , " sleep " , 0.0f ) ;
float delay = OpFloat ( line , " delay " , 3.0f ) ;
float magnetic = OpFloat ( line , " magnetic " , 50.0f ) * g_unit ;
float progress = OpFloat ( line , " progress " , 0.0f ) ;
m_lightning - > SetStatus ( sleep , delay , magnetic , progress ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateFret " ) )
fret = IOReadObject ( line , filename , - 1 ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreatePower " ) )
power = IOReadObject ( line , filename , - 1 ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( Cmd ( line , " CreateObject " ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * obj = IOReadObject ( line , filename , objRank + + ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( OpInt ( line , " select " , 0 ) )
sel = obj ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( fret ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetFret ( fret ) ;
2013-02-16 21:37:43 +00:00
CTaskManip * task = new CTaskManip ( obj ) ;
2012-06-26 20:23:05 +00:00
task - > Start ( TMO_AUTO , TMA_GRAB ) ; // holds the object!
delete task ;
}
2012-09-15 13:33:08 +00:00
if ( power ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
obj - > SetPower ( power ) ;
power - > SetTruck ( obj ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
fret = nullptr ;
power = nullptr ;
2012-06-26 20:23:05 +00:00
}
}
fclose ( file ) ;
# if CBOT_STACK
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-06-26 20:23:05 +00:00
// Compiles scripts.
2012-09-15 13:33:08 +00:00
int nbError = 0 ;
int lastError = 0 ;
2012-06-26 20:23:05 +00:00
do
{
lastError = nbError ;
nbError = 0 ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
objRank = obj - > GetDefRank ( ) ;
if ( objRank = = - 1 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
LoadFileScript ( obj , filename , objRank , nbError ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
while ( nbError > 0 & & nbError ! = lastError ) ;
2012-06-26 20:23:05 +00:00
// Reads the file of stacks of execution.
file = fOpen ( filecbot , " rb " ) ;
2012-09-15 13:33:08 +00:00
if ( file ! = NULL )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
long version ;
2012-06-26 20:23:05 +00:00
fRead ( & version , sizeof ( long ) , 1 , file ) ; // version of COLOBOT
2012-09-15 13:33:08 +00:00
if ( version = = 1 )
2012-06-26 20:23:05 +00:00
{
fRead ( & version , sizeof ( long ) , 1 , file ) ; // version of CBOT
2012-09-15 13:33:08 +00:00
if ( version = = CBotProgram : : GetVersion ( ) )
2012-06-26 20:23:05 +00:00
{
objRank = 0 ;
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_TOTO ) continue ;
if ( obj - > GetType ( ) = = OBJECT_FIX ) continue ;
if ( obj - > GetTruck ( ) ! = nullptr ) continue ;
if ( obj - > GetBurn ( ) ) continue ;
if ( obj - > GetDead ( ) ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! ReadFileStack ( obj , file , objRank + + ) ) break ;
2012-06-26 20:23:05 +00:00
}
}
}
CBotClass : : RestoreStaticState ( file ) ;
fClose ( file ) ;
}
# endif
2013-04-01 16:24:12 +00:00
RestoreNumericLocale ( ) ;
2012-09-15 13:33:08 +00:00
return sel ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Writes the global parameters for free play
2012-06-26 20:23:05 +00:00
void CRobotMain : : WriteFreeParam ( )
{
m_freeResearch | = g_researchDone ;
m_freeBuild | = g_build ;
2013-05-01 19:02:43 +00:00
if ( m_gamerName = = " " ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char filename [ MAX_FNAME ] ;
2013-05-01 19:02:43 +00:00
sprintf ( filename , " %s/%s/research.gam " , GetSavegameDir ( ) , m_gamerName . c_str ( ) ) ;
2012-09-15 13:33:08 +00:00
FILE * file = fopen ( filename , " w " ) ;
if ( file = = NULL ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char line [ 100 ] ;
2012-06-26 20:23:05 +00:00
sprintf ( line , " research=%d build=%d \n " , m_freeResearch , m_freeBuild ) ;
fputs ( line , file ) ;
fclose ( file ) ;
}
2012-09-15 13:33:08 +00:00
//! Reads the global parameters for free play
2012-06-26 20:23:05 +00:00
void CRobotMain : : ReadFreeParam ( )
{
m_freeResearch = 0 ;
m_freeBuild = 0 ;
2013-05-01 19:02:43 +00:00
if ( m_gamerName = = " " ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char filename [ MAX_FNAME ] ;
2013-05-01 19:02:43 +00:00
sprintf ( filename , " %s/%s/research.gam " , GetSavegameDir ( ) , m_gamerName . c_str ( ) ) ;
2012-09-15 13:33:08 +00:00
FILE * file = fopen ( filename , " r " ) ;
if ( file = = NULL ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
char line [ 100 ] ;
if ( fgets ( line , 100 , file ) ! = NULL )
2012-06-26 20:23:05 +00:00
sscanf ( line , " research=%d build=%d \n " , & m_freeResearch , & m_freeBuild ) ;
fclose ( file ) ;
}
2012-09-15 13:33:08 +00:00
//! Resets all objects to their original position
2012-06-26 20:23:05 +00:00
void CRobotMain : : ResetObject ( )
{
2012-09-15 13:33:08 +00:00
// TODO: ?
2012-06-26 20:23:05 +00:00
#if 0
2012-09-15 13:33:08 +00:00
CObject * obj ;
CObject * truck ;
CAuto * objAuto ;
2012-06-26 20:23:05 +00:00
CBrain * brain ;
CPyro * pyro ;
ResetCap cap ;
Math : : Vector pos , angle ;
int i ;
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-06-26 20:23:05 +00:00
// Removes all pyrotechnic effects in progress.
while ( true )
{
2013-02-16 21:37:43 +00:00
pyro = static_cast < CPyro * > ( iMan - > SearchInstance ( CLASS_PYRO , 0 ) ) ;
2012-06-26 20:23:05 +00:00
if ( pyro = = 0 ) break ;
pyro - > DeleteObject ( ) ;
delete pyro ;
}
// Removes all bullets in progress.
2012-09-15 13:33:08 +00:00
m_particle - > DeleteParticle ( PARTIGUN1 ) ;
m_particle - > DeleteParticle ( PARTIGUN2 ) ;
m_particle - > DeleteParticle ( PARTIGUN3 ) ;
m_particle - > DeleteParticle ( PARTIGUN4 ) ;
2012-06-26 20:23:05 +00:00
for ( i = 0 ; i < 1000000 ; i + + )
{
2013-02-16 21:37:43 +00:00
obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = 0 ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
cap = obj - > GetResetCap ( ) ;
2012-06-26 20:23:05 +00:00
if ( cap = = RESET_NONE ) continue ;
if ( cap = = RESET_DELETE )
{
2012-09-15 13:33:08 +00:00
truck = obj - > GetTruck ( ) ;
if ( truck ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
truck - > SetFret ( 0 ) ;
obj - > SetTruck ( 0 ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
obj - > DeleteObject ( ) ;
delete obj ;
2012-06-26 20:23:05 +00:00
i - - ;
continue ;
}
2012-09-15 13:33:08 +00:00
objAuto = obj - > GetAuto ( ) ;
if ( objAuto ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
objAuto - > Abort ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
if ( obj - > GetEnable ( ) ) // object still active?
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
brain = obj - > GetBrain ( ) ;
2012-06-26 20:23:05 +00:00
if ( brain ! = 0 )
{
2012-09-15 13:33:08 +00:00
pos = obj - > GetResetPosition ( ) ;
angle = obj - > GetResetAngle ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( pos = = obj - > GetPosition ( 0 ) & &
angle = = obj - > GetAngle ( 0 ) ) continue ;
2012-06-26 20:23:05 +00:00
brain - > StartTaskReset ( pos , angle ) ;
continue ;
}
}
2012-09-15 13:33:08 +00:00
obj - > SetEnable ( true ) ; // active again
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
pos = obj - > GetResetPosition ( ) ;
angle = obj - > GetResetAngle ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( pos = = obj - > GetPosition ( 0 ) & &
angle = = obj - > GetAngle ( 0 ) ) continue ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
pyro = new CPyro ( ) ;
2012-09-15 13:33:08 +00:00
pyro - > Create ( PT_RESET , obj ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
brain = obj - > GetBrain ( ) ;
2012-06-26 20:23:05 +00:00
if ( brain ! = 0 )
{
2012-09-15 13:33:08 +00:00
brain - > RunProgram ( obj - > GetResetRun ( ) ) ;
2012-06-26 20:23:05 +00:00
}
}
# else
2012-09-15 13:33:08 +00:00
m_resetCreate = true ;
2012-06-26 20:23:05 +00:00
# endif
}
2012-09-15 13:33:08 +00:00
//! Resets all objects to their original position
2012-06-26 20:23:05 +00:00
void CRobotMain : : ResetCreate ( )
{
SaveAllScript ( ) ;
// Removes all bullets in progress.
2012-09-15 13:33:08 +00:00
m_particle - > DeleteParticle ( Gfx : : PARTIGUN1 ) ;
m_particle - > DeleteParticle ( Gfx : : PARTIGUN2 ) ;
m_particle - > DeleteParticle ( Gfx : : PARTIGUN3 ) ;
m_particle - > DeleteParticle ( Gfx : : PARTIGUN4 ) ;
2012-06-26 20:23:05 +00:00
DeselectAll ( ) ; // removes the control buttons
DeleteAllObjects ( ) ; // removes all the current 3D Scene
2012-09-15 13:33:08 +00:00
m_particle - > FlushParticle ( ) ;
2012-06-26 20:23:05 +00:00
m_terrain - > FlushBuildingLevel ( ) ;
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
iMan - > Flush ( CLASS_OBJECT ) ;
iMan - > Flush ( CLASS_PHYSICS ) ;
iMan - > Flush ( CLASS_BRAIN ) ;
iMan - > Flush ( CLASS_PYRO ) ;
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_DIALOG ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
CreateScene ( m_dialog - > GetSceneSoluce ( ) , false , true ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( ! GetNiceReset ( ) ) return ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
ResetCap cap = obj - > GetResetCap ( ) ;
if ( cap = = RESET_NONE ) continue ;
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
Gfx : : CPyro * pyro = new Gfx : : CPyro ( ) ;
2012-09-15 13:33:08 +00:00
pyro - > Create ( Gfx : : PT_RESET , obj ) ;
2012-06-26 20:23:05 +00:00
}
}
2013-04-13 09:44:16 +00:00
//! Updates the audiotracks
void CRobotMain : : UpdateAudio ( bool frame )
{
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
for ( int t = 0 ; t < m_audioChangeTotal ; t + + )
{
2013-05-26 15:47:54 +00:00
if ( m_audioChange [ t ] . changed ) continue ;
2013-04-13 13:07:08 +00:00
2013-04-13 09:44:16 +00:00
Math : : Vector bPos = m_audioChange [ t ] . pos ;
bPos . y = 0.0f ;
Math : : Vector oPos ;
int nb = 0 ;
for ( int i = 0 ; i < 1000000 ; i + + )
{
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
if ( obj = = nullptr ) break ;
// Do not use GetActif () because an invisible worm (underground)
// should be regarded as existing here!
if ( obj - > GetLock ( ) ) continue ;
if ( obj - > GetRuin ( ) ) continue ;
if ( ! obj - > GetEnable ( ) ) continue ;
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_SCRAP2 | |
type = = OBJECT_SCRAP3 | |
type = = OBJECT_SCRAP4 | |
type = = OBJECT_SCRAP5 ) // wastes?
{
type = OBJECT_SCRAP1 ;
}
2013-12-29 14:03:21 +00:00
ToolType tool = CObject : : GetToolFromObject ( type ) ;
DriveType drive = CObject : : GetDriveFromObject ( type ) ;
if ( m_audioChange [ t ] . tool ! = TOOL_OTHER ) if ( tool ! = m_audioChange [ t ] . tool ) continue ;
if ( m_audioChange [ t ] . drive ! = DRIVE_OTHER ) if ( drive ! = m_audioChange [ t ] . drive ) continue ;
2013-04-13 09:44:16 +00:00
2013-12-29 14:03:21 +00:00
if ( m_audioChange [ t ] . tool = = TOOL_OTHER & & m_audioChange [ t ] . drive = = DRIVE_OTHER ) if ( type ! = m_audioChange [ t ] . type ) continue ;
2013-04-13 09:44:16 +00:00
2013-04-20 10:08:48 +00:00
float energyLevel = - 1 ;
CObject * power = obj - > GetPower ( ) ;
2013-05-26 15:47:54 +00:00
if ( power ! = nullptr )
{
2013-04-20 10:08:48 +00:00
energyLevel = power - > GetEnergy ( ) ;
if ( power - > GetType ( ) = = OBJECT_ATOMIC ) energyLevel * = 100 ;
}
2013-12-25 17:53:32 +00:00
if ( energyLevel < m_audioChange [ t ] . powermin | | energyLevel > m_audioChange [ t ] . powermax )
continue ;
2013-04-20 10:08:48 +00:00
2013-04-13 09:44:16 +00:00
if ( obj - > GetTruck ( ) = = 0 )
oPos = obj - > GetPosition ( 0 ) ;
else
oPos = obj - > GetTruck ( ) - > GetPosition ( 0 ) ;
oPos . y = 0.0f ;
if ( Math : : DistanceProjected ( oPos , bPos ) < = m_audioChange [ t ] . dist )
nb + + ;
}
if ( nb > = m_audioChange [ t ] . min & &
2013-04-13 13:07:08 +00:00
nb < = m_audioChange [ t ] . max )
2013-04-13 09:44:16 +00:00
{
2013-12-25 17:53:32 +00:00
CLogger : : GetInstancePointer ( ) - > Info ( " Changing music to \" %s \" \n " , m_audioChange [ t ] . music ) ;
2013-04-13 09:44:16 +00:00
m_sound - > PlayMusic ( std : : string ( m_audioChange [ t ] . music ) , m_audioChange [ t ] . repeat ) ;
m_audioChange [ t ] . changed = true ;
}
}
}
2013-04-30 19:43:59 +00:00
void CRobotMain : : SetEndMission ( Error result , float delay )
{
2013-05-26 15:47:54 +00:00
if ( m_controller ! = nullptr )
{
2013-04-30 19:43:59 +00:00
m_endTakeWinDelay = delay ;
m_endTakeLostDelay = delay ;
m_missionResult = result ;
}
}
2012-09-15 13:33:08 +00:00
//! Checks if the mission is over
Error CRobotMain : : CheckEndMission ( bool frame )
2012-06-26 20:23:05 +00:00
{
2013-05-26 15:47:54 +00:00
if ( m_controller ! = nullptr )
{
if ( m_missionResult = = INFO_LOST ) //mission lost?
{
2013-04-30 19:43:59 +00:00
m_displayText - > DisplayError ( INFO_LOST , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_winDelay = 0.0f ;
2013-05-26 15:47:54 +00:00
if ( m_lostDelay = = 0 ) m_lostDelay = m_endTakeLostDelay ;
2013-04-30 19:43:59 +00:00
m_displayText - > SetEnable ( false ) ;
}
2013-05-26 15:47:54 +00:00
if ( m_missionResult = = INFO_LOSTq ) //mission lost?
{
2013-04-30 19:43:59 +00:00
m_winDelay = 0.0f ;
2013-05-26 15:47:54 +00:00
if ( m_lostDelay = = 0 ) m_lostDelay = 0.1f ;
2013-04-30 19:43:59 +00:00
m_displayText - > SetEnable ( false ) ;
}
if ( frame & & m_base ) return ERR_MISSION_NOTERM ;
if ( m_missionResult = = ERR_OK ) { //mission win?
2013-05-01 10:12:32 +00:00
m_displayText - > DisplayError ( INFO_WIN , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
2013-05-26 15:47:54 +00:00
if ( m_winDelay = = 0 ) m_winDelay = m_endTakeWinDelay ;
2013-04-30 19:43:59 +00:00
m_lostDelay = 0.0f ;
m_displayText - > SetEnable ( false ) ;
}
if ( m_missionResult = = ERR_MISSION_NOTERM ) m_displayText - > SetEnable ( true ) ;
return m_missionResult ;
}
2013-04-28 18:05:19 +00:00
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-15 13:33:08 +00:00
for ( int t = 0 ; t < m_endTakeTotal ; t + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_endTake [ t ] . message [ 0 ] ! = 0 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Vector bPos = m_endTake [ t ] . pos ;
2012-06-26 20:23:05 +00:00
bPos . y = 0.0f ;
2012-09-15 13:33:08 +00:00
Math : : Vector oPos ;
int nb = 0 ;
for ( int i = 0 ; i < 1000000 ; i + + )
2012-06-26 20:23:05 +00:00
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2012-09-15 13:33:08 +00:00
if ( obj = = nullptr ) break ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
// Do not use GetActif () because an invisible worm (underground)
2012-06-26 20:23:05 +00:00
// should be regarded as existing here!
2012-09-15 13:33:08 +00:00
if ( obj - > GetLock ( ) ) continue ;
if ( obj - > GetRuin ( ) ) continue ;
if ( ! obj - > GetEnable ( ) ) continue ;
ObjectType type = obj - > GetType ( ) ;
if ( type = = OBJECT_SCRAP2 | |
type = = OBJECT_SCRAP3 | |
type = = OBJECT_SCRAP4 | |
type = = OBJECT_SCRAP5 ) // wastes?
2012-06-26 20:23:05 +00:00
{
type = OBJECT_SCRAP1 ;
}
2013-12-29 14:03:21 +00:00
ToolType tool = CObject : : GetToolFromObject ( type ) ;
DriveType drive = CObject : : GetDriveFromObject ( type ) ;
if ( m_endTake [ t ] . tool ! = TOOL_OTHER ) if ( tool ! = m_endTake [ t ] . tool ) continue ;
if ( m_endTake [ t ] . drive ! = DRIVE_OTHER ) if ( drive ! = m_endTake [ t ] . drive ) continue ;
if ( m_endTake [ t ] . tool = = TOOL_OTHER & & m_endTake [ t ] . drive = = DRIVE_OTHER ) if ( type ! = m_endTake [ t ] . type ) continue ;
2012-09-15 13:33:08 +00:00
2013-04-20 10:08:48 +00:00
float energyLevel = - 1 ;
CObject * power = obj - > GetPower ( ) ;
2013-05-26 15:47:54 +00:00
if ( power ! = nullptr )
{
2013-04-20 10:08:48 +00:00
energyLevel = power - > GetEnergy ( ) ;
if ( power - > GetType ( ) = = OBJECT_ATOMIC ) energyLevel * = 100 ;
}
if ( energyLevel < m_endTake [ t ] . powermin | | energyLevel > m_endTake [ t ] . powermax ) continue ;
2012-09-15 13:33:08 +00:00
if ( obj - > GetTruck ( ) = = 0 )
oPos = obj - > GetPosition ( 0 ) ;
2012-06-26 20:23:05 +00:00
else
2012-09-15 13:33:08 +00:00
oPos = obj - > GetTruck ( ) - > GetPosition ( 0 ) ;
2012-06-26 20:23:05 +00:00
oPos . y = 0.0f ;
2012-09-15 13:33:08 +00:00
if ( Math : : DistanceProjected ( oPos , bPos ) < = m_endTake [ t ] . dist )
2012-06-26 20:23:05 +00:00
nb + + ;
}
2012-09-15 13:33:08 +00:00
if ( nb < = m_endTake [ t ] . lost )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_endTake [ t ] . type = = OBJECT_HUMAN )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_lostDelay = = 0.0f )
2012-06-26 20:23:05 +00:00
{
m_lostDelay = 0.1f ; // lost immediately
m_winDelay = 0.0f ;
}
m_displayText - > SetEnable ( false ) ;
return INFO_LOSTq ;
}
else
{
2012-09-15 13:33:08 +00:00
if ( m_lostDelay = = 0.0f )
2012-06-26 20:23:05 +00:00
{
m_displayText - > DisplayError ( INFO_LOST , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_lostDelay = m_endTakeLostDelay ; // lost in 6 seconds
m_winDelay = 0.0f ;
}
m_displayText - > SetEnable ( false ) ;
return INFO_LOST ;
}
}
2012-09-15 13:33:08 +00:00
if ( nb < m_endTake [ t ] . min | |
2013-04-28 16:33:59 +00:00
nb > m_endTake [ t ] . max | |
2013-04-28 18:05:19 +00:00
m_endTakeNever )
2012-06-26 20:23:05 +00:00
{
m_displayText - > SetEnable ( true ) ;
return ERR_MISSION_NOTERM ;
}
2012-09-15 13:33:08 +00:00
if ( m_endTake [ t ] . immediat )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_winDelay = = 0.0f )
2012-06-26 20:23:05 +00:00
{
m_winDelay = m_endTakeWinDelay ; // wins in x seconds
m_lostDelay = 0.0f ;
}
m_displayText - > SetEnable ( false ) ;
return ERR_OK ; // mission ended
}
}
2012-09-15 13:33:08 +00:00
if ( m_endTakeResearch ! = 0 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_endTakeResearch ! = ( m_endTakeResearch & g_researchDone ) )
2012-06-26 20:23:05 +00:00
{
m_displayText - > SetEnable ( true ) ;
return ERR_MISSION_NOTERM ;
}
}
2012-09-15 13:33:08 +00:00
if ( m_endTakeWinDelay = = - 1.0f )
2012-06-26 20:23:05 +00:00
{
m_winDelay = 1.0f ; // wins in one second
m_lostDelay = 0.0f ;
m_displayText - > SetEnable ( false ) ;
return ERR_OK ; // mission ended
}
2012-09-15 13:33:08 +00:00
if ( frame & & m_base ) return ERR_MISSION_NOTERM ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( m_winDelay = = 0.0f )
2012-06-26 20:23:05 +00:00
{
m_displayText - > DisplayError ( INFO_WIN , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_winDelay = m_endTakeWinDelay ; // wins in two seconds
m_lostDelay = 0.0f ;
}
m_displayText - > SetEnable ( false ) ;
return ERR_OK ; // mission ended
}
2012-09-15 13:33:08 +00:00
//! Checks if the mission is finished after displaying a message
2012-09-15 16:50:51 +00:00
void CRobotMain : : CheckEndMessage ( const char * message )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int t = 0 ; t < m_endTakeTotal ; t + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_endTake [ t ] . message [ 0 ] = = 0 ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( strcmp ( m_endTake [ t ] . message , message ) = = 0 )
2012-06-26 20:23:05 +00:00
{
m_displayText - > DisplayError ( INFO_WIN , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_winDelay = m_endTakeWinDelay ; // wins in 2 seconds
m_lostDelay = 0.0f ;
}
}
}
2012-09-15 13:33:08 +00:00
//! Returns the number of instructions required
int CRobotMain : : GetObligatoryToken ( )
2012-06-26 20:23:05 +00:00
{
return m_obligatoryTotal ;
}
2012-09-15 13:33:08 +00:00
//! Returns the name of a required instruction
char * CRobotMain : : GetObligatoryToken ( int i )
2012-06-26 20:23:05 +00:00
{
return m_obligatoryToken [ i ] ;
}
2012-09-15 13:33:08 +00:00
//! Checks if an instruction is part of the obligatory list
2012-09-15 16:50:51 +00:00
int CRobotMain : : IsObligatoryToken ( const char * token )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < m_obligatoryTotal ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( strcmp ( token , m_obligatoryToken [ i ] ) = = 0 )
2012-06-26 20:23:05 +00:00
return i ;
}
return - 1 ;
}
2012-09-15 13:33:08 +00:00
//! Checks if an instruction is not part of the banned list
2012-09-15 16:50:51 +00:00
bool CRobotMain : : IsProhibitedToken ( const char * token )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
for ( int i = 0 ; i < m_prohibitedTotal ; i + + )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( strcmp ( token , m_prohibitedToken [ i ] ) = = 0 )
2012-06-26 20:23:05 +00:00
return false ;
}
return true ;
}
2012-09-15 13:33:08 +00:00
//! Indicates whether it is possible to control a driving robot
bool CRobotMain : : GetTrainerPilot ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_trainerPilot ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Indicates whether the scene is fixed, without interaction
bool CRobotMain : : GetFixScene ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_fixScene ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
char * CRobotMain : : GetTitle ( )
2012-06-26 20:23:05 +00:00
{
return m_title ;
}
2012-09-15 13:33:08 +00:00
char * CRobotMain : : GetResume ( )
2012-06-26 20:23:05 +00:00
{
return m_resume ;
}
2012-09-15 13:33:08 +00:00
char * CRobotMain : : GetScriptName ( )
2012-06-26 20:23:05 +00:00
{
return m_scriptName ;
}
2012-09-15 13:33:08 +00:00
char * CRobotMain : : GetScriptFile ( )
2012-06-26 20:23:05 +00:00
{
return m_scriptFile ;
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetGlint ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetGlint ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetSoluce4 ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetSoluce4 ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetMovies ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetMovies ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetNiceReset ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetNiceReset ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetHimselfDamage ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetHimselfDamage ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetShowSoluce ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_showSoluce ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetSceneSoluce ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_infoFilename [ SATCOM_SOLUCE ] [ 0 ] = = 0 ) return false ;
return m_dialog - > GetSceneSoluce ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetShowAll ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_showAll ;
2012-06-26 20:23:05 +00:00
}
2012-09-29 23:51:37 +00:00
bool CRobotMain : : GetRadar ( )
2012-06-26 20:23:05 +00:00
{
2012-09-29 23:51:37 +00:00
if ( m_cheatRadar )
return true ;
2013-02-16 21:37:43 +00:00
CInstanceManager * iMan = CInstanceManager : : GetInstancePointer ( ) ;
2012-09-29 23:51:37 +00:00
for ( int i = 0 ; i < 1000000 ; i + + )
{
2013-02-16 21:37:43 +00:00
CObject * obj = static_cast < CObject * > ( iMan - > SearchInstance ( CLASS_OBJECT , i ) ) ;
2013-04-11 13:34:03 +00:00
if ( obj = = nullptr ) break ;
2012-09-29 23:51:37 +00:00
ObjectType type = obj - > GetType ( ) ;
2013-04-11 13:34:03 +00:00
if ( type = = OBJECT_RADAR & & ! obj - > GetLock ( ) )
2012-09-29 23:51:37 +00:00
return true ;
}
return false ;
2012-06-26 20:23:05 +00:00
}
2012-09-26 20:57:43 +00:00
const char * CRobotMain : : GetSavegameDir ( )
2012-06-26 20:23:05 +00:00
{
2012-09-26 20:57:43 +00:00
return m_dialog - > GetSavegameDir ( ) . c_str ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-26 20:57:43 +00:00
const char * CRobotMain : : GetPublicDir ( )
2012-06-26 20:23:05 +00:00
{
2012-09-26 20:57:43 +00:00
return m_dialog - > GetPublicDir ( ) . c_str ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-26 20:57:43 +00:00
const char * CRobotMain : : GetFilesDir ( )
2012-06-26 20:23:05 +00:00
{
2012-09-26 20:57:43 +00:00
return m_dialog - > GetFilesDir ( ) . c_str ( ) ;
2012-06-26 20:23:05 +00:00
}
2013-03-24 18:05:20 +00:00
bool CRobotMain : : GetRetroMode ( )
{
return m_retroStyle ;
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
//! Change the player's name
2012-09-18 20:33:28 +00:00
void CRobotMain : : SetGamerName ( const char * name )
2012-06-26 20:23:05 +00:00
{
2013-05-01 19:02:43 +00:00
m_gamerName = std : : string ( name ) ;
2012-06-26 20:23:05 +00:00
SetGlobalGamerName ( m_gamerName ) ;
ReadFreeParam ( ) ;
}
2013-05-01 19:02:43 +00:00
//! Gets the player's name
2012-09-15 13:33:08 +00:00
char * CRobotMain : : GetGamerName ( )
2012-06-26 20:23:05 +00:00
{
2013-05-01 19:02:43 +00:00
return const_cast < char * > ( m_gamerName . c_str ( ) ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the representation to use for the player
int CRobotMain : : GetGamerFace ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetGamerFace ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the representation to use for the player
int CRobotMain : : GetGamerGlasses ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetGamerGlasses ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the mode with just the head
bool CRobotMain : : GetGamerOnlyHead ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetGamerOnlyHead ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Returns the angle of presentation
float CRobotMain : : GetPersoAngle ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_dialog - > GetPersoAngle ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Changes on the pause mode
void CRobotMain : : ChangePause ( bool pause )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_pause = pause ;
m_engine - > SetPause ( m_pause ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_sound - > MuteAll ( m_pause ) ;
2012-06-26 20:23:05 +00:00
CreateShortcuts ( ) ;
2012-09-15 13:33:08 +00:00
if ( m_pause ) HiliteClear ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Changes game speed
2012-06-26 20:23:05 +00:00
void CRobotMain : : SetSpeed ( float speed )
{
2012-10-06 21:35:27 +00:00
m_app - > SetSimulationSpeed ( speed ) ;
UpdateSpeedLabel ( ) ;
}
float CRobotMain : : GetSpeed ( )
{
return m_app - > GetSimulationSpeed ( ) ;
}
2012-06-26 20:23:05 +00:00
2012-10-06 21:35:27 +00:00
void CRobotMain : : UpdateSpeedLabel ( )
{
2012-10-17 19:48:40 +00:00
Ui : : CButton * pb = static_cast < Ui : : CButton * > ( m_interface - > SearchControl ( EVENT_SPEED ) ) ;
2012-10-06 21:35:27 +00:00
float speed = m_app - > GetSimulationSpeed ( ) ;
2012-10-17 19:48:40 +00:00
2012-09-15 13:33:08 +00:00
if ( pb ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( speed = = 1.0f )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
pb - > ClearState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-09-15 13:33:08 +00:00
char text [ 10 ] ;
2012-06-26 20:23:05 +00:00
sprintf ( text , " x%.1f " , speed ) ;
pb - > SetName ( text ) ;
2012-09-15 13:33:08 +00:00
pb - > SetState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
}
}
}
2012-09-15 13:33:08 +00:00
//! Creates interface shortcuts to the units
2012-06-26 20:23:05 +00:00
bool CRobotMain : : CreateShortcuts ( )
{
2012-09-15 13:33:08 +00:00
if ( m_phase ! = PHASE_SIMUL ) return false ;
if ( ! m_shortCut ) return false ;
2012-06-26 20:23:05 +00:00
return m_short - > CreateShortcuts ( ) ;
}
2012-09-15 13:33:08 +00:00
//! Updates the map
2012-06-26 20:23:05 +00:00
void CRobotMain : : UpdateMap ( )
{
m_map - > UpdateMap ( ) ;
}
2012-09-15 13:33:08 +00:00
//! Indicates whether the mini-map is visible
bool CRobotMain : : GetShowMap ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_map - > GetShowMap ( ) & & m_mapShow ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Management of the lock mode for movies
void CRobotMain : : SetMovieLock ( bool lock )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_movieLock = lock ;
m_engine - > SetMovieLock ( m_movieLock ) ;
2012-06-26 20:23:05 +00:00
CreateShortcuts ( ) ;
2012-09-15 13:33:08 +00:00
m_map - > ShowMap ( ! m_movieLock & & m_mapShow ) ;
if ( m_movieLock ) HiliteClear ( ) ;
2012-09-20 18:37:37 +00:00
if ( m_movieLock )
m_app - > SetMouseMode ( MOUSE_NONE ) ;
else
m_app - > SetMouseMode ( MOUSE_ENGINE ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetMovieLock ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_movieLock ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetInfoLock ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_displayInfo ! = nullptr ; // info in progress?
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Management of the blocking of the call of SatCom
void CRobotMain : : SetSatComLock ( bool lock )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_satComLock = lock ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetSatComLock ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_satComLock ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Management of the lock mode for the edition
void CRobotMain : : SetEditLock ( bool lock , bool edit )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_editLock = lock ;
2012-06-26 20:23:05 +00:00
CreateShortcuts ( ) ;
// Do not remove the card if it contains a still image.
2012-09-15 13:33:08 +00:00
if ( ! lock | | ! m_map - > GetFixImage ( ) )
m_map - > ShowMap ( ! m_editLock & & m_mapShow ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_displayText - > HideText ( lock ) ;
2012-09-15 19:47:19 +00:00
m_app - > ResetKeyStates ( ) ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
if ( m_editLock )
2012-06-26 20:23:05 +00:00
HiliteClear ( ) ;
else
2012-09-15 13:33:08 +00:00
m_editFull = false ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetEditLock ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_editLock ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Management of the fullscreen mode during editing
void CRobotMain : : SetEditFull ( bool full )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_editFull = full ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetEditFull ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_editFull ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetFreePhoto ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_freePhoto ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Indicates whether mouse is on an friend object, on which we should not shoot
void CRobotMain : : SetFriendAim ( bool friendAim )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_friendAim = friendAim ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetFriendAim ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_friendAim ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Management of the precision of drawing the ground
2012-06-26 20:23:05 +00:00
void CRobotMain : : SetTracePrecision ( float factor )
{
m_engine - > SetTracePrecision ( factor ) ;
}
2012-09-15 13:33:08 +00:00
float CRobotMain : : GetTracePrecision ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
return m_engine - > GetTracePrecision ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Starts music with a mission
2012-06-26 20:23:05 +00:00
void CRobotMain : : StartMusic ( )
{
2013-04-13 09:44:16 +00:00
CLogger : : GetInstancePointer ( ) - > Debug ( " Starting music... \n " ) ;
2013-04-13 14:35:35 +00:00
if ( m_audioTrack ! = " " )
2012-06-26 20:23:05 +00:00
{
2013-12-28 11:30:46 +00:00
m_sound - > PlayMusic ( m_audioTrack , m_audioRepeat , 0.0f ) ;
2013-05-26 15:47:54 +00:00
}
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Removes hilite and tooltip
2012-06-26 20:23:05 +00:00
void CRobotMain : : ClearInterface ( )
{
HiliteClear ( ) ; // removes setting evidence
2013-12-02 23:11:26 +00:00
m_tooltipName . clear ( ) ; // really removes the tooltip
2012-06-26 20:23:05 +00:00
}
2013-04-01 16:24:12 +00:00
void CRobotMain : : SetNumericLocale ( )
{
char * locale = setlocale ( LC_NUMERIC , nullptr ) ;
if ( locale ! = nullptr )
m_oldLocale = locale ;
setlocale ( LC_NUMERIC , " C " ) ;
}
void CRobotMain : : RestoreNumericLocale ( )
{
setlocale ( LC_NUMERIC , m_oldLocale . c_str ( ) ) ;
}
2013-05-26 15:47:54 +00:00
2013-06-24 20:09:39 +00:00
void CRobotMain : : DisplayError ( Error err , CObject * pObj , float time )
{
m_displayText - > DisplayError ( err , pObj , time ) ;
}
void CRobotMain : : DisplayError ( Error err , Math : : Vector goal , float height , float dist , float time )
{
m_displayText - > DisplayError ( err , goal , height , dist , time ) ;
}