//------------------------------------------------------------- // ViewFrame::getViewExpr() return view expr for object //------------------------------------------------------------- char *FrameMgr::getViewExpr(ObjectNode *vobj) { LinkedList<ObjectNode*>objpath; char buff[256]; buff[0]=0; ObjectNode *obj=vobj; while(obj&&(obj->typeClass()& ID_OBJECT)){ objpath.push(obj); obj=obj->parent; } obj=objpath.ss(); sprintf(buff,"%s.1",obj->name()); while((obj=objpath++)>0){ ObjectNode *nextobj=objpath.at(); if(!nextobj) break; int i=type_index(obj,nextobj); if(i>0) sprintf(buff+strlen(buff),".%s.%d",nextobj->name(),i); } char *vexpr; MALLOC(strlen(buff)+1,char,vexpr); strcpy(vexpr,buff); return vexpr; }
void CStreamCtrlXml::sendEvent(const CmdStreamBase* ev) { try { ((*this).*type_serializers.at(type_index(typeid(*ev))))(ev); } catch (const std::out_of_range& ore) { cerr << "CStreamCtrlXml::sendEvent: unknown event type: " << typeid(ev).name() << " got out of range exception: " << ore.what() << endl; } catch (const std::bad_cast &bce) { cerr << "CStreamCtrlXml::sendEvent bad cast: " << bce.what() << endl; } }
void TradeInterface::Reinitialize() { _RefreshItemCategories(); // Set the initial category to the last category that was added (this is usually "All Wares") _current_category = _number_categories > 0 ? _number_categories - 1 : 0; // Initialize the category display with the initial category if(_number_categories > 0) _category_display.ChangeCategory(_category_names[_current_category], _category_icons[_current_category]); // Prepare object data containers and determine category index mappings // Containers of object data used to populate the display lists std::vector<std::vector<ShopObject *> > object_data; for(uint32 i = 0; i < _number_categories; ++i) { object_data.push_back(std::vector<ShopObject *>()); } // Holds the index to the _object_data vector where the container for a specific object type is located // The + 1 is set to reserve space for key items. std::vector<uint32> type_index(GLOBAL_OBJECT_TOTAL + 1, 0); // Used to set the appropriate data in the type_index vector uint32 next_index = 0; // Used to do a bit-by-bit analysis of the deal_types variable uint8 bit_x = 0x01; // This loop determines where each type of object should be placed in the object_data container. For example, // if the available categories in the shop are items, weapons, spirits, and all wares, the size of object_data // will be four. When we go to add an object of one of these types into the object_data container, we need // to know the correct index for each type of object. These indeces are stored in the type_index vector. The // size of this vector is the number of object types, so it becomes simple to map each object type to its correct // location in object_data. for(uint8 i = 0; i < GLOBAL_OBJECT_TOTAL; ++i, bit_x <<= 1) { // Check if the type is available by doing a bit-wise comparison if(_trade_deal_types & bit_x) { type_index[i] = next_index++; } } // Populate the object_data containers // Pointer to the container of all objects that are bought/sold/traded in the shop std::map<uint32, ShopObject *>* trade_objects = ShopMode::CurrentInstance()->GetAvailableTrade(); for(std::map<uint32, ShopObject *>::iterator it = trade_objects->begin(); it != trade_objects->end(); ++it) { ShopObject* obj = it->second; switch(obj->GetObject()->GetObjectType()) { case GLOBAL_OBJECT_ITEM: object_data[type_index[0]].push_back(obj); break; case GLOBAL_OBJECT_WEAPON: object_data[type_index[1]].push_back(obj); break; case GLOBAL_OBJECT_HEAD_ARMOR: object_data[type_index[2]].push_back(obj); break; case GLOBAL_OBJECT_TORSO_ARMOR: object_data[type_index[3]].push_back(obj); break; case GLOBAL_OBJECT_ARM_ARMOR: object_data[type_index[4]].push_back(obj); break; case GLOBAL_OBJECT_LEG_ARMOR: object_data[type_index[5]].push_back(obj); break; case GLOBAL_OBJECT_SPIRIT: object_data[type_index[6]].push_back(obj); break; default: IF_PRINT_WARNING(SHOP_DEBUG) << "added object of unknown type: " << obj->GetObject()->GetObjectType() << std::endl; break; } // Also test whether this is a key item. if (obj->GetObject()->IsKeyItem()) object_data[type_index[7]].push_back(obj); // If there is an "All Wares" category, make sure the object gets added there as well if(_number_categories > 1) { object_data.back().push_back(obj); } } // Create the buy displays using the object data that is now ready for(uint32 i = 0; i < _list_displays.size(); ++i) { delete _list_displays[i]; } _list_displays.clear(); for(uint32 i = 0; i < object_data.size(); ++i) { TradeListDisplay *new_list = new TradeListDisplay(); new_list->PopulateList(object_data[i]); _list_displays.push_back(new_list); } if(_number_categories > 0) _selected_object = _list_displays[_current_category]->GetSelectedObject(); _ChangeViewMode(SHOP_VIEW_MODE_LIST); } // void TradeInterface::Initialize()