/* * Describe slays and brands on weapons */ static bool describe_slays(textblock *tb, const bitflag flags[OF_SIZE], int tval) { bool printed = FALSE; const char *slay_descs[SL_MAX] = { 0 }; bitflag slay_mask[OF_SIZE], kill_mask[OF_SIZE], brand_mask[OF_SIZE]; size_t count; bool fulldesc; create_mask(slay_mask, FALSE, OFT_SLAY, OFT_MAX); create_mask(kill_mask, FALSE, OFT_KILL, OFT_MAX); create_mask(brand_mask, FALSE, OFT_BRAND, OFT_MAX); if (tval == TV_SWORD || tval == TV_HAFTED || tval == TV_POLEARM || tval == TV_DIGGING || tval == TV_BOW || tval == TV_SHOT || tval == TV_ARROW || tval == TV_BOLT || tval == TV_FLASK) fulldesc = FALSE; else fulldesc = TRUE; /* Slays */ count = list_slays(flags, slay_mask, slay_descs, NULL, NULL, TRUE); if (count) { if (fulldesc) textblock_append(tb, "It causes your melee attacks to slay "); else textblock_append(tb, "Slays "); info_out_list(tb, slay_descs, count); printed = TRUE; } /* Kills */ count = list_slays(flags, kill_mask, slay_descs, NULL, NULL, TRUE); if (count) { if (fulldesc) textblock_append(tb, "It causes your melee attacks to *slay* "); else textblock_append(tb, "*Slays* "); info_out_list(tb, slay_descs, count); printed = TRUE; } /* Brands */ count = list_slays(flags, brand_mask, NULL, slay_descs, NULL, TRUE); if (count) { if (fulldesc) textblock_append(tb, "It brands your melee attacks with "); else textblock_append(tb, "Branded with "); info_out_list(tb, slay_descs, count); printed = TRUE; } return printed; }
/** * Apply generation magic to an ego-item. */ void ego_apply_magic(struct object *obj, int level) { int i, x, resist = 0; bitflag newf[OF_SIZE]; /* Extra powers */ if (kf_has(obj->ego->kind_flags, KF_RAND_SUSTAIN)) { create_mask(newf, false, OFT_SUST, OFT_MAX); of_on(obj->flags, get_new_attr(obj->flags, newf)); } else if (kf_has(obj->ego->kind_flags, KF_RAND_POWER)) { create_mask(newf, false, OFT_PROT, OFT_MISC, OFT_MAX); of_on(obj->flags, get_new_attr(obj->flags, newf)); } else if (kf_has(obj->ego->kind_flags, KF_RAND_HI_RES)) /* Get a high resist if available, mark it as random */ if (random_high_resist(obj, &resist)) { obj->el_info[resist].res_level = 1; obj->el_info[resist].flags |= EL_INFO_RANDOM; } /* Apply extra obj->ego bonuses */ obj->to_h += randcalc(obj->ego->to_h, level, RANDOMISE); obj->to_d += randcalc(obj->ego->to_d, level, RANDOMISE); obj->to_a += randcalc(obj->ego->to_a, level, RANDOMISE); /* Apply modifiers */ for (i = 0; i < OBJ_MOD_MAX; i++) { x = randcalc(obj->ego->modifiers[i], level, RANDOMISE); obj->modifiers[i] += x; } /* Apply flags */ of_union(obj->flags, obj->ego->flags); of_diff(obj->flags, obj->ego->flags_off); /* Add slays and brands */ copy_slay(&obj->slays, obj->ego->slays); copy_brand(&obj->brands, obj->ego->brands); /* Add resists */ for (i = 0; i < ELEM_MAX; i++) { /* Take the larger of ego and base object resist levels */ obj->el_info[i].res_level = MAX(obj->ego->el_info[i].res_level, obj->el_info[i].res_level); /* Union of flags so as to know when ignoring is notable */ obj->el_info[i].flags |= obj->ego->el_info[i].flags; } /* Add effect (ego effect will trump object effect, when there are any) */ if (obj->ego->effect) { obj->effect = obj->ego->effect; obj->time = obj->ego->time; } return; }
local_map::local_map(double robot_size, int size, double scale) : m_robot_size(robot_size), m_scale(scale), m_moved(false) { m_grid.clear(); m_masked.clear(); m_mask = create_mask(0.8 * robot_size); m_laser.clear(); }
/** * Describe random powers on ego items * * \param tb is the description textblock we're building * \param ego is the ego type we're analysing */ static bool describe_ego(textblock *tb, const struct ego_item *ego) { if (ego && ego->num_randlines) { int i, of_type, tot = 0; bitflag f[OF_SIZE]; for (i = 0; i < ego->num_randlines; i++) { /* See whether we recognise the flagset for this choice */ of_type = obj_flag_type(of_next(ego->randmask[i], FLAG_START)); create_mask(f, FALSE, of_type, OFT_MAX); if (of_is_equal(f, ego->randmask[i])) { textblock_append(tb, "It provides %s random %s. ", ego->num_randflags[i] > 1 ? "more than one" : "one", obj_flagtype_name(of_type)); } else /* We don't, so count the number for later */ tot += ego->num_randflags[i]; } if (tot) textblock_append(tb, "It provides %s random power. ", tot > 1 ? "more than one" : "one"); return TRUE; } return FALSE; }
static size_t obj_desc_pval(const object_type *o_ptr, char *buf, size_t max, size_t end, bool spoil) { bitflag f[OF_SIZE], f2[OF_SIZE]; int i; bool any = FALSE; object_flags(o_ptr, f); create_mask(f2, FALSE, OFT_PVAL, OFT_STAT, OFT_MAX); if (!of_is_inter(f, f2)) return end; strnfcat(buf, max, &end, " <"); for (i = 0; i < o_ptr->num_pvals; i++) { if (spoil || object_this_pval_is_visible(o_ptr, i)) { if (any) strnfcat(buf, max, &end, ", "); strnfcat(buf, max, &end, "%+d", o_ptr->pval[i]); any = TRUE; } } strnfcat(buf, max, &end, ">"); return end; }
/** * Add player-defined inscriptions or game-defined descriptions */ static size_t obj_desc_inscrip(const struct object *obj, char *buf, size_t max, size_t end) { const char *u[4] = { 0, 0, 0, 0 }; int n = 0; int feel = object_pseudo(obj); bitflag flags_known[OF_SIZE], f2[OF_SIZE]; object_flags_known(obj, flags_known); /* Get inscription */ if (obj->note) u[n++] = quark_str(obj->note); /* Use special inscription, if any */ if (!object_is_known(obj)) { if (feel) { /* cannot tell excellent vs strange vs splendid until wield */ if (!object_was_worn(obj) && obj->ego) u[n++] = "ego"; else u[n++] = inscrip_text[feel]; } else if (tval_can_have_charges(obj) && (obj->pval == 0)) u[n++] = "empty"; else if (object_was_worn(obj)) u[n++] = (tval_is_weapon(obj)) ? "wielded" : "worn"; else if (!object_flavor_is_aware(obj) && object_flavor_was_tried(obj)) u[n++] = "tried"; } /* Note curses */ create_mask(f2, FALSE, OFT_CURSE, OFT_MAX); if (of_is_inter(flags_known, f2)) u[n++] = "cursed"; /* Note ignore */ if (ignore_item_ok(obj)) u[n++] = "ignore"; if (n) { int i; for (i = 0; i < n; i++) { if (i == 0) strnfcat(buf, max, &end, " {"); strnfcat(buf, max, &end, "%s", u[i]); if (i < n-1) strnfcat(buf, max, &end, ", "); } strnfcat(buf, max, &end, "}"); } return end; }
/** * Create a cache of slay combinations found on ego items, and the values of * these combinations. This is to speed up slay_power(), which will be called * many times for ego items during the game. * * \param items is the set of ego types from which we are extracting slay * combinations */ errr create_slay_cache(struct ego_item *items) { int i; int j; int count = 0; bitflag cacheme[OF_SIZE]; bitflag slay_mask[OF_SIZE]; bitflag **dupcheck; ego_item_type *e_ptr; /* Build the slay mask */ create_mask(slay_mask, FALSE, OFT_SLAY, OFT_KILL, OFT_BRAND, OFT_MAX); /* Calculate necessary size of slay_cache */ dupcheck = C_ZNEW(z_info->e_max, bitflag *); for (i = 0; i < z_info->e_max; i++) { dupcheck[i] = C_ZNEW(OF_SIZE, bitflag); e_ptr = items + i; /* Find the slay flags on this ego */ of_copy(cacheme, e_ptr->flags); of_inter(cacheme, slay_mask); /* Only consider non-empty combinations of slay flags */ if (!of_is_empty(cacheme)) { /* Skip previously scanned combinations */ for (j = 0; j < i; j++) if (of_is_equal(cacheme, dupcheck[j])) continue; /* msg("Found a new slay combo on an ego item"); */ count++; of_copy(dupcheck[i], cacheme); } } /* Allocate slay_cache with an extra empty element for an iteration stop */ slay_cache = C_ZNEW((count + 1), struct flag_cache); count = 0; /* Populate the slay_cache */ for (i = 0; i < z_info->e_max; i++) { if (!of_is_empty(dupcheck[i])) { of_copy(slay_cache[count].flags, dupcheck[i]); slay_cache[count].value = 0; count++; /*msg("Cached a slay combination");*/ } } for (i = 0; i < z_info->e_max; i++) FREE(dupcheck[i]); FREE(dupcheck); /* Success */ return 0; }
/** * Determine whether a flagset includes any curse flags. */ bool cursed_p(bitflag *f) { bitflag f2[OF_SIZE]; of_wipe(f2); create_mask(f2, FALSE, OFT_CURSE, OFT_MAX); return of_is_inter(f, f2); }
/** * Apply generation magic to an ego-item. */ void ego_apply_magic(object_type *o_ptr, int level) { int i, flag, x; bitflag flags[OF_SIZE], newf[OF_SIZE], f2[OF_SIZE]; object_flags(o_ptr, flags); /* Extra powers */ if (o_ptr->ego->xtra == OBJECT_XTRA_TYPE_SUSTAIN) create_mask(newf, FALSE, OFT_SUST, OFT_MAX); else if (o_ptr->ego->xtra == OBJECT_XTRA_TYPE_RESIST) create_mask(newf, FALSE, OFT_HRES, OFT_MAX); else if (o_ptr->ego->xtra == OBJECT_XTRA_TYPE_POWER) create_mask(newf, FALSE, OFT_PROT, OFT_MISC, OFT_MAX); if (o_ptr->ego->xtra) of_on(o_ptr->flags, get_new_attr(flags, newf)); /* Apply extra o_ptr->ego bonuses */ o_ptr->to_h += randcalc(o_ptr->ego->to_h, level, RANDOMISE); o_ptr->to_d += randcalc(o_ptr->ego->to_d, level, RANDOMISE); o_ptr->to_a += randcalc(o_ptr->ego->to_a, level, RANDOMISE); /* Apply pvals */ of_copy(f2, o_ptr->ego->flags); for (i = 0; i < o_ptr->ego->num_pvals; i++) { of_copy(flags, o_ptr->ego->pval_flags[i]); x = randcalc(o_ptr->ego->pval[i], level, RANDOMISE); for (flag = of_next(flags, FLAG_START); flag != FLAG_END; flag = of_next(flags, flag + 1)) /* Prevent phantom flags */ if (x) object_add_pval(o_ptr, x, flag); else of_off(f2, flag); } /* Apply remaining flags */ of_union(o_ptr->flags, f2); return; }
/** * \returns whether the object is known to be cursed */ bool object_is_known_cursed(const object_type *o_ptr) { bitflag f[OF_SIZE], f2[OF_SIZE]; object_flags_known(o_ptr, f); /* Gather whatever curse flags there are to know */ create_mask(f2, false, OFT_CURSE, OFT_MAX); return of_is_inter(f, f2); }
/** * Tweak the cursed status of an object. * * \param o_ptr is the object to curse or decurse */ static void wiz_tweak_curse(object_type *o_ptr) { if (cursed_p(o_ptr->flags)) { bitflag f[OF_SIZE]; msg("Resetting existing curses."); create_mask(f, FALSE, OFT_CURSE, OFT_MAX); of_diff(o_ptr->flags, f); } if (get_check("Set light curse? ")) flags_set(o_ptr->flags, OF_SIZE, OF_LIGHT_CURSE, FLAG_END); else if (get_check("Set heavy curse? ")) flags_set(o_ptr->flags, OF_SIZE, OF_LIGHT_CURSE, OF_HEAVY_CURSE, FLAG_END); else if (get_check("Set permanent curse? ")) flags_set(o_ptr->flags, OF_SIZE, OF_LIGHT_CURSE, OF_HEAVY_CURSE, OF_PERMA_CURSE, FLAG_END); }
void MovableIcon::show(void) { if(!shown()) Fl_X::make_xid(this); #ifdef HAVE_SHAPE if(icon->image()) { mask = create_mask(icon->image()); if(mask) { XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet); /* now set transparency; composite manager should handle the rest (if running) */ unsigned int opacity = 0xc0000000; XChangeProperty(fl_display, fl_xid(this), opacity_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&opacity, 1L); } } #endif }
typename allocator<T>::pointer allocator<T>::allocate(size_type n, void *const hint) { const size_type nb = n * sizeof(T); # if DEBUG_SMA_TRACE_INTERFACE std::cout << "alloc " << nb << " bytes (n=" << n << ", hint=" << static_cast<void *>(hint) << ")" << std::endl; # endif assert(nb > 0); if (!(nb > 0)) { std::cerr << "cannot allocate a memory block of size " << nb << std::endl; goto badalloc; } if (nb > memfree->size()) { std::cerr << "triing to allocate a memory block of size " << nb << " bytes, " << "but the managed memory has only a size of " << memfree->size() << " bytes." << std::endl; goto badalloc; } {//block auto mask = create_mask(nb, memfree->size()); const size_type pos = find_free_memory(*memfree, mask); assert(0 <= pos && pos <= memfree->size()); if (pos < memfree->size()) { # if DEBUG_SMA_TRACE_MEMALLOCATION std::cout << "reserved memory: " << mask.count() << " bytes -> " << (memfree->count() - mask.count()) << " bytes free." << std::endl; # endif *memfree = reserve_memory(*memfree, std::move(mask)); # if DEBUG_SMA_TRACE_MEMALLOCATION print_free_memory(); # endif return calc_pointer(memstart, pos); } else { # if DEBUG_SMA_TRACE_MEMALLOCATION std::cout << "not enough free memory to allocate " << nb << " bytes." << std::endl; print_free_memory(); # endif } } badalloc: /* not enough memory free */ throw std::bad_alloc(); return nullptr; }
void allocator<T>::deallocate(pointer p, size_type n) { const size_type nb = n * sizeof(T); # if DEBUG_SMA_TRACE_INTERFACE std::cout << "dealloc " << nb << " bytes (n=" << n << ", pointer=" << static_cast<void *>(p) <<")" << std::endl; # endif assert(nb > 0); const size_type pos = calc_pos(memstart, p); assert(0 <= pos && pos < memfree->size()); auto mask = create_mask(nb, memfree->size()) << pos; # if DEBUG_SMA_TRACE_MEMALLOCATION std::cout << "freeed memory: " << mask.count() << " bytes -> " << (memfree->count() + mask.count()) << " bytes free." << std::endl; # endif *memfree = free_memory(*memfree, std::move(mask)); # if DEBUG_SMA_TRACE_MEMALLOCATION print_free_memory(); # endif }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *image, *mask; image = cairo_test_create_surface_from_png (ctx, png_filename); mask = create_mask (cr, 40, 40); /* opaque background */ cairo_paint (cr); /* center */ cairo_translate (cr, (width - cairo_image_surface_get_width (image)) / 2., (height - cairo_image_surface_get_height (image)) / 2.); /* rotate 30 degree around the center */ cairo_translate (cr, width/2., height/2.); cairo_rotate (cr, -30 * 2 * M_PI / 360); cairo_translate (cr, -width/2., -height/2.); /* place the image on our surface */ cairo_set_source_surface (cr, image, 0, 0); /* reset the drawing matrix */ cairo_identity_matrix (cr); /* fill nicely */ cairo_scale (cr, width / 40., height / 40.); /* apply the mask */ cairo_mask_surface (cr, mask, 0, 0); cairo_surface_destroy (mask); cairo_surface_destroy (image); return CAIRO_TEST_SUCCESS; }
/** * Check item flags for legality. This function currently does three things: * - checks slay_table for slay & brand contradictions (dedup_slays) * - checks gf_table for imm/res/vuln contradictions (dedup_gf_flags) * - removes all attrs from ammo except slays/brands/ignore/hates */ void check_flags(object_type *o_ptr) { bitflag f[OF_SIZE]; int i; dedup_slays(o_ptr->flags); dedup_gf_flags(o_ptr->flags); if (kind_is_ammo(o_ptr->tval)) { create_mask(f, FALSE, OFT_SLAY, OFT_BRAND, OFT_KILL, OFT_IGNORE, OFT_HATES, OFT_INT, OFT_MAX); of_inter(o_ptr->flags, f); for (i = 0; i < MAX_PVALS; i++) of_wipe(o_ptr->pval_flags[i]); o_ptr->num_pvals = 0; o_ptr->ac = 0; o_ptr->to_a = 0; } return; }
void MovableIcon::show(void) { if(!shown()) Fl_X::make_xid(this); #ifdef HAVE_SHAPE if(icon->icon_image()) { mask = create_mask(icon->icon_image()); if(mask) { XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet); /* * now set transparency; composite manager should handle the rest (if running) * TODO: should this be declared as part of the class ? */ Atom opacity_atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False); unsigned int opacity = 0xc0000000; XChangeProperty(fl_display, fl_xid(this), opacity_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&opacity, 1L); } } #endif }
block_bits::block_bits(size_t chip_count) : _usable_chips(create_mask(chip_count)) , _zombie_chips(0) { assert(chip_count <= 8*sizeof(bitmap)); }
int main(){ uint8_t dummy_mask[MTCH_FLD_LEN]; uint8_t dummy_flow_entry[MTCH_FLD_LEN + 1]; uint8_t dummy_action[ACTN_ST_LEN]; uint8_t dummy_flag[2]; int mask_pos[2]; tcam_unit match_unit; match_unit.mask_tail = 0; match_unit.flow_tail = 0; create_mask(dummy_mask); create_flow_entry(dummy_flow_entry); create_action(dummy_action); dummy_flag[0] = rand() % 256; dummy_flag[1] = rand() % 256; //mask 1 has 1 flow add_new_entry(&match_unit, dummy_mask, dummy_flow_entry, dummy_action, dummy_flag); uint8_t dummy_flow_entry_2[MTCH_FLD_LEN + 1]; create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); dummy_flag[0] = rand() % 256; dummy_flag[1] = rand() % 256; //mask 1 has 2 flows add_new_entry(&match_unit, dummy_mask, dummy_flow_entry_2, dummy_action, dummy_flag); uint8_t dummy_mask_2[MTCH_FLD_LEN]; create_mask(dummy_mask_2); create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); dummy_flag[0] = 65; dummy_flag[1] = rand() % 256; //mask 2 has 1 flow add_new_entry(&match_unit, dummy_mask_2, dummy_flow_entry_2, dummy_action, dummy_flag); uint8_t dummy_flow_entry_3[MTCH_FLD_LEN + 1]; create_flow_entry(dummy_flow_entry_3); create_action(dummy_action); //mask 2 has 2 flows add_new_entry(&match_unit, dummy_mask_2, dummy_flow_entry_3, dummy_action, dummy_flag); create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); //mask 1 has 3 flows add_new_entry(&match_unit, dummy_mask, dummy_flow_entry_2, dummy_action, dummy_flag); create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); //mask 2 has 3 flows add_new_entry(&match_unit, dummy_mask_2, dummy_flow_entry_2, dummy_action, dummy_flag); output_all_actions(&match_unit); output_all_flow_entries(&match_unit); output_flags(&match_unit); int pos = delete_flow_entry(&match_unit, dummy_flow_entry); printf("%d\n", pos); output_all_actions(&match_unit); output_all_flow_entries(&match_unit); output_flags(&match_unit); uint8_t dummy_action_set[ACTN_ST_LEN]; //search Mask 1 entry 1 //this flow entry has been deleted pos = search_flow(&match_unit, dummy_flow_entry, dummy_action_set, mask_pos); printf("%d %d\n", pos, get_mask_pos(&match_unit, pos)); if(pos != -1) write_output(dummy_action_set); //search mask 2 entry 3 pos = search_flow(&match_unit, dummy_flow_entry_2, dummy_action_set, mask_pos); printf("%d %d\n", pos, get_mask_pos(&match_unit, pos)); if(pos != -1) write_output(dummy_action_set); //search mask 2 entry 2 pos = search_flow(&match_unit, dummy_flow_entry_3, dummy_action_set, mask_pos); printf("%d %d\n", pos, get_mask_pos(&match_unit, pos)); if(pos != -1) write_output(dummy_action_set); /*uint8_t flag_modification[2]; flag_modification[0] = 64; flag_modification[1] = 9; uint8_t new_action_val[8]; uint8_t i; printf("New Action Values:\n"); for(i = 0; i < 8; i++){ new_action_val[i] = rand() % 256; printf("%d\t", new_action_val[i]); } modify_entry(&match_unit, dummy_flow_entry_2, flag_modification, new_action_val); output_all_actions(&match_unit); output_all_flow_entries(&match_unit); output_flags(&match_unit);*/ return 0; }
/* * Describe combat advantages. */ static bool describe_combat(textblock *tb, const object_type *o_ptr, oinfo_detail_t mode) { bool full = mode & OINFO_FULL; const char *desc[SL_MAX] = { 0 }; int i; int mult[SL_MAX]; int cnt, dam, total_dam, plus = 0; int xtra_postcrit = 0, xtra_precrit = 0; int crit_mult, crit_div, crit_add; int str_plus, dex_plus, old_blows = 0, new_blows, extra_blows; int str_faster = -1, str_done = -1; object_type *bow = &p_ptr->inventory[INVEN_BOW]; bitflag f[OF_SIZE], tmp_f[OF_SIZE], mask[OF_SIZE]; bool weapon = (wield_slot(o_ptr) == INVEN_WIELD); bool ammo = (p_ptr->state.ammo_tval == o_ptr->tval) && (bow->kind); int multiplier = 1; /* Create the "all slays" mask */ create_mask(mask, FALSE, OFT_SLAY, OFT_KILL, OFT_BRAND, OFT_MAX); /* Abort if we've nothing to say */ if (mode & OINFO_DUMMY) return FALSE; if (!weapon && !ammo) { /* Potions can have special text */ if (o_ptr->tval != TV_POTION || o_ptr->dd == 0 || o_ptr->ds == 0 || !object_flavor_is_aware(o_ptr)) return FALSE; textblock_append(tb, "It can be thrown at creatures with damaging effect.\n"); return TRUE; } if (full) { object_flags(o_ptr, f); } else { object_flags_known(o_ptr, f); } textblock_append_c(tb, TERM_L_WHITE, "Combat info:\n"); if (weapon) { /* * Get the player's hypothetical state, were they to be * wielding this item. */ player_state state; int dex_plus_bound; int str_plus_bound; object_type inven[INVEN_TOTAL]; memcpy(inven, p_ptr->inventory, INVEN_TOTAL * sizeof(object_type)); inven[INVEN_WIELD] = *o_ptr; if (full) object_know_all_flags(&inven[INVEN_WIELD]); calc_bonuses(inven, &state, TRUE); dex_plus_bound = STAT_RANGE - state.stat_ind[A_DEX]; str_plus_bound = STAT_RANGE - state.stat_ind[A_STR]; dam = ((o_ptr->ds + 1) * o_ptr->dd * 5); xtra_postcrit = state.dis_to_d * 10; if (object_attack_plusses_are_visible(o_ptr)) { xtra_precrit += o_ptr->to_d * 10; plus += o_ptr->to_h; } calculate_melee_crits(&state, o_ptr->weight, plus, &crit_mult, &crit_add, &crit_div); /* Warn about heavy weapons */ if (adj_str_hold[state.stat_ind[A_STR]] < o_ptr->weight / 10) textblock_append_c(tb, TERM_L_RED, "You are too weak to use this weapon.\n"); textblock_append_c(tb, TERM_L_GREEN, "%d.%d ", state.num_blows / 100, (state.num_blows / 10) % 10); textblock_append(tb, "blow%s/round.\n", (state.num_blows > 100) ? "s" : ""); /* Check to see if extra STR or DEX would yield extra blows */ old_blows = state.num_blows; extra_blows = 0; /* First we need to look for extra blows on other items, as * state does not track these */ for (i = INVEN_BOW; i < INVEN_TOTAL; i++) { if (!p_ptr->inventory[i].kind) continue; object_flags_known(&p_ptr->inventory[i], tmp_f); if (of_has(tmp_f, OF_BLOWS)) extra_blows += p_ptr->inventory[i].pval[which_pval(&p_ptr->inventory[i], OF_BLOWS)]; } /* Then we add blows from the weapon being examined */ if (of_has(f, OF_BLOWS)) extra_blows += o_ptr->pval[which_pval(o_ptr, OF_BLOWS)]; /* Then we check for extra "real" blows */ for (dex_plus = 0; dex_plus < dex_plus_bound; dex_plus++) { for (str_plus = 0; str_plus < str_plus_bound; str_plus++) { state.stat_ind[A_STR] += str_plus; state.stat_ind[A_DEX] += dex_plus; new_blows = calc_blows(o_ptr, &state, extra_blows); /* Test to make sure that this extra blow is a * new str/dex combination, not a repeat */ if ((new_blows - new_blows % 10) > (old_blows - old_blows % 10) && (str_plus < str_done || str_done == -1)) { textblock_append(tb, "With +%d STR and +%d DEX you would get %d.%d blows\n", str_plus, dex_plus, (new_blows / 100), (new_blows / 10) % 10); state.stat_ind[A_STR] -= str_plus; state.stat_ind[A_DEX] -= dex_plus; str_done = str_plus; break; } /* If the combination doesn't increment * the displayed blows number, it might still * take a little less energy */ if (new_blows > old_blows && (str_plus < str_faster || str_faster == -1) && (str_plus < str_done || str_done == -1)) { textblock_append(tb, "With +%d STR and +%d DEX you would attack a bit faster\n", str_plus, dex_plus); state.stat_ind[A_STR] -= str_plus; state.stat_ind[A_DEX] -= dex_plus; str_faster = str_plus; continue; } state.stat_ind[A_STR] -= str_plus; state.stat_ind[A_DEX] -= dex_plus; } } } else { int tdis = 6 + 2 * p_ptr->state.ammo_mult; if (object_attack_plusses_are_visible(o_ptr)) plus += o_ptr->to_h; calculate_missile_crits(&p_ptr->state, o_ptr->weight, plus, &crit_mult, &crit_add, &crit_div); /* Calculate damage */ dam = ((o_ptr->ds + 1) * o_ptr->dd * 5); if (object_attack_plusses_are_visible(o_ptr)) dam += (o_ptr->to_d * 10); if (object_attack_plusses_are_visible(bow)) dam += (bow->to_d * 10); /* Apply brands/slays from the shooter to the ammo, but only if known * Note that this is not dependent on mode, so that viewing shop-held * ammo (fully known) does not leak information about launcher */ object_flags_known(bow, tmp_f); of_union(f, tmp_f); textblock_append(tb, "Hits targets up to "); textblock_append_c(tb, TERM_L_GREEN, format("%d", tdis * 10)); textblock_append(tb, " feet away.\n"); } /* Collect slays */ /* Melee weapons get slays and brands from other items now */ if (weapon) { bool nonweap = FALSE; for (i = INVEN_LEFT; i < INVEN_TOTAL; i++) { if (!p_ptr->inventory[i].kind) continue; object_flags_known(&p_ptr->inventory[i], tmp_f); of_inter(tmp_f, mask); /* strip out non-slays */ if (of_union(f, tmp_f)) nonweap = TRUE; } if (nonweap) textblock_append(tb, "This weapon may benefit from one or more off-weapon brands or slays.\n"); } textblock_append(tb, "Average damage/round: "); if (ammo) multiplier = p_ptr->state.ammo_mult; cnt = list_slays(f, mask, desc, NULL, mult, TRUE); for (i = 0; i < cnt; i++) { int melee_adj_mult = ammo ? 0 : 1; /* ammo mult adds fully, melee mult is times 1, so adds 1 less */ /* Include bonus damage and slay in stated average */ total_dam = dam * (multiplier + mult[i] - melee_adj_mult) + xtra_precrit; total_dam = (total_dam * crit_mult + crit_add) / crit_div; total_dam += xtra_postcrit; if (weapon) total_dam = (total_dam * old_blows) / 100; else total_dam *= p_ptr->state.num_shots; if (total_dam <= 0) textblock_append_c(tb, TERM_L_RED, "%d", 0); else if (total_dam % 10) textblock_append_c(tb, TERM_L_GREEN, "%d.%d", total_dam / 10, total_dam % 10); else textblock_append_c(tb, TERM_L_GREEN, "%d", total_dam / 10); textblock_append(tb, " vs. %s, ", desc[i]); } if (cnt) textblock_append(tb, "and "); /* Include bonus damage in stated average */ total_dam = dam * multiplier + xtra_precrit; total_dam = (total_dam * crit_mult + crit_add) / crit_div; total_dam += xtra_postcrit; if (weapon) total_dam = (total_dam * old_blows) / 100; else total_dam *= p_ptr->state.num_shots; if (total_dam <= 0) textblock_append_c(tb, TERM_L_RED, "%d", 0); else if (total_dam % 10) textblock_append_c(tb, TERM_L_GREEN, "%d.%d", total_dam / 10, total_dam % 10); else textblock_append_c(tb, TERM_L_GREEN, "%d", total_dam / 10); if (cnt) textblock_append(tb, " vs. others"); textblock_append(tb, ".\n"); /* Note the impact flag */ if (of_has(f, OF_IMPACT)) textblock_append(tb, "Sometimes creates earthquakes on impact.\n"); /* Add breakage chance */ if (ammo) { int chance = breakage_chance(o_ptr, TRUE); textblock_append_c(tb, TERM_L_GREEN, "%d%%", chance); textblock_append(tb, " chance of breaking upon contact.\n"); } /* You always have something to say... */ return TRUE; }
/*********** * MAIN **********/ int main(int argc, char **argv) { ///////////////////////////////////////////////////////// // mask definition for analysis of neighborhood of voxels UFO mask = create_mask(MASKSIZE); mask_ground = create_ground_mask_Z(MASKSIZE); ///////////////////////////////////////////////////////// // 3D Viewing if (debug & DEBUG_3D) { my_view_3D = new CView_3D(); my_view_3D->show_axis(); my_view_3D->initialize_ball_actors(); if (debug & DEBUG_MASK) my_view_3D->initialize_mask_actors(mask,MASKSIZE,gridsize); if (debug & DEBUG_TRAJECTORY) my_view_3D->initialize_traj_actors(TRAJECTORY_SAMPLE); } my_trajectory = new CTrajectory(); /////////////////////////////////// // for pointcloud reading from disk int image_number = 0; //int first_image = 0; int first_image = 0; //int last_image = 126; int last_image = 17; char filename[200]; // debug if (argc == 2) { debug = atoi(argv[1]); } if (ros_com==0) { // update fisrt and last image from args if (argc == 3) { first_image = atoi(argv[1]); last_image = atoi(argv[2]); } pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in (new pcl::PointCloud<pcl::PointXYZ>); for (image_number = first_image; image_number < last_image; image_number++) { ////////////////////// // Read point cloud //sprintf(filename,"/home/paulo/rosbag/at_home_15032013/cloud/kinect_cloud_%d.pcd",image_number); sprintf(filename,"/home/paulo/rosbag/ball_arm/cloud/kinect_cloud_%d.pcd",image_number); //printf("\n reading %s",filename); if (pcl::io::loadPCDFile<pcl::PointXYZ> (filename, *cloud_in) == -1) //* load the file { printf ("Couldn't read file %s\n",filename); getchar(); return (-1); } Callback(cloud_in); } } // for pointcloud reading from disk /////////////////////////////////// ////////////////////////////////// // for ROS Operation else { ros::init(argc, argv, "camera_depth_optical_frame"); listener = new (tf::TransformListener); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/camera/depth/points", 1, Callback); pub = n.advertise<geometry_msgs::PointStamped>("/ball3D", 10); ros::spin(); } //for ROS Operation ////////////////////////////////// printf("\n---------------------------------"); printf("\n- General Report"); printf("\n Air ball detected: %d",air_detect); printf("\n Ground ball detected: %d",ground_detect); printf("\n Processed images: %d",im_num); printf("\n---------------------------------\n"); if (debug & DEBUG_3D) my_view_3D->start_interaction(); // HouseKeeping delete(mask); delete(mask_ground); return 0; }
/* * Describe damage. */ static bool describe_damage(textblock *tb, const object_type *o_ptr, player_state state, bitflag f[OF_SIZE], oinfo_detail_t mode) { const char *desc[SL_MAX] = { 0 }; size_t i, cnt; int mult[SL_MAX]; int dice, sides, dam, total_dam, plus = 0; int xtra_postcrit = 0, xtra_precrit = 0; int crit_mult, crit_div, crit_add; int old_blows = 0; object_type *bow = &p_ptr->inventory[INVEN_BOW]; bitflag tmp_f[OF_SIZE], mask[OF_SIZE]; bool weapon = (wield_slot(o_ptr) == INVEN_WIELD); bool ammo = (p_ptr->state.ammo_tval == o_ptr->tval) && (bow->kind); int multiplier = 1; bool full = mode & OINFO_FULL; /* Create the "all slays" mask */ create_mask(mask, FALSE, OFT_SLAY, OFT_KILL, OFT_BRAND, OFT_MAX); /* Use displayed dice if real dice not known */ if (full || object_attack_plusses_are_visible(o_ptr)) { dice = o_ptr->dd; sides = o_ptr->ds; } else { dice = o_ptr->kind->dd; sides = o_ptr->kind->ds; } /* Calculate damage */ dam = ((sides + 1) * dice * 5); if (weapon) { xtra_postcrit = state.dis_to_d * 10; if (object_attack_plusses_are_visible(o_ptr) || full) { xtra_precrit += o_ptr->to_d * 10; plus += o_ptr->to_h; } calculate_melee_crits(&state, o_ptr->weight, plus, &crit_mult, &crit_add, &crit_div); old_blows = state.num_blows; } else { /* Ammo */ if (object_attack_plusses_are_visible(o_ptr) || full) plus += o_ptr->to_h; calculate_missile_crits(&p_ptr->state, o_ptr->weight, plus, &crit_mult, &crit_add, &crit_div); if (object_attack_plusses_are_visible(o_ptr) || full) dam += (o_ptr->to_d * 10); if (object_attack_plusses_are_visible(bow)) dam += (bow->to_d * 10); /* Apply brands/slays from the shooter to the ammo, but only if known * Note that this is not dependent on mode, so that viewing shop-held * ammo (fully known) does not leak information about launcher */ object_flags_known(bow, tmp_f); of_union(f, tmp_f); } /* Collect slays */ /* Melee weapons get slays and brands from other items now */ if (weapon) { bool nonweap_slay = FALSE; for (i = INVEN_LEFT; i < INVEN_TOTAL; i++) { if (!p_ptr->inventory[i].kind) continue; object_flags_known(&p_ptr->inventory[i], tmp_f); /* Strip out non-slays */ of_inter(tmp_f, mask); if (of_union(f, tmp_f)) nonweap_slay = TRUE; } if (nonweap_slay) textblock_append(tb, "This weapon may benefit from one or more off-weapon brands or slays.\n"); } textblock_append(tb, "Average damage/round: "); if (ammo) multiplier = p_ptr->state.ammo_mult; /* Output damage for creatures effected by the brands or slays */ cnt = list_slays(f, mask, desc, NULL, mult, TRUE); for (i = 0; i < cnt; i++) { /* ammo mult adds fully, melee mult is times 1, so adds 1 less */ int melee_adj_mult = ammo ? 0 : 1; /* Include bonus damage and slay in stated average */ total_dam = dam * (multiplier + mult[i] - melee_adj_mult) + xtra_precrit; total_dam = (total_dam * crit_mult + crit_add) / crit_div; total_dam += xtra_postcrit; if (weapon) total_dam = (total_dam * old_blows) / 100; else total_dam *= p_ptr->state.num_shots; if (total_dam <= 0) textblock_append_c(tb, TERM_L_RED, "%d", 0); else if (total_dam % 10) textblock_append_c(tb, TERM_L_GREEN, "%d.%d", total_dam / 10, total_dam % 10); else textblock_append_c(tb, TERM_L_GREEN, "%d", total_dam / 10); textblock_append(tb, " vs. %s, ", desc[i]); } if (cnt) textblock_append(tb, "and "); /* Include bonus damage in stated average */ total_dam = dam * multiplier + xtra_precrit; total_dam = (total_dam * crit_mult + crit_add) / crit_div; total_dam += xtra_postcrit; /* Normal damage, not considering brands or slays */ if (weapon) total_dam = (total_dam * old_blows) / 100; else total_dam *= p_ptr->state.num_shots; if (total_dam <= 0) textblock_append_c(tb, TERM_L_RED, "%d", 0); else if (total_dam % 10) textblock_append_c(tb, TERM_L_GREEN, "%d.%d", total_dam / 10, total_dam % 10); else textblock_append_c(tb, TERM_L_GREEN, "%d", total_dam / 10); if (cnt) textblock_append(tb, " vs. others"); textblock_append(tb, ".\n"); return TRUE; }
/* * Determine the squelch level of an object, which is similar to its pseudo. * * The main point is when the value is undetermined given current info, * return the maximum possible value. */ byte squelch_level_of(const object_type *o_ptr) { byte value; bitflag f[OF_SIZE], f2[OF_SIZE]; int i; object_flags_known(o_ptr, f); /* Deal with jewelry specially. */ if (object_is_jewelry(o_ptr)) { /* CC: average jewelry has at least one known positive pval */ for (i = 0; i < o_ptr->num_pvals; i++) if ((object_this_pval_is_visible(o_ptr, i)) && (o_ptr->pval[i] > 0)) return SQUELCH_AVERAGE; if ((o_ptr->to_h > 0) || (o_ptr->to_d > 0) || (o_ptr->to_a > 0)) return SQUELCH_AVERAGE; if ((object_attack_plusses_are_visible(o_ptr) && ((o_ptr->to_h < 0) || (o_ptr->to_d < 0))) || (object_defence_plusses_are_visible(o_ptr) && o_ptr->to_a < 0)) return SQUELCH_BAD; return SQUELCH_AVERAGE; } /* And lights */ if (o_ptr->tval == TV_LIGHT) { create_mask(f2, TRUE, OFID_WIELD, OFT_MAX); if (of_is_inter(f, f2)) return SQUELCH_ALL; if ((o_ptr->to_h > 0) || (o_ptr->to_d > 0) || (o_ptr->to_a > 0)) return SQUELCH_GOOD; if ((o_ptr->to_h < 0) || (o_ptr->to_d < 0) || (o_ptr->to_a < 0)) return SQUELCH_BAD; return SQUELCH_AVERAGE; } /* CC: we need to redefine "bad" with multiple pvals * At the moment we use "all pvals known and negative" */ for (i = 0; i < o_ptr->num_pvals; i++) { if (!object_this_pval_is_visible(o_ptr, i) || (o_ptr->pval[i] > 0)) break; if (i == (o_ptr->num_pvals - 1)) return SQUELCH_BAD; } if (object_was_sensed(o_ptr)) { obj_pseudo_t pseudo = object_pseudo(o_ptr); switch (pseudo) { case INSCRIP_AVERAGE: { value = SQUELCH_AVERAGE; break; } case INSCRIP_EXCELLENT: { /* have to assume splendid until you have tested it */ if (object_was_worn(o_ptr)) { if (object_high_resist_is_possible(o_ptr)) value = SQUELCH_EXCELLENT_NO_SPL; else value = SQUELCH_EXCELLENT_NO_HI; } else { value = SQUELCH_ALL; } break; } case INSCRIP_SPLENDID: value = SQUELCH_ALL; break; case INSCRIP_NULL: case INSCRIP_SPECIAL: value = SQUELCH_MAX; break; /* This is the interesting case */ case INSCRIP_STRANGE: case INSCRIP_MAGICAL: { value = SQUELCH_GOOD; if ((object_attack_plusses_are_visible(o_ptr) || randcalc_valid(o_ptr->kind->to_h, o_ptr->to_h) || randcalc_valid(o_ptr->kind->to_d, o_ptr->to_d)) && (object_defence_plusses_are_visible(o_ptr) || randcalc_valid(o_ptr->kind->to_a, o_ptr->to_a))) { int isgood = is_object_good(o_ptr); if (isgood > 0) { value = SQUELCH_GOOD; } else if (isgood < 0) { value = SQUELCH_BAD; } else { value = SQUELCH_AVERAGE; } } break; } default: /* do not handle any other possible pseudo values */ assert(0); } } else { if (object_was_worn(o_ptr)) value = SQUELCH_EXCELLENT_NO_SPL; /* object would be sensed if it were splendid */ else if (object_is_known_not_artifact(o_ptr)) value = SQUELCH_ALL; else value = SQUELCH_MAX; } return value; }
/** * Determine the ignore level of an object, which is similar to its pseudo. * * The main point is when the value is undetermined given current info, * return the maximum possible value. */ byte ignore_level_of(const struct object *obj) { byte value = 0; bitflag f[OF_SIZE], f2[OF_SIZE]; int i; bool negative_mod = FALSE; object_flags_known(obj, f); /* Deal with jewelry specially. */ if (tval_is_jewelry(obj)) { /* CC: average jewelry has at least one known positive modifier */ for (i = 0; i < OBJ_MOD_MAX; i++) if ((object_this_mod_is_visible(obj, i)) && (obj->modifiers[i] > 0)) return IGNORE_AVERAGE; if ((obj->to_h > 0) || (obj->to_d > 0) || (obj->to_a > 0)) return IGNORE_AVERAGE; if ((object_attack_plusses_are_visible(obj) && ((obj->to_h < 0) || (obj->to_d < 0))) || (object_defence_plusses_are_visible(obj) && obj->to_a < 0)) return IGNORE_BAD; return IGNORE_AVERAGE; } /* And lights */ if (tval_is_light(obj)) { create_mask(f2, TRUE, OFID_WIELD, OFT_MAX); if (of_is_inter(f, f2)) return IGNORE_ALL; if ((obj->to_h > 0) || (obj->to_d > 0) || (obj->to_a > 0)) return IGNORE_GOOD; if ((obj->to_h < 0) || (obj->to_d < 0) || (obj->to_a < 0)) return IGNORE_BAD; return IGNORE_AVERAGE; } /* We need to redefine "bad" * At the moment we use "all modifiers known and negative" */ for (i = 0; i < OBJ_MOD_MAX; i++) { if (!object_this_mod_is_visible(obj, i) || (obj->modifiers[i] > 0)) break; if (obj->modifiers[i] < 0) negative_mod = TRUE; } if ((i == OBJ_MOD_MAX) && negative_mod) return IGNORE_BAD; if (object_was_sensed(obj)) { obj_pseudo_t pseudo = object_pseudo(obj); switch (pseudo) { case INSCRIP_AVERAGE: { value = IGNORE_AVERAGE; break; } case INSCRIP_EXCELLENT: { /* have to assume splendid until you have tested it */ if (object_was_worn(obj)) { if (object_high_resist_is_possible(obj)) value = IGNORE_EXCELLENT_NO_SPL; else value = IGNORE_EXCELLENT_NO_HI; } else { value = IGNORE_ALL; } break; } case INSCRIP_SPLENDID: value = IGNORE_ALL; break; case INSCRIP_NULL: case INSCRIP_SPECIAL: value = IGNORE_MAX; break; /* This is the interesting case */ case INSCRIP_STRANGE: case INSCRIP_MAGICAL: { value = IGNORE_GOOD; if ((object_attack_plusses_are_visible(obj) || randcalc_valid(obj->kind->to_h, obj->to_h) || randcalc_valid(obj->kind->to_d, obj->to_d)) && (object_defence_plusses_are_visible(obj) || randcalc_valid(obj->kind->to_a, obj->to_a))) { int isgood = is_object_good(obj); if (isgood > 0) { value = IGNORE_GOOD; } else if (isgood < 0) { value = IGNORE_BAD; } else { value = IGNORE_AVERAGE; } } break; } default: /* do not handle any other possible pseudo values */ assert(0); } } else { if (object_was_worn(obj)) value = IGNORE_EXCELLENT_NO_SPL; /* object would be sensed if it were splendid */ else if (object_is_known_not_artifact(obj)) value = IGNORE_ALL; else value = IGNORE_MAX; } return value; }
MaskDatum TopologyModule::create_mask( const Token& t ) { // t can be either an existing MaskDatum, or a Dictionary containing // mask parameters MaskDatum* maskd = dynamic_cast< MaskDatum* >( t.datum() ); if ( maskd ) { return *maskd; } else { DictionaryDatum* dd = dynamic_cast< DictionaryDatum* >( t.datum() ); if ( dd == 0 ) { throw BadProperty( "Mask must be masktype or dictionary." ); } // The dictionary should contain one key which is the name of the // mask type, and optionally the key 'anchor'. To find the unknown // mask type key, we must loop through all keys. The value for the // anchor key will be stored in the anchor_token variable. Token anchor_token; bool has_anchor = false; AbstractMask* mask = 0; for ( Dictionary::iterator dit = ( *dd )->begin(); dit != ( *dd )->end(); ++dit ) { if ( dit->first == names::anchor ) { anchor_token = dit->second; has_anchor = true; } else { if ( mask != 0 ) { // mask has already been defined throw BadProperty( "Mask definition dictionary contains extraneous items." ); } mask = create_mask( dit->first, getValue< DictionaryDatum >( dit->second ) ); } } if ( has_anchor ) { // The anchor may be an array of doubles (a spatial position), or a // dictionary containing the keys 'column' and 'row' (for grid // masks only) try { std::vector< double > anchor = getValue< std::vector< double > >( anchor_token ); AbstractMask* amask; switch ( anchor.size() ) { case 2: amask = new AnchoredMask< 2 >( dynamic_cast< Mask< 2 >& >( *mask ), anchor ); break; case 3: amask = new AnchoredMask< 3 >( dynamic_cast< Mask< 3 >& >( *mask ), anchor ); break; default: throw BadProperty( "Anchor must be 2- or 3-dimensional." ); } delete mask; mask = amask; } catch ( TypeMismatch& e ) { DictionaryDatum ad = getValue< DictionaryDatum >( anchor_token ); int dim = 2; int column = getValue< long >( ad, names::column ); int row = getValue< long >( ad, names::row ); int layer; if ( ad->known( names::layer ) ) { layer = getValue< long >( ad, names::layer ); dim = 3; } switch ( dim ) { case 2: try { GridMask< 2 >& grid_mask_2d = dynamic_cast< GridMask< 2 >& >( *mask ); grid_mask_2d.set_anchor( Position< 2, int >( column, row ) ); } catch ( std::bad_cast& e ) { throw BadProperty( "Mask must be 2-dimensional grid mask." ); } break; case 3: try { GridMask< 3 >& grid_mask_3d = dynamic_cast< GridMask< 3 >& >( *mask ); grid_mask_3d.set_anchor( Position< 3, int >( column, row, layer ) ); } catch ( std::bad_cast& e ) { throw BadProperty( "Mask must be 3-dimensional grid mask." ); } break; } } } return mask; } }
int main(int argc, char *argv[]){ int c; //set up initial values char *interface = NULL; //interface to attack from char *addr = NULL; //ipv4 address of the fake net int metric = 1; char *next_hop_addr = (char *) "0.0.0.0"; //the address of the next hop int route_tag = 0; char *pass = NULL; int mask; char *temp; while((c = getopt(argc, argv, "i:r:m:n:t:p:h")) != -1){ switch(c){ case 'i': interface = optarg; break; case 'r': addr = strtok(optarg, "/"); temp = strtok(NULL, "\0"); mask = atoi(( (temp == NULL) ? "-1": temp)); break; case 'm': metric = ( is_numeric(std::string(optarg)) ? atoi(optarg) : -1) ; break; case 'n': next_hop_addr = optarg; break; case 't': route_tag = (is_numeric(std::string(optarg)) ? atoi(optarg) : -1); break; case 'p': pass = optarg; break; case 'h': help(); return 0; break; case '?': std::cerr << "Unknown option specified...quitting. To show help, type -h." << std::endl; return(1); default: abort(); break; } } //check the input if(addr == NULL){ std::cerr << "Invalid or none fake address specified, quitting. To show help, type -h" << std::endl; return(1); } if(mask < 8 || mask > 32){ std::cerr << "Invalid netmask, quitting. To show help, type -h" << std::endl; return(1); } if(metric < 1 || metric > 16){ std::cerr << "Invalid metric, quitting. To show help, type -h" << std::endl; return(1); } if(!check_addr(std::string(addr)) || !check_addr(std::string(next_hop_addr))){ std::cerr << "Invalid address format, quitting. To show help, type -h" << std::endl; return(1); } if(route_tag == -1){ std::cerr << "Invalid router tag value, quitting. To show help, type -h" << std::endl; return(1); } struct Header *h = new Header; struct Data *d = new Data; struct Auth *a = NULL; //compute netmask char *entry_mask = new char[15]; create_mask(mask, entry_mask); inet_aton(entry_mask, &((d->mask))); //print the specified settings std::cout << "fake addr: " << addr << " netmask: " << mask << " or " << entry_mask << std::endl; std::cout << "metric: " << metric << std::endl; std::cout << "next hop: " << next_hop_addr << std::endl; std::cout << "route tag: " << route_tag << std::endl; std::cout << "pass: "******"no pass" : pass) << std::endl; if(pass != NULL) a = new Auth; //check and fill the password if(pass != NULL){ //check password length int pass_len = strlen(pass); if(pass_len > MAX_PASS_LEN){ std::cerr << "password too long, max length " << MAX_PASS_LEN << std::endl; return(1); } memset((char *) &a->pass, 0, sizeof(a->pass)); memcpy(a->pass, pass, strlen(pass)); } //fill the RIP header h->command = 2; h->version = 2; //fill the RIP data d->AFI = 2; d->route_tag = route_tag; d->metric = metric; inet_aton(addr, &((d->IP))); inet_aton(next_hop_addr, &((d->next_hop))); //create a sender and load the data Sender *my_sender; if(interface == NULL) my_sender = new Sender(); else my_sender = new Sender(std::string(interface)); my_sender->load_packet(h, d, a); //send packet if(my_sender->send_packet() != 0){ std::cerr << "chyba pri odesilani paketu" << std::endl; } //free the memory delete my_sender; delete h; delete d; delete a; delete entry_mask; std::cout << std::endl; return 0; }
/* * Evaluate the object's overall power level. */ s32b object_power(const object_type* o_ptr, int verbose, ang_file *log_file, bool known) { s32b p = 0, q = 0, slay_pwr = 0; unsigned int i, j; int extra_stat_bonus = 0, mult = 1, num_slays = 0, k = 1; bitflag flags[OF_SIZE], mask[OF_SIZE]; /* Zero the flag counts */ for (i = 0; i < N_ELEMENTS(sets); i++) sets[i].count = 0; /* Extract the flags */ if (known) { file_putf(log_file, "Object is deemed known\n"); object_flags(o_ptr, flags); } else { file_putf(log_file, "Object may not be fully known\n"); object_flags_known(o_ptr, flags); } /* Log the flags in human-readable form */ if (verbose) log_flags(flags, log_file); /* Get the slay power and number of slay/brand types */ create_mask(mask, FALSE, OFT_SLAY, OFT_KILL, OFT_BRAND, OFT_MAX); num_slays = list_slays(flags, mask, NULL, NULL, NULL, TRUE); if (num_slays) slay_pwr = slay_power(o_ptr, verbose, log_file, known); /* Start with any damage boost from the item itself */ p += (o_ptr->to_d * DAMAGE_POWER / 2); file_putf(log_file, "Adding power from to_dam, total is %d\n", p); /* Add damage from dice for any wieldable weapon or ammo */ if (wield_slot(o_ptr) == INVEN_WIELD || obj_is_ammo(o_ptr)) { p += (o_ptr->dd * (o_ptr->ds + 1) * DAMAGE_POWER / 4); file_putf(log_file, "Adding power for dam dice, total is %d\n", p); /* Add 2nd lot of damage power for nonweapons */ } else if (wield_slot(o_ptr) != INVEN_BOW) { p += (o_ptr->to_d * DAMAGE_POWER); file_putf(log_file, "Adding power from nonweap to_dam, total is %d\n", p); /* Add power boost for nonweapons with combat flags */ if (num_slays || of_has(flags, OF_BLOWS) || of_has(flags, OF_SHOTS) || of_has(flags, OF_MIGHT)) { p += (WEAP_DAMAGE * DAMAGE_POWER); file_putf(log_file, "Adding power for nonweap combat flags, total is %d\n", p); } } /* Add ammo damage for launchers, get multiplier and rescale */ if (wield_slot(o_ptr) == INVEN_BOW) { p += (archery[o_ptr->sval / 10].ammo_dam * DAMAGE_POWER / 2); file_putf(log_file, "Adding power from ammo, total is %d\n", p); mult = bow_multiplier(o_ptr->sval); file_putf(log_file, "Base mult for this weapon is %d\n", mult); } /* Add launcher bonus for ego ammo, multiply for launcher and rescale */ if (obj_is_ammo(o_ptr)) { if (o_ptr->ego) p += (archery[o_ptr->tval - TV_SHOT].launch_dam * DAMAGE_POWER / 2); p = p * archery[o_ptr->tval - TV_SHOT].launch_mult / (2 * MAX_BLOWS); file_putf(log_file, "After multiplying ammo and rescaling, power is %d\n", p); } /* Add power for extra blows */ if (of_has(flags, OF_BLOWS)) { j = which_pval(o_ptr, OF_BLOWS); if (known || object_this_pval_is_visible(o_ptr, j)) { if (o_ptr->pval[j] >= INHIBIT_BLOWS) { p += INHIBIT_POWER; file_putf(log_file, "INHIBITING - too many extra blows\n"); } else { p = p * (MAX_BLOWS + o_ptr->pval[j]) / MAX_BLOWS; /* Add boost for assumed off-weapon damage */ p += (NONWEAP_DAMAGE * o_ptr->pval[j] * DAMAGE_POWER / 2); file_putf(log_file, "Adding power for extra blows, total is %d\n", p); } } } /* Add power for extra shots - note that we cannot handle negative shots */ if (of_has(flags, OF_SHOTS)) { j = which_pval(o_ptr, OF_SHOTS); if (known || object_this_pval_is_visible(o_ptr, j)) { if (o_ptr->pval[j] >= INHIBIT_SHOTS) { p += INHIBIT_POWER; file_putf(log_file, "INHIBITING - too many extra shots\n"); } else if (o_ptr->pval[j] > 0) { p = (p * (1 + o_ptr->pval[j])); file_putf(log_file, "Extra shots: multiplying power by 1 + %d, total is %d\n", o_ptr->pval[j], p); } } } /* Add power for extra might */ if (of_has(flags, OF_MIGHT)) { j = which_pval(o_ptr, OF_MIGHT); if (known || object_this_pval_is_visible(o_ptr, j)) { if (o_ptr->pval[j] >= INHIBIT_MIGHT) { p += INHIBIT_POWER; mult = 1; /* don't overflow */ file_putf(log_file, "INHIBITING - too much extra might\n"); } else mult += o_ptr->pval[j]; file_putf(log_file, "Mult after extra might is %d\n", mult); } } p *= mult; file_putf(log_file, "After multiplying power for might, total is %d\n", p); /* Apply the correct slay multiplier */ if (slay_pwr) { p = (p * (slay_pwr / 10)) / (tot_mon_power / 10); file_putf(log_file, "Adjusted for slay power, total is %d\n", p); } /* Melee weapons assume MAX_BLOWS per turn, so we must divide by MAX_BLOWS * to get equal ratings for launchers. */ if (wield_slot(o_ptr) == INVEN_BOW) { p /= MAX_BLOWS; file_putf(log_file, "Rescaling bow power, total is %d\n", p); } /* Add power for +to_hit */ p += (o_ptr->to_h * TO_HIT_POWER / 2); file_putf(log_file, "Adding power for to hit, total is %d\n", p); /* Add power for base AC and adjust for weight */ if (o_ptr->ac) { q += BASE_ARMOUR_POWER; q += (o_ptr->ac * BASE_AC_POWER / 2); file_putf(log_file, "Adding %d power for base AC value\n", q); /* Add power for AC per unit weight */ if (o_ptr->weight > 0) { i = 800 * (o_ptr->ac + o_ptr->to_a) / o_ptr->weight; /* Avoid overpricing Elven Cloaks */ if (i > 450) i = 450; q *= i; q /= 100; /* Weightless (ethereal) armour items get fixed boost */ } else q *= 5; p += q; file_putf(log_file, "Adding power for AC per unit weight, now %d\n", p); } /* Add power for +to_ac */ p += (o_ptr->to_a * TO_AC_POWER / 2); file_putf(log_file, "Adding power for to_ac of %d, total is %d\n", o_ptr->to_a, p); if (o_ptr->to_a > HIGH_TO_AC) { p += ((o_ptr->to_a - (HIGH_TO_AC - 1)) * TO_AC_POWER); file_putf(log_file, "Adding power for high to_ac value, total is %d\n", p); } if (o_ptr->to_a > VERYHIGH_TO_AC) { p += ((o_ptr->to_a - (VERYHIGH_TO_AC -1)) * TO_AC_POWER * 2); file_putf(log_file, "Adding power for very high to_ac value, total is %d\n", p); } if (o_ptr->to_a >= INHIBIT_AC) { p += INHIBIT_POWER; file_putf(log_file, "INHIBITING: AC bonus too high\n"); } /* Add power for light sources by radius XXX Hack - rewrite calc_torch! */ if (wield_slot(o_ptr) == INVEN_LIGHT) { p += BASE_LIGHT_POWER; /* Artifact lights have larger radius so add more */ if (o_ptr->artifact) p += BASE_LIGHT_POWER; file_putf(log_file, "Adding power for light radius, total is %d\n", p); } /* Add base power for jewelry */ if (object_is_jewelry(o_ptr)) { p += BASE_JEWELRY_POWER; file_putf(log_file, "Adding power for jewelry, total is %d\n", p); } /* Add power for non-derived flags (derived flags have flag_power 0) */ for (i = 0; i < OF_MAX; i++) { if (of_has(flags, i)) { if (flag_uses_pval(i)) { j = which_pval(o_ptr, i); if (known || object_this_pval_is_visible(o_ptr, j)) { k = o_ptr->pval[j]; extra_stat_bonus += (k * pval_mult(i)); } } else k = 1; if (flag_power(i)) { p += (k * flag_power(i) * slot_mult(i, wield_slot(o_ptr))); file_putf(log_file, "Adding power for %s, total is %d\n", flag_name(i), p); } /* Track combinations of flag types - note we ignore SUST_CHR */ for (j = 0; j < N_ELEMENTS(sets); j++) if ((sets[j].type == obj_flag_type(i)) && (i != OF_SUST_CHR)) sets[j].count++; } } /* Add extra power term if there are a lot of ability bonuses */ if (extra_stat_bonus > 249) { file_putf(log_file, "Inhibiting! (Total ability bonus of %d is too high)\n", extra_stat_bonus); p += INHIBIT_POWER; } else { p += ability_power[extra_stat_bonus / 10]; file_putf(log_file, "Adding power for pval total of %d, total is %d\n", extra_stat_bonus, p); } /* Add extra power for multiple flags of the same type */ for (i = 0; i < N_ELEMENTS(sets); i++) { if (sets[i].count > 1) { p += (sets[i].factor * sets[i].count * sets[i].count); file_putf(log_file, "Adding power for multiple flags of type %d, total is %d\n", i, p); } /* Add bonus if item has a full set of these flags */ if (sets[i].count == sets[i].size) { p += sets[i].bonus; file_putf(log_file, "Adding power for full set of type %d, total is %d\n", i, p); } } /* add power for effect */ if (known || object_effect_is_known(o_ptr)) { if (o_ptr->artifact && o_ptr->artifact->effect) { p += effect_power(o_ptr->artifact->effect); file_putf(log_file, "Adding power for artifact activation, total is %d\n", p); } else { p += effect_power(o_ptr->kind->effect); file_putf(log_file, "Adding power for item activation, total is %d\n", p); } } file_putf(log_file, "FINAL POWER IS %d\n", p); return p; }
/** * Calculate the rating for a given slay combination */ static s32b slay_power(const object_type *o_ptr, int verbose, ang_file* log_file, bool known) { bitflag s_index[OF_SIZE], f[OF_SIZE], f2[OF_SIZE]; u32b sv = 0; int i, j; int mult; const struct slay *best_s_ptr = NULL; monster_race *r_ptr; monster_type *m_ptr; monster_type monster_type_body; const char *desc[SL_MAX] = { 0 }, *brand[SL_MAX] = { 0 }; int s_mult[SL_MAX] = { 0 }; if (known) object_flags(o_ptr, f); else object_flags_known(o_ptr, f); /* Combine the slay bytes into an index value, return if there are none */ of_copy(s_index, f); create_mask(f2, FALSE, OFT_SLAY, OFT_KILL, OFT_BRAND, OFT_MAX); if (!of_is_inter(s_index, f2)) return tot_mon_power; else of_inter(s_index, f2); /* Look in the cache to see if we know this one yet */ sv = check_slay_cache(s_index); /* If it's cached (or there are no slays), return the value */ if (sv) { file_putf(log_file, "Slay cache hit\n"); return sv; } /* * Otherwise we need to calculate the expected average multiplier * for this combination (multiplied by the total number of * monsters, which we'll divide out later). */ for (i = 0; i < z_info->r_max; i++) { best_s_ptr = NULL; mult = 1; r_ptr = &r_info[i]; m_ptr = &monster_type_body; m_ptr->r_idx = i; /* Find the best multiplier against this monster */ improve_attack_modifier((object_type *)o_ptr, m_ptr, &best_s_ptr, FALSE, !known); if (best_s_ptr) mult = best_s_ptr->mult; /* Add the multiple to sv */ sv += mult * r_ptr->scaled_power; } /* * To get the expected damage for this weapon, multiply the * average damage from base dice by sv, and divide by the * total number of monsters. */ if (verbose) { /* Write info about the slay combination and multiplier */ file_putf(log_file, "Slay multiplier for: "); j = list_slays(s_index, s_index, desc, brand, s_mult, FALSE); for (i = 0; i < j; i++) { if (brand[i]) { file_putf(log_file, brand[i]); } else { file_putf(log_file, desc[i]); } file_putf(log_file, "x%d ", s_mult[i]); } file_putf(log_file, "\nsv is: %d\n", sv); file_putf(log_file, " and t_m_p is: %d \n", tot_mon_power); file_putf(log_file, "times 1000 is: %d\n", (1000 * sv) / tot_mon_power); } /* Add to the cache */ if (fill_slay_cache(s_index, sv)) file_putf(log_file, "Added to slay cache\n"); return sv; }
static size_t obj_desc_inscrip(const object_type *o_ptr, char *buf, size_t max, size_t end) { const char *u[4] = { 0, 0, 0, 0 }; int n = 0; int feel = object_pseudo(o_ptr); bitflag flags_known[OF_SIZE], f2[OF_SIZE]; object_flags_known(o_ptr, flags_known); /* Get inscription */ if (o_ptr->note) u[n++] = quark_str(o_ptr->note); /* Use special inscription, if any */ if (!object_is_known(o_ptr) && feel) { /* cannot tell excellent vs strange vs splendid until wield */ if (!object_was_worn(o_ptr) && o_ptr->ego) u[n++] = "ego"; else u[n++] = inscrip_text[feel]; } else if ((o_ptr->ident & IDENT_EMPTY) && !object_is_known(o_ptr)) u[n++] = "empty"; else if (!object_is_known(o_ptr) && object_was_worn(o_ptr)) { if (wield_slot(o_ptr) == INVEN_WIELD || wield_slot(o_ptr) == INVEN_BOW) u[n++] = "wielded"; else u[n++] = "worn"; } else if (!object_is_known(o_ptr) && object_was_fired(o_ptr)) u[n++] = "fired"; else if (!object_flavor_is_aware(o_ptr) && object_flavor_was_tried(o_ptr)) u[n++] = "tried"; /* Note curses */ create_mask(f2, FALSE, OFT_CURSE, OFT_MAX); if (of_is_inter(flags_known, f2)) u[n++] = "cursed"; /* Note squelch */ if (squelch_item_ok(o_ptr)) u[n++] = "squelch"; if (n) { int i; for (i = 0; i < n; i++) { if (i == 0) strnfcat(buf, max, &end, " {"); strnfcat(buf, max, &end, "%s", u[i]); if (i < n-1) strnfcat(buf, max, &end, ", "); } strnfcat(buf, max, &end, "}"); } return end; }