src/engine.cpp
changeset 10148 ad8e8a65f6a2
parent 10127 4f53c1cfcfe9
child 10207 c291a21b304e
equal deleted inserted replaced
10147:f0215b6c526e 10148:ad8e8a65f6a2
   492  * @param p2 unused
   492  * @param p2 unused
   493  */
   493  */
   494 CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   494 CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   495 {
   495 {
   496 	if (!IsEngineIndex(p1)) return CMD_ERROR;
   496 	if (!IsEngineIndex(p1)) return CMD_ERROR;
   497 	if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
   497 
   498 
   498 	bool reset = StrEmpty(_cmd_text);
   499 	if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
   499 
       
   500 	if (!reset) {
       
   501 		if (strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
       
   502 		if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
       
   503 	}
   500 
   504 
   501 	if (flags & DC_EXEC) {
   505 	if (flags & DC_EXEC) {
   502 		Engine *e = GetEngine(p1);
   506 		Engine *e = GetEngine(p1);
   503 		free(e->name);
   507 		free(e->name);
   504 		e->name = strdup(_cmd_text);
   508 
   505 		_vehicle_design_names |= 3;
   509 		if (reset) {
       
   510 			e->name = NULL;
       
   511 			/* if we removed the last custom name, disable the 'Save custom names' button */
       
   512 			_vehicle_design_names &= ~1;
       
   513 			FOR_ALL_ENGINES(e) {
       
   514 				if (e->name != NULL) {
       
   515 					_vehicle_design_names |= 1;
       
   516 					break;
       
   517 				}
       
   518 			}
       
   519 		} else {
       
   520 			e->name = strdup(_cmd_text);
       
   521 			_vehicle_design_names |= 3;
       
   522 		}
       
   523 
   506 		MarkWholeScreenDirty();
   524 		MarkWholeScreenDirty();
   507 	}
   525 	}
   508 
   526 
   509 	return CommandCost();
   527 	return CommandCost();
   510 }
   528 }