19 #include "aircraft.h" |
19 #include "aircraft.h" |
20 #include "newgrf_cargo.h" |
20 #include "newgrf_cargo.h" |
21 #include "date.h" |
21 #include "date.h" |
22 #include "table/engines.h" |
22 #include "table/engines.h" |
23 #include "group.h" |
23 #include "group.h" |
|
24 #include "string.h" |
|
25 #include "strings.h" |
24 |
26 |
25 EngineInfo _engine_info[TOTAL_NUM_ENGINES]; |
27 EngineInfo _engine_info[TOTAL_NUM_ENGINES]; |
26 RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; |
28 RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; |
27 ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES]; |
29 ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES]; |
28 AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; |
30 AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; |
366 } |
368 } |
367 } |
369 } |
368 } |
370 } |
369 } |
371 } |
370 |
372 |
|
373 static bool IsUniqueEngineName(const char *name) |
|
374 { |
|
375 char buf[512]; |
|
376 |
|
377 for (EngineID i = 0; i < TOTAL_NUM_ENGINES; i++) { |
|
378 SetDParam(0, i); |
|
379 GetString(buf, STR_ENGINE_NAME, lastof(buf)); |
|
380 if (strcmp(buf, name) == 0) return false; |
|
381 } |
|
382 |
|
383 return true; |
|
384 } |
|
385 |
371 /** Rename an engine. |
386 /** Rename an engine. |
372 * @param tile unused |
387 * @param tile unused |
373 * @param flags operation to perfom |
388 * @param flags operation to perfom |
374 * @param p1 engine ID to rename |
389 * @param p1 engine ID to rename |
375 * @param p2 unused |
390 * @param p2 unused |
376 */ |
391 */ |
377 CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
392 CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
378 { |
393 { |
379 StringID str; |
394 StringID str; |
380 |
395 |
381 if (!IsEngineIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
396 if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
382 |
397 |
383 str = AllocateNameUnique(_cmd_text, 0); |
398 if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
|
399 |
|
400 str = AllocateName(_cmd_text, 0); |
384 if (str == 0) return CMD_ERROR; |
401 if (str == 0) return CMD_ERROR; |
385 |
402 |
386 if (flags & DC_EXEC) { |
403 if (flags & DC_EXEC) { |
387 StringID old_str = _engine_name_strings[p1]; |
404 StringID old_str = _engine_name_strings[p1]; |
388 _engine_name_strings[p1] = str; |
405 _engine_name_strings[p1] = str; |