# ai_testmode.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_testmode.cpp 17236 2009-08-20 13:25:21Z rubidium $ */
    00002
    00005 #include "ai_testmode.hpp"
    00006 #include "../../command_type.h"
    00007 #include "../../company_base.h"
    00008 #include "../../company_func.h"
    00009 #include "../ai_instance.hpp"
    00010
    00011 bool AITestMode::ModeProc(TileIndex tile, uint32 p1, uint32 p2, uint procc, CommandCost costs)
    00012 {
    00013   /* In test mode we only return 'false', telling the DoCommand it
    00014    *  should stop after testing the command and return with that result. */
    00015   return false;
    00016 }
    00017
    00018 AITestMode::AITestMode()
    00019 {
    00020   this->last_mode     = this->GetDoCommandMode();
    00021   this->last_instance = this->GetDoCommandModeInstance();
    00022   this->SetDoCommandMode(&AITestMode::ModeProc, this);
    00023 }
    00024
    00025 AITestMode::~AITestMode()
    00026 {
    00027   if (this->GetDoCommandModeInstance() != this) {
    00028     AIInstance *instance = GetCompany(_current_company)->ai_instance;
    00029     /* Ignore this error if the AI already died. */
    00030     if (!instance->IsDead()) {
    00031       throw AI_FatalError("AITestmode object was removed while it was not the latest AI*Mode object created.");
    00032     }
    00033   }
    00034   this->SetDoCommandMode(this->last_mode, this->last_instance);
    00035 }