int main(int argc, char **argv) { if(argc != 5) { std::cout << "USEGE : [genset seed/int size/int scale/int output-filename/string]" <<std::endl; return 0; } std::cout << "RND_MIN : " << 0 << " / RND_MAX : " << RAND_MAX; int seed = atoi(argv[1]); srand(seed); int size = atoi(argv[2]); int scale = atoi(argv[3]); std::vector<int> x(size), y(size); for(int i=0; i<size; ++i) { int a = 0; int b = 0; do { a = nrand(scale); } while(is_member(x, a)); do { b = nrand(scale); } while(is_member(y, b)); x[i] = a; y[i] = b; } std::ofstream fout(argv[4]); if(fout.is_open()) { for(int i=0; i<size; ++i) { fout << x[i] << " " << y[i] << std::endl; } } return 0; }
/* Starts a subprocess with the arguments in the null-terminated argv[] array. * argv[0] is used as the name of the process. Searches the PATH environment * variable to find the program to execute. * * All file descriptors are closed before executing the subprocess, except for * fds 0, 1, and 2 and the 'n_keep_fds' fds listed in 'keep_fds'. Also, any of * the 'n_null_fds' fds listed in 'null_fds' are replaced by /dev/null. * * Returns 0 if successful, otherwise a positive errno value indicating the * error. If successful, '*pp' is assigned a new struct process that may be * used to query the process's status. On failure, '*pp' is set to NULL. */ int process_start(char **argv, const int keep_fds[], size_t n_keep_fds, const int null_fds[], size_t n_null_fds, struct process **pp) { sigset_t oldsigs; pid_t pid; int error; *pp = NULL; COVERAGE_INC(process_start); error = process_prestart(argv); if (error) { return error; } block_sigchld(&oldsigs); pid = fork(); if (pid < 0) { unblock_sigchld(&oldsigs); VLOG_WARN("fork failed: %s", strerror(errno)); return errno; } else if (pid) { /* Running in parent process. */ *pp = process_register(argv[0], pid); unblock_sigchld(&oldsigs); return 0; } else { /* Running in child process. */ int fd_max = get_max_fds(); int fd; fatal_signal_fork(); unblock_sigchld(&oldsigs); for (fd = 0; fd < fd_max; fd++) { if (is_member(fd, null_fds, n_null_fds)) { /* We can't use get_null_fd() here because we might have * already closed its fd. */ int nullfd = open("/dev/null", O_RDWR); dup2(nullfd, fd); close(nullfd); } else if (fd >= 3 && !is_member(fd, keep_fds, n_keep_fds)) { close(fd); } } execvp(argv[0], argv); fprintf(stderr, "execvp(\"%s\") failed: %s\n", argv[0], strerror(errno)); _exit(1); } }
int udp_server::recv_msg(std::string &_out_msg) { struct sockaddr_in cli; char buf[_SIZE_]; memset(buf, '\0',sizeof(buf)); socklen_t len = sizeof(struct sockaddr_in); bzero(&cli, len); int ret = recvfrom(this->fd, buf, sizeof(buf), 0, (struct sockaddr*)&cli, &len); if(ret < 0) { debug_printf("recv msg error"); return 1; }else{ std::string _tmp; _tmp = buf; std::string ip = inet_ntoa(cli.sin_addr); if(! is_member(ip)) { add_member(ip, &cli); } udp_data judge_quit; judge_quit.deserialize(_tmp); if(judge_quit.type=="command" && judge_quit.cmd=="quit") { del_member(ip); } _out_msg = buf; } return 0; }
/* -------------------------------------------------------------------------- */ void compute_plane( Complex *c_max, Complex *c_min, Complex *c_factor) { unsigned int x, y; Complex c_cur; /* used as the current z value */ static char plane[HEIGHT][WIDTH]; /* array to hold the generated image */ /* classic nested for loop approach */ for(y = 0; y < HEIGHT; y++) { c_cur.im = convert_y_coord( c_max->im, c_factor->im, y); for(x = 0; x < WIDTH; x++) { c_cur.re = convert_x_coord( c_min->re, c_factor->re, x); if( is_outside_rad2( &c_cur)){ plane[y][x] = MAX_ITERATIONS / 2; /* make the outer grey */ } else{ /* compute c_cur checking if it is in the set */ plane[y][x] = is_member( c_cur); } } } /* write it out to a PPM file */ write_to_ppm( plane); }
void MotifSearch::genes(int* genes) const { int count = 0; for (int g = 0; g < ngenes; g++) { if (is_member(g)) { genes[count] = g; count++; } } assert(count == size()); }
bool room::add_player(network::connection player) { if (is_member(player)) { ERR_ROOM << "ERROR: Player is already in this room. (socket: " << player << ")\n"; return false; } members_.push_back(player); return true; }
int find_char_mana (CHAR_DATA * ch, int bit, int sn) { SINGLE_OBJECT *gem; int mana = 0; SPELL_DATA *spell = NULL; int level = 0; if (IS_MOB(ch) || LEVEL(ch) >= 100) return 500; spell = skill_lookup (NULL, sn); level = (is_member(ch, GUILD_WIZARD) ? 1 : 0)+ (is_member(ch, GUILD_HEALER) ? 1 : 0)+ (is_member(ch, GUILD_MYSTIC) ? 1 : 0)+ (is_member(ch, GUILD_CONJURER) ? 1: 0); if (IS_AUGMENTED(ch, AUG_CHANNEL)) { level *=2; level +=2; } level += ((get_curr_int (ch) + get_curr_wis (ch)) / 2) +(ch->pcdata->remort_times+1); if (ch->pcdata->n_mana < 0) ch->pcdata->n_mana = 0; mana = ch->pcdata->n_mana; if ((gem = ch->hold1) != NULL && gem->pIndexData->item_type == ITEM_GEM && IS_SET(((I_GEM *) gem->more)->gem_type, bit)) { mana += ((I_GEM *)gem->more)->mana_now; level += ((I_GEM *)gem->more)->max_level; } else if ((gem = ch->hold2) != NULL && gem->pIndexData->item_type == ITEM_GEM && IS_SET(((I_GEM *) gem->more)->gem_type, bit)) { mana += ((I_GEM *)gem->more)->mana_now; level += ((I_GEM *)gem->more)->max_level; } if (spell->spell_level > level) { send_to_char("You cannot cast this spell without the proper type of gem!\n\r", ch); return 0; } return mana; }
void con_room_forward_decline(cnr room, jpacket jp, xmlnode decline) { cnu user; jid user_jid; if (room == NULL || decline == NULL || jp == NULL) { log_warn(NAME, "[%s] Aborting - NULL attribute found", FZONE); xmlnode_free(jp->x); return; } user_jid=jid_new(decline->p,xmlnode_get_attrib(decline,"to")); if ((room->invitation == 1 && !is_member(room, jp->from) && !is_owner(room, jp->from)) || user_jid == NULL) { log_warn(NAME, "[%s] Aborting - User is not allowed to send a decline", FZONE); jutil_error(jp->x, TERROR_MUC_OUTSIDE); deliver(dpacket_new(jp->x), NULL); return; } if (user_jid->resource == NULL) { log_warn(NAME, "[%s] Aborting - cannot send back decline, bare jid found", FZONE); return; } if (room->visible == 1) { user = g_hash_table_lookup(room->remote, jid_full(jid_fix(user_jid))); } else { user = g_hash_table_lookup(room->local, user_jid->resource); } if (user == NULL){ log_warn(NAME, "[%s] Aborting - Decline recipient is not in the room", FZONE); jutil_error(jp->x, TERROR_MUC_OUTSIDE); deliver(dpacket_new(jp->x), NULL); return; } log_debug(NAME, "[%s] Sending invitation decline", FZONE); xmlnode_put_attrib(decline, "from", jid_full(jp->from)); xmlnode_hide_attrib(decline, "to"); xmlnode_put_attrib(jp->x, "to", jid_full(user->realid)); xmlnode_put_attrib(jp->x, "from", jid_full(room->id)); log_debug(NAME, "[%s] >>>%s<<<", FZONE, xmlnode2str(jp->x)); deliver(dpacket_new(jp->x), NULL); return; }
/* Possible points : 15 * * Param playlist : An empty array of song structs * Param inputFile : An array of strings, each one representing one input file * Param numInputFiles : The number of files in the inputFile array * * return The length of the input file or -1 if the function fails * * This method should read the songs from each file into the playlist array. * If there are more than PLAYLIST_LEN number of songs then only the the first * PLAYLIST_LEN number of songs should be read in. This method will call the * is_member function on each song. The playlist cannot hold duplicates and if * it discovers two songs with the same title then it should error out and * return -1. * * IMPORTANT : Input files do not have their length at the top * ex) * * Beatles AbbeyRoad Because 10 * Beatles Anthology1 Shout 12 * . . . */ int build_playlist(Song playlist[], char* inputFiles[], int numInputFiles) { int i=0; int num=0; FILE *ptr_file; char tempArtist[STRING_LEN]; char tempTitle[STRING_LEN]; char tempAlbum[STRING_LEN]; int tempRating; for(i=0;i<numInputFiles;i++){ ptr_file =fopen(inputFiles[i],"r"); while(num<PLAYLIST_LEN){ fscanf(ptr_file, "%s %s %s %d",tempArtist,tempTitle,tempAlbum,&tempRating); if(feof(ptr_file)){ break; } //printf("%s %s %s %d",tempArtist,tempTitle,tempAlbum,tempRating); if(is_member(playlist, num, tempTitle)==1){ fclose(ptr_file); return -1; } strcpy(playlist[num].artist,tempArtist); strcpy(playlist[num].title,tempTitle); strcpy(playlist[num].album,tempAlbum); playlist[num].rating=tempRating; num++; if(feof(ptr_file)){ break; } } fclose(ptr_file); } return num; }
int lookup_group_ids(uid_t uid, gid_t *gid, t_groups *groups) { struct passwd *pwd; struct group *grp; int size, result; gid_t *id; if ((gid == NULL) || (groups == NULL)) { return -1; } else if ((pwd = getpwuid(uid)) == NULL) { return -1; } if ((*gid = pwd->pw_gid) == 0) { result = 0; } else { result = 1; } groups->number = size = 0; groups->array = NULL; while ((grp = getgrent()) != NULL) { if (is_member(pwd->pw_name, grp->gr_mem)) { if (grp->gr_gid == 0) { result = 0; } if (groups->number == size) { size += 10; if ((id = realloc(groups->array, size * sizeof(gid_t))) == NULL) { free(groups->array); endgrent(); return -1; } groups->array = id; } *(groups->array + groups->number) = grp->gr_gid; groups->number++; } } endgrent(); return result; }
void do_guild (CHAR_DATA * ch, char *argy) { int i; CHAR_DATA *mob; char buf[STD_LENGTH]; char arg1[SML_LENGTH]; DEFINE_COMMAND ("guild", do_guild, POSITION_STANDING, 0, LOG_NORMAL, "This command allows you to perform guild options at a guild house.") if (IS_MOB (ch)) return; argy = one_argy(argy, arg1); if (!str_cmp (arg1, "info") || !str_cmp(arg1, "cost") || !str_cmp(arg1, "costs")) { show_guild_costs(ch, ""); return; } for (mob = ch->in_room->more->people; mob != NULL; mob = mob->next_in_room) { if (IS_MOB (mob) && ( IS_SET (mob->pIndexData->act3, ACT3_TINKER) || IS_SET (mob->pIndexData->act3, ACT3_WARRIOR) || IS_SET (mob->pIndexData->act3, ACT3_HEALER) || IS_SET (mob->pIndexData->act3, ACT3_WIZARD) || IS_SET (mob->pIndexData->act3, ACT3_THIEFG) || IS_SET (mob->pIndexData->act3, ACT3_RANGER) || IS_SET (mob->pIndexData->act3, ACT3_ROGUE) || IS_SET (mob->pIndexData->act3, ACT3_MYSTIC) || IS_SET (mob->pIndexData->act3, ACT3_CONJURER) || IS_SET (mob->pIndexData->act3, ACT3_BATTLEMASTER) || IS_SET (mob->pIndexData->act3, ACT3_NECROMANCER) || IS_SET (mob->pIndexData->act3, ACT3_MONK) ) ) break; } if (mob == NULL) { send_to_char ("There is no guildmaster present here!\n\r", ch); return; } if (arg1[0] == '\0') { send_to_char ("\n\rOptions:\n\r---> Guild leave\n\r---> Guild info\n\r---> Guild join\n\r---> Guild status\n\r", ch); return; } /*end of GUILD INFO */ if (!str_cmp (arg1, "status")) { if (!IS_SET (ch->pcdata->guilds, (mob->pIndexData->act3))) { send_to_char ("You are not a member of our guild!\n\r", ch); return; } send_to_char ("You are an highly respected member of the guild.\n\r", ch); return; } /*end of GUILD STATUS */ if (!str_cmp (arg1, "leave")) { if (!is_member (ch, (mob->pIndexData->act3))) { send_to_char ("You aren't even a member!!\n\r", ch); return; } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(mob->pIndexData->act3, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]--; REMOVE_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); send_to_char("You are no longer a member of the guild.", ch); player_preset(ch, "Zlughlkheyn"); do_remove(ch, "all"); break; } } } /*end of GUILD LEAVE */ if (!str_cmp(arg1, "replace")) { char arg2[STD_LENGTH]; char arg3[STD_LENGTH]; int oldnum = -1; int newnum = -1; argy = one_argy(argy, arg2); argy = one_argy(argy, arg3); if (arg2[0] == '\0' || arg3[0] == '\0') { send_to_char("Syntax: Guild Replace <old_guild> <new_guild>\n\r", ch); return; } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (!str_cmp(guild_data[i].what_you_type, arg2)) { oldnum = guild_data[i].mob_guildmaster_bit; break; } } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (!str_cmp(guild_data[i].what_you_type, arg3)) { newnum = guild_data[i].mob_guildmaster_bit; break; } } if (oldnum == -1 || newnum == -1) { send_to_char("You need to check those names again. I don't know which guilds you are talking about.\n\r", ch); return; } if (!IS_SET(ch->pcdata->guilds, oldnum)) { send_to_char("You don't have that guild so how do you expect to replace it?\n\r", ch); return; } if (newnum == oldnum) { send_to_char("You are not changing anything!! Get a clue.\n\r", ch); return; } if (!IS_SET(mob->pIndexData->act3, newnum)) { send_to_char("This guildmaster cannot add you. You must find the proper guildmaster for the guild you wish to join.\n\r", ch); return; } if (is_member(ch, newnum)) { send_to_char("You are already a member of that guild!\n\r", ch); return; } if (ch->pcdata->bank < 60000) { send_to_char("You need 60000 coins in the bank for this to be done.\n\r", ch); return; } if(ch->pcdata->warpoints < 100) { send_to_char("You need 100 warpoints for this to be done.\n\r", ch); return; } ch->pcdata->bank -= 60000; ch->pcdata->warpoints -= 100; for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(oldnum, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]--; REMOVE_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); break; } } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(newnum, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]++; SET_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); break; } } sprintf(buf, "Congratulations! You are now a member of the %s!\n\r", guild_data[i].what_you_see); send_to_char(buf, ch); sprintf (buf, "Welcome to our guild, %s!", NAME (ch)); do_say (mob, buf); player_preset(ch, "Zlughlkheyn"); fix_char(ch); send_to_char("Ok, the guilds have been switched.\n\r", ch); return; } if (!str_cmp (arg1, "join")) { int num = get_num_guilds(ch); int remorts = pow.guild_info[num][0]; int lvl = pow.guild_info[num][1]; int cst = (pow.guild_info[num][2] * 100); int wps = pow.guild_info[num][3]; int kps = pow.guild_info[num][4]; bool can_join = TRUE; if (IS_SET (ch->pcdata->guilds, mob->pIndexData->act3 )) { send_to_char ("You are already a member of our guild!\n\r", ch); return; } if (ch->pcdata->remort_times < remorts) { sprintf (buf, "You need to have at least %d remorts to join this guild!\n\r", remorts); send_to_char (buf, ch); can_join = FALSE; } // Commented out because i replaced it with the code below. /* if (LEVEL (ch) < lvl) { sprintf (buf, "You need to be level %d to join the guild!\n\r", lvl); send_to_char (buf, ch); can_join = FALSE; }*/ //Added so if the player has a remort that they can join even if they don't meet the level req. //Sabelis 1-18-2006 if ((LEVEL (ch) >lvl) || (ch->pcdata->remort_times>0)) { can_join = TRUE; } else if (LEVEL (ch) < lvl) { sprintf (buf, "You need to be level %d to join the guild!\n\r", lvl); send_to_char (buf, ch); can_join = FALSE; } if (tally_coins (ch) < cst) { sprintf (buf, "We need a payment of %d coins before we can let you join.\n\r", cst); send_to_char (buf, ch); can_join = FALSE; } if (ch->pcdata->warpoints < wps) { sprintf (buf, "You need to have at least %d warpoints to join this guild!\n\r", wps); send_to_char (buf, ch); can_join = FALSE; } if (ch->pcdata->killpoints < kps) { sprintf (buf, "You need to have at least %d killpoints to join this guild!\n\r", kps); send_to_char (buf, ch); can_join = FALSE; } if (!can_join) return; ch->pcdata->warpoints -= wps; ch->pcdata->killpoints -= kps; sub_coins (cst, ch); for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(mob->pIndexData->act3, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]++; SET_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); break; } } sprintf(buf, "Congratulations! You are now a member of the %s!\n\r", guild_data[i].what_you_see); send_to_char(buf, ch); sprintf (buf, "Welcome to our guild, %s!", NAME (ch)); do_say (mob, buf); } return; }
static int is_cman_member(int nodeid) { return is_member(cman_nodes, cman_node_count, nodeid); }
int is_cluster_member(int nodeid) { return is_member(cman_nodes, cman_node_count, nodeid); }
static int is_old_member(int nodeid) { return is_member(old_nodes, old_node_count, nodeid); }
void run_test(enum test_type t_type, uint8_t use_hashes) { uint64_t i; uint64_t is_member_count; uint64_t rnd_nbr; char *type; uint64_t set_bits; struct timeval tval_before, tval_after, tval_result; /* insertion */ create_filter(filter_size, use_hashes); gettimeofday(&tval_before, NULL); switch (t_type) { case EVEN_UNEVEN: type = "un/even"; for (i = 1; i < insert_size << 1; i += 2) { insert_key((char *)&i, 8); } break; case RANDOM: type = "random"; for (i = 0; i < insert_size; i++) { rnd_nbr = arc4random(); rnd_nbr = rnd_nbr << 32; rnd_nbr = rnd_nbr | arc4random(); insert_key((char *)&rnd_nbr, 8); } break; case COUNTING: type = "counting"; for (i = 0; i < insert_size; i++) { insert_key((char *)&i, 8); } break; default: /* not reached */ type = ""; break; } gettimeofday(&tval_after, NULL); timersub(&tval_after, &tval_before, &tval_result); /* testing */ is_member_count = 0; switch (t_type) { case EVEN_UNEVEN: for (i = 0; i < insert_size << 1; i += 2) { if (is_member((char *)&i, 8)) { is_member_count++; } } break; case RANDOM: for (i = 0; i < insert_size; i++) { rnd_nbr = arc4random(); rnd_nbr = rnd_nbr << 32; rnd_nbr = rnd_nbr | arc4random(); if (is_member((char *)&rnd_nbr, 8)) { is_member_count++; } } break; case COUNTING: for (i = insert_size; i < insert_size << 1; i++) { if (is_member((char *)&i, 8)) { is_member_count++; } } break; default: /* not reached */ break; } set_bits = estimate_cardinality(); /* print info */ printf("%-8s: ins time: %2ld.%-6ld false pos: %6.2f%% (%10lu) fill factor: %6.2f%% (%10lu) err rate: %6.2f%% (%10lu)\n", type, (long int)tval_result.tv_sec, (long int)tval_result.tv_usec, (double)is_member_count / (double)insert_size * 100.0, is_member_count, (double)set_bits / (double)filter_size * 100.0, set_bits, (double)(insert_size * K - set_bits) / (double)(insert_size * K) * 100.0, insert_size * K - set_bits); }
void do_skill (CHAR_DATA * ch, char *argy) { char buf[STD_LENGTH]; char hg[300]; SPELL_DATA *spell; int sn; int col; int oldtrack; int oldtrap; int oldpick; DEFINE_COMMAND ("skills", do_skill, POSITION_DEAD, 0, LOG_NORMAL, "This command shows you what skills you know, if any.") if (IS_MOB (ch)) return; hugebuf_o[0] = '\0'; send_to_char ("\x1B[1;37mYou have knowledge in the following skills:\x1B[37;0m\n\r", ch); send_to_char ("\x1B[1;34m-------------------------------------------\x1B[37;0m\n\r", ch); col = 0; oldtrack = ch->pcdata->learned[gsn_track]; oldtrap = ch->pcdata->learned[gsn_trapset]; oldpick = ch->pcdata->learned[gsn_pick_lock]; if (is_member (ch, GUILD_THIEFG)) ch->pcdata->learned[gsn_pick_lock] = 100; if (is_member (ch, GUILD_RANGER) && is_member(ch, GUILD_THIEFG) && is_member(ch, GUILD_TINKER)) ch->pcdata->learned[gsn_trapset] = 100; if (is_member (ch, GUILD_RANGER)) ch->pcdata->learned[gsn_track] = 100; ch->pcdata->learned[gsn_sneak] += ch->pcdata->plus_sneak; ch->pcdata->learned[gsn_hide] += ch->pcdata->plus_hide; for (sn = 0; sn < SKILL_COUNT; sn++) { spell = skill_lookup (NULL, sn); if (spell == NULL) continue; if ((LEVEL (ch) < spell->spell_level) || (ch->pcdata->learned[sn] == -100) || spell->slot == 1) continue; strcpy (hg, how_good (ch, sn)); if (LEVEL (ch) >= 100) sprintf (buf, "%s%22s %3d%%\x1b[0;37m ",(spell->slot == 2 ? "\x1b[1;36m" : ""), spell->spell_funky_name, ch->pcdata->learned[sn]); else sprintf (buf, "%s%22s %10s",(spell->slot == 2 ? "\x1b[1;36m" : "\x1b[0;37m"), spell->spell_funky_name, hg); strcat (hugebuf_o, buf); if (++col % 2 == 0) strcat (hugebuf_o, "\n\r"); } ch->pcdata->learned[gsn_track] = oldtrack; ch->pcdata->learned[gsn_trapset] = oldtrap; ch->pcdata->learned[gsn_pick_lock] = oldpick; ch->pcdata->learned[gsn_sneak] -= ch->pcdata->plus_sneak; ch->pcdata->learned[gsn_hide] -= ch->pcdata->plus_hide; if (col % 2 != 0) strcat (hugebuf_o, "\n\r"); sprintf (buf, "\n\rYou have %d practice sessions left.\n\r", ch->pcdata->practice); strcat (hugebuf_o, buf); page_to_char (hugebuf_o, ch); return; }
boolean check_subsets(Itemset *I, TreeNode *X){ boolean result = is_member(I->itemset, X); return result; }
GList *dt_noiseprofile_get_matching(const dt_image_t *cimg) { JsonParser *parser = darktable.noiseprofile_parser; JsonReader *reader = NULL; GList *result = NULL; if(!parser) goto end; dt_print(DT_DEBUG_CONTROL, "[noiseprofile] looking for maker `%s', model `%s'\n", cimg->camera_maker, cimg->camera_model); JsonNode *root = json_parser_get_root(parser); reader = json_reader_new(root); json_reader_read_member(reader, "noiseprofiles"); // go through all makers const int n_makers = json_reader_count_elements(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d makers\n", n_makers); for(int i = 0; i < n_makers; i++) { json_reader_read_element(reader, i); json_reader_read_member(reader, "maker"); if(g_strstr_len(cimg->camera_maker, -1, json_reader_get_string_value(reader))) { dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found `%s' as `%s'\n", cimg->camera_maker, json_reader_get_string_value(reader)); // go through all models and check those json_reader_end_member(reader); json_reader_read_member(reader, "models"); const int n_models = json_reader_count_elements(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d models\n", n_models); for(int j = 0; j < n_models; j++) { json_reader_read_element(reader, j); json_reader_read_member(reader, "model"); if(!g_strcmp0(cimg->camera_model, json_reader_get_string_value(reader))) { dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %s\n", cimg->camera_model); // we got a match, return at most bufsize elements json_reader_end_member(reader); json_reader_read_member(reader, "profiles"); const int n_profiles = json_reader_count_elements(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d profiles\n", n_profiles); for(int k = 0; k < n_profiles; k++) { dt_noiseprofile_t tmp_profile = { 0 }; json_reader_read_element(reader, k); gchar** member_names = json_reader_list_members(reader); // do we want to skip this entry? if(is_member(member_names, "skip")) { json_reader_read_member(reader, "skip"); gboolean skip = json_reader_get_boolean_value(reader); json_reader_end_member(reader); if(skip) { json_reader_end_element(reader); g_strfreev(member_names); continue; } } // maker tmp_profile.maker = g_strdup(cimg->camera_maker); // model tmp_profile.model = g_strdup(cimg->camera_model); // name json_reader_read_member(reader, "name"); tmp_profile.name = g_strdup(json_reader_get_string_value(reader)); json_reader_end_member(reader); // iso json_reader_read_member(reader, "iso"); tmp_profile.iso = json_reader_get_double_value(reader); json_reader_end_member(reader); // a json_reader_read_member(reader, "a"); for(int a = 0; a < 3; a++) { json_reader_read_element(reader, a); tmp_profile.a[a] = json_reader_get_double_value(reader); json_reader_end_element(reader); } json_reader_end_member(reader); // b json_reader_read_member(reader, "b"); for(int b = 0; b < 3; b++) { json_reader_read_element(reader, b); tmp_profile.b[b] = json_reader_get_double_value(reader); json_reader_end_element(reader); } json_reader_end_member(reader); json_reader_end_element(reader); // everything worked out, add tmp_profile to result dt_noiseprofile_t *new_profile = (dt_noiseprofile_t *)malloc(sizeof(dt_noiseprofile_t)); *new_profile = tmp_profile; result = g_list_append(result, new_profile); g_strfreev(member_names); } // profiles goto end; } json_reader_end_member(reader); json_reader_end_element(reader); } // models } json_reader_end_member(reader); json_reader_end_element(reader); } // makers json_reader_end_member(reader); end: if(reader) g_object_unref(reader); if(result) result = g_list_sort(result, _sort_by_iso); return result; }
void do_statistical_tests() { #ifndef TRACK_STATISTICS printf("Enable TRACK_STATISTICS to do statistical tests...\n"); return ; #else /* some sizes test to see how the bitfield or rather hashing function behaves depending on its size. */ unsigned int sizes_to_test[] = {10000, /* 10 thousands bits, about 1.25 kilobytes. */ 100000, /* 12.5 kilobytes. */ 1000000, /* 125 kilobytes */ 10000000 /* 1.25 megabytes. */}, number_of_sizes = 4, index_0, index_1, number_of_strings = 10000; /* create two set of strings both of which are completely disjoint (if the empty string is excluded), in principles their shouldn't be any collisions. */ char **inserted_strings = get_combinations(number_of_strings, "abcdefghi"), **non_inserted_strings = get_combinations(number_of_strings, "jklmnopqr"); printf("Testing with combinations.\n"); membership_type *membership; for (index_0 = 0; index_0 < number_of_sizes; index_0++) { membership = create_membership(sizes_to_test[index_0]); /* create a new membership. */ for (index_1 = 1; index_1 <= number_of_strings; index_1++) /* skip over the empty string */ insert_string(membership, inserted_strings[index_1]); for (index_1 = 1; index_1 <= number_of_strings; index_1++) /* skip over the empty string */ if (!is_member(membership, inserted_strings[index_1], 1)) error("Failed to insert value!"); for (index_1 = 1; index_1 <= number_of_strings; index_1++) is_member(membership, non_inserted_strings[index_1], 0); printf("Bitfield size %u number_of_strings %u\n", sizes_to_test[index_0], number_of_strings); printf("%u, %f%% collisions while inserting.\n", (unsigned int)(number_of_strings - membership->number_of_set_bits), (((unsigned int)(number_of_strings - membership->number_of_set_bits)/(double)(number_of_strings)) * 100)); printf("%u, %f%% collisions while searching.\n", (unsigned int)(membership->number_of_false_positives), (((unsigned int)(membership->number_of_false_positives)/(double)(number_of_strings)) * 100) ); printf("\n"); free_membership(membership); } for (index_0 = 0; index_0 < number_of_strings + 1; index_0++) { free(inserted_strings[index_0]); free(non_inserted_strings[index_0]); } printf("Testing with permutations.\n"); inserted_strings = permute_string("abcdefghi", number_of_strings); non_inserted_strings = permute_string("jklmnopqr", number_of_strings); for (index_0 = 0; index_0 < number_of_sizes; index_0++) { membership = create_membership(sizes_to_test[index_0]); /* create a new membership. */ for (index_1 = 0; index_1 < number_of_strings; index_1++) insert_string(membership, inserted_strings[index_1]); for (index_1 = 0; index_1 < number_of_strings; index_1++) if (!is_member(membership, inserted_strings[index_1], 1)) error("Failed to insert value!"); for (index_1 = 0; index_1 < number_of_strings; index_1++) is_member(membership, non_inserted_strings[index_1], 0); printf("Bitfield size %u number_of_strings %u\n", sizes_to_test[index_0], number_of_strings); printf("%u, %f%% collisions while inserting.\n", (unsigned int)(number_of_strings - membership->number_of_set_bits), (((unsigned int)(number_of_strings - membership->number_of_set_bits)/(double)(number_of_strings)) * 100)); printf("%u, %f%% collisions while searching.\n", (unsigned int)(membership->number_of_false_positives), (((unsigned int)(membership->number_of_false_positives)/(double)(number_of_strings)) * 100) ); printf("\n"); free_membership(membership); } for (index_0 = 0; index_0 < number_of_strings; index_0++) { free(inserted_strings[index_0]); free(non_inserted_strings[index_0]); } #endif }
struct object * get_object(struct linked_list *container, char *purpose, int type, int (*bff_p)(struct object *obj, bag_arg *junk)) /* char *container; what container has what we want */ /* char *purpose; a message (verb) to print if we cant find any */ /* char type; type (o_type) to pick out (NULL = any) */ /* int (*bff_p) (); bag filter function to test item */ { struct object *obj_p = NULL; char sel_id; /* selected type and id */ int sel_type; char response; if (container == NULL) { msg("There isn't anything in there."); after = FALSE; return(NULL); } /* Make sure we have at least one item that qualifies! */ if (apply_to_bag(container, type, bff_p, NULL, NULL) == NULL) { msg("You seem to have nothing to %s.", purpose); after = FALSE; return(NULL); } while (obj_p == NULL) { if (type == 0) { msg("What kind of item <%s> do you want to %s (* for list)?", type_list, purpose); response = readchar(); ESCAPE_EXIT(response); msg(""); if (response == '*') { add_line("! Potion"); add_line("? Scroll"); add_line("= Ring"); add_line("/ Stick"); add_line("] Armor"); add_line(") Weapon"); add_line(": Food"); end_line(); continue; } if (!is_member(type_list, response)) { beep(); continue; } if (count_bag(container, response, NULL) == 0) { msg("You don't have any %s.", name_type(response)); continue; } type = response; } while(obj_p == NULL) { msg("What item do you want to %s (* for list)?", purpose); response = readchar(); msg(""); ESCAPE_EXIT(response); if (response == '*') { mpos = 0; apply_to_bag(container, type, bff_p, baf_print_item, &type); end_line(); continue; } sel_type = type; sel_id = response; obj_p = scan_bag(container, sel_type,unprint_id(&sel_id)); } } mpos = 0; msg(""); return(obj_p); }
void dam_message (CHAR_DATA * ch, CHAR_DATA * victim, int dam, int dt, int p) { char buf[256], buf1[256], buf2[256], buf3[256]; char *tt; int ty; char hit_you_far[2000]; char other_hit_far[2000]; char subbuf[256], *bufptr; char attack[256]; char bare[256]; char punct; SINGLE_OBJECT *obj = NULL; you_hit[0] = '\0'; bare[0] = '\0'; attack[0] = '\0'; other_hit[0] = '\0'; hit_you[0] = '\0'; hit_you_far[0] = '\0'; other_hit_far[0] = '\0'; nocolor = FALSE; if (FIGHTING (ch) != NULL && FIGHTING (ch)->position == POSITION_GROUNDFIGHTING && dam < 3) dam += 3; if(IS_MOB(ch) && ch->pIndexData->mobtype == MOB_DUMMY) return; general_hit (dam, ch, victim); punct = (dam <= 20) ? '.' : '!'; if (IS_MOB (ch)) { if (!ch->pIndexData->attackname || !str_cmp ("(null)", ch->pIndexData->attackname) || !str_cmp ("N/A", ch->pIndexData->attackname) || ch->pIndexData->attackname == NULL || ch->pIndexData->attackname[0] == ' ') { if (!str_cmp (mob_type_attack (ch->pIndexData->mobtype), "punch") && FIGHTING (ch) != NULL && FIGHTING (ch)->position == POSITION_GROUNDFIGHTING) strcpy (bare, "stomp"); else strcpy (bare, mob_type_attack (ch->pIndexData->mobtype)); } else { if (!str_cmp (ch->pIndexData->attackname, "punch") && FIGHTING (ch) != NULL && FIGHTING (ch)->position == POSITION_GROUNDFIGHTING) strcpy (bare, "stomp"); else strcpy (bare, ch->pIndexData->attackname); } } else { if (FIGHTING (ch) != NULL && FIGHTING (ch)->position == POSITION_GROUNDFIGHTING) strcpy (bare, "stomp"); else strcpy (bare, "punch"); if (is_member(ch, GUILD_MONK)) { int randhit = number_range(1,12); if (randhit == 1) strcpy (bare, "punch"); else if (randhit == 2) strcpy (bare, "kick"); else if (randhit == 3) strcpy (bare, "leg sweep"); else if (randhit == 4) strcpy (bare, "elbow"); else if (randhit == 5) strcpy (bare, "flipkick"); else if (randhit == 6) strcpy (bare, "headbutt"); else if (randhit == 7) strcpy (bare, "shinkick"); else if (randhit == 8) strcpy (bare, "palm strike"); else if (randhit == 9) strcpy (bare, "knee"); else if (randhit == 10) strcpy (bare, "backfist"); else if (randhit == 11) strcpy (bare, "uppercut"); else if (randhit == 12) strcpy (bare, "quick jab"); } } if (dt == gsn_circle) { if ((obj = get_item_held (ch, ITEM_WEAPON)) == NULL) return; if (dam > 0) { sprintf (buf1, "\x1B[1;37m$n\x1B[0;37m sneaks up on $N... $n thrusts $p\x1B[0;37m into $S back!"); if (dam < 20) sprintf (buf2, "You circle and thrust $p\x1B[0m into \x1B[1m$N\x1B[0m's back."); if ((dam > 19) && (dam < 50)) sprintf (buf2, "You circle and thrust $p\x1B[0m into \x1B[1m$N\x1B[0m's back, causing cries of agony and pain."); if ((dam > 49) && (dam < 100)) sprintf (buf2, "You circle your opponent.... $p\x1B[0m finds its mark in \x1B[1m$N\x1B[0m's back, causing $S body to spasm in pain."); if ((dam > 99) && (dam < 200)) sprintf (buf2, "You circle your opponent.... $p\x1B[0m sinks deeply into \x1B[1m$N\x1B[0m's back, and blood runs over your hands."); if ((dam > 199) && (dam < 275)) sprintf (buf2, "You circle your opponent.... $p\x1B[0m has struck a pressure point in \x1B[1m$N\x1B[0m's back!\n\rThat's gotta hurt!"); if ((dam > 274) && (dam < 350)) sprintf (buf2, "You circle around and twist $p\x1B[0m around several times in \x1B[1m$N\x1B[0m's back! That's gotta hurt!"); if (dam > 349) sprintf(buf2, "Your $p\x1B[0m penetrates the base of \x1B[1m$N\x1B[0m's neck spraying spinal fluid onto your armor!"); sprintf (buf3, "\x1B[1m$n\x1B[0m is behind you before you know it, and slips $p\x1B[0m into your back.\n\r"); } } else if (dt == gsn_backstab) { if ((obj = get_item_held (ch, ITEM_WEAPON)) == NULL) return; if (dam > 0) { if (dam <100) sprintf (buf1, "\x1B[1;37m$n\x1B[0;37m thrusts $p\x1B[0;37m into \x1B[1;37m$N\x1B[0m's back.\n\r"); if ((dam > 99) && (dam < 200)) sprintf (buf1, "Blood runs over \x1B[1;37m$n\x1B[0;37m hands as $p\x1B[0;37m\n\ris thrust into \x1B[1;37m$N\x1B[0m's back.\n\r"); if ((dam > 199) && (dam < 275)) sprintf (buf1, "\x1B[1;37m$n\x1B[0;37m hits a pressure point as $p\x1B[0;37m\n\ris thrust into \x1B[1;37m$N\x1B[0m's back.\n\r"); if ((dam > 274) && (dam < 350)) sprintf (buf1, "\x1B[1;37m$n\x1B[0;37m twists $p\x1B[0;37m around several times\n\rin \x1B[1;37m$N\x1B[0m's back.\n\r"); if ((dam > 349) && (dam < 425)) sprintf (buf1, "Spinal fluid sprays as \x1B[1;37m$n\x1B[0;37m thrusts $p\x1B[0;37m\n\rinto \x1B[1;37m$N\x1B[0m's back. That had to HURT!\n\r"); if (dam > 424) sprintf (buf1, "\x1B[1;37m$n\x1B[0;37m uses $p\x1B[0;37m to punch a hole \n\rclean through \x1B[1;37m$N\x1B[0m's neck! Guts spray everywhere!\n\rThat REALLY had to HURT!"); if (dam < 20) sprintf (buf2, "You thrust $p\x1B[0m into \x1B[1m$N\x1B[0m's back."); if ((dam > 19) && (dam < 50)) sprintf (buf2, "You thrust $p\x1B[0m into \x1B[1m$N\x1B[0m's back, causing cries of agony and pain."); if ((dam > 49) && (dam < 100)) sprintf (buf2, "$p\x1B[0m finds its mark in \x1B[1m$N\x1B[0m's back, causing $s body to spasm."); if ((dam > 99) && (dam < 200)) sprintf (buf2, "$p\x1B[0m sinks deeply into \x1B[1m$N\x1B[0m's back, and blood runs over your hands."); if ((dam > 199) && (dam < 275)) sprintf (buf2, "$p\x1B[0m has struck a pressure point in \x1B[1m$N\x1B[0m's back! \n\rThat's gotta hurt!"); if ((dam > 274) && (dam < 350)) sprintf (buf2, "You twist $p\x1B[0m around several times in \x1B[1m$N\x1B[0m's back!\n\rThat's gotta hurt!"); if ((dam > 349) && (dam < 425)) sprintf(buf2, "Your $p\x1B[0m penetrates the base of \x1B[1m$N\x1B[0m's neck spraying spinal fluid onto your armor!\n\rThat REALLY had to HURT!"); if (dam > 424) sprintf(buf2, "Your $p\x1B[0m punches a hole clean through \x1B[1m$N\x1B[0m's neck spraying guts all over you!\n\rThat REALLY had to HURT SEVERELY!"); /* Added Damage Display for backstabee j. ellis (cyric) 2-6-01 */ if (dam <100) sprintf (buf3, "Before you know what's going on, \x1B[1m$n\x1B[0m\n\ris behind you, and thrusts $p\x1B[0m into your back.\n\r"); if ((dam > 99) && (dam < 200)) sprintf (buf3, "Blood runs all over \x1B[1m$n\x1B[0m's hands as $p\x1B[0m\n\ris thrust into your back.\n\r"); if ((dam >199) && (dam < 275)) sprintf (buf3, "\x1B[1m$n\x1B[0m strikes a pressure point as $p\x1B[0m\n\ris thrust into your back.\n\r"); if ((dam >274) && (dam < 350)) sprintf (buf3, "\x1B[1m$n\x1B[0m twists $p\x1B[0m around several times\n\rin your back! That HURT!"); if ((dam >349) && (dam < 425)) sprintf (buf3, "\x1B[1m$n\x1B[0m penetrates the base of your neck with $p\x1B[0m\n\rYour spinal fluid sprays everywhere!\n\rThat REALLY HURT!"); if (dam >424) sprintf (buf3, "\x1B[1m$n\x1B[0m punches a hole clean through your neck with \n\r$p\x1B[0m, That REALLY HURT!"); /* sprintf (buf3, "Before you know what's going on, \x1B[1m$n\x1B[0m\n\ris behind you, and thrusts $p\x1B[0m\n\r into your back.\n\r");*/ } else { sprintf (buf1, "\x1B[1m$n\x1B[0m fails to lunge $p\x1B[0m in \x1B[1m$N\x1B[0m's back."); sprintf (buf2, "You fail to place $p\x1B[0m into \x1B[1m$N\x1B[0m's back."); sprintf (buf3, "\x1B[1m$n\x1B[0m's \x1B[1;30mbackstab\x1B[0m just barely misses you."); } } else if (dt == gsn_fireshield) { if(dam > 0) { if( dam > 0 && dam <= 20 ) { sprintf (buf1, "\x1B[1m$n\x1B[0m's shield of fire scorches \x1B[1m$N\x1B[0m!"); sprintf (buf2, "Your shield of fire \x1B[1mburns\x1B[0m $N!"); sprintf (buf3, "\x1B[1m$n\x1B[0m's \x1B[1;30mfire shield\x1B[0m chars you!"); } else if( dam > 20 && dam <= 40) { sprintf (buf1, "\x1B[1m$n\x1B[0m's shield of fire engulfs \x1B[1m$N\x1B[0m!"); sprintf (buf2, "Your shield of fire \x1B[1minflames\x1B[0m $N!"); sprintf (buf3, "Ouch!! \x1B[1m$n\x1B[0m's \x1B[1;30mfire shield\x1B[0m engulfs you!"); } else if( dam > 40 && dam < 100) { sprintf (buf1, "\x1B[1m$n\x1B[0m's shield of fire roasts \x1B[1m$N\x1B[0m!"); sprintf (buf2, "Your shield of fire \x1B[1mROASTS\x1B[0m $N!"); sprintf (buf3, "Oof!! \x1B[1m$n\x1B[0m's \x1B[1;30mfire shield\x1B[0m ROASTS you!"); } else if( dam >= 100) { sprintf (buf1, "\x1B[1m$n\x1B[0m's shield of fire OBLITERATES \x1B[1m$N\x1B[0m!!"); sprintf (buf2, "Your shield of fire \x1B[1mOBLITERATES\x1B[0m $N!"); sprintf (buf3, "AARRGGHH!!! \x1B[1m$n\x1B[0m's \x1B[1;30mfire shield\x1B[0m OBLITERATES you!"); } else { sprintf (buf1, "\x1B[1m$n\x1B[0m's shield of fire OBLITERATES \x1B[1m$N\x1B[0m!! [%d]",dam); sprintf (buf2, "Your shield of fire \x1B[1mOBLITERATES\x1B[0m $N! [%d]",dam); sprintf (buf3, "AARRGGHH!!! \x1B[1m$n\x1B[0m's \x1B[1;30mfire shield\x1B[0m OBLITERATES you! [%d]",dam); } } else { sprintf (buf1, "\x1B[1m$n\x1B[0m's fire shield fails to affect $p\x1B[0m in \x1B[1m$N\x1B[0m."); sprintf (buf2, "\x1B[1m$N\x1B[0m's attack goes right through your fire shield!."); sprintf (buf3, "\x1B[1m$n\x1B[0m's fire shield fails to protect him from your attack."); } } else if (dt == TYPE_HIT || dt < 0) { if (nocolor) { sprintf (buf, "%s", other_hit); sprintf (buf1, buf, bare); sprintf (buf, "%s", you_hit); sprintf (buf2, buf, bare); sprintf (buf, "%s", hit_you); sprintf (buf3, buf, bare); if (RIDING (ch) != NULL) { send_to_char ("ACK! You are having problems punching while riding!\n\r", ch); } } else { sprintf (buf, "\x1B[1;37m%s\x1B[0m", other_hit); sprintf (buf1, buf, bare); sprintf (buf, "\x1B[1;35m%s\x1B[0m", you_hit); sprintf (buf2, buf, bare); sprintf (buf, "\x1B[1;36m%s\x1B[0m", hit_you); sprintf (buf3, buf, bare); } } else { if (dt >= 0 && dt < SKILL_COUNT) { SPELL_DATA *spell; if ((spell = skill_lookup (NULL, dt)) == NULL) return; strcpy (attack, spell->noun_damage); } else if ((dt - TYPE_HIT) < MAX_ATTACK) { strcpy (attack, attack_table[dt - TYPE_HIT].name); } else { bug ("Dam_message: bad dt %d.", dt); dt = TYPE_HIT; strcpy (attack, attack_table[0].name); } if (nocolor) { sprintf (buf, "%s", other_hit); sprintf (buf1, buf, attack); sprintf (buf, "%s", you_hit); sprintf (buf2, buf, attack); sprintf (buf, "%s", hit_you); sprintf (buf3, buf, attack); } else { sprintf (buf, "\x1B[1;37m%s\x1B[0m", other_hit); sprintf (buf1, buf, attack); sprintf (buf, "\x1B[1;35m%s\x1B[0m", you_hit); sprintf (buf2, buf, attack); sprintf (buf, "\x1B[1;36m%s\x1B[0m", hit_you); sprintf (buf3, buf, attack); } } if ((bufptr = strstr (buf1, "hs "))) { sprintf (subbuf, bufptr + 2); *(bufptr + 1) = 'e'; *(bufptr + 2) = 's'; *(bufptr + 3) = '\0'; strcat (buf1, subbuf); } if ((bufptr = strstr (buf2, "hs "))) { sprintf (subbuf, bufptr + 2); *(bufptr + 1) = 'e'; *(bufptr + 2) = 's'; *(bufptr + 3) = '\0'; strcat (buf2, subbuf); } if ((bufptr = strstr (buf3, "hs "))) { sprintf (subbuf, bufptr + 2); *(bufptr + 1) = 'e'; *(bufptr + 2) = 's'; *(bufptr + 3) = '\0'; strcat (buf3, subbuf); } if (dam <= 1) { act(buf1, ch, obj, victim, TO_NOTVICT_SPAM + 1000); act(buf2, ch, obj, victim, TO_CHAR_SPAM + 1000); act(buf3, ch, obj, victim, TO_VICT_SPAM + 1000); } else { act(buf1, ch, obj, victim, TO_NOTVICT + 1000); act(buf2, ch, obj, victim, TO_CHAR + 1000); act(buf3, ch, obj, victim, TO_VICT + 1000); if (victim->in_room != ch->in_room) { ty = 0; for (tt = buf1; *tt != '\0'; tt++) { if (*tt == '$') { ty++; tt++; switch(*tt) { case 'N': buf1[ty] = 'n'; break; case 'n': buf1[ty] = 'N'; break; case 'S': buf1[ty] = 's'; break; case 's': buf1[ty] = 'S'; break; } } ty++; } ty = 0; for (tt = buf3; *tt != '\0'; tt++) { if (*tt == '$') { ty++; tt++; switch(*tt) { case 'N': buf3[ty] = 'n'; break; case 'n': buf3[ty] = 'N'; break; case 'S': buf3[ty] = 's'; break; case 's': buf3[ty] = 'S'; break; } } ty++; } act(buf1, victim, obj, ch, TO_NOTVICT + 1000); act(buf3, victim, obj, ch, TO_CHAR + 1000); } } if (dt == gsn_backstab && dam > 0) check_social (victim, "wince", ""); return; }
void do_practice (CHAR_DATA * ch, char *argy) { char buf[STD_LENGTH]; char hg[500]; bool found; int sn; int cnttt; SPELL_DATA *spell; CHAR_DATA *mob; int adept; DEFINE_COMMAND ("practice", do_practice, POSITION_STANDING, 0, LOG_NORMAL, "This command can be used to list all skills/spells you know, or, at a practitioner, can be used to practice a spell or skill.") hugebuf_o[0] = '\0'; cnttt = 0; if (IS_MOB (ch)) return; for (mob = ch->in_room->more->people; mob != NULL; mob = mob->next_in_room) { if (IS_MOB (mob) && IS_SET (mob->act, ACT_PRACTICE) && mob->pIndexData->opt) break; } if (mob != NULL && (!IS_SET (mob->act, ACT_PRACTICE) || IS_PLAYER (mob))) { if (argy[0] != '\0') { send_to_char ("You cannot practice here!\n\r", ch); return; } } if (mob == NULL && argy[0] == '\0') { int col; int oldtrack; int oldtrap; int oldpick; sprintf (hugebuf_o, "You have knowledge in the following:\n\r\n\r"); sprintf (hugebuf_o,"\x1B[1;37mYou have knowledge in the following:\x1B[37;0m\n\r"); sprintf (hugebuf_o+strlen(hugebuf_o),"\x1B[1;34m------------------------------------\x1B[37;0m\n\r"); col = 0; oldtrack = ch->pcdata->learned[gsn_track]; if (is_member (ch, GUILD_RANGER)) ch->pcdata->learned[gsn_track] = 100; oldtrap = ch->pcdata->learned[gsn_trapset]; if (is_member (ch, GUILD_RANGER) && is_member(ch, GUILD_THIEFG) && is_member(ch, GUILD_TINKER)) ch->pcdata->learned[gsn_trapset] = 100; oldpick = ch->pcdata->learned[gsn_pick_lock]; if (is_member (ch, GUILD_THIEFG)) ch->pcdata->learned[gsn_pick_lock] = 100; ch->pcdata->learned[gsn_sneak] += ch->pcdata->plus_sneak; ch->pcdata->learned[gsn_hide] += ch->pcdata->plus_hide; for (sn = 0; sn < SKILL_COUNT; sn++) { if ((spell = skill_lookup (NULL, sn)) == NULL) continue; if ((LEVEL (ch) < spell->spell_level) || (ch->pcdata->learned[sn] < -1)) continue; strcpy (hg, how_good (ch, sn)); if (LEVEL (ch) >= 100) sprintf (buf, "%22s %3d%% ", spell->spell_funky_name, ch->pcdata->learned[sn]); else sprintf (buf, " %22s %10s", spell->spell_funky_name, hg); strcat (hugebuf_o, buf); if (++col % 2 == 0) strcat (hugebuf_o, "\n\r"); } ch->pcdata->learned[gsn_track] = oldtrack; ch->pcdata->learned[gsn_trapset] = oldtrap; ch->pcdata->learned[gsn_pick_lock] = oldpick; ch->pcdata->learned[gsn_sneak] -= ch->pcdata->plus_sneak; ch->pcdata->learned[gsn_hide] -= ch->pcdata->plus_hide; if (col % 2 != 0) strcat (hugebuf_o, "\n\r"); sprintf (buf, "\n\rYou have %d practices and %d learns left.\x1B[0m\n\r", ch->pcdata->practice, ch->pcdata->learn); strcat (hugebuf_o, buf); page_to_char (hugebuf_o, ch); return; } if (!IS_AWAKE (ch)) { send_to_char ("In your dreams? Good luck!\n\r", ch); return; } if (argy[0] == '\0') { int col; int oldtrack; int oldtrap; int oldpick; hugebuf_o[0] = '\0'; send_to_char("\x1B[1;37mYou have knowledge in the following:\x1B[37;0m\n\r", ch); send_to_char("\x1B[1;34m------------------------------------\x1B[37;0m\n\r", ch); found = FALSE; col = 0; if (mob == NULL || IS_PLAYER (mob)) return; oldpick = ch->pcdata->learned[gsn_pick_lock]; if (is_member (ch, GUILD_THIEFG)) ch->pcdata->learned[gsn_pick_lock] = 100; oldtrack = ch->pcdata->learned[gsn_track]; if (is_member (ch, GUILD_RANGER) && is_member(ch, GUILD_THIEFG) && is_member(ch, GUILD_TINKER)) ch->pcdata->learned[gsn_trapset] = 100; oldtrap = ch->pcdata->learned[gsn_trapset]; if (is_member (ch, GUILD_RANGER)) ch->pcdata->learned[gsn_track] = 100; ch->pcdata->learned[gsn_sneak] += ch->pcdata->plus_sneak; ch->pcdata->learned[gsn_hide] += ch->pcdata->plus_hide; for (sn = 0; sn <= 28; sn++) { if (mob->pIndexData->opt->skltaught[sn] > 0 && (spell = skill_lookup (NULL, mob->pIndexData->opt->skltaught[sn])) != NULL) { if (LEVEL (ch) >= spell->spell_level) { char hg[300]; found = TRUE; strcpy (hg, how_good (ch, spell->gsn)); sprintf (buf, " %22s %10s", spell->spell_funky_name, hg); strcat (hugebuf_o, buf); if (++col % 2 == 0) strcat (hugebuf_o, "\n\r"); } } } ch->pcdata->learned[gsn_trapset] = oldtrap; ch->pcdata->learned[gsn_track] = oldtrack; ch->pcdata->learned[gsn_pick_lock] = oldpick; ch->pcdata->learned[gsn_sneak] -= ch->pcdata->plus_sneak; ch->pcdata->learned[gsn_hide] -= ch->pcdata->plus_hide; if (!found) strcat (hugebuf_o, "Nothing.\n\r"); if (col % 2 != 0) strcat (hugebuf_o, "\n\r"); sprintf (buf, "\n\rYou have %d practice sessions left.\n\r", ch->pcdata->practice); strcat (hugebuf_o, buf); page_to_char (hugebuf_o, ch); return; } spell = skill_lookup (argy, -1); if (spell == NULL) { send_to_char ("What's that?\n\r", ch); return; } if (spell == NULL || (IS_PLAYER (ch) && (LEVEL (ch) < spell->spell_level || ch->pcdata->learned[spell->gsn] == -100))) { if (spell->gsn > 0 && spell->gsn < SKILL_COUNT && ch->pcdata->learned[spell->gsn] == -100) { do_learn (ch, argy); if (ch->pcdata->learned[spell->gsn] == -100) { send_to_char ("For some reason or another, you could not LEARN this spell/skill.\n\r", ch); send_to_char ("Perhaps you are out of learns? Type 'learn' for more information.\n\r", ch); return; } goto lerned_it; } send_to_char ("I have no knowledge in that area.\n\r", ch); return; } lerned_it: if (mob == NULL) return; while (cnttt <= 30) { if (IS_MOB (mob) && mob->pIndexData->opt->skltaught[cnttt] == spell->gsn) { cnttt = 50; break; } cnttt++; } if (cnttt != 50) { send_to_char ("I have too little knowledge in that area to help you practice.\n\r", ch); return; } if (ch->pcdata->practice < 1) { send_to_char ("You have no practice sessions left!\n\r", ch); return; } if (spell->slot != 0) adept = pow.max_prac_spells; else adept = pow.max_prac_skills; if (spell->slot == 0) { if(get_curr_dex (ch) < spell->min_wis) { adept -= (spell->min_wis - get_curr_dex (ch)) * 8; } if(get_curr_str (ch) < spell->min_int) { adept -= (spell->min_int - get_curr_str (ch)) * 8; if (adept < 20) adept = 20; } } else if (spell->slot == 1) { if (get_curr_wis (ch) < spell->min_wis) { adept -= (spell->min_wis - get_curr_wis (ch)) * 8; } if (get_curr_int (ch) < spell->min_int) { adept -= (spell->min_int - get_curr_int (ch)) * 8; if (adept < 20) adept = 20; } } else if (spell->slot == 2) { if (get_curr_dex (ch) < spell->min_wis) { adept -= (spell->min_wis - get_curr_dex (ch)) * 8; } if (get_curr_int (ch) < spell->min_int) { adept -= (spell->min_int - get_curr_int (ch)) * 8; if (adept < 20) adept = 20; } } if (IS_PLAYER (ch)) { SPELL_DATA *spl; if (spell->prereq_1 != NULL && (spl = skill_lookup(spell->prereq_1, -1)) != NULL && ch->pcdata->learned[spl->gsn] < pow.prereq) { sprintf (buf, "You need to be skilled in %s first.\n\r", spl->spell_funky_name); send_to_char (buf, ch); return; } if (spell->prereq_2 != NULL && (spl = skill_lookup(spell->prereq_2, -1)) != NULL && ch->pcdata->learned[spl->gsn] < pow.prereq) { sprintf (buf, "You need to be skilled in %s first.\n\r", spl->spell_funky_name); send_to_char (buf, ch); return; } } if (ch->pcdata->learned[spell->gsn] >= adept) { sprintf (buf, "You are already quite good at %s.\n\r", spell->spell_funky_name); send_to_char (buf, ch); return; } if (spell->guilds != 0) { int i; for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if(IS_SET(spell->guilds, guild_data[i].mob_guildmaster_bit) && !IS_SET(ch->pcdata->guilds, guild_data[i].mob_guildmaster_bit)) { send_to_char("You do not have the proper guilds to practice this!\n\r", ch); return; } } } ch->pcdata->practice--; if (spell->slot == 1) ch->pcdata->learned[spell->gsn] += int_app[get_curr_int (ch) - 1].learn; if (spell->slot != 1) ch->pcdata->learned[spell->gsn] += int_app[get_curr_int (ch) - 1].learn - 1; if (ch->pcdata->learned[spell->gsn] < adept) { act ("You practice $T.", ch, NULL, spell->spell_funky_name, TO_CHAR); } else { ch->pcdata->learned[spell->gsn] = adept; act ("You now have a good understanding of $T.", ch, NULL, spell->spell_funky_name, TO_CHAR); if (spell->gsn > 549 && IS_PLAYER(ch) && !str_cmp(race_info[ch->pcdata->race].name, "orc") && adept == pow.max_prac_skills) ch->pcdata->learned[spell->gsn]+= 15; } return; }
void mana (CHAR_DATA * ch, char *argy) { char bufff[500]; int mana_water = 0; int mana_earth = 0; int mana_fire = 0; int mana_air = 0; int mana_spirit = 0; int water_lev = 0; int earth_lev = 0; int fire_lev = 0; int air_lev = 0; int spirit_lev = 0; SINGLE_OBJECT *obj = NULL; int nat_level = 0; int bonus = 0; DEFINE_COMMAND ("mana", mana, POSITION_DEAD, 0, LOG_NORMAL, "Allows you to see your mana in different element types, and max spell levels you can cast.") if (IS_MOB (ch)) return; bonus = (is_member(ch, GUILD_WIZARD) ? 1 : 0)+ (is_member(ch, GUILD_HEALER) ? 1 : 0)+ (is_member(ch, GUILD_MYSTIC) ? 1 : 0)+ (is_member(ch, GUILD_CONJURER) ? 1: 0); if (IS_AUGMENTED(ch, AUG_CHANNEL)) { bonus *=2; bonus +=2; } nat_level = (get_curr_int (ch) + get_curr_wis (ch)) / 2 + bonus + (ch->pcdata->remort_times+1)/2; /* Set up the base case. */ fire_lev = nat_level; air_lev = nat_level; earth_lev = nat_level; spirit_lev = nat_level; water_lev = nat_level; if (ch->pcdata->n_mana < 0) ch->pcdata->n_mana = 0; mana_fire = ch->pcdata->n_mana; mana_air = ch->pcdata->n_mana; mana_water = ch->pcdata->n_mana; mana_earth = ch->pcdata->n_mana; mana_spirit = ch->pcdata->n_mana; if ((obj = get_item_held (ch, ITEM_GEM)) != NULL) { I_GEM *gem = (I_GEM *) obj->more; if (IS_SET (gem->gem_type, MANA_FIRE)) { fire_lev += gem->max_level; mana_fire += gem->mana_now; } if (IS_SET (gem->gem_type, MANA_AIR)) { air_lev += gem->max_level; mana_air += gem->mana_now; } if (IS_SET (gem->gem_type, MANA_EARTH)) { earth_lev += gem->max_level; mana_earth += gem->mana_now; } if (IS_SET (gem->gem_type, MANA_WATER)) { water_lev += gem->max_level; mana_water += gem->mana_now; } if (IS_SET (gem->gem_type, MANA_SPIRIT)) { spirit_lev += gem->max_level; mana_spirit += gem->mana_now; } } sprintf (bufff, "Fire mana available is : [\x1B[1m%3d\x1B[0m] (Max spell level \x1B[1m%d\x1B[0m).\n\r", mana_fire, fire_lev); send_to_char (bufff, ch); sprintf (bufff, "Air mana available is : [\x1B[1m%3d\x1B[0m] (Max spell level \x1B[1m%d\x1B[0m).\n\r", mana_air, air_lev); send_to_char (bufff, ch); sprintf (bufff, "Water mana available is : [\x1B[1m%3d\x1B[0m] (Max spell level \x1B[1m%d\x1B[0m).\n\r", mana_water, water_lev); send_to_char (bufff, ch); sprintf (bufff, "Earth mana available is : [\x1B[1m%3d\x1B[0m] (Max spell level \x1B[1m%d\x1B[0m).\n\r", mana_earth, earth_lev); send_to_char (bufff, ch); sprintf (bufff, "Spirit mana available is : [\x1B[1m%3d\x1B[0m] (Max spell level \x1B[1m%d\x1B[0m).\n\r", mana_spirit, spirit_lev); send_to_char (bufff, ch); sprintf (bufff, "\n\rGeneral mana available is the max of the above values and spell levels.\n\r"); send_to_char (bufff, ch); return; }
int get_num_guilds(CHAR_DATA *ch) { int num = 0; if (is_member(ch, GUILD_HEALER)) num++; if (is_member(ch, GUILD_THIEFG)) num++; if (is_member(ch, GUILD_WARRIOR)) num++; if (is_member(ch, GUILD_ROGUE)) num++; if (is_member(ch, GUILD_WIZARD)) num++; if (is_member(ch, GUILD_TINKER)) num++; if (is_member(ch, GUILD_RANGER)) num++; if (is_member(ch, GUILD_CONJURER)) num++; if (is_member(ch, GUILD_MYSTIC)) num++; if (is_member(ch, GUILD_BATTLEMASTER)) num++; if (is_member(ch, GUILD_NECROMANCER)) num++; if (is_member(ch, GUILD_MONK)) num++; return num; }
static gboolean dt_noiseprofile_verify(JsonParser *parser) { JsonReader *reader = NULL; gboolean valid = TRUE; dt_print(DT_DEBUG_CONTROL, "[noiseprofile] verifying noiseprofile file\n"); JsonNode *root = json_parser_get_root(parser); if(!root) _ERROR("can't get the root node"); reader = json_reader_new(root); if(!json_reader_read_member(reader, "version")) _ERROR("can't find file version."); // check the file version const int version = json_reader_get_int_value(reader); json_reader_end_member(reader); if(version != DT_NOISE_PROFILE_VERSION) _ERROR("file version is not what this code understands"); if(!json_reader_read_member(reader, "noiseprofiles")) _ERROR("can't find `noiseprofiles' entry."); if(!json_reader_is_array(reader)) _ERROR("`noiseprofiles' is supposed to be an array"); // go through all makers const int n_makers = json_reader_count_elements(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d makers\n", n_makers); for(int i = 0; i < n_makers; i++) { if(!json_reader_read_element(reader, i)) _ERROR("can't access maker at position %d / %d", i+1, n_makers); if(!json_reader_read_member(reader, "maker")) _ERROR("missing `maker`"); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found maker `%s'\n", json_reader_get_string_value(reader)); // go through all models and check those json_reader_end_member(reader); if(!json_reader_read_member(reader, "models")) _ERROR("missing `models`"); const int n_models = json_reader_count_elements(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d models\n", n_models); for(int j = 0; j < n_models; j++) { if(!json_reader_read_element(reader, j)) _ERROR("can't access model at position %d / %d", j+1, n_models); if(!json_reader_read_member(reader, "model")) _ERROR("missing `model`"); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %s\n", json_reader_get_string_value(reader)); json_reader_end_member(reader); if(!json_reader_read_member(reader, "profiles")) _ERROR("missing `profiles`"); const int n_profiles = json_reader_count_elements(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d profiles\n", n_profiles); for(int k = 0; k < n_profiles; k++) { if(!json_reader_read_element(reader, k)) _ERROR("can't access profile at position %d / %d", k+1, n_profiles); gchar** member_names = json_reader_list_members(reader); // name if(!is_member(member_names, "name")) { g_strfreev(member_names); _ERROR("missing `name`"); } // iso if(!is_member(member_names, "iso")) { g_strfreev(member_names); _ERROR("missing `iso`"); } // a if(!is_member(member_names, "a")) { g_strfreev(member_names); _ERROR("missing `a`"); } json_reader_read_member(reader, "a"); if(json_reader_count_elements(reader) != 3) { g_strfreev(member_names); _ERROR("`a` with size != 3"); } json_reader_end_member(reader); // b if(!is_member(member_names, "b")) { g_strfreev(member_names); _ERROR("missing `b`"); } json_reader_read_member(reader, "b"); if(json_reader_count_elements(reader) != 3) { g_strfreev(member_names); _ERROR("`b` with size != 3"); } json_reader_end_member(reader); json_reader_end_element(reader); g_strfreev(member_names); } // profiles json_reader_end_member(reader); json_reader_end_element(reader); } // models json_reader_end_member(reader); json_reader_end_element(reader); } // makers json_reader_end_member(reader); dt_print(DT_DEBUG_CONTROL, "[noiseprofile] verifying noiseprofile completed\n"); end: if(reader) g_object_unref(reader); return valid; }
void cljp_coarsening(Mat depends_on, IS *pCoarse) { const int debug = 0; //create a vector of the weights. Vec w; MatGetVecs(depends_on, PETSC_NULL, &w); VecZeroEntries(w); //Get my local matrix size PetscInt start; PetscInt end; MatGetOwnershipRange(depends_on, &start, &end); //TODO: replace with something that doesn't require re-creating the matrix structure. //Initialize all the weights { Mat influences; MatTranspose(depends_on, &influences); { RawGraph influences_raw(influences); assert(influences_raw.local_nrows() == end-start); //Initialize the weight vector with \norm{S^T_i} + \sigma(i) PetscScalar *local_weights; VecGetArray(w, &local_weights); for (int local_row=0; local_row < influences_raw.local_nrows(); local_row++) { local_weights[local_row] = influences_raw.ia(local_row+1)-influences_raw.ia(local_row) + frand(); } VecRestoreArray(w, &local_weights); } MatDestroy(influences); } //VecView(w, PETSC_VIEWER_STDOUT_WORLD); //-------------------------------------------------------------- //Prepare the scatters needed for the independent set algorithm. IS all_local_nodes; describe_partition(depends_on, &all_local_nodes); NonlocalCollection nonlocal(depends_on, all_local_nodes); ISDestroy(all_local_nodes); //while we are here, get the matrix + graph nodes that we need. Mat extended_depend_mat; get_matrix_rows(depends_on, nonlocal.nodes, &extended_depend_mat); // Vec used only for display purposes enum NodeType {UNKNOWN=-1, FINE, COARSE}; Vec node_type; VecDuplicate(w, &node_type); VecSet(node_type, UNKNOWN); Vec w_nonlocal; VecDuplicate(nonlocal.vec, &w_nonlocal); Vec node_type_nonlocal; VecDuplicate(w_nonlocal, &node_type_nonlocal); VecSet(node_type_nonlocal, UNKNOWN); Vec is_not_independent; VecDuplicate(w, &is_not_independent); Vec is_not_independent_nonlocal; VecDuplicate(w_nonlocal, &is_not_independent_nonlocal); VecScatterBegin(nonlocal.scatter, w, w_nonlocal, INSERT_VALUES, SCATTER_FORWARD); VecScatterEnd(nonlocal.scatter, w, w_nonlocal, INSERT_VALUES, SCATTER_FORWARD); Vec w_update_nonlocal; VecDuplicate(w_nonlocal, &w_update_nonlocal); //get ready to find all the coarse and fine points typedef std::set<PetscInt> IntSet; IntSet unknown; //initialize the unknown set with all points that are local to this processor. for (int ii=start; ii<end; ii++) { unknown.insert(ii); } //we use MPI_INT here because we need to allreduce it with MPI_LAND int all_points_partitioned=0; int inc = 0; { RawGraph dep_nonlocal_raw(extended_depend_mat); //while not done while(!all_points_partitioned) { //Start: non-local weights, non-local coarse points if (debug) { LTRACE(); char fname[] = "weightsXXX"; char selection_graph[] = "selectionXXX"; sprintf(fname, "weights%03d", inc); sprintf(selection_graph, "selection%03d", inc); inc++; /* PetscViewer view; PetscViewerBinaryMatlabOpen(PETSC_COMM_WORLD, fname, &view); PetscViewerBinaryMatlabOutputVecDA(view, "z", w, user->da); PetscViewerBinaryMatlabDestroy(view); PetscViewerBinaryMatlabOpen(PETSC_COMM_WORLD, selection_graph, &view); PetscViewerBinaryMatlabOutputVecDA(view, "z", node_type, user->da); PetscViewerBinaryMatlabDestroy(view); //*/ } //Pre: non-local weights, non-local coarse points //find the independent set. //By using ADD_VALUES in a scattter, we can perform //a boolean OR across procesors. //is_not_independent[*] = false VecSet(is_not_independent_nonlocal, 0); //for all unknown points P { RawVector node_type_nonlocal_raw(node_type_nonlocal); RawVector w_nonlocal_raw(w_nonlocal); RawVector is_not_independent_nonlocal_raw(is_not_independent_nonlocal); FOREACH(P, unknown) { //get weight(P) PetscScalar weight_P = w_nonlocal_raw.at(nonlocal.map[*P]); //for all dependencies K of P (K st P->K) for (PetscInt ii=0; ii<dep_nonlocal_raw.nnz_in_row(nonlocal.map[*P]); ii++) { PetscInt K = dep_nonlocal_raw.col(nonlocal.map[*P], ii); //skip if K is fine/coarse /* Notice that we don't have to consider the independent set we've been generating here. By construction, if K is in the independent set, then P cannot be in the independent set. */ if (node_type_nonlocal_raw.at(nonlocal.map[K]) != UNKNOWN) { continue; } //skip if P->K is marked if (dep_nonlocal_raw.is_marked(nonlocal.map[*P], ii)) { continue; } //get weight(K) PetscScalar weight_K = w_nonlocal_raw.at(nonlocal.map[K]); if (weight_K <= weight_P) { //is_not_independent(K) = true is_not_independent_nonlocal_raw.at(nonlocal.map[K]) = 1; } else { // (weight(P) < weight_K) is_not_independent_nonlocal_raw.at(nonlocal.map[*P]) = 1; } } } } if (debug) {LTRACE();} //VecView(is_not_independent_nonlocal, PETSC_VIEWER_STDOUT_WORLD); //reconstruct is_not_independent vector with a ADD_VALUES, which //performs boolean OR VecSet(is_not_independent, 0); VecScatterBegin(nonlocal.scatter, is_not_independent_nonlocal, is_not_independent, ADD_VALUES, SCATTER_REVERSE); VecScatterEnd(nonlocal.scatter, is_not_independent_nonlocal, is_not_independent, ADD_VALUES, SCATTER_REVERSE); IntSet new_coarse_points; { RawVector is_not_independent_raw(is_not_independent); //for all unknown points P FOREACH(P, unknown) { //if (!is_not_independent(P)) if (is_not_independent_raw.at(*P) == 0) { new_coarse_points.insert(*P); if (debug) {SHOWVAR(*P, d);} } } } //Post: new coarse points (independent set) if (debug) {LTRACE();} //Pre: independent set { RawVector node_type_raw(node_type); // for each independent point FOREACH(I, new_coarse_points) { //mark that point as coarse node_type_raw.at(*I) = COARSE; unknown.erase(*I); } } //Post: updated coarse local if (debug) {LTRACE();} //Pre: updated coarse local //scatter changes to other processors VecScatterBegin(nonlocal.scatter, node_type, node_type_nonlocal, INSERT_VALUES, SCATTER_FORWARD); VecScatterEnd(nonlocal.scatter, node_type, node_type_nonlocal, INSERT_VALUES, SCATTER_FORWARD); //Post: updated coarse non-local if (debug) {LTRACE();} //Pre: updated coarse non-local, new local coarse points VecSet(w_update_nonlocal, 0); { RawVector node_type_nonlocal_raw(node_type_nonlocal); RawVector w_update_nonlocal_raw(w_update_nonlocal); //for all new coarse points C FOREACH(C, new_coarse_points) { //for all K st C->K for(PetscInt ii=0; ii<dep_nonlocal_raw.nnz_in_row(nonlocal.map[*C]); ii++) { //mark (C->K) dep_nonlocal_raw.mark(nonlocal.map[*C], ii); PetscInt K = dep_nonlocal_raw.col(nonlocal.map[*C], ii); //if K is unknown if (node_type_nonlocal_raw.at(nonlocal.map[K]) == UNKNOWN) { //measure(K)-- w_update_nonlocal_raw.at(nonlocal.map[K]) -= 1; } } } //for all unknown points I FOREACH(I, unknown) { IntSet common_coarse; //for all (J->K) for (PetscInt kk=0; kk<dep_nonlocal_raw.nnz_in_row(nonlocal.map[*I]); kk++) { if (!dep_nonlocal_raw.is_marked(nonlocal.map[*I], kk)) { //if K is coarse PetscInt K = dep_nonlocal_raw.col(nonlocal.map[*I], kk); if (node_type_nonlocal_raw.at(nonlocal.map[K]) == COARSE) { //mark K as common coarse common_coarse.insert(K); //mark (J->K) if unmarked dep_nonlocal_raw.mark(nonlocal.map[*I], kk); } } } //for all unmarked (I->J) for (PetscInt jj=0; jj<dep_nonlocal_raw.nnz_in_row(nonlocal.map[*I]); jj++) { if (!dep_nonlocal_raw.is_marked(nonlocal.map[*I], jj)) { //for all (J->K), marked or no PetscInt J = dep_nonlocal_raw.col(nonlocal.map[*I], jj); for(PetscInt kk=0; kk<dep_nonlocal_raw.nnz_in_row(nonlocal.map[J]); kk++) { //if K is in layer or ghost layer and common-coarse PetscInt K = dep_nonlocal_raw.col(nonlocal.map[J], kk); if (is_member(K, common_coarse)) { //mark (I->J) dep_nonlocal_raw.mark(nonlocal.map[*I], jj); //measure(J)-- w_update_nonlocal_raw.at(nonlocal.map[J]) -= 1; } } } } } }
int is_cluster_member(uint32_t nodeid) { return is_member(quorum_nodes, quorum_node_count, nodeid); }