ai_event_types.cpp

Go to the documentation of this file.
00001 /* $Id: ai_event_types.cpp 21571 2010-12-21 15:23:54Z alberth $ */
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     }
00060 
00061     case VEH_SHIP:
00062     case VEH_AIRCRAFT:
00063       return e->GetDisplayDefaultCapacity();
00064 
00065     default: NOT_REACHED();
00066   }
00067 }
00068 
00069 int32 AIEventEnginePreview::GetMaxSpeed()
00070 {
00071   const Engine *e = ::Engine::Get(this->engine);
00072   int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
00073   if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
00074   return max_speed;
00075 }
00076 
00077 Money AIEventEnginePreview::GetPrice()
00078 {
00079   return ::Engine::Get(this->engine)->GetCost();
00080 }
00081 
00082 Money AIEventEnginePreview::GetRunningCost()
00083 {
00084   return ::Engine::Get(this->engine)->GetRunningCost();
00085 }
00086 
00087 int32 AIEventEnginePreview::GetVehicleType()
00088 {
00089   switch (::Engine::Get(this->engine)->type) {
00090     case VEH_ROAD:     return AIVehicle::VT_ROAD;
00091     case VEH_TRAIN:    return AIVehicle::VT_RAIL;
00092     case VEH_SHIP:     return AIVehicle::VT_WATER;
00093     case VEH_AIRCRAFT: return AIVehicle::VT_AIR;
00094     default: NOT_REACHED();
00095   }
00096 }
00097 
00098 bool AIEventEnginePreview::AcceptPreview()
00099 {
00100   return AIObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
00101 }
00102 
00103 bool AIEventCompanyAskMerger::AcceptMerger()
00104 {
00105   return AIObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
00106 }

Generated on Fri Dec 31 17:15:28 2010 for OpenTTD by  doxygen 1.6.1