vehicles and orders?
Moderator: OpenTTD Developers
-
- Engineer
- Posts: 70
- Joined: 05 Jun 2008 15:51
vehicles and orders?
I have questions about vehicles and orders:
- is it possible to get the current order that a vehicle is executing?
- is there a way to determine whether a vehicle is stopped by the AIVehicle.StartStopVehicle command?
- is it possible to get the current order that a vehicle is executing?
- is there a way to determine whether a vehicle is stopped by the AIVehicle.StartStopVehicle command?
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Re: vehicles and orders?
Not as far as I know.wilco_moerman wrote:I have questions about vehicles and orders:
- is it possible to get the current order that a vehicle is executing?
I don;t know if this is exactly what you mean, but you could try...- is there a way to determine whether a vehicle is stopped by the AIVehicle.StartStopVehicle command?
Code: Select all
local isStopped = AIVehicle.GetCurrentSpeed(vehicle_id) == 0 && !AIVehicle.IsStoppedInDepot(vehicle_id);
PathZilla - A networking AI - Now with tram support.
-
- Engineer
- Posts: 70
- Joined: 05 Jun 2008 15:51
Re: vehicles and orders?
hmm, but a human player does have access to that kind of information. Same goes for "first truck at .... station". There is no event for that occasion in the noai framework.Zutty wrote:Not as far as I know.wilco_moerman wrote:I have questions about vehicles and orders:
- is it possible to get the current order that a vehicle is executing?
I was thinking along the same lines, but it occurred to me that a vehicle that is stopped at a station would also yield TRUE this way. And I can't find a way to detect if a vehicle is stopped at a station.I don;t know if this is exactly what you mean, but you could try...- is there a way to determine whether a vehicle is stopped by the AIVehicle.StartStopVehicle command?
Code: Select all
local isStopped = AIVehicle.GetCurrentSpeed(vehicle_id) == 0 && !AIVehicle.IsStoppedInDepot(vehicle_id);
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Re: vehicles and orders?
The current order will be a usefull addition to the framework, for the first vehicle at ... station event, see the wiki:wilco_moerman wrote:hmm, but a human player does have access to that kind of information. Same goes for "first truck at .... station". There is no event for that occasion in the noai framework.Zutty wrote:Not as far as I know.wilco_moerman wrote:I have questions about vehicles and orders:
- is it possible to get the current order that a vehicle is executing?
http://wiki.openttd.org/index.php/AI:TODO wrote: Events
* Arriving of vehicles at stations (for the first time)
Re: vehicles and orders?
We CAN do that, but its a little long winded...wilco_moerman wrote:I was thinking along the same lines, but it occurred to me that a vehicle that is stopped at a station would also yield TRUE this way. And I can't find a way to detect if a vehicle is stopped at a station.
Code: Select all
local isVehicleAtStation = AIStation.IsValidStation(AIStation.GetStationID(AIVehicle.GetLocation(vehicle_id)));
local isStopped = AIVehicle.GetCurrentSpeed(vehicle_id) == 0
&& !AIVehicle.IsStoppedInDepot(vehicle_id)
&& !isVehicleAtStation;
PathZilla - A networking AI - Now with tram support.
Re: vehicles and orders?
That doesn't always work, because a vehicle could be stopped on a station tile, so it's not a foolproof solution.Zutty wrote:We CAN do that, but its a little long winded...wilco_moerman wrote:I was thinking along the same lines, but it occurred to me that a vehicle that is stopped at a station would also yield TRUE this way. And I can't find a way to detect if a vehicle is stopped at a station.
Code: Select all
local isVehicleAtStation = AIStation.IsValidStation(AIStation.GetStationID(AIVehicle.GetLocation(vehicle_id))); local isStopped = AIVehicle.GetCurrentSpeed(vehicle_id) == 0 && !AIVehicle.IsStoppedInDepot(vehicle_id) && !isVehicleAtStation;
Re: vehicles and orders?
Not sure I quite follow you. Do you mean stopped at station that it isn't loading at? Perhaps if a bus breaks down in a DTRS?Yexo wrote:That doesn't always work, because a vehicle could be stopped on a station tile, so it's not a foolproof solution.Zutty wrote:We CAN do that, but its a little long winded...wilco_moerman wrote:I was thinking along the same lines, but it occurred to me that a vehicle that is stopped at a station would also yield TRUE this way. And I can't find a way to detect if a vehicle is stopped at a station.
Code: Select all
local isVehicleAtStation = AIStation.IsValidStation(AIStation.GetStationID(AIVehicle.GetLocation(vehicle_id))); local isStopped = AIVehicle.GetCurrentSpeed(vehicle_id) == 0 && !AIVehicle.IsStoppedInDepot(vehicle_id) && !isVehicleAtStation;
PathZilla - A networking AI - Now with tram support.
Re: vehicles and orders?
Vehicle != Road VehicleZutty wrote:Not sure I quite follow you. Do you mean stopped at station that it isn't loading at? Perhaps if a bus breaks down in a DTRS?
Last edited by Ralph on 15 Jun 2008 16:42, edited 1 time in total.
Re: vehicles and orders?
Not sure I quite follow you. Do you mean stopped at station that it isn't loading at? Perhaps if a bus breaks down in a DTRS?[/quote]Zutty wrote:That doesn't always work, because a vehicle could be stopped on a station tile, so it's not a foolproof solution....
The ai could've stopped the vehicle earlier using AIVehicle.StartStopVehicle while it was on a station tile. Read your own code again:
Code: Select all
local isVehicleAtStation = AIStation.IsValidStation(AIStation.GetStationID(AIVehicle.GetLocation(vehicle_id)));
Re: vehicles and orders?
Oh yes I see.Yexo wrote:This sets isVehicleAtStation to true when the vehicle is manually stopped on a station tile.
PathZilla - A networking AI - Now with tram support.
-
- Engineer
- Posts: 70
- Joined: 05 Jun 2008 15:51
Re: vehicles and orders?
isn't it possible to just add a AIVehicle.vehicleIsStopped(...) or a vehicleIsRunning(...) method to the noai framework? I figure that the vehicles are probably just simple finite state machines or just have one simple variable "stopped" or whatever, so my guess would be it can't be that hard?
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Re: vehicles and orders?
The devs are generally very helpful when it comes to adding new features. This one sounds fair enough to me.wilco_moerman wrote:isn't it possible to just add a AIVehicle.vehicleIsStopped(...) or a vehicleIsRunning(...) method to the noai framework? I figure that the vehicles are probably just simple finite state machines or just have one simple variable "stopped" or whatever, so my guess would be it can't be that hard?
PathZilla - A networking AI - Now with tram support.
-
- Engineer
- Posts: 70
- Joined: 05 Jun 2008 15:51
Re: vehicles and orders?
my sollution for now is, to make a new class MyVehicle that has a field aiVehicle where I store the reference to a AIVehicle, and a boolean isStopped. I just rerout all commands to the AIVehicle through MyVehicle, and store whether I have stopped or started the vehicle. But this obviously only works if the AI the only one that actually stops or starts vehicles, and there are no function in the game that do so autonomously.Zutty wrote:The devs are generally very helpful when it comes to adding new features. This one sounds fair enough to me.wilco_moerman wrote:isn't it possible to just add a AIVehicle.vehicleIsStopped(...) or a vehicleIsRunning(...) method to the noai framework? I figure that the vehicles are probably just simple finite state machines or just have one simple variable "stopped" or whatever, so my guess would be it can't be that hard?
Making a wrapper around AIVehicle also has other advantages: I can use java style programming.
Code: Select all
class MyVehicle {
aiVehicle = null;
//
//extra information
isStopped = true;
//
//initialize
constructor(_aiVehicle) {
aiVehicle = _aiVehicle;
isStopped = true;
}
//
//one static method needed for construction
static function BuildVehicle(depot, type) {
local vehicle = MyVehicle(AIVehicle.BuildVehicle(depot,type));
//do some initializing or registering or whatever
return vehicle;
}
//
//non-static methods for easy access
function GetName() {return AIVehicle.GetName(this.aiVehicle);}
//
function start() {
if (stopped) {
stopped = false;
AIVehicle.StartStopVehicle(this.aiVehicle);
}
else AILog.Warning(this + " is already running (invalid start() command");
}
//etc.
}//end class MyVehicle
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Re: vehicles and orders?
I will add those two functions for the TODO:
AIVehicle.GetVehicleStatus(), which returns: STOPPED, BROKEN, RUNNING, IN_DEPOT, or something similar
AIOrder.GetCurrentOrder(), or something similar, returning the current OrderID.
AIVehicle.GetVehicleStatus(), which returns: STOPPED, BROKEN, RUNNING, IN_DEPOT, or something similar
AIOrder.GetCurrentOrder(), or something similar, returning the current OrderID.
The only thing necessary for the triumph of evil is for good men to do nothing.
Who is online
Users browsing this forum: No registered users and 3 guests