station_cmd.c
changeset 2967 4208a82bf0d9
parent 2952 6a26eeda9679
child 2989 99c95a3ebcaa
equal deleted inserted replaced
2966:7f382cfeb93d 2967:4208a82bf0d9
  1194 	} while (TileBelongsToRailStation(st, t) && (_m[t].m5 & 1) == dir);
  1194 	} while (TileBelongsToRailStation(st, t) && (_m[t].m5 & 1) == dir);
  1195 
  1195 
  1196 	return len - 1;
  1196 	return len - 1;
  1197 }
  1197 }
  1198 
  1198 
  1199 static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg, const Station *st)
       
  1200 {
       
  1201 	switch (spg->type) {
       
  1202 		case SGT_REAL:
       
  1203 			return &spg->g.real;
       
  1204 
       
  1205 		case SGT_DETERMINISTIC: {
       
  1206 			const DeterministicSpriteGroup *dsg = &spg->g.determ;
       
  1207 			SpriteGroup *target;
       
  1208 			int value = -1;
       
  1209 
       
  1210 			if ((dsg->variable >> 6) == 0) {
       
  1211 				/* General property */
       
  1212 				value = GetDeterministicSpriteValue(dsg->variable);
       
  1213 			} else {
       
  1214 				if (st == NULL) {
       
  1215 					/* We are in a build dialog of something,
       
  1216 					 * and we are checking for something undefined.
       
  1217 					 * That means we should get the first target
       
  1218 					 * (NOT the default one). */
       
  1219 					if (dsg->num_ranges > 0) {
       
  1220 						target = dsg->ranges[0].group;
       
  1221 					} else {
       
  1222 						target = dsg->default_group;
       
  1223 					}
       
  1224 					return ResolveStationSpriteGroup(target, NULL);
       
  1225 				}
       
  1226 
       
  1227 				/* Station-specific property. */
       
  1228 				if (dsg->var_scope == VSG_SCOPE_PARENT) {
       
  1229 					/* TODO: Town structure. */
       
  1230 
       
  1231 				} else /* VSG_SELF */ {
       
  1232 					if (dsg->variable == 0x40 || dsg->variable == 0x41) {
       
  1233 						/* FIXME: This is ad hoc only
       
  1234 						 * for waypoints. */
       
  1235 						value = 0x01010000;
       
  1236 					} else {
       
  1237 						/* TODO: Only small fraction done. */
       
  1238 						// TTDPatch runs on little-endian arch;
       
  1239 						// Variable is 0x70 + offset in the TTD's station structure
       
  1240 						switch (dsg->variable - 0x70) {
       
  1241 							case 0x80: value = st->facilities;             break;
       
  1242 							case 0x81: value = st->airport_type;           break;
       
  1243 							case 0x82: value = st->truck_stops->status;    break;
       
  1244 							case 0x83: value = st->bus_stops->status;      break;
       
  1245 							case 0x86: value = st->airport_flags & 0xFFFF; break;
       
  1246 							case 0x87: value = st->airport_flags & 0xFF;   break;
       
  1247 							case 0x8A: value = st->build_date;             break;
       
  1248 						}
       
  1249 					}
       
  1250 				}
       
  1251 			}
       
  1252 
       
  1253 			target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group;
       
  1254 			return ResolveStationSpriteGroup(target, st);
       
  1255 		}
       
  1256 
       
  1257 		default:
       
  1258 		case SGT_RANDOMIZED:
       
  1259 			error("I don't know how to handle random spritegroups yet!");
       
  1260 			return NULL;
       
  1261 	}
       
  1262 }
       
  1263 
       
  1264 uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype)
       
  1265 {
       
  1266 	const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
       
  1267 
       
  1268 	if (rsg->sprites_per_set != 0) {
       
  1269 		if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
       
  1270 		if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
       
  1271 	}
       
  1272 
       
  1273 	error("Custom station 0x%08x::0x%02x has no sprites associated.",
       
  1274 		spec->grfid, spec->localidx);
       
  1275 	/* This is what gets subscribed of dtss->image in newgrf.c,
       
  1276 	 * so it's probably kinda "default offset". Try to use it as
       
  1277 	 * emergency measure. */
       
  1278 	return SPR_RAIL_PLATFORM_Y_FRONT;
       
  1279 }
       
  1280 
       
  1281 static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
  1199 static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
  1282 {
  1200 {
  1283 	int w,h;
  1201 	int w,h;
  1284 	int32 cost;
  1202 	int32 cost;
  1285 
  1203