|
作者:暗月之舞
[codes=jass]
//############################################################################
// Return Bug System
// Edit by feelerly
// 2007.09.21
// * 这是Return Bug系统,用于游戏中的数据转换,十分重要
// * 这个系统是公开的,大家可以对其进行编辑以及修改
// * 这个是专用于我所出品的地图以及演示图中所用的储存系统
// * 函数 S2ID 专用来转换代码,比如要将物品,单位,技能等代码进行编辑时,可以使用
// ID2S 函数将代码转为字符串,再使用S2ID函数可以将字符再次化为代码
// * 这个是自己编辑的Return Bug System,仅供大家参考
//#############################################################################
//========================================================================
// 常量函数部分
// * constant 开头的函数为常量函数,一般不能更改
// * CacheValue 函数中,常量bj_lastCreatedGameCache的值可以在地图初始化中设定
// 也可以不用设定,游戏中,最好不要随便更改bj_lastCreatedGameCache的取值
// * H2I 是Return Bug函数,可以将handle类数据当作整数进行编辑,但事实上,H2I传回
// * 的是handle类数据,因为不能按照整数那样进行"+,-,*,/"等操作,否则会导致数据
// * 溢出,以致游戏崩溃.
//========================================================================
constant function StringNum takes nothing returns string
return "0123456789"
endfunction
constant function StringABC takes nothing returns string
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
endfunction
constant function Stringabc takes nothing returns string
return "abcdefghijklmnopqrstuvwxyz"
endfunction
constant function H2I takes handle H returns integer
return H
return 0
endfunction
function CacheValue takes nothing returns gamecache
if(bj_lastCreatedGameCache==null)then
set bj_lastCreatedGameCache=InitGameCache("ReturnBugSystem.w3v")
endif
return bj_lastCreatedGameCache
endfunction
//========================================================================
// 主要函数功能介绍: 数据存储
// * SetHandleValue(subject,missonkey,value) -- 将value值(类型为handle)
// 梆定在subject(类型为handle)上,missonkey是字符名
// * SetHandleInteger(subject,missonkey,value) -- 将value值(类型为integer)
// 梆定在subject(类型为handle)上,missonkey是字符名
// * SetHandleReal(subject,missonkey,value) -- 将value值(类型为real)
// 梆定在subject(类型为handle)上,missonkey是字符名
// * SetHandleString(subject,missonkey,value) -- 将value值(类型为string)
// 梆定在subject(类型为handle)上,missonkey是字符名
// * SetHandleBoolean(subject,missonkey,value) -- 将value值(类型为boolean)
// 梆定在subject(类型为handle)上,missonkey是字符名
//========================================================================
function SetHandleValue takes handle subject,string missonkey,handle value returns nothing
if(value==null)then
call FlushStoredInteger(CacheValue(),I2S(H2I(subject)),missonkey)
else
call StoreInteger(CacheValue(),I2S(H2I(subject)),missonkey,H2I(value))
endif
endfunction
function SetHandleInteger takes handle subject,string missonkey,integer value returns nothing
if(value==0)then
call FlushStoredInteger(CacheValue(),I2S(H2I(subject)),missonkey)
return
else
call StoreInteger(CacheValue(),I2S(H2I(subject)),missonkey,value)
endif
endfunction
function SetHandleReal takes handle subject,string missonkey,real value returns nothing
if(value==0.00)then
call FlushStoredReal(CacheValue(),I2S(H2I(subject)),missonkey)
return
else
call StoreReal(CacheValue(),I2S(H2I(subject)),missonkey,value)
endif
endfunction
function SetHandleString takes handle subject,string missonkey,string value returns nothing
if(value==null or value=="")then
call FlushStoredString(CacheValue(),I2S(H2I(subject)),missonkey)
return
else
call StoreString(CacheValue(),I2S(H2I(subject)),missonkey,value)
endif
endfunction
function SetHandleBoolean takes handle subject,string missonkey,boolean value returns nothing
if(value==false)then
call FlushStoredBoolean(CacheValue(),I2S(H2I(subject)),missonkey)
return
else
call StoreBoolean(CacheValue(),I2S(H2I(subject)),missonkey,value)
endif
endfunction
//========================================================================
// 主要函数功能介绍: 数据读取
// * GetHandleHandle(subject,missonkey) -- 取得梆定在subject(类型为handle)
// 字符名missonkey上的(handle)句柄数据
// * GetHandleInteger(subject,missonkey) -- 取得梆定在subject(类型为handle)
// 字符名missonkey上的(integer)整数数据
// * GetHandleReal(subject,missonkey) -- 取得梆定在subject(类型为handle)
// 字符名missonkey上的(real)实数数据
// * GetHandleString(subject,missonkey) -- 取得梆定在subject(类型为handle)
// 字符名missonkey上的(string)字符数据
// * GetHandleBoolean(subject,missonkey) -- 取得梆定在subject(类型为handle)
// 字符名missonkey上的(boolean)布尔数据
// * GetHandleUnit(subject,missonkey) -- 取得梆定在subject(类型为handle)
// 字符名missonkey上的(unit)单位数据
// **再以下都是GetHandleHandle的扩展类型函数,一般可以自由添加**
//========================================================================
function GetHandleHandle takes handle subject,string missonkey returns handle
return GetStoredInteger(CacheValue(),I2S(H2I(subject)),missonkey)
return null
endfunction
function GetHandleInteger takes handle subject,string missonkey returns integer
return GetStoredInteger(CacheValue(),I2S(H2I(subject)),missonkey)
endfunction
function GetHandleReal takes handle subject,string missonkey returns real
return GetStoredReal(CacheValue(),I2S(H2I(subject)),missonkey)
endfunction
function GetHandleString takes handle subject,string missonkey returns string
return GetStoredString(CacheValue(),I2S(H2I(subject)),missonkey)
endfunction
function GetHandleBoolean takes handle subject,string missonkey returns boolean
return GetStoredBoolean(CacheValue(),I2S(H2I(subject)),missonkey)
endfunction
function GetHandleUnit takes handle subject,string missonkey returns unit
return GetHandleHandle(subject,missonkey)
endfunction
function GetHandleGroup takes handle subject,string missonkey returns group
return GetHandleHandle(subject,missonkey)
endfunction
function GetHandleTrigger takes handle subject,string missonkey returns trigger
return GetHandleHandle(subject,missonkey)
endfunction
function GetHandleTriggerAction takes handle subject,string missonkey returns triggeraction
return GetHandleHandle(subject,missonkey)
endfunction
function GetHandleEffect takes handle subject,string missonkey returns effect
return GetHandleHandle(subject,missonkey)
endfunction
function GetHandleWeather takes handle subject,string missonkey returns weathereffect
return GetHandleHandle(subject,missonkey)
endfunction
function GetHandleLightning takes handle subject,string missonkey returns lightning
return GetHandleHandle(subject,missonkey)
endfunction
//#############################################################################
// Save Data System
// Edit by feelerly
// 2007.09.21
// * 附加这个系统,主要是为了主便技能以及各种代码的移植,看起来虽然作用不是很大
// 但在某些方面确实有其好的一面,配合上Return Bug System的应用,其意义也不仅限
// 于此了,其中妙用自己慢慢体会
// 函数功能介绍:
// * S2ID(source) -- 将字符source(类型string)转化为代码(类型integer)
// * ID2S(int) -- 将代码int(类型integer)转化为字符串
//#############################################################################
function S2ID takes string source returns integer
local integer Id = 0
local integer n1 = 1
local integer n2 = 1
loop
exitwhen(n1>StringLength(source))
loop
exitwhen(n2>10)
if(SubString(source,n1-1,n1)==SubString(StringNum(),n2-1,n2))then
set Id=Id+R2I(('0'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
set n2=n2+1
else
set n2=n2+1
endif
endloop
set n2=1
loop
exitwhen(n2>26)
if(SubString(source,n1-1,n1)==SubString(StringABC(),n2-1,n2))then
set Id=Id+R2I(I2R('A'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
set n2=n2+1
else
set n2=n2+1
endif
endloop
set n2=1
loop
exitwhen(n2>26)
if(SubString(source,n1-1,n1) == SubString(Stringabc(),n2-1,n2))then
set Id=Id+R2I(('a'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
set n2=n2+1
else
set n2=n2+1
endif
endloop
set n2=1
set n1=n1+1
endloop
return Id
endfunction
function ID2S takes integer int returns string
local string target=""
local integer n=0
local integer dis=0
loop
exitwhen(int==0)
set n=ModuloInteger(int,256)
if(n>='0' and n<='9')then
set dis=n-'0'
set target=SubString(StringNum(),dis,dis+1)+target
endif
if(n>='A' and n<='Z')then
set dis=n-'A'
set target=SubString(StringABC(),dis,dis+1)+target
endif
if(n>='a' and n<='z')then
set dis=n-'a'
set target=SubString(Stringabc(),dis,dis+1)+target
endif
set int=int/256
endloop
return target
endfunction
[/codes] |
|