# ai_execmode.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_execmode.cpp 18809 2010-01-15 16:41:15Z rubidium $ */
    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 "ai_execmode.hpp"
    00013 #include "../../company_base.h"
    00014 #include "../../company_func.h"
    00015 #include "../ai_instance.hpp"
    00016
    00017 bool AIExecMode::ModeProc()
    00018 {
    00019   /* In execution mode we only return 'true', telling the DoCommand it
    00020    *  should continue with the real execution of the command. */
    00021   return true;
    00022 }
    00023
    00024 AIExecMode::AIExecMode()
    00025 {
    00026   this->last_mode     = this->GetDoCommandMode();
    00027   this->last_instance = this->GetDoCommandModeInstance();
    00028   this->SetDoCommandMode(&AIExecMode::ModeProc, this);
    00029 }
    00030
    00031 AIExecMode::~AIExecMode()
    00032 {
    00033   if (this->GetDoCommandModeInstance() != this) {
    00034     AIInstance *instance = Company::Get(_current_company)->ai_instance;
    00035     /* Ignore this error if the AI already died. */
    00036     if (!instance->IsDead()) {
    00037       throw AI_FatalError("AIExecMode object was removed while it was not the latest AI*Mode object created.");
    00038     }
    00039   }
    00040   this->SetDoCommandMode(this->last_mode, this->last_instance);
    00041 }