Example #1
0
	void Inventory::modify(InventoryType::Id type, int16_t slot, int8_t mode, int16_t arg, Movement move)
	{
		if (slot < 0)
		{
			slot = -slot;
			type = InventoryType::EQUIPPED;
		}
		arg = (arg < 0) ? -arg : arg;

		switch (mode)
		{
		case CHANGECOUNT:
			change_count(type, slot, arg);
			break;
		case SWAP:
			switch (move)
			{
			case MOVE_INTERNAL:
				swap(type, slot, type, arg);
				break;
			case MOVE_UNEQUIP:
				swap(InventoryType::EQUIPPED, slot, InventoryType::EQUIP, arg);
				break;
			case MOVE_EQUIP:
				swap(InventoryType::EQUIP, slot, InventoryType::EQUIPPED, arg);
				break;
			}
			break;
		case REMOVE:
			remove(type, slot);
			break;
		}
	}
Example #2
0
static t_block reallocate_block(t_mchecker mc, t_block list, t_block block, x_size new_size) {

  t_block new_block;
  x_size old_size = block->size;
  x_ubyte pattern = block->pattern;
  x_ubyte * data;
  x_size which = x_random() % 5;
  x_size orsize;
  x_size nrsize;
  w_chunk chunk;

  x_mutex_lock(test_mutex, x_eternal);

  x_list_remove(block);

  chunk = block2chunk(block);
  orsize = x_mem_size(chunk);

  /*
  ** Use 'which' to bring some variation in the __LINE__ number.
  */
  
  if (which == 0) {
    new_block = reallocMem(block, sizeof(t_Block) + new_size);
  }
  else if (which == 1) {
    new_block = reallocMem(block, sizeof(t_Block) + new_size);
  }
  else if (which == 2) {
    new_block = reallocMem(block, sizeof(t_Block) + new_size);
  }
  else if (which == 3) {
    new_block = reallocMem(block, sizeof(t_Block) + new_size);
  }
  else {
    new_block = reallocMem(block, sizeof(t_Block) + new_size);
  }
  
  if (new_block == NULL) {
    x_list_insert(list, block);
    x_mutex_unlock(test_mutex);
    return NULL;
  }
  else {
    chunk = block2chunk(new_block);
    nrsize = x_mem_size(chunk);
    new_block->size = new_size;
    change_count(orsize, nrsize, new_block, old_size, new_size);
  }
  
  x_list_insert(list, new_block);

  /*
  ** If the block has grown, fill the new room with the pattern data.
  */

  if (old_size < new_size) {
    data = & new_block->data[old_size];
    set_data(data, new_size - old_size, pattern);
    growed += 1;
  }
  else {
    shrinked += 1;
  }

  x_mutex_unlock(test_mutex);

  return new_block;

}