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

Templates can now use multiple configurations of treasure piles.

This commit is contained in:
DjWarmonger 2014-06-07 15:51:03 +02:00
parent b3a39f4920
commit 81a64a8e67
3 changed files with 103 additions and 47 deletions

View File

@ -10,7 +10,10 @@
{ {
"type" : "playerStart", "size" : 1, "owner" : 1, "type" : "playerStart", "size" : 1, "owner" : 1,
"playerTowns" : { "castles" : 1 }, "neutralTowns" : { "towns" : 1 }, "townsAreSameType" : true, "playerTowns" : { "castles" : 1 }, "neutralTowns" : { "towns" : 1 }, "townsAreSameType" : true,
"treasure" : {"min" : 1500, "max": 3000} "treasure" : [
{"min" : 2100, "max": 3000, "density" : 5},
{"min" : 300, "max": 1500, "density" : 10}
]
}, },
"2" : "2" :
{ {
@ -33,7 +36,10 @@
"5" : "5" :
{ {
"type" : "treasure", "size" : 2, "terrainTypes" : [ "sand" ], "neutralTowns" : { "castles" : 1 }, "type" : "treasure", "size" : 2, "terrainTypes" : [ "sand" ], "neutralTowns" : { "castles" : 1 },
"treasure" : {"min" : 9000, "max": 10000} "treasure" : [
{"min" : 9000, "max": 10000, "density" : 3},
{"min" : 6000, "max": 10000, "density" : 15}
]
} }
}, },
"connections" : "connections" :
@ -54,7 +60,10 @@
{ {
"type" : "playerStart", "size" : 1, "owner" : 1, "type" : "playerStart", "size" : 1, "owner" : 1,
"playerTowns" : { "castles" : 1 }, "playerTowns" : { "castles" : 1 },
"treasure" : {"min" : 500, "max": 2000} "treasure" : [
{"min" : 400, "max": 1000, "density" : 16},
{"min" : 1500, "max": 2500, "density" : 4}
]
}, },
"2" : "2" :
{ {
@ -65,7 +74,10 @@
"3" : "3" :
{ {
"type" : "treasure", "size" : 2, "neutralTowns" : { "towns" : 1 }, "townTypeLikeZone" : "1", "type" : "treasure", "size" : 2, "neutralTowns" : { "towns" : 1 }, "townTypeLikeZone" : "1",
"treasure" : {"min" : 2000, "max": 4000} "treasure" : [
{"min" : 2000, "max": 4000, "density" : 15},
{"min" : 4000, "max": 5000, "density" : 5}
]
}, },
"4" : "4" :
{ {
@ -75,7 +87,10 @@
"5" : "5" :
{ {
"type" : "treasure", "size" : 3, "neutralTowns" : { "castles" : 1 }, "terrainTypes" : [ "sand" ], "type" : "treasure", "size" : 3, "neutralTowns" : { "castles" : 1 }, "terrainTypes" : [ "sand" ],
"treasure" : {"min" : 11000, "max": 12000} "treasure" : [
{"min" : 11000, "max": 12000, "density" : 5},
{"min" : 6000, "max": 11000, "density" : 10}
]
} }
}, },
"connections" : "connections" :
@ -98,7 +113,10 @@
{ {
"type" : "playerStart", "size" : 3, "owner" : 1, "type" : "playerStart", "size" : 3, "owner" : 1,
"playerTowns" : { "castles" : 1 }, "playerTowns" : { "castles" : 1 },
"treasure" : {"min" : 1000, "max": 2000} "treasure" : [
{"min" : 300, "max": 2000, "density": 15},
{"min" : 2100, "max": 2500, "density": 5}
]
}, },
"2" : "2" :
{ {
@ -112,13 +130,19 @@
"playerTowns" : { "castles" : 1 }, "playerTowns" : { "castles" : 1 },
"treasureLikeZone" : 1 "treasureLikeZone" : 1
}, },
"4" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasure" : {"min" : 3000, "max": 10000} }, "4" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasure" : [
{"min" : 3000, "max": 10000, "density" : 12},
{"min" : 6000, "max": 10000, "density" : 6}
]},
"5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasureLikeZone" : 4}, "5" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "1", "treasureLikeZone" : 4},
"6" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "2", "treasureLikeZone" : 4 }, "6" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "2", "treasureLikeZone" : 4 },
"7" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "2", "treasureLikeZone" : 4 }, "7" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "2", "treasureLikeZone" : 4 },
"8" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3", "treasureLikeZone" : 4 }, "8" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3", "treasureLikeZone" : 4 },
"9" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3", "treasureLikeZone" : 4 }, "9" : { "type" : "treasure", "size" : 1, "terrainTypeLikeZone" : "3", "treasureLikeZone" : 4 },
"10" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasure" : {"min" : 21000, "max": 25000} }, "10" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasure" : [
{"min" : 21000, "max": 25000, "density" : 3},
{"min" : 10000, "max": 21000, "density" : 10}
]},
"11" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasureLikeZone" : 10 }, "11" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasureLikeZone" : 10 },
"12" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasureLikeZone" : 10 } "12" : { "type" : "treasure", "size" : 1, "neutralTowns" : { "towns" : 1 }, "treasureLikeZone" : 10 }
}, },

View File

@ -68,13 +68,27 @@ void CJsonRmgTemplateLoader::loadTemplates()
if (!zoneNode["treasure"].isNull()) if (!zoneNode["treasure"].isNull())
{ {
//TODO: parse vector of different treasure settings //TODO: parse vector of different treasure settings
auto treasureInfo = zoneNode["treasure"].Struct(); if (zoneNode["treasure"].getType() == JsonNode::DATA_STRUCT)
{ {
CTreasureInfo ti; auto treasureInfo = zoneNode["treasure"].Struct();
ti.min = treasureInfo["min"].Float(); {
ti.max = treasureInfo["max"].Float(); CTreasureInfo ti;
ti.density = 1; //TODO: use me ti.min = treasureInfo["min"].Float();
zone->addTreasureInfo(ti); ti.max = treasureInfo["max"].Float();
ti.density = treasureInfo["density"].Float(); //TODO: use me
zone->addTreasureInfo(ti);
}
}
else if (zoneNode["treasure"].getType() == JsonNode::DATA_VECTOR)
{
for (auto treasureInfo : zoneNode["treasure"].Vector())
{
CTreasureInfo ti;
ti.min = treasureInfo["min"].Float();
ti.max = treasureInfo["max"].Float();
ti.density = treasureInfo["density"].Float();
zone->addTreasureInfo(ti);
}
} }
} }

View File

@ -471,11 +471,29 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
int maxValue = 5000; int maxValue = 5000;
int minValue = 1500; int minValue = 1500;
//TODO: choose random treasure info based on density
if (treasureInfo.size()) if (treasureInfo.size())
{ {
maxValue = treasureInfo.front().max; //roulette wheel
minValue = treasureInfo.front().min; std::vector<std::pair<ui16, CTreasureInfo>> tresholds;
ui16 total = 0;
//TODO: precalculate density chance for entire zone
for (auto ti : treasureInfo)
{
total += ti.density;
tresholds.push_back (std::make_pair (total, ti));
}
int r = gen->rand.nextInt (1, total);
for (auto t : tresholds)
{
if (r <= t.first)
{
maxValue = t.second.max;
minValue = t.second.min;
break;
}
}
} }
int currentValue = 0; int currentValue = 0;
@ -1094,37 +1112,37 @@ void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen)
} }
//non-removable object for test //non-removable object for test
oi.generateObject = [gen]() -> CGObjectInstance * //oi.generateObject = [gen]() -> CGObjectInstance *
{ //{
auto obj = new CGMagicWell(); // auto obj = new CGMagicWell();
obj->ID = Obj::MAGIC_WELL; // obj->ID = Obj::MAGIC_WELL;
obj->subID = 0; // obj->subID = 0;
return obj; // return obj;
}; //};
oi.value = 250; //oi.value = 250;
oi.probability = 100; //oi.probability = 100;
possibleObjects.push_back (oi); //possibleObjects.push_back (oi);
oi.generateObject = [gen]() -> CGObjectInstance * //oi.generateObject = [gen]() -> CGObjectInstance *
{ //{
auto obj = new CGObelisk(); // auto obj = new CGObelisk();
obj->ID = Obj::OBELISK; // obj->ID = Obj::OBELISK;
obj->subID = 0; // obj->subID = 0;
return obj; // return obj;
}; //};
oi.value = 3500; //oi.value = 3500;
oi.probability = 200; //oi.probability = 200;
possibleObjects.push_back (oi); //possibleObjects.push_back (oi);
oi.generateObject = [gen]() -> CGObjectInstance * //oi.generateObject = [gen]() -> CGObjectInstance *
{ //{
auto obj = new CBank(); // auto obj = new CBank();
obj->ID = Obj::CREATURE_BANK; // obj->ID = Obj::CREATURE_BANK;
obj->subID = 5; //naga bank // obj->subID = 5; //naga bank
return obj; // return obj;
}; //};
oi.value = 3000; //oi.value = 3000;
oi.probability = 100; //oi.probability = 100;
possibleObjects.push_back (oi); //possibleObjects.push_back (oi);
} }