Esempio n. 1
0
void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const {

	if (this!=p_original && get_owner()!=p_original)
		return;

	List<Connection> conns;
	get_all_signal_connections(&conns);

	for (List<Connection>::Element *E=conns.front();E;E=E->next()) {

		if (E->get().flags&CONNECT_PERSIST) {
			//user connected
			NodePath p = p_original->get_path_to(this);
			Node *copy = p_copy->get_node(p);

			Node *target = E->get().target->cast_to<Node>();
			if (!target)
				continue;
			NodePath ptarget = p_original->get_path_to(target);
			Node *copytarget = p_copy->get_node(ptarget);

			if (copy && copytarget) {
				copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST);
			}
		}
	}

	for(int i=0;i<get_child_count();i++) {
		get_child(i)->_duplicate_signals(p_original,p_copy);
	}

}
Esempio n. 2
0
// -----------------------------------------------------------
// object owned by a player
// -----------------------------------------------------------
void t_owned_adv_object::place( t_adventure_map& map, t_adv_map_point const& point )
{
	t_stationary_adventure_object::place( map, point );

	if (m_owner >= 0)
		get_owner()->add_object( this );
	setup_flag_color();
}
Esempio n. 3
0
/**
 * \brief Get the epsilon to apply when the item is aligned.
 */
bear::universe::coordinate_type
bear::universe::physical_item::get_align_epsilon() const
{
  if ( has_owner() )
    return get_owner().get_position_epsilon();
  else
    return 0;
} // physical_item::get_align_epsilon()
Esempio n. 4
0
void dsp_preset::contents_to_stream(stream_writer * p_stream,abort_callback & p_abort) const {
	t_size size = get_data_size();
	p_stream->write_lendian_t(get_owner(),p_abort);
	p_stream->write_lendian_t(size,p_abort);
	if (size > 0) {
		p_stream->write_object(get_data(),size,p_abort);
	}
}
Esempio n. 5
0
/**
 * Fires an archetype.
 * @param op Person firing the object.
 * @param caster Object casting the spell.
 * @param x X position where to fire the spell.
 * @param y Y position where to fire the spell.
 * @param dir Direction to fire in.
 * @param at The archetype to fire.
 * @param type Spell ID.
 * @return 0 on failure, 1 on success. */
int fire_arch_from_position(object *op, object *caster, sint16 x, sint16 y, int dir, archetype *at, int type, object *target)
{
	object *tmp, *env;

	if (at == NULL)
	{
		return 0;
	}

	for (env = op; env->env != NULL; env = env->env)
	{
	}

	if (env->map == NULL)
	{
		return 0;
	}

	tmp = arch_to_object(at);

	if (tmp == NULL)
	{
		return 0;
	}

	tmp->stats.sp = type;
	tmp->stats.dam = (sint16) SP_level_dam_adjust(caster, type, tmp->stats.dam);
	tmp->stats.hp = spells[type].bdur + SP_level_strength_adjust(caster, type);
	tmp->x = x, tmp->y = y;
	tmp->direction = dir;
	tmp->stats.grace = tmp->last_sp;
	tmp->stats.maxgrace = 60 + (RANDOM() % 12);
	tmp->enemy = target;

	if (get_owner(op) != NULL)
	{
		copy_owner(tmp, op);
	}
	else
	{
		set_owner(tmp, op);
	}

	tmp->level = SK_level(caster);

	if (QUERY_FLAG(tmp, FLAG_IS_TURNABLE))
	{
		SET_ANIMATION(tmp, (NUM_ANIMATIONS(tmp) / NUM_FACINGS(tmp)) * dir);
	}

	if ((tmp = insert_ob_in_map(tmp, op->map, op, 0)) == NULL)
	{
		return 1;
	}

	move_fired_arch(tmp);
	return 1;
}
Esempio n. 6
0
void Node::_propagate_replace_owner(Node *p_owner,Node* p_by_owner) {	
	if (get_owner()==p_owner)
		set_owner(p_by_owner);
	
	data.blocked++;
	for (int i=0;i<data.children.size();i++) 
		data.children[i]->_propagate_replace_owner(p_owner,p_by_owner);
	data.blocked--;		
}
Esempio n. 7
0
/**
 * \brief Calculate the new acceleration of the item.
 */
void bear::universe::physical_item::adjust_cinetic()
{
  speed_type s( get_speed() );

  if ( has_owner() )
    {
      const speed_type eps(get_owner().get_speed_epsilon());

      if ( (s.x < eps.x) && (s.x > -eps.x) )
        s.x = 0;
      if ( (s.y < eps.y) && (s.y > -eps.y) )
        s.y = 0;

      set_speed(s);

      if ( (get_angular_speed() < get_owner().get_angular_speed_epsilon()) &&
           (get_angular_speed() > -get_owner().get_angular_speed_epsilon()) )
        set_angular_speed(0);
    }
} // physical_item::adjust_cinetic()
Esempio n. 8
0
int main(void){
    chat_t * chat = chat_new("First Chat");
    printf("1st task(Chat name is) : %s\n", get_chat_name(chat));//1st task

    user_t * firstUser = user_new("Dima", "Diachenko", 18);
    chat_add_user(chat, firstUser);
    user_t * secondUser = user_new("Gleb", "Davidov", 18);
    chat_add_user(chat, secondUser); //6th task

    list_t * users_list = list_new();
    users_list = chat_get_list_of_users(chat);

    printf("4th task (and 6th task)(Users in list) : %i\n", list_getSize(users_list));//4th task

    printf("2d task : List of users:\n"); // 2d task
    for(int i = 0; i < list_getSize(users_list); i++){
        user_t * tmp  = (user_t*) list_get(users_list, i);
        printf("%s %s %i\n", user_get_name(tmp), user_get_surname(tmp), user_get_age(tmp));
    }

    printf("7th task : %s - this user was removed!\n", user_get_surname(chat_remove_user_by_surname(chat, "Davidov")));//7th task

    users_list = chat_get_list_of_users(chat);

    printf("2d task : List of users:\n"); // 2d task
    for(int i = 0; i < list_getSize(users_list); i++){
        user_t * tmp  = (user_t*) list_get(users_list, i);
        printf("%s %s %i\n", user_get_name(tmp), user_get_surname(tmp), user_get_age(tmp));
    }

    message_t * msg1 = message_new("Hello!", firstUser);

    chat_add_message(chat, msg1);//8th task
    printf("8th task: added message to chat:\n%s:\t%s\n", user_get_surname(get_owner(msg1)), get_message_text(msg1));

    list_t * msgs_list = list_new();
    msgs_list = get_list_of_messages_of_one_user(chat, firstUser);//5th task
    printf("5th task : Messages of user %s\n", user_get_surname(firstUser));
    for(int i = 0; i < list_getSize(msgs_list); i++){
        message_t * tmpmsg = list_get(msgs_list, i);
        printf("%s\n", get_message_text(tmpmsg));
    }

    msgs_list = get_last_messages(chat, 1);
    printf("3d task : List of last messages(1):\n");
    for(int i = 0; i < list_getSize(msgs_list); i++){
        message_t * tmpmsg = list_get(msgs_list, i);
        printf("%s\n", get_message_text(tmpmsg));
    }

    return 0;
}
Esempio n. 9
0
// -----------------------------------------------------------
// object owned by a player
// -----------------------------------------------------------
void t_owned_adv_object::set_owner( int player_number )
{
	if ( player_number == m_owner )
		return;

	if (m_map!=NULL)
		m_map->record_set_owner_event( this, player_number );

	int old_owner = m_owner;

	if (is_on_map() && m_owner >= 0)
		get_owner()->remove_object( this );

	m_owner = player_number;

	if (is_on_map() && m_owner >= 0)
		get_owner()->add_object( this );

	setup_flag_color();
	on_owner_changed( m_owner, old_owner );

}
Esempio n. 10
0
// -----------------------------------------------------------
// Override of t_abstract_grail_data_source function
// -----------------------------------------------------------
bool t_abstract_town::gets_global_grail_effects( t_town_type alignment ) const
{
	// Note: make sure unowned towns still give grail effects to their garrison
	if ( m_type == alignment && has( k_town_grail ) )
		return true;

	t_player * owner = get_owner();

	if ( owner && owner->gets_global_grail_effects( alignment ) )
		return true;

	return false;
}
Esempio n. 11
0
/**
 * \brief Test if the item is in a given environment.
 * \param e The considered environment.
 */
bool bear::universe::physical_item::is_in_environment
(const universe::environment_type e) const
{
  bool result = false;

  if ( has_owner() )
    {
      std::set<universe::environment_type> environments;
      get_owner().get_environments(get_bounding_box(), environments);
      result = ( environments.find(e) != environments.end());
    }

  return result;
} // physical_item::is_in_environment()
Esempio n. 12
0
/**
 * \brief Test if the item is only in a given environment.
 * \param e The considered environment.
 */
bool bear::universe::physical_item::is_only_in_environment
(const universe::environment_type e) const
{
  bool result = false;

  if ( has_owner() )
    {
      std::set<universe::environment_type> environments;
      get_owner().get_environments(get_bounding_box(), environments);
      if ( environments.size() == 1 )
        result = ( *(environments.begin()) == e );
    }

  return result;
} // physical_item::is_only_in_environment()
Esempio n. 13
0
HRESULT process_get_owner( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
{
    VARIANT user, domain, retval;
    IWbemClassObject *sig, *out_params = NULL;
    HRESULT hr;

    TRACE("%p, %p, %p\n", obj, in, out);

    hr = create_signature( class_processW, method_getownerW, PARAM_OUT, &sig );
    if (hr != S_OK) return hr;

    if (out)
    {
        hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
        if (hr != S_OK)
        {
            IWbemClassObject_Release( sig );
            return hr;
        }
    }
    VariantInit( &user );
    VariantInit( &domain );
    hr = get_owner( &user, &domain, &retval );
    if (hr != S_OK) goto done;
    if (out_params)
    {
        if (!V_UI4( &retval ))
        {
            hr = IWbemClassObject_Put( out_params, param_userW, 0, &user, CIM_STRING );
            if (hr != S_OK) goto done;
            hr = IWbemClassObject_Put( out_params, param_domainW, 0, &domain, CIM_STRING );
            if (hr != S_OK) goto done;
        }
        hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
    }

done:
    VariantClear( &user );
    VariantClear( &domain );
    IWbemClassObject_Release( sig );
    if (hr == S_OK && out)
    {
        *out = out_params;
        IWbemClassObject_AddRef( out_params );
    }
    if (out_params) IWbemClassObject_Release( out_params );
    return hr;
}
Esempio n. 14
0
	void WinSD::parse(PSECURITY_DESCRIPTOR sd) {
#ifdef ENABLE_LOGGER
		WORD ctrl = get_control(sd);
		LogInfo("Security descriptor:");
		LogInfo(L"SDDL: %s", WinSD::as_sddl(sd).c_str());
		LogInfo("Size: %Iu", size(sd));
		try {
			LogInfo(L"Owner: %s", Sid::get_name(get_owner(sd)).c_str());
		} catch (...) {
		}
		try {
			LogInfo(L"Group: %s", Sid::get_name(get_group(sd)).c_str());
		} catch (...) {
		}
		LogInfo(L"Control: 0x%x (%s) [%s]", (int)ctrl, bits::BitMask<WORD>::to_str_bin(ctrl).c_str(), bits::BitMask<WORD>::to_str_num(ctrl).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_OWNER_DEFAULTED))
			LogInfo(L"\tSE_OWNER_DEFAULTED (%s)", simstd::to_wstring(SE_OWNER_DEFAULTED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_GROUP_DEFAULTED))
			LogInfo(L"\tSE_GROUP_DEFAULTED (%s)", simstd::to_wstring(SE_GROUP_DEFAULTED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_DACL_PRESENT))
			LogInfo(L"\tSE_DACL_PRESENT (%s)", simstd::to_wstring(SE_DACL_PRESENT).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_DACL_DEFAULTED))
			LogInfo(L"\tSE_DACL_DEFAULTED (%s)", simstd::to_wstring(SE_DACL_DEFAULTED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_SACL_PRESENT))
			LogInfo(L"\tSE_SACL_PRESENT (%s)", simstd::to_wstring(SE_SACL_PRESENT).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_SACL_DEFAULTED))
			LogInfo(L"\tSE_SACL_DEFAULTED (%s)", simstd::to_wstring(SE_SACL_DEFAULTED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_DACL_AUTO_INHERIT_REQ))
			LogInfo(L"\tSE_DACL_AUTO_INHERIT_REQ (%s)", simstd::to_wstring(SE_DACL_AUTO_INHERIT_REQ).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_SACL_AUTO_INHERIT_REQ))
			LogInfo(L"\tSE_SACL_AUTO_INHERIT_REQ (%s)", simstd::to_wstring(SE_SACL_AUTO_INHERIT_REQ).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_DACL_AUTO_INHERITED))
			LogInfo(L"\tSE_DACL_AUTO_INHERITED (%s)", simstd::to_wstring(SE_DACL_AUTO_INHERITED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_SACL_AUTO_INHERITED))
			LogInfo(L"\tSE_SACL_AUTO_INHERITED (%s)", simstd::to_wstring(SE_SACL_AUTO_INHERITED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_DACL_PROTECTED))
			LogInfo(L"\tSE_DACL_PROTECTED (%s)", simstd::to_wstring(SE_DACL_PROTECTED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_SACL_PROTECTED))
			LogInfo(L"\tSE_SACL_PROTECTED (%s)", simstd::to_wstring(SE_SACL_PROTECTED).c_str());
		if (bits::Flags::check(ctrl, (WORD)SE_SELF_RELATIVE))
			LogInfo(L"\tSE_SELF_RELATIVE (%s)", simstd::to_wstring(SE_SELF_RELATIVE).c_str());
#else
		(void)sd;
#endif
	}
Esempio n. 15
0
int
get_read_copy (int page_number) {
    printf("%d: get_read_copy on page_number: %d\n", thisid, page_number);
    int result;
    pthread_mutex_lock(&locks[page_number]);
    int owner_id = get_owner(page_number);
    if (owner_id == thisid) {
        // Ask myself for read-ownership
        printf("%d: Asking myself for read-ownership of page %d\n", thisid,
                page_number);
        pthread_mutex_unlock(&locks[page_number]);
        return give_read_copy(thisid, NO_RESPONSE, page_number);
    } else {
        // Ask for read-ownership over network
        printf("%d: Asking %d for read-ownership of page %d\n", thisid, owner_id,
                page_number);
        struct Message m = create_message(REQUEST_PERMISSION, READING,
                page_number);
        result = send_and_wait_for_response(owner_id, &m);
    }
    return result;
}
Esempio n. 16
0
File: downboy2.c Progetto: anl/IT
main(int argc,char *argv[])
{
   int k=-1; /* kill threshold in CPU seconds */

   override_type *override_list;
   struct dirent *dir_entry_p;
   DIR *dir_p;
   int uid;

   int opt;

   while ((opt=getopt(argc,argv,"k:h"))!=-1)
      switch (opt)
         {
         case 'k': /* kill threshold in CPU seconds */
            if ((k=atoi(optarg))>0)
               break;

         case '?': /* miscellaneous error condition */
         case 'h': /* help! */
            fprintf(stderr,"downboy2 [-k kill_threshold_in_CPU_seconds]\n");
            exit(-1);
         }

   if ((dir_p=opendir(PROC_ROOT))==NULL)
      fprintf(stderr,"Error: failed to open '%s'!\n",PROC_ROOT);
   else
      {
      override_list=load_override(OVERRIDE_FILE);

      while ((dir_entry_p=readdir(dir_p))!=NULL)
         if (COUNT_DIGITS(dir_entry_p->d_name)==strlen(dir_entry_p->d_name)
            && (uid=get_owner(dir_entry_p->d_name))!=0) /* if not root */
            read_stat(dir_entry_p->d_name,find_override(override_list,uid),
               k,uid);

      closedir(dir_p);
      }
}
Esempio n. 17
0
void Node::remove_and_skip() {
	
	ERR_FAIL_COND(!data.parent);
		
	Node *new_owner=get_owner();
	
	List<Node*> children;
	
	while(true) {
	
		bool clear=true;
		for (int i=0;i<data.children.size();i++) {
			if (!data.children[i]->get_owner())
				continue;
				
			remove_child(data.children[i]);
			data.children[i]->_propagate_replace_owner(this,NULL);
			children.push_back(data.children[i]);	
			clear=false;
			break;
		}
		
		if (clear)
			break;
	}
				
	while(!children.empty()) {
		
		Node *c=children.front()->get();
		data.parent->add_child(c);
		c->_propagate_replace_owner(NULL,new_owner);		
		children.pop_front();
	}
	
	data.parent->remove_child(this);
}
Esempio n. 18
0
File: chown.c Progetto: LubkaB/mc
void
chown_cmd (void)
{
    char *fname;
    struct stat sf_stat;
    uid_t new_user;
    gid_t new_group;
    char buffer[BUF_TINY];

    chown_i18n ();

    do
    {                           /* do while any files remaining */
        vfs_path_t *vpath;
        WDialog *ch_dlg;

        ch_dlg = init_chown ();
        new_user = new_group = -1;

        if (current_panel->marked)
            fname = next_file ();       /* next marked file */
        else
            fname = selection (current_panel)->fname;   /* single file */

        vpath = vfs_path_from_str (fname);
        if (mc_stat (vpath, &sf_stat) != 0)
        {                       /* get status of file */
            dlg_destroy (ch_dlg);
            vfs_path_free (vpath);
            break;
        }
        vfs_path_free (vpath);

        /* select in listboxes */
        listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid)));
        listbox_select_entry (l_group, listbox_search_text (l_group, get_group (sf_stat.st_gid)));

        chown_label (0, str_trunc (fname, GW - 4));
        chown_label (1, str_trunc (get_owner (sf_stat.st_uid), GW - 4));
        chown_label (2, str_trunc (get_group (sf_stat.st_gid), GW - 4));
        size_trunc_len (buffer, GW - 4, sf_stat.st_size, 0, panels_options.kilobyte_si);
        chown_label (3, buffer);
        chown_label (4, string_perm (sf_stat.st_mode));

        switch (dlg_run (ch_dlg))
        {
        case B_CANCEL:
            end_chown = 1;
            break;

        case B_SETUSR:
            {
                struct passwd *user;
                char *text;

                listbox_get_current (l_user, &text, NULL);
                user = getpwnam (text);
                if (user)
                {
                    new_user = user->pw_uid;
                    apply_chowns (new_user, new_group);
                }
                break;
            }

        case B_SETGRP:
            {
                struct group *grp;
                char *text;

                listbox_get_current (l_group, &text, NULL);
                grp = getgrnam (text);
                if (grp)
                {
                    new_group = grp->gr_gid;
                    apply_chowns (new_user, new_group);
                }
                break;
            }

        case B_SETALL:
        case B_ENTER:
            {
                struct group *grp;
                struct passwd *user;
                char *text;

                listbox_get_current (l_group, &text, NULL);
                grp = getgrnam (text);
                if (grp)
                    new_group = grp->gr_gid;
                listbox_get_current (l_user, &text, NULL);
                user = getpwnam (text);
                if (user)
                    new_user = user->pw_uid;
                if (ch_dlg->ret_value == B_ENTER)
                {
                    vfs_path_t *fname_vpath;

                    fname_vpath = vfs_path_from_str (fname);
                    need_update = 1;
                    if (mc_chown (fname_vpath, new_user, new_group) == -1)
                        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                                 fname, unix_error_string (errno));
                    vfs_path_free (fname_vpath);
                }
                else
                    apply_chowns (new_user, new_group);
                break;
            }
        }                       /* switch */

        if (current_panel->marked && ch_dlg->ret_value != B_CANCEL)
        {
            do_file_mark (current_panel, current_file, 0);
            need_update = 1;
        }

        dlg_destroy (ch_dlg);
    }
    while (current_panel->marked && !end_chown);

    chown_done ();
}
Esempio n. 19
0
void MeshInstance::create_debug_tangents() {

	Vector<Vector3> lines;
	Vector<Color> colors;

	Ref<Mesh> mesh = get_mesh();
	if (!mesh.is_valid())
		return;

	for (int i = 0; i < mesh->get_surface_count(); i++) {
		Array arrays = mesh->surface_get_arrays(i);
		Vector<Vector3> verts = arrays[Mesh::ARRAY_VERTEX];
		Vector<Vector3> norms = arrays[Mesh::ARRAY_NORMAL];
		if (norms.size() == 0)
			continue;
		Vector<float> tangents = arrays[Mesh::ARRAY_TANGENT];
		if (tangents.size() == 0)
			continue;

		for (int j = 0; j < verts.size(); j++) {
			Vector3 v = verts[j];
			Vector3 n = norms[j];
			Vector3 t = Vector3(tangents[j * 4 + 0], tangents[j * 4 + 1], tangents[j * 4 + 2]);
			Vector3 b = (n.cross(t)).normalized() * tangents[j * 4 + 3];

			lines.push_back(v); //normal
			colors.push_back(Color(0, 0, 1)); //color
			lines.push_back(v + n * 0.04); //normal
			colors.push_back(Color(0, 0, 1)); //color

			lines.push_back(v); //tangent
			colors.push_back(Color(1, 0, 0)); //color
			lines.push_back(v + t * 0.04); //tangent
			colors.push_back(Color(1, 0, 0)); //color

			lines.push_back(v); //binormal
			colors.push_back(Color(0, 1, 0)); //color
			lines.push_back(v + b * 0.04); //binormal
			colors.push_back(Color(0, 1, 0)); //color
		}
	}

	if (lines.size()) {

		Ref<SpatialMaterial> sm;
		sm.instance();

		sm->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
		sm->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
		sm->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);

		Ref<ArrayMesh> am;
		am.instance();
		Array a;
		a.resize(Mesh::ARRAY_MAX);
		a[Mesh::ARRAY_VERTEX] = lines;
		a[Mesh::ARRAY_COLOR] = colors;

		am->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
		am->surface_set_material(0, sm);

		MeshInstance *mi = memnew(MeshInstance);
		mi->set_mesh(am);
		mi->set_name("DebugTangents");
		add_child(mi);
#ifdef TOOLS_ENABLED

		if (this == get_tree()->get_edited_scene_root())
			mi->set_owner(this);
		else
			mi->set_owner(get_owner());
#endif
	}
}
Esempio n. 20
0
// -----------------------------------------------------------
// object owned by a player
// -----------------------------------------------------------
t_player_color t_owned_adv_object::get_player_color() const
{
	t_player * owner_ptr = get_owner();
	return owner_ptr != 0 ? owner_ptr->get_color() : m_player_color;
}
Esempio n. 21
0
File: achown.c Progetto: jskDr/mc
static void
update_ownership (void)
{
    button_set_text (b_user, get_owner (sf_stat->st_uid));
    button_set_text (b_group, get_group (sf_stat->st_gid));
}
Esempio n. 22
0
File: chmod.c Progetto: BrEacK/mc
static Dlg_head *
init_chmod (const char *fname, const struct stat *sf_stat)
{
    Dlg_head *ch_dlg;
    int lines, cols;
    int perm_gb_len;
    int file_gb_len;
    unsigned int i;
    const char *c_fname, *c_fown, *c_fgrp;
    char buffer[BUF_TINY];

    single_set = (current_panel->marked < 2);
    perm_gb_len = check_perm_len + 2;
    file_gb_len = file_info_labels_len + 2;
    cols = str_term_width1 (fname) + 2 + 1;
    file_gb_len = max (file_gb_len, cols);

    lines = single_set ? 20 : 23;
    cols = perm_gb_len + file_gb_len + 1 + 6;

    if (cols > COLS)
    {
        /* shrink the right groupbox */
        cols = COLS;
        file_gb_len = cols - (perm_gb_len + 1 + 6);
    }

    ch_dlg =
        create_dlg (TRUE, 0, 0, lines, cols, dialog_colors,
                    chmod_callback, NULL, "[Chmod]", _("Chmod command"), DLG_CENTER | DLG_REVERSE);

    for (i = 0; i < chmod_but_num; i++)
    {
        add_widget (ch_dlg,
                    button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 + 1,
                                chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));

        i++;

        add_widget (ch_dlg,
                    button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 - chmod_but[i].len,
                                chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));

        if (single_set)
            break;
    }

    file_gb = groupbox_new (PY, PX + perm_gb_len + 1, check_perm_num + 2, file_gb_len, _("File"));
    add_widget (ch_dlg, file_gb);

    for (i = 0; i < check_perm_num; i++)
    {
        check_perm[i].check = check_new (PY + (check_perm_num - i), PX + 2,
                                         (c_stat & check_perm[i].mode) != 0 ? 1 : 0,
                                         check_perm[i].text);
        add_widget (ch_dlg, check_perm[i].check);
    }

    add_widget (ch_dlg, groupbox_new (PY, PX, check_perm_num + 2, perm_gb_len, _("Permission")));

    /* Set the labels */
    /* Do this at end to have a widget id in a simple way */
    lines = PY + 2;
    cols = PX + perm_gb_len + 3;
    c_fname = str_trunc (fname, file_gb_len - 3);
    add_widget (ch_dlg, label_new (lines, cols, c_fname));
    c_fown = str_trunc (get_owner (sf_stat->st_uid), file_gb_len - 3);
    add_widget (ch_dlg, label_new (lines + 4, cols, c_fown));
    c_fgrp = str_trunc (get_group (sf_stat->st_gid), file_gb_len - 3);
    add_widget (ch_dlg, label_new (lines + 6, cols, c_fgrp));
    g_snprintf (buffer, sizeof (buffer), "%o", (unsigned int) c_stat);
    statl = label_new (lines + 2, cols, buffer);
    add_widget (ch_dlg, statl);

    return ch_dlg;
}
Esempio n. 23
0
/**
 * This is an implementation of the swarm spell. It was written for
 * meteor swarm, but it could be used for any swarm. A swarm spell is a
 * special type of object that casts swarms of other types of spells.
 * Which spell it casts is flexible. It fires the spells from a set of
 * squares surrounding the caster, in a given direction.
 * @param op The spell effect. */
void move_swarm_spell(object *op)
{
	int cardinal_adjust[9] = {-3, -2, -1, 0, 0, 0, 1, 2, 3};
	int diagonal_adjust[10] = {-3, -2, -2, -1, 0, 0, 1, 2, 2, 3};
	int xt, yt, basedir, adjustdir;
	sint16 target_x, target_y, origin_x, origin_y;

	if (op->stats.hp == 0 || get_owner(op) == NULL)
	{
		remove_ob(op);
		check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
		return;
	}

	op->stats.hp--;

	basedir = op->direction;

	if (basedir == 0)
	{
		/* Spray in all directions! 8) */
		basedir = get_random_dir();
	}

	/* New offset calculation to make swarm element distribution
	 * more uniform */
	if (op->stats.hp)
	{
		if (basedir & 1)
		{
			adjustdir = cardinal_adjust[rndm(0, 8)];
		}
		else
		{
			adjustdir = diagonal_adjust[rndm(0, 9)];
		}
	}
	/* Fire the last one from forward. */
	else
	{
		adjustdir = 0;
	}

	target_x = op->x + freearr_x[absdir(basedir + adjustdir)];
	target_y = op->y + freearr_y[absdir(basedir + adjustdir)];

	/* Back up one space so we can hit point-blank targets, but this
	 * necessitates extra get_map_from_coord check below */
	origin_x = target_x - freearr_x[basedir];
	origin_y = target_y - freearr_y[basedir];

	xt = (int) origin_x;
	yt = (int) origin_y;

	if (!get_map_from_coord(op->map, &xt, &yt))
	{
		return;
	}

	if (!wall(op->map, target_x, target_y))
	{
		fire_arch_from_position(op, op, origin_x, origin_y, basedir, op->other_arch, op->stats.sp, NULL);
	}
}
Esempio n. 24
0
/**
 * Detect target for casting a spell.
 * @param op Caster.
 * @param[out] target Will contain target for the spell we're casting.
 * @param flags Spell flags.
 * @return 1 if the object can cast the spell on the target, 0
 * otherwise. */
