|
楼主 |
发表于 2010-6-6 14:35:07
|
显示全部楼层
代码也贴上把,因为是Znic,基本上是接近c语法的,不过那时候我还没接触过c语言,所以缩进的话貌似看起来很不舒服。
[codes=jass]
//! textmacro hash takes Q
integer $Q$hasha[],$Q$hashb[],$Q$hashc[],$Q$hashd[],$Q$hashe=1;
function $Q$_get(integer z)->integer{integer x=$Q$hasha[z-z/8191*8191];
while(x!=0){if($Q$hashd[x]==z)break;x=$Q$hashc[x];}return x;}
function $Q$_sto(integer z)->integer{integer n=z-z/8191*8191,x=$Q$hasha[n],y=x;
while(x!=0){if($Q$hashd[x]==z)return x;x=$Q$hashc[x];}if($Q$hashe<8191)
{x=$Q$hashe;$Q$hasha[n]=x;if(y!=0)$Q$hashb[y]=x;n=$Q$hashc[x];$Q$hashc[x]=y;
$Q$hashd[x]=z;if(n!=0)$Q$hashe=n;else $Q$hashe=x+1;}return x;}
function $Q$_del(integer m){integer x=$Q$hashb[m],y=$Q$hashc[m],n;if(x!=0)
{$Q$hashb[m]=0;$Q$hashc[x]=y;}else{n=$Q$hashd[m];if(n==0)return;n=n-n/8191*8191;
$Q$hasha[n]=y;}if(y!=0)$Q$hashb[y]=x;$Q$hashd[m]=0;$Q$hashc[m]=$Q$hashe;$Q$hashe=m;}
//! endtextmacro
//初始时,要调用下这个 就是用 //runtextmacro SetP()
//! textmacro SetP
globals
player Lp
integer Lpid
player array P
constant group G=CreateGroup()
constant force F=CreateForce()
endglobals
set P[0]=Player(0)
set P[1]=Player(1)
set P[2]=Player(2)
set P[3]=Player(3)
set P[4]=Player(4)
set P[5]=Player(5)
set P[6]=Player(6)
set P[7]=Player(7)
set P[8]=Player(8)
set P[9]=Player(9)
set P[10]=Player(10)
set P[11]=Player(11)
set P[12]=Player(12)
set P[13]=Player(13)
set P[14]=Player(14)
set P[15]=Player(15)
set Lp=GetLocalPlayer()
set Lpid=GetPlayerId(Lp)
call ForceAddPlayer(F,P[0])
//! endtextmacro
//! zinc
library rwshuxing
{
constant integer Maxnum=50;
function H2I(handle h)->integer{return h;return 0;}
//! runtextmacro hash("Unit")
function getunitid(unit u)->integer
{return Unit_sto(H2I(u));}
integer UnitT[],Unitid=1;
public function CreateUnitDataId(unit u)->integer
{
integer x=getunitid(u),y=Unitid;
if(x!=0)
{
if(y<8190-Maxnum)
{
if(UnitData[y]!=0) Unitid=UnitData[y];
else Unitid=y+Maxnum;
UnitT[x]=y;return y;
}
else Unit_del(x);
}
return 0;
}
function GetUnitDataId(unit u)->integer
{return UnitT[Unit_get(H2I(u))];}
function DelUnitDataId(unit u)
{
integer x=Unit_get(H2I(u)),y;
if(x!=0)
{
Unit_del(x);y=UnitT[x];
if(y!=0)
{
UnitData[y]=Unitid;Unitid=y;
}
}
}
//! textmacro UnitSetxx takes xx,id
integer $xx$num=0;function Set$xx$(unit u,integer y){
integer x=y,z=$id$,num=0;while(y>0){y=y/4;
SetUnitAbilityLevel(u,z+num,x-y*4+1);num=num+1;x=y;}if($xx$num<=num)$xx$num=num;
else while(num<$xx$num){SetUnitAbilityLevel(u,z+num,0);num=num+1;}}
//! endtextmacro
//! textmacro UnitSetxx2 takes xx,id
function Set$xx$(unit u,integer x)
{integer y=x,num=$id$;while(x>0){x=x/4;
SetUnitAbilityLevel(u,num,y-x*4+1);UnitRemoveAbility(u,num);
UnitAddAbility(u,num);num=num+1;y=x;}}
//! endtextmacro
//! textmacro ConditionX takes xx
function UnitSet$xx$()->boolean
{unit u=tUnit;integer x;x=UnitData[tId+Unit_$xx$]+tData;UnitData[tId+Unit_$xx$]=x;
if(x>=0){Set$xx$(u,x*(Unit_div+UnitData[tId+Unit_$xx$p])/Unit_div);Set$xx$2(u,0);}else {Set$xx$(u,0);Set$xx$2(u,-x);}
u=null;return true;}
function UnitSet$xx$p()->boolean{unit u=tUnit;integer x,y;
x=UnitData[tId+Unit_$xx$p]+tData;UnitData[tId+Unit_$xx$p]=x;y=UnitData[tId+Unit_$xx$];
if(y>=0){Set$xx$(u,y*(Unit_div+x)/Unit_div);Set$xx$2(u,0);}else {Set$xx$(u,0);Set$xx$2(u,-y);}
u=null;return true;}
//! endtextmacro
unit tUnit;
integer tData,tId;
integer UnitData[];
//设置单位附加的攻击力
//! runtextmacro UnitSetxx("ATK","'+ATa'")
//! runtextmacro UnitSetxx("ATK2","'/ATa'")
//! runtextmacro ConditionX("ATK")
//防御 !!
//! runtextmacro UnitSetxx("DFF","'+DFa'")
//! runtextmacro UnitSetxx("DFF2","'/DFa'")
//! runtextmacro ConditionX("DFF")
//攻击速度 (+- 500)
//! runtextmacro UnitSetxx("ASp","'+As0'")
//! runtextmacro UnitSetxx("ASp2","'/As0'")
function UnitSetASp()->boolean
{
unit u=tUnit;
integer x;
x=UnitData[tId+Unit_ASp]+tData;UnitData[tId+Unit_ASp]=x;
if(x>=0){SetASp(u,x);SetASp2(u,0);}
else {SetASp(u,0);SetASp2(u,-x);}
u=null;return true;
}
//三围 !!
//力量
//! runtextmacro UnitSetxx("LL","'+LLa'")
//! runtextmacro UnitSetxx("LL2","'/LLa'")
//! runtextmacro ConditionX("LL")
//敏捷
//! runtextmacro UnitSetxx("MJ","'+MJa'")
//! runtextmacro UnitSetxx("MJ2","'/MJa'")
//! runtextmacro ConditionX("MJ")
//智慧
//! runtextmacro UnitSetxx("ZH","'+ZHa'")
//! runtextmacro UnitSetxx("ZH2","'/ZHa'")
//! runtextmacro ConditionX("ZH")
function UnitSetSW()->boolean
{
unit u=tUnit;
integer x;
x=UnitData[tId+Unit_LL]+tData;UnitData[tId+Unit_LL]=x;
if(x>=0){SetLL(u,x*(Unit_div+UnitData[tId+Unit_LLp])/Unit_div);SetLL2(u,0);}else {SetLL(u,0);SetLL2(u,-x);}
x=UnitData[tId+Unit_MJ]+tData;UnitData[tId+Unit_MJ]=x;
if(x>=0){SetMJ(u,x*(Unit_div+UnitData[tId+Unit_MJp])/Unit_div);SetMJ2(u,0);}else {SetMJ(u,0);SetMJ2(u,-x);}
x=UnitData[tId+Unit_ZH]+tData;UnitData[tId+Unit_ZH]=x;
if(x>=0){SetZH(u,x*(Unit_div+UnitData[tId+Unit_ZHp])/Unit_div);SetZH2(u,0);}else {SetZH(u,0);SetZH2(u,-x);}
u=null;return true;
}
function UnitSetSWp()->boolean
{
unit u=tUnit;
integer x,y;
x=UnitData[tId+Unit_LLp]+tData;UnitData[tId+Unit_LLp]=x;y=UnitData[tId+Unit_LL];
if(y>=0){SetLL(u,y*(Unit_div+x)/Unit_div);SetLL2(u,0);}else {SetLL(u,0);SetLL2(u,-y);}
x=UnitData[tId+Unit_MJp]+tData;UnitData[tId+Unit_MJp]=x;y=UnitData[tId+Unit_MJ];
if(y>=0){SetMJ(u,y*(Unit_div+x)/Unit_div);SetMJ2(u,0);}else {SetMJ(u,0);SetMJ2(u,-y);}
x=UnitData[tId+Unit_ZHp]+tData;UnitData[tId+Unit_ZHp]=x;y=UnitData[tId+Unit_ZH];
if(y>=0){SetZH(u,y*(Unit_div+x)/Unit_div);SetZH2(u,0);}else {SetZH(u,0);SetZH2(u,-y);}
u=null;return true;
}
//! textmacro ConditionX2 takes xx
function UnitSet$xx$()->boolean
{unit u=tUnit;
integer x,y,z,l;
y=UnitData[tId+Unit_$xx$];x=tData;z=x+y;UnitData[tId+Unit_$xx$]=z;
l=UnitData[tId+Unit_$xx$p];
if(l>=-Unit_div)
{if(z>=0)
{if(y>=0) x=x*(Unit_div+l)/Unit_div;
else x=-y+z*(Unit_div+l)/Unit_div;}
else {if(y>=0) x=z-y*(Unit_div+l)/Unit_div;}}
else
{if(z>=0) {if(y>=0) x=0;else x=-y;}
else {if(y>=0) x=z;}}
if(x>=0) Set$xx$(u,x);else Set$xx$2(u,-x);
return true;}
function UnitSet$xx$p()->boolean
{unit u=tUnit;
integer x,y,z,l,a=-Unit_div;
x=tData,y=UnitData[tId+Unit_$xx$p];z=x+y;UnitData[tId+Unit_$xx$p]=z;l=UnitData[tId+Unit_$xx$];
if(l>=0)
{if(z>=a) {if(y<a) x=z-a;}
else {if(y>=a) x=a-y;else x=0;}
if(x>=0) Set$xx$(u,l*x/Unit_div);else Set$xx$2(u,l*x/a);}
return true;}
//! endtextmacro
//生命上限
//! runtextmacro UnitSetxx2("HP","'+HPa'")
//! runtextmacro UnitSetxx2("HP2","'/HPa'")
//! runtextmacro ConditionX2("HP")
//魔法上限
//! runtextmacro UnitSetxx2("MP","'+MPa'")
//! runtextmacro UnitSetxx2("MP2","'/MPa'")
//! runtextmacro ConditionX2("MP")
//移动速度
function UnitSetWSp()->boolean
{
unit u=tUnit;
integer x;
x=tData+UnitData[tId+Unit_WSp];UnitData[tId+Unit_WSp]=x;x=R2I(GetUnitDefaultMoveSpeed(u))+x;
if(x>=Unit_w_max) x=Unit_w_max;
else {if(x<=Unit_w_min) x=Unit_w_min;}
SetUnitMoveSpeed(u,x);
u=null;return true;
}
//需要传入一个物品,测试用
public function UnitAddCondition(unit u)
{
integer z=1;tId=GetUnitDataId(u);tUnit=u;
while(z<10){
tData=GetRandomInt(0,100);
ForceEnumPlayersCounted(F,zhuce[z],1);
z=z+1;}
}
public function UnitAddConditionByType(unit u,integer data,integer fenlei)
{
tId=GetUnitDataId(u);tUnit=u;tData=data;
ForceEnumPlayersCounted(F,zhuce[fenlei],1);
}
conditionfunc zhuce[];
string zhuces[];
//几率 除数
constant integer Unit_div=100;
//单位移动速度区间
constant integer Unit_w_min=150;
constant integer Unit_w_max=400;
//单位数据对应的地址
//基础属性附加(1-10)(1-6)
constant integer Unit_ATK=1;
constant integer Unit_DFF=2;
constant integer Unit_LL=3;
constant integer Unit_MJ=4;
constant integer Unit_ZH=5;
constant integer Unit_ASp=6;
constant integer Unit_SW=7;
constant integer Unit_HP=8;
constant integer Unit_MP=9;
constant integer Unit_WSp=10;
//基础属性附加百分比(11-18)
constant integer Unit_ATKp=18;
constant integer Unit_DFFp=11;
constant integer Unit_LLp=12;
constant integer Unit_MJp=13;
constant integer Unit_ZHp=14;
constant integer Unit_SWp=15;
constant integer Unit_HPp=16;
constant integer Unit_MPp=17;
function onInit()
{
zhuce[Unit_ATK]=Condition(function UnitSetATK);
zhuce[Unit_ATKp]=Condition(function UnitSetATKp);
zhuce[Unit_DFF]=Condition(function UnitSetDFF);
zhuce[Unit_DFFp]=Condition(function UnitSetDFFp);
zhuce[Unit_LL]=Condition(function UnitSetLL);
zhuce[Unit_LLp]=Condition(function UnitSetLLp);
zhuce[Unit_MJ]=Condition(function UnitSetMJ);
zhuce[Unit_MJp]=Condition(function UnitSetMJp);
zhuce[Unit_ZH]=Condition(function UnitSetZH);
zhuce[Unit_ZHp]=Condition(function UnitSetZHp);
zhuce[Unit_SW]=Condition(function UnitSetSW);
zhuce[Unit_SWp]=Condition(function UnitSetSWp);
zhuce[Unit_ASp]=Condition(function UnitSetASp);
zhuce[Unit_HP]=Condition(function UnitSetHP);
zhuce[Unit_HPp]=Condition(function UnitSetHPp);
zhuce[Unit_MP]=Condition(function UnitSetMP);
zhuce[Unit_MPp]=Condition(function UnitSetMPp);
zhuce[Unit_WSp]=Condition(function UnitSetWSp);
}
}
//! endzinc
[/codes] |
|