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

Comparing deliantra/server/common/treasure.C (file contents):
Revision 1.4 by root, Tue Aug 29 08:01:36 2006 UTC vs.
Revision 1.5 by root, Wed Aug 30 06:06:27 2006 UTC

1 1
2/* 2/*
3 * static char *rcs_treasure_c = 3 * static char *rcs_treasure_c =
4 * "$Id: treasure.C,v 1.4 2006/08/29 08:01:36 root Exp $"; 4 * "$Id: treasure.C,v 1.5 2006/08/30 06:06:27 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
1270 * Builds up the lists of artifacts from the file in the libdir. 1270 * Builds up the lists of artifacts from the file in the libdir.
1271 */ 1271 */
1272 1272
1273void init_artifacts(void) { 1273void init_artifacts(void) {
1274 static int has_been_inited=0; 1274 static int has_been_inited=0;
1275 FILE *fp_;
1276 char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; 1275 char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next;
1277 artifact *art=NULL; 1276 artifact *art=NULL;
1278 linked_char *tmp; 1277 linked_char *tmp;
1279 int value, comp; 1278 int value, comp;
1280 artifactlist *al; 1279 artifactlist *al;
1281 1280
1282 if (has_been_inited) return; 1281 if (has_been_inited) return;
1283 else has_been_inited = 1; 1282 else has_been_inited = 1;
1284 1283
1285 sprintf(filename, "%s/artifacts", settings.datadir); 1284 sprintf(filename, "%s/artifacts", settings.datadir);
1286 LOG(llevDebug, "Reading artifacts from %s...",filename); 1285 object_thawer thawer (filename);
1287 if ((fp_ = open_and_uncompress(filename, 0, &comp)) == NULL) { 1286
1288 LOG(llevError, "Can't open %s.\n", filename); 1287 if (!thawer)
1289 return; 1288 return;
1290 }
1291 1289
1292 object_thawer fp (fp_);
1293
1294 while (fgets(buf, HUGE_BUF, fp)!=NULL) { 1290 while (fgets(buf, HUGE_BUF, thawer)!=NULL) {
1295 if (*buf=='#') continue; 1291 if (*buf=='#') continue;
1296 if((cp=strchr(buf,'\n'))!=NULL) 1292 if((cp=strchr(buf,'\n'))!=NULL)
1297 *cp='\0'; 1293 *cp='\0';
1298 cp=buf; 1294 cp=buf;
1299 while(*cp==' ') /* Skip blanks */ 1295 while(*cp==' ') /* Skip blanks */
1323 else if (sscanf(cp, "difficulty %d", &value)) 1319 else if (sscanf(cp, "difficulty %d", &value))
1324 art->difficulty = (uint8) value; 1320 art->difficulty = (uint8) value;
1325 else if (!strncmp(cp, "Object",6)) { 1321 else if (!strncmp(cp, "Object",6)) {
1326 art->item = (object *) calloc(1, sizeof(object)); 1322 art->item = (object *) calloc(1, sizeof(object));
1327 reset_object(art->item); 1323 reset_object(art->item);
1328 if (!load_object(fp, art->item,LO_LINEMODE,0)) 1324 if (!load_object(thawer, art->item,LO_LINEMODE,0))
1329 LOG(llevError,"Init_Artifacts: Could not load object.\n"); 1325 LOG(llevError,"Init_Artifacts: Could not load object.\n");
1330 art->item->name = add_string((strchr(cp, ' ')+1)); 1326 art->item->name = add_string((strchr(cp, ' ')+1));
1331 al=find_artifactlist(art->item->type); 1327 al=find_artifactlist(art->item->type);
1332 if (al==NULL) { 1328 if (al==NULL) {
1333 al = get_empty_artifactlist(); 1329 al = get_empty_artifactlist();
1340 art = NULL; 1336 art = NULL;
1341 } 1337 }
1342 else 1338 else
1343 LOG(llevError,"Unknown input in artifact file: %s\n", buf); 1339 LOG(llevError,"Unknown input in artifact file: %s\n", buf);
1344 } 1340 }
1345
1346 close_and_delete(fp, comp);
1347 1341
1348 for (al=first_artifactlist; al!=NULL; al=al->next) { 1342 for (al=first_artifactlist; al!=NULL; al=al->next) {
1349 for (art=al->items; art!=NULL; art=art->next) { 1343 for (art=al->items; art!=NULL; art=art->next) {
1350 if (!art->chance) 1344 if (!art->chance)
1351 LOG(llevError,"Warning: artifact with no chance: %s\n", art->item->name); 1345 LOG(llevError,"Warning: artifact with no chance: %s\n", art->item->name);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines