… | |
… | |
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 | virtual archetype *get_arch (const char *name); |
|
|
38 | virtual void put_arch (archetype *arch); |
|
|
39 | |
34 | |
40 | virtual object *get_object (const char *name); |
35 | // the base class warns about and skips everything |
41 | virtual void put_object (object *op); |
36 | archetype * |
|
|
37 | loader_base::get_arch (const char *name) |
|
|
38 | { |
|
|
39 | LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of this type.\n", |
|
|
40 | filename, name); |
42 | |
41 | |
43 | virtual player *get_player (); |
42 | return new archetype; |
44 | virtual void put_player (player *pl); |
43 | } |
45 | |
44 | |
46 | virtual region *get_region (); |
45 | object * |
47 | virtual void put_region (region *region); |
46 | loader_base::get_object (const char *name) |
|
|
47 | { |
|
|
48 | LOG (llevError, "%s: found object definition '%s', which is not allowed in files of this type.\n", |
|
|
49 | filename, name); |
48 | |
50 | |
49 | virtual facetile *get_face (const char *name); |
51 | return object::create (); |
50 | virtual void put_face (facetile *face); |
52 | } |
51 | |
53 | |
52 | virtual treasurelist *get_treasure (const char *name, bool one = false); |
54 | player * |
|
|
55 | loader_base::get_player () |
|
|
56 | { |
|
|
57 | LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n", |
|
|
58 | filename); |
|
|
59 | |
|
|
60 | return player::create (); |
|
|
61 | } |
|
|
62 | |
|
|
63 | region * |
|
|
64 | loader_base::get_region (const char *name) |
|
|
65 | { |
|
|
66 | LOG (llevError, "%s: found region definition '%s', which is not allowed in files of this type.\n", |
|
|
67 | filename, name); |
|
|
68 | |
|
|
69 | return new region; |
|
|
70 | } |
|
|
71 | |
|
|
72 | facetile * |
|
|
73 | loader_base::get_face (const char *name) |
|
|
74 | { |
|
|
75 | LOG (llevError, "%s: found face definition '%s', which is not allowed in files of this type.\n", |
|
|
76 | filename, name); |
|
|
77 | |
|
|
78 | return new facetile; |
|
|
79 | } |
|
|
80 | |
|
|
81 | treasurelist * |
|
|
82 | loader_base::get_treasure (const char *name, bool one) |
|
|
83 | { |
|
|
84 | LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of this type.\n", |
|
|
85 | filename, name); |
|
|
86 | |
|
|
87 | return new treasurelist;//D |
|
|
88 | } |
|
|
89 | |
|
|
90 | animation * |
|
|
91 | loader_base::get_animation (const char *name) |
|
|
92 | { |
|
|
93 | LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of this type.\n", |
|
|
94 | filename, name); |
|
|
95 | |
|
|
96 | return new animation; |
|
|
97 | } |
|
|
98 | |
|
|
99 | void |
|
|
100 | loader_base::put_arch (archetype *arch) |
|
|
101 | { |
|
|
102 | delete arch; |
|
|
103 | } |
|
|
104 | |
|
|
105 | void |
|
|
106 | loader_base::put_object (object *op) |
|
|
107 | { |
|
|
108 | op->destroy (); |
|
|
109 | } |
|
|
110 | |
|
|
111 | void |
|
|
112 | loader_base::put_player (player *pl) |
|
|
113 | { |
|
|
114 | delete pl; |
|
|
115 | } |
|
|
116 | |
|
|
117 | void |
|
|
118 | loader_base::put_region (region *region) |
|
|
119 | { |
|
|
120 | delete region; |
|
|
121 | } |
|
|
122 | |
|
|
123 | void |
|
|
124 | loader_base::put_face (facetile *face) |
|
|
125 | { |
|
|
126 | delete face; |
|
|
127 | } |
|
|
128 | |
|
|
129 | void |
53 | virtual void put_treasure (treasurelist *treasure); |
130 | loader_base::put_treasure (treasurelist *treasure) |
54 | |
|
|
55 | virtual animation *get_animation (const char *name); |
|
|
56 | virtual void put_animation (animation *anim); |
|
|
57 | }; |
|
|
58 | |
|
|
59 | // future generic resource loader |
|
|
60 | // handles generic stuff valid in most files, such as |
|
|
61 | // animations, treasures, faces and so on |
|
|
62 | struct loader_generic : loader_base |
|
|
63 | { |
131 | { |
64 | virtual region *get_region (); |
132 | delete treasure; |
65 | virtual void put_region (region *region); |
133 | } |
66 | |
134 | |
67 | virtual facetile *get_face (const char *name); |
135 | void |
68 | virtual void put_face (facetile *face); |
136 | loader_base::put_animation (animation *anim) |
|
|
137 | { |
|
|
138 | delete anim; |
|
|
139 | } |
69 | |
140 | |
70 | virtual treasurelist *get_treasure (const char *name, bool one = false); |
141 | ///////////////////////////////////////////////////////////////////////////// |
71 | virtual void put_treasure (treasurelist *treasure); |
|
|
72 | |
142 | |
73 | virtual animation *get_animation (const char *name); |
143 | bool loader_base::parse (object_thawer &thawer) |
74 | virtual void put_animation (animation *anim); |
144 | { |
75 | }; |
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 | ///////////////////////////////////////////////////////////////////////////// |
76 | |
188 | |
77 | /* Maps the MOVE_* values to names */ |
189 | /* Maps the MOVE_* values to names */ |
78 | 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 }; |
79 | |
191 | |
80 | /* 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 |
… | |
… | |
1078 | 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); |
1079 | //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 |
1080 | break; |
1192 | break; |
1081 | |
1193 | |
1082 | default: |
1194 | default: |
1083 | 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; |
1084 | break; |
1197 | break; |
1085 | } |
1198 | } |
1086 | } |
1199 | } |
1087 | } |
1200 | } |
1088 | |
1201 | |