# ai_testmode.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_testmode.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_testmode.hpp"
    00013 #include "../../company_base.h"
    00014 #include "../../company_func.h"
    00015 #include "../ai_instance.hpp"
    00016
    00017 bool AITestMode::ModeProc()
    00018 {
    00019   /* In test mode we only return 'false', telling the DoCommand it
    00020    *  should stop after testing the command and return with that result. */
    00021   return false;
    00022 }
    00023
    00024 AITestMode::AITestMode()
    00025 {
    00026   this->last_mode     = this->GetDoCommandMode();
    00027   this->last_instance = this->GetDoCommandModeInstance();
    00028   this->SetDoCommandMode(&AITestMode::ModeProc, this);
    00029 }
    00030
    00031 AITestMode::~AITestMode()
    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("AITestmode 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 }