- Joined
- Aug 12, 2010
- Messages
- 29
So this is my first time really getting used to writing something mainly using structs and as of now, it works how it's intended to(Create a chain, allowing healing or damage and executing a function if one is set). My question is: How could I go about betting optimizing or improving what I created? I looked at quite a bit of coding while writing this for pointers, but I could never really find an advance tutorial on structs. I'm pretty positive it's MUI.
Any feedback, criticism and comments are very much welcomed!
The entire system is written with Zinc.
Any feedback, criticism and comments are very much welcomed!
The entire system is written with Zinc.
JASS:
//! zinc
library ChainSys requires GroupUtils,AIDS,Damage,TimerUtils{
private{
//Height of the chain
constant real OFFSET = 65.0;
//How often the chain will move
constant real INTERVAL = 0.15;
}
private{
location SourceZ=Location(0,0);
location TargetZ=Location(0,0);
}
public{
constant string LIGHTNING_CHAIN_LIGHTNING_PRIMARY = "CLPB";
constant string LIGHTNING_CHAIN_LIGHTNING_SECONDARY = "CLSB";
constant string LIGHTNING_DRAIN = "DRAB";
constant string LIGHTNING_DRAIN_LIFE = "DRAL";
constant string LIGHTNING_DRAIN_MANA = "DRAM";
constant string LIGHTNING_FINGER_OF_DEATH = "AFOD";
constant string LIGHTNING_FORKED_LIGHTNING = "FORK";
constant string LIGHTNING_HEALING_WAVE_PRIMARY = "HWPB";
constant string LIGHTNING_HEALING_WAVE_SECONDARY = "HWSB";
constant string LIGHTNING_LIGHTNING_ATTACK = "CHIM";
constant string LIGHTNING_MAGIC_LEASH = "LEAS";
constant string LIGHTNING_MANA_BURN = "MBUR";
constant string LIGHTNING_MANA_FLARE = "MFPB";
constant string LIGHTNING_SPIRIT_LINK = "SPLK";
}
public{
unit Chain_LastCasterUnit;
unit Chain_LastHitUnit;
}
struct ChainTime{
lightning light;
method destroy(){
DestroyLightning(this.light);
this.light=null;
}
}
function onTimer(){
timer t=GetExpiredTimer();
ChainTime this=GetTimerData(t);
this.destroy();
}
function AddLightningTimed(string art,unit whichUnit,unit target,real duration,integer red,integer green,integer blue){
ChainTime this=ChainTime.create();
timer t=NewTimer();
real sourceX=GetUnitX(whichUnit),sourceY=GetUnitY(whichUnit),sourceH=GetUnitFlyHeight(whichUnit);
real targetX=GetUnitX(target),targetY=GetUnitY(target),targetH=GetUnitFlyHeight(target);
MoveLocation(SourceZ,sourceX,sourceY);
MoveLocation(TargetZ,targetX,targetY);
this.light=AddLightningEx(art,true,
sourceX,sourceY,GetLocationZ(SourceZ)+OFFSET+sourceH,
targetX,targetY,GetLocationZ(TargetZ)+OFFSET+targetH);
SetLightningColor(this.light,red,green,blue,1.0);
SetTimerData(t,integer(this));
TimerStart(t,duration,false,function onTimer);
t=null;
}
public struct Chain{
unit caster,source,target;
player owner;
real radiusX,radiusY;
string primaryChain;
string secondaryChain;
string impact;
string point;
integer maxBounce;
integer red=1;
integer green=1;
integer blue=1;
real radius;
real damage;
real heal;
real modify;
boolean hitFriendly=false;
boolean hitEnemy=false;
boolean hitStructure=false;
attacktype attackType;
damagetype damageType;
static code onHit;
group chainGroup;
integer tick=-1;
method destroy(){
ReleaseGroup(this.chainGroup);
this.caster=null;
this.source=null;
this.target=null;
this.owner=null;
this.chainGroup=null;
}
static method onTimer(){
timer t=GetExpiredTimer();
trigger e;
thistype this=GetTimerData(t);
real sourceX=GetUnitX(this.source),sourceY=GetUnitY(this.source),sourceH=GetUnitFlyHeight(this.source);
real targetX=GetUnitX(this.target),targetY=GetUnitY(this.source),targetH=GetUnitFlyHeight(this.target);
group g=NewGroup();
MoveLocation(SourceZ,sourceX,sourceY);
MoveLocation(TargetZ,targetX,targetY);
GroupAddUnit(this.chainGroup,this.target);
if (this.target!=null){
//Primary creation
if (this.tick==-1){
AddLightningTimed(this.primaryChain,this.source,this.target,0.45,this.red,this.green,this.blue);
//Secondary creation
}else if (this.tick>=0&&this.secondaryChain!=null){
AddLightningTimed(this.secondaryChain,this.source,this.target,0.45,this.red,this.green,this.blue);
}
if (this.damage>0){
UnitDamageTargetEx(this.caster,this.target,this.damage,false,false,this.attackType,this.damageType,WEAPON_TYPE_WHOKNOWS);
this.damage-=this.damage*modify;
}else if (this.heal>0){
SetWidgetLife(this.target,GetWidgetLife(this.target)+this.heal);
this.heal-=this.heal*modify;
}
Chain_LastHitUnit=this.target;
Chain_LastCasterUnit=this.caster;
e=CreateTrigger();
TriggerAddAction(e,this.onHit);
TriggerExecute(e);
DestroyTrigger(e);
DestroyEffect(AddSpecialEffectTarget(this.impact,this.target,this.point));
this.tick+=1;
this.source=this.target;
GroupEnumUnitsInRange(g,radiusX,radiusY,this.radius,null);
this.target=FirstOfGroup(g);
while (this.target!=null){
if (!IsUnitType(this.target,UNIT_TYPE_DEAD)&&GetUnitTypeId(this.target)>0&&!IsUnitInGroup(this.target,this.chainGroup)){
if (this.hitStructure||!IsUnitType(this.target,UNIT_TYPE_STRUCTURE)){
if (this.hitEnemy&&IsUnitEnemy(this.target,this.owner)){
break;
}else if (this.hitFriendly&&IsUnitAlly(this.target,this.owner)){
break;
}
}
}
GroupRemoveUnit(g,this.target);
this.target=FirstOfGroup(g);
}
}else{
ReleaseTimer(t);
this.destroy();
}
if (this.tick>=this.maxBounce){
ReleaseTimer(t);
this.destroy();
}
ReleaseGroup(g);
g=null;
e=null;
t=null;
}
static method launch(thistype this){
timer t=NewTimer();
this.source=this.caster;
this.radiusX=GetUnitX(this.target);
this.radiusY=GetUnitY(this.target);
this.chainGroup=NewGroup();
if (this.secondaryChain==null){
this.secondaryChain=this.primaryChain;
}
SetTimerData(t,this);
TimerStart(t,INTERVAL,true,function thistype.onTimer);
t=null;
}
static method initialize(unit whichCaster)->thistype{
Chain this=GetUnitId(whichCaster);
this.caster=whichCaster;
this.owner=GetOwningPlayer(this.caster);
this.tick=-1;
return this;
}
method operator primaryArt=(string art){
this.primaryChain=art;
}
method operator secondaryArt=(string art){
this.secondaryChain=art;
}
method operator impactArt=(string art){
this.impact=art;
}
method operator attachment=(string where){
this.point=where;
}
method operator onStrike=(code whatEvent){
this.onHit=whatEvent;
}
method operator bounce=(integer value){
this.maxBounce=value;
}
method operator colorRed=(integer value){
this.red=value;
}
method operator colorBlue=(integer value){
this.blue=value;
}
method operator colorGreen=(integer value){
this.green=value;
}
method operator area=(real value){
this.radius=value;
}
method operator targetDamage=(real value){
this.damage=value;
}
method operator targetHeal=(real value){
this.heal=value;
}
method operator modifyValue=(real value){
this.modify=value;
}
method operator attacktype=(attacktype value){
this.attackType=value;
}
method operator damagetype=(damagetype value){
this.damageType=value;
}
method operator filterFriendly=(boolean flag){
this.hitFriendly=flag;
}
method operator filterEnemy=(boolean flag){
this.hitEnemy=flag;
}
method operator filterStructure=(boolean flag){
this.hitStructure=flag;
}
}
}
//! endzinc
Last edited: