- Joined
- Sep 26, 2009
- Messages
- 9,534
I have been working on a system for TacoBell, but at the same time the system is using simple Jass (I encapsulated it with a scope just to contain the variables) and I would like to optimize it as much as possible. Here is the overall process:
1. Slide system detects the lowest point in each units' proximities...
2. If slope is greater than 60 degrees, cause move the unit towards it.
Since I don't know much about structs, really I barely understand the global concept of them (yes I've read through all the tutorials but I don't see why they need to be created/declared as a type... like how does the game even know to interpret all these generated variables?), I think a good place to start learning is from editing my own work. Can you take a look at this and see if it even needs to be contained in a struct?
1. Slide system detects the lowest point in each units' proximities...
2. If slope is greater than 60 degrees, cause move the unit towards it.
Since I don't know much about structs, really I barely understand the global concept of them (yes I've read through all the tutorials but I don't see why they need to be created/declared as a type... like how does the game even know to interpret all these generated variables?), I think a good place to start learning is from editing my own work. Can you take a look at this and see if it even needs to be contained in a struct?
JASS:
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
scope Locator initializer Init
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
globals
private constant group The_Group = CreateGroup()
private constant real SR3 = SquareRoot(3.)
private constant location loc = Location(0.,0.)
private real array cos
private real array sin
endglobals
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
private function Found takes unit u,integer i,real SrcX,real SrcY,real SrcZ returns boolean
local real To_X = SrcX + cos[i]
local real To_Y = SrcY + sin[i]
local real To_Z = GetLocationZ(loc)
loop
exitwhen (i == 0)
set i = i - 1
call MoveLocation(loc,SrcX + cos[i],SrcY + sin[i])
if (GetLocationZ(loc) < To_Z) then
set To_X = SrcX + cos[i]
set To_Y = SrcY + sin[i]
set To_Z = GetLocationZ(loc)
endif
endloop
if (SrcZ - To_Z >= SR3) then
call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl",SrcX,SrcY))
call SetUnitX(u,To_X)
call SetUnitY(u,To_Y)
endif
return true
endfunction
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
private function DoEval takes unit u returns nothing
local integer i = 23
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real z
call MoveLocation(loc,x,y)
set z = GetLocationZ(loc)
loop
call MoveLocation(loc,x + cos[i],y + sin[i])
if (GetLocationZ(loc) < z) then
exitwhen (Found(u,i,x,y,z))
endif
exitwhen (i == 0)
set i = i - 1
endloop
endfunction
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
private function Pick takes nothing returns nothing
call DoEval(GetEnumUnit())
endfunction
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
private function Slide takes nothing returns nothing
call ForGroup(The_Group,function Pick)
endfunction
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
private function Init takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
loop
set cos[i] = 3.*Cos(15*(i+1)*bj_DEGTORAD)
set sin[i] = 3.*Sin(15*(i+1)*bj_DEGTORAD)
set i = i + 1
exitwhen (i > 23)
endloop
call TriggerAddAction(t,function Slide)
call TriggerRegisterTimerEvent(t,0.03,true)
call GroupEnumUnitsInRect(The_Group,bj_mapInitialPlayableArea,null)
endfunction
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
endscope
//ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Last edited: