2012-12-20 23:16:34 +00:00
|
|
|
#include "defines.hpp"
|
|
|
|
|
2022-08-03 00:00:54 +02:00
|
|
|
#include <algorithm>
|
2013-01-01 11:59:05 -08:00
|
|
|
#include <sstream>
|
2012-12-20 23:16:34 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-08-14 19:42:41 +04:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2022-08-03 00:00:54 +02:00
|
|
|
#include <components/misc/strings/lower.hpp>
|
2015-12-07 21:58:30 +01:00
|
|
|
|
2012-12-20 23:16:34 +00:00
|
|
|
namespace Interpreter
|
|
|
|
{
|
|
|
|
|
2014-10-28 16:07:37 +01:00
|
|
|
bool check(const std::string& str, const std::string& escword, unsigned int* i, unsigned int* start)
|
|
|
|
{
|
2012-12-20 23:16:34 +00:00
|
|
|
bool retval = str.find(escword) == 0;
|
|
|
|
if (retval)
|
|
|
|
{
|
|
|
|
(*i) += escword.length();
|
|
|
|
(*start) = (*i) + 1;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> globals;
|
|
|
|
|
2014-10-28 16:07:37 +01:00
|
|
|
bool longerStr(const std::string& a, const std::string& b)
|
|
|
|
{
|
2012-12-20 23:16:34 +00:00
|
|
|
return a.length() > b.length();
|
|
|
|
}
|
|
|
|
|
2021-06-25 21:52:02 +02:00
|
|
|
static std::string fixDefinesReal(const std::string& text, bool dialogue, Context& context)
|
2014-10-28 16:07:37 +01:00
|
|
|
{
|
2012-12-20 23:16:34 +00:00
|
|
|
unsigned int start = 0;
|
2013-01-01 11:59:05 -08:00
|
|
|
std::ostringstream retval;
|
2014-10-28 16:07:37 +01:00
|
|
|
for (unsigned int i = 0; i < text.length(); i++)
|
|
|
|
{
|
2016-02-16 14:55:13 +01:00
|
|
|
char eschar = text[i];
|
|
|
|
if (eschar == '%' || eschar == '^')
|
2014-10-28 16:07:37 +01:00
|
|
|
{
|
2013-01-01 11:59:05 -08:00
|
|
|
retval << text.substr(start, i - start);
|
2022-08-02 23:57:09 +02:00
|
|
|
std::string temp = Misc::StringUtils::lowerCase(std::string_view(text).substr(i + 1, 100));
|
|
|
|
|
2014-10-28 16:07:37 +01:00
|
|
|
bool found = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ((found = check(temp, "actionslideright", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sRight}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionreadymagic", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sReady_Magic}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionprevweapon", &i, &start)))
|
|
|
|
{
|
2014-12-20 00:06:14 +01:00
|
|
|
retval << context.getActionBinding("#{sPrevWeapon}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionnextweapon", &i, &start)))
|
|
|
|
{
|
2014-12-20 00:06:14 +01:00
|
|
|
retval << context.getActionBinding("#{sNextWeapon}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actiontogglerun", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sAuto_Run}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionslideleft", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sLeft}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionreadyitem", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sReady_Weapon}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionprevspell", &i, &start)))
|
|
|
|
{
|
2014-12-20 00:06:14 +01:00
|
|
|
retval << context.getActionBinding("#{sPrevSpell}");
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "actionnextspell", &i, &start)))
|
|
|
|
{
|
2014-12-20 00:06:14 +01:00
|
|
|
retval << context.getActionBinding("#{sNextSpell}");
|
2014-10-28 16:07:37 +01:00
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionrestmenu", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sRestKey}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionmenumode", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sInventory}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionactivate", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sActivate}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionjournal", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sJournal}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionforward", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sForward}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "pccrimelevel", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCBounty();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actioncrouch", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sCrouch_Sneak}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionjump", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sJump}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionback", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sBack}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionuse", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sUse}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "actionrun", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getActionBinding("#{sRun}");
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "pcclass", &i, &start)))
|
|
|
|
{
|
2013-01-01 11:59:05 -08:00
|
|
|
retval << context.getPCClass();
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "pcrace", &i, &start)))
|
|
|
|
{
|
2013-01-01 11:59:05 -08:00
|
|
|
retval << context.getPCRace();
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "pcname", &i, &start)))
|
|
|
|
{
|
2013-01-01 11:59:05 -08:00
|
|
|
retval << context.getPCName();
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "cell", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getCurrentCellName();
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
2016-02-18 01:25:52 +01:00
|
|
|
else if (dialogue)
|
|
|
|
{ // In Dialogue, not messagebox
|
2014-10-28 16:07:37 +01:00
|
|
|
if ((found = check(temp, "faction", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getNPCFaction();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "nextpcrank", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCNextRank();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "pcnextrank", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCNextRank();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "pcrank", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCRank();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "rank", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getNPCRank();
|
2012-12-26 18:07:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:07:37 +01:00
|
|
|
else if ((found = check(temp, "class", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getNPCClass();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "race", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getNPCRace();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "name", &i, &start)))
|
|
|
|
{
|
2018-09-16 20:47:51 +04:00
|
|
|
retval << context.getActorName();
|
2014-10-28 16:07:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // In messagebox or book, not dialogue
|
|
|
|
|
|
|
|
/* empty outside dialogue */
|
|
|
|
if ((found = check(temp, "faction", &i, &start)))
|
|
|
|
;
|
|
|
|
else if ((found = check(temp, "nextpcrank", &i, &start)))
|
|
|
|
;
|
|
|
|
else if ((found = check(temp, "pcnextrank", &i, &start)))
|
|
|
|
;
|
|
|
|
else if ((found = check(temp, "pcrank", &i, &start)))
|
|
|
|
;
|
|
|
|
else if ((found = check(temp, "rank", &i, &start)))
|
|
|
|
;
|
|
|
|
|
|
|
|
/* uses pc in messageboxes */
|
|
|
|
else if ((found = check(temp, "class", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCClass();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "race", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCRace();
|
|
|
|
}
|
|
|
|
else if ((found = check(temp, "name", &i, &start)))
|
|
|
|
{
|
|
|
|
retval << context.getPCName();
|
|
|
|
}
|
|
|
|
}
|
2012-12-20 23:16:34 +00:00
|
|
|
|
2014-10-28 16:07:37 +01:00
|
|
|
/* Not a builtin, try global variables */
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
/* if list of globals is empty, grab it and sort it by descending string length */
|
|
|
|
if (globals.empty())
|
|
|
|
{
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
auto globalIds = context.getGlobals();
|
|
|
|
for (auto id : globalIds)
|
|
|
|
{
|
|
|
|
globals.push_back(id);
|
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
sort(globals.begin(), globals.end(), longerStr);
|
|
|
|
}
|
|
|
|
|
2022-08-02 23:57:09 +02:00
|
|
|
for (unsigned int j = 0; j < globals.size(); j++)
|
|
|
|
{
|
|
|
|
if (globals[j].length() > temp.length()) // Just in case there's a global with a huuuge name
|
|
|
|
temp = Misc::StringUtils::lowerCase(
|
|
|
|
std::string_view(text).substr(i + 1, globals[j].length()));
|
2014-10-28 16:07:37 +01:00
|
|
|
|
2021-04-21 09:31:44 +04:00
|
|
|
found = check(temp, globals[j], &i, &start);
|
|
|
|
if (found)
|
|
|
|
{
|
2014-10-28 16:07:37 +01:00
|
|
|
char type = context.getGlobalType(globals[j]);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
retval << context.getGlobalShort(globals[j]);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
retval << context.getGlobalLong(globals[j]);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
retval << context.getGlobalFloat(globals[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-28 16:07:37 +01:00
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2018-08-14 19:42:41 +04:00
|
|
|
Log(Debug::Error) << "Error: Failed to replace escape character, with the following error: "
|
|
|
|
<< e.what();
|
|
|
|
Log(Debug::Error) << "Full text below:\n" << text;
|
2014-10-28 16:07:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not found, or error
|
2012-12-20 23:16:34 +00:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
/* leave unmodified */
|
|
|
|
i += 1;
|
|
|
|
start = i;
|
2013-01-01 11:59:05 -08:00
|
|
|
retval << eschar;
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 11:59:05 -08:00
|
|
|
retval << text.substr(start, text.length() - start);
|
|
|
|
return retval.str();
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 14:55:13 +01:00
|
|
|
std::string fixDefinesDialog(const std::string& text, Context& context)
|
|
|
|
{
|
|
|
|
return fixDefinesReal(text, true, context);
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 14:55:13 +01:00
|
|
|
std::string fixDefinesMsgBox(const std::string& text, Context& context)
|
|
|
|
{
|
|
|
|
return fixDefinesReal(text, false, context);
|
2012-12-26 18:07:56 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 14:55:13 +01:00
|
|
|
std::string fixDefinesBook(const std::string& text, Context& context)
|
|
|
|
{
|
|
|
|
return fixDefinesReal(text, false, context);
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
|
|
|
}
|