343 Station *st = (Station*)object->u.station.st; |
343 Station *st = (Station*)object->u.station.st; |
344 assert(st != NULL); |
344 assert(st != NULL); |
345 st->waiting_triggers = triggers; |
345 st->waiting_triggers = triggers; |
346 } |
346 } |
347 |
347 |
|
348 /** |
|
349 * Station variable cache |
|
350 * This caches 'expensive' station variable lookups which iterate over |
|
351 * several tiles that may be called multiple times per Resolve(). |
|
352 */ |
|
353 static struct { |
|
354 uint32 v40; |
|
355 uint32 v41; |
|
356 uint32 v45; |
|
357 uint32 v46; |
|
358 uint32 v47; |
|
359 uint32 v49; |
|
360 uint8 valid; |
|
361 } _svc; |
348 |
362 |
349 static uint32 StationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
363 static uint32 StationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
350 { |
364 { |
351 const Station *st = object->u.station.st; |
365 const Station *st = object->u.station.st; |
352 TileIndex tile = object->u.station.tile; |
366 TileIndex tile = object->u.station.tile; |
385 return UINT_MAX; |
399 return UINT_MAX; |
386 } |
400 } |
387 |
401 |
388 switch (variable) { |
402 switch (variable) { |
389 /* Calculated station variables */ |
403 /* Calculated station variables */ |
390 case 0x40: return GetPlatformInfoHelper(tile, false, false, false); |
404 case 0x40: |
391 case 0x41: return GetPlatformInfoHelper(tile, true, false, false); |
405 if (!HASBIT(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(tile, false, false, false); SETBIT(_svc.valid, 0); } |
|
406 return _svc.v40; |
|
407 |
|
408 case 0x41: |
|
409 if (!HASBIT(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(tile, true, false, false); SETBIT(_svc.valid, 1); } |
|
410 return _svc.v41; |
|
411 |
392 case 0x42: return GetTerrainType(tile) | (GetRailType(tile) << 8); |
412 case 0x42: return GetTerrainType(tile) | (GetRailType(tile) << 8); |
393 case 0x43: return st->owner; // Station owner |
413 case 0x43: return st->owner; // Station owner |
394 case 0x44: return 2; // PBS status |
414 case 0x44: return 2; // PBS status |
395 case 0x45: return GetRailContinuationInfo(tile); |
415 case 0x45: |
396 case 0x46: return GetPlatformInfoHelper(tile, false, false, true); |
416 if (!HASBIT(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(tile); SETBIT(_svc.valid, 2); } |
397 case 0x47: return GetPlatformInfoHelper(tile, true, false, true); |
417 return _svc.v45; |
|
418 |
|
419 case 0x46: |
|
420 if (!HASBIT(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(tile, false, false, true); SETBIT(_svc.valid, 3); } |
|
421 return _svc.v46; |
|
422 |
|
423 case 0x47: |
|
424 if (!HASBIT(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(tile, true, false, true); SETBIT(_svc.valid, 4); } |
|
425 return _svc.v47; |
|
426 |
398 case 0x48: { // Accepted cargo types |
427 case 0x48: { // Accepted cargo types |
399 CargoID cargo_type; |
428 CargoID cargo_type; |
400 uint32 value = 0; |
429 uint32 value = 0; |
401 |
430 |
402 for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { |
431 for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { |
403 if (st->goods[cargo_type].acceptance) SETBIT(value, cargo_type); |
432 if (st->goods[cargo_type].acceptance) SETBIT(value, cargo_type); |
404 } |
433 } |
405 return value; |
434 return value; |
406 } |
435 } |
407 case 0x49: return GetPlatformInfoHelper(tile, false, true, false); |
436 case 0x49: |
|
437 if (!HASBIT(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(tile, false, true, false); SETBIT(_svc.valid, 5); } |
|
438 return _svc.v49; |
408 |
439 |
409 /* Variables which use the parameter */ |
440 /* Variables which use the parameter */ |
410 /* Variables 0x60 to 0x65 are handled separately below */ |
441 /* Variables 0x60 to 0x65 are handled separately below */ |
411 |
442 |
412 /* General station properties */ |
443 /* General station properties */ |
561 if (group == NULL) return NULL; |
592 if (group == NULL) return NULL; |
562 |
593 |
563 /* Remember the cargo type we've picked */ |
594 /* Remember the cargo type we've picked */ |
564 object->u.station.cargo_type = ctype; |
595 object->u.station.cargo_type = ctype; |
565 |
596 |
|
597 /* Invalidate all cached vars */ |
|
598 _svc.valid = 0; |
|
599 |
566 return Resolve(group, object); |
600 return Resolve(group, object); |
567 } |
601 } |
568 |
602 |
569 SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
603 SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
570 { |
604 { |