# ai_testmode.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    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 "ai_testmode.hpp"
    00014 #include "../../company_base.h"
    00015 #include "../../company_func.h"
    00016 #include "../ai_instance.hpp"
    00017
    00018 bool AITestMode::ModeProc()
    00019 {
    00020   /* In test mode we only return 'false', telling the DoCommand it
    00021    *  should stop after testing the command and return with that result. */
    00022   return false;
    00023 }
    00024
    00025 AITestMode::AITestMode()
    00026 {
    00027   this->last_mode     = this->GetDoCommandMode();
    00028   this->last_instance = this->GetDoCommandModeInstance();
    00029   this->SetDoCommandMode(&AITestMode::ModeProc, this);
    00030 }
    00031
    00032 AITestMode::~AITestMode()
    00033 {
    00034   if (this->GetDoCommandModeInstance() != this) {
    00035     AIInstance *instance = Company::Get(_current_company)->ai_instance;
    00036     /* Ignore this error if the AI already died. */
    00037     if (!instance->IsDead()) {
    00038       throw AI_FatalError("AITestmode 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 }