|
[jass]
//#####BEGIN#####
//! define MOD(a,b) (a-(a/b)*b)
function POW takes integer a,integer b returns integer
local integer r = a
if a == 0 then
return 0
endif
if b == 0 then
return 1
endif
loop
exitwhen b == 1
set r = r * a
set b = b - 1
endloop
return r
endfunction
struct Stream
string S = ""
method Push takes integer data,integer nbit returns nothing
local string ret = null
local integer i = 0
local integer n = POW(2,nbit)
set data = MOD(data,n)
loop
if MOD(data,2) == 1 then
set ret = "1" + ret
else
set ret = "0" + ret
endif
set i = i + 1
exitwhen data <= 1
set data = data / 2
endloop
loop
exitwhen i >= nbit
set ret = "0" + ret
set i = i + 1
endloop
set this.S = this.S + ret
endmethod
method Pop takes integer nbit returns integer
local integer i = StringLength(this.S)
local integer k = 0
local string ret = SubString(this.S,i-nbit,i)
set this.S = SubString(this.S,0,i-nbit)
set i = 0
loop
exitwhen k == nbit
if SubString(ret,k,k+1)=="1" then
set i = i + POW(2,nbit-k-1)
endif
set k = k + 1
endloop
return i
endmethod
method Xor takes integer data, integer nbit returns nothing
local string ret = null
local Stream ts = Stream.create()
local integer i = 0
local integer n = StringLength(this.S)
loop
exitwhen i >= n
call ts.Push(data,nbit)
set i = i + nbit
endloop
set i = 0
loop
exitwhen i >= n
if SubString(this.S,i,i+1)==SubString(ts.S,i,i+1) then
set ret = ret + "0"
else
set ret = ret + "1"
endif
set i = i + 1
endloop
set this.S = ret
endmethod
endstruct
library CNS initializer InitCNS
globals
string array CNST
private gamecache gc
endglobals
function InitCNS takes nothing returns nothing
local integer i = 0
local integer m
local integer n
local string ch = null
set CNST[0] = "的是在和有这主中为们地用时要动国产以到会作来分生对学级就年阶发成部民可出能方进同行面种过命度革而多后自社加机也经线电高量党得实家定深法表着理化争现所起政好战农使前等反体合路图把结第里正新开论物从当两些还天资事队批如应形想制心样都向变关重其思与间内因利相由压"
set CNST[1] = "员气代全组数果期导平各基或月然问展外没看提解林者群意明道认次通但条较克孔领军流接席位情运器原油放题质指建区验活很教决特此常石强极根共直团统式转别造切取西持总料连任志观调程报更见必真保热委改管处将修支识象先老光专型具复安带东增则完风回南劳轮科北积车计给节做务"
set CNST[2] = "被整联步类集列温知研单坚据速防世设达场历花受传断况采精金界判参层止边清至确究书状须离再海权青证试规近注铁需议县固除般引胜细影济白格效置推空配叶率述选养德话查差始施响收华觉备红续均药标记难存紧派准角降维板许破述技消势端感神构照容非亚族火段适讲按值美态黄易服削"
set CNST[3] = "信排声该击素张害草何树继右属严检页抗苏显苦英称移材省黑武培著河帝仅针植助升抓含副杂普谈围射源例致酸充足划剂宣环落首波承粉府随考刻够满包促局周护岩师举春超负模贫减阳扬球朝医校稻宋唯滑站卫字鼓刚略供某功套友限项卷创律雨让远帮初皮播优占毒伟训控云互跟裂粮粒练钢顶"
set CNST[4] = "策双留误础阻故盾晚丝散功株亲院冷彻弹错散商视艺版烈零室轻血倍缺厘察绝富城冲喷简否柱李望盘似困巩益洲投送侧盖挥距触星松送获独官混纪依突架宽冬章纹执矿责稳夺价努奇预职评读背协损棉侵灰虽厚罗泥告箱停曾溶营终纲孟钱待尽沙退陈讨奋剥迫旋征担鲜粗逐弱盐丰编印蜂急扩伤露"
set CNST[5] = "核缘游振域甚迅辉异序纸夜念兰映儒杀汽艰晶埃燃欢铁补永瓦倾阵碳演威附永瓦斜欧献顺洋腐透司危脉宜若尾壮暴企菜穗楚汉愈绿拖份染既秋遍锻玉夏疗尖费州访荣铜沿替滚客召悟刺脑措贯藏敢隙炉壳硫煤迎铸粘探临薄善福纵择礼愿伏残雷延烟纯渐耕跑泽慢赤繁境潮横掉希池败船假亮谓托伙"
set CNST[6] = "哲割摆贡呈劲财仪沉炼麻祖息车穿货销齐画龙库守筑房歌寒喜洗蚀废纳录镜恶庄险赞钟典柄竹谷乱虚桥奥赶垂途额壁网野遗静谋挂课镇妄盛耐援虑键归符聚绕摩忙舞遇索顾胶湖钉仁音迹碎灯避泛答勇频皇柳哈揭诺概宪浓岛袭洪谢浇斑讯懂灵闭释徒银伊景坦累霉杜乐隔弯绩招绍胡峰零柴居尚秦"
set CNST[7] = "稍追耗殊岗挖剧堆荷勤篇登驻案刊缓役剪雪渔洛盟旗坐竟陷冒暗弧爆涂味陆健尊拔抵警污冰饭塑寄康遵牧遭订香屋敏恢忘衣龄骗稀昆浪茶拥浸紫戏塔锤岁貌牢锋疑霸闪猛诉刷狠忽闹漏荒抢旁玻忠捕锁乘智淡允叛毕宝芯鉴秘枯轨循诱祝肯酒绳泡惯贸综墙彼墨启逆卸航辐渗惊顿悬姆森糖圣陶词迟"
set gc = InitGameCache("hjCNS")
loop
exitwhen i == 1024
set m = i/128
set n = MOD(i,128)
set ch = SubString(CNST[m],n*3,n*3+3)
call StoreInteger(gc,"hjCNST",ch,i)
set i = i + 1
endloop
endfunction
function CNS2INT takes string ch returns integer
return GetStoredInteger(gc,"hjCNST",ch)
endfunction
function INT2CNS takes integer i returns string
local integer m = i/128
set i = MOD(i,128)
return SubString(CNST[m],i*3,i*3+3)
endfunction
endlibrary
//#####END#####
//真的很方便啊
//简单地介绍一下
local string c= null
local Stream S = Stream.create()
call S.Push(3,2)//角色
call S.Push(99,8)//等级
call S.Push(999,10)//力量
call S.Push(999,10)//敏捷
call S.Push(999,10)//智力
//call S.Xor(123,7)
set c = c + INT2CNS(S.Pop(10))
set c = c + INT2CNS(S.Pop(10))
set c = c + INT2CNS(S.Pop(10))
set c = c + INT2CNS(S.Pop(10))
call BJDebugMsg("你的存档码是:"+c)
//再可以加点加密和随机的函数,就能用于地图的存档了
[/jass] |
|