int find_target_for_spell(object *op, object **target, uint32 flags)
{
	object *tmp;

	/* Default target is nothing. */
	*target = NULL;

	/* We cast something on the map... No target */
	if (flags & SPELL_DESC_DIRECTION)
	{
		return 1;
	}

	/* A player has invoked this spell. */
	if (op->type == PLAYER)
	{
		/* Try to cast on self but only when really no friendly or enemy is set. */
		if ((flags & SPELL_DESC_SELF) && !(flags & (SPELL_DESC_ENEMY | SPELL_DESC_FRIENDLY)))
		{
			/* Self... and no other tests */
			*target = op;
			return 1;
		}

		tmp = CONTR(op)->target_object;

		/* Let's check our target - we have one? friend or enemy? */
		if (!tmp || !OBJECT_ACTIVE(tmp) || tmp == CONTR(op)->ob || CONTR(op)->target_object_count != tmp->count)
		{
			/* Can we cast this on self? */
			if (flags & SPELL_DESC_SELF)
			{
				/* Right, we are target */
				*target = op;
				return 1;
			}
		}
		/* We have a target and it's not self */
		else
		{
			/* Player? */
			if (tmp->type == PLAYER)
			{
				/* Now it will be tricky...
				 * a.) Friendly spell - always allowed to cast
				 * b.) Enemy spell - only allowed when op AND target are
				 *     in a pvp area.
				 * c.) If not a. and b. AND self - cast on self */
				if ((flags & SPELL_DESC_FRIENDLY) && !pvp_area(op, tmp))
				{
					*target = tmp;
					return 1;
				}

				if (flags & SPELL_DESC_ENEMY)
				{
					/* Ok... now op AND tmp must be in PvP - if one not,
					 * this is not allowed. */
					if (op->map && tmp->map && pvp_area(op->type == PLAYER ? op : get_owner(op), tmp->type == PLAYER ? tmp : get_owner(tmp)))
					{
						/* Here we go... PvP! */
						*target = tmp;
						return 1;
					}
				}

				if (flags & SPELL_DESC_SELF)
				{
					*target = op;
					return 1;
				}
			}
			/* Friendly NPC? */
			else if (QUERY_FLAG(tmp, FLAG_FRIENDLY))
			{
				if (flags & SPELL_DESC_FRIENDLY)
				{
					*target = tmp;
					return 1;
				}

				if (flags & SPELL_DESC_SELF)
				{
					*target = op;
					return 1;
				}

				/* Can't cast unfriendly spells on friendly NPCs, but we set target
				 * so the message player gets is accurate. */
				if (flags & SPELL_DESC_ENEMY)
				{
					*target = tmp;
					return 0;
				}
			}
			/* Ok, it is a bad guy */
			else
			{
				if (flags & SPELL_DESC_ENEMY)
				{
					*target = tmp;
					return 1;
				}

				if (flags & SPELL_DESC_SELF)
				{
					*target = op;
					return 1;
				}
			}
		}
	}
	/* A monster or rune/firewall/etc */
	else
	{
		if ((flags & SPELL_DESC_SELF) && !(flags & (SPELL_DESC_ENEMY | SPELL_DESC_FRIENDLY)))
		{
			*target = op;
			return 1;
		}
		else if ((flags & SPELL_DESC_ENEMY) && op->enemy && OBJECT_ACTIVE(op->enemy) && op->enemy->count == op->enemy_count)
		{
			*target = op->enemy;
			return 1;
		}
		else
		{
			*target = op;
			return 1;
		}
	}

	/* Invalid target/spell or whatever */
	return 0;
}
Esempio n. 25
0
/**
 * If we are here, the arch (spell) we check was able to move to this
 * place. wall() has failed, including reflection checking.
 *
 * Look for a target.
 * @param op The spell object. */
