1 /* 2 * This file is part of OpenTTD. 3 * OpenTTD 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, version 2. 4 * OpenTTD 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. 5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 6 */ 7 8 /** @file script_testmode.cpp Implementation of ScriptTestMode. */ 9 10 #include "../../stdafx.h" 11 #include "script_testmode.hpp" 12 #include "../script_instance.hpp" 13 #include "../script_fatalerror.hpp" 14 15 #include "../../safeguards.h" 16 ModeProc()17bool ScriptTestMode::ModeProc() 18 { 19 /* In test mode we only return 'false', telling the DoCommand it 20 * should stop after testing the command and return with that result. */ 21 return false; 22 } 23 ScriptTestMode()24ScriptTestMode::ScriptTestMode() 25 { 26 this->last_mode = this->GetDoCommandMode(); 27 this->last_instance = this->GetDoCommandModeInstance(); 28 this->SetDoCommandMode(&ScriptTestMode::ModeProc, this); 29 } 30 FinalRelease()31void ScriptTestMode::FinalRelease() 32 { 33 if (this->GetDoCommandModeInstance() != this) { 34 /* Ignore this error if the script already died. */ 35 if (!ScriptObject::GetActiveInstance()->IsDead()) { 36 throw Script_FatalError("Testmode object was removed while it was not the latest *Mode object created."); 37 } 38 } 39 } 40 ~ScriptTestMode()41ScriptTestMode::~ScriptTestMode() 42 { 43 this->SetDoCommandMode(this->last_mode, this->last_instance); 44 } 45