Skip to content

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

Closed

Description

@DorpsGek

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

Activity

  1. TrueBrain commented on Apr 14, 2018

    @TrueBrain
    Member

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

  2. fanioz commented on Jun 15, 2018

    @fanioz

    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);
    	}
    }
    
  3. added
    staleStale issues
    and removed
    staleStale issues
    on Jan 7, 2019
  4. added 5 commits that reference this issue on Jun 5, 2019
    afbc679
    4f25799
    c945c39
    ce6349d
    6cd5b61
  5. added a commit that references this issue on Jul 7, 2019
    e9a117c
  6. added 2 commits that reference this issue on Jul 7, 2019
    55fca73
    9026736
  7. added a commit that references this issue on Apr 16, 2020
    d8cfe59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: AI/Game script (squirrel)This issue is related to Squirrel (Scripting language)enhancementIssue would be a good enhancement; we accept Pull Requests!flysprayThis issue is imported from FlySpray (https://bugs.openttd.org/)good first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions