pair_t * make_pair_impl(const pair_t * dummy_pair, const void * first, const void * second) {
    pair_t   * pair;

    if (!(pair         = malloc(sizeof(pair_t))))                  goto ERR_MALLOC;
    if (!(pair->first  = make_object(dummy_pair->first,  first)))  goto ERR_FIRST_MAKE_OBJECT;
    if (!(pair->second = make_object(dummy_pair->second, second))) goto ERR_SECOND_MAKE_OBJECT;
    return pair;

ERR_SECOND_MAKE_OBJECT:
    object_free(pair->first);
ERR_FIRST_MAKE_OBJECT:
    free(pair);
ERR_MALLOC:
    return NULL;
}
PyObject*
js2py_function(Context* cx, jsval val, jsval parent)
{
    Function* ret = NULL;

    if(parent == JSVAL_VOID || !JSVAL_IS_OBJECT(parent))
    {
        PyErr_BadInternalCall();
        goto error;
    }
    
    ret = (Function*) make_object(FunctionType, cx, val);
    if(ret == NULL) goto error;

    ret->parent = parent;
    if(!JS_AddRoot(cx->cx, &(ret->parent)))
    {
        PyErr_SetString(PyExc_RuntimeError, "Failed to add GC root.");
        goto error;
    }

    goto success;

error:
    Py_XDECREF((PyObject*)ret);
    ret = NULL; // In case of AddRoot error.
success:
    return (PyObject*) ret;
}
void
MainWindow::open(QString fileName)
{
    std::ifstream ifs(qPrintable(fileName));
    char c;
    double x,y;
    Segment_2 s;
    
    while(ifs >> c){
      if(c == 's'){
	ifs >> x >> y;
	Point_2 p(x,y);
	ifs >> x >> y;
	Point_2 q(x,y);
	
	Line_arc_2 la(Segment_2(p,q));
	for(std::vector<CGAL::Object>::iterator it = arcs.begin(); it != arcs.end(); ++it){
	  Circular_arc_2 vca;
	  Line_arc_2 vla;
	  if(assign(vca, *it)){
	    CGAL::intersection(la, vca, std::back_inserter(intersections));
	  } else if(assign(vla, *it)){
	    CGAL::intersection(la, vla, std::back_inserter(intersections));
	  }
	}
	arcs.push_back(make_object(la));
      } else if(c == 'c'){
示例#4
0
struct obj_data *
roll_joint(struct obj_data *tobac, struct obj_data *paper)
{
    struct obj_data *obj;
    struct extra_descr_data *new_descr;
    char buf[200];

    if (!tobac || !paper) {
        errlog(" Attempt to roll_joint with NULL tobac or paper.");
        return NULL;
    }
    obj = make_object();
    obj->shared = null_obj_shared;
    CREATE(new_descr, struct extra_descr_data, 1);

    snprintf(buf, sizeof(buf), "cig cigarette joint %s", fname(tobac->aliases));
    obj->aliases = strdup(buf);
    snprintf(buf, sizeof(buf), "a %s cigarette", fname(tobac->aliases));
    obj->name = strdup(buf);
    snprintf_cat(buf, sizeof(buf), " has been dropped here.", sizeof(buf), "It looks like a %s cigarette, waiting to be smoked.",
        fname(tobac->aliases));
    new_descr->description = strdup(buf);
    new_descr->next = NULL;
    obj->ex_description = new_descr;

    GET_OBJ_TYPE(obj) = ITEM_CIGARETTE;
    GET_OBJ_VAL(obj, 0) = 3 + (GET_OBJ_WEIGHT(tobac) * 3);
    GET_OBJ_VAL(obj, 1) = GET_OBJ_VAL(tobac, 2);
    GET_OBJ_VAL(obj, 2) = SMOKE_TYPE(tobac);
    GET_OBJ_WEAR(obj) = ITEM_WEAR_TAKE + ITEM_WEAR_HOLD;
    GET_OBJ_COST(obj) = GET_OBJ_COST(tobac);

    return obj;
}
示例#5
0
void WizardModeDialog::wiz_mass_create_items(void)
{
    int i;
    object_type object_type_body;

    object_type *i_ptr;

    this->accept();

    for(i=0; i < 25; i++)
    {
        /* Get local object */
        i_ptr = &object_type_body;

        /* Wipe the object */
        i_ptr->object_wipe();

        /* Make a object (if possible) */
        if (!make_object(i_ptr, FALSE, FALSE, DROP_TYPE_UNTHEMED, FALSE)) continue;

        /* Drop the object */
        drop_near(i_ptr, -1, p_ptr->py, p_ptr->px);
    }

}
示例#6
0
/**
 * Place a random object at (x, y).
 * \param c current chunk
 * \param y co-ordinates
 * \param x co-ordinates
 * \param level generation depth
 * \param good is it a good object?
 * \param great is it a great object?
 * \param origin item origin
 * \param tval specified tval, if any
 */
void place_object(struct chunk *c, int y, int x, int level, bool good,
				  bool great, byte origin, int tval)
{
    s32b rating = 0;
    struct object *new_obj;
	bool dummy = true;

    if (!square_in_bounds(c, y, x)) return;
    if (!square_canputitem(c, y, x)) return;

	/* Make an appropriate object */
    new_obj = make_object(c, level, good, great, false, &rating, tval);
	if (!new_obj) return;
    new_obj->origin = origin;
    new_obj->origin_depth = c->depth;

    /* Give it to the floor */
    if (!floor_carry(c, y, x, new_obj, &dummy)) {
		if (new_obj->artifact) {
			new_obj->artifact->created = false;
		}
		object_delete(&new_obj);
		return;
    } else {
		list_object(c, new_obj);
		if (new_obj->artifact) {
			c->good_item = true;
		}
		/* Avoid overflows */
		if (rating > 2500000) {
			rating = 2500000;
		}
		c->obj_rating += (rating / 100) * (rating / 100);
    }
}
示例#7
0
int
main(int argc, char *argv[])
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

  glutCreateWindow("Spin");
  Object = make_object();
  glCullFace(GL_BACK);
  glDisable(GL_DITHER);
  glShadeModel(GL_FLAT);

  glColor3f(1.0, 1.0, 1.0);

  Xrot = Yrot = Zrot = 0.0;
  Xstep = Step;
  Ystep = Zstep = 0.0;

  glutReshapeFunc(reshape);
  glutKeyboardFunc(key);
  glutVisibilityFunc(visible);
  glutDisplayFunc(draw);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
示例#8
0
Value ffi_pointer_read(VMState *state, Object *type, void *ptr) {
  ValueCache *vcache = &state->shared->vcache;
  Object *string_base = vcache->string_base;
  FFIObject *ffi = (FFIObject*) vcache->ffi_obj;
  if (type == ffi->float_obj) {
    float f = *(float*) ptr;
    return FLOAT2VAL(f);
  } else if (type == ffi->int_obj) {
    int i = *(int*) ptr;
    return INT2VAL(i);
  } else if (type == ffi->uint_obj) {
    unsigned int i = *(unsigned int*) ptr;
    return INT2VAL(i);
  } else {
    bool has_pointer = false;
    OBJECT_LOOKUP_P(type, pointer, &has_pointer);
    if (!has_pointer) {
      Object *c_type_obj = OBJ_OR_NULL(OBJECT_LOOKUP(type, c_type));
      StringObject *c_type = (StringObject*) obj_instance_of(c_type_obj, string_base);
      VM_ASSERT(c_type, "internal type error") VNULL;
      VM_ASSERT(false, "unhandled pointer read type: %s", c_type->value) VNULL;
    }
    Value res = make_object(state, type, false);
    char *error = OBJECT_SET(state, AS_OBJ(res), pointer, make_ffi_pointer(state, ptr));
    VM_ASSERT(!error, error) VNULL;
    return res;
  }
}
示例#9
0
文件: gen-util.c 项目: ewert/angband
/**
 * Place a random object at (x, y).
 * \param c current chunk
 * \param y
 * \param x co-ordinates
 * \param level generation depth
 * \param good is it a good object?
 * \param great is it a great object?
 * \param origin item origin
 * \param tval specified tval, if any
 */
void place_object(struct chunk *c, int y, int x, int level, bool good, bool great, byte origin, int tval)
{
    s32b rating = 0;
    struct object *new_obj;

    assert(square_in_bounds(c, y, x));

    if (!square_canputitem(c, y, x)) return;

    new_obj = make_object(c, level, good, great, FALSE, &rating, tval);
	if (!new_obj) return;

    new_obj->origin = origin;
    new_obj->origin_depth = c->depth;

    /* Give it to the floor */
    if (!floor_carry(c, y, x, new_obj, FALSE)) {
		if (new_obj->artifact)
			new_obj->artifact->created = FALSE;
		object_delete(&new_obj);
		return;
    } else {
		if (new_obj->artifact)
			c->good_item = TRUE;
		if (rating > 2500000)
			rating = 2500000; /* avoid overflows */
		c->obj_rating += (rating / 100) * (rating / 100);
    }
}
示例#10
0
/**
 * Allocate objects upon opening a chest
 *
 * Disperse treasures from the given chest, centered at (x,y).
 *
 * Small chests often contain "gold", while Large chests always contain
 * items.  Wooden chests contain 2 items, Iron chests contain 4 items,
 * and Steel chests contain 6 items.  The "value" of the items in a
 * chest is based on the level on which the chest is generated.
 *
 * Judgment of size and construction of chests is currently made from the name.
 */
static void chest_death(int y, int x, struct object *chest)
{
	int number, value;

	bool tiny;

	struct object *treasure;

	/* Small chests often hold "gold" */
	tiny = strstr(chest->kind->name, "Small") ? TRUE : FALSE;

	/* Determine how much to drop (see above) */
	if (strstr(chest->kind->name, "wooden"))
		number = 2;
	else if (strstr(chest->kind->name, "iron"))
		number = 4;
	else if (strstr(chest->kind->name, "steel"))
		number = 6;
	else
		number = 2 * (randint1(3));

	/* Zero pval means empty chest */
	if (!chest->pval) number = 0;

	/* Determine the "value" of the items */
	value = chest->origin_depth - 10 + 2 * chest->sval;
	if (value < 1)
		value = 1;

	/* Drop some objects (non-chests) */
	for (; number > 0; --number) {
		/* Small chests often drop gold */
		if (tiny && (randint0(100) < 75))
			treasure = make_gold(value, "any");

		/* Otherwise drop an item, as long as it isn't a chest */
		else {
			treasure = make_object(cave, value, FALSE, FALSE, FALSE, NULL, 0);
			if (!treasure) continue;
			if (tval_is_chest(treasure)) {
				mem_free(treasure);
				continue;
			}
		}

		/* Record origin */
		treasure->origin = ORIGIN_CHEST;
		treasure->origin_depth = chest->origin_depth;

		/* Drop it in the dungeon */
		drop_near(cave, treasure, 0, y, x, TRUE);
	}

	/* Empty */
	chest->pval = 0;

	/* Known */
	object_notice_everything(chest);
}
示例#11
0
文件: vm.c 项目: kwiskia/chinnu
HeapObject *make_string_ref(VM *vm, char *s) {
    HeapObject *obj = make_object(vm);

    obj->type = OBJECT_STRING;
    obj->value.s = s;

    return obj;
}
示例#12
0
文件: vm.c 项目: kwiskia/chinnu
HeapObject *make_closure_ref(VM *vm, Closure *c) {
    HeapObject *obj = make_object(vm);

    obj->type = OBJECT_CLOSURE;
    obj->value.c = c;

    return obj;
}
示例#13
0
static bool on_begin_json (void * userContext, bool isObject)
{
	user_context * ctx = static_cast<user_context *>(userContext);

	json j = isObject ? make_object() : make_array();
	json * p = ctx->ptr_stack.top();
	p->swap(j);
	return true;
}
示例#14
0
文件: object2.c 项目: jcubic/ToME
/*
 * Attempt to place an object (normal or good/great) at the given location.
 *
 * This routine plays nasty games to generate the "special artifacts".
 *
 * This routine uses "object_level" for the "generation level".
 *
 * This routine requires a clean floor grid destination.
 */
void place_object(s32b y, s32b x, bool good, bool great, s32b where)
{
	object_type *q_ptr;


	/* Paranoia -- check bounds */
	if (!in_bounds(y, x)) return;

	/* Require clean floor space */
	if (!cave_clean_bold(y, x)) return;


	/* Get local object */
	q_ptr = make_object(good, great, NULL);

	/* Make an object (if possible) */
	if (q_ptr == NULL)
		return;

	if (where == OBJ_FOUND_VAULT)
	{
		q_ptr->found = OBJ_FOUND_VAULT;
		q_ptr->found_aux1 = dungeon_type;
		q_ptr->found_aux2 = level_or_feat(dungeon_type, dun_level);
	}
	else if (where == OBJ_FOUND_FLOOR)
	{
		q_ptr->found = OBJ_FOUND_FLOOR;
		q_ptr->found_aux1 = dungeon_type;
		q_ptr->found_aux2 = level_or_feat(dungeon_type, dun_level);
	}
	else if (where == OBJ_FOUND_SPECIAL)
	{
		q_ptr->found = OBJ_FOUND_SPECIAL;
	}
	else if (where == OBJ_FOUND_RUBBLE)
	{
		q_ptr->found = OBJ_FOUND_RUBBLE;
	}

	/* Object array overflow */
	if (!floor_carry(y, x, q_ptr))
	{
		/* Hack -- Preserve artifacts */
		if (q_ptr->artifact_id)
		{
			a_info[q_ptr->artifact_id].cur_num = 0;
		}
		else if (has_flag(&k_info[q_ptr->k_idx], FLAG_NORM_ART))
		{
			k_info[q_ptr->k_idx].artifact = 0;
		}

		delete_object(q_ptr);
	}
}
示例#15
0
    std::vector<std::shared_ptr<monitor_t>> get_list(xcb_connection_t *connection, xcb_window_t root)
    {
      std::vector<std::shared_ptr<monitor_t>> monitors;

      xcb_randr_get_screen_resources_reply_t *sres =
        xcb_randr_get_screen_resources_reply(connection,
          xcb_randr_get_screen_resources(connection, root), nullptr);

      if (sres == nullptr)
        return monitors;

      int len = xcb_randr_get_screen_resources_outputs_length(sres);
      xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_outputs(sres);

      for (int i = 0; i < len; i++) {
        xcb_randr_get_output_info_cookie_t cookie =
          xcb_randr_get_output_info(connection, outputs[i], XCB_CURRENT_TIME);
        xcb_randr_get_output_info_reply_t *info =
          xcb_randr_get_output_info_reply(connection, cookie, nullptr);
        xcb_randr_get_output_info(connection, outputs[i], XCB_CURRENT_TIME);

        if (info == nullptr)
          continue;

        if (info->crtc == XCB_NONE) {
          free(info);
          continue;
        }

        xcb_randr_get_crtc_info_reply_t *cir =
          xcb_randr_get_crtc_info_reply(connection,
            xcb_randr_get_crtc_info(connection, info->crtc, XCB_CURRENT_TIME), nullptr);

        if (cir == nullptr) {
          free(info);
          continue;
        }

        char *monitor_name = (char *) xcb_randr_get_output_info_name(info);
        monitors.emplace_back(make_object(monitor_name, info->name_len, i,
            {cir->x, cir->y, cir->width, cir->height}));

        free(cir);
      }

      std::sort(monitors.begin(), monitors.end(), [](std::shared_ptr<monitor_t> m1, std::shared_ptr<monitor_t> m2) -> bool
      {
        if (m1->bounds.x < m2->bounds.x || m1->bounds.y + m1->bounds.height <= m2->bounds.y)
          return 1;
        if (m1->bounds.x > m2->bounds.x || m1->bounds.y + m1->bounds.height > m2->bounds.y)
          return -1;
        return 0;
      });

      return monitors;
    }
示例#16
0
文件: number.c 项目: Liutos/LiutCL
/* Constructors */
Bignum make_bignum(mpz_t integer)
{
    Bignum bn;

    bn = make_object();
    bn->type = BIGNUM;
    *theBIGNUM(bn) = *integer;

    return bn;
}
示例#17
0
文件: number.c 项目: Liutos/LiutCL
Ratio make_ratio(ratio_t ratio)
{
    Ratio r;

    r = make_object();
    r->type = RATIO;
    theRATIO(r) = ratio;

    return r;
}
示例#18
0
static inline void make_object(const object_t &json_obj, char* json_ptr, const std::string &keys, T &val, Types& ...values )
{
    std::string::size_type pos = keys.find(',');

    std::string current_key = keys.substr(0, pos);

    type::json_traits<T&>::extract(json_obj, json_ptr, current_key.c_str(), current_key.length(), val);

    make_object(json_obj, json_ptr, keys.substr(pos+1, keys.length()-1 ).c_str(), values...);
}
示例#19
0
  template<class K> Object intersection_unoptimized(const Rectangle_2<K> &a, const Rectangle_2<K> &b) {
    typedef K::Point_2                        Point_2;
    typedef std::vector<Point_2>              Container;
    typedef Polygon_2<K, Container>           Polygon_2;
    typedef Polygon_with_holes_2<K,Container> Polygon_with_holes_2;

    if(a.is_degenerate() || b.is_degenerate()) return Object();
    Container pa(a.center()ontainer(true)), pb(b.center()ontainer(true));
    std::vector<Polygon_with_holes_2> res;
    Polygon_2 polya(pa.begin(),pa.end()), polyb(pb.begin(),pb.end());
    intersection(polya,polyb,std::back_inserter(res));
    return (res.empty())?Object():make_object(res.back().outer_boundary().container());
  }
示例#20
0
static void ffi_open_fn(VMState *state, CallInfo *info) {
  VM_ASSERT(info->args_len == 1, "wrong arity: expected 1, got %i", info->args_len);
  Object *root = state->root;
  Object *string_base = state->shared->vcache.string_base;
  Object *array_base = state->shared->vcache.array_base;
  Object *ffi = AS_OBJ(OBJECT_LOOKUP(root, ffi));
  Object *handle_base = AS_OBJ(OBJECT_LOOKUP(ffi, handle));

  StringObject *sarg = (StringObject*) obj_instance_of(OBJ_OR_NULL(load_arg(state->frame, INFO_ARGS_PTR(info)[0])), string_base);
  VM_ASSERT(sarg, "argument to ffi.open must be string!");

  Object *libmap = AS_OBJ(OBJECT_LOOKUP(ffi, library_map));

  char *file = sarg->value;

  bool file_found = false;
  FastKey file_key = prepare_key(file, strlen(file));
  Value mapping = object_lookup_p(libmap, &file_key, &file_found);
  const char **file_list_ptr = NULL;
  int file_list_len = 0;
  if (file_found) {
    ArrayObject *aobj = (ArrayObject*) obj_instance_of(OBJ_OR_NULL(mapping), array_base);
    StringObject *sobj = (StringObject*) obj_instance_of(OBJ_OR_NULL(mapping), string_base);
    if (aobj) {
      file_list_len = aobj->length;
      file_list_ptr = malloc(sizeof(char*) * file_list_len);
      for (int i = 0; i < file_list_len; i++) {
        StringObject *file = (StringObject*) obj_instance_of(OBJ_OR_NULL(aobj->ptr[i]), string_base);
        VM_ASSERT(file, "library_map sub-entries must be string");
        file_list_ptr[i] = my_asprintf("%s", file->value); // outside gc, make copy
      }
    } else if (sobj) {
      file_list_len = 1;
      file_list_ptr = malloc(sizeof(char*) * 1);
      file_list_ptr[0] = my_asprintf("%s", sobj->value);
    } else VM_ASSERT(false, "library_map entries must be string or array");
  } else {
    file_list_len = 1;
    file_list_ptr = malloc(sizeof(char*) * 1);
    file_list_ptr[0] = file;
  }

  void *dlptr = my_dlopen(file_list_len, file_list_ptr);

  Object *handle_obj = AS_OBJ(make_object(state, handle_base, false));
  handle_obj->flags |= OBJ_FROZEN;
  OBJECT_SET(state, handle_obj, pointer, make_ptr(state, dlptr));
  vm_return(state, info, OBJ2VAL(handle_obj));
}
示例#21
0
    std::shared_ptr<monitor_t> make_object(char *name, size_t name_len, int idx, xcb_rectangle_t rect)
    {
      auto mon = make_object();

      mon->bounds = rect;
      mon->index = idx;

      size_t name_size = name_len + 1;
      if (sizeof(mon->name) < name_size)
        name_size = sizeof(mon->name);

      std::snprintf(mon->name, name_size, "%s", name);

      return mon;
    }
示例#22
0
/**
 * Scatter some objects near the player
 */
void acquirement(int y1, int x1, int level, int num, bool great)
{
	struct object *nice_obj;

	/* Acquirement */
	while (num--) {
		/* Make a good (or great) object (if possible) */
		nice_obj = make_object(cave, level, true, great, true, NULL, 0);
		if (!nice_obj) continue;

		nice_obj->origin = ORIGIN_ACQUIRE;
		nice_obj->origin_depth = player->depth;

		/* Drop the object */
		drop_near(cave, nice_obj, 0, y1, x1, true);
	}
}
示例#23
0
object python_result_set::fetch_row()
{
	auto const row = row_based_.fetch_row();
	if (not row.empty()) {
		pybind11::list python_row;
		for (std::size_t column = 0; column != row.size(); ++column) {
			if (row[column].indicator == SQL_NULL_DATA) {
				python_row.append(pybind11::none());
			} else {
				python_row.append(make_object(types_[column], row[column].data_pointer));
			}
		}
		return python_row;
	} else {
		return pybind11::list();
	}
}
示例#24
0
/**
 * Allocate objects upon opening a chest
 *
 * Disperse treasures from the given chest, centered at (x,y).
 *
 * Wooden chests contain 1 item, Iron chests contain 2 items,
 * and Steel chests contain 3 items.  Small chests now contain good items,
 * large chests great items, out of depth for the level on which the chest
 * is generated.
 *
 * Judgment of size and construction of chests is currently made from the name.
 */
static void chest_death(int y, int x, struct object *chest)
{
	int number, level;
	bool large = strstr(chest->kind->name, "Large") ? true : false;;

	/* Zero pval means empty chest */
	if (!chest->pval)
		return;

	/* Determine how much to drop (see above) */
	if (strstr(chest->kind->name, "wooden")) {
		number = 1;
	} else if (strstr(chest->kind->name, "iron")) {
		number = 2;
	} else if (strstr(chest->kind->name, "steel")) {
		number = 3;
	} else {
		number = randint1(3);
	}

	/* Drop some valuable objects (non-chests) */
	level = chest->origin_depth + 5;
	while (number > 0) {
		struct object *treasure;
		treasure = make_object(cave, level, true, large, false, NULL, 0);
		if (!treasure)
			continue;
		if (tval_is_chest(treasure)) {
			object_delete(&treasure);
			continue;
		}

		treasure->origin = ORIGIN_CHEST;
		treasure->origin_depth = chest->origin_depth;
		drop_near(cave, &treasure, 0, y, x, true);
		number--;
	}

	/* Chest is now empty */
	chest->pval = 0;
	chest->known->pval = 0;
}
//======================>>> sboxOGLCanvasPane::graphicsInit <<<========================
  void sboxOGLCanvasPane::graphicsInit(void)
  {
    vBaseGLCanvasPane::graphicsInit();	// Always call the superclass first!

    // **** Your OpenGL initialization code goes here!
  Object = make_object();
  glCullFace(GL_BACK);
  glDisable(GL_DITHER);
  glShadeModel(GL_FLAT);

  glColor3f(1.0, 1.0, 1.0);

  Xrot = Yrot = Zrot = 0.0;
  Xstep = Step;
  Ystep = Zstep = 0.0;
  reshape(300,300);



    initDone = 1;
  }
示例#26
0
文件: object2.c 项目: jcubic/ToME
/*
 * Scatter some "great" objects near the player
 */
void acquirement(s32b y1, s32b x1, s32b num, bool great, bool known)
{
	object_type *i_ptr;

	/* Acquirement */
	while (num--)
	{
		/* Get local object */
		i_ptr = make_object(TRUE, great, NULL);

		/* Make a good (or great) object (if possible) */
		if (i_ptr == NULL)
			return;

		if (known)
		{
			object_aware(i_ptr);
			object_known(i_ptr);
		}

		/* Drop the object */
		drop_near(i_ptr, -1, y1, x1);
	}
}
示例#27
0
extern int parse_directive(int internal_flag)
{
    /*  Internal_flag is FALSE if the directive is encountered normally,
        TRUE if encountered with a # prefix inside a routine or object
        definition.

        Returns: TRUE if program continues, FALSE if end of file reached.    */

    int routine_symbol, rep_symbol;
    int is_renamed;

    begin_syntax_line(FALSE);
    get_next_token();

    if (token_type == EOF_TT) return(FALSE);

    if ((token_type == SEP_TT) && (token_value == HASH_SEP))
        get_next_token();

    if ((token_type == SEP_TT) && (token_value == OPEN_SQUARE_SEP))
    {   if (internal_flag)
        {   error("It is illegal to nest routines using '#['");
            return(TRUE);
        }

        directives.enabled = FALSE;
        directive_keywords.enabled = FALSE;
        segment_markers.enabled = FALSE;

        /* The upcoming symbol is a definition; don't count it as a
           top-level reference *to* the function. */
        df_dont_note_global_symbols = TRUE;
        get_next_token();
        df_dont_note_global_symbols = FALSE;
        if ((token_type != SYMBOL_TT)
                || ((!(sflags[token_value] & UNKNOWN_SFLAG))
                    && (!(sflags[token_value] & REPLACE_SFLAG))))
        {   ebf_error("routine name", token_text);
            return(FALSE);
        }

        routine_symbol = token_value;

        rep_symbol = routine_symbol;
        is_renamed = find_symbol_replacement(&rep_symbol);

        if ((sflags[routine_symbol] & REPLACE_SFLAG)
                && !is_renamed && (is_systemfile()))
        {   /* The function is definitely being replaced (system_file
               always loses priority in a replacement) but is not
               being renamed to something else. Skip its definition
               entirely. */
            dont_enter_into_symbol_table = TRUE;
            do
            {   get_next_token();
            } while (!((token_type == EOF_TT)
                       || ((token_type==SEP_TT)
                           && (token_value==CLOSE_SQUARE_SEP))));
            dont_enter_into_symbol_table = FALSE;
            if (token_type == EOF_TT) return FALSE;
        }
        else
        {   /* Parse the function definition and assign its symbol. */
            assign_symbol(routine_symbol,
                          parse_routine(lexical_source, FALSE,
                                        (char *) symbs[routine_symbol], FALSE, routine_symbol),
                          ROUTINE_T);
            slines[routine_symbol] = routine_starts_line;
        }

        if (is_renamed) {
            /* This function was subject to a "Replace X Y" directive.
               The first time we see a definition for symbol X, we
               copy it to Y -- that's the "original" form of the
               function. */
            if (svals[rep_symbol] == 0) {
                assign_symbol(rep_symbol, svals[routine_symbol], ROUTINE_T);
            }
        }

        get_next_token();
        if ((token_type != SEP_TT) || (token_value != SEMICOLON_SEP))
        {   ebf_error("';' after ']'", token_text);
            put_token_back();
        }
        return TRUE;
    }

    if ((token_type == SYMBOL_TT) && (stypes[token_value] == CLASS_T))
    {   if (internal_flag)
        {   error("It is illegal to nest an object in a routine using '#classname'");
            return(TRUE);
        }
        sflags[token_value] |= USED_SFLAG;
        make_object(FALSE, NULL, -1, -1, svals[token_value]);
        return TRUE;
    }

    if (token_type != DIRECTIVE_TT)
    {   /* If we're internal, we expect only a directive here. If
           we're top-level, the possibilities are broader. */
        if (internal_flag)
            ebf_error("directive", token_text);
        else
            ebf_error("directive, '[' or class name", token_text);
        panic_mode_error_recovery();
        return TRUE;
    }

    return !(parse_given_directive(internal_flag));
}
示例#28
0
/*
 * Helper function for monster_death -
 * Drop the monster's normal objects
 */
static void mon_drop_loot(int m_idx)
{
	monster_type *m_ptr = &mon_list[m_idx];

	monster_race *r_ptr = &r_info[m_ptr->r_idx];

	int j;
	bool chest = (r_ptr->flags1 & (RF1_DROP_CHEST)) ? TRUE : FALSE;
	bool good = (r_ptr->flags1 & (RF1_DROP_GOOD)) ? TRUE : FALSE;
	bool great = (r_ptr->flags1 & (RF1_DROP_GREAT)) ? TRUE : FALSE;

	bool do_gold = (!(r_ptr->flags1 & (RF1_ONLY_ITEM)));
	bool do_item = (!(r_ptr->flags1 & (RF1_ONLY_GOLD)));
	bool visible = (m_ptr->ml || (r_ptr->flags1 & (RF1_UNIQUE)));

	int force_coin = get_coin_type(r_ptr);

	int dump_item = 0;
	int dump_gold = 0;

	int number_drops = 0;

	object_type *i_ptr;
	object_type object_type_body;

	/* Average dungeon and monster levels */
	s16b set_object_level = object_level = (effective_depth(p_ptr->depth) + r_ptr->level) / 2;

	/* Determine how much we can drop */
	if ((r_ptr->flags1 & (RF1_DROP_60)) && (rand_int(100) < 60)) number_drops++;
	if ((r_ptr->flags1 & (RF1_DROP_90)) && (rand_int(100) < 90)) number_drops++;
	if (r_ptr->flags1 & (RF1_DROP_1D2)) number_drops += damroll(1, 2);
	if (r_ptr->flags1 & (RF1_DROP_2D2)) number_drops += damroll(2, 2);
	if (r_ptr->flags1 & (RF1_DROP_3D2)) number_drops += damroll(3, 2);
	if (r_ptr->flags1 & (RF1_DROP_4D2)) number_drops += damroll(4, 2);

	/* Hack -- handle creeping coins */
	coin_type = force_coin;

	/* Drop some objects */
	for (j = 0; j < number_drops; j++)
	{
		bool interesting = FALSE;

		/* Re-set the object level */
		object_level = set_object_level;

		/* Get local object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		/* work on the "too much junk" problem, large drops sometimes are less items with a "boost". */
		if ((randint(750) < (number_drops * number_drops)) && (!(r_ptr->flags1 & (RF1_UNIQUE))))
		{
			interesting = TRUE;
			number_drops -= 5;
			object_level += 5;

			/*Boundry Control*/
			if (number_drops < 0) number_drops = 0;
			if (object_level > MAX_DEPTH) object_level = MAX_DEPTH;
		}

		/* Make Gold */
		if (do_gold && (!chest) && (!do_item || (rand_int(100) < 50)))
		{
			/* Make some gold */
			if (!make_gold(i_ptr)) continue;

			/* Assume seen XXX XXX XXX */
			dump_gold++;
		}

		/* Make Object */
		else
		{
			if (chest)
			{
				if (!make_object(i_ptr, good, great, DROP_TYPE_CHEST, FALSE)) continue;
			}

			/* Make an object */
			else if (!make_object(i_ptr, good, great, DROP_TYPE_UNTHEMED, interesting)) continue;

			/* Remember history */
			if (visible) object_history(i_ptr, ORIGIN_DROP_KNOWN, m_ptr->r_idx);
			else object_history(i_ptr, ORIGIN_DROP_UNKNOWN, 0);

			/* Assume seen XXX XXX XXX */
			dump_item++;
		}

		/* Drop it in the dungeon */
		drop_near(i_ptr, -1, m_ptr->fy, m_ptr->fx);
	}

	/* Re-set the object level */
	object_level = set_object_level;

	/*If marked for a bonus item, create it and drop it */
	if (m_ptr->mflag & (MFLAG_BONUS_ITEM))
	{
		bool this_good = good;
		bool this_great = great;
		bool this_chest = chest;
		bool interesting = FALSE;

		char o_name[80];

		/* Get local object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		if (one_in_(50)) this_chest = TRUE;
		if (one_in_(15)) this_great = TRUE;
		if (one_in_(5)) this_good = TRUE;
		if ((!this_good) && (!this_great) && (!this_chest))
		{
			object_level += 5;
			if (object_level > MAX_DEPTH) object_level = MAX_DEPTH;
			interesting = TRUE;
		}

		if (this_chest)
		{
			while (!make_object(i_ptr, TRUE, TRUE, DROP_TYPE_CHEST, FALSE)) continue;
		}

		/* Make an object */
		else while (!make_object(i_ptr, this_good, this_good, DROP_TYPE_UNTHEMED, interesting)) continue;

		/* Remember history */
		if (visible) object_history(i_ptr, ORIGIN_DROP_KNOWN, m_ptr->r_idx);
		else object_history(i_ptr, ORIGIN_DROP_UNKNOWN, 0);

		object_desc(o_name, sizeof(o_name), i_ptr, ODESC_PREFIX | ODESC_FULL);

		/* Drop it in the dungeon */
		drop_near(i_ptr, -1, m_ptr->fy, m_ptr->fx);


	}

	/* Reset the object level */
	object_level = effective_depth(p_ptr->depth);

	/* Reset "coin" type */
	coin_type = 0;

	/* Take note of any dropped treasure */
	if (visible && (dump_item || dump_gold))
	{
		/* Take notes on treasure */
		lore_treasure(m_idx, dump_item, dump_gold);
	}

}
示例#29
0
文件: chest.c 项目: JEAus/angband
/*
 * Allocate objects upon opening a chest
 *
 * Disperse treasures from the given chest, centered at (x,y).
 *
 * Small chests often contain "gold", while Large chests always contain
 * items.  Wooden chests contain 2 items, Iron chests contain 4 items,
 * and Steel chests contain 6 items.  The "value" of the items in a
 * chest is based on the level on which the chest is generated.
 */
static void chest_death(int y, int x, s16b o_idx)
{
	int number, value;

	bool tiny;

	object_type *o_ptr;

	object_type *i_ptr;
	object_type object_type_body;


	/* Get the chest */
	o_ptr = object_byid(o_idx);

	/* Small chests often hold "gold" */
	tiny = (o_ptr->sval < SV_CHEST_MIN_LARGE);

	/* Determine how much to drop (see above) */
	number = (o_ptr->sval % SV_CHEST_MIN_LARGE) * 2;

	/* Zero pval means empty chest */
	if (!o_ptr->pval[DEFAULT_PVAL]) number = 0;

	/* Determine the "value" of the items */
	value = o_ptr->origin_depth - 10 + 2 * o_ptr->sval;
	if (value < 1)
		value = 1;

	/* Drop some objects (non-chests) */
	for (; number > 0; --number)
	{
		/* Get local object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		/* Small chests often drop gold */
		if (tiny && (randint0(100) < 75))
			make_gold(i_ptr, value, SV_GOLD_ANY);

		/* Otherwise drop an item, as long as it isn't a chest */
		else {
			if (!make_object(cave, i_ptr, value, FALSE, FALSE, NULL)) continue;
			if (i_ptr->tval == TV_CHEST) continue;
		}

		/* Record origin */
		i_ptr->origin = ORIGIN_CHEST;
		i_ptr->origin_depth = o_ptr->origin_depth;

		/* Drop it in the dungeon */
		drop_near(cave, i_ptr, 0, y, x, TRUE);
	}

	/* Empty */
	o_ptr->pval[DEFAULT_PVAL] = 0;

	/* Known */
	object_notice_everything(o_ptr);
}
示例#30
0
bool test_object(const fig_object & o, const std::string & mask){
  return make_object(o, mask)==o;
}