1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Support creature setting up

This commit is contained in:
nordsoft 2022-09-07 05:33:48 +04:00
parent 289ae8a1f8
commit c3355aa976
3 changed files with 98 additions and 20 deletions

View File

@ -570,7 +570,10 @@ void CInsertObjectOperation::execute()
{ {
obj->id = ObjectInstanceID(map->objects.size()); obj->id = ObjectInstanceID(map->objects.size());
do
{
map->setUniqueInstanceName(obj); map->setUniqueInstanceName(obj);
} while(vstd::contains(map->instanceNames, obj->instanceName));
map->addNewObject(obj); map->addNewObject(obj);
} }

View File

@ -18,14 +18,30 @@ Initializer::Initializer(CMap * m, CGObjectInstance * o) : map(m)
INIT_OBJ_TYPE(CGMine); INIT_OBJ_TYPE(CGMine);
INIT_OBJ_TYPE(CGDwelling); INIT_OBJ_TYPE(CGDwelling);
INIT_OBJ_TYPE(CGTownInstance); INIT_OBJ_TYPE(CGTownInstance);
INIT_OBJ_TYPE(CGCreature);
INIT_OBJ_TYPE(CGHeroInstance); INIT_OBJ_TYPE(CGHeroInstance);
} }
bool stringToBool(const QString & s)
{
if(s == "TRUE")
return true;
//if(s == "FALSE")
return false;
}
void Initializer::initialize(CArmedInstance * o) void Initializer::initialize(CArmedInstance * o)
{ {
if(!o) return; if(!o) return;
} }
void Initializer::initialize(CGCreature * o)
{
if(!o) return;
o->character = CGCreature::Character::HOSTILE;
}
void Initializer::initialize(CGDwelling * o) void Initializer::initialize(CGDwelling * o)
{ {
if(!o) return; if(!o) return;
@ -166,6 +182,17 @@ void Inspector::updateProperties(CGResource * o)
addProperty("Amount", o->amount, false); addProperty("Amount", o->amount, false);
} }
void Inspector::updateProperties(CGCreature * o)
{
if(!o) return;
addProperty("Message", o->message, false);
addProperty<CGCreature::Character>("Character", (CGCreature::Character)o->character, false);
addProperty("Never flees", o->neverFlees, false);
addProperty("Not growing", o->notGrowingTeam, false);
addProperty("Artifact reward", o->gainedArtifact); //TODO: implement in setProperty
//addProperty("Resources reward", o->resources); //TODO: implement in setProperty
}
void Inspector::updateProperties() void Inspector::updateProperties()
@ -191,6 +218,7 @@ void Inspector::updateProperties()
UPDATE_OBJ_PROPERTIES(CGShipyard); UPDATE_OBJ_PROPERTIES(CGShipyard);
UPDATE_OBJ_PROPERTIES(CGDwelling); UPDATE_OBJ_PROPERTIES(CGDwelling);
UPDATE_OBJ_PROPERTIES(CGTownInstance); UPDATE_OBJ_PROPERTIES(CGTownInstance);
UPDATE_OBJ_PROPERTIES(CGCreature);
UPDATE_OBJ_PROPERTIES(CGHeroInstance); UPDATE_OBJ_PROPERTIES(CGHeroInstance);
table->show(); table->show();
@ -219,20 +247,19 @@ void Inspector::setProperty(const QString & key, const QVariant & value)
SET_PROPERTIES(CGResource); SET_PROPERTIES(CGResource);
SET_PROPERTIES(CGDwelling); SET_PROPERTIES(CGDwelling);
SET_PROPERTIES(CGGarrison); SET_PROPERTIES(CGGarrison);
SET_PROPERTIES(CGCreature);
SET_PROPERTIES(CGHeroInstance); SET_PROPERTIES(CGHeroInstance);
SET_PROPERTIES(CGShipyard); SET_PROPERTIES(CGShipyard);
} }
void Inspector::setProperty(CArmedInstance * object, const QString & key, const QVariant & value) void Inspector::setProperty(CArmedInstance * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
} }
void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
if(key == "Town name") if(key == "Town name")
object->name = value.toString().toStdString(); object->name = value.toString().toStdString();
@ -240,8 +267,7 @@ void Inspector::setProperty(CGTownInstance * object, const QString & key, const
void Inspector::setProperty(CGMine * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGMine * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
if(key == "Productivity") if(key == "Productivity")
object->producedQuantity = value.toString().toInt(); object->producedQuantity = value.toString().toInt();
@ -249,43 +275,64 @@ void Inspector::setProperty(CGMine * object, const QString & key, const QVariant
void Inspector::setProperty(CGArtifact * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGArtifact * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
} }
void Inspector::setProperty(CGDwelling * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGDwelling * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
} }
void Inspector::setProperty(CGGarrison * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGGarrison * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
} }
void Inspector::setProperty(CGHeroInstance * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGHeroInstance * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
} }
void Inspector::setProperty(CGShipyard * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGShipyard * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
} }
void Inspector::setProperty(CGResource * object, const QString & key, const QVariant & value) void Inspector::setProperty(CGResource * object, const QString & key, const QVariant & value)
{ {
if(!object) if(!object) return;
return;
if(key == "Amount") if(key == "Amount")
object->amount = value.toString().toInt(); object->amount = value.toString().toInt();
} }
void Inspector::setProperty(CGCreature * object, const QString & key, const QVariant & value)
{
if(!object) return;
if(key == "Message")
object->message = value.toString().toStdString();
if(key == "Character")
{
//COMPLIANT = 0, FRIENDLY = 1, AGRESSIVE = 2, HOSTILE = 3, SAVAGE = 4
if(value == "COMPLIANT")
object->character = CGCreature::Character::COMPLIANT;
if(value == "FRIENDLY")
object->character = CGCreature::Character::FRIENDLY;
if(value == "AGRESSIVE")
object->character = CGCreature::Character::AGRESSIVE;
if(value == "HOSTILE")
object->character = CGCreature::Character::HOSTILE;
if(value == "SAVAGE")
object->character = CGCreature::Character::SAVAGE;
}
if(key == "Never flees")
object->neverFlees = stringToBool(value.toString());
if(key == "Not growing")
object->notGrowingTeam = stringToBool(value.toString());
}
//===============IMPLEMENT PROPERTY VALUE TYPE============================ //===============IMPLEMENT PROPERTY VALUE TYPE============================
QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value) QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
{ {
@ -367,6 +414,31 @@ QTableWidgetItem * Inspector::addProperty(const Res::ERes & value)
return new QTableWidgetItem(str); return new QTableWidgetItem(str);
} }
QTableWidgetItem * Inspector::addProperty(CGCreature::Character value)
{
QString str;
switch (value) {
case CGCreature::Character::COMPLIANT:
str = "COMPLIANT";
break;
case CGCreature::Character::FRIENDLY:
str = "FRIENDLY";
break;
case CGCreature::Character::AGRESSIVE:
str = "AGRESSIVE";
break;
case CGCreature::Character::HOSTILE:
str = "HOSTILE";
break;
case CGCreature::Character::SAVAGE:
str = "SAVAGE";
break;
default:
break;
}
return new QTableWidgetItem(str);
}
//======================================================================== //========================================================================
Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t) Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t)

View File

@ -32,6 +32,7 @@ public:
DECLARE_OBJ_TYPE(CGDwelling); DECLARE_OBJ_TYPE(CGDwelling);
DECLARE_OBJ_TYPE(CGGarrison); DECLARE_OBJ_TYPE(CGGarrison);
DECLARE_OBJ_TYPE(CGHeroInstance); DECLARE_OBJ_TYPE(CGHeroInstance);
DECLARE_OBJ_TYPE(CGCreature);
Initializer(CMap *, CGObjectInstance *); Initializer(CMap *, CGObjectInstance *);
@ -53,6 +54,7 @@ protected:
DECLARE_OBJ_PROPERTY_METHODS(CGDwelling); DECLARE_OBJ_PROPERTY_METHODS(CGDwelling);
DECLARE_OBJ_PROPERTY_METHODS(CGGarrison); DECLARE_OBJ_PROPERTY_METHODS(CGGarrison);
DECLARE_OBJ_PROPERTY_METHODS(CGHeroInstance); DECLARE_OBJ_PROPERTY_METHODS(CGHeroInstance);
DECLARE_OBJ_PROPERTY_METHODS(CGCreature);
//===============DECLARE PROPERTY VALUE TYPE============================== //===============DECLARE PROPERTY VALUE TYPE==============================
QTableWidgetItem * addProperty(unsigned int value); QTableWidgetItem * addProperty(unsigned int value);
@ -64,6 +66,7 @@ protected:
QTableWidgetItem * addProperty(const Res::ERes & value); QTableWidgetItem * addProperty(const Res::ERes & value);
QTableWidgetItem * addProperty(bool value); QTableWidgetItem * addProperty(bool value);
QTableWidgetItem * addProperty(CGObjectInstance * value); QTableWidgetItem * addProperty(CGObjectInstance * value);
QTableWidgetItem * addProperty(CGCreature::Character value);
//===============END OF DECLARATION======================================= //===============END OF DECLARATION=======================================
public: public: