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.35 by root, Sat Jan 27 02:19:36 2007 UTC vs.
Revision 1.40 by root, Wed Mar 14 00:04:58 2007 UTC

194 return; 194 return;
195 } 195 }
196 while (fgets (buf, MAX_BUF, fp) != NULL) 196 while (fgets (buf, MAX_BUF, fp) != NULL)
197 { 197 {
198 line++; 198 line++;
199 if (*buf == '#') 199 if (*buf == '#' || *buf == '\n')
200 continue; 200 ; // ignore
201
202 if (sscanf (buf, "treasureone %s\n", name) || sscanf (buf, "treasure %s\n", name)) 201 else if (sscanf (buf, "treasureone %s\n", name) || sscanf (buf, "treasure %s\n", name))
203 { 202 {
204 treasurelist *tl = get_empty_treasurelist (); 203 treasurelist *tl = get_empty_treasurelist ();
205 204
206 tl->name = name; 205 tl->name = name;
207 if (previous == NULL) 206 if (previous == NULL)
208 first_treasurelist = tl; 207 first_treasurelist = tl;
209 else 208 else
210 previous->next = tl; 209 previous->next = tl;
210
211 previous = tl; 211 previous = tl;
212 tl->items = load_treasure (fp, &line); 212 tl->items = load_treasure (fp, &line);
213 213
214 /* This is a one of the many items on the list should be generated. 214 /* This is a one of the many items on the list should be generated.
215 * Add up the chance total, and check to make sure the yes & no 215 * Add up the chance total, and check to make sure the yes & no
433 * to do that. 433 * to do that.
434 */ 434 */
435void 435void
436create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries) 436create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
437{ 437{
438
439 if (tries++ > 100) 438 if (tries++ > 100)
440 { 439 {
441 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 440 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
442 return; 441 return;
443 } 442 }
443
444 if (tl->total_chance) 444 if (tl->total_chance)
445 create_one_treasure (tl, op, flag, difficulty, tries); 445 create_one_treasure (tl, op, flag, difficulty, tries);
446 else 446 else
447 create_all_treasures (tl->items, op, flag, difficulty, tries); 447 create_all_treasures (tl->items, op, flag, difficulty, tries);
448} 448}
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];
1350 artifact *art = NULL; 1349 artifact *art = NULL;
1351 linked_char *tmp;
1352 int value;
1353 artifactlist *al; 1350 artifactlist *al;
1354 1351
1355 if (has_been_inited) 1352 if (has_been_inited)
1356 return; 1353 return;
1357 else 1354 else
1358 has_been_inited = 1; 1355 has_been_inited = 1;
1359 1356
1360 sprintf (filename, "%s/artifacts", settings.datadir); 1357 sprintf (filename, "%s/artifacts", settings.datadir);
1361 object_thawer thawer (filename); 1358 object_thawer f (filename);
1362 1359
1363 if (!thawer) 1360 if (!f)
1364 return; 1361 return;
1365 1362
1366 while (fgets (buf, HUGE_BUF, thawer) != NULL) 1363 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 1364
1378 if (!strncmp (cp, "Allowed", 7)) 1365 for (;;)
1366 {
1367 switch (f.kw)
1379 { 1368 {
1369 case KW_allowed:
1380 if (art == NULL) 1370 if (!art)
1371 {
1372 art = get_empty_artifact ();
1373 nrofartifacts++;
1374 }
1375
1381 { 1376 {
1382 art = get_empty_artifact (); 1377 if (!strcmp (f.get_str (), "all"))
1383 nrofartifacts++; 1378 break;
1379
1380 char *next, *cp = f.get_str ();
1381
1382 do
1383 {
1384 nrofallowedstr++;
1385
1386 if ((next = strchr (cp, ',')))
1387 *next++ = '\0';
1388
1389 linked_char *tmp = new linked_char;
1390
1391 tmp->name = cp;
1392 tmp->next = art->allowed;
1393 art->allowed = tmp;
1394 }
1395 while ((cp = next));
1384 } 1396 }
1385 cp = strchr (cp, ' ') + 1; 1397 break;
1386 if (!strcmp (cp, "all")) 1398
1399 case KW_chance:
1400 f.get (art->chance);
1401 break;
1402
1403 case KW_difficulty:
1404 f.get (art->difficulty);
1405 break;
1406
1407 case KW_object:
1408 {
1409 art->item = object::create ();
1410
1411 if (!art->item->parse_kv (f))
1412 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1413
1414 al = find_artifactlist (art->item->type);
1415
1416 if (!al)
1417 {
1418 al = get_empty_artifactlist ();
1419 al->type = art->item->type;
1420 al->next = first_artifactlist;
1421 first_artifactlist = al;
1422 }
1423
1424 art->next = al->items;
1425 al->items = art;
1426 art = 0;
1427 }
1387 continue; 1428 continue;
1388 1429
1389 do 1430 case KW_EOF:
1431 goto done;
1432
1433 default:
1434 if (!f.parse_error ("artifacts file"))
1435 cleanup ("artifacts file required");
1390 { 1436 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))
1407 { 1437 }
1408 art->item = object::create ();
1409 1438
1410 if (!load_object (thawer, art->item, 0)) 1439 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 } 1440 }
1429 1441
1442done:
1430 for (al = first_artifactlist; al != NULL; al = al->next) 1443 for (al = first_artifactlist; al; al = al->next)
1431 { 1444 {
1432 for (art = al->items; art != NULL; art = art->next) 1445 for (art = al->items; art; art = art->next)
1433 { 1446 {
1434 if (!art->chance) 1447 if (!art->chance)
1435 LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name); 1448 LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name);
1436 else 1449 else
1437 al->total_chance += art->chance; 1450 al->total_chance += art->chance;
1619 op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100); 1632 op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100);
1620 } 1633 }
1621 1634
1622 op->value *= change->value; 1635 op->value *= change->value;
1623 1636
1624 if (change->material) 1637 if (change->materials)
1625 op->material = change->material; 1638 op->materials = change->materials;
1626 1639
1627 if (change->materialname) 1640 if (change->materialname)
1628 op->materialname = change->materialname; 1641 op->materialname = change->materialname;
1629 1642
1630 if (change->slaying) 1643 if (change->slaying)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines