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
Labels
component: AI/Game script (squirrel) enhancement flyspray good first issue

Comments

@DorpsGek
Copy link
Member

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
@DorpsGek DorpsGek added flyspray enhancement labels Apr 7, 2018
@andythenorth andythenorth added component: AI/Game script (squirrel) and removed Script labels Apr 13, 2018
@TrueBrain
Copy link
Member

TrueBrain commented Apr 14, 2018

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

@TrueBrain TrueBrain added good first issue enhancement and removed enhancement from FlySpray labels Apr 14, 2018
@fanioz
Copy link

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 pushed a commit to aekruijssen/OpenTTD that referenced this issue Jul 7, 2019
@LordAro LordAro closed this as completed in 6f28a0c Jul 7, 2019
douiwby pushed a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
spnda pushed 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
Labels
component: AI/Game script (squirrel) enhancement flyspray good first issue
Projects
None yet
Development

No branches or pull requests

4 participants