Skip to main content
Topic: Patch: making stops public also transfer goods (Read 3706 times) previous topic - next topic

Patch: making stops public also transfer goods

When joining with public halts, the goods at the public halts get lost. This patch fixes this.

Code: [Select]
Index: simhalt.cc
===================================================================
--- simhalt.cc (revision 2489)
+++ simhalt.cc (working copy)
@@ -1772,6 +1772,9 @@
  add_grund(gr);
  // and check for existence
  if(!halt->existiert_in_welt()) {
+ // transfer goods from halt to self
+ halt->transfer_goods(self);
+
  destroy(halt);
  }
  }
@@ -1780,6 +1783,23 @@
  recalc_station_type();
 }
 
+void haltestelle_t::transfer_goods(halthandle_t halt)
+{
+ if (!self.is_bound() || !halt.is_bound()) {
+ return;
+ }
+ // transfer goods
+ for(uint8 i=0; i<warenbauer_t::get_max_catg_index(); i++) {
+ vector_tpl<ware_t> * warray = waren[i];
+ if (warray) {
+ for(uint32 j=0; j<warray->get_count(); j++) {
+ halt->add_ware_to_halt( (*warray)[j] );
+ }
+ delete waren[i];
+ waren[i] = NULL;
+ }
+ }
+}
 
 
 /*
Index: simhalt.h
===================================================================
--- simhalt.h (revision 2489)
+++ simhalt.h (working copy)
@@ -478,6 +478,13 @@
  uint32 liefere_an(ware_t ware);
  uint32 starte_mit_route(ware_t ware);
 
+ /*
+ * transfers all goods to given station
+ *
+ * @author Dwachs
+ */
+ void transfer_goods(halthandle_t halt);
+
  /**
  * wird von Fahrzeug aufgerufen, wenn dieses an der Haltestelle
  * gehalten hat.

Parsley, sage, rosemary, and maggikraut.

Re: Patch: making stops public also transfer goods

Reply #1
Since this is called at exactly one location, I would use direct this code.


Re: Patch: making stops public also transfer goods

Reply #3
Since this is called at exactly one location, I would use direct this code.
Then however, the waren-variable has to be declared public, otherwise there is no chance for the new stop to get the goods of the joined stop.
Parsley, sage, rosemary, and maggikraut.

Re: Patch: making stops public also transfer goods

Reply #4
I think it's better to put this code in an extra function even though it's only used in one location:
- If the same method is used in future, it's already a function and you haven't to search it in the code.
- It increases readability of the code, since you haven't to read 10 lines, but only the statement "transfer goods", and you know what this line does - or should do ;)

[idea]
How about a new tool: joining two (own) adjacent stops? This could be realized with the code, which makes a stop public.
[/idea]

Re: Patch: making stops public also transfer goods

Reply #5
Gerw,

that seems like a very useful idea :-)
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.

Re: Patch: making stops public also transfer goods

Reply #6
It isn't in the game already? :o Of course supported... that might be very useful, although I can't imagine when - but it seems logical to enable this.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: Patch: making stops public also transfer goods

Reply #7
No. If you build two separate stops only some tiles away and connect them afterwards (e.g. if they "grow"). Then you get two adjacent halts.

Edit: By reading the code I think the change in r2492 doesn't work. It would remove also all goods from the halt ("delete waren").

 

Re: Patch: making stops public also transfer goods

Reply #8
yes, you are right. It now transfers goods from self to self and deletes them afterwards, the transfer however should go from halt to self. Should be fixed in 2494.
Parsley, sage, rosemary, and maggikraut.