Update strings.uc

Update strings.uc

Casing for string equates

# strings.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.95 on 3/19/2014 12:58:24 PM
# Comment: Converts string-related code from PowerBASIC to C++

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Converts string-related code from PowerBASIC to C++
Selected: False
Highlight: True
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
FilterTally: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
InputFile:
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Find: {@Start}
Replace: #include <algorithm>
         #include <string>
         #include "pbstrings.h"
         using namespace std;{nl}{nl}

Criteria: 2
SkipOver: True
Find: ' {Comment:".*"}
Replace: [Skip over]

Criteria: 3
Find: String
Replace: string

Criteria: 4
Selected: True
Find: WString
Replace: wstring

Criteria: 5
BackColor: DodgerBlue
PassOnce: False
Find: InStr([{n=1},] {MainStr}, {MatchStr})
Replace: PB_INSTR({n}, {MainStr}, {MatchStr})

Criteria: 6
BackColor: Tomato
PassOnce: False
Find: InStr([{n=1},] {MainStr}, Any {MatchStr})
Replace: PB_INSTR_ANY({n}, {MainStr}, {MatchStr})

Criteria: 7
BackColor: Red
PassOnce: False
Find: Left$({Str}, {n})
Replace: PB_LEFT({Str}, {n})

Criteria: 8
BackColor: Brown
PassOnce: False
Find: Right$({Str}, {n})
Replace: PB_RIGHT({Str}, {n})

Criteria: 9
BackColor: Orange
PassOnce: False
Find: Mid$({Str}, {Start} [, {Length=FULL_STRING}])
Replace: PB_MID({Str}, {Start}, {Length})

Criteria: 10
BackColor: DeepSkyBlue
PassOnce: False
Find: {Sep: {nl} | : | Then | Else }
      Mid$({Str}, {Start} [, {Length=FULL_STRING}]) = {Txt%}
Replace: {Sep} PB_MID_REPLACE({Str}, {Txt}, {Start}, {Length})

Criteria: 11
BackColor: RoyalBlue
PassOnce: False
Find: Val({Str})
Replace: stold({Str})

Criteria: 12
BackColor: Pink
PassOnce: False
Find: Str$({Number})
Replace: to_string((long double){Number})

Criteria: 13
Find: Space$({count})
Replace: string({count}, _char( ))

Criteria: 14
Find: String$({count}, {char})
Replace: string({count}, {char})

Criteria: 15
BackColor: Violet
Find: String$({count}, {q}{char}{q})
Replace: string({count}, _char({char}))

Criteria: 16
Find: UCase$({text})
Replace: PB_UCASE({text})

Criteria: 17
BackColor: YellowGreen
Find: LCase$({text})
Replace: PB_LCASE({text})

Criteria: 18
Find: Trim$({Str} [, ANY {chars=" "}])
Replace: PB_TRIM_ANY({Str}, {chars})

Criteria: 19
BackColor: Gold
Find: LTrim$({Str} [, ANY {chars=" "}])
Replace: PB_LTRIM_ANY({Str}, {chars})

Criteria: 20
BackColor: Silver
Find: RTrim$({Str} [, ANY {chars=" "}])
Replace: PB_RTRIM_ANY({Str}, {chars})

Criteria: 21
Find: Extract$([{start=1},] {MainStr}, {MatchStr})
Replace: PB_EXTRACT({start}, {MainStr}, {MatchStr})

Criteria: 22
Find: Extract$([{start=1},] {MainStr}, Any {MatchStr})
Replace: PB_EXTRACT_ANY({start}, {MainStr}, {MatchStr})

Criteria: 23
Find: Remain$([{start=1},] {MainStr}, {MatchStr})
Replace: PB_REMAIN({start}, {MainStr}, {MatchStr})

Criteria: 24
Find: Remain$([{start=1},] {MainStr}, Any {MatchStr})
Replace: PB_REMAIN_ANY({start}, {MainStr}, {MatchStr})

Criteria: 25
Find: Remove$({Str}, {MatchStr})
Replace: PB_REMOVE({Str}, {MatchStr})

Criteria: 26
Find: Remove$({Str}, Any {MatchStr})
Replace: PB_REMOVE_ANY({Str}, {MatchStr})

Criteria: 27
Find: Replace {MatchStr} With {NewStr} In {MainStr}
Replace: PB_REPLACE({MainStr}, {MatchStr}, {NewStr})

Criteria: 28
Find: Replace Any {MatchStr} With {NewStr} In {MainStr}
Replace: PB_REPLACE_ANY({MainStr}, {MatchStr}, {NewStr})

Criteria: 29
Find: Repeat$({count}, {Str})
Replace: PB_REPEAT({Str}, {count})

Criteria: 30
Find: Asc({Str}[, {pos=1}])
Replace: PB_ASC({Str}, {pos})

Criteria: 31
Find: ${equate: NUL|BEL|BS|TAB|LF|VT|FF|CR|CRLF|EOF|ESC|SPC|DQ|SQ|QCQ }
Replace: PB_{@Eval: UCase("{equate}", "{'.*'}")}

# End Search

# strings.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.5 on 2/28/2014 8:27:30 AM
# Comment: Converts string-related code from PowerBASIC to C++

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Converts string-related code from PowerBASIC to C++
Selected: False
Highlight: True
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
SkipOver: True
Find: ' {Comment:".*"}
Replace: [Skip over]

Criteria: 2
Find: String
Replace: string

Criteria: 3
Find: WString
Replace: wstring

Criteria: 4
Find: {@Start}
Replace: #include <algorithm>
         #include <string>
         #include "pbstrings.h"
         using namespace std;{nl}{nl}

Criteria: 5
BackColor: DodgerBlue
PassOnce: False
Find: InStr([{n=1},] {MainStr}, {MatchStr})
Replace: PB_INSTR({n}, {MainStr}, {MatchStr})

Criteria: 6
BackColor: Tomato
PassOnce: False
Find: InStr([{n=1},] {MainStr}, Any {MatchStr})
Replace: PB_INSTR_ANY({n}, {MainStr}, {MatchStr})

Criteria: 7
BackColor: Red
PassOnce: False
Find: Left$({Str}, {n})
Replace: PB_LEFT({Str}, {n})

Criteria: 8
BackColor: Brown
PassOnce: False
Find: Right$({Str}, {n})
Replace: PB_RIGHT({Str}, {n})

Criteria: 9
BackColor: Orange
PassOnce: False
Find: Mid$({Str}, {Start} [, {Length=FULL_STRING}])
Replace: PB_MID({Str}, {Start}, {Length})

Criteria: 10
BackColor: DeepSkyBlue
PassOnce: False
Find: {Sep: {nl} | : | Then | Else }
      Mid$({Str}, {Start} [, {Length=FULL_STRING}]) = {Txt%}
Replace: {Sep} PB_MID_REPLACE({Str}, {Txt}, {Start}, {Length})

Criteria: 11
BackColor: RoyalBlue
PassOnce: False
Find: Val({Str})
Replace: stold({Str})

Criteria: 12
BackColor: Pink
PassOnce: False
Find: Str$({Number})
Replace: to_string((long double){Number})

Criteria: 13
Find: Space$({count})
Replace: string({count}, _char( ))

Criteria: 14
Find: String$({count}, {char})
Replace: string({count}, {char})

Criteria: 15
BackColor: Violet
Find: String$({count}, {q}{char}{q})
Replace: string({count}, _char({char}))

Criteria: 16
Find: UCase$({text})
Replace: PB_UCASE({text})

Criteria: 17
BackColor: YellowGreen
Find: LCase$({text})
Replace: PB_LCASE({text})

Criteria: 18
Find: Trim$({Str} [, ANY {chars=" "}])
Replace: PB_TRIM_ANY({Str}, {chars})

Criteria: 19
BackColor: Gold
Find: LTrim$({Str} [, ANY {chars=" "}])
Replace: PB_LTRIM_ANY({Str}, {chars})

Criteria: 20
BackColor: Silver
Find: RTrim$({Str} [, ANY {chars=" "}])
Replace: PB_RTRIM_ANY({Str}, {chars})

Criteria: 21
Find: Extract$([{start=1},] {MainStr}, {MatchStr})
Replace: PB_EXTRACT({start}, {MainStr}, {MatchStr})

Criteria: 22
Find: Extract$([{start=1},] {MainStr}, Any {MatchStr})
Replace: PB_EXTRACT_ANY({start}, {MainStr}, {MatchStr})

Criteria: 23
Find: Remain$([{start=1},] {MainStr}, {MatchStr})
Replace: PB_REMAIN({start}, {MainStr}, {MatchStr})

Criteria: 24
Find: Remain$([{start=1},] {MainStr}, Any {MatchStr})
Replace: PB_REMAIN_ANY({start}, {MainStr}, {MatchStr})

Criteria: 25
Find: Remove$({Str}, {MatchStr})
Replace: PB_REMOVE({Str}, {MatchStr})

Criteria: 26
Find: Remove$({Str}, Any {MatchStr})
Replace: PB_REMOVE_ANY({Str}, {MatchStr})

Criteria: 27
Find: Replace {MatchStr} With {NewStr} In {MainStr}
Replace: PB_REPLACE({MainStr}, {MatchStr}, {NewStr})

Criteria: 28
Find: Replace Any {MatchStr} With {NewStr} In {MainStr}
Replace: PB_REPLACE_ANY({MainStr}, {MatchStr}, {NewStr})

Criteria: 29
Find: Repeat$({count}, {Str})
Replace: PB_REPEAT({Str}, {count})

Criteria: 30
Find: Asc({Str}[, {pos=1}])
Replace: PB_ASC({Str}, {pos})

Criteria: 31
Selected: True
Find: ${e: NUL|BEL|BS|TAB|LF|VT|FF|CR|CRLF|EOF|ESC|SPC|DQ|SQ|QCQ }
Replace: PB_{e}

# End Search


Delete pb-to-cpp.uc

Delete pb-to-cpp.uc

# pb-to-cpp.uc - uCalc Transformation file
# This file was saved with uCalc Transform 1.8 on 9/10/2013 8:50:47 PM
# Comment: Converts PB source code to C++; modified by Daniel Corbier

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterStartText, FilterUnique

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Converts PB source code to C++; modified by Daniel Corbier
Selected: False
Highlight: True
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterStartText:
FilterUnique: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Selected: True
BackColor: DarkKhaki
Find: Function {name} ([{args%}]) As {type%}{nl}
         {code%+}
      End Function
Replace: {type} {name}({args}) {
            {code}
         }

Criteria: 2
BackColor: Green
Find: If {cond} Then {statement%}{nl}
Replace: if ({cond}) { {statement} }{nl}

Criteria: 3
Find: If {cond} Then {nl}
         {code%+}
      End If
Replace: if ({cond}) {
            {code}
         }

Criteria: 4
Find: For {x} = {start} To {stop} [Step {inc=1}]{nl}
         {code%+}
      Next
Replace: for ({x}={start}; {x}{@Eval: IIF(sgn({inc})>0, '<', '>')}={stop}; x += {inc}) {
            {code}
         }

Criteria: 5
BackColor: Orange
Find: Dim {var} As {type%}
Replace: {type} {var};

Criteria: 6
BackColor: SandyBrown
PassOnce: False
Find: Dim {var1}, {more}
Replace: Dim {var1}
         Dim {more}

Criteria: 7
BackColor: DeepSkyBlue
Find: Function = {value}
Replace: return {value};

Criteria: 8
BackColor: Lime
Find: Long
Replace: long

Criteria: 9
BackColor: Red
Find: Single
Replace: float

Criteria: 10
BackColor: SlateBlue
Find: ByRef {arg} As {type%:1}
Replace: {type}& {arg}

Criteria: 11
BackColor: Pink
Find: ByVal {arg} As {type%:1}
Replace: {type} {arg}

# End Search


Update pb-to-cpp.uc

Update pb-to-cpp.uc

Exit Sub

# pb-to-cpp.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.0 on 1/1/2014 6:11:22 PM
# Comment: Converts PB source code to C++; modified by Daniel Corbier

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Converts PB source code to C++; modified by Daniel Corbier
Selected: False
Highlight: True
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Find:
Replace: {@Define:
            Var: Array As String
            Var: ArrayNames As Table
            Var: CleanUp As String
            Var: BitType As String
         }

Criteria: 2
Comment: Handles long line break (underscore _)
Pass: 1

Criteria: 3
PassOnce: False
Find: {nl}{line} _ [{comment:".*"}] {nl}

