… | |
… | |
32 | #include <sproto.h> |
32 | #include <sproto.h> |
33 | |
33 | |
34 | // future resource loader base class |
34 | // future resource loader base class |
35 | struct loader_base |
35 | struct loader_base |
36 | { |
36 | { |
|
|
37 | const char *filename; |
|
|
38 | virtual const char *type () const = 0; |
|
|
39 | |
37 | virtual archetype *get_arch (const char *name); |
40 | virtual archetype *get_arch (const char *name); |
38 | virtual void put_arch (archetype *arch); |
41 | virtual void put_arch (archetype *arch); |
39 | |
42 | |
40 | virtual object *get_object (const char *name); |
43 | virtual object *get_object (const char *name); |
41 | virtual void put_object (object *op); |
44 | virtual void put_object (object *op); |
42 | |
45 | |
43 | virtual player *get_player (); |
46 | virtual player *get_player (); |
44 | virtual void put_player (player *pl); |
47 | virtual void put_player (player *pl); |
45 | |
48 | |
46 | virtual region *get_region (); |
49 | virtual region *get_region (const char *name); |
47 | virtual void put_region (region *region); |
50 | virtual void put_region (region *region); |
48 | |
51 | |
49 | virtual facetile *get_face (const char *name); |
52 | virtual facetile *get_face (const char *name); |
50 | virtual void put_face (facetile *face); |
53 | virtual void put_face (facetile *face); |
51 | |
54 | |
… | |
… | |
59 | // future generic resource loader |
62 | // future generic resource loader |
60 | // handles generic stuff valid in most files, such as |
63 | // handles generic stuff valid in most files, such as |
61 | // animations, treasures, faces and so on |
64 | // animations, treasures, faces and so on |
62 | struct loader_generic : loader_base |
65 | struct loader_generic : loader_base |
63 | { |
66 | { |
|
|
67 | const char *type () const = 0; |
|
|
68 | |
64 | virtual region *get_region (); |
69 | region *get_region (); |
65 | virtual void put_region (region *region); |
70 | void put_region (region *region); |
66 | |
71 | |
67 | virtual facetile *get_face (const char *name); |
72 | facetile *get_face (const char *name); |
68 | virtual void put_face (facetile *face); |
73 | void put_face (facetile *face); |
69 | |
74 | |
70 | virtual treasurelist *get_treasure (const char *name, bool one = false); |
75 | treasurelist *get_treasure (const char *name, bool one = false); |
71 | virtual void put_treasure (treasurelist *treasure); |
76 | void put_treasure (treasurelist *treasure); |
72 | |
77 | |
73 | virtual animation *get_animation (const char *name); |
78 | animation *get_animation (const char *name); |
74 | virtual void put_animation (animation *anim); |
79 | void put_animation (animation *anim); |
75 | }; |
80 | }; |
|
|
81 | |
|
|
82 | // the base class warns about and skips everything |
|
|
83 | archetype * |
|
|
84 | loader_base::get_arch (const char *name) |
|
|
85 | { |
|
|
86 | LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of type %s.\n", |
|
|
87 | filename, name, type ()); |
|
|
88 | |
|
|
89 | return new archetype; |
|
|
90 | } |
|
|
91 | |
|
|
92 | object * |
|
|
93 | loader_base::get_object (const char *name) |
|
|
94 | { |
|
|
95 | LOG (llevError, "%s: found object definition '%s', which is not allowed in files of type %s.\n", |
|
|
96 | filename, name, type ()); |
|
|
97 | |
|
|
98 | return object::create (); |
|
|
99 | } |
|
|
100 | |
|
|
101 | player * |
|
|
102 | loader_base::get_player () |
|
|
103 | { |
|
|
104 | LOG (llevError, "%s: found player definition, which is not allowed in files of type %s.\n", |
|
|
105 | filename, type ()); |
|
|
106 | |
|
|
107 | return player::create (); |
|
|
108 | } |
|
|
109 | |
|
|
110 | region * |
|
|
111 | loader_base::get_region (const char *name) |
|
|
112 | { |
|
|
113 | LOG (llevError, "%s: found region definition '%s', which is not allowed in files of type %s.\n", |
|
|
114 | filename, name, type ()); |
|
|
115 | |
|
|
116 | return new region; |
|
|
117 | } |
|
|
118 | |
|
|
119 | facetile * |
|
|
120 | loader_base::get_face (const char *name) |
|
|
121 | { |
|
|
122 | LOG (llevError, "%s: found face definition '%s', which is not allowed in files of type %s.\n", |
|
|
123 | filename, name, type ()); |
|
|
124 | |
|
|
125 | return new facetile; |
|
|
126 | } |
|
|
127 | |
|
|
128 | treasurelist * |
|
|
129 | loader_base::get_treasure (const char *name, bool one) |
|
|
130 | { |
|
|
131 | LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of type %s.\n", |
|
|
132 | filename, name, type ()); |
|
|
133 | |
|
|
134 | return new treasurelist;//D |
|
|
135 | } |
|
|
136 | |
|
|
137 | animation * |
|
|
138 | loader_base::get_animation (const char *name) |
|
|
139 | { |
|
|
140 | LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of type %s.\n", |
|
|
141 | filename, name, type ()); |
|
|
142 | |
|
|
143 | return new animation; |
|
|
144 | } |
|
|
145 | |
|
|
146 | void |
|
|
147 | loader_base::put_arch (archetype *arch) |
|
|
148 | { |
|
|
149 | delete arch; |
|
|
150 | } |
|
|
151 | |
|
|
152 | void |
|
|
153 | loader_base::put_object (object *op) |
|
|
154 | { |
|
|
155 | op->destroy (); |
|
|
156 | } |
|
|
157 | |
|
|
158 | void |
|
|
159 | loader_base::put_player (player *pl) |
|
|
160 | { |
|
|
161 | delete pl; |
|
|
162 | } |
|
|
163 | |
|
|
164 | void |
|
|
165 | loader_base::put_region (region *region) |
|
|
166 | { |
|
|
167 | delete region; |
|
|
168 | } |
|
|
169 | |
|
|
170 | void |
|
|
171 | loader_base::put_face (facetile *face) |
|
|
172 | { |
|
|
173 | delete face; |
|
|
174 | } |
|
|
175 | |
|
|
176 | void |
|
|
177 | loader_base::put_treasure (treasurelist *treasure) |
|
|
178 | { |
|
|
179 | delete treasure; |
|
|
180 | } |
|
|
181 | |
|
|
182 | void |
|
|
183 | loader_base::put_animation (animation *anim) |
|
|
184 | { |
|
|
185 | delete anim; |
|
|
186 | } |
76 | |
187 | |
77 | /* Maps the MOVE_* values to names */ |
188 | /* Maps the MOVE_* values to names */ |
78 | static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; |
189 | static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; |
79 | |
190 | |
80 | /* This table is only necessary to convert objects that existed before the |
191 | /* This table is only necessary to convert objects that existed before the |