HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Struct extending struct and interface

06-08-2009, 02:26 PM#1
XieLong
Hi guys,

Collapse 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
As you can see this wont work because this syntax isn't supported by vJASS... But how can I realize this anyway?
06-08-2009, 02:56 PM#2
Vexorian
Hard

Only think I can think of is:
Collapse 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
XieLong
Cool thank you :) Now I've got a reason to update my JassHelper version :b
06-08-2009, 05:18 PM#4
moyack
I usually did in this way:

Collapse 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
XieLong
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
Alevice
or just use modules :P