1
From 72359f80fb81c039a2f3e14acff11a6056b27a28 Mon Sep 17 00:00:00 2001
2
From: Dwachs <dwachs@gmx.net>
3
Date: Fri, 11 Mar 2011 09:16:26 +0000
4
Subject: [PATCH 2/3] FIX loading of savegames with line with id=0
6
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@4358 8aca7d54-2c30-db11-9de9-000461428c89
8
simconvoi.cc | 11 ++++++++---
9
simline.cc | 14 ++++++++++++--
10
simlinemgmt.cc | 23 +++++++++++++++++++++--
11
simlinemgmt.h | 8 ++++++++
12
tpl/quickstone_tpl.h | 5 ++++-
13
5 files changed, 53 insertions(+), 8 deletions(-)
15
diff --git a/simconvoi.cc b/simconvoi.cc
16
index fa6ddf1..9499a84 100644
19
@@ -353,9 +353,14 @@ DBG_MESSAGE("convoi_t::laden_abschliessen()","state=%s, next_stop_index=%d", sta
22
DBG_MESSAGE("convoi_t::laden_abschliessen()","next_stop_index=%d", next_stop_index );
23
- if( line.is_bound() ) {
24
- linehandle_t new_line = line;
25
- if ( !fpl->matches( welt, line->get_schedule() ) ) {
27
+ linehandle_t new_line = line;
28
+ if( !new_line.is_bound() ) {
29
+ // if there is a line with id=0 in the savegame try to assign cnv to this line
30
+ new_line = get_besitzer()->simlinemgmt.get_line_with_id_zero();
32
+ if( new_line.is_bound() ) {
33
+ if ( !fpl->matches( welt, new_line->get_schedule() ) ) {
34
// 101 version produced broken line ids => we have to find our line the hard way ...
35
vector_tpl<linehandle_t> lines;
36
get_besitzer()->simlinemgmt.get_lines(fpl->get_type(), &lines);
37
diff --git a/simline.cc b/simline.cc
38
index 1d10047..042e196 100644
41
@@ -49,7 +49,10 @@ simline_t::simline_t(karte_t* welt, spieler_t* sp, linetype type, loadsave_t *fi
43
// now self has the right id but the this-pointer is not assigned to the quickstone handle yet
45
- self = linehandle_t(this, self.get_id());
46
+ // some savegames have line_id=0, resolve that in laden_abschliessen
47
+ if (self.get_id()!=0) {
48
+ self = linehandle_t(this, self.get_id());
53
@@ -85,8 +88,9 @@ void simline_t::create_schedule()
55
void simline_t::add_convoy(convoihandle_t cnv)
57
- if (line_managed_convoys.empty()) {
58
+ if (line_managed_convoys.empty() && self.is_bound()) {
59
// first convoi -> ok, now we can announce this connection to the stations
60
+ // unbound self can happen during loading if this line had line_id=0
64
@@ -225,6 +229,12 @@ void simline_t::rdwr(loadsave_t *file)
66
void simline_t::laden_abschliessen()
68
+ if( !self.is_bound() ) {
69
+ // get correct handle
70
+ self = sp->simlinemgmt.get_line_with_id_zero();
71
+ assert( self.get_rep() == this );
72
+ DBG_MESSAGE("simline_t::laden_abschliessen", "assigned id=%d to line %s", self.get_id(), get_name());
74
if( line_managed_convoys.get_count()>0 ) {
77
diff --git a/simlinemgmt.cc b/simlinemgmt.cc
78
index db8b324..19f61ba 100644
81
@@ -118,6 +118,9 @@ void simlinemgmt_t::rdwr(karte_t * welt, loadsave_t *file, spieler_t *sp)
82
sint32 totalLines = 0;
83
file->rdwr_long(totalLines);
84
DBG_MESSAGE("simlinemgmt_t::rdwr()","number of lines=%i",totalLines);
86
+ simline_t *unbound_line = NULL;
88
for (int i = 0; i<totalLines; i++) {
89
simline_t::linetype lt=simline_t::line;
91
@@ -126,7 +129,24 @@ DBG_MESSAGE("simlinemgmt_t::rdwr()","number of lines=%i",totalLines);
92
dbg->fatal( "simlinemgmt_t::rdwr()", "Cannot create default line!" );
94
simline_t *line = new simline_t(welt, sp, lt, file);
95
- add_line( line->get_handle() );
96
+ if (!line->get_handle().is_bound()) {
97
+ // line id was saved as zero ...
99
+ dbg->fatal( "simlinemgmt_t::rdwr()", "More than one line with unbound id read" );
102
+ unbound_line = line;
106
+ add_line( line->get_handle() );
110
+ if (unbound_line) {
111
+ // linehandle will be corrected in simline_t::laden_abschliessen
112
+ line_with_id_zero = linehandle_t(unbound_line);
113
+ add_line( line_with_id_zero );
117
@@ -156,7 +176,6 @@ void simlinemgmt_t::sort_lines()
119
void simlinemgmt_t::laden_abschliessen()
122
for (vector_tpl<linehandle_t>::const_iterator i = all_managed_lines.begin(), end = all_managed_lines.end(); i != end; i++) {
123
(*i)->laden_abschliessen();
125
diff --git a/simlinemgmt.h b/simlinemgmt.h
126
index 0fe2aa6..7cdd698 100644
129
@@ -79,6 +79,12 @@ public:
131
linehandle_t create_line(int ltype, spieler_t * sp, schedule_t * fpl);
135
+ * If there was a line with id=0 map it to non-zero handle
137
+ linehandle_t get_line_with_id_zero() const {return line_with_id_zero; }
140
* fill the list with all lines of a certain type
141
* type == simline_t::line will return all lines
142
@@ -101,6 +107,8 @@ private:
143
static karte_t * welt;
145
schedule_list_gui_t *schedule_list_gui; // Use with caution. Valid only afer zeige_info
147
+ linehandle_t line_with_id_zero;
151
diff --git a/tpl/quickstone_tpl.h b/tpl/quickstone_tpl.h
152
index 57e6c3e..3998f94 100644
153
--- a/tpl/quickstone_tpl.h
154
+++ b/tpl/quickstone_tpl.h
155
@@ -138,11 +138,14 @@ public:
156
quickstone_tpl(T* p, uint16 id)
160
+ dbg->fatal("quickstone<T>::quickstone_tpl(T*,uint16)","wants to assign non-null pointer to null index");
162
while( id >= size ) {
165
if( data[id]!=NULL && data[id]!=p ) {
166
- dbg->fatal("quickstone<T>::quickstone_tpl(T*,uint16)","slot (%) already taken", id);
167
+ dbg->fatal("quickstone<T>::quickstone_tpl(T*,uint16)","slot (%d) already taken", id);