Exemplo n.º 1
0
/// Creates a deep clone of an object
static Object copy_object(Object obj)
{
  switch (obj.type) {
    case kObjectTypeNil:
    case kObjectTypeBoolean:
    case kObjectTypeInteger:
    case kObjectTypeFloat:
      return obj;

    case kObjectTypeString:
      return STRING_OBJ(cstr_to_string(obj.data.string.data));

    case kObjectTypeArray: {
      Array rv = ARRAY_DICT_INIT;
      for (size_t i = 0; i < obj.data.array.size; i++) {
        ADD(rv, copy_object(obj.data.array.items[i]));
      }
      return ARRAY_OBJ(rv);
    }

    case kObjectTypeDictionary: {
      Dictionary rv = ARRAY_DICT_INIT;
      for (size_t i = 0; i < obj.data.dictionary.size; i++) {
        KeyValuePair item = obj.data.dictionary.items[i];
        PUT(rv, item.key.data, copy_object(item.value));
      }
      return DICTIONARY_OBJ(rv);
    }
    default:
      abort();
  }
}
Exemplo n.º 2
0
static void ui_bridge_cursor_styleset(UI *b, Dictionary style)
{
  Object copy = copy_object(DICTIONARY_OBJ(style));
  Object *pobj = xmalloc(sizeof(copy));
  *pobj = copy;
  UI_CALL(b, cursor_styleset, 2, b, pobj);
}
Exemplo n.º 3
0
void oedit_setup_existing(struct descriptor_data *d, int real_num)
{
  struct obj_data *obj;

  /*
   * Allocate object in memory.
   */
  CREATE(obj, struct obj_data, 1);
  copy_object(obj, &obj_proto[real_num]);

  /*
   * Attach new object to player's descriptor.
   */
  OLC_OBJ(d) = obj;
  OLC_VAL(d) = 0;
  OLC_ITEM_TYPE(d) = OBJ_TRIGGER;
  dg_olc_script_copy(d);
  /*
   * The edited obj must not have a script.
   * It will be assigned to the updated obj later, after editing.
   */
  SCRIPT(obj) = NULL;
  OLC_OBJ(d)->proto_script = NULL;

  oedit_disp_menu(d);
}
Exemplo n.º 4
0
void TEST_COPY_OBJECT_WITH_SRC_OBJECT_NOT_EXIST() {
    int error;
    buffer* resp = NULL;

    const char* src_obj_key = "src_object_not_exist";

    // delete src object 
    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    // copy obj
    const char* dst_obj_key = src_obj_key;
    resp = copy_object(host, src_bucket, src_obj_key,
            dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(404 == resp->status_code);
    if (404 != resp->status_code) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);
}
Exemplo n.º 5
0
/* 
 * Called from process_info/1,2.
 */
Eterm erts_dictionary_copy(Process *p, ProcDict *pd) 
{
    Eterm* hp;
    Eterm* heap_start;
    Eterm res = NIL;
    Eterm tmp, tmp2;
    unsigned int i, num;

    if (pd == NULL) {
	return res;
    }

    PD_CHECK(pd);
    num = HASH_RANGE(pd);
    heap_start = hp = (Eterm *) erts_alloc(ERTS_ALC_T_TMP,
					   sizeof(Eterm) * pd->numElements * 2);
    for (i = 0; i < num; ++i) {
	tmp = ARRAY_GET(pd, i);
	if (is_boxed(tmp)) {
	    ASSERT(is_tuple(tmp));
	    res = CONS(hp, tmp, res);
	    hp += 2;
	} else if (is_list(tmp)) {
	    while (tmp != NIL) {
		tmp2 = TCAR(tmp);
		res = CONS(hp, tmp2, res);
		hp += 2;
		tmp = TCDR(tmp);
	    }
	}
    }
    res = copy_object(res, p);
    erts_free(ERTS_ALC_T_TMP, (void *) heap_start);
    return res;
}
Exemplo n.º 6
0
static void ui_bridge_mode_info_set(UI *b, bool enabled, Array modes)
{
  bool *enabledp = xmalloc(sizeof(*enabledp));
  Object *modesp = xmalloc(sizeof(*modesp));
  *enabledp = enabled;
  *modesp = copy_object(ARRAY_OBJ(modes));
  UI_CALL(b, mode_info_set, 3, b, enabledp, modesp);
}
Exemplo n.º 7
0
Arquivo: shop.c Projeto: atrinik/dwc
/**
 * Insert money inside player.
 * @param pl Player.
 * @param money Money object to insert.
 * @param nrof How many money objects to insert to player. */
