Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetCargoProduction on Company HQ returns 0 for PASS/MAIL, but on TileLoop it does produce cargo #7697

Closed
SamuXarick opened this issue Aug 16, 2019 · 0 comments

Comments

@SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Aug 16, 2019

Version of OpenTTD

Expected result

According to town_cmd.cpp, AITile.GetCargoProduction should return +1 for PASS and MAIL for each HQ tile.

OpenTTD/src/town_cmd.cpp

Lines 654 to 679 in f0aea2d

static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced)
{
HouseID house_id = GetHouseType(tile);
const HouseSpec *hs = HouseSpec::Get(house_id);
Town *t = Town::GetByTile(tile);
if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
for (uint i = 0; i < 256; i++) {
uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile);
if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break;
CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grf_prop.grffile);
if (cargo == CT_INVALID) continue;
produced[cargo]++;
}
} else {
if (hs->population > 0) {
produced[CT_PASSENGERS]++;
}
if (hs->mail_generation > 0) {
produced[CT_MAIL]++;
}
}
}

Actual result

AITile.GetCargoProduction returns +0 for PASS and MAIL for each HQ tile. AddProducedCargo_Object simply does not exist.

OpenTTD/src/object_cmd.cpp

Lines 832 to 847 in f0aea2d

extern const TileTypeProcs _tile_type_object_procs = {
DrawTile_Object, // draw_tile_proc
GetSlopePixelZ_Object, // get_slope_z_proc
ClearTile_Object, // clear_tile_proc
AddAcceptedCargo_Object, // add_accepted_cargo_proc
GetTileDesc_Object, // get_tile_desc_proc
GetTileTrackStatus_Object, // get_tile_track_status_proc
ClickTile_Object, // click_tile_proc
AnimateTile_Object, // animate_tile_proc
TileLoop_Object, // tile_loop_proc
ChangeTileOwner_Object, // change_tile_owner_proc
nullptr, // add_produced_cargo_proc
nullptr, // vehicle_enter_tile_proc
GetFoundation_Object, // get_foundation_proc
TerraformTile_Object, // terraform_tile_proc
};

But on TileLoop_Object, PASS and MAIL is produced.

OpenTTD/src/object_cmd.cpp

Lines 575 to 613 in f0aea2d

static void TileLoop_Object(TileIndex tile)
{
const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
if (spec->flags & OBJECT_FLAG_ANIMATION) {
Object *o = Object::GetByTile(tile);
TriggerObjectTileAnimation(o, tile, OAT_TILELOOP, spec);
if (o->location.tile == tile) TriggerObjectAnimation(o, OAT_256_TICKS, spec);
}
if (IsTileOnWater(tile)) TileLoop_Water(tile);
if (!IsObjectType(tile, OBJECT_HQ)) return;
/* HQ accepts passenger and mail; but we have to divide the values
* between 4 tiles it occupies! */
/* HQ level (depends on company performance) in the range 1..5. */
uint level = GetCompanyHQSize(tile) + 1;
assert(level < 6);
StationFinder stations(TileArea(tile, 2, 2));
uint r = Random();
/* Top town buildings generate 250, so the top HQ type makes 256. */
if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
uint amt = GB(r, 0, 8) / 8 / 4 + 1;
if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
MoveGoodsToStation(CT_PASSENGERS, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations());
}
/* Top town building generates 90, HQ can make up to 196. The
* proportion passengers:mail is about the same as in the acceptance
* equations. */
if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
uint amt = GB(r, 8, 8) / 8 / 4 + 1;
if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
MoveGoodsToStation(CT_MAIL, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations());
}
}

Steps to reproduce

SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Nov 3, 2019
On TileLoop_Object, HQs are able to produce and move passengers and mail to stations, but querying the HQ tiles for cargo supplied was returning nothing. This makes it so that they return +1 to both passengers and mail.
@LordAro LordAro closed this in 3d362f2 Nov 10, 2019
douiwby added a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
On TileLoop_Object, HQs are able to produce and move passengers and mail to stations, but querying the HQ tiles for cargo supplied was returning nothing. This makes it so that they return +1 to both passengers and mail.
spnda added a commit to spnda/OpenTTD that referenced this issue Jun 17, 2020
On TileLoop_Object, HQs are able to produce and move passengers and mail to stations, but querying the HQ tiles for cargo supplied was returning nothing. This makes it so that they return +1 to both passengers and mail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.