… | |
… | |
29 | #include <stdio.h> |
29 | #include <stdio.h> |
30 | #include <sys/types.h> |
30 | #include <sys/types.h> |
31 | #include <sys/uio.h> |
31 | #include <sys/uio.h> |
32 | #include <object.h> |
32 | #include <object.h> |
33 | #include <funcpoint.h> |
33 | #include <funcpoint.h> |
|
|
34 | #include <sproto.h> |
34 | #include <loader.h> |
35 | #include <loader.h> |
35 | |
36 | |
36 | #include <bitset> |
37 | #include <bitset> |
37 | |
38 | |
38 | int nrofallocobjects = 0; |
39 | int nrofallocobjects = 0; |
… | |
… | |
313 | |
314 | |
314 | /* Everything passes, must be OK. */ |
315 | /* Everything passes, must be OK. */ |
315 | return 1; |
316 | return 1; |
316 | } |
317 | } |
317 | |
318 | |
318 | void |
|
|
319 | player::set_range (rangetype r) |
|
|
320 | { |
|
|
321 | shoottype = r; |
|
|
322 | } |
|
|
323 | |
|
|
324 | /* |
319 | /* |
325 | * sum_weight() is a recursive function which calculates the weight |
320 | * sum_weight() is a recursive function which calculates the weight |
326 | * an object is carrying. It goes through in figures out how much |
321 | * an object is carrying. It goes through in figures out how much |
327 | * containers are carrying, and sums it up. |
322 | * containers are carrying, and sums it up. |
328 | */ |
323 | */ |
… | |
… | |
330 | sum_weight (object *op) |
325 | sum_weight (object *op) |
331 | { |
326 | { |
332 | long sum; |
327 | long sum; |
333 | object *inv; |
328 | object *inv; |
334 | |
329 | |
335 | for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) |
330 | for (sum = 0, inv = op->inv; inv; inv = inv->below) |
336 | { |
331 | { |
337 | if (inv->inv) |
332 | if (inv->inv) |
338 | sum_weight (inv); |
333 | sum_weight (inv); |
|
|
334 | |
339 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
335 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
340 | } |
336 | } |
341 | |
337 | |
342 | if (op->type == CONTAINER && op->stats.Str) |
338 | if (op->type == CONTAINER && op->stats.Str) |
343 | sum = (sum * (100 - op->stats.Str)) / 100; |
339 | sum = (sum * (100 - op->stats.Str)) / 100; |
… | |
… | |
452 | */ |
448 | */ |
453 | while (owner->owner) |
449 | while (owner->owner) |
454 | owner = owner->owner; |
450 | owner = owner->owner; |
455 | |
451 | |
456 | this->owner = owner; |
452 | this->owner = owner; |
|
|
453 | } |
|
|
454 | |
|
|
455 | int |
|
|
456 | object::slottype () const |
|
|
457 | { |
|
|
458 | if (type == SKILL) |
|
|
459 | { |
|
|
460 | if (IS_COMBAT_SKILL (subtype)) return slot_combat; |
|
|
461 | if (IS_RANGED_SKILL (subtype)) return slot_ranged; |
|
|
462 | } |
|
|
463 | else |
|
|
464 | { |
|
|
465 | if (slot [body_combat].info) return slot_combat; |
|
|
466 | if (slot [body_range ].info) return slot_ranged; |
|
|
467 | } |
|
|
468 | |
|
|
469 | return slot_none; |
|
|
470 | } |
|
|
471 | |
|
|
472 | bool |
|
|
473 | object::change_weapon (object *ob) |
|
|
474 | { |
|
|
475 | if (current_weapon == ob) |
|
|
476 | return true; |
|
|
477 | |
|
|
478 | if (chosen_skill) |
|
|
479 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
480 | |
|
|
481 | current_weapon = ob; |
|
|
482 | chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); |
|
|
483 | |
|
|
484 | if (chosen_skill) |
|
|
485 | chosen_skill->flag [FLAG_APPLIED] = true; |
|
|
486 | |
|
|
487 | update_stats (); |
|
|
488 | |
|
|
489 | if (ob) |
|
|
490 | { |
|
|
491 | // now check wether any body locations became invalid, in which case |
|
|
492 | // we cannot apply the weapon at the moment. |
|
|
493 | for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) |
|
|
494 | if (slot[i].used < 0) |
|
|
495 | { |
|
|
496 | current_weapon = chosen_skill = 0; |
|
|
497 | update_stats (); |
|
|
498 | |
|
|
499 | new_draw_info_format (NDI_UNIQUE, 0, this, |
|
|
500 | "You try to balance your applied items all at once, but the %s is too much. " |
|
|
501 | "You need to unapply some items first.", &ob->name); |
|
|
502 | return false; |
|
|
503 | } |
|
|
504 | |
|
|
505 | //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); |
|
|
506 | } |
|
|
507 | else |
|
|
508 | ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); |
|
|
509 | |
|
|
510 | if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL) |
|
|
511 | { |
|
|
512 | LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s", |
|
|
513 | &name, ob->debug_desc ()); |
|
|
514 | return false; |
|
|
515 | } |
|
|
516 | |
|
|
517 | return true; |
457 | } |
518 | } |
458 | |
519 | |
459 | /* Zero the key_values on op, decrementing the shared-string |
520 | /* Zero the key_values on op, decrementing the shared-string |
460 | * refcounts and freeing the links. |
521 | * refcounts and freeing the links. |
461 | */ |
522 | */ |
… | |
… | |
543 | * need for monsters, but doesn't hurt to do it for everything. |
604 | * need for monsters, but doesn't hurt to do it for everything. |
544 | * by doing so, when a monster is created, it has good starting |
605 | * by doing so, when a monster is created, it has good starting |
545 | * values for the body_used info, so when items are created |
606 | * values for the body_used info, so when items are created |
546 | * for it, they can be properly equipped. |
607 | * for it, they can be properly equipped. |
547 | */ |
608 | */ |
548 | memcpy (body_used, body_info, sizeof (body_used)); |
609 | for (int i = NUM_BODY_LOCATIONS; i--; ) |
|
|
610 | slot[i].used = slot[i].info; |
549 | |
611 | |
550 | attachable::instantiate (); |
612 | attachable::instantiate (); |
551 | } |
613 | } |
552 | |
614 | |
553 | object * |
615 | object * |
… | |
… | |
1603 | LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); |
1665 | LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); |
1604 | free (dump); |
1666 | free (dump); |
1605 | return op; |
1667 | return op; |
1606 | } |
1668 | } |
1607 | |
1669 | |
1608 | if (where->head) |
1670 | if (where->head_ () != where) |
1609 | { |
1671 | { |
1610 | LOG (llevDebug, "Warning: Tried to insert object into wrong part of multipart object.\n"); |
1672 | LOG (llevError | logBacktrace, "Warning: Tried to insert object into wrong part of multipart object.\n"); |
1611 | where = where->head; |
1673 | where = where->head; |
1612 | } |
1674 | } |
1613 | |
1675 | |
1614 | return where->insert (op); |
1676 | return where->insert (op); |
1615 | } |
1677 | } |
… | |
… | |
1943 | for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) |
2005 | for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) |
1944 | { |
2006 | { |
1945 | CLEAR_FLAG (tmp, flag); |
2007 | CLEAR_FLAG (tmp, flag); |
1946 | unflag_inv (tmp, flag); |
2008 | unflag_inv (tmp, flag); |
1947 | } |
2009 | } |
1948 | } |
|
|
1949 | |
|
|
1950 | /* |
|
|
1951 | * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in |
|
|
1952 | * all it's inventory (recursively). |
|
|
1953 | * If checksums are used, a player will get set_cheat called for |
|
|
1954 | * him/her-self and all object carried by a call to this function. |
|
|
1955 | */ |
|
|
1956 | void |
|
|
1957 | set_cheat (object *op) |
|
|
1958 | { |
|
|
1959 | SET_FLAG (op, FLAG_WAS_WIZ); |
|
|
1960 | flag_inv (op, FLAG_WAS_WIZ); |
|
|
1961 | } |
2010 | } |
1962 | |
2011 | |
1963 | /* |
2012 | /* |
1964 | * find_free_spot(object, map, x, y, start, stop) will search for |
2013 | * find_free_spot(object, map, x, y, start, stop) will search for |
1965 | * a spot at the given map and coordinates which will be able to contain |
2014 | * a spot at the given map and coordinates which will be able to contain |
… | |
… | |
2589 | } |
2638 | } |
2590 | |
2639 | |
2591 | const char * |
2640 | const char * |
2592 | object::debug_desc () const |
2641 | object::debug_desc () const |
2593 | { |
2642 | { |
2594 | static char info[256 * 4]; |
2643 | static char info[3][256 * 4]; |
|
|
2644 | static int info_idx; |
|
|
2645 | |
2595 | return debug_desc (info); |
2646 | return debug_desc (info [++info_idx % 3]); |
2596 | } |
|
|
2597 | |
|
|
2598 | const char * |
|
|
2599 | object::debug_desc2 () const |
|
|
2600 | { |
|
|
2601 | static char info[256 * 4]; |
|
|
2602 | return debug_desc (info); |
|
|
2603 | } |
2647 | } |
2604 | |
2648 | |
2605 | struct region * |
2649 | struct region * |
2606 | object::region () const |
2650 | object::region () const |
2607 | { |
2651 | { |