Changeset - r7481:5a6c742af0f6
[Not reviewed]
master
0 3 0
rubidium - 17 years ago 2007-08-27 21:33:26
rubidium@openttd.org
(svn r10992) -Fix [FS#1132]: huge amount of vehicles in the "ungrouped" group. Patch by frosch.
3 files changed with 9 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_gui.cpp
Show inline comments
 
@@ -46,13 +46,13 @@ void InitializeVehiclesGuiList()
 
 *   - when not changing the count (used when changing replace orders)
 
 */
 
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
 
{
 
	Player *p = GetPlayer(_local_player);
 
	byte type = GetEngine(e)->type;
 
	uint num_engines = GetGroupNumEngines(id_g, e);
 
	uint num_engines = GetGroupNumEngines(_local_player, id_g, e);
 

	
 
	if (num_engines == 0 || p->num_engines[e] == 0) {
 
		/* We don't have any of this engine type.
 
		 * Either we just sold the last one, we build a new one or we stopped replacing it.
 
		 * In all cases, we need to update the left list */
 
		_rebuild_left_list = true;
 
@@ -151,13 +151,13 @@ static void GenerateReplaceVehList(Windo
 

	
 
	FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
 
		if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains
 

	
 
		if (draw_left) {
 
			const GroupID selected_group = WP(w, replaceveh_d).sel_group;
 
			const uint num_engines = GetGroupNumEngines(selected_group, e);
 
			const uint num_engines = GetGroupNumEngines(_local_player, selected_group, e);
 

	
 
			/* Skip drawing the engines we don't have any of and haven't set for replacement */
 
			if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue;
 
		} else {
 
			/* This is for engines we can replace to and they should depend on what we selected to replace from */
 
			if (!IsEngineBuildable(e, type, _local_player)) continue; // we need to be able to build the engine
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -850,13 +850,14 @@ void DrawEngineList(VehicleType type, in
 
			break;
 
		default: NOT_REACHED();
 
	}
 

	
 
	for (; min < max; min++, y += step_size) {
 
		const EngineID engine = eng_list[min];
 
		const uint num_engines = GetGroupNumEngines(selected_group, engine);
 
		/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
 
		const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
 

	
 
		SetDParam(0, engine);
 
		DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? 0xC : 0x10);
 
		DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
 
		if (show_count) {
 
			SetDParam(0, num_engines);
src/group.h
Show inline comments
 
@@ -73,21 +73,23 @@ static inline uint GetGroupArraySize(voi
 
 * Get the number of engines with EngineID id_e in the group with GroupID
 
 * id_g
 
 * @param id_g The GroupID of the group used
 
 * @param id_e The EngineID of the engine to count
 
 * @return The number of engines with EngineID id_e in the group
 
 */
 
static inline uint GetGroupNumEngines(GroupID id_g, EngineID id_e)
 
static inline uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e)
 
{
 
	if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e];
 

	
 
	uint num = GetPlayer(_local_player)->num_engines[id_e];
 
	uint num = GetPlayer(p)->num_engines[id_e];
 
	if (!IsDefaultGroupID(id_g)) return num;
 

	
 
	const Group *g;
 
	FOR_ALL_GROUPS(g) num -= g->num_engines[id_e];
 
	FOR_ALL_GROUPS(g) {
 
		if (g->owner == p) num -= g->num_engines[id_e];
 
	}
 
	return num;
 
}
 

	
 
static inline void IncreaseGroupNumVehicle(GroupID id_g)
 
{
 
	if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++;
0 comments (0 inline, 0 general)