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.47 by root, Tue Apr 17 18:24:30 2007 UTC vs.
Revision 1.58 by root, Sat Apr 28 17:51:57 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
54> tl_map_t; 54> tl_map_t;
55 55
56static tl_map_t tl_map; 56static tl_map_t tl_map;
57 57
58/* 58/*
59 * Initialize global archtype pointers:
60 */
61void
62init_archetype_pointers ()
63{
64 int prev_warn = warn_archetypes;
65
66 warn_archetypes = 1;
67
68 if (ring_arch == NULL)
69 ring_arch = archetype::find ("ring");
70 if (amulet_arch == NULL)
71 amulet_arch = archetype::find ("amulet");
72 if (staff_arch == NULL)
73 staff_arch = archetype::find ("staff");
74 if (crown_arch == NULL)
75 crown_arch = archetype::find ("crown");
76
77 warn_archetypes = prev_warn;
78}
79
80/*
81 * Searches for the given treasurelist 59 * Searches for the given treasurelist
82 */ 60 */
83treasurelist * 61treasurelist *
84treasurelist::find (const char *name) 62treasurelist::find (const char *name)
85{ 63{
167 coroapi::cede_to_tick_every (10); 145 coroapi::cede_to_tick_every (10);
168 146
169 switch (f.kw) 147 switch (f.kw)
170 { 148 {
171 case KW_arch: 149 case KW_arch:
172 if (!(t->item = archetype::find (f.get_str ()))) 150 t->item = archetype::get (f.get_str ());
173 LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ());
174 break; 151 break;
175 152
176 case KW_list: f.get (t->name); break; 153 case KW_list: f.get (t->name); break;
177 case KW_change_name: f.get (t->change_arch.name); break; 154 case KW_change_name: f.get (t->change_arch.name); break;
178 case KW_change_title: f.get (t->change_arch.title); break; 155 case KW_change_title: f.get (t->change_arch.title); break;
220 197
221 /* This is a one of the many items on the list should be generated. 198 /* This is a one of the many items on the list should be generated.
222 * Add up the chance total, and check to make sure the yes & no 199 * Add up the chance total, and check to make sure the yes & no
223 * fields of the treasures are not being used. 200 * fields of the treasures are not being used.
224 */ 201 */
225 tl->total_chance = 0;
226
227 if (one) 202 if (one)
228 { 203 {
229 for (treasure *t = tl->items; t; t = t->next) 204 for (treasure *t = tl->items; t; t = t->next)
230 { 205 {
231 if (t->next_yes || t->next_no) 206 if (t->next_yes || t->next_no)
253 * start with equipment, but only their abilities). 228 * start with equipment, but only their abilities).
254 */ 229 */
255static void 230static void
256put_treasure (object *op, object *creator, int flags) 231put_treasure (object *op, object *creator, int flags)
257{ 232{
258 object *tmp; 233 if (flags & GT_ENVIRONMENT)
259 234 {
260 /* 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
261 * 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
262 * 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
263 * by another object. 238 * by another object.
264 */ 239 */
265 if (flags & GT_ENVIRONMENT && op->type != SPELL) 240 //TODO: flag such as objects... as such (no drop, anybody?)
266 { 241 if (op->type == SPELL)
242 {
243 op->destroy ();
244 return;
245 }
246
247 op->expand_tail ();
248
249 if (ob_blocked (op, creator->map, creator->x, creator->y))
250 op->destroy ();
251 else
252 {
267 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 253 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
268 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); 254 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
255 }
269 } 256 }
270 else 257 else
271 { 258 {
272 op = creator->insert (op); 259 op = creator->insert (op);
273 260
274 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 261 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
275 monster_check_apply (creator, op); 262 monster_check_apply (creator, op);
276 263
277 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) 264 if (flags & GT_UPDATE_INV)
265 if (object *tmp = creator->in_player ())
278 esrv_send_item (tmp, op); 266 esrv_send_item (tmp, op);
279 } 267 }
280} 268}
281 269
282/* if there are change_xxx commands in the treasure, we include the changes 270/* if there are change_xxx commands in the treasure, we include the changes
283 * in the generated object 271 * in the generated object
381 fix_generated_item (tmp, op, difficulty, t->magic, flag); 369 fix_generated_item (tmp, op, difficulty, t->magic, flag);
382 change_treasure (t, tmp); 370 change_treasure (t, tmp);
383 put_treasure (tmp, op, flag); 371 put_treasure (tmp, op, flag);
384 } 372 }
385 } 373 }
374}
375
376void
377object::create_treasure (treasurelist *tl, int flags)
378{
379 ::create_treasure (tl, this, flags, map ? map->difficulty : 0);
386} 380}
387 381
388/* This calls the appropriate treasure creation function. tries is passed 382/* This calls the appropriate treasure creation function. tries is passed
389 * to determine how many list transitions or attempts to create treasure 383 * to determine how many list transitions or attempts to create treasure
390 * have been made. It is really in place to prevent infinite loops with 384 * have been made. It is really in place to prevent infinite loops with
403 { 397 {
404 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 398 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
405 return; 399 return;
406 } 400 }
407 401
402 if (op->flag [FLAG_TREASURE_ENV])
403 flag |= GT_ENVIRONMENT;
404
408 if (tl->total_chance) 405 if (tl->total_chance)
409 create_one_treasure (tl, op, flag, difficulty, tries); 406 create_one_treasure (tl, op, flag, difficulty, tries);
410 else 407 else
411 create_all_treasures (tl->items, op, flag, difficulty, tries); 408 create_all_treasures (tl->items, op, flag, difficulty, tries);
412} 409}
419object * 416object *
420generate_treasure (treasurelist *tl, int difficulty) 417generate_treasure (treasurelist *tl, int difficulty)
421{ 418{
422 difficulty = clamp (difficulty, 1, settings.max_level); 419 difficulty = clamp (difficulty, 1, settings.max_level);
423 420
424 object *ob = object::create (), *tmp; 421 object *ob = object::create ();
425 422
426 create_treasure (tl, ob, 0, difficulty, 0); 423 create_treasure (tl, ob, 0, difficulty, 0);
427 424
428 /* Don't want to free the object we are about to return */ 425 /* Don't want to free the object we are about to return */
429 tmp = ob->inv; 426 object *tmp = ob->inv;
430 if (tmp != NULL) 427 if (tmp)
431 tmp->remove (); 428 tmp->remove ();
432 429
433 if (ob->inv) 430 if (ob->inv)
434 LOG (llevError, "In generate treasure, created multiple objects.\n"); 431 LOG (llevError, "In generate treasure, created multiple objects.\n");
435 432
443 * The array has two arguments, the difficulty of the level, and the 440 * The array has two arguments, the difficulty of the level, and the
444 * magical bonus "wanted". 441 * magical bonus "wanted".
445 */ 442 */
446 443
447static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { 444static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = {
448
449// chance of magic difficulty 445// chance of magic difficulty
450// +0 +1 +2 +3 +4 446// +0 +1 +2 +3 +4
451 {95, 2, 2, 1, 0}, // 1 447 {95, 2, 2, 1, 0}, // 1
452 {92, 5, 2, 1, 0}, // 2 448 {92, 5, 2, 1, 0}, // 2
453 {85, 10, 4, 1, 0}, // 3 449 {85, 10, 4, 1, 0}, // 3
479 { 0, 0, 0, 3, 97}, // 29 475 { 0, 0, 0, 3, 97}, // 29
480 { 0, 0, 0, 0, 100}, // 30 476 { 0, 0, 0, 0, 100}, // 30
481 { 0, 0, 0, 0, 100}, // 31 477 { 0, 0, 0, 0, 100}, // 31
482}; 478};
483 479
484
485/* calculate the appropriate level for wands staves and scrolls. 480/* calculate the appropriate level for wands staves and scrolls.
486 * This code presumes that op has had its spell object created (in op->inv) 481 * This code presumes that op has had its spell object created (in op->inv)
487 * 482 *
488 * elmex Wed Aug 9 17:44:59 CEST 2006: 483 * elmex Wed Aug 9 17:44:59 CEST 2006:
489 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 484 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
490 */ 485 */
491
492int 486int
493level_for_item (const object *op, int difficulty) 487level_for_item (const object *op, int difficulty)
494{ 488{
495 int olevel = 0; 489 int olevel = 0;
496 490
806 save_item_power = op->item_power; 800 save_item_power = op->item_power;
807 op->item_power = 0; 801 op->item_power = 0;
808 802
809 if (op->randomitems && op->type != SPELL) 803 if (op->randomitems && op->type != SPELL)
810 { 804 {
811 create_treasure (op->randomitems, op, flags, difficulty, 0); 805 create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0);
812 if (!op->inv)
813 LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ());
814
815 /* So the treasure doesn't get created again */ 806 /* So the treasure doesn't get created again */
816 op->randomitems = 0; 807 op->randomitems = 0;
817 } 808 }
818 809
819 if (difficulty < 1) 810 if (difficulty < 1)
1349 break; 1340 break;
1350 1341
1351 case KW_object: 1342 case KW_object:
1352 { 1343 {
1353 art->item = object::create (); 1344 art->item = object::create ();
1345 f.get (art->item->name);
1346 f.next ();
1354 1347
1355 if (!art->item->parse_kv (f)) 1348 if (!art->item->parse_kv (f))
1356 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1349 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1357 1350
1358 al = find_artifactlist (art->item->type); 1351 al = find_artifactlist (art->item->type);
1593 if (change->msg) 1586 if (change->msg)
1594 op->msg = change->msg; 1587 op->msg = change->msg;
1595} 1588}
1596 1589
1597static int 1590static int
1598legal_artifact_combination (object *op, artifact * art) 1591legal_artifact_combination (object *op, artifact *art)
1599{ 1592{
1600 int neg, success = 0; 1593 int neg, success = 0;
1601 linked_char *tmp; 1594 linked_char *tmp;
1602 const char *name; 1595 const char *name;
1603 1596
1604 if (art->allowed == (linked_char *) NULL) 1597 if (!art->allowed)
1605 return 1; /* Ie, "all" */ 1598 return 1; /* Ie, "all" */
1599
1606 for (tmp = art->allowed; tmp; tmp = tmp->next) 1600 for (tmp = art->allowed; tmp; tmp = tmp->next)
1607 { 1601 {
1608#ifdef TREASURE_VERBOSE 1602#ifdef TREASURE_VERBOSE
1609 LOG (llevDebug, "legal_art: %s\n", &tmp->name); 1603 LOG (llevDebug, "legal_art: %s\n", &tmp->name);
1610#endif 1604#endif
1621 * everything is allowed except what we match 1615 * everything is allowed except what we match
1622 */ 1616 */
1623 else if (neg) 1617 else if (neg)
1624 success = 1; 1618 success = 1;
1625 } 1619 }
1620
1626 return success; 1621 return success;
1627} 1622}
1628 1623
1629/* 1624/*
1630 * Fixes the given object, giving it the abilities and titles 1625 * Fixes the given object, giving it the abilities and titles

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines