本文整理汇总了C++中N_ELEMENTS函数的典型用法代码示例。如果您正苦于以下问题:C++ N_ELEMENTS函数的具体用法?C++ N_ELEMENTS怎么用?C++ N_ELEMENTS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了N_ELEMENTS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: spoil_mon_desc
/*
* Create a spoiler file for monsters -BEN-
*/
static void spoil_mon_desc(void)
{
int i, n = 0;
C_TNEW(who, MAX_R_IDX, s16b);
char nam[80];
char lev[80];
char rar[80];
char spd[80];
char ac[80];
char hp[80];
char exp[80];
/* Dump the header */
fprintf(fff, "Monster Spoilers for %s Version %s\n", GAME_NAME,
GAME_VERSION);
fprintf(fff, "------------------------------------------\n\n");
/* Dump the header */
fprintf(fff, "%-40.40s%4s%4s%6s%8s%4s %11.11s\n",
"Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info");
fprintf(fff, "%-40.40s%4s%4s%6s%8s%4s %11.11s\n",
"----", "---", "---", "---", "--", "--", "-----------");
/* Scan the monsters (except the ghost) */
for (i = 1; i < MAX_R_IDX; i++)
{
monster_race *r_ptr = &r_info[i];
/* Hack - skip "fake" monsters. */
if (is_fake_monster(r_ptr)) continue;
/* Use that monster */
if (r_ptr->name) who[n++] = i;
}
/* Scan again */
for (i = 0; i < n; i++)
{
monster_race *r_ptr = &r_info[who[i]];
cptr pre;
/* Get the "name" */
if (r_ptr->flags1 & (RF1_GUARDIAN)) pre = "[G]";
else if (r_ptr->flags1 & (RF1_UNIQUE)) pre = "[U]";
else pre = "The";
strnfmt(nam, N_ELEMENTS(nam), "%s %.*v", pre,
N_ELEMENTS(nam)-strlen(pre)-1, monster_desc_aux_f3, r_ptr, 1, 0);
/* Level */
sprintf(lev, "%d", r_ptr->level);
/* Rarity */
sprintf(rar, "%d", r_ptr->rarity);
/* Speed */
if (r_ptr->speed >= 110)
{
sprintf(spd, "+%d", (r_ptr->speed - 110));
}
else
{
sprintf(spd, "-%d", (110 - r_ptr->speed));
}
/* Armor Class */
sprintf(ac, "%d", r_ptr->ac);
/* Hitpoints */
if ((r_ptr->flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
{
sprintf(hp, "%d", r_ptr->hdice * r_ptr->hside);
}
else
{
sprintf(hp, "%dd%d", r_ptr->hdice, r_ptr->hside);
}
/* Power */
sprintf(exp, "%ld", (long)(r_ptr->mexp));
/* Hack -- use visual instead */
sprintf(exp, "%s '%c'", attr_to_text(r_ptr->gfx.da), r_ptr->gfx.dc);
/* Dump the info */
fprintf(fff, "%-40.40s%4s%4s%6s%8s%4s %11.11s\n",
nam, lev, rar, spd, hp, ac, exp);
}
/* End it */
fprintf(fff, "\n");
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:scthangband,代码行数:101,代码来源:wizard1.c
示例2: do_autopickup
int do_autopickup(void)
{
int py = p_ptr->py;
int px = p_ptr->px;
s16b this_o_idx, next_o_idx = 0;
object_type *o_ptr;
/* Objects picked up. Used to determine time cost of command. */
byte objs_picked_up = 0;
size_t floor_num = 0;
int floor_list[MAX_FLOOR_STACK + 1];
/* Nothing to pick up -- return */
if (!cave->o_idx[py][px]) return (0);
/* Always pickup gold, effortlessly */
py_pickup_gold();
/* Scan the remaining objects */
for (this_o_idx = cave->o_idx[py][px]; this_o_idx; this_o_idx = next_o_idx)
{
/* Get the object and the next object */
o_ptr = object_byid(this_o_idx);
next_o_idx = o_ptr->next_o_idx;
/* Ignore all hidden objects and non-objects */
if (squelch_item_ok(o_ptr) || !o_ptr->kind) continue;
/* XXX Hack -- Enforce limit */
if (floor_num >= N_ELEMENTS(floor_list)) break;
/* Hack -- disturb */
disturb(0, 0);
/* Automatically pick up items into the backpack */
if (auto_pickup_okay(o_ptr))
{
/* Pick up the object with message */
py_pickup_aux(this_o_idx, TRUE);
objs_picked_up++;
continue;
}
/* Tally objects and store them in an array. */
/* Remember this object index */
floor_list[floor_num] = this_o_idx;
/* Count non-gold objects that remain on the floor. */
floor_num++;
}
return objs_picked_up;
}
开发者ID:eddiegrove,项目名称:angband,代码行数:62,代码来源:cmd1.c
示例3: effect_do
//.........这里部分代码省略.........
if (p_ptr->csp < p_ptr->msp)
{
p_ptr->csp = p_ptr->msp;
p_ptr->csp_frac = 0;
*ident = TRUE;
msg("Your feel your head clear.");
p_ptr->redraw |= (PR_MANA);
}
return TRUE;
}
case EF_STAFF_HOLY:
{
dam = 120 * (100 + boost) / 100;
if (dispel_evil(dam)) *ident = TRUE;
if (player_inc_timed(p_ptr, TMD_PROTEVIL, randint1(25) + 3 *
p_ptr->lev, TRUE, TRUE)) *ident = TRUE;
if (player_clear_timed(p_ptr, TMD_POISONED, TRUE)) *ident = TRUE;
if (player_clear_timed(p_ptr, TMD_AFRAID, TRUE)) *ident = TRUE;
if (hp_player(50)) *ident = TRUE;
if (player_clear_timed(p_ptr, TMD_STUN, TRUE)) *ident = TRUE;
if (player_clear_timed(p_ptr, TMD_CUT, TRUE)) *ident = TRUE;
return TRUE;
}
case EF_DRINK_BREATH:
{
const int breath_types[] =
{
GF_FIRE, 80,
GF_COLD, 80,
};
int which = 2 * randint0(N_ELEMENTS(breath_types) / 2);
fire_ball(breath_types[which], dir, breath_types[which + 1], 2);
*ident = TRUE;
return TRUE;
}
case EF_DRINK_GOOD:
{
msg("You feel less thirsty.");
*ident = TRUE;
return TRUE;
}
case EF_DRINK_DEATH:
{
msg("A feeling of Death flows through your body.");
take_hit(p_ptr, 5000, "a potion of Death");
*ident = TRUE;
return TRUE;
}
case EF_DRINK_RUIN:
{
msg("Your nerves and muscles feel weak and lifeless!");
take_hit(p_ptr, damroll(10, 10), "a potion of Ruination");
player_stat_dec(p_ptr, A_DEX, TRUE);
player_stat_dec(p_ptr, A_WIS, TRUE);
player_stat_dec(p_ptr, A_CON, TRUE);
player_stat_dec(p_ptr, A_STR, TRUE);
player_stat_dec(p_ptr, A_CHR, TRUE);
player_stat_dec(p_ptr, A_INT, TRUE);
*ident = TRUE;
return TRUE;
开发者ID:nomadicwriter,项目名称:v4,代码行数:67,代码来源:effects.c
示例4: N_ELEMENTS
static vbi_bool
filter_frame (const vbi_sliced * sliced_in,
unsigned int n_lines,
const uint8_t * raw,
const vbi_sampling_par *sp,
double sample_time,
int64_t stream_time)
{
vbi_sliced sliced_out[64];
vbi_sliced *s;
unsigned int n_lines_prev_in;
unsigned int n_lines_prev_out;
unsigned int n_lines_in;
unsigned int n_lines_out;
vbi_bool success;
raw = raw; /* unused */
sp = sp;
if (!started) {
option_start_time += sample_time;
option_end_time += sample_time;
started = TRUE;
}
if (sample_time < option_start_time
|| sample_time >= option_end_time)
return TRUE;
if (0 == n_lines)
return TRUE;
n_lines_prev_in = 0;
n_lines_prev_out = 0;
do {
const unsigned int max_lines_out = N_ELEMENTS (sliced_out);
n_lines_in = n_lines - n_lines_prev_in;
success = vbi_sliced_filter_cor
(sf,
sliced_out + n_lines_prev_out,
&n_lines_out,
max_lines_out - n_lines_prev_out,
sliced_in + n_lines_prev_in,
&n_lines_in);
if (success)
break;
error_msg (vbi_sliced_filter_errstr (sf));
if (option_abort_on_error) {
exit (EXIT_FAILURE);
}
/* Skip the consumed lines and the broken line. */
n_lines_prev_in += n_lines_in + 1;
n_lines_prev_out += n_lines_out;
} while (n_lines_prev_in < n_lines);
n_lines_in += n_lines_prev_in;
n_lines_out += n_lines_prev_out;
s = sliced_out;
if (0 == n_lines_out) {
if (0) {
/* Decoder may assume data loss without
continuous timestamps. */
s = &sliced_blank;
n_lines_out = 1;
} else {
return TRUE;
}
}
write_stream_sliced (wst, s, n_lines_out,
/* raw */ NULL,
/* sp */ NULL,
sample_time, stream_time);
return TRUE;
}
开发者ID:AndroNN,项目名称:libzvbi-obe-dev,代码行数:88,代码来源:ttxfilter.c
示例5: py_pickup
//.........这里部分代码省略.........
/* One object */
if (floor_num == 1) {
if (!can_pickup)
p = "have no room for";
else if (blind)
p = "feel";
/* Get the object */
o_ptr = &o_list[floor_o_idx];
/* Describe the object. Less detail if blind. */
if (blind)
object_desc(o_name, sizeof(o_name), o_ptr,
ODESC_PREFIX | ODESC_BASE);
else
object_desc(o_name, sizeof(o_name), o_ptr,
ODESC_PREFIX | ODESC_FULL);
/* Message */
message_flush();
msg("You %s %s.", p, o_name);
} else {
/* Display more information about floor items */
ui_event e;
if (!can_pickup)
p = "have no room for the following objects";
else if (blind)
p = "feel something on the floor";
/* Scan all marked objects in the grid */
floor_num =
scan_floor(floor_list, N_ELEMENTS(floor_list), y, x, 0x03);
/* Save screen */
screen_save();
/* Display objects on the floor */
show_floor(floor_list, floor_num, (OLIST_WEIGHT));
/* Display prompt */
prt(format("You %s: ", p), 0, 0);
/* Wait for it. Use key as next command. */
e = inkey_ex();
Term_event_push(&e);
/* Restore screen */
screen_load();
}
/* Done */
return (objs_picked_up);
}
/* We can pick up objects. Menus are not requested (yet). */
if (pickup == 1) {
/* Scan floor (again) */
floor_num =
scan_floor(floor_list, N_ELEMENTS(floor_list), y, x, 0x03);
/* Use a menu interface for multiple objects, or get single objects */
if (floor_num > 1)
pickup = 2;
else
开发者ID:NickMcConnell,项目名称:FAangband,代码行数:67,代码来源:cmd1.c
示例6: get_item
//.........这里部分代码省略.........
/* Full inventory */
i1 = 0;
i2 = INVEN_PACK - 1;
/* Forbid inventory */
if (!use_inven) i2 = -1;
/* Restrict inventory indexes */
while ((i1 <= i2) && (!get_item_okay(i1))) i1++;
while ((i1 <= i2) && (!get_item_okay(i2))) i2--;
/* Accept inventory */
if (i1 <= i2) allow_inven = TRUE;
/* Full equipment */
e1 = INVEN_WIELD;
e2 = ALL_INVEN_TOTAL - 1;
/* Forbid equipment */
if (!use_equip) e2 = -1;
/* Restrict equipment indexes */
while ((e1 <= e2) && (!get_item_okay(e1))) e1++;
while ((e1 <= e2) && (!get_item_okay(e2))) e2--;
/* Accept equipment */
if (e1 <= e2) allow_equip = TRUE;
/* Scan all non-gold objects in the grid */
floor_num = scan_floor(floor_list, N_ELEMENTS(floor_list), py, px, 0x03);
/* Full floor */
f1 = 0;
f2 = floor_num - 1;
/* Forbid floor */
if (!use_floor) f2 = -1;
/* Restrict floor indexes */
while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f1]))) f1++;
while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f2]))) f2--;
/* Accept floor */
if (f1 <= f2) allow_floor = TRUE;
/* Require at least one legal choice */
if (!allow_inven && !allow_equip && !allow_floor)
{
/* Oops */
oops = TRUE;
done = TRUE;
}
/* Analyze choices */
else
{
/* Hack -- Start on equipment if requested */
if ((p_ptr->command_wrk == USE_EQUIP) && allow_equip)
p_ptr->command_wrk = USE_EQUIP;
else if ((p_ptr->command_wrk == USE_INVEN) && allow_inven)
p_ptr->command_wrk = USE_INVEN;
开发者ID:ryz,项目名称:angband,代码行数:67,代码来源:obj-ui.c
示例7: malloc
struct lwan_fd_watch *lwan_watch_fd(struct lwan *l,
int fd,
uint32_t events,
coro_function_t coro_fn,
void *data)
{
struct lwan_fd_watch *watch;
watch = malloc(sizeof(*watch));
if (!watch)
return NULL;
watch->coro = coro_new(&l->switcher, coro_fn, data);
if (!watch->coro)
goto out;
struct epoll_event ev = {.events = events, .data.ptr = watch->coro};
if (epoll_ctl(l->epfd, EPOLL_CTL_ADD, fd, &ev) < 0) {
coro_free(watch->coro);
goto out;
}
watch->fd = fd;
return watch;
out:
free(watch);
return NULL;
}
void lwan_unwatch_fd(struct lwan *l, struct lwan_fd_watch *w)
{
if (l->main_socket != w->fd) {
if (epoll_ctl(l->epfd, EPOLL_CTL_DEL, w->fd, NULL) < 0)
lwan_status_perror("Could not unwatch fd %d", w->fd);
}
coro_free(w->coro);
free(w);
}
void lwan_main_loop(struct lwan *l)
{
struct epoll_event evs[16];
struct lwan_fd_watch *watch;
assert(main_socket == -1);
main_socket = l->main_socket;
if (signal(SIGINT, sigint_handler) == SIG_ERR)
lwan_status_critical("Could not set signal handler");
watch = lwan_watch_fd(l, l->main_socket, EPOLLIN | EPOLLHUP | EPOLLRDHUP,
accept_connection_coro, l);
if (!watch)
lwan_status_critical("Could not watch main socket");
lwan_status_info("Ready to serve");
while (true) {
int n_evs = epoll_wait(l->epfd, evs, N_ELEMENTS(evs), -1);
if (UNLIKELY(n_evs < 0)) {
if (main_socket < 0)
break;
if (errno == EINTR || errno == EAGAIN)
continue;
break;
}
for (int i = 0; i < n_evs; i++) {
if (!coro_resume_value(evs[i].data.ptr, (int)evs[i].events))
break;
}
}
lwan_unwatch_fd(l, watch);
}
#ifdef CLOCK_MONOTONIC_COARSE
__attribute__((constructor)) static void detect_fastest_monotonic_clock(void)
{
struct timespec ts;
if (!clock_gettime(CLOCK_MONOTONIC_COARSE, &ts))
monotonic_clock_id = CLOCK_MONOTONIC_COARSE;
}
#endif
void lwan_set_thread_name(const char *name)
{
char thread_name[16];
char process_name[PATH_MAX];
char *tmp;
int ret;
if (proc_pidpath(getpid(), process_name, sizeof(process_name)) < 0)
return;
tmp = strrchr(process_name, '/');
//.........这里部分代码省略.........
开发者ID:lpereira,项目名称:lwan,代码行数:101,代码来源:lwan.c
示例8: apply_magic
//.........这里部分代码省略.........
a_m_aux_3(o_ptr, lev, power);
break;
}
case TV_LIGHT:
{
if (power == 2 || power == -2)
make_ego_item(o_ptr, lev, (bool)(power > 0));
/* Fuel it */
a_m_aux_4(o_ptr, lev, power);
break;
}
default:
{
a_m_aux_4(o_ptr, lev, power);
break;
}
}
/* Hack -- analyze ego-items */
if (o_ptr->name2)
{
ego_item_type *e_ptr = &e_info[o_ptr->name2];
bitflag flags[OF_SIZE];
object_flags(o_ptr, flags);
/* Extra powers */
if (e_ptr->xtra == OBJECT_XTRA_TYPE_SUSTAIN)
of_on(o_ptr->flags, get_new_attr(flags, ego_sustains,
N_ELEMENTS(ego_sustains)));
else if (e_ptr->xtra == OBJECT_XTRA_TYPE_RESIST)
of_on(o_ptr->flags, get_new_attr(flags, ego_resists,
N_ELEMENTS(ego_resists)));
else if (e_ptr->xtra == OBJECT_XTRA_TYPE_POWER)
of_on(o_ptr->flags, get_new_attr(flags, ego_powers,
N_ELEMENTS(ego_powers)));
/* Hack -- acquire "cursed" flags */
if (cursed_p(e_ptr))
{
bitflag curse_flags[OF_SIZE];
of_copy(curse_flags, e_ptr->flags);
flags_mask(curse_flags, OF_SIZE, OF_CURSE_MASK, FLAG_END);
of_union(o_ptr->flags, curse_flags);
}
/* Hack -- apply extra penalties if needed */
if (cursed_p(o_ptr))
{
/* Apply extra ego bonuses */
o_ptr->to_h -= randcalc(e_ptr->to_h, lev, RANDOMISE);
o_ptr->to_d -= randcalc(e_ptr->to_d, lev, RANDOMISE);
o_ptr->to_a -= randcalc(e_ptr->to_a, lev, RANDOMISE);
/* Apply ego pval */
o_ptr->pval -= randcalc(e_ptr->pval, lev, RANDOMISE);
/* Apply minimums */
if (o_ptr->to_h > -1 * e_ptr->min_to_h) o_ptr->to_h = -1 * e_ptr->min_to_h;
if (o_ptr->to_d > -1 * e_ptr->min_to_d) o_ptr->to_d = -1 * e_ptr->min_to_d;
if (o_ptr->to_a > -1 * e_ptr->min_to_a) o_ptr->to_a = -1 * e_ptr->min_to_a;
开发者ID:cinereaste,项目名称:angband,代码行数:67,代码来源:obj-make.c
示例9: main
//.........这里部分代码省略.........
mstr = arg;
continue;
#ifdef SOUND
case 's':
if (!*arg) goto usage;
soundstr = arg;
continue;
#endif
case 'd':
change_path(arg);
continue;
case 'x':
debug_opt(arg);
continue;
case '-':
argv[i] = argv[0];
argc = argc - i;
argv = argv + i;
args = false;
break;
default:
usage:
puts("Usage: angband [options] [-- subopts]");
puts(" -n Start a new character (WARNING: overwrites default savefile without -u)");
puts(" -l Lists all savefiles you can play");
puts(" -w Resurrect dead character (marks savefile)");
puts(" -g Request graphics mode");
puts(" -x<opt> Debug options; see -xhelp");
puts(" -u<who> Use your <who> savefile");
puts(" -d<dir>=<path> Override a specific directory with <path>. <path> can be:");
for (i = 0; i < (int)N_ELEMENTS(change_path_values); i++) {
#ifdef SETGID
if (!change_path_values[i].setgid_ok) continue;
#endif
printf(" %s (default is %s)\n", change_path_values[i].name, *change_path_values[i].path);
}
puts(" Multiple -d options are allowed.");
#ifdef SOUND
puts(" -s<mod> Use sound module <sys>:");
print_sound_help();
#endif
puts(" -m<sys> Use module <sys>, where <sys> can be:");
/* Print the name and help for each available module */
for (i = 0; i < (int)N_ELEMENTS(modules); i++)
printf(" %s %s\n",
modules[i].name, modules[i].help);
/* Actually abort the process */
quit(NULL);
}
if (*arg) goto usage;
}
/* Hack -- Forget standard args */
if (args) {
argc = 1;
argv[1] = NULL;
}
/* Install "quit" hook */
quit_aux = quit_hook;
开发者ID:NickMcConnell,项目名称:angband,代码行数:66,代码来源:main.c
示例10: py_attack_real
/**
* Attack the monster at the given location with a single blow.
*/
static bool py_attack_real(int y, int x, bool *fear) {
size_t i;
/* Information about the target of the attack */
monster_type *m_ptr = cave_monster_at(cave, y, x);
char m_name[80];
bool stop = FALSE;
/* The weapon used */
object_type *o_ptr = &p_ptr->inventory[INVEN_WIELD];
/* Information about the attack */
int bonus = p_ptr->state.to_h + o_ptr->to_h;
int chance = p_ptr->state.skills[SKILL_TO_HIT_MELEE] + bonus * BTH_PLUS_ADJ;
bool do_quake = FALSE;
bool success = FALSE;
/* Default to punching for one damage */
const char *hit_verb = "punch";
int dmg = 1;
u32b msg_type = MSG_HIT;
/* Extract monster name (or "it") */
monster_desc(m_name, sizeof(m_name), m_ptr, 0);
/* Auto-Recall if possible and visible */
if (m_ptr->ml) monster_race_track(m_ptr->race);
/* Track a new monster */
if (m_ptr->ml) health_track(p_ptr, m_ptr);
/* Handle player fear (only for invisible monsters) */
if (check_state(p_ptr, OF_AFRAID, p_ptr->state.flags)) {
msgt(MSG_AFRAID, "You are too afraid to attack %s!", m_name);
return FALSE;
}
/* Disturb the monster */
mon_clear_timed(m_ptr, MON_TMD_SLEEP, MON_TMD_FLG_NOMESSAGE, FALSE);
/* See if the player hit */
success = test_hit(chance, m_ptr->race->ac, m_ptr->ml);
/* If a miss, skip this hit */
if (!success) {
msgt(MSG_MISS, "You miss %s.", m_name);
return FALSE;
}
/* Handle normal weapon */
if (o_ptr->kind) {
const struct slay *best_s_ptr = NULL;
hit_verb = "hit";
/* Get the best attack from all slays or
* brands on all non-launcher equipment */
for (i = INVEN_LEFT; i < INVEN_TOTAL; i++) {
struct object *obj = &p_ptr->inventory[i];
if (obj->kind)
improve_attack_modifier(obj, m_ptr, &best_s_ptr, TRUE, FALSE);
}
improve_attack_modifier(o_ptr, m_ptr, &best_s_ptr, TRUE, FALSE);
if (best_s_ptr != NULL)
hit_verb = best_s_ptr->melee_verb;
dmg = damroll(o_ptr->dd, o_ptr->ds);
dmg *= (best_s_ptr == NULL) ? 1 : best_s_ptr->mult;
dmg += o_ptr->to_d;
dmg = critical_norm(o_ptr->weight, o_ptr->to_h, dmg, &msg_type);
/* Learn by use for the weapon */
object_notice_attack_plusses(o_ptr);
if (check_state(p_ptr, OF_IMPACT, p_ptr->state.flags) && dmg > 50) {
do_quake = TRUE;
wieldeds_notice_flag(p_ptr, OF_IMPACT);
}
}
/* Learn by use for other equipped items */
wieldeds_notice_on_attack();
/* Apply the player damage bonuses */
dmg += p_ptr->state.to_d;
/* No negative damage; change verb if no damage done */
if (dmg <= 0) {
dmg = 0;
msg_type = MSG_MISS;
hit_verb = "fail to harm";
}
for (i = 0; i < N_ELEMENTS(melee_hit_types); i++) {
const char *dmg_text = "";
//.........这里部分代码省略.........
开发者ID:creidieki,项目名称:angband,代码行数:101,代码来源:attack.c
示例11: ranged_helper
//.........这里部分代码省略.........
Term_fresh();
if (p_ptr->redraw) redraw_stuff(p_ptr);
} else {
/* Delay anyway for consistency */
Term_xtra(TERM_XTRA_DELAY, msec);
}
/* Handle monster */
if (cave->m_idx[y][x] > 0) break;
}
/* Try the attack on the monster at (x, y) if any */
if (cave->m_idx[y][x] > 0) {
monster_type *m_ptr = cave_monster_at(cave, y, x);
int visible = m_ptr->ml;
bool fear = FALSE;
char m_name[80];
const char *note_dies = monster_is_unusual(m_ptr->race) ? " is destroyed." : " dies.";
struct attack_result result = attack(o_ptr, y, x);
int dmg = result.dmg;
u32b msg_type = result.msg_type;
const char *hit_verb = result.hit_verb;
if (result.success) {
hit_target = TRUE;
/* Get "the monster" or "it" */
monster_desc(m_name, sizeof(m_name), m_ptr, 0);
object_notice_attack_plusses(o_ptr);
/* Learn by use for other equipped items */
wieldeds_notice_to_hit_on_attack();
/* No negative damage; change verb if no damage done */
if (dmg <= 0) {
dmg = 0;
msg_type = MSG_MISS;
hit_verb = "fail to harm";
}
if (!visible) {
/* Invisible monster */
msgt(MSG_SHOOT_HIT, "The %s finds a mark.", o_name);
} else {
for (i = 0; i < (int)N_ELEMENTS(ranged_hit_types); i++) {
const char *dmg_text = "";
if (msg_type != ranged_hit_types[i].msg)
continue;
if (OPT(show_damage))
dmg_text = format(" (%d)", dmg);
if (ranged_hit_types[i].text)
msgt(msg_type, "Your %s %s %s%s. %s", o_name, hit_verb,
m_name, dmg_text, ranged_hit_types[i].text);
else
msgt(msg_type, "Your %s %s %s%s.", o_name, hit_verb,
m_name, dmg_text);
}
/* Track this monster */
if (m_ptr->ml) monster_race_track(m_ptr->race);
if (m_ptr->ml) health_track(p_ptr, m_ptr);
}
/* Hit the monster, check for death */
if (!mon_take_hit(m_ptr, dmg, &fear, note_dies)) {
message_pain(m_ptr, dmg);
if (fear && m_ptr->ml)
add_monster_message(m_name, m_ptr, MON_MSG_FLEE_IN_TERROR, TRUE);
}
}
}
/* Obtain a local object */
object_copy(i_ptr, o_ptr);
object_split(i_ptr, o_ptr, 1);
/* See if the ammunition broke or not */
j = breakage_chance(i_ptr, hit_target);
/* Drop (or break) near that location */
drop_near(cave, i_ptr, j, y, x, TRUE);
if (item >= 0) {
/* The ammo is from the inventory */
inven_item_increase(item, -1);
inven_item_describe(item);
inven_item_optimize(item);
} else {
/* The ammo is from the floor */
floor_item_increase(0 - item, -1);
floor_item_optimize(0 - item);
}
}
开发者ID:creidieki,项目名称:angband,代码行数:101,代码来源:attack.c
示例12: context_menu_command
int context_menu_command(int mx, int my)
{
menu_type *m;
region r;
int selected;
m = menu_dynamic_new();
if (!m) {
return 0;
}
m->selections = lower_case;
menu_dynamic_add(m, "Item", 1);
menu_dynamic_add(m, "Action", 2);
menu_dynamic_add(m, "Item Management", 3);
menu_dynamic_add(m, "Info", 4);
menu_dynamic_add(m, "Util", 5);
menu_dynamic_add(m, "Misc", 6);
/* work out display region */
r.width = menu_dynamic_longest_entry(m) + 3 + 2; /* +3 for tag, 2 for pad */
if (mx > Term->wid - r.width - 1) {
r.col = Term->wid - r.width - 1;
} else {
r.col = mx + 1;
}
r.page_rows = m->count;
if (my > Term->hgt - r.page_rows - 1) {
if (my - r.page_rows - 1 <= 0) {
/* menu has too many items, so put in upper right corner */
r.row = 1;
r.col = Term->wid - r.width - 1;
} else {
r.row = Term->hgt - r.page_rows - 1;
}
} else {
r.row = my + 1;
}
screen_save();
menu_layout(m, &r);
region_erase_bordered(&r);
prt("(Enter to select, ESC) Command:", 0, 0);
selected = menu_dynamic_select(m);
menu_dynamic_free(m);
screen_load();
switch (selected) {
case 1:
show_command_list(cmd_item, N_ELEMENTS(cmd_item), mx, my);
break;
case 2:
show_command_list(cmd_action, N_ELEMENTS(cmd_action), mx, my);
break;
case 3:
show_command_list(cmd_item_manage, N_ELEMENTS(cmd_item_manage), mx, my);
break;
case 4:
show_command_list(cmd_info, N_ELEMENTS(cmd_info), mx, my);
break;
case 5:
show_command_list(cmd_util, N_ELEMENTS(cmd_util), mx, my);
break;
case 6:
show_command_list(cmd_hidden, N_ELEMENTS(cmd_hidden), mx, my);
break;
}
return 1;
}
开发者ID:KertaLosataure,项目名称:angband,代码行数:72,代码来源:cmd-process.c
示例13: N_ELEMENTS
/*
* A categorised list of all the command lists.
*/
typedef struct
{
const char *name;
struct cmd_info *list;
size_t len;
} command_list;
static command_list cmds_all[] =
{
{ "Items", cmd_item, N_ELEMENTS(cmd_item) },
{ "Action commands", cmd_action, N_ELEMENTS(cmd_action) },
{ "Manage items", cmd_item_manage, N_ELEMENTS(cmd_item_manage) },
{ "Information", cmd_info, N_ELEMENTS(cmd_info) },
{ "Utility", cmd_util, N_ELEMENTS(cmd_util) },
{ "Hidden", cmd_hidden, N_ELEMENTS(cmd_hidden) }
};
/*** Menu functions ***/
/* Display an entry on a command menu */
static void cmd_sub_entry(menu_type *menu, int oid, bool cursor, int row, int col, int width)
{
开发者ID:KertaLosataure,项目名称:angband,代码行数:28,代码来源:cmd-process.c
示例14: vaapiFillPicture
bool VaapiDecoderH264::fillPicture(VaapiPictureH264 * picture,
H264SliceHdr * sliceHdr,
H264NalUnit * nalu)
{
uint32_t i, n;
H264PPS *const pps = picture->m_pps;
H264SPS *const sps = pps->sequence;
VaapiDecPicBufLayer *DPBLayer = m_DPBManager->DPBLayer;
VaapiBufObject *picParamObj = picture->m_picParam;
VAPictureParameterBufferH264 *picParam =
(VAPictureParameterBufferH264 *) picParamObj->map();
/* Fill in VAPictureParameterBufferH264 */
vaapiFillPicture(&picParam->CurrPic, picture, 0);
for (i = 0, n = 0; i < DPBLayer->DPBCount; i++) {
VaapiFrameStore *const frameStore = DPBLayer->DPB[i];
if (frameStore && frameStore->hasReference())
vaapiFillPicture(&picParam->ReferenceFrames[n++],
frameStore->m_buffers[0],
frameStore->m_structure);
}
for (; n < N_ELEMENTS(picParam->ReferenceFrames); n++)
vaapiInitPicture(&picParam->ReferenceFrames[n]);
#define COPY_FIELD(s, f) \
picParam->f = (s)->f
#define COPY_BFM(a, s, f) \
picParam->a.bits.f = (s)->f
picParam->picture_width_in_mbs_minus1 = m_mbWidth - 1;
picParam->picture_height_in_mbs_minus1 = m_mbHeight - 1;
picParam->frame_num = m_frameNum;
COPY_FIELD(sps, bit_depth_luma_minus8);
COPY_FIELD(sps, bit_depth_chroma_minus8);
COPY_FIELD(sps, num_ref_frames);
COPY_FIELD(pps, num_slice_groups_minus1);
COPY_FIELD(pps, slice_group_map_type);
COPY_FIELD(pps, slice_group_change_rate_minus1);
COPY_FIELD(pps, pic_init_qp_minus26);
COPY_FIELD(pps, pic_init_qs_minus26);
COPY_FIELD(pps, chroma_qp_index_offset);
COPY_FIELD(pps, second_chroma_qp_index_offset);
picParam->seq_fields.value = 0; /* reset all bits */
picParam->seq_fields.bits.residual_colour_transform_flag =
sps->separate_colour_plane_flag;
picParam->seq_fields.bits.MinLumaBiPredSize8x8 = sps->level_idc >= 31; /* A.3.3.2 */
COPY_BFM(seq_fields, sps, chroma_format_idc);
COPY_BFM(seq_fields, sps, gaps_in_frame_num_value_allowed_flag);
COPY_BFM(seq_fields, sps, frame_mbs_only_flag);
COPY_BFM(seq_fields, sps, mb_adaptive_frame_field_flag);
COPY_BFM(seq_fields, sps, direct_8x8_inference_flag);
COPY_BFM(seq_fields, sps, log2_max_frame_num_minus4);
COPY_BFM(seq_fields, sps, pic_order_cnt_type);
COPY_BFM(seq_fields, sps, log2_max_pic_order_cnt_lsb_minus4);
COPY_BFM(seq_fields, sps, delta_pic_order_always_zero_flag);
picParam->pic_fields.value = 0; /* reset all bits */
picParam->pic_fields.bits.field_pic_flag = sliceHdr->field_pic_flag;
picParam->pic_fields.bits.reference_pic_flag =
VAAPI_PICTURE_IS_REFERENCE(picture);
COPY_BFM(pic_fields, pps, entropy_coding_mode_flag);
COPY_BFM(pic_fields, pps, weighted_pred_flag);
COPY_BFM(pic_fields, pps, weighted_bipred_idc);
COPY_BFM(pic_fields, pps, transform_8x8_mode_flag);
COPY_BFM(pic_fields, pps, constrained_intra_pred_flag);
COPY_BFM(pic_fields, pps, pic_order_present_flag);
COPY_BFM(pic_fields, pps, deblocking_filter_control_present_flag);
COPY_BFM(pic_fields, pps, redundant_pic_cnt_present_flag);
picParamObj->unmap();
return true;
}
开发者ID:zhongcong,项目名称:libyami-private,代码行数:80,代码来源:vaapidecoder_h264.cpp
示例15: mail_transaction_log_file_get_modseq_next_offset
int mail_transaction_log_file_get_modseq_next_offset(
struct mail_transaction_log_file *file,
uint64_t modseq, uoff_t *next_offset_r)
{
const struct mail_transaction_header *hdr;
struct modseq_cache *cache;
uoff_t cur_offset;
uint64_t cur_modseq;
int ret;
if (modseq >= file->sync_highest_modseq) {
*next_offset_r = file->sync_offset;
return 0;
}
if (modseq == file->hdr.initial_modseq) {
*next_offset_r = file->hdr.hdr_size;
return 0;
}
cache = modseq_cache_get_modseq(file, modseq);
if (cache == NULL) {
/* nothing usable in cache - scan from beginning */
cur_offset = file->hdr.hdr_size;
cur_modseq = file->hdr.initial_modseq;
} else if (cache->highest_modseq == modseq) {
/* exact cache hit */
*next_offset_r = cache->offset;
return 0;
} else {
/* use cache to skip over some records */
cur_offset = cache->offset;
cur_modseq = cache->highest_modseq;
}
ret = mail_transaction_log_file_map(file, cur_offset,
file->sync_offset);
if (ret <= 0) {
if (ret < 0)
return -1;
mail_index_set_error(file->log->index,
"%s: Transaction log corrupted, can't get modseq",
file->filepath);
return -1;
}
i_assert(cur_offset >= file->buffer_offset);
while (cur_offset < file->sync_offset) {
if (log_get_synced_record(file, &cur_offset, &hdr) < 0)
return -1;
mail_transaction_update_modseq(hdr, hdr + 1, &cur_modseq);
if (cur_modseq >= modseq)
break;
}
if (cur_offset == file->sync_offset) {
/* if we got to sync_offset, cur_modseq should be
sync_highest_modseq */
mail_index_set_error(file->log->index,
"%s: Transaction log changed unexpectedly, "
"can't get modseq", file->filepath);
return -1;
}
/* @UNSAFE: cache the value */
memmove(file->modseq_cache + 1, file->modseq_cache,
sizeof(*file->modseq_cache) *
(N_ELEMENTS(file->modseq_cache) - 1));
file->modseq_cache[0].offset = cur_offset;
file->modseq_cache[0].highest_modseq = cur_modseq;
*next_offset_r = cur_offset;
return 0;
}
开发者ID:IvanKharpalev,项目名称:core,代码行数:72,代码来源:mail-transaction-log-file.c
示例16: mail_send_rejection
//.........这里部分代码省略.........
i_debug("Sending a rejection to %s: %s", recipient,
str_sanitize(reason, 512));
}
smtp_client = smtp_client_open(ctx->set, return_addr, NULL, &output);
msgid = mail_deliver_get_new_message_id(ctx);
boundary = t_strdup_printf("%s/%s", my_pid, ctx->set->hostname);
str = t_str_new(512);
str_printfa(str, "Message-ID: %s\r\n", msgid);
str_printfa(str, "Date: %s\r\n", message_date_create(ioloop_time));
str_printfa(str, "From: Mail Delivery Subsystem <%s>\r\n",
ctx->set->postmaster_address);
str_printfa(str, "To: <%s>\r\n", return_addr);
str_append(str, "MIME-Version: 1.0\r\n");
str_printfa(str, "Content-Type: "
"multipart/report; report-type=%s;\r\n"
"\tboundary=\"%s\"\r\n",
ctx->dsn ? "delivery-status" : "disposition-notification",
boundary);
str_append(str, "Subject: ");
var_expand(str, ctx->set->rejection_subject,
get_var_expand_table(mail, reason, recipient));
str_append(str, "\r\n");
str_append(str, "Auto-Submitted: auto-replied (rejected)\r\n");
str_append(str, "Precedence: bulk\r\n");
str_append(str, "\r\nThis is a MIME-encapsulated message\r\n\r\n");
/* human readable status report */
str_printfa(str, "--%s\r\n", boundary);
str_append(str, "Content-Type: text/plain; charset=utf-8\r\n");
str_append(str, "Content-Disposition: inline\r\n");
str_append(str, "Content-Transfer-Encoding: 8bit\r\n\r\n");
var_expand(str, ctx->set->rejection_reason,
get_var_expand_table(mail, reason, recipient));
str_append(str, "\r\n");
if (ctx->dsn) {
/* DSN status report: For LDA rejects. currently only used when
user is out of quota */
str_printfa(str, "--%s\r\n"
"Content-Type: message/delivery-status\r\n\r\n",
boundary);
str_printfa(str, "Reporting-MTA: dns; %s\r\n", ctx->set->hostname);
if (mail_get_first_header(mail, "Original-Recipient", &hdr) > 0)
str_printfa(str, "Original-Recipient: rfc822; %s\r\n", hdr);
str_printfa(str, "Final-Recipient: rfc822; %s\r\n", recipient);
str_append(str, "Action: failed\r\n");
str_printfa(str, "Status: %s\r\n", ctx->mailbox_full ? "5.2.2" : "5.2.0");
} else {
/* MDN status report: For Sieve "reject" */
str_printfa(str, "--%s\r\n"
"Content-Type: message/disposition-notification\r\n\r\n",
boundary);
str_printfa(str, "Reporting-UA: %s; Dovecot Mail Delivery Agent\r\n",
ctx->set->hostname);
if (mail_get_first_header(mail, "Original-Recipient", &hdr) > 0)
str_printfa(str, "Original-Recipient: rfc822; %s\r\n", hdr);
str_printfa(str, "Final-Recipient: rfc822; %s\r\n", recipient);
if (orig_msgid != NULL)
str_printfa(str, "Original-Message-ID: %s\r\n", orig_msgid);
str_append(str, "Disposition: "
"automatic-action/MDN-sent-automatically; deleted\r\n");
}
str_append(str, "\r\n");
/* original message's headers */
str_printfa(str, "--%s\r\nContent-Type: message/rfc822\r\n\r\n", boundary);
o_stream_nsend(output, str_data(str), str_len(str));
if (mail_get_hdr_stream(mail, NULL, &input) == 0) {
/* Note: If you add more headers, they need to be sorted.
We'll drop Content-Type because we're not including the message
body, and having a multipart Content-Type may confuse some
MIME parsers when they don't see the message boundaries. */
static const char *const exclude_headers[] = {
"Content-Type"
};
input = i_stream_create_header_filter(input,
HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR |
HEADER_FILTER_HIDE_BODY, exclude_headers,
N_ELEMENTS(exclude_headers),
*null_header_filter_callback, (void *)NULL);
ret = o_stream_send_istream(output, input);
i_stream_unref(&input);
i_assert(ret != 0);
}
str_truncate(str, 0);
str_printfa(str, "\r\n\r\n--%s--\r\n", boundary);
o_stream_nsend(output, str_data(str), str_len(str));
return smtp_client_close(smtp_client);
}
开发者ID:dhultin,项目名称:dovecot-pop-uidl-proxy,代码行数:101,代码来源:mail-send.c
示例17: show_obj_list
/*
* Display a list of objects. Each object may be prefixed with a label.
* Used by show_inven(), show_equip(), and show_floor(). Mode flags are
* documented in object.h
*/
static void show_obj_list(int num_obj, int num_head, char labels[50][80],
object_type *objects[50], olist_detail_t mode)
{
int i, row = 0, col = 0;
int attr;
size_t max_len = 0;
int ex_width = 0, ex_offset, ex_offset_ctr;
object_type *o_ptr;
char o_name[50][80];
char tmp_val[80];
bool in_term;
in_term = (mode & OLIST_WINDOW) ? TRUE : FALSE;
if (in_term) max_len = 40;
/* Calculate name offset and max name length */
for (i = 0; i < num_obj; i++)
{
o_ptr = objects[i];
/* Null objects are used to skip lines, or display only a label */
if (!o_ptr || !o_ptr->kind)
{
if (i < num_head)
strnfmt(o_name[i], sizeof(o_name[i]), "");
else
strnfmt(o_name[i], sizeof(o_name[i]), "(nothing)");
}
else
object_desc(o_name[i], sizeof(o_name[i]), o_ptr, ODESC_PREFIX | ODESC_FULL);
/* Max length of label + object name */
max_len = MAX(max_len, strlen(labels[i]) + strlen(o_name[i]));
}
/* Take the quiver message into consideration */
if (mode & OLIST_QUIVER && p_ptr->quiver_slots > 0)
max_len = MAX(max_len, 24);
/* Width of extra fields */
if (mode & OLIST_WEIGHT) ex_width += 9;
if (mode & OLIST_PRICE) ex_width += 9;
if (mode & OLIST_FAIL) ex_width += 10;
/* Determine beginning row and column */
if (in_term)
{
/* Term window */
row = 0;
col = 0;
}
else
{
/* Main window */
row = 1;
col = Term->wid - 1 - max_len - ex_width;
if (col < 3) col = 0;
}
/* Column offset of the first extra field */
ex_offset = MIN(max_len, (size_t)(Term->wid - 1 - ex_width - col));
/* Output the list */
for (i = 0; i < num_obj; i++)
{
o_ptr = objects[i];
/* Clear the line */
prt("", row + i, MAX(col - 2, 0));
/* If we have no label then we won't display anything */
if (!strlen(labels[i])) continue;
/* Print the label */
put_str(labels[i], row + i, col);
/* Limit object name */
if (strlen(labels[i]) + strlen(o_name[i]) > (size_t)ex_offset)
{
int truncate = ex_offset - strlen(labels[i]);
if (truncate < 0) truncate = 0;
if ((size_t)truncate > sizeof(o_name[i]) - 1) truncate = sizeof(o_name[i]) - 1;
o_name[i][truncate] = '\0';
}
/* Item kind determines the color of the output */
if (o_ptr && o_ptr->kind)
attr = tval_to_attr[o_ptr->tval % N_ELEMENTS(tval_to_attr)];
else
//.........这里部分代码省略.........
开发者ID:ryz,项目名称:angband,代码行数:101,代码来源:obj-ui.c
示例18: DENTRY
bool CSTmHDMI::StartV29PHY(const stm_mode_line_t *const pModeLine, ULONG tvStandard)
{
DENTRY();
/*
* We have arranged in the chip specific PreConfiguration for the input
* clock to the PHY PLL to be the normal TMDS clock for 24bit colour, taking
* into account pixel repetition. We have been passed a modeline where the
* pixelclock parameter is in fact that TMDS clock in the case of the
* pixel doubled/quadded modes.
*/
ULONG ckpxpll = pModeLine->TimingParams.ulPixelClock;
ULONG tmdsck;
ULONG freqvco;
ULONG pllctrl = 0;
unsigned i;
switch(m_ulOutputFormat & STM_VIDEO_OUT_HDMI_COLOURDEPTH_MASK)
{
case STM_VIDEO_OUT_HDMI_COLOURDEPTH_30BIT:
tmdsck = (ckpxpll * 5) / 4; // 1.25x
pllctrl = (5 << STM_HDMI_SRZ_PLL_CFG_NDIV_SHIFT) | STM_HDMI_SRZ_PLL_CFG_SEL_12P5;
m_ulDeepcolourGCP = STM_HDMI_GENCTRL_PKT_COLORDEPTH_30BIT;
DEBUGF2(2,("%s: Selected 30bit colour\n",__PRETTY_FUNCTION__));
break;
case STM_VIDEO_OUT_HDMI_COLOURDEPTH_36BIT:
|
请发表评论