• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Turret Mounting System V1.10


Author Commments
---------------------------------------------------------------------------
Tank-Commander presents for the very first time: Something /NOT/ GUI

Indeed, this is my very first and first attempted at a Pure JASS system (yes JASS not vJASS)

uses Dynamic Indexing (like my more recent GUI spells, I was sick of how GUI handled my IF statements so I decided to write them myself, and then I figured what the hell not and did it all in JASS
---------------------------------------------------------------------------

Turret Mounting System:

Ever wanted tiny little independant turrets attached to a unit with a smart AI? Well now you can with this Turret Mounting System, capable of supporting thousands of different turret types, only using one little trigger, with configurable behaviours, effects, damages, AOEs, layouts and more!

Great for boss units, minigames, and generally kickass units

NOTE: not designed for En masse use, it takes a lot of processing so many carriers will cause lag, if you want to use en masse with this system you will need quite a bit of coding knowledge and to follow that section in the readme on how to convert it (will lose a lot of extra functionality to do this, including mid-flight changing missile speeds, automatic after effects, targetting AI, projectile target markers, speed limiters, incoming time (automatic adjusting speed to match distance), fuel system on homing missiles, etc.)

Safe limit: about 20-30 carriers in a game at any given time (about 2 per player in 12 player games)


- Carriers
- Large turrets (multiple different attacks)
- Boss units
- Minigames (arenas)
- Battle Tanks type map
- Multi-purposes tower/units (able to change loadout freely)
- Hero vehicles
- gas tower



- Hugely large diversity
- Comes with 5 stock turrets
- 3 files to help with creating new turrets and importing
- extensive Readme
- support for expansion of the system (extre projectile effects upon landing)
- Intelligent AI with many options
- Can support multiple carrier unit types using the same turrets and still mount correctly
- Turrets stay attached to unit points when they change facing angle
- Multiple behaviours to apply to your turrets, including Fuel, changing Speed, and homing




JASS:
/////////////////////////////////////
//                                 //
//  Turret Mounting System README  //
//                                 //
/////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  If your World Editor does not create variables automatically from JASS variables           //
//  remember to follow the instructions in "Information" and import TMS_VariableCreator        //
//  and it can be deleted after importing as it serves no other function                       //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  The following information is to explain setting up and using your turrets and carriers     //
// to allow the most desireable setup for you map. Firstly a brief explanation of what         //
//  carriers are in this system:                                                               //
//                                                                                             //                                                   
//  Carriers are units which serve as centers for turrets, the turrets should be mounted on    //
//  them, around them or above them. Each carrier has a limit amount of turrets it can         //
//  have mounted at any given time, and destruction of the carrier, will automatically         //
//  destroy all the turrets that are associated with it.                                       //
//                                                                                             // 
//  Setting up carrier units:                                                                  //
//  Carriers have only two variables necessary to run in the system:                           //
//  the udg_TMS_CarrierUnitType vairable and udg_TMS_TurretLimit                               //
//                                                                                             //         
//  udg_TMS_CarrierUnitType: This variable should be set to the data value of your carrier     //
//, to find the data value, press Ctrl + D                                                     //
//  udg_TMS_TurretLimit:     This variable should be set to the maximum number of turrets      //
//  you want your carrier to carry                                                             //
//                                                                                             //                                         
//  To register a unit you use the function "call TMS_RegisterCarrier(UnitID, TurretLimit)     //
// the first value is for the unit type, the second is for the turret limit that you will be   //
//  using for this specific carrier unit, everything else is doen for you                      //
//                                                                                             //
//  This ends the section on carriers                                                          //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Setting up turrets:                                                                        //
//  This section covers creating a turret with the specific features that you wish it to have  //
//                                                                                             //
//  Setting Turret name:                                                                       //
//    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Input turret name"                         //
//                                                                                             //
//  This should be unique to every turret, it can be used to find the turret using the         //
//  TMS_GetTurretByName function, to allow you to find the turret when you don't know the      //
//  registry number assigned to it, if you want to assign players to it (i.e. have one for     //
//  each player so they can be upgraded seperately) it's recommended you add a player number   //
//  to the end of it through a variable or another function i.e. "GetOwningPlayer(unit)"       //
//  so you'd have the name set as "MyTurretName" + GetOwningPlayer(unit) or something similar  //
//  to give greater use the system, and allowing players to seperately upgrade                 //
//                                                                                             //
//  Setting up Models:                                                                         //
//    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "Input turret model"                       //
//    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Input projectile model"               //
//    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Input launch effect model"                //
//    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Input impact effect model"                //
//    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Input death effect model"                  //
//    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"        //
//                                                                                             //
//  to input a model, go into the object editor and select a unit (one you can quickly change  //
//  back to default, and change it's model to the desired model for each feature of the        //
//  turret, press enter twice and then copy the model path, go into your trigger, highlight    //
//  the text, and paste the filepath,next make sure each "\" is a "\\" or it will not work     //
//  by default, model paths will use a single "\", so in almost all cases, you will need to    //
//  change them you do not need the extra "\"s if you're using the GUI version of setting up   //
//                                                                                             //
//  Setting Model scales:                                                                      //
//    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 0.00                                       //
//    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 0.00                                   //
//    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 0.00                                       //
//    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 0.00                                       //
//    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 0.00                                        //
//    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00                                   //
//                                                                                             //
//  Each real is a value of 100% where 1.00 == 1% of the models normal size, set these to      //
//  your desired sizes, (20% - 40% tends to work pretty well)                                  //
//                                                                                             //
//  Setting Turret features:                                                                   //
//    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false                                    //
//    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false                                    //
//    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false                                     //
//    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false                                //
//    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false                                       //
//    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false                               //
//    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = false                                   //
//    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = false                                //
//    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = false                                    //
//    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00                                      //
//                                                                                             //
//  The first three booleans determine whether or not those sfx's are displayed on the turret  //
//  if they are set to false, then there is no need to set a modelpath for the corresponding   //
//  feature.                                                                                   //
//  HaveHoming: Determines if your missile homes in on the target (ignores accuracy modifers)  //
//  HaveRelativeDamage: Determines if units further away from the center of the projectile     //
//  impact, take a reduced amount of damage                                                    //
//  HaveInaccuracy: Determines if projectiles stay off course slightly or not                  //
//  HaveProjectileArc: Determines if projectiles go directly to their target, or arc to them   //
//  HaveTrueSpeed: Determines if a projectile has a fixed speed, or a relative speed based     //
//  on how far it has to travel to reach the target                                            //
//  BonusEffects: Determines if the ProjectileEffects function runs upon projectile            //
//  impact, setting to a value to higher than 0.00 by default, read the bottom for more info   //
//                                                                                             //
//  Setting Real values:                                                                       //
//    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 0.00                                    //
//    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 0.00                                    //
//    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 0.00                                     //
//    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 0.00                              //
//    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 0.00                                        //
//    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.00                                         //
//    set udg_TMS_Range[udg_TMS_TurretInit] = 0.00                                             //
//    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 0.00                                   //
//    set udg_TMS_SpeedOverTimeMultipler[udg_TMS_TurretInit] = 0.00                            //
//    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00                                //
//    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 0.00                                        //
//    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00                                        //
//    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 0.00                                      //
//    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00                                        //
//    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 0.00                                      //
//    set udg_TMS_TurretWeight[udg_TMS_TurretIniit] = 0                                        //
//                                                                                             //
//  MountingHeight: How heigh the turret is placed (added on to carrier fly height)            //
//  MountingOffset: How far from the carrier the turret is placed                              //
//  ProjectileAOE: Area of effect (damage) the projectile has                                  //
//  AoeDamageDissapation: (Requires HaveRelativeDamage) determines rate of damage loss         //
//  Inaccuracy: (Requires HaveInaccuracy) determines how inaccurate a projectile is            //
//  ArcFactor: (Requires HaveProjectileArc) determines the ratio of distance to Arc height     //
//  Range: Determines how far the turret can search for a target/can fire                      //
//  ProjectileSpeed: (Requires HaveTrueSpeed = true) sets how fast the projectile travels      //
//  SpeedOverTimeMultipler: Exponentially changes the speed of your missile (1 is normal)      //
//  SpeedOverTimeFixed: Adds this value to your projectile speed each cycle                    //
//  SpeedLimit: Projectiles with changing speed, will not be able to supass this number        //
//  ImpactTime: (Requires HaveTrueSpeed = false) how fast a projectile hits it's target        //
//  HealthDamage: Determines damage done to health upon impact with projectile                 //
//  ManaDamage: Determines damage done to mana upon impact with projectile                     //
//  FireCooldown: Determines the firing rate of the turret                                     //
//  TurretWeight: Determines how many turret slots it uses (1 is standard)                     //
//                                                                                             //
//  Every time based variable (i.e. FireCooldown) is in seconds                                //
//                                                                                             //
//  Setting Targetting information:                                                            //
//    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 0                                     //
//    set udg_TMS_TargetType[udg_TMS_TurretInit] = 0                                           //
//    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 0                                         //
//    set udg_TMS_TargetLock[udg_TMS_TurretInit] = false                                       //
//                                                                                             //
//  TargettingMethod:                                                                          //
//    1 - Target Enemy with highest max health                                                 //
//    2 - Target Enemy with highest current health                                             //
//    3 - Target Enemy with lowest max health                                                  //
//    4 - Target Enemy with lowest current health                                              //
//    5 - Target Enemy with highest max mana                                                   //
//    6 - Target Enemy with highest current mana                                               //
//    7 - Target Enemy with lowest max mana                                                    //
//    8 - Target Enemy with lowest current mana                                                //
//    9 - Target closest Enemy                                                                 //
//    10 - Target furthest away Enemy                                                          //
//    11 - Manual Targetting (Target must be selected by a trigger function elsewhere)         //
//                                                                                             //
//  TargetType:                                                                                //
//    1 - Target is an Enemy                                                                   //
//    2 - Target is an Enemy Hero                                                              //
//    3 - Target is a Normal Unit                                                              //
//                                                                                             //
//  TargetStatus:                                                                              //
//    1 - will mean your turret will only attack/target flyers                                 //
//    2 - will mean your turret will only attack/target ground units                           //
//    3 - will mean your turret will attack/target both ground and flying units                //
//    4 - will mean your turret will only attack/target ground units and structures            //
//    5 - will mean your turret will only attack/target flyers and structures                  //
//    6 - will mean your turret will attack only structures                                    //
//    7 - will mean your turret will attack/target ground units, flyers and structures         //
//                                                                                             //
//  TargetLock:                                                                                //
//    True - Will target one unit, and constantly attack it until it dies or leaves range      //
//    False - Will constantly retarget to attack the target most fitting to its targetting AI  //
//                                                                                             //
//  When you have set all these variables to what you want in a trigger, use the function      //
//  call TMS_RegisterTurret(0)                                                                 //
//  It will take the data you have set above the function, and create a turret with it         //
//  allowing you to then use the turret for your carriers                                      //
//                                                                                             //
//  This concludes the guide on setting up your turret, if anything remains unclear, playing   //
//  with the configurables will soon explain what each one does                                //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Attack and Damage Type:                                                                    //
//    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL                          //
//    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL                          //
//                                                                                             //
//  Setting these types will change resistances of your targets, MAGIC damage will not hurt    //
//  magic immune targets, and as such, turrets with that damage type, will not target them     //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Adding a turret to a carrier:                                                              //
//    call TMS_AddTurret(Unit, TurretNumber, TurretAmount)                                     //
//                                                                                             //
//  Calling this function will add TurretAmount turrets of type TurretNumber, to Unit          //
//  E.g. call TMS_AddTurret(u, 1, 3)                                                           //
//  The above example will add 3 turrets of type 1 to unit u                                   //
//                                                                                             //
//  If you add more turrets than a unit has room for, you will recieve an error message for    //
//  every extra turret that you tried to add                                                   //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Removing a turret from a carrier                                                           //
//   call TMS_DestroyTurrets(Unit, TurretNumber, TurretAmount)                                 //
//                                                                                             //
//  The same deal with this function, TurretAmount turrets of TurretNumber removed from unit   //
//  E.g. call TMS_DestroyTurrets(u, 1, 3)                                                      //
//  The above example will remove 3 turrets of type 1 from unit u                              //
//                                                                                             //
//  If you remove more turrets from a unit than it has, then it will remove all the ones of    //
//  that type that it is carrying                                                              //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Updating a turret                                                                          //
//                                                                                             //
//  Some of you may have noticed that earlier in the "Creating a turret" section that the      //
//  function at the end (TMS_RegisterTurret) was passed a 0 this is because the system also    //
//  supports turret updating, allowing you to change already existing turrets, to a new form   //
//  you do this by passing the number of the turret you want to update to the function         //
//  so if you want to update turret 1, pass a 1 to the function like so:                       //
//    call TMS_RegisterTurret(1)                                                               //
//                                                                                             //
//  However, some maps will not know which order the turrets were necessarily registered in    //
//  (say, a player had to "Buy" them in the map to unlock them, and then they bought an        //
//  upgrade) well, the system also comes with the handy function of TMS_GetTurretByName        //
//  the function will need to be passed the name of your turret, and it will automatically     //
//  find the turret for you in the system, and return the number of the turret, which makes    //
//  it much easier to update turrets when you don't necessarily know their position            //
//                                                                                             //
//  Example:                                                                                   //
//    call TMS_RegisterTurret(TMS_GetTurretByName("MyTurret"))                                 //
//                                                                                             //
//  Slightly more costly on your processor to run the extra functions, but makes things much   //
//  easier, but lets say you want an upgrade to only happen for one person?                    //
//  well, the easiest way to go about this, is to - when you register a turret, to append      //
//  a player number to the end, i.e. "MyTurret1" for player 1 and such, well by utilising      //
//  the TMS_GetTurretByName function, this is also relatively easy to do by using a            //
//  combinations of strings, you can do this by setting a variable to the player number        //
//  or, if you know what you're doing with them, use a function to get the player number       //
//  within the function call                                                                   //
//                                                                                             //
//  Examples:                                                                                  //
//    call TMS_RegisterTurret(TMS_GetTurretByName("MyTurret" + udg_TMS_TempPlayer))            //
//    call TMS_RegiserTurret(TMS_GetTurretByName("MyTurret" + GetOwningPlayer(Unit)))          //
//                                                                                             //
//  Using the update fuction cal also help you recycle turrets, though, it'd require a bit of  //
//  programming knowledge, you could set a variable to the "Next turret" to be recyled's name  //
//  and then when registering the new turret to replace the old one, you can again use the     //
//  TMS_GetTurretByName function, to replace it, though, this is not recommended to do, if     //
//  any of those turrets which are to be replaced, are currently in use, as they will change   //
//  automatically, to match the new turret, hence it's primary design, is for updating         //
//  turrets, into upgraded forms                                                               //
//                                                                                             //
//  If no turret is found by TMS_GetTurretByName it returns 0 (TMS_RegisterTurret will create  //
//  a new turret in this case)                                                                 //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Functions List:                                                                            //
//    call TMS_RegisterCarrier(UnitID, TurretLimit)                                            //
//    call TMS_RegisterTurret()                                                                //
//    call TMS_AddTurret(Unit, TurretType, Amount)                                             //
//    call TMS_DestroyTurrets(Unit, TurretType, Amount)                                        //
//    call TMS_GetTurretByName(Name)                                                           //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Bonus effects:                                                                             //
//                                                                                             //
//  This variable is used to allow building off from the system when your projectile lands     //
//  to give additional effects to them, allowing more interesting and advanced projectiles     //
//  to use, in your turret setup set udg_TMS_BonusEffects[udg_TMS_TurretInit] = (number        //
//  which is higher than 0) remember this number, then you can either write your own JASS      //
//  functions, or GUI trigger, using the event "Game - udg_TMS_ActivateEffects becomes         //
//  (your number)" when a projectile lands, ActivateEffectes becomes the same as the number    //
//  you chose, so doing this will cause those effects to run when the projectile lands         //
//                                                                                             //
//  Additional Information:                                                                    //
//                                                                                             //
//  udg_TMS_TempX and udg_TMS_TempY will already be set to the co-ordinates of the impact      //
//  udg_TMS_TurretType will already be set to the TurretType associated with the projectile    //
//  These variables can help you make your function/trigger more efficient and easier to       //
//  write on your part, so don't be shy to use them when you feel the need to                  //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  En masse:                                                                                  //
//                                                                                             //
//  This system is NOT designed for large amounts of units all mounting turrets in it's        //
//  current form (with the AI and most things trigger controlled) if you are intending         //
//  to use it for many units then there are a few changes that can be made to keep this        //
//  from slowing down your computer, though you will lose quite a large amount of the          //
//  functionality, while maintaining the concept (turrets mounted on other units               //
//  firstly: you can delete all of the code in the system marked with //*+ to //*-             //
//  read through the script and delete all code which appears between these markers*           //
//  secondly, you will need to modify the TMS_CreateTurrets() function to create different     //
//  unit types other than dummies (all turret registering data can be deleted other than the   //
//  ID and you will need to add your own variable to note the unit to be attached)             //
//  basically, all trigger functions except keeping the turrets mounted will become object     //
//  data                                                                                       //
//                                                                                             //
//  This section is only suggested to those with triggering knowledge to be able to carry it   //
//  out correctly.                                                                             //
//                                                                                             //
//  *Some may be necessary - it's hard to tell due to the length but I'm pretty certain that   //
//  which is marked it fine to delete - just keep a reference of the original incase I'm       //
//  wrong about that                                                                           //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////
//                                 //
//  Thank you for reading the      //
//  TurretSystem Readme            //
//                                 //
/////////////////////////////////////



JASS:
//////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                              //
//                          Turret Mounting System V1.10                                        //
//  Author: Tank-Commander                                                                      //
//  Requirements: Dummy.mdl                                                                     //
//                                                                                              //
//  Purpose: Allow players to mount turrets onto their normal units to make bosses and such     //
//                                                                                              //      
//  Comments: - Credits must be given if you use this system in your map                        //
//            - Read the readme section on how to set up your own turrets and carriers          //
//            - Use the function TMS_AddTurret (Unit, TurretNumber, TurretCount)                //
//            - Functions explained in the Readme                                               //
//                                                                                              //
//////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////
//                 //
//  Configuration  //
//                 //
/////////////////////

function InitTrig_TMS_TurretMountingSystem takes nothing returns nothing
    //Error messages for the system
    set udg_TMS_ErrorMessages[0] = "This unit cannot have turrets mounted"
    set udg_TMS_ErrorMessages[1] = "Turret limit reached"
    set udg_TMS_ErrorMessages[2] = "You need to specify the number of turrets to mount"
    set udg_TMS_ErrorMessages[3] = "You need to specify the turret type number"
    //Determines the default limit for units not registered in the Carrier Units setup
    set udg_TMS_DefaultLimit = 0
    // Determines the how long death effects play for before the unit is removed
    set udg_TMS_DeathTimer = 1.00
    // Determines the dummy used for the turrets
    set udg_TMS_DummyType = 'u001'
    // Determines the height proximity a projectile can have, to it's target to make contact with it
    set udg_TMS_HeightLet = 75
    // --------
    // Determines the Speed of the loop trigger
    set udg_TMS_TimerSpeed = 0.031250000
endfunction

////////////////////////////
//                        //
//  End of configuration  //
//                        //
////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                             //
//     Below is the script to run the system, unless you want to make a modification to how    //
//     the system works, it's highly recommended that you do not bother scrolling further      //
//     - Tank-Commander                                                                        //
//                                                                                             //
/////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function which can be used to locate a turret in the registry, based on the name of the    //
//  turret you have used, names should be unique to every turret in the registry, like the     //
//  number, returns the number in the registry                                                 //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_GetTurretByName takes string Name returns integer
    set udg_TMS_Index = 1
    loop
        exitwhen udg_TMS_Index > udg_TMS_TurretNumber            
        if (udg_TMS_TurretName[udg_TMS_Index] == Name) then
            return udg_TMS_Index
        endif
        set udg_TMS_Index = udg_TMS_Index + 1
    endloop
    return 0
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function which updates pre-existing turrets, when a change is made to that turret in the   //
//  registry, specifically, this is for updating the turret model, and size                    //
/////////////////////////////////////////////////////////////////////////////////////////////////

//*+
function TMS_UpdateTurrets takes integer UpdatedTurretType returns nothing
    set udg_TMS_Index = 1
    loop
        exitwhen udg_TMS_Index > udg_TMS_MaxIndex            
        if (udg_TMS_TurretType[udg_TMS_Index] == UpdatedTurretType) and (udg_TMS_StageID[udg_TMS_Index] == 2)then
            call DestroyEffect(udg_TMS_CurrentEffect[udg_TMS_Index])
            set udg_TMS_CurrentEffect[udg_TMS_Index] = AddSpecialEffectTarget(udg_TMS_TurretModel[UpdatedTurretType], udg_TMS_UnitIndex[udg_TMS_Index], "origin")
            call SetUnitScale(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_TurretScale[UpdatedTurretType] * 0.01, 0.00, 0.00)
        endif
        set udg_TMS_Index = udg_TMS_Index + 1
    endloop
endfunction
//*-

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function ussed for registering Turrets into the system                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_RegisterTurret takes integer RegisterNumber returns nothing
    if (RegisterNumber == 0) then
        set udg_TMS_TurretNumber = ( udg_TMS_TurretNumber + 1 )
        set udg_TMS_TempInteger = udg_TMS_TurretNumber
    else
        set udg_TMS_TempInteger = RegisterNumber
    endif
    set udg_TMS_TurretName[udg_TMS_TempInteger] = udg_TMS_TurretName[udg_TMS_TurretInit]
    //*+
    set udg_TMS_TurretModel[udg_TMS_TempInteger] = udg_TMS_TurretModel[udg_TMS_TurretInit]
    set udg_TMS_ProjectileModel[udg_TMS_TempInteger] = udg_TMS_ProjectileModel[udg_TMS_TurretInit]
    set udg_TMS_LaunchModel[udg_TMS_TempInteger] = udg_TMS_LaunchModel[udg_TMS_TurretInit]
    set udg_TMS_ImpactModel[udg_TMS_TempInteger] = udg_TMS_ImpactModel[udg_TMS_TurretInit]
    set udg_TMS_DeathModel[udg_TMS_TempInteger] = udg_TMS_DeathModel[udg_TMS_TurretInit]
    set udg_TMS_TargettingModel[udg_TMS_TempInteger] = udg_TMS_TargettingModel[udg_TMS_TurretInit]
    set udg_TMS_TurretScale[udg_TMS_TempInteger] = udg_TMS_TurretScale[udg_TMS_TurretInit]
    set udg_TMS_ProjectileScale[udg_TMS_TempInteger] = udg_TMS_ProjectileScale[udg_TMS_TurretInit]
    set udg_TMS_LaunchScale[udg_TMS_TempInteger] = udg_TMS_LaunchScale[udg_TMS_TurretInit]
    set udg_TMS_ImpactScale[udg_TMS_TempInteger] = udg_TMS_ImpactScale[udg_TMS_TurretInit]
    set udg_TMS_DeathScale[udg_TMS_TempInteger] = udg_TMS_DeathScale[udg_TMS_TurretInit]
    set udg_TMS_TargettingScale[udg_TMS_TempInteger] = udg_TMS_TargettingScale[udg_TMS_TurretInit]
    set udg_TMS_HaveLaunchSfx[udg_TMS_TempInteger] = udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit]
    set udg_TMS_HaveImpactSfx[udg_TMS_TempInteger] = udg_TMS_HaveImpactSfx[udg_TMS_TurretInit]
    set udg_TMS_HaveDeathSfx[udg_TMS_TempInteger] = udg_TMS_HaveDeathSfx[udg_TMS_TurretInit]
    set udg_TMS_HaveTargettingSfx[udg_TMS_TempInteger] = udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit]
    set udg_TMS_HaveHoming[udg_TMS_TempInteger] = udg_TMS_HaveHoming[udg_TMS_TurretInit]
    set udg_TMS_HaveRelativeDamage[udg_TMS_TempInteger] = udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit]
    set udg_TMS_HaveInaccuracy[udg_TMS_TempInteger] = udg_TMS_HaveInaccuracy[udg_TMS_TurretInit]
    set udg_TMS_HaveProjectileArc[udg_TMS_TempInteger] = udg_TMS_HaveProjectileArc[udg_TMS_TurretInit]
    set udg_TMS_HaveTrueSpeed[udg_TMS_TempInteger] = udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit]
    set udg_TMS_BonusEffects[udg_TMS_TempInteger] = udg_TMS_BonusEffects[udg_TMS_TurretInit]
    set udg_TMS_MountingHeight[udg_TMS_TempInteger] = udg_TMS_MountingHeight[udg_TMS_TurretInit]
    set udg_TMS_MountingOffset[udg_TMS_TempInteger] = udg_TMS_MountingOffset[udg_TMS_TurretInit]
    set udg_TMS_ProjectileAOE[udg_TMS_TempInteger] = udg_TMS_ProjectileAOE[udg_TMS_TurretInit]
    set udg_TMS_AoeDamageDissapation[udg_TMS_TempInteger] = udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit]
    set udg_TMS_Inaccuracy[udg_TMS_TempInteger] = udg_TMS_Inaccuracy[udg_TMS_TurretInit]
    set udg_TMS_ArcFactor[udg_TMS_TempInteger] = udg_TMS_ArcFactor[udg_TMS_TurretInit]
    set udg_TMS_Range[udg_TMS_TempInteger] = udg_TMS_Range[udg_TMS_TurretInit]
    set udg_TMS_ProjectileSpeed[udg_TMS_TempInteger] = udg_TMS_ProjectileSpeed[udg_TMS_TurretInit]
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TempInteger] = udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit]
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TempInteger] = udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit]
    set udg_TMS_SpeedLimit[udg_TMS_TempInteger] = udg_TMS_SpeedLimit[udg_TMS_TurretInit]
    set udg_TMS_ProjectileFuel[udg_TMS_TempInteger] = udg_TMS_ProjectileFuel[udg_TMS_TurretInit]
    set udg_TMS_ImpactTime[udg_TMS_TempInteger] = udg_TMS_ImpactTime[udg_TMS_TurretInit]
    set udg_TMS_HealthDamage[udg_TMS_TempInteger] = udg_TMS_HealthDamage[udg_TMS_TurretInit]
    set udg_TMS_ManaDamage[udg_TMS_TempInteger] = udg_TMS_ManaDamage[udg_TMS_TurretInit]
    set udg_TMS_FireCooldown[udg_TMS_TempInteger] = udg_TMS_FireCooldown[udg_TMS_TurretInit]
    //*-
    set udg_TMS_TurretWeight[udg_TMS_TempInteger] = udg_TMS_TurretWeight[udg_TMS_TurretInit]
    //*+
    set udg_TMS_TargettingMethod[udg_TMS_TempInteger] = udg_TMS_TargettingMethod[udg_TMS_TurretInit]
    set udg_TMS_TargetType[udg_TMS_TempInteger] = udg_TMS_TargetType[udg_TMS_TurretInit]
    set udg_TMS_TargetStatus[udg_TMS_TempInteger] = udg_TMS_TargetStatus[udg_TMS_TurretInit]
    set udg_TMS_TargetLock[udg_TMS_TempInteger] = udg_TMS_TargetLock[udg_TMS_TurretInit]
    set udg_TMS_AttackType[udg_TMS_TempInteger] = udg_TMS_AttackType[udg_TMS_TurretInit]
    set udg_TMS_DamageType[udg_TMS_TempInteger] = udg_TMS_DamageType[udg_TMS_TurretInit]
    call TMS_UpdateTurrets(udg_TMS_TempInteger)
    //*-
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function ussed for registering Carriers into the system                                    //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_RegisterCarrier takes integer UnitID, integer CarryNumber returns nothing
    set udg_TMS_TempInteger = -1
    set udg_TMS_Index = 1
    loop
        exitwhen udg_TMS_Index > udg_TMS_CarrierTypesCount or udg_TMS_TempInteger != -1            
        if (UnitID == udg_TMS_CarrierUnitType[udg_TMS_Index]) then
            set udg_TMS_TempInteger = udg_TMS_Index
        endif
        set udg_TMS_Index = udg_TMS_Index + 1
    endloop
    if (udg_TMS_TempInteger == -1) then
        set udg_TMS_CarrierTypesCount = udg_TMS_CarrierTypesCount + 1
        set udg_TMS_TempInteger = udg_TMS_CarrierTypesCount
    endif
    set udg_TMS_CarrierUnitType[udg_TMS_TempInteger] = UnitID
    set udg_TMS_TurretLimit[udg_TMS_TempInteger] = CarryNumber
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function used for managing the data filtered by TMS_TargetFilers                           //
/////////////////////////////////////////////////////////////////////////////////////////////////

//*+
function TMS_FilterData takes unit u returns nothing
    set udg_TMS_TempReal2 = udg_TMS_TempReal
    set udg_TMS_TempUnit3 = u
    set u = null
endfunction
//*-

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function used for identifying targets for turrets, and those who take damage from the      //
//  impact from a projectile of those turrets, also tells turrets when they need to retarget   //
//  upon the death of those targets.                                                           //
/////////////////////////////////////////////////////////////////////////////////////////////////

//*+
function TMS_TargetFilter takes unit u returns nothing
    set udg_TMS_TempPlayer = GetOwningPlayer(udg_TMS_MountedUnit[udg_TMS_Index])
    if (IsUnitEnemy(u, udg_TMS_TempPlayer)) and (GetUnitState(u, UNIT_STATE_LIFE) > 0) then
        if(udg_TMS_TargetType[udg_TMS_TurretType[udg_TMS_Index]] == 2 and not IsUnitType(u, UNIT_TYPE_HERO)) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        elseif (udg_TMS_TargetType[udg_TMS_TurretType[udg_TMS_Index]] == 3 and IsUnitType(u, UNIT_TYPE_HERO)) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
        if ((udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 1) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 5) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 6)) and (IsUnitType(u, UNIT_TYPE_GROUND)) then
            if ((udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 5) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 6)) and (not IsUnitType(u, UNIT_TYPE_STRUCTURE)) then
                call GroupRemoveUnit(udg_TMS_TempGroup, u)
            else
                call GroupRemoveUnit(udg_TMS_TempGroup, u)
            endif                   
        endif
        if (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 2) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 4) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 6) and (IsUnitType(u, UNIT_TYPE_FLYING)) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
        if (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 1) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 2) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 3) and (IsUnitType(u, UNIT_TYPE_STRUCTURE)) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
        if (udg_TMS_DamageType[udg_TMS_TurretType[udg_TMS_Index]] == DAMAGE_TYPE_MAGIC) and (IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
    else
        call GroupRemoveUnit(udg_TMS_TempGroup, u)
    endif
    if (IsUnitInGroup(u, udg_TMS_TempGroup)) then
        if (udg_TMS_FilterMode == 2) then
            if (udg_TMS_HaveRelativeDamage[udg_TMS_TurretType[udg_TMS_Index]]) then
                set udg_TMS_TempX = GetUnitX(udg_TMS_UnitIndex[udg_TMS_Index])
                set udg_TMS_TempY = GetUnitY(udg_TMS_UnitIndex[udg_TMS_Index])
                set udg_TMS_TempX2 = GetUnitX(u)
                set udg_TMS_TempY2 = GetUnitY(u)
                set udg_TMS_TempReal = SquareRoot(((udg_TMS_TempX2 - udg_TMS_TempX) * (udg_TMS_TempX2 - udg_TMS_TempX)) + ((udg_TMS_TempY2 - udg_TMS_TempY) * (udg_TMS_TempY2 - udg_TMS_TempY)))
                set udg_TMS_TempReal = udg_TMS_TempReal / udg_TMS_AoeDamageDissapation[udg_TMS_TurretType[udg_TMS_Index]]
                if (udg_TMS_TempReal < 1.00) then
                    set udg_TMS_TempReal = 1.00
                endif
                set udg_TMS_TempReal2 = udg_TMS_ManaDamage[udg_TMS_TurretType[udg_TMS_Index]] / udg_TMS_TempReal
                set udg_TMS_TempReal3 = udg_TMS_HealthDamage[udg_TMS_TurretType[udg_TMS_Index]] / udg_TMS_TempReal
            else
                set udg_TMS_TempReal2 = udg_TMS_ManaDamage[udg_TMS_TurretType[udg_TMS_Index]]
                set udg_TMS_TempReal3 = udg_TMS_HealthDamage[udg_TMS_TurretType[udg_TMS_Index]]
            endif
            call UnitDamageTarget(udg_TMS_MountedUnit[udg_TMS_Index], u, udg_TMS_TempReal3, true, false, udg_TMS_AttackType[udg_TMS_TurretType[udg_TMS_Index]], udg_TMS_DamageType[udg_TMS_TurretType[udg_TMS_Index]], null)
            call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MANA) - udg_TMS_TempReal2)
            if (IsUnitType(u, UNIT_TYPE_DEAD)) and ((GetUnitTypeId(u) != 0)) then
                set udg_TMS_SecondaryIndex = 1
                loop
                    exitwhen udg_TMS_SecondaryIndex > udg_TMS_MaxIndex
                    if(u == udg_TMS_SelectedTarget[udg_TMS_SecondaryIndex]) then
                        set udg_TMS_SelectedTarget[udg_TMS_SecondaryIndex] = null
                    endif
                    set udg_TMS_SecondaryIndex = udg_TMS_SecondaryIndex + 1
                endloop
            endif
        else
            if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 1) then
                set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_LIFE)
                if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                else
                    call TMS_FilterData(u)
                endif
            elseif(udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 2) then
                set udg_TMS_TempReal = GetWidgetLife(u)
                if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                else
                    call TMS_FilterData(u)
                endif                
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 3) then
                set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_LIFE)
                if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
                    call TMS_FilterData(u)
                else
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                endif
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 4) then
               set udg_TMS_TempReal = GetWidgetLife(u)
               if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
                    call TMS_FilterData(u)
                else
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                endif   
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 5) then
                set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_MANA)
                if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                else
                    call TMS_FilterData(u)
                endif
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 6) then
                set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MANA)
                if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                else
                    call TMS_FilterData(u)
                endif
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 7) then
                set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_MANA)
                if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
                    call TMS_FilterData(u)
                else
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                endif
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 8) then
                set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MANA)
                if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
                    call TMS_FilterData(u)
                else
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                endif
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 9) then
                set udg_TMS_TempX = GetUnitX(udg_TMS_MountedUnit[udg_TMS_Index])
                set udg_TMS_TempY = GetUnitY(udg_TMS_MountedUnit[udg_TMS_Index])
                set udg_TMS_TempX2 = GetUnitX(u)
                set udg_TMS_TempY2 = GetUnitY(u)
                set udg_TMS_TempReal = ((udg_TMS_TempX2 - udg_TMS_TempX) * (udg_TMS_TempX2 - udg_TMS_TempX)) + ((udg_TMS_TempY2 - udg_TMS_TempY) * (udg_TMS_TempY2 - udg_TMS_TempY))
                if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
                    call TMS_FilterData(u)
                else
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                endif            
            elseif (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 10) then
                set udg_TMS_TempX = GetUnitX(udg_TMS_MountedUnit[udg_TMS_Index])
                set udg_TMS_TempY = GetUnitY(udg_TMS_MountedUnit[udg_TMS_Index])
                set udg_TMS_TempX2 = GetUnitX(u)
                set udg_TMS_TempY2 = GetUnitY(u)
                set udg_TMS_TempReal = ((udg_TMS_TempX2 - udg_TMS_TempX) * (udg_TMS_TempX2 - udg_TMS_TempX)) + ((udg_TMS_TempY2 - udg_TMS_TempY) * (udg_TMS_TempY2 - udg_TMS_TempY))
                if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
                    call GroupRemoveUnit(udg_TMS_TempGroup, u)
                else
                    call TMS_FilterData(u)
                endif            
            endif
        endif
    endif
    set u = null
endfunction
//*-

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function used to retarget the turrets attached to a carrier, calls the TargetFilter        //
//  function to identify valid targets for that specific turret type                           //
/////////////////////////////////////////////////////////////////////////////////////////////////

//*+
function TMS_FindTarget takes integer TurretNumber returns unit
    set udg_TMS_TempReal2 = -1.00
    set udg_TMS_FilterMode = 1
    set udg_TMS_TempUnit2 = null
    set udg_TMS_TempUnit3 = null
    call GroupEnumUnitsInRange(udg_TMS_TempGroup, udg_TMS_TempX, udg_TMS_TempY, udg_TMS_Range[TurretNumber], null)
    loop
        set udg_TMS_TempUnit2 = FirstOfGroup(udg_TMS_TempGroup)
        exitwhen udg_TMS_TempUnit2 == null
        call TMS_TargetFilter(udg_TMS_TempUnit2)
        call GroupRemoveUnit(udg_TMS_TempGroup, udg_TMS_TempUnit2)
    endloop
    return udg_TMS_TempUnit3
endfunction
//*-

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function that controls the creation of new projectiles, sets their trajectory and speeds   //
//  depending on the configuration set up by the user, does not call any other functions       //
/////////////////////////////////////////////////////////////////////////////////////////////////

//*+
function TMS_FireProjectile takes unit Turret, unit Target returns nothing
    local real X = GetUnitX(Turret)
    local real X2 = GetUnitX(Target)
    local real Y = GetUnitY(Turret)
    local real Y2 = GetUnitY(Target)
    local real dx
    local real dy
    if (udg_TMS_HaveInaccuracy[udg_TMS_TurretType[udg_TMS_Index]]) then
        set udg_TMS_Angle = GetRandomReal(-bj_PI, bj_PI)
        set X2 = X2 + GetRandomReal(-bj_PI, udg_TMS_Inaccuracy[udg_TMS_TurretType[udg_TMS_Index]]) * Cos(udg_TMS_Angle)
        set Y2 = Y2 + GetRandomReal(-bj_PI, udg_TMS_Inaccuracy[udg_TMS_TurretType[udg_TMS_Index]]) * Sin(udg_TMS_Angle)
    endif
    set dx = X2 - X
    set dy = Y2 - Y
    set udg_TMS_Angle = Atan2(dy, dx)    
    set udg_TMS_MaxIndex = udg_TMS_MaxIndex + 1
    set udg_TMS_TurretType[udg_TMS_MaxIndex] = udg_TMS_TurretType[udg_TMS_Index]
    set udg_TMS_MaxDistance[udg_TMS_MaxIndex] = SquareRoot(dx * dx + dy * dy)
    set udg_TMS_MaxHeight[udg_TMS_MaxIndex] = udg_TMS_MaxDistance[udg_TMS_MaxIndex] * udg_TMS_ArcFactor[udg_TMS_TurretType[udg_TMS_MaxIndex]]
    set udg_TMS_CurrentDistance[udg_TMS_MaxIndex] = 0.00
    set udg_TMS_StackedCorrection[udg_TMS_MaxIndex] = 0.00
    set udg_TMS_CurrentHeight[udg_TMS_MaxIndex] = udg_TMS_ZHeight[udg_TMS_Index]
    set udg_TMS_SelectedTarget[udg_TMS_MaxIndex] = udg_TMS_SelectedTarget[udg_TMS_Index]
    set udg_TMS_TempReal2 = GetUnitFlyHeight(udg_TMS_SelectedTarget[udg_TMS_Index])
    set udg_TMS_StageID[udg_TMS_MaxIndex] = 3
    set udg_TMS_MountedUnit[udg_TMS_MaxIndex] = udg_TMS_MountedUnit[udg_TMS_Index]
    set udg_TMS_PositionAngle[udg_TMS_MaxIndex] = udg_TMS_Angle
    set udg_TMS_ZHeight[udg_TMS_MaxIndex] = udg_TMS_ZHeight[udg_TMS_Index]
    set udg_TMS_UnitIndex[udg_TMS_MaxIndex] = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), udg_TMS_DummyType, X, Y, udg_TMS_Angle * bj_RADTODEG)   
    if UnitAddAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') and UnitRemoveAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') then
    endif
    if (udg_TMS_HaveHoming[udg_TMS_TurretType[udg_TMS_Index]]) then
         call UnitApplyTimedLife(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 1, udg_TMS_ProjectileFuel[udg_TMS_TurretType[udg_TMS_MaxIndex]])
    endif
    set udg_TMS_CurrentEffect[udg_TMS_MaxIndex] = AddSpecialEffectTarget(udg_TMS_ProjectileModel[udg_TMS_TurretType[udg_TMS_MaxIndex]], udg_TMS_UnitIndex[udg_TMS_MaxIndex], "origin")
    call SetUnitScale(udg_TMS_UnitIndex[udg_TMS_MaxIndex], udg_TMS_ProjectileScale[udg_TMS_TurretType[udg_TMS_MaxIndex]] * 0.01, 0.00, 0.00)
    if (udg_TMS_HaveTrueSpeed[udg_TMS_TurretType[udg_TMS_MaxIndex]]) then
        set udg_TMS_MovementSpeed[udg_TMS_MaxIndex] = udg_TMS_ProjectileSpeed[udg_TMS_TurretType[udg_TMS_MaxIndex]]
    else
        set udg_TMS_MovementSpeed[udg_TMS_MaxIndex] = (udg_TMS_MaxDistance[udg_TMS_MaxIndex] / udg_TMS_ImpactTime[udg_TMS_TurretType[udg_TMS_MaxIndex]]) * udg_TMS_TimerSpeed
    endif
    set udg_TMS_HeightCorrection[udg_TMS_MaxIndex] = (udg_TMS_TempReal2 - udg_TMS_CurrentHeight[udg_TMS_MaxIndex]) / (udg_TMS_MaxDistance[udg_TMS_MaxIndex] / udg_TMS_MovementSpeed[udg_TMS_MaxIndex])
    if (udg_TMS_HaveTargettingSfx[udg_TMS_TurretType[udg_TMS_Index]]) then
        if (udg_TMS_HaveHoming[udg_TMS_TurretType[udg_TMS_MaxIndex]]) then
            set udg_TMS_TargettingEffect[udg_TMS_MaxIndex] = AddSpecialEffectTarget(udg_TMS_TargettingModel[udg_TMS_TurretType[udg_TMS_MaxIndex]], Target, "origin") 
        else
            set udg_TMS_TempUnit3 = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), udg_TMS_DummyType, X2, Y2, udg_TMS_Angle * bj_RADTODEG)
            set udg_TMS_TargettingUnit[udg_TMS_MaxIndex] = udg_TMS_TempUnit3
            set udg_TMS_TargettingEffect[udg_TMS_MaxIndex] = AddSpecialEffectTarget(udg_TMS_TargettingModel[udg_TMS_TurretType[udg_TMS_MaxIndex]], udg_TMS_TargettingUnit[udg_TMS_MaxIndex], "origin") 
            call SetUnitScale(udg_TMS_TargettingUnit[udg_TMS_MaxIndex], udg_TMS_TargettingScale[udg_TMS_TurretType[udg_TMS_MaxIndex]] * 0.01, 0.00, 0.00)
            call SetUnitFlyHeight(udg_TMS_TargettingUnit[udg_TMS_MaxIndex], udg_TMS_TempReal2, 0.00)
            set udg_TMS_MaxIndex = udg_TMS_MaxIndex + 1
            set udg_TMS_StageID[udg_TMS_MaxIndex] = 5
            set udg_TMS_UnitIndex[udg_TMS_MaxIndex] = udg_TMS_TempUnit3
        endif
    endif
    if (udg_TMS_HaveLaunchSfx[udg_TMS_TurretType[udg_TMS_Index]]) then
        set udg_TMS_MaxIndex = udg_TMS_MaxIndex + 1
        set udg_TMS_StageID[udg_TMS_MaxIndex] = 4
        set udg_TMS_TurretType[udg_TMS_MaxIndex] = udg_TMS_TurretType[udg_TMS_Index]
        set udg_TMS_UnitIndex[udg_TMS_MaxIndex] = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), udg_TMS_DummyType, X, Y, udg_TMS_Angle * bj_RADTODEG)
        if UnitAddAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') and UnitRemoveAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') then
        endif     
        call SetUnitFlyHeight(udg_TMS_UnitIndex[udg_TMS_MaxIndex], udg_TMS_ZHeight[udg_TMS_Index], 0.00)
        call SetUnitScale(udg_TMS_UnitIndex[udg_TMS_MaxIndex], udg_TMS_LaunchScale[udg_TMS_TurretType[udg_TMS_MaxIndex]] * 0.01, 0.00, 0.00)
        call DestroyEffect(AddSpecialEffectTarget(udg_TMS_LaunchModel[udg_TMS_TurretType[udg_TMS_MaxIndex]], udg_TMS_UnitIndex[udg_TMS_MaxIndex], "origin"))
    endif
    if (not udg_TMS_HaveProjectileArc[udg_TMS_TurretType[udg_TMS_MaxIndex]]) then
        set udg_TMS_TempReal3 = (Atan(4 * udg_TMS_CurrentHeight[udg_TMS_MaxIndex] / udg_TMS_MaxDistance[udg_TMS_MaxIndex] - 8 * udg_TMS_CurrentHeight[udg_TMS_MaxIndex] * udg_TMS_CurrentDistance[udg_TMS_MaxIndex] / (udg_TMS_MaxDistance[udg_TMS_MaxIndex] * udg_TMS_MaxDistance[udg_TMS_MaxIndex])) * bj_RADTODEG + 0.5) + 45
        call SetUnitAnimationByIndex(udg_TMS_UnitIndex[udg_TMS_MaxIndex],R2I(udg_TMS_TempReal3))
    endif
    set Turret = null
    set Target = null
endfunction
//*-

/////////////////////////////////////////////////////////////////////////////////////////////////
//  function used for controlling the facing of turrets when they have or find a target        //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_TurretFacing takes nothing returns nothing
    set udg_TMS_TempX2 = GetUnitX(udg_TMS_SelectedTarget[udg_TMS_Index])
    set udg_TMS_TempY2 = GetUnitY(udg_TMS_SelectedTarget[udg_TMS_Index])
    set udg_TMS_TempReal = udg_TMS_TempX2 - udg_TMS_TempX
    set udg_TMS_TempReal2 = udg_TMS_TempY2 - udg_TMS_TempY
    set udg_TMS_Angle2 = Atan2(udg_TMS_TempReal2, udg_TMS_TempReal) * bj_RADTODEG
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Main looping function, controls the fixation of the turrets to their carrier, the          //
//  cooldowns of the turrets, and the movement and arcs of their projectiles, calls the unit   //
//  find target, and the FireProjectile Functions                                              //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_Loop takes nothing returns nothing
    set udg_TMS_Index = 1
    loop
        exitwhen udg_TMS_Index > udg_TMS_MaxIndex
        set udg_TMS_TempUnit = udg_TMS_UnitIndex[udg_TMS_Index]
        if (udg_TMS_StageID[udg_TMS_Index] == 1) then
            if (GetUnitTypeId(udg_TMS_TempUnit) != udg_TMS_DummyType) then
                set udg_TMS_SecondaryIndex = 1
                set udg_TMS_TempX = GetUnitX(udg_TMS_TempUnit)
                set udg_TMS_TempY = GetUnitY(udg_TMS_TempUnit)
                set udg_TMS_TempPoint = Location(udg_TMS_TempX, udg_TMS_TempY)
                set udg_TMS_TempReal = GetLocationZ(udg_TMS_TempPoint)
                call RemoveLocation(udg_TMS_TempPoint)
                set udg_TMS_TempPoint = null
                loop
                    exitwhen udg_TMS_SecondaryIndex > udg_TMS_MaxIndex
                    set udg_TMS_SecondaryIndex = udg_TMS_SecondaryIndex + 1
                    if (udg_TMS_TempUnit == udg_TMS_MountedUnit[udg_TMS_SecondaryIndex]) and (udg_TMS_StageID[udg_TMS_SecondaryIndex] == 2) then
                        if (GetWidgetLife(udg_TMS_TempUnit) <= 0) then
                            call SetWidgetLife(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex], 0.00)
                        endif
                        set udg_TMS_AngleAlteration[udg_TMS_SecondaryIndex] = (udg_TMS_CarrierFacing[udg_TMS_Index] - GetUnitFacing(udg_TMS_UnitIndex[udg_TMS_Index]))
                        set udg_TMS_TempReal2 = udg_TMS_PositionAngle[udg_TMS_SecondaryIndex]  - (udg_TMS_AngleAlteration[udg_TMS_SecondaryIndex] * bj_DEGTORAD)
                        call SetUnitX(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex], udg_TMS_TempX + udg_TMS_MountingOffset[udg_TMS_TurretType[udg_TMS_SecondaryIndex]] * Cos(udg_TMS_TempReal2))
                        call SetUnitY(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex], udg_TMS_TempY + udg_TMS_MountingOffset[udg_TMS_TurretType[udg_TMS_SecondaryIndex]] * Sin(udg_TMS_TempReal2))
                        set udg_TMS_TempPoint2 = Location(GetUnitX(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex]), GetUnitY(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex]))
                        set udg_TMS_TempReal2 = GetLocationZ(udg_TMS_TempPoint2)
                        call SetUnitFlyHeight(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex], (udg_TMS_TempReal - udg_TMS_TempReal2) + udg_TMS_ZHeight[udg_TMS_SecondaryIndex], 0.00)
                    endif
                endloop
                if (IsUnitType(udg_TMS_TempUnit, UNIT_TYPE_DEAD)) then
                    set udg_TMS_StageID[udg_TMS_Index] = 4
                endif
            endif
        elseif (udg_TMS_StageID[udg_TMS_Index] == 2) then
            if (not IsUnitType(udg_TMS_TempUnit, UNIT_TYPE_DEAD)) then
                //*+
                if (udg_TMS_FireCooldownCurrent[udg_TMS_Index] >= udg_TMS_FireCooldown[udg_TMS_TurretType[udg_TMS_Index]]) then
                    set udg_TMS_FireCooldownCurrent[udg_TMS_Index] = 0.00
                    set udg_TMS_TempX = GetUnitX(udg_TMS_TempUnit)
                    set udg_TMS_TempY = GetUnitY(udg_TMS_TempUnit)
                    call TMS_TurretFacing()
                    set udg_TMS_TempReal3 = (udg_TMS_TempReal2 * udg_TMS_TempReal2) + (udg_TMS_TempReal * udg_TMS_TempReal)
                    if (udg_TMS_SelectedTarget[udg_TMS_Index] == null) or (not udg_TMS_TargetLock[udg_TMS_TurretType[udg_TMS_Index]]) or (udg_TMS_TempReal3 > udg_TMS_Range[udg_TMS_TurretType[udg_TMS_Index]] * udg_TMS_Range[udg_TMS_TurretType[udg_TMS_Index]]) then   
                        if (udg_TMS_TargettingMethod[udg_TMS_Index] == 11) then
                            set udg_TMS_SelectedTarget[udg_TMS_Index] = null
                        else                         
                            set udg_TMS_SelectedTarget[udg_TMS_Index] = TMS_FindTarget(udg_TMS_TurretType[udg_TMS_Index])
                        endif
                        if (udg_TMS_SelectedTarget[udg_TMS_Index] != null) then
                            call TMS_TurretFacing()
                            call SetUnitFacing(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_Angle2)
                            call TMS_FireProjectile(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_SelectedTarget[udg_TMS_Index])
                        else
                            set udg_TMS_TempReal2 = (udg_TMS_PositionAngle[udg_TMS_Index] * bj_RADTODEG) - udg_TMS_AngleAlteration[udg_TMS_Index]
                            call SetUnitFacing(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_TempReal2)
                        endif
                    else
                        call SetUnitFacing(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_Angle2)
                        call TMS_FireProjectile(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_SelectedTarget[udg_TMS_Index])
                    endif
                else
                    set udg_TMS_FireCooldownCurrent[udg_TMS_Index] = udg_TMS_FireCooldownCurrent[udg_TMS_Index] + udg_TMS_TimerSpeed
                endif
                //*-
            else
                //*+
                call DestroyEffect(udg_TMS_CurrentEffect[udg_TMS_Index])
                if (udg_TMS_HaveDeathSfx[udg_TMS_TurretType[udg_TMS_Index]]) then
                    call DestroyEffect(AddSpecialEffectTarget(udg_TMS_DeathModel[udg_TMS_TurretType[udg_TMS_MaxIndex]], udg_TMS_UnitIndex[udg_TMS_Index], "origin"))
                    call SetUnitScale(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_DeathScale[udg_TMS_TurretType[udg_TMS_Index]] * 0.01, udg_TMS_DeathScale[udg_TMS_TurretType[udg_TMS_Index]] * 0.01, udg_TMS_DeathScale[udg_TMS_TurretType[udg_TMS_Index]] * 0.01)                  
                endif
                //*-
                set udg_TMS_StageID[udg_TMS_Index] = 4
            endif
        //*+
        elseif (udg_TMS_StageID[udg_TMS_Index] == 3) then
            set udg_TMS_TempX = GetUnitX(udg_TMS_TempUnit)
            set udg_TMS_TempY = GetUnitY(udg_TMS_TempUnit)
            if (udg_TMS_HaveHoming[udg_TMS_TurretType[udg_TMS_Index]]) then
                if (udg_TMS_SelectedTarget[udg_TMS_Index] == null) or (IsUnitType(udg_TMS_TempUnit, UNIT_TYPE_DEAD)) then
                    set udg_TMS_StageID[udg_TMS_Index] = 4
                    call DestroyEffect (udg_TMS_CurrentEffect[udg_TMS_Index])
                    if (udg_TMS_HaveTargettingSfx[udg_TMS_TurretType[udg_TMS_Index]]) then
                        call DestroyEffect(udg_TMS_TargettingEffect[udg_TMS_Index])
                        set udg_TMS_SecondaryIndex = 1
                        loop
                            if (udg_TMS_UnitIndex[udg_TMS_SecondaryIndex] == udg_TMS_TargettingUnit[udg_TMS_Index]) and (udg_TMS_StageID[udg_TMS_SecondaryIndex] == 5) then
                                set udg_TMS_StageID[udg_TMS_SecondaryIndex] = 4
                                set udg_TMS_DeathTimerCurrent[udg_TMS_SecondaryIndex] = 0.00
                            endif
                            exitwhen udg_TMS_UnitIndex[udg_TMS_SecondaryIndex] == udg_TMS_TargettingUnit[udg_TMS_Index]
                            set udg_TMS_SecondaryIndex = udg_TMS_SecondaryIndex + 1
                        endloop
                    endif
                else
                    set udg_TMS_TempX2 = GetUnitX(udg_TMS_SelectedTarget[udg_TMS_Index])
                    set udg_TMS_TempY2 = GetUnitY(udg_TMS_SelectedTarget[udg_TMS_Index])
                    set udg_TMS_Angle = Atan2(udg_TMS_TempY2 - udg_TMS_TempY, udg_TMS_TempX2 - udg_TMS_TempX)
                    set udg_TMS_PositionAngle[udg_TMS_Index] = udg_TMS_Angle
                    call SetUnitFacing(udg_TMS_TempUnit, udg_TMS_Angle * bj_RADTODEG)
                    set udg_TMS_MaxDistance[udg_TMS_Index] = udg_TMS_CurrentDistance[udg_TMS_Index] + SquareRoot((udg_TMS_TempX2 - udg_TMS_TempX) * (udg_TMS_TempX2 - udg_TMS_TempX) + (udg_TMS_TempY2 - udg_TMS_TempY) * (udg_TMS_TempY2 - udg_TMS_TempY))
                    set udg_TMS_MaxHeight[udg_TMS_Index] = udg_TMS_MaxDistance[udg_TMS_Index] * udg_TMS_ArcFactor[udg_TMS_TurretType[udg_TMS_Index]]
                endif
            endif
            if (udg_TMS_MovementSpeed[udg_TMS_Index] >= udg_TMS_SpeedLimit[udg_TMS_TurretType[udg_TMS_Index]]) then
                set udg_TMS_MovementSpeed[udg_TMS_Index] = udg_TMS_SpeedLimit[udg_TMS_TurretType[udg_TMS_Index]]
            else
                set udg_TMS_MovementSpeed[udg_TMS_Index] = (udg_TMS_MovementSpeed[udg_TMS_Index] + udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretType[udg_TMS_Index]]) * udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretType[udg_TMS_Index]]
            endif
            set udg_TMS_TempReal3 = GetUnitFlyHeight(udg_TMS_SelectedTarget[udg_TMS_Index])
            if ((udg_TMS_CurrentHeight[udg_TMS_Index] <= udg_TMS_TempReal3 + udg_TMS_HeightLet) and (udg_TMS_CurrentHeight[udg_TMS_Index] >= udg_TMS_TempReal3 - udg_TMS_HeightLet) and (udg_TMS_CurrentDistance[udg_TMS_Index] >= udg_TMS_MaxDistance[udg_TMS_Index])) or (udg_TMS_CurrentDistance[udg_TMS_Index] >= udg_TMS_Range[udg_TMS_TurretType[udg_TMS_Index]]) or (udg_TMS_CurrentHeight[udg_TMS_Index] < 0)then
                call DestroyEffect (udg_TMS_CurrentEffect[udg_TMS_Index])
                call GroupEnumUnitsInRange(udg_TMS_TempGroup, udg_TMS_TempX, udg_TMS_TempY, udg_TMS_ProjectileAOE[udg_TMS_TurretType[udg_TMS_Index]], null)
                set udg_TMS_FilterMode = 2
                set udg_TMS_TempUnit2 = null
                set udg_TMS_TempUnit3 = null
                loop
                    set udg_TMS_TempUnit2 = FirstOfGroup(udg_TMS_TempGroup)
                    exitwhen udg_TMS_TempUnit2 == null
                    call TMS_TargetFilter(udg_TMS_TempUnit2)
                    call GroupRemoveUnit(udg_TMS_TempGroup, udg_TMS_TempUnit2)
                endloop
                if (udg_TMS_HaveImpactSfx[udg_TMS_TurretType[udg_TMS_Index]]) then
                    call DestroyEffect(AddSpecialEffectTarget(udg_TMS_ImpactModel[udg_TMS_TurretType[udg_TMS_Index]], udg_TMS_UnitIndex[udg_TMS_Index], "origin"))
                    call SetUnitScale(udg_TMS_UnitIndex[udg_TMS_Index], udg_TMS_ImpactScale[udg_TMS_TurretType[udg_TMS_Index]] * 0.01, 0.00, 0.00)
                endif
                if (udg_TMS_HaveTargettingSfx[udg_TMS_TurretType[udg_TMS_Index]]) then
                    call DestroyEffect(udg_TMS_TargettingEffect[udg_TMS_Index])
                    if (not udg_TMS_HaveHoming[udg_TMS_TurretType[udg_TMS_Index]]) then
                        set udg_TMS_SecondaryIndex = 1
                        loop
                            if (udg_TMS_UnitIndex[udg_TMS_SecondaryIndex] == udg_TMS_TargettingUnit[udg_TMS_Index]) and (udg_TMS_StageID[udg_TMS_SecondaryIndex] == 5) then
                                set udg_TMS_StageID[udg_TMS_SecondaryIndex] = 4
                                set udg_TMS_DeathTimerCurrent[udg_TMS_SecondaryIndex] = 0.00
                            endif
                            exitwhen udg_TMS_SecondaryIndex >= udg_TMS_MaxIndex or udg_TMS_UnitIndex[udg_TMS_SecondaryIndex] == udg_TMS_TargettingUnit[udg_TMS_Index]
                            set udg_TMS_SecondaryIndex = udg_TMS_SecondaryIndex + 1
                        endloop
                    endif
                endif
                set udg_TMS_StageID[udg_TMS_Index] = 4
                set udg_TMS_ActivateEffects = udg_TMS_BonusEffects[udg_TMS_TurretType[udg_TMS_Index]]
                set udg_TMS_ActivateEffects = 0.00
            else
                if (udg_TMS_SelectedTarget[udg_TMS_Index] != null) then
                    set udg_TMS_HeightCorrection[udg_TMS_Index] = ((GetUnitFlyHeight(udg_TMS_SelectedTarget[udg_TMS_Index]) - udg_TMS_ZHeight[udg_TMS_Index]) - udg_TMS_StackedCorrection[udg_TMS_Index]) / ((udg_TMS_MaxDistance[udg_TMS_Index] - udg_TMS_CurrentDistance[udg_TMS_Index]) / udg_TMS_MovementSpeed[udg_TMS_Index])
                endif
                call SetUnitX(udg_TMS_TempUnit, udg_TMS_TempX + udg_TMS_MovementSpeed[udg_TMS_Index] * Cos(udg_TMS_PositionAngle[udg_TMS_Index]))
                call SetUnitY(udg_TMS_TempUnit, udg_TMS_TempY + udg_TMS_MovementSpeed[udg_TMS_Index] * Sin(udg_TMS_PositionAngle[udg_TMS_Index]))
                set udg_TMS_CurrentDistance[udg_TMS_Index] = udg_TMS_CurrentDistance[udg_TMS_Index] + udg_TMS_MovementSpeed[udg_TMS_Index]
                if (udg_TMS_HaveProjectileArc[udg_TMS_TurretType[udg_TMS_Index]]) then
                    set udg_TMS_StackedCorrection[udg_TMS_Index] = udg_TMS_StackedCorrection[udg_TMS_Index] + udg_TMS_HeightCorrection[udg_TMS_Index]
                    set udg_TMS_StackedCorrection[udg_TMS_Index] = udg_TMS_StackedCorrection[udg_TMS_Index] + udg_TMS_HeightCorrection[udg_TMS_Index]
                    set udg_TMS_TempReal =  (((4 * udg_TMS_MaxHeight[udg_TMS_Index]) / udg_TMS_MaxDistance[udg_TMS_Index]) * (udg_TMS_MaxDistance[udg_TMS_Index] -  udg_TMS_CurrentDistance[udg_TMS_Index]) * (udg_TMS_CurrentDistance[udg_TMS_Index] / udg_TMS_MaxDistance[udg_TMS_Index])) + udg_TMS_ZHeight[udg_TMS_Index] + udg_TMS_StackedCorrection[udg_TMS_Index]
                    set udg_TMS_TempReal3 = (Atan(4 * udg_TMS_CurrentHeight[udg_TMS_Index] / udg_TMS_MaxDistance[udg_TMS_Index] - 12 * udg_TMS_CurrentHeight[udg_TMS_Index] * udg_TMS_CurrentDistance[udg_TMS_Index] / (udg_TMS_MaxDistance[udg_TMS_Index] * udg_TMS_MaxDistance[udg_TMS_Index])) * bj_RADTODEG + 0.5) + 90
                    call SetUnitAnimationByIndex(udg_TMS_TempUnit,R2I(udg_TMS_TempReal3))
                else
                    set udg_TMS_StackedCorrection[udg_TMS_Index] = udg_TMS_StackedCorrection[udg_TMS_Index] + udg_TMS_HeightCorrection[udg_TMS_Index]
                    set udg_TMS_TempReal = udg_TMS_CurrentHeight[udg_TMS_Index] + udg_TMS_HeightCorrection[udg_TMS_Index]
                endif
                call SetUnitFlyHeight(udg_TMS_TempUnit, udg_TMS_TempReal, 0.00)
                set udg_TMS_CurrentHeight[udg_TMS_Index] = udg_TMS_TempReal
            endif
        //*-
        elseif (udg_TMS_DeathTimerCurrent[udg_TMS_Index] == udg_TMS_DeathTimer) and (udg_TMS_StageID[udg_TMS_Index] == 4) then
            call RemoveUnit(udg_TMS_TempUnit)
            set udg_TMS_DeathTimerCurrent[udg_TMS_Index] = udg_TMS_DeathTimerCurrent[udg_TMS_MaxIndex]
            set udg_TMS_DeathTimerCurrent[udg_TMS_MaxIndex] = 0.00   
            //*+                         
            set udg_TMS_FireCooldownCurrent[udg_TMS_Index] = udg_TMS_FireCooldownCurrent[udg_TMS_MaxIndex]
            //*-
            set udg_TMS_StageID[udg_TMS_Index] = udg_TMS_StageID[udg_TMS_MaxIndex]
            //*+
            set udg_TMS_CurrentHeight[udg_TMS_Index] = udg_TMS_CurrentHeight[udg_TMS_MaxIndex]
            set udg_TMS_MaxHeight[udg_TMS_Index] = udg_TMS_MaxHeight[udg_TMS_MaxIndex]
            set udg_TMS_CurrentDistance[udg_TMS_Index] = udg_TMS_CurrentDistance[udg_TMS_MaxIndex]
            set udg_TMS_MaxDistance[udg_TMS_Index] = udg_TMS_MaxDistance[udg_TMS_MaxIndex]
            set udg_TMS_HeightCorrection[udg_TMS_Index] = udg_TMS_HeightCorrection[udg_TMS_MaxIndex]
            set udg_TMS_StackedCorrection[udg_TMS_Index] = udg_TMS_StackedCorrection[udg_TMS_MaxIndex]
            set udg_TMS_MovementSpeed[udg_TMS_Index] = udg_TMS_MovementSpeed[udg_TMS_MaxIndex]
            //*-
            set udg_TMS_MountedUnit[udg_TMS_Index] = udg_TMS_MountedUnit[udg_TMS_MaxIndex]
            set udg_TMS_PositionAngle[udg_TMS_Index] = udg_TMS_PositionAngle[udg_TMS_MaxIndex]
            //*+
            set udg_TMS_SelectedTarget[udg_TMS_Index] = udg_TMS_SelectedTarget[udg_TMS_MaxIndex]
            set udg_TMS_TargettingEffect[udg_TMS_Index] = udg_TMS_TargettingEffect[udg_TMS_MaxIndex]
            set udg_TMS_TargettingUnit[udg_TMS_Index] = udg_TMS_TargettingUnit[udg_TMS_MaxIndex]
            //*-
            set udg_TMS_TurretType[udg_TMS_Index] = udg_TMS_TurretType[udg_TMS_MaxIndex]
            set udg_TMS_UnitIndex[udg_TMS_Index] = udg_TMS_UnitIndex[udg_TMS_MaxIndex]
            //*+
            set udg_TMS_CurrentEffect[udg_TMS_Index] = udg_TMS_CurrentEffect[udg_TMS_MaxIndex]
            //*-
            set udg_TMS_CurrentTurretCount[udg_TMS_Index] = udg_TMS_CurrentTurretCount[udg_TMS_MaxIndex]
            set udg_TMS_ZHeight[udg_TMS_Index] = udg_TMS_ZHeight[udg_TMS_MaxIndex]
            set udg_TMS_CarrierFacing[udg_TMS_Index] = udg_TMS_CarrierFacing[udg_TMS_MaxIndex]
            set udg_TMS_AngleAlteration[udg_TMS_Index] = udg_TMS_AngleAlteration[udg_TMS_MaxIndex]
            set udg_TMS_CurrentWeight[udg_TMS_Index] = udg_TMS_CurrentWeight[udg_TMS_MaxIndex]
            set udg_TMS_MaxIndex = udg_TMS_MaxIndex - 1
            set udg_TMS_Index = udg_TMS_Index - 1
            if (udg_TMS_MaxIndex == 0) then
                call PauseTimer(udg_TMS_Timer)
            endif
        else
            set udg_TMS_DeathTimerCurrent[udg_TMS_Index] = udg_TMS_DeathTimerCurrent[udg_TMS_Index] + udg_TMS_TimerSpeed
        endif
        set udg_TMS_Index = udg_TMS_Index + 1
    endloop    
endfunction



/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function that runs rearrangement of the turrets on a particular carrier (u) called by      //
//  CreateTurrets and DestroyTurrets functions                                                 //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_ReArrangeTurrets takes unit u returns nothing
    set udg_TMS_SecondaryIndex = 1
    set udg_TMS_Angle = udg_TMS_CarrierFacing[udg_TMS_Index]
    loop
        exitwhen udg_TMS_SecondaryIndex > udg_TMS_MaxIndex
        if (u == udg_TMS_MountedUnit[udg_TMS_SecondaryIndex]) and (udg_TMS_StageID[udg_TMS_SecondaryIndex] == 2) and (udg_TMS_UnitIndex[udg_TMS_SecondaryIndex] != udg_TMS_TempUnit3) then
            set udg_TMS_Angle = udg_TMS_Angle + (360 / udg_TMS_CurrentTurretCount[udg_TMS_Index])
            set udg_TMS_PositionAngle[udg_TMS_SecondaryIndex] = udg_TMS_Angle * bj_DEGTORAD
            call SetUnitFacing(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex], udg_TMS_Angle) 
        endif
        set udg_TMS_SecondaryIndex = udg_TMS_SecondaryIndex + 1
    endloop
    set u = null
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
// Function that creates new turrets and attached them to the specified carrier unit, called   //
// by AddTurrets, sets up turrets, and gives an error message when the limit has been reached  //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_CreateTurrets takes unit u, integer TurretNumber, integer TurretCount returns nothing
    set udg_TMS_SecondaryIndex = 1
    set udg_TMS_TempReal3 = GetUnitFlyHeight(u)
    set udg_TMS_TempPlayer = GetOwningPlayer(u)
    loop
        exitwhen udg_TMS_SecondaryIndex > TurretCount
        if (udg_TMS_CurrentWeight[udg_TMS_Index] < udg_TMS_TempInteger) then
            set udg_TMS_CurrentTurretCount[udg_TMS_Index] = udg_TMS_CurrentTurretCount[udg_TMS_Index] + 1
            set udg_TMS_CurrentWeight[udg_TMS_Index] = udg_TMS_CurrentWeight[udg_TMS_Index] + udg_TMS_TurretWeight[TurretNumber]
            set udg_TMS_MaxIndex = udg_TMS_MaxIndex + 1
            set udg_TMS_MountedUnit[udg_TMS_MaxIndex] = u
            set udg_TMS_TurretType[udg_TMS_MaxIndex] = TurretNumber
            set udg_TMS_SelectedTarget[udg_TMS_MaxIndex] = null
            set udg_TMS_StageID[udg_TMS_MaxIndex] = 2
            set udg_TMS_ZHeight[udg_TMS_MaxIndex] = udg_TMS_TempReal3 + udg_TMS_MountingHeight[TurretNumber]
            set udg_TMS_UnitIndex[udg_TMS_MaxIndex] = CreateUnit(udg_TMS_TempPlayer, udg_TMS_DummyType, GetUnitX(u), GetUnitY(u), 0.00)
            if UnitAddAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') and UnitRemoveAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') then
            endif
            //*+
            set udg_TMS_CurrentEffect[udg_TMS_MaxIndex] = AddSpecialEffectTarget(udg_TMS_TurretModel[TurretNumber], udg_TMS_UnitIndex[udg_TMS_MaxIndex], "origin")
            call SetUnitFlyHeight(udg_TMS_UnitIndex[udg_TMS_MaxIndex], udg_TMS_ZHeight[udg_TMS_MaxIndex], 0.00)
            call SetUnitScale(udg_TMS_UnitIndex[udg_TMS_MaxIndex], udg_TMS_TurretScale[TurretNumber] * 0.01, 0.00, 0.00)
            //*-
        else
            call DisplayTextToPlayer(udg_TMS_TempPlayer, 0, 0, udg_TMS_ErrorMessages[1])
        endif
        set udg_TMS_SecondaryIndex  = udg_TMS_SecondaryIndex + 1
    endloop
    set udg_TMS_TempUnit3 = null
    call TMS_ReArrangeTurrets(u)
    set u = null
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function used to remove turrets from a carrier unit and change the arrnagements of the     //
//  turrets to match the new number of them, removes the passed number of the passed type of   //
//  the passed unit                                                                            //
/////////////////////////////////////////////////////////////////////////////////////////////////

function TMS_DestroyTurrets takes unit u, integer TurretNumber, integer TurretCount returns nothing
    local integer Removed = 0
    set udg_TMS_Index = 1
    loop
        exitwhen udg_TMS_Index > udg_TMS_MaxIndex
        if (u == udg_TMS_UnitIndex[udg_TMS_Index]) then
            set udg_TMS_TempInteger = 1
            loop
                exitwhen udg_TMS_TempInteger > udg_TMS_MaxIndex
                if (u == udg_TMS_MountedUnit[udg_TMS_TempInteger]) and (udg_TMS_StageID[udg_TMS_TempInteger] == 2) and (udg_TMS_TurretType[udg_TMS_TempInteger] == TurretNumber) and (Removed < TurretCount) then
                    set Removed = Removed + 1
                    //*+
                    call DestroyEffect (udg_TMS_CurrentEffect[udg_TMS_TempInteger])
                    //*-
                    set udg_TMS_CurrentTurretCount[udg_TMS_Index] = udg_TMS_CurrentTurretCount[udg_TMS_Index] - 1
                    set udg_TMS_StageID[udg_TMS_TempInteger] = 4
                    set udg_TMS_CurrentWeight[udg_TMS_Index] = udg_TMS_CurrentWeight[udg_TMS_Index] - udg_TMS_TurretWeight[TurretNumber]
                    call SetUnitState(udg_TMS_UnitIndex[udg_TMS_TempInteger], UNIT_STATE_LIFE, 0.00)
                    set udg_TMS_TempUnit3 = udg_TMS_UnitIndex[udg_TMS_TempInteger]
                    set udg_TMS_CarrierFacing[udg_TMS_Index] = GetUnitFacing(udg_TMS_UnitIndex[udg_TMS_Index])
                    call TMS_ReArrangeTurrets(u)
                endif
                set udg_TMS_TempInteger = udg_TMS_TempInteger + 1
            endloop
        endif
        set udg_TMS_Index = udg_TMS_Index + 1
    endloop
    set u = null
    set udg_TMS_TempUnit3 = null
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
//  Function Used to determine if a unit can hold any more turrets/can hold any turrets        //
//  if so, then calls CreateTurrets, passing the necessary parameters to create new turrets    //
//  then starts the loop timer for the system to run, if it was not already                    //
/////////////////////////////////////////////////////////////////////////////////////////////////
function TMS_AddTurret takes unit u, integer TurretNumber, integer TurretCount returns nothing
    if (TurretCount > 0) and (TurretNumber > 0) then
        set udg_TMS_TempBoolean = false
        set udg_TMS_Index = 1
        loop
            exitwhen udg_TMS_Index > udg_TMS_CarrierTypesCount            
            if (GetUnitTypeId(u) == udg_TMS_CarrierUnitType[udg_TMS_Index]) then
                set udg_TMS_TempBoolean = true
                set udg_TMS_TempInteger = udg_TMS_TurretLimit[udg_TMS_Index]
            elseif not udg_TMS_TempBoolean then
                set udg_TMS_TempInteger = udg_TMS_DefaultLimit
            endif
            set udg_TMS_Index = udg_TMS_Index + 1
        endloop
        if (udg_TMS_TempInteger > 0) then
            set udg_TMS_Index = 1
            set udg_TMS_TempBoolean = false
            loop
                exitwhen udg_TMS_Index > udg_TMS_MaxIndex
                if (u == udg_TMS_UnitIndex[udg_TMS_Index]) then
                    set udg_TMS_TempBoolean = true
                    set udg_TMS_CarrierFacing[udg_TMS_Index] = GetUnitFacing(udg_TMS_UnitIndex[udg_TMS_Index])
                    call TMS_CreateTurrets(u, TurretNumber, TurretCount)
                endif
                set udg_TMS_Index = udg_TMS_Index + 1
            endloop
            if (not udg_TMS_TempBoolean) then
                set udg_TMS_MaxIndex = udg_TMS_MaxIndex + 1
                set udg_TMS_UnitIndex[udg_TMS_MaxIndex] = u
                set udg_TMS_CurrentTurretCount[udg_TMS_MaxIndex] = 0
                set udg_TMS_StageID[udg_TMS_MaxIndex] = 1
                set udg_TMS_CarrierFacing[udg_TMS_MaxIndex] = GetUnitFacing(udg_TMS_UnitIndex[udg_TMS_MaxIndex])
                set udg_TMS_Index = udg_TMS_MaxIndex
                if (udg_TMS_MaxIndex == 1) then
                     call TimerStart(udg_TMS_Timer, udg_TMS_TimerSpeed, true, function TMS_Loop)
                endif
                call TMS_CreateTurrets(u, TurretNumber, TurretCount)
            endif
        else
            call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, udg_TMS_ErrorMessages[0])
        endif
    elseif (TurretCount < 1) then
        call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, udg_TMS_ErrorMessages[2])
    else
        call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, udg_TMS_ErrorMessages[3])
    endif
    set u = null
endfunction

/////////////////////////////////////////////////////////////////////////////////////////////////
// End of the system                                                                           //
/////////////////////////////////////////////////////////////////////////////////////////////////




JASS:
function InitTrig_Register_Data takes nothing returns nothing
    // calling RegisterCarrier to add the carrier to the system
    call TMS_RegisterCarrier('u002', 5)
    // calling RegisterCarrier to add the turret to the system
    call TMS_RegisterCarrier('h000', 1)
    //setting up data for turrets
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Anti-Ground Plasma Cannon"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\creeps\\InfernalCannonCannon\\InfernalCannonCannon.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspirittarget.mdl"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 30.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 75.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 20.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 50.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 20.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 10.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = true
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = false
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 90.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 100.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 10.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 500.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.45
    set udg_TMS_Range[udg_TMS_TurretInit] = 500.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 6.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 40.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 4.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 50.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 0.40
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 4
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 3
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 2
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = false
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //NextTurret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Flak Copter"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\human\\Gyrocopter\\Gyrocopter_V1.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\RocketMissile\\RocketMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Input launch effect model"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Input impact effect model"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Human\\DispelMagic\\DispelMagicTarget.mdl"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 40.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 50.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 20.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 50.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 20.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = true
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = true
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 250.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 60.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 50.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 10.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 20.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Range[udg_TMS_TurretInit] = 900.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 40.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 40.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.50
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 2.50
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 0.15
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 9
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = true  
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL  
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //NextTurret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Crusher Artillery Launcher"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\orc\\catapult\\catapult_V1.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "abilities\\weapons\\DemolisherMissile\\DemolisherMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\SteamTank\\SteamTankImpact.mdl"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Input death effect model"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 100.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 100.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = true
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = true
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 90.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 150.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 10.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 250.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.75
    set udg_TMS_Range[udg_TMS_TurretInit] = 1500.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 15.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 15.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 300.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 3.00
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 3
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 6
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = true
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Energy Sap Zepplin"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\creeps\\GoblinZeppelin\\GoblinZeppelin.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\ZigguratMissile\\ZigguratMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Units\\NightElf\\Wisp\\WispExplode.mdl"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Other\\Charm\\CharmTarget.mdl"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 40.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 80.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 40.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 80.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 25.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = false
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = false
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 250.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 90.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Range[udg_TMS_TurretInit] = 700.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 40.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.40
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 40.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 1.50
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 6
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 2
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 2
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = false
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Spider Spit Launcher"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\creeps\\SpiderGreen\\SpiderGreen.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\ChimaeraAcidMissile\\ChimaeraAcidMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Input launch effect model"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Input impact effect model"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 30.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 100.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 30.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = true
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 100.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 50.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 70.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.30
    set udg_TMS_Range[udg_TMS_TurretInit] = 1100.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 20.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 20.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 5.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 25.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 0.25
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 2
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 7
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = false
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Armageddon Cannon"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\creeps\\FelstalkerPurple\\FelstalkerPurple.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Undead\\OrbOfDeath\\AnnihilationMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Other\\HowlOfTerror\\HowlCaster.mdl"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 90.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 150.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 200.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 200.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 90.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = true
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = true
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 100.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 10.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 400.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 50.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 200.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Range[udg_TMS_TurretInit] = 800.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 90.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 90.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.40
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 4000.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 2.50
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 5
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 4
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 4
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = true
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Eliminator Missile Platform"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "buildings\\undead\\Ziggurat\\Ziggurat.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\RocketMissile\\RocketMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Input launch effect model"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\SteamTank\\SteamTankImpact.mdl"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Input death effect model"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Human\\Brilliance\\Brilliance.mdl"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 100.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 100.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 120.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = true
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = true
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 90.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 150.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 10.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 250.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.35
    set udg_TMS_Range[udg_TMS_TurretInit] = 1500.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 3.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.10
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = -0.20
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 30.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 300.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 4.00
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 2
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = true
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Seeker Bolt Elemental"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\human\\WaterElemental\\WaterElemental.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveDamage.mdl"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Input impact effect model"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Input death effect model"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Abilities\\Spells\\Orc\\LightningShield\\LightningShieldTarget.mdl"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 35.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 100.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 50.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 20.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = true
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = false
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 90.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 150.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Range[udg_TMS_TurretInit] = 1100.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 25.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 10.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 7.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 50.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 2.00
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 1
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 2
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 4
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = false
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Archer Tower"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "units\\nightelf\\Archer\\Archer.mdl"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Abilities\\Weapons\\Arrow\\ArrowMissile.mdl"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Input launch effect model"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Input impact effect model"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Input death effect model"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 75.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 150.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 50.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 20.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = true
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = true
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = false
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = true
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = true
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 160.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 100.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.40
    set udg_TMS_Range[udg_TMS_TurretInit] = 800.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 45.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 1.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 45.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 90.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 1.50
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 0
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 11
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 1
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 4
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = true
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL
    //Calling the register function after you've set up your turret
    call TMS_RegisterTurret(0)
    //Next Turret
endfunction


  • GUI Register Data
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- calling RegisterCarrier to add the carrier to the system --------
      • Custom script: call TMS_RegisterCarrier('u002', 5)
      • -------- setting up data for turrets --------
      • Set TMS_TurretName[TMS_TurretInit] = Anti-Ground Plasma Cannon
      • Set TMS_TurretModel[TMS_TurretInit] = units\creeps\InfernalCannonCannon\InfernalCannonCannon.mdl
      • Set TMS_ProjectileModel[TMS_TurretInit] = Abilities\Weapons\PhoenixMissile\Phoenix_Missile_mini.mdl
      • Set TMS_LaunchModel[TMS_TurretInit] = Abilities\Spells\Human\MarkOfChaos\MarkOfChaosTarget.mdl
      • Set TMS_ImpactModel[TMS_TurretInit] = Abilities\Spells\Other\Incinerate\FireLordDeathExplode.mdl
      • Set TMS_DeathModel[TMS_TurretInit] = Abilities\Spells\Orc\FeralSpirit\feralspirittarget.mdl
      • Set TMS_TargettingModel[TMS_TurretInit] = Input targetting effect model
      • Set TMS_TurretScale[TMS_TurretInit] = 30.00
      • Set TMS_ProjectileScale[TMS_TurretInit] = 75.00
      • Set TMS_LaunchScale[TMS_Index] = 20.00
      • Set TMS_ImpactScale[TMS_TurretInit] = 50.00
      • Set TMS_DeathScale[TMS_TurretInit] = 20.00
      • Set TMS_TargettingScale[TMS_TurretInit] = 0.00
      • Set TMS_HaveLaunchSfx[TMS_TurretInit] = False
      • Set TMS_HaveImpactSfx[TMS_TurretInit] = True
      • Set TMS_HaveDeathSfx[TMS_TurretInit] = True
      • Set TMS_HaveTargettingSfx[TMS_TurretInit] = False
      • Set TMS_HaveHoming[TMS_TurretInit] = False
      • Set TMS_HaveRelativeDamage[TMS_TurretInit] = False
      • Set TMS_HaveInaccuracy[TMS_TurretInit] = True
      • Set TMS_HaveProjectileArc[TMS_TurretInit] = True
      • Set TMS_HaveTrueSpeed[TMS_TurretInit] = False
      • Set TMS_BonusEffects[TMS_TurretInit] = 0.00
      • Set TMS_MountingHeight[TMS_TurretInit] = 90.00
      • Set TMS_MountingOffset[TMS_TurretInit] = 45.00
      • Set TMS_ProjectileAOE[TMS_TurretInit] = 100.00
      • Set TMS_AoeDamageDissapation[TMS_TurretInit] = 10.00
      • Set TMS_Inaccuracy[TMS_TurretInit] = 100.00
      • Set TMS_ArcFactor[TMS_TurretInit] = 0.45
      • Set TMS_Range[TMS_TurretInit] = 500.00
      • Set TMS_ProjectileSpeed[TMS_TurretInit] = 6.00
      • Set TMS_SpeedOverTimeMultiplyer[TMS_TurretInit] = 1.00
      • Set TMS_SpeedOverTimeFixed[TMS_TurretInit] = 0.00
      • Set TMS_SpeedLimit[TMS_TurretInit] = 40.00
      • Set TMS_ProjectileFuel[TMS_TurretInit] = 0.00
      • Set TMS_ImpactTime[TMS_TurretInit] = 1.00
      • Set TMS_HealthDamage[TMS_TurretInit] = 50.00
      • Set TMS_ManaDamage[TMS_TurretInit] = 0.00
      • Set TMS_FireCooldown[TMS_TurretInit] = 0.30
      • Set TMS_TurretWeight[TMS_TurretInit] = 1
      • Set TMS_TargettingMethod[TMS_TurretInit] = 4
      • Set TMS_TargetType[TMS_TurretInit] = 3
      • Set TMS_TargetStatus[TMS_TurretInit] = 2
      • Set TMS_TargetLock[TMS_TurretInit] = False
      • Set TMS_AttackType[TMS_TurretInit] = Normal
      • Set TMS_DamageType[TMS_TurretInit] = Normal
      • -------- Calling the register function after you've set up your turret --------
      • Custom script: call TMS_RegisterTurret(0)
      • -------- Next Turret --------




  • Carrier setup
    • Events
      • Time - Elapsed game time is 0.50 seconds
    • Conditions
    • Actions
      • Set TMS_TempPoint = (Player 1 (Red) start location)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 1, 5)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 2, 5)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 3, 5)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 4, 5)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 5, 5)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 6, 1)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 7, 5)
      • Unit - Create 1 Carrier for Player 1 (Red) at TMS_TempPoint facing 270.00 degrees
      • Set TMS_TempUnit = (Last created unit)
      • Custom script: call TMS_AddTurret(udg_TMS_TempUnit, 8, 5)
      • Custom script: call RemoveLocation(udg_TMS_TempPoint)



  • Upgrade Example
    • Events
      • Player - Player 1 (Red) types a chat message containing -Upgrade 1 as An exact match
    • Conditions
    • Actions
      • Set TMS_TurretName[TMS_TurretInit] = Anti-Ground Plasma Cannon
      • Set TMS_TurretModel[TMS_TurretInit] = units\creeps\InfernalCannonCannon\InfernalCannonCannon.mdl
      • Set TMS_ProjectileModel[TMS_TurretInit] = Abilities\Weapons\PhoenixMissile\Phoenix_Missile.mdl
      • Set TMS_LaunchModel[TMS_TurretInit] = Abilities\Spells\Human\MarkOfChaos\MarkOfChaosTarget.mdl
      • Set TMS_ImpactModel[TMS_TurretInit] = Abilities\Spells\Other\Incinerate\FireLordDeathExplode.mdl
      • Set TMS_DeathModel[TMS_TurretInit] = Abilities\Spells\Orc\FeralSpirit\feralspirittarget.mdl
      • Set TMS_TargettingModel[TMS_TurretInit] = Input targetting model
      • Set TMS_TurretScale[TMS_TurretInit] = 45.00
      • Set TMS_ProjectileScale[TMS_TurretInit] = 75.00
      • Set TMS_LaunchScale[TMS_Index] = 20.00
      • Set TMS_ImpactScale[TMS_TurretInit] = 50.00
      • Set TMS_DeathScale[TMS_TurretInit] = 20.00
      • Set TMS_TargettingScale[TMS_TurretInit] = 0.00
      • Set TMS_HaveLaunchSfx[TMS_TurretInit] = False
      • Set TMS_HaveImpactSfx[TMS_TurretInit] = True
      • Set TMS_HaveDeathSfx[TMS_TurretInit] = True
      • Set TMS_HaveTargettingSfx[TMS_TurretInit] = False
      • Set TMS_HaveHoming[TMS_TurretInit] = False
      • Set TMS_HaveRelativeDamage[TMS_TurretInit] = False
      • Set TMS_HaveInaccuracy[TMS_TurretInit] = True
      • Set TMS_HaveProjectileArc[TMS_TurretInit] = True
      • Set TMS_HaveTrueSpeed[TMS_TurretInit] = False
      • Set TMS_BonusEffects[TMS_TurretInit] = 0.00
      • Set TMS_MountingHeight[TMS_TurretInit] = 90.00
      • Set TMS_MountingOffset[TMS_TurretInit] = 45.00
      • Set TMS_ProjectileAOE[TMS_TurretInit] = 100.00
      • Set TMS_AoeDamageDissapation[TMS_TurretInit] = 10.00
      • Set TMS_Inaccuracy[TMS_TurretInit] = 150.00
      • Set TMS_ArcFactor[TMS_TurretInit] = 0.45
      • Set TMS_Range[TMS_TurretInit] = 650.00
      • Set TMS_ProjectileSpeed[TMS_TurretInit] = 6.00
      • Set TMS_SpeedOverTimeMultiplyer[TMS_TurretInit] = 1.00
      • Set TMS_SpeedOverTimeFixed[TMS_TurretInit] = 0.00
      • Set TMS_SpeedLimit[TMS_TurretInit] = 40.00
      • Set TMS_ProjectileFuel[TMS_TurretInit] = 0.00
      • Set TMS_ImpactTime[TMS_TurretInit] = 2.00
      • Set TMS_HealthDamage[TMS_TurretInit] = 75.00
      • Set TMS_ManaDamage[TMS_TurretInit] = 0.00
      • Set TMS_FireCooldown[TMS_TurretInit] = 0.30
      • Set TMS_TurretWeight[TMS_TurretInit] = 1
      • Set TMS_TargettingMethod[TMS_TurretInit] = 4
      • Set TMS_TargetType[TMS_TurretInit] = 3
      • Set TMS_TargetStatus[TMS_TurretInit] = 2
      • Set TMS_TargetLock[TMS_TurretInit] = False
      • Set TMS_AttackType[TMS_TurretInit] = Normal
      • Set TMS_DamageType[TMS_TurretInit] = Normal
      • -------- Calling the register function after you've set up your turret --------
      • Custom script: call TMS_RegisterTurret(TMS_GetTurretByName("Anti-Ground Plasma Cannon"))



  • Manual Targetting Example
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Archer Tower
    • Actions
      • Set TMS_TempUnit = (Attacking unit)
      • For each (Integer TMS_Index) from 1 to TMS_MaxIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TMS_UnitIndex[TMS_Index] Equal to (Attacking unit)
            • Then - Actions
              • For each (Integer TMS_SecondaryIndex) from 1 to TMS_MaxIndex, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TMS_UnitIndex[TMS_Index] Equal to TMS_MountedUnit[TMS_SecondaryIndex]
                    • Then - Actions
                      • Custom script: set udg_TMS_SelectedTarget[udg_TMS_SecondaryIndex] = GetTriggerUnit()
                    • Else - Actions
            • Else - Actions

Examples are for demo purposes only


  • TMS VariableCreator
    • Events
    • Conditions
    • Actions
      • Set TMS_ActivateEffects = 0.00
      • Set TMS_Angle = 0.00
      • Set TMS_Angle2 = 0.00
      • Set TMS_AngleAlteration[0] = 0.00
      • Set TMS_AoeDamageDissapation[0] = 0.00
      • Set TMS_ArcFactor[0] = 0.00
      • Set TMS_BonusEffects[0] = 0.00
      • Set TMS_CarrierFacing[0] = 0.00
      • Set TMS_CarrierTypesCount = 0
      • Set TMS_CarrierUnitType[0] = TMS_CarrierUnitType[0]
      • Set TMS_CurrentDistance[0] = 0.00
      • Set TMS_CurrentEffect[0] = TMS_CurrentEffect[0]
      • Set TMS_CurrentHeight[0] = 0.00
      • Set TMS_CurrentTurretCount[0] = 0
      • Set TMS_CurrentWeight[0] = 0
      • Set TMS_DeathModel[0] = <Empty String>
      • Set TMS_DeathScale[0] = 0.00
      • Set TMS_DeathTimer = 0.00
      • Set TMS_DeathTimerCurrent[0] = 0.00
      • Set TMS_DefaultLimit = 0
      • Set TMS_DummyType = TMS_DummyType
      • Set TMS_ErrorMessages[0] = <Empty String>
      • Set TMS_FilterMode = 0
      • Set TMS_FireCooldown[0] = 0.00
      • Set TMS_FireCooldownCurrent[0] = 0.00
      • Set TMS_HaveDeathSfx[0] = False
      • Set TMS_HaveHoming[0] = False
      • Set TMS_HaveImpactSfx[0] = False
      • Set TMS_HaveInaccuracy[0] = False
      • Set TMS_HaveLaunchSfx[0] = False
      • Set TMS_HaveProjectileArc[0] = False
      • Set TMS_HaveRelativeDamage[0] = False
      • Set TMS_HaveTargettingSfx[0] = False
      • Set TMS_HaveTrueSpeed[0] = False
      • Set TMS_HealthDamage[0] = 0.00
      • Set TMS_HeightCorrection[0] = 0.00
      • Set TMS_HeightLet = 0.00
      • Set TMS_ImpactModel[0] = <Empty String>
      • Set TMS_ImpactScale[0] = 0.00
      • Set TMS_ImpactTime[0] = 0.00
      • Set TMS_Inaccuracy[0] = 0.00
      • Set TMS_Index = 0
      • Set TMS_LaunchModel[0] = <Empty String>
      • Set TMS_LaunchScale[0] = 0.00
      • Set TMS_ManaDamage[0] = 0.00
      • Set TMS_MaxDistance[0] = 0.00
      • Set TMS_MaxHeight[0] = 0.00
      • Set TMS_MaxIndex = 0
      • Set TMS_MountedUnit[0] = TMS_MountedUnit[0]
      • Set TMS_MountingHeight[0] = 0.00
      • Set TMS_MountingOffset[0] = 0.00
      • Set TMS_MovementSpeed[0] = 0.00
      • Set TMS_PositionAngle[0] = 0.00
      • Set TMS_ProjectileAOE[0] = 0.00
      • Set TMS_ProjectileFuel[0] = 0.00
      • Set TMS_ProjectileModel[0] = <Empty String>
      • Set TMS_ProjectileScale[0] = 0.00
      • Set TMS_ProjectileSpeed[0] = 0.00
      • Set TMS_Range[0] = 0.00
      • Set TMS_SecondaryIndex = 0
      • Set TMS_SelectedTarget[0] = TMS_SelectedTarget[0]
      • Set TMS_SpeedLimit[0] = 0.00
      • Set TMS_SpeedOverTimeFixed[0] = 0.00
      • Set TMS_SpeedOverTimeMultiplyer[0] = 0.00
      • Set TMS_StackedCorrection[0] = 0.00
      • Set TMS_StageID[0] = 0
      • Set TMS_TargetLock[0] = False
      • Set TMS_TargetStatus[0] = 0
      • Set TMS_TargetType[0] = 0
      • Set TMS_TargettingEffect[0] = TMS_TargettingEffect[0]
      • Set TMS_TargettingMethod[0] = 0
      • Set TMS_TargettingModel[0] = <Empty String>
      • Set TMS_TargettingScale[0] = 0.00
      • Set TMS_TargettingUnit[0] = TMS_TargettingUnit[0]
      • Set TMS_TempBoolean = False
      • Set TMS_TempGroup = TMS_TempGroup
      • Set TMS_TempInteger = 0
      • Set TMS_TempInteger2 = 0
      • Set TMS_TempPlayer = TMS_TempPlayer
      • Set TMS_TempPoint = TMS_TempPoint
      • Set TMS_TempPoint2 = TMS_TempPoint2
      • Set TMS_TempReal = 0.00
      • Set TMS_TempReal2 = 0.00
      • Set TMS_TempReal3 = 0.00
      • Set TMS_TempUnit = TMS_TempUnit
      • Set TMS_TempUnit2 = TMS_TempUnit2
      • Set TMS_TempUnit3 = TMS_TempUnit3
      • Set TMS_TempX = 0.00
      • Set TMS_TempX2 = 0.00
      • Set TMS_TempY = 0.00
      • Set TMS_TempY2 = 0.00
      • Set TMS_Timer = TMS_Timer
      • Set TMS_TimerSpeed = 0.00
      • Set TMS_TurretInit = 0
      • Set TMS_TurretLimit[0] = 0
      • Set TMS_TurretModel[0] = <Empty String>
      • Set TMS_TurretName[0] = <Empty String>
      • Set TMS_TurretNumber = 0
      • Set TMS_TurretScale[0] = 0.00
      • Set TMS_TurretType[0] = 0
      • Set TMS_TurretWeight[0] = 0
      • Set TMS_UnitIndex[0] = TMS_UnitIndex[0]
      • Set TMS_ZHeight[0] = 0.00




JASS:
////////////////////////////////////////////////////////////////////////////////////////////////
// This is the default information which all turrets need/have to function properly, CnP this //
// into the trigger or script you are using to register a turret and the configure it         //
////////////////////////////////////////////////////////////////////////////////////////////////

    set udg_TMS_TurretName[udg_TMS_TurretInit] = "Input turret name"
    set udg_TMS_TurretModel[udg_TMS_TurretInit] = "Input turret model"
    set udg_TMS_ProjectileModel[udg_TMS_TurretInit] = "Input projectile model"
    set udg_TMS_LaunchModel[udg_TMS_TurretInit] = "Input launch effect model"
    set udg_TMS_ImpactModel[udg_TMS_TurretInit] = "Input impact effect model"
    set udg_TMS_DeathModel[udg_TMS_TurretInit] = "Input death effect model"
    set udg_TMS_TargettingModel[udg_TMS_TurretInit] = "Input targetting effect model"
    set udg_TMS_TurretScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ProjectileScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_LaunchScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_DeathScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_TargettingScale[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HaveLaunchSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveImpactSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveDeathSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTargettingSfx[udg_TMS_TurretInit] = false
    set udg_TMS_HaveHoming[udg_TMS_TurretInit] = false
    set udg_TMS_HaveRelativeDamage[udg_TMS_TurretInit] = false
    set udg_TMS_HaveInaccuracy[udg_TMS_TurretInit] = false
    set udg_TMS_HaveProjectileArc[udg_TMS_TurretInit] = false
    set udg_TMS_HaveTrueSpeed[udg_TMS_TurretInit] = false
    set udg_TMS_BonusEffects[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingHeight[udg_TMS_TurretInit] = 0.00
    set udg_TMS_MountingOffset[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ProjectileAOE[udg_TMS_TurretInit] = 0.00
    set udg_TMS_AoeDamageDissapation[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Inaccuracy[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ArcFactor[udg_TMS_TurretInit] = 0.00
    set udg_TMS_Range[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ProjectileSpeed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedOverTimeMultiplyer[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedOverTimeFixed[udg_TMS_TurretInit] = 0.00
    set udg_TMS_SpeedLimit[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ProjectileFuel[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ImpactTime[udg_TMS_TurretInit] = 0.00
    set udg_TMS_HealthDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_ManaDamage[udg_TMS_TurretInit] = 0.00
    set udg_TMS_FireCooldown[udg_TMS_TurretInit] = 0.00
    set udg_TMS_TurretWeight[udg_TMS_TurretInit] = 0
    set udg_TMS_TargettingMethod[udg_TMS_TurretInit] = 0
    set udg_TMS_TargetType[udg_TMS_TurretInit] = 0
    set udg_TMS_TargetStatus[udg_TMS_TurretInit] = 0
    set udg_TMS_TargetLock[udg_TMS_TurretInit] = false
    set udg_TMS_AttackType[udg_TMS_TurretInit] = ATTACK_TYPE_NORMAL
    set udg_TMS_DamageType[udg_TMS_TurretInit] = DAMAGE_TYPE_NORMAL 
    call TMS_RegisterTurret(0)


  • TMS GUI Stock Turret Data
    • Events
    • Conditions
    • Actions
      • Set TMS_TurretName[TMS_TurretInit] = Input turret name
      • Set TMS_TurretModel[TMS_TurretInit] = Input turret model
      • Set TMS_ProjectileModel[TMS_TurretInit] = Input projectile model
      • Set TMS_LaunchModel[TMS_TurretInit] = Input launch model
      • Set TMS_ImpactModel[TMS_TurretInit] = Input impact model
      • Set TMS_DeathModel[TMS_TurretInit] = Input death model
      • Set TMS_TargettingModel[TMS_TurretInit] = Input targetting model
      • Set TMS_TurretScale[TMS_TurretInit] = 0.00
      • Set TMS_ProjectileScale[TMS_TurretInit] = 0.00
      • Set TMS_LaunchScale[TMS_Index] = 0.00
      • Set TMS_ImpactScale[TMS_TurretInit] = 0.00
      • Set TMS_DeathScale[TMS_TurretInit] = 0.00
      • Set TMS_TargettingScale[TMS_TurretInit] = 0.00
      • Set TMS_HaveLaunchSfx[TMS_TurretInit] = False
      • Set TMS_HaveImpactSfx[TMS_TurretInit] = False
      • Set TMS_HaveDeathSfx[TMS_TurretInit] = False
      • Set TMS_HaveTargettingSfx[TMS_TurretInit] = False
      • Set TMS_HaveHoming[TMS_TurretInit] = False
      • Set TMS_HaveRelativeDamage[TMS_TurretInit] = False
      • Set TMS_HaveInaccuracy[TMS_TurretInit] = False
      • Set TMS_HaveProjectileArc[TMS_TurretInit] = False
      • Set TMS_HaveTrueSpeed[TMS_TurretInit] = False
      • Set TMS_BonusEffects[TMS_TurretInit] = 0.00
      • Set TMS_MountingHeight[TMS_TurretInit] = 0.00
      • Set TMS_MountingOffset[TMS_TurretInit] = 0.00
      • Set TMS_ProjectileAOE[TMS_TurretInit] = 0.00
      • Set TMS_AoeDamageDissapation[TMS_TurretInit] = 0.00
      • Set TMS_Inaccuracy[TMS_TurretInit] = 0.00
      • Set TMS_ArcFactor[TMS_TurretInit] = 0.00
      • Set TMS_Range[TMS_TurretInit] = 0.00
      • Set TMS_ProjectileSpeed[TMS_TurretInit] = 0.00
      • Set TMS_SpeedOverTimeMultiplyer[TMS_TurretInit] = 0.00
      • Set TMS_SpeedOverTimeFixed[TMS_TurretInit] = 0.00
      • Set TMS_SpeedLimit[TMS_TurretInit] = 0.00
      • Set TMS_ProjectileFuel[TMS_TurretInit] = 0.00
      • Set TMS_ImpactTime[TMS_TurretInit] = 0.00
      • Set TMS_HealthDamage[TMS_TurretInit] = 0.00
      • Set TMS_ManaDamage[TMS_TurretInit] = 0.00
      • Set TMS_FireCooldown[TMS_TurretInit] = 0.00
      • Set TMS_TurretWeight[TMS_TurretInit] = 0
      • Set TMS_TargettingMethod[TMS_TurretInit] = 0
      • Set TMS_TargetType[TMS_TurretInit] = 0
      • Set TMS_TargetStatus[TMS_TurretInit] = 0
      • Set TMS_TargetLock[TMS_TurretInit] = False
      • Set TMS_AttackType[TMS_TurretInit] = Normal
      • Set TMS_DamageType[TMS_TurretInit] = Normal
      • Custom script: call TMS_RegisterTurret(0)




-=V1.00=-
- Initial Upload
-=V1.01=-
- Can now register turrets on-the-fly (unlockable turrets for a map?)
- Can now register carriers on-the-fly (unlockable carriers for a map?)
- Updated readme to include function list and further function explanation
- Cached target filter data handling into another function
- Shortened script
- Added error for when the TurretType has not been specified with AddTurret function
- Streamlined Configuration
- A few minor other changes
-=V1.02=-
- Changed The finding target function to use a different method
- Modified IF statements to be more efficient
- Shortened code
- Changed the filter function slightly
- Ommited redundant SquareRoot functions
- Made Unit Group selections more efficient
- Other minor changes
-=V1.03=-
- Minor Corrections
- Changed method of build-off-support (read updated readme)
-=V1.04=-
- Fixed a bug involving Launch Sfx modifying turret size
- Fixed a facing direction bug upon original attacking of targets
- Fixed a facing direction bug when you had one turret on your carrier
- Fixed a projectile AOE bug which was causing projectiles to deal too little damage
- Added turret weight - now your turrets can take up more than one carrier slot if desired
- Added new test carrier and example turret - Armageddon Cannon, takes up 5 slots
- Projectiles now graphically follow the arc the dummys have.
-=V1.05=-
- Made Attack Type and Damage Type configurable
- Magic damage turrets won't target Magic immunes
- More ElseIf business (just give me a list of them if I missed any more)
- Changed Death detection of targets
- Made temporary effects more efficient (no more variable needed)
- Made the TempPoint removal more obvious so Mag won't miss it when he re-reads again this time
- Widget business
- Rearrangement of some things
- Minor changes
-=V1.06=-
- Can now update already registered turrets for upgrading (why didn't I do this before?)
- Added names to turrets (should be unique to each turret)
- By using the names, added TMS_GetTurretByName function, to help locate turrets in the registry, you don't know the assigned number for (designed to help with upgrading)
- Can no longer have duplicate carriers in the system, but can also change the limit for a carrier on-the-fly (just re-register the carrier with the new limit)
- Added example of an upgradable turret
- Updated readme, also now includes a section to help with how one would create turrets specific to a player using the GetTurretByName function and player numbers
- Generally think the system has a lot more practical support uses now for mapmakers
-=V1.07=-
- Added missile homing
- Added missile speed changing in flight (exponent and constant) note: speeds over 50 may cause projectile displacement (increased inaccuracy)
- Added targetting effects (can either be attached to the terrain or to units)
- Added height let (greater accuracy of projectiles overshooting/undershooting (particularly vs flying units))
- Added projectile fuel (only applies to homing units, as it's redundant to use on others due to range limits)
- Corrected slight projectile displacement just before landing
- 2 new example turrets (one homing, one using missile speed changes in-flight
- New screenshot
- Test map changed and improved (quests explaining each turret, and starting with 1 of each) (example carriers updated to carry the max of each turret)
-=V1.08=-
- swapped some GetUnitStates with GetWidgetLife
- minor changes
-=V1.09=-
- Added "En masse" section to readme - gives information about how to use the system if you want to have En masse units using mounted turrets (as this system is not designed for that in it's current form)
- Added manual targetting (turns off the AI for that turret)
- Added another example: Archer tower - uses Manual targetting (must be trigger controlled) automatically placed on the Archer tower structure (example unit) targets using the basic attack of the tower (deals 0 damage, but tells the archer to attack that target)
- More or less the same just with some more support and examples for you guys
-=V1.10=-
- Fixed a bug which caused DamageTypes and WeaponTypes from not correctly registering/updating


Give credits if you use this system in your map and most of all, enjoy!

Keywords:
AI, Turret, Carrier, Automatic, System, Mini Turrets, Escorts, Projectile, Smart, Tank-Commander, over-configurable, long readme.
Contents

Turret Mounting System (Map)

Reviews
14:07, 14th Apr 2013 Magtheridon96: Approved. 5/5 This is a wonderful system and I am really proud of you Tankehpoo. I bet you're really mad right now. There are tiny pedantic improvements though. In the TMS_Loop, you can use...

Moderator

M

Moderator

14:07, 14th Apr 2013
Magtheridon96:

Approved. 5/5
This is a wonderful system and I am really proud of you Tankehpoo.
I bet you're really mad right now.

There are tiny pedantic improvements though.
In the TMS_Loop, you can use Get/SetWidgetLife instead of the Get/SetUnitState calls.
Your death check in TMS_Loop should use the IsUnitType and the GetUnitTypeId natives for more accurate results.
Yes, that last one is not very pedantic. You go ahead and update this, okay? ;)
Please don't kill me, I have children to attend to ;_;

Comments

  • You can use elseif here:

    JASS:
    else
        if (TurretCount < 1) then
            call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, udg_TMS_ErrorMessages[2])
        else
            call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, udg_TMS_ErrorMessages[3])
        endif
    endif
  • The entire TMS_Loop function can be improved if you were to rely on an if/elseif/elseif/elseif/else structure.
    This is because all of the if blocks nested into each other are evaluating mutually exclusive conditions (since they are reading the same variable)
  • In case you didn't know this, you can pass 0 without a decimal point as a real and it would be totally fine in JASS :p
  • Use GetWidgetLife and SetWidgetLife instead of those SetUnitState calls. (Only for current life)
  • Instead of WEAPON_TYPE_WHOKNOWS, you can use null because they're pretty much the same thing.
  • Make the ATTACK_TYPE and DAMAGE_TYPE configurable D:
  • You may need to do a death check like so: not IsUnitType(u, UNIT_TYPE_DEAD). Beware though, this returns true for null units D:
    In addition to this, you can add a life check. You shouldn't compare with 0 however, you should compare with 0.405 :eek:
    You can never be 100% accurate in such a case. Reincarnating units need to be taken into account. Another solution is to add a GetUnitTypeId(...) != 0 check. You'd have to experiment with all these to get the best results :p
  • JASS:
    if ((udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 5) or (udg_TMS_TargetStatus[udg_TMS_TurretType[udg_TMS_Index]] == 6)) and ((IsUnitType(u, UNIT_TYPE_GROUND)) and (not IsUnitType(u, UNIT_TYPE_STRUCTURE))) then
        call GroupRemoveUnit(udg_TMS_TempGroup, u)
    elseif (IsUnitType(u, UNIT_TYPE_GROUND)) then
        call GroupRemoveUnit(udg_TMS_TempGroup, u)
    endif
    IsUnitType(u, UNIT_TYPE_GROUND) can be taken outside of both of those expressions and put in the if block that surrounds this snippet of code.
    You would then change the logic in both of the conditional expressions above making them assume that the unit is in fact a ground unit because the outer if block would have assured that :p
  • JASS:
    set udg_TMS_TempPoint2 = Location(GetUnitX(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex]), GetUnitY(udg_TMS_UnitIndex[udg_TMS_SecondaryIndex]))
    set udg_TMS_TempReal2 = GetLocationZ(udg_TMS_TempPoint2)
    This location should be removed directly after you get the Z of the location.
  • Wanna know an alternative solution to something like this?

    JASS:
    set my_effect = AddSpecialEffect(...)
    call DestroyEffect(my_effect)

    It looks a little bit like this:

    JASS:
    call DestroyEffect(AddSpecialEffect(...))

    This is applicable to a lot of sections in your code.
  • JASS:
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 1) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_LIFE)
        if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        else
            call TMS_FilterData(u)
        endif
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 2) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_LIFE)
        if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        else
            call TMS_FilterData(u)
        endif                
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 3) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_LIFE)
        if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
            call TMS_FilterData(u)
        else
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 4) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_LIFE)
        if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
            call TMS_FilterData(u)
        else
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif   
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 5) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_MANA)
        if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        else
            call TMS_FilterData(u)
        endif
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 6) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MANA)
        if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        else
            call TMS_FilterData(u)
        endif
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 7) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MAX_MANA)
        if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
            call TMS_FilterData(u)
        else
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 8) then
        set udg_TMS_TempReal = GetUnitState(u, UNIT_STATE_MANA)
        if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
            call TMS_FilterData(u)
        else
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 9) then
        set udg_TMS_TempX = GetUnitX(udg_TMS_MountedUnit[udg_TMS_Index])
        set udg_TMS_TempY = GetUnitY(udg_TMS_MountedUnit[udg_TMS_Index])
        set udg_TMS_TempX2 = GetUnitX(u)
        set udg_TMS_TempY2 = GetUnitY(u)
        set udg_TMS_TempReal = ((udg_TMS_TempX2 - udg_TMS_TempX) * (udg_TMS_TempX2 - udg_TMS_TempX)) + ((udg_TMS_TempY2 - udg_TMS_TempY) * (udg_TMS_TempY2 - udg_TMS_TempY))
        if (udg_TMS_TempReal < udg_TMS_TempReal2) or (udg_TMS_TempReal2 == -1.00) then
            call TMS_FilterData(u)
        else
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        endif            
    endif
    if (udg_TMS_TargettingMethod[udg_TMS_TurretType[udg_TMS_Index]] == 10) then
        set udg_TMS_TempX = GetUnitX(udg_TMS_MountedUnit[udg_TMS_Index])
        set udg_TMS_TempY = GetUnitY(udg_TMS_MountedUnit[udg_TMS_Index])
        set udg_TMS_TempX2 = GetUnitX(u)
        set udg_TMS_TempY2 = GetUnitY(u)
        set udg_TMS_TempReal = ((udg_TMS_TempX2 - udg_TMS_TempX) * (udg_TMS_TempX2 - udg_TMS_TempX)) + ((udg_TMS_TempY2 - udg_TMS_TempY) * (udg_TMS_TempY2 - udg_TMS_TempY))
        if (udg_TMS_TempReal <= udg_TMS_TempReal2) then
            call GroupRemoveUnit(udg_TMS_TempGroup, u)
        else
            call TMS_FilterData(u)
        endif            
    endif
    This entire code block can rely on the elseif keyword since all the conditional expressions are mutually exclusive. You are evaluating the same variable value. No two if blocks will run at once, so why check all of them? :p. Using the elseif keyword will assure that you will stop checking the rest of the conditional expressions as soon as the correct one has been found.
  • JASS:
    set udg_TMS_TempReal3 = SquareRoot(udg_TMS_TempReal2 * udg_TMS_TempReal2 + udg_TMS_TempReal * udg_TMS_TempReal)
    if (udg_TMS_SelectedTarget[udg_TMS_Index] == null) or (not udg_TMS_TargetLock[udg_TMS_TurretType[udg_TMS_Index]]) or (udg_TMS_TempReal3 > udg_TMS_Range[udg_TMS_TurretType[udg_TMS_Index]]) then
    In this snippet of code, you can get rid of the SquareRoot call and just compare TempReal3 with udg_TMS_Range*udg_TMS_Range.
  • You're sometimes restarting the system timer when you don't need to. With the low timeout that the system has right now, this is totally fine, but with larger timeouts and heavy turret adding, the effects would be terrible :p. You should only start the timer if the instance that you're registering happens to be the first instance in the list, meaning the total turrent count is now exactly 1. (after you increment it while taking account the current instance of course)

