Komaqtion
You can change this now in User CP.
- Reaction score
- 469
Hello
I just saw a little post about someone wanting to do something in a grid formation, and I thought I'd cook something up which would do just that
Well, the concept of this is actually done, and it works but I just wanted to get some pointers on how useful it would be to have a system like this, and also what I can do to make it more usable and configurable...
This is the code I have atm, and as you can see I've tried using a hashtable and an array to index the different squares you get in a grid. At first I really wanted to use an integer array which would contain the square-number of each grid-square and also the grid_square struct of those but since vJass can't really handle arrays inside structs (You have to specify the size of the array), I went another way.
I then tried using a hashtable for it, and use the Grid struct's integer number as the parent key, and the Grid_Square struct integer number for the child key, but I was unable to find a way to implement this into the Grid struct (I don't really wanna use globals) and I also found it hard to index it very well so I scrapped this too...
Anyways, code:
If any of you have any thoughts or ideas on this, please share them Good or bad
I just saw a little post about someone wanting to do something in a grid formation, and I thought I'd cook something up which would do just that
Well, the concept of this is actually done, and it works but I just wanted to get some pointers on how useful it would be to have a system like this, and also what I can do to make it more usable and configurable...
This is the code I have atm, and as you can see I've tried using a hashtable and an array to index the different squares you get in a grid. At first I really wanted to use an integer array which would contain the square-number of each grid-square and also the grid_square struct of those but since vJass can't really handle arrays inside structs (You have to specify the size of the array), I went another way.
I then tried using a hashtable for it, and use the Grid struct's integer number as the parent key, and the Grid_Square struct integer number for the child key, but I was unable to find a way to implement this into the Grid struct (I don't really wanna use globals) and I also found it hard to index it very well so I scrapped this too...
Anyways, code:
JASS:
library Gridder
globals
//hashtable Grid_Hash
//location array Square_Loc
endglobals
private keyword Grid
struct Grid_Square
real centerX
real centerY
real square_width
real square_height
Grid owningGrid
static method create takes real x, real y, real width, real height, Grid belongto returns thistype
local thistype this = thistype.allocate()
set centerX = x
set centerY = y
set square_width = width
set square_height = height
set owningGrid = belongto
return this
endmethod
endstruct
struct Grid
real g_centerX = 0.
real g_centerY = 0.
real g_width = 0.
real g_height = 0.
real sq_width = 0.
real sq_height = 0.
integer g_squares = 0
static method create takes real x, real y, integer h_number, integer v_number, real squarewide, real squarehigh returns thistype
local thistype this = thistype.allocate()
local integer i = 0
local integer i1 = 0
//local integer i2 = 0
local real curX = 0.
local real curY = 0.
local real startX = x - ((squarewide * h_number) / 2.)
local real startY = y + ((squarehigh * v_number) / 2.)
set g_centerX = x
set g_centerY = y
set g_width = h_number * squarewide
set g_height = v_number * squarehigh
set g_squares = h_number * v_number
set sq_width = squarewide
set sq_height = squarehigh
loop
set i = i + 1
set i1 = 0
exitwhen i > v_number
set curY = startY - (squarehigh * i)
//call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 60., "Y: " + R2S( curY ) )
loop
set i1 = i1 + 1
exitwhen i1 > h_number
set curX = startX + (squarewide * i1)
call Grid_Square.create( curX, curY, squarewide, squarehigh, this )
//call SaveLocationHandle( Grid_Hash, this, Grid_Square.create( curX, curY, squarewide, squarehigh, this ), Location( curX, curY ) )
//call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 60., "X: (" + I2S( i2 ) + "<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> " + R2S( curX ) )
//call AddSpecialEffect( "Abilities\\Spells\\NightElf\\Barkskin\\BarkSkinTarget.mdl", curX, curY )
//set i2 = i2 + 1
endloop
endloop
//call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 60., "StartX: " + R2S( startX ) )
//call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 60., "StartY: " + R2S( startY ) )
//call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 60., "CenterX: " + R2S( x ) )
//call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 60., "CenterY: " + R2S( y ) )
return this
endmethod
private static method onInit takes nothing returns nothing
local thistype this = thistype.create( 0., 0., 10, 10, 150., 150. )
//set Grid_Hash = InitHashtable()
endmethod
endstruct
endlibrary
If any of you have any thoughts or ideas on this, please share them Good or bad