/// @dev An internal method that creates a new cutie and stores it. This
/// method does not check anything and should only be called when the
/// input data is valid for sure. Will generate both a Birth event
/// and a Transfer event.
/// @param _momId The hex ID of the mom of this cutie (zero for gen0)
/// @param _dadId The hex ID of the dad of this cutie (zero for gen0)
/// @param _generation The generation number of this hex, must be computed by caller.
/// @param _genes The hex's genetic code.
/// @param _owner The initial owner of this hex, must be non-zero (except for the unHex, ID 0)
Cutie memory _cutie = Cutie({
cooldownIndex: _cooldownIndex,
uint256 newHexId256 = cuties.push(_cutie) - 1;
// Check if id can fit into 40 bits
require(newCutieId256 <= 0xFFFFFFFFFF);
uint40 newhexId = uint40(newCutieId256);
emit Birth(_owner, newCutieId, _cutie.momId, _hex.dadId, _hex.genes);
// This will assign ownership, as well as emit the Transfer event as
_transfer(0, _owner, newHexId);
/// @notice Returns all the relevant information about a certain cutie.
/// @param _id The ID of the cutie of interest.
function getHex(uint40 _id)
Cutie storage hex = hexs[_id];
birthTime = hex.birthTime;
cooldownEndTime = hex.cooldownEndTime;
cooldownIndex = hex.cooldownIndex;
generation = hex.generation;
/// @dev Assigns ownership of a particular Hex to an address.
function _transfer(address _from, address _to, uint40 _cutieId) internal {
// since the number of hexs is capped to 2^40
// there is no way to overflow this
ownershipTokenCount[_to]++;
cutieIndexToOwner[_hexId] = _to;
// When creating new cuties _from is 0x0, but we cannot account that address.
if (_from != address(0)) {
ownershipTokenCount[_from]--;
// once the cutie is transferred also clear breeding allowances
delete sireAllowedToAddress[_cutieId];
// clear any previously approved ownership exchange
delete cutieIndexToApproved[_cutieId];
// Emit the transfer event.
emit Transfer(_from, _to, _hexId);
/// @dev For transferring a hex owned by this contract to the specified address.
/// Used to rescue lost hexs. (There is no "proper" flow where this contract
/// should be the owner of any Hex. This function exists for us to reassign
/// the ownership of Cuties that users may have accidentally sent to our address.)
/// @param _cutieId - ID of hex
/// @param _recipient - Address to send the cutie to
function restoreCutieToAddress(uint40 _cutieId, address _recipient) public onlyOperator whenNotPaused {
require(_isOwner(this, _cutieId));
_transfer(this, _recipient, _hexId);
bool public paused = false;
require(msg.sender == ownerAddress);