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

AI: wagons are lost in depot because of lack of API feature #5685

Closed
DorpsGek opened this issue Jul 30, 2013 · 2 comments
Closed

AI: wagons are lost in depot because of lack of API feature #5685

DorpsGek opened this issue Jul 30, 2013 · 2 comments

Comments

@DorpsGek
Copy link

@DorpsGek DorpsGek commented Jul 30, 2013

krinn opened the ticket and wrote:

There's simply no feature to get a vehicle that isn't made of a train engine.

Every tricks i tried fail :
- AIVehicleList_Depot : list only vehicle with orders for the depot, and of course wagons have no orders
- AIVehicleList_DefaultGroup : they aren't in the list
- AIVehicleList : they aren't in the list
...

Out of all functions i tried, none answer a valid vehicle ID and just all list as just empty.

You can handle that in the game by taking great care this never happen (that you loose the vehicle ID of the newly create wagon), else you're dead.

But there a race condition you cannot avoid : create wagon if user save before you attach it to an engine or before you sell it : you're dead, on next loading you don't have the vehicleID and it's now impossible to get it.

Results :
- wagons stays in the depot and you don't know it
- there's no way you could remove the depot, as wagons are in it.
- depot cannot be switch to another rail type depot.
- And of course, plenty weirdness as the AI is getting mad trying to figure out what's going on there :)

Reported version: Version?
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/5685
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Apr 14, 2018

How evil! I guess a function to list unconnected wagons or something is not the worst idea :D

@fanioz
Copy link

@fanioz fanioz commented Jun 15, 2018

I found on script_vehicle.cpp, a free wagon is valid vehicle :

/* static */ bool ScriptVehicle::IsValidVehicle(VehicleID vehicle_id)
{
	const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id);
	return v != NULL && (v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
}

Can we implement that in "ScriptVehicleList" , so that AI/GS VehicleList will include those free wagon ID?

ScriptVehicleList::ScriptVehicleList()
{
	const Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		if ((v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()))) this->AddItem(v->index);
	}
}
@andythenorth andythenorth added stale and removed stale labels Jan 7, 2019
aekruijssen added a commit to aekruijssen/OpenTTD that referenced this issue Jun 5, 2019
…ure:Added free wagon check in ScriptVehicleList
aekruijssen added a commit to aekruijssen/OpenTTD that referenced this issue Jun 5, 2019
…ure:Added free wagon check in ScriptVehicleList
aekruijssen added a commit to aekruijssen/OpenTTD that referenced this issue Jun 5, 2019
aekruijssen added a commit to aekruijssen/OpenTTD that referenced this issue Jun 5, 2019
aekruijssen added a commit to aekruijssen/OpenTTD that referenced this issue Jun 5, 2019
LordAro added a commit to aekruijssen/OpenTTD that referenced this issue Jul 7, 2019
@LordAro LordAro closed this in 6f28a0c Jul 7, 2019
douiwby added a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
spnda added a commit to spnda/OpenTTD that referenced this issue Jun 17, 2020
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
4 participants
You can’t perform that action at this time.