402 const Station *st = object->u.station.st; |
402 const Station *st = object->u.station.st; |
403 const StationSpec *statspec = object->u.station.statspec; |
403 const StationSpec *statspec = object->u.station.statspec; |
404 uint set; |
404 uint set; |
405 |
405 |
406 uint cargo = 0; |
406 uint cargo = 0; |
407 CargoID cargo_type = CT_INVALID; /* XXX Pick the correct cargo type */ |
407 CargoID cargo_type = object->u.station.cargo_type; |
408 |
408 |
409 if (st == NULL || statspec->sclass == STAT_CLASS_WAYP) { |
409 if (st == NULL || statspec->sclass == STAT_CLASS_WAYP) { |
410 return group->g.real.loading[0]; |
410 return group->g.real.loading[0]; |
411 } |
411 } |
412 |
412 |
413 if (cargo_type == CT_INVALID) { |
413 switch (cargo_type) { |
414 for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { |
414 case GC_INVALID: |
415 cargo += GB(st->goods[cargo_type].waiting_acceptance, 0, 12); |
415 case GC_DEFAULT_NA: |
416 } |
416 case GC_PURCHASE: |
417 } else { |
417 cargo = 0; |
418 cargo = GB(st->goods[cargo_type].waiting_acceptance, 0, 12); |
418 break; |
|
419 |
|
420 case GC_DEFAULT: |
|
421 for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { |
|
422 cargo += GB(st->goods[cargo_type].waiting_acceptance, 0, 12); |
|
423 } |
|
424 break; |
|
425 |
|
426 default: |
|
427 cargo = GB(st->goods[_local_cargo_id_ctype[cargo_type]].waiting_acceptance, 0, 12); |
|
428 break; |
419 } |
429 } |
420 |
430 |
421 if (HASBIT(statspec->flags, 1)) cargo /= (st->trainst_w + st->trainst_h); |
431 if (HASBIT(statspec->flags, 1)) cargo /= (st->trainst_w + st->trainst_h); |
422 cargo = min(0xfff, cargo); |
432 cargo = min(0xfff, cargo); |
423 |
433 |
455 res->last_value = 0; |
465 res->last_value = 0; |
456 res->trigger = 0; |
466 res->trigger = 0; |
457 res->reseed = 0; |
467 res->reseed = 0; |
458 } |
468 } |
459 |
469 |
|
470 static const SpriteGroup *ResolveStation(const StationSpec *statspec, const Station *st, ResolverObject *object) |
|
471 { |
|
472 const SpriteGroup *group; |
|
473 CargoID ctype = GC_DEFAULT_NA; |
|
474 |
|
475 if (st == NULL) { |
|
476 /* No station, so we are in a purchase list */ |
|
477 ctype = GC_PURCHASE; |
|
478 } else { |
|
479 CargoID cargo; |
|
480 |
|
481 /* Pick the first cargo that we have waiting */ |
|
482 for (cargo = 0; cargo < NUM_GLOBAL_CID; cargo++) { |
|
483 CargoID lcid = _local_cargo_id_ctype[cargo]; |
|
484 if (lcid != CT_INVALID && statspec->spritegroup[cargo] != NULL && GB(st->goods[lcid].waiting_acceptance, 0, 12) != 0) { |
|
485 ctype = cargo; |
|
486 break; |
|
487 } |
|
488 } |
|
489 } |
|
490 |
|
491 group = statspec->spritegroup[ctype]; |
|
492 if (group == NULL) { |
|
493 ctype = GC_DEFAULT; |
|
494 group = statspec->spritegroup[ctype]; |
|
495 } |
|
496 |
|
497 if (group == NULL) return NULL; |
|
498 |
|
499 /* Remember the cargo type we've picked */ |
|
500 object->u.station.cargo_type = ctype; |
|
501 |
|
502 return Resolve(group, object); |
|
503 } |
460 |
504 |
461 SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
505 SpriteID GetCustomStationRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
462 { |
506 { |
463 const SpriteGroup *group; |
507 const SpriteGroup *group; |
464 ResolverObject object; |
508 ResolverObject object; |
465 CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA; |
|
466 |
509 |
467 NewStationResolver(&object, statspec, st, tile); |
510 NewStationResolver(&object, statspec, st, tile); |
468 |
511 |
469 group = Resolve(statspec->spritegroup[ctype], &object); |
512 group = ResolveStation(statspec, st, &object); |
470 if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT_NA) { |
|
471 group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object); |
|
472 } |
|
473 if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT) { |
|
474 group = Resolve(statspec->spritegroup[GC_DEFAULT], &object); |
|
475 } |
|
476 |
|
477 if (group == NULL || group->type != SGT_RESULT) return 0; |
513 if (group == NULL || group->type != SGT_RESULT) return 0; |
478 |
|
479 return group->g.result.sprite - 0x42D; |
514 return group->g.result.sprite - 0x42D; |
480 } |
515 } |
481 |
516 |
482 |
517 |
483 SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
518 SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile) |
484 { |
519 { |
485 const SpriteGroup *group; |
520 const SpriteGroup *group; |
486 ResolverObject object; |
521 ResolverObject object; |
487 CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA; |
|
488 |
522 |
489 NewStationResolver(&object, statspec, st, tile); |
523 NewStationResolver(&object, statspec, st, tile); |
490 object.callback_param1 = 1; /* Indicate we are resolving the ground sprite */ |
524 object.callback_param1 = 1; /* Indicate we are resolving the ground sprite */ |
491 |
525 |
492 group = Resolve(statspec->spritegroup[ctype], &object); |
526 group = ResolveStation(statspec, st, &object); |
493 if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT_NA) { |
|
494 group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object); |
|
495 } |
|
496 if ((group == NULL || group->type != SGT_RESULT) && ctype != GC_DEFAULT) { |
|
497 group = Resolve(statspec->spritegroup[GC_DEFAULT], &object); |
|
498 } |
|
499 if ((group == NULL || group->type != SGT_RESULT)) { |
|
500 group = Resolve(statspec->groundgroup, &object); |
|
501 } |
|
502 |
|
503 if (group == NULL || group->type != SGT_RESULT) return 0; |
527 if (group == NULL || group->type != SGT_RESULT) return 0; |
504 |
|
505 return group->g.result.sprite - 0x42D; |
528 return group->g.result.sprite - 0x42D; |
506 } |
529 } |
507 |
530 |
508 |
531 |
509 uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile) |
532 uint16 GetStationCallback(uint16 callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile) |
510 { |
533 { |
511 const SpriteGroup *group; |
534 const SpriteGroup *group; |
512 ResolverObject object; |
535 ResolverObject object; |
513 CargoID ctype = (st == NULL) ? GC_PURCHASE : GC_DEFAULT_NA; |
|
514 |
536 |
515 NewStationResolver(&object, statspec, st, tile); |
537 NewStationResolver(&object, statspec, st, tile); |
516 |
538 |
517 object.callback = callback; |
539 object.callback = callback; |
518 object.callback_param1 = param1; |
540 object.callback_param1 = param1; |
519 object.callback_param2 = param2; |
541 object.callback_param2 = param2; |
520 |
542 |
521 group = Resolve(statspec->spritegroup[ctype], &object); |
543 group = ResolveStation(statspec, st, &object); |
522 if ((group == NULL || group->type != SGT_CALLBACK) && ctype != GC_DEFAULT_NA) { |
|
523 group = Resolve(statspec->spritegroup[GC_DEFAULT_NA], &object); |
|
524 } |
|
525 if ((group == NULL || group->type != SGT_CALLBACK) && ctype != GC_DEFAULT) { |
|
526 group = Resolve(statspec->spritegroup[GC_DEFAULT], &object); |
|
527 } |
|
528 |
|
529 if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
544 if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
530 |
|
531 return group->g.callback.result; |
545 return group->g.callback.result; |
532 } |
546 } |
533 |
547 |
534 |
548 |
535 /** |
549 /** |