# ai_event_types.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_event_types.cpp 17898 2009-10-28 20:15:46Z frosch $ */
    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_event_types.hpp"
    00013 #include "ai_vehicle.hpp"
    00014 #include "../../command_type.h"
    00015 #include "../../strings_func.h"
    00016 #include "../../settings_type.h"
    00017 #include "../../engine_base.h"
    00018 #include "../../articulated_vehicles.h"
    00019 #include "table/strings.h"
    00020
    00021 char *AIEventEnginePreview::GetName()
    00022 {
    00023   static const int len = 64;
    00024   char *engine_name = MallocT<char>(len);
    00025
    00026 	::SetDParam(0, this->engine);
    00027   ::GetString(engine_name, STR_ENGINE_NAME, &engine_name[len - 1]);
    00028   return engine_name;
    00029 }
    00030
    00031 CargoID AIEventEnginePreview::GetCargoType()
    00032 {
    00033   CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine);
    00034
    00035   CargoID most_cargo = CT_INVALID;
    00036   uint amount = 0;
    00037   for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
    00038     if (cap[cid] > amount) {
    00039       amount = cap[cid];
    00040       most_cargo = cid;
    00041     }
    00042   }
    00043
    00044   return most_cargo;
    00045 }
    00046
    00047 int32 AIEventEnginePreview::GetCapacity()
    00048 {
    00049   const Engine *e = ::Engine::Get(this->engine);
    00050   switch (e->type) {
    00051     case VEH_ROAD:
    00052     case VEH_TRAIN: {
    00053       CargoArray capacities = GetCapacityOfArticulatedParts(this->engine);
    00054       for (CargoID c = 0; c < NUM_CARGO; c++) {
    00055         if (capacities[c] == 0) continue;
    00056         return capacities[c];
    00057       }
    00058       return -1;
    00059     } break;
    00060
    00061     case VEH_SHIP:
    00062     case VEH_AIRCRAFT:
    00063       return e->GetDisplayDefaultCapacity();
    00064       break;
    00065
    00066     default: NOT_REACHED();
    00067   }
    00068 }
    00069
    00070 int32 AIEventEnginePreview::GetMaxSpeed()
    00071 {
    00072   const Engine *e = ::Engine::Get(this->engine);
    00073   int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
    00074   if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
    00075   return max_speed;
    00076 }
    00077
    00078 Money AIEventEnginePreview::GetPrice()
    00079 {
    00080   return ::Engine::Get(this->engine)->GetCost();
    00081 }
    00082
    00083 Money AIEventEnginePreview::GetRunningCost()
    00084 {
    00085   return ::Engine::Get(this->engine)->GetRunningCost();
    00086 }
    00087
    00088 int32 AIEventEnginePreview::GetVehicleType()
    00089 {
    00090   switch (::Engine::Get(this->engine)->type) {
    00091     case VEH_ROAD:     return AIVehicle::VT_ROAD;
    00092     case VEH_TRAIN:    return AIVehicle::VT_RAIL;
    00093     case VEH_SHIP:     return AIVehicle::VT_WATER;
    00094     case VEH_AIRCRAFT: return AIVehicle::VT_AIR;
    00095     default: NOT_REACHED();
    00096   }
    00097 }
    00098
    00099 bool AIEventEnginePreview::AcceptPreview()
    00100 {
    00101   return AIObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
    00102 }
    00103
    00104 bool AIEventCompanyAskMerger::AcceptMerger()
    00105 {
    00106   return AIObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
    00107 }