/** * dump struct data * @param symbol struct variable * @param position position of the struct in the array, or zero */ int dump_struct (SYMBOL *symbol, int position) { int dumped_bytes = 0; int i, number_of_members, value; number_of_members = tag_table[symbol->tagidx].number_of_members; for (i = 0; i < number_of_members; i++) { // i is the index of current member, get type int member_type = member_table[tag_table[symbol->tagidx].member_idx + i].type; if (member_type == CCHAR || member_type == CUCHAR) { defbyte(); dumped_bytes += 1; } else { /* XXX: compound types? */ defword(); dumped_bytes += 2; } if (position < get_size(symbol->name)) { // dump data value = get_item_at(symbol->name, position * number_of_members + i, &tag_table[symbol->tagidx]); outdec(value); } else { // dump zero, no more data available outdec(0); } nl(); } return (dumped_bytes); }
void do_player_pickup(int x, int y) { int num_items = count_items_at(current_dungeon, x, y); if (num_items == 0) { append_msg_log("No items here."); return; } if (num_items == 1) { if (_full_inventory()) { append_msg_log("Your inventory is full."); return; } item_t* item = get_item_at(current_dungeon, x, y); if (in_shop()) { if (buy_item(item)) { _pickup(item, SINGLE_ITEM); } } else { _pickup(item, WHOLE_STACK); } } else { std::vector<item_t*> items = _do_multi_pickup(x, y); for (auto it = items.begin(); it != items.end(); ++it) { if (_full_inventory()) { append_msg_log("Your inventory is full."); return; } if (in_shop()) { if (buy_item(*it)) { _pickup(*it, SINGLE_ITEM); } } else { _pickup(*it, WHOLE_STACK); } } } player.ap -= PICKUP_COST; }
/** * dump all static variables */ void dumpglbs(void) { int dim, i, list_size, line_count, value; if (!glbflag) return; current_symbol_table_idx = rglobal_table_index; while (current_symbol_table_idx < global_table_index) { SYMBOL *symbol = &symbol_table[current_symbol_table_idx]; if (symbol->identity != FUNCTION) { ppubext(symbol); if (symbol->storage != EXTERN) { output_string(symbol->name); output_label_terminator(); dim = symbol->offset; list_size = 0; line_count = 0; if (find_symbol_initials(symbol->name)) { // has initials list_size = get_size(symbol->name); if (dim == -1) { dim = list_size; } } for (i=0; i<dim; i++) { if (symbol->type == STRUCT) { dump_struct(symbol, i); } else { if (line_count % 10 == 0) { newline(); if ((symbol->type & CINT) || (symbol->identity == POINTER)) { gen_def_word(); } else { gen_def_byte(); } } if (i < list_size) { // dump data value = get_item_at(symbol->name, i, &tag_table[symbol->tagidx]); output_number(value); } else { // dump zero, no more data available output_number(0); } line_count++; if (line_count % 10 == 0) { line_count = 0; } else { if (i < dim-1) { output_byte( ',' ); } } } } newline(); } } else { fpubext(symbol); } current_symbol_table_idx++; } }
void CCreature::pick() { int i, j; CItem * item; bool picked; int nb; for (j = 0; j < get_item_count_at(x, y); j++) { picked = false; item = get_item_at(x, y, j); nb = item->get_entity_nb (); if (nb == EMERALD || nb == SAPHIR || nb == RUBIS) { item->use(this); item->unmap(x, y); delete item; continue; } else { for (i = 0; i < 24; i++) if (inventory[i] && inventory[i]->get_entity_nb () == nb) { inventory[i]->count += item->count; item->unmap(x, y); delete item; picked = true; break; } } if (!picked) for (i = 0; i < 24; i++) if (!inventory[i]) { inventory[i] = item; item->unmap(x, y); break; } } }
/** * dump struct data * @param symbol struct variable * @param position position of the struct in the array, or zero */ void dump_struct(SYMBOL *symbol, int position) { int i, number_of_members, value; number_of_members = tag_table[symbol->tagidx].number_of_members; newline(); for (i=0; i<number_of_members; i++) { // i is the index of current member, get type int member_type = member_table[tag_table[symbol->tagidx].member_idx + i].type; if (member_type & CINT) { gen_def_word(); } else { gen_def_byte(); } if (position < get_size(symbol->name)) { // dump data value = get_item_at(symbol->name, position*number_of_members+i, &tag_table[symbol->tagidx]); output_number(value); } else { // dump zero, no more data available output_number(0); } newline(); } }
/* * dump all static variables */ void dumpglbs (void) { long i = 1; int dim, list_size, line_count; int j; FILE *save = output; if (!data) data = fmemopen(data_buf, DATABUFSIZE, "w"); if (!rodata) rodata = fmemopen(rodata_buf, DATABUFSIZE, "w"); /* This is done in several passes: Pass 0: Dump initialization data into const bank. Pass 1: Define space for uninitialized data. Pass 2: Define space for initialized data. */ if (glbflag) { int pass = 0; next: i = 1; for (cptr = rglbptr; cptr < glbptr; cptr++) { if (cptr->ident != FUNCTION) { // ppubext(cptr); if ((cptr->storage & WRITTEN) == 0 && /* Not yet written to file */ cptr->storage != EXTERN) { dim = cptr->offset; if (find_symbol_initials(cptr->name)) { // has initials /* dump initialization data */ if (pass == 1) /* initialized data not handled in pass 1 */ continue; else if (pass == 2) { /* define space for initialized data */ output = data; if (cptr->storage != LSTATIC) prefix(); outstr(cptr->name); outstr(":\t"); defstorage(); outdec(cptr->size); nl(); cptr->storage |= WRITTEN; output = save; continue; } /* output initialization data into const bank */ output = rodata; have_init_data = 1; list_size = 0; line_count = 0; list_size = get_size(cptr->name); if (cptr->type == CSTRUCT) list_size /= tag_table[cptr->tagidx].number_of_members; if (dim == -1) dim = list_size; int item; /* dim is an item count for non-compound types and a byte size for compound types; dump_struct() wants an item number, so we have to count both to get the right members out. */ for (j = item = 0; j < dim; j++, item++) { if (cptr->type == CSTRUCT) j += dump_struct(cptr, item) - 1; else { if (line_count % 10 == 0) { nl(); if (cptr->type == CCHAR || cptr->type == CUCHAR) defbyte(); else defword(); } if (j < list_size) { // dump data int value = get_item_at(cptr->name, j, &tag_table[cptr->tagidx]); outdec(value); } else { // dump zero, no more data available outdec(0); } line_count++; if (line_count % 10 == 0) line_count = 0; else { if (j < dim - 1) outbyte(','); } } } nl(); output = save; } else { if (pass == 0) continue; /* define space in bss */ if (i) { i = 0; nl(); gdata(); } if (cptr->storage != LSTATIC) prefix(); outstr(cptr->name); outstr(":\t"); defstorage(); outdec(cptr->size); nl(); cptr->storage |= WRITTEN; } } } else { // fpubext(cptr); } } if (++pass < 3) goto next; } if (i) { nl(); gdata(); } output = save; }