Other than that, this looks like a lovely system and I'd be more than happy to give it a high rating. It's not the most efficient beast out there, but it's wicked sick either way!
 
If anybody would be able/willing to create a dedicated model for this system for mounting turrets onto while looking aesthetically pleasing that would really be the icing on the cake.

if somebody does, (or knows a good model for this) link it to me in PM or a post, and I'll add it to the description

~reserved
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
Woah!
Tank- Commander released a system yay! and it features tanks too :3

Uhmm,to reduce variables,i think you should use constants.But meh,it will make the script longer.

You should use hashtable and an encapsulation method.Register the available turrets and its data to that function then save it for every instance the Register is called.
Example:
JASS:
function Register takes integer id, string mdl returns nothing
    call SaveString(udg_Hash, id, 0, mdl)
endfunction

function Init takes nothing returns nothing
    call Register('hfoo', "Hello")
endfunction
Also,let them register the turret and datas they want. Just put the datas on demos.

About the projectile effects,you don't need them to add their functions.Let them register the effects they want via either code or trigger.


JASS:
                    set udg_TMS_TempReal2 = udg_TMS_TempReal
                    if (not(udg_TMS_TempUnit3 == null)) then
                        call GroupRemoveUnit(udg_TMS_TempGroup, udg_TMS_TempUnit3)
                    endif
                    set udg_TMS_TempUnit3 = udg_TMS_TempUnit2
Cache this into a function.

You should also read this mini-tutorial : http://www.hiveworkshop.com/forums/tutorial-submission-283/use-functions-other-triggers-232537/
That tutorial teaches you not to use Map Header for your functions. And also this works 100% not to encounter any code errors.

if (udg_TMS_TempBoolean == false) then
->
if not udg_TMS_TempBoolean then

JASS:
    call UnitAddAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf')
    call UnitRemoveAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf')
->
JASS:
 if UnitAddAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') and UnitRemoveAbility(udg_TMS_UnitIndex[udg_TMS_MaxIndex], 'Amrf') then
endif
For safety.

set udg_TMS_Angle = GetRandomReal(0, 360) * bj_DEGTORAD
->
set udg_TMS_Angle = GetRandomReal(-bj_PI, bj_PI)

set udg_TMS_TimerSpeed = 0.03125
Add "0000" at the end of 5 ( reals are inaccurate )

RemoveUnit function does not guarantee you to clean leaks.
The guaranteed one is by setting the Death Animation to 0 and Fix the death type of the dummy (It should be Can't raise, does not decay).
 
Modifications in progress, also updating Readme, will edit this post when updates are completed.

Edit: Initial Modifications complete

Notes: Almia, explain why the remove/add abilities are in an if statement/why that works? if you be so kind, logically doesn't make much sense to me
additionally, I feel adding 4 "0"s on the end of "0.03125" is fairly superfluous but if you think it'd be benefitial to the system then I can't see a reason why not
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
You can test the real inaccuracy with this I think.

JASS:
library TimerTest initializer init
    globals
        private timer t1 = CreateTimer()
        private timer t2 = CreateTimer()
        private timer t3 = CreateTimer()
        private constant real to1 = 0.001
        private constant real to2 = 0.0010000
        private constant real addA = 0.001
        private constant real addB = 0.0010000
        private real totalA = 0
        private real totalB = 0
        private boolean pause
    endglobals
    
    private function results takes nothing returns nothing
        call DisplayTimedTextToPlayer(Player(0), 0, 0, 10, "Timer A: " + R2S(totalA))
        call DisplayTimedTextToPlayer(Player(0), 0, 0, 10, "Timer B: " + R2S(totalB))
    endfunction
    
    private function timerEndB takes nothing returns nothing
        set totalB = totalB + addB
        if pause then
            call PauseTimer(t2)
        endif
    endfunction
    
    private function timerEndA takes nothing returns nothing
        set totalA = totalA + addA
        if pause then
            call PauseTimer(t1)
            call TimerStart(t3, 0.05, false, function results)
        endif
    endfunction
    
    private function StartTimers takes nothing returns nothing
        if ModuloInteger(GetTriggerExecCount(GetTriggeringTrigger()), 2) == 1 then
            call DisplayTimedTextToPlayer(Player(0), 0, 0, 10, "Start")
            set pause = false
            call TimerStart(t1, to1, true, function timerEndA)
            call TimerStart(t2, to2, true, function timerEndB)
        else
            set pause = true
        endif
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t, function StartTimers)
    endfunction
    
endlibrary

I let it run for 73 seconds and both values were the same, though the message only displays three decimals.
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
Idk how Mag exceeded the 3 decimals in the text.

edit
The DEGTORAD at GetRandomReal(-bj_PI,bj_PI) * bj_DEGTORAD must be removed. It is already in radians.

GetOwningPlayer(u) must be cached.

You can replace this:
JASS:
function InitTrig_TMS_TurretMountingSystem takes nothing returns nothing
    //Error messages for the system
    set udg_TMS_ErrorMessages[0] = "This unit cannot have turrets mounted"
    set udg_TMS_ErrorMessages[1] = "Turret limit reached"
    set udg_TMS_ErrorMessages[2] = "You need to specify the number of turrets to mount"
    set udg_TMS_ErrorMessages[3] = "You need to specify the turret type number"
    //Determines the default limit for units not registered in the Carrier Units setup
    set udg_TMS_DefaultLimit = 0
    // Determines the how long death effects play for before the unit is removed
    set udg_TMS_DeathTimer = 1.00
    // Determines the dummy used for the turrets
    set udg_TMS_DummyType = 'u001'
    // --------
    // Determines the Speed of the loop trigger
    set udg_TMS_TimerSpeed = 0.031250000
endfunction

With constant functions.

If you are going to use some TempVariables for just one function,just use locals instead(to reduce mass variable importing.JASS can't support instant variable CnP in preferences > Create unknown variables while pasting data)
 
Last edited:
Level 6
Joined
May 23, 2011
Messages
295
so this is what you were talking about on the chat..i must say you did a great job with the turrets and off course stunned everione again XD 5\5 but like you said you have to watch out for the lag
 
It's written in pure JASS, to my understanding, that makes "globals" blocks not useable, so the configuration, would still be using udg_ all the time, you can just CnP the config and that saves you the effort of typing any of it but the values you want, as for locals, I already do in quite a few places, though I suppose I could use more, possibly.

Currently working on a physics improvement
 
yeah, I'm aware of the issue, however I can't do much to solve it because if I set it to "true" physics, then some shots the turret AI will take, cannot hit, and the processing would increase tenfold to make the AI account for such when selecting targets as to make it only select targets it can hit, and the system already uses a lot of processing, so you're a bit stuck with the slightly wobbly arcs with sea-to-land battles I'm afraid.
 
You know, that doesn't necessarily mean there's a memory leak (or leaks), if there is one you can find, I will of course remove it, but a non-specific speculative reasoning isn't exactly going to help with that - since it gives no indication of where to even begin looking. After all it could've been a lack of RAM in your Computer system or just the game failing (along with a few other explanations)
 
Level 25
Joined
Feb 2, 2006
Messages
1,669
Hi, this is a nice system and really useful for Modern Warfare maps but I am wondering about:

  • Why no manual targeting example in the demo map or did I miss it? You could simply catch smart orders of the tank and translate them into attack orders/targeting from the turret. The tank only has to move in range and the target should have priority then. Only auto targeting in the demo map makes it hard to image the system if you still want to have the control over the targets. The big advantage of the turrets in my opinion is that you can move while shooting (like Phoenix Fire) but the targeting would be something which Phoenix Fire does not have.
  • How would AI handle tanks with turrets? Since the tanks have no attack, do they just move around with the army randomly?
  • When the turret kills a unit, is the tank the killing unit or the turret? I guess the turret right?
  • It seems that you create the missiles manually with code from the turrets and the turret models as well? Why not create dummies as turrets which are clickable of configured and can have their own HP and be healed/repaired?
  • The tanks in the demo map seem to flee when hit which is a bit annoying.
  • Could you show the damage as regular damage for the tank unit BUT catch attack orders, so the tank will never really attack but the turret will focus the target instead if it is range.
  • It seems that all turrets from one carrier fire at the same target? Is it possible to allow them attacking different targets?

I think it is a great useful system for modern warfare maps BUT I think it would be much better to create dummies for the different turret types with Warcraft's attack/missile engine. You can still use the custom auto targeting code to prefer certain targets but the whole code for projectiles will be obsolete which would probably improve the performance a lot! You just have to auto update the positions of the turret units and their targets. The code for the loop TMS_Loop is pretty long. I am not even sure if you want to specify specific targets if you use Warcraft dummy units with their own attacks. If not, the loop code would only update the turret positions and issue them to attack a focused target if it is in range which would really reduce the code.
You would not need the moving special effects either with one dummy unit type per turret type since you only have to move the dummy.

edit:
I tried it myself and if you use dummy units for turrets you have to auto move them with SetUnitX and SetUnitY as described here: Attacking WHILE moving!
Otherwise, the attack gets interrupted.
 
Last edited:
Top