Jump to content


Photo

linking kit IDS name with weapprof column


18 replies to this topic

#1 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 21 December 2017 - 02:41 PM

I'm hitting a mental block here.  I'd like to link each kit's IDS name from kit.ids, with the kit's weapprof column number.  To do that, I need to read and parse kit.ids, giving the 0x000040xx number as input and obtaining the corresponding IDS name as output.  I'm used to arrays and .2da tables... how do you parse .ids files?

 

I'm trying to do something like this (this pseudocode parse the ids file within the PHP_EACH, but I could as well do it earlier and create an array or .2da table linking the IDS name and the weapprof column. 

COPY_EXISTING ~kitlist.2da~ ~override~
  COUNT_2DA_COLS cols
  READ_2DA_ENTRIES_NOW ~r2en_kitlist~ cols
  FOR (row = 2; row < r2en_kitlist; row += 1) BEGIN
    READ_2DA_ENTRY_FORMER ~r2en_kitlist~ row 6 prof_col
    READ_2DA_ENTRY_FORMER ~r2en_kitlist~ row 9 kitids_num
    SPRINT $d5_kits_profs(~%kitids_num%~) ~%prof_col%~
  END
 
ACTION_PHP_EACH d5_kits_profs AS idsnum => profcol BEGIN
  ACTION_IF FILE_CONTAINS_EVALUATED (~kit.ids~ ~%d5_kits_profs%~) BEGIN
(1) [parse kit.ids to find the kit name corresponding to %idsnum%, and set it to ~%idsname%~]
(2) [do some jiggery-pokery in a .BAF file with that ids name]
    OUTER_SET bastard_sword_prof = 0
    OUTER_SET long_sword_prof = 0
    OUTER_SET short_sword_prof = 0
    [etc.]
    COPY_EXISTING ~weapprof.2da~ ~override~
      COUNT_2DA_COLS cols
      READ_2DA_ENTRY 9 profcol cols bastard_sword_prof
      READ_2DA_ENTRY 10 profcol cols long_sword_prof
      READ_2DA_ENTRY 11 profcol cols short_sword_prof
      [etc.]
    BUT_ONLY
    COPY ~mod/staging_folder/script.baf~ ~mod/staging_folder/script.baf~
      PATCH_FOR_EACH var IN ~bastard_sword~ ~long_sword~ ~short_sword~ [etc] BEGIN     
        PATCH_IF (var > 0) BEGIN
          REPLACE_TEXTUALLY
~    SetGlobal("D5_%idsname%","LOCALS",1)~
~    SetGlobal("D5_%idsname%","LOCALS",1)
    SetGlobal("D5_%var%","LOCALS",%var%)~
        END
      END
  END
END

At the moment, I'm concerned with (1).  I'll get to (2) in a bit.  (And yes, for the big picture, I'm trying to put the data from weapprof.2da into a .BCS script - with a script block for each kit and a global variable for each nonzero proficiency value.)


Edited by subtledoctor, 21 December 2017 - 02:48 PM.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#2 Mike1072

Mike1072
  • Gibberling Poobah
  • 2410 posts
  • Gender:Male
  • Location:Canada

Posted 21 December 2017 - 05:32 PM

There's a slight difference between the original games and the enhanced editions. The original games match up the UNUSABLE column in kitlist.2da with the identifiers in kit.ids, while the enhanced editions match up the KITIDS column in kitlist.2da with the identifiers in kit.ids.

So, you'll need to read from column 7 of kitlist.2da for the original games and from column 9 for the enhanced editions. Here's how you'd do it on the original game.
 
COPY_EXISTING ~kitlist.2da~ ~override~
  COUNT_2DA_COLS cols
  READ_2DA_ENTRIES_NOW ~r2en_kitlist~ cols
  FOR (row = 1; row < r2en_kitlist; row += 1) BEGIN
    READ_2DA_ENTRY_FORMER ~r2en_kitlist~ row 7 kitids_num
    LOOKUP_IDS_SYMBOL_OF_INT identifier ~kit~ kitids_num
    SPRINT $d5_kits_profs(~%kitids_num%~) ~%prof_col%~
    SPRINT $d5_kits_ids(~%kitids_num%~) ~%identifier%~
  END
  BUT_ONLY
I saved the identifier in an array but you can do whatever you want with it. Note that there might not be an entry in kit.ids in the original games for WILDMAGE.

#3 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 21 December 2017 - 09:16 PM

Ah!

LOOKUP_IDS_SYMBOL_OF_INT identifier ~kit~ kitids_num

That's what I was forgetting.  Peachy keen.  (This is EE-only, so it's no problem to use the KITIDS column of kitlist.2da.)

 

Okay, on to (2). 

 

I have a .BAF script, and I need to add a script block to it for each kit.  Then later, as you can see, I'll go in and add variables for the kit's weapon proficencies.  I'm wondering what is the most efficient way to do that.  Because the end of the script calls out to a .DLG and then clears a bunch of variables, the new blocks for each kit need to be added to the top of the file.

 

The obvious method is EXTEND_TOP.  But, in my brief testing it doesn't seem to be working on an uncompiled .BAF script.  It works fine on a compiled .BCS script, but that means I'll have to DECOMPILE_AND_PATCH for every patch for every addition, of which there will be hundreds.  Seems silly.  I'd much rather craft the script as a simple text/.BAF and then compile it once at the very end.

 

I suppose I could inline the new text, and APPEND_FILE the existing script, and maybe increment a counter to put in each working file's filename... and then at the very end, rename the result to the final .BAF  name and then compile it.  But this seems clunky.

 

Is there some way to APPEND_TOP or something like that?

 

Wait, dang it - I suppose I could simple APPEND the new text into an incomplete working file, and then APPEND the bottom portion of the script at the end.  That should work fine.

 

Okay, I'm off.  Thanks!


Edited by subtledoctor, 21 December 2017 - 09:17 PM.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#4 Mike1072

Mike1072
  • Gibberling Poobah
  • 2410 posts
  • Gender:Male
  • Location:Canada

Posted 22 December 2017 - 05:21 AM

I'm not sure if I'm following exactly what you're trying to do, but there's probably a way to do it that minimizes usage of the file system, either with inlined files or variables. You can use OUTER_PATCH_SAVE/INNER_PATCH_SAVE on a variable to treat it like a file if you need to do REPLACE_TEXTUALLY or something.

#5 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 22 December 2017 - 09:55 AM

Yeah, I need to do REPLACE_TEXTUALLY ~2,000 times

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#6 CamDawg

CamDawg

    Just a simple country Hyper-Chicken

  • Gibberling Poobah
  • 9404 posts
  • Gender:Not Telling

Posted 22 December 2017 - 10:37 AM

Yeah, in that case follow Mike's suggestion--having WeiDU do a bunch of files copies will be a lot slower than using something like INNER_PATCH_SAVE.


I came here with a simple dream: a dream of killing all humans. And this is how it must end? Who's the real seven billion ton robot monster here? Not I. Not... I.


#7 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 22 December 2017 - 11:38 AM

I guess I better learn how that works then :laugh:


Edited by subtledoctor, 22 December 2017 - 11:39 AM.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#8 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6505 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 22 December 2017 - 12:22 PM

I guess I better learn how that works then :laugh:

Or you know, you could tell what exactly are you trying to do and get the help that way.
Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#9 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 22 December 2017 - 01:47 PM

A) I've used INNER_PATCH_SAVE before, but don't quite understand the concept of what it actually does. In this case I have a text file (an I compiled script in .BAF form) and I need to add a line to it a couple thousand times, inserting information derived from entries in a .2da file.

B) Big picture, the project here is to read the information in kit.ids and weapprof.2da to create a big .BCS script that has a block for each class and kit, and sets variables for the weapon proficiency limits of each kit. It will then start a dialogue that presents options to advance your proficiencies in a manner appropriate for your class, kit, and level. Voila: the proficiency system recreated in dialogue.

Then, each joinable NPC will get an innate ability that allows you to wipe out their existing proficiencies, and rebuild them from scratch however you see fit.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#10 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6505 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 22 December 2017 - 02:09 PM

Then, each joinable NPC will get an innate ability that allows you to wipe out their existing proficiencies, and rebuild them from scratch however you see fit.

Or one can use the Level 1 NPCs. The mod would appreciate an EE update that might be very much easier to do... but it's of course up to you on how to use/waste time. :D

And then there's a kit mod that adds proffpoints to all the .cre's weapon proficiencies, via an effect, and your system will bounce off the rails. 


Edited by Jarno Mikkola, 22 December 2017 - 02:12 PM.

Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#11 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 22 December 2017 - 03:42 PM

Or one can use the Level 1 NPCs.  

Ya. But 1) when I made my mod L1NPCs was not available for the EE games. It is now, partially, but my mod is still out there and still distinct and I'd still like to improve it.

2) L1NPCs still doesn't work with all the new EE NPCs or various newer mod NPCs, AFAIK.

3) There are substantive differences between the two mods. The biggest being, L1NPCs requires you to leave the game and uninstall/reinstall in Weidu if you want to change anything. My mod aims to allow changes without leaving the game or reinstalling anything. So you can play an Archer and kit out Kivan as a Stalker, or you can play a Stalker and kit out Kivan as an Archer, and you can run those games simultaneously, with two different complementary versions of Kivan, without making any changes in Weidu. That's especially useful for players using a iPad, like myself. As of the recent game patch, the iOS version is my new target platform when it comes to mod design.

And then there's a kit mod that adds proffpoints to all the .cre's weapon proficiencies, via an effect, and your system will bounce off the rails. 

No, that should work fine with the ability I'm envisioning. Unless that mod (I dunno which one you're talking about - you're pretty coy for someone who just demanded a more in-depth explanation)... unless that mod uses the new EE capacity of opcode 233 to increment proficiencies, instead of setting them. But, that part of the opcode is bugged and really shouldn't be used, so I'm not too concerned about it.

Edited by subtledoctor, 22 December 2017 - 03:44 PM.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#12 Mike1072

Mike1072
  • Gibberling Poobah
  • 2410 posts
  • Gender:Male
  • Location:Canada

Posted 22 December 2017 - 04:30 PM

A) I've used INNER_PATCH_SAVE before, but don't quite understand the concept of what it actually does. In this case I have a text file (an I compiled script in .BAF form) and I need to add a line to it a couple thousand times, inserting information derived from entries in a .2da file.


INNER_PATCH lets you perform patch operations within its scope. Patch operations are normally done in the context of the current file that you are modifying (e.g. in a COPY action). Patch statements let you do things like READ_* and WRITE_*, INSERT_BYTES, REPLACE_TEXTUALLY and REPLACE_EVALUATE.

With INNER_PATCH, instead of performing these operations on the current file, they are performed on whatever string you provide.
 

INNER_PATCH ~1234567890~ BEGIN
  READ_ASCII 0x00 numbers (5)
END

PATCH_PRINT ~%numbers%~

This READ_ASCII operation behaves as though it is dealing with a text file that has as its contents "1234567890". It reads five characters from the start of the file and stores them in a variable for use later. The PATCH_PRINT statement should print out "12345".

The difference between INNER_PATCH and INNER_PATCH_SAVE is that any changes you make to the "file" in an INNER_PATCH are completely discarded. With INNER_PATCH_SAVE, you can store those changes back into a variable.
 

INNER_PATCH_SAVE results ~1234567890~ BEGIN
  WRITE_ASCII 0x00 ~33333~ #5
END

PATCH_PRINT ~%results%~

Here, the changes we make to the "file" that originally contained "1234567890" get stored into a variable named results. The PATCH_PRINT statement should print out "3333367890".

Instead of providing the static string "1234567890" to the command, we can provide the contents of a variable.
 

READ_STRREF UNIDENTIFIED_DESC description

INNER_PATCH_SAVE new_description ~%description%~ BEGIN
  REPLACE_TEXTUALLY CASE_SENSITIVE ~armor~ ~armour~
  REPLACE_TEXTUALLY CASE_SENSITIVE ~Armor~ ~Armour~
END

SAY_EVALUATED UNIDENTIFIED_DESC ~%new_description%~

In this example, we read the unidentified description of an item or spell into a variable named description. Then, we initiate an INNER_PATCH on the contents of that variable and save the changes into a variable named new_description.

Our modifications are to change the spelling of armor wherever it appears.

Once we are done, we write our new description back to the item or spell file.

 

 

Addendum:

 

There is also OUTER_PATCH, which functions the same as INNER_PATCH.  The difference is that you use INNER_PATCH when you are already within a patch (e.g. COPYing a file), and you use OUTER_PATCH when you aren't.  It's the same as using PATCH_PRINT and PRINT.



#13 Mike1072

Mike1072
  • Gibberling Poobah
  • 2410 posts
  • Gender:Male
  • Location:Canada

Posted 22 December 2017 - 04:39 PM

So, if you wanted, you could store your template file in a variable and perform your REPLACE_TEXTUALLY statements using INNER_PATCH.

You could also use an inlined template file and COPY - statements to do REPLACE_TEXTUALLY, which should also keep everything in-memory. (Probably what I would suggest.)

As a third option, you could avoid REPLACE_TEXTUALLY and just assemble your files by concatenating variables.



#14 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 23 December 2017 - 08:09 AM

Okay, LOOKUP_SYMBOL_OF_INT is working beautifully:

 

ACTION_PHP_EACH d5_kits_profs AS kitidsname => profcol BEGIN
  PRINT ~%kitidsname% = column %profcol%~
END

 

Screen Shot 2017-12-23 at 11.02.44 AM.png


Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#15 subtledoctor

subtledoctor
  • Modders
  • 2417 posts
  • Gender:Male

Posted 23 December 2017 - 11:31 AM

Working!  I ended up not even delving into INNER_PATCH_SAVE, because it ended up only needing one COPY operation per kit, which is manageable.  It installs in about 4 seconds on my 5-year-old computer so it's quite tolerable, even though I'm sure it could be made more efficient.

 

For posterity, this begins aith a .BAF file containing this:

Spoiler

 

...and this is the .tp2:

Spoiler

 

Now on the the dialogue


Edited by subtledoctor, 23 December 2017 - 11:33 AM.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE




Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users