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.37 by root, Thu Feb 8 03:09:31 2007 UTC vs.
Revision 1.38 by root, Fri Feb 16 19:43:41 2007 UTC

831 * value. 831 * value.
832 * GT_MINIMAL: Does minimal processing on the object - just enough to make it 832 * GT_MINIMAL: Does minimal processing on the object - just enough to make it
833 * a working object - don't change magic, value, etc, but set it material 833 * a working object - don't change magic, value, etc, but set it material
834 * type as appropriate, for objects that need spell objects, set those, etc 834 * type as appropriate, for objects that need spell objects, set those, etc
835 */ 835 */
836
837void 836void
838fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags) 837fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags)
839{ 838{
840 int was_magic = op->magic, num_enchantments = 0, save_item_power = 0; 839 int was_magic = op->magic, num_enchantments = 0, save_item_power = 0;
841 840
1174 */ 1173 */
1175 1174
1176/* 1175/*
1177 * Allocate and return the pointer to an empty artifactlist structure. 1176 * Allocate and return the pointer to an empty artifactlist structure.
1178 */ 1177 */
1179
1180static artifactlist * 1178static artifactlist *
1181get_empty_artifactlist (void) 1179get_empty_artifactlist (void)
1182{ 1180{
1183 artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist)); 1181 artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist));
1184 1182
1191} 1189}
1192 1190
1193/* 1191/*
1194 * Allocate and return the pointer to an empty artifact structure. 1192 * Allocate and return the pointer to an empty artifact structure.
1195 */ 1193 */
1196
1197static artifact * 1194static artifact *
1198get_empty_artifact (void) 1195get_empty_artifact (void)
1199{ 1196{
1200 artifact *a = (artifact *) malloc (sizeof (artifact)); 1197 artifact *a = (artifact *) malloc (sizeof (artifact));
1201 1198
1202 if (a == NULL) 1199 if (a == NULL)
1203 fatal (OUT_OF_MEMORY); 1200 fatal (OUT_OF_MEMORY);
1201
1204 a->item = NULL; 1202 a->item = NULL;
1205 a->next = NULL; 1203 a->next = NULL;
1206 a->chance = 0; 1204 a->chance = 0;
1207 a->difficulty = 0; 1205 a->difficulty = 0;
1208 a->allowed = NULL; 1206 a->allowed = NULL;
1211 1209
1212/* 1210/*
1213 * Searches the artifact lists and returns one that has the same type 1211 * Searches the artifact lists and returns one that has the same type
1214 * of objects on it. 1212 * of objects on it.
1215 */ 1213 */
1216
1217artifactlist * 1214artifactlist *
1218find_artifactlist (int type) 1215find_artifactlist (int type)
1219{ 1216{
1220 artifactlist *al; 1217 artifactlist *al;
1221 1218
1222 for (al = first_artifactlist; al != NULL; al = al->next) 1219 for (al = first_artifactlist; al; al = al->next)
1223 if (al->type == type) 1220 if (al->type == type)
1224 return al; 1221 return al;
1222
1225 return NULL; 1223 return 0;
1226} 1224}
1227 1225
1228/* 1226/*
1229 * For debugging purposes. Dumps all tables. 1227 * For debugging purposes. Dumps all tables.
1230 */ 1228 */
1231
1232void 1229void
1233dump_artifacts (void) 1230dump_artifacts (void)
1234{ 1231{
1235 artifactlist *al; 1232 artifactlist *al;
1236 artifact *art; 1233 artifact *art;
1243 for (art = al->items; art != NULL; art = art->next) 1240 for (art = al->items; art != NULL; art = art->next)
1244 { 1241 {
1245 fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance); 1242 fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance);
1246 if (art->allowed != NULL) 1243 if (art->allowed != NULL)
1247 { 1244 {
1248 fprintf (logfile, "\tAllowed combinations:"); 1245 fprintf (logfile, "\tallowed combinations:");
1249 for (next = art->allowed; next != NULL; next = next->next) 1246 for (next = art->allowed; next != NULL; next = next->next)
1250 fprintf (logfile, "%s,", &next->name); 1247 fprintf (logfile, "%s,", &next->name);
1251 fprintf (logfile, "\n"); 1248 fprintf (logfile, "\n");
1252 } 1249 }
1253 } 1250 }
1321 archetype *at; 1318 archetype *at;
1322 int found; 1319 int found;
1323 1320
1324 found = 0; 1321 found = 0;
1325 fprintf (logfile, "\n"); 1322 fprintf (logfile, "\n");
1323
1326 for (at = first_archetype; at != NULL; at = at->next) 1324 for (at = first_archetype; at != NULL; at = at->next)
1327 if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL) 1325 if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL)
1328 { 1326 {
1329 fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->name); 1327 fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->name);
1330 if (at->clone.randomitems != NULL) 1328 if (at->clone.randomitems != NULL)
1331 dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1); 1329 dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1);
1332 else 1330 else
1333 fprintf (logfile, "(nothing)\n"); 1331 fprintf (logfile, "(nothing)\n");
1332
1334 fprintf (logfile, "\n"); 1333 fprintf (logfile, "\n");
1335 found++; 1334 found++;
1336 } 1335 }
1336
1337 if (found == 0) 1337 if (found == 0)
1338 fprintf (logfile, "No objects have the name %s!\n\n", name); 1338 fprintf (logfile, "No objects have the name %s!\n\n", name);
1339} 1339}
1340 1340
1341/* 1341/*
1342 * Builds up the lists of artifacts from the file in the libdir. 1342 * Builds up the lists of artifacts from the file in the libdir.
1343 */ 1343 */
1344
1345void 1344void
1346init_artifacts (void) 1345init_artifacts (void)
1347{ 1346{
1348 static int has_been_inited = 0; 1347 static int has_been_inited = 0;
1349 char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; 1348 char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next;
1350 artifact *art = NULL; 1349 artifact *art = NULL;
1351 linked_char *tmp;
1352 int value; 1350 int value;
1353 artifactlist *al; 1351 artifactlist *al;
1354 1352
1355 if (has_been_inited) 1353 if (has_been_inited)
1356 return; 1354 return;
1357 else 1355 else
1358 has_been_inited = 1; 1356 has_been_inited = 1;
1359 1357
1360 sprintf (filename, "%s/artifacts", settings.datadir); 1358 sprintf (filename, "%s/artifacts", settings.datadir);
1361 object_thawer thawer (filename); 1359 object_thawer f (filename);
1362 1360
1363 if (!thawer) 1361 if (!f)
1364 return; 1362 return;
1365 1363
1366 while (fgets (buf, HUGE_BUF, thawer) != NULL) 1364 f.next ();
1367 {
1368 if (*buf == '#')
1369 continue;
1370 if ((cp = strchr (buf, '\n')) != NULL)
1371 *cp = '\0';
1372 cp = buf;
1373 while (*cp == ' ') /* Skip blanks */
1374 cp++;
1375 if (*cp == '\0')
1376 continue;
1377 1365
1378 if (!strncmp (cp, "Allowed", 7)) 1366 for (;;)
1367 {
1368 switch (f.kw)
1379 { 1369 {
1370 case KW_allowed:
1380 if (art == NULL) 1371 if (!art)
1372 {
1373 art = get_empty_artifact ();
1374 nrofartifacts++;
1375 }
1376
1381 { 1377 {
1382 art = get_empty_artifact (); 1378 if (!strcmp (f.get_str (), "all"))
1383 nrofartifacts++; 1379 break;
1380
1381 char *next, *cp = f.get_str ();
1382
1383 do
1384 {
1385 nrofallowedstr++;
1386
1387 if ((next = strchr (cp, ',')))
1388 *next++ = '\0';
1389
1390 linked_char *tmp = new linked_char;
1391
1392 tmp->name = cp;
1393 tmp->next = art->allowed;
1394 art->allowed = tmp;
1395 }
1396 while ((cp = next));
1384 } 1397 }
1385 cp = strchr (cp, ' ') + 1; 1398 break;
1386 if (!strcmp (cp, "all")) 1399
1400 case KW_chance:
1401 f.get (art->chance);
1402 break;
1403
1404 case KW_difficulty:
1405 f.get (art->difficulty);
1406 break;
1407
1408 case KW_object:
1409 {
1410 art->item = object::create ();
1411
1412 if (!art->item->parse_kv (f))
1413 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1414
1415 al = find_artifactlist (art->item->type);
1416
1417 if (!al)
1418 {
1419 al = get_empty_artifactlist ();
1420 al->type = art->item->type;
1421 al->next = first_artifactlist;
1422 first_artifactlist = al;
1423 }
1424
1425 art->next = al->items;
1426 al->items = art;
1427 art = 0;
1428 }
1387 continue; 1429 continue;
1388 1430
1389 do 1431 case KW_EOF:
1432 goto done;
1433
1434 default:
1435 if (!f.parse_error ("artifacts file"))
1436 cleanup ("artifacts file required");
1390 { 1437 break;
1391 nrofallowedstr++;
1392 if ((next = strchr (cp, ',')) != NULL)
1393 *(next++) = '\0';
1394 tmp = new linked_char;
1395
1396 tmp->name = cp;
1397 tmp->next = art->allowed;
1398 art->allowed = tmp;
1399 }
1400 while ((cp = next) != NULL);
1401 }
1402 else if (sscanf (cp, "chance %d", &value))
1403 art->chance = (uint16) value;
1404 else if (sscanf (cp, "difficulty %d", &value))
1405 art->difficulty = (uint8) value;
1406 else if (!strncmp (cp, "Object", 6) || !strncmp (cp, "object", 6))
1407 { 1438 }
1408 art->item = object::create ();
1409 1439
1410 if (!load_object (thawer, art->item, 0)) 1440 f.next ();
1411 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1412
1413 art->item->name = strchr (cp, ' ') + 1;
1414 al = find_artifactlist (art->item->type);
1415 if (al == NULL)
1416 {
1417 al = get_empty_artifactlist ();
1418 al->type = art->item->type;
1419 al->next = first_artifactlist;
1420 first_artifactlist = al;
1421 }
1422 art->next = al->items;
1423 al->items = art;
1424 art = NULL;
1425 }
1426 else
1427 LOG (llevError, "Unknown input in artifact file: %s\n", buf);
1428 } 1441 }
1429 1442
1443done:
1430 for (al = first_artifactlist; al != NULL; al = al->next) 1444 for (al = first_artifactlist; al; al = al->next)
1431 { 1445 {
1432 for (art = al->items; art != NULL; art = art->next) 1446 for (art = al->items; art; art = art->next)
1433 { 1447 {
1434 if (!art->chance) 1448 if (!art->chance)
1435 LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name); 1449 LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name);
1436 else 1450 else
1437 al->total_chance += art->chance; 1451 al->total_chance += art->chance;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines