daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Dec 14th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @notice Have a pregnant Kitty give birth!
  2.     /// @param _matronId A Kitty ready to give birth.
  3.     /// @return The Kitty ID of the new kitten.
  4.     /// @dev Looks at a given Kitty and, if pregnant and if the gestation period has passed,
  5.     ///  combines the genes of the two parents to create a new kitten. The new Kitty is assigned
  6.     ///  to the current owner of the matron. Upon successful completion, both the matron and the
  7.     ///  new kitten will be ready to breed again. Note that anyone can call this function (if they
  8.     ///  are willing to pay the gas!), but the new kitten always goes to the mother's owner.
  9.     function giveBirth(uint256 _matronId)
  10.         external
  11.         whenNotPaused
  12.         returns(uint256)
  13.     {
  14.         // Grab a reference to the matron in storage.
  15.         Kitty storage matron = kitties[_matronId];
  16.  
  17.         // Check that the matron is a valid cat.
  18.         require(matron.birthTime != 0);
  19.  
  20.         // Check that the matron is pregnant, and that its time has come!
  21.         require(_isReadyToGiveBirth(matron));
  22.  
  23.         // Grab a reference to the sire in storage.
  24.         uint256 sireId = matron.siringWithId;
  25.         Kitty storage sire = kitties[sireId];
  26.  
  27.         // Determine the higher generation number of the two parents
  28.         uint16 parentGen = matron.generation;
  29.         if (sire.generation > matron.generation) {
  30.             parentGen = sire.generation;
  31.         }
  32.  
  33.         // Call the sooper-sekret gene mixing operation.
  34.         uint256 childGenes = geneScience.mixGenes(matron.genes, sire.genes, matron.cooldownEndBlock - 1);
  35.  
  36.         // Make the new kitten!
  37.         address owner = kittyIndexToOwner[_matronId];
  38.         uint256 kittenId = _createKitty(_matronId, matron.siringWithId, parentGen + 1, childGenes, owner);
  39.  
  40.         // Clear the reference to sire from the matron (REQUIRED! Having siringWithId
  41.         // set is what marks a matron as being pregnant.)
  42.         delete matron.siringWithId;
  43.  
  44.         // Every time a kitty gives birth counter is decremented.
  45.         pregnantKitties--;
  46.  
  47.         // Send the balance fee to the person who made birth happen.
  48.         msg.sender.send(autoBirthFee);
  49.  
  50.         // return the new kitten's ID
  51.         return kittenId;
  52.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top