/** * Handler for clicking on the heal button. * @param action Pointer to an action. */ void MedikitState::onHealClick(Action *) { int heal = _item->getHealQuantity(); RuleItem *rule = _item->getRules(); if (heal == 0) { return; } if (_unit->spendTimeUnits (rule->getTUUse())) { _targetUnit->heal(_medikitView->getSelectedPart(), rule->getWoundRecovery(), rule->getHealthRecovery()); _item->setHealQuantity(--heal); _medikitView->updateSelectedPart(); _medikitView->invalidate(); update(); if (_targetUnit->getStatus() == STATUS_UNCONSCIOUS && _targetUnit->getStunlevel() < _targetUnit->getHealth() && _targetUnit->getHealth() > 0) { _targetUnit->setTimeUnits(0); _action->actor->getStatistics()->revivedSoldier++; } _unit->getStatistics()->woundsHealed++; } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; onEndClick(0); } }
bool RuleListModel::realDeserializeData() { QSettings setting("Ray Fung", "Excel JSON"); QByteArray json = setting.value("rule_list", QByteArray("[]")).toByteArray(); QJsonDocument doc = QJsonDocument::fromJson(json); ruleList.clear(); if(doc.isArray() == false) return false; QJsonArray array = doc.array(); int count = array.size(); for(int i = 0; i < count; ++i) { QJsonValue val = array.at(i); if(val.isObject() == false) return false; QJsonObject data = val.toObject(); RuleData rule; RuleItem item; rule.isEnabled = data.value("enable").toBool(true); rule.excelPath = data.value("excel_path").toString(); rule.jsonPath = data.value("json_path").toString(); item.setRule(rule); ruleList.append(item); } return true; }
/** * Handler for clicking on the stimulant button * @param action Pointer to an action. */ void MedikitState::onStimulantClick(Action *) { int stimulant = _item->getStimulantQuantity(); RuleItem *rule = _item->getRules(); if (stimulant == 0) { return; } if (_unit->spendTimeUnits (rule->getTUUse())) { _targetUnit->stimulant(rule->getEnergy(), rule->getStun()); _item->setStimulantQuantity(--stimulant); update(); // if the unit has revived we quit this screen automatically if (_targetUnit->getStatus() == STATUS_UNCONSCIOUS && _targetUnit->getStunlevel() < _targetUnit->getHealth() && _targetUnit->getHealth() > 0) { _targetUnit->setTimeUnits(0); _game->popState(); } } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; _game->popState(); } }
/** * Updates the displayed quantities of the * selected item on the list. */ void CraftEquipmentState::updateQuantity() { Craft *c = _base->getCrafts()->at(_craft); std::wstringstream ss, ss2; ss << _base->getItems()->getItem(_items[_sel]); ss2 << c->getItems()->getItem(_items[_sel]); Uint8 color; if (c->getItems()->getItem(_items[_sel]) == 0) { RuleItem *rule = _game->getRuleset()->getItem(_items[_sel]); if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(_sel, color); _lstEquipment->setCellText(_sel, 1, ss.str()); _lstEquipment->setCellText(_sel, 2, ss2.str()); }
/** * Initializes all the elements in the Stores window. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. */ StoresState::StoresState(Game *game, Base *base) : State(game), _base(base) { // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(300, 16, 10, 176); _txtTitle = new Text(310, 16, 5, 8); _txtItem = new Text(142, 8, 10, 32); _txtQuantity = new Text(88, 8, 152, 32); _txtSpaceUsed = new Text(74, 8, 240, 32); _lstStores = new TextList(288, 128, 8, 40); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(0)), Palette::backPos, 16); add(_window); add(_btnOk); add(_txtTitle); add(_txtItem); add(_txtQuantity); add(_txtSpaceUsed); add(_lstStores); // Set up objects _window->setColor(Palette::blockOffset(13)+10); _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR")); _btnOk->setColor(Palette::blockOffset(13)+10); _btnOk->setText(_game->getLanguage()->getString("STR_OK")); _btnOk->onMouseClick((ActionHandler)&StoresState::btnOkClick); _txtTitle->setColor(Palette::blockOffset(13)+10); _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(_game->getLanguage()->getString("STR_STORES")); _txtItem->setColor(Palette::blockOffset(13)+10); _txtItem->setText(_game->getLanguage()->getString("STR_ITEM")); _txtQuantity->setColor(Palette::blockOffset(13)+10); _txtQuantity->setText(_game->getLanguage()->getString("STR_QUANTITY_UC")); _txtSpaceUsed->setColor(Palette::blockOffset(13)+10); _txtSpaceUsed->setText(_game->getLanguage()->getString("STR_SPACE_USED")); _lstStores->setColor(Palette::blockOffset(13)+10); _lstStores->setColumns(3, 162, 92, 32); _lstStores->setSelectable(true); _lstStores->setBackground(_window); _lstStores->setMargin(2); for (std::map<std::string, int>::iterator i = _base->getItems()->getContents()->begin(); i != _base->getItems()->getContents()->end(); ++i) { RuleItem *rule = _game->getRuleset()->getItem(i->first); std::wstringstream ss, ss2; ss << i->second; ss2 << i->second * rule->getSize(); _lstStores->addRow(3, _game->getLanguage()->getString(i->first).c_str(), ss.str().c_str(), ss2.str().c_str()); } }
void RuleListModel::setRealData(const QModelIndex &index, RuleData data) { int row = index.row(); RuleItem item; item.setRule(data); ruleList[row] = item; emit QAbstractListModel::dataChanged(index, index); }
/* * get how many clips are loaded into this weapon. * @param mod a pointer to the core mod. * @return number of clips loaded. */ int CraftWeapon::getClipsLoaded(const Mod *mod) { int retVal = (int)floor((double)_ammo / _rules->getRearmRate()); RuleItem *clip = mod->getItem(_rules->getClipItem()); if (clip && clip->getClipSize() > 0) { retVal = (int)floor((double)_ammo / clip->getClipSize()); } return retVal; }
/** * Updates the displayed quantities of the * selected item on the list. */ void CraftEquipmentState::updateQuantity() { 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]); } std::wstringstream ss, ss2; if (_game->getSavedGame()->getMonthsPassed() > -1) { ss << _base->getItems()->getItem(_items[_sel]); } else { ss << "-"; } ss2 << cQty; Uint8 color; if (cQty == 0) { RuleItem *rule = _game->getRuleset()->getItem(_items[_sel]); if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(_sel, color); _lstEquipment->setCellText(_sel, 1, ss.str()); _lstEquipment->setCellText(_sel, 2, ss2.str()); std::wstringstream ss3; ss3 << tr("STR_SPACE_AVAILABLE") << L'\x01' << c->getSpaceAvailable(); _txtAvailable->setText(ss3.str()); std::wstringstream ss4; ss4 << tr("STR_SPACE_USED") << L'\x01' << c->getSpaceUsed(); _txtUsed->setText(ss4.str()); }
/** * Handler for clicking on the heal button. * @param action Pointer to an action. */ void MedikitState::onHealClick(Action *) { int heal = _item->getHealQuantity(); RuleItem *rule = _item->getRules(); if (heal == 0) { return; } if (_unit->spendTimeUnits(_tu)) { _targetUnit->heal(_medikitView->getSelectedPart(), rule->getWoundRecovery(), rule->getHealthRecovery()); _item->setHealQuantity(--heal); _medikitView->updateSelectedPart(); _medikitView->invalidate(); update(); if (_targetUnit->getStatus() == STATUS_UNCONSCIOUS && _targetUnit->getStunlevel() < _targetUnit->getHealth() && _targetUnit->getHealth() > 0) { if (!_revivedTarget) { _targetUnit->setTimeUnits(0); if(_targetUnit->getOriginalFaction() == FACTION_PLAYER) { _action->actor->getStatistics()->revivedSoldier++; } else if(_targetUnit->getOriginalFaction() == FACTION_HOSTILE) { _action->actor->getStatistics()->revivedHostile++; } else { _action->actor->getStatistics()->revivedNeutral++; } _revivedTarget = true; } // if the unit has revived and has no more wounds, we quit this screen automatically if (_targetUnit->getFatalWounds() == 0) { onEndClick(0); } } _unit->getStatistics()->woundsHealed++; } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; onEndClick(0); } }
QVariant RuleListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); RuleItem item = ruleList.at(index.row()); if(role == Qt::ForegroundRole) return item.getForegroundColor(); if(role == Qt::DisplayRole) return item.toString(); return QVariant(); }
/** * Updates the displayed quantities of the * selected item on the list. */ void CraftEquipmentState::updateQuantity() { 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]); } std::wostringstream ss, ss2; if (_game->getSavedGame()->getMonthsPassed() > -1) { ss << _base->getStorageItems()->getItem(_items[_sel]); } else { ss << "-"; } ss2 << cQty; Uint8 color; if (cQty == 0) { RuleItem *rule = _game->getMod()->getItem(_items[_sel]); if (rule->getBattleType() == BT_AMMO) { color = _ammoColor; } else { color = _lstEquipment->getColor(); } } else { color = _lstEquipment->getSecondaryColor(); } _lstEquipment->setRowColor(_sel, color); _lstEquipment->setCellText(_sel, 1, ss.str()); _lstEquipment->setCellText(_sel, 2, ss2.str()); _txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(c->getSpaceAvailable())); _txtUsed->setText(tr("STR_SPACE_USED").arg(c->getSpaceUsed())); }
/** * 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(); } } } }
/** * Handler for clicking on the pain killer button. * @param action Pointer to an action. */ void MedikitState::onPainKillerClick(Action *) { int pk = _item->getPainKillerQuantity(); RuleItem *rule = _item->getRules(); if (pk == 0) { return; } if (_unit->spendTimeUnits (rule->getTUUse())) { _targetUnit->painKillers(); _item->setPainKillerQuantity(--pk); update(); } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; onEndClick(0); } }
/** * Updates the quantity-strings of the selected item. */ void SellState::updateItemStrings() { std::wostringstream ss, ss2, ss5; ss << _qtys[_sel]; _lstItems->setCellText(_sel, 2, ss.str()); ss2 << getQuantity() - _qtys[_sel]; _lstItems->setCellText(_sel, 1, ss2.str()); _txtSales->setText(tr("STR_VALUE_OF_SALES").arg(Text::formatFunding(_total))); if (_qtys[_sel] > 0) { _lstItems->setRowColor(_sel, _lstItems->getSecondaryColor()); } else { _lstItems->setRowColor(_sel, _lstItems->getColor()); if (_sel > _itemOffset) { RuleItem *rule = _game->getRuleset()->getItem(_items[_sel - _itemOffset]); if (rule->getBattleType() == BT_AMMO || (rule->getBattleType() == BT_NONE && rule->getClipSize() > 0)) { _lstItems->setRowColor(_sel, _ammoColor); } } } ss5 << _base->getUsedStores(); if (std::abs(_spaceChange) > 0.05) { ss5 << "("; if (_spaceChange > 0.05) ss5 << "+"; ss5 << std::fixed << std::setprecision(1) << _spaceChange << ")"; } ss5 << ":" << _base->getAvailableStores(); _txtSpaceUsed->setText(tr("STR_SPACE_USED").arg(ss5.str())); if (Options::storageLimitsEnforced) { _btnOk->setVisible(!_base->storesOverfull(_spaceChange)); } }
/** * Updates the quantity-strings of the selected item. */ void SellState::updateItemStrings() { std::ostringstream ss, ss2, ss3; ss << getRow().amount; _lstItems->setCellText(_sel, 2, ss.str()); ss2 << getRow().qtySrc - getRow().amount; _lstItems->setCellText(_sel, 1, ss2.str()); _txtSales->setText(tr("STR_VALUE_OF_SALES").arg(Unicode::formatFunding(_total))); if (getRow().amount > 0) { _lstItems->setRowColor(_sel, _lstItems->getSecondaryColor()); } else { _lstItems->setRowColor(_sel, _lstItems->getColor()); if (getRow().type == TRANSFER_ITEM) { RuleItem *rule = (RuleItem*)getRow().rule; if (rule->getBattleType() == BT_AMMO || (rule->getBattleType() == BT_NONE && rule->getClipSize() > 0)) { _lstItems->setRowColor(_sel, _ammoColor); } } } ss3 << _base->getUsedStores(); if (std::abs(_spaceChange) > 0.05) { ss3 << "("; if (_spaceChange > 0.05) ss3 << "+"; ss3 << std::fixed << std::setprecision(1) << _spaceChange << ")"; } ss3 << ":" << _base->getAvailableStores(); _txtSpaceUsed->setText(tr("STR_SPACE_USED").arg(ss3.str())); if (Options::storageLimitsEnforced) { _btnOk->setVisible(!_base->storesOverfull(_spaceChange)); } }
/** * Handler for clicking on the heal button * @param action Pointer to an action. */ void MedikitState::onHealClick(Action *) { int heal = _item->getHealQuantity(); RuleItem *rule = _item->getRules(); if (heal == 0) { return; } if (_unit->spendTimeUnits (rule->getTUUse())) { _targetUnit->heal(_medikitView->getSelectedPart(), rule->getHealAmount(), rule->getHealthAmount()); _item->setHealQuantity(--heal); _medikitView->invalidate(); update(); } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; _game->popState(); } }
/** * Handler for clicking on the stimulant button. * @param action Pointer to an action. */ void MedikitState::onStimulantClick(Action *) { int stimulant = _item->getStimulantQuantity(); RuleItem *rule = _item->getRules(); if (stimulant == 0) { return; } if (_unit->spendTimeUnits (_tu)) { _targetUnit->stimulant(rule->getEnergyRecovery(), rule->getStunRecovery()); _item->setStimulantQuantity(--stimulant); _action->actor->getStatistics()->appliedStimulant++; update(); // if the unit has revived we quit this screen automatically if (_targetUnit->getStatus() == STATUS_UNCONSCIOUS && _targetUnit->getStunlevel() < _targetUnit->getHealth() && _targetUnit->getHealth() > 0) { _targetUnit->setTimeUnits(0); if(_targetUnit->getOriginalFaction() == FACTION_PLAYER) { _action->actor->getStatistics()->revivedSoldier++; } else if(_targetUnit->getOriginalFaction() == FACTION_HOSTILE) { _action->actor->getStatistics()->revivedHostile++; } else { _action->actor->getStatistics()->revivedNeutral++; } onEndClick(0); } } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; onEndClick(0); } }
/** * Determines the category a row item belongs in. * @param sel Selected row. * @returns Item category. */ std::string SellState::getCategory(int sel) const { RuleItem *rule = 0; switch (_items[sel].type) { case TRANSFER_SOLDIER: case TRANSFER_SCIENTIST: case TRANSFER_ENGINEER: return "STR_PERSONNEL"; case TRANSFER_CRAFT: return "STR_CRAFT_ARMAMENT"; case TRANSFER_ITEM: rule = (RuleItem*)_items[sel].rule; if (rule->getBattleType() == BT_CORPSE || rule->isAlien()) { return "STR_ALIENS"; } if (rule->getBattleType() == BT_NONE) { if (_craftWeapons.find(rule->getType()) != _craftWeapons.end()) { return "STR_CRAFT_ARMAMENT"; } if (_armors.find(rule->getType()) != _armors.end()) { return "STR_EQUIPMENT"; } return "STR_COMPONENTS"; } return "STR_EQUIPMENT"; } return "STR_ALL_ITEMS"; }
/** * 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(); }
/** * Filters the current list of items. */ void SellState::updateList() { _lstItems->clearList(); _rows.clear(); for (size_t i = 0; i < _items.size(); ++i) { std::string cat = _cats[_cbxCategory->getSelected()]; if (cat != "STR_ALL_ITEMS" && cat != getCategory(i)) { continue; } std::string name = _items[i].name; bool ammo = false; if (_items[i].type == TRANSFER_ITEM) { RuleItem *rule = (RuleItem*)_items[i].rule; ammo = (rule->getBattleType() == BT_AMMO || (rule->getBattleType() == BT_NONE && rule->getClipSize() > 0)); if (ammo) { name.insert(0, " "); } } std::ostringstream ssQty, ssAmount; ssQty << _items[i].qtySrc - _items[i].amount; ssAmount << _items[i].amount; _lstItems->addRow(4, name.c_str(), ssQty.str().c_str(), ssAmount.str().c_str(), Unicode::formatFunding(_items[i].cost).c_str()); _rows.push_back(i); if (_items[i].amount > 0) { _lstItems->setRowColor(_rows.size() - 1, _lstItems->getSecondaryColor()); } else if (ammo) { _lstItems->setRowColor(_rows.size() - 1, _ammoColor); } } }
/** * 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(); } } }
/** * 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(); } }
/** * Initializes all the elements in the Craft Equipment screen. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param craft ID of the selected craft. */ CraftEquipmentState::CraftEquipmentState(Game *game, Base *base, unsigned int craft) : State(game), _sel(0), _base(base), _craft(craft) { // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(288, 16, 16, 176); _txtTitle = new Text(300, 16, 16, 7); _txtItem = new Text(144, 9, 16, 32); _txtStores = new Text(150, 9, 160, 32); _txtAvailable = new Text(110, 9, 16, 24); _txtUsed = new Text(110, 9, 130, 24); _lstEquipment = new TextList(288, 128, 8, 40); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(2)), Palette::backPos, 16); add(_window); add(_btnOk); add(_txtTitle); add(_txtItem); add(_txtStores); add(_txtAvailable); add(_txtUsed); add(_lstEquipment); // Set up objects _window->setColor(Palette::blockOffset(15)+1); _window->setBackground(_game->getResourcePack()->getSurface("BACK04.SCR")); _btnOk->setColor(Palette::blockOffset(15)+1); _btnOk->setText(_game->getLanguage()->getString("STR_OK")); _btnOk->onMouseClick((ActionHandler)&CraftEquipmentState::btnOkClick); _txtTitle->setColor(Palette::blockOffset(15)+1); _txtTitle->setBig(); Craft *c = _base->getCrafts()->at(_craft); std::wstring s; s = _game->getLanguage()->getString("STR_EQUIPMENT_FOR") + c->getName(_game->getLanguage()); _txtTitle->setText(s); _txtItem->setColor(Palette::blockOffset(15)+1); _txtItem->setText(_game->getLanguage()->getString("STR_ITEM")); _txtStores->setColor(Palette::blockOffset(15)+1); _txtStores->setText(_game->getLanguage()->getString("STR_STORES")); _txtAvailable->setColor(Palette::blockOffset(15)+1); _txtAvailable->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss; ss << _game->getLanguage()->getString("STR_SPACE_AVAILABLE") << L'\x01'<< c->getRules()->getSoldiers() - c->getNumSoldiers(); _txtAvailable->setText(ss.str()); _txtUsed->setColor(Palette::blockOffset(15)+1); _txtUsed->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss2; ss2 << _game->getLanguage()->getString("STR_SPACE_USED") << L'\x01'<< c->getNumSoldiers(); _txtUsed->setText(ss2.str()); _lstEquipment->setColor(Palette::blockOffset(13)+10); _lstEquipment->setArrowColor(Palette::blockOffset(15)+1); _lstEquipment->setArrowColumn(203, ARROW_HORIZONTAL); _lstEquipment->setColumns(3, 154, 85, 41); _lstEquipment->setSelectable(true); _lstEquipment->setBackground(_window); _lstEquipment->setMargin(8); _lstEquipment->onLeftArrowPress((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowPress); _lstEquipment->onLeftArrowRelease((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowRelease); _lstEquipment->onRightArrowPress((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowPress); _lstEquipment->onRightArrowRelease((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowRelease); _items.push_back("STR_PISTOL"); _items.push_back("STR_PISTOL_CLIP"); _items.push_back("STR_RIFLE"); _items.push_back("STR_RIFLE_CLIP"); _items.push_back("STR_HEAVY_CANNON"); _items.push_back("STR_HC_AP_AMMO"); _items.push_back("STR_HC_HE_AMMO"); _items.push_back("STR_HC_I_AMMO"); _items.push_back("STR_AUTO_CANNON"); _items.push_back("STR_AC_AP_AMMO"); _items.push_back("STR_AC_HE_AMMO"); _items.push_back("STR_AC_I_AMMO"); _items.push_back("STR_ROCKET_LAUNCHER"); _items.push_back("STR_SMALL_ROCKET"); _items.push_back("STR_LARGE_ROCKET"); _items.push_back("STR_INCENDIARY_ROCKET"); _items.push_back("STR_GRENADE"); _items.push_back("STR_SMOKE_GRENADE"); _items.push_back("STR_ELECTRO_FLARE"); int row = 0; for (std::vector<std::string>::iterator i = _items.begin(); i != _items.end();) { if (_base->getItems()->getItem(*i) == 0 && c->getItems()->getItem(*i) == 0) { i = _items.erase(i); } else { std::wstringstream ss, ss2; ss << _base->getItems()->getItem(*i); ss2 << c->getItems()->getItem(*i); RuleItem *rule = _game->getRuleset()->getItem(*i); std::wstring s = _game->getLanguage()->getString(*i); if (rule->getBattleType() == BT_AMMO) { s.insert(0, L" "); } _lstEquipment->addRow(3, s.c_str(), ss.str().c_str(), ss2.str().c_str()); Uint8 color; if (c->getItems()->getItem(*i) == 0) { if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(row, color); ++i; row++; } } _timerLeft = new Timer(50); _timerLeft->onTimer((StateHandler)&CraftEquipmentState::moveLeft); _timerRight = new Timer(50); _timerRight->onTimer((StateHandler)&CraftEquipmentState::moveRight); }
/** * Initializes all the elements in the Sell/Sack screen. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. */ SellState::SellState(Game *game, Base *base) : State(game), _base(base), _qtys(), _soldiers(), _crafts(), _items(), _sel(0), _total(0), _sOffset(0), _eOffset(0) { // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(148, 16, 8, 176); _btnCancel = new TextButton(148, 16, 164, 176); _txtTitle = new Text(310, 16, 5, 8); _txtSales = new Text(190, 9, 10, 24); _txtFunds = new Text(114, 9, 200, 24); _txtItem = new Text(130, 9, 10, 32); _txtQuantity = new Text(54, 9, 130, 32); _txtSell = new Text(96, 9, 180, 32); _txtValue = new Text(40, 9, 266, 32); _lstItems = new TextList(287, 120, 8, 44); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(0)), Palette::backPos, 16); add(_window); add(_btnOk); add(_btnCancel); add(_txtTitle); add(_txtSales); add(_txtFunds); add(_txtItem); add(_txtQuantity); add(_txtSell); add(_txtValue); add(_lstItems); // Set up objects _window->setColor(Palette::blockOffset(13)+10); _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR")); _btnOk->setColor(Palette::blockOffset(13)+10); _btnOk->setText(_game->getLanguage()->getString("STR_SELL_SACK")); _btnOk->onMouseClick((ActionHandler)&SellState::btnOkClick); _btnCancel->setColor(Palette::blockOffset(13)+10); _btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL")); _btnCancel->onMouseClick((ActionHandler)&SellState::btnCancelClick); _txtTitle->setColor(Palette::blockOffset(13)+10); _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(_game->getLanguage()->getString("STR_SELL_ITEMS_SACK_PERSONNEL")); std::wstring s1 = _game->getLanguage()->getString("STR_VALUE_OF_SALES"); s1 += Text::formatFunding(_total); _txtSales->setColor(Palette::blockOffset(13)+10); _txtSales->setText(s1); std::wstring s2 = _game->getLanguage()->getString("STR_FUNDS"); s2 += Text::formatFunding(_game->getSavedGame()->getFunds()); _txtFunds->setColor(Palette::blockOffset(13)+10); _txtFunds->setText(s2); _txtItem->setColor(Palette::blockOffset(13)+10); _txtItem->setText(_game->getLanguage()->getString("STR_ITEM")); _txtQuantity->setColor(Palette::blockOffset(13)+10); _txtQuantity->setText(_game->getLanguage()->getString("STR_QUANTITY_UC")); _txtSell->setColor(Palette::blockOffset(13)+10); _txtSell->setText(_game->getLanguage()->getString("STR_SELL_SACK")); _txtValue->setColor(Palette::blockOffset(13)+10); _txtValue->setText(_game->getLanguage()->getString("STR_VALUE")); _lstItems->setColor(Palette::blockOffset(13)+10); _lstItems->setArrowColumn(189, ARROW_VERTICAL); _lstItems->setColumns(4, 150, 66, 22, 40); _lstItems->setSelectable(true); _lstItems->setBackground(_window); _lstItems->setMargin(2); _lstItems->onLeftArrowPress((ActionHandler)&SellState::lstItemsLeftArrowPress); _lstItems->onLeftArrowRelease((ActionHandler)&SellState::lstItemsLeftArrowRelease); _lstItems->onLeftArrowClick((ActionHandler)&SellState::lstItemsLeftArrowClick); _lstItems->onRightArrowPress((ActionHandler)&SellState::lstItemsRightArrowPress); _lstItems->onRightArrowRelease((ActionHandler)&SellState::lstItemsRightArrowRelease); _lstItems->onRightArrowClick((ActionHandler)&SellState::lstItemsRightArrowClick); for (std::vector<Soldier*>::iterator i = _base->getSoldiers()->begin(); i != _base->getSoldiers()->end(); ++i) { if ((*i)->getCraft() == 0) { _qtys.push_back(0); _soldiers.push_back(*i); _lstItems->addRow(4, (*i)->getName().c_str(), L"1", L"0", Text::formatFunding(0).c_str()); } } for (std::vector<Craft*>::iterator i = _base->getCrafts()->begin(); i != _base->getCrafts()->end(); ++i) { if ((*i)->getStatus() != "STR_OUT") { _qtys.push_back(0); _crafts.push_back(*i); _lstItems->addRow(4, (*i)->getName(_game->getLanguage()).c_str(), L"1", L"0", Text::formatFunding(0).c_str()); } } if (_base->getAvailableScientists() > 0) { _qtys.push_back(0); _sOffset++; std::wstringstream ss; ss << _base->getAvailableScientists(); _lstItems->addRow(4, _game->getLanguage()->getString("STR_SCIENTIST").c_str(), ss.str().c_str(), L"0", Text::formatFunding(0).c_str()); } if (_base->getAvailableEngineers() > 0) { _qtys.push_back(0); _eOffset++; std::wstringstream ss; ss << _base->getAvailableEngineers(); _lstItems->addRow(4, _game->getLanguage()->getString("STR_ENGINEER").c_str(), ss.str().c_str(), L"0", Text::formatFunding(0).c_str()); } std::vector<std::string> items = _game->getRuleset()->getItemsList(); for (std::vector<std::string>::iterator i = items.begin(); i != items.end(); ++i) { int qty = _base->getItems()->getItem(*i); if (qty > 0) { _qtys.push_back(0); _items.push_back(*i); RuleItem *rule = _game->getRuleset()->getItem(*i); std::wstringstream ss; ss << qty; _lstItems->addRow(4, _game->getLanguage()->getString(*i).c_str(), ss.str().c_str(), L"0", Text::formatFunding(rule->getSellCost()).c_str()); } } _timerInc = new Timer(50); _timerInc->onTimer((StateHandler)&SellState::increase); _timerDec = new Timer(50); _timerDec->onTimer((StateHandler)&SellState::decrease); }
/** * 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(); }
/** * Initializes all the elements in the Sell/Sack screen. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param origin Game section that originated this state. */ SellState::SellState(Base *base, OptionsOrigin origin) : _base(base), _sel(0), _itemOffset(0), _total(0), _hasSci(0), _hasEng(0), _spaceChange(0), _origin(origin) { bool overfull = Options::storageLimitsEnforced && _base->storesOverfull(); // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(overfull? 288:148, 16, overfull? 16:8, 176); _btnCancel = new TextButton(148, 16, 164, 176); _txtTitle = new Text(310, 17, 5, 8); _txtSales = new Text(150, 9, 10, 24); _txtFunds = new Text(150, 9, 160, 24); _txtSpaceUsed = new Text(150, 9, 160, 34); _txtItem = new Text(130, 9, 10, Options::storageLimitsEnforced? 44:33); _txtQuantity = new Text(54, 9, 126, Options::storageLimitsEnforced? 44:33); _txtSell = new Text(96, 9, 180, Options::storageLimitsEnforced? 44:33); _txtValue = new Text(40, 9, 260, Options::storageLimitsEnforced? 44:33); _lstItems = new TextList(287, Options::storageLimitsEnforced? 112:120, 8, Options::storageLimitsEnforced? 55:44); // Set palette setInterface("sellMenu"); _ammoColor = _game->getRuleset()->getInterface("sellMenu")->getElement("ammoColor")->color; add(_window, "window", "sellMenu"); add(_btnOk, "button", "sellMenu"); add(_btnCancel, "button", "sellMenu"); add(_txtTitle, "text", "sellMenu"); add(_txtSales, "text", "sellMenu"); add(_txtFunds, "text", "sellMenu"); add(_txtSpaceUsed, "text", "sellMenu"); add(_txtItem, "text", "sellMenu"); add(_txtQuantity, "text", "sellMenu"); add(_txtSell, "text", "sellMenu"); add(_txtValue, "text", "sellMenu"); add(_lstItems, "list", "sellMenu"); centerAllSurfaces(); // Set up objects _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR")); _btnOk->setText(tr("STR_SELL_SACK")); _btnOk->onMouseClick((ActionHandler)&SellState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&SellState::btnOkClick, Options::keyOk); _btnCancel->setText(tr("STR_CANCEL")); _btnCancel->onMouseClick((ActionHandler)&SellState::btnCancelClick); _btnCancel->onKeyboardPress((ActionHandler)&SellState::btnCancelClick, Options::keyCancel); if (overfull) { _btnCancel->setVisible(false); _btnOk->setVisible(false); } _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(tr("STR_SELL_ITEMS_SACK_PERSONNEL")); _txtSales->setText(tr("STR_VALUE_OF_SALES").arg(Text::formatFunding(_total))); _txtFunds->setText(tr("STR_FUNDS").arg(Text::formatFunding(_game->getSavedGame()->getFunds()))); _txtSpaceUsed->setVisible(Options::storageLimitsEnforced); std::wostringstream ss5; ss5 << _base->getUsedStores() << ":" << _base->getAvailableStores(); _txtSpaceUsed->setText(ss5.str()); _txtSpaceUsed->setText(tr("STR_SPACE_USED").arg(ss5.str())); _txtItem->setText(tr("STR_ITEM")); _txtQuantity->setText(tr("STR_QUANTITY_UC")); _txtSell->setText(tr("STR_SELL_SACK")); _txtValue->setText(tr("STR_VALUE")); _lstItems->setArrowColumn(182, ARROW_VERTICAL); _lstItems->setColumns(4, 156, 54, 24, 53); _lstItems->setSelectable(true); _lstItems->setBackground(_window); _lstItems->setMargin(2); _lstItems->onLeftArrowPress((ActionHandler)&SellState::lstItemsLeftArrowPress); _lstItems->onLeftArrowRelease((ActionHandler)&SellState::lstItemsLeftArrowRelease); _lstItems->onLeftArrowClick((ActionHandler)&SellState::lstItemsLeftArrowClick); _lstItems->onRightArrowPress((ActionHandler)&SellState::lstItemsRightArrowPress); _lstItems->onRightArrowRelease((ActionHandler)&SellState::lstItemsRightArrowRelease); _lstItems->onRightArrowClick((ActionHandler)&SellState::lstItemsRightArrowClick); _lstItems->onMousePress((ActionHandler)&SellState::lstItemsMousePress); for (std::vector<Soldier*>::iterator i = _base->getSoldiers()->begin(); i != _base->getSoldiers()->end(); ++i) { if ((*i)->getCraft() == 0) { _qtys.push_back(0); _soldiers.push_back(*i); _lstItems->addRow(4, (*i)->getName(true).c_str(), L"1", L"0", Text::formatFunding(0).c_str()); ++_itemOffset; } } for (std::vector<Craft*>::iterator i = _base->getCrafts()->begin(); i != _base->getCrafts()->end(); ++i) { if ((*i)->getStatus() != "STR_OUT") { _qtys.push_back(0); _crafts.push_back(*i); _lstItems->addRow(4, (*i)->getName(_game->getLanguage()).c_str(), L"1", L"0", Text::formatFunding((*i)->getRules()->getSellCost()).c_str()); ++_itemOffset; } } if (_base->getAvailableScientists() > 0) { _qtys.push_back(0); _hasSci = 1; std::wostringstream ss; ss << _base->getAvailableScientists(); _lstItems->addRow(4, tr("STR_SCIENTIST").c_str(), ss.str().c_str(), L"0", Text::formatFunding(0).c_str()); ++_itemOffset; } if (_base->getAvailableEngineers() > 0) { _qtys.push_back(0); _hasEng = 1; std::wostringstream ss; ss << _base->getAvailableEngineers(); _lstItems->addRow(4, tr("STR_ENGINEER").c_str(), ss.str().c_str(), L"0", Text::formatFunding(0).c_str()); ++_itemOffset; } const std::vector<std::string> &items = _game->getRuleset()->getItemsList(); for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) { int qty = _base->getItems()->getItem(*i); if (Options::storageLimitsEnforced && origin == OPT_BATTLESCAPE) { for (std::vector<Transfer*>::iterator j = _base->getTransfers()->begin(); j != _base->getTransfers()->end(); ++j) { if ((*j)->getItems() == *i) { qty += (*j)->getQuantity(); } } for (std::vector<Craft*>::iterator j = _base->getCrafts()->begin(); j != _base->getCrafts()->end(); ++j) { qty += (*j)->getItems()->getItem(*i); } } if (qty > 0 && (Options::canSellLiveAliens || !_game->getRuleset()->getItem(*i)->isAlien())) { _qtys.push_back(0); _items.push_back(*i); RuleItem *rule = _game->getRuleset()->getItem(*i); std::wostringstream ss; ss << qty; std::wstring item = tr(*i); if (rule->getBattleType() == BT_AMMO || (rule->getBattleType() == BT_NONE && rule->getClipSize() > 0)) { item.insert(0, L" "); _lstItems->addRow(4, item.c_str(), ss.str().c_str(), L"0", Text::formatFunding(rule->getSellCost()).c_str()); _lstItems->setRowColor(_qtys.size() - 1, _ammoColor); } else { _lstItems->addRow(4, item.c_str(), ss.str().c_str(), L"0", Text::formatFunding(rule->getSellCost()).c_str()); } } } _timerInc = new Timer(250); _timerInc->onTimer((StateHandler)&SellState::increase); _timerDec = new Timer(250); _timerDec->onTimer((StateHandler)&SellState::decrease); }
/** * Initializes all the elements in the Action Menu window. * @param game Pointer to the core game. * @param action Pointer to the action. * @param x Position on the x-axis. * @param y position on the y-axis. */ ActionMenuState::ActionMenuState(Game *game, BattleAction *action, int x, int y) : State(game), _action(action) { _screen = false; for (int i = 0; i < 6; ++i) { _actionMenu[i] = new ActionMenuItem(i, _game->getResourcePack()->getFont("Big.fnt"), x, y); add(_actionMenu[i]); _actionMenu[i]->setVisible(false); _actionMenu[i]->onMouseClick((ActionHandler)&ActionMenuState::btnActionMenuItemClick); } // Build up the popup menu int id = 0; RuleItem *weapon = _action->weapon->getRules(); // throwing (if not a fixed weapon) if (!weapon->isFixed()) { addItem(BA_THROW, "STR_THROW", &id); } // priming if ((weapon->getBattleType() == BT_GRENADE || weapon->getBattleType() == BT_PROXIMITYGRENADE) && _action->weapon->getExplodeTurn() == 0) { addItem(BA_PRIME, "STR_PRIME_GRENADE", &id); } if (weapon->getBattleType() == BT_FIREARM) { if (weapon->isWaypoint()) { addItem(BA_LAUNCH, "STR_LAUNCH_MISSILE", &id); } else { if (weapon->getAccuracyAuto() != 0) { addItem(BA_AUTOSHOT, "STR_AUTO_SHOT", &id); } if (weapon->getAccuracySnap() != 0) { addItem(BA_SNAPSHOT, "STR_SNAP_SHOT", &id); } if (weapon->getAccuracyAimed() != 0) { addItem(BA_AIMEDSHOT, "STR_AIMED_SHOT", &id); } } } else if (weapon->getBattleType() == BT_MELEE) { // stun rod if (weapon->getDamageType() == DT_STUN) { addItem(BA_HIT, "STR_STUN", &id); } else // melee weapon { addItem(BA_HIT, "STR_HIT", &id); } } // special items else if (weapon->getBattleType() == BT_MEDIKIT) { addItem(BA_USE, "STR_USE_MEDI_KIT", &id); } else if (weapon->getBattleType() == BT_SCANNER) { addItem(BA_USE, "STR_USE_SCANNER", &id); } else if (weapon->getBattleType() == BT_PSIAMP && _action->actor->getStats()->psiSkill > 0) { addItem(BA_MINDCONTROL, "STR_MIND_CONTROL", &id); addItem(BA_PANIC, "STR_PANIC_UNIT", &id); } else if (weapon->getBattleType() == BT_MINDPROBE) { addItem(BA_USE, "STR_USE_MIND_PROBE", &id); } }
/** * Initializes all the elements in the Craft Equipment screen. * @param game Pointer to the core game. * @param base Pointer to the base to get info from. * @param craft ID of the selected craft. */ CraftEquipmentState::CraftEquipmentState(Game *game, Base *base, size_t craft) : State(game), _sel(0), _base(base), _craft(craft) { bool allowChangeListValuesByMouseWheel=Options::getBool("allowChangeListValuesByMouseWheel"); _changeValueByMouseWheel = Options::getInt("changeValueByMouseWheel"); // Create objects _window = new Window(this, 320, 200, 0, 0); _btnOk = new TextButton(288, 16, 16, 176); _txtTitle = new Text(300, 16, 16, 7); _txtItem = new Text(144, 9, 16, 32); _txtStores = new Text(150, 9, 160, 32); _txtAvailable = new Text(110, 9, 16, 24); _txtUsed = new Text(110, 9, 130, 24); _txtCrew = new Text(71, 9, 244, 24); _lstEquipment = new TextList(288, 128, 8, 40); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(2)), Palette::backPos, 16); add(_window); add(_btnOk); add(_txtTitle); add(_txtItem); add(_txtStores); add(_txtAvailable); add(_txtUsed); add(_txtCrew); add(_lstEquipment); // Set up objects _window->setColor(Palette::blockOffset(15)+1); _window->setBackground(_game->getResourcePack()->getSurface("BACK04.SCR")); _btnOk->setColor(Palette::blockOffset(15)+1); _btnOk->setText(_game->getLanguage()->getString("STR_OK")); _btnOk->onMouseClick((ActionHandler)&CraftEquipmentState::btnOkClick); _txtTitle->setColor(Palette::blockOffset(15)+1); _txtTitle->setBig(); Craft *c = _base->getCrafts()->at(_craft); _txtTitle->setText(tr("STR_EQUIPMENT_FOR_craftname").arg(c->getName(_game->getLanguage()))); _txtItem->setColor(Palette::blockOffset(15)+1); _txtItem->setText(_game->getLanguage()->getString("STR_ITEM")); _txtStores->setColor(Palette::blockOffset(15)+1); _txtStores->setText(_game->getLanguage()->getString("STR_STORES")); _txtAvailable->setColor(Palette::blockOffset(15)+1); _txtAvailable->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss; ss << _game->getLanguage()->getString("STR_SPACE_AVAILABLE") << L'\x01'<< c->getSpaceAvailable(); _txtAvailable->setText(ss.str()); _txtUsed->setColor(Palette::blockOffset(15)+1); _txtUsed->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss2; ss2 << _game->getLanguage()->getString("STR_SPACE_USED") << L'\x01'<< c->getSpaceUsed(); _txtUsed->setText(ss2.str()); _txtCrew->setColor(Palette::blockOffset(15)+1); _txtCrew->setSecondaryColor(Palette::blockOffset(13)); std::wstringstream ss3; ss3 << _game->getLanguage()->getString("STR_SOLDIERS_UC") << ">" << L'\x01'<< c->getNumSoldiers(); _txtCrew->setText(ss3.str()); _lstEquipment->setColor(Palette::blockOffset(13)+10); _lstEquipment->setArrowColor(Palette::blockOffset(15)+1); _lstEquipment->setArrowColumn(203, ARROW_HORIZONTAL); _lstEquipment->setColumns(3, 154, 85, 41); _lstEquipment->setSelectable(true); _lstEquipment->setBackground(_window); _lstEquipment->setMargin(8); if (allowChangeListValuesByMouseWheel) _lstEquipment->setAllowScrollOnArrowButtons(false); _lstEquipment->onLeftArrowPress((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowPress); _lstEquipment->onLeftArrowRelease((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowRelease); _lstEquipment->onLeftArrowClick((ActionHandler)&CraftEquipmentState::lstEquipmentLeftArrowClick); _lstEquipment->onRightArrowPress((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowPress); _lstEquipment->onRightArrowRelease((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowRelease); _lstEquipment->onRightArrowClick((ActionHandler)&CraftEquipmentState::lstEquipmentRightArrowClick); if (allowChangeListValuesByMouseWheel) _lstEquipment->onMousePress((ActionHandler)&CraftEquipmentState::lstEquipmentMousePress); int row = 0; const std::vector<std::string> &items = _game->getRuleset()->getItemsList(); for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) { // CHEAP HACK TO HIDE HWP AMMO if ((*i).substr(0, 8) == "STR_HWP_") continue; RuleItem *rule = _game->getRuleset()->getItem(*i); int cQty = 0; if (rule->isFixed()) { cQty = c->getVehicleCount(*i); } else { cQty = c->getItems()->getItem(*i); } if (rule->getBigSprite() > -1 && rule->getBattleType() != BT_NONE && rule->getBattleType() != BT_CORPSE && _game->getSavedGame()->isResearched(rule->getRequirements()) && (_base->getItems()->getItem(*i) > 0 || cQty > 0)) { _items.push_back(*i); std::wstringstream ss, ss2; ss << _base->getItems()->getItem(*i); ss2 << cQty; std::wstring s = _game->getLanguage()->getString(*i); if (rule->getBattleType() == BT_AMMO) { s.insert(0, L" "); } _lstEquipment->addRow(3, s.c_str(), ss.str().c_str(), ss2.str().c_str()); Uint8 color; if (cQty == 0) { if (rule->getBattleType() == BT_AMMO) { color = Palette::blockOffset(15)+6; } else { color = Palette::blockOffset(13)+10; } } else { color = Palette::blockOffset(13); } _lstEquipment->setRowColor(row, color); ++row; } } _timerLeft = new Timer(50); _timerLeft->onTimer((StateHandler)&CraftEquipmentState::moveLeft); _timerRight = new Timer(50); _timerRight->onTimer((StateHandler)&CraftEquipmentState::moveRight); }
/** * Execute the action corresponding with this action menu item. * @param action Pointer to an action. */ void ActionMenuState::btnActionMenuItemClick(Action *action) { int btnID = -1; RuleItem *weapon = _action->weapon->getRules(); // got to find out which button was pressed for (int i = 0; i < 10 && btnID == -1; ++i) { if (action->getSender() == _actionMenu[i]) { btnID = i; } } if (btnID != -1) { _action->type = _actionMenu[btnID]->getAction(); _action->TU = _actionMenu[btnID]->getTUs(); if (_action->type == BA_PRIME) { if (Options::getBool("battleAltGrenade") || weapon->getBattleType() == BT_PROXIMITYGRENADE) { _action->value = 1; _game->popState(); } else { _game->pushState(new PrimeGrenadeState(_game, _action)); } } else if (_action->type == BA_USE && weapon->getBattleType() == BT_MEDIKIT) { BattleUnit *targetUnit = NULL; std::vector<BattleUnit*> *const units (_game->getSavedGame()->getBattleGame()->getUnits()); for(std::vector<BattleUnit*>::const_iterator i = units->begin (); i != units->end () && !targetUnit; ++i) { // we can heal a unit that is at the same position, unconscious and healable(=woundable) if ((*i)->getPosition() == _action->actor->getPosition() && *i != _action->actor && (*i)->getStatus () == STATUS_UNCONSCIOUS && (*i)->isWoundable()) { targetUnit = *i; } } if (!targetUnit) { Position p; Pathfinding::directionToVector(_action->actor->getDirection(), &p); Tile * tile (_game->getSavedGame()->getBattleGame()->getTile(_action->actor->getPosition() + p)); if (tile->getUnit() && tile->getUnit()->isWoundable()) targetUnit = tile->getUnit(); } if (targetUnit) { _game->pushState (new MedikitState (_game, targetUnit, _action)); } else { _action->result = "STR_THERE_IS_NO_ONE_THERE"; _game->popState(); } } else if (_action->type == BA_USE && weapon->getBattleType() == BT_SCANNER) { // spend TUs first, then show the scanner if (_action->actor->spendTimeUnits (_action->TU, false)) { _game->pushState (new ScannerState (_game, _action)); } else { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; _game->popState(); } } else if (_action->type == BA_LAUNCH) { // check beforehand if we have enough time units if (_action->TU > _action->actor->getTimeUnits()) { _action->result = "STR_NOT_ENOUGH_TIME_UNITS"; } else if (_action->weapon->getAmmoItem() ==0 || (_action->weapon->getAmmoItem() && _action->weapon->getAmmoItem()->getAmmoQuantity() == 0)) { _action->result = "STR_NO_AMMUNITION_LOADED"; } else { _action->targeting = true; } _game->popState(); } else if ((_action->type == BA_STUN || _action->type == BA_HIT) && weapon->getBattleType() == BT_MELEE) { BattleUnit *targetUnit = NULL; Position p; Pathfinding::directionToVector(_action->actor->getDirection(), &p); Tile * tile (_game->getSavedGame()->getBattleGame()->getTile(_action->actor->getPosition() + p)); if (tile->getUnit()) targetUnit = tile->getUnit(); if (targetUnit) { _game->popState(); } else { _action->result = "STR_THERE_IS_NO_ONE_THERE"; _game->popState(); } } else { _action->targeting = true; _game->popState(); } } }