Replace: {comment: ' {comment}{nl}}{nl}{line}{sp}

Criteria: 4
SkipOver: True
Find: {"[\(\)]"} {@Note: These are ( and ); must be skipped}
Replace: [Skip over]

Criteria: 5
SkipOver: True
Find: ' {comment:".*"}
Replace: [Skip over]

Criteria: 6
Comment: Processes some operators
Pass: 2

Criteria: 7
Comment: Bitwise AND and OR
Find: ({expr%})
Replace: ({@Eval: Replace(Replace(Replace('{expr}', "And", "&"), "Or", "|"), "=", "==")})

Criteria: 8
Comment: Logical (short-circuit) AND
Find: And
Replace: &&

Criteria: 9
Comment: Logical (short-circuit) OR
Find: Or
Replace: ||

Criteria: 10
Find: Xor
Replace: ^

Criteria: 11
Find: Not
Replace: ~

Criteria: 12
Find: IsFalse
Replace: !

Criteria: 13
Find: <>
Replace: !=

Criteria: 14
Find: =
Replace: ==

Criteria: 15
SkipOver: True
Find: { {nl}[%]|Then|Else|For|: } {var:" *[a-z\@\.]+"}[({index})] =
Replace: [Skip over]

Criteria: 16
SkipOver: True
Find: { { #If | #ElseIf } Not | ' {comment:".*"} }
Replace: [Skip over]

Criteria: 17
Comment:
Pass: 3

Criteria: 18
SkipOver: True
Find: // {comment~}
Replace: [Skip over]

Criteria: 19
Find: ' {comment~}
Replace: // {comment}

Criteria: 20
BackColor: Green
PassOnce: False
Find: {nl}%{equate} = {value}
Replace: {nl}const int {equate} = {value};

Criteria: 21
BackColor: Green
Find: %{equate}
Replace: {equate}

Criteria: 22
BackColor: SandyBrown
Find: {"&h"}
Replace: 0x

Criteria: 23
BackColor: Green
PassOnce: False
Find: If {cond} Then {statement} [Else {else}]{nl}
Replace: if ({cond}) { {statement} }{else: else {{else}}}{nl}

Criteria: 24
PassOnce: False
Find: If {cond} Then {nl}
         {code+}
      End If
Replace: if ({cond}) {
            {code}
         }

Criteria: 25
BackColor: DarkKhaki
PassOnce: False
Find: Function {name} ([{args}]) As {type}{nl}
         {code+}
      End Function
Replace: {type} {name}({args}) {
            {code}
         !!ReleaseDynamicArrays!!}

Criteria: 26
PassOnce: False
Find: Sub {name} ([{args}]){nl}
         {code+}
      End Sub
Replace: void {name}({args}) {
            {code}
         !!ReleaseDynamicArrays!!}

Criteria: 27
PassOnce: False
Find: For {x} = {start} To {stop} [Step {inc=1}]{nl}
         {code+}
      Next
Replace: for ({x}={start}; {x}{@Eval: IIF(sgn({inc})>0, '<', '>')}={stop}; {x} += {inc}) {
            {code}
         }

Criteria: 28
PassOnce: False
Find: While {cond} {nl}
         {code+}
      Wend
Replace: while ({cond}) {
            {code}
         }

Criteria: 29
Find: !!ReleaseDynamicArrays!!
Replace: {@Eval:
            CleanUp = ""
            uc_For(x, 1, Count(ArrayNames), 1,
               Array = ReadKey(ArrayNames, x)
               CleanUp=CleanUp+"delete[] "+Array+";{nl}"
               Delete(ArrayNames, Array)
            )
            CleanUp
         }

Criteria: 30
BackColor: Orange
PassOnce: False
Find: { Dim | {member: {nl}}} {var:1} As {type} [{ptr: Ptr}]
Replace: {member: {nl}}{type} {ptr:*}{var};

Criteria: 31
PassOnce: False
Find: {nl} {bitfield:1} As Bit * {size} [{in: In {type}}]
Replace: {nl}{@Eval:
            IIf("{type}" <> "", SetVar(BitType, "{type}"))
            BitType
         } {bitfield} : {size};

Criteria: 32
PassOnce: False
Find: Dim {array}({subscript}) As {type}
Replace: {type} *{array} = new {type} [{subscript}+1];{@Eval:
            Insert(ArrayNames, "{array}")
         }{@Define:: Syntax: {array}({index}) ::= {array}[{index}]}

Criteria: 33
BackColor: SandyBrown
PassOnce: False
Find: Dim {var1}, {more}
Replace: Dim {var1}
         Dim {more}

Criteria: 34
BackColor: Gold
PassOnce: False
Find: { Local | Global | Register }
Replace: Dim

Criteria: 35
Find: @
Replace: *

Criteria: 36
BackColor: Silver
Find: VarPtr({var})
Replace: &{var}

Criteria: 37
BackColor: DeepSkyBlue
PassOnce: False
Find: Function = {value}
Replace: return {value};

Criteria: 38
Selected: True
Find: Exit Sub
Replace: return;

Criteria: 39
BackColor: Lime
Find: Long
Replace: long

Criteria: 40
BackColor: Red
Find: Single
Replace: float

Criteria: 41
Find: Double
Replace: double

Criteria: 42
Find: Byte
Replace: unsigned char

Criteria: 43
Find: Integer
Replace: short

Criteria: 44
Find: Word
Replace: unsigned short

Criteria: 45
Find: Dword
Replace: unsigned long

Criteria: 46
BackColor: SlateBlue
PassOnce: False
Find: ByRef {arg} As {type:1}
Replace: {type}& {arg}

Criteria: 47
BackColor: Pink
PassOnce: False
Find: ByVal {arg} As {type:1} [{ptr: Ptr}]
Replace: {type} {ptr:*}{arg}

Criteria: 48
PassOnce: False
Find: Type {name:1}
         {members+}
      End Type
Replace: struct {name} {
            {members}
         }

Criteria: 49
Find: #If
Replace: #if

Criteria: 50
Find: #Else
Replace: #else

Criteria: 51
Find: #ElseIf
Replace: #elif

Criteria: 52
Find: #EndIf
Replace: #endif

Criteria: 53
PassOnce: False
Find: [{NOT: Not }] %Def({const})
Replace: {NOT:!}defined {const}

Criteria: 54
Comment: Adds semi-colons to statements
Pass: 4

Criteria: 55
SkipOver: True
Find: { "{" | "}" | ; | //{".*"} | #{".*"} } {nl} [{"[ \n]+"}]
Replace: [Skip over]

Criteria: 56
Comment: Skips over so that colons in bit fields are not affected
SkipOver: True
Find: struct {name:1} "{" {members+} "}"
Replace: [Skip over]

Criteria: 57
Find: :
Replace: ;

Criteria: 58
PassOnce: False
Find: {nl}
Replace: ;{nl}

# End Search

# pb-to-cpp.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.0 on 12/27/2013 3:49:26 PM
# Comment: Converts PB source code to C++; modified by Daniel Corbier

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Converts PB source code to C++; modified by Daniel Corbier
Selected: False
Highlight: True
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Find:
Replace: {@Define:
            Var: Array As String
            Var: ArrayNames As Table
            Var: CleanUp As String
            Var: BitType As String
         }

Criteria: 2
Comment: Handles long line break (underscore _)
Pass: 1

Criteria: 3
PassOnce: False
Find: {nl}{line} _ [{comment:".*"}] {nl}

Replace: {comment: ' {comment}{nl}}{nl}{line}{sp}

Criteria: 4
SkipOver: True
Find: {"[\(\)]"} {@Note: These are ( and ); must be skipped}
Replace: [Skip over]

Criteria: 5
SkipOver: True
Find: ' {comment:".*"}
Replace: [Skip over]

Criteria: 6
Comment: Processes some operators
Pass: 2

Criteria: 7
Comment: Bitwise AND and OR
Selected: True
Find: ({expr%})
Replace: ({@Eval: Replace(Replace(Replace('{expr}', "And", "&"), "Or", "|"), "=", "==")})

Criteria: 8
Comment: Logical (short-circuit) AND
Find: And
Replace: &&

Criteria: 9
Comment: Logical (short-circuit) OR
Find: Or
Replace: ||

Criteria: 10
Find: Xor
Replace: ^

Criteria: 11
Find: Not
Replace: ~

Criteria: 12
Find: IsFalse
Replace: !

Criteria: 13
Find: <>
Replace: !=

Criteria: 14
Find: =
Replace: ==

Criteria: 15
SkipOver: True
Find: { {nl}[%]|Then|Else|For|: } {var:" *[a-z\@\.]+"}[({index})] =
Replace: [Skip over]

Criteria: 16
SkipOver: True
Find: { { #If | #ElseIf } Not | ' {comment:".*"} }
Replace: [Skip over]

Criteria: 17
Comment:
Pass: 3

Criteria: 18
SkipOver: True
Find: // {comment~}
Replace: [Skip over]

Criteria: 19
Find: ' {comment~}
Replace: // {comment}

Criteria: 20
BackColor: Green
PassOnce: False
Find: {nl}%{equate} = {value}
Replace: {nl}const int {equate} = {value};

Criteria: 21
BackColor: Green
Find: %{equate}
Replace: {equate}

Criteria: 22
BackColor: SandyBrown
Find: {"&h"}
Replace: 0x

Criteria: 23
BackColor: Green
PassOnce: False
Find: If {cond} Then {statement} [Else {else}]{nl}
Replace: if ({cond}) { {statement} }{else: else {{else}}}{nl}

Criteria: 24
PassOnce: False
Find: If {cond} Then {nl}
         {code+}
      End If
Replace: if ({cond}) {
            {code}
         }

Criteria: 25
BackColor: DarkKhaki
PassOnce: False
Find: Function {name} ([{args}]) As {type}{nl}
         {code+}
      End Function
Replace: {type} {name}({args}) {
            {code}
         !!ReleaseDynamicArrays!!}

Criteria: 26
PassOnce: False
Find: Sub {name} ([{args}]){nl}
         {code+}
      End Sub
Replace: void {name}({args}) {
            {code}
         !!ReleaseDynamicArrays!!}

Criteria: 27
PassOnce: False
Find: For {x} = {start} To {stop} [Step {inc=1}]{nl}
         {code+}
      Next
Replace: for ({x}={start}; {x}{@Eval: IIF(sgn({inc})>0, '<', '>')}={stop}; {x} += {inc}) {
            {code}
         }

Criteria: 28
PassOnce: False
Find: While {cond} {nl}
         {code+}
      Wend
Replace: while ({cond}) {
            {code}
         }

Criteria: 29
Find: !!ReleaseDynamicArrays!!
Replace: {@Eval:
            CleanUp = ""
            uc_For(x, 1, Count(ArrayNames), 1,
               Array = ReadKey(ArrayNames, x)
               CleanUp=CleanUp+"delete[] "+Array+";{nl}"
               Delete(ArrayNames, Array)
            )
            CleanUp
         }

Criteria: 30
BackColor: Orange
PassOnce: False
Find: { Dim | {member: {nl}}} {var:1} As {type} [{ptr: Ptr}]
Replace: {member: {nl}}{type} {ptr:*}{var};

Criteria: 31
PassOnce: False
Find: {nl} {bitfield:1} As Bit * {size} [{in: In {type}}]
Replace: {nl}{@Eval:
            IIf("{type}" <> "", SetVar(BitType, "{type}"))
            BitType
         } {bitfield} : {size};

Criteria: 32
PassOnce: False
Find: Dim {array}({subscript}) As {type}
Replace: {type} *{array} = new {type} [{subscript}+1];{@Eval:
            Insert(ArrayNames, "{array}")
         }{@Define:: Syntax: {array}({index}) ::= {array}[{index}]}

Criteria: 33
BackColor: SandyBrown
PassOnce: False
Find: Dim {var1}, {more}
Replace: Dim {var1}
         Dim {more}

Criteria: 34
BackColor: Gold
PassOnce: False
Find: { Local | Global | Register }
Replace: Dim

Criteria: 35
Find: @
Replace: *

Criteria: 36
BackColor: Silver
Find: VarPtr({var})
Replace: &{var}

Criteria: 37
BackColor: DeepSkyBlue
PassOnce: False
Find: Function = {value}
Replace: return {value};

Criteria: 38
BackColor: Lime
Find: Long
Replace: long

Criteria: 39
BackColor: Red
Find: Single
Replace: float

Criteria: 40
Find: Double
Replace: double

Criteria: 41
Find: Byte
Replace: unsigned char

Criteria: 42
Find: Integer
Replace: short

Criteria: 43
Find: Word
Replace: unsigned short

Criteria: 44
Find: Dword
Replace: unsigned long

Criteria: 45
BackColor: SlateBlue
PassOnce: False
Find: ByRef {arg} As {type:1}
Replace: {type}& {arg}

Criteria: 46
BackColor: Pink
PassOnce: False
Find: ByVal {arg} As {type:1} [{ptr: Ptr}]
Replace: {type} {ptr:*}{arg}

Criteria: 47
PassOnce: False
Find: Type {name:1}
         {members+}
      End Type
Replace: struct {name} {
            {members}
         }

Criteria: 48
Find: #If
Replace: #if

Criteria: 49
Find: #Else
Replace: #else

Criteria: 50
Find: #ElseIf
Replace: #elif

Criteria: 51
Find: #EndIf
Replace: #endif

Criteria: 52
PassOnce: False
Find: [{NOT: Not }] %Def({const})
Replace: {NOT:!}defined {const}

Criteria: 53
Comment: Adds semi-colons to statements
Pass: 4

Criteria: 54
SkipOver: True
Find: { "{" | "}" | ; | //{".*"} | #{".*"} } {nl} [{"[ \n]+"}]
Replace: [Skip over]

Criteria: 55
Comment: Skips over so that colons in bit fields are not affected
SkipOver: True
Find: struct {name:1} "{" {members+} "}"
Replace: [Skip over]

Criteria: 56
Find: :
Replace: ;

Criteria: 57
PassOnce: False
Find: {nl}
Replace: ;{nl}

# End Search


Removed protectedwrite from Loadouts

Removed protectedwrite from Loadouts

//---------------------------------------------------------------------------------------
//  FILE:    X2ItemTemplateManager.uc
//  AUTHOR:  Joshua Bouscher
//
//---------------------------------------------------------------------------------------
//  Copyright (c) 2016 Firaxis Games, Inc. All rights reserved.
//---------------------------------------------------------------------------------------

class X2ItemTemplateManager extends X2DataTemplateManager
	native(Core) config(GameData);

var config array<name>       ItemCategories;
var config array<name>       UniqueEquipCategories;      //  should be a subset of ItemCategories
var config array<name>       WeaponCategories;
var config array<name>       WeaponTechCategories;
var config array<name>       ArmorTechCategories;

var config array<name>      BuildItemWeaponCategories;
var config array<name>      BuildItemArmorCategories;
var config array<name>      BuildItemMiscCategories;

var config int				MaxTechDistanceForValidDrop;  // number of techs "away" from being useable an item can be for it to be eligible to drop (schematics)
// Start Issue #698
var config array<InventoryLoadout>  Loadouts;
// End Issue #698
var protectedwrite config array<StatBoostDefinition> StatBoostTable;
var protectedwrite config array<TX2MPSoldierItemDefinition> MPAvailableSoldierItems; // the list of items that are available for MP soldier to equip. -tsmith

var protectedwrite X2LootTableManager  LootTableManager;

native static function X2ItemTemplateManager GetItemTemplateManager();

cpptext
{
public:
	virtual void GetDynamicListValues(const FString& ListName, TArray<FString>& Values);
}

protected event ValidateTemplatesEvent()
{
	local int i;
	local X2ItemTemplate kItemTemplate;

	super.ValidateTemplatesEvent();

	LootTableManager = new class'X2LootTableManager';
	LootTableManager.InitLootTables();

	for(i = 0; i < MPAvailableSoldierItems.Length; i++)
	{
		kItemTemplate = FindItemTemplate(MPAvailableSoldierItems[i].ItemTemplateName);
		if(kItemTemplate != none)
		{
			kItemTemplate.MPCost = MPAvailableSoldierItems[i].ItemCost;
		}
	}
}

function bool AddItemTemplate(X2ItemTemplate Template, bool ReplaceDuplicate = false)
{
	return AddDataTemplate(Template, ReplaceDuplicate);
}

function X2DamageTypeTemplate FindDamageTypeTemplate(name DataName)
{
	local X2DataTemplate kTemplate;

	kTemplate = FindDataTemplate(DataName);
	if(kTemplate != none)
		return X2DamageTypeTemplate(kTemplate);
	return none;
}

function X2ItemTemplate FindItemTemplate(name DataName)
{
	local X2DataTemplate kTemplate;

	kTemplate = FindDataTemplate(DataName);
	if (kTemplate != none)
		return X2ItemTemplate(kTemplate);
	return none;
}

function TX2MPSoldierItemDefinition FindMPSoldierItemDefinition(name ItemTemplateName)
{
	local TX2MPSoldierItemDefinition ItemDef;
	local int i;

	for(i = 0; i < MPAvailableSoldierItems.Length; i++)
	{
		if(MPAvailableSoldierItems[i].ItemTemplateName == ItemTemplateName)
		{
			ItemDef = MPAvailableSoldierItems[i];
			break;
		}
	}

	return ItemDef;
}

function array<X2WeaponTemplate> GetAllWeaponTemplates()
{
	local array<X2WeaponTemplate> arrWeaponTemplates;
	local X2DataTemplate Template;
	local X2WeaponTemplate WeaponTemplate;

	foreach IterateTemplates(Template, none)
	{
		WeaponTemplate = X2WeaponTemplate(Template);

		if(WeaponTemplate != none)
		{
			arrWeaponTemplates.AddItem(WeaponTemplate);
		}
	}

	return arrWeaponTemplates;
}

function array<X2EquipmentTemplate> GetAllArmorTemplates()
{
	local array<X2EquipmentTemplate> arrArmorTemplates;
	local X2DataTemplate Template;
	local X2EquipmentTemplate ArmorTemplate;

	foreach IterateTemplates(Template, none)
	{
		ArmorTemplate = X2ArmorTemplate(Template);

		if(ArmorTemplate != none)
		{
			arrArmorTemplates.AddItem(ArmorTemplate);
		}
	}

	return arrArmorTemplates;
}

function array<X2WeaponUpgradeTemplate> GetAllUpgradeTemplates()
{
	local array<X2WeaponUpgradeTemplate> arrUpgradeTemplates;
	local X2DataTemplate Template;
	local X2WeaponUpgradeTemplate UpgradeTemplate;

	foreach IterateTemplates(Template, none)
	{
		UpgradeTemplate = X2WeaponUpgradeTemplate(Template);

		if(UpgradeTemplate != none)
		{
			arrUpgradeTemplates.AddItem(UpgradeTemplate);
		}
	}

	return arrUpgradeTemplates;
}

function array<X2SchematicTemplate> GetAllSchematicTemplates()
{
	local array<X2SchematicTemplate> arrSchematicTemplates;
	local X2DataTemplate Template;
	local X2SchematicTemplate SchematicTemplate;

	foreach IterateTemplates(Template, none)
	{
		SchematicTemplate = X2SchematicTemplate(Template);

		if(SchematicTemplate != none)
		{
			arrSchematicTemplates.AddItem(SchematicTemplate);
		}
	}

	return arrSchematicTemplates;
}

function array<X2ItemTemplate> GetAllItemsCreatedByTemplate(name TemplateName)
{
	local array<X2ItemTemplate> arrItemTemplates;
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if (ItemTemplate != none && ItemTemplate.CreatorTemplateName == TemplateName)
		{
			arrItemTemplates.AddItem(ItemTemplate);
		}
	}

	return arrItemTemplates;
}

// This uses the *mostly* deprecated UpgradeItem variable, mainly existing for backwards compatibility with Day 0 DLC
function array<X2ItemTemplate> GetAllBaseItemTemplatesFromUpgrade(name UpgradeTemplateName)
{
	local array<X2ItemTemplate> arrItemTemplates;
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if (ItemTemplate != none && ItemTemplate.UpgradeItem == UpgradeTemplateName)
		{
			arrItemTemplates.AddItem(ItemTemplate);
		}
	}

	return arrItemTemplates;
}

// Every upgraded item should have only one base
function X2ItemTemplate GetUpgradedItemTemplateFromBase(name BaseTemplateName)
{
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if (ItemTemplate != none && ItemTemplate.BaseItem == BaseTemplateName)
		{
			return ItemTemplate;
		}
	}

	return none;
}

function array<X2ItemTemplate> GetBuildableItemTemplates()
{
	local array<X2ItemTemplate> arrBuildTemplates;
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;
	local XComGameState_HeadquartersXCom XComHQ;
	local XComGameStateHistory History;

	History = `XCOMHISTORY;
	XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if(ItemTemplate != none)
		{
			if(ItemTemplate.CanBeBuilt &&
				(!ItemTemplate.bOneTimeBuild || (!XComHQ.HasItem(ItemTemplate) && XComHQ.GetNumItemBeingBuilt(ItemTemplate) == 0)) &&
				(!ItemTemplate.bBlocked || XComHQ.UnlockedItems.Find(ItemTemplate.DataName) != INDEX_NONE) &&
				XComHQ.MeetsEnoughRequirementsToBeVisible(ItemTemplate.Requirements, ItemTemplate.AlternateRequirements) &&
				!XComHQ.IsTechResearched(ItemTemplate.HideIfResearched) && !XComHQ.HasItemByName(ItemTemplate.HideIfPurchased))
			{
				arrBuildTemplates.AddItem(ItemTemplate);
			}
		}
	}

	return arrBuildTemplates;
}

function bool GetItemStatBoost(int PowerLevel, ECharStatType StatType, out StatBoost ItemStatBoost, optional bool bMaxBoost = false)
{
	local int idx;

	for(idx = 0; idx < StatBoostTable.Length; idx++)
	{
		if (bMaxBoost) // skirmish mode uses negative power and wants max boost
		{
			if (StatBoostTable[idx].PowerLevel == PowerLevel && StatBoostTable[idx].StatType == StatType)
			{
				ItemStatBoost.StatType = StatBoostTable[idx].StatType;
				ItemStatBoost.Boost = StatBoostTable[idx].MaxBoost;
				return true;
			}
		}
		else if(StatBoostTable[idx].PowerLevel == PowerLevel && StatBoostTable[idx].StatType == StatType)
		{
			ItemStatBoost.StatType = StatBoostTable[idx].StatType;
			ItemStatBoost.Boost = StatBoostTable[idx].MinBoost +
				`SYNC_RAND(StatBoostTable[idx].MaxBoost - StatBoostTable[idx].MinBoost + 1);
			return true;
		}
	}

	return false;
}

function bool WeaponCategoryIsValid(const out name Category)
{
	return WeaponCategories.Find(Category) != INDEX_NONE;
}

function bool ItemCategoryIsValid(const out name Category)
{
	return ItemCategories.Find(Category) != INDEX_NONE;
}

function bool WeaponTechIsValid(const out name Tech)
{
	return  WeaponTechCategories.Find(Tech) != INDEX_NONE;
}

function bool ArmorTechIsValid(const out name Tech)
{
	return ArmorTechCategories.Find(Tech) != INDEX_NONE;
}

function bool ItemCategoryIsUniqueEquip(const out name Category)
{
	return UniqueEquipCategories.Find(Category) != INDEX_NONE;
}

function LoadAllContent()
{
	local X2DataTemplate Template;
	local X2EquipmentTemplate EquipmentTemplate;
	local XComContentManager ContentMgr;
	local int i;

	ContentMgr = `CONTENT;
	foreach IterateTemplates(Template, none)
	{
		EquipmentTemplate = X2EquipmentTemplate(Template);
		if(EquipmentTemplate != none)
		{
			if(EquipmentTemplate.GameArchetype != "")
			{
				ContentMgr.RequestGameArchetype(EquipmentTemplate.GameArchetype, none, none, true);
			}

			if(EquipmentTemplate.AltGameArchetype != "")
			{
				ContentMgr.RequestGameArchetype(EquipmentTemplate.AltGameArchetype, none, none, true);
			}

			if(EquipmentTemplate.CosmeticUnitTemplate != "")
			{
				ContentMgr.RequestGameArchetype(EquipmentTemplate.CosmeticUnitTemplate, none, none, true);
			}

			for (i = 0; i < EquipmentTemplate.AltGameArchetypeArray.Length; ++i)
			{
				if (EquipmentTemplate.AltGameArchetypeArray[i].ArchetypeString != "")
				{
					ContentMgr.RequestGameArchetype(EquipmentTemplate.AltGameArchetypeArray[i].ArchetypeString, none, none, true);
				}
			}
		}
	}
}

DefaultProperties
{
	TemplateDefinitionClass=class'X2Item';
}

//---------------------------------------------------------------------------------------
//  FILE:    X2ItemTemplateManager.uc
//  AUTHOR:  Joshua Bouscher
//
//---------------------------------------------------------------------------------------
//  Copyright (c) 2016 Firaxis Games, Inc. All rights reserved.
//---------------------------------------------------------------------------------------

class X2ItemTemplateManager extends X2DataTemplateManager
	native(Core) config(GameData);

var config array<name>       ItemCategories;
var config array<name>       UniqueEquipCategories;      //  should be a subset of ItemCategories
var config array<name>       WeaponCategories;
var config array<name>       WeaponTechCategories;
var config array<name>       ArmorTechCategories;

var config array<name>      BuildItemWeaponCategories;
var config array<name>      BuildItemArmorCategories;
var config array<name>      BuildItemMiscCategories;

var config int				MaxTechDistanceForValidDrop;  // number of techs "away" from being useable an item can be for it to be eligible to drop (schematics)

var protectedwrite config array<InventoryLoadout>  Loadouts;
var protectedwrite config array<StatBoostDefinition> StatBoostTable;
var protectedwrite config array<TX2MPSoldierItemDefinition> MPAvailableSoldierItems; // the list of items that are available for MP soldier to equip. -tsmith

var protectedwrite X2LootTableManager  LootTableManager;

native static function X2ItemTemplateManager GetItemTemplateManager();

cpptext
{
public:
	virtual void GetDynamicListValues(const FString& ListName, TArray<FString>& Values);
}

protected event ValidateTemplatesEvent()
{
	local int i;
	local X2ItemTemplate kItemTemplate;

	super.ValidateTemplatesEvent();

	LootTableManager = new class'X2LootTableManager';
	LootTableManager.InitLootTables();

	for(i = 0; i < MPAvailableSoldierItems.Length; i++)
	{
		kItemTemplate = FindItemTemplate(MPAvailableSoldierItems[i].ItemTemplateName);
		if(kItemTemplate != none)
		{
			kItemTemplate.MPCost = MPAvailableSoldierItems[i].ItemCost;
		}
	}
}

function bool AddItemTemplate(X2ItemTemplate Template, bool ReplaceDuplicate = false)
{
	return AddDataTemplate(Template, ReplaceDuplicate);
}

function X2DamageTypeTemplate FindDamageTypeTemplate(name DataName)
{
	local X2DataTemplate kTemplate;

	kTemplate = FindDataTemplate(DataName);
	if(kTemplate != none)
		return X2DamageTypeTemplate(kTemplate);
	return none;
}

function X2ItemTemplate FindItemTemplate(name DataName)
{
	local X2DataTemplate kTemplate;

	kTemplate = FindDataTemplate(DataName);
	if (kTemplate != none)
		return X2ItemTemplate(kTemplate);
	return none;
}

function TX2MPSoldierItemDefinition FindMPSoldierItemDefinition(name ItemTemplateName)
{
	local TX2MPSoldierItemDefinition ItemDef;
	local int i;

	for(i = 0; i < MPAvailableSoldierItems.Length; i++)
	{
		if(MPAvailableSoldierItems[i].ItemTemplateName == ItemTemplateName)
		{
			ItemDef = MPAvailableSoldierItems[i];
			break;
		}
	}

	return ItemDef;
}

function array<X2WeaponTemplate> GetAllWeaponTemplates()
{
	local array<X2WeaponTemplate> arrWeaponTemplates;
	local X2DataTemplate Template;
	local X2WeaponTemplate WeaponTemplate;

	foreach IterateTemplates(Template, none)
	{
		WeaponTemplate = X2WeaponTemplate(Template);

		if(WeaponTemplate != none)
		{
			arrWeaponTemplates.AddItem(WeaponTemplate);
		}
	}

	return arrWeaponTemplates;
}

function array<X2EquipmentTemplate> GetAllArmorTemplates()
{
	local array<X2EquipmentTemplate> arrArmorTemplates;
	local X2DataTemplate Template;
	local X2EquipmentTemplate ArmorTemplate;

	foreach IterateTemplates(Template, none)
	{
		ArmorTemplate = X2ArmorTemplate(Template);

		if(ArmorTemplate != none)
		{
			arrArmorTemplates.AddItem(ArmorTemplate);
		}
	}

	return arrArmorTemplates;
}

function array<X2WeaponUpgradeTemplate> GetAllUpgradeTemplates()
{
	local array<X2WeaponUpgradeTemplate> arrUpgradeTemplates;
	local X2DataTemplate Template;
	local X2WeaponUpgradeTemplate UpgradeTemplate;

	foreach IterateTemplates(Template, none)
	{
		UpgradeTemplate = X2WeaponUpgradeTemplate(Template);

		if(UpgradeTemplate != none)
		{
			arrUpgradeTemplates.AddItem(UpgradeTemplate);
		}
	}

	return arrUpgradeTemplates;
}

function array<X2SchematicTemplate> GetAllSchematicTemplates()
{
	local array<X2SchematicTemplate> arrSchematicTemplates;
	local X2DataTemplate Template;
	local X2SchematicTemplate SchematicTemplate;

	foreach IterateTemplates(Template, none)
	{
		SchematicTemplate = X2SchematicTemplate(Template);

		if(SchematicTemplate != none)
		{
			arrSchematicTemplates.AddItem(SchematicTemplate);
		}
	}

	return arrSchematicTemplates;
}

function array<X2ItemTemplate> GetAllItemsCreatedByTemplate(name TemplateName)
{
	local array<X2ItemTemplate> arrItemTemplates;
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if (ItemTemplate != none && ItemTemplate.CreatorTemplateName == TemplateName)
		{
			arrItemTemplates.AddItem(ItemTemplate);
		}
	}

	return arrItemTemplates;
}

// This uses the *mostly* deprecated UpgradeItem variable, mainly existing for backwards compatibility with Day 0 DLC
function array<X2ItemTemplate> GetAllBaseItemTemplatesFromUpgrade(name UpgradeTemplateName)
{
	local array<X2ItemTemplate> arrItemTemplates;
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if (ItemTemplate != none && ItemTemplate.UpgradeItem == UpgradeTemplateName)
		{
			arrItemTemplates.AddItem(ItemTemplate);
		}
	}

	return arrItemTemplates;
}

// Every upgraded item should have only one base
function X2ItemTemplate GetUpgradedItemTemplateFromBase(name BaseTemplateName)
{
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if (ItemTemplate != none && ItemTemplate.BaseItem == BaseTemplateName)
		{
			return ItemTemplate;
		}
	}

	return none;
}

function array<X2ItemTemplate> GetBuildableItemTemplates()
{
	local array<X2ItemTemplate> arrBuildTemplates;
	local X2DataTemplate Template;
	local X2ItemTemplate ItemTemplate;
	local XComGameState_HeadquartersXCom XComHQ;
	local XComGameStateHistory History;

	History = `XCOMHISTORY;
	XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));

	foreach IterateTemplates(Template, none)
	{
		ItemTemplate = X2ItemTemplate(Template);

		if(ItemTemplate != none)
		{
			if(ItemTemplate.CanBeBuilt &&
				(!ItemTemplate.bOneTimeBuild || (!XComHQ.HasItem(ItemTemplate) && XComHQ.GetNumItemBeingBuilt(ItemTemplate) == 0)) &&
				(!ItemTemplate.bBlocked || XComHQ.UnlockedItems.Find(ItemTemplate.DataName) != INDEX_NONE) &&
				XComHQ.MeetsEnoughRequirementsToBeVisible(ItemTemplate.Requirements, ItemTemplate.AlternateRequirements) &&
				!XComHQ.IsTechResearched(ItemTemplate.HideIfResearched) && !XComHQ.HasItemByName(ItemTemplate.HideIfPurchased))
			{
				arrBuildTemplates.AddItem(ItemTemplate);
			}
		}
	}

	return arrBuildTemplates;
}

function bool GetItemStatBoost(int PowerLevel, ECharStatType StatType, out StatBoost ItemStatBoost, optional bool bMaxBoost = false)
{
	local int idx;

	for(idx = 0; idx < StatBoostTable.Length; idx++)
	{
		if (bMaxBoost) // skirmish mode uses negative power and wants max boost
		{
			if (StatBoostTable[idx].PowerLevel == PowerLevel && StatBoostTable[idx].StatType == StatType)
			{
				ItemStatBoost.StatType = StatBoostTable[idx].StatType;
				ItemStatBoost.Boost = StatBoostTable[idx].MaxBoost;
				return true;
			}
		}
		else if(StatBoostTable[idx].PowerLevel == PowerLevel && StatBoostTable[idx].StatType == StatType)
		{
			ItemStatBoost.StatType = StatBoostTable[idx].StatType;
			ItemStatBoost.Boost = StatBoostTable[idx].MinBoost +
				`SYNC_RAND(StatBoostTable[idx].MaxBoost - StatBoostTable[idx].MinBoost + 1);
			return true;
		}
	}

	return false;
}

function bool WeaponCategoryIsValid(const out name Category)
{
	return WeaponCategories.Find(Category) != INDEX_NONE;
}

function bool ItemCategoryIsValid(const out name Category)
{
	return ItemCategories.Find(Category) != INDEX_NONE;
}

function bool WeaponTechIsValid(const out name Tech)
{
	return  WeaponTechCategories.Find(Tech) != INDEX_NONE;
}

function bool ArmorTechIsValid(const out name Tech)
{
	return ArmorTechCategories.Find(Tech) != INDEX_NONE;
}

function bool ItemCategoryIsUniqueEquip(const out name Category)
{
	return UniqueEquipCategories.Find(Category) != INDEX_NONE;
}

function LoadAllContent()
{
	local X2DataTemplate Template;
	local X2EquipmentTemplate EquipmentTemplate;
	local XComContentManager ContentMgr;
	local int i;

	ContentMgr = `CONTENT;
	foreach IterateTemplates(Template, none)
	{
		EquipmentTemplate = X2EquipmentTemplate(Template);
		if(EquipmentTemplate != none)
		{
			if(EquipmentTemplate.GameArchetype != "")
			{
				ContentMgr.RequestGameArchetype(EquipmentTemplate.GameArchetype, none, none, true);
			}

			if(EquipmentTemplate.AltGameArchetype != "")
			{
				ContentMgr.RequestGameArchetype(EquipmentTemplate.AltGameArchetype, none, none, true);
			}

			if(EquipmentTemplate.CosmeticUnitTemplate != "")
			{
				ContentMgr.RequestGameArchetype(EquipmentTemplate.CosmeticUnitTemplate, none, none, true);
			}

			for (i = 0; i < EquipmentTemplate.AltGameArchetypeArray.Length; ++i)
			{
				if (EquipmentTemplate.AltGameArchetypeArray[i].ArchetypeString != "")
				{
					ContentMgr.RequestGameArchetype(EquipmentTemplate.AltGameArchetypeArray[i].ArchetypeString, none, none, true);
				}
			}
		}
	}
}

DefaultProperties
{
	TemplateDefinitionClass=class'X2Item';
}


Update implicit-dim.uc

Update implicit-dim.uc

Fixed Export so it works with Sub

# implicit-dim.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.96 on 6/4/2014 5:06:03 PM
# Comment: Declares variables (with Dim) that were not explicitely declared before

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Declares variables (with Dim) that were not explicitely declared before
Selected: False
Highlight: False
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
FilterTally: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
InputFile: ImplicitDim.Bas
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Find: {@Note:

         This transform does the following:

         * Declares variables that were not previously declared explicitely
         * Comments out user declarations that are from the Windows API
         * Ensures that the casing of variables/functions is consistent
           with their declarations since C++ is case-sensitive

      }

Replace: {@Define::
            Token: \x27.* ~~ Properties: ucWhitespace
            Token: _[^\n]*\n ~~ Properties: ucWhitespace
         }
         {@Define:
            Var: Globals As Table
            Var: ImplicitDim As Table
            Var: ExplicitDim As Table
            Var: CurrentRoutine As String
            Var: Prototype As String
            Var: Prototypes As String
            Var: ExpIndex As Long
            Var: ImpIndex As Long
            Var: FuncIndex As Long
            Var: GlobalIndex As Long
            SyntaxArg: NameAndSpecifier = "[a-z][a-z0-9_]*[$#!?%&]*"
         }
         {@Exec:
            Split(File("PBKeywords.txt")+Chr(13,10)+File("WinAPIKeywords.txt"))
            uc_For(x, 1, StringItemCount, 2, Insert(Globals, StringItem(x)))
         }

Criteria: 2
Comment: Teporarily adds Dim keyword in front of args for further parsing
Pass: 1

Criteria: 3
Selected: True
Find: {nl}{routine: Sub | Function } {etc}([{args}]) [[{exp: Export}] [As {type:1}]]
Replace: {@Eval:
            Prototype = {Q}{routine} {etc}({args:Dim {args}}){exp}{type: As {type}}{Q}
            Prototypes += "{nl}Declare " + Prototype
            "{nl}" + Prototype
         }

Criteria: 4
SkipOver: True
Find: {nl}Function =
Replace: [Skip over]

Criteria: 5
Comment: Inserts explicitly Dimmed variable names in global or local tables
Pass: 2

Criteria: 6
PassOnce: False
Find: {@Start}
Replace: ' Prototypes
         {@Eval: Prototypes}
         ' End of prototypes{nl}

Criteria: 7
Find: Global{" +"}{variable:NameAndSpecifier}
Replace: {Self}{@Evaluate: Insert(Globals, {variable})}

Criteria: 8
BackColor: Silver
Find: {nl}{ Macro | Type | Union | % | $[$] | Declare {func:1} }  {name:1}
Replace: {Self}{@Evaluate: Insert(Globals, {name})}

Criteria: 9
BackColor: Lime
Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"}
Replace: {Self}{@Define:
            Var: {RoutineName}ExplicitDim As Table
            Var: {RoutineName}ImplicitDim As Table
         }{@Eval: SetVar(CurrentRoutine, "{RoutineName}"); Insert(Globals,"{RoutineName}")}

Criteria: 10
Find: {nl}End { Sub | Function }
Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, "")}

Criteria: 11
BackColor: Pink
Find: {declare: Dim [[Optional] { ByVal | ByRef }] | Local | Static | Register | fstream }
      {" +"}{variable:NameAndSpecifier}
Replace: {Self}{@Eval: Insert(~Eval(CurrentRoutine)ExplicitDim, "{variable}")}

Criteria: 12
Comment: Temporarily inserts declaration for each individual variable a lines with a list of multiple vars, for easier parsing
BackColor: SlateBlue
PassOnce: False
Find: {declare: Global|Dim|Local|Static|Register} {variable},
Replace: {declare} {variable} ::: {declare}

Criteria: 13
Find: {nl}%{equate:1} = {@If: Index(Globals, {equate})}
Replace: {nl} ' <WinAPI> {equate} =

Criteria: 14
Find: {nl}Declare {method: Sub | Function } {name:1}  {@If: Index(Globals, {name})}
Replace: {nl} ' <WinAPI> Declare {method} {name}

Criteria: 15
Comment: Places non-Dimmed variable names in separate local tables
Pass: 3

Criteria: 16
Find: [{eq: %}]{name:NameAndSpecifier} [{IsFunc:" *\("}]
Replace: {eq}{@Eval:
            ExpIndex    = Index(~Eval(CurrentRoutine)ExplicitDim, "{name}")
            ImpIndex    = Index(~Eval(CurrentRoutine)ImplicitDim, "{name}")
            FuncIndex   = Index(Globals, Remove("{name}", "{'[$#!?%&]+'}"))
            GlobalIndex = Index(Globals, "{name}")
            IIf(ExpIndex+ImpIndex+FuncIndex+GlobalIndex == 0 And "{IsFunc}" == "",
                Insert(~Eval(CurrentRoutine)ImplicitDim, "{name}"))

            text = "{name}"
            IIf(GlobalIndex, text = ReadKey(Globals, GlobalIndex))
            IIf(ExpIndex, text = ReadKey(~Eval(CurrentRoutine)ExplicitDim, ExpIndex))
            IIf(ImpIndex, text = ReadKey(~Eval(CurrentRoutine)ImplicitDim, ImpIndex))
            text + "{IsFunc}"
         }

Criteria: 17
SkipOver: True
Find: {"[a-z0-9_]+"}  {UDT:"\.[a-z0-9_\@\.]+"}
Replace: [Skip over]

Criteria: 18
SkipOver: True
Find: {"&h[0-9a-f]+"}
Replace: [Skip over]

Criteria: 19
Find: {"Exe"}.{suffix:1}$
Replace: Exe.{suffix}

Criteria: 20
BackColor: Brown
Find: {"\n"}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"}
Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, {RoutineName})}

Criteria: 21
Find: {"\n"}End { Sub | Function }
Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, "")}

Criteria: 22
Comment: Inserts local Dim statements for variables that were not dimmed
Pass: 4

Criteria: 23
BackColor: Purple
Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"} {etc}
Replace: {Self}
         {@Eval:
            Range(1, Count({RoutineName}ImplicitDim),
            {Q}"   Dim "+ReadKey({RoutineName}ImplicitDim, x)+" ' Implicit"+Chr(10){Q})
         }

Criteria: 24
Comment: Clean up (temp declaration statements removed)
Pass: 5

Criteria: 25
BackColor: Violet
Find: ::: {declare:1}
Replace: ,

Criteria: 26
BackColor: CornflowerBlue
Find: (Dim {args})
Replace: ({@Eval: Replace("{args}", "::: Dim", ",")})

Criteria: 27
Find: Dim {nl}
Replace: {Nothing}

# End Search

# implicit-dim.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.96 on 5/16/2014 12:01:23 PM
# Comment: Declares variables (with Dim) that were not explicitely declared before

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally

FindMode: Replace

# Definitions

# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Declares variables (with Dim) that were not explicitely declared before
Selected: False
Highlight: False
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
FilterTally: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
InputFile: ImplicitDim.Bas
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Find: {@Note:

         This transform does the following:

         * Declares variables that were not previously declared explicitely
         * Comments out user declarations that are from the Windows API
         * Ensures that the casing of variables/functions is consistent
           with their declarations since C++ is case-sensitive

      }

Replace: {@Define::
            Token: \x27.* ~~ Properties: ucWhitespace
            Token: _[^\n]*\n ~~ Properties: ucWhitespace
         }
         {@Define:
            Var: Globals As Table
            Var: ImplicitDim As Table
            Var: ExplicitDim As Table
            Var: CurrentRoutine As String
            Var: Prototype As String
            Var: Prototypes As String
            Var: ExpIndex As Long
            Var: ImpIndex As Long
            Var: FuncIndex As Long
            Var: GlobalIndex As Long
            SyntaxArg: NameAndSpecifier = "[a-z][a-z0-9_]*[$#!?%&]*"
         }
         {@Exec:
            Split(File("PBKeywords.txt")+Chr(13,10)+File("WinAPIKeywords.txt"))
            uc_For(x, 1, StringItemCount, 2, Insert(Globals, StringItem(x)))
         }

Criteria: 2
Comment: Teporarily adds Dim keyword in front of args for further parsing
Pass: 1

Criteria: 3
Selected: True
Find: {nl}{routine: Sub | Function } {etc}([{args}]) [[{exp: Export}] As {type:1}]
Replace: {@Eval:
            Prototype = {Q}{routine} {etc}({args:Dim {args}}){exp}{type: As {type}}{Q}
            Prototypes += "{nl}Declare " + Prototype
            "{nl}" + Prototype
         }

Criteria: 4
SkipOver: True
Find: {nl}Function =
Replace: [Skip over]

Criteria: 5
Comment: Inserts explicitly Dimmed variable names in global or local tables
Pass: 2

Criteria: 6
PassOnce: False
Find: {@Start}
Replace: ' Prototypes
         {@Eval: Prototypes}
         ' End of prototypes{nl}

Criteria: 7
Find: Global{" +"}{variable:NameAndSpecifier}
Replace: {Self}{@Evaluate: Insert(Globals, {variable})}

Criteria: 8
BackColor: Silver
Find: {nl}{ Macro | Type | Union | % | $[$] | Declare {func:1} }  {name:1}
Replace: {Self}{@Evaluate: Insert(Globals, {name})}

Criteria: 9
BackColor: Lime
Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"}
Replace: {Self}{@Define:
            Var: {RoutineName}ExplicitDim As Table
            Var: {RoutineName}ImplicitDim As Table
         }{@Eval: SetVar(CurrentRoutine, "{RoutineName}"); Insert(Globals,"{RoutineName}")}

Criteria: 10
Find: {nl}End { Sub | Function }
Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, "")}

Criteria: 11
BackColor: Pink
Find: {declare: Dim [[Optional] { ByVal | ByRef }] | Local | Static | Register | fstream }
      {" +"}{variable:NameAndSpecifier}
Replace: {Self}{@Eval: Insert(~Eval(CurrentRoutine)ExplicitDim, "{variable}")}

Criteria: 12
Comment: Temporarily inserts declaration for each individual variable a lines with a list of multiple vars, for easier parsing
BackColor: SlateBlue
PassOnce: False
Find: {declare: Global|Dim|Local|Static|Register} {variable},
Replace: {declare} {variable} ::: {declare}

Criteria: 13
Find: {nl}%{equate:1} = {@If: Index(Globals, {equate})}
Replace: {nl} ' <WinAPI> {equate} =

Criteria: 14
Find: {nl}Declare {method: Sub | Function } {name:1}  {@If: Index(Globals, {name})}
Replace: {nl} ' <WinAPI> Declare {method} {name}

Criteria: 15
Comment: Places non-Dimmed variable names in separate local tables
Pass: 3

Criteria: 16
Find: [{eq: %}]{name:NameAndSpecifier} [{IsFunc:" *\("}]
Replace: {eq}{@Eval:
            ExpIndex    = Index(~Eval(CurrentRoutine)ExplicitDim, "{name}")
            ImpIndex    = Index(~Eval(CurrentRoutine)ImplicitDim, "{name}")
            FuncIndex   = Index(Globals, Remove("{name}", "{'[$#!?%&]+'}"))
            GlobalIndex = Index(Globals, "{name}")
            IIf(ExpIndex+ImpIndex+FuncIndex+GlobalIndex == 0 And "{IsFunc}" == "",
                Insert(~Eval(CurrentRoutine)ImplicitDim, "{name}"))

            text = "{name}"
            IIf(GlobalIndex, text = ReadKey(Globals, GlobalIndex))
            IIf(ExpIndex, text = ReadKey(~Eval(CurrentRoutine)ExplicitDim, ExpIndex))
            IIf(ImpIndex, text = ReadKey(~Eval(CurrentRoutine)ImplicitDim, ImpIndex))
            text + "{IsFunc}"
         }

Criteria: 17
SkipOver: True
Find: {"[a-z0-9_]+"}  {UDT:"\.[a-z0-9_\@\.]+"}
Replace: [Skip over]

Criteria: 18
SkipOver: True
Find: {"&h[0-9a-f]+"}
Replace: [Skip over]

Criteria: 19
Find: {"Exe"}.{suffix:1}$
Replace: Exe.{suffix}

Criteria: 20
BackColor: Brown
Find: {"\n"}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"}
Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, {RoutineName})}

Criteria: 21
Find: {"\n"}End { Sub | Function }
Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, "")}

Criteria: 22
Comment: Inserts local Dim statements for variables that were not dimmed
Pass: 4

Criteria: 23
BackColor: Purple
Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"} {etc}
Replace: {Self}
         {@Eval:
            Range(1, Count({RoutineName}ImplicitDim),
            {Q}"   Dim "+ReadKey({RoutineName}ImplicitDim, x)+" ' Implicit"+Chr(10){Q})
         }

Criteria: 24
Comment: Clean up (temp declaration statements removed)
Pass: 5

Criteria: 25
BackColor: Violet
Find: ::: {declare:1}
Replace: ,

Criteria: 26
BackColor: CornflowerBlue
Find: (Dim {args})
Replace: ({@Eval: Replace("{args}", "::: Dim", ",")})

Criteria: 27
Find: Dim {nl}
Replace: {Nothing}

# End Search