- Joined
- Sep 26, 2009
- Messages
- 9,492
Time for some tests then.
library SphericalProjection /* v1.0.0.1
*************************************************************************************
*
* */uses/*
*
* */ AutoFly /* hiveworkshop.com/forums/submissions-414/autofly-unitindexer-version-195563/
*
************************************************************************************
*
* function SphericalProjection takes real x, real y, real z, real facing, verticalFacing, unit whichUnit, real distance, real theta, real phi returns nothing
* - x,y,z,facing,verticalFacing source position. Vertical facing is z facing of unit, normally 0.
* - whichUnit unit to project
* - distance distance from position
* - theta x,y angle, 0 radians would be directly in front
* - phi z angle, 0 radians would be flat, pi/2 directly above,
* - -pi/2 directly below
*
************************************************************************************/
function SphericalProjection takes real x, real y, real z, real f, real vf, unit u, real d, real t, real p returns nothing
set t=t+f
set f=d*Sin(p+vf)
call SetUnitX(u,Cos(t)*f)
call SetUnitY(u,Sin(t)*f)
call SetUnitFlyHeight(u,d*Cos(p+vf),10000)
endfunction
endlibrary
function SphericalProjection takes real x, real y, real z, real f, real vf, unit u, real d, real t, real p returns nothing
local real pvf = Sin(p+vf)
call SetUnitX(u, d*Cos(t+f)*pvf)
call SetUnitY(u, d*Sin(t+f)*pvf)
call SetUnitZ(u, d*pvf)
endfunction
function SphericalProjection takes real x, real y, real z, real f, real vf, unit u, real d, real t, real p returns nothing
set t = t + f
set d = d*Sin(p+vf)
call SetUnitX(u, d*Cos(t))
call SetUnitY(u, d*Sin(t))
call SetUnitZ(u, d)
endfunction
/*******************************************
* Clock
* v1.0.0.0
* Magtheridon96
*
* - A clock system that stores hours, minutes and seconds.
*
* API:
* ----
*
* - function GetGameSeconds takes nothing returns integer
* - function GetGameMinutes takes nothing returns integer
* - function GetGameHours takes nothing returns integer
*
* - function GetGameTimeString takes nothing returns string
* - Returns the game-time string formatted: HH:MM:SS
*
*******************************************/
library Clock
private struct Clock extends array
static integer hours = 0
static integer minutes = 0
static integer seconds = 0
static method buffer takes nothing returns nothing
set seconds = seconds + 1
if seconds == 60 then
set seconds = 0
set minutes = minutes + 1
if minutes == 60
set minutes = 0
set hours = hours + 1
endif
endif
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), 1, true, function thistype.buffer)
endmethod
endstruct
function GetGameSeconds takes nothing returns integer
return Clock.seconds
endfunction
function GetGameMinutes takes nothing returns integer
return Clock.minutes
endfunction
function GetGameHours takes nothing returns integer
return Clock.hours
endfunction
function GetGameTimeString takes nothing returns string
local string t = I2S(Clock.seconds)
if Clock.seconds <= 9 then
set t = "0" + t
endif
set t = I2S(Clock.minutes) + ":" + t
if Clock.minutes <= 9 then
set t = "0" + t
endif
set t = I2S(Clock.hours) + ":" + t
if Clock.hours <= 9 then
set t = "0" + t
endif
return t
endfunction
endlibrary
function AddCommas takes integer i returns string
local string read = I2S(i)
local string val = ""
local integer pos = StringLength(read)
loop
set pos = pos - 3
if pos < 0 then
set val = SubString(read, 0, pos + 3) + val
exitwhen true
endif
set val = "," + SubString(read, pos, pos + 3) + val
endloop
if SubString(val, 0, 1) == "," then
return SubString(val, 1, StringLength(val))
elseif SubString(val, 0, 2) == "-," then
return "-" + SubString(val, 2, StringLength(val))
endif
return val
endfunction
function AddCommas takes integer n returns string
local integer m = 0
local string s = ""
local boolean b = false
if (n < 0) then
set n = -n
set b = true
endif
loop
exitwhen n == 0
if (m > 0) then
set s = "," + s
endif
set m = n
set n = n/1000
set m = m-n*1000
if (n > 0) then
if (m < 10) then
set s = "00" + I2S(m) + s
elseif (m < 100) then
set s = "0" + I2S(m) + s
else
set s = I2S(m) + s
endif
set m = 1
else
set s = I2S(m) + s
set m = 0
endif
endloop
if (s == "") then
return "0"
endif
if (b) then
set s = "-" + s
endif
return s
endfunction
function AddCommas takes integer n returns string
local integer m = 0
local string s = ""
local boolean b = false
if (n < 0) then
set n = -n
set b = true
endif
loop
exitwhen n == 0
if (m > 0) then
set s = "," + s
endif
set m = n
set n = n/1000
set m = m-n*1000
if (n > 0) then
if (m < 10) then
set s = "00" + I2S(m) + s
elseif (m < 100) then
set s = "0" + I2S(m) + s
else
set s = I2S(m) + s
endif
else
set s = I2S(m) + s
endif
endloop
if (s == "") then
return "0"
endif
if (b) then
set s = "-" + s
endif
return s
endfunction
You can't use it to optimize the map's script since a good portion of maps can't use it to optimize their scripts >.>.
It'd be a pretty fail test since it wouldn't be the case in an actual map =P.
Just make ur var names 1 char each =D
globals
integer loopint = 0
endglobals
function AddCommas takes integer i returns string
local string r = I2S(i)
local string s = ""
local integer p = StringLength(r)
loop
set p = p - 3
if p < 0 then
set s = SubString(r, 0, p + 3) + s
if SubString(s, 0, 1) == "," then
return SubString(s, 1, StringLength(s))
elseif SubString(s, 0, 2) == "-," then
return "-" + SubString(s, 2, StringLength(s))
endif
return s
endif
set s = "," + SubString(r, p, p + 3) + s
endloop
return "" //Parser thinks a return is missing -_-
endfunction
/*
function AddCommas takes integer n returns string
local integer m = 0
local string s = ""
local boolean b = false
if (n < 0) then
set n = -n
set b = true
endif
loop
exitwhen n == 0
if (m > 0) then
set s = "," + s
endif
set m = n
set n = n/1000
set m = m-n*1000
if (n > 0) then
if (m < 10) then
set s = "00" + I2S(m) + s
elseif (m < 100) then
set s = "0" + I2S(m) + s
else
set s = I2S(m) + s
endif
else
set s = I2S(m) + s
endif
endloop
if (s == "") then
return "0"
endif
if (b) then
set s = "-" + s
endif
return s
endfunction
*/
function go takes nothing returns nothing
local integer i = 200
loop
call AddCommas(-1000000000)
set i = i - 1
exitwhen i == 0
endloop
set loopint = loopint + 1
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0,0,60,I2S(loopint))
if loopint == 32 then
set loopint = 0
endif
endfunction
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
call TimerStart(CreateTimer(), 0.03125, true, function go)
endfunction
And what if you increase it in each loop iteration instead of keeping a constant value ?
(this way the string functions won't use the same string stored in the string table, so it would be slower)
function AddCommas takes integer n returns string
local integer m = 0
local string s = ""
local boolean b = false
if (n == 0) then
return "0"
elseif (n < 0) then
set n = -n
set b = true
endif
loop
set m = n
set n = n/1000
set m = m-n*1000
if (n > 0) then
if (m < 10) then
set s = ",00" + I2S(m) + s
elseif (m < 100) then
set s = ",0" + I2S(m) + s
else
set s = "," + I2S(m) + s
endif
elseif (b) then
return "-" + I2S(m) + s
else
return I2S(m) + s
endif
endloop
return ""
endfunction
Why is WarCraft III still caching strings to that table when it's 100% useless now?
It was possible to get a unique value from a string - you now must rely on the much slower StringHash native.
but anyway, it could be useful to
SOMEONE =P
[...]and also convert locals variables in globals[...]
function subtractVectorAngleX takes real ax, real ay, real bx, real by, real a returns real
return ax/a*bx + ay/a*by
endfunction
function subtractVectorAngleY takes real ax, real ay, real bx, real by, real a returns real
return ay/a*bx - ax/a*by
endfunction
function addVectorAngleX takes real ax, real ay, real bx, real by, real a returns real
return ax/a*bx - ay/a*by
endfunction
function addVectorAngleY takes real ax, real ay, real bx, real by, real a returns real
return ay/a*bx + ax/a*by
endfunction
MAX_COORD = 32556
MIN_COORD = -32556
MAX_RANGE = 92083
MAX_COORD = 32556
MIN_COORD = -32556
MAX_RANGE = 92083
library Constants
globals
real MAX_COORD = 32556.
real MIN_COORD = -MAX_COORD
real MAX_RANGE = 92083.
endglobals
endlibrary
library Players
globals
player array PLAYER
endglobals
private module Init
private static method onInit takes nothing returns nothing
local integer i = 0
loop
exitwhen i > 15
set PLAYER[i] = Player(i)
set i = i + 1
endloop
endmethod
endmodule
private struct Inits
implement Init
endstruct
endlibrary
library Clipboard
private module Init
private static method onInit takes nothing returns nothing
set Clipboard.i = 0
set Clipboard.s = ""
set Clipboard.b = false
set Clipboard.r = 0.0
endmethod
endmodule
struct Clipboard extends array
static integer i
static string s
static boolean b
static real r
static method copyI takes integer d returns nothing
set thistype.i = d
endmethod
static method pasteI takes nothing returns integer
return thistype.i
endmethod
static method copyS takes string d returns nothing
set thistype.s = d
endmethod
static method pasteS takes nothing returns string
return thistype.s
endmethod
static method copyB takes boolean d returns nothing
set thistype.b = d
endmethod
static method pasteB takes nothing returns boolean
return thistype.b
endmethod
static method copyR takes real d returns nothing
set thistype.r = d
endmethod
static method pasteR takes nothing returns real
return thistype.r
endmethod
implement Init
endstruct
endlibrary
@xD.Schurke
Yeah, but it's better to use MAX_RANGE for ... senseless reasons
MAX_COORD and MIN_COORD are VERY useful (That way you don't have to call WorldBounds() that often anymore :])
library Powers
function isPowerX takes real i, integer j returns boolean
loop
exitwhen i<j
set i=i/j
endloop
return i==1.0
endfunction
// wrappers
function isSquare takes real i returns boolean
return isPowerX(i,2)
endfunction
function isCube takes real i returns boolean
return isPowerX(i,3)
endfunction
endlibrary
ModuloInteger
.struct integer:
boolean isPowerX(integer i): return this.mod(i) == 0
boolean isSquare(): return this.mod(2) == 0
boolean isCube(): return this.mod(3) == 0
I knew itI think that's a fine example of why evaluating submissions should be illegal for me in the mornings -_-
function isDivisible takes integer i, integer j returns boolean
local integer m=i-(i/j)*j
if m<0 then
return m+j==0
endif
return m==0
endfunction
If I remember correctly,JASS:library SphericalProjection /* v1.0.0.1 ************************************************************************************* * * */uses/* * * */ AutoFly /* hiveworkshop.com/forums/submissions-414/autofly-unitindexer-version-195563/ * ************************************************************************************ * * function SphericalProjection takes real x, real y, real z, real facing, verticalFacing, unit whichUnit, real distance, real theta, real phi returns nothing * - x,y,z,facing,verticalFacing source position. Vertical facing is z facing of unit, normally 0. * - whichUnit unit to project * - distance distance from position * - theta x,y angle, 0 radians would be directly in front * - phi z angle, 0 radians would be flat, pi/2 directly above, * - -pi/2 directly below * ************************************************************************************/ function SphericalProjection takes real x, real y, real z, real f, real vf, unit u, real d, real t, real p returns nothing set t=t+f set f=d*Sin(p+vf) call SetUnitX(u,Cos(t)*f) call SetUnitY(u,Sin(t)*f) call SetUnitFlyHeight(u,d*Cos(p+vf),10000) endfunction endlibrary
SetUnitFlyHeight(u,d*Cos(p+vf),0)
is equivalent to call SetUnitFlyHeight(u,d*Cos(p+vf),<some arbitrarily high number>)