示例#1
0
文件: bridge.cpp 项目: yannicklm/bear
/**
 * \brief Align \a that on the bridge.
 * \param that The other item of the collision.
 * \param info Some informations about the collision.
 */
bool bear::bridge::align_on_bridge
( engine::base_item& that, universe::collision_info& info )
{
  bool result = false;
  
  universe::position_type previous_pos;
  universe::position_type next_pos;
  
  compute_neighboor
    (info.other_previous_state().get_bottom_middle(),previous_pos,next_pos);
  if ( check_item
       ( info.other_previous_state().get_bottom_middle(),
	 previous_pos, next_pos, 0 ) )
    {
      compute_neighboor(that.get_bottom_middle(),previous_pos,next_pos);

      if ( ! check_item( that.get_bottom_middle(), previous_pos, next_pos, 
			 s_line_width ) ) 
	{
	  universe::position_type pos = 
	    compute_align_position(that,previous_pos, next_pos);

	  apply_angle_to(that,info);
	  
	  return collision_align_top(info, pos);	  
	}
    }
  return result;
} // bridge::align_on_bridge()
示例#2
0
TEST (undo_handler, test_add_remove)
{
  undo_handler handler;
  undoable_stub *new_item1 = new undoable_stub (1);
  handler.add_item (new_item1);
  EXPECT_EQ (0, new_item1->undo_id ());
  handler.create_undo ("Test"); // 1
  
  handler.remove_item (new_item1);
  handler.create_undo ("Test"); // 2

  undoable_stub *new_item2 = new undoable_stub (2);
  handler.add_item (new_item2);
  EXPECT_EQ (1, new_item2->undo_id ());
  handler.create_undo ("Test"); // 3

  handler.undo (1); // 2
  EXPECT_EQ (nullptr, handler.get_item (1));
  EXPECT_EQ (nullptr, handler.get_item (0));

  handler.undo (1); // 1
  EXPECT_EQ (nullptr, handler.get_item (1));
  check_item (handler, 0, 1);

  undoable_stub *new_item3 = new undoable_stub (3);
  handler.add_item (new_item3);
  handler.create_undo ("Test"); // 2

  handler.undo (1); // 1
  EXPECT_EQ (nullptr, handler.get_item (1));
  check_item (handler, 0, 1);
}
示例#3
0
文件: ypscheme.c 项目: idtek/knot
int yp_scheme_check_parser(
	yp_check_ctx_t *ctx,
	const yp_parser_t *parser)
{
	if (ctx == NULL || parser == NULL) {
		return KNOT_EINVAL;
	}

	int ret;

	switch (parser->event) {
	case YP_EKEY0:
		reset_ctx(ctx, 0);
		ret = check_item(parser->key, parser->key_len, parser->data,
		                 parser->data_len, ctx, false);
		break;
	case YP_EKEY1:
		reset_ctx(ctx, 1);
		ret = check_item(parser->key, parser->key_len, parser->data,
		                 parser->data_len, ctx, false);
		if (ret != KNOT_EOK) {
			break;
		}

		// Check for KEY1 event with id item.
		if (ctx->current != 1) {
			return KNOT_YP_ENOTSUP_ID;
		}

		break;
	case YP_EID:
		reset_ctx(ctx, 1);
		ret = check_item(parser->key, parser->key_len, parser->data,
		                 parser->data_len, ctx, false);
		if (ret != KNOT_EOK) {
			break;
		}

		// Check for ID event with nonid item.
		if (ctx->current != 0) {
			return KNOT_YP_EINVAL_ID;
		}

		break;
	default:
		ret = KNOT_EPARSEFAIL;
		break;
	}

	return ret;
}
示例#4
0
/**
 * \brief Implementation of item:get_game().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_game(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  push_game(l, item.get_savegame());
  return 1;
}
示例#5
0
文件: golem.c 项目: julienq/golem
// Create and populate a world from a list of rules.
golem_world *new_world(golem_rule *rules) {
  golem_world *world = mallocd(sizeof(golem_world));
  world->items = NULL;
  golem_item *last = NULL;
  for (golem_rule *rule = rules; rule; rule = rule->next) {
    if (!rule->effects) {
      if (rule->target) {
        warn("ignoring target in no-effect rule.");
      }
      if (rule->others) {
        warn("ignoring others in no-effect rule.");
      }
      log("+ item: %s\n", rule->item->name);
      if (check_item(rule->item)) {
        if (last) {
          last->next_sibling = rule->item;
        } else {
          world->items = rule->item;
        }
        last = rule->item;
      }
    }
  }
  world->pc = find_pc(world->items);
  if (!world->pc) {
    die("no PC found.");
  }
  for (world->current = world->pc; world->current->parent;
      world->current = world->current->parent);
  return world;
}
示例#6
0
/**
 * \brief Implementation of item:get_brandish_when_picked().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_brandish_when_picked(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  lua_pushboolean(l, item.get_brandish_when_picked());
  return 1;
}
示例#7
0
/**
 * \brief Implementation of item:is_assignable().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_is_assignable(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  lua_pushboolean(l, item.is_assignable());
  return 1;
}
示例#8
0
/**
 * \brief Implementation of item:get_can_disappear().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_can_disappear(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  lua_pushboolean(l, item.get_can_disappear());
  return 1;
}
示例#9
0
/**
 * \brief Implementation of item:has_variant().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_has_variant(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  int variant = 1;
  if (lua_gettop(l) >= 2) {
    variant = luaL_checkint(l, 2);
  }

  lua_pushboolean(l, item.get_variant() >= variant);
  return 1;
}
示例#10
0
/**
 * \brief Implementation of item:get_variant().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_variant(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  if (!item.is_saved()) {
    LuaTools::error(l, std::string("Item '") + item.get_name() + "' is not saved");
  }

  lua_pushinteger(l, item.get_variant());
  return 1;
}
示例#11
0
bool LASzip::check_items(const U16 num_items, const LASitem* items)
{
  if (num_items == 0) return return_error("number of items cannot be zero");
  if (items == 0) return return_error("items pointer cannot be NULL");
  U16 i;
  for (i = 0; i < num_items; i++)
  {
    if (!check_item(&items[i])) return false;
  }
  return true;
}
示例#12
0
/**
 * \brief Implementation of item:get_max_amount().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_max_amount(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  if (!item.has_amount()) {
    LuaTools::error(l, std::string("Item '") + item.get_name() + "' has no amount");
  }

  lua_pushinteger(l, item.get_max_amount());
  return 1;
}
示例#13
0
/**
 * \brief Implementation of item:get_max_amount().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_max_amount(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  if (!item.has_amount()) {
    error(l, StringConcat() << "Item '" << item.get_name() << "' has no amount");
  }

  lua_pushinteger(l, item.get_max_amount());
  return 1;
}
示例#14
0
/**
 * \brief Implementation of item:get_variant().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_variant(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  if (!item.is_saved()) {
    error(l, StringConcat() << "Item '" << item.get_name() << "' is not saved");
  }

  lua_pushinteger(l, item.get_variant());
  return 1;
}
示例#15
0
// unpack from VLR data
bool LASzip::unpack(const U8* bytes, const I32 num)
{
  // check input
  if (num < 34) return return_error("too few bytes to unpack");
  if (((num - 34) % 6) != 0) return return_error("wrong number bytes to unpack"); 
  if (((num - 34) / 6) == 0) return return_error("zero items to unpack");
  num_items = (num - 34) / 6;

  // create item list
  if (items) delete [] items;
  items = new LASitem[num_items];

  // do the unpacking
  U16 i;
  const U8* b = bytes;
  compressor = *((U16*)b);
  b += 2;
  coder = *((U16*)b);
  b += 2;
  version_major = *((U8*)b);
  b += 1;
  version_minor = *((U8*)b);
  b += 1;
  version_revision = *((U16*)b);
  b += 2;
  options = *((U32*)b);
  b += 4;
  chunk_size = *((U32*)b);
  b += 4;
  number_of_special_evlrs = *((I64*)b);
  b += 8;
  offset_to_special_evlrs = *((I64*)b);
  b += 8;
  num_items = *((U16*)b);
  b += 2;
  for (i = 0; i < num_items; i++)
  {
    items[i].type = (LASitem::Type)*((U16*)b);
    b += 2;
    items[i].size = *((U16*)b);
    b += 2;
    items[i].version = *((U16*)b);
    b += 2;
  }
  assert((bytes + num) == b);

  // check if we support the contents

  for (i = 0; i < num_items; i++)
  {
    if (!check_item(&items[i])) return false;
  }
  return true;
}
示例#16
0
bool Status::equip_item(const char *name)
{
    bool result = false;

    Item *item = check_item(name);
    if (item) {
        result = equip_item(item);
    }

    return result;
}
示例#17
0
/**
 * \brief Implementation of item:set_brandish_when_picked().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_brandish_when_picked(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  bool brandish_when_picked = true;
  if (lua_gettop(l) >= 2) {
    brandish_when_picked = lua_toboolean(l, 2);
  }

  item.set_brandish_when_picked(brandish_when_picked);

  return 0;
}
示例#18
0
/**
 * \brief Implementation of item:set_assignable().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_assignable(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  bool assignable = true;
  if (lua_gettop(l) >= 2) {
    assignable = lua_toboolean(l, 2);
  }

  item.set_assignable(assignable);

  return 0;
}
示例#19
0
/**
 * \brief Implementation of item:set_shadow().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_shadow(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  std::string shadow;
  if (!lua_isnil(l, 2)) {
    shadow = luaL_checkstring(l, 2);
  }

  item.set_shadow(shadow);

  return 0;
}
示例#20
0
/**
 * \brief Implementation of item:set_can_disappear().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_can_disappear(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  bool can_disappear = true;
  if (lua_gettop(l) >= 2) {
    can_disappear = lua_toboolean(l, 2);
  }

  item.set_can_disappear(can_disappear);

  return 0;
}
示例#21
0
/**
 * \brief Implementation of item:get_amount().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_amount(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  if (!item.has_amount()) {
    lua_pushnil(l);
  }
  else {
    lua_pushinteger(l, item.get_amount());
  }
  return 1;
}
示例#22
0
/**
 * \brief Implementation of item:set_sound_when_brandished().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_sound_when_brandished(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  std::string sound_when_brandished;
  if (!lua_isnil(l, 2)) {
    sound_when_brandished = luaL_checkstring(l, 2);
  }

  item.set_sound_when_brandished(sound_when_brandished);

  return 0;
}
示例#23
0
文件: bridge.cpp 项目: yannicklm/bear
/**
 * \brief Check if a given item on bridge must be erase.
 * \param it Iterator on item to consider.
 * \param previous_pos Position of previous item.
 * \param next_pos Position of next item.
 */
  bool bear::bridge::check_erase_item
  (items_list_iterator it, const universe::position_type& previous_pos,
   const universe::position_type& next_pos) const
{
  return 
    check_item
    ( it->get_reference_item()->get_center_of_mass(), 
      previous_pos, next_pos, 0 ) ||
    ( it->get_item().get() == NULL ) ||
    ( it->get_item()->get_bottom() > get_top() ) ||
    ( it->get_item()->get_horizontal_middle() < get_left() )|| 
    ( it->get_item()->get_horizontal_middle() > get_right() );
} // bridge::check_erase_item()
示例#24
0
/**
 * \brief Implementation of item:set_max_amount().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_max_amount(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  int max_amount = luaL_checkint(l, 2);

  if (!item.has_amount()) {
    error(l, StringConcat() << "Item '" << item.get_name() << "' has no amount");
  }

  item.set_max_amount(max_amount);

  return 0;
}
示例#25
0
/**
 * \brief Implementation of item:set_max_amount().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_max_amount(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  int max_amount = luaL_checkint(l, 2);

  if (!item.has_amount()) {
    LuaTools::error(l, std::string("Item '") + item.get_name() + "' has no amount");
  }

  item.set_max_amount(max_amount);

  return 0;
}
示例#26
0
/**
 * \brief Implementation of item:get_map().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_map(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  Game* game = item.get_game();
  if (game != NULL) {
    push_map(l, game->get_current_map());
  }
  else {
    lua_pushnil(l);
  }
  return 1;
}
示例#27
0
/**
 * \brief Implementation of item:set_variant().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_set_variant(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);
  int variant = luaL_checkint(l, 2);

  if (!item.is_saved()) {
    LuaTools::error(l, std::string("Item '") + item.get_name() + "' is not saved");
  }

  item.set_variant(variant);

  return 0;
}
示例#28
0
/**
 * \brief Implementation of item:get_amount_savegame_variable().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_amount_savegame_variable(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  const std::string& amount_savegame_variable = item.get_amount_savegame_variable();
  if (amount_savegame_variable.empty()) {
    lua_pushnil(l);
  }
  else {
    push_string(l, amount_savegame_variable);
  }
  return 1;
}
示例#29
0
/**
 * \brief Implementation of item:get_shadow().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_shadow(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  const std::string& shadow = item.get_shadow();
  if (shadow.empty()) {
    lua_pushnil(l);
  }
  else {
    push_string(l, shadow);
  }
  return 1;
}
示例#30
0
/**
 * \brief Implementation of item:get_sound_when_brandished().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_sound_when_brandished(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  const std::string& sound_when_brandished = item.get_sound_when_brandished();
  if (sound_when_brandished.empty()) {
    lua_pushnil(l);
  }
  else {
    push_string(l, sound_when_brandished);
  }
  return 1;
}