void insert_money_in_player(object *pl, object *money, uint32 nrof)
{
	object *tmp = get_object();
	copy_object(money, tmp, 0);
	tmp->nrof = nrof;
	tmp = insert_ob_in_ob(tmp, pl);
	esrv_send_item(pl, tmp);
	esrv_send_item(pl, pl);
	esrv_update_item(UPD_WEIGHT, pl, pl);
}
Exemplo n.º 8
0
Arquivo: ui.c Projeto: roxma/neovim
static Array translate_firstarg(UI *ui, Array args)
{
  Array new_args = ARRAY_DICT_INIT;
  Array contents = args.items[0].data.array;

  ADD(new_args, ARRAY_OBJ(translate_contents(ui, contents)));
  for (size_t i = 1; i < args.size; i++) {
    ADD(new_args, copy_object(args.items[i]));
  }
  return new_args;
}
Exemplo n.º 9
0
int main(int argc, char* argv[]) {
    if (argc != 6) {
        printf("[Usage] %s [region(bj/hz/sh/hk/skll)] [src_bucket]"
                " [src_object] [dst_bucket] [dst_object]\n", argv[0]);
        return 0;
    }
    int ret = load_key();
    if (ret != 0) {
        printf("[ERROR] load key failed\n");
        return ret;
    }

    char* region = argv[1];
    char* src_bucket = argv[2];
    char* src_object = argv[3];
    char* dst_bucket = argv[4];
    char* dst_object = argv[5];
    char* host = NULL;
    if (strncmp(region, "bj", strlen("bj")) == 0) {
        host = bj_host;
    } else if (strncmp(region, "hz", strlen("hz")) == 0) {
        host = hz_host;
    } else if (strncmp(region, "sh", strlen("sh")) == 0) {
        host = sh_host;
    } else if (strncmp(region, "hk", strlen("hk")) == 0) {
        host = hk_host;
    } else if (strncmp(region, "skll", strlen("skll")) == 0) {
        host = skll_host;
    } else {
        printf("[ERROR] unknown region %s\n", region);
        return 0;
    }

    int error;
    buffer* resp = NULL;

    resp = copy_object(host, src_bucket, src_object, dst_bucket,
            dst_object, ak, sk, NULL, NULL, &error);
    if (error != 0) {
        printf("curl error=%d\n", error);
        return error;
    }

    if (resp->status_code == 200) {
        printf("[OK] copy object [%s:%s]->[%s:%s] ok\n",
                src_bucket, src_object, dst_bucket, dst_object);
    } else {
        printf("[ERROR] status_code=%d\n", resp->status_code);
        printf("[ERROR] status_msg=%s\n", resp->status_msg);
        printf("[ERROR] err_msg=%s\n", resp->body);
    }
    buffer_free(resp);
    return 0;
}
Exemplo n.º 10
0
void TEST_COPY_OBJECT_WITH_DIFF_BUCKET() {
    int error;
    buffer* resp = NULL;

    const char* src_obj_key = "unit_test_dir/src_object1";

    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    // upload first
    const char* filename = "./lib/libcunit.a";
    resp = upload_file_object(host, src_bucket, src_obj_key, filename,
            ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (resp->status_code != 200) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // copy obj
    const char* dst_obj_key = src_obj_key;

    resp = delete_object(host, dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = copy_object(host, src_bucket, src_obj_key,
            dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (200 != resp->status_code) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // delete src and dst obj
    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);

    resp = delete_object(host, dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);
}
Exemplo n.º 11
0
Dictionary api_metadata(void)
{
    static Dictionary metadata = ARRAY_DICT_INIT;

    if (!metadata.size) {
        msgpack_rpc_init_function_metadata(&metadata);
        init_error_type_metadata(&metadata);
        init_type_metadata(&metadata);
    }

    return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary;
}
Exemplo n.º 12
0
object *
copy_object (object *obj)
{
    object *ret = NULL;
    if (NULL == obj)
        return NULL;
    else if (SCM_VOID == obj->type)
        ret = SCM_void ();
    else if (SCM_ERROR == obj->type)
        ret = SCM_error (((error_object *) obj)->error,
                         ((error_object *) obj)->msg);
    else if (SCM_ATOM == obj->type)
        ret = SCM_atom (((atom_object *) obj)->name);
    else if (SCM_BOOL == obj->type)
        ret = SCM_bool (((bool_object *) obj)->value);
    else if (SCM_VARIABLE == obj->type)
        ret = SCM_variable (((variable_object *) obj)->name,
                            copy_object (((variable_object *) obj)->value));
    else if (SCM_NUMBER == obj->type)
        ret = SCM_number_from_double (((number_object *) obj)->num);
    else if (SCM_STRING == obj->type)
        ret = SCM_string (((string_object *) obj)->str);
    else if (SCM_PAIR == obj->type)
        ret = SCM_cons (copy_object (car (obj)), copy_object (cdr (obj)));
    else if (SCM_FUNC == obj->type)
        ret = SCM_func (((func_object *) obj)->fn);
    else if (SCM_LAMBDA == obj->type)
        ret = SCM_lambda (copy_object (((lambda_object *) obj)->args),
                          copy_object (((lambda_object *) obj)->sexp));
    else
    {
        print_fatal (ETYPE);
        exit (1);
    }

    return ret;
}
Exemplo n.º 13
0
Arquivo: ui.c Projeto: fatbird/neovim
static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
{
  Array my_args = ARRAY_DICT_INIT;
  // Objects are currently single-reference
  // make a copy, but only if necessary
  if (*args_consumed) {
    for (size_t i = 0; i < args.size; i++) {
      ADD(my_args, copy_object(args.items[i]));
    }
  } else {
    my_args = args;
    *args_consumed = true;
  }
  push_call(ui, name, my_args);
}
Exemplo n.º 14
0
static void remote_ui_cmdline_show(UI *ui, Array args)
{
  Array new_args = ARRAY_DICT_INIT;
  Array contents = args.items[0].data.array;
  Array new_contents = ARRAY_DICT_INIT;
  for (size_t i = 0; i < contents.size; i++) {
    Array item = contents.items[i].data.array;
    Array new_item = ARRAY_DICT_INIT;
    int attr = (int)item.items[0].data.integer;
    if (attr) {
      Dictionary rgb_attrs = hlattrs2dict(syn_attr2entry(attr), ui->rgb);
      ADD(new_item, DICTIONARY_OBJ(rgb_attrs));
    } else {
      ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
    }
    ADD(new_item, copy_object(item.items[1]));
    ADD(new_contents, ARRAY_OBJ(new_item));
  }
  ADD(new_args, ARRAY_OBJ(new_contents));
  for (size_t i = 1; i < args.size; i++) {
    ADD(new_args, copy_object(args.items[i]));
  }
  push_call(ui, "cmdline_show", new_args);
}
Exemplo n.º 15
0
static pyc_object *get_ref_object(RBuffer *buffer) {
	pyc_object *ret;
	pyc_object *obj;
	bool error = false;
	ut32 index = get_ut32 (buffer, &error);
	if (error || index >= r_list_length (refs))
		return NULL;
	obj = r_list_get_n (refs, index);
	if (!obj)
		return NULL;
	ret = copy_object (obj);
	if (!ret)
		free (obj);
	return ret;
}
Exemplo n.º 16
0
Arquivo: ui.c Projeto: roxma/neovim
static Array translate_contents(UI *ui, Array contents)
{
  Array new_contents = ARRAY_DICT_INIT;
  for (size_t i = 0; i < contents.size; i++) {
    Array item = contents.items[i].data.array;
    Array new_item = ARRAY_DICT_INIT;
    int attr = (int)item.items[0].data.integer;
    if (attr) {
      Dictionary rgb_attrs = hlattrs2dict(syn_attr2entry(attr), ui->rgb);
      ADD(new_item, DICTIONARY_OBJ(rgb_attrs));
    } else {
      ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
    }
    ADD(new_item, copy_object(item.items[1]));
    ADD(new_contents, ARRAY_OBJ(new_item));
  }
  return new_contents;
}
Exemplo n.º 17
0
void TEST_COPY_OBJECT_WITH_BLANK_SRC_OBJECT_NAME() {
    int error;
    buffer* resp = NULL;

    const char* src_obj_key = NULL;
    const char* dst_obj_key = "dst-object1";

    // copy obj with blank src object name
    resp = copy_object(host, src_bucket, src_obj_key,
            dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(400 == resp->status_code); // invalid argument
    if (400 != resp->status_code) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);
}
Exemplo n.º 18
0
obj_rnum add_object(struct obj_data *newobj, obj_vnum ovnum)
{
  int found = NOTHING;
  zone_rnum rznum = real_zone_by_thing(ovnum);

  /*
   * Write object to internal tables.
   */
  if ((newobj->item_number = real_object(ovnum)) != NOTHING) {
    copy_object(&obj_proto[newobj->item_number], newobj);
    update_objects(&obj_proto[newobj->item_number]);
    add_to_save_list(zone_table[rznum].number, SL_OBJ);
    return newobj->item_number;
  }

  found = insert_object(newobj, ovnum);
  adjust_objects(found);
  add_to_save_list(zone_table[rznum].number, SL_OBJ);
  return (found);
}
Exemplo n.º 19
0
void TEST_COPY_OBJECT_WITH_SAME_BUCKET_AND_SAME_OBJ_KEY(void) {
    int error;
    buffer* resp = NULL;

    const char* src_obj_key = "unit_test_dir/src_object1";
    const char* filename = "./lib/libcunit.a";

    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = upload_file_object(host, src_bucket, src_obj_key, filename,
            ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (resp->status_code != 200) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    const char* l_dst_bucket = src_bucket;
    const char* dst_obj_key = src_obj_key;
    resp = copy_object(host, src_bucket, src_obj_key,
            l_dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(400 == resp->status_code);
    if (resp->status_code != 400) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);
}
Exemplo n.º 20
0
Arquivo: ui.c Projeto: roxma/neovim
static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
{
  if (!ui->ui_ext[kUILinegrid]) {
    // the representation of highlights in cmdline changed, translate back
    // never consumes args
    if (strequal(name, "cmdline_show")) {
      Array new_args = translate_firstarg(ui, args);
      push_call(ui, name, new_args);
      return;
    } else if (strequal(name, "cmdline_block_show")) {
      Array new_args = ARRAY_DICT_INIT;
      Array block = args.items[0].data.array;
      Array new_block = ARRAY_DICT_INIT;
      for (size_t i = 0; i < block.size; i++) {
        ADD(new_block,
            ARRAY_OBJ(translate_contents(ui, block.items[i].data.array)));
      }
      ADD(new_args, ARRAY_OBJ(new_block));
      push_call(ui, name, new_args);
      return;
    } else if (strequal(name, "cmdline_block_append")) {
      Array new_args = translate_firstarg(ui, args);
      push_call(ui, name, new_args);
      return;
    }
  }

  Array my_args = ARRAY_DICT_INIT;
  // Objects are currently single-reference
  // make a copy, but only if necessary
  if (*args_consumed) {
    for (size_t i = 0; i < args.size; i++) {
      ADD(my_args, copy_object(args.items[i]));
    }
  } else {
    my_args = args;
    *args_consumed = true;
  }
  push_call(ui, name, my_args);
}
Exemplo n.º 21
0
static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
{
  if (!ui->ui_ext[kUINewgrid]) {
    // the representation of cmdline_show changed, translate back
    if (strequal(name, "cmdline_show")) {
      remote_ui_cmdline_show(ui, args);
      // never consumes args
      return;
    }
  }
  Array my_args = ARRAY_DICT_INIT;
  // Objects are currently single-reference
  // make a copy, but only if necessary
  if (*args_consumed) {
    for (size_t i = 0; i < args.size; i++) {
      ADD(my_args, copy_object(args.items[i]));
    }
  } else {
    my_args = args;
    *args_consumed = true;
  }
  push_call(ui, name, my_args);
}
Exemplo n.º 22
0
static Object *AddNewBlenderMesh(Scene *scene, Base *base)
{
	// This little function adds a new mesh object to the blender object list
	// It uses ob to duplicate data as this seems to be easier than creating
	// a new one. This new oject contains no faces nor vertices.
	Mesh *old_me;
	Base *basen;
	Object *ob_new;

	// now create a new blender object.
	// duplicating all the settings from the previous object
	// to the new one.
	ob_new= copy_object(base->object);

	// Ok we don't want to use the actual data from the
	// last object, the above function incremented the 
	// number of users, so decrement it here.
	old_me= ob_new->data;
	old_me->id.us--;

	// Now create a new base to add into the linked list of 
	// vase objects.
	
	basen= MEM_mallocN(sizeof(Base), "duplibase");
	*basen= *base;
	BLI_addhead(&scene->base, basen);	/* addhead: anders oneindige lus */
	basen->object= ob_new;
	basen->flag &= ~SELECT;
				
	// Initialize the mesh data associated with this object.						
	ob_new->data= add_mesh("Mesh");

	// Finally assign the object type.
	ob_new->type= OB_MESH;

	return ob_new;
}
Exemplo n.º 23
0
int main(int argc,const string_t* argv){
	int status,i;
	struct stat statbuf;
	if(argc<3)
		goto printhowto;
	if(stat(argv[argc-1],&statbuf)){
		/*
		 * The destination file/dir does not exist.
		 */
		if(argc>3)
			goto printhowto;
	}else{
		/*
		 * The destination file/dir does exist.
		 */
		if(S_ISDIR(statbuf.st_mode))
			/*
			 * The destination is a directory.
			 */
			goto copydir;
		else /*if(!(S_ISREG(statbuf.st_mode)))*/
			/*
			 * If the destination is not a directory, fail.
			 */
			goto printhowto;
	}
	return copy_object(argv[1],argv[2]);
copydir:
	status = 0;
	for(i=1;i<argc-1;++i)
		if(copy_dir(argv[i],argv[argc-1]))
			status = 1;
	return status;
printhowto:
	fprintf(stderr,"Usage: cp from-file-or-dir dest-name; or cp file1 ... fileN dest-dir\n");
	return 1;
}
Exemplo n.º 24
0
/**
 * Creates the Atrinik map structure from the layout, and adds the floor.
 * @param floorstyle floor style. Can be NULL, in which case a random one
 * is chosen.
 * @param RP Random map parameters.
 * @return Atrinik map structure. */
mapstruct *make_map_floor(char *floorstyle, RMParms *RP)
{
	char styledirname[256], stylefilepath[256];
	mapstruct *style_map = NULL, *newMap = NULL;
	int x, y;

	/* Allocate the map */
	newMap = get_empty_map(RP->Xsize, RP->Ysize);

	/* Get the style map */
	strncpy(styledirname, "/styles/floorstyles", sizeof(styledirname) - 1);
	snprintf(stylefilepath, sizeof(stylefilepath), "%s/%s", styledirname, floorstyle);
	style_map = find_style(styledirname, floorstyle, -1);

	if (style_map == NULL)
	{
		return newMap;
	}

	/* Fill up the map with the given floor style */
	for (x = 0; x < RP->Xsize; x++)
	{
		for (y = 0; y < RP->Ysize; y++)
		{
			object *the_floor = pick_random_object(style_map), *thisfloor = get_object();

			copy_object(the_floor, thisfloor, 0);
			thisfloor->x = x;
			thisfloor->y = y;

			insert_ob_in_map(thisfloor, newMap, thisfloor, INS_NO_MERGE | INS_NO_WALK_ON);
		}
	}

	return newMap;
}
Exemplo n.º 25
0
int id_copy(ID *id, ID **newid, int test)
{
	if(!test) *newid= NULL;

	/* conventions:
	 * - make shallow copy, only this ID block
	 * - id.us of the new ID is set to 1 */
	switch(GS(id->name)) {
		case ID_SCE:
			return 0; /* can't be copied from here */
		case ID_LI:
			return 0; /* can't be copied from here */
		case ID_OB:
			if(!test) *newid= (ID*)copy_object((Object*)id);
			return 1;
		case ID_ME:
			if(!test) *newid= (ID*)copy_mesh((Mesh*)id);
			return 1;
		case ID_CU:
			if(!test) *newid= (ID*)copy_curve((Curve*)id);
			return 1;
		case ID_MB:
			if(!test) *newid= (ID*)copy_mball((MetaBall*)id);
			return 1;
		case ID_MA:
			if(!test) *newid= (ID*)copy_material((Material*)id);
			return 1;
		case ID_TE:
			if(!test) *newid= (ID*)copy_texture((Tex*)id);
			return 1;
		case ID_IM:
			if(!test) *newid= (ID*)copy_image((Image*)id);
			return 1;
		case ID_LT:
			if(!test) *newid= (ID*)copy_lattice((Lattice*)id);
			return 1;
		case ID_LA:
			if(!test) *newid= (ID*)copy_lamp((Lamp*)id);
			return 1;
		case ID_SPK:
			if(!test) *newid= (ID*)copy_speaker((Speaker*)id);
			return 1;
		case ID_CA:
			if(!test) *newid= (ID*)copy_camera((Camera*)id);
			return 1;
		case ID_IP:
			return 0; /* deprecated */
		case ID_KE:
			if(!test) *newid= (ID*)copy_key((Key*)id);
			return 1;
		case ID_WO:
			if(!test) *newid= (ID*)copy_world((World*)id);
			return 1;
		case ID_SCR:
			return 0; /* can't be copied from here */
		case ID_VF:
			return 0; /* not implemented */
		case ID_TXT:
			if(!test) *newid= (ID*)copy_text((Text*)id);
			return 1;
		case ID_SCRIPT:
			return 0; /* deprecated */
		case ID_SO:
			return 0; /* not implemented */
		case ID_GR:
			if(!test) *newid= (ID*)copy_group((Group*)id);
			return 1;
		case ID_AR:
			if(!test) *newid= (ID*)copy_armature((bArmature*)id);
			return 1;
		case ID_AC:
			if(!test) *newid= (ID*)copy_action((bAction*)id);
			return 1;
		case ID_NT:
			if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id);
			return 1;
		case ID_BR:
			if(!test) *newid= (ID*)copy_brush((Brush*)id);
			return 1;
		case ID_PA:
			if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id);
			return 1;
		case ID_WM:
			return 0; /* can't be copied from here */
		case ID_GD:
			return 0; /* not implemented */
	}
	
	return 0;
}
Exemplo n.º 26
0
static PyObject*
test_neighborhood_iterator(PyObject* NPY_UNUSED(self), PyObject* args)
{
    PyObject *x, *fill, *out, *b;
    PyArrayObject *ax, *afill;
    PyArrayIterObject *itx;
    int i, typenum, mode, st;
    npy_intp bounds[NPY_MAXDIMS*2];
    PyArrayNeighborhoodIterObject *niterx;

    if (!PyArg_ParseTuple(args, "OOOi", &x, &b, &fill, &mode)) {
        return NULL;
    }

    if (!PySequence_Check(b)) {
        return NULL;
    }

    typenum = PyArray_ObjectType(x, 0);
    typenum = PyArray_ObjectType(fill, typenum);

    ax = (PyArrayObject*)PyArray_FromObject(x, typenum, 1, 10);
    if (ax == NULL) {
        return NULL;
    }
    if (PySequence_Size(b) != 2 * PyArray_NDIM(ax)) {
        PyErr_SetString(PyExc_ValueError,
                "bounds sequence size not compatible with x input");
        goto clean_ax;
    }

    out = PyList_New(0);
    if (out == NULL) {
        goto clean_ax;
    }

    itx = (PyArrayIterObject*)PyArray_IterNew(x);
    if (itx == NULL) {
        goto clean_out;
    }

    /* Compute boundaries for the neighborhood iterator */
    for (i = 0; i < 2 * PyArray_NDIM(ax); ++i) {
        PyObject* bound;
        bound = PySequence_GetItem(b, i);
        if (bounds == NULL) {
            goto clean_itx;
        }
        if (!PyInt_Check(bound)) {
            PyErr_SetString(PyExc_ValueError,
                    "bound not long");
            Py_DECREF(bound);
            goto clean_itx;
        }
        bounds[i] = PyInt_AsLong(bound);
        Py_DECREF(bound);
    }

    /* Create the neighborhood iterator */
    afill = NULL;
    if (mode == NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING) {
            afill = (PyArrayObject *)PyArray_FromObject(fill, typenum, 0, 0);
            if (afill == NULL) {
            goto clean_itx;
        }
    }

    niterx = (PyArrayNeighborhoodIterObject*)PyArray_NeighborhoodIterNew(
                    (PyArrayIterObject*)itx, bounds, mode, afill);
    if (niterx == NULL) {
        goto clean_afill;
    }

    switch (typenum) {
        case NPY_OBJECT:
            st = copy_object(itx, niterx, bounds, &out);
            break;
        case NPY_INT:
            st = copy_int(itx, niterx, bounds, &out);
            break;
        case NPY_DOUBLE:
            st = copy_double(itx, niterx, bounds, &out);
            break;
        default:
            PyErr_SetString(PyExc_ValueError,
                    "Type not supported");
            goto clean_niterx;
    }

    if (st) {
        goto clean_niterx;
    }

    Py_DECREF(niterx);
    Py_XDECREF(afill);
    Py_DECREF(itx);

    Py_DECREF(ax);

    return out;

clean_niterx:
    Py_DECREF(niterx);
clean_afill:
    Py_XDECREF(afill);
clean_itx:
    Py_DECREF(itx);
clean_out:
    Py_DECREF(out);
clean_ax:
    Py_DECREF(ax);
    return NULL;
}
Exemplo n.º 27
0
/**
 * Causes op to fork.
 * @param op Original bolt.
 * @param tmp First piece of the fork. */
void forklightning(object *op, object *tmp)
{
	mapstruct *m;
	/* Direction or -1 for left, +1 for right 0 if no new bolt */
	int xt, yt, new_dir = 1;
	/* Stores temporary dir calculation */
	int t_dir;

	/* pick a fork direction.  tmp->stats.Con is the left bias
	 * i.e., the chance in 100 of forking LEFT
	 * Should start out at 50, down to 25 for one already going left
	 * down to 0 for one going 90 degrees left off original path*/

	/* Fork left */
	if (rndm(0, 99) < tmp->stats.Con)
	{
		new_dir = -1;
	}

	/* Check the new dir for a wall and in the map*/
	t_dir = absdir(tmp->direction + new_dir);

	xt = tmp->x + freearr_x[t_dir];
	yt = tmp->y + freearr_y[t_dir];

	if (!(m = get_map_from_coord(tmp->map, &xt, &yt)) || wall(m, xt, yt))
	{
		new_dir = 0;
	}

	/* OK, we made a fork */
	if (new_dir)
	{
		object *new_bolt = get_object();

		copy_object(tmp, new_bolt, 0);
		new_bolt->stats.food = 0;
		/* Reduce chances of subsequent forking */
		new_bolt->stats.Dex -= 10;
		/* Less forks from main bolt too */
		tmp->stats.Dex -= 10;
		/* Adjust the left bias */
		new_bolt->stats.Con += 25 * new_dir;
		new_bolt->speed_left = -0.1f;
		new_bolt->direction = t_dir;
		new_bolt->stats.hp++;
		new_bolt->x = xt;
		new_bolt->y = yt;
		/* Reduce daughter bolt damage */
		new_bolt->stats.dam /= 2;
		new_bolt->stats.dam++;
		/* Reduce father bolt damage */
		tmp->stats.dam /= 2;
		tmp->stats.dam++;

		if (!insert_ob_in_map(new_bolt, m, op, 0))
		{
			return;
		}

		update_turn_face(new_bolt);
	}
}
Exemplo n.º 28
0
Arquivo: shop.c Projeto: atrinik/dwc
/**
 * This pays for the item, and takes the proper amount of money off the
 * player.
 * @param op Player paying.
 * @param pouch Container (pouch or player) to remove the coins from.
 * @param to_pay Required amount.
 * @return Amount still not paid after using "pouch". */
static sint64 pay_from_container(object *op, object *pouch, sint64 to_pay)
{
	sint64 remain;
	int count, i;
	object *tmp, *coin_objs[NUM_COINS], *next, *bank_object = NULL;
	archetype *at;
	object *who;

	(void) op;

	if (pouch->type != PLAYER && pouch->type != CONTAINER)
	{
		return to_pay;
	}

	remain = to_pay;

	for (i = 0; i < NUM_COINS; i++)
	{
		coin_objs[i] = NULL;
	}

	/* This hunk should remove all the money objects from the player/container */
	for (tmp = pouch->inv; tmp; tmp = next)
	{
		next = tmp->below;

		if (tmp->type == MONEY)
		{
			for (i = 0; i < NUM_COINS; i++)
			{
				if (!strcmp(coins[NUM_COINS - 1 - i], tmp->arch->name) && (tmp->value == tmp->arch->clone.value))
				{
					/* This should not happen, but if it does, just merge
					 * the two. */
					if (coin_objs[i] != NULL)
					{
						LOG(llevBug, "BUG: pay_from_container(): %s has two money entries of (%s)\n", query_name(pouch, NULL), coins[NUM_COINS - 1 - i]);
						remove_ob(tmp);
						coin_objs[i]->nrof += tmp->nrof;
						esrv_del_item(CONTR(pouch), tmp->count, tmp->env);
					}
					else
					{
						remove_ob(tmp);

						if (pouch->type == PLAYER)
						{
							esrv_del_item(CONTR(pouch), tmp->count,tmp->env);
						}

						coin_objs[i] = tmp;
					}

					break;
				}
			}

			if (i == NUM_COINS)
			{
				LOG(llevBug, "BUG: pay_from_container(): Did not find string match for %s\n", tmp->arch->name);
			}
		}
		else if (tmp->arch->name == shstr_cons.player_info && tmp->name == shstr_cons.BANK_GENERAL)
		{
			bank_object = tmp;
		}
	}

	/* Fill in any gaps in the coin_objs array - needed to make change. */
	/* Note that the coin_objs array goes from least value to greatest value */
	for (i = 0; i < NUM_COINS; i++)
	{
		if (coin_objs[i] == NULL)
		{
			at = find_archetype(coins[NUM_COINS - 1 - i]);

			if (at == NULL)
			{
				LOG(llevBug, "BUG: pay_from_container(): Could not find %s archetype", coins[NUM_COINS - 1 - i]);
			}

			coin_objs[i] = get_object();
			copy_object(&at->clone, coin_objs[i], 0);
			coin_objs[i]->nrof = 0;
		}
	}

	for (i = 0; i < NUM_COINS; i++)
	{
		sint64 num_coins;

		if ((sint64) (coin_objs[i]->nrof * coin_objs[i]->value) > remain)
		{
			num_coins = remain / coin_objs[i]->value;

			if ((num_coins * coin_objs[i]->value) < remain)
			{
				num_coins++;
			}
		}
		else
		{
			num_coins = coin_objs[i]->nrof;
		}

		if (num_coins > ((sint64) 1 << 31))
		{
			LOG(llevDebug, "DEBUG: pay_from_container(): Money overflow value->nrof: number of coins > 2 ^ 32 (type coin %d)\n", i);
			num_coins = ((sint64) 1 << 31);
		}

		remain -= num_coins * coin_objs[i]->value;
		coin_objs[i]->nrof -= (uint32) num_coins;
		/* Now start making change.  Start at the coin value
		 * below the one we just did, and work down to
		 * the lowest value. */
		count = i - 1;

		while (remain < 0 && count >= 0)
		{
			num_coins = -remain / coin_objs[count]->value;
			coin_objs[count]->nrof += (uint32) num_coins;
			remain += num_coins * coin_objs[count]->value;
			count--;
		}
	}

	/* If there's still some remain, that means we could try to pay from
	 * bank. */
	if (bank_object && bank_object->value != 0 && remain != 0 && bank_object->value >= remain)
	{
		bank_object->value -= remain;
		remain = 0;
	}

	for (i = 0; i < NUM_COINS; i++)
	{
		if (coin_objs[i]->nrof)
		{
			object *tmp = insert_ob_in_ob(coin_objs[i], pouch);

			for (who = pouch; who && who->type != PLAYER && who->env != NULL; who = who->env)
			{
			}

			esrv_send_item(who, tmp);
			esrv_send_item (who, pouch);
			esrv_update_item(UPD_WEIGHT, who, pouch);

			if (pouch->type != PLAYER)
			{
				esrv_send_item(who, who);
				esrv_update_item(UPD_WEIGHT, who, who);
			}
		}
	}

	return remain;
}
Exemplo n.º 29
0
Arquivo: shop.c Projeto: atrinik/dwc
/**
 * Insert coins into a player.
 * @param pl Player.
 * @param value Value of coins to insert (for example, 120 for 1 silver and 20 copper).
 * @return value. */
sint64 insert_coins(object *pl, sint64 value)
{
	int count;
	object *tmp, *pouch;
	archetype *at;

	for (count = 0; coins[count]; count++)
	{
		at = find_archetype(coins[count]);

		if (at == NULL)
		{
			LOG(llevBug, "BUG: Could not find %s archetype", coins[count]);
		}
		else if ((value / at->clone.value) > 0)
		{
			for (pouch = pl->inv; pouch; pouch = pouch->below)
			{
				if (pouch->type == CONTAINER && QUERY_FLAG(pouch, FLAG_APPLIED) && pouch->race && strstr(pouch->race, "gold"))
				{
					int w = (int) ((float) at->clone.weight * pouch->weapon_speed);
					uint32 n = (uint32) (value / at->clone.value);

					/* Prevent FPE */
					if (w == 0)
					{
						w = 1;
					}

					if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= (sint32) pouch->weight_limit))
					{
						if (pouch->weight_limit && ((sint32)pouch->weight_limit-pouch->carrying) / w < (sint32) n)
						{
							n = (pouch->weight_limit-pouch->carrying) / w;
						}

						tmp = get_object();
						copy_object(&at->clone, tmp, 0);
						tmp->nrof = n;
						value -= tmp->nrof * tmp->value;
						tmp = insert_ob_in_ob(tmp, pouch);
						esrv_send_item(pl, tmp);
						esrv_send_item(pl, pouch);
						esrv_update_item(UPD_WEIGHT, pl, pouch);
						esrv_send_item(pl, pl);
						esrv_update_item(UPD_WEIGHT, pl, pl);
					}
				}
			}

			if (value / at->clone.value > 0)
			{
				tmp = get_object();
				copy_object(&at->clone, tmp, 0);
				tmp->nrof = (uint32) (value / tmp->value);
				value -= tmp->nrof * tmp->value;
				tmp = insert_ob_in_ob(tmp, pl);
				esrv_send_item(pl, tmp);
				esrv_send_item(pl, pl);
				esrv_update_item(UPD_WEIGHT, pl, pl);
			}
		}
	}

	return value;
}
Exemplo n.º 30
0
/**
 * Moves bolt 'op'. Basically, it just advances a space, and checks for
 * various things that may stop it.
 * @param op The bolt object moving. */
