~ubuntu-branches/ubuntu/raring/simutrans/raring-proposed

« back to all changes in this revision

Viewing changes to debian/patches/0002-FIX-loading-of-savegames-with-line-with-id-0.patch

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2011-11-03 19:59:02 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20111103195902-uopgwf488mfctb75
Tags: 111.0-1
* New upstream release.
* debian/rules: Update get-orig-source target for new upstream release.
* Use xz compression for source and binary packages.
* Use override_* targets to simplify debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
 
6
 
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@4358 8aca7d54-2c30-db11-9de9-000461428c89
7
 
---
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(-)
14
 
 
15
 
diff --git a/simconvoi.cc b/simconvoi.cc
16
 
index fa6ddf1..9499a84 100644
17
 
--- a/simconvoi.cc
18
 
+++ b/simconvoi.cc
19
 
@@ -353,9 +353,14 @@ DBG_MESSAGE("convoi_t::laden_abschliessen()","state=%s, next_stop_index=%d", sta
20
 
                        }
21
 
                }
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() )  ) {
26
 
+
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();
31
 
+               }
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
39
 
--- a/simline.cc
40
 
+++ b/simline.cc
41
 
@@ -49,7 +49,10 @@ simline_t::simline_t(karte_t* welt, spieler_t* sp, linetype type, loadsave_t *fi
42
 
        rdwr(file);
43
 
        // now self has the right id but the this-pointer is not assigned to the quickstone handle yet
44
 
        // do this explicitly
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());
49
 
+       }
50
 
 }
51
 
 
52
 
 
53
 
@@ -85,8 +88,9 @@ void simline_t::create_schedule()
54
 
 
55
 
 void simline_t::add_convoy(convoihandle_t cnv)
56
 
 {
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
61
 
                register_stops(fpl);
62
 
        }
63
 
 
64
 
@@ -225,6 +229,12 @@ void simline_t::rdwr(loadsave_t *file)
65
 
 
66
 
 void simline_t::laden_abschliessen()
67
 
 {
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());
73
 
+       }
74
 
        if(  line_managed_convoys.get_count()>0  ) {
75
 
                register_stops(fpl);
76
 
        }
77
 
diff --git a/simlinemgmt.cc b/simlinemgmt.cc
78
 
index db8b324..19f61ba 100644
79
 
--- a/simlinemgmt.cc
80
 
+++ b/simlinemgmt.cc
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);
85
 
+
86
 
+               simline_t *unbound_line = NULL;
87
 
+
88
 
                for (int i = 0; i<totalLines; i++) {
89
 
                        simline_t::linetype lt=simline_t::line;
90
 
                        file->rdwr_enum(lt);
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!" );
93
 
                        }
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 ...
98
 
+                               if (unbound_line) {
99
 
+                                       dbg->fatal( "simlinemgmt_t::rdwr()", "More than one line with unbound id read" );
100
 
+                               }
101
 
+                               else {
102
 
+                                       unbound_line = line;
103
 
+                               }
104
 
+                       }
105
 
+                       else {
106
 
+                               add_line( line->get_handle() );
107
 
+                       }
108
 
+               }
109
 
+
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 );
114
 
                }
115
 
        }
116
 
 }
117
 
@@ -156,7 +176,6 @@ void simlinemgmt_t::sort_lines()
118
 
 
119
 
 void simlinemgmt_t::laden_abschliessen()
120
 
 {
121
 
-       sort_lines();
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();
124
 
        }
125
 
diff --git a/simlinemgmt.h b/simlinemgmt.h
126
 
index 0fe2aa6..7cdd698 100644
127
 
--- a/simlinemgmt.h
128
 
+++ b/simlinemgmt.h
129
 
@@ -79,6 +79,12 @@ public:
130
 
         */
131
 
        linehandle_t create_line(int ltype, spieler_t * sp, schedule_t * fpl);
132
 
 
133
 
+
134
 
+       /**
135
 
+        * If there was a line with id=0 map it to non-zero handle
136
 
+        */
137
 
+       linehandle_t get_line_with_id_zero() const {return line_with_id_zero; }
138
 
+
139
 
        /*
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;
144
 
 
145
 
        schedule_list_gui_t *schedule_list_gui;  // Use with caution.  Valid only afer zeige_info
146
 
+
147
 
+       linehandle_t line_with_id_zero;
148
 
 };
149
 
 
150
 
 #endif
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)
157
 
        {
158
 
                if(p) {
159
 
+                       if(  id == 0  ) {
160
 
+                               dbg->fatal("quickstone<T>::quickstone_tpl(T*,uint16)","wants to assign non-null pointer to null index");
161
 
+                       }
162
 
                        while(  id >= size  ) {
163
 
                                enlarge();
164
 
                        }
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);
168
 
                        }
169
 
                        entry = id;
170
 
                        data[entry] = p;
171
 
1.7.2.3
172