//////////////////////////////////////////////////////////////////////////////////////////////////
// //
// 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 //
/////////////////////////////////////////////////////////////////////////////////////////////////