mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
Draft of new Event conditions
This commit is contained in:
parent
dc5ad7d7b3
commit
4bcfb8c27d
@ -325,7 +325,7 @@ void CGObjectInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
if(handler.saving)
|
||||
{
|
||||
handler.serializeString("type", typeName);
|
||||
handler.serializeString("subType", subTypeName);
|
||||
handler.serializeString("subtype", subTypeName);
|
||||
}
|
||||
|
||||
handler.serializeNumeric("x", pos.x);
|
||||
|
@ -63,6 +63,7 @@ EventCondition::EventCondition(EWinLoseType condition):
|
||||
object(nullptr),
|
||||
value(-1),
|
||||
objectType(-1),
|
||||
objectSubtype(-1),
|
||||
position(-1, -1, -1),
|
||||
condition(condition)
|
||||
{
|
||||
@ -72,6 +73,7 @@ EventCondition::EventCondition(EWinLoseType condition, si32 value, si32 objectTy
|
||||
object(nullptr),
|
||||
value(value),
|
||||
objectType(objectType),
|
||||
objectSubtype(-1),
|
||||
position(position),
|
||||
condition(condition)
|
||||
{}
|
||||
|
@ -98,6 +98,7 @@ struct DLL_LINKAGE PlayerInfo
|
||||
struct DLL_LINKAGE EventCondition
|
||||
{
|
||||
enum EWinLoseType {
|
||||
//internal use, deprecated
|
||||
HAVE_ARTIFACT, // type - required artifact
|
||||
HAVE_CREATURES, // type - creatures to collect, value - amount to collect
|
||||
HAVE_RESOURCES, // type - resource ID, value - amount to collect
|
||||
@ -105,19 +106,28 @@ struct DLL_LINKAGE EventCondition
|
||||
CONTROL, // position - position of object, optional, type - type of object
|
||||
DESTROY, // position - position of object, optional, type - type of object
|
||||
TRANSPORT, // position - where artifact should be transported, type - type of artifact
|
||||
|
||||
//map format version pre 1.0
|
||||
DAYS_PASSED, // value - number of days from start of the game
|
||||
IS_HUMAN, // value - 0 = player is AI, 1 = player is human
|
||||
DAYS_WITHOUT_TOWN, // value - how long player can live without town, 0=instakill
|
||||
STANDARD_WIN, // normal defeat all enemies condition
|
||||
CONST_VALUE // condition that always evaluates to "value" (0 = false, 1 = true)
|
||||
CONST_VALUE, // condition that always evaluates to "value" (0 = false, 1 = true)
|
||||
|
||||
//map format version 1.0+
|
||||
HAVE_0,
|
||||
HAVE_BUILDING_0,
|
||||
DESTROY_0
|
||||
};
|
||||
|
||||
EventCondition(EWinLoseType condition = STANDARD_WIN);
|
||||
EventCondition(EWinLoseType condition, si32 value, si32 objectType, int3 position = int3(-1, -1, -1));
|
||||
|
||||
const CGObjectInstance * object; // object that was at specified position on start
|
||||
const CGObjectInstance * object; // object that was at specified position or with instance name on start
|
||||
si32 value;
|
||||
si32 objectType;
|
||||
si32 objectSubtype;
|
||||
std::string objectInstanceName;
|
||||
int3 position;
|
||||
EWinLoseType condition;
|
||||
|
||||
@ -129,6 +139,11 @@ struct DLL_LINKAGE EventCondition
|
||||
h & objectType;
|
||||
h & position;
|
||||
h & condition;
|
||||
if(version > 759)
|
||||
{
|
||||
h & objectSubtype;
|
||||
h & objectInstanceName;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -44,13 +44,16 @@ namespace HeaderDetail
|
||||
|
||||
namespace TriggeredEventsDetail
|
||||
{
|
||||
static const std::array<std::string, 12> conditionNames =
|
||||
static const std::array<std::string, 15> conditionNames =
|
||||
{
|
||||
"haveArtifact", "haveCreatures", "haveResources", "haveBuilding",
|
||||
"control", "destroy", "transport", "daysPassed",
|
||||
"isHuman", "daysWithoutTown", "standardWin", "constValue"
|
||||
"isHuman", "daysWithoutTown", "standardWin", "constValue",
|
||||
|
||||
"have_0", "haveBuilding_0", "destroy_0"
|
||||
};
|
||||
|
||||
|
||||
static const std::array<std::string, 2> typeNames = { "victory", "defeat" };
|
||||
|
||||
static EventCondition JsonToCondition(const JsonNode & node)
|
||||
@ -88,6 +91,12 @@ namespace TriggeredEventsDetail
|
||||
event.position.y = position.at(1).Float();
|
||||
event.position.z = position.at(2).Float();
|
||||
}
|
||||
|
||||
// if(!data["subtype"].isNull())
|
||||
// {
|
||||
// //todo
|
||||
// }
|
||||
// event.objectInstanceName = data["object"].String();
|
||||
}
|
||||
return event;
|
||||
}
|
||||
@ -452,7 +461,9 @@ void CMapFormatJson::writeOptions(JsonSerializer & handler)
|
||||
CMapPatcher::CMapPatcher(JsonNode stream):
|
||||
input(stream)
|
||||
{
|
||||
|
||||
//todo: update map patches and change this
|
||||
fileVersionMajor = 0;
|
||||
fileVersionMinor = 0;
|
||||
}
|
||||
|
||||
void CMapPatcher::patchMapHeader(std::unique_ptr<CMapHeader> & header)
|
||||
@ -540,19 +551,19 @@ void CMapLoaderJson::readHeader(const bool complete)
|
||||
//do not use map field here, use only mapHeader
|
||||
JsonNode header = getFromArchive(HEADER_FILE_NAME);
|
||||
|
||||
int versionMajor = header["versionMajor"].Float();
|
||||
fileVersionMajor = header["versionMajor"].Float();
|
||||
|
||||
if(versionMajor != VERSION_MAJOR)
|
||||
if(fileVersionMajor != VERSION_MAJOR)
|
||||
{
|
||||
logGlobal->errorStream() << "Unsupported map format version: " << versionMajor;
|
||||
logGlobal->errorStream() << "Unsupported map format version: " << fileVersionMajor;
|
||||
throw std::runtime_error("Unsupported map format version");
|
||||
}
|
||||
|
||||
int versionMinor = header["versionMinor"].Float();
|
||||
fileVersionMinor = header["versionMinor"].Float();
|
||||
|
||||
if(versionMinor > VERSION_MINOR)
|
||||
if(fileVersionMinor > VERSION_MINOR)
|
||||
{
|
||||
logGlobal->traceStream() << "Too new map format revision: " << versionMinor << ". This map should work but some of map features may be ignored.";
|
||||
logGlobal->traceStream() << "Too new map format revision: " << fileVersionMinor << ". This map should work but some of map features may be ignored.";
|
||||
}
|
||||
|
||||
JsonDeserializer handler(header);
|
||||
@ -759,7 +770,7 @@ void CMapLoaderJson::MapObjectLoader::construct()
|
||||
}
|
||||
else if(subTypeName.empty())
|
||||
{
|
||||
logGlobal->errorStream() << "Object subType missing";
|
||||
logGlobal->errorStream() << "Object subtype missing";
|
||||
logGlobal->debugStream() << configuration;
|
||||
return;
|
||||
}
|
||||
@ -839,7 +850,8 @@ CMapSaverJson::CMapSaverJson(CInputOutputStream * stream):
|
||||
ioApi(new CProxyIOApi(buffer)),
|
||||
saver(ioApi, "_")
|
||||
{
|
||||
|
||||
fileVersionMajor = VERSION_MAJOR;
|
||||
fileVersionMinor = VERSION_MINOR;
|
||||
}
|
||||
|
||||
CMapSaverJson::~CMapSaverJson()
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
|
||||
static const std::string HEADER_FILE_NAME;
|
||||
static const std::string OBJECTS_FILE_NAME;
|
||||
|
||||
int fileVersionMajor;
|
||||
int fileVersionMinor;
|
||||
protected:
|
||||
|
||||
/** ptr to the map object which gets filled by data from the buffer or written to buffer */
|
||||
|
Loading…
x
Reference in New Issue
Block a user