Inventory::Inventory(int in_size) : items(in_size, nullptr), size(in_size) { set_item(0, pickaxe, 1); set_item(1, iid_dirt_block, 10); }
int main(){ Item* listptr; int i; listptr = new_item(0); for (i=1; i < 6; i++){ listptr=insert_front(listptr, i); } for (i=0; i < 6; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } listptr = remove_item(listptr, 3); for (i=0; i <= 5; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } printf("Index for 3 %d\n", get_index(listptr, 3)); for (i=1; i < 6; i++){ listptr=insert_back(listptr, i); } for (i=0; i < 12; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } set_item(listptr, 9, 15); for (i=0; i < 12; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } set_item(listptr, 10, 15); free_all(listptr); }
static void bug_14741() { zzz_type c = make_container ("bug_14741"); add_item (&c, 71); set_item(&c, 0, 42); /* breakpoint bug 14741 */ set_item(&c, 0, 5); }
/** * Makes sure the <new_object> is valid for this text chooser, then calls an * update in case it has changed, and writes the new object string in the widget. */ void select_object(FE_object *new_object) { static const char *null_object_name = "<NONE>"; wxString tmpstr = GetValue(); const char *current_string = tmpstr.mb_str(wxConvUTF8); // hard-coded for node cmzn_fieldmodule_id fieldmodule = cmzn_region_get_fieldmodule(region); cmzn_nodeset_id nodeset = cmzn_fieldmodule_find_nodeset_by_field_domain_type( fieldmodule, this->domain_type); if (current_string != 0) { if (new_object && ((!cmzn_nodeset_contains_node(nodeset, new_object)) || (conditional_function && !(conditional_function(new_object, conditional_function_user_data))))) { display_message(ERROR_MESSAGE, "TEXT_CHOOSE_FROM_FE_REGION_SELECT_OBJECT(object_type). Invalid object"); new_object = (FE_object *)0; } if (new_object) current_object = new_object; else if (!current_object) { cmzn_nodeiterator_id iter = cmzn_nodeset_create_nodeiterator(nodeset); while (0 != (current_object = cmzn_nodeiterator_next(iter))) { // remove access on current_object cmzn_node_id tmp = current_object; cmzn_node_destroy(&tmp); if ((!this->conditional_function) || this->conditional_function(current_object, this->conditional_function_user_data)) break; } } /* write out the current_object */ if (current_object) { char object_name[50]; sprintf(object_name, "%d", cmzn_node_get_identifier(current_object)); set_item(object_name); } else if (strcmp(null_object_name, current_string)) set_item(null_object_name); /* inform the client of any change */ update(); } cmzn_nodeset_destroy(&nodeset); cmzn_fieldmodule_destroy(&fieldmodule); }
void *gen_class(char *inf) { if(*inf == '[') { inf++; if(inf[strlen(inf) - 1] == ']') inf[strlen(inf) - 1] = 0; else return NULL; } int state; void *ret = malloc(32); if(*inf == '^') { memset(ret, 0xFF, 32); state = 0; inf++; } else { memset(ret, 0x00, 32); state = 1; } if(*inf == '-') { flp_item(ret, '-'); inf++; } else if(inf[strlen(inf) - 1] == '-') { flp_item(ret, '-'); inf[strlen(inf) - 1] = 0; } while(*inf) { if(*inf == '-') { set_range(ret, inf[-1], inf[1], state); } else set_item(ret, inf[0], state); inf++; } return ret; }
void ShipGoalsDlg::OnSelchangeBehavior10() { UpdateData(TRUE); m_object[9] = 0; set_item(9); m_subsys[9] = m_dock2[9] = 0; UpdateData(FALSE); }
void check_cave() { int ok = DRAG_D->query_data("eventstarted") || DRAG_D->query_data("eventfinished"); if (DRAG_D->query_data("testing")) ok = 0; if (toggle == -1) toggle = !ok; if (!toggle && ok) { toggle = !toggle; set_item("cave", "It looks a little brighter inside."); set_long(long+" The beach ends abruptly at a cave opening."); add_exit(DRAG_ROOMS+"ogre69", "enter"); }
char * perlcall (char* sub, char* in, char* out, long item, char* input) { char *retval=NULL; int count, foo; an_array *array; dSP ; if (!isperlrunning) RETURN_MSTR(retval); ++perlcalldepth; ENTER; SAVETMPS; PUSHMARK(SP); if (input && *input) XPUSHs(sv_2mortal(newSVpv(input, 0))); if (in && *in && (array=get_array(in))) { for (foo=0; foo<array->size; foo++) { XPUSHs(sv_2mortal(newSVpv(array->item[foo], 0))); } } PUTBACK ; if (out && *out) { long size; upper(out); size=(array=get_array(out))?array->size:0; if (0>item) item=size-~item; if (item>size) item=-1; } else { item=-1; } if (0<=item) { I32 ax; count = perl_call_pv(sub, G_EVAL|G_ARRAY); SPAGAIN ; SP -= count ; ax = (SP - PL_stack_base) + 1 ; for (foo=0; foo<count; foo++) { set_item(out, item+foo, (char*)SvPV_nolen(ST(foo)), 1); } retval=(void*)new_realloc((void**)(&retval),32); snprintf(retval,31,"%u",count); } else { SV *sv; count = perl_call_pv(sub, G_EVAL|G_SCALAR); SPAGAIN ; sv=POPs ; SV2STR(sv,retval); } PUTBACK ; FREETMPS; LEAVE; --perlcalldepth; RETURN_MSTR(retval); }
MCHashTableIndex _binding(mc_class* const aclass, const char* methodname, MCFuncPtr value) { if (aclass == null) { error_log("_binding_h(mc_class* aclass) aclass is nill return 0\n"); return 0; } MCHashTableIndex res = set_item(&(aclass->table), new_item(methodname, MCGenericFp(value), hash(methodname)), true, nameofc(aclass));//will override return res; }
//---------------------------------------------------------------------------------------------------------------------- // POPULATE //---------------------------------------------------------------------------------------------------------------------- void cListViewComputers::populate ( cMachlist * pMachlist ) { assert ( 0 < iQtyColumns ); assert ( pMachlist ); if ( ListView_GetItemCount ( hwnd ) ) ListView_DeleteAllItems ( hwnd ); LVITEM lvI; ZeroMemory ( &lvI, sizeof(lvI) ); lvI.mask = LVIF_TEXT | LVIF_PARAM ; lvI.state = 0; lvI.stateMask = 0; int i = 0; for ( mojo::cMach * p = pMachlist->pHead; p; p = p->pNext, i++ ) { // if ( p->bExclude ) // continue; SetLastError(0); lvI.iItem = i; lvI.iImage = 0; lvI.iSubItem = 0; lvI.lParam = (LPARAM) ( p->dwSerialNumber ); lvI.pszText = const_cast<LPWSTR>( p->sName.cstr() ); lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE ; lvI.state = 1<<12; SendMessage ( hwnd, LVM_INSERTITEM, 0, (LPARAM) &lvI ); lvI.iSubItem = 1; if ( 2 <= iQtyColumns ) ListView_SetItemText ( hwnd, i, 1, L"This is an IP" ); if ( 3 <= iQtyColumns ) ListView_SetItemText ( hwnd, i, 2, L"This is a status" ); if ( 4 <= iQtyColumns ) ListView_SetItemText ( hwnd, i, 2, L"Screen size" ); set_item ( i, p ); } InvalidateRect ( hwnd, NULL, true ); UpdateWindow ( hwnd ); }
static void guardian_faction(plane * pl, int id) { region *r; faction *f = findfaction(id); if (!f) { f = calloc(1, sizeof(faction)); f->banner = _strdup("Sie dienen dem großen Wyrm"); f->passw = _strdup(itoa36(rng_int())); set_email(&f->email, "*****@*****.**"); f->name = _strdup("Igjarjuks Kundschafter"); f->race = new_race[RC_ILLUSION]; f->age = turn; f->locale = find_locale("de"); f->options = want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN) | want(O_DEBUG); f->no = id; addlist(&factions, f); fhash(f); } if (f->race != new_race[RC_ILLUSION]) { assert(!"guardian id vergeben"); exit(0); } f->lastorders = turn; f->alive = true; for (r = regions; r; r = r->next) if (getplane(r) == pl && rterrain(r) != T_FIREWALL) { unit *u; freset(r, RF_ENCOUNTER); for (u = r->units; u; u = u->next) { if (u->faction == f) break; } if (u) continue; u = createunit(r, f, 1, new_race[RC_GOBLIN]); set_string(&u->name, "Igjarjuks Auge"); set_item(u, I_RING_OF_INVISIBILITY, 1); set_order(&u->thisorder, NULL); fset(u, UFL_ANON_FACTION); set_money(u, 1000); } }
static void eaten_by_monster(unit * u) { /* adjustment for smaller worlds */ static double multi = 0.0; int n = 0; int horse = 0; if (multi == 0.0) { multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; } switch (old_race(u_race(u))) { case RC_FIREDRAGON: n = rng_int() % 80 * u->number; horse = get_item(u, I_HORSE); break; case RC_DRAGON: n = rng_int() % 200 * u->number; horse = get_item(u, I_HORSE); break; case RC_WYRM: n = rng_int() % 500 * u->number; horse = get_item(u, I_HORSE); break; default: n = rng_int() % (u->number / 20 + 1); } n = (int)(n * multi); if (n > 0) { n = lovar(n); n = MIN(rpeasants(u->region), n); if (n > 0) { deathcounts(u->region, n); rsetpeasants(u->region, rpeasants(u->region) - n); ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); } } if (horse > 0) { set_item(u, I_HORSE, 0); ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); } }
mc_class* _load(const char* name, size_t objsize, MCLoaderPointer loader) { mc_class* aclass = findclass(name); //try lock spin lock trylock_global_classtable(); if (aclass == null) { //new a item aclass = alloc_mc_class(objsize); mc_hashitem* item = new_item(name, MCGenericVp(null), hash(name));//nil first package_by_item(item, aclass); (*loader)(aclass); //set item //MCBool isOverride, MCBool isFreeValue set_item(&mc_global_classtable, item, false, name); runtime_log("load a class[%s]\n", name); } else { runtime_log("find a class[%s]\n", name); } //unlock unlock_global_classtable(); return aclass; }
int yp_scheme_copy( yp_item_t **dst, const yp_item_t *src) { if (dst == NULL || src == NULL) { return KNOT_EINVAL; } // Count scheme items. size_t scheme_items = 0; for (const yp_item_t *item = src; item->name != NULL; item++) { scheme_items++; } // Allocate space for new scheme. size_t size = (scheme_items + 1) * sizeof(yp_item_t); *dst = malloc(size); if (*dst == NULL) { return KNOT_ENOMEM; } memset(*dst, 0, size); // Copy the scheme. for (int i = 0; i < scheme_items; i++) { if (src[i].name == NULL) { break; } int ret = set_item(*dst + i, src + i, *dst); if (ret != KNOT_EOK) { yp_scheme_free(*dst); return ret; } } return KNOT_EOK; }
BOOL ShipGoalsDlg::OnInitDialog() { int i, j, z, valid[99]; object *ptr; Assert(Ai_goal_list_size <= _countof(valid)); // set up pointers to all the combo boxes to simplify things a lot m_behavior_box[0] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR1); m_behavior_box[1] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR2); m_behavior_box[2] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR3); m_behavior_box[3] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR4); m_behavior_box[4] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR5); m_behavior_box[5] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR6); m_behavior_box[6] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR7); m_behavior_box[7] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR8); m_behavior_box[8] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR9); m_behavior_box[9] = (CComboBox *) GetDlgItem(IDC_BEHAVIOR10); m_object_box[0] = (CComboBox *) GetDlgItem(IDC_OBJECT1); m_object_box[1] = (CComboBox *) GetDlgItem(IDC_OBJECT2); m_object_box[2] = (CComboBox *) GetDlgItem(IDC_OBJECT3); m_object_box[3] = (CComboBox *) GetDlgItem(IDC_OBJECT4); m_object_box[4] = (CComboBox *) GetDlgItem(IDC_OBJECT5); m_object_box[5] = (CComboBox *) GetDlgItem(IDC_OBJECT6); m_object_box[6] = (CComboBox *) GetDlgItem(IDC_OBJECT7); m_object_box[7] = (CComboBox *) GetDlgItem(IDC_OBJECT8); m_object_box[8] = (CComboBox *) GetDlgItem(IDC_OBJECT9); m_object_box[9] = (CComboBox *) GetDlgItem(IDC_OBJECT10); m_subsys_box[0] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM1); m_subsys_box[1] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM2); m_subsys_box[2] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM3); m_subsys_box[3] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM4); m_subsys_box[4] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM5); m_subsys_box[5] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM6); m_subsys_box[6] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM7); m_subsys_box[7] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM8); m_subsys_box[8] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM9); m_subsys_box[9] = (CComboBox *) GetDlgItem(IDC_SUBSYSTEM10); m_dock2_box[0] = (CComboBox *) GetDlgItem(IDC_DOCK1); m_dock2_box[1] = (CComboBox *) GetDlgItem(IDC_DOCK2); m_dock2_box[2] = (CComboBox *) GetDlgItem(IDC_DOCK3); m_dock2_box[3] = (CComboBox *) GetDlgItem(IDC_DOCK4); m_dock2_box[4] = (CComboBox *) GetDlgItem(IDC_DOCK5); m_dock2_box[5] = (CComboBox *) GetDlgItem(IDC_DOCK6); m_dock2_box[6] = (CComboBox *) GetDlgItem(IDC_DOCK7); m_dock2_box[7] = (CComboBox *) GetDlgItem(IDC_DOCK8); m_dock2_box[8] = (CComboBox *) GetDlgItem(IDC_DOCK9); m_dock2_box[9] = (CComboBox *) GetDlgItem(IDC_DOCK10); m_priority_box[0] = (CComboBox *) GetDlgItem(IDC_PRIORITY1); m_priority_box[1] = (CComboBox *) GetDlgItem(IDC_PRIORITY2); m_priority_box[2] = (CComboBox *) GetDlgItem(IDC_PRIORITY3); m_priority_box[3] = (CComboBox *) GetDlgItem(IDC_PRIORITY4); m_priority_box[4] = (CComboBox *) GetDlgItem(IDC_PRIORITY5); m_priority_box[5] = (CComboBox *) GetDlgItem(IDC_PRIORITY6); m_priority_box[6] = (CComboBox *) GetDlgItem(IDC_PRIORITY7); m_priority_box[7] = (CComboBox *) GetDlgItem(IDC_PRIORITY8); m_priority_box[8] = (CComboBox *) GetDlgItem(IDC_PRIORITY9); m_priority_box[9] = (CComboBox *) GetDlgItem(IDC_PRIORITY10); // start off with all goals available for (i=0; i<Ai_goal_list_size; i++) valid[i] = 1; // disallow orders if they aren't allowed because of ship type if (self_ship >= 0) { // editing orders for just one ship for (i=0; i<Ai_goal_list_size; i++){ if (!(ai_query_goal_valid(self_ship, Ai_goal_list[i].def))){ valid[i] = 0; } } } else if (self_wing >= 0) { // editing orders for just one wing for (i=0; i<Wings[self_wing].wave_count; i++){ for (j=0; j<Ai_goal_list_size; j++){ if (!ai_query_goal_valid(Wings[self_wing].ship_index[i], Ai_goal_list[j].def)){ valid[j] = 0; } } } for (i=0; i<Ai_goal_list_size; i++){ if (Ai_goal_list[i].def == AI_GOAL_DOCK){ // a whole wing can't dock with one object.. valid[i] = 0; } } } else { // editing orders for all marked ships ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags[Object::Object_Flags::Marked])){ for (i=0; i<Ai_goal_list_size; i++){ if (!ai_query_goal_valid(ptr->instance, Ai_goal_list[i].def)){ valid[i] = 0; } } } ptr = GET_NEXT(ptr); } } if (Waypoint_lists.empty()) { for (i=0; i<Ai_goal_list_size; i++){ switch (Ai_goal_list[i].def) { case AI_GOAL_WAYPOINTS: case AI_GOAL_WAYPOINTS_ONCE: //case AI_GOAL_WARP: valid[i] = 0; } } } z = 0; ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) { i = ptr->instance; if ((self_ship > 0) && (self_ship != i) && ship_docking_valid(self_ship, i)){ z = 1; } } ptr = GET_NEXT(ptr); } if (!z){ for (i=0; i<Ai_goal_list_size; i++){ if (Ai_goal_list[i].def == AI_GOAL_DOCK){ valid[i] = 0; } } } // initialize the behavior boxes (they remain constant) and initialize each goal's data for (i=0; i<ED_MAX_GOALS; i++) { m_behavior_box[i] -> ResetContent(); z = m_behavior_box[i] -> AddString("None"); m_behavior_box[i] -> SetItemData(z, (DWORD) AI_GOAL_NONE); for (j=0; j<Ai_goal_list_size; j++){ if (valid[j]) { z = m_behavior_box[i] -> AddString(Ai_goal_list[j].name); m_behavior_box[i] -> SetItemData(z, (DWORD) Ai_goal_list[j].def); } } } if (self_ship >= 0){ initialize(Ai_info[Ships[self_ship].ai_index].goals, self_ship); } else if (self_wing >= 0){ initialize(Wings[self_wing].ai_goals); } else { initialize_multi(); } for (i=0; i<ED_MAX_GOALS; i++){ set_item(i, 1); } CDialog::OnInitDialog(); // restrict spin controls to a range of 0 - MAX_EDITOR_GOAL_PRIORITY ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN1)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN2)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN3)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN4)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN5)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN6)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN7)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN8)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN9)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); ((CSpinButtonCtrl *) GetDlgItem(IDC_SPIN10)) -> SetRange(0, MAX_EDITOR_GOAL_PRIORITY); return TRUE; }
void set_range(void *ret, int from, int to, int val) { int i; for(i = from; i <= to; i++) set_item(ret, i, val); }
istream& RAM::readFile(istream& file) { vector<string> vTag; I_.clear(); set_n(2); // En esta opción sólo se almacena el opcode y su operando string line, tag, comm, instruc, oper; // Cada línea, etiqueta, comentario, opcode, operando/etiqueta size_t indexC, indexT; // Índice de Comentario, Etiqueta y Et Fin int nLine = 1; // Nº de líneas con código sin comentario. Útil para saber donde van las etiquetas while (getline(file, line)) { // ****** ETIQUETA indexT = line.find(":"); // Índice que guarda el lugar donde termina la etiqueta if (indexT < 1000) { // Si existe etiqueta (el índice no puede ser el npos). tag = line.substr(0, indexT); // Substring que contiene desde el inicio hasta el :, almacena el nombre de la etiqueta tag = Trim(tag.begin(), tag.end()); // Eliminamos los espacios en blanco vTag.push_back(to_string(nLine)); // Se añade a un vector el nº de línea donde aparece vTag.push_back(tag); // Se añade el nombre de la etiqueta indexT++; // Se añade uno al índice de la etiqueta para no coger el caracter : en las instrucciones } else { indexT = 0; // Sino se encuentra etiqueta coloco el índice en 0, para iniciar desde ahí la búsqueda de la instrucción tag = ""; // Si me hiciera almacenar más adelante el nombre de la etiqueta, saber que aquí no tenía } // ****** COMENTARIO indexC = line.find(";"); // Almacena el índice donde empieza el comentario if (indexC < 1000) { // Si existe comentario su índice es distinto del npos (un nº muy grande) comm = line.substr(indexC + 1); // Almacena el comentario, es un substring desde ; hasta el final (se le añade +1 para eliminar ; } else { indexC = line.size(); // Sino se encuentra comentario es hasta el final de la línea la instrucción comm = ""; // Sino existe comentario es "" } // ****** INSTRUCCIONES = OPCODE + OPERANDO/ETIQUETA/NADA if (indexT != indexC) { // Cuando existe código instruc = line.substr(indexT, indexC - indexT); // Substring que contiene la instrucción y el operando/tag juntos instruc.append(" "); // Añado un espacio al final para no exista fallo con el último comando instruc = TrimFirst(instruc.begin(), instruc.end()); // Captura la primera palabra instruc = codOpcode(instruc); // Codifico el opcode if (instruc != "12") { // 12 = HALT, entra salvo que sea 12, que no tiene ni tag ni operando oper = line.substr(indexT, indexC - indexT); // Substring que contiene la instrucción y el operando/tag juntos //oper.append(" "); oper = TrimSecond(oper.begin(), oper.end()); // Se toma la segunda palabra que corresponde con el operando/etiqueta } else oper = ""; // Halt no tiene nada I_.push_back(instruc); // Se añade el opcode a la estructura I_.push_back(oper); // Se añade el operando/etiqueta a la estructura nLine++; // Se incrementa el nº de líneas con código, para identificar la etiqueta } } set_m(nLine - 1); // Al querer sólo contar las líneas con código, y estar el tag primero que instrucc // se me hace necesario incrementarlo dentro de éste, por lo que, al final me sobra uno for (int i = 0; i < vTag.size() / 2; i++) { // Se recorre el vector que almacena las etiquetas y su posición for (int j = 0; j < get_m(); j++) { // Se recorre el vector que almacena el opcode y su operando/etiqueta if (vTag[2 * i + 1] == get_item(j, 1)) // Si coincide el nombre de la etiqueta con el etiqueta del opcode set_item(j, 1, vTag[2 * i]); // Se cambia por el nº de línea } } return file; }
// Fix menu ghosting for a lister void lister_fix_menus(Lister *lister,BOOL sel_only) { struct MenuItem *item; struct Menu *menu; BOOL busy=0,icon=0,action=0,sel=0; short a; // Get menu pointer if (!lister_valid_window(lister) || !(menu=lister->window->MenuStrip)) return; // Clear menu strip ClearMenuStrip(lister->window); // Get flags if (lister->flags&LISTERF_LOCK) busy=1; if (lister->flags&LISTERF_VIEW_ICONS) icon=1; if (lister->flags&LISTERF_ICON_ACTION) action=1; // In icon mode? if (icon) { BackdropObject *icon; // Lock icon list lock_listlock(&lister->backdrop_info->objects,FALSE); // Go through list for (icon=(BackdropObject *)lister->backdrop_info->objects.list.lh_Head; icon->node.ln_Succ; icon=(BackdropObject *)icon->node.ln_Succ) { // Something selected? if (icon->state) { // Set flag and break sel=1; break; } } // Unlock icon list unlock_listlock(&lister->backdrop_info->objects); } /* // Text mode else { // Anything selected? if (lister->cur_buffer->buf_SelectedFiles[0]>0 || lister->cur_buffer->buf_SelectedDirs[0]>0) sel=1; } */ // Not just doing things dependant on selected icon? if (!sel_only) { // Show as name (set) if ((item=find_menu_item(menu,MENU_LISTER_VIEW_NAME))) { set_item(item,!icon); } // Show as icon (set) if ((item=find_menu_item(menu,MENU_LISTER_VIEW_ICON))) { set_item(item,icon && !action); } // Icon action (set) if ((item=find_menu_item(menu,MENU_LISTER_ICON_ACTION))) { set_item(item,icon && action); } // Show all if ((item=find_menu_item(menu,MENU_LISTER_SHOW_ALL))) { set_item(item,icon && lister->flags&LISTERF_SHOW_ALL); } // Close (disabled when busy) if ((item=find_menu_item(menu,MENU_LISTER_CLOSE))) { off_item(item,busy); } // Lister states (disabled when busy, or in icon - not action - mode) for (a=MENU_LISTER_SOURCE;a<=MENU_LISTER_OFF;a++) { // Find item if ((item=find_menu_item(menu,a))) { off_item(item,busy || (icon && !action)); } } // Edit (disabled when busy or in icon mode) if ((item=find_menu_item(menu,MENU_EDIT_LISTER))) { off_item(item,busy || icon); } // New drawer (disabled when busy) if ((item=find_menu_item(menu,MENU_ICON_MAKEDIR))) { off_item(item,busy); } // Snapshot (disabled when busy) if ((item=find_menu_item(menu,MENU_ICON_SNAPSHOT))) { off_item(item,busy); } // Select all (disabled when busy) if ((item=find_menu_item(menu,MENU_ICON_SELECT_ALL))) { off_item(item,busy); } // Clean up (disabled when busy or not in icon mode) if ((item=find_menu_item(menu,MENU_ICON_CLEANUP))) { off_item(item,busy || !icon); } // Open parent (disabled when there's no parent) if ((item=find_menu_item(menu,MENU_OPEN_PARENT))) { BOOL dis=0; // Does path end in a colon? if (lister->cur_buffer->buf_Path[strlen(lister->cur_buffer->buf_Path)-1]==':') dis=1; // Do disable off_item(item,dis); } } // Open icon (disabled when busy or nothing selected) if ((item=find_menu_item(menu,MENU_ICON_OPEN))) { off_item(item,busy || !sel); } // Information (disabled when busy or nothing selected) if ((item=find_menu_item(menu,MENU_ICON_INFO))) { off_item(item,busy || !sel); } // Snapshot icon (disabled when nothing selected) if ((item=find_menu_item(menu,MENU_ICON_SNAPSHOT_ICON))) { off_item(item,!sel); } // Unsnapshot (disabled when busy or nothing selected) if ((item=find_menu_item(menu,MENU_ICON_UNSNAPSHOT))) { off_item(item,busy || !sel); } // Leave out (disabled when busy or nothing selected in icon mode) if ((item=find_menu_item(menu,MENU_ICON_LEAVE_OUT))) { off_item(item,busy || (!sel && icon)); } // Rename (disabled when busy or nothing selected in icon mode) if ((item=find_menu_item(menu,MENU_ICON_RENAME))) { off_item(item,busy || (!sel && icon)); } // Delete (disabled when busy or nothing selected in icon mode) if ((item=find_menu_item(menu,MENU_ICON_DELETE))) { off_item(item,busy || (!sel && icon)); } // Reset menu strip ResetMenuStrip(lister->window,menu); }
void set_items(void *ret, char *items, int val) { for(; *items; items++) set_item(ret, *items, val); }
void ShipGoalsDlg::set_item(int item, int init) { SCP_list<waypoint_list>::iterator ii; int i, t, z, num, inst; object *ptr; if (init) m_object[item] = -1; if (item >= MAX_AI_GOALS) m_behavior_box[item] -> EnableWindow(FALSE); Assert(item >= 0 && item < ED_MAX_GOALS); m_object_box[item] -> ResetContent(); if (m_behavior[item] < 1) { m_object_box[item] -> EnableWindow(FALSE); m_subsys_box[item] -> EnableWindow(FALSE); m_dock2_box[item] -> EnableWindow(FALSE); m_priority_box[item] -> EnableWindow(FALSE); m_subsys[item] = -1; m_dock2[item] = -1; return; } auto mode = m_behavior_box[item] -> GetItemData(m_behavior[item]); m_priority_box[item] -> EnableWindow(TRUE); if ((mode == AI_GOAL_CHASE_ANY) || (mode == AI_GOAL_UNDOCK) || (mode == AI_GOAL_KEEP_SAFE_DISTANCE) || (mode == AI_GOAL_PLAY_DEAD) || (mode == AI_GOAL_PLAY_DEAD_PERSISTENT) || (mode == AI_GOAL_WARP) ) { m_object_box[item] -> EnableWindow(FALSE); m_subsys_box[item] -> EnableWindow(FALSE); m_dock2_box[item] -> EnableWindow(FALSE); m_subsys[item] = -1; m_dock2[item] = -1; return; } m_object_box[item] -> EnableWindow(TRUE); // for goals that deal with waypoint paths or individual waypoints switch (mode) { case AI_GOAL_WAYPOINTS: case AI_GOAL_WAYPOINTS_ONCE: //case AI_GOAL_WARP: for (i = 0, ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++i, ++ii) { z = m_object_box[item] -> AddString(ii->get_name()); m_object_box[item] -> SetItemData(z, i | TYPE_PATH); if (init && (m_data[item] == (i | TYPE_PATH))) m_object[item] = z; } break; case AI_GOAL_STAY_STILL: ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if (ptr->type == OBJ_WAYPOINT) { z = m_object_box[item] -> AddString(object_name(OBJ_INDEX(ptr))); m_object_box[item] -> SetItemData(z, OBJ_INDEX(ptr) | TYPE_WAYPOINT); if (init && (m_data[item] == (OBJ_INDEX(ptr) | TYPE_WAYPOINT))) m_object[item] = z; } ptr = GET_NEXT(ptr); } break; } // for goals that deal with ship classes switch (mode) { case AI_GOAL_CHASE_SHIP_CLASS: for (i = 0; i < static_cast<int>(Ship_info.size()); i++) { z = m_object_box[item] -> AddString(Ship_info[i].name); m_object_box[item] -> SetItemData(z, i | TYPE_SHIP_CLASS); if (init && (m_data[item] == (i | TYPE_SHIP_CLASS))) m_object[item] = z; } break; } // for goals that deal with individual ships switch (mode) { case AI_GOAL_DESTROY_SUBSYSTEM: case AI_GOAL_CHASE | AI_GOAL_CHASE_WING: case AI_GOAL_DOCK: case AI_GOAL_GUARD | AI_GOAL_GUARD_WING: case AI_GOAL_DISABLE_SHIP: case AI_GOAL_DISARM_SHIP: case AI_GOAL_EVADE_SHIP: case AI_GOAL_IGNORE: case AI_GOAL_IGNORE_NEW: case AI_GOAL_STAY_NEAR_SHIP: case AI_GOAL_STAY_STILL: ptr = GET_FIRST(&obj_used_list); while (ptr != END_OF_LIST(&obj_used_list)) { if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) { inst = ptr->instance; if (ptr->type == OBJ_SHIP) t = TYPE_SHIP; else t = TYPE_PLAYER; Assert(inst >= 0 && inst < MAX_SHIPS); // remove all marked ships from list if (!goalp && (ptr->flags[Object::Object_Flags::Marked])) inst = -1; // when docking, remove invalid dock targets else if (mode == AI_GOAL_DOCK) { if (self_ship < 0 || !ship_docking_valid(self_ship, inst)) inst = -1; } // disallow ship being its own target if (inst >= 0 && inst != self_ship) { z = m_object_box[item] -> AddString(Ships[inst].ship_name); m_object_box[item] -> SetItemData(z, inst | t); if (init && (m_data[item] == (inst | t))) m_object[item] = z; } } ptr = GET_NEXT(ptr); } break; } // for goals that deal with wings switch (mode) { case AI_GOAL_CHASE | AI_GOAL_CHASE_WING: case AI_GOAL_GUARD | AI_GOAL_GUARD_WING: for (i=0; i<MAX_WINGS; i++) { if (Wings[i].wave_count && i != self_wing) { z = m_object_box[item] -> AddString(Wings[i].name); m_object_box[item] -> SetItemData(z, i | TYPE_WING); if (init && (m_data[item] == (i | TYPE_WING))) m_object[item] = z; } } break; } // special cases depending on the target: subsystems and docking points if (mode == AI_GOAL_DESTROY_SUBSYSTEM) { m_subsys_box[item] -> EnableWindow(TRUE); m_dock2_box[item] -> EnableWindow(FALSE); m_dock2[item] = -1; set_object(item); if (!m_behavior[item]) set_item(item, init); } else if (mode == AI_GOAL_DOCK) { num = get_docking_list(Ship_info[Ships[cur_ship].ship_info_index].model_num); m_subsys_box[item] -> EnableWindow(TRUE); m_subsys_box[item] -> ResetContent(); for (i=0; i<num; i++) { Assert(Docking_bay_list[i]); z = m_subsys_box[item] -> AddString(Docking_bay_list[i]); m_subsys_box[item] -> SetItemDataPtr(z, Docking_bay_list[i]); } set_object(item); if (!m_behavior[item]) set_item(item, init); } else { m_subsys_box[item] -> EnableWindow(FALSE); m_dock2_box[item] -> EnableWindow(FALSE); m_subsys[item] = -1; m_dock2[item] = -1; } }