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:07:38 +00:00
|
|
|
/** @file script_testmode.cpp Implementation of AITestMode. */
|
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"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-01-10 23:20:11 +00:00
|
|
|
bool AITestMode::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
AITestMode::AITestMode()
|
|
|
|
{
|
|
|
|
this->last_mode = this->GetDoCommandMode();
|
|
|
|
this->last_instance = this->GetDoCommandModeInstance();
|
|
|
|
this->SetDoCommandMode(&AITestMode::ModeProc, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AITestMode::~AITestMode()
|
|
|
|
{
|
2009-08-20 10:39:39 +00:00
|
|
|
if (this->GetDoCommandModeInstance() != this) {
|
|
|
|
/* Ignore this error if the AI already died. */
|
2011-11-13 20:43:48 +00:00
|
|
|
if (!AIObject::GetActiveInstance()->IsDead()) {
|
2009-08-20 10:39:39 +00:00
|
|
|
throw AI_FatalError("AITestmode object was removed while it was not the latest AI*Mode object created.");
|
|
|
|
}
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
this->SetDoCommandMode(this->last_mode, this->last_instance);
|
|
|
|
}
|