Jump to content

.tp2 coding for reading .2da files to make list.


Jarno Mikkola

Recommended Posts

Yeah, I need help in making list of the GA_ -abilities the games resources have in the *.2da files. Easy. Yeah, I wish I knew where to start really. As I need to go through all of the .2da files, custom and vanilla the kits have associated with them, and there are also the Bhall Spawn powers and so on.

This is for compatibility's sake. I don't want to use a static list as it easily fails at what I try to archive. As I'll then want to use the list for evil.

Link to comment

Is this a conceptual question or specific code is needed?

 

Personally, I'd start with parsing luabbr.2da and kitlist.2da to get a list of all custom & vanilla 2da tables that contain definitions for level up and HL abilities in-game kits has assigned to them. If I understand correctly, no matter what, every kit that exists should have its tables listed in those two files.

 

Then, there's question of parsing each and every 2da table and building a list of abilities which might be tricky yet certainly not undoable. Hence the question above.

 

Dunno about the bhaalspawn powers though, I have never studied how they work.

Link to comment

kitlist doesn't contain the trueclass clab tables, so you would have to read them include them specifically.

 

I mean, this is possible.

1) Add the trueclass clab tables to an array

2) Loop through kitlist, add every clab table to the array

3) Loop through luabbr, add every HLA table to the array

4) Now, loop through the array, checking each file for FILE_CONTAINS_REGEXP (~GA_*~ or whatever, I don't know regexp)

5) Add each found instance of the regexp to the output list

 

That output list will contain all the GA_abilities. I don't know if Weidu can strip out the GA_ from in front of them. SNPRINT can grab the beginning characters, but not the ending characters...

Link to comment

Is this a conceptual question or specific code is needed?

...

Dunno about the bhaalspawn powers though, I have never studied how they work.

Usable code...

I know this is a lot to ask for. So any other imput it also appreciated too. Also it doesn't need to be the whole code either.

 

The Bhallspawn powers are listed in the abstart.2da, they are not in a GA_* configuration, but that doesn't matter in this case, as one can add them to the start of the list (file, or what ever is used). Similar, the true class abilities are likely not going to be that much of a problem as they should be replicated in the other kits clab* files. Not that it's a full proof solution. Ouh, and yeah, I would like the list to only contain the same ability reference one time only.

Link to comment

Strings can be manipulated with the (INNER|OUTER)_PATCH_SAVE commands.

If all you want to do is extracting GA_* resources from CLAB files listed in KITLIST.2DA you can use the following code:

OUTER_TEXT_SPRINT ability_list ~~
COPY_EXISTING - ~kitlist.2da~ ~override~
COUNT_2DA_COLS kit_numCols
COUNT_2DA_ROWS kit_numCols kit_numRows
FOR (kit_row = 0; kit_row < kit_numRows; ++kit_row) BEGIN
  READ_2DA_ENTRY kit_row 5 kit_numCols clabFile
  PATCH_IF (FILE_EXISTS_IN_GAME ~%clabFile%.2da~) BEGIN
    INNER_ACTION BEGIN
      COPY_EXISTING - ~%clabFile%.2da~ ~override~
        COUNT_2DA_COLS clab_numCols
        COUNT_2DA_ROWS clab_numCols clab_numRows
        FOR (clab_row = 0; clab_row < clab_numRows; ++clab_row) BEGIN
          FOR (clab_col = 1; clab_col < clab_numCols; ++clab_col) BEGIN
            READ_2DA_ENTRY clab_row clab_col clab_numCols entry
            // processing GA_* entries...
            PATCH_IF (~%entry%~ STRING_MATCHES_REGEXP ~GA_.+~ = 0) BEGIN
              INNER_PATCH_SAVE splFile ~%entry%~ BEGIN
                REPLACE_TEXTUALLY ~GA_\(.+\)~ ~\1.SPL~
              END
              PATCH_IF (~%ability_list%~ STRING_CONTAINS_REGEXP ~%splFile%~ != 0) BEGIN
                TEXT_SPRINT ability_list ~%ability_list%%splFile%%WNL%~
              END
            END
          END
        END
    END
  END
END

PRINT ~Abilities found:~
PRINT ~%ability_list%~

The code can be easily expanded to create a second list for AP_* resources.

The LUAABR.2DA can be handled in a similar fashion. You could also outsource the inner code block into a separate function to reuse it for static files (ABSTART.2DA, or the various trueclass CLABs).

Link to comment

Thank you very much argent77 !

 

What this is all about, you ask. Well, here's the on work code for an innate spell refreshment component, that igi tried to realize in ~2006, but the weidu didn't really have the tools for that:

BACKUP ~Innates/backup~
AUTHOR ~Jarno Mikkola/The Imp @ http://www.shsforums.net/topic/.../~
//README ~ImplicitSpellAdjustments/Readme.txt~
VERSION ~v0.59 beta until~ //6.10.2016

//LANGUAGE ~English~ ~English~ ~ImplicitSpellAdjustments/Languages/English/setup.tra~

BEGIN ~Innate Spell Refreshment~
PRINT ~First we build a list of spells to patch~

OUTER_TEXT_SPRINT ability_list ~~
COPY_EXISTING - ~kitlist.2da~ ~override~
COUNT_2DA_COLS kit_numCols
COUNT_2DA_ROWS kit_numCols kit_numRows
FOR (kit_row = 0; kit_row < kit_numRows; ++kit_row) BEGIN
  READ_2DA_ENTRY kit_row 5 kit_numCols clabFile
  PATCH_IF (FILE_EXISTS_IN_GAME ~%clabFile%.2da~) BEGIN
    INNER_ACTION BEGIN
      COPY_EXISTING - ~%clabFile%.2da~ ~override~
      COUNT_2DA_COLS clab_numCols
      COUNT_2DA_ROWS clab_numCols clab_numRows
      FOR (clab_row = 0; clab_row < clab_numRows; ++clab_row) BEGIN
        FOR (clab_col = 1; clab_col < clab_numCols; ++clab_col) BEGIN
          READ_2DA_ENTRY clab_row clab_col clab_numCols entry
          // processing GA_* entries...
          PATCH_IF (~%entry%~ STRING_MATCHES_REGEXP ~GA_.+~ = 0) BEGIN
            INNER_PATCH_SAVE splFile ~%entry%~ BEGIN
              REPLACE_TEXTUALLY ~GA_\(.+\)~ ~\1~
            END
            PATCH_IF (~%ability_list%~ STRING_CONTAINS_REGEXP ~%splFile%~ != 0) BEGIN
              TEXT_SPRINT ability_list ~%ability_list%%splFile%%WNL%~
            END
          END
        END
      END
    END
  END
END

/*
COPY_EXISTING - ~abstart.2da~ ~override~        //this would be ideal but we forgo and skip the ideal for now
*/
TEXT_SPRINT ability_list ~%ability_list%
SPIN101
SPIN102
SPIN103
SPIN104
SPIN105
SPIN106~

PRINT ~Abilities found:~
PRINT ~%ability_list%~

PRINT ~Now you need to decide if you wish the spell the refresh rate to apply on successful casting only or even when you are interrupted ?
Choose:
1) Only on successful casting
2) Even when interrupted~
ACTION_READLN sucfail
OUTER_WHILE (!(IS_AN_INT %sucfail%) || (%sucfail% > 2) || (%sucfail% < 1)) BEGIN
  PRINT ~Choose:
1) Only on successful casting
2) Even when interrupted~
  ACTION_READLN sucfail
END

PRINT ~Set a refresh rate timer for all Innate spells, recommendation is to set it to be at least 900 which is 15 minutes in real time~
ACTION_READLN timer0
OUTER_WHILE !(IS_AN_INT %timer0%) BEGIN
  PRINT ~What number do you wish to set for the timer to ?~
  ACTION_READLN timer0
END

ACTION_IF (IS_AN_INT %timer0% AND %sucfail% = 1) THEN BEGIN
COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~
PATCH_IF ((SOURCE_SIZE > 0x113) AND (~%ability_list%~ STRING_CONTAINS_REGEXP ~%SOURCE_RES%~) AND (STRING_LENGTH ~%SOURCE_RES%~ > 8 )) THEN BEGIN
  READ_SHORT 0x1c "spl_type"
  PATCH_IF ("%spl_type%" = "4") THEN BEGIN
    LPF ~ADD_SPELL_EFFECT~ INT_VAR opcode = 172 target = 1 timing = 1 resist_dispel = 2 probability1 = 100 STR_VAR resource = EVAL "%SOURCE_RES%" END
    LPF ~ADD_SPELL_EFFECT~ INT_VAR opcode = 171 target = 1 timing = 4 resist_dispel = 2 duration = timer0 probability1 = 100 STR_VAR resource = EVAL "%SOURCE_RES%" END
    END
  END
BUT_ONLY

ACTION_IF (IS_AN_INT %timer0% AND %sucfail% = 2) THEN BEGIN
COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~
PATCH_IF ((SOURCE_SIZE > 0x113) AND (~%ability_list%~ STRING_CONTAINS_REGEXP ~%SOURCE_RES%~) AND (STRING_LENGTH ~%SOURCE_RES%~ > 8 )) THEN BEGIN
  READ_SHORT 0x1c "spl_type"
  PATCH_IF ("%spl_type%" = "4") THEN BEGIN
    LPF ~ADD_SPELL_CFEFFECT~ INT_VAR opcode = 172 target = 1 timing = 1 resist_dispel = 2 probability1 = 100 STR_VAR resource = EVAL "%SOURCE_RES%" END
    LPF ~ADD_SPELL_CFEFFECT~ INT_VAR opcode = 171 target = 1 timing = 4 resist_dispel = 2 duration = timer0 probability1 = 100 STR_VAR resource = EVAL "%SOURCE_RES%" END
    END
  END
BUT_ONLY

PRINT ~Success.~

EDIT: code. :p

Link to comment

I have a further question. Is there any reason to NOT include an empty line in the "ability_list" list variable ? Aka is there a (known) possibility of it breaking something ?

The game is unlikely going to have a ".spl" innate spell, but I ask just to be sure. I can avoid it, so it's not a real big deal... but I ask, just in case.

Link to comment

(~%ability_list%~ STRING_CONTAINS_REGEXP ~%SOURCE_RES%~)

Since this checks for the SOURCE_RES (e.g. file name without extension), you're not risking anything at all.

 

The more likely source of issue is that such code would also return true for SPIN1.SPL if you have SPIN101 in your list.

Can be proofed against by building an array, rather than simply appending with text. E.g. use

SET $ability_list("%splFile%") = 1 // does it need manual EVAL?.. i forgot 

instead of

PATCH_IF (~%ability_list%~ STRING_CONTAINS_REGEXP ~%splFile%~ != 0) BEGIN
  TEXT_SPRINT ability_list ~%ability_list%%splFile%%WNL%~
END

Then, add SPIN10* via

SET $ability_list("spin101") = 1
SET $ability_list("spin102") = 1
SET $ability_list("spin103") = 1
SET $ability_list("spin104") = 1
SET $ability_list("spin105") = 1
SET $ability_list("spin106") = 1

And finally load the list with ACTION_PHP_EACH

ACTION_PHP_EACH ability_list AS ability => unused_param BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%ability%.spl~ BEGIN
    COPY_EXISTING ~%ability%.spl~ override
      READ_SHORT 0x1c "spl_type"
      PATCH_IF ("%spl_type%" = "4") THEN BEGIN
        LPF ~ADD_SPELL_EFFECT~ INT_VAR opcode = 172 target = 1 timing = 1 resist_dispel = 2 probability1 = 100 STR_VAR resource = EVAL "%ability%" END
        LPF ~ADD_SPELL_EFFECT~ INT_VAR opcode = 171 target = 1 timing = 4 resist_dispel = 2 duration = timer0 probability1 = 100 STR_VAR resource = EVAL "%ability%" END
     END
    BUT_ONLY
  END
END

No guarantee it actually works as claimed, I obviously didn't run it locally to test.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...