… | |
… | |
24 | |
24 | |
25 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
25 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
26 | sub/add_weight will transcend the environment updating the carrying |
26 | sub/add_weight will transcend the environment updating the carrying |
27 | variable. */ |
27 | variable. */ |
28 | |
28 | |
29 | |
|
|
30 | #include <global.h> |
29 | #include <global.h> |
31 | #include <loader.h> |
30 | #include <loader.h> |
32 | #include <sproto.h> |
31 | #include <sproto.h> |
33 | |
32 | |
34 | // future resource loader base class |
33 | ///////////////////////////////////////////////////////////////////////////// |
35 | struct loader_base |
|
|
36 | { |
|
|
37 | const char *filename; |
|
|
38 | virtual const char *type () const = 0; |
|
|
39 | |
|
|
40 | virtual archetype *get_arch (const char *name); |
|
|
41 | virtual void put_arch (archetype *arch); |
|
|
42 | |
|
|
43 | virtual object *get_object (const char *name); |
|
|
44 | virtual void put_object (object *op); |
|
|
45 | |
|
|
46 | virtual player *get_player (); |
|
|
47 | virtual void put_player (player *pl); |
|
|
48 | |
|
|
49 | virtual region *get_region (const char *name); |
|
|
50 | virtual void put_region (region *region); |
|
|
51 | |
|
|
52 | virtual facetile *get_face (const char *name); |
|
|
53 | virtual void put_face (facetile *face); |
|
|
54 | |
|
|
55 | virtual treasurelist *get_treasure (const char *name, bool one = false); |
|
|
56 | virtual void put_treasure (treasurelist *treasure); |
|
|
57 | |
|
|
58 | virtual animation *get_animation (const char *name); |
|
|
59 | virtual void put_animation (animation *anim); |
|
|
60 | }; |
|
|
61 | |
|
|
62 | // future generic resource loader |
|
|
63 | // handles generic stuff valid in most files, such as |
|
|
64 | // animations, treasures, faces and so on |
|
|
65 | struct loader_generic : loader_base |
|
|
66 | { |
|
|
67 | const char *type () const = 0; |
|
|
68 | |
|
|
69 | region *get_region (); |
|
|
70 | void put_region (region *region); |
|
|
71 | |
|
|
72 | facetile *get_face (const char *name); |
|
|
73 | void put_face (facetile *face); |
|
|
74 | |
|
|
75 | treasurelist *get_treasure (const char *name, bool one = false); |
|
|
76 | void put_treasure (treasurelist *treasure); |
|
|
77 | |
|
|
78 | animation *get_animation (const char *name); |
|
|
79 | void put_animation (animation *anim); |
|
|
80 | }; |
|
|
81 | |
34 | |
82 | // the base class warns about and skips everything |
35 | // the base class warns about and skips everything |
83 | archetype * |
36 | archetype * |
84 | loader_base::get_arch (const char *name) |
37 | loader_base::get_arch (const char *name) |
85 | { |
38 | { |
86 | LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of type %s.\n", |
39 | LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of this type.\n", |
87 | filename, name, type ()); |
40 | filename, name); |
88 | |
41 | |
89 | return new archetype; |
42 | return new archetype; |
90 | } |
43 | } |
91 | |
44 | |
92 | object * |
45 | object * |
93 | loader_base::get_object (const char *name) |
46 | loader_base::get_object (const char *name) |
94 | { |
47 | { |
95 | LOG (llevError, "%s: found object definition '%s', which is not allowed in files of type %s.\n", |
48 | LOG (llevError, "%s: found object definition '%s', which is not allowed in files of this type.\n", |
96 | filename, name, type ()); |
49 | filename, name); |
97 | |
50 | |
98 | return object::create (); |
51 | return object::create (); |
99 | } |
52 | } |
100 | |
53 | |
101 | player * |
54 | player * |
102 | loader_base::get_player () |
55 | loader_base::get_player () |
103 | { |
56 | { |
104 | LOG (llevError, "%s: found player definition, which is not allowed in files of type %s.\n", |
57 | LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n", |
105 | filename, type ()); |
58 | filename); |
106 | |
59 | |
107 | return player::create (); |
60 | return player::create (); |
108 | } |
61 | } |
109 | |
62 | |
110 | region * |
63 | region * |
111 | loader_base::get_region (const char *name) |
64 | loader_base::get_region (const char *name) |
112 | { |
65 | { |
113 | LOG (llevError, "%s: found region definition '%s', which is not allowed in files of type %s.\n", |
66 | LOG (llevError, "%s: found region definition '%s', which is not allowed in files of this type.\n", |
114 | filename, name, type ()); |
67 | filename, name); |
115 | |
68 | |
116 | return new region; |
69 | return new region; |
117 | } |
70 | } |
118 | |
71 | |
119 | facetile * |
72 | facetile * |
120 | loader_base::get_face (const char *name) |
73 | loader_base::get_face (const char *name) |
121 | { |
74 | { |
122 | LOG (llevError, "%s: found face definition '%s', which is not allowed in files of type %s.\n", |
75 | LOG (llevError, "%s: found face definition '%s', which is not allowed in files of this type.\n", |
123 | filename, name, type ()); |
76 | filename, name); |
124 | |
77 | |
125 | return new facetile; |
78 | return new facetile; |
126 | } |
79 | } |
127 | |
80 | |
128 | treasurelist * |
81 | treasurelist * |
129 | loader_base::get_treasure (const char *name, bool one) |
82 | loader_base::get_treasure (const char *name, bool one) |
130 | { |
83 | { |
131 | LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of type %s.\n", |
84 | LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of this type.\n", |
132 | filename, name, type ()); |
85 | filename, name); |
133 | |
86 | |
134 | return new treasurelist;//D |
87 | return new treasurelist;//D |
135 | } |
88 | } |
136 | |
89 | |
137 | animation * |
90 | animation * |
138 | loader_base::get_animation (const char *name) |
91 | loader_base::get_animation (const char *name) |
139 | { |
92 | { |
140 | LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of type %s.\n", |
93 | LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of this type.\n", |
141 | filename, name, type ()); |
94 | filename, name); |
142 | |
95 | |
143 | return new animation; |
96 | return new animation; |
144 | } |
97 | } |
145 | |
98 | |
146 | void |
99 | void |
… | |
… | |
182 | void |
135 | void |
183 | loader_base::put_animation (animation *anim) |
136 | loader_base::put_animation (animation *anim) |
184 | { |
137 | { |
185 | delete anim; |
138 | delete anim; |
186 | } |
139 | } |
|
|
140 | |
|
|
141 | ///////////////////////////////////////////////////////////////////////////// |
|
|
142 | |
|
|
143 | bool loader_base::parse (object_thawer &thawer) |
|
|
144 | { |
|
|
145 | for (;;) |
|
|
146 | { |
|
|
147 | keyword kw = thawer.get_kv (); |
|
|
148 | |
|
|
149 | switch (kw) |
|
|
150 | { |
|
|
151 | case KW_region: |
|
|
152 | { |
|
|
153 | region *rgn = get_region (thawer.get_str ()); |
|
|
154 | |
|
|
155 | if (!parse_region (thawer, rgn)) |
|
|
156 | { |
|
|
157 | delete rgn; |
|
|
158 | return false; |
|
|
159 | } |
|
|
160 | |
|
|
161 | put_region (rgn); |
|
|
162 | } |
|
|
163 | break; |
|
|
164 | |
|
|
165 | case KW_EOF: |
|
|
166 | return true; |
|
|
167 | |
|
|
168 | default: |
|
|
169 | if (!thawer.parse_error (kw, "resource file")) |
|
|
170 | return false; |
|
|
171 | } |
|
|
172 | } |
|
|
173 | } |
|
|
174 | |
|
|
175 | bool loader_base::load (const char *filename) |
|
|
176 | { |
|
|
177 | this->filename = filename; |
|
|
178 | |
|
|
179 | object_thawer fp (filename); |
|
|
180 | |
|
|
181 | if (!fp) |
|
|
182 | return false; |
|
|
183 | |
|
|
184 | return parse (fp); |
|
|
185 | } |
|
|
186 | |
|
|
187 | ///////////////////////////////////////////////////////////////////////////// |
187 | |
188 | |
188 | /* Maps the MOVE_* values to names */ |
189 | /* Maps the MOVE_* values to names */ |
189 | static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; |
190 | static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; |
190 | |
191 | |
191 | /* This table is only necessary to convert objects that existed before the |
192 | /* This table is only necessary to convert objects that existed before the |
… | |
… | |
1189 | set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true); |
1190 | set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true); |
1190 | //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D |
1191 | //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D |
1191 | break; |
1192 | break; |
1192 | |
1193 | |
1193 | default: |
1194 | default: |
1194 | LOG (llevError, "UNSUPPORTED KEYWORD IN MAP: \"%s\", bug in normaliser. skipping.\n", keyword_str[kw]); |
1195 | if (!thawer.parse_error (kw, "object", op->name)) |
|
|
1196 | return false; |
1195 | break; |
1197 | break; |
1196 | } |
1198 | } |
1197 | } |
1199 | } |
1198 | } |
1200 | } |
1199 | |
1201 | |