• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] Type

I'll give an example.

Imagine a system with custom damage types.

You can use this to make one damage extend others. You'll have a damage type tree that you can work with and this will allow you to avoid a ton of flags for each damage type :D

JASS:
// Base types
globals
    Type DAMAGE_TYPE_DPS
    Type DAMAGE_TYPE_SLOW
endglobals

globals
    Type DAMAGE_TYPE_FIRE
    Type DAMAGE_TYPE_POISON

    Type DAMAGE_TYPE_ICE
    Type DAMAGE_TYPE_FROST
    Type DAMAGE_TYPE_MUCK
endglobals

private module Init
    private static method onInit takes nothing returns nothing
        set DAMAGE_TYPE_DPS = Type.create(0)
        set DAMAGE_TYPE_SLOW = Type.create(0)

        set DAMAGE_TYPE_FIRE = Type.create(DAMAGE_TYPE_DPS)
        set DAMAGE_TYPE_POISON = Type.create(DAMAGE_TYPE_DPS)

        set DAMAGE_TYPE_ICE = Type.create(DAMAGE_TYPE_SLOW)
        set DAMAGE_TYPE_FROST = Type.create(DAMAGE_TYPE_SLOW)
        set DAMAGE_TYPE_MUCK = Type.create(DAMAGE_TYPE_SLOW)
    endmethod
endmodule

private struct InitS extends array
    implement Init
endstruct

This is one example of the many uses this has :D
Imagine being able to define code for each base damage type.
The extending damage types would instantly have that code work for them and they would also add to it ^_^.
DAMAGE_TYPE_DPS would deal damage over time. DAMAGE_TYPE_FIRE would do what DAMAGE_TYPE_DPS does, then it would add a fire special effect for example :D
 
Structs compile like this:

- Static methods become regular functions
- Static variables become global variables
- Methods become functions that take an integer called this
- Variables become global array variables that use this as an index.
- Static method operators and method operators are treated like static and non-static methods.
- Modules just CnP the code they have inside them in the struct before everything compiles. Thankfully, Vexorian assured that a module will only be implemented once per struct. (No duplicate code, wee /o/)
- If the struct does not extend an array, you'll have generated allocate() and deallocate(integer) methods. Allocate compiles to a function that returns a unique integer and deallocate will compile to a function that takes an integer representing the instance to be deallocated and returns nothing.
- When inheritance comes into play, it's about either sharing functions or copying them.

That's all I can come up with on the spot. I might be wrong about something and I might have left something out. (I know I left out delegates and interfaces for one)
 
Structs compile like this:

- Static methods become regular functions
- Static variables become global variables
- Methods become functions that take an integer called this
- Variables become global array variables that use this as an index.
- Static method operators and method operators are treated like static and non-static methods.
- Modules just CnP the code they have inside them in the struct before everything compiles. Thankfully, Vexorian assured that a module will only be implemented once per struct. (No duplicate code, wee /o/)
- If the struct does not extend an array, you'll have generated allocate() and deallocate(integer) methods. Allocate compiles to a function that returns a unique integer and deallocate will compile to a function that takes an integer representing the instance to be deallocated and returns nothing.
- When inheritance comes into play, it's about either sharing functions or copying them.

That's all I can come up with on the spot. I might be wrong about something and I might have left something out. (I know I left out delegates and interfaces for one)
Thanks for this writeup on this. I still don't understand how custom extensions are actually possible, as it should only be possible from the compiler side, but meh, it doesn't really matter if it works. ^^
 
Seems cool...

Seeing Maggy's example, I could imagine lots of possible things with this... Maybe I'll have a use for this when I decide to go back to making maps... Probably for creating additional things to damage systems and such...
It would also be pretty need for things like buff systems.

You can basicly have a "basic" buff struct and then extend different types of buffs, adding parameters which are needed and leaving those which are not needed. Could improve the performance and code length of buff systems by a lot, to leave out the redundant stuff.
 
This has nothing to do with arrays :|

It's used to define object types and track inheritance.

Object Damage
Object Magical Damage extends Damage
Object Elemental Damage extends Magical Damage
Object Fire Damage extends Elemental Damage


Now in damage, if you want something to run whenever the unit gets hit by magical damage, that magical damage will catch all subtypes. If you want it to just be fire damage, it'll just be fire damage and possible subtypes of fire damage.

if (damageType.extends(DamageType.MAGIC)) then

Extends and isParent return true when damageType == targetType as well
 
Top