



AttemptToTakeObject (lines 1458-1535)
Back to List
Browsing verblibm.h
1458 [ AttemptToTakeObject item ancestor after_recipient i j k;
1459 ! Try to transfer the given item to the player: return false
1460 ! if successful, true if unsuccessful, printing a suitable message
1461 ! in the latter case.
1462 ! People cannot ordinarily be taken.
1463 if (item == player) return L__M(##Take, 2);
1464 if (item has animate) return L__M(##Take, 3, item);
1465
1466 ancestor = CommonAncestor(player, item);
1467
1468 if (ancestor == 0) {
1469 i = ObjectScopedBySomething(item);
1470 if (i ~= 0) ancestor = CommonAncestor(player, i);
1471 }
1472
1473 ! Is the player indirectly inside the item?
1474 if (ancestor == item) return L__M(##Take, 4, item);
1475
1476 ! Does the player already directly contain the item?
1477 if (item in player) return L__M(##Take, 5, item);
1478
1479 ! Can the player touch the item, or is there (e.g.) a closed container
1480 ! in the way?
1481 if (ObjectIsUntouchable(item, false, true)) return;
1482
1483 ! The item is now known to be accessible.
1484
1485 ! Consult the immediate possessor of the item, if it's in a container
1486 ! which the player is not in.
1487
1488 i = parent(item);
1489 if (i ~= ancestor && (i has container || i has supporter)) {
1490 after_recipient = i;
1491 k = action; action = ##LetGo;
1492 if (RunRoutines(i, before) ~= 0) { action = k; rtrue; }
1493 action=k;
1494 }
1495
1496 if (item has scenery) return L__M(##Take, 10, item);
1497 if (item has static) return L__M(##Take, 11, item);
1498
1499 ! The item is now known to be available for taking. Is the player
1500 ! carrying too much? If so, possibly juggle items into the rucksack
1501 ! to make room.
1502
1503 k = 0; objectloop (j in player) if (j hasnt worn) k++;
1504
1505 if (k >= ValueOrRun(player, capacity)) {
1506 if (SACK_OBJECT ~= 0) {
1507 if (parent(SACK_OBJECT) ~= player)
1508 return L__M(##Take, 12);
1509 j = 0;
1510 objectloop (k in player)
1511 if (k ~= SACK_OBJECT && k hasnt worn && k hasnt light) j = k;
1512
1513 if (j ~= 0) {
1514 L__M(##Take, 13, j);
1515 keep_silent = 1; <Insert j SACK_OBJECT>; keep_silent = 0;
1516 if (j notin SACK_OBJECT) rtrue;
1517 }
1518 else return L__M(##Take, 12);
1519 }
1520 else return L__M(##Take, 12);
1521 }
1522
1523 ! Transfer the item.
1524
1525 move item to player;
1526
1527 ! Send "after" message to the object letting go of the item, if any.
1528
1529 if (after_recipient ~= 0) {
1530 k = action; action = ##LetGo;
1531 if (RunRoutines(after_recipient, after) ~= 0) { action = k; rtrue; }
1532 action=k;
1533 }
1534 rfalse;
1535 ];
Last updated 27 February 2004. The librarian in charge of this page is Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight. Please email any comments, suggestions or corrections to cedenqs@inform-fiction.org.