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

« back to all changes in this revision

Viewing changes to besch/writer/groundobj_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:
1
1
#include <string>
2
2
#include "../../dataobj/tabfile.h"
3
 
#include "../groundobj_besch.h"
4
3
#include "obj_node.h"
5
4
#include "text_writer.h"
6
5
#include "imagelist2d_writer.h"
17
16
 
18
17
        // Hajodoc: Preferred height of this tree type
19
18
        // Hajoval: int (useful range: 0-14)
20
 
        groundobj_besch_t besch;
 
19
        climate_bits allowed_climates;
21
20
        const char *climate_str = obj.get("climates");
22
21
        if (climate_str) {
23
 
                besch.allowed_climates = get_climate_bits(climate_str);
 
22
                allowed_climates = get_climate_bits(climate_str);
24
23
        } else {
25
24
                printf("WARNING: without climates!\n");
26
 
                besch.allowed_climates = all_but_arctic_climate;
 
25
                allowed_climates = all_but_arctic_climate;
27
26
        }
28
27
        // seasons = 1: no seasons
29
28
        // otherwise the year will be devided by the (number_of_seasons-1)
30
29
        // The last image is alsway the snow image!
31
 
        besch.number_of_seasons = obj.get_int("seasons", 1);
 
30
        uint8 const number_of_seasons = obj.get_int("seasons", 1);
32
31
 
33
32
        // distribution probabiltion for all of this set
34
 
        besch.distribution_weight = obj.get_int("distributionweight", 3);
 
33
        uint16 const distribution_weight = obj.get_int("distributionweight", 3);
35
34
 
36
35
        // how much for removal
37
 
        besch.cost_removal = obj.get_int("cost", 0);
 
36
        sint32 const cost_removal = obj.get_int("cost", 0);
38
37
 
39
38
        // !=0 for moving objects (sheeps, birds)
40
 
        besch.speed = obj.get_int("speed", 0);
 
39
        uint16 const speed = obj.get_int("speed", 0);
41
40
 
42
41
        // 1 for to allow trees on this objects
43
 
        besch.trees_on_top = obj.get_int("trees_on_top", 1)!=0;
 
42
        bool const trees_on_top = obj.get_int("trees_on_top", 1) != 0;
44
43
 
45
44
        // waytype for moving stuff; meaningful air for birds, water for fish, does not matter for everything else
46
 
        const char* waytype = obj.get("waytype");
47
 
        besch.waytype = (waytype==0  ||  waytype[0]==0) ? ignore_wt : (waytype_t)get_waytype(waytype);
 
45
        char const* const waytype_txt = obj.get("waytype");
 
46
        waytype_t   const waytype     = waytype_txt && waytype_txt[0] != '\0' ? get_waytype(waytype_txt) : ignore_wt;
48
47
 
49
48
        // now for the images
50
49
        slist_tpl<slist_tpl<string> > keys;
51
 
        if(besch.speed==0) {
 
50
        if (speed == 0) {
52
51
                // fixed stuff
53
52
                for (unsigned int phase = 0; 1; phase++) {
54
53
                        keys.append(slist_tpl<string>());
55
54
 
56
 
                        for (int seasons = 0; seasons < besch.number_of_seasons; seasons++) {
 
55
                        for (int seasons = 0; seasons < number_of_seasons; seasons++) {
57
56
                                char buf[40];
58
57
 
59
58
                                // Images of the tree
60
59
                                // age is 1..5 (usually five stages, seasons is the seaons
61
60
                                sprintf(buf, "image[%d][%d]", phase, seasons);
62
61
                                string str = obj.get(buf);
63
 
                                if (str.size() == 0) {
 
62
                                if (str.empty()) {
64
63
                                        if(seasons==0) {
65
64
                                                goto finish_images;
66
65
                                        }
80
79
                for (unsigned int dir = 0; dir<8; dir++) {
81
80
                        keys.append(slist_tpl<string>());
82
81
 
83
 
                        for (int seasons = 0; seasons < besch.number_of_seasons; seasons++) {
 
82
                        for (int seasons = 0; seasons < number_of_seasons; seasons++) {
84
83
                                char buf[40];
85
84
 
86
85
                                // Images of the tree
87
86
                                // age is 1..5 (usually five stages, seasons is the seaons
88
87
                                sprintf(buf, "image[%s][%d]", dir_codes[dir], seasons);
89
88
                                string str = obj.get(buf);
90
 
                                if (str.size() == 0) {
 
89
                                if (str.empty()) {
91
90
                                        printf("Missing images in moving groundobj (expected %s)!\n", buf );
92
91
                                        dbg->fatal("groundobj_writer_t","Season image for season %i missing (%s)!",seasons);
93
92
                                }
99
98
        imagelist2d_writer_t::instance()->write_obj(fp, node, keys);
100
99
 
101
100
        // Hajo: write version data
102
 
        node.write_uint16(fp, 0x8001,                              0);
103
 
 
104
 
        node.write_uint16(fp, (uint16) besch.allowed_climates,     2);
105
 
        node.write_uint16(fp, (uint16) besch.distribution_weight,  4);
106
 
        node.write_uint8 (fp, (uint8)  besch.number_of_seasons,    6);
107
 
        node.write_uint8 (fp, (uint8)  besch.trees_on_top,         7);
108
 
        node.write_uint16(fp, (uint16) besch.speed,                8);
109
 
        node.write_uint16(fp, (uint16) besch.waytype,             10);
110
 
        node.write_sint32(fp, (sint32) besch.cost_removal,        12);
 
101
        node.write_uint16(fp, 0x8001,               0);
 
102
        node.write_uint16(fp, allowed_climates,     2);
 
103
        node.write_uint16(fp, distribution_weight,  4);
 
104
        node.write_uint8 (fp, number_of_seasons,    6);
 
105
        node.write_uint8 (fp, trees_on_top,         7);
 
106
        node.write_uint16(fp, speed,                8);
 
107
        node.write_uint16(fp, waytype,             10);
 
108
        node.write_sint32(fp, cost_removal,        12);
111
109
 
112
110
        node.write(fp);
113
111
}