diff -r 1d50fe99b7e9 -r e1b5f29cc6f9 src/ai/api/ai_vehicle.cpp --- a/src/ai/api/ai_vehicle.cpp Sun Aug 19 13:31:04 2007 +0000 +++ b/src/ai/api/ai_vehicle.cpp Sun Aug 19 13:43:59 2007 +0000 @@ -10,6 +10,8 @@ #include "../../engine.h" #include "../../player.h" #include "../../aircraft.h" +#include "../../strings.h" +#include "table/strings.h" /* static */ bool AIVehicle::IsValidEngine(EngineID engine_id) { @@ -189,6 +191,15 @@ return this->DoCommand(0, vehicle_id, 0, CMD_SKIP_TO_ORDER); } +bool AIVehicle::SetName(VehicleID vehicle_id, const char *name) +{ + if (!this->IsValidVehicle(vehicle_id)) return false; + if (name == NULL) return false; + + _cmd_text = name; + return this->DoCommand(0, vehicle_id, 0, CMD_NAME_VEHICLE); +} + /* static */ TileIndex AIVehicle::GetLocation(VehicleID vehicle_id) { if (!AIVehicle::IsValidVehicle(vehicle_id)) return INVALID_TILE; @@ -210,6 +221,18 @@ return ::GetVehicle(vehicle_id)->unitnumber; } +/* static */ char *AIVehicle::GetName(VehicleID vehicle_id) +{ + if (!AIVehicle::IsValidVehicle(vehicle_id)) return NULL; + + static const int len = 64; + char *vehicle_name = MallocT(len); + + SetDParam(0, ::GetVehicle(vehicle_id)->unitnumber); + GetString(vehicle_name, ::GetVehicle(vehicle_id)->string_id, &vehicle_name[len - 1]); + return vehicle_name; +} + /* static */ int32 AIVehicle::GetAge(VehicleID vehicle_id) { if (!AIVehicle::IsValidVehicle(vehicle_id)) return -1;