|
楼主 |
发表于 2009-3-3 21:37:17
|
显示全部楼层
RCCS v W
[jass]
constant function H2I takes handle h returns integer
return h
return 0
endfunction
constant function B2I takes boolean b returns integer
if(b)then
return 1
endif
return 0
endfunction
function GetItemSlot takes unit hero, item it returns integer
local integer i=0
loop
exitwhen i==6
if(UnitItemInSlot(hero,i)==it)then
return i
endif
set i=i+1
endloop
return -1
endfunction
function SimError takes player ForPlayer, string msg returns nothing
local sound error=CreateSoundFromLabel( "InterfaceError",false,false,false,10,10)
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
call StartSound( error )
call DisplayTimedTextToPlayer( ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r" )
endif
call KillSoundWhenDone(error)
set error=null
endfunction
function AbilityGetMaxLevel takes integer abil returns integer
local unit hero
local integer max=GetStoredInteger(objects(),I2S(abil),"m_maxlvl")
if(abil==0)then
return 0
endif
if(max==0)then
set hero=CreateUnit(Player(15),'hfoo',0,0,0)
call UnitAddAbility(hero,abil)
call SetUnitAbilityLevel(hero,abil,100)
set max=GetUnitAbilityLevel(hero,abil)
call StoreInteger(objects(),I2S(abil),"m_maxlvl",max)
call RemoveUnit(hero)
set hero=null
endif
return max
endfunction
function Vector_size takes string vector returns integer
return GetStoredInteger(objects(),vector,"m_size")
endfunction
function Vector_getElem takes string vector,integer index returns integer
return GetStoredInteger(objects(),vector,"m_a"+I2S(index))
endfunction
function Vector_setElem takes string vector,integer index, integer data returns boolean
if(index<0 or index>=Vector_size(vector))then
return false
endif
call StoreInteger(objects(),vector,"m_a"+I2S(index),data)
return true
endfunction
function Vector_addElem takes string vector, integer data returns boolean
local gamecache gc=objects()
local integer size=Vector_size(vector)
call StoreInteger(gc,vector,"m_a"+I2S(size),data)
call StoreInteger(gc,vector,"m_size",size+1)
return true
endfunction
function Vector_removeElem takes string vector, integer index returns integer
local integer size=Vector_size(vector)-1
local gamecache gc=objects()
local integer val=GetStoredInteger(gc,vector,"m_a"+I2S(index))
local integer i=index
if(index<=size and index>=0)then
loop
exitwhen i==size
call StoreInteger(gc,vector,"m_a"+I2S(i),GetStoredInteger(gc,vector,"m_a"+I2S(i+1)))
set i=i+1
endloop
call StoreInteger(gc,vector,"m_size",size)
call StoreInteger(gc,vector,"m_a"+I2S(size),0) //reset it to zero
endif
set gc=null
return val
endfunction
function Vector_swapElems takes string vector, integer x,integer y returns nothing
local integer i=Vector_getElem(vector,x)
call Vector_setElem(vector,x,Vector_getElem(vector,y))
call Vector_setElem(vector,y,i)
endfunction
function GetUniqueId takes nothing returns integer
local gamecache gc=null
local integer last=0
local integer size=Vector_size("0")
set gc=objects()
if(size!=0)then
return Vector_removeElem("0",size-1)
endif
set last=GetStoredInteger(gc,"index","index")+1
call StoreInteger(gc,"Index","index",last)
set gc=null
return last
endfunction
function DestroyObject takes string object returns nothing
call FlushStoredMission(objects(),object)
endfunction
function RecycleObject takes string object returns nothing
if(object=="0")then
return
endif
call Vector_addElem("0",S2I(object)) //recycle object type.
call DestroyObject(object)
endfunction
function CreateVector takes nothing returns string
return I2S(GetUniqueId())
endfunction
//==================================================================
function Node_setData takes string node,integer data returns nothing
local gamecache gc=objects()
call StoreInteger(gc,node,"M_data",data)
set gc=null
endfunction
function Node_setNext takes string node,string next returns nothing
local gamecache gc=objects()
call StoreString(gc,node,"m_next",next)
set gc=null
endfunction
function Node_setPred takes string node,string pred returns nothing
local gamecache gc=objects()
call StoreString(gc,node,"m_pred",pred)
set gc=null
endfunction
function Node_getData takes string node returns integer
local gamecache gc=objects()
local integer data=GetStoredInteger(gc,node,"m_data")
set gc=null
return data
endfunction
function Node_getNext takes string node returns string
local gamecache gc=objects()
local string next=GetStoredString(gc,node,"m_next")
set gc=null
return next
endfunction
function Node_getPred takes string node returns string
local gamecache gc=objects()
local string pred=GetStoredString(gc,node,"m_pred")
set gc=null
return pred
endfunction
function CreateNode takes integer data,string next,string pred returns string
local string this=I2S(GetUniqueId())
local gamecache gc=objects()
call StoreInteger(gc,this,"m_data",data)
if (next=="this")then
set next=this
endif
call StoreString(gc,this,"m_next",next)
if(pred=="this")then
set pred=this
endif
call StoreString(gc,this,"m_pred",pred)
set gc=null
return this
endfunction
function Queue_getTail takes string q returns string
local gamecache gc=objects()
local string t=GetStoredString(gc,q,"m_tail")
set gc=null
return t
endfunction
function Queue_getLength takes string q returns integer
local gamecache gc=objects()
local integer l=GetStoredInteger(gc,q,"m_length")
set gc=null
return l
endfunction
function Queue_getSize takes string q returns integer
local gamecache gc=objects()
local integer s=GetStoredInteger(gc,q,"m_size")
set gc=null
return s
endfunction
//Will only return the falling off tail's data field.
function Queue_Enqueue takes string q,integer data returns integer
local gamecache gc=objects()
local string tail=Queue_getTail(q)
local string head=null
local string pred=null
local string new=null
local integer size=Queue_getSize(q)
local integer length=Queue_getLength(q)
local integer ret=0
if(tail==null)then //0 element q
set new=CreateNode(data,"this","this")
call StoreString(gc,q,"m_tail",new)
call StoreInteger(gc,q,"m_size",1)
elseif(size!=length)then
set head=Node_getNext(tail)
set new=CreateNode(data,head,tail)
call Node_setNext(tail,new)
call Node_setPred(head,new)
call StoreInteger(gc,q,"m_size",size+1)
else
set head=Node_getNext(tail)
set pred=Node_getPred(tail)
set new=CreateNode(data,head,pred)
call Node_setPred(head,new)
call Node_setNext(pred,new)
call StoreString(gc,q,"m_tail",pred)
set ret=Node_getData(tail)
call RecycleObject(tail)
endif
return ret
endfunction
function Queue_Dequeue takes string q returns integer
local gamecache gc=objects()
local string tail=Queue_getTail(q)
local string head=null
local string pred=null
local integer ret
if(tail==null)then
set ret=-1
elseif(Queue_getSize(q)==1)then //this queue has one elem
call StoreInteger(gc,q,"m_size",0)
set ret=Node_getData(tail)
call RecycleObject(tail)
call StoreString(gc,q,"m_tail",null)
else
set head=Node_getNext(tail)
set pred=Node_getPred(tail)
call StoreInteger(gc,q,"m_size",Queue_getSize(q)-1)
set ret=Node_getData(tail)
call Node_setNext(pred,head)
call Node_setPred(head,pred)
call RecycleObject(tail)
call StoreString(gc,q,"m_tail",pred)
endif
return ret
endfunction
//length must be at least two.
function CreateQueue takes integer length returns string
local string this=I2S(GetUniqueId())
local gamecache gc=objects()
call StoreInteger(gc,this,"m_length",length)
call StoreInteger(gc,this,"m_size",0)
set gc=null
return this
endfunction
//==============================================================
function IV_capacity takes string iv returns integer
return GetStoredInteger(objects(),iv,"m_capacity")
endfunction
function IV_getItem takes string iv,integer ix returns item
return Vector_getElem(iv,ix)
return null
endfunction
function IV_setItem takes string iv,integer ix,item it returns nothing
call Vector_setElem(iv,ix,H2I(it))
endfunction
function IV_getIndexOfItem takes string iv,item it returns integer
local integer i=0
local integer end=Vector_size(iv)
local integer target=H2I(it)
loop
exitwhen i==end
if(Vector_getElem(iv,i)==target)then
return i
endif
set i=i+1
endloop
return -1
endfunction
function IV_addItem takes string iv,item it returns boolean
if(IV_capacity(iv)==0)then
return Vector_addElem(iv,H2I(it))
elseif(IV_capacity(iv)==Vector_size(iv))then
return false
else
return Vector_addElem(iv,H2I(it))
endif
endfunction
function IV_removeItemByIx takes string iv,integer ix returns item
return Vector_removeElem(iv,ix)
return null
endfunction
function IV_removeItem takes string iv,item toRemove returns boolean
return IV_removeItemByIx(iv,IV_getIndexOfItem(iv,toRemove))!=null
endfunction
function PrintIV takes string iv returns nothing
local integer i=0
local integer size=Vector_size(iv)
loop
exitwhen i==size
call BJDebugMsg(GetItemName(IV_getItem(iv,i)))
set i=i+1
endloop
endfunction
function CreateIV takes integer capacity returns string
local string this=CreateVector()
call StoreInteger(objects(),this,"m_capacity",capacity)
return this
endfunction
//=========================================================================
function Hero_getState takes unit hero returns integer
return GetStoredInteger(objects(),I2S(H2I(hero)),"m_state")
endfunction
function Hero_setState takes unit hero,integer state returns nothing
call StoreInteger(objects(),I2S(H2I(hero)),"m_state",state)
endfunction
function Hero_getNext takes unit hero returns item
return GetStoredInteger(objects(),I2S(H2I(hero)),"m_next")
return null
endfunction
function Hero_getCancel takes unit hero returns item
return GetStoredInteger(objects(),I2S(H2I(hero)),"m_cancel")
return null
endfunction
function Hero_BlankIV takes unit hero returns string
return GetStoredString(objects(),I2S(H2I(hero)),"m_biv")
endfunction
function Hero_IV takes unit hero returns string
return GetStoredString(objects(),I2S(H2I(hero)),"m_iv")
endfunction
function Hero_getFree takes unit hero returns integer
return GetStoredInteger(objects(),I2S(H2I(hero)),"m_free")
endfunction
function Hero_setFree takes unit hero,integer free returns nothing
call StoreInteger(objects(),I2S(H2I(hero)),"M_free",free)
endfunction
function Hero_addToIV takes unit hero,item toAdd returns boolean
local string iv=Hero_IV(hero)
local integer i=0
local integer free=Hero_getFree(hero)
if(free==0)then
return false
else
loop
exitwhen i==6
if(IV_getItem(iv,i)==null)then
call UnitRemoveItem(hero,toAdd)
call SetItemVisible(toAdd,false)
call IV_setItem(iv,i,toAdd)
call Hero_setFree(hero,free-1)
set i=5
endif
set i=i+1
endloop
return true
endif
endfunction
function Hero_removeBlanks takes unit hero returns nothing
local integer i=0
local integer state=Hero_getState(hero)
local item temp=null
call Hero_setState(hero,74)
loop
exitwhen i==6
set temp=UnitItemInSlot(hero,i)
if(GetItemTypeId(temp)==IDBlank())then
call UnitRemoveItem(hero,temp)
call SetItemVisible(temp,false)
endif
set i=i+1
endloop
call Hero_setState(hero,state)
set temp=null
endfunction
function Hero_clearInv takes unit hero returns nothing
local integer i=0
local integer state=Hero_getState(hero)
call Hero_setState(hero,74) //prevents drop from firing.
loop
exitwhen i==6
call SetItemVisible(UnitRemoveItemFromSlot(hero,i),false)
set i=i+1
endloop
call Hero_setState(hero,state)
endfunction
function Hero_swapInv takes unit hero returns nothing
local integer i=0
local item toIV=null
local item toH=null
local string hiv=Hero_IV(hero)
local string biv=Hero_BlankIV(hero)
local integer state=Hero_getState(hero)
local integer free=0
call Hero_setState(hero,74) //prevents drop from firing.
call StoreInteger(objects(),I2S(H2I(hero)),"m_used",UnitInventoryCount(hero))
loop
exitwhen i==6
set toIV=UnitRemoveItemFromSlot(hero,i)
if(toIV==null)then
set free=free+1
endif
set toH=IV_getItem(hiv,i)
if(toH==null)then
set toH=IV_getItem(biv,i)
endif
call SetItemVisible(toIV,false)
call SetItemVisible(toH,true)
call IV_setItem(hiv,i,toIV)
call UnitAddItem(hero,toH)
set i=i+1
endloop
set i=0
call Hero_setFree(hero,free)
call Hero_removeBlanks(hero)
call Hero_setState(hero,state)
set toIV=null
set toH=null
endfunction
//assumes passed an empty INVed hero
// Returns the current Page indexed.
function Hero_nextPage takes unit hero,string iv,integer page,boolean droppable returns integer
local integer i=0
local integer limit=Vector_size(iv)
local item temp=null
set page=page+1
if( ((page-1)*4)>=limit)then
set page=1
endif
loop
exitwhen i==4
set temp=IV_getItem(iv,(page-1)*4+i)
if(temp==null)then
set temp=IV_getItem(Hero_BlankIV(hero),i )
endif
call SetItemVisible(temp,true)
call UnitAddItem(hero,temp)
set i=i+1
endloop
set temp=Hero_getNext(hero)
call SetItemVisible(temp,true)
call SetItemCharges(temp,page)
call UnitAddItem(hero,temp)
set temp=Hero_getCancel(hero)
call UnitAddItem(hero,temp)
call SetItemVisible(temp,true)
call SetItemDroppable(temp,droppable)
return page
endfunction
//===========================================================================
// Constructor:
// ===========
// There is only one constructor for hero.
// CreateHero(unit hero) turns the unit in to a Hero object. It also creates
// the internal iv and explicitly sets it size to 6.
//===========================================================================
function CreateHero takes unit hero returns unit
local gamecache gc=objects()
local string this=I2S(H2I(hero))
local string iv=CreateIV(6)
local string biv=CreateIV(6)
local integer i=0
local item temp=null
call StoreString(gc,this,"m_IV",iv)
call StoreString(gc,this,"m_BIV",biv)
loop
exitwhen i==6
set temp=CreateItem(IDBlank(),0,0)
call IV_addItem(biv,temp)
call SetItemVisible(temp,false)
set i=i+1
endloop
set temp=CreateItem(IDCancel(),0,0)
call SetItemVisible(temp,false)
call StoreInteger(gc,this,"m_cancel",H2I(temp))
set temp=CreateItem(IDNext(),0,0)
call SetItemVisible(temp,false)
call StoreInteger(gc,this,"m_next",H2I(temp))
call StoreInteger(gc,iv,"m_size",6)
set gc=null
set temp=null
return hero
endfunction
function T_getHero takes timer t returns unit
return GetStoredInteger(objects(),I2S(H2I(t)),"m_hero")
return null
endfunction
function T_getItem takes timer t returns item
return GetStoredInteger(objects(),I2S(H2I(t)),"m_item")
return null
endfunction
function T_getItem2 takes timer t returns item
return GetStoredInteger(objects(),I2S(H2I(t)),"m_item2")
return null
endfunction
function reAdd_child takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit hero=T_getHero(t)
local item bag=T_getItem(t)
call UnitAddItem(hero,bag)
call FlushStoredMission(objects(),I2S(H2I(t)))
call DestroyTimer(t)
set t=null
set hero=null
set bag=null
endfunction
function reAddItem takes unit hero,item it returns nothing
local timer t=CreateTimer()
local gamecache gc=objects()
call StoreInteger(objects(),I2S(H2I(t)),"m_hero",H2I(hero))
call StoreInteger(objects(),I2S(H2I(t)),"m_item",H2I(it))
call TimerStart(t,0,false,function reAdd_child)
set t=null
set gc=null
endfunction
function Tro_Child takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit hero=T_getHero(t)
call IssueImmediateOrder(hero,"replenishon")
call IssueImmediateOrder(hero,"replenishlifeoff")
call DestroyObject(I2S(H2I(t)))
call DestroyTimer(t)
set t=null
set hero=null
endfunction
function TRO takes unit hero returns nothing
local timer t=CreateTimer()
call StoreInteger(objects(),I2S(H2I(t)),"m_hero",H2I(hero))
call TimerStart(t,0,false,function Tro_Child)
endfunction
function GetItemCostById_Hero takes nothing returns unit
return GetStoredInteger(objects(),"rccs","m_hero")
return null
endfunction
function GetItemCostById_Shop takes nothing returns unit
return GetStoredInteger(objects(),"rccs","m_shop")
return null
endfunction
function GetItemCostById takes integer id,boolean whichtype,integer charges returns integer
local unit h
local unit s
local player p
local gamecache gc=objects()
local string t=I2S(id)
local integer gold=GetStoredInteger(gc,t,"m_gold")
local integer lumber=GetStoredInteger(gc,t,"m_lumber")
local integer def=GetStoredInteger(gc,t,"m_def")
local item it=null
if(not (gold==0 and lumber==0))then
set gc=null
if(def==0 or charges==0)then
set charges=1
set def=charges
endif
return charges/def*( B2I(whichtype)*gold+B2I(not whichtype)*lumber)
endif
set h=GetItemCostById_Hero()
set s=GetItemCostById_Shop()
set p=GetItemCostById_DummyPlayer()
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,50000)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,50000)
call AddItemToStock(s,id,1,1)
call IssueTargetOrder(s,"neutralinteract",h)
call IssueNeutralImmediateOrderById(p,s,id)
set it= UnitRemoveItemFromSlot(h,0)
set def=GetItemCharges(it)
call StoreInteger(gc,t,"m_def",def)
call RemoveItemFromStock(s,id)
call RemoveItem(it)
set gold=50000-GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)
set lumber=50000-GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)
call StoreInteger(gc,t,"m_gold",gold)
call StoreInteger(gc,t,"m_lumber",lumber)
set h=null
set s=null
set gc=null
set p=null
set it=null
if(def==0 or charges==0)then
set charges=1
set def=charges
endif
return charges/def*(B2I(whichtype)*gold+B2I(not whichtype)*lumber)
endfunction
function Bounty takes player whichplayer, integer bounty, real x, real y returns nothing
local texttag t=CreateTextTag()
local string s="+"
local sound error=CreateSound( "Abilities\\\\Spells\\\\Items\\\\ResourceItems\\\\ReceiveGold.wav", false, true, true, 10, 10, "SpellsEAX" )
if bounty<0 then
set s=""
endif
call SetTextTagText(t,s+I2S(bounty),0.025)
call SetTextTagPos(t,x,y, 0.00)
call SetTextTagColor(t,255,220,0,255)
call SetTextTagVelocity(t,0,0.03)
if (GetLocalPlayer()==whichplayer) then
call SetTextTagVisibility(t,true)
call SetSoundPosition(error,x,y,0)
call SetSoundVolume(error,127)
call StartSound( error )
set s="UI\\\\Feedback\\\\GoldCredit\\\\GoldCredit.mdl"
else
call SetTextTagVisibility(t,false)
set s=""
endif
call KillSoundWhenDone(error)
call DestroyEffect(AddSpecialEffect(s,x,y))
call SetTextTagFadepoint(t,2)
call SetTextTagLifespan(t,3)
call SetTextTagPermanent(t,false)
set error=null
set t=null
endfunction
function InitTrig_RCCS_v_W takes nothing returns nothing
local unit h=CreateUnit(GetItemCostById_DummyPlayer(),GetItemCostById_BuyerTypeId(),0,0,0)
local unit s=CreateUnit(GetItemCostById_DummyPlayer(),GetItemCostById_ShopTypeId(),0,0,0)
local gamecache gc=objects()
local rect r=GetWorldBounds()
call SetUnitX(h,GetRectMaxX(r)-10)
call SetUnitX(s,GetRectMaxX(r))
call SetUnitY(h,GetRectMaxY(r)-10)
call SetUnitY(s,GetRectMaxY(r))
call StoreInteger(gc,"rccs","m_hero",H2I(h))
call StoreInteger(gc,"rccs","m_shop",H2I(s))
call UnitAddAbility(s,'Asid')
call UnitAddAbility(s,'Aneu')
call UnitAddAbility(s,'Apit')
call UnitAddAbility(s,'Avul')
call UnitRemoveAbility(s,'Awan')
call UnitAddAbility(s,'Aloc')
call RemoveRect(r)
set h=null
set s=null
set gc=null
set r=null
endfunction
[/jass] |
|