vehicle_gui.c
changeset 1859 870dcb6fd65b
parent 1802 da61740cc1e7
child 1891 862800791170
equal deleted inserted replaced
1858:3aa257df0e04 1859:870dcb6fd65b
   163 	else
   163 	else
   164 		ormod = PALETTE_TO_GREEN;
   164 		ormod = PALETTE_TO_GREEN;
   165 	DrawSprite(SPR_BLOT | ormod, x, y);
   165 	DrawSprite(SPR_BLOT | ormod, x, y);
   166 }
   166 }
   167 
   167 
   168 /** Draw the list of available refit options.
   168 /** Draw the list of available refit options for a consist.
   169  * Draw the list and highlight the selected refit option (if any)
   169  * Draw the list and highlight the selected refit option (if any)
   170  * @param *v vehicle(type) to get the refit-options of
   170  * @param *v first vehicle in consist to get the refit-options of
   171  * @param sel selected refit cargo-type in the window
   171  * @param sel selected refit cargo-type in the window
   172  * @return the cargo type that is hightlighted, CT_INVALID if none
   172  * @return the cargo type that is hightlighted, CT_INVALID if none
   173  */
   173  */
   174 CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel)
   174 CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel)
   175 {
   175 {
   176 	uint32 cmask;
   176 	uint32 cmask;
   177 	CargoID cid, cargo = CT_INVALID;
   177 	CargoID cid, cargo = CT_INVALID;
   178 	int y = 25;
   178 	int y = 25;
       
   179 	const Vehicle* u;
   179 #define show_cargo(ctype) { \
   180 #define show_cargo(ctype) { \
   180 		byte colour = 16; \
   181 		byte colour = 16; \
   181 		if (sel == 0) { \
   182 		if (sel == 0) { \
   182 			cargo = ctype; \
   183 			cargo = ctype; \
   183 			colour = 12; \
   184 			colour = 12; \
   185 		sel--; \
   186 		sel--; \
   186 		DrawString(6, y, _cargoc.names_s[ctype], colour); \
   187 		DrawString(6, y, _cargoc.names_s[ctype], colour); \
   187 		y += 10; \
   188 		y += 10; \
   188 }
   189 }
   189 
   190 
   190 		/* Check if engine has custom refit or normal ones, and get its bitmasked value.
   191 		/* Check if vehicle has custom refit or normal ones, and get its bitmasked value.
   191 		 * Now just and it with the bitmasked available cargo on the current landscape, and
   192 		 * If its a train, 'or' this with the refit masks of the wagons. Now just 'and'
   192 		* where the bits are set: those are available */
   193 		 * it with the bitmask of available cargo on the current landscape, and
   193 		cmask = (_engine_refit_masks[v->engine_type] != 0) ? _engine_refit_masks[v->engine_type] : _default_refitmasks[v->type - VEH_Train];
   194 		 * where the bits are set: those are available */
       
   195 		cmask = 0;
       
   196 		u = v;
       
   197 		do {
       
   198 			if (_engine_refit_masks[u->engine_type] != 0) { // newgrf custom refit mask
       
   199 				cmask |= _engine_refit_masks[u->engine_type];
       
   200 			} else if (u->cargo_cap != 0) {
       
   201 				// rail wagons cant be refitted by default
       
   202 				if (v->type != VEH_Train || !(RailVehInfo(u->engine_type)->flags & RVI_WAGON))
       
   203 					cmask |= _default_refitmasks[v->type - VEH_Train];
       
   204 			}
       
   205 			u = u->next;
       
   206 		} while (v->type == VEH_Train && u != NULL);
       
   207 
   194 		cmask &= _landscape_global_cargo_mask[_opt_ptr->landscape];
   208 		cmask &= _landscape_global_cargo_mask[_opt_ptr->landscape];
   195 
   209 
   196 		/* Check which cargo has been selected from the refit window and draw list */
   210 		/* Check which cargo has been selected from the refit window and draw list */
   197 		for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
   211 		for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
   198 			if (HASBIT(cmask, 0)) // vehicle is refittable to this cargo
   212 			if (HASBIT(cmask, 0)) // vehicle is refittable to this cargo