src/autoreplace_cmd.cpp
changeset 6505 8b4c20ddacd3
parent 6491 00dc414c909d
child 6551 85a70a72ffef
equal deleted inserted replaced
6504:1beaedad1611 6505:8b4c20ddacd3
    85  *    CT_NO_REFIT is returned if no refit is needed
    85  *    CT_NO_REFIT is returned if no refit is needed
    86  *    CT_INVALID is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
    86  *    CT_INVALID is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible
    87  */
    87  */
    88 static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type)
    88 static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type)
    89 {
    89 {
    90 	bool new_cargo_capacity = true;
    90 	CargoID new_cargo_type = GetEngineCargoType(engine_type);
    91 	CargoID new_cargo_type = CT_INVALID;
    91 
    92 
    92 	if (new_cargo_type == CT_INVALID) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
    93 	switch (v->type) {
       
    94 		case VEH_TRAIN:
       
    95 			new_cargo_capacity = (RailVehInfo(engine_type)->capacity > 0);
       
    96 			new_cargo_type     = RailVehInfo(engine_type)->cargo_type;
       
    97 			break;
       
    98 
       
    99 		case VEH_ROAD:
       
   100 			new_cargo_capacity = (RoadVehInfo(engine_type)->capacity > 0);
       
   101 			new_cargo_type     = RoadVehInfo(engine_type)->cargo_type;
       
   102 			break;
       
   103 		case VEH_SHIP:
       
   104 			new_cargo_capacity = (ShipVehInfo(engine_type)->capacity > 0);
       
   105 			new_cargo_type     = ShipVehInfo(engine_type)->cargo_type;
       
   106 			break;
       
   107 
       
   108 		case VEH_AIRCRAFT:
       
   109 			/* all aircraft starts as passenger planes with cargo capacity
       
   110 			 * new_cargo_capacity is always true for aircraft, which is the init value. No need to set it here */
       
   111 			new_cargo_type     = CT_PASSENGERS;
       
   112 			break;
       
   113 
       
   114 		default: NOT_REACHED(); break;
       
   115 	}
       
   116 
       
   117 	if (!new_cargo_capacity) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
       
   118 
    93 
   119 	if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) {
    94 	if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) {
   120 		if (VerifyAutoreplaceRefitForOrders(v, engine_type)) {
    95 		if (VerifyAutoreplaceRefitForOrders(v, engine_type)) {
   121 			return v->cargo_type == new_cargo_type ? (CargoID)CT_NO_REFIT : v->cargo_type;
    96 			return v->cargo_type == new_cargo_type ? (CargoID)CT_NO_REFIT : v->cargo_type;
   122 		} else {
    97 		} else {