- Joined
- Sep 30, 2009
- Messages
- 698
Main Library
Changelog
JASS:
//############################### CREDITS ###################################//
//##
//## Version: 0.04 Alpha
//## System: Axarion
//## AutoIndex: grim001
//## AIDS: Jesus4Lyf
//## UnitIndexer: Nestharus
//##
//############################### DESCRIPTION ###############################//
//##
//## This system allows an easier manipulation of units. If AutoCreateData is
//## set to true it will also automatically create one UnitData or HeroData
//## instance per unit. The instances are destroyed when the unit leaves the
//## map so you don't have to worry about unused struct instances.
//##
//## The main part of this system are the modules and everything is optional.
//## Just import UnitData, HeroData and all modules you want into your map.
//## If you feel like doing a module for this system you are free to do so
//## and I will include it if it works well and credit you.
//##
//## Look into the modules to see what can be used. It would just take too much
//## time and place to list all functions and operators.
//##
//## Note:
//## Right now not all features are done, but I will add the other stuff
//## as fast as possible and include BonusMod, UnitStatus and so on...
//##
//############################################################################//
library UnitData requires optional UnitIndexer, optional AutoIndex, optional AIDS //one is required!
struct UnitData extends array
unit InstanceUnit
integer UnitUserData
//implementing the modules
implement optional UnitDataCoordinates
implement optional UnitDataAbilities
implement optional UnitDataMisc
implement optional UnitDataState
implement optional UnitDataOrder
implement optional UnitDataItem
implement optional HeroDataMisc
implement optional HeroDataStats
implement optional HeroDataLevel
static method operator [] takes unit u returns thistype
static if LIBRARY_AIDS then
return GetUnitIndex(u)
else
return GetUnitId(u)
endif
endmethod
static method operator []= takes unit u, thistype this returns nothing
set UnitData[u] = this
endmethod
static method get takes unit u returns thistype
return UnitData[u]
endmethod
static method fromUnit takes unit u returns thistype
set UnitData[u].InstanceUnit = u
return UnitData[u]
endmethod
static method create takes player p, integer id, real x, real y, real f returns thistype
return UnitData[CreateUnit(p, id, x, y, f)]
endmethod
//###################################### INDEXER STUFF ######################################//
// for UnitIndexer
static if LIBRARY_UnitIndexer then
private static method UnitDataDeindexed takes nothing returns boolean
set UnitData[GetIndexedUnit()].InstanceUnit = null
return false
endmethod
private static method UnitDataIndexed takes nothing returns boolean
call thistype.fromUnit(GetIndexedUnit())
return false
endmethod
private static method onInit takes nothing returns nothing
call OnUnitDeindex(Condition(function thistype.UnitDataDeindexed))
call OnUnitIndex (Condition(function thistype.UnitDataIndexed))
endmethod
endif
//for AutoIndex
static if LIBRARY_AutoIndex and not LIBRARY_AIDS then
private static method UnitDataDeindexed takes unit u returns nothing
set UnitData[u].InstanceUnit = null
endmethod
static if AutoCreateData then
private static method UnitDataIndexed takes unit u returns nothing
call thistype.fromUnit(u)
endmethod
endif
private static method onInit takes nothing returns nothing
call OnUnitDeindexed(thistype.UnitDataDeindexed)
call OnUnitIndexed(thistype.UnitDataIndexed)
endmethod
endif
endstruct
// for people with AIDS
static if LIBRARY_AIDS then
private struct UnitDataAIDS extends array
method AIDS_onCreate takes nothing returns nothing
call UnitData.fromUnit(.unit)
endmethod
method AIDS_onDestroy takes nothing returns nothing
set UnitData[.unit].InstanceUnit = null
endmethod
//! runtextmacro optional AIDS()
endstruct
endif
endlibrary
- UnitDataState
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module UnitDataState method operator life takes nothing returns real return GetWidgetLife(.InstanceUnit) endmethod method operator life= takes real newLife returns nothing call SetWidgetLife(.InstanceUnit, newLife) endmethod method operator maxlife takes nothing returns real return GetUnitState(.InstanceUnit, UNIT_STATE_MAX_LIFE) endmethod method operator mana takes nothing returns real return GetUnitState(.InstanceUnit, UNIT_STATE_MANA) endmethod method operator mana= takes real newMana returns nothing call SetUnitState(.InstanceUnit, UNIT_STATE_MANA, newMana) endmethod method operator maxmana takes nothing returns real return GetUnitState(.InstanceUnit, UNIT_STATE_MAX_MANA) endmethod endmodule
- UnitDataMisc
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module UnitDataMisc method operator name takes nothing returns string return GetUnitName(.InstanceUnit) endmethod method operator id takes nothing returns integer return GetUnitTypeId(.InstanceUnit) endmethod method operator owner takes nothing returns player return GetOwningPlayer(.InstanceUnit) endmethod method operator owner= takes player p returns nothing call SetUnitOwner(.InstanceUnit, p, false) endmethod method operator level takes nothing returns integer return GetUnitLevel(.InstanceUnit) endmethod method kill takes nothing returns nothing call KillUnit(.InstanceUnit) endmethod method remove takes nothing returns nothing call RemoveUnit(.InstanceUnit) endmethod method operator hide= takes boolean val returns nothing call ShowUnit(.InstanceUnit, val) endmethod method operator acquireRange takes nothing returns real return GetUnitAcquireRange(.InstanceUnit) endmethod method operator acquireRange= takes real range returns nothing call SetUnitAcquireRange(.InstanceUnit, range) endmethod method operator foodUsed takes nothing returns integer return GetUnitFoodUsed(.InstanceUnit) endmethod method operator useFood= takes boolean flag returns nothing call SetUnitUseFood(.InstanceUnit, flag) endmethod method operator foodMade takes nothing returns integer return GetUnitFoodMade(.InstanceUnit) endmethod method isType takes unittype whichUnitType returns boolean return IsUnitType(.InstanceUnit, whichUnitType) endmethod endmodule
- UnitDataCoordinates
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module UnitDataCoordinates method operator x takes nothing returns real return GetUnitX(.InstanceUnit) endmethod method operator x= takes real x returns nothing call SetUnitX(.InstanceUnit, x) endmethod method operator y takes nothing returns real return GetUnitY(.InstanceUnit) endmethod method operator y= takes real y returns nothing call SetUnitY(.InstanceUnit, y) endmethod method operator z takes nothing returns real return GetUnitFlyHeight(.InstanceUnit) endmethod method operator z= takes real z returns nothing call SetUnitFlyHeight(.InstanceUnit, z, 0) endmethod method operator facing takes nothing returns real return GetUnitFacing(.InstanceUnit) endmethod method operator facing= takes real facing returns nothing call SetUnitFacing(.InstanceUnit, facing) endmethod endmodule
- UnitDataAbilities
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module UnitDataAbilities method addAbility takes integer id returns boolean return UnitAddAbility(.InstanceUnit, id) endmethod method removeAbility takes integer id returns boolean return UnitRemoveAbility(.InstanceUnit, id) endmethod method setAbilityLevel takes integer id, integer level returns integer return SetUnitAbilityLevel(.InstanceUnit, id, level) endmethod method resetAbilityCooldown takes nothing returns nothing call UnitResetCooldown(.InstanceUnit) endmethod method makeAbilityPermanent takes integer id, boolean permanent returns boolean return UnitMakeAbilityPermanent(.InstanceUnit, permanent, id) endmethod endmodule
- UnitDataOrder
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module UnitDataOrder method operator order takes nothing returns integer return GetUnitCurrentOrder (.InstanceUnit) endmethod method pointOrder takes string order, real x, real y returns boolean return IssuePointOrder(.InstanceUnit, order, x, y) endmethod method pointOrderId takes integer orderId, real x, real y returns boolean return IssuePointOrderById(.InstanceUnit, orderId, x, y) endmethod method targetOrder takes string order, widget target returns boolean return IssueTargetOrder(.InstanceUnit, order, target) endmethod method targetOrderId takes integer orderId, widget target returns boolean return IssueTargetOrderById(.InstanceUnit, orderId, target) endmethod method immediateOrder takes string order returns boolean return IssueImmediateOrder(.InstanceUnit, order) endmethod method immediateOrderId takes integer orderId returns boolean return IssueImmediateOrderById(.InstanceUnit, orderId) endmethod endmodule
- UnitDataItem
JASS:module UnitDataItem method addItem takes item i returns boolean return UnitAddItem(.InstanceUnit, i) endmethod method addItemId takes integer id returns item return UnitAddItemById(.InstanceUnit, id) endmethod method removeItem takes item i returns nothing call UnitRemoveItem(.InstanceUnit, i) endmethod method useItem takes item i returns boolean return UnitUseItem(.InstanceUnit, i) endmethod method useItemTarget takes item i, widget target returns boolean return UnitUseItemTarget(.InstanceUnit, i, target) endmethod method useItemXY takes item i, real x, real y returns boolean return UnitUseItemPoint(.InstanceUnit, i, x ,y) endmethod method itemInSlot takes integer slot returns item return UnitItemInSlot(.InstanceUnit, slot) endmethod method hasItem takes item i returns boolean return UnitHasItem(.InstanceUnit, i) endmethod endmodule
- HeroDataMisc
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module HeroDataMisc method revive takes real x, real y, boolean doEyecandy returns boolean return ReviveHero(.InstanceUnit, x, y, doEyecandy) endmethod method operator heroname takes nothing returns string return GetHeroProperName(.InstanceUnit) endmethod endmodule
- HeroDataStats
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module HeroDataStats method operator strength takes nothing returns integer return GetHeroStr(.InstanceUnit, false) endmethod method operator strength= takes integer i returns nothing call SetHeroStr(.InstanceUnit, i, true) endmethod method operator agility takes nothing returns integer return GetHeroAgi(.InstanceUnit, false) endmethod method operator agility= takes integer i returns nothing call SetHeroAgi(.InstanceUnit, i, true) endmethod method operator intelligence takes nothing returns integer return GetHeroInt(.InstanceUnit, false) endmethod method operator intelligence= takes integer i returns nothing call SetHeroInt(.InstanceUnit, i, true) endmethod endmodule
- HeroDataLevel
JASS:
//############################### INFORMATION ##################################// //## Creator: Axarion // //##############################################################################// module HeroDataLevel method operator experience takes nothing returns integer return GetHeroXP(.InstanceUnit) endmethod method operator experience= takes integer i returns nothing call SetHeroXP(.InstanceUnit, i, true) endmethod method operator herolevel takes nothing returns integer return GetHeroLevel(.InstanceUnit) endmethod method operator herolevel= takes integer i returns nothing call SetHeroLevel(.InstanceUnit, i, true) endmethod method operator skillpoints takes nothing returns integer return GetHeroSkillPoints(.InstanceUnit) endmethod method operator skillpoints= takes integer i returns nothing call UnitModifySkillPoints(.InstanceUnit, i - .skillpoints) endmethod endmodule
Changelog
- Version 0.01 Alpha: First Release
- Version 0.02 Alpha: Added UnitDataOrder module, fixed a minor fail
- Version 0.03 Alpha: Recoded some things, made it an array struct, merged UnitData and HeroData, removed AutoCreateData boolean
- Version 0.04 Alpha: Added UnitDataItem
Attachments
Last edited: