2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00: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-29 23:15:35 +00:00
|
|
|
/** @file script_testmode.cpp Implementation of ScriptTestMode. */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-01-22 10:33:16 +00:00
|
|
|
#include "../../stdafx.h"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "script_testmode.hpp"
|
2009-08-20 10:39:39 +00:00
|
|
|
#include "../../company_base.h"
|
|
|
|
#include "../../company_func.h"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "../../ai/ai_instance.hpp"
|
2011-11-29 23:21:13 +00:00
|
|
|
#include "../script_fatalerror.hpp"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
bool ScriptTestMode::ModeProc()
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
/* In test mode we only return 'false', telling the DoCommand it
|
2009-03-14 18:16:29 +00:00
|
|
|
* should stop after testing the command and return with that result. */
|
2009-01-12 17:11:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
ScriptTestMode::ScriptTestMode()
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
this->last_mode = this->GetDoCommandMode();
|
|
|
|
this->last_instance = this->GetDoCommandModeInstance();
|
2011-11-29 23:15:35 +00:00
|
|
|
this->SetDoCommandMode(&ScriptTestMode::ModeProc, this);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
ScriptTestMode::~ScriptTestMode()
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2009-08-20 10:39:39 +00:00
|
|
|
if (this->GetDoCommandModeInstance() != this) {
|
|
|
|
/* Ignore this error if the AI already died. */
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptObject::GetActiveInstance()->IsDead()) {
|
2011-11-29 23:21:13 +00:00
|
|
|
throw Script_FatalError("AITestmode object was removed while it was not the latest AI*Mode object created.");
|
2009-08-20 10:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
this->SetDoCommandMode(this->last_mode, this->last_instance);
|
|
|
|
}
|