| 06-08-2009, 02:26 PM | #1 |
Hi guys, I would like to make something like that:private struct Module real dX real dY Color Tint static method create takes real dx, real dy returns Module local Module this = Module.allocate() if this != 0 then set .Bubbles = CreateGroup() set .Face = 0 endif return this endmethod method turn takes real radians returns nothing // turn all units of the Module endmethod endstruct struct WeaponModule extends Module static method create takes Tank t, real dx, real dy returns WeaponModule local WeaponModule this = Module.create(t, dx, dy) if this != 0 then set .Tint = Color.create(255, 255, 0, 255) endif return this endmethod endstruct struct CompModule extends Module static method create takes Tank t, real dx, real dy returns CompModule local CompModule this = Module.create(t, dx, dy) if this != 0 then set .Tint = Color.create(0, 128, 255, 255) endif return this endmethod endstruct interface Weapon method shoot takes nothing returns nothing endinterface struct BasicCannon extends WeaponModule implements Weapon method shoot takes nothing returns nothing // Shoot into the actual facing of the module endmethod endstruct |
| 06-08-2009, 02:56 PM | #2 |
Hard Only think I can think of is: JASS:
module Module
real dX
real dY
Color Tint
static method create takes real dx, real dy returns Module
local Module this = Module.allocate()
if this != 0 then
set .Bubbles = CreateGroup()
set .Face = 0
endif
return this
endmethod
method turn takes real radians returns nothing
// turn all units of the Module
endmethod
endmodule
module WeaponModule
implement Module
static method create2 takes Tank t, real dx, real dy returns thistype
local WeaponModule this = thistype.create(t, dx, dy)
if this != 0 then
set .Tint = Color.create(255, 255, 0, 255)
endif
return this
endmethod
endmodule
module CompModule
implement Module
static method create2 takes Tank t, real dx, real dy returns thistype
local CompModule this = thistype.create(t, dx, dy)
if this != 0 then
set .Tint = Color.create(0, 128, 255, 255)
endif
return this
endmethod
endmodule
interface Weapon
method shoot takes nothing returns nothing
endinterface
struct BasicCannon extends Weapon
implement WeaponModule
method shoot takes nothing returns nothing
// Shoot into the actual facing of the module
endmethod
endstruct
|
| 06-08-2009, 04:21 PM | #3 |
Cool thank you :) Now I've got a reason to update my JassHelper version :b |
| 06-08-2009, 05:18 PM | #4 |
I usually did in this way: JASS:library test interface Common method onEffect takes nothing returns nothing endinterface struct Daddy extends Common method stub onEffect takes nothing returns nothing // stub makes this function replaceable by the one used by the child endmethod endstruct struct Kid extends Daddy // therefore it extends the interface "Common" method onEffect takes nothing returns nothing endmethod endstruct endlibrary EDIT: in your case, the thing is not as easy, and Vex answer is probably the best option... this could be done if interface can be an extend of a struct, but it's not logical anyways. |
| 06-08-2009, 05:53 PM | #5 |
The best solution would be the possibility to implement this case as I wrote and how it also could be done in Java. |
| 06-08-2009, 06:41 PM | #6 |
or just use modules :P |
