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.27 by root, Wed Dec 20 09:14:21 2006 UTC vs.
Revision 1.30 by elmex, Wed Jan 3 02:30:51 2007 UTC

156 * so that the treasure name can be printed out 156 * so that the treasure name can be printed out
157 */ 157 */
158static void 158static void
159check_treasurelist (const treasure *t, const treasurelist * tl) 159check_treasurelist (const treasure *t, const treasurelist * tl)
160{ 160{
161 if (t->item == NULL && t->name == NULL)
162 LOG (llevError, "Treasurelist %s has element with no name or archetype\n", &tl->name);
163 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) 161 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no))
164 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); 162 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name);
165 /* find_treasurelist will print out its own error message */ 163 /* find_treasurelist will print out its own error message */
166 if (t->name && *t->name) 164 if (t->name && *t->name)
167 (void) find_treasurelist (t->name); 165 find_treasurelist (t->name);
168 if (t->next) 166 if (t->next)
169 check_treasurelist (t->next, tl); 167 check_treasurelist (t->next, tl);
170 if (t->next_yes) 168 if (t->next_yes)
171 check_treasurelist (t->next_yes, tl); 169 check_treasurelist (t->next_yes, tl);
172 if (t->next_no) 170 if (t->next_no)
292 * this is the original object, or if this is an object that should be created 290 * this is the original object, or if this is an object that should be created
293 * by another object. 291 * by another object.
294 */ 292 */
295 if (flags & GT_ENVIRONMENT && op->type != SPELL) 293 if (flags & GT_ENVIRONMENT && op->type != SPELL)
296 { 294 {
297 op->x = creator->x;
298 op->y = creator->y;
299 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 295 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
300 insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); 296 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
301 } 297 }
302 else 298 else
303 { 299 {
304 op = insert_ob_in_ob (op, creator); 300 op = creator->insert (op);
305 301
306 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 302 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
307 monster_check_apply (creator, op); 303 monster_check_apply (creator, op);
308 304
309 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) 305 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ()))
338 334
339 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 335 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
340 { 336 {
341 if (t->name) 337 if (t->name)
342 { 338 {
343 if (strcmp (t->name, "NONE") && difficulty >= t->magic) 339 if (difficulty >= t->magic)
344 { 340 {
345 treasurelist *tl = find_treasurelist (t->name); 341 treasurelist *tl = find_treasurelist (t->name);
346 if (tl) 342 if (tl)
347 create_treasure (tl, op, flag, difficulty, tries); 343 create_treasure (tl, op, flag, difficulty, tries);
348 } 344 }
349 } 345 }
350 else 346 else
351 { 347 {
352 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) 348 if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)))
353 { 349 {
354 tmp = arch_to_object (t->item); 350 tmp = arch_to_object (t->item);
355 if (t->nrof && tmp->nrof <= 1) 351 if (t->nrof && tmp->nrof <= 1)
356 tmp->nrof = RANDOM () % ((int) t->nrof) + 1; 352 tmp->nrof = RANDOM () % ((int) t->nrof) + 1;
357 fix_generated_item (tmp, op, difficulty, t->magic, flag); 353 fix_generated_item (tmp, op, difficulty, t->magic, flag);
397 return; 393 return;
398 } 394 }
399 395
400 if (t->name) 396 if (t->name)
401 { 397 {
402 if (!strcmp (t->name, "NONE"))
403 return;
404
405 if (difficulty >= t->magic) 398 if (difficulty >= t->magic)
406 { 399 {
407 treasurelist *tl = find_treasurelist (t->name); 400 treasurelist *tl = find_treasurelist (t->name);
408 if (tl) 401 if (tl)
409 create_treasure (tl, op, flag, difficulty, tries); 402 create_treasure (tl, op, flag, difficulty, tries);
412 create_one_treasure (tl, op, flag, difficulty, tries); 405 create_one_treasure (tl, op, flag, difficulty, tries);
413 406
414 return; 407 return;
415 } 408 }
416 409
417 if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) 410 if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE))
418 { 411 {
419 object *tmp = arch_to_object (t->item); 412 object *tmp = arch_to_object (t->item);
420 413
421 if (!tmp) 414 if (!tmp)
422 return; 415 return;
436 * list transitions, or so that excessively good treasure will not be 429 * list transitions, or so that excessively good treasure will not be
437 * created on weak maps, because it will exceed the number of allowed tries 430 * created on weak maps, because it will exceed the number of allowed tries
438 * to do that. 431 * to do that.
439 */ 432 */
440void 433void
441create_treasure (treasurelist * t, object *op, int flag, int difficulty, int tries) 434create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
442{ 435{
443 436
444 if (tries++ > 100) 437 if (tries++ > 100)
445 { 438 {
446 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 439 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
447 return; 440 return;
448 } 441 }
449 if (t->total_chance) 442 if (tl->total_chance)
450 create_one_treasure (t, op, flag, difficulty, tries); 443 create_one_treasure (tl, op, flag, difficulty, tries);
451 else 444 else
452 create_all_treasures (t->items, op, flag, difficulty, tries); 445 create_all_treasures (tl->items, op, flag, difficulty, tries);
453} 446}
454 447
455/* This is similar to the old generate treasure function. However, 448/* This is similar to the old generate treasure function. However,
456 * it instead takes a treasurelist. It is really just a wrapper around 449 * it instead takes a treasurelist. It is really just a wrapper around
457 * create_treasure. We create a dummy object that the treasure gets 450 * create_treasure. We create a dummy object that the treasure gets
458 * inserted into, and then return that treausre 451 * inserted into, and then return that treausre
459 */ 452 */
460object * 453object *
461generate_treasure (treasurelist *t, int difficulty) 454generate_treasure (treasurelist *tl, int difficulty)
462{ 455{
463 difficulty = clamp (difficulty, 1, settings.max_level); 456 difficulty = clamp (difficulty, 1, settings.max_level);
464 457
465 object *ob = object::create (), *tmp; 458 object *ob = object::create (), *tmp;
466 459
467 create_treasure (t, ob, 0, difficulty, 0); 460 create_treasure (tl, ob, 0, difficulty, 0);
468 461
469 /* Don't want to free the object we are about to return */ 462 /* Don't want to free the object we are about to return */
470 tmp = ob->inv; 463 tmp = ob->inv;
471 if (tmp != NULL) 464 if (tmp != NULL)
472 tmp->remove (); 465 tmp->remove ();
1178 */ 1171 */
1179 1172
1180static artifactlist * 1173static artifactlist *
1181get_empty_artifactlist (void) 1174get_empty_artifactlist (void)
1182{ 1175{
1183 artifactlist *tl = (artifactlist *) malloc (sizeof (artifactlist)); 1176 artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist));
1184 1177
1185 if (tl == NULL) 1178 if (al == NULL)
1186 fatal (OUT_OF_MEMORY); 1179 fatal (OUT_OF_MEMORY);
1187 tl->next = NULL; 1180 al->next = NULL;
1188 tl->items = NULL; 1181 al->items = NULL;
1189 tl->total_chance = 0; 1182 al->total_chance = 0;
1190 return tl; 1183 return al;
1191} 1184}
1192 1185
1193/* 1186/*
1194 * Allocate and return the pointer to an empty artifact structure. 1187 * Allocate and return the pointer to an empty artifact structure.
1195 */ 1188 */
1196 1189
1197static artifact * 1190static artifact *
1198get_empty_artifact (void) 1191get_empty_artifact (void)
1199{ 1192{
1200 artifact *t = (artifact *) malloc (sizeof (artifact)); 1193 artifact *a = (artifact *) malloc (sizeof (artifact));
1201 1194
1202 if (t == NULL) 1195 if (a == NULL)
1203 fatal (OUT_OF_MEMORY); 1196 fatal (OUT_OF_MEMORY);
1204 t->item = NULL; 1197 a->item = NULL;
1205 t->next = NULL; 1198 a->next = NULL;
1206 t->chance = 0; 1199 a->chance = 0;
1207 t->difficulty = 0; 1200 a->difficulty = 0;
1208 t->allowed = NULL; 1201 a->allowed = NULL;
1209 return t; 1202 return a;
1210} 1203}
1211 1204
1212/* 1205/*
1213 * Searches the artifact lists and returns one that has the same type 1206 * Searches the artifact lists and returns one that has the same type
1214 * of objects on it. 1207 * of objects on it.
1264 treasurelist *tl; 1257 treasurelist *tl;
1265 int i; 1258 int i;
1266 1259
1267 if (depth > 100) 1260 if (depth > 100)
1268 return; 1261 return;
1269 while (t != NULL) 1262 while (t)
1270 { 1263 {
1271 if (t->name != NULL) 1264 if (t->name)
1272 { 1265 {
1273 for (i = 0; i < depth; i++) 1266 for (i = 0; i < depth; i++)
1274 fprintf (logfile, " "); 1267 fprintf (logfile, " ");
1275 fprintf (logfile, "{ (list: %s)\n", &t->name); 1268 fprintf (logfile, "{ (list: %s)\n", &t->name);
1276 tl = find_treasurelist (t->name); 1269 tl = find_treasurelist (t->name);
1282 } 1275 }
1283 else 1276 else
1284 { 1277 {
1285 for (i = 0; i < depth; i++) 1278 for (i = 0; i < depth; i++)
1286 fprintf (logfile, " "); 1279 fprintf (logfile, " ");
1287 if (t->item->clone.type == FLESH) 1280 if (t->item && t->item->clone.type == FLESH)
1288 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); 1281 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name);
1289 else 1282 else
1290 fprintf (logfile, "%s\n", &t->item->clone.name); 1283 fprintf (logfile, "%s\n", &t->item->clone.name);
1291 } 1284 }
1285
1292 if (t->next_yes != NULL) 1286 if (t->next_yes)
1293 { 1287 {
1294 for (i = 0; i < depth; i++) 1288 for (i = 0; i < depth; i++)
1295 fprintf (logfile, " "); 1289 fprintf (logfile, " ");
1296 fprintf (logfile, " (if yes)\n"); 1290 fprintf (logfile, " (if yes)\n");
1297 dump_monster_treasure_rec (name, t->next_yes, depth + 1); 1291 dump_monster_treasure_rec (name, t->next_yes, depth + 1);
1298 } 1292 }
1293
1299 if (t->next_no != NULL) 1294 if (t->next_no)
1300 { 1295 {
1301 for (i = 0; i < depth; i++) 1296 for (i = 0; i < depth; i++)
1302 fprintf (logfile, " "); 1297 fprintf (logfile, " ");
1303 fprintf (logfile, " (if no)\n"); 1298 fprintf (logfile, " (if no)\n");
1304 dump_monster_treasure_rec (name, t->next_no, depth + 1); 1299 dump_monster_treasure_rec (name, t->next_no, depth + 1);
1305 } 1300 }
1301
1306 t = t->next; 1302 t = t->next;
1307 } 1303 }
1308} 1304}
1309 1305
1310/* 1306/*
1499 CLEAR_FLAG (op, FLAG_ANIMATE); 1495 CLEAR_FLAG (op, FLAG_ANIMATE);
1500 /* so artifacts will join */ 1496 /* so artifacts will join */
1501 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1497 if (!QUERY_FLAG (op, FLAG_ALIVE))
1502 op->speed = 0.0; 1498 op->speed = 0.0;
1503 1499
1504 update_ob_speed (op); 1500 op->set_speed (op->speed);
1505 } 1501 }
1506 1502
1507 if (change->nrof) 1503 if (change->nrof)
1508 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1504 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1509 1505
1810/* special_potion() - so that old potion code is still done right. */ 1806/* special_potion() - so that old potion code is still done right. */
1811 1807
1812int 1808int
1813special_potion (object *op) 1809special_potion (object *op)
1814{ 1810{
1815
1816 int i;
1817
1818 if (op->attacktype) 1811 if (op->attacktype)
1819 return 1; 1812 return 1;
1820 1813
1821 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) 1814 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1822 return 1; 1815 return 1;
1823 1816
1824 for (i = 0; i < NROFATTACKS; i++) 1817 for (int i = 0; i < NROFATTACKS; i++)
1825 if (op->resist[i]) 1818 if (op->resist[i])
1826 return 1; 1819 return 1;
1827 1820
1828 return 0; 1821 return 0;
1829} 1822}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines