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

« back to all changes in this revision

Viewing changes to besch/writer/building_writer.cc

  • 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:
18
18
        slist_tpl<slist_tpl<slist_tpl<string> > >& frontkeys
19
19
)
20
20
{
21
 
        haus_tile_besch_t besch;
22
 
 
23
21
        obj_node_t node(this, 7, &parent);
24
22
 
25
 
        besch.phasen = 0;
 
23
        uint8 phasen = 0;
26
24
        for (int i = 0; i < seasons; i++) {
27
25
                slist_iterator_tpl<slist_tpl<string> > iter(backkeys.at(i));
28
26
                while (iter.next()) {
29
 
                        if (iter.get_current().get_count() > besch.phasen) {
30
 
                                besch.phasen = iter.get_current().get_count();
 
27
                        if (iter.get_current().get_count() > phasen) {
 
28
                                phasen = iter.get_current().get_count();
31
29
                        }
32
30
                }
33
31
                iter = slist_iterator_tpl<slist_tpl<string> >(frontkeys.at(i));
34
32
                while (iter.next()) {
35
 
                        if (iter.get_current().get_count() > besch.phasen) {
36
 
                                besch.phasen = iter.get_current().get_count();
 
33
                        if (iter.get_current().get_count() > phasen) {
 
34
                                phasen = iter.get_current().get_count();
37
35
                        }
38
36
                }
39
37
        }
40
 
        besch.index = index;
41
 
        besch.seasons = seasons;
42
38
 
43
39
        for (int i = 0; i < seasons; i++) {
44
40
                imagelist2d_writer_t::instance()->write_obj(fp, node, backkeys.at(i));
52
48
        v16 = 0x8002;
53
49
        node.write_uint16(fp, v16, 0);
54
50
 
55
 
        v16 = besch.phasen;
 
51
        v16 = phasen;
56
52
        node.write_uint16(fp, v16, 2);
57
53
 
58
 
        v16 = besch.index;
 
54
        v16 = index;
59
55
        node.write_uint16(fp, v16, 4);
60
56
 
61
 
        uint8 uv8 = besch.seasons;
 
57
        uint8 uv8 = seasons;
62
58
        node.write_uint8(fp, uv8, 6);
63
59
 
64
60
        node.write(fp);
67
63
 
68
64
void building_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj)
69
65
{
70
 
        haus_besch_t besch;
71
 
 
72
66
        // Hajo: take care, hardocded size of node on disc here!
73
67
        obj_node_t node(this, 26, &parent);
74
68
 
75
69
        write_head(fp, node, obj);
76
70
 
77
 
        besch.groesse = koord(1, 1);
78
 
        besch.layouts = 0;
 
71
        koord groesse(1, 1);
 
72
        uint8 layouts = 0;
79
73
 
80
74
        int* ints = obj.get_ints("dims");
81
75
 
82
76
        switch (ints[0]) {
83
77
                default:
84
 
                case 3: besch.layouts   = ints[3]; /* FALLTHROUGH */
85
 
                case 2: besch.groesse.y = ints[2]; /* FALLTHROUGH */
86
 
                case 1: besch.groesse.x = ints[1]; /* FALLTHROUGH */
 
78
                case 3: layouts   = ints[3]; /* FALLTHROUGH */
 
79
                case 2: groesse.y = ints[2]; /* FALLTHROUGH */
 
80
                case 1: groesse.x = ints[1]; /* FALLTHROUGH */
87
81
                case 0: break;
88
82
        }
89
 
        if (besch.layouts == 0) {
90
 
                besch.layouts = besch.groesse.x == besch.groesse.y ? 1 : 2;
 
83
        if (layouts == 0) {
 
84
                layouts = groesse.x == groesse.y ? 1 : 2;
91
85
        }
92
86
        delete [] ints;
93
87
 
94
 
        besch.gtyp             = gebaeude_t::unbekannt;
95
 
        besch.utype            = haus_besch_t::unbekannt;
96
 
        besch.extra_data          = 0;
97
 
        besch.allowed_climates = all_but_water_climate; // all but water
98
 
        besch.enables          = 0;
99
 
        besch.level            = obj.get_int("level", 1) - 1;
100
 
        besch.flags            = haus_besch_t::flag_t(
101
 
                (obj.get_int("noinfo",         0) > 0 ? haus_besch_t::FLAG_KEINE_INFO  : 0) |
102
 
                (obj.get_int("noconstruction", 0) > 0 ? haus_besch_t::FLAG_KEINE_GRUBE : 0) |
103
 
                (obj.get_int("needs_ground",   0) > 0 ? haus_besch_t::FLAG_NEED_GROUND : 0)
104
 
        );
105
 
        besch.animation_time = obj.get_int("animation_time", 300);
 
88
        gebaeude_t::typ            gtyp             = gebaeude_t::unbekannt;
 
89
        haus_besch_t::utyp         utype            = haus_besch_t::unbekannt;
 
90
        uint16                     extra_data       = 0;
 
91
        climate_bits               allowed_climates = all_but_water_climate; // all but water
 
92
        uint8                      enables          = 0;
 
93
        uint16                     level            = obj.get_int("level", 1) - 1;
 
94
        haus_besch_t::flag_t const flags            =
 
95
                (obj.get_int("noinfo",         0) > 0 ? haus_besch_t::FLAG_KEINE_INFO  : haus_besch_t::FLAG_NULL) |
 
96
                (obj.get_int("noconstruction", 0) > 0 ? haus_besch_t::FLAG_KEINE_GRUBE : haus_besch_t::FLAG_NULL) |
 
97
                (obj.get_int("needs_ground",   0) > 0 ? haus_besch_t::FLAG_NEED_GROUND : haus_besch_t::FLAG_NULL);
 
98
        uint16               const animation_time   = obj.get_int("animation_time", 300);
106
99
 
107
100
        // get the allowed area for this building
108
101
        const char* climate_str = obj.get("climates");
109
102
        if (climate_str && strlen(climate_str) > 4) {
110
 
                besch.allowed_climates = get_climate_bits(climate_str);
 
103
                allowed_climates = get_climate_bits(climate_str);
111
104
        }
112
105
 
113
106
        const char* type_name = obj.get("type");
114
107
        if (!STRICMP(type_name, "res")) {
115
 
                besch.gtyp = gebaeude_t::wohnung;
 
108
                gtyp = gebaeude_t::wohnung;
116
109
        } else if (!STRICMP(type_name, "com")) {
117
 
                besch.gtyp = gebaeude_t::gewerbe;
 
110
                gtyp = gebaeude_t::gewerbe;
118
111
        } else if (!STRICMP(type_name, "ind")) {
119
 
                besch.gtyp = gebaeude_t::industrie;
 
112
                gtyp = gebaeude_t::industrie;
120
113
        } else if (!STRICMP(type_name, "cur")) {
121
 
                besch.extra_data = obj.get_int("build_time", 0);
122
 
                besch.level = obj.get_int("passengers",  besch.level);
123
 
                besch.utype = besch.extra_data == 0 ? haus_besch_t::attraction_land : haus_besch_t::attraction_city;
 
114
                extra_data = obj.get_int("build_time", 0);
 
115
                level      = obj.get_int("passengers",  level);
 
116
                utype      = extra_data == 0 ? haus_besch_t::attraction_land : haus_besch_t::attraction_city;
124
117
        } else if (!STRICMP(type_name, "mon")) {
125
 
                besch.utype = haus_besch_t::denkmal;
126
 
                besch.level = obj.get_int("passengers",  besch.level);
 
118
                utype = haus_besch_t::denkmal;
 
119
                level = obj.get_int("passengers",  level);
127
120
        } else if (!STRICMP(type_name, "tow")) {
128
 
                besch.level = obj.get_int("passengers",  besch.level);
129
 
                besch.extra_data = obj.get_int("build_time", 0);
130
 
                besch.utype = haus_besch_t::rathaus;
 
121
                level      = obj.get_int("passengers",  level);
 
122
                extra_data = obj.get_int("build_time", 0);
 
123
                utype = haus_besch_t::rathaus;
131
124
        } else if (!STRICMP(type_name, "hq")) {
132
 
                besch.level = obj.get_int("passengers",  besch.level);
133
 
                besch.extra_data = obj.get_int("hq_level", 0);
134
 
                besch.utype = haus_besch_t::firmensitz;
 
125
                level      = obj.get_int("passengers",  level);
 
126
                extra_data = obj.get_int("hq_level", 0);
 
127
                utype = haus_besch_t::firmensitz;
135
128
        } else if (!STRICMP(type_name, "habour")  ||  !STRICMP(type_name, "harbour")) {
136
 
                besch.utype = haus_besch_t::hafen;
137
 
                besch.extra_data = water_wt;
 
129
                utype      = haus_besch_t::hafen;
 
130
                extra_data = water_wt;
138
131
        } else if (!STRICMP(type_name, "fac")) {
139
 
                besch.utype = haus_besch_t::fabrik;
140
 
                besch.enables |= 4;
 
132
                utype    = haus_besch_t::fabrik;
 
133
                enables |= 4;
141
134
        } else if (!STRICMP(type_name, "stop")) {
142
 
                besch.utype = haus_besch_t::generic_stop;
143
 
                besch.extra_data = get_waytype(obj.get("waytype"));
 
135
                utype      = haus_besch_t::generic_stop;
 
136
                extra_data = get_waytype(obj.get("waytype"));
144
137
        } else if (!STRICMP(type_name, "extension")) {
145
 
                besch.utype = haus_besch_t::generic_extension;
 
138
                utype = haus_besch_t::generic_extension;
146
139
                const char *wt = obj.get("waytype");
147
140
                if(wt  &&  *wt>' ') {
148
141
                        // not waytype => just a generic exten that fits all
149
 
                        besch.extra_data = get_waytype(wt);
 
142
                        extra_data = get_waytype(wt);
150
143
                }
151
144
        } else if (!STRICMP(type_name, "depot")) {
152
 
                besch.utype = haus_besch_t::depot;
153
 
                besch.extra_data = get_waytype(obj.get("waytype"));
 
145
                utype      = haus_besch_t::depot;
 
146
                extra_data = get_waytype(obj.get("waytype"));
154
147
        } else if (!STRICMP(type_name, "any") || *type_name == '\0') {
155
148
                // for instance "MonorailGround"
156
 
                besch.utype = haus_besch_t::weitere;
 
149
                utype = haus_besch_t::weitere;
157
150
        } else if (
158
151
                !STRICMP(type_name, "station")  ||
159
152
                !STRICMP(type_name, "railstop")  ||
176
169
        }
177
170
 
178
171
        if (obj.get_int("enables_pax", 0) > 0) {
179
 
                besch.enables |= 1;
 
172
                enables |= 1;
180
173
        }
181
174
        if (obj.get_int("enables_post", 0) > 0) {
182
 
                besch.enables |= 2;
 
175
                enables |= 2;
183
176
        }
184
 
        if (besch.utype == haus_besch_t::fabrik || obj.get_int("enables_ware", 0) > 0) {
185
 
                besch.enables |= 4;
 
177
        if(  utype == haus_besch_t::fabrik  ||  obj.get_int("enables_ware", 0) > 0  ) {
 
178
                enables |= 4;
186
179
        }
187
180
 
188
 
        // some station thing ...
189
 
        if (besch.enables) {
190
 
                besch.level ++;
 
181
        if(  utype==haus_besch_t::generic_extension  ||  utype==haus_besch_t::generic_stop  ||  utype==haus_besch_t::hafen  ||  utype==haus_besch_t::depot  ||  utype==haus_besch_t::fabrik  ) {
 
182
                // since elevel was reduced by one beforehand ...
 
183
                ++level;
191
184
        }
192
185
 
193
186
        // Hajo: read chance - default is 100% chance to be built
194
 
        besch.chance = obj.get_int("chance", 100) ;
 
187
        uint8 const chance = obj.get_int("chance", 100);
195
188
 
196
189
        // prissi: timeline for buildings
197
 
        besch.intro_date  = obj.get_int("intro_year", DEFAULT_INTRO_DATE) * 12;
198
 
        besch.intro_date += obj.get_int("intro_month", 1) - 1;
 
190
        uint16 const intro_date =
 
191
                obj.get_int("intro_year", DEFAULT_INTRO_DATE) * 12 +
 
192
                obj.get_int("intro_month", 1) - 1;
199
193
 
200
 
        besch.obsolete_date  = obj.get_int("retire_year", DEFAULT_RETIRE_DATE) * 12;
201
 
        besch.obsolete_date += obj.get_int("retire_month", 1) - 1;
 
194
        uint16 const obsolete_date =
 
195
                obj.get_int("retire_year", DEFAULT_RETIRE_DATE) * 12 +
 
196
                obj.get_int("retire_month", 1) - 1;
202
197
 
203
198
        // scan for most number of seasons
204
199
        int seasons = 1;
205
 
        for (int l = 0; l < besch.layouts; l++) { // each layout
206
 
                for (int y = 0; y < besch.get_h(l); y++) {
207
 
                        for (int x = 0; x < besch.get_b(l); x++) { // each tile
 
200
        for (int l = 0; l < layouts; l++) { // each layout
 
201
                int const h = l & 1 ? groesse.x : groesse.y;
 
202
                int const w = l & 1 ? groesse.y : groesse.x;
 
203
                for (int y = 0; y < h; ++y) {
 
204
                        for (int x = 0; x < w; ++x) { // each tile
208
205
                                for (int pos = 0; pos < 2; pos++) {
209
206
                                        for (int season = seasons; season < 12; season++) {
210
207
                                                char buf[40];
222
219
        }
223
220
 
224
221
        int tile_index = 0;
225
 
        for (int l = 0; l < besch.layouts; l++) { // each layout
226
 
                for (int y = 0; y < besch.get_h(l); y++) {
227
 
                        for (int x = 0; x < besch.get_b(l); x++) { // each tile
 
222
        for (int l = 0; l < layouts; l++) { // each layout
 
223
                int const h = l & 1 ? groesse.x : groesse.y;
 
224
                int const w = l & 1 ? groesse.y : groesse.x;
 
225
                for (int y = 0; y < h; ++y) {
 
226
                        for (int x = 0; x < w; ++x) { // each tile
228
227
                                slist_tpl<slist_tpl<slist_tpl<string> > > backkeys;
229
228
                                slist_tpl<slist_tpl<slist_tpl<string> > > frontkeys;
230
229
 
243
242
                                                                string str = obj.get(buf);
244
243
 
245
244
                                                                // if no string check to see whether using format without seasons parameter
246
 
                                                                if (str.size() == 0 && seasons == 1) {
 
245
                                                                if (str.empty() && seasons == 1) {
247
246
                                                                        sprintf(buf, "%simage[%d][%d][%d][%d][%d]", pos ? "back" : "front", l, y, x, h, phase);
248
247
                                                                        str = obj.get(buf);
249
248
                                                                }
250
 
                                                                if (str.size() == 0) {
 
249
                                                                if (str.empty()) {
251
250
#if 0
252
251
                                                                        printf("Not found: %s\n", buf);
253
252
                                                                        fflush(NULL);
278
277
        }
279
278
 
280
279
        // Hajo: write version data
281
 
        node.write_uint16(fp, 0x8005,                           0);
 
280
        node.write_uint16(fp, 0x8006,            0);
282
281
 
283
282
        // Hajo: write besch data
284
 
        node.write_uint8 (fp, (uint8) besch.gtyp,               2);
285
 
        node.write_uint8 (fp, (uint8) besch.utype,              3);
286
 
        node.write_uint16(fp, (uint16) besch.level,             4);
287
 
        node.write_uint32(fp, (uint32) besch.extra_data,        6);
288
 
        node.write_uint16(fp, besch.groesse.x,                 10);
289
 
        node.write_uint16(fp, besch.groesse.y,                 12);
290
 
        node.write_uint8 (fp, (uint8) besch.layouts,           14);
291
 
        node.write_uint16(fp, (uint16) besch.allowed_climates, 15);
292
 
        node.write_uint8 (fp, (uint8) besch.enables,           17);
293
 
        node.write_uint8 (fp, (uint8) besch.flags,             18);
294
 
        node.write_uint8 (fp, (uint8) besch.chance,            19);
295
 
        node.write_uint16(fp, besch.intro_date,                20);
296
 
        node.write_uint16(fp, besch.obsolete_date,             22);
297
 
        node.write_uint16(fp, besch.animation_time,            24);
 
283
        node.write_uint8 (fp, gtyp,              2);
 
284
        node.write_uint8 (fp, utype,             3);
 
285
        node.write_uint16(fp, level,             4);
 
286
        node.write_uint32(fp, extra_data,        6);
 
287
        node.write_uint16(fp, groesse.x,        10);
 
288
        node.write_uint16(fp, groesse.y,        12);
 
289
        node.write_uint8 (fp, layouts,          14);
 
290
        node.write_uint16(fp, allowed_climates, 15);
 
291
        node.write_uint8 (fp, enables,          17);
 
292
        node.write_uint8 (fp, flags,            18);
 
293
        node.write_uint8 (fp, chance,           19);
 
294
        node.write_uint16(fp, intro_date,       20);
 
295
        node.write_uint16(fp, obsolete_date,    22);
 
296
        node.write_uint16(fp, animation_time,   24);
298
297
 
299
298
        // probably add some icons, if defined
300
299
        slist_tpl<string> cursorkeys;
303
302
        string i = string(obj.get("icon"));
304
303
        cursorkeys.append(c);
305
304
        cursorkeys.append(i);
306
 
        if (c.size() > 0 || i.size() > 0) {
 
305
        if (!c.empty() || !i.empty()) {
307
306
                cursorskin_writer_t::instance()->write_obj(fp, node, obj, cursorkeys);
308
307
        }
309
308
        node.write(fp);