1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Fix hero type for random hero

This commit is contained in:
nordsoft 2023-09-10 16:57:41 +02:00
parent e912a2db38
commit 5136305455
5 changed files with 18 additions and 11 deletions

View File

@ -135,12 +135,14 @@ void Initializer::initialize(CGHeroInstance * o)
}
}
if(!o->type)
o->type = VLC->heroh->objects.at(o->subID);
o->gender = o->type->gender;
o->portrait = o->type->imageIndex;
o->randomizeArmy(o->type->heroClass->faction);
if(o->type)
{
// o->type = VLC->heroh->objects.at(o->subID);
o->gender = o->type->gender;
o->portrait = o->type->imageIndex;
o->randomizeArmy(o->type->heroClass->faction);
}
}
void Initializer::initialize(CGTownInstance * o)
@ -250,7 +252,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
addProperty("Owner", o->tempOwner, o->ID == Obj::PRISON); //field is not editable for prison
addProperty<int>("Experience", o->exp, false);
addProperty("Hero class", o->type->heroClass->getNameTranslated(), true);
addProperty("Hero class", o->type ? o->type->heroClass->getNameTranslated() : "", true);
{ //Sex
auto * delegate = new InspectorDelegate;
@ -261,6 +263,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
addProperty("Biography", o->biographyCustom, new MessageDelegate, false);
addProperty("Portrait", o->portrait, false);
if(o->type)
{ //Hero type
auto * delegate = new InspectorDelegate;
for(int i = 0; i < VLC->heroh->objects.size(); ++i)

View File

@ -126,7 +126,8 @@ protected:
table->setRowCount(row + 1);
table->setItem(row, 0, itemKey);
table->setItem(row, 1, itemValue);
table->setItemDelegateForRow(row, delegate);
if(delegate)
table->setItemDelegateForRow(row, delegate);
++row;
}
}

View File

@ -145,7 +145,8 @@ void MapController::repairMap()
nih->subID = 0;
}
nih->type = type;
if(obj->ID != Obj::RANDOM_HERO)
nih->type = type;
if(nih->ID == Obj::HERO) //not prison
nih->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, type->heroClass->getIndex())->getTemplates().front();

View File

@ -397,6 +397,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
bool tab = false;
if(sc->selectionObjectsView.selectionMode == SelectionObjectsLayer::MOVEMENT)
{
tab = sc->selectionObjectsView.shift.isNull();
controller->commitObjectShift(sc->level);
}
else
@ -405,7 +406,6 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
sc->selectionObjectsView.shift = QPoint(0, 0);
sc->selectionObjectsView.draw();
tab = true;
//check if we have only one object
}
auto selection = sc->selectionObjectsView.getSelection();
if(selection.size() == 1)
@ -463,7 +463,9 @@ void MapView::dropEvent(QDropEvent * event)
QString errorMsg;
if(controller->canPlaceObject(sc->level, sc->selectionObjectsView.newObject, errorMsg))
{
auto * obj = sc->selectionObjectsView.newObject;
controller->commitObjectCreate(sc->level);
emit openObjectProperties(obj, false);
}
else
{

View File

@ -131,7 +131,7 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
if(!allHeroesOnMap.insert(ins->type).second)
issues.emplace_back(QString(tr("Hero %1 has duplicate on map")).arg(ins->type->getNameTranslated().c_str()), false);
}
else
else if(ins->ID != Obj::RANDOM_HERO)
issues.emplace_back(QString(tr("Hero %1 has an empty type and must be removed")).arg(ins->instanceName.c_str()), true);
}