D.V.D
Make a wish
- Reaction score
- 73
Thanks to Aziler for helping me store reals in structs.
JASS:
library RealGroups initializer Init
//================================================================\\
// Real Groups Created By D.V.D \\
//================================================================\\
// Purpose: \\
// To store and return unlimited amounts of reals instead of \\
// making another function call for every real you want to return \\
//================================================================\\
// Pros: \\
// -Allows you to store and manipulate reals in real groups \\
// -Replacing and copying real groups \\
// -Makes life easier for certian systems \\
// -Can be used instead of structs to store reals for abilities \\
//================================================================\\
// method create takes nothing returns realgroup \\
// -Creates a real group \\
// \\
// method addreal takes real r returns nothing \\
// -Adds a real to the real group increasing the count \\
// \\
// method copyrealgroup takes nothing returns realgroup \\
// -Copies and creates a new realgroup \\
// \\
// method getreal takes integer count returns nothing \\
// -Gets a real from the real group by getting the reals count \\
// \\
// method getrealnumber takes nothing returns integer \\
// -Gets the amount of reals in a realgroup \\
// \\
// method cleargroup takes nothing returns nothing \\
// -Clears all the reals from a realgroup. Does not destroy \\
// \\
// method removereal takes integer count returns nothing \\
// -Removes a real numberd by the count \\
// \\
// method replace real takes integer coun, real r returns nothing \\
// -Replaces a real counted by count with a new real \\
// \\
// method mathallreals takes integer math returns nothing \\
// -Adds,Subtracts,Multiplies, or Divides all reals. The values \\
// are 0 = add, 1 = subtract, 2 = multiply, 3 = divide \\
// \\
// method setallreals takes real r returns nothing \\
// -Sets all reals in a group to a certian value \\
// \\
// method destroy takes nothing returns nothing \\
// -Destroys the real group \\ \\
//================================================================\\
struct realgroup
hashtable h
integer count
static method create takes nothing returns realgroup
local realgroup g = realgroup.allocate()
set g.h = InitHashtable()
set g.count = 0
return g
endmethod
method addreal takes real r returns nothing
set .count = .count + 1
call SaveReal( .h, .count, this, r )
endmethod
method copyrealgroup takes nothing returns realgroup
local integer i = 0
local real r
local realgroup g = realgroup.allocate()
loop
exitwhen i > .count
set r = LoadReal( .h, i, this)
call g.addreal(r)
set i = i + 1
endloop
return g
endmethod
method getreal takes integer count returns real
return LoadReal(.h, count, this)
endmethod
method getrealnumber takes nothing returns integer
return .count
endmethod
method cleargroup takes nothing returns nothing
local integer i = 0
local real r
loop
exitwhen i > .count
set r = LoadReal(.h, i, this)
set i = i + 1
endloop
endmethod
method removereal takes integer count returns nothing
local real r = LoadReal( .h, count, this )
call RemoveSavedReal( .h, .count, this )
set .count = .count - 1
endmethod
method replacereal takes integer count, real r returns nothing
call SaveReal(.h, count, this, r )
endmethod
method mathallreals takes integer math, real p returns nothing
local integer i = 0
local real r
loop
exitwhen i > .count
if ( math == 0 ) then //add
set r = LoadReal(.h, i, this)
set r = r + p
call SaveReal( .h, i, this, r )
elseif ( math == 1 ) then //subtract
set r = LoadReal(.h, i, this)
set r = r - p
call SaveReal( .h, i, this, r )
elseif ( math == 2 ) then //multiply
set r = LoadReal(.h, i, this)
set r = r * p
call SaveReal( .h, i, this, r )
elseif ( math == 3 ) then //divide
set r = LoadReal(.h, i, this)
set r = r / p
call SaveReal( .h, i, this, r )
endif
set i = i + 1
endloop
endmethod
method setallreals takes real r returns nothing
local integer i = 0
loop
exitwhen i > .count
set r = LoadReal(.h, i, this)
call .replacereal(i, r)
set i = i + 1
endloop
endmethod
endstruct
//===========================================================================
function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
endfunction
endlibrary