当前位置: 首页>>代码示例>>C++>>正文


C++ ARR_FIND函数代码示例

本文整理汇总了C++中ARR_FIND函数的典型用法代码示例。如果您正苦于以下问题:C++ ARR_FIND函数的具体用法?C++ ARR_FIND怎么用?C++ ARR_FIND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ARR_FIND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: chat_changechatowner

/*==========================================
 * change a chatroom's owner
 *------------------------------------------*/
int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
{
	struct chat_data* cd;
	struct map_session_data* tmpsd;
	int i;

	nullpo_retr(1, sd);

	cd = (struct chat_data*)map_id2bl(sd->chatID);
	if( cd == NULL || (struct block_list*) sd != cd->owner )
		return 1;

	ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
	if( i == cd->users )
		return -1;  // name not found

	// erase temporarily
	clif_clearchat(cd,0);

	// set new owner
	cd->owner = (struct block_list*) cd->usersd[i];
	clif_changechatowner(cd,cd->usersd[i]);

	// swap the old and new owners' positions
	tmpsd = cd->usersd[i];
	cd->usersd[i] = cd->usersd[0];
	cd->usersd[0] = tmpsd;

	// set the new chatroom position
	map_delblock( &cd->bl );
	cd->bl.x = cd->owner->x;
	cd->bl.y = cd->owner->y;
	map_addblock( &cd->bl );

	// and display again
	clif_dispchat(cd,0);

	return 0;
}
开发者ID:darkmeistersp,项目名称:test,代码行数:42,代码来源:chat.c

示例2: chat_changechatowner

/*==========================================
 * Change a chatroom's owner
 * Return
 *  0: User not found/Missing data
 *  1: Success
 *------------------------------------------*/
bool chat_changechatowner(struct map_session_data* sd, const char* nextownername) {
	struct chat_data* cd;
	struct map_session_data* tmpsd;
	int i;

	nullpo_ret(sd);
	nullpo_ret(nextownername);

	cd = map->id2cd(sd->chat_id);
	if (cd == NULL || &sd->bl != cd->owner)
		return false;

	ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
	if( i == cd->users )
		return false;  // name not found

	// erase temporarily
	clif->clearchat(cd,0);

	// set new owner
	cd->owner = &cd->usersd[i]->bl;
	clif->changechatowner(cd,cd->usersd[i]);

	// swap the old and new owners' positions
	tmpsd = cd->usersd[i];
	cd->usersd[i] = cd->usersd[0];
	cd->usersd[0] = tmpsd;

	// set the new chatroom position
	map->delblock( &cd->bl );
	cd->bl.x = cd->owner->x;
	cd->bl.y = cd->owner->y;
	map->addblock( &cd->bl );

	// and display again
	clif->dispchat(cd,0);

	return true;
}
开发者ID:EPuncker,项目名称:Hercules,代码行数:45,代码来源:chat.c

示例3: elemental_change_mode_ack

/*===============================================================
 * Action that elemental perform after changing mode.
 * Activates one of the skills of the new mode.
 *-------------------------------------------------------------*/
int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
	struct block_list *bl = &ed->master->bl;
	uint16 skill_id, skill_lv;
	int i;

	nullpo_ret(ed);

	if( !bl )
		return 0;

	// Select a skill.
	ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode));
	if( i == MAX_ELESKILLTREE )
		return 0;

	skill_id = ed->db->skill[i].id;
	skill_lv = ed->db->skill[i].lv;

	if( elemental_skillnotok(skill_id, ed) )
		return 0;

	if( ed->ud.skilltimer != INVALID_TIMER )
		return 0;
	else if( DIFF_TICK(gettick(), ed->ud.canact_tick) < 0 )
		return 0;

	ed->target_id = bl->id;	// Set new target
	ed->last_thinktime = gettick();

	if( skill_get_inf(skill_id) & INF_GROUND_SKILL )
		unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv);
	else
		unit_skilluse_id(&ed->bl,bl->id,skill_id,skill_lv);

	ed->target_id = 0;	// Reset target after casting the skill  to avoid continious attack.

	return 1;
}
开发者ID:newmessage,项目名称:rathena,代码行数:42,代码来源:elemental.c

示例4: hplugins_addconf

/**
 * Adds a configuration listener for a plugin.
 *
 * @param pluginID The plugin identifier.
 * @param type     The configuration type to listen for.
 * @param name     The configuration entry name.
 * @param func     The callback function.
 * @retval true if the listener was added successfully.
 * @retval false in case of error.
 */
bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key))
{
	struct HPConfListenStorage *conf;
	int i;

	if (parse_func == NULL) {
		ShowError("HPM->addConf:%s: missing setter function for config '%s'\n",HPM->pid2name(pluginID),name);
		return false;
	}

	if (type == HPCT_BATTLE && return_func == NULL) {
		ShowError("HPM->addConf:%s: missing getter function for config '%s'\n",HPM->pid2name(pluginID),name);
		return false;
	}

	if (type >= HPCT_MAX) {
		ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name);
		return false;
	}

	ARR_FIND(0, VECTOR_LENGTH(HPM->config_listeners[type]), i, strcmpi(name, VECTOR_INDEX(HPM->config_listeners[type], i).key) == 0);
	if (i != VECTOR_LENGTH(HPM->config_listeners[type])) {
		ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",
				HPM->pid2name(pluginID), name, HPM->pid2name(VECTOR_INDEX(HPM->config_listeners[type], i).pluginID));
		return false;
	}

	VECTOR_ENSURE(HPM->config_listeners[type], 1, 1);
	VECTOR_PUSHZEROED(HPM->config_listeners[type]);
	conf = &VECTOR_LAST(HPM->config_listeners[type]);

	conf->pluginID = pluginID;
	safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH);
	conf->parse_func = parse_func;
	conf->return_func = return_func;

	return true;
}
开发者ID:DeepBugs,项目名称:Hercules,代码行数:48,代码来源:HPM.c

示例5: channel_clean

/**
 * Make player leave the channel and cleanup association
 * - If no one remains in the chat, delete it
 * @param channel: Channel data
 * @param sd: Player data
 * @param flag: Called from deletion process, do not recall delete
 * @return
 *  0: Success
 * -1: Invalid player or channel
 */
int channel_clean(struct Channel *channel, struct map_session_data *sd, int flag) {
	unsigned char i;

	if(!channel || !sd)
		return -1;

	if( channel == sd->gcbind )
		sd->gcbind = NULL;

	ARR_FIND(0, sd->channel_count, i, sd->channels[i] == channel);
	if( i < sd->channel_count ) {
		unsigned char cursor = i;
		sd->channels[i] = NULL;
		sd->channel_tick[i] = 0;
		for(; i < sd->channel_count; i++ ) { //slice move list down
			if( sd->channels[i] == NULL )
				continue;
			if(i != cursor) {
				sd->channels[cursor] = sd->channels[i];
				sd->channel_tick[cursor] = sd->channel_tick[i];
			}
			cursor++;
		}
		if ( !(sd->channel_count = cursor) ) { //if in no more chan delete db
			aFree(sd->channels);
			aFree(sd->channel_tick);
			sd->channels = NULL;
			sd->channel_tick = NULL;
		}
	}

	idb_remove(channel->users,sd->status.char_id); //remove user for channel user list
	//auto delete when no more user in
	if( !db_size(channel->users) && !(flag&1) )
		channel_delete(channel,false);

	return 0;
}
开发者ID:Atemo,项目名称:rathena,代码行数:48,代码来源:channel.cpp

示例6: quest_update_status

int quest_update_status(TBL_PC * sd, int quest_id, quest_state status)
{
	int i;

	//Only status of active and inactive quests can be updated. Completed quests can't (for now). [Inkfish]
	ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id);
	if(i == sd->avail_quests)
	{
		ShowError("quest_update_status: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
		return -1;
	}

	sd->quest_log[i].state = status;
	sd->save_quest = true;

	if( status < Q_COMPLETE )
	{
		clif_quest_update_status(sd, quest_id, (bool)status);
		return 0;
	}

	achievement_validate_quest(sd,quest_id);

	if( i != (--sd->avail_quests) )
	{
		struct quest tmp_quest;
		memcpy(&tmp_quest, &sd->quest_log[i],sizeof(struct quest));
		memcpy(&sd->quest_log[i], &sd->quest_log[sd->avail_quests],sizeof(struct quest));
		memcpy(&sd->quest_log[sd->avail_quests], &tmp_quest,sizeof(struct quest));
	}

	clif_quest_delete(sd, quest_id);

	if( save_settings&64 )
		chrif_save(sd,0);

	return 0;
}
开发者ID:philg666,项目名称:Latest_eAmod,代码行数:38,代码来源:quest.c

示例7: party_removemember2

int party_removemember2(struct map_session_data *sd,uint32 char_id,int party_id)
{
	if( sd ) {
		if( !sd->status.party_id )
			return -3;

		party_trade_bound_cancel(sd);
		intif_party_leave(sd->status.party_id,sd->status.account_id,sd->status.char_id);
		return 1;
	} else {
		int i;
		struct party_data *p;

		if( !(p = party_search(party_id)) )
			return -2;

		ARR_FIND(0,MAX_PARTY,i,p->party.member[i].char_id == char_id );
		if( i >= MAX_PARTY )
			return -1;
		intif_party_leave(party_id,p->party.member[i].account_id,char_id);
		return 1;
	}
}
开发者ID:julius5,项目名称:rathena,代码行数:23,代码来源:party.c

示例8: chat_kickchat

/*==========================================
 * Kick an user from a chatroom
 * Return:
 *  0: User cannot be kicked (is gm)/Missing data
 *  1: Success
 *------------------------------------------*/
bool chat_kickchat(struct map_session_data* sd, const char* kickusername) {
    struct chat_data* cd;
    int i;

    nullpo_ret(sd);

    cd = (struct chat_data *)map->id2bl(sd->chatID);

    if( cd==NULL || (struct block_list *)sd != cd->owner )
        return false;

    ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
    if( i == cd->users ) // User not found
        return false;

    if (pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
        return false; //gm kick protection [Valaris]

    idb_iput(cd->kick_list,cd->usersd[i]->status.char_id,1);

    chat->leave(cd->usersd[i], true);
    return true;
}
开发者ID:kwang1go,项目名称:Hercules,代码行数:29,代码来源:chat.c

示例9: mapif_parse_PartyAddMember

// Add a player to party request
int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member)
{
	struct party_data *p;
	int i;

	nullpo_ret(member);
	p = inter_party->fromsql(party_id);
	if( p == NULL || p->size == MAX_PARTY ) {
		mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
		return 0;
	}

	ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == 0 );
	if( i == MAX_PARTY )
	{// Party full
		mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
		return 0;
	}

	memcpy(&p->party.member[i], member, sizeof(struct party_member));
	p->party.member[i].leader = 0;
	if (p->party.member[i].online) p->party.count++;
	p->size++;
	if (p->size == 2 || p->size == 3) // Check family state. And also accept either of their Parents. [RoM]
		inter_party->calc_state(p);
	else //Check even share range.
	if (member->lv < p->min_lv || member->lv > p->max_lv || p->family) {
		if (p->family) p->family = 0; //Family state broken.
		inter_party->check_lv(p);
	}

	mapif->party_info(-1, &p->party, 0);
	mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 0);
	inter_party->tosql(&p->party, PS_ADDMEMBER, i);

	return 0;
}
开发者ID:Mateuus,项目名称:Cronus,代码行数:38,代码来源:int_party.c

示例10: quest_update_status

/**
 * Updates a quest's state.
 * Only status of active and inactive quests can be updated. Completed quests can't (for now).
 * @param sd : Character's data
 * @param quest_id : Quest ID to update
 * @param qs : New quest state
 * @return 0 in case of success, nonzero otherwise
 * @author [Inkfish]
 */
int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status)
{
	int i;

	ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id);
	if( i == sd->avail_quests ) {
		ShowError("quest_update_status: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
		return -1;
	}

	sd->quest_log[i].state = status;
	sd->save_quest = true;

	if( status < Q_COMPLETE ) {
		clif_quest_update_status(sd, quest_id, status == Q_ACTIVE ? true : false);
		return 0;
	}

	achievement_validate_quest(sd,quest_id);	
	
	// The quest is complete, so it needs to be moved to the completed quests block at the end of the array.
	if( i < (--sd->avail_quests) ) {
		struct quest tmp_quest;

		memcpy(&tmp_quest, &sd->quest_log[i], sizeof(struct quest));
		memcpy(&sd->quest_log[i], &sd->quest_log[sd->avail_quests], sizeof(struct quest));
		memcpy(&sd->quest_log[sd->avail_quests], &tmp_quest, sizeof(struct quest));
	}

	clif_quest_delete(sd, quest_id);

	if( save_settings&64 )
		chrif_save(sd,0);

	return 0;
}
开发者ID:LKJeronimo,项目名称:eamod,代码行数:45,代码来源:quest.c

示例11: mapif_parse_GuildAddMember

// ギルドメンバ追加要求
int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m)
{
	struct guild *g;
	int i;

	g = (struct guild*)idb_get(guild_db, guild_id);
	if (g == NULL) {
		mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);
		return 0;
	}

	ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 );
	if( i < g->max_member )
	{
		memcpy(&g->member[i], m, sizeof(struct guild_member));
		mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 0);
		guild_calcinfo(g);
		mapif_guild_info(-1, g);
	}
	else
		mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);

	return 0;
}
开发者ID:KimKyung-wook,项目名称:ilathena-project,代码行数:25,代码来源:int_guild.c

示例12: chat_kickchat

/*==========================================
 * kick an user from a chatroom
 *------------------------------------------*/
int chat_kickchat(struct map_session_data *sd, const char *kickusername)
{
	struct chat_data *cd;
	int i;

	nullpo_retr(1, sd);

	cd = (struct chat_data *)map_id2bl(sd->chatID);

	if(cd==NULL || (struct block_list *)sd != cd->owner)
		return -1;

	ARR_FIND(0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0);
	if(i == cd->users)
		return -1;

	if(pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
		return 0; //gm kick protection [Valaris]

	idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void *)1);

	chat_leavechat(cd->usersd[i],1);
	return 0;
}
开发者ID:philg666,项目名称:Latest_eAmod,代码行数:27,代码来源:chat.c

示例13: read_homunculus_skilldb_sub

/**
* Read homunculus skill db
*/
static bool read_homunculus_skilldb_sub(char* split[], int columns, int current)
{// <hom class>,<skill id>,<max level>[,<job level>],<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>,<intimacy lv req>
	int skill_id, class_idx;
	int i, j;
	int minJobLevelPresent = 0;

	if (columns == 14)
		minJobLevelPresent = 1;	// MinJobLvl has been added

	// check for bounds [celest]
	if ((class_idx = hom_class2index(atoi(split[0]))) == -1) {
		ShowWarning("read_homunculus_skilldb: Invalud homunculus class %d.\n", atoi(split[0]));
		return false;
	}

	skill_id = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex]
	// Search an empty line or a line with the same skill_id (stored in j)
	ARR_FIND( 0, MAX_SKILL_TREE, j, !hskill_tree[class_idx][j].id || hskill_tree[class_idx][j].id == skill_id );
	if (j == MAX_SKILL_TREE) {
		ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", skill_id, atoi(split[0]));
		return false;
	}

	hskill_tree[class_idx][j].id = skill_id;
	hskill_tree[class_idx][j].max = atoi(split[2]);
	if (minJobLevelPresent)
		hskill_tree[class_idx][j].joblv = atoi(split[3]);

	for (i = 0; i < MAX_HOM_SKILL_REQUIRE; i++) {
		hskill_tree[class_idx][j].need[i].id = atoi(split[3+i*2+minJobLevelPresent]);
		hskill_tree[class_idx][j].need[i].lv = atoi(split[3+i*2+minJobLevelPresent+1]);
	}

	hskill_tree[class_idx][j].intimacylv = atoi(split[13+minJobLevelPresent]);
	return true;
}
开发者ID:Lucciola541,项目名称:rathena,代码行数:39,代码来源:homunculus.c

示例14: bg_team_join

/// Player joins team
bool bg_team_join(int bg_id, struct map_session_data *sd) {
	int i;
	struct battleground_data *bgd = bg->team_search(bg_id);

	if( bgd == NULL || sd == NULL || sd->bg_id ) return false;

	ARR_FIND(0, MAX_BG_MEMBERS, i, bgd->members[i].sd == NULL);
	if( i == MAX_BG_MEMBERS ) return false; // No free slots

	sd->bg_id = bg_id;
	bgd->members[i].sd = sd;
	bgd->members[i].x = sd->bl.x;
	bgd->members[i].y = sd->bl.y;
	/* populate 'where i came from' */
	if(map->list[sd->bl.m].flag.nosave || map->list[sd->bl.m].instance_id >= 0) {
		struct map_data *m=&map->list[sd->bl.m];
		if(m->save.map)
			memcpy(&bgd->members[i].source,&m->save,sizeof(struct point));
		else
			memcpy(&bgd->members[i].source,&sd->status.save_point,sizeof(struct point));
	} else
		memcpy(&bgd->members[i].source,&sd->status.last_point,sizeof(struct point));
	bgd->count++;

	guild->send_dot_remove(sd);

	for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
		struct map_session_data *pl_sd = bgd->members[i].sd;
		if (pl_sd != NULL && pl_sd != sd)
			clif->hpmeter_single(sd->fd, pl_sd->bl.id, pl_sd->battle_status.hp, pl_sd->battle_status.max_hp);
	}

	clif->bg_hp(sd);
	clif->bg_xy(sd);
	return true;
}
开发者ID:IeYasuru,项目名称:CrystalCore,代码行数:37,代码来源:battleground.c

示例15: cashshop_parse_dbrow

/*
 * Reads one line from database and assigns it to RAM.
 * return
 *  0 = failure
 *  1 = success
 */
static int cashshop_parse_dbrow( char** str, const char* source, int line ){
	unsigned short nameid = atoi( str[1] );

	if( itemdb_exists( nameid ) ){
		uint16 tab = atoi( str[0] );
		uint32 price = atoi( str[2] );
		struct cash_item_data* cid;
		int j;

		if( tab > CASHSHOP_TAB_SEARCH ){
			ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line %d of \"%s\", skipping...\n", tab, line, source );
			return 0;
		}else if( price < 1 ){
			ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line %d of \"%s\", skipping...\n", price, line, source );
			return 0;
		}

		ARR_FIND( 0, cash_shop_items[tab].count, j, nameid == cash_shop_items[tab].item[j]->nameid );

		if( j == cash_shop_items[tab].count ){
			RECREATE( cash_shop_items[tab].item, struct cash_item_data *, ++cash_shop_items[tab].count );
			CREATE( cash_shop_items[tab].item[ cash_shop_items[tab].count - 1], struct cash_item_data, 1 );
			cid = cash_shop_items[tab].item[ cash_shop_items[tab].count - 1];
		}else{
开发者ID:MyKafra,项目名称:rAthena,代码行数:30,代码来源:cashshop.c


注:本文中的ARR_FIND函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。