src/vehicle_gui.cpp
changeset 8012 51288087bccd
parent 7988 6075538f6111
child 8026 269979f5319d
equal deleted inserted replaced
8011:8e95362021d5 8012:51288087bccd
   473 	/* STR_02BD is used to start the string with {BLACK} */
   473 	/* STR_02BD is used to start the string with {BLACK} */
   474 	SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback));
   474 	SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback));
   475 	return DrawStringMultiLine(x, y, STR_02BD, w);
   475 	return DrawStringMultiLine(x, y, STR_02BD, w);
   476 }
   476 }
   477 
   477 
   478 /** Count the number of bits that are set in a mask */
       
   479 static uint CountBits(uint32 mask)
       
   480 {
       
   481 	uint c = 0;
       
   482 	for (; mask != 0; mask >>= 1) if (HASBIT(mask, 0)) c++;
       
   483 	return c;
       
   484 }
       
   485 
       
   486 /** Display list of cargo types of the engine, for the purchase information window */
   478 /** Display list of cargo types of the engine, for the purchase information window */
   487 uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
   479 uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
   488 {
   480 {
   489 	/* List of cargo types of this engine */
   481 	/* List of cargo types of this engine */
   490 	uint32 cmask = EngInfo(engine)->refit_mask;
   482 	uint32 cmask = EngInfo(engine)->refit_mask;
   491 	/* List of cargo types available in this climate */
   483 	/* List of cargo types available in this climate */
   492 	uint32 lmask = _cargo_mask;
   484 	uint32 lmask = _cargo_mask;
   493 	char *b = _userstring;
   485 	char *b = _userstring;
   494 
   486 
   495 	/* Draw nothing if the engine is not refittable */
   487 	/* Draw nothing if the engine is not refittable */
   496 	if (CountBits(cmask) <= 1) return 0;
   488 	if (COUNTBITS(cmask) <= 1) return 0;
   497 
   489 
   498 	b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
   490 	b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
   499 
   491 
   500 	if (cmask == lmask) {
   492 	if (cmask == lmask) {
   501 		/* Engine can be refitted to all types in this climate */
   493 		/* Engine can be refitted to all types in this climate */
   502 		b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
   494 		b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
   503 	} else {
   495 	} else {
   504 		/* Check if we are able to refit to more cargo types and unable to. If
   496 		/* Check if we are able to refit to more cargo types and unable to. If
   505 		 * so, invert the cargo types to list those that we can't refit to. */
   497 		 * so, invert the cargo types to list those that we can't refit to. */
   506 		if (CountBits(cmask ^ lmask) < CountBits(cmask)) {
   498 		if (COUNTBITS(cmask ^ lmask) < COUNTBITS(cmask)) {
   507 			cmask ^= lmask;
   499 			cmask ^= lmask;
   508 			b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
   500 			b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
   509 		}
   501 		}
   510 
   502 
   511 		bool first = true;
   503 		bool first = true;