/*********************************************************************** * Character * swapWeapons ***********************************************************************/ void fired::Character::swapWeapons() { if (weaponCooldown.isActive()) return; swapItems(&inventory->primaryWeapon, &inventory->secondaryWeapon); swapItems(&inventory->primaryAmmo , &inventory->secondaryAmmo); if (inventory->primaryWeapon.base) setWeapon(container->weapons[inventory->primaryWeapon.base->UID]); else setWeapon(base->weapon); if (inventory->primaryAmmo.base) ammo = container->ammos[inventory->primaryAmmo.base->UID]; else ammo = base->ammo; weaponCooldown.setTimer(WEAPON_SWITCH_COOLDOWN); }
/*********************************************************************** * ExchangeWindow * click ***********************************************************************/ void fired::ExchangeWindow::click(sf::Vector2f mousePos) { fired::InventoryWindowItem *selected = NULL; if (trashCan->rect.contains(mousePos)) { if (inHand->item->base != NULL) emptyItem(trashCan->item); swapItems(trashCan->item, inHand->item); return; } for (unsigned int i = 0; i < items.size(); i++) if (items[i]->rect.contains(mousePos)) { selected = items[i]; break; } for (unsigned int i = 0; i < exchange.size(); i++) if (exchange[i]->rect.contains(mousePos)) { selected = exchange[i]; break; } if (selected == NULL) return; if (inHand->item->base != NULL) { if (selected->filter != itAny && selected->filter != inHand->item->base->type) return; if (selected->filter == itArmor && selected->armorFilter != container->armors[inHand->item->base->UID]->type) return; if (selected->item->base == inHand->item->base) { if (selected->item->count + inHand->item->count <= selected->item->base->maxStack) { selected->item->count += inHand->item->count; emptyItem(inHand->item); } else { inHand->item->count = selected->item->count + inHand->item->count - selected->item->base->maxStack; selected->item->count = selected->item->base->maxStack; } owner->updateStats(); return; } } swapItems(selected->item, inHand->item); owner->updateStats(); }
void CompletionOrderEditor::slotMoveDown() { CompletionViewItem *item = static_cast<CompletionViewItem *>(mListView->selectedItem()); if(!item) return; CompletionViewItem *below = static_cast<CompletionViewItem *>(item->itemBelow()); if(!below) return; swapItems(item, below); mListView->setCurrentItem(below); mListView->setSelected(below, true); mDirty = true; }
void CompletionOrderEditor::slotMoveUp() { CompletionViewItem *item = static_cast<CompletionViewItem *>(mListView->selectedItem()); if(!item) return; CompletionViewItem *above = static_cast<CompletionViewItem *>(item->itemAbove()); if(!above) return; swapItems(item, above); mListView->setCurrentItem(above); mListView->setSelected(above, true); mDirty = true; }
/*********************************************************************** * Character * findAmmo ***********************************************************************/ bool fired::Character::findAmmo() { for (int i = 0; i < 10; i++) for (int j = 0; j < 5; j++) if (inventory->items[i][j].base && inventory->items[i][j].base->type == itAmmo) if (container->ammos[inventory->items[i][j].base->UID]->subtype == weapon->subtype) { swapItems(&inventory->primaryAmmo, &inventory->items[i][j]); ammo = container->ammos[inventory->primaryAmmo.base->UID]; return true; } ammo = base->ammo; return false; }
void Room::swapToAlternate() { if((alternate_room != NULL) && active) //If room is active base room { renderer.cleanList(); disable(); //Disable current room alternate_room->disable(); //Paranoid swapPortals(alternate_room); //Update portals to match this room swapItems(alternate_room); //Update items to match this room alternate_room->enable(); //Enable base room } }
void Room::swapToBase() { if((base_room != nullptr) && active) //If room is active alternate room { renderer.cleanList(); disable(); //Disable current room base_room->disable(); //Paranoid swapPortals(base_room); //Update portals to match this room swapItems(base_room); //Update items to match this room base_room->enable(); //Enable original room } }
TabItem* TabControl::insertItemAt(size_t _index, const UString& _name, Any _data) { MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "TabControl::insertItem"); Widget* widget = Base::baseCreateWidget(WidgetStyle::Child, TabItem::getClassTypeName(), "Default", _getWidgetTemplate()->getCoord(), _getWidgetTemplate()->getAlign(), "", "", false); size_t lastIndex = mItemsInfo.size() - 1; setItemNameAt(lastIndex, _name); setItemDataAt(lastIndex, _data); swapItems(_index == ITEM_NONE ? lastIndex : _index, lastIndex); return widget->castType<TabItem>(); }
void SchedScene::clickItem(size_t id) { if (!selected_.is_initialized()) { selectItem(id); } else if (*selected_ == id) { deselectItem(); } else { swapItems(*selected_, id); deselectItem(); } }
void TreeWidget::mouseMoveEvent(QMouseEvent* event) { if (!d.pressedItem) { int time = d.pressedTime.elapsed(); int distance = QPoint(event->pos() - d.pressedPoint).manhattanLength(); if (time >= QApplication::startDragTime() && distance >= QApplication::startDragDistance()) d.pressedItem = itemAt(d.pressedPoint); } if (d.pressedItem) { QTreeWidgetItem* target = itemAt(event->pos()); if (target && d.pressedItem != target) { QTreeWidgetItem* parent = target->parent(); if (parent == d.pressedItem->parent()) { setSortingBlocked(true); swapItems(d.pressedItem, target); } } } QTreeWidget::mouseMoveEvent(event); }
int main(void) { int type; double op2; char s[MAXOP]; int flag = TRUE; while((type = Getop(s)) != EOF) { switch(type) { case NUMBER: push(atof(s)); break; case IDENTIFIER: dealWithName(s); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop()- op2); break; case '/': op2 = pop(); if(op2) push(pop() / op2); else printf("\nError: division by zero!"); break; case '%': op2 = pop(); if(op2) push(fmod(pop(), op2)); else printf("\nError: division by zero!"); break; case '?': showTop(); break; case '#': duplicate(); break; case '~': swapItems(); break; case '!': clearStack(); case '\n': printf("\n\t%.8g\n", pop()); break; default: printf("\nError: unknown command %s.\n", s); break; } } return EXIT_SUCCESS; }
// Simple parallel quick-sort. "first" and "last" are the first // and last items (inclusive) in the vector. void DepthVector::SortRange(Item *first, Item *last) { while (first < last) { if (last-first <= 100) { // Use the standard library function for small ranges. qsort(first, last-first+1, sizeof(Item), qsCompare); return; } // Select the best pivot from the first, last and middle item // by sorting these three items. We use the middle item as // the pivot and since the first and last items are sorted // by this we can skip them when we start the partitioning. Item *middle = first + (last-first)/2; if (CompareItems(first, middle) > 0) swapItems(first, middle); if (CompareItems(middle, last) > 0) { swapItems(middle, last); if (CompareItems(first, middle) > 0) swapItems(first, middle); } // Partition the data about the pivot. This divides the // vector into two partitions with all items <= pivot to // the left and all items >= pivot to the right. // Note: items equal to the pivot could be in either partition. Item *f = first+1; Item *l = last-1; do { // Find an item we have to move. These loops will always // terminate because testing the middle with itself // will return == 0. while (CompareItems(f, middle/* pivot*/) < 0) f++; while (CompareItems(middle/* pivot*/, l) < 0) l--; // If we haven't finished we need to swap the items. if (f < l) { swapItems(f, l); // If one of these was the pivot item it will have moved to // the other position. if (middle == f) middle = l; else if (middle == l) middle = f; f++; l--; } else if (f == l) { f++; l--; break; } } while (f <= l); // Process the larger partition as a separate task or // by recursion and do the smaller partition by tail // recursion. if (l-first > last-f) { // Lower part is larger gpTaskFarm->AddWorkOrRunNow(sortTask, first, l); first = f; } else { // Upper part is larger gpTaskFarm->AddWorkOrRunNow(sortTask, f, last); last = l; } } }