Current time: 24.11.2024, 16:12 Hello There, Guest! (LoginRegister)
Language: english | russian  

Post Reply 
Threaded Mode | Linear Mode
ERA BattleQueue
» Move order for combat / очерёдность хода в битве
Author Message
Berserker Offline
Administrators

Posts: 16657
Post: #16

RoseKavalier,
Try to use era.h https://gofile.io/d/KXWJqA
Example of language file can be found in Era II\Mods\WoG\Lang\era.json
Code:
{
  "era": {
    "global_scripts_vs_map_scripts_warning": "{Skip global scripts?}\n\nThe map has its own set of ERM scripts. Do you wish to skip loading global ERM scripts (they may cause errors, if map was not intended to be played with other ERM scripts)?",
    "no_memory_for_erm_optimization": "Sorry, but compiled ERM scripts size exceeds @limit@ MB limit. ERM optimization failed. ERM will be disabled"
  }
}

Calling tr('era.no_memory_for_erm_optimization') will return std::string with translation in ANSI (current active page) encoding (json files use UTF-8). String can be stored anywere and .c_str() method returns null terminated string pointer then.
If you need parameters in string, you can write in json:
"no_memory_for_erm_optimization": "There are only @mem_free@ MB left"
And call something like tr('era.no_memory_for_erm_optimization', { "mem_free", IntToStr(100) });

Quote:how is it handled by the game - unicode? utf8?
Json are in UTF-8. Era translation API always returns ANSI version.

RoseKavalier, there is no tactical phase in BattleHeroes. All player actions occur between BG1 and BG0.
If it is possible to update the queue when updating the battlefield via !!BU:R, it will be great.
Code:
BG0 - event before stack action
BG1 - event after stack action when another stack already obtained turn
BACall3 in ERM.

{0x473F6B,0,DP(Monster2Battle)}, // hook address

void _MonsterAfterBattle(void)
{
  __asm pusha
//asm int 3
  _EAX(MAB_ret);
  #include "templ.h"
  if((*(int *)&((Byte *)M2B_BatMan)[0x132F8])==1){
//    for(int i=0;i<(21*2);i++) *(Dword *)&M2B_BatMan[0x54CC+0x548*i+0x84]|=0x00200000;
    CheckForAliveNPCAfterBattle((Byte *)M2B_BatMan);
    MAB_ret=2;
  }
//  BACall3(1,*(int *)&((Byte *)M2B_BatMan)[0x13D6C]);
  BACall3(1,BACall_Day);
  STOP
  __asm popa
  __asm mov  eax,MAB_ret
}

void __stdcall Monster2Battle(Dword Pv2,Dword Pv1)
{
  _ECX(M2B_BatMan);
  _Monster2Battle();
  #include "templ.h"
  __asm  push   Pv1
  __asm  push   Pv2
  __asm  mov    ecx,M2B_BatMan
  __asm  mov    eax,0x4786B0
  __asm  call   eax
  STOP
  _MonsterAfterBattle();
}

BU:R — redraw battlefield, executes:

Code:
void RedrawBF(void)
{
  #include "templ.h"
  __asm{
    mov    ecx,0x699420 //-> CombatManager
    mov    ecx,[ecx]
    push   0
    push   -1
    mov    eax,0x468570
    call   eax
  }
  RETURNV
}


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
17.06.2020 00:11
Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #17

Code:
std::string tr (const char *key, const std::vector<std::string> params = {}) {
    const int MAX_PARAMS = 64;
    const char* _params[MAX_PARAMS];
    int numParams = params.size() <= MAX_PARAMS ? params.size() : MAX_PARAMS;

    for (int i = 0; i < numParams; i++) {
      _params[i] = params[i].c_str();
    }

    char* buf = _tr(key, _params, numParams - 1);
    MemFree(buf);

    return buf;
  }

This function is undefined behaviour.
It returns buf which was just MemFree, this is definitely not safe.

Thanks for the addresses!

My question related to CN-specifically was what encoding the game used... GB or GBK codepage 936.
17.06.2020 01:50
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16657
Post: #18

RoseKavalier, thanks, my fail:
Code:
char *pcharRes = _tr(key, _params, numParams - 1);
std::string result = pcharRes;
MemFree(pcharRes);

return buf;

Something like that would be better. Anyway, the best case is not to detect language (what will you do with Polish and Italian?), but provide single translation English.
Other languages can be released as translation mods, not a task for main maintener, imho.


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
17.06.2020 02:23
Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #19

No worries, I rewrote that file a bit) It works as advertised otherwise!
You are right of course, leave the language to others.

I hooked BG0 and BGR. BG1 should already be calling BattleQueue update... I'll post another version in a bit, not tested with extra mods ~ if someone could verify that then I can make a proper release again.

Downlaod 1.01
[+] BattleQueue updates through BG0 and BG1
[*] Text is now read through ERA from Lang/BattleQueue.json
(This post was last modified: 17.06.2020 03:13 by RoseKavalier.)
17.06.2020 03:03
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16657
Post: #20

Nice! 132 Thank you very much, tested a bit without mods, everything works (right click info, first/second player numbers, updates).
In tactics after first turn em, numbers in the right top corner change to #2, #3, then #3, #4.
https://yadi.sk/i/Exqn-lKbdk3hhw


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
17.06.2020 03:25
Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #21

I have to revise tactics rounds, thanks for reminding :D
17.06.2020 04:37
Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #22

So what's the preferred showing during tactics phase?
Rounds of tactics show correctly based on the number of turns you've spent in tactics.

I tested placing '*' instead of round number... alternatively I can just have nothing be shown.
Image: sgJX3pF.png
17.06.2020 07:12
Find all posts by this user Quote this message in a reply
daemon_n Offline
Administrators

Posts: 4343
Post: #23

RoseKavalier, is that compatible with " tactical phase fast troop selection", i mean dynamic order switch after mouse click?

And yes, i think " * " is good.


Image: widget.png?style=banner2

Новейший Heroes Launcher
17.06.2020 07:35
Visit this user's website Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #24

Yes.
During tactics phase, all enemy troops (without tactic) are removed from consideration; the initiative logic is otherwise the same.
17.06.2020 09:26
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16657
Post: #25

RoseKavalier, got it, sorry. It's round number and nothing wrong to count it in tactics, though, maybe display space ' ' instead? No round number at all.


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
17.06.2020 15:00
Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #26

Updated opening post to version 1.02.
I haven't had time to check on winXP for lag issues... problem for future me.

Quote:Arrow towers text was not showing up correctly (thanks daemon_n)
Arrow towers order was incorrect (thanks daemon_n)
Tactics turns are no longer counted, '*' is shown instead (thanks Berserker, daemon_n)
Adjusted round text position to prevent some overlap during tactics
22.06.2020 03:58
Find all posts by this user Quote this message in a reply
Berserker Offline
Administrators

Posts: 16657
Post: #27

RoseKavalier, great update, thank you!


Скачать Герои 3 Эра и всё, что с ней связано / ERA 2.46f для старых модов
Поддержать проект
22.06.2020 04:22
Find all posts by this user Quote this message in a reply
Archer30 Offline
Moderators

Posts: 1175
Post: #28

Great update RoseKavalier! Just notice now your mod shows Chinese character flawlessly. Awesome! 96-copy


Latest ERA mods and scripts in development - My GitHub
(This post was last modified: 22.06.2020 13:01 by Archer30.)
22.06.2020 12:04
Find all posts by this user Quote this message in a reply
Archer30 Offline
Moderators

Posts: 1175
Post: #29

Hi RK, a little suggestion to your mod about auto-switching language for turrets - how about reading names of turrets from ...\Data\Wall.txt? These are internal names of walls (including turrets), should match up different languages of H3.


Latest ERA mods and scripts in development - My GitHub
(This post was last modified: 09.07.2020 11:42 by Archer30.)
09.07.2020 11:27
Find all posts by this user Quote this message in a reply
RoseKavalier Offline

Posts: 118
Post: #30

Simply because the names may be too wide.
'Keep' is just fine but 'Upper Tower' and 'Lower Tower' would be cut off (or overflow on the sides if I didn't set a width limit).
09.07.2020 17:29
Find all posts by this user Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Forum Jump:

Powered by MyBB Copyright © 2002-2024 MyBB Group