00001 /* $Id: script_execmode.cpp 23369 2011-11-29 23:27:17Z truebrain $ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * 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. 00006 * 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. 00007 * 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/>. 00008 */ 00009 00012 #include "../../stdafx.h" 00013 #include "script_execmode.hpp" 00014 #include "../../company_base.h" 00015 #include "../../company_func.h" 00016 #include "../script_instance.hpp" 00017 #include "../script_fatalerror.hpp" 00018 00019 bool ScriptExecMode::ModeProc() 00020 { 00021 /* In execution mode we only return 'true', telling the DoCommand it 00022 * should continue with the real execution of the command. */ 00023 return true; 00024 } 00025 00026 ScriptExecMode::ScriptExecMode() 00027 { 00028 this->last_mode = this->GetDoCommandMode(); 00029 this->last_instance = this->GetDoCommandModeInstance(); 00030 this->SetDoCommandMode(&ScriptExecMode::ModeProc, this); 00031 } 00032 00033 ScriptExecMode::~ScriptExecMode() 00034 { 00035 if (this->GetDoCommandModeInstance() != this) { 00036 /* Ignore this error if the AI already died. */ 00037 if (!ScriptObject::GetActiveInstance()->IsDead()) { 00038 throw Script_FatalError("ScriptExecMode object was removed while it was not the latest AI*Mode object created."); 00039 } 00040 } 00041 this->SetDoCommandMode(this->last_mode, this->last_instance); 00042 }