News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

Xref issues and bridges

Started by jamespetts, December 30, 2014, 12:26:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jamespetts

I am currently working on a system to allow for bridges being upgraded to other bridges of the same type for Experimental. The idea is that the cost of "upgrading" the bridge is much lower where the only difference between the two bridges is the type of road surface/rail/etc. on top of them rather than the actual structure of the bridge, to simulate replacing the way on top of the bridge without replacing the bridge itself. To do this, I am trying to use a system where bridges define other bridges to which they can upgrade. I have previously done something similar for vehicles which has worked without much difficulty using the same xref system as is used for the coupling constraints (nachfolger and vorganger), adapting the makeobj and vehicle_reader.cc code.

However, I cannot seem to get the same system to work for bridges: I get access violations on the code trying to read the icon image (wkz->set_icon( besch->get_cursor()->get_bild_nr(1) ); in void brueckenbauer_t::register_besch(bruecke_besch_t *besch)). I have already added the line obj_for_xref(get_type(), besch->get_name(), data); in void bridge_reader_t::register_obj(obj_besch_t *&data), and this has not helped.

Does anyone know what other steps that I need to take in order to allow bridges (and in due course tunnels) to work with the xref system in this way? I should be most grateful for any help.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Dwachs

You cannot access the other bridge in register_obj. That is, the xref's are not resolved at this point. Other than this I cannot say anything helpful.
Parsley, sage, rosemary, and maggikraut.

jamespetts

#2
How do bridges differ from vehicles in this respect?

Edit: I suppose that the other option is not to use xrefs at all, and just use abstract groupings.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Ters

Quote from: jamespetts on December 30, 2014, 01:48:59 PM
How do bridges differ from vehicles in this respect?

As far as I know, the xref i vehikel_besch_t are only used during play. At the time register_obj is called, not only isn't xrefs resolved, the object referred to might not be loaded yet.

prissi

If xrefs work that early, then this is pure luck, since it depends on loading order.

jamespetts

Happily, I have managed now to deal with the issue in another way without requiring xrefs.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.