Skip to content

InfoTranslator: Draft randomUnits support#113

Draft
Slayer95 wants to merge 1 commit into
ChiefOfGxBxL:masterfrom
Slayer95:mine-wc3
Draft

InfoTranslator: Draft randomUnits support#113
Slayer95 wants to merge 1 commit into
ChiefOfGxBxL:masterfrom
Slayer95:mine-wc3

Conversation

@Slayer95

@Slayer95 Slayer95 commented May 5, 2026

Copy link
Copy Markdown
Contributor
  • This is work done on top of wc3maptranslator's v1.0.0
  • Tested for w3i file format 25 (TFT)
  • Works so far, but there are unsolved questions (no luck finding an accurate spec).
  • Sorry, this is untidy (other unrelated tiny stuff included). I figure it can't really be merged even if I tidied it, though. But let me know if you think otherwise and would want me to rebase on master.

@Slayer95 Slayer95 marked this pull request as draft May 5, 2026 21:41

@ChiefOfGxBxL ChiefOfGxBxL left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. A bunch of this work is actually in the TypeScript version already, including some of your previous work!

Comment on lines +148 to +162
// Partial support: Unit table (random)
outBuffer.addInt(infoJson.randomUnits.length);
for (const randomUnitsGroup of infoJson.randomUnits) {
outBuffer.addInt(randomUnitsGroup.id);
outBuffer.addString(randomUnitsGroup.name, true);
outBuffer.addInt(randomUnitsGroup.subTables.length);
for (let i = 0; i < randomUnitsGroup.subTables.length; i++) outBuffer.addInt(0); // ????
outBuffer.addInt(randomUnitsGroup.subTables.length);
for (let i = 0; i < randomUnitsGroup.subTables.length; i++) {
outBuffer.addFourCCTwice(randomUnitsGroup.subTables[i].variants.length);
for (let j = 0; j < randomUnitsGroup.subTables[i].variants.length; j++) {
outBuffer.addString(randomUnitsGroup.subTables[i].variants[j].object, false);
}
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're editing a .js file, when the project had several years ago been ported to TypeScript (.ts). The random unit/item table is already implemented via https://github.com/ChiefOfGxBxL/WC3MapTranslator/blob/master/src/translators/InfoTranslator.ts#L728-L757.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. After submitting this, I realized that v5.0.0 already supports random units tables. I was under the impression that v4.0.0 didn't and that v5.0.0 didn't either, which is why I originally thought this PR would be more useful 😅 , but I was wrong lol.

Still, there are some details here such as UTF8 strings, which I do correctly, but the rest of my algorithm is actually iffy.

Comment thread lib/W3Buffer.js
return String.fromCharCode(ch);
}).join('');
},
readChars: function(len, allowNull = false) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it was your commit fe0b16c 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know. As I said, this is based on v1.0.0, so I had to include it for completeness.

Ultimately, gotta evaluate to what extent each implementation of random tables is accurate. It's a bit awkward that I didn't realize at first that you already had an implementation... Feel free to close and/or cherry-pick improvements.

Comment thread lib/HexBuffer.js
},

addFourCCTwice: function(int) {
if (int >= 10) throw new Error(`idk how to encode ${int}`);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoding an int can be done via HexBuffer.addInt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is roughly supposed to store an integer as a decimal string, not as an int properly.

Comment thread lib/W3Buffer.js
let c = string.charCodeAt(i);
if (c === 0) continue;
if (c < 0x30 || 0x39 < c) throw new Error(`Invalid numerical FourCC`);
value += (c - 0x30) * (1 << (8 * i));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting - I haven't seen documentation on WC3's FourCC format, so am unfamiliar.

Do you have any references or examples, perhaps ones where the prior WC3MapTranslator implementation fails and this one is correct?

@Slayer95 Slayer95 May 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any references or examples, perhaps ones where the prior WC3MapTranslator implementation fails and this one is correct?

Will gather this. Note that the previous "FourCC" implementation is correct per se. This is a different thing, which I named "FourCC twice" for lack of a better name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, regarding FourCC, this is a close reference https://ubershmekel.github.io/fourcc-to-text/. The difference is that WC3 treats FourCC texts as case-insensitive in some contexts, such as tooltips files. I haven't fully researched the sensitiveness stuff, but it's not relevant for WC3MapTranslator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants