src/newgrf.cpp
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6878 7d1ff2f621c7
child 10192 195d7f6dcf71
--- a/src/newgrf.cpp	Mon Apr 14 20:32:36 2008 +0000
+++ b/src/newgrf.cpp	Tue Apr 15 00:47:19 2008 +0000
@@ -9,9 +9,8 @@
 #include "openttd.h"
 #include "debug.h"
 #include "fileio.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "spritecache.h"
-#include "station.h"
 #include "sprite.h"
 #include "newgrf.h"
 #include "variables.h"
@@ -26,6 +25,7 @@
 #include "newgrf_house.h"
 #include "newgrf_sound.h"
 #include "newgrf_spritegroup.h"
+#include "newgrf_station.h"
 #include "cargotype.h"
 #include "industry.h"
 #include "newgrf_canal.h"
@@ -2932,13 +2932,19 @@
 		/* Randomized Sprite Group */
 		case 0x80: // Self scope
 		case 0x83: // Parent scope
+		case 0x84: // Relative scope
 		{
-			if (!check_length(bufend - buf, 7, "NewSpriteGroup (Randomized) (1)")) return;
+			if (!check_length(bufend - buf, HasBit(type, 2) ? 8 : 7, "NewSpriteGroup (Randomized) (1)")) return;
 
 			group = AllocateSpriteGroup();
 			group->type = SGT_RANDOMIZED;
 			group->g.random.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
 
+			if (HasBit(type, 2)) {
+				if (feature <= GSF_AIRCRAFT) group->g.random.var_scope = VSG_SCOPE_RELATIVE;
+				group->g.random.count = grf_load_byte(&buf);
+			}
+
 			uint8 triggers = grf_load_byte(&buf);
 			group->g.random.triggers       = GB(triggers, 0, 7);
 			group->g.random.cmp_mode       = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
@@ -3981,6 +3987,10 @@
 			return true;
 		}
 
+		case 0x22: // difficulty level
+			*value = _opt.diff_level;
+			return true;
+
 		default: return false;
 	}
 }
@@ -5070,7 +5080,7 @@
 	} else {
 		/* Attach the label to the end of the list */
 		GRFLabel *l;
-		for (l = _cur_grffile->label; l->next != NULL; l = l->next);
+		for (l = _cur_grffile->label; l->next != NULL; l = l->next) {}
 		l->next = label;
 	}
 
@@ -5798,17 +5808,18 @@
 static void CalculateRefitMasks()
 {
 	for (EngineID engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
+		EngineInfo *ei = &_engine_info[engine];
 		uint32 mask = 0;
 		uint32 not_mask = 0;
 		uint32 xor_mask = 0;
 
-		if (_engine_info[engine].refit_mask != 0) {
+		if (ei->refit_mask != 0) {
 			const GRFFile *file = GetEngineGRF(engine);
 			if (file != NULL && file->cargo_max != 0) {
 				/* Apply cargo translation table to the refit mask */
 				uint num_cargo = min(32, file->cargo_max);
 				for (uint i = 0; i < num_cargo; i++) {
-					if (!HasBit(_engine_info[engine].refit_mask, i)) continue;
+					if (!HasBit(ei->refit_mask, i)) continue;
 
 					CargoID c = GetCargoIDByLabel(file->cargo_list[i]);
 					if (c == CT_INVALID) continue;
@@ -5821,7 +5832,7 @@
 					const CargoSpec *cs = GetCargo(c);
 					if (!cs->IsValid()) continue;
 
-					if (HasBit(_engine_info[engine].refit_mask, cs->bitnum)) SetBit(xor_mask, c);
+					if (HasBit(ei->refit_mask, cs->bitnum)) SetBit(xor_mask, c);
 				}
 			}
 		}
@@ -5852,7 +5863,8 @@
 				}
 			}
 		}
-		_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _cargo_mask;
+
+		ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) & _cargo_mask;
 
 		/* Check if this engine's cargo type is valid. If not, set to the first refittable
 		 * cargo type. Apparently cargo_type isn't a common property... */
@@ -5862,19 +5874,19 @@
 			case VEH_TRAIN: {
 				RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
 				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
-				if (rvi->cargo_type == CT_INVALID) _engine_info[engine].climates = 0;
+				if (rvi->cargo_type == CT_INVALID) ei->climates = 0;
 				break;
 			}
 			case VEH_ROAD: {
 				RoadVehicleInfo *rvi = &_road_vehicle_info[engine - ROAD_ENGINES_INDEX];
 				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
-				if (rvi->cargo_type == CT_INVALID) _engine_info[engine].climates = 0;
+				if (rvi->cargo_type == CT_INVALID) ei->climates = 0;
 				break;
 			}
 			case VEH_SHIP: {
 				ShipVehicleInfo *svi = &_ship_vehicle_info[engine - SHIP_ENGINES_INDEX];
 				if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
-				if (svi->cargo_type == CT_INVALID) _engine_info[engine].climates = 0;
+				if (svi->cargo_type == CT_INVALID) ei->climates = 0;
 				break;
 			}
 		}