Name | Type | is_array | initial_value |
code_Bits | integer | Yes | |
code_BitsCRC | integer | Yes | |
code_BitsEnd | integer | No | |
code_CharMap | string | No | |
code_CRCSize | integer | No | |
code_CRCStart | integer | No | |
code_Creator | string | No | |
code_CurrentPlayer | player | No | |
code_CurrentPlayerGroup | force | No | |
code_Data | integer | Yes | |
code_DataEnd | integer | No | |
code_DataSample | integer | Yes | |
code_DataSize | integer | Yes | |
code_DataSizeTotal | integer | No | |
code_Debug | boolean | Yes | |
code_DecodingError | boolean | No | |
code_ErrorMessage | string | No | |
code_Raw | integer | Yes | |
code_RawBase | integer | No | |
code_RawEnd | integer | No | |
code_RawSize | integer | No | |
code_TB_Input | integer | No | |
code_TB_Output | integer | No | |
code_Text | string | No | |
code_Unit | unit | No | |
cv_Ability | integer | Yes | |
cv_Ability_AGI | integer | No | |
cv_Ability_INT | integer | No | |
cv_Ability_STR | integer | No | |
cv_Bits | integer | No | |
cv_CRC | integer | No | |
cv_Data | integer | No | |
cv_HeroType | integer | No | |
cv_ItemType | integer | Yes | |
cv_Level | integer | No | |
cv_Padding | integer | No | |
cv_Raw | integer | No | |
cv_Version | integer | No | |
doorTimer | timer | No | |
i | integer | No | |
store_AbilityCount | integer | No | |
store_AbilityTypes | abilcode | Yes | |
store_HeroTypes | unitcode | Yes | |
store_HeroTypesEnd | integer | No | |
store_ItemTypes | itemcode | Yes | |
store_ItemTypesEnd | integer | No | |
store_Location | location | No | |
tempAbility | abilcode | No | |
tempBoolean | boolean | No | |
tempItem | item | No | |
tempItemType | itemcode | No | |
tempString | string | No | |
tempUnit | unit | No | |
tempUnitGroup | group | No | |
tempUnitType | unitcode | No |
// positive shifts left (larger number), negative shifts right (smaller number)
// this is not a complete implementation of a bit shift because sign is ignored
function BitShift takes integer x, integer shift returns integer
return R2I(x * Pow( 2, shift))
endfunction
// bits is the number of bits to keep (starting with low bits)
function BitClip takes integer x, integer bits returns integer
return ModuloInteger ( x, R2I( Pow( 2, bits )))
endfunction
// All of the functions ending in "TB" serve the purpose of array pointers.
// Translate Base can write to/from any of 3 structures, the structures it uses
// are chosen by setting udg_code_TB_Input and udg_code_TB_Output
// This is complicated, but the goal is to push the complexity out of
// the Trig_Translate_Base_Actions function.
function GetTB takes integer arrayID, integer index returns integer
if arrayID == udg_cv_Data then
return udg_code_Data[index]
elseif arrayID == udg_cv_Bits then
return udg_code_Bits[index]
elseif arrayID == udg_cv_Raw then
return udg_code_Raw[index]
endif
return 0
endfunction
function GetInputTB takes integer index returns integer
return GetTB( udg_code_TB_Input, index)
endfunction
function GetOutputTB takes integer index returns integer
return GetTB( udg_code_TB_Output, index)
endfunction
function GetSizeTB takes integer arrayID, integer index returns integer
if arrayID == udg_cv_Data then
return udg_code_DataSize[index]
elseif arrayID == udg_cv_Bits then
return 1
elseif arrayID == udg_cv_Raw then
return udg_code_RawSize
endif
return 0
endfunction
function GetInputSizeTB takes integer index returns integer
return GetSizeTB( udg_code_TB_Input, index)
endfunction
function GetOutputSizeTB takes integer index returns integer
return GetSizeTB( udg_code_TB_Output, index)
endfunction
function SetTB takes integer arrayID, integer index, integer value returns integer
if arrayID == udg_cv_Data then
set udg_code_Data[index] = value
elseif arrayID == udg_cv_Bits then
set udg_code_Bits[index] = value
elseif arrayID == udg_cv_Raw then
set udg_code_Raw[index] = value
endif
return 0
endfunction
function SetOutputTB takes integer index, integer value returns integer
return SetTB( udg_code_TB_Output, index, value)
endfunction
function GetEndTB takes integer arrayID returns integer
if arrayID == udg_cv_Data then
return udg_code_DataEnd
elseif arrayID == udg_cv_Bits then
return udg_code_BitsEnd
elseif arrayID == udg_cv_Raw then
return udg_code_RawEnd
endif
return 0
endfunction
function GetOutputEndTB takes nothing returns integer
return GetEndTB( udg_code_TB_Output)
endfunction
function GetInputEndTB takes nothing returns integer
return GetEndTB( udg_code_TB_Input)
endfunction
// ***************************************************
function Trig_Translate_Base_Actions takes nothing returns nothing
local integer entry
local integer entrySize
local integer input= -1
local integer inputBitsLeft = 0
local integer inputEnd = GetInputEndTB()
local integer output = -1
local integer outputBitsLeft = 0
local integer outputEnd = GetOutputEndTB()
loop
if inputBitsLeft == 0 then
exitwhen input == inputEnd
set input = input + 1
set inputBitsLeft = GetInputSizeTB(input)
endif
if outputBitsLeft == 0 then
exitwhen output == outputEnd
set output = output + 1
call SetOutputTB(output, 0)
set outputBitsLeft = GetOutputSizeTB(output)
endif
set entrySize = IMinBJ(inputBitsLeft, outputBitsLeft)
set entry = GetInputTB(input)
set entry = BitShift (entry, - (GetInputSizeTB(input) - inputBitsLeft))
set entry = BitClip (entry, entrySize)
set entry = BitShift (entry, GetOutputSizeTB(output) - outputBitsLeft)
// call DisplayTimedTextToForce( GetPlayersAll(), 600.00, I2S(entry))
call SetOutputTB(output, GetOutputTB(output) + entry)
set inputBitsLeft = inputBitsLeft - entrySize
set outputBitsLeft = outputBitsLeft - entrySize
endloop
endfunction
//===========================================================================
function InitTrig_Code_Translate_Base takes nothing returns nothing
set gg_trg_Code_Translate_Base = CreateTrigger( )
call TriggerAddAction( gg_trg_Code_Translate_Base, function Trig_Translate_Base_Actions )
endfunction
function Trig_Code_Text_to_Raw_Actions takes nothing returns nothing
local integer rawIndex = 0
local integer textIndex = 1
local integer charMapIndex
local string currentCharacter
local integer textLength = StringLength(udg_code_Text)
loop
exitwhen rawIndex > udg_code_RawEnd
if textIndex > textLength then
set udg_code_DecodingError = true
set udg_code_ErrorMessage = "Not enough characters in entered code, code should be " + I2S(udg_code_RawEnd + 1) + " characters long."
exitwhen true
endif
set currentCharacter = StringCase(SubStringBJ(udg_code_Text, textIndex, textIndex), true)
set charMapIndex = 1
loop
if SubStringBJ(udg_code_CharMap, charMapIndex, charMapIndex) == currentCharacter then
set udg_code_Raw[rawIndex] = charMapIndex - 1
set rawIndex = rawIndex + 1
exitwhen true
endif
set charMapIndex = charMapIndex + 1
exitwhen charMapIndex > udg_code_RawBase
endloop
set textIndex = textIndex + 1
endloop
endfunction
//===========================================================================
function InitTrig_Code_Text_to_Raw takes nothing returns nothing
set gg_trg_Code_Text_to_Raw = CreateTrigger( )
call TriggerAddAction( gg_trg_Code_Text_to_Raw, function Trig_Code_Text_to_Raw_Actions )
endfunction