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

Bonusing objects are now configured in json

This commit is contained in:
Ivan Savenko 2023-01-23 01:05:10 +02:00
parent bfd6c40f25
commit 62e127fb59
11 changed files with 449 additions and 473 deletions

View File

@ -82,9 +82,6 @@ void AIMemory::markObjectVisited(const CGObjectInstance * obj)
if(dynamic_cast<const CGVisitableOPH *>(obj)) //we may want to visit it with another hero
return;
if(dynamic_cast<const CGBonusingObject *>(obj)) //or another time
return;
if(obj->ID == Obj::MONSTER)
return;

View File

@ -1618,10 +1618,10 @@ void VCAI::markObjectVisited(const CGObjectInstance * obj)
if(dynamic_cast<const CGVisitableOPH *>(obj)) //we may want to visit it with another hero
return;
if(dynamic_cast<const CGBonusingObject *>(obj)) //or another time
return;
if(obj->ID == Obj::MONSTER)
return;
alreadyVisited.insert(obj);
}

View File

@ -54,7 +54,8 @@
"config/objects/rewardable.json",
"config/objects/rewardablePickable.json",
"config/objects/rewardableOnceVisitable.json",
"config/objects/rewardableOncePerHero.json"
"config/objects/rewardableOncePerHero.json",
"config/objects/rewardableBonusing.json"
],
"artifacts" :

View File

@ -83,253 +83,5 @@
}
}
}
},
"buoy" : {
"index" : 11,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPBUOY"],
"visit" : ["MORALE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"value" : 100,
"rarity" : 100
}
}
}
},
"swanPond" : {
"index" : 14,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"visit" : ["LUCK"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
}
}
}
},
"faerieRing" : {
"index" : 28,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPFAER"],
"visit" : ["LUCK"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
}
}
}
},
"fountainOfFortune" : {
"index" : 30,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPFOUN"],
"visit" : ["LUCK"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
}
}
}
},
"fountainOfYouth" : {
"index" : 31,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPFALL"],
"visit" : ["MORALE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 50
}
}
}
},
"idolOfFortune" : {
"index" : 38,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"visit" : ["LUCK"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
}
},
"object1" : {//WoG?
"index" : 1
}
}
},
"mermaids" : {
"index" : 52,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"visit" : ["LUCK"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"value" : 100,
"rarity" : 20
}
}
}
},
"oasis" : {
"index" : 56,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"visit" : ["MORALE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 50
}
}
}
},
"stables" : {
"index" : 94,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPHORS"],
"visit" : ["STORE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 200,
"rmg" : {
"zoneLimit" : 1,
"value" : 200,
"rarity" : 40
}
}
}
},
"temple" : {
"index" : 96,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPSANC"],
"visit" : ["TEMPLE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
}
}
}
},
"rallyFlag" : {
"index" : 64,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"ambient" : ["LOOPFLAG"],
"visit" : ["MORALE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
}
}
}
},
"wateringHole" : {//waters
"index" : 110,
"handler": "bonusingObject",
"base" : {
"sounds" : {
"visit" : ["MORALE"]
}
},
"types" : {
"object" : {
"index" : 0,
"aiValue" : 500,
"rmg" : {
"zoneLimit" : 1,
"value" : 500,
"rarity" : 50
}
}
}
}
}

View File

@ -0,0 +1,431 @@
{
/// These are objects that covered by concept of "configurable object" and have their entire configuration in this config
"buoy" : {
"index" : 11,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPBUOY"],
"visit" : ["MORALE"]
}
},
"types" : {
"buoy" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"value" : 100,
"rarity" : 100
},
"blockedVisitable" : true,
"onVisitedMessage" : 22,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 21,
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 94 } ]
}
]
}
}
},
"swanPond" : {
"index" : 14,
"handler": "configurable",
"base" : {
"sounds" : {
"visit" : ["LUCK"]
}
},
"types" : {
"swanPond" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
},
"onVisitedMessage" : 30,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 29,
"movePercentage" : 0,
"bonuses" : [ { "type" : "LUCK", "val" : 2, "duration" : "ONE_BATTLE", "desription" : 67 } ]
}
]
}
}
},
"faerieRing" : {
"index" : 28,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPFAER"],
"visit" : ["LUCK"]
}
},
"types" : {
"faerieRing" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
},
"onVisitedMessage" : 50,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 49,
"bonuses" : [ { "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 71 } ]
}
]
}
}
},
"fountainOfFortune" : {
"index" : 30,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPFOUN"],
"visit" : ["LUCK"]
}
},
"types" : {
"fountainOfFortune" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
},
"onVisitedMessage" : 56,
"visitMode" : "bonus",
"selectMode" : "selectRandom",
"rewards" : [
{
"message" : 55,
"bonuses" : [ { "type" : "LUCK", "val" : -1, "duration" : "ONE_BATTLE", "desription" : 69 } ] // NOTE: strings has %s placeholder for morale value
},
{
"message" : 55,
"bonuses" : [ { "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 69 } ] // NOTE: strings has %s placeholder for morale value
},
{
"message" : 55,
"bonuses" : [ { "type" : "LUCK", "val" : 2, "duration" : "ONE_BATTLE", "desription" : 69 } ] // NOTE: strings has %s placeholder for morale value
},
{
"message" : 55,
"bonuses" : [ { "type" : "LUCK", "val" : 3, "duration" : "ONE_BATTLE", "desription" : 69 } ] // NOTE: strings has %s placeholder for morale value
},
]
}
}
},
"fountainOfYouth" : {
"index" : 31,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPFALL"],
"visit" : ["MORALE"]
}
},
"types" : {
"fountainOfYouth" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 50
},
"onVisitedMessage" : 58,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 57,
"movePoints" : 400,
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 103 } ]
}
]
}
}
},
"idolOfFortune" : {
"index" : 38,
"handler": "configurable",
"base" : {
"sounds" : {
"visit" : ["LUCK"]
}
},
"types" : {
"idolOfFortune" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
},
"onVisitedMessage" : 63,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 62,
"limiter" : { "dayOfWeek" : 1 },
"bonuses" : [ { "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 } ]
},
{
"message" : 62,
"limiter" : { "dayOfWeek" : 2 },
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 } ]
},
{
"message" : 62,
"limiter" : { "dayOfWeek" : 3 },
"bonuses" : [ { "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 } ]
},
{
"message" : 62,
"limiter" : { "dayOfWeek" : 4 },
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 } ]
},
{
"message" : 62,
"limiter" : { "dayOfWeek" : 5 },
"bonuses" : [ { "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 } ]
},
{
"message" : 62,
"limiter" : { "dayOfWeek" : 6 },
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 } ]
},
{
"message" : 62,
"limiter" : { "dayOfWeek" : 7 },
"bonuses" : [
{ "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 },
{ "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 68 }
]
}
]
}
}
},
"mermaids" : {
"index" : 52,
"handler": "configurable",
"base" : {
"sounds" : {
"visit" : ["LUCK"]
}
},
"types" : {
"mermaids" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"value" : 100,
"rarity" : 20
},
"onVisitedMessage" : 82,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 83,
"bonuses" : [ { "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 72 } ]
}
]
}
}
},
"oasis" : {
"index" : 56,
"handler": "configurable",
"base" : {
"sounds" : {
"visit" : ["MORALE"]
}
},
"types" : {
"oasis" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 50
},
"onVisitedMessage" : 95,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 94,
"movePoints" : 800,
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 95 } ]
}
]
}
}
},
"stables" : {
"index" : 94,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPHORS"],
"visit" : ["STORE"]
}
},
"types" : {
"stables" : {
"index" : 0,
"aiValue" : 200,
"rmg" : {
"zoneLimit" : 1,
"value" : 200,
"rarity" : 40
},
"onVisitedMessage" : 136,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 137,
"movePoints" : 400,
"bonuses" : [ { "type" : "LAND_MOVEMENT", "val" : 400, "duration" : "ONE_WEEK",} ]
}
// TODO: 2nd reward with Cavalier -> Champions upgrade & text ID 138
]
}
}
},
"temple" : {
"index" : 96,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPSANC"],
"visit" : ["TEMPLE"]
}
},
"types" : {
"temple" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
},
"onVisitedMessage" : 141,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 140,
"limiter" : { "dayOfWeek" : 7 },
"bonuses" : [ { "type" : "MORALE", "val" : 2, "duration" : "ONE_BATTLE", "desription" : 97 } ]
},
{
"message" : 140,
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 96 } ]
}
]
}
}
},
"rallyFlag" : {
"index" : 64,
"handler": "configurable",
"base" : {
"sounds" : {
"ambient" : ["LOOPFLAG"],
"visit" : ["MORALE"]
}
},
"types" : {
"rallyFlag" : {
"index" : 0,
"aiValue" : 100,
"rmg" : {
"zoneLimit" : 1,
"value" : 100,
"rarity" : 100
},
"onVisitedMessage" : 111,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 110,
"movePoints" : 400,
"bonuses" : [
{ "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 102 },
{ "type" : "LUCK", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 102 }
]
}
]
}
}
},
"wateringHole" : {
"index" : 110,
"handler": "configurable",
"base" : {
"sounds" : {
"visit" : ["MORALE"]
}
},
"types" : {
"wateringHole" : {
"index" : 0,
"aiValue" : 500,
"rmg" : {
"zoneLimit" : 1,
"value" : 500,
"rarity" : 50
},
"onVisitedMessage" : 167,
"visitMode" : "bonus",
"selectMode" : "selectFirst",
"rewards" : [
{
"message" : 166,
"movePoints" : 400,
"bonuses" : [ { "type" : "MORALE", "val" : 1, "duration" : "ONE_BATTLE", "desription" : 100 } ]
}
]
}
}
}
}

View File

@ -11,7 +11,7 @@
}
},
"types" : {
"object" : {
"arena" : {
"index" : 0,
"aiValue" : 3000,
"rmg" : {
@ -44,7 +44,7 @@
}
},
"types" : {
"object" : {
"marlettoTower" : {
"index" : 0,
"aiValue" : 1500,
"rmg" : {
@ -74,7 +74,7 @@
}
},
"types" : {
"object" : {
"gardenOfRevelation" : {
"index" : 0,
"aiValue" : 1500,
"rmg" : {
@ -103,7 +103,7 @@
}
},
"types" : {
"object" : {
"libraryOfEnlightenment" : {
"index" : 0,
"aiValue" : 12000,
"rmg" : {
@ -181,7 +181,7 @@
}
},
"types" : {
"object" : {
"mercenaryCamp" : {
"index" : 0,
"aiValue" : 1500,
"rmg" : {
@ -211,7 +211,7 @@
}
},
"types" : {
"object" : {
"starAxis" : {
"index" : 0,
"aiValue" : 1500,
"rmg" : {
@ -240,7 +240,7 @@
}
},
"types" : {
"object" : {
"treeOfKnowledge" : {
"index" : 0,
"aiValue" : 2500,
"rmg" : {
@ -261,7 +261,7 @@
}
},
"types" : {
"object" : {
"schoolOfMagic" : {
"index" : 0,
"aiValue" : 1000,
"rmg" : {
@ -300,7 +300,7 @@
}
},
"types" : {
"object" : {
"schoolOfWar" : {
"index" : 0,
"aiValue" : 1000,
"rmg" : {
@ -339,7 +339,7 @@
}
},
"types" : {
"object" : {
"learningStone" : {
"index" : 0,
"aiValue" : 1500,
"rmg" : {

View File

@ -54,7 +54,6 @@ CObjectClassesHandler::CObjectClassesHandler()
SET_HANDLER("artifact", CGArtifact);
SET_HANDLER("blackMarket", CGBlackMarket);
SET_HANDLER("boat", CGBoat);
SET_HANDLER("bonusingObject", CGBonusingObject);
SET_HANDLER("borderGate", CGBorderGate);
SET_HANDLER("borderGuard", CGBorderGuard);
SET_HANDLER("monster", CGCreature);

View File

@ -106,6 +106,10 @@ void CRandomRewardObjectInfo::configureObject(CRewardableObject * object, CRando
bonus.source = Bonus::OBJECT;
bonus.sid = object->ID;
//TODO: bonus.description = object->getObjectName();
if (bonus.type == Bonus::MORALE)
info.reward.extraComponents.push_back(Component(Component::MORALE, 0, bonus.val, 0));
if (bonus.type == Bonus::LUCK)
info.reward.extraComponents.push_back(Component(Component::LUCK, 0, bonus.val, 0));
}
info.reward.primary = JsonRandom::loadPrimary(reward["primary"], rng);

View File

@ -472,190 +472,6 @@ CRewardableObject::CRewardableObject():
canRefuse(false)
{}
///////////////////////////////////////////////////////////////////////////////////////////////////
/// END OF CODE FOR CREWARDABLEOBJECT AND RELATED CLASSES ///
///////////////////////////////////////////////////////////////////////////////////////////////////
CGBonusingObject::CGBonusingObject()
{
visitMode = VISIT_BONUS;
selectMode = SELECT_FIRST;
}
void CGBonusingObject::initObj(CRandomGenerator & rand)
{
auto configureBonusDuration = [&](CVisitInfo & visit, Bonus::BonusDuration duration, Bonus::BonusType type, si32 value, si32 descrID)
{
Bonus b(duration, type, Bonus::OBJECT, value, ID, descrID != 0 ? VLC->generaltexth->advobtxt[descrID] : "");
visit.reward.bonuses.push_back(b);
if (type == Bonus::MORALE)
visit.reward.extraComponents.push_back(Component(Component::MORALE, 0, value, 0));
if (type == Bonus::LUCK)
visit.reward.extraComponents.push_back(Component(Component::LUCK, 0, value, 0));
};
auto configureBonus = [&](CVisitInfo & visit, Bonus::BonusType type, si32 value, si32 descrID)
{
configureBonusDuration(visit, Bonus::ONE_BATTLE, type, value, descrID);
};
auto configureMessage = [&](CVisitInfo & visit, int onGrantID, int onVisitedID)
{
visit.message.addTxt(MetaString::ADVOB_TXT, onGrantID);
onVisited.addTxt(MetaString::ADVOB_TXT, onVisitedID);
};
info.resize(1);
switch(ID)
{
case Obj::BUOY:
blockVisit = true;
configureMessage(info[0], 21, 22);
configureBonus(info[0], Bonus::MORALE, +1, 94);
break;
case Obj::SWAN_POND:
configureMessage(info[0], 29, 30);
configureBonus(info[0], Bonus::LUCK, 2, 67);
info[0].reward.movePercentage = 0;
break;
case Obj::FAERIE_RING:
configureMessage(info[0], 49, 50);
configureBonus(info[0], Bonus::LUCK, 1, 71);
break;
case Obj::FOUNTAIN_OF_FORTUNE:
selectMode = SELECT_RANDOM;
info.resize(5);
for (int i=0; i<5; i++)
{
configureBonus(info[i], Bonus::LUCK, i-1, 69); //NOTE: description have %d that should be replaced with value
info[i].message.addTxt(MetaString::ADVOB_TXT, 55);
}
onVisited.addTxt(MetaString::ADVOB_TXT, 56);
break;
case Obj::IDOL_OF_FORTUNE:
info.resize(7);
for (int i=0; i<6; i++)
{
info[i].limiter.dayOfWeek = i+1;
configureBonus(info[i], (i%2) ? Bonus::MORALE : Bonus::LUCK, 1, 68);
info[i].message.addTxt(MetaString::ADVOB_TXT, 62);
}
info.back().limiter.dayOfWeek = 7;
configureBonus(info.back(), Bonus::MORALE, 1, 68); // on last day of week
configureBonus(info.back(), Bonus::LUCK, 1, 68);
configureMessage(info.back(), 62, 63);
break;
case Obj::MERMAID:
blockVisit = true;
configureMessage(info[0], 83, 82);
configureBonus(info[0], Bonus::LUCK, 1, 72);
break;
case Obj::RALLY_FLAG:
configureMessage(info[0], 111, 110);
configureBonus(info[0], Bonus::MORALE, 1, 102);
configureBonus(info[0], Bonus::LUCK, 1, 102);
info[0].reward.movePoints = 400;
break;
case Obj::OASIS:
configureMessage(info[0], 95, 94);
configureBonus(info[0], Bonus::MORALE, 1, 95);
info[0].reward.movePoints = 800;
break;
case Obj::TEMPLE:
info[0].limiter.dayOfWeek = 7;
info.resize(2);
configureBonus(info[0], Bonus::MORALE, 2, 96);
configureBonus(info[1], Bonus::MORALE, 1, 97);
info[0].message.addTxt(MetaString::ADVOB_TXT, 140);
info[1].message.addTxt(MetaString::ADVOB_TXT, 140);
onVisited.addTxt(MetaString::ADVOB_TXT, 141);
break;
case Obj::WATERING_HOLE:
configureMessage(info[0], 166, 167);
configureBonus(info[0], Bonus::MORALE, 1, 100);
info[0].reward.movePoints = 400;
break;
case Obj::FOUNTAIN_OF_YOUTH:
configureMessage(info[0], 57, 58);
configureBonus(info[0], Bonus::MORALE, 1, 103);
info[0].reward.movePoints = 400;
break;
case Obj::STABLES:
configureMessage(info[0], 137, 136);
configureBonusDuration(info[0], Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 400, 0);
info[0].reward.movePoints = 400;
break;
}
}
CVisitInfo CGBonusingObject::getVisitInfo(int index, const CGHeroInstance *h) const
{
if(ID == Obj::STABLES)
{
assert(index == 0);
for(auto& slot : h->Slots())
{
if(slot.second->type->idNumber == CreatureID::CAVALIER)
{
CVisitInfo vi(info[0]);
vi.message.clear();
vi.message.addTxt(MetaString::ADVOB_TXT, 138);
vi.reward.extraComponents.push_back(Component(
Component::CREATURE, CreatureID::CHAMPION, 0, 1));
return vi;
}
}
}
return info[index];
}
void CGBonusingObject::onHeroVisit(const CGHeroInstance *h) const
{
CRewardableObject::onHeroVisit(h);
if(ID == Obj::STABLES)
{
//regardless of whether this hero visited stables or not, cavaliers must be upgraded
for(auto& slot : h->Slots())
{
if(slot.second->type->idNumber == CreatureID::CAVALIER)
{
cb->changeStackType(StackLocation(h, slot.first),
VLC->creh->objects[CreatureID::CHAMPION]);
}
}
}
}
bool CGBonusingObject::wasVisited(const CGHeroInstance * h) const
{
if(ID == Obj::STABLES)
{
for(auto& slot : h->Slots())
{
if(slot.second->type->idNumber == CreatureID::CAVALIER)
{
// always display the reward message if the hero got cavaliers
return false;
}
}
}
return CRewardableObject::wasVisited(h);
}
void CGBonusingObject::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
{
if(ID == Obj::STABLES && CRewardableObject::wasVisited(hero))
{
// reward message has been displayed - do not give the actual bonus
return;
}
CRewardableObject::grantReward(rewardID, hero);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
CGVisitableOPH::CGVisitableOPH()

View File

@ -295,28 +295,6 @@ public:
friend class CRandomRewardObjectInfo;
};
class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving bonuses to luck/morale/movement
{
protected:
CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const override;
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
public:
void initObj(CRandomGenerator & rand) override;
CGBonusingObject();
void onHeroVisit(const CGHeroInstance *h) const override;
bool wasVisited(const CGHeroInstance * h) const override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGVisitableOPH : public CRewardableObject //objects visitable only once per hero
{
public:

View File

@ -99,7 +99,6 @@ void registerTypesMapObjectTypes(Serializer &s)
REGISTER_GENERIC_HANDLER(CGArtifact);
REGISTER_GENERIC_HANDLER(CGBlackMarket);
REGISTER_GENERIC_HANDLER(CGBoat);
REGISTER_GENERIC_HANDLER(CGBonusingObject);
REGISTER_GENERIC_HANDLER(CGBorderGate);
REGISTER_GENERIC_HANDLER(CGBorderGuard);
REGISTER_GENERIC_HANDLER(CGCreature);
@ -160,7 +159,6 @@ void registerTypesMapObjects2(Serializer &s)
s.template registerType<CGTownBuilding, COPWBonus>();
s.template registerType<CGObjectInstance, CRewardableObject>();
s.template registerType<CRewardableObject, CGBonusingObject>();
s.template registerType<CRewardableObject, CGVisitableOPH>();
s.template registerType<CRewardableObject, CGVisitableOPW>();
s.template registerType<CGVisitableOPW, CGMagicSpring>();