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.48 by root, Tue Apr 17 18:40:31 2007 UTC vs.
Revision 1.54 by root, Sat Apr 21 17:34:23 2007 UTC

145 coroapi::cede_to_tick_every (10); 145 coroapi::cede_to_tick_every (10);
146 146
147 switch (f.kw) 147 switch (f.kw)
148 { 148 {
149 case KW_arch: 149 case KW_arch:
150 if (!(t->item = archetype::find (f.get_str ()))) 150 t->item = archetype::get (f.get_str ());
151 LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ());
152 break; 151 break;
153 152
154 case KW_list: f.get (t->name); break; 153 case KW_list: f.get (t->name); break;
155 case KW_change_name: f.get (t->change_arch.name); break; 154 case KW_change_name: f.get (t->change_arch.name); break;
156 case KW_change_title: f.get (t->change_arch.title); break; 155 case KW_change_title: f.get (t->change_arch.title); break;
231 * start with equipment, but only their abilities). 230 * start with equipment, but only their abilities).
232 */ 231 */
233static void 232static void
234put_treasure (object *op, object *creator, int flags) 233put_treasure (object *op, object *creator, int flags)
235{ 234{
236 object *tmp;
237
238 /* Bit of a hack - spells should never be put onto the map. The entire 235 /* Bit of a hack - spells should never be put onto the map. The entire
239 * treasure stuff is a problem - there is no clear idea of knowing 236 * treasure stuff is a problem - there is no clear idea of knowing
240 * this is the original object, or if this is an object that should be created 237 * this is the original object, or if this is an object that should be created
241 * by another object. 238 * by another object.
242 */ 239 */
243 if (flags & GT_ENVIRONMENT && op->type != SPELL) 240 if (flags & GT_ENVIRONMENT && op->type != SPELL)
244 { 241 {
242 op->expand_tail ();
243
244 if (ob_blocked (op, creator->map, creator->x, creator->y))
245 op->destroy ();
246 else
247 {
245 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 248 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
246 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); 249 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
250 }
247 } 251 }
248 else 252 else
249 { 253 {
250 op = creator->insert (op); 254 op = creator->insert (op);
251 255
252 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 256 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
253 monster_check_apply (creator, op); 257 monster_check_apply (creator, op);
254 258
255 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) 259 if (flags & GT_UPDATE_INV)
260 if (object *tmp = creator->in_player ())
256 esrv_send_item (tmp, op); 261 esrv_send_item (tmp, op);
257 } 262 }
258} 263}
259 264
260/* if there are change_xxx commands in the treasure, we include the changes 265/* if there are change_xxx commands in the treasure, we include the changes
261 * in the generated object 266 * in the generated object
397object * 402object *
398generate_treasure (treasurelist *tl, int difficulty) 403generate_treasure (treasurelist *tl, int difficulty)
399{ 404{
400 difficulty = clamp (difficulty, 1, settings.max_level); 405 difficulty = clamp (difficulty, 1, settings.max_level);
401 406
402 object *ob = object::create (), *tmp; 407 object *ob = object::create ();
403 408
404 create_treasure (tl, ob, 0, difficulty, 0); 409 create_treasure (tl, ob, 0, difficulty, 0);
405 410
406 /* Don't want to free the object we are about to return */ 411 /* Don't want to free the object we are about to return */
407 tmp = ob->inv; 412 object *tmp = ob->inv;
408 if (tmp != NULL) 413 if (tmp)
409 tmp->remove (); 414 tmp->remove ();
410 415
411 if (ob->inv) 416 if (ob->inv)
412 LOG (llevError, "In generate treasure, created multiple objects.\n"); 417 LOG (llevError, "In generate treasure, created multiple objects.\n");
413 418
421 * The array has two arguments, the difficulty of the level, and the 426 * The array has two arguments, the difficulty of the level, and the
422 * magical bonus "wanted". 427 * magical bonus "wanted".
423 */ 428 */
424 429
425static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { 430static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = {
426
427// chance of magic difficulty 431// chance of magic difficulty
428// +0 +1 +2 +3 +4 432// +0 +1 +2 +3 +4
429 {95, 2, 2, 1, 0}, // 1 433 {95, 2, 2, 1, 0}, // 1
430 {92, 5, 2, 1, 0}, // 2 434 {92, 5, 2, 1, 0}, // 2
431 {85, 10, 4, 1, 0}, // 3 435 {85, 10, 4, 1, 0}, // 3
457 { 0, 0, 0, 3, 97}, // 29 461 { 0, 0, 0, 3, 97}, // 29
458 { 0, 0, 0, 0, 100}, // 30 462 { 0, 0, 0, 0, 100}, // 30
459 { 0, 0, 0, 0, 100}, // 31 463 { 0, 0, 0, 0, 100}, // 31
460}; 464};
461 465
462
463/* calculate the appropriate level for wands staves and scrolls. 466/* calculate the appropriate level for wands staves and scrolls.
464 * This code presumes that op has had its spell object created (in op->inv) 467 * This code presumes that op has had its spell object created (in op->inv)
465 * 468 *
466 * elmex Wed Aug 9 17:44:59 CEST 2006: 469 * elmex Wed Aug 9 17:44:59 CEST 2006:
467 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 470 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
468 */ 471 */
469
470int 472int
471level_for_item (const object *op, int difficulty) 473level_for_item (const object *op, int difficulty)
472{ 474{
473 int olevel = 0; 475 int olevel = 0;
474 476
784 save_item_power = op->item_power; 786 save_item_power = op->item_power;
785 op->item_power = 0; 787 op->item_power = 0;
786 788
787 if (op->randomitems && op->type != SPELL) 789 if (op->randomitems && op->type != SPELL)
788 { 790 {
789 create_treasure (op->randomitems, op, flags, difficulty, 0); 791 create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0);
790 if (!op->inv)
791 LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ());
792
793 /* So the treasure doesn't get created again */ 792 /* So the treasure doesn't get created again */
794 op->randomitems = 0; 793 op->randomitems = 0;
795 } 794 }
796 795
797 if (difficulty < 1) 796 if (difficulty < 1)
1327 break; 1326 break;
1328 1327
1329 case KW_object: 1328 case KW_object:
1330 { 1329 {
1331 art->item = object::create (); 1330 art->item = object::create ();
1331 f.get (art->item->name);
1332 f.next ();
1332 1333
1333 if (!art->item->parse_kv (f)) 1334 if (!art->item->parse_kv (f))
1334 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1335 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1335 1336
1336 al = find_artifactlist (art->item->type); 1337 al = find_artifactlist (art->item->type);
1571 if (change->msg) 1572 if (change->msg)
1572 op->msg = change->msg; 1573 op->msg = change->msg;
1573} 1574}
1574 1575
1575static int 1576static int
1576legal_artifact_combination (object *op, artifact * art) 1577legal_artifact_combination (object *op, artifact *art)
1577{ 1578{
1578 int neg, success = 0; 1579 int neg, success = 0;
1579 linked_char *tmp; 1580 linked_char *tmp;
1580 const char *name; 1581 const char *name;
1581 1582
1582 if (art->allowed == (linked_char *) NULL) 1583 if (!art->allowed)
1583 return 1; /* Ie, "all" */ 1584 return 1; /* Ie, "all" */
1585
1584 for (tmp = art->allowed; tmp; tmp = tmp->next) 1586 for (tmp = art->allowed; tmp; tmp = tmp->next)
1585 { 1587 {
1586#ifdef TREASURE_VERBOSE 1588#ifdef TREASURE_VERBOSE
1587 LOG (llevDebug, "legal_art: %s\n", &tmp->name); 1589 LOG (llevDebug, "legal_art: %s\n", &tmp->name);
1588#endif 1590#endif
1599 * everything is allowed except what we match 1601 * everything is allowed except what we match
1600 */ 1602 */
1601 else if (neg) 1603 else if (neg)
1602 success = 1; 1604 success = 1;
1603 } 1605 }
1606
1604 return success; 1607 return success;
1605} 1608}
1606 1609
1607/* 1610/*
1608 * Fixes the given object, giving it the abilities and titles 1611 * Fixes the given object, giving it the abilities and titles

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines