Expression parser: Try to parse strings as number literals (bug #5097)

pull/2539/head
Capostrophic 5 years ago
parent 7b0cf868af
commit 138a7ac434

@ -127,6 +127,7 @@
Bug #5089: Swimming/Underwater creatures only swim around ground level
Bug #5092: NPCs with enchanted weapons play sound when out of charges
Bug #5093: Hand to hand sound plays on knocked out enemies
Bug #5097: String arguments can't be parsed as number literals in scripts
Bug #5099: Non-swimming enemies will enter water if player is water walking
Bug #5103: Sneaking state behavior is still inconsistent
Bug #5104: Black Dart's enchantment doesn't trigger at low Enchant levels

@ -5,6 +5,7 @@
#include <algorithm>
#include <stack>
#include <iterator>
#include <sstream>
#include <components/misc/stringops.hpp>
@ -324,6 +325,21 @@ namespace Compiler
mExplicit = name2;
return true;
}
// This is terrible, but of course we must have this for legacy content.
// Convert the string to a number even if it's impossible and use it as a number literal.
// Can't use stof/atof or to_string out of locale concerns.
float number;
std::stringstream stream(name2);
stream >> number;
stream.str(std::string());
stream.clear();
stream << number;
pushFloatLiteral(number);
mTokenLoc = loc;
getErrorHandler().warning ("Parsing a non-variable string as a number: " + stream.str(), loc);
return true;
}
else
{

Loading…
Cancel
Save