|
本帖最后由 RoyalFlare 于 2015-1-24 12:56 编辑
检查单位可通行状态
- library CheckPathability initializer init
- public function init takes nothing returns nothing
- function CheckPathability takes unit u, real x, real y returns boolean
- local real ox = GetUnitX(u)
- local real oy = GetUnitY(u)
- if x > 9376. or x < -9632. or y > 9376. or y < -9632. then //map bounds
- return false
- endif
- call SetUnitX(u, -9472.) //move unit to safespot
- call SetUnitY(u, 9216.)
- call SetUnitPosition(checkpathabilityunit, x, y) //requires global unit here
- set x = GetUnitX(checkpathabilityunit)-x
- set y = GetUnitY(checkpathabilityunit)-y
- call SetUnitX(checkpathabilityunit, -9472.) //moves global unit back to safespot
- call SetUnitY(checkpathabilityunit, 9216.)
- call SetUnitX(u, ox)
- call SetUnitY(u, oy)
- return x*x+y*y <= 100.
- endfunction
- function CheckPathability_IgnoreUnits takes real x, real y returns boolean
- if x > 9376. or x < -9632. or y > 9376. or y < -9632. then //map bounds
- return false
- endif
- call SetItemPosition(checkpathabilityitem,x,y) //requires global item
- call SetItemVisible(checkpathabilityitem, false)
- set x = GetItemX(checkpathabilityitem)-x
- set y = GetItemY(checkpathabilityitem)-y
- return x*x+y*y <=100
- endfunction
- endfunction
- endlibrary
- //===========================================================================
- function InitTrig_Init takes nothing returns nothing
- endfunction
复制代码 击退主函数
- library Knockback requires CheckPathability
- globals
- // Things to change, !!CHANING THE DUMMY UNIT TO YOURS IS NECESSARY TO WORK!!
- private constant real Interval = 0.3125 // How often the timer will execute
- private constant integer Dummy = 'h000' // Rawcode ID of your dummy unit
- // Change these values to the ones where your unit should slide faster
- // NOTE: If you want any more terrain types added, create a new "private constant integer" named
- // TerrainIdx, replace x with the next number. After that, increase the "TerrainChecks" value by 1.
- private constant integer TerrainId1 = 'Nice' // Northrend Ice
- private constant integer TerrainId2 = 'Idki' // Icecrown Glacies, Dark Ice
- private constant integer TerrainId3 = 'Iice' // Icecrown Glacies, Ice
- private constant integer TerrainId4 = 'Ldrt'
- private constant integer TerrainId5 = 'Ldro'
- private constant integer TerrainId6 = 'Ldrg'
- private constant integer TerrainChecks = 6 // Amount of Terrain Checks which have to be checked
- // Things you mustn't change, necessary for the whole to work
- private timer KnockbackTimer = CreateTimer() // Timer used to move the unit
- private integer array StructArray // Struct array to allow multiple instances
- private integer TotalRunnings = 0 // Integer to show the number of running instances
- endglobals
- public struct Data
- unit KnockbackedUnit // Stores the unit which gets moved
- real MoveAmount // Amount of how many the unit gets moved each time
- real MoveAmountAbstraction // Amount of how many is substraced each time to make the movement slowly stop
- real sin // Stores the sin value of the unit to not need to execute it each time
- real cos // Same as above, only for the cos value
- real Radius // The radius in which units/trees will trigger
- real HitPercentage // The percentage of how fast the unit has to move from its original speed
- boolean UnitCanMove // Boolean to check if the unit gets paused during the whole thing or not
- boolean CheckTerrain // Boolean to check if the terrain should be checked or not
- string MoveEffect = "" // Model Path for the effect which gets created
- static method init takes unit Target, real Distance, real TimeUntilFinish, real Angle, real Radius, real HitPercentage, boolean UnitCanMove, boolean CheckTerrain, string EffectName returns Data
- // Creates the struct
- local Data data = .allocate()
- // Initializes the target as the KnockbackedUnit
- set data.KnockbackedUnit = Target
- // Formula for this. 2 * max distance moved, divided by the number of executions + 1. Simply, huh?
- set data.MoveAmount = 2 * Distance / ( ( TimeUntilFinish / Interval ) + 1 )
- // Formula for the Abtraction. Should be pretty obvious.
- set data.MoveAmountAbstraction = data.MoveAmount / ( TimeUntilFinish / Interval )
- // Sets up the sin and cos.
- set data.sin = Sin(Angle)
- set data.cos = Cos(Angle)
- // Sets up the radius
- set data.Radius = Radius
- // Sets up the percentage
- set data.HitPercentage = data.MoveAmount * HitPercentage
- // Sets up the booleans
- set data.UnitCanMove = UnitCanMove
- set data.CheckTerrain = CheckTerrain
- // Sets up the effect
- set data.MoveEffect = EffectName
- // If the unit shouldn't move, it will be paused. Before that it will be moved to its own position to stop all orders.
- if UnitCanMove then
- call SetUnitPosition ( Target, GetUnitX( Target ), GetUnitY( Target ) )
- call PauseUnit ( Target, true )
- endif
- // If there are no executions yet, the timer will be started.
- if TotalRunnings == 0 then
- call TimerStart ( KnockbackTimer, Interval, true, function Data.move )
- endif
- // Sets up the array for the structstack, and sets the running Knockbacks to one more.
- set StructArray[ TotalRunnings ] = data
- set TotalRunnings = TotalRunnings + 1
- return data
- endmethod
- static method move takes nothing returns nothing
- local Data data
- local integer LoopInteger = 0 // Needed for the structstack
- local real UnitX // X value of the unit, will be changed to get the new unitposition
- local real UnitY // same as above, for the Y value
- local rect CheckRect // Neede to check for the units/trees
- local boolean Pathable // To check if the terrain is pathable or not
- loop
- exitwhen LoopInteger >= TotalRunnings
- // Setup the struct for the usage
- set data = StructArray[ TotalRunnings - 1 ]
- // To not have some problems with the Pathability
- set Pathable = false
- // If theres an special effect specified, there will be one created, otherwise not.
- if data.MoveEffect != "" and data.MoveEffect != null then
- set UnitX = GetUnitX( data.KnockbackedUnit )
- set UnitY = GetUnitY( data.KnockbackedUnit )
- call DestroyEffect ( AddSpecialEffect( data.MoveEffect, UnitX, UnitY ) )
- set UnitX = UnitX + data.MoveAmount * data.cos
- set UnitY = UnitY + data.MoveAmount * data.sin
- else
- // Simple polar projection with X/Y values [ Old X/Y + amount * cos for X and sin for Y ]
- set UnitX = GetUnitX( data.KnockbackedUnit ) + data.MoveAmount * data.cos
- set UnitY = GetUnitY( data.KnockbackedUnit ) + data.MoveAmount * data.sin
- endif
- // Reduce the amount each time
- set data.MoveAmount = data.MoveAmount - data.MoveAmountAbstraction
- // Checks whether the terrain is pathable or not. thx to Vexorian for his function
- set Pathable = CheckPathability( UnitX, UnitY )
- if Pathable then
- call SetUnitX( data.KnockbackedUnit, UnitX )
- call SetUnitY( data.KnockbackedUnit, UnitY )
- endif
- // If the movement is finished (amount <= 0), the struct gets destroyed
- if data.MoveAmount <= 0 or Pathable == false then
- set TotalRunnings = TotalRunnings - 1
- set data = StructArray[ TotalRunnings ]
- call data.destroy()
- endif
- set LoopInteger = LoopInteger + 1
- endloop
- // When there are no knockbacks left, the timer gets paused
- if TotalRunnings == 0 then
- call PauseTimer( KnockbackTimer )
- endif
- endmethod
- method onDestroy takes nothing returns nothing
- // To unpause the unit when it is needed, after the destroy
- if .UnitCanMove == false then
- call PauseUnit( .KnockbackedUnit, false)
- endif
- endmethod
- endstruct
- function Knockback takes unit Target, real Distance, real TimeUntilFinish, real Angle, real Radius, real HitPercentage, boolean UnitCanMove, boolean CheckTerrain, string EffectName returns nothing
- call Data.init( Target, Distance, TimeUntilFinish, Angle, Radius, HitPercentage, UnitCanMove, CheckTerrain, EffectName )
- endfunction
- endlibrary
- //===========================================================================
- function InitTrig_Knockback takes nothing returns nothing
- endfunction
复制代码 最近重建地图的核心代码 用上老外的系统 JassHelper编译的时候提示如下
Line 60: Syntax Error, unexpected: "takes"?
指向这个位置
function CheckPathability takes unit u, real x, real y returns boolean
求各位大神答疑解惑 难道返回的布尔值有问题麽? takes不到数值[bq3]
@希瓦 @chyj4747 @ckpig @zhuzeitou @actboy168
原帖地址在此:
http://www.wc3c.net/showthread.php?t=92525
http://www.wc3c.net/showthread.php?t=93891
原始代码页:
http://peeeq.de/code.php?id=2195 KnockBack System
http://peeeq.de/code.php?id=2202 Library CheckPathability
|
|