Industry Confusion

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
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Industry Confusion

Post by reylas »

Another question. I have decided to start playing with transporting some industries, and I have run into a little issue. At first I wanted to just transport some coal between stations, but remembered that with NewGRF, CargoID' could be overwritten. No problem then, I would start and develop something that handles that possibility. But here is my problem. How do you determine what kind of vehicle to use to deliver a CargoID from station to station?

For instance, the only CargoID I could find was for bulk. But that could be Coal or Ore, which use different vehicles and are accepted by very different locations. How do I determine the different bulk items? I do not want to look at the label, as that would cause more problems in the future.

What am I not seeing? I am sure I am overlooking it.

Thanks,
MarkS
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Industry Confusion

Post by Yexo »

You can use AIEngine.CanRefitCargo (EngineID engine_id, CargoID cargo_id)
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Industry Confusion

Post by reylas »

Yexo wrote:You can use AIEngine.CanRefitCargo (EngineID engine_id, CargoID cargo_id)

But would the CargoID of Coal and Ore be the same? That is what is throwing me.

enum AICargo::CargoClass

The classes of cargo (from newgrf_cargo.h).

Enumerator:
CC_PASSENGERS Passengers.
CC_MAIL Mail.
CC_EXPRESS Express cargo (Goods, Food, Candy, but also possible for passengers).
CC_ARMOURED Armoured cargo (Valuables, Gold, Diamonds).
CC_BULK Bulk cargo (Coal, Grain etc., Ores, Fruit).
CC_PIECE_GOODS Piece goods (Livestock, Wood, Steel, Paper).
CC_LIQUID Liquids (Oil, Water, Rubber).
CC_REFRIGERATED Refrigerated cargo (Food, Fruit).
CC_HAZARDOUS Hazardous cargo (Nucleair Fuel, Explosives, etc.).
CC_COVERED Covered/Sheltered Freight (Transporation in Box Vans, Silo Wagons, etc.).

Thanks,
MarkS.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Industry Confusion

Post by Yexo »

You're confusing CargoClass and CargoID now. See http://devs.openttd.org/~noai/aidocs/classAICargo.html for CargoClass (the same list as you posted, but from the NoAI documentation). You can check whether a cargo is in a cargoclass with AICargo.HasCargoClass (CargoID cargo_type, CargoClass cargo_class). CargoID's are unique, there is exactly one CargoID per cargo in game. There can be multiple cargos with the same cargoclass, such as both coal (cargoid = 1) and ore (cargoid = something else) are in the CC_BULK cargo class.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Industry Confusion

Post by reylas »

Yexo wrote:You're confusing CargoClass and CargoID now. See http://devs.openttd.org/~noai/aidocs/classAICargo.html for CargoClass (the same list as you posted, but from the NoAI documentation). You can check whether a cargo is in a cargoclass with AICargo.HasCargoClass (CargoID cargo_type, CargoClass cargo_class). CargoID's are unique, there is exactly one CargoID per cargo in game. There can be multiple cargos with the same cargoclass, such as both coal (cargoid = 1) and ore (cargoid = something else) are in the CC_BULK cargo class.
Oh, ok.. I get it now. This paragraph is exactly what I needed. I had already looked at the NoAI documentation, but I was not making the distinction between CargoClass and CargoID. So I will never care that it is coal, only that a station produces or accepts a cargoID. I may be hauling mulch as far as I know, only that it is a cargo.

So may I ask as to the significance of CargoClass? Why would one care what class a cargo is? Is it safe to assume that if two cargoID's are in the same class, the vehicle can be retrofit?

And If I wanted to say start a coal trucking company (the area I live in is full of them) the only way to find coal cargo is to *search* on the cargo label?

Thanks Yexo, you have helped me a lot.

MarkS
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: Industry Confusion

Post by Finaldeath »

The CargoClass was introduced, as far as I'm aware, because of the need to at least distinguish passengers exactly - due to the separation of bus stations and truck stations on road transport, and because they are a "special case" generated by towns. The other categories are general categories too, and you could always add in some form of personality which decides to only want certain categories of stuff :)
Finaldeath
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Industry Confusion

Post by TrueBrain »

reylas wrote: (..) So may I ask as to the significance of CargoClass? Why would one care what class a cargo is? Is it safe to assume that if two cargoID's are in the same class, the vehicle can be retrofit?
People wanted a simple way to get all CargoIDs belonging to passengers, so we made a general function for that .. but as always, where one person sees the use, the other things it is utterly useless ;)
reylas wrote: And If I wanted to say start a coal trucking company (the area I live in is full of them) the only way to find coal cargo is to *search* on the cargo label? (..)
Don't. There is no promise a label is like it is. Also, you want your AI to work on other climates, don't you? :) So simply, don't. You can either use the CargoClass to get an idea of the type of cargo (I personally don't see how it can be useful), or you can use the AICargo::GetCargoIncome() to get the best cargo to transport, which is what I would advise to do :)

Good luck!
The only thing necessary for the triumph of evil is for good men to do nothing.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Industry Confusion

Post by reylas »

TrueLight wrote:
reylas wrote: (..) So may I ask as to the significance of CargoClass? Why would one care what class a cargo is? Is it safe to assume that if two cargoID's are in the same class, the vehicle can be retrofit?
People wanted a simple way to get all CargoIDs belonging to passengers, so we made a general function for that .. but as always, where one person sees the use, the other things it is utterly useless ;)
reylas wrote: And If I wanted to say start a coal trucking company (the area I live in is full of them) the only way to find coal cargo is to *search* on the cargo label? (..)
Don't. There is no promise a label is like it is. Also, you want your AI to work on other climates, don't you? :) So simply, don't. You can either use the CargoClass to get an idea of the type of cargo (I personally don't see how it can be useful), or you can use the AICargo::GetCargoIncome() to get the best cargo to transport, which is what I would advise to do :)

Good luck!
Thanks. That is what I assumed. The only need for it would be if someone decided they wanted to make a coal shipping company, but that is only personal preference nothing that should be supported per say. I only asked the question to try to get a better understanding of the Industry side.

All three of you have given me enough to understand what I need to and I thank you for it. The big problem was not seeing the distinction between CargoID and CargoClass. That helps tremendously.

Thanks,
MarkS
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 18 guests