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

Comparing deliantra/server/server/init.C (file contents):
Revision 1.67 by root, Sun Dec 28 05:44:58 2008 UTC vs.
Revision 1.68 by root, Sun Dec 28 06:59:27 2008 UTC

33 materialtype_t *mt; 33 materialtype_t *mt;
34 int i; 34 int i;
35 35
36 mt = new materialtype_t; 36 mt = new materialtype_t;
37 37
38 mt->name = 0; 38 mt->name = shstr_unknown;
39 mt->description = 0; 39 mt->description = 0;
40 40
41 for (i = 0; i < NROFATTACKS; i++) 41 for (i = 0; i < NROFATTACKS; i++)
42 { 42 {
43 mt->save[i] = 0; 43 mt->save[i] = 0;
61 61
62void 62void
63load_materials (void) 63load_materials (void)
64{ 64{
65 char filename[MAX_BUF]; 65 char filename[MAX_BUF];
66 materialtype_t *mt;
67 66
68 sprintf (filename, "%s/materials", settings.datadir); 67 sprintf (filename, "%s/materials", settings.datadir);
69 LOG (llevDebug, "Reading material type data from %s...\n", filename); 68 LOG (llevDebug, "Reading material type data from %s...\n", filename);
69
70 //TODO: somehow free old materials, or update them in-place
71 materialt = 0;
70 72
71 object_thawer thawer (filename); 73 object_thawer thawer (filename);
72 74
73 if (!thawer) 75 if (!thawer)
74 { 76 {
75 LOG (llevError, "Cannot open %s for reading\n", filename); 77 LOG (llevError, "Cannot open %s for reading\n", filename);
76 mt = get_empty_mat (); 78 goto done;
77 mt->next = 0; 79 }
78 materialt = mt; 80
79 return; 81 while (thawer.kw != KW_name)
80 } 82 {
83 thawer.next ();
81 84
82 mt = get_empty_mat (); 85 if (thawer.kw == KW_EOF)
83 materialt = mt; 86 goto done;
87 }
88
89 materialtype_t *mt;
84 90
85 for (;;) 91 for (;;)
86 { 92 {
87 thawer.next ();
88
89 switch (thawer.kw) 93 switch (thawer.kw)
90 { 94 {
91 case KW_name: 95 case KW_name:
92 /* clean up the previous entry */
93 if (mt->next)
94 {
95 if (!mt->description)
96 mt->description = mt->name;
97
98 mt = mt->next;
99 }
100
101 mt->next = get_empty_mat (); 96 mt = get_empty_mat ();
97 mt->next = materialt;
98 materialt = mt;
99
102 thawer.get (mt->name); 100 thawer.get (mt->name);
101 mt->description = mt->name;
103 break; 102 break;
104 103
105 case KW_description: 104 case KW_description:
106 thawer.get (mt->description); 105 thawer.get (mt->description);
107 break; 106 break;
171 default: 170 default:
172 if (!thawer.parse_error ("materials file", "materials")) 171 if (!thawer.parse_error ("materials file", "materials"))
173 goto done; 172 goto done;
174 break; 173 break;
175 } 174 }
175
176 thawer.next ();
176 } 177 }
177 178
178done: 179done:
179 if (mt->next) 180 if (!materialt)
180 { 181 materialt = get_empty_mat ();
181 delete mt->next;
182
183 mt->next = 0;
184 }
185 182
186 LOG (llevDebug, "Done.\n"); 183 LOG (llevDebug, "Done.\n");
187} 184}
188 185
189/* This loads the settings file. There could be debate whether this should 186/* This loads the settings file. There could be debate whether this should

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines