/** * Moves all the items to the base on right-click. * @param action Pointer to an action. */ void CraftEquipmentState::lstEquipmentLeftArrowClick(Action *action) { if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) { cQty = c->getVehicleCount(_items[_sel]); if (cQty > 0) { while (cQty > 0) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ++i) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); c->getVehicles()->erase(i); break; } } _base->getItems()->addItem(_items[_sel]); cQty = c->getVehicleCount(_items[_sel]); } updateQuantity(); } } else { cQty = c->getItems()->getItem(_items[_sel]); if (cQty > 0) { _base->getItems()->addItem(_items[_sel], cQty); c->getItems()->removeItem(_items[_sel], cQty); updateQuantity(); } } } }
/** * Moves the selected item to the craft. */ void CraftEquipmentState::moveRight() { Craft *c = _base->getCrafts()->at(_craft); if (_base->getItems()->getItem(_items[_sel]) > 0) { _base->getItems()->removeItem(_items[_sel]); c->getItems()->addItem(_items[_sel]); updateQuantity(); } }
/** * Moves the given number of items (selected) to the base. */ void CraftEquipmentState::moveLeft(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) cQty = c->getVehicleCount(_items[_sel]); else cQty = c->getItems()->getItem(_items[_sel]); if (0 >= change || 0 >= cQty) return; change = std::min(cQty, change); // Convert vehicle to item if (item->isFixed()) { if(item->getClipSize() != -1) { // First we remove all vehicles because we want to redistribute the ammo RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); c->getVehicles()->erase(i); i = c->getVehicles()->begin(); // Since we erased the current iterator, we have to start over (to avoid a crash) } else ++i; } _base->getItems()->addItem(_items[_sel], cQty); // And now reAdd the count we want to keep in the craft (and redistribute the ammo among them) if (cQty > change) moveRight(cQty - change); } else { _base->getItems()->addItem(_items[_sel], change); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { delete (*i); c->getVehicles()->erase(i); if (0 >= --change) break; i = c->getVehicles()->begin(); // Since we erased the current iterator, we have to start over (to avoid a crash) } else ++i; } } } else { c->getItems()->removeItem(_items[_sel], change); _base->getItems()->addItem(_items[_sel], change); } updateQuantity(); }
void updateProductQuantityMenu() { int id, newQuantity; printf("Id of the product: "); scanf("%d", &id); printf("New quantity: "); scanf("%d", &newQuantity); int result = updateQuantity(id, newQuantity); if (result == 0) { printf("Quantity was updated!"); } else { printf("Unknown id!"); } }
/** * Moves all the items (as much as possible) to the craft on right-click. * @param action Pointer to an action. */ void CraftEquipmentState::lstEquipmentRightArrowClick(Action *action) { if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int bqty = _base->getItems()->getItem(_items[_sel]); if (bqty > 0) { // Do we need to convert item to vehicle? if (item->isFixed()) { // Check if there's enough room int room = std::min(c->getRules()->getVehicles() - c->getNumVehicles(), c->getSpaceAvailable() / 4); if (room > 0) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); int baqty = _base->getItems()->getItem(ammo->getType()); int vehiclesCount = std::min(std::min(bqty, room), baqty); if (vehiclesCount > 0) { int newAmmoPerVehicle = std::min(baqty / vehiclesCount, ammo->getClipSize());; int remainder = baqty - (vehiclesCount * newAmmoPerVehicle); if (ammo->getClipSize() == newAmmoPerVehicle) remainder = 0; int newAmmo; for (int i=0; i < vehiclesCount; ++i) { newAmmo = newAmmoPerVehicle; if (i<remainder) ++newAmmo; c->getVehicles()->push_back(new Vehicle(item, newAmmo)); _base->getItems()->removeItem(ammo->getType(), newAmmo); _base->getItems()->removeItem(_items[_sel]); } } } } else { _base->getItems()->removeItem(_items[_sel],bqty); c->getItems()->addItem(_items[_sel],bqty); } updateQuantity(); } } }
void updateStock() { int i; do { printf("----------------------------------------------------\n"); printf("Push 1 to add to stock.\n"); printf("Push 2 to delete from stock.\n"); printf("Push 3 to update price of stock.\n"); printf("Push 4 to update quantity.\n"); printf("Push 5 or higher to go back to main.\n"); printf("?: "); scanf("%d", &i); switch(i) { case 1: printf("\n----------------------------------------------------\n"); addStock(sFile1); printf("----------------------------------------------------\n\n"); break; case 2: printf("\n----------------------------------------------------\n"); delStock(sFile1); printf("----------------------------------------------------\n\n"); break; case 3: printf("\n----------------------------------------------------\n"); updatePrice(sFile1); printf("----------------------------------------------------\n\n"); break; case 4: printf("\n----------------------------------------------------\n"); updateQuantity(); printf("----------------------------------------------------\n\n"); break; } } while(i<5); }
/** * Moves the selected item to the craft. */ void CraftEquipmentState::moveRight() { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); if (_base->getItems()->getItem(_items[_sel]) > 0) { // Convert item to vehicle if (item->isFixed()) { // Check if there's enough room if (c->getNumVehicles() < c->getRules()->getVehicles() && c->getSpaceAvailable() >= 4) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); int qty = _base->getItems()->getItem(ammo->getType()); if (qty == 0) { std::wstringstream ss; ss << _game->getLanguage()->getString("STR_NOT_ENOUGH"); ss << _game->getLanguage()->getString(ammo->getType()); ss << _game->getLanguage()->getString("STR_TO_ARM_HWP"); _game->pushState(new ErrorMessageState(_game, ss.str(), Palette::blockOffset(15)+1, "BACK04.SCR", 2)); _timerRight->stop(); } else { int newAmmo = std::min(qty, ammo->getClipSize()); c->getVehicles()->push_back(new Vehicle(item, newAmmo)); _base->getItems()->removeItem(ammo->getType(), newAmmo); _base->getItems()->removeItem(_items[_sel]); } } } else { _base->getItems()->removeItem(_items[_sel]); c->getItems()->addItem(_items[_sel]); } updateQuantity(); } }
/** * Moves the selected item to the base. */ void CraftEquipmentState::moveLeft() { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) { cQty = c->getVehicleCount(_items[_sel]); } else { cQty = c->getItems()->getItem(_items[_sel]); } if (cQty > 0) { RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); // Convert vehicle to item if (item->isFixed()) { RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ++i) { if ((*i)->getRules() == item) { _base->getItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); c->getVehicles()->erase(i); break; } } _base->getItems()->addItem(_items[_sel]); } else { _base->getItems()->addItem(_items[_sel]); c->getItems()->removeItem(_items[_sel]); } updateQuantity(); } }
/** * Moves the given number of items (selected) to the craft. */ void CraftEquipmentState::moveRight(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getRuleset()->getItem(_items[_sel]); int bqty = _base->getItems()->getItem(_items[_sel]); if (0 >= change || 0 >= bqty) return; change = std::min(bqty, change); // Do we need to convert item to vehicle? if (item->isFixed()) { // Check if there's enough room int room = std::min(c->getRules()->getVehicles() - c->getNumVehicles(), c->getSpaceAvailable() / 4); if (room > 0) { change = std::min(room, change); if(item->getClipSize() != -1) { // We want to redistribute all the available ammo among the vehicles, // so first we note the total number of vehicles we want in the craft int oldVehiclesCount = c->getVehicleCount(_items[_sel]); int newVehiclesCount = oldVehiclesCount + change; // ...and we move back all of this vehicle-type to the base. if (0 < oldVehiclesCount) moveLeft(INT_MAX); // And now let's see if we can add the total number of vehicles. RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front()); int baqty = _base->getItems()->getItem(ammo->getType()); // Ammo Quantity for this vehicle-type on the base int canBeAdded = std::min(newVehiclesCount, baqty); if (canBeAdded > 0) { int newAmmoPerVehicle = std::min(baqty / canBeAdded, ammo->getClipSize());; int remainder = 0; if (ammo->getClipSize() > newAmmoPerVehicle) remainder = baqty - (canBeAdded * newAmmoPerVehicle); int newAmmo; for (int i=0; i < canBeAdded; ++i) { newAmmo = newAmmoPerVehicle; if (i<remainder) ++newAmmo; c->getVehicles()->push_back(new Vehicle(item, newAmmo)); _base->getItems()->removeItem(ammo->getType(), newAmmo); _base->getItems()->removeItem(_items[_sel]); } } if (oldVehiclesCount >= canBeAdded) { // So we haven't managed to increase the count of vehicles because of the ammo _timerRight->stop(); LocalizedText msg(tr("STR_NOT_ENOUGH_ammotype_TO_ARM_HWP").arg(tr(ammo->getType()))); _game->pushState(new ErrorMessageState(_game, msg, Palette::blockOffset(15)+1, "BACK04.SCR", 2)); } } else for (int i=0; i < change; ++i) { c->getVehicles()->push_back(new Vehicle(item, 255)); _base->getItems()->removeItem(_items[_sel]); } } } else { _base->getItems()->removeItem(_items[_sel],change); c->getItems()->addItem(_items[_sel],change); } updateQuantity(); }
/** * Moves the given number of items (selected) to the craft. * @param change Item difference. */ void CraftEquipmentState::moveRightByValue(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getMod()->getItem(_items[_sel]); int bqty = _base->getStorageItems()->getItem(_items[_sel]); if (_game->getSavedGame()->getMonthsPassed() == -1) { if (change == INT_MAX) { change = 10; } bqty = change; } if (0 >= change || 0 >= bqty) return; change = std::min(bqty, change); // Do we need to convert item to vehicle? if (item->isFixed()) { int size = 4; if (_game->getMod()->getUnit(item->getType())) { size = _game->getMod()->getArmor(_game->getMod()->getUnit(item->getType())->getArmor())->getSize(); size *= size; } // Check if there's enough room int room = std::min(c->getRules()->getVehicles() - c->getNumVehicles(), c->getSpaceAvailable() / size); if (room > 0) { change = std::min(room, change); if (!item->getCompatibleAmmo()->empty()) { // And now let's see if we can add the total number of vehicles. RuleItem *ammo = _game->getMod()->getItem(item->getCompatibleAmmo()->front()); int ammoPerVehicle, clipSize; if (ammo->getClipSize() > 0 && item->getClipSize() > 0) { clipSize = item->getClipSize(); ammoPerVehicle = clipSize / ammo->getClipSize(); } else { clipSize = ammo->getClipSize(); ammoPerVehicle = clipSize; } int baseQty = _base->getStorageItems()->getItem(ammo->getType()) / ammoPerVehicle; if (_game->getSavedGame()->getMonthsPassed() == -1) baseQty = 1; int canBeAdded = std::min(change, baseQty); if (canBeAdded > 0) { for (int i=0; i < canBeAdded; ++i) { if (_game->getSavedGame()->getMonthsPassed() != -1) { _base->getStorageItems()->removeItem(ammo->getType(), ammoPerVehicle); _base->getStorageItems()->removeItem(_items[_sel]); } c->getVehicles()->push_back(new Vehicle(item, clipSize, size)); } } else { // So we haven't managed to increase the count of vehicles because of the ammo _timerRight->stop(); LocalizedText msg(tr("STR_NOT_ENOUGH_AMMO_TO_ARM_HWP").arg(tr(ammo->getType()))); _game->pushState(new ErrorMessageState(msg, _palette, _game->getMod()->getInterface("craftEquipment")->getElement("errorMessage")->color, "BACK04.SCR", _game->getMod()->getInterface("craftEquipment")->getElement("errorPalette")->color)); } } else for (int i=0; i < change; ++i) { c->getVehicles()->push_back(new Vehicle(item, item->getClipSize(), size)); if (_game->getSavedGame()->getMonthsPassed() != -1) { _base->getStorageItems()->removeItem(_items[_sel]); } } } } else { if (c->getRules()->getMaxItems() > 0 && _totalItems + change > c->getRules()->getMaxItems()) { _timerRight->stop(); LocalizedText msg(tr("STR_NO_MORE_EQUIPMENT_ALLOWED", c->getRules()->getMaxItems())); _game->pushState(new ErrorMessageState(msg, _palette, _game->getMod()->getInterface("craftEquipment")->getElement("errorMessage")->color, "BACK04.SCR", _game->getMod()->getInterface("craftEquipment")->getElement("errorPalette")->color)); change = c->getRules()->getMaxItems() - _totalItems; } c->getItems()->addItem(_items[_sel],change); _totalItems += change; if (_game->getSavedGame()->getMonthsPassed() > -1) { _base->getStorageItems()->removeItem(_items[_sel],change); } } updateQuantity(); }
/** * Moves the given number of items (selected) to the base. * @param change Item difference. */ void CraftEquipmentState::moveLeftByValue(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getMod()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) cQty = c->getVehicleCount(_items[_sel]); else cQty = c->getItems()->getItem(_items[_sel]); if (change <= 0 || cQty <= 0) return; change = std::min(cQty, change); // Convert vehicle to item if (item->isFixed()) { if (!item->getCompatibleAmmo()->empty()) { // First we remove all vehicles because we want to redistribute the ammo RuleItem *ammo = _game->getMod()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { _base->getStorageItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); i = c->getVehicles()->erase(i); } else ++i; } if (_game->getSavedGame()->getMonthsPassed() != -1) { _base->getStorageItems()->addItem(_items[_sel], cQty); } // And now reAdd the count we want to keep in the craft (and redistribute the ammo among them) if (cQty > change) moveRightByValue(cQty - change); } else { if (_game->getSavedGame()->getMonthsPassed() != -1) { _base->getStorageItems()->addItem(_items[_sel], change); } for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { delete (*i); i = c->getVehicles()->erase(i); if (0 >= --change) break; } else ++i; } } } else { c->getItems()->removeItem(_items[_sel], change); _totalItems -= change; if (_game->getSavedGame()->getMonthsPassed() > -1) { _base->getStorageItems()->addItem(_items[_sel], change); } } updateQuantity(); }
void BillItemMeasure::setFormula( const QString & nf ){ if( nf != m_d->formula ){ m_d->formula = nf; updateQuantity(); } }
void BillItemMeasure::setUnitMeasure(UnitMeasure *ump) { if( m_d->unitMeasure != ump ){ m_d->unitMeasure = ump; updateQuantity(); } }