ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.C
(Generate patch)

Comparing deliantra/server/common/loader.C (file contents):
Revision 1.51 by root, Thu Feb 1 17:29:16 2007 UTC vs.
Revision 1.55 by root, Thu Feb 8 03:09:31 2007 UTC

28 28
29#include <global.h> 29#include <global.h>
30#include <loader.h> 30#include <loader.h>
31#include <sproto.h> 31#include <sproto.h>
32 32
33// resource loader pure base class 33/////////////////////////////////////////////////////////////////////////////
34struct loader_base
35{
36 const char *filename;
37 virtual const char *type () const = 0;
38 34
39 virtual archetype *get_arch (const char *name); 35loader_base::~loader_base ()
40 virtual void put_arch (archetype *arch);
41
42 virtual object *get_object (const char *name);
43 virtual void put_object (object *op);
44
45 virtual player *get_player ();
46 virtual void put_player (player *pl);
47
48 virtual region *get_region (const char *name);
49 virtual void put_region (region *region);
50
51 virtual facetile *get_face (const char *name);
52 virtual void put_face (facetile *face);
53
54 virtual treasurelist *get_treasure (const char *name, bool one = false);
55 virtual void put_treasure (treasurelist *treasure);
56
57 virtual animation *get_animation (const char *name);
58 virtual void put_animation (animation *anim);
59};
60
61// pure base class for default archetype loader
62struct loader_arch : virtual loader_base {
63 archetype *get_arch (const char *name);
64 void put_arch (archetype *arch);
65};
66
67// pure base class for default object loader
68struct loader_object : virtual loader_base {
69 object *get_object (const char *name);
70 void put_object (object *op);
71};
72
73// pure base class for default player loader
74struct loader_player : virtual loader_base {
75 virtual player *get_player ();
76 virtual void put_player (player *pl);
77};
78
79// pure base class for default region loader
80struct loader_region : virtual loader_base {
81 region *get_region ();
82 void put_region (region *region);
83};
84
85// pure base class for default face loader
86struct loader_face : virtual loader_base {
87 facetile *get_face (const char *name);
88 void put_face (facetile *face);
89};
90
91// pure base class for default treasure loader
92struct loader_treasure : virtual loader_base {
93 treasurelist *get_treasure (const char *name, bool one = false);
94 void put_treasure (treasurelist *treasure);
95};
96
97// pure base class for default animation loader
98struct loader_animation : virtual loader_base {
99 animation *get_animation (const char *name);
100 void put_animation (animation *anim);
101};
102
103// future generic resource loader
104// handles generic stuff valid in most files, such as
105// animations, treasures, faces and so on
106struct loader_generic
107: virtual loader_base,
108 loader_object, loader_player,
109 loader_region, loader_face,
110 loader_treasure, loader_animation
111{ 36{
112 const char *type () const = 0; 37}
113};
114 38
115// the base class warns about and skips everything 39// the base class warns about and skips everything
116archetype * 40archetype *
117loader_base::get_arch (const char *name) 41loader_base::get_arch (const char *name)
118{ 42{
119 LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of type %s.\n", 43 LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of this type.\n",
120 filename, name, type ()); 44 filename, name);
121 45
122 return new archetype; 46 return new archetype;
123} 47}
124 48
125object * 49object *
126loader_base::get_object (const char *name) 50loader_base::get_object (const char *name)
127{ 51{
128 LOG (llevError, "%s: found object definition '%s', which is not allowed in files of type %s.\n", 52 LOG (llevError, "%s: found object definition '%s', which is not allowed in files of this type.\n",
129 filename, name, type ()); 53 filename, name);
130 54
131 return object::create (); 55 return object::create ();
132} 56}
133 57
134player * 58player *
135loader_base::get_player () 59loader_base::get_player ()
136{ 60{
137 LOG (llevError, "%s: found player definition, which is not allowed in files of type %s.\n", 61 LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n",
138 filename, type ()); 62 filename);
139 63
140 return player::create (); 64 return player::create ();
141} 65}
142 66
143region * 67region *
144loader_base::get_region (const char *name) 68loader_base::get_region (const char *name)
145{ 69{
146 LOG (llevError, "%s: found region definition '%s', which is not allowed in files of type %s.\n", 70 LOG (llevError, "%s: found region definition '%s', which is not allowed in files of this type.\n",
147 filename, name, type ()); 71 filename, name);
148 72
149 return new region; 73 return new region;
150} 74}
151 75
152facetile * 76facetile *
153loader_base::get_face (const char *name) 77loader_base::get_face (const char *name)
154{ 78{
155 LOG (llevError, "%s: found face definition '%s', which is not allowed in files of type %s.\n", 79 LOG (llevError, "%s: found face definition '%s', which is not allowed in files of this type.\n",
156 filename, name, type ()); 80 filename, name);
157 81
158 return new facetile; 82 return new facetile;
159} 83}
160 84
161treasurelist * 85treasurelist *
162loader_base::get_treasure (const char *name, bool one) 86loader_base::get_treasure (const char *name, bool one)
163{ 87{
164 LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of type %s.\n", 88 LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of this type.\n",
165 filename, name, type ()); 89 filename, name);
166 90
167 return new treasurelist;//D 91 return new treasurelist;//D
168} 92}
169 93
170animation * 94animation *
171loader_base::get_animation (const char *name) 95loader_base::get_animation (const char *name)
172{ 96{
173 LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of type %s.\n", 97 LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of this type.\n",
174 filename, name, type ()); 98 filename, name);
175 99
176 return new animation; 100 return new animation;
177} 101}
178 102
179void 103void
215void 139void
216loader_base::put_animation (animation *anim) 140loader_base::put_animation (animation *anim)
217{ 141{
218 delete anim; 142 delete anim;
219} 143}
144
145/////////////////////////////////////////////////////////////////////////////
146
147bool loader_base::parse (object_thawer &thawer)
148{
149 for (;;)
150 {
151 keyword kw = thawer.get_kv ();
152
153 switch (kw)
154 {
155 case KW_region:
156 {
157 region *rgn = get_region (thawer.get_str ());
158
159 if (!parse_region (thawer, rgn))
160 {
161 delete rgn;
162 return false;
163 }
164
165 put_region (rgn);
166 }
167 break;
168
169 case KW_EOF:
170 return true;
171
172 default:
173 if (!thawer.parse_error (kw, "resource file"))
174 return false;
175 }
176 }
177}
178
179bool loader_base::load (const char *filename)
180{
181 this->filename = filename;
182
183 object_thawer fp (filename);
184
185 if (!fp)
186 return false;
187
188 return parse (fp);
189}
190
191/////////////////////////////////////////////////////////////////////////////
220 192
221/* Maps the MOVE_* values to names */ 193/* Maps the MOVE_* values to names */
222static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; 194static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL };
223 195
224/* This table is only necessary to convert objects that existed before the 196/* This table is only necessary to convert objects that existed before the
898 case KW_path_denied: thawer.get (op->path_denied); break; 870 case KW_path_denied: thawer.get (op->path_denied); break;
899 case KW_invisible: thawer.get (op->invisible); break; 871 case KW_invisible: thawer.get (op->invisible); break;
900 case KW_magic: thawer.get (op->magic); break; 872 case KW_magic: thawer.get (op->magic); break;
901 case KW_state: thawer.get (op->state); break; 873 case KW_state: thawer.get (op->state); break;
902 case KW_move_slow_penalty: thawer.get (op->move_slow_penalty); break; 874 case KW_move_slow_penalty: thawer.get (op->move_slow_penalty); break;
903 case KW_material: thawer.get (op->material); break; 875 case KW_material: thawer.get (op->materials); break; //TODO: nuke
904 case KW_materialname: thawer.get (op->materialname); break; 876 case KW_materialname: thawer.get (op->materialname); break;
905 877
906 /* These are the new values */ 878 /* These are the new values */
907 case KW_move_block: set_move (op->move_block, thawer.get_str ()); break; 879 case KW_move_block: set_move (op->move_block, thawer.get_str ()); break;
908 case KW_move_allow: set_move (op->move_allow, thawer.get_str ()); break; 880 case KW_move_allow: set_move (op->move_allow, thawer.get_str ()); break;
1170 add_button_link (op, op->map, thawer.get_sint32 ()); 1142 add_button_link (op, op->map, thawer.get_sint32 ());
1171 break; 1143 break;
1172 1144
1173 case KW_randomitems: 1145 case KW_randomitems:
1174 op->randomitems = find_treasurelist (thawer.get_str ()); 1146 op->randomitems = find_treasurelist (thawer.get_str ());
1147 //if (!op->randomitems)
1148 // LOG (llevError, "%s uses unknown randomitems '%s'.\n", op->debug_desc (), thawer.get_str ());
1175 break; 1149 break;
1176 1150
1177 case KW_msg: 1151 case KW_msg:
1178 thawer.get_ml (KW_endmsg, op->msg); 1152 thawer.get_ml (KW_endmsg, op->msg);
1179 //TODO: allow longer messages 1153 //TODO: allow longer messages
1222 set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true); 1196 set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true);
1223 //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D 1197 //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D
1224 break; 1198 break;
1225 1199
1226 default: 1200 default:
1227 LOG (llevError, "UNSUPPORTED KEYWORD IN MAP: \"%s\", bug in normaliser. skipping.\n", keyword_str[kw]); 1201 if (!thawer.parse_error (kw, "object", op->name))
1202 return false;
1228 break; 1203 break;
1229 } 1204 }
1230 } 1205 }
1231} 1206}
1232 1207
1566 f.put (resist_save[i], op->resist[i]); 1541 f.put (resist_save[i], op->resist[i]);
1567 1542
1568 CMP_OUT (path_attuned); 1543 CMP_OUT (path_attuned);
1569 CMP_OUT (path_repelled); 1544 CMP_OUT (path_repelled);
1570 CMP_OUT (path_denied); 1545 CMP_OUT (path_denied);
1571 CMP_OUT (material); 1546 CMP_OUT2 (material, materials);//TODO: nuke
1572 CMP_OUT (materialname); 1547 CMP_OUT (materialname);
1573 CMP_OUT (value); 1548 CMP_OUT (value);
1574 CMP_OUT (carrying); 1549 CMP_OUT (carrying);
1575 CMP_OUT (weight); 1550 CMP_OUT (weight);
1576 CMP_OUT (invisible); 1551 CMP_OUT (invisible);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines