Changeset - r27342:12ceee3b2fcf
[Not reviewed]
master
0 2 0
PeterN - 16 months ago 2023-05-13 21:27:32
peter1138@openttd.org
Fix: Don't use a loop to test if classid is valid. (#10818)

Additionally the Object class test was broken.
2 files changed with 3 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/object_gui.cpp
Show inline comments
 
@@ -182,19 +182,8 @@ public:
 
		} else {
 
			/* Check if the previously selected object class is not available anymore as a
 
			 * result of starting a new game without the corresponding NewGRF. */
 
			bool available = false;
 
			for (uint i = 0; ObjectClass::GetClassCount(); ++i) {
 
				if ((ObjectClassID)i == _selected_object_class) {
 
					available = true;
 
					break;
 
				}
 
			}
 

	
 
			if (available) {
 
				this->SelectOtherClass(_selected_object_class);
 
			} else {
 
				this->SelectOtherClass(this->object_classes[0]);
 
			}
 
			bool available = _selected_object_class < ObjectClass::GetClassCount();
 
			this->SelectOtherClass(available ? _selected_object_class : this->object_classes[0]);
 
		}
 

	
 
		if (this->CanRestoreSelectedObject()) {
src/rail_gui.cpp
Show inline comments
 
@@ -1089,14 +1089,7 @@ public:
 
		} else {
 
			/* Check if the previously selected station class is not available anymore as a
 
			 * result of starting a new game without the corresponding NewGRF. */
 
			bool available = false;
 
			for (uint i = 0; i < StationClass::GetClassCount(); ++i) {
 
				if ((StationClassID)i == _railstation.station_class) {
 
					available = true;
 
					break;
 
				}
 
			}
 

	
 
			bool available = _railstation.station_class < StationClass::GetClassCount();
 
			this->SelectOtherClass(available ? _railstation.station_class : StationClassID::STAT_CLASS_DFLT);
 
		}
 
	}
0 comments (0 inline, 0 general)