|
测试时很好用的东东,将String形式的比如用PlayerChatEvent输入的字符换算成整数格式方便动态添加单位,技能等.
原理和麦德原来作StringToId相识似..不过来自暴雪本身的DebugIdInteger2IdString.(cheat.j,藏在WAR3.MPQ里)居然有错..汗,主要是里面用的字典都错了一位,因为这个问题我弄了好半天,(我用暴雪原装的DebugIdInteger2IdString去检查,谁想得到是blizzard自己的毛病.)
[codes=jass]//===========================================================================
// Convert a integer id value into a 4-letter id code.
//
function DebugIdInteger2IdString takes integer value returns string
local string charMap = "..................................!.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................"
local string result = ""
local integer remainingValue = value
local integer charValue
local integer byteno
set byteno = 0
loop
set charValue = ModuloInteger(remainingValue, 256)
set remainingValue = remainingValue / 256
set result = SubString(charMap, charValue, charValue + 1) + result
set byteno = byteno + 1
exitwhen byteno == 4
endloop
return result
endfunction[/codes]
修正一个点的位置.能用了..
下面是我写的:
[codes=jass]function debugS2I takes string targetstr returns integer
local string originstr="..................................!.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................"
local integer strlength=StringLength(targetstr)
local integer a=0 //分部当前数字
local integer b=0 //当前处理字
local integer numx=1 //位权
local integer result=0
loop
exitwhen b>strlength-1
set numx=R2I(Pow(256,strlength-1-b))
set a=1
loop
exitwhen a>255
if SubString(targetstr,b,b+1)==SubString(originstr,a,a+1) then
set result=result+a*numx
set a=256
endif
set a=a+1
endloop
set b=b+1
endloop
return result
endfunction
[/codes]
[ 本帖最后由 kook 于 2006-4-21 20:46 编辑 ] |
|