mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Merge branch 'develop' into feature/nullkiller2
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "../networkPacks/StackLocation.h"
|
||||
#include "../serializer/JsonSerializeFormat.h"
|
||||
#include "../entities/faction/CTownHandler.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
|
||||
#include <vstd/RNG.h>
|
||||
|
||||
@@ -522,7 +523,7 @@ void CGCreature::battleFinished(IGameEventCallback & gameEvents, const CGHeroIns
|
||||
else if(result.winner == BattleSide::NONE) // draw
|
||||
{
|
||||
// guarded reward is lost forever on draw
|
||||
gameEvents.removeObject(this, hero->getOwner());
|
||||
gameEvents.removeObject(this, result.attacker);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -630,7 +631,7 @@ void CGCreature::giveReward(IGameEventCallback & gameEvents, const CGHeroInstanc
|
||||
if(!resources.empty())
|
||||
{
|
||||
gameEvents.giveResources(h->tempOwner, resources);
|
||||
for(const auto & res : GameResID::ALL_RESOURCES())
|
||||
for(const auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
{
|
||||
if(resources[res] > 0)
|
||||
iw.components.emplace_back(ComponentType::RESOURCE, res, resources[res]);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "../entities/faction/CTownHandler.h"
|
||||
#include "../entities/hero/CHeroHandler.h"
|
||||
#include "../entities/hero/CHeroClass.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
#include "../battle/CBattleInfoEssentials.h"
|
||||
#include "../campaign/CampaignState.h"
|
||||
#include "../json/JsonBonus.h"
|
||||
@@ -1816,7 +1817,7 @@ ResourceSet CGHeroInstance::dailyIncome() const
|
||||
{
|
||||
ResourceSet income;
|
||||
|
||||
for (GameResID k : GameResID::ALL_RESOURCES())
|
||||
for (GameResID k : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
income[k] += valOfBonuses(BonusType::GENERATE_RESOURCE, BonusSubtypeID(k));
|
||||
|
||||
const auto & playerSettings = cb->getPlayerSettings(getOwner());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CObjectHandler.cpp, part of VCMI engine
|
||||
* CGObjectInstance.cpp, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
|
||||
@@ -294,6 +294,18 @@ void CGEvent::init()
|
||||
}
|
||||
}
|
||||
|
||||
void CGEvent::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
|
||||
{
|
||||
if(result.winner == BattleSide::ATTACKER)
|
||||
{
|
||||
CRewardableObject::onHeroVisit(gameEvents, hero);
|
||||
}
|
||||
if(result.winner == BattleSide::NONE && removeAfterVisit) //rewards are lost if therer is a draw and an event is not repeatable
|
||||
{
|
||||
gameEvents.removeObject(this, result.attacker);
|
||||
}
|
||||
}
|
||||
|
||||
void CGEvent::grantRewardWithMessage(IGameEventCallback & gameEvents, const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const
|
||||
{
|
||||
CRewardableObject::grantRewardWithMessage(gameEvents, contextHero, rewardIndex, markAsVisit);
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
}
|
||||
|
||||
void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
|
||||
void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
|
||||
protected:
|
||||
void grantRewardWithMessage(IGameEventCallback & gameEvents, const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const override;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../gameState/CGameState.h"
|
||||
#include "../serializer/JsonSerializeFormat.h"
|
||||
#include "../CSoundBase.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
|
||||
#include <vstd/RNG.h>
|
||||
|
||||
@@ -50,7 +51,7 @@ GameResID CGResource::resourceID() const
|
||||
|
||||
std::string CGResource::getHoverText(PlayerColor player) const
|
||||
{
|
||||
return LIBRARY->generaltexth->restypes[resourceID().getNum()];
|
||||
return resourceID().toResource()->getNameTranslated();
|
||||
}
|
||||
|
||||
void CGResource::pickRandomObject(IGameRandomizer & gameRandomizer)
|
||||
@@ -60,7 +61,7 @@ void CGResource::pickRandomObject(IGameRandomizer & gameRandomizer)
|
||||
if (ID == Obj::RANDOM_RESOURCE)
|
||||
{
|
||||
ID = Obj::RESOURCE;
|
||||
subID = gameRandomizer.getDefault().nextInt(EGameResID::WOOD, EGameResID::GOLD);
|
||||
subID = gameRandomizer.getDefault().nextInt(EGameResID::WOOD, EGameResID::GOLD); //todo: configurable resource support
|
||||
setType(ID, subID);
|
||||
|
||||
amount *= getAmountMultiplier();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "../callback/IGameRandomizer.h"
|
||||
#include "../entities/building/CBuilding.h"
|
||||
#include "../entities/faction/CTownHandler.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../mapObjects/CGHeroInstance.h"
|
||||
@@ -209,7 +210,7 @@ TResources CGTownInstance::dailyIncome() const
|
||||
{
|
||||
ResourceSet ret;
|
||||
|
||||
for (GameResID k : GameResID::ALL_RESOURCES())
|
||||
for (GameResID k : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
ret[k] += valOfBonuses(BonusType::GENERATE_RESOURCE, BonusSubtypeID(k));
|
||||
|
||||
for(const auto & p : getTown()->buildings)
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* CObjectHandler.cpp, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "CObjectHandler.h"
|
||||
|
||||
#include "CGObjectInstance.h"
|
||||
#include "../filesystem/ResourcePath.h"
|
||||
#include "../json/JsonNode.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
CObjectHandler::CObjectHandler()
|
||||
{
|
||||
logGlobal->trace("\t\tReading resources prices ");
|
||||
const JsonNode config2(JsonPath::builtin("config/resources.json"));
|
||||
for(const JsonNode &price : config2["resources_prices"].Vector())
|
||||
{
|
||||
resVals.push_back(static_cast<ui32>(price.Float()));
|
||||
}
|
||||
logGlobal->trace("\t\tDone loading resource prices!");
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* CObjectHandler.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../GameConstants.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class CGObjectInstance;
|
||||
class int3;
|
||||
|
||||
class DLL_LINKAGE CObjectHandler
|
||||
{
|
||||
public:
|
||||
std::vector<ui32> resVals; //default values of resources in gold
|
||||
|
||||
CObjectHandler();
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "../callback/IGameRandomizer.h"
|
||||
#include "../entities/artifact/CArtifact.h"
|
||||
#include "../entities/hero/CHeroHandler.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../serializer/JsonSerializeFormat.h"
|
||||
#include "../GameConstants.h"
|
||||
@@ -233,7 +234,7 @@ void CQuest::addTextReplacements(const IGameInfoCallback * cb, MetaString & text
|
||||
if(mission.resources.nonZero())
|
||||
{
|
||||
MetaString loot;
|
||||
for(auto i : GameResID::ALL_RESOURCES())
|
||||
for(auto i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
{
|
||||
if(mission.resources[i])
|
||||
{
|
||||
@@ -372,11 +373,9 @@ void CQuest::serializeJson(JsonSerializeFormat & handler, const std::string & fi
|
||||
if(missionType == "Resources")
|
||||
{
|
||||
auto r = handler.enterStruct("resources");
|
||||
|
||||
for(size_t idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
||||
{
|
||||
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], mission.resources[idx], 0);
|
||||
}
|
||||
|
||||
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
handler.serializeInt(idx.toResource()->getJsonKey(), mission.resources[idx], 0);
|
||||
}
|
||||
|
||||
if(missionType == "Hero")
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
|
||||
#include "CCreatureHandler.h"
|
||||
#include "CGObjectInstance.h"
|
||||
#include "CObjectHandler.h"
|
||||
|
||||
#include "../GameLibrary.h"
|
||||
#include "../entities/artifact/CArtHandler.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@@ -33,8 +33,8 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
||||
{
|
||||
double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5);
|
||||
|
||||
double r = LIBRARY->objh->resVals[id1]; //value of given resource
|
||||
double g = LIBRARY->objh->resVals[id2] / effectiveness; //value of wanted resource
|
||||
double r = GameResID(id1).toResource()->getPrice(); //value of given resource
|
||||
double g = GameResID(id2).toResource()->getPrice() / effectiveness; //value of wanted resource
|
||||
|
||||
if(r>g) //if given resource is more expensive than wanted
|
||||
{
|
||||
@@ -54,7 +54,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
||||
double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)];
|
||||
|
||||
double r = LIBRARY->creatures()->getByIndex(id1)->getRecruitCost(EGameResID::GOLD); //value of given creature in gold
|
||||
double g = LIBRARY->objh->resVals[id2] / effectiveness; //value of wanted resource
|
||||
double g = GameResID(id2).toResource()->getPrice() / effectiveness; //value of wanted resource
|
||||
|
||||
if(r>g) //if given resource is more expensive than wanted
|
||||
{
|
||||
@@ -75,7 +75,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
||||
case EMarketMode::RESOURCE_ARTIFACT:
|
||||
{
|
||||
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
||||
double r = LIBRARY->objh->resVals[id1]; //value of offered resource
|
||||
double r = GameResID(id1).toResource()->getPrice(); //value of offered resource
|
||||
double g = LIBRARY->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold
|
||||
|
||||
if(id1 != 6) //non-gold prices are doubled
|
||||
@@ -89,7 +89,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
||||
{
|
||||
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
||||
double r = LIBRARY->artifacts()->getByIndex(id1)->getPrice() * effectiveness;
|
||||
double g = LIBRARY->objh->resVals[id2];
|
||||
double g = GameResID(id2).toResource()->getPrice();
|
||||
|
||||
// if(id2 != 6) //non-gold prices are doubled
|
||||
// r /= 2;
|
||||
@@ -163,7 +163,7 @@ std::vector<TradeItemBuy> IMarket::availableItemsIds(const EMarketMode mode) con
|
||||
case EMarketMode::RESOURCE_RESOURCE:
|
||||
case EMarketMode::ARTIFACT_RESOURCE:
|
||||
case EMarketMode::CREATURE_RESOURCE:
|
||||
for(const auto & res : GameResID::ALL_RESOURCES())
|
||||
for(const auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
ret.push_back(res);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#pragma once
|
||||
|
||||
// Helper header that includes all map objects, similar to old CObjectHandler.h
|
||||
// Possible TODO - remove this header after CObjectHandler.cpp will be fully split into smaller files
|
||||
#include "CObjectHandler.h"
|
||||
|
||||
#include "CGDwelling.h"
|
||||
#include "CGHeroInstance.h"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "../constants/StringConstants.h"
|
||||
#include "../entities/artifact/ArtifactUtils.h"
|
||||
#include "../entities/artifact/CArtifact.h"
|
||||
#include "../entities/ResourceTypeHandler.h"
|
||||
#include "../CConfigHandler.h"
|
||||
#include "../texts/CGeneralTextHandler.h"
|
||||
#include "../CSkillHandler.h"
|
||||
@@ -143,7 +144,7 @@ ResourceSet CGMine::dailyIncome() const
|
||||
{
|
||||
ResourceSet result;
|
||||
|
||||
for (GameResID k : GameResID::ALL_RESOURCES())
|
||||
for (GameResID k : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
result[k] += valOfBonuses(BonusType::GENERATE_RESOURCE, BonusSubtypeID(k));
|
||||
|
||||
result[producedResource] += defaultResProduction();
|
||||
@@ -164,7 +165,7 @@ std::string CGMine::getHoverText(PlayerColor player) const
|
||||
std::string hoverName = CArmedInstance::getHoverText(player);
|
||||
|
||||
if (tempOwner != PlayerColor::NEUTRAL)
|
||||
hoverName += "\n(" + LIBRARY->generaltexth->restypes[producedResource.getNum()] + ")";
|
||||
hoverName += "\n(" + producedResource.toResource()->getNameTranslated() + ")";
|
||||
|
||||
if(stacksCount())
|
||||
{
|
||||
@@ -238,7 +239,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
JsonNode node;
|
||||
for(const auto & resID : abandonedMineResources)
|
||||
node.Vector().emplace_back(GameConstants::RESOURCE_NAMES[resID.getNum()]);
|
||||
node.Vector().emplace_back(resID.toResource()->getJsonKey());
|
||||
|
||||
handler.serializeRaw("possibleResources", node, std::nullopt);
|
||||
}
|
||||
@@ -251,7 +252,10 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
|
||||
for(const std::string & s : names)
|
||||
{
|
||||
int raw_res = vstd::find_pos(GameConstants::RESOURCE_NAMES, s);
|
||||
std::vector<std::string> resNames;
|
||||
for(auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
resNames.push_back(res.toResource()->getJsonKey());
|
||||
int raw_res = vstd::find_pos(resNames, s);
|
||||
if(raw_res < 0)
|
||||
logGlobal->error("Invalid resource name: %s", s);
|
||||
else
|
||||
@@ -872,7 +876,7 @@ const IOwnableObject * CGGarrison::asOwnable() const
|
||||
ResourceSet CGGarrison::dailyIncome() const
|
||||
{
|
||||
ResourceSet result;
|
||||
for (GameResID k : GameResID::ALL_RESOURCES())
|
||||
for (GameResID k : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||
result[k] += valOfBonuses(BonusType::GENERATE_RESOURCE, BonusSubtypeID(k));
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user