(svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
This commit is contained in:
		
							
								
								
									
										4
									
								
								engine.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								engine.c
									
									
									
									
									
								
							| @@ -183,7 +183,7 @@ void StartupEngines(void) | |||||||
| 		uint32 r; | 		uint32 r; | ||||||
|  |  | ||||||
| 		e->age = 0; | 		e->age = 0; | ||||||
| 		e->railtype = ei->railtype_climates >> 4; | 		e->railtype = ei->railtype; | ||||||
| 		e->flags = 0; | 		e->flags = 0; | ||||||
| 		e->player_avail = 0; | 		e->player_avail = 0; | ||||||
|  |  | ||||||
| @@ -217,7 +217,7 @@ void StartupEngines(void) | |||||||
| 		e->lifelength = ei->lifelength + _patches.extend_vehicle_life; | 		e->lifelength = ei->lifelength + _patches.extend_vehicle_life; | ||||||
|  |  | ||||||
| 		// prevent certain engines from ever appearing. | 		// prevent certain engines from ever appearing. | ||||||
| 		if (!HASBIT(ei->railtype_climates, _opt.landscape)) { | 		if (!HASBIT(ei->climates, _opt.landscape)) { | ||||||
| 			e->flags |= ENGINE_AVAILABLE; | 			e->flags |= ENGINE_AVAILABLE; | ||||||
| 			e->player_avail = 0; | 			e->player_avail = 0; | ||||||
| 		} | 		} | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								engine.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								engine.h
									
									
									
									
									
								
							| @@ -70,7 +70,8 @@ typedef struct EngineInfo { | |||||||
| 	byte unk2;              ///< Carriages have the highest bit set in this one | 	byte unk2;              ///< Carriages have the highest bit set in this one | ||||||
| 	byte lifelength; | 	byte lifelength; | ||||||
| 	byte base_life; | 	byte base_life; | ||||||
| 	byte railtype_climates; ///< contains the railtype in the lower four bits, and a mask to the climates where the vehicle is available in the upper four | 	byte railtype:4; | ||||||
|  | 	byte climates:4; | ||||||
| } EngineInfo; | } EngineInfo; | ||||||
|  |  | ||||||
| typedef struct Engine { | typedef struct Engine { | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								newgrf.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								newgrf.c
									
									
									
									
									
								
							| @@ -215,8 +215,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf | |||||||
| 			FOR_EACH_OBJECT { | 			FOR_EACH_OBJECT { | ||||||
| 				uint8 tracktype = grf_load_byte(&buf); | 				uint8 tracktype = grf_load_byte(&buf); | ||||||
|  |  | ||||||
| 				ei[i].railtype_climates &= 0xf; | 				ei[i].railtype = tracktype; | ||||||
| 				ei[i].railtype_climates |= tracktype << 4; |  | ||||||
| 			} | 			} | ||||||
| 		} break; | 		} break; | ||||||
| 		case 0x08: { /* AI passenger service */ | 		case 0x08: { /* AI passenger service */ | ||||||
| @@ -1196,8 +1195,7 @@ static void VehicleChangeInfo(byte *buf, int len) | |||||||
| 						FOR_EACH_OBJECT { | 						FOR_EACH_OBJECT { | ||||||
| 							uint8 climates = grf_load_byte(&buf); | 							uint8 climates = grf_load_byte(&buf); | ||||||
|  |  | ||||||
| 							ei[i].railtype_climates &= 0xf0; | 							ei[i].climates = climates; | ||||||
| 							ei[i].railtype_climates |= climates; |  | ||||||
| 						} | 						} | ||||||
| 					}	break; | 					}	break; | ||||||
| 					case 0x07: { /* Loading speed */ | 					case 0x07: { /* Loading speed */ | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
|   * @param e Rail Type of the vehicle |   * @param e Rail Type of the vehicle | ||||||
|   * @param f Bitmask of the climates |   * @param f Bitmask of the climates | ||||||
|   */ |   */ | ||||||
| #define MK(a,b,c,d,e,f) {a,b,c,d,((e)<<4)|(f)} | #define MK(a, b, c, d, e, f) { a, b, c, d, e, f } | ||||||
| /** Writes the properties of a train carriage into the EngineInfo struct. | /** Writes the properties of a train carriage into the EngineInfo struct. | ||||||
|   * @see EngineInfo |   * @see EngineInfo | ||||||
|   * @param a Introduction date |   * @param a Introduction date | ||||||
| @@ -23,7 +23,7 @@ | |||||||
|   * @param f Bitmask of the climates |   * @param f Bitmask of the climates | ||||||
|   * @note the 0x80 in parameter b sets the "is carriage bit" |   * @note the 0x80 in parameter b sets the "is carriage bit" | ||||||
|   */ |   */ | ||||||
| #define MW(a,b,c,d,e,f) {a,b|0x80,c,d,((e)<<4)|(f)} | #define MW(a, b, c, d, e, f) { a, b | 0x80, c, d, e, f } | ||||||
|  |  | ||||||
| // Rail types | // Rail types | ||||||
| // R = Conventional railway | // R = Conventional railway | ||||||
|   | |||||||
| @@ -409,7 +409,7 @@ static int CDECL VehicleMaxSpeedSorter(const void *a, const void *b) | |||||||
|  |  | ||||||
| // this define is to match engine.c, but engine.c keeps it to itself | // this define is to match engine.c, but engine.c keeps it to itself | ||||||
| // ENGINE_AVAILABLE is used in ReplaceVehicleWndProc | // ENGINE_AVAILABLE is used in ReplaceVehicleWndProc | ||||||
| #define ENGINE_AVAILABLE ((e->flags & 1 && HASBIT(info->railtype_climates, _opt.landscape)) || HASBIT(e->player_avail, _local_player)) | #define ENGINE_AVAILABLE ((e->flags & 1 && HASBIT(info->climates, _opt.landscape)) || HASBIT(e->player_avail, _local_player)) | ||||||
|  |  | ||||||
| /*  if show_outdated is selected, it do not sort psudo engines properly but it draws all engines | /*  if show_outdated is selected, it do not sort psudo engines properly but it draws all engines | ||||||
|  *	if used compined with show_cars set to false, it will work as intended. Replace window do it like that |  *	if used compined with show_cars set to false, it will work as intended. Replace window do it like that | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 tron
					tron