[Info] Porting add-ons to 1.13 and [advance] → [advancement]
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
[Info] Porting add-ons to 1.13 and [advance] → [advancement]
Wesnoth version 1.13.2 brought a change to the unit interface, unit advancements that were taken were renamed from [advance] to [advancement], which simplified a few things but caused a lot of compatibility problems, especially with add-ons that modify the advancements units had taken.
My campaign was massively impacted by this, there were hundreds of places where this change happened. Changing it would be maddening and would certainly introduce a thousand bugs. To deal with this issue, I have created a script that fixes it. I am posting it for the case if someone else had a similar problem.
It's written in C++, so you have to compile it (in the following example, it's to
Here is an example of a change it does.
My campaign was massively impacted by this, there were hundreds of places where this change happened. Changing it would be maddening and would certainly introduce a thousand bugs. To deal with this issue, I have created a script that fixes it. I am posting it for the case if someone else had a similar problem.
Code: Select all
#include <cstring>
#include <iostream>
#include <fstream>
#include <cstdlib>
int main(int argc, char *argv[])
{
if (argc < 2) {
std::cerr << "Too few arguments, use " << argv[0] << " (working_file)" << std::endl;
return 1;
}
std::ifstream in(argv[1]);
if (!in.is_open()) {
std::cout << argv[1] << ": No such file\n";
return 2;
}
bool found = false;
std::string line;
while (std::getline(in, line)) {
if (line.find("advance") != std::string::npos) {
found = true;
break;
}
}
if (!found) {
in.close();
return 0;
}
in.clear();
in.seekg(0, std::ios::beg);
system(std::string(std::string("mv ") + argv[1] + std::string(" ") + argv[1] + ".backup").c_str());
std::ofstream out(argv[1]);
int edits = 0;
while (std::getline(in, line)) {
if (line.find("advance") == std::string::npos) {
out << line << std::endl;
continue;
}
std::string editedLine;
for (unsigned int i = 0; i < line.size(); i++) {
if (line[i] != '=' && i >= 7 && (line[i] < 'a' || line[i] > 'z') && line[i-7] == 'a' && line[i-6] == 'd' && line[i-5] == 'v' && line[i-4] == 'a' && line[i-3] == 'n' && line[i-2] == 'c' && line[i-1] == 'e') {
editedLine.append("ment");
editedLine.push_back(line[i]);
} else editedLine.push_back(line[i]);
}
if (editedLine != line) {
//std::cout << "Replaced line '" << line << "' with '" << editedLine << "'.\n";
edits++;
out << "#ifver WESNOTH_VERSION >= 1.13.2" << std::endl;
out << editedLine << std::endl;
out << "#else" << std::endl;
out << line << std::endl;
out << "#endif" << std::endl;
} else out << line << std::endl;
}
std::cout << "Opened " << argv[1] << " and did " << edits << " edits\n";
in.close();
out.close();
return 0;
}
advancement_updader
). If it breaks something, don't worry, it leaves backups of files. Then you can use it on all files in a folder using this bash script (if you're using Windows, you can run it by installing Windows 10 Anniversary Edition, enabling the bash feature in its settings and using the bash program that appears in start menu):for FILE in $(find -name '*.cfg'); do ./advancement_updater $FILE; done
Here is an example of a change it does.
Re: [Info] Porting add-ons to 1.13 and [advance] → [advancem
Hmm i wonder why not just defining a macro
and then replace all advance words with {ADVANCE} with regexp replace. Ofc It also matches some "post advance" and "advance" event names so you have to check each case manually but i guess thats also true for your code.
Code: Select all
#ifver WESNOTH_VERSION >= 1.13.2
#define ADVANCE
advancement#endef
#else
#define ADVANCE
advance#endef
#endif
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: [Info] Porting add-ons to 1.13 and [advance] → [advancem
Ehm, yes, that would be shorter. I haven't thought of that.