Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Splstates #43

Open
Grammarsalad opened this issue Feb 1, 2019 · 0 comments
Open

Adding Splstates #43

Grammarsalad opened this issue Feb 1, 2019 · 0 comments

Comments

@Grammarsalad
Copy link
Owner

Kjeron's code:

DEFINE_ACTION_FUNCTION ADD_SPLSTATE STR_VAR label = ~~ RET new_ids BEGIN
OUTER_SET new_ids = ~-1~
ACTION_IF FILE_CONTAINS_EVALUATED (~SPLSTATE.IDS~ ~^.+[ %TAB%]%label%\b~) BEGIN
  COPY_EXISTING ~SPLSTATE.IDS~ override
  COUNT_2DA_ROWS 2 rows
  FOR (i = 0; i < rows; ++i) BEGIN
      READ_2DA_ENTRY i 1 2 state_label
          PATCH_IF ~%state_label%~ STRING_EQUAL_CASE ~%label%~ BEGIN
              READ_2DA_ENTRY i 0 2 state_id
              SET new_ids = state_id
           END //state_label
  END //For Loop
  BUT_ONLY
END ELSE BEGIN
        OUTER_FOR (i = 0; i < 256; ++i) BEGIN
            OUTER_SET $occupied_spell_state(~%i%~) = 0
        END //outer_for
    ACTION_IF (~%label%~ STRING_EQUAL ~~) BEGIN FAIL ~Missing Spell State label~ END ELSE BEGIN
    ACTION_IF ((~%label%~ STRING_CONTAINS_REGEXP ~ ~) = 0) BEGIN FAIL ~Spell State label cannot have spaces~ END ELSE BEGIN
        COPY_EXISTING ~SPLSTATE.IDS~ override
            COUNT_2DA_ROWS 2 rows
            FOR (i = 0; i < rows; ++i) BEGIN
                READ_2DA_ENTRY i 0 2 state_id
                SET $occupied_spell_state(~%state_id%~) = 1
            END //for
            FOR (i = 0; i < 256; ++i) BEGIN
                PATCH_IF $occupied_spell_state(~%i%~) = 0 BEGIN
                SET new_ids = i
                SET i = 256
                    PATCH_IF new_ids <= rows BEGIN
                        INSERT_2DA_ROW new_ids 2 ~%new_ids% %label%~
                    END ELSE BEGIN
                        INSERT_2DA_ROW new_ids 2 ~%new_ids% %label%~
                    END
                 END //occupied spell state
            END //for
PATCH_IF (new_ids = ~-1~) BEGIN PATCH_FAIL ~No available Spell States~ END
BUT_ONLY
END
END
END
END //end function


LAF ADD_SPLSTATE STR_VAR label = ~CUSTOM_STATE~ RET new_ids END

@Grammarsalad Grammarsalad transferred this issue from another repository Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant