1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcs_treasure_c = |
3 | * static char *rcs_treasure_c = |
4 | * "$Id: treasure.C,v 1.11 2006/09/04 11:07:59 root Exp $"; |
4 | * "$Id: treasure.C,v 1.12 2006/09/04 13:55:54 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
255 | */ |
255 | */ |
256 | |
256 | |
257 | treasurelist * |
257 | treasurelist * |
258 | find_treasurelist (const char *name) |
258 | find_treasurelist (const char *name) |
259 | { |
259 | { |
260 | const char *tmp = shstr::find (name); |
|
|
261 | treasurelist *tl; |
|
|
262 | |
|
|
263 | /* Special cases - randomitems of none is to override default. If |
260 | /* Special cases - randomitems of NULL is to override default. If |
264 | * first_treasurelist is null, it means we are on the first pass of |
261 | * first_treasurelist is null, it means we are on the first pass of |
265 | * of loading archetyps, so for now, just return - second pass will |
262 | * of loading archetypes, so for now, just return - second pass will |
266 | * init these values. |
263 | * init these values. |
267 | */ |
264 | */ |
268 | if (!name || !*name) |
265 | if (!name) |
269 | return NULL; |
266 | return 0; |
270 | |
267 | |
271 | if (tmp != NULL) |
268 | if (const char *tmp = shstr::find (name)) |
272 | for (tl = first_treasurelist; tl != NULL; tl = tl->next) |
269 | for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) |
273 | { |
|
|
274 | if (tmp == tl->name) |
270 | if (tmp == tl->name) |
275 | return tl; |
271 | return tl; |
276 | } |
|
|
277 | |
272 | |
278 | if (first_treasurelist) |
273 | if (first_treasurelist) |
279 | LOG (llevError, "Couldn't find treasurelist %s(%s)\n", name, tmp); |
274 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
280 | |
275 | |
281 | return NULL; |
276 | return 0; |
282 | } |
277 | } |
283 | |
278 | |
284 | |
279 | |
285 | /* |
280 | /* |
286 | * Generates the objects specified by the given treasure. |
281 | * Generates the objects specified by the given treasure. |
… | |
… | |
324 | |
319 | |
325 | /* if there are change_xxx commands in the treasure, we include the changes |
320 | /* if there are change_xxx commands in the treasure, we include the changes |
326 | * in the generated object |
321 | * in the generated object |
327 | */ |
322 | */ |
328 | static void |
323 | static void |
329 | change_treasure (treasure * t, object * op) |
324 | change_treasure (treasure *t, object *op) |
330 | { |
325 | { |
331 | /* CMD: change_name xxxx */ |
326 | /* CMD: change_name xxxx */ |
332 | if (t->change_arch.name) |
327 | if (t->change_arch.name) |
333 | { |
328 | { |
334 | op->name = t->change_arch.name; |
329 | op->name = t->change_arch.name; |
… | |
… | |
341 | if (t->change_arch.slaying) |
336 | if (t->change_arch.slaying) |
342 | op->slaying = t->change_arch.slaying; |
337 | op->slaying = t->change_arch.slaying; |
343 | } |
338 | } |
344 | |
339 | |
345 | void |
340 | void |
346 | create_all_treasures (treasure * t, object * op, int flag, int difficulty, int tries) |
341 | create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries) |
347 | { |
342 | { |
348 | object *tmp; |
343 | object *tmp; |
349 | |
|
|
350 | |
344 | |
351 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
345 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
352 | { |
346 | { |
353 | if (t->name) |
347 | if (t->name) |
354 | { |
348 | { |
… | |
… | |
365 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
359 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
366 | change_treasure (t, tmp); |
360 | change_treasure (t, tmp); |
367 | put_treasure (tmp, op, flag); |
361 | put_treasure (tmp, op, flag); |
368 | } |
362 | } |
369 | } |
363 | } |
|
|
364 | |
370 | if (t->next_yes != NULL) |
365 | if (t->next_yes != NULL) |
371 | create_all_treasures (t->next_yes, op, flag, difficulty, tries); |
366 | create_all_treasures (t->next_yes, op, flag, difficulty, tries); |
372 | } |
367 | } |
373 | else if (t->next_no != NULL) |
368 | else if (t->next_no != NULL) |
374 | create_all_treasures (t->next_no, op, flag, difficulty, tries); |
369 | create_all_treasures (t->next_no, op, flag, difficulty, tries); |
|
|
370 | |
375 | if (t->next != NULL) |
371 | if (t->next != NULL) |
376 | create_all_treasures (t->next, op, flag, difficulty, tries); |
372 | create_all_treasures (t->next, op, flag, difficulty, tries); |
377 | } |
373 | } |
378 | |
374 | |
379 | void |
375 | void |
380 | create_one_treasure (treasurelist * tl, object * op, int flag, int difficulty, int tries) |
376 | create_one_treasure (treasurelist *tl, object * op, int flag, int difficulty, int tries) |
381 | { |
377 | { |
382 | int value = RANDOM () % tl->total_chance; |
378 | int value = RANDOM () % tl->total_chance; |
383 | treasure *t; |
379 | treasure *t; |
384 | |
380 | |
385 | if (tries++ > 100) |
381 | if (tries++ > 100) |
386 | { |
382 | { |
387 | LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n"); |
383 | LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n"); |
388 | return; |
384 | return; |
389 | } |
385 | } |
|
|
386 | |
390 | for (t = tl->items; t != NULL; t = t->next) |
387 | for (t = tl->items; t != NULL; t = t->next) |
391 | { |
388 | { |
392 | value -= t->chance; |
389 | value -= t->chance; |
|
|
390 | |
393 | if (value < 0) |
391 | if (value < 0) |
394 | break; |
392 | break; |
395 | } |
393 | } |
396 | |
394 | |
397 | if (!t || value >= 0) |
395 | if (!t || value >= 0) |
398 | { |
396 | { |
399 | LOG (llevError, "create_one_treasure: got null object or not able to find treasure\n"); |
397 | LOG (llevError, "create_one_treasure: got null object or not able to find treasure\n"); |
400 | abort (); |
398 | abort (); |
401 | return; |
399 | return; |
402 | } |
400 | } |
|
|
401 | |
403 | if (t->name) |
402 | if (t->name) |
404 | { |
403 | { |
405 | if (!strcmp (t->name, "NONE")) |
404 | if (!strcmp (t->name, "NONE")) |
406 | return; |
405 | return; |
|
|
406 | |
407 | if (difficulty >= t->magic) |
407 | if (difficulty >= t->magic) |
408 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
408 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
409 | else if (t->nrof) |
409 | else if (t->nrof) |
410 | create_one_treasure (tl, op, flag, difficulty, tries); |
410 | create_one_treasure (tl, op, flag, difficulty, tries); |
|
|
411 | |
411 | return; |
412 | return; |
412 | } |
413 | } |
|
|
414 | |
413 | if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) |
415 | if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) |
414 | { |
416 | { |
415 | object *tmp = arch_to_object (t->item); |
417 | object *tmp = arch_to_object (t->item); |
|
|
418 | |
416 | if (!tmp) |
419 | if (!tmp) |
417 | return; |
420 | return; |
|
|
421 | |
418 | if (t->nrof && tmp->nrof <= 1) |
422 | if (t->nrof && tmp->nrof <= 1) |
419 | tmp->nrof = RANDOM () % ((int) t->nrof) + 1; |
423 | tmp->nrof = RANDOM () % ((int) t->nrof) + 1; |
|
|
424 | |
420 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
425 | // fix_generated_item (tmp, op, difficulty, t->magic, flag); |
421 | change_treasure (t, tmp); |
426 | // change_treasure (t, tmp); |
422 | put_treasure (tmp, op, flag); |
427 | put_treasure (tmp, op, flag); |
423 | } |
428 | } |
424 | } |
429 | } |
425 | |
430 | |
426 | /* This calls the appropriate treasure creation function. tries is passed |
431 | /* This calls the appropriate treasure creation function. tries is passed |
… | |
… | |
1473 | { |
1478 | { |
1474 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1479 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1475 | /* so artifacts will join */ |
1480 | /* so artifacts will join */ |
1476 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1481 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1477 | op->speed = 0.0; |
1482 | op->speed = 0.0; |
|
|
1483 | |
1478 | update_ob_speed (op); |
1484 | update_ob_speed (op); |
1479 | } |
1485 | } |
1480 | |
1486 | |
1481 | if (change->nrof) |
1487 | if (change->nrof) |
1482 | op->nrof = RANDOM () % ((int) change->nrof) + 1; |
1488 | op->nrof = RANDOM () % ((int) change->nrof) + 1; |
… | |
… | |
1651 | * Fixes the given object, giving it the abilities and titles |
1657 | * Fixes the given object, giving it the abilities and titles |
1652 | * it should have due to the second artifact-template. |
1658 | * it should have due to the second artifact-template. |
1653 | */ |
1659 | */ |
1654 | |
1660 | |
1655 | void |
1661 | void |
1656 | give_artifact_abilities (object * op, object * artifct) |
1662 | give_artifact_abilities (object *op, object *artifct) |
1657 | { |
1663 | { |
1658 | char new_name[MAX_BUF]; |
1664 | char new_name[MAX_BUF]; |
1659 | |
1665 | |
1660 | sprintf (new_name, "of %s", &artifct->name); |
1666 | sprintf (new_name, "of %s", &artifct->name); |
1661 | op->title = new_name; |
1667 | op->title = new_name; |