void move_bolt(object *op)
{
	int w, r;
	object *tmp;

	if (--(op->stats.hp) < 0)
	{
		destruct_ob(op);
		return;
	}

	if (!op->direction)
	{
		return;
	}

	if (blocks_magic(op->map, op->x + DIRX(op), op->y + DIRY(op)))
	{
		return;
	}

	check_fired_arch(op);

	if (!OBJECT_ACTIVE(op))
	{
		return;
	}

	w = wall(op->map, op->x + DIRX(op), op->y + DIRY(op));
	r = reflwall(op->map, op->x + DIRX(op), op->y + DIRY(op), op);

	if (w && !QUERY_FLAG(op, FLAG_REFLECTING))
	{
		return;
	}

	/* We're about to bounce */
	if (w || r)
	{
		if (op->direction & 1)
		{
			op->direction = absdir(op->direction + 4);
		}
		else
		{
			int left = wall(op->map, op->x + freearr_x[absdir(op->direction - 1)], op->y + freearr_y[absdir(op->direction - 1)]), right = wall(op->map, op->x + freearr_x[absdir(op->direction + 1)], op->y + freearr_y[absdir(op->direction + 1)]);

			if (left == right)
			{
				op->direction = absdir(op->direction + 4);
			}
			else if (left)
			{
				op->direction = absdir(op->direction + 2);
			}
			else if (right)
			{
				op->direction = absdir(op->direction - 2);
			}
		}

		update_turn_face(op);
		return;
	}

	if (op->stats.food || !op->stats.hp)
	{
		return;
	}

	op->stats.food = 1;

	/* Create a copy of this object and put it ahead */
	tmp = get_object();
	copy_object(op, tmp, 0);
	tmp->speed_left = -0.1f;
	tmp->x += DIRX(tmp);
	tmp->y += DIRY(tmp);

	if (!insert_ob_in_map(tmp, op->map, op, 0))
	{
		return;
	}

	if (rndm(0, 99) < tmp->stats.Dex)
	{
		forklightning(op, tmp);
	}

	if (tmp)
	{
		if (!tmp->stats.food)
		{
			tmp->stats.food = 1;
			move_bolt(tmp);
		}
		else
		{
			tmp->stats.food = 0;
		}
	}
}