Page 1 of 1
Coding beginner's questions (now: refitted capacity)
Posted: 28 Dec 2005 03:32
by Prebral
I have recently tried to code some new trains and succesfully coded a new loco (not to be released...yet). However, there is always some stuff I do not understand even after consulting wiki...
1) How do you use to determine vehicle costs and running costs if real costs are unknown?
2) What actions and settings are necessary to create a refit for existing engine? I do not need to modify cargo amount at this time (the loco carries nothing), just to make an alternative livery choice.
Posted: 28 Dec 2005 17:41
by Death
1) I won't put this properties until I know the numbers.
2) It's an Action 00, property 1D. (wiki, Action0 for trains)
Re: Coding beginner's questions (now: train costs, refitting
Posted: 28 Dec 2005 20:22
by OzTrans
Prebral wrote: ... What actions and settings are necessary to create a refit for existing engine? I do not need to modify cargo amount at this time (the loco carries nothing), just to make an alternative livery choice.
You cannot refit liveries, if the vehicle (engine) does not carry cargo.
Basically you have 2 choices :
a) you could refit the wagons attached to other liveries and have the engine take on a livery depending on the wagon livery.
b) you could use a random livery selection of the vehicle (engine); the player then buys the vehicle until the wanted livery turns up and then sells the unwanted ones.
Re: Coding beginner's questions (now: train costs, refitting
Posted: 28 Dec 2005 22:13
by Prebral
OzTransLtd wrote:
b) you could use a random livery selection of the vehicle (engine); the player then buys the vehicle until the wanted livery turns up and then sells the unwanted ones.
I will probably try to do it this way, thanks.
Posted: 30 Dec 2005 12:10
by Prebral
I have recently tried to create a random livery (four color versions) of a passenger car. I reverse-engineered CSDCargoSet teaser to understand how it works. However, that file used also loading stages while my wagon does not have any and I probably messed up something in this stage. The vehicle itself works, both grfcodec and Patch report no errors, but I always get only the first livery. Somehow, randomizing action 2 does not work, but action 3 may be messed up too. I suppose there is some problem with cargoIDs, but I was unable to figure it out. Here it the relevant part of the code:
Code: Select all
41 * 11 04 00 1F 01 70 44 4d 20 31 32 00
42 * 41 00 00 0F 01 70 00 00 00 06 01 05 02 0B 00 00 0D 00 0E 00 00 00 00 12 FD 13 00 14 0C 15 00 16 02 17 01 21 03 24 00 09 15 00
43 * 4 01 00 04 08
44 c:\ttdx\codecs\sprites\mdpub.pcx 5 38 01 9 2 -2 -11
45 c:\ttdx\codecs\sprites\mdpub.pcx 14 38 09 9 10 -8 -9
46 c:\ttdx\codecs\sprites\mdpub.pcx 29 38 01 6 14 -7 -6
47 c:\ttdx\codecs\sprites\mdpub.pcx 48 38 09 9 10 -4 -7
48 c:\ttdx\codecs\sprites\mdpub.pcx 63 38 01 9 2 -2 -5
49 c:\ttdx\codecs\sprites\mdpub.pcx 72 38 09 9 10 -12 -6
50 c:\ttdx\codecs\sprites\mdpub.pcx 88 38 01 6 14 -11 -6
51 c:\ttdx\codecs\sprites\mdpub.pcx 107 38 09 9 10 -6 -10
52 c:\ttdx\codecs\sprites\mdpub.pcx 122 38 01 9 2 -2 -11
53 c:\ttdx\codecs\sprites\mdpub.pcx 130 38 09 9 10 -8 -9
54 c:\ttdx\codecs\sprites\mdpub.pcx 145 38 01 6 14 -7 -6
55 c:\ttdx\codecs\sprites\mdpub.pcx 164 38 09 9 10 -4 -7
56 c:\ttdx\codecs\sprites\mdpub.pcx 180 38 01 9 2 -2 -5
57 c:\ttdx\codecs\sprites\mdpub.pcx 187 38 09 9 10 -12 -6
58 c:\ttdx\codecs\sprites\mdpub.pcx 203 38 01 6 14 -11 -6
59 c:\ttdx\codecs\sprites\mdpub.pcx 222 38 09 9 10 -6 -10
60 c:\ttdx\codecs\sprites\mdpub.pcx 237 38 01 9 2 -2 -11
61 c:\ttdx\codecs\sprites\mdpub.pcx 246 38 09 9 10 -8 -9
62 c:\ttdx\codecs\sprites\mdpub.pcx 261 38 01 6 14 -7 -6
63 c:\ttdx\codecs\sprites\mdpub.pcx 280 38 09 9 10 -4 -7
64 c:\ttdx\codecs\sprites\mdpub.pcx 296 38 01 9 2 -2 -5
65 c:\ttdx\codecs\sprites\mdpub.pcx 305 38 09 9 10 -12 -6
66 c:\ttdx\codecs\sprites\mdpub.pcx 321 38 01 6 14 -11 -6
67 c:\ttdx\codecs\sprites\mdpub.pcx 340 38 09 9 10 -6 -10
68 c:\ttdx\codecs\sprites\mdpub.pcx 355 38 01 9 2 -2 -11
69 c:\ttdx\codecs\sprites\mdpub.pcx 364 38 09 9 10 -8 -9
70 c:\ttdx\codecs\sprites\mdpub.pcx 379 38 01 6 14 -7 -6
71 c:\ttdx\codecs\sprites\mdpub.pcx 398 38 09 9 10 -4 -7
72 c:\ttdx\codecs\sprites\mdpub.pcx 414 38 01 9 2 -2 -5
73 c:\ttdx\codecs\sprites\mdpub.pcx 423 38 09 9 10 -12 -6
74 c:\ttdx\codecs\sprites\mdpub.pcx 439 38 01 6 14 -11 -6
75 c:\ttdx\codecs\sprites\mdpub.pcx 458 38 09 9 10 -6 -10
76 * 9 02 00 01 01 01 00 00 00 00
77 * 9 02 00 02 01 01 01 00 00 00
78 * 9 02 00 03 01 01 02 00 00 00
79 * 9 02 00 04 01 01 03 00 00 00
80 * 15 02 00 05 83 00 00 04 01 00 02 00 03 00 04 00
81 * 10 03 00 01 70 01 FF 01 00 01 00
Posted: 30 Dec 2005 12:27
by PikkaBird
Prebral wrote:I suppose there is some problem with cargoIDs
Yes, there is; your action 3 points to 01, rather than 05.
Posted: 30 Dec 2005 12:28
by michael blunck
No wonder, you´re using c-ID "01" (which is just one livery) instead of the random c-ID "5".
Code: Select all
81 * 10 03 00 01 70 01 FF 05 00 05 00
That should work. BTW, notice that "83" randomizes per engine. Use "80" for randomizing per waggon.
regards
Michael
Posted: 30 Dec 2005 12:33
by Prebral
Thank you both, it works now and I even understand how

Posted: 30 Dec 2005 22:59
by OzTrans
BTW, have you noticed, that all your random wagons revert to the first livery while they are being loaded. You need to adjust those action-02s.
Posted: 31 Dec 2005 06:30
by Prebral
I have noticed it yesterday during playtesting. I was not sure how to fill these loading stages bytes when loading stages do not differ from normal graphics...hope it is right now (renumbered):
Code: Select all
109 * 9 02 00 01 01 01 00 00 00 00
110 * 9 02 00 02 01 01 01 00 01 00
111 * 9 02 00 03 01 01 02 00 02 00
112 * 9 02 00 04 01 01 03 00 03 00
113 * 15 02 00 05 83 00 00 04 01 00 02 00 03 00 04 00
Posted: 31 Dec 2005 23:11
by OzTrans
Looks right to me.
BTW, those double set ID's have little to do with loading stages; the first set ID is used when the vehicle is on the move, the second one while it is at a station and being un/loaded. When you get to loading stages, these two are then expanded. Both of them if it is an open wagon (e.g. a coal car), only the second one if it is a closed wagon (e.g. a box car).
Posted: 02 Jan 2006 12:52
by _I_
I´d like to ask, what program is the best, or wich program shall I use for coding. I need a simply program, somethin, where I can just take in the sprites, tell what it is (like if it is a bridge, house, road veh. ...), and the speed, refits, costs, etc. Does something like that exist? Hope you understand me, sorry for my bad english.
Posted: 02 Jan 2006 23:36
by OzTrans
I wrote:... what program is the best, or wich program shall I use for coding. ...
I use a sophisticated text editor, or NotePad. There is no pogram that allows coding without the knowledge of NFO-code.
Posted: 03 Jan 2006 04:07
by DaleStan
Personally, I use
metapad, NFORenum (see .sig), and grfcodec.
I write a file in metapad that will be used to tell grfcodec (and hence, TTDPatch) "what it is (like if it is a bridge, house, road veh. ...), and the speed, refits, costs, etc." I then point NFORenum at the file help ensure that the file is valid, prior to pointing grfcodec at the NFO or TTDPatch at the GRF.
Posted: 04 Jan 2006 07:46
by Prebral
If I set a vehicle to be refittable to some other cargos, do I also have to set refitted capacity for it, or is there some default internal basic calculation?
In other words, if I have a vehicle that can carry X tons of iron ore or 3X tons of coal (based on real world cargo weights) and I do not set refitted capacity callback (which I still cannot understand), will the vehicle always carry exactly X of a cargo no matter what the cargo is?
Posted: 04 Jan 2006 08:16
by DaleStan
Prebral wrote:In other words, if I have a vehicle that can carry X tons of iron ore or 3X tons of coal (based on real world cargo weights) and I do not set refitted capacity callback (which I still cannot understand), will the vehicle always carry exactly X of a cargo no matter what the cargo is?
X units (tons, 1000 liters, bags, head of livestock, &c.) of everything except (IIRC): Passengers (4X passengers), Mail (2X bags), and Goods (2X crates).
To implement a callback check variable 0C, and then use "<value> 80" to return a value where you'd normally put an "<ID> 00"--a pointer to another action 2.
So, "04 80" is a callback return value of four, and "FE 80" is a callback return value of 254.
Returning values greater than 255 is more complex; use "<low> <high>" where low and high are assigned as by the following C code snippet (retval must not exceed 7EFFh (32511)):
Code: Select all
low = retval & 0xFF; // low gets retval's low byte.
high = 0x80 | (retval >> 8) // high gets retval's high byte, but with the high bit set.
The reversal of that is:
Code: Select all
retval = low | ((high & 0x7F) << 8)
So, "01 81" is a callback return of 257 (101h), and "80 FE" is callback return of 32384 (7E80h).