mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Some vic/loss conditions for editor
This commit is contained in:
parent
4e21aab76a
commit
a3413eefce
@ -24,9 +24,12 @@ int expiredDate(const QString & date)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
for(auto component : date.split(" "))
|
for(auto component : date.split(" "))
|
||||||
{
|
{
|
||||||
result += component.left(component.lastIndexOf('d')).toInt();
|
int days = component.left(component.lastIndexOf('d')).toInt();
|
||||||
result += component.left(component.lastIndexOf('w')).toInt() * 7;
|
int weeks = component.left(component.lastIndexOf('w')).toInt();
|
||||||
result += component.left(component.lastIndexOf('m')).toInt() * 28;
|
int months = component.left(component.lastIndexOf('m')).toInt();
|
||||||
|
result += days > 0 ? days - 1 : 0;
|
||||||
|
result += (weeks > 0 ? weeks - 1 : 0) * 7;
|
||||||
|
result += (months > 0 ? months - 1 : 0) * 28;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -54,6 +57,27 @@ QString expiredDate(int date)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int3 posFromJson(const JsonNode & json)
|
||||||
|
{
|
||||||
|
return int3(json.Vector()[0].Integer(), json.Vector()[1].Integer(), json.Vector()[2].Integer());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<JsonNode> linearJsonArray(const JsonNode & json)
|
||||||
|
{
|
||||||
|
std::vector<JsonNode> result;
|
||||||
|
if(json.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||||
|
result.push_back(json);
|
||||||
|
if(json.getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||||
|
{
|
||||||
|
for(auto & node : json.Vector())
|
||||||
|
{
|
||||||
|
auto subvector = linearJsonArray(node);
|
||||||
|
result.insert(result.end(), subvector.begin(), subvector.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
|
MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::MapSettings),
|
ui(new Ui::MapSettings),
|
||||||
@ -215,25 +239,35 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
|
|||||||
|
|
||||||
if(ev.identifier == "specialVictory")
|
if(ev.identifier == "specialVictory")
|
||||||
{
|
{
|
||||||
auto json = ev.trigger.toJson(conditionToJson);
|
auto readjson = ev.trigger.toJson(conditionToJson);
|
||||||
switch(json["condition"].Integer())
|
auto linearNodes = linearJsonArray(readjson);
|
||||||
|
|
||||||
|
for(auto & json : linearNodes)
|
||||||
{
|
{
|
||||||
case EventCondition::HAVE_ARTIFACT: {
|
switch(json["condition"].Integer())
|
||||||
ui->victoryComboBox->setCurrentIndex(1);
|
{
|
||||||
assert(victoryTypeWidget);
|
case EventCondition::HAVE_ARTIFACT: {
|
||||||
victoryTypeWidget->setCurrentIndex(json["objectType"].Integer());
|
ui->victoryComboBox->setCurrentIndex(1);
|
||||||
break;
|
assert(victoryTypeWidget);
|
||||||
}
|
victoryTypeWidget->setCurrentIndex(json["objectType"].Integer());
|
||||||
|
break;
|
||||||
case EventCondition::HAVE_CREATURES: {
|
}
|
||||||
ui->victoryComboBox->setCurrentIndex(2);
|
|
||||||
assert(victoryTypeWidget);
|
case EventCondition::HAVE_CREATURES: {
|
||||||
assert(victoryValueWidget);
|
ui->victoryComboBox->setCurrentIndex(2);
|
||||||
victoryTypeWidget->setCurrentIndex(json["objectType"].Integer());
|
assert(victoryTypeWidget);
|
||||||
victoryValueWidget->setText(QString::number(json["value"].Integer()));
|
assert(victoryValueWidget);
|
||||||
break;
|
victoryTypeWidget->setCurrentIndex(json["objectType"].Integer());
|
||||||
}
|
victoryValueWidget->setText(QString::number(json["value"].Integer()));
|
||||||
};
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case EventCondition::IS_HUMAN: {
|
||||||
|
ui->onlyForHumansCheck->setChecked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,41 +278,54 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
|
|||||||
|
|
||||||
if(ev.identifier == "specialDefeat")
|
if(ev.identifier == "specialDefeat")
|
||||||
{
|
{
|
||||||
auto json = ev.trigger.toJson(conditionToJson);
|
auto readjson = ev.trigger.toJson(conditionToJson);
|
||||||
switch(json["condition"].Integer())
|
auto linearNodes = linearJsonArray(readjson);
|
||||||
|
|
||||||
|
for(auto & json : linearNodes)
|
||||||
{
|
{
|
||||||
case EventCondition::CONTROL: {
|
switch(json["condition"].Integer())
|
||||||
if(json["objectType"].Integer() == Obj::TOWN)
|
{
|
||||||
{
|
case EventCondition::CONTROL: {
|
||||||
ui->loseComboBox->setCurrentIndex(1);
|
if(json["objectType"].Integer() == Obj::TOWN)
|
||||||
//assert(loseValueWidget);
|
{
|
||||||
//loseValueWidget->setText(QString::number(json["value"].Integer()));
|
ui->loseComboBox->setCurrentIndex(1);
|
||||||
|
assert(loseTypeWidget);
|
||||||
|
int townIdx = getTownByPos(posFromJson(json["position"]));
|
||||||
|
if(townIdx >= 0)
|
||||||
|
{
|
||||||
|
auto idx = loseTypeWidget->findData(townIdx);
|
||||||
|
loseTypeWidget->setCurrentIndex(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(json["objectType"].Integer() == Obj::HERO)
|
||||||
|
{
|
||||||
|
ui->loseComboBox->setCurrentIndex(2);
|
||||||
|
//assert(loseValueWidget);
|
||||||
|
//loseValueWidget->setText(QString::number(json["value"].Integer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(json["objectType"].Integer() == Obj::HERO)
|
|
||||||
{
|
case EventCondition::DAYS_PASSED: {
|
||||||
ui->loseComboBox->setCurrentIndex(2);
|
ui->loseComboBox->setCurrentIndex(3);
|
||||||
//assert(loseValueWidget);
|
assert(loseValueWidget);
|
||||||
//loseValueWidget->setText(QString::number(json["value"].Integer()));
|
loseValueWidget->setText(expiredDate(json["value"].Integer()));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case EventCondition::DAYS_WITHOUT_TOWN: {
|
||||||
}
|
ui->loseComboBox->setCurrentIndex(4);
|
||||||
|
assert(loseValueWidget);
|
||||||
case EventCondition::DAYS_PASSED: {
|
loseValueWidget->setText(QString::number(json["value"].Integer()));
|
||||||
ui->loseComboBox->setCurrentIndex(3);
|
break;
|
||||||
assert(loseValueWidget);
|
|
||||||
loseValueWidget->setText(expiredDate(json["value"].Integer()));
|
case EventCondition::IS_HUMAN:
|
||||||
break;
|
break; //ignore as always applicable for defeat conditions
|
||||||
}
|
}
|
||||||
|
|
||||||
case EventCondition::DAYS_WITHOUT_TOWN: {
|
};
|
||||||
ui->loseComboBox->setCurrentIndex(4);
|
}
|
||||||
assert(loseValueWidget);
|
|
||||||
loseValueWidget->setText(QString::number(json["value"].Integer()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,6 +346,46 @@ MapSettings::~MapSettings()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MapSettings::getTownName(int townObjectIdx)
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
if(auto town = dynamic_cast<CGTownInstance*>(controller.map()->objects[townObjectIdx].get()))
|
||||||
|
{
|
||||||
|
auto * ctown = town->town;
|
||||||
|
if(!ctown)
|
||||||
|
ctown = VLC->townh->randomTown;
|
||||||
|
|
||||||
|
name = ctown->faction ? town->getObjectName() : town->name + ", (random)";
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> MapSettings::getTownIndexes() const
|
||||||
|
{
|
||||||
|
std::vector<int> result;
|
||||||
|
for(int i = 0; i < controller.map()->objects.size(); ++i)
|
||||||
|
{
|
||||||
|
if(auto town = dynamic_cast<CGTownInstance*>(controller.map()->objects[i].get()))
|
||||||
|
{
|
||||||
|
result.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MapSettings::getTownByPos(const int3 & pos)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < controller.map()->objects.size(); ++i)
|
||||||
|
{
|
||||||
|
if(auto town = dynamic_cast<CGTownInstance*>(controller.map()->objects[i].get()))
|
||||||
|
{
|
||||||
|
if(town->pos == pos)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void MapSettings::on_pushButton_clicked()
|
void MapSettings::on_pushButton_clicked()
|
||||||
{
|
{
|
||||||
controller.map()->name = ui->mapNameEdit->text().toStdString();
|
controller.map()->name = ui->mapNameEdit->text().toStdString();
|
||||||
@ -436,7 +523,7 @@ void MapSettings::on_pushButton_clicked()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int lossCondition = ui->victoryComboBox->currentIndex() - 1;
|
int lossCondition = ui->loseComboBox->currentIndex() - 1;
|
||||||
|
|
||||||
TriggeredEvent specialDefeat;
|
TriggeredEvent specialDefeat;
|
||||||
specialDefeat.effect.type = EventEffect::DEFEAT;
|
specialDefeat.effect.type = EventEffect::DEFEAT;
|
||||||
@ -448,6 +535,19 @@ void MapSettings::on_pushButton_clicked()
|
|||||||
|
|
||||||
switch(lossCondition)
|
switch(lossCondition)
|
||||||
{
|
{
|
||||||
|
case 0: {
|
||||||
|
EventExpression::OperatorNone noneOf;
|
||||||
|
EventCondition cond(EventCondition::CONTROL);
|
||||||
|
cond.objectType = Obj::TOWN;
|
||||||
|
assert(loseTypeWidget);
|
||||||
|
int townIdx = loseTypeWidget->currentData().toInt();
|
||||||
|
cond.position = controller.map()->objects[townIdx]->pos;
|
||||||
|
noneOf.expressions.push_back(cond);
|
||||||
|
specialDefeat.onFulfill = VLC->generaltexth->allTexts[251];
|
||||||
|
specialDefeat.trigger = EventExpression(noneOf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 2: {
|
case 2: {
|
||||||
EventCondition cond(EventCondition::DAYS_PASSED);
|
EventCondition cond(EventCondition::DAYS_PASSED);
|
||||||
assert(loseValueWidget);
|
assert(loseValueWidget);
|
||||||
@ -460,7 +560,7 @@ void MapSettings::on_pushButton_clicked()
|
|||||||
case 3: {
|
case 3: {
|
||||||
EventCondition cond(EventCondition::DAYS_WITHOUT_TOWN);
|
EventCondition cond(EventCondition::DAYS_WITHOUT_TOWN);
|
||||||
assert(loseValueWidget);
|
assert(loseValueWidget);
|
||||||
cond.value = victoryValueWidget->text().toInt();
|
cond.value = loseValueWidget->text().toInt();
|
||||||
specialDefeat.onFulfill = VLC->generaltexth->allTexts[7];
|
specialDefeat.onFulfill = VLC->generaltexth->allTexts[7];
|
||||||
specialDefeat.trigger = EventExpression(cond);
|
specialDefeat.trigger = EventExpression(cond);
|
||||||
break;
|
break;
|
||||||
@ -522,7 +622,6 @@ void MapSettings::on_victoryComboBox_currentIndexChanged(int index)
|
|||||||
|
|
||||||
victoryValueWidget = new QLineEdit;
|
victoryValueWidget = new QLineEdit;
|
||||||
ui->victoryParamsLayout->addWidget(victoryValueWidget);
|
ui->victoryParamsLayout->addWidget(victoryValueWidget);
|
||||||
victoryValueWidget->setInputMask("9000");
|
|
||||||
victoryValueWidget->setText("1");
|
victoryValueWidget->setText("1");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -551,8 +650,8 @@ void MapSettings::on_loseComboBox_currentIndexChanged(int index)
|
|||||||
case 0: { //EventCondition::CONTROL (Obj::TOWN)
|
case 0: { //EventCondition::CONTROL (Obj::TOWN)
|
||||||
loseTypeWidget = new QComboBox;
|
loseTypeWidget = new QComboBox;
|
||||||
ui->loseParamsLayout->addWidget(loseTypeWidget);
|
ui->loseParamsLayout->addWidget(loseTypeWidget);
|
||||||
//for(int i = 0; i < controller.map()->allowedArtifact.size(); ++i)
|
for(int i : getTownIndexes())
|
||||||
//loseTypeWidget->addItem(QString::fromStdString(VLC->arth->objects[i]->getName()), QVariant::fromValue(i));
|
loseTypeWidget->addItem(tr(getTownName(i).c_str()), QVariant::fromValue(i));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,11 @@ private slots:
|
|||||||
void on_loseComboBox_currentIndexChanged(int index);
|
void on_loseComboBox_currentIndexChanged(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
std::string getTownName(int townObjectIdx);
|
||||||
|
std::vector<int> getTownIndexes() const;
|
||||||
|
int getTownByPos(const int3 & pos);
|
||||||
|
|
||||||
Ui::MapSettings *ui;
|
Ui::MapSettings *ui;
|
||||||
MapController & controller;
|
MapController & controller;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user