AIVehicle.VehicleType and AITile.TransportType confusions

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

AIVehicle.VehicleType and AITile.TransportType confusions

Post by Xander »

So I'm at the point where I'm trying to replaced a crashed vehicle and I noticed a bit of... awkward duplication. When I want to build the AIDepotList I have to use AITile.TransportType, but surely it'd make more sense to use AIVehicle.VehicleType? I can't imagine many cases where you'd be looking for the depots without a Vehicles information stored somewhere.

At the minute I'm having to switch statement it to translate between the two but if something could be done API side that'd be awesome :)

Or maybe it's something else for the Common.Library?
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by fanioz »

My vehicle has a goto depot order. And I extract information from there. Or you didn't like this approach? :)
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Xander »

fanioz wrote:My vehicle has a goto depot order. And I extract information from there. Or you didn't like this approach? :)
It's not ideal as my vehicles don't have goto depot orders.
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by fanioz »

AIRoad.IsRoadDepotTile.
AIRail.IsRailDepotTile.
AIAirport.IsHangarTile.
AIMarine.IsWaterDepotTile.
Are theese, still not enouh to valuate an AIDepotList ? Or you mean something else?
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Xander »

That's not what I'm trying to do. I want to establish which depot type I should be looking for, given a vehicleID (as in when a vehicle crashes).

Code: Select all

function Engineer::ReplaceVehicle(vehicleid){
	AILog.Info("ENGINEER: Replacing vehicle " + vehicleid);
	
	local depotlist = null;
	
	switch(AIVehicle.GetVehicleType(vehicleid)){
		case AIVehicle.VT_ROAD:
			depotlist = AIDepotList(AITile.TRANSPORT_ROAD);
			break;
		default:
			AILog.Warning("ENGINEER: I can't handle this kind of vehicle");
			return false;
			break;
	}
	//Find the nearest depot to the vehicles starting station
	depotlist.Valuate(AIMap.DistanceManhattan, AIOrder.GetOrderDestination(vehicleid, 0));
	depotlist.KeepBottom(1);
	AIVehicle.StartStopVehicle(AIVehicle.CloneVehicle(depotlist.Begin(), vehicleid, true));
}
It would be nice if the switch statement wasn't needed and I could go straight to

Code: Select all

depotlist = AIDepotList(AIVehice.GetVehicleType(vehicleID));
EDIT: As I said, it's not critical, it's just a Like-to-have
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Dustin »

Xander wrote:So I'm at the point where I'm trying to replaced a crashed vehicle and I noticed a bit of... awkward duplication. When I want to build the AIDepotList I have to use AITile.TransportType, but surely it'd make more sense to use AIVehicle.VehicleType? I can't imagine many cases where you'd be looking for the depots without a Vehicles information stored somewhere.

At the minute I'm having to switch statement it to translate between the two but if something could be done API side that'd be awesome :)

Or maybe it's something else for the Common.Library?

How does you AI crash vehicles in the first place? I don't think mine ever managed it.
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Xander »

Dustin wrote:How does you AI crash vehicles in the first place? I don't think mine ever managed it.
Your AI won't but other players will with their trains...
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
Dustin
Transport Coordinator
Transport Coordinator
Posts: 272
Joined: 07 Dec 2005 19:22

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Dustin »

Xander wrote:
Dustin wrote:How does you AI crash vehicles in the first place? I don't think mine ever managed it.
Your AI won't but other players will with their trains...
Explain? Do you mean players are using exploits to crash the AI's trains? Or do you mean you are playing as the same player and you make an error that crashes trains?
User avatar
Xander
Route Supervisor
Route Supervisor
Posts: 485
Joined: 18 May 2007 12:47
Location: Oxford
Contact:

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Xander »

Dustin wrote:
Xander wrote:
Dustin wrote:How does you AI crash vehicles in the first place? I don't think mine ever managed it.
Your AI won't but other players will with their trains...
Explain? Do you mean players are using exploits to crash the AI's trains? Or do you mean you are playing as the same player and you make an error that crashes trains?
No. I mean using the old "run a train over a road as a vehicle goes over it" crash.
Attachments
Vehicle Crash.PNG
Vehicle Crash.PNG (25.46 KiB) Viewed 2091 times
Real Tycoons do it on Trains!

JAMI: Just Another Moronic Intelligence
User avatar
Abenhor
Engineer
Engineer
Posts: 33
Joined: 08 Jul 2009 20:06
Location: Spain

Re: AIVehicle.VehicleType and AITile.TransportType confusions

Post by Abenhor »

Xander wrote:That's not what I'm trying to do. I want to establish which depot type I should be looking for, given a vehicleID (as in when a vehicle crashes).
It would be nice if the switch statement wasn't needed and I could go straight to

Code: Select all

depotlist = AIDepotList(AIVehice.GetVehicleType(vehicleID));
I think you can, as things are for now, but maybe a developer would say what is planned for the future...
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests