Page 1 of 1

Problems with coding refit cycle

Posted: 16 Jun 2008 08:10
by Wile E. Coyote
New problems... :(

I tried to code refit cycle. I set in Action 0 cargo to passengers and in refit mask passengers only. I defined D0 strings for cargo subtype and used this code:

Code: Select all

  109 * 9	  02 01 00 01 01 00 00 00 00
  110 * 9	  02 01 01 01 01 01 00 01 00
  111 * 18	 02 01 10 81 F2 00 FF 02 30 FF 00 00 31 FF 01 01 FF FF
//Var. F2 (refit cycle) - text: use text D0 30 for first option and D0 31 for second option
  112 * 14	 02 01 11 81 F2 00 FF 01 01 00 01 01 00 00
//Var. F2 (refit cycle) - graphics: use c-ID 01 for second option, else use c-ID 00
  113 * 18	 02 01 20 81 10 00 FF 02 49 FF 01 02 0E FF 03 03 11 00 // set sound effects
  114 * 18	 02 01 21 81 0C 00 FF 02 20 00 33 33 10 00 19 19 11 00
//use c-ID 20 for sound callback and c-ID 10 for cargo subtype display callback
  115 * 7	  03 01 01 47 00 21 00
In refit menu appears only "Passengers", not two rows with two texts. Also, you can refit vehicle once, livery changes, twice, livery changes again, and you can't refit it anymore. Where is mistake?

Re: Problems with coding refit cycle

Posted: 16 Jun 2008 10:09
by michael blunck
How does your action0 look like? Did you set the bit for CB19 (cargo subtype)?

regards
Michael

Re: Problems with coding refit cycle

Posted: 16 Jun 2008 10:41
by Wile E. Coyote
No! I forgot to set it! Thanx, Michael! :D

But second problem appears: I want to make refit to articulated or non-articulated vehicle. Code now looks like this:

Code: Select all

  109 * 9	  02 01 00 01 01 00 00 00 00
//tram graphics
  110 * 9	  02 01 01 01 01 01 00 01 00
//trailer graphics
  111 * 14	 02 01 02 81 0C 00 FF 01 03 FF 11 11 00 00
//shortened tram, c-id 02
  112 * 14	 02 01 03 81 0C 00 FF 01 03 FF 11 11 01 00
//shortened trailer, c-id 03

  113 * 18	 02 01 10 81 10 00 FF 02 49 FF 01 02 0E FF 03 03 02 00
//sound effects, else use c-id 02
  114 * 14	 02 01 11 81 0C 00 FF 01 10 00 33 33 02 00
//callback for tram without trailer, else use c-id 02; this is c-id 11

  115 * 14	 02 01 20 81 41 00 01 01 02 00 00 00 03 00
//sprite layout
  116 * 14	 02 01 21 81 10 00 FF 01 47 FF 01 01 FF FF
//build articulated vehicle for ID 47
  117 * 18	 02 01 22 81 10 00 FF 02 49 FF 01 02 0E FF 03 03 20 00
//sound effects, else use sprite layout
  118 * 18	 02 01 23 81 0C 00 FF 02 21 00 16 16 22 00 33 33 20 00
//callback for tram with trailer, else use sprite layout; this is c-id 23

  119 * 18	 02 01 30 81 F2 00 FF 02 30 FF 00 00 31 FF 01 01 FF FF
//texts cycle
  120 * 14	 02 01 31 81 F2 00 FF 01 23 00 01 01 11 00
//second in refit cycle is c-id 23, else use c-id 11

  121 * 14	 02 01 40 81 0C 00 FF 01 30 00 19 19 31 00
//use texts cycle 30 to display texts, else use refit cycle
  122 * 7	  03 01 01 47 00 40 00
//assign c-id 40 to ID 47
Texts are displayed, but in both cases is shown only non-articulated vehicle. I set bits for: length, building articulated vehicle, showing suffix text and sound effects (that is sum B2 in hex). I tried with setting bit for refitted capacity, but nothing is changed. Where is mistake now?

Re: Problems with coding refit cycle

Posted: 16 Jun 2008 13:02
by PikkaBird
You cannot create or destroy articulated parts on the fly; the articulation callback is run only once when the vehicle is bought.

Re: Problems with coding refit cycle

Posted: 16 Jun 2008 13:16
by Wile E. Coyote
I was affraid of that...

I used fake trailer to display tram without trailer:

Code: Select all

  110 * 9	  02 01 00 01 01 00 00 00 00
//tram
  111 * 9	  02 01 01 01 01 01 00 01 00
//trailer
  112 * 14	 02 01 02 81 0C 00 FF 01 03 FF 11 11 00 00
//shortened tram, c-id 02
  113 * 14	 02 01 03 81 0C 00 FF 01 03 FF 11 11 01 00
//shortened trailer, c-id 03
  114 * 4	  01 01 01 01
  115 c:\igre\ttwin95\sprites/srvttw.pcx 178 104 09 1 1 0 0
  116 * 9	  02 01 04 01 01 00 00 00 00
//fake trailer
  117 * 14	 02 01 05 81 0C 00 FF 01 08 FF 11 11 04 00
//shortened fake trailer, c-id 05
  118 * 14	 02 01 10 81 41 00 01 01 02 00 00 00 05 00
//sprite layout (tram + fake trailer)
  119 * 14	 02 01 11 81 10 00 FF 01 47 FF 01 01 FF FF
//build one more vehicle with ID 47
  120 * 18	 02 01 13 81 0C 00 FF 02 11 00 16 16 22 FF 15 15 10 00
//callbacks: build articulated vehicle, set refitted capacity, else sprite layout, c-id 13
  121 * 14	 02 01 20 81 41 00 01 01 02 00 00 00 03 00
//sprite layout (tram + trailer)
  122 * 14	 02 01 21 81 10 00 FF 01 47 FF 01 01 FF FF
//build one more vehicle with ID 47
  123 * 18	 02 01 23 81 0C 00 FF 02 21 00 16 16 44 FF 15 15 20 00
//callbacks: build articulated vehicle, set refitted capacity, else sprite layout, c-id 13
  124 * 18	 02 01 30 81 F2 00 FF 02 30 FF 00 00 31 FF 01 01 FF FF
//text cycle
  125 * 14	 02 01 31 81 F2 00 FF 01 23 00 01 01 13 00
//vehicles cycle
  126 * 18	 02 01 39 81 10 00 FF 02 49 FF 01 02 0E FF 03 03 4A FF
//sound effects
  127 * 18	 02 01 40 81 0C 00 FF 02 30 00 19 19 39 00 33 33 31 00
//callbacks: cargo sub-type cycle, sound effects, else vehicles cycle
  128 * 7	  03 01 01 47 00 40 00//assign c-id 40 to ID 47
Of course, I set bit for refitted capacity in Action 0 as well. But when I click on refit, Patch crashes without crashlog. Did I make mistake, or I wish impossible thing again, or it's bug in Patch?
(With OTTD there is no crash, but all capacities, even in buy list, are doubled.)

Re: Problems with coding refit cycle

Posted: 16 Jun 2008 19:53
by DaleStan
Wile E. Coyote wrote:Patch crashes without crashlog. Did I make mistake,
You mean, besides failing to follow the instructions in my signature?

Re: Problems with coding refit cycle

Posted: 17 Jun 2008 07:05
by Wile E. Coyote
Does that question means that code is OK? I was convinced I did something impossible again. :) Here is debug. Configs are also attached. Maybe could help: callback does not crash Patch. Setting bit for refitting callback is enough. I had to run debug in TTD window mode because when I run it in fullscreen computer totally hangs.

Re: Problems with coding refit cycle

Posted: 18 Jun 2008 03:29
by DaleStan
OK, I found the crash, but I'd rather not try to fix it blind. Chances are that the NFO is valid. Please post a test GRF.

The significant detail is that there be at least two vehicles in the consist for which the bit for CB15 is set.

Re: Problems with coding refit cycle

Posted: 18 Jun 2008 06:06
by Wile E. Coyote
OK, here is test GRF. ID which caused crash is 47 (named Les Ateliers Métallurgiques in game). Open refit list and click on any of two refit options. Patch crashes in that moment.

EDIT: Attachment removed. Download new attachment below.

Re: Problems with coding refit cycle

Posted: 18 Jun 2008 17:56
by Lakie
What refit values should we be getting, currently I get 17 (default), 68 for a single trailer and 136 for two trailers.

~ Lakie

Re: Problems with coding refit cycle

Posted: 18 Jun 2008 22:36
by Lakie
Having looked at the grf and debugging it seems like you are trying to spoof the refit code, so that both vehicles return 34 for one trailer and two trailers return 68, so basically 34 per part, however with articulated road vehicles like trains it loops through all parts of the articulated road vehicle getting the total cargo of the refit (which is the correct behaviour), so it acts like multiplying the cargo amount by 2. :o

~ Lakie

Re: Problems with coding refit cycle

Posted: 19 Jun 2008 06:24
by Wile E. Coyote
I'm trying to obtain 34 for first (with fake trailer) and 68 for second, so I put 17 for default but obtained double double capacity. :?
EDIT: But it's not big problem, I just changed refitted capacities and obtained desired values. Bigger problems are becoming runaway trailers and total desintegrating of 5-part consist. Here is GRF for testing. Pay attention on tram which appears in 2007 (CROTRAM TMK 2200). Vehicle we discussed about has trailer problems too.

Re: Problems with coding refit cycle

Posted: 19 Jun 2008 15:53
by Lakie
Then simply returning 17 for the first instance and 34 for both would work, you need to remeber that like train articulated units it adds the cargo of the whole articulated consist, though this shouldn't be anything new to you.

As for the trams breaking up, I am aware that trams are by far more likely to breakup than plain articulated road vehicles, not sure what this is down too to be honest, although I do remember something about poor alignment causing more frequent breakups from previous testing a year or so ago with Steven (not sure how that works though). Also to cover all possibilities I recommend with shortened vehicles you do not go under 3/8's as I remember train consists explode under that value as well.

~ Lakie

Re: Problems with coding refit cycle

Posted: 24 Jun 2008 09:01
by Wile E. Coyote
Unfortunately, neither limiting vehicle shortening (I used 3/8 as shortest) haven't solved breaking problem. Strange thing is that first articulated vehicle (horse tram) is working properly, maybe because there was no shortening? I'll investigate further and inform you about what I obtained.

Thanx everybody for help! :bow:

EDIT: I investigated consist desintegration and spotted that shortening vehicle for minimum 3/8 causes breaking. 2/8 is working good. (Train vehicles are working good even with smaller length.) But this is not discussion under this topic, refitting is solved. :bow: So desintegrating we could discuss in original thread. This thread maybe could be locked?