Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Thu Jun 20, 2013 12:19 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Fri Jun 08, 2012 2:49 pm 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Sep 28, 2004 4:01 pm
Posts: 202
Hello,
following the NML tutorial, the tram part specifically, I can see that when you have different capacities for the different articulated parts you have to deal with it a bit differently.

The problem I have is that when the capacity is not a multiple of the number of articulated parts (8/3), I will get a "rounding error" in the purchase display (I expect to get 8 but get 6 instead). It works fine for the real vehicle capacity.
There is any way to fix this without changing the capacity of the vehicle? How?

This is the part of the code related to the issue:
Code:
switch (FEAT_ROADVEHS, SELF, switch_capacity_trailer_3, position_in_consist ) {
   3: return 8;
   1..2: return 0;
   return 0; //default
}
Code:
cargo_capacity:  8/3;

graphics {
      cargo_capacity:      switch_capacity_trailer_3;
      purchase_cargo_capacity: purchase_TRUCK_TRAILER_03; //purchase sprite

_________________
Image

Pipelines for the people! PIPE


Top
 Profile  
 
PostPosted: Fri Jun 08, 2012 2:53 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
No, there's no fix for that.

It's easiest to change your capacity to be a multiple of the amount of vehicle parts.

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
PostPosted: Fri Jun 08, 2012 4:29 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Sun Jan 27, 2008 1:02 pm
Posts: 298
Or alternatively, use a different item / vehicle ID for the trailers.

_________________
Create your own NewGRF? Check out this tutorial!


Top
 Profile  
 
PostPosted: Sat Jun 09, 2012 7:57 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Mar 31, 2007 2:23 pm
Posts: 3207
Location: Standing by the jams
Do you know the vehicle's correct capacity in advance? If so you can simply set that as the value for the purchase cargo capacity.

That's often not so easy as it sounds, e.g. vehicles are templated, or use some method for setting variable capacity etc.

BANDIT and HEQS both solve this issue. If you need more help, post here....

_________________
Want to help OTTD development? Here's the official list of bitesize patches needed: http://wiki.openttd.org/Todo_list

FIRS Industry Replacement Set (Released)
HEQS Heavy Equipment Set (trucks, industrial trams and more) (Finished)
FISH is Ships (Released)
CHIPS Has Improved Players' Stations (Finished)


Top
 Profile  
 
PostPosted: Sat Jun 09, 2012 12:39 pm 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Sep 28, 2004 4:01 pm
Posts: 202
andythenorth wrote:
Do you know the vehicle's correct capacity in advance? If so you can simply set that as the value for the purchase cargo capacity.
Setting the purchase cargo capacity directly seems to multiply the number I put there for the number of articulated parts :?

_________________
Image

Pipelines for the people! PIPE


Top
 Profile  
 
PostPosted: Sat Jun 09, 2012 4:35 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Mar 31, 2007 2:23 pm
Posts: 3207
Location: Standing by the jams
Paste all your code for this vehicle here, I'll have a look

_________________
Want to help OTTD development? Here's the official list of bitesize patches needed: http://wiki.openttd.org/Todo_list

FIRS Industry Replacement Set (Released)
HEQS Heavy Equipment Set (trucks, industrial trams and more) (Finished)
FISH is Ships (Released)
CHIPS Has Improved Players' Stations (Finished)


Top
 Profile  
 
PostPosted: Sun Jun 10, 2012 4:38 pm 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Sep 28, 2004 4:01 pm
Posts: 202
Here is the code, nevertheless setting the "trailer" as a independent vehicle (without climate availability) and then linking it in the articulated_part callback seems enough.

Code:
switch (FEAT_ROADVEHS, SELF, switch_length_horse_3, position_in_consist) {
    2: return 6;
   1: return 5;
    return 5;
}

switch (FEAT_ROADVEHS, SELF, switch_capacity_trailer_horse_3, position_in_consist ) {
    2: return 8;
   1: return 0;
    return 0; //default
}


/* START: item_TRUCK_MAIL_TRAILER_03*/

switch (FEAT_ROADVEHS, SELF, switch_spriteset_TRUCK_MAIL_HORSE_03, position_in_consist ) {
   2: spriteset_MAIL_TRAILER_HORSE;
   1: random_switch_spriteset_2HORSE; //default
    random_switch_spriteset_2HORSE; //default
}

switch (FEAT_ROADVEHS, SELF, switch_articulated_TRUCK_MAIL_HORSE_03, extra_callback_info1) {
    1..2: return item_TRUCK_MAIL_HORSE_03; //use same vehicle for all parts
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS; //stop adding vehicle parts
}

/* Define the road vehicle */
item(FEAT_ROADVEHS, item_TRUCK_MAIL_HORSE_03, 67) {
    property {
        /* Properties common to all vehicle types */
        name:                           string(STR_NAME_TRUCK_MAIL_HORSE_03);
        climates_available:             enable_horses == 1 && general_enable != 1 ? ALL_CLIMATES : NO_CLIMATE;   
        introduction_date:              date(1700,01,01);
        model_life:                     220;
        vehicle_life:                   25;
        reliability_decay:              32;
      CARGOBLOCK_MAIL
        loading_speed:                  5;
        cost_factor:                    33;
        running_cost_factor:            32;

        /* RV-specific properties */
        sprite_id:                      SPRITE_ID_NEW_ROADVEH; //enable new graphics
        speed:                          16 mph;
        misc_flags:                     bitmask(ROADVEH_FLAG_2CC);
        refit_cost:                     0; // Refitting is free
        running_cost_base:              RUNNING_COST_ROADVEH;
        power:                          10 hp;
        weight:                         1 ton;
      default_cargo_type:            MAIL;
        cargo_capacity:                   9/3;
        sound_effect:                   SOUND_HORSE;
    }
   
    /* Define graphics */
    graphics {
      articulated_part:   switch_articulated_TRUCK_MAIL_HORSE_03;
      length:            switch_length_horse_3;
      cargo_capacity:      switch_capacity_trailer_horse_3;
      purchase_cargo_capacity: purchase_TRUCK_MAIL_HORSE_03; //force cargo capacity property is used instead
      purchase:          purchase_TRUCK_MAIL_HORSE_03;
        default:          switch_spriteset_TRUCK_MAIL_HORSE_03;   
    }
}
/* END: item_TRUCK_MAIL_HORSE_03 */

_________________
Image

Pipelines for the people! PIPE


Top
 Profile  
 
PostPosted: Sun Jun 10, 2012 6:32 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Mar 31, 2007 2:23 pm
Posts: 3207
Location: Standing by the jams
LaDoncella wrote:
Here is the code, nevertheless setting the "trailer" as a independent vehicle (without climate availability) and then linking it in the articulated_part callback seems enough.

Yes, the easiest way to solve this is to use a different vehicle for each part that has different properties. There are plenty of vehicle IDs to do this with. :wink:

_________________
Want to help OTTD development? Here's the official list of bitesize patches needed: http://wiki.openttd.org/Todo_list

FIRS Industry Replacement Set (Released)
HEQS Heavy Equipment Set (trucks, industrial trams and more) (Finished)
FISH is Ships (Released)
CHIPS Has Improved Players' Stations (Finished)


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 12:23 am 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Sep 28, 2004 4:01 pm
Posts: 202
Thanks.

Related to articulated vehicles it seems that any weight given to the trailers/asrticulated parts are ignored. Is this normal/intended ?

_________________
Image

Pipelines for the people! PIPE


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 5:01 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Mar 31, 2007 2:23 pm
Posts: 3207
Location: Standing by the jams
Yes, weight (and power) are ignored for trailing parts of articulated vehicles.
EDIT: weight should be zero for trailing parts.

The solution is to apply the total weight / power for the consist to the lead vehicle.

This makes for 'interesting' code :) I've solved it for things like:
- trams where every vehicle can be powered, but the tram can be refitted to different lengths
- articulated trucks with variable number of trailers

You can set weight with cb36, which can be useful for cases like variable number of trailers.
You can also (iirc) do maths when setting a property in nml, so you can make the total weight a calculation summing the weight of each part (might be easier to read).

For BANDIT I use a python build script + templating to handle all this stuff. It's more complicated to setup than plain nml, but easier overall.

_________________
Want to help OTTD development? Here's the official list of bitesize patches needed: http://wiki.openttd.org/Todo_list

FIRS Industry Replacement Set (Released)
HEQS Heavy Equipment Set (trucks, industrial trams and more) (Finished)
FISH is Ships (Released)
CHIPS Has Improved Players' Stations (Finished)


Last edited by andythenorth on Thu Jun 14, 2012 6:33 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 6:12 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Wed Dec 20, 2006 1:31 pm
Posts: 692
Location: Aschaffenburg
Note, that if andy says that "weight" is ignored for articulated parts, that does not mean that you should assign a random value or no value to it.

http://newgrf-specs.tt-wiki.net/wiki/NML:Vehicles

The specs list what to do for properties of articulated parts. For "weight" it says "=0", which means you should set it to zero for all articulated parts.
The reason behind this is that, if one day OpenTTD/TTDPatch learn about weight of articulated parts a value of zero would keep your GRF unaffected, while other values would randomly break it.

_________________
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁


Top
 Profile  
 
PostPosted: Fri Jun 15, 2012 12:13 pm 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Sep 28, 2004 4:01 pm
Posts: 202
Thanks both of you, I will keep this in mind.

_________________
Image

Pipelines for the people! PIPE


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000-2013 phpBB Group

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2013.
Hosted by Zernebok Hosting.