void check_fired_arch(object *op)
{
	tag_t op_tag = op->count, tmp_tag;
	object *tmp, *hitter, *head;
	int dam;

	/* we return here if we have NOTHING blocking here */
	if (!blocked(op, op->map, op->x, op->y, op->terrain_flag))
	{
		return;
	}

	if (op->other_arch)
	{
		explode_object(op);
		return;
	}

	if (op->stats.sp == SP_PROBE && op->type == BULLET)
	{
		probe(op);
		remove_ob(op);
		check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
		return;
	}

	hitter = get_owner(op);

	if (!hitter)
	{
		hitter = op;
	}
	else if (hitter->head)
	{
		hitter = hitter->head;
	}

	for (tmp = get_map_ob(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
	{
		head = tmp->head;

		if (!head)
		{
			head = tmp;
		}

		if (!IS_LIVE(tmp))
		{
			continue;
		}

		/* Let friends fire through friends */
		if (is_friend_of(hitter, head) || head == hitter)
		{
			continue;
		}

		tmp_tag = tmp->count;

		dam = hit_player(tmp, op->stats.dam, op, AT_INTERNAL);

		if (was_destroyed(op, op_tag) || !was_destroyed(tmp, tmp_tag) || (op->stats.dam -= dam) < 0)
		{
			if (!QUERY_FLAG(op, FLAG_REMOVED))
			{
				remove_ob(op);
				check_walk_off(op, NULL, MOVE_APPLY_VANISHED);

				return;
			}
		}
	}
}
Esempio n. 26
0
/**
 * Causes cone object 'op' to move a space/hit creatures.
 * @param op Cone object moving. */
void move_cone(object *op)
{
	int i;
	tag_t tag;

	/* If no map then hit_map will crash so just ignore object */
	if (!op->map)
	{
		LOG(llevBug, "BUG: Tried to move_cone object %s without a map.\n", query_name(op, NULL));
		remove_ob(op);
		check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
		return;
	}

	/* Lava saves it's life, but not yours :) */
	if (QUERY_FLAG(op, FLAG_LIFESAVE))
	{
		hit_map(op, 0, 0);
		return;
	}

	/* If no owner left, the spell dies out. */
	if (get_owner(op) == NULL)
	{
		remove_ob(op);
		check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
		return;
	}

	/* Hit map returns 1 if it hits a monster.  If it does, set
	 * food to 1, which will stop the cone from progressing. */
	tag = op->count;
	op->stats.food |= hit_map(op, 0, 1);

	if (was_destroyed(op, tag))
	{
		return;
	}

	if ((op->stats.hp -= 2) < 0)
	{
		if (op->stats.exp)
		{
			op->speed = 0;
			update_ob_speed(op);
			op->stats.exp = 0;
			/* So they will join */
			op->stats.sp = 0;
		}
		else
		{
			remove_ob(op);
			check_walk_off(op, NULL, MOVE_APPLY_VANISHED);
		}

		return;
	}

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

	op->stats.food = 1;

	for (i = -1; i < 2; i++)
	{
		int x = op->x + freearr_x[absdir(op->stats.sp + i)], y = op->y + freearr_y[absdir(op->stats.sp + i)];

		if (ok_to_put_more(op->map, x, y, op))
		{
			object *tmp = arch_to_object(op->arch);

			copy_owner(tmp, op);

			/* *very* important - this is the count value of the
			 * *first* object we created with this cone spell.
			 * we use it for identify this spell. Miss this
			 * and ok_to_put_more will allow to create 1000th
			 * in a single tile! */
			tmp->weight_limit = op->weight_limit;
			tmp->x = x, tmp->y = y;

			tmp->level = op->level;
			tmp->stats.sp = op->stats.sp, tmp->stats.hp = op->stats.hp + 1;
			tmp->stats.maxhp = op->stats.maxhp;
			tmp->stats.dam = op->stats.dam;

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

			if (tmp->other_arch)
			{
				cone_drop(tmp);
			}
		}
	}
}
Esempio n. 27
0
void chmod_cmd (void)
{
    char buffer [BUF_TINY];
    char *fname;
    int i;
    struct stat sf_stat;
    Dlg_head *ch_dlg;

    do {			/* do while any files remaining */
        ch_dlg = init_chmod ();
        if (current_panel->marked)
            fname = next_file ();	/* next marked file */
        else
            fname = selection (current_panel)->fname;	/* single file */

        if (mc_stat (fname, &sf_stat) != 0) {	/* get status of file */
            destroy_dlg (ch_dlg);
            break;
        }

        c_stat = sf_stat.st_mode;
        mode_change = 0;	/* clear changes flag */

        /* set check buttons */
        for (i = 0; i < PERMISSIONS; i++) {
            check_perm[i].check->state = (c_stat & check_perm[i].mode) ? 1 : 0;
            check_perm[i].selected = 0;
        }

        /* Set the labels */
        c_fname = name_trunc (fname, 21);
        add_widget (ch_dlg, label_new (FY+2, FX+2, c_fname));
        c_fown = name_trunc (get_owner (sf_stat.st_uid), 21);
        add_widget (ch_dlg, label_new (FY+6, FX+2, c_fown));
        c_fgrp = name_trunc (get_group (sf_stat.st_gid), 21);
        add_widget (ch_dlg, label_new (FY+8, FX+2, c_fgrp));
        g_snprintf (buffer, sizeof (buffer), "%o", c_stat);
        statl = label_new (FY+4, FX+2, buffer);
        add_widget (ch_dlg, statl);

        run_dlg (ch_dlg);	/* retrieve an action */

        /* do action */
        switch (ch_dlg->ret_value) {
        case B_ENTER:
            if (mode_change)
                if (mc_chmod (fname, c_stat) == -1)
                    message (1, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "),
                             fname, unix_error_string (errno));
            need_update = 1;
            break;

        case B_CANCEL:
            end_chmod = 1;
            break;

        case B_ALL:
        case B_MARKED:
            and_mask = or_mask = 0;
            and_mask = ~and_mask;

            for (i = 0; i < PERMISSIONS; i++) {
                if (check_perm[i].selected || ch_dlg->ret_value == B_ALL) {
                    if (check_perm[i].check->state & C_BOOL)
                        or_mask |= check_perm[i].mode;
                    else
                        and_mask &= ~check_perm[i].mode;
                }
            }

            apply_mask (&sf_stat);
            break;

        case B_SETMRK:
            and_mask = or_mask = 0;
            and_mask = ~and_mask;

            for (i = 0; i < PERMISSIONS; i++) {
                if (check_perm[i].selected)
                    or_mask |= check_perm[i].mode;
            }

            apply_mask (&sf_stat);
            break;
        case B_CLRMRK:
            and_mask = or_mask = 0;
            and_mask = ~and_mask;

            for (i = 0; i < PERMISSIONS; i++) {
                if (check_perm[i].selected)
                    and_mask &= ~check_perm[i].mode;
            }

            apply_mask (&sf_stat);
            break;
        }

        if (current_panel->marked && ch_dlg->ret_value!=B_CANCEL) {
            do_file_mark (current_panel, c_file, 0);
            need_update = 1;
        }
        destroy_dlg (ch_dlg);
    } while (current_panel->marked && !end_chmod);
    chmod_done ();
}
Esempio n. 28
0
void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const {

	if (get_owner()!=get_parent()->get_owner())
		return;

	Node *node=NULL;

	if (get_filename()!="") {

		Ref<PackedScene> res = ResourceLoader::load(get_filename());
		ERR_FAIL_COND(res.is_null());
		node=res->instance();
		ERR_FAIL_COND(!node);
	} else {

		Object *obj = ObjectTypeDB::instance(get_type());
		if (!obj) {
			print_line("could not duplicate: "+String(get_type()));
		}
		ERR_FAIL_COND(!obj);
		node = obj->cast_to<Node>();
		if (!node)
			memdelete(obj);
	}


	List<PropertyInfo> plist;

	get_property_list(&plist);

	for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {

		if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
			continue;
		String name = E->get().name;
		node->set( name, get(name) );

	}

	node->set_name(get_name());
	p_new_parent->add_child(node);

	Node *owner=get_owner();

	if (p_reown_map.has(owner))
		owner=p_reown_map[owner];


	if (owner) {
		NodePath p = get_path_to(owner);
		if (owner!=this) {
			Node *new_owner = node->get_node(p);
			if (new_owner) {
				node->set_owner(new_owner);
			}
		}
	}

	for(int i=0;i<get_child_count();i++) {

		get_child(i)->_duplicate_and_reown(node,p_reown_map);
	}

}
Esempio n. 29
0
File: achown.c Progetto: jskDr/mc
static void
do_enter_key (WDialog * h, int f_pos)
{
    WListbox *chl_list;
    struct passwd *chl_pass;
    struct group *chl_grp;
    int fe;
    gboolean chl_end, is_owner;

    do
    {
        int result;
        WDialog *chl_dlg;
        const char *title;
        int lxx, lyy, b_pos;

        is_owner = (f_pos == 3);
        title = is_owner ? _("owner") : _("group");

        lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53);
        lyy = (LINES - 13) / 2;
        chl_end = FALSE;

        chl_dlg =
            dlg_create (TRUE, lyy, lxx, 13, 17, WPOS_KEEP_DEFAULT, TRUE, dialog_colors,
                        chl_callback, NULL, "[Advanced Chown]", title);

        /* get new listboxes */
        chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL);
        listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL, FALSE);
        if (is_owner)
        {
            /* get and put user names in the listbox */
            setpwent ();
            while ((chl_pass = getpwent ()) != NULL)
                listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL,
                                  FALSE);
            endpwent ();
            fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid));
        }
        else
        {
            /* get and put group names in the listbox */
            setgrent ();
            while ((chl_grp = getgrent ()) != NULL)
                listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL,
                                  FALSE);
            endgrent ();
            fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid));
        }

        listbox_select_entry (chl_list, fe);

        b_pos = chl_list->pos;
        add_widget (chl_dlg, chl_list);

        result = dlg_run (chl_dlg);

        if (result != B_CANCEL)
        {
            if (b_pos != chl_list->pos)
            {
                gboolean ok = FALSE;
                char *text;

                listbox_get_current (chl_list, &text, NULL);
                if (is_owner)
                {
                    chl_pass = getpwnam (text);
                    if (chl_pass != NULL)
                    {
                        ok = TRUE;
                        sf_stat->st_uid = chl_pass->pw_uid;
                    }
                }
                else
                {
                    chl_grp = getgrnam (text);
                    if (chl_grp != NULL)
                    {
                        sf_stat->st_gid = chl_grp->gr_gid;
                        ok = TRUE;
                    }
                }
                if (ok)
                {
                    ch_flags[f_pos + 6] = '+';
                    update_ownership ();
                }
                dlg_focus (h);
                if (ok)
                    print_flags ();
            }
            if (result == KEY_LEFT)
            {
                if (!is_owner)
                    chl_end = TRUE;
                dlg_one_up (ch_dlg);
                f_pos--;
            }
            else if (result == KEY_RIGHT)
            {
                if (is_owner)
                    chl_end = TRUE;
                dlg_one_down (ch_dlg);
                f_pos++;
            }
        }

        /* Here we used to redraw the window */
        dlg_destroy (chl_dlg);
    }
    while (chl_end);
}
Esempio n. 30
0
double initialize(double **data, double **centroids, int *ppp, int rank, int size, options opt) {
  MPI_Status status;
  double comm_time = 0.0;

  if(rank == 0) {
    #ifdef TIME_ALL
      timestamp_type comm_s, comm_e;  
    #endif
    int i, idx, owner;

    int *init = (int*) malloc(opt.n_centroids * sizeof(int));
    check(init);

    double *point = (double*) malloc(opt.dimensions * sizeof(double));
    check(point);
    double *tofree = point;

    for(i = 0; i < opt.n_centroids; i++){
        while(In(idx = randint(opt.n_points), init, i));
        init[i] = idx;
        owner = get_owner(&idx, ppp);
        if(owner != 0) {
          #ifdef TIME_ALL
            get_timestamp(&comm_s);
          #endif
          MPI_Send(&idx, 1, MPI_INT, owner, 999, MPI_COMM_WORLD);
          MPI_Recv(point, opt.dimensions, MPI_DOUBLE, owner, 999, MPI_COMM_WORLD, &status);
          #ifdef TIME_ALL
            get_timestamp(&comm_e);
            comm_time += timestamp_diff_in_seconds(comm_s, comm_e);
          #endif
        } 
        else{
          point = data[idx];
        }
        // printf("%d owned by %d at %d ", init[i], owner, idx);
        // print_vec(point, opt.dimensions);
        memcpy(centroids[i], point, opt.dimensions * sizeof(double));
        point = tofree;
    }
    idx = -1;
    #ifdef TIME_ALL
      get_timestamp(&comm_s);
    #endif
    for(i = 1; i < size; i++)
      MPI_Send(&idx, 1, MPI_INT, i, 999, MPI_COMM_WORLD);
    #ifdef TIME_ALL
      get_timestamp(&comm_e);
      comm_time += timestamp_diff_in_seconds(comm_s, comm_e);
    #endif

    free(init);
    free(tofree);
  }
  else {
    int get_point;
    while(1) {
      MPI_Recv(&get_point, 1, MPI_INT, 0, 999, MPI_COMM_WORLD, &status);
      if(get_point != -1)
        MPI_Send(data[get_point], opt.dimensions, MPI_DOUBLE, 0, 999, MPI_COMM_WORLD);
      else break;
    }
  }
  return comm_time;
}