mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
vcmi: modernize lib/mapObjects
This commit is contained in:
@@ -40,17 +40,17 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMar
|
||||
{
|
||||
double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5);
|
||||
|
||||
double r = VLC->objh->resVals[id1], //value of given resource
|
||||
g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource
|
||||
double r = VLC->objh->resVals[id1]; //value of given resource
|
||||
double g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource
|
||||
|
||||
if(r>g) //if given resource is more expensive than wanted
|
||||
{
|
||||
val2 = (int)ceil(r / g);
|
||||
val2 = static_cast<int>(ceil(r / g));
|
||||
val1 = 1;
|
||||
}
|
||||
else //if wanted resource is more expensive
|
||||
{
|
||||
val1 = (int)((g / r) + 0.5);
|
||||
val1 = static_cast<int>((g / r) + 0.5);
|
||||
val2 = 1;
|
||||
}
|
||||
}
|
||||
@@ -60,17 +60,17 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMar
|
||||
const double effectivenessArray[] = {0.0, 0.3, 0.45, 0.50, 0.65, 0.7, 0.85, 0.9, 1.0};
|
||||
double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)];
|
||||
|
||||
double r = VLC->creh->objects[id1]->cost[6], //value of given creature in gold
|
||||
g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource
|
||||
double r = VLC->creh->objects[id1]->cost[6]; //value of given creature in gold
|
||||
double g = VLC->objh->resVals[id2] / effectiveness; //value of wanted resource
|
||||
|
||||
if(r>g) //if given resource is more expensive than wanted
|
||||
{
|
||||
val2 = (int)ceil(r / g);
|
||||
val2 = static_cast<int>(ceil(r / g));
|
||||
val1 = 1;
|
||||
}
|
||||
else //if wanted resource is more expensive
|
||||
{
|
||||
val1 = (int)((g / r) + 0.5);
|
||||
val1 = static_cast<int>((g / r) + 0.5);
|
||||
val2 = 1;
|
||||
}
|
||||
}
|
||||
@@ -82,27 +82,27 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMar
|
||||
case EMarketMode::RESOURCE_ARTIFACT:
|
||||
{
|
||||
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
||||
double r = VLC->objh->resVals[id1], //value of offered resource
|
||||
g = VLC->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold
|
||||
double r = VLC->objh->resVals[id1]; //value of offered resource
|
||||
double g = VLC->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold
|
||||
|
||||
if(id1 != 6) //non-gold prices are doubled
|
||||
r /= 2;
|
||||
|
||||
val1 = std::max(1, (int)((g / r) + 0.5)); //don't sell arts for less than 1 resource
|
||||
val1 = std::max(1, static_cast<int>((g / r) + 0.5)); //don't sell arts for less than 1 resource
|
||||
val2 = 1;
|
||||
}
|
||||
break;
|
||||
case EMarketMode::ARTIFACT_RESOURCE:
|
||||
{
|
||||
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
||||
double r = VLC->artifacts()->getByIndex(id1)->getPrice() * effectiveness,
|
||||
g = VLC->objh->resVals[id2];
|
||||
double r = VLC->artifacts()->getByIndex(id1)->getPrice() * effectiveness;
|
||||
double g = VLC->objh->resVals[id2];
|
||||
|
||||
// if(id2 != 6) //non-gold prices are doubled
|
||||
// r /= 2;
|
||||
|
||||
val1 = 1;
|
||||
val2 = std::max(1, (int)((r / g) + 0.5)); //at least one resource is given in return
|
||||
val2 = std::max(1, static_cast<int>((r / g) + 0.5)); //at least one resource is given in return
|
||||
}
|
||||
break;
|
||||
case EMarketMode::CREATURE_EXP:
|
||||
@@ -122,7 +122,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode::EMar
|
||||
return false;
|
||||
}
|
||||
|
||||
static const int expPerClass[] = {1000, 1500, 3000, 6000};
|
||||
static constexpr int expPerClass[] = {1000, 1500, 3000, 6000};
|
||||
val2 = expPerClass[givenClass];
|
||||
}
|
||||
break;
|
||||
@@ -171,15 +171,15 @@ const IMarket * IMarket::castFrom(const CGObjectInstance *obj, bool verbose)
|
||||
switch(obj->ID)
|
||||
{
|
||||
case Obj::TOWN:
|
||||
return static_cast<const CGTownInstance*>(obj);
|
||||
return dynamic_cast<const CGTownInstance *>(obj);
|
||||
case Obj::ALTAR_OF_SACRIFICE:
|
||||
case Obj::BLACK_MARKET:
|
||||
case Obj::TRADING_POST:
|
||||
case Obj::TRADING_POST_SNOW:
|
||||
case Obj::FREELANCERS_GUILD:
|
||||
return static_cast<const CGMarket*>(obj);
|
||||
return dynamic_cast<const CGMarket *>(obj);
|
||||
case Obj::UNIVERSITY:
|
||||
return static_cast<const CGUniversity*>(obj);
|
||||
return dynamic_cast<const CGUniversity *>(obj);
|
||||
default:
|
||||
if(verbose)
|
||||
logGlobal->error("Cannot cast to IMarket object with ID %d", obj->ID);
|
||||
@@ -197,8 +197,8 @@ std::vector<EMarketMode::EMarketMode> IMarket::availableModes() const
|
||||
{
|
||||
std::vector<EMarketMode::EMarketMode> ret;
|
||||
for (int i = 0; i < EMarketMode::MARTKET_AFTER_LAST_PLACEHOLDER; i++)
|
||||
if(allowsTrade((EMarketMode::EMarketMode)i))
|
||||
ret.push_back((EMarketMode::EMarketMode)i);
|
||||
if(allowsTrade(static_cast<EMarketMode::EMarketMode>(i)))
|
||||
ret.push_back(static_cast<EMarketMode::EMarketMode>(i));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user