2014-10-14 13:11:37 +00:00
/*
* This file is part of the Colobot : Gold Edition source code
2016-02-13 13:11:30 +00:00
* Copyright ( C ) 2001 - 2016 , Daniel Roux , EPSITEC SA & TerranovaTeam
2015-08-22 14:40:02 +00:00
* http : //epsitec.ch; http://colobot.info; http://github.com/colobot
2014-10-14 13:11:37 +00:00
*
* 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 : //gnu.org/licenses
*/
2012-06-26 20:23:05 +00:00
2015-08-13 09:47:32 +00:00
# include "level/robotmain.h"
2012-06-26 20:23:05 +00:00
2015-11-22 17:29:25 +00:00
# include "CBot/CBot.h"
2012-09-15 13:33:08 +00:00
# include "app/app.h"
2014-12-11 18:01:57 +00:00
# include "app/input.h"
2015-08-31 19:47:55 +00:00
# include "app/pausemanager.h"
2012-09-20 18:37:37 +00:00
2015-08-02 11:09:48 +00:00
# include "common/config_file.h"
2012-06-26 20:23:05 +00:00
# include "common/event.h"
2012-09-29 23:51:37 +00:00
# include "common/logger.h"
2015-07-17 17:22:31 +00:00
# include "common/make_unique.h"
2012-06-26 20:23:05 +00:00
# include "common/restext.h"
2015-08-04 10:45:52 +00:00
# include "common/settings.h"
2015-07-22 10:45:50 +00:00
# include "common/stringutils.h"
2012-09-20 18:37:37 +00:00
2014-06-22 19:30:23 +00:00
# include "common/resources/inputstream.h"
2014-11-10 17:49:00 +00:00
# include "common/resources/outputstream.h"
2015-08-02 11:09:48 +00:00
# include "common/resources/resourcemanager.h"
2014-06-22 19:30:23 +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"
2015-07-09 16:45:02 +00:00
# include "graphics/engine/oldmodelmanager.h"
2012-09-15 13:33:08 +00:00
# include "graphics/engine/particle.h"
# include "graphics/engine/planet.h"
2015-06-22 19:58:58 +00:00
# include "graphics/engine/pyro_manager.h"
2012-09-15 13:33:08 +00:00
# include "graphics/engine/terrain.h"
# include "graphics/engine/text.h"
# include "graphics/engine/water.h"
2015-08-02 11:09:48 +00:00
2015-07-11 17:48:37 +00:00
# include "graphics/model/model_manager.h"
2012-09-20 18:37:37 +00:00
2015-08-13 09:47:32 +00:00
# include "level/mainmovie.h"
# include "level/player_profile.h"
# include "level/scene_conditions.h"
2017-05-17 16:22:27 +00:00
# include "level/scoreboard.h"
2015-08-13 09:47:32 +00:00
# include "level/parser/parser.h"
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/object.h"
2015-07-14 16:20:05 +00:00
# include "object/object_create_exception.h"
2015-06-20 18:02:40 +00:00
# include "object/object_manager.h"
2015-08-02 11:09:48 +00:00
# include "object/auto/auto.h"
# include "object/motion/motion.h"
# include "object/motion/motionhuman.h"
# include "object/motion/motiontoto.h"
# include "object/subclass/exchange_post.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/script.h"
2014-12-20 17:45:46 +00:00
# include "script/scriptfunc.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
2016-03-28 11:51:39 +00:00
# include "ui/debug_menu.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"
2012-06-26 20:23:05 +00:00
# include "ui/maindialog.h"
# include "ui/mainmap.h"
2012-09-15 13:33:08 +00:00
# include "ui/mainshort.h"
2015-08-06 10:59:09 +00:00
# include "ui/mainui.h"
2015-08-07 18:48:55 +00:00
# include "ui/controls/button.h"
# include "ui/controls/edit.h"
2015-09-27 14:28:11 +00:00
# include "ui/controls/group.h"
2015-08-07 18:48:55 +00:00
# include "ui/controls/interface.h"
# include "ui/controls/label.h"
2015-08-06 11:25:24 +00:00
# include "ui/controls/map.h"
# include "ui/controls/shortcut.h"
# include "ui/controls/slider.h"
# include "ui/controls/window.h"
2012-09-15 13:33:08 +00:00
2015-08-07 18:48:55 +00:00
# include "ui/screen/screen_loading.h"
2016-05-15 17:42:27 +00:00
# include <algorithm>
2013-05-26 17:34:05 +00:00
# include <iomanip>
2015-08-14 17:02:56 +00:00
# include <stdexcept>
2016-04-09 16:52:15 +00:00
# include <ctime>
2012-09-15 13:33:08 +00:00
2014-09-24 20:54:26 +00:00
# include <boost/lexical_cast.hpp>
2014-01-18 18:20:40 +00:00
2012-06-26 20:23:05 +00:00
// Global variables.
2015-08-15 21:37:30 +00:00
const float UNIT = 4.0f ; // default for g_unit
2012-06-26 20:23:05 +00:00
float g_unit ; // conversion factor
2016-03-27 11:34:26 +00:00
// Reference colors used when recoloring textures, see ChangeColor()
const Gfx : : Color COLOR_REF_BOT = Gfx : : Color ( 10.0f / 256.0f , 166.0f / 256.0f , 254.0f / 256.0f ) ; // blue
const Gfx : : Color COLOR_REF_ALIEN = Gfx : : Color ( 135.0f / 256.0f , 170.0f / 256.0f , 13.0f / 256.0f ) ; // green
const Gfx : : Color COLOR_REF_GREEN = Gfx : : Color ( 135.0f / 256.0f , 170.0f / 256.0f , 13.0f / 256.0f ) ; // green
const Gfx : : Color COLOR_REF_WATER = Gfx : : Color ( 25.0f / 256.0f , 255.0f / 256.0f , 240.0f / 256.0f ) ; // cyan
2012-09-15 13:33:08 +00:00
//! Constructor of robot application
2015-08-06 10:59:09 +00:00
CRobotMain : : CRobotMain ( )
2014-12-22 09:35:05 +00:00
{
2015-08-06 10:59:09 +00:00
m_app = CApplication : : GetInstancePointer ( ) ;
2014-12-22 09:35:05 +00:00
2015-08-06 10:59:09 +00:00
m_eventQueue = m_app - > GetEventQueue ( ) ;
m_sound = m_app - > GetSound ( ) ;
2014-12-22 09:35:05 +00:00
2015-08-06 10:59:09 +00:00
m_engine = Gfx : : CEngine : : GetInstancePointer ( ) ;
m_oldModelManager = m_engine - > GetModelManager ( ) ;
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 ( ) ;
m_input = CInput : : GetInstancePointer ( ) ;
2015-08-14 21:11:24 +00:00
m_modelManager = MakeUnique < Gfx : : CModelManager > ( ) ;
m_settings = MakeUnique < CSettings > ( ) ;
2015-10-01 16:55:41 +00:00
m_pause = MakeUnique < CPauseManager > ( ) ;
2015-08-14 21:11:24 +00:00
m_interface = MakeUnique < Ui : : CInterface > ( ) ;
m_terrain = MakeUnique < Gfx : : CTerrain > ( ) ;
m_camera = MakeUnique < Gfx : : CCamera > ( ) ;
m_displayText = MakeUnique < Ui : : CDisplayText > ( ) ;
m_movie = MakeUnique < CMainMovie > ( ) ;
2015-08-06 10:59:09 +00:00
m_ui = MakeUnique < Ui : : CMainUserInterface > ( ) ;
2015-08-14 21:11:24 +00:00
m_short = MakeUnique < Ui : : CMainShort > ( ) ;
m_map = MakeUnique < Ui : : CMainMap > ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-14 21:11:24 +00:00
m_objMan = MakeUnique < CObjectManager > (
m_engine ,
m_terrain . get ( ) ,
m_oldModelManager ,
m_modelManager . get ( ) ,
m_particle ) ;
2015-08-06 10:59:09 +00:00
2016-03-28 11:51:39 +00:00
m_debugMenu = MakeUnique < Ui : : CDebugMenu > ( this , m_engine , m_objMan . get ( ) , m_sound ) ;
2012-06-26 20:23:05 +00:00
m_time = 0.0f ;
m_gameTime = 0.0f ;
2015-07-09 21:15:30 +00:00
m_gameTimeAbsolute = 0.0f ;
2015-06-20 17:27:43 +00:00
2015-08-04 08:52:10 +00:00
m_levelCategory = LevelCategory : : Exercises ;
m_levelChap = 0 ;
m_levelRank = 0 ;
m_sceneReadPath = " " ;
2014-10-29 16:53:46 +00:00
m_missionTimerEnabled = false ;
m_missionTimerStarted = false ;
m_missionTimer = 0.0f ;
2012-06-26 20:23:05 +00:00
2015-07-19 21:11:41 +00:00
m_phase = PHASE_PLAYER_SELECT ;
2012-06-26 20:23:05 +00:00
m_visitLast = EVENT_NULL ;
2015-08-17 20:40:52 +00:00
m_visitObject = nullptr ;
m_visitArrow = nullptr ;
2013-04-13 14:35:35 +00:00
m_audioTrack = " " ;
2012-09-15 13:33:08 +00:00
m_audioRepeat = true ;
2014-02-21 13:19:58 +00:00
m_satcomTrack = " " ;
m_satcomRepeat = true ;
m_editorTrack = " " ;
m_editorRepeat = true ;
2015-08-17 20:40:52 +00:00
m_selectObject = nullptr ;
2012-06-26 20:23:05 +00:00
m_infoUsed = 0 ;
2013-04-29 15:26:32 +00:00
m_controller = nullptr ;
2015-06-26 20:07:55 +00:00
m_missionType = MISSION_NORMAL ;
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_hilite = false ;
2016-12-27 22:38:57 +00:00
m_cheatSelectInsect = false ;
m_cheatShowSoluce = false ;
2013-06-21 23:11:37 +00:00
2015-06-26 20:07:55 +00:00
m_codeBattleInit = false ;
m_codeBattleStarted = false ;
2015-07-07 19:25:13 +00:00
m_teamNames . clear ( ) ;
2013-06-21 23:11:37 +00:00
# if DEV_BUILD
2016-12-27 22:38:57 +00:00
m_cheatAllMission = true ; // for development
2013-06-21 23:11:37 +00:00
# else
2016-12-27 22:38:57 +00:00
m_cheatAllMission = 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 ;
2016-12-27 22:38:57 +00:00
m_cheatTrainerPilot = false ;
2012-09-15 13:33:08 +00:00
m_friendAim = false ;
m_resetCreate = false ;
m_shortCut = true ;
2015-06-21 18:59:23 +00:00
2012-06-26 20:23:05 +00:00
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 ;
2012-09-15 13:33:08 +00:00
m_winTerminate = false ;
2015-06-21 18:59:23 +00:00
2015-07-15 16:10:49 +00:00
m_globalMagnifyDamage = 1.0f ;
2014-11-11 13:50:44 +00:00
m_autosave = true ;
2015-04-06 20:04:23 +00:00
m_autosaveInterval = 5 ;
2014-11-11 13:50:44 +00:00
m_autosaveSlots = 3 ;
m_autosaveLast = 0.0f ;
2012-06-26 20:23:05 +00:00
2015-08-06 18:15:17 +00:00
m_shotSaving = 0 ;
2015-07-13 15:38:19 +00:00
m_build = 0 ;
2015-07-13 16:13:28 +00:00
m_researchDone . clear ( ) ; // no research done
m_researchDone [ 0 ] = 0 ;
2015-07-13 15:38:19 +00:00
m_researchEnable = 0 ;
2014-12-22 09:35:05 +00:00
g_unit = UNIT ;
for ( int i = 0 ; i < MAXSHOWLIMIT ; i + + )
{
m_showLimit [ i ] . used = false ;
m_showLimit [ i ] . total = 0 ;
2015-08-17 20:40:52 +00:00
m_showLimit [ i ] . link = nullptr ;
2014-12-22 09:35:05 +00:00
}
2015-06-20 17:27:43 +00:00
2016-03-17 03:31:16 +00:00
m_debugCrashSpheres = false ;
2015-08-14 21:11:24 +00:00
m_engine - > SetTerrain ( m_terrain . get ( ) ) ;
2015-06-21 18:59:23 +00:00
2015-07-14 19:03:27 +00:00
m_app - > SetMouseMode ( MOUSE_ENGINE ) ;
2014-12-22 09:35:05 +00:00
m_movie - > Flush ( ) ;
2015-06-21 18:59:23 +00:00
2014-12-22 09:35:05 +00:00
FlushDisplayInfo ( ) ;
2015-06-21 18:59:23 +00:00
2012-06-26 20:23:05 +00:00
InitEye ( ) ;
2015-06-21 18:59:23 +00:00
2012-06-26 20:23:05 +00:00
m_engine - > SetTracePrecision ( 1.0f ) ;
2015-06-21 18:59:23 +00:00
2016-01-24 15:03:24 +00:00
m_settings - > LoadSettings ( ) ;
m_settings - > SaveSettings ( ) ;
m_settings - > SaveResolutionSettings ( m_app - > GetVideoConfig ( ) ) ;
2015-07-19 13:34:49 +00:00
SelectPlayer ( CPlayerProfile : : GetLastName ( ) ) ;
2015-06-21 18:59:23 +00:00
2014-12-20 17:45:46 +00:00
CScriptFunctions : : Init ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Destructor of robot application
2012-06-26 20:23:05 +00:00
CRobotMain : : ~ CRobotMain ( )
{
2012-09-15 13:33:08 +00:00
}
2012-06-26 20:23:05 +00:00
2013-02-16 21:37:43 +00:00
Gfx : : CCamera * CRobotMain : : GetCamera ( )
{
2015-08-14 21:11:24 +00:00
return m_camera . get ( ) ;
2013-02-16 21:37:43 +00:00
}
Gfx : : CTerrain * CRobotMain : : GetTerrain ( )
{
2015-08-14 21:11:24 +00:00
return m_terrain . get ( ) ;
2013-02-16 21:37:43 +00:00
}
Ui : : CInterface * CRobotMain : : GetInterface ( )
{
2015-08-14 21:11:24 +00:00
return m_interface . get ( ) ;
2013-02-16 21:37:43 +00:00
}
Ui : : CDisplayText * CRobotMain : : GetDisplayText ( )
{
2015-08-14 21:11:24 +00:00
return m_displayText . get ( ) ;
2013-02-16 21:37:43 +00:00
}
2015-10-01 16:55:41 +00:00
CPauseManager * CRobotMain : : GetPauseManager ( )
{
return m_pause . get ( ) ;
}
2015-08-15 15:07:21 +00:00
std : : string PhaseToString ( Phase phase )
{
if ( phase = = PHASE_WELCOME1 ) return " PHASE_WELCOME1 " ;
if ( phase = = PHASE_WELCOME2 ) return " PHASE_WELCOME2 " ;
if ( phase = = PHASE_WELCOME3 ) return " PHASE_WELCOME3 " ;
if ( phase = = PHASE_PLAYER_SELECT ) return " PHASE_PLAYER_SELECT " ;
if ( phase = = PHASE_APPERANCE ) return " PHASE_APPERANCE " ;
if ( phase = = PHASE_MAIN_MENU ) return " PHASE_MAIN_MENU " ;
if ( phase = = PHASE_LEVEL_LIST ) return " PHASE_LEVEL_LIST " ;
if ( phase = = PHASE_SIMUL ) return " PHASE_SIMUL " ;
if ( phase = = PHASE_SETUPd ) return " PHASE_SETUPd " ;
if ( phase = = PHASE_SETUPg ) return " PHASE_SETUPg " ;
if ( phase = = PHASE_SETUPp ) return " PHASE_SETUPp " ;
if ( phase = = PHASE_SETUPc ) return " PHASE_SETUPc " ;
if ( phase = = PHASE_SETUPs ) return " PHASE_SETUPs " ;
if ( phase = = PHASE_SETUPds ) return " PHASE_SETUPds " ;
if ( phase = = PHASE_SETUPgs ) return " PHASE_SETUPgs " ;
if ( phase = = PHASE_SETUPps ) return " PHASE_SETUPps " ;
if ( phase = = PHASE_SETUPcs ) return " PHASE_SETUPcs " ;
if ( phase = = PHASE_SETUPss ) return " PHASE_SETUPss " ;
if ( phase = = PHASE_WRITEs ) return " PHASE_WRITEs " ;
if ( phase = = PHASE_READ ) return " PHASE_READ " ;
if ( phase = = PHASE_READs ) return " PHASE_READs " ;
if ( phase = = PHASE_WIN ) return " PHASE_WIN " ;
if ( phase = = PHASE_LOST ) return " PHASE_LOST " ;
if ( phase = = PHASE_QUIT_SCREEN ) return " PHASE_QUIT_SCREEN " ;
2016-02-10 16:04:26 +00:00
if ( phase = = PHASE_SATCOM ) return " PHASE_SATCOM " ;
2015-08-15 15:07:21 +00:00
return " (unknown) " ;
}
2015-08-04 21:28:58 +00:00
bool IsInSimulationConfigPhase ( Phase phase )
{
return ( phase > = PHASE_SETUPds & & phase < = PHASE_SETUPss ) | | phase = = PHASE_READs | | phase = = PHASE_WRITEs ;
}
bool IsPhaseWithWorld ( Phase phase )
{
if ( phase = = PHASE_SIMUL ) return true ;
if ( phase = = PHASE_WIN ) return true ;
if ( phase = = PHASE_LOST ) return true ;
if ( phase = = PHASE_APPERANCE ) return true ;
if ( IsInSimulationConfigPhase ( phase ) ) return true ;
return false ;
}
2015-08-06 12:03:07 +00:00
bool IsMainMenuPhase ( Phase phase )
{
2015-08-18 17:33:01 +00:00
if ( phase = = PHASE_APPERANCE ) return true ;
2015-08-06 12:03:07 +00:00
return ! IsPhaseWithWorld ( phase ) ;
}
2012-09-15 13:33:08 +00:00
//! Changes phase
2012-06-26 20:23:05 +00:00
void CRobotMain : : ChangePhase ( Phase phase )
{
2015-08-05 20:54:08 +00:00
bool resetWorld = false ;
if ( ( IsPhaseWithWorld ( m_phase ) | | IsPhaseWithWorld ( phase ) ) & & ! IsInSimulationConfigPhase ( m_phase ) & & ! IsInSimulationConfigPhase ( phase ) )
2015-08-04 21:28:58 +00:00
{
2016-03-27 11:46:48 +00:00
if ( IsPhaseWithWorld ( m_phase ) & & ! IsPhaseWithWorld ( phase ) & & m_exitAfterMission )
{
GetLogger ( ) - > Info ( " Mission finished in single mission mode, exiting \n " ) ;
m_eventQueue - > AddEvent ( Event ( EVENT_QUIT ) ) ;
return ;
}
2015-08-05 20:54:08 +00:00
GetLogger ( ) - > Info ( " Reseting world on phase change... \n " ) ;
resetWorld = true ;
2015-08-04 21:28:58 +00:00
}
2015-08-05 20:54:08 +00:00
if ( resetWorld )
2012-06-26 20:23:05 +00:00
{
2015-08-05 20:54:08 +00:00
m_missionTimerEnabled = m_missionTimerStarted = false ;
m_missionTimer = 0.0f ;
2012-06-26 20:23:05 +00:00
2015-08-05 20:54:08 +00:00
if ( m_phase = = PHASE_SIMUL ) // ends a simulation?
2012-06-26 20:23:05 +00:00
{
2015-08-05 20:54:08 +00:00
SaveAllScript ( ) ;
m_sound - > StopMusic ( 0.0f ) ;
2015-08-17 20:40:52 +00:00
m_camera - > SetControllingObject ( nullptr ) ;
2015-08-05 20:54:08 +00:00
if ( m_gameTime > 10.0f ) // did you play at least 10 seconds?
{
m_playerProfile - > IncrementLevelTryCount ( m_levelCategory , m_levelChap , m_levelRank ) ;
}
2016-02-13 19:40:23 +00:00
if ( m_userPause ! = nullptr )
{
m_pause - > DeactivatePause ( m_userPause ) ;
m_userPause = nullptr ;
}
2012-06-26 20:23:05 +00:00
}
2015-08-05 20:54:08 +00:00
if ( phase = = PHASE_WIN ) // wins a simulation?
{
m_playerProfile - > SetLevelPassed ( m_levelCategory , m_levelChap , m_levelRank , true ) ;
2015-08-06 10:59:09 +00:00
m_ui - > NextMission ( ) ; // passes to the next mission
2015-08-05 20:54:08 +00:00
}
2012-06-26 20:23:05 +00:00
2015-08-05 20:54:08 +00:00
DeleteAllObjects ( ) ; // removes all the current 3D Scene
}
2012-06-26 20:23:05 +00:00
2015-08-05 20:54:08 +00:00
m_phase = phase ;
2012-09-15 13:33:08 +00:00
2015-11-08 18:03:35 +00:00
if ( m_phase ! = PHASE_SIMUL )
{
2015-11-10 21:33:02 +00:00
Ui : : CWindow * pw = static_cast < Ui : : CWindow * > ( m_interface - > SearchControl ( EVENT_WINDOW6 ) ) ;
if ( pw ! = nullptr ) pw - > ClearState ( Ui : : STATE_VISIBLE | Ui : : STATE_ENABLE ) ;
}
2012-09-15 13:33:08 +00:00
2015-08-05 20:54:08 +00:00
if ( resetWorld )
{
m_winDelay = 0.0f ;
m_lostDelay = 0.0f ;
m_beginSatCom = false ;
m_movieLock = false ;
m_satComLock = false ;
m_editLock = false ;
m_resetCreate = false ;
m_infoObject = nullptr ;
2015-08-31 19:47:55 +00:00
m_pause - > FlushPause ( ) ;
2015-10-01 16:55:41 +00:00
m_freePhotoPause = nullptr ;
m_userPause = nullptr ;
2016-02-16 11:26:44 +00:00
m_focusPause = nullptr ;
2015-08-05 20:54:08 +00:00
FlushDisplayInfo ( ) ;
m_engine - > SetRankView ( 0 ) ;
m_terrain - > FlushRelief ( ) ;
m_engine - > DeleteAllObjects ( ) ;
m_oldModelManager - > DeleteAllModelCopies ( ) ;
m_engine - > SetWaterAddColor ( Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ;
m_engine - > SetBackground ( " " ) ;
m_engine - > SetBackForce ( false ) ;
m_engine - > SetForegroundName ( " " ) ;
m_engine - > SetOverColor ( ) ;
m_engine - > DeleteGroundMark ( 0 ) ;
SetSpeed ( 1.0f ) ;
m_terrain - > SetWind ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_terrain - > FlushBuildingLevel ( ) ;
m_terrain - > FlushFlyingLimit ( ) ;
m_lightMan - > FlushLights ( ) ;
m_particle - > FlushParticle ( ) ;
m_water - > Flush ( ) ;
m_cloud - > Flush ( ) ;
m_lightning - > Flush ( ) ;
m_planet - > Flush ( ) ;
m_interface - > Flush ( ) ;
2016-12-27 22:38:57 +00:00
m_newScriptName . clear ( ) ;
2015-08-05 20:54:08 +00:00
m_sound - > SetListener ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) , Math : : Vector ( 0.0f , 0.0f , 1.0f ) ) ;
2016-02-09 19:05:04 +00:00
m_sound - > StopAll ( ) ;
2016-05-28 10:50:32 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_NULL ) ;
2015-08-05 20:54:08 +00:00
m_movie - > Flush ( ) ;
m_movieInfoIndex = - 1 ;
m_shortCut = true ;
}
2015-08-06 14:14:11 +00:00
ClearInterface ( ) ;
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 ;
2015-07-14 19:32:08 +00:00
pos . x = 20.0f / 640.0f ;
pos . y = 100.0f / 480.0f ;
2015-08-06 18:15:17 +00:00
Ui : : CEdit * pe = m_interface - > CreateEdit ( pos , dim , 0 , EVENT_CMD ) ;
2012-09-15 13:33:08 +00:00
pe - > ClearState ( Ui : : STATE_VISIBLE ) ;
2015-07-18 21:16:14 +00:00
pe - > SetMaxChar ( 100 ) ;
2012-09-15 13:33:08 +00:00
m_cmdEdit = false ; // hidden for now
2012-06-26 20:23:05 +00:00
// Creates the speedometer.
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
2015-08-06 18:15:17 +00:00
// Creates the save indicator
2012-09-15 13:33:08 +00:00
Ui : : CButton * pb = m_interface - > CreateButton ( pos , dim , 0 , EVENT_SPEED ) ;
pb - > SetState ( Ui : : STATE_SIMPLY ) ;
pb - > ClearState ( Ui : : STATE_VISIBLE ) ;
2012-06-26 20:23:05 +00:00
2015-08-17 18:56:42 +00:00
if ( m_phase = = PHASE_PLAYER_SELECT )
{
if ( CResourceManager : : DirectoryExists ( " crashsave " ) )
{
GetLogger ( ) - > Info ( " Pre-crash save found! \n " ) ;
2015-10-03 20:05:14 +00:00
m_ui - > GetDialog ( ) - > StartQuestion (
" Your game seems to have crashed. Do you want to restore pre-crash state? " , false , false , false ,
[ & ] ( )
{
GetLogger ( ) - > Info ( " Trying to restore pre-crash state... \n " ) ;
assert ( m_playerProfile ! = nullptr ) ;
m_playerProfile - > LoadScene ( " ../../crashsave " ) ;
CResourceManager : : RemoveDirectory ( " crashsave " ) ;
} ,
[ & ] ( )
{
GetLogger ( ) - > Info ( " Not restoring pre-crash state \n " ) ;
CResourceManager : : RemoveDirectory ( " crashsave " ) ;
}
) ;
2015-08-17 18:56:42 +00:00
}
}
2015-08-06 10:59:09 +00:00
m_ui - > ChangePhase ( m_phase ) ;
2016-02-10 16:04:26 +00:00
if ( m_phase = = PHASE_SATCOM )
{
m_interface - > DeleteControl ( EVENT_WINDOW5 ) ;
StartDisplayInfo ( InjectLevelPathsForCurrentLevel ( " cbot.txt " , " help/%lng% " ) , 0 ) ;
}
2015-08-05 20:54:08 +00:00
if ( ! resetWorld ) return ;
2012-06-26 20:23:05 +00:00
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
2015-07-19 21:11:41 +00:00
if ( m_phase ! = PHASE_APPERANCE )
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_SIMUL )
2012-06-26 20:23:05 +00:00
{
2015-08-04 08:52:10 +00:00
bool loading = ! m_sceneReadPath . empty ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-07 18:48:55 +00:00
m_ui - > ShowLoadingScreen ( true ) ;
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.0f , RT_LOADING_INIT ) ;
2012-06-26 20:23:05 +00:00
m_map - > CreateMap ( ) ;
2015-08-07 18:48:55 +00:00
m_map - > ShowMap ( false ) ;
2015-06-21 18:59:23 +00:00
try
{
2015-08-06 10:59:09 +00:00
CreateScene ( m_ui - > GetSceneSoluce ( ) , false , false ) ; // interactive scene
2014-09-24 20:54:26 +00:00
if ( m_mapImage )
m_map - > SetFixImage ( m_mapFilename ) ;
2012-09-15 13:33:08 +00:00
2014-09-24 20:54:26 +00:00
m_app - > ResetTimeAfterLoading ( ) ;
2013-06-13 15:25:58 +00:00
2016-02-05 19:38:03 +00:00
m_sound - > StopMusic ( 0.0f ) ;
if ( m_base = = nullptr | | loading ) StartMusic ( ) ;
2014-09-24 20:54:26 +00:00
if ( m_immediatSatCom & & ! loading & &
m_infoFilename [ SATCOM_HUSTON ] [ 0 ] ! = 0 )
StartDisplayInfo ( SATCOM_HUSTON , false ) ; // shows the instructions
}
2015-07-14 16:46:22 +00:00
catch ( const std : : runtime_error & e )
2014-09-24 20:54:26 +00:00
{
2016-03-30 11:40:26 +00:00
LevelLoadingError ( " An error occurred while trying to load a level " , e ) ;
2014-09-24 20:54:26 +00:00
}
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 ( ) ;
2016-05-27 21:37:36 +00:00
if ( m_endingWin . empty ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-19 21:07:36 +00:00
ChangePhase ( PHASE_LEVEL_LIST ) ;
2012-06-26 20:23:05 +00:00
}
else
{
2016-05-27 21:37:36 +00:00
m_winTerminate = ( m_endingWin . substr ( m_endingWin . find_last_of ( " / " ) + 1 ) = = " win904.txt " ) ;
m_levelFile = m_endingWin ;
2015-06-21 18:59:23 +00:00
try
{
2014-09-24 20:54:26 +00:00
CreateScene ( false , true , false ) ; // sets scene
2012-06-26 20:23:05 +00:00
2014-09-24 20:54:26 +00:00
pos . x = ox + sx * 1 ; pos . y = oy + sy * 1 ;
Math : : Point ddim ;
ddim . x = dim . x * 2 ; ddim . y = dim . y * 2 ;
m_interface - > CreateButton ( pos , ddim , 16 , EVENT_BUTTON_OK ) ;
2012-06-26 20:23:05 +00:00
2014-09-24 20:54:26 +00:00
if ( m_winTerminate )
{
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 ) ;
pe - > SetFontType ( Gfx : : FONT_COLOBOT ) ;
pe - > SetEditCap ( false ) ;
pe - > SetHighlightCap ( false ) ;
pe - > ReadText ( std : : string ( " help/ " ) + m_app - > GetLanguageChar ( ) + std : : string ( " /win.txt " ) ) ;
}
else
{
m_displayText - > DisplayError ( INFO_WIN , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 15.0f , 60.0f , 1000.0f ) ;
}
StartMusic ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-14 16:46:22 +00:00
catch ( const std : : runtime_error & e )
2012-06-26 20:23:05 +00:00
{
2016-03-30 11:40:26 +00:00
LevelLoadingError ( " An error occurred while trying to load win scene " , e ) ;
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 ( ) ;
2016-05-27 21:37:36 +00:00
if ( m_endingLost . empty ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-19 21:07:36 +00:00
ChangePhase ( PHASE_LEVEL_LIST ) ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-09-15 13:33:08 +00:00
m_winTerminate = false ;
2016-05-27 21:37:36 +00:00
m_levelFile = m_endingLost ;
2015-06-21 18:59:23 +00:00
try
{
2014-09-24 20:54:26 +00:00
CreateScene ( false , true , false ) ; // sets scene
2012-06-26 20:23:05 +00:00
2014-09-24 20:54:26 +00:00
pos . x = ox + sx * 1 ; pos . y = oy + sy * 1 ;
Math : : Point ddim ;
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
2014-09-24 20:54:26 +00:00
StartMusic ( ) ;
}
2015-07-14 16:46:22 +00:00
catch ( const std : : runtime_error & e )
2014-09-24 20:54:26 +00:00
{
2016-03-30 11:40:26 +00:00
LevelLoadingError ( " An error occurred while trying to load lost scene " , e ) ;
2014-09-24 20:54:26 +00:00
}
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
}
2015-08-15 15:07:21 +00:00
Phase CRobotMain : : GetPhase ( )
{
return m_phase ;
}
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
{
2015-08-06 10:59:09 +00:00
if ( ! m_ui - > EventProcess ( event ) ) return false ;
2016-03-28 11:51:39 +00:00
if ( m_phase = = PHASE_SIMUL )
{
if ( ! m_editFull )
m_camera - > EventProcess ( event ) ;
}
if ( ! m_debugMenu - > EventProcess ( event ) ) return false ;
2015-08-06 10:59:09 +00:00
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
{
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_satcomMoviePause ) ;
m_satcomMoviePause = nullptr ;
2012-06-26 20:23:05 +00:00
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_displayText - > 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 ) ;
2015-06-21 18:59:23 +00:00
2014-10-29 16:53:46 +00:00
UpdateInfoText ( ) ;
2012-09-15 13:33:08 +00:00
2012-06-26 20:23:05 +00:00
return EventFrame ( event ) ;
}
2016-03-26 17:55:39 +00:00
if ( event . type = = EVENT_RELOAD_TEXTURES )
{
if ( IsPhaseWithWorld ( m_phase ) )
{
ChangeColor ( ) ;
UpdateMap ( ) ;
}
2016-06-19 17:57:55 +00:00
m_engine - > LoadAllTextures ( ) ;
2016-03-26 17:55:39 +00:00
}
if ( event . type = = EVENT_RESOLUTION_CHANGED )
{
// Recreate the interface (needed if the aspect ratio changes)
// TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
CreateShortcuts ( ) ;
}
2016-02-13 20:35:01 +00:00
if ( event . type = = EVENT_FOCUS_LOST )
{
GetLogger ( ) - > Trace ( " Window unfocused \n " ) ;
if ( m_settings - > GetFocusLostPause ( ) )
{
m_focusPause = m_pause - > ActivatePause ( PAUSE_ENGINE ) ;
}
return false ;
}
if ( event . type = = EVENT_FOCUS_GAINED )
{
GetLogger ( ) - > Trace ( " Window focused \n " ) ;
if ( m_focusPause ! = nullptr )
{
m_pause - > DeactivatePause ( m_focusPause ) ;
2016-02-15 18:05:32 +00:00
m_focusPause = nullptr ;
2016-02-13 20:35:01 +00:00
}
return false ;
}
2015-08-04 18:30:31 +00:00
if ( event . type = = EVENT_WRITE_SCENE_FINISHED )
{
IOWriteSceneFinished ( ) ;
return false ;
}
2015-09-06 17:12:00 +00:00
if ( event . type = = EVENT_UPDINTERFACE )
{
if ( m_missionType = = MISSION_CODE_BATTLE & & ! m_codeBattleStarted )
{
CreateCodeBattleInterface ( ) ;
}
}
if ( event . type = = EVENT_CODE_BATTLE_START )
{
m_pause - > DeactivatePause ( m_userPause ) ;
m_userPause = nullptr ;
}
2015-09-13 13:59:42 +00:00
if ( event . type = = EVENT_CODE_BATTLE_SPECTATOR )
{
SetCodeBattleSpectatorMode ( ! m_codeBattleSpectator ) ;
}
2012-06-26 20:23:05 +00:00
// Management of the console.
2016-02-10 16:06:02 +00:00
if ( event . type = = EVENT_KEY_DOWN )
2012-09-15 13:33:08 +00:00
{
2016-02-10 16:06:02 +00:00
auto data = event . GetData < KeyEventData > ( ) ;
if ( data - > slot = = INPUT_SLOT_CMDLINE )
2015-04-06 15:23:18 +00:00
{
2016-02-10 16:06:02 +00:00
if ( m_phase ! = PHASE_PLAYER_SELECT & &
! m_movie - > IsExist ( ) & &
! m_movieLock & & ! m_editLock & & ! m_cmdEdit )
{
Ui : : CEdit * pe = static_cast < Ui : : CEdit * > ( m_interface - > SearchControl ( EVENT_CMD ) ) ;
if ( pe = = nullptr ) return false ;
pe - > SetState ( Ui : : STATE_VISIBLE ) ;
m_interface - > SetFocus ( pe ) ;
if ( m_phase = = PHASE_SIMUL ) m_cmdEditPause = m_pause - > ActivatePause ( PAUSE_ENGINE ) ;
m_cmdEdit = true ;
2017-01-02 19:23:19 +00:00
m_commandHistoryIndex = - 1 ; // no element selected in command history
2016-02-10 16:06:02 +00:00
}
return false ;
2015-04-06 15:23:18 +00:00
}
2016-03-28 11:51:39 +00:00
if ( IsPhaseWithWorld ( m_phase ) )
{
if ( data - > key = = KEY ( F11 ) )
{
m_debugMenu - > ToggleInterface ( ) ;
return false ;
}
}
2012-06-26 20:23:05 +00:00
}
2015-08-06 15:51:28 +00:00
2017-01-02 19:23:19 +00:00
// Browse forward command history with UP key
if ( event . type = = EVENT_KEY_DOWN & &
event . GetData < KeyEventData > ( ) - > key = = KEY ( UP ) & & m_cmdEdit )
{
Ui : : CEdit * pe = static_cast < Ui : : CEdit * > ( m_interface - > SearchControl ( EVENT_CMD ) ) ;
if ( pe = = nullptr ) return false ;
std : : string cmd = GetNextFromCommandHistory ( ) ;
if ( ! cmd . empty ( ) ) pe - > SetText ( cmd ) ;
return false ;
}
// Browse backward command history with DOWN key
if ( event . type = = EVENT_KEY_DOWN & &
event . GetData < KeyEventData > ( ) - > key = = KEY ( DOWN ) & & m_cmdEdit )
{
Ui : : CEdit * pe = static_cast < Ui : : CEdit * > ( m_interface - > SearchControl ( EVENT_CMD ) ) ;
if ( pe = = nullptr ) return false ;
std : : string cmd = GetPreviousFromCommandHistory ( ) ;
if ( ! cmd . empty ( ) ) pe - > SetText ( cmd ) ;
return false ;
}
2012-09-15 13:33:08 +00:00
if ( event . type = = EVENT_KEY_DOWN & &
2015-08-06 15:51:28 +00:00
event . GetData < KeyEventData > ( ) - > key = = KEY ( RETURN ) & & m_cmdEdit )
2012-06-26 20:23:05 +00:00
{
2016-09-25 17:13:04 +00:00
std : : string cmd ;
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 ;
2016-09-25 17:13:04 +00:00
cmd = pe - > GetText ( 50 ) ;
2012-06-26 20:23:05 +00:00
pe - > SetText ( " " ) ;
2012-09-15 13:33:08 +00:00
pe - > ClearState ( Ui : : STATE_VISIBLE ) ;
2016-02-10 16:06:02 +00:00
m_interface - > SetFocus ( nullptr ) ;
2015-08-31 19:47:55 +00:00
if ( m_phase = = PHASE_SIMUL )
{
m_pause - > DeactivatePause ( m_cmdEditPause ) ;
m_cmdEditPause = nullptr ;
}
2012-06-26 20:23:05 +00:00
ExecuteCmd ( cmd ) ;
2017-01-02 19:23:19 +00:00
PushToCommandHistory ( cmd ) ;
2012-09-15 13:33:08 +00:00
m_cmdEdit = false ;
2012-06-26 20:23:05 +00:00
return false ;
}
2015-07-15 17:08:45 +00:00
if ( event . type = = EVENT_KEY_DOWN & & m_cmdEdit )
return false ; // cheat console active, so ignore keys
2012-06-26 20:23:05 +00:00
// 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_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
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
{
2015-08-06 15:51:28 +00:00
auto data = event . GetData < KeyEventData > ( ) ;
if ( data - > slot = = INPUT_SLOT_HELP | |
data - > slot = = INPUT_SLOT_PROG | |
data - > 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
2016-02-10 16:04:26 +00:00
if ( m_displayInfo = = nullptr & & m_phase = = PHASE_SATCOM )
ChangePhase ( PHASE_MAIN_MENU ) ;
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
{
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 :
2015-08-06 15:51:28 +00:00
{
auto data = event . GetData < KeyEventData > ( ) ;
2012-06-26 20:23:05 +00:00
HiliteClear ( ) ;
2012-09-15 13:33:08 +00:00
if ( m_editLock ) // current edition?
2012-06-26 20:23:05 +00:00
{
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_HELP )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_HUSTON , false ) ;
return false ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_PROG )
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
{
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_QUIT | |
data - > 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
{
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_VISIT )
2012-06-26 20:23:05 +00:00
{
StartDisplayVisit ( EVENT_NULL ) ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_QUIT | |
data - > key = = KEY ( ESCAPE ) )
2012-06-26 20:23:05 +00:00
{
StopDisplayVisit ( ) ;
}
return false ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_QUIT )
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 )
2015-08-06 14:02:59 +00:00
m_ui - > GetDialog ( ) - > StartPauseMenu ( ) ; // do you want to leave?
2012-06-26 20:23:05 +00:00
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_PAUSE )
2012-06-26 20:23:05 +00:00
{
2015-08-31 19:47:55 +00:00
if ( m_userPause = = nullptr )
{
2015-10-01 16:55:41 +00:00
if ( ! m_pause - > IsPauseType ( PAUSE_ENGINE ) )
2015-08-31 19:47:55 +00:00
{
2015-10-01 16:55:41 +00:00
m_userPause = m_pause - > ActivatePause ( PAUSE_ENGINE ) ;
2015-08-31 19:47:55 +00:00
}
}
else
2012-06-26 20:23:05 +00:00
{
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_userPause ) ;
m_userPause = nullptr ;
2012-06-26 20:23:05 +00:00
}
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_CAMERA )
2012-06-26 20:23:05 +00:00
{
ChangeCamera ( ) ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_DESEL )
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 ( ) ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_HUMAN )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
SelectObject ( SearchHuman ( ) ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_NEXT & & ( ( event . kmodState & KEY_MOD ( CTRL ) ) ! = 0 ) )
2015-03-22 15:02:05 +00:00
{
2015-07-16 11:46:05 +00:00
m_short - > SelectShortcut ( EVENT_OBJECT_SHORTCUT_MODE ) ; // switch bots <-> buildings
2015-03-22 15:02:05 +00:00
return false ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_NEXT )
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 ( ) ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_HELP )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_HUSTON , true ) ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_PROG )
2012-06-26 20:23:05 +00:00
{
StartDisplayInfo ( SATCOM_PROG , true ) ;
}
2015-08-06 15:51:28 +00:00
if ( data - > slot = = INPUT_SLOT_VISIT )
2012-06-26 20:23:05 +00:00
{
StartDisplayVisit ( EVENT_NULL ) ;
}
2017-06-11 15:50:21 +00:00
if ( data - > slot = = INPUT_SLOT_SPEED_DEC )
2014-12-14 16:05:28 +00:00
{
2017-06-11 15:50:21 +00:00
SetSpeed ( GetSpeed ( ) * 0.5f ) ;
2014-12-14 16:05:28 +00:00
}
2017-06-11 15:50:21 +00:00
if ( data - > slot = = INPUT_SLOT_SPEED_RESET )
2012-06-26 20:23:05 +00:00
{
SetSpeed ( 1.0f ) ;
}
2017-06-11 15:50:21 +00:00
if ( data - > slot = = INPUT_SLOT_SPEED_INC )
2012-06-26 20:23:05 +00:00
{
2017-06-11 15:50:21 +00:00
SetSpeed ( GetSpeed ( ) * 2.0f ) ;
2012-06-26 20:23:05 +00:00
}
2017-06-11 15:50:21 +00:00
if ( data - > slot = = INPUT_SLOT_QUICKSAVE )
2012-06-26 20:23:05 +00:00
{
2017-06-11 15:50:21 +00:00
QuickSave ( ) ;
2012-06-26 20:23:05 +00:00
}
2017-06-11 15:50:21 +00:00
if ( data - > slot = = INPUT_SLOT_QUICKLOAD )
2014-12-14 16:05:28 +00:00
{
2017-06-11 15:50:21 +00:00
QuickLoad ( ) ;
2015-07-10 18:17:00 +00:00
}
2015-08-06 15:51:28 +00:00
if ( data - > key = = KEY ( c ) & & ( ( event . kmodState & KEY_MOD ( CTRL ) ) ! = 0 ) & & m_engine - > GetShowStats ( ) )
2015-03-22 15:32:21 +00:00
{
CObject * obj = GetSelect ( ) ;
2015-06-21 18:59:23 +00:00
if ( obj ! = nullptr )
{
2015-07-17 17:22:31 +00:00
CLevelParserLine line ( " CreateObject " ) ;
2015-07-17 18:36:01 +00:00
line . AddParam ( " type " , MakeUnique < CLevelParserParam > ( obj - > GetType ( ) ) ) ;
2016-08-20 11:22:53 +00:00
2015-08-03 20:26:22 +00:00
Math : : Vector pos = obj - > GetPosition ( ) / g_unit ;
pos . y = 0.0f ;
line . AddParam ( " pos " , MakeUnique < CLevelParserParam > ( pos ) ) ;
2016-08-20 11:22:53 +00:00
float dir = Math : : NormAngle ( obj - > GetRotationY ( ) ) / Math : : PI ;
line . AddParam ( " dir " , MakeUnique < CLevelParserParam > ( dir ) ) ;
2015-07-10 09:51:59 +00:00
std : : stringstream ss ;
2015-07-17 17:22:31 +00:00
ss < < line ;
2015-09-24 19:09:46 +00:00
SDL_SetClipboardText ( ss . str ( ) . c_str ( ) ) ;
2015-03-22 15:32:21 +00:00
}
}
2012-06-26 20:23:05 +00:00
break ;
2015-08-06 15:51:28 +00:00
}
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
case EVENT_MOUSE_BUTTON_DOWN :
2015-08-06 15:51:28 +00:00
{
if ( event . GetData < MouseButtonEventData > ( ) - > 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
2015-08-06 15:51:28 +00:00
{
2012-09-15 13:33:08 +00:00
SelectObject ( obj ) ;
2015-08-06 15:51:28 +00:00
}
2012-06-26 20:23:05 +00:00
break ;
2015-08-06 15:51:28 +00:00
}
2012-06-26 20:23:05 +00:00
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_DELETE :
2015-10-03 20:05:14 +00:00
m_ui - > GetDialog ( ) - > StartQuestion (
RT_DIALOG_DELOBJ , true , false , false ,
[ & ] ( )
{
DestroySelectedObject ( ) ;
}
) ;
2012-06-26 20:23:05 +00:00
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_MOVIELOCK :
AbortMovie ( ) ;
break ;
case EVENT_WIN :
2014-10-29 16:53:46 +00:00
m_missionTimerEnabled = m_missionTimerStarted = false ;
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_WIN ) ;
break ;
case EVENT_LOST :
2014-10-29 16:53:46 +00:00
m_missionTimerEnabled = m_missionTimerStarted = false ;
2012-06-26 20:23:05 +00:00
ChangePhase ( PHASE_LOST ) ;
break ;
2012-09-15 13:33:08 +00:00
default :
break ;
2012-06-26 20:23:05 +00:00
}
2015-07-16 11:46:05 +00:00
if ( event . type > = EVENT_OBJECT_SHORTCUT_MODE & & event . type < = EVENT_OBJECT_SHORTCUT_MAX )
{
m_short - > SelectShortcut ( event . type ) ;
}
2012-06-26 20:23:05 +00:00
EventObject ( event ) ;
return false ;
}
2015-07-19 21:11:41 +00:00
if ( m_phase = = PHASE_APPERANCE )
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 :
2015-08-06 15:51:28 +00:00
{
auto data = event . GetData < KeyEventData > ( ) ;
if ( data - > key = = KEY ( ESCAPE ) | |
data - > key = = KEY ( RETURN ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( m_winTerminate )
2015-07-19 21:11:41 +00:00
ChangePhase ( PHASE_MAIN_MENU ) ;
2012-06-26 20:23:05 +00:00
else
2015-07-19 21:07:36 +00:00
ChangePhase ( PHASE_LEVEL_LIST ) ;
2012-06-26 20:23:05 +00:00
}
break ;
2015-08-06 15:51:28 +00:00
}
2012-06-26 20:23:05 +00:00
case EVENT_BUTTON_OK :
2012-09-15 13:33:08 +00:00
if ( m_winTerminate )
2015-07-19 21:11:41 +00:00
ChangePhase ( PHASE_MAIN_MENU ) ;
2012-06-26 20:23:05 +00:00
else
2015-07-19 21:07:36 +00:00
ChangePhase ( PHASE_LEVEL_LIST ) ;
2015-06-21 18:59:23 +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
2016-03-26 18:05:58 +00:00
void CRobotMain : : ExecuteCmd ( const std : : string & cmd )
2012-06-26 20:23:05 +00:00
{
2016-03-26 18:05:58 +00:00
if ( cmd . empty ( ) ) 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
{
2016-03-26 18:05:58 +00:00
if ( cmd = = " winmission " )
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_WIN ) ) ;
2012-06-26 20:23:05 +00:00
2016-03-26 18:05:58 +00:00
if ( cmd = = " lostmission " )
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_LOST ) ) ;
2012-06-26 20:23:05 +00:00
2016-03-26 18:05:58 +00:00
if ( cmd = = " trainerpilot " )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
m_cheatTrainerPilot = ! m_cheatTrainerPilot ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " fly " )
2012-06-26 20:23:05 +00:00
{
2015-07-13 16:13:28 +00:00
m_researchDone [ 0 ] | = RESEARCH_FLY ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " allresearch " )
2012-06-26 20:23:05 +00:00
{
2015-07-13 16:13:28 +00:00
m_researchDone [ 0 ] = - 1 ; // all research are done
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " allbuildings " )
2013-04-12 20:52:32 +00:00
{
2015-07-13 15:38:19 +00:00
m_build = - 1 ; // all buildings are available
2013-04-12 20:52:32 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " all " )
2013-04-12 20:52:32 +00:00
{
2015-07-13 16:13:28 +00:00
m_researchDone [ 0 ] = - 1 ; // all research are done
2015-07-13 15:38:19 +00:00
m_build = - 1 ; // all buildings are available
2013-04-12 20:52:32 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " nolimit " )
2012-06-26 20:23:05 +00:00
{
m_terrain - > SetFlyingMaxHeight ( 280.0f ) ;
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " controller " )
2013-04-29 15:26:32 +00:00
{
2016-04-08 18:56:09 +00:00
if ( m_controller = = nullptr )
2013-05-26 15:47:54 +00:00
{
2016-04-08 18:56:09 +00:00
GetLogger ( ) - > Error ( " No LevelController on the map to select \n " ) ;
return ;
}
2013-04-29 15:26:32 +00:00
2016-04-08 18:56:09 +00:00
// Don't use SelectObject because it checks if the object is selectable
if ( m_camera - > GetType ( ) = = Gfx : : CAM_TYPE_VISIT )
StopDisplayVisit ( ) ;
2013-04-29 15:26:32 +00:00
2016-04-08 18:56:09 +00:00
CObject * prev = DeselectAll ( ) ;
if ( prev ! = nullptr & & prev ! = m_controller )
PushToSelectionHistory ( prev ) ;
SelectOneObject ( m_controller , true ) ;
m_short - > UpdateShortcuts ( ) ;
2013-04-29 15:26:32 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " photo1 " )
2012-06-26 20:23:05 +00:00
{
2015-10-01 16:55:41 +00:00
if ( m_freePhotoPause = = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_FREE ) ;
2015-10-01 16:55:41 +00:00
m_freePhotoPause = m_pause - > ActivatePause ( PAUSE_ENGINE | PAUSE_PHOTO | PAUSE_OBJECT_UPDATES ) ;
2012-06-26 20:23:05 +00:00
}
else
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_BACK ) ;
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_freePhotoPause ) ;
m_freePhotoPause = nullptr ;
2012-06-26 20:23:05 +00:00
}
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " photo2 " )
2012-06-26 20:23:05 +00:00
{
2015-10-01 16:55:41 +00:00
if ( m_freePhotoPause = = nullptr )
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
DeselectAll ( ) ; // removes the control buttons
2015-10-01 16:55:41 +00:00
m_freePhotoPause = m_pause - > ActivatePause ( PAUSE_ENGINE | PAUSE_PHOTO | PAUSE_OBJECT_UPDATES ) ;
2012-06-26 20:23:05 +00:00
m_map - > ShowMap ( false ) ;
m_displayText - > HideText ( true ) ;
}
else
{
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_BACK ) ;
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_freePhotoPause ) ;
m_freePhotoPause = nullptr ;
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 ;
}
2015-09-04 16:34:49 +00:00
int camtype ;
2016-03-26 18:05:58 +00:00
if ( sscanf ( cmd . c_str ( ) , " camtype %d " , & camtype ) > 0 )
2015-09-04 16:34:49 +00:00
{
m_camera - > SetType ( static_cast < Gfx : : CameraType > ( camtype ) ) ;
return ;
}
float camspeed ;
2016-03-26 18:05:58 +00:00
if ( sscanf ( cmd . c_str ( ) , " camspeed %f " , & camspeed ) > 0 )
2015-09-04 16:34:49 +00:00
{
m_camera - > SetCameraSpeed ( camspeed ) ;
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " freecam " )
2015-09-04 16:34:49 +00:00
{
m_camera - > SetType ( Gfx : : CAM_TYPE_FREE ) ;
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " noclip " )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2015-08-11 15:51:39 +00:00
object - > SetCollisions ( false ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " clip " )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
if ( object ! = nullptr )
2015-08-11 15:51:39 +00:00
object - > SetCollisions ( true ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " addhusky " )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
2015-08-13 11:41:25 +00:00
if ( object ! = nullptr & & object - > Implements ( ObjectInterfaceType : : Shielded ) )
dynamic_cast < CShieldedObject * > ( object ) - > SetMagnifyDamage ( dynamic_cast < CShieldedObject * > ( object ) - > GetMagnifyDamage ( ) * 0.1f ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " addfreezer " )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
2015-08-12 17:09:35 +00:00
if ( object ! = nullptr & & object - > Implements ( ObjectInterfaceType : : JetFlying ) )
dynamic_cast < CJetFlyingObject * > ( object ) - > SetRange ( dynamic_cast < CJetFlyingObject * > ( object ) - > GetRange ( ) * 10.0f ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2013-05-26 15:47:54 +00:00
2016-03-26 18:05:58 +00:00
if ( cmd = = " \155 \157 \157 " )
2012-09-29 23:51:37 +00:00
{
// 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
2016-03-26 18:05:58 +00:00
if ( cmd = = " fullpower " )
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
{
2015-07-10 21:47:59 +00:00
if ( object - > Implements ( ObjectInterfaceType : : Powered ) )
{
CObject * power = dynamic_cast < CPoweredObject * > ( object ) - > GetPower ( ) ;
2015-08-11 20:51:09 +00:00
if ( power ! = nullptr & & power - > Implements ( ObjectInterfaceType : : PowerContainer ) )
dynamic_cast < CPowerContainerObject * > ( power ) - > SetEnergyLevel ( 1.0f ) ;
2015-07-10 21:47:59 +00:00
}
2012-09-15 13:33:08 +00:00
2015-08-13 11:41:25 +00:00
if ( object - > Implements ( ObjectInterfaceType : : Shielded ) )
dynamic_cast < CShieldedObject * > ( object ) - > SetShield ( 1.0f ) ;
2015-07-12 13:09:32 +00:00
2015-08-13 08:49:26 +00:00
if ( object - > Implements ( ObjectInterfaceType : : JetFlying ) )
dynamic_cast < CJetFlyingObject * > ( object ) - > SetReactorRange ( 1.0f ) ;
2012-06-26 20:23:05 +00:00
}
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " fullenergy " )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
2015-07-10 21:47:59 +00:00
2012-09-15 13:33:08 +00:00
if ( object ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-07-10 21:47:59 +00:00
if ( object - > Implements ( ObjectInterfaceType : : Powered ) )
{
CObject * power = dynamic_cast < CPoweredObject * > ( object ) - > GetPower ( ) ;
2015-08-11 20:51:09 +00:00
if ( power ! = nullptr & & power - > Implements ( ObjectInterfaceType : : PowerContainer ) )
dynamic_cast < CPowerContainerObject * > ( power ) - > SetEnergyLevel ( 1.0f ) ;
2015-07-10 21:47:59 +00:00
}
2012-06-26 20:23:05 +00:00
}
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " fullshield " )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * object = GetSelect ( ) ;
2015-08-13 11:41:25 +00:00
if ( object ! = nullptr & & object - > Implements ( ObjectInterfaceType : : Shielded ) )
dynamic_cast < CShieldedObject * > ( object ) - > SetShield ( 1.0f ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " fullrange " )
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
{
2015-08-13 08:49:26 +00:00
if ( object - > Implements ( ObjectInterfaceType : : JetFlying ) )
dynamic_cast < CJetFlyingObject * > ( object ) - > SetReactorRange ( 1.0f ) ;
2012-06-26 20:23:05 +00:00
}
return ;
}
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " debugmode " )
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 ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " showstat " )
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 ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " invui " )
2015-09-12 08:35:31 +00:00
{
m_engine - > SetRenderInterface ( ! m_engine - > GetRenderInterface ( ) ) ;
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " selectinsect " )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
m_cheatSelectInsect = ! m_cheatSelectInsect ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " showsoluce " )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
m_cheatShowSoluce = ! m_cheatShowSoluce ;
2015-08-06 10:59:09 +00:00
m_ui - > ShowSoluceUpdate ( ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " allmission " )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
m_cheatAllMission = ! m_cheatAllMission ;
2015-08-06 10:59:09 +00:00
m_ui - > AllMissionUpdate ( ) ;
2012-06-26 20:23:05 +00:00
return ;
}
2016-03-26 18:05:58 +00:00
if ( cmd = = " invradar " )
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 ;
}
2015-07-10 18:45:50 +00:00
float speed ;
2016-03-26 18:05:58 +00:00
if ( sscanf ( cmd . c_str ( ) , " speed %f " , & speed ) > 0 )
2013-05-26 15:47:54 +00:00
{
2015-07-10 18:45:50 +00:00
SetSpeed ( speed ) ;
2013-04-12 20:52:32 +00:00
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 ;
}
2013-05-26 09:34:53 +00:00
strcpy ( m_infoFilename [ SATCOM_OBJECT ] , " objects.txt " ) ;
2012-06-26 20:23:05 +00:00
}
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
{
2015-08-13 08:49:26 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Movable ) ) ;
if ( dynamic_cast < CMovableObject * > ( obj ) - > GetMotion ( ) - > GetAction ( ) = = - 1 )
2012-06-26 20:23:05 +00:00
{
m_movieInfoIndex = index ;
m_movie - > Start ( MM_SATCOMopen , 2.5f ) ;
2015-10-01 16:55:41 +00:00
m_satcomMoviePause = m_pause - > ActivatePause ( PAUSE_ENGINE | PAUSE_HIDE_SHORTCUTS ) ;
2012-06-26 20:23:05 +00:00
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 ( ) ;
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_satcomMoviePause ) ;
m_satcomMoviePause = nullptr ;
2012-06-26 20:23:05 +00:00
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
2015-08-11 20:47:07 +00:00
void CRobotMain : : StartDisplayInfo ( const std : : string & 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 ) ;
}
2015-08-06 10:59:09 +00:00
bool soluce = m_ui - > GetSceneSoluce ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-14 21:11:24 +00:00
m_displayInfo = MakeUnique < Ui : : CDisplayInfo > ( ) ;
2012-09-15 13:33:08 +00:00
m_displayInfo - > StartDisplayInfo ( filename , index , soluce ) ;
2015-10-01 18:10:52 +00:00
m_displayInfo - > SetPosition ( 0 ) ;
2012-06-26 20:23:05 +00:00
}
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 ) ;
m_displayInfo - > StopDisplayInfo ( ) ;
2015-08-14 21:11:24 +00:00
m_displayInfo . reset ( ) ;
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
{
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
//! Beginning of a dialogue during the game
2012-06-26 20:23:05 +00:00
void CRobotMain : : StartSuspend ( )
{
2016-07-04 15:02:39 +00:00
if ( m_suspend ! = nullptr ) return ; // already suspended
2016-06-19 20:18:03 +00:00
if ( ! IsPhaseWithWorld ( m_phase ) ) return ;
2016-07-04 15:02:39 +00:00
GetLogger ( ) - > Info ( " Start suspend \n " ) ;
2016-06-19 20:18:03 +00:00
2015-08-04 21:28:58 +00:00
m_sound - > MuteAll ( true ) ;
ClearInterface ( ) ;
2016-07-04 15:02:39 +00:00
m_suspend = m_pause - > ActivatePause ( PAUSE_ENGINE | PAUSE_HIDE_SHORTCUTS | PAUSE_MUTE_SOUND | PAUSE_CAMERA ) ;
2015-08-04 21:28:58 +00:00
m_engine - > SetOverFront ( false ) ; // over flat behind
CreateShortcuts ( ) ;
2012-06-26 20:23:05 +00:00
m_map - > ShowMap ( false ) ;
m_infoObject = DeselectAll ( ) ; // removes the control buttons
m_displayText - > HideText ( true ) ;
2016-05-21 12:27:35 +00:00
m_engine - > EnablePauseBlur ( ) ;
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 ( )
{
2016-07-04 15:02:39 +00:00
if ( m_suspend = = nullptr ) return ; // not suspended
GetLogger ( ) - > Info ( " Stop suspend \n " ) ;
2015-08-04 21:28:58 +00:00
m_sound - > MuteAll ( false ) ;
ClearInterface ( ) ;
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_suspend ) ;
m_suspend = nullptr ;
2015-08-04 21:28:58 +00:00
m_engine - > SetOverFront ( true ) ; // over flat front
CreateShortcuts ( ) ;
2016-07-04 15:02:39 +00:00
if ( m_infoObject ! = nullptr )
2015-08-04 21:28:58 +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 ) ;
2016-05-21 12:27:35 +00:00
m_engine - > DisablePauseBlur ( ) ;
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
//! 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
2016-03-29 20:29:24 +00:00
if ( m_visitPause )
{
m_pause - > DeactivatePause ( m_visitPause ) ;
m_visitPause = nullptr ;
}
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.
2015-08-17 20:40:52 +00:00
if ( m_interface - > SearchControl ( EVENT_DT_END ) = = 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
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.
2015-08-17 20:40:52 +00:00
if ( m_visitArrow ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-06-21 09:16:09 +00:00
CObjectManager : : GetInstancePointer ( ) - > DeleteObject ( m_visitArrow ) ;
m_visitArrow = nullptr ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
2015-08-14 16:19:58 +00:00
ObjectCreateParams params ;
params . pos = m_displayText - > GetVisitGoal ( event ) ;
params . type = OBJECT_SHOW ;
params . height = 10.0f ;
m_visitArrow = m_objMan - > CreateObject ( params ) ;
2012-06-26 20:23:05 +00:00
2015-07-12 09:01:16 +00:00
m_visitPos = m_visitArrow - > GetPosition ( ) ;
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 ) ;
2015-07-13 21:19:46 +00:00
m_visitArrow - > SetPosition ( m_visitPosArrow ) ;
2012-06-26 20:23:05 +00:00
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 ) ;
2015-10-01 16:55:41 +00:00
m_visitPause = m_pause - > ActivatePause ( PAUSE_ENGINE ) ;
2012-06-26 20:23:05 +00:00
}
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 )
{
2015-08-17 20:40:52 +00:00
if ( m_visitArrow = = nullptr ) 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 ;
2015-07-13 21:19:46 +00:00
m_visitArrow - > SetPosition ( pos ) ;
2015-07-14 19:29:13 +00:00
m_visitArrow - > SetRotationY ( m_visitTime * 2.0f ) ;
2012-06-26 20:23:05 +00:00
// 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
{
2015-06-21 09:16:09 +00:00
CObjectManager : : GetInstancePointer ( ) - > DeleteObject ( 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 ( ) ;
2015-08-31 19:47:55 +00:00
m_pause - > DeactivatePause ( m_visitPause ) ;
m_visitPause = nullptr ;
2015-08-17 20:40:52 +00:00
if ( m_visitObject ! = nullptr )
2012-06-26 20:23:05 +00:00
{
SelectObject ( m_visitObject , false ) ; // gives the command buttons
2015-08-17 20:40:52 +00:00
m_visitObject = nullptr ;
2012-06-26 20:23:05 +00:00
}
}
void CRobotMain : : UpdateShortcuts ( )
{
m_short - > UpdateShortcuts ( ) ;
}
2012-09-15 13:33:08 +00:00
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 ( ) ;
}
CObject * CRobotMain : : DeselectAll ( )
{
2012-09-15 13:33:08 +00:00
CObject * prev = nullptr ;
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-10 21:20:36 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Controllable ) ) continue ;
auto controllableObj = dynamic_cast < CControllableObject * > ( obj ) ;
if ( controllableObj - > GetSelect ( ) ) prev = obj ;
controllableObj - > 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
{
2015-08-10 21:20:36 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Controllable ) ) ;
dynamic_cast < CControllableObject * > ( 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 | |
2017-11-16 17:43:45 +00:00
type = = OBJECT_MOBILEfb | |
type = = OBJECT_MOBILEtb | |
type = = OBJECT_MOBILEwb | |
type = = OBJECT_MOBILEib | |
2012-06-26 20:23:05 +00:00
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 )
{
2015-08-10 21:20:36 +00:00
m_camera - > SetType ( dynamic_cast < CControllableObject * > ( obj ) - > GetCameraType ( ) ) ;
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
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 ( ) ;
2015-06-26 20:07:55 +00:00
if ( m_movieLock | | m_editLock ) return false ;
2012-09-15 13:33:08 +00:00
if ( m_movie - > IsExist ( ) ) return false ;
2016-12-27 21:20:58 +00:00
if ( obj ! = nullptr & &
2016-12-27 22:38:57 +00:00
( ! obj - > Implements ( ObjectInterfaceType : : Controllable ) | | ! ( dynamic_cast < CControllableObject * > ( obj ) - > GetSelectable ( ) | | m_cheatSelectInsect ) ) ) return false ;
2012-06-26 20:23:05 +00:00
2015-09-13 13:59:42 +00:00
if ( m_missionType = = MISSION_CODE_BATTLE & & m_codeBattleStarted & & m_codeBattleSpectator )
2015-09-06 17:59:26 +00:00
{
2015-09-09 18:32:56 +00:00
DeselectAll ( ) ;
2015-09-06 17:59:26 +00:00
// During code battles, only change camera
2015-09-06 18:09:47 +00:00
m_camera - > SetControllingObject ( obj ) ;
2015-09-06 17:59:26 +00:00
if ( obj ! = nullptr )
{
m_camera - > SetType ( Gfx : : CAM_TYPE_PLANE ) ;
}
else
{
m_camera - > SetType ( Gfx : : CAM_TYPE_FREE ) ;
}
}
else
{
if ( obj = = nullptr ) return false ;
2015-09-09 18:32:56 +00:00
CObject * prev = DeselectAll ( ) ;
2015-09-06 17:59:26 +00:00
if ( prev ! = nullptr & & prev ! = obj )
PushToSelectionHistory ( prev ) ;
2012-06-26 20:23:05 +00:00
2015-09-06 17:59:26 +00:00
SelectOneObject ( obj , displayError ) ;
}
2012-06-26 20:23:05 +00:00
m_short - > UpdateShortcuts ( ) ;
return true ;
}
bool CRobotMain : : DeselectObject ( )
{
2015-07-14 20:05:12 +00:00
DeselectAll ( ) ;
2012-06-26 20:23:05 +00:00
2015-07-14 20:05:12 +00:00
CObject * obj = PopFromSelectionHistory ( ) ;
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 ( )
{
2015-06-22 19:58:58 +00:00
m_engine - > GetPyroManager ( ) - > DeleteAll ( ) ;
2012-06-26 20:23:05 +00:00
// Removes the arrow.
2012-09-15 13:33:08 +00:00
if ( m_visitArrow ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-06-21 09:16:09 +00:00
CObjectManager : : GetInstancePointer ( ) - > DeleteObject ( 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 ) ;
2015-06-21 09:16:09 +00:00
m_objMan - > DeleteAllObjects ( ) ;
2012-06-26 20:23:05 +00:00
}
CObject * CRobotMain : : SearchHuman ( )
{
2015-06-20 17:27:43 +00:00
return m_objMan - > FindNearest ( nullptr , OBJECT_HUMAN ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
CObject * CRobotMain : : GetSelect ( )
2012-06-26 20:23:05 +00:00
{
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-10 21:20:36 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Controllable ) ) continue ;
if ( dynamic_cast < CControllableObject * > ( obj ) - > GetSelect ( ) )
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
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 )
{
2016-03-28 11:51:39 +00:00
Math : : Vector p ;
int objRank = m_engine - > DetectObject ( pos , p ) ;
2012-06-26 20:23:05 +00:00
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
2015-08-16 18:24:48 +00:00
if ( ! obj - > GetDetectable ( ) ) continue ;
2015-07-10 17:03:27 +00:00
CObject * transporter = nullptr ;
if ( obj - > Implements ( ObjectInterfaceType : : Transportable ) )
transporter = dynamic_cast < CTransportableObject * > ( obj ) - > GetTransporter ( ) ;
2015-08-16 18:24:48 +00:00
if ( transporter ! = nullptr & & ! transporter - > GetDetectable ( ) ) continue ;
2012-09-15 13:33:08 +00:00
if ( obj - > GetProxyActivate ( ) ) continue ;
2012-06-26 20:23:05 +00:00
2015-08-13 17:41:21 +00:00
CObject * target = obj ;
2015-08-18 10:29:41 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : PowerContainer ) & & obj - > Implements ( ObjectInterfaceType : : Transportable ) )
2015-06-21 18:59:23 +00:00
{
2015-07-10 17:03:27 +00:00
target = dynamic_cast < CTransportableObject * > ( obj ) - > GetTransporter ( ) ; // battery connected
2015-08-18 10:29:41 +00:00
if ( target = = nullptr )
{
target = obj ; // standalone battery
}
else
{
if ( ! target - > Implements ( ObjectInterfaceType : : Powered ) | | dynamic_cast < CPoweredObject * > ( target ) - > GetPower ( ) ! = obj )
{
// transported, but not in the power slot
target = obj ;
}
}
2015-06-21 18:59:23 +00:00
}
2012-06-26 20:23:05 +00:00
2015-08-16 18:24:48 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Old ) ) continue ;
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
}
}
2015-08-17 20:40:52 +00:00
return nullptr ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Deletes the selected object
2015-09-06 10:37:49 +00:00
bool CRobotMain : : DestroySelectedObject ( )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj = = nullptr ) return false ;
2015-08-10 21:20:36 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Controllable ) ) ;
2012-06-26 20:23:05 +00:00
2015-06-22 19:58:58 +00:00
m_engine - > GetPyroManager ( ) - > Create ( Gfx : : PT_FRAGT , obj ) ;
2012-06-26 20:23:05 +00:00
2015-08-10 21:20:36 +00:00
dynamic_cast < CControllableObject * > ( obj ) - > SetSelect ( false ) ; // deselects the object
2012-09-15 13:33:08 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_EXPLO ) ;
2012-06-26 20:23:05 +00:00
DeselectAll ( ) ;
2015-07-14 20:05:12 +00:00
RemoveFromSelectionHistory ( 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
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
2015-08-11 21:37:44 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Controllable ) ) continue ;
dynamic_cast < CControllableObject * > ( obj ) - > SetHighlight ( false ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-17 20:40:52 +00:00
m_map - > SetHighlight ( nullptr ) ;
m_short - > SetHighlight ( nullptr ) ;
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 )
{
2015-07-19 21:11:41 +00:00
if ( m_fixScene & & m_phase ! = PHASE_APPERANCE ) return ;
2012-09-15 13:33:08 +00:00
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 ;
2015-08-04 10:45:52 +00:00
if ( m_settings - > GetTooltips ( ) & & 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
}
2015-08-31 19:47:55 +00:00
if ( m_suspend ! = nullptr ) 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
{
2015-08-11 22:12:37 +00:00
if ( m_settings - > GetTooltips ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-11 22:12:37 +00:00
std : : string objectTooltipName = obj - > GetTooltipText ( ) ;
if ( ! objectTooltipName . empty ( ) )
{
m_tooltipPos = pos ;
m_tooltipName = objectTooltipName ;
m_tooltipTime = 0.0f ;
}
2012-06-26 20:23:05 +00:00
}
2016-12-27 22:38:57 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Controllable ) & & ( dynamic_cast < CControllableObject * > ( obj ) - > GetSelectable ( ) | | m_cheatSelectInsect ) )
2012-06-26 20:23:05 +00:00
{
2016-12-27 21:20:58 +00:00
if ( dynamic_cast < CControllableObject * > ( obj ) - > GetSelectable ( ) )
{
// Don't highlight objects that would not be selectable without selectinsect
dynamic_cast < CControllableObject * > ( obj ) - > SetHighlight ( 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 )
{
2015-07-19 21:11:41 +00:00
if ( m_fixScene & & m_phase ! = PHASE_APPERANCE ) return ;
2012-09-15 13:33:08 +00:00
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
2015-12-20 13:28:38 +00:00
std : : string filename = GetHelpFilename ( obj - > GetType ( ) ) ;
if ( filename . empty ( ) ) 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 ( )
{
2015-08-10 21:20:36 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj = = nullptr ) return ;
assert ( obj - > Implements ( ObjectInterfaceType : : Controllable ) ) ;
auto controllableObj = dynamic_cast < CControllableObject * > ( obj ) ;
if ( controllableObj - > GetCameraLock ( ) ) return ;
ObjectType oType = obj - > GetType ( ) ;
Gfx : : CameraType type = controllableObj - > GetCameraType ( ) ;
2016-04-02 12:43:40 +00:00
if ( oType ! = OBJECT_HUMAN & &
oType ! = OBJECT_TECH & &
oType ! = OBJECT_MOBILEfa & &
2015-08-10 21:20:36 +00:00
oType ! = OBJECT_MOBILEta & &
oType ! = OBJECT_MOBILEwa & &
oType ! = OBJECT_MOBILEia & &
2017-11-16 17:43:45 +00:00
oType ! = OBJECT_MOBILEfb & &
oType ! = OBJECT_MOBILEtb & &
oType ! = OBJECT_MOBILEwb & &
oType ! = OBJECT_MOBILEib & &
2015-08-10 21:20:36 +00:00
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 ;
if ( oType = = OBJECT_MOBILEdr ) // designer?
{
if ( type = = Gfx : : CAM_TYPE_PLANE ) type = Gfx : : CAM_TYPE_BACK ;
else if ( type = = Gfx : : CAM_TYPE_BACK ) type = Gfx : : CAM_TYPE_PLANE ;
}
else if ( controllableObj - > GetTrainer ( ) ) // trainer?
{
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 ;
}
else
2012-06-26 20:23:05 +00:00
{
2015-08-10 21:20:36 +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
}
2015-08-10 21:20:36 +00:00
controllableObj - > SetCameraType ( type ) ;
m_camera - > SetType ( type ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Cancels the current movie
2012-06-26 20:23:05 +00:00
void CRobotMain : : AbortMovie ( )
{
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-11 21:41:41 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Old ) )
{
CAuto * automat = obj - > GetAuto ( ) ;
2015-08-17 20:40:52 +00:00
if ( automat ! = nullptr )
2015-07-11 21:41:41 +00:00
automat - > Abort ( ) ;
}
2012-06-26 20:23:05 +00:00
}
}
2016-04-09 16:46:12 +00:00
std : : string TimeFormat ( float time )
{
int minutes = static_cast < int > ( floor ( time / 60 ) ) ;
double time2 = fmod ( time , 60 ) ;
double seconds ;
double fraction = modf ( time2 , & seconds ) * 100 ;
std : : ostringstream sstream ;
sstream < < std : : setfill ( ' 0 ' ) < < std : : setw ( 2 ) < < minutes < < " : " < < std : : setfill ( ' 0 ' ) < < std : : setw ( 2 ) < < floor ( seconds ) < < " . " < < std : : setfill ( ' 0 ' ) < < std : : setw ( 2 ) < < floor ( fraction ) ;
return sstream . str ( ) ;
}
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 ( )
{
2014-10-29 16:53:46 +00:00
if ( m_phase = = PHASE_SIMUL )
2012-06-26 20:23:05 +00:00
{
2014-10-29 16:53:46 +00:00
CObject * obj = GetSelect ( ) ;
if ( obj ! = nullptr )
{
2015-07-12 09:01:16 +00:00
Math : : Vector pos = obj - > GetPosition ( ) ;
2015-08-15 12:02:07 +00:00
m_engine - > SetStatisticPos ( pos / g_unit ) ;
2014-10-29 16:53:46 +00:00
}
2012-06-26 20:23:05 +00:00
}
2014-10-29 16:53:46 +00:00
m_engine - > SetTimerDisplay ( m_missionTimerEnabled & & m_missionTimerStarted ? TimeFormat ( m_missionTimer ) : " " ) ;
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 ;
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 ) ;
2016-03-17 03:31:16 +00:00
UpdateDebugCrashSpheres ( ) ;
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
}
2015-06-21 09:16:09 +00:00
2012-09-15 13:33:08 +00:00
CObject * toto = nullptr ;
2015-10-01 16:55:41 +00:00
if ( ! m_pause - > IsPauseType ( PAUSE_OBJECT_UPDATES ) )
2012-06-26 20:23:05 +00:00
{
// Advances all the robots, but not toto.
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-09-15 13:33:08 +00:00
{
2015-07-02 21:48:30 +00:00
if ( pm ! = nullptr )
pm - > UpdateObject ( obj ) ;
2015-07-10 17:03:27 +00:00
if ( IsObjectBeingTransported ( obj ) )
2015-07-02 21:48:30 +00:00
continue ;
if ( obj - > GetType ( ) = = OBJECT_TOTO )
2012-09-15 13:33:08 +00:00
toto = obj ;
2015-07-02 21:48:30 +00:00
else if ( obj - > Implements ( ObjectInterfaceType : : Interactive ) )
dynamic_cast < CInteractiveObject * > ( obj ) - > EventProcess ( event ) ;
2015-08-11 15:51:39 +00:00
if ( obj - > GetProxyActivate ( ) ) // active if it is near?
{
Math : : Vector eye = m_engine - > GetLookatPt ( ) ;
float dist = Math : : Distance ( eye , obj - > GetPosition ( ) ) ;
2015-08-14 10:10:27 +00:00
if ( dist < obj - > GetProxyDistance ( ) )
2015-08-11 15:51:39 +00:00
{
obj - > SetProxyActivate ( false ) ;
CreateShortcuts ( ) ;
m_sound - > Play ( SOUND_FINDING ) ;
m_engine - > GetPyroManager ( ) - > Create ( Gfx : : PT_FINDING , obj , 0.0f ) ;
DisplayError ( INFO_FINDING , obj ) ;
}
}
2012-06-26 20:23:05 +00:00
}
// Advances all objects transported by robots.
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-10 17:03:27 +00:00
if ( ! IsObjectBeingTransported ( obj ) )
2015-07-02 21:48:30 +00:00
continue ;
if ( obj - > Implements ( ObjectInterfaceType : : Interactive ) )
dynamic_cast < CInteractiveObject * > ( obj ) - > EventProcess ( event ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-22 19:58:58 +00:00
m_engine - > GetPyroManager ( ) - > EventProcess ( event ) ;
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
}
2015-07-19 21:11:41 +00:00
if ( m_phase = = PHASE_APPERANCE | |
2012-09-15 13:33:08 +00:00
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 )
2015-07-02 21:48:30 +00:00
dynamic_cast < CInteractiveObject * > ( toto ) - > EventProcess ( event ) ;
2012-06-26 20:23:05 +00:00
2017-06-04 11:10:50 +00:00
// NOTE: m_movieLock is set only after the first update of CAutoBase finishes
if ( m_phase = = PHASE_SIMUL )
{
if ( ! m_immediatSatCom & & ! m_beginSatCom & & ! m_movieLock )
{
m_displayText - > DisplayError ( INFO_BEGINSATCOM , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_beginSatCom = true ; // message appears
}
if ( ! m_pause - > IsPauseType ( PAUSE_ENGINE ) & & ! m_movieLock )
{
m_gameTime + = event . rTime ;
m_gameTimeAbsolute + = m_app - > GetRealRelTime ( ) / 1e9 f ;
if ( m_missionTimerStarted )
m_missionTimer + = event . rTime ;
if ( m_autosave & & m_gameTimeAbsolute > = m_autosaveLast + ( m_autosaveInterval * 60 ) )
{
if ( m_levelCategory = = LevelCategory : : Missions | |
m_levelCategory = = LevelCategory : : FreeGame | |
m_levelCategory = = LevelCategory : : CustomLevels )
{
if ( ! IOIsBusy ( ) & & m_missionType ! = MISSION_CODE_BATTLE )
{
m_autosaveLast = m_gameTimeAbsolute ;
Autosave ( ) ;
}
}
}
}
}
2012-06-26 20:23:05 +00:00
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.
2015-10-01 16:55:41 +00:00
if ( m_editLock | | m_pause - > IsPauseType ( PAUSE_ENGINE ) ) // 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 ;
2015-06-26 20:07:55 +00:00
pos . x = ( 640.0f - 24.0f ) / 640.0f ;
2012-06-26 20:23:05 +00:00
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 ) ;
}
}
2015-08-06 18:15:17 +00:00
Ui : : CControl * pc = m_interface - > SearchControl ( EVENT_OBJECT_SAVING ) ;
if ( pc ! = nullptr )
{
Math : : Point pos , dim ;
2015-08-07 13:59:05 +00:00
if ( m_shotSaving < = 0 )
2015-08-06 18:15:17 +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 = ( 640.0f - 24.0f ) / 640.0f ;
pos . y = ( 480.0f - 24.0f ) / 480.0f ;
float zoom = 1.0f + sinf ( m_time * 6.0f ) * 0.1f ; // 0.9 .. 1.1
dim . x * = zoom ;
dim . y * = zoom ;
pos . x - = dim . x / 2.0f ;
pos . y - = dim . y / 2.0f ;
}
pc - > SetPos ( pos ) ;
pc - > SetDim ( dim ) ;
}
2012-06-26 20:23:05 +00:00
// 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
{
2017-05-17 16:22:27 +00:00
if ( ! m_editLock & & ! m_engine - > GetPause ( ) )
2012-06-26 20:23:05 +00:00
{
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 )
2016-12-27 14:21:49 +00:00
m_lostDelay = 1.0f ;
2012-06-26 20:23:05 +00:00
else
2012-09-15 13:33:08 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_LOST ) ) ;
2012-06-26 20:23:05 +00:00
}
}
2017-05-24 10:42:37 +00:00
if ( GetMissionType ( ) = = MISSION_CODE_BATTLE )
2015-06-27 16:06:49 +00:00
{
2017-05-24 10:42:37 +00:00
if ( ! m_codeBattleInit )
{
// NOTE: It's important to do this AFTER the first update event finished processing
// because otherwise all robot parts are misplaced
m_userPause = m_pause - > ActivatePause ( PAUSE_ENGINE ) ;
m_codeBattleInit = true ; // Will start on resume
}
2015-06-27 16:06:49 +00:00
2017-05-24 10:42:37 +00:00
if ( ! m_codeBattleStarted & & m_userPause = = nullptr )
{
m_codeBattleStarted = true ;
ApplyCodeBattleInterface ( ) ;
CreateCodeBattleInterface ( ) ;
2015-09-06 17:59:26 +00:00
2017-05-24 10:42:37 +00:00
SetCodeBattleSpectatorMode ( true ) ;
2015-09-06 17:59:26 +00:00
2017-05-24 10:42:37 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_UPDINTERFACE ) ) ;
}
2017-05-19 19:11:43 +00:00
2017-05-24 10:42:37 +00:00
UpdateCodeBattleInterface ( ) ;
}
2015-06-26 20:07:55 +00:00
}
2012-09-15 13:33:08 +00:00
return true ;
2012-06-26 20:23:05 +00:00
}
2015-08-07 13:59:05 +00:00
void CRobotMain : : ShowSaveIndicator ( bool show )
{
Ui : : CControl * pc = m_interface - > SearchControl ( EVENT_OBJECT_SAVING ) ;
if ( pc ! = nullptr )
{
Math : : Point pos , dim ;
if ( ! show )
{
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 = ( 640.0f - 24.0f ) / 640.0f ;
pos . y = ( 480.0f - 24.0f ) / 480.0f ;
pos . x - = dim . x / 2.0f ;
pos . y - = dim . y / 2.0f ;
}
pc - > SetPos ( pos ) ;
pc - > SetDim ( dim ) ;
}
}
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 )
{
2015-10-01 16:55:41 +00:00
if ( m_pause - > IsPauseType ( PAUSE_OBJECT_UPDATES ) ) 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
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
2015-07-02 21:48:30 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Interactive ) )
{
dynamic_cast < CInteractiveObject * > ( 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
}
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 ( ) ;
2015-07-11 17:48:37 +00:00
m_oldModelManager - > 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
2016-07-24 14:44:27 +00:00
m_levelFile = " levels/other/perso.txt " ;
2015-06-21 18:59:23 +00:00
try
{
2014-09-24 20:54:26 +00:00
CreateScene ( false , true , false ) ; // sets scene
}
2015-07-14 16:46:22 +00:00
catch ( const std : : runtime_error & e )
2014-09-24 20:54:26 +00:00
{
2016-03-30 11:40:26 +00:00
LevelLoadingError ( " An error occurred while trying to load apperance scene " , e , PHASE_PLAYER_SELECT ) ;
2014-09-24 20:54:26 +00:00
}
2012-06-26 20:23:05 +00:00
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
2015-08-13 08:49:26 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Movable ) ) ;
CMotionHuman * mh = static_cast < CMotionHuman * > ( dynamic_cast < CMovableObject * > ( obj ) - > GetMotion ( ) ) ;
mh - > StartDisplayPerso ( ) ;
2012-06-26 20:23:05 +00:00
}
}
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-15 13:33:08 +00:00
m_fixScene = fixScene ;
2012-06-26 20:23:05 +00:00
2014-11-09 18:26:36 +00:00
m_base = nullptr ;
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
{
2015-07-13 15:38:19 +00:00
m_build = 0 ;
2015-07-13 16:13:28 +00:00
m_researchDone . clear ( ) ; // no research done
m_researchDone [ 0 ] = 0 ;
2015-07-13 15:38:19 +00:00
m_researchEnable = 0 ;
2012-06-26 20:23:05 +00:00
2016-02-13 19:46:03 +00:00
g_unit = UNIT ;
2012-06-26 20:23:05 +00:00
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 ;
2014-02-21 13:19:58 +00:00
m_satcomTrack = " " ;
m_satcomRepeat = true ;
m_editorTrack = " " ;
m_editorRepeat = 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 ;
2016-05-27 21:37:36 +00:00
m_endingWin = " " ;
m_endingLost = " " ;
2015-07-07 14:17:19 +00:00
m_audioChange . clear ( ) ;
m_endTake . clear ( ) ;
2016-04-08 18:56:09 +00:00
m_endTakeImmediat = false ;
2012-06-26 20:23:05 +00:00
m_endTakeResearch = 0 ;
m_endTakeWinDelay = 2.0f ;
m_endTakeLostDelay = 2.0f ;
2017-05-17 16:22:27 +00:00
m_teamFinished . clear ( ) ;
m_scoreboard . reset ( ) ;
2015-07-15 16:10:49 +00:00
m_globalMagnifyDamage = 1.0f ;
2016-04-08 20:15:54 +00:00
m_obligatoryTokens . clear ( ) ;
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 ;
2015-07-22 10:45:50 +00:00
m_colorNewBot . clear ( ) ;
2016-03-27 11:34:26 +00:00
m_colorNewBot [ 0 ] = COLOR_REF_BOT ;
m_colorNewAlien = COLOR_REF_ALIEN ;
m_colorNewGreen = COLOR_REF_GREEN ;
m_colorNewWater = COLOR_REF_WATER ;
2015-06-21 18:59:23 +00:00
2014-11-11 14:38:11 +00:00
m_engine - > SetAmbientColor ( Gfx : : Color ( 0.5f , 0.5f , 0.5f , 0.5f ) , 0 ) ;
m_engine - > SetAmbientColor ( Gfx : : Color ( 0.5f , 0.5f , 0.5f , 0.5f ) , 1 ) ;
m_engine - > SetFogColor ( Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) , 0 ) ;
m_engine - > SetFogColor ( Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) , 1 ) ;
m_engine - > SetDeepView ( 1000.0f , 0 ) ;
m_engine - > SetDeepView ( 1000.0f , 1 ) ;
m_engine - > SetFogStart ( 0.75f , 0 ) ;
m_engine - > SetFogStart ( 0.75f , 1 ) ;
m_engine - > SetSecondTexture ( " " ) ;
m_engine - > SetForegroundName ( " " ) ;
2012-06-26 20:23:05 +00:00
2015-10-01 17:37:31 +00:00
GetResource ( RES_TEXT , RT_SCRIPT_NEW , m_scriptName ) ;
m_scriptFile = " " ;
2013-03-23 18:04:41 +00:00
2015-06-26 20:07:55 +00:00
m_missionType = MISSION_NORMAL ;
m_codeBattleInit = false ;
m_codeBattleStarted = false ;
2013-04-30 19:43:59 +00:00
2015-07-07 19:25:13 +00:00
m_teamNames . clear ( ) ;
2015-06-26 20:07:55 +00:00
m_missionResult = ERR_MISSION_NOTERM ;
2016-04-08 18:56:09 +00:00
m_missionResultFromScript = false ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2016-05-27 21:37:36 +00:00
// NOTE: Reset timer always, even when only resetting object positions
2014-10-29 16:53:46 +00:00
m_missionTimerEnabled = false ;
m_missionTimerStarted = false ;
m_missionTimer = 0.0f ;
2015-06-21 18:59:23 +00:00
2015-08-07 18:48:55 +00:00
std : : string backgroundPath = " " ;
Gfx : : Color backgroundUp = Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
Gfx : : Color backgroundDown = Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
Gfx : : Color backgroundCloudUp = Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
Gfx : : Color backgroundCloudDown = Gfx : : Color ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
bool backgroundFull = false ;
2016-07-04 14:30:22 +00:00
auto LoadingWarning = [ & ] ( const std : : string & message )
{
GetLogger ( ) - > Warn ( " %s \n " , message . c_str ( ) ) ;
m_ui - > GetDialog ( ) - > StartInformation ( " Level loading warning " , " This level contains problems. It may stop working in future versions of the game. " , message ) ;
} ;
2015-06-21 18:59:23 +00:00
try
{
2015-08-07 18:48:55 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.05f , RT_LOADING_PROCESSING ) ;
2016-05-27 21:37:36 +00:00
GetLogger ( ) - > Info ( " Loading level: %s \n " , m_levelFile . c_str ( ) ) ;
CLevelParser levelParser ( m_levelFile ) ;
levelParser . SetLevelPaths ( m_levelCategory , m_levelChap , m_levelRank ) ;
2015-06-21 18:59:23 +00:00
levelParser . Load ( ) ;
2015-08-07 18:48:55 +00:00
int numObjects = levelParser . CountLines ( " CreateObject " ) ;
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.1f , RT_LOADING_LEVEL_SETTINGS ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 21:50:00 +00:00
int rankObj = 0 ;
2015-08-17 20:40:52 +00:00
CObject * sel = nullptr ;
2013-02-28 21:56:44 +00:00
2015-06-21 18:59:23 +00:00
for ( auto & line : levelParser . GetLines ( ) )
2013-05-26 15:47:54 +00:00
{
2015-06-21 18:59:23 +00:00
if ( line - > GetCommand ( ) = = " Title " & & ! resetObject )
2014-11-10 21:50:00 +00:00
{
2015-10-01 17:37:31 +00:00
//strcpy(m_title, line->GetParam("text")->AsString().c_str());
2014-11-10 21:50:00 +00:00
continue ;
2014-10-29 16:53:46 +00:00
}
2015-06-21 18:59:23 +00:00
if ( line - > GetCommand ( ) = = " Resume " & & ! resetObject )
2013-04-13 09:44:16 +00:00
{
2015-10-01 17:37:31 +00:00
//strcpy(m_resume, line->GetParam("text")->AsString().c_str());
2014-11-10 21:50:00 +00:00
continue ;
2013-04-13 09:44:16 +00:00
}
2015-06-21 18:59:23 +00:00
if ( line - > GetCommand ( ) = = " ScriptName " & & ! resetObject )
2013-05-26 15:47:54 +00:00
{
2015-10-01 17:37:31 +00:00
m_scriptName = line - > GetParam ( " text " ) - > AsString ( ) ;
2014-11-10 21:50:00 +00:00
continue ;
2013-05-26 15:47:54 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " ScriptFile " & & ! resetObject )
2013-05-26 15:47:54 +00:00
{
2015-10-01 17:37:31 +00:00
m_scriptFile = line - > GetParam ( " name " ) - > AsString ( ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " Instructions " & & ! resetObject )
{
strcpy ( m_infoFilename [ SATCOM_HUSTON ] , line - > GetParam ( " name " ) - > AsPath ( " help/%lng% " ) . c_str ( ) ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
m_immediatSatCom = line - > GetParam ( " immediat " ) - > AsBool ( false ) ;
2015-03-28 10:23:29 +00:00
m_beginSatCom = m_lockedSatCom = line - > GetParam ( " lock " ) - > AsBool ( false ) ;
2014-11-10 21:50:00 +00:00
if ( m_app - > GetSceneTestMode ( ) ) m_immediatSatCom = false ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " Satellite " & & ! resetObject )
{
strcpy ( m_infoFilename [ SATCOM_SAT ] , line - > GetParam ( " name " ) - > AsPath ( " help/%lng% " ) . c_str ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " Loading " & & ! resetObject )
{
strcpy ( m_infoFilename [ SATCOM_LOADING ] , line - > GetParam ( " name " ) - > AsPath ( " help/%lng% " ) . c_str ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " HelpFile " & & ! resetObject )
{
strcpy ( m_infoFilename [ SATCOM_PROG ] , line - > GetParam ( " name " ) - > AsPath ( " help/%lng% " ) . c_str ( ) ) ;
continue ;
}
if ( line - > GetCommand ( ) = = " SoluceFile " & & ! resetObject )
{
strcpy ( m_infoFilename [ SATCOM_SOLUCE ] , line - > GetParam ( " name " ) - > AsPath ( " help/%lng% " ) . c_str ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " EndingFile " & & ! resetObject )
{
2016-05-27 21:37:36 +00:00
auto Process = [ & ] ( const std : : string & type ) - > std : : string
{
if ( line - > GetParam ( type ) - > IsDefined ( ) )
{
try
{
int rank = boost : : lexical_cast < int > ( line - > GetParam ( type ) - > GetValue ( ) ) ;
if ( rank > = 0 )
{
2016-07-04 14:30:22 +00:00
// TODO: Fix default levels and add a future removal warning
2016-05-27 21:37:36 +00:00
GetLogger ( ) - > Warn ( " This level is using deprecated way of defining %1$s scene. Please change the %1$s= parameter in EndingFile from %2$d to \" levels/other/%1$s%2$03d.txt \" . \n " , type . c_str ( ) , rank ) ;
std : : stringstream ss ;
ss < < " levels/other/ " < < type < < std : : setfill ( ' 0 ' ) < < std : : setw ( 3 ) < < rank < < " .txt " ;
return ss . str ( ) ;
}
else
{
2016-07-04 14:30:22 +00:00
// TODO: Fix default levels and add a future removal warning
2016-05-27 21:37:36 +00:00
GetLogger ( ) - > Warn ( " This level is using deprecated way of defining %1$s scene. Please remove the %1$s= parameter in EndingFile. \n " , type . c_str ( ) ) ;
return " " ;
}
}
catch ( boost : : bad_lexical_cast & e )
{
return line - > GetParam ( type ) - > AsPath ( " levels " ) ;
}
}
return " " ;
} ;
m_endingWin = Process ( " win " ) ;
m_endingLost = Process ( " lost " ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " MessageDelay " & & ! resetObject )
{
m_displayText - > SetDelay ( line - > GetParam ( " factor " ) - > AsFloat ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " MissionTimer " )
{
m_missionTimerEnabled = line - > GetParam ( " enabled " ) - > AsBool ( ) ;
2015-06-21 18:59:23 +00:00
if ( ! line - > GetParam ( " program " ) - > AsBool ( false ) )
{
2014-11-10 21:50:00 +00:00
m_missionTimerStarted = true ;
2014-10-26 17:30:56 +00:00
}
2014-11-10 21:50:00 +00:00
continue ;
2013-04-26 13:34:02 +00:00
}
2015-06-21 18:59:23 +00:00
2015-07-07 19:25:13 +00:00
if ( line - > GetCommand ( ) = = " TeamName " )
{
int team = line - > GetParam ( " team " ) - > AsInt ( ) ;
std : : string name = line - > GetParam ( " name " ) - > AsString ( ) ;
m_teamNames [ team ] = name ;
continue ;
}
2015-03-28 10:23:29 +00:00
if ( line - > GetCommand ( ) = = " CacheAudio " & & ! resetObject )
2014-11-10 21:50:00 +00:00
{
2015-08-07 18:48:55 +00:00
std : : string filename = line - > GetParam ( " filename " ) - > AsPath ( " music " ) ;
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.15f , RT_LOADING_MUSIC , filename ) ;
2015-08-14 17:44:31 +00:00
m_sound - > CacheMusic ( filename ) ;
2014-11-10 21:50:00 +00:00
continue ;
2014-11-10 19:46:39 +00:00
}
2015-06-21 18:59:23 +00:00
2016-04-08 18:56:09 +00:00
if ( line - > GetCommand ( ) = = " AudioChange " & & ! resetObject )
2013-05-26 15:47:54 +00:00
{
2015-07-17 17:22:31 +00:00
auto audioChange = MakeUnique < CAudioChangeCondition > ( ) ;
2015-07-07 14:17:19 +00:00
audioChange - > Read ( line . get ( ) ) ;
2015-08-14 17:44:31 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.15f , RT_LOADING_MUSIC , audioChange - > music ) ;
2015-07-07 14:17:19 +00:00
m_sound - > CacheMusic ( audioChange - > music ) ;
m_audioChange . push_back ( std : : move ( audioChange ) ) ;
2016-07-04 14:30:22 +00:00
if ( ! line - > GetParam ( " pos " ) - > IsDefined ( ) | | ! line - > GetParam ( " dist " ) - > IsDefined ( ) )
{
LoadingWarning ( " The defaults for pos= and dist= are going to change, specify them explicitly. See issue #759 (https://git.io/vVBzH) " ) ;
}
2014-11-10 21:50:00 +00:00
continue ;
2013-03-23 18:04:41 +00:00
}
2015-06-21 18:59:23 +00:00
2016-04-08 18:56:09 +00:00
if ( line - > GetCommand ( ) = = " Audio " & & ! resetObject )
2014-11-10 21:50:00 +00:00
{
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " track " ) - > IsDefined ( ) )
2014-09-24 20:54:26 +00:00
{
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " filename " ) - > IsDefined ( ) )
throw CLevelParserException ( " You can't use track and filename at the same time " ) ;
2015-03-28 10:23:29 +00:00
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Warn ( " Using track= is deprecated. Please replace this with filename= \n " ) ;
2014-11-10 21:50:00 +00:00
int trackid = line - > GetParam ( " track " ) - > AsInt ( ) ;
if ( trackid ! = 0 )
2014-09-24 20:54:26 +00:00
{
2014-11-10 21:50:00 +00:00
std : : stringstream filenameStr ;
2015-08-14 17:44:31 +00:00
filenameStr < < " music/music " < < std : : setfill ( ' 0 ' ) < < std : : setw ( 3 ) < < trackid < < " .ogg " ;
2014-11-10 21:50:00 +00:00
m_audioTrack = filenameStr . str ( ) ;
2014-09-24 20:54:26 +00:00
}
2015-03-28 10:23:29 +00:00
else
{
m_audioTrack = " " ;
}
2014-09-24 20:54:26 +00:00
}
2014-11-10 21:50:00 +00:00
else
2014-09-24 20:54:26 +00:00
{
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " filename " ) - > IsDefined ( ) )
2015-03-28 10:23:29 +00:00
{
2015-08-14 17:44:31 +00:00
m_audioTrack = line - > GetParam ( " filename " ) - > AsPath ( " music " ) ;
2014-11-10 21:50:00 +00:00
}
2015-03-28 10:23:29 +00:00
else
{
m_audioTrack = " " ;
2014-11-10 21:50:00 +00:00
}
2015-03-28 10:23:29 +00:00
}
2015-06-21 18:59:23 +00:00
if ( ! m_audioTrack . empty ( ) )
2015-03-28 10:23:29 +00:00
{
m_audioRepeat = line - > GetParam ( " repeat " ) - > AsBool ( true ) ;
}
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " satcom " ) - > IsDefined ( ) )
{
2015-08-14 17:44:31 +00:00
m_satcomTrack = line - > GetParam ( " satcom " ) - > AsPath ( " music " ) ;
2015-03-28 10:23:29 +00:00
m_satcomRepeat = line - > GetParam ( " satcomRepeat " ) - > AsBool ( true ) ;
2015-06-21 18:59:23 +00:00
}
else
{
2015-03-28 10:23:29 +00:00
m_satcomTrack = " " ;
2014-09-24 20:54:26 +00:00
}
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " editor " ) - > IsDefined ( ) )
{
2015-08-14 17:44:31 +00:00
m_editorTrack = line - > GetParam ( " editor " ) - > AsPath ( " music " ) ;
2015-03-28 10:23:29 +00:00
m_editorRepeat = line - > GetParam ( " editorRepeat " ) - > AsBool ( true ) ;
2015-06-21 18:59:23 +00:00
}
else
{
2015-03-28 10:23:29 +00:00
m_editorTrack = " " ;
}
2015-08-07 18:48:55 +00:00
if ( ! m_audioTrack . empty ( ) )
{
2015-08-14 17:44:31 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.15f , RT_LOADING_MUSIC , m_audioTrack ) ;
2015-08-07 18:48:55 +00:00
m_sound - > CacheMusic ( m_audioTrack ) ;
}
if ( ! m_satcomTrack . empty ( ) )
{
2015-08-14 17:44:31 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.15f , RT_LOADING_MUSIC , m_satcomTrack ) ;
2015-08-07 18:48:55 +00:00
m_sound - > CacheMusic ( m_satcomTrack ) ;
}
if ( ! m_editorTrack . empty ( ) )
{
2015-08-14 17:44:31 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.15f , RT_LOADING_MUSIC , m_editorTrack ) ;
2015-08-07 18:48:55 +00:00
m_sound - > CacheMusic ( m_editorTrack ) ;
}
2014-11-10 21:50:00 +00:00
continue ;
2013-03-23 18:04:41 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " AmbientColor " & & ! resetObject )
{
m_engine - > SetAmbientColor ( line - > GetParam ( " air " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 0 ) ;
m_engine - > SetAmbientColor ( line - > GetParam ( " water " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 1 ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " FogColor " & & ! resetObject )
{
m_engine - > SetFogColor ( line - > GetParam ( " air " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 0 ) ;
m_engine - > SetFogColor ( line - > GetParam ( " water " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) , 1 ) ;
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " VehicleColor " & & ! resetObject )
{
2015-07-22 10:45:50 +00:00
m_colorNewBot [ line - > GetParam ( " team " ) - > AsInt ( 0 ) ] = line - > GetParam ( " color " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " InsectColor " & & ! resetObject )
{
m_colorNewAlien = line - > GetParam ( " color " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " GreeneryColor " & & ! resetObject )
2013-04-28 18:05:19 +00:00
{
2014-11-10 21:50:00 +00:00
m_colorNewGreen = line - > GetParam ( " color " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ;
continue ;
2013-04-28 18:05:19 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " DeepView " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2016-01-31 00:07:34 +00:00
m_engine - > SetDeepView ( line - > GetParam ( " air " ) - > AsFloat ( 500.0f ) * g_unit , 0 , false ) ;
m_engine - > SetDeepView ( line - > GetParam ( " water " ) - > AsFloat ( 100.0f ) * g_unit , 1 , false ) ;
2014-11-10 21:50:00 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " FogStart " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2014-11-10 21:50:00 +00:00
m_engine - > SetFogStart ( line - > GetParam ( " air " ) - > AsFloat ( 0.5f ) , 0 ) ;
m_engine - > SetFogStart ( line - > GetParam ( " water " ) - > AsFloat ( 0.5f ) , 1 ) ;
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " SecondTexture " & & ! resetObject )
{
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " rank " ) - > IsDefined ( ) )
{
2014-11-10 21:50:00 +00:00
char tex [ 20 ] = { 0 } ;
sprintf ( tex , " dirty%.2d.png " , line - > GetParam ( " rank " ) - > AsInt ( ) ) ;
m_engine - > SetSecondTexture ( tex ) ;
2015-06-21 18:59:23 +00:00
}
else
{
m_engine - > SetSecondTexture ( " ../ " + line - > GetParam ( " texture " ) - > AsPath ( " textures " ) ) ;
2014-11-10 21:50:00 +00:00
}
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " Background " & & ! resetObject )
2014-01-01 15:45:08 +00:00
{
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " image " ) - > IsDefined ( ) )
2015-08-07 18:48:55 +00:00
backgroundPath = line - > GetParam ( " image " ) - > AsPath ( " textures " ) ;
backgroundUp = line - > GetParam ( " up " ) - > AsColor ( backgroundUp ) ;
backgroundDown = line - > GetParam ( " down " ) - > AsColor ( backgroundDown ) ;
backgroundCloudUp = line - > GetParam ( " cloudUp " ) - > AsColor ( backgroundCloudUp ) ;
backgroundCloudDown = line - > GetParam ( " cloudDown " ) - > AsColor ( backgroundCloudDown ) ;
backgroundFull = line - > GetParam ( " full " ) - > AsBool ( backgroundFull ) ;
2014-11-10 21:50:00 +00:00
continue ;
2014-01-01 15:45:08 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " Planet " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2014-11-10 21:50:00 +00:00
Math : : Vector ppos , uv1 , uv2 ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
ppos = line - > GetParam ( " pos " ) - > AsPoint ( ) ;
uv1 = line - > GetParam ( " uv1 " ) - > AsPoint ( ) ;
uv2 = line - > GetParam ( " uv2 " ) - > AsPoint ( ) ;
2015-08-06 09:12:43 +00:00
m_planet - > Create ( line - > GetParam ( " mode " ) - > AsPlanetType ( ) ,
2014-11-10 21:50:00 +00:00
Math : : Point ( ppos . x , ppos . z ) ,
line - > GetParam ( " dim " ) - > AsFloat ( 0.2f ) ,
line - > GetParam ( " speed " ) - > AsFloat ( 0.0f ) ,
line - > GetParam ( " dir " ) - > AsFloat ( 0.0f ) ,
2015-08-03 18:55:33 +00:00
line - > GetParam ( " image " ) - > AsPath ( " textures " ) ,
2014-11-10 21:50:00 +00:00
Math : : Point ( uv1 . x , uv1 . z ) ,
Math : : Point ( uv2 . x , uv2 . z ) ,
line - > GetParam ( " image " ) - > AsPath ( " textures " ) . find ( " planet " ) ! = std : : string : : npos // TODO: add transparent op or modify textures
) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " ForegroundName " & & ! resetObject )
{
2015-08-03 18:55:33 +00:00
m_engine - > SetForegroundName ( line - > GetParam ( " image " ) - > AsPath ( " textures " ) ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2015-07-15 16:10:49 +00:00
if ( line - > GetCommand ( ) = = " Level " & & ! resetObject )
2014-11-10 21:50:00 +00:00
{
g_unit = line - > GetParam ( " unitScale " ) - > AsFloat ( 4.0f ) ;
m_engine - > SetTracePrecision ( line - > GetParam ( " traceQuality " ) - > AsFloat ( 1.0f ) ) ;
m_shortCut = line - > GetParam ( " shortcut " ) - > AsBool ( true ) ;
2015-03-28 10:23:29 +00:00
2015-06-26 20:07:55 +00:00
m_missionType = line - > GetParam ( " type " ) - > AsMissionType ( MISSION_NORMAL ) ;
2015-07-15 16:10:49 +00:00
m_globalMagnifyDamage = line - > GetParam ( " magnifyDamage " ) - > AsFloat ( 1.0f ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainGenerate " & & ! resetObject )
{
2015-08-07 18:48:55 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f , RT_LOADING_TERRAIN ) ;
2014-11-10 21:50:00 +00:00
m_terrain - > Generate ( line - > GetParam ( " mosaic " ) - > AsInt ( 20 ) ,
line - > GetParam ( " brick " ) - > AsInt ( 3 ) ,
line - > GetParam ( " size " ) - > AsFloat ( 20.0f ) ,
line - > GetParam ( " vision " ) - > AsFloat ( 500.0f ) * g_unit ,
line - > GetParam ( " depth " ) - > AsInt ( 2 ) ,
line - > GetParam ( " hard " ) - > AsFloat ( 0.5f ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainWind " & & ! resetObject )
{
m_terrain - > SetWind ( line - > GetParam ( " speed " ) - > AsPoint ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainRelief " & & ! resetObject )
{
2015-08-07 21:40:38 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f + ( 1.f / 5.f ) * 0.05f , RT_LOADING_TERRAIN , RT_LOADING_TERRAIN_RELIEF ) ;
2014-11-10 21:50:00 +00:00
m_terrain - > LoadRelief (
line - > GetParam ( " image " ) - > AsPath ( " textures " ) ,
line - > GetParam ( " factor " ) - > AsFloat ( 1.0f ) ,
line - > GetParam ( " border " ) - > AsBool ( true ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainRandomRelief " & & ! resetObject )
{
2015-08-07 21:40:38 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f + ( 1.f / 5.f ) * 0.05f , RT_LOADING_TERRAIN , RT_LOADING_TERRAIN_RELIEF ) ;
2014-11-10 21:50:00 +00:00
m_terrain - > RandomizeRelief ( ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainResource " & & ! resetObject )
{
2015-08-07 21:40:38 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f + ( 2.f / 5.f ) * 0.05f , RT_LOADING_TERRAIN , RT_LOADING_TERRAIN_RES ) ;
2014-11-10 21:50:00 +00:00
m_terrain - > LoadResources ( line - > GetParam ( " image " ) - > AsPath ( " textures " ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainWater " & & ! resetObject )
{
Math : : Vector pos ;
2015-09-30 18:31:09 +00:00
pos . x = line - > GetParam ( " moveX " ) - > AsFloat ( 0.0f ) ;
pos . y = line - > GetParam ( " moveY " ) - > AsFloat ( 0.0f ) ;
2014-11-10 21:50:00 +00:00
pos . z = pos . x ;
m_water - > Create ( line - > GetParam ( " air " ) - > AsWaterType ( Gfx : : WATER_TT ) ,
line - > GetParam ( " water " ) - > AsWaterType ( Gfx : : WATER_TT ) ,
2015-08-03 18:55:33 +00:00
line - > GetParam ( " image " ) - > AsPath ( " textures " ) ,
2014-11-10 21:50:00 +00:00
line - > GetParam ( " diffuse " ) - > AsColor ( Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
line - > GetParam ( " ambient " ) - > AsColor ( Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
line - > GetParam ( " level " ) - > AsFloat ( 100.0f ) * g_unit ,
line - > GetParam ( " glint " ) - > AsFloat ( 1.0f ) ,
pos ) ;
2016-03-27 11:34:26 +00:00
m_colorNewWater = line - > GetParam ( " color " ) - > AsColor ( COLOR_REF_WATER ) ;
2014-11-10 21:50:00 +00:00
m_colorShiftWater = line - > GetParam ( " brightness " ) - > AsFloat ( 0.0f ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainLava " & & ! resetObject )
{
m_water - > SetLava ( line - > GetParam ( " mode " ) - > AsBool ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainCloud " & & ! resetObject )
{
std : : string path = " " ;
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " image " ) - > IsDefined ( ) )
2015-08-03 18:55:33 +00:00
path = line - > GetParam ( " image " ) - > AsPath ( " textures " ) ;
2014-11-10 21:50:00 +00:00
m_cloud - > Create ( path ,
line - > GetParam ( " diffuse " ) - > AsColor ( Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
line - > GetParam ( " ambient " ) - > AsColor ( Gfx : : Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ,
line - > GetParam ( " level " ) - > AsFloat ( 500.0f ) * g_unit ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainBlitz " & & ! resetObject )
{
m_lightning - > Create ( line - > GetParam ( " sleep " ) - > AsFloat ( 0.0f ) ,
line - > GetParam ( " delay " ) - > AsFloat ( 3.0f ) ,
line - > GetParam ( " magnetic " ) - > AsFloat ( 50.0f ) * g_unit ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainInitTextures " & & ! resetObject )
{
2015-08-07 21:40:38 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f + ( 3.f / 5.f ) * 0.05f , RT_LOADING_TERRAIN , RT_LOADING_TERRAIN_TEX ) ;
2015-06-21 18:59:23 +00:00
std : : string name = " ../ " + line - > GetParam ( " image " ) - > AsPath ( " textures " ) ;
if ( name . find ( " . " ) = = std : : string : : npos )
2014-11-10 21:50:00 +00:00
name + = " .png " ;
unsigned int dx = line - > GetParam ( " dx " ) - > AsInt ( 1 ) ;
unsigned int dy = line - > GetParam ( " dy " ) - > AsInt ( 1 ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
int tt [ 100 ] ; //TODO: I have no idea how TerrainInitTextures works, but maybe we shuld remove the limit to 100?
2015-06-21 18:59:23 +00:00
if ( dx * dy > 100 )
2014-11-10 21:50:00 +00:00
throw CLevelParserException ( " In TerrainInitTextures: dx*dy must be <100 " ) ;
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " table " ) - > IsDefined ( ) )
{
auto & table = line - > GetParam ( " table " ) - > AsArray ( ) ;
if ( table . size ( ) > dx * dy )
2014-11-10 21:50:00 +00:00
throw CLevelParserException ( " In TerrainInitTextures: table size must be dx*dy " ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
for ( unsigned int i = 0 ; i < dx * dy ; i + + )
{
2015-06-21 18:59:23 +00:00
if ( i > = table . size ( ) )
2014-11-10 21:50:00 +00:00
{
tt [ i ] = 0 ;
2015-06-21 18:59:23 +00:00
}
else
{
2014-11-10 21:50:00 +00:00
tt [ i ] = table [ i ] - > AsInt ( ) ;
}
2014-09-24 20:54:26 +00:00
}
2015-06-21 18:59:23 +00:00
}
else
{
2014-11-10 21:50:00 +00:00
for ( unsigned int i = 0 ; i < dx * dy ; i + + )
2014-09-24 20:54:26 +00:00
{
2014-11-10 21:50:00 +00:00
tt [ i ] = 0 ;
2014-09-24 20:54:26 +00:00
}
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
m_terrain - > InitTextures ( name . c_str ( ) , tt , dx , dy ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainInit " & & ! resetObject )
{
m_terrain - > InitMaterials ( line - > GetParam ( " id " ) - > AsInt ( 1 ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainMaterial " & & ! resetObject )
{
std : : string name = line - > GetParam ( " image " ) - > AsPath ( " textures " ) ;
2015-06-21 18:59:23 +00:00
if ( name . find ( " . " ) = = std : : string : : npos )
2014-11-10 21:50:00 +00:00
name + = " .png " ;
2015-06-21 18:59:23 +00:00
name = " ../ " + name ;
2014-11-10 21:50:00 +00:00
m_terrain - > AddMaterial ( line - > GetParam ( " id " ) - > AsInt ( 0 ) ,
name . c_str ( ) ,
Math : : Point ( line - > GetParam ( " u " ) - > AsFloat ( ) ,
line - > GetParam ( " v " ) - > AsFloat ( ) ) ,
line - > GetParam ( " up " ) - > AsInt ( ) ,
line - > GetParam ( " right " ) - > AsInt ( ) ,
line - > GetParam ( " down " ) - > AsInt ( ) ,
line - > GetParam ( " left " ) - > AsInt ( ) ,
line - > GetParam ( " hard " ) - > AsFloat ( 0.5f ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainLevel " & & ! resetObject )
{
2015-08-07 21:40:38 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f + ( 3.f / 5.f ) * 0.05f , RT_LOADING_TERRAIN , RT_LOADING_TERRAIN_TEX ) ;
2014-11-10 21:50:00 +00:00
int id [ 50 ] ; //TODO: I have no idea how TerrainLevel works, but maybe we should remove the limit to 50?
2015-06-21 18:59:23 +00:00
if ( line - > GetParam ( " id " ) - > IsDefined ( ) )
{
auto & idArray = line - > GetParam ( " id " ) - > AsArray ( ) ;
if ( idArray . size ( ) > 50 )
2014-11-10 21:50:00 +00:00
throw CLevelParserException ( " In TerrainLevel: id array size must be < 50 " ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
unsigned int i = 0 ;
while ( i < 50 )
2014-09-24 20:54:26 +00:00
{
2015-06-21 18:59:23 +00:00
id [ i ] = idArray [ i ] - > AsInt ( ) ;
2014-11-10 21:50:00 +00:00
i + + ;
2015-06-21 18:59:23 +00:00
if ( i > = idArray . size ( ) ) break ;
2014-09-24 20:54:26 +00:00
}
2014-11-10 21:50:00 +00:00
id [ i ] = 0 ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
m_terrain - > GenerateMaterials ( id ,
line - > GetParam ( " min " ) - > AsFloat ( 0.0f ) * g_unit ,
line - > GetParam ( " max " ) - > AsFloat ( 100.0f ) * g_unit ,
line - > GetParam ( " slope " ) - > AsFloat ( 5.0f ) ,
line - > GetParam ( " freq " ) - > AsFloat ( 100.0f ) ,
line - > GetParam ( " center " ) - > AsPoint ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) * g_unit ,
line - > GetParam ( " radius " ) - > AsFloat ( 0.0f ) * g_unit ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " TerrainCreate " & & ! resetObject )
{
2015-08-07 21:40:38 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.2f + ( 4.f / 5.f ) * 0.05f , RT_LOADING_TERRAIN , RT_LOADING_TERRAIN_GEN ) ;
2014-11-10 21:50:00 +00:00
m_terrain - > CreateObjects ( ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " BeginObject " )
{
InitEye ( ) ;
SetMovieLock ( false ) ;
2015-06-21 18:59:23 +00:00
2016-03-25 16:06:01 +00:00
if ( ! resetObject )
2015-07-22 10:45:50 +00:00
ChangeColor ( ) ; // changes the colors of texture
2015-08-04 08:52:10 +00:00
if ( ! m_sceneReadPath . empty ( ) ) // loading file ?
2015-08-07 18:48:55 +00:00
{
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.25f , RT_LOADING_OBJECTS_SAVED ) ;
2015-08-04 08:52:10 +00:00
sel = IOReadScene ( m_sceneReadPath + " /data.sav " , m_sceneReadPath + " /cbot.run " ) ;
2015-08-07 18:48:55 +00:00
}
else
{
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.25f , RT_LOADING_OBJECTS ) ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2015-08-04 08:52:10 +00:00
if ( line - > GetCommand ( ) = = " LevelController " & & m_sceneReadPath . empty ( ) )
2014-11-10 21:50:00 +00:00
{
2016-04-08 18:56:09 +00:00
if ( m_controller ! = nullptr )
{
throw CLevelParserException ( " There can be only one LevelController in the level " ) ;
}
2015-08-14 16:19:58 +00:00
m_controller = m_objMan - > CreateObject ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 0.0f , OBJECT_CONTROLLER ) ;
2015-08-15 19:29:08 +00:00
assert ( m_controller - > Implements ( ObjectInterfaceType : : Programmable ) ) ;
assert ( m_controller - > Implements ( ObjectInterfaceType : : ProgramStorage ) ) ;
2017-05-24 08:50:43 +00:00
assert ( m_controller - > Implements ( ObjectInterfaceType : : Old ) ) ;
dynamic_cast < COldObject * > ( m_controller ) - > SetCheckToken ( false ) ;
2015-08-15 19:29:08 +00:00
if ( line - > GetParam ( " script " ) - > IsDefined ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-15 21:29:21 +00:00
CProgramStorageObject * programStorage = dynamic_cast < CProgramStorageObject * > ( m_controller ) ;
Program * program = programStorage - > AddProgram ( ) ;
2016-01-30 16:24:02 +00:00
programStorage - > ReadProgram ( program , line - > GetParam ( " script " ) - > AsPath ( " ai " ) ) ;
2015-08-15 19:29:08 +00:00
program - > readOnly = true ;
2015-08-15 21:29:21 +00:00
dynamic_cast < CProgrammableObject * > ( m_controller ) - > RunProgram ( program ) ;
2012-06-26 20:23:05 +00:00
}
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2015-08-04 08:52:10 +00:00
if ( line - > GetCommand ( ) = = " CreateObject " & & m_sceneReadPath . empty ( ) )
2014-11-10 21:50:00 +00:00
{
2015-08-14 16:19:58 +00:00
ObjectCreateParams params = CObject : : ReadCreateParams ( line . get ( ) ) ;
2015-06-21 18:59:23 +00:00
2015-08-07 18:48:55 +00:00
float objectProgress = static_cast < float > ( rankObj ) / static_cast < float > ( numObjects ) ;
std : : string details = StrUtils : : ToString < int > ( rankObj + 1 ) + " / " + StrUtils : : ToString < int > ( numObjects ) ;
# if DEV_BUILD
// Object categories may spoil the level a bit, so hide them in release builds
2015-08-14 16:19:58 +00:00
details + = " : " + CLevelParserParam : : FromObjectType ( params . type ) ;
2015-08-07 18:48:55 +00:00
# endif
2015-08-15 21:37:30 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.25f + objectProgress * 0.75f , RT_LOADING_OBJECTS , details ) ;
2015-08-07 18:48:55 +00:00
2015-07-14 16:20:05 +00:00
try
{
2015-08-14 16:19:58 +00:00
CObject * obj = m_objMan - > CreateObject ( params ) ;
obj - > Read ( line . get ( ) ) ;
2015-07-11 17:48:37 +00:00
2015-08-14 16:19:58 +00:00
if ( m_fixScene & & obj - > GetType ( ) = = OBJECT_HUMAN )
2012-06-26 20:23:05 +00:00
{
2015-08-14 16:19:58 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Movable ) ) ;
CMotion * motion = dynamic_cast < CMovableObject * > ( obj ) - > GetMotion ( ) ;
if ( m_phase = = PHASE_WIN ) motion - > SetAction ( MHS_WIN , 0.4f ) ;
if ( m_phase = = PHASE_LOST ) motion - > SetAction ( MHS_LOST , 0.5f ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2015-08-14 16:19:58 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Controllable ) & & line - > GetParam ( " select " ) - > AsBool ( false ) )
sel = obj ;
2015-06-21 18:59:23 +00:00
2015-08-14 16:19:58 +00:00
if ( obj - > GetType ( ) = = OBJECT_BASE )
m_base = obj ;
2015-06-21 18:59:23 +00:00
2015-08-15 19:29:08 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : ProgramStorage ) )
2014-11-10 21:50:00 +00:00
{
2015-08-15 21:29:21 +00:00
CProgramStorageObject * programStorage = dynamic_cast < CProgramStorageObject * > ( obj ) ;
2015-06-21 18:59:23 +00:00
2015-08-15 21:29:21 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Controllable ) & & dynamic_cast < CControllableObject * > ( obj ) - > GetSelectable ( ) & & obj - > GetType ( ) ! = OBJECT_HUMAN )
2014-11-10 21:50:00 +00:00
{
2015-08-15 21:29:21 +00:00
programStorage - > SetProgramStorageIndex ( rankObj ) ;
2014-11-10 21:50:00 +00:00
}
2015-06-21 18:59:23 +00:00
2015-08-15 21:29:21 +00:00
char categoryChar = GetLevelCategoryDir ( m_levelCategory ) [ 0 ] ;
programStorage - > LoadAllProgramsForLevel (
line . get ( ) ,
m_playerProfile - > GetSaveFile ( StrUtils : : Format ( " %c%.3d%.3d " , categoryChar , m_levelChap , m_levelRank ) ) ,
soluce
) ;
}
2015-08-14 16:19:58 +00:00
}
catch ( const CObjectCreateException & e )
{
GetLogger ( ) - > Error ( " Error loading level object: %s \n " , e . what ( ) ) ;
throw ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
rankObj + + ;
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " CreateFog " & & ! resetObject )
{
Gfx : : ParticleType type = static_cast < Gfx : : ParticleType > ( Gfx : : PARTIFOG0 + ( line - > GetParam ( " type " ) - > AsInt ( ) ) ) ;
Math : : Vector pos = line - > GetParam ( " pos " ) - > AsPoint ( ) * g_unit ;
float height = line - > GetParam ( " height " ) - > AsFloat ( 1.0f ) * g_unit ;
float ddim = line - > GetParam ( " dim " ) - > AsFloat ( 50.0f ) * g_unit ;
float delay = line - > GetParam ( " delay " ) - > AsFloat ( 2.0f ) ;
m_terrain - > AdjustToFloor ( pos ) ;
pos . y + = height ;
Math : : Point dim ;
dim . x = ddim ;
dim . y = dim . x ;
m_particle - > CreateParticle ( pos , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , dim , type , delay , 0.0f , 0.0f ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " CreateLight " & & ! resetObject )
{
Gfx : : EngineObjectType type ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
int lightRank = CreateLight ( line - > GetParam ( " dir " ) - > AsPoint ( ) ,
line - > GetParam ( " color " ) - > AsColor ( Gfx : : Color ( 0.5f , 0.5f , 0.5f , 1.0f ) ) ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
type = line - > GetParam ( " type " ) - > AsTerrainType ( Gfx : : ENG_OBJTYPE_NULL ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_TERRAIN )
{
m_lightMan - > SetLightPriority ( lightRank , Gfx : : LIGHT_PRI_HIGHEST ) ;
m_lightMan - > SetLightIncludeType ( lightRank , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_QUARTZ )
m_lightMan - > SetLightIncludeType ( lightRank , Gfx : : ENG_OBJTYPE_QUARTZ ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_METAL )
m_lightMan - > SetLightIncludeType ( lightRank , Gfx : : ENG_OBJTYPE_METAL ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_FIX )
m_lightMan - > SetLightExcludeType ( lightRank , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
continue ;
}
if ( line - > GetCommand ( ) = = " CreateSpot " & & ! resetObject )
{
Gfx : : EngineObjectType type ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
int rankLight = CreateSpot ( line - > GetParam ( " pos " ) - > AsPoint ( ) * g_unit ,
2014-09-24 20:54:26 +00:00
line - > GetParam ( " color " ) - > AsColor ( Gfx : : Color ( 0.5f , 0.5f , 0.5f , 1.0f ) ) ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
type = line - > GetParam ( " type " ) - > AsTerrainType ( Gfx : : ENG_OBJTYPE_NULL ) ;
if ( type = = Gfx : : ENG_OBJTYPE_TERRAIN )
m_lightMan - > SetLightIncludeType ( rankLight , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_QUARTZ )
m_lightMan - > SetLightIncludeType ( rankLight , Gfx : : ENG_OBJTYPE_QUARTZ ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_METAL )
m_lightMan - > SetLightIncludeType ( rankLight , Gfx : : ENG_OBJTYPE_METAL ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( type = = Gfx : : ENG_OBJTYPE_FIX )
m_lightMan - > SetLightExcludeType ( rankLight , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " GroundSpot " & & ! resetObject )
2013-06-20 21:14:37 +00:00
{
2015-08-04 08:52:10 +00:00
int rank = m_engine - > CreateGroundSpot ( ) ;
2014-11-10 21:50:00 +00:00
if ( rank ! = - 1 )
{
m_engine - > SetObjectGroundSpotPos ( rank , line - > GetParam ( " pos " ) - > AsPoint ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) * g_unit ) ;
m_engine - > SetObjectGroundSpotRadius ( rank , line - > GetParam ( " radius " ) - > AsFloat ( 10.0f ) * g_unit ) ;
m_engine - > SetObjectGroundSpotColor ( rank , line - > GetParam ( " color " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ) ;
m_engine - > SetObjectGroundSpotSmooth ( rank , line - > GetParam ( " smooth " ) - > AsFloat ( 1.0f ) ) ;
m_engine - > SetObjectGroundSpotMinMax ( rank , line - > GetParam ( " min " ) - > AsFloat ( 0.0f ) * g_unit ,
line - > GetParam ( " max " ) - > AsFloat ( 0.0f ) * g_unit ) ;
}
continue ;
2013-06-20 21:14:37 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " WaterColor " & & ! resetObject )
{
m_engine - > SetWaterAddColor ( line - > GetParam ( " color " ) - > AsColor ( ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " MapColor " & & ! resetObject )
{
m_map - > FloorColorMap ( line - > GetParam ( " floor " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ,
line - > GetParam ( " water " ) - > AsColor ( Gfx : : Color ( 0.533f , 0.533f , 0.533f , 0.533f ) ) ) ;
m_mapShow = line - > GetParam ( " show " ) - > AsBool ( true ) ;
m_map - > SetToy ( line - > GetParam ( " toyIcon " ) - > AsBool ( false ) ) ;
m_mapImage = line - > GetParam ( " image " ) - > AsBool ( false ) ;
if ( m_mapImage )
{
Math : : Vector offset ;
2015-08-03 18:55:33 +00:00
strcpy ( m_mapFilename , line - > GetParam ( " filename " ) - > AsPath ( " textures " ) . c_str ( ) ) ;
2014-11-10 21:50:00 +00:00
offset = line - > GetParam ( " offset " ) - > AsPoint ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
m_map - > SetFixParam ( line - > GetParam ( " zoom " ) - > AsFloat ( 1.0f ) ,
offset . x , offset . z ,
line - > GetParam ( " angle " ) - > AsFloat ( 0.0f ) * Math : : PI / 180.0f ,
line - > GetParam ( " mode " ) - > AsInt ( 0 ) ,
line - > GetParam ( " debug " ) - > AsBool ( false ) ) ;
}
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " MapZoom " & & ! resetObject )
{
m_map - > ZoomMap ( line - > GetParam ( " factor " ) - > AsFloat ( 2.0f ) ) ;
m_map - > MapEnable ( line - > GetParam ( " enable " ) - > AsBool ( true ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " MaxFlyingHeight " & & ! resetObject )
{
m_terrain - > SetFlyingMaxHeight ( line - > GetParam ( " max " ) - > AsFloat ( 280.0f ) * g_unit ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " AddFlyingHeight " & & ! resetObject )
{
m_terrain - > AddFlyingLimit ( line - > GetParam ( " center " ) - > AsPoint ( ) * g_unit ,
line - > GetParam ( " extRadius " ) - > AsFloat ( 20.0f ) * g_unit ,
line - > GetParam ( " intRadius " ) - > AsFloat ( 10.0f ) * g_unit ,
line - > GetParam ( " maxHeight " ) - > AsFloat ( 200.0f ) ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " Camera " )
{
m_camera - > Init ( line - > GetParam ( " eye " ) - > AsPoint ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) * g_unit ,
line - > GetParam ( " lookat " ) - > AsPoint ( Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) * g_unit ,
resetObject ? 0.0f : line - > GetParam ( " delay " ) - > AsFloat ( 0.0f ) ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetParam ( " fadeIn " ) - > AsBool ( false ) )
m_camera - > StartOver ( Gfx : : CAM_OVER_EFFECT_FADEIN_WHITE , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 1.0f ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2016-04-08 18:56:09 +00:00
if ( line - > GetCommand ( ) = = " EndMissionTake " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2015-07-17 17:22:31 +00:00
auto endTake = MakeUnique < CSceneEndCondition > ( ) ;
2015-07-07 14:17:19 +00:00
endTake - > Read ( line . get ( ) ) ;
2016-04-08 18:56:09 +00:00
if ( endTake - > immediat )
m_endTakeImmediat = true ;
2015-07-07 14:17:19 +00:00
m_endTake . push_back ( std : : move ( endTake ) ) ;
2016-07-04 14:30:22 +00:00
if ( ! line - > GetParam ( " pos " ) - > IsDefined ( ) | | ! line - > GetParam ( " dist " ) - > IsDefined ( ) )
{
LoadingWarning ( " The defaults for pos= and dist= are going to change, specify them explicitly. See issue #759 (https://git.io/vVBzH) " ) ;
}
2014-11-10 21:50:00 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2016-04-08 18:56:09 +00:00
if ( line - > GetCommand ( ) = = " EndMissionDelay " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2014-11-10 21:50:00 +00:00
m_endTakeWinDelay = line - > GetParam ( " win " ) - > AsFloat ( 2.0f ) ;
m_endTakeLostDelay = line - > GetParam ( " lost " ) - > AsFloat ( 2.0f ) ;
continue ;
}
2016-04-08 18:56:09 +00:00
if ( line - > GetCommand ( ) = = " EndMissionResearch " & & ! resetObject ) // This is not used in any original Colobot levels, but we'll keep it for userlevel creators
2014-11-10 21:50:00 +00:00
{
m_endTakeResearch | = line - > GetParam ( " type " ) - > AsResearchFlag ( ) ;
continue ;
}
2015-06-21 18:59:23 +00:00
2017-05-17 16:22:27 +00:00
if ( line - > GetCommand ( ) = = " Scoreboard " & & ! resetObject )
{
if ( line - > GetParam ( " enable " ) - > AsBool ( false ) )
{
// Create the scoreboard
m_scoreboard = MakeUnique < CScoreboard > ( ) ;
}
continue ;
}
if ( line - > GetCommand ( ) = = " ScoreboardKillRule " & & ! resetObject )
{
if ( ! m_scoreboard )
throw CLevelParserException ( " ScoreboardKillRule encountered but scoreboard is not enabled " ) ;
auto rule = MakeUnique < CScoreboard : : CScoreboardKillRule > ( ) ;
rule - > Read ( line . get ( ) ) ;
m_scoreboard - > AddKillRule ( std : : move ( rule ) ) ;
continue ;
}
if ( line - > GetCommand ( ) = = " ScoreboardEndTakeRule " & & ! resetObject )
{
if ( ! m_scoreboard )
throw CLevelParserException ( " ScoreboardEndTakeRule encountered but scoreboard is not enabled " ) ;
auto rule = MakeUnique < CScoreboard : : CScoreboardEndTakeRule > ( ) ;
rule - > Read ( line . get ( ) ) ;
m_scoreboard - > AddEndTakeRule ( std : : move ( rule ) ) ;
continue ;
}
2016-04-08 20:15:54 +00:00
if ( line - > GetCommand ( ) = = " ObligatoryToken " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2016-04-08 20:15:54 +00:00
std : : string token = line - > GetParam ( " text " ) - > AsString ( ) ;
if ( ! line - > GetParam ( " min " ) - > IsDefined ( ) & & ! line - > GetParam ( " max " ) - > IsDefined ( ) )
GetLogger ( ) - > Warn ( " ObligatoryToken without specifying min/max is provided only for backwards compatibility - instead, do this: ObligatoryToken text= \" %s \" min=1 \n " , token . c_str ( ) ) ;
if ( m_obligatoryTokens . count ( token ) )
throw CLevelParserException ( " Incorrect ObligatoryToken specification - you cannot define a token twice " ) ;
m_obligatoryTokens [ token ] . min = line - > GetParam ( " min " ) - > AsInt ( line - > GetParam ( " max " ) - > IsDefined ( ) ? - 1 : 1 ) ; // BACKWARDS COMPATIBILITY: if neither min or max are defined, default to min=1
m_obligatoryTokens [ token ] . max = line - > GetParam ( " max " ) - > AsInt ( - 1 ) ;
if ( m_obligatoryTokens [ token ] . min > = 0 & & m_obligatoryTokens [ token ] . max > = 0 & & m_obligatoryTokens [ token ] . min > m_obligatoryTokens [ token ] . max )
2013-05-26 15:47:54 +00:00
{
2016-04-08 20:15:54 +00:00
throw CLevelParserException ( " Incorrect ObligatoryToken specification - min cannot be greater than max " ) ;
2013-05-26 15:47:54 +00:00
}
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2016-04-08 20:15:54 +00:00
if ( line - > GetCommand ( ) = = " ProhibitedToken " & & ! resetObject ) // NOTE: Kept only for backwards compatibility
2014-11-10 21:50:00 +00:00
{
2016-04-08 20:15:54 +00:00
std : : string token = line - > GetParam ( " text " ) - > AsString ( ) ;
GetLogger ( ) - > Warn ( " ProhibitedToken is only provided for backwards compatibility - instead, do this: ObligatoryToken text= \" %s \" max=0 \n " , token . c_str ( ) ) ;
if ( m_obligatoryTokens . count ( token ) )
throw CLevelParserException ( " Incorrect ObligatoryToken specification - you cannot define a token twice " ) ;
m_obligatoryTokens [ token ] . min = - 1 ;
m_obligatoryTokens [ token ] . max = 0 ;
2014-11-10 21:50:00 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " EnableBuild " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2015-07-13 15:38:19 +00:00
m_build | = line - > GetParam ( " type " ) - > AsBuildFlag ( ) ;
2014-11-10 21:50:00 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " EnableResearch " & & ! resetObject )
2012-06-26 20:23:05 +00:00
{
2015-07-13 15:38:19 +00:00
m_researchEnable | = line - > GetParam ( " type " ) - > AsResearchFlag ( ) ;
2014-11-10 21:50:00 +00:00
continue ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
2015-08-04 08:52:10 +00:00
if ( line - > GetCommand ( ) = = " DoneResearch " & & m_sceneReadPath . empty ( ) & & ! resetObject ) // not loading file?
2014-11-10 21:50:00 +00:00
{
2015-07-13 16:13:28 +00:00
m_researchDone [ 0 ] | = line - > GetParam ( " type " ) - > AsResearchFlag ( ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2014-11-10 21:50:00 +00:00
if ( line - > GetCommand ( ) = = " NewScript " & & ! resetObject )
{
2016-12-27 22:38:57 +00:00
m_newScriptName . push_back ( NewScriptName ( line - > GetParam ( " type " ) - > AsObjectType ( OBJECT_NULL ) , const_cast < char * > ( line - > GetParam ( " name " ) - > AsPath ( " ai " ) . c_str ( ) ) ) ) ;
2014-11-10 21:50:00 +00:00
continue ;
}
2015-06-21 18:59:23 +00:00
2015-08-04 08:52:10 +00:00
if ( ! m_sceneReadPath . empty ( ) ) continue ; // ignore errors when loading saved game (TODO: don't report ones that are just not loaded when loading saved game)
2015-06-21 18:59:23 +00:00
if ( resetObject ) continue ; // ignore when reseting just objects (TODO: see above)
2015-08-05 17:27:26 +00:00
throw CLevelParserException ( " Unknown command: ' " + line - > GetCommand ( ) + " ' in " + line - > GetLevelFilename ( ) + " : " + boost : : lexical_cast < std : : string > ( line - > GetLineNumber ( ) ) ) ;
2012-06-26 20:23:05 +00:00
}
2017-06-04 11:10:50 +00:00
// Do this here to prevent the first frame from taking a long time to render
m_engine - > UpdateGroundSpotTextures ( ) ;
2015-08-07 18:48:55 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 1.0f , RT_LOADING_FINISHED ) ;
2015-08-13 22:07:45 +00:00
if ( m_ui - > GetLoadingScreen ( ) - > IsVisible ( ) )
{
2017-06-04 11:10:50 +00:00
// Force render of the "Loading finished" screen because it looks weird when the progress bar disappears in the middle
2015-08-13 22:07:45 +00:00
m_app - > Render ( ) ;
}
2015-08-07 18:48:55 +00:00
if ( ! resetObject )
{
m_engine - > SetBackground ( backgroundPath ,
backgroundUp ,
backgroundDown ,
backgroundCloudUp ,
backgroundCloudDown ,
backgroundFull ) ;
}
2015-08-04 08:52:10 +00:00
if ( m_levelCategory = = LevelCategory : : Missions & & ! resetObject ) // mission?
2015-07-18 21:14:20 +00:00
{
2015-07-19 13:34:49 +00:00
m_playerProfile - > SetFreeGameResearchUnlock ( m_playerProfile - > GetFreeGameResearchUnlock ( ) | m_researchDone [ 0 ] ) ;
m_playerProfile - > SetFreeGameBuildUnlock ( m_playerProfile - > GetFreeGameBuildUnlock ( ) | m_build ) ;
2015-07-18 21:14:20 +00:00
}
2012-09-15 13:33:08 +00:00
2015-08-04 08:52:10 +00:00
if ( m_levelCategory = = LevelCategory : : FreeGame & & ! resetObject ) // free play?
2014-11-10 21:50:00 +00:00
{
2015-07-19 13:34:49 +00:00
m_researchDone [ 0 ] = m_playerProfile - > GetFreeGameResearchUnlock ( ) ;
2015-07-13 15:38:19 +00:00
2015-07-19 13:34:49 +00:00
m_build = m_playerProfile - > GetFreeGameBuildUnlock ( ) ;
2015-07-13 15:38:19 +00:00
m_build & = ~ BUILD_RESEARCH ;
m_build & = ~ BUILD_LABO ;
m_build | = BUILD_FACTORY ;
m_build | = BUILD_GFLAT ;
m_build | = BUILD_FLAG ;
2014-11-10 21:50:00 +00:00
}
2012-06-26 20:23:05 +00:00
2015-07-20 17:35:20 +00:00
if ( ! resetObject )
2014-11-10 21:50:00 +00:00
{
m_short - > SetMode ( false ) ; // vehicles?
}
2012-06-26 20:23:05 +00:00
2015-08-07 18:48:55 +00:00
m_map - > ShowMap ( m_mapShow ) ;
2014-11-10 21:50:00 +00:00
m_map - > UpdateMap ( ) ;
// TODO: m_engine->TimeInit(); ??
2014-12-11 18:01:57 +00:00
m_input - > ResetKeyStates ( ) ;
2014-11-10 21:50:00 +00:00
m_time = 0.0f ;
2017-10-24 09:12:19 +00:00
if ( m_sceneReadPath . empty ( ) ) m_gameTime = 0.0f ;
2015-07-09 21:15:30 +00:00
m_gameTimeAbsolute = 0.0f ;
2014-11-11 13:50:44 +00:00
m_autosaveLast = 0.0f ;
2014-11-10 21:50:00 +00:00
m_infoUsed = 0 ;
2012-06-26 20:23:05 +00:00
2014-11-10 21:50:00 +00:00
m_selectObject = sel ;
2012-09-15 13:33:08 +00:00
2014-11-10 21:50:00 +00:00
if ( m_base = = nullptr & & // no main base?
! m_fixScene ) // interractive scene?
2012-06-26 20:23:05 +00:00
{
2015-08-14 16:19:58 +00:00
CObject * obj = sel ;
2014-11-10 21:50:00 +00:00
if ( sel = = nullptr )
obj = SearchHuman ( ) ;
if ( obj ! = nullptr )
{
2015-08-10 21:20:36 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Controllable ) ) ;
2014-11-10 21:50:00 +00:00
SelectObject ( obj ) ;
m_camera - > SetControllingObject ( obj ) ;
2015-08-10 21:20:36 +00:00
m_camera - > SetType ( dynamic_cast < CControllableObject * > ( obj ) - > GetCameraType ( ) ) ;
2014-11-10 21:50:00 +00:00
}
2012-06-26 20:23:05 +00:00
}
2014-11-10 21:50:00 +00:00
if ( m_fixScene )
m_camera - > SetType ( Gfx : : CAM_TYPE_SCRIPT ) ;
2012-09-15 13:33:08 +00:00
2015-08-17 20:40:52 +00:00
if ( ! m_sceneReadPath . empty ( ) & & sel ! = nullptr ) // loading file?
2014-11-10 21:50:00 +00:00
{
2015-07-12 09:01:16 +00:00
Math : : Vector pos = sel - > GetPosition ( ) ;
2014-11-10 21:50:00 +00:00
m_camera - > Init ( pos , pos , 0.0f ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 21:50:00 +00:00
SelectObject ( sel ) ;
m_camera - > SetControllingObject ( sel ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 21:50:00 +00:00
m_beginSatCom = true ; // message already displayed
}
2015-06-21 18:59:23 +00:00
}
catch ( . . . )
{
2015-08-04 08:52:10 +00:00
m_sceneReadPath = " " ;
2014-11-10 21:50:00 +00:00
throw ;
2012-06-26 20:23:05 +00:00
}
2015-08-04 08:52:10 +00:00
m_sceneReadPath = " " ;
2015-06-21 18:59:23 +00:00
if ( m_app - > GetSceneTestMode ( ) )
2014-11-10 19:23:18 +00:00
m_eventQueue - > AddEvent ( Event ( EVENT_QUIT ) ) ;
2015-08-07 18:48:55 +00:00
m_ui - > ShowLoadingScreen ( false ) ;
2015-09-06 17:12:00 +00:00
if ( m_missionType = = MISSION_CODE_BATTLE )
{
CreateCodeBattleInterface ( ) ;
}
2015-08-07 18:48:55 +00:00
CreateShortcuts ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-06 16:19:01 +00:00
void CRobotMain : : LevelLoadingError ( const std : : string & error , const std : : runtime_error & exception , Phase exitPhase )
{
2015-08-14 16:19:58 +00:00
m_ui - > ShowLoadingScreen ( false ) ;
2015-08-06 16:19:01 +00:00
GetLogger ( ) - > Error ( " %s \n " , error . c_str ( ) ) ;
GetLogger ( ) - > Error ( " %s \n " , exception . what ( ) ) ;
ChangePhase ( exitPhase ) ;
m_ui - > GetDialog ( ) - > StartInformation ( " Loading error " , error , exception . what ( ) , true , false ) ;
}
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 ( )
{
2015-07-20 17:35:20 +00:00
if ( m_phase ! = PHASE_SIMUL & &
m_phase ! = PHASE_SETUPds & &
m_phase ! = PHASE_SETUPgs & &
m_phase ! = PHASE_SETUPps & &
m_phase ! = PHASE_SETUPcs & &
m_phase ! = PHASE_SETUPss & &
m_phase ! = PHASE_WIN & &
m_phase ! = PHASE_LOST & &
m_phase ! = PHASE_APPERANCE ) return ;
2015-07-22 10:45:50 +00:00
// Player texture
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
2015-07-19 13:34:49 +00:00
colorNew1 = m_playerProfile - > GetApperance ( ) . colorCombi ;
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
2015-07-19 13:34:49 +00:00
colorNew2 = m_playerProfile - > GetApperance ( ) . colorBand ;
2012-09-15 13:33:08 +00:00
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
2014-11-11 14:52:08 +00:00
m_engine - > ChangeTextureColor ( " textures/objects/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 ;
}
2015-07-19 13:34:49 +00:00
colorNew1 = m_playerProfile - > GetApperance ( ) . colorHair ;
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 ] ;
2014-11-11 14:52:08 +00:00
sprintf ( name , " textures/objects/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 ;
2015-07-22 10:45:50 +00:00
// VehicleColor
2012-06-26 20:23:05 +00:00
2016-03-27 11:34:26 +00:00
for ( auto it : m_colorNewBot )
2015-07-22 10:45:50 +00:00
{
int team = it . first ;
Gfx : : Color newColor = it . second ;
std : : string teamStr = StrUtils : : ToString < int > ( team ) ;
if ( team = = 0 ) teamStr = " " ;
2012-06-26 20:23:05 +00:00
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/objects/base1.png " + teamStr , " textures/objects/base1.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
m_engine - > ChangeTextureColor ( " textures/objects/convert.png " + teamStr , " textures/objects/convert.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
m_engine - > ChangeTextureColor ( " textures/objects/derrick.png " + teamStr , " textures/objects/derrick.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
m_engine - > ChangeTextureColor ( " textures/objects/factory.png " + teamStr , " textures/objects/factory.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
m_engine - > ChangeTextureColor ( " textures/objects/lemt.png " + teamStr , " textures/objects/lemt.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
m_engine - > ChangeTextureColor ( " textures/objects/roller.png " + teamStr , " textures/objects/roller.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
m_engine - > ChangeTextureColor ( " textures/objects/search.png " + teamStr , " textures/objects/search.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , nullptr , 0 , true ) ;
2015-07-22 10:45:50 +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
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/objects/drawer.png " + teamStr , " textures/objects/drawer.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , exclu , 0 , true ) ;
2015-07-22 10:45:50 +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
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/objects/subm.png " + teamStr , " textures/objects/subm.png " , COLOR_REF_BOT , newColor , colorRef2 , colorNew2 , 0.10f , - 1.0f , ts , ti , exclu , 0 , true ) ;
2015-07-22 10:45:50 +00:00
}
// AlienColor
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
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/objects/ant.png " , COLOR_REF_ALIEN , m_colorNewAlien , colorRef2 , colorNew2 , 0.50f , - 1.0f , ts , ti , exclu ) ;
m_engine - > ChangeTextureColor ( " textures/objects/mother.png " , COLOR_REF_ALIEN , m_colorNewAlien , colorRef2 , colorNew2 , 0.50f , - 1.0f , ts , ti ) ;
2012-06-26 20:23:05 +00:00
2015-07-22 10:45:50 +00:00
// GreeneryColor
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/objects/plant.png " , COLOR_REF_GREEN , m_colorNewGreen , colorRef2 , colorNew2 , 0.50f , - 1.0f , ts , ti ) ;
2012-06-26 20:23:05 +00:00
2015-07-22 10:45:50 +00:00
// water color
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 ) ;
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/effect00.png " , COLOR_REF_WATER , m_colorNewWater , colorRef2 , colorNew2 , 0.20f , - 1.0f , ts , ti , nullptr , 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 ) ;
2016-03-27 11:34:26 +00:00
m_engine - > ChangeTextureColor ( " textures/effect02.png " , COLOR_REF_WATER , m_colorNewWater , colorRef2 , colorNew2 , 0.20f , - 1.0f , ts , ti , nullptr , m_colorShiftWater , true ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Calculates the distance to the nearest object
2016-12-27 22:38:57 +00:00
namespace
{
float SearchNearestObject ( CObjectManager * objMan , Math : : Vector center , CObject * exclu )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
float min = 100000.0f ;
2016-12-27 22:38:57 +00:00
for ( CObject * obj : objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-16 18:24:48 +00:00
if ( ! obj - > GetDetectable ( ) ) continue ; // inactive?
2015-07-10 17:03:27 +00:00
if ( IsObjectBeingTransported ( obj ) ) continue ;
2016-12-27 22:38:57 +00:00
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
{
2015-07-12 09:01:16 +00:00
Math : : Vector oPos = obj - > GetPosition ( ) ;
2012-09-15 13:33:08 +00:00
if ( oPos . x ! = center . x | |
oPos . z ! = center . z )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
float dist = Math : : Distance ( center , oPos ) - 80.0f ;
2012-09-15 13:33:08 +00:00
if ( dist < 0.0f ) dist = 0.0f ;
2012-06-26 20:23:05 +00:00
min = Math : : Min ( min , dist ) ;
continue ;
}
}
2016-12-27 22:38:57 +00:00
if ( type = = OBJECT_STATION | |
type = = OBJECT_REPAIR | |
2012-09-15 13:33:08 +00:00
type = = OBJECT_DESTROYER )
2012-06-26 20:23:05 +00:00
{
2015-07-12 09:01:16 +00:00
Math : : Vector oPos = obj - > GetPosition ( ) ;
2016-12-27 22:38:57 +00:00
float dist = Math : : Distance ( center , oPos ) - 8.0f ;
2012-09-15 13:33:08 +00:00
if ( dist < 0.0f ) dist = 0.0f ;
2012-06-26 20:23:05 +00:00
min = Math : : Min ( min , dist ) ;
}
2016-12-27 22:38:57 +00:00
for ( const auto & crashSphere : obj - > GetAllCrashSpheres ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-10 07:26:38 +00:00
Math : : Vector oPos = crashSphere . sphere . pos ;
float oRadius = crashSphere . sphere . radius ;
2016-12-27 22:38:57 +00:00
float dist = Math : : Distance ( center , oPos ) - oRadius ;
2012-09-15 13:33:08 +00:00
if ( dist < 0.0f ) dist = 0.0f ;
2012-06-26 20:23:05 +00:00
min = Math : : Min ( min , dist ) ;
}
}
return min ;
}
2016-12-27 22:38:57 +00:00
}
2012-06-26 20:23:05 +00:00
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 ) ;
2016-12-27 22:38:57 +00:00
float dist = SearchNearestObject ( m_objMan . get ( ) , pos , exclu ) ;
2012-09-15 13:33:08 +00:00
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 ) ;
2016-12-27 22:38:57 +00:00
float dist = SearchNearestObject ( m_objMan . get ( ) , pos , exclu ) ;
2012-09-15 13:33:08 +00:00
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 ;
}
2015-07-22 16:26:05 +00:00
//! Calculates a flat free space
bool CRobotMain : : FlatFreeSpace ( Math : : Vector & center , float minFlat , float minRadius , float maxRadius ,
float space , CObject * exclu )
{
if ( minRadius < maxRadius ) // from internal to external?
{
for ( float radius = minRadius ; radius < = maxRadius ; radius + = space )
{
float ia = space / radius ;
for ( float angle = 0.0f ; angle < Math : : PI * 2.0f ; angle + = ia )
{
Math : : Point p ;
p . x = center . x + radius ;
p . y = center . z ;
p = Math : : RotatePoint ( Math : : Point ( center . x , center . z ) , angle , p ) ;
Math : : Vector pos ;
pos . x = p . x ;
pos . z = p . y ;
pos . y = 0.0f ;
m_terrain - > AdjustToFloor ( pos , true ) ;
2016-12-27 22:38:57 +00:00
float dist = SearchNearestObject ( m_objMan . get ( ) , pos , exclu ) ;
2015-07-22 16:26:05 +00:00
if ( dist > = space )
{
float flat = m_terrain - > GetFlatZoneRadius ( pos , dist / 2.0f ) ;
if ( flat > = dist / 2.0f )
{
flat = m_terrain - > GetFlatZoneRadius ( pos , minFlat ) ;
if ( flat > = minFlat )
{
center = pos ;
return true ;
}
}
}
}
}
}
else // from external to internal?
{
for ( float radius = maxRadius ; radius > = minRadius ; radius - = space )
{
float ia = space / radius ;
for ( float angle = 0.0f ; angle < Math : : PI * 2.0f ; angle + = ia )
{
Math : : Point p ;
p . x = center . x + radius ;
p . y = center . z ;
p = Math : : RotatePoint ( Math : : Point ( center . x , center . z ) , angle , p ) ;
Math : : Vector pos ;
pos . x = p . x ;
pos . z = p . y ;
pos . y = 0.0f ;
m_terrain - > AdjustToFloor ( pos , true ) ;
2016-12-27 22:38:57 +00:00
float dist = SearchNearestObject ( m_objMan . get ( ) , pos , exclu ) ;
2015-07-22 16:26:05 +00:00
if ( dist > = space )
{
float flat = m_terrain - > GetFlatZoneRadius ( pos , dist / 2.0f ) ;
if ( flat > = dist / 2.0f )
{
flat = m_terrain - > GetFlatZoneRadius ( pos , minFlat ) ;
if ( flat > = minFlat )
{
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 )
{
2016-12-27 22:38:57 +00:00
float dist = SearchNearestObject ( m_objMan . get ( ) , center , exclu ) ;
2012-09-15 13:33:08 +00:00
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
2015-06-29 21:05:31 +00:00
void CRobotMain : : ShowDropZone ( CObject * metal , CObject * transporter )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( metal = = nullptr ) return ;
2012-06-26 20:23:05 +00:00
2015-07-12 09:01:16 +00:00
Math : : Vector center = metal - > GetPosition ( ) ;
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 ;
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-16 18:24:48 +00:00
if ( ! obj - > GetDetectable ( ) ) continue ; // inactive?
2015-07-10 17:03:27 +00:00
if ( IsObjectBeingTransported ( obj ) ) continue ;
2012-09-15 13:33:08 +00:00
if ( obj = = metal ) continue ;
2015-06-29 21:05:31 +00:00
if ( obj = = transporter ) continue ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
Math : : Vector oPos ;
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
{
2015-07-12 09:01:16 +00:00
oPos = obj - > GetPosition ( ) ;
2012-09-15 13:33:08 +00:00
float dist = Math : : Distance ( center , oPos ) - 80.0f ;
2012-06-26 20:23:05 +00:00
oMax = Math : : Min ( oMax , dist ) ;
}
else
{
2015-07-10 07:26:38 +00:00
for ( const auto & crashSphere : obj - > GetAllCrashSpheres ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-10 07:26:38 +00:00
float dist = Math : : Distance ( center , crashSphere . sphere . pos ) - crashSphere . sphere . radius ;
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?
{
2015-07-10 07:26:38 +00:00
for ( const auto & crashSphere : obj - > GetAllCrashSpheres ( ) )
2012-06-26 20:23:05 +00:00
{
2015-07-10 07:26:38 +00:00
float dist = Math : : Distance ( center , crashSphere . sphere . pos ) - crashSphere . sphere . radius - 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
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 ;
2015-08-17 20:40:52 +00:00
m_showLimit [ i ] . link = nullptr ;
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
//! 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 ;
2015-08-12 16:05:11 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Ranged ) ) return ;
float range = dynamic_cast < CRangedObject * > ( obj ) - > GetShowLimitRadius ( ) ;
if ( range = = 0.0f ) return ;
SetShowLimit ( 0 , Gfx : : PARTILIMIT1 , obj , obj - > GetPosition ( ) , range ) ;
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
2015-08-11 15:51:39 +00:00
if ( m_showLimit [ i ] . link ! = nullptr )
{
m_showLimit [ i ] . pos = m_showLimit [ i ] . link - > GetPosition ( ) ;
}
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-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 ( )
{
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
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.
void CRobotMain : : SaveOneScript ( CObject * obj )
2012-06-26 20:23:05 +00:00
{
2015-08-15 19:29:08 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : ProgramStorage ) ) return ;
2015-07-10 18:38:44 +00:00
2015-08-15 19:29:08 +00:00
CProgramStorageObject * programStorage = dynamic_cast < CProgramStorageObject * > ( obj ) ;
2012-06-26 20:23:05 +00:00
2015-08-04 08:52:10 +00:00
char categoryChar = GetLevelCategoryDir ( m_levelCategory ) [ 0 ] ;
2015-08-15 21:29:21 +00:00
programStorage - > SaveAllUserPrograms ( m_playerProfile - > GetSaveFile ( StrUtils : : Format ( " %c%.3d%.3d " , categoryChar , m_levelChap , m_levelRank ) ) ) ;
2012-06-26 20:23:05 +00:00
}
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
2015-07-10 18:38:44 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Programmable ) ) return true ;
2015-08-10 16:16:00 +00:00
CProgrammableObject * programmable = dynamic_cast < CProgrammableObject * > ( obj ) ;
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
2015-08-10 16:16:00 +00:00
return programmable - > WriteStack ( file ) ;
2012-06-26 20:23:05 +00:00
}
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
2015-07-10 18:38:44 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : Programmable ) ) return true ;
2015-08-10 16:16:00 +00:00
CProgrammableObject * programmable = dynamic_cast < CProgrammableObject * > ( obj ) ;
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
2015-08-10 16:16:00 +00:00
return programmable - > ReadStack ( file ) ;
2012-06-26 20:23:05 +00:00
}
2016-12-27 22:38:57 +00:00
std : : vector < std : : string > CRobotMain : : GetNewScriptNames ( ObjectType type )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
std : : vector < std : : string > names ;
for ( const auto & newScript : m_newScriptName )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
if ( newScript . type = = type | |
newScript . type = = OBJECT_NULL )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
names . push_back ( newScript . name ) ;
2012-06-26 20:23:05 +00:00
}
}
2016-12-27 22:38:57 +00:00
return names ;
2012-06-26 20:23:05 +00:00
}
2012-09-15 13:33:08 +00:00
//! Seeks if an object occupies in a spot, to prevent a backup of the game
2015-08-13 22:21:18 +00:00
bool CRobotMain : : IOIsBusy ( )
2012-06-26 20:23:05 +00:00
{
2015-12-20 17:35:52 +00:00
if ( CScriptFunctions : : CheckOpenFiles ( ) ) return true ;
2012-06-26 20:23:05 +00:00
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
2015-08-10 11:46:39 +00:00
if ( ! obj - > Implements ( ObjectInterfaceType : : TaskExecutor ) ) continue ;
2015-07-10 18:38:44 +00:00
2015-08-13 22:21:18 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Programmable ) & & dynamic_cast < CProgrammableObject * > ( obj ) - > IsProgram ( ) ) continue ; // TODO: I'm not sure if this is correct but this is how it worked earlier
2015-08-10 11:46:39 +00:00
if ( dynamic_cast < CTaskExecutorObject * > ( obj ) - > IsForegroundTask ( ) ) 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
2015-08-15 21:29:21 +00:00
void CRobotMain : : IOWriteObject ( CLevelParserLine * line , CObject * obj , const std : : string & programDir , int objRank )
2012-06-26 20:23:05 +00:00
{
2015-07-17 18:36:01 +00:00
line - > AddParam ( " type " , MakeUnique < CLevelParserParam > ( obj - > GetType ( ) ) ) ;
line - > AddParam ( " id " , MakeUnique < CLevelParserParam > ( obj - > GetID ( ) ) ) ;
line - > AddParam ( " pos " , MakeUnique < CLevelParserParam > ( obj - > GetPosition ( ) / g_unit ) ) ;
line - > AddParam ( " angle " , MakeUnique < CLevelParserParam > ( obj - > GetRotation ( ) * Math : : RAD_TO_DEG ) ) ;
line - > AddParam ( " zoom " , MakeUnique < CLevelParserParam > ( obj - > GetScale ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2015-07-11 21:41:41 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Old ) )
2012-06-26 20:23:05 +00:00
{
2015-07-17 18:36:01 +00:00
line - > AddParam ( " option " , MakeUnique < CLevelParserParam > ( obj - > GetOption ( ) ) ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-10 21:20:36 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Controllable ) )
{
auto controllableObj = dynamic_cast < CControllableObject * > ( obj ) ;
line - > AddParam ( " trainer " , MakeUnique < CLevelParserParam > ( controllableObj - > GetTrainer ( ) ) ) ;
if ( controllableObj - > GetSelect ( ) )
line - > AddParam ( " select " , MakeUnique < CLevelParserParam > ( true ) ) ;
}
2015-06-21 18:59:23 +00:00
2012-09-15 13:33:08 +00:00
obj - > Write ( line ) ;
2015-06-21 18:59:23 +00:00
if ( obj - > GetType ( ) = = OBJECT_BASE )
2015-07-17 18:36:01 +00:00
line - > AddParam ( " run " , MakeUnique < CLevelParserParam > ( 3 ) ) ; // stops and open (PARAM_FIXSCENE)
2015-06-21 18:59:23 +00:00
2015-08-15 21:29:21 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : ProgramStorage ) )
2012-06-26 20:23:05 +00:00
{
2015-08-15 21:29:21 +00:00
CProgramStorageObject * programStorage = dynamic_cast < CProgramStorageObject * > ( obj ) ;
2016-04-08 16:28:35 +00:00
if ( programStorage - > GetProgramStorageIndex ( ) > = 0 )
2012-06-26 20:23:05 +00:00
{
2015-08-15 21:29:21 +00:00
programStorage - > SaveAllProgramsForSavedScene ( line , programDir ) ;
}
else
{
// Probably an object created after the scene started, not loaded from level file
// This means it doesn't normally store programs so it doesn't have program storage id assigned
programStorage - > SetProgramStorageIndex ( 999 - objRank ) ; // Set something that won't collide with normal programs
programStorage - > SaveAllProgramsForSavedScene ( line , programDir ) ;
programStorage - > SetProgramStorageIndex ( - 1 ) ; // Disable again
2012-06-26 20:23:05 +00:00
}
2015-04-07 11:27:11 +00:00
2015-08-15 21:29:21 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Programmable ) )
2015-04-07 11:27:11 +00:00
{
2015-08-15 21:29:21 +00:00
int run = dynamic_cast < CProgramStorageObject * > ( obj ) - > GetProgramIndex ( dynamic_cast < CProgrammableObject * > ( obj ) - > GetCurrentProgram ( ) ) ;
if ( run ! = - 1 )
2015-04-07 11:27:11 +00:00
{
2015-08-15 21:29:21 +00:00
line - > AddParam ( " run " , MakeUnique < CLevelParserParam > ( run + 1 ) ) ;
2015-04-07 11:27:11 +00:00
}
}
2012-06-26 20:23:05 +00:00
}
}
2012-09-15 13:33:08 +00:00
//! Saves the current game
2015-08-17 18:56:42 +00:00
bool CRobotMain : : IOWriteScene ( std : : string filename , std : : string filecbot , std : : string filescreenshot , const std : : string & info , bool emergencySave )
2012-06-26 20:23:05 +00:00
{
2015-08-17 18:56:42 +00:00
if ( ! emergencySave )
{
// Render the indicator to show that we are working
ShowSaveIndicator ( true ) ;
m_app - > Render ( ) ; // update
}
2015-08-07 13:59:05 +00:00
2015-08-15 21:29:21 +00:00
std : : string dirname = filename . substr ( 0 , filename . find_last_of ( " / " ) ) ;
2015-06-21 18:59:23 +00:00
CLevelParser levelParser ( filename ) ;
CLevelParserLineUPtr line ;
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " Title " ) ;
line - > AddParam ( " text " , MakeUnique < CLevelParserParam > ( std : : string ( info ) ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 20:23:05 +00:00
2015-06-21 09:16:09 +00:00
2014-11-10 13:16:32 +00:00
//TODO: Do we need that? It's not used anyway
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " Version " ) ;
line - > AddParam ( " maj " , MakeUnique < CLevelParserParam > ( 0 ) ) ;
line - > AddParam ( " min " , MakeUnique < CLevelParserParam > ( 1 ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2015-06-21 09:16:09 +00:00
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " Created " ) ;
2016-04-09 16:58:34 +00:00
line - > AddParam ( " date " , MakeUnique < CLevelParserParam > ( static_cast < int > ( time ( nullptr ) ) ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 21:01:17 +00:00
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " Mission " ) ;
2015-08-04 08:52:10 +00:00
line - > AddParam ( " base " , MakeUnique < CLevelParserParam > ( GetLevelCategoryDir ( m_levelCategory ) ) ) ;
if ( m_levelCategory = = LevelCategory : : CustomLevels )
line - > AddParam ( " dir " , MakeUnique < CLevelParserParam > ( GetCustomLevelDir ( ) ) ) ;
2015-07-18 17:43:22 +00:00
else
2015-08-04 08:52:10 +00:00
line - > AddParam ( " chap " , MakeUnique < CLevelParserParam > ( m_levelChap ) ) ;
line - > AddParam ( " rank " , MakeUnique < CLevelParserParam > ( m_levelRank ) ) ;
2017-10-24 09:12:19 +00:00
line - > AddParam ( " gametime " , MakeUnique < CLevelParserParam > ( GetGameTime ( ) ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 20:23:05 +00:00
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " Map " ) ;
line - > AddParam ( " zoom " , MakeUnique < CLevelParserParam > ( m_map - > GetZoomMap ( ) ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 20:23:05 +00:00
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " DoneResearch " ) ;
line - > AddParam ( " bits " , MakeUnique < CLevelParserParam > ( static_cast < int > ( m_researchDone [ 0 ] ) ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 20:23:05 +00:00
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
{
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " BlitzMode " ) ;
line - > AddParam ( " sleep " , MakeUnique < CLevelParserParam > ( sleep ) ) ;
line - > AddParam ( " delay " , MakeUnique < CLevelParserParam > ( delay ) ) ;
line - > AddParam ( " magnetic " , MakeUnique < CLevelParserParam > ( magnetic / g_unit ) ) ;
line - > AddParam ( " progress " , MakeUnique < CLevelParserParam > ( progress ) ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 09:16:09 +00:00
2015-06-21 18:59:23 +00:00
2012-09-15 13:33:08 +00:00
int objRank = 0 ;
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_TOTO ) continue ;
2015-07-10 17:03:27 +00:00
if ( IsObjectBeingTransported ( obj ) ) continue ;
2015-08-16 18:24:48 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Destroyable ) & & dynamic_cast < CDestroyableObject * > ( obj ) - > IsDying ( ) ) continue ;
2012-06-26 20:23:05 +00:00
2015-07-10 20:13:39 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Carrier ) )
2015-06-21 18:59:23 +00:00
{
2015-07-10 20:13:39 +00:00
CObject * cargo = dynamic_cast < CCarrierObject * > ( obj ) - > GetCargo ( ) ;
if ( cargo ! = nullptr ) // object transported?
{
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " CreateFret " ) ;
2015-08-15 21:29:21 +00:00
IOWriteObject ( line . get ( ) , cargo , dirname , objRank + + ) ;
2015-07-10 20:13:39 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
}
2014-11-10 13:16:32 +00:00
}
2012-06-26 20:23:05 +00:00
2015-07-10 21:47:59 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Powered ) )
2015-06-21 18:59:23 +00:00
{
2015-07-10 21:47:59 +00:00
CObject * power = dynamic_cast < CPoweredObject * > ( obj ) - > GetPower ( ) ;
if ( power ! = nullptr ) // battery transported?
{
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " CreatePower " ) ;
2015-08-15 21:29:21 +00:00
IOWriteObject ( line . get ( ) , power , dirname , objRank + + ) ;
2015-07-10 21:47:59 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
}
2014-11-10 13:16:32 +00:00
}
2015-06-21 09:16:09 +00:00
2015-06-21 18:59:23 +00:00
2015-07-17 18:36:01 +00:00
line = MakeUnique < CLevelParserLine > ( " CreateObject " ) ;
2015-08-15 21:29:21 +00:00
IOWriteObject ( line . get ( ) , obj , dirname , objRank + + ) ;
2015-06-21 18:59:23 +00:00
levelParser . AddLine ( std : : move ( line ) ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
try
{
levelParser . Save ( ) ;
}
catch ( CLevelParserException & e )
{
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Error ( " Failed to save level state - %s \n " , e . what ( ) ) ;
2014-11-10 13:16:32 +00:00
return false ;
}
2012-06-26 20:23:05 +00:00
// Writes the file of stacks of execution.
2015-12-26 13:19:24 +00:00
FILE * file = CBot : : fOpen ( ( CResourceManager : : GetSaveLocation ( ) + " / " + filecbot ) . c_str ( ) , " wb " ) ;
2015-08-16 10:43:42 +00:00
if ( file = = nullptr ) return false ;
2012-06-26 20:23:05 +00:00
2012-09-15 13:33:08 +00:00
long version = 1 ;
2015-12-26 13:19:24 +00:00
CBot : : fWrite ( & version , sizeof ( long ) , 1 , file ) ; // version of COLOBOT
version = CBot : : CBotProgram : : GetVersion ( ) ;
CBot : : fWrite ( & version , sizeof ( long ) , 1 , file ) ; // version of CBOT
2012-06-26 20:23:05 +00:00
objRank = 0 ;
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_TOTO ) continue ;
2015-07-10 17:03:27 +00:00
if ( IsObjectBeingTransported ( obj ) ) continue ;
2015-08-16 18:24:48 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Destroyable ) & & dynamic_cast < CDestroyableObject * > ( obj ) - > IsDying ( ) ) 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
}
2015-12-26 13:19:24 +00:00
CBot : : CBotClass : : SaveStaticState ( file ) ;
CBot : : fClose ( file ) ;
2012-06-26 20:23:05 +00:00
2015-08-17 18:56:42 +00:00
if ( ! emergencySave )
{
ShowSaveIndicator ( false ) ; // force hide for screenshot
MouseMode oldMouseMode = m_app - > GetMouseMode ( ) ;
m_app - > SetMouseMode ( MOUSE_NONE ) ; // disable the mouse
m_displayText - > HideText ( true ) ; // hide
m_engine - > SetScreenshotMode ( true ) ;
2015-08-07 13:59:05 +00:00
2015-08-17 18:56:42 +00:00
m_engine - > Render ( ) ; // update (but don't show, we're not swapping buffers here!)
m_engine - > WriteScreenShot ( CResourceManager : : GetSaveLocation ( ) + " / " + filescreenshot ) ; //TODO: Use PHYSFS?
m_shotSaving + + ;
2015-08-06 18:15:17 +00:00
2015-08-17 18:56:42 +00:00
m_engine - > SetScreenshotMode ( false ) ;
m_displayText - > HideText ( false ) ;
m_app - > SetMouseMode ( oldMouseMode ) ;
2015-08-07 13:59:05 +00:00
2015-08-17 18:56:42 +00:00
m_app - > ResetTimeAfterLoading ( ) ;
}
2012-06-26 20:23:05 +00:00
return true ;
}
2015-08-03 19:40:30 +00:00
//! Notifies the user that scene write is finished
void CRobotMain : : IOWriteSceneFinished ( )
{
m_displayText - > DisplayError ( INFO_WRITEOK , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
2015-08-06 18:15:17 +00:00
m_shotSaving - - ;
2015-08-03 19:40:30 +00:00
}
2012-09-15 13:33:08 +00:00
//! Resumes the game
2015-08-15 21:29:21 +00:00
CObject * CRobotMain : : IOReadObject ( CLevelParserLine * line , const std : : string & programDir , const std : : string & objCounterText , float objectProgress , int objRank )
2012-06-26 20:23:05 +00:00
{
2015-08-14 16:19:58 +00:00
ObjectCreateParams params = CObject : : ReadCreateParams ( line ) ;
params . power = - 1.0f ;
params . id = line - > GetParam ( " id " ) - > AsInt ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-07 18:48:55 +00:00
std : : string details = objCounterText ;
# if DEV_BUILD
// Object categories may spoil the level a bit, so hide them in release builds
2015-08-14 16:19:58 +00:00
details + = " : " + CLevelParserParam : : FromObjectType ( params . type ) ;
2015-08-07 18:48:55 +00:00
# endif
2015-08-15 21:37:30 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.25f + objectProgress * 0.7f , RT_LOADING_OBJECTS_SAVED , details ) ;
2015-08-07 18:48:55 +00:00
2015-08-14 16:19:58 +00:00
CObject * obj = m_objMan - > CreateObject ( params ) ;
2012-09-15 13:33:08 +00:00
2015-07-11 21:41:41 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Old ) )
2012-06-26 20:23:05 +00:00
{
2015-07-13 21:19:46 +00:00
COldObject * oldObj = dynamic_cast < COldObject * > ( obj ) ;
2015-08-15 21:29:21 +00:00
oldObj - > SetPosition ( line - > GetParam ( " pos " ) - > AsPoint ( ) * g_unit ) ;
oldObj - > SetRotation ( line - > GetParam ( " angle " ) - > AsPoint ( ) * Math : : DEG_TO_RAD ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-14 16:19:58 +00:00
if ( obj - > GetType ( ) = = OBJECT_BASE ) m_base = obj ;
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
2014-11-10 16:15:34 +00:00
int run = line - > GetParam ( " run " ) - > AsInt ( - 1 ) ;
2012-09-15 13:33:08 +00:00
if ( run ! = - 1 )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
CAuto * automat = obj - > GetAuto ( ) ;
if ( automat ! = nullptr )
automat - > Start ( run ) ; // starts the film
2015-04-07 11:27:11 +00:00
}
2015-04-07 11:18:34 +00:00
2015-08-15 19:29:08 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : ProgramStorage ) )
{
2015-08-15 21:29:21 +00:00
CProgramStorageObject * programStorage = dynamic_cast < CProgramStorageObject * > ( obj ) ;
2016-04-08 16:28:35 +00:00
if ( ! line - > GetParam ( " programStorageIndex " ) - > IsDefined ( ) ) // Backwards compatibility
2015-08-15 21:29:21 +00:00
programStorage - > SetProgramStorageIndex ( objRank ) ;
programStorage - > LoadAllProgramsForSavedScene ( line , programDir ) ;
2012-06-26 20:23:05 +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
2015-08-04 08:52:10 +00:00
CObject * CRobotMain : : IOReadScene ( std : : string filename , std : : string filecbot )
2012-06-26 20:23:05 +00:00
{
2015-08-15 21:29:21 +00:00
std : : string dirname = filename . substr ( 0 , filename . find_last_of ( " / " ) ) ;
2015-06-21 18:59:23 +00:00
CLevelParser levelParser ( filename ) ;
2015-08-24 18:08:04 +00:00
levelParser . SetLevelPaths ( m_levelCategory , m_levelChap , m_levelRank ) ;
2015-06-21 18:59:23 +00:00
levelParser . Load ( ) ;
2015-08-07 18:48:55 +00:00
int numObjects = levelParser . CountLines ( " CreateObject " ) + levelParser . CountLines ( " CreatePower " ) + levelParser . CountLines ( " CreateFret " ) ;
2013-05-26 15:47:54 +00:00
2014-11-10 16:15:34 +00:00
m_base = nullptr ;
2015-07-10 20:13:39 +00:00
2015-07-19 14:43:03 +00:00
CObject * cargo = nullptr ;
CObject * power = nullptr ;
2012-09-15 13:33:08 +00:00
CObject * sel = nullptr ;
int objRank = 0 ;
2015-08-07 18:48:55 +00:00
int objCounter = 0 ;
2015-06-21 18:59:23 +00:00
for ( auto & line : levelParser . GetLines ( ) )
2012-06-26 20:23:05 +00:00
{
2017-10-24 09:12:19 +00:00
if ( line - > GetCommand ( ) = = " Mission " )
m_gameTime = line - > GetParam ( " gametime " ) - > AsFloat ( 0.0f ) ;
2014-11-10 16:15:34 +00:00
if ( line - > GetCommand ( ) = = " Map " )
m_map - > ZoomMap ( line - > GetParam ( " zoom " ) - > AsFloat ( ) ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 16:15:34 +00:00
if ( line - > GetCommand ( ) = = " DoneResearch " )
2015-07-13 16:13:28 +00:00
m_researchDone [ 0 ] = line - > GetParam ( " bits " ) - > AsInt ( ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 16:15:34 +00:00
if ( line - > GetCommand ( ) = = " BlitzMode " )
2012-06-26 20:23:05 +00:00
{
2014-11-10 16:15:34 +00:00
float sleep = line - > GetParam ( " sleep " ) - > AsFloat ( ) ;
float delay = line - > GetParam ( " delay " ) - > AsFloat ( ) ;
float magnetic = line - > GetParam ( " magnetic " ) - > AsFloat ( ) * g_unit ;
float progress = line - > GetParam ( " progress " ) - > AsFloat ( ) ;
2012-09-15 13:33:08 +00:00
m_lightning - > SetStatus ( sleep , delay , magnetic , progress ) ;
2012-06-26 20:23:05 +00:00
}
2014-11-10 16:15:34 +00:00
if ( line - > GetCommand ( ) = = " CreateFret " )
2015-08-07 18:48:55 +00:00
{
2015-08-15 21:29:21 +00:00
cargo = IOReadObject ( line . get ( ) , dirname , StrUtils : : ToString < int > ( objCounter + 1 ) + " / " + StrUtils : : ToString < int > ( numObjects ) , static_cast < float > ( objCounter ) / static_cast < float > ( numObjects ) ) ;
2015-08-07 18:48:55 +00:00
objCounter + + ;
}
2012-06-26 20:23:05 +00:00
2014-11-10 16:15:34 +00:00
if ( line - > GetCommand ( ) = = " CreatePower " )
2015-08-07 18:48:55 +00:00
{
2015-08-15 21:29:21 +00:00
power = IOReadObject ( line . get ( ) , dirname , StrUtils : : ToString < int > ( objCounter + 1 ) + " / " + StrUtils : : ToString < int > ( numObjects ) , static_cast < float > ( objCounter ) / static_cast < float > ( numObjects ) ) ;
2015-08-07 18:48:55 +00:00
objCounter + + ;
}
2012-06-26 20:23:05 +00:00
2014-11-10 16:15:34 +00:00
if ( line - > GetCommand ( ) = = " CreateObject " )
2012-06-26 20:23:05 +00:00
{
2015-08-15 21:29:21 +00:00
CObject * obj = IOReadObject ( line . get ( ) , dirname , StrUtils : : ToString < int > ( objCounter + 1 ) + " / " + StrUtils : : ToString < int > ( numObjects ) , static_cast < float > ( objCounter ) / static_cast < float > ( numObjects ) , objRank + + ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 16:15:34 +00:00
if ( line - > GetParam ( " select " ) - > AsBool ( false ) )
2012-09-15 13:33:08 +00:00
sel = obj ;
2012-06-26 20:23:05 +00:00
2015-06-29 21:05:31 +00:00
if ( cargo ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-07-10 20:13:39 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Carrier ) ) ; // TODO: exception?
2015-07-12 11:46:25 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Old ) ) ;
2015-07-10 20:13:39 +00:00
dynamic_cast < CCarrierObject * > ( obj ) - > SetCargo ( cargo ) ;
2015-08-14 21:11:24 +00:00
auto task = MakeUnique < CTaskManip > ( dynamic_cast < COldObject * > ( obj ) ) ;
2012-06-26 20:23:05 +00:00
task - > Start ( TMO_AUTO , TMA_GRAB ) ; // holds the object!
}
2012-09-15 13:33:08 +00:00
if ( power ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-07-10 21:47:59 +00:00
assert ( obj - > Implements ( ObjectInterfaceType : : Powered ) ) ;
dynamic_cast < CPoweredObject * > ( obj ) - > SetPower ( power ) ;
assert ( power - > Implements ( ObjectInterfaceType : : Transportable ) ) ;
2015-07-10 17:03:27 +00:00
dynamic_cast < CTransportableObject * > ( power ) - > SetTransporter ( obj ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-07 18:48:55 +00:00
cargo = nullptr ;
2015-07-19 14:43:03 +00:00
power = nullptr ;
2015-08-07 18:48:55 +00:00
objCounter + + ;
2012-06-26 20:23:05 +00:00
}
}
2015-06-21 18:59:23 +00:00
2015-08-07 18:48:55 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 0.95f , RT_LOADING_CBOT_SAVE ) ;
2012-06-26 20:23:05 +00:00
// Reads the file of stacks of execution.
2015-12-26 13:19:24 +00:00
FILE * file = CBot : : fOpen ( ( CResourceManager : : GetSaveLocation ( ) + " / " + filecbot ) . c_str ( ) , " rb " ) ;
2015-08-16 10:43:42 +00:00
if ( file ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
long version ;
2015-12-26 13:19:24 +00:00
CBot : : 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
{
2015-12-26 13:19:24 +00:00
CBot : : fRead ( & version , sizeof ( long ) , 1 , file ) ; // version of CBOT
if ( version = = CBot : : CBotProgram : : GetVersion ( ) )
2012-06-26 20:23:05 +00:00
{
objRank = 0 ;
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
2012-06-26 20:23:05 +00:00
{
2012-09-15 13:33:08 +00:00
if ( obj - > GetType ( ) = = OBJECT_TOTO ) continue ;
2015-07-10 17:03:27 +00:00
if ( IsObjectBeingTransported ( obj ) ) continue ;
2015-08-16 18:24:48 +00:00
if ( obj - > Implements ( ObjectInterfaceType : : Destroyable ) & & dynamic_cast < CDestroyableObject * > ( obj ) - > IsDying ( ) ) 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
}
}
}
2015-12-26 13:19:24 +00:00
CBot : : CBotClass : : RestoreStaticState ( file ) ;
CBot : : fClose ( file ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-07 18:48:55 +00:00
m_ui - > GetLoadingScreen ( ) - > SetProgress ( 1.0f , RT_LOADING_FINISHED ) ;
2012-09-15 13:33:08 +00:00
return sel ;
2012-06-26 20:23:05 +00:00
}
2015-07-18 21:14:20 +00:00
//! Changes current player
void CRobotMain : : SelectPlayer ( std : : string playerName )
2012-06-26 20:23:05 +00:00
{
2015-07-18 21:14:20 +00:00
assert ( ! playerName . empty ( ) ) ;
2015-06-21 18:59:23 +00:00
2015-07-19 13:34:49 +00:00
m_playerProfile = MakeUnique < CPlayerProfile > ( playerName ) ;
2015-07-18 21:14:20 +00:00
SetGlobalGamerName ( playerName ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-19 13:34:49 +00:00
CPlayerProfile * CRobotMain : : GetPlayerProfile ( )
2012-06-26 20:23:05 +00:00
{
2015-07-19 13:34:49 +00:00
return m_playerProfile . get ( ) ;
2012-06-26 20:23:05 +00:00
}
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 ( )
{
2015-07-13 19:51:18 +00:00
// schedule reset during next frame
2012-09-15 13:33:08 +00:00
m_resetCreate = true ;
2012-06-26 20:23:05 +00:00
}
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
2016-05-28 10:50:32 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_NULL ) ;
2012-06-26 20:23:05 +00:00
2015-06-21 18:59:23 +00:00
try
{
2015-08-06 10:59:09 +00:00
CreateScene ( m_ui - > GetSceneSoluce ( ) , false , true ) ;
2012-06-26 20:23:05 +00:00
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
2015-07-13 20:40:55 +00:00
if ( obj - > GetAnimateOnReset ( ) )
{
m_engine - > GetPyroManager ( ) - > Create ( Gfx : : PT_RESET , obj ) ;
}
2014-09-24 20:54:26 +00:00
}
}
2015-07-14 16:46:22 +00:00
catch ( const std : : runtime_error & e )
2014-09-24 20:54:26 +00:00
{
2016-03-30 11:40:26 +00:00
LevelLoadingError ( " An error occurred while trying to reset scene " , e ) ;
2012-06-26 20:23:05 +00:00
}
}
2013-04-13 09:44:16 +00:00
//! Updates the audiotracks
void CRobotMain : : UpdateAudio ( bool frame )
{
2015-07-07 14:17:19 +00:00
for ( std : : unique_ptr < CAudioChangeCondition > & audioChange : m_audioChange )
2013-04-13 09:44:16 +00:00
{
2015-07-07 14:17:19 +00:00
if ( audioChange - > changed ) continue ;
2013-04-13 09:44:16 +00:00
2015-07-07 14:17:19 +00:00
if ( audioChange - > Check ( ) )
2013-04-13 09:44:16 +00:00
{
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Info ( " Changing music to \" %s \" \n " , audioChange - > music . c_str ( ) ) ;
2015-07-07 14:17:19 +00:00
m_sound - > PlayMusic ( audioChange - > music , audioChange - > repeat ) ;
audioChange - > changed = true ;
2013-04-13 09:44:16 +00:00
}
}
}
2016-04-08 18:56:09 +00:00
//! Set mission result from LevelController script
void CRobotMain : : SetMissionResultFromScript ( Error result , float delay )
2013-04-30 19:43:59 +00:00
{
2016-04-08 18:56:09 +00:00
m_endTakeWinDelay = delay ;
m_endTakeLostDelay = delay ;
m_missionResult = result ;
m_missionResultFromScript = true ;
2013-04-30 19:43:59 +00:00
}
2016-04-08 18:56:09 +00:00
Error CRobotMain : : ProcessEndMissionTakeForGroup ( std : : vector < CSceneEndCondition * > & endTakes )
2015-07-07 15:48:49 +00:00
{
Error finalResult = ERR_OK ;
2015-07-07 16:04:17 +00:00
bool hasWinningConditions = false ;
2015-07-07 15:48:49 +00:00
for ( CSceneEndCondition * endTake : endTakes )
{
Error result = endTake - > GetMissionResult ( ) ;
2015-07-07 16:04:17 +00:00
if ( endTake - > lost < 0 )
hasWinningConditions = true ;
2015-07-10 08:45:30 +00:00
if ( result = = ERR_OK & & endTake - > immediat )
2015-07-07 16:04:17 +00:00
{
2015-07-10 08:45:30 +00:00
hasWinningConditions = true ;
finalResult = result ;
break ;
}
if ( result ! = ERR_OK )
{
finalResult = result ;
2015-07-19 17:19:47 +00:00
break ;
2015-07-07 15:48:49 +00:00
}
}
2015-07-19 17:19:47 +00:00
if ( finalResult = = ERR_OK & & ! hasWinningConditions ) finalResult = ERR_MISSION_NOTERM ; // Never end mission without ending conditions
2015-07-07 15:48:49 +00:00
return finalResult ;
}
2016-04-08 19:16:03 +00:00
//! Process EndMissionTake commands, result is stored in m_missionResult
2016-04-08 19:18:45 +00:00
//! If return value is different than ERR_MISSION_NOTERM, assume the mission is finished and pass on the result
Error CRobotMain : : ProcessEndMissionTake ( )
2012-06-26 20:23:05 +00:00
{
2016-04-08 18:56:09 +00:00
// Sort end conditions by teams
2017-05-19 19:11:43 +00:00
std : : map < int , std : : vector < CSceneEndCondition * > > teamsEndTake ;
2016-04-08 18:56:09 +00:00
for ( std : : unique_ptr < CSceneEndCondition > & endTake : m_endTake )
2017-05-19 19:11:43 +00:00
teamsEndTake [ endTake - > winTeam ] . push_back ( endTake . get ( ) ) ;
2016-04-08 18:56:09 +00:00
2017-05-19 19:11:43 +00:00
// This is just a smart way to check if we have any map values other than 0 defined
bool usesTeamConditions = teamsEndTake . size ( ) > teamsEndTake . count ( 0 ) ;
2015-07-07 15:48:49 +00:00
2016-04-08 18:56:09 +00:00
if ( ! usesTeamConditions )
{
2017-05-19 19:11:43 +00:00
m_missionResult = ProcessEndMissionTakeForGroup ( teamsEndTake [ 0 ] ) ;
2016-04-08 18:56:09 +00:00
}
else
{
// Special handling for teams
m_missionResult = ERR_MISSION_NOTERM ;
2015-07-07 15:48:49 +00:00
2017-05-19 19:11:43 +00:00
if ( GetAllActiveTeams ( ) . empty ( ) )
2015-07-07 16:04:17 +00:00
{
2017-05-17 16:22:27 +00:00
GetLogger ( ) - > Info ( " All teams died, mission ended \n " ) ;
if ( m_scoreboard )
{
2017-05-17 17:00:40 +00:00
std : : string title , text , details_line ;
GetResource ( RES_TEXT , RT_SCOREBOARD_RESULTS , title ) ;
GetResource ( RES_TEXT , RT_SCOREBOARD_RESULTS_TEXT , text ) ;
GetResource ( RES_TEXT , RT_SCOREBOARD_RESULTS_LINE , details_line ) ;
2017-05-17 16:22:27 +00:00
std : : string details = " " ;
2017-05-19 19:11:43 +00:00
for ( int team : GetAllTeams ( ) )
2017-05-17 16:22:27 +00:00
{
2017-05-17 17:00:40 +00:00
if ( ! details . empty ( ) )
details + = " , " ;
details + = StrUtils : : Format ( details_line . c_str ( ) , GetTeamName ( team ) . c_str ( ) , m_scoreboard - > GetScore ( team ) ) ;
2017-05-17 16:22:27 +00:00
}
m_ui - > GetDialog ( ) - > StartInformation (
2017-05-17 17:00:40 +00:00
title ,
text ,
2017-05-17 16:22:27 +00:00
details ,
false , true ,
[ & ] ( ) {
ChangePhase ( PHASE_WIN ) ;
}
) ;
m_endTakeWinDelay = 0.0f ;
m_missionResult = ERR_OK ;
}
else
{
m_missionResult = INFO_LOST ;
}
2015-07-07 16:04:17 +00:00
}
else
{
2017-05-19 19:11:43 +00:00
for ( auto it : teamsEndTake )
2015-08-02 09:40:47 +00:00
{
2016-04-08 18:56:09 +00:00
int team = it . first ;
if ( team = = 0 ) continue ;
2017-05-17 16:22:27 +00:00
if ( m_teamFinished [ team ] ) continue ;
2016-04-08 18:56:09 +00:00
Error result = ProcessEndMissionTakeForGroup ( it . second ) ;
if ( result = = INFO_LOST | | result = = INFO_LOSTq )
2015-07-07 16:04:17 +00:00
{
2016-04-08 18:56:09 +00:00
GetLogger ( ) - > Info ( " Team %d lost \n " , team ) ;
2017-05-17 17:00:40 +00:00
std : : string text ;
GetResource ( RES_ERR , INFO_TEAM_DEAD , text ) ;
text = StrUtils : : Format ( text . c_str ( ) , GetTeamName ( team ) . c_str ( ) ) ;
m_displayText - > DisplayText ( text . c_str ( ) , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 15.0f , 60.0f , 10.0f , Ui : : TT_ERROR ) ;
2015-07-07 15:48:49 +00:00
2016-04-08 18:56:09 +00:00
m_displayText - > SetEnable ( false ) ; // To prevent "bot destroyed" messages
m_objMan - > DestroyTeam ( team ) ;
m_displayText - > SetEnable ( true ) ;
2017-05-17 16:22:27 +00:00
m_teamFinished [ team ] = true ;
2016-04-08 18:56:09 +00:00
}
else if ( result = = ERR_OK )
{
2017-05-17 16:22:27 +00:00
/*if (m_winDelay == 0.0f)
2015-07-07 16:04:17 +00:00
{
2016-04-08 18:56:09 +00:00
GetLogger ( ) - > Info ( " Team %d won \n " , team ) ;
2015-07-10 20:11:22 +00:00
2016-04-08 18:56:09 +00:00
m_displayText - > DisplayText ( ( " <<< Team " + boost : : lexical_cast < std : : string > ( team ) + " won the game >>> " ) . c_str ( ) , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
if ( m_missionTimerEnabled & & m_missionTimerStarted )
2015-07-07 15:48:49 +00:00
{
2016-04-08 18:56:09 +00:00
GetLogger ( ) - > Info ( " Mission time: %s \n " , TimeFormat ( m_missionTimer ) . c_str ( ) ) ;
m_displayText - > DisplayText ( ( " Time: " + TimeFormat ( m_missionTimer ) ) . c_str ( ) , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
2015-07-07 15:48:49 +00:00
}
2016-04-08 18:56:09 +00:00
m_missionTimerEnabled = m_missionTimerStarted = false ;
m_winDelay = m_endTakeWinDelay ; // wins in two seconds
m_lostDelay = 0.0f ;
m_displayText - > SetEnable ( false ) ;
2015-07-07 15:48:49 +00:00
}
2016-04-08 18:56:09 +00:00
m_missionResult = ERR_OK ;
2017-05-17 16:22:27 +00:00
return ERR_OK ; */
GetLogger ( ) - > Info ( " Team %d finished \n " , team ) ;
2017-05-17 17:00:40 +00:00
std : : string text ;
GetResource ( RES_ERR , INFO_TEAM_FINISH , text ) ;
text = StrUtils : : Format ( text . c_str ( ) , GetTeamName ( team ) . c_str ( ) ) ;
m_displayText - > DisplayText ( text . c_str ( ) , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
2017-05-17 16:22:27 +00:00
if ( m_scoreboard )
m_scoreboard - > ProcessEndTake ( team ) ;
m_objMan - > DestroyTeam ( team , DestructionType : : Win ) ;
m_teamFinished [ team ] = true ;
2015-07-07 15:48:49 +00:00
}
2014-10-29 16:53:46 +00:00
}
2013-04-30 19:43:59 +00:00
}
2016-04-08 18:56:09 +00:00
}
2012-06-26 20:23:05 +00:00
2016-04-08 18:56:09 +00:00
if ( m_missionResult ! = INFO_LOST & & m_missionResult ! = INFO_LOSTq )
{
if ( m_endTakeResearch ! = 0 )
2012-06-26 20:23:05 +00:00
{
2016-04-08 18:56:09 +00:00
if ( m_endTakeResearch ! = ( m_endTakeResearch & m_researchDone [ 0 ] ) )
2015-03-28 11:19:40 +00:00
{
2016-04-08 18:56:09 +00:00
m_missionResult = ERR_MISSION_NOTERM ;
2013-04-20 10:08:48 +00:00
}
2012-06-26 20:23:05 +00:00
}
}
2016-04-08 19:18:45 +00:00
return ERR_MISSION_NOTERM ;
2016-04-08 18:56:09 +00:00
}
//! Checks if the mission is over
Error CRobotMain : : CheckEndMission ( bool frame )
{
// Process EndMissionTake, unless we are using LevelController script for processing ending conditions
2016-04-08 19:18:45 +00:00
if ( ! m_missionResultFromScript )
{
Error result = ProcessEndMissionTake ( ) ;
if ( result ! = ERR_MISSION_NOTERM ) return result ;
}
2015-07-07 14:17:19 +00:00
// Take action depending on m_missionResult
2016-04-08 18:56:09 +00:00
if ( m_missionResult = = INFO_LOSTq )
2012-06-26 20:23:05 +00:00
{
2015-07-07 14:17:19 +00:00
if ( m_lostDelay = = 0.0f )
2012-06-26 20:23:05 +00:00
{
2015-07-07 14:17:19 +00:00
m_lostDelay = 0.1f ; // lost immediately
m_winDelay = 0.0f ;
2012-06-26 20:23:05 +00:00
}
2014-10-29 16:53:46 +00:00
m_missionTimerEnabled = m_missionTimerStarted = false ;
2012-06-26 20:23:05 +00:00
m_displayText - > SetEnable ( false ) ;
2015-07-07 14:17:19 +00:00
return INFO_LOSTq ;
2012-06-26 20:23:05 +00:00
}
2016-04-08 18:56:09 +00:00
if ( m_missionResult = = INFO_LOST )
2012-06-26 20:23:05 +00:00
{
2015-07-07 14:17:19 +00:00
if ( m_lostDelay = = 0.0f )
2015-06-21 18:59:23 +00:00
{
2015-07-07 14:17:19 +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 ;
2014-10-29 16:53:46 +00:00
}
m_missionTimerEnabled = m_missionTimerStarted = false ;
2015-07-07 14:17:19 +00:00
m_displayText - > SetEnable ( false ) ;
return INFO_LOST ;
2012-06-26 20:23:05 +00:00
}
2015-07-07 14:17:19 +00:00
if ( m_missionResult = = ERR_OK )
2012-06-26 20:23:05 +00:00
{
2015-08-25 15:17:11 +00:00
if ( m_endTakeWinDelay = = - 1.0f & & m_winDelay = = 0.0f )
2015-07-07 14:17:19 +00:00
{
m_winDelay = 1.0f ; // wins in one second
m_lostDelay = 0.0f ;
m_missionTimerEnabled = m_missionTimerStarted = false ;
m_displayText - > SetEnable ( false ) ;
return ERR_OK ; // mission ended
}
2012-06-26 20:23:05 +00:00
2015-08-10 21:20:36 +00:00
if ( frame )
{
2016-04-08 18:56:09 +00:00
if ( m_base ! = nullptr & & ! m_endTakeImmediat )
2015-08-10 21:20:36 +00:00
{
assert ( m_base - > Implements ( ObjectInterfaceType : : Controllable ) ) ;
if ( dynamic_cast < CControllableObject * > ( m_base ) - > GetSelectable ( ) )
return ERR_MISSION_NOTERM ;
}
}
2015-07-07 14:17:19 +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 ) ) ;
2015-07-07 14:17:19 +00:00
if ( m_missionTimerEnabled & & m_missionTimerStarted )
{
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Info ( " Mission time: %s \n " , TimeFormat ( m_missionTimer ) . c_str ( ) ) ;
2015-07-07 14:17:19 +00:00
m_displayText - > DisplayText ( ( " Time: " + TimeFormat ( m_missionTimer ) ) . c_str ( ) , Math : : Vector ( 0.0f , 0.0f , 0.0f ) ) ;
}
m_missionTimerEnabled = m_missionTimerStarted = false ;
m_winDelay = m_endTakeWinDelay ; // wins in two seconds
2012-06-26 20:23:05 +00:00
m_lostDelay = 0.0f ;
}
2015-07-07 14:17:19 +00:00
m_displayText - > SetEnable ( false ) ;
return ERR_OK ; // mission ended
}
else
{
m_displayText - > SetEnable ( true ) ;
return ERR_MISSION_NOTERM ;
2012-06-26 20:23:05 +00:00
}
}
2016-04-08 20:15:54 +00:00
//! Returns the list instructions required in CBot program in level
const std : : map < std : : string , MinMax > & CRobotMain : : GetObligatoryTokenList ( )
2012-06-26 20:23:05 +00:00
{
2016-04-08 20:15:54 +00:00
return m_obligatoryTokens ;
2012-06-26 20:23:05 +00:00
}
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
{
2016-12-27 22:38:57 +00:00
return m_cheatTrainerPilot ;
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
}
2015-10-01 17:37:31 +00:00
const std : : string & CRobotMain : : GetScriptName ( )
2012-06-26 20:23:05 +00:00
{
return m_scriptName ;
}
2015-10-01 17:37:31 +00:00
const std : : string & CRobotMain : : GetScriptFile ( )
2012-06-26 20:23:05 +00:00
{
return m_scriptFile ;
}
2012-09-15 13:33:08 +00:00
bool CRobotMain : : GetShowSoluce ( )
2012-06-26 20:23:05 +00:00
{
2016-12-27 22:38:57 +00:00
return m_cheatShowSoluce ;
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 ;
2015-08-06 10:59:09 +00:00
return m_ui - > 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
{
2016-12-27 22:38:57 +00:00
return m_cheatAllMission ;
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 ;
2015-06-21 14:22:09 +00:00
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
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
}
2015-06-26 20:07:55 +00:00
MissionType CRobotMain : : GetMissionType ( )
2013-03-24 18:05:20 +00:00
{
2015-06-26 20:07:55 +00:00
return m_missionType ;
2013-03-24 18:05:20 +00:00
}
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
{
2015-07-19 13:34:49 +00:00
return m_playerProfile - > GetApperance ( ) . face ;
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
{
2015-07-19 13:34:49 +00:00
return m_playerProfile - > GetApperance ( ) . glasses ;
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
{
2015-08-06 10:59:09 +00:00
return m_ui - > 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
{
2015-08-06 10:59:09 +00:00
return m_ui - > GetPersoAngle ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-04 07:55:39 +00:00
void CRobotMain : : SetLevel ( LevelCategory cat , int chap , int rank )
{
2016-05-27 21:37:36 +00:00
GetLogger ( ) - > Debug ( " Change level to %s %d %d \n " , GetLevelCategoryDir ( cat ) . c_str ( ) , chap , rank ) ;
2015-08-04 08:52:10 +00:00
m_levelCategory = cat ;
m_levelChap = chap ;
m_levelRank = rank ;
2016-05-27 21:37:36 +00:00
m_levelFile = CLevelParser : : BuildScenePath ( m_levelCategory , m_levelChap , m_levelRank ) ;
2015-08-04 07:55:39 +00:00
}
2015-07-18 16:52:37 +00:00
LevelCategory CRobotMain : : GetLevelCategory ( )
2014-07-11 14:40:07 +00:00
{
2015-08-04 08:52:10 +00:00
return m_levelCategory ;
2014-07-11 14:40:07 +00:00
}
2015-07-18 17:43:22 +00:00
int CRobotMain : : GetLevelChap ( )
{
2015-08-04 08:52:10 +00:00
return m_levelChap ;
2015-07-18 17:43:22 +00:00
}
2015-07-18 16:52:37 +00:00
int CRobotMain : : GetLevelRank ( )
2014-07-11 14:40:07 +00:00
{
2015-08-04 08:52:10 +00:00
return m_levelRank ;
}
//! Returns folder name of the scene that user selected to play.
std : : string CRobotMain : : GetCustomLevelDir ( )
{
assert ( m_levelCategory = = LevelCategory : : CustomLevels ) ;
2015-08-06 10:59:09 +00:00
return m_ui - > GetCustomLevelName ( m_levelChap ) ;
2015-08-04 08:52:10 +00:00
}
void CRobotMain : : SetReadScene ( std : : string path )
{
m_sceneReadPath = path ;
2014-07-11 14:40:07 +00:00
}
2015-07-18 21:14:20 +00:00
void CRobotMain : : UpdateChapterPassed ( )
{
2015-08-06 10:59:09 +00:00
return m_ui - > UpdateChapterPassed ( ) ;
2015-07-18 21:14:20 +00:00
}
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
}
}
}
bool CRobotMain : : CreateShortcuts ( )
{
2012-09-15 13:33:08 +00:00
if ( m_phase ! = PHASE_SIMUL ) return false ;
2015-08-07 18:48:55 +00:00
if ( m_ui - > GetLoadingScreen ( ) - > IsVisible ( ) ) return false ;
2012-09-15 13:33:08 +00:00
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
{
2015-08-07 18:48:55 +00:00
return 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 ;
2012-06-26 20:23:05 +00:00
CreateShortcuts ( ) ;
2015-08-07 18:48:55 +00:00
m_map - > ShowMap ( ! m_movieLock & & m_mapShow & & ! m_ui - > GetLoadingScreen ( ) - > IsVisible ( ) ) ;
2012-09-15 13:33:08 +00:00
if ( m_movieLock ) HiliteClear ( ) ;
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 ) ;
2014-12-11 18:01:57 +00:00
m_input - > 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
//! 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
//! Starts music with a mission
2012-06-26 20:23:05 +00:00
void CRobotMain : : StartMusic ( )
{
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > 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
}
2015-08-31 19:47:55 +00:00
void CRobotMain : : UpdatePause ( PauseType pause )
2014-02-21 13:19:58 +00:00
{
2015-10-01 16:55:41 +00:00
m_engine - > SetPause ( pause & PAUSE_ENGINE ) ;
2016-05-28 10:50:32 +00:00
m_camera - > SetFreeze ( pause & PAUSE_CAMERA ) ;
2015-10-01 16:55:41 +00:00
m_sound - > MuteAll ( pause & PAUSE_MUTE_SOUND ) ;
2015-08-31 19:47:55 +00:00
CreateShortcuts ( ) ;
if ( pause ! = PAUSE_NONE ) HiliteClear ( ) ;
2015-10-01 16:55:41 +00:00
}
2015-08-31 19:47:55 +00:00
2015-10-01 16:55:41 +00:00
void CRobotMain : : UpdatePauseMusic ( PauseMusic music )
{
switch ( music )
2015-06-21 18:59:23 +00:00
{
2015-10-01 16:55:41 +00:00
case PAUSE_MUSIC_NONE :
2015-08-31 19:47:55 +00:00
m_sound - > StopPauseMusic ( ) ;
break ;
2015-10-01 16:55:41 +00:00
case PAUSE_MUSIC_EDITOR :
2015-06-21 18:59:23 +00:00
if ( m_editorTrack ! = " " )
2014-03-02 13:39:29 +00:00
m_sound - > PlayPauseMusic ( m_editorTrack , m_editorRepeat ) ;
2014-02-21 13:19:58 +00:00
break ;
2015-06-21 18:59:23 +00:00
2015-10-01 16:55:41 +00:00
case PAUSE_MUSIC_SATCOM :
2015-06-21 18:59:23 +00:00
if ( m_satcomTrack ! = " " )
2014-03-02 13:39:29 +00:00
m_sound - > PlayPauseMusic ( m_satcomTrack , m_satcomRepeat ) ;
2014-02-21 13:19:58 +00:00
break ;
}
}
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
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 ) ;
}
2014-07-11 14:40:07 +00:00
2015-08-04 07:55:39 +00:00
void CRobotMain : : UpdateCustomLevelList ( )
{
2015-08-06 10:59:09 +00:00
m_ui - > UpdateCustomLevelList ( ) ;
2015-08-04 07:55:39 +00:00
}
2015-07-19 21:07:36 +00:00
std : : string CRobotMain : : GetCustomLevelName ( int id )
2014-07-11 14:40:07 +00:00
{
2015-08-06 10:59:09 +00:00
return m_ui - > GetCustomLevelName ( id ) ;
2014-07-11 14:40:07 +00:00
}
2014-10-29 16:53:46 +00:00
2015-08-04 07:55:39 +00:00
const std : : vector < std : : string > & CRobotMain : : GetCustomLevelList ( )
{
2015-08-06 10:59:09 +00:00
return m_ui - > GetCustomLevelList ( ) ;
2015-08-04 07:55:39 +00:00
}
2015-09-01 14:15:59 +00:00
bool CRobotMain : : IsLoading ( )
{
return m_ui - > GetLoadingScreen ( ) - > IsVisible ( ) ;
}
2014-10-29 16:53:46 +00:00
void CRobotMain : : StartMissionTimer ( )
{
2015-06-21 18:59:23 +00:00
if ( m_missionTimerEnabled & & ! m_missionTimerStarted )
{
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Info ( " Starting mission timer... \n " ) ;
2014-10-29 16:53:46 +00:00
m_missionTimerStarted = true ;
}
}
2014-11-11 13:50:44 +00:00
void CRobotMain : : SetAutosave ( bool enable )
{
2015-08-06 14:11:49 +00:00
if ( m_autosave = = enable ) return ;
2014-11-11 13:50:44 +00:00
m_autosave = enable ;
2015-07-09 21:15:30 +00:00
m_autosaveLast = m_gameTimeAbsolute ;
2014-11-11 13:50:44 +00:00
}
bool CRobotMain : : GetAutosave ( )
{
return m_autosave ;
}
void CRobotMain : : SetAutosaveInterval ( int interval )
{
2015-08-06 14:11:49 +00:00
if ( m_autosaveInterval = = interval ) return ;
2014-11-11 13:50:44 +00:00
m_autosaveInterval = interval ;
2015-07-09 21:15:30 +00:00
m_autosaveLast = m_gameTimeAbsolute ;
2014-11-11 13:50:44 +00:00
}
int CRobotMain : : GetAutosaveInterval ( )
{
return m_autosaveInterval ;
}
void CRobotMain : : SetAutosaveSlots ( int slots )
{
2015-08-06 14:11:49 +00:00
if ( m_autosaveSlots = = slots ) return ;
2014-11-11 13:50:44 +00:00
m_autosaveSlots = slots ;
}
int CRobotMain : : GetAutosaveSlots ( )
{
return m_autosaveSlots ;
}
2016-05-15 17:42:27 +00:00
// Remove oldest saves with autosave prefix
void CRobotMain : : AutosaveRotate ( )
2014-11-11 13:50:44 +00:00
{
2016-01-28 19:36:55 +00:00
if ( m_playerProfile = = nullptr )
2016-05-15 17:42:27 +00:00
return ;
2016-01-28 19:36:55 +00:00
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Debug ( " Rotate autosaves... \n " ) ;
2015-07-19 13:34:49 +00:00
auto saveDirs = CResourceManager : : ListDirectories ( m_playerProfile - > GetSaveDir ( ) ) ;
2016-05-15 17:42:27 +00:00
const std : : string autosavePrefix = " autosave " ;
std : : vector < std : : string > autosaves ;
2016-07-09 18:39:18 +00:00
std : : copy_if ( saveDirs . begin ( ) , saveDirs . end ( ) , std : : back_inserter ( autosaves ) , [ & ] ( const std : : string & save )
{
2016-05-15 17:42:27 +00:00
return save . substr ( 0 , autosavePrefix . length ( ) ) = = autosavePrefix ;
} ) ;
2015-06-21 18:59:23 +00:00
2016-05-15 17:42:27 +00:00
std : : sort ( autosaves . begin ( ) , autosaves . end ( ) , std : : less < std : : string > ( ) ) ;
for ( int i = 0 ; i < static_cast < int > ( autosaves . size ( ) ) - m_autosaveSlots + 1 ; i + + )
2015-06-21 18:59:23 +00:00
{
2016-05-15 17:42:27 +00:00
CResourceManager : : RemoveDirectory ( m_playerProfile - > GetSaveDir ( ) + " / " + autosaves [ i ] ) ;
2014-11-11 13:50:44 +00:00
}
}
void CRobotMain : : Autosave ( )
{
2016-05-15 17:42:27 +00:00
AutosaveRotate ( ) ;
2015-07-16 19:30:55 +00:00
GetLogger ( ) - > Info ( " Autosave! \n " ) ;
2015-06-21 18:59:23 +00:00
2014-11-11 13:50:44 +00:00
char timestr [ 100 ] ;
2016-05-15 17:42:27 +00:00
char infostr [ 100 ] ;
2016-04-09 16:23:57 +00:00
time_t now = time ( nullptr ) ;
2016-05-15 17:42:27 +00:00
strftime ( timestr , 99 , " %y%m%d%H%M%S " , localtime ( & now ) ) ;
strftime ( infostr , 99 , " %y.%m.%d %H:%M " , localtime ( & now ) ) ;
std : : string info = std : : string ( " [AUTOSAVE] " ) + infostr ;
std : : string dir = m_playerProfile - > GetSaveFile ( std : : string ( " autosave " ) + timestr ) ;
2015-06-21 18:59:23 +00:00
2015-07-19 13:34:49 +00:00
m_playerProfile - > SaveScene ( dir , info ) ;
2014-12-22 09:35:05 +00:00
}
2017-06-11 15:50:21 +00:00
void CRobotMain : : QuickSave ( )
{
GetLogger ( ) - > Info ( " Quicksave! \n " ) ;
char infostr [ 100 ] ;
time_t now = time ( nullptr ) ;
strftime ( infostr , 99 , " %y.%m.%d %H:%M " , localtime ( & now ) ) ;
std : : string info = std : : string ( " [QUICKSAVE] " ) + infostr ;
std : : string dir = m_playerProfile - > GetSaveFile ( std : : string ( " quicksave " ) ) ;
m_playerProfile - > SaveScene ( dir , info ) ;
}
void CRobotMain : : QuickLoad ( )
{
std : : string dir = m_playerProfile - > GetSaveFile ( std : : string ( " quicksave " ) ) ;
if ( ! CResourceManager : : Exists ( dir ) )
{
2017-06-11 21:29:50 +00:00
m_displayText - > DisplayError ( ERR_NO_QUICK_SLOT , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , 15.0f , 60.0f , 1000.0f ) ;
2017-06-11 15:50:21 +00:00
GetLogger ( ) - > Debug ( " Quicksave slot not found \n " ) ;
return ;
}
m_playerProfile - > LoadScene ( dir ) ;
}
2014-12-22 09:35:05 +00:00
void CRobotMain : : SetExitAfterMission ( bool exit )
{
m_exitAfterMission = exit ;
2015-06-21 18:59:23 +00:00
}
2015-06-26 20:07:55 +00:00
bool CRobotMain : : CanPlayerInteract ( )
{
2015-07-22 16:01:24 +00:00
if ( GetMissionType ( ) = = MISSION_CODE_BATTLE )
{
2015-06-26 20:07:55 +00:00
return ! m_codeBattleStarted ;
}
return true ;
2015-07-07 19:25:13 +00:00
}
const std : : string NO_TEAM_NAME = " Team " ;
const std : : string & CRobotMain : : GetTeamName ( int id )
{
if ( m_teamNames . count ( id ) = = 0 ) return NO_TEAM_NAME ;
return m_teamNames [ id ] ;
2015-07-13 15:38:19 +00:00
}
2015-07-22 10:45:50 +00:00
bool CRobotMain : : IsTeamColorDefined ( int id )
{
if ( id = = 0 ) return false ; // Always use default for team 0
return m_colorNewBot . find ( id ) ! = m_colorNewBot . end ( ) ;
}
2015-07-13 15:38:19 +00:00
int CRobotMain : : GetEnableBuild ( )
{
return m_build ;
}
void CRobotMain : : SetEnableBuild ( int enableBuild )
{
m_build = enableBuild ;
}
int CRobotMain : : GetEnableResearch ( )
{
return m_researchEnable ;
}
void CRobotMain : : SetEnableResearch ( int enableResearch )
{
m_researchEnable = enableResearch ;
}
2015-07-13 16:13:28 +00:00
int CRobotMain : : GetDoneResearch ( int team )
2015-07-13 15:38:19 +00:00
{
2015-07-13 16:13:28 +00:00
return m_researchDone [ team ] ;
2015-07-13 15:38:19 +00:00
}
2015-07-13 16:13:28 +00:00
void CRobotMain : : SetDoneResearch ( int doneResearch , int team )
2015-07-13 15:38:19 +00:00
{
2015-07-13 16:13:28 +00:00
m_researchDone [ team ] = doneResearch ;
2015-07-13 15:38:19 +00:00
}
bool CRobotMain : : IsBuildingEnabled ( BuildType type )
{
return ( m_build & type ) ! = 0 ;
}
bool CRobotMain : : IsBuildingEnabled ( ObjectType type )
{
if ( type = = OBJECT_DERRICK ) return IsBuildingEnabled ( BUILD_DERRICK ) ;
if ( type = = OBJECT_FACTORY ) return IsBuildingEnabled ( BUILD_FACTORY ) ;
if ( type = = OBJECT_STATION ) return IsBuildingEnabled ( BUILD_STATION ) ;
if ( type = = OBJECT_CONVERT ) return IsBuildingEnabled ( BUILD_CONVERT ) ;
if ( type = = OBJECT_REPAIR ) return IsBuildingEnabled ( BUILD_REPAIR ) ;
if ( type = = OBJECT_TOWER ) return IsBuildingEnabled ( BUILD_TOWER ) ;
if ( type = = OBJECT_RESEARCH ) return IsBuildingEnabled ( BUILD_RESEARCH ) ;
if ( type = = OBJECT_RADAR ) return IsBuildingEnabled ( BUILD_RADAR ) ;
if ( type = = OBJECT_ENERGY ) return IsBuildingEnabled ( BUILD_ENERGY ) ;
if ( type = = OBJECT_LABO ) return IsBuildingEnabled ( BUILD_LABO ) ;
if ( type = = OBJECT_NUCLEAR ) return IsBuildingEnabled ( BUILD_NUCLEAR ) ;
if ( type = = OBJECT_INFO ) return IsBuildingEnabled ( BUILD_INFO ) ;
if ( type = = OBJECT_PARA ) return IsBuildingEnabled ( BUILD_PARA ) ;
if ( type = = OBJECT_DESTROYER ) return IsBuildingEnabled ( BUILD_DESTROYER ) ;
2016-12-05 13:16:11 +00:00
return false ;
2015-07-13 15:38:19 +00:00
}
bool CRobotMain : : IsResearchEnabled ( ResearchType type )
{
return ( m_researchEnable & type ) ! = 0 ;
}
2015-07-13 16:13:28 +00:00
bool CRobotMain : : IsResearchDone ( ResearchType type , int team )
2015-07-13 15:38:19 +00:00
{
2015-07-13 16:13:28 +00:00
if ( team ! = 0 & & m_researchDone . count ( team ) = = 0 )
{
// Initialize with defaults
m_researchDone [ team ] = m_researchDone [ 0 ] ;
}
return ( m_researchDone [ team ] & type ) ! = 0 ;
2015-07-13 15:38:19 +00:00
}
2015-07-13 16:13:28 +00:00
void CRobotMain : : MarkResearchDone ( ResearchType type , int team )
2015-07-13 15:38:19 +00:00
{
2015-07-13 16:13:28 +00:00
if ( team ! = 0 & & m_researchDone . count ( team ) = = 0 )
{
// Initialize with defaults
m_researchDone [ team ] = m_researchDone [ 0 ] ;
}
m_researchDone [ team ] | = type ;
if ( team = = 0 )
{
2015-07-19 13:34:49 +00:00
m_playerProfile - > SetFreeGameResearchUnlock ( m_playerProfile - > GetFreeGameResearchUnlock ( ) | m_researchDone [ 0 ] ) ;
2015-07-13 16:13:28 +00:00
}
2015-07-13 15:38:19 +00:00
}
2015-07-13 16:13:28 +00:00
Error CRobotMain : : CanBuildError ( ObjectType type , int team )
2015-07-13 15:38:19 +00:00
{
if ( ! IsBuildingEnabled ( type ) ) return ERR_BUILD_DISABLED ;
2016-01-24 21:04:06 +00:00
if ( type = = OBJECT_TOWER & & ! IsResearchDone ( RESEARCH_TOWER , team ) ) return ERR_BUILD_RESEARCH ;
if ( type = = OBJECT_NUCLEAR & & ! IsResearchDone ( RESEARCH_ATOMIC , team ) ) return ERR_BUILD_RESEARCH ;
2015-07-13 15:38:19 +00:00
return ERR_OK ;
}
2015-07-13 16:13:28 +00:00
Error CRobotMain : : CanFactoryError ( ObjectType type , int team )
2015-07-13 15:38:19 +00:00
{
ToolType tool = GetToolFromObject ( type ) ;
DriveType drive = GetDriveFromObject ( type ) ;
2015-07-13 16:13:28 +00:00
if ( tool = = ToolType : : Sniffer & & ! IsResearchDone ( RESEARCH_SNIFFER , team ) ) return ERR_BUILD_RESEARCH ;
if ( tool = = ToolType : : Shooter & & ! IsResearchDone ( RESEARCH_CANON , team ) ) return ERR_BUILD_RESEARCH ;
if ( tool = = ToolType : : OrganicShooter & & ! IsResearchDone ( RESEARCH_iGUN , team ) ) return ERR_BUILD_RESEARCH ;
2017-11-22 23:11:29 +00:00
if ( tool = = ToolType : : Builder & & ! IsResearchDone ( RESEARCH_BUILDER , team ) ) return ERR_BUILD_RESEARCH ;
2015-07-13 15:38:19 +00:00
2015-07-13 16:13:28 +00:00
if ( drive = = DriveType : : Tracked & & ! IsResearchDone ( RESEARCH_TANK , team ) ) return ERR_BUILD_RESEARCH ;
if ( drive = = DriveType : : Winged & & ! IsResearchDone ( RESEARCH_FLY , team ) ) return ERR_BUILD_RESEARCH ;
if ( drive = = DriveType : : Legged & & ! IsResearchDone ( RESEARCH_iPAW , team ) ) return ERR_BUILD_RESEARCH ;
if ( drive = = DriveType : : BigTracked & & ! IsResearchDone ( RESEARCH_TANK , team ) ) return ERR_BUILD_RESEARCH ; // NOTE: Subber is not BigTracked! It currently counts as Other
2015-07-13 15:38:19 +00:00
2015-07-13 16:13:28 +00:00
if ( type = = OBJECT_MOBILErt & & ! IsResearchDone ( RESEARCH_THUMP , team ) ) return ERR_BUILD_RESEARCH ;
if ( type = = OBJECT_MOBILErc & & ! IsResearchDone ( RESEARCH_PHAZER , team ) ) return ERR_BUILD_RESEARCH ;
if ( type = = OBJECT_MOBILErr & & ! IsResearchDone ( RESEARCH_RECYCLER , team ) ) return ERR_BUILD_RESEARCH ;
if ( type = = OBJECT_MOBILErs & & ! IsResearchDone ( RESEARCH_SHIELD , team ) ) return ERR_BUILD_RESEARCH ;
if ( type = = OBJECT_MOBILEsa & & ! IsResearchDone ( RESEARCH_SUBM , team ) ) return ERR_BUILD_DISABLED ; // Can be only researched manually in Scene file
2015-07-13 15:38:19 +00:00
return ERR_OK ;
}
2015-07-14 20:05:12 +00:00
void CRobotMain : : PushToSelectionHistory ( CObject * obj )
{
if ( ! m_selectionHistory . empty ( ) & & m_selectionHistory . back ( ) = = obj )
return ; // already in history
m_selectionHistory . push_back ( obj ) ;
if ( m_selectionHistory . size ( ) > 50 ) // to avoid infinite growth
m_selectionHistory . pop_front ( ) ;
}
CObject * CRobotMain : : PopFromSelectionHistory ( )
{
if ( m_selectionHistory . empty ( ) )
return nullptr ;
CObject * obj = m_selectionHistory . back ( ) ;
m_selectionHistory . pop_back ( ) ;
return obj ;
}
void CRobotMain : : RemoveFromSelectionHistory ( CObject * object )
{
auto it = std : : remove_if ( m_selectionHistory . begin ( ) , m_selectionHistory . end ( ) ,
[ object ] ( const CObject * obj ) { return obj = = object ; } ) ;
m_selectionHistory . erase ( it , m_selectionHistory . end ( ) ) ;
}
2015-07-15 16:10:49 +00:00
float CRobotMain : : GetGlobalMagnifyDamage ( )
{
return m_globalMagnifyDamage ;
}
2015-08-11 21:13:57 +00:00
// Beginning of the effect when the instruction "detect" is used.
void CRobotMain : : StartDetectEffect ( COldObject * object , CObject * target )
{
Math : : Matrix * mat ;
Math : : Vector pos , goal ;
Math : : Point dim ;
mat = object - > GetWorldMatrix ( 0 ) ;
pos = Math : : Transform ( * mat , Math : : Vector ( 2.0f , 3.0f , 0.0f ) ) ;
2015-08-17 20:40:52 +00:00
if ( target = = nullptr )
2015-08-11 21:13:57 +00:00
{
goal = Math : : Transform ( * mat , Math : : Vector ( 50.0f , 3.0f , 0.0f ) ) ;
}
else
{
goal = target - > GetPosition ( ) ;
goal . y + = 3.0f ;
goal = Math : : SegmentPoint ( pos , goal , Math : : Distance ( pos , goal ) - 3.0f ) ;
}
dim . x = 3.0f ;
dim . y = dim . x ;
m_particle - > CreateRay ( pos , goal , Gfx : : PARTIRAY2 , dim , 0.2f ) ;
if ( target ! = nullptr )
{
goal = target - > GetPosition ( ) ;
goal . y + = 3.0f ;
goal = Math : : SegmentPoint ( pos , goal , Math : : Distance ( pos , goal ) - 1.0f ) ;
dim . x = 6.0f ;
dim . y = dim . x ;
m_particle - > CreateParticle ( goal , Math : : Vector ( 0.0f , 0.0f , 0.0f ) , dim ,
target ! = nullptr ? Gfx : : PARTIGLINT : Gfx : : PARTIGLINTr , 0.5f ) ;
}
m_sound - > Play ( target ! = nullptr ? SOUND_BUILD : SOUND_RECOVER ) ;
}
2015-09-06 17:12:00 +00:00
void CRobotMain : : CreateCodeBattleInterface ( )
{
2017-05-19 19:11:43 +00:00
if ( m_phase = = PHASE_SIMUL )
2015-11-10 21:33:02 +00:00
{
Math : : Point pos , ddim ;
2015-09-06 17:12:00 +00:00
2017-05-19 19:11:43 +00:00
int numTeams = m_scoreboard ? GetAllTeams ( ) . size ( ) : 0 ;
assert ( numTeams < EVENT_SCOREBOARD_MAX - EVENT_SCOREBOARD + 1 ) ;
2017-05-24 10:39:05 +00:00
float textHeight = m_engine - > GetText ( ) - > GetHeight ( Gfx : : FONT_COLOBOT , Gfx : : FONT_SIZE_SMALL ) ;
2017-05-19 19:11:43 +00:00
2015-11-10 21:33:02 +00:00
ddim . x = 100.0f / 640.0f ;
2017-05-19 19:11:43 +00:00
ddim . y = 100.0f / 480.0f + numTeams * textHeight ;
2015-11-10 21:33:02 +00:00
pos . x = 540.0f / 640.0f ;
pos . y = 100.0f / 480.0f ;
Ui : : CWindow * pw = m_interface - > CreateWindows ( pos , ddim , 3 , EVENT_WINDOW6 ) ;
2015-09-06 17:12:00 +00:00
2015-11-10 21:33:02 +00:00
ddim . x = 100.0f / 640.0f ;
ddim . y = 16.0f / 480.0f ;
pos . x = 540.0f / 640.0f ;
2017-05-19 19:11:43 +00:00
pos . y = 178.0f / 480.0f + numTeams * textHeight ;
2017-05-19 19:23:14 +00:00
std : : string text ;
GetResource ( RES_EVENT , EVENT_LABEL_CODE_BATTLE , text ) ;
pw - > CreateLabel ( pos , ddim , 0 , EVENT_LABEL_CODE_BATTLE , text ) ;
2015-09-06 17:12:00 +00:00
2015-11-10 21:33:02 +00:00
float titleBarSize = ( 11.0f / 64.0f ) ; // this is from the texture
ddim . x = 80.0f / 640.0f ;
ddim . y = ( ( 1 - titleBarSize ) * 100.0f - 20.0f ) / 480.0f ;
pos . x = 550.0f / 640.0f ;
pos . y = 110.0f / 480.0f ;
if ( ! m_codeBattleStarted )
{
pw - > CreateButton ( pos , ddim , 21 , EVENT_CODE_BATTLE_START ) ;
}
else
{
pw - > CreateButton ( pos , ddim , 13 , EVENT_CODE_BATTLE_SPECTATOR ) ;
}
2017-05-19 19:11:43 +00:00
2017-11-04 10:23:08 +00:00
if ( ! m_scoreboard ) return ;
2017-05-19 19:11:43 +00:00
pos . y + = ddim . y ;
ddim . y = textHeight ;
2017-05-24 10:39:05 +00:00
int i = 0 ;
auto teams = GetAllTeams ( ) ;
for ( auto it = teams . rbegin ( ) ; it ! = teams . rend ( ) ; + + it )
2017-05-19 19:11:43 +00:00
{
2017-05-24 10:39:05 +00:00
int team = * it ;
Ui : : CControl * pl ;
ddim . x = 55.0f / 640.0f ;
pl = m_codeBattleStarted
? static_cast < Ui : : CControl * > ( pw - > CreateLabel ( pos , ddim , 0 , static_cast < EventType > ( EVENT_SCOREBOARD + 2 * ( numTeams - i - 1 ) + 0 ) , " XXXXX " ) )
: static_cast < Ui : : CControl * > ( pw - > CreateEdit ( pos , ddim , 0 , static_cast < EventType > ( EVENT_SCOREBOARD + 2 * ( numTeams - i - 1 ) + 0 ) ) ) ;
2017-05-19 19:11:43 +00:00
pl - > SetTextAlign ( Gfx : : TEXT_ALIGN_LEFT ) ;
2017-05-24 10:39:05 +00:00
pl - > SetFontSize ( m_codeBattleStarted ? Gfx : : FONT_SIZE_SMALL : Gfx : : FONT_SIZE_SMALL * 0.75f ) ;
m_codeBattleStarted ? pl - > SetName ( GetTeamName ( team ) ) : static_cast < Ui : : CEdit * > ( pl ) - > SetText ( GetTeamName ( team ) ) ;
pos . x + = 57.5f / 640.0f ;
ddim . x = 22.5f / 640.0f ;
pl = m_codeBattleStarted
? static_cast < Ui : : CControl * > ( pw - > CreateLabel ( pos , ddim , 0 , static_cast < EventType > ( EVENT_SCOREBOARD + 2 * ( numTeams - i - 1 ) + 1 ) , " ??? " ) )
: static_cast < Ui : : CControl * > ( pw - > CreateEdit ( pos , ddim , 0 , static_cast < EventType > ( EVENT_SCOREBOARD + 2 * ( numTeams - i - 1 ) + 1 ) ) ) ;
2017-05-19 19:11:43 +00:00
pl - > SetTextAlign ( Gfx : : TEXT_ALIGN_RIGHT ) ;
2017-05-24 10:39:05 +00:00
pl - > SetFontSize ( m_codeBattleStarted ? Gfx : : FONT_SIZE_SMALL : Gfx : : FONT_SIZE_SMALL * 0.75f ) ;
m_codeBattleStarted ? pl - > SetName ( StrUtils : : ToString < int > ( m_scoreboard - > GetScore ( team ) ) ) : static_cast < Ui : : CEdit * > ( pl ) - > SetText ( StrUtils : : ToString < int > ( m_scoreboard - > GetScore ( team ) ) ) ;
pos . x - = 57.5f / 640.0f ;
2017-05-19 19:11:43 +00:00
pos . y + = ddim . y ;
2017-05-24 10:39:05 +00:00
i + + ;
2017-05-19 19:11:43 +00:00
}
2015-09-13 13:59:42 +00:00
}
2015-09-06 17:12:00 +00:00
}
2017-05-24 10:39:05 +00:00
void CRobotMain : : ApplyCodeBattleInterface ( )
{
assert ( GetMissionType ( ) = = MISSION_CODE_BATTLE ) ;
if ( ! m_scoreboard ) return ;
Ui : : CWindow * pw = static_cast < Ui : : CWindow * > ( m_interface - > SearchControl ( EVENT_WINDOW6 ) ) ;
assert ( pw ! = nullptr ) ;
int i = 0 ;
for ( int team : GetAllTeams ( ) )
{
Ui : : CEdit * pl ;
pl = static_cast < Ui : : CEdit * > ( pw - > SearchControl ( static_cast < EventType > ( EVENT_SCOREBOARD + 2 * i + 0 ) ) ) ;
assert ( pl ! = nullptr ) ;
m_teamNames [ team ] = pl - > GetText ( pl - > GetTextLength ( ) ) ;
pl = static_cast < Ui : : CEdit * > ( pw - > SearchControl ( static_cast < EventType > ( EVENT_SCOREBOARD + 2 * i + 1 ) ) ) ;
assert ( pl ! = nullptr ) ;
m_scoreboard - > SetScore ( team , StrUtils : : FromString < int > ( pl - > GetText ( pl - > GetTextLength ( ) ) ) ) ;
i + + ;
}
}
2017-05-19 19:11:43 +00:00
void CRobotMain : : UpdateCodeBattleInterface ( )
{
assert ( GetMissionType ( ) = = MISSION_CODE_BATTLE ) ;
if ( ! m_scoreboard ) return ;
Ui : : CWindow * pw = static_cast < Ui : : CWindow * > ( m_interface - > SearchControl ( EVENT_WINDOW6 ) ) ;
assert ( pw ! = nullptr ) ;
int i = 0 ;
for ( int team : GetAllTeams ( ) )
{
2017-05-24 10:39:05 +00:00
Ui : : CControl * pl ;
2017-05-19 19:11:43 +00:00
2017-05-24 10:39:05 +00:00
pl = pw - > SearchControl ( static_cast < EventType > ( EVENT_SCOREBOARD + 2 * i + 0 ) ) ;
2017-05-19 19:11:43 +00:00
assert ( pl ! = nullptr ) ;
pl - > SetName ( GetTeamName ( team ) ) ;
2017-05-24 10:39:05 +00:00
pl = pw - > SearchControl ( static_cast < EventType > ( EVENT_SCOREBOARD + 2 * i + 1 ) ) ;
2017-05-19 19:11:43 +00:00
assert ( pl ! = nullptr ) ;
pl - > SetName ( StrUtils : : ToString < int > ( m_scoreboard - > GetScore ( team ) ) ) ;
i + + ;
}
}
2015-09-06 17:12:00 +00:00
void CRobotMain : : DestroyCodeBattleInterface ( )
{
m_interface - > DeleteControl ( EVENT_WINDOW6 ) ;
}
2015-09-13 13:59:42 +00:00
void CRobotMain : : SetCodeBattleSpectatorMode ( bool mode )
{
// Deselect object, but keep camera attached to it
CObject * obj = DeselectAll ( ) ;
if ( m_codeBattleSpectator )
obj = m_camera - > GetControllingObject ( ) ;
m_codeBattleSpectator = mode ;
SelectObject ( obj , false ) ; // this uses code battle selection mode already
}
2016-03-17 03:31:16 +00:00
void CRobotMain : : UpdateDebugCrashSpheres ( )
{
m_engine - > ClearDisplayCrashSpheres ( ) ;
if ( m_debugCrashSpheres )
{
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
auto crashSpheres = obj - > GetAllCrashSpheres ( ) ;
std : : vector < Math : : Sphere > displaySpheres ;
for ( const auto & crashSphere : crashSpheres )
{
displaySpheres . push_back ( crashSphere . sphere ) ;
}
m_engine - > AddDisplayCrashSpheres ( displaySpheres ) ;
}
}
}
2016-03-28 11:51:39 +00:00
void CRobotMain : : SetDebugCrashSpheres ( bool draw )
{
m_debugCrashSpheres = draw ;
}
bool CRobotMain : : GetDebugCrashSpheres ( )
{
return m_debugCrashSpheres ;
}
2017-01-02 19:23:19 +00:00
void CRobotMain : : PushToCommandHistory ( std : : string str )
{
if ( ! m_commandHistory . empty ( ) & & m_commandHistory . front ( ) = = str ) // already in history
return ;
m_commandHistory . push_front ( str ) ;
if ( m_commandHistory . size ( ) > 50 ) // to avoid infinite growth
m_commandHistory . pop_back ( ) ;
}
std : : string CRobotMain : : GetNextFromCommandHistory ( )
{
if ( m_commandHistory . empty ( ) | | static_cast < int > ( m_commandHistory . size ( ) ) < = m_commandHistoryIndex + 1 ) // no next element
return " " ;
return m_commandHistory [ + + m_commandHistoryIndex ] ;
}
std : : string CRobotMain : : GetPreviousFromCommandHistory ( )
{
if ( m_commandHistory . empty ( ) | | m_commandHistoryIndex < 1 ) // first or none element selected
return " " ;
return m_commandHistory [ - - m_commandHistoryIndex ] ;
}
2017-05-17 16:22:27 +00:00
CScoreboard * CRobotMain : : GetScoreboard ( )
{
return m_scoreboard . get ( ) ;
}
2017-05-19 19:11:43 +00:00
std : : set < int > CRobotMain : : GetAllTeams ( )
{
std : : set < int > teams = GetAllActiveTeams ( ) ;
for ( auto & it : m_teamFinished )
{
teams . insert ( it . first ) ;
}
return teams ;
}
std : : set < int > CRobotMain : : GetAllActiveTeams ( )
{
std : : set < int > teams ;
for ( CObject * obj : m_objMan - > GetAllObjects ( ) )
{
int team = obj - > GetTeam ( ) ;
if ( team = = 0 ) continue ;
teams . insert ( team ) ;
}
return teams ;
}