1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-31 22:59:54 +02:00

Possibility to set hero patrol radius in map editor

This commit is contained in:
godric3 2024-10-28 18:30:30 +01:00
parent 3a45e6dae1
commit a9e04428c8
3 changed files with 23 additions and 7 deletions

View File

@ -1749,21 +1749,20 @@ void CGHeroInstance::serializeJsonOptions(JsonSerializeFormat & handler)
CArmedInstance::serializeJsonOptions(handler); CArmedInstance::serializeJsonOptions(handler);
{ {
static constexpr int NO_PATROLING = -1; int rawPatrolRadius = NO_PATROLLING;
int rawPatrolRadius = NO_PATROLING;
if(handler.saving) if(handler.saving)
{ {
rawPatrolRadius = patrol.patrolling ? patrol.patrolRadius : NO_PATROLING; rawPatrolRadius = patrol.patrolling ? patrol.patrolRadius : NO_PATROLLING;
} }
handler.serializeInt("patrolRadius", rawPatrolRadius, NO_PATROLING); handler.serializeInt("patrolRadius", rawPatrolRadius, NO_PATROLLING);
if(!handler.saving) if(!handler.saving)
{ {
patrol.patrolling = (rawPatrolRadius > NO_PATROLING); patrol.patrolling = (rawPatrolRadius > NO_PATROLLING);
patrol.initialPos = visitablePos(); patrol.initialPos = visitablePos();
patrol.patrolRadius = (rawPatrolRadius > NO_PATROLING) ? rawPatrolRadius : 0; patrol.patrolRadius = (rawPatrolRadius > NO_PATROLLING) ? rawPatrolRadius : 0;
} }
} }
} }

View File

@ -92,6 +92,7 @@ public:
static constexpr si32 UNINITIALIZED_MANA = -1; static constexpr si32 UNINITIALIZED_MANA = -1;
static constexpr ui32 UNINITIALIZED_MOVEMENT = -1; static constexpr ui32 UNINITIALIZED_MOVEMENT = -1;
static constexpr auto UNINITIALIZED_EXPERIENCE = std::numeric_limits<TExpType>::max(); static constexpr auto UNINITIALIZED_EXPERIENCE = std::numeric_limits<TExpType>::max();
static constexpr int NO_PATROLLING = -1;
//std::vector<const CArtifact*> artifacts; //hero's artifacts from bag //std::vector<const CArtifact*> artifacts; //hero's artifacts from bag
//std::map<ui16, const CArtifact*> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 //std::map<ui16, const CArtifact*> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
@ -99,7 +100,7 @@ public:
struct DLL_LINKAGE Patrol struct DLL_LINKAGE Patrol
{ {
Patrol(){patrolling=false;initialPos=int3();patrolRadius=-1;}; Patrol(){patrolling=false;initialPos=int3();patrolRadius=NO_PATROLLING;};
bool patrolling; bool patrolling;
int3 initialPos; int3 initialPos;
ui32 patrolRadius; ui32 patrolRadius;

View File

@ -335,6 +335,15 @@ void Inspector::updateProperties(CGHeroInstance * o)
} }
addProperty("Hero type", o->getHeroTypeID().hasValue() ? o->getHeroType()->getNameTranslated() : "", delegate, false); addProperty("Hero type", o->getHeroTypeID().hasValue() ? o->getHeroType()->getNameTranslated() : "", delegate, false);
} }
{
const int maxRadius = 60;
auto * patrolDelegate = new InspectorDelegate;
patrolDelegate->options = { {QObject::tr("No patrol"), QVariant::fromValue(CGHeroInstance::NO_PATROLLING)} };
for(int i = 0; i <= maxRadius; ++i)
patrolDelegate->options.push_back({ QObject::tr("%1 tile(s)").arg(i), QVariant::fromValue(i) });
auto patrolRadiusText = o->patrol.patrolling ? QObject::tr("%1 tile(s)").arg(o->patrol.patrolRadius) : QObject::tr("No patrol");
addProperty("Patrol radius", patrolRadiusText, patrolDelegate, false);
}
} }
void Inspector::updateProperties(CGTownInstance * o) void Inspector::updateProperties(CGTownInstance * o)
@ -711,6 +720,13 @@ void Inspector::setProperty(CGHeroInstance * o, const QString & key, const QVari
o->randomizeArmy(o->getHeroType()->heroClass->faction); o->randomizeArmy(o->getHeroType()->heroClass->faction);
updateProperties(); //updating other properties after change updateProperties(); //updating other properties after change
} }
if(key == "Patrol radius")
{
o->patrol.patrolRadius = value.toInt();
if(o->patrol.patrolRadius != CGHeroInstance::NO_PATROLLING)
o->patrol.patrolling = true;
}
} }
void Inspector::setProperty(CGShipyard * o, const QString & key, const QVariant & value) void Inspector::setProperty(CGShipyard * o, const QString & key, const QVariant & value)