mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-02 03:06:41 +00:00
take2 resolve
This commit is contained in:
parent
83ebaf27cc
commit
58a16dacbe
8 changed files with 51 additions and 29 deletions
|
@ -91,11 +91,6 @@ namespace MWClass
|
||||||
return ptr.get<ESM::Light>()->mBase->mData.mFlags & ESM::Light::Carry;
|
return ptr.get<ESM::Light>()->mBase->mData.mFlags & ESM::Light::Carry;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Light::isLight(const MWWorld::ConstPtr& ptr) const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MWWorld::Action> Light::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const
|
std::unique_ptr<MWWorld::Action> Light::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const
|
||||||
{
|
{
|
||||||
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
|
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
|
||||||
|
|
|
@ -38,8 +38,6 @@ namespace MWClass
|
||||||
|
|
||||||
bool isItem(const MWWorld::ConstPtr&) const override;
|
bool isItem(const MWWorld::ConstPtr&) const override;
|
||||||
|
|
||||||
bool isLight(const MWWorld::ConstPtr&) const override;
|
|
||||||
|
|
||||||
std::unique_ptr<MWWorld::Action> activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override;
|
std::unique_ptr<MWWorld::Action> activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override;
|
||||||
///< Generate action for activation
|
///< Generate action for activation
|
||||||
|
|
||||||
|
|
|
@ -71,10 +71,11 @@ namespace MWLua
|
||||||
if (prop == "condition")
|
if (prop == "condition")
|
||||||
{
|
{
|
||||||
MWWorld::Ptr o = mObject.ptr();
|
MWWorld::Ptr o = mObject.ptr();
|
||||||
if (o.getClass().isLight(o))
|
if (o.mRef->getType() == ESM::REC_LIGH)
|
||||||
return sol::make_object(context.mLua->sol(), o.getClass().getRemainingUsageTime(o));
|
return sol::make_object(context.mLua->sol(), o.getClass().getRemainingUsageTime(o));
|
||||||
else if (o.getClass().hasItemHealth(o))
|
else if (o.getClass().hasItemHealth(o))
|
||||||
return sol::make_object(context.mLua->sol(), o.getClass().getItemHealth(o));
|
return sol::make_object(
|
||||||
|
context.mLua->sol(), o.getClass().getItemHealth(o) + o.getCellRef().getChargeIntRemainder());
|
||||||
}
|
}
|
||||||
|
|
||||||
return sol::lua_nil;
|
return sol::lua_nil;
|
||||||
|
@ -84,14 +85,26 @@ namespace MWLua
|
||||||
{
|
{
|
||||||
if (prop == "condition")
|
if (prop == "condition")
|
||||||
{
|
{
|
||||||
double cond = value.as<double>();
|
float cond = LuaUtil::cast<float>(value);
|
||||||
if (ptr.getClass().isLight(ptr))
|
if (ptr.mRef->getType() == ESM::REC_LIGH)
|
||||||
ptr.getClass().setRemainingUsageTime(ptr, cond);
|
ptr.getClass().setRemainingUsageTime(ptr, cond);
|
||||||
else if (ptr.getClass().hasItemHealth(ptr))
|
else if (ptr.getClass().hasItemHealth(ptr))
|
||||||
ptr.getCellRef().setCharge(std::max(0, static_cast<int>(cond)));
|
{
|
||||||
else /*ignore or error?*/
|
const float lastChargeRemainder = ptr.getCellRef().getChargeIntRemainder();
|
||||||
|
// if the value set is less than 0, chargeInt and chargeIntRemainder is set to 0
|
||||||
|
ptr.getCellRef().setChargeIntRemainder(std::max(0.f, std::modf(cond, &cond)));
|
||||||
|
ptr.getCellRef().setCharge(std::max(0.f, cond));
|
||||||
|
// resolve the remaining charge remainder to be subtracted
|
||||||
|
if (lastChargeRemainder < 0)
|
||||||
|
ptr.getCellRef().applyChargeRemainderToBeSubtracted(lastChargeRemainder);
|
||||||
|
}
|
||||||
|
else
|
||||||
invalidPropErr(prop, ptr);
|
invalidPropErr(prop, ptr);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*ignore or error?*/
|
||||||
|
invalidPropErr(prop, ptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace MWLua
|
||||||
public:
|
public:
|
||||||
sol::object getCurrent(const Context& context) const
|
sol::object getCurrent(const Context& context) const
|
||||||
{
|
{
|
||||||
return getValue(context, mObject, &LevelStat::setValue, 0, "current",
|
return getValue(context, mObject, &LevelStat::setValue, std::monostate{}, "current",
|
||||||
[](const MWWorld::Ptr& ptr) { return ptr.getClass().getCreatureStats(ptr).getLevel(); });
|
[](const MWWorld::Ptr& ptr) { return ptr.getClass().getCreatureStats(ptr).getLevel(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ namespace MWLua
|
||||||
{
|
{
|
||||||
SelfObject* obj = mObject.asSelfObject();
|
SelfObject* obj = mObject.asSelfObject();
|
||||||
addStatUpdateAction(context.mLuaManager, *obj);
|
addStatUpdateAction(context.mLuaManager, *obj);
|
||||||
obj->mStatsCache[SelfObject::CachedStat{ &LevelStat::setValue, 0, "current" }] = value;
|
obj->mStatsCache[SelfObject::CachedStat{ &LevelStat::setValue, std::monostate{}, "current" }] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::object getProgress(const Context& context) const
|
sol::object getProgress(const Context& context) const
|
||||||
|
|
|
@ -188,19 +188,14 @@ namespace MWWorld
|
||||||
void CellRef::applyChargeRemainderToBeSubtracted(float chargeRemainder)
|
void CellRef::applyChargeRemainderToBeSubtracted(float chargeRemainder)
|
||||||
{
|
{
|
||||||
auto esm3Visit = [&](ESM::CellRef& cellRef3) {
|
auto esm3Visit = [&](ESM::CellRef& cellRef3) {
|
||||||
cellRef3.mChargeIntRemainder += std::abs(chargeRemainder);
|
cellRef3.mChargeIntRemainder -= std::abs(chargeRemainder);
|
||||||
if (cellRef3.mChargeIntRemainder > 1.0f)
|
if (cellRef3.mChargeIntRemainder <= -1.0f)
|
||||||
{
|
{
|
||||||
float newChargeRemainder = (cellRef3.mChargeIntRemainder - std::floor(cellRef3.mChargeIntRemainder));
|
float newChargeRemainder = std::modf(cellRef3.mChargeIntRemainder, &cellRef3.mChargeIntRemainder);
|
||||||
if (cellRef3.mChargeInt <= static_cast<int>(cellRef3.mChargeIntRemainder))
|
cellRef3.mChargeInt += static_cast<int>(cellRef3.mChargeIntRemainder);
|
||||||
{
|
|
||||||
cellRef3.mChargeInt = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cellRef3.mChargeInt -= static_cast<int>(cellRef3.mChargeIntRemainder);
|
|
||||||
}
|
|
||||||
cellRef3.mChargeIntRemainder = newChargeRemainder;
|
cellRef3.mChargeIntRemainder = newChargeRemainder;
|
||||||
|
if (cellRef3.mChargeInt < 0)
|
||||||
|
cellRef3.mChargeInt = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::visit(ESM::VisitOverload{
|
std::visit(ESM::VisitOverload{
|
||||||
|
@ -211,6 +206,16 @@ namespace MWWorld
|
||||||
mCellRef.mVariant);
|
mCellRef.mVariant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CellRef::setChargeIntRemainder(float chargeRemainder)
|
||||||
|
{
|
||||||
|
std::visit(ESM::VisitOverload{
|
||||||
|
[&](ESM4::Reference& /*ref*/) {},
|
||||||
|
[&](ESM4::ActorCharacter&) {},
|
||||||
|
[&](ESM::CellRef& ref) { ref.mChargeIntRemainder = chargeRemainder; },
|
||||||
|
},
|
||||||
|
mCellRef.mVariant);
|
||||||
|
}
|
||||||
|
|
||||||
void CellRef::setChargeFloat(float charge)
|
void CellRef::setChargeFloat(float charge)
|
||||||
{
|
{
|
||||||
std::visit(ESM::VisitOverload{
|
std::visit(ESM::VisitOverload{
|
||||||
|
|
|
@ -118,10 +118,23 @@ namespace MWWorld
|
||||||
};
|
};
|
||||||
return std::visit(Visitor(), mCellRef.mVariant);
|
return std::visit(Visitor(), mCellRef.mVariant);
|
||||||
} // Implemented as union with int charge
|
} // Implemented as union with int charge
|
||||||
|
float getChargeIntRemainder() const
|
||||||
|
{
|
||||||
|
struct Visitor
|
||||||
|
{
|
||||||
|
float operator()(const ESM::CellRef& ref) { return ref.mChargeIntRemainder; }
|
||||||
|
float operator()(const ESM4::Reference& /*ref*/) { return 0; }
|
||||||
|
float operator()(const ESM4::ActorCharacter&) { throw std::logic_error("Not applicable"); }
|
||||||
|
};
|
||||||
|
return std::visit(Visitor(), mCellRef.mVariant);
|
||||||
|
}
|
||||||
void setCharge(int charge);
|
void setCharge(int charge);
|
||||||
void setChargeFloat(float charge);
|
void setChargeFloat(float charge);
|
||||||
void applyChargeRemainderToBeSubtracted(float chargeRemainder); // Stores remainders and applies if > 1
|
void applyChargeRemainderToBeSubtracted(float chargeRemainder); // Stores remainders and applies if > 1
|
||||||
|
|
||||||
|
// Stores fractional part of mChargeInt
|
||||||
|
void setChargeIntRemainder(float chargeRemainder);
|
||||||
|
|
||||||
// The NPC that owns this object (and will get angry if you steal it)
|
// The NPC that owns this object (and will get angry if you steal it)
|
||||||
ESM::RefId getOwner() const
|
ESM::RefId getOwner() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -332,8 +332,6 @@ namespace MWWorld
|
||||||
// True if it is an item that can be picked up.
|
// True if it is an item that can be picked up.
|
||||||
virtual bool isItem(const MWWorld::ConstPtr& ptr) const { return false; }
|
virtual bool isItem(const MWWorld::ConstPtr& ptr) const { return false; }
|
||||||
|
|
||||||
virtual bool isLight(const MWWorld::ConstPtr& ptr) const { return false; }
|
|
||||||
|
|
||||||
virtual bool isBipedal(const MWWorld::ConstPtr& ptr) const;
|
virtual bool isBipedal(const MWWorld::ConstPtr& ptr) const;
|
||||||
virtual bool canFly(const MWWorld::ConstPtr& ptr) const;
|
virtual bool canFly(const MWWorld::ConstPtr& ptr) const;
|
||||||
virtual bool canSwim(const MWWorld::ConstPtr& ptr) const;
|
virtual bool canSwim(const MWWorld::ConstPtr& ptr) const;
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace ESM
|
||||||
int32_t mChargeInt; // Used by everything except lights
|
int32_t mChargeInt; // Used by everything except lights
|
||||||
float mChargeFloat; // Used only by lights
|
float mChargeFloat; // Used only by lights
|
||||||
};
|
};
|
||||||
float mChargeIntRemainder; // Stores amount of charge not subtracted from mChargeInt
|
float mChargeIntRemainder; // Fractional part of mChargeInt
|
||||||
|
|
||||||
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
||||||
float mEnchantmentCharge;
|
float mEnchantmentCharge;
|
||||||
|
|
Loading…
Reference in a new issue