- Joined
- Nov 22, 2006
- Messages
- 1,260
Wait, so "f" is that facing angle and "a" determines how wide the cone is?
Wait, so "f" is that facing angle and "a" determines how wide the cone is?
Nice. What about a 3D version?
But it would be much easier to use and slightly quicker if you made that in just one function. You might as well do it (if it's like you say it wouldn't exactly be hard or time-consuming).
Main problem with that being 2 Cos calls and the angle limitation for a (0-pi/4). I had posted a similiar script that used an angle instead of the coordinates, but covered all angles. It's somewhere in this thread...
The cone angle is just 2 times the angle you insert in.
globals
private constant location l = Location(0., 0.)
private constant location l2 = Location(0., 0.)
private constant real SR = 1.//The accuracy. Higher values means less accuracy and setting it to 0 will make the function fail.
endglobals
struct vector
real xvel
real yvel
real zvel
static method GetBounceVector takes real x, real y, real xvel, real yvel, real zvel, real re returns vector
local real vx
local real vy
local real vz
local real px
local real py
local real pz
local vector v = vector.allocate()
call MoveLocation(l, x-SR, y)
call MoveLocation(l2, x+SR, y)
set vx = GetLocationZ(l) - GetLocationZ(l2)
call MoveLocation(l, x, y-SR)
call MoveLocation(l2, x, y+SR)
set vy = GetLocationZ(l) - GetLocationZ(l2)
set vz = (xvel*vx + yvel*vy + zvel*SR)/(vx*vx + vy*vy + SR*SR)
set px = vx*vz
set py = vy*vz
set pz = SR*vz
set v.xvel = (xvel - px) - px*re
set v.yvel = (yvel - py) - py*re
set v.zvel = (zvel - pz) - pz*re
return v
endmethod
endstruct
A bit complicated, but I guess that's needed for the terrain height checking...
tbh anyone who would do anything this function could be used in would just code it themselves...
Terrain deformations caused by abilities are sync'd. Otherwise, I don't see why anyone'd want to make a terrain deformation for just one player - wouldn't it desync when units walked over it and such anyway?
That's stupid... I guess dynamic terrain defomations (like waves and ripples) aren't sync'd right either? Meh. People generally wouldn't use something that needed bounce vectors and abilities like stomp in the same map...
library_once GUT initializer Init
globals
private widget array saved
endglobals
function GetUnitCurrentTarget takes unit u returns widget
return saved[GetHandleId(u)-0x100000]
endfunction
private function Flush takes nothing returns nothing
set saved[GetHandleId(GetTriggerUnit())-0x100000] = null
endfunction
private function Work takes nothing returns nothing
set saved[GetHandleId(GetTriggerUnit())-0x100000] = GetOrderTarget()
endfunction
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddAction(trg, function Work)
set trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_DEATH)
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddAction(trg, function Flush)
set trg = null
endfunction
endlibrary
You should use hashtable for this as something like this doesn't need to be quick and the current form is quite error prone.
You should use hashtable for this as something like this doesn't need to be quick and the current form is quite error prone.
library_once GUT initializer Init
globals
private hashtable hash
endglobals
function GetUnitCurrentTarget takes unit u returns widget
return LoadWidgetHandle(hash, GetHandleId(u), 0)
endfunction
private function Flush takes nothing returns nothing
call FlushChildHashtable(hash, GetHandleId(GetTriggerUnit()))
endfunction
private function Work takes nothing returns nothing
call SaveWidgetHandle(hash, GetHandleId(GetTriggerUnit()), 0, GetOrderTarget())
endfunction
private function Init takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddAction(trg, function Work)
set trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_DEATH)
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddAction(trg, function Flush)
set trg = null
set hash = InitHashtable()
endfunction
endlibrary
////////////////////////////////////////////////////
// function Round
////////////////////////////////////////////////////
//Function: Rounds a real to its nearest integer
//
//Explanation: takes a real number, multiplies it by 2
//and takes the integer part, then rests the old
//number's integer part. Example:takes 0.8; 0.8*2 = 1.6,
// integer part of 1.6 = 1, - the integer part of 0.8
// that is 0, returns 1 - 0 = 1, so 0.8 rounds to 1
/////////////////////////////////////////////////////
function Round takes real q returns integer
return R2I(q*2.00) - R2I(q)
endfunction
#define inline_Round(r) = R2I(r*2.00) - R2I(r);
//or
int Round(float r) { return R2I(r*2.00) - R2I(r); }
function Round takes real q returns integer
return R2I(q+0.5)
endfunction
#define <inline_Round>(x) = R2I(x+.5)
//or
int Round(float x) {return R2I(x+.5)}
call SetDayNightModels("", "")
hm why multiplying it by 2?... that way would be shorter:
JASS:function Round takes real q returns integer return R2I(q+0.5) endfunction
so lets say we have 0.8 .... it would be 0.8+0.5 and in integer 1 because 1,3....
if we would have 0.3+0.5 the integer would be 0. 0.3 rounded is 0.
hm why multiplying it by 2?... that way would be shorter:
JASS:function Round takes real q returns integer return R2I(q+0.5) endfunction
so lets say we have 0.8 .... it would be 0.8+0.5 and in integer 1 because 1,3....
if we would have 0.3+0.5 the integer would be 0. 0.3 rounded is 0.
function Round takes real q returns integer
if q > 0 then
return R2I(q+.5)
else
return R2I(q-.5)
endif
endfunction
function CountNumberOfPlayers takes nothing returns int:
int i = 0
int numberofplayers = 0
loop:
exitwhen i > 11
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER:
numberofplayers++
i++
return numberofplayers
library MiscFunctions:
function Add takes int a, int b returns int:
return a + b
if spell(ID).Type == NOTARGET:
IssueImmediateOrder(FakeHero, spell(ID).Order)
Seconded. Why the hell do we need to be able to code JASS in every language?omg, python Jass now? what's next? an ASM x86 Jass?
let's try to add functions in common Jass, vJass and cJass. I doubt anyone will use somthing different. Starting by ZINC and other freaky weird experiments around to dizzy ppl more.
I think vJass is in a desperate need for a brainfuck syntax. It'll make jassers really happy.
I think vJass is in a desperate need for a brainfuck syntax. It'll make jassers really happy.
I totaly agree.
But whitespace would be more readable.
Maybe a new language - the combination of brainfuck and whitespace.
Every working block of code would be worthy of a screenshot.
function interface Pool_EmptyFunction takes nothing returns nothing
#include "cj_types.j"
#define CreatePool(name, type, endfunction) =
{
struct name
static type array List
static int Count = -1
static Pool_EmptyFunction EF = endfunction
static method Add takes type data returns nothing
.Count++
List[.Count] = data
endmethod
static method Get takes nothing returns type
int rand = GetRandomInt(0, .Count)
type selection = List[rand]
List[rand] = List[.Count]
.Count--
if .Count < 0 then
.EF.execute()
endif
return selection
endmethod
endstruct
}
CreatePool(names, string, 0)
function Trig_Init_Test_Actions takes nothing returns nothing
names.Add("Lol")
names.Add("Frog")
names.Add("Bear")
BJDebugMsg(names.Get())
endfunction
//===========================================================================
function InitTrig_Init_Test takes nothing returns nothing
set gg_trg_Init_Test = CreateTrigger( )
call TriggerAddAction( gg_trg_Init_Test, function Trig_Init_Test_Actions )
endfunction
#include "cj_types.j"
#define CreateRecyclable(name, type, creator, cleaner) =
{
scope name##RecyclerScope initializer Init
globals
private hashtable Hash
endglobals
private function Init takes void returns void
Hash = InitHashtable()
endfunction
struct name
bool Used
type Recyclee
static method Get takes void returns type
thistype r = thistype.create()
if not r.Used then
r.Recyclee = creator
r.Used = true
SaveInteger(Hash, GetHandleId(r.Recyclee), 0, int(r))
endif
return r.Recyclee
endmethod
static method Give takes type r returns void
cleaner
thistype(LoadInteger(Hash, GetHandleId(r), 0)).destroy()
r = null
endmethod
endstruct
endscope
}
CreateRecyclable(groups, group, CreateGroup(), GroupClear(r))
CreateRecyclable(timers, timer, CreateTimer(), PauseTimer(r))
local timer t = timers.Get()
timers.Give(t)
CreateRecyclable(dummys, unit, CreateUnit(Player(0), id, 0, 0, 0), HideUnit(r))
#define Round(num) = Round(num, 1)
real Rou##nd(real num, real base){
num /= base
if num < 0:
num -= .5
else:
num += .5
return R2I(num) * base}
library IsPathBlocked
// Configurables
globals
private constant real CHECK_DISTANCE = 64
private constant real CHECK_RADIUS = 128
endglobals
globals
private group check = CreateGroup()
public unit Target = null
endglobals
private function CheckPath takes real x, real y, code func returns boolean
call GroupEnumUnitsInRange(check, x, y, CHECK_RADIUS, Filter(func))
set Target = FirstOfGroup(check)
return Target != null
endfunction
function IsPathBlocked takes real x1, real y1, real x2, real y2, code func returns boolean
local real distance = SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
local real angle = Atan2(y2-y1, x2-x1)
local real sin = Sin(angle)
local real cos = Cos(angle)
loop
exitwhen distance <= 0
if CheckPath.evaluate(x1, y1, func) then
return true
endif
set x1 = x1+CHECK_DISTANCE*cos
set y1 = y1+CHECK_DISTANCE*sin
set distance = distance-CHECK_DISTANCE
endloop
return false
endfunction
endlibrary
//|**************************************************************************
//| TableMacros v. 1.0
//| by Anachron
//|
//| Implement this module into your struct to use it.
//|
//| New methods:
//| ------------
//|
//| private static method initTable takes nothing returns nothing
//| > Initializes the Table.
//|
//| public method save takes nothing returns nothing
//| > Saves the instance.
//|
//| public method remove takes nothing returns nothing
//| > Kills the instance, using Table.flush before the destroy() call.
//|
//| public static method load takes $KTYPE$ id returns thistype
//| > Loads the instance from the InstanceTable.
//|
//|**************************************************************************
globals
constant boolean TM_DISPLAY_NOTICES = false
endglobals
module TableMacros requires Table
private static Table INSTANCES = 0
private integer ID = 0
private static method onInit takes nothing returns nothing
set thistype.INSTANCES = Table.create()
endmethod
public method save takes nothing returns nothing
set thistype.INSTANCES[.ID] = integer(this)
debug if TM_DISPLAY_NOTICES then
debug call BJDebugMsg("TableMacros_NOTICE: [|cffffcc00$TNAME$|r] SAVED (|cffffcc00Key|r: " + I2S(.ID) + " | |cffffcc00ID|r: " + I2S(integer(this)) + " )")
debug endif
endmethod
public method remove takes nothing returns nothing
debug if TM_DISPLAY_NOTICES then
debug call BJDebugMsg("TableMacros_NOTICE: [|cffffcc00$TNAME$|r] KILLED (|cffffcc00Key|r: " + I2S(.ID) + " | |cffffcc00ID|r: " + I2S(integer(this)) + " )")
debug endif
call thistype.INSTANCES.flush(.ID)
call .destroy()
endmethod
public static method load takes integer id returns thistype
debug if TM_DISPLAY_NOTICES then
debug call BJDebugMsg("TableMacros_NOTICE: [|cffffcc00$TNAME$|r] LOADED (|cffffcc00Key|r: " + I2S(id) + " | |cffffcc00ID|r: " + I2S(integer(thistype(thistype.INSTANCES[id]))) + " )")
debug endif
return thistype(thistype.INSTANCES[id])
endmethod
endmodule