2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
/** @file script_testmode.cpp Implementation of ScriptTestMode. */
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2011-01-22 11:33:16 +01:00
|
|
|
#include "../../stdafx.h"
|
2011-11-30 00:07:38 +01:00
|
|
|
#include "script_testmode.hpp"
|
2011-11-30 00:27:17 +01:00
|
|
|
#include "../script_instance.hpp"
|
2011-11-30 00:21:13 +01:00
|
|
|
#include "../script_fatalerror.hpp"
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../../safeguards.h"
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
bool ScriptTestMode::ModeProc()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
/* In test mode we only return 'false', telling the DoCommand it
|
2009-03-14 19:16:29 +01:00
|
|
|
* should stop after testing the command and return with that result. */
|
2009-01-12 18:11:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:15:35 +01:00
|
|
|
ScriptTestMode::ScriptTestMode()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
this->last_mode = this->GetDoCommandMode();
|
|
|
|
this->last_instance = this->GetDoCommandModeInstance();
|
2011-11-30 00:15:35 +01:00
|
|
|
this->SetDoCommandMode(&ScriptTestMode::ModeProc, this);
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2015-08-10 22:04:31 +02:00
|
|
|
void ScriptTestMode::FinalRelease()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-08-20 12:39:39 +02:00
|
|
|
if (this->GetDoCommandModeInstance() != this) {
|
2023-12-14 21:07:40 +01:00
|
|
|
/* Ignore this error if the script is not alive. */
|
|
|
|
if (ScriptObject::GetActiveInstance()->IsAlive()) {
|
2012-03-04 17:54:12 +01:00
|
|
|
throw Script_FatalError("Testmode object was removed while it was not the latest *Mode object created.");
|
2009-08-20 12:39:39 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-10 22:04:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptTestMode::~ScriptTestMode()
|
|
|
|
{
|
2009-01-12 18:11:45 +01:00
|
|
|
this->SetDoCommandMode(this->last_mode, this->last_instance);
|
|
|
|
}
|