diff --git a/src/game/script/routines_combat.cpp b/src/game/script/routines_combat.cpp index 97636778..e42ac8e3 100644 --- a/src/game/script/routines_combat.cpp +++ b/src/game/script/routines_combat.cpp @@ -159,7 +159,7 @@ Variable Routines::getPlayerRestrictMode(const VariablesList &args, ExecutionCon // TODO: why is this object necessary? auto object = getCreatureOrCaller(args, 0, ctx); - return Variable(_game->module()->player().isRestrictMode() ? 1 : 0); + return Variable::ofInt(_game->module()->player().isRestrictMode() ? 1 : 0); } Variable Routines::setPlayerRestrictMode(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_common.cpp b/src/game/script/routines_common.cpp index 9fd40ee8..0ce6d2be 100644 --- a/src/game/script/routines_common.cpp +++ b/src/game/script/routines_common.cpp @@ -45,7 +45,7 @@ Variable Routines::d2(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 2); } - return result; + return Variable::ofInt(result); } Variable Routines::d3(const VariablesList &args, ExecutionContext &ctx) { @@ -56,7 +56,7 @@ Variable Routines::d3(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 3); } - return result; + return Variable::ofInt(result); } Variable Routines::d4(const VariablesList &args, ExecutionContext &ctx) { @@ -67,7 +67,7 @@ Variable Routines::d4(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 4); } - return result; + return Variable::ofInt(result); } Variable Routines::d6(const VariablesList &args, ExecutionContext &ctx) { @@ -78,7 +78,7 @@ Variable Routines::d6(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 6); } - return result; + return Variable::ofInt(result); } Variable Routines::d8(const VariablesList &args, ExecutionContext &ctx) { @@ -89,7 +89,7 @@ Variable Routines::d8(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 8); } - return result; + return Variable::ofInt(result); } Variable Routines::d10(const VariablesList &args, ExecutionContext &ctx) { @@ -100,7 +100,7 @@ Variable Routines::d10(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 10); } - return result; + return Variable::ofInt(result); } Variable Routines::d12(const VariablesList &args, ExecutionContext &ctx) { @@ -111,7 +111,7 @@ Variable Routines::d12(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 12); } - return result; + return Variable::ofInt(result); } Variable Routines::d20(const VariablesList &args, ExecutionContext &ctx) { @@ -122,7 +122,7 @@ Variable Routines::d20(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 20); } - return result; + return Variable::ofInt(result); } Variable Routines::d100(const VariablesList &args, ExecutionContext &ctx) { @@ -133,109 +133,109 @@ Variable Routines::d100(const VariablesList &args, ExecutionContext &ctx) { result += reone::random(1, 100); } - return result; + return Variable::ofInt(result); } Variable Routines::feetToMeters(const VariablesList &args, ExecutionContext &ctx) { - return getFloat(args, 0) * 0.3048f; + return Variable::ofFloat(getFloat(args, 0) * 0.3048f); } Variable Routines::floatToInt(const VariablesList &args, ExecutionContext &ctx) { - return static_cast(getFloat(args, 0)); + return Variable::ofInt(static_cast(getFloat(args, 0))); } Variable Routines::floatToString(const VariablesList &args, ExecutionContext &ctx) { // TODO: handle optional arguments - return to_string(getFloat(args, 0)); + return Variable::ofString(to_string(getFloat(args, 0))); } Variable Routines::hoursToSeconds(const VariablesList &args, ExecutionContext &ctx) { - return getInt(args, 0) * 3600; + return Variable::ofInt(getInt(args, 0) * 3600); } Variable Routines::intToFloat(const VariablesList &args, ExecutionContext &ctx) { - return static_cast(getInt(args, 0)); + return Variable::ofFloat(static_cast(getInt(args, 0))); } Variable Routines::intToHexString(const VariablesList &args, ExecutionContext &ctx) { - return str(boost::format("%08x") % getInt(args, 0)); + return Variable::ofString(str(boost::format("%08x") % getInt(args, 0))); } Variable Routines::intToString(const VariablesList &args, ExecutionContext &ctx) { - return to_string(getInt(args, 0)); + return Variable::ofString(to_string(getInt(args, 0))); } Variable Routines::roundsToSeconds(const VariablesList &args, ExecutionContext &ctx) { - return getInt(args, 0) / 6.0f; + return Variable::ofFloat(getInt(args, 0) / 6.0f); } Variable Routines::stringToFloat(const VariablesList &args, ExecutionContext &ctx) { - return stof(getString(args, 0)); + return Variable::ofFloat(stof(getString(args, 0))); } Variable Routines::stringToInt(const VariablesList &args, ExecutionContext &ctx) { - return stoi(getString(args, 0)); + return Variable::ofInt(stoi(getString(args, 0))); } Variable Routines::turnsToSeconds(const VariablesList &args, ExecutionContext &ctx) { - return getInt(args, 0) / 60.0f; + return Variable::ofFloat(getInt(args, 0) / 60.0f); } Variable Routines::yardsToMeters(const VariablesList &args, ExecutionContext &ctx) { - return getFloat(args, 0) * 0.9144f; + return Variable::ofFloat(getFloat(args, 0) * 0.9144f); } Variable Routines::getStringLength(const VariablesList &args, ExecutionContext &ctx) { - return static_cast(getString(args, 0).length()); + return Variable::ofInt(static_cast(getString(args, 0).length())); } Variable Routines::getStringUpperCase(const VariablesList &args, ExecutionContext &ctx) { string result(getString(args, 0)); boost::to_upper(result); - return move(result); + return Variable::ofString(move(result)); } Variable Routines::getStringLowerCase(const VariablesList &args, ExecutionContext &ctx) { string result(getString(args, 0)); boost::to_lower(result); - return move(result); + return Variable::ofString(move(result)); } Variable Routines::getStringRight(const VariablesList &args, ExecutionContext &ctx) { string str(getString(args, 0)); int count = getInt(args, 1); - return str.substr(str.length() - count, count); + return Variable::ofString(str.substr(str.length() - count, count)); } Variable Routines::getStringLeft(const VariablesList &args, ExecutionContext &ctx) { string str(getString(args, 0)); int count = getInt(args, 1); - return str.substr(0, count); + return Variable::ofString(str.substr(0, count)); } Variable Routines::insertString(const VariablesList &args, ExecutionContext &ctx) { string dest(getString(args, 0)); string str(getString(args, 1)); int pos = getInt(args, 2); - return dest.insert(pos, str); + return Variable::ofString(dest.insert(pos, str)); } Variable Routines::getSubString(const VariablesList &args, ExecutionContext &ctx) { string str(getString(args, 0)); int start = getInt(args, 1); int count = getInt(args, 2); - return str.substr(start, count); + return Variable::ofString(str.substr(start, count)); } Variable Routines::findSubString(const VariablesList &args, ExecutionContext &ctx) { string str(getString(args, 0)); string substr(getString(args, 1)); size_t pos = str.find(substr); - return pos != string::npos ? static_cast(pos) : -1; + return Variable::ofInt(pos != string::npos ? static_cast(pos) : -1); } Variable Routines::shipBuild(const VariablesList &args, ExecutionContext &ctx) { - return g_shipBuild ? 1 : 0; + return Variable::ofInt(g_shipBuild ? 1 : 0); } Variable Routines::executeScript(const VariablesList &args, ExecutionContext &ctx) { @@ -254,20 +254,20 @@ Variable Routines::executeScript(const VariablesList &args, ExecutionContext &ct } Variable Routines::getRunScriptVar(const VariablesList &args, ExecutionContext &ctx) { - return _game->getRunScriptVar(); + return Variable::ofInt(_game->getRunScriptVar()); } Variable Routines::random(const VariablesList &args, ExecutionContext &ctx) { - return reone::random(0, getInt(args, 0) - 1); + return Variable::ofInt(reone::random(0, getInt(args, 0) - 1)); } Variable Routines::getLoadFromSaveGame(const VariablesList &args, ExecutionContext &ctx) { - return Variable(_game->isLoadFromSaveGame() ? 1 : 0); + return Variable::ofInt(_game->isLoadFromSaveGame() ? 1 : 0); } Variable Routines::getStringByStrRef(const VariablesList &args, ExecutionContext &ctx) { int strRef = getInt(args, 0); - return Variable(Strings::instance().get(strRef)); + return Variable::ofString(Strings::instance().get(strRef)); } Variable Routines::startNewModule(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_effects.cpp b/src/game/script/routines_effects.cpp index 7a32fa87..8dfca9be 100644 --- a/src/game/script/routines_effects.cpp +++ b/src/game/script/routines_effects.cpp @@ -32,447 +32,447 @@ namespace game { Variable Routines::effectAssuredHit(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AssuredHit); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectHeal(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Heal); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamage(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Damage); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectAbilityIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AbilityIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageResistance(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageResistance); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectResurrection(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Resurrection); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectACIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ACIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSavingThrowIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SavingThrowIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectAttackIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AttackIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageReduction(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageReduction); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectEntangle(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Entangle); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDeath(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Death); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectKnockdown(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Knockdown); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectParalyze(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Paralyze); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSpellImmunity(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SpellImmunity); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceJump(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceJump); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSleep(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Sleep); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectTemporaryForcePoints(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::TemporaryHitpoints); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectConfused(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Confused); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectFrightened(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Frightened); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectChoke(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Choke); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectStunned(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Stunned); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectRegenerate(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Regenerate); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectMovementSpeedIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::MovementSpeedIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectAreaOfEffect(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AreaOfEffect); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectVisualEffect(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Visual); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectLinkEffects(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::LinkEffects); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectBeam(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Beam); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceResistanceIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceResistanceIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectBodyFuel(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::BodyFuel); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectPoison(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Poison); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectAssuredDeflection(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AssuredDeflection); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForcePushTargeted(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForcePushTargeted); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectHaste(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Haste); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectImmunity(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Immunity); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageImmunityIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageImmunityIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectTemporaryHitpoints(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::TemporaryHitpoints); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSkillIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SkillIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageForcePoints(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageForcePoints); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectHealForcePoints(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::HealForcePoints); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectHitPointChangeWhenDying(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::HitPointsChangeWhenDying); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDroidStun(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DroidStun); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForcePushed(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForcePushed); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceResisted(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceResisted); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceFizzle(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceFizzle); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectAbilityDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AbilityDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectAttackDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::AttackDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageImmunityDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageImmunityDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectACDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ACDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectMovementSpeedDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::MovementSpeedDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSavingThrowDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SavingThrowDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSkillDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SkillDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceResistanceDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceResistanceDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectInvisibility(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Invisibility); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectConcealment(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Concealment); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceShield(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceShield); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDispelMagicAll(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DispelMagicAll); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDisguise(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Disguise); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectTrueSeeing(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::TrueSeeing); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSeeInvisible(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SeeInvisible); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectTimeStop(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::TimeStop); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectBlasterDeflectionIncrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::BlasterDeflectionIncrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectBlasterDeflectionDecrease(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::BlasterDeflectionDecrease); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectHorrified(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Horrified); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectSpellLevelAbsorption(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::SpellLevelAbsorption); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDispelMagicBest(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DispelMagicBest); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectMissChance(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::MissChance); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectModifyAttacks(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ModifyAttacks); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDamageShield(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DamageShield); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceDrain(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceDrain); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectPsychicStatic(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::PsychicStatic); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectLightsaberThrow(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::LightsaberThrow); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectWhirlWind(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::WhirlWind); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectCutSceneHorrified(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::CutSceneHorrified); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectCutSceneParalyze(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::CutSceneParalyze); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectCutSceneStunned(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::CutSceneStunned); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceBody(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceBody); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectFury(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Fury); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectBlind(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Blindness); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectFPRegenModifier(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::FPRegenModifier); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectVPRegenModifier(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::VPRegenModifier); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectCrush(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::Crush); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDroidConfused(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DroidConfused); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectForceSight(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::ForceSight); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectMindTrick(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::MindTrick); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectFactionModifier(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::FactionModifier); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::effectDroidScramble(const VariablesList &args, ExecutionContext &ctx) { auto effect = make_shared(EffectType::DroidScramble); - return Variable(VariableType::Effect, static_pointer_cast(effect)); + return Variable::ofEffect(effect); } Variable Routines::clearAllEffects(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_enginetypes.cpp b/src/game/script/routines_enginetypes.cpp index d75e2d74..0cacf401 100644 --- a/src/game/script/routines_enginetypes.cpp +++ b/src/game/script/routines_enginetypes.cpp @@ -34,9 +34,9 @@ Variable Routines::getFacingFromLocation(const VariablesList &args, ExecutionCon auto location = getLocationEngineType(args, 0); if (!location) { debug("Script: getFacingFromLocation: location is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } - return location->facing(); + return Variable::ofFloat(location->facing()); } Variable Routines::getLocation(const VariablesList &args, ExecutionContext &ctx) { @@ -59,9 +59,9 @@ Variable Routines::getPositionFromLocation(const VariablesList &args, ExecutionC auto location = getLocationEngineType(args, 0); if (!location) { debug("Script: getPositionFromLocation: location is invalid"); - return glm::vec3(0.0f); + return Variable::ofVector(glm::vec3(0.0f)); } - return location->position(); + return Variable::ofVector(location->position()); } Variable Routines::location(const VariablesList &args, ExecutionContext &ctx) { @@ -69,41 +69,41 @@ Variable Routines::location(const VariablesList &args, ExecutionContext &ctx) { float orientation = getFloat(args, 1); auto location = make_shared(move(position), orientation); - return Variable(VariableType::Location, location); + return Variable::ofLocation(location); } Variable Routines::getDistanceBetweenLocations(const VariablesList &args, ExecutionContext &ctx) { auto locationA = getLocationEngineType(args, 0); if (!locationA) { debug("Script: getDistanceBetweenLocations: locationA is invalid"); - return 0.0f; + return Variable::ofFloat(0.0f); } auto locationB = getLocationEngineType(args, 1); if (!locationB) { debug("Script: getDistanceBetweenLocations: locationB is invalid"); - return 0.0f; + return Variable::ofFloat(0.0f); } - return glm::distance(locationA->position(), locationB->position()); + return Variable::ofFloat(glm::distance(locationA->position(), locationB->position())); } Variable Routines::getDistanceBetweenLocations2D(const VariablesList &args, ExecutionContext &ctx) { auto locationA = getLocationEngineType(args, 0); if (!locationA) { debug("Script: getDistanceBetweenLocations2D: locationA is invalid"); - return 0.0f; + return Variable::ofFloat(0.0f); } auto locationB = getLocationEngineType(args, 1); if (!locationB) { debug("Script: getDistanceBetweenLocations2D: locationB is invalid"); - return 0.0f; + return Variable::ofFloat(0.0f); } - return glm::distance(glm::vec2(locationA->position()), glm::vec2(locationB->position())); + return Variable::ofFloat(glm::distance(glm::vec2(locationA->position()), glm::vec2(locationB->position()))); } Variable Routines::getStartingLocation(const VariablesList &args, ExecutionContext &ctx) { const ModuleInfo &info = _game->module()->info(); auto location = make_shared(info.entryPosition, info.entryFacing); - return Variable(VariableType::Location, move(location)); + return Variable::ofLocation(move(location)); } } // namespace game diff --git a/src/game/script/routines_events.cpp b/src/game/script/routines_events.cpp index 422c74ee..830b8e43 100644 --- a/src/game/script/routines_events.cpp +++ b/src/game/script/routines_events.cpp @@ -33,7 +33,7 @@ namespace game { Variable Routines::eventUserDefined(const VariablesList &args, ExecutionContext &ctx) { int eventNumber = getInt(args, 0); auto event = make_shared(eventNumber); - return Variable(VariableType::Event, event); + return Variable::ofEvent(event); } Variable Routines::signalEvent(const VariablesList &args, ExecutionContext &ctx) { @@ -53,7 +53,7 @@ Variable Routines::signalEvent(const VariablesList &args, ExecutionContext &ctx) } Variable Routines::getUserDefinedEventNumber(const VariablesList &args, ExecutionContext &ctx) { - return ctx.userDefinedEventNumber; + return Variable::ofInt(ctx.userDefinedEventNumber); } } // namespace game diff --git a/src/game/script/routines_items.cpp b/src/game/script/routines_items.cpp index 0e3a19fc..86eb14ee 100644 --- a/src/game/script/routines_items.cpp +++ b/src/game/script/routines_items.cpp @@ -106,9 +106,9 @@ Variable Routines::getItemStackSize(const VariablesList &args, ExecutionContext auto item = getItem(args, 0); if (!item) { debug("Script: getItemStackSize: item is invalid"); - return 0; + return Variable::ofInt(0); } - return item->stackSize(); + return Variable::ofInt(item->stackSize()); } Variable Routines::setItemStackSize(const VariablesList &args, ExecutionContext &ctx) { @@ -126,9 +126,9 @@ Variable Routines::getIdentified(const VariablesList &args, ExecutionContext &ct auto item = getItem(args, 0); if (!item) { debug("Script: getIdentified: item is invalid"); - return 0; + return Variable::ofInt(0); } - return item->isIdentified() ? 1 : 0; + return Variable::ofInt(item->isIdentified() ? 1 : 0); } Variable Routines::setIdentified(const VariablesList &args, ExecutionContext &ctx) { @@ -144,11 +144,11 @@ Variable Routines::setIdentified(const VariablesList &args, ExecutionContext &ct Variable Routines::getItemPossessedBy(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); - if (!creature) return shared_ptr(); + if (!creature) return Variable::ofObject(shared_ptr()); auto itemTag = boost::to_lower_copy(getString(args, 1)); - return static_pointer_cast(creature->getItemByTag(itemTag)); + return Variable::ofObject(creature->getItemByTag(itemTag)); } Variable Routines::getBaseItemType(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_math.cpp b/src/game/script/routines_math.cpp index 8ab390d1..6c05370d 100644 --- a/src/game/script/routines_math.cpp +++ b/src/game/script/routines_math.cpp @@ -29,83 +29,83 @@ namespace game { Variable Routines::fabs(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - return glm::abs(value); + return Variable::ofFloat(glm::abs(value)); } Variable Routines::cos(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - return glm::cos(value); + return Variable::ofFloat(glm::cos(value)); } Variable Routines::sin(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - return glm::sin(value); + return Variable::ofFloat(glm::sin(value)); } Variable Routines::tan(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - return glm::tan(value); + return Variable::ofFloat(glm::tan(value)); } Variable Routines::acos(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - if (value > 1 || value < -1) return 0.0f; + if (value > 1 || value < -1) return Variable::ofFloat(0.0f); - return glm::acos(value); + return Variable::ofFloat(glm::acos(value)); } Variable Routines::asin(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - if (value > 1 || value < -1) return 0.0f; + if (value > 1 || value < -1) return Variable::ofFloat(0.0f); - return glm::asin(value); + return Variable::ofFloat(glm::asin(value)); } Variable Routines::atan(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - return glm::atan(value); + return Variable::ofFloat(glm::atan(value)); } Variable Routines::log(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - if (value <= 0.0f) return 0.0f; + if (value <= 0.0f) return Variable::ofFloat(0.0f); - return glm::log(value); + return Variable::ofFloat(glm::log(value)); } Variable Routines::pow(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); float exponent = getFloat(args, 1); - if (value == 0.0f && exponent < 0.0f) return 0.0f; + if (value == 0.0f && exponent < 0.0f) return Variable::ofFloat(0.0f); - return glm::pow(value, exponent); + return Variable::ofFloat(glm::pow(value, exponent)); } Variable Routines::sqrt(const VariablesList &args, ExecutionContext &ctx) { float value = getFloat(args, 0); - if (value < 0.0f) return 0.0f; + if (value < 0.0f) return Variable::ofFloat(0.0f); - return glm::sqrt(value); + return Variable::ofFloat(glm::sqrt(value)); } Variable Routines::abs(const VariablesList &args, ExecutionContext &ctx) { int value = getInt(args, 0); - return glm::abs(value); + return Variable::ofInt(glm::abs(value)); } Variable Routines::vectorCreate(const VariablesList &args, ExecutionContext &ctx) { float x = getFloat(args, 0); float y = getFloat(args, 1); float z = getFloat(args, 2); - return glm::vec3(x, y, z); + return Variable::ofVector(glm::vec3(x, y, z)); } Variable Routines::vectorNormalize(const VariablesList &args, ExecutionContext &ctx) { - return glm::normalize(getVector(args, 0)); + return Variable::ofVector(glm::normalize(getVector(args, 0))); } Variable Routines::vectorMagnitude(const VariablesList &args, ExecutionContext &ctx) { - return getVector(args, 0).length(); + return Variable::ofFloat(getVector(args, 0).length()); } } // namespace game diff --git a/src/game/script/routines_objects.cpp b/src/game/script/routines_objects.cpp index daa3bfcf..e63a444a 100644 --- a/src/game/script/routines_objects.cpp +++ b/src/game/script/routines_objects.cpp @@ -45,11 +45,11 @@ Variable Routines::destroyObject(const VariablesList &args, ExecutionContext &ct } Variable Routines::getEnteringObject(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(getTriggerrer(ctx)); + return Variable::ofObject(getTriggerrer(ctx)); } Variable Routines::getIsObjectValid(const VariablesList &args, ExecutionContext &ctx) { - return static_cast(getObject(args, 0)); + return Variable::ofInt(static_cast(getObject(args, 0)) ? 1 : 0); } Variable Routines::getObjectByTag(const VariablesList &args, ExecutionContext &ctx) { @@ -58,11 +58,11 @@ Variable Routines::getObjectByTag(const VariablesList &args, ExecutionContext &c // Apparently, empty string in this context stands for the player if (tag.empty()) { - return static_pointer_cast(_game->party().player()); + return Variable::ofObject(_game->party().player()); } int nth = getInt(args, 1, 0); - return static_pointer_cast(_game->module()->area()->getObjectByTag(tag, nth)); + return Variable::ofObject(_game->module()->area()->getObjectByTag(tag, nth)); } Variable Routines::getWaypointByTag(const VariablesList &args, ExecutionContext &ctx) { @@ -71,15 +71,15 @@ Variable Routines::getWaypointByTag(const VariablesList &args, ExecutionContext for (auto &waypoint : _game->module()->area()->getObjectsByType(ObjectType::Waypoint)) { if (waypoint->tag() == tag) { - return static_pointer_cast(waypoint); + return Variable::ofObject(waypoint); } } - return shared_ptr(); + return Variable::ofObject(shared_ptr()); } Variable Routines::getArea(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(_game->module()->area()); + return Variable::ofObject(_game->module()->area()); } Variable Routines::setLocked(const VariablesList &args, ExecutionContext &ctx) { @@ -97,77 +97,74 @@ Variable Routines::getLocked(const VariablesList &args, ExecutionContext &ctx) { auto target = getDoor(args, 0); if (!target) { debug("Script: getLocked: target is invalid"); - return 0; + return Variable::ofInt(0); } - return target->isLocked() ? 1 : 0; + return Variable::ofInt(target->isLocked() ? 1 : 0); } Variable Routines::getModule(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(_game->module()); + return Variable::ofObject(_game->module()); } Variable Routines::getTag(const VariablesList &args, ExecutionContext &ctx) { - static string empty; - auto object = getObject(args, 0); if (!object) { debug("Script: getTag: object is invalid"); - return empty; + return Variable::ofString(""); } - - return object->tag(); + return Variable::ofString(object->tag()); } Variable Routines::getDistanceToObject(const VariablesList &args, ExecutionContext &ctx) { auto caller = getCallerAsSpatial(ctx); if (!caller) { debug("Script: getDistanceToObject: caller is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } auto object = getSpatialObject(args, 0); if (!object) { debug("Script: getDistanceToObject: object is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } - return caller->getDistanceTo(*object); + return Variable::ofFloat(caller->getDistanceTo(*object)); } Variable Routines::getDistanceToObject2D(const VariablesList &args, ExecutionContext &ctx) { auto caller = getCallerAsSpatial(ctx); if (!caller) { debug("Script: getDistanceToObject2D: caller is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } auto object = getSpatialObject(args, 0); if (!object) { debug("Script: getDistanceToObject2D: object is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } - return caller->getDistanceTo(glm::vec2(object->position())); + return Variable::ofFloat(caller->getDistanceTo(glm::vec2(object->position()))); } Variable Routines::getExitingObject(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(getTriggerrer(ctx)); + return Variable::ofObject(getTriggerrer(ctx)); } Variable Routines::getFacing(const VariablesList &args, ExecutionContext &ctx) { auto target = getSpatialObject(args, 0); if (!target) { debug("Script: getFacing: target is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } - return glm::degrees(target->facing()); + return Variable::ofFloat(glm::degrees(target->facing())); } Variable Routines::getPosition(const VariablesList &args, ExecutionContext &ctx) { auto target = getSpatialObject(args, 0); if (!target) { debug("Script: getPosition: target is invalid"); - return glm::vec3(0.0f); + return Variable::ofVector(glm::vec3(0.0f)); } - return target->position(); + return Variable::ofVector(target->position()); } Variable Routines::soundObjectPlay(const VariablesList &args, ExecutionContext &ctx) { @@ -194,56 +191,56 @@ Variable Routines::getDistanceBetween(const VariablesList &args, ExecutionContex auto objectA = getSpatialObject(args, 0); if (!objectA) { debug("Script: getDistanceBetween: objectA is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } auto objectB = getSpatialObject(args, 1); if (!objectB) { debug("Script: getDistanceBetween: objectB is invalid"); - return -1.0f; + return Variable::ofFloat(-1.0f); } - return objectA->getDistanceTo(*objectB); + return Variable::ofFloat(objectA->getDistanceTo(*objectB)); } Variable Routines::getDistanceBetween2D(const VariablesList &args, ExecutionContext &ctx) { auto objectA = getSpatialObject(args, 0); if (!objectA) { debug("Script: getDistanceBetween2D: objectA is invalid"); - return 0.0f; + return Variable::ofFloat(0.0f); } auto objectB = getSpatialObject(args, 1); if (!objectB) { debug("Script: getDistanceBetween2D: objectB is invalid"); - return 0.0f; + return Variable::ofFloat(0.0f); } - return objectA->getDistanceTo(glm::vec2(objectB->position())); + return Variable::ofFloat(objectA->getDistanceTo(glm::vec2(objectB->position()))); } Variable Routines::getIsDead(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: getIsDead: creature is invalid"); - return false; + return Variable::ofInt(0); } - return creature->isDead(); + return Variable::ofInt(creature->isDead() ? 1 : 0); } Variable Routines::getIsInCombat(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreatureOrCaller(args, 0, ctx); if (!creature) { debug("Script: getIsInCombat: creature is invalid"); - return false; + return Variable::ofInt(0); } - return creature->isInCombat(); + return Variable::ofInt(creature->isInCombat() ? 1 : 0); } Variable Routines::getIsOpen(const VariablesList &args, ExecutionContext &ctx) { auto object = getSpatialObject(args, 0); if (!object) { debug("Script: getIsOpen: object is invalid"); - return false; + return Variable::ofInt(0); } - return object->isOpen(); + return Variable::ofInt(object->isOpen() ? 1 : 0); } Variable Routines::setFacing(const VariablesList &args, ExecutionContext &ctx) { @@ -269,33 +266,31 @@ Variable Routines::setFacingPoint(const VariablesList &args, ExecutionContext &c } Variable Routines::getName(const VariablesList &args, ExecutionContext &ctx) { - static string empty; - auto object = getObject(args, 0); if (!object) { debug("Script: getName: object is invalid"); - return empty; + return Variable::ofString(""); } - return object->name(); + return Variable::ofString(object->name()); } Variable Routines::getObjectType(const VariablesList &args, ExecutionContext &ctx) { auto target = getObject(args, 0); if (!target) { debug("Script: getObjectType: target is invalid"); - return static_cast(ObjectType::Invalid); + return Variable::ofInt(static_cast(ObjectType::Invalid)); } - return static_cast(target->type()); + return Variable::ofInt(static_cast(target->type())); } Variable Routines::getPlotFlag(const VariablesList &args, ExecutionContext &ctx) { auto target = getObjectOrCaller(args, 0, ctx); if (!target) { debug("Script: getPlotFlag: target is invalid"); - return 0; + return Variable::ofInt(0); } - return target->plotFlag(); + return Variable::ofInt(target->plotFlag()); } Variable Routines::setPlotFlag(const VariablesList &args, ExecutionContext &ctx) { @@ -329,9 +324,9 @@ Variable Routines::getCommandable(const VariablesList &args, ExecutionContext &c auto target = getObjectOrCaller(args, 0, ctx); if (!target) { debug("Script: getCommandable: target is invalid"); - return 0; + return Variable::ofInt(0); } - return target->isCommandable() ? 1 : 0; + return Variable::ofInt(target->isCommandable() ? 1 : 0); } Variable Routines::setCommandable(const VariablesList &args, ExecutionContext &ctx) { @@ -361,11 +356,11 @@ Variable Routines::playAnimation(const VariablesList &args, ExecutionContext &ct } Variable Routines::getLastOpenedBy(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(getTriggerrer(ctx)); + return Variable::ofObject(getTriggerrer(ctx)); } Variable Routines::getAreaUnescapable(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->area()->isUnescapable() ? 1 : 0; + return Variable::ofInt(_game->module()->area()->isUnescapable() ? 1 : 0); } Variable Routines::setAreaUnescapable(const VariablesList &args, ExecutionContext &ctx) { @@ -400,7 +395,7 @@ Variable Routines::createObject(const VariablesList &args, ExecutionContext &ctx auto location = getLocationEngineType(args, 2); bool useAppearAnimation = getBool(args, 3, false); - return static_pointer_cast(_game->module()->area()->createObject(objectType, blueprintResRef, location)); + return Variable::ofObject(_game->module()->area()->createObject(objectType, blueprintResRef, location)); } Variable Routines::getNearestCreature(const VariablesList &args, ExecutionContext &ctx) { @@ -424,7 +419,7 @@ Variable Routines::getNearestCreature(const VariablesList &args, ExecutionContex shared_ptr creature(_game->module()->area()->creatureFinder().getNearestCreature(target, criterias, nth - 1)); - return static_pointer_cast(creature); + return Variable::ofObject(creature); } Variable Routines::getNearestCreatureToLocation(const VariablesList &args, ExecutionContext &ctx) { @@ -448,7 +443,7 @@ Variable Routines::getNearestCreatureToLocation(const VariablesList &args, Execu shared_ptr creature(_game->module()->area()->creatureFinder().getNearestCreatureToLocation(*location, criterias, nth - 1)); - return static_pointer_cast(creature); + return Variable::ofObject(creature); } Variable Routines::getNearestObject(const VariablesList &args, ExecutionContext &ctx) { @@ -460,7 +455,7 @@ Variable Routines::getNearestObject(const VariablesList &args, ExecutionContext return object->type() == objectType; })); - return static_pointer_cast(object); + return Variable::ofObject(object); } Variable Routines::getNearestObjectToLocation(const VariablesList &args, ExecutionContext &ctx) { @@ -472,7 +467,7 @@ Variable Routines::getNearestObjectToLocation(const VariablesList &args, Executi return object->type() == objectType; })); - return static_pointer_cast(object); + return Variable::ofObject(object); } Variable Routines::getNearestObjectByTag(const VariablesList &args, ExecutionContext &ctx) { @@ -484,7 +479,7 @@ Variable Routines::getNearestObjectByTag(const VariablesList &args, ExecutionCon return object->tag() == tag; })); - return static_pointer_cast(object); + return Variable::ofObject(object); } Variable Routines::getCurrentAction(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_party.cpp b/src/game/script/routines_party.cpp index 3fbe6cdf..0327ee2e 100644 --- a/src/game/script/routines_party.cpp +++ b/src/game/script/routines_party.cpp @@ -40,7 +40,7 @@ Variable Routines::addAvailableNPCByTemplate(const VariablesList &args, Executio bool added = _game->party().addAvailableMember(npc, blueprint); - return added ? 1 : 0; + return Variable::ofInt(added ? 1 : 0); } Variable Routines::showPartySelectionGUI(const VariablesList &args, ExecutionContext &ctx) { @@ -64,40 +64,40 @@ Variable Routines::getIsPC(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: getIsPC: creature is invalid"); - return 0; + return Variable::ofInt(0); } auto player = _game->party().player(); - return player == creature ? 1 : 0; + return Variable::ofInt(player == creature ? 1 : 0); } Variable Routines::isAvailableCreature(const VariablesList &args, ExecutionContext &ctx) { int npc = getInt(args, 0); bool isAvailable = _game->party().isMemberAvailable(npc); - return isAvailable ? 1 : 0; + return Variable::ofInt(isAvailable ? 1 : 0); } Variable Routines::isObjectPartyMember(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: isObjectPartyMember: creature is invalid"); - return 0; + return Variable::ofInt(0); } - return _game->party().isMember(*creature) ? 1 : 0; + return Variable::ofInt(_game->party().isMember(*creature) ? 1 : 0); } Variable Routines::getPartyMemberByIndex(const VariablesList &args, ExecutionContext &ctx) { int index = getInt(args, 0); - return static_pointer_cast(_game->party().getMember(index)); + return Variable::ofObject(_game->party().getMember(index)); } Variable Routines::getPCSpeaker(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(_game->party().player()); + return Variable::ofObject(_game->party().player()); } Variable Routines::isNPCPartyMember(const VariablesList &args, ExecutionContext &ctx) { int npc = getInt(args, 0); bool isMember = _game->party().isMember(npc); - return isMember ? 1 : 0; + return Variable::ofInt(isMember ? 1 : 0); } Variable Routines::setPartyLeader(const VariablesList &args, ExecutionContext &ctx) { @@ -110,17 +110,17 @@ Variable Routines::addPartyMember(const VariablesList &args, ExecutionContext &c auto creature = getCreature(args, 1); if (!creature) { debug("Script: addPartyMember: creature is invalid"); - return 0; + return Variable::ofInt(0); } int npc = getInt(args, 0); _game->party().addAvailableMember(npc, creature->blueprintResRef()); - return 1; + return Variable::ofInt(1); } Variable Routines::removePartyMember(const VariablesList &args, ExecutionContext &ctx) { int npc = getInt(args, 0); - if (!_game->party().isMember(npc)) return 0; + if (!_game->party().isMember(npc)) return Variable::ofInt(0); _game->party().removeMember(npc); @@ -128,29 +128,29 @@ Variable Routines::removePartyMember(const VariablesList &args, ExecutionContext area->unloadParty(); area->reloadParty(); - return 1; + return Variable::ofInt(1); } Variable Routines::getFirstPC(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(_game->party().player()); + return Variable::ofObject(_game->party().player()); } Variable Routines::getPartyMemberCount(const VariablesList &args, ExecutionContext &ctx) { - return _game->party().getSize(); + return Variable::ofInt(_game->party().getSize()); } Variable Routines::removeAvailableNPC(const VariablesList &args, ExecutionContext &ctx) { int npc = getInt(args, 0); bool removed = _game->party().removeAvailableMember(npc); - return removed ? 1 : 0; + return Variable::ofInt(removed ? 1 : 0); } Variable Routines::getPartyLeader(const VariablesList &args, ExecutionContext &ctx) { - return static_pointer_cast(_game->party().getLeader()); + return Variable::ofObject(_game->party().getLeader()); } Variable Routines::getSoloMode(const VariablesList &args, ExecutionContext &ctx) { - return _game->party().isSoloMode() ? 1 : 0; + return Variable::ofInt(_game->party().isSoloMode() ? 1 : 0); } Variable Routines::setSoloMode(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_rp.cpp b/src/game/script/routines_rp.cpp index 41540409..f9542ae6 100644 --- a/src/game/script/routines_rp.cpp +++ b/src/game/script/routines_rp.cpp @@ -35,114 +35,111 @@ Variable Routines::getGender(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: getGender: creature is invalid"); - return static_cast(Gender::None); + return Variable::ofInt(static_cast(Gender::None)); } - return static_cast(creature->gender()); + return Variable::ofInt(static_cast(creature->gender())); } Variable Routines::getHitDice(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: getGender: creature is invalid"); - return static_cast(Gender::None); + return Variable::ofInt(static_cast(Gender::None)); } - return static_cast(creature->attributes().getAggregateLevel()); + return Variable::ofInt(static_cast(creature->attributes().getAggregateLevel())); } Variable Routines::getClassByPosition(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreatureOrCaller(args, 1, ctx); if (!creature) { debug("Script: getClassByPosition: creature is invalid"); - return static_cast(ClassType::Invalid); + return Variable::ofInt(static_cast(ClassType::Invalid)); } int position = getInt(args, 0); - return static_cast(creature->attributes().getClassByPosition(position)); + return Variable::ofInt(static_cast(creature->attributes().getClassByPosition(position))); } Variable Routines::getLevelByClass(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreatureOrCaller(args, 1, ctx); if (!creature) { debug("Script: getLevelByClass: creature is invalid"); - return 0; + return Variable::ofInt(0); } ClassType clazz = static_cast(getInt(args, 0)); - return creature->attributes().getClassLevel(clazz); + return Variable::ofInt(creature->attributes().getClassLevel(clazz)); } Variable Routines::getHasSkill(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreatureOrCaller(args, 1, ctx); if (!creature) { debug("Script: getHasSkill: creature is invalid"); - return 0; + return Variable::ofInt(0); } Skill skill = static_cast(getInt(args, 0)); - return creature->attributes().skills().contains(skill) ? 1 : 0; + return Variable::ofInt(creature->attributes().skills().contains(skill) ? 1 : 0); } Variable Routines::getCurrentHitPoints(const VariablesList &args, ExecutionContext &ctx) { auto object = getObjectOrCaller(args, 0, ctx); if (!object) { debug("Script: getCurrentHitPoints: object is invalid"); - return 0; + return Variable::ofInt(0); } - return object->currentHitPoints(); + return Variable::ofInt(object->currentHitPoints()); } Variable Routines::getMaxHitPoints(const VariablesList &args, ExecutionContext &ctx) { auto object = getObjectOrCaller(args, 0, ctx); if (!object) { debug("Script: getMaxHitPoints: object is invalid"); - return 0; + return Variable::ofInt(0); } - return object->maxHitPoints(); + return Variable::ofInt(object->maxHitPoints()); } Variable Routines::getMinOneHP(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); if (!object) { debug("Script: getMinOneHP: object is invalid"); - return 0; + return Variable::ofInt(0); } - return object->isMinOneHP() ? 1 : 0; + return Variable::ofInt(object->isMinOneHP() ? 1 : 0); } Variable Routines::setMaxHitPoints(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); - if (!object) { + if (object) { + int maxHP = getInt(args, 1); + object->setMaxHitPoints(maxHP); + } else { debug("Script: setMaxHitPoints: object is invalid"); - return 0; } - int maxHP = getInt(args, 1); - object->setMaxHitPoints(maxHP); - return Variable(); } Variable Routines::setMinOneHP(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); - if (!object) { + if (object) { + bool minOneHP = getBool(args, 1); + object->setMinOneHP(minOneHP); + } else { debug("Script: setMinOneHP: object is invalid"); - return 0; } - bool minOneHP = getBool(args, 1); - object->setMinOneHP(minOneHP); - return Variable(); } Variable Routines::changeFaction(const VariablesList &args, ExecutionContext &ctx) { auto objectToChangeFaction = getCreature(args, 0); - if (!objectToChangeFaction) { + if (objectToChangeFaction) { + auto memberOfFactionToJoin = getCreature(args, 1); + if (memberOfFactionToJoin) { + objectToChangeFaction->setFaction(memberOfFactionToJoin->faction()); + } else { + debug("Script: changeFaction: memberOfFactionToJoin is invalid"); + } + } else { debug("Script: changeFaction: objectToChangeFaction is invalid"); - return Variable(); } - auto memberOfFactionToJoin = getCreature(args, 1); - if (!memberOfFactionToJoin) { - debug("Script: changeFaction: memberOfFactionToJoin is invalid"); - return Variable(); - } - objectToChangeFaction->setFaction(memberOfFactionToJoin->faction()); - return Variable(); } @@ -161,107 +158,107 @@ Variable Routines::getFactionEqual(const VariablesList &args, ExecutionContext & auto firstObject = getCreature(args, 0); if (!firstObject) { debug("Script: getStandardFaction: firstObject is invalid"); - return 0; + return Variable::ofInt(0); } auto secondObject = getCreatureOrCaller(args, 1, ctx); if (!secondObject) { debug("Script: getStandardFaction: secondObject is invalid"); - return 0; + return Variable::ofInt(0); } - return firstObject->faction() == secondObject->faction() ? 1 : 0; + return Variable::ofInt(firstObject->faction() == secondObject->faction() ? 1 : 0); } Variable Routines::getStandardFaction(const VariablesList &args, ExecutionContext &ctx) { auto object = getCreature(args, 0); if (!object) { debug("Script: getStandardFaction: object is invalid"); - return static_cast(Faction::Invalid); + return Variable::ofInt(static_cast(Faction::Invalid)); } - return static_cast(object->faction()); + return Variable::ofInt(static_cast(object->faction())); } Variable Routines::getIsEnemy(const VariablesList &args, ExecutionContext &ctx) { auto target = getCreature(args, 0); if (!target) { debug("Script: getIsEnemy: target is invalid"); - return 0; + return Variable::ofInt(0); } auto source = getCreatureOrCaller(args, 1, ctx); if (!source) { debug("Script: getIsEnemy: source is invalid"); - return 0; + return Variable::ofInt(0); } - return Reputes::instance().getIsEnemy(*target, *source); + return Variable::ofInt(Reputes::instance().getIsEnemy(*target, *source)); } Variable Routines::getIsFriend(const VariablesList &args, ExecutionContext &ctx) { auto target = getCreature(args, 0); if (!target) { debug("Script: getIsFriend: target is invalid"); - return 0; + return Variable::ofInt(0); } auto source = getCreatureOrCaller(args, 1, ctx); if (!source) { debug("Script: getIsFriend: source is invalid"); - return 0; + return Variable::ofInt(0); } - return Reputes::instance().getIsFriend(*target, *source); + return Variable::ofInt(Reputes::instance().getIsFriend(*target, *source)); } Variable Routines::getIsNeutral(const VariablesList &args, ExecutionContext &ctx) { auto target = getCreature(args, 0); if (!target) { debug("Script: getIsNeutral: target is invalid"); - return 0; + return Variable::ofInt(0); } auto source = getCreatureOrCaller(args, 1, ctx); if (!source) { debug("Script: getIsNeutral: source is invalid"); - return 0; + return Variable::ofInt(0); } - return Reputes::instance().getIsNeutral(*target, *source); + return Variable::ofInt(Reputes::instance().getIsNeutral(*target, *source)); } Variable Routines::getAbilityScore(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: getAbilityScore: creature is invalid"); - return 0; + return Variable::ofInt(0); } Ability type = static_cast(getInt(args, 1)); - return creature->attributes().abilities().getScore(type); + return Variable::ofInt(creature->attributes().abilities().getScore(type)); } Variable Routines::getLevelByPosition(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreatureOrCaller(args, 1, ctx); if (!creature) { debug("Script: getLevelByPosition: creature is invalid"); - return 0; + return Variable::ofInt(0); } int position = getInt(args, 0); - return creature->attributes().getLevelByPosition(position); + return Variable::ofInt(creature->attributes().getLevelByPosition(position)); } Variable Routines::getSkillRank(const VariablesList &args, ExecutionContext &ctx) { auto object = getCreatureOrCaller(args, 1, ctx); if (!object) { debug("Script: getSkillRank: object is invalid"); - return 0; + return Variable::ofInt(0); } Skill skill = static_cast(getInt(args, 0)); - return object->attributes().skills().getRank(skill); + return Variable::ofInt(object->attributes().skills().getRank(skill)); } Variable Routines::getXP(const VariablesList &args, ExecutionContext &ctx) { auto creature = getCreature(args, 0); if (!creature) { debug("Script: getXP: creature is invalid"); - return 0; + return Variable::ofInt(0); } - return creature->xp(); + return Variable::ofInt(creature->xp()); } Variable Routines::setXP(const VariablesList &args, ExecutionContext &ctx) { @@ -287,7 +284,7 @@ Variable Routines::giveXPToCreature(const VariablesList &args, ExecutionContext } Variable Routines::getMaxStealthXP(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->area()->maxStealthXP(); + return Variable::ofInt(_game->module()->area()->maxStealthXP()); } Variable Routines::setMaxStealthXP(const VariablesList &args, ExecutionContext &ctx) { @@ -297,7 +294,7 @@ Variable Routines::setMaxStealthXP(const VariablesList &args, ExecutionContext & } Variable Routines::getCurrentStealthXP(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->area()->currentStealthXP(); + return Variable::ofInt(_game->module()->area()->currentStealthXP()); } Variable Routines::setCurrentStealthXP(const VariablesList &args, ExecutionContext &ctx) { @@ -308,7 +305,7 @@ Variable Routines::setCurrentStealthXP(const VariablesList &args, ExecutionConte Variable Routines::getStealthXPEnabled(const VariablesList &args, ExecutionContext &ctx) { bool enabled = _game->module()->area()->isStealthXPEnabled(); - return enabled ? 1 : 0; + return Variable::ofInt(enabled ? 1 : 0); } Variable Routines::setStealthXPEnabled(const VariablesList &args, ExecutionContext &ctx) { @@ -318,7 +315,7 @@ Variable Routines::setStealthXPEnabled(const VariablesList &args, ExecutionConte } Variable Routines::getStealthXPDecrement(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->area()->stealthXPDecrement(); + return Variable::ofInt(_game->module()->area()->stealthXPDecrement()); } Variable Routines::setStealthXPDecrement(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_time.cpp b/src/game/script/routines_time.cpp index 03f8e5e4..bd30f019 100644 --- a/src/game/script/routines_time.cpp +++ b/src/game/script/routines_time.cpp @@ -30,41 +30,41 @@ namespace game { Variable Routines::getIsDawn(const VariablesList &args, ExecutionContext &ctx) { shared_ptr module(_game->module()); const Module::Time &time = module->time(); - return time.hour == module->info().dawnHour ? 1 : 0; + return Variable::ofInt(time.hour == module->info().dawnHour ? 1 : 0); } Variable Routines::getIsDay(const VariablesList &args, ExecutionContext &ctx) { shared_ptr module(_game->module()); const Module::Time &time = module->time(); - return time.hour > module->info().dawnHour && time.hour < module->info().duskHour ? 1 : 0; + return Variable::ofInt(time.hour > module->info().dawnHour && time.hour < module->info().duskHour ? 1 : 0); } Variable Routines::getIsDusk(const VariablesList &args, ExecutionContext &ctx) { shared_ptr module(_game->module()); const Module::Time &time = module->time(); - return time.hour == module->info().duskHour ? 1 : 0; + return Variable::ofInt(time.hour == module->info().duskHour ? 1 : 0); } Variable Routines::getIsNight(const VariablesList &args, ExecutionContext &ctx) { shared_ptr module(_game->module()); const Module::Time &time = module->time(); - return time.hour < module->info().dawnHour || time.hour > module->info().duskHour ? 1 : 0; + return Variable::ofInt(time.hour < module->info().dawnHour || time.hour > module->info().duskHour ? 1 : 0); } Variable Routines::getTimeHour(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->time().hour; + return Variable::ofInt(_game->module()->time().hour); } Variable Routines::getTimeMillisecond(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->time().millisecond; + return Variable::ofInt(_game->module()->time().millisecond); } Variable Routines::getTimeMinute(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->time().minute; + return Variable::ofInt(_game->module()->time().minute); } Variable Routines::getTimeSecond(const VariablesList &args, ExecutionContext &ctx) { - return _game->module()->time().second; + return Variable::ofInt(_game->module()->time().second); } Variable Routines::setTime(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_vars.cpp b/src/game/script/routines_vars.cpp index 4bc76bd1..f3f5b3d6 100644 --- a/src/game/script/routines_vars.cpp +++ b/src/game/script/routines_vars.cpp @@ -32,39 +32,39 @@ namespace game { Variable Routines::getGlobalBoolean(const VariablesList &args, ExecutionContext &ctx) { string id(getString(args, 0)); - return _game->getGlobalBoolean(id); + return Variable::ofInt(static_cast(_game->getGlobalBoolean(id))); } Variable Routines::getGlobalNumber(const VariablesList &args, ExecutionContext &ctx) { string id(getString(args, 0)); - return _game->getGlobalNumber(id); + return Variable::ofInt(_game->getGlobalNumber(id)); } Variable Routines::getGlobalString(const VariablesList &args, ExecutionContext &ctx) { string id(getString(args, 0)); - return _game->getGlobalString(id); + return Variable::ofString(_game->getGlobalString(id)); } Variable Routines::getLocalBoolean(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); if (!object) { debug("Script: getLocalBoolean: object is invalid"); - return false; + return Variable::ofInt(0); } int index = getInt(args, 1); - return _game->getLocalBoolean(object->id(), index); + return Variable::ofInt(static_cast(_game->getLocalBoolean(object->id(), index))); } Variable Routines::getLocalNumber(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); if (!object) { debug("Script: getLocalNumber: object is invalid"); - return false; + return Variable::ofInt(0); } int index = getInt(args, 1); - return _game->getLocalNumber(object->id(), index); + return Variable::ofInt(_game->getLocalNumber(object->id(), index)); } Variable Routines::setGlobalBoolean(const VariablesList &args, ExecutionContext &ctx) { @@ -96,33 +96,31 @@ Variable Routines::setGlobalString(const VariablesList &args, ExecutionContext & Variable Routines::setLocalBoolean(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); - if (!object) { + if (object) { + int index = getInt(args, 1); + bool value = getBool(args, 2); + _game->setLocalBoolean(object->id(), index, value); + } else { debug("Script: setLocalBoolean: object is invalid"); - return false; } - int index = getInt(args, 1); - bool value = getBool(args, 2); - _game->setLocalBoolean(object->id(), index, value); - return Variable(); } Variable Routines::setLocalNumber(const VariablesList &args, ExecutionContext &ctx) { auto object = getObject(args, 0); - if (!object) { + if (object) { + int index = getInt(args, 1); + int value = getInt(args, 2); + _game->setLocalNumber(object->id(), index, value); + } else { debug("Script: setLocalNumber: object is invalid"); - return false; } - int index = getInt(args, 1); - int value = getInt(args, 2); - _game->setLocalNumber(object->id(), index, value); - return Variable(); } Variable Routines::getGlobalLocation(const VariablesList &args, ExecutionContext &ctx) { string id(getString(args, 0)); - return Variable(VariableType::Location, _game->getGlobalLocation(id)); + return Variable::ofLocation(_game->getGlobalLocation(id)); } Variable Routines::setGlobalLocation(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/script/execution.cpp b/src/script/execution.cpp index e50cd912..838d1b2a 100644 --- a/src/script/execution.cpp +++ b/src/script/execution.cpp @@ -186,10 +186,10 @@ void ScriptExecution::executeCopyTopSP(const Instruction &ins) { void ScriptExecution::executePushConstant(const Instruction &ins) { switch (ins.type) { case InstructionType::Int: - _stack.push_back(ins.intValue); + _stack.push_back(Variable::ofInt(ins.intValue)); break; case InstructionType::Float: - _stack.push_back(ins.floatValue); + _stack.push_back(Variable::ofFloat(ins.floatValue)); break; case InstructionType::Object: { shared_ptr object; @@ -202,11 +202,11 @@ void ScriptExecution::executePushConstant(const Instruction &ins) { default: throw logic_error("Invalid object id"); } - _stack.emplace_back(object); + _stack.push_back(Variable::ofObject(object)); break; } case InstructionType::String: - _stack.push_back(ins.strValue); + _stack.push_back(Variable::ofString(ins.strValue)); break; default: throw invalid_argument("Script: invalid instruction type: " + to_string(static_cast(ins.type))); @@ -232,7 +232,7 @@ void ScriptExecution::executeCallRoutine(const Instruction &ins) { case VariableType::Action: { ExecutionContext ctx(_context); ctx.savedState = make_shared(_savedState); - args.push_back(ctx); + args.push_back(Variable::ofAction(ctx)); break; } default: @@ -260,9 +260,9 @@ void ScriptExecution::executeCallRoutine(const Instruction &ins) { case VariableType::Void: break; case VariableType::Vector: - _stack.push_back(retValue.vecValue.z); - _stack.push_back(retValue.vecValue.y); - _stack.push_back(retValue.vecValue.x); + _stack.push_back(Variable::ofFloat(retValue.vecValue.z)); + _stack.push_back(Variable::ofFloat(retValue.vecValue.y)); + _stack.push_back(Variable::ofFloat(retValue.vecValue.x)); break; default: _stack.push_back(retValue); @@ -275,7 +275,7 @@ Variable ScriptExecution::getVectorFromStack() { float y = getFloatFromStack().floatValue; float z = getFloatFromStack().floatValue; - return glm::vec3(x, y, z); + return Variable::ofVector(glm::vec3(x, y, z)); } Variable ScriptExecution::getFloatFromStack() { @@ -293,7 +293,7 @@ void ScriptExecution::executeLogicalAnd(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue && right.intValue); + _stack.push_back(Variable::ofInt(static_cast(left.intValue && right.intValue))); } void ScriptExecution::getTwoIntegersFromStack(Variable &left, Variable &right) { @@ -308,28 +308,28 @@ void ScriptExecution::executeLogicalOr(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue || right.intValue); + _stack.push_back(Variable::ofInt(static_cast(left.intValue || right.intValue))); } void ScriptExecution::executeInclusiveBitwiseOr(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue | right.intValue); + _stack.push_back(Variable::ofInt(left.intValue | right.intValue)); } void ScriptExecution::executeExclusiveBitwiseOr(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue ^ right.intValue); + _stack.push_back(Variable::ofInt(left.intValue ^ right.intValue)); } void ScriptExecution::executeBitwiseAnd(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue & right.intValue); + _stack.push_back(Variable::ofInt(left.intValue & right.intValue)); } void ScriptExecution::executeEqual(const Instruction &ins) { @@ -338,7 +338,7 @@ void ScriptExecution::executeEqual(const Instruction &ins) { _stack.pop_back(); _stack.pop_back(); - _stack.push_back(equal); + _stack.push_back(Variable::ofInt(static_cast(equal))); } void ScriptExecution::executeNotEqual(const Instruction &ins) { @@ -347,7 +347,7 @@ void ScriptExecution::executeNotEqual(const Instruction &ins) { _stack.pop_back(); _stack.pop_back(); - _stack.push_back(notEqual); + _stack.push_back(Variable::ofInt(static_cast(notEqual))); } void ScriptExecution::executeGreaterThanOrEqual(const Instruction &ins) { @@ -356,7 +356,7 @@ void ScriptExecution::executeGreaterThanOrEqual(const Instruction &ins) { _stack.pop_back(); _stack.pop_back(); - _stack.push_back(ge); + _stack.push_back(Variable::ofInt(static_cast(ge))); } void ScriptExecution::executeGreaterThan(const Instruction &ins) { @@ -365,7 +365,7 @@ void ScriptExecution::executeGreaterThan(const Instruction &ins) { _stack.pop_back(); _stack.pop_back(); - _stack.push_back(greater); + _stack.push_back(Variable::ofInt(static_cast(greater))); } void ScriptExecution::executeLessThan(const Instruction &ins) { @@ -374,7 +374,7 @@ void ScriptExecution::executeLessThan(const Instruction &ins) { _stack.pop_back(); _stack.pop_back(); - _stack.push_back(less); + _stack.push_back(Variable::ofInt(static_cast(less))); } void ScriptExecution::executeLessThanOrEqual(const Instruction &ins) { @@ -383,21 +383,21 @@ void ScriptExecution::executeLessThanOrEqual(const Instruction &ins) { _stack.pop_back(); _stack.pop_back(); - _stack.push_back(le); + _stack.push_back(Variable::ofInt(static_cast(le))); } void ScriptExecution::executeShiftLeft(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue << right.intValue); + _stack.push_back(Variable::ofInt(left.intValue << right.intValue)); } void ScriptExecution::executeShiftRight(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue >> right.intValue); + _stack.push_back(Variable::ofInt(left.intValue >> right.intValue)); } void ScriptExecution::executeUnsignedShiftRight(const Instruction &ins) { @@ -405,7 +405,7 @@ void ScriptExecution::executeUnsignedShiftRight(const Instruction &ins) { getTwoIntegersFromStack(left, right); // TODO: proper unsigned shift - _stack.push_back(left.intValue >> right.intValue); + _stack.push_back(Variable::ofInt(left.intValue >> right.intValue)); } void ScriptExecution::executeAdd(const Instruction &ins) { @@ -448,16 +448,16 @@ void ScriptExecution::executeMod(const Instruction &ins) { Variable left, right; getTwoIntegersFromStack(left, right); - _stack.push_back(left.intValue % right.intValue); + _stack.push_back(Variable::ofInt(left.intValue % right.intValue)); } void ScriptExecution::executeNegate(const Instruction &ins) { switch (ins.type) { case InstructionType::Int: - _stack.back() = -_stack.back().intValue; + _stack.back().intValue *= -1; break; case InstructionType::Float: - _stack.back() = -_stack.back().floatValue; + _stack.back().floatValue *= -1.0f; break; default: break; @@ -523,7 +523,7 @@ void ScriptExecution::executeLogicalNot(const Instruction &ins) { bool zero = _stack.back().intValue == 0; _stack.pop_back(); - _stack.push_back(zero); + _stack.push_back(Variable::ofInt(static_cast(zero))); } void ScriptExecution::executeJumpIfNonZero(const Instruction &ins) { @@ -566,7 +566,7 @@ void ScriptExecution::executeIncRelToBP(const Instruction &ins) { void ScriptExecution::executeSaveBP(const Instruction &ins) { _globalCount = static_cast(_stack.size()); - _stack.push_back(_globalCount); + _stack.push_back(Variable::ofInt(_globalCount)); } void ScriptExecution::executeRestoreBP(const Instruction &ins) { diff --git a/src/script/variable.cpp b/src/script/variable.cpp index 1d86b030..10785e05 100644 --- a/src/script/variable.cpp +++ b/src/script/variable.cpp @@ -32,19 +32,19 @@ namespace script { Variable Variable::operator+(const Variable &other) const { if (type == VariableType::Int && other.type == VariableType::Int) { - return intValue + other.intValue; + return Variable::ofInt(intValue + other.intValue); } if (type == VariableType::Int && other.type == VariableType::Float) { - return intValue + other.floatValue; + return Variable::ofFloat(intValue + other.floatValue); } if (type == VariableType::Float && other.type == VariableType::Int) { - return floatValue + other.intValue; + return Variable::ofFloat(floatValue + other.intValue); } if (type == VariableType::Float && other.type == VariableType::Float) { - return floatValue + other.floatValue; + return Variable::ofFloat(floatValue + other.floatValue); } if (type == VariableType::String && other.type == VariableType::String) { - return strValue + other.strValue; + return Variable::ofString(strValue + other.strValue); } throw logic_error(str(boost::format("Unsupported variable types: %02x %02x") % static_cast(type) % static_cast(other.type))); @@ -52,16 +52,16 @@ Variable Variable::operator+(const Variable &other) const { Variable Variable::operator-(const Variable &other) const { if (type == VariableType::Int && other.type == VariableType::Int) { - return intValue - other.intValue; + return Variable::ofInt(intValue - other.intValue); } if (type == VariableType::Int && other.type == VariableType::Float) { - return intValue - other.floatValue; + return Variable::ofFloat(intValue - other.floatValue); } if (type == VariableType::Float && other.type == VariableType::Int) { - return floatValue - other.intValue; + return Variable::ofFloat(floatValue - other.intValue); } if (type == VariableType::Float && other.type == VariableType::Float) { - return floatValue - other.floatValue; + return Variable::ofFloat(floatValue - other.floatValue); } throw logic_error(str(boost::format("Unsupported variable types: %02x %02x") % static_cast(type) % static_cast(other.type))); @@ -69,16 +69,16 @@ Variable Variable::operator-(const Variable &other) const { Variable Variable::operator*(const Variable &other) const { if (type == VariableType::Int && other.type == VariableType::Int) { - return intValue * other.intValue; + return Variable::ofInt(intValue * other.intValue); } if (type == VariableType::Int && other.type == VariableType::Float) { - return intValue * other.floatValue; + return Variable::ofFloat(intValue * other.floatValue); } if (type == VariableType::Float && other.type == VariableType::Int) { - return floatValue * other.intValue; + return Variable::ofFloat(floatValue * other.intValue); } if (type == VariableType::Float && other.type == VariableType::Float) { - return floatValue * other.floatValue; + return Variable::ofFloat(floatValue * other.floatValue); } throw logic_error(str(boost::format("Unsupported variable types: %02x %02x") % static_cast(type) % static_cast(other.type))); @@ -86,40 +86,89 @@ Variable Variable::operator*(const Variable &other) const { Variable Variable::operator/(const Variable &other) const { if (type == VariableType::Int && other.type == VariableType::Int) { - return intValue / other.intValue; + return Variable::ofInt(intValue / other.intValue); } if (type == VariableType::Int && other.type == VariableType::Float) { - return intValue / other.floatValue; + return Variable::ofFloat(intValue / other.floatValue); } if (type == VariableType::Float && other.type == VariableType::Int) { - return floatValue / other.intValue; + return Variable::ofFloat(floatValue / other.intValue); } if (type == VariableType::Float && other.type == VariableType::Float) { - return floatValue / other.floatValue; + return Variable::ofFloat(floatValue / other.floatValue); } throw logic_error(str(boost::format("Unsupported variable types: %02x %02x") % static_cast(type) % static_cast(other.type))); } -Variable::Variable(int value) : type(VariableType::Int), intValue(value) { +Variable Variable::ofInt(int value) { + Variable result; + result.type = VariableType::Int; + result.intValue = value; + return move(result); } -Variable::Variable(float value) : type(VariableType::Float), floatValue(value) { +Variable Variable::ofFloat(float value) { + Variable result; + result.type = VariableType::Float; + result.floatValue = value; + return move(result); } -Variable::Variable(string value) : type(VariableType::String), strValue(move(value)) { +Variable Variable::ofString(string value) { + Variable result; + result.type = VariableType::String; + result.strValue = move(value); + return move(result); } -Variable::Variable(glm::vec3 value) : type(VariableType::Vector), vecValue(move(value)) { +Variable Variable::ofVector(glm::vec3 value) { + Variable result; + result.type = VariableType::Vector; + result.vecValue = move(value); + return move(result); } -Variable::Variable(const shared_ptr &object) : type(VariableType::Object), object(object) { +Variable Variable::ofObject(shared_ptr object) { + Variable result; + result.type = VariableType::Object; + result.object = move(object); + return move(result); } -Variable::Variable(VariableType type, const shared_ptr &engineType) : type(type), engineType(engineType) { +Variable Variable::ofEffect(shared_ptr engineType) { + Variable result; + result.type = VariableType::Effect; + result.engineType = move(engineType); + return move(result); } -Variable::Variable(const ExecutionContext &ctx) : type(VariableType::Action), context(ctx) { +Variable Variable::ofEvent(shared_ptr engineType) { + Variable result; + result.type = VariableType::Event; + result.engineType = move(engineType); + return move(result); +} + +Variable Variable::ofLocation(shared_ptr engineType) { + Variable result; + result.type = VariableType::Location; + result.engineType = move(engineType); + return move(result); +} + +Variable Variable::ofTalent(shared_ptr engineType) { + Variable result; + result.type = VariableType::Talent; + result.engineType = move(engineType); + return move(result); +} + +Variable Variable::ofAction(ExecutionContext context) { + Variable result; + result.type = VariableType::Action; + result.context = move(context); + return move(result); } bool Variable::operator==(const Variable &other) const { diff --git a/src/script/variable.h b/src/script/variable.h index 5ce0cb64..5b21ff26 100644 --- a/src/script/variable.h +++ b/src/script/variable.h @@ -33,8 +33,8 @@ enum class VariableType { Int, Float, String, - Object, Vector, + Object, Effect, Event, Location, @@ -59,13 +59,17 @@ struct Variable { }; Variable() = default; - Variable(int value); - Variable(float value); - Variable(std::string value); - Variable(glm::vec3 value); - Variable(const std::shared_ptr &object); - Variable(VariableType type, const std::shared_ptr &engineType); - Variable(const ExecutionContext &context); + + static Variable ofInt(int value); + static Variable ofFloat(float value); + static Variable ofString(std::string value); + static Variable ofVector(glm::vec3 value); + static Variable ofObject(std::shared_ptr object); + static Variable ofEffect(std::shared_ptr engineType); + static Variable ofEvent(std::shared_ptr engineType); + static Variable ofLocation(std::shared_ptr engineType); + static Variable ofTalent(std::shared_ptr engineType); + static Variable ofAction(ExecutionContext context); Variable operator+(const Variable &other) const; Variable operator-(const Variable &other) const;