Author Topic: CLONE_EFFECT... to make *two* cloned effects?  (Read 1432 times)

Offline subtledoctor

  • Planewalker
  • *****
  • Posts: 131
CLONE_EFFECT... to make *two* cloned effects?
« on: March 10, 2016, 10:35:26 AM »
I'm cloning some priest spells to be one level lower for certain kits; and to make sure that all spells and items that interact with the original spell also interact with the modified spell, I use a modified CLONE_EFFECT to add the new spell to all effects that use opcode 206, 318, 321, and 324.  Something like this:

Code: [Select]
COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
   LPF CLONE_EFFECT INT_VAR match_opcode=206 STR_VAR resource=~lowspell~ END

Now, say I want to make another clone of the spell, at a higher level, or something.  If I do this:

Code: [Select]
COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
   LPF CLONE_EFFECT INT_VAR match_opcode=206 STR_VAR resource=~lowspell~ END
   LPF CLONE_EFFECT INT_VAR match_opcode=206 STR_VAR resource=~highspell~ END
...I end up with 4 206 effects, because the macro will run once and clone the 206 effect, and then run again, find *two* 206 effects, and clone both of them.

I just want 3 206 effects: one for the original spell, and one for each new spell.  Can I run CLONE_EFFECT just once to derive two clones of the 206 effect?  Can I edit some part of the CLONE_EFFECT macro to achieve this?  (@CamDawg?)  It would be a nice way to make my code more efficient.  Right now this routine take about 60 seconds to run... which is a long time in Weidu terms (setting aside SCS).  If I could get that down to 30-40 seconds, it would be a noticeable improvement.

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: CLONE_EFFECT... to make *two* cloned effects?
« Reply #1 on: March 10, 2016, 02:06:05 PM »
If you want to make CLONE_EFFECT stop after finding a match, that feature already exists.
Quote from: Readme
INT_VAR multi_match to the number of effects to clone in the active stack. If you just want to match the first effect and have the function stop, use 1. Otherwise the function will continue matching until the number of cloned effects matches this value. The function will always make at least one change (e.g. 0 or negative values are treated as 1). (default is 999).
If you place the cloned effect after the original one, CLONE_EFFECT will also only clone the original effect on the second pass.
« Last Edit: March 10, 2016, 02:34:08 PM by Wisp »

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: CLONE_EFFECT... to make *two* cloned effects?
« Reply #2 on: March 10, 2016, 02:58:38 PM »
^^ What Wisp said, or define a match_resource so it doesn't clone every stray 206 it finds.
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline subtledoctor

  • Planewalker
  • *****
  • Posts: 131
Re: CLONE_EFFECT... to make *two* cloned effects?
« Reply #3 on: March 10, 2016, 05:14:49 PM »
Can't use multi_match, because some spells/items might have two 206 effects, in which case I want to clone them both twice and end up with six. (But not eight.)

Could match_resource take a negative? Like,

CLONE_EFFECT STR match_resource = NOT ~[some regexp]~ ...?

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: CLONE_EFFECT... to make *two* cloned effects?
« Reply #4 on: March 10, 2016, 08:00:25 PM »
Each CLONE call is an independent action; setting multi_match = 1 will not affect future calls.

Code: [Select]
COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
   LPF CLONE_EFFECT INT_VAR match_opcode=206 multi_match = 1 STR_VAR resource=~lowspell~ END
   LPF CLONE_EFFECT INT_VAR match_opcode=206 multi_match = 1 STR_VAR resource=~highspell~ END

The first CLONE runs, finds the first 206, makes one copy, and stops. The second CLONE runs, finds the first 206, makes one copy, and stops. Now you have the original 206, one for highspell, and one for lowspell. Alternatively

Code: [Select]
COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
   LPF CLONE_EFFECT INT_VAR match_opcode=206 STR_VAR resource=~lowspell~ match_resource = ~originalspell~ END
   LPF CLONE_EFFECT INT_VAR match_opcode=206 STR_VAR resource=~highspell~ match_resource = ~originalspell~ END

Now it runs, finds the existing spell protection, makes a clone for lowspell. The second one runs, ignores the new 206 for lowspell, finds the original 206, and clones it into a new 206 for highspell.

Both ways end up with the original 206, one for lowspell, and one for highspell.

If you're doing a ton of these, probably the best way would be to simply make an array of new_spell => original and then iterate through it with PHP_EACH. E.g.

Code: [Select]
ACTION_DEFINE_ASSOCIATIVE_ARRAY cd_map_newspells BEGIN
  low_aid=> sppr201
  high_aid=> sppr201
  low_ani=> sppr301
  high_ani=> sppr301
END

COPY_EXISTING_REGEXP GLOB ~.*\.spl~ ~override~
                          ~.*\.itm~ ~override~
                          ~.*\.cre~ ~override~
  PHP_EACH cd_map_newspells AS new => old BEGIN
    PATCH_FOR_EACH op IN 206 318 321 324 BEGIN
      LPF CLONE_EFFECT INT_VAR match_opcode = op STR_VAR resource = EVAL ~%new%~ match_resource = EVAL ~%old%~ END
    END
  END
  BUT_ONLY

edit: missing a BEGIN
« Last Edit: March 10, 2016, 08:01:34 PM by CamDawg »
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline subtledoctor

  • Planewalker
  • *****
  • Posts: 131
Re: CLONE_EFFECT... to make *two* cloned effects?
« Reply #5 on: March 24, 2016, 06:44:37 PM »
Yeah but if I want it to work on every spell it's not really feasible to use an array, or to use the match_resource parameter.  I suppose I could build an array, by iterating through every row in SPELL.IDS... but that still wouldn't catch mod spells that aren't ADD_SPELL'd. 

Eh, it's not worth spending too much energy on this, the mod works right now (if slightly messily) and even in its current inefficient form it still installs in like 1/20th the time that SCS takes... :)

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: