1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Start working on Triggered Events

This commit is contained in:
AlexVinS 2015-08-14 05:22:24 +03:00 committed by AlexVinS
parent b683c29b6e
commit 11af00bcdf
3 changed files with 54 additions and 10 deletions

View File

@ -17,13 +17,13 @@
#include "../CModHandler.h"
#include "../VCMI_Lib.h"
static const std::string conditionNames[] = {
static const std::array<std::string, 12> conditionNames = {
"haveArtifact", "haveCreatures", "haveResources", "haveBuilding",
"control", "destroy", "transport", "daysPassed",
"isHuman", "daysWithoutTown", "standardWin", "constValue"
};
static const std::string typeNames[] = { "victory", "defeat" };
static const std::array<std::string, 2> typeNames = { "victory", "defeat" };
static EventCondition JsonToCondition(const JsonNode & node)
{
@ -50,6 +50,11 @@ static EventCondition JsonToCondition(const JsonNode & node)
return event;
}
static void ConditionToJson(const EventCondition& event, JsonNode& dest)
{
}
///CMapFormatJson
const int CMapFormatJson::VERSION_MAJOR = 1;
const int CMapFormatJson::VERSION_MINOR = 0;
@ -85,6 +90,32 @@ void CMapFormatJson::readTriggeredEvent(TriggeredEvent & event, const JsonNode &
event.trigger = EventExpression(source["condition"], JsonToCondition); // logical expression
}
void CMapFormatJson::writeTriggeredEvents(JsonNode& output)
{
output["victoryString"].String() = map->victoryMessage;
output["victoryIconIndex"].Float() = map->victoryIconIndex;
output["defeatString"].String() = map->defeatMessage;
output["defeatIconIndex"].Float() = map->defeatIconIndex;
// JsonMap & triggeredEvents = output["triggeredEvents"].Struct();
//
// for(auto event : map->triggeredEvents)
// writeTriggeredEvent(event, triggeredEvents[event.identifier]);
}
void CMapFormatJson::writeTriggeredEvent(const TriggeredEvent& event, JsonNode& dest)
{
dest["message"].String() = event.onFulfill;
dest["description"].String() = event.description;
dest["effect"]["type"].String() = typeNames.at(event.effect.type);
dest["effect"]["messageToSend"].String() = event.effect.toOtherMessage;
}
///CMapPatcher
CMapPatcher::CMapPatcher(JsonNode stream):
input(stream)
@ -296,6 +327,10 @@ void CMapSaverJson::saveHeader()
header["difficulty"].String() = difficultyMap.at(map->difficulty);
header["levelLimit"].Float() = map->levelLimit;
writeTriggeredEvents(header);
//todo: player info
//todo: allowedHeroes;
//todo: placeholdedHeroes;

View File

@ -33,7 +33,7 @@ protected:
CMap * map;
/**
* ptr to the map header object which gets filled by data from the buffer or written to buffer.
* ptr to the map header object which gets filled by data from the buffer.
* (when loading map and mapHeader point to the same object)
*/
std::unique_ptr<CMapHeader> mapHeader;
@ -43,10 +43,20 @@ protected:
*/
void readTriggeredEvents(const JsonNode & input);
/**
* Writes triggered events, including victory/loss conditions
*/
void writeTriggeredEvents(JsonNode & output);
/**
* Reads one of triggered events
*/
void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
/**
* Writes one of triggered events
*/
void writeTriggeredEvent(const TriggeredEvent & event, JsonNode & dest);
};
class DLL_LINKAGE CMapPatcher : public CMapFormatJson, public IMapPatcher

View File

@ -42,6 +42,11 @@ bool operator!=(const PlayerInfo & actual, const PlayerInfo & expected)
void MapComparer::compareHeader()
{
//map size parameters are vital for further checks
VCMI_REQUIRE_FIELD_EQUAL(height);
VCMI_REQUIRE_FIELD_EQUAL(width);
VCMI_REQUIRE_FIELD_EQUAL(twoLevel);
VCMI_CHECK_FIELD_EQUAL_P(name);
VCMI_CHECK_FIELD_EQUAL_P(description);
VCMI_CHECK_FIELD_EQUAL_P(difficulty);
@ -54,12 +59,6 @@ void MapComparer::compareHeader()
BOOST_CHECK_EQUAL_COLLECTIONS(actual->players.begin(), actual->players.end(), expected->players.begin(), expected->players.end());
//map size parameters are vital for further checks
VCMI_REQUIRE_FIELD_EQUAL(height);
VCMI_REQUIRE_FIELD_EQUAL(width);
VCMI_REQUIRE_FIELD_EQUAL(twoLevel);
BOOST_ERROR("Not